@apollo/client-ai-apps 0.6.4 → 0.7.0

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 (272) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/CONTRIBUTING.md +195 -0
  3. package/README.md +74 -0
  4. package/dist/core/AbstractApolloClient.d.ts +33 -0
  5. package/dist/core/AbstractApolloClient.d.ts.map +1 -0
  6. package/dist/core/AbstractApolloClient.js +129 -0
  7. package/dist/core/AbstractApolloClient.js.map +1 -0
  8. package/dist/core/ApolloClient.d.ts +3 -7
  9. package/dist/core/ApolloClient.d.ts.map +1 -1
  10. package/dist/core/ApolloClient.js +5 -4
  11. package/dist/core/ApolloClient.js.map +1 -1
  12. package/dist/core/McpAppManager.d.ts +42 -0
  13. package/dist/core/McpAppManager.d.ts.map +1 -0
  14. package/dist/core/McpAppManager.js +56 -0
  15. package/dist/core/McpAppManager.js.map +1 -0
  16. package/dist/core/typeRegistration.d.ts +0 -14
  17. package/dist/core/typeRegistration.d.ts.map +1 -1
  18. package/dist/core/typeRegistration.js.map +1 -1
  19. package/dist/core/types.d.ts +2 -1
  20. package/dist/core/types.d.ts.map +1 -1
  21. package/dist/core/types.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mcp.d.ts +0 -1
  26. package/dist/index.mcp.d.ts.map +1 -1
  27. package/dist/index.mcp.js +0 -1
  28. package/dist/index.mcp.js.map +1 -1
  29. package/dist/index.openai.d.ts +0 -1
  30. package/dist/index.openai.d.ts.map +1 -1
  31. package/dist/index.openai.js +0 -1
  32. package/dist/index.openai.js.map +1 -1
  33. package/dist/link/ToolCallLink.d.ts +6 -1
  34. package/dist/link/ToolCallLink.d.ts.map +1 -1
  35. package/dist/link/ToolCallLink.js +17 -4
  36. package/dist/link/ToolCallLink.js.map +1 -1
  37. package/dist/link/ToolHydrationLink.d.ts +21 -0
  38. package/dist/link/ToolHydrationLink.d.ts.map +1 -0
  39. package/dist/link/ToolHydrationLink.js +57 -0
  40. package/dist/link/ToolHydrationLink.js.map +1 -0
  41. package/dist/mcp/core/ApolloClient.d.ts +3 -20
  42. package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
  43. package/dist/mcp/core/ApolloClient.js +20 -98
  44. package/dist/mcp/core/ApolloClient.js.map +1 -1
  45. package/dist/mcp/index.d.ts +0 -1
  46. package/dist/mcp/index.d.ts.map +1 -1
  47. package/dist/mcp/index.js +0 -1
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/openai/core/ApolloClient.d.ts +3 -20
  50. package/dist/openai/core/ApolloClient.d.ts.map +1 -1
  51. package/dist/openai/core/ApolloClient.js +36 -98
  52. package/dist/openai/core/ApolloClient.js.map +1 -1
  53. package/dist/openai/index.d.ts +0 -1
  54. package/dist/openai/index.d.ts.map +1 -1
  55. package/dist/openai/index.js +0 -1
  56. package/dist/openai/index.js.map +1 -1
  57. package/dist/openai/react/index.d.ts +0 -7
  58. package/dist/openai/react/index.d.ts.map +1 -1
  59. package/dist/openai/react/index.js +0 -7
  60. package/dist/openai/react/index.js.map +1 -1
  61. package/dist/react/ApolloProvider.d.ts.map +1 -1
  62. package/dist/react/ApolloProvider.js +1 -1
  63. package/dist/react/ApolloProvider.js.map +1 -1
  64. package/dist/{mcp/react/hooks → react}/createHydrationUtils.d.ts +1 -1
  65. package/dist/react/createHydrationUtils.d.ts.map +1 -0
  66. package/dist/{mcp/react/hooks → react}/createHydrationUtils.js +7 -9
  67. package/dist/react/createHydrationUtils.js.map +1 -0
  68. package/dist/react/hooks/internal/useApolloClient.d.ts +3 -0
  69. package/dist/react/hooks/internal/useApolloClient.d.ts.map +1 -0
  70. package/dist/{mcp/react/hooks → react/hooks/internal}/useApolloClient.js +3 -3
  71. package/dist/react/hooks/internal/useApolloClient.js.map +1 -0
  72. package/dist/react/hooks/useApp.d.ts.map +1 -0
  73. package/dist/react/hooks/useApp.js +5 -0
  74. package/dist/react/hooks/useApp.js.map +1 -0
  75. package/dist/react/hooks/useHostContext.d.ts.map +1 -0
  76. package/dist/{openai/react → react}/hooks/useHostContext.js +1 -1
  77. package/dist/react/hooks/useHostContext.js.map +1 -0
  78. package/dist/react/hooks/useToolInfo.d.ts +3 -0
  79. package/dist/react/hooks/useToolInfo.d.ts.map +1 -0
  80. package/dist/react/hooks/useToolInfo.js +5 -0
  81. package/dist/react/hooks/useToolInfo.js.map +1 -0
  82. package/dist/react/hooks/useToolMetadata.d.ts +2 -0
  83. package/dist/react/hooks/useToolMetadata.d.ts.map +1 -0
  84. package/dist/react/hooks/useToolMetadata.js +5 -0
  85. package/dist/react/hooks/useToolMetadata.js.map +1 -0
  86. package/dist/react/index.d.ts +5 -16
  87. package/dist/react/index.d.ts.map +1 -1
  88. package/dist/react/index.js +5 -19
  89. package/dist/react/index.js.map +1 -1
  90. package/dist/types/application-manifest.d.ts +1 -0
  91. package/dist/types/application-manifest.d.ts.map +1 -1
  92. package/dist/types/application-manifest.js.map +1 -1
  93. package/dist/utilities/connectToHost.d.ts +3 -0
  94. package/dist/utilities/connectToHost.d.ts.map +1 -0
  95. package/dist/utilities/connectToHost.js +11 -0
  96. package/dist/utilities/connectToHost.js.map +1 -0
  97. package/dist/utilities/index.d.ts +1 -0
  98. package/dist/utilities/index.d.ts.map +1 -1
  99. package/dist/utilities/index.js +1 -0
  100. package/dist/utilities/index.js.map +1 -1
  101. package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
  102. package/dist/vite/apolloClientAiApps.js +2 -0
  103. package/dist/vite/apolloClientAiApps.js.map +1 -1
  104. package/package.json +5 -22
  105. package/src/core/AbstractApolloClient.ts +217 -0
  106. package/src/core/ApolloClient.ts +8 -10
  107. package/src/core/McpAppManager.ts +106 -0
  108. package/src/core/typeRegistration.ts +0 -15
  109. package/src/core/types.ts +2 -1
  110. package/src/index.mcp.ts +0 -1
  111. package/src/index.openai.ts +0 -1
  112. package/src/index.ts +1 -6
  113. package/src/link/ToolCallLink.ts +27 -5
  114. package/src/link/ToolHydrationLink.ts +90 -0
  115. package/src/link/__tests__/ToolCallLink.test.ts +99 -0
  116. package/src/mcp/core/ApolloClient.ts +32 -165
  117. package/src/mcp/core/__tests__/ApolloClient.test.ts +571 -71
  118. package/src/mcp/index.ts +0 -1
  119. package/src/openai/core/ApolloClient.ts +48 -161
  120. package/src/openai/core/__tests__/ApolloClient.test.ts +916 -118
  121. package/src/openai/index.ts +0 -1
  122. package/src/openai/react/index.ts +0 -7
  123. package/src/react/ApolloProvider.tsx +1 -6
  124. package/src/react/__tests__/ApolloProvider/mcp.test.tsx +66 -29
  125. package/src/react/__tests__/ApolloProvider/openai.test.tsx +16 -41
  126. package/src/react/__tests__/createHydrationUtils.test.tsx +1260 -0
  127. package/src/{mcp/react/hooks → react}/createHydrationUtils.ts +7 -10
  128. package/src/react/hooks/__tests__/useApp.test.tsx +46 -0
  129. package/src/react/hooks/__tests__/useHostContext.test.tsx +99 -0
  130. package/src/react/hooks/__tests__/useToolInfo.test.tsx +98 -0
  131. package/src/react/hooks/__tests__/useToolMetadata.test.tsx +58 -0
  132. package/src/{mcp/react/hooks → react/hooks/internal}/useApolloClient.ts +3 -3
  133. package/src/{mcp/react → react}/hooks/useApp.ts +1 -1
  134. package/src/{openai/react → react}/hooks/useHostContext.ts +1 -1
  135. package/src/react/hooks/useToolInfo.ts +6 -0
  136. package/src/react/hooks/useToolMetadata.ts +5 -0
  137. package/src/react/index.ts +5 -36
  138. package/src/testing/internal/graphql/parseManifestOperation.ts +87 -0
  139. package/src/testing/internal/index.ts +3 -0
  140. package/src/testing/internal/matchers/index.ts +1 -0
  141. package/src/testing/internal/matchers/toEmitAnything.ts +43 -0
  142. package/src/testing/internal/matchers/types.ts +1 -0
  143. package/src/testing/internal/mcp/mockMcpHost.ts +25 -4
  144. package/src/testing/internal/tests/eachHostEnv.ts +22 -0
  145. package/src/testing/internal/utilities/createHostEnv.ts +117 -0
  146. package/src/types/application-manifest.ts +1 -0
  147. package/src/utilities/connectToHost.ts +13 -0
  148. package/src/utilities/index.ts +1 -0
  149. package/src/vite/__tests__/apolloClientAiApps.test.ts +56 -0
  150. package/src/vite/apolloClientAiApps.ts +5 -0
  151. package/tsconfig.vite.json +1 -1
  152. package/vitest.config.ts +13 -0
  153. package/dist/mcp/core/McpAppManager.d.ts +0 -30
  154. package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
  155. package/dist/mcp/core/McpAppManager.js +0 -82
  156. package/dist/mcp/core/McpAppManager.js.map +0 -1
  157. package/dist/mcp/link/ToolCallLink.d.ts +0 -28
  158. package/dist/mcp/link/ToolCallLink.d.ts.map +0 -1
  159. package/dist/mcp/link/ToolCallLink.js +0 -35
  160. package/dist/mcp/link/ToolCallLink.js.map +0 -1
  161. package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +0 -1
  162. package/dist/mcp/react/hooks/createHydrationUtils.js.map +0 -1
  163. package/dist/mcp/react/hooks/useApolloClient.d.ts +0 -3
  164. package/dist/mcp/react/hooks/useApolloClient.d.ts.map +0 -1
  165. package/dist/mcp/react/hooks/useApolloClient.js.map +0 -1
  166. package/dist/mcp/react/hooks/useApp.d.ts.map +0 -1
  167. package/dist/mcp/react/hooks/useApp.js +0 -5
  168. package/dist/mcp/react/hooks/useApp.js.map +0 -1
  169. package/dist/mcp/react/hooks/useHostContext.d.ts.map +0 -1
  170. package/dist/mcp/react/hooks/useHostContext.js +0 -7
  171. package/dist/mcp/react/hooks/useHostContext.js.map +0 -1
  172. package/dist/mcp/react/hooks/useToolInfo.d.ts +0 -3
  173. package/dist/mcp/react/hooks/useToolInfo.d.ts.map +0 -1
  174. package/dist/mcp/react/hooks/useToolInfo.js +0 -10
  175. package/dist/mcp/react/hooks/useToolInfo.js.map +0 -1
  176. package/dist/mcp/react/hooks/useToolInput.d.ts +0 -7
  177. package/dist/mcp/react/hooks/useToolInput.d.ts.map +0 -1
  178. package/dist/mcp/react/hooks/useToolInput.js +0 -9
  179. package/dist/mcp/react/hooks/useToolInput.js.map +0 -1
  180. package/dist/mcp/react/hooks/useToolMetadata.d.ts +0 -2
  181. package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +0 -1
  182. package/dist/mcp/react/hooks/useToolMetadata.js +0 -5
  183. package/dist/mcp/react/hooks/useToolMetadata.js.map +0 -1
  184. package/dist/mcp/react/hooks/useToolName.d.ts +0 -7
  185. package/dist/mcp/react/hooks/useToolName.d.ts.map +0 -1
  186. package/dist/mcp/react/hooks/useToolName.js +0 -9
  187. package/dist/mcp/react/hooks/useToolName.js.map +0 -1
  188. package/dist/mcp/react/index.d.ts +0 -8
  189. package/dist/mcp/react/index.d.ts.map +0 -1
  190. package/dist/mcp/react/index.js +0 -8
  191. package/dist/mcp/react/index.js.map +0 -1
  192. package/dist/openai/core/McpAppManager.d.ts +0 -29
  193. package/dist/openai/core/McpAppManager.d.ts.map +0 -1
  194. package/dist/openai/core/McpAppManager.js +0 -91
  195. package/dist/openai/core/McpAppManager.js.map +0 -1
  196. package/dist/openai/link/ToolCallLink.d.ts +0 -28
  197. package/dist/openai/link/ToolCallLink.d.ts.map +0 -1
  198. package/dist/openai/link/ToolCallLink.js +0 -35
  199. package/dist/openai/link/ToolCallLink.js.map +0 -1
  200. package/dist/openai/react/hooks/createHydrationUtils.d.ts +0 -15
  201. package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +0 -1
  202. package/dist/openai/react/hooks/createHydrationUtils.js +0 -113
  203. package/dist/openai/react/hooks/createHydrationUtils.js.map +0 -1
  204. package/dist/openai/react/hooks/useApp.d.ts +0 -2
  205. package/dist/openai/react/hooks/useApp.d.ts.map +0 -1
  206. package/dist/openai/react/hooks/useApp.js +0 -5
  207. package/dist/openai/react/hooks/useApp.js.map +0 -1
  208. package/dist/openai/react/hooks/useHostContext.d.ts +0 -2
  209. package/dist/openai/react/hooks/useHostContext.d.ts.map +0 -1
  210. package/dist/openai/react/hooks/useHostContext.js.map +0 -1
  211. package/dist/openai/react/hooks/useToolInfo.d.ts +0 -3
  212. package/dist/openai/react/hooks/useToolInfo.d.ts.map +0 -1
  213. package/dist/openai/react/hooks/useToolInfo.js +0 -10
  214. package/dist/openai/react/hooks/useToolInfo.js.map +0 -1
  215. package/dist/openai/react/hooks/useToolInput.d.ts +0 -7
  216. package/dist/openai/react/hooks/useToolInput.d.ts.map +0 -1
  217. package/dist/openai/react/hooks/useToolInput.js +0 -9
  218. package/dist/openai/react/hooks/useToolInput.js.map +0 -1
  219. package/dist/openai/react/hooks/useToolMetadata.d.ts +0 -2
  220. package/dist/openai/react/hooks/useToolMetadata.d.ts.map +0 -1
  221. package/dist/openai/react/hooks/useToolMetadata.js +0 -5
  222. package/dist/openai/react/hooks/useToolMetadata.js.map +0 -1
  223. package/dist/openai/react/hooks/useToolName.d.ts +0 -7
  224. package/dist/openai/react/hooks/useToolName.d.ts.map +0 -1
  225. package/dist/openai/react/hooks/useToolName.js +0 -9
  226. package/dist/openai/react/hooks/useToolName.js.map +0 -1
  227. package/dist/react/index.mcp.d.ts +0 -3
  228. package/dist/react/index.mcp.d.ts.map +0 -1
  229. package/dist/react/index.mcp.js +0 -3
  230. package/dist/react/index.mcp.js.map +0 -1
  231. package/dist/react/index.openai.d.ts +0 -3
  232. package/dist/react/index.openai.d.ts.map +0 -1
  233. package/dist/react/index.openai.js +0 -3
  234. package/dist/react/index.openai.js.map +0 -1
  235. package/dist/react/missingHook.d.ts +0 -2
  236. package/dist/react/missingHook.d.ts.map +0 -1
  237. package/dist/react/missingHook.js +0 -6
  238. package/dist/react/missingHook.js.map +0 -1
  239. package/src/mcp/core/McpAppManager.ts +0 -129
  240. package/src/mcp/link/ToolCallLink.ts +0 -40
  241. package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -62
  242. package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1228
  243. package/src/mcp/react/hooks/__tests__/useApp.test.tsx +0 -46
  244. package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +0 -95
  245. package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +0 -53
  246. package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +0 -50
  247. package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +0 -53
  248. package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +0 -50
  249. package/src/mcp/react/hooks/useHostContext.ts +0 -14
  250. package/src/mcp/react/hooks/useToolInfo.ts +0 -13
  251. package/src/mcp/react/hooks/useToolInput.ts +0 -10
  252. package/src/mcp/react/hooks/useToolMetadata.ts +0 -5
  253. package/src/mcp/react/hooks/useToolName.ts +0 -10
  254. package/src/mcp/react/index.ts +0 -7
  255. package/src/openai/core/McpAppManager.ts +0 -139
  256. package/src/openai/link/ToolCallLink.ts +0 -40
  257. package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1333
  258. package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +0 -92
  259. package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +0 -85
  260. package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +0 -86
  261. package/src/openai/react/hooks/__tests__/useToolName.test.tsx +0 -50
  262. package/src/openai/react/hooks/createHydrationUtils.ts +0 -182
  263. package/src/openai/react/hooks/useApp.ts +0 -5
  264. package/src/openai/react/hooks/useToolInfo.ts +0 -13
  265. package/src/openai/react/hooks/useToolInput.ts +0 -10
  266. package/src/openai/react/hooks/useToolMetadata.ts +0 -5
  267. package/src/openai/react/hooks/useToolName.ts +0 -10
  268. package/src/react/index.mcp.ts +0 -10
  269. package/src/react/index.openai.ts +0 -10
  270. package/src/react/missingHook.ts +0 -9
  271. /package/dist/{mcp/react → react}/hooks/useApp.d.ts +0 -0
  272. /package/dist/{mcp/react → react}/hooks/useHostContext.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YA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AI,KAAK,QAAQ,CAAC,EAAE,CAAC;gBAC3D,IAAI,CAAC,UAAU,CAAC;oBACd,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;oBAC5B,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,qCAAqC,CAAC,SAAS,EAAE,IAAI,CAAC;iBAClE,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,uBAAuB,CAAC,IAAgB;IAC/C,IAAI,eAAe,GAAG,IAAI,CAAC;IAE3B,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,eAAe,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,CAAC;IAED,IACE,CAAC,WAAW,CAAC,eAAe,CAAC;QAC7B,eAAe,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import {\n ApolloLink,\n ApolloClient as BaseApolloClient,\n DocumentTransform,\n} from \"@apollo/client\";\nimport type {\n WatchQueryOptions,\n ObservableQuery,\n OperationVariables,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse, visit } from \"graphql\";\nimport { equal } from \"@wry/equality\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type { ApplicationManifest } from \"../../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n aiClientSymbol,\n cacheAsync,\n getToolNamesFromDocument,\n getVariableNamesFromDocument,\n getVariablesForOperationFromToolInput,\n warnOnVariableMismatch,\n} from \"../../utilities/index.js\";\nimport { McpAppManager } from \"./McpAppManager.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n #toolInput: Record<string, unknown> | undefined;\n\n constructor(options: ApolloClient.Options) {\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link,\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n const serverDocument = removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n\n return visit(serverDocument, {\n OperationDefinition(node) {\n return { ...node, description: undefined };\n },\n });\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest);\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n clearToolInput() {\n this.#toolInput = undefined;\n }\n\n watchQuery<\n T = any,\n TVariables extends OperationVariables = OperationVariables,\n >(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {\n if (__DEV__) {\n const toolInput = this.#toolInput;\n\n if (toolInput) {\n const toolName = this.appManager.toolName;\n const hasMatchingTool =\n !!toolName && getToolNamesFromDocument(options.query).has(toolName);\n\n if (hasMatchingTool) {\n // Clear after first matching comparison so this only fires once and\n // remounting doesn't produce spurious warnings.\n this.#toolInput = undefined;\n\n const variableNames = getVariableNamesFromDocument(options.query);\n\n if (variableNames.size > 0) {\n const { variables } = options;\n const toolInputVariables = Object.entries(toolInput).filter(\n ([key]) => variableNames.has(key)\n );\n\n const hasToolInputMismatch = toolInputVariables.some(\n ([key, value]) => !equal(value, variables?.[key])\n );\n\n if (hasToolInputMismatch) {\n warnOnVariableMismatch(\n options.query,\n Object.fromEntries(toolInputVariables),\n variables\n );\n }\n }\n }\n }\n }\n\n return super.watchQuery(options);\n }\n\n connect = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.connect();\n\n this.#toolInput = args;\n\n this.manifest.operations.forEach((operation) => {\n if (operation.prefetchID && prefetch?.[operation.prefetchID]) {\n this.writeQuery({\n query: parse(operation.body),\n data: prefetch[operation.prefetchID].data,\n });\n }\n\n if (operation.tools.find((tool) => tool.name === toolName)) {\n this.writeQuery({\n query: parse(operation.body),\n data: result.data,\n variables: getVariablesForOperationFromToolInput(operation, args),\n });\n }\n });\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAO/E,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IACpD,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,UAAU,GACd,oBAAoB,EAAsC,CAAC;YAC7D,MAAM,SAAS,GACb,oBAAoB,EAAqC,CAAC;YAE5D,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC5B,UAAU,CAAC,OAAO,CAChB,MAAuD,CACxD,CAAC;YACJ,CAAC,CAAC;YAEF,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC3B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC,CAAC;YAEF,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YAEzB,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9D,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC;YAEpD,OAAO;gBACL,iBAAiB;gBACjB,SAAS,EAAE,IAAI;gBACf,KAAK;aACN,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { App } from \"@modelcontextprotocol/ext-apps\";\nimport { AbstractApolloClient } from \"../../core/AbstractApolloClient.js\";\nimport { connectToHost, promiseWithResolvers } from \"../../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"../../core/types.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends AbstractApolloClient.Options {}\n}\n\nexport class ApolloClient extends AbstractApolloClient {\n constructor(options: ApolloClient.Options) {\n super(options, async (app) => {\n const toolResult =\n promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n const toolInput =\n promiseWithResolvers<Parameters<App[\"ontoolinput\"]>[0]>();\n\n app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n app.ontoolinput = (params) => {\n toolInput.resolve(params);\n };\n\n await connectToHost(app);\n\n const { structuredContent, _meta } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n return {\n structuredContent,\n toolInput: args,\n _meta,\n };\n });\n }\n}\n"]}
@@ -1,3 +1,2 @@
1
1
  export { ApolloClient } from "./core/ApolloClient.js";
2
- export { ToolCallLink } from "./link/ToolCallLink.js";
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/mcp/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export { ApolloClient } from "./core/ApolloClient.js";
2
- export { ToolCallLink } from "./link/ToolCallLink.js";
3
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\n"]}
@@ -1,26 +1,9 @@
1
- import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
- import type { WatchQueryOptions, ObservableQuery, OperationVariables } from "@apollo/client";
3
- import type { ApplicationManifest } from "../../types/application-manifest.js";
4
- import { aiClientSymbol } from "../../utilities/index.js";
1
+ import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
5
2
  export declare namespace ApolloClient {
6
- interface Options extends Omit<BaseApolloClient.Options, "link"> {
7
- link?: BaseApolloClient.Options["link"];
8
- manifest: ApplicationManifest;
3
+ interface Options extends AbstractApolloClient.Options {
9
4
  }
10
5
  }
11
- export declare class ApolloClient extends BaseApolloClient {
12
- #private;
13
- manifest: ApplicationManifest;
14
- private readonly appManager;
15
- /** @internal */
16
- readonly [aiClientSymbol] = true;
6
+ export declare class ApolloClient extends AbstractApolloClient {
17
7
  constructor(options: ApolloClient.Options);
18
- stop(): void;
19
- get toolInput(): Record<string, unknown> | undefined;
20
- clearToolInput(): void;
21
- watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
22
- connect: (() => Promise<void>) & {
23
- reset: () => void;
24
- };
25
8
  }
26
9
  //# sourceMappingURL=ApolloClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAKf,MAAM,0BAA0B,CAAC;AAIlC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;;IAChD,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAIrB,OAAO,EAAE,YAAY,CAAC,OAAO;IA6BzC,IAAI;IAKJ,IAAI,SAAS,wCAEZ;IAED,cAAc;IAId,UAAU,CACR,CAAC,GAAG,GAAG,EACP,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,OAAO,EAAE,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;IA0C5E,OAAO;;MAsBJ;CACJ"}
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAI1E,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,oBAAoB,CAAC,OAAO;KAAG;CACjE;AAED,qBAAa,YAAa,SAAQ,oBAAoB;gBACxC,OAAO,EAAE,YAAY,CAAC,OAAO;CAiD1C"}
@@ -1,105 +1,43 @@
1
- import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
- import { DocumentTransform } from "@apollo/client";
3
- import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
4
- import { parse, visit } from "graphql";
5
- import { equal } from "@wry/equality";
6
- import { __DEV__ } from "@apollo/client/utilities/environment";
7
- import { ToolCallLink } from "../link/ToolCallLink.js";
8
- import { aiClientSymbol, cacheAsync, getToolNamesFromDocument, getVariablesForOperationFromToolInput, warnOnVariableMismatch, } from "../../utilities/index.js";
9
- import { McpAppManager } from "./McpAppManager.js";
10
- import { getVariableNamesFromDocument } from "../../utilities/getVariableNamesFromDocument.js";
11
- export class ApolloClient extends BaseApolloClient {
12
- manifest;
13
- appManager;
14
- /** @internal */
15
- [aiClientSymbol] = true;
16
- #toolInput;
1
+ import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
2
+ import { connectToHost, promiseWithResolvers } from "../../utilities/index.js";
3
+ export class ApolloClient extends AbstractApolloClient {
17
4
  constructor(options) {
18
- const link = options.link ?? new ToolCallLink();
19
- if (__DEV__) {
20
- validateTerminatingLink(link);
21
- }
22
- super({
23
- ...options,
24
- link,
25
- // Strip out the prefetch/tool directives so they don't get sent with the operation to the server
26
- documentTransform: new DocumentTransform((document) => {
27
- const serverDocument = removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
28
- return visit(serverDocument, {
29
- OperationDefinition(node) {
30
- return { ...node, description: undefined };
31
- },
32
- });
33
- }).concat(options.documentTransform ?? DocumentTransform.identity()),
34
- });
35
- this.manifest = options.manifest;
36
- this.appManager = new McpAppManager(this.manifest);
37
- }
38
- stop() {
39
- super.stop();
40
- this.appManager.close().catch(() => { });
41
- }
42
- get toolInput() {
43
- return this.#toolInput;
44
- }
45
- clearToolInput() {
46
- this.#toolInput = undefined;
47
- }
48
- watchQuery(options) {
49
- if (__DEV__) {
50
- const toolInput = this.#toolInput;
51
- if (toolInput) {
52
- const toolName = this.appManager.toolName;
53
- const hasMatchingTool = !!toolName && getToolNamesFromDocument(options.query).has(toolName);
54
- if (hasMatchingTool) {
55
- // Clear after first matching comparison so this only fires once and
56
- // remounting doesn't produce spurious warnings.
57
- this.#toolInput = undefined;
58
- const variableNames = getVariableNamesFromDocument(options.query);
59
- if (variableNames.size > 0) {
60
- const { variables } = options;
61
- const toolInputVariables = Object.entries(toolInput).filter(([key]) => variableNames.has(key));
62
- const hasToolInputMismatch = toolInputVariables.some(([key, value]) => !equal(value, variables?.[key]));
63
- if (hasToolInputMismatch) {
64
- warnOnVariableMismatch(options.query, Object.fromEntries(toolInputVariables), variables);
65
- }
66
- }
67
- }
68
- }
69
- }
70
- return super.watchQuery(options);
71
- }
72
- connect = cacheAsync(async () => {
73
- const { prefetch, result, toolName, args } = await this.appManager.connect();
74
- this.#toolInput = args;
75
- this.manifest.operations.forEach((operation) => {
76
- if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
77
- this.writeQuery({
78
- query: parse(operation.body),
79
- data: prefetch[operation.prefetchID].data,
80
- });
81
- }
82
- if (operation.tools.find((tool) => tool.name === toolName)) {
83
- this.writeQuery({
84
- query: parse(operation.body),
85
- data: result.data,
86
- variables: getVariablesForOperationFromToolInput(operation, args),
5
+ super(options, async (app) => {
6
+ const toolResult = promiseWithResolvers();
7
+ app.ontoolresult = (params) => {
8
+ toolResult.resolve(params);
9
+ };
10
+ await connectToHost(app);
11
+ // After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.
12
+ // Instead, the tool result is available immediately via `window.openai.toolOutput`.
13
+ // If it's already set, resolve the promise now rather than waiting for the
14
+ // notification that will never arrive.
15
+ if (window.openai.toolOutput !== null) {
16
+ toolResult.resolve({
17
+ structuredContent: window.openai.toolOutput,
18
+ content: [],
87
19
  });
88
20
  }
21
+ const { structuredContent } = await toolResult.promise;
22
+ return {
23
+ structuredContent,
24
+ // OpenAI is not consistent about sending `ui/notifications/tool-input`.
25
+ // Sometimes it doesn't send at all, other times it sends more than once
26
+ // before we get the tool result (which should always happen and at most
27
+ // once according to the spec). Rather than relying on the
28
+ // `ui/notifications/tool-input` notification to set the tool input value,
29
+ // we read from `window.openai.toolInput so that we have the most recent
30
+ // set value.
31
+ //
32
+ // When OpenAI fixes this issue and sends `ui/notifications/tool-input`
33
+ // consistently according to the MCP Apps specification, this can be
34
+ // reverted to use the `app.ontoolinput` callback.
35
+ toolInput: window.openai.toolInput,
36
+ // OpenAI doesn't provide access to `_meta` from ui/notifications/tool-result,
37
+ // so we need to use window.openai.toolResponseMetadata directly
38
+ _meta: window.openai.toolResponseMetadata,
39
+ };
89
40
  });
90
- });
91
- }
92
- function validateTerminatingLink(link) {
93
- let terminatingLink = link;
94
- while (terminatingLink.right) {
95
- terminatingLink = terminatingLink.right;
96
- }
97
- if (!isNamedLink(terminatingLink) ||
98
- terminatingLink.name !== "ToolCallLink") {
99
- throw new Error("The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.");
100
41
  }
101
42
  }
102
- function isNamedLink(link) {
103
- return "name" in link;
104
- }
105
43
  //# sourceMappingURL=ApolloClient.js.map
@@ -1 +1 @@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EAAE,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI;iBAC1C,CAAC,CAAC;YACL,CAAC;YAED,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;gBAC3D,IAAI,CAAC,UAAU,CAAC;oBACd,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;oBAC5B,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,qCAAqC,CAAC,SAAS,EAAE,IAAI,CAAC;iBAClE,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,uBAAuB,CAAC,IAAgB;IAC/C,IAAI,eAAe,GAAG,IAAI,CAAC;IAE3B,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,eAAe,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,CAAC;IAED,IACE,CAAC,WAAW,CAAC,eAAe,CAAC;QAC7B,eAAe,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import type { ApolloLink } from \"@apollo/client\";\nimport { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport { DocumentTransform } from \"@apollo/client\";\nimport type {\n WatchQueryOptions,\n ObservableQuery,\n OperationVariables,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse, visit } from \"graphql\";\nimport { equal } from \"@wry/equality\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type { ApplicationManifest } from \"../../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n aiClientSymbol,\n cacheAsync,\n getToolNamesFromDocument,\n getVariablesForOperationFromToolInput,\n warnOnVariableMismatch,\n} from \"../../utilities/index.js\";\nimport { McpAppManager } from \"./McpAppManager.js\";\nimport { getVariableNamesFromDocument } from \"../../utilities/getVariableNamesFromDocument.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n #toolInput: Record<string, unknown> | undefined;\n\n constructor(options: ApolloClient.Options) {\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link,\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n const serverDocument = removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n\n return visit(serverDocument, {\n OperationDefinition(node) {\n return { ...node, description: undefined };\n },\n });\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest);\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n clearToolInput() {\n this.#toolInput = undefined;\n }\n\n watchQuery<\n T = any,\n TVariables extends OperationVariables = OperationVariables,\n >(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {\n if (__DEV__) {\n const toolInput = this.#toolInput;\n\n if (toolInput) {\n const toolName = this.appManager.toolName;\n const hasMatchingTool =\n !!toolName && getToolNamesFromDocument(options.query).has(toolName);\n\n if (hasMatchingTool) {\n // Clear after first matching comparison so this only fires once and\n // remounting doesn't produce spurious warnings.\n this.#toolInput = undefined;\n\n const variableNames = getVariableNamesFromDocument(options.query);\n\n if (variableNames.size > 0) {\n const { variables } = options;\n\n const toolInputVariables = Object.entries(toolInput).filter(\n ([key]) => variableNames.has(key)\n );\n\n const hasToolInputMismatch = toolInputVariables.some(\n ([key, value]) => !equal(value, variables?.[key])\n );\n\n if (hasToolInputMismatch) {\n warnOnVariableMismatch(\n options.query,\n Object.fromEntries(toolInputVariables),\n variables\n );\n }\n }\n }\n }\n }\n\n return super.watchQuery(options);\n }\n\n connect = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.connect();\n\n this.#toolInput = args;\n\n this.manifest.operations.forEach((operation) => {\n if (operation.prefetchID && prefetch?.[operation.prefetchID]) {\n this.writeQuery({\n query: parse(operation.body),\n data: prefetch[operation.prefetchID].data,\n });\n }\n\n if (operation.tools.find((tool) => tool.name === toolName)) {\n this.writeQuery({\n query: parse(operation.body),\n data: result.data,\n variables: getVariablesForOperationFromToolInput(operation, args),\n });\n }\n });\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAO/E,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IACpD,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,UAAU,GACd,oBAAoB,EAAsC,CAAC;YAE7D,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC5B,UAAU,CAAC,OAAO,CAChB,MAAuD,CACxD,CAAC;YACJ,CAAC,CAAC;YAEF,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YAEzB,gFAAgF;YAChF,oFAAoF;YACpF,2EAA2E;YAC3E,uCAAuC;YACvC,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBACtC,UAAU,CAAC,OAAO,CAAC;oBACjB,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;oBAC3C,OAAO,EAAE,EAAE;iBACZ,CAAC,CAAC;YACL,CAAC;YAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAEvD,OAAO;gBACL,iBAAiB;gBACjB,wEAAwE;gBACxE,wEAAwE;gBACxE,wEAAwE;gBACxE,0DAA0D;gBAC1D,0EAA0E;gBAC1E,wEAAwE;gBACxE,aAAa;gBACb,EAAE;gBACF,uEAAuE;gBACvE,oEAAoE;gBACpE,kDAAkD;gBAClD,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS;gBAElC,8EAA8E;gBAC9E,gEAAgE;gBAChE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,oBAER;aACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { AbstractApolloClient } from \"../../core/AbstractApolloClient.js\";\nimport { connectToHost, promiseWithResolvers } from \"../../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"../../core/types.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends AbstractApolloClient.Options {}\n}\n\nexport class ApolloClient extends AbstractApolloClient {\n constructor(options: ApolloClient.Options) {\n super(options, async (app) => {\n const toolResult =\n promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n\n app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n await connectToHost(app);\n\n // After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.\n // Instead, the tool result is available immediately via `window.openai.toolOutput`.\n // If it's already set, resolve the promise now rather than waiting for the\n // notification that will never arrive.\n if (window.openai.toolOutput !== null) {\n toolResult.resolve({\n structuredContent: window.openai.toolOutput,\n content: [],\n });\n }\n\n const { structuredContent } = await toolResult.promise;\n\n return {\n structuredContent,\n // OpenAI is not consistent about sending `ui/notifications/tool-input`.\n // Sometimes it doesn't send at all, other times it sends more than once\n // before we get the tool result (which should always happen and at most\n // once according to the spec). Rather than relying on the\n // `ui/notifications/tool-input` notification to set the tool input value,\n // we read from `window.openai.toolInput so that we have the most recent\n // set value.\n //\n // When OpenAI fixes this issue and sends `ui/notifications/tool-input`\n // consistently according to the MCP Apps specification, this can be\n // reverted to use the `app.ontoolinput` callback.\n toolInput: window.openai.toolInput,\n\n // OpenAI doesn't provide access to `_meta` from ui/notifications/tool-result,\n // so we need to use window.openai.toolResponseMetadata directly\n _meta: window.openai.toolResponseMetadata as\n | ApolloMcpServerApps.Meta\n | undefined,\n };\n });\n }\n}\n"]}
@@ -1,3 +1,2 @@
1
1
  export { ApolloClient } from "./core/ApolloClient.js";
2
- export { ToolCallLink } from "./link/ToolCallLink.js";
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,3 +1,2 @@
1
1
  export { ApolloClient } from "./core/ApolloClient.js";
2
- export { ToolCallLink } from "./link/ToolCallLink.js";
3
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\n"]}
@@ -1,9 +1,2 @@
1
- export { useApp } from "./hooks/useApp.js";
2
- export { useHostContext } from "./hooks/useHostContext.js";
3
- export { useToolName } from "./hooks/useToolName.js";
4
- export { useToolMetadata } from "./hooks/useToolMetadata.js";
5
- export { useToolInput } from "./hooks/useToolInput.js";
6
- export { useToolInfo } from "./hooks/useToolInfo.js";
7
- export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
8
1
  export { useWidgetState } from "./hooks/useWidgetState.js";
9
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,9 +1,2 @@
1
- export { useApp } from "./hooks/useApp.js";
2
- export { useHostContext } from "./hooks/useHostContext.js";
3
- export { useToolName } from "./hooks/useToolName.js";
4
- export { useToolMetadata } from "./hooks/useToolMetadata.js";
5
- export { useToolInput } from "./hooks/useToolInput.js";
6
- export { useToolInfo } from "./hooks/useToolInfo.js";
7
- export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
8
1
  export { useWidgetState } from "./hooks/useWidgetState.js";
9
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { useApp } from \"./hooks/useApp.js\";\nexport { useHostContext } from \"./hooks/useHostContext.js\";\nexport { useToolName } from \"./hooks/useToolName.js\";\nexport { useToolMetadata } from \"./hooks/useToolMetadata.js\";\nexport { useToolInput } from \"./hooks/useToolInput.js\";\nexport { useToolInfo } from \"./hooks/useToolInfo.js\";\nexport { createHydrationUtils } from \"./hooks/createHydrationUtils.js\";\nexport { useWidgetState } from \"./hooks/useWidgetState.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { useWidgetState } from \"./hooks/useWidgetState.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloProvider.d.ts","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAIpF,KAAK,YAAY,GAAG,kBAAkB,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAEhF,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,UAAiB,KAAK;QACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC;KACtB;CACF;AAED,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,KAAK,2CAexE"}
1
+ {"version":3,"file":"ApolloProvider.d.ts","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAIpF,KAAK,YAAY,GAAG,kBAAkB,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAEhF,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,UAAiB,KAAK;QACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC;KACtB;CACF;AAED,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,KAAK,2CAWxE"}
@@ -10,6 +10,6 @@ export function ApolloProvider({ children, client }) {
10
10
  invariant(client[aiClientSymbol], 'The "client" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.');
11
11
  }
12
12
  use(client.connect());
13
- return (_jsx(BaseApolloProvider, { client: client, children: children }));
13
+ return _jsx(BaseApolloProvider, { client: client, children: children });
14
14
  }
15
15
  //# sourceMappingURL=ApolloProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAWlE,MAAM,UAAU,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAwB;IACvE,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,CACP,MAAM,CAAC,cAAc,CAAC,EACtB,+MAA+M,CAChN,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAEtB,OAAO,CACL,KAAC,kBAAkB,IAAC,MAAM,EAAE,MAA0B,YACnD,QAAQ,GACU,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { use } from \"react\";\nimport { ApolloProvider as BaseApolloProvider } from \"@apollo/client/react\";\nimport type { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport { ApolloClient as OpenAiApolloClient } from \"../openai/core/ApolloClient.js\";\nimport { ApolloClient as McpApolloClient } from \"../mcp/core/ApolloClient.js\";\nimport type { ApolloClient as FallbackApolloClient } from \"../core/ApolloClient.js\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { aiClientSymbol, invariant } from \"../utilities/index.js\";\n\ntype ApolloClient = OpenAiApolloClient | McpApolloClient | FallbackApolloClient;\n\nexport declare namespace ApolloProvider {\n export interface Props {\n children?: ReactNode;\n client: ApolloClient;\n }\n}\n\nexport function ApolloProvider({ children, client }: ApolloProvider.Props) {\n if (__DEV__) {\n invariant(\n client[aiClientSymbol],\n 'The \"client\" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'\n );\n }\n\n use(client.connect());\n\n return (\n <BaseApolloProvider client={client as BaseApolloClient}>\n {children}\n </BaseApolloProvider>\n );\n}\n"]}
1
+ {"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAWlE,MAAM,UAAU,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAwB;IACvE,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,CACP,MAAM,CAAC,cAAc,CAAC,EACtB,+MAA+M,CAChN,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAEtB,OAAO,KAAC,kBAAkB,IAAC,MAAM,EAAE,MAAM,YAAG,QAAQ,GAAsB,CAAC;AAC7E,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { use } from \"react\";\nimport { ApolloProvider as BaseApolloProvider } from \"@apollo/client/react\";\nimport { ApolloClient as OpenAiApolloClient } from \"../openai/core/ApolloClient.js\";\nimport { ApolloClient as McpApolloClient } from \"../mcp/core/ApolloClient.js\";\nimport type { ApolloClient as FallbackApolloClient } from \"../core/ApolloClient.js\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { aiClientSymbol, invariant } from \"../utilities/index.js\";\n\ntype ApolloClient = OpenAiApolloClient | McpApolloClient | FallbackApolloClient;\n\nexport declare namespace ApolloProvider {\n export interface Props {\n children?: ReactNode;\n client: ApolloClient;\n }\n}\n\nexport function ApolloProvider({ children, client }: ApolloProvider.Props) {\n if (__DEV__) {\n invariant(\n client[aiClientSymbol],\n 'The \"client\" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'\n );\n }\n\n use(client.connect());\n\n return <BaseApolloProvider client={client}>{children}</BaseApolloProvider>;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
2
- import type { Reactive } from "../../../react/reactive.js";
2
+ import { type Reactive } from "./reactive.js";
3
3
  type HydratedVariablesInput<TVariables> = {
4
4
  [K in keyof TVariables]: TVariables[K] | Reactive<TVariables[K]>;
5
5
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHydrationUtils.d.ts","sourceRoot":"","sources":["../../src/react/createHydrationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQ1D,KAAK,sBAAsB,CAAC,UAAU,IAAI;KACvC,CAAC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CACjE,CAAC;AAEF,KAAK,cAAc,CAAC,UAAU,EAAE,KAAK,IAAI;KACtC,CAAC,IAAI,MAAM,UAAU,IAAI,CAAC,SAAS,MAAM,KAAK,GAC7C,KAAK,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,GAC5B,KAAK,GACL,CAAC,GACH,CAAC,GAAG,CAAC,SAAS,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK;CACzD,CAAC;AAEF,KAAK,YAAY,CAAC,MAAM,IAAI,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,KAC1D,IAAI,CAAC;AAEV,oBAAoB;AACpB,wBAAgB,oBAAoB,CAClC,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,QAAQ,EAAE,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,YAAY;2BAKzD,eAAe,SAAS,sBAAsB,CAAC,UAAU,CAAC,aAE/C,eAAe,GACxB,MAAM,CAAC,OAAO,CAAC,MAAM,eAAe,EAAE,MAAM,UAAU,CAAC,EAAE,KAAK,CAAC,KAChE,CACD,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CACxE;EAoIF"}
@@ -1,21 +1,19 @@
1
1
  import { useState, useCallback, useRef, useMemo, useLayoutEffect } from "react";
2
- import { useApolloClient } from "./useApolloClient.js";
3
- import { useToolName } from "./useToolName.js";
4
- import { isReactive } from "../../../react/reactive.js";
2
+ import { useApolloClient } from "./hooks/internal/useApolloClient.js";
3
+ import { isReactive } from "./reactive.js";
5
4
  import { equal } from "@wry/equality";
6
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
7
- import { getToolNamesFromDocument, getVariableNamesFromDocument, } from "../../../utilities/index.js";
6
+ import { getToolNamesFromDocument, getVariableNamesFromDocument, } from "../utilities/index.js";
8
7
  /** @experimental */
9
8
  export function createHydrationUtils(document) {
10
9
  const documentToolNames = getToolNamesFromDocument(document);
11
10
  const variableNames = getVariableNamesFromDocument(document);
12
11
  function useHydratedVariables(variables) {
13
12
  const client = useApolloClient();
14
- const toolName = useToolName();
15
- const [toolInput] = useState(() => client.toolInput);
13
+ const [toolInput] = useState(() => client["hydratedToolInput"]);
16
14
  const toolMatches = toolInput !== undefined &&
17
- toolName !== undefined &&
18
- documentToolNames.has(toolName);
15
+ client.toolInfo?.toolName !== undefined &&
16
+ documentToolNames.has(client.toolInfo.toolName);
19
17
  const [stateVars, setStateVars] = useState(() => {
20
18
  const values = {};
21
19
  for (const [key, value] of Object.entries(toolMatches ? toolInput : variables)) {
@@ -71,7 +69,7 @@ export function createHydrationUtils(document) {
71
69
  // present, so both paths are idempotent.
72
70
  useLayoutEffect(() => {
73
71
  if (toolMatches) {
74
- client.clearToolInput();
72
+ client["clearHydratedToolInput"]();
75
73
  }
76
74
  // eslint-disable-next-line react-hooks/exhaustive-deps
77
75
  }, []);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHydrationUtils.js","sourceRoot":"","sources":["../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AAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { useState, useCallback, useRef, useMemo, useLayoutEffect } from \"react\";\nimport type {\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport { useApolloClient } from \"./hooks/internal/useApolloClient.js\";\nimport { isReactive, type Reactive } from \"./reactive.js\";\nimport { equal } from \"@wry/equality\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport {\n getToolNamesFromDocument,\n getVariableNamesFromDocument,\n} from \"../utilities/index.js\";\n\ntype HydratedVariablesInput<TVariables> = {\n [K in keyof TVariables]: TVariables[K] | Reactive<TVariables[K]>;\n};\n\ntype StateVariables<TVariables, Input> = {\n [K in keyof TVariables as K extends keyof Input ?\n Input[K] extends Reactive<any> ?\n never\n : K\n : K]: K extends keyof TVariables ? TVariables[K] : never;\n};\n\ntype SetVariables<TState> = (\n update: Partial<TState> | ((prev: TState) => Partial<TState>)\n) => void;\n\n/** @experimental */\nexport function createHydrationUtils<\n TVariables extends OperationVariables = OperationVariables,\n>(document: TypedDocumentNode<any, TVariables> | DocumentNode) {\n const documentToolNames = getToolNamesFromDocument(document);\n const variableNames = getVariableNamesFromDocument(document);\n\n function useHydratedVariables<\n TInputVariables extends HydratedVariablesInput<TVariables>,\n >(\n variables: TInputVariables &\n Record<Exclude<keyof TInputVariables, keyof TVariables>, never>\n ): [\n variables: TVariables,\n setVariables: SetVariables<StateVariables<TVariables, TInputVariables>>,\n ] {\n const client = useApolloClient();\n const [toolInput] = useState(() => client[\"hydratedToolInput\"]);\n\n const toolMatches =\n toolInput !== undefined &&\n client.toolInfo?.toolName !== undefined &&\n documentToolNames.has(client.toolInfo.toolName);\n\n const [stateVars, setStateVars] = useState<Record<string, unknown>>(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(\n toolMatches ? toolInput : variables\n )) {\n if (variableNames.has(key) && !isReactive(value)) {\n values[key] = value;\n }\n }\n\n return values;\n });\n\n const [initialReactiveVars] = useState<Record<string, unknown>>(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(variables)) {\n if (variableNames.has(key) && isReactive(value)) {\n values[key] = value.value;\n }\n }\n\n return values;\n });\n\n const [reactiveVars, setReactiveVars] = useState(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(initialReactiveVars)) {\n if (toolMatches && key in toolInput) {\n values[key] = toolInput[key];\n } else if (!toolMatches) {\n values[key] = value;\n }\n }\n\n return values;\n });\n\n const changedKeysRef = useRef(new Set<string>());\n const nextReactiveVars: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(variables)) {\n if (!variableNames.has(key) || !isReactive(value)) continue;\n\n const hasChanged =\n changedKeysRef.current.has(key) ||\n !equal(value.value, initialReactiveVars[key]);\n\n if (toolMatches && !hasChanged) {\n if (key in toolInput) {\n nextReactiveVars[key] = toolInput[key];\n }\n } else {\n nextReactiveVars[key] = value.value;\n }\n }\n\n if (!equal(nextReactiveVars, reactiveVars)) {\n setReactiveVars(nextReactiveVars);\n }\n\n // Clear the tool input after first mount so that remounting the component\n // uses the user-provided variables rather than the hydrated tool input.\n // This runs once on mount; watchQuery also clears it when useQuery is\n // present, so both paths are idempotent.\n useLayoutEffect(() => {\n if (toolMatches) {\n client[\"clearHydratedToolInput\"]();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n for (const [key, value] of Object.entries(variables)) {\n if (\n variableNames.has(key) &&\n isReactive(value) &&\n !changedKeysRef.current.has(key) &&\n !equal(value.value, initialReactiveVars[key])\n ) {\n changedKeysRef.current.add(key);\n }\n }\n });\n\n const resolvedVariables = useMemo(() => {\n return { ...stateVars, ...reactiveVars } as TVariables;\n }, [stateVars, reactiveVars]);\n\n const setVariables = useCallback<\n SetVariables<StateVariables<TVariables, TInputVariables>>\n >((update) => {\n setStateVars((prev) => {\n const updates =\n typeof update === \"function\" ? update(prev as any) : update;\n\n const filtered = Object.fromEntries(\n Object.entries(updates).filter(([key]) => {\n if (key in initialReactiveVars) {\n if (__DEV__) {\n console.warn(\n `Attempted to set reactive variable \"${key}\" via setVariables. ` +\n `Reactive variables are read-only and are ignored. `\n );\n }\n return false;\n }\n return true;\n })\n );\n\n if (Object.keys(filtered).length === 0) return prev;\n\n return { ...prev, ...filtered };\n });\n }, []);\n\n return [resolvedVariables, setVariables];\n }\n\n return { useHydratedVariables };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { AbstractApolloClient } from "../../../core/AbstractApolloClient.js";
2
+ export declare function useApolloClient(): AbstractApolloClient;
3
+ //# sourceMappingURL=useApolloClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApolloClient.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAG7E,wBAAgB,eAAe,yBAS9B"}
@@ -1,8 +1,8 @@
1
1
  import { useApolloClient as useBaseApolloClient } from "@apollo/client/react";
2
- import { ApolloClient } from "../../core/ApolloClient.js";
2
+ import { AbstractApolloClient } from "../../../core/AbstractApolloClient.js";
3
3
  import { aiClientSymbol, invariant } from "../../../utilities/index.js";
4
- export function useApolloClient(override) {
5
- const client = useBaseApolloClient(override);
4
+ export function useApolloClient() {
5
+ const client = useBaseApolloClient();
6
6
  invariant(client[aiClientSymbol], 'The "client" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.');
7
7
  return client;
8
8
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,mBAAmB,EAA0B,CAAC;IAE7D,SAAS,CACP,MAAM,CAAC,cAAc,CAAC,EACtB,+MAA+M,CAChN,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useApolloClient as useBaseApolloClient } from \"@apollo/client/react\";\nimport { AbstractApolloClient } from \"../../../core/AbstractApolloClient.js\";\nimport { aiClientSymbol, invariant } from \"../../../utilities/index.js\";\n\nexport function useApolloClient() {\n const client = useBaseApolloClient() as AbstractApolloClient;\n\n invariant(\n client[aiClientSymbol],\n 'The \"client\" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'\n );\n\n return client;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApp.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useApp.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,iDAErB"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./internal/useApolloClient.js";
2
+ export function useApp() {
3
+ return useApolloClient()["appManager"].app;
4
+ }
5
+ //# sourceMappingURL=useApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApp.js","sourceRoot":"","sources":["../../../src/react/hooks/useApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,MAAM;IACpB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;AAC7C,CAAC","sourcesContent":["import { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useApp() {\n return useApolloClient()[\"appManager\"].app;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHostContext.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,0EAU7B"}
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useSyncExternalStore } from "react";
2
- import { useApolloClient } from "./useApolloClient";
2
+ import { useApolloClient } from "./internal/useApolloClient";
3
3
  export function useHostContext() {
4
4
  const appManager = useApolloClient()["appManager"];
5
5
  return useSyncExternalStore(useCallback((update) => appManager.onHostContextChanged(update), [appManager]), () => appManager.app.getHostContext());
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHostContext.js","sourceRoot":"","sources":["../../../src/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,UAAU,cAAc;IAC5B,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC;IAEnD,OAAO,oBAAoB,CACzB,WAAW,CACT,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,MAAM,CAAC,EACnD,CAAC,UAAU,CAAC,CACb,EACD,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,EAAE,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useSyncExternalStore } from \"react\";\nimport { useApolloClient } from \"./internal/useApolloClient\";\n\nexport function useHostContext() {\n const appManager = useApolloClient()[\"appManager\"];\n\n return useSyncExternalStore(\n useCallback(\n (update) => appManager.onHostContextChanged(update),\n [appManager]\n ),\n () => appManager.app.getHostContext()\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { ToolInfo } from "../../core/typeRegistration.js";
2
+ export declare function useToolInfo(): ToolInfo | undefined;
3
+ //# sourceMappingURL=useToolInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolInfo.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG/D,wBAAgB,WAAW,IAAI,QAAQ,GAAG,SAAS,CAElD"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./internal/useApolloClient.js";
2
+ export function useToolInfo() {
3
+ return useApolloClient().toolInfo;
4
+ }
5
+ //# sourceMappingURL=useToolInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolInfo.js","sourceRoot":"","sources":["../../../src/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,WAAW;IACzB,OAAO,eAAe,EAAE,CAAC,QAAQ,CAAC;AACpC,CAAC","sourcesContent":["import type { ToolInfo } from \"../../core/typeRegistration.js\";\nimport { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useToolInfo(): ToolInfo | undefined {\n return useApolloClient().toolInfo;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function useToolMetadata(): import("../../core/types.js").ApolloMcpServerApps.Meta | undefined;
2
+ //# sourceMappingURL=useToolMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,uEAE9B"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./internal/useApolloClient.js";
2
+ export function useToolMetadata() {
3
+ return useApolloClient().toolMetadata;
4
+ }
5
+ //# sourceMappingURL=useToolMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolMetadata.js","sourceRoot":"","sources":["../../../src/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,eAAe;IAC7B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC;AACxC,CAAC","sourcesContent":["import { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useToolMetadata() {\n return useApolloClient().toolMetadata;\n}\n"]}
@@ -1,20 +1,9 @@
1
1
  export { ApolloProvider } from "./ApolloProvider.js";
2
2
  export { reactive } from "./reactive.js";
3
3
  export type { Reactive } from "./reactive.js";
4
- export declare const useApp: typeof import("./index.mcp.js").useApp;
5
- export declare const useHostContext: typeof import("./index.mcp.js").useHostContext;
6
- /**
7
- * @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
8
- * in the next major version.
9
- */
10
- export declare const useToolInput: typeof import("./index.mcp.js").useToolInput;
11
- export declare const useToolMetadata: typeof import("./index.mcp.js").useToolMetadata;
12
- /**
13
- * @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
14
- * in the next major version.
15
- */
16
- export declare const useToolName: typeof import("./index.mcp.js").useToolName;
17
- export declare const useToolInfo: typeof import("./index.mcp.js").useToolInfo;
18
- /** @experimental */
19
- export declare const createHydrationUtils: typeof import("./index.mcp.js").createHydrationUtils;
4
+ export { useApp } from "./hooks/useApp.js";
5
+ export { useHostContext } from "./hooks/useHostContext.js";
6
+ export { useToolInfo } from "./hooks/useToolInfo.js";
7
+ export { useToolMetadata } from "./hooks/useToolMetadata.js";
8
+ export { createHydrationUtils } from "./createHydrationUtils.js";
20
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI9C,eAAO,MAAM,MAAM,wCAC4C,CAAC;AAEhE,eAAO,MAAM,cAAc,gDACoD,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,YAAY,8CACkD,CAAC;AAE5E,eAAO,MAAM,eAAe,iDAGzB,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,WAAW,6CACiD,CAAC;AAE1E,eAAO,MAAM,WAAW,6CACiD,CAAC;AAE1E,oBAAoB;AACpB,eAAO,MAAM,oBAAoB,sDAER,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}