skybridge 0.0.0-dev.ca5fa02 → 0.0.0-dev.d4e36b5
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/README.md +2 -74
- package/dist/src/server/templates/development.hbs +1 -0
- package/dist/src/server/templates/production.hbs +1 -0
- package/dist/src/web/index.d.ts +0 -2
- package/dist/src/web/index.js +0 -2
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin.js +1 -0
- package/dist/src/web/plugin.js.map +1 -1
- package/dist/src/web/types.d.ts +1 -9
- package/dist/src/web/types.js.map +1 -1
- package/package.json +2 -7
- package/dist/src/web/use-call-tool.d.ts +0 -54
- package/dist/src/web/use-call-tool.js +0 -44
- package/dist/src/web/use-call-tool.js.map +0 -1
- package/dist/src/web/use-call-tool.test.d.ts +0 -1
- package/dist/src/web/use-call-tool.test.js +0 -66
- package/dist/src/web/use-call-tool.test.js.map +0 -1
- package/dist/src/web/use-tool-response-metadata.d.ts +0 -3
- package/dist/src/web/use-tool-response-metadata.js +0 -5
- package/dist/src/web/use-tool-response-metadata.js.map +0 -1
package/README.md
CHANGED
|
@@ -99,87 +99,15 @@ export default defineConfig({
|
|
|
99
99
|
|
|
100
100
|
**Hooks**
|
|
101
101
|
|
|
102
|
-
The `skybridge/web` package comes with a set of hooks to help you build your widgets
|
|
103
|
-
|
|
104
|
-
- `useOpenAiGlobal`: A generic hook to get any global data from the OpenAI iFrame skybridge runtime (in `window.openai`).
|
|
105
|
-
- `useToolOutput`: A hook to get the initial tool `structuredContent` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
|
|
106
|
-
- `useToolResponseMetadata`: A hook to get the initial tool `meta` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
|
|
107
|
-
- `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
|
|
108
|
-
|
|
109
|
-
_useOpenAiGlobal_
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
import { useOpenAiGlobal } from "skybridge/web";
|
|
113
|
-
|
|
114
|
-
const theme = useOpenAiGlobal("theme");
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
_useToolOutput_
|
|
102
|
+
The `skybridge/web` package comes with a set of hooks to help you build your widgets.
|
|
118
103
|
|
|
119
104
|
```ts
|
|
120
105
|
import { useToolOutput } from "skybridge/web";
|
|
121
106
|
|
|
107
|
+
// Initial data returned by the tool invocation on structuredOutput
|
|
122
108
|
const toolOutput = useToolOutput();
|
|
123
109
|
```
|
|
124
110
|
|
|
125
|
-
_useToolResponseMetadata_
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
import { useToolResponseMetadata } from "skybridge/web";
|
|
129
|
-
|
|
130
|
-
const toolResponseMetadata = useToolResponseMetadata();
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
_useCallTool_ in synchronous mode
|
|
134
|
-
|
|
135
|
-
```ts
|
|
136
|
-
import { useCallTool } from "skybridge/web";
|
|
137
|
-
|
|
138
|
-
export const TestTool: React.FunctionComponent = () => {
|
|
139
|
-
const { callTool, isPending } = useCallTool("myToolName");
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<div>
|
|
143
|
-
<button
|
|
144
|
-
disabled={isPending}
|
|
145
|
-
onClick={() => {
|
|
146
|
-
callTool({ input: "test input" }, {
|
|
147
|
-
onSuccess: (data) => {
|
|
148
|
-
alert("Tool returned: " + data);
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
>
|
|
152
|
-
Call Tool inside a widget
|
|
153
|
-
</button>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
_useCallTool_ in asynchronous mode
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
import { useCallTool } from "skybridge/web";
|
|
163
|
-
|
|
164
|
-
export const TestTool: React.FunctionComponent = () => {
|
|
165
|
-
const { callToolAsync, isPending } = useCallTool("myToolName");
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<div>
|
|
169
|
-
<button
|
|
170
|
-
disabled={isPending}
|
|
171
|
-
onClick={async () => {
|
|
172
|
-
const data = await callToolAsync({ input: "test input" });
|
|
173
|
-
alert("Tool returned: " + data);
|
|
174
|
-
}}
|
|
175
|
-
>
|
|
176
|
-
Call Tool inside a widget
|
|
177
|
-
</button>
|
|
178
|
-
</div>
|
|
179
|
-
);
|
|
180
|
-
};
|
|
181
|
-
```
|
|
182
|
-
|
|
183
111
|
## Migrate your existing MCP server to a ChatGPT app
|
|
184
112
|
|
|
185
113
|
If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
|
package/dist/src/web/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
2
|
export { useToolOutput } from "./use-tool-output.js";
|
|
3
|
-
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
4
|
-
export { useCallTool } from "./use-call-tool.js";
|
|
5
3
|
export * from "./types.js";
|
|
6
4
|
export { mountWidget } from "./mount-widget.js";
|
|
7
5
|
export { skybridge } from "./plugin.js";
|
package/dist/src/web/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
2
|
export { useToolOutput } from "./use-tool-output.js";
|
|
3
|
-
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
4
|
-
export { useCallTool } from "./use-call-tool.js";
|
|
5
3
|
export * from "./types.js";
|
|
6
4
|
export { mountWidget } from "./mount-widget.js";
|
|
7
5
|
export { skybridge } from "./plugin.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/src/web/plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACjD,MAAM,cAAc,GAAG,OAAO,CAC5B,WAAW,EACX,oCAAoC,CACrC,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,IAAI;aACL,CAAC,CACH,CAAC;YAEF,OAAO;gBACL,KAAK,EAAE;oBACL,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;wBACL,MAAM,EAAE;4BACN,cAAc,EAAE,WAAW;4BAC3B,cAAc,EAAE,iBAAiB;yBAClC;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACjD,MAAM,cAAc,GAAG,OAAO,CAC5B,WAAW,EACX,oCAAoC,CACrC,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,IAAI;aACL,CAAC,CACH,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;wBACL,MAAM,EAAE;4BACN,cAAc,EAAE,WAAW;4BAC3B,cAAc,EAAE,iBAAiB;yBAClC;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -38,20 +38,12 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolO
|
|
|
38
38
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
39
39
|
widgetState: WidgetState | null;
|
|
40
40
|
};
|
|
41
|
-
export type CallToolArgs = Record<string, unknown> | null;
|
|
42
41
|
export type CallToolResponse = {
|
|
43
|
-
content: {
|
|
44
|
-
type: "text";
|
|
45
|
-
text: string;
|
|
46
|
-
}[];
|
|
47
|
-
structuredContent: Record<string, unknown>;
|
|
48
|
-
isError: boolean;
|
|
49
42
|
result: string;
|
|
50
|
-
meta: Record<string, unknown>;
|
|
51
43
|
};
|
|
52
44
|
type API<WidgetState extends UnknownObject> = {
|
|
53
45
|
/** Calls a tool on your MCP. Returns the full response. */
|
|
54
|
-
callTool:
|
|
46
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
55
47
|
/** Triggers a followup turn in the ChatGPT conversation */
|
|
56
48
|
sendFollowUpMessage: (args: {
|
|
57
49
|
prompt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA+DD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skybridge",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.d4e36b5",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -19,10 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc && pnpm run build:templates",
|
|
21
21
|
"build:templates": "cp -r src/server/templates dist/src/server/",
|
|
22
|
-
"test": "vitest run --silent"
|
|
23
|
-
"docs:dev": "pnpm --filter @skybridge/docs start",
|
|
24
|
-
"docs:build": "pnpm --filter @skybridge/docs build",
|
|
25
|
-
"docs:serve": "pnpm --filter @skybridge/docs serve"
|
|
22
|
+
"test": "vitest run --silent"
|
|
26
23
|
},
|
|
27
24
|
"keywords": [
|
|
28
25
|
"chatgpt",
|
|
@@ -45,8 +42,6 @@
|
|
|
45
42
|
"zod": "^3.25.51"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
|
-
"@testing-library/dom": "^10.4.1",
|
|
49
|
-
"@testing-library/react": "^16.3.0",
|
|
50
45
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
51
46
|
"@types/cors": "^2.8.19",
|
|
52
47
|
"@types/express": "^5.0.3",
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { CallToolArgs, CallToolResponse } from "./types.js";
|
|
2
|
-
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string) => {
|
|
3
|
-
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
4
|
-
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
5
|
-
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
6
|
-
}) => void;
|
|
7
|
-
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
8
|
-
status: "idle";
|
|
9
|
-
isIdle: true;
|
|
10
|
-
isPending: false;
|
|
11
|
-
isSuccess: false;
|
|
12
|
-
isError: false;
|
|
13
|
-
data: undefined;
|
|
14
|
-
error: undefined;
|
|
15
|
-
} | {
|
|
16
|
-
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
17
|
-
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
18
|
-
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
19
|
-
}) => void;
|
|
20
|
-
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
21
|
-
status: "pending";
|
|
22
|
-
isIdle: false;
|
|
23
|
-
isPending: true;
|
|
24
|
-
isSuccess: false;
|
|
25
|
-
isError: false;
|
|
26
|
-
data: undefined;
|
|
27
|
-
error: undefined;
|
|
28
|
-
} | {
|
|
29
|
-
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
30
|
-
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
31
|
-
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
32
|
-
}) => void;
|
|
33
|
-
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
34
|
-
status: "error";
|
|
35
|
-
isIdle: false;
|
|
36
|
-
isPending: false;
|
|
37
|
-
isSuccess: false;
|
|
38
|
-
isError: true;
|
|
39
|
-
data: undefined;
|
|
40
|
-
error: unknown;
|
|
41
|
-
} | {
|
|
42
|
-
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
43
|
-
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
44
|
-
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
45
|
-
}) => void;
|
|
46
|
-
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
47
|
-
status: "success";
|
|
48
|
-
isIdle: false;
|
|
49
|
-
isPending: false;
|
|
50
|
-
isSuccess: true;
|
|
51
|
-
isError: false;
|
|
52
|
-
data: ToolResponse;
|
|
53
|
-
error: undefined;
|
|
54
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
export const useCallTool = (name) => {
|
|
3
|
-
const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
|
|
4
|
-
const callToolAsync = async (toolArgs) => {
|
|
5
|
-
setCallToolState({ status: "pending", data: undefined, error: undefined });
|
|
6
|
-
try {
|
|
7
|
-
const data = await window.openai.callTool(name, toolArgs);
|
|
8
|
-
setCallToolState({ status: "success", data, error: undefined });
|
|
9
|
-
return data;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
setCallToolState({ status: "error", data: undefined, error });
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const callTool = (toolArgs, sideEffects) => {
|
|
17
|
-
callToolAsync(toolArgs)
|
|
18
|
-
.then((data) => {
|
|
19
|
-
if (sideEffects?.onSuccess) {
|
|
20
|
-
sideEffects.onSuccess(data, toolArgs);
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
.catch((error) => {
|
|
24
|
-
if (sideEffects?.onError) {
|
|
25
|
-
sideEffects.onError(error, toolArgs);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const callToolState = {
|
|
30
|
-
status,
|
|
31
|
-
data,
|
|
32
|
-
error,
|
|
33
|
-
isIdle: status === "idle",
|
|
34
|
-
isPending: status === "pending",
|
|
35
|
-
isSuccess: status === "success",
|
|
36
|
-
isError: status === "error",
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
...callToolState,
|
|
40
|
-
callTool,
|
|
41
|
-
callToolAsync,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=use-call-tool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4BjC,MAAM,CAA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AAC,CAAC;YACvC,CAAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACG,CAAC;IAEjC,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { useCallTool } from "./use-call-tool.js";
|
|
2
|
-
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
-
import { renderHook, act, waitFor } from "@testing-library/react";
|
|
4
|
-
describe("useCallTool - onSuccess callback", () => {
|
|
5
|
-
let OpenaiMock;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
OpenaiMock = {
|
|
8
|
-
callTool: vi.fn(),
|
|
9
|
-
};
|
|
10
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
vi.unstubAllGlobals();
|
|
14
|
-
vi.resetAllMocks();
|
|
15
|
-
});
|
|
16
|
-
const toolName = "test-tool";
|
|
17
|
-
const args = { input: "test input" };
|
|
18
|
-
const data = {
|
|
19
|
-
content: [{ type: "text", text: "test result" }],
|
|
20
|
-
structuredContent: { result: "test" },
|
|
21
|
-
isError: false,
|
|
22
|
-
result: "test result",
|
|
23
|
-
meta: {},
|
|
24
|
-
};
|
|
25
|
-
const error = new Error("test error");
|
|
26
|
-
it("should call window.openai.callTool with correct arguments", async () => {
|
|
27
|
-
const { result } = renderHook(() => useCallTool(toolName));
|
|
28
|
-
act(() => {
|
|
29
|
-
result.current.callTool(args);
|
|
30
|
-
});
|
|
31
|
-
expect(OpenaiMock.callTool).toHaveBeenCalledWith(toolName, args);
|
|
32
|
-
});
|
|
33
|
-
it("should call onSuccess callback with correct data and toolArgs on successful execution", async () => {
|
|
34
|
-
const onSuccess = vi.fn();
|
|
35
|
-
const onError = vi.fn();
|
|
36
|
-
OpenaiMock.callTool.mockResolvedValueOnce(data);
|
|
37
|
-
const { result } = renderHook(() => useCallTool(toolName));
|
|
38
|
-
act(() => {
|
|
39
|
-
result.current.callTool(args, {
|
|
40
|
-
onSuccess,
|
|
41
|
-
onError,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
await waitFor(() => {
|
|
45
|
-
expect(onSuccess).toHaveBeenCalledWith(data, args);
|
|
46
|
-
expect(onError).not.toHaveBeenCalled();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it("should call onError callback with error and toolArgs on failed execution", async () => {
|
|
50
|
-
const onSuccess = vi.fn();
|
|
51
|
-
const onError = vi.fn();
|
|
52
|
-
OpenaiMock.callTool.mockRejectedValueOnce(error);
|
|
53
|
-
const { result } = renderHook(() => useCallTool(toolName));
|
|
54
|
-
act(() => {
|
|
55
|
-
result.current.callTool(args, {
|
|
56
|
-
onSuccess,
|
|
57
|
-
onError,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
await waitFor(() => {
|
|
61
|
-
expect(onSuccess).not.toHaveBeenCalled();
|
|
62
|
-
expect(onError).toHaveBeenCalledWith(error, args);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
//# sourceMappingURL=use-call-tool.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV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