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,6 +1,21 @@
|
|
|
1
1
|
import { type RequestModalOptions } from "../bridges/index.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Open the current view in a modal overlay (`displayMode === "modal"`).
|
|
4
|
+
*
|
|
5
|
+
* Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render
|
|
6
|
+
* the view in a modal, optionally passing `params` that are surfaced back via
|
|
7
|
+
* `params` here. Useful for confirmation flows, detail panels, or any modal
|
|
8
|
+
* lifecycle owned by the host.
|
|
9
|
+
*
|
|
10
|
+
* Use {@link useDisplayMode} for non-modal display modes.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { isOpen, open } = useRequestModal();
|
|
15
|
+
* <button onClick={() => open({ params: { id: 42 } })}>Show details</button>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-modal
|
|
4
19
|
*/
|
|
5
20
|
export declare function useRequestModal(): {
|
|
6
21
|
isOpen: boolean;
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor, useHostContext, } from "../bridges/index.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Open the current view in a modal overlay (`displayMode === "modal"`).
|
|
5
|
+
*
|
|
6
|
+
* Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render
|
|
7
|
+
* the view in a modal, optionally passing `params` that are surfaced back via
|
|
8
|
+
* `params` here. Useful for confirmation flows, detail panels, or any modal
|
|
9
|
+
* lifecycle owned by the host.
|
|
10
|
+
*
|
|
11
|
+
* Use {@link useDisplayMode} for non-modal display modes.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const { isOpen, open } = useRequestModal();
|
|
16
|
+
* <button onClick={() => open({ params: { id: 42 } })}>Show details</button>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-modal
|
|
5
20
|
*/
|
|
6
21
|
export function useRequestModal() {
|
|
7
22
|
const adaptor = getAdaptor();
|
|
8
|
-
const
|
|
23
|
+
const display = useHostContext("display");
|
|
9
24
|
const open = useCallback((opts) => adaptor.openModal(opts), [adaptor]);
|
|
10
25
|
return {
|
|
11
|
-
isOpen:
|
|
12
|
-
params:
|
|
26
|
+
isOpen: display.mode === "modal",
|
|
27
|
+
params: display.params,
|
|
13
28
|
open,
|
|
14
29
|
};
|
|
15
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,EAEV,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,EAEV,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,WAAW,CACtB,CAAC,IAAyB,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EACtD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,OAAO;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type RequestModalOptions,\n useHostContext,\n} from \"../bridges/index.js\";\n\n/**\n * Open the current view in a modal overlay (`displayMode === \"modal\"`).\n *\n * Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render\n * the view in a modal, optionally passing `params` that are surfaced back via\n * `params` here. Useful for confirmation flows, detail panels, or any modal\n * lifecycle owned by the host.\n *\n * Use {@link useDisplayMode} for non-modal display modes.\n *\n * @example\n * ```tsx\n * const { isOpen, open } = useRequestModal();\n * <button onClick={() => open({ params: { id: 42 } })}>Show details</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-modal\n */\nexport function useRequestModal() {\n const adaptor = getAdaptor();\n const display = useHostContext(\"display\");\n const open = useCallback(\n (opts: RequestModalOptions) => adaptor.openModal(opts),\n [adaptor],\n );\n return {\n isOpen: display.mode === \"modal\",\n params: display.params,\n open,\n };\n}\n"]}
|
|
@@ -48,7 +48,11 @@ describe("useRequestModal", () => {
|
|
|
48
48
|
it("should call window.openai.requestModal with the options when open is called", () => {
|
|
49
49
|
const { result } = renderHook(() => useRequestModal());
|
|
50
50
|
const { open } = result.current;
|
|
51
|
-
const options = {
|
|
51
|
+
const options = {
|
|
52
|
+
title: "Test Modal",
|
|
53
|
+
params: { foo: "bar" },
|
|
54
|
+
template: "ui://view/modal-template.html",
|
|
55
|
+
};
|
|
52
56
|
open(options);
|
|
53
57
|
expect(requestModalMock).toHaveBeenCalledTimes(1);
|
|
54
58
|
expect(requestModalMock).toHaveBeenCalledWith(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.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,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,WAA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AAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QACvD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QAEhC,MAAM,OAAO,GAAG;YACd,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;YACtB,QAAQ,EAAE,+BAA+B;SAC1C,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,CAAC;QAEd,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { useRequestModal } from \"./use-request-modal.js\";\n\ndescribe(\"useRequestModal\", () => {\n let requestModalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n requestModalMock = vi.fn();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"inline\" },\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal\", () => {\n const { result } = renderHook(() => useRequestModal());\n\n expect(typeof result.current).toBe(\"object\");\n expect(result.current).toHaveProperty(\"open\");\n expect(result.current).toHaveProperty(\"isOpen\");\n expect(result.current).toHaveProperty(\"params\");\n\n const { open, isOpen, params } = result.current;\n expect(typeof open).toBe(\"function\");\n expect(isOpen).toBe(false);\n expect(params).toBeUndefined();\n });\n\n it(\"should return isOpen as true when mode is modal\", () => {\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\" },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { isOpen } = result.current;\n\n expect(isOpen).toBe(true);\n });\n\n it(\"should return params from view when available\", () => {\n const testParams = { foo: \"bar\", baz: 42 };\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\", params: testParams },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { params } = result.current;\n\n expect(params).toEqual(testParams);\n });\n\n it(\"should call window.openai.requestModal with the options when open is called\", () => {\n const { result } = renderHook(() => useRequestModal());\n const { open } = result.current;\n\n const options = {\n title: \"Test Modal\",\n params: { foo: \"bar\" },\n template: \"ui://view/modal-template.html\",\n };\n open(options);\n\n expect(requestModalMock).toHaveBeenCalledTimes(1);\n expect(requestModalMock).toHaveBeenCalledWith(options);\n });\n});\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequestSizeOptions } from "../bridges/types.js";
|
|
2
|
+
/** Function that asks the host to resize the view, returned by {@link useRequestSize}. */
|
|
3
|
+
export type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Ask the host to resize the view iframe. The applied size is host-driven —
|
|
6
|
+
* the host decides whether and how to honor the request, and {@link useLayout}
|
|
7
|
+
* still reports the final `maxHeight` it allows.
|
|
8
|
+
*
|
|
9
|
+
* Pair with a `ResizeObserver` on your root element to react to content size
|
|
10
|
+
* changes without hard-coded values.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const requestSize = useRequestSize();
|
|
15
|
+
* useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-size
|
|
19
|
+
*/
|
|
20
|
+
export declare function useRequestSize(): RequestSizeFn;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ask the host to resize the view iframe. The applied size is host-driven —
|
|
5
|
+
* the host decides whether and how to honor the request, and {@link useLayout}
|
|
6
|
+
* still reports the final `maxHeight` it allows.
|
|
7
|
+
*
|
|
8
|
+
* Pair with a `ResizeObserver` on your root element to react to content size
|
|
9
|
+
* changes without hard-coded values.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const requestSize = useRequestSize();
|
|
14
|
+
* useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-size
|
|
18
|
+
*/
|
|
19
|
+
export function useRequestSize() {
|
|
20
|
+
const adaptor = getAdaptor();
|
|
21
|
+
const requestSize = useCallback((size) => adaptor.requestSize(size), [adaptor]);
|
|
22
|
+
return requestSize;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=use-request-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-size.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EACvD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { RequestSizeOptions } from \"../bridges/types.js\";\n\n/** Function that asks the host to resize the view, returned by {@link useRequestSize}. */\nexport type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;\n\n/**\n * Ask the host to resize the view iframe. The applied size is host-driven —\n * the host decides whether and how to honor the request, and {@link useLayout}\n * still reports the final `maxHeight` it allows.\n *\n * Pair with a `ResizeObserver` on your root element to react to content size\n * changes without hard-coded values.\n *\n * @example\n * ```tsx\n * const requestSize = useRequestSize();\n * useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-size\n */\nexport function useRequestSize(): RequestSizeFn {\n const adaptor = getAdaptor();\n const requestSize = useCallback(\n (size: RequestSizeOptions) => adaptor.requestSize(size),\n [adaptor],\n );\n\n return requestSize;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { AppsSdkAdaptor } from "../bridges/apps-sdk/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
+
import { useRequestSize } from "./use-request-size.js";
|
|
7
|
+
describe("useRequestSize", () => {
|
|
8
|
+
describe("apps-sdk host", () => {
|
|
9
|
+
let consoleWarnSpy;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
AppsSdkAdaptor.resetInstance();
|
|
12
|
+
vi.stubGlobal("openai", {});
|
|
13
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
14
|
+
consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
AppsSdkAdaptor.resetInstance();
|
|
18
|
+
vi.unstubAllGlobals();
|
|
19
|
+
vi.resetAllMocks();
|
|
20
|
+
});
|
|
21
|
+
it("warns that requestSize is not supported on Apps SDK", async () => {
|
|
22
|
+
const { result } = renderHook(() => useRequestSize());
|
|
23
|
+
await result.current({ height: 400 });
|
|
24
|
+
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(consoleWarnSpy.mock.calls[0]?.[0]).toContain("not supported");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("mcp-app host", () => {
|
|
29
|
+
let postMessageMock;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
32
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
33
|
+
postMessageMock = getMcpAppHostPostMessageMock();
|
|
34
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
35
|
+
});
|
|
36
|
+
afterEach(async () => {
|
|
37
|
+
vi.unstubAllGlobals();
|
|
38
|
+
vi.resetAllMocks();
|
|
39
|
+
McpAppBridge.resetInstance();
|
|
40
|
+
});
|
|
41
|
+
it("sends a ui/notifications/size-changed notification with width and height", async () => {
|
|
42
|
+
const { result } = renderHook(() => useRequestSize());
|
|
43
|
+
await result.current({ width: 800, height: 400 });
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
46
|
+
jsonrpc: "2.0",
|
|
47
|
+
method: "ui/notifications/size-changed",
|
|
48
|
+
params: { width: 800, height: 400 },
|
|
49
|
+
}), "*");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("forwards height-only payloads as-is", async () => {
|
|
53
|
+
const { result } = renderHook(() => useRequestSize());
|
|
54
|
+
await result.current({ height: 400 });
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
57
|
+
jsonrpc: "2.0",
|
|
58
|
+
method: "ui/notifications/size-changed",
|
|
59
|
+
params: { height: 400 },
|
|
60
|
+
}), "*");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=use-request-size.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-size.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,cAA2C,CAAC;QAEhD,UAAU,CAAC,GAAG,EAAE;YACd,cAAc,CAAC,aAAa,EAAE,CAAC;YAC/B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC5B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;YACrD,cAAc,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,cAAc,CAAC,aAAa,EAAE,CAAC;YAC/B,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,C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C,OAAO,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAElD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,+BAA+B;oBACvC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;iBACpC,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;YACnD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;YAEtD,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAEtC,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,+BAA+B;oBACvC,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;iBACxB,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useRequestSize } from \"./use-request-size.js\";\n\ndescribe(\"useRequestSize\", () => {\n describe(\"apps-sdk host\", () => {\n let consoleWarnSpy: ReturnType<typeof vi.spyOn>;\n\n beforeEach(() => {\n AppsSdkAdaptor.resetInstance();\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n consoleWarnSpy = vi.spyOn(console, \"warn\").mockImplementation(() => {});\n });\n\n afterEach(() => {\n AppsSdkAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"warns that requestSize is not supported on Apps SDK\", async () => {\n const { result } = renderHook(() => useRequestSize());\n\n await result.current({ height: 400 });\n\n expect(consoleWarnSpy).toHaveBeenCalledTimes(1);\n expect(consoleWarnSpy.mock.calls[0]?.[0]).toContain(\"not supported\");\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends a ui/notifications/size-changed notification with width and height\", async () => {\n const { result } = renderHook(() => useRequestSize());\n\n await result.current({ width: 800, height: 400 });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/size-changed\",\n params: { width: 800, height: 400 },\n }),\n \"*\",\n );\n });\n });\n\n it(\"forwards height-only payloads as-is\", async () => {\n const { result } = renderHook(() => useRequestSize());\n\n await result.current({ height: 400 });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/size-changed\",\n params: { height: 400 },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { type SendFollowUpMessageOptions } from "../bridges/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Send a follow-up message to the LLM on behalf of the view, as if the user
|
|
4
|
+
* had sent it. Use to chain interactions from view UI (e.g. a button that
|
|
5
|
+
* triggers the next assistant turn).
|
|
6
|
+
*
|
|
7
|
+
* Pass `scrollToBottom: false` to keep the chat scroll position when the host
|
|
8
|
+
* posts the message. This option is Apps-SDK-only; it is silently ignored in
|
|
9
|
+
* the MCP Apps runtime.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const send = useSendFollowUpMessage();
|
|
14
|
+
* <button onClick={() => send("Summarize the last 5 results")}>Summarize</button>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message
|
|
18
|
+
*/
|
|
19
|
+
export declare function useSendFollowUpMessage(): (prompt: string, options?: SendFollowUpMessageOptions) => Promise<void>;
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
-
import { getAdaptor } from "../bridges/index.js";
|
|
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
|
-
const sendFollowUpMessage = useCallback((prompt) => adaptor.sendFollowUpMessage(prompt), [adaptor]);
|
|
22
|
+
const sendFollowUpMessage = useCallback((prompt, options) => adaptor.sendFollowUpMessage(prompt, options), [adaptor]);
|
|
6
23
|
return sendFollowUpMessage;
|
|
7
24
|
}
|
|
8
25
|
//# sourceMappingURL=use-send-follow-up-message.js.map
|
|
@@ -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,
|
|
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"}
|
|
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"]}
|
|
@@ -31,18 +31,12 @@ describe("useSetOpenInAppUrl", () => {
|
|
|
31
31
|
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
32
32
|
expect(() => result.current("")).toThrow("The href parameter is required.");
|
|
33
33
|
});
|
|
34
|
-
it("should
|
|
35
|
-
vi.stubGlobal("skybridge", {
|
|
36
|
-
hostType: "apps-sdk",
|
|
37
|
-
serverUrl: undefined,
|
|
38
|
-
});
|
|
39
|
-
AppsSdkAdaptor.resetInstance();
|
|
34
|
+
it("should call setOpenInAppUrl when href origin differs from serverUrl origin", async () => {
|
|
40
35
|
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(() => result.current("https://different-domain.com/path")).toThrow("Provided href is not compatible with widget domain: origin differs");
|
|
36
|
+
const href = "https://different-domain.com/path";
|
|
37
|
+
await result.current(href);
|
|
38
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
|
|
46
40
|
});
|
|
47
41
|
});
|
|
48
42
|
});
|
|
@@ -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,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,mBAA6C,CAAC;QAElD,UAAU,CAAC,GAAG,EAAE;YACd,mBAAmB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC3D,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,eAAe,EAAE,mBAAmB;aACrC,CAAC,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE;gBACzB,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,qBAAqB;aACjC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;YACnB,cAAc,CAAC,aAAa,EAAE,CAAC;QACjC,CAAC,CAAC,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C1F,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC;YAE1D,MAAM,IAAI,GAAG,mCAAmC,CAAC;YACjD,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAE3B,MAAM,CAAC,mBAAmB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YACrD,MAAM,CAAC,mBAAmB,CAAC,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7D,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 { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\n\ndescribe(\"useSetOpenInAppUrl\", () => {\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 });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n AppsSdkAdaptor.resetInstance();\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 throw an error when href is empty\", () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n expect(() => result.current(\"\")).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"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { UnknownObject } from "../types.js";
|
|
2
|
+
/** {@link useToolInfo} state before the tool has been invoked. */
|
|
2
3
|
export type ToolIdleState = {
|
|
3
4
|
status: "idle";
|
|
4
5
|
isIdle: true;
|
|
@@ -8,6 +9,7 @@ export type ToolIdleState = {
|
|
|
8
9
|
output: undefined;
|
|
9
10
|
responseMetadata: undefined;
|
|
10
11
|
};
|
|
12
|
+
/** {@link useToolInfo} state while the tool is executing — `input` is available, output is not yet. */
|
|
11
13
|
export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
12
14
|
status: "pending";
|
|
13
15
|
isIdle: false;
|
|
@@ -17,6 +19,7 @@ export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
|
17
19
|
output: undefined;
|
|
18
20
|
responseMetadata: undefined;
|
|
19
21
|
};
|
|
22
|
+
/** {@link useToolInfo} state once the tool returned — `input`, `output`, and `responseMetadata` are all available. */
|
|
20
23
|
export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
21
24
|
status: "success";
|
|
22
25
|
isIdle: false;
|
|
@@ -26,11 +29,41 @@ export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends
|
|
|
26
29
|
output: ToolOutput;
|
|
27
30
|
responseMetadata: ToolResponseMetadata;
|
|
28
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Discriminated union describing the tool invocation that triggered the
|
|
34
|
+
* current view render. Use `isIdle` / `isPending` / `isSuccess` to narrow.
|
|
35
|
+
*/
|
|
29
36
|
export type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolIdleState | ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
30
37
|
type ToolSignature = {
|
|
31
38
|
input: UnknownObject;
|
|
32
39
|
output: UnknownObject;
|
|
33
40
|
responseMetadata: UnknownObject;
|
|
34
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Access the tool invocation that produced the current view: its `input`,
|
|
44
|
+
* resulting `output`, and `responseMetadata`. The shape evolves as the tool
|
|
45
|
+
* runs (idle → pending → success), exposed through {@link ToolState}.
|
|
46
|
+
*
|
|
47
|
+
* For full input/output typing per tool name, prefer the typed `useToolInfo`
|
|
48
|
+
* returned by {@link generateHelpers} over the generic form.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
|
|
51
|
+
* to refine each field's type. When omitted, each typed field resolves to
|
|
52
|
+
* `never` — pass an explicit shape or use the typed helper from
|
|
53
|
+
* {@link generateHelpers} to get usable types.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const { isSuccess, input, output } = useToolInfo<{
|
|
58
|
+
* input: { query: string };
|
|
59
|
+
* output: { results: Result[] };
|
|
60
|
+
* }>();
|
|
61
|
+
*
|
|
62
|
+
* if (!isSuccess || !output) return <Skeleton />;
|
|
63
|
+
* return <Results items={output.results} />;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see https://docs.skybridge.tech/api-reference/use-tool-info
|
|
67
|
+
*/
|
|
35
68
|
export declare function useToolInfo<TS extends Partial<ToolSignature> = Record<string, never>>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
|
|
36
69
|
export {};
|
|
@@ -8,6 +8,32 @@ function deriveStatus(input, output, responseMetadata) {
|
|
|
8
8
|
}
|
|
9
9
|
return "success";
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Access the tool invocation that produced the current view: its `input`,
|
|
13
|
+
* resulting `output`, and `responseMetadata`. The shape evolves as the tool
|
|
14
|
+
* runs (idle → pending → success), exposed through {@link ToolState}.
|
|
15
|
+
*
|
|
16
|
+
* For full input/output typing per tool name, prefer the typed `useToolInfo`
|
|
17
|
+
* returned by {@link generateHelpers} over the generic form.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
|
|
20
|
+
* to refine each field's type. When omitted, each typed field resolves to
|
|
21
|
+
* `never` — pass an explicit shape or use the typed helper from
|
|
22
|
+
* {@link generateHelpers} to get usable types.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const { isSuccess, input, output } = useToolInfo<{
|
|
27
|
+
* input: { query: string };
|
|
28
|
+
* output: { results: Result[] };
|
|
29
|
+
* }>();
|
|
30
|
+
*
|
|
31
|
+
* if (!isSuccess || !output) return <Skeleton />;
|
|
32
|
+
* return <Results items={output.results} />;
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see https://docs.skybridge.tech/api-reference/use-tool-info
|
|
36
|
+
*/
|
|
11
37
|
export function useToolInfo() {
|
|
12
38
|
const input = useHostContext("toolInput");
|
|
13
39
|
const output = useHostContext("toolOutput");
|
|
@@ -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;AA2DrD,SAAS,YAAY,CACnB,KAAqC,EACrC,MAAsC,EACtC,gBAAgD;IAEhD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,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,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAM7D,OAAO;QACL,KAAK;QACL,MAAM;QACN,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,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/** {@link useToolInfo} state before the tool has been invoked. */\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/** {@link useToolInfo} state while the tool is executing — `input` is available, output is not yet. */\nexport type ToolPendingState<ToolInput extends UnknownObject> = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n input: ToolInput;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/** {@link useToolInfo} state once the tool returned — `input`, `output`, and `responseMetadata` are all available. */\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;\n output: ToolOutput;\n responseMetadata: ToolResponseMetadata;\n};\n\n/**\n * Discriminated union describing the tool invocation that triggered the\n * current view render. Use `isIdle` / `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 input: Record<string, unknown> | null,\n output: Record<string, unknown> | null,\n responseMetadata: Record<string, unknown> | null,\n): \"idle\" | \"pending\" | \"success\" {\n if (input === null) {\n return \"idle\";\n }\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 (idle → 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(input, 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,\n status,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n output,\n responseMetadata,\n } as ToolState<Input, Output, Metadata>;\n}\n"]}
|
|
@@ -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,uCAAuC;QACvC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC7B,YAAY,CAAY,MAAM,CAAC,KAAK,CAAC,CAAC;YACtC,YAAY,CAAY,MAAM,CAAC,MAAM,CAAC,CAAC;YACvC,YAAY,CAAY,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACnD,CAAC;QAED,gEAAgE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAY,MAAM,C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AAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/D,YAAY,CAAY,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,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,gEAAgE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/D,YAAY,CAA0B,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,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 idle, input should be undefined\n if (result.status === \"idle\") {\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When pending, output and responseMetadata should be undefined\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When success, output and responseMetadata should be defined\n if (result.status === \"success\") {\n expectTypeOf<TestInput>(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 idle\n if (result.isIdle) {\n expectTypeOf<\"idle\">(result.status);\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\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<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<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n\n if (result.status === \"idle\") {\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(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>(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 can be TestInput or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n }\n\n if (result.status === \"success\") {\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 // Input can be Record<string, unknown> or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<Record<string, unknown>>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestOutput>(result.output);\n }\n });\n});\n"]}
|
|
@@ -68,7 +68,7 @@ describe("useToolInfo", () => {
|
|
|
68
68
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
69
69
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
70
70
|
});
|
|
71
|
-
afterEach(() => {
|
|
71
|
+
afterEach(async () => {
|
|
72
72
|
vi.unstubAllGlobals();
|
|
73
73
|
vi.resetAllMocks();
|
|
74
74
|
McpAppBridge.resetInstance();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"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;gBACjE,0BAA0B,CAAC;oBACzB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;oBACjD,iBAAiB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBACvD,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;oBACnC,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,KAAK;oBAChB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;oBAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, fireEvent, renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n type AppsSdkContext,\n SET_GLOBALS_EVENT_TYPE,\n SetGlobalsEvent,\n} from \"../bridges/apps-sdk/index.js\";\nimport { McpAppAdaptor, McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n let OpenaiMock: Pick<\n AppsSdkContext,\n \"toolInput\" | \"toolOutput\" | \"toolResponseMetadata\"\n >;\n\n beforeEach(() => {\n OpenaiMock = {\n toolInput: { name: \"pokemon\", args: { name: \"pikachu\" } },\n toolOutput: null,\n toolResponseMetadata: null,\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 toolInput on initial mount window.openai\", () => {\n const { result } = renderHook(() => useToolInfo());\n\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n });\n });\n\n it(\"should eventually return tool output and response metadata once tool call completes\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n OpenaiMock.toolOutput = toolOutput;\n OpenaiMock.toolResponseMetadata = toolResponseMetadata;\n fireEvent(\n window,\n new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {\n detail: {\n globals: {\n toolOutput,\n toolResponseMetadata,\n },\n },\n }),\n );\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should return idle state initially when tool input is not yet set\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"idle\",\n isIdle: true,\n isPending: false,\n isSuccess: false,\n input: null,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}
|