@apollo/client-ai-apps 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +416 -0
- package/__mocks__/fs/promises.cjs +3 -0
- package/__mocks__/fs.cjs +3 -0
- package/dist/config/defineConfig.d.ts +26 -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 +2 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -14
- 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 +13 -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 +109 -12
- 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 +4 -28
- 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 +16 -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 -274
- package/dist/vite/application_manifest_plugin.js.map +0 -1
- package/src/core/__tests__/ApolloClient.test.ts +0 -626
- 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 -1038
- package/src/vite/absolute_asset_imports_plugin.ts +0 -22
- package/src/vite/application_manifest_plugin.ts +0 -443
- /package/dist/{react → openai/react}/hooks/useToolName.d.ts +0 -0
- /package/dist/{react → openai/react}/hooks/useWidgetState.js +0 -0
|
@@ -1,626 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe, vi } from "vitest";
|
|
2
|
-
import { ApolloClient } from "../ApolloClient.js";
|
|
3
|
-
import type { ApplicationManifest } from "../../types/application-manifest.js";
|
|
4
|
-
import { parse } from "graphql";
|
|
5
|
-
import { ApolloLink, HttpLink, InMemoryCache } from "@apollo/client";
|
|
6
|
-
import { ToolCallLink } from "../../link/ToolCallLink.js";
|
|
7
|
-
|
|
8
|
-
describe("Client Basics", () => {
|
|
9
|
-
test("Should execute tool call when client.query is called", async () => {
|
|
10
|
-
vi.stubGlobal("openai", {
|
|
11
|
-
toolInput: {},
|
|
12
|
-
toolOutput: {},
|
|
13
|
-
toolResponseMetadata: {
|
|
14
|
-
toolName: "the-store--Get Product",
|
|
15
|
-
},
|
|
16
|
-
callTool: vi.fn(async (name: string, args: Record<string, unknown>) => {
|
|
17
|
-
return {
|
|
18
|
-
structuredContent: {
|
|
19
|
-
data: {
|
|
20
|
-
product: {
|
|
21
|
-
id: "1",
|
|
22
|
-
title: "Pen",
|
|
23
|
-
rating: 5,
|
|
24
|
-
price: 1.0,
|
|
25
|
-
description: "Awesome pen",
|
|
26
|
-
images: [],
|
|
27
|
-
__typename: "Product",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const manifest = {
|
|
36
|
-
format: "apollo-ai-app-manifest",
|
|
37
|
-
version: "1",
|
|
38
|
-
name: "the-store",
|
|
39
|
-
description:
|
|
40
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
41
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
42
|
-
operations: [
|
|
43
|
-
{
|
|
44
|
-
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
45
|
-
name: "Product",
|
|
46
|
-
type: "query",
|
|
47
|
-
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}",
|
|
48
|
-
variables: { id: "ID" },
|
|
49
|
-
prefetch: false,
|
|
50
|
-
tools: [
|
|
51
|
-
{
|
|
52
|
-
name: "Get Product",
|
|
53
|
-
description: "Shows the details page for a specific product.",
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
resource: "index.html",
|
|
59
|
-
csp: { connectDomains: [], resourceDomains: [] },
|
|
60
|
-
} satisfies ApplicationManifest;
|
|
61
|
-
|
|
62
|
-
const client = new ApolloClient({
|
|
63
|
-
cache: new InMemoryCache(),
|
|
64
|
-
manifest,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const variables = { id: "1" };
|
|
68
|
-
await client.query({
|
|
69
|
-
query: parse(manifest.operations[0].body),
|
|
70
|
-
variables,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(window.openai.callTool).toBeCalledWith("execute", {
|
|
74
|
-
query: manifest.operations[0].body,
|
|
75
|
-
variables,
|
|
76
|
-
});
|
|
77
|
-
expect(client.extract()).toMatchInlineSnapshot(`
|
|
78
|
-
{
|
|
79
|
-
"Product:1": {
|
|
80
|
-
"__typename": "Product",
|
|
81
|
-
"description": "Awesome pen",
|
|
82
|
-
"id": "1",
|
|
83
|
-
"images": [],
|
|
84
|
-
"price": 1,
|
|
85
|
-
"rating": 5,
|
|
86
|
-
"title": "Pen",
|
|
87
|
-
},
|
|
88
|
-
"ROOT_QUERY": {
|
|
89
|
-
"__typename": "Query",
|
|
90
|
-
"product({"id":"1"})": {
|
|
91
|
-
"__ref": "Product:1",
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
`);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("prefetchData", () => {
|
|
100
|
-
test("Should cache tool response when data is provided", async () => {
|
|
101
|
-
vi.stubGlobal("openai", {
|
|
102
|
-
toolInput: {
|
|
103
|
-
id: 1,
|
|
104
|
-
},
|
|
105
|
-
toolOutput: {
|
|
106
|
-
result: {
|
|
107
|
-
data: {
|
|
108
|
-
product: {
|
|
109
|
-
id: "1",
|
|
110
|
-
title: "Pen",
|
|
111
|
-
rating: 5,
|
|
112
|
-
price: 1.0,
|
|
113
|
-
description: "Awesome pen",
|
|
114
|
-
images: [],
|
|
115
|
-
__typename: "Product",
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
toolResponseMetadata: {
|
|
121
|
-
toolName: "the-store--Get Product",
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const manifest = {
|
|
126
|
-
format: "apollo-ai-app-manifest",
|
|
127
|
-
version: "1",
|
|
128
|
-
name: "the-store",
|
|
129
|
-
description:
|
|
130
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
131
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
132
|
-
operations: [
|
|
133
|
-
{
|
|
134
|
-
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
135
|
-
name: "Product",
|
|
136
|
-
type: "query",
|
|
137
|
-
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}",
|
|
138
|
-
variables: { id: "ID" },
|
|
139
|
-
prefetch: false,
|
|
140
|
-
tools: [
|
|
141
|
-
{
|
|
142
|
-
name: "Get Product",
|
|
143
|
-
description: "Shows the details page for a specific product.",
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
resource: "index.html",
|
|
149
|
-
csp: { connectDomains: [], resourceDomains: [] },
|
|
150
|
-
} satisfies ApplicationManifest;
|
|
151
|
-
|
|
152
|
-
const client = new ApolloClient({
|
|
153
|
-
cache: new InMemoryCache(),
|
|
154
|
-
manifest,
|
|
155
|
-
});
|
|
156
|
-
await client.prefetchData();
|
|
157
|
-
|
|
158
|
-
expect(client.extract()).toMatchInlineSnapshot(`
|
|
159
|
-
{
|
|
160
|
-
"Product:1": {
|
|
161
|
-
"__typename": "Product",
|
|
162
|
-
"description": "Awesome pen",
|
|
163
|
-
"id": "1",
|
|
164
|
-
"images": [],
|
|
165
|
-
"price": 1,
|
|
166
|
-
"rating": 5,
|
|
167
|
-
"title": "Pen",
|
|
168
|
-
},
|
|
169
|
-
"ROOT_QUERY": {
|
|
170
|
-
"__typename": "Query",
|
|
171
|
-
"product({"id":1})": {
|
|
172
|
-
"__ref": "Product:1",
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
}
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("Should cache prefetched data when prefetched data is provided", async () => {
|
|
180
|
-
vi.stubGlobal("openai", {
|
|
181
|
-
toolInput: {},
|
|
182
|
-
toolOutput: {
|
|
183
|
-
result: {},
|
|
184
|
-
prefetch: {
|
|
185
|
-
__anonymous: {
|
|
186
|
-
data: {
|
|
187
|
-
topProducts: [
|
|
188
|
-
{
|
|
189
|
-
id: "2",
|
|
190
|
-
title: "iPhone 17",
|
|
191
|
-
rating: 5,
|
|
192
|
-
price: 999.99,
|
|
193
|
-
description: "Awesome phone",
|
|
194
|
-
images: [],
|
|
195
|
-
__typename: "Product",
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
toolResponseMetadata: {
|
|
203
|
-
toolName: "the-store--Get Product",
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const manifest = {
|
|
208
|
-
format: "apollo-ai-app-manifest",
|
|
209
|
-
version: "1",
|
|
210
|
-
name: "the-store",
|
|
211
|
-
description:
|
|
212
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
213
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
214
|
-
operations: [
|
|
215
|
-
{
|
|
216
|
-
id: "cd0d52159b9003e791de97c6a76efa03d34fe00cee278d1a3f4bfcec5fb3e1e6",
|
|
217
|
-
name: "TopProducts",
|
|
218
|
-
type: "query",
|
|
219
|
-
body: "query TopProducts {\n topProducts {\n id\n title\n rating\n price\n __typename\n }\n}",
|
|
220
|
-
variables: {},
|
|
221
|
-
prefetch: true,
|
|
222
|
-
prefetchID: "__anonymous",
|
|
223
|
-
tools: [
|
|
224
|
-
{
|
|
225
|
-
name: "Top Products",
|
|
226
|
-
description: "Shows the currently highest rated products.",
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
resource: "index.html",
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
const client = new ApolloClient({
|
|
235
|
-
cache: new InMemoryCache(),
|
|
236
|
-
manifest: manifest as ApplicationManifest,
|
|
237
|
-
});
|
|
238
|
-
await client.prefetchData();
|
|
239
|
-
|
|
240
|
-
expect(client.extract()).toMatchInlineSnapshot(`
|
|
241
|
-
{
|
|
242
|
-
"Product:2": {
|
|
243
|
-
"__typename": "Product",
|
|
244
|
-
"id": "2",
|
|
245
|
-
"price": 999.99,
|
|
246
|
-
"rating": 5,
|
|
247
|
-
"title": "iPhone 17",
|
|
248
|
-
},
|
|
249
|
-
"ROOT_QUERY": {
|
|
250
|
-
"__typename": "Query",
|
|
251
|
-
"topProducts": [
|
|
252
|
-
{
|
|
253
|
-
"__ref": "Product:2",
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
},
|
|
257
|
-
}
|
|
258
|
-
`);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("Should cache both prefetch and tool response when both are provided", async () => {
|
|
262
|
-
vi.stubGlobal("openai", {
|
|
263
|
-
toolInput: {
|
|
264
|
-
id: 1,
|
|
265
|
-
},
|
|
266
|
-
toolOutput: {
|
|
267
|
-
result: {
|
|
268
|
-
data: {
|
|
269
|
-
product: {
|
|
270
|
-
id: "1",
|
|
271
|
-
title: "Pen",
|
|
272
|
-
rating: 5,
|
|
273
|
-
price: 1.0,
|
|
274
|
-
description: "Awesome pen",
|
|
275
|
-
images: [],
|
|
276
|
-
__typename: "Product",
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
prefetch: {
|
|
281
|
-
__anonymous: {
|
|
282
|
-
data: {
|
|
283
|
-
topProducts: [
|
|
284
|
-
{
|
|
285
|
-
id: "2",
|
|
286
|
-
title: "iPhone 17",
|
|
287
|
-
rating: 5,
|
|
288
|
-
price: 999.99,
|
|
289
|
-
description: "Awesome phone",
|
|
290
|
-
images: [],
|
|
291
|
-
__typename: "Product",
|
|
292
|
-
},
|
|
293
|
-
],
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
toolResponseMetadata: {
|
|
299
|
-
toolName: "the-store--Get Product",
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const manifest = {
|
|
304
|
-
format: "apollo-ai-app-manifest",
|
|
305
|
-
version: "1",
|
|
306
|
-
name: "the-store",
|
|
307
|
-
description:
|
|
308
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
309
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
310
|
-
operations: [
|
|
311
|
-
{
|
|
312
|
-
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
313
|
-
name: "Product",
|
|
314
|
-
type: "query",
|
|
315
|
-
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}",
|
|
316
|
-
variables: { id: "ID" },
|
|
317
|
-
prefetch: false,
|
|
318
|
-
tools: [
|
|
319
|
-
{
|
|
320
|
-
name: "Get Product",
|
|
321
|
-
description: "Shows the details page for a specific product.",
|
|
322
|
-
},
|
|
323
|
-
],
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
id: "cd0d52159b9003e791de97c6a76efa03d34fe00cee278d1a3f4bfcec5fb3e1e6",
|
|
327
|
-
name: "TopProducts",
|
|
328
|
-
type: "query",
|
|
329
|
-
body: "query TopProducts {\n topProducts {\n id\n title\n rating\n price\n __typename\n }\n}",
|
|
330
|
-
variables: {},
|
|
331
|
-
prefetch: true,
|
|
332
|
-
prefetchID: "__anonymous",
|
|
333
|
-
tools: [
|
|
334
|
-
{
|
|
335
|
-
name: "Top Products",
|
|
336
|
-
description: "Shows the currently highest rated products.",
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
},
|
|
340
|
-
],
|
|
341
|
-
resource: "index.html",
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const client = new ApolloClient({
|
|
345
|
-
cache: new InMemoryCache(),
|
|
346
|
-
manifest: manifest as ApplicationManifest,
|
|
347
|
-
});
|
|
348
|
-
await client.prefetchData();
|
|
349
|
-
|
|
350
|
-
expect(client.extract()).toMatchInlineSnapshot(`
|
|
351
|
-
{
|
|
352
|
-
"Product:1": {
|
|
353
|
-
"__typename": "Product",
|
|
354
|
-
"description": "Awesome pen",
|
|
355
|
-
"id": "1",
|
|
356
|
-
"images": [],
|
|
357
|
-
"price": 1,
|
|
358
|
-
"rating": 5,
|
|
359
|
-
"title": "Pen",
|
|
360
|
-
},
|
|
361
|
-
"Product:2": {
|
|
362
|
-
"__typename": "Product",
|
|
363
|
-
"id": "2",
|
|
364
|
-
"price": 999.99,
|
|
365
|
-
"rating": 5,
|
|
366
|
-
"title": "iPhone 17",
|
|
367
|
-
},
|
|
368
|
-
"ROOT_QUERY": {
|
|
369
|
-
"__typename": "Query",
|
|
370
|
-
"product({"id":1})": {
|
|
371
|
-
"__ref": "Product:1",
|
|
372
|
-
},
|
|
373
|
-
"topProducts": [
|
|
374
|
-
{
|
|
375
|
-
"__ref": "Product:2",
|
|
376
|
-
},
|
|
377
|
-
],
|
|
378
|
-
},
|
|
379
|
-
}
|
|
380
|
-
`);
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
test("Should exclude extra inputs when writing to cache", async () => {
|
|
384
|
-
vi.stubGlobal("openai", {
|
|
385
|
-
toolInput: {
|
|
386
|
-
id: 1,
|
|
387
|
-
myOtherThing: 2,
|
|
388
|
-
},
|
|
389
|
-
toolOutput: {
|
|
390
|
-
result: {
|
|
391
|
-
data: {
|
|
392
|
-
product: {
|
|
393
|
-
id: "1",
|
|
394
|
-
title: "Pen",
|
|
395
|
-
rating: 5,
|
|
396
|
-
price: 1.0,
|
|
397
|
-
description: "Awesome pen",
|
|
398
|
-
images: [],
|
|
399
|
-
__typename: "Product",
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
toolResponseMetadata: {
|
|
405
|
-
toolName: "the-store--Get Product",
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const manifest = {
|
|
410
|
-
format: "apollo-ai-app-manifest",
|
|
411
|
-
version: "1",
|
|
412
|
-
name: "the-store",
|
|
413
|
-
description:
|
|
414
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
415
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
416
|
-
operations: [
|
|
417
|
-
{
|
|
418
|
-
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
419
|
-
name: "Product",
|
|
420
|
-
type: "query",
|
|
421
|
-
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}",
|
|
422
|
-
variables: { id: "ID" },
|
|
423
|
-
prefetch: false,
|
|
424
|
-
tools: [
|
|
425
|
-
{
|
|
426
|
-
name: "Get Product",
|
|
427
|
-
description: "Shows the details page for a specific product.",
|
|
428
|
-
},
|
|
429
|
-
],
|
|
430
|
-
},
|
|
431
|
-
],
|
|
432
|
-
resource: "index.html",
|
|
433
|
-
csp: { connectDomains: [], resourceDomains: [] },
|
|
434
|
-
} satisfies ApplicationManifest;
|
|
435
|
-
|
|
436
|
-
const client = new ApolloClient({
|
|
437
|
-
cache: new InMemoryCache(),
|
|
438
|
-
manifest,
|
|
439
|
-
});
|
|
440
|
-
await client.prefetchData();
|
|
441
|
-
|
|
442
|
-
expect(client.extract()).toMatchInlineSnapshot(`
|
|
443
|
-
{
|
|
444
|
-
"Product:1": {
|
|
445
|
-
"__typename": "Product",
|
|
446
|
-
"description": "Awesome pen",
|
|
447
|
-
"id": "1",
|
|
448
|
-
"images": [],
|
|
449
|
-
"price": 1,
|
|
450
|
-
"rating": 5,
|
|
451
|
-
"title": "Pen",
|
|
452
|
-
},
|
|
453
|
-
"ROOT_QUERY": {
|
|
454
|
-
"__typename": "Query",
|
|
455
|
-
"product({"id":1})": {
|
|
456
|
-
"__ref": "Product:1",
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
}
|
|
460
|
-
`);
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
describe("custom links", () => {
|
|
465
|
-
test("allows for custom links provided to the constructor", async () => {
|
|
466
|
-
vi.stubGlobal("openai", {
|
|
467
|
-
toolInput: {},
|
|
468
|
-
toolOutput: {},
|
|
469
|
-
toolResponseMetadata: {
|
|
470
|
-
toolName: "the-store--Get Product",
|
|
471
|
-
},
|
|
472
|
-
callTool: vi.fn(async (name: string, args: Record<string, unknown>) => {
|
|
473
|
-
return {
|
|
474
|
-
structuredContent: {
|
|
475
|
-
data: {
|
|
476
|
-
product: {
|
|
477
|
-
id: "1",
|
|
478
|
-
title: "Pen",
|
|
479
|
-
rating: 5,
|
|
480
|
-
price: 1.0,
|
|
481
|
-
description: "Awesome pen",
|
|
482
|
-
images: [],
|
|
483
|
-
__typename: "Product",
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
},
|
|
487
|
-
};
|
|
488
|
-
}),
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
const manifest = createManifest();
|
|
492
|
-
const linkHandler = vi.fn<ApolloLink.RequestHandler>((operation, forward) =>
|
|
493
|
-
forward(operation)
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
const client = new ApolloClient({
|
|
497
|
-
manifest,
|
|
498
|
-
cache: new InMemoryCache(),
|
|
499
|
-
link: ApolloLink.from([new ApolloLink(linkHandler), new ToolCallLink()]),
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
const variables = { id: "1" };
|
|
503
|
-
const query = parse(manifest.operations[0].body);
|
|
504
|
-
|
|
505
|
-
await expect(client.query({ query, variables })).resolves.toStrictEqual({
|
|
506
|
-
data: {
|
|
507
|
-
product: {
|
|
508
|
-
id: "1",
|
|
509
|
-
title: "Pen",
|
|
510
|
-
rating: 5,
|
|
511
|
-
price: 1.0,
|
|
512
|
-
description: "Awesome pen",
|
|
513
|
-
images: [],
|
|
514
|
-
__typename: "Product",
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
expect(linkHandler).toHaveBeenCalledOnce();
|
|
520
|
-
expect(linkHandler).toHaveBeenCalledWith(
|
|
521
|
-
expect.objectContaining({ query, variables, operationType: "query" }),
|
|
522
|
-
expect.any(Function)
|
|
523
|
-
);
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
test("enforces ToolCallLink as terminating link", async () => {
|
|
527
|
-
const manifest = createManifest();
|
|
528
|
-
const expectedError = new Error(
|
|
529
|
-
"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."
|
|
530
|
-
);
|
|
531
|
-
|
|
532
|
-
expect(() => {
|
|
533
|
-
new ApolloClient({
|
|
534
|
-
manifest,
|
|
535
|
-
cache: new InMemoryCache(),
|
|
536
|
-
link: new HttpLink(),
|
|
537
|
-
});
|
|
538
|
-
}).toThrow(expectedError);
|
|
539
|
-
|
|
540
|
-
expect(() => {
|
|
541
|
-
new ApolloClient({
|
|
542
|
-
manifest,
|
|
543
|
-
cache: new InMemoryCache(),
|
|
544
|
-
link: new ApolloLink(),
|
|
545
|
-
});
|
|
546
|
-
}).toThrow(expectedError);
|
|
547
|
-
|
|
548
|
-
expect(() => {
|
|
549
|
-
new ApolloClient({
|
|
550
|
-
manifest,
|
|
551
|
-
cache: new InMemoryCache(),
|
|
552
|
-
link: ApolloLink.from([new ApolloLink(), new HttpLink()]),
|
|
553
|
-
});
|
|
554
|
-
}).toThrow(expectedError);
|
|
555
|
-
|
|
556
|
-
expect(() => {
|
|
557
|
-
new ApolloClient({
|
|
558
|
-
manifest,
|
|
559
|
-
cache: new InMemoryCache(),
|
|
560
|
-
link: ApolloLink.split(() => true, new ApolloLink(), new HttpLink()),
|
|
561
|
-
});
|
|
562
|
-
}).toThrow(expectedError);
|
|
563
|
-
|
|
564
|
-
expect(() => {
|
|
565
|
-
new ApolloClient({
|
|
566
|
-
manifest,
|
|
567
|
-
cache: new InMemoryCache(),
|
|
568
|
-
link: ApolloLink.split(() => true, new ToolCallLink(), new HttpLink()),
|
|
569
|
-
});
|
|
570
|
-
}).toThrow(expectedError);
|
|
571
|
-
|
|
572
|
-
// Allow you to use a custom terminating link for `split` links if the
|
|
573
|
-
// custom link is the `left` branch link.
|
|
574
|
-
expect(() => {
|
|
575
|
-
new ApolloClient({
|
|
576
|
-
manifest,
|
|
577
|
-
cache: new InMemoryCache(),
|
|
578
|
-
link: ApolloLink.split(() => true, new HttpLink(), new ToolCallLink()),
|
|
579
|
-
});
|
|
580
|
-
}).not.toThrow(expectedError);
|
|
581
|
-
|
|
582
|
-
expect(() => {
|
|
583
|
-
new ApolloClient({
|
|
584
|
-
manifest,
|
|
585
|
-
cache: new InMemoryCache(),
|
|
586
|
-
link: ApolloLink.split(
|
|
587
|
-
() => true,
|
|
588
|
-
new ToolCallLink(),
|
|
589
|
-
new ToolCallLink()
|
|
590
|
-
),
|
|
591
|
-
});
|
|
592
|
-
}).not.toThrow();
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
function createManifest(
|
|
597
|
-
overrides?: Partial<ApplicationManifest>
|
|
598
|
-
): ApplicationManifest {
|
|
599
|
-
return {
|
|
600
|
-
format: "apollo-ai-app-manifest",
|
|
601
|
-
version: "1",
|
|
602
|
-
name: "the-store",
|
|
603
|
-
description:
|
|
604
|
-
"An online store selling a variety of high quality products across many different categories.",
|
|
605
|
-
hash: "f6a24922f6ad6ed8c2aa57baf3b8242ae5f38a09a6df3f2693077732434c4256",
|
|
606
|
-
operations: [
|
|
607
|
-
{
|
|
608
|
-
id: "c43af26552874026c3fb346148c5795896aa2f3a872410a0a2621cffee25291c",
|
|
609
|
-
name: "Product",
|
|
610
|
-
type: "query",
|
|
611
|
-
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}",
|
|
612
|
-
variables: { id: "ID" },
|
|
613
|
-
prefetch: false,
|
|
614
|
-
tools: [
|
|
615
|
-
{
|
|
616
|
-
name: "Get Product",
|
|
617
|
-
description: "Shows the details page for a specific product.",
|
|
618
|
-
},
|
|
619
|
-
],
|
|
620
|
-
},
|
|
621
|
-
],
|
|
622
|
-
resource: "index.html",
|
|
623
|
-
csp: { resourceDomains: [], connectDomains: [] },
|
|
624
|
-
...overrides,
|
|
625
|
-
};
|
|
626
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { ApolloProvider } from "../ApolloProvider.js";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
4
|
-
import { ApolloClient } from "../../core/ApolloClient.js";
|
|
5
|
-
import { SET_GLOBALS_EVENT_TYPE } from "../../types/openai.js";
|
|
6
|
-
|
|
7
|
-
test("Should call prefetch data when window.open is immediately available", () => {
|
|
8
|
-
vi.stubGlobal("openai", {
|
|
9
|
-
toolOutput: {},
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const client = {
|
|
13
|
-
prefetchData: vi.fn(async () => {}),
|
|
14
|
-
} as unknown as ApolloClient;
|
|
15
|
-
|
|
16
|
-
render(<ApolloProvider client={client} />);
|
|
17
|
-
|
|
18
|
-
expect(client.prefetchData).toBeCalled();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("Should NOT call prefetch data when window.open is not immediately available", () => {
|
|
22
|
-
const client = {
|
|
23
|
-
prefetchData: vi.fn(async () => {}),
|
|
24
|
-
} as unknown as ApolloClient;
|
|
25
|
-
|
|
26
|
-
render(<ApolloProvider client={client} />);
|
|
27
|
-
|
|
28
|
-
expect(client.prefetchData).not.toBeCalled();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("Should call prefetch data when window.open is not immediately available and event is sent", () => {
|
|
32
|
-
const client = {
|
|
33
|
-
prefetchData: vi.fn(async () => {}),
|
|
34
|
-
} as unknown as ApolloClient;
|
|
35
|
-
|
|
36
|
-
render(<ApolloProvider client={client} />);
|
|
37
|
-
|
|
38
|
-
window.dispatchEvent(new CustomEvent(SET_GLOBALS_EVENT_TYPE));
|
|
39
|
-
|
|
40
|
-
expect(client.prefetchData).toBeCalled();
|
|
41
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { createContext, useContext, useState } from "react";
|
|
3
|
-
|
|
4
|
-
interface ToolUseState {
|
|
5
|
-
appName: string;
|
|
6
|
-
hasNavigated: boolean;
|
|
7
|
-
setHasNavigated: (v: boolean) => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const ToolUseContext = createContext<ToolUseState | null>(null);
|
|
11
|
-
|
|
12
|
-
export declare namespace ToolUseProvider {
|
|
13
|
-
export interface Props {
|
|
14
|
-
children?: ReactNode;
|
|
15
|
-
appName: string;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function ToolUseProvider({ children, appName }: ToolUseProvider.Props) {
|
|
20
|
-
const [hasNavigated, setHasNavigated] = useState(false);
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<ToolUseContext.Provider value={{ hasNavigated, setHasNavigated, appName }}>
|
|
24
|
-
{children}
|
|
25
|
-
</ToolUseContext.Provider>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function useToolUseState() {
|
|
30
|
-
return useContext(ToolUseContext);
|
|
31
|
-
}
|