skybridge 0.0.0-dev.df0cfdd → 0.0.0-dev.df1e961
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/cli/build-helpers.d.ts +1 -1
- package/dist/cli/build-helpers.js +4 -4
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +2 -2
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.js +1 -1
- package/dist/cli/build-steps.js.map +1 -1
- package/dist/cli/detect-port.js +0 -1
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.js +11 -3
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/dev.js +1 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +2 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/server/app.d.ts +194 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.js +97 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/auth/discovery.d.ts +2 -1
- package/dist/server/auth/discovery.js +2 -2
- package/dist/server/auth/discovery.js.map +1 -1
- package/dist/server/auth/index.d.ts +21 -17
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +2 -2
- package/dist/server/auth/providers/auth0.js +13 -8
- package/dist/server/auth/providers/auth0.js.map +1 -1
- package/dist/server/auth/providers/auth0.test.js +1 -1
- package/dist/server/auth/providers/auth0.test.js.map +1 -1
- package/dist/server/auth/providers/authplane.d.ts +2 -2
- package/dist/server/auth/providers/authplane.js.map +1 -1
- package/dist/server/auth/providers/authplane.test.js +10 -7
- package/dist/server/auth/providers/authplane.test.js.map +1 -1
- package/dist/server/auth/providers/clerk.d.ts +2 -2
- package/dist/server/auth/providers/clerk.js.map +1 -1
- package/dist/server/auth/providers/clerk.test.js +1 -1
- package/dist/server/auth/providers/clerk.test.js.map +1 -1
- package/dist/server/auth/providers/custom.d.ts +4 -4
- package/dist/server/auth/providers/custom.js +5 -2
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +13 -10
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +2 -2
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +3 -3
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- package/dist/server/auth/providers/stytch.d.ts +2 -2
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/workos.d.ts +2 -2
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/setup.d.ts +1 -1
- package/dist/server/auth/setup.js +3 -4
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +83 -77
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.js +2 -2
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth-extra.test-d.js +97 -49
- package/dist/server/auth-extra.test-d.js.map +1 -1
- package/dist/server/auth.d.ts +7 -8
- package/dist/server/auth.js +4 -5
- package/dist/server/auth.js.map +1 -1
- package/dist/server/build-manifest.test.js +7 -6
- package/dist/server/build-manifest.test.js.map +1 -1
- package/dist/server/content-helpers.d.ts +1 -1
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.d.ts +23 -3
- package/dist/server/express.js +38 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +220 -103
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +1 -1
- package/dist/server/file-ref.js +1 -1
- package/dist/server/file-ref.js.map +1 -1
- package/dist/server/index.d.ts +6 -3
- package/dist/server/index.js +3 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-errors.test.js +41 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/middleware.d.ts +6 -6
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +222 -150
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +27 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +74 -122
- package/dist/server/server.js +101 -302
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.js +19 -12
- package/dist/server/skills-integration.test.js.map +1 -1
- package/dist/server/skills.d.ts +3 -5
- package/dist/server/skills.js +17 -24
- package/dist/server/skills.js.map +1 -1
- package/dist/server/skills.test.js +8 -12
- package/dist/server/skills.test.js.map +1 -1
- package/dist/server/templateHelper.d.ts +0 -3
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js +4 -8
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +88 -0
- package/dist/server/tool-extra.test.js.map +1 -0
- package/dist/server/view-resource-resolution.test.js +18 -13
- package/dist/server/view-resource-resolution.test.js.map +1 -1
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +25 -37
- package/dist/test/view.test.js.map +1 -1
- package/dist/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/views/scan-views.d.ts +16 -0
- package/dist/views/scan-views.js +88 -0
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/views/scan-views.test.js +99 -0
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/views/validate-view.js +9 -0
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js +24 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.test.js +1 -1
- package/dist/web/bridges/adaptor.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.js +2 -2
- package/dist/web/bridges/get-adaptor.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +1 -1
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +17 -12
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/create-store.test.js +2 -2
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.test.js +2 -2
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +19 -15
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +3 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -2
- package/dist/web/hooks/index.js +2 -2
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +2 -2
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +1 -1
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +1 -3
- package/dist/web/hooks/use-download.js +1 -2
- package/dist/web/hooks/use-download.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +7 -7
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +1 -1
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/{use-host-info.d.ts → use-host.d.ts} +2 -2
- package/dist/web/hooks/{use-host-info.js → use-host.js} +3 -3
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/{use-host-info.test.js → use-host.test.js} +7 -7
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +2 -2
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
- package/dist/web/hooks/use-register-view-tool.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +1 -1
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +1 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +1 -1
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +1 -20
- package/dist/web/hooks/use-tool-info.js +0 -1
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +0 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +2 -7
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +5 -3
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +2 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/dist/web/mount-view.d.ts +3 -2
- package/dist/web/mount-view.js +5 -8
- package/dist/web/mount-view.js.map +1 -1
- package/package.json +15 -8
- package/dist/web/hooks/use-host-info.js.map +0 -1
- package/dist/web/hooks/use-host-info.test.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js.map +0 -1
- /package/dist/{web/hooks/use-host-info.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-layout.test.d.ts → server/mcp-errors.test.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OA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IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBACvD,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;oBACnC,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,KAAK;oBAChB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;oBAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, 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/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"openai\", {\n toolInput: null,\n toolOutput: null,\n toolResponseMetadata: null,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n });\n });\n });\n\n it(\"should return success state once tool-result notification arrives\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n fireToolResultNotification({\n content: [{ type: \"text\", text: JSON.stringify(toolOutput) }],\n structuredContent: toolOutput,\n _meta: toolResponseMetadata,\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with undefined input before tool-input notification arrives\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: undefined,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC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L,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, 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/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"openai\", {\n toolInput: null,\n toolOutput: null,\n toolResponseMetadata: null,\n });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isPending: true,\n isSuccess: false,\n });\n });\n });\n\n it(\"should return success state once tool-result notification arrives\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n fireToolResultNotification({\n content: [{ type: \"text\", text: JSON.stringify(toolOutput) }],\n structuredContent: toolOutput,\n _meta: toolResponseMetadata,\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with undefined input before tool-input notification arrives\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isPending: true,\n isSuccess: false,\n input: undefined,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type UserAgent } from "../bridges/index.js";
|
|
1
|
+
import { type Theme, type UserAgent } from "../bridges/index.js";
|
|
2
2
|
export type UserState = {
|
|
3
3
|
locale: string;
|
|
4
|
+
theme: Theme;
|
|
4
5
|
userAgent: UserAgent;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
@@ -9,7 +10,7 @@ export type UserState = {
|
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```tsx
|
|
12
|
-
* const { locale, userAgent } = useUser();
|
|
13
|
+
* const { locale, theme, userAgent } = useUser();
|
|
13
14
|
*
|
|
14
15
|
* // Access device type
|
|
15
16
|
* const isMobile = userAgent.device.type === "mobile";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useHostContext } from "../bridges/index.js";
|
|
1
|
+
import { useHostContext, } from "../bridges/index.js";
|
|
2
2
|
const DEFAULT_LOCALE = "en-US";
|
|
3
3
|
/**
|
|
4
4
|
* Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.
|
|
@@ -21,7 +21,7 @@ function normalizeLocale(locale) {
|
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```tsx
|
|
24
|
-
* const { locale, userAgent } = useUser();
|
|
24
|
+
* const { locale, theme, userAgent } = useUser();
|
|
25
25
|
*
|
|
26
26
|
* // Access device type
|
|
27
27
|
* const isMobile = userAgent.device.type === "mobile";
|
|
@@ -31,7 +31,8 @@ function normalizeLocale(locale) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function useUser() {
|
|
33
33
|
const rawLocale = useHostContext("locale");
|
|
34
|
+
const theme = useHostContext("theme");
|
|
34
35
|
const userAgent = useHostContext("userAgent");
|
|
35
|
-
return { locale: normalizeLocale(rawLocale), userAgent };
|
|
36
|
+
return { locale: normalizeLocale(rawLocale), theme, userAgent };
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=use-user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,GACf,MAAM,qBAAqB,CAAC;AAQ7B,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAClE,CAAC","sourcesContent":["import {\n type Theme,\n type UserAgent,\n useHostContext,\n} from \"../bridges/index.js\";\n\nexport type UserState = {\n locale: string;\n theme: Theme;\n userAgent: UserAgent;\n};\n\nconst DEFAULT_LOCALE = \"en-US\";\n\n/**\n * Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.\n *\n * Handles underscored identifiers returned by the ChatGPT mobile app (e.g. \"fr_FR\" → \"fr-FR\"),\n * incorrect casing (e.g. \"en-us\" → \"en-US\"), and complex subtags (e.g. \"zh_Hans_CN\" → \"zh-Hans-CN\").\n * Falls back to \"en-US\" if the locale is invalid.\n */\nfunction normalizeLocale(locale: string): string {\n try {\n return new Intl.Locale(locale.replace(/_/g, \"-\")).toString();\n } catch {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Hook for accessing session-stable user information.\n * These values are set once at initialization and do not change during the session.\n *\n * @example\n * ```tsx\n * const { locale, theme, userAgent } = useUser();\n *\n * // Access device type\n * const isMobile = userAgent.device.type === \"mobile\";\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-user\n */\nexport function useUser(): UserState {\n const rawLocale = useHostContext(\"locale\");\n const theme = useHostContext(\"theme\");\n const userAgent = useHostContext(\"userAgent\");\n\n return { locale: normalizeLocale(rawLocale), theme, userAgent };\n}\n"]}
|
|
@@ -10,7 +10,7 @@ describe("useUser", () => {
|
|
|
10
10
|
HostAdaptor.resetInstance();
|
|
11
11
|
McpAppBridge.resetInstance();
|
|
12
12
|
vi.stubGlobal("openai", { locale: "en-US" });
|
|
13
|
-
vi.stubGlobal("skybridge", {
|
|
13
|
+
vi.stubGlobal("skybridge", {});
|
|
14
14
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
15
15
|
});
|
|
16
16
|
afterEach(() => {
|
|
@@ -19,10 +19,11 @@ describe("useUser", () => {
|
|
|
19
19
|
McpAppBridge.resetInstance();
|
|
20
20
|
HostAdaptor.resetInstance();
|
|
21
21
|
});
|
|
22
|
-
it("should return locale and userAgent from mcp host context", async () => {
|
|
22
|
+
it("should return locale, theme and userAgent from mcp host context", async () => {
|
|
23
23
|
vi.stubGlobal("parent", {
|
|
24
24
|
postMessage: getMcpAppHostPostMessageMock({
|
|
25
25
|
locale: "en-US",
|
|
26
|
+
theme: "dark",
|
|
26
27
|
platform: "web",
|
|
27
28
|
deviceCapabilities: { hover: true, touch: false },
|
|
28
29
|
}),
|
|
@@ -30,6 +31,7 @@ describe("useUser", () => {
|
|
|
30
31
|
const { result } = renderHook(() => useUser());
|
|
31
32
|
await waitFor(() => {
|
|
32
33
|
expect(result.current.locale).toBe("en-US");
|
|
34
|
+
expect(result.current.theme).toBe("dark");
|
|
33
35
|
expect(result.current.userAgent).toEqual({
|
|
34
36
|
device: { type: "desktop" },
|
|
35
37
|
capabilities: { hover: true, touch: false },
|
|
@@ -108,7 +110,7 @@ describe("useUser", () => {
|
|
|
108
110
|
HostAdaptor.resetInstance();
|
|
109
111
|
McpAppBridge.resetInstance();
|
|
110
112
|
vi.stubGlobal("openai", undefined);
|
|
111
|
-
vi.stubGlobal("skybridge", {
|
|
113
|
+
vi.stubGlobal("skybridge", {});
|
|
112
114
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
113
115
|
});
|
|
114
116
|
afterEach(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.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,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,UAAU,CAAC,GAAG,EAAE;YACd,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAC7C,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;YACrD,EA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MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAEzD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YAElD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,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 {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", { locale: \"en-US\" });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"mobile\",\n deviceCapabilities: { hover: false, touch: true },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n });\n\n it(\"should return different locale when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"es-ES\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"es-ES\");\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should canonicalize locale casing\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-us\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n it(\"should fall back to en-US for invalid locale\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"not-a-locale-!!\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA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,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 {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", { locale: \"en-US\" });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale, theme and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n theme: \"dark\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.theme).toBe(\"dark\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"mobile\",\n deviceCapabilities: { hover: false, touch: true },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n });\n\n it(\"should return different locale when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"es-ES\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"es-ES\");\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should canonicalize locale casing\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-us\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n it(\"should fall back to en-US for invalid locale\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"not-a-locale-!!\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
@@ -13,7 +13,7 @@ describe("useViewState", () => {
|
|
|
13
13
|
setWidgetState: vi.fn().mockResolvedValue(undefined),
|
|
14
14
|
};
|
|
15
15
|
vi.stubGlobal("openai", OpenaiMock);
|
|
16
|
-
vi.stubGlobal("skybridge", {
|
|
16
|
+
vi.stubGlobal("skybridge", {});
|
|
17
17
|
});
|
|
18
18
|
afterEach(() => {
|
|
19
19
|
vi.unstubAllGlobals();
|
|
@@ -100,7 +100,7 @@ describe("useViewState", () => {
|
|
|
100
100
|
describe("useViewState (mcp-app host — localStorage persistence)", () => {
|
|
101
101
|
beforeEach(() => {
|
|
102
102
|
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
103
|
-
vi.stubGlobal("skybridge", {
|
|
103
|
+
vi.stubGlobal("skybridge", {});
|
|
104
104
|
vi.stubGlobal("openai", undefined);
|
|
105
105
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
106
106
|
localStorage.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-view-state.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-view-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,UAA0D,CAAC;IAE/D,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAAW,EAAE,IAAI;YACjB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;SACrD,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACnB,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;IAC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,EAAE;YACnB,0BAA0B,CAAC;gBACzB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC3C,iBAAiB,EAAE,EAAE;gBACrB,KAAK,EAAE,EAAE,QAAQ,EAAE;aACpB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,EAAE;YACP,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,sDAAsD;QACtD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport { StrictMode } from \"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 { McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useViewState } from \"./use-view-state.js\";\n\ndescribe(\"useViewState\", () => {\n let OpenaiMock: { widgetState: unknown; setWidgetState: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: null,\n setWidgetState: vi.fn().mockResolvedValue(undefined),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n const defaultState = { count: 0, name: \"test\" };\n const windowState = { count: 5, name: \"window\" };\n\n it(\"should initialize with default state when window.openai.widgetState is null\", () => {\n OpenaiMock.widgetState = null;\n const { result } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(defaultState);\n });\n\n it(\"should initialize with window.openai.widgetState when available\", () => {\n OpenaiMock.widgetState = { modelContent: windowState };\n const { result } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(windowState);\n });\n\n it(\"should call window.openai.setWidgetState when setViewState is called with a new state\", async () => {\n const { result } = renderHook(() => useViewState(defaultState));\n const newState = { count: 10, name: \"updated\" };\n\n act(() => {\n result.current[1](newState);\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({\n modelContent: newState,\n privateContent: {},\n });\n expect(result.current[0]).toEqual(newState);\n });\n\n it(\"should call window.openai.setWidgetState when setViewState is called with a function updater\", async () => {\n const { result } = renderHook(() => useViewState(defaultState));\n\n act(() => {\n result.current[1]((prev) => ({ ...prev, count: prev.count + 1 }));\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({\n modelContent: { count: 1, name: \"test\" },\n privateContent: {},\n });\n expect(result.current[0]).toEqual({ count: 1, name: \"test\" });\n });\n\n it(\"should call window.openai.setWidgetState once per update under StrictMode\", () => {\n const { result } = renderHook(() => useViewState(defaultState), {\n wrapper: StrictMode,\n });\n\n act(() => {\n result.current[1]({ count: 10, name: \"updated\" });\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledTimes(1);\n });\n\n it(\"should not persist anything on mount\", () => {\n renderHook(() => useViewState(defaultState), { wrapper: StrictMode });\n\n expect(OpenaiMock.setWidgetState).not.toHaveBeenCalled();\n });\n\n it(\"should persist state when setViewState and unmount happen in the same tick\", () => {\n const { result, unmount } = renderHook(() => useViewState(defaultState));\n\n act(() => {\n result.current[1]({ count: 10, name: \"updated\" });\n unmount();\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledTimes(1);\n });\n\n it(\"should not persist state when setViewState is called after unmount\", () => {\n const { result, unmount } = renderHook(() => useViewState(defaultState));\n const setViewState = result.current[1];\n\n unmount();\n\n act(() => {\n setViewState({ count: 10, name: \"updated\" });\n });\n\n expect(OpenaiMock.setWidgetState).not.toHaveBeenCalled();\n });\n\n it(\"should update state when window.openai.widgetState changes\", () => {\n OpenaiMock.widgetState = { modelContent: defaultState };\n const { result, rerender } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(defaultState);\n\n // Simulate window.openai.widgetState changing\n OpenaiMock.widgetState = { modelContent: windowState };\n // Trigger re-render to simulate the useEffect running\n rerender();\n\n expect(result.current[0]).toEqual(windowState);\n });\n});\n\ndescribe(\"useViewState (mcp-app host — localStorage persistence)\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n localStorage.clear();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n localStorage.clear();\n });\n\n it(\"should persist state to localStorage when viewUUID is available\", async () => {\n const viewUUID = \"test-uuid-123\";\n const { result } = renderHook(() => useViewState({ page: 1, zoom: 100 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 3, zoom: 150 });\n });\n\n expect(result.current[0]).toEqual({ page: 3, zoom: 150 });\n expect(localStorage.length).toBe(1);\n });\n\n it(\"should restore state from localStorage when viewUUID arrives\", async () => {\n const viewUUID = \"test-uuid-456\";\n // Pre-seed with the sb:{timestamp}:{viewUUID} format\n localStorage.setItem(\n `sb:1700000000000:${viewUUID}`,\n JSON.stringify({ page: 5, zoom: 200 }),\n );\n\n const { result } = renderHook(() => useViewState({ page: 1, zoom: 100 }));\n\n act(() => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n await waitFor(() => {\n expect(result.current[0]).toEqual({ page: 5, zoom: 200 });\n });\n });\n\n it(\"should not persist when no viewUUID is available\", () => {\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n act(() => {\n result.current[1]({ page: 2 });\n });\n\n expect(result.current[0]).toEqual({ page: 2 });\n expect(localStorage.length).toBe(0);\n });\n\n it(\"should handle corrupted localStorage data gracefully\", async () => {\n const viewUUID = \"test-uuid-corrupt\";\n localStorage.setItem(`sb:1700000000000:${viewUUID}`, \"not valid json{{{\");\n\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n act(() => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n await waitFor(() => {\n expect(result.current[0]).toEqual({ page: 1 });\n });\n });\n\n it(\"should refresh localStorage timestamp on each persist (LRU)\", async () => {\n const viewUUID = \"lru-test-uuid\";\n const oldKey = `sb:1000000000000:${viewUUID}`;\n localStorage.setItem(oldKey, JSON.stringify({ page: 1 }));\n\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 2 });\n });\n\n // Old key removed, replaced with a new one (still just 1 entry)\n expect(localStorage.getItem(oldKey)).toBeNull();\n expect(localStorage.length).toBe(1);\n });\n\n it(\"should evict oldest entries when exceeding max storage entries\", async () => {\n // Fill localStorage with 200 entries (the max)\n for (let i = 0; i < 200; i++) {\n localStorage.setItem(\n `sb:${String(1000000000000 + i)}:old-uuid-${String(i).padStart(4, \"0\")}`,\n JSON.stringify({ i }),\n );\n }\n expect(localStorage.length).toBe(200);\n\n const viewUUID = \"eviction-test-uuid\";\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 99 });\n });\n\n // Should have evicted the oldest entry to stay at 200\n expect(localStorage.length).toBe(200);\n expect(localStorage.getItem(\"sb:1000000000000:old-uuid-0000\")).toBeNull();\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-view-state.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-view-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,UAA0D,CAAC;IAE/D,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAAW,EAAE,IAAI;YACjB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;SACrD,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,E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CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE/D,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,0BAA0B,CAAC;gBACzB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC3C,iBAAiB,EAAE,EAAE;gBACrB,KAAK,EAAE,EAAE,QAAQ,EAAE;aACpB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,EAAE;YACP,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,sDAAsD;QACtD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport { StrictMode } from \"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 { McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useViewState } from \"./use-view-state.js\";\n\ndescribe(\"useViewState\", () => {\n let OpenaiMock: { widgetState: unknown; setWidgetState: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: null,\n setWidgetState: vi.fn().mockResolvedValue(undefined),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", {});\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n const defaultState = { count: 0, name: \"test\" };\n const windowState = { count: 5, name: \"window\" };\n\n it(\"should initialize with default state when window.openai.widgetState is null\", () => {\n OpenaiMock.widgetState = null;\n const { result } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(defaultState);\n });\n\n it(\"should initialize with window.openai.widgetState when available\", () => {\n OpenaiMock.widgetState = { modelContent: windowState };\n const { result } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(windowState);\n });\n\n it(\"should call window.openai.setWidgetState when setViewState is called with a new state\", async () => {\n const { result } = renderHook(() => useViewState(defaultState));\n const newState = { count: 10, name: \"updated\" };\n\n act(() => {\n result.current[1](newState);\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({\n modelContent: newState,\n privateContent: {},\n });\n expect(result.current[0]).toEqual(newState);\n });\n\n it(\"should call window.openai.setWidgetState when setViewState is called with a function updater\", async () => {\n const { result } = renderHook(() => useViewState(defaultState));\n\n act(() => {\n result.current[1]((prev) => ({ ...prev, count: prev.count + 1 }));\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({\n modelContent: { count: 1, name: \"test\" },\n privateContent: {},\n });\n expect(result.current[0]).toEqual({ count: 1, name: \"test\" });\n });\n\n it(\"should call window.openai.setWidgetState once per update under StrictMode\", () => {\n const { result } = renderHook(() => useViewState(defaultState), {\n wrapper: StrictMode,\n });\n\n act(() => {\n result.current[1]({ count: 10, name: \"updated\" });\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledTimes(1);\n });\n\n it(\"should not persist anything on mount\", () => {\n renderHook(() => useViewState(defaultState), { wrapper: StrictMode });\n\n expect(OpenaiMock.setWidgetState).not.toHaveBeenCalled();\n });\n\n it(\"should persist state when setViewState and unmount happen in the same tick\", () => {\n const { result, unmount } = renderHook(() => useViewState(defaultState));\n\n act(() => {\n result.current[1]({ count: 10, name: \"updated\" });\n unmount();\n });\n\n expect(OpenaiMock.setWidgetState).toHaveBeenCalledTimes(1);\n });\n\n it(\"should not persist state when setViewState is called after unmount\", () => {\n const { result, unmount } = renderHook(() => useViewState(defaultState));\n const setViewState = result.current[1];\n\n unmount();\n\n act(() => {\n setViewState({ count: 10, name: \"updated\" });\n });\n\n expect(OpenaiMock.setWidgetState).not.toHaveBeenCalled();\n });\n\n it(\"should update state when window.openai.widgetState changes\", () => {\n OpenaiMock.widgetState = { modelContent: defaultState };\n const { result, rerender } = renderHook(() => useViewState(defaultState));\n\n expect(result.current[0]).toEqual(defaultState);\n\n // Simulate window.openai.widgetState changing\n OpenaiMock.widgetState = { modelContent: windowState };\n // Trigger re-render to simulate the useEffect running\n rerender();\n\n expect(result.current[0]).toEqual(windowState);\n });\n});\n\ndescribe(\"useViewState (mcp-app host — localStorage persistence)\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n localStorage.clear();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n localStorage.clear();\n });\n\n it(\"should persist state to localStorage when viewUUID is available\", async () => {\n const viewUUID = \"test-uuid-123\";\n const { result } = renderHook(() => useViewState({ page: 1, zoom: 100 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 3, zoom: 150 });\n });\n\n expect(result.current[0]).toEqual({ page: 3, zoom: 150 });\n expect(localStorage.length).toBe(1);\n });\n\n it(\"should restore state from localStorage when viewUUID arrives\", async () => {\n const viewUUID = \"test-uuid-456\";\n // Pre-seed with the sb:{timestamp}:{viewUUID} format\n localStorage.setItem(\n `sb:1700000000000:${viewUUID}`,\n JSON.stringify({ page: 5, zoom: 200 }),\n );\n\n const { result } = renderHook(() => useViewState({ page: 1, zoom: 100 }));\n\n act(() => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n await waitFor(() => {\n expect(result.current[0]).toEqual({ page: 5, zoom: 200 });\n });\n });\n\n it(\"should not persist when no viewUUID is available\", () => {\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n act(() => {\n result.current[1]({ page: 2 });\n });\n\n expect(result.current[0]).toEqual({ page: 2 });\n expect(localStorage.length).toBe(0);\n });\n\n it(\"should handle corrupted localStorage data gracefully\", async () => {\n const viewUUID = \"test-uuid-corrupt\";\n localStorage.setItem(`sb:1700000000000:${viewUUID}`, \"not valid json{{{\");\n\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n act(() => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n await waitFor(() => {\n expect(result.current[0]).toEqual({ page: 1 });\n });\n });\n\n it(\"should refresh localStorage timestamp on each persist (LRU)\", async () => {\n const viewUUID = \"lru-test-uuid\";\n const oldKey = `sb:1000000000000:${viewUUID}`;\n localStorage.setItem(oldKey, JSON.stringify({ page: 1 }));\n\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 2 });\n });\n\n // Old key removed, replaced with a new one (still just 1 entry)\n expect(localStorage.getItem(oldKey)).toBeNull();\n expect(localStorage.length).toBe(1);\n });\n\n it(\"should evict oldest entries when exceeding max storage entries\", async () => {\n // Fill localStorage with 200 entries (the max)\n for (let i = 0; i < 200; i++) {\n localStorage.setItem(\n `sb:${String(1000000000000 + i)}:old-uuid-${String(i).padStart(4, \"0\")}`,\n JSON.stringify({ i }),\n );\n }\n expect(localStorage.length).toBe(200);\n\n const viewUUID = \"eviction-test-uuid\";\n const { result } = renderHook(() => useViewState({ page: 1 }));\n\n await act(async () => {\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"result\" }],\n structuredContent: {},\n _meta: { viewUUID },\n });\n });\n\n act(() => {\n result.current[1]({ page: 99 });\n });\n\n // Should have evicted the oldest entry to stay at 200\n expect(localStorage.length).toBe(200);\n expect(localStorage.getItem(\"sb:1000000000000:old-uuid-0000\")).toBeNull();\n });\n});\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type SafeArea } from "../bridges/index.js";
|
|
2
|
+
export type ViewportState = {
|
|
3
|
+
maxHeight: number | undefined;
|
|
4
|
+
safeArea: SafeArea;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook for accessing the live viewport geometry the host grants the view.
|
|
8
|
+
* These values change on resize, so consumers re-render with them by design.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { maxHeight, safeArea } = useViewport();
|
|
13
|
+
*
|
|
14
|
+
* // Respect safe area insets
|
|
15
|
+
* const paddingTop = safeArea.insets.top;
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-viewport
|
|
19
|
+
*/
|
|
20
|
+
export declare function useViewport(): ViewportState;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing the live viewport geometry the host grants the view.
|
|
4
|
+
* These values change on resize, so consumers re-render with them by design.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const { maxHeight, safeArea } = useViewport();
|
|
9
|
+
*
|
|
10
|
+
* // Respect safe area insets
|
|
11
|
+
* const paddingTop = safeArea.insets.top;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-viewport
|
|
15
|
+
*/
|
|
16
|
+
export function useViewport() {
|
|
17
|
+
const maxHeight = useHostContext("maxHeight");
|
|
18
|
+
const safeArea = useHostContext("safeArea");
|
|
19
|
+
return { maxHeight, safeArea };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-viewport.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOpE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { type SafeArea, useHostContext } from \"../bridges/index.js\";\n\nexport type ViewportState = {\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing the live viewport geometry the host grants the view.\n * These values change on resize, so consumers re-render with them by design.\n *\n * @example\n * ```tsx\n * const { maxHeight, safeArea } = useViewport();\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-viewport\n */\nexport function useViewport(): ViewportState {\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { maxHeight, safeArea };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,13 +3,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
3
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
|
-
import {
|
|
7
|
-
describe("
|
|
6
|
+
import { useViewport } from "./use-viewport.js";
|
|
7
|
+
describe("useViewport", () => {
|
|
8
8
|
describe("apps-sdk host type", () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
HostAdaptor.resetInstance();
|
|
11
11
|
McpAppBridge.resetInstance();
|
|
12
|
-
vi.stubGlobal("skybridge", {
|
|
12
|
+
vi.stubGlobal("skybridge", {});
|
|
13
13
|
vi.stubGlobal("openai", { view: { mode: "inline" } });
|
|
14
14
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
15
15
|
});
|
|
@@ -19,45 +19,29 @@ describe("useLayout", () => {
|
|
|
19
19
|
McpAppBridge.resetInstance();
|
|
20
20
|
HostAdaptor.resetInstance();
|
|
21
21
|
});
|
|
22
|
-
it("should return
|
|
22
|
+
it("should return maxHeight and safeArea from mcp host context", async () => {
|
|
23
23
|
vi.stubGlobal("parent", {
|
|
24
24
|
postMessage: getMcpAppHostPostMessageMock({
|
|
25
|
-
theme: "light",
|
|
26
25
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
27
26
|
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
28
27
|
}),
|
|
29
28
|
});
|
|
30
|
-
const { result } = renderHook(() =>
|
|
29
|
+
const { result } = renderHook(() => useViewport());
|
|
31
30
|
await waitFor(() => {
|
|
32
|
-
expect(result.current.theme).toBe("light");
|
|
33
31
|
expect(result.current.maxHeight).toBe(500);
|
|
34
32
|
expect(result.current.safeArea).toEqual({
|
|
35
33
|
insets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
36
34
|
});
|
|
37
35
|
});
|
|
38
36
|
});
|
|
39
|
-
it("should return dark theme when set to dark", async () => {
|
|
40
|
-
vi.stubGlobal("parent", {
|
|
41
|
-
postMessage: getMcpAppHostPostMessageMock({
|
|
42
|
-
theme: "dark",
|
|
43
|
-
containerDimensions: { maxHeight: 500, width: 400 },
|
|
44
|
-
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
45
|
-
}),
|
|
46
|
-
});
|
|
47
|
-
const { result } = renderHook(() => useLayout());
|
|
48
|
-
await waitFor(() => {
|
|
49
|
-
expect(result.current.theme).toBe("dark");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
37
|
it("should return different maxHeight when set", async () => {
|
|
53
38
|
vi.stubGlobal("parent", {
|
|
54
39
|
postMessage: getMcpAppHostPostMessageMock({
|
|
55
|
-
theme: "light",
|
|
56
40
|
containerDimensions: { maxHeight: 800, width: 400 },
|
|
57
41
|
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
58
42
|
}),
|
|
59
43
|
});
|
|
60
|
-
const { result } = renderHook(() =>
|
|
44
|
+
const { result } = renderHook(() => useViewport());
|
|
61
45
|
await waitFor(() => {
|
|
62
46
|
expect(result.current.maxHeight).toBe(800);
|
|
63
47
|
});
|
|
@@ -65,12 +49,11 @@ describe("useLayout", () => {
|
|
|
65
49
|
it("should return safeArea with insets when set", async () => {
|
|
66
50
|
vi.stubGlobal("parent", {
|
|
67
51
|
postMessage: getMcpAppHostPostMessageMock({
|
|
68
|
-
theme: "light",
|
|
69
52
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
70
53
|
safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },
|
|
71
54
|
}),
|
|
72
55
|
});
|
|
73
|
-
const { result } = renderHook(() =>
|
|
56
|
+
const { result } = renderHook(() => useViewport());
|
|
74
57
|
await waitFor(() => {
|
|
75
58
|
expect(result.current.safeArea.insets.top).toBe(44);
|
|
76
59
|
expect(result.current.safeArea.insets.bottom).toBe(34);
|
|
@@ -81,7 +64,7 @@ describe("useLayout", () => {
|
|
|
81
64
|
beforeEach(() => {
|
|
82
65
|
HostAdaptor.resetInstance();
|
|
83
66
|
McpAppBridge.resetInstance();
|
|
84
|
-
vi.stubGlobal("skybridge", {
|
|
67
|
+
vi.stubGlobal("skybridge", {});
|
|
85
68
|
vi.stubGlobal("openai", undefined);
|
|
86
69
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
87
70
|
});
|
|
@@ -91,17 +74,15 @@ describe("useLayout", () => {
|
|
|
91
74
|
McpAppBridge.resetInstance();
|
|
92
75
|
HostAdaptor.resetInstance();
|
|
93
76
|
});
|
|
94
|
-
it("should return
|
|
77
|
+
it("should return maxHeight and safeArea from mcp host context", async () => {
|
|
95
78
|
vi.stubGlobal("parent", {
|
|
96
79
|
postMessage: getMcpAppHostPostMessageMock({
|
|
97
|
-
theme: "dark",
|
|
98
80
|
containerDimensions: { maxHeight: 800, width: 400 },
|
|
99
81
|
safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },
|
|
100
82
|
}),
|
|
101
83
|
});
|
|
102
|
-
const { result } = renderHook(() =>
|
|
84
|
+
const { result } = renderHook(() => useViewport());
|
|
103
85
|
await waitFor(() => {
|
|
104
|
-
expect(result.current.theme).toBe("dark");
|
|
105
86
|
expect(result.current.maxHeight).toBe(800);
|
|
106
87
|
expect(result.current.safeArea).toEqual({
|
|
107
88
|
insets: { top: 20, right: 0, bottom: 34, left: 0 },
|
|
@@ -111,12 +92,11 @@ describe("useLayout", () => {
|
|
|
111
92
|
it("should maintain safeArea referential stability when data has not changed", async () => {
|
|
112
93
|
vi.stubGlobal("parent", {
|
|
113
94
|
postMessage: getMcpAppHostPostMessageMock({
|
|
114
|
-
theme: "light",
|
|
115
95
|
containerDimensions: { maxHeight: 500, width: 400 },
|
|
116
96
|
safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },
|
|
117
97
|
}),
|
|
118
98
|
});
|
|
119
|
-
const { result, rerender } = renderHook(() =>
|
|
99
|
+
const { result, rerender } = renderHook(() => useViewport());
|
|
120
100
|
await waitFor(() => {
|
|
121
101
|
expect(result.current.safeArea).toBeDefined();
|
|
122
102
|
});
|
|
@@ -126,4 +106,4 @@ describe("useLayout", () => {
|
|
|
126
106
|
});
|
|
127
107
|
});
|
|
128
108
|
});
|
|
129
|
-
//# sourceMappingURL=use-
|
|
109
|
+
//# sourceMappingURL=use-viewport.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-viewport.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.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,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,UAAU,CAAC,GAAG,EAAE;YACd,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC/B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;YACnB,YAAY,CAAC,aAAa,EAAE,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C;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;YACxF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,WAAW,EAAE,4BAA4B,CAAC;oBACxC,mBAAmB,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE;oBACnD,cAAc,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;iBAC3D,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAE7D,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAEhD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,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 {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useViewport } from \"./use-viewport.js\";\n\ndescribe(\"useViewport\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}
|
package/dist/web/mount-view.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mount a view's root React component into `#root`.
|
|
3
|
-
*
|
|
2
|
+
* Mount a view's root React component into `#root`. The Vite plugin
|
|
3
|
+
* auto-mounts every view, so apps normally never call this themselves —
|
|
4
|
+
* it is the entry point the generated view wrappers use.
|
|
4
5
|
*
|
|
5
6
|
* Wraps the component in `StrictMode`, applies host-specific providers
|
|
6
7
|
* automatically (e.g. modal support for MCP Apps), and installs the dev-mode
|
package/dist/web/mount-view.js
CHANGED
|
@@ -4,8 +4,9 @@ import { createRoot } from "react-dom/client";
|
|
|
4
4
|
import { installOpenAILoggingProxy } from "./proxy.js";
|
|
5
5
|
let rootInstance = null;
|
|
6
6
|
/**
|
|
7
|
-
* Mount a view's root React component into `#root`.
|
|
8
|
-
*
|
|
7
|
+
* Mount a view's root React component into `#root`. The Vite plugin
|
|
8
|
+
* auto-mounts every view, so apps normally never call this themselves —
|
|
9
|
+
* it is the entry point the generated view wrappers use.
|
|
9
10
|
*
|
|
10
11
|
* Wraps the component in `StrictMode`, applies host-specific providers
|
|
11
12
|
* automatically (e.g. modal support for MCP Apps), and installs the dev-mode
|
|
@@ -33,13 +34,9 @@ export const mountView = (component) => {
|
|
|
33
34
|
if (import.meta.env.DEV) {
|
|
34
35
|
installOpenAILoggingProxy();
|
|
35
36
|
}
|
|
36
|
-
const hostType = window.skybridge?.hostType;
|
|
37
37
|
(async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const { ModalProvider } = await import("./components/modal-provider.js");
|
|
41
|
-
app = createElement(ModalProvider, null, component);
|
|
42
|
-
}
|
|
38
|
+
const { ModalProvider } = await import("./components/modal-provider.js");
|
|
39
|
+
const app = createElement(ModalProvider, null, component);
|
|
43
40
|
rootInstance.render(createElement(StrictMode, null, app));
|
|
44
41
|
})();
|
|
45
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-view.js","sourceRoot":"","sources":["../../src/web/mount-view.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"mount-view.js","sourceRoot":"","sources":["../../src/web/mount-view.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAA0B,EAAE,EAAE;IACtD,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;IAC9B,CAAC;IAED,CAAC,KAAK,IAAI,EAAE;QACV,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;QACzE,MAAM,GAAG,GAAG,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAC1D,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC","sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { createElement, StrictMode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { installOpenAILoggingProxy } from \"./proxy.js\";\n\nlet rootInstance: Root | null = null;\n\n/**\n * Mount a view's root React component into `#root`. The Vite plugin\n * auto-mounts every view, so apps normally never call this themselves —\n * it is the entry point the generated view wrappers use.\n *\n * Wraps the component in `StrictMode`, applies host-specific providers\n * automatically (e.g. modal support for MCP Apps), and installs the dev-mode\n * logging proxy for `window.openai` calls.\n *\n * @param component - Your root React element (already constructed, e.g. `<App />`).\n *\n * @example\n * ```tsx\n * // src/views/search.tsx\n * import { mountView } from \"skybridge/web\";\n * import { App } from \"./App\";\n *\n * mountView(<App />);\n * ```\n */\nexport const mountView = (component: React.ReactNode) => {\n const rootElement = document.getElementById(\"root\");\n if (!rootElement) {\n throw new Error(\"Root element not found\");\n }\n\n if (!rootInstance) {\n rootInstance = createRoot(rootElement);\n }\n\n if (import.meta.env.DEV) {\n installOpenAILoggingProxy();\n }\n\n (async () => {\n const { ModalProvider } = await import(\"./components/modal-provider.js\");\n const app = createElement(ModalProvider, null, component);\n rootInstance.render(createElement(StrictMode, null, app));\n })();\n};\n"]}
|