@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,86 @@
|
|
|
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 { useToolMetadata } from "../useToolMetadata.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 metadata from window.openai", async () => {
|
|
23
|
+
using _ = spyOnConsole("debug");
|
|
24
|
+
stubOpenAiGlobals({ toolResponseMetadata: { foo: true } });
|
|
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: {} });
|
|
34
|
+
host.sendToolResult({
|
|
35
|
+
content: [],
|
|
36
|
+
structuredContent: {},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
using _disabledAct = disableActEnvironment();
|
|
40
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
41
|
+
() => useToolMetadata(),
|
|
42
|
+
{
|
|
43
|
+
wrapper: ({ children }) => (
|
|
44
|
+
<Suspense>
|
|
45
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
46
|
+
</Suspense>
|
|
47
|
+
),
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
await expect(takeSnapshot()).resolves.toEqual({ foo: true });
|
|
52
|
+
await expect(takeSnapshot).not.toRerender();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("returns null when not set", async () => {
|
|
56
|
+
using _ = spyOnConsole("debug");
|
|
57
|
+
stubOpenAiGlobals();
|
|
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.sendToolInput({ arguments: {} });
|
|
67
|
+
host.sendToolResult({
|
|
68
|
+
content: [],
|
|
69
|
+
structuredContent: {},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
using _disabledAct = disableActEnvironment();
|
|
73
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
74
|
+
() => useToolMetadata(),
|
|
75
|
+
{
|
|
76
|
+
wrapper: ({ children }) => (
|
|
77
|
+
<Suspense>
|
|
78
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
79
|
+
</Suspense>
|
|
80
|
+
),
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
await expect(takeSnapshot()).resolves.toBeNull();
|
|
85
|
+
await expect(takeSnapshot).not.toRerender();
|
|
86
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { useToolName } from "../useToolName.js";
|
|
3
|
+
import {
|
|
4
|
+
graphqlToolResult,
|
|
5
|
+
minimalHostContextWithToolName,
|
|
6
|
+
mockApplicationManifest,
|
|
7
|
+
mockMcpHost,
|
|
8
|
+
spyOnConsole,
|
|
9
|
+
stubOpenAiGlobals,
|
|
10
|
+
} from "../../../../testing/internal/index.js";
|
|
11
|
+
import { ApolloClient } from "../../../core/ApolloClient.js";
|
|
12
|
+
import { InMemoryCache } from "@apollo/client";
|
|
13
|
+
import {
|
|
14
|
+
disableActEnvironment,
|
|
15
|
+
renderHookToSnapshotStream,
|
|
16
|
+
} from "@testing-library/react-render-stream";
|
|
17
|
+
import { Suspense } from "react";
|
|
18
|
+
import { ApolloProvider } from "../../../../react/ApolloProvider.js";
|
|
19
|
+
|
|
20
|
+
test("returns the tool name from the MCP host", async () => {
|
|
21
|
+
using _ = spyOnConsole("debug");
|
|
22
|
+
stubOpenAiGlobals({ toolResponseMetadata: {} });
|
|
23
|
+
const client = new ApolloClient({
|
|
24
|
+
cache: new InMemoryCache(),
|
|
25
|
+
manifest: mockApplicationManifest(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
using host = await mockMcpHost({
|
|
29
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
30
|
+
});
|
|
31
|
+
host.onCleanup(() => client.stop());
|
|
32
|
+
|
|
33
|
+
host.sendToolInput({ arguments: {} });
|
|
34
|
+
host.sendToolResult(graphqlToolResult({ data: { product: null } }));
|
|
35
|
+
|
|
36
|
+
using _disabledAct = disableActEnvironment();
|
|
37
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
38
|
+
() => useToolName(),
|
|
39
|
+
{
|
|
40
|
+
wrapper: ({ children }) => (
|
|
41
|
+
<Suspense>
|
|
42
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
43
|
+
</Suspense>
|
|
44
|
+
),
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await expect(takeSnapshot()).resolves.toBe("GetProduct");
|
|
49
|
+
await expect(takeSnapshot).not.toRerender();
|
|
50
|
+
});
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
renderHookToSnapshotStream,
|
|
5
5
|
} from "@testing-library/react-render-stream";
|
|
6
6
|
import { useWidgetState } from "../useWidgetState.js";
|
|
7
|
-
import { stubOpenAiGlobals } from "
|
|
7
|
+
import { stubOpenAiGlobals } from "../../../../testing/internal/index.js";
|
|
8
8
|
|
|
9
9
|
afterEach(() => {
|
|
10
10
|
vi.unstubAllGlobals();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useApolloClient as useBaseApolloClient } from "@apollo/client/react";
|
|
2
|
+
import { ApolloClient } from "../../core/ApolloClient.js";
|
|
3
|
+
import { aiClientSymbol, invariant } from "../../../utilities/index.js";
|
|
4
|
+
|
|
5
|
+
export function useApolloClient(override?: ApolloClient) {
|
|
6
|
+
const client = useBaseApolloClient(override) as ApolloClient;
|
|
7
|
+
|
|
8
|
+
invariant(
|
|
9
|
+
client[aiClientSymbol],
|
|
10
|
+
'The "client" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return client;
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useSyncExternalStore, useCallback } from "react";
|
|
2
|
-
import type { SetGlobalsEvent, OpenAiGlobals } from "../../types
|
|
3
|
-
import { SET_GLOBALS_EVENT_TYPE } from "../../types
|
|
2
|
+
import type { SetGlobalsEvent, OpenAiGlobals } from "../../types.js";
|
|
3
|
+
import { SET_GLOBALS_EVENT_TYPE } from "../../types.js";
|
|
4
4
|
|
|
5
5
|
export function useOpenAiGlobal<K extends keyof OpenAiGlobals>(
|
|
6
6
|
key: K
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SetStateAction } from "react";
|
|
2
2
|
import { useCallback, useState } from "react";
|
|
3
|
-
import type { UnknownObject } from "../../types
|
|
3
|
+
import type { UnknownObject } from "../../types.js";
|
|
4
4
|
import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
|
|
5
5
|
|
|
6
6
|
export function useWidgetState<T extends UnknownObject>(
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useApp } from "./hooks/useApp.js";
|
|
2
|
+
export { useToolName } from "./hooks/useToolName.js";
|
|
3
|
+
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
4
|
+
export { useToolInput } from "./hooks/useToolInput.js";
|
|
5
|
+
export { useWidgetState } from "./hooks/useWidgetState.js";
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
openai: API<any> & OpenAiGlobals;
|
|
6
|
-
}
|
|
1
|
+
import type { ApolloMcpServerApps } from "../core/types";
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
3
|
+
export type UnknownObject = Record<string, unknown>;
|
|
12
4
|
|
|
13
5
|
export type OpenAiGlobals<
|
|
14
6
|
ToolInput extends UnknownObject = UnknownObject,
|
|
15
|
-
ToolOutput
|
|
16
|
-
ToolResponseMetadata
|
|
7
|
+
ToolOutput = ApolloMcpServerApps.StructuredContent,
|
|
8
|
+
ToolResponseMetadata = UnknownObject,
|
|
17
9
|
WidgetState extends UnknownObject = UnknownObject,
|
|
18
10
|
> = {
|
|
19
11
|
theme: Theme;
|
|
@@ -65,7 +57,11 @@ export class SetGlobalsEvent extends CustomEvent<{
|
|
|
65
57
|
export type CallTool = (
|
|
66
58
|
name: string,
|
|
67
59
|
args: Record<string, unknown>
|
|
68
|
-
) => Promise<
|
|
60
|
+
) => Promise<CallToolResponse>;
|
|
61
|
+
|
|
62
|
+
export type CallToolResponse = {
|
|
63
|
+
result: string;
|
|
64
|
+
};
|
|
69
65
|
|
|
70
66
|
export type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
71
67
|
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { use } from "react";
|
|
3
3
|
import { ApolloProvider as BaseApolloProvider } from "@apollo/client/react";
|
|
4
|
-
import type { ApolloClient } from "
|
|
5
|
-
import {
|
|
4
|
+
import type { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
5
|
+
import { ApolloClient as OpenAiApolloClient } from "../openai/core/ApolloClient.js";
|
|
6
|
+
import { ApolloClient as McpApolloClient } from "../mcp/core/ApolloClient.js";
|
|
7
|
+
import type { ApolloClient as FallbackApolloClient } from "../core/ApolloClient.js";
|
|
8
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
9
|
+
import { aiClientSymbol, invariant } from "../utilities/index.js";
|
|
10
|
+
|
|
11
|
+
type ApolloClient = OpenAiApolloClient | McpApolloClient | FallbackApolloClient;
|
|
6
12
|
|
|
7
13
|
export declare namespace ApolloProvider {
|
|
8
14
|
export interface Props {
|
|
@@ -11,33 +17,19 @@ export declare namespace ApolloProvider {
|
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const prefetchData = async () => {
|
|
22
|
-
await client.prefetchData();
|
|
23
|
-
setHasPreloaded(true);
|
|
24
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
window.addEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData, {
|
|
28
|
-
passive: true,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
if (window.openai?.toolOutput) {
|
|
32
|
-
window.dispatchEvent(new CustomEvent(SET_GLOBALS_EVENT_TYPE));
|
|
33
|
-
}
|
|
20
|
+
export function ApolloProvider({ children, client }: ApolloProvider.Props) {
|
|
21
|
+
if (__DEV__) {
|
|
22
|
+
invariant(
|
|
23
|
+
client[aiClientSymbol],
|
|
24
|
+
'The "client" instance provided to <ApolloProvider /> is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
28
|
+
use(client.waitForInitialization());
|
|
39
29
|
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
return (
|
|
31
|
+
<BaseApolloProvider client={client as BaseApolloClient}>
|
|
32
|
+
{children}
|
|
33
|
+
</BaseApolloProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { ApolloProvider } from "../../ApolloProvider.js";
|
|
4
|
+
import { waitFor } from "@testing-library/react";
|
|
5
|
+
import { ApolloClient } from "../../../mcp/core/ApolloClient.js";
|
|
6
|
+
import { gql, InMemoryCache } from "@apollo/client";
|
|
7
|
+
import { print } from "@apollo/client/utilities";
|
|
8
|
+
import {
|
|
9
|
+
minimalHostContextWithToolName,
|
|
10
|
+
mockApplicationManifest,
|
|
11
|
+
mockMcpHost,
|
|
12
|
+
renderAsync,
|
|
13
|
+
spyOnConsole,
|
|
14
|
+
} from "../../../testing/internal/index.js";
|
|
15
|
+
|
|
16
|
+
test("writes to the cache as soon as toolOutput is available", async () => {
|
|
17
|
+
using _ = spyOnConsole("debug");
|
|
18
|
+
|
|
19
|
+
const toolName = "GreetingQuery";
|
|
20
|
+
using host = await mockMcpHost({
|
|
21
|
+
hostContext: minimalHostContextWithToolName(toolName),
|
|
22
|
+
});
|
|
23
|
+
host.onCleanup(() => client.stop());
|
|
24
|
+
|
|
25
|
+
const query = gql`
|
|
26
|
+
query GreetingQuery {
|
|
27
|
+
greeting
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
const data = {
|
|
31
|
+
greeting: "hello",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const client = new ApolloClient({
|
|
35
|
+
cache: new InMemoryCache(),
|
|
36
|
+
manifest: mockApplicationManifest({
|
|
37
|
+
operations: [
|
|
38
|
+
{
|
|
39
|
+
id: "1",
|
|
40
|
+
name: "GreetingQuery",
|
|
41
|
+
body: print(query),
|
|
42
|
+
prefetch: true,
|
|
43
|
+
prefetchID: "__anonymous",
|
|
44
|
+
type: "query",
|
|
45
|
+
variables: {},
|
|
46
|
+
tools: [{ name: toolName, description: "Fetches a greeting" }],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
await renderAsync(<ApolloProvider client={client} />, {
|
|
53
|
+
wrapper: ({ children }) => <Suspense>{children}</Suspense>,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await expect(
|
|
57
|
+
waitFor(() => expect(client.extract()).not.toEqual({}))
|
|
58
|
+
).rejects.toThrow();
|
|
59
|
+
|
|
60
|
+
host.sendToolInput({ arguments: {} });
|
|
61
|
+
host.sendToolResult({
|
|
62
|
+
content: [{ type: "text", text: JSON.stringify({ result: { data } }) }],
|
|
63
|
+
structuredContent: { result: { data } },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await waitFor(() => {
|
|
67
|
+
expect(client.extract()).toEqual({
|
|
68
|
+
ROOT_QUERY: {
|
|
69
|
+
__typename: "Query",
|
|
70
|
+
greeting: "hello",
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { ApolloProvider } from "../../ApolloProvider.js";
|
|
4
|
+
import { waitFor } from "@testing-library/react";
|
|
5
|
+
import { ApolloClient } from "../../../openai/core/ApolloClient.js";
|
|
6
|
+
import { gql, InMemoryCache } from "@apollo/client";
|
|
7
|
+
import { print } from "@apollo/client/utilities";
|
|
8
|
+
import {
|
|
9
|
+
minimalHostContextWithToolName,
|
|
10
|
+
mockApplicationManifest,
|
|
11
|
+
mockMcpHost,
|
|
12
|
+
renderAsync,
|
|
13
|
+
spyOnConsole,
|
|
14
|
+
stubOpenAiGlobals,
|
|
15
|
+
} from "../../../testing/internal/index.js";
|
|
16
|
+
|
|
17
|
+
test("writes data to the cache when immediately available", async () => {
|
|
18
|
+
stubOpenAiGlobals();
|
|
19
|
+
using _ = spyOnConsole("debug");
|
|
20
|
+
|
|
21
|
+
const query = gql`
|
|
22
|
+
query GreetingQuery {
|
|
23
|
+
greeting
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const data = {
|
|
28
|
+
greeting: "hello",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const client = new ApolloClient({
|
|
32
|
+
cache: new InMemoryCache(),
|
|
33
|
+
manifest: mockApplicationManifest({
|
|
34
|
+
operations: [
|
|
35
|
+
{
|
|
36
|
+
id: "1",
|
|
37
|
+
name: "GreetingQuery",
|
|
38
|
+
body: print(query),
|
|
39
|
+
prefetch: true,
|
|
40
|
+
prefetchID: "__anonymous",
|
|
41
|
+
type: "query",
|
|
42
|
+
variables: {},
|
|
43
|
+
tools: [],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
using host = await mockMcpHost({
|
|
50
|
+
hostContext: minimalHostContextWithToolName("GreetingQuery"),
|
|
51
|
+
});
|
|
52
|
+
host.onCleanup(() => client.stop());
|
|
53
|
+
|
|
54
|
+
host.sendToolInput({ arguments: {} });
|
|
55
|
+
host.sendToolResult({
|
|
56
|
+
content: [],
|
|
57
|
+
structuredContent: {
|
|
58
|
+
result: {
|
|
59
|
+
data: null,
|
|
60
|
+
},
|
|
61
|
+
prefetch: {
|
|
62
|
+
__anonymous: { data },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await renderAsync(<ApolloProvider client={client} />, {
|
|
68
|
+
wrapper: ({ children }) => <Suspense>{children}</Suspense>,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(client.extract()).toEqual({
|
|
73
|
+
ROOT_QUERY: {
|
|
74
|
+
__typename: "Query",
|
|
75
|
+
greeting: "hello",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("writes to the cache as soon as toolOutput is available", async () => {
|
|
82
|
+
stubOpenAiGlobals();
|
|
83
|
+
using _ = spyOnConsole("debug");
|
|
84
|
+
|
|
85
|
+
stubOpenAiGlobals();
|
|
86
|
+
|
|
87
|
+
const query = gql`
|
|
88
|
+
query GreetingQuery {
|
|
89
|
+
greeting
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
const data = {
|
|
93
|
+
greeting: "hello",
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const client = new ApolloClient({
|
|
97
|
+
cache: new InMemoryCache(),
|
|
98
|
+
manifest: mockApplicationManifest({
|
|
99
|
+
operations: [
|
|
100
|
+
{
|
|
101
|
+
id: "1",
|
|
102
|
+
name: "GreetingQuery",
|
|
103
|
+
body: print(query),
|
|
104
|
+
prefetch: true,
|
|
105
|
+
prefetchID: "__anonymous",
|
|
106
|
+
type: "query",
|
|
107
|
+
variables: {},
|
|
108
|
+
tools: [],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
using host = await mockMcpHost({
|
|
115
|
+
hostContext: minimalHostContextWithToolName("GreetingQuery"),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
host.onCleanup(() => client.stop());
|
|
119
|
+
host.sendToolInput({ arguments: {} });
|
|
120
|
+
|
|
121
|
+
await renderAsync(<ApolloProvider client={client} />, {
|
|
122
|
+
wrapper: ({ children }) => <Suspense>{children}</Suspense>,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await expect(
|
|
126
|
+
waitFor(() => expect(client.extract()).not.toEqual({}))
|
|
127
|
+
).rejects.toThrow();
|
|
128
|
+
|
|
129
|
+
host.sendToolResult({
|
|
130
|
+
content: [],
|
|
131
|
+
structuredContent: {
|
|
132
|
+
prefetch: {
|
|
133
|
+
__anonymous: { data },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await waitFor(() => {
|
|
139
|
+
expect(client.extract()).toEqual({
|
|
140
|
+
ROOT_QUERY: {
|
|
141
|
+
__typename: "Query",
|
|
142
|
+
greeting: "hello",
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { missingHook } from "./missingHook.js";
|
|
2
|
+
|
|
3
|
+
export { ApolloProvider } from "./ApolloProvider.js";
|
|
4
|
+
|
|
5
|
+
// Use `mcp` related types since these are the most common between the two
|
|
6
|
+
// targets
|
|
7
|
+
export const useApp =
|
|
8
|
+
missingHook<typeof import("./index.mcp.js").useApp>("useApp");
|
|
9
|
+
|
|
10
|
+
export const useToolInput =
|
|
11
|
+
missingHook<typeof import("./index.mcp.js").useToolInput>("useToolInput");
|
|
12
|
+
|
|
13
|
+
export const useToolMetadata =
|
|
14
|
+
missingHook<typeof import("./index.mcp.js").useToolMetadata>(
|
|
15
|
+
"useToolMetadata"
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const useToolName =
|
|
19
|
+
missingHook<typeof import("./index.mcp.js").useToolName>("useToolName");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function missingHook<HookFn extends (...args: any[]) => any>(
|
|
2
|
+
name: string
|
|
3
|
+
) {
|
|
4
|
+
return (() => {
|
|
5
|
+
throw new Error(
|
|
6
|
+
`Cannot use the '${name}' hook without export conditions. Please set export conditions or import from the \`/openai\` or \`/mcp\` subpath directly.`
|
|
7
|
+
);
|
|
8
|
+
}) as unknown as HookFn;
|
|
9
|
+
}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export { dispatchStateChange } from "./openai/dispatchStateChange.js";
|
|
2
|
+
export { graphqlToolResult } from "./mcp/graphqlToolResult.js";
|
|
3
|
+
export { mockApplicationManifest } from "./utilities/mockApplicationManifest.js";
|
|
2
4
|
export { stubOpenAiGlobals } from "./openai/stubOpenAiGlobals.js";
|
|
5
|
+
export { minimalHostContextWithToolName } from "./mcp/minimalHostContextWithToolName.js";
|
|
6
|
+
export { mockMcpHost } from "./mcp/mockMcpHost.js";
|
|
7
|
+
export { ObservableStream } from "./utilities/ObservableStream.js";
|
|
8
|
+
export { renderAsync } from "./react/renderAsync.js";
|
|
9
|
+
export { spyOnConsole } from "./utilities/spyOnConsole.js";
|
|
10
|
+
export { wait } from "./utilities/wait.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { expect } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ObservableStream,
|
|
5
|
+
TakeOptions,
|
|
6
|
+
} from "../utilities/ObservableStream.js";
|
|
7
|
+
import { EventMismatchError } from "../utilities/ObservableStream.js";
|
|
8
|
+
|
|
9
|
+
expect.extend({
|
|
10
|
+
async toComplete(actual, options?: TakeOptions) {
|
|
11
|
+
const stream = actual as ObservableStream<any>;
|
|
12
|
+
const hint = this.utils.matcherHint("toComplete", "stream", "");
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
await stream.takeComplete(options);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
pass: true,
|
|
19
|
+
message: () => {
|
|
20
|
+
return hint + "\n\nExpected stream not to complete but it did.";
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (
|
|
25
|
+
error instanceof Error &&
|
|
26
|
+
error.message === "Timeout waiting for next event"
|
|
27
|
+
) {
|
|
28
|
+
return {
|
|
29
|
+
pass: false,
|
|
30
|
+
message: () =>
|
|
31
|
+
hint + "\n\nExpected stream to complete but it did not.",
|
|
32
|
+
};
|
|
33
|
+
} else if (EventMismatchError.is(error)) {
|
|
34
|
+
return {
|
|
35
|
+
pass: false,
|
|
36
|
+
message: () =>
|
|
37
|
+
hint +
|
|
38
|
+
"\n\n" +
|
|
39
|
+
this.utils.printDiffOrStringify(error.actual, error.expected),
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|