@apollo/client-ai-apps 0.6.0 → 0.6.2
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 +131 -0
- 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/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 +1 -0
- package/dist/mcp/react/index.d.ts.map +1 -1
- package/dist/mcp/react/index.js +1 -0
- package/dist/mcp/react/index.js.map +1 -1
- 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 +1 -0
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +1 -0
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/index.d.ts +9 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +9 -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/vite/apolloClientAiApps.d.ts +1 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +346 -43
- 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 -3
- package/src/core/typeRegistration.ts +32 -0
- package/src/index.ts +7 -0
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +53 -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 +1 -0
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +92 -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 +1 -0
- package/src/react/index.mcp.ts +1 -0
- package/src/react/index.openai.ts +1 -0
- package/src/react/index.ts +11 -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/vite/__tests__/apolloClientAiApps.test.ts +754 -6
- package/src/vite/apolloClientAiApps.ts +564 -68
- 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
|
+
}
|