skybridge 0.0.1 → 0.2.0
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/LICENSE +674 -0
- package/README.md +196 -1
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.js +3 -0
- package/dist/src/server/index.js.map +1 -0
- package/dist/src/server/server.d.ts +12 -0
- package/dist/src/server/server.js +45 -0
- package/dist/src/server/server.js.map +1 -0
- package/dist/src/server/templateHelper.d.ts +14 -0
- package/dist/src/server/templateHelper.js +37 -0
- package/dist/src/server/templateHelper.js.map +1 -0
- package/dist/src/server/templates/development.hbs +11 -0
- package/dist/src/server/templates/production.hbs +5 -0
- package/dist/src/server/widgetsDevServer.d.ts +12 -0
- package/dist/src/server/widgetsDevServer.js +39 -0
- package/dist/src/server/widgetsDevServer.js.map +1 -0
- package/dist/src/test/setup.d.ts +1 -0
- package/dist/src/test/setup.js +9 -0
- package/dist/src/test/setup.js.map +1 -0
- package/dist/src/test/utils.d.ts +28 -0
- package/dist/src/test/utils.js +43 -0
- package/dist/src/test/utils.js.map +1 -0
- package/dist/src/test/widget.test.d.ts +1 -0
- package/dist/src/test/widget.test.js +69 -0
- package/dist/src/test/widget.test.js.map +1 -0
- package/dist/src/web/index.d.ts +7 -0
- package/dist/src/web/index.js +8 -0
- package/dist/src/web/index.js.map +1 -0
- package/dist/src/web/mount-widget.d.ts +1 -0
- package/dist/src/web/mount-widget.js +14 -0
- package/dist/src/web/mount-widget.js.map +1 -0
- package/dist/src/web/plugin.d.ts +2 -0
- package/dist/src/web/plugin.js +30 -0
- package/dist/src/web/plugin.js.map +1 -0
- package/dist/src/web/types.d.ts +103 -0
- package/dist/src/web/types.js +10 -0
- package/dist/src/web/types.js.map +1 -0
- package/dist/src/web/use-call-tool.d.ts +54 -0
- package/dist/src/web/use-call-tool.js +44 -0
- package/dist/src/web/use-call-tool.js.map +1 -0
- package/dist/src/web/use-call-tool.test.d.ts +1 -0
- package/dist/src/web/use-call-tool.test.js +66 -0
- package/dist/src/web/use-call-tool.test.js.map +1 -0
- package/dist/src/web/use-openai-global.d.ts +2 -0
- package/dist/src/web/use-openai-global.js +21 -0
- package/dist/src/web/use-openai-global.js.map +1 -0
- package/dist/src/web/use-tool-output.d.ts +3 -0
- package/dist/src/web/use-tool-output.js +5 -0
- package/dist/src/web/use-tool-output.js.map +1 -0
- package/dist/src/web/use-tool-response-metadata.d.ts +3 -0
- package/dist/src/web/use-tool-response-metadata.js +5 -0
- package/dist/src/web/use-tool-response-metadata.js.map +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +9 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +47 -7
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function skybridge() {
|
|
2
|
+
return {
|
|
3
|
+
name: "skybridge",
|
|
4
|
+
async config(config) {
|
|
5
|
+
// Dynamic imports to ensure Node modules are only loaded in Node.js context
|
|
6
|
+
const { globSync } = await import("node:fs");
|
|
7
|
+
const { resolve } = await import("node:path");
|
|
8
|
+
const projectRoot = config.root || process.cwd();
|
|
9
|
+
const widgetsPattern = resolve(projectRoot, "src/widgets/*.{js,ts,jsx,tsx,html}");
|
|
10
|
+
const input = Object.fromEntries(globSync(widgetsPattern).map((file) => [
|
|
11
|
+
file.match(/src\/widgets\/(.+)\.tsx$/)?.[1],
|
|
12
|
+
file,
|
|
13
|
+
]));
|
|
14
|
+
return {
|
|
15
|
+
build: {
|
|
16
|
+
minify: true,
|
|
17
|
+
cssCodeSplit: false,
|
|
18
|
+
rollupOptions: {
|
|
19
|
+
input,
|
|
20
|
+
output: {
|
|
21
|
+
entryFileNames: "[name].js",
|
|
22
|
+
assetFileNames: "[name][extname]",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
type UnknownObject = Record<string, unknown>;
|
|
2
|
+
export type WidgetState = UnknownObject;
|
|
3
|
+
export type SetWidgetState = (state: WidgetState) => Promise<void>;
|
|
4
|
+
export type SendFollowUpMessage = (args: {
|
|
5
|
+
prompt: string;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
export type RequestDisplayMode = (args: {
|
|
8
|
+
mode: DisplayMode;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
mode: DisplayMode;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
13
|
+
export declare class ToolResponseEvent extends CustomEvent<{
|
|
14
|
+
tool: {
|
|
15
|
+
name: string;
|
|
16
|
+
args: UnknownObject;
|
|
17
|
+
};
|
|
18
|
+
}> {
|
|
19
|
+
readonly type = "openai:tool_response";
|
|
20
|
+
}
|
|
21
|
+
declare global {
|
|
22
|
+
interface Window {
|
|
23
|
+
openai: API<WidgetState> & OpenAiGlobals;
|
|
24
|
+
}
|
|
25
|
+
interface WindowEventMap {
|
|
26
|
+
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
|
|
30
|
+
theme: Theme;
|
|
31
|
+
userAgent: UserAgent;
|
|
32
|
+
locale: string;
|
|
33
|
+
maxHeight: number;
|
|
34
|
+
displayMode: DisplayMode;
|
|
35
|
+
safeArea: SafeArea;
|
|
36
|
+
toolInput: ToolInput;
|
|
37
|
+
toolOutput: ToolOutput | null;
|
|
38
|
+
toolResponseMetadata: ToolResponseMetadata | null;
|
|
39
|
+
widgetState: WidgetState | null;
|
|
40
|
+
};
|
|
41
|
+
export type CallToolArgs = Record<string, unknown> | null;
|
|
42
|
+
export type CallToolResponse = {
|
|
43
|
+
content: {
|
|
44
|
+
type: "text";
|
|
45
|
+
text: string;
|
|
46
|
+
}[];
|
|
47
|
+
structuredContent: Record<string, unknown>;
|
|
48
|
+
isError: boolean;
|
|
49
|
+
result: string;
|
|
50
|
+
meta: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
type API<WidgetState extends UnknownObject> = {
|
|
53
|
+
/** Calls a tool on your MCP. Returns the full response. */
|
|
54
|
+
callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
55
|
+
/** Triggers a followup turn in the ChatGPT conversation */
|
|
56
|
+
sendFollowUpMessage: (args: {
|
|
57
|
+
prompt: string;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
/** Opens an external link, redirects web page or mobile app */
|
|
60
|
+
openExternal(payload: {
|
|
61
|
+
href: string;
|
|
62
|
+
}): void;
|
|
63
|
+
/** For transitioning an app from inline to fullscreen or pip */
|
|
64
|
+
requestDisplayMode: (args: {
|
|
65
|
+
mode: DisplayMode;
|
|
66
|
+
}) => Promise<{
|
|
67
|
+
/**
|
|
68
|
+
* The granted display mode. The host may reject the request.
|
|
69
|
+
* For mobile, PiP is always coerced to fullscreen.
|
|
70
|
+
*/
|
|
71
|
+
mode: DisplayMode;
|
|
72
|
+
}>;
|
|
73
|
+
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
76
|
+
export declare class SetGlobalsEvent extends CustomEvent<{
|
|
77
|
+
globals: Partial<OpenAiGlobals>;
|
|
78
|
+
}> {
|
|
79
|
+
readonly type = "openai:set_globals";
|
|
80
|
+
}
|
|
81
|
+
export type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
82
|
+
export type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
83
|
+
export type Theme = "light" | "dark";
|
|
84
|
+
export type SafeAreaInsets = {
|
|
85
|
+
top: number;
|
|
86
|
+
bottom: number;
|
|
87
|
+
left: number;
|
|
88
|
+
right: number;
|
|
89
|
+
};
|
|
90
|
+
export type SafeArea = {
|
|
91
|
+
insets: SafeAreaInsets;
|
|
92
|
+
};
|
|
93
|
+
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
94
|
+
export type UserAgent = {
|
|
95
|
+
device: {
|
|
96
|
+
type: DeviceType;
|
|
97
|
+
};
|
|
98
|
+
capabilities: {
|
|
99
|
+
hover: boolean;
|
|
100
|
+
touch: boolean;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
2
|
+
export class ToolResponseEvent extends CustomEvent {
|
|
3
|
+
type = TOOL_RESPONSE_EVENT_TYPE;
|
|
4
|
+
}
|
|
5
|
+
// Dispatched when any global changes in the host page
|
|
6
|
+
export const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
7
|
+
export class SetGlobalsEvent extends CustomEvent {
|
|
8
|
+
type = SET_GLOBALS_EVENT_TYPE;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +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;AA2ED,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
|
@@ -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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,QAAQ,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,IAAI,WAAW,EAAE,OAAO,EAAE,CAAC;gBACzB,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,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"}
|
|
@@ -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","source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AQ,CAAC,CAChD,CAAC;QAEF,GAAG,CAAC,GAAG,EAAE;YACP,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAC5B,SAAS;gBACT,OAAO;aACR,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YACzC,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,21 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types.js";
|
|
3
|
+
export function useOpenAiGlobal(key) {
|
|
4
|
+
return useSyncExternalStore((onChange) => {
|
|
5
|
+
const handleSetGlobal = (event) => {
|
|
6
|
+
const value = event.detail.globals[key];
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
console.dir(event.detail.globals, { depth: Infinity });
|
|
11
|
+
onChange();
|
|
12
|
+
};
|
|
13
|
+
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
14
|
+
passive: true,
|
|
15
|
+
});
|
|
16
|
+
return () => {
|
|
17
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
18
|
+
};
|
|
19
|
+
}, () => window.openai?.[key]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-openai-global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-response-metadata.js","sourceRoot":"","sources":["../../../src/web/use-tool-response-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,uBAAuB;IACrC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.config.js","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,CAAC,qBAAqB,CAAC;KACpC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skybridge",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT apps",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
"./server": {
|
|
11
|
+
"types": "./dist/src/server/index.d.ts",
|
|
12
|
+
"default": "./dist/src/server/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./web": {
|
|
15
|
+
"types": "./dist/src/web/index.d.ts",
|
|
16
|
+
"default": "./dist/src/web/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc && pnpm run build:templates",
|
|
21
|
+
"build:templates": "cp -r src/server/templates dist/src/server/",
|
|
22
|
+
"test": "vitest run --silent"
|
|
23
|
+
},
|
|
6
24
|
"keywords": [
|
|
7
25
|
"chatgpt",
|
|
8
26
|
"app",
|
|
@@ -11,10 +29,32 @@
|
|
|
11
29
|
],
|
|
12
30
|
"author": "Frédéric Barthelet",
|
|
13
31
|
"license": "ISC",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18.0.0",
|
|
34
|
+
"react-dom": ">=18.0.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.20.0",
|
|
38
|
+
"cors": "^2.8.5",
|
|
39
|
+
"express": "^5.1.0",
|
|
40
|
+
"handlebars": "^4.7.8",
|
|
41
|
+
"vite": "^7.1.11",
|
|
42
|
+
"zod": "^3.25.51"
|
|
43
|
+
},
|
|
14
44
|
"devDependencies": {
|
|
15
|
-
"
|
|
45
|
+
"@testing-library/dom": "^10.4.1",
|
|
46
|
+
"@testing-library/react": "^16.3.0",
|
|
47
|
+
"@total-typescript/tsconfig": "^1.0.4",
|
|
48
|
+
"@types/cors": "^2.8.19",
|
|
49
|
+
"@types/express": "^5.0.3",
|
|
50
|
+
"@types/jsdom": "^21.1.6",
|
|
51
|
+
"@types/node": "^22.15.30",
|
|
52
|
+
"@types/react": "^19.2.2",
|
|
53
|
+
"@types/react-dom": "^19.2.2",
|
|
54
|
+
"@vitest/ui": "^2.1.8",
|
|
55
|
+
"jsdom": "^25.0.1",
|
|
56
|
+
"typescript": "^5.9.3",
|
|
57
|
+
"vitest": "^2.1.8"
|
|
16
58
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}
|
|
59
|
+
"packageManager": "pnpm@10.17.1"
|
|
60
|
+
}
|