skybridge 0.0.0-dev.ed29eee → 0.0.0-dev.ed38f16

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 (285) hide show
  1. package/README.md +8 -7
  2. package/dist/cli/build-helpers.d.ts +1 -1
  3. package/dist/cli/build-helpers.js +4 -4
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +2 -2
  6. package/dist/cli/build-helpers.test.js.map +1 -1
  7. package/dist/cli/build-steps.js +1 -1
  8. package/dist/cli/build-steps.js.map +1 -1
  9. package/dist/cli/build-steps.test.js +3 -3
  10. package/dist/cli/build-steps.test.js.map +1 -1
  11. package/dist/cli/detect-port.js +0 -1
  12. package/dist/cli/detect-port.js.map +1 -1
  13. package/dist/cli/run-plain.js +2 -1
  14. package/dist/cli/run-plain.js.map +1 -1
  15. package/dist/cli/telemetry.js +2 -0
  16. package/dist/cli/telemetry.js.map +1 -1
  17. package/dist/cli/use-execute-steps.d.ts +1 -1
  18. package/dist/cli/use-nodemon.d.ts +11 -1
  19. package/dist/cli/use-nodemon.js +30 -8
  20. package/dist/cli/use-nodemon.js.map +1 -1
  21. package/dist/cli/use-typescript-check.js +1 -1
  22. package/dist/cli/use-typescript-check.js.map +1 -1
  23. package/dist/commands/dev.js +4 -4
  24. package/dist/commands/dev.js.map +1 -1
  25. package/dist/commands/start.js +2 -2
  26. package/dist/commands/start.js.map +1 -1
  27. package/dist/server/app.d.ts +194 -0
  28. package/dist/server/app.js +266 -0
  29. package/dist/server/app.js.map +1 -0
  30. package/dist/server/app.test.js +97 -0
  31. package/dist/server/app.test.js.map +1 -0
  32. package/dist/server/auth/discovery.d.ts +2 -1
  33. package/dist/server/auth/discovery.js +2 -2
  34. package/dist/server/auth/discovery.js.map +1 -1
  35. package/dist/server/auth/index.d.ts +21 -17
  36. package/dist/server/auth/index.js.map +1 -1
  37. package/dist/server/auth/providers/auth0.d.ts +2 -2
  38. package/dist/server/auth/providers/auth0.js +13 -8
  39. package/dist/server/auth/providers/auth0.js.map +1 -1
  40. package/dist/server/auth/providers/auth0.test.js +1 -1
  41. package/dist/server/auth/providers/auth0.test.js.map +1 -1
  42. package/dist/server/auth/providers/authplane.d.ts +2 -2
  43. package/dist/server/auth/providers/authplane.js.map +1 -1
  44. package/dist/server/auth/providers/authplane.test.js +10 -7
  45. package/dist/server/auth/providers/authplane.test.js.map +1 -1
  46. package/dist/server/auth/providers/clerk.d.ts +2 -2
  47. package/dist/server/auth/providers/clerk.js.map +1 -1
  48. package/dist/server/auth/providers/clerk.test.js +1 -1
  49. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  50. package/dist/server/auth/providers/custom.d.ts +8 -6
  51. package/dist/server/auth/providers/custom.js +5 -2
  52. package/dist/server/auth/providers/custom.js.map +1 -1
  53. package/dist/server/auth/providers/custom.test.js +13 -10
  54. package/dist/server/auth/providers/custom.test.js.map +1 -1
  55. package/dist/server/auth/providers/descope.d.ts +2 -2
  56. package/dist/server/auth/providers/descope.js.map +1 -1
  57. package/dist/server/auth/providers/descope.test.js +3 -3
  58. package/dist/server/auth/providers/descope.test.js.map +1 -1
  59. package/dist/server/auth/providers/stytch.d.ts +2 -2
  60. package/dist/server/auth/providers/stytch.js.map +1 -1
  61. package/dist/server/auth/providers/workos.d.ts +5 -4
  62. package/dist/server/auth/providers/workos.js +2 -1
  63. package/dist/server/auth/providers/workos.js.map +1 -1
  64. package/dist/server/auth/setup.d.ts +1 -1
  65. package/dist/server/auth/setup.js +3 -4
  66. package/dist/server/auth/setup.js.map +1 -1
  67. package/dist/server/auth/setup.test.js +83 -77
  68. package/dist/server/auth/setup.test.js.map +1 -1
  69. package/dist/server/auth/verify.d.ts +5 -3
  70. package/dist/server/auth/verify.js +2 -2
  71. package/dist/server/auth/verify.js.map +1 -1
  72. package/dist/server/auth/verify.test.js +16 -0
  73. package/dist/server/auth/verify.test.js.map +1 -1
  74. package/dist/server/auth-extra.test-d.js +97 -49
  75. package/dist/server/auth-extra.test-d.js.map +1 -1
  76. package/dist/server/auth.d.ts +7 -8
  77. package/dist/server/auth.js +4 -5
  78. package/dist/server/auth.js.map +1 -1
  79. package/dist/server/build-manifest.test.js +7 -6
  80. package/dist/server/build-manifest.test.js.map +1 -1
  81. package/dist/server/content-helpers.d.ts +1 -1
  82. package/dist/server/content-helpers.js.map +1 -1
  83. package/dist/server/express.d.ts +23 -3
  84. package/dist/server/express.js +38 -32
  85. package/dist/server/express.js.map +1 -1
  86. package/dist/server/express.test.js +220 -103
  87. package/dist/server/express.test.js.map +1 -1
  88. package/dist/server/file-ref.d.ts +1 -1
  89. package/dist/server/file-ref.js +1 -1
  90. package/dist/server/file-ref.js.map +1 -1
  91. package/dist/server/index.d.ts +6 -3
  92. package/dist/server/index.js +3 -1
  93. package/dist/server/index.js.map +1 -1
  94. package/dist/server/mcp-errors.test.js +41 -0
  95. package/dist/server/mcp-errors.test.js.map +1 -0
  96. package/dist/server/middleware.d.ts +6 -6
  97. package/dist/server/middleware.js.map +1 -1
  98. package/dist/server/middleware.test-d.js +1 -1
  99. package/dist/server/middleware.test-d.js.map +1 -1
  100. package/dist/server/middleware.test.js +222 -150
  101. package/dist/server/middleware.test.js.map +1 -1
  102. package/dist/server/register-tool.test.js +77 -0
  103. package/dist/server/register-tool.test.js.map +1 -0
  104. package/dist/server/server.d.ts +149 -119
  105. package/dist/server/server.js +146 -303
  106. package/dist/server/server.js.map +1 -1
  107. package/dist/server/skills-integration.test.js +19 -12
  108. package/dist/server/skills-integration.test.js.map +1 -1
  109. package/dist/server/skills.d.ts +3 -5
  110. package/dist/server/skills.js +17 -24
  111. package/dist/server/skills.js.map +1 -1
  112. package/dist/server/skills.test.js +8 -12
  113. package/dist/server/skills.test.js.map +1 -1
  114. package/dist/server/templateHelper.d.ts +0 -3
  115. package/dist/server/templateHelper.js.map +1 -1
  116. package/dist/server/templates.generated.js +4 -8
  117. package/dist/server/templates.generated.js.map +1 -1
  118. package/dist/server/tool-extra.test.js +88 -0
  119. package/dist/server/tool-extra.test.js.map +1 -0
  120. package/dist/server/view-resource-resolution.test.js +18 -13
  121. package/dist/server/view-resource-resolution.test.js.map +1 -1
  122. package/dist/test/utils.d.ts +9 -11
  123. package/dist/test/utils.js +220 -201
  124. package/dist/test/utils.js.map +1 -1
  125. package/dist/test/view.test.js +25 -37
  126. package/dist/test/view.test.js.map +1 -1
  127. package/dist/views/index.d.ts +10 -0
  128. package/dist/views/index.js +3 -0
  129. package/dist/views/index.js.map +1 -0
  130. package/dist/{web/plugin → views}/scan-views.js +1 -1
  131. package/dist/views/scan-views.js.map +1 -0
  132. package/dist/views/scan-views.test.js.map +1 -0
  133. package/dist/views/validate-view.d.ts +1 -0
  134. package/dist/{web/plugin → views}/validate-view.js +2 -2
  135. package/dist/views/validate-view.js.map +1 -0
  136. package/dist/views/validate-view.test.js.map +1 -0
  137. package/dist/web/bridges/adaptor.d.ts +6 -2
  138. package/dist/web/bridges/adaptor.js +47 -10
  139. package/dist/web/bridges/adaptor.js.map +1 -1
  140. package/dist/web/bridges/adaptor.test.js +1 -1
  141. package/dist/web/bridges/adaptor.test.js.map +1 -1
  142. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
  143. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
  144. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  145. package/dist/web/bridges/get-adaptor.test.js +2 -2
  146. package/dist/web/bridges/get-adaptor.test.js.map +1 -1
  147. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -1
  148. package/dist/web/bridges/mcp-app/bridge.js +10 -3
  149. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  150. package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
  151. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
  152. package/dist/web/bridges/mcp-app/types.d.ts +26 -3
  153. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  154. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  155. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  156. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  157. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  158. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  159. package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
  160. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  161. package/dist/web/bridges/types.d.ts +33 -14
  162. package/dist/web/bridges/types.js.map +1 -1
  163. package/dist/web/create-store.test.js +2 -2
  164. package/dist/web/create-store.test.js.map +1 -1
  165. package/dist/web/data-llm.js +3 -2
  166. package/dist/web/data-llm.js.map +1 -1
  167. package/dist/web/data-llm.test.js +8 -2
  168. package/dist/web/data-llm.test.js.map +1 -1
  169. package/dist/web/generate-helpers.d.ts +23 -19
  170. package/dist/web/generate-helpers.js +21 -17
  171. package/dist/web/generate-helpers.js.map +1 -1
  172. package/dist/web/generate-helpers.test-d.js +3 -3
  173. package/dist/web/generate-helpers.test-d.js.map +1 -1
  174. package/dist/web/generate-helpers.test.js +2 -2
  175. package/dist/web/generate-helpers.test.js.map +1 -1
  176. package/dist/web/hooks/index.d.ts +4 -2
  177. package/dist/web/hooks/index.js +4 -2
  178. package/dist/web/hooks/index.js.map +1 -1
  179. package/dist/web/hooks/openai-extensions.test.js +104 -0
  180. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  181. package/dist/web/hooks/use-call-tool.d.ts +2 -2
  182. package/dist/web/hooks/use-call-tool.js +15 -10
  183. package/dist/web/hooks/use-call-tool.js.map +1 -1
  184. package/dist/web/hooks/use-call-tool.test.js +9 -2
  185. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  186. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  187. package/dist/web/hooks/use-deep-link.js +60 -0
  188. package/dist/web/hooks/use-deep-link.js.map +1 -0
  189. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  190. package/dist/web/hooks/use-display-mode.js +1 -1
  191. package/dist/web/hooks/use-display-mode.js.map +1 -1
  192. package/dist/web/hooks/use-display-mode.test.js +1 -1
  193. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  194. package/dist/web/hooks/use-download.d.ts +1 -3
  195. package/dist/web/hooks/use-download.js +1 -2
  196. package/dist/web/hooks/use-download.js.map +1 -1
  197. package/dist/web/hooks/use-download.test.js +7 -7
  198. package/dist/web/hooks/use-download.test.js.map +1 -1
  199. package/dist/web/hooks/use-files.test.js +1 -1
  200. package/dist/web/hooks/use-files.test.js.map +1 -1
  201. package/dist/web/hooks/use-host.d.ts +44 -0
  202. package/dist/web/hooks/use-host.js +45 -0
  203. package/dist/web/hooks/use-host.js.map +1 -0
  204. package/dist/web/hooks/{use-host-info.test.js → use-host.test.js} +7 -7
  205. package/dist/web/hooks/use-host.test.js.map +1 -0
  206. package/dist/web/hooks/use-model-context.d.ts +42 -0
  207. package/dist/web/hooks/use-model-context.js +63 -0
  208. package/dist/web/hooks/use-model-context.js.map +1 -0
  209. package/dist/web/hooks/use-open-external.test.js +2 -2
  210. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  211. package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
  212. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  213. package/dist/web/hooks/use-request-close.test.js +1 -1
  214. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  215. package/dist/web/hooks/use-request-modal.test.js +1 -1
  216. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  217. package/dist/web/hooks/use-request-size.d.ts +1 -1
  218. package/dist/web/hooks/use-request-size.js +1 -1
  219. package/dist/web/hooks/use-request-size.js.map +1 -1
  220. package/dist/web/hooks/use-request-size.test.js +1 -1
  221. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  222. package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
  223. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  224. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  225. package/dist/web/hooks/use-tool-info.js +0 -1
  226. package/dist/web/hooks/use-tool-info.js.map +1 -1
  227. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  228. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  229. package/dist/web/hooks/use-tool-info.test.js +2 -7
  230. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  231. package/dist/web/hooks/use-user.d.ts +3 -2
  232. package/dist/web/hooks/use-user.js +4 -3
  233. package/dist/web/hooks/use-user.js.map +1 -1
  234. package/dist/web/hooks/use-user.test.js +5 -3
  235. package/dist/web/hooks/use-user.test.js.map +1 -1
  236. package/dist/web/hooks/use-view-state.test.js +2 -2
  237. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  238. package/dist/web/hooks/use-viewport.d.ts +20 -0
  239. package/dist/web/hooks/use-viewport.js +21 -0
  240. package/dist/web/hooks/use-viewport.js.map +1 -0
  241. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  242. package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
  243. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  244. package/dist/web/mount-view.d.ts +3 -2
  245. package/dist/web/mount-view.js +5 -8
  246. package/dist/web/mount-view.js.map +1 -1
  247. package/package.json +14 -12
  248. package/dist/web/hooks/use-host-info.d.ts +0 -22
  249. package/dist/web/hooks/use-host-info.js +0 -30
  250. package/dist/web/hooks/use-host-info.js.map +0 -1
  251. package/dist/web/hooks/use-host-info.test.js.map +0 -1
  252. package/dist/web/hooks/use-layout.d.ts +0 -24
  253. package/dist/web/hooks/use-layout.js +0 -25
  254. package/dist/web/hooks/use-layout.js.map +0 -1
  255. package/dist/web/hooks/use-layout.test.js.map +0 -1
  256. package/dist/web/plugin/data-llm.test.js +0 -81
  257. package/dist/web/plugin/data-llm.test.js.map +0 -1
  258. package/dist/web/plugin/plugin-build.test.js +0 -54
  259. package/dist/web/plugin/plugin-build.test.js.map +0 -1
  260. package/dist/web/plugin/plugin.d.ts +0 -39
  261. package/dist/web/plugin/plugin.js +0 -200
  262. package/dist/web/plugin/plugin.js.map +0 -1
  263. package/dist/web/plugin/plugin.test.js +0 -61
  264. package/dist/web/plugin/plugin.test.js.map +0 -1
  265. package/dist/web/plugin/scan-views.js.map +0 -1
  266. package/dist/web/plugin/scan-views.test.js.map +0 -1
  267. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  268. package/dist/web/plugin/transform-data-llm.js +0 -96
  269. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  270. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  271. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  272. package/dist/web/plugin/validate-view.d.ts +0 -1
  273. package/dist/web/plugin/validate-view.js.map +0 -1
  274. package/dist/web/plugin/validate-view.test.js.map +0 -1
  275. /package/dist/{web/hooks/use-host-info.test.d.ts → server/app.test.d.ts} +0 -0
  276. /package/dist/{web/hooks/use-layout.test.d.ts → server/mcp-errors.test.d.ts} +0 -0
  277. /package/dist/{web/plugin/data-llm.test.d.ts → server/register-tool.test.d.ts} +0 -0
  278. /package/dist/{web/plugin/plugin-build.test.d.ts → server/tool-extra.test.d.ts} +0 -0
  279. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  280. /package/dist/{web/plugin → views}/scan-views.test.d.ts +0 -0
  281. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  282. /package/dist/{web/plugin → views}/validate-view.test.d.ts +0 -0
  283. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
  284. /package/dist/web/{plugin/plugin.test.d.ts → hooks/openai-extensions.test.d.ts} +0 -0
  285. /package/dist/web/{plugin/transform-data-llm.test.d.ts → hooks/use-host.test.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { InferTools, ToolInput, ToolOutput, ToolResponseMetadata } from "../server/index.js";
2
- import type { CallToolResponse } from "./bridges/types.js";
2
+ import type { CallToolOptions, CallToolResponse } from "./bridges/types.js";
3
3
  import { type CallToolAsyncFn, type CallToolFn, type CallToolState } from "./hooks/use-call-tool.js";
4
4
  import { type ToolState } from "./hooks/use-tool-info.js";
5
5
  import type { Objectify, Prettify } from "./types.js";
@@ -18,24 +18,28 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
18
18
  * This is the recommended way to use skybridge hooks in your views.
19
19
  * Set this up once in a dedicated file and export the typed hooks for use across your app.
20
20
  *
21
- * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
22
- * Must be a server instance created with method chaining.
23
- * TypeScript will validate that tools can be inferred from this type.
21
+ * @typeParam AppType - The type of your Skybridge app (use `typeof app`). The
22
+ * handler must return the chained server so the tool
23
+ * types are carried on the app type.
24
24
  *
25
25
  * @example
26
26
  * ```typescript
27
27
  * // src/server.ts
28
- * const server = new McpServer({ name: "my-app", version: "1.0" }, {})
29
- * .registerTool({
30
- * name: "search-trip",
31
- * inputSchema: { destination: z.string() },
32
- * outputSchema: { results: z.array(z.string()) },
33
- * view: { component: "search-trip", description: "Search trips" },
34
- * }, async ({ destination }) => {
35
- * return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
36
- * });
28
+ * export const app = new Skybridge({
29
+ * name: "my-app",
30
+ * version: "1.0",
31
+ * handler: (server) =>
32
+ * server.registerTool({
33
+ * name: "search-trip",
34
+ * inputSchema: { destination: z.string() },
35
+ * outputSchema: { results: z.array(z.string()) },
36
+ * view: { component: "search-trip", description: "Search trips" },
37
+ * }, async ({ destination }) => {
38
+ * return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
39
+ * }),
40
+ * });
37
41
  *
38
- * export type AppType = typeof server;
42
+ * export type AppType = typeof app;
39
43
  * ```
40
44
  *
41
45
  * @example
@@ -67,12 +71,12 @@ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objecti
67
71
  *
68
72
  * @see https://docs.skybridge.tech/api-reference/generate-helpers
69
73
  */
70
- export declare function generateHelpers<ServerType = never>(): {
74
+ export declare function generateHelpers<AppType = never>(): {
71
75
  /**
72
76
  * Typed version of `useCallTool` that provides autocomplete for tool names
73
77
  * and type inference for inputs and outputs.
74
78
  *
75
- * @param name - The name of the tool to call. Autocompletes based on your server's tool registry.
79
+ * @param name - The name of the tool to call. Autocompletes based on your app's tool registry.
76
80
  * @returns A hook with typed `callTool` function and `data` property.
77
81
  *
78
82
  * @example
@@ -87,12 +91,12 @@ export declare function generateHelpers<ServerType = never>(): {
87
91
  * }
88
92
  * ```
89
93
  */
90
- useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
94
+ useCallTool: <ToolName extends keyof InferTools<AppType> & string>(name: ToolName, options?: CallToolOptions) => TypedCallToolReturn<ToolInput<AppType, ToolName>, ToolOutput<AppType, ToolName>>;
91
95
  /**
92
96
  * Typed version of `useToolInfo` that provides autocomplete for tool names
93
97
  * and type inference for inputs, outputs, and responseMetadata.
94
98
  *
95
- * @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.
99
+ * @typeParam K - The name of the tool. Autocompletes based on your app's tool registry.
96
100
  * @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
97
101
  *
98
102
  * @example
@@ -115,6 +119,6 @@ export declare function generateHelpers<ServerType = never>(): {
115
119
  * }
116
120
  * ```
117
121
  */
118
- useToolInfo: <ToolName extends keyof InferTools<ServerType> & string>() => TypedToolInfoReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>, ToolResponseMetadata<ServerType, ToolName>>;
122
+ useToolInfo: <ToolName extends keyof InferTools<AppType> & string>() => TypedToolInfoReturn<ToolInput<AppType, ToolName>, ToolOutput<AppType, ToolName>, ToolResponseMetadata<AppType, ToolName>>;
119
123
  };
120
124
  export {};
@@ -7,24 +7,28 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
7
7
  * This is the recommended way to use skybridge hooks in your views.
8
8
  * Set this up once in a dedicated file and export the typed hooks for use across your app.
9
9
  *
10
- * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
11
- * Must be a server instance created with method chaining.
12
- * TypeScript will validate that tools can be inferred from this type.
10
+ * @typeParam AppType - The type of your Skybridge app (use `typeof app`). The
11
+ * handler must return the chained server so the tool
12
+ * types are carried on the app type.
13
13
  *
14
14
  * @example
15
15
  * ```typescript
16
16
  * // src/server.ts
17
- * const server = new McpServer({ name: "my-app", version: "1.0" }, {})
18
- * .registerTool({
19
- * name: "search-trip",
20
- * inputSchema: { destination: z.string() },
21
- * outputSchema: { results: z.array(z.string()) },
22
- * view: { component: "search-trip", description: "Search trips" },
23
- * }, async ({ destination }) => {
24
- * return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
25
- * });
17
+ * export const app = new Skybridge({
18
+ * name: "my-app",
19
+ * version: "1.0",
20
+ * handler: (server) =>
21
+ * server.registerTool({
22
+ * name: "search-trip",
23
+ * inputSchema: { destination: z.string() },
24
+ * outputSchema: { results: z.array(z.string()) },
25
+ * view: { component: "search-trip", description: "Search trips" },
26
+ * }, async ({ destination }) => {
27
+ * return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
28
+ * }),
29
+ * });
26
30
  *
27
- * export type AppType = typeof server;
31
+ * export type AppType = typeof app;
28
32
  * ```
29
33
  *
30
34
  * @example
@@ -62,7 +66,7 @@ export function generateHelpers() {
62
66
  * Typed version of `useCallTool` that provides autocomplete for tool names
63
67
  * and type inference for inputs and outputs.
64
68
  *
65
- * @param name - The name of the tool to call. Autocompletes based on your server's tool registry.
69
+ * @param name - The name of the tool to call. Autocompletes based on your app's tool registry.
66
70
  * @returns A hook with typed `callTool` function and `data` property.
67
71
  *
68
72
  * @example
@@ -77,14 +81,14 @@ export function generateHelpers() {
77
81
  * }
78
82
  * ```
79
83
  */
80
- useCallTool: (name) => {
81
- return useCallTool(name);
84
+ useCallTool: (name, options) => {
85
+ return useCallTool(name, options);
82
86
  },
83
87
  /**
84
88
  * Typed version of `useToolInfo` that provides autocomplete for tool names
85
89
  * and type inference for inputs, outputs, and responseMetadata.
86
90
  *
87
- * @typeParam K - The name of the tool. Autocompletes based on your server's tool registry.
91
+ * @typeParam K - The name of the tool. Autocompletes based on your app's tool registry.
88
92
  * @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
89
93
  *
90
94
  * @example
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"]}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EACd,OAAyB,EAIzB,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAG/B,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 { CallToolOptions, 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 AppType - The type of your Skybridge app (use `typeof app`). The\n * handler must return the chained server so the tool\n * types are carried on the app type.\n *\n * @example\n * ```typescript\n * // src/server.ts\n * export const app = new Skybridge({\n * name: \"my-app\",\n * version: \"1.0\",\n * handler: (server) =>\n * server.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 *\n * export type AppType = typeof app;\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<AppType = never>() {\n type Tools = InferTools<AppType>;\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 app'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 options?: CallToolOptions,\n ): TypedCallToolReturn<\n ToolInput<AppType, ToolName>,\n ToolOutput<AppType, ToolName>\n > => {\n return useCallTool(name, options) as TypedCallToolReturn<\n ToolInput<AppType, ToolName>,\n ToolOutput<AppType, 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 app'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<AppType, ToolName>,\n ToolOutput<AppType, ToolName>,\n ToolResponseMetadata<AppType, ToolName>\n > => {\n return useToolInfo() as TypedToolInfoReturn<\n ToolInput<AppType, ToolName>,\n ToolOutput<AppType, ToolName>,\n ToolResponseMetadata<AppType, ToolName>\n >;\n },\n };\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { expectTypeOf, test } from "vitest";
2
- import { createInterfaceTestServer, createTestServer } from "../test/utils.js";
2
+ import { createInterfaceTestApp, createTestApp } from "../test/utils.js";
3
3
  import { generateHelpers } from "./generate-helpers.js";
4
- const server = createTestServer();
5
- const interfaceServer = createInterfaceTestServer();
4
+ const app = createTestApp();
5
+ const interfaceApp = createInterfaceTestApp();
6
6
  test("InferTools extracts the tool registry type (views + registerTool)", () => {
7
7
  expectTypeOf().toHaveProperty("search-trip");
8
8
  expectTypeOf().toHaveProperty("get-trip-details");
@@ -1 +1 @@
1
- {"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAGlC,MAAM,eAAe,GAAG,yBAAyB,EAAE,CAAC;AAGpD,IAAI,CAAC,mEAAmE,EAAE,GAAG,EAAE;IAG7E,YAAY,EAAS,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACpD,YAAY,EAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACzD,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACxD,YAAY,EAAS,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAC7D,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;IAC3D,YAAY,EAAS,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;IAC3D,YAAY,EAAS,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC;AAClE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wEAAwE,EAAE,GAAG,EAAE;IAGlF,YAAY,EAAS,CAAC,aAAa,EAUhC,CA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C","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type {\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"../server/index.js\";\nimport { createInterfaceTestServer, createTestServer } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst server = createTestServer();\ntype TestServer = typeof server;\n\nconst interfaceServer = createInterfaceTestServer();\ntype InterfaceTestServer = typeof interfaceServer;\n\ntest(\"InferTools extracts the tool registry type (views + registerTool)\", () => {\n type Tools = InferTools<TestServer>;\n\n expectTypeOf<Tools>().toHaveProperty(\"search-trip\");\n expectTypeOf<Tools>().toHaveProperty(\"get-trip-details\");\n expectTypeOf<Tools>().toHaveProperty(\"no-input-view\");\n expectTypeOf<Tools>().toHaveProperty(\"calculate-price\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-output-view\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-tool\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"tool-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-mixed-returns\");\n});\n\ntest(\"ToolNames returns a union of tool name literals (views + registerTool)\", () => {\n type Names = ToolNames<TestServer>;\n\n expectTypeOf<Names>().toEqualTypeOf<\n | \"search-trip\"\n | \"get-trip-details\"\n | \"no-input-view\"\n | \"calculate-price\"\n | \"inferred-output-view\"\n | \"inferred-tool\"\n | \"view-with-metadata\"\n | \"tool-with-metadata\"\n | \"view-with-mixed-returns\"\n >();\n});\n\ntest(\"ToolInput extracts the correct input type from Zod schema\", () => {\n type SearchInput = ToolInput<TestServer, \"search-trip\">;\n\n expectTypeOf<SearchInput>().toEqualTypeOf<{\n destination: string;\n departureDate?: string | undefined;\n maxPrice?: number | undefined;\n }>();\n\n type DetailsInput = ToolInput<TestServer, \"get-trip-details\">;\n\n expectTypeOf<DetailsInput>().toEqualTypeOf<{\n tripId: string;\n }>();\n\n type CalculateInput = ToolInput<TestServer, \"calculate-price\">;\n\n expectTypeOf<CalculateInput>().toEqualTypeOf<{\n tripId: string;\n passengers: number;\n }>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback's structuredContent\", () => {\n type SearchOutput = ToolOutput<TestServer, \"search-trip\">;\n\n expectTypeOf<SearchOutput>().toEqualTypeOf<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n type DetailsOutput = ToolOutput<TestServer, \"get-trip-details\">;\n\n expectTypeOf<DetailsOutput>().toEqualTypeOf<{\n name: string;\n description: string;\n images: string[];\n }>();\n\n // Note: outputSchema has totalPrice: z.string(), but callback returns number\n // Type is inferred from callback, so totalPrice is number\n type CalculateOutput = ToolOutput<TestServer, \"calculate-price\">;\n\n expectTypeOf<CalculateOutput>().toEqualTypeOf<{\n totalPrice: number;\n currency: string;\n }>();\n\n type NoInputOutput = ToolOutput<TestServer, \"no-input-view\">;\n expectTypeOf<NoInputOutput>().toEqualTypeOf<Record<never, unknown>>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback (inferred)\", () => {\n type InferredViewOutput = ToolOutput<TestServer, \"inferred-output-view\">;\n\n expectTypeOf<InferredViewOutput>().toEqualTypeOf<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n\n type InferredToolOutput = ToolOutput<TestServer, \"inferred-tool\">;\n\n expectTypeOf<InferredToolOutput>().toEqualTypeOf<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n});\n\ntest(\"generateHelpers provides autocomplete for tool names (views + registerTool)\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n useCallTool(\"search-trip\");\n useCallTool(\"get-trip-details\");\n useCallTool(\"no-input-view\");\n useCallTool(\"calculate-price\");\n useCallTool(\"inferred-output-view\");\n useCallTool(\"inferred-tool\");\n useCallTool(\"view-with-metadata\");\n useCallTool(\"tool-with-metadata\");\n useCallTool(\"view-with-mixed-returns\");\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useCallTool(\"invalid-name\");\n});\n\ntest(\"useCallTool returns correctly typed callTool function\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool({ destination: \"Spain\" });\n callTool({ destination: \"France\", departureDate: \"2024-06-01\" });\n callTool({ destination: \"Italy\", maxPrice: 1000 });\n\n const { callTool: calculateTool } = useCallTool(\"calculate-price\");\n calculateTool({ tripId: \"123\", passengers: 2 });\n});\n\ntest(\"callTool can be called without args for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool, callToolAsync } = useCallTool(\"no-input-view\");\n\n callTool();\n\n callTool({});\n\n callToolAsync();\n callToolAsync({});\n});\n\ntest(\"callTool requires args for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n // @ts-expect-error - \"destination\" is required\n callTool();\n\n // @ts-expect-error - \"destination\" is required\n callTool({});\n\n // This should work\n callTool({ destination: \"Spain\" });\n});\n\ntest(\"callTool supports sideEffects for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool(\n { destination: \"Spain\" },\n {\n onSuccess: (response, args) => {\n expectTypeOf(response.structuredContent.results).toBeArray();\n expectTypeOf(args.destination).toBeString();\n },\n onError: (error, args) => {\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n onSettled: (response, error, args) => {\n if (response) {\n expectTypeOf(response.structuredContent.totalCount).toBeNumber();\n }\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n },\n );\n});\n\ntest(\"callTool supports sideEffects for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"no-input-view\");\n\n callTool({\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n });\n\n callTool(\n {},\n {\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n },\n );\n});\n\ntest(\"callToolAsync returns correctly typed promise\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n const { callToolAsync: searchAsync } = useCallTool(\"search-trip\");\n const searchPromise = searchAsync({ destination: \"Spain\" });\n expectTypeOf(searchPromise).resolves.toHaveProperty(\"structuredContent\");\n\n const { callToolAsync: noInputAsync } = useCallTool(\"no-input-view\");\n const noInputPromise = noInputAsync();\n expectTypeOf(noInputPromise).resolves.toHaveProperty(\"structuredContent\");\n});\n\ntest(\"useCallTool returns correctly typed data\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { data } = useCallTool(\"search-trip\");\n\n if (data) {\n expectTypeOf(data.structuredContent).toExtend<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n expectTypeOf(data.structuredContent.results).toBeArray();\n expectTypeOf(data.structuredContent.totalCount).toBeNumber();\n }\n});\n\ntest(\"useCallTool returns correctly typed data for callback-inferred outputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n const { data: viewData } = useCallTool(\"inferred-output-view\");\n if (viewData) {\n expectTypeOf(viewData.structuredContent).toExtend<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n }\n\n const { data: toolData } = useCallTool(\"inferred-tool\");\n if (toolData) {\n expectTypeOf(toolData.structuredContent).toExtend<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n }\n});\n\ntest(\"generateHelpers provides autocomplete for tool names in useToolInfo (views + registerTool)\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n\n useToolInfo<\"search-trip\">();\n useToolInfo<\"get-trip-details\">();\n useToolInfo<\"no-input-view\">();\n useToolInfo<\"calculate-price\">();\n useToolInfo<\"inferred-output-view\">();\n useToolInfo<\"inferred-tool\">();\n useToolInfo<\"view-with-metadata\">();\n useToolInfo<\"tool-with-metadata\">();\n useToolInfo<\"view-with-mixed-returns\">();\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useToolInfo<\"invalid-name\">();\n});\n\ntest(\"useToolInfo infers input and output types\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n const toolInfo = useToolInfo<\"search-trip\">();\n\n // Input is optional in pending — host may not have delivered args yet\n if (toolInfo.status === \"pending\") {\n expectTypeOf(toolInfo.input).toExtend<\n ToolInput<TestServer, \"search-trip\"> | undefined\n >();\n }\n\n if (toolInfo.status === \"success\") {\n // Input is optional in success — the host may not have surfaced args yet\n expectTypeOf(toolInfo.input).toExtend<\n ToolInput<TestServer, \"search-trip\"> | undefined\n >();\n expectTypeOf(toolInfo.output).toExtend<\n ToolOutput<TestServer, \"search-trip\">\n >();\n expectTypeOf(toolInfo.output.results).toBeArray();\n expectTypeOf(toolInfo.output.totalCount).toBeNumber();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta type from callback\", () => {\n type ViewMeta = ToolResponseMetadata<TestServer, \"view-with-metadata\">;\n expectTypeOf<ViewMeta>().toEqualTypeOf<{\n requestId: string;\n timestamp: number;\n cached: boolean;\n }>();\n\n type ToolMeta = ToolResponseMetadata<TestServer, \"tool-with-metadata\">;\n expectTypeOf<ToolMeta>().toEqualTypeOf<{\n executionTime: number;\n source: string;\n }>();\n\n type SearchMeta = ToolResponseMetadata<TestServer, \"search-trip\">;\n expectTypeOf<SearchMeta>().toBeUnknown();\n});\n\ntest(\"useToolInfo infers responseMetadata type from generateHelpers\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n const toolInfo = useToolInfo<\"view-with-metadata\">();\n\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();\n expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta from mixed return paths\", () => {\n // View has multiple return paths: some with _meta, some without\n // ExtractMeta should still infer the _meta type from branches that have it\n type MixedMeta = ToolResponseMetadata<TestServer, \"view-with-mixed-returns\">;\n expectTypeOf<MixedMeta>().toEqualTypeOf<{\n processedAt: number;\n region: string;\n }>();\n});\n\ntest(\"ToolOutput extracts correct type when using interface declaration\", () => {\n type InterfaceViewOutput = ToolOutput<InterfaceTestServer, \"interface-view\">;\n\n expectTypeOf<InterfaceViewOutput>().toHaveProperty(\"itemName\");\n expectTypeOf<InterfaceViewOutput[\"itemName\"]>().toBeString();\n expectTypeOf<InterfaceViewOutput[\"quantity\"]>().toBeNumber();\n});\n\ntest(\"ToolResponseMetadata extracts correct type when using interface declaration\", () => {\n type InterfaceViewMeta = ToolResponseMetadata<\n InterfaceTestServer,\n \"interface-view\"\n >;\n\n expectTypeOf<InterfaceViewMeta>().toHaveProperty(\"processedBy\");\n expectTypeOf<InterfaceViewMeta[\"processedBy\"]>().toBeString();\n expectTypeOf<InterfaceViewMeta[\"version\"]>().toBeNumber();\n});\n\ntest(\"generateHelpers works with interface-typed server\", () => {\n const { useCallTool, useToolInfo } = generateHelpers<InterfaceTestServer>();\n\n const { data } = useCallTool(\"interface-view\");\n if (data) {\n expectTypeOf(data.structuredContent.itemName).toBeString();\n expectTypeOf(data.structuredContent.quantity).toBeNumber();\n }\n\n const toolInfo = useToolInfo<\"interface-view\">();\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.output.itemName).toBeString();\n expectTypeOf(toolInfo.output.quantity).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.processedBy).toBeString();\n expectTypeOf(toolInfo.responseMetadata.version).toBeNumber();\n }\n});\n"]}
1
+ {"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,eAAe,EAA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WAAW,EAAE,WAAW,EAAE,GAAG,eAAe,EAAoB,CAAC;IAEzE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAC/C,IAAI,IAAI,EAAE,CAAC;QACT,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QAC3D,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,EAAoB,CAAC;IACjD,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACvB,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type {\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"../server/index.js\";\nimport { createInterfaceTestApp, createTestApp } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst app = createTestApp();\ntype TestApp = typeof app;\n\nconst interfaceApp = createInterfaceTestApp();\ntype InterfaceTestApp = typeof interfaceApp;\n\ntest(\"InferTools extracts the tool registry type (views + registerTool)\", () => {\n type Tools = InferTools<TestApp>;\n\n expectTypeOf<Tools>().toHaveProperty(\"search-trip\");\n expectTypeOf<Tools>().toHaveProperty(\"get-trip-details\");\n expectTypeOf<Tools>().toHaveProperty(\"no-input-view\");\n expectTypeOf<Tools>().toHaveProperty(\"calculate-price\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-output-view\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-tool\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"tool-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-mixed-returns\");\n});\n\ntest(\"ToolNames returns a union of tool name literals (views + registerTool)\", () => {\n type Names = ToolNames<TestApp>;\n\n expectTypeOf<Names>().toEqualTypeOf<\n | \"search-trip\"\n | \"get-trip-details\"\n | \"no-input-view\"\n | \"calculate-price\"\n | \"inferred-output-view\"\n | \"inferred-tool\"\n | \"view-with-metadata\"\n | \"tool-with-metadata\"\n | \"view-with-mixed-returns\"\n >();\n});\n\ntest(\"ToolInput extracts the correct input type from Zod schema\", () => {\n type SearchInput = ToolInput<TestApp, \"search-trip\">;\n\n expectTypeOf<SearchInput>().toEqualTypeOf<{\n destination: string;\n departureDate?: string | undefined;\n maxPrice?: number | undefined;\n }>();\n\n type DetailsInput = ToolInput<TestApp, \"get-trip-details\">;\n\n expectTypeOf<DetailsInput>().toEqualTypeOf<{\n tripId: string;\n }>();\n\n type CalculateInput = ToolInput<TestApp, \"calculate-price\">;\n\n expectTypeOf<CalculateInput>().toEqualTypeOf<{\n tripId: string;\n passengers: number;\n }>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback's structuredContent\", () => {\n type SearchOutput = ToolOutput<TestApp, \"search-trip\">;\n\n expectTypeOf<SearchOutput>().toEqualTypeOf<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n type DetailsOutput = ToolOutput<TestApp, \"get-trip-details\">;\n\n expectTypeOf<DetailsOutput>().toEqualTypeOf<{\n name: string;\n description: string;\n images: string[];\n }>();\n\n // Note: outputSchema has totalPrice: z.string(), but callback returns number\n // Type is inferred from callback, so totalPrice is number\n type CalculateOutput = ToolOutput<TestApp, \"calculate-price\">;\n\n expectTypeOf<CalculateOutput>().toEqualTypeOf<{\n totalPrice: number;\n currency: string;\n }>();\n\n type NoInputOutput = ToolOutput<TestApp, \"no-input-view\">;\n expectTypeOf<NoInputOutput>().toEqualTypeOf<Record<never, unknown>>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback (inferred)\", () => {\n type InferredViewOutput = ToolOutput<TestApp, \"inferred-output-view\">;\n\n expectTypeOf<InferredViewOutput>().toEqualTypeOf<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n\n type InferredToolOutput = ToolOutput<TestApp, \"inferred-tool\">;\n\n expectTypeOf<InferredToolOutput>().toEqualTypeOf<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n});\n\ntest(\"generateHelpers provides autocomplete for tool names (views + registerTool)\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n\n useCallTool(\"search-trip\");\n useCallTool(\"get-trip-details\");\n useCallTool(\"no-input-view\");\n useCallTool(\"calculate-price\");\n useCallTool(\"inferred-output-view\");\n useCallTool(\"inferred-tool\");\n useCallTool(\"view-with-metadata\");\n useCallTool(\"tool-with-metadata\");\n useCallTool(\"view-with-mixed-returns\");\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useCallTool(\"invalid-name\");\n});\n\ntest(\"useCallTool returns correctly typed callTool function\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool({ destination: \"Spain\" });\n callTool({ destination: \"France\", departureDate: \"2024-06-01\" });\n callTool({ destination: \"Italy\", maxPrice: 1000 });\n\n const { callTool: calculateTool } = useCallTool(\"calculate-price\");\n calculateTool({ tripId: \"123\", passengers: 2 });\n});\n\ntest(\"callTool can be called without args for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { callTool, callToolAsync } = useCallTool(\"no-input-view\");\n\n callTool();\n\n callTool({});\n\n callToolAsync();\n callToolAsync({});\n});\n\ntest(\"callTool requires args for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { callTool } = useCallTool(\"search-trip\");\n\n // @ts-expect-error - \"destination\" is required\n callTool();\n\n // @ts-expect-error - \"destination\" is required\n callTool({});\n\n // This should work\n callTool({ destination: \"Spain\" });\n});\n\ntest(\"callTool supports sideEffects for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool(\n { destination: \"Spain\" },\n {\n onSuccess: (response, args) => {\n expectTypeOf(response.structuredContent.results).toBeArray();\n expectTypeOf(args.destination).toBeString();\n },\n onError: (error, args) => {\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n onSettled: (response, error, args) => {\n if (response) {\n expectTypeOf(response.structuredContent.totalCount).toBeNumber();\n }\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n },\n );\n});\n\ntest(\"callTool supports sideEffects for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { callTool } = useCallTool(\"no-input-view\");\n\n callTool({\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n });\n\n callTool(\n {},\n {\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n },\n );\n});\n\ntest(\"callToolAsync returns correctly typed promise\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n\n const { callToolAsync: searchAsync } = useCallTool(\"search-trip\");\n const searchPromise = searchAsync({ destination: \"Spain\" });\n expectTypeOf(searchPromise).resolves.toHaveProperty(\"structuredContent\");\n\n const { callToolAsync: noInputAsync } = useCallTool(\"no-input-view\");\n const noInputPromise = noInputAsync();\n expectTypeOf(noInputPromise).resolves.toHaveProperty(\"structuredContent\");\n});\n\ntest(\"useCallTool returns correctly typed data\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n const { data } = useCallTool(\"search-trip\");\n\n if (data) {\n expectTypeOf(data.structuredContent).toExtend<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n expectTypeOf(data.structuredContent.results).toBeArray();\n expectTypeOf(data.structuredContent.totalCount).toBeNumber();\n }\n});\n\ntest(\"useCallTool returns correctly typed data for callback-inferred outputs\", () => {\n const { useCallTool } = generateHelpers<TestApp>();\n\n const { data: viewData } = useCallTool(\"inferred-output-view\");\n if (viewData) {\n expectTypeOf(viewData.structuredContent).toExtend<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n }\n\n const { data: toolData } = useCallTool(\"inferred-tool\");\n if (toolData) {\n expectTypeOf(toolData.structuredContent).toExtend<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n }\n});\n\ntest(\"generateHelpers provides autocomplete for tool names in useToolInfo (views + registerTool)\", () => {\n const { useToolInfo } = generateHelpers<TestApp>();\n\n useToolInfo<\"search-trip\">();\n useToolInfo<\"get-trip-details\">();\n useToolInfo<\"no-input-view\">();\n useToolInfo<\"calculate-price\">();\n useToolInfo<\"inferred-output-view\">();\n useToolInfo<\"inferred-tool\">();\n useToolInfo<\"view-with-metadata\">();\n useToolInfo<\"tool-with-metadata\">();\n useToolInfo<\"view-with-mixed-returns\">();\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useToolInfo<\"invalid-name\">();\n});\n\ntest(\"useToolInfo infers input and output types\", () => {\n const { useToolInfo } = generateHelpers<TestApp>();\n const toolInfo = useToolInfo<\"search-trip\">();\n\n // Input is optional in pending — host may not have delivered args yet\n if (toolInfo.status === \"pending\") {\n expectTypeOf(toolInfo.input).toExtend<\n ToolInput<TestApp, \"search-trip\"> | undefined\n >();\n }\n\n if (toolInfo.status === \"success\") {\n // Input is optional in success — the host may not have surfaced args yet\n expectTypeOf(toolInfo.input).toExtend<\n ToolInput<TestApp, \"search-trip\"> | undefined\n >();\n expectTypeOf(toolInfo.output).toExtend<\n ToolOutput<TestApp, \"search-trip\">\n >();\n expectTypeOf(toolInfo.output.results).toBeArray();\n expectTypeOf(toolInfo.output.totalCount).toBeNumber();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta type from callback\", () => {\n type ViewMeta = ToolResponseMetadata<TestApp, \"view-with-metadata\">;\n expectTypeOf<ViewMeta>().toEqualTypeOf<{\n requestId: string;\n timestamp: number;\n cached: boolean;\n }>();\n\n type ToolMeta = ToolResponseMetadata<TestApp, \"tool-with-metadata\">;\n expectTypeOf<ToolMeta>().toEqualTypeOf<{\n executionTime: number;\n source: string;\n }>();\n\n type SearchMeta = ToolResponseMetadata<TestApp, \"search-trip\">;\n expectTypeOf<SearchMeta>().toBeUnknown();\n});\n\ntest(\"useToolInfo infers responseMetadata type from generateHelpers\", () => {\n const { useToolInfo } = generateHelpers<TestApp>();\n const toolInfo = useToolInfo<\"view-with-metadata\">();\n\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();\n expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta from mixed return paths\", () => {\n // View has multiple return paths: some with _meta, some without\n // ExtractMeta should still infer the _meta type from branches that have it\n type MixedMeta = ToolResponseMetadata<TestApp, \"view-with-mixed-returns\">;\n expectTypeOf<MixedMeta>().toEqualTypeOf<{\n processedAt: number;\n region: string;\n }>();\n});\n\ntest(\"ToolOutput extracts correct type when using interface declaration\", () => {\n type InterfaceViewOutput = ToolOutput<InterfaceTestApp, \"interface-view\">;\n\n expectTypeOf<InterfaceViewOutput>().toHaveProperty(\"itemName\");\n expectTypeOf<InterfaceViewOutput[\"itemName\"]>().toBeString();\n expectTypeOf<InterfaceViewOutput[\"quantity\"]>().toBeNumber();\n});\n\ntest(\"ToolResponseMetadata extracts correct type when using interface declaration\", () => {\n type InterfaceViewMeta = ToolResponseMetadata<\n InterfaceTestApp,\n \"interface-view\"\n >;\n\n expectTypeOf<InterfaceViewMeta>().toHaveProperty(\"processedBy\");\n expectTypeOf<InterfaceViewMeta[\"processedBy\"]>().toBeString();\n expectTypeOf<InterfaceViewMeta[\"version\"]>().toBeNumber();\n});\n\ntest(\"generateHelpers works with interface-typed server\", () => {\n const { useCallTool, useToolInfo } = generateHelpers<InterfaceTestApp>();\n\n const { data } = useCallTool(\"interface-view\");\n if (data) {\n expectTypeOf(data.structuredContent.itemName).toBeString();\n expectTypeOf(data.structuredContent.quantity).toBeNumber();\n }\n\n const toolInfo = useToolInfo<\"interface-view\">();\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.output.itemName).toBeString();\n expectTypeOf(toolInfo.output.quantity).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.processedBy).toBeString();\n expectTypeOf(toolInfo.responseMetadata.version).toBeNumber();\n }\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { createMinimalTestServer } from "../test/utils.js";
2
+ import { createMinimalTestApp } from "../test/utils.js";
3
3
  import { generateHelpers } from "./generate-helpers.js";
4
- const server = createMinimalTestServer();
4
+ const app = createMinimalTestApp();
5
5
  describe("generateHelpers", () => {
6
6
  it("should return an object with useCallTool hook", () => {
7
7
  const hooks = generateHelpers();
@@ -1 +1 @@
1
- {"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;AAGzC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { createMinimalTestServer } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst server = createMinimalTestServer();\ntype TestServer = typeof server;\n\ndescribe(\"generateHelpers\", () => {\n it(\"should return an object with useCallTool hook\", () => {\n const hooks = generateHelpers<TestServer>();\n expect(hooks).toHaveProperty(\"useCallTool\");\n expect(typeof hooks.useCallTool).toBe(\"function\");\n });\n\n it(\"should return an object with useToolInfo hook\", () => {\n const hooks = generateHelpers<TestServer>();\n expect(hooks).toHaveProperty(\"useToolInfo\");\n expect(typeof hooks.useToolInfo).toBe(\"function\");\n });\n});\n"]}
1
+ {"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;AAGnC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAW,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAW,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { createMinimalTestApp } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst app = createMinimalTestApp();\ntype TestApp = typeof app;\n\ndescribe(\"generateHelpers\", () => {\n it(\"should return an object with useCallTool hook\", () => {\n const hooks = generateHelpers<TestApp>();\n expect(hooks).toHaveProperty(\"useCallTool\");\n expect(typeof hooks.useCallTool).toBe(\"function\");\n });\n\n it(\"should return an object with useToolInfo hook\", () => {\n const hooks = generateHelpers<TestApp>();\n expect(hooks).toHaveProperty(\"useToolInfo\");\n expect(typeof hooks.useToolInfo).toBe(\"function\");\n });\n});\n"]}
@@ -1,9 +1,10 @@
1
1
  export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
2
+ export { useDeepLink } from "./use-deep-link.js";
2
3
  export { useDisplayMode } from "./use-display-mode.js";
3
4
  export { type DownloadFn, useDownload } from "./use-download.js";
4
5
  export { useFiles } from "./use-files.js";
5
- export { type Host, type HostInfo, useHostInfo } from "./use-host-info.js";
6
- export { type LayoutState, useLayout } from "./use-layout.js";
6
+ export { type Host, type HostInfo, type OpenAIHostCapabilities, useHost, } from "./use-host.js";
7
+ export { type ModelContextState, useModelContext, } from "./use-model-context.js";
7
8
  export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
8
9
  export { useRegisterViewTool } from "./use-register-view-tool.js";
9
10
  export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
@@ -14,3 +15,4 @@ export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
14
15
  export { useToolInfo } from "./use-tool-info.js";
15
16
  export { type UserState, useUser } from "./use-user.js";
16
17
  export { useViewState } from "./use-view-state.js";
18
+ export { useViewport, type ViewportState } from "./use-viewport.js";
@@ -1,9 +1,10 @@
1
1
  export { useCallTool, } from "./use-call-tool.js";
2
+ export { useDeepLink } from "./use-deep-link.js";
2
3
  export { useDisplayMode } from "./use-display-mode.js";
3
4
  export { useDownload } from "./use-download.js";
4
5
  export { useFiles } from "./use-files.js";
5
- export { useHostInfo } from "./use-host-info.js";
6
- export { useLayout } from "./use-layout.js";
6
+ export { useHost, } from "./use-host.js";
7
+ export { useModelContext, } from "./use-model-context.js";
7
8
  export { useOpenExternal } from "./use-open-external.js";
8
9
  export { useRegisterViewTool } from "./use-register-view-tool.js";
9
10
  export { useRequestClose } from "./use-request-close.js";
@@ -14,4 +15,5 @@ export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
14
15
  export { useToolInfo } from "./use-tool-info.js";
15
16
  export { useUser } from "./use-user.js";
16
17
  export { useViewState } from "./use-view-state.js";
18
+ export { useViewport } from "./use-viewport.js";
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAA4B,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type Host, type HostInfo, useHostInfo } from \"./use-host-info.js\";\nexport { type LayoutState, useLayout } from \"./use-layout.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { useRegisterViewTool } from \"./use-register-view-tool.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAIL,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDeepLink } from \"./use-deep-link.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport {\n type Host,\n type HostInfo,\n type OpenAIHostCapabilities,\n useHost,\n} from \"./use-host.js\";\nexport {\n type ModelContextState,\n useModelContext,\n} from \"./use-model-context.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { useRegisterViewTool } from \"./use-register-view-tool.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\nexport { useViewport, type ViewportState } from \"./use-viewport.js\";\n"]}
@@ -0,0 +1,104 @@
1
+ import { act, renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app/index.js";
5
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
6
+ import { useDeepLink } from "./use-deep-link.js";
7
+ import { useModelContext } from "./use-model-context.js";
8
+ import { useViewState } from "./use-view-state.js";
9
+ async function notifyHostContext(params) {
10
+ await act(async () => {
11
+ window.dispatchEvent(new MessageEvent("message", {
12
+ source: window.parent,
13
+ data: {
14
+ jsonrpc: "2.0",
15
+ method: "ui/notifications/host-context-changed",
16
+ params,
17
+ },
18
+ }));
19
+ });
20
+ }
21
+ describe("model context and deep links in the view", () => {
22
+ beforeEach(() => {
23
+ vi.stubGlobal("openai", undefined);
24
+ vi.stubGlobal("skybridge", {});
25
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
26
+ localStorage.clear();
27
+ });
28
+ afterEach(() => {
29
+ HostAdaptor.resetInstance();
30
+ McpAppBridge.resetInstance();
31
+ vi.unstubAllGlobals();
32
+ localStorage.clear();
33
+ });
34
+ it("merges model context with view state and drops it once the user removes it", async () => {
35
+ const postMessage = getMcpAppHostPostMessageMock({}, { hostCapabilities: { updateModelContext: {} } });
36
+ vi.stubGlobal("parent", { postMessage });
37
+ const { result } = renderHook(() => ({
38
+ model: useModelContext(),
39
+ view: useViewState({ tab: "a" }),
40
+ }));
41
+ await waitFor(() => expect(result.current.model.supported).toBe(true));
42
+ const content = [
43
+ {
44
+ type: "text",
45
+ text: "Selected ski",
46
+ _meta: { "openai/title": "Ski" },
47
+ },
48
+ ];
49
+ const lastModelContext = () => postMessage.mock.calls
50
+ .map(([message]) => message)
51
+ .filter((message) => message.method === "ui/update-model-context")
52
+ .at(-1)?.params;
53
+ await act(async () => result.current.model.update({
54
+ content,
55
+ structuredContent: { ski: 1, tab: "x" },
56
+ }));
57
+ await act(async () => result.current.view[1]({ tab: "b" }));
58
+ expect(lastModelContext()).toEqual({
59
+ structuredContent: { ski: 1, tab: "b" },
60
+ content: [
61
+ { type: "text", text: JSON.stringify({ tab: "b" }) },
62
+ ...content,
63
+ ],
64
+ });
65
+ await notifyHostContext({
66
+ "openai/modelContext": { updateId: "one", content },
67
+ });
68
+ expect(result.current.model.context).toEqual({ updateId: "one", content });
69
+ await notifyHostContext({ "openai/modelContext": null });
70
+ expect(result.current.model.context).toBeNull();
71
+ await act(async () => result.current.view[1]({ tab: "c" }));
72
+ expect(lastModelContext()).toEqual({
73
+ structuredContent: { tab: "c" },
74
+ content: [{ type: "text", text: JSON.stringify({ tab: "c" }) }],
75
+ });
76
+ });
77
+ it("rejects model context updates on hosts without the capability", async () => {
78
+ const postMessage = getMcpAppHostPostMessageMock();
79
+ vi.stubGlobal("parent", { postMessage });
80
+ const { result } = renderHook(useModelContext);
81
+ await expect(result.current.update({ content: [] })).rejects.toThrow("updateModelContext");
82
+ expect(result.current.supported).toBe(false);
83
+ expect(postMessage.mock.calls.some(([message]) => message.method === "ui/update-model-context")).toBe(false);
84
+ });
85
+ it("reads split legacy deep links and ignores malformed ones", async () => {
86
+ vi.stubGlobal("parent", {
87
+ postMessage: getMcpAppHostPostMessageMock({
88
+ "openai/deepLink": { url: "/parts?tag=bolt" },
89
+ }),
90
+ });
91
+ const { result } = renderHook(useDeepLink);
92
+ await waitFor(() => expect(result.current).toBe("/parts?tag=bolt"));
93
+ await notifyHostContext({
94
+ "openai/deepLink": {
95
+ path: ["parts", "a/b"],
96
+ query: [["tag", "hex bolt"]],
97
+ },
98
+ });
99
+ expect(result.current).toBe("/parts/a%2Fb?tag=hex+bolt");
100
+ await notifyHostContext({ "openai/deepLink": { url: "//evil.test" } });
101
+ expect(result.current).toBeUndefined();
102
+ });
103
+ });
104
+ //# sourceMappingURL=openai-extensions.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-extensions.test.js","sourceRoot":"","sources":["../../../src/web/hooks/openai-extensions.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,KAAK,UAAU,iBAAiB,CAAC,MAA+B;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from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDeepLink } from \"./use-deep-link.js\";\nimport { useModelContext } from \"./use-model-context.js\";\nimport { useViewState } from \"./use-view-state.js\";\n\nasync function notifyHostContext(params: Record<string, unknown>) {\n await act(async () => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params,\n },\n }),\n );\n });\n}\n\ndescribe(\"model context and deep links in the view\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n localStorage.clear();\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n localStorage.clear();\n });\n\n it(\"merges model context with view state and drops it once the user removes it\", async () => {\n const postMessage = getMcpAppHostPostMessageMock(\n {},\n { hostCapabilities: { updateModelContext: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage });\n const { result } = renderHook(() => ({\n model: useModelContext(),\n view: useViewState({ tab: \"a\" }),\n }));\n await waitFor(() => expect(result.current.model.supported).toBe(true));\n const content = [\n {\n type: \"text\" as const,\n text: \"Selected ski\",\n _meta: { \"openai/title\": \"Ski\" },\n },\n ];\n const lastModelContext = () =>\n postMessage.mock.calls\n .map(([message]) => message as { method: string; params?: unknown })\n .filter((message) => message.method === \"ui/update-model-context\")\n .at(-1)?.params;\n\n await act(async () =>\n result.current.model.update({\n content,\n structuredContent: { ski: 1, tab: \"x\" },\n }),\n );\n await act(async () => result.current.view[1]({ tab: \"b\" }));\n expect(lastModelContext()).toEqual({\n structuredContent: { ski: 1, tab: \"b\" },\n content: [\n { type: \"text\", text: JSON.stringify({ tab: \"b\" }) },\n ...content,\n ],\n });\n\n await notifyHostContext({\n \"openai/modelContext\": { updateId: \"one\", content },\n });\n expect(result.current.model.context).toEqual({ updateId: \"one\", content });\n await notifyHostContext({ \"openai/modelContext\": null });\n expect(result.current.model.context).toBeNull();\n\n await act(async () => result.current.view[1]({ tab: \"c\" }));\n expect(lastModelContext()).toEqual({\n structuredContent: { tab: \"c\" },\n content: [{ type: \"text\", text: JSON.stringify({ tab: \"c\" }) }],\n });\n });\n\n it(\"rejects model context updates on hosts without the capability\", async () => {\n const postMessage = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage });\n const { result } = renderHook(useModelContext);\n\n await expect(result.current.update({ content: [] })).rejects.toThrow(\n \"updateModelContext\",\n );\n expect(result.current.supported).toBe(false);\n expect(\n postMessage.mock.calls.some(\n ([message]) => message.method === \"ui/update-model-context\",\n ),\n ).toBe(false);\n });\n\n it(\"reads split legacy deep links and ignores malformed ones\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n \"openai/deepLink\": { url: \"/parts?tag=bolt\" },\n }),\n });\n const { result } = renderHook(useDeepLink);\n await waitFor(() => expect(result.current).toBe(\"/parts?tag=bolt\"));\n\n await notifyHostContext({\n \"openai/deepLink\": {\n path: [\"parts\", \"a/b\"],\n query: [[\"tag\", \"hex bolt\"]],\n },\n });\n expect(result.current).toBe(\"/parts/a%2Fb?tag=hex+bolt\");\n\n await notifyHostContext({ \"openai/deepLink\": { url: \"//evil.test\" } });\n expect(result.current).toBeUndefined();\n });\n});\n"]}
@@ -1,4 +1,4 @@
1
- import { type CallToolArgs, type CallToolResponse } from "../bridges/index.js";
1
+ import { type CallToolArgs, type CallToolOptions, type CallToolResponse } from "../bridges/index.js";
2
2
  import type { HasRequiredKeys } from "../types.js";
3
3
  type CallToolIdleState = {
4
4
  status: "idle";
@@ -102,7 +102,7 @@ type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta"
102
102
  *
103
103
  * @see https://docs.skybridge.tech/api-reference/use-call-tool
104
104
  */
105
- export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
105
+ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string, options?: CallToolOptions) => {
106
106
  callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
107
107
  callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
108
108
  status: "idle";
@@ -1,4 +1,4 @@
1
- import { useRef, useState } from "react";
1
+ import { useCallback, useRef, useState } from "react";
2
2
  import { getAdaptor, } from "../bridges/index.js";
3
3
  /**
4
4
  * Call a server tool from a view and track its execution state.
@@ -28,15 +28,20 @@ import { getAdaptor, } from "../bridges/index.js";
28
28
  *
29
29
  * @see https://docs.skybridge.tech/api-reference/use-call-tool
30
30
  */
31
- export const useCallTool = (name) => {
31
+ export const useCallTool = (name, options) => {
32
32
  const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
33
33
  const callIdRef = useRef(0);
34
34
  const adaptor = getAdaptor();
35
- const execute = async (toolArgs) => {
35
+ const timeout = options?.timeout;
36
+ const execute = useCallback(async (toolArgs) => {
36
37
  const callId = ++callIdRef.current;
37
- setCallToolState({ status: "pending", data: undefined, error: undefined });
38
+ setCallToolState({
39
+ status: "pending",
40
+ data: undefined,
41
+ error: undefined,
42
+ });
38
43
  try {
39
- const data = await adaptor.callTool(name, toolArgs);
44
+ const data = await adaptor.callTool(name, toolArgs, ...(timeout === undefined ? [] : [{ timeout }]));
40
45
  if (callId === callIdRef.current) {
41
46
  setCallToolState({ status: "success", data, error: undefined });
42
47
  }
@@ -48,14 +53,14 @@ export const useCallTool = (name) => {
48
53
  }
49
54
  throw error;
50
55
  }
51
- };
52
- const callToolAsync = ((toolArgs) => {
56
+ }, [adaptor, name, timeout]);
57
+ const callToolAsync = useCallback((toolArgs) => {
53
58
  if (toolArgs === undefined) {
54
59
  return execute(null);
55
60
  }
56
61
  return execute(toolArgs);
57
- });
58
- const callTool = ((firstArg, sideEffects) => {
62
+ }, [execute]);
63
+ const callTool = useCallback((firstArg, sideEffects) => {
59
64
  let toolArgs;
60
65
  if (firstArg &&
61
66
  typeof firstArg === "object" &&
@@ -77,7 +82,7 @@ export const useCallTool = (name) => {
77
82
  sideEffects?.onError?.(error, toolArgs);
78
83
  sideEffects?.onSettled?.(undefined, error, toolArgs);
79
84
  });
80
- });
85
+ }, [execute]);
81
86
  const callToolState = {
82
87
  status,
83
88
  data,