rdesign/frontend/node_modules/@copilotkitnext/react/dist/hooks/use-render-tool.d.mts

87 lines
2.6 KiB
TypeScript

import { InferSchemaOutput, StandardSchemaV1 } from "@copilotkitnext/shared";
//#region src/hooks/use-render-tool.d.ts
interface RenderToolInProgressProps<S extends StandardSchemaV1> {
name: string;
parameters: Partial<InferSchemaOutput<S>>;
status: "inProgress";
result: undefined;
}
interface RenderToolExecutingProps<S extends StandardSchemaV1> {
name: string;
parameters: InferSchemaOutput<S>;
status: "executing";
result: undefined;
}
interface RenderToolCompleteProps<S extends StandardSchemaV1> {
name: string;
parameters: InferSchemaOutput<S>;
status: "complete";
result: string;
}
type RenderToolProps<S extends StandardSchemaV1> = RenderToolInProgressProps<S> | RenderToolExecutingProps<S> | RenderToolCompleteProps<S>;
/**
* Registers a wildcard (`"*"`) renderer for tool calls.
*
* The wildcard renderer is used as a fallback when no exact name-matched
* renderer is registered for a tool call.
*
* @param config - Wildcard renderer configuration.
* @param deps - Optional dependencies to refresh registration.
*
* @example
* ```tsx
* useRenderTool(
* {
* name: "*",
* render: ({ name, status }) => (
* <div>
* {status === "complete" ? "✓" : "⏳"} {name}
* </div>
* ),
* },
* [],
* );
* ```
*/
declare function useRenderTool(config: {
name: "*";
render: (props: any) => React.ReactElement;
agentId?: string;
}, deps?: ReadonlyArray<unknown>): void;
/**
* Registers a name-scoped renderer for tool calls.
*
* The provided `parameters` schema defines the typed shape of `props.parameters`
* in `render` for `executing` and `complete` states. Accepts any Standard Schema V1
* compatible library (Zod, Valibot, ArkType, etc.).
*
* @typeParam S - Schema type describing tool call parameters.
* @param config - Named renderer configuration.
* @param deps - Optional dependencies to refresh registration.
*
* @example
* ```tsx
* useRenderTool(
* {
* name: "searchDocs",
* parameters: z.object({ query: z.string() }),
* render: ({ status, parameters, result }) => {
* if (status === "inProgress") return <div>Preparing...</div>;
* if (status === "executing") return <div>Searching {parameters.query}</div>;
* return <div>{result}</div>;
* },
* },
* [],
* );
* ```
*/
declare function useRenderTool<S extends StandardSchemaV1>(config: {
name: string;
parameters: S;
render: (props: RenderToolProps<S>) => React.ReactElement;
agentId?: string;
}, deps?: ReadonlyArray<unknown>): void;
//#endregion
export { useRenderTool };
//# sourceMappingURL=use-render-tool.d.mts.map