skybridge 1.0.2 → 1.0.3

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 (107) hide show
  1. package/dist/cli/resolve-views-dir.d.ts +1 -0
  2. package/dist/cli/resolve-views-dir.js +17 -0
  3. package/dist/cli/resolve-views-dir.js.map +1 -0
  4. package/dist/cli/use-open-tunnel-browser.d.ts +6 -0
  5. package/dist/cli/use-open-tunnel-browser.js +19 -0
  6. package/dist/cli/use-open-tunnel-browser.js.map +1 -0
  7. package/dist/cli/use-typescript-check.js +1 -1
  8. package/dist/cli/use-typescript-check.js.map +1 -1
  9. package/dist/commands/build.js +1 -16
  10. package/dist/commands/build.js.map +1 -1
  11. package/dist/commands/dev.js +19 -1
  12. package/dist/commands/dev.js.map +1 -1
  13. package/dist/server/content-helpers.d.ts +40 -0
  14. package/dist/server/content-helpers.js +33 -0
  15. package/dist/server/content-helpers.js.map +1 -1
  16. package/dist/server/file-ref.d.ts +20 -0
  17. package/dist/server/file-ref.js +19 -0
  18. package/dist/server/file-ref.js.map +1 -1
  19. package/dist/server/middleware.d.ts +16 -3
  20. package/dist/server/middleware.js.map +1 -1
  21. package/dist/server/server.d.ts +152 -0
  22. package/dist/server/server.js +142 -57
  23. package/dist/server/server.js.map +1 -1
  24. package/dist/test/view.test.js +45 -0
  25. package/dist/test/view.test.js.map +1 -1
  26. package/dist/web/bridges/apps-sdk/adaptor.d.ts +1 -0
  27. package/dist/web/bridges/apps-sdk/adaptor.js +1 -0
  28. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  29. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  30. package/dist/web/bridges/apps-sdk/bridge.js +1 -0
  31. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  32. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  33. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  34. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  35. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  36. package/dist/web/bridges/get-adaptor.js +7 -0
  37. package/dist/web/bridges/get-adaptor.js.map +1 -1
  38. package/dist/web/bridges/mcp-app/adaptor.d.ts +1 -0
  39. package/dist/web/bridges/mcp-app/adaptor.js +1 -0
  40. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  41. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -0
  42. package/dist/web/bridges/mcp-app/bridge.js +1 -0
  43. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  44. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
  45. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  46. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  47. package/dist/web/bridges/types.d.ts +47 -0
  48. package/dist/web/bridges/types.js.map +1 -1
  49. package/dist/web/bridges/use-host-context.d.ts +5 -0
  50. package/dist/web/bridges/use-host-context.js +5 -0
  51. package/dist/web/bridges/use-host-context.js.map +1 -1
  52. package/dist/web/create-store.d.ts +26 -0
  53. package/dist/web/create-store.js +26 -0
  54. package/dist/web/create-store.js.map +1 -1
  55. package/dist/web/data-llm.d.ts +33 -0
  56. package/dist/web/data-llm.js +28 -0
  57. package/dist/web/data-llm.js.map +1 -1
  58. package/dist/web/generate-helpers.d.ts +2 -0
  59. package/dist/web/generate-helpers.js +2 -0
  60. package/dist/web/generate-helpers.js.map +1 -1
  61. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  62. package/dist/web/hooks/use-call-tool.js +28 -0
  63. package/dist/web/hooks/use-call-tool.js.map +1 -1
  64. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  65. package/dist/web/hooks/use-display-mode.js +20 -0
  66. package/dist/web/hooks/use-display-mode.js.map +1 -1
  67. package/dist/web/hooks/use-files.d.ts +32 -0
  68. package/dist/web/hooks/use-files.js +32 -0
  69. package/dist/web/hooks/use-files.js.map +1 -1
  70. package/dist/web/hooks/use-layout.d.ts +2 -0
  71. package/dist/web/hooks/use-layout.js +2 -0
  72. package/dist/web/hooks/use-layout.js.map +1 -1
  73. package/dist/web/hooks/use-open-external.d.ts +17 -0
  74. package/dist/web/hooks/use-open-external.js +16 -0
  75. package/dist/web/hooks/use-open-external.js.map +1 -1
  76. package/dist/web/hooks/use-request-close.d.ts +14 -0
  77. package/dist/web/hooks/use-request-close.js +13 -0
  78. package/dist/web/hooks/use-request-close.js.map +1 -1
  79. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  80. package/dist/web/hooks/use-request-modal.js +16 -1
  81. package/dist/web/hooks/use-request-modal.js.map +1 -1
  82. package/dist/web/hooks/use-request-size.d.ts +17 -0
  83. package/dist/web/hooks/use-request-size.js +16 -0
  84. package/dist/web/hooks/use-request-size.js.map +1 -1
  85. package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
  86. package/dist/web/hooks/use-send-follow-up-message.js +17 -0
  87. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  88. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  89. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  90. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  91. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  92. package/dist/web/hooks/use-tool-info.js +26 -0
  93. package/dist/web/hooks/use-tool-info.js.map +1 -1
  94. package/dist/web/hooks/use-user.d.ts +2 -0
  95. package/dist/web/hooks/use-user.js +2 -0
  96. package/dist/web/hooks/use-user.js.map +1 -1
  97. package/dist/web/hooks/use-view-state.d.ts +21 -0
  98. package/dist/web/hooks/use-view-state.js.map +1 -1
  99. package/dist/web/mount-view.d.ts +19 -0
  100. package/dist/web/mount-view.js +19 -0
  101. package/dist/web/mount-view.js.map +1 -1
  102. package/dist/web/plugin/plugin.d.ts +28 -0
  103. package/dist/web/plugin/plugin.js +26 -0
  104. package/dist/web/plugin/plugin.js.map +1 -1
  105. package/dist/web/types.d.ts +4 -0
  106. package/dist/web/types.js.map +1 -1
  107. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/adaptor.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,OAAO,cAAc;IACjB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAE/C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IACjC,CAAC;IAEM,mBAAmB,CACxB,GAAM;QAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QAE3C,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,OAAO;gBACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC;gBAC1C,WAAW,EAAE,GAAG,EAAE,CAChB,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;aACnC,CAAC;QAC3B,CAAC;QAED,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO;gBACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;gBACnC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;aACvB,CAAC;QAC3B,CAAC;QAED,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;YAChC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SACpB,CAAC;IA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C,CAAC,MAAM,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,GAAG,OAAiB;QAC7C,MAAM,KAAK,GAAuB,MAAM,CAAC,MAAM,CAAC,WAAW;YACzD,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE;YAClC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QACtB,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAChC,MAAM,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEM,SAAS,CAAC,OAA4B;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC","sourcesContent":["import type {\n Adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n FileMetadata,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n UploadFileOptions,\n} from \"../types.js\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkWidgetState } from \"./types.js\";\n\nexport class AppsSdkAdaptor implements Adaptor {\n private static instance: AppsSdkAdaptor | null = null;\n\n public static getInstance(): AppsSdkAdaptor {\n if (!AppsSdkAdaptor.instance) {\n AppsSdkAdaptor.instance = new AppsSdkAdaptor();\n }\n return AppsSdkAdaptor.instance;\n }\n\n public static resetInstance(): void {\n AppsSdkAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n const bridge = AppsSdkBridge.getInstance();\n\n if (key === \"viewState\") {\n return {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n } as HostContextStore<K>;\n }\n\n if (key === \"display\") {\n return {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n } as HostContextStore<K>;\n }\n\n return {\n subscribe: bridge.subscribe(key),\n getSnapshot: () => bridge.getSnapshot(key),\n } as HostContextStore<K>;\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const response = await (window.openai.callTool(name, args) as Promise<\n CallToolResponse & { _meta?: CallToolResponse[\"meta\"] }\n >);\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? response.meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = (\n mode: RequestDisplayMode,\n ): Promise<{ mode: RequestDisplayMode }> => {\n return window.openai.requestDisplayMode({ mode });\n };\n\n public requestClose = (): Promise<void> => {\n return window.openai.requestClose();\n };\n\n public requestSize = async (_size: RequestSizeOptions): Promise<void> => {\n console.warn(\"[skybridge] requestSize: not supported on Apps SDK\");\n };\n\n public sendFollowUpMessage = (\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void> => {\n return window.openai.sendFollowUpMessage({\n prompt,\n scrollToBottom: options?.scrollToBottom,\n });\n };\n\n public download = async (\n _params: DownloadParams,\n ): Promise<DownloadResult> => {\n console.error(\"[skybridge] download: not supported on Apps SDK\");\n return { isError: true };\n };\n\n public openExternal(href: string, options: OpenExternalOptions = {}): void {\n window.openai.openExternal({ href, ...options });\n }\n\n public setViewState = (stateOrUpdater: SetViewStateAction): Promise<void> => {\n const modelContent =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(window.openai.widgetState?.modelContent ?? null)\n : stateOrUpdater;\n\n return window.openai.setWidgetState({\n privateContent: {},\n ...window.openai.widgetState,\n modelContent,\n });\n };\n\n public uploadFile = async (file: File, options?: UploadFileOptions) => {\n const metadata = await window.openai.uploadFile(file, options);\n await this.trackFileIds(metadata.fileId);\n return metadata;\n };\n\n public getFileDownloadUrl = (file: { fileId: string }) => {\n return window.openai.getFileDownloadUrl(file);\n };\n\n public selectFiles = async (): Promise<FileMetadata[]> => {\n if (!window.openai.selectFiles) {\n throw new Error(\n \"selectFiles is not supported by the current host version.\",\n );\n }\n const files = await window.openai.selectFiles();\n if (files.length > 0) {\n await this.trackFileIds(...files.map((f) => f.fileId));\n }\n return files;\n };\n\n private async trackFileIds(...fileIds: string[]): Promise<void> {\n const state: AppsSdkWidgetState = window.openai.widgetState\n ? { ...window.openai.widgetState }\n : { modelContent: {}, privateContent: {} };\n if (!state.imageIds) {\n state.imageIds = [];\n }\n state.imageIds.push(...fileIds);\n await window.openai.setWidgetState(state);\n }\n\n public openModal(options: RequestModalOptions) {\n return window.openai.requestModal(options);\n }\n\n public setOpenInAppUrl(href: string): Promise<void> {\n href = href.trim();\n\n if (!href) {\n throw new Error(\"The href parameter is required.\");\n }\n\n return window.openai.setOpenInAppUrl({ href });\n }\n}\n"]}
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/adaptor.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,6FAA6F;AAC7F,MAAM,OAAO,cA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,EAAE;YAClC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QACtB,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAChC,MAAM,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEM,SAAS,CAAC,OAA4B;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC","sourcesContent":["import type {\n Adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n FileMetadata,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n UploadFileOptions,\n} from \"../types.js\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkWidgetState } from \"./types.js\";\n\n/** @internal Apps SDK implementation of {@link Adaptor}. Resolved via {@link getAdaptor}. */\nexport class AppsSdkAdaptor implements Adaptor {\n private static instance: AppsSdkAdaptor | null = null;\n\n public static getInstance(): AppsSdkAdaptor {\n if (!AppsSdkAdaptor.instance) {\n AppsSdkAdaptor.instance = new AppsSdkAdaptor();\n }\n return AppsSdkAdaptor.instance;\n }\n\n public static resetInstance(): void {\n AppsSdkAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n const bridge = AppsSdkBridge.getInstance();\n\n if (key === \"viewState\") {\n return {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n } as HostContextStore<K>;\n }\n\n if (key === \"display\") {\n return {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n } as HostContextStore<K>;\n }\n\n return {\n subscribe: bridge.subscribe(key),\n getSnapshot: () => bridge.getSnapshot(key),\n } as HostContextStore<K>;\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const response = await (window.openai.callTool(name, args) as Promise<\n CallToolResponse & { _meta?: CallToolResponse[\"meta\"] }\n >);\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? response.meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = (\n mode: RequestDisplayMode,\n ): Promise<{ mode: RequestDisplayMode }> => {\n return window.openai.requestDisplayMode({ mode });\n };\n\n public requestClose = (): Promise<void> => {\n return window.openai.requestClose();\n };\n\n public requestSize = async (_size: RequestSizeOptions): Promise<void> => {\n console.warn(\"[skybridge] requestSize: not supported on Apps SDK\");\n };\n\n public sendFollowUpMessage = (\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void> => {\n return window.openai.sendFollowUpMessage({\n prompt,\n scrollToBottom: options?.scrollToBottom,\n });\n };\n\n public download = async (\n _params: DownloadParams,\n ): Promise<DownloadResult> => {\n console.error(\"[skybridge] download: not supported on Apps SDK\");\n return { isError: true };\n };\n\n public openExternal(href: string, options: OpenExternalOptions = {}): void {\n window.openai.openExternal({ href, ...options });\n }\n\n public setViewState = (stateOrUpdater: SetViewStateAction): Promise<void> => {\n const modelContent =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(window.openai.widgetState?.modelContent ?? null)\n : stateOrUpdater;\n\n return window.openai.setWidgetState({\n privateContent: {},\n ...window.openai.widgetState,\n modelContent,\n });\n };\n\n public uploadFile = async (file: File, options?: UploadFileOptions) => {\n const metadata = await window.openai.uploadFile(file, options);\n await this.trackFileIds(metadata.fileId);\n return metadata;\n };\n\n public getFileDownloadUrl = (file: { fileId: string }) => {\n return window.openai.getFileDownloadUrl(file);\n };\n\n public selectFiles = async (): Promise<FileMetadata[]> => {\n if (!window.openai.selectFiles) {\n throw new Error(\n \"selectFiles is not supported by the current host version.\",\n );\n }\n const files = await window.openai.selectFiles();\n if (files.length > 0) {\n await this.trackFileIds(...files.map((f) => f.fileId));\n }\n return files;\n };\n\n private async trackFileIds(...fileIds: string[]): Promise<void> {\n const state: AppsSdkWidgetState = window.openai.widgetState\n ? { ...window.openai.widgetState }\n : { modelContent: {}, privateContent: {} };\n if (!state.imageIds) {\n state.imageIds = [];\n }\n state.imageIds.push(...fileIds);\n await window.openai.setWidgetState(state);\n }\n\n public openModal(options: RequestModalOptions) {\n return window.openai.requestModal(options);\n }\n\n public setOpenInAppUrl(href: string): Promise<void> {\n href = href.trim();\n\n if (!href) {\n throw new Error(\"The href parameter is required.\");\n }\n\n return window.openai.setOpenInAppUrl({ href });\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { Bridge, Subscribe } from "../types.js";
2
2
  import { type AppsSdkContext } from "./types.js";
3
+ /** @internal Singleton bridge over `window.openai` events. Used by {@link AppsSdkAdaptor}. */
3
4
  export declare class AppsSdkBridge implements Bridge<AppsSdkContext> {
4
5
  private static instance;
5
6
  static getInstance(): AppsSdkBridge;
@@ -1,4 +1,5 @@
1
1
  import { SET_GLOBALS_EVENT_TYPE, } from "./types.js";
2
+ /** @internal Singleton bridge over `window.openai` events. Used by {@link AppsSdkAdaptor}. */
2
3
  export class AppsSdkBridge {
3
4
  static instance = null;
4
5
  static getInstance() {
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;YACxC,MAAM,CAAC,MAAM,KAAK,SAAS,EAC3B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC3B,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC;IAIM,SAAS,CACd,SAAmE;QAEnE,MAAM,IAAI,GAAsC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACtE,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChB,OAAO,CAAC,QAAoB,EAAE,EAAE;YAC9B,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;gBACjD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CACjC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CACjD,CAAC;gBACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBACD,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;gBAC/D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;YACtE,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,GAAG,CAAiC,GAAM,EAAE,EAAE;QAC9D,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","sourcesContent":["import type { Bridge, Subscribe } from \"../types.js\";\nimport {\n type AppsSdkContext,\n SET_GLOBALS_EVENT_TYPE,\n type SetGlobalsEvent,\n} from \"./types.js\";\n\nexport class AppsSdkBridge implements Bridge<AppsSdkContext> {\n private static instance: AppsSdkBridge | null = null;\n\n public static getInstance(): AppsSdkBridge {\n if (\n window.skybridge.hostType !== \"apps-sdk\" ||\n window.openai === undefined\n ) {\n throw new Error(\n \"Apps SDK Bridge can only be used in the apps-sdk runtime\",\n );\n }\n if (AppsSdkBridge.instance === null) {\n AppsSdkBridge.instance = new AppsSdkBridge();\n }\n return AppsSdkBridge.instance;\n }\n\n public static resetInstance(): void {\n if (AppsSdkBridge.instance) {\n AppsSdkBridge.instance = null;\n }\n }\n\n public subscribe(key: keyof AppsSdkContext): Subscribe;\n public subscribe(keys: readonly (keyof AppsSdkContext)[]): Subscribe;\n public subscribe(\n keyOrKeys: keyof AppsSdkContext | readonly (keyof AppsSdkContext)[],\n ): Subscribe {\n const keys: readonly (keyof AppsSdkContext)[] = Array.isArray(keyOrKeys)\n ? keyOrKeys\n : [keyOrKeys];\n return (onChange: () => void) => {\n const handleSetGlobal = (event: SetGlobalsEvent) => {\n const hasRelevantChange = keys.some(\n (key) => event.detail.globals[key] !== undefined,\n );\n if (!hasRelevantChange) {\n return;\n }\n onChange();\n };\n\n window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);\n };\n };\n }\n\n public getSnapshot = <K extends keyof AppsSdkContext>(key: K) => {\n if (window.openai === undefined) {\n throw new Error(\n `window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`,\n );\n }\n\n return window.openai[key];\n };\n}\n"]}
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AAEpB,8FAA8F;AAC9F,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;YACxC,MAAM,CAAC,MAAM,KAAK,SAAS,EAC3B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC3B,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC;IAIM,SAAS,CACd,SAAmE;QAEnE,MAAM,IAAI,GAAsC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACtE,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChB,OAAO,CAAC,QAAoB,EAAE,EAAE;YAC9B,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;gBACjD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CACjC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CACjD,CAAC;gBACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBACD,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;gBAC/D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;YACtE,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,GAAG,CAAiC,GAAM,EAAE,EAAE;QAC9D,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","sourcesContent":["import type { Bridge, Subscribe } from \"../types.js\";\nimport {\n type AppsSdkContext,\n SET_GLOBALS_EVENT_TYPE,\n type SetGlobalsEvent,\n} from \"./types.js\";\n\n/** @internal Singleton bridge over `window.openai` events. Used by {@link AppsSdkAdaptor}. */\nexport class AppsSdkBridge implements Bridge<AppsSdkContext> {\n private static instance: AppsSdkBridge | null = null;\n\n public static getInstance(): AppsSdkBridge {\n if (\n window.skybridge.hostType !== \"apps-sdk\" ||\n window.openai === undefined\n ) {\n throw new Error(\n \"Apps SDK Bridge can only be used in the apps-sdk runtime\",\n );\n }\n if (AppsSdkBridge.instance === null) {\n AppsSdkBridge.instance = new AppsSdkBridge();\n }\n return AppsSdkBridge.instance;\n }\n\n public static resetInstance(): void {\n if (AppsSdkBridge.instance) {\n AppsSdkBridge.instance = null;\n }\n }\n\n public subscribe(key: keyof AppsSdkContext): Subscribe;\n public subscribe(keys: readonly (keyof AppsSdkContext)[]): Subscribe;\n public subscribe(\n keyOrKeys: keyof AppsSdkContext | readonly (keyof AppsSdkContext)[],\n ): Subscribe {\n const keys: readonly (keyof AppsSdkContext)[] = Array.isArray(keyOrKeys)\n ? keyOrKeys\n : [keyOrKeys];\n return (onChange: () => void) => {\n const handleSetGlobal = (event: SetGlobalsEvent) => {\n const hasRelevantChange = keys.some(\n (key) => event.detail.globals[key] !== undefined,\n );\n if (!hasRelevantChange) {\n return;\n }\n onChange();\n };\n\n window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);\n };\n };\n }\n\n public getSnapshot = <K extends keyof AppsSdkContext>(key: K) => {\n if (window.openai === undefined) {\n throw new Error(\n `window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`,\n );\n }\n\n return window.openai[key];\n };\n}\n"]}
@@ -1,2 +1,13 @@
1
1
  import type { AppsSdkContext } from "./types.js";
2
+ /**
3
+ * Read a single key from the raw Apps SDK (`window.openai`) context.
4
+ *
5
+ * Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,
6
+ * `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
7
+ * this when you need ChatGPT-only fields not surfaced by the public hooks.
8
+ *
9
+ * Throws if called outside the Apps SDK runtime.
10
+ *
11
+ * @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context
12
+ */
2
13
  export declare function useAppsSdkContext<K extends keyof AppsSdkContext>(key: K): AppsSdkContext[K];
@@ -1,5 +1,16 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { AppsSdkBridge } from "./bridge.js";
3
+ /**
4
+ * Read a single key from the raw Apps SDK (`window.openai`) context.
5
+ *
6
+ * Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,
7
+ * `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for
8
+ * this when you need ChatGPT-only fields not surfaced by the public hooks.
9
+ *
10
+ * Throws if called outside the Apps SDK runtime.
11
+ *
12
+ * @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context
13
+ */
3
14
  export function useAppsSdkContext(key) {
4
15
  const bridge = AppsSdkBridge.getInstance();
5
16
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
@@ -1 +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","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkContext } from \"./types.js\";\n\nexport function useAppsSdkContext<K extends keyof AppsSdkContext>(\n key: K,\n): AppsSdkContext[K] {\n const bridge = AppsSdkBridge.getInstance();\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
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;;;;;;;;;;GAUG;AACH,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","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { AppsSdkBridge } from \"./bridge.js\";\nimport type { AppsSdkContext } from \"./types.js\";\n\n/**\n * Read a single key from the raw Apps SDK (`window.openai`) context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) which work in both Apps SDK and MCP Apps. Reach for\n * this when you need ChatGPT-only fields not surfaced by the public hooks.\n *\n * Throws if called outside the Apps SDK runtime.\n *\n * @see https://docs.skybridge.tech/api-reference/use-apps-sdk-context\n */\nexport function useAppsSdkContext<K extends keyof AppsSdkContext>(\n key: K,\n): AppsSdkContext[K] {\n const bridge = AppsSdkBridge.getInstance();\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
@@ -1,2 +1,9 @@
1
1
  import type { Adaptor } from "./types.js";
2
+ /**
3
+ * @internal
4
+ * Resolve the host-specific {@link Adaptor} based on `window.skybridge.hostType`.
5
+ * Prefer the documented hooks (`useCallTool`, `useViewState`, etc.) over
6
+ * calling this directly — it's the escape hatch used by the hooks themselves
7
+ * and by advanced integrations.
8
+ */
2
9
  export declare const getAdaptor: () => Adaptor;
@@ -1,5 +1,12 @@
1
1
  import { AppsSdkAdaptor } from "./apps-sdk/adaptor.js";
2
2
  import { McpAppAdaptor } from "./mcp-app/adaptor.js";
3
+ /**
4
+ * @internal
5
+ * Resolve the host-specific {@link Adaptor} based on `window.skybridge.hostType`.
6
+ * Prefer the documented hooks (`useCallTool`, `useViewState`, etc.) over
7
+ * calling this directly — it's the escape hatch used by the hooks themselves
8
+ * and by advanced integrations.
9
+ */
3
10
  export const getAdaptor = () => {
4
11
  return window.skybridge.hostType === "apps-sdk"
5
12
  ? AppsSdkAdaptor.getInstance()
@@ -1 +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","sourcesContent":["import { AppsSdkAdaptor } from \"./apps-sdk/adaptor.js\";\nimport { McpAppAdaptor } from \"./mcp-app/adaptor.js\";\nimport type { Adaptor } from \"./types.js\";\n\nexport const getAdaptor = (): Adaptor => {\n return window.skybridge.hostType === \"apps-sdk\"\n ? AppsSdkAdaptor.getInstance()\n : McpAppAdaptor.getInstance();\n};\n"]}
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;;;;;;GAMG;AACH,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","sourcesContent":["import { AppsSdkAdaptor } from \"./apps-sdk/adaptor.js\";\nimport { McpAppAdaptor } from \"./mcp-app/adaptor.js\";\nimport type { Adaptor } from \"./types.js\";\n\n/**\n * @internal\n * Resolve the host-specific {@link Adaptor} based on `window.skybridge.hostType`.\n * Prefer the documented hooks (`useCallTool`, `useViewState`, etc.) over\n * calling this directly — it's the escape hatch used by the hooks themselves\n * and by advanced integrations.\n */\nexport const getAdaptor = (): Adaptor => {\n return window.skybridge.hostType === \"apps-sdk\"\n ? AppsSdkAdaptor.getInstance()\n : McpAppAdaptor.getInstance();\n};\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { Adaptor, CallToolResponse, DownloadParams, DownloadResult, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, RequestSizeOptions, SendFollowUpMessageOptions, SetViewStateAction } from "../types.js";
2
+ /** @internal MCP Apps implementation of {@link Adaptor}. Resolved via {@link getAdaptor}. */
2
3
  export declare class McpAppAdaptor implements Adaptor {
3
4
  private static instance;
4
5
  private stores;
@@ -12,6 +12,7 @@ function findStorageKey(viewUUID) {
12
12
  }
13
13
  return undefined;
14
14
  }
15
+ /** @internal MCP Apps implementation of {@link Adaptor}. Resolved via {@link getAdaptor}. */
15
16
  export class McpAppAdaptor {
16
17
  static instance = null;
17
18
  stores;
@@ -1 +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;AAerC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,QAAQ,EA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CAAC;IAEO,sBAAsB,CAG5B,IAAU,EAAE,eAAkD;QAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,WAA0B,CAAC;QAE/B,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,WAAW,EAAE,GAAG,EAAE;gBAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;gBACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;gBAE1C,IAAI,WAAW,KAAK,SAAS,IAAI,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","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type {\n Adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n} from \"../types.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nconst STORAGE_PREFIX = \"sb:\";\nconst MAX_STORAGE_ENTRIES = 200;\n\nfunction findStorageKey(viewUUID: string): string | undefined {\n const suffix = `:${viewUUID}`;\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {\n return key;\n }\n }\n return undefined;\n}\n\nexport class McpAppAdaptor implements Adaptor {\n private static instance: McpAppAdaptor | null = null;\n private stores: {\n [K in keyof HostContext]: HostContextStore<K>;\n };\n private _viewState: HostContext[\"viewState\"] = null;\n private viewStateListeners = new Set<() => void>();\n private _viewUUID: string | null = null;\n\n private _displayState: HostContext[\"display\"] = {\n mode: \"inline\",\n };\n private displayListeners = new Set<() => void>();\n\n private constructor() {\n this.stores = this.initializeStores();\n this.subscribeToViewUUID();\n }\n\n public static getInstance(): McpAppAdaptor {\n if (!McpAppAdaptor.instance) {\n McpAppAdaptor.instance = new McpAppAdaptor();\n }\n return McpAppAdaptor.instance;\n }\n\n public static resetInstance(): void {\n McpAppAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n return this.stores[key];\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const app = await McpAppBridge.getInstance().getApp();\n const response = await app.callServerTool({\n name,\n arguments: args ?? undefined,\n });\n\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = async (mode: RequestDisplayMode) => {\n const app = await McpAppBridge.getInstance().getApp();\n return app.requestDisplayMode({ mode });\n };\n\n public requestClose = async (): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.requestTeardown();\n };\n\n public requestSize = async (size: RequestSizeOptions): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendSizeChanged(size);\n };\n\n public sendFollowUpMessage = async (\n prompt: string,\n _options?: SendFollowUpMessageOptions,\n ) => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendMessage({\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: prompt,\n },\n ],\n });\n };\n\n public download = async (params: DownloadParams): Promise<DownloadResult> => {\n const app = await McpAppBridge.getInstance().getApp();\n if (!app.getHostCapabilities()?.downloadFile) {\n console.error(\n \"[skybridge] download: host does not support ui/download-file\",\n );\n return { isError: true };\n }\n return app.downloadFile(params);\n };\n\n public openExternal(href: string, options?: OpenExternalOptions): void {\n if (options?.redirectUrl === false) {\n console.warn(\n \"[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.\",\n );\n }\n\n McpAppBridge.getInstance()\n .getApp()\n .then((app) => app.openLink({ url: href }))\n .catch((err) => {\n console.error(\"Failed to open external link:\", err);\n });\n }\n\n private initializeStores(): {\n [K in keyof HostContext]: HostContextStore<K>;\n } {\n return {\n theme: this.createHostContextStore(\n [\"theme\"],\n ({ theme }) => theme ?? \"light\",\n ),\n locale: this.createHostContextStore(\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: this.createHostContextStore(\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: this.createHostContextStore(\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: this.createHostContextStore(\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n\n return undefined;\n },\n ),\n userAgent: this.createHostContextStore(\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: this.createHostContextStore(\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n display: {\n subscribe: (onChange: () => void) => {\n this.displayListeners.add(onChange);\n return () => {\n this.displayListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._displayState,\n },\n viewState: {\n subscribe: (onChange: () => void) => {\n this.viewStateListeners.add(onChange);\n return () => {\n this.viewStateListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._viewState,\n },\n };\n }\n\n public setViewState = async (\n stateOrUpdater: SetViewStateAction,\n ): Promise<void> => {\n const newState =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(this._viewState)\n : stateOrUpdater;\n\n // must happen before the async bridge call to ensure the state is updated immediately for the UI,\n // otherwise successive calls to setViewState may have stale state\n this._viewState = newState;\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n\n this.persistToLocalStorage(newState);\n\n try {\n const app = await McpAppBridge.getInstance().getApp();\n await app.updateModelContext({\n structuredContent: newState,\n content: [{ type: \"text\", text: JSON.stringify(newState) }],\n });\n } catch (error) {\n console.error(\"Failed to update view state in MCP App.\", error);\n }\n };\n\n /**\n * @throws File upload is not supported in MCP App.\n */\n public uploadFile(): Promise<{ fileId: string }> {\n throw new Error(\"File upload is not supported in MCP App.\");\n }\n\n /**\n * @throws File download is not supported in MCP App.\n */\n public getFileDownloadUrl(): Promise<{ downloadUrl: string }> {\n throw new Error(\"File download is not supported in MCP App.\");\n }\n\n /**\n * @throws File selection is not supported in MCP App.\n */\n public selectFiles(): Promise<{ fileId: string }[]> {\n throw new Error(\"File selection is not supported in MCP App.\");\n }\n\n public openModal(options: RequestModalOptions) {\n this._displayState = { mode: \"modal\", params: options.params };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public closeModal() {\n this._displayState = { mode: \"inline\" };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public setOpenInAppUrl(_href: string): Promise<void> {\n throw new Error(\"setOpenInAppUrl is not implemented in MCP App.\");\n }\n\n private subscribeToViewUUID(): void {\n const bridge = McpAppBridge.getInstance();\n bridge.subscribe(\"toolResult\")(() => {\n const toolResult = bridge.getSnapshot(\"toolResult\");\n const viewUUID = (\n toolResult?._meta as Record<string, unknown> | undefined\n )?.viewUUID as string | undefined;\n\n if (viewUUID && viewUUID !== this._viewUUID) {\n this._viewUUID = viewUUID;\n this.restoreFromLocalStorage(viewUUID);\n }\n });\n }\n\n // localStorage keys: sb:{unix_ms}:{viewUUID}\n // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.\n private restoreFromLocalStorage(viewUUID: string): void {\n try {\n const existingKey = findStorageKey(viewUUID);\n if (existingKey) {\n const stored = localStorage.getItem(existingKey);\n if (stored !== null) {\n this._viewState = JSON.parse(stored);\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n }\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private persistToLocalStorage(state: Record<string, unknown> | null): void {\n if (!this._viewUUID || state === null) {\n return;\n }\n try {\n // Remove old key for this view, write with fresh timestamp (LRU)\n const oldKey = findStorageKey(this._viewUUID);\n if (oldKey) {\n localStorage.removeItem(oldKey);\n }\n const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;\n localStorage.setItem(newKey, JSON.stringify(state));\n\n // lru cleanup\n const keys: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX)) {\n keys.push(key);\n }\n }\n if (keys.length <= MAX_STORAGE_ENTRIES) {\n return;\n }\n keys.sort();\n const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);\n for (const key of toRemove) {\n localStorage.removeItem(key);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private createHostContextStore<\n const Keys extends readonly McpAppContextKey[],\n R,\n >(keys: Keys, computeSnapshot: (context: PickContext<Keys>) => R) {\n const bridge = McpAppBridge.getInstance();\n let cachedValue: R | undefined;\n\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n\n cachedValue = newValue;\n return newValue;\n },\n };\n }\n}\n"]}
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;AAerC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5D,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,6FAA6F;AAC7F,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,UAAU,GAA6B,IAAI,CAAC;IAC5C,kBAAkB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC3C,SAAS,GAAkB,IAAI,CAAC;IAEhC,aAAa,GAA2B;QAC9C,IAAI,EAAE,QAAQ;KACf,CAAC;IACM,gBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;IAEjD;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE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adaptor,\n CallToolResponse,\n DownloadParams,\n DownloadResult,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n RequestSizeOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n} from \"../types.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal */\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nconst STORAGE_PREFIX = \"sb:\";\nconst MAX_STORAGE_ENTRIES = 200;\n\nfunction findStorageKey(viewUUID: string): string | undefined {\n const suffix = `:${viewUUID}`;\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {\n return key;\n }\n }\n return undefined;\n}\n\n/** @internal MCP Apps implementation of {@link Adaptor}. Resolved via {@link getAdaptor}. */\nexport class McpAppAdaptor implements Adaptor {\n private static instance: McpAppAdaptor | null = null;\n private stores: {\n [K in keyof HostContext]: HostContextStore<K>;\n };\n private _viewState: HostContext[\"viewState\"] = null;\n private viewStateListeners = new Set<() => void>();\n private _viewUUID: string | null = null;\n\n private _displayState: HostContext[\"display\"] = {\n mode: \"inline\",\n };\n private displayListeners = new Set<() => void>();\n\n private constructor() {\n this.stores = this.initializeStores();\n this.subscribeToViewUUID();\n }\n\n public static getInstance(): McpAppAdaptor {\n if (!McpAppAdaptor.instance) {\n McpAppAdaptor.instance = new McpAppAdaptor();\n }\n return McpAppAdaptor.instance;\n }\n\n public static resetInstance(): void {\n McpAppAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n return this.stores[key];\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const app = await McpAppBridge.getInstance().getApp();\n const response = await app.callServerTool({\n name,\n arguments: args ?? undefined,\n });\n\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = async (mode: RequestDisplayMode) => {\n const app = await McpAppBridge.getInstance().getApp();\n return app.requestDisplayMode({ mode });\n };\n\n public requestClose = async (): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.requestTeardown();\n };\n\n public requestSize = async (size: RequestSizeOptions): Promise<void> => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendSizeChanged(size);\n };\n\n public sendFollowUpMessage = async (\n prompt: string,\n _options?: SendFollowUpMessageOptions,\n ) => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendMessage({\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: prompt,\n },\n ],\n });\n };\n\n public download = async (params: DownloadParams): Promise<DownloadResult> => {\n const app = await McpAppBridge.getInstance().getApp();\n if (!app.getHostCapabilities()?.downloadFile) {\n console.error(\n \"[skybridge] download: host does not support ui/download-file\",\n );\n return { isError: true };\n }\n return app.downloadFile(params);\n };\n\n public openExternal(href: string, options?: OpenExternalOptions): void {\n if (options?.redirectUrl === false) {\n console.warn(\n \"[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.\",\n );\n }\n\n McpAppBridge.getInstance()\n .getApp()\n .then((app) => app.openLink({ url: href }))\n .catch((err) => {\n console.error(\"Failed to open external link:\", err);\n });\n }\n\n private initializeStores(): {\n [K in keyof HostContext]: HostContextStore<K>;\n } {\n return {\n theme: this.createHostContextStore(\n [\"theme\"],\n ({ theme }) => theme ?? \"light\",\n ),\n locale: this.createHostContextStore(\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: this.createHostContextStore(\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: this.createHostContextStore(\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: this.createHostContextStore(\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n\n return undefined;\n },\n ),\n userAgent: this.createHostContextStore(\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: this.createHostContextStore(\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n display: {\n subscribe: (onChange: () => void) => {\n this.displayListeners.add(onChange);\n return () => {\n this.displayListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._displayState,\n },\n viewState: {\n subscribe: (onChange: () => void) => {\n this.viewStateListeners.add(onChange);\n return () => {\n this.viewStateListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._viewState,\n },\n };\n }\n\n public setViewState = async (\n stateOrUpdater: SetViewStateAction,\n ): Promise<void> => {\n const newState =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(this._viewState)\n : stateOrUpdater;\n\n // must happen before the async bridge call to ensure the state is updated immediately for the UI,\n // otherwise successive calls to setViewState may have stale state\n this._viewState = newState;\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n\n this.persistToLocalStorage(newState);\n\n try {\n const app = await McpAppBridge.getInstance().getApp();\n await app.updateModelContext({\n structuredContent: newState,\n content: [{ type: \"text\", text: JSON.stringify(newState) }],\n });\n } catch (error) {\n console.error(\"Failed to update view state in MCP App.\", error);\n }\n };\n\n /**\n * @throws File upload is not supported in MCP App.\n */\n public uploadFile(): Promise<{ fileId: string }> {\n throw new Error(\"File upload is not supported in MCP App.\");\n }\n\n /**\n * @throws File download is not supported in MCP App.\n */\n public getFileDownloadUrl(): Promise<{ downloadUrl: string }> {\n throw new Error(\"File download is not supported in MCP App.\");\n }\n\n /**\n * @throws File selection is not supported in MCP App.\n */\n public selectFiles(): Promise<{ fileId: string }[]> {\n throw new Error(\"File selection is not supported in MCP App.\");\n }\n\n public openModal(options: RequestModalOptions) {\n this._displayState = { mode: \"modal\", params: options.params };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public closeModal() {\n this._displayState = { mode: \"inline\" };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public setOpenInAppUrl(_href: string): Promise<void> {\n throw new Error(\"setOpenInAppUrl is not implemented in MCP App.\");\n }\n\n private subscribeToViewUUID(): void {\n const bridge = McpAppBridge.getInstance();\n bridge.subscribe(\"toolResult\")(() => {\n const toolResult = bridge.getSnapshot(\"toolResult\");\n const viewUUID = (\n toolResult?._meta as Record<string, unknown> | undefined\n )?.viewUUID as string | undefined;\n\n if (viewUUID && viewUUID !== this._viewUUID) {\n this._viewUUID = viewUUID;\n this.restoreFromLocalStorage(viewUUID);\n }\n });\n }\n\n // localStorage keys: sb:{unix_ms}:{viewUUID}\n // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.\n private restoreFromLocalStorage(viewUUID: string): void {\n try {\n const existingKey = findStorageKey(viewUUID);\n if (existingKey) {\n const stored = localStorage.getItem(existingKey);\n if (stored !== null) {\n this._viewState = JSON.parse(stored);\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n }\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private persistToLocalStorage(state: Record<string, unknown> | null): void {\n if (!this._viewUUID || state === null) {\n return;\n }\n try {\n // Remove old key for this view, write with fresh timestamp (LRU)\n const oldKey = findStorageKey(this._viewUUID);\n if (oldKey) {\n localStorage.removeItem(oldKey);\n }\n const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;\n localStorage.setItem(newKey, JSON.stringify(state));\n\n // lru cleanup\n const keys: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX)) {\n keys.push(key);\n }\n }\n if (keys.length <= MAX_STORAGE_ENTRIES) {\n return;\n }\n keys.sort();\n const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);\n for (const key of toRemove) {\n localStorage.removeItem(key);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private createHostContextStore<\n const Keys extends readonly McpAppContextKey[],\n R,\n >(keys: Keys, computeSnapshot: (context: PickContext<Keys>) => R) {\n const bridge = McpAppBridge.getInstance();\n let cachedValue: R | undefined;\n\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n\n cachedValue = newValue;\n return newValue;\n },\n };\n }\n}\n"]}
@@ -2,6 +2,7 @@ import { App } from "@modelcontextprotocol/ext-apps";
2
2
  import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
3
3
  import type { Bridge, Subscribe } from "../types.js";
4
4
  import type { McpAppContext, McpAppContextKey } from "./types.js";
5
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */
5
6
  export declare class McpAppBridge implements Bridge<McpAppContext> {
6
7
  private static instance;
7
8
  context: McpAppContext;
@@ -1,4 +1,5 @@
1
1
  import { App } from "@modelcontextprotocol/ext-apps";
2
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */
2
3
  export class McpAppBridge {
3
4
  static instance = null;
4
5
  context = {
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","source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AC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo);\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,6GAA6G;AAC7G,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,GAAG,CAAM;IACT,cAAc,CA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,CAAC,EAAE,QAAQ,CAAC,CAAC,CACxD,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,EAAE;gBACV,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC5C,CAAC;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,CAAgC,GAAM;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo);\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
@@ -3,5 +3,17 @@ import type { McpAppContext } from "./types.js";
3
3
  type McpAppInitializationOptions = {
4
4
  appInfo: Implementation;
5
5
  };
6
+ /**
7
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
8
+ *
9
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
10
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
11
+ * when you need protocol-level fields not surfaced by the public hooks.
12
+ *
13
+ * `options.appInfo` is honored only on the first call that creates the
14
+ * underlying bridge; subsequent calls reuse the singleton.
15
+ *
16
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
17
+ */
6
18
  export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
7
19
  export {};
@@ -1,5 +1,17 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { McpAppBridge } from "./bridge.js";
3
+ /**
4
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
5
+ *
6
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
7
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
8
+ * when you need protocol-level fields not surfaced by the public hooks.
9
+ *
10
+ * `options.appInfo` is honored only on the first call that creates the
11
+ * underlying bridge; subsequent calls reuse the singleton.
12
+ *
13
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
14
+ */
3
15
  export function useMcpAppContext(key, options) {
4
16
  const bridge = McpAppBridge.getInstance(options);
5
17
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
@@ -1 +1 @@
1
- {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
1
+ {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  import type { CallToolResult, EmbeddedResource, ResourceLink } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { useSyncExternalStore } from "react";
3
3
  import type { ViewHostType } from "../../server/index.js";
4
+ /**
5
+ * Globals injected on `window.skybridge` by the host. Tells the view which
6
+ * runtime it's running under and where to reach the MCP server.
7
+ */
4
8
  export type SkybridgeProperties = {
5
9
  hostType: ViewHostType;
6
10
  serverUrl: string;
@@ -10,26 +14,43 @@ declare global {
10
14
  skybridge: SkybridgeProperties;
11
15
  }
12
16
  }
17
+ /** Arguments passed to a tool call. `null` for tools that take no input. */
13
18
  export type CallToolArgs = Record<string, unknown> | null;
19
+ /**
20
+ * Result of a tool call as surfaced to the view: MCP `content` blocks plus
21
+ * the typed `structuredContent` and optional `meta`. `isError` is set when
22
+ * the server marks the call as failed.
23
+ */
14
24
  export type CallToolResponse = {
15
25
  content: CallToolResult["content"];
16
26
  structuredContent: NonNullable<CallToolResult["structuredContent"]>;
17
27
  isError: NonNullable<CallToolResult["isError"]>;
18
28
  meta?: CallToolResult["_meta"];
19
29
  };
30
+ /**
31
+ * How the view is laid out by the host. `"modal"` is host-driven (see
32
+ * {@link useRequestModal}); `"pip"`, `"inline"`, and `"fullscreen"` are
33
+ * requestable via {@link useDisplayMode}.
34
+ */
20
35
  export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
36
+ /** Subset of {@link DisplayMode} that the view can request from the host. */
21
37
  export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
38
+ /** Host theme. Mirror this in your view's styling for a native feel. */
22
39
  export type Theme = "light" | "dark";
40
+ /** Coarse device class reported by the host. `"unknown"` when unavailable. */
23
41
  export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
42
+ /** Pixel insets the view should keep clear of (notches, home indicators, etc.). */
24
43
  export type SafeAreaInsets = {
25
44
  top: number;
26
45
  right: number;
27
46
  bottom: number;
28
47
  left: number;
29
48
  };
49
+ /** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */
30
50
  export type SafeArea = {
31
51
  insets: SafeAreaInsets;
32
52
  };
53
+ /** Device and input-capability hints exposed via {@link useUser}. */
33
54
  export type UserAgent = {
34
55
  device: {
35
56
  type: DeviceType;
@@ -39,6 +60,11 @@ export type UserAgent = {
39
60
  touch: boolean;
40
61
  };
41
62
  };
63
+ /**
64
+ * Full snapshot of state the host exposes to the view. Most fields are
65
+ * better accessed through their dedicated hooks (`useLayout`, `useUser`,
66
+ * `useToolInfo`, etc.) — read this directly only for advanced cases.
67
+ */
42
68
  export interface HostContext {
43
69
  theme: Theme;
44
70
  locale: string;
@@ -55,26 +81,34 @@ export interface HostContext {
55
81
  };
56
82
  viewState: Record<string, unknown> | null;
57
83
  }
84
+ /** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */
58
85
  export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
86
+ /** @internal Bridge contract implemented by per-host bridge classes. */
59
87
  export interface Bridge<Context> {
60
88
  subscribe(key: keyof Context): Subscribe;
61
89
  subscribe(keys: readonly (keyof Context)[]): Subscribe;
62
90
  getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
63
91
  }
92
+ /** @internal Per-key snapshot store backing {@link useHostContext}. */
64
93
  export type HostContextStore<K extends keyof HostContext> = {
65
94
  subscribe: Subscribe;
66
95
  getSnapshot: () => HostContext[K];
67
96
  };
97
+ /** Persisted view state shape (a plain object). See {@link useViewState}. */
68
98
  export type ViewState = Record<string, unknown>;
99
+ /** Updater form accepted when writing to view state. */
69
100
  export type SetViewStateAction = ViewState | ((prevState: ViewState | null) => ViewState);
101
+ /** Reference to a host-managed file (returned by {@link useFiles}). */
70
102
  export type FileMetadata = {
71
103
  fileId: string;
72
104
  fileName?: string;
73
105
  mimeType?: string;
74
106
  };
107
+ /** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */
75
108
  export type UploadFileOptions = {
76
109
  library?: boolean;
77
110
  };
111
+ /** Options for {@link useRequestModal}'s `open` call. */
78
112
  export type RequestModalOptions = {
79
113
  title?: string;
80
114
  params?: Record<string, unknown>;
@@ -86,12 +120,19 @@ export type RequestModalOptions = {
86
120
  height?: number;
87
121
  };
88
122
  };
123
+ /**
124
+ * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the
125
+ * host not to append its `?redirectUrl=…` tracking query parameter when
126
+ * opening allowlisted targets.
127
+ */
89
128
  export type OpenExternalOptions = {
90
129
  redirectUrl?: false;
91
130
  };
131
+ /** Options for {@link useSendFollowUpMessage}. */
92
132
  export type SendFollowUpMessageOptions = {
93
133
  scrollToBottom?: boolean;
94
134
  };
135
+ /** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */
95
136
  export type RequestSizeOptions = {
96
137
  width?: number;
97
138
  height?: number;
@@ -102,6 +143,12 @@ export type DownloadParams = {
102
143
  export type DownloadResult = {
103
144
  isError?: boolean;
104
145
  };
146
+ /**
147
+ * @internal
148
+ * Low-level interface every host bridge implements. End-user code should use
149
+ * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than
150
+ * calling this directly.
151
+ */
105
152
  export interface Adaptor {
106
153
  getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
107
154
  callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\nexport type CallToolArgs = Record<string, unknown> | null;\n\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\nexport type Theme = \"light\" | \"dark\";\n\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\nexport type ViewState = Record<string, unknown>;\n\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\nexport type UploadFileOptions = { library?: boolean };\n\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\n/** Device and input-capability hints exposed via {@link useUser}. */\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\n/**\n * Full snapshot of state the host exposes to the view. Most fields are\n * better accessed through their dedicated hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) — read this directly only for advanced cases.\n */\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\n/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\n/** @internal Bridge contract implemented by per-host bridge classes. */\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\n/** @internal Per-key snapshot store backing {@link useHostContext}. */\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\n/** Persisted view state shape (a plain object). See {@link useViewState}. */\nexport type ViewState = Record<string, unknown>;\n\n/** Updater form accepted when writing to view state. */\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\n/** Reference to a host-managed file (returned by {@link useFiles}). */\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\n/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */\nexport type UploadFileOptions = { library?: boolean };\n\n/** Options for {@link useRequestModal}'s `open` call. */\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\n/**\n * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the\n * host not to append its `?redirectUrl=…` tracking query parameter when\n * opening allowlisted targets.\n */\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\n/** Options for {@link useSendFollowUpMessage}. */\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\n/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\n/**\n * @internal\n * Low-level interface every host bridge implements. End-user code should use\n * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than\n * calling this directly.\n */\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
@@ -1,2 +1,7 @@
1
1
  import type { HostContext } from "./types.js";
2
+ /**
3
+ * @internal
4
+ * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
5
+ * Used to build the higher-level hooks; prefer those for app code.
6
+ */
2
7
  export declare const useHostContext: <K extends keyof HostContext>(key: K) => HostContext[K];
@@ -1,5 +1,10 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { getAdaptor } from "./get-adaptor.js";
3
+ /**
4
+ * @internal
5
+ * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
6
+ * Used to build the higher-level hooks; prefer those for app code.
7
+ */
3
8
  export const useHostContext = (key) => {
4
9
  const adaptor = getAdaptor();
5
10
  const store = adaptor.getHostContextStore(key);
@@ -1 +1 @@
1
- {"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
1
+ {"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\n/**\n * @internal\n * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.\n * Used to build the higher-level hooks; prefer those for app code.\n */\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
@@ -1,3 +1,29 @@
1
1
  import { type StateCreator } from "zustand";
2
2
  import type { UnknownObject } from "./types.js";
3
+ /**
4
+ * Create a Zustand store that is bidirectionally synced with the host's
5
+ * `viewState`. Local store updates persist to the host, and external host
6
+ * updates rehydrate the store — making the store the single source of truth
7
+ * for state that should survive view remounts.
8
+ *
9
+ * Use this when you outgrow {@link useViewState} and want first-class Zustand
10
+ * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
11
+ *
12
+ * Skybridge-internal context fields (see {@link DataLLM}) are filtered out
13
+ * automatically before reaching your store.
14
+ *
15
+ * @typeParam State - Shape of the store's state. Must be a plain object.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * export const useStore = createStore<{ count: number; inc: () => void }>(
20
+ * (set) => ({
21
+ * count: 0,
22
+ * inc: () => set((s) => ({ count: s.count + 1 })),
23
+ * }),
24
+ * );
25
+ * ```
26
+ *
27
+ * @see https://docs.skybridge.tech/api-reference/create-store
28
+ */
3
29
  export declare function createStore<State extends UnknownObject>(storeCreator: StateCreator<State, [], [], State>, defaultState?: State | (() => State)): import("zustand").UseBoundStore<import("zustand").StoreApi<State>>;