skybridge 1.1.2 → 1.2.1

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 (151) hide show
  1. package/dist/commands/dev.js +1 -3
  2. package/dist/commands/dev.js.map +1 -1
  3. package/dist/server/auth/discovery.d.ts +32 -0
  4. package/dist/server/auth/discovery.js +56 -0
  5. package/dist/server/auth/discovery.js.map +1 -0
  6. package/dist/server/auth/discovery.test.d.ts +1 -0
  7. package/dist/server/auth/discovery.test.js +93 -0
  8. package/dist/server/auth/discovery.test.js.map +1 -0
  9. package/dist/server/auth/index.d.ts +18 -0
  10. package/dist/server/auth/index.js +2 -0
  11. package/dist/server/auth/index.js.map +1 -0
  12. package/dist/server/auth/providers/auth0.d.ts +18 -0
  13. package/dist/server/auth/providers/auth0.js +31 -0
  14. package/dist/server/auth/providers/auth0.js.map +1 -0
  15. package/dist/server/auth/providers/auth0.test.d.ts +1 -0
  16. package/dist/server/auth/providers/auth0.test.js +48 -0
  17. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  18. package/dist/server/auth/providers/clerk.d.ts +14 -0
  19. package/dist/server/auth/providers/clerk.js +16 -0
  20. package/dist/server/auth/providers/clerk.js.map +1 -0
  21. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  22. package/dist/server/auth/providers/clerk.test.js +28 -0
  23. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  24. package/dist/server/auth/providers/custom.d.ts +24 -0
  25. package/dist/server/auth/providers/custom.js +37 -0
  26. package/dist/server/auth/providers/custom.js.map +1 -0
  27. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  28. package/dist/server/auth/providers/custom.test.js +107 -0
  29. package/dist/server/auth/providers/custom.test.js.map +1 -0
  30. package/dist/server/auth/providers/descope.d.ts +15 -0
  31. package/dist/server/auth/providers/descope.js +33 -0
  32. package/dist/server/auth/providers/descope.js.map +1 -0
  33. package/dist/server/auth/providers/descope.test.d.ts +1 -0
  34. package/dist/server/auth/providers/descope.test.js +37 -0
  35. package/dist/server/auth/providers/descope.test.js.map +1 -0
  36. package/dist/server/auth/providers/shared.d.ts +2 -0
  37. package/dist/server/auth/providers/shared.js +6 -0
  38. package/dist/server/auth/providers/shared.js.map +1 -0
  39. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  40. package/dist/server/auth/providers/shared.test.js +10 -0
  41. package/dist/server/auth/providers/shared.test.js.map +1 -0
  42. package/dist/server/auth/providers/stytch.d.ts +12 -0
  43. package/dist/server/auth/providers/stytch.js +13 -0
  44. package/dist/server/auth/providers/stytch.js.map +1 -0
  45. package/dist/server/auth/providers/workos.d.ts +11 -0
  46. package/dist/server/auth/providers/workos.js +12 -0
  47. package/dist/server/auth/providers/workos.js.map +1 -0
  48. package/dist/server/auth/setup.d.ts +4 -0
  49. package/dist/server/auth/setup.js +51 -0
  50. package/dist/server/auth/setup.js.map +1 -0
  51. package/dist/server/auth/setup.test.d.ts +1 -0
  52. package/dist/server/auth/setup.test.js +185 -0
  53. package/dist/server/auth/setup.test.js.map +1 -0
  54. package/dist/server/auth/verify.d.ts +12 -0
  55. package/dist/server/auth/verify.js +38 -0
  56. package/dist/server/auth/verify.js.map +1 -0
  57. package/dist/server/auth/verify.test.d.ts +1 -0
  58. package/dist/server/auth/verify.test.js +100 -0
  59. package/dist/server/auth/verify.test.js.map +1 -0
  60. package/dist/server/express.test.js +31 -0
  61. package/dist/server/express.test.js.map +1 -1
  62. package/dist/server/index.d.ts +8 -1
  63. package/dist/server/index.js +6 -0
  64. package/dist/server/index.js.map +1 -1
  65. package/dist/server/requestOrigin.d.ts +7 -0
  66. package/dist/server/requestOrigin.js +25 -0
  67. package/dist/server/requestOrigin.js.map +1 -0
  68. package/dist/server/server.d.ts +30 -7
  69. package/dist/server/server.js +79 -123
  70. package/dist/server/server.js.map +1 -1
  71. package/dist/server/view-resource-resolution.test.js +24 -9
  72. package/dist/server/view-resource-resolution.test.js.map +1 -1
  73. package/dist/test/view.test.js +69 -101
  74. package/dist/test/view.test.js.map +1 -1
  75. package/dist/web/bridges/adaptor.d.ts +51 -0
  76. package/dist/web/bridges/adaptor.js +310 -0
  77. package/dist/web/bridges/adaptor.js.map +1 -0
  78. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  79. package/dist/web/bridges/adaptor.test.js +197 -0
  80. package/dist/web/bridges/adaptor.test.js.map +1 -0
  81. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  82. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  83. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  84. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  85. package/dist/web/bridges/apps-sdk/index.js +0 -1
  86. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  87. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  88. package/dist/web/bridges/get-adaptor.js +6 -11
  89. package/dist/web/bridges/get-adaptor.js.map +1 -1
  90. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  91. package/dist/web/bridges/get-adaptor.test.js +32 -0
  92. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  93. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
  94. package/dist/web/bridges/mcp-app/bridge.js +46 -4
  95. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  96. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  97. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  98. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  99. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  100. package/dist/web/bridges/mcp-app/index.js +0 -1
  101. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  102. package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
  103. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  104. package/dist/web/bridges/types.d.ts +10 -0
  105. package/dist/web/bridges/types.js +14 -1
  106. package/dist/web/bridges/types.js.map +1 -1
  107. package/dist/web/bridges/types.test.d.ts +1 -0
  108. package/dist/web/bridges/types.test.js +19 -0
  109. package/dist/web/bridges/types.test.js.map +1 -0
  110. package/dist/web/components/modal-provider.js +4 -3
  111. package/dist/web/components/modal-provider.js.map +1 -1
  112. package/dist/web/create-store.test.js +8 -5
  113. package/dist/web/create-store.test.js.map +1 -1
  114. package/dist/web/data-llm.test.js +9 -5
  115. package/dist/web/data-llm.test.js.map +1 -1
  116. package/dist/web/hooks/use-call-tool.test.js +37 -23
  117. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  118. package/dist/web/hooks/use-display-mode.test.js +56 -20
  119. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  120. package/dist/web/hooks/use-download.test.js +11 -3
  121. package/dist/web/hooks/use-download.test.js.map +1 -1
  122. package/dist/web/hooks/use-files.test.js +10 -2
  123. package/dist/web/hooks/use-files.test.js.map +1 -1
  124. package/dist/web/hooks/use-layout.test.js +59 -26
  125. package/dist/web/hooks/use-layout.test.js.map +1 -1
  126. package/dist/web/hooks/use-open-external.test.js +13 -3
  127. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  128. package/dist/web/hooks/use-request-close.test.js +35 -40
  129. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  130. package/dist/web/hooks/use-request-modal.test.js +10 -0
  131. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  132. package/dist/web/hooks/use-request-size.test.js +35 -53
  133. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  134. package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
  135. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  136. package/dist/web/hooks/use-tool-info.test.js +37 -27
  137. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  138. package/dist/web/hooks/use-user.test.js +81 -35
  139. package/dist/web/hooks/use-user.test.js.map +1 -1
  140. package/dist/web/hooks/use-view-state.test.js +6 -2
  141. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  142. package/package.json +3 -2
  143. package/dist/cli/use-open-tunnel-browser.d.ts +0 -6
  144. package/dist/cli/use-open-tunnel-browser.js +0 -19
  145. package/dist/cli/use-open-tunnel-browser.js.map +0 -1
  146. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
  147. package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
  148. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  149. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
  150. package/dist/web/bridges/mcp-app/adaptor.js +0 -283
  151. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../src/web/data-llm.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,SAAS,CAAC,GAAG,EAAE;QACb,sDAAsD;QACtD,OAAO,EAAE,CAAC;QACV,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,UAA0D,CAAC;QAE/D,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,WAAW,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;gBACjC,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE;aACxB,CAAC;YACF,kDAAkD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qBAChC,WAAW,EAAE,CAAC;gBACjB,MAAM,OAAO,GAAG,SAAS,EAAE,cAAwB,CAAC;gBACpD,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;gBAC/C,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;YAC3E,MAAM,CACJ,KAAC,OAAO,IAAC,OAAO,EAAC,cAAc,YAC7B,kCAAgB,GACR,CACX,CAAC;YAEF,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;gBACpB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,EAC9D,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { cleanup, render } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { McpAppAdaptor, McpAppBridge } from \"./bridges/mcp-app/index.js\";\nimport { DataLLM } from \"./data-llm.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./hooks/test/utils.js\";\n\ndescribe(\"DataLLM\", () => {\n afterEach(() => {\n // Clean up React components BEFORE unstubbing globals\n cleanup();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n describe(\"apps-sdk mode\", () => {\n let OpenaiMock: { widgetState: unknown; setWidgetState: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: { modelContent: {} },\n setWidgetState: vi.fn(),\n };\n // Use Object.defineProperty to ensure it persists\n Object.defineProperty(globalThis, \"openai\", {\n value: OpenaiMock,\n writable: true,\n configurable: true,\n });\n // Also set on window for browser-like environment\n if (typeof window !== \"undefined\") {\n Object.defineProperty(window, \"openai\", {\n value: OpenaiMock,\n writable: true,\n configurable: true,\n });\n }\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n // Keep the mock available for React cleanup, but reset it\n if (typeof window !== \"undefined\" && window.openai) {\n window.openai.setWidgetState = vi.fn();\n window.openai.widgetState = { modelContent: {}, privateContent: {} };\n }\n });\n\n it(\"should register a node with content and call setViewState\", () => {\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalled();\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[0]?.[0]?.modelContent;\n expect(callArgs).toHaveProperty(\"__view_context\");\n expect(callArgs?.__view_context).toContain(\"- Test content\");\n });\n it(\"should preserve existing viewState when updating context\", () => {\n OpenaiMock.widgetState = {\n modelContent: { existingKey: \"existingValue\" },\n };\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[0]?.[0]?.modelContent;\n expect(callArgs).toHaveProperty(\"existingKey\", \"existingValue\");\n expect(callArgs).toHaveProperty(\"__view_context\");\n });\n\n it(\"should handle deeply nested DataLLM components\", () => {\n render(\n <DataLLM content=\"Level 1\">\n <DataLLM content=\"Level 2A\" />\n <DataLLM content=\"Level 2B\">\n <DataLLM content=\"Level 3\">\n <div>Content</div>\n </DataLLM>\n </DataLLM>\n </DataLLM>,\n );\n\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n const context = callArgs?.__view_context as string;\n expect(context).toContain(\"- Level 1\");\n expect(context).toContain(\" - Level 2A\");\n expect(context).toContain(\" - Level 2B\");\n expect(context).toContain(\" - Level 3\");\n });\n\n it(\"should update context when content changes\", () => {\n const { rerender } = render(\n <DataLLM content=\"Initial content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const initialCalls = OpenaiMock.setWidgetState.mock.calls.length;\n\n rerender(\n <DataLLM content=\"Updated content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(\n initialCalls,\n );\n const lastCallArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n expect(lastCallArgs?.__view_context).toContain(\"- Updated content\");\n });\n\n it(\"should remove node and update context when component unmounts\", () => {\n const { unmount } = render(\n <DataLLM content=\"Content to remove\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const callsBeforeUnmount = OpenaiMock.setWidgetState.mock.calls.length;\n\n unmount();\n\n expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(\n callsBeforeUnmount,\n );\n const lastCallArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n expect(lastCallArgs?.__view_context).not.toContain(\"Content to remove\");\n });\n });\n\n describe(\"mcp-app mode\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n cleanup();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should register a node and update view state via adaptor\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n expect(viewState?.__view_context).toContain(\"- Test content\");\n });\n });\n\n it(\"should preserve existing view state when updating context\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n await adaptor.setViewState({ existingKey: \"existingValue\" });\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n expect(viewState?.existingKey).toBe(\"existingValue\");\n expect(viewState?.__view_context).toContain(\"- Test content\");\n });\n });\n\n it(\"should handle multiple DataLLM components sharing state through adaptor\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n\n render(\n <>\n <DataLLM content=\"First component\">\n <div>First</div>\n </DataLLM>\n <DataLLM content=\"Second component\">\n <div>Second</div>\n </DataLLM>\n </>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n const context = viewState?.__view_context as string;\n expect(context).toContain(\"- First component\");\n expect(context).toContain(\"- Second component\");\n });\n });\n\n it(\"should call ui/update-model-context when view state changes\", async () => {\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/update-model-context\" }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../src/web/data-llm.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE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AAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { cleanup, render } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { HostAdaptor } from \"./bridges/adaptor.js\";\nimport { getAdaptor } from \"./bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"./bridges/mcp-app/index.js\";\nimport { DataLLM } from \"./data-llm.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./hooks/test/utils.js\";\n\ndescribe(\"DataLLM\", () => {\n afterEach(() => {\n // Clean up React components BEFORE unstubbing globals\n cleanup();\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n describe(\"apps-sdk mode\", () => {\n let OpenaiMock: { widgetState: unknown; setWidgetState: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: { modelContent: {} },\n setWidgetState: vi.fn(),\n };\n // Use Object.defineProperty to ensure it persists\n Object.defineProperty(globalThis, \"openai\", {\n value: OpenaiMock,\n writable: true,\n configurable: true,\n });\n // Also set on window for browser-like environment\n if (typeof window !== \"undefined\") {\n Object.defineProperty(window, \"openai\", {\n value: OpenaiMock,\n writable: true,\n configurable: true,\n });\n }\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n // Keep the mock available for React cleanup, but reset it\n if (typeof window !== \"undefined\" && window.openai) {\n window.openai.setWidgetState = vi.fn();\n window.openai.widgetState = { modelContent: {}, privateContent: {} };\n }\n });\n\n it(\"should register a node with content and call setViewState\", () => {\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalled();\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[0]?.[0]?.modelContent;\n expect(callArgs).toHaveProperty(\"__view_context\");\n expect(callArgs?.__view_context).toContain(\"- Test content\");\n });\n it(\"should preserve existing viewState when updating context\", () => {\n OpenaiMock.widgetState = {\n modelContent: { existingKey: \"existingValue\" },\n };\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[0]?.[0]?.modelContent;\n expect(callArgs).toHaveProperty(\"existingKey\", \"existingValue\");\n expect(callArgs).toHaveProperty(\"__view_context\");\n });\n\n it(\"should handle deeply nested DataLLM components\", () => {\n render(\n <DataLLM content=\"Level 1\">\n <DataLLM content=\"Level 2A\" />\n <DataLLM content=\"Level 2B\">\n <DataLLM content=\"Level 3\">\n <div>Content</div>\n </DataLLM>\n </DataLLM>\n </DataLLM>,\n );\n\n const callArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n const context = callArgs?.__view_context as string;\n expect(context).toContain(\"- Level 1\");\n expect(context).toContain(\" - Level 2A\");\n expect(context).toContain(\" - Level 2B\");\n expect(context).toContain(\" - Level 3\");\n });\n\n it(\"should update context when content changes\", () => {\n const { rerender } = render(\n <DataLLM content=\"Initial content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const initialCalls = OpenaiMock.setWidgetState.mock.calls.length;\n\n rerender(\n <DataLLM content=\"Updated content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(\n initialCalls,\n );\n const lastCallArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n expect(lastCallArgs?.__view_context).toContain(\"- Updated content\");\n });\n\n it(\"should remove node and update context when component unmounts\", () => {\n const { unmount } = render(\n <DataLLM content=\"Content to remove\">\n <div>Child</div>\n </DataLLM>,\n );\n\n const callsBeforeUnmount = OpenaiMock.setWidgetState.mock.calls.length;\n\n unmount();\n\n expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(\n callsBeforeUnmount,\n );\n const lastCallArgs =\n OpenaiMock.setWidgetState.mock.calls[\n OpenaiMock.setWidgetState.mock.calls.length - 1\n ]?.[0]?.modelContent;\n expect(lastCallArgs?.__view_context).not.toContain(\"Content to remove\");\n });\n });\n\n describe(\"mcp-app mode\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n cleanup();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should register a node and update view state via adaptor\", async () => {\n const adaptor = getAdaptor();\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n expect(viewState?.__view_context).toContain(\"- Test content\");\n });\n });\n\n it(\"should preserve existing view state when updating context\", async () => {\n const adaptor = getAdaptor();\n await adaptor.setViewState({ existingKey: \"existingValue\" });\n\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n expect(viewState?.existingKey).toBe(\"existingValue\");\n expect(viewState?.__view_context).toContain(\"- Test content\");\n });\n });\n\n it(\"should handle multiple DataLLM components sharing state through adaptor\", async () => {\n const adaptor = getAdaptor();\n\n render(\n <>\n <DataLLM content=\"First component\">\n <div>First</div>\n </DataLLM>\n <DataLLM content=\"Second component\">\n <div>Second</div>\n </DataLLM>\n </>,\n );\n\n await vi.waitFor(() => {\n const viewState = adaptor\n .getHostContextStore(\"viewState\")\n .getSnapshot();\n const context = viewState?.__view_context as string;\n expect(context).toContain(\"- First component\");\n expect(context).toContain(\"- Second component\");\n });\n });\n\n it(\"should call ui/update-model-context when view state changes\", async () => {\n render(\n <DataLLM content=\"Test content\">\n <div>Child</div>\n </DataLLM>,\n );\n\n await vi.waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/update-model-context\" }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
@@ -1,18 +1,27 @@
1
1
  import { act, renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi, } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { getAdaptor } from "../bridges/get-adaptor.js";
6
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
3
7
  import { useCallTool } from "./use-call-tool.js";
4
8
  describe("useCallTool - onSuccess callback", () => {
5
- let OpenaiMock;
9
+ let callToolMock;
6
10
  beforeEach(() => {
7
- OpenaiMock = {
8
- callTool: vi.fn(),
9
- };
10
- vi.stubGlobal("openai", OpenaiMock);
11
+ HostAdaptor.resetInstance();
12
+ McpAppBridge.resetInstance();
13
+ AppsSdkBridge.resetInstance();
14
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
11
15
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
16
+ vi.stubGlobal("openai", { callTool: vi.fn() });
17
+ callToolMock = vi.spyOn(getAdaptor(), "callTool");
12
18
  });
13
19
  afterEach(() => {
14
20
  vi.unstubAllGlobals();
15
21
  vi.resetAllMocks();
22
+ HostAdaptor.resetInstance();
23
+ McpAppBridge.resetInstance();
24
+ AppsSdkBridge.resetInstance();
16
25
  });
17
26
  const toolName = "test-tool";
18
27
  const args = { input: "test input" };
@@ -28,9 +37,9 @@ describe("useCallTool - onSuccess callback", () => {
28
37
  content: [{ type: "text", text: "result" }],
29
38
  structuredContent: { value: 1 },
30
39
  isError: false,
31
- _meta: { secret: "only visible to widget" },
40
+ meta: { secret: "only visible to widget" },
32
41
  };
33
- OpenaiMock.callTool.mockResolvedValueOnce(rawSdkResponse);
42
+ callToolMock.mockResolvedValueOnce(rawSdkResponse);
34
43
  const { result } = renderHook(() => useCallTool(toolName));
35
44
  await act(async () => {
36
45
  result.current.callTool(args);
@@ -41,17 +50,17 @@ describe("useCallTool - onSuccess callback", () => {
41
50
  });
42
51
  });
43
52
  });
44
- it("should call window.openai.callTool with correct arguments", async () => {
53
+ it("should call adaptor.callTool with correct arguments", async () => {
45
54
  const { result } = renderHook(() => useCallTool(toolName));
46
55
  await act(async () => {
47
56
  result.current.callTool(args);
48
57
  });
49
- expect(OpenaiMock.callTool).toHaveBeenCalledWith(toolName, args);
58
+ expect(callToolMock).toHaveBeenCalledWith(toolName, args);
50
59
  });
51
60
  it("should call onSuccess callback with correct data and toolArgs on successful execution", async () => {
52
61
  const onSuccess = vi.fn();
53
62
  const onError = vi.fn();
54
- OpenaiMock.callTool.mockResolvedValueOnce(data);
63
+ callToolMock.mockResolvedValueOnce(data);
55
64
  const { result } = renderHook(() => useCallTool(toolName));
56
65
  act(() => {
57
66
  result.current.callTool(args, {
@@ -67,7 +76,7 @@ describe("useCallTool - onSuccess callback", () => {
67
76
  it("should call onError callback with error and toolArgs on failed execution", async () => {
68
77
  const onSuccess = vi.fn();
69
78
  const onError = vi.fn();
70
- OpenaiMock.callTool.mockRejectedValueOnce(error);
79
+ callToolMock.mockRejectedValueOnce(error);
71
80
  const { result } = renderHook(() => useCallTool(toolName));
72
81
  act(() => {
73
82
  result.current.callTool(args, {
@@ -84,7 +93,7 @@ describe("useCallTool - onSuccess callback", () => {
84
93
  const onSuccess = vi.fn();
85
94
  const onError = vi.fn();
86
95
  const onSettled = vi.fn();
87
- OpenaiMock.callTool.mockResolvedValueOnce(data);
96
+ callToolMock.mockResolvedValueOnce(data);
88
97
  const { result } = renderHook(() => useCallTool(toolName));
89
98
  act(() => {
90
99
  result.current.callTool(args, {
@@ -103,7 +112,7 @@ describe("useCallTool - onSuccess callback", () => {
103
112
  const onSuccess = vi.fn();
104
113
  const onError = vi.fn();
105
114
  const onSettled = vi.fn();
106
- OpenaiMock.callTool.mockRejectedValueOnce(error);
115
+ callToolMock.mockRejectedValueOnce(error);
107
116
  const { result } = renderHook(() => useCallTool(toolName));
108
117
  act(() => {
109
118
  result.current.callTool(args, {
@@ -130,7 +139,7 @@ describe("useCallTool - onSuccess callback", () => {
130
139
  };
131
140
  const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } = Promise.withResolvers();
132
141
  const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } = Promise.withResolvers();
133
- OpenaiMock.callTool
142
+ callToolMock
134
143
  .mockImplementationOnce(() => firstCallToolPromise)
135
144
  .mockImplementationOnce(() => secondCallToolPromise);
136
145
  await act(() => {
@@ -149,17 +158,22 @@ describe("useCallTool - onSuccess callback", () => {
149
158
  });
150
159
  });
151
160
  describe("useCallTool - TypeScript typing", () => {
152
- let OpenaiMock;
161
+ let callToolMock;
153
162
  beforeEach(() => {
154
- OpenaiMock = {
155
- callTool: vi.fn(),
156
- };
157
- vi.stubGlobal("openai", OpenaiMock);
163
+ HostAdaptor.resetInstance();
164
+ McpAppBridge.resetInstance();
165
+ AppsSdkBridge.resetInstance();
166
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
158
167
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
168
+ vi.stubGlobal("openai", { callTool: vi.fn() });
169
+ callToolMock = vi.spyOn(getAdaptor(), "callTool");
159
170
  });
160
171
  afterEach(() => {
161
172
  vi.unstubAllGlobals();
162
173
  vi.resetAllMocks();
174
+ HostAdaptor.resetInstance();
175
+ McpAppBridge.resetInstance();
176
+ AppsSdkBridge.resetInstance();
163
177
  });
164
178
  it("should have correct return types when ToolArgs is null and ToolResponse is specified", async () => {
165
179
  const { result } = renderHook(() => useCallTool("test-tool"));
@@ -169,11 +183,11 @@ describe("useCallTool - TypeScript typing", () => {
169
183
  isError: false,
170
184
  meta: { id: 123 },
171
185
  };
172
- OpenaiMock.callTool.mockResolvedValueOnce(data);
186
+ callToolMock.mockResolvedValueOnce(data);
173
187
  await act(async () => {
174
188
  result.current.callTool();
175
189
  });
176
- expect(OpenaiMock.callTool).toHaveBeenCalledWith("test-tool", null);
190
+ expect(callToolMock).toHaveBeenCalledWith("test-tool", null);
177
191
  expectTypeOf(result.current.data);
178
192
  });
179
193
  it("should correctly type callToolAsync return value", async () => {
@@ -185,7 +199,7 @@ describe("useCallTool - TypeScript typing", () => {
185
199
  isError: false,
186
200
  meta: {},
187
201
  };
188
- OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
202
+ callToolMock.mockResolvedValueOnce(mockResponse);
189
203
  const returnedValue = await act(async () => {
190
204
  return result.current.callToolAsync(testArgs);
191
205
  });
@@ -200,7 +214,7 @@ describe("useCallTool - TypeScript typing", () => {
200
214
  isError: false,
201
215
  meta: {},
202
216
  };
203
- OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
217
+ callToolMock.mockResolvedValueOnce(mockResponse);
204
218
  const returnedValue = await act(async () => {
205
219
  return result.current.callToolAsync();
206
220
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,UAA8B,CAAC;IAEnC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IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QAKzE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CACjC,WAAW,CAAqB,WAAW,CAAC,CAC7C,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAClD,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,UAAU,CAAC,QAAQ,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAExD,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n expectTypeOf,\n it,\n type Mock,\n vi,\n} from \"vitest\";\n\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let OpenaiMock: { callTool: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n callTool: vi.fn(),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n const toolName = \"test-tool\";\n const args = { input: \"test input\" };\n const data: CallToolResponse = {\n content: [{ type: \"text\" as const, text: \"test result\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: {},\n };\n const error = new Error(\"test error\");\n\n it(\"should normalize _meta to meta when SDK returns _meta instead of meta\", async () => {\n const rawSdkResponse = {\n content: [{ type: \"text\" as const, text: \"result\" }],\n structuredContent: { value: 1 },\n isError: false,\n _meta: { secret: \"only visible to widget\" },\n };\n OpenaiMock.callTool.mockResolvedValueOnce(rawSdkResponse);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n await act(async () => {\n result.current.callTool(args);\n });\n\n await waitFor(() => {\n expect(result.current.data).toMatchObject({\n meta: { secret: \"only visible to widget\" },\n });\n });\n });\n\n it(\"should call window.openai.callTool with correct arguments\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n await act(async () => {\n result.current.callTool(args);\n });\n expect(OpenaiMock.callTool).toHaveBeenCalledWith(toolName, args);\n });\n\n it(\"should call onSuccess callback with correct data and toolArgs on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n OpenaiMock.callTool.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onError callback with error and toolArgs on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n OpenaiMock.callTool.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).not.toHaveBeenCalled();\n expect(onError).toHaveBeenCalledWith(error, args);\n });\n });\n\n it(\"should call onSettled callback with data and undefined error on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n OpenaiMock.callTool.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onSettled).toHaveBeenCalledWith(data, undefined, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onSettled callback with undefined data and error on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n OpenaiMock.callTool.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onError).toHaveBeenCalledWith(error, args);\n expect(onSettled).toHaveBeenCalledWith(undefined, error, args);\n expect(onSuccess).not.toHaveBeenCalled();\n });\n });\n\n it(\"should always return last call started state\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n const firstCallData = {\n ...data,\n structuredContent: { result: \"first call result\" },\n };\n const secondCallData = {\n ...data,\n structuredContent: { result: \"second call result\" },\n };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n OpenaiMock.callTool\n .mockImplementationOnce(() => firstCallToolPromise)\n .mockImplementationOnce(() => secondCallToolPromise);\n\n await act(() => {\n result.current.callTool(args);\n result.current.callTool(args);\n resolveFirstCallTool(firstCallData);\n return firstCallToolPromise;\n });\n\n expect(result.current.status).toEqual(\"pending\");\n expect(result.current.data).toEqual(undefined);\n resolveSecondCallTool(secondCallData);\n\n await waitFor(() => {\n expect(result.current.status).toEqual(\"success\");\n expect(result.current.data).toEqual(secondCallData);\n });\n });\n});\n\ndescribe(\"useCallTool - TypeScript typing\", () => {\n let OpenaiMock: { callTool: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n callTool: vi.fn(),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should have correct return types when ToolArgs is null and ToolResponse is specified\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { result: string };\n meta: { id: number };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n const data: TestResponse = {\n content: [{ type: \"text\" as const, text: \"test\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: { id: 123 },\n };\n\n OpenaiMock.callTool.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(OpenaiMock.callTool).toHaveBeenCalledWith(\"test-tool\", null);\n expectTypeOf<typeof data | undefined>(result.current.data);\n });\n\n it(\"should correctly type callToolAsync return value\", async () => {\n type TestArgs = { query: string };\n type TestResponse = CallToolResponse & {\n structuredContent: { answer: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<TestArgs, TestResponse>(\"test-tool\"),\n );\n\n const testArgs: TestArgs = { query: \"test\" };\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"answer\" }],\n structuredContent: { answer: \"test answer\" },\n isError: false,\n meta: {},\n };\n\n OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync(testArgs);\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n\n it(\"should correctly type callToolAsync when ToolArgs is null\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { data: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"data\" }],\n structuredContent: { data: \"test data\" },\n isError: false,\n meta: {},\n };\n\n OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync();\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n});\n"]}
1
+ {"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,YAAkB,CAAC;IAEvB,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;QAClD,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,EAA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M,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QAKzE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CACjC,WAAW,CAAqB,WAAW,CAAC,CAC7C,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAClD,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,YAAY,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n expectTypeOf,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n const toolName = \"test-tool\";\n const args = { input: \"test input\" };\n const data: CallToolResponse = {\n content: [{ type: \"text\" as const, text: \"test result\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: {},\n };\n const error = new Error(\"test error\");\n\n it(\"should normalize _meta to meta when SDK returns _meta instead of meta\", async () => {\n const rawSdkResponse = {\n content: [{ type: \"text\" as const, text: \"result\" }],\n structuredContent: { value: 1 },\n isError: false,\n meta: { secret: \"only visible to widget\" },\n };\n callToolMock.mockResolvedValueOnce(rawSdkResponse);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n await act(async () => {\n result.current.callTool(args);\n });\n\n await waitFor(() => {\n expect(result.current.data).toMatchObject({\n meta: { secret: \"only visible to widget\" },\n });\n });\n });\n\n it(\"should call adaptor.callTool with correct arguments\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n await act(async () => {\n result.current.callTool(args);\n });\n expect(callToolMock).toHaveBeenCalledWith(toolName, args);\n });\n\n it(\"should call onSuccess callback with correct data and toolArgs on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onError callback with error and toolArgs on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).not.toHaveBeenCalled();\n expect(onError).toHaveBeenCalledWith(error, args);\n });\n });\n\n it(\"should call onSettled callback with data and undefined error on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onSettled).toHaveBeenCalledWith(data, undefined, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onSettled callback with undefined data and error on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onError).toHaveBeenCalledWith(error, args);\n expect(onSettled).toHaveBeenCalledWith(undefined, error, args);\n expect(onSuccess).not.toHaveBeenCalled();\n });\n });\n\n it(\"should always return last call started state\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n const firstCallData = {\n ...data,\n structuredContent: { result: \"first call result\" },\n };\n const secondCallData = {\n ...data,\n structuredContent: { result: \"second call result\" },\n };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n callToolMock\n .mockImplementationOnce(() => firstCallToolPromise)\n .mockImplementationOnce(() => secondCallToolPromise);\n\n await act(() => {\n result.current.callTool(args);\n result.current.callTool(args);\n resolveFirstCallTool(firstCallData);\n return firstCallToolPromise;\n });\n\n expect(result.current.status).toEqual(\"pending\");\n expect(result.current.data).toEqual(undefined);\n resolveSecondCallTool(secondCallData);\n\n await waitFor(() => {\n expect(result.current.status).toEqual(\"success\");\n expect(result.current.data).toEqual(secondCallData);\n });\n });\n});\n\ndescribe(\"useCallTool - TypeScript typing\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should have correct return types when ToolArgs is null and ToolResponse is specified\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { result: string };\n meta: { id: number };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n const data: TestResponse = {\n content: [{ type: \"text\" as const, text: \"test\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: { id: 123 },\n };\n\n callToolMock.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(callToolMock).toHaveBeenCalledWith(\"test-tool\", null);\n expectTypeOf<typeof data | undefined>(result.current.data);\n });\n\n it(\"should correctly type callToolAsync return value\", async () => {\n type TestArgs = { query: string };\n type TestResponse = CallToolResponse & {\n structuredContent: { answer: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<TestArgs, TestResponse>(\"test-tool\"),\n );\n\n const testArgs: TestArgs = { query: \"test\" };\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"answer\" }],\n structuredContent: { answer: \"test answer\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync(testArgs);\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n\n it(\"should correctly type callToolAsync when ToolArgs is null\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { data: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"data\" }],\n structuredContent: { data: \"test data\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync();\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n});\n"]}
@@ -1,39 +1,75 @@
1
- import { act, renderHook } from "@testing-library/react";
2
- import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
1
+ import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { getAdaptor } from "../bridges/get-adaptor.js";
6
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
7
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
3
8
  import { useDisplayMode } from "./use-display-mode.js";
4
9
  describe("useDisplayMode", () => {
5
- let OpenaiMock;
6
10
  beforeEach(() => {
7
- OpenaiMock = {
8
- displayMode: "inline",
9
- requestDisplayMode: vi.fn().mockResolvedValue({ mode: "inline" }),
10
- };
11
- vi.stubGlobal("openai", OpenaiMock);
11
+ HostAdaptor.resetInstance();
12
+ McpAppBridge.resetInstance();
13
+ AppsSdkBridge.resetInstance();
12
14
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
15
+ vi.stubGlobal("openai", { view: { mode: "inline" } });
16
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
13
17
  });
14
18
  afterEach(() => {
15
19
  vi.unstubAllGlobals();
16
20
  vi.resetAllMocks();
21
+ HostAdaptor.resetInstance();
22
+ McpAppBridge.resetInstance();
23
+ AppsSdkBridge.resetInstance();
17
24
  });
18
- it("should return the current display mode from window.openai.displayMode", () => {
19
- OpenaiMock.displayMode = "inline";
25
+ it("should return the current display mode from MCP host context", async () => {
26
+ vi.stubGlobal("parent", {
27
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
28
+ });
20
29
  const { result } = renderHook(() => useDisplayMode());
21
- expect(result.current[0]).toBe("inline");
30
+ await waitFor(() => {
31
+ expect(result.current[0]).toBe("inline");
32
+ });
22
33
  });
23
- it("should return different display modes when window.openai.displayMode changes", () => {
24
- OpenaiMock.displayMode = "inline";
25
- const { result, rerender } = renderHook(() => useDisplayMode());
26
- expect(result.current[0]).toBe("inline");
27
- OpenaiMock.displayMode = "fullscreen";
28
- rerender();
29
- expect(result.current[0]).toBe("fullscreen");
34
+ it("should update display mode on host-context-changed notification", async () => {
35
+ vi.stubGlobal("parent", {
36
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
37
+ });
38
+ const { result } = renderHook(() => useDisplayMode());
39
+ await waitFor(() => {
40
+ expect(result.current[0]).toBe("inline");
41
+ });
42
+ act(() => {
43
+ fireEvent(window, new MessageEvent("message", {
44
+ source: window.parent,
45
+ data: {
46
+ jsonrpc: "2.0",
47
+ method: "ui/notifications/host-context-changed",
48
+ params: { displayMode: "fullscreen" },
49
+ },
50
+ }));
51
+ });
52
+ await waitFor(() => {
53
+ expect(result.current[0]).toBe("fullscreen");
54
+ });
30
55
  });
31
- it("should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called", async () => {
56
+ it("should call requestDisplayMode on the adaptor when setDisplayMode is called", async () => {
57
+ vi.stubGlobal("parent", {
58
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
59
+ });
32
60
  const { result } = renderHook(() => useDisplayMode());
61
+ await waitFor(() => expect(result.current[0]).toBe("inline"));
62
+ // Patch mcp.getApp to avoid real protocol request
63
+ const adaptor = getAdaptor();
64
+ const fakeApp = {
65
+ requestDisplayMode: vi.fn().mockResolvedValue({ mode: "fullscreen" }),
66
+ };
67
+ // biome-ignore lint/suspicious/noExplicitAny: test seam
68
+ adaptor.mcp.getApp = vi.fn().mockResolvedValue(fakeApp);
33
69
  await act(async () => {
34
70
  await result.current[1]("fullscreen");
35
71
  });
36
- expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({
72
+ expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({
37
73
  mode: "fullscreen",
38
74
  });
39
75
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-display-mode.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,UAGH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,G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AE,CAAC,8FAA8F,EAAE,KAAK,IAAI,EAAE;QAC5G,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACzD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport type { DisplayMode } from \"../bridges/types.js\";\nimport { useDisplayMode } from \"./use-display-mode.js\";\n\ndescribe(\"useDisplayMode\", () => {\n let OpenaiMock: {\n displayMode: DisplayMode;\n requestDisplayMode: Mock;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n displayMode: \"inline\",\n requestDisplayMode: vi.fn().mockResolvedValue({ mode: \"inline\" }),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return the current display mode from window.openai.displayMode\", () => {\n OpenaiMock.displayMode = \"inline\";\n const { result } = renderHook(() => useDisplayMode());\n\n expect(result.current[0]).toBe(\"inline\");\n });\n\n it(\"should return different display modes when window.openai.displayMode changes\", () => {\n OpenaiMock.displayMode = \"inline\";\n const { result, rerender } = renderHook(() => useDisplayMode());\n\n expect(result.current[0]).toBe(\"inline\");\n\n OpenaiMock.displayMode = \"fullscreen\";\n rerender();\n\n expect(result.current[0]).toBe(\"fullscreen\");\n });\n\n it(\"should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called\", async () => {\n const { result } = renderHook(() => useDisplayMode());\n\n await act(async () => {\n await result.current[1](\"fullscreen\");\n });\n\n expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({\n mode: \"fullscreen\",\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-display-mode.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,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,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC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AAY,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACtD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, fireEvent, renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDisplayMode } from \"./use-display-mode.js\";\n\ndescribe(\"useDisplayMode\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should return the current display mode from MCP host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n });\n\n it(\"should update display mode on host-context-changed notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n\n act(() => {\n fireEvent(\n window,\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params: { displayMode: \"fullscreen\" },\n },\n }),\n );\n });\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"fullscreen\");\n });\n });\n\n it(\"should call requestDisplayMode on the adaptor when setDisplayMode is called\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => expect(result.current[0]).toBe(\"inline\"));\n\n // Patch mcp.getApp to avoid real protocol request\n const adaptor = getAdaptor();\n const fakeApp = {\n requestDisplayMode: vi.fn().mockResolvedValue({ mode: \"fullscreen\" }),\n };\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n (adaptor as any).mcp.getApp = vi.fn().mockResolvedValue(fakeApp);\n\n await act(async () => {\n await result.current[1](\"fullscreen\");\n });\n\n expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({\n mode: \"fullscreen\",\n });\n });\n});\n"]}
@@ -1,6 +1,6 @@
1
1
  import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { AppsSdkAdaptor } from "../bridges/apps-sdk/adaptor.js";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
4
  import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
5
5
  import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
6
6
  import { useDownload } from "./use-download.js";
@@ -21,22 +21,26 @@ describe("useDownload", () => {
21
21
  beforeEach(() => {
22
22
  vi.stubGlobal("openai", {});
23
23
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
24
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
25
+ vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
24
26
  });
25
27
  afterEach(() => {
26
28
  vi.unstubAllGlobals();
27
29
  vi.resetAllMocks();
28
- AppsSdkAdaptor.resetInstance();
30
+ HostAdaptor.resetInstance();
31
+ McpAppBridge.resetInstance();
29
32
  });
30
33
  it("returns { isError: true } and logs an error", async () => {
31
34
  const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
32
35
  const { result } = renderHook(() => useDownload());
33
36
  const res = await result.current.download(params);
34
37
  expect(res).toEqual({ isError: true });
35
- expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("not supported on Apps SDK"));
38
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("does not support ui/download-file"));
36
39
  });
37
40
  });
38
41
  describe("mcp-app host without downloadFile capability", () => {
39
42
  beforeEach(() => {
43
+ vi.stubGlobal("openai", undefined);
40
44
  vi.stubGlobal("skybridge", { hostType: "mcp-app" });
41
45
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
42
46
  vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
@@ -44,6 +48,7 @@ describe("useDownload", () => {
44
48
  afterEach(async () => {
45
49
  vi.unstubAllGlobals();
46
50
  vi.resetAllMocks();
51
+ HostAdaptor.resetInstance();
47
52
  McpAppBridge.resetInstance();
48
53
  });
49
54
  it("returns { isError: true } and logs an error", async () => {
@@ -57,6 +62,7 @@ describe("useDownload", () => {
57
62
  describe("mcp-app host with downloadFile capability", () => {
58
63
  let postMessageMock;
59
64
  beforeEach(() => {
65
+ vi.stubGlobal("openai", undefined);
60
66
  vi.stubGlobal("skybridge", { hostType: "mcp-app" });
61
67
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
62
68
  postMessageMock = getMcpAppHostPostMessageMock({}, { hostCapabilities: { downloadFile: {} } });
@@ -65,6 +71,7 @@ describe("useDownload", () => {
65
71
  afterEach(async () => {
66
72
  vi.unstubAllGlobals();
67
73
  vi.resetAllMocks();
74
+ HostAdaptor.resetInstance();
68
75
  McpAppBridge.resetInstance();
69
76
  });
70
77
  it("sends ui/download-file with the provided contents", async () => {
@@ -80,6 +87,7 @@ describe("useDownload", () => {
80
87
  });
81
88
  });
82
89
  it("returns { isError: true } when the host denies the request", async () => {
90
+ HostAdaptor.resetInstance();
83
91
  McpAppBridge.resetInstance();
84
92
  postMessageMock = getMcpAppHostPostMessageMock({}, {
85
93
  hostCapabilities: { downloadFile: {} },
@@ -1 +1 @@
1
- {"version":3,"file":"use-download.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAmB;IAC7B,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,GAAG,EAAE,qBAAqB;gBAC1B,QAAQ,EAAE,kBAAkB;gBAC5B,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF;CACF,CAAC;AAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC5B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE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C;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { DownloadParams } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDownload } from \"./use-download.js\";\n\nconst params: DownloadParams = {\n contents: [\n {\n type: \"resource\",\n resource: {\n uri: \"file:///export.json\",\n mimeType: \"application/json\",\n text: '{\"hello\":\"world\"}',\n },\n },\n ],\n};\n\ndescribe(\"useDownload\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n AppsSdkAdaptor.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"not supported on Apps SDK\"),\n );\n });\n });\n\n describe(\"mcp-app host without downloadFile capability\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host with downloadFile capability\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n { hostCapabilities: { downloadFile: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends ui/download-file with the provided contents\", async () => {\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({});\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/download-file\",\n params,\n }),\n \"*\",\n );\n });\n });\n\n it(\"returns { isError: true } when the host denies the request\", async () => {\n McpAppBridge.resetInstance();\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n {\n hostCapabilities: { downloadFile: {} },\n downloadFileResult: { isError: true },\n },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-download.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAA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AC,WAAW,EAAE,CAAC,CAAC;YAEnD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAElD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACxB,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,kBAAkB;oBAC1B,MAAM;iBACP,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;YAC1E,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,eAAe,GAAG,4BAA4B,CAC5C,EAAE,EACF;gBACE,gBAAgB,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;gBACtC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACtC,CACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;YAE1D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAEnD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAElD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { DownloadParams } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDownload } from \"./use-download.js\";\n\nconst params: DownloadParams = {\n contents: [\n {\n type: \"resource\",\n resource: {\n uri: \"file:///export.json\",\n mimeType: \"application/json\",\n text: '{\"hello\":\"world\"}',\n },\n },\n ],\n};\n\ndescribe(\"useDownload\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host without downloadFile capability\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host with downloadFile capability\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n { hostCapabilities: { downloadFile: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends ui/download-file with the provided contents\", async () => {\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({});\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/download-file\",\n params,\n }),\n \"*\",\n );\n });\n });\n\n it(\"returns { isError: true } when the host denies the request\", async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n {\n hostCapabilities: { downloadFile: {} },\n downloadFileResult: { isError: true },\n },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n });\n });\n});\n"]}
@@ -1,6 +1,8 @@
1
1
  import { renderHook } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { AppsSdkAdaptor } from "../bridges/apps-sdk/adaptor.js";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
4
6
  import { useFiles } from "./use-files.js";
5
7
  describe("useFiles", () => {
6
8
  const OpenaiMock = {
@@ -12,13 +14,19 @@ describe("useFiles", () => {
12
14
  setWidgetState: vi.fn(),
13
15
  };
14
16
  beforeEach(() => {
17
+ HostAdaptor.resetInstance();
18
+ McpAppBridge.resetInstance();
19
+ AppsSdkBridge.resetInstance();
15
20
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
16
21
  vi.stubGlobal("openai", OpenaiMock);
22
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
17
23
  });
18
24
  afterEach(() => {
19
25
  vi.unstubAllGlobals();
20
26
  vi.clearAllMocks();
21
- AppsSdkAdaptor.resetInstance();
27
+ HostAdaptor.resetInstance();
28
+ McpAppBridge.resetInstance();
29
+ AppsSdkBridge.resetInstance();
22
30
  });
23
31
  const dummyFile = new File([], "test.txt");
24
32
  it("should upload a file to ChatGPT", () => {