skybridge 0.0.0-dev.fff2bae → 0.0.0-next.1ec1c19
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 +132 -124
- package/dist/cli/build-helpers.d.ts +7 -0
- package/dist/cli/build-helpers.js +82 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +64 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +18 -30
- 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.js +16 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +16 -1
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +32 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +18 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +18 -0
- package/dist/server/auth/providers/auth0.js +31 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +16 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +24 -0
- package/dist/server/auth/providers/custom.js +37 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +107 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +33 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +37 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- 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/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.test.js +61 -0
- 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 +11 -2
- package/dist/server/index.js +9 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +221 -6
- package/dist/server/server.js +301 -159
- package/dist/server/server.js.map +1 -1
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +103 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/test/view.test.js +109 -96
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +310 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +197 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -1
- package/dist/web/bridges/apps-sdk/bridge.js +15 -3
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +2 -0
- 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 +9 -7
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +68 -4
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +104 -1
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- 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 +4 -3
- 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 +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +33 -0
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +9 -5
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/hooks/index.d.ts +4 -0
- package/dist/web/hooks/index.js +4 -0
- 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 +13 -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.js +62 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +20 -0
- 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.js +56 -20
- 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 +103 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -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 +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- 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 +47 -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 +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- 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 +47 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
- package/dist/web/hooks/use-send-follow-up-message.js +17 -0
- 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 +28 -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 +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -32
- 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 +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +6 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +33 -0
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +10 -3
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -24
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -96
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -48
- package/dist/web/bridges/mcp-app/adaptor.js +0 -263
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor, } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Send a follow-up message to the LLM on behalf of the view, as if the user
|
|
5
|
+
* had sent it. Use to chain interactions from view UI (e.g. a button that
|
|
6
|
+
* triggers the next assistant turn).
|
|
7
|
+
*
|
|
8
|
+
* Pass `scrollToBottom: false` to keep the chat scroll position when the host
|
|
9
|
+
* posts the message. This option is Apps-SDK-only; it is silently ignored in
|
|
10
|
+
* the MCP Apps runtime.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const send = useSendFollowUpMessage();
|
|
15
|
+
* <button onClick={() => send("Summarize the last 5 results")}>Summarize</button>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message
|
|
19
|
+
*/
|
|
3
20
|
export function useSendFollowUpMessage() {
|
|
4
21
|
const adaptor = getAdaptor();
|
|
5
22
|
const sendFollowUpMessage = useCallback((prompt, options) => adaptor.sendFollowUpMessage(prompt, options), [adaptor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAE7B,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,MAAc,EAAE,OAAoC,EAAE,EAAE,CACvD,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type SendFollowUpMessageOptions,\n} from \"../bridges/index.js\";\n\nexport function useSendFollowUpMessage() {\n const adaptor = getAdaptor();\n const sendFollowUpMessage = useCallback(\n (prompt: string, options?: SendFollowUpMessageOptions) =>\n adaptor.sendFollowUpMessage(prompt, options),\n [adaptor],\n );\n\n return sendFollowUpMessage;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,MAAc,EAAE,OAAoC,EAAE,EAAE,CACvD,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type SendFollowUpMessageOptions,\n} from \"../bridges/index.js\";\n\n/**\n * Send a follow-up message to the LLM on behalf of the view, as if the user\n * had sent it. Use to chain interactions from view UI (e.g. a button that\n * triggers the next assistant turn).\n *\n * Pass `scrollToBottom: false` to keep the chat scroll position when the host\n * posts the message. This option is Apps-SDK-only; it is silently ignored in\n * the MCP Apps runtime.\n *\n * @example\n * ```tsx\n * const send = useSendFollowUpMessage();\n * <button onClick={() => send(\"Summarize the last 5 results\")}>Summarize</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message\n */\nexport function useSendFollowUpMessage() {\n const adaptor = getAdaptor();\n const sendFollowUpMessage = useCallback(\n (prompt: string, options?: SendFollowUpMessageOptions) =>\n adaptor.sendFollowUpMessage(prompt, options),\n [adaptor],\n );\n\n return sendFollowUpMessage;\n}\n"]}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Override the target URL the host opens from its fullscreen "Open in <App>"
|
|
3
|
+
* affordance. If unset, the host opens the view's current iframe path.
|
|
4
|
+
*
|
|
5
|
+
* Currently Apps-SDK-only — calling this from MCP Apps throws.
|
|
6
|
+
*
|
|
7
|
+
* Call this once your view has enough context to construct the canonical URL
|
|
8
|
+
* (e.g. a permalink to the entity the user is currently viewing).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const setOpenInAppUrl = useSetOpenInAppUrl();
|
|
13
|
+
* useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url
|
|
17
|
+
*/
|
|
1
18
|
export declare function useSetOpenInAppUrl(): (href: string) => Promise<void>;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Override the target URL the host opens from its fullscreen "Open in <App>"
|
|
5
|
+
* affordance. If unset, the host opens the view's current iframe path.
|
|
6
|
+
*
|
|
7
|
+
* Currently Apps-SDK-only — calling this from MCP Apps throws.
|
|
8
|
+
*
|
|
9
|
+
* Call this once your view has enough context to construct the canonical URL
|
|
10
|
+
* (e.g. a permalink to the entity the user is currently viewing).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const setOpenInAppUrl = useSetOpenInAppUrl();
|
|
15
|
+
* useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url
|
|
19
|
+
*/
|
|
3
20
|
export function useSetOpenInAppUrl() {
|
|
4
21
|
const adaptor = getAdaptor();
|
|
5
22
|
const setOpenInAppUrl = useCallback((href) => adaptor.setOpenInAppUrl(href), [adaptor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-set-open-in-app-url.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,WAAW,CACjC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAC/C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\nexport function useSetOpenInAppUrl() {\n const adaptor = getAdaptor();\n const setOpenInAppUrl = useCallback(\n (href: string) => adaptor.setOpenInAppUrl(href),\n [adaptor],\n );\n\n return setOpenInAppUrl;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-set-open-in-app-url.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,WAAW,CACjC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAC/C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\n/**\n * Override the target URL the host opens from its fullscreen \"Open in <App>\"\n * affordance. If unset, the host opens the view's current iframe path.\n *\n * Currently Apps-SDK-only — calling this from MCP Apps throws.\n *\n * Call this once your view has enough context to construct the canonical URL\n * (e.g. a permalink to the entity the user is currently viewing).\n *\n * @example\n * ```tsx\n * const setOpenInAppUrl = useSetOpenInAppUrl();\n * useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url\n */\nexport function useSetOpenInAppUrl() {\n const adaptor = getAdaptor();\n const setOpenInAppUrl = useCallback(\n (href: string) => adaptor.setOpenInAppUrl(href),\n [adaptor],\n );\n\n return setOpenInAppUrl;\n}\n"]}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
|
|
5
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
6
|
+
import { NotSupportedError } from "../bridges/types.js";
|
|
4
7
|
import { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
5
8
|
describe("useSetOpenInAppUrl", () => {
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals();
|
|
11
|
+
vi.resetAllMocks();
|
|
12
|
+
HostAdaptor.resetInstance();
|
|
13
|
+
AppsSdkBridge.resetInstance();
|
|
14
|
+
McpAppBridge.resetInstance();
|
|
15
|
+
});
|
|
6
16
|
describe("apps-sdk host", () => {
|
|
7
17
|
let setOpenInAppUrlMock;
|
|
8
18
|
beforeEach(() => {
|
|
@@ -14,11 +24,7 @@ describe("useSetOpenInAppUrl", () => {
|
|
|
14
24
|
hostType: "apps-sdk",
|
|
15
25
|
serverUrl: "https://example.com",
|
|
16
26
|
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
vi.unstubAllGlobals();
|
|
20
|
-
vi.resetAllMocks();
|
|
21
|
-
AppsSdkAdaptor.resetInstance();
|
|
27
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
22
28
|
});
|
|
23
29
|
it("should return a function that calls window.openai.setOpenInAppUrl with the href", async () => {
|
|
24
30
|
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
@@ -27,9 +33,9 @@ describe("useSetOpenInAppUrl", () => {
|
|
|
27
33
|
expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
|
|
28
34
|
expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
|
|
29
35
|
});
|
|
30
|
-
it("should
|
|
36
|
+
it("should reject when href is empty", async () => {
|
|
31
37
|
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
32
|
-
expect(
|
|
38
|
+
await expect(result.current("")).rejects.toThrow("The href parameter is required.");
|
|
33
39
|
});
|
|
34
40
|
it("should call setOpenInAppUrl when href origin differs from serverUrl origin", async () => {
|
|
35
41
|
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
@@ -39,5 +45,19 @@ describe("useSetOpenInAppUrl", () => {
|
|
|
39
45
|
expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
|
|
40
46
|
});
|
|
41
47
|
});
|
|
48
|
+
describe("mcp-app host", () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
vi.stubGlobal("openai", undefined);
|
|
51
|
+
vi.stubGlobal("skybridge", {
|
|
52
|
+
hostType: "mcp-app",
|
|
53
|
+
serverUrl: "https://example.com",
|
|
54
|
+
});
|
|
55
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
56
|
+
});
|
|
57
|
+
it("should throw NotSupportedError when called from an MCP App runtime", async () => {
|
|
58
|
+
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
59
|
+
await expect(result.current("https://example.com/path")).rejects.toBeInstanceOf(NotSupportedError);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
42
62
|
});
|
|
43
63
|
//# sourceMappingURL=use-set-open-in-app-url.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-set-open-in-app-url.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use-set-open-in-app-url.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,E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AClF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC;YAE1D,MAAM,MAAM,CACV,MAAM,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAC3C,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { NotSupportedError } from \"../bridges/types.js\";\nimport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\n\ndescribe(\"useSetOpenInAppUrl\", () => {\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n AppsSdkBridge.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n describe(\"apps-sdk host\", () => {\n let setOpenInAppUrlMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n setOpenInAppUrlMock = vi.fn().mockResolvedValue(undefined);\n vi.stubGlobal(\"openai\", {\n setOpenInAppUrl: setOpenInAppUrlMock,\n });\n vi.stubGlobal(\"skybridge\", {\n hostType: \"apps-sdk\",\n serverUrl: \"https://example.com\",\n });\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n it(\"should return a function that calls window.openai.setOpenInAppUrl with the href\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://example.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n\n it(\"should reject when href is empty\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n await expect(result.current(\"\")).rejects.toThrow(\n \"The href parameter is required.\",\n );\n });\n\n it(\"should call setOpenInAppUrl when href origin differs from serverUrl origin\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://different-domain.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {\n hostType: \"mcp-app\",\n serverUrl: \"https://example.com\",\n });\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n it(\"should throw NotSupportedError when called from an MCP App runtime\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n await expect(\n result.current(\"https://example.com/path\"),\n ).rejects.toBeInstanceOf(NotSupportedError);\n });\n });\n});\n"]}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { UnknownObject } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* {@link useToolInfo} state before the tool has been invoked.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated `useToolInfo` no longer returns the idle state — it starts in
|
|
6
|
+
* `"pending"` and transitions to `"success"`, so `isIdle` is always `false` at
|
|
7
|
+
* runtime. This type is retained in {@link ToolState} for backwards
|
|
8
|
+
* compatibility and will be removed in the next major.
|
|
9
|
+
*/
|
|
2
10
|
export type ToolIdleState = {
|
|
3
11
|
status: "idle";
|
|
4
12
|
isIdle: true;
|
|
@@ -8,29 +16,72 @@ export type ToolIdleState = {
|
|
|
8
16
|
output: undefined;
|
|
9
17
|
responseMetadata: undefined;
|
|
10
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* {@link useToolInfo} state while the tool is executing — `output` is not yet
|
|
21
|
+
* available.
|
|
22
|
+
*
|
|
23
|
+
* `input` is optional: the host may render the view before delivering the
|
|
24
|
+
* tool arguments.
|
|
25
|
+
*/
|
|
11
26
|
export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
12
27
|
status: "pending";
|
|
13
28
|
isIdle: false;
|
|
14
29
|
isPending: true;
|
|
15
30
|
isSuccess: false;
|
|
16
|
-
input: ToolInput;
|
|
31
|
+
input: ToolInput | undefined;
|
|
17
32
|
output: undefined;
|
|
18
33
|
responseMetadata: undefined;
|
|
19
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* {@link useToolInfo} state once the tool returned — `output` is available.
|
|
37
|
+
*
|
|
38
|
+
* `input` is optional: the host may not have surfaced the tool arguments by
|
|
39
|
+
* the time `output` arrives.
|
|
40
|
+
*/
|
|
20
41
|
export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
21
42
|
status: "success";
|
|
22
43
|
isIdle: false;
|
|
23
44
|
isPending: false;
|
|
24
45
|
isSuccess: true;
|
|
25
|
-
input: ToolInput;
|
|
46
|
+
input: ToolInput | undefined;
|
|
26
47
|
output: ToolOutput;
|
|
27
48
|
responseMetadata: ToolResponseMetadata;
|
|
28
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Discriminated union describing the tool invocation that triggered the
|
|
52
|
+
* current view render. Use `isPending` / `isSuccess` to narrow.
|
|
53
|
+
*/
|
|
29
54
|
export type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolIdleState | ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
30
55
|
type ToolSignature = {
|
|
31
56
|
input: UnknownObject;
|
|
32
57
|
output: UnknownObject;
|
|
33
58
|
responseMetadata: UnknownObject;
|
|
34
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Access the tool invocation that produced the current view: its `input`,
|
|
62
|
+
* resulting `output`, and `responseMetadata`. The shape evolves as the tool
|
|
63
|
+
* runs (pending → success), exposed through {@link ToolState}.
|
|
64
|
+
*
|
|
65
|
+
* For full input/output typing per tool name, prefer the typed `useToolInfo`
|
|
66
|
+
* returned by {@link generateHelpers} over the generic form.
|
|
67
|
+
*
|
|
68
|
+
* @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
|
|
69
|
+
* to refine each field's type. When omitted, each typed field resolves to
|
|
70
|
+
* `never` — pass an explicit shape or use the typed helper from
|
|
71
|
+
* {@link generateHelpers} to get usable types.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* const { isSuccess, input, output } = useToolInfo<{
|
|
76
|
+
* input: { query: string };
|
|
77
|
+
* output: { results: Result[] };
|
|
78
|
+
* }>();
|
|
79
|
+
*
|
|
80
|
+
* if (!isSuccess || !output) return <Skeleton />;
|
|
81
|
+
* return <Results items={output.results} />;
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see https://docs.skybridge.tech/api-reference/use-tool-info
|
|
85
|
+
*/
|
|
35
86
|
export declare function useToolInfo<TS extends Partial<ToolSignature> = Record<string, never>>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
|
|
36
87
|
export {};
|
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
import { useHostContext } from "../bridges/index.js";
|
|
2
|
-
function deriveStatus(
|
|
3
|
-
if (input === null) {
|
|
4
|
-
return "idle";
|
|
5
|
-
}
|
|
2
|
+
function deriveStatus(output, responseMetadata) {
|
|
6
3
|
if (output === null && responseMetadata === null) {
|
|
7
4
|
return "pending";
|
|
8
5
|
}
|
|
9
6
|
return "success";
|
|
10
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Access the tool invocation that produced the current view: its `input`,
|
|
10
|
+
* resulting `output`, and `responseMetadata`. The shape evolves as the tool
|
|
11
|
+
* runs (pending → success), exposed through {@link ToolState}.
|
|
12
|
+
*
|
|
13
|
+
* For full input/output typing per tool name, prefer the typed `useToolInfo`
|
|
14
|
+
* returned by {@link generateHelpers} over the generic form.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
|
|
17
|
+
* to refine each field's type. When omitted, each typed field resolves to
|
|
18
|
+
* `never` — pass an explicit shape or use the typed helper from
|
|
19
|
+
* {@link generateHelpers} to get usable types.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { isSuccess, input, output } = useToolInfo<{
|
|
24
|
+
* input: { query: string };
|
|
25
|
+
* output: { results: Result[] };
|
|
26
|
+
* }>();
|
|
27
|
+
*
|
|
28
|
+
* if (!isSuccess || !output) return <Skeleton />;
|
|
29
|
+
* return <Results items={output.results} />;
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see https://docs.skybridge.tech/api-reference/use-tool-info
|
|
33
|
+
*/
|
|
11
34
|
export function useToolInfo() {
|
|
12
35
|
const input = useHostContext("toolInput");
|
|
13
36
|
const output = useHostContext("toolOutput");
|
|
14
37
|
const responseMetadata = useHostContext("toolResponseMetadata");
|
|
15
|
-
const status = deriveStatus(
|
|
38
|
+
const status = deriveStatus(output, responseMetadata);
|
|
16
39
|
return {
|
|
17
|
-
input,
|
|
40
|
+
input: input ?? undefined,
|
|
18
41
|
status,
|
|
19
|
-
isIdle:
|
|
42
|
+
isIdle: false,
|
|
20
43
|
isPending: status === "pending",
|
|
21
44
|
isSuccess: status === "success",
|
|
22
45
|
output,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA6ErD,SAAS,YAAY,CACnB,MAAsC,EACtC,gBAAgD;IAEhD,IAAI,MAAM,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,WAAW;IAGzB,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAEhE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAMtD,OAAO;QACL,KAAK,EAAE,KAAK,IAAI,SAAS;QACzB,MAAM;QACN,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,MAAM;QACN,gBAAgB;KACqB,CAAC;AAC1C,CAAC","sourcesContent":["import { useHostContext } from \"../bridges/index.js\";\nimport type { UnknownObject } from \"../types.js\";\n\n/**\n * {@link useToolInfo} state before the tool has been invoked.\n *\n * @deprecated `useToolInfo` no longer returns the idle state — it starts in\n * `\"pending\"` and transitions to `\"success\"`, so `isIdle` is always `false` at\n * runtime. This type is retained in {@link ToolState} for backwards\n * compatibility and will be removed in the next major.\n */\nexport type ToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n input: undefined;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/**\n * {@link useToolInfo} state while the tool is executing — `output` is not yet\n * available.\n *\n * `input` is optional: the host may render the view before delivering the\n * tool arguments.\n */\nexport type ToolPendingState<ToolInput extends UnknownObject> = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n input: ToolInput | undefined;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/**\n * {@link useToolInfo} state once the tool returned — `output` is available.\n *\n * `input` is optional: the host may not have surfaced the tool arguments by\n * the time `output` arrives.\n */\nexport type ToolSuccessState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n input: ToolInput | undefined;\n output: ToolOutput;\n responseMetadata: ToolResponseMetadata;\n};\n\n/**\n * Discriminated union describing the tool invocation that triggered the\n * current view render. Use `isPending` / `isSuccess` to narrow.\n */\nexport type ToolState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> =\n | ToolIdleState\n | ToolPendingState<ToolInput>\n | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;\n\ntype ToolSignature = {\n input: UnknownObject;\n output: UnknownObject;\n responseMetadata: UnknownObject;\n};\n\nfunction deriveStatus(\n output: Record<string, unknown> | null,\n responseMetadata: Record<string, unknown> | null,\n): \"pending\" | \"success\" {\n if (output === null && responseMetadata === null) {\n return \"pending\";\n }\n return \"success\";\n}\n\n/**\n * Access the tool invocation that produced the current view: its `input`,\n * resulting `output`, and `responseMetadata`. The shape evolves as the tool\n * runs (pending → success), exposed through {@link ToolState}.\n *\n * For full input/output typing per tool name, prefer the typed `useToolInfo`\n * returned by {@link generateHelpers} over the generic form.\n *\n * @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`\n * to refine each field's type. When omitted, each typed field resolves to\n * `never` — pass an explicit shape or use the typed helper from\n * {@link generateHelpers} to get usable types.\n *\n * @example\n * ```tsx\n * const { isSuccess, input, output } = useToolInfo<{\n * input: { query: string };\n * output: { results: Result[] };\n * }>();\n *\n * if (!isSuccess || !output) return <Skeleton />;\n * return <Results items={output.results} />;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-tool-info\n */\nexport function useToolInfo<\n TS extends Partial<ToolSignature> = Record<string, never>,\n>() {\n const input = useHostContext(\"toolInput\");\n const output = useHostContext(\"toolOutput\");\n const responseMetadata = useHostContext(\"toolResponseMetadata\");\n\n const status = deriveStatus(output, responseMetadata);\n\n type Input = UnknownObject & TS[\"input\"];\n type Output = UnknownObject & TS[\"output\"];\n type Metadata = UnknownObject & TS[\"responseMetadata\"];\n\n return {\n input: input ?? undefined,\n status,\n isIdle: false,\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n output,\n responseMetadata,\n } as ToolState<Input, Output, Metadata>;\n}\n"]}
|
|
@@ -11,19 +11,15 @@ test("useToolInfo - TypeScript typing", () => {
|
|
|
11
11
|
});
|
|
12
12
|
test("should correctly type input, output, and responseMetadata with explicit ToolSignature", () => {
|
|
13
13
|
const result = useToolInfo();
|
|
14
|
-
// When
|
|
15
|
-
|
|
16
|
-
expectTypeOf(result.input);
|
|
17
|
-
expectTypeOf(result.output);
|
|
18
|
-
expectTypeOf(result.responseMetadata);
|
|
19
|
-
}
|
|
20
|
-
// When pending, output and responseMetadata should be undefined
|
|
14
|
+
// When pending, input may be undefined (host hasn't delivered args yet,
|
|
15
|
+
// or the tool has no input schema)
|
|
21
16
|
if (result.status === "pending") {
|
|
22
17
|
expectTypeOf(result.input);
|
|
23
18
|
expectTypeOf(result.output);
|
|
24
19
|
expectTypeOf(result.responseMetadata);
|
|
25
20
|
}
|
|
26
|
-
// When success, output and responseMetadata
|
|
21
|
+
// When success, output and responseMetadata are defined; input may still
|
|
22
|
+
// be undefined if the host hasn't surfaced the tool arguments
|
|
27
23
|
if (result.status === "success") {
|
|
28
24
|
expectTypeOf(result.input);
|
|
29
25
|
expectTypeOf(result.output);
|
|
@@ -32,34 +28,18 @@ test("useToolInfo - TypeScript typing", () => {
|
|
|
32
28
|
});
|
|
33
29
|
test("should correctly narrow types based on status discriminated union", () => {
|
|
34
30
|
const result = useToolInfo();
|
|
35
|
-
// Test type narrowing for idle
|
|
36
|
-
if (result.isIdle) {
|
|
37
|
-
expectTypeOf(result.status);
|
|
38
|
-
expectTypeOf(result.isIdle);
|
|
39
|
-
expectTypeOf(result.isPending);
|
|
40
|
-
expectTypeOf(result.isSuccess);
|
|
41
|
-
expectTypeOf(result.input);
|
|
42
|
-
expectTypeOf(result.output);
|
|
43
|
-
expectTypeOf(result.responseMetadata);
|
|
44
|
-
}
|
|
45
31
|
// Test type narrowing for pending
|
|
46
32
|
if (result.isPending) {
|
|
47
33
|
expectTypeOf(result.status);
|
|
48
34
|
expectTypeOf(result.isIdle);
|
|
49
35
|
expectTypeOf(result.isPending);
|
|
50
36
|
expectTypeOf(result.isSuccess);
|
|
37
|
+
expectTypeOf(result.input);
|
|
51
38
|
expectTypeOf(result.output);
|
|
52
39
|
expectTypeOf(result.responseMetadata);
|
|
53
40
|
}
|
|
54
41
|
if (result.isSuccess) {
|
|
55
42
|
expectTypeOf(result.status);
|
|
56
|
-
expectTypeOf(result.isIdle);
|
|
57
|
-
expectTypeOf(result.isPending);
|
|
58
|
-
expectTypeOf(result.isSuccess);
|
|
59
|
-
expectTypeOf(result.output);
|
|
60
|
-
expectTypeOf(result.responseMetadata);
|
|
61
|
-
}
|
|
62
|
-
if (result.status === "idle") {
|
|
63
43
|
expectTypeOf(result.isIdle);
|
|
64
44
|
expectTypeOf(result.isPending);
|
|
65
45
|
expectTypeOf(result.isSuccess);
|
|
@@ -86,22 +66,24 @@ test("useToolInfo - TypeScript typing", () => {
|
|
|
86
66
|
});
|
|
87
67
|
test("should handle partial ToolSignature with only input specified", () => {
|
|
88
68
|
const result = useToolInfo();
|
|
89
|
-
// Input
|
|
90
|
-
|
|
69
|
+
// Input is optional in both states — undefined while args haven't arrived
|
|
70
|
+
// (pending) and for no-input tools (success).
|
|
71
|
+
if (result.status === "pending") {
|
|
91
72
|
expectTypeOf(result.input);
|
|
92
73
|
}
|
|
93
74
|
if (result.status === "success") {
|
|
75
|
+
expectTypeOf(result.input);
|
|
94
76
|
expectTypeOf(result.output);
|
|
95
77
|
expectTypeOf(result.responseMetadata);
|
|
96
78
|
}
|
|
97
79
|
});
|
|
98
80
|
test("should handle ToolSignature with only output specified", () => {
|
|
99
81
|
const result = useToolInfo();
|
|
100
|
-
|
|
101
|
-
if (result.status === "pending" || result.status === "success") {
|
|
82
|
+
if (result.status === "pending") {
|
|
102
83
|
expectTypeOf(result.input);
|
|
103
84
|
}
|
|
104
85
|
if (result.status === "success") {
|
|
86
|
+
expectTypeOf(result.input);
|
|
105
87
|
expectTypeOf(result.output);
|
|
106
88
|
}
|
|
107
89
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,IAAI,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAC3E,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAE7B,YAAY,CAAiC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5D,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAAU,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uFAAuF,EAAE,GAAG,EAAE;QAKjG,MAAM,MAAM,GAAG,WAAW,EAItB,CAAC;QAEL,
|
|
1
|
+
{"version":3,"file":"use-tool-info.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,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,CAAC,CAAC;YACtC,YAAY,CAAO,MAAM,CAAC,SAAS,CAAC,CAAC;YACrC,YAAY,CAAa,MAAM,CAAC,MAAM,CAAC,CAAC;YACxC,YAAY,CAAe,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,+DAA+D,EAAE,GAAG,EAAE;QAGzE,MAAM,MAAM,GAAG,WAAW,EAEtB,CAAC;QAEL,0EAA0E;QAC1E,8CAA8C;QAC9C,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAwB,MAAM,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAwB,MAAM,CAAC,KAAK,CAAC,CAAC;YAClD,YAAY,CAA0B,MAAM,CAAC,MAAM,CAAC,CAAC;YACrD,YAAY,CAA0B,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAGlE,MAAM,MAAM,GAAG,WAAW,EAEtB,CAAC;QAEL,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,YAAY,CAAa,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ntest(\"useToolInfo - TypeScript typing\", () => {\n test(\"should have correct types when no generic parameter is provided\", () => {\n const result = useToolInfo();\n\n expectTypeOf<\"idle\" | \"pending\" | \"success\">(result.status);\n expectTypeOf<boolean>(result.isPending);\n expectTypeOf<boolean>(result.isSuccess);\n expectTypeOf<boolean>(result.isIdle);\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n });\n\n test(\"should correctly type input, output, and responseMetadata with explicit ToolSignature\", () => {\n type TestInput = { name: string; args: { name: string } };\n type TestOutput = { name: string; color: string };\n type TestMetadata = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // When pending, input may be undefined (host hasn't delivered args yet,\n // or the tool has no input schema)\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When success, output and responseMetadata are defined; input may still\n // be undefined if the host hasn't surfaced the tool arguments\n if (result.status === \"success\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should correctly narrow types based on status discriminated union\", () => {\n type TestInput = { query: string };\n type TestOutput = { result: string };\n type TestMetadata = { timestamp: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // Test type narrowing for pending\n if (result.isPending) {\n expectTypeOf<\"pending\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.isSuccess) {\n expectTypeOf<\"success\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should handle partial ToolSignature with only input specified\", () => {\n type TestInput = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n }>();\n\n // Input is optional in both states — undefined while args haven't arrived\n // (pending) and for no-input tools (success).\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<Record<string, unknown>>(result.output);\n expectTypeOf<Record<string, unknown>>(result.responseMetadata);\n }\n });\n\n test(\"should handle ToolSignature with only output specified\", () => {\n type TestOutput = { data: string[] };\n\n const result = useToolInfo<{\n output: TestOutput;\n }>();\n\n if (result.status === \"pending\") {\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n expectTypeOf<TestOutput>(result.output);\n }\n });\n});\n"]}
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import { act,
|
|
1
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "../bridges/mcp-app/index.js";
|
|
5
5
|
import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
6
|
import { useToolInfo } from "./use-tool-info.js";
|
|
7
7
|
describe("useToolInfo", () => {
|
|
8
8
|
describe("apps-sdk host", () => {
|
|
9
|
-
let OpenaiMock;
|
|
10
9
|
beforeEach(() => {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
11
|
+
vi.stubGlobal("openai", {
|
|
12
|
+
toolInput: null,
|
|
13
13
|
toolOutput: null,
|
|
14
14
|
toolResponseMetadata: null,
|
|
15
|
-
};
|
|
16
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
15
|
+
});
|
|
17
16
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
17
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
18
18
|
});
|
|
19
19
|
afterEach(() => {
|
|
20
|
+
HostAdaptor.resetInstance();
|
|
20
21
|
vi.unstubAllGlobals();
|
|
21
22
|
vi.resetAllMocks();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
22
24
|
});
|
|
23
|
-
it("should return
|
|
25
|
+
it("should return pending state with tool input from tool-input notification", async () => {
|
|
24
26
|
const { result } = renderHook(() => useToolInfo());
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
act(() => {
|
|
28
|
+
fireToolInputNotification({
|
|
29
|
+
name: "pokemon",
|
|
30
|
+
args: { name: "pikachu" },
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
await waitFor(() => {
|
|
34
|
+
expect(result.current).toMatchObject({
|
|
35
|
+
input: { name: "pokemon", args: { name: "pikachu" } },
|
|
36
|
+
status: "pending",
|
|
37
|
+
isIdle: false,
|
|
38
|
+
isPending: true,
|
|
39
|
+
isSuccess: false,
|
|
40
|
+
});
|
|
31
41
|
});
|
|
32
42
|
});
|
|
33
|
-
it("should
|
|
43
|
+
it("should return success state once tool-result notification arrives", async () => {
|
|
34
44
|
const toolOutput = {
|
|
35
45
|
name: "pikachu",
|
|
36
46
|
color: "yellow",
|
|
@@ -39,16 +49,15 @@ describe("useToolInfo", () => {
|
|
|
39
49
|
const toolResponseMetadata = { id: 12 };
|
|
40
50
|
const { result } = renderHook(() => useToolInfo());
|
|
41
51
|
act(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}));
|
|
52
|
+
fireToolInputNotification({
|
|
53
|
+
name: "pokemon",
|
|
54
|
+
args: { name: "pikachu" },
|
|
55
|
+
});
|
|
56
|
+
fireToolResultNotification({
|
|
57
|
+
content: [{ type: "text", text: JSON.stringify(toolOutput) }],
|
|
58
|
+
structuredContent: toolOutput,
|
|
59
|
+
_meta: toolResponseMetadata,
|
|
60
|
+
});
|
|
52
61
|
});
|
|
53
62
|
await waitFor(() => {
|
|
54
63
|
expect(result.current).toMatchObject({
|
|
@@ -66,23 +75,24 @@ describe("useToolInfo", () => {
|
|
|
66
75
|
beforeEach(() => {
|
|
67
76
|
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
68
77
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
78
|
+
vi.stubGlobal("openai", undefined);
|
|
69
79
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
70
80
|
});
|
|
71
81
|
afterEach(async () => {
|
|
82
|
+
HostAdaptor.resetInstance();
|
|
72
83
|
vi.unstubAllGlobals();
|
|
73
84
|
vi.resetAllMocks();
|
|
74
85
|
McpAppBridge.resetInstance();
|
|
75
|
-
McpAppAdaptor.resetInstance();
|
|
76
86
|
});
|
|
77
|
-
it("should return
|
|
87
|
+
it("should return pending state with undefined input before tool-input notification arrives", async () => {
|
|
78
88
|
const { result } = renderHook(() => useToolInfo());
|
|
79
89
|
await waitFor(() => {
|
|
80
90
|
expect(result.current).toMatchObject({
|
|
81
|
-
status: "
|
|
82
|
-
isIdle:
|
|
83
|
-
isPending:
|
|
91
|
+
status: "pending",
|
|
92
|
+
isIdle: false,
|
|
93
|
+
isPending: true,
|
|
84
94
|
isSuccess: false,
|
|
85
|
-
input:
|
|
95
|
+
input: undefined,
|
|
86
96
|
output: null,
|
|
87
97
|
responseMetadata: null,
|
|
88
98
|
});
|