@apollo/client-ai-apps 0.6.5 → 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 +62 -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/{mcp/core → core}/McpAppManager.d.ts +14 -10
- 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/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 -101
- 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 -101
- 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/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/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/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 -170
- package/src/mcp/core/__tests__/ApolloClient.test.ts +398 -140
- package/src/mcp/index.ts +0 -1
- package/src/openai/core/ApolloClient.ts +48 -166
- package/src/openai/core/__tests__/ApolloClient.test.ts +680 -185
- 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/utilities/connectToHost.ts +13 -0
- package/src/utilities/index.ts +1 -0
- package/tsconfig.vite.json +1 -1
- package/vitest.config.ts +13 -0
- package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
- package/dist/mcp/core/McpAppManager.js +0 -88
- 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 -37
- package/dist/openai/core/McpAppManager.d.ts.map +0 -1
- package/dist/openai/core/McpAppManager.js +0 -97
- 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 -136
- package/src/mcp/link/ToolCallLink.ts +0 -40
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -113
- 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 -148
- 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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe } from "vitest";
|
|
2
|
+
import { createHostEnv } from "../utilities/createHostEnv";
|
|
3
|
+
import { AbstractApolloClient } from "../../../core/AbstractApolloClient";
|
|
4
|
+
import { ApolloClient as McpApolloClient } from "../../../mcp/core/ApolloClient.js";
|
|
5
|
+
import { ApolloClient as OpenAiApolloClient } from "../../../openai/core/ApolloClient.js";
|
|
6
|
+
|
|
7
|
+
export function eachHostEnv(
|
|
8
|
+
suite: (
|
|
9
|
+
setupHost: ReturnType<typeof createHostEnv>,
|
|
10
|
+
ApolloClient: new (
|
|
11
|
+
options: AbstractApolloClient.Options
|
|
12
|
+
) => AbstractApolloClient,
|
|
13
|
+
opts: { hostEnv: "mcp" | "openai" }
|
|
14
|
+
) => void | PromiseLike<void>
|
|
15
|
+
) {
|
|
16
|
+
describe.each([
|
|
17
|
+
["mcp", McpApolloClient],
|
|
18
|
+
["openai", OpenAiApolloClient],
|
|
19
|
+
] as const)("Host: %s", (hostEnv, ApolloClient) => {
|
|
20
|
+
return suite(createHostEnv(hostEnv), ApolloClient, { hostEnv });
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { McpUiHostContext } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { AbstractApolloClient } from "../../../core/AbstractApolloClient";
|
|
3
|
+
import { minimalHostContextWithToolName } from "../mcp/minimalHostContextWithToolName";
|
|
4
|
+
import { mockMcpHost } from "../mcp/mockMcpHost";
|
|
5
|
+
import { stubOpenAiGlobals } from "../openai/stubOpenAiGlobals";
|
|
6
|
+
import type { ApolloMcpServerApps } from "../../../core/types";
|
|
7
|
+
import type { OpenAiGlobals } from "../../../openai/types";
|
|
8
|
+
|
|
9
|
+
export declare namespace createHostEnv {
|
|
10
|
+
export namespace setupHost {
|
|
11
|
+
export interface MockToolResult extends Pick<
|
|
12
|
+
ApolloMcpServerApps.CallToolResult,
|
|
13
|
+
"structuredContent" | "isError"
|
|
14
|
+
> {
|
|
15
|
+
_meta?: Omit<ApolloMcpServerApps.Meta, "toolName"> & {
|
|
16
|
+
toolName?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Options {
|
|
21
|
+
/**
|
|
22
|
+
* The ApolloClient instance under test. Passed here so that
|
|
23
|
+
* `client.stop()` is called automatically when the env is disposed,
|
|
24
|
+
* preventing MCP event listener leaks between tests.
|
|
25
|
+
*/
|
|
26
|
+
client: AbstractApolloClient;
|
|
27
|
+
hostContext?: McpUiHostContext;
|
|
28
|
+
toolCall?: {
|
|
29
|
+
name?: string;
|
|
30
|
+
input?: Record<string, unknown>;
|
|
31
|
+
result?: setupHost.MockToolResult;
|
|
32
|
+
};
|
|
33
|
+
openai?: {
|
|
34
|
+
/**
|
|
35
|
+
* When true, sets window.openai.toolOutput to toolCall.result.structuredContent.
|
|
36
|
+
* Simulates the page-refresh scenario where ChatGPT does not re-send the
|
|
37
|
+
* tool-result notification. Call host.sendToolInput(params.toolInput) but
|
|
38
|
+
* omit host.sendToolResult() in the test.
|
|
39
|
+
*/
|
|
40
|
+
toolOutput?: true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createHostEnv(hostEnv: "openai" | "mcp") {
|
|
47
|
+
return async function setupHost(options: createHostEnv.setupHost.Options) {
|
|
48
|
+
const { client, toolCall } = options;
|
|
49
|
+
|
|
50
|
+
const toolName = toolCall?.name;
|
|
51
|
+
const toolInput = toolCall?.input;
|
|
52
|
+
|
|
53
|
+
const mockOptions: mockMcpHost.Options = {};
|
|
54
|
+
|
|
55
|
+
const hostContext =
|
|
56
|
+
toolName ?
|
|
57
|
+
{ ...minimalHostContextWithToolName(toolName), ...options.hostContext }
|
|
58
|
+
: options.hostContext;
|
|
59
|
+
|
|
60
|
+
if (hostContext) {
|
|
61
|
+
mockOptions.hostContext = hostContext;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const toolResult =
|
|
65
|
+
toolName ?
|
|
66
|
+
{
|
|
67
|
+
...options.toolCall?.result,
|
|
68
|
+
structuredContent: {
|
|
69
|
+
...options.toolCall?.result?.structuredContent,
|
|
70
|
+
toolName,
|
|
71
|
+
},
|
|
72
|
+
_meta: { ...options.toolCall?.result?._meta, toolName },
|
|
73
|
+
}
|
|
74
|
+
: options.toolCall?.result;
|
|
75
|
+
|
|
76
|
+
const host = await mockMcpHost(mockOptions);
|
|
77
|
+
|
|
78
|
+
const params = {
|
|
79
|
+
toolInput: toolInput ? { arguments: toolInput } : {},
|
|
80
|
+
toolResult: { ...toolResult },
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (hostEnv === "openai") {
|
|
84
|
+
// OpenAI doesn't set _meta in the notification
|
|
85
|
+
delete params.toolResult._meta;
|
|
86
|
+
|
|
87
|
+
stubOpenAiGlobals((defaults) => {
|
|
88
|
+
const globals: Partial<OpenAiGlobals> = { ...defaults };
|
|
89
|
+
|
|
90
|
+
if (toolInput) {
|
|
91
|
+
globals.toolInput = toolInput;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const _meta = toolResult?._meta;
|
|
95
|
+
|
|
96
|
+
if (_meta) {
|
|
97
|
+
globals.toolResponseMetadata = _meta;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (options.openai?.toolOutput && toolResult?.structuredContent) {
|
|
101
|
+
globals.toolOutput = toolResult.structuredContent;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return globals;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
host,
|
|
110
|
+
params,
|
|
111
|
+
[Symbol.dispose]() {
|
|
112
|
+
host[Symbol.dispose]();
|
|
113
|
+
client.stop();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PostMessageTransport, type App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
|
|
3
|
+
export async function connectToHost(app: App) {
|
|
4
|
+
try {
|
|
5
|
+
return await app.connect(
|
|
6
|
+
new PostMessageTransport(window.parent, window.parent)
|
|
7
|
+
);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
const error = e instanceof Error ? e : new Error("Failed to connect");
|
|
10
|
+
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/utilities/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { aiClientSymbol } from "./constants.js";
|
|
2
|
+
export { connectToHost } from "./connectToHost.js";
|
|
2
3
|
export { getVariablesForOperationFromToolInput } from "./getVariablesForOperationFromToolInput.js";
|
|
3
4
|
export { getToolNamesFromDocument } from "./getToolNamesFromDocument.js";
|
|
4
5
|
export { getVariableNamesFromDocument } from "./getVariableNamesFromDocument.js";
|
package/tsconfig.vite.json
CHANGED
package/vitest.config.ts
CHANGED
|
@@ -8,5 +8,18 @@ export default defineConfig({
|
|
|
8
8
|
setupFiles: ["./vitest-setup.ts"],
|
|
9
9
|
mockReset: true,
|
|
10
10
|
unstubGlobals: true,
|
|
11
|
+
tags: [
|
|
12
|
+
{
|
|
13
|
+
name: "flaky",
|
|
14
|
+
retry: 3,
|
|
15
|
+
description:
|
|
16
|
+
"Tests that might intermittently fail due to e.g. timeout issues.",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "fs",
|
|
20
|
+
timeout: 10_000,
|
|
21
|
+
description: "Tests that write to the filesystem.",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
11
24
|
},
|
|
12
25
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAEH,KAAK,mCAAmC,EACzC,MAAM,gCAAgC,CAAC;AAExC,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;AAGvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAO5D,gBAAgB;AAChB,qBAAa,aAAa;;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;gBAUN,QAAQ,EAAE,mBAAmB;IAIzC,IAAI,QAAQ,uBAEX;IAED,IAAI,YAAY,yCAEf;IAED,IAAI,SAAS,wCAEZ;IAED,oBAAoB,CAClB,EAAE,EAAE,CAAC,MAAM,EAAE,mCAAmC,CAAC,QAAQ,CAAC,KAAK,IAAI;IASrE,OAAO;;;;;;;;;;;MA4CJ;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;;;;;YAYa,aAAa;CAW5B"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { App, PostMessageTransport, } from "@modelcontextprotocol/ext-apps";
|
|
2
|
-
import { print } from "@apollo/client/utilities";
|
|
3
|
-
import { cacheAsync, promiseWithResolvers } from "../../utilities";
|
|
4
|
-
/** @internal */
|
|
5
|
-
export class McpAppManager {
|
|
6
|
-
app;
|
|
7
|
-
#toolName;
|
|
8
|
-
#toolMetadata;
|
|
9
|
-
#toolInput;
|
|
10
|
-
#hostContextCallbacks = new Set();
|
|
11
|
-
constructor(manifest) {
|
|
12
|
-
this.app = new App({ name: manifest.name, version: manifest.appVersion });
|
|
13
|
-
}
|
|
14
|
-
get toolName() {
|
|
15
|
-
return this.#toolName;
|
|
16
|
-
}
|
|
17
|
-
get toolMetadata() {
|
|
18
|
-
return this.#toolMetadata;
|
|
19
|
-
}
|
|
20
|
-
get toolInput() {
|
|
21
|
-
return this.#toolInput;
|
|
22
|
-
}
|
|
23
|
-
onHostContextChanged(cb) {
|
|
24
|
-
this.#hostContextCallbacks.add(cb);
|
|
25
|
-
return () => {
|
|
26
|
-
this.#hostContextCallbacks.delete(cb);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
connect = cacheAsync(async () => {
|
|
30
|
-
let toolResult = promiseWithResolvers();
|
|
31
|
-
let toolInput = promiseWithResolvers();
|
|
32
|
-
this.app.ontoolresult = (params) => {
|
|
33
|
-
toolResult.resolve(params);
|
|
34
|
-
};
|
|
35
|
-
this.app.ontoolinput = (params) => {
|
|
36
|
-
toolInput.resolve(params);
|
|
37
|
-
};
|
|
38
|
-
this.app.onhostcontextchanged = (params) => {
|
|
39
|
-
this.#hostContextCallbacks.forEach((cb) => cb(params));
|
|
40
|
-
};
|
|
41
|
-
await this.connectToHost();
|
|
42
|
-
const { structuredContent, _meta } = await toolResult.promise;
|
|
43
|
-
const { arguments: args } = await toolInput.promise;
|
|
44
|
-
// Some hosts do not provide toolInfo in the ui/initialize response, so we
|
|
45
|
-
// fallback to `_meta.toolName` provided by Apollo MCP server if the value
|
|
46
|
-
// is not available.
|
|
47
|
-
this.#toolName =
|
|
48
|
-
this.app.getHostContext()?.toolInfo?.tool.name ??
|
|
49
|
-
_meta?.toolName ??
|
|
50
|
-
// Some hosts do not forward `_meta` nor do they provide `toolInfo`. Our
|
|
51
|
-
// MCP server provides `toolName` in `structuredContent` as a workaround
|
|
52
|
-
// that we can use if all else fails
|
|
53
|
-
structuredContent.toolName;
|
|
54
|
-
this.#toolMetadata = _meta;
|
|
55
|
-
this.#toolInput = args;
|
|
56
|
-
return {
|
|
57
|
-
structuredContent: {
|
|
58
|
-
...structuredContent,
|
|
59
|
-
..._meta?.structuredContent,
|
|
60
|
-
},
|
|
61
|
-
toolName: this.toolName,
|
|
62
|
-
args,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
close() {
|
|
66
|
-
return this.app.close();
|
|
67
|
-
}
|
|
68
|
-
async executeQuery({ query, variables, }) {
|
|
69
|
-
const result = (await this.app.callServerTool({
|
|
70
|
-
name: "execute",
|
|
71
|
-
arguments: { query: print(query), variables },
|
|
72
|
-
}));
|
|
73
|
-
return {
|
|
74
|
-
...result.structuredContent,
|
|
75
|
-
...result._meta?.structuredContent,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async connectToHost() {
|
|
79
|
-
try {
|
|
80
|
-
return await this.app.connect(new PostMessageTransport(window.parent, window.parent));
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
const error = e instanceof Error ? e : new Error("Failed to connect");
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=McpAppManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,oBAAoB,GAErB,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAQnE,gBAAgB;AAChB,MAAM,OAAO,aAAa;IACf,GAAG,CAAM;IAElB,SAAS,CAAqB;IAC9B,aAAa,CAA0D;IACvE,UAAU,CAAsC;IAEhD,qBAAqB,GAAG,IAAI,GAAG,EAE5B,CAAC;IAEJ,YAAY,QAA6B;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI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CAAC,mBAAmB,CAAC,CAAC;YAEtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n App,\n PostMessageTransport,\n type McpUiHostContextChangedNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { ApplicationManifest } from \"../../types/application-manifest\";\nimport type { FormattedExecutionResult } from \"graphql\";\nimport type { DocumentNode, OperationVariables } from \"@apollo/client\";\nimport { print } from \"@apollo/client/utilities\";\nimport { cacheAsync, promiseWithResolvers } from \"../../utilities\";\nimport type { ApolloMcpServerApps } from \"../../core/types\";\n\ntype ExecuteQueryCallToolResult = Omit<CallToolResult, \"structuredContent\"> & {\n structuredContent: FormattedExecutionResult;\n _meta?: { structuredContent?: FormattedExecutionResult };\n};\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #toolName: string | undefined;\n #toolMetadata: ApolloMcpServerApps.CallToolResult[\"_meta\"] | undefined;\n #toolInput: Record<string, unknown> | undefined;\n\n #hostContextCallbacks = new Set<\n (params: McpUiHostContextChangedNotification[\"params\"]) => void\n >();\n\n constructor(manifest: ApplicationManifest) {\n this.app = new App({ name: manifest.name, version: manifest.appVersion });\n }\n\n get toolName() {\n return this.#toolName;\n }\n\n get toolMetadata() {\n return this.#toolMetadata;\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n onHostContextChanged(\n cb: (params: McpUiHostContextChangedNotification[\"params\"]) => void\n ) {\n this.#hostContextCallbacks.add(cb);\n\n return () => {\n this.#hostContextCallbacks.delete(cb);\n };\n }\n\n connect = cacheAsync(async () => {\n let toolResult = promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n let toolInput = promiseWithResolvers<Parameters<App[\"ontoolinput\"]>[0]>();\n\n this.app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n this.app.ontoolinput = (params) => {\n toolInput.resolve(params);\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.#hostContextCallbacks.forEach((cb) => cb(params));\n };\n\n await this.connectToHost();\n\n const { structuredContent, _meta } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n // Some hosts do not provide toolInfo in the ui/initialize response, so we\n // fallback to `_meta.toolName` provided by Apollo MCP server if the value\n // is not available.\n this.#toolName =\n this.app.getHostContext()?.toolInfo?.tool.name ??\n _meta?.toolName ??\n // Some hosts do not forward `_meta` nor do they provide `toolInfo`. Our\n // MCP server provides `toolName` in `structuredContent` as a workaround\n // that we can use if all else fails\n structuredContent.toolName;\n this.#toolMetadata = _meta;\n this.#toolInput = args;\n\n return {\n structuredContent: {\n ...structuredContent,\n ..._meta?.structuredContent,\n },\n toolName: this.toolName,\n args,\n };\n });\n\n close() {\n return this.app.close();\n }\n\n async executeQuery({\n query,\n variables,\n }: {\n query: DocumentNode;\n variables: OperationVariables | undefined;\n }) {\n const result = (await this.app.callServerTool({\n name: \"execute\",\n arguments: { query: print(query), variables },\n })) as ExecuteQueryCallToolResult;\n\n return {\n ...result.structuredContent,\n ...result._meta?.structuredContent,\n };\n }\n\n private async connectToHost() {\n try {\n return await this.app.connect(\n new PostMessageTransport(window.parent, window.parent)\n );\n } catch (e) {\n const error = e instanceof Error ? e : new Error(\"Failed to connect\");\n\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ApolloLink, Observable } from "@apollo/client";
|
|
2
|
-
/**
|
|
3
|
-
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
4
|
-
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
5
|
-
* validate that the terminating link is an instance of this link.
|
|
6
|
-
*
|
|
7
|
-
* @example Providing a custom link chain
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { ApolloLink } from "@apollo/client";
|
|
11
|
-
* import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
|
|
12
|
-
*
|
|
13
|
-
* const link = ApolloLink.from([
|
|
14
|
-
* ...otherLinks,
|
|
15
|
-
* new ToolCallLink()
|
|
16
|
-
* ]);
|
|
17
|
-
*
|
|
18
|
-
* const client = new ApolloClient({
|
|
19
|
-
* link,
|
|
20
|
-
* // ...
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class ToolCallLink extends ApolloLink {
|
|
25
|
-
readonly name = "ToolCallLink";
|
|
26
|
-
request(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=ToolCallLink.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../../src/mcp/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIxD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,QAAQ,CAAC,IAAI,kBAAkB;IAE/B,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CAUxE"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ApolloLink, Observable } from "@apollo/client";
|
|
2
|
-
import { from } from "rxjs";
|
|
3
|
-
/**
|
|
4
|
-
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
5
|
-
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
6
|
-
* validate that the terminating link is an instance of this link.
|
|
7
|
-
*
|
|
8
|
-
* @example Providing a custom link chain
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { ApolloLink } from "@apollo/client";
|
|
12
|
-
* import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
|
|
13
|
-
*
|
|
14
|
-
* const link = ApolloLink.from([
|
|
15
|
-
* ...otherLinks,
|
|
16
|
-
* new ToolCallLink()
|
|
17
|
-
* ]);
|
|
18
|
-
*
|
|
19
|
-
* const client = new ApolloClient({
|
|
20
|
-
* link,
|
|
21
|
-
* // ...
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export class ToolCallLink extends ApolloLink {
|
|
26
|
-
name = "ToolCallLink";
|
|
27
|
-
request(operation) {
|
|
28
|
-
const client = operation.client;
|
|
29
|
-
return from(client["appManager"].executeQuery({
|
|
30
|
-
query: operation.query,
|
|
31
|
-
variables: operation.variables,
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=ToolCallLink.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../../src/mcp/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IACjC,IAAI,GAAG,cAAc,CAAC;IAE/B,OAAO,CAAC,SAA+B;QACrC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAyB,CAAC;QAEnD,OAAO,IAAI,CACT,MAAM,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC;YAChC,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B,CAAC,CACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink, Observable } from \"@apollo/client\";\nimport { from } from \"rxjs\";\nimport type { ApolloClient as McpApolloClient } from \"../core/ApolloClient\";\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 readonly name = \"ToolCallLink\";\n\n request(operation: ApolloLink.Operation): Observable<ApolloLink.Result> {\n const client = operation.client as McpApolloClient;\n\n return from(\n client[\"appManager\"].executeQuery({\n query: operation.query,\n variables: operation.variables,\n })\n );\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHydrationUtils.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/createHydrationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAQ3D,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,MAA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AM,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE;oBACvC,IAAI,GAAG,IAAI,mBAAmB,EAAE,CAAC;wBAC/B,IAAI,OAAO,EAAE,CAAC;4BACZ,OAAO,CAAC,IAAI,CACV,uCAAuC,GAAG,sBAAsB;gCAC9D,oDAAoD,CACvD,CAAC;wBACJ,CAAC;wBACD,OAAO,KAAK,CAAC;oBACf,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC,CACH,CAAC;gBAEF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAEpD,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { useState, useCallback, useRef, useMemo, useLayoutEffect } from \"react\";\nimport type {\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useToolName } from \"./useToolName.js\";\nimport { isReactive } from \"../../../react/reactive.js\";\nimport type { Reactive } from \"../../../react/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 toolName = useToolName();\n const [toolInput] = useState(() => client.toolInput);\n\n const toolMatches =\n toolInput !== undefined &&\n toolName !== undefined &&\n documentToolNames.has(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.clearToolInput();\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useApolloClient.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,YAAY,gBAStD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,UAAU,eAAe,CAAC,QAAuB;IACrD,MAAM,MAAM,GAAG,mBAAmB,CAAC,QAAQ,CAAiB,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 { ApolloClient } from \"../../core/ApolloClient.js\";\nimport { aiClientSymbol, invariant } from \"../../../utilities/index.js\";\n\nexport function useApolloClient(override?: ApolloClient) {\n const client = useBaseApolloClient(override) as ApolloClient;\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useApp.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApp.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,iDAErB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useApp.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,MAAM;IACpB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;AAC7C,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useApp() {\n return useApolloClient()[\"appManager\"].app;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHostContext.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,0EAU7B"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
-
import { useApolloClient } from "./useApolloClient";
|
|
3
|
-
export function useHostContext() {
|
|
4
|
-
const appManager = useApolloClient()["appManager"];
|
|
5
|
-
return useSyncExternalStore(useCallback((update) => appManager.onHostContextChanged(update), [appManager]), () => appManager.app.getHostContext());
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=useHostContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHostContext.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,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 \"./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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInfo.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAGlE,wBAAgB,WAAW,IAAI,QAAQ,GAAG,SAAS,CASlD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from "./useApolloClient.js";
|
|
2
|
-
export function useToolInfo() {
|
|
3
|
-
const appManager = useApolloClient()["appManager"];
|
|
4
|
-
const toolName = appManager.toolName;
|
|
5
|
-
if (!toolName) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
return { toolName, toolInput: appManager.toolInput };
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=useToolInfo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInfo.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,WAAW;IACzB,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;IAErC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import type { ToolInfo } from \"../../../core/typeRegistration.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useToolInfo(): ToolInfo | undefined {\n const appManager = useApolloClient()[\"appManager\"];\n const toolName = appManager.toolName;\n\n if (!toolName) {\n return;\n }\n\n return { toolName, toolInput: appManager.toolInput };\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ToolInput } from "../../../core/typeRegistration.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
|
|
4
|
-
* in the next major version.
|
|
5
|
-
*/
|
|
6
|
-
export declare function useToolInput(): ToolInput | undefined;
|
|
7
|
-
//# sourceMappingURL=useToolInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInput.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAGnE;;;GAGG;AACH,wBAAgB,YAAY,IAAI,SAAS,GAAG,SAAS,CAEpD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from "./useApolloClient.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
|
|
4
|
-
* in the next major version.
|
|
5
|
-
*/
|
|
6
|
-
export function useToolInput() {
|
|
7
|
-
return useApolloClient()["appManager"].toolInput;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=useToolInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInput.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC","sourcesContent":["import type { ToolInput } from \"../../../core/typeRegistration.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\n/**\n * @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed\n * in the next major version.\n */\nexport function useToolInput(): ToolInput | undefined {\n return useApolloClient()[\"appManager\"].toolInput;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,0EAE9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolMetadata.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,eAAe;IAC7B,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC;AACtD,CAAC","sourcesContent":["import { useApolloClient } from \"./useApolloClient.js\";\n\nexport function useToolMetadata() {\n return useApolloClient()[\"appManager\"].toolMetadata;\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ToolName } from "../../../core/typeRegistration.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
4
|
-
* in the next major version.
|
|
5
|
-
*/
|
|
6
|
-
export declare function useToolName(): ToolName | undefined;
|
|
7
|
-
//# sourceMappingURL=useToolName.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolName.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAGlE;;;GAGG;AACH,wBAAgB,WAAW,IAAI,QAAQ,GAAG,SAAS,CAElD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from "./useApolloClient.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
4
|
-
* in the next major version.
|
|
5
|
-
*/
|
|
6
|
-
export function useToolName() {
|
|
7
|
-
return useApolloClient()["appManager"].toolName;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=useToolName.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolName.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolName.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC","sourcesContent":["import type { ToolName } from \"../../../core/typeRegistration.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\n/**\n * @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed\n * in the next major version.\n */\nexport function useToolName(): ToolName | undefined {\n return useApolloClient()[\"appManager\"].toolName;\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/react/index.ts"],"names":[],"mappings":"AAAA,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,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/mcp/react/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/react/index.ts"],"names":[],"mappings":"AAAA,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,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export { useApp } from \"./hooks/useApp.js\";\nexport { useHostContext } from \"./hooks/useHostContext.js\";\nexport { useToolName } from \"./hooks/useToolName.js\";\nexport { useToolMetadata } from \"./hooks/useToolMetadata.js\";\nexport { useToolInput } from \"./hooks/useToolInput.js\";\nexport { useToolInfo } from \"./hooks/useToolInfo.js\";\nexport { createHydrationUtils } from \"./hooks/createHydrationUtils.js\";\n"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { App, type McpUiHostContextChangedNotification } 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(): Record<string, unknown> | null;
|
|
12
|
-
get toolInput(): Record<string, unknown> | undefined;
|
|
13
|
-
onHostContextChanged(cb: (params: McpUiHostContextChangedNotification["params"]) => void): () => void;
|
|
14
|
-
connect: (() => Promise<{
|
|
15
|
-
structuredContent: {
|
|
16
|
-
[x: string]: unknown;
|
|
17
|
-
result?: FormattedExecutionResult;
|
|
18
|
-
prefetch?: Record<string, FormattedExecutionResult>;
|
|
19
|
-
toolName?: string;
|
|
20
|
-
};
|
|
21
|
-
toolName: string | undefined;
|
|
22
|
-
args: Record<string, unknown>;
|
|
23
|
-
}>) & {
|
|
24
|
-
reset: () => void;
|
|
25
|
-
};
|
|
26
|
-
close(): Promise<void>;
|
|
27
|
-
executeQuery({ query, variables, }: {
|
|
28
|
-
query: DocumentNode;
|
|
29
|
-
variables: OperationVariables | undefined;
|
|
30
|
-
}): Promise<{
|
|
31
|
-
errors?: ReadonlyArray<import("graphql").GraphQLFormattedError>;
|
|
32
|
-
data?: import("graphql/jsutils/ObjMap").ObjMap<unknown> | null;
|
|
33
|
-
extensions?: import("graphql/jsutils/ObjMap").ObjMap<unknown>;
|
|
34
|
-
}>;
|
|
35
|
-
private connectToHost;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=McpAppManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/openai/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAEH,KAAK,mCAAmC,EACzC,MAAM,gCAAgC,CAAC;AAExC,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;AAUvE,gBAAgB;AAChB,qBAAa,aAAa;;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;gBAUN,QAAQ,EAAE,mBAAmB;IAIzC,IAAI,QAAQ,uBAEX;IAED,IAAI,YAAY,mCAEf;IAED,IAAI,SAAS,wCAEZ;IAED,oBAAoB,CAClB,EAAE,EAAE,CAAC,MAAM,EAAE,mCAAmC,CAAC,QAAQ,CAAC,KAAK,IAAI;IAQrE,OAAO;;;;;;;;;;;MAyDJ;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;;;;;YAYa,aAAa;CAW5B"}
|