@apollo/client-ai-apps 0.6.4 → 0.7.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/CHANGELOG.md +100 -0
- package/CONTRIBUTING.md +195 -0
- package/README.md +74 -0
- package/dist/core/AbstractApolloClient.d.ts +33 -0
- package/dist/core/AbstractApolloClient.d.ts.map +1 -0
- package/dist/core/AbstractApolloClient.js +129 -0
- package/dist/core/AbstractApolloClient.js.map +1 -0
- package/dist/core/ApolloClient.d.ts +3 -7
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +5 -4
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/core/McpAppManager.d.ts +42 -0
- package/dist/core/McpAppManager.d.ts.map +1 -0
- package/dist/core/McpAppManager.js +56 -0
- package/dist/core/McpAppManager.js.map +1 -0
- package/dist/core/typeRegistration.d.ts +0 -14
- package/dist/core/typeRegistration.d.ts.map +1 -1
- package/dist/core/typeRegistration.js.map +1 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mcp.d.ts +0 -1
- package/dist/index.mcp.d.ts.map +1 -1
- package/dist/index.mcp.js +0 -1
- package/dist/index.mcp.js.map +1 -1
- package/dist/index.openai.d.ts +0 -1
- package/dist/index.openai.d.ts.map +1 -1
- package/dist/index.openai.js +0 -1
- package/dist/index.openai.js.map +1 -1
- package/dist/link/ToolCallLink.d.ts +6 -1
- package/dist/link/ToolCallLink.d.ts.map +1 -1
- package/dist/link/ToolCallLink.js +17 -4
- package/dist/link/ToolCallLink.js.map +1 -1
- package/dist/link/ToolHydrationLink.d.ts +21 -0
- package/dist/link/ToolHydrationLink.d.ts.map +1 -0
- package/dist/link/ToolHydrationLink.js +57 -0
- package/dist/link/ToolHydrationLink.js.map +1 -0
- package/dist/mcp/core/ApolloClient.d.ts +3 -20
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
- package/dist/mcp/core/ApolloClient.js +20 -98
- package/dist/mcp/core/ApolloClient.js.map +1 -1
- package/dist/mcp/index.d.ts +0 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +0 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/openai/core/ApolloClient.d.ts +3 -20
- package/dist/openai/core/ApolloClient.d.ts.map +1 -1
- package/dist/openai/core/ApolloClient.js +36 -98
- package/dist/openai/core/ApolloClient.js.map +1 -1
- package/dist/openai/index.d.ts +0 -1
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/openai/index.js +0 -1
- package/dist/openai/index.js.map +1 -1
- package/dist/openai/react/index.d.ts +0 -7
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +0 -7
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/ApolloProvider.d.ts.map +1 -1
- package/dist/react/ApolloProvider.js +1 -1
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.d.ts +1 -1
- package/dist/react/createHydrationUtils.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.js +7 -9
- package/dist/react/createHydrationUtils.js.map +1 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts +3 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react/hooks/internal}/useApolloClient.js +3 -3
- package/dist/react/hooks/internal/useApolloClient.js.map +1 -0
- package/dist/react/hooks/useApp.d.ts.map +1 -0
- package/dist/react/hooks/useApp.js +5 -0
- package/dist/react/hooks/useApp.js.map +1 -0
- package/dist/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/{openai/react → react}/hooks/useHostContext.js +1 -1
- package/dist/react/hooks/useHostContext.js.map +1 -0
- package/dist/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/react/hooks/useToolInfo.js +5 -0
- package/dist/react/hooks/useToolInfo.js.map +1 -0
- package/dist/react/hooks/useToolMetadata.d.ts +2 -0
- package/dist/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/react/hooks/useToolMetadata.js +5 -0
- package/dist/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/react/index.d.ts +5 -16
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -19
- package/dist/react/index.js.map +1 -1
- package/dist/types/application-manifest.d.ts +1 -0
- package/dist/types/application-manifest.d.ts.map +1 -1
- package/dist/types/application-manifest.js.map +1 -1
- package/dist/utilities/connectToHost.d.ts +3 -0
- package/dist/utilities/connectToHost.d.ts.map +1 -0
- package/dist/utilities/connectToHost.js +11 -0
- package/dist/utilities/connectToHost.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +2 -0
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/package.json +5 -22
- package/src/core/AbstractApolloClient.ts +217 -0
- package/src/core/ApolloClient.ts +8 -10
- package/src/core/McpAppManager.ts +106 -0
- package/src/core/typeRegistration.ts +0 -15
- package/src/core/types.ts +2 -1
- package/src/index.mcp.ts +0 -1
- package/src/index.openai.ts +0 -1
- package/src/index.ts +1 -6
- package/src/link/ToolCallLink.ts +27 -5
- package/src/link/ToolHydrationLink.ts +90 -0
- package/src/link/__tests__/ToolCallLink.test.ts +99 -0
- package/src/mcp/core/ApolloClient.ts +32 -165
- package/src/mcp/core/__tests__/ApolloClient.test.ts +571 -71
- package/src/mcp/index.ts +0 -1
- package/src/openai/core/ApolloClient.ts +48 -161
- package/src/openai/core/__tests__/ApolloClient.test.ts +916 -118
- package/src/openai/index.ts +0 -1
- package/src/openai/react/index.ts +0 -7
- package/src/react/ApolloProvider.tsx +1 -6
- package/src/react/__tests__/ApolloProvider/mcp.test.tsx +66 -29
- package/src/react/__tests__/ApolloProvider/openai.test.tsx +16 -41
- package/src/react/__tests__/createHydrationUtils.test.tsx +1260 -0
- package/src/{mcp/react/hooks → react}/createHydrationUtils.ts +7 -10
- package/src/react/hooks/__tests__/useApp.test.tsx +46 -0
- package/src/react/hooks/__tests__/useHostContext.test.tsx +99 -0
- package/src/react/hooks/__tests__/useToolInfo.test.tsx +98 -0
- package/src/react/hooks/__tests__/useToolMetadata.test.tsx +58 -0
- package/src/{mcp/react/hooks → react/hooks/internal}/useApolloClient.ts +3 -3
- package/src/{mcp/react → react}/hooks/useApp.ts +1 -1
- package/src/{openai/react → react}/hooks/useHostContext.ts +1 -1
- package/src/react/hooks/useToolInfo.ts +6 -0
- package/src/react/hooks/useToolMetadata.ts +5 -0
- package/src/react/index.ts +5 -36
- package/src/testing/internal/graphql/parseManifestOperation.ts +87 -0
- package/src/testing/internal/index.ts +3 -0
- package/src/testing/internal/matchers/index.ts +1 -0
- package/src/testing/internal/matchers/toEmitAnything.ts +43 -0
- package/src/testing/internal/matchers/types.ts +1 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +25 -4
- package/src/testing/internal/tests/eachHostEnv.ts +22 -0
- package/src/testing/internal/utilities/createHostEnv.ts +117 -0
- package/src/types/application-manifest.ts +1 -0
- package/src/utilities/connectToHost.ts +13 -0
- package/src/utilities/index.ts +1 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +56 -0
- package/src/vite/apolloClientAiApps.ts +5 -0
- package/tsconfig.vite.json +1 -1
- package/vitest.config.ts +13 -0
- package/dist/mcp/core/McpAppManager.d.ts +0 -30
- package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
- package/dist/mcp/core/McpAppManager.js +0 -82
- package/dist/mcp/core/McpAppManager.js.map +0 -1
- package/dist/mcp/link/ToolCallLink.d.ts +0 -28
- package/dist/mcp/link/ToolCallLink.d.ts.map +0 -1
- package/dist/mcp/link/ToolCallLink.js +0 -35
- package/dist/mcp/link/ToolCallLink.js.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.d.ts +0 -3
- package/dist/mcp/react/hooks/useApolloClient.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.js.map +0 -1
- package/dist/mcp/react/hooks/useApp.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApp.js +0 -5
- package/dist/mcp/react/hooks/useApp.js.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.js +0 -7
- package/dist/mcp/react/hooks/useHostContext.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/mcp/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.js +0 -10
- package/dist/mcp/react/hooks/useToolInfo.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.js +0 -9
- package/dist/mcp/react/hooks/useToolInput.js.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.js +0 -5
- package/dist/mcp/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/mcp/react/hooks/useToolName.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolName.js +0 -9
- package/dist/mcp/react/hooks/useToolName.js.map +0 -1
- package/dist/mcp/react/index.d.ts +0 -8
- package/dist/mcp/react/index.d.ts.map +0 -1
- package/dist/mcp/react/index.js +0 -8
- package/dist/mcp/react/index.js.map +0 -1
- package/dist/openai/core/McpAppManager.d.ts +0 -29
- package/dist/openai/core/McpAppManager.d.ts.map +0 -1
- package/dist/openai/core/McpAppManager.js +0 -91
- package/dist/openai/core/McpAppManager.js.map +0 -1
- package/dist/openai/link/ToolCallLink.d.ts +0 -28
- package/dist/openai/link/ToolCallLink.d.ts.map +0 -1
- package/dist/openai/link/ToolCallLink.js +0 -35
- package/dist/openai/link/ToolCallLink.js.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.d.ts +0 -15
- package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.js +0 -113
- package/dist/openai/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/openai/react/hooks/useApp.d.ts +0 -2
- package/dist/openai/react/hooks/useApp.d.ts.map +0 -1
- package/dist/openai/react/hooks/useApp.js +0 -5
- package/dist/openai/react/hooks/useApp.js.map +0 -1
- package/dist/openai/react/hooks/useHostContext.d.ts +0 -2
- package/dist/openai/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/openai/react/hooks/useHostContext.js.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/openai/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.js +0 -10
- package/dist/openai/react/hooks/useToolInfo.js.map +0 -1
- package/dist/openai/react/hooks/useToolInput.d.ts +0 -7
- package/dist/openai/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInput.js +0 -9
- package/dist/openai/react/hooks/useToolInput.js.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/openai/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.js +0 -5
- package/dist/openai/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/openai/react/hooks/useToolName.d.ts +0 -7
- package/dist/openai/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolName.js +0 -9
- package/dist/openai/react/hooks/useToolName.js.map +0 -1
- package/dist/react/index.mcp.d.ts +0 -3
- package/dist/react/index.mcp.d.ts.map +0 -1
- package/dist/react/index.mcp.js +0 -3
- package/dist/react/index.mcp.js.map +0 -1
- package/dist/react/index.openai.d.ts +0 -3
- package/dist/react/index.openai.d.ts.map +0 -1
- package/dist/react/index.openai.js +0 -3
- package/dist/react/index.openai.js.map +0 -1
- package/dist/react/missingHook.d.ts +0 -2
- package/dist/react/missingHook.d.ts.map +0 -1
- package/dist/react/missingHook.js +0 -6
- package/dist/react/missingHook.js.map +0 -1
- package/src/mcp/core/McpAppManager.ts +0 -129
- package/src/mcp/link/ToolCallLink.ts +0 -40
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -62
- package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1228
- package/src/mcp/react/hooks/__tests__/useApp.test.tsx +0 -46
- package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +0 -95
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +0 -50
- package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/mcp/react/hooks/useHostContext.ts +0 -14
- package/src/mcp/react/hooks/useToolInfo.ts +0 -13
- package/src/mcp/react/hooks/useToolInput.ts +0 -10
- package/src/mcp/react/hooks/useToolMetadata.ts +0 -5
- package/src/mcp/react/hooks/useToolName.ts +0 -10
- package/src/mcp/react/index.ts +0 -7
- package/src/openai/core/McpAppManager.ts +0 -139
- package/src/openai/link/ToolCallLink.ts +0 -40
- package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1333
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +0 -92
- package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +0 -85
- package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +0 -86
- package/src/openai/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/openai/react/hooks/createHydrationUtils.ts +0 -182
- package/src/openai/react/hooks/useApp.ts +0 -5
- package/src/openai/react/hooks/useToolInfo.ts +0 -13
- package/src/openai/react/hooks/useToolInput.ts +0 -10
- package/src/openai/react/hooks/useToolMetadata.ts +0 -5
- package/src/openai/react/hooks/useToolName.ts +0 -10
- package/src/react/index.mcp.ts +0 -10
- package/src/react/index.openai.ts +0 -10
- package/src/react/missingHook.ts +0 -9
- /package/dist/{mcp/react → react}/hooks/useApp.d.ts +0 -0
- /package/dist/{mcp/react → react}/hooks/useHostContext.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAO/E,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IACpD,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,UAAU,GACd,oBAAoB,EAAsC,CAAC;YAC7D,MAAM,SAAS,GACb,oBAAoB,EAAqC,CAAC;YAE5D,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC5B,UAAU,CAAC,OAAO,CAChB,MAAuD,CACxD,CAAC;YACJ,CAAC,CAAC;YAEF,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC3B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC,CAAC;YAEF,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YAEzB,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9D,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC;YAEpD,OAAO;gBACL,iBAAiB;gBACjB,SAAS,EAAE,IAAI;gBACf,KAAK;aACN,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { App } from \"@modelcontextprotocol/ext-apps\";\nimport { AbstractApolloClient } from \"../../core/AbstractApolloClient.js\";\nimport { connectToHost, promiseWithResolvers } from \"../../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"../../core/types.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends AbstractApolloClient.Options {}\n}\n\nexport class ApolloClient extends AbstractApolloClient {\n constructor(options: ApolloClient.Options) {\n super(options, async (app) => {\n const toolResult =\n promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n const toolInput =\n promiseWithResolvers<Parameters<App[\"ontoolinput\"]>[0]>();\n\n app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n app.ontoolinput = (params) => {\n toolInput.resolve(params);\n };\n\n await connectToHost(app);\n\n const { structuredContent, _meta } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n return {\n structuredContent,\n toolInput: args,\n _meta,\n };\n });\n }\n}\n"]}
|
package/dist/mcp/index.d.ts
CHANGED
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/mcp/index.js
CHANGED
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\n"]}
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { WatchQueryOptions, ObservableQuery, OperationVariables } from "@apollo/client";
|
|
3
|
-
import type { ApplicationManifest } from "../../types/application-manifest.js";
|
|
4
|
-
import { aiClientSymbol } from "../../utilities/index.js";
|
|
1
|
+
import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
|
|
5
2
|
export declare namespace ApolloClient {
|
|
6
|
-
interface Options extends
|
|
7
|
-
link?: BaseApolloClient.Options["link"];
|
|
8
|
-
manifest: ApplicationManifest;
|
|
3
|
+
interface Options extends AbstractApolloClient.Options {
|
|
9
4
|
}
|
|
10
5
|
}
|
|
11
|
-
export declare class ApolloClient extends
|
|
12
|
-
#private;
|
|
13
|
-
manifest: ApplicationManifest;
|
|
14
|
-
private readonly appManager;
|
|
15
|
-
/** @internal */
|
|
16
|
-
readonly [aiClientSymbol] = true;
|
|
6
|
+
export declare class ApolloClient extends AbstractApolloClient {
|
|
17
7
|
constructor(options: ApolloClient.Options);
|
|
18
|
-
stop(): void;
|
|
19
|
-
get toolInput(): Record<string, unknown> | undefined;
|
|
20
|
-
clearToolInput(): void;
|
|
21
|
-
watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
|
|
22
|
-
connect: (() => Promise<void>) & {
|
|
23
|
-
reset: () => void;
|
|
24
|
-
};
|
|
25
8
|
}
|
|
26
9
|
//# sourceMappingURL=ApolloClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAI1E,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,oBAAoB,CAAC,OAAO;KAAG;CACjE;AAED,qBAAa,YAAa,SAAQ,oBAAoB;gBACxC,OAAO,EAAE,YAAY,CAAC,OAAO;CAiD1C"}
|
|
@@ -1,105 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { parse, visit } from "graphql";
|
|
5
|
-
import { equal } from "@wry/equality";
|
|
6
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
7
|
-
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
8
|
-
import { aiClientSymbol, cacheAsync, getToolNamesFromDocument, getVariablesForOperationFromToolInput, warnOnVariableMismatch, } from "../../utilities/index.js";
|
|
9
|
-
import { McpAppManager } from "./McpAppManager.js";
|
|
10
|
-
import { getVariableNamesFromDocument } from "../../utilities/getVariableNamesFromDocument.js";
|
|
11
|
-
export class ApolloClient extends BaseApolloClient {
|
|
12
|
-
manifest;
|
|
13
|
-
appManager;
|
|
14
|
-
/** @internal */
|
|
15
|
-
[aiClientSymbol] = true;
|
|
16
|
-
#toolInput;
|
|
1
|
+
import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
|
|
2
|
+
import { connectToHost, promiseWithResolvers } from "../../utilities/index.js";
|
|
3
|
+
export class ApolloClient extends AbstractApolloClient {
|
|
17
4
|
constructor(options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
}).concat(options.documentTransform ?? DocumentTransform.identity()),
|
|
34
|
-
});
|
|
35
|
-
this.manifest = options.manifest;
|
|
36
|
-
this.appManager = new McpAppManager(this.manifest);
|
|
37
|
-
}
|
|
38
|
-
stop() {
|
|
39
|
-
super.stop();
|
|
40
|
-
this.appManager.close().catch(() => { });
|
|
41
|
-
}
|
|
42
|
-
get toolInput() {
|
|
43
|
-
return this.#toolInput;
|
|
44
|
-
}
|
|
45
|
-
clearToolInput() {
|
|
46
|
-
this.#toolInput = undefined;
|
|
47
|
-
}
|
|
48
|
-
watchQuery(options) {
|
|
49
|
-
if (__DEV__) {
|
|
50
|
-
const toolInput = this.#toolInput;
|
|
51
|
-
if (toolInput) {
|
|
52
|
-
const toolName = this.appManager.toolName;
|
|
53
|
-
const hasMatchingTool = !!toolName && getToolNamesFromDocument(options.query).has(toolName);
|
|
54
|
-
if (hasMatchingTool) {
|
|
55
|
-
// Clear after first matching comparison so this only fires once and
|
|
56
|
-
// remounting doesn't produce spurious warnings.
|
|
57
|
-
this.#toolInput = undefined;
|
|
58
|
-
const variableNames = getVariableNamesFromDocument(options.query);
|
|
59
|
-
if (variableNames.size > 0) {
|
|
60
|
-
const { variables } = options;
|
|
61
|
-
const toolInputVariables = Object.entries(toolInput).filter(([key]) => variableNames.has(key));
|
|
62
|
-
const hasToolInputMismatch = toolInputVariables.some(([key, value]) => !equal(value, variables?.[key]));
|
|
63
|
-
if (hasToolInputMismatch) {
|
|
64
|
-
warnOnVariableMismatch(options.query, Object.fromEntries(toolInputVariables), variables);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return super.watchQuery(options);
|
|
71
|
-
}
|
|
72
|
-
connect = cacheAsync(async () => {
|
|
73
|
-
const { prefetch, result, toolName, args } = await this.appManager.connect();
|
|
74
|
-
this.#toolInput = args;
|
|
75
|
-
this.manifest.operations.forEach((operation) => {
|
|
76
|
-
if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
|
|
77
|
-
this.writeQuery({
|
|
78
|
-
query: parse(operation.body),
|
|
79
|
-
data: prefetch[operation.prefetchID].data,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (operation.tools.find((tool) => tool.name === toolName)) {
|
|
83
|
-
this.writeQuery({
|
|
84
|
-
query: parse(operation.body),
|
|
85
|
-
data: result.data,
|
|
86
|
-
variables: getVariablesForOperationFromToolInput(operation, args),
|
|
5
|
+
super(options, async (app) => {
|
|
6
|
+
const toolResult = promiseWithResolvers();
|
|
7
|
+
app.ontoolresult = (params) => {
|
|
8
|
+
toolResult.resolve(params);
|
|
9
|
+
};
|
|
10
|
+
await connectToHost(app);
|
|
11
|
+
// After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.
|
|
12
|
+
// Instead, the tool result is available immediately via `window.openai.toolOutput`.
|
|
13
|
+
// If it's already set, resolve the promise now rather than waiting for the
|
|
14
|
+
// notification that will never arrive.
|
|
15
|
+
if (window.openai.toolOutput !== null) {
|
|
16
|
+
toolResult.resolve({
|
|
17
|
+
structuredContent: window.openai.toolOutput,
|
|
18
|
+
content: [],
|
|
87
19
|
});
|
|
88
20
|
}
|
|
21
|
+
const { structuredContent } = await toolResult.promise;
|
|
22
|
+
return {
|
|
23
|
+
structuredContent,
|
|
24
|
+
// OpenAI is not consistent about sending `ui/notifications/tool-input`.
|
|
25
|
+
// Sometimes it doesn't send at all, other times it sends more than once
|
|
26
|
+
// before we get the tool result (which should always happen and at most
|
|
27
|
+
// once according to the spec). Rather than relying on the
|
|
28
|
+
// `ui/notifications/tool-input` notification to set the tool input value,
|
|
29
|
+
// we read from `window.openai.toolInput so that we have the most recent
|
|
30
|
+
// set value.
|
|
31
|
+
//
|
|
32
|
+
// When OpenAI fixes this issue and sends `ui/notifications/tool-input`
|
|
33
|
+
// consistently according to the MCP Apps specification, this can be
|
|
34
|
+
// reverted to use the `app.ontoolinput` callback.
|
|
35
|
+
toolInput: window.openai.toolInput,
|
|
36
|
+
// OpenAI doesn't provide access to `_meta` from ui/notifications/tool-result,
|
|
37
|
+
// so we need to use window.openai.toolResponseMetadata directly
|
|
38
|
+
_meta: window.openai.toolResponseMetadata,
|
|
39
|
+
};
|
|
89
40
|
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function validateTerminatingLink(link) {
|
|
93
|
-
let terminatingLink = link;
|
|
94
|
-
while (terminatingLink.right) {
|
|
95
|
-
terminatingLink = terminatingLink.right;
|
|
96
|
-
}
|
|
97
|
-
if (!isNamedLink(terminatingLink) ||
|
|
98
|
-
terminatingLink.name !== "ToolCallLink") {
|
|
99
|
-
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.");
|
|
100
41
|
}
|
|
101
42
|
}
|
|
102
|
-
function isNamedLink(link) {
|
|
103
|
-
return "name" in link;
|
|
104
|
-
}
|
|
105
43
|
//# sourceMappingURL=ApolloClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAO/E,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IACpD,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,UAAU,GACd,oBAAoB,EAAsC,CAAC;YAE7D,GAAG,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC5B,UAAU,CAAC,OAAO,CAChB,MAAuD,CACxD,CAAC;YACJ,CAAC,CAAC;YAEF,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YAEzB,gFAAgF;YAChF,oFAAoF;YACpF,2EAA2E;YAC3E,uCAAuC;YACvC,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBACtC,UAAU,CAAC,OAAO,CAAC;oBACjB,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;oBAC3C,OAAO,EAAE,EAAE;iBACZ,CAAC,CAAC;YACL,CAAC;YAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAEvD,OAAO;gBACL,iBAAiB;gBACjB,wEAAwE;gBACxE,wEAAwE;gBACxE,wEAAwE;gBACxE,0DAA0D;gBAC1D,0EAA0E;gBAC1E,wEAAwE;gBACxE,aAAa;gBACb,EAAE;gBACF,uEAAuE;gBACvE,oEAAoE;gBACpE,kDAAkD;gBAClD,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS;gBAElC,8EAA8E;gBAC9E,gEAAgE;gBAChE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,oBAER;aACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { AbstractApolloClient } from \"../../core/AbstractApolloClient.js\";\nimport { connectToHost, promiseWithResolvers } from \"../../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"../../core/types.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends AbstractApolloClient.Options {}\n}\n\nexport class ApolloClient extends AbstractApolloClient {\n constructor(options: ApolloClient.Options) {\n super(options, async (app) => {\n const toolResult =\n promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n\n app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n await connectToHost(app);\n\n // After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.\n // Instead, the tool result is available immediately via `window.openai.toolOutput`.\n // If it's already set, resolve the promise now rather than waiting for the\n // notification that will never arrive.\n if (window.openai.toolOutput !== null) {\n toolResult.resolve({\n structuredContent: window.openai.toolOutput,\n content: [],\n });\n }\n\n const { structuredContent } = await toolResult.promise;\n\n return {\n structuredContent,\n // OpenAI is not consistent about sending `ui/notifications/tool-input`.\n // Sometimes it doesn't send at all, other times it sends more than once\n // before we get the tool result (which should always happen and at most\n // once according to the spec). Rather than relying on the\n // `ui/notifications/tool-input` notification to set the tool input value,\n // we read from `window.openai.toolInput so that we have the most recent\n // set value.\n //\n // When OpenAI fixes this issue and sends `ui/notifications/tool-input`\n // consistently according to the MCP Apps specification, this can be\n // reverted to use the `app.ontoolinput` callback.\n toolInput: window.openai.toolInput,\n\n // OpenAI doesn't provide access to `_meta` from ui/notifications/tool-result,\n // so we need to use window.openai.toolResponseMetadata directly\n _meta: window.openai.toolResponseMetadata as\n | ApolloMcpServerApps.Meta\n | undefined,\n };\n });\n }\n}\n"]}
|
package/dist/openai/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/openai/index.js
CHANGED
package/dist/openai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ApolloClient } from \"./core/ApolloClient.js\";\n"]}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export { useApp } from "./hooks/useApp.js";
|
|
2
|
-
export { useHostContext } from "./hooks/useHostContext.js";
|
|
3
|
-
export { useToolName } from "./hooks/useToolName.js";
|
|
4
|
-
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
5
|
-
export { useToolInput } from "./hooks/useToolInput.js";
|
|
6
|
-
export { useToolInfo } from "./hooks/useToolInfo.js";
|
|
7
|
-
export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
|
|
8
1
|
export { useWidgetState } from "./hooks/useWidgetState.js";
|
|
9
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export { useApp } from "./hooks/useApp.js";
|
|
2
|
-
export { useHostContext } from "./hooks/useHostContext.js";
|
|
3
|
-
export { useToolName } from "./hooks/useToolName.js";
|
|
4
|
-
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
5
|
-
export { useToolInput } from "./hooks/useToolInput.js";
|
|
6
|
-
export { useToolInfo } from "./hooks/useToolInfo.js";
|
|
7
|
-
export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
|
|
8
1
|
export { useWidgetState } from "./hooks/useWidgetState.js";
|
|
9
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/openai/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { useWidgetState } from \"./hooks/useWidgetState.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloProvider.d.ts","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ApolloProvider.d.ts","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAIpF,KAAK,YAAY,GAAG,kBAAkB,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAEhF,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,UAAiB,KAAK;QACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC;KACtB;CACF;AAED,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,KAAK,2CAWxE"}
|
|
@@ -10,6 +10,6 @@ export function ApolloProvider({ children, client }) {
|
|
|
10
10
|
invariant(client[aiClientSymbol], '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
11
|
}
|
|
12
12
|
use(client.connect());
|
|
13
|
-
return
|
|
13
|
+
return _jsx(BaseApolloProvider, { client: client, children: children });
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=ApolloProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAWlE,MAAM,UAAU,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAwB;IACvE,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,CACP,MAAM,CAAC,cAAc,CAAC,EACtB,+MAA+M,CAChN,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAEtB,OAAO,KAAC,kBAAkB,IAAC,MAAM,EAAE,MAAM,YAAG,QAAQ,GAAsB,CAAC;AAC7E,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { use } from \"react\";\nimport { ApolloProvider as BaseApolloProvider } from \"@apollo/client/react\";\nimport { ApolloClient as OpenAiApolloClient } from \"../openai/core/ApolloClient.js\";\nimport { ApolloClient as McpApolloClient } from \"../mcp/core/ApolloClient.js\";\nimport type { ApolloClient as FallbackApolloClient } from \"../core/ApolloClient.js\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { aiClientSymbol, invariant } from \"../utilities/index.js\";\n\ntype ApolloClient = OpenAiApolloClient | McpApolloClient | FallbackApolloClient;\n\nexport declare namespace ApolloProvider {\n export interface Props {\n children?: ReactNode;\n client: ApolloClient;\n }\n}\n\nexport function ApolloProvider({ children, client }: ApolloProvider.Props) {\n if (__DEV__) {\n invariant(\n client[aiClientSymbol],\n '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.'\n );\n }\n\n use(client.connect());\n\n return <BaseApolloProvider client={client}>{children}</BaseApolloProvider>;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
2
|
-
import type
|
|
2
|
+
import { type Reactive } from "./reactive.js";
|
|
3
3
|
type HydratedVariablesInput<TVariables> = {
|
|
4
4
|
[K in keyof TVariables]: TVariables[K] | Reactive<TVariables[K]>;
|
|
5
5
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHydrationUtils.d.ts","sourceRoot":"","sources":["../../src/react/createHydrationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQ1D,KAAK,sBAAsB,CAAC,UAAU,IAAI;KACvC,CAAC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CACjE,CAAC;AAEF,KAAK,cAAc,CAAC,UAAU,EAAE,KAAK,IAAI;KACtC,CAAC,IAAI,MAAM,UAAU,IAAI,CAAC,SAAS,MAAM,KAAK,GAC7C,KAAK,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,GAC5B,KAAK,GACL,CAAC,GACH,CAAC,GAAG,CAAC,SAAS,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK;CACzD,CAAC;AAEF,KAAK,YAAY,CAAC,MAAM,IAAI,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,KAC1D,IAAI,CAAC;AAEV,oBAAoB;AACpB,wBAAgB,oBAAoB,CAClC,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,QAAQ,EAAE,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,YAAY;2BAKzD,eAAe,SAAS,sBAAsB,CAAC,UAAU,CAAC,aAE/C,eAAe,GACxB,MAAM,CAAC,OAAO,CAAC,MAAM,eAAe,EAAE,MAAM,UAAU,CAAC,EAAE,KAAK,CAAC,KAChE,CACD,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CACxE;EAoIF"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { useState, useCallback, useRef, useMemo, useLayoutEffect } from "react";
|
|
2
|
-
import { useApolloClient } from "./useApolloClient.js";
|
|
3
|
-
import {
|
|
4
|
-
import { isReactive } from "../../../react/reactive.js";
|
|
2
|
+
import { useApolloClient } from "./hooks/internal/useApolloClient.js";
|
|
3
|
+
import { isReactive } from "./reactive.js";
|
|
5
4
|
import { equal } from "@wry/equality";
|
|
6
5
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
7
|
-
import { getToolNamesFromDocument, getVariableNamesFromDocument, } from "
|
|
6
|
+
import { getToolNamesFromDocument, getVariableNamesFromDocument, } from "../utilities/index.js";
|
|
8
7
|
/** @experimental */
|
|
9
8
|
export function createHydrationUtils(document) {
|
|
10
9
|
const documentToolNames = getToolNamesFromDocument(document);
|
|
11
10
|
const variableNames = getVariableNamesFromDocument(document);
|
|
12
11
|
function useHydratedVariables(variables) {
|
|
13
12
|
const client = useApolloClient();
|
|
14
|
-
const
|
|
15
|
-
const [toolInput] = useState(() => client.toolInput);
|
|
13
|
+
const [toolInput] = useState(() => client["hydratedToolInput"]);
|
|
16
14
|
const toolMatches = toolInput !== undefined &&
|
|
17
|
-
toolName !== undefined &&
|
|
18
|
-
documentToolNames.has(toolName);
|
|
15
|
+
client.toolInfo?.toolName !== undefined &&
|
|
16
|
+
documentToolNames.has(client.toolInfo.toolName);
|
|
19
17
|
const [stateVars, setStateVars] = useState(() => {
|
|
20
18
|
const values = {};
|
|
21
19
|
for (const [key, value] of Object.entries(toolMatches ? toolInput : variables)) {
|
|
@@ -71,7 +69,7 @@ export function createHydrationUtils(document) {
|
|
|
71
69
|
// present, so both paths are idempotent.
|
|
72
70
|
useLayoutEffect(() => {
|
|
73
71
|
if (toolMatches) {
|
|
74
|
-
client
|
|
72
|
+
client["clearHydratedToolInput"]();
|
|
75
73
|
}
|
|
76
74
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
75
|
}, []);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHydrationUtils.js","sourceRoot":"","sources":["../../src/react/createHydrationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAMhF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,C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utEffect } from \"react\";\nimport type {\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport { useApolloClient } from \"./hooks/internal/useApolloClient.js\";\nimport { isReactive, type Reactive } from \"./reactive.js\";\nimport { equal } from \"@wry/equality\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport {\n getToolNamesFromDocument,\n getVariableNamesFromDocument,\n} from \"../utilities/index.js\";\n\ntype HydratedVariablesInput<TVariables> = {\n [K in keyof TVariables]: TVariables[K] | Reactive<TVariables[K]>;\n};\n\ntype StateVariables<TVariables, Input> = {\n [K in keyof TVariables as K extends keyof Input ?\n Input[K] extends Reactive<any> ?\n never\n : K\n : K]: K extends keyof TVariables ? TVariables[K] : never;\n};\n\ntype SetVariables<TState> = (\n update: Partial<TState> | ((prev: TState) => Partial<TState>)\n) => void;\n\n/** @experimental */\nexport function createHydrationUtils<\n TVariables extends OperationVariables = OperationVariables,\n>(document: TypedDocumentNode<any, TVariables> | DocumentNode) {\n const documentToolNames = getToolNamesFromDocument(document);\n const variableNames = getVariableNamesFromDocument(document);\n\n function useHydratedVariables<\n TInputVariables extends HydratedVariablesInput<TVariables>,\n >(\n variables: TInputVariables &\n Record<Exclude<keyof TInputVariables, keyof TVariables>, never>\n ): [\n variables: TVariables,\n setVariables: SetVariables<StateVariables<TVariables, TInputVariables>>,\n ] {\n const client = useApolloClient();\n const [toolInput] = useState(() => client[\"hydratedToolInput\"]);\n\n const toolMatches =\n toolInput !== undefined &&\n client.toolInfo?.toolName !== undefined &&\n documentToolNames.has(client.toolInfo.toolName);\n\n const [stateVars, setStateVars] = useState<Record<string, unknown>>(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(\n toolMatches ? toolInput : variables\n )) {\n if (variableNames.has(key) && !isReactive(value)) {\n values[key] = value;\n }\n }\n\n return values;\n });\n\n const [initialReactiveVars] = useState<Record<string, unknown>>(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(variables)) {\n if (variableNames.has(key) && isReactive(value)) {\n values[key] = value.value;\n }\n }\n\n return values;\n });\n\n const [reactiveVars, setReactiveVars] = useState(() => {\n const values: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(initialReactiveVars)) {\n if (toolMatches && key in toolInput) {\n values[key] = toolInput[key];\n } else if (!toolMatches) {\n values[key] = value;\n }\n }\n\n return values;\n });\n\n const changedKeysRef = useRef(new Set<string>());\n const nextReactiveVars: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(variables)) {\n if (!variableNames.has(key) || !isReactive(value)) continue;\n\n const hasChanged =\n changedKeysRef.current.has(key) ||\n !equal(value.value, initialReactiveVars[key]);\n\n if (toolMatches && !hasChanged) {\n if (key in toolInput) {\n nextReactiveVars[key] = toolInput[key];\n }\n } else {\n nextReactiveVars[key] = value.value;\n }\n }\n\n if (!equal(nextReactiveVars, reactiveVars)) {\n setReactiveVars(nextReactiveVars);\n }\n\n // Clear the tool input after first mount so that remounting the component\n // uses the user-provided variables rather than the hydrated tool input.\n // This runs once on mount; watchQuery also clears it when useQuery is\n // present, so both paths are idempotent.\n useLayoutEffect(() => {\n if (toolMatches) {\n client[\"clearHydratedToolInput\"]();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n for (const [key, value] of Object.entries(variables)) {\n if (\n variableNames.has(key) &&\n isReactive(value) &&\n !changedKeysRef.current.has(key) &&\n !equal(value.value, initialReactiveVars[key])\n ) {\n changedKeysRef.current.add(key);\n }\n }\n });\n\n const resolvedVariables = useMemo(() => {\n return { ...stateVars, ...reactiveVars } as TVariables;\n }, [stateVars, reactiveVars]);\n\n const setVariables = useCallback<\n SetVariables<StateVariables<TVariables, TInputVariables>>\n >((update) => {\n setStateVars((prev) => {\n const updates =\n typeof update === \"function\" ? update(prev as any) : update;\n\n const filtered = Object.fromEntries(\n Object.entries(updates).filter(([key]) => {\n if (key in initialReactiveVars) {\n if (__DEV__) {\n console.warn(\n `Attempted to set reactive variable \"${key}\" via setVariables. ` +\n `Reactive variables are read-only and are ignored. `\n );\n }\n return false;\n }\n return true;\n })\n );\n\n if (Object.keys(filtered).length === 0) return prev;\n\n return { ...prev, ...filtered };\n });\n }, []);\n\n return [resolvedVariables, setVariables];\n }\n\n return { useHydratedVariables };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApolloClient.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAG7E,wBAAgB,eAAe,yBAS9B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useApolloClient as useBaseApolloClient } from "@apollo/client/react";
|
|
2
|
-
import {
|
|
2
|
+
import { AbstractApolloClient } from "../../../core/AbstractApolloClient.js";
|
|
3
3
|
import { aiClientSymbol, invariant } from "../../../utilities/index.js";
|
|
4
|
-
export function useApolloClient(
|
|
5
|
-
const client = useBaseApolloClient(
|
|
4
|
+
export function useApolloClient() {
|
|
5
|
+
const client = useBaseApolloClient();
|
|
6
6
|
invariant(client[aiClientSymbol], '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.');
|
|
7
7
|
return client;
|
|
8
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,mBAAmB,EAA0B,CAAC;IAE7D,SAAS,CACP,MAAM,CAAC,cAAc,CAAC,EACtB,+MAA+M,CAChN,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useApolloClient as useBaseApolloClient } from \"@apollo/client/react\";\nimport { AbstractApolloClient } from \"../../../core/AbstractApolloClient.js\";\nimport { aiClientSymbol, invariant } from \"../../../utilities/index.js\";\n\nexport function useApolloClient() {\n const client = useBaseApolloClient() as AbstractApolloClient;\n\n invariant(\n client[aiClientSymbol],\n '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.'\n );\n\n return client;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApp.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useApp.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,iDAErB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApp.js","sourceRoot":"","sources":["../../../src/react/hooks/useApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,MAAM;IACpB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;AAC7C,CAAC","sourcesContent":["import { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useApp() {\n return useApolloClient()[\"appManager\"].app;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHostContext.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,0EAU7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
-
import { useApolloClient } from "./useApolloClient";
|
|
2
|
+
import { useApolloClient } from "./internal/useApolloClient";
|
|
3
3
|
export function useHostContext() {
|
|
4
4
|
const appManager = useApolloClient()["appManager"];
|
|
5
5
|
return useSyncExternalStore(useCallback((update) => appManager.onHostContextChanged(update), [appManager]), () => appManager.app.getHostContext());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHostContext.js","sourceRoot":"","sources":["../../../src/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,UAAU,cAAc;IAC5B,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC;IAEnD,OAAO,oBAAoB,CACzB,WAAW,CACT,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,MAAM,CAAC,EACnD,CAAC,UAAU,CAAC,CACb,EACD,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,EAAE,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useSyncExternalStore } from \"react\";\nimport { useApolloClient } from \"./internal/useApolloClient\";\n\nexport function useHostContext() {\n const appManager = useApolloClient()[\"appManager\"];\n\n return useSyncExternalStore(\n useCallback(\n (update) => appManager.onHostContextChanged(update),\n [appManager]\n ),\n () => appManager.app.getHostContext()\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolInfo.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG/D,wBAAgB,WAAW,IAAI,QAAQ,GAAG,SAAS,CAElD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolInfo.js","sourceRoot":"","sources":["../../../src/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,WAAW;IACzB,OAAO,eAAe,EAAE,CAAC,QAAQ,CAAC;AACpC,CAAC","sourcesContent":["import type { ToolInfo } from \"../../core/typeRegistration.js\";\nimport { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useToolInfo(): ToolInfo | undefined {\n return useApolloClient().toolInfo;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,uEAE9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolMetadata.js","sourceRoot":"","sources":["../../../src/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,eAAe;IAC7B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC;AACxC,CAAC","sourcesContent":["import { useApolloClient } from \"./internal/useApolloClient.js\";\n\nexport function useToolMetadata() {\n return useApolloClient().toolMetadata;\n}\n"]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
export { ApolloProvider } from "./ApolloProvider.js";
|
|
2
2
|
export { reactive } from "./reactive.js";
|
|
3
3
|
export type { Reactive } from "./reactive.js";
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export declare const useToolInput: typeof import("./index.mcp.js").useToolInput;
|
|
11
|
-
export declare const useToolMetadata: typeof import("./index.mcp.js").useToolMetadata;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
14
|
-
* in the next major version.
|
|
15
|
-
*/
|
|
16
|
-
export declare const useToolName: typeof import("./index.mcp.js").useToolName;
|
|
17
|
-
export declare const useToolInfo: typeof import("./index.mcp.js").useToolInfo;
|
|
18
|
-
/** @experimental */
|
|
19
|
-
export declare const createHydrationUtils: typeof import("./index.mcp.js").createHydrationUtils;
|
|
4
|
+
export { useApp } from "./hooks/useApp.js";
|
|
5
|
+
export { useHostContext } from "./hooks/useHostContext.js";
|
|
6
|
+
export { useToolInfo } from "./hooks/useToolInfo.js";
|
|
7
|
+
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
8
|
+
export { createHydrationUtils } from "./createHydrationUtils.js";
|
|
20
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|