skybridge 0.0.0-dev.f0904af → 0.0.0-dev.f5a2ffe
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 +74 -2
- package/dist/src/server/server.d.ts +1 -0
- package/dist/src/server/server.js +15 -6
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +9 -8
- package/dist/src/server/templateHelper.js +0 -8
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/production.hbs +2 -2
- package/dist/src/test/widget.test.js +23 -2
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +7 -0
- package/dist/src/web/hooks/index.js +8 -0
- package/dist/src/web/hooks/index.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +54 -0
- package/dist/src/web/hooks/use-call-tool.js +44 -0
- package/dist/src/web/hooks/use-call-tool.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +66 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/src/web/hooks/use-display-mode.js +7 -0
- package/dist/src/web/hooks/use-display-mode.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js +40 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
- package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +1 -1
- package/dist/src/web/hooks/use-openai-global.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.d.ts +5 -0
- package/dist/src/web/hooks/use-tool-info.js +9 -0
- package/dist/src/web/hooks/use-tool-info.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +38 -0
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-output.js +9 -0
- package/dist/src/web/hooks/use-tool-output.js.map +1 -0
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
- package/dist/src/web/hooks/use-widget-state.js +30 -0
- package/dist/src/web/hooks/use-widget-state.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js +61 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/src/web/index.d.ts +1 -2
- package/dist/src/web/index.js +1 -2
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin.js +1 -4
- package/dist/src/web/plugin.js.map +1 -1
- package/dist/src/web/types.d.ts +11 -2
- package/dist/src/web/types.js.map +1 -1
- package/package.json +7 -2
- package/dist/src/web/use-openai-global.js.map +0 -1
- package/dist/src/web/use-tool-output.d.ts +0 -3
- package/dist/src/web/use-tool-output.js +0 -5
- package/dist/src/web/use-tool-output.js.map +0 -1
package/README.md
CHANGED
|
@@ -99,15 +99,87 @@ 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
|
|
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_
|
|
103
118
|
|
|
104
119
|
```ts
|
|
105
120
|
import { useToolOutput } from "skybridge/web";
|
|
106
121
|
|
|
107
|
-
// Initial data returned by the tool invocation on structuredOutput
|
|
108
122
|
const toolOutput = useToolOutput();
|
|
109
123
|
```
|
|
110
124
|
|
|
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
|
+
|
|
111
183
|
## Migrate your existing MCP server to a ChatGPT app
|
|
112
184
|
|
|
113
185
|
If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { templateHelper } from "./templateHelper.js";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
export class McpServer extends McpServerBase {
|
|
4
6
|
widget(name, resourceConfig, toolConfig, toolCallback) {
|
|
5
7
|
const uri = `ui://widgets/${name}.html`;
|
|
@@ -15,13 +17,16 @@ export class McpServer extends McpServerBase {
|
|
|
15
17
|
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
16
18
|
extra?.requestInfo?.headers?.host}`
|
|
17
19
|
: `http://localhost:3000`;
|
|
18
|
-
const templateData = {
|
|
19
|
-
serverUrl,
|
|
20
|
-
widgetName: name,
|
|
21
|
-
};
|
|
22
20
|
const html = process.env.NODE_ENV === "production"
|
|
23
|
-
? templateHelper.renderProduction(
|
|
24
|
-
|
|
21
|
+
? templateHelper.renderProduction({
|
|
22
|
+
serverUrl,
|
|
23
|
+
widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
|
|
24
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
25
|
+
})
|
|
26
|
+
: templateHelper.renderDevelopment({
|
|
27
|
+
serverUrl,
|
|
28
|
+
widgetName: name,
|
|
29
|
+
});
|
|
25
30
|
return {
|
|
26
31
|
contents: [
|
|
27
32
|
{
|
|
@@ -41,5 +46,9 @@ export class McpServer extends McpServerBase {
|
|
|
41
46
|
_meta: toolMeta,
|
|
42
47
|
}, toolCallback);
|
|
43
48
|
}
|
|
49
|
+
lookupDistFile(key) {
|
|
50
|
+
const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
51
|
+
return manifest[key]?.file;
|
|
52
|
+
}
|
|
44
53
|
}
|
|
45
54
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AA4B7B,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,MAAM,CACJ,IAAY,EACZ,cAA+C,EAC/C,UAGC,EACD,YAAqC;QAErC,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,MAAM,gBAAgB,GAAiB,EAAE,GAAG,CAAC,cAAc,CAAC,KAAK,IAA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AQ;SAChB,EACD,YAAY,CACb,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
type TemplateData = {
|
|
2
|
-
serverUrl: string;
|
|
3
|
-
widgetName: string;
|
|
4
|
-
};
|
|
5
1
|
declare class TemplateHelper {
|
|
6
2
|
private templateCache;
|
|
7
3
|
private loadTemplate;
|
|
8
|
-
renderProduction(data:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
renderProduction(data: {
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
widgetFile: string;
|
|
7
|
+
styleFile: string;
|
|
8
|
+
}): string;
|
|
9
|
+
renderDevelopment(data: {
|
|
10
|
+
serverUrl: string;
|
|
11
|
+
widgetName: string;
|
|
12
|
+
}): string;
|
|
12
13
|
}
|
|
13
14
|
export declare const templateHelper: TemplateHelper;
|
|
14
15
|
export {};
|
|
@@ -24,14 +24,6 @@ class TemplateHelper {
|
|
|
24
24
|
const template = this.loadTemplate("development");
|
|
25
25
|
return template(data);
|
|
26
26
|
}
|
|
27
|
-
renderViteClient(data) {
|
|
28
|
-
const template = this.loadTemplate("vite-client");
|
|
29
|
-
return template(data);
|
|
30
|
-
}
|
|
31
|
-
injectViteClient(html, data) {
|
|
32
|
-
const viteClientScript = this.renderViteClient(data);
|
|
33
|
-
return viteClientScript + html;
|
|
34
|
-
}
|
|
35
27
|
}
|
|
36
28
|
export const templateHelper = new TemplateHelper();
|
|
37
29
|
//# sourceMappingURL=templateHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAOtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC;QAC/C,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM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script type="module">
|
|
4
|
-
import('{{serverUrl}}/assets/{{
|
|
4
|
+
import('{{serverUrl}}/assets/{{widgetFile}}');
|
|
5
5
|
</script>
|
|
6
|
-
<link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/
|
|
6
|
+
<link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
2
3
|
import { McpServer } from "../server/server.js";
|
|
3
|
-
import { createMockMcpServer,
|
|
4
|
+
import { createMockExtra, createMockMcpServer, resetTestEnv, setTestEnv, } from "./utils.js";
|
|
5
|
+
const mockManifest = {
|
|
6
|
+
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
7
|
+
"style.css": { file: "style.css" },
|
|
8
|
+
};
|
|
9
|
+
vi.mock("node:fs", async () => {
|
|
10
|
+
const actual = await vi.importActual("node:fs");
|
|
11
|
+
const readFileSync = vi.fn((path, ...args) => {
|
|
12
|
+
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
13
|
+
return JSON.stringify(mockManifest);
|
|
14
|
+
}
|
|
15
|
+
return actual.readFileSync(path, ...args);
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
readFileSync,
|
|
19
|
+
default: {
|
|
20
|
+
readFileSync,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
4
24
|
describe("McpServer.widget", () => {
|
|
5
25
|
let server;
|
|
6
26
|
let mockResource;
|
|
7
27
|
let mockRegisterTool;
|
|
28
|
+
let readFileSyncSpy = null;
|
|
8
29
|
beforeEach(() => {
|
|
9
30
|
({ server, mockResource, mockRegisterTool } = createMockMcpServer());
|
|
10
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings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C;YACrB,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,6BAA6B;oBAClC,QAAQ,EAAE,qBAAqB;oBAC/B,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;iBACvD;aACF;SACF,CAAC,CAAC;QAEH,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAC5C,SAAS,GAAG,gBAAgB,CAC7B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC;QAC3E,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CACxC,SAAS,GAAG,sBAAsB,CACnC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,GAAG,mBAAmB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
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
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
6
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
7
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
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
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
6
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
7
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4BjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EA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I;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/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,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAElE,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MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
+
export function useDisplayMode() {
|
|
3
|
+
const displayMode = useOpenAiGlobal("displayMode");
|
|
4
|
+
const setDisplayMode = (mode) => window.openai.requestDisplayMode({ mode });
|
|
5
|
+
return [displayMode, setDisplayMode];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=use-display-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,eAAe,CAAC,aAAa,CAAE,CAAC;IACpD,MAAM,cAAc,GAAG,CAAC,IAAiB,EAAE,EAAE,CAC3C,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useDisplayMode } from "./use-display-mode.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook, act } from "@testing-library/react";
|
|
4
|
+
describe("useDisplayMode", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
displayMode: "inline",
|
|
9
|
+
requestDisplayMode: vi.fn().mockResolvedValue({ mode: "inline" }),
|
|
10
|
+
};
|
|
11
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
it("should return the current display mode from window.openai.displayMode", () => {
|
|
18
|
+
OpenaiMock.displayMode = "inline";
|
|
19
|
+
const { result } = renderHook(() => useDisplayMode());
|
|
20
|
+
expect(result.current[0]).toBe("inline");
|
|
21
|
+
});
|
|
22
|
+
it("should return different display modes when window.openai.displayMode changes", () => {
|
|
23
|
+
OpenaiMock.displayMode = "inline";
|
|
24
|
+
const { result, rerender } = renderHook(() => useDisplayMode());
|
|
25
|
+
expect(result.current[0]).toBe("inline");
|
|
26
|
+
OpenaiMock.displayMode = "fullscreen";
|
|
27
|
+
rerender();
|
|
28
|
+
expect(result.current[0]).toBe("fullscreen");
|
|
29
|
+
});
|
|
30
|
+
it("should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called", async () => {
|
|
31
|
+
const { result } = renderHook(() => useDisplayMode());
|
|
32
|
+
await act(async () => {
|
|
33
|
+
await result.current[1]("fullscreen");
|
|
34
|
+
});
|
|
35
|
+
expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({
|
|
36
|
+
mode: "fullscreen",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=use-display-mode.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-display-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CA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AC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8FAA8F,EAAE,KAAK,IAAI,EAAE;QAC5G,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACzD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type OpenAiGlobals } from "
|
|
1
|
+
import { type OpenAiGlobals } from "../types.js";
|
|
2
2
|
export declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "
|
|
2
|
+
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
|
|
3
3
|
export function useOpenAiGlobal(key) {
|
|
4
4
|
return useSyncExternalStore((onChange) => {
|
|
5
5
|
const handleSetGlobal = (event) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-openai-global.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-openai-global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,eAAe,CAC7B,GAAM;IAEN,OAAO,oBAAoB,CACzB,CAAC,QAAQ,EAAE,EAAE;QACX,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YACvD,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EACD,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useOpenAiGlobal } from "skybridge/web";
|
|
2
|
+
export function useToolInfo() {
|
|
3
|
+
return {
|
|
4
|
+
output: useOpenAiGlobal("toolOutput"),
|
|
5
|
+
input: useOpenAiGlobal("toolInput"),
|
|
6
|
+
responseMetadata: useOpenAiGlobal("toolResponseMetadata"),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=use-tool-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,MAAM,EAAE,eAAe,CAAC,YAAY,CAAC;QACrC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC;QACnC,gBAAgB,EAAE,eAAe,CAAC,sBAAsB,CAAC;KAC1D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
4
|
+
describe("useToolInfo", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
toolInput: { name: "pikachu", args: { param: "value" } },
|
|
9
|
+
toolOutput: {
|
|
10
|
+
name: "pikachu",
|
|
11
|
+
color: "yellow",
|
|
12
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
13
|
+
},
|
|
14
|
+
toolResponseMetadata: { id: 12 },
|
|
15
|
+
};
|
|
16
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.unstubAllGlobals();
|
|
20
|
+
vi.resetAllMocks();
|
|
21
|
+
});
|
|
22
|
+
it("should return toolInput, toolOutput, and toolResponseMetadata from window.openai", () => {
|
|
23
|
+
const { result } = renderHook(() => useToolInfo());
|
|
24
|
+
expect(result.current.input).toEqual({
|
|
25
|
+
name: "pikachu",
|
|
26
|
+
args: { param: "value" },
|
|
27
|
+
});
|
|
28
|
+
expect(result.current.output).toEqual({
|
|
29
|
+
name: "pikachu",
|
|
30
|
+
color: "yellow",
|
|
31
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
32
|
+
});
|
|
33
|
+
expect(result.current.responseMetadata).toEqual({
|
|
34
|
+
id: 12,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=use-tool-info.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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C,OAAO,CAAC;YACpC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,QAAQ;YACf,WAAW,EACT,kGAAkG;SACrG,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC;YAC9C,EAAE,EAAE,EAAE;SACP,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `output` property.
|
|
4
|
+
*/
|
|
5
|
+
export function useToolOutput() {
|
|
6
|
+
const { output } = useToolInfo();
|
|
7
|
+
return output;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=use-tool-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `responseMetadata` property.
|
|
4
|
+
*/
|
|
5
|
+
export function useToolResponseMetadata() {
|
|
6
|
+
return useOpenAiGlobal("toolResponseMetadata");
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-tool-response-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-response-metadata.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-response-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SetStateAction } from "react";
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
|
+
export declare function useWidgetState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
4
|
+
export declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
3
|
+
export function useWidgetState(defaultState) {
|
|
4
|
+
const widgetStateFromWindow = useOpenAiGlobal("widgetState");
|
|
5
|
+
const [widgetState, _setWidgetState] = useState(() => {
|
|
6
|
+
if (widgetStateFromWindow !== null) {
|
|
7
|
+
return widgetStateFromWindow;
|
|
8
|
+
}
|
|
9
|
+
return typeof defaultState === "function"
|
|
10
|
+
? defaultState()
|
|
11
|
+
: defaultState ?? null;
|
|
12
|
+
});
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
// Fixes openai implementation bug
|
|
15
|
+
if (widgetStateFromWindow !== null) {
|
|
16
|
+
_setWidgetState(widgetStateFromWindow);
|
|
17
|
+
}
|
|
18
|
+
}, [widgetStateFromWindow]);
|
|
19
|
+
const setWidgetState = useCallback((state) => {
|
|
20
|
+
_setWidgetState((prevState) => {
|
|
21
|
+
const newState = typeof state === "function" ? state(prevState) : state;
|
|
22
|
+
if (newState !== null) {
|
|
23
|
+
window.openai.setWidgetState(newState);
|
|
24
|
+
}
|
|
25
|
+
return newState;
|
|
26
|
+
});
|
|
27
|
+
}, [window.openai.setWidgetState]);
|
|
28
|
+
return [widgetState, setWidgetState];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=use-widget-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-state.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAQzD,MAAM,UAAU,cAAc,CAC5B,YAA0C;IAE1C,MAAM,qBAAqB,GAAG,eAAe,CAAC,aAAa,CAAM,CAAC;IAElE,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE;QAC7D,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACnC,OAAO,qBAAqB,CAAC;QAC/B,CAAC;QAED,OAAO,OAAO,YAAY,KAAK,UAAU;YACvC,CAAC,CAAC,YAAY,EAAE;YAChB,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,kCAAkC;QAClC,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACnC,eAAe,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAE5B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,KAA+B,EAAE,EAAE;QAClC,eAAe,CAAC,CAAC,SAAS,EAAE,EAAE;YAC5B,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAExE,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YACzC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAC/B,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useWidgetState } from "./use-widget-state.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook, act } from "@testing-library/react";
|
|
4
|
+
describe("useWidgetState", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
widgetState: null,
|
|
9
|
+
setWidgetState: vi.fn().mockResolvedValue(undefined),
|
|
10
|
+
};
|
|
11
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
const defaultState = { count: 0, name: "test" };
|
|
18
|
+
const windowState = { count: 5, name: "window" };
|
|
19
|
+
it("should initialize with default state when window.openai.widgetState is null", () => {
|
|
20
|
+
OpenaiMock.widgetState = null;
|
|
21
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
22
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
23
|
+
});
|
|
24
|
+
it("should initialize with window.openai.widgetState when available", () => {
|
|
25
|
+
OpenaiMock.widgetState = windowState;
|
|
26
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
27
|
+
expect(result.current[0]).toEqual(windowState);
|
|
28
|
+
});
|
|
29
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a new state", async () => {
|
|
30
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
31
|
+
const newState = { count: 10, name: "updated" };
|
|
32
|
+
act(() => {
|
|
33
|
+
result.current[1](newState);
|
|
34
|
+
});
|
|
35
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith(newState);
|
|
36
|
+
expect(result.current[0]).toEqual(newState);
|
|
37
|
+
});
|
|
38
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a function updater", async () => {
|
|
39
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
40
|
+
act(() => {
|
|
41
|
+
result.current[1]((prev) => ({ ...prev, count: prev.count + 1 }));
|
|
42
|
+
});
|
|
43
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({
|
|
44
|
+
count: 1,
|
|
45
|
+
name: "test",
|
|
46
|
+
});
|
|
47
|
+
console.log("widgetState", result.current[0]);
|
|
48
|
+
expect(result.current[0]).toEqual({ count: 1, name: "test" });
|
|
49
|
+
});
|
|
50
|
+
it("should update state when window.openai.widgetState changes", () => {
|
|
51
|
+
OpenaiMock.widgetState = defaultState;
|
|
52
|
+
const { result, rerender } = renderHook(() => useWidgetState(defaultState));
|
|
53
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
54
|
+
// Simulate window.openai.widgetState changing
|
|
55
|
+
OpenaiMock.widgetState = windowState;
|
|
56
|
+
// Trigger re-render to simulate the useEffect running
|
|
57
|
+
rerender();
|
|
58
|
+
expect(result.current[0]).toEqual(windowState);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=use-widget-state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-state.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UA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AAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;QACtC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAEhD,8CAA8C;QAC9C,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;QACrC,sDAAsD;QACtD,QAAQ,EAAE,CAAC;QAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
-
export { useToolOutput } from "./use-tool-output.js";
|
|
3
1
|
export * from "./types.js";
|
|
4
2
|
export { mountWidget } from "./mount-widget.js";
|
|
5
3
|
export { skybridge } from "./plugin.js";
|
|
4
|
+
export * from "./hooks/index.js";
|
package/dist/src/web/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
-
export { useToolOutput } from "./use-tool-output.js";
|
|
3
1
|
export * from "./types.js";
|
|
4
2
|
export { mountWidget } from "./mount-widget.js";
|
|
5
3
|
export { skybridge } from "./plugin.js";
|
|
4
|
+
export * from "./hooks/index.js";
|
|
6
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
|
package/dist/src/web/plugin.js
CHANGED
|
@@ -14,14 +14,11 @@ export function skybridge() {
|
|
|
14
14
|
return {
|
|
15
15
|
base: "/assets",
|
|
16
16
|
build: {
|
|
17
|
+
manifest: true,
|
|
17
18
|
minify: true,
|
|
18
19
|
cssCodeSplit: false,
|
|
19
20
|
rollupOptions: {
|
|
20
21
|
input,
|
|
21
|
-
output: {
|
|
22
|
-
entryFileNames: "[name].js",
|
|
23
|
-
assetFileNames: "[name][extname]",
|
|
24
|
-
},
|
|
25
22
|
},
|
|
26
23
|
},
|
|
27
24
|
};
|
|
@@ -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,CA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,CAAC;AACJ,CAAC"}
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type UnknownObject = Record<string, unknown>;
|
|
1
|
+
export type UnknownObject = Record<string, unknown>;
|
|
2
2
|
export type WidgetState = UnknownObject;
|
|
3
3
|
export type SetWidgetState = (state: WidgetState) => Promise<void>;
|
|
4
4
|
export type SendFollowUpMessage = (args: {
|
|
@@ -37,13 +37,22 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolO
|
|
|
37
37
|
toolOutput: ToolOutput | null;
|
|
38
38
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
39
39
|
widgetState: WidgetState | null;
|
|
40
|
+
requestDisplayMode: RequestDisplayMode;
|
|
40
41
|
};
|
|
42
|
+
export type CallToolArgs = Record<string, unknown> | null;
|
|
41
43
|
export type CallToolResponse = {
|
|
44
|
+
content: {
|
|
45
|
+
type: "text";
|
|
46
|
+
text: string;
|
|
47
|
+
}[];
|
|
48
|
+
structuredContent: Record<string, unknown>;
|
|
49
|
+
isError: boolean;
|
|
42
50
|
result: string;
|
|
51
|
+
meta: Record<string, unknown>;
|
|
43
52
|
};
|
|
44
53
|
type API<WidgetState extends UnknownObject> = {
|
|
45
54
|
/** Calls a tool on your MCP. Returns the full response. */
|
|
46
|
-
callTool: (name: string, args:
|
|
55
|
+
callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
47
56
|
/** Triggers a followup turn in the ChatGPT conversation */
|
|
48
57
|
sendFollowUpMessage: (args: {
|
|
49
58
|
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;AA4ED,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.f5a2ffe",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,10 @@
|
|
|
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"
|
|
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"
|
|
23
26
|
},
|
|
24
27
|
"keywords": [
|
|
25
28
|
"chatgpt",
|
|
@@ -42,6 +45,8 @@
|
|
|
42
45
|
"zod": "^3.25.51"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
48
|
+
"@testing-library/dom": "^10.4.1",
|
|
49
|
+
"@testing-library/react": "^16.3.0",
|
|
45
50
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
46
51
|
"@types/cors": "^2.8.19",
|
|
47
52
|
"@types/express": "^5.0.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-openai-global.js","sourceRoot":"","sources":["../../../src/web/use-openai-global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AAEzF,MAAM,UAAU,eAAe,CAAgC,GAAM;IACnE,OAAO,oBAAoB,CACzB,CAAC,QAAQ,EAAE,EAAE;QACX,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YACvD,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EACD,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../src/web/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,aAAa;IAC3B,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;AACvC,CAAC"}
|