@assistant-ui/core 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model-context/tool.d.ts +1 -1
- package/dist/model-context/tool.js +1 -1
- package/dist/model-context/tool.js.map +1 -1
- package/dist/model-context/types.js +17 -2
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +12 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +9 -3
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +7 -3
- package/dist/react/index.js +6 -2
- package/dist/react/model-context/define-mcp-toolkit.d.ts +12 -0
- package/dist/react/model-context/define-mcp-toolkit.d.ts.map +1 -0
- package/dist/react/model-context/define-mcp-toolkit.js +14 -0
- package/dist/react/model-context/define-mcp-toolkit.js.map +1 -0
- package/dist/react/model-context/define-toolkit.d.ts +4 -3
- package/dist/react/model-context/define-toolkit.d.ts.map +1 -1
- package/dist/react/model-context/define-toolkit.js +1 -14
- package/dist/react/model-context/define-toolkit.js.map +1 -1
- package/dist/react/model-context/hitl.d.ts +8 -4
- package/dist/react/model-context/hitl.d.ts.map +1 -1
- package/dist/react/model-context/hitl.js +9 -5
- package/dist/react/model-context/hitl.js.map +1 -1
- package/dist/react/model-context/makeAssistantTool.d.ts +8 -0
- package/dist/react/model-context/makeAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantTool.js +4 -0
- package/dist/react/model-context/makeAssistantTool.js.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.d.ts +8 -0
- package/dist/react/model-context/makeAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.js +4 -0
- package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/provider-tool.d.ts +15 -0
- package/dist/react/model-context/provider-tool.d.ts.map +1 -0
- package/dist/react/model-context/provider-tool.js +12 -0
- package/dist/react/model-context/provider-tool.js.map +1 -0
- package/dist/react/model-context/stub-tool.d.ts +12 -0
- package/dist/react/model-context/stub-tool.d.ts.map +1 -0
- package/dist/react/model-context/stub-tool.js +15 -0
- package/dist/react/model-context/stub-tool.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +62 -15
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +19 -1
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantTool.d.ts +11 -1
- package/dist/react/model-context/useAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantTool.js +12 -6
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.d.ts +13 -4
- package/dist/react/model-context/useAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +6 -3
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.d.ts +22 -0
- package/dist/react/model-context/useAuiToolOverrides.d.ts.map +1 -0
- package/dist/react/model-context/useAuiToolOverrides.js +31 -0
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -0
- package/dist/react/primitives/part/PartMessages.d.ts +13 -11
- package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.js +13 -11
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +28 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +9 -2
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts +2 -0
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +6 -0
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +2 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +5 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js +3 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -0
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +1 -0
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/model-context/tool.ts +1 -1
- package/src/model-context/types.ts +21 -3
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +15 -2
- package/src/react/client/Tools.ts +22 -7
- package/src/react/index.ts +14 -3
- package/src/react/model-context/define-mcp-toolkit.ts +16 -0
- package/src/react/model-context/define-toolkit.test.ts +92 -4
- package/src/react/model-context/define-toolkit.ts +21 -3
- package/src/react/model-context/hitl.ts +10 -5
- package/src/react/model-context/makeAssistantTool.ts +8 -0
- package/src/react/model-context/makeAssistantToolUI.ts +8 -0
- package/src/react/model-context/provider-tool.ts +30 -0
- package/src/react/model-context/stub-tool.ts +14 -0
- package/src/react/model-context/toolbox.test.ts +182 -0
- package/src/react/model-context/toolbox.ts +189 -21
- package/src/react/model-context/useAssistantTool.ts +28 -8
- package/src/react/model-context/useAssistantToolUI.ts +13 -4
- package/src/react/model-context/useAuiToolOverrides.ts +38 -0
- package/src/react/primitives/part/PartMessages.tsx +13 -11
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +43 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +9 -0
- package/src/runtime/api/thread-list-item-runtime.ts +15 -0
- package/src/runtime/interfaces/thread-list-runtime-core.ts +4 -0
- package/src/runtimes/external-store/external-store-adapter.ts +7 -0
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +13 -0
- package/src/runtimes/remote-thread-list/adapter/in-memory.ts +4 -0
- package/src/runtimes/remote-thread-list/types.ts +4 -0
- package/src/store/clients/model-context-client.test.ts +87 -2
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +1 -0
- package/src/store/scopes/thread-list-item.ts +1 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-custom-metadata.test.ts +69 -1
- package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeAssistantToolUI.js","names":[],"sources":["../../../src/react/model-context/makeAssistantToolUI.ts"],"sourcesContent":["import type { FC } from \"react\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\n/**\n * Component returned by {@link makeAssistantToolUI}.\n *\n * Rendering the component registers a renderer for matching tool-call message\n * parts.\n */\nexport type AssistantToolUI = FC & {\n /** Tool renderer registered by this component. */\n unstable_tool: AssistantToolUIProps<any, any>;\n};\n\n/**\n * Creates a React component that registers a tool-call renderer when rendered.\n *\n * Use this to package reusable display components for tools whose definitions\n * are registered elsewhere.\n *\n * @param tool - Tool renderer registration.\n */\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI: AssistantToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n ToolUI.unstable_tool = tool;\n return ToolUI;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"makeAssistantToolUI.js","names":[],"sources":["../../../src/react/model-context/makeAssistantToolUI.ts"],"sourcesContent":["import type { FC } from \"react\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\n/**\n * Component returned by {@link makeAssistantToolUI}.\n *\n * Rendering the component registers a renderer for matching tool-call message\n * parts.\n *\n * @deprecated Put `render`/`renderText` on the matching toolkit entry, or use\n * `MessagePrimitive.Parts` inline tool render overrides for per-message UI.\n * See https://assistant-ui.com/docs/migrations/toolkit-tools.\n */\nexport type AssistantToolUI = FC & {\n /** Tool renderer registered by this component. */\n unstable_tool: AssistantToolUIProps<any, any>;\n};\n\n/**\n * Creates a React component that registers a tool-call renderer when rendered.\n *\n * Use this to package reusable display components for tools whose definitions\n * are registered elsewhere.\n *\n * @param tool - Tool renderer registration.\n *\n * @deprecated Put `render`/`renderText` on the matching toolkit entry, or use\n * `MessagePrimitive.Parts` inline tool render overrides for per-message UI.\n * See https://assistant-ui.com/docs/migrations/toolkit-tools.\n */\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI: AssistantToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n ToolUI.unstable_tool = tool;\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;;;;;;AAiCA,MAAa,uBACX,SACG;CACH,MAAM,eAAgC;EACpC,mBAAmB,IAAI;EACvB,OAAO;CACT;CACA,OAAO,gBAAgB;CACvB,OAAO;AACT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tool } from "assistant-stream";
|
|
2
|
+
|
|
3
|
+
//#region src/react/model-context/provider-tool.d.ts
|
|
4
|
+
type ProviderToolDefinition<TArgs extends Record<string, unknown>> = Extract<Tool<TArgs, unknown>, {
|
|
5
|
+
type: "provider";
|
|
6
|
+
}>;
|
|
7
|
+
type ProviderToolConfig<TArgs extends Record<string, unknown> = Record<string, unknown>> = Pick<ProviderToolDefinition<TArgs>, "providerId" | "args" | "parameters" | "providerOptions" | "supportsDeferredResults">;
|
|
8
|
+
/**
|
|
9
|
+
* Marks a tool as provider-executed. The use-generative compiler converts
|
|
10
|
+
* `execute: providerTool(...)` into a `type: "provider"` tool entry.
|
|
11
|
+
*/
|
|
12
|
+
declare function providerTool(_config: ProviderToolConfig): never;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ProviderToolConfig, providerTool };
|
|
15
|
+
//# sourceMappingURL=provider-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-tool.d.ts","names":[],"sources":["../../../src/react/model-context/provider-tool.ts"],"mappings":";;;KAEK,sBAAA,eAAqC,MAAA,qBAA2B,OAAA,CACnE,IAAA,CAAK,KAAA;EACH,IAAA;AAAA;AAAA,KAGQ,kBAAA,eACI,MAAA,oBAA0B,MAAA,qBACtC,IAAA,CACF,sBAAA,CAAuB,KAAA;;;;;iBAYT,YAAA,CAAa,OAA2B,EAAlB,kBAAkB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/react/model-context/provider-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Marks a tool as provider-executed. The use-generative compiler converts
|
|
4
|
+
* `execute: providerTool(...)` into a `type: "provider"` tool entry.
|
|
5
|
+
*/
|
|
6
|
+
function providerTool(_config) {
|
|
7
|
+
throw new Error("[assistant-ui] providerTool() has no runtime implementation — it marks a provider-executed tool and is stripped at build time by the use-generative compiler. Reaching it means this module was not compiled (e.g. providerTool() used outside a \"use generative\" file).");
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { providerTool };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=provider-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-tool.js","names":[],"sources":["../../../src/react/model-context/provider-tool.ts"],"sourcesContent":["import type { Tool } from \"assistant-stream\";\n\ntype ProviderToolDefinition<TArgs extends Record<string, unknown>> = Extract<\n Tool<TArgs, unknown>,\n { type: \"provider\" }\n>;\n\nexport type ProviderToolConfig<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n> = Pick<\n ProviderToolDefinition<TArgs>,\n | \"providerId\"\n | \"args\"\n | \"parameters\"\n | \"providerOptions\"\n | \"supportsDeferredResults\"\n>;\n\n/**\n * Marks a tool as provider-executed. The use-generative compiler converts\n * `execute: providerTool(...)` into a `type: \"provider\"` tool entry.\n */\nexport function providerTool(_config: ProviderToolConfig): never {\n throw new Error(\n \"[assistant-ui] providerTool() has no runtime implementation — it marks a \" +\n \"provider-executed tool and is stripped at build time by the \" +\n \"use-generative compiler. Reaching it means this module was not compiled \" +\n '(e.g. providerTool() used outside a \"use generative\" file).',\n );\n}\n"],"mappings":";;;;;AAsBA,SAAgB,aAAa,SAAoC;CAC/D,MAAM,IAAI,MACR,4QAIF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/react/model-context/stub-tool.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Marks a generative toolkit entry as a frontend tool whose executor will be
|
|
4
|
+
* supplied by `useAuiToolOverrides(...)`.
|
|
5
|
+
*
|
|
6
|
+
* `stubTool()` has no runtime implementation. It must be used inside a
|
|
7
|
+
* `"use generative"` toolkit file so the compiler can strip it.
|
|
8
|
+
*/
|
|
9
|
+
declare function stubTool(): never;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { stubTool };
|
|
12
|
+
//# sourceMappingURL=stub-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub-tool.d.ts","names":[],"sources":["../../../src/react/model-context/stub-tool.ts"],"mappings":";;AAOA;;;;AAAwB;;iBAAR,QAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/react/model-context/stub-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Marks a generative toolkit entry as a frontend tool whose executor will be
|
|
4
|
+
* supplied by `useAuiToolOverrides(...)`.
|
|
5
|
+
*
|
|
6
|
+
* `stubTool()` has no runtime implementation. It must be used inside a
|
|
7
|
+
* `"use generative"` toolkit file so the compiler can strip it.
|
|
8
|
+
*/
|
|
9
|
+
function stubTool() {
|
|
10
|
+
throw new Error("[assistant-ui] stubTool() has no runtime implementation - it marks a tool executor that must be supplied via useAuiToolOverrides(...). Make sure this module is compiled as \"use generative\".");
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { stubTool };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=stub-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub-tool.js","names":[],"sources":["../../../src/react/model-context/stub-tool.ts"],"sourcesContent":["/**\n * Marks a generative toolkit entry as a frontend tool whose executor will be\n * supplied by `useAuiToolOverrides(...)`.\n *\n * `stubTool()` has no runtime implementation. It must be used inside a\n * `\"use generative\"` toolkit file so the compiler can strip it.\n */\nexport function stubTool(): never {\n throw new Error(\n \"[assistant-ui] stubTool() has no runtime implementation - it marks a \" +\n \"tool executor that must be supplied via useAuiToolOverrides(...). Make \" +\n 'sure this module is compiled as \"use generative\".',\n );\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,WAAkB;CAChC,MAAM,IAAI,MACR,iMAGF;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ToolCallMessagePartComponent } from "../types/MessagePartComponentTypes.js";
|
|
2
|
-
import { Tool, ToolDeclaration } from "assistant-stream";
|
|
2
|
+
import { Tool, ToolCallReader, ToolDeclaration, ToolModelOutputFunction } from "assistant-stream";
|
|
3
|
+
import { ReactNode } from "react";
|
|
3
4
|
|
|
4
5
|
//#region src/react/model-context/toolbox.d.ts
|
|
5
6
|
/**
|
|
@@ -14,21 +15,47 @@ import { Tool, ToolDeclaration } from "assistant-stream";
|
|
|
14
15
|
declare const isStandaloneToolDisplay: (tool: Pick<Tool<any, any>, "type" | "display">) => boolean;
|
|
15
16
|
type WithRender<T, TArgs extends Record<string, unknown>, TResult> = T extends {
|
|
16
17
|
type: "frontend" | "human";
|
|
17
|
-
} ? T & {
|
|
18
|
+
} ? T & (T extends {
|
|
19
|
+
type: "frontend";
|
|
20
|
+
} ? {
|
|
18
21
|
render: ToolCallMessagePartComponent<TArgs, TResult>;
|
|
19
|
-
}
|
|
22
|
+
} | {
|
|
23
|
+
render?: ToolCallMessagePartComponent<TArgs, TResult>;
|
|
24
|
+
renderText: ToolCallText<TArgs, TResult>;
|
|
25
|
+
} : {
|
|
26
|
+
render: ToolCallMessagePartComponent<TArgs, TResult>;
|
|
27
|
+
}) : T & {
|
|
20
28
|
render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;
|
|
29
|
+
renderText?: ToolCallText<TArgs, TResult> | undefined;
|
|
30
|
+
};
|
|
31
|
+
type ToolParameters<TArgs extends Record<string, unknown>> = ToolDeclaration<TArgs>["parameters"];
|
|
32
|
+
type ToolExecuteContext = Parameters<NonNullable<ToolDeclaration["execute"]>>[1];
|
|
33
|
+
type ToolExecute<TArgs extends Record<string, unknown>, TResult> = (args: TArgs, context: ToolExecuteContext) => TResult | Promise<TResult>;
|
|
34
|
+
type ToolStreamCall<TArgs extends Record<string, unknown>, TResult> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecuteContext) => void;
|
|
35
|
+
type ToolCallRunningText<TArgs extends Record<string, unknown>> = ReactNode | ((options: {
|
|
36
|
+
args: TArgs;
|
|
37
|
+
}) => ReactNode);
|
|
38
|
+
type ToolCallCompleteText<TArgs extends Record<string, unknown>, TResult> = ReactNode | ((options: {
|
|
39
|
+
args: TArgs;
|
|
40
|
+
result: TResult | undefined;
|
|
41
|
+
}) => ReactNode);
|
|
42
|
+
type ToolCallText<TArgs extends Record<string, unknown>, TResult> = {
|
|
43
|
+
running: ToolCallRunningText<TArgs>;
|
|
44
|
+
complete?: ToolCallCompleteText<TArgs, TResult> | undefined;
|
|
45
|
+
} | {
|
|
46
|
+
running?: ToolCallRunningText<TArgs> | undefined;
|
|
47
|
+
complete: ToolCallCompleteText<TArgs, TResult>;
|
|
21
48
|
};
|
|
49
|
+
declare const makeToolCallTextComponent: <TArgs extends Record<string, unknown>, TResult>(text: ToolCallText<TArgs, TResult>) => ToolCallMessagePartComponent<TArgs, TResult>;
|
|
22
50
|
/**
|
|
23
51
|
* Tool definition accepted by the React tool registry.
|
|
24
52
|
*
|
|
25
|
-
* Extends the core tool contract with
|
|
26
|
-
*
|
|
27
|
-
* browser and require
|
|
28
|
-
* tools execute server-side and may omit a renderer.
|
|
29
|
-
* required for frontend and human tools and optional for backend tools.
|
|
53
|
+
* Extends the core tool contract with tool-call display options. Human tools
|
|
54
|
+
* rely on `render` to collect input from the user. Frontend tools execute in
|
|
55
|
+
* the browser and require either `render` or `renderText` for their progress
|
|
56
|
+
* and result. Backend tools execute server-side and may omit a renderer.
|
|
30
57
|
*/
|
|
31
|
-
type ToolDefinition<TArgs extends Record<string, unknown>, TResult> = WithRender<Tool<TArgs, TResult>, TArgs, TResult>;
|
|
58
|
+
type ToolDefinition<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = WithRender<Tool<TArgs, TResult>, TArgs, TResult>;
|
|
32
59
|
/**
|
|
33
60
|
* Named collection of tools exposed to the assistant model.
|
|
34
61
|
*
|
|
@@ -52,23 +79,43 @@ type Toolkit = Record<string, ToolDefinition<any, any>>;
|
|
|
52
79
|
* A tool as authored, before the build splits it: like {@link ToolDefinition}
|
|
53
80
|
* but it may declare `description`, `parameters`, and a server-side `execute`
|
|
54
81
|
* alongside its `render`. The `type` field is **not** authored — the
|
|
55
|
-
* `"use generative"` compiler infers it (`execute:
|
|
56
|
-
*
|
|
57
|
-
*
|
|
82
|
+
* `"use generative"` compiler infers it (`execute: hitlTool()` → human;
|
|
83
|
+
* `execute: providerTool(...)` → provider; `execute` with a `"use client"`
|
|
84
|
+
* directive → frontend; otherwise backend) and writes it back — so declaring it
|
|
85
|
+
* here is a type error.
|
|
58
86
|
*/
|
|
59
|
-
type
|
|
87
|
+
type OverrideOptionalField<T, TKey extends keyof T, TValue> = undefined extends T[TKey] ? Exclude<T[TKey], undefined> extends never ? { [K in TKey]?: undefined } : { [K in TKey]?: TValue | undefined } : { [K in TKey]: TValue };
|
|
88
|
+
type OverrideToolDeclarationCallbacks<T extends {
|
|
89
|
+
streamCall?: unknown;
|
|
90
|
+
}, TArgs extends Record<string, unknown>, TResult> = Omit<T, "type" | "execute" | "toModelOutput" | "experimental_onSchemaValidationError" | "streamCall"> & {
|
|
60
91
|
type?: never;
|
|
92
|
+
} & ("execute" extends keyof T ? OverrideOptionalField<T, "execute", ToolExecute<NoInfer<TArgs>, TResult>> : {}) & ("toModelOutput" extends keyof T ? OverrideOptionalField<T, "toModelOutput", ToolModelOutputFunction<NoInfer<TArgs>, NoInfer<TResult>>> : {}) & ("experimental_onSchemaValidationError" extends keyof T ? OverrideOptionalField<T, "experimental_onSchemaValidationError", (args: unknown, context: ToolExecuteContext) => NoInfer<TResult> | Promise<NoInfer<TResult>>> : {}) & OverrideOptionalField<T, "streamCall", ToolStreamCall<TArgs, NoInfer<TResult>>>;
|
|
93
|
+
type ToolkitDefinitionInput<TArgs extends Record<string, unknown>, TResult> = WithRender<ToolDeclaration<TArgs, TResult> extends infer T ? T extends {
|
|
94
|
+
streamCall?: unknown;
|
|
95
|
+
} ? OverrideToolDeclarationCallbacks<T, TArgs, TResult> : never : never, TArgs, TResult>;
|
|
96
|
+
/**
|
|
97
|
+
* A single entry in a {@link ToolkitDefinition}.
|
|
98
|
+
*
|
|
99
|
+
* Either authored inline (whose `type` the compiler infers) or an already-formed
|
|
100
|
+
* {@link ToolDefinition} produced by a factory whose own build splits it across
|
|
101
|
+
* targets — e.g. `new JSONGenerativeUI({ library }).present()`. The factory case
|
|
102
|
+
* carries a `type`, so it can only match the {@link ToolDefinition} arm of this
|
|
103
|
+
* union.
|
|
104
|
+
*/
|
|
105
|
+
type ToolkitDefinitionEntry<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolkitDefinitionInput<TArgs, TResult> | ToolDefinition<any, any>;
|
|
106
|
+
type ToolkitDefinitionEntryWithParameters<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolkitDefinitionInput<TArgs, TResult> & {
|
|
107
|
+
parameters: NonNullable<ToolParameters<TArgs>>;
|
|
61
108
|
};
|
|
62
109
|
/**
|
|
63
110
|
* The permissive, authoring-time counterpart to {@link Toolkit} — the input to
|
|
64
111
|
* {@link defineToolkit}. Backend entries may carry their server `execute` here;
|
|
65
112
|
* the canonical {@link Toolkit} keeps those fields `undefined`.
|
|
66
113
|
*/
|
|
67
|
-
type
|
|
114
|
+
type ToolkitDefinition<TArgsByName extends { [K in keyof TArgsByName]: Record<string, unknown> } = Record<string, any>, TResultByName extends { [K in keyof TArgsByName]: unknown } = { [K in keyof TArgsByName]: any }> = { [K in keyof TArgsByName]: ToolkitDefinitionEntry<TArgsByName[K], TResultByName[K]> };
|
|
68
115
|
/** Configuration for the {@link Tools} resource. */
|
|
69
116
|
type ToolsConfig = {
|
|
70
117
|
/** Tools to register with model context and, when provided, message renderers. */toolkit: Toolkit;
|
|
71
118
|
};
|
|
72
119
|
//#endregion
|
|
73
|
-
export { ToolDefinition, Toolkit,
|
|
120
|
+
export { ToolCallText, ToolDefinition, Toolkit, ToolkitDefinition, ToolkitDefinitionEntry, ToolkitDefinitionEntryWithParameters, ToolsConfig, isStandaloneToolDisplay, makeToolCallTextComponent };
|
|
74
121
|
//# sourceMappingURL=toolbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbox.d.ts","names":[],"sources":["../../../src/react/model-context/toolbox.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"toolbox.d.ts","names":[],"sources":["../../../src/react/model-context/toolbox.ts"],"mappings":"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"}
|
|
@@ -12,7 +12,25 @@ const isStandaloneToolDisplay = (tool) => {
|
|
|
12
12
|
if (tool.display !== void 0) return tool.display === "standalone";
|
|
13
13
|
return tool.type === "human";
|
|
14
14
|
};
|
|
15
|
+
const resolveToolCallText = (text, part) => {
|
|
16
|
+
if (!(part.status?.type === "running" || part.status?.type === "requires-action")) {
|
|
17
|
+
const value = text.complete;
|
|
18
|
+
if (typeof value !== "function") return value ?? null;
|
|
19
|
+
return value({
|
|
20
|
+
args: part.args,
|
|
21
|
+
result: part.result
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const value = text.running;
|
|
25
|
+
if (typeof value !== "function") return value ?? null;
|
|
26
|
+
return value({ args: part.args });
|
|
27
|
+
};
|
|
28
|
+
const makeToolCallTextComponent = (text) => {
|
|
29
|
+
return function ToolCallTextComponent(part) {
|
|
30
|
+
return resolveToolCallText(text, part);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
15
33
|
//#endregion
|
|
16
|
-
export { isStandaloneToolDisplay };
|
|
34
|
+
export { isStandaloneToolDisplay, makeToolCallTextComponent };
|
|
17
35
|
|
|
18
36
|
//# sourceMappingURL=toolbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbox.js","names":[],"sources":["../../../src/react/model-context/toolbox.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"toolbox.js","names":[],"sources":["../../../src/react/model-context/toolbox.ts"],"sourcesContent":["import type {\n Tool,\n ToolCallReader,\n ToolDeclaration,\n ToolModelOutputFunction,\n} from \"assistant-stream\";\nimport type { ReactNode } from \"react\";\nimport type {\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n} from \"../types/MessagePartComponentTypes\";\n\n/**\n * Resolves whether a tool's UI should be presented standalone (outside the\n * chain-of-thought grouping), applying the type-based defaults.\n *\n * An explicit `display` wins. Otherwise `human` tools default to standalone\n * (they prompt the user), and every other tool defaults to inline (a trace of\n * what the model is doing). MCP-app tool calls are detected separately from\n * the part itself and are not resolved here.\n */\nexport const isStandaloneToolDisplay = (\n tool: Pick<Tool<any, any>, \"type\" | \"display\">,\n): boolean => {\n if (tool.display !== undefined) return tool.display === \"standalone\";\n return tool.type === \"human\";\n};\n\ntype WithRender<T, TArgs extends Record<string, unknown>, TResult> = T extends {\n type: \"frontend\" | \"human\";\n}\n ? T &\n (T extends { type: \"frontend\" }\n ?\n | { render: ToolCallMessagePartComponent<TArgs, TResult> }\n | {\n render?: ToolCallMessagePartComponent<TArgs, TResult>;\n renderText: ToolCallText<TArgs, TResult>;\n }\n : { render: ToolCallMessagePartComponent<TArgs, TResult> })\n : T & {\n render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;\n renderText?: ToolCallText<TArgs, TResult> | undefined;\n };\n\ntype ToolParameters<TArgs extends Record<string, unknown>> =\n ToolDeclaration<TArgs>[\"parameters\"];\n\n// ToolExecutionContext is not re-exported from assistant-stream's public entry.\ntype ToolExecuteContext = Parameters<\n NonNullable<ToolDeclaration[\"execute\"]>\n>[1];\n\ntype ToolExecute<TArgs extends Record<string, unknown>, TResult> = (\n args: TArgs,\n context: ToolExecuteContext,\n) => TResult | Promise<TResult>;\n\ntype ToolStreamCall<TArgs extends Record<string, unknown>, TResult> = (\n reader: ToolCallReader<TArgs, TResult>,\n context: ToolExecuteContext,\n) => void;\n\ntype ToolCallRunningText<TArgs extends Record<string, unknown>> =\n | ReactNode\n | ((options: { args: TArgs }) => ReactNode);\n\ntype ToolCallCompleteText<TArgs extends Record<string, unknown>, TResult> =\n | ReactNode\n | ((options: { args: TArgs; result: TResult | undefined }) => ReactNode);\n\nexport type ToolCallText<TArgs extends Record<string, unknown>, TResult> =\n | {\n running: ToolCallRunningText<TArgs>;\n complete?: ToolCallCompleteText<TArgs, TResult> | undefined;\n }\n | {\n running?: ToolCallRunningText<TArgs> | undefined;\n complete: ToolCallCompleteText<TArgs, TResult>;\n };\n\nconst resolveToolCallText = <TArgs extends Record<string, unknown>, TResult>(\n text: ToolCallText<TArgs, TResult>,\n part: ToolCallMessagePartProps<TArgs, TResult>,\n): ReactNode => {\n const isRunning =\n part.status?.type === \"running\" || part.status?.type === \"requires-action\";\n\n if (!isRunning) {\n const value = text.complete;\n if (typeof value !== \"function\") return value ?? null;\n return value({ args: part.args, result: part.result });\n }\n\n const value = text.running;\n if (typeof value !== \"function\") return value ?? null;\n return value({ args: part.args });\n};\n\nexport const makeToolCallTextComponent = <\n TArgs extends Record<string, unknown>,\n TResult,\n>(\n text: ToolCallText<TArgs, TResult>,\n): ToolCallMessagePartComponent<TArgs, TResult> => {\n return function ToolCallTextComponent(part) {\n return resolveToolCallText(text, part);\n };\n};\n\n/**\n * Tool definition accepted by the React tool registry.\n *\n * Extends the core tool contract with tool-call display options. Human tools\n * rely on `render` to collect input from the user. Frontend tools execute in\n * the browser and require either `render` or `renderText` for their progress\n * and result. Backend tools execute server-side and may omit a renderer.\n */\nexport type ToolDefinition<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = WithRender<Tool<TArgs, TResult>, TArgs, TResult>;\n\n/**\n * Named collection of tools exposed to the assistant model.\n *\n * Keys are the tool names the model receives and uses in tool calls.\n *\n * @example\n * ```tsx\n * const toolkit = {\n * get_weather: {\n * type: \"frontend\",\n * description: \"Get the weather for a city.\",\n * parameters: weatherSchema,\n * execute: async ({ city }: { city: string }) => fetchWeather(city),\n * render: WeatherToolUI,\n * },\n * } satisfies Toolkit;\n * ```\n */\nexport type Toolkit = Record<string, ToolDefinition<any, any>>;\n\n/**\n * A tool as authored, before the build splits it: like {@link ToolDefinition}\n * but it may declare `description`, `parameters`, and a server-side `execute`\n * alongside its `render`. The `type` field is **not** authored — the\n * `\"use generative\"` compiler infers it (`execute: hitlTool()` → human;\n * `execute: providerTool(...)` → provider; `execute` with a `\"use client\"`\n * directive → frontend; otherwise backend) and writes it back — so declaring it\n * here is a type error.\n */\ntype OverrideOptionalField<\n T,\n TKey extends keyof T,\n TValue,\n> = undefined extends T[TKey]\n ? // Preserve `?: undefined` fields (for variants that explicitly disallow a\n // callback) instead of widening them to accept the override value.\n Exclude<T[TKey], undefined> extends never\n ? { [K in TKey]?: undefined }\n : { [K in TKey]?: TValue | undefined }\n : { [K in TKey]: TValue };\n\ntype OverrideToolDeclarationCallbacks<\n T extends { streamCall?: unknown },\n TArgs extends Record<string, unknown>,\n TResult,\n> = Omit<\n T,\n | \"type\"\n | \"execute\"\n | \"toModelOutput\"\n | \"experimental_onSchemaValidationError\"\n | \"streamCall\"\n> & {\n type?: never;\n} & (\"execute\" extends keyof T\n ? OverrideOptionalField<T, \"execute\", ToolExecute<NoInfer<TArgs>, TResult>>\n : {}) &\n (\"toModelOutput\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"toModelOutput\",\n ToolModelOutputFunction<NoInfer<TArgs>, NoInfer<TResult>>\n >\n : {}) &\n (\"experimental_onSchemaValidationError\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"experimental_onSchemaValidationError\",\n (\n args: unknown,\n context: ToolExecuteContext,\n ) => NoInfer<TResult> | Promise<NoInfer<TResult>>\n >\n : {}) &\n OverrideOptionalField<\n T,\n \"streamCall\",\n ToolStreamCall<TArgs, NoInfer<TResult>>\n >;\n\n// Keep the authored shape tied to ToolDeclaration's union variants while\n// overriding callback fields to avoid inference pollution.\ntype ToolkitDefinitionInput<\n TArgs extends Record<string, unknown>,\n TResult,\n> = WithRender<\n ToolDeclaration<TArgs, TResult> extends infer T\n ? T extends { streamCall?: unknown }\n ? OverrideToolDeclarationCallbacks<T, TArgs, TResult>\n : never\n : never,\n TArgs,\n TResult\n>;\n\n/**\n * A single entry in a {@link ToolkitDefinition}.\n *\n * Either authored inline (whose `type` the compiler infers) or an already-formed\n * {@link ToolDefinition} produced by a factory whose own build splits it across\n * targets — e.g. `new JSONGenerativeUI({ library }).present()`. The factory case\n * carries a `type`, so it can only match the {@link ToolDefinition} arm of this\n * union.\n */\nexport type ToolkitDefinitionEntry<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> | ToolDefinition<any, any>;\n\nexport type ToolkitDefinitionEntryWithParameters<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> & {\n parameters: NonNullable<ToolParameters<TArgs>>;\n};\n\n/**\n * The permissive, authoring-time counterpart to {@link Toolkit} — the input to\n * {@link defineToolkit}. Backend entries may carry their server `execute` here;\n * the canonical {@link Toolkit} keeps those fields `undefined`.\n */\nexport type ToolkitDefinition<\n TArgsByName extends {\n [K in keyof TArgsByName]: Record<string, unknown>;\n } = Record<string, any>,\n TResultByName extends { [K in keyof TArgsByName]: unknown } = {\n [K in keyof TArgsByName]: any;\n },\n> = {\n [K in keyof TArgsByName]: ToolkitDefinitionEntry<\n TArgsByName[K],\n TResultByName[K]\n >;\n};\n\n/** Configuration for the {@link Tools} resource. */\nexport type ToolsConfig = {\n /** Tools to register with model context and, when provided, message renderers. */\n toolkit: Toolkit;\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAa,2BACX,SACY;CACZ,IAAI,KAAK,YAAY,KAAA,GAAW,OAAO,KAAK,YAAY;CACxD,OAAO,KAAK,SAAS;AACvB;AAuDA,MAAM,uBACJ,MACA,SACc;CAId,IAAI,EAFF,KAAK,QAAQ,SAAS,aAAa,KAAK,QAAQ,SAAS,oBAE3C;EACd,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS;EACjD,OAAO,MAAM;GAAE,MAAM,KAAK;GAAM,QAAQ,KAAK;EAAO,CAAC;CACvD;CAEA,MAAM,QAAQ,KAAK;CACnB,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS;CACjD,OAAO,MAAM,EAAE,MAAM,KAAK,KAAK,CAAC;AAClC;AAEA,MAAa,6BAIX,SACiD;CACjD,OAAO,SAAS,sBAAsB,MAAM;EAC1C,OAAO,oBAAoB,MAAM,IAAI;CACvC;AACF"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { AssistantToolProps as AssistantToolProps$1 } from "../../model-context/types.js";
|
|
2
2
|
import { ToolCallMessagePartComponent } from "../types/MessagePartComponentTypes.js";
|
|
3
|
+
import { ToolCallText } from "./toolbox.js";
|
|
3
4
|
|
|
4
5
|
//#region src/react/model-context/useAssistantTool.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Props used to register a tool from React.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use a toolkit with `Tools({ toolkit })` and register it via
|
|
10
|
+
* `useAui({ tools: Tools({ toolkit }) })` instead. See
|
|
11
|
+
* https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
7
12
|
*/
|
|
8
13
|
type AssistantToolProps<TArgs extends Record<string, unknown>, TResult> = AssistantToolProps$1<TArgs, TResult> & {
|
|
9
|
-
/** Component used to render calls to this tool in assistant messages. */render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;
|
|
14
|
+
/** Component used to render calls to this tool in assistant messages. */render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined; /** Lightweight text rendered while a tool call is running or complete. */
|
|
15
|
+
renderText?: ToolCallText<TArgs, TResult> | undefined;
|
|
10
16
|
};
|
|
11
17
|
/**
|
|
12
18
|
* Registers a tool with the assistant model context while the component is
|
|
@@ -21,6 +27,10 @@ type AssistantToolProps<TArgs extends Record<string, unknown>, TResult> = Assist
|
|
|
21
27
|
*
|
|
22
28
|
* @param tool - Tool definition and name to register.
|
|
23
29
|
*
|
|
30
|
+
* @deprecated Use a toolkit with `Tools({ toolkit })` and register it via
|
|
31
|
+
* `useAui({ tools: Tools({ toolkit }) })` instead. See
|
|
32
|
+
* https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
33
|
+
*
|
|
24
34
|
* @example
|
|
25
35
|
* ```tsx
|
|
26
36
|
* const weatherTool = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantTool.d.ts","names":[],"sources":["../../../src/react/model-context/useAssistantTool.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAssistantTool.d.ts","names":[],"sources":["../../../src/react/model-context/useAssistantTool.ts"],"mappings":";;;;;;;;AAiBA;;;;KAAY,kBAAA,eACI,MAAA,8BAEZ,oBAAA,CAAuB,KAAA,EAAO,OAAA;EAAA,yEAEhC,MAAA,GAAS,4BAAA,CAA6B,KAAA,EAAO,OAAA,eAAP;EAEtC,UAAA,GAAa,YAAA,CAAa,KAAA,EAAO,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;AAAO;AAqC1C;;;;;;;;;;;;;cAAa,gBAAA,iBACG,MAAA,4BAGd,IAAA,EAAM,kBAAA,CAAmB,KAAA,EAAO,OAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isStandaloneToolDisplay } from "./toolbox.js";
|
|
2
|
-
import { useEffect } from "react";
|
|
1
|
+
import { isStandaloneToolDisplay, makeToolCallTextComponent } from "./toolbox.js";
|
|
2
|
+
import { useEffect, useMemo } from "react";
|
|
3
3
|
import { useAui } from "@assistant-ui/store";
|
|
4
4
|
//#region src/react/model-context/useAssistantTool.ts
|
|
5
5
|
/**
|
|
@@ -15,6 +15,10 @@ import { useAui } from "@assistant-ui/store";
|
|
|
15
15
|
*
|
|
16
16
|
* @param tool - Tool definition and name to register.
|
|
17
17
|
*
|
|
18
|
+
* @deprecated Use a toolkit with `Tools({ toolkit })` and register it via
|
|
19
|
+
* `useAui({ tools: Tools({ toolkit }) })` instead. See
|
|
20
|
+
* https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
21
|
+
*
|
|
18
22
|
* @example
|
|
19
23
|
* ```tsx
|
|
20
24
|
* const weatherTool = {
|
|
@@ -35,17 +39,19 @@ import { useAui } from "@assistant-ui/store";
|
|
|
35
39
|
const useAssistantTool = (tool) => {
|
|
36
40
|
const aui = useAui();
|
|
37
41
|
const standalone = isStandaloneToolDisplay(tool);
|
|
42
|
+
const renderTextComponent = useMemo(() => tool.renderText ? makeToolCallTextComponent(tool.renderText) : void 0, [tool.renderText]);
|
|
43
|
+
const render = tool.render ?? renderTextComponent;
|
|
38
44
|
useEffect(() => {
|
|
39
|
-
if (!
|
|
40
|
-
return aui.tools().setToolUI(tool.toolName,
|
|
45
|
+
if (!render) return void 0;
|
|
46
|
+
return aui.tools().setToolUI(tool.toolName, render, { standalone });
|
|
41
47
|
}, [
|
|
42
48
|
aui,
|
|
43
49
|
tool.toolName,
|
|
44
|
-
|
|
50
|
+
render,
|
|
45
51
|
standalone
|
|
46
52
|
]);
|
|
47
53
|
useEffect(() => {
|
|
48
|
-
const { toolName, render, display, ...rest } = tool;
|
|
54
|
+
const { toolName, render, renderText, display, ...rest } = tool;
|
|
49
55
|
const context = { tools: { [toolName]: rest } };
|
|
50
56
|
return aui.modelContext().register({ getModelContext: () => context });
|
|
51
57
|
}, [aui, tool]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantTool.js","names":[],"sources":["../../../src/react/model-context/useAssistantTool.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { ToolCallMessagePartComponent } from \"../types/MessagePartComponentTypes\";\nimport type { AssistantToolProps as CoreAssistantToolProps } from \"../..\";\nimport {
|
|
1
|
+
{"version":3,"file":"useAssistantTool.js","names":[],"sources":["../../../src/react/model-context/useAssistantTool.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { ToolCallMessagePartComponent } from \"../types/MessagePartComponentTypes\";\nimport type { AssistantToolProps as CoreAssistantToolProps } from \"../..\";\nimport {\n isStandaloneToolDisplay,\n makeToolCallTextComponent,\n type ToolCallText,\n} from \"./toolbox\";\n\n/**\n * Props used to register a tool from React.\n *\n * @deprecated Use a toolkit with `Tools({ toolkit })` and register it via\n * `useAui({ tools: Tools({ toolkit }) })` instead. See\n * https://assistant-ui.com/docs/migrations/toolkit-tools.\n */\nexport type AssistantToolProps<\n TArgs extends Record<string, unknown>,\n TResult,\n> = CoreAssistantToolProps<TArgs, TResult> & {\n /** Component used to render calls to this tool in assistant messages. */\n render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;\n /** Lightweight text rendered while a tool call is running or complete. */\n renderText?: ToolCallText<TArgs, TResult> | undefined;\n};\n\n/**\n * Registers a tool with the assistant model context while the component is\n * mounted.\n *\n * If `render` is provided, it is also installed as the renderer for matching\n * tool-call message parts. The registration is removed automatically when the\n * component unmounts or the tool definition changes.\n *\n * Pass a referentially stable tool object, such as one declared at module\n * scope or memoized with `useMemo`, to avoid re-registering on every render.\n *\n * @param tool - Tool definition and name to register.\n *\n * @deprecated Use a toolkit with `Tools({ toolkit })` and register it via\n * `useAui({ tools: Tools({ toolkit }) })` instead. See\n * https://assistant-ui.com/docs/migrations/toolkit-tools.\n *\n * @example\n * ```tsx\n * const weatherTool = {\n * toolName: \"get_weather\",\n * type: \"frontend\",\n * description: \"Get the weather for a city.\",\n * parameters: weatherSchema,\n * execute: async ({ city }: { city: string }) => fetchWeather(city),\n * render: WeatherToolUI,\n * } satisfies AssistantToolProps<{ city: string }, Weather>;\n *\n * function WeatherToolRegistration() {\n * useAssistantTool(weatherTool);\n * return null;\n * }\n * ```\n */\nexport const useAssistantTool = <\n TArgs extends Record<string, unknown>,\n TResult,\n>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const aui = useAui();\n\n const standalone = isStandaloneToolDisplay(tool);\n const renderTextComponent = useMemo(\n () =>\n tool.renderText ? makeToolCallTextComponent(tool.renderText) : undefined,\n [tool.renderText],\n );\n const render = tool.render ?? renderTextComponent;\n\n useEffect(() => {\n if (!render) return undefined;\n return aui.tools().setToolUI(tool.toolName, render, { standalone });\n }, [aui, tool.toolName, render, standalone]);\n\n useEffect(() => {\n // `render`, `renderText`, and `display` are client-only presentation\n // concerns and never reach the model.\n const { toolName, render, renderText, display, ...rest } = tool;\n const context = {\n tools: {\n [toolName]: rest,\n },\n };\n return aui.modelContext().register({\n getModelContext: () => context,\n });\n }, [aui, tool]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAa,oBAIX,SACG;CACH,MAAM,MAAM,OAAO;CAEnB,MAAM,aAAa,wBAAwB,IAAI;CAC/C,MAAM,sBAAsB,cAExB,KAAK,aAAa,0BAA0B,KAAK,UAAU,IAAI,KAAA,GACjE,CAAC,KAAK,UAAU,CAClB;CACA,MAAM,SAAS,KAAK,UAAU;CAE9B,gBAAgB;EACd,IAAI,CAAC,QAAQ,OAAO,KAAA;EACpB,OAAO,IAAI,MAAM,EAAE,UAAU,KAAK,UAAU,QAAQ,EAAE,WAAW,CAAC;CACpE,GAAG;EAAC;EAAK,KAAK;EAAU;EAAQ;CAAU,CAAC;CAE3C,gBAAgB;EAGd,MAAM,EAAE,UAAU,QAAQ,YAAY,SAAS,GAAG,SAAS;EAC3D,MAAM,UAAU,EACd,OAAO,GACJ,WAAW,KACd,EACF;EACA,OAAO,IAAI,aAAa,EAAE,SAAS,EACjC,uBAAuB,QACzB,CAAC;CACH,GAAG,CAAC,KAAK,IAAI,CAAC;AAChB"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { ToolCallMessagePartComponent } from "../types/MessagePartComponentTypes.js";
|
|
2
2
|
|
|
3
3
|
//#region src/react/model-context/useAssistantToolUI.d.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Props used to register a renderer for tool-call message parts.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Put `render`/`renderText` on the matching toolkit entry, or use
|
|
8
|
+
* `MessagePrimitive.Parts` inline tool render overrides for per-message UI.
|
|
9
|
+
* See https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
10
|
+
*/
|
|
5
11
|
type AssistantToolUIProps<TArgs, TResult> = {
|
|
6
12
|
/** Name of the tool whose calls should use this renderer. */toolName: string; /** Component rendered for matching tool-call message parts. */
|
|
7
13
|
render: ToolCallMessagePartComponent<TArgs, TResult>;
|
|
@@ -15,11 +21,14 @@ type AssistantToolUIProps<TArgs, TResult> = {
|
|
|
15
21
|
/**
|
|
16
22
|
* Registers a tool-call renderer while the component is mounted.
|
|
17
23
|
*
|
|
18
|
-
* This only affects rendering. Pair it with {@link
|
|
19
|
-
*
|
|
20
|
-
* definition to the model.
|
|
24
|
+
* This only affects rendering. Pair it with {@link Tools} or a backend tool
|
|
25
|
+
* registry to expose the actual tool definition to the model.
|
|
21
26
|
*
|
|
22
27
|
* @param tool - Tool renderer registration, or `null` to skip registration.
|
|
28
|
+
*
|
|
29
|
+
* @deprecated Put `render`/`renderText` on the matching toolkit entry, or use
|
|
30
|
+
* `MessagePrimitive.Parts` inline tool render overrides for per-message UI.
|
|
31
|
+
* See https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
23
32
|
*/
|
|
24
33
|
declare const useAssistantToolUI: (tool: AssistantToolUIProps<any, any> | null) => void;
|
|
25
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantToolUI.d.ts","names":[],"sources":["../../../src/react/model-context/useAssistantToolUI.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAssistantToolUI.d.ts","names":[],"sources":["../../../src/react/model-context/useAssistantToolUI.ts"],"mappings":";;;;;AAWA;;;;;KAAY,oBAAA;EAI0B,6DAFpC,QAAA,UAF+B;EAI/B,MAAA,EAAQ,4BAAA,CAA6B,KAAA,EAAO,OAAA;EAF5C;;;;;EAQA,OAAA;AAAA;AAAO;AAeT;;;;AAC6C;;;;;;;AAhBpC,cAeI,kBAAA,GACX,IAA2C,EAArC,oBAAoB"}
|
|
@@ -4,11 +4,14 @@ import { useAui } from "@assistant-ui/store";
|
|
|
4
4
|
/**
|
|
5
5
|
* Registers a tool-call renderer while the component is mounted.
|
|
6
6
|
*
|
|
7
|
-
* This only affects rendering. Pair it with {@link
|
|
8
|
-
*
|
|
9
|
-
* definition to the model.
|
|
7
|
+
* This only affects rendering. Pair it with {@link Tools} or a backend tool
|
|
8
|
+
* registry to expose the actual tool definition to the model.
|
|
10
9
|
*
|
|
11
10
|
* @param tool - Tool renderer registration, or `null` to skip registration.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Put `render`/`renderText` on the matching toolkit entry, or use
|
|
13
|
+
* `MessagePrimitive.Parts` inline tool render overrides for per-message UI.
|
|
14
|
+
* See https://assistant-ui.com/docs/migrations/toolkit-tools.
|
|
12
15
|
*/
|
|
13
16
|
const useAssistantToolUI = (tool) => {
|
|
14
17
|
const aui = useAui();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantToolUI.js","names":[],"sources":["../../../src/react/model-context/useAssistantToolUI.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { ToolCallMessagePartComponent } from \"../types/MessagePartComponentTypes\";\n\n
|
|
1
|
+
{"version":3,"file":"useAssistantToolUI.js","names":[],"sources":["../../../src/react/model-context/useAssistantToolUI.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { ToolCallMessagePartComponent } from \"../types/MessagePartComponentTypes\";\n\n/**\n * Props used to register a renderer for tool-call message parts.\n *\n * @deprecated Put `render`/`renderText` on the matching toolkit entry, or use\n * `MessagePrimitive.Parts` inline tool render overrides for per-message UI.\n * See https://assistant-ui.com/docs/migrations/toolkit-tools.\n */\nexport type AssistantToolUIProps<TArgs, TResult> = {\n /** Name of the tool whose calls should use this renderer. */\n toolName: string;\n /** Component rendered for matching tool-call message parts. */\n render: ToolCallMessagePartComponent<TArgs, TResult>;\n /**\n * How the UI is presented relative to the chain-of-thought trace. Set\n * `\"standalone\"` to surface it on its own (e.g. human-in-the-loop or\n * generative UI for a backend/MCP tool). Defaults to `\"inline\"`.\n */\n display?: \"standalone\" | \"inline\";\n};\n\n/**\n * Registers a tool-call renderer while the component is mounted.\n *\n * This only affects rendering. Pair it with {@link Tools} or a backend tool\n * registry to expose the actual tool definition to the model.\n *\n * @param tool - Tool renderer registration, or `null` to skip registration.\n *\n * @deprecated Put `render`/`renderText` on the matching toolkit entry, or use\n * `MessagePrimitive.Parts` inline tool render overrides for per-message UI.\n * See https://assistant-ui.com/docs/migrations/toolkit-tools.\n */\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const aui = useAui();\n const standalone = tool?.display === \"standalone\";\n useEffect(() => {\n if (!tool?.toolName || !tool?.render) return undefined;\n return aui.tools().setToolUI(tool.toolName, tool.render, { standalone });\n }, [aui, tool?.toolName, tool?.render, standalone]);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,MAAa,sBACX,SACG;CACH,MAAM,MAAM,OAAO;CACnB,MAAM,aAAa,MAAM,YAAY;CACrC,gBAAgB;EACd,IAAI,CAAC,MAAM,YAAY,CAAC,MAAM,QAAQ,OAAO,KAAA;EAC7C,OAAO,IAAI,MAAM,EAAE,UAAU,KAAK,UAAU,KAAK,QAAQ,EAAE,WAAW,CAAC;CACzE,GAAG;EAAC;EAAK,MAAM;EAAU,MAAM;EAAQ;CAAU,CAAC;AACpD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Tool } from "assistant-stream";
|
|
2
|
+
|
|
3
|
+
//#region src/react/model-context/useAuiToolOverrides.d.ts
|
|
4
|
+
type AuiToolOverride<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = Partial<Tool<TArgs, TResult>>;
|
|
5
|
+
type AuiToolOverrides = Record<string, AuiToolOverride<any, any>>;
|
|
6
|
+
/**
|
|
7
|
+
* Overrides toolkit entries for the current assistant scope.
|
|
8
|
+
*
|
|
9
|
+
* This is intended for dynamic local-state tools whose model-facing contract is
|
|
10
|
+
* declared in a `"use generative"` toolkit file with `execute: stubTool()`, but
|
|
11
|
+
* whose actual executor must close over React state in the mounted component.
|
|
12
|
+
* Keep the override keys stable after mount; dynamic key addition/removal is not
|
|
13
|
+
* currently observed.
|
|
14
|
+
* Overrides are registered at priority 1000, above toolkit defaults. Only one
|
|
15
|
+
* mounted override provider may define a given tool name at a time.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Experimental, API may change.
|
|
18
|
+
*/
|
|
19
|
+
declare function useAuiToolOverrides(overrides: AuiToolOverrides): void;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useAuiToolOverrides };
|
|
22
|
+
//# sourceMappingURL=useAuiToolOverrides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuiToolOverrides.d.ts","names":[],"sources":["../../../src/react/model-context/useAuiToolOverrides.ts"],"mappings":";;;KAIK,eAAA,eACW,MAAA,oBAA0B,MAAA,wCAEtC,OAAA,CAAQ,IAAA,CAAK,KAAA,EAAO,OAAA;AAAA,KAEnB,gBAAA,GAAmB,MAAM,SAAS,eAAA;AAPM;;;;;;;;;;;;;AAAA,iBAsB7B,mBAAA,CAAoB,SAA2B,EAAhB,gBAAgB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useAui } from "@assistant-ui/store";
|
|
3
|
+
//#region src/react/model-context/useAuiToolOverrides.ts
|
|
4
|
+
/**
|
|
5
|
+
* Overrides toolkit entries for the current assistant scope.
|
|
6
|
+
*
|
|
7
|
+
* This is intended for dynamic local-state tools whose model-facing contract is
|
|
8
|
+
* declared in a `"use generative"` toolkit file with `execute: stubTool()`, but
|
|
9
|
+
* whose actual executor must close over React state in the mounted component.
|
|
10
|
+
* Keep the override keys stable after mount; dynamic key addition/removal is not
|
|
11
|
+
* currently observed.
|
|
12
|
+
* Overrides are registered at priority 1000, above toolkit defaults. Only one
|
|
13
|
+
* mounted override provider may define a given tool name at a time.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated Experimental, API may change.
|
|
16
|
+
*/
|
|
17
|
+
function useAuiToolOverrides(overrides) {
|
|
18
|
+
const aui = useAui();
|
|
19
|
+
const overridesRef = useRef(overrides);
|
|
20
|
+
overridesRef.current = overrides;
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
return aui.modelContext().register({ getModelContext: () => ({
|
|
23
|
+
priority: 1e3,
|
|
24
|
+
tools: overridesRef.current
|
|
25
|
+
}) });
|
|
26
|
+
}, [aui]);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useAuiToolOverrides };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=useAuiToolOverrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuiToolOverrides.js","names":[],"sources":["../../../src/react/model-context/useAuiToolOverrides.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { Tool } from \"assistant-stream\";\n\ntype AuiToolOverride<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = Partial<Tool<TArgs, TResult>>;\n\ntype AuiToolOverrides = Record<string, AuiToolOverride<any, any>>;\n\n/**\n * Overrides toolkit entries for the current assistant scope.\n *\n * This is intended for dynamic local-state tools whose model-facing contract is\n * declared in a `\"use generative\"` toolkit file with `execute: stubTool()`, but\n * whose actual executor must close over React state in the mounted component.\n * Keep the override keys stable after mount; dynamic key addition/removal is not\n * currently observed.\n * Overrides are registered at priority 1000, above toolkit defaults. Only one\n * mounted override provider may define a given tool name at a time.\n *\n * @deprecated Experimental, API may change.\n */\nexport function useAuiToolOverrides(overrides: AuiToolOverrides): void {\n const aui = useAui();\n const overridesRef = useRef(overrides);\n overridesRef.current = overrides;\n\n useEffect(() => {\n return aui.modelContext().register({\n getModelContext: () => ({\n priority: 1000,\n tools: overridesRef.current as Record<string, Tool<any, any>>,\n }),\n });\n }, [aui]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,SAAgB,oBAAoB,WAAmC;CACrE,MAAM,MAAM,OAAO;CACnB,MAAM,eAAe,OAAO,SAAS;CACrC,aAAa,UAAU;CAEvB,gBAAgB;EACd,OAAO,IAAI,aAAa,EAAE,SAAS,EACjC,wBAAwB;GACtB,UAAU;GACV,OAAO,aAAa;EACtB,GACF,CAAC;CACH,GAAG,CAAC,GAAG,CAAC;AACV"}
|
|
@@ -20,17 +20,19 @@ declare namespace PartPrimitiveMessages {
|
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```tsx
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
23
|
+
* const toolkit = {
|
|
24
|
+
* invoke_sub_agent: {
|
|
25
|
+
* type: "backend",
|
|
26
|
+
* render: () => (
|
|
27
|
+
* <PartPrimitive.Messages>
|
|
28
|
+
* {({ message }) => {
|
|
29
|
+
* if (message.role === "user") return <MyUserMessage />;
|
|
30
|
+
* return <MyAssistantMessage />;
|
|
31
|
+
* }}
|
|
32
|
+
* </PartPrimitive.Messages>
|
|
33
|
+
* ),
|
|
34
|
+
* },
|
|
35
|
+
* } satisfies Toolkit;
|
|
34
36
|
* ```
|
|
35
37
|
*/
|
|
36
38
|
declare const PartPrimitiveMessagesImpl: FC<PartPrimitiveMessages.Props>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"mappings":";;;;;kBASiB,qBAAA;EAAA,KACH,KAAA;IACV,UAAA,GAAa,uBAAA,CAAwB,KAAA,gBAFH;IAIlC,QAAA,IAAY,KAAA;MAAS,OAAA,EAAS,aAAA;IAAA,MAAoB,SAAA;EAAA;AAAA;;;;;;;;;;;;AAAS;
|
|
1
|
+
{"version":3,"file":"PartMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"mappings":";;;;;kBASiB,qBAAA;EAAA,KACH,KAAA;IACV,UAAA,GAAa,uBAAA,CAAwB,KAAA,gBAFH;IAIlC,QAAA,IAAY,KAAA;MAAS,OAAA,EAAS,aAAA;IAAA,MAAoB,SAAA;EAAA;AAAA;;;;;;;;;;;;AAAS;AAsC/D;;;;;;;;AAAsE;AAyBtE;;;cAzBa,yBAAA,EAA2B,EAAE,CAAC,qBAAA,CAAsB,KAAA;AAAA,cAyBpD,qBAAA,kBAAqB,oBAAA,CAAA,qBAAA,CAAA,KAAA"}
|
|
@@ -20,17 +20,19 @@ const usePartMessages = () => {
|
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```tsx
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
23
|
+
* const toolkit = {
|
|
24
|
+
* invoke_sub_agent: {
|
|
25
|
+
* type: "backend",
|
|
26
|
+
* render: () => (
|
|
27
|
+
* <PartPrimitive.Messages>
|
|
28
|
+
* {({ message }) => {
|
|
29
|
+
* if (message.role === "user") return <MyUserMessage />;
|
|
30
|
+
* return <MyAssistantMessage />;
|
|
31
|
+
* }}
|
|
32
|
+
* </PartPrimitive.Messages>
|
|
33
|
+
* ),
|
|
34
|
+
* },
|
|
35
|
+
* } satisfies Toolkit;
|
|
34
36
|
* ```
|
|
35
37
|
*/
|
|
36
38
|
const PartPrimitiveMessagesImpl = ({ components, children }) => {
|