@apollo/client-ai-apps 0.5.4 → 0.6.1
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 +180 -0
- package/dist/config/defineConfig.d.ts +1 -0
- package/dist/config/defineConfig.d.ts.map +1 -1
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/core/typeRegistration.d.ts +33 -0
- package/dist/core/typeRegistration.d.ts.map +1 -0
- package/dist/core/typeRegistration.js +2 -0
- package/dist/core/typeRegistration.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/core/McpAppManager.d.ts +2 -1
- package/dist/mcp/core/McpAppManager.d.ts.map +1 -1
- package/dist/mcp/core/McpAppManager.js +11 -1
- package/dist/mcp/core/McpAppManager.js.map +1 -1
- package/dist/mcp/react/hooks/useHostContext.d.ts +2 -0
- package/dist/mcp/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useHostContext.js +7 -0
- package/dist/mcp/react/hooks/useHostContext.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/mcp/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolInfo.js +10 -0
- package/dist/mcp/react/hooks/useToolInfo.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts +6 -1
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -1
- package/dist/mcp/react/hooks/useToolInput.js +4 -0
- package/dist/mcp/react/hooks/useToolInput.js.map +1 -1
- package/dist/mcp/react/hooks/useToolName.d.ts +6 -1
- package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -1
- package/dist/mcp/react/hooks/useToolName.js +4 -0
- package/dist/mcp/react/hooks/useToolName.js.map +1 -1
- package/dist/mcp/react/index.d.ts +2 -0
- package/dist/mcp/react/index.d.ts.map +1 -1
- package/dist/mcp/react/index.js +2 -0
- package/dist/mcp/react/index.js.map +1 -1
- package/dist/openai/core/McpAppManager.d.ts +2 -1
- package/dist/openai/core/McpAppManager.d.ts.map +1 -1
- package/dist/openai/core/McpAppManager.js +11 -1
- package/dist/openai/core/McpAppManager.js.map +1 -1
- package/dist/openai/react/hooks/useHostContext.d.ts +2 -0
- package/dist/openai/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/openai/react/hooks/useHostContext.js +7 -0
- package/dist/openai/react/hooks/useHostContext.js.map +1 -0
- package/dist/openai/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/openai/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolInfo.js +10 -0
- package/dist/openai/react/hooks/useToolInfo.js.map +1 -0
- package/dist/openai/react/hooks/useToolInput.d.ts +6 -1
- package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -1
- package/dist/openai/react/hooks/useToolInput.js +4 -0
- package/dist/openai/react/hooks/useToolInput.js.map +1 -1
- package/dist/openai/react/hooks/useToolName.d.ts +6 -1
- package/dist/openai/react/hooks/useToolName.d.ts.map +1 -1
- package/dist/openai/react/hooks/useToolName.js +4 -0
- package/dist/openai/react/hooks/useToolName.js.map +1 -1
- package/dist/openai/react/index.d.ts +2 -0
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +2 -0
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mcp.d.ts +1 -1
- package/dist/react/index.mcp.d.ts.map +1 -1
- package/dist/react/index.mcp.js +1 -1
- package/dist/react/index.mcp.js.map +1 -1
- package/dist/react/index.openai.d.ts +1 -1
- package/dist/react/index.openai.d.ts.map +1 -1
- package/dist/react/index.openai.js +1 -1
- package/dist/react/index.openai.js.map +1 -1
- package/dist/tsconfig/core/tsconfig.json +2 -0
- package/dist/tsconfig/mcp/tsconfig.json +2 -0
- package/dist/tsconfig/openai/tsconfig.json +2 -0
- 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/vite/__tests__/utilities/build.d.ts.map +1 -1
- package/dist/vite/__tests__/utilities/build.js +0 -1
- package/dist/vite/__tests__/utilities/build.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts +2 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +362 -53
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/dist/vite/utilities/recast.d.ts +54 -0
- package/dist/vite/utilities/recast.d.ts.map +1 -0
- package/dist/vite/utilities/recast.js +71 -0
- package/dist/vite/utilities/recast.js.map +1 -0
- package/package.json +7 -6
- package/src/config/schema.ts +1 -0
- package/src/core/typeRegistration.ts +32 -0
- package/src/index.ts +7 -0
- package/src/mcp/core/McpAppManager.ts +23 -1
- package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +95 -0
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +53 -0
- package/src/mcp/react/hooks/useHostContext.ts +14 -0
- package/src/mcp/react/hooks/useToolInfo.ts +13 -0
- package/src/mcp/react/hooks/useToolInput.ts +6 -1
- package/src/mcp/react/hooks/useToolName.ts +6 -1
- package/src/mcp/react/index.ts +2 -0
- package/src/openai/core/McpAppManager.ts +22 -1
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +92 -0
- package/src/openai/react/hooks/useHostContext.ts +14 -0
- package/src/openai/react/hooks/useToolInfo.ts +13 -0
- package/src/openai/react/hooks/useToolInput.ts +6 -1
- package/src/openai/react/hooks/useToolName.ts +6 -1
- package/src/openai/react/index.ts +2 -0
- package/src/react/index.mcp.ts +2 -0
- package/src/react/index.openai.ts +2 -0
- package/src/react/index.ts +14 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +12 -0
- package/src/testing/internal/utilities/mockApplicationManifest.ts +1 -0
- package/src/tsconfig/core/tsconfig.json +2 -0
- package/src/tsconfig/mcp/tsconfig.json +2 -0
- package/src/tsconfig/openai/tsconfig.json +2 -0
- package/src/types/application-manifest.ts +1 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +1022 -66
- package/src/vite/__tests__/utilities/build.ts +0 -1
- package/src/vite/apolloClientAiApps.ts +604 -81
- package/src/vite/utilities/recast.ts +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as recast from "recast";
|
|
2
|
+
import type { ManifestExtraInput } from "../../types/application-manifest.js";
|
|
3
|
+
|
|
4
|
+
const b = recast.types.builders;
|
|
5
|
+
|
|
6
|
+
export type TSInterfaceBody = Parameters<typeof b.tsInterfaceBody>[0];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds an import statement with named imports.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* buildImportStatement(
|
|
15
|
+
* ["a", "b"],
|
|
16
|
+
* "./path",
|
|
17
|
+
* );
|
|
18
|
+
* // => import { a, b } from "./path";
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function buildImportStatement(
|
|
22
|
+
specifiers: string[],
|
|
23
|
+
source: string,
|
|
24
|
+
importKind: "type" | "value" = "value"
|
|
25
|
+
) {
|
|
26
|
+
return b.importDeclaration(
|
|
27
|
+
specifiers.map((s) => b.importSpecifier(b.identifier(s))),
|
|
28
|
+
b.stringLiteral(source),
|
|
29
|
+
importKind
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type TSTypeAnnotation = Parameters<typeof b.tsTypeAnnotation>[0];
|
|
34
|
+
const VALID_IDENTIFIER = /^[$_a-zA-Z][a-zA-Z0-9_$]*$/;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds a key/value pair for use in a type. Automatically quotes the key if it
|
|
38
|
+
* contains invalid JavaScript identifier characters.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* buildPropertySignature(
|
|
44
|
+
* "key"
|
|
45
|
+
* b.tsLiteralType(b.tsStringKeyword())
|
|
46
|
+
* );
|
|
47
|
+
* // => key: string
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function buildPropertySignature(
|
|
51
|
+
keyName: string,
|
|
52
|
+
value: TSTypeAnnotation,
|
|
53
|
+
optional = false
|
|
54
|
+
) {
|
|
55
|
+
return b.tsPropertySignature(
|
|
56
|
+
VALID_IDENTIFIER.test(keyName) ?
|
|
57
|
+
b.identifier(keyName)
|
|
58
|
+
: b.stringLiteral(keyName),
|
|
59
|
+
b.tsTypeAnnotation(value),
|
|
60
|
+
optional
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Type that tracks any reference to a type literal so that we can create an AST
|
|
65
|
+
// node from it
|
|
66
|
+
type SupportedLiteralTypes = ManifestExtraInput["type"];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns a TypeScript literal type from a string.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* buildKeywordLiteral("string");
|
|
74
|
+
* // => string
|
|
75
|
+
*
|
|
76
|
+
* buildKeywordLiteral("number");
|
|
77
|
+
* // => number
|
|
78
|
+
* ````
|
|
79
|
+
*/
|
|
80
|
+
export function buildKeywordLiteral(type: SupportedLiteralTypes) {
|
|
81
|
+
switch (type) {
|
|
82
|
+
case "string":
|
|
83
|
+
return b.tsStringKeyword();
|
|
84
|
+
case "boolean":
|
|
85
|
+
return b.tsBooleanKeyword();
|
|
86
|
+
case "number":
|
|
87
|
+
return b.tsNumberKeyword();
|
|
88
|
+
default: {
|
|
89
|
+
const _: never = type;
|
|
90
|
+
throw new Error(`Unexpected input type: ${_}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Pretty prints the TypeScript AST into a code string.
|
|
97
|
+
*/
|
|
98
|
+
export function printRecast(ast: recast.types.ASTNode) {
|
|
99
|
+
return recast.prettyPrint(ast, { tabWidth: 2, quote: "double" }).code;
|
|
100
|
+
}
|