@apollo/client-ai-apps 0.5.1 → 0.5.3

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/core/ApolloClient.d.ts +1 -1
  3. package/dist/core/ApolloClient.d.ts.map +1 -1
  4. package/dist/core/ApolloClient.js +1 -1
  5. package/dist/core/ApolloClient.js.map +1 -1
  6. package/dist/core/types.d.ts +6 -0
  7. package/dist/core/types.d.ts.map +1 -1
  8. package/dist/core/types.js.map +1 -1
  9. package/dist/mcp/core/ApolloClient.d.ts +6 -1
  10. package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
  11. package/dist/mcp/core/ApolloClient.js +36 -3
  12. package/dist/mcp/core/ApolloClient.js.map +1 -1
  13. package/dist/mcp/core/McpAppManager.d.ts +4 -9
  14. package/dist/mcp/core/McpAppManager.d.ts.map +1 -1
  15. package/dist/mcp/core/McpAppManager.js +13 -4
  16. package/dist/mcp/core/McpAppManager.js.map +1 -1
  17. package/dist/mcp/react/hooks/createHydrationUtils.d.ts +15 -0
  18. package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +1 -0
  19. package/dist/mcp/react/hooks/createHydrationUtils.js +113 -0
  20. package/dist/mcp/react/hooks/createHydrationUtils.js.map +1 -0
  21. package/dist/mcp/react/hooks/useToolMetadata.d.ts +1 -7
  22. package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +1 -1
  23. package/dist/mcp/react/index.d.ts +1 -0
  24. package/dist/mcp/react/index.d.ts.map +1 -1
  25. package/dist/mcp/react/index.js +1 -0
  26. package/dist/mcp/react/index.js.map +1 -1
  27. package/dist/openai/core/ApolloClient.d.ts +6 -1
  28. package/dist/openai/core/ApolloClient.d.ts.map +1 -1
  29. package/dist/openai/core/ApolloClient.js +37 -3
  30. package/dist/openai/core/ApolloClient.js.map +1 -1
  31. package/dist/openai/core/McpAppManager.d.ts +2 -2
  32. package/dist/openai/core/McpAppManager.d.ts.map +1 -1
  33. package/dist/openai/core/McpAppManager.js +16 -18
  34. package/dist/openai/core/McpAppManager.js.map +1 -1
  35. package/dist/openai/react/hooks/createHydrationUtils.d.ts +15 -0
  36. package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +1 -0
  37. package/dist/openai/react/hooks/createHydrationUtils.js +113 -0
  38. package/dist/openai/react/hooks/createHydrationUtils.js.map +1 -0
  39. package/dist/openai/react/index.d.ts +1 -0
  40. package/dist/openai/react/index.d.ts.map +1 -1
  41. package/dist/openai/react/index.js +1 -0
  42. package/dist/openai/react/index.js.map +1 -1
  43. package/dist/react/ApolloProvider.js +1 -1
  44. package/dist/react/ApolloProvider.js.map +1 -1
  45. package/dist/react/index.d.ts +4 -0
  46. package/dist/react/index.d.ts.map +1 -1
  47. package/dist/react/index.js +3 -0
  48. package/dist/react/index.js.map +1 -1
  49. package/dist/react/index.mcp.d.ts +1 -1
  50. package/dist/react/index.mcp.d.ts.map +1 -1
  51. package/dist/react/index.mcp.js +1 -1
  52. package/dist/react/index.mcp.js.map +1 -1
  53. package/dist/react/index.openai.d.ts +1 -1
  54. package/dist/react/index.openai.d.ts.map +1 -1
  55. package/dist/react/index.openai.js +1 -1
  56. package/dist/react/index.openai.js.map +1 -1
  57. package/dist/react/reactive.d.ts +9 -0
  58. package/dist/react/reactive.d.ts.map +1 -0
  59. package/dist/react/reactive.js +11 -0
  60. package/dist/react/reactive.js.map +1 -0
  61. package/dist/utilities/getToolNamesFromDocument.d.ts +3 -0
  62. package/dist/utilities/getToolNamesFromDocument.d.ts.map +1 -0
  63. package/dist/utilities/getToolNamesFromDocument.js +12 -0
  64. package/dist/utilities/getToolNamesFromDocument.js.map +1 -0
  65. package/dist/utilities/getVariableNamesFromDocument.d.ts +3 -0
  66. package/dist/utilities/getVariableNamesFromDocument.d.ts.map +1 -0
  67. package/dist/utilities/getVariableNamesFromDocument.js +6 -0
  68. package/dist/utilities/getVariableNamesFromDocument.js.map +1 -0
  69. package/dist/utilities/index.d.ts +3 -0
  70. package/dist/utilities/index.d.ts.map +1 -1
  71. package/dist/utilities/index.js +3 -0
  72. package/dist/utilities/index.js.map +1 -1
  73. package/dist/utilities/warnOnVariableMismatch.d.ts +3 -0
  74. package/dist/utilities/warnOnVariableMismatch.d.ts.map +1 -0
  75. package/dist/utilities/warnOnVariableMismatch.js +10 -0
  76. package/dist/utilities/warnOnVariableMismatch.js.map +1 -0
  77. package/package.json +2 -1
  78. package/src/core/ApolloClient.ts +1 -1
  79. package/src/core/types.ts +7 -0
  80. package/src/mcp/core/ApolloClient.ts +67 -2
  81. package/src/mcp/core/McpAppManager.ts +14 -5
  82. package/src/mcp/core/__tests__/ApolloClient.test.ts +109 -6
  83. package/src/mcp/link/__tests__/ToolCallLink.test.ts +13 -4
  84. package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +1228 -0
  85. package/src/mcp/react/hooks/createHydrationUtils.ts +182 -0
  86. package/src/mcp/react/index.ts +1 -0
  87. package/src/openai/core/ApolloClient.ts +68 -2
  88. package/src/openai/core/McpAppManager.ts +17 -20
  89. package/src/openai/core/__tests__/ApolloClient.test.ts +117 -11
  90. package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +1333 -0
  91. package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +1 -1
  92. package/src/openai/react/hooks/createHydrationUtils.ts +182 -0
  93. package/src/openai/react/index.ts +1 -0
  94. package/src/react/ApolloProvider.tsx +1 -1
  95. package/src/react/index.mcp.ts +1 -0
  96. package/src/react/index.openai.ts +1 -0
  97. package/src/react/index.ts +7 -0
  98. package/src/react/reactive.ts +19 -0
  99. package/src/testing/internal/mcp/graphqlToolResult.ts +5 -5
  100. package/src/utilities/getToolNamesFromDocument.ts +15 -0
  101. package/src/utilities/getVariableNamesFromDocument.ts +9 -0
  102. package/src/utilities/index.ts +3 -0
  103. package/src/utilities/warnOnVariableMismatch.ts +20 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ ## 0.5.3 (2026-02-26)
2
+
3
+ ### Features
4
+
5
+ #### Add `createHydrationUtils` factory and `reactive` helper
6
+
7
+ Adds a new `createHydrationUtils(query)` factory that returns a `useHydratedVariables` hook. This hook is used to populate `variables` from tool input to ensure the data returned by your query matches what the LLM returned.
8
+
9
+ ```typescript
10
+ import { createHydrationUtils, reactive } from "@apollo/client-ai-apps/react";
11
+
12
+ const MY_QUERY = gql`
13
+ query MyQuery($category: String!, $page: Int) @tool(name: "MyQuery") {
14
+ # ...
15
+ }
16
+ `;
17
+
18
+ const { useHydratedVariables } = createHydrationUtils(MY_QUERY);
19
+
20
+ function ProductPage({ id, category }: Props) {
21
+ const [variables, setVariables] = useHydratedVariables({
22
+ page: 1, // state: managed internally, seeded from tool input
23
+ sortBy: "title", // state: managed internally, seeded from tool input
24
+ id: reactive(props.id), // reactive: always follows props.id after hydration
25
+ category: reactive(props.category), // reactive: always follows props.category
26
+ });
27
+
28
+ const { data } = useQuery(MY_QUERY, { variables });
29
+ }
30
+ ```
31
+
32
+ ## 0.5.2 (2026-02-23)
33
+
34
+ ### Fixes
35
+
36
+ #### Add fallback when `toolName` is not available from host context
37
+
38
+ Provides a fallback in MCP apps to get the executed tool name from `_meta.toolName` when the host does not provide `toolInfo` from host context, or `structuredContent.toolName` when the host does not forward `_meta` to the connected application.
39
+
40
+ #### Always use `window.openai.toolInput` to initialize the tool input value
41
+
42
+ ChatGPT doesn't always send the `ui/notifications/tool-input` notification before we get `ui/notifications/tool-result`. Other times it sends the notification more than once. Because of the inconsistency, we can't always accurately get the correct tool input value using the notification by the time we get the `ui/notifications/tool-result` notification. This results in the wrong value for `variables` and incorrectly writes the query data to the cache.
43
+
44
+ This fix falls back to get `toolInput` from `window.openai.toolInput` in ChatGPT apps after we receive the `ui/notification/tool-result` notification to ensure we have the correct tool input value.
45
+
1
46
  ## 0.5.1 (2026-02-19)
2
47
 
3
48
  ### Fixes
@@ -11,6 +11,6 @@ export declare class ApolloClient extends BaseApolloClient {
11
11
  /** @internal */
12
12
  readonly [aiClientSymbol] = true;
13
13
  constructor(options: ApolloClient.Options);
14
- waitForInitialization(): Promise<void>;
14
+ connect(): Promise<void>;
15
15
  }
16
16
  //# sourceMappingURL=ApolloClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAQnC,qBAAqB;CAC5B"}
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAQnC,OAAO;CACd"}
@@ -7,6 +7,6 @@ export class ApolloClient extends BaseApolloClient {
7
7
  super(options);
8
8
  throw new Error("Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.");
9
9
  }
10
- async waitForInitialization() { }
10
+ async connect() { }
11
11
  }
12
12
  //# sourceMappingURL=ApolloClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAS3D,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAc,CAAC,CAAC;QAEtB,MAAM,IAAI,KAAK,CACb,qLAAqL,CACtL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,qBAAqB,KAAI,CAAC;CACjC","sourcesContent":["import { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { aiClientSymbol } from \"../utilities/constants.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n super(options as any);\n\n throw new Error(\n \"Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n\n async waitForInitialization() {}\n}\n"]}
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAS3D,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAc,CAAC,CAAC;QAEtB,MAAM,IAAI,KAAK,CACb,qLAAqL,CACtL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,KAAI,CAAC;CACnB","sourcesContent":["import { ApolloClient as BaseApolloClient } from \"@apollo/client\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { aiClientSymbol } from \"../utilities/constants.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n super(options as any);\n\n throw new Error(\n \"Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n\n async connect() {}\n}\n"]}
@@ -1,12 +1,18 @@
1
1
  import type { CallToolResult as McpCallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { FormattedExecutionResult } from "graphql";
3
3
  export declare namespace ApolloMcpServerApps {
4
+ interface Meta {
5
+ toolName: string;
6
+ [x: string]: unknown;
7
+ }
4
8
  interface StructuredContent {
5
9
  result: FormattedExecutionResult;
6
10
  prefetch?: Record<string, FormattedExecutionResult>;
11
+ toolName?: string;
7
12
  [x: string]: unknown;
8
13
  }
9
14
  interface CallToolResult extends McpCallToolResult {
15
+ _meta?: ApolloMcpServerApps.Meta;
10
16
  structuredContent: ApolloMcpServerApps.StructuredContent;
11
17
  }
12
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,iBAAiB;QAChC,MAAM,EAAE,wBAAwB,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,IAAI;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,iBAAiB;QAChC,MAAM,EAAE,wBAAwB,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,KAAK,CAAC,EAAE,mBAAmB,CAAC,IAAI,CAAC;QACjC,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface StructuredContent {\n result: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface Meta {\n toolName: string;\n [x: string]: unknown;\n }\n\n export interface StructuredContent {\n result: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n toolName?: string;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n _meta?: ApolloMcpServerApps.Meta;\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
+ import type { WatchQueryOptions, ObservableQuery, OperationVariables } from "@apollo/client";
2
3
  import type { ApplicationManifest } from "../../types/application-manifest.js";
3
4
  import { aiClientSymbol } from "../../utilities/index.js";
4
5
  export declare namespace ApolloClient {
@@ -8,13 +9,17 @@ export declare namespace ApolloClient {
8
9
  }
9
10
  }
10
11
  export declare class ApolloClient extends BaseApolloClient {
12
+ #private;
11
13
  manifest: ApplicationManifest;
12
14
  private readonly appManager;
13
15
  /** @internal */
14
16
  readonly [aiClientSymbol] = true;
15
17
  constructor(options: ApolloClient.Options);
16
18
  stop(): void;
17
- waitForInitialization: (() => Promise<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>) & {
18
23
  reset: () => void;
19
24
  };
20
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,IAAI,gBAAgB,EAEjC,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAGf,MAAM,0BAA0B,CAAC;AAGlC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;IAuBzC,IAAI;IAKJ,qBAAqB;;MAoBlB;CACJ"}
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,IAAI,gBAAgB,EAEjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAMf,MAAM,0BAA0B,CAAC;AAGlC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;;IAChD,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAIrB,OAAO,EAAE,YAAY,CAAC,OAAO;IAuBzC,IAAI;IAKJ,IAAI,SAAS,wCAEZ;IAED,cAAc;IAId,UAAU,CACR,CAAC,GAAG,GAAG,EACP,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,OAAO,EAAE,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;IAyC5E,OAAO;;MAsBJ;CACJ"}
@@ -1,15 +1,17 @@
1
1
  import { ApolloLink, ApolloClient as BaseApolloClient, DocumentTransform, } from "@apollo/client";
2
2
  import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
3
3
  import { parse } from "graphql";
4
+ import { equal } from "@wry/equality";
4
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
5
6
  import { ToolCallLink } from "../link/ToolCallLink.js";
6
- import { aiClientSymbol, cacheAsync, getVariablesForOperationFromToolInput, } from "../../utilities/index.js";
7
+ import { aiClientSymbol, cacheAsync, getToolNamesFromDocument, getVariableNamesFromDocument, getVariablesForOperationFromToolInput, warnOnVariableMismatch, } from "../../utilities/index.js";
7
8
  import { McpAppManager } from "./McpAppManager.js";
8
9
  export class ApolloClient extends BaseApolloClient {
9
10
  manifest;
10
11
  appManager;
11
12
  /** @internal */
12
13
  [aiClientSymbol] = true;
14
+ #toolInput;
13
15
  constructor(options) {
14
16
  const link = options.link ?? new ToolCallLink();
15
17
  if (__DEV__) {
@@ -30,8 +32,39 @@ export class ApolloClient extends BaseApolloClient {
30
32
  super.stop();
31
33
  this.appManager.close().catch(() => { });
32
34
  }
33
- waitForInitialization = cacheAsync(async () => {
34
- const { prefetch, result, toolName, args } = await this.appManager.waitForInitialization();
35
+ get toolInput() {
36
+ return this.#toolInput;
37
+ }
38
+ clearToolInput() {
39
+ this.#toolInput = undefined;
40
+ }
41
+ watchQuery(options) {
42
+ if (__DEV__) {
43
+ const toolInput = this.#toolInput;
44
+ if (toolInput) {
45
+ const toolName = this.appManager.toolName;
46
+ const hasMatchingTool = !!toolName && getToolNamesFromDocument(options.query).has(toolName);
47
+ if (hasMatchingTool) {
48
+ // Clear after first matching comparison so this only fires once and
49
+ // remounting doesn't produce spurious warnings.
50
+ this.#toolInput = undefined;
51
+ const variableNames = getVariableNamesFromDocument(options.query);
52
+ if (variableNames.size > 0) {
53
+ const { variables } = options;
54
+ const toolInputVariables = Object.entries(toolInput).filter(([key]) => variableNames.has(key));
55
+ const hasToolInputMismatch = toolInputVariables.some(([key, value]) => !equal(value, variables?.[key]));
56
+ if (hasToolInputMismatch) {
57
+ warnOnVariableMismatch(options.query, Object.fromEntries(toolInputVariables), variables);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ return super.watchQuery(options);
64
+ }
65
+ connect = cacheAsync(async () => {
66
+ const { prefetch, result, toolName, args } = await this.appManager.connect();
67
+ this.#toolInput = args;
35
68
  this.manifest.operations.forEach((operation) => {
36
69
  if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
37
70
  this.writeQuery({
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,gBAAgB,EAChC,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,UAAU,EACV,qCAAqC,GACtC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnD,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAChD,QAAQ,CAAsB;IACb,UAAU,CAAgB;IAE3C,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,YAAY,EAAE,CAAC;QAEhD,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,IAAI;YACJ,iGAAiG;YACjG,iBAAiB,EAAE,IAAI,iBAAiB,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACpD,OAAO,4BAA4B,CACjC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EACxC,QAAQ,CACR,CAAC;YACL,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB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AAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,uBAAuB,CAAC,IAAgB;IAC/C,IAAI,eAAe,GAAG,IAAI,CAAC;IAE3B,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,eAAe,GAAG,eAAe,CAAC,KAAK,CAAC;IAC1C,CAAC;IAED,IACE,CAAC,WAAW,CAAC,eAAe,CAAC;QAC7B,eAAe,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import {\n ApolloLink,\n ApolloClient as BaseApolloClient,\n DocumentTransform,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse } from \"graphql\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type { ApplicationManifest } from \"../../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n aiClientSymbol,\n cacheAsync,\n getVariablesForOperationFromToolInput,\n} from \"../../utilities/index.js\";\nimport { McpAppManager } from \"./McpAppManager.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link,\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest);\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n waitForInitialization = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.waitForInitialization();\n\n this.manifest.operations.forEach((operation) => {\n if (operation.prefetchID && prefetch?.[operation.prefetchID]) {\n this.writeQuery({\n query: parse(operation.body),\n data: prefetch[operation.prefetchID].data,\n });\n }\n\n if (operation.tools.find((tool) => tool.name === toolName)) {\n this.writeQuery({\n query: parse(operation.body),\n data: result.data,\n variables: getVariablesForOperationFromToolInput(operation, args),\n });\n }\n });\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
1
+ {"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,gBAAgB,EAChC,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,cA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,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import {\n ApolloLink,\n ApolloClient as BaseApolloClient,\n DocumentTransform,\n} from \"@apollo/client\";\nimport type {\n WatchQueryOptions,\n ObservableQuery,\n OperationVariables,\n} from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse } from \"graphql\";\nimport { equal } from \"@wry/equality\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type { ApplicationManifest } from \"../../types/application-manifest.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n aiClientSymbol,\n cacheAsync,\n getToolNamesFromDocument,\n getVariableNamesFromDocument,\n getVariablesForOperationFromToolInput,\n warnOnVariableMismatch,\n} from \"../../utilities/index.js\";\nimport { McpAppManager } from \"./McpAppManager.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends Omit<BaseApolloClient.Options, \"link\"> {\n link?: BaseApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class ApolloClient extends BaseApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n #toolInput: Record<string, unknown> | undefined;\n\n constructor(options: ApolloClient.Options) {\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link,\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest);\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n get toolInput() {\n return this.#toolInput;\n }\n\n clearToolInput() {\n this.#toolInput = undefined;\n }\n\n watchQuery<\n T = any,\n TVariables extends OperationVariables = OperationVariables,\n >(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {\n if (__DEV__) {\n const toolInput = this.#toolInput;\n\n if (toolInput) {\n const toolName = this.appManager.toolName;\n const hasMatchingTool =\n !!toolName && getToolNamesFromDocument(options.query).has(toolName);\n\n if (hasMatchingTool) {\n // Clear after first matching comparison so this only fires once and\n // remounting doesn't produce spurious warnings.\n this.#toolInput = undefined;\n\n const variableNames = getVariableNamesFromDocument(options.query);\n\n if (variableNames.size > 0) {\n const { variables } = options;\n const toolInputVariables = Object.entries(toolInput).filter(\n ([key]) => variableNames.has(key)\n );\n\n const hasToolInputMismatch = toolInputVariables.some(\n ([key, value]) => !equal(value, variables?.[key])\n );\n\n if (hasToolInputMismatch) {\n warnOnVariableMismatch(\n options.query,\n Object.fromEntries(toolInputVariables),\n variables\n );\n }\n }\n }\n }\n }\n\n return super.watchQuery(options);\n }\n\n connect = cacheAsync(async () => {\n const { prefetch, result, toolName, args } =\n await this.appManager.connect();\n\n this.#toolInput = args;\n\n this.manifest.operations.forEach((operation) => {\n if (operation.prefetchID && prefetch?.[operation.prefetchID]) {\n this.writeQuery({\n query: parse(operation.body),\n data: prefetch[operation.prefetchID].data,\n });\n }\n\n if (operation.tools.find((tool) => tool.name === toolName)) {\n this.writeQuery({\n query: parse(operation.body),\n data: result.data,\n variables: getVariablesForOperationFromToolInput(operation, args),\n });\n }\n });\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
@@ -2,21 +2,16 @@ import { App } from "@modelcontextprotocol/ext-apps";
2
2
  import type { ApplicationManifest } from "../../types/application-manifest";
3
3
  import type { FormattedExecutionResult } from "graphql";
4
4
  import type { DocumentNode, OperationVariables } from "@apollo/client";
5
+ import type { ApolloMcpServerApps } from "../../core/types";
5
6
  /** @internal */
6
7
  export declare class McpAppManager {
7
8
  #private;
8
9
  readonly app: App;
9
10
  constructor(manifest: ApplicationManifest);
10
11
  get toolName(): string | undefined;
11
- get toolMetadata(): {
12
- [x: string]: unknown;
13
- progressToken?: string | number | undefined;
14
- "io.modelcontextprotocol/related-task"?: {
15
- taskId: string;
16
- } | undefined;
17
- } | undefined;
12
+ get toolMetadata(): ApolloMcpServerApps.Meta | undefined;
18
13
  get toolInput(): Record<string, unknown> | undefined;
19
- waitForInitialization: (() => Promise<{
14
+ connect: (() => Promise<{
20
15
  toolName: string | undefined;
21
16
  args: Record<string, unknown> | undefined;
22
17
  result: FormattedExecutionResult;
@@ -29,6 +24,6 @@ export declare class McpAppManager {
29
24
  query: DocumentNode;
30
25
  variables: OperationVariables | undefined;
31
26
  }): Promise<FormattedExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
32
- private connect;
27
+ private connectToHost;
33
28
  }
34
29
  //# sourceMappingURL=McpAppManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,gCAAgC,CAAC;AAE3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO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AppManager {
19
19
  get toolInput() {
20
20
  return this.#toolInput;
21
21
  }
22
- waitForInitialization = cacheAsync(async () => {
22
+ connect = cacheAsync(async () => {
23
23
  let toolResult = promiseWithResolvers();
24
24
  let toolInput = promiseWithResolvers();
25
25
  this.app.ontoolresult = (params) => {
@@ -28,10 +28,19 @@ export class McpAppManager {
28
28
  this.app.ontoolinput = (params) => {
29
29
  toolInput.resolve(params);
30
30
  };
31
- await this.connect();
31
+ await this.connectToHost();
32
32
  const { structuredContent, _meta } = await toolResult.promise;
33
33
  const { arguments: args } = await toolInput.promise;
34
- this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;
34
+ // Some hosts do not provide toolInfo in the ui/initialize response, so we
35
+ // fallback to `_meta.toolName` provided by Apollo MCP server if the value
36
+ // is not available.
37
+ this.#toolName =
38
+ this.app.getHostContext()?.toolInfo?.tool.name ??
39
+ _meta?.toolName ??
40
+ // Some hosts do not forward `_meta` nor do they provide `toolInfo`. Our
41
+ // MCP server provides `toolName` in `structuredContent` as a workaround
42
+ // that we can use if all else fails
43
+ structuredContent.toolName;
35
44
  this.#toolMetadata = _meta;
36
45
  this.#toolInput = args;
37
46
  return {
@@ -50,7 +59,7 @@ export class McpAppManager {
50
59
  }));
51
60
  return result.structuredContent;
52
61
  }
53
- async connect() {
62
+ async connectToHost() {
54
63
  try {
55
64
  return await this.app.connect(new PostMessageTransport(window.parent, window.parent));
56
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAK3E,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAOnE,gBAAgB;AAChB,MAAM,OAAO,aAAa;IACf,GAAG,CAAM;IAElB,SAAS,CAAq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O;YACL,GAAG,iBAAiB;YACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI;SACL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GAIV;QACC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;YAC5C,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE;SAC9C,CAAC,CAA+B,CAAC;QAElC,OAAO,MAAM,CAAC,iBAAiB,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAC3B,IAAI,oBAAoB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CACvD,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAEtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import { App, PostMessageTransport } 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};\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #toolName: string | undefined;\n #toolMetadata: ApolloMcpServerApps.CallToolResult[\"_meta\"];\n #toolInput: Record<string, unknown> | undefined;\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 waitForInitialization = 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 await this.connect();\n\n const { structuredContent, _meta } = await toolResult.promise;\n const { arguments: args } = await toolInput.promise;\n\n this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;\n this.#toolMetadata = _meta;\n this.#toolInput = args;\n\n return {\n ...structuredContent,\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 result.structuredContent;\n }\n\n private async connect() {\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
+ {"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/mcp/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAK3E,OAAO,EAAE,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@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};\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 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 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 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 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 result.structuredContent;\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"]}
@@ -0,0 +1,15 @@
1
+ import type { DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
2
+ import type { Reactive } from "../../../react/reactive.js";
3
+ type HydratedVariablesInput<TVariables> = {
4
+ [K in keyof TVariables]: TVariables[K] | Reactive<TVariables[K]>;
5
+ };
6
+ type StateVariables<TVariables, Input> = {
7
+ [K in keyof TVariables as K extends keyof Input ? Input[K] extends Reactive<any> ? never : K : K]: K extends keyof TVariables ? TVariables[K] : never;
8
+ };
9
+ type SetVariables<TState> = (update: Partial<TState> | ((prev: TState) => Partial<TState>)) => void;
10
+ /** @experimental */
11
+ export declare function createHydrationUtils<TVariables extends OperationVariables = OperationVariables>(document: TypedDocumentNode<any, TVariables> | DocumentNode): {
12
+ useHydratedVariables: <TInputVariables extends HydratedVariablesInput<TVariables>>(variables: TInputVariables & Record<Exclude<keyof TInputVariables, keyof TVariables>, never>) => [variables: TVariables, setVariables: SetVariables<StateVariables<TVariables, TInputVariables>>];
13
+ };
14
+ export {};
15
+ //# sourceMappingURL=createHydrationUtils.d.ts.map
@@ -0,0 +1 @@
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,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;EAqIF"}
@@ -0,0 +1,113 @@
1
+ import { useState, useCallback, useRef, useMemo, useLayoutEffect } from "react";
2
+ import { useApolloClient } from "./useApolloClient.js";
3
+ import { useToolName } from "./useToolName.js";
4
+ import { isReactive } from "../../../react/reactive.js";
5
+ import { equal } from "@wry/equality";
6
+ import { __DEV__ } from "@apollo/client/utilities/environment";
7
+ import { getToolNamesFromDocument, getVariableNamesFromDocument, } from "../../../utilities/index.js";
8
+ /** @experimental */
9
+ export function createHydrationUtils(document) {
10
+ const documentToolNames = getToolNamesFromDocument(document);
11
+ const variableNames = getVariableNamesFromDocument(document);
12
+ function useHydratedVariables(variables) {
13
+ const client = useApolloClient();
14
+ const toolName = useToolName();
15
+ const [toolInput] = useState(() => client.toolInput);
16
+ const toolMatches = toolInput !== undefined &&
17
+ toolName !== undefined &&
18
+ documentToolNames.has(toolName);
19
+ const [stateVars, setStateVars] = useState(() => {
20
+ const values = {};
21
+ for (const [key, value] of Object.entries(toolMatches ? toolInput : variables)) {
22
+ if (variableNames.has(key) && !isReactive(value)) {
23
+ values[key] = value;
24
+ }
25
+ }
26
+ return values;
27
+ });
28
+ const [initialReactiveVars] = useState(() => {
29
+ const values = {};
30
+ for (const [key, value] of Object.entries(variables)) {
31
+ if (variableNames.has(key) && isReactive(value)) {
32
+ values[key] = value.value;
33
+ }
34
+ }
35
+ return values;
36
+ });
37
+ const [reactiveVars, setReactiveVars] = useState(() => {
38
+ const values = {};
39
+ for (const [key, value] of Object.entries(initialReactiveVars)) {
40
+ if (toolMatches && key in toolInput) {
41
+ values[key] = toolInput[key];
42
+ }
43
+ else if (!toolMatches) {
44
+ values[key] = value;
45
+ }
46
+ }
47
+ return values;
48
+ });
49
+ const changedKeysRef = useRef(new Set());
50
+ const nextReactiveVars = {};
51
+ for (const [key, value] of Object.entries(variables)) {
52
+ if (!variableNames.has(key) || !isReactive(value))
53
+ continue;
54
+ const hasChanged = changedKeysRef.current.has(key) ||
55
+ !equal(value.value, initialReactiveVars[key]);
56
+ if (toolMatches && !hasChanged) {
57
+ if (key in toolInput) {
58
+ nextReactiveVars[key] = toolInput[key];
59
+ }
60
+ }
61
+ else {
62
+ nextReactiveVars[key] = value.value;
63
+ }
64
+ }
65
+ if (!equal(nextReactiveVars, reactiveVars)) {
66
+ setReactiveVars(nextReactiveVars);
67
+ }
68
+ // Clear the tool input after first mount so that remounting the component
69
+ // uses the user-provided variables rather than the hydrated tool input.
70
+ // This runs once on mount; watchQuery also clears it when useQuery is
71
+ // present, so both paths are idempotent.
72
+ useLayoutEffect(() => {
73
+ if (toolMatches) {
74
+ client.clearToolInput();
75
+ }
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
+ }, []);
78
+ useLayoutEffect(() => {
79
+ for (const [key, value] of Object.entries(variables)) {
80
+ if (variableNames.has(key) &&
81
+ isReactive(value) &&
82
+ !changedKeysRef.current.has(key) &&
83
+ !equal(value.value, initialReactiveVars[key])) {
84
+ changedKeysRef.current.add(key);
85
+ }
86
+ }
87
+ });
88
+ const resolvedVariables = useMemo(() => {
89
+ return { ...stateVars, ...reactiveVars };
90
+ }, [stateVars, reactiveVars]);
91
+ const setVariables = useCallback((update) => {
92
+ setStateVars((prev) => {
93
+ const updates = typeof update === "function" ? update(prev) : update;
94
+ const filtered = Object.fromEntries(Object.entries(updates).filter(([key]) => {
95
+ if (key in initialReactiveVars) {
96
+ if (__DEV__) {
97
+ console.warn(`Attempted to set reactive variable "${key}" via setVariables. ` +
98
+ `Reactive variables are read-only and are ignored. `);
99
+ }
100
+ return false;
101
+ }
102
+ return true;
103
+ }));
104
+ if (Object.keys(filtered).length === 0)
105
+ return prev;
106
+ return { ...prev, ...filtered };
107
+ });
108
+ }, []);
109
+ return [resolvedVariables, setVariables];
110
+ }
111
+ return { useHydratedVariables };
112
+ }
113
+ //# sourceMappingURL=createHydrationUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHydrationUtils.js","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/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,sBAAsB,CAAC;AAC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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,8 +1,2 @@
1
- export declare function useToolMetadata(): {
2
- [x: string]: unknown;
3
- progressToken?: string | number | undefined;
4
- "io.modelcontextprotocol/related-task"?: {
5
- taskId: string;
6
- } | undefined;
7
- } | undefined;
1
+ export declare function useToolMetadata(): import("../../../core/types.js").ApolloMcpServerApps.Meta | undefined;
8
2
  //# sourceMappingURL=useToolMetadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;;;cAE9B"}
1
+ {"version":3,"file":"useToolMetadata.d.ts","sourceRoot":"","sources":["../../../../src/mcp/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,0EAE9B"}
@@ -2,4 +2,5 @@ export { useApp } from "./hooks/useApp.js";
2
2
  export { useToolName } from "./hooks/useToolName.js";
3
3
  export { useToolMetadata } from "./hooks/useToolMetadata.js";
4
4
  export { useToolInput } from "./hooks/useToolInput.js";
5
+ export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
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,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -2,4 +2,5 @@ export { useApp } from "./hooks/useApp.js";
2
2
  export { useToolName } from "./hooks/useToolName.js";
3
3
  export { useToolMetadata } from "./hooks/useToolMetadata.js";
4
4
  export { useToolInput } from "./hooks/useToolInput.js";
5
+ export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { useApp } from \"./hooks/useApp.js\";\nexport { useToolName } from \"./hooks/useToolName.js\";\nexport { useToolMetadata } from \"./hooks/useToolMetadata.js\";\nexport { useToolInput } from \"./hooks/useToolInput.js\";\n"]}
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,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export { useApp } from \"./hooks/useApp.js\";\nexport { useToolName } from \"./hooks/useToolName.js\";\nexport { useToolMetadata } from \"./hooks/useToolMetadata.js\";\nexport { useToolInput } from \"./hooks/useToolInput.js\";\nexport { createHydrationUtils } from \"./hooks/createHydrationUtils.js\";\n"]}
@@ -1,4 +1,5 @@
1
1
  import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
+ import type { WatchQueryOptions, ObservableQuery, OperationVariables } from "@apollo/client";
2
3
  import type { ApplicationManifest } from "../../types/application-manifest.js";
3
4
  import { aiClientSymbol } from "../../utilities/index.js";
4
5
  export declare namespace ApolloClient {
@@ -8,13 +9,17 @@ export declare namespace ApolloClient {
8
9
  }
9
10
  }
10
11
  export declare class ApolloClient extends BaseApolloClient {
12
+ #private;
11
13
  manifest: ApplicationManifest;
12
14
  private readonly appManager;
13
15
  /** @internal */
14
16
  readonly [aiClientSymbol] = true;
15
17
  constructor(options: ApolloClient.Options);
16
18
  stop(): void;
17
- waitForInitialization: (() => Promise<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>) & {
18
23
  reset: () => void;
19
24
  };
20
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/openai/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAGf,MAAM,0BAA0B,CAAC;AAG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