skybridge 0.0.0-dev.fec1c58 → 0.0.0-dev.fef24cf
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 +123 -116
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/tunnel-control-server.d.ts +9 -0
- package/dist/cli/tunnel-control-server.js +31 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.d.ts +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -6
- package/dist/cli/use-nodemon.js +18 -14
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +1 -0
- package/dist/cli/use-typescript-check.js +42 -7
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.js +63 -7
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +4 -1
- package/dist/commands/dev.js +57 -8
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +30 -9
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
- package/dist/server/asset-base-url-transform-plugin.js +25 -11
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/content-helpers.d.ts +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +7 -5
- package/dist/server/express.js +60 -28
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +381 -25
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/index.d.ts +7 -3
- package/dist/server/index.js +5 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +137 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +358 -69
- package/dist/server/server.js +469 -102
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -8
- package/dist/server/templateHelper.js +3 -22
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +47 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +16 -244
- package/dist/test/utils.js +42 -37
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +568 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +13 -7
- package/dist/web/bridges/apps-sdk/adaptor.js +62 -29
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +2 -1
- package/dist/web/bridges/apps-sdk/bridge.js +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +26 -11
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +7 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +25 -9
- package/dist/web/bridges/mcp-app/adaptor.js +156 -66
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +14 -30
- package/dist/web/bridges/mcp-app/bridge.js +44 -196
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
- 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 -41
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +87 -14
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.js +3 -5
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +21 -18
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +31 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +24 -23
- 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 +22 -18
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +26 -26
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +5 -2
- package/dist/web/hooks/index.js +4 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +6 -2
- package/dist/web/hooks/test/utils.js +17 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +27 -6
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +23 -3
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +95 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +34 -1
- package/dist/web/hooks/use-files.js +33 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +22 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +3 -3
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +20 -1
- package/dist/web/hooks/use-open-external.js +17 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +26 -11
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +52 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +19 -4
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +65 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +5 -11
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +33 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +1 -1
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +20 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +29 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +177 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -2
- package/dist/web/index.js +1 -2
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +20 -0
- package/dist/web/{mount-widget.js → mount-view.js} +21 -2
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +32 -1
- package/dist/web/plugin/plugin.js +161 -18
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +16 -0
- package/dist/web/plugin/scan-views.js +88 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +99 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.js +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- package/dist/web/plugin/validate-view.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +42 -25
- package/tsconfig.base.json +33 -0
- package/dist/server/templates/development.hbs +0 -67
- package/dist/server/templates/production.hbs +0 -6
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -57
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -261
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/web/hooks/use-widget-state.js +0 -32
- package/dist/web/hooks/use-widget-state.js.map +0 -1
- package/dist/web/hooks/use-widget-state.test.js +0 -62
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../src/web/helpers/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"state.test.js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AAC,CAAC;YAC5D,MAAM,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YACvC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG;gBACb,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK;gBACL,IAAI;gBACJ,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;aACvB,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAC/B,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { VIEW_CONTEXT_KEY } from \"../data-llm.js\";\nimport { filterViewContext, serializeState } from \"./state.js\";\n\ndescribe(\"state helpers\", () => {\n describe(\"filterViewContext\", () => {\n it(\"should return null when state is null\", () => {\n expect(filterViewContext(null)).toBe(null);\n });\n\n it(\"should return null when state is undefined\", () => {\n expect(filterViewContext(undefined)).toBe(null);\n });\n\n it(\"should correctly filter VIEW_CONTEXT_KEY and preserve other properties\", () => {\n const stateWithContextAndOthers = {\n a: 1,\n b: \"two\",\n c: { nested: true },\n [VIEW_CONTEXT_KEY]: \"context\",\n };\n const filteredWithContextAndOthers = filterViewContext(\n stateWithContextAndOthers,\n );\n expect(filteredWithContextAndOthers).toEqual({\n a: 1,\n b: \"two\",\n c: { nested: true },\n });\n\n const stateNoContext = { count: 5, name: \"test\" };\n const filteredNoContext = filterViewContext(stateNoContext);\n expect(filteredNoContext).toEqual(stateNoContext);\n });\n });\n\n describe(\"serializeState\", () => {\n it(\"should serialize plain objects\", () => {\n const array = [1, \"two\", { three: 3 }];\n const date = new Date(\"2023-01-01T00:00:00Z\");\n const object = {\n a: 1,\n b: \"test\",\n c: true,\n array,\n date,\n function: () => \"test\",\n };\n const result = serializeState(object);\n\n expect(result).toEqual({\n a: 1,\n b: \"test\",\n c: true,\n array: [1, \"two\", { three: 3 }],\n date: new Date(\"2023-01-01T00:00:00.000Z\"),\n });\n });\n });\n});\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { type DownloadFn, useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
5
|
export { type LayoutState, useLayout } from "./use-layout.js";
|
|
5
|
-
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
|
|
6
8
|
export { useRequestModal } from "./use-request-modal.js";
|
|
9
|
+
export { type RequestSizeFn, useRequestSize } from "./use-request-size.js";
|
|
7
10
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
11
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
12
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
13
|
export { type UserState, useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
14
|
+
export { useViewState } from "./use-view-state.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export { useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
5
|
export { useLayout } from "./use-layout.js";
|
|
5
6
|
export { useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { useRequestClose } from "./use-request-close.js";
|
|
6
8
|
export { useRequestModal } from "./use-request-modal.js";
|
|
9
|
+
export { useRequestSize } from "./use-request-size.js";
|
|
7
10
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
11
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
12
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
13
|
export { useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
14
|
+
export { useViewState } from "./use-view-state.js";
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type LayoutState, useLayout } from \"./use-layout.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
1
|
+
import type { McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
2
|
export declare class MockResizeObserver {
|
|
3
3
|
observe(): void;
|
|
4
4
|
unobserve(): void;
|
|
5
5
|
disconnect(): void;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type McpAppHostMockOptions = {
|
|
8
|
+
hostCapabilities?: McpUiHostCapabilities;
|
|
9
|
+
downloadFileResult?: McpUiDownloadFileResult;
|
|
10
|
+
};
|
|
11
|
+
export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext, options?: McpAppHostMockOptions) => import("vitest").Mock<(message: {
|
|
8
12
|
method: string;
|
|
9
13
|
id: number;
|
|
10
14
|
}) => void>;
|
|
@@ -7,16 +7,17 @@ export class MockResizeObserver {
|
|
|
7
7
|
disconnect() { }
|
|
8
8
|
}
|
|
9
9
|
const DEFAULT_CONTEXT = {};
|
|
10
|
-
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
|
|
10
|
+
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT, options = {}) => vi.fn((message) => {
|
|
11
11
|
switch (message.method) {
|
|
12
12
|
case "ui/initialize": {
|
|
13
13
|
const result = {
|
|
14
14
|
protocolVersion: "2025-06-18",
|
|
15
15
|
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
16
|
-
hostCapabilities: {},
|
|
16
|
+
hostCapabilities: options.hostCapabilities ?? {},
|
|
17
17
|
hostContext: initialContext,
|
|
18
18
|
};
|
|
19
19
|
act(() => fireEvent(window, new MessageEvent("message", {
|
|
20
|
+
source: window.parent,
|
|
20
21
|
data: {
|
|
21
22
|
jsonrpc: "2.0",
|
|
22
23
|
id: message.id,
|
|
@@ -27,6 +28,7 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
27
28
|
}
|
|
28
29
|
case "ui/update-model-context": {
|
|
29
30
|
act(() => fireEvent(window, new MessageEvent("message", {
|
|
31
|
+
source: window.parent,
|
|
30
32
|
data: {
|
|
31
33
|
jsonrpc: "2.0",
|
|
32
34
|
id: message.id,
|
|
@@ -35,10 +37,22 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
35
37
|
})));
|
|
36
38
|
break;
|
|
37
39
|
}
|
|
40
|
+
case "ui/download-file": {
|
|
41
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
42
|
+
source: window.parent,
|
|
43
|
+
data: {
|
|
44
|
+
jsonrpc: "2.0",
|
|
45
|
+
id: message.id,
|
|
46
|
+
result: options.downloadFileResult ?? {},
|
|
47
|
+
},
|
|
48
|
+
})));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
38
51
|
}
|
|
39
52
|
});
|
|
40
53
|
export const fireToolInputNotification = (args) => {
|
|
41
54
|
fireEvent(window, new MessageEvent("message", {
|
|
55
|
+
source: window.parent,
|
|
42
56
|
data: {
|
|
43
57
|
jsonrpc: "2.0",
|
|
44
58
|
method: "ui/notifications/tool-input",
|
|
@@ -50,6 +64,7 @@ export const fireToolInputNotification = (args) => {
|
|
|
50
64
|
};
|
|
51
65
|
export const fireToolResultNotification = (params) => {
|
|
52
66
|
fireEvent(window, new MessageEvent("message", {
|
|
67
|
+
source: window.parent,
|
|
53
68
|
data: {
|
|
54
69
|
jsonrpc: "2.0",
|
|
55
70
|
method: "ui/notifications/tool-result",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EA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oBACd,MAAM,EAAE,EAAE;iBACX;aACF,CACF,CACF,CACF,CAAC;YACF,MAAM;QACR,CAAC;QACD,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CAIb,SAAS,EAAE;gBACZ,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,MAAM,EAAE,OAAO,CAAC,kBAAkB,IAAI,EAAE;iBACzC;aACF,CAAC,CACH,CACF,CAAC;YACF,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,IAA6B,EAAE,EAAE;IACzE,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,6BAA6B;YACrC,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n McpUiDownloadFileResult,\n McpUiHostCapabilities,\n McpUiHostContext,\n McpUiInitializeResult,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport { fireEvent } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { vi } from \"vitest\";\n\nexport class MockResizeObserver {\n observe(): void {}\n unobserve(): void {}\n disconnect(): void {}\n}\n\nconst DEFAULT_CONTEXT: McpUiHostContext = {};\n\nexport type McpAppHostMockOptions = {\n hostCapabilities?: McpUiHostCapabilities;\n downloadFileResult?: McpUiDownloadFileResult;\n};\n\nexport const getMcpAppHostPostMessageMock = (\n initialContext: McpUiHostContext = DEFAULT_CONTEXT,\n options: McpAppHostMockOptions = {},\n) =>\n vi.fn((message: { method: string; id: number }) => {\n switch (message.method) {\n case \"ui/initialize\": {\n const result: McpUiInitializeResult = {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: options.hostCapabilities ?? {},\n hostContext: initialContext,\n };\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiInitializeResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result,\n },\n }),\n ),\n );\n break;\n }\n case \"ui/update-model-context\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{ jsonrpc: \"2.0\"; id: number; result: unknown }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {},\n },\n },\n ),\n ),\n );\n break;\n }\n case \"ui/download-file\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiDownloadFileResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: options.downloadFileResult ?? {},\n },\n }),\n ),\n );\n break;\n }\n }\n });\n\nexport const fireToolInputNotification = (args: Record<string, unknown>) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolInputNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: {\n arguments: args,\n },\n },\n },\n ),\n );\n};\n\nexport const fireToolResultNotification = (params: {\n content: McpUiToolResultNotification[\"params\"][\"content\"];\n structuredContent: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n}) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolResultNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params,\n },\n },\n ),\n );\n};\n"]}
|
|
@@ -36,13 +36,26 @@ type CallToolErrorState = {
|
|
|
36
36
|
data: undefined;
|
|
37
37
|
error: unknown;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* State of a {@link useCallTool} invocation, discriminated by `status`.
|
|
41
|
+
* Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.
|
|
42
|
+
*/
|
|
39
43
|
export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
|
|
44
|
+
/**
|
|
45
|
+
* Optional callbacks fired around a {@link useCallTool} call.
|
|
46
|
+
* `onSettled` runs after success or error.
|
|
47
|
+
*/
|
|
40
48
|
export type SideEffects<ToolArgs, ToolResponse> = {
|
|
41
49
|
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
42
50
|
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
43
51
|
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
44
52
|
};
|
|
45
53
|
type IsArgsOptional<T> = [T] extends [null] ? true : HasRequiredKeys<T> extends false ? true : false;
|
|
54
|
+
/**
|
|
55
|
+
* Fire-and-forget call function returned by {@link useCallTool}. Tracks state
|
|
56
|
+
* on the hook and supports optional {@link SideEffects} callbacks. Args are
|
|
57
|
+
* optional when the tool accepts none.
|
|
58
|
+
*/
|
|
46
59
|
export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
47
60
|
(): void;
|
|
48
61
|
(sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
@@ -52,11 +65,43 @@ export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ?
|
|
|
52
65
|
(args: TArgs): void;
|
|
53
66
|
(args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
54
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Promise-returning call function returned by {@link useCallTool}. Rejects
|
|
70
|
+
* if the tool errors; use `try/catch` for error handling.
|
|
71
|
+
*/
|
|
55
72
|
export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
56
73
|
(): Promise<TResponse>;
|
|
57
74
|
(args: TArgs): Promise<TResponse>;
|
|
58
75
|
} : (args: TArgs) => Promise<TResponse>;
|
|
59
76
|
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
|
|
77
|
+
/**
|
|
78
|
+
* Call a server tool from a view and track its execution state.
|
|
79
|
+
*
|
|
80
|
+
* Returns the current {@link CallToolState} plus two callers: `callTool`
|
|
81
|
+
* (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
|
|
82
|
+
* (promise-returning). If the same instance is invoked again while a call is
|
|
83
|
+
* in flight, the older response is dropped from the rendered state (but any
|
|
84
|
+
* `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
|
|
85
|
+
*
|
|
86
|
+
* Pair with {@link useToolInfo} to read the result of the tool invocation
|
|
87
|
+
* that produced the current view. For end-to-end type safety across tool
|
|
88
|
+
* inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
|
|
89
|
+
* over calling this hook directly.
|
|
90
|
+
*
|
|
91
|
+
* @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
|
|
92
|
+
* @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
|
|
97
|
+
*
|
|
98
|
+
* <button onClick={() => callTool({ query: "skybridge" }, {
|
|
99
|
+
* onSuccess: (res) => console.log(res.structuredContent),
|
|
100
|
+
* })} />
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @see https://docs.skybridge.tech/api-reference/use-call-tool
|
|
104
|
+
*/
|
|
60
105
|
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
|
|
61
106
|
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
62
107
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
2
|
import { getAdaptor, } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Call a server tool from a view and track its execution state.
|
|
5
|
+
*
|
|
6
|
+
* Returns the current {@link CallToolState} plus two callers: `callTool`
|
|
7
|
+
* (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
|
|
8
|
+
* (promise-returning). If the same instance is invoked again while a call is
|
|
9
|
+
* in flight, the older response is dropped from the rendered state (but any
|
|
10
|
+
* `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
|
|
11
|
+
*
|
|
12
|
+
* Pair with {@link useToolInfo} to read the result of the tool invocation
|
|
13
|
+
* that produced the current view. For end-to-end type safety across tool
|
|
14
|
+
* inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
|
|
15
|
+
* over calling this hook directly.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
|
|
18
|
+
* @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
|
|
23
|
+
*
|
|
24
|
+
* <button onClick={() => callTool({ query: "skybridge" }, {
|
|
25
|
+
* onSuccess: (res) => console.log(res.structuredContent),
|
|
26
|
+
* })} />
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see https://docs.skybridge.tech/api-reference/use-call-tool
|
|
30
|
+
*/
|
|
3
31
|
export const useCallTool = (name) => {
|
|
4
32
|
const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
|
|
5
33
|
const callIdRef = useRef(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAK1D,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,MAAM,OAAO,GAAG,KAAK,EACnB,QAAkB,EACiB,EAAE;QACrC,MAAM,MAAM,GAAG,EAAE,SA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QACzB,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAa,CAAC;QACpE,CAAC;QAED,OAAO,CAAC,QAAQ,CAAC;aACd,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACzC,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,WAAW,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACxC,WAAW,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAmD,CAAC;IAErD,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useRef, useState } from \"react\";\n\nimport {\n type CallToolArgs,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\n/**\n * State of a {@link useCallTool} invocation, discriminated by `status`.\n * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.\n */\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\n/**\n * Optional callbacks fired around a {@link useCallTool} call.\n * `onSettled` runs after success or error.\n */\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\n/**\n * Fire-and-forget call function returned by {@link useCallTool}. Tracks state\n * on the hook and supports optional {@link SideEffects} callbacks. Args are\n * optional when the tool accepts none.\n */\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\n/**\n * Promise-returning call function returned by {@link useCallTool}. Rejects\n * if the tool errors; use `try/catch` for error handling.\n */\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\n/**\n * Call a server tool from a view and track its execution state.\n *\n * Returns the current {@link CallToolState} plus two callers: `callTool`\n * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`\n * (promise-returning). If the same instance is invoked again while a call is\n * in flight, the older response is dropped from the rendered state (but any\n * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).\n *\n * Pair with {@link useToolInfo} to read the result of the tool invocation\n * that produced the current view. For end-to-end type safety across tool\n * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}\n * over calling this hook directly.\n *\n * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).\n * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.\n *\n * @example\n * ```tsx\n * const { callTool, isPending, data } = useCallTool<{ query: string }>(\"search\");\n *\n * <button onClick={() => callTool({ query: \"skybridge\" }, {\n * onSuccess: (res) => console.log(res.structuredContent),\n * })} />\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-call-tool\n */\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n\n const execute = async (\n toolArgs: ToolArgs,\n ): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({ status: \"pending\", data: undefined, error: undefined });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n };\n\n const callToolAsync = ((toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n }) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = ((\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n }) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,EAGL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,IAAI,CAAC,2DAA2D,EAAE,GAAG,EAAE;IACrE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE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C;QACrB,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAa,CAAC;QACvD,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;IAChE,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAW,CAAC;IACvD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;IAI/D,MAAM,KAAK,GAAY,EAAa,CAAC;IAErC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC/B,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9D,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;IAI7D,MAAM,WAAW,GAAgC;QAC/C,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;YACpD,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QACpC,CAAC;KACF,CAAC;IAEF,YAAY,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport {\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\n\ntest(\"callTool can be called without args when ToolArgs is null\", () => {\n const { callTool, callToolAsync } = useCallTool<null>(\"test-tool\");\n callTool();\n callTool({ onSuccess: () => {} });\n callToolAsync();\n});\n\ntest(\"callTool requires args when ToolArgs has required properties\", () => {\n type Args = { query: string };\n const { callTool, callToolAsync } = useCallTool<Args>(\"test-tool\");\n\n // @ts-expect-error - query is required\n callTool();\n\n callTool({ query: \"test\" });\n callTool({ query: \"test\" }, { onSuccess: () => {} });\n\n // @ts-expect-error - query is required\n callToolAsync();\n callToolAsync({ query: \"test\" });\n});\n\ntest(\"callTool supports sideEffects with correct types\", () => {\n type Args = { id: number };\n type Response = { structuredContent: { result: string } };\n\n const { callTool } = useCallTool<Args, Response>(\"test-tool\");\n\n callTool(\n { id: 1 },\n {\n onSuccess: (data, args) => {\n expectTypeOf(data.structuredContent.result).toBeString();\n expectTypeOf(args.id).toBeNumber();\n },\n onError: (error, args) => {\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.id).toBeNumber();\n },\n onSettled: (data, error, args) => {\n if (data) {\n expectTypeOf(data.structuredContent.result).toBeString();\n }\n expectTypeOf(error).toEqualTypeOf<unknown | undefined>();\n expectTypeOf(args.id).toBeNumber();\n },\n },\n );\n});\n\ntest(\"callTool allows sideEffects as first arg when ToolArgs is null\", () => {\n type Response = { structuredContent: { value: number } };\n const { callTool } = useCallTool<null, Response>(\"test-tool\");\n\n callTool({\n onSuccess: (data) => {\n expectTypeOf(data.structuredContent.value).toBeNumber();\n },\n });\n});\n\ntest(\"callToolAsync returns correctly typed promise\", () => {\n type Args = { name: string };\n type Response = {\n structuredContent: { greeting: string };\n meta: { id: number };\n };\n\n const { callToolAsync } = useCallTool<Args, Response>(\"test-tool\");\n\n const promise = callToolAsync({ name: \"test\" });\n\n expectTypeOf(promise).resolves.toHaveProperty(\"structuredContent\");\n expectTypeOf(promise).resolves.toHaveProperty(\"meta\");\n});\n\ntest(\"state narrowing works correctly with status\", () => {\n type Response = { structuredContent: { data: string } };\n const result = useCallTool<null, Response>(\"test-tool\");\n\n if (result.status === \"idle\") {\n expectTypeOf(result.isIdle).toEqualTypeOf<true>();\n expectTypeOf(result.data).toEqualTypeOf<undefined>();\n }\n\n if (result.status === \"pending\") {\n expectTypeOf(result.isPending).toEqualTypeOf<true>();\n expectTypeOf(result.data).toEqualTypeOf<undefined>();\n }\n\n if (result.status === \"success\") {\n expectTypeOf(result.isSuccess).toEqualTypeOf<true>();\n expectTypeOf(result.data).not.toEqualTypeOf<undefined>();\n expectTypeOf(result.data.structuredContent.data).toBeString();\n }\n\n if (result.status === \"error\") {\n expectTypeOf(result.isError).toEqualTypeOf<true>();\n expectTypeOf(result.error).toBeUnknown();\n }\n});\n\ntest(\"state narrowing works correctly with boolean flags\", () => {\n type Response = { structuredContent: { items: string[] } };\n const result = useCallTool<null, Response>(\"test-tool\");\n\n if (result.isIdle) {\n expectTypeOf(result.status).toEqualTypeOf<\"idle\">();\n }\n\n if (result.isPending) {\n expectTypeOf(result.status).toEqualTypeOf<\"pending\">();\n }\n\n if (result.isSuccess) {\n expectTypeOf(result.status).toEqualTypeOf<\"success\">();\n expectTypeOf(result.data.structuredContent.items).toBeArray();\n }\n\n if (result.isError) {\n expectTypeOf(result.status).toEqualTypeOf<\"error\">();\n }\n});\n\ntest(\"CallToolState type is correctly exported and usable\", () => {\n type Response = { structuredContent: { foo: string } };\n type MyState = CallToolState<CallToolResponse & Response>;\n\n const state: MyState = {} as MyState;\n\n if (state.status === \"success\") {\n expectTypeOf(state.data.structuredContent.foo).toBeString();\n }\n});\n\ntest(\"SideEffects type is correctly exported and usable\", () => {\n type Args = { x: number };\n type Response = CallToolResponse & { structuredContent: { y: string } };\n\n const sideEffects: SideEffects<Args, Response> = {\n onSuccess: (data, args) => {\n expectTypeOf(data.structuredContent.y).toBeString();\n expectTypeOf(args.x).toBeNumber();\n },\n };\n\n expectTypeOf(sideEffects).toHaveProperty(\"onSuccess\");\n});\n"]}
|
|
@@ -20,9 +20,27 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
20
20
|
content: [{ type: "text", text: "test result" }],
|
|
21
21
|
structuredContent: { result: "test" },
|
|
22
22
|
isError: false,
|
|
23
|
-
|
|
23
|
+
meta: {},
|
|
24
24
|
};
|
|
25
25
|
const error = new Error("test error");
|
|
26
|
+
it("should normalize _meta to meta when SDK returns _meta instead of meta", async () => {
|
|
27
|
+
const rawSdkResponse = {
|
|
28
|
+
content: [{ type: "text", text: "result" }],
|
|
29
|
+
structuredContent: { value: 1 },
|
|
30
|
+
isError: false,
|
|
31
|
+
_meta: { secret: "only visible to widget" },
|
|
32
|
+
};
|
|
33
|
+
OpenaiMock.callTool.mockResolvedValueOnce(rawSdkResponse);
|
|
34
|
+
const { result } = renderHook(() => useCallTool(toolName));
|
|
35
|
+
await act(async () => {
|
|
36
|
+
result.current.callTool(args);
|
|
37
|
+
});
|
|
38
|
+
await waitFor(() => {
|
|
39
|
+
expect(result.current.data).toMatchObject({
|
|
40
|
+
meta: { secret: "only visible to widget" },
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
26
44
|
it("should call window.openai.callTool with correct arguments", async () => {
|
|
27
45
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
28
46
|
await act(async () => {
|
|
@@ -102,8 +120,14 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
102
120
|
});
|
|
103
121
|
it("should always return last call started state", async () => {
|
|
104
122
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
105
|
-
const firstCallData = {
|
|
106
|
-
|
|
123
|
+
const firstCallData = {
|
|
124
|
+
...data,
|
|
125
|
+
structuredContent: { result: "first call result" },
|
|
126
|
+
};
|
|
127
|
+
const secondCallData = {
|
|
128
|
+
...data,
|
|
129
|
+
structuredContent: { result: "second call result" },
|
|
130
|
+
};
|
|
107
131
|
const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } = Promise.withResolvers();
|
|
108
132
|
const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } = Promise.withResolvers();
|
|
109
133
|
OpenaiMock.callTool
|
|
@@ -143,7 +167,6 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
143
167
|
content: [{ type: "text", text: "test" }],
|
|
144
168
|
structuredContent: { result: "test" },
|
|
145
169
|
isError: false,
|
|
146
|
-
result: "test",
|
|
147
170
|
meta: { id: 123 },
|
|
148
171
|
};
|
|
149
172
|
OpenaiMock.callTool.mockResolvedValueOnce(data);
|
|
@@ -160,7 +183,6 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
160
183
|
content: [{ type: "text", text: "answer" }],
|
|
161
184
|
structuredContent: { answer: "test answer" },
|
|
162
185
|
isError: false,
|
|
163
|
-
result: "answer",
|
|
164
186
|
meta: {},
|
|
165
187
|
};
|
|
166
188
|
OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
|
|
@@ -176,7 +198,6 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
176
198
|
content: [{ type: "text", text: "data" }],
|
|
177
199
|
structuredContent: { data: "test data" },
|
|
178
200
|
isError: false,
|
|
179
|
-
result: "data",
|
|
180
201
|
meta: {},
|
|
181
202
|
};
|
|
182
203
|
OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
|
|
@@ -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,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE;SAClB,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CA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ACzC,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,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,4 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { RequestDisplayMode } from "../bridges/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
|
|
4
|
+
*
|
|
5
|
+
* Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
|
|
6
|
+
* host to switch modes — the host returns the mode it actually applied, which
|
|
7
|
+
* may differ from the request. The reported value also updates when the host
|
|
8
|
+
* changes the mode on its own (e.g. user expands the widget).
|
|
9
|
+
*
|
|
10
|
+
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
11
|
+
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
12
|
+
* pair with {@link useLayout}.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const [mode, setMode] = useDisplayMode();
|
|
17
|
+
* <button onClick={() => setMode("fullscreen")}>Expand</button>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see https://docs.skybridge.tech/api-reference/use-display-mode
|
|
21
|
+
*/
|
|
22
|
+
export declare function useDisplayMode(): readonly [import("../index.js").DisplayMode, (mode: RequestDisplayMode) => Promise<{
|
|
23
|
+
mode: RequestDisplayMode;
|
|
4
24
|
}>];
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor, useHostContext } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
|
|
5
|
+
*
|
|
6
|
+
* Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
|
|
7
|
+
* host to switch modes — the host returns the mode it actually applied, which
|
|
8
|
+
* may differ from the request. The reported value also updates when the host
|
|
9
|
+
* changes the mode on its own (e.g. user expands the widget).
|
|
10
|
+
*
|
|
11
|
+
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
12
|
+
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
13
|
+
* pair with {@link useLayout}.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const [mode, setMode] = useDisplayMode();
|
|
18
|
+
* <button onClick={() => setMode("fullscreen")}>Expand</button>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @see https://docs.skybridge.tech/api-reference/use-display-mode
|
|
22
|
+
*/
|
|
3
23
|
export function useDisplayMode() {
|
|
4
24
|
const displayMode = useHostContext("displayMode");
|
|
5
25
|
const adaptor = getAdaptor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,
|
|
1
|
+
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useLayout}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
test("setDisplayMode only accepts requestable display modes", () => {
|
|
3
|
+
expectTypeOf().toEqualTypeOf();
|
|
4
|
+
// @ts-expect-error "modal" is a host state, not a valid request mode
|
|
5
|
+
const _invalidMode = "modal";
|
|
6
|
+
void _invalidMode;
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=use-display-mode.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI5C,IAAI,CAAC,uDAAuD,EAAE,GAAG,EAAE;IAGjE,YAAY,EAET,CAAC,aAAa,EAAsB,CAAC;IAExC,qEAAqE;IACrE,MAAM,YAAY,GAAkC,OAAO,CAAC;IAC5D,KAAK,YAAY,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\nimport type { useDisplayMode } from \"./use-display-mode.js\";\n\ntest(\"setDisplayMode only accepts requestable display modes\", () => {\n type SetDisplayMode = ReturnType<typeof useDisplayMode>[1];\n\n expectTypeOf<\n Parameters<SetDisplayMode>[0]\n >().toEqualTypeOf<RequestDisplayMode>();\n\n // @ts-expect-error \"modal\" is a host state, not a valid request mode\n const _invalidMode: Parameters<SetDisplayMode>[0] = \"modal\";\n void _invalidMode;\n});\n"]}
|
|
@@ -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,MAA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,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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
export function useDownload() {
|
|
4
|
+
const adaptor = getAdaptor();
|
|
5
|
+
const download = useCallback((params) => adaptor.download(params), [adaptor]);
|
|
6
|
+
return { download };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-download.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EACpC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { DownloadParams, DownloadResult } from \"../bridges/types.js\";\n\nexport type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;\n\nexport function useDownload(): { download: DownloadFn } {\n const adaptor = getAdaptor();\n const download = useCallback<DownloadFn>(\n (params) => adaptor.download(params),\n [adaptor],\n );\n\n return { download };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|