skybridge 0.0.1 → 0.1.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.
Files changed (47) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +124 -1
  3. package/dist/src/server/index.d.ts +2 -0
  4. package/dist/src/server/index.js +3 -0
  5. package/dist/src/server/index.js.map +1 -0
  6. package/dist/src/server/server.d.ts +12 -0
  7. package/dist/src/server/server.js +45 -0
  8. package/dist/src/server/server.js.map +1 -0
  9. package/dist/src/server/templateHelper.d.ts +14 -0
  10. package/dist/src/server/templateHelper.js +37 -0
  11. package/dist/src/server/templateHelper.js.map +1 -0
  12. package/dist/src/server/templates/development.hbs +11 -0
  13. package/dist/src/server/templates/production.hbs +5 -0
  14. package/dist/src/server/widgetsDevServer.d.ts +12 -0
  15. package/dist/src/server/widgetsDevServer.js +39 -0
  16. package/dist/src/server/widgetsDevServer.js.map +1 -0
  17. package/dist/src/test/setup.d.ts +1 -0
  18. package/dist/src/test/setup.js +9 -0
  19. package/dist/src/test/setup.js.map +1 -0
  20. package/dist/src/test/utils.d.ts +28 -0
  21. package/dist/src/test/utils.js +43 -0
  22. package/dist/src/test/utils.js.map +1 -0
  23. package/dist/src/test/widget.test.d.ts +1 -0
  24. package/dist/src/test/widget.test.js +69 -0
  25. package/dist/src/test/widget.test.js.map +1 -0
  26. package/dist/src/web/index.d.ts +5 -0
  27. package/dist/src/web/index.js +6 -0
  28. package/dist/src/web/index.js.map +1 -0
  29. package/dist/src/web/mount-widget.d.ts +1 -0
  30. package/dist/src/web/mount-widget.js +14 -0
  31. package/dist/src/web/mount-widget.js.map +1 -0
  32. package/dist/src/web/plugin.d.ts +2 -0
  33. package/dist/src/web/plugin.js +30 -0
  34. package/dist/src/web/plugin.js.map +1 -0
  35. package/dist/src/web/types.d.ts +95 -0
  36. package/dist/src/web/types.js +10 -0
  37. package/dist/src/web/types.js.map +1 -0
  38. package/dist/src/web/use-openai-global.d.ts +2 -0
  39. package/dist/src/web/use-openai-global.js +21 -0
  40. package/dist/src/web/use-openai-global.js.map +1 -0
  41. package/dist/src/web/use-tool-output.d.ts +3 -0
  42. package/dist/src/web/use-tool-output.js +5 -0
  43. package/dist/src/web/use-tool-output.js.map +1 -0
  44. package/dist/vitest.config.d.ts +2 -0
  45. package/dist/vitest.config.js +9 -0
  46. package/dist/vitest.config.js.map +1 -0
  47. package/package.json +45 -7
@@ -0,0 +1,95 @@
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 CallToolResponse = {
42
+ result: string;
43
+ };
44
+ type API<WidgetState extends UnknownObject> = {
45
+ /** Calls a tool on your MCP. Returns the full response. */
46
+ callTool: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
47
+ /** Triggers a followup turn in the ChatGPT conversation */
48
+ sendFollowUpMessage: (args: {
49
+ prompt: string;
50
+ }) => Promise<void>;
51
+ /** Opens an external link, redirects web page or mobile app */
52
+ openExternal(payload: {
53
+ href: string;
54
+ }): void;
55
+ /** For transitioning an app from inline to fullscreen or pip */
56
+ requestDisplayMode: (args: {
57
+ mode: DisplayMode;
58
+ }) => Promise<{
59
+ /**
60
+ * The granted display mode. The host may reject the request.
61
+ * For mobile, PiP is always coerced to fullscreen.
62
+ */
63
+ mode: DisplayMode;
64
+ }>;
65
+ setWidgetState: (state: WidgetState) => Promise<void>;
66
+ };
67
+ export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
68
+ export declare class SetGlobalsEvent extends CustomEvent<{
69
+ globals: Partial<OpenAiGlobals>;
70
+ }> {
71
+ readonly type = "openai:set_globals";
72
+ }
73
+ export type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
74
+ export type DisplayMode = "pip" | "inline" | "fullscreen";
75
+ export type Theme = "light" | "dark";
76
+ export type SafeAreaInsets = {
77
+ top: number;
78
+ bottom: number;
79
+ left: number;
80
+ right: number;
81
+ };
82
+ export type SafeArea = {
83
+ insets: SafeAreaInsets;
84
+ };
85
+ export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
86
+ export type UserAgent = {
87
+ device: {
88
+ type: DeviceType;
89
+ };
90
+ capabilities: {
91
+ hover: boolean;
92
+ touch: boolean;
93
+ };
94
+ };
95
+ 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;AA+DD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ import { type OpenAiGlobals } from "./types.js";
2
+ export declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
@@ -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,3 @@
1
+ export declare function useToolOutput(): {
2
+ [x: string]: unknown;
3
+ } | null | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ export function useToolOutput() {
3
+ return useOpenAiGlobal("toolOutput");
4
+ }
5
+ //# sourceMappingURL=use-tool-output.js.map
@@ -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,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "vitest/config";
2
+ export default defineConfig({
3
+ test: {
4
+ environment: "jsdom",
5
+ globals: true,
6
+ setupFiles: ["./src/test/setup.ts"],
7
+ },
8
+ });
9
+ //# sourceMappingURL=vitest.config.js.map
@@ -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.1",
3
+ "version": "0.1.0",
4
4
  "description": "Skybridge is a framework for building ChatGPT apps",
5
- "main": "index.js",
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,30 @@
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
- "typescript": "^5.9.3"
45
+ "@total-typescript/tsconfig": "^1.0.4",
46
+ "@types/cors": "^2.8.19",
47
+ "@types/express": "^5.0.3",
48
+ "@types/jsdom": "^21.1.6",
49
+ "@types/node": "^22.15.30",
50
+ "@types/react": "^19.2.2",
51
+ "@types/react-dom": "^19.2.2",
52
+ "@vitest/ui": "^2.1.8",
53
+ "jsdom": "^25.0.1",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^2.1.8"
16
56
  },
17
- "scripts": {
18
- "test": "echo \"Error: no test specified\" && exit 1"
19
- }
20
- }
57
+ "packageManager": "pnpm@10.17.1"
58
+ }