@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,63 @@
1
+ import { App, PostMessageTransport } from "@modelcontextprotocol/ext-apps";
2
+ import { print } from "@apollo/client/utilities";
3
+ import { cacheAsync, promiseWithResolvers } from "../../utilities";
4
+ /** @internal */
5
+ export class McpAppManager {
6
+ app;
7
+ #toolName;
8
+ #toolMetadata;
9
+ #toolInput;
10
+ constructor(manifest) {
11
+ this.app = new App({ name: manifest.name, version: manifest.appVersion });
12
+ }
13
+ get toolName() {
14
+ return this.#toolName;
15
+ }
16
+ get toolMetadata() {
17
+ return this.#toolMetadata;
18
+ }
19
+ get toolInput() {
20
+ return this.#toolInput;
21
+ }
22
+ waitForInitialization = cacheAsync(async () => {
23
+ let toolResult = promiseWithResolvers();
24
+ let toolInput = promiseWithResolvers();
25
+ this.app.ontoolresult = (params) => {
26
+ toolResult.resolve(params);
27
+ };
28
+ this.app.ontoolinput = (params) => {
29
+ toolInput.resolve(params);
30
+ };
31
+ await this.connect();
32
+ const { structuredContent, _meta } = await toolResult.promise;
33
+ const { arguments: args } = await toolInput.promise;
34
+ this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;
35
+ this.#toolMetadata = _meta;
36
+ this.#toolInput = args;
37
+ return {
38
+ ...structuredContent,
39
+ toolName: this.toolName,
40
+ args,
41
+ };
42
+ });
43
+ close() {
44
+ return this.app.close();
45
+ }
46
+ async executeQuery({ query, variables, }) {
47
+ const result = (await this.app.callServerTool({
48
+ name: "execute",
49
+ arguments: { query: print(query), variables },
50
+ }));
51
+ return result.structuredContent;
52
+ }
53
+ async connect() {
54
+ try {
55
+ return await this.app.connect(new PostMessageTransport(window.parent, window.parent));
56
+ }
57
+ catch (e) {
58
+ const error = e instanceof Error ? e : new Error("Failed to connect");
59
+ throw error;
60
+ }
61
+ }
62
+ }
63
+ //# sourceMappingURL=McpAppManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAK3E,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAOnE,gBAAgB;AAChB,MAAM,OAAO,aAAa;IACf,GAAG,CAAM;IAElB,SAAS,CAAqB;IAC9B,aAAa,CAA8C;IAC3D,UAAU,CAAsC;IAEhD,YAAY,QAA6B;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,qBAAqB,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE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,CAAC,iBAAiB,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAC3B,IAAI,oBAAoB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CACvD,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAEtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import { App, PostMessageTransport } from \"@modelcontextprotocol/ext-apps\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { ApplicationManifest } from \"../../types/application-manifest\";\nimport type { FormattedExecutionResult } from \"graphql\";\nimport type { DocumentNode, OperationVariables } from \"@apollo/client\";\nimport { print } from \"@apollo/client/utilities\";\nimport { cacheAsync, promiseWithResolvers } from \"../../utilities\";\nimport type { ApolloMcpServerApps } from \"../../core/types\";\n\ntype ExecuteQueryCallToolResult = Omit<CallToolResult, \"structuredContent\"> & {\n structuredContent: FormattedExecutionResult;\n};\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #toolName: string | undefined;\n #toolMetadata: ApolloMcpServerApps.CallToolResult[\"_meta\"];\n #toolInput: Record<string, unknown> | undefined;\n\n constructor(manifest: ApplicationManifest) {\n this.app = new App({ name: manifest.name, version: manifest.appVersion });\n }\n\n get toolName() {\n return this.#toolName;\n }\n\n get toolMetadata() {\n return this.#toolMetadata;\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n waitForInitialization = cacheAsync(async () => {\n let toolResult = promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n let toolInput = promiseWithResolvers<Parameters<App[\"ontoolinput\"]>[0]>();\n\n this.app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n this.app.ontoolinput = (params) => {\n toolInput.resolve(params);\n };\n\n await this.connect();\n\n const { structuredContent, _meta } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;\n this.#toolMetadata = _meta;\n this.#toolInput = args;\n\n return {\n ...structuredContent,\n toolName: this.toolName,\n args,\n };\n });\n\n close() {\n return this.app.close();\n }\n\n async executeQuery({\n query,\n variables,\n }: {\n query: DocumentNode;\n variables: OperationVariables | undefined;\n }) {\n const result = (await this.app.callServerTool({\n name: \"execute\",\n arguments: { query: print(query), variables },\n })) as ExecuteQueryCallToolResult;\n\n return result.structuredContent;\n }\n\n private async connect() {\n try {\n return await this.app.connect(\n new PostMessageTransport(window.parent, window.parent)\n );\n } catch (e) {\n const error = e instanceof Error ? e : new Error(\"Failed to connect\");\n\n throw error;\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const Platform: Readonly<{
2
+ target: "mcp";
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/mcp/core/Platform.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;WAGjB,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;EAKvD,CAAC"}
@@ -0,0 +1,8 @@
1
+ export const Platform = Object.freeze({
2
+ target: "mcp",
3
+ select(config) {
4
+ const value = config.mcp;
5
+ return typeof value === "function" ? value() : value;
6
+ },
7
+ });
8
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/mcp/core/Platform.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,KAAK;IACb,MAAM,CAGJ,MAA+B;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC;QAEzB,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAE,KAAiB,CAAC;IACpE,CAAC;CACF,CAAC,CAAC","sourcesContent":["export const Platform = Object.freeze({\n target: \"mcp\",\n select<\n T = unknown,\n TReturn = T extends (...args: any[]) => infer TReturn ? TReturn : T,\n >(config: { mcp?: T; openai?: T }): TReturn | undefined {\n const value = config.mcp;\n\n return typeof value === \"function\" ? value() : (value as TReturn);\n },\n});\n"]}
@@ -0,0 +1,3 @@
1
+ export { ApolloClient } from "./core/ApolloClient.js";
2
+ export { ToolCallLink } from "./link/ToolCallLink.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export { ApolloClient } from "./core/ApolloClient.js";
2
+ export { ToolCallLink } from "./link/ToolCallLink.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,28 @@
1
+ import { ApolloLink, Observable } from "@apollo/client";
2
+ /**
3
+ * A terminating link that sends a GraphQL request through an agent tool call.
4
+ * When providing a custom link chain to `ApolloClient`, `ApolloClient` will
5
+ * validate that the terminating link is an instance of this link.
6
+ *
7
+ * @example Providing a custom link chain
8
+ *
9
+ * ```ts
10
+ * import { ApolloLink } from "@apollo/client";
11
+ * import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
12
+ *
13
+ * const link = ApolloLink.from([
14
+ * ...otherLinks,
15
+ * new ToolCallLink()
16
+ * ]);
17
+ *
18
+ * const client = new ApolloClient({
19
+ * link,
20
+ * // ...
21
+ * });
22
+ * ```
23
+ */
24
+ export declare class ToolCallLink extends ApolloLink {
25
+ readonly name = "ToolCallLink";
26
+ request(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
27
+ }
28
+ //# sourceMappingURL=ToolCallLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../../src/mcp/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIxD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,QAAQ,CAAC,IAAI,kBAAkB;IAE/B,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CAUxE"}
@@ -0,0 +1,35 @@
1
+ import { ApolloLink, Observable } from "@apollo/client";
2
+ import { from } from "rxjs";
3
+ /**
4
+ * A terminating link that sends a GraphQL request through an agent tool call.
5
+ * When providing a custom link chain to `ApolloClient`, `ApolloClient` will
6
+ * validate that the terminating link is an instance of this link.
7
+ *
8
+ * @example Providing a custom link chain
9
+ *
10
+ * ```ts
11
+ * import { ApolloLink } from "@apollo/client";
12
+ * import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
13
+ *
14
+ * const link = ApolloLink.from([
15
+ * ...otherLinks,
16
+ * new ToolCallLink()
17
+ * ]);
18
+ *
19
+ * const client = new ApolloClient({
20
+ * link,
21
+ * // ...
22
+ * });
23
+ * ```
24
+ */
25
+ export class ToolCallLink extends ApolloLink {
26
+ name = "ToolCallLink";
27
+ request(operation) {
28
+ const client = operation.client;
29
+ return from(client["appManager"].executeQuery({
30
+ query: operation.query,
31
+ variables: operation.variables,
32
+ }));
33
+ }
34
+ }
35
+ //# sourceMappingURL=ToolCallLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../../src/mcp/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IACjC,IAAI,GAAG,cAAc,CAAC;IAE/B,OAAO,CAAC,SAA+B;QACrC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAyB,CAAC;QAEnD,OAAO,IAAI,CACT,MAAM,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC;YAChC,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B,CAAC,CACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink, Observable } from \"@apollo/client\";\nimport { from } from \"rxjs\";\nimport type { ApolloClient as McpApolloClient } from \"../core/ApolloClient\";\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 readonly name = \"ToolCallLink\";\n\n request(operation: ApolloLink.Operation): Observable<ApolloLink.Result> {\n const client = operation.client as McpApolloClient;\n\n return from(\n client[\"appManager\"].executeQuery({\n query: operation.query,\n variables: operation.variables,\n })\n );\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { ApolloClient } from "../../core/ApolloClient.js";
2
+ export declare function useApolloClient(override?: ApolloClient): ApolloClient;
3
+ //# sourceMappingURL=useApolloClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApolloClient.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,YAAY,gBAStD"}
@@ -0,0 +1,9 @@
1
+ import { useApolloClient as useBaseApolloClient } from "@apollo/client/react";
2
+ import { ApolloClient } from "../../core/ApolloClient.js";
3
+ import { aiClientSymbol, invariant } from "../../../utilities/index.js";
4
+ export function useApolloClient(override) {
5
+ const client = useBaseApolloClient(override);
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
+ return client;
8
+ }
9
+ //# sourceMappingURL=useApolloClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,UAAU,eAAe,CAAC,QAAuB;IACrD,MAAM,MAAM,GAAG,mBAAmB,CAAC,QAAQ,CAAiB,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 { ApolloClient } from \"../../core/ApolloClient.js\";\nimport { aiClientSymbol, invariant } from \"../../../utilities/index.js\";\n\nexport function useApolloClient(override?: ApolloClient) {\n const client = useBaseApolloClient(override) as ApolloClient;\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,2 @@
1
+ export declare function useApp(): import("@modelcontextprotocol/ext-apps").App;
2
+ //# sourceMappingURL=useApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApp.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApp.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,iDAErB"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./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/mcp/react/hooks/useApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,MAAM;IACpB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;AAC7C,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useApp() {\n return useApolloClient()[\"appManager\"].app;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function useToolInput(): Record<string, unknown> | undefined;
2
+ //# sourceMappingURL=useToolInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolInput.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInput.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,wCAE3B"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./useApolloClient.js";
2
+ export function useToolInput() {
3
+ return useApolloClient()["appManager"].toolInput;
4
+ }
5
+ //# sourceMappingURL=useToolInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolInput.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,YAAY;IAC1B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useToolInput() {\n return useApolloClient()[\"appManager\"].toolInput;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare function useToolMetadata(): {
2
+ [x: string]: unknown;
3
+ progressToken?: string | number | undefined;
4
+ "io.modelcontextprotocol/related-task"?: {
5
+ taskId: string;
6
+ } | undefined;
7
+ } | undefined;
8
+ //# sourceMappingURL=useToolMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;;;cAE9B"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./useApolloClient.js";
2
+ export function useToolMetadata() {
3
+ return useApolloClient()["appManager"].toolMetadata;
4
+ }
5
+ //# sourceMappingURL=useToolMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolMetadata.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,eAAe;IAC7B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC;AACtD,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useToolMetadata() {\n return useApolloClient()[\"appManager\"].toolMetadata;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function useToolName(): string | undefined;
2
+ //# sourceMappingURL=useToolName.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolName.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolName.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,uBAE1B"}
@@ -0,0 +1,5 @@
1
+ import { useApolloClient } from "./useApolloClient.js";
2
+ export function useToolName() {
3
+ return useApolloClient()["appManager"].toolName;
4
+ }
5
+ //# sourceMappingURL=useToolName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolName.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,WAAW;IACzB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useToolName() {\n return useApolloClient()[\"appManager\"].toolName;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { useApp } from "./hooks/useApp.js";
2
+ export { useToolName } from "./hooks/useToolName.js";
3
+ export { useToolMetadata } from "./hooks/useToolMetadata.js";
4
+ export { useToolInput } from "./hooks/useToolInput.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { useApp } from "./hooks/useApp.js";
2
+ export { useToolName } from "./hooks/useToolName.js";
3
+ export { useToolMetadata } from "./hooks/useToolMetadata.js";
4
+ export { useToolInput } from "./hooks/useToolInput.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { useApp } from \"./hooks/useApp.js\";\nexport { useToolName } from \"./hooks/useToolName.js\";\nexport { useToolMetadata } from \"./hooks/useToolMetadata.js\";\nexport { useToolInput } from \"./hooks/useToolInput.js\";\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/openai/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKlE,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,66 @@
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 { ToolCallLink } from "../link/ToolCallLink.js";
7
+ import { aiClientSymbol, cacheAsync, getVariablesForOperationFromToolInput, } from "../../utilities/index.js";
8
+ import { McpAppManager } from "./McpAppManager.js";
9
+ export class ApolloClient extends BaseApolloClient {
10
+ manifest;
11
+ appManager;
12
+ /** @internal */
13
+ [aiClientSymbol] = true;
14
+ constructor(options) {
15
+ const link = options.link ?? new ToolCallLink();
16
+ if (__DEV__) {
17
+ validateTerminatingLink(link);
18
+ }
19
+ super({
20
+ ...options,
21
+ link,
22
+ // Strip out the prefetch/tool directives so they don't get sent with the operation to the server
23
+ documentTransform: new DocumentTransform((document) => {
24
+ return removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
25
+ }).concat(options.documentTransform ?? DocumentTransform.identity()),
26
+ });
27
+ this.manifest = options.manifest;
28
+ this.appManager = new McpAppManager(this.manifest);
29
+ }
30
+ stop() {
31
+ super.stop();
32
+ this.appManager.close().catch(() => { });
33
+ }
34
+ waitForInitialization = cacheAsync(async () => {
35
+ const { prefetch, result, toolName, args } = await this.appManager.waitForInitialization();
36
+ this.manifest.operations.forEach((operation) => {
37
+ if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
38
+ this.writeQuery({
39
+ query: parse(operation.body),
40
+ data: prefetch[operation.prefetchID].data,
41
+ });
42
+ }
43
+ if (operation.tools.find((tool) => tool.name === toolName)) {
44
+ this.writeQuery({
45
+ query: parse(operation.body),
46
+ data: result.data,
47
+ variables: getVariablesForOperationFromToolInput(operation, args),
48
+ });
49
+ }
50
+ });
51
+ });
52
+ }
53
+ function validateTerminatingLink(link) {
54
+ let terminatingLink = link;
55
+ while (terminatingLink.right) {
56
+ terminatingLink = terminatingLink.right;
57
+ }
58
+ if (!isNamedLink(terminatingLink) ||
59
+ terminatingLink.name !== "ToolCallLink") {
60
+ 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.");
61
+ }
62
+ }
63
+ function isNamedLink(link) {
64
+ return "name" in link;
65
+ }
66
+ //# sourceMapp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ACJ;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 { 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,28 @@
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(): Record<string, unknown> | null;
12
+ get toolInput(): Record<string, unknown> | undefined;
13
+ waitForInitialization: (() => Promise<{
14
+ toolName: string | undefined;
15
+ args: Record<string, unknown> | undefined;
16
+ result: FormattedExecutionResult;
17
+ prefetch?: Record<string, FormattedExecutionResult>;
18
+ }>) & {
19
+ reset: () => void;
20
+ };
21
+ close(): Promise<void>;
22
+ executeQuery({ query, variables, }: {
23
+ query: DocumentNode;
24
+ variables: OperationVariables | undefined;
25
+ }): Promise<FormattedExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
26
+ private connect;
27
+ }
28
+ //# sourceMappingURL=McpAppManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/openai/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,mCAEf;IAED,IAAI,SAAS,wCAEZ;IAED,qBAAqB;;;;;;;MAwClB;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"}
@@ -0,0 +1,73 @@
1
+ import { App, PostMessageTransport } from "@modelcontextprotocol/ext-apps";
2
+ import { print } from "@apollo/client/utilities";
3
+ import { cacheAsync, promiseWithResolvers } from "../../utilities";
4
+ /** @internal */
5
+ export class McpAppManager {
6
+ app;
7
+ #toolName;
8
+ #toolMetadata = null;
9
+ #toolInput;
10
+ constructor(manifest) {
11
+ this.app = new App({ name: manifest.name, version: manifest.appVersion });
12
+ }
13
+ get toolName() {
14
+ return this.#toolName;
15
+ }
16
+ get toolMetadata() {
17
+ return this.#toolMetadata;
18
+ }
19
+ get toolInput() {
20
+ return this.#toolInput;
21
+ }
22
+ waitForInitialization = cacheAsync(async () => {
23
+ let toolResult = promiseWithResolvers();
24
+ let toolInput = promiseWithResolvers();
25
+ this.app.ontoolresult = (params) => {
26
+ toolResult.resolve(params);
27
+ // OpenAI is not consistent about sending `ui/notifications/tool-input`
28
+ // before we get the rool result (which should happen according to the
29
+ // spec). We resolve this promise in case it wasn't sent to avoid stalling
30
+ // initialization indefinitely.
31
+ //
32
+ // When OpenAI fixes this issue and sends `ui/notifications/tool-input`
33
+ // consistently, this can be removed.
34
+ toolInput.resolve({});
35
+ };
36
+ this.app.ontoolinput = (params) => {
37
+ toolInput.resolve(params);
38
+ };
39
+ await this.connect();
40
+ const { structuredContent } = await toolResult.promise;
41
+ const { arguments: args } = await toolInput.promise;
42
+ this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;
43
+ this.#toolInput = args;
44
+ // OpenAI doesn't provide access to `_meta`, so we need to use
45
+ // window.openai.toolResponseMetadata directly
46
+ this.#toolMetadata = window.openai.toolResponseMetadata;
47
+ return {
48
+ ...structuredContent,
49
+ toolName: this.toolName,
50
+ args,
51
+ };
52
+ });
53
+ close() {
54
+ return this.app.close();
55
+ }
56
+ async executeQuery({ query, variables, }) {
57
+ const result = (await this.app.callServerTool({
58
+ name: "execute",
59
+ arguments: { query: print(query), variables },
60
+ }));
61
+ return result.structuredContent;
62
+ }
63
+ async connect() {
64
+ try {
65
+ return await this.app.connect(new PostMessageTransport(window.parent, window.parent));
66
+ }
67
+ catch (e) {
68
+ const error = e instanceof Error ? e : new Error("Failed to connect");
69
+ throw error;
70
+ }
71
+ }
72
+ }
73
+ //# sourceMappingURL=McpAppManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/openai/core/McpAppManager.ts"],"names":[],"mappings":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AC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAEtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import { App, PostMessageTransport } from \"@modelcontextprotocol/ext-apps\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { ApplicationManifest } from \"../../types/application-manifest\";\nimport type { FormattedExecutionResult } from \"graphql\";\nimport type { DocumentNode, OperationVariables } from \"@apollo/client\";\nimport { print } from \"@apollo/client/utilities\";\nimport { cacheAsync, promiseWithResolvers } from \"../../utilities\";\nimport type { ApolloMcpServerApps } from \"../../core/types\";\n\ntype ExecuteQueryCallToolResult = Omit<CallToolResult, \"structuredContent\"> & {\n structuredContent: FormattedExecutionResult;\n};\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #toolName: string | undefined;\n #toolMetadata: Record<string, unknown> | null = null;\n #toolInput: Record<string, unknown> | undefined;\n\n constructor(manifest: ApplicationManifest) {\n this.app = new App({ name: manifest.name, version: manifest.appVersion });\n }\n\n get toolName() {\n return this.#toolName;\n }\n\n get toolMetadata() {\n return this.#toolMetadata;\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n waitForInitialization = cacheAsync(async () => {\n let toolResult = promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n let toolInput = promiseWithResolvers<Parameters<App[\"ontoolinput\"]>[0]>();\n\n this.app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n\n // OpenAI is not consistent about sending `ui/notifications/tool-input`\n // before we get the rool result (which should happen according to the\n // spec). We resolve this promise in case it wasn't sent to avoid stalling\n // initialization indefinitely.\n //\n // When OpenAI fixes this issue and sends `ui/notifications/tool-input`\n // consistently, this can be removed.\n toolInput.resolve({});\n };\n\n this.app.ontoolinput = (params) => {\n toolInput.resolve(params);\n };\n\n await this.connect();\n\n const { structuredContent } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;\n this.#toolInput = args;\n\n // OpenAI doesn't provide access to `_meta`, so we need to use\n // window.openai.toolResponseMetadata directly\n this.#toolMetadata = window.openai.toolResponseMetadata;\n\n return {\n ...structuredContent,\n toolName: this.toolName,\n args,\n };\n });\n\n close() {\n return this.app.close();\n }\n\n async executeQuery({\n query,\n variables,\n }: {\n query: DocumentNode;\n variables: OperationVariables | undefined;\n }) {\n const result = (await this.app.callServerTool({\n name: \"execute\",\n arguments: { query: print(query), variables },\n })) as ExecuteQueryCallToolResult;\n\n return result.structuredContent;\n }\n\n private async connect() {\n try {\n return await this.app.connect(\n new PostMessageTransport(window.parent, window.parent)\n );\n } catch (e) {\n const error = e instanceof Error ? e : new Error(\"Failed to connect\");\n\n throw error;\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const Platform: Readonly<{
2
+ target: "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/openai/core/Platform.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;WAGjB,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;EAKvD,CAAC"}
@@ -0,0 +1,8 @@
1
+ export const Platform = Object.freeze({
2
+ target: "openai",
3
+ select(config) {
4
+ const value = config.openai;
5
+ return typeof value === "function" ? value() : value;
6
+ },
7
+ });
8
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/openai/core/Platform.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,QAAQ;IAChB,MAAM,CAGJ,MAA+B;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;QAE5B,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAE,KAAiB,CAAC;IACpE,CAAC;CACF,CAAC,CAAC","sourcesContent":["export const Platform = Object.freeze({\n target: \"openai\",\n select<\n T = unknown,\n TReturn = T extends (...args: any[]) => infer TReturn ? TReturn : T,\n >(config: { mcp?: T; openai?: T }): TReturn | undefined {\n const value = config.openai;\n\n return typeof value === \"function\" ? value() : (value as TReturn);\n },\n});\n"]}
@@ -0,0 +1,12 @@
1
+ import type { API, OpenAiGlobals } from "./types.js";
2
+ import type { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types.js";
3
+ declare global {
4
+ interface Window {
5
+ openai: API<any> & OpenAiGlobals;
6
+ }
7
+ interface WindowEventMap {
8
+ [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
9
+ }
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/openai/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;KAClC;IAED,UAAU,cAAc;QACtB,CAAC,sBAAsB,CAAC,EAAE,eAAe,CAAC;KAC3C;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/openai/globals.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC","sourcesContent":["import type { API, OpenAiGlobals } from \"./types.js\";\nimport type { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from \"./types.js\";\n\ndeclare global {\n interface Window {\n openai: API<any> & OpenAiGlobals;\n }\n\n interface WindowEventMap {\n [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;\n }\n}\n\nexport {};\n"]}
@@ -0,0 +1,3 @@
1
+ export { ApolloClient } from "./core/ApolloClient.js";
2
+ export { ToolCallLink } from "./link/ToolCallLink.js";
3
+ //# sourceMappingURL=index.d.ts.map