skybridge 0.0.0-dev.c210709 → 0.0.0-dev.c269e58
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/src/server/devtoolsStaticServer.d.ts +15 -0
- package/dist/src/server/devtoolsStaticServer.js +38 -0
- package/dist/src/server/devtoolsStaticServer.js.map +1 -0
- package/dist/src/server/index.d.ts +3 -2
- package/dist/src/server/index.js +1 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/inferUtilityTypes.d.ts +22 -6
- package/dist/src/server/server.d.ts +55 -16
- package/dist/src/server/server.js +54 -34
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +3 -0
- package/dist/src/server/templateHelper.js +5 -4
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +3 -2
- package/dist/src/server/templates/production.hbs +1 -0
- package/dist/src/server/widgetsDevServer.js +3 -3
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/utils.d.ts +54 -8
- package/dist/src/test/utils.js +86 -8
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +83 -27
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/bridges/apps-sdk-adapter.d.ts +2 -0
- package/dist/src/web/bridges/apps-sdk-adapter.js +4 -0
- package/dist/src/web/bridges/apps-sdk-adapter.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +8 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js +41 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/get-bridge-methods.d.ts +2 -0
- package/dist/src/web/bridges/get-bridge-methods.js +8 -0
- package/dist/src/web/bridges/get-bridge-methods.js.map +1 -0
- package/dist/src/web/bridges/hooks/types.d.ts +6 -0
- package/dist/src/web/bridges/hooks/types.js +2 -0
- package/dist/src/web/bridges/hooks/types.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-bridge.js +19 -0
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +4 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +58 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -0
- package/dist/src/web/bridges/index.d.ts +4 -0
- package/dist/src/web/bridges/index.js +5 -0
- package/dist/src/web/bridges/index.js.map +1 -0
- package/dist/src/web/bridges/mcp-app-adapter.d.ts +4 -0
- package/dist/src/web/bridges/mcp-app-adapter.js +44 -0
- package/dist/src/web/bridges/mcp-app-adapter.js.map +1 -0
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +30 -0
- package/dist/src/web/bridges/mcp-app-bridge.js +139 -0
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/types.d.ts +32 -0
- package/dist/src/web/bridges/types.js +2 -0
- package/dist/src/web/bridges/types.js.map +1 -0
- package/dist/src/web/create-store.d.ts +3 -0
- package/dist/src/web/create-store.js +25 -0
- package/dist/src/web/create-store.js.map +1 -0
- package/dist/src/web/create-store.test.js +70 -0
- package/dist/src/web/create-store.test.js.map +1 -0
- package/dist/src/web/data-llm.d.ts +14 -0
- package/dist/src/web/data-llm.js +68 -0
- package/dist/src/web/data-llm.js.map +1 -0
- package/dist/src/web/data-llm.test.js +76 -0
- package/dist/src/web/data-llm.test.js.map +1 -0
- package/dist/src/web/generate-helpers.d.ts +21 -18
- package/dist/src/web/generate-helpers.js +10 -6
- package/dist/src/web/generate-helpers.js.map +1 -1
- package/dist/src/web/generate-helpers.test-d.js +117 -1
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/generate-helpers.test.js +1 -1
- package/dist/src/web/generate-helpers.test.js.map +1 -1
- package/dist/src/web/helpers/state.d.ts +7 -0
- package/dist/src/web/helpers/state.js +40 -0
- package/dist/src/web/helpers/state.js.map +1 -0
- package/dist/src/web/helpers/state.test.d.ts +1 -0
- package/dist/src/web/helpers/state.test.js +53 -0
- package/dist/src/web/helpers/state.test.js.map +1 -0
- package/dist/src/web/hooks/index.d.ts +4 -7
- package/dist/src/web/hooks/index.js +4 -7
- package/dist/src/web/hooks/index.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.d.ts +21 -20
- package/dist/src/web/hooks/use-call-tool.js +7 -15
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +14 -12
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +2 -2
- package/dist/src/web/hooks/use-display-mode.js +6 -3
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js +3 -2
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/src/web/hooks/use-files.test.js +1 -1
- package/dist/src/web/hooks/use-files.test.js.map +1 -1
- package/dist/src/web/hooks/use-layout.d.ts +22 -0
- package/dist/src/web/hooks/use-layout.js +23 -0
- package/dist/src/web/hooks/use-layout.js.map +1 -0
- package/dist/src/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/src/web/hooks/use-layout.test.js +46 -0
- package/dist/src/web/hooks/use-layout.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.test.js +2 -2
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +3 -2
- package/dist/src/web/hooks/use-openai-global.js +3 -20
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +6 -3
- package/dist/src/web/hooks/use-request-modal.js +6 -1
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.test.js +37 -4
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +1 -1
- package/dist/src/web/hooks/use-tool-info.js +5 -7
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +3 -2
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.d.ts +18 -0
- package/dist/src/web/hooks/use-user.js +19 -0
- package/dist/src/web/hooks/use-user.js.map +1 -0
- package/dist/src/web/hooks/use-user.test.d.ts +1 -0
- package/dist/src/web/hooks/use-user.test.js +44 -0
- package/dist/src/web/hooks/use-user.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.js +11 -9
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +3 -2
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/index.d.ts +7 -4
- package/dist/src/web/index.js +7 -4
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/data-llm.test.js +81 -0
- package/dist/src/web/plugin/data-llm.test.js.map +1 -0
- package/dist/src/web/plugin/plugin.js +39 -0
- package/dist/src/web/plugin/plugin.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/src/web/plugin/transform-data-llm.js +93 -0
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
- package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/src/web/proxy.js +6 -1
- package/dist/src/web/proxy.js.map +1 -1
- package/dist/src/web/types.d.ts +36 -8
- package/dist/src/web/types.js +1 -0
- package/dist/src/web/types.js.map +1 -1
- package/package.json +19 -9
- package/LICENSE +0 -674
- package/README.md +0 -371
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-output.js +0 -9
- package/dist/src/web/hooks/use-tool-output.js.map +0 -1
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/plugin.js +0 -28
- package/dist/src/web/plugin.js.map +0 -1
- /package/dist/src/web/{hooks/use-locale.test.d.ts → bridges/hooks/use-mcp-app-bridge.test.d.ts} +0 -0
- /package/dist/src/web/{hooks/use-theme.test.d.ts → create-store.test.d.ts} +0 -0
- /package/dist/src/web/{hooks/use-user-agent.test.d.ts → data-llm.test.d.ts} +0 -0
- /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InferTools, ToolInput, ToolOutput, ToolResponseMetadata } from "../server/index.js";
|
|
2
|
+
import { type CallToolAsyncFn, type CallToolFn, type CallToolState } from "./hooks/use-call-tool.js";
|
|
2
3
|
import { type ToolState } from "./hooks/use-tool-info.js";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type TypedCallToolReturn<TInput, TOutput> = Prettify<CallToolState<CallToolResponse & {
|
|
4
|
+
import type { CallToolResponse, Objectify, Prettify } from "./types.js";
|
|
5
|
+
type TypedCallToolResponse<TOutput> = CallToolResponse & {
|
|
6
6
|
structuredContent: TOutput;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}>;
|
|
7
|
+
};
|
|
8
|
+
type TypedCallToolReturn<TInput, TOutput> = Prettify<CallToolState<TypedCallToolResponse<TOutput>> & {
|
|
9
|
+
callTool: CallToolFn<TInput, TypedCallToolResponse<TOutput>>;
|
|
10
|
+
callToolAsync: CallToolAsyncFn<TInput, TypedCallToolResponse<TOutput>>;
|
|
12
11
|
}>;
|
|
13
|
-
type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objectify<TOutput>, Objectify<
|
|
12
|
+
type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objectify<TInput>, Objectify<TOutput>, Objectify<TResponseMetadata>>;
|
|
14
13
|
/**
|
|
15
14
|
* Creates typed versions of skybridge hooks with full type inference
|
|
16
15
|
* for tool names, inputs, and outputs.
|
|
@@ -18,7 +17,9 @@ type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objecti
|
|
|
18
17
|
* This is the recommended way to use skybridge hooks in your widgets.
|
|
19
18
|
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
20
19
|
*
|
|
21
|
-
* @typeParam
|
|
20
|
+
* @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
|
|
21
|
+
* Must be a server instance created with method chaining.
|
|
22
|
+
* TypeScript will validate that tools can be inferred from this type.
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* ```typescript
|
|
@@ -57,11 +58,11 @@ type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objecti
|
|
|
57
58
|
* const toolInfo = useToolInfo<"search-voyage">();
|
|
58
59
|
* // ^ autocomplete for widget names
|
|
59
60
|
* // toolInfo.input is typed based on widget input schema
|
|
60
|
-
* // toolInfo.output is typed based on widget output schema
|
|
61
|
+
* // toolInfo.output.structuredContent is typed based on widget output schema
|
|
61
62
|
* }
|
|
62
63
|
* ```
|
|
63
64
|
*/
|
|
64
|
-
export declare function generateHelpers<
|
|
65
|
+
export declare function generateHelpers<ServerType = never>(): {
|
|
65
66
|
/**
|
|
66
67
|
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
67
68
|
* and type inference for inputs and outputs.
|
|
@@ -81,7 +82,7 @@ export declare function generateHelpers<T extends McpServer<AnyToolRegistry>>():
|
|
|
81
82
|
* }
|
|
82
83
|
* ```
|
|
83
84
|
*/
|
|
84
|
-
useCallTool: <
|
|
85
|
+
useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
|
|
85
86
|
/**
|
|
86
87
|
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
87
88
|
* and type inference for inputs, outputs, and responseMetadata.
|
|
@@ -93,20 +94,22 @@ export declare function generateHelpers<T extends McpServer<AnyToolRegistry>>():
|
|
|
93
94
|
* ```typescript
|
|
94
95
|
* const toolInfo = useToolInfo<"search-voyage">();
|
|
95
96
|
* // toolInfo.input is typed as { destination: string; ... }
|
|
96
|
-
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
97
|
+
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
98
|
+
* // toolInfo.responseMetadata is typed based on _meta in callback return
|
|
97
99
|
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
98
100
|
*
|
|
99
101
|
* if (toolInfo.isPending) {
|
|
100
|
-
* // TypeScript knows output
|
|
102
|
+
* // TypeScript knows output and responseMetadata are undefined here
|
|
101
103
|
* console.log(toolInfo.input.destination);
|
|
102
104
|
* }
|
|
103
105
|
*
|
|
104
106
|
* if (toolInfo.isSuccess) {
|
|
105
|
-
* // TypeScript knows output
|
|
107
|
+
* // TypeScript knows output and responseMetadata are defined here
|
|
106
108
|
* console.log(toolInfo.output.results);
|
|
109
|
+
* console.log(toolInfo.responseMetadata);
|
|
107
110
|
* }
|
|
108
111
|
* ```
|
|
109
112
|
*/
|
|
110
|
-
useToolInfo: <
|
|
113
|
+
useToolInfo: <ToolName extends keyof InferTools<ServerType> & string>() => TypedToolInfoReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>, ToolResponseMetadata<ServerType, ToolName>>;
|
|
111
114
|
};
|
|
112
115
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallTool } from "./hooks/use-call-tool.js";
|
|
1
|
+
import { useCallTool, } from "./hooks/use-call-tool.js";
|
|
2
2
|
import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates typed versions of skybridge hooks with full type inference
|
|
@@ -7,7 +7,9 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
7
7
|
* This is the recommended way to use skybridge hooks in your widgets.
|
|
8
8
|
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
9
9
|
*
|
|
10
|
-
* @typeParam
|
|
10
|
+
* @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
|
|
11
|
+
* Must be a server instance created with method chaining.
|
|
12
|
+
* TypeScript will validate that tools can be inferred from this type.
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```typescript
|
|
@@ -46,7 +48,7 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
|
46
48
|
* const toolInfo = useToolInfo<"search-voyage">();
|
|
47
49
|
* // ^ autocomplete for widget names
|
|
48
50
|
* // toolInfo.input is typed based on widget input schema
|
|
49
|
-
* // toolInfo.output is typed based on widget output schema
|
|
51
|
+
* // toolInfo.output.structuredContent is typed based on widget output schema
|
|
50
52
|
* }
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
@@ -85,17 +87,19 @@ export function generateHelpers() {
|
|
|
85
87
|
* ```typescript
|
|
86
88
|
* const toolInfo = useToolInfo<"search-voyage">();
|
|
87
89
|
* // toolInfo.input is typed as { destination: string; ... }
|
|
88
|
-
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
90
|
+
* // toolInfo.output is typed as { results: Array<...>; ... }
|
|
91
|
+
* // toolInfo.responseMetadata is typed based on _meta in callback return
|
|
89
92
|
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
90
93
|
*
|
|
91
94
|
* if (toolInfo.isPending) {
|
|
92
|
-
* // TypeScript knows output
|
|
95
|
+
* // TypeScript knows output and responseMetadata are undefined here
|
|
93
96
|
* console.log(toolInfo.input.destination);
|
|
94
97
|
* }
|
|
95
98
|
*
|
|
96
99
|
* if (toolInfo.isSuccess) {
|
|
97
|
-
* // TypeScript knows output
|
|
100
|
+
* // TypeScript knows output and responseMetadata are defined here
|
|
98
101
|
* console.log(toolInfo.output.results);
|
|
102
|
+
* console.log(toolInfo.responseMetadata);
|
|
99
103
|
* }
|
|
100
104
|
* ```
|
|
101
105
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAId,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAIjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { createInterfaceTestServer, createTestServer } from "../test/utils.js";
|
|
2
3
|
import { generateHelpers } from "./generate-helpers.js";
|
|
3
|
-
import { createTestServer } from "../test/utils.js";
|
|
4
4
|
const server = createTestServer();
|
|
5
|
+
const interfaceServer = createInterfaceTestServer();
|
|
5
6
|
test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
|
|
6
7
|
expectTypeOf().toHaveProperty("search-voyage");
|
|
7
8
|
expectTypeOf().toHaveProperty("get-trip-details");
|
|
@@ -9,6 +10,9 @@ test("InferTools extracts the tool registry type (widgets + registerTool)", () =
|
|
|
9
10
|
expectTypeOf().toHaveProperty("calculate-price");
|
|
10
11
|
expectTypeOf().toHaveProperty("inferred-output-widget");
|
|
11
12
|
expectTypeOf().toHaveProperty("inferred-tool");
|
|
13
|
+
expectTypeOf().toHaveProperty("widget-with-metadata");
|
|
14
|
+
expectTypeOf().toHaveProperty("tool-with-metadata");
|
|
15
|
+
expectTypeOf().toHaveProperty("widget-with-mixed-returns");
|
|
12
16
|
});
|
|
13
17
|
test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
|
|
14
18
|
expectTypeOf().toEqualTypeOf();
|
|
@@ -36,6 +40,9 @@ test("generateHelpers provides autocomplete for tool names (widgets + registerTo
|
|
|
36
40
|
useCallTool("calculate-price");
|
|
37
41
|
useCallTool("inferred-output-widget");
|
|
38
42
|
useCallTool("inferred-tool");
|
|
43
|
+
useCallTool("widget-with-metadata");
|
|
44
|
+
useCallTool("tool-with-metadata");
|
|
45
|
+
useCallTool("widget-with-mixed-returns");
|
|
39
46
|
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
40
47
|
useCallTool("invalid-name");
|
|
41
48
|
});
|
|
@@ -48,6 +55,68 @@ test("useCallTool returns correctly typed callTool function", () => {
|
|
|
48
55
|
const { callTool: calculateTool } = useCallTool("calculate-price");
|
|
49
56
|
calculateTool({ tripId: "123", passengers: 2 });
|
|
50
57
|
});
|
|
58
|
+
test("callTool can be called without args for tools with no required inputs", () => {
|
|
59
|
+
const { useCallTool } = generateHelpers();
|
|
60
|
+
const { callTool, callToolAsync } = useCallTool("no-input-widget");
|
|
61
|
+
callTool();
|
|
62
|
+
callTool({});
|
|
63
|
+
callToolAsync();
|
|
64
|
+
callToolAsync({});
|
|
65
|
+
});
|
|
66
|
+
test("callTool requires args for tools with required inputs", () => {
|
|
67
|
+
const { useCallTool } = generateHelpers();
|
|
68
|
+
const { callTool } = useCallTool("search-voyage");
|
|
69
|
+
// @ts-expect-error - "destination" is required
|
|
70
|
+
callTool();
|
|
71
|
+
// @ts-expect-error - "destination" is required
|
|
72
|
+
callTool({});
|
|
73
|
+
// This should work
|
|
74
|
+
callTool({ destination: "Spain" });
|
|
75
|
+
});
|
|
76
|
+
test("callTool supports sideEffects for tools with required inputs", () => {
|
|
77
|
+
const { useCallTool } = generateHelpers();
|
|
78
|
+
const { callTool } = useCallTool("search-voyage");
|
|
79
|
+
callTool({ destination: "Spain" }, {
|
|
80
|
+
onSuccess: (response, args) => {
|
|
81
|
+
expectTypeOf(response.structuredContent.results).toBeArray();
|
|
82
|
+
expectTypeOf(args.destination).toBeString();
|
|
83
|
+
},
|
|
84
|
+
onError: (error, args) => {
|
|
85
|
+
expectTypeOf(error).toBeUnknown();
|
|
86
|
+
expectTypeOf(args.destination).toBeString();
|
|
87
|
+
},
|
|
88
|
+
onSettled: (response, error, args) => {
|
|
89
|
+
if (response) {
|
|
90
|
+
expectTypeOf(response.structuredContent.totalCount).toBeNumber();
|
|
91
|
+
}
|
|
92
|
+
expectTypeOf(error).toBeUnknown();
|
|
93
|
+
expectTypeOf(args.destination).toBeString();
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
test("callTool supports sideEffects for tools with no required inputs", () => {
|
|
98
|
+
const { useCallTool } = generateHelpers();
|
|
99
|
+
const { callTool } = useCallTool("no-input-widget");
|
|
100
|
+
callTool({
|
|
101
|
+
onSuccess: (response) => {
|
|
102
|
+
expectTypeOf(response).toHaveProperty("structuredContent");
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
callTool({}, {
|
|
106
|
+
onSuccess: (response) => {
|
|
107
|
+
expectTypeOf(response).toHaveProperty("structuredContent");
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
test("callToolAsync returns correctly typed promise", () => {
|
|
112
|
+
const { useCallTool } = generateHelpers();
|
|
113
|
+
const { callToolAsync: searchAsync } = useCallTool("search-voyage");
|
|
114
|
+
const searchPromise = searchAsync({ destination: "Spain" });
|
|
115
|
+
expectTypeOf(searchPromise).resolves.toHaveProperty("structuredContent");
|
|
116
|
+
const { callToolAsync: noInputAsync } = useCallTool("no-input-widget");
|
|
117
|
+
const noInputPromise = noInputAsync();
|
|
118
|
+
expectTypeOf(noInputPromise).resolves.toHaveProperty("structuredContent");
|
|
119
|
+
});
|
|
51
120
|
test("useCallTool returns correctly typed data", () => {
|
|
52
121
|
const { useCallTool } = generateHelpers();
|
|
53
122
|
const { data } = useCallTool("search-voyage");
|
|
@@ -76,6 +145,9 @@ test("generateHelpers provides autocomplete for tool names in useToolInfo (widge
|
|
|
76
145
|
useToolInfo();
|
|
77
146
|
useToolInfo();
|
|
78
147
|
useToolInfo();
|
|
148
|
+
useToolInfo();
|
|
149
|
+
useToolInfo();
|
|
150
|
+
useToolInfo();
|
|
79
151
|
// @ts-expect-error - "invalid-name" is not a valid tool name
|
|
80
152
|
useToolInfo();
|
|
81
153
|
});
|
|
@@ -85,6 +157,50 @@ test("useToolInfo infers input and output types", () => {
|
|
|
85
157
|
expectTypeOf(toolInfo.input).toExtend();
|
|
86
158
|
if (toolInfo.status === "success") {
|
|
87
159
|
expectTypeOf(toolInfo.output).toExtend();
|
|
160
|
+
expectTypeOf(toolInfo.output.results).toBeArray();
|
|
161
|
+
expectTypeOf(toolInfo.output.totalCount).toBeNumber();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
test("ToolResponseMetadata extracts _meta type from callback", () => {
|
|
165
|
+
expectTypeOf().toEqualTypeOf();
|
|
166
|
+
expectTypeOf().toEqualTypeOf();
|
|
167
|
+
expectTypeOf().toBeUnknown();
|
|
168
|
+
});
|
|
169
|
+
test("useToolInfo infers responseMetadata type from generateHelpers", () => {
|
|
170
|
+
const { useToolInfo } = generateHelpers();
|
|
171
|
+
const toolInfo = useToolInfo();
|
|
172
|
+
if (toolInfo.isSuccess) {
|
|
173
|
+
expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();
|
|
174
|
+
expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();
|
|
175
|
+
expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
test("ToolResponseMetadata extracts _meta from mixed return paths", () => {
|
|
179
|
+
expectTypeOf().toEqualTypeOf();
|
|
180
|
+
});
|
|
181
|
+
test("ToolOutput extracts correct type when using interface declaration", () => {
|
|
182
|
+
expectTypeOf().toHaveProperty("itemName");
|
|
183
|
+
expectTypeOf().toBeString();
|
|
184
|
+
expectTypeOf().toBeNumber();
|
|
185
|
+
});
|
|
186
|
+
test("ToolResponseMetadata extracts correct type when using interface declaration", () => {
|
|
187
|
+
expectTypeOf().toHaveProperty("processedBy");
|
|
188
|
+
expectTypeOf().toBeString();
|
|
189
|
+
expectTypeOf().toBeNumber();
|
|
190
|
+
});
|
|
191
|
+
test("generateHelpers works with interface-typed server", () => {
|
|
192
|
+
const { useCallTool, useToolInfo } = generateHelpers();
|
|
193
|
+
const { data } = useCallTool("interface-widget");
|
|
194
|
+
if (data) {
|
|
195
|
+
expectTypeOf(data.structuredContent.itemName).toBeString();
|
|
196
|
+
expectTypeOf(data.structuredContent.quantity).toBeNumber();
|
|
197
|
+
}
|
|
198
|
+
const toolInfo = useToolInfo();
|
|
199
|
+
if (toolInfo.isSuccess) {
|
|
200
|
+
expectTypeOf(toolInfo.output.itemName).toBeString();
|
|
201
|
+
expectTypeOf(toolInfo.output.quantity).toBeNumber();
|
|
202
|
+
expectTypeOf(toolInfo.responseMetadata.processedBy).toBeString();
|
|
203
|
+
expectTypeOf(toolInfo.responseMetadata.version).toBeNumber();
|
|
88
204
|
}
|
|
89
205
|
});
|
|
90
206
|
//# sourceMappingURL=generate-helpers.test-d.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAA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C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QAC3D,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,EAAsB,CAAC;IACnD,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACvB,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { generateHelpers } from "./generate-helpers.js";
|
|
3
2
|
import { createMinimalTestServer } from "../test/utils.js";
|
|
3
|
+
import { generateHelpers } from "./generate-helpers.js";
|
|
4
4
|
const server = createMinimalTestServer();
|
|
5
5
|
describe("generateHelpers", () => {
|
|
6
6
|
it("should return an object with useCallTool hook", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;AAGzC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SuperJSONResult } from "superjson";
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
|
+
export declare function filterWidgetContext<T extends UnknownObject>(state?: T | null): T | null;
|
|
4
|
+
export declare function injectWidgetContext<T extends UnknownObject>(newState: T | null): T | null;
|
|
5
|
+
export declare function serializeState(value: UnknownObject): unknown;
|
|
6
|
+
export declare function deserializeState(value: SuperJSONResult): unknown;
|
|
7
|
+
export declare function getInitialState<State extends UnknownObject>(defaultState?: State | (() => State)): State | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import superjson, {} from "superjson";
|
|
2
|
+
import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
|
|
3
|
+
export function filterWidgetContext(state) {
|
|
4
|
+
if (state === null || state === undefined) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const { [WIDGET_CONTEXT_KEY]: _, ...filteredState } = state;
|
|
8
|
+
return filteredState;
|
|
9
|
+
}
|
|
10
|
+
export function injectWidgetContext(newState) {
|
|
11
|
+
if (newState === null) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const currentWindowState = window.openai?.widgetState;
|
|
15
|
+
if (currentWindowState !== null &&
|
|
16
|
+
currentWindowState !== undefined &&
|
|
17
|
+
WIDGET_CONTEXT_KEY in currentWindowState) {
|
|
18
|
+
return {
|
|
19
|
+
...newState,
|
|
20
|
+
[WIDGET_CONTEXT_KEY]: currentWindowState[WIDGET_CONTEXT_KEY],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return newState;
|
|
24
|
+
}
|
|
25
|
+
export function serializeState(value) {
|
|
26
|
+
return superjson.parse(superjson.stringify(value)); // Strips functions
|
|
27
|
+
}
|
|
28
|
+
export function deserializeState(value) {
|
|
29
|
+
return superjson.deserialize(value);
|
|
30
|
+
}
|
|
31
|
+
export function getInitialState(defaultState) {
|
|
32
|
+
const widgetStateFromWindow = window.openai?.widgetState;
|
|
33
|
+
if (widgetStateFromWindow !== null && widgetStateFromWindow !== undefined) {
|
|
34
|
+
return filterWidgetContext(widgetStateFromWindow);
|
|
35
|
+
}
|
|
36
|
+
return typeof defaultState === "function"
|
|
37
|
+
? defaultState()
|
|
38
|
+
: (defaultState ?? null);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../../src/web/helpers/state.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAwB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,UAAU,mBA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B,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
|
|
3
|
+
import { filterWidgetContext, serializeState } from "./state.js";
|
|
4
|
+
describe("state helpers", () => {
|
|
5
|
+
describe("filterWidgetContext", () => {
|
|
6
|
+
it("should return null when state is null", () => {
|
|
7
|
+
expect(filterWidgetContext(null)).toBe(null);
|
|
8
|
+
});
|
|
9
|
+
it("should return null when state is undefined", () => {
|
|
10
|
+
expect(filterWidgetContext(undefined)).toBe(null);
|
|
11
|
+
});
|
|
12
|
+
it("should correctly filter WIDGET_CONTEXT_KEY and preserve other properties", () => {
|
|
13
|
+
const stateWithContextAndOthers = {
|
|
14
|
+
a: 1,
|
|
15
|
+
b: "two",
|
|
16
|
+
c: { nested: true },
|
|
17
|
+
[WIDGET_CONTEXT_KEY]: "context",
|
|
18
|
+
};
|
|
19
|
+
const filteredWithContextAndOthers = filterWidgetContext(stateWithContextAndOthers);
|
|
20
|
+
expect(filteredWithContextAndOthers).toEqual({
|
|
21
|
+
a: 1,
|
|
22
|
+
b: "two",
|
|
23
|
+
c: { nested: true },
|
|
24
|
+
});
|
|
25
|
+
const stateNoContext = { count: 5, name: "test" };
|
|
26
|
+
const filteredNoContext = filterWidgetContext(stateNoContext);
|
|
27
|
+
expect(filteredNoContext).toEqual(stateNoContext);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("serializeState", () => {
|
|
31
|
+
it("should serialize plain objects", () => {
|
|
32
|
+
const array = [1, "two", { three: 3 }];
|
|
33
|
+
const date = new Date("2023-01-01T00:00:00Z");
|
|
34
|
+
const object = {
|
|
35
|
+
a: 1,
|
|
36
|
+
b: "test",
|
|
37
|
+
c: true,
|
|
38
|
+
array,
|
|
39
|
+
date,
|
|
40
|
+
function: () => "test",
|
|
41
|
+
};
|
|
42
|
+
const result = serializeState(object);
|
|
43
|
+
expect(result).toEqual({
|
|
44
|
+
a: 1,
|
|
45
|
+
b: "test",
|
|
46
|
+
c: true,
|
|
47
|
+
array: [1, "two", { three: 3 }],
|
|
48
|
+
date: new Date("2023-01-01T00:00:00.000Z"),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../../src/web/helpers/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0EAA0E,EAAE,GAAG,EAAE;YAClF,MAAM,yBAAyB,GAAG;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,KAAK;gBACR,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBACnB,CAAC,kBAAkB,CAAC,EAAE,SAAS;aA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0B,CAAC;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
export { useCallTool } from "./use-call-tool.js";
|
|
1
|
+
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
3
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export {
|
|
5
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
4
|
+
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
6
5
|
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
7
7
|
export { useRequestModal } from "./use-request-modal.js";
|
|
8
8
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
9
|
-
export { useTheme } from "./use-theme.js";
|
|
10
9
|
export { useToolInfo } from "./use-tool-info.js";
|
|
11
|
-
export {
|
|
12
|
-
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
13
|
-
export { useUserAgent } from "./use-user-agent.js";
|
|
10
|
+
export { type UserState, useUser } from "./use-user.js";
|
|
14
11
|
export { useWidgetState } from "./use-widget-state.js";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
export { useCallTool } from "./use-call-tool.js";
|
|
1
|
+
export { useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
3
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export {
|
|
5
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
4
|
+
export { useLayout } from "./use-layout.js";
|
|
6
5
|
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
7
7
|
export { useRequestModal } from "./use-request-modal.js";
|
|
8
8
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
9
|
-
export { useTheme } from "./use-theme.js";
|
|
10
9
|
export { useToolInfo } from "./use-tool-info.js";
|
|
11
|
-
export {
|
|
12
|
-
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
13
|
-
export { useUserAgent } from "./use-user-agent.js";
|
|
10
|
+
export { useUser } from "./use-user.js";
|
|
14
11
|
export { useWidgetState } from "./use-widget-state.js";
|
|
15
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CallToolArgs, CallToolResponse } from "../types.js";
|
|
1
|
+
import type { CallToolArgs, CallToolResponse, HasRequiredKeys } from "../types.js";
|
|
2
2
|
type CallToolIdleState = {
|
|
3
3
|
status: "idle";
|
|
4
4
|
isIdle: true;
|
|
@@ -36,18 +36,28 @@ type CallToolErrorState = {
|
|
|
36
36
|
error: unknown;
|
|
37
37
|
};
|
|
38
38
|
export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
|
|
39
|
-
type SideEffects<ToolArgs, ToolResponse> = {
|
|
39
|
+
export type SideEffects<ToolArgs, ToolResponse> = {
|
|
40
40
|
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
41
41
|
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
42
42
|
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
43
43
|
};
|
|
44
|
-
type
|
|
44
|
+
type IsArgsOptional<T> = [T] extends [null] ? true : HasRequiredKeys<T> extends false ? true : false;
|
|
45
|
+
export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
46
|
+
(): void;
|
|
47
|
+
(sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
48
|
+
(args: TArgs): void;
|
|
49
|
+
(args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
50
|
+
} : {
|
|
51
|
+
(args: TArgs): void;
|
|
52
|
+
(args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
53
|
+
};
|
|
54
|
+
export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
55
|
+
(): Promise<TResponse>;
|
|
56
|
+
(args: TArgs): Promise<TResponse>;
|
|
57
|
+
} : (args: TArgs) => Promise<TResponse>;
|
|
45
58
|
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
|
|
46
|
-
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> =
|
|
47
|
-
callTool:
|
|
48
|
-
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
49
|
-
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
50
|
-
};
|
|
59
|
+
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
|
|
60
|
+
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
51
61
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
52
62
|
status: "idle";
|
|
53
63
|
isIdle: true;
|
|
@@ -57,10 +67,7 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
|
|
|
57
67
|
data: undefined;
|
|
58
68
|
error: undefined;
|
|
59
69
|
} | {
|
|
60
|
-
callTool:
|
|
61
|
-
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
62
|
-
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
63
|
-
};
|
|
70
|
+
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
64
71
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
65
72
|
status: "pending";
|
|
66
73
|
isIdle: false;
|
|
@@ -70,10 +77,7 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
|
|
|
70
77
|
data: undefined;
|
|
71
78
|
error: undefined;
|
|
72
79
|
} | {
|
|
73
|
-
callTool:
|
|
74
|
-
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
75
|
-
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
76
|
-
};
|
|
80
|
+
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
77
81
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
78
82
|
status: "error";
|
|
79
83
|
isIdle: false;
|
|
@@ -83,10 +87,7 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
|
|
|
83
87
|
data: undefined;
|
|
84
88
|
error: unknown;
|
|
85
89
|
} | {
|
|
86
|
-
callTool:
|
|
87
|
-
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
88
|
-
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
89
|
-
};
|
|
90
|
+
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
90
91
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
91
92
|
status: "success";
|
|
92
93
|
isIdle: false;
|
|
@@ -13,13 +13,13 @@ export const useCallTool = (name) => {
|
|
|
13
13
|
throw error;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
const callToolAsync = (
|
|
16
|
+
const callToolAsync = ((toolArgs) => {
|
|
17
17
|
if (toolArgs === undefined) {
|
|
18
18
|
return execute(null);
|
|
19
19
|
}
|
|
20
20
|
return execute(toolArgs);
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const callTool = ((firstArg, sideEffects) => {
|
|
23
23
|
let toolArgs;
|
|
24
24
|
if (firstArg &&
|
|
25
25
|
typeof firstArg === "object" &&
|
|
@@ -34,22 +34,14 @@ export const useCallTool = (name) => {
|
|
|
34
34
|
}
|
|
35
35
|
execute(toolArgs)
|
|
36
36
|
.then((data) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (sideEffects?.onSettled) {
|
|
41
|
-
sideEffects.onSettled(data, undefined, toolArgs);
|
|
42
|
-
}
|
|
37
|
+
sideEffects?.onSuccess?.(data, toolArgs);
|
|
38
|
+
sideEffects?.onSettled?.(data, undefined, toolArgs);
|
|
43
39
|
})
|
|
44
40
|
.catch((error) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (sideEffects?.onSettled) {
|
|
49
|
-
sideEffects.onSettled(undefined, error, toolArgs);
|
|
50
|
-
}
|
|
41
|
+
sideEffects?.onError?.(error, toolArgs);
|
|
42
|
+
sideEffects?.onSettled?.(undefined, error, toolArgs);
|
|
51
43
|
});
|
|
52
|
-
}
|
|
44
|
+
});
|
|
53
45
|
const callToolState = {
|
|
54
46
|
status,
|
|
55
47
|
data,
|