@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.
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/pr.yaml +23 -1
- package/.github/workflows/release.yaml +1 -5
- package/.github/workflows/verify-changeset.yml +112 -21
- package/CHANGELOG.md +361 -0
- package/__mocks__/fs/promises.cjs +3 -0
- package/__mocks__/fs.cjs +3 -0
- package/dist/config/defineConfig.d.ts +28 -0
- package/dist/config/defineConfig.d.ts.map +1 -0
- package/dist/config/defineConfig.js +7 -0
- package/dist/config/defineConfig.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +29 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +51 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/types.d.ts +7 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/ApolloClient.d.ts +4 -3
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +6 -59
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/core/Platform.d.ts +8 -0
- package/dist/core/Platform.d.ts.map +1 -0
- package/dist/core/Platform.js +20 -0
- package/dist/core/Platform.js.map +1 -0
- package/dist/core/types.d.ts +13 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mcp.d.ts +5 -0
- package/dist/index.mcp.d.ts.map +1 -0
- package/dist/index.mcp.js +5 -0
- package/dist/index.mcp.js.map +1 -0
- package/dist/index.openai.d.ts +5 -0
- package/dist/index.openai.d.ts.map +1 -0
- package/dist/index.openai.js +5 -0
- package/dist/index.openai.js.map +1 -0
- package/dist/link/ToolCallLink.d.ts +3 -3
- package/dist/link/ToolCallLink.d.ts.map +1 -1
- package/dist/link/ToolCallLink.js +5 -14
- package/dist/link/ToolCallLink.js.map +1 -1
- package/dist/mcp/core/ApolloClient.d.ts +21 -0
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -0
- package/dist/mcp/core/ApolloClient.js +65 -0
- package/dist/mcp/core/ApolloClient.js.map +1 -0
- package/dist/mcp/core/McpAppManager.d.ts +34 -0
- package/dist/mcp/core/McpAppManager.d.ts.map +1 -0
- package/dist/mcp/core/McpAppManager.js +63 -0
- package/dist/mcp/core/McpAppManager.js.map +1 -0
- package/dist/mcp/core/Platform.d.ts +8 -0
- package/dist/mcp/core/Platform.d.ts.map +1 -0
- package/dist/mcp/core/Platform.js +8 -0
- package/dist/mcp/core/Platform.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/link/ToolCallLink.d.ts +28 -0
- package/dist/mcp/link/ToolCallLink.d.ts.map +1 -0
- package/dist/mcp/link/ToolCallLink.js +35 -0
- package/dist/mcp/link/ToolCallLink.js.map +1 -0
- package/dist/mcp/react/hooks/useApolloClient.d.ts +3 -0
- package/dist/mcp/react/hooks/useApolloClient.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useApolloClient.js +9 -0
- package/dist/mcp/react/hooks/useApolloClient.js.map +1 -0
- package/dist/mcp/react/hooks/useApp.d.ts +2 -0
- package/dist/mcp/react/hooks/useApp.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useApp.js +5 -0
- package/dist/mcp/react/hooks/useApp.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts +2 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.js +5 -0
- package/dist/mcp/react/hooks/useToolInput.js.map +1 -0
- package/dist/mcp/react/hooks/useToolMetadata.d.ts +8 -0
- package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolMetadata.js +5 -0
- package/dist/mcp/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/mcp/react/hooks/useToolName.d.ts +2 -0
- package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolName.js +5 -0
- package/dist/mcp/react/hooks/useToolName.js.map +1 -0
- package/dist/mcp/react/index.d.ts +5 -0
- package/dist/mcp/react/index.d.ts.map +1 -0
- package/dist/mcp/react/index.js +5 -0
- package/dist/mcp/react/index.js.map +1 -0
- package/dist/openai/core/ApolloClient.d.ts +21 -0
- package/dist/openai/core/ApolloClient.d.ts.map +1 -0
- package/dist/openai/core/ApolloClient.js +66 -0
- package/dist/openai/core/ApolloClient.js.map +1 -0
- package/dist/openai/core/McpAppManager.d.ts +28 -0
- package/dist/openai/core/McpAppManager.d.ts.map +1 -0
- package/dist/openai/core/McpAppManager.js +73 -0
- package/dist/openai/core/McpAppManager.js.map +1 -0
- package/dist/openai/core/Platform.d.ts +8 -0
- package/dist/openai/core/Platform.d.ts.map +1 -0
- package/dist/openai/core/Platform.js +8 -0
- package/dist/openai/core/Platform.js.map +1 -0
- package/dist/openai/globals.d.ts +12 -0
- package/dist/openai/globals.d.ts.map +1 -0
- package/dist/openai/globals.js +2 -0
- package/dist/openai/globals.js.map +1 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +3 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/openai/link/ToolCallLink.d.ts +28 -0
- package/dist/openai/link/ToolCallLink.d.ts.map +1 -0
- package/dist/openai/link/ToolCallLink.js +35 -0
- package/dist/openai/link/ToolCallLink.js.map +1 -0
- package/dist/openai/react/hooks/useApolloClient.d.ts +3 -0
- package/dist/openai/react/hooks/useApolloClient.d.ts.map +1 -0
- package/dist/openai/react/hooks/useApolloClient.js +9 -0
- package/dist/openai/react/hooks/useApolloClient.js.map +1 -0
- package/dist/openai/react/hooks/useApp.d.ts +2 -0
- package/dist/openai/react/hooks/useApp.d.ts.map +1 -0
- package/dist/openai/react/hooks/useApp.js +5 -0
- package/dist/openai/react/hooks/useApp.js.map +1 -0
- package/dist/openai/react/hooks/useOpenAiGlobal.d.ts +3 -0
- package/dist/openai/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
- package/dist/{react → openai/react}/hooks/useOpenAiGlobal.js +1 -1
- package/dist/openai/react/hooks/useOpenAiGlobal.js.map +1 -0
- package/dist/openai/react/hooks/useToolInput.d.ts +2 -0
- package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolInput.js +5 -0
- package/dist/openai/react/hooks/useToolInput.js.map +1 -0
- package/dist/openai/react/hooks/useToolMetadata.d.ts +2 -0
- package/dist/openai/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolMetadata.js +5 -0
- package/dist/openai/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/openai/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolName.js +5 -0
- package/dist/openai/react/hooks/useToolName.js.map +1 -0
- package/dist/{react → openai/react}/hooks/useWidgetState.d.ts +1 -1
- package/dist/openai/react/hooks/useWidgetState.d.ts.map +1 -0
- package/dist/openai/react/hooks/useWidgetState.js.map +1 -0
- package/dist/openai/react/index.d.ts +6 -0
- package/dist/openai/react/index.d.ts.map +1 -0
- package/dist/openai/react/index.js +6 -0
- package/dist/openai/react/index.js.map +1 -0
- package/dist/{types/openai.d.ts → openai/types.d.ts} +7 -11
- package/dist/openai/types.d.ts.map +1 -0
- package/dist/{types/openai.js → openai/types.js} +1 -1
- package/dist/openai/types.js.map +1 -0
- package/dist/react/ApolloProvider.d.ts +6 -2
- package/dist/react/ApolloProvider.d.ts.map +1 -1
- package/dist/react/ApolloProvider.js +12 -27
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mcp.d.ts +3 -0
- package/dist/react/index.mcp.d.ts.map +1 -0
- package/dist/react/index.mcp.js +3 -0
- package/dist/react/index.mcp.js.map +1 -0
- package/dist/react/index.openai.d.ts +3 -0
- package/dist/react/index.openai.d.ts.map +1 -0
- package/dist/react/index.openai.js +3 -0
- package/dist/react/index.openai.js.map +1 -0
- package/dist/react/missingHook.d.ts +2 -0
- package/dist/react/missingHook.d.ts.map +1 -0
- package/dist/react/missingHook.js +6 -0
- package/dist/react/missingHook.js.map +1 -0
- package/dist/tsconfig/core/tsconfig.json +5 -0
- package/dist/tsconfig/mcp/tsconfig.json +6 -0
- package/dist/tsconfig/openai/tsconfig.json +7 -0
- package/dist/types/application-manifest.d.ts +5 -1
- package/dist/types/application-manifest.d.ts.map +1 -1
- package/dist/types/application-manifest.js.map +1 -1
- package/dist/utilities/cacheAsync.d.ts +4 -0
- package/dist/utilities/cacheAsync.d.ts.map +1 -0
- package/dist/utilities/cacheAsync.js +19 -0
- package/dist/utilities/cacheAsync.js.map +1 -0
- package/dist/utilities/constants.d.ts +6 -0
- package/dist/utilities/constants.d.ts.map +1 -0
- package/dist/utilities/constants.js +6 -0
- package/dist/utilities/constants.js.map +1 -0
- package/dist/utilities/emptyModule.d.ts +2 -0
- package/dist/utilities/emptyModule.d.ts.map +1 -0
- package/dist/utilities/emptyModule.js +2 -0
- package/dist/utilities/emptyModule.js.map +1 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.d.ts +5 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.d.ts.map +1 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.js +18 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.js.map +1 -0
- package/dist/utilities/index.d.ts +6 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +6 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/invariant.d.ts +2 -0
- package/dist/utilities/invariant.d.ts.map +1 -0
- package/dist/utilities/invariant.js +6 -0
- package/dist/utilities/invariant.js.map +1 -0
- package/dist/utilities/promiseWithResolvers.d.ts +7 -0
- package/dist/utilities/promiseWithResolvers.d.ts.map +1 -0
- package/dist/utilities/promiseWithResolvers.js +16 -0
- package/dist/utilities/promiseWithResolvers.js.map +1 -0
- package/dist/vite/__tests__/utilities/build.d.ts +41 -0
- package/dist/vite/__tests__/utilities/build.d.ts.map +1 -0
- package/dist/vite/__tests__/utilities/build.js +63 -0
- package/dist/vite/__tests__/utilities/build.js.map +1 -0
- package/dist/vite/apolloClientAiApps.d.ts +14 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -0
- package/dist/vite/apolloClientAiApps.js +350 -0
- package/dist/vite/apolloClientAiApps.js.map +1 -0
- package/dist/vite/index.d.ts +1 -2
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +1 -2
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/utilities/config.d.ts +2 -0
- package/dist/vite/utilities/config.d.ts.map +1 -0
- package/dist/vite/utilities/config.js +11 -0
- package/dist/vite/utilities/config.js.map +1 -0
- package/dist/vite/utilities/graphql.d.ts +20 -0
- package/dist/vite/utilities/graphql.d.ts.map +1 -0
- package/dist/vite/utilities/graphql.js +42 -0
- package/dist/vite/utilities/graphql.js.map +1 -0
- package/knope.toml +1 -1
- package/package.json +105 -9
- package/src/config/defineConfig.ts +8 -0
- package/src/config/index.ts +2 -0
- package/src/config/schema.ts +73 -0
- package/src/config/types.ts +7 -0
- package/src/core/ApolloClient.ts +7 -95
- package/src/core/Platform.ts +27 -0
- package/src/core/types.ts +14 -0
- package/src/index.mcp.ts +5 -0
- package/src/index.openai.ts +5 -0
- package/src/index.ts +2 -27
- package/src/link/ToolCallLink.ts +6 -22
- package/src/mcp/core/ApolloClient.ts +102 -0
- package/src/mcp/core/McpAppManager.ts +98 -0
- package/src/mcp/core/Platform.ts +11 -0
- package/src/mcp/core/__tests__/ApolloClient.test.ts +464 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/link/ToolCallLink.ts +40 -0
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +53 -0
- package/src/mcp/react/hooks/__tests__/useApp.test.tsx +46 -0
- package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +50 -0
- package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +53 -0
- package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +50 -0
- package/src/mcp/react/hooks/useApolloClient.ts +14 -0
- package/src/mcp/react/hooks/useApp.ts +5 -0
- package/src/mcp/react/hooks/useToolInput.ts +5 -0
- package/src/mcp/react/hooks/useToolMetadata.ts +5 -0
- package/src/mcp/react/hooks/useToolName.ts +5 -0
- package/src/mcp/react/index.ts +4 -0
- package/src/openai/core/ApolloClient.ts +100 -0
- package/src/openai/core/McpAppManager.ts +110 -0
- package/src/openai/core/Platform.ts +11 -0
- package/src/openai/core/__tests__/ApolloClient.test.ts +537 -0
- package/src/openai/globals.ts +14 -0
- package/src/openai/index.ts +2 -0
- package/src/openai/link/ToolCallLink.ts +40 -0
- package/src/{react → openai/react}/hooks/__tests__/useOpenAiGlobal.test.ts +1 -1
- package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +85 -0
- package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +86 -0
- package/src/openai/react/hooks/__tests__/useToolName.test.tsx +50 -0
- package/src/{react → openai/react}/hooks/__tests__/useWidgetState.test.tsx +1 -1
- package/src/openai/react/hooks/useApolloClient.ts +14 -0
- package/src/openai/react/hooks/useApp.ts +5 -0
- package/src/{react → openai/react}/hooks/useOpenAiGlobal.ts +2 -2
- package/src/openai/react/hooks/useToolInput.ts +5 -0
- package/src/openai/react/hooks/useToolMetadata.ts +5 -0
- package/src/openai/react/hooks/useToolName.ts +5 -0
- package/src/{react → openai/react}/hooks/useWidgetState.ts +1 -1
- package/src/openai/react/index.ts +5 -0
- package/src/{types/openai.ts → openai/types.ts} +9 -13
- package/src/react/ApolloProvider.tsx +23 -31
- package/src/react/__tests__/ApolloProvider/mcp.test.tsx +74 -0
- package/src/react/__tests__/ApolloProvider/openai.test.tsx +146 -0
- package/src/react/index.mcp.ts +7 -0
- package/src/react/index.openai.ts +7 -0
- package/src/react/index.ts +19 -0
- package/src/react/missingHook.ts +9 -0
- package/src/testing/internal/index.ts +8 -0
- package/src/testing/internal/matchers/index.ts +2 -0
- package/src/testing/internal/matchers/toComplete.ts +46 -0
- package/src/testing/internal/matchers/toEmitValue.ts +71 -0
- package/src/testing/internal/matchers/types.ts +3 -0
- package/src/testing/internal/mcp/graphqlToolResult.ts +31 -0
- package/src/testing/internal/mcp/minimalHostContextWithToolName.ts +9 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +188 -0
- package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +22 -9
- package/src/testing/internal/react/renderAsync.ts +7 -0
- package/src/testing/internal/utilities/ObservableStream.ts +172 -0
- package/src/testing/internal/utilities/getSerializableProperties.ts +55 -0
- package/src/testing/internal/utilities/mockApplicationManifest.ts +39 -0
- package/src/testing/internal/utilities/spyOnConsole.ts +29 -0
- package/src/testing/internal/utilities/wait.ts +3 -0
- package/src/tsconfig/core/tsconfig.json +5 -0
- package/src/tsconfig/mcp/tsconfig.json +6 -0
- package/src/tsconfig/openai/tsconfig.json +7 -0
- package/src/types/application-manifest.ts +7 -1
- package/src/utilities/__tests__/cacheAsync.test.ts +64 -0
- package/src/utilities/cacheAsync.ts +25 -0
- package/src/utilities/constants.ts +5 -0
- package/src/utilities/emptyModule.ts +1 -0
- package/src/utilities/getVariablesForOperationFromToolInput.ts +27 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/invariant.ts +5 -0
- package/src/utilities/promiseWithResolvers.ts +18 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +1521 -0
- package/src/vite/__tests__/utilities/build.ts +72 -0
- package/src/vite/apolloClientAiApps.ts +515 -0
- package/src/vite/index.ts +1 -2
- package/src/vite/utilities/config.ts +13 -0
- package/src/vite/utilities/graphql.ts +123 -0
- package/tsconfig.base.json +2 -2
- package/tsconfig.vite.build.json +4 -1
- package/tsconfig.vite.json +8 -2
- package/vitest-setup.ts +28 -0
- package/dist/react/context/ToolUseContext.d.ts +0 -16
- package/dist/react/context/ToolUseContext.d.ts.map +0 -1
- package/dist/react/context/ToolUseContext.js +0 -11
- package/dist/react/context/ToolUseContext.js.map +0 -1
- package/dist/react/hooks/useCallTool.d.ts +0 -4
- package/dist/react/hooks/useCallTool.d.ts.map +0 -1
- package/dist/react/hooks/useCallTool.js +0 -5
- package/dist/react/hooks/useCallTool.js.map +0 -1
- package/dist/react/hooks/useOpenAiGlobal.d.ts +0 -3
- package/dist/react/hooks/useOpenAiGlobal.d.ts.map +0 -1
- package/dist/react/hooks/useOpenAiGlobal.js.map +0 -1
- package/dist/react/hooks/useOpenExternal.d.ts +0 -4
- package/dist/react/hooks/useOpenExternal.d.ts.map +0 -1
- package/dist/react/hooks/useOpenExternal.js +0 -5
- package/dist/react/hooks/useOpenExternal.js.map +0 -1
- package/dist/react/hooks/useRequestDisplayMode.d.ts +0 -7
- package/dist/react/hooks/useRequestDisplayMode.d.ts.map +0 -1
- package/dist/react/hooks/useRequestDisplayMode.js +0 -6
- package/dist/react/hooks/useRequestDisplayMode.js.map +0 -1
- package/dist/react/hooks/useSendFollowUpMessage.d.ts +0 -2
- package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +0 -1
- package/dist/react/hooks/useSendFollowUpMessage.js +0 -8
- package/dist/react/hooks/useSendFollowUpMessage.js.map +0 -1
- package/dist/react/hooks/useToolEffect.d.ts +0 -3
- package/dist/react/hooks/useToolEffect.d.ts.map +0 -1
- package/dist/react/hooks/useToolEffect.js +0 -28
- package/dist/react/hooks/useToolEffect.js.map +0 -1
- package/dist/react/hooks/useToolInput.d.ts +0 -2
- package/dist/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/react/hooks/useToolInput.js +0 -6
- package/dist/react/hooks/useToolInput.js.map +0 -1
- package/dist/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/react/hooks/useToolName.js +0 -6
- package/dist/react/hooks/useToolName.js.map +0 -1
- package/dist/react/hooks/useToolOutput.d.ts +0 -2
- package/dist/react/hooks/useToolOutput.d.ts.map +0 -1
- package/dist/react/hooks/useToolOutput.js +0 -5
- package/dist/react/hooks/useToolOutput.js.map +0 -1
- package/dist/react/hooks/useToolResponseMetadata.d.ts +0 -2
- package/dist/react/hooks/useToolResponseMetadata.d.ts.map +0 -1
- package/dist/react/hooks/useToolResponseMetadata.js +0 -5
- package/dist/react/hooks/useToolResponseMetadata.js.map +0 -1
- package/dist/react/hooks/useWidgetState.d.ts.map +0 -1
- package/dist/react/hooks/useWidgetState.js.map +0 -1
- package/dist/types/openai.d.ts.map +0 -1
- package/dist/types/openai.js.map +0 -1
- package/dist/vite/absolute_asset_imports_plugin.d.ts +0 -5
- package/dist/vite/absolute_asset_imports_plugin.d.ts.map +0 -1
- package/dist/vite/absolute_asset_imports_plugin.js +0 -17
- package/dist/vite/absolute_asset_imports_plugin.js.map +0 -1
- package/dist/vite/application_manifest_plugin.d.ts +0 -10
- package/dist/vite/application_manifest_plugin.d.ts.map +0 -1
- package/dist/vite/application_manifest_plugin.js +0 -317
- package/dist/vite/application_manifest_plugin.js.map +0 -1
- package/src/core/__tests__/ApolloClient.test.ts +0 -646
- package/src/react/__tests__/ApolloProvider.test.tsx +0 -41
- package/src/react/context/ToolUseContext.tsx +0 -31
- package/src/react/hooks/__tests__/useCallTool.test.ts +0 -46
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +0 -24
- package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +0 -17
- package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +0 -15
- package/src/react/hooks/__tests__/useToolEffect.test.tsx +0 -67
- package/src/react/hooks/__tests__/useToolInput.test.ts +0 -13
- package/src/react/hooks/__tests__/useToolName.test.ts +0 -13
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +0 -49
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +0 -49
- package/src/react/hooks/useCallTool.ts +0 -13
- package/src/react/hooks/useOpenExternal.ts +0 -11
- package/src/react/hooks/useRequestDisplayMode.ts +0 -7
- package/src/react/hooks/useSendFollowUpMessage.ts +0 -7
- package/src/react/hooks/useToolEffect.tsx +0 -37
- package/src/react/hooks/useToolInput.ts +0 -7
- package/src/react/hooks/useToolName.ts +0 -7
- package/src/react/hooks/useToolOutput.ts +0 -5
- package/src/react/hooks/useToolResponseMetadata.ts +0 -5
- package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +0 -102
- package/src/vite/__tests__/application_manifest_plugin.test.ts +0 -1199
- package/src/vite/absolute_asset_imports_plugin.ts +0 -22
- package/src/vite/application_manifest_plugin.ts +0 -539
- /package/dist/{react → openai/react}/hooks/useToolName.d.ts +0 -0
- /package/dist/{react → openai/react}/hooks/useWidgetState.js +0 -0
package/package.json
CHANGED
|
@@ -1,19 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://www.schemastore.org/package.json",
|
|
2
3
|
"name": "@apollo/client-ai-apps",
|
|
3
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
4
5
|
"publishConfig": {
|
|
5
6
|
"access": "public"
|
|
6
7
|
},
|
|
7
8
|
"repository": {
|
|
8
|
-
"url": "https://github.com/apollographql/apollo-ai-apps
|
|
9
|
+
"url": "https://github.com/apollographql/apollo-client-ai-apps"
|
|
9
10
|
},
|
|
10
11
|
"type": "module",
|
|
11
12
|
"main": "dist/index.js",
|
|
12
13
|
"module": "dist/index.js",
|
|
13
14
|
"types": "dist/index.d.ts",
|
|
14
15
|
"exports": {
|
|
15
|
-
".":
|
|
16
|
-
|
|
16
|
+
".": {
|
|
17
|
+
"mcp": {
|
|
18
|
+
"types": "./dist/index.mcp.d.ts",
|
|
19
|
+
"default": "./dist/index.mcp.js"
|
|
20
|
+
},
|
|
21
|
+
"openai": {
|
|
22
|
+
"types": "./dist/index.openai.d.ts",
|
|
23
|
+
"default": "./dist/index.openai.js"
|
|
24
|
+
},
|
|
25
|
+
"default": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./config": {
|
|
31
|
+
"types": "./dist/config/index.d.ts",
|
|
32
|
+
"default": "./dist/config/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./mcp": {
|
|
35
|
+
"mcp": {
|
|
36
|
+
"types": "./dist/mcp/index.d.ts",
|
|
37
|
+
"default": "./dist/mcp/index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": "./dist/utilities/emptyModule.js"
|
|
40
|
+
},
|
|
41
|
+
"./mcp/react": {
|
|
42
|
+
"mcp": {
|
|
43
|
+
"types": "./dist/mcp/react/index.d.ts",
|
|
44
|
+
"default": "./dist/mcp/react/index.js"
|
|
45
|
+
},
|
|
46
|
+
"default": "./dist/utilities/emptyModule.js"
|
|
47
|
+
},
|
|
48
|
+
"./openai": {
|
|
49
|
+
"openai": {
|
|
50
|
+
"types": "./dist/openai/index.d.ts",
|
|
51
|
+
"default": "./dist/openai/index.js"
|
|
52
|
+
},
|
|
53
|
+
"default": "./dist/utilities/emptyModule.js"
|
|
54
|
+
},
|
|
55
|
+
"./openai/globals": {
|
|
56
|
+
"openai": {
|
|
57
|
+
"types": "./dist/openai/globals.d.ts",
|
|
58
|
+
"default": "./dist/openai/globals.js"
|
|
59
|
+
},
|
|
60
|
+
"default": "./dist/utilities/emptyModule.js"
|
|
61
|
+
},
|
|
62
|
+
"./openai/react": {
|
|
63
|
+
"openai": {
|
|
64
|
+
"types": "./dist/openai/react/index.d.ts",
|
|
65
|
+
"default": "./dist/openai/react/index.js"
|
|
66
|
+
},
|
|
67
|
+
"default": "./dist/utilities/emptyModule.js"
|
|
68
|
+
},
|
|
69
|
+
"./react": {
|
|
70
|
+
"mcp": {
|
|
71
|
+
"types": "./dist/react/index.mcp.d.ts",
|
|
72
|
+
"default": "./dist/react/index.mcp.js"
|
|
73
|
+
},
|
|
74
|
+
"openai": {
|
|
75
|
+
"types": "./dist/react/index.openai.d.ts",
|
|
76
|
+
"default": "./dist/react/index.openai.js"
|
|
77
|
+
},
|
|
78
|
+
"default": {
|
|
79
|
+
"types": "./dist/react/index.d.ts",
|
|
80
|
+
"default": "./dist/react/index.js"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"./tsconfig/core": "./dist/tsconfig/core/tsconfig.json",
|
|
84
|
+
"./tsconfig/mcp": "./dist/tsconfig/mcp/tsconfig.json",
|
|
85
|
+
"./tsconfig/openai": "./dist/tsconfig/openai/tsconfig.json",
|
|
86
|
+
"./vite": {
|
|
87
|
+
"types": "./dist/vite/index.d.ts",
|
|
88
|
+
"default": "./dist/vite/index.js"
|
|
89
|
+
}
|
|
17
90
|
},
|
|
18
91
|
"devEngines": {
|
|
19
92
|
"packageManager": {
|
|
@@ -23,16 +96,17 @@
|
|
|
23
96
|
"scripts": {
|
|
24
97
|
"dev": "node ./scripts/dev.mjs",
|
|
25
98
|
"prebuild": "npm run clean",
|
|
26
|
-
"build": "npm run build:src && npm run build:vite",
|
|
99
|
+
"build": "npm run build:src && npm run build:vite && npm run copy-ts-configs",
|
|
27
100
|
"build:src": "tsc --project tsconfig.src.build.json",
|
|
28
101
|
"build:vite": "tsc --project tsconfig.vite.build.json",
|
|
102
|
+
"copy-ts-configs": "copyfiles -u 1 \"src/tsconfig/*/tsconfig.json\" dist",
|
|
29
103
|
"clean": "rimraf dist",
|
|
30
|
-
"test": "vitest
|
|
31
|
-
"test:watch": "vitest --coverage",
|
|
104
|
+
"test": "vitest",
|
|
32
105
|
"changeset": "knope document-change",
|
|
33
106
|
"format": "prettier --write .",
|
|
34
107
|
"format:check": "prettier --check .",
|
|
35
|
-
"typecheck": "tsc -b --emitDeclarationOnly"
|
|
108
|
+
"typecheck": "tsc -b --emitDeclarationOnly",
|
|
109
|
+
"attw": "npm run build && attw --pack . --ignore-rules cjs-resolves-to-esm --profile node16"
|
|
36
110
|
},
|
|
37
111
|
"keywords": [],
|
|
38
112
|
"author": "",
|
|
@@ -40,31 +114,53 @@
|
|
|
40
114
|
"description": "",
|
|
41
115
|
"devDependencies": {
|
|
42
116
|
"@apollo/client": "^4.0.12",
|
|
117
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
118
|
+
"@modelcontextprotocol/ext-apps": "^1.0.1",
|
|
43
119
|
"@testing-library/jest-dom": "^6.9.1",
|
|
44
120
|
"@testing-library/react": "^16.3.0",
|
|
45
121
|
"@testing-library/react-render-stream": "^2.0.2",
|
|
122
|
+
"@types/mock-require": "^3.0.0",
|
|
46
123
|
"@types/node": "^24.10.4",
|
|
47
124
|
"@types/react": "^19.2.2",
|
|
48
125
|
"@vitejs/plugin-react": "^5.1.1",
|
|
49
126
|
"@vitest/coverage-v8": "^4.0.13",
|
|
127
|
+
"copyfiles": "^2.4.1",
|
|
50
128
|
"esbuild": "^0.25.12",
|
|
51
129
|
"graphql": "^16.9.0",
|
|
52
130
|
"happy-dom": "^20.0.10",
|
|
131
|
+
"memfs": "^4.56.10",
|
|
132
|
+
"mock-require": "^3.0.3",
|
|
53
133
|
"prettier": "^3.7.4",
|
|
134
|
+
"react-error-boundary": "^6.1.0",
|
|
54
135
|
"rimraf": "^6.1.2",
|
|
55
136
|
"rxjs": "^7.8.1",
|
|
56
137
|
"typescript": "^5.9.3",
|
|
138
|
+
"vite": "^7.3.1",
|
|
57
139
|
"vitest": "^4.0.13"
|
|
58
140
|
},
|
|
59
141
|
"peerDependencies": {
|
|
60
142
|
"@apollo/client": "^4.0.0",
|
|
143
|
+
"@modelcontextprotocol/ext-apps": "^1.0.0",
|
|
61
144
|
"react": "^19.0.0",
|
|
62
145
|
"react-dom": "^19.0.0"
|
|
63
146
|
},
|
|
147
|
+
"peerDependenciesMeta": {
|
|
148
|
+
"@modelcontextprotocol/ext-apps": {
|
|
149
|
+
"optional": true
|
|
150
|
+
},
|
|
151
|
+
"react": {
|
|
152
|
+
"optional": true
|
|
153
|
+
},
|
|
154
|
+
"react-dom": {
|
|
155
|
+
"optional": true
|
|
156
|
+
}
|
|
157
|
+
},
|
|
64
158
|
"dependencies": {
|
|
65
159
|
"@graphql-tools/graphql-tag-pluck": "^8.3.23",
|
|
160
|
+
"cosmiconfig": "^9.0.0",
|
|
66
161
|
"crypto-hash": "^4.0.0",
|
|
67
162
|
"glob": "^11.0.3",
|
|
68
|
-
"tslib": "^2.8.1"
|
|
163
|
+
"tslib": "^2.8.1",
|
|
164
|
+
"zod": "^4.3.6"
|
|
69
165
|
}
|
|
70
166
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const AppTarget = z.literal(["mcp", "openai"]);
|
|
4
|
+
|
|
5
|
+
const Mode = z
|
|
6
|
+
.literal(["development", "production"])
|
|
7
|
+
.or(z.custom<string & {}>((value) => typeof value === "string"));
|
|
8
|
+
|
|
9
|
+
const labelsInput = z.exactOptional(
|
|
10
|
+
z.strictObject({
|
|
11
|
+
toolInvocation: z.exactOptional(
|
|
12
|
+
z.strictObject({
|
|
13
|
+
invoking: z.string().exactOptional(),
|
|
14
|
+
invoked: z.string().exactOptional(),
|
|
15
|
+
})
|
|
16
|
+
),
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const labelsOutput = z.exactOptional(
|
|
21
|
+
z.strictObject({
|
|
22
|
+
"toolInvocation/invoking": z.string().exactOptional(),
|
|
23
|
+
"toolInvocation/invoked": z.string().exactOptional(),
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const ApolloClientAiAppsConfigSchema = z.strictObject({
|
|
28
|
+
name: z.string().exactOptional(),
|
|
29
|
+
description: z.string().exactOptional(),
|
|
30
|
+
version: z.string().exactOptional(),
|
|
31
|
+
entry: z.exactOptional(
|
|
32
|
+
z.partialRecord(
|
|
33
|
+
Mode,
|
|
34
|
+
z.union([z.string(), z.partialRecord(AppTarget, z.string())])
|
|
35
|
+
)
|
|
36
|
+
),
|
|
37
|
+
csp: z.exactOptional(
|
|
38
|
+
z.strictObject({
|
|
39
|
+
connectDomains: z.array(z.string()).exactOptional(),
|
|
40
|
+
frameDomains: z.array(z.string()).exactOptional(),
|
|
41
|
+
redirectDomains: z.array(z.string()).exactOptional(),
|
|
42
|
+
resourceDomains: z.array(z.string()).exactOptional(),
|
|
43
|
+
})
|
|
44
|
+
),
|
|
45
|
+
widgetSettings: z.exactOptional(
|
|
46
|
+
z.strictObject({
|
|
47
|
+
prefersBorder: z.boolean().exactOptional(),
|
|
48
|
+
description: z.string().exactOptional(),
|
|
49
|
+
domain: z.string().exactOptional(),
|
|
50
|
+
})
|
|
51
|
+
),
|
|
52
|
+
labels: z.codec(labelsInput, labelsOutput, {
|
|
53
|
+
encode: () => {
|
|
54
|
+
// encode is currently not used so we can skip the business logic and
|
|
55
|
+
// return an empty object which satisfies the type. If we need to encode
|
|
56
|
+
// labels back to the original form, this will need to be implemented
|
|
57
|
+
return {};
|
|
58
|
+
},
|
|
59
|
+
decode: ({ toolInvocation }) => {
|
|
60
|
+
const config: z.infer<typeof labelsOutput> = {};
|
|
61
|
+
|
|
62
|
+
if (toolInvocation?.invoking) {
|
|
63
|
+
config["toolInvocation/invoking"] = toolInvocation.invoking;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (toolInvocation?.invoked) {
|
|
67
|
+
config["toolInvocation/invoked"] = toolInvocation.invoked;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return config;
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ApolloClientAiAppsConfigSchema, AppTarget } from "./schema.js";
|
|
3
|
+
|
|
4
|
+
export declare namespace ApolloClientAiAppsConfig {
|
|
5
|
+
export type AppTarget = z.infer<typeof AppTarget>;
|
|
6
|
+
export type Config = z.input<typeof ApolloClientAiAppsConfigSchema>;
|
|
7
|
+
}
|
package/src/core/ApolloClient.ts
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import type { ApolloLink } from "@apollo/client";
|
|
2
1
|
import { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
3
|
-
import { DocumentTransform } from "@apollo/client";
|
|
4
|
-
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
5
|
-
import { parse } from "graphql";
|
|
6
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
7
|
-
import "../types/openai.js";
|
|
8
2
|
import type { ApplicationManifest } from "../types/application-manifest.js";
|
|
9
|
-
import {
|
|
10
|
-
import type { FetchResult } from "@apollo/client";
|
|
11
|
-
|
|
12
|
-
// TODO: In the future if/when we support PQs again, do pqLink.concat(toolCallLink)
|
|
13
|
-
// Commenting this out for now.
|
|
14
|
-
// import { sha256 } from "crypto-hash";
|
|
15
|
-
// import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
|
|
16
|
-
// const pqLink = new PersistedQueryLink({
|
|
17
|
-
// sha256: (queryString) => sha256(queryString),
|
|
18
|
-
// });
|
|
3
|
+
import { aiClientSymbol } from "../utilities/constants.js";
|
|
19
4
|
|
|
20
5
|
export declare namespace ApolloClient {
|
|
21
|
-
// This allows us to extend the options with the "manifest" option AND make link optional (it is normally required)
|
|
22
6
|
export interface Options extends Omit<BaseApolloClient.Options, "link"> {
|
|
23
7
|
link?: BaseApolloClient.Options["link"];
|
|
24
8
|
manifest: ApplicationManifest;
|
|
@@ -26,88 +10,16 @@ export declare namespace ApolloClient {
|
|
|
26
10
|
}
|
|
27
11
|
|
|
28
12
|
export class ApolloClient extends BaseApolloClient {
|
|
29
|
-
|
|
13
|
+
/** @internal */
|
|
14
|
+
readonly [aiClientSymbol] = true;
|
|
30
15
|
|
|
31
16
|
constructor(options: ApolloClient.Options) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (__DEV__) {
|
|
35
|
-
validateTerminatingLink(link);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
super({
|
|
39
|
-
...options,
|
|
40
|
-
link,
|
|
41
|
-
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
42
|
-
documentTransform: new DocumentTransform((document) => {
|
|
43
|
-
return removeDirectivesFromDocument(
|
|
44
|
-
[{ name: "prefetch" }, { name: "tool" }],
|
|
45
|
-
document
|
|
46
|
-
)!;
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
this.manifest = options.manifest;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async prefetchData() {
|
|
54
|
-
const toolOutput = window.openai.toolOutput as {
|
|
55
|
-
prefetch?: Record<string, FetchResult<any>>;
|
|
56
|
-
} | null;
|
|
57
|
-
|
|
58
|
-
// Write prefetched data to the cache
|
|
59
|
-
this.manifest.operations.forEach((operation) => {
|
|
60
|
-
if (
|
|
61
|
-
operation.prefetch &&
|
|
62
|
-
operation.prefetchID &&
|
|
63
|
-
toolOutput?.prefetch?.[operation.prefetchID]
|
|
64
|
-
) {
|
|
65
|
-
this.writeQuery({
|
|
66
|
-
query: parse(operation.body),
|
|
67
|
-
data: toolOutput.prefetch[operation.prefetchID].data,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// If this operation has the tool that matches up with the tool that was executed, write the tool result to the cache
|
|
72
|
-
if (
|
|
73
|
-
operation.tools?.find(
|
|
74
|
-
(tool) =>
|
|
75
|
-
`${this.manifest.name}--${tool.name}` ===
|
|
76
|
-
window.openai.toolResponseMetadata?.toolName
|
|
77
|
-
)
|
|
78
|
-
) {
|
|
79
|
-
// We need to include the variables that were used as part of the tool call so that we get a proper cache entry
|
|
80
|
-
// However, we only want to include toolInput's that were graphql operation (ignore extraInputs)
|
|
81
|
-
const variables = Object.keys(window.openai.toolInput).reduce(
|
|
82
|
-
(obj, key) =>
|
|
83
|
-
operation.variables?.[key] ?
|
|
84
|
-
{ ...obj, [key]: window.openai.toolInput[key] }
|
|
85
|
-
: obj,
|
|
86
|
-
{}
|
|
87
|
-
);
|
|
17
|
+
super(options as any);
|
|
88
18
|
|
|
89
|
-
if (window.openai.toolOutput) {
|
|
90
|
-
this.writeQuery({
|
|
91
|
-
query: parse(operation.body),
|
|
92
|
-
data: (window.openai.toolOutput.result as any).data,
|
|
93
|
-
variables,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function validateTerminatingLink(link: ApolloLink) {
|
|
102
|
-
let terminatingLink = link;
|
|
103
|
-
|
|
104
|
-
while (terminatingLink.right) {
|
|
105
|
-
terminatingLink = terminatingLink.right;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (terminatingLink.constructor.name !== "ToolCallLink") {
|
|
109
19
|
throw new Error(
|
|
110
|
-
"
|
|
20
|
+
"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."
|
|
111
21
|
);
|
|
112
22
|
}
|
|
23
|
+
|
|
24
|
+
async waitForInitialization() {}
|
|
113
25
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
2
|
+
|
|
3
|
+
let warned = false;
|
|
4
|
+
|
|
5
|
+
export const Platform = Object.freeze({
|
|
6
|
+
get target() {
|
|
7
|
+
if (__DEV__) {
|
|
8
|
+
if (!warned) {
|
|
9
|
+
console.error(
|
|
10
|
+
"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."
|
|
11
|
+
);
|
|
12
|
+
warned = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Even though this return the "unknown" string, this value should never
|
|
17
|
+
// actually be seen at runtime unless something is misconfigured, hence the
|
|
18
|
+
// type cast to the other values.
|
|
19
|
+
return "unknown" as unknown as "mcp" | "openai";
|
|
20
|
+
},
|
|
21
|
+
select<
|
|
22
|
+
T = unknown,
|
|
23
|
+
TReturn = T extends (...args: any[]) => infer TReturn ? TReturn : T,
|
|
24
|
+
>(config: { mcp?: T; openai?: T }): TReturn | undefined {
|
|
25
|
+
return;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CallToolResult as McpCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { FormattedExecutionResult } from "graphql";
|
|
3
|
+
|
|
4
|
+
export namespace ApolloMcpServerApps {
|
|
5
|
+
export interface StructuredContent {
|
|
6
|
+
result: FormattedExecutionResult;
|
|
7
|
+
prefetch?: Record<string, FormattedExecutionResult>;
|
|
8
|
+
[x: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CallToolResult extends McpCallToolResult {
|
|
12
|
+
structuredContent: ApolloMcpServerApps.StructuredContent;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/index.mcp.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
API,
|
|
3
|
-
CallTool,
|
|
4
|
-
DeviceType,
|
|
5
|
-
DisplayMode,
|
|
6
|
-
OpenAiGlobals,
|
|
7
|
-
SafeArea,
|
|
8
|
-
SafeAreaInsets,
|
|
9
|
-
Theme,
|
|
10
|
-
UserAgent,
|
|
11
|
-
UnknownObject,
|
|
12
|
-
} from "./types/openai.js";
|
|
13
|
-
export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
|
|
14
|
-
|
|
15
1
|
export type {
|
|
16
2
|
ApplicationManifest,
|
|
17
3
|
ManifestOperation,
|
|
@@ -22,18 +8,7 @@ export type {
|
|
|
22
8
|
ManifestWidgetSettings,
|
|
23
9
|
} from "./types/application-manifest.js";
|
|
24
10
|
|
|
25
|
-
export { ToolUseProvider } from "./react/context/ToolUseContext.js";
|
|
26
|
-
export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
|
|
27
|
-
export { useToolName } from "./react/hooks/useToolName.js";
|
|
28
|
-
export { useToolInput } from "./react/hooks/useToolInput.js";
|
|
29
|
-
export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
|
|
30
|
-
export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
|
|
31
|
-
export { useToolEffect } from "./react/hooks/useToolEffect.js";
|
|
32
|
-
export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
|
|
33
|
-
export { useToolOutput } from "./react/hooks/useToolOutput.js";
|
|
34
|
-
export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
|
|
35
|
-
export { useWidgetState } from "./react/hooks/useWidgetState.js";
|
|
36
|
-
|
|
37
11
|
export { ApolloClient } from "./core/ApolloClient.js";
|
|
38
|
-
export { ApolloProvider } from "./react/ApolloProvider.js";
|
|
39
12
|
export { ToolCallLink } from "./link/ToolCallLink.js";
|
|
13
|
+
|
|
14
|
+
export { Platform } from "./core/Platform.js";
|
package/src/link/ToolCallLink.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { ApolloLink
|
|
2
|
-
import { from, map } from "rxjs";
|
|
3
|
-
import {
|
|
4
|
-
fallbackHttpConfig,
|
|
5
|
-
selectHttpOptionsAndBody,
|
|
6
|
-
} from "@apollo/client/link/http";
|
|
1
|
+
import { ApolloLink } from "@apollo/client";
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
10
5
|
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
11
6
|
* validate that the terminating link is an instance of this link.
|
|
12
7
|
*
|
|
13
|
-
* @example
|
|
8
|
+
* @example Providing a custom link chain
|
|
14
9
|
*
|
|
15
10
|
* ```ts
|
|
16
11
|
* import { ApolloLink } from "@apollo/client";
|
|
@@ -28,22 +23,11 @@ import {
|
|
|
28
23
|
* ```
|
|
29
24
|
*/
|
|
30
25
|
export class ToolCallLink extends ApolloLink {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const contextConfig = {
|
|
34
|
-
http: context.http,
|
|
35
|
-
options: context.fetchOptions,
|
|
36
|
-
credentials: context.credentials,
|
|
37
|
-
headers: context.headers,
|
|
38
|
-
};
|
|
39
|
-
const { query, variables } = selectHttpOptionsAndBody(
|
|
40
|
-
operation,
|
|
41
|
-
fallbackHttpConfig,
|
|
42
|
-
contextConfig
|
|
43
|
-
).body;
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
throw new Error(
|
|
30
|
+
"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."
|
|
47
31
|
);
|
|
48
32
|
}
|
|
49
33
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApolloLink,
|
|
3
|
+
ApolloClient as BaseApolloClient,
|
|
4
|
+
DocumentTransform,
|
|
5
|
+
} from "@apollo/client";
|
|
6
|
+
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
7
|
+
import { parse } from "graphql";
|
|
8
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
9
|
+
import type { ApplicationManifest } from "../../types/application-manifest.js";
|
|
10
|
+
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
11
|
+
import {
|
|
12
|
+
aiClientSymbol,
|
|
13
|
+
cacheAsync,
|
|
14
|
+
getVariablesForOperationFromToolInput,
|
|
15
|
+
} from "../../utilities/index.js";
|
|
16
|
+
import { McpAppManager } from "./McpAppManager.js";
|
|
17
|
+
|
|
18
|
+
export declare namespace ApolloClient {
|
|
19
|
+
export interface Options extends Omit<BaseApolloClient.Options, "link"> {
|
|
20
|
+
link?: BaseApolloClient.Options["link"];
|
|
21
|
+
manifest: ApplicationManifest;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ApolloClient extends BaseApolloClient {
|
|
26
|
+
manifest: ApplicationManifest;
|
|
27
|
+
private readonly appManager: McpAppManager;
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
readonly [aiClientSymbol] = true;
|
|
31
|
+
|
|
32
|
+
constructor(options: ApolloClient.Options) {
|
|
33
|
+
const link = options.link ?? new ToolCallLink();
|
|
34
|
+
|
|
35
|
+
if (__DEV__) {
|
|
36
|
+
validateTerminatingLink(link);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
super({
|
|
40
|
+
...options,
|
|
41
|
+
link,
|
|
42
|
+
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
43
|
+
documentTransform: new DocumentTransform((document) => {
|
|
44
|
+
return removeDirectivesFromDocument(
|
|
45
|
+
[{ name: "prefetch" }, { name: "tool" }],
|
|
46
|
+
document
|
|
47
|
+
)!;
|
|
48
|
+
}).concat(options.documentTransform ?? DocumentTransform.identity()),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.manifest = options.manifest;
|
|
52
|
+
this.appManager = new McpAppManager(this.manifest);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
stop() {
|
|
56
|
+
super.stop();
|
|
57
|
+
this.appManager.close().catch(() => {});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
waitForInitialization = cacheAsync(async () => {
|
|
61
|
+
const { prefetch, result, toolName, args } =
|
|
62
|
+
await this.appManager.waitForInitialization();
|
|
63
|
+
|
|
64
|
+
this.manifest.operations.forEach((operation) => {
|
|
65
|
+
if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
|
|
66
|
+
this.writeQuery({
|
|
67
|
+
query: parse(operation.body),
|
|
68
|
+
data: prefetch[operation.prefetchID].data,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (operation.tools.find((tool) => tool.name === toolName)) {
|
|
73
|
+
this.writeQuery({
|
|
74
|
+
query: parse(operation.body),
|
|
75
|
+
data: result.data,
|
|
76
|
+
variables: getVariablesForOperationFromToolInput(operation, args),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function validateTerminatingLink(link: ApolloLink) {
|
|
84
|
+
let terminatingLink = link;
|
|
85
|
+
|
|
86
|
+
while (terminatingLink.right) {
|
|
87
|
+
terminatingLink = terminatingLink.right;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
!isNamedLink(terminatingLink) ||
|
|
92
|
+
terminatingLink.name !== "ToolCallLink"
|
|
93
|
+
) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"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."
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {
|
|
101
|
+
return "name" in link;
|
|
102
|
+
}
|