@apollo/client-ai-apps 0.4.0 → 0.5.1

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 (404) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/workflows/pr.yaml +23 -1
  3. package/.github/workflows/release.yaml +1 -5
  4. package/.github/workflows/verify-changeset.yml +112 -21
  5. package/CHANGELOG.md +361 -0
  6. package/__mocks__/fs/promises.cjs +3 -0
  7. package/__mocks__/fs.cjs +3 -0
  8. package/dist/config/defineConfig.d.ts +28 -0
  9. package/dist/config/defineConfig.d.ts.map +1 -0
  10. package/dist/config/defineConfig.js +7 -0
  11. package/dist/config/defineConfig.js.map +1 -0
  12. package/dist/config/index.d.ts +3 -0
  13. package/dist/config/index.d.ts.map +1 -0
  14. package/dist/config/index.js +2 -0
  15. package/dist/config/index.js.map +1 -0
  16. package/dist/config/schema.d.ts +29 -0
  17. package/dist/config/schema.d.ts.map +1 -0
  18. package/dist/config/schema.js +51 -0
  19. package/dist/config/schema.js.map +1 -0
  20. package/dist/config/types.d.ts +7 -0
  21. package/dist/config/types.d.ts.map +1 -0
  22. package/dist/config/types.js +2 -0
  23. package/dist/config/types.js.map +1 -0
  24. package/dist/core/ApolloClient.d.ts +4 -3
  25. package/dist/core/ApolloClient.d.ts.map +1 -1
  26. package/dist/core/ApolloClient.js +6 -59
  27. package/dist/core/ApolloClient.js.map +1 -1
  28. package/dist/core/Platform.d.ts +8 -0
  29. package/dist/core/Platform.d.ts.map +1 -0
  30. package/dist/core/Platform.js +20 -0
  31. package/dist/core/Platform.js.map +1 -0
  32. package/dist/core/types.d.ts +13 -0
  33. package/dist/core/types.d.ts.map +1 -0
  34. package/dist/core/types.js +2 -0
  35. package/dist/core/types.js.map +1 -0
  36. package/dist/index.d.ts +1 -14
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -13
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mcp.d.ts +5 -0
  41. package/dist/index.mcp.d.ts.map +1 -0
  42. package/dist/index.mcp.js +5 -0
  43. package/dist/index.mcp.js.map +1 -0
  44. package/dist/index.openai.d.ts +5 -0
  45. package/dist/index.openai.d.ts.map +1 -0
  46. package/dist/index.openai.js +5 -0
  47. package/dist/index.openai.js.map +1 -0
  48. package/dist/link/ToolCallLink.d.ts +3 -3
  49. package/dist/link/ToolCallLink.d.ts.map +1 -1
  50. package/dist/link/ToolCallLink.js +5 -14
  51. package/dist/link/ToolCallLink.js.map +1 -1
  52. package/dist/mcp/core/ApolloClient.d.ts +21 -0
  53. package/dist/mcp/core/ApolloClient.d.ts.map +1 -0
  54. package/dist/mcp/core/ApolloClient.js +65 -0
  55. package/dist/mcp/core/ApolloClient.js.map +1 -0
  56. package/dist/mcp/core/McpAppManager.d.ts +34 -0
  57. package/dist/mcp/core/McpAppManager.d.ts.map +1 -0
  58. package/dist/mcp/core/McpAppManager.js +63 -0
  59. package/dist/mcp/core/McpAppManager.js.map +1 -0
  60. package/dist/mcp/core/Platform.d.ts +8 -0
  61. package/dist/mcp/core/Platform.d.ts.map +1 -0
  62. package/dist/mcp/core/Platform.js +8 -0
  63. package/dist/mcp/core/Platform.js.map +1 -0
  64. package/dist/mcp/index.d.ts +3 -0
  65. package/dist/mcp/index.d.ts.map +1 -0
  66. package/dist/mcp/index.js +3 -0
  67. package/dist/mcp/index.js.map +1 -0
  68. package/dist/mcp/link/ToolCallLink.d.ts +28 -0
  69. package/dist/mcp/link/ToolCallLink.d.ts.map +1 -0
  70. package/dist/mcp/link/ToolCallLink.js +35 -0
  71. package/dist/mcp/link/ToolCallLink.js.map +1 -0
  72. package/dist/mcp/react/hooks/useApolloClient.d.ts +3 -0
  73. package/dist/mcp/react/hooks/useApolloClient.d.ts.map +1 -0
  74. package/dist/mcp/react/hooks/useApolloClient.js +9 -0
  75. package/dist/mcp/react/hooks/useApolloClient.js.map +1 -0
  76. package/dist/mcp/react/hooks/useApp.d.ts +2 -0
  77. package/dist/mcp/react/hooks/useApp.d.ts.map +1 -0
  78. package/dist/mcp/react/hooks/useApp.js +5 -0
  79. package/dist/mcp/react/hooks/useApp.js.map +1 -0
  80. package/dist/mcp/react/hooks/useToolInput.d.ts +2 -0
  81. package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -0
  82. package/dist/mcp/react/hooks/useToolInput.js +5 -0
  83. package/dist/mcp/react/hooks/useToolInput.js.map +1 -0
  84. package/dist/mcp/react/hooks/useToolMetadata.d.ts +8 -0
  85. package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +1 -0
  86. package/dist/mcp/react/hooks/useToolMetadata.js +5 -0
  87. package/dist/mcp/react/hooks/useToolMetadata.js.map +1 -0
  88. package/dist/mcp/react/hooks/useToolName.d.ts +2 -0
  89. package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -0
  90. package/dist/mcp/react/hooks/useToolName.js +5 -0
  91. package/dist/mcp/react/hooks/useToolName.js.map +1 -0
  92. package/dist/mcp/react/index.d.ts +5 -0
  93. package/dist/mcp/react/index.d.ts.map +1 -0
  94. package/dist/mcp/react/index.js +5 -0
  95. package/dist/mcp/react/index.js.map +1 -0
  96. package/dist/openai/core/ApolloClient.d.ts +21 -0
  97. package/dist/openai/core/ApolloClient.d.ts.map +1 -0
  98. package/dist/openai/core/ApolloClient.js +66 -0
  99. package/dist/openai/core/ApolloClient.js.map +1 -0
  100. package/dist/openai/core/McpAppManager.d.ts +28 -0
  101. package/dist/openai/core/McpAppManager.d.ts.map +1 -0
  102. package/dist/openai/core/McpAppManager.js +73 -0
  103. package/dist/openai/core/McpAppManager.js.map +1 -0
  104. package/dist/openai/core/Platform.d.ts +8 -0
  105. package/dist/openai/core/Platform.d.ts.map +1 -0
  106. package/dist/openai/core/Platform.js +8 -0
  107. package/dist/openai/core/Platform.js.map +1 -0
  108. package/dist/openai/globals.d.ts +12 -0
  109. package/dist/openai/globals.d.ts.map +1 -0
  110. package/dist/openai/globals.js +2 -0
  111. package/dist/openai/globals.js.map +1 -0
  112. package/dist/openai/index.d.ts +3 -0
  113. package/dist/openai/index.d.ts.map +1 -0
  114. package/dist/openai/index.js +3 -0
  115. package/dist/openai/index.js.map +1 -0
  116. package/dist/openai/link/ToolCallLink.d.ts +28 -0
  117. package/dist/openai/link/ToolCallLink.d.ts.map +1 -0
  118. package/dist/openai/link/ToolCallLink.js +35 -0
  119. package/dist/openai/link/ToolCallLink.js.map +1 -0
  120. package/dist/openai/react/hooks/useApolloClient.d.ts +3 -0
  121. package/dist/openai/react/hooks/useApolloClient.d.ts.map +1 -0
  122. package/dist/openai/react/hooks/useApolloClient.js +9 -0
  123. package/dist/openai/react/hooks/useApolloClient.js.map +1 -0
  124. package/dist/openai/react/hooks/useApp.d.ts +2 -0
  125. package/dist/openai/react/hooks/useApp.d.ts.map +1 -0
  126. package/dist/openai/react/hooks/useApp.js +5 -0
  127. package/dist/openai/react/hooks/useApp.js.map +1 -0
  128. package/dist/openai/react/hooks/useOpenAiGlobal.d.ts +3 -0
  129. package/dist/openai/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
  130. package/dist/{react → openai/react}/hooks/useOpenAiGlobal.js +1 -1
  131. package/dist/openai/react/hooks/useOpenAiGlobal.js.map +1 -0
  132. package/dist/openai/react/hooks/useToolInput.d.ts +2 -0
  133. package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -0
  134. package/dist/openai/react/hooks/useToolInput.js +5 -0
  135. package/dist/openai/react/hooks/useToolInput.js.map +1 -0
  136. package/dist/openai/react/hooks/useToolMetadata.d.ts +2 -0
  137. package/dist/openai/react/hooks/useToolMetadata.d.ts.map +1 -0
  138. package/dist/openai/react/hooks/useToolMetadata.js +5 -0
  139. package/dist/openai/react/hooks/useToolMetadata.js.map +1 -0
  140. package/dist/openai/react/hooks/useToolName.d.ts.map +1 -0
  141. package/dist/openai/react/hooks/useToolName.js +5 -0
  142. package/dist/openai/react/hooks/useToolName.js.map +1 -0
  143. package/dist/{react → openai/react}/hooks/useWidgetState.d.ts +1 -1
  144. package/dist/openai/react/hooks/useWidgetState.d.ts.map +1 -0
  145. package/dist/openai/react/hooks/useWidgetState.js.map +1 -0
  146. package/dist/openai/react/index.d.ts +6 -0
  147. package/dist/openai/react/index.d.ts.map +1 -0
  148. package/dist/openai/react/index.js +6 -0
  149. package/dist/openai/react/index.js.map +1 -0
  150. package/dist/{types/openai.d.ts → openai/types.d.ts} +7 -11
  151. package/dist/openai/types.d.ts.map +1 -0
  152. package/dist/{types/openai.js → openai/types.js} +1 -1
  153. package/dist/openai/types.js.map +1 -0
  154. package/dist/react/ApolloProvider.d.ts +6 -2
  155. package/dist/react/ApolloProvider.d.ts.map +1 -1
  156. package/dist/react/ApolloProvider.js +12 -27
  157. package/dist/react/ApolloProvider.js.map +1 -1
  158. package/dist/react/index.d.ts +6 -0
  159. package/dist/react/index.d.ts.map +1 -0
  160. package/dist/react/index.js +9 -0
  161. package/dist/react/index.js.map +1 -0
  162. package/dist/react/index.mcp.d.ts +3 -0
  163. package/dist/react/index.mcp.d.ts.map +1 -0
  164. package/dist/react/index.mcp.js +3 -0
  165. package/dist/react/index.mcp.js.map +1 -0
  166. package/dist/react/index.openai.d.ts +3 -0
  167. package/dist/react/index.openai.d.ts.map +1 -0
  168. package/dist/react/index.openai.js +3 -0
  169. package/dist/react/index.openai.js.map +1 -0
  170. package/dist/react/missingHook.d.ts +2 -0
  171. package/dist/react/missingHook.d.ts.map +1 -0
  172. package/dist/react/missingHook.js +6 -0
  173. package/dist/react/missingHook.js.map +1 -0
  174. package/dist/tsconfig/core/tsconfig.json +5 -0
  175. package/dist/tsconfig/mcp/tsconfig.json +6 -0
  176. package/dist/tsconfig/openai/tsconfig.json +7 -0
  177. package/dist/types/application-manifest.d.ts +5 -1
  178. package/dist/types/application-manifest.d.ts.map +1 -1
  179. package/dist/types/application-manifest.js.map +1 -1
  180. package/dist/utilities/cacheAsync.d.ts +4 -0
  181. package/dist/utilities/cacheAsync.d.ts.map +1 -0
  182. package/dist/utilities/cacheAsync.js +19 -0
  183. package/dist/utilities/cacheAsync.js.map +1 -0
  184. package/dist/utilities/constants.d.ts +6 -0
  185. package/dist/utilities/constants.d.ts.map +1 -0
  186. package/dist/utilities/constants.js +6 -0
  187. package/dist/utilities/constants.js.map +1 -0
  188. package/dist/utilities/emptyModule.d.ts +2 -0
  189. package/dist/utilities/emptyModule.d.ts.map +1 -0
  190. package/dist/utilities/emptyModule.js +2 -0
  191. package/dist/utilities/emptyModule.js.map +1 -0
  192. package/dist/utilities/getVariablesForOperationFromToolInput.d.ts +5 -0
  193. package/dist/utilities/getVariablesForOperationFromToolInput.d.ts.map +1 -0
  194. package/dist/utilities/getVariablesForOperationFromToolInput.js +18 -0
  195. package/dist/utilities/getVariablesForOperationFromToolInput.js.map +1 -0
  196. package/dist/utilities/index.d.ts +6 -0
  197. package/dist/utilities/index.d.ts.map +1 -0
  198. package/dist/utilities/index.js +6 -0
  199. package/dist/utilities/index.js.map +1 -0
  200. package/dist/utilities/invariant.d.ts +2 -0
  201. package/dist/utilities/invariant.d.ts.map +1 -0
  202. package/dist/utilities/invariant.js +6 -0
  203. package/dist/utilities/invariant.js.map +1 -0
  204. package/dist/utilities/promiseWithResolvers.d.ts +7 -0
  205. package/dist/utilities/promiseWithResolvers.d.ts.map +1 -0
  206. package/dist/utilities/promiseWithResolvers.js +16 -0
  207. package/dist/utilities/promiseWithResolvers.js.map +1 -0
  208. package/dist/vite/__tests__/utilities/build.d.ts +41 -0
  209. package/dist/vite/__tests__/utilities/build.d.ts.map +1 -0
  210. package/dist/vite/__tests__/utilities/build.js +63 -0
  211. package/dist/vite/__tests__/utilities/build.js.map +1 -0
  212. package/dist/vite/apolloClientAiApps.d.ts +14 -0
  213. package/dist/vite/apolloClientAiApps.d.ts.map +1 -0
  214. package/dist/vite/apolloClientAiApps.js +350 -0
  215. package/dist/vite/apolloClientAiApps.js.map +1 -0
  216. package/dist/vite/index.d.ts +1 -2
  217. package/dist/vite/index.d.ts.map +1 -1
  218. package/dist/vite/index.js +1 -2
  219. package/dist/vite/index.js.map +1 -1
  220. package/dist/vite/utilities/config.d.ts +2 -0
  221. package/dist/vite/utilities/config.d.ts.map +1 -0
  222. package/dist/vite/utilities/config.js +11 -0
  223. package/dist/vite/utilities/config.js.map +1 -0
  224. package/dist/vite/utilities/graphql.d.ts +20 -0
  225. package/dist/vite/utilities/graphql.d.ts.map +1 -0
  226. package/dist/vite/utilities/graphql.js +42 -0
  227. package/dist/vite/utilities/graphql.js.map +1 -0
  228. package/knope.toml +1 -1
  229. package/package.json +105 -9
  230. package/src/config/defineConfig.ts +8 -0
  231. package/src/config/index.ts +2 -0
  232. package/src/config/schema.ts +73 -0
  233. package/src/config/types.ts +7 -0
  234. package/src/core/ApolloClient.ts +7 -95
  235. package/src/core/Platform.ts +27 -0
  236. package/src/core/types.ts +14 -0
  237. package/src/index.mcp.ts +5 -0
  238. package/src/index.openai.ts +5 -0
  239. package/src/index.ts +2 -27
  240. package/src/link/ToolCallLink.ts +6 -22
  241. package/src/mcp/core/ApolloClient.ts +102 -0
  242. package/src/mcp/core/McpAppManager.ts +98 -0
  243. package/src/mcp/core/Platform.ts +11 -0
  244. package/src/mcp/core/__tests__/ApolloClient.test.ts +464 -0
  245. package/src/mcp/index.ts +2 -0
  246. package/src/mcp/link/ToolCallLink.ts +40 -0
  247. package/src/mcp/link/__tests__/ToolCallLink.test.ts +53 -0
  248. package/src/mcp/react/hooks/__tests__/useApp.test.tsx +46 -0
  249. package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +50 -0
  250. package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +53 -0
  251. package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +50 -0
  252. package/src/mcp/react/hooks/useApolloClient.ts +14 -0
  253. package/src/mcp/react/hooks/useApp.ts +5 -0
  254. package/src/mcp/react/hooks/useToolInput.ts +5 -0
  255. package/src/mcp/react/hooks/useToolMetadata.ts +5 -0
  256. package/src/mcp/react/hooks/useToolName.ts +5 -0
  257. package/src/mcp/react/index.ts +4 -0
  258. package/src/openai/core/ApolloClient.ts +100 -0
  259. package/src/openai/core/McpAppManager.ts +110 -0
  260. package/src/openai/core/Platform.ts +11 -0
  261. package/src/openai/core/__tests__/ApolloClient.test.ts +537 -0
  262. package/src/openai/globals.ts +14 -0
  263. package/src/openai/index.ts +2 -0
  264. package/src/openai/link/ToolCallLink.ts +40 -0
  265. package/src/{react → openai/react}/hooks/__tests__/useOpenAiGlobal.test.ts +1 -1
  266. package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +85 -0
  267. package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +86 -0
  268. package/src/openai/react/hooks/__tests__/useToolName.test.tsx +50 -0
  269. package/src/{react → openai/react}/hooks/__tests__/useWidgetState.test.tsx +1 -1
  270. package/src/openai/react/hooks/useApolloClient.ts +14 -0
  271. package/src/openai/react/hooks/useApp.ts +5 -0
  272. package/src/{react → openai/react}/hooks/useOpenAiGlobal.ts +2 -2
  273. package/src/openai/react/hooks/useToolInput.ts +5 -0
  274. package/src/openai/react/hooks/useToolMetadata.ts +5 -0
  275. package/src/openai/react/hooks/useToolName.ts +5 -0
  276. package/src/{react → openai/react}/hooks/useWidgetState.ts +1 -1
  277. package/src/openai/react/index.ts +5 -0
  278. package/src/{types/openai.ts → openai/types.ts} +9 -13
  279. package/src/react/ApolloProvider.tsx +23 -31
  280. package/src/react/__tests__/ApolloProvider/mcp.test.tsx +74 -0
  281. package/src/react/__tests__/ApolloProvider/openai.test.tsx +146 -0
  282. package/src/react/index.mcp.ts +7 -0
  283. package/src/react/index.openai.ts +7 -0
  284. package/src/react/index.ts +19 -0
  285. package/src/react/missingHook.ts +9 -0
  286. package/src/testing/internal/index.ts +8 -0
  287. package/src/testing/internal/matchers/index.ts +2 -0
  288. package/src/testing/internal/matchers/toComplete.ts +46 -0
  289. package/src/testing/internal/matchers/toEmitValue.ts +71 -0
  290. package/src/testing/internal/matchers/types.ts +3 -0
  291. package/src/testing/internal/mcp/graphqlToolResult.ts +31 -0
  292. package/src/testing/internal/mcp/minimalHostContextWithToolName.ts +9 -0
  293. package/src/testing/internal/mcp/mockMcpHost.ts +188 -0
  294. package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
  295. package/src/testing/internal/openai/stubOpenAiGlobals.ts +22 -9
  296. package/src/testing/internal/react/renderAsync.ts +7 -0
  297. package/src/testing/internal/utilities/ObservableStream.ts +172 -0
  298. package/src/testing/internal/utilities/getSerializableProperties.ts +55 -0
  299. package/src/testing/internal/utilities/mockApplicationManifest.ts +39 -0
  300. package/src/testing/internal/utilities/spyOnConsole.ts +29 -0
  301. package/src/testing/internal/utilities/wait.ts +3 -0
  302. package/src/tsconfig/core/tsconfig.json +5 -0
  303. package/src/tsconfig/mcp/tsconfig.json +6 -0
  304. package/src/tsconfig/openai/tsconfig.json +7 -0
  305. package/src/types/application-manifest.ts +7 -1
  306. package/src/utilities/__tests__/cacheAsync.test.ts +64 -0
  307. package/src/utilities/cacheAsync.ts +25 -0
  308. package/src/utilities/constants.ts +5 -0
  309. package/src/utilities/emptyModule.ts +1 -0
  310. package/src/utilities/getVariablesForOperationFromToolInput.ts +27 -0
  311. package/src/utilities/index.ts +5 -0
  312. package/src/utilities/invariant.ts +5 -0
  313. package/src/utilities/promiseWithResolvers.ts +18 -0
  314. package/src/vite/__tests__/apolloClientAiApps.test.ts +1521 -0
  315. package/src/vite/__tests__/utilities/build.ts +72 -0
  316. package/src/vite/apolloClientAiApps.ts +515 -0
  317. package/src/vite/index.ts +1 -2
  318. package/src/vite/utilities/config.ts +13 -0
  319. package/src/vite/utilities/graphql.ts +123 -0
  320. package/tsconfig.base.json +2 -2
  321. package/tsconfig.vite.build.json +4 -1
  322. package/tsconfig.vite.json +8 -2
  323. package/vitest-setup.ts +28 -0
  324. package/dist/react/context/ToolUseContext.d.ts +0 -16
  325. package/dist/react/context/ToolUseContext.d.ts.map +0 -1
  326. package/dist/react/context/ToolUseContext.js +0 -11
  327. package/dist/react/context/ToolUseContext.js.map +0 -1
  328. package/dist/react/hooks/useCallTool.d.ts +0 -4
  329. package/dist/react/hooks/useCallTool.d.ts.map +0 -1
  330. package/dist/react/hooks/useCallTool.js +0 -5
  331. package/dist/react/hooks/useCallTool.js.map +0 -1
  332. package/dist/react/hooks/useOpenAiGlobal.d.ts +0 -3
  333. package/dist/react/hooks/useOpenAiGlobal.d.ts.map +0 -1
  334. package/dist/react/hooks/useOpenAiGlobal.js.map +0 -1
  335. package/dist/react/hooks/useOpenExternal.d.ts +0 -4
  336. package/dist/react/hooks/useOpenExternal.d.ts.map +0 -1
  337. package/dist/react/hooks/useOpenExternal.js +0 -5
  338. package/dist/react/hooks/useOpenExternal.js.map +0 -1
  339. package/dist/react/hooks/useRequestDisplayMode.d.ts +0 -7
  340. package/dist/react/hooks/useRequestDisplayMode.d.ts.map +0 -1
  341. package/dist/react/hooks/useRequestDisplayMode.js +0 -6
  342. package/dist/react/hooks/useRequestDisplayMode.js.map +0 -1
  343. package/dist/react/hooks/useSendFollowUpMessage.d.ts +0 -2
  344. package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +0 -1
  345. package/dist/react/hooks/useSendFollowUpMessage.js +0 -8
  346. package/dist/react/hooks/useSendFollowUpMessage.js.map +0 -1
  347. package/dist/react/hooks/useToolEffect.d.ts +0 -3
  348. package/dist/react/hooks/useToolEffect.d.ts.map +0 -1
  349. package/dist/react/hooks/useToolEffect.js +0 -28
  350. package/dist/react/hooks/useToolEffect.js.map +0 -1
  351. package/dist/react/hooks/useToolInput.d.ts +0 -2
  352. package/dist/react/hooks/useToolInput.d.ts.map +0 -1
  353. package/dist/react/hooks/useToolInput.js +0 -6
  354. package/dist/react/hooks/useToolInput.js.map +0 -1
  355. package/dist/react/hooks/useToolName.d.ts.map +0 -1
  356. package/dist/react/hooks/useToolName.js +0 -6
  357. package/dist/react/hooks/useToolName.js.map +0 -1
  358. package/dist/react/hooks/useToolOutput.d.ts +0 -2
  359. package/dist/react/hooks/useToolOutput.d.ts.map +0 -1
  360. package/dist/react/hooks/useToolOutput.js +0 -5
  361. package/dist/react/hooks/useToolOutput.js.map +0 -1
  362. package/dist/react/hooks/useToolResponseMetadata.d.ts +0 -2
  363. package/dist/react/hooks/useToolResponseMetadata.d.ts.map +0 -1
  364. package/dist/react/hooks/useToolResponseMetadata.js +0 -5
  365. package/dist/react/hooks/useToolResponseMetadata.js.map +0 -1
  366. package/dist/react/hooks/useWidgetState.d.ts.map +0 -1
  367. package/dist/react/hooks/useWidgetState.js.map +0 -1
  368. package/dist/types/openai.d.ts.map +0 -1
  369. package/dist/types/openai.js.map +0 -1
  370. package/dist/vite/absolute_asset_imports_plugin.d.ts +0 -5
  371. package/dist/vite/absolute_asset_imports_plugin.d.ts.map +0 -1
  372. package/dist/vite/absolute_asset_imports_plugin.js +0 -17
  373. package/dist/vite/absolute_asset_imports_plugin.js.map +0 -1
  374. package/dist/vite/application_manifest_plugin.d.ts +0 -10
  375. package/dist/vite/application_manifest_plugin.d.ts.map +0 -1
  376. package/dist/vite/application_manifest_plugin.js +0 -317
  377. package/dist/vite/application_manifest_plugin.js.map +0 -1
  378. package/src/core/__tests__/ApolloClient.test.ts +0 -646
  379. package/src/react/__tests__/ApolloProvider.test.tsx +0 -41
  380. package/src/react/context/ToolUseContext.tsx +0 -31
  381. package/src/react/hooks/__tests__/useCallTool.test.ts +0 -46
  382. package/src/react/hooks/__tests__/useOpenExternal.test.tsx +0 -24
  383. package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +0 -17
  384. package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +0 -15
  385. package/src/react/hooks/__tests__/useToolEffect.test.tsx +0 -67
  386. package/src/react/hooks/__tests__/useToolInput.test.ts +0 -13
  387. package/src/react/hooks/__tests__/useToolName.test.ts +0 -13
  388. package/src/react/hooks/__tests__/useToolOutput.test.tsx +0 -49
  389. package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +0 -49
  390. package/src/react/hooks/useCallTool.ts +0 -13
  391. package/src/react/hooks/useOpenExternal.ts +0 -11
  392. package/src/react/hooks/useRequestDisplayMode.ts +0 -7
  393. package/src/react/hooks/useSendFollowUpMessage.ts +0 -7
  394. package/src/react/hooks/useToolEffect.tsx +0 -37
  395. package/src/react/hooks/useToolInput.ts +0 -7
  396. package/src/react/hooks/useToolName.ts +0 -7
  397. package/src/react/hooks/useToolOutput.ts +0 -5
  398. package/src/react/hooks/useToolResponseMetadata.ts +0 -5
  399. package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +0 -102
  400. package/src/vite/__tests__/application_manifest_plugin.test.ts +0 -1199
  401. package/src/vite/absolute_asset_imports_plugin.ts +0 -22
  402. package/src/vite/application_manifest_plugin.ts +0 -539
  403. /package/dist/{react → openai/react}/hooks/useToolName.d.ts +0 -0
  404. /package/dist/{react → openai/react}/hooks/useWidgetState.js +0 -0
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ export const AppTarget = z.literal(["mcp", "openai"]);
3
+ const Mode = z
4
+ .literal(["development", "production"])
5
+ .or(z.custom((value) => typeof value === "string"));
6
+ const labelsInput = z.exactOptional(z.strictObject({
7
+ toolInvocation: z.exactOptional(z.strictObject({
8
+ invoking: z.string().exactOptional(),
9
+ invoked: z.string().exactOptional(),
10
+ })),
11
+ }));
12
+ const labelsOutput = z.exactOptional(z.strictObject({
13
+ "toolInvocation/invoking": z.string().exactOptional(),
14
+ "toolInvocation/invoked": z.string().exactOptional(),
15
+ }));
16
+ export const ApolloClientAiAppsConfigSchema = z.strictObject({
17
+ name: z.string().exactOptional(),
18
+ description: z.string().exactOptional(),
19
+ version: z.string().exactOptional(),
20
+ entry: z.exactOptional(z.partialRecord(Mode, z.union([z.string(), z.partialRecord(AppTarget, z.string())]))),
21
+ csp: z.exactOptional(z.strictObject({
22
+ connectDomains: z.array(z.string()).exactOptional(),
23
+ frameDomains: z.array(z.string()).exactOptional(),
24
+ redirectDomains: z.array(z.string()).exactOptional(),
25
+ resourceDomains: z.array(z.string()).exactOptional(),
26
+ })),
27
+ widgetSettings: z.exactOptional(z.strictObject({
28
+ prefersBorder: z.boolean().exactOptional(),
29
+ description: z.string().exactOptional(),
30
+ domain: z.string().exactOptional(),
31
+ })),
32
+ labels: z.codec(labelsInput, labelsOutput, {
33
+ encode: () => {
34
+ // encode is currently not used so we can skip the business logic and
35
+ // return an empty object which satisfies the type. If we need to encode
36
+ // labels back to the original form, this will need to be implemented
37
+ return {};
38
+ },
39
+ decode: ({ toolInvocation }) => {
40
+ const config = {};
41
+ if (toolInvocation?.invoking) {
42
+ config["toolInvocation/invoking"] = toolInvocation.invoking;
43
+ }
44
+ if (toolInvocation?.invoked) {
45
+ config["toolInvocation/invoked"] = toolInvocation.invoked;
46
+ }
47
+ return config;
48
+ },
49
+ }),
50
+ });
51
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"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","sourcesContent":["import { z } from \"zod\";\n\nexport const AppTarget = z.literal([\"mcp\", \"openai\"]);\n\nconst Mode = z\n .literal([\"development\", \"production\"])\n .or(z.custom<string & {}>((value) => typeof value === \"string\"));\n\nconst labelsInput = z.exactOptional(\n z.strictObject({\n toolInvocation: z.exactOptional(\n z.strictObject({\n invoking: z.string().exactOptional(),\n invoked: z.string().exactOptional(),\n })\n ),\n })\n);\n\nconst labelsOutput = z.exactOptional(\n z.strictObject({\n \"toolInvocation/invoking\": z.string().exactOptional(),\n \"toolInvocation/invoked\": z.string().exactOptional(),\n })\n);\n\nexport const ApolloClientAiAppsConfigSchema = z.strictObject({\n name: z.string().exactOptional(),\n description: z.string().exactOptional(),\n version: z.string().exactOptional(),\n entry: z.exactOptional(\n z.partialRecord(\n Mode,\n z.union([z.string(), z.partialRecord(AppTarget, z.string())])\n )\n ),\n csp: z.exactOptional(\n z.strictObject({\n connectDomains: z.array(z.string()).exactOptional(),\n frameDomains: z.array(z.string()).exactOptional(),\n redirectDomains: z.array(z.string()).exactOptional(),\n resourceDomains: z.array(z.string()).exactOptional(),\n })\n ),\n widgetSettings: z.exactOptional(\n z.strictObject({\n prefersBorder: z.boolean().exactOptional(),\n description: z.string().exactOptional(),\n domain: z.string().exactOptional(),\n })\n ),\n labels: z.codec(labelsInput, labelsOutput, {\n encode: () => {\n // encode is currently not used so we can skip the business logic and\n // return an empty object which satisfies the type. If we need to encode\n // labels back to the original form, this will need to be implemented\n return {};\n },\n decode: ({ toolInvocation }) => {\n const config: z.infer<typeof labelsOutput> = {};\n\n if (toolInvocation?.invoking) {\n config[\"toolInvocation/invoking\"] = toolInvocation.invoking;\n }\n\n if (toolInvocation?.invoked) {\n config[\"toolInvocation/invoked\"] = toolInvocation.invoked;\n }\n\n return config;\n },\n }),\n});\n"]}
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ import type { ApolloClientAiAppsConfigSchema, AppTarget } from "./schema.js";
3
+ export declare namespace ApolloClientAiAppsConfig {
4
+ type AppTarget = z.infer<typeof AppTarget>;
5
+ type Config = z.input<typeof ApolloClientAiAppsConfigSchema>;
6
+ }
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,8BAA8B,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,CAAC,OAAO,WAAW,wBAAwB,CAAC;IAChD,KAAY,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;IAClD,KAAY,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;CACrE"}
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { ApolloClientAiAppsConfigSchema, AppTarget } from \"./schema.js\";\n\nexport declare namespace ApolloClientAiAppsConfig {\n export type AppTarget = z.infer<typeof AppTarget>;\n export type Config = z.input<typeof ApolloClientAiAppsConfigSchema>;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
- import "../types/openai.js";
3
2
  import type { ApplicationManifest } from "../types/application-manifest.js";
3
+ import { aiClientSymbol } from "../utilities/constants.js";
4
4
  export declare namespace ApolloClient {
5
5
  interface Options extends Omit<BaseApolloClient.Options, "link"> {
6
6
  link?: BaseApolloClient.Options["link"];
@@ -8,8 +8,9 @@ export declare namespace ApolloClient {
8
8
  }
9
9
  }
10
10
  export declare class ApolloClient extends BaseApolloClient {
11
- manifest: ApplicationManifest;
11
+ /** @internal */
12
+ readonly [aiClientSymbol] = true;
12
13
  constructor(options: ApolloClient.Options);
13
- prefetchData(): Promise<void>;
14
+ waitForInitialization(): Promise<void>;
14
15
  }
15
16
  //# sourceMappingURL=ApolloClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKlE,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAY5E,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IAEpC,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;gBAElB,OAAO,EAAE,YAAY,CAAC,OAAO;IAsBnC,YAAY;CA8CnB"}
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,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,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAQnC,qBAAqB;CAC5B"}
@@ -1,65 +1,12 @@
1
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 } from "graphql";
5
- import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import "../types/openai.js";
7
- import { ToolCallLink } from "../link/ToolCallLink.js";
2
+ import { aiClientSymbol } from "../utilities/constants.js";
8
3
  export class ApolloClient extends BaseApolloClient {
9
- manifest;
4
+ /** @internal */
5
+ [aiClientSymbol] = true;
10
6
  constructor(options) {
11
- const link = options.link ?? new ToolCallLink();
12
- if (__DEV__) {
13
- validateTerminatingLink(link);
14
- }
15
- super({
16
- ...options,
17
- link,
18
- // Strip out the prefetch/tool directives so they don't get sent with the operation to the server
19
- documentTransform: new DocumentTransform((document) => {
20
- return removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
21
- }),
22
- });
23
- this.manifest = options.manifest;
24
- }
25
- async prefetchData() {
26
- const toolOutput = window.openai.toolOutput;
27
- // Write prefetched data to the cache
28
- this.manifest.operations.forEach((operation) => {
29
- if (operation.prefetch &&
30
- operation.prefetchID &&
31
- toolOutput?.prefetch?.[operation.prefetchID]) {
32
- this.writeQuery({
33
- query: parse(operation.body),
34
- data: toolOutput.prefetch[operation.prefetchID].data,
35
- });
36
- }
37
- // If this operation has the tool that matches up with the tool that was executed, write the tool result to the cache
38
- if (operation.tools?.find((tool) => `${this.manifest.name}--${tool.name}` ===
39
- window.openai.toolResponseMetadata?.toolName)) {
40
- // We need to include the variables that were used as part of the tool call so that we get a proper cache entry
41
- // However, we only want to include toolInput's that were graphql operation (ignore extraInputs)
42
- const variables = Object.keys(window.openai.toolInput).reduce((obj, key) => operation.variables?.[key] ?
43
- { ...obj, [key]: window.openai.toolInput[key] }
44
- : obj, {});
45
- if (window.openai.toolOutput) {
46
- this.writeQuery({
47
- query: parse(operation.body),
48
- data: window.openai.toolOutput.result.data,
49
- variables,
50
- });
51
- }
52
- }
53
- });
54
- }
55
- }
56
- function validateTerminatingLink(link) {
57
- let terminatingLink = link;
58
- while (terminatingLink.right) {
59
- terminatingLink = terminatingLink.right;
60
- }
61
- if (terminatingLink.constructor.name !== "ToolCallLink") {
62
- 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.");
7
+ super(options);
8
+ throw new Error("Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.");
63
9
  }
10
+ async waitForInitialization() { }
64
11
  }
65
12
  //# sourceMappingURL=ApolloClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"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","sourcesContent":["import type { ApolloLink } from \"@apollo/client\";\nimport { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport { DocumentTransform } from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse } from \"graphql\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport \"../types/openai.js\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport type { FetchResult } from \"@apollo/client\";\n\n// TODO: In the future if/when we support PQs again, do pqLink.concat(toolCallLink)\n// Commenting this out for now.\n// import { sha256 } from \"crypto-hash\";\n// import { PersistedQueryLink } from \"@apollo/client/link/persisted-queries\";\n// const pqLink = new PersistedQueryLink({\n// sha256: (queryString) => sha256(queryString),\n// });\n\nexport declare namespace ApolloClient {\n // This allows us to extend the options with the \"manifest\" option AND make link optional (it is normally required)\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\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 return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n }),\n });\n\n this.manifest = options.manifest;\n }\n\n async prefetchData() {\n const toolOutput = window.openai.toolOutput as {\n prefetch?: Record<string, FetchResult<any>>;\n } | null;\n\n // Write prefetched data to the cache\n this.manifest.operations.forEach((operation) => {\n if (\n operation.prefetch &&\n operation.prefetchID &&\n toolOutput?.prefetch?.[operation.prefetchID]\n ) {\n this.writeQuery({\n query: parse(operation.body),\n data: toolOutput.prefetch[operation.prefetchID].data,\n });\n }\n\n // If this operation has the tool that matches up with the tool that was executed, write the tool result to the cache\n if (\n operation.tools?.find(\n (tool) =>\n `${this.manifest.name}--${tool.name}` ===\n window.openai.toolResponseMetadata?.toolName\n )\n ) {\n // We need to include the variables that were used as part of the tool call so that we get a proper cache entry\n // However, we only want to include toolInput's that were graphql operation (ignore extraInputs)\n const variables = Object.keys(window.openai.toolInput).reduce(\n (obj, key) =>\n operation.variables?.[key] ?\n { ...obj, [key]: window.openai.toolInput[key] }\n : obj,\n {}\n );\n\n if (window.openai.toolOutput) {\n this.writeQuery({\n query: parse(operation.body),\n data: (window.openai.toolOutput.result as any).data,\n variables,\n });\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 (terminatingLink.constructor.name !== \"ToolCallLink\") {\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"]}
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAS3D,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAc,CAAC,CAAC;QAEtB,MAAM,IAAI,KAAK,CACb,qLAAqL,CACtL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,qBAAqB,KAAI,CAAC;CACjC","sourcesContent":["import { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { aiClientSymbol } from \"../utilities/constants.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 /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n super(options as any);\n\n throw new Error(\n \"Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n\n async waitForInitialization() {}\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const Platform: Readonly<{
2
+ readonly target: "mcp" | "openai";
3
+ select<T = unknown, TReturn = T extends (...args: any[]) => infer TReturn_1 ? TReturn_1 : T>(config: {
4
+ mcp?: T;
5
+ openai?: T;
6
+ }): TReturn | undefined;
7
+ }>;
8
+ //# sourceMappingURL=Platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/core/Platform.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ;qBAcc,KAAK,GAAG,QAAQ;WAG/C,CAAC,YACD,OAAO,uBAAuB,GAAG,EAAE,KAAK,MAAM,SAAO,0BAC7C;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,GAAG,SAAS;EAGvD,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { __DEV__ } from "@apollo/client/utilities/environment";
2
+ let warned = false;
3
+ export const Platform = Object.freeze({
4
+ get target() {
5
+ if (__DEV__) {
6
+ if (!warned) {
7
+ console.error("Could not determine the platform target because module conditions are not properly configured for either the `mcp` or `openai` environment. Please ensure you are using the `apolloClientAiApps` vite plugin.");
8
+ warned = true;
9
+ }
10
+ }
11
+ // Even though this return the "unknown" string, this value should never
12
+ // actually be seen at runtime unless something is misconfigured, hence the
13
+ // type cast to the other values.
14
+ return "unknown";
15
+ },
16
+ select(config) {
17
+ return;
18
+ },
19
+ });
20
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../src/core/Platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,IAAI,MAAM;QACR,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,CACX,+MAA+M,CAChN,CAAC;gBACF,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;QACH,CAAC;QAED,wEAAwE;QACxE,2EAA2E;QAC3E,iCAAiC;QACjC,OAAO,SAAwC,CAAC;IAClD,CAAC;IACD,MAAM,CAGJ,MAA+B;QAC/B,OAAO;IACT,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { __DEV__ } from \"@apollo/client/utilities/environment\";\n\nlet warned = false;\n\nexport const Platform = Object.freeze({\n get target() {\n if (__DEV__) {\n if (!warned) {\n console.error(\n \"Could not determine the platform target because module conditions are not properly configured for either the `mcp` or `openai` environment. Please ensure you are using the `apolloClientAiApps` vite plugin.\"\n );\n warned = true;\n }\n }\n\n // Even though this return the \"unknown\" string, this value should never\n // actually be seen at runtime unless something is misconfigured, hence the\n // type cast to the other values.\n return \"unknown\" as unknown as \"mcp\" | \"openai\";\n },\n select<\n T = unknown,\n TReturn = T extends (...args: any[]) => infer TReturn ? TReturn : T,\n >(config: { mcp?: T; openai?: T }): TReturn | undefined {\n return;\n },\n});\n"]}
@@ -0,0 +1,13 @@
1
+ import type { CallToolResult as McpCallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
+ import type { FormattedExecutionResult } from "graphql";
3
+ export declare namespace ApolloMcpServerApps {
4
+ interface StructuredContent {
5
+ result: FormattedExecutionResult;
6
+ prefetch?: Record<string, FormattedExecutionResult>;
7
+ [x: string]: unknown;
8
+ }
9
+ interface CallToolResult extends McpCallToolResult {
10
+ structuredContent: ApolloMcpServerApps.StructuredContent;
11
+ }
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,iBAAiB;QAChC,MAAM,EAAE,wBAAwB,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface StructuredContent {\n result: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,18 +1,5 @@
1
- export type { API, CallTool, DeviceType, DisplayMode, OpenAiGlobals, SafeArea, SafeAreaInsets, Theme, UserAgent, UnknownObject, } from "./types/openai.js";
2
- export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
3
1
  export type { ApplicationManifest, ManifestOperation, ManifestTool, ManifestExtraInput, ManifestCsp, ManifestLabels, ManifestWidgetSettings, } from "./types/application-manifest.js";
4
- export { ToolUseProvider } from "./react/context/ToolUseContext.js";
5
- export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
6
- export { useToolName } from "./react/hooks/useToolName.js";
7
- export { useToolInput } from "./react/hooks/useToolInput.js";
8
- export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
9
- export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
10
- export { useToolEffect } from "./react/hooks/useToolEffect.js";
11
- export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
12
- export { useToolOutput } from "./react/hooks/useToolOutput.js";
13
- export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
14
- export { useWidgetState } from "./react/hooks/useWidgetState.js";
15
2
  export { ApolloClient } from "./core/ApolloClient.js";
16
- export { ApolloProvider } from "./react/ApolloProvider.js";
17
3
  export { ToolCallLink } from "./link/ToolCallLink.js";
4
+ export { Platform } from "./core/Platform.js";
18
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,GAAG,EACH,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,QAAQ,EACR,cAAc,EACd,KAAK,EACL,SAAS,EACT,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE5E,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,4 @@
1
- export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
2
- export { ToolUseProvider } from "./react/context/ToolUseContext.js";
3
- export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
4
- export { useToolName } from "./react/hooks/useToolName.js";
5
- export { useToolInput } from "./react/hooks/useToolInput.js";
6
- export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
7
- export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
8
- export { useToolEffect } from "./react/hooks/useToolEffect.js";
9
- export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
10
- export { useToolOutput } from "./react/hooks/useToolOutput.js";
11
- export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
12
- export { useWidgetState } from "./react/hooks/useWidgetState.js";
13
1
  export { ApolloClient } from "./core/ApolloClient.js";
14
- export { ApolloProvider } from "./react/ApolloProvider.js";
15
2
  export { ToolCallLink } from "./link/ToolCallLink.js";
3
+ export { Platform } from "./core/Platform.js";
16
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAY5E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export type {\n API,\n CallTool,\n DeviceType,\n DisplayMode,\n OpenAiGlobals,\n SafeArea,\n SafeAreaInsets,\n Theme,\n UserAgent,\n UnknownObject,\n} from \"./types/openai.js\";\nexport { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from \"./types/openai.js\";\n\nexport type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport { ToolUseProvider } from \"./react/context/ToolUseContext.js\";\nexport { useOpenAiGlobal } from \"./react/hooks/useOpenAiGlobal.js\";\nexport { useToolName } from \"./react/hooks/useToolName.js\";\nexport { useToolInput } from \"./react/hooks/useToolInput.js\";\nexport { useSendFollowUpMessage } from \"./react/hooks/useSendFollowUpMessage.js\";\nexport { useRequestDisplayMode } from \"./react/hooks/useRequestDisplayMode.js\";\nexport { useToolEffect } from \"./react/hooks/useToolEffect.js\";\nexport { useOpenExternal } from \"./react/hooks/useOpenExternal.js\";\nexport { useToolOutput } from \"./react/hooks/useToolOutput.js\";\nexport { useToolResponseMetadata } from \"./react/hooks/useToolResponseMetadata.js\";\nexport { useWidgetState } from \"./react/hooks/useWidgetState.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ApolloProvider } from \"./react/ApolloProvider.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n\nexport { Platform } from \"./core/Platform.js\";\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./index.js";
2
+ export { Platform } from "./mcp/core/Platform.js";
3
+ export { ApolloClient } from "./mcp/core/ApolloClient.js";
4
+ export { ToolCallLink } from "./mcp/link/ToolCallLink.js";
5
+ //# sourceMappingURL=index.mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mcp.d.ts","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./index.js";
2
+ export { Platform } from "./mcp/core/Platform.js";
3
+ export { ApolloClient } from "./mcp/core/ApolloClient.js";
4
+ export { ToolCallLink } from "./mcp/link/ToolCallLink.js";
5
+ //# sourceMappingURL=index.mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mcp.js","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./mcp/core/Platform.js\";\nexport { ApolloClient } from \"./mcp/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./mcp/link/ToolCallLink.js\";\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./index.js";
2
+ export { Platform } from "./openai/core/Platform.js";
3
+ export { ApolloClient } from "./openai/core/ApolloClient.js";
4
+ export { ToolCallLink } from "./openai/link/ToolCallLink.js";
5
+ //# sourceMappingURL=index.openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.openai.d.ts","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./index.js";
2
+ export { Platform } from "./openai/core/Platform.js";
3
+ export { ApolloClient } from "./openai/core/ApolloClient.js";
4
+ export { ToolCallLink } from "./openai/link/ToolCallLink.js";
5
+ //# sourceMappingURL=index.openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.openai.js","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./openai/core/Platform.js\";\nexport { ApolloClient } from \"./openai/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./openai/link/ToolCallLink.js\";\n"]}
@@ -1,10 +1,10 @@
1
- import { ApolloLink, Observable } from "@apollo/client";
1
+ import { ApolloLink } from "@apollo/client";
2
2
  /**
3
3
  * A terminating link that sends a GraphQL request through an agent tool call.
4
4
  * When providing a custom link chain to `ApolloClient`, `ApolloClient` will
5
5
  * validate that the terminating link is an instance of this link.
6
6
  *
7
- * @example Provding a custom link chain
7
+ * @example Providing a custom link chain
8
8
  *
9
9
  * ```ts
10
10
  * import { ApolloLink } from "@apollo/client";
@@ -22,6 +22,6 @@ import { ApolloLink, Observable } from "@apollo/client";
22
22
  * ```
23
23
  */
24
24
  export declare class ToolCallLink extends ApolloLink {
25
- request(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
25
+ constructor();
26
26
  }
27
27
  //# sourceMappingURL=ToolCallLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOxD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CAkBxE"}
1
+ {"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;;CAQ3C"}
@@ -1,12 +1,10 @@
1
- import { ApolloLink, Observable } from "@apollo/client";
2
- import { from, map } from "rxjs";
3
- import { fallbackHttpConfig, selectHttpOptionsAndBody, } from "@apollo/client/link/http";
1
+ import { ApolloLink } from "@apollo/client";
4
2
  /**
5
3
  * A terminating link that sends a GraphQL request through an agent tool call.
6
4
  * When providing a custom link chain to `ApolloClient`, `ApolloClient` will
7
5
  * validate that the terminating link is an instance of this link.
8
6
  *
9
- * @example Provding a custom link chain
7
+ * @example Providing a custom link chain
10
8
  *
11
9
  * ```ts
12
10
  * import { ApolloLink } from "@apollo/client";
@@ -24,16 +22,9 @@ import { fallbackHttpConfig, selectHttpOptionsAndBody, } from "@apollo/client/li
24
22
  * ```
25
23
  */
26
24
  export class ToolCallLink extends ApolloLink {
27
- request(operation) {
28
- const context = operation.getContext();
29
- const contextConfig = {
30
- http: context.http,
31
- options: context.fetchOptions,
32
- credentials: context.credentials,
33
- headers: context.headers,
34
- };
35
- const { query, variables } = selectHttpOptionsAndBody(operation, fallbackHttpConfig, contextConfig).body;
36
- return from(window.openai.callTool("execute", { query, variables })).pipe(map((result) => ({ data: result.structuredContent.data })));
25
+ constructor() {
26
+ super();
27
+ throw new Error("Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.");
37
28
  }
38
29
  }
39
30
  //# sourceMappingURL=ToolCallLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,SAA+B;QACrC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,aAAa,GAAG;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,YAAY;YAC7B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;QACF,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,wBAAwB,CACnD,SAAS,EACT,kBAAkB,EAClB,aAAa,CACd,CAAC,IAAI,CAAC;QAEP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CACvE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,CAC3D,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink, Observable } from \"@apollo/client\";\nimport { from, map } from \"rxjs\";\nimport {\n fallbackHttpConfig,\n selectHttpOptionsAndBody,\n} from \"@apollo/client/link/http\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Provding a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n request(operation: ApolloLink.Operation): Observable<ApolloLink.Result> {\n const context = operation.getContext();\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n const { query, variables } = selectHttpOptionsAndBody(\n operation,\n fallbackHttpConfig,\n contextConfig\n ).body;\n\n return from(window.openai.callTool(\"execute\", { query, variables })).pipe(\n map((result) => ({ data: result.structuredContent.data }))\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C;QACE,KAAK,EAAE,CAAC;QAER,MAAM,IAAI,KAAK,CACb,mLAAmL,CACpL,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Providing a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n constructor() {\n super();\n\n throw new Error(\n \"Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
+ import type { ApplicationManifest } from "../../types/application-manifest.js";
3
+ import { aiClientSymbol } from "../../utilities/index.js";
4
+ export declare namespace ApolloClient {
5
+ interface Options extends Omit<BaseApolloClient.Options, "link"> {
6
+ link?: BaseApolloClient.Options["link"];
7
+ manifest: ApplicationManifest;
8
+ }
9
+ }
10
+ export declare class ApolloClient extends BaseApolloClient {
11
+ manifest: ApplicationManifest;
12
+ private readonly appManager;
13
+ /** @internal */
14
+ readonly [aiClientSymbol] = true;
15
+ constructor(options: ApolloClient.Options);
16
+ stop(): void;
17
+ waitForInitialization: (() => Promise<void>) & {
18
+ reset: () => void;
19
+ };
20
+ }
21
+ //# sourceMappingURL=ApolloClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,IAAI,gBAAgB,EAEjC,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAGf,MAAM,0BAA0B,CAAC;AAGlC,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;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAuBzC,IAAI;IAKJ,qBAAqB;;MAoBlB;CACJ"}
@@ -0,0 +1,65 @@
1
+ import { ApolloLink, ApolloClient as BaseApolloClient, DocumentTransform, } from "@apollo/client";
2
+ import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
3
+ import { parse } from "graphql";
4
+ import { __DEV__ } from "@apollo/client/utilities/environment";
5
+ import { ToolCallLink } from "../link/ToolCallLink.js";
6
+ import { aiClientSymbol, cacheAsync, getVariablesForOperationFromToolInput, } from "../../utilities/index.js";
7
+ import { McpAppManager } from "./McpAppManager.js";
8
+ export class ApolloClient extends BaseApolloClient {
9
+ manifest;
10
+ appManager;
11
+ /** @internal */
12
+ [aiClientSymbol] = true;
13
+ constructor(options) {
14
+ const link = options.link ?? new ToolCallLink();
15
+ if (__DEV__) {
16
+ validateTerminatingLink(link);
17
+ }
18
+ super({
19
+ ...options,
20
+ link,
21
+ // Strip out the prefetch/tool directives so they don't get sent with the operation to the server
22
+ documentTransform: new DocumentTransform((document) => {
23
+ return removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
24
+ }).concat(options.documentTransform ?? DocumentTransform.identity()),
25
+ });
26
+ this.manifest = options.manifest;
27
+ this.appManager = new McpAppManager(this.manifest);
28
+ }
29
+ stop() {
30
+ super.stop();
31
+ this.appManager.close().catch(() => { });
32
+ }
33
+ waitForInitialization = cacheAsync(async () => {
34
+ const { prefetch, result, toolName, args } = await this.appManager.waitForInitialization();
35
+ this.manifest.operations.forEach((operation) => {
36
+ if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
37
+ this.writeQuery({
38
+ query: parse(operation.body),
39
+ data: prefetch[operation.prefetchID].data,
40
+ });
41
+ }
42
+ if (operation.tools.find((tool) => tool.name === toolName)) {
43
+ this.writeQuery({
44
+ query: parse(operation.body),
45
+ data: result.data,
46
+ variables: getVariablesForOperationFromToolInput(operation, args),
47
+ });
48
+ }
49
+ });
50
+ });
51
+ }
52
+ function validateTerminatingLink(link) {
53
+ let terminatingLink = link;
54
+ while (terminatingLink.right) {
55
+ terminatingLink = terminatingLink.right;
56
+ }
57
+ if (!isNamedLink(terminatingLink) ||
58
+ terminatingLink.name !== "ToolCallLink") {
59
+ 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.");
60
+ }
61
+ }
62
+ function isNamedLink(link) {
63
+ return "name" in link;
64
+ }
65
+ //# sourceMappingURL=ApolloClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,gBAAgB,EAChC,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,UAAU,EACV,qCAAqC,GACtC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnD,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,QAAQ,CAAsB;IACb,UAAU,CAAgB;IAE3C,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,YAAY,EAAE,CAAC;QAEhD,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,IAAI;YACJ,iGAAiG;YACjG,iBAAiB,EAAE,IAAI,iBAAiB,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACpD,OAAO,4BAA4B,CACjC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EACxC,QAAQ,CACR,CAAC;YACL,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,IAAI,iBAAiB,CAAC,QAAQ,EAAE,CAAC;SACrE,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,IAAI;QACF,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,qBAAqB,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;QAC5C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GACxC,MAAM,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC;QAEhD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAC7C,IAAI,SAAS,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7D,IAAI,CAAC,UAAU,CAAC;oBACd,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;oBAC5B,IAAI,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 {\n ApolloLink,\n ApolloClient as BaseApolloClient,\n DocumentTransform,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse } from \"graphql\";\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 getVariablesForOperationFromToolInput,\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 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 return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\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 waitForInitialization = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.waitForInitialization();\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"]}
@@ -0,0 +1,34 @@
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ import type { ApplicationManifest } from "../../types/application-manifest";
3
+ import type { FormattedExecutionResult } from "graphql";
4
+ import type { DocumentNode, OperationVariables } from "@apollo/client";
5
+ /** @internal */
6
+ export declare class McpAppManager {
7
+ #private;
8
+ readonly app: App;
9
+ constructor(manifest: ApplicationManifest);
10
+ get toolName(): string | undefined;
11
+ get toolMetadata(): {
12
+ [x: string]: unknown;
13
+ progressToken?: string | number | undefined;
14
+ "io.modelcontextprotocol/related-task"?: {
15
+ taskId: string;
16
+ } | undefined;
17
+ } | undefined;
18
+ get toolInput(): Record<string, unknown> | undefined;
19
+ waitForInitialization: (() => Promise<{
20
+ toolName: string | undefined;
21
+ args: Record<string, unknown> | undefined;
22
+ result: FormattedExecutionResult;
23
+ prefetch?: Record<string, FormattedExecutionResult>;
24
+ }>) & {
25
+ reset: () => void;
26
+ };
27
+ close(): Promise<void>;
28
+ executeQuery({ query, variables, }: {
29
+ query: DocumentNode;
30
+ variables: OperationVariables | undefined;
31
+ }): Promise<FormattedExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
32
+ private connect;
33
+ }
34
+ //# sourceMappingURL=McpAppManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,gCAAgC,CAAC;AAE3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASvE,gBAAgB;AAChB,qBAAa,aAAa;;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;gBAMN,QAAQ,EAAE,mBAAmB;IAIzC,IAAI,QAAQ,uBAEX;IAED,IAAI,YAAY;;;;;;kBAEf;IAED,IAAI,SAAS,wCAEZ;IAED,qBAAqB;;;;;;;MA4BlB;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;YASa,OAAO;CAWtB"}