skybridge 0.0.0-dev.da10bf6 → 0.0.0-dev.dbd3f0e
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/bin/run.js +9 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +10 -0
- package/dist/cli/use-execute-steps.js +31 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +44 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.js +20 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +33 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/{src/server → server}/index.d.ts +1 -2
- package/dist/{src/server → server}/index.js +0 -1
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/{src/server → server}/server.d.ts +46 -11
- package/dist/server/server.js +138 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +3 -0
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +66 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -0
- package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
- package/dist/{src/server → server}/widgetsDevServer.js +11 -3
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +11 -0
- package/dist/{src/test → test}/utils.js +20 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.js +255 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +14 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +39 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
- package/dist/web/bridges/apps-sdk/bridge.js +46 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +28 -40
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/adaptor.d.ts +19 -0
- package/dist/web/bridges/mcp-app/adaptor.js +145 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
- package/dist/web/bridges/mcp-app/bridge.js +255 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +60 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +74 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +2 -0
- package/dist/web/bridges/use-host-context.js +8 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/{src/web → web}/create-store.js +6 -7
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +126 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/{src/web → web}/data-llm.js +9 -5
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +139 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +2 -1
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +31 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.js +13 -8
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/index.d.ts +2 -4
- package/dist/{src/web → web}/hooks/index.js +2 -4
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +60 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +2 -1
- package/dist/{src/web → web}/hooks/use-call-tool.js +12 -4
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +26 -1
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.test.js +1 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.d.ts +1 -1
- package/dist/web/hooks/use-files.js +7 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.test.js +4 -4
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.js +8 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +50 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +14 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.js +57 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.d.ts +12 -1
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -4
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +19 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.js +94 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.js +10 -10
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.test.js +1 -0
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +1 -0
- package/dist/{src/web → web}/index.js +1 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +6 -3
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/proxy.js +5 -0
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +49 -33
- package/README.md +0 -123
- package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
- package/dist/src/server/devtoolsStaticServer.js +0 -38
- package/dist/src/server/devtoolsStaticServer.js.map +0 -1
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.js +0 -71
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -112
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/create-store.test.js +0 -70
- package/dist/src/web/create-store.test.js.map +0 -1
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/helpers/state.test.js.map +0 -1
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.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 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -25
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.js +0 -20
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -59
- package/dist/src/web/hooks/use-tool-info.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.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/server → server}/inferUtilityTypes.d.ts +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/server → server}/templateHelper.js +0 -0
- /package/dist/{src/test → test}/widget.test.d.ts +0 -0
- /package/dist/{src/web/create-store.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web → web}/create-store.d.ts +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web → web}/data-llm.d.ts +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web → web}/generate-helpers.js +0 -0
- /package/dist/{src/web → web}/generate-helpers.test-d.d.ts +0 -0
- /package/dist/{src/web → web}/generate-helpers.test.d.ts +0 -0
- /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
- /package/dist/{src/web → web}/helpers/state.d.ts +0 -0
- /package/dist/{src/web → web}/helpers/state.test.d.ts +0 -0
- /package/dist/{src/web → web}/helpers/state.test.js +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.test-d.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.test.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-display-mode.test.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-files.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → web/hooks/use-layout.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-open-external.test.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-request-modal.test.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-tool-info.test-d.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-tool-info.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/hooks/use-user.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.test.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.js +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/plugin/data-llm.test.d.ts} +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
- /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/plugin.js +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
- /package/dist/{src/web → web}/proxy.d.ts +0 -0
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"data-llm"?: string;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export type UnknownObject = Record<string, unknown>;
|
|
8
|
-
export type Prettify<T> = {
|
|
9
|
-
[K in keyof T]: T[K];
|
|
10
|
-
} & {};
|
|
11
|
-
export type Objectify<T> = T & UnknownObject;
|
|
12
|
-
type RequiredKeys<T> = {
|
|
13
|
-
[K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
|
|
14
|
-
}[keyof T];
|
|
15
|
-
export type HasRequiredKeys<T> = RequiredKeys<T> extends never ? false : true;
|
|
1
|
+
import type { UnknownObject } from "../../types.js";
|
|
2
|
+
import type { CallToolArgs, CallToolResponse } from "../types.js";
|
|
3
|
+
type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
|
|
16
4
|
type WidgetState = UnknownObject;
|
|
17
5
|
type FileMetadata = {
|
|
18
6
|
fileId: string;
|
|
@@ -28,19 +16,20 @@ export declare class ToolResponseEvent extends CustomEvent<{
|
|
|
28
16
|
}
|
|
29
17
|
declare global {
|
|
30
18
|
interface Window {
|
|
31
|
-
openai:
|
|
19
|
+
openai: AppsSdkMethods<WidgetState> & AppsSdkContext;
|
|
32
20
|
}
|
|
33
21
|
interface WindowEventMap {
|
|
34
22
|
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
|
-
export type
|
|
25
|
+
export type AppsSdkContext<ToolInput extends UnknownObject = Record<never, unknown>, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
|
|
38
26
|
theme: Theme;
|
|
39
27
|
userAgent: UserAgent;
|
|
40
28
|
locale: string;
|
|
41
29
|
maxHeight: number;
|
|
42
30
|
displayMode: DisplayMode;
|
|
43
31
|
safeArea: SafeArea;
|
|
32
|
+
view: View;
|
|
44
33
|
toolInput: ToolInput;
|
|
45
34
|
toolOutput: ToolOutput | {
|
|
46
35
|
text: string;
|
|
@@ -48,18 +37,17 @@ export type OpenAiProperties<ToolInput extends UnknownObject = Record<never, unk
|
|
|
48
37
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
49
38
|
widgetState: WidgetState | null;
|
|
50
39
|
};
|
|
51
|
-
export type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
meta: Record<string, unknown>;
|
|
40
|
+
export type RequestModalOptions = {
|
|
41
|
+
title?: string;
|
|
42
|
+
params?: Record<string, unknown>;
|
|
43
|
+
anchor?: {
|
|
44
|
+
top?: number;
|
|
45
|
+
left?: number;
|
|
46
|
+
width?: number;
|
|
47
|
+
height?: number;
|
|
48
|
+
};
|
|
61
49
|
};
|
|
62
|
-
export type
|
|
50
|
+
export type AppsSdkMethods<WidgetState extends UnknownObject = UnknownObject> = {
|
|
63
51
|
/** Calls a tool on your MCP. Returns the full response. */
|
|
64
52
|
callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
65
53
|
/** Triggers a followup turn in the ChatGPT conversation */
|
|
@@ -89,39 +77,39 @@ export type OpenAiMethods<WidgetState extends UnknownObject = UnknownObject> = {
|
|
|
89
77
|
* Opens a modal portaled outside of the widget iFrame.
|
|
90
78
|
* This ensures the modal is correctly displayed and not limited to the widget's area.
|
|
91
79
|
*/
|
|
92
|
-
requestModal: (args:
|
|
93
|
-
title: string;
|
|
94
|
-
}) => Promise<void>;
|
|
80
|
+
requestModal: (args: RequestModalOptions) => Promise<void>;
|
|
95
81
|
/** Uploads a new file to the host */
|
|
96
82
|
uploadFile: (file: File) => Promise<FileMetadata>;
|
|
97
83
|
/**
|
|
98
84
|
* Downloads a file from the host that was previously uploaded.
|
|
99
85
|
* Only files uploaded by the same connector instance can be downloaded.
|
|
100
86
|
*/
|
|
101
|
-
|
|
87
|
+
getFileDownloadUrl: (file: FileMetadata) => Promise<{
|
|
102
88
|
downloadUrl: string;
|
|
103
89
|
}>;
|
|
104
90
|
};
|
|
105
91
|
export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
106
92
|
export declare class SetGlobalsEvent extends CustomEvent<{
|
|
107
|
-
globals: Partial<
|
|
93
|
+
globals: Partial<AppsSdkContext>;
|
|
108
94
|
}> {
|
|
109
95
|
readonly type = "openai:set_globals";
|
|
110
96
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
type View = {
|
|
98
|
+
mode: DisplayMode;
|
|
99
|
+
params?: Record<string, unknown>;
|
|
100
|
+
};
|
|
101
|
+
type Theme = "light" | "dark";
|
|
102
|
+
type SafeAreaInsets = {
|
|
115
103
|
top: number;
|
|
116
104
|
bottom: number;
|
|
117
105
|
left: number;
|
|
118
106
|
right: number;
|
|
119
107
|
};
|
|
120
|
-
|
|
108
|
+
type SafeArea = {
|
|
121
109
|
insets: SafeAreaInsets;
|
|
122
110
|
};
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
112
|
+
type UserAgent = {
|
|
125
113
|
device: {
|
|
126
114
|
type: DeviceType;
|
|
127
115
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/types.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA2FD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { AppsSdkBridge } from "./bridge.js";
|
|
3
|
+
export function useAppsSdkContext(key) {
|
|
4
|
+
const bridge = AppsSdkBridge.getInstance();
|
|
5
|
+
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=use-apps-sdk-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-apps-sdk-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/use-apps-sdk-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,UAAU,iBAAiB,CAC/B,GAAM;IAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC3C,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AppsSdkAdaptor } from "./apps-sdk/adaptor.js";
|
|
2
|
+
import { McpAppAdaptor } from "./mcp-app/adaptor.js";
|
|
3
|
+
export const getAdaptor = () => {
|
|
4
|
+
return window.skybridge.hostType === "apps-sdk"
|
|
5
|
+
? AppsSdkAdaptor.getInstance()
|
|
6
|
+
: McpAppAdaptor.getInstance();
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=get-adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-adaptor.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE;IACtC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { McpUiRequestDisplayModeResult } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Adaptor, CallToolResponse, DisplayMode, HostContext, HostContextStore, SetWidgetStateAction } from "../types.js";
|
|
3
|
+
export declare class McpAppAdaptor implements Adaptor {
|
|
4
|
+
private static instance;
|
|
5
|
+
private stores;
|
|
6
|
+
private _widgetState;
|
|
7
|
+
private widgetStateListeners;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): McpAppAdaptor;
|
|
10
|
+
static resetInstance(): void;
|
|
11
|
+
getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
|
|
12
|
+
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
13
|
+
requestDisplayMode: (mode: DisplayMode) => Promise<McpUiRequestDisplayModeResult>;
|
|
14
|
+
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
15
|
+
openExternal(href: string): void;
|
|
16
|
+
private initializeStores;
|
|
17
|
+
setWidgetState: (stateOrUpdater: SetWidgetStateAction) => Promise<void>;
|
|
18
|
+
private createHostContextStore;
|
|
19
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { dequal } from "dequal/lite";
|
|
2
|
+
import { McpAppBridge } from "./bridge.js";
|
|
3
|
+
export class McpAppAdaptor {
|
|
4
|
+
static instance = null;
|
|
5
|
+
stores;
|
|
6
|
+
_widgetState = null;
|
|
7
|
+
widgetStateListeners = new Set();
|
|
8
|
+
constructor() {
|
|
9
|
+
this.stores = this.initializeStores();
|
|
10
|
+
}
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!McpAppAdaptor.instance) {
|
|
13
|
+
McpAppAdaptor.instance = new McpAppAdaptor();
|
|
14
|
+
}
|
|
15
|
+
return McpAppAdaptor.instance;
|
|
16
|
+
}
|
|
17
|
+
static resetInstance() {
|
|
18
|
+
McpAppAdaptor.instance = null;
|
|
19
|
+
}
|
|
20
|
+
getHostContextStore(key) {
|
|
21
|
+
return this.stores[key];
|
|
22
|
+
}
|
|
23
|
+
callTool = async (name, args) => {
|
|
24
|
+
const bridge = McpAppBridge.getInstance();
|
|
25
|
+
const response = await bridge.request({
|
|
26
|
+
method: "tools/call",
|
|
27
|
+
params: {
|
|
28
|
+
name,
|
|
29
|
+
arguments: args ?? undefined,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const result = response.content
|
|
33
|
+
.filter((content) => content.type === "text")
|
|
34
|
+
.map(({ text }) => text)
|
|
35
|
+
.join("\n");
|
|
36
|
+
return {
|
|
37
|
+
content: response.content,
|
|
38
|
+
structuredContent: response.structuredContent ?? {},
|
|
39
|
+
isError: response.isError ?? false,
|
|
40
|
+
result,
|
|
41
|
+
meta: response._meta ?? {},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
requestDisplayMode = (mode) => {
|
|
45
|
+
const bridge = McpAppBridge.getInstance();
|
|
46
|
+
if (mode !== "modal") {
|
|
47
|
+
return bridge.request({
|
|
48
|
+
method: "ui/request-display-mode",
|
|
49
|
+
params: { mode },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw new Error("Modal display mode is not accessible in MCP App.");
|
|
53
|
+
};
|
|
54
|
+
sendFollowUpMessage = async (prompt) => {
|
|
55
|
+
const bridge = McpAppBridge.getInstance();
|
|
56
|
+
await bridge.request({
|
|
57
|
+
method: "ui/message",
|
|
58
|
+
params: {
|
|
59
|
+
role: "user",
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: "text",
|
|
63
|
+
text: prompt,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
openExternal(href) {
|
|
70
|
+
const bridge = McpAppBridge.getInstance();
|
|
71
|
+
bridge.request({
|
|
72
|
+
method: "ui/open-link",
|
|
73
|
+
params: { url: href },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
initializeStores() {
|
|
77
|
+
return {
|
|
78
|
+
theme: this.createHostContextStore(["theme"], ({ theme }) => theme ?? "light"),
|
|
79
|
+
locale: this.createHostContextStore(["locale"], ({ locale }) => locale ?? "en-US"),
|
|
80
|
+
safeArea: this.createHostContextStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
81
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
82
|
+
})),
|
|
83
|
+
displayMode: this.createHostContextStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
84
|
+
maxHeight: this.createHostContextStore(["containerDimensions"], ({ containerDimensions }) => {
|
|
85
|
+
if (containerDimensions && "maxHeight" in containerDimensions) {
|
|
86
|
+
return containerDimensions.maxHeight ?? window.innerHeight;
|
|
87
|
+
}
|
|
88
|
+
return window.innerHeight;
|
|
89
|
+
}),
|
|
90
|
+
userAgent: this.createHostContextStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
91
|
+
device: {
|
|
92
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
93
|
+
},
|
|
94
|
+
capabilities: {
|
|
95
|
+
hover: true,
|
|
96
|
+
touch: true,
|
|
97
|
+
...deviceCapabilities,
|
|
98
|
+
},
|
|
99
|
+
})),
|
|
100
|
+
toolInput: this.createHostContextStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
101
|
+
toolOutput: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
102
|
+
toolResponseMetadata: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
103
|
+
widgetState: {
|
|
104
|
+
subscribe: (onChange) => {
|
|
105
|
+
this.widgetStateListeners.add(onChange);
|
|
106
|
+
return () => {
|
|
107
|
+
this.widgetStateListeners.delete(onChange);
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
getSnapshot: () => this._widgetState,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
setWidgetState = async (stateOrUpdater) => {
|
|
115
|
+
const newState = typeof stateOrUpdater === "function"
|
|
116
|
+
? stateOrUpdater(this._widgetState)
|
|
117
|
+
: stateOrUpdater;
|
|
118
|
+
const bridge = McpAppBridge.getInstance();
|
|
119
|
+
await bridge.request({
|
|
120
|
+
method: "ui/update-model-context",
|
|
121
|
+
params: { structuredContent: newState },
|
|
122
|
+
});
|
|
123
|
+
this._widgetState = newState;
|
|
124
|
+
this.widgetStateListeners.forEach((listener) => {
|
|
125
|
+
listener();
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
createHostContextStore(keys, computeSnapshot) {
|
|
129
|
+
const bridge = McpAppBridge.getInstance();
|
|
130
|
+
let cachedValue;
|
|
131
|
+
return {
|
|
132
|
+
subscribe: bridge.subscribe(keys),
|
|
133
|
+
getSnapshot: () => {
|
|
134
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
135
|
+
const newValue = computeSnapshot(context);
|
|
136
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
137
|
+
return cachedValue;
|
|
138
|
+
}
|
|
139
|
+
cachedValue = newValue;
|
|
140
|
+
return newValue;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,YAAY,GAA+B,IAAI,CAAC;IAChD,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAErD;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;IAChC,CAAC;IAEM,mBAAmB,CACxB,GA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AI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAC/D,OAAO,WAAW,CAAC;gBACrB,CAAC;gBAED,WAAW,GAAG,QAAQ,CAAC;gBACvB,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { McpUiHostContext, McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Bridge, Subscribe } from "../types.js";
|
|
3
|
+
import type { McpAppContext, McpAppContextKey } from "./types.js";
|
|
4
|
+
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
5
|
+
export declare class McpAppBridge implements Bridge<McpUiHostContext> {
|
|
6
|
+
private static instance;
|
|
7
|
+
context: McpAppContext;
|
|
8
|
+
private listeners;
|
|
9
|
+
private pendingRequests;
|
|
10
|
+
private nextId;
|
|
11
|
+
private initialized;
|
|
12
|
+
private appInitializationOptions;
|
|
13
|
+
private requestTimeout;
|
|
14
|
+
private cleanupSizeObserver;
|
|
15
|
+
constructor(options: McpAppInitializationOptions, requestTimeout?: number);
|
|
16
|
+
static getInstance(options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridge;
|
|
17
|
+
subscribe(key: McpAppContextKey): Subscribe;
|
|
18
|
+
subscribe(keys: readonly McpAppContextKey[]): Subscribe;
|
|
19
|
+
getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
|
|
20
|
+
cleanup: () => void;
|
|
21
|
+
static resetInstance(): void;
|
|
22
|
+
request<R extends {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown;
|
|
25
|
+
}, T>({ method, params, }: R): Promise<T>;
|
|
26
|
+
private emit;
|
|
27
|
+
private updateContext;
|
|
28
|
+
private init;
|
|
29
|
+
private handleMessage;
|
|
30
|
+
private handleResponse;
|
|
31
|
+
private handleNotification;
|
|
32
|
+
private handleRequest;
|
|
33
|
+
private connect;
|
|
34
|
+
private notify;
|
|
35
|
+
private sendSizeChanged;
|
|
36
|
+
/**
|
|
37
|
+
* Set up automatic size change notifications using ResizeObserver.
|
|
38
|
+
* Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
|
|
39
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
|
|
40
|
+
*/
|
|
41
|
+
private setupSizeChangedNotifications;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const LATEST_PROTOCOL_VERSION = "2025-11-21";
|
|
2
|
+
var JsonRpcErrorCode;
|
|
3
|
+
(function (JsonRpcErrorCode) {
|
|
4
|
+
JsonRpcErrorCode[JsonRpcErrorCode["ParseError"] = -32700] = "ParseError";
|
|
5
|
+
JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
6
|
+
JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
7
|
+
JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
8
|
+
JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
|
|
9
|
+
})(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
|
|
10
|
+
export class McpAppBridge {
|
|
11
|
+
static instance = null;
|
|
12
|
+
context = {
|
|
13
|
+
toolInput: null,
|
|
14
|
+
toolCancelled: null,
|
|
15
|
+
toolResult: null,
|
|
16
|
+
};
|
|
17
|
+
listeners = new Map();
|
|
18
|
+
pendingRequests = new Map();
|
|
19
|
+
nextId = 1;
|
|
20
|
+
initialized;
|
|
21
|
+
appInitializationOptions;
|
|
22
|
+
requestTimeout;
|
|
23
|
+
cleanupSizeObserver = null;
|
|
24
|
+
constructor(options, requestTimeout = 10_000) {
|
|
25
|
+
this.requestTimeout = requestTimeout;
|
|
26
|
+
this.initialized = false;
|
|
27
|
+
this.appInitializationOptions = {
|
|
28
|
+
appInfo: options.appInfo,
|
|
29
|
+
appCapabilities: {},
|
|
30
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
31
|
+
};
|
|
32
|
+
this.init();
|
|
33
|
+
}
|
|
34
|
+
static getInstance(options, requestTimeout) {
|
|
35
|
+
if (window.skybridge.hostType !== "mcp-app") {
|
|
36
|
+
throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
|
|
37
|
+
}
|
|
38
|
+
if (McpAppBridge.instance && (options || requestTimeout)) {
|
|
39
|
+
console.warn("McpAppBridge.getInstance: options and requestTimeout ignored, instance already exists");
|
|
40
|
+
}
|
|
41
|
+
if (!McpAppBridge.instance) {
|
|
42
|
+
const defaultOptions = {
|
|
43
|
+
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
44
|
+
};
|
|
45
|
+
McpAppBridge.instance = new McpAppBridge({ ...defaultOptions, ...options }, requestTimeout);
|
|
46
|
+
}
|
|
47
|
+
return McpAppBridge.instance;
|
|
48
|
+
}
|
|
49
|
+
subscribe(keyOrKeys) {
|
|
50
|
+
const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
51
|
+
return (onChange) => {
|
|
52
|
+
for (const key of keys) {
|
|
53
|
+
this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
this.listeners.get(key)?.delete(onChange);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
getSnapshot(key) {
|
|
63
|
+
return this.context[key];
|
|
64
|
+
}
|
|
65
|
+
cleanup = () => {
|
|
66
|
+
window.removeEventListener("message", this.handleMessage);
|
|
67
|
+
this.pendingRequests.forEach((request) => {
|
|
68
|
+
clearTimeout(request.timeout);
|
|
69
|
+
});
|
|
70
|
+
this.pendingRequests.clear();
|
|
71
|
+
this.listeners.clear();
|
|
72
|
+
this.cleanupSizeObserver?.();
|
|
73
|
+
this.cleanupSizeObserver = null;
|
|
74
|
+
};
|
|
75
|
+
static resetInstance() {
|
|
76
|
+
if (McpAppBridge.instance) {
|
|
77
|
+
McpAppBridge.instance.cleanup();
|
|
78
|
+
McpAppBridge.instance = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
request({ method, params, }) {
|
|
82
|
+
const id = this.nextId++;
|
|
83
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
84
|
+
this.pendingRequests.set(id, {
|
|
85
|
+
resolve: resolve,
|
|
86
|
+
reject,
|
|
87
|
+
timeout: setTimeout(() => {
|
|
88
|
+
reject(new Error("Request timed out"));
|
|
89
|
+
this.pendingRequests.delete(id);
|
|
90
|
+
}, this.requestTimeout),
|
|
91
|
+
});
|
|
92
|
+
window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
|
|
93
|
+
return promise;
|
|
94
|
+
}
|
|
95
|
+
emit(key) {
|
|
96
|
+
this.listeners.get(key)?.forEach((listener) => {
|
|
97
|
+
listener();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
updateContext(context) {
|
|
101
|
+
this.context = { ...this.context, ...context };
|
|
102
|
+
for (const key of Object.keys(context)) {
|
|
103
|
+
this.emit(key);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
init() {
|
|
107
|
+
if (this.initialized) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.initialized = true;
|
|
111
|
+
if (typeof window === "undefined" || window.parent === window) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
window.addEventListener("message", this.handleMessage);
|
|
115
|
+
this.connect();
|
|
116
|
+
}
|
|
117
|
+
handleMessage = (event) => {
|
|
118
|
+
const data = event.data;
|
|
119
|
+
if (data.jsonrpc !== "2.0") {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if ("id" in data) {
|
|
123
|
+
if ("method" in data) {
|
|
124
|
+
this.handleRequest(data);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.handleResponse(data);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.handleNotification(data);
|
|
131
|
+
};
|
|
132
|
+
handleResponse(response) {
|
|
133
|
+
const request = this.pendingRequests.get(response.id);
|
|
134
|
+
if (request) {
|
|
135
|
+
clearTimeout(request.timeout);
|
|
136
|
+
this.pendingRequests.delete(response.id);
|
|
137
|
+
if ("error" in response) {
|
|
138
|
+
request.reject(new Error(response.error.message));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
request.resolve(response.result);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
handleNotification = (notification) => {
|
|
145
|
+
switch (notification.method) {
|
|
146
|
+
case "ui/notifications/host-context-changed":
|
|
147
|
+
this.updateContext(notification.params);
|
|
148
|
+
return;
|
|
149
|
+
case "ui/notifications/tool-input":
|
|
150
|
+
this.updateContext({
|
|
151
|
+
toolInput: notification.params.arguments ?? {},
|
|
152
|
+
});
|
|
153
|
+
return;
|
|
154
|
+
case "ui/notifications/tool-result":
|
|
155
|
+
this.updateContext({
|
|
156
|
+
toolResult: notification.params,
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
case "ui/notifications/tool-cancelled":
|
|
160
|
+
this.updateContext({
|
|
161
|
+
toolCancelled: notification.params,
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
handleRequest = (request) => {
|
|
167
|
+
switch (request.method) {
|
|
168
|
+
case "ui/resource-teardown":
|
|
169
|
+
this.cleanup();
|
|
170
|
+
window.parent.postMessage({
|
|
171
|
+
jsonrpc: "2.0",
|
|
172
|
+
id: request.id,
|
|
173
|
+
result: {},
|
|
174
|
+
}, "*");
|
|
175
|
+
return;
|
|
176
|
+
default:
|
|
177
|
+
window.parent.postMessage({
|
|
178
|
+
jsonrpc: "2.0",
|
|
179
|
+
id: request.id,
|
|
180
|
+
error: {
|
|
181
|
+
code: JsonRpcErrorCode.MethodNotFound,
|
|
182
|
+
message: "Unsupported Request",
|
|
183
|
+
},
|
|
184
|
+
}, "*");
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
async connect() {
|
|
188
|
+
try {
|
|
189
|
+
const result = await this.request({
|
|
190
|
+
method: "ui/initialize",
|
|
191
|
+
params: this.appInitializationOptions,
|
|
192
|
+
});
|
|
193
|
+
this.updateContext(result.hostContext);
|
|
194
|
+
this.notify({ method: "ui/notifications/initialized" });
|
|
195
|
+
this.cleanupSizeObserver = this.setupSizeChangedNotifications();
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
console.error(err);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
notify(notification) {
|
|
202
|
+
window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
|
|
203
|
+
}
|
|
204
|
+
sendSizeChanged(params) {
|
|
205
|
+
this.notify({ method: "ui/notifications/size-changed", params });
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Set up automatic size change notifications using ResizeObserver.
|
|
209
|
+
* Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
|
|
210
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
|
|
211
|
+
*/
|
|
212
|
+
setupSizeChangedNotifications() {
|
|
213
|
+
let scheduled = false;
|
|
214
|
+
let lastWidth = 0;
|
|
215
|
+
let lastHeight = 0;
|
|
216
|
+
const sendBodySizeChanged = () => {
|
|
217
|
+
if (scheduled) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
scheduled = true;
|
|
221
|
+
requestAnimationFrame(() => {
|
|
222
|
+
scheduled = false;
|
|
223
|
+
let width;
|
|
224
|
+
let height;
|
|
225
|
+
// In fullscreen mode, use viewport size since the widget should fill
|
|
226
|
+
// the entire available space provided by the host.
|
|
227
|
+
if (this.context.displayMode === "fullscreen") {
|
|
228
|
+
width = window.innerWidth;
|
|
229
|
+
height = window.innerHeight;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// Use scrollWidth/scrollHeight to measure actual rendered content size.
|
|
233
|
+
// This works better than fit-content for viewport-based layouts (vw/vh)
|
|
234
|
+
// and fluid elements like maps that want to fill available space.
|
|
235
|
+
const body = document.body;
|
|
236
|
+
width = Math.ceil(body.scrollWidth);
|
|
237
|
+
height = Math.ceil(body.scrollHeight);
|
|
238
|
+
}
|
|
239
|
+
// Only send if size actually changed (prevents feedback loops from
|
|
240
|
+
// style changes)
|
|
241
|
+
if (width !== lastWidth || height !== lastHeight) {
|
|
242
|
+
lastWidth = width;
|
|
243
|
+
lastHeight = height;
|
|
244
|
+
this.sendSizeChanged({ width, height });
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
sendBodySizeChanged();
|
|
249
|
+
const resizeObserver = new ResizeObserver(sendBodySizeChanged);
|
|
250
|
+
resizeObserver.observe(document.documentElement);
|
|
251
|
+
resizeObserver.observe(document.body);
|
|
252
|
+
return () => resizeObserver.disconnect();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=bridge.js.map
|