@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
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { expect, test, describe, vi } from "vitest";
|
|
2
|
+
import { ApolloClient } from "../ApolloClient.js";
|
|
3
|
+
import { parse } from "graphql";
|
|
4
|
+
import { ApolloLink, HttpLink, InMemoryCache } from "@apollo/client";
|
|
5
|
+
import { ToolCallLink } from "../../link/ToolCallLink.js";
|
|
6
|
+
import {
|
|
7
|
+
minimalHostContextWithToolName,
|
|
8
|
+
mockApplicationManifest,
|
|
9
|
+
mockMcpHost,
|
|
10
|
+
spyOnConsole,
|
|
11
|
+
stubOpenAiGlobals,
|
|
12
|
+
} from "../../../testing/internal/index.js";
|
|
13
|
+
|
|
14
|
+
describe("Client Basics", () => {
|
|
15
|
+
test("executes tool call when client.query is called", async () => {
|
|
16
|
+
stubOpenAiGlobals();
|
|
17
|
+
using _ = spyOnConsole("debug");
|
|
18
|
+
const manifest = mockApplicationManifest();
|
|
19
|
+
const client = new ApolloClient({
|
|
20
|
+
cache: new InMemoryCache(),
|
|
21
|
+
manifest,
|
|
22
|
+
});
|
|
23
|
+
using host = await mockMcpHost();
|
|
24
|
+
|
|
25
|
+
host.onCleanup(() => client.stop());
|
|
26
|
+
|
|
27
|
+
host.sendToolInput({});
|
|
28
|
+
host.sendToolResult({
|
|
29
|
+
content: [],
|
|
30
|
+
structuredContent: {},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await client.waitForInitialization();
|
|
34
|
+
|
|
35
|
+
host.mockToolCall("execute", () => ({
|
|
36
|
+
content: [],
|
|
37
|
+
structuredContent: {
|
|
38
|
+
data: {
|
|
39
|
+
product: {
|
|
40
|
+
id: "1",
|
|
41
|
+
title: "Pen",
|
|
42
|
+
rating: 5,
|
|
43
|
+
price: 1.0,
|
|
44
|
+
description: "Awesome pen",
|
|
45
|
+
images: [],
|
|
46
|
+
__typename: "Product",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const variables = { id: "1" };
|
|
53
|
+
const result = await client.query({
|
|
54
|
+
query: parse(manifest.operations[0].body),
|
|
55
|
+
variables,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual({
|
|
59
|
+
data: {
|
|
60
|
+
product: {
|
|
61
|
+
id: "1",
|
|
62
|
+
title: "Pen",
|
|
63
|
+
rating: 5,
|
|
64
|
+
price: 1.0,
|
|
65
|
+
description: "Awesome pen",
|
|
66
|
+
images: [],
|
|
67
|
+
__typename: "Product",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
expect(client.extract()).toMatchInlineSnapshot(`
|
|
72
|
+
{
|
|
73
|
+
"Product:1": {
|
|
74
|
+
"__typename": "Product",
|
|
75
|
+
"description": "Awesome pen",
|
|
76
|
+
"id": "1",
|
|
77
|
+
"images": [],
|
|
78
|
+
"price": 1,
|
|
79
|
+
"rating": 5,
|
|
80
|
+
"title": "Pen",
|
|
81
|
+
},
|
|
82
|
+
"ROOT_QUERY": {
|
|
83
|
+
"__typename": "Query",
|
|
84
|
+
"product({"id":"1"})": {
|
|
85
|
+
"__ref": "Product:1",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
`);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("prefetchData", () => {
|
|
94
|
+
test("caches tool response when data is provided", async () => {
|
|
95
|
+
stubOpenAiGlobals();
|
|
96
|
+
using _ = spyOnConsole("debug");
|
|
97
|
+
const client = new ApolloClient({
|
|
98
|
+
cache: new InMemoryCache(),
|
|
99
|
+
manifest: mockApplicationManifest(),
|
|
100
|
+
});
|
|
101
|
+
using host = await mockMcpHost({
|
|
102
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
host.onCleanup(() => client.stop());
|
|
106
|
+
|
|
107
|
+
host.sendToolInput({ arguments: { id: 1 } });
|
|
108
|
+
host.sendToolResult({
|
|
109
|
+
content: [],
|
|
110
|
+
structuredContent: {
|
|
111
|
+
result: {
|
|
112
|
+
data: {
|
|
113
|
+
product: {
|
|
114
|
+
id: "1",
|
|
115
|
+
title: "Pen",
|
|
116
|
+
rating: 5,
|
|
117
|
+
price: 1.0,
|
|
118
|
+
description: "Awesome pen",
|
|
119
|
+
images: [],
|
|
120
|
+
__typename: "Product",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await client.waitForInitialization();
|
|
128
|
+
|
|
129
|
+
expect(client.extract()).toMatchInlineSnapshot(`
|
|
130
|
+
{
|
|
131
|
+
"Product:1": {
|
|
132
|
+
"__typename": "Product",
|
|
133
|
+
"description": "Awesome pen",
|
|
134
|
+
"id": "1",
|
|
135
|
+
"images": [],
|
|
136
|
+
"price": 1,
|
|
137
|
+
"rating": 5,
|
|
138
|
+
"title": "Pen",
|
|
139
|
+
},
|
|
140
|
+
"ROOT_QUERY": {
|
|
141
|
+
"__typename": "Query",
|
|
142
|
+
"product({"id":1})": {
|
|
143
|
+
"__ref": "Product:1",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("caches prefetched data when prefetched data is provided", async () => {
|
|
151
|
+
stubOpenAiGlobals();
|
|
152
|
+
using _ = spyOnConsole("debug");
|
|
153
|
+
const client = new ApolloClient({
|
|
154
|
+
cache: new InMemoryCache(),
|
|
155
|
+
manifest: mockApplicationManifest({
|
|
156
|
+
operations: [
|
|
157
|
+
{
|
|
158
|
+
id: "cd0d52159b9003e791de97c6a76efa03d34fe00cee278d1a3f4bfcec5fb3e1e6",
|
|
159
|
+
name: "TopProducts",
|
|
160
|
+
type: "query",
|
|
161
|
+
body: "query TopProducts {\n topProducts {\n id\n title\n rating\n price\n __typename\n }\n}",
|
|
162
|
+
variables: {},
|
|
163
|
+
prefetch: true,
|
|
164
|
+
prefetchID: "__anonymous",
|
|
165
|
+
tools: [
|
|
166
|
+
{
|
|
167
|
+
name: "TopProducts",
|
|
168
|
+
description: "Shows the currently highest rated products.",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
using host = await mockMcpHost({
|
|
176
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
host.onCleanup(() => client.stop());
|
|
180
|
+
|
|
181
|
+
host.sendToolInput({ arguments: { id: 1 } });
|
|
182
|
+
host.sendToolResult({
|
|
183
|
+
content: [],
|
|
184
|
+
structuredContent: {
|
|
185
|
+
prefetch: {
|
|
186
|
+
__anonymous: {
|
|
187
|
+
data: {
|
|
188
|
+
topProducts: [
|
|
189
|
+
{
|
|
190
|
+
id: "2",
|
|
191
|
+
title: "iPhone 17",
|
|
192
|
+
rating: 5,
|
|
193
|
+
price: 999.99,
|
|
194
|
+
description: "Awesome phone",
|
|
195
|
+
images: [],
|
|
196
|
+
__typename: "Product",
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
await client.waitForInitialization();
|
|
206
|
+
|
|
207
|
+
expect(client.extract()).toMatchInlineSnapshot(`
|
|
208
|
+
{
|
|
209
|
+
"Product:2": {
|
|
210
|
+
"__typename": "Product",
|
|
211
|
+
"id": "2",
|
|
212
|
+
"price": 999.99,
|
|
213
|
+
"rating": 5,
|
|
214
|
+
"title": "iPhone 17",
|
|
215
|
+
},
|
|
216
|
+
"ROOT_QUERY": {
|
|
217
|
+
"__typename": "Query",
|
|
218
|
+
"topProducts": [
|
|
219
|
+
{
|
|
220
|
+
"__ref": "Product:2",
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("caches both prefetch and tool response when both are provided", async () => {
|
|
229
|
+
stubOpenAiGlobals();
|
|
230
|
+
using _ = spyOnConsole("debug");
|
|
231
|
+
const client = new ApolloClient({
|
|
232
|
+
cache: new InMemoryCache(),
|
|
233
|
+
manifest: mockApplicationManifest({
|
|
234
|
+
operations: [
|
|
235
|
+
{
|
|
236
|
+
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
237
|
+
name: "Product",
|
|
238
|
+
type: "query",
|
|
239
|
+
body: "query Product($id: ID!) {\n product(id: $id) {\n id\n title\n rating\n price\n description\n images\n __typename\n }\n}",
|
|
240
|
+
variables: { id: "ID" },
|
|
241
|
+
prefetch: false,
|
|
242
|
+
tools: [
|
|
243
|
+
{
|
|
244
|
+
name: "GetProduct",
|
|
245
|
+
description: "Shows the details page for a specific product.",
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "cd0d52159b9003e791de97c6a76efa03d34fe00cee278d1a3f4bfcec5fb3e1e6",
|
|
251
|
+
name: "TopProducts",
|
|
252
|
+
type: "query",
|
|
253
|
+
body: "query TopProducts {\n topProducts {\n id\n title\n rating\n price\n __typename\n }\n}",
|
|
254
|
+
variables: {},
|
|
255
|
+
prefetch: true,
|
|
256
|
+
prefetchID: "__anonymous",
|
|
257
|
+
tools: [
|
|
258
|
+
{
|
|
259
|
+
name: "TopProducts",
|
|
260
|
+
description: "Shows the currently highest rated products.",
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
}),
|
|
266
|
+
});
|
|
267
|
+
using host = await mockMcpHost({
|
|
268
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
host.onCleanup(() => client.stop());
|
|
272
|
+
|
|
273
|
+
host.sendToolInput({ arguments: { id: 1 } });
|
|
274
|
+
host.sendToolResult({
|
|
275
|
+
content: [],
|
|
276
|
+
structuredContent: {
|
|
277
|
+
result: {
|
|
278
|
+
data: {
|
|
279
|
+
product: {
|
|
280
|
+
id: "1",
|
|
281
|
+
title: "Pen",
|
|
282
|
+
rating: 5,
|
|
283
|
+
price: 1.0,
|
|
284
|
+
description: "Awesome pen",
|
|
285
|
+
images: [],
|
|
286
|
+
__typename: "Product",
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
prefetch: {
|
|
291
|
+
__anonymous: {
|
|
292
|
+
data: {
|
|
293
|
+
topProducts: [
|
|
294
|
+
{
|
|
295
|
+
id: "2",
|
|
296
|
+
title: "iPhone 17",
|
|
297
|
+
rating: 5,
|
|
298
|
+
price: 999.99,
|
|
299
|
+
description: "Awesome phone",
|
|
300
|
+
images: [],
|
|
301
|
+
__typename: "Product",
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
await client.waitForInitialization();
|
|
311
|
+
|
|
312
|
+
expect(client.extract()).toMatchInlineSnapshot(`
|
|
313
|
+
{
|
|
314
|
+
"Product:1": {
|
|
315
|
+
"__typename": "Product",
|
|
316
|
+
"description": "Awesome pen",
|
|
317
|
+
"id": "1",
|
|
318
|
+
"images": [],
|
|
319
|
+
"price": 1,
|
|
320
|
+
"rating": 5,
|
|
321
|
+
"title": "Pen",
|
|
322
|
+
},
|
|
323
|
+
"Product:2": {
|
|
324
|
+
"__typename": "Product",
|
|
325
|
+
"id": "2",
|
|
326
|
+
"price": 999.99,
|
|
327
|
+
"rating": 5,
|
|
328
|
+
"title": "iPhone 17",
|
|
329
|
+
},
|
|
330
|
+
"ROOT_QUERY": {
|
|
331
|
+
"__typename": "Query",
|
|
332
|
+
"product({"id":1})": {
|
|
333
|
+
"__ref": "Product:1",
|
|
334
|
+
},
|
|
335
|
+
"topProducts": [
|
|
336
|
+
{
|
|
337
|
+
"__ref": "Product:2",
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
}
|
|
342
|
+
`);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("excludes extra inputs when writing to cache", async () => {
|
|
346
|
+
stubOpenAiGlobals();
|
|
347
|
+
using _ = spyOnConsole("debug");
|
|
348
|
+
const client = new ApolloClient({
|
|
349
|
+
cache: new InMemoryCache(),
|
|
350
|
+
manifest: mockApplicationManifest(),
|
|
351
|
+
});
|
|
352
|
+
using host = await mockMcpHost({
|
|
353
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
host.onCleanup(() => client.stop());
|
|
357
|
+
|
|
358
|
+
host.sendToolInput({ arguments: { id: 1, myOtherThing: 2 } });
|
|
359
|
+
host.sendToolResult({
|
|
360
|
+
content: [],
|
|
361
|
+
structuredContent: {
|
|
362
|
+
result: {
|
|
363
|
+
data: {
|
|
364
|
+
product: {
|
|
365
|
+
id: "1",
|
|
366
|
+
title: "Pen",
|
|
367
|
+
rating: 5,
|
|
368
|
+
price: 1.0,
|
|
369
|
+
description: "Awesome pen",
|
|
370
|
+
images: [],
|
|
371
|
+
__typename: "Product",
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
await client.waitForInitialization();
|
|
379
|
+
|
|
380
|
+
expect(client.extract()).toMatchInlineSnapshot(`
|
|
381
|
+
{
|
|
382
|
+
"Product:1": {
|
|
383
|
+
"__typename": "Product",
|
|
384
|
+
"description": "Awesome pen",
|
|
385
|
+
"id": "1",
|
|
386
|
+
"images": [],
|
|
387
|
+
"price": 1,
|
|
388
|
+
"rating": 5,
|
|
389
|
+
"title": "Pen",
|
|
390
|
+
},
|
|
391
|
+
"ROOT_QUERY": {
|
|
392
|
+
"__typename": "Query",
|
|
393
|
+
"product({"id":1})": {
|
|
394
|
+
"__ref": "Product:1",
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
}
|
|
398
|
+
`);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
describe("custom links", () => {
|
|
403
|
+
test("allows for custom links provided to the constructor", async () => {
|
|
404
|
+
stubOpenAiGlobals();
|
|
405
|
+
using _ = spyOnConsole("debug");
|
|
406
|
+
const manifest = mockApplicationManifest();
|
|
407
|
+
const linkHandler = vi.fn<ApolloLink.RequestHandler>((operation, forward) =>
|
|
408
|
+
forward(operation)
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
const client = new ApolloClient({
|
|
412
|
+
manifest,
|
|
413
|
+
cache: new InMemoryCache(),
|
|
414
|
+
link: ApolloLink.from([new ApolloLink(linkHandler), new ToolCallLink()]),
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
using host = await mockMcpHost();
|
|
418
|
+
host.onCleanup(() => client.stop());
|
|
419
|
+
|
|
420
|
+
host.sendToolInput({ arguments: {} });
|
|
421
|
+
host.sendToolResult({
|
|
422
|
+
content: [],
|
|
423
|
+
structuredContent: {},
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
host.mockToolCall("execute", () => ({
|
|
427
|
+
content: [],
|
|
428
|
+
structuredContent: {
|
|
429
|
+
data: {
|
|
430
|
+
product: {
|
|
431
|
+
id: "1",
|
|
432
|
+
title: "Pen",
|
|
433
|
+
rating: 5,
|
|
434
|
+
price: 1.0,
|
|
435
|
+
description: "Awesome pen",
|
|
436
|
+
images: [],
|
|
437
|
+
__typename: "Product",
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
}));
|
|
442
|
+
|
|
443
|
+
await client.waitForInitialization();
|
|
444
|
+
|
|
445
|
+
const variables = { id: "1" };
|
|
446
|
+
const query = parse(manifest.operations[0].body);
|
|
447
|
+
|
|
448
|
+
await expect(client.query({ query, variables })).resolves.toStrictEqual({
|
|
449
|
+
data: {
|
|
450
|
+
product: {
|
|
451
|
+
id: "1",
|
|
452
|
+
title: "Pen",
|
|
453
|
+
rating: 5,
|
|
454
|
+
price: 1.0,
|
|
455
|
+
description: "Awesome pen",
|
|
456
|
+
images: [],
|
|
457
|
+
__typename: "Product",
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
expect(linkHandler).toHaveBeenCalledOnce();
|
|
463
|
+
expect(linkHandler).toHaveBeenCalledWith(
|
|
464
|
+
expect.objectContaining({ query, variables, operationType: "query" }),
|
|
465
|
+
expect.any(Function)
|
|
466
|
+
);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test("enforces ToolCallLink as terminating link", async () => {
|
|
470
|
+
const manifest = mockApplicationManifest();
|
|
471
|
+
const expectedError = new Error(
|
|
472
|
+
"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."
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
expect(() => {
|
|
476
|
+
new ApolloClient({
|
|
477
|
+
manifest,
|
|
478
|
+
cache: new InMemoryCache(),
|
|
479
|
+
link: new HttpLink(),
|
|
480
|
+
});
|
|
481
|
+
}).toThrow(expectedError);
|
|
482
|
+
|
|
483
|
+
expect(() => {
|
|
484
|
+
new ApolloClient({
|
|
485
|
+
manifest,
|
|
486
|
+
cache: new InMemoryCache(),
|
|
487
|
+
link: new ApolloLink(),
|
|
488
|
+
});
|
|
489
|
+
}).toThrow(expectedError);
|
|
490
|
+
|
|
491
|
+
expect(() => {
|
|
492
|
+
new ApolloClient({
|
|
493
|
+
manifest,
|
|
494
|
+
cache: new InMemoryCache(),
|
|
495
|
+
link: ApolloLink.from([new ApolloLink(), new HttpLink()]),
|
|
496
|
+
});
|
|
497
|
+
}).toThrow(expectedError);
|
|
498
|
+
|
|
499
|
+
expect(() => {
|
|
500
|
+
new ApolloClient({
|
|
501
|
+
manifest,
|
|
502
|
+
cache: new InMemoryCache(),
|
|
503
|
+
link: ApolloLink.split(() => true, new ApolloLink(), new HttpLink()),
|
|
504
|
+
});
|
|
505
|
+
}).toThrow(expectedError);
|
|
506
|
+
|
|
507
|
+
expect(() => {
|
|
508
|
+
new ApolloClient({
|
|
509
|
+
manifest,
|
|
510
|
+
cache: new InMemoryCache(),
|
|
511
|
+
link: ApolloLink.split(() => true, new ToolCallLink(), new HttpLink()),
|
|
512
|
+
});
|
|
513
|
+
}).toThrow(expectedError);
|
|
514
|
+
|
|
515
|
+
// Allow you to use a custom terminating link for `split` links if the
|
|
516
|
+
// custom link is the `left` branch link.
|
|
517
|
+
expect(() => {
|
|
518
|
+
new ApolloClient({
|
|
519
|
+
manifest,
|
|
520
|
+
cache: new InMemoryCache(),
|
|
521
|
+
link: ApolloLink.split(() => true, new HttpLink(), new ToolCallLink()),
|
|
522
|
+
});
|
|
523
|
+
}).not.toThrow(expectedError);
|
|
524
|
+
|
|
525
|
+
expect(() => {
|
|
526
|
+
new ApolloClient({
|
|
527
|
+
manifest,
|
|
528
|
+
cache: new InMemoryCache(),
|
|
529
|
+
link: ApolloLink.split(
|
|
530
|
+
() => true,
|
|
531
|
+
new ToolCallLink(),
|
|
532
|
+
new ToolCallLink()
|
|
533
|
+
),
|
|
534
|
+
});
|
|
535
|
+
}).not.toThrow();
|
|
536
|
+
});
|
|
537
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { API, OpenAiGlobals } from "./types.js";
|
|
2
|
+
import type { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types.js";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
openai: API<any> & OpenAiGlobals;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface WindowEventMap {
|
|
10
|
+
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ApolloLink, Observable } from "@apollo/client";
|
|
2
|
+
import { from } from "rxjs";
|
|
3
|
+
import type { ApolloClient as OpenAiApolloClient } from "../core/ApolloClient";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
7
|
+
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
8
|
+
* validate that the terminating link is an instance of this link.
|
|
9
|
+
*
|
|
10
|
+
* @example Providing a custom link chain
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { ApolloLink } from "@apollo/client";
|
|
14
|
+
* import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
|
|
15
|
+
*
|
|
16
|
+
* const link = ApolloLink.from([
|
|
17
|
+
* ...otherLinks,
|
|
18
|
+
* new ToolCallLink()
|
|
19
|
+
* ]);
|
|
20
|
+
*
|
|
21
|
+
* const client = new ApolloClient({
|
|
22
|
+
* link,
|
|
23
|
+
* // ...
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class ToolCallLink extends ApolloLink {
|
|
28
|
+
readonly name = "ToolCallLink";
|
|
29
|
+
|
|
30
|
+
request(operation: ApolloLink.Operation): Observable<ApolloLink.Result> {
|
|
31
|
+
const client = operation.client as OpenAiApolloClient;
|
|
32
|
+
|
|
33
|
+
return from(
|
|
34
|
+
client["appManager"].executeQuery({
|
|
35
|
+
query: operation.query,
|
|
36
|
+
variables: operation.variables,
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect, test, vi } from "vitest";
|
|
2
2
|
import { useOpenAiGlobal } from "../useOpenAiGlobal.js";
|
|
3
3
|
import { renderHook, act } from "@testing-library/react";
|
|
4
|
-
import { SET_GLOBALS_EVENT_TYPE } from "../../../types
|
|
4
|
+
import { SET_GLOBALS_EVENT_TYPE } from "../../../types.js";
|
|
5
5
|
|
|
6
6
|
test("Should update value when globals are updated and event it triggered", async () => {
|
|
7
7
|
vi.stubGlobal("openai", {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { afterEach, expect, test, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
mockApplicationManifest,
|
|
4
|
+
mockMcpHost,
|
|
5
|
+
spyOnConsole,
|
|
6
|
+
stubOpenAiGlobals,
|
|
7
|
+
} from "../../../../testing/internal/index.js";
|
|
8
|
+
import {
|
|
9
|
+
disableActEnvironment,
|
|
10
|
+
renderHookToSnapshotStream,
|
|
11
|
+
} from "@testing-library/react-render-stream";
|
|
12
|
+
import { useToolInput } from "../useToolInput.js";
|
|
13
|
+
import { ApolloClient } from "../../../core/ApolloClient.js";
|
|
14
|
+
import { InMemoryCache } from "@apollo/client";
|
|
15
|
+
import { Suspense } from "react";
|
|
16
|
+
import { ApolloProvider } from "../../../../react/ApolloProvider.js";
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.unstubAllGlobals();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("returns the tool input from the MCP host", async () => {
|
|
23
|
+
using _ = spyOnConsole("debug");
|
|
24
|
+
stubOpenAiGlobals({ toolResponseMetadata: {} });
|
|
25
|
+
const client = new ApolloClient({
|
|
26
|
+
cache: new InMemoryCache(),
|
|
27
|
+
manifest: mockApplicationManifest(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
using host = await mockMcpHost();
|
|
31
|
+
host.onCleanup(() => client.stop());
|
|
32
|
+
|
|
33
|
+
host.sendToolInput({ arguments: { id: "1" } });
|
|
34
|
+
host.sendToolResult({
|
|
35
|
+
content: [],
|
|
36
|
+
structuredContent: {},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
using _disabledAct = disableActEnvironment();
|
|
40
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
41
|
+
() => useToolInput(),
|
|
42
|
+
{
|
|
43
|
+
wrapper: ({ children }) => (
|
|
44
|
+
<Suspense>
|
|
45
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
46
|
+
</Suspense>
|
|
47
|
+
),
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
await expect(takeSnapshot()).resolves.toEqual({ id: "1" });
|
|
52
|
+
await expect(takeSnapshot).not.toRerender();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("returns undefined when ontoolinput is not fired", async () => {
|
|
56
|
+
using _ = spyOnConsole("debug");
|
|
57
|
+
stubOpenAiGlobals({ toolResponseMetadata: {} });
|
|
58
|
+
const client = new ApolloClient({
|
|
59
|
+
cache: new InMemoryCache(),
|
|
60
|
+
manifest: mockApplicationManifest(),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
using host = await mockMcpHost();
|
|
64
|
+
host.onCleanup(() => client.stop());
|
|
65
|
+
|
|
66
|
+
host.sendToolResult({
|
|
67
|
+
content: [],
|
|
68
|
+
structuredContent: {},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
using _disabledAct = disableActEnvironment();
|
|
72
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
73
|
+
() => useToolInput(),
|
|
74
|
+
{
|
|
75
|
+
wrapper: ({ children }) => (
|
|
76
|
+
<Suspense>
|
|
77
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
78
|
+
</Suspense>
|
|
79
|
+
),
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
await expect(takeSnapshot()).resolves.toBeUndefined();
|
|
84
|
+
await expect(takeSnapshot).not.toRerender();
|
|
85
|
+
});
|