@apollo/client-ai-apps 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +100 -0
- package/CONTRIBUTING.md +195 -0
- package/README.md +74 -0
- package/dist/core/AbstractApolloClient.d.ts +33 -0
- package/dist/core/AbstractApolloClient.d.ts.map +1 -0
- package/dist/core/AbstractApolloClient.js +129 -0
- package/dist/core/AbstractApolloClient.js.map +1 -0
- package/dist/core/ApolloClient.d.ts +3 -7
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +5 -4
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/core/McpAppManager.d.ts +42 -0
- package/dist/core/McpAppManager.d.ts.map +1 -0
- package/dist/core/McpAppManager.js +56 -0
- package/dist/core/McpAppManager.js.map +1 -0
- package/dist/core/typeRegistration.d.ts +0 -14
- package/dist/core/typeRegistration.d.ts.map +1 -1
- package/dist/core/typeRegistration.js.map +1 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mcp.d.ts +0 -1
- package/dist/index.mcp.d.ts.map +1 -1
- package/dist/index.mcp.js +0 -1
- package/dist/index.mcp.js.map +1 -1
- package/dist/index.openai.d.ts +0 -1
- package/dist/index.openai.d.ts.map +1 -1
- package/dist/index.openai.js +0 -1
- package/dist/index.openai.js.map +1 -1
- package/dist/link/ToolCallLink.d.ts +6 -1
- package/dist/link/ToolCallLink.d.ts.map +1 -1
- package/dist/link/ToolCallLink.js +17 -4
- package/dist/link/ToolCallLink.js.map +1 -1
- package/dist/link/ToolHydrationLink.d.ts +21 -0
- package/dist/link/ToolHydrationLink.d.ts.map +1 -0
- package/dist/link/ToolHydrationLink.js +57 -0
- package/dist/link/ToolHydrationLink.js.map +1 -0
- package/dist/mcp/core/ApolloClient.d.ts +3 -20
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
- package/dist/mcp/core/ApolloClient.js +20 -98
- package/dist/mcp/core/ApolloClient.js.map +1 -1
- package/dist/mcp/index.d.ts +0 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +0 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/openai/core/ApolloClient.d.ts +3 -20
- package/dist/openai/core/ApolloClient.d.ts.map +1 -1
- package/dist/openai/core/ApolloClient.js +36 -98
- package/dist/openai/core/ApolloClient.js.map +1 -1
- package/dist/openai/index.d.ts +0 -1
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/openai/index.js +0 -1
- package/dist/openai/index.js.map +1 -1
- package/dist/openai/react/index.d.ts +0 -7
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +0 -7
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/ApolloProvider.d.ts.map +1 -1
- package/dist/react/ApolloProvider.js +1 -1
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.d.ts +1 -1
- package/dist/react/createHydrationUtils.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.js +7 -9
- package/dist/react/createHydrationUtils.js.map +1 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts +3 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react/hooks/internal}/useApolloClient.js +3 -3
- package/dist/react/hooks/internal/useApolloClient.js.map +1 -0
- package/dist/react/hooks/useApp.d.ts.map +1 -0
- package/dist/react/hooks/useApp.js +5 -0
- package/dist/react/hooks/useApp.js.map +1 -0
- package/dist/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/{openai/react → react}/hooks/useHostContext.js +1 -1
- package/dist/react/hooks/useHostContext.js.map +1 -0
- package/dist/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/react/hooks/useToolInfo.js +5 -0
- package/dist/react/hooks/useToolInfo.js.map +1 -0
- package/dist/react/hooks/useToolMetadata.d.ts +2 -0
- package/dist/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/react/hooks/useToolMetadata.js +5 -0
- package/dist/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/react/index.d.ts +5 -16
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -19
- package/dist/react/index.js.map +1 -1
- package/dist/types/application-manifest.d.ts +1 -0
- package/dist/types/application-manifest.d.ts.map +1 -1
- package/dist/types/application-manifest.js.map +1 -1
- package/dist/utilities/connectToHost.d.ts +3 -0
- package/dist/utilities/connectToHost.d.ts.map +1 -0
- package/dist/utilities/connectToHost.js +11 -0
- package/dist/utilities/connectToHost.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +2 -0
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/package.json +5 -22
- package/src/core/AbstractApolloClient.ts +217 -0
- package/src/core/ApolloClient.ts +8 -10
- package/src/core/McpAppManager.ts +106 -0
- package/src/core/typeRegistration.ts +0 -15
- package/src/core/types.ts +2 -1
- package/src/index.mcp.ts +0 -1
- package/src/index.openai.ts +0 -1
- package/src/index.ts +1 -6
- package/src/link/ToolCallLink.ts +27 -5
- package/src/link/ToolHydrationLink.ts +90 -0
- package/src/link/__tests__/ToolCallLink.test.ts +99 -0
- package/src/mcp/core/ApolloClient.ts +32 -165
- package/src/mcp/core/__tests__/ApolloClient.test.ts +571 -71
- package/src/mcp/index.ts +0 -1
- package/src/openai/core/ApolloClient.ts +48 -161
- package/src/openai/core/__tests__/ApolloClient.test.ts +916 -118
- package/src/openai/index.ts +0 -1
- package/src/openai/react/index.ts +0 -7
- package/src/react/ApolloProvider.tsx +1 -6
- package/src/react/__tests__/ApolloProvider/mcp.test.tsx +66 -29
- package/src/react/__tests__/ApolloProvider/openai.test.tsx +16 -41
- package/src/react/__tests__/createHydrationUtils.test.tsx +1260 -0
- package/src/{mcp/react/hooks → react}/createHydrationUtils.ts +7 -10
- package/src/react/hooks/__tests__/useApp.test.tsx +46 -0
- package/src/react/hooks/__tests__/useHostContext.test.tsx +99 -0
- package/src/react/hooks/__tests__/useToolInfo.test.tsx +98 -0
- package/src/react/hooks/__tests__/useToolMetadata.test.tsx +58 -0
- package/src/{mcp/react/hooks → react/hooks/internal}/useApolloClient.ts +3 -3
- package/src/{mcp/react → react}/hooks/useApp.ts +1 -1
- package/src/{openai/react → react}/hooks/useHostContext.ts +1 -1
- package/src/react/hooks/useToolInfo.ts +6 -0
- package/src/react/hooks/useToolMetadata.ts +5 -0
- package/src/react/index.ts +5 -36
- package/src/testing/internal/graphql/parseManifestOperation.ts +87 -0
- package/src/testing/internal/index.ts +3 -0
- package/src/testing/internal/matchers/index.ts +1 -0
- package/src/testing/internal/matchers/toEmitAnything.ts +43 -0
- package/src/testing/internal/matchers/types.ts +1 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +25 -4
- package/src/testing/internal/tests/eachHostEnv.ts +22 -0
- package/src/testing/internal/utilities/createHostEnv.ts +117 -0
- package/src/types/application-manifest.ts +1 -0
- package/src/utilities/connectToHost.ts +13 -0
- package/src/utilities/index.ts +1 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +56 -0
- package/src/vite/apolloClientAiApps.ts +5 -0
- package/tsconfig.vite.json +1 -1
- package/vitest.config.ts +13 -0
- package/dist/mcp/core/McpAppManager.d.ts +0 -30
- package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
- package/dist/mcp/core/McpAppManager.js +0 -82
- package/dist/mcp/core/McpAppManager.js.map +0 -1
- package/dist/mcp/link/ToolCallLink.d.ts +0 -28
- package/dist/mcp/link/ToolCallLink.d.ts.map +0 -1
- package/dist/mcp/link/ToolCallLink.js +0 -35
- package/dist/mcp/link/ToolCallLink.js.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.d.ts +0 -3
- package/dist/mcp/react/hooks/useApolloClient.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.js.map +0 -1
- package/dist/mcp/react/hooks/useApp.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApp.js +0 -5
- package/dist/mcp/react/hooks/useApp.js.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.js +0 -7
- package/dist/mcp/react/hooks/useHostContext.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/mcp/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.js +0 -10
- package/dist/mcp/react/hooks/useToolInfo.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.js +0 -9
- package/dist/mcp/react/hooks/useToolInput.js.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.js +0 -5
- package/dist/mcp/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/mcp/react/hooks/useToolName.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolName.js +0 -9
- package/dist/mcp/react/hooks/useToolName.js.map +0 -1
- package/dist/mcp/react/index.d.ts +0 -8
- package/dist/mcp/react/index.d.ts.map +0 -1
- package/dist/mcp/react/index.js +0 -8
- package/dist/mcp/react/index.js.map +0 -1
- package/dist/openai/core/McpAppManager.d.ts +0 -29
- package/dist/openai/core/McpAppManager.d.ts.map +0 -1
- package/dist/openai/core/McpAppManager.js +0 -91
- package/dist/openai/core/McpAppManager.js.map +0 -1
- package/dist/openai/link/ToolCallLink.d.ts +0 -28
- package/dist/openai/link/ToolCallLink.d.ts.map +0 -1
- package/dist/openai/link/ToolCallLink.js +0 -35
- package/dist/openai/link/ToolCallLink.js.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.d.ts +0 -15
- package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.js +0 -113
- package/dist/openai/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/openai/react/hooks/useApp.d.ts +0 -2
- package/dist/openai/react/hooks/useApp.d.ts.map +0 -1
- package/dist/openai/react/hooks/useApp.js +0 -5
- package/dist/openai/react/hooks/useApp.js.map +0 -1
- package/dist/openai/react/hooks/useHostContext.d.ts +0 -2
- package/dist/openai/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/openai/react/hooks/useHostContext.js.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/openai/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.js +0 -10
- package/dist/openai/react/hooks/useToolInfo.js.map +0 -1
- package/dist/openai/react/hooks/useToolInput.d.ts +0 -7
- package/dist/openai/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInput.js +0 -9
- package/dist/openai/react/hooks/useToolInput.js.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/openai/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.js +0 -5
- package/dist/openai/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/openai/react/hooks/useToolName.d.ts +0 -7
- package/dist/openai/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolName.js +0 -9
- package/dist/openai/react/hooks/useToolName.js.map +0 -1
- package/dist/react/index.mcp.d.ts +0 -3
- package/dist/react/index.mcp.d.ts.map +0 -1
- package/dist/react/index.mcp.js +0 -3
- package/dist/react/index.mcp.js.map +0 -1
- package/dist/react/index.openai.d.ts +0 -3
- package/dist/react/index.openai.d.ts.map +0 -1
- package/dist/react/index.openai.js +0 -3
- package/dist/react/index.openai.js.map +0 -1
- package/dist/react/missingHook.d.ts +0 -2
- package/dist/react/missingHook.d.ts.map +0 -1
- package/dist/react/missingHook.js +0 -6
- package/dist/react/missingHook.js.map +0 -1
- package/src/mcp/core/McpAppManager.ts +0 -129
- package/src/mcp/link/ToolCallLink.ts +0 -40
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -62
- package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1228
- package/src/mcp/react/hooks/__tests__/useApp.test.tsx +0 -46
- package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +0 -95
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +0 -50
- package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/mcp/react/hooks/useHostContext.ts +0 -14
- package/src/mcp/react/hooks/useToolInfo.ts +0 -13
- package/src/mcp/react/hooks/useToolInput.ts +0 -10
- package/src/mcp/react/hooks/useToolMetadata.ts +0 -5
- package/src/mcp/react/hooks/useToolName.ts +0 -10
- package/src/mcp/react/index.ts +0 -7
- package/src/openai/core/McpAppManager.ts +0 -139
- package/src/openai/link/ToolCallLink.ts +0 -40
- package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1333
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +0 -92
- package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +0 -85
- package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +0 -86
- package/src/openai/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/openai/react/hooks/createHydrationUtils.ts +0 -182
- package/src/openai/react/hooks/useApp.ts +0 -5
- package/src/openai/react/hooks/useToolInfo.ts +0 -13
- package/src/openai/react/hooks/useToolInput.ts +0 -10
- package/src/openai/react/hooks/useToolMetadata.ts +0 -5
- package/src/openai/react/hooks/useToolName.ts +0 -10
- package/src/react/index.mcp.ts +0 -10
- package/src/react/index.openai.ts +0 -10
- package/src/react/missingHook.ts +0 -9
- /package/dist/{mcp/react → react}/hooks/useApp.d.ts +0 -0
- /package/dist/{mcp/react → react}/hooks/useHostContext.d.ts +0 -0
|
@@ -1 +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,29 +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
|
-
toolName: string | undefined;
|
|
16
|
-
args: Record<string, unknown> | undefined;
|
|
17
|
-
result: FormattedExecutionResult;
|
|
18
|
-
prefetch?: Record<string, FormattedExecutionResult>;
|
|
19
|
-
}>) & {
|
|
20
|
-
reset: () => void;
|
|
21
|
-
};
|
|
22
|
-
close(): Promise<void>;
|
|
23
|
-
executeQuery({ query, variables, }: {
|
|
24
|
-
query: DocumentNode;
|
|
25
|
-
variables: OperationVariables | undefined;
|
|
26
|
-
}): Promise<FormattedExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
|
|
27
|
-
private connectToHost;
|
|
28
|
-
}
|
|
29
|
-
//# 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;AASvE,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;;;;;;;MAoDJ;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;YASa,aAAa;CAW5B"}
|
|
@@ -1,91 +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 = null;
|
|
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
|
-
this.app.ontoolresult = (params) => {
|
|
32
|
-
toolResult.resolve(params);
|
|
33
|
-
};
|
|
34
|
-
this.app.onhostcontextchanged = (params) => {
|
|
35
|
-
this.#hostContextCallbacks.forEach((cb) => cb(params));
|
|
36
|
-
};
|
|
37
|
-
await this.connectToHost();
|
|
38
|
-
// After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.
|
|
39
|
-
// Instead, the tool result is available immediately via `window.openai.toolOutput`.
|
|
40
|
-
// If it's already set, resolve the promise now rather than waiting for the
|
|
41
|
-
// notification that will never arrive.
|
|
42
|
-
if (window.openai.toolOutput !== null) {
|
|
43
|
-
toolResult.resolve({
|
|
44
|
-
structuredContent: window.openai.toolOutput,
|
|
45
|
-
content: [],
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const { structuredContent } = await toolResult.promise;
|
|
49
|
-
this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;
|
|
50
|
-
// OpenAI is not consistent about sending `ui/notifications/tool-input`.
|
|
51
|
-
// Sometimes it doesn't send at all, other times it sends more than once
|
|
52
|
-
// before we get the tool result (which should always happen and at most
|
|
53
|
-
// once according to the spec). Rather than relying on the
|
|
54
|
-
// `ui/notifications/tool-input` notification to set the tool input value,
|
|
55
|
-
// we read from `window.openai.toolInput so that we have the most recent
|
|
56
|
-
// set value.
|
|
57
|
-
//
|
|
58
|
-
// When OpenAI fixes this issue and sends `ui/notifications/tool-input`
|
|
59
|
-
// consistently according to the MCP Apps specification, this can be
|
|
60
|
-
// reverted to use the `app.ontoolinput` callback.
|
|
61
|
-
this.#toolInput = window.openai.toolInput;
|
|
62
|
-
// OpenAI doesn't provide access to `_meta`, so we need to use
|
|
63
|
-
// window.openai.toolResponseMetadata directly
|
|
64
|
-
this.#toolMetadata = window.openai.toolResponseMetadata;
|
|
65
|
-
return {
|
|
66
|
-
...structuredContent,
|
|
67
|
-
toolName: this.toolName,
|
|
68
|
-
args: this.toolInput,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
close() {
|
|
72
|
-
return this.app.close();
|
|
73
|
-
}
|
|
74
|
-
async executeQuery({ query, variables, }) {
|
|
75
|
-
const result = (await this.app.callServerTool({
|
|
76
|
-
name: "execute",
|
|
77
|
-
arguments: { query: print(query), variables },
|
|
78
|
-
}));
|
|
79
|
-
return result.structuredContent;
|
|
80
|
-
}
|
|
81
|
-
async connectToHost() {
|
|
82
|
-
try {
|
|
83
|
-
return await this.app.connect(new PostMessageTransport(window.parent, window.parent));
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
const error = e instanceof Error ? e : new Error("Failed to connect");
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=McpAppManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../../src/openai/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;AAOnE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MAAM,CAAC,iBAAiB,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,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 {\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};\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #toolName: string | undefined;\n #toolMetadata: Record<string, unknown> | null = null;\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 return () => {\n this.#hostContextCallbacks.delete(cb);\n };\n }\n\n connect = cacheAsync(async () => {\n let toolResult = promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();\n\n this.app.ontoolresult = (params) => {\n toolResult.resolve(\n params as unknown as ApolloMcpServerApps.CallToolResult\n );\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.#hostContextCallbacks.forEach((cb) => cb(params));\n };\n\n await this.connectToHost();\n\n // After a page refresh, OpenAI does not re-send `ui/notifications/tool-result`.\n // Instead, the tool result is available immediately via `window.openai.toolOutput`.\n // If it's already set, resolve the promise now rather than waiting for the\n // notification that will never arrive.\n if (window.openai.toolOutput !== null) {\n toolResult.resolve({\n structuredContent: window.openai.toolOutput,\n content: [],\n });\n }\n\n const { structuredContent } = await toolResult.promise;\n\n this.#toolName = this.app.getHostContext()?.toolInfo?.tool.name;\n\n // OpenAI is not consistent about sending `ui/notifications/tool-input`.\n // Sometimes it doesn't send at all, other times it sends more than once\n // before we get the tool result (which should always happen and at most\n // once according to the spec). Rather than relying on the\n // `ui/notifications/tool-input` notification to set the tool input value,\n // we read from `window.openai.toolInput so that we have the most recent\n // set value.\n //\n // When OpenAI fixes this issue and sends `ui/notifications/tool-input`\n // consistently according to the MCP Apps specification, this can be\n // reverted to use the `app.ontoolinput` callback.\n this.#toolInput = window.openai.toolInput;\n\n // OpenAI doesn't provide access to `_meta`, so we need to use\n // window.openai.toolResponseMetadata directly\n this.#toolMetadata = window.openai.toolResponseMetadata;\n\n return {\n ...structuredContent,\n toolName: this.toolName,\n args: this.toolInput,\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"]}
|
|
@@ -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/openai/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/openai/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,MAA4B,CAAC;QAEtD,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 OpenAiApolloClient } 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 OpenAiApolloClient;\n\n return from(\n client[\"appManager\"].executeQuery({\n query: operation.query,\n variables: operation.variables,\n })\n );\n }\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHydrationUtils.d.ts","sourceRoot":"","sources":["../../../../src/openai/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"}
|
|
@@ -1,113 +0,0 @@
|
|
|
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 [initialReactiveValues] = 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(initialReactiveValues)) {
|
|
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, initialReactiveValues[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, initialReactiveValues[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 initialReactiveValues) {
|
|
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
|
|
@@ -1 +0,0 @@
|
|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pD,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 [initialReactiveValues] = 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(initialReactiveValues)) {\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, initialReactiveValues[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, initialReactiveValues[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 initialReactiveValues) {\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":"useApp.d.ts","sourceRoot":"","sources":["../../../../src/openai/react/hooks/useApp.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,iDAErB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useApp.js","sourceRoot":"","sources":["../../../../src/openai/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/openai/react/hooks/useHostContext.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,0EAU7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHostContext.js","sourceRoot":"","sources":["../../../../src/openai/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/openai/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/openai/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/openai/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/openai/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/openai/react/hooks/useToolMetadata.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,mCAE9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolMetadata.js","sourceRoot":"","sources":["../../../../src/openai/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 const useToolName: () => ToolName | undefined;
|
|
7
|
-
//# sourceMappingURL=useToolName.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolName.d.ts","sourceRoot":"","sources":["../../../../src/openai/react/hooks/useToolName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAGlE;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAO,QAAQ,GAAG,SAEzC,CAAC"}
|
|
@@ -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 const useToolName = () => {
|
|
7
|
-
return useApolloClient()["appManager"].toolName;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=useToolName.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToolName.js","sourceRoot":"","sources":["../../../../src/openai/react/hooks/useToolName.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAyB,EAAE;IACpD,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC,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 const useToolName = (): ToolName | undefined => {\n return useApolloClient()[\"appManager\"].toolName;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mcp.d.ts","sourceRoot":"","sources":["../../src/react/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,MAAM,EACN,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,WAAW,GACZ,MAAM,uBAAuB,CAAC"}
|
package/dist/react/index.mcp.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mcp.js","sourceRoot":"","sources":["../../src/react/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,MAAM,EACN,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,WAAW,GACZ,MAAM,uBAAuB,CAAC","sourcesContent":["export * from \"./index.js\";\nexport {\n useApp,\n useHostContext,\n useToolInput,\n useToolInfo,\n createHydrationUtils,\n useToolMetadata,\n useToolName,\n} from \"../mcp/react/index.js\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.openai.d.ts","sourceRoot":"","sources":["../../src/react/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,MAAM,EACN,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,WAAW,GACZ,MAAM,0BAA0B,CAAC"}
|