@apollo/client-ai-apps 0.4.0 → 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 +353 -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 +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,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const AppTarget = z.literal(["mcp", "openai"]);
|
|
3
|
+
const Mode = z
|
|
4
|
+
.literal(["development", "production"])
|
|
5
|
+
.or(z.custom((value) => typeof value === "string"));
|
|
6
|
+
const labelsInput = z.exactOptional(z.strictObject({
|
|
7
|
+
toolInvocation: z.exactOptional(z.strictObject({
|
|
8
|
+
invoking: z.string().exactOptional(),
|
|
9
|
+
invoked: z.string().exactOptional(),
|
|
10
|
+
})),
|
|
11
|
+
}));
|
|
12
|
+
const labelsOutput = z.exactOptional(z.strictObject({
|
|
13
|
+
"toolInvocation/invoking": z.string().exactOptional(),
|
|
14
|
+
"toolInvocation/invoked": z.string().exactOptional(),
|
|
15
|
+
}));
|
|
16
|
+
export const ApolloClientAiAppsConfigSchema = z.strictObject({
|
|
17
|
+
name: z.string().exactOptional(),
|
|
18
|
+
description: z.string().exactOptional(),
|
|
19
|
+
version: z.string().exactOptional(),
|
|
20
|
+
entry: z.exactOptional(z.partialRecord(Mode, z.union([z.string(), z.partialRecord(AppTarget, z.string())]))),
|
|
21
|
+
csp: z.exactOptional(z.strictObject({
|
|
22
|
+
connectDomains: z.array(z.string()).exactOptional(),
|
|
23
|
+
frameDomains: z.array(z.string()).exactOptional(),
|
|
24
|
+
redirectDomains: z.array(z.string()).exactOptional(),
|
|
25
|
+
resourceDomains: z.array(z.string()).exactOptional(),
|
|
26
|
+
})),
|
|
27
|
+
widgetSettings: z.exactOptional(z.strictObject({
|
|
28
|
+
prefersBorder: z.boolean().exactOptional(),
|
|
29
|
+
description: z.string().exactOptional(),
|
|
30
|
+
domain: z.string().exactOptional(),
|
|
31
|
+
})),
|
|
32
|
+
labels: z.codec(labelsInput, labelsOutput, {
|
|
33
|
+
encode: () => {
|
|
34
|
+
// encode is currently not used so we can skip the business logic and
|
|
35
|
+
// return an empty object which satisfies the type. If we need to encode
|
|
36
|
+
// labels back to the original form, this will need to be implemented
|
|
37
|
+
return {};
|
|
38
|
+
},
|
|
39
|
+
decode: ({ toolInvocation }) => {
|
|
40
|
+
const config = {};
|
|
41
|
+
if (toolInvocation?.invoking) {
|
|
42
|
+
config["toolInvocation/invoking"] = toolInvocation.invoking;
|
|
43
|
+
}
|
|
44
|
+
if (toolInvocation?.invoked) {
|
|
45
|
+
config["toolInvocation/invoked"] = toolInvocation.invoked;
|
|
46
|
+
}
|
|
47
|
+
return config;
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"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","sourcesContent":["import { z } from \"zod\";\n\nexport const AppTarget = z.literal([\"mcp\", \"openai\"]);\n\nconst Mode = z\n .literal([\"development\", \"production\"])\n .or(z.custom<string & {}>((value) => typeof value === \"string\"));\n\nconst labelsInput = z.exactOptional(\n z.strictObject({\n toolInvocation: z.exactOptional(\n z.strictObject({\n invoking: z.string().exactOptional(),\n invoked: z.string().exactOptional(),\n })\n ),\n })\n);\n\nconst labelsOutput = z.exactOptional(\n z.strictObject({\n \"toolInvocation/invoking\": z.string().exactOptional(),\n \"toolInvocation/invoked\": z.string().exactOptional(),\n })\n);\n\nexport const ApolloClientAiAppsConfigSchema = z.strictObject({\n name: z.string().exactOptional(),\n description: z.string().exactOptional(),\n version: z.string().exactOptional(),\n entry: z.exactOptional(\n z.partialRecord(\n Mode,\n z.union([z.string(), z.partialRecord(AppTarget, z.string())])\n )\n ),\n csp: z.exactOptional(\n z.strictObject({\n connectDomains: z.array(z.string()).exactOptional(),\n frameDomains: z.array(z.string()).exactOptional(),\n redirectDomains: z.array(z.string()).exactOptional(),\n resourceDomains: z.array(z.string()).exactOptional(),\n })\n ),\n widgetSettings: z.exactOptional(\n z.strictObject({\n prefersBorder: z.boolean().exactOptional(),\n description: z.string().exactOptional(),\n domain: z.string().exactOptional(),\n })\n ),\n labels: z.codec(labelsInput, labelsOutput, {\n encode: () => {\n // encode is currently not used so we can skip the business logic and\n // return an empty object which satisfies the type. If we need to encode\n // labels back to the original form, this will need to be implemented\n return {};\n },\n decode: ({ toolInvocation }) => {\n const config: z.infer<typeof labelsOutput> = {};\n\n if (toolInvocation?.invoking) {\n config[\"toolInvocation/invoking\"] = toolInvocation.invoking;\n }\n\n if (toolInvocation?.invoked) {\n config[\"toolInvocation/invoked\"] = toolInvocation.invoked;\n }\n\n return config;\n },\n }),\n});\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ApolloClientAiAppsConfigSchema, AppTarget } from "./schema.js";
|
|
3
|
+
export declare namespace ApolloClientAiAppsConfig {
|
|
4
|
+
type AppTarget = z.infer<typeof AppTarget>;
|
|
5
|
+
type Config = z.infer<typeof ApolloClientAiAppsConfigSchema>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,8BAA8B,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,CAAC,OAAO,WAAW,wBAAwB,CAAC;IAChD,KAAY,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;IAClD,KAAY,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;CACrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { ApolloClientAiAppsConfigSchema, AppTarget } from \"./schema.js\";\n\nexport declare namespace ApolloClientAiAppsConfig {\n export type AppTarget = z.infer<typeof AppTarget>;\n export type Config = z.infer<typeof ApolloClientAiAppsConfigSchema>;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
2
|
-
import "../types/openai.js";
|
|
3
2
|
import type { ApplicationManifest } from "../types/application-manifest.js";
|
|
3
|
+
import { aiClientSymbol } from "../utilities/constants.js";
|
|
4
4
|
export declare namespace ApolloClient {
|
|
5
5
|
interface Options extends Omit<BaseApolloClient.Options, "link"> {
|
|
6
6
|
link?: BaseApolloClient.Options["link"];
|
|
@@ -8,8 +8,9 @@ export declare namespace ApolloClient {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare class ApolloClient extends BaseApolloClient {
|
|
11
|
-
|
|
11
|
+
/** @internal */
|
|
12
|
+
readonly [aiClientSymbol] = true;
|
|
12
13
|
constructor(options: ApolloClient.Options);
|
|
13
|
-
|
|
14
|
+
waitForInitialization(): Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=ApolloClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAQnC,qBAAqB;CAC5B"}
|
|
@@ -1,65 +1,12 @@
|
|
|
1
1
|
import { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
2
|
-
import {
|
|
3
|
-
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
4
|
-
import { parse } from "graphql";
|
|
5
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
6
|
-
import "../types/openai.js";
|
|
7
|
-
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
2
|
+
import { aiClientSymbol } from "../utilities/constants.js";
|
|
8
3
|
export class ApolloClient extends BaseApolloClient {
|
|
9
|
-
|
|
4
|
+
/** @internal */
|
|
5
|
+
[aiClientSymbol] = true;
|
|
10
6
|
constructor(options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
validateTerminatingLink(link);
|
|
14
|
-
}
|
|
15
|
-
super({
|
|
16
|
-
...options,
|
|
17
|
-
link,
|
|
18
|
-
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
19
|
-
documentTransform: new DocumentTransform((document) => {
|
|
20
|
-
return removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
|
|
21
|
-
}),
|
|
22
|
-
});
|
|
23
|
-
this.manifest = options.manifest;
|
|
24
|
-
}
|
|
25
|
-
async prefetchData() {
|
|
26
|
-
const toolOutput = window.openai.toolOutput;
|
|
27
|
-
// Write prefetched data to the cache
|
|
28
|
-
this.manifest.operations.forEach((operation) => {
|
|
29
|
-
if (operation.prefetch &&
|
|
30
|
-
operation.prefetchID &&
|
|
31
|
-
toolOutput?.prefetch?.[operation.prefetchID]) {
|
|
32
|
-
this.writeQuery({
|
|
33
|
-
query: parse(operation.body),
|
|
34
|
-
data: toolOutput.prefetch[operation.prefetchID].data,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// If this operation has the tool that matches up with the tool that was executed, write the tool result to the cache
|
|
38
|
-
if (operation.tools?.find((tool) => `${this.manifest.name}--${tool.name}` ===
|
|
39
|
-
window.openai.toolResponseMetadata?.toolName)) {
|
|
40
|
-
// We need to include the variables that were used as part of the tool call so that we get a proper cache entry
|
|
41
|
-
// However, we only want to include toolInput's that were graphql operation (ignore extraInputs)
|
|
42
|
-
const variables = Object.keys(window.openai.toolInput).reduce((obj, key) => operation.variables?.[key] ?
|
|
43
|
-
{ ...obj, [key]: window.openai.toolInput[key] }
|
|
44
|
-
: obj, {});
|
|
45
|
-
if (window.openai.toolOutput) {
|
|
46
|
-
this.writeQuery({
|
|
47
|
-
query: parse(operation.body),
|
|
48
|
-
data: window.openai.toolOutput.result.data,
|
|
49
|
-
variables,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function validateTerminatingLink(link) {
|
|
57
|
-
let terminatingLink = link;
|
|
58
|
-
while (terminatingLink.right) {
|
|
59
|
-
terminatingLink = terminatingLink.right;
|
|
60
|
-
}
|
|
61
|
-
if (terminatingLink.constructor.name !== "ToolCallLink") {
|
|
62
|
-
throw new Error("The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.");
|
|
7
|
+
super(options);
|
|
8
|
+
throw new Error("Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.");
|
|
63
9
|
}
|
|
10
|
+
async waitForInitialization() { }
|
|
64
11
|
}
|
|
65
12
|
//# sourceMappingURL=ApolloClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAS3D,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAc,CAAC,CAAC;QAEtB,MAAM,IAAI,KAAK,CACb,qLAAqL,CACtL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,qBAAqB,KAAI,CAAC;CACjC","sourcesContent":["import { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { aiClientSymbol } from \"../utilities/constants.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n super(options as any);\n\n throw new Error(\n \"Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n\n async waitForInitialization() {}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const Platform: Readonly<{
|
|
2
|
+
readonly target: "mcp" | "openai";
|
|
3
|
+
select<T = unknown, TReturn = T extends (...args: any[]) => infer TReturn_1 ? TReturn_1 : T>(config: {
|
|
4
|
+
mcp?: T;
|
|
5
|
+
openai?: T;
|
|
6
|
+
}): TReturn | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/core/Platform.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ;qBAcc,KAAK,GAAG,QAAQ;WAG/C,CAAC,YACD,OAAO,uBAAuB,GAAG,EAAE,KAAK,MAAM,SAAO,0BAC7C;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,GAAG,SAAS;EAGvD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
2
|
+
let warned = false;
|
|
3
|
+
export const Platform = Object.freeze({
|
|
4
|
+
get target() {
|
|
5
|
+
if (__DEV__) {
|
|
6
|
+
if (!warned) {
|
|
7
|
+
console.error("Could not determine the platform target because module conditions are not properly configured for either the `mcp` or `openai` environment. Please ensure you are using the `apolloClientAiApps` vite plugin.");
|
|
8
|
+
warned = true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
// Even though this return the "unknown" string, this value should never
|
|
12
|
+
// actually be seen at runtime unless something is misconfigured, hence the
|
|
13
|
+
// type cast to the other values.
|
|
14
|
+
return "unknown";
|
|
15
|
+
},
|
|
16
|
+
select(config) {
|
|
17
|
+
return;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=Platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../src/core/Platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,IAAI,MAAM;QACR,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,CACX,+MAA+M,CAChN,CAAC;gBACF,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;QACH,CAAC;QAED,wEAAwE;QACxE,2EAA2E;QAC3E,iCAAiC;QACjC,OAAO,SAAwC,CAAC;IAClD,CAAC;IACD,MAAM,CAGJ,MAA+B;QAC/B,OAAO;IACT,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { __DEV__ } from \"@apollo/client/utilities/environment\";\n\nlet warned = false;\n\nexport const Platform = Object.freeze({\n get target() {\n if (__DEV__) {\n if (!warned) {\n console.error(\n \"Could not determine the platform target because module conditions are not properly configured for either the `mcp` or `openai` environment. Please ensure you are using the `apolloClientAiApps` vite plugin.\"\n );\n warned = true;\n }\n }\n\n // Even though this return the \"unknown\" string, this value should never\n // actually be seen at runtime unless something is misconfigured, hence the\n // type cast to the other values.\n return \"unknown\" as unknown as \"mcp\" | \"openai\";\n },\n select<\n T = unknown,\n TReturn = T extends (...args: any[]) => infer TReturn ? TReturn : T,\n >(config: { mcp?: T; openai?: T }): TReturn | undefined {\n return;\n },\n});\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CallToolResult as McpCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { FormattedExecutionResult } from "graphql";
|
|
3
|
+
export declare namespace ApolloMcpServerApps {
|
|
4
|
+
interface StructuredContent {
|
|
5
|
+
result: FormattedExecutionResult;
|
|
6
|
+
prefetch?: Record<string, FormattedExecutionResult>;
|
|
7
|
+
[x: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface CallToolResult extends McpCallToolResult {
|
|
10
|
+
structuredContent: ApolloMcpServerApps.StructuredContent;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,iBAAiB;QAChC,MAAM,EAAE,wBAAwB,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface StructuredContent {\n result: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
export type { API, CallTool, DeviceType, DisplayMode, OpenAiGlobals, SafeArea, SafeAreaInsets, Theme, UserAgent, UnknownObject, } from "./types/openai.js";
|
|
2
|
-
export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
|
|
3
1
|
export type { ApplicationManifest, ManifestOperation, ManifestTool, ManifestExtraInput, ManifestCsp, ManifestLabels, ManifestWidgetSettings, } from "./types/application-manifest.js";
|
|
4
|
-
export { ToolUseProvider } from "./react/context/ToolUseContext.js";
|
|
5
|
-
export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
|
|
6
|
-
export { useToolName } from "./react/hooks/useToolName.js";
|
|
7
|
-
export { useToolInput } from "./react/hooks/useToolInput.js";
|
|
8
|
-
export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
|
|
9
|
-
export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
|
|
10
|
-
export { useToolEffect } from "./react/hooks/useToolEffect.js";
|
|
11
|
-
export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
|
|
12
|
-
export { useToolOutput } from "./react/hooks/useToolOutput.js";
|
|
13
|
-
export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
|
|
14
|
-
export { useWidgetState } from "./react/hooks/useWidgetState.js";
|
|
15
2
|
export { ApolloClient } from "./core/ApolloClient.js";
|
|
16
|
-
export { ApolloProvider } from "./react/ApolloProvider.js";
|
|
17
3
|
export { ToolCallLink } from "./link/ToolCallLink.js";
|
|
4
|
+
export { Platform } from "./core/Platform.js";
|
|
18
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
|
|
2
|
-
export { ToolUseProvider } from "./react/context/ToolUseContext.js";
|
|
3
|
-
export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
|
|
4
|
-
export { useToolName } from "./react/hooks/useToolName.js";
|
|
5
|
-
export { useToolInput } from "./react/hooks/useToolInput.js";
|
|
6
|
-
export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
|
|
7
|
-
export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
|
|
8
|
-
export { useToolEffect } from "./react/hooks/useToolEffect.js";
|
|
9
|
-
export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
|
|
10
|
-
export { useToolOutput } from "./react/hooks/useToolOutput.js";
|
|
11
|
-
export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
|
|
12
|
-
export { useWidgetState } from "./react/hooks/useWidgetState.js";
|
|
13
1
|
export { ApolloClient } from "./core/ApolloClient.js";
|
|
14
|
-
export { ApolloProvider } from "./react/ApolloProvider.js";
|
|
15
2
|
export { ToolCallLink } from "./link/ToolCallLink.js";
|
|
3
|
+
export { Platform } from "./core/Platform.js";
|
|
16
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n\nexport { Platform } from \"./core/Platform.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mcp.d.ts","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mcp.js","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./mcp/core/Platform.js\";\nexport { ApolloClient } from \"./mcp/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./mcp/link/ToolCallLink.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.openai.d.ts","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.openai.js","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./openai/core/Platform.js\";\nexport { ApolloClient } from \"./openai/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./openai/link/ToolCallLink.js\";\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ApolloLink
|
|
1
|
+
import { ApolloLink } from "@apollo/client";
|
|
2
2
|
/**
|
|
3
3
|
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
4
4
|
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
5
5
|
* validate that the terminating link is an instance of this link.
|
|
6
6
|
*
|
|
7
|
-
* @example
|
|
7
|
+
* @example Providing a custom link chain
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* import { ApolloLink } from "@apollo/client";
|
|
@@ -22,6 +22,6 @@ import { ApolloLink, Observable } from "@apollo/client";
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export declare class ToolCallLink extends ApolloLink {
|
|
25
|
-
|
|
25
|
+
constructor();
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=ToolCallLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;;CAQ3C"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { ApolloLink
|
|
2
|
-
import { from, map } from "rxjs";
|
|
3
|
-
import { fallbackHttpConfig, selectHttpOptionsAndBody, } from "@apollo/client/link/http";
|
|
1
|
+
import { ApolloLink } from "@apollo/client";
|
|
4
2
|
/**
|
|
5
3
|
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
6
4
|
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
7
5
|
* validate that the terminating link is an instance of this link.
|
|
8
6
|
*
|
|
9
|
-
* @example
|
|
7
|
+
* @example Providing a custom link chain
|
|
10
8
|
*
|
|
11
9
|
* ```ts
|
|
12
10
|
* import { ApolloLink } from "@apollo/client";
|
|
@@ -24,16 +22,9 @@ import { fallbackHttpConfig, selectHttpOptionsAndBody, } from "@apollo/client/li
|
|
|
24
22
|
* ```
|
|
25
23
|
*/
|
|
26
24
|
export class ToolCallLink extends ApolloLink {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
http: context.http,
|
|
31
|
-
options: context.fetchOptions,
|
|
32
|
-
credentials: context.credentials,
|
|
33
|
-
headers: context.headers,
|
|
34
|
-
};
|
|
35
|
-
const { query, variables } = selectHttpOptionsAndBody(operation, fallbackHttpConfig, contextConfig).body;
|
|
36
|
-
return from(window.openai.callTool("execute", { query, variables })).pipe(map((result) => ({ data: result.structuredContent.data })));
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
throw new Error("Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.");
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
//# sourceMappingURL=ToolCallLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C;QACE,KAAK,EAAE,CAAC;QAER,MAAM,IAAI,KAAK,CACb,mLAAmL,CACpL,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Providing a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n constructor() {\n super();\n\n throw new Error(\n \"Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
2
|
+
import type { ApplicationManifest } from "../../types/application-manifest.js";
|
|
3
|
+
import { aiClientSymbol } from "../../utilities/index.js";
|
|
4
|
+
export declare namespace ApolloClient {
|
|
5
|
+
interface Options extends Omit<BaseApolloClient.Options, "link"> {
|
|
6
|
+
link?: BaseApolloClient.Options["link"];
|
|
7
|
+
manifest: ApplicationManifest;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare class ApolloClient extends BaseApolloClient {
|
|
11
|
+
manifest: ApplicationManifest;
|
|
12
|
+
private readonly appManager;
|
|
13
|
+
/** @internal */
|
|
14
|
+
readonly [aiClientSymbol] = true;
|
|
15
|
+
constructor(options: ApolloClient.Options);
|
|
16
|
+
stop(): void;
|
|
17
|
+
waitForInitialization: (() => Promise<void>) & {
|
|
18
|
+
reset: () => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ApolloClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,IAAI,gBAAgB,EAEjC,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAGf,MAAM,0BAA0B,CAAC;AAGlC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAuBzC,IAAI;IAKJ,qBAAqB;;MAoBlB;CACJ"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ApolloLink, ApolloClient as BaseApolloClient, DocumentTransform, } from "@apollo/client";
|
|
2
|
+
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
3
|
+
import { parse } from "graphql";
|
|
4
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
+
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
6
|
+
import { aiClientSymbol, cacheAsync, getVariablesForOperationFromToolInput, } from "../../utilities/index.js";
|
|
7
|
+
import { McpAppManager } from "./McpAppManager.js";
|
|
8
|
+
export class ApolloClient extends BaseApolloClient {
|
|
9
|
+
manifest;
|
|
10
|
+
appManager;
|
|
11
|
+
/** @internal */
|
|
12
|
+
[aiClientSymbol] = true;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const link = options.link ?? new ToolCallLink();
|
|
15
|
+
if (__DEV__) {
|
|
16
|
+
validateTerminatingLink(link);
|
|
17
|
+
}
|
|
18
|
+
super({
|
|
19
|
+
...options,
|
|
20
|
+
link,
|
|
21
|
+
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
22
|
+
documentTransform: new DocumentTransform((document) => {
|
|
23
|
+
return removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
|
|
24
|
+
}).concat(options.documentTransform ?? DocumentTransform.identity()),
|
|
25
|
+
});
|
|
26
|
+
this.manifest = options.manifest;
|
|
27
|
+
this.appManager = new McpAppManager(this.manifest);
|
|
28
|
+
}
|
|
29
|
+
stop() {
|
|
30
|
+
super.stop();
|
|
31
|
+
this.appManager.close().catch(() => { });
|
|
32
|
+
}
|
|
33
|
+
waitForInitialization = cacheAsync(async () => {
|
|
34
|
+
const { prefetch, result, toolName, args } = await this.appManager.waitForInitialization();
|
|
35
|
+
this.manifest.operations.forEach((operation) => {
|
|
36
|
+
if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
|
|
37
|
+
this.writeQuery({
|
|
38
|
+
query: parse(operation.body),
|
|
39
|
+
data: prefetch[operation.prefetchID].data,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (operation.tools.find((tool) => tool.name === toolName)) {
|
|
43
|
+
this.writeQuery({
|
|
44
|
+
query: parse(operation.body),
|
|
45
|
+
data: result.data,
|
|
46
|
+
variables: getVariablesForOperationFromToolInput(operation, args),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function validateTerminatingLink(link) {
|
|
53
|
+
let terminatingLink = link;
|
|
54
|
+
while (terminatingLink.right) {
|
|
55
|
+
terminatingLink = terminatingLink.right;
|
|
56
|
+
}
|
|
57
|
+
if (!isNamedLink(terminatingLink) ||
|
|
58
|
+
terminatingLink.name !== "ToolCallLink") {
|
|
59
|
+
throw new Error("The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function isNamedLink(link) {
|
|
63
|
+
return "name" in link;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=ApolloClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n ApolloLink,\n ApolloClient as BaseApolloClient,\n DocumentTransform,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse } from \"graphql\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type { ApplicationManifest } from \"../../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n aiClientSymbol,\n cacheAsync,\n getVariablesForOperationFromToolInput,\n} from \"../../utilities/index.js\";\nimport { McpAppManager } from \"./McpAppManager.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link,\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest);\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n waitForInitialization = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.waitForInitialization();\n\n this.manifest.operations.forEach((operation) => {\n if (operation.prefetchID && prefetch?.[operation.prefetchID]) {\n this.writeQuery({\n query: parse(operation.body),\n data: prefetch[operation.prefetchID].data,\n });\n }\n\n if (operation.tools.find((tool) => tool.name === toolName)) {\n this.writeQuery({\n query: parse(operation.body),\n data: result.data,\n variables: getVariablesForOperationFromToolInput(operation, args),\n });\n }\n });\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { ApplicationManifest } from "../../types/application-manifest";
|
|
3
|
+
import type { FormattedExecutionResult } from "graphql";
|
|
4
|
+
import type { DocumentNode, OperationVariables } from "@apollo/client";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare class McpAppManager {
|
|
7
|
+
#private;
|
|
8
|
+
readonly app: App;
|
|
9
|
+
constructor(manifest: ApplicationManifest);
|
|
10
|
+
get toolName(): string | undefined;
|
|
11
|
+
get toolMetadata(): {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
progressToken?: string | number | undefined;
|
|
14
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
15
|
+
taskId: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
get toolInput(): Record<string, unknown> | undefined;
|
|
19
|
+
waitForInitialization: (() => Promise<{
|
|
20
|
+
toolName: string | undefined;
|
|
21
|
+
args: Record<string, unknown> | undefined;
|
|
22
|
+
result: FormattedExecutionResult;
|
|
23
|
+
prefetch?: Record<string, FormattedExecutionResult>;
|
|
24
|
+
}>) & {
|
|
25
|
+
reset: () => void;
|
|
26
|
+
};
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
executeQuery({ query, variables, }: {
|
|
29
|
+
query: DocumentNode;
|
|
30
|
+
variables: OperationVariables | undefined;
|
|
31
|
+
}): Promise<FormattedExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
|
|
32
|
+
private connect;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=McpAppManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,gCAAgC,CAAC;AAE3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASvE,gBAAgB;AAChB,qBAAa,aAAa;;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;gBAMN,QAAQ,EAAE,mBAAmB;IAIzC,IAAI,QAAQ,uBAEX;IAED,IAAI,YAAY;;;;;;kBAEf;IAED,IAAI,SAAS,wCAEZ;IAED,qBAAqB;;;;;;;MA4BlB;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;YASa,OAAO;CAWtB"}
|