skybridge 0.0.0-dev.ad2a0aa → 0.0.0-dev.add8872
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/server/server.d.ts +1 -1
- package/dist/src/server/server.js +2 -2
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templates/development.hbs +1 -1
- package/dist/src/server/templates/production.hbs +1 -1
- package/dist/src/server/widgetsDevServer.js +0 -1
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/widget.test.js +1 -1
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +16 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +10 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js +46 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-bridge.js +8 -0
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +5 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +41 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -0
- package/dist/src/web/bridges/index.d.ts +4 -2
- package/dist/src/web/bridges/index.js +4 -2
- package/dist/src/web/bridges/index.js.map +1 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +38 -0
- package/dist/src/web/bridges/mcp-app-bridge.js +162 -0
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/types.d.ts +57 -0
- package/dist/src/web/bridges/types.js +2 -0
- package/dist/src/web/bridges/types.js.map +1 -0
- package/dist/src/web/data-llm.js +4 -2
- package/dist/src/web/data-llm.js.map +1 -1
- package/dist/src/web/generate-helpers.test-d.js +4 -1
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +2 -3
- package/dist/src/web/hooks/index.js +2 -3
- package/dist/src/web/hooks/index.js.map +1 -1
- package/dist/src/web/hooks/test/utils.d.ts +10 -0
- package/dist/src/web/hooks/test/utils.js +40 -0
- package/dist/src/web/hooks/test/utils.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.js +12 -4
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +26 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +2 -2
- package/dist/src/web/hooks/use-display-mode.js +6 -6
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/src/web/hooks/use-layout.d.ts +22 -0
- package/dist/src/web/hooks/use-layout.js +23 -0
- package/dist/src/web/hooks/use-layout.js.map +1 -0
- package/dist/src/web/hooks/use-layout.test.js +95 -0
- package/dist/src/web/hooks/use-layout.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.js +5 -3
- package/dist/src/web/hooks/use-open-external.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.test.js +41 -15
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +1 -1
- package/dist/src/web/hooks/use-openai-global.js +1 -1
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +6 -3
- package/dist/src/web/hooks/use-request-modal.js +6 -1
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.test.js +35 -2
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +3 -6
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +12 -1
- package/dist/src/web/hooks/use-tool-info.js +15 -9
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +40 -4
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +117 -47
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.d.ts +18 -0
- package/dist/src/web/hooks/use-user.js +19 -0
- package/dist/src/web/hooks/use-user.js.map +1 -0
- package/dist/src/web/hooks/use-user.test.js +93 -0
- package/dist/src/web/hooks/use-user.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.js +1 -1
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/plugin/transform-data-llm.js +6 -3
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/src/web/types.d.ts +19 -8
- package/dist/src/web/types.js.map +1 -1
- package/package.json +10 -9
- package/LICENSE +0 -21
- package/README.md +0 -125
- package/dist/src/web/bridges/constants.d.ts +0 -2
- package/dist/src/web/bridges/constants.js +0 -3
- package/dist/src/web/bridges/constants.js.map +0 -1
- package/dist/src/web/bridges/use-apps-sdk-bridge.d.ts +0 -7
- package/dist/src/web/bridges/use-apps-sdk-bridge.js +0 -39
- package/dist/src/web/bridges/use-apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/use-mcp-app-bridge.d.ts +0 -25
- package/dist/src/web/bridges/use-mcp-app-bridge.js +0 -128
- package/dist/src/web/bridges/use-mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/use-mcp-app-bridge.test.js +0 -65
- package/dist/src/web/bridges/use-mcp-app-bridge.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -10
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -22
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -10
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -27
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -32
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- /package/dist/src/web/bridges/{use-mcp-app-bridge.test.d.ts → hooks/use-mcp-app-bridge.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-locale.test.d.ts → use-layout.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-theme.test.d.ts → use-user.test.d.ts} +0 -0
package/README.md
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
<img alt="Skybridge" src="docs/static/img/github-banner.png" width="100%">
|
|
4
|
-
|
|
5
|
-
<br />
|
|
6
|
-
|
|
7
|
-
# Skybridge
|
|
8
|
-
|
|
9
|
-
**Build ChatGPT Apps. The Modern TypeScript Way.**
|
|
10
|
-
|
|
11
|
-
The fullstack TypeScript framework for ChatGPT Apps.<br />
|
|
12
|
-
**Type-safe. React-powered. Zero config.**
|
|
13
|
-
|
|
14
|
-
<br />
|
|
15
|
-
|
|
16
|
-
[](https://www.npmjs.com/package/skybridge)
|
|
17
|
-
[](https://www.npmjs.com/package/skybridge)
|
|
18
|
-
[](https://github.com/alpic-ai/skybridge/blob/main/LICENSE)
|
|
19
|
-
|
|
20
|
-
<br />
|
|
21
|
-
|
|
22
|
-
[Documentation](https://skybridge.tech) · [Quick Start](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) · [Examples](https://github.com/alpic-ai/apps-sdk-template)
|
|
23
|
-
|
|
24
|
-
</div>
|
|
25
|
-
|
|
26
|
-
<br />
|
|
27
|
-
|
|
28
|
-
## ✨ Why Skybridge?
|
|
29
|
-
|
|
30
|
-
ChatGPT Apps let you embed **rich, interactive UIs** directly in conversations. But the raw SDK is low-level—no hooks, no type safety, no dev tools, and no HMR.
|
|
31
|
-
|
|
32
|
-
**Skybridge fixes that.**
|
|
33
|
-
|
|
34
|
-
| | |
|
|
35
|
-
|:--|:--|
|
|
36
|
-
| 👨💻 **Full Dev Environment** — HMR, debug traces, and local devtools. No more refresh loops. | ✅ **End-to-End Type Safety** — tRPC-style inference from server to widget. Autocomplete everywhere. |
|
|
37
|
-
| 🔄 **Widget-to-Model Sync** — Keep the model aware of UI state with `data-llm`. Dual surfaces, one source of truth. | ⚒️ **React Query-style Hooks** — `isPending`, `isError`, callbacks. State management you already know. |
|
|
38
|
-
|
|
39
|
-
<br />
|
|
40
|
-
|
|
41
|
-
## 🚀 Get Started
|
|
42
|
-
|
|
43
|
-
**Create a new ChatGPT app:**
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
gh repo create my-app --template alpic-ai/apps-sdk-template --clone
|
|
47
|
-
cd my-app && pnpm install
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
**Or add to an existing project:**
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm i skybridge
|
|
54
|
-
yarn add skybridge
|
|
55
|
-
pnpm add skybridge
|
|
56
|
-
bun add skybridge
|
|
57
|
-
deno add skybridge
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
<div align="center">
|
|
61
|
-
|
|
62
|
-
**👉 [Read the Docs](https://skybridge.tech) 👈**
|
|
63
|
-
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<br />
|
|
67
|
-
|
|
68
|
-
## 📦 The Stack
|
|
69
|
-
|
|
70
|
-
- **`skybridge/server`** — Drop-in MCP SDK replacement with widget registration and type inference.
|
|
71
|
-
- **`skybridge/web`** — React hooks and components for ChatGPT's runtime.
|
|
72
|
-
|
|
73
|
-
### Server
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
import { McpServer } from "skybridge/server";
|
|
77
|
-
|
|
78
|
-
server.registerWidget("flights", {}, {
|
|
79
|
-
inputSchema: { destination: z.string() },
|
|
80
|
-
}, async ({ destination }) => {
|
|
81
|
-
const flights = await searchFlights(destination);
|
|
82
|
-
return { structuredContent: { flights } };
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Widget
|
|
87
|
-
|
|
88
|
-
```tsx
|
|
89
|
-
import { useToolInfo } from "skybridge/web";
|
|
90
|
-
|
|
91
|
-
function FlightsWidget() {
|
|
92
|
-
const { output } = useToolInfo();
|
|
93
|
-
|
|
94
|
-
return output.structuredContent.flights.map(f =>
|
|
95
|
-
<FlightCard key={f.id} flight={f} />
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
<br />
|
|
101
|
-
|
|
102
|
-
## 🎯 Features at a Glance
|
|
103
|
-
|
|
104
|
-
- **Live Reload** — Vite HMR. See changes instantly without reinstalling.
|
|
105
|
-
- **Typed Hooks** — Full autocomplete for tools, inputs, outputs.
|
|
106
|
-
- **Widget → Tool Calls** — Trigger server actions from UI.
|
|
107
|
-
- **Dual Surface Sync** — Keep model aware of what users see with `data-llm`.
|
|
108
|
-
- **React Query-style API** — `isPending`, `isError`, callbacks.
|
|
109
|
-
- **MCP Compatible** — Extends the official SDK. Works with any MCP client.
|
|
110
|
-
|
|
111
|
-
<br />
|
|
112
|
-
|
|
113
|
-
<div align="center">
|
|
114
|
-
|
|
115
|
-
[](https://github.com/alpic-ai/skybridge/discussions)
|
|
116
|
-
[](https://github.com/alpic-ai/skybridge/issues)
|
|
117
|
-
[](https://discord.com/invite/gNAazGueab)
|
|
118
|
-
|
|
119
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
|
|
120
|
-
|
|
121
|
-
<br />
|
|
122
|
-
|
|
123
|
-
**[MIT License](LICENSE)** · Made with ❤️ by **[Alpic](https://alpic.ai)**
|
|
124
|
-
|
|
125
|
-
</div>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/web/bridges/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type OpenAiProperties } from "../types.js";
|
|
2
|
-
export declare function getAppsSdkBridge(): AppsSdkBridge;
|
|
3
|
-
export declare class AppsSdkBridge {
|
|
4
|
-
subscribe: (key: keyof OpenAiProperties) => (onChange: () => void) => () => void;
|
|
5
|
-
getSnapshot: <K extends keyof OpenAiProperties>(key: K) => (import("../types.js").OpenAiMethods<import("../types.js").UnknownObject> & OpenAiProperties<Record<never, unknown>, import("../types.js").UnknownObject, import("../types.js").UnknownObject, import("../types.js").UnknownObject>)[K];
|
|
6
|
-
}
|
|
7
|
-
export declare function useAppsSdkBridge<K extends keyof OpenAiProperties>(key: K): OpenAiProperties[K] | undefined;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { SET_GLOBALS_EVENT_TYPE, } from "../types.js";
|
|
3
|
-
import { NOOP_GET_SNAPSHOT, NOOP_SUBSCRIBE } from "./constants.js";
|
|
4
|
-
let appsSdkBridge = null;
|
|
5
|
-
export function getAppsSdkBridge() {
|
|
6
|
-
if (appsSdkBridge === null) {
|
|
7
|
-
appsSdkBridge = new AppsSdkBridge();
|
|
8
|
-
}
|
|
9
|
-
return appsSdkBridge;
|
|
10
|
-
}
|
|
11
|
-
export class AppsSdkBridge {
|
|
12
|
-
subscribe = (key) => (onChange) => {
|
|
13
|
-
const handleSetGlobal = (event) => {
|
|
14
|
-
const value = event.detail.globals[key];
|
|
15
|
-
if (value === undefined) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
onChange();
|
|
19
|
-
};
|
|
20
|
-
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
21
|
-
passive: true,
|
|
22
|
-
});
|
|
23
|
-
return () => {
|
|
24
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
getSnapshot = (key) => {
|
|
28
|
-
if (window.openai === undefined) {
|
|
29
|
-
throw new Error(`window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`);
|
|
30
|
-
}
|
|
31
|
-
return window.openai[key];
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export function useAppsSdkBridge(key) {
|
|
35
|
-
const hostType = window.skybridge.hostType;
|
|
36
|
-
const bridge = hostType === "chatgpt-app" ? getAppsSdkBridge() : null;
|
|
37
|
-
return useSyncExternalStore(bridge ? bridge.subscribe(key) : NOOP_SUBSCRIBE, bridge ? () => bridge.getSnapshot(key) : NOOP_GET_SNAPSHOT);
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=use-apps-sdk-bridge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/use-apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAEL,sBAAsB,GAEvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnE,IAAI,aAAa,GAAyB,IAAI,CAAC;AAE/C,MAAM,UAAU,gBAAgB;IAC9B,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;QAC3B,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,OAAO,aAAa;IACxB,SAAS,GAAG,CAAC,GAA2B,EAAE,EAAE,CAAC,CAAC,QAAoB,EAAE,EAAE;QACpE,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,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,CAAC;IACF,WAAW,GAAG,CAAmC,GAAM,EAAE,EAAE;QACzD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,+EAA+E,GAAG,8CAA8C,CACjI,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC;CACH;AAED,MAAM,UAAU,gBAAgB,CAC9B,GAAM;IAEN,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IAC3C,MAAM,MAAM,GAAG,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAEtE,OAAO,oBAAoB,CACzB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,EAC/C,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { McpUiHostContext, McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
|
|
2
|
-
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
3
|
-
export declare class McpAppBridge {
|
|
4
|
-
context: McpUiHostContext | null;
|
|
5
|
-
private listeners;
|
|
6
|
-
private pendingRequests;
|
|
7
|
-
private nextId;
|
|
8
|
-
private initialized;
|
|
9
|
-
private appInitializationOptions;
|
|
10
|
-
private requestTimeout;
|
|
11
|
-
constructor(options: McpAppInitializationOptions, requestTimeout?: number);
|
|
12
|
-
subscribe: (key: keyof McpUiHostContext) => (onChange: () => void) => () => boolean | undefined;
|
|
13
|
-
getSnapshot: <K extends keyof McpUiHostContext>(key: K) => McpUiHostContext[K] | undefined;
|
|
14
|
-
cleanup: () => void;
|
|
15
|
-
private request;
|
|
16
|
-
private emit;
|
|
17
|
-
private setContext;
|
|
18
|
-
private init;
|
|
19
|
-
private handleMessage;
|
|
20
|
-
private connect;
|
|
21
|
-
private notify;
|
|
22
|
-
}
|
|
23
|
-
export declare function getMcpAppBridge(options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridge;
|
|
24
|
-
export declare function useMcpAppBridge<K extends keyof McpUiHostContext>(key: K, options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpUiHostContext[K] | undefined;
|
|
25
|
-
export {};
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { NOOP_GET_SNAPSHOT, NOOP_SUBSCRIBE } from "./constants.js";
|
|
3
|
-
const LATEST_PROTOCOL_VERSION = "2025-11-21";
|
|
4
|
-
export class McpAppBridge {
|
|
5
|
-
context = null;
|
|
6
|
-
listeners = new Map();
|
|
7
|
-
pendingRequests = new Map();
|
|
8
|
-
nextId = 1;
|
|
9
|
-
initialized;
|
|
10
|
-
appInitializationOptions;
|
|
11
|
-
requestTimeout;
|
|
12
|
-
constructor(options, requestTimeout = 10_000) {
|
|
13
|
-
this.requestTimeout = requestTimeout;
|
|
14
|
-
this.initialized = false;
|
|
15
|
-
this.appInitializationOptions = {
|
|
16
|
-
appInfo: options.appInfo,
|
|
17
|
-
appCapabilities: {},
|
|
18
|
-
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
subscribe = (key) => (onChange) => {
|
|
22
|
-
this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
|
|
23
|
-
this.init();
|
|
24
|
-
return () => this.listeners.get(key)?.delete(onChange);
|
|
25
|
-
};
|
|
26
|
-
getSnapshot = (key) => {
|
|
27
|
-
return this.context?.[key];
|
|
28
|
-
};
|
|
29
|
-
cleanup = () => {
|
|
30
|
-
window.removeEventListener("message", this.handleMessage);
|
|
31
|
-
this.pendingRequests.forEach((request) => {
|
|
32
|
-
clearTimeout(request.timeout);
|
|
33
|
-
});
|
|
34
|
-
this.pendingRequests.clear();
|
|
35
|
-
this.listeners.clear();
|
|
36
|
-
};
|
|
37
|
-
request({ method, params, }) {
|
|
38
|
-
const id = this.nextId++;
|
|
39
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
40
|
-
this.pendingRequests.set(id, {
|
|
41
|
-
resolve: resolve,
|
|
42
|
-
reject,
|
|
43
|
-
timeout: setTimeout(() => {
|
|
44
|
-
reject(new Error("Request timed out"));
|
|
45
|
-
this.pendingRequests.delete(id);
|
|
46
|
-
}, this.requestTimeout),
|
|
47
|
-
});
|
|
48
|
-
window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
|
|
49
|
-
return promise;
|
|
50
|
-
}
|
|
51
|
-
emit(key) {
|
|
52
|
-
this.listeners.get(key)?.forEach((listener) => {
|
|
53
|
-
listener();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
setContext(context) {
|
|
57
|
-
if (context == null)
|
|
58
|
-
return;
|
|
59
|
-
this.context = context;
|
|
60
|
-
for (const key of Object.keys(context)) {
|
|
61
|
-
this.emit(key);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
init() {
|
|
65
|
-
if (this.initialized)
|
|
66
|
-
return;
|
|
67
|
-
this.initialized = true;
|
|
68
|
-
if (typeof window === "undefined" || window.parent === window) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
window.addEventListener("message", this.handleMessage);
|
|
72
|
-
this.connect();
|
|
73
|
-
}
|
|
74
|
-
handleMessage = (event) => {
|
|
75
|
-
const data = event.data;
|
|
76
|
-
if (data?.jsonrpc !== "2.0")
|
|
77
|
-
return;
|
|
78
|
-
const request = this.pendingRequests.get(data.id);
|
|
79
|
-
if (request) {
|
|
80
|
-
clearTimeout(request.timeout);
|
|
81
|
-
this.pendingRequests.delete(data.id);
|
|
82
|
-
if (data.error) {
|
|
83
|
-
request.reject(new Error(data.error.message));
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
request.resolve(data.result);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (data.method === "ui/notifications/host-context-changed") {
|
|
90
|
-
this.setContext({ ...this.context, ...data.params });
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
async connect() {
|
|
94
|
-
try {
|
|
95
|
-
const result = await this.request({
|
|
96
|
-
method: "ui/initialize",
|
|
97
|
-
params: this.appInitializationOptions,
|
|
98
|
-
});
|
|
99
|
-
this.setContext(result.hostContext);
|
|
100
|
-
this.notify({ method: "ui/notifications/initialized" });
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
console.error(err);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
notify(notification) {
|
|
107
|
-
window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
let instance = null;
|
|
111
|
-
const defaultOptions = {
|
|
112
|
-
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
113
|
-
};
|
|
114
|
-
export function getMcpAppBridge(options, requestTimeout) {
|
|
115
|
-
if (instance && (options || requestTimeout)) {
|
|
116
|
-
console.warn("getMcpAppBridge: options and requestTimeout ignored, instance already exists");
|
|
117
|
-
}
|
|
118
|
-
if (!instance) {
|
|
119
|
-
instance = new McpAppBridge({ ...defaultOptions, ...options }, requestTimeout);
|
|
120
|
-
}
|
|
121
|
-
return instance;
|
|
122
|
-
}
|
|
123
|
-
export function useMcpAppBridge(key, options, requestTimeout) {
|
|
124
|
-
const hostType = window.skybridge.hostType;
|
|
125
|
-
const bridge = hostType === "mcp-app" ? getMcpAppBridge(options, requestTimeout) : null;
|
|
126
|
-
return useSyncExternalStore(bridge ? bridge.subscribe(key) : NOOP_SUBSCRIBE, bridge ? () => bridge.getSnapshot(key) : NOOP_GET_SNAPSHOT);
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=use-mcp-app-bridge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/use-mcp-app-bridge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAanE,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAE7C,MAAM,OAAO,YAAY;IAChB,OAAO,GAA4B,IAAI,CAAC;IACvC,SAAS,GAAG,IAAI,GAAG,EAA2C,CAAC;IAC/D,eAAe,GAAG,IAAI,GAAG,EAAmC,CAAC;IAC7D,MAAM,GAAG,CAAC,CAAC;IACX,WAAW,CAAU;IACrB,wBAAwB,CAAmC;IAC3D,cAAc,CAAS;IAE/B,YACE,OAAoC,EACpC,iBAAyB,MAAM;QAE/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,wBAAwB,GAAG;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,EAAE;YACnB,eAAe,EAAE,uBAAuB;SACzC,CAAC;IACJ,CAAC;IAEM,SAAS,GACd,CAAC,GAA2B,EAAE,EAAE,CAAC,CAAC,QAAoB,EAAE,EAAE;QACxD,IAAI,CAAC,SAAS,CAAC,GAAG,CAChB,GAAG,EACH,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CACxD,CAAC;QACF,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,GA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AAO,IAAI,cAAc,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,IAAI,CACV,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,YAAY,CACzB,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,EACjC,cAAc,CACf,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAM,EACN,OAA8C,EAC9C,cAAuB;IAEvB,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IAC3C,MAAM,MAAM,GACV,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,OAAO,oBAAoB,CACzB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,EAC/C,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
describe("useMcpAppBridge", () => {
|
|
4
|
-
let mockPostMessage;
|
|
5
|
-
let mcpAppModule;
|
|
6
|
-
const importModule = async () => {
|
|
7
|
-
return import("./use-mcp-app-bridge.js");
|
|
8
|
-
};
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
vi.resetModules();
|
|
11
|
-
mcpAppModule = await importModule();
|
|
12
|
-
mockPostMessage = vi.fn();
|
|
13
|
-
Object.defineProperty(window, "parent", {
|
|
14
|
-
value: { postMessage: mockPostMessage },
|
|
15
|
-
writable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
});
|
|
18
|
-
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
19
|
-
});
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
vi.clearAllMocks();
|
|
22
|
-
});
|
|
23
|
-
it("should return the theme value from host context", async () => {
|
|
24
|
-
const { useMcpAppBridge } = mcpAppModule;
|
|
25
|
-
const { result } = renderHook(() => useMcpAppBridge("theme"));
|
|
26
|
-
const initCall = mockPostMessage.mock.calls.find((call) => call[0].method === "ui/initialize");
|
|
27
|
-
if (initCall) {
|
|
28
|
-
act(() => {
|
|
29
|
-
window.dispatchEvent(new MessageEvent("message", {
|
|
30
|
-
data: {
|
|
31
|
-
jsonrpc: "2.0",
|
|
32
|
-
id: initCall[0].id,
|
|
33
|
-
result: {
|
|
34
|
-
protocolVersion: "2025-06-18",
|
|
35
|
-
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
36
|
-
hostCapabilities: {},
|
|
37
|
-
hostContext: { theme: "light" },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
}));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
await waitFor(() => {
|
|
44
|
-
expect(result.current).toBe("light");
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it("should reject the request after timeout", async () => {
|
|
48
|
-
vi.useFakeTimers();
|
|
49
|
-
const consoleErrorSpy = vi
|
|
50
|
-
.spyOn(console, "error")
|
|
51
|
-
.mockImplementation(() => { });
|
|
52
|
-
const { useMcpAppBridge, getMcpAppBridge } = mcpAppModule;
|
|
53
|
-
const bridge = getMcpAppBridge({ appInfo: { name: "test", version: "1.0.0" } }, 100);
|
|
54
|
-
renderHook(() => useMcpAppBridge("theme"));
|
|
55
|
-
expect(mockPostMessage).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/initialize" }), "*");
|
|
56
|
-
await act(async () => {
|
|
57
|
-
await vi.advanceTimersByTimeAsync(100);
|
|
58
|
-
});
|
|
59
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(new Error("Request timed out"));
|
|
60
|
-
consoleErrorSpy.mockRestore();
|
|
61
|
-
vi.useRealTimers();
|
|
62
|
-
bridge.cleanup();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
//# sourceMappingURL=use-mcp-app-bridge.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-bridge.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/use-mcp-app-bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,eAAyC,CAAC;IAC9C,IAAI,YAAsD,CAAC;IAE3D,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;QAC9B,OAAO,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEF,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,YAAY,EAAE,CAAC;QACpC,eAAe,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;YACtC,KAAK,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE;YACvC,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EA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B,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAEhC,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,YAAY,CAAC;QAC1D,MAAM,MAAM,GAAG,eAAe,CAC5B,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAC/C,GAAG,CACJ,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QAE3C,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,EACpD,GAAG,CACJ,CAAC;QAEF,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,EAAE,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAC/B,CAAC;QAEF,eAAe,CAAC,WAAW,EAAE,CAAC;QAC9B,EAAE,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useLocale(): string | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useAppsSdkBridge } from "../bridges/use-apps-sdk-bridge.js";
|
|
2
|
-
import { useMcpAppBridge } from "../bridges/use-mcp-app-bridge.js";
|
|
3
|
-
export function useLocale() {
|
|
4
|
-
const hostType = window.skybridge.hostType;
|
|
5
|
-
const appsSdkLocale = useAppsSdkBridge("locale");
|
|
6
|
-
const mcpAppLocale = useMcpAppBridge("locale");
|
|
7
|
-
const locale = hostType === "chatgpt-app" ? appsSdkLocale : mcpAppLocale;
|
|
8
|
-
return locale;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=use-locale.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-locale.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,UAAU,SAAS;IACvB,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IAC3C,MAAM,aAAa,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;IAEzE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react";
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { useLocale } from "./use-locale.js";
|
|
4
|
-
describe("useLocale", () => {
|
|
5
|
-
let OpenaiMock;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
OpenaiMock = {
|
|
8
|
-
locale: "en-US",
|
|
9
|
-
};
|
|
10
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
-
vi.stubGlobal("skybridge", { hostType: "chatgpt-app" });
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
vi.unstubAllGlobals();
|
|
15
|
-
vi.resetAllMocks();
|
|
16
|
-
});
|
|
17
|
-
it("should return the current locale from window.openai.locale", () => {
|
|
18
|
-
const { result } = renderHook(() => useLocale());
|
|
19
|
-
expect(result.current).toBe("en-US");
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
//# sourceMappingURL=use-locale.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-locale.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-locale.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,MAAM,EAAE,OAAO;SAChB,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useTheme(): "light" | "dark" | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useAppsSdkBridge } from "../bridges/use-apps-sdk-bridge.js";
|
|
2
|
-
import { useMcpAppBridge } from "../bridges/use-mcp-app-bridge.js";
|
|
3
|
-
export function useTheme() {
|
|
4
|
-
const hostType = window.skybridge.hostType;
|
|
5
|
-
const appsSdkTheme = useAppsSdkBridge("theme");
|
|
6
|
-
const mcpAppTheme = useMcpAppBridge("theme");
|
|
7
|
-
const theme = hostType === "chatgpt-app" ? appsSdkTheme : mcpAppTheme;
|
|
8
|
-
return theme;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=use-theme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-theme.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,UAAU,QAAQ;IACtB,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IAC3C,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;IAEtE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react";
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { useTheme } from "./use-theme.js";
|
|
4
|
-
describe("useTheme", () => {
|
|
5
|
-
let OpenaiMock;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
OpenaiMock = {
|
|
8
|
-
theme: "light",
|
|
9
|
-
};
|
|
10
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
-
vi.stubGlobal("skybridge", { hostType: "chatgpt-app" });
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
vi.unstubAllGlobals();
|
|
15
|
-
vi.resetAllMocks();
|
|
16
|
-
});
|
|
17
|
-
it("should return the current theme from window.openai.theme", () => {
|
|
18
|
-
const { result } = renderHook(() => useTheme());
|
|
19
|
-
expect(result.current).toBe("light");
|
|
20
|
-
});
|
|
21
|
-
it("should return dark theme when set to dark", () => {
|
|
22
|
-
OpenaiMock.theme = "dark";
|
|
23
|
-
const { result } = renderHook(() => useTheme());
|
|
24
|
-
expect(result.current).toBe("dark");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=use-theme.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-theme.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-theme.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,KAAK,EAAE,OAAO;SACf,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC;QAC1B,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useUserAgent(): import("../types.js").UserAgent | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-user-agent.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,MAAM,UAAU,YAAY;IAC1B,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react";
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { useUserAgent } from "./use-user-agent.js";
|
|
4
|
-
describe("useUserAgent", () => {
|
|
5
|
-
let OpenaiMock;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
OpenaiMock = {
|
|
8
|
-
userAgent: {
|
|
9
|
-
device: { type: "mobile" },
|
|
10
|
-
capabilities: { hover: false, touch: true },
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
14
|
-
vi.stubGlobal("skybridge", { hostType: "chatgpt-app" });
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
vi.unstubAllGlobals();
|
|
18
|
-
vi.resetAllMocks();
|
|
19
|
-
});
|
|
20
|
-
it("should return the current user agent from window.openai.userAgent", () => {
|
|
21
|
-
OpenaiMock.userAgent = {
|
|
22
|
-
device: { type: "mobile" },
|
|
23
|
-
capabilities: { hover: false, touch: true },
|
|
24
|
-
};
|
|
25
|
-
const { result } = renderHook(() => useUserAgent());
|
|
26
|
-
expect(result.current).toEqual({
|
|
27
|
-
device: { type: "mobile" },
|
|
28
|
-
capabilities: { hover: false, touch: true },
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
//# sourceMappingURL=use-user-agent.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-user-agent.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-user-agent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,SAAS,EAAE;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC1B,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;aAC5C;SACF,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAA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