skybridge 0.0.0-dev.f40327b → 0.0.0-dev.f40afe0

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 (214) hide show
  1. package/README.md +1 -0
  2. package/dist/cli/build-helpers.d.ts +10 -0
  3. package/dist/cli/build-helpers.js +93 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.d.ts +1 -0
  6. package/dist/cli/build-helpers.test.js +89 -0
  7. package/dist/cli/build-helpers.test.js.map +1 -0
  8. package/dist/cli/build-steps.d.ts +2 -0
  9. package/dist/cli/build-steps.js +68 -0
  10. package/dist/cli/build-steps.js.map +1 -0
  11. package/dist/cli/build-steps.test.d.ts +1 -0
  12. package/dist/cli/build-steps.test.js +52 -0
  13. package/dist/cli/build-steps.test.js.map +1 -0
  14. package/dist/cli/detect-port.d.ts +2 -2
  15. package/dist/cli/detect-port.js +9 -20
  16. package/dist/cli/detect-port.js.map +1 -1
  17. package/dist/cli/header.d.ts +1 -1
  18. package/dist/cli/resolve-views-dir.d.ts +1 -0
  19. package/dist/cli/resolve-views-dir.js +17 -0
  20. package/dist/cli/resolve-views-dir.js.map +1 -0
  21. package/dist/cli/run-plain.d.ts +18 -0
  22. package/dist/cli/run-plain.js +89 -0
  23. package/dist/cli/run-plain.js.map +1 -0
  24. package/dist/cli/start-tunnel-view-build.d.ts +1 -0
  25. package/dist/cli/start-tunnel-view-build.js +16 -0
  26. package/dist/cli/start-tunnel-view-build.js.map +1 -0
  27. package/dist/cli/use-execute-steps.d.ts +1 -1
  28. package/dist/cli/use-nodemon.d.ts +14 -0
  29. package/dist/cli/use-nodemon.js +71 -60
  30. package/dist/cli/use-nodemon.js.map +1 -1
  31. package/dist/cli/use-typescript-check.d.ts +8 -2
  32. package/dist/cli/use-typescript-check.js +70 -67
  33. package/dist/cli/use-typescript-check.js.map +1 -1
  34. package/dist/commands/build.d.ts +0 -3
  35. package/dist/commands/build.js +2 -73
  36. package/dist/commands/build.js.map +1 -1
  37. package/dist/commands/dev.d.ts +1 -0
  38. package/dist/commands/dev.js +57 -0
  39. package/dist/commands/dev.js.map +1 -1
  40. package/dist/commands/start.js +7 -1
  41. package/dist/commands/start.js.map +1 -1
  42. package/dist/server/auth/discovery.d.ts +32 -0
  43. package/dist/server/auth/discovery.js +56 -0
  44. package/dist/server/auth/discovery.js.map +1 -0
  45. package/dist/server/auth/discovery.test.d.ts +1 -0
  46. package/dist/server/auth/discovery.test.js +93 -0
  47. package/dist/server/auth/discovery.test.js.map +1 -0
  48. package/dist/server/auth/index.d.ts +18 -0
  49. package/dist/server/auth/index.js +2 -0
  50. package/dist/server/auth/index.js.map +1 -0
  51. package/dist/server/auth/providers/auth0.d.ts +18 -0
  52. package/dist/server/auth/providers/auth0.js +31 -0
  53. package/dist/server/auth/providers/auth0.js.map +1 -0
  54. package/dist/server/auth/providers/auth0.test.d.ts +1 -0
  55. package/dist/server/auth/providers/auth0.test.js +48 -0
  56. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  57. package/dist/server/auth/providers/clerk.d.ts +14 -0
  58. package/dist/server/auth/providers/clerk.js +16 -0
  59. package/dist/server/auth/providers/clerk.js.map +1 -0
  60. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  61. package/dist/server/auth/providers/clerk.test.js +28 -0
  62. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  63. package/dist/server/auth/providers/custom.d.ts +24 -0
  64. package/dist/server/auth/providers/custom.js +37 -0
  65. package/dist/server/auth/providers/custom.js.map +1 -0
  66. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  67. package/dist/server/auth/providers/custom.test.js +107 -0
  68. package/dist/server/auth/providers/custom.test.js.map +1 -0
  69. package/dist/server/auth/providers/descope.d.ts +15 -0
  70. package/dist/server/auth/providers/descope.js +33 -0
  71. package/dist/server/auth/providers/descope.js.map +1 -0
  72. package/dist/server/auth/providers/descope.test.d.ts +1 -0
  73. package/dist/server/auth/providers/descope.test.js +37 -0
  74. package/dist/server/auth/providers/descope.test.js.map +1 -0
  75. package/dist/server/auth/providers/shared.d.ts +2 -0
  76. package/dist/server/auth/providers/shared.js +6 -0
  77. package/dist/server/auth/providers/shared.js.map +1 -0
  78. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  79. package/dist/server/auth/providers/shared.test.js +10 -0
  80. package/dist/server/auth/providers/shared.test.js.map +1 -0
  81. package/dist/server/auth/providers/stytch.d.ts +12 -0
  82. package/dist/server/auth/providers/stytch.js +13 -0
  83. package/dist/server/auth/providers/stytch.js.map +1 -0
  84. package/dist/server/auth/providers/workos.d.ts +11 -0
  85. package/dist/server/auth/providers/workos.js +12 -0
  86. package/dist/server/auth/providers/workos.js.map +1 -0
  87. package/dist/server/auth/setup.d.ts +4 -0
  88. package/dist/server/auth/setup.js +51 -0
  89. package/dist/server/auth/setup.js.map +1 -0
  90. package/dist/server/auth/setup.test.d.ts +1 -0
  91. package/dist/server/auth/setup.test.js +185 -0
  92. package/dist/server/auth/setup.test.js.map +1 -0
  93. package/dist/server/auth/verify.d.ts +12 -0
  94. package/dist/server/auth/verify.js +38 -0
  95. package/dist/server/auth/verify.js.map +1 -0
  96. package/dist/server/auth/verify.test.d.ts +1 -0
  97. package/dist/server/auth/verify.test.js +100 -0
  98. package/dist/server/auth/verify.test.js.map +1 -0
  99. package/dist/server/build-manifest.test.d.ts +1 -0
  100. package/dist/server/build-manifest.test.js +27 -0
  101. package/dist/server/build-manifest.test.js.map +1 -0
  102. package/dist/server/express.js +3 -0
  103. package/dist/server/express.js.map +1 -1
  104. package/dist/server/express.test.js +61 -0
  105. package/dist/server/express.test.js.map +1 -1
  106. package/dist/server/index.d.ts +9 -2
  107. package/dist/server/index.js +7 -1
  108. package/dist/server/index.js.map +1 -1
  109. package/dist/server/requestOrigin.d.ts +7 -0
  110. package/dist/server/requestOrigin.js +25 -0
  111. package/dist/server/requestOrigin.js.map +1 -0
  112. package/dist/server/server.d.ts +56 -35
  113. package/dist/server/server.js +232 -136
  114. package/dist/server/server.js.map +1 -1
  115. package/dist/server/view-name.test-d.d.ts +1 -0
  116. package/dist/server/view-name.test-d.js +8 -0
  117. package/dist/server/view-name.test-d.js.map +1 -0
  118. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  119. package/dist/server/view-resource-resolution.test.js +207 -0
  120. package/dist/server/view-resource-resolution.test.js.map +1 -0
  121. package/dist/test/view.test.js +69 -101
  122. package/dist/test/view.test.js.map +1 -1
  123. package/dist/web/bridges/adaptor.d.ts +51 -0
  124. package/dist/web/bridges/adaptor.js +330 -0
  125. package/dist/web/bridges/adaptor.js.map +1 -0
  126. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  127. package/dist/web/bridges/adaptor.test.js +208 -0
  128. package/dist/web/bridges/adaptor.test.js.map +1 -0
  129. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  130. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  131. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  132. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  133. package/dist/web/bridges/apps-sdk/index.js +0 -1
  134. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  135. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  136. package/dist/web/bridges/get-adaptor.js +6 -11
  137. package/dist/web/bridges/get-adaptor.js.map +1 -1
  138. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  139. package/dist/web/bridges/get-adaptor.test.js +32 -0
  140. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  141. package/dist/web/bridges/mcp-app/bridge.d.ts +15 -3
  142. package/dist/web/bridges/mcp-app/bridge.js +68 -5
  143. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  144. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  145. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  146. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  147. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  148. package/dist/web/bridges/mcp-app/index.js +0 -1
  149. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  150. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  151. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  152. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  153. package/dist/web/bridges/types.d.ts +44 -1
  154. package/dist/web/bridges/types.js +14 -1
  155. package/dist/web/bridges/types.js.map +1 -1
  156. package/dist/web/bridges/types.test.d.ts +1 -0
  157. package/dist/web/bridges/types.test.js +19 -0
  158. package/dist/web/bridges/types.test.js.map +1 -0
  159. package/dist/web/components/modal-provider.d.ts +1 -1
  160. package/dist/web/components/modal-provider.js +4 -3
  161. package/dist/web/components/modal-provider.js.map +1 -1
  162. package/dist/web/create-store.test.js +8 -5
  163. package/dist/web/create-store.test.js.map +1 -1
  164. package/dist/web/data-llm.d.ts +1 -1
  165. package/dist/web/data-llm.test.js +17 -5
  166. package/dist/web/data-llm.test.js.map +1 -1
  167. package/dist/web/generate-helpers.test-d.js +4 -2
  168. package/dist/web/generate-helpers.test-d.js.map +1 -1
  169. package/dist/web/hooks/index.d.ts +1 -0
  170. package/dist/web/hooks/index.js +1 -0
  171. package/dist/web/hooks/index.js.map +1 -1
  172. package/dist/web/hooks/use-call-tool.test.js +37 -23
  173. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  174. package/dist/web/hooks/use-display-mode.test.js +56 -20
  175. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  176. package/dist/web/hooks/use-download.test.js +11 -3
  177. package/dist/web/hooks/use-download.test.js.map +1 -1
  178. package/dist/web/hooks/use-files.test.js +10 -2
  179. package/dist/web/hooks/use-files.test.js.map +1 -1
  180. package/dist/web/hooks/use-layout.test.js +59 -26
  181. package/dist/web/hooks/use-layout.test.js.map +1 -1
  182. package/dist/web/hooks/use-open-external.test.js +13 -3
  183. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  184. package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
  185. package/dist/web/hooks/use-register-view-tool.js +50 -0
  186. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  187. package/dist/web/hooks/use-request-close.test.js +35 -40
  188. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  189. package/dist/web/hooks/use-request-modal.test.js +10 -0
  190. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  191. package/dist/web/hooks/use-request-size.test.js +35 -53
  192. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  193. package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
  194. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  195. package/dist/web/hooks/use-tool-info.d.ts +25 -7
  196. package/dist/web/hooks/use-tool-info.js +5 -8
  197. package/dist/web/hooks/use-tool-info.js.map +1 -1
  198. package/dist/web/hooks/use-tool-info.test-d.js +11 -29
  199. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  200. package/dist/web/hooks/use-tool-info.test.js +42 -32
  201. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  202. package/dist/web/hooks/use-user.test.js +81 -35
  203. package/dist/web/hooks/use-user.test.js.map +1 -1
  204. package/dist/web/hooks/use-view-state.test.js +6 -2
  205. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  206. package/dist/web/plugin/plugin.js +0 -1
  207. package/dist/web/plugin/plugin.js.map +1 -1
  208. package/package.json +22 -19
  209. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -28
  210. package/dist/web/bridges/apps-sdk/adaptor.js +0 -113
  211. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  212. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -52
  213. package/dist/web/bridges/mcp-app/adaptor.js +0 -280
  214. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
@@ -1,11 +1,10 @@
1
1
  import { SET_GLOBALS_EVENT_TYPE, } from "./types.js";
2
- /** @internal Singleton bridge over `window.openai` events. Used by {@link AppsSdkAdaptor}. */
2
+ /** @internal Singleton bridge over `window.openai` events. Used by `HostAdaptor`. */
3
3
  export class AppsSdkBridge {
4
4
  static instance = null;
5
5
  static getInstance() {
6
- if (window.skybridge.hostType !== "apps-sdk" ||
7
- window.openai === undefined) {
8
- throw new Error("Apps SDK Bridge can only be used in the apps-sdk runtime");
6
+ if (window.openai === undefined) {
7
+ throw new Error("Apps SDK Bridge requires window.openai (Apps SDK runtime).");
9
8
  }
10
9
  if (AppsSdkBridge.instance === null) {
11
10
  AppsSdkBridge.instance = new AppsSdkBridge();
@@ -43,5 +42,17 @@ export class AppsSdkBridge {
43
42
  }
44
43
  return window.openai[key];
45
44
  };
45
+ createOverlayStores() {
46
+ return {
47
+ display: {
48
+ subscribe: this.subscribe("view"),
49
+ getSnapshot: () => this.getSnapshot("view"),
50
+ },
51
+ viewState: {
52
+ subscribe: this.subscribe("widgetState"),
53
+ getSnapshot: () => this.getSnapshot("widgetState")?.modelContent ?? null,
54
+ },
55
+ };
56
+ }
46
57
  }
47
58
  //# sourceMappingURL=bridge.js.map
@@ -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,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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YPE,\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
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;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C,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;IAEK,mBAAmB;QAIxB,OAAO;YACL,OAAO,EAAE;gBACP,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBACjC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;aAC5C;YACD,SAAS,EAAE;gBACT,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;gBACxC,WAAW,EAAE,GAAG,EAAE,CAChB,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;aACxD;SACF,CAAC;IACJ,CAAC","sourcesContent":["import type { Bridge, HostContextStore, 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 `HostAdaptor`. */\nexport class AppsSdkBridge implements Bridge<AppsSdkContext> {\n private static instance: AppsSdkBridge | null = null;\n\n public static getInstance(): AppsSdkBridge {\n if (window.openai === undefined) {\n throw new Error(\n \"Apps SDK Bridge requires window.openai (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 public createOverlayStores(): {\n display: HostContextStore<\"display\">;\n viewState: HostContextStore<\"viewState\">;\n } {\n return {\n display: {\n subscribe: this.subscribe(\"view\"),\n getSnapshot: () => this.getSnapshot(\"view\"),\n },\n viewState: {\n subscribe: this.subscribe(\"widgetState\"),\n getSnapshot: () =>\n this.getSnapshot(\"widgetState\")?.modelContent ?? null,\n },\n };\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- export { AppsSdkAdaptor } from "./adaptor.js";
2
1
  export { AppsSdkBridge } from "./bridge.js";
3
2
  export type { AppsSdkContext, AppsSdkMethods, AppsSdkWidgetState, ToolResponseEvent, } from "./types.js";
4
3
  export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, TOOL_RESPONSE_EVENT_TYPE, } from "./types.js";
@@ -1,4 +1,3 @@
1
- export { AppsSdkAdaptor } from "./adaptor.js";
2
1
  export { AppsSdkBridge } from "./bridge.js";
3
2
  export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, TOOL_RESPONSE_EVENT_TYPE, } from "./types.js";
4
3
  export { useAppsSdkContext } from "./use-apps-sdk-context.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { AppsSdkAdaptor } from \"./adaptor.js\";\nexport { AppsSdkBridge } from \"./bridge.js\";\nexport type {\n AppsSdkContext,\n AppsSdkMethods,\n AppsSdkWidgetState,\n ToolResponseEvent,\n} from \"./types.js\";\nexport {\n SET_GLOBALS_EVENT_TYPE,\n SetGlobalsEvent,\n TOOL_RESPONSE_EVENT_TYPE,\n} from \"./types.js\";\nexport { useAppsSdkContext } from \"./use-apps-sdk-context.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { AppsSdkBridge } from \"./bridge.js\";\nexport type {\n AppsSdkContext,\n AppsSdkMethods,\n AppsSdkWidgetState,\n ToolResponseEvent,\n} from \"./types.js\";\nexport {\n SET_GLOBALS_EVENT_TYPE,\n SetGlobalsEvent,\n TOOL_RESPONSE_EVENT_TYPE,\n} from \"./types.js\";\nexport { useAppsSdkContext } from \"./use-apps-sdk-context.js\";\n"]}
@@ -1,9 +1,9 @@
1
1
  import type { Adaptor } from "./types.js";
2
2
  /**
3
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.
4
+ * Resolve the single host {@link Adaptor} instance. Prefer the documented
5
+ * hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;
6
+ * it's the escape hatch used by the hooks themselves and by advanced
7
+ * integrations.
8
8
  */
9
9
  export declare const getAdaptor: () => Adaptor;
@@ -1,15 +1,10 @@
1
- import { AppsSdkAdaptor } from "./apps-sdk/adaptor.js";
2
- import { McpAppAdaptor } from "./mcp-app/adaptor.js";
1
+ import { HostAdaptor } from "./adaptor.js";
3
2
  /**
4
3
  * @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.
4
+ * Resolve the single host {@link Adaptor} instance. Prefer the documented
5
+ * hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;
6
+ * it's the escape hatch used by the hooks themselves and by advanced
7
+ * integrations.
9
8
  */
10
- export const getAdaptor = () => {
11
- return window.skybridge.hostType === "apps-sdk"
12
- ? AppsSdkAdaptor.getInstance()
13
- : McpAppAdaptor.getInstance();
14
- };
9
+ export const getAdaptor = () => HostAdaptor.getInstance();
15
10
  //# sourceMappingURL=get-adaptor.js.map
@@ -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;;;;;;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
+ {"version":3,"file":"get-adaptor.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import { HostAdaptor } from \"./adaptor.js\";\nimport type { Adaptor } from \"./types.js\";\n\n/**\n * @internal\n * Resolve the single host {@link Adaptor} instance. Prefer the documented\n * hooks (`useCallTool`, `useViewState`, etc.) over calling this directly;\n * it's the escape hatch used by the hooks themselves and by advanced\n * integrations.\n */\nexport const getAdaptor = (): Adaptor => HostAdaptor.getInstance();\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { HostAdaptor } from "./adaptor.js";
3
+ import { AppsSdkBridge } from "./apps-sdk/bridge.js";
4
+ import { getAdaptor } from "./get-adaptor.js";
5
+ import { McpAppBridge } from "./mcp-app/bridge.js";
6
+ describe("getAdaptor", () => {
7
+ beforeEach(() => {
8
+ HostAdaptor.resetInstance();
9
+ McpAppBridge.resetInstance();
10
+ AppsSdkBridge.resetInstance();
11
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
12
+ });
13
+ afterEach(() => {
14
+ vi.unstubAllGlobals();
15
+ HostAdaptor.resetInstance();
16
+ McpAppBridge.resetInstance();
17
+ AppsSdkBridge.resetInstance();
18
+ });
19
+ it("returns a HostAdaptor instance", () => {
20
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
21
+ vi.stubGlobal("openai", undefined);
22
+ expect(getAdaptor()).toBeInstanceOf(HostAdaptor);
23
+ });
24
+ it("memoizes the instance", () => {
25
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
26
+ vi.stubGlobal("openai", undefined);
27
+ const a = getAdaptor();
28
+ const b = getAdaptor();
29
+ expect(a).toBe(b);
30
+ });
31
+ });
32
+ //# sourceMappingURL=get-adaptor.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-adaptor.test.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CAAC,aAAa,EAAE,CAAC;QAC9B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"./adaptor.js\";\nimport { AppsSdkBridge } from \"./apps-sdk/bridge.js\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport { McpAppBridge } from \"./mcp-app/bridge.js\";\n\ndescribe(\"getAdaptor\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"returns a HostAdaptor instance\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n expect(getAdaptor()).toBeInstanceOf(HostAdaptor);\n });\n\n it(\"memoizes the instance\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n const a = getAdaptor();\n const b = getAdaptor();\n expect(a).toBe(b);\n });\n});\n"]}
@@ -1,8 +1,8 @@
1
1
  import { App } from "@modelcontextprotocol/ext-apps";
2
- import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
3
- import type { Bridge, Subscribe } from "../types.js";
2
+ import { type Implementation } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { AnyViewToolHandler, Bridge, HostContextStore, Subscribe, ViewToolConfig } 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
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
6
6
  export declare class McpAppBridge implements Bridge<McpAppContext> {
7
7
  private static instance;
8
8
  context: McpAppContext;
@@ -14,12 +14,24 @@ export declare class McpAppBridge implements Bridge<McpAppContext> {
14
14
  });
15
15
  private connect;
16
16
  getApp(): Promise<App>;
17
+ registerViewTool(config: ViewToolConfig, handler: AnyViewToolHandler): () => void;
17
18
  static getInstance(options?: Partial<{
18
19
  appInfo: Implementation;
19
20
  }>): McpAppBridge;
20
21
  subscribe(key: McpAppContextKey): Subscribe;
21
22
  subscribe(keys: readonly McpAppContextKey[]): Subscribe;
22
23
  getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
24
+ createContextStores(): {
25
+ theme: HostContextStore<"theme">;
26
+ locale: HostContextStore<"locale">;
27
+ safeArea: HostContextStore<"safeArea">;
28
+ displayMode: HostContextStore<"displayMode">;
29
+ maxHeight: HostContextStore<"maxHeight">;
30
+ userAgent: HostContextStore<"userAgent">;
31
+ toolInput: HostContextStore<"toolInput">;
32
+ toolOutput: HostContextStore<"toolOutput">;
33
+ toolResponseMetadata: HostContextStore<"toolResponseMetadata">;
34
+ };
23
35
  cleanup: () => void;
24
36
  static resetInstance(): void;
25
37
  private emit;
@@ -1,5 +1,23 @@
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
+ import { ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
+ import { dequal } from "dequal/lite";
4
+ import * as z from "zod";
5
+ function createMcpStore(bridge, keys, computeSnapshot) {
6
+ let cachedValue;
7
+ return {
8
+ subscribe: bridge.subscribe(keys),
9
+ getSnapshot: () => {
10
+ const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
11
+ const newValue = computeSnapshot(context);
12
+ if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
13
+ return cachedValue;
14
+ }
15
+ cachedValue = newValue;
16
+ return newValue;
17
+ },
18
+ };
19
+ }
20
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
3
21
  export class McpAppBridge {
4
22
  static instance = null;
5
23
  context = {
@@ -11,7 +29,10 @@ export class McpAppBridge {
11
29
  app;
12
30
  connectPromise;
13
31
  constructor(options) {
14
- this.app = new App(options.appInfo);
32
+ this.app = new App(options.appInfo, { tools: { listChanged: true } });
33
+ this.app.setRequestHandler(ListToolsRequestSchema, async () => ({
34
+ tools: [],
35
+ }));
15
36
  this.app.ontoolinput = (params) => {
16
37
  this.updateContext({ toolInput: params.arguments ?? {} });
17
38
  };
@@ -45,10 +66,23 @@ export class McpAppBridge {
45
66
  await this.connectPromise;
46
67
  return this.app;
47
68
  }
69
+ registerViewTool(config, handler) {
70
+ const inputSchema = config.inputSchema
71
+ ? z.object(config.inputSchema)
72
+ : z.object({});
73
+ const registered = this.app.registerTool(config.name, {
74
+ ...(config.title !== undefined ? { title: config.title } : {}),
75
+ ...(config.description !== undefined
76
+ ? { description: config.description }
77
+ : {}),
78
+ inputSchema,
79
+ ...(config.annotations ? { annotations: config.annotations } : {}),
80
+ }, handler);
81
+ return () => {
82
+ registered.remove();
83
+ };
84
+ }
48
85
  static getInstance(options) {
49
- if (window.skybridge.hostType !== "mcp-app") {
50
- throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
51
- }
52
86
  if (McpAppBridge.instance && options) {
53
87
  console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
54
88
  }
@@ -79,6 +113,35 @@ export class McpAppBridge {
79
113
  getSnapshot(key) {
80
114
  return this.context[key];
81
115
  }
116
+ createContextStores() {
117
+ return {
118
+ theme: createMcpStore(this, ["theme"], ({ theme }) => theme ?? "light"),
119
+ locale: createMcpStore(this, ["locale"], ({ locale }) => locale ?? "en-US"),
120
+ safeArea: createMcpStore(this, ["safeAreaInsets"], ({ safeAreaInsets }) => ({
121
+ insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
122
+ })),
123
+ displayMode: createMcpStore(this, ["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
124
+ maxHeight: createMcpStore(this, ["containerDimensions"], ({ containerDimensions }) => {
125
+ if (containerDimensions && "maxHeight" in containerDimensions) {
126
+ return containerDimensions.maxHeight;
127
+ }
128
+ return undefined;
129
+ }),
130
+ userAgent: createMcpStore(this, ["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
131
+ device: {
132
+ type: platform === "web" ? "desktop" : (platform ?? "unknown"),
133
+ },
134
+ capabilities: {
135
+ hover: true,
136
+ touch: true,
137
+ ...deviceCapabilities,
138
+ },
139
+ })),
140
+ toolInput: createMcpStore(this, ["toolInput"], ({ toolInput }) => toolInput ?? null),
141
+ toolOutput: createMcpStore(this, ["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
142
+ toolResponseMetadata: createMcpStore(this, ["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
143
+ };
144
+ }
82
145
  cleanup = () => {
83
146
  this.listeners.clear();
84
147
  };
@@ -1 +1 @@
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,CAAgB;IAEtC,YAAY,OAAoC;QAC9C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;YAChC,IAAI,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,kBAAkB,GAAG,CAAC,MAAM,EAAE,EAAE;YACvC,IAAI,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;YACjC,IAAI,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC;QAEF,IAAI,CAA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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"]}
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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} from \"@modelcontextprotocol/sdk/types.js\";\nimport { dequal } from \"dequal/lite\";\nimport * as z from \"zod\";\nimport type {\n AnyViewToolHandler,\n Bridge,\n HostContextStore,\n Subscribe,\n ViewToolConfig,\n} from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nfunction createMcpStore<const Keys extends readonly McpAppContextKey[], R>(\n bridge: McpAppBridge,\n keys: Keys,\n computeSnapshot: (context: PickContext<Keys>) => R,\n) {\n let cachedValue: R | undefined;\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 if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n cachedValue = newValue;\n return newValue;\n },\n };\n}\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */\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, { tools: { listChanged: true } });\n\n this.app.setRequestHandler(ListToolsRequestSchema, async () => ({\n tools: [],\n }));\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 registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void {\n const inputSchema = config.inputSchema\n ? z.object(config.inputSchema)\n : z.object({});\n\n const registered = this.app.registerTool(\n config.name,\n {\n ...(config.title !== undefined ? { title: config.title } : {}),\n ...(config.description !== undefined\n ? { description: config.description }\n : {}),\n inputSchema,\n ...(config.annotations ? { annotations: config.annotations } : {}),\n },\n handler,\n );\n\n return () => {\n registered.remove();\n };\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\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 createContextStores(): {\n theme: HostContextStore<\"theme\">;\n locale: HostContextStore<\"locale\">;\n safeArea: HostContextStore<\"safeArea\">;\n displayMode: HostContextStore<\"displayMode\">;\n maxHeight: HostContextStore<\"maxHeight\">;\n userAgent: HostContextStore<\"userAgent\">;\n toolInput: HostContextStore<\"toolInput\">;\n toolOutput: HostContextStore<\"toolOutput\">;\n toolResponseMetadata: HostContextStore<\"toolResponseMetadata\">;\n } {\n return {\n theme: createMcpStore(this, [\"theme\"], ({ theme }) => theme ?? \"light\"),\n locale: createMcpStore(\n this,\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: createMcpStore(\n this,\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: createMcpStore(\n this,\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: createMcpStore(\n this,\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n return undefined;\n },\n ),\n userAgent: createMcpStore(\n this,\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: createMcpStore(\n this,\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: createMcpStore(\n this,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: createMcpStore(\n this,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n };\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"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { McpAppBridge } from "./bridge.js";
3
+ describe("McpAppBridge.getInstance", () => {
4
+ beforeEach(() => {
5
+ McpAppBridge.resetInstance();
6
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
7
+ });
8
+ afterEach(() => {
9
+ vi.unstubAllGlobals();
10
+ McpAppBridge.resetInstance();
11
+ });
12
+ it("instantiates regardless of injected hostType", () => {
13
+ vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
14
+ expect(() => McpAppBridge.getInstance()).not.toThrow();
15
+ });
16
+ });
17
+ //# sourceMappingURL=bridge.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ndescribe(\"McpAppBridge.getInstance\", () => {\n beforeEach(() => {\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n McpAppBridge.resetInstance();\n });\n\n it(\"instantiates regardless of injected hostType\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n});\n"]}
@@ -1,4 +1,3 @@
1
- export { McpAppAdaptor } from "./adaptor.js";
2
1
  export { McpAppBridge } from "./bridge.js";
3
2
  export type { McpAppContext, McpAppContextKey, McpToolState, } from "./types.js";
4
3
  export { useMcpAppContext } from "./use-mcp-app-context.js";
@@ -1,4 +1,3 @@
1
- export { McpAppAdaptor } from "./adaptor.js";
2
1
  export { McpAppBridge } from "./bridge.js";
3
2
  export { useMcpAppContext } from "./use-mcp-app-context.js";
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppAdaptor } from \"./adaptor.js\";\nexport { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,143 @@
1
+ import { waitFor } from "@testing-library/react";
2
+ import { act } from "react";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import * as z from "zod";
5
+ import { MockResizeObserver } from "../../hooks/test/utils.js";
6
+ import { HostAdaptor } from "../adaptor.js";
7
+ import { McpAppBridge } from "./bridge.js";
8
+ const outgoing = [];
9
+ /**
10
+ * Stand-in MCP Apps host: replies to `ui/initialize` and records every message
11
+ * the app posts so tests can assert on responses and notifications.
12
+ */
13
+ function installHostMock() {
14
+ outgoing.length = 0;
15
+ const postMessage = vi.fn((message) => {
16
+ outgoing.push(message);
17
+ if (message.method === "ui/initialize" && message.id !== undefined) {
18
+ act(() => {
19
+ window.dispatchEvent(new MessageEvent("message", {
20
+ source: window.parent,
21
+ data: {
22
+ jsonrpc: "2.0",
23
+ id: message.id,
24
+ result: {
25
+ protocolVersion: "2025-06-18",
26
+ hostInfo: { name: "test-host", version: "1.0.0" },
27
+ hostCapabilities: {},
28
+ hostContext: {},
29
+ },
30
+ },
31
+ }));
32
+ });
33
+ }
34
+ });
35
+ vi.stubGlobal("parent", { postMessage });
36
+ }
37
+ let nextId = 1000;
38
+ /** Send a host → app JSON-RPC request and resolve with the full response (result or error). */
39
+ async function callHost(method, params = {}) {
40
+ const id = ++nextId;
41
+ act(() => {
42
+ window.dispatchEvent(new MessageEvent("message", {
43
+ source: window.parent,
44
+ data: { jsonrpc: "2.0", id, method, params },
45
+ }));
46
+ });
47
+ await waitFor(() => {
48
+ expect(outgoing.some((m) => m.id === id)).toBe(true);
49
+ });
50
+ return outgoing.find((m) => m.id === id);
51
+ }
52
+ describe("McpApp view tools", () => {
53
+ beforeEach(() => {
54
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
55
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
56
+ McpAppBridge.resetInstance();
57
+ installHostMock();
58
+ });
59
+ afterEach(() => {
60
+ vi.unstubAllGlobals();
61
+ vi.clearAllMocks();
62
+ });
63
+ it("advertises the tools capability during ui/initialize", async () => {
64
+ await McpAppBridge.getInstance().getApp();
65
+ const init = outgoing.find((m) => m.method === "ui/initialize");
66
+ expect(init?.params?.appCapabilities).toMatchObject({
67
+ tools: { listChanged: true },
68
+ });
69
+ });
70
+ it("lists a registered view tool with its input schema", async () => {
71
+ const adaptor = new HostAdaptor();
72
+ await McpAppBridge.getInstance().getApp();
73
+ adaptor.registerViewTool({
74
+ name: "chess_make_move",
75
+ description: "Play a move",
76
+ inputSchema: { san: z.string() },
77
+ annotations: { readOnlyHint: false },
78
+ }, () => ({ content: [{ type: "text", text: "ok" }] }));
79
+ const response = await callHost("tools/list");
80
+ const tools = response?.result?.tools;
81
+ expect(tools).toHaveLength(1);
82
+ const [tool] = tools;
83
+ expect(tool?.name).toBe("chess_make_move");
84
+ expect(tool?.description).toBe("Play a move");
85
+ expect(tool?.inputSchema.properties).toHaveProperty("san");
86
+ expect(tool?.annotations?.readOnlyHint).toBe(false);
87
+ });
88
+ it("invokes the handler with validated args and returns its result", async () => {
89
+ const adaptor = new HostAdaptor();
90
+ await McpAppBridge.getInstance().getApp();
91
+ const handler = vi.fn(({ san }) => ({
92
+ content: [{ type: "text", text: `played ${san}` }],
93
+ structuredContent: { lastMove: san },
94
+ }));
95
+ adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
96
+ const response = await callHost("tools/call", {
97
+ name: "chess_make_move",
98
+ arguments: { san: "e4" },
99
+ });
100
+ const result = response?.result;
101
+ // ext-apps invokes the callback as `(args, extra)`; assert on the args only.
102
+ expect(handler.mock.calls[0]?.[0]).toEqual({ san: "e4" });
103
+ expect(result?.structuredContent).toEqual({ lastMove: "e4" });
104
+ expect(result?.isError).toBeFalsy();
105
+ expect(result?.content).toEqual([{ type: "text", text: "played e4" }]);
106
+ });
107
+ it("rejects the call without invoking the handler when args are invalid", async () => {
108
+ const adaptor = new HostAdaptor();
109
+ await McpAppBridge.getInstance().getApp();
110
+ const handler = vi.fn(() => ({ content: [] }));
111
+ adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
112
+ // ext-apps validates input against the schema and rejects with a JSON-RPC
113
+ // error before the handler runs.
114
+ const response = await callHost("tools/call", {
115
+ name: "chess_make_move",
116
+ arguments: { san: 42 },
117
+ });
118
+ expect(handler).not.toHaveBeenCalled();
119
+ expect(response?.error).toBeDefined();
120
+ });
121
+ it("rejects a call to an unknown tool", async () => {
122
+ await McpAppBridge.getInstance().getApp();
123
+ const response = await callHost("tools/call", {
124
+ name: "nope",
125
+ arguments: {},
126
+ });
127
+ expect(response?.error).toBeDefined();
128
+ });
129
+ it("removes the tool and notifies the host when unregistered", async () => {
130
+ const adaptor = new HostAdaptor();
131
+ await McpAppBridge.getInstance().getApp();
132
+ const unregister = adaptor.registerViewTool({ name: "chess_reset" }, () => ({ content: [{ type: "text", text: "reset" }] }));
133
+ await waitFor(() => {
134
+ expect(outgoing.some((m) => m.method === "notifications/tools/list_changed")).toBe(true);
135
+ });
136
+ let listed = await callHost("tools/list");
137
+ expect(listed?.result?.tools).toHaveLength(1);
138
+ unregister();
139
+ listed = await callHost("tools/list");
140
+ expect(listed?.result?.tools).toHaveLength(0);
141
+ });
142
+ });
143
+ //# sourceMappingURL=view-tools.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-tools.test.js","sourceRoot":"","sources":["../../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":["import { waitFor } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport * as z from \"zod\";\nimport { MockResizeObserver } from \"../../hooks/test/utils.js\";\nimport { HostAdaptor } from \"../adaptor.js\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ntype JsonRpcMessage = {\n jsonrpc: \"2.0\";\n id?: number;\n method?: string;\n params?: Record<string, unknown>;\n result?: Record<string, unknown>;\n error?: { message: string };\n};\n\nconst outgoing: JsonRpcMessage[] = [];\n\n/**\n * Stand-in MCP Apps host: replies to `ui/initialize` and records every message\n * the app posts so tests can assert on responses and notifications.\n */\nfunction installHostMock() {\n outgoing.length = 0;\n const postMessage = vi.fn((message: JsonRpcMessage) => {\n outgoing.push(message);\n if (message.method === \"ui/initialize\" && message.id !== undefined) {\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: {},\n hostContext: {},\n },\n },\n }),\n );\n });\n }\n });\n vi.stubGlobal(\"parent\", { postMessage });\n}\n\nlet nextId = 1000;\n\n/** Send a host → app JSON-RPC request and resolve with the full response (result or error). */\nasync function callHost(method: string, params: Record<string, unknown> = {}) {\n const id = ++nextId;\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: { jsonrpc: \"2.0\", id, method, params },\n }),\n );\n });\n await waitFor(() => {\n expect(outgoing.some((m) => m.id === id)).toBe(true);\n });\n return outgoing.find((m) => m.id === id);\n}\n\ndescribe(\"McpApp view tools\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n installHostMock();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"advertises the tools capability during ui/initialize\", async () => {\n await McpAppBridge.getInstance().getApp();\n const init = outgoing.find((m) => m.method === \"ui/initialize\");\n expect(init?.params?.appCapabilities).toMatchObject({\n tools: { listChanged: true },\n });\n });\n\n it(\"lists a registered view tool with its input schema\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n adaptor.registerViewTool(\n {\n name: \"chess_make_move\",\n description: \"Play a move\",\n inputSchema: { san: z.string() },\n annotations: { readOnlyHint: false },\n },\n () => ({ content: [{ type: \"text\", text: \"ok\" }] }),\n );\n\n const response = await callHost(\"tools/list\");\n const tools = response?.result?.tools as Array<{\n name: string;\n description?: string;\n inputSchema: { properties?: Record<string, unknown> };\n annotations?: { readOnlyHint?: boolean };\n }>;\n expect(tools).toHaveLength(1);\n const [tool] = tools;\n expect(tool?.name).toBe(\"chess_make_move\");\n expect(tool?.description).toBe(\"Play a move\");\n expect(tool?.inputSchema.properties).toHaveProperty(\"san\");\n expect(tool?.annotations?.readOnlyHint).toBe(false);\n });\n\n it(\"invokes the handler with validated args and returns its result\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(({ san }: { san: string }) => ({\n content: [{ type: \"text\" as const, text: `played ${san}` }],\n structuredContent: { lastMove: san },\n }));\n\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: \"e4\" },\n });\n const result = response?.result;\n\n // ext-apps invokes the callback as `(args, extra)`; assert on the args only.\n expect(handler.mock.calls[0]?.[0]).toEqual({ san: \"e4\" });\n expect(result?.structuredContent).toEqual({ lastMove: \"e4\" });\n expect(result?.isError).toBeFalsy();\n expect(result?.content).toEqual([{ type: \"text\", text: \"played e4\" }]);\n });\n\n it(\"rejects the call without invoking the handler when args are invalid\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(() => ({ content: [] }));\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n // ext-apps validates input against the schema and rejects with a JSON-RPC\n // error before the handler runs.\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: 42 },\n });\n\n expect(handler).not.toHaveBeenCalled();\n expect(response?.error).toBeDefined();\n });\n\n it(\"rejects a call to an unknown tool\", async () => {\n await McpAppBridge.getInstance().getApp();\n const response = await callHost(\"tools/call\", {\n name: \"nope\",\n arguments: {},\n });\n expect(response?.error).toBeDefined();\n });\n\n it(\"removes the tool and notifies the host when unregistered\", async () => {\n const adaptor = new HostAdaptor();\n await McpAppBridge.getInstance().getApp();\n\n const unregister = adaptor.registerViewTool(\n { name: \"chess_reset\" },\n () => ({ content: [{ type: \"text\", text: \"reset\" }] }),\n );\n\n await waitFor(() => {\n expect(\n outgoing.some((m) => m.method === \"notifications/tools/list_changed\"),\n ).toBe(true);\n });\n\n let listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(1);\n\n unregister();\n listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(0);\n });\n});\n"]}