skybridge 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/cli/resolve-views-dir.d.ts +1 -0
  2. package/dist/cli/resolve-views-dir.js +17 -0
  3. package/dist/cli/resolve-views-dir.js.map +1 -0
  4. package/dist/cli/use-open-tunnel-browser.d.ts +6 -0
  5. package/dist/cli/use-open-tunnel-browser.js +19 -0
  6. package/dist/cli/use-open-tunnel-browser.js.map +1 -0
  7. package/dist/cli/use-typescript-check.js +1 -1
  8. package/dist/cli/use-typescript-check.js.map +1 -1
  9. package/dist/commands/build.js +1 -16
  10. package/dist/commands/build.js.map +1 -1
  11. package/dist/commands/dev.js +19 -1
  12. package/dist/commands/dev.js.map +1 -1
  13. package/dist/server/content-helpers.d.ts +40 -0
  14. package/dist/server/content-helpers.js +33 -0
  15. package/dist/server/content-helpers.js.map +1 -1
  16. package/dist/server/file-ref.d.ts +20 -0
  17. package/dist/server/file-ref.js +19 -0
  18. package/dist/server/file-ref.js.map +1 -1
  19. package/dist/server/middleware.d.ts +16 -3
  20. package/dist/server/middleware.js.map +1 -1
  21. package/dist/server/server.d.ts +152 -0
  22. package/dist/server/server.js +142 -57
  23. package/dist/server/server.js.map +1 -1
  24. package/dist/test/view.test.js +45 -0
  25. package/dist/test/view.test.js.map +1 -1
  26. package/dist/web/bridges/apps-sdk/adaptor.d.ts +1 -0
  27. package/dist/web/bridges/apps-sdk/adaptor.js +1 -0
  28. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  29. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  30. package/dist/web/bridges/apps-sdk/bridge.js +1 -0
  31. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  32. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  33. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  34. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  35. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  36. package/dist/web/bridges/get-adaptor.js +7 -0
  37. package/dist/web/bridges/get-adaptor.js.map +1 -1
  38. package/dist/web/bridges/mcp-app/adaptor.d.ts +1 -0
  39. package/dist/web/bridges/mcp-app/adaptor.js +1 -0
  40. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  41. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -0
  42. package/dist/web/bridges/mcp-app/bridge.js +1 -0
  43. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  44. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
  45. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  46. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  47. package/dist/web/bridges/types.d.ts +47 -0
  48. package/dist/web/bridges/types.js.map +1 -1
  49. package/dist/web/bridges/use-host-context.d.ts +5 -0
  50. package/dist/web/bridges/use-host-context.js +5 -0
  51. package/dist/web/bridges/use-host-context.js.map +1 -1
  52. package/dist/web/create-store.d.ts +26 -0
  53. package/dist/web/create-store.js +26 -0
  54. package/dist/web/create-store.js.map +1 -1
  55. package/dist/web/data-llm.d.ts +33 -0
  56. package/dist/web/data-llm.js +28 -0
  57. package/dist/web/data-llm.js.map +1 -1
  58. package/dist/web/generate-helpers.d.ts +2 -0
  59. package/dist/web/generate-helpers.js +2 -0
  60. package/dist/web/generate-helpers.js.map +1 -1
  61. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  62. package/dist/web/hooks/use-call-tool.js +28 -0
  63. package/dist/web/hooks/use-call-tool.js.map +1 -1
  64. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  65. package/dist/web/hooks/use-display-mode.js +20 -0
  66. package/dist/web/hooks/use-display-mode.js.map +1 -1
  67. package/dist/web/hooks/use-files.d.ts +32 -0
  68. package/dist/web/hooks/use-files.js +32 -0
  69. package/dist/web/hooks/use-files.js.map +1 -1
  70. package/dist/web/hooks/use-layout.d.ts +2 -0
  71. package/dist/web/hooks/use-layout.js +2 -0
  72. package/dist/web/hooks/use-layout.js.map +1 -1
  73. package/dist/web/hooks/use-open-external.d.ts +17 -0
  74. package/dist/web/hooks/use-open-external.js +16 -0
  75. package/dist/web/hooks/use-open-external.js.map +1 -1
  76. package/dist/web/hooks/use-request-close.d.ts +14 -0
  77. package/dist/web/hooks/use-request-close.js +13 -0
  78. package/dist/web/hooks/use-request-close.js.map +1 -1
  79. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  80. package/dist/web/hooks/use-request-modal.js +16 -1
  81. package/dist/web/hooks/use-request-modal.js.map +1 -1
  82. package/dist/web/hooks/use-request-size.d.ts +17 -0
  83. package/dist/web/hooks/use-request-size.js +16 -0
  84. package/dist/web/hooks/use-request-size.js.map +1 -1
  85. package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
  86. package/dist/web/hooks/use-send-follow-up-message.js +17 -0
  87. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  88. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  89. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  90. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  91. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  92. package/dist/web/hooks/use-tool-info.js +26 -0
  93. package/dist/web/hooks/use-tool-info.js.map +1 -1
  94. package/dist/web/hooks/use-user.d.ts +2 -0
  95. package/dist/web/hooks/use-user.js +2 -0
  96. package/dist/web/hooks/use-user.js.map +1 -1
  97. package/dist/web/hooks/use-view-state.d.ts +21 -0
  98. package/dist/web/hooks/use-view-state.js.map +1 -1
  99. package/dist/web/mount-view.d.ts +19 -0
  100. package/dist/web/mount-view.js +19 -0
  101. package/dist/web/mount-view.js.map +1 -1
  102. package/dist/web/plugin/plugin.d.ts +28 -0
  103. package/dist/web/plugin/plugin.js +26 -0
  104. package/dist/web/plugin/plugin.js.map +1 -1
  105. package/dist/web/types.d.ts +4 -0
  106. package/dist/web/types.js.map +1 -1
  107. package/package.json +1 -1
@@ -2,6 +2,32 @@ import { dequal } from "dequal/lite";
2
2
  import { create } from "zustand";
3
3
  import { getAdaptor } from "./bridges/index.js";
4
4
  import { filterViewContext, getInitialState, injectViewContext, serializeState, } from "./helpers/state.js";
5
+ /**
6
+ * Create a Zustand store that is bidirectionally synced with the host's
7
+ * `viewState`. Local store updates persist to the host, and external host
8
+ * updates rehydrate the store — making the store the single source of truth
9
+ * for state that should survive view remounts.
10
+ *
11
+ * Use this when you outgrow {@link useViewState} and want first-class Zustand
12
+ * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
13
+ *
14
+ * Skybridge-internal context fields (see {@link DataLLM}) are filtered out
15
+ * automatically before reaching your store.
16
+ *
17
+ * @typeParam State - Shape of the store's state. Must be a plain object.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * export const useStore = createStore<{ count: number; inc: () => void }>(
22
+ * (set) => ({
23
+ * count: 0,
24
+ * inc: () => set((s) => ({ count: s.count + 1 })),
25
+ * }),
26
+ * );
27
+ * ```
28
+ *
29
+ * @see https://docs.skybridge.tech/api-reference/create-store
30
+ */
5
31
  export function createStore(storeCreator, defaultState) {
6
32
  const initialState = getInitialState(defaultState);
7
33
  const store = create()((...args) => {
@@ -1 +1 @@
1
- {"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,MAAM,UAAU,WAAW,CACzB,YAAgD,EAChD,YAAoC;IAEpC,MAAM,YAAY,GAAG,eAAe,CAAC,Y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CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport { create, type StateCreator } from \"zustand\";\nimport { getAdaptor } from \"./bridges/index.js\";\nimport {\n filterViewContext,\n getInitialState,\n injectViewContext,\n serializeState,\n} from \"./helpers/state.js\";\nimport type { UnknownObject } from \"./types.js\";\n\nexport function createStore<State extends UnknownObject>(\n storeCreator: StateCreator<State, [], [], State>,\n defaultState?: State | (() => State),\n) {\n const initialState = getInitialState(defaultState);\n\n const store = create<State>()(\n (...args: Parameters<StateCreator<State, [], [], State>>) => {\n const baseStore = storeCreator(...args);\n\n if (initialState !== null) {\n return { ...baseStore, ...initialState };\n }\n\n return baseStore;\n },\n );\n\n // Bidirectional sync between the Zustand store and the adaptor's viewState.\n // Store changes persist to the host; external viewState changes rehydrate the store.\n store.subscribe((state: State) => {\n const serializedState = serializeState(state);\n if (serializedState !== null && serializedState !== undefined) {\n const stateToPersist = injectViewContext(serializedState as State);\n if (stateToPersist !== null) {\n getAdaptor().setViewState(stateToPersist);\n }\n }\n });\n\n const viewStateStore = getAdaptor().getHostContextStore(\"viewState\");\n viewStateStore.subscribe(() => {\n const externalState = viewStateStore.getSnapshot();\n if (externalState !== null) {\n const filtered = filterViewContext(externalState) as State;\n const current = serializeState(store.getState()) as State;\n if (!dequal(filtered, current)) {\n store.setState(filtered);\n }\n }\n });\n\n return store;\n}\n"]}
1
+ {"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG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;gBAC/B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport { create, type StateCreator } from \"zustand\";\nimport { getAdaptor } from \"./bridges/index.js\";\nimport {\n filterViewContext,\n getInitialState,\n injectViewContext,\n serializeState,\n} from \"./helpers/state.js\";\nimport type { UnknownObject } from \"./types.js\";\n\n/**\n * Create a Zustand store that is bidirectionally synced with the host's\n * `viewState`. Local store updates persist to the host, and external host\n * updates rehydrate the store — making the store the single source of truth\n * for state that should survive view remounts.\n *\n * Use this when you outgrow {@link useViewState} and want first-class Zustand\n * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.\n *\n * Skybridge-internal context fields (see {@link DataLLM}) are filtered out\n * automatically before reaching your store.\n *\n * @typeParam State - Shape of the store's state. Must be a plain object.\n *\n * @example\n * ```ts\n * export const useStore = createStore<{ count: number; inc: () => void }>(\n * (set) => ({\n * count: 0,\n * inc: () => set((s) => ({ count: s.count + 1 })),\n * }),\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/create-store\n */\nexport function createStore<State extends UnknownObject>(\n storeCreator: StateCreator<State, [], [], State>,\n defaultState?: State | (() => State),\n) {\n const initialState = getInitialState(defaultState);\n\n const store = create<State>()(\n (...args: Parameters<StateCreator<State, [], [], State>>) => {\n const baseStore = storeCreator(...args);\n\n if (initialState !== null) {\n return { ...baseStore, ...initialState };\n }\n\n return baseStore;\n },\n );\n\n // Bidirectional sync between the Zustand store and the adaptor's viewState.\n // Store changes persist to the host; external viewState changes rehydrate the store.\n store.subscribe((state: State) => {\n const serializedState = serializeState(state);\n if (serializedState !== null && serializedState !== undefined) {\n const stateToPersist = injectViewContext(serializedState as State);\n if (stateToPersist !== null) {\n getAdaptor().setViewState(stateToPersist);\n }\n }\n });\n\n const viewStateStore = getAdaptor().getHostContextStore(\"viewState\");\n viewStateStore.subscribe(() => {\n const externalState = viewStateStore.getSnapshot();\n if (externalState !== null) {\n const filtered = filterViewContext(externalState) as State;\n const current = serializeState(store.getState()) as State;\n if (!dequal(filtered, current)) {\n store.setState(filtered);\n }\n }\n });\n\n return store;\n}\n"]}
@@ -1,14 +1,47 @@
1
1
  import { type ReactNode } from "react";
2
+ /** Text content surfaced to the model by a {@link DataLLM} component. */
2
3
  export type DataLLMContent = string;
4
+ /**
5
+ * A node in the {@link DataLLM} tree. Nested `<DataLLM>` elements form a
6
+ * hierarchy that is serialized as an indented bullet list for the model.
7
+ */
3
8
  export interface DataLLMNode {
4
9
  id: string;
5
10
  parentId: string | null;
6
11
  content: string | null;
7
12
  }
13
+ /**
14
+ * Key under which the serialized {@link DataLLM} tree is persisted on the
15
+ * host's `viewState`. The host exposes the value to the model on subsequent
16
+ * turns.
17
+ */
8
18
  export declare const VIEW_CONTEXT_KEY: "__view_context";
9
19
  interface DataLLMProps {
10
20
  content: DataLLMContent | null | undefined;
11
21
  children?: ReactNode;
12
22
  }
23
+ /**
24
+ * Surface in-view content to the LLM so it can reason about what the user is
25
+ * seeing without an extra tool call.
26
+ *
27
+ * Each `<DataLLM>` registers `content` as a node in a tree (parented by any
28
+ * enclosing `<DataLLM>`). The flattened tree is serialized as an indented
29
+ * bullet list and persisted on the host's `viewState` under
30
+ * {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of
31
+ * the next turn's context.
32
+ *
33
+ * Pass `null`/`undefined` for `content` to register only as a structural
34
+ * parent (useful for grouping).
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * <DataLLM content="Active filters">
39
+ * <DataLLM content={`Sort: ${sort}`} />
40
+ * <DataLLM content={`Page: ${page}`} />
41
+ * </DataLLM>
42
+ * ```
43
+ *
44
+ * @see https://docs.skybridge.tech/api-reference/data-llm
45
+ */
13
46
  export declare function DataLLM({ content, children }: DataLLMProps): import("react/jsx-runtime").JSX.Element;
14
47
  export {};
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useEffect, useId, } from "react";
3
3
  import { getAdaptor } from "./bridges/index.js";
4
+ /**
5
+ * Key under which the serialized {@link DataLLM} tree is persisted on the
6
+ * host's `viewState`. The host exposes the value to the model on subsequent
7
+ * turns.
8
+ */
4
9
  export const VIEW_CONTEXT_KEY = "__view_context";
5
10
  const nodes = new Map();
6
11
  function setNode(node) {
@@ -20,6 +25,29 @@ function onChange() {
20
25
  }));
21
26
  }
22
27
  const ParentIdContext = createContext(null);
28
+ /**
29
+ * Surface in-view content to the LLM so it can reason about what the user is
30
+ * seeing without an extra tool call.
31
+ *
32
+ * Each `<DataLLM>` registers `content` as a node in a tree (parented by any
33
+ * enclosing `<DataLLM>`). The flattened tree is serialized as an indented
34
+ * bullet list and persisted on the host's `viewState` under
35
+ * {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of
36
+ * the next turn's context.
37
+ *
38
+ * Pass `null`/`undefined` for `content` to register only as a structural
39
+ * parent (useful for grouping).
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * <DataLLM content="Active filters">
44
+ * <DataLLM content={`Sort: ${sort}`} />
45
+ * <DataLLM content={`Page: ${page}`} />
46
+ * </DataLLM>
47
+ * ```
48
+ *
49
+ * @see https://docs.skybridge.tech/api-reference/data-llm
50
+ */
23
51
  export function DataLLM({ content, children }) {
24
52
  const parentId = useContext(ParentIdContext);
25
53
  const id = useId();
@@ -1 +1 @@
1
- {"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../src/web/data-llm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,KAAK,GACN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAUhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAyB,CAAC;AAE1D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,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ACpC,CAAC;IACH,CAAC;IAED,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEtB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n createContext,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n} from \"react\";\nimport { getAdaptor } from \"./bridges/index.js\";\n\nexport type DataLLMContent = string;\n\nexport interface DataLLMNode {\n id: string;\n parentId: string | null;\n content: string | null;\n}\n\nexport const VIEW_CONTEXT_KEY = \"__view_context\" as const;\n\nconst nodes = new Map<string, DataLLMNode>();\n\nfunction setNode(node: DataLLMNode) {\n nodes.set(node.id, node);\n onChange();\n}\n\nfunction removeNode(id: string) {\n nodes.delete(id);\n onChange();\n}\n\nfunction onChange() {\n const description = getLLMDescriptionString();\n const adaptor = getAdaptor();\n adaptor.setViewState((prevState) => ({\n ...prevState,\n [VIEW_CONTEXT_KEY]: description,\n }));\n}\n\nconst ParentIdContext = createContext<string | null>(null);\n\ninterface DataLLMProps {\n content: DataLLMContent | null | undefined;\n children?: ReactNode;\n}\n\nexport function DataLLM({ content, children }: DataLLMProps) {\n const parentId = useContext(ParentIdContext);\n const id = useId();\n\n useEffect(() => {\n if (content) {\n setNode({\n id,\n parentId,\n content,\n });\n } else {\n removeNode(id);\n }\n\n return () => {\n removeNode(id);\n };\n }, [id, parentId, content]);\n\n return (\n <ParentIdContext.Provider value={id}>{children}</ParentIdContext.Provider>\n );\n}\n\nfunction getLLMDescriptionString(): string {\n const byParent = new Map<string | null, DataLLMNode[]>();\n for (const node of Array.from(nodes.values())) {\n const key = node.parentId ?? null;\n if (!byParent.has(key)) {\n byParent.set(key, []);\n }\n byParent.get(key)?.push(node);\n }\n\n for (const list of byParent.values()) {\n list.sort((a, b) => a.id.localeCompare(b.id));\n }\n\n const lines: string[] = [];\n\n function traverseTree(parentId: string | null, depth: number) {\n const children = byParent.get(parentId);\n if (!children) {\n return;\n }\n\n for (const child of children) {\n if (child.content?.trim()) {\n const indent = \" \".repeat(depth);\n lines.push(`${indent}- ${child.content.trim()}`);\n }\n traverseTree(child.id, depth + 1);\n }\n }\n\n traverseTree(null, 0);\n\n return lines.join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../src/web/data-llm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,KAAK,GACN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAehD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAyB,CAAC;AAE1D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;AAE7C,SAAS,OAAO,CAAC,IAAiB;IAChC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzB,QAAQ,EAAE,CAAC;AACb,CAAC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACjB,QAAQ,EAAE,CAAC;AACb,CAAC;AAED,SAAS,QAAQ;IACf,MAAM,WAAW,GAAG,uBAAuB,EAAE,CAAC;IAC9C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,OAAO,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACnC,GAAG,SAAS;QACZ,CAAC,gBAAgB,CAAC,EAAE,WAAW;KAChC,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,eAAe,GAAG,aAAa,CAAgB,IAAI,CAAC,CAAC;AAO3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAgB;IACzD,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;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D,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;gBAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAClC,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACnD,CAAC;YACD,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEtB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n createContext,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n} from \"react\";\nimport { getAdaptor } from \"./bridges/index.js\";\n\n/** Text content surfaced to the model by a {@link DataLLM} component. */\nexport type DataLLMContent = string;\n\n/**\n * A node in the {@link DataLLM} tree. Nested `<DataLLM>` elements form a\n * hierarchy that is serialized as an indented bullet list for the model.\n */\nexport interface DataLLMNode {\n id: string;\n parentId: string | null;\n content: string | null;\n}\n\n/**\n * Key under which the serialized {@link DataLLM} tree is persisted on the\n * host's `viewState`. The host exposes the value to the model on subsequent\n * turns.\n */\nexport const VIEW_CONTEXT_KEY = \"__view_context\" as const;\n\nconst nodes = new Map<string, DataLLMNode>();\n\nfunction setNode(node: DataLLMNode) {\n nodes.set(node.id, node);\n onChange();\n}\n\nfunction removeNode(id: string) {\n nodes.delete(id);\n onChange();\n}\n\nfunction onChange() {\n const description = getLLMDescriptionString();\n const adaptor = getAdaptor();\n adaptor.setViewState((prevState) => ({\n ...prevState,\n [VIEW_CONTEXT_KEY]: description,\n }));\n}\n\nconst ParentIdContext = createContext<string | null>(null);\n\ninterface DataLLMProps {\n content: DataLLMContent | null | undefined;\n children?: ReactNode;\n}\n\n/**\n * Surface in-view content to the LLM so it can reason about what the user is\n * seeing without an extra tool call.\n *\n * Each `<DataLLM>` registers `content` as a node in a tree (parented by any\n * enclosing `<DataLLM>`). The flattened tree is serialized as an indented\n * bullet list and persisted on the host's `viewState` under\n * {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of\n * the next turn's context.\n *\n * Pass `null`/`undefined` for `content` to register only as a structural\n * parent (useful for grouping).\n *\n * @example\n * ```tsx\n * <DataLLM content=\"Active filters\">\n * <DataLLM content={`Sort: ${sort}`} />\n * <DataLLM content={`Page: ${page}`} />\n * </DataLLM>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/data-llm\n */\nexport function DataLLM({ content, children }: DataLLMProps) {\n const parentId = useContext(ParentIdContext);\n const id = useId();\n\n useEffect(() => {\n if (content) {\n setNode({\n id,\n parentId,\n content,\n });\n } else {\n removeNode(id);\n }\n\n return () => {\n removeNode(id);\n };\n }, [id, parentId, content]);\n\n return (\n <ParentIdContext.Provider value={id}>{children}</ParentIdContext.Provider>\n );\n}\n\nfunction getLLMDescriptionString(): string {\n const byParent = new Map<string | null, DataLLMNode[]>();\n for (const node of Array.from(nodes.values())) {\n const key = node.parentId ?? null;\n if (!byParent.has(key)) {\n byParent.set(key, []);\n }\n byParent.get(key)?.push(node);\n }\n\n for (const list of byParent.values()) {\n list.sort((a, b) => a.id.localeCompare(b.id));\n }\n\n const lines: string[] = [];\n\n function traverseTree(parentId: string | null, depth: number) {\n const children = byParent.get(parentId);\n if (!children) {\n return;\n }\n\n for (const child of children) {\n if (child.content?.trim()) {\n const indent = \" \".repeat(depth);\n lines.push(`${indent}- ${child.content.trim()}`);\n }\n traverseTree(child.id, depth + 1);\n }\n }\n\n traverseTree(null, 0);\n\n return lines.join(\"\\n\");\n}\n"]}
@@ -64,6 +64,8 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
64
64
  * // toolInfo.output.structuredContent is typed based on view output schema
65
65
  * }
66
66
  * ```
67
+ *
68
+ * @see https://docs.skybridge.tech/api-reference/generate-helpers
67
69
  */
68
70
  export declare function generateHelpers<ServerType = never>(): {
69
71
  /**
@@ -53,6 +53,8 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
53
53
  * // toolInfo.output.structuredContent is typed based on view output schema
54
54
  * }
55
55
  * ```
56
+ *
57
+ * @see https://docs.skybridge.tech/api-reference/generate-helpers
56
58
  */
57
59
  export function generateHelpers() {
58
60
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAId,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAIjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InferTools,\n ToolInput,\n ToolOutput,\n ToolResponseMetadata,\n} from \"../server/index.js\";\nimport type { CallToolResponse } from \"./bridges/types.js\";\nimport {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n useCallTool,\n} from \"./hooks/use-call-tool.js\";\nimport { type ToolState, useToolInfo } from \"./hooks/use-tool-info.js\";\nimport type { Objectify, Prettify } from \"./types.js\";\n\ntype TypedCallToolResponse<TOutput> = CallToolResponse & {\n structuredContent: TOutput;\n};\n\ntype TypedCallToolReturn<TInput, TOutput> = Prettify<\n CallToolState<TypedCallToolResponse<TOutput>> & {\n callTool: CallToolFn<TInput, TypedCallToolResponse<TOutput>>;\n callToolAsync: CallToolAsyncFn<TInput, TypedCallToolResponse<TOutput>>;\n }\n>;\n\ntype TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<\n Objectify<TInput>,\n Objectify<TOutput>,\n Objectify<TResponseMetadata>\n>;\n\n/**\n * Creates typed versions of skybridge hooks with full type inference\n * for tool names, inputs, and outputs.\n *\n * This is the recommended way to use skybridge hooks in your views.\n * Set this up once in a dedicated file and export the typed hooks for use across your app.\n *\n * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).\n * Must be a server instance created with method chaining.\n * TypeScript will validate that tools can be inferred from this type.\n *\n * @example\n * ```typescript\n * // src/server.ts\n * const server = new McpServer({ name: \"my-app\", version: \"1.0\" }, {})\n * .registerTool({\n * name: \"search-trip\",\n * inputSchema: { destination: z.string() },\n * outputSchema: { results: z.array(z.string()) },\n * view: { component: \"search-trip\", description: \"Search trips\" },\n * }, async ({ destination }) => {\n * return { content: [{ type: \"text\", text: `Found trips to ${destination}` }] };\n * });\n *\n * export type AppType = typeof server;\n * ```\n *\n * @example\n * ```typescript\n * // src/helpers.ts (one-time setup)\n * import type { AppType } from \"./server\";\n * import { generateHelpers } from \"skybridge/web\";\n *\n * export const { useCallTool, useToolInfo } = generateHelpers<AppType>();\n * ```\n *\n * @example\n * ```typescript\n * // src/views/search.tsx (usage)\n * import { useCallTool, useToolInfo } from \"../helpers\";\n *\n * export function SearchView() {\n * const { callTool, data } = useCallTool(\"search-trip\");\n * // ^ autocomplete for tool names\n * callTool({ destination: \"Spain\" });\n * // ^ autocomplete for input fields\n *\n * const toolInfo = useToolInfo<\"search-trip\">();\n * // ^ autocomplete for view names\n * // toolInfo.input is typed based on view input schema\n * // toolInfo.output.structuredContent is typed based on view output schema\n * }\n * ```\n */\nexport function generateHelpers<ServerType = never>() {\n type Tools = InferTools<ServerType>;\n type ToolNames = keyof Tools & string;\n\n return {\n /**\n * Typed version of `useCallTool` that provides autocomplete for tool names\n * and type inference for inputs and outputs.\n *\n * @param name - The name of the tool to call. Autocompletes based on your server's tool registry.\n * @returns A hook with typed `callTool` function and `data` property.\n *\n * @example\n * ```typescript\n * const { callTool, data, isPending } = useCallTool(\"search-trip\");\n * // TypeScript knows callTool expects { destination: string }\n * callTool({ destination: \"Spain\" });\n *\n * // data.structuredContent is typed based on your outputSchema\n * if (data) {\n * console.log(data.structuredContent.results);\n * }\n * ```\n */\n useCallTool: <ToolName extends ToolNames>(\n name: ToolName,\n ): TypedCallToolReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>\n > => {\n return useCallTool(name) as TypedCallToolReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>\n >;\n },\n\n /**\n * Typed version of `useToolInfo` that provides autocomplete for tool names\n * and type inference for inputs, outputs, and responseMetadata.\n *\n * @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.\n * @returns A discriminated union with `status: \"pending\" | \"success\"` that narrows correctly.\n *\n * @example\n * ```typescript\n * const toolInfo = useToolInfo<\"search-trip\">();\n * // toolInfo.input is typed as { destination: string; ... }\n * // toolInfo.output is typed as { results: Array<...>; ... }\n * // toolInfo.responseMetadata is typed based on _meta in callback return\n * // toolInfo.status narrows correctly: \"pending\" | \"success\"\n *\n * if (toolInfo.isPending) {\n * // TypeScript knows output and responseMetadata are undefined here\n * console.log(toolInfo.input.destination);\n * }\n *\n * if (toolInfo.isSuccess) {\n * // TypeScript knows output and responseMetadata are defined here\n * console.log(toolInfo.output.results);\n * console.log(toolInfo.responseMetadata);\n * }\n * ```\n */\n useToolInfo: <ToolName extends ToolNames>(): TypedToolInfoReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>,\n ToolResponseMetadata<ServerType, ToolName>\n > => {\n return useToolInfo() as TypedToolInfoReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>,\n ToolResponseMetadata<ServerType, ToolName>\n >;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAId,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAIjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InferTools,\n ToolInput,\n ToolOutput,\n ToolResponseMetadata,\n} from \"../server/index.js\";\nimport type { CallToolResponse } from \"./bridges/types.js\";\nimport {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n useCallTool,\n} from \"./hooks/use-call-tool.js\";\nimport { type ToolState, useToolInfo } from \"./hooks/use-tool-info.js\";\nimport type { Objectify, Prettify } from \"./types.js\";\n\ntype TypedCallToolResponse<TOutput> = CallToolResponse & {\n structuredContent: TOutput;\n};\n\ntype TypedCallToolReturn<TInput, TOutput> = Prettify<\n CallToolState<TypedCallToolResponse<TOutput>> & {\n callTool: CallToolFn<TInput, TypedCallToolResponse<TOutput>>;\n callToolAsync: CallToolAsyncFn<TInput, TypedCallToolResponse<TOutput>>;\n }\n>;\n\ntype TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<\n Objectify<TInput>,\n Objectify<TOutput>,\n Objectify<TResponseMetadata>\n>;\n\n/**\n * Creates typed versions of skybridge hooks with full type inference\n * for tool names, inputs, and outputs.\n *\n * This is the recommended way to use skybridge hooks in your views.\n * Set this up once in a dedicated file and export the typed hooks for use across your app.\n *\n * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).\n * Must be a server instance created with method chaining.\n * TypeScript will validate that tools can be inferred from this type.\n *\n * @example\n * ```typescript\n * // src/server.ts\n * const server = new McpServer({ name: \"my-app\", version: \"1.0\" }, {})\n * .registerTool({\n * name: \"search-trip\",\n * inputSchema: { destination: z.string() },\n * outputSchema: { results: z.array(z.string()) },\n * view: { component: \"search-trip\", description: \"Search trips\" },\n * }, async ({ destination }) => {\n * return { content: [{ type: \"text\", text: `Found trips to ${destination}` }] };\n * });\n *\n * export type AppType = typeof server;\n * ```\n *\n * @example\n * ```typescript\n * // src/helpers.ts (one-time setup)\n * import type { AppType } from \"./server\";\n * import { generateHelpers } from \"skybridge/web\";\n *\n * export const { useCallTool, useToolInfo } = generateHelpers<AppType>();\n * ```\n *\n * @example\n * ```typescript\n * // src/views/search.tsx (usage)\n * import { useCallTool, useToolInfo } from \"../helpers\";\n *\n * export function SearchView() {\n * const { callTool, data } = useCallTool(\"search-trip\");\n * // ^ autocomplete for tool names\n * callTool({ destination: \"Spain\" });\n * // ^ autocomplete for input fields\n *\n * const toolInfo = useToolInfo<\"search-trip\">();\n * // ^ autocomplete for view names\n * // toolInfo.input is typed based on view input schema\n * // toolInfo.output.structuredContent is typed based on view output schema\n * }\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/generate-helpers\n */\nexport function generateHelpers<ServerType = never>() {\n type Tools = InferTools<ServerType>;\n type ToolNames = keyof Tools & string;\n\n return {\n /**\n * Typed version of `useCallTool` that provides autocomplete for tool names\n * and type inference for inputs and outputs.\n *\n * @param name - The name of the tool to call. Autocompletes based on your server's tool registry.\n * @returns A hook with typed `callTool` function and `data` property.\n *\n * @example\n * ```typescript\n * const { callTool, data, isPending } = useCallTool(\"search-trip\");\n * // TypeScript knows callTool expects { destination: string }\n * callTool({ destination: \"Spain\" });\n *\n * // data.structuredContent is typed based on your outputSchema\n * if (data) {\n * console.log(data.structuredContent.results);\n * }\n * ```\n */\n useCallTool: <ToolName extends ToolNames>(\n name: ToolName,\n ): TypedCallToolReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>\n > => {\n return useCallTool(name) as TypedCallToolReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>\n >;\n },\n\n /**\n * Typed version of `useToolInfo` that provides autocomplete for tool names\n * and type inference for inputs, outputs, and responseMetadata.\n *\n * @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.\n * @returns A discriminated union with `status: \"pending\" | \"success\"` that narrows correctly.\n *\n * @example\n * ```typescript\n * const toolInfo = useToolInfo<\"search-trip\">();\n * // toolInfo.input is typed as { destination: string; ... }\n * // toolInfo.output is typed as { results: Array<...>; ... }\n * // toolInfo.responseMetadata is typed based on _meta in callback return\n * // toolInfo.status narrows correctly: \"pending\" | \"success\"\n *\n * if (toolInfo.isPending) {\n * // TypeScript knows output and responseMetadata are undefined here\n * console.log(toolInfo.input.destination);\n * }\n *\n * if (toolInfo.isSuccess) {\n * // TypeScript knows output and responseMetadata are defined here\n * console.log(toolInfo.output.results);\n * console.log(toolInfo.responseMetadata);\n * }\n * ```\n */\n useToolInfo: <ToolName extends ToolNames>(): TypedToolInfoReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>,\n ToolResponseMetadata<ServerType, ToolName>\n > => {\n return useToolInfo() as TypedToolInfoReturn<\n ToolInput<ServerType, ToolName>,\n ToolOutput<ServerType, ToolName>,\n ToolResponseMetadata<ServerType, ToolName>\n >;\n },\n };\n}\n"]}
@@ -36,13 +36,26 @@ type CallToolErrorState = {
36
36
  data: undefined;
37
37
  error: unknown;
38
38
  };
39
+ /**
40
+ * State of a {@link useCallTool} invocation, discriminated by `status`.
41
+ * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.
42
+ */
39
43
  export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
44
+ /**
45
+ * Optional callbacks fired around a {@link useCallTool} call.
46
+ * `onSettled` runs after success or error.
47
+ */
40
48
  export type SideEffects<ToolArgs, ToolResponse> = {
41
49
  onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
42
50
  onError?: (error: unknown, toolArgs: ToolArgs) => void;
43
51
  onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
44
52
  };
45
53
  type IsArgsOptional<T> = [T] extends [null] ? true : HasRequiredKeys<T> extends false ? true : false;
54
+ /**
55
+ * Fire-and-forget call function returned by {@link useCallTool}. Tracks state
56
+ * on the hook and supports optional {@link SideEffects} callbacks. Args are
57
+ * optional when the tool accepts none.
58
+ */
46
59
  export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
47
60
  (): void;
48
61
  (sideEffects: SideEffects<TArgs, TResponse>): void;
@@ -52,11 +65,43 @@ export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ?
52
65
  (args: TArgs): void;
53
66
  (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
54
67
  };
68
+ /**
69
+ * Promise-returning call function returned by {@link useCallTool}. Rejects
70
+ * if the tool errors; use `try/catch` for error handling.
71
+ */
55
72
  export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
56
73
  (): Promise<TResponse>;
57
74
  (args: TArgs): Promise<TResponse>;
58
75
  } : (args: TArgs) => Promise<TResponse>;
59
76
  type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
77
+ /**
78
+ * Call a server tool from a view and track its execution state.
79
+ *
80
+ * Returns the current {@link CallToolState} plus two callers: `callTool`
81
+ * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
82
+ * (promise-returning). If the same instance is invoked again while a call is
83
+ * in flight, the older response is dropped from the rendered state (but any
84
+ * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
85
+ *
86
+ * Pair with {@link useToolInfo} to read the result of the tool invocation
87
+ * that produced the current view. For end-to-end type safety across tool
88
+ * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
89
+ * over calling this hook directly.
90
+ *
91
+ * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
92
+ * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
97
+ *
98
+ * <button onClick={() => callTool({ query: "skybridge" }, {
99
+ * onSuccess: (res) => console.log(res.structuredContent),
100
+ * })} />
101
+ * ```
102
+ *
103
+ * @see https://docs.skybridge.tech/api-reference/use-call-tool
104
+ */
60
105
  export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
61
106
  callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
62
107
  callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
@@ -1,5 +1,33 @@
1
1
  import { useRef, useState } from "react";
2
2
  import { getAdaptor, } from "../bridges/index.js";
3
+ /**
4
+ * Call a server tool from a view and track its execution state.
5
+ *
6
+ * Returns the current {@link CallToolState} plus two callers: `callTool`
7
+ * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
8
+ * (promise-returning). If the same instance is invoked again while a call is
9
+ * in flight, the older response is dropped from the rendered state (but any
10
+ * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
11
+ *
12
+ * Pair with {@link useToolInfo} to read the result of the tool invocation
13
+ * that produced the current view. For end-to-end type safety across tool
14
+ * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
15
+ * over calling this hook directly.
16
+ *
17
+ * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
18
+ * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
23
+ *
24
+ * <button onClick={() => callTool({ query: "skybridge" }, {
25
+ * onSuccess: (res) => console.log(res.structuredContent),
26
+ * })} />
27
+ * ```
28
+ *
29
+ * @see https://docs.skybridge.tech/api-reference/use-call-tool
30
+ */
3
31
  export const useCallTool = (name) => {
4
32
  const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
5
33
  const callIdRef = useRef(0);
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA2F7B,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAK1D,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,MAAM,OAAO,GAAG,KAAK,EACnB,QAAkB,EACiB,EAAE;QACrC,MAAM,MAAM,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC;QACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,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,CAAa,CAAC;QACpE,CAAC;QAED,OAAO,CAAC,QAAQ,CAAC;aACd,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACzC,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,WAAW,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACxC,WAAW,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAmD,CAAC;IAErD,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useRef, useState } from \"react\";\n\nimport {\n type CallToolArgs,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n\n const execute = async (\n toolArgs: ToolArgs,\n ): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({ status: \"pending\", data: undefined, error: undefined });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n };\n\n const callToolAsync = ((toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n }) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = ((\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n }) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
1
+ {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,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L,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useRef, useState } from \"react\";\n\nimport {\n type CallToolArgs,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\n/**\n * State of a {@link useCallTool} invocation, discriminated by `status`.\n * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.\n */\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\n/**\n * Optional callbacks fired around a {@link useCallTool} call.\n * `onSettled` runs after success or error.\n */\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\n/**\n * Fire-and-forget call function returned by {@link useCallTool}. Tracks state\n * on the hook and supports optional {@link SideEffects} callbacks. Args are\n * optional when the tool accepts none.\n */\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\n/**\n * Promise-returning call function returned by {@link useCallTool}. Rejects\n * if the tool errors; use `try/catch` for error handling.\n */\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\n/**\n * Call a server tool from a view and track its execution state.\n *\n * Returns the current {@link CallToolState} plus two callers: `callTool`\n * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`\n * (promise-returning). If the same instance is invoked again while a call is\n * in flight, the older response is dropped from the rendered state (but any\n * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).\n *\n * Pair with {@link useToolInfo} to read the result of the tool invocation\n * that produced the current view. For end-to-end type safety across tool\n * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}\n * over calling this hook directly.\n *\n * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).\n * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.\n *\n * @example\n * ```tsx\n * const { callTool, isPending, data } = useCallTool<{ query: string }>(\"search\");\n *\n * <button onClick={() => callTool({ query: \"skybridge\" }, {\n * onSuccess: (res) => console.log(res.structuredContent),\n * })} />\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-call-tool\n */\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n\n const execute = async (\n toolArgs: ToolArgs,\n ): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({ status: \"pending\", data: undefined, error: undefined });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n };\n\n const callToolAsync = ((toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n }) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = ((\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n }) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
@@ -1,4 +1,24 @@
1
1
  import type { RequestDisplayMode } from "../bridges/types.js";
2
+ /**
3
+ * Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
4
+ *
5
+ * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
6
+ * host to switch modes — the host returns the mode it actually applied, which
7
+ * may differ from the request. The reported value also updates when the host
8
+ * changes the mode on its own (e.g. user expands the widget).
9
+ *
10
+ * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
11
+ * to layout changes that come with display-mode switches (e.g. `maxHeight`),
12
+ * pair with {@link useLayout}.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const [mode, setMode] = useDisplayMode();
17
+ * <button onClick={() => setMode("fullscreen")}>Expand</button>
18
+ * ```
19
+ *
20
+ * @see https://docs.skybridge.tech/api-reference/use-display-mode
21
+ */
2
22
  export declare function useDisplayMode(): readonly [import("../index.js").DisplayMode, (mode: RequestDisplayMode) => Promise<{
3
23
  mode: RequestDisplayMode;
4
24
  }>];
@@ -1,5 +1,25 @@
1
1
  import { useCallback } from "react";
2
2
  import { getAdaptor, useHostContext } from "../bridges/index.js";
3
+ /**
4
+ * Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
5
+ *
6
+ * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
7
+ * host to switch modes — the host returns the mode it actually applied, which
8
+ * may differ from the request. The reported value also updates when the host
9
+ * changes the mode on its own (e.g. user expands the widget).
10
+ *
11
+ * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
12
+ * to layout changes that come with display-mode switches (e.g. `maxHeight`),
13
+ * pair with {@link useLayout}.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const [mode, setMode] = useDisplayMode();
18
+ * <button onClick={() => setMode("fullscreen")}>Expand</button>
19
+ * ```
20
+ *
21
+ * @see https://docs.skybridge.tech/api-reference/use-display-mode
22
+ */
3
23
  export function useDisplayMode() {
4
24
  const displayMode = useHostContext("displayMode");
5
25
  const adaptor = getAdaptor();
@@ -1 +1 @@
1
- {"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
1
+ {"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useLayout}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
@@ -1,3 +1,35 @@
1
+ /**
2
+ * File operations bound to the current host: `upload` a `File`, resolve a
3
+ * `downloadUrl` for an uploaded file, and `selectFiles` to open the host's
4
+ * native file picker.
5
+ *
6
+ * Currently Apps-SDK-only — calling any of these from MCP Apps throws.
7
+ * `selectFiles` additionally requires a ChatGPT host version that exposes the
8
+ * picker; it throws if the capability is unavailable.
9
+ *
10
+ * `upload` returns `FileMetadata` (`fileId`, optional `fileName`, `mimeType`).
11
+ * To pass an uploaded file to a tool whose input uses {@link FileRef}, first
12
+ * call `getDownloadUrl` and then build the ref yourself — field names differ
13
+ * (camelCase on the client, snake_case in the schema) and `download_url` is
14
+ * required.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const { upload, getDownloadUrl } = useFiles();
19
+ * const meta = await upload(file);
20
+ * const { downloadUrl } = await getDownloadUrl(meta);
21
+ * callTool({
22
+ * document: {
23
+ * file_id: meta.fileId,
24
+ * download_url: downloadUrl,
25
+ * file_name: meta.fileName,
26
+ * mime_type: meta.mimeType,
27
+ * },
28
+ * });
29
+ * ```
30
+ *
31
+ * @see https://docs.skybridge.tech/api-reference/use-files
32
+ */
1
33
  export declare function useFiles(): {
2
34
  upload: (file: File, options?: import("../index.js").UploadFileOptions) => Promise<import("../index.js").FileMetadata>;
3
35
  getDownloadUrl: (file: import("../index.js").FileMetadata) => Promise<{
@@ -1,4 +1,36 @@
1
1
  import { getAdaptor } from "../bridges/index.js";
2
+ /**
3
+ * File operations bound to the current host: `upload` a `File`, resolve a
4
+ * `downloadUrl` for an uploaded file, and `selectFiles` to open the host's
5
+ * native file picker.
6
+ *
7
+ * Currently Apps-SDK-only — calling any of these from MCP Apps throws.
8
+ * `selectFiles` additionally requires a ChatGPT host version that exposes the
9
+ * picker; it throws if the capability is unavailable.
10
+ *
11
+ * `upload` returns `FileMetadata` (`fileId`, optional `fileName`, `mimeType`).
12
+ * To pass an uploaded file to a tool whose input uses {@link FileRef}, first
13
+ * call `getDownloadUrl` and then build the ref yourself — field names differ
14
+ * (camelCase on the client, snake_case in the schema) and `download_url` is
15
+ * required.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const { upload, getDownloadUrl } = useFiles();
20
+ * const meta = await upload(file);
21
+ * const { downloadUrl } = await getDownloadUrl(meta);
22
+ * callTool({
23
+ * document: {
24
+ * file_id: meta.fileId,
25
+ * download_url: downloadUrl,
26
+ * file_name: meta.fileName,
27
+ * mime_type: meta.mimeType,
28
+ * },
29
+ * });
30
+ * ```
31
+ *
32
+ * @see https://docs.skybridge.tech/api-reference/use-files
33
+ */
2
34
  export function useFiles() {
3
35
  const adaptor = getAdaptor();
4
36
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"use-files.js","sourceRoot":"","sources":["../../../src/web/hooks/use-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,QAAQ;IACtB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,UAAU;QAC1B,cAAc,EAAE,OAAO,CAAC,kBAAkB;QAC1C,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import { getAdaptor } from \"../bridges/index.js\";\n\nexport function useFiles() {\n const adaptor = getAdaptor();\n return {\n upload: adaptor.uploadFile,\n getDownloadUrl: adaptor.getFileDownloadUrl,\n selectFiles: adaptor.selectFiles,\n };\n}\n"]}
1
+ {"version":3,"file":"use-files.js","sourceRoot":"","sources":["../../../src/web/hooks/use-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,UAAU;QAC1B,cAAc,EAAE,OAAO,CAAC,kBAAkB;QAC1C,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import { getAdaptor } from \"../bridges/index.js\";\n\n/**\n * File operations bound to the current host: `upload` a `File`, resolve a\n * `downloadUrl` for an uploaded file, and `selectFiles` to open the host's\n * native file picker.\n *\n * Currently Apps-SDK-only — calling any of these from MCP Apps throws.\n * `selectFiles` additionally requires a ChatGPT host version that exposes the\n * picker; it throws if the capability is unavailable.\n *\n * `upload` returns `FileMetadata` (`fileId`, optional `fileName`, `mimeType`).\n * To pass an uploaded file to a tool whose input uses {@link FileRef}, first\n * call `getDownloadUrl` and then build the ref yourself — field names differ\n * (camelCase on the client, snake_case in the schema) and `download_url` is\n * required.\n *\n * @example\n * ```tsx\n * const { upload, getDownloadUrl } = useFiles();\n * const meta = await upload(file);\n * const { downloadUrl } = await getDownloadUrl(meta);\n * callTool({\n * document: {\n * file_id: meta.fileId,\n * download_url: downloadUrl,\n * file_name: meta.fileName,\n * mime_type: meta.mimeType,\n * },\n * });\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-files\n */\nexport function useFiles() {\n const adaptor = getAdaptor();\n return {\n upload: adaptor.uploadFile,\n getDownloadUrl: adaptor.getFileDownloadUrl,\n selectFiles: adaptor.selectFiles,\n };\n}\n"]}
@@ -18,5 +18,7 @@ export type LayoutState = {
18
18
  * // Respect safe area insets
19
19
  * const paddingTop = safeArea.insets.top;
20
20
  * ```
21
+ *
22
+ * @see https://docs.skybridge.tech/api-reference/use-layout
21
23
  */
22
24
  export declare function useLayout(): LayoutState;
@@ -13,6 +13,8 @@ import { useHostContext } from "../bridges/index.js";
13
13
  * // Respect safe area insets
14
14
  * const paddingTop = safeArea.insets.top;
15
15
  * ```
16
+ *
17
+ * @see https://docs.skybridge.tech/api-reference/use-layout
16
18
  */
17
19
  export function useLayout() {
18
20
  const theme = useHostContext("theme");
@@ -1 +1 @@
1
- {"version":3,"file":"use-layout.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQhF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { type SafeArea, type Theme, useHostContext } from \"../bridges/index.js\";\n\nexport type LayoutState = {\n theme: Theme;\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing layout and visual environment information.\n * These values may change on resize or theme toggle.\n *\n * @example\n * ```tsx\n * const { theme, maxHeight, safeArea } = useLayout();\n *\n * // Apply theme-aware styling\n * const backgroundColor = theme === \"dark\" ? \"#1a1a1a\" : \"#ffffff\";\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n */\nexport function useLayout(): LayoutState {\n const theme = useHostContext(\"theme\");\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { theme, maxHeight, safeArea };\n}\n"]}
1
+ {"version":3,"file":"use-layout.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQhF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { type SafeArea, type Theme, useHostContext } from \"../bridges/index.js\";\n\nexport type LayoutState = {\n theme: Theme;\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing layout and visual environment information.\n * These values may change on resize or theme toggle.\n *\n * @example\n * ```tsx\n * const { theme, maxHeight, safeArea } = useLayout();\n *\n * // Apply theme-aware styling\n * const backgroundColor = theme === \"dark\" ? \"#1a1a1a\" : \"#ffffff\";\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-layout\n */\nexport function useLayout(): LayoutState {\n const theme = useHostContext(\"theme\");\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { theme, maxHeight, safeArea };\n}\n"]}
@@ -1,3 +1,20 @@
1
1
  import type { OpenExternalOptions } from "../bridges/types.js";
2
+ /** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */
2
3
  export type OpenExternalFn = (href: string, options?: OpenExternalOptions) => void;
4
+ /**
5
+ * Open an external URL through the host (e.g. in the user's browser).
6
+ *
7
+ * Use this instead of `window.open` or anchor `target="_blank"`, which are
8
+ * unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
9
+ * ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
10
+ * `redirectUrl: false` to suppress it).
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const openExternal = useOpenExternal();
15
+ * <button onClick={() => openExternal("https://example.com")}>Open docs</button>
16
+ * ```
17
+ *
18
+ * @see https://docs.skybridge.tech/api-reference/use-open-external
19
+ */
3
20
  export declare function useOpenExternal(): OpenExternalFn;
@@ -1,5 +1,21 @@
1
1
  import { useCallback } from "react";
2
2
  import { getAdaptor } from "../bridges/index.js";
3
+ /**
4
+ * Open an external URL through the host (e.g. in the user's browser).
5
+ *
6
+ * Use this instead of `window.open` or anchor `target="_blank"`, which are
7
+ * unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
8
+ * ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
9
+ * `redirectUrl: false` to suppress it).
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const openExternal = useOpenExternal();
14
+ * <button onClick={() => openExternal("https://example.com")}>Open docs</button>
15
+ * ```
16
+ *
17
+ * @see https://docs.skybridge.tech/api-reference/use-open-external
18
+ */
3
19
  export function useOpenExternal() {
4
20
  const adaptor = getAdaptor();
5
21
  const openExternal = useCallback((href, options) => adaptor.openExternal(href, options), [adaptor]);
@@ -1 +1 @@
1
- {"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQjD,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAY,EAAE,OAA6B,EAAE,EAAE,CAC9C,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EACrC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { OpenExternalOptions } from \"../bridges/types.js\";\n\nexport type OpenExternalFn = (\n href: string,\n options?: OpenExternalOptions,\n) => void;\n\nexport function useOpenExternal(): OpenExternalFn {\n const adaptor = getAdaptor();\n const openExternal = useCallback(\n (href: string, options?: OpenExternalOptions) =>\n adaptor.openExternal(href, options),\n [adaptor],\n );\n\n return openExternal;\n}\n"]}
1
+ {"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AASjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAY,EAAE,OAA6B,EAAE,EAAE,CAC9C,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EACrC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { OpenExternalOptions } from \"../bridges/types.js\";\n\n/** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */\nexport type OpenExternalFn = (\n href: string,\n options?: OpenExternalOptions,\n) => void;\n\n/**\n * Open an external URL through the host (e.g. in the user's browser).\n *\n * Use this instead of `window.open` or anchor `target=\"_blank\"`, which are\n * unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.\n * ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass\n * `redirectUrl: false` to suppress it).\n *\n * @example\n * ```tsx\n * const openExternal = useOpenExternal();\n * <button onClick={() => openExternal(\"https://example.com\")}>Open docs</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-open-external\n */\nexport function useOpenExternal(): OpenExternalFn {\n const adaptor = getAdaptor();\n const openExternal = useCallback(\n (href: string, options?: OpenExternalOptions) =>\n adaptor.openExternal(href, options),\n [adaptor],\n );\n\n return openExternal;\n}\n"]}
@@ -1,2 +1,16 @@
1
+ /** Function that asks the host to close the current view, returned by {@link useRequestClose}. */
1
2
  export type RequestCloseFn = () => Promise<void>;
3
+ /**
4
+ * Ask the host to close (dismiss) the current view. The host decides whether
5
+ * to honor the request. Useful from modal views or after a terminal action
6
+ * like "Done".
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const close = useRequestClose();
11
+ * <button onClick={() => close()}>Done</button>
12
+ * ```
13
+ *
14
+ * @see https://docs.skybridge.tech/api-reference/use-request-close
15
+ */
2
16
  export declare function useRequestClose(): RequestCloseFn;