@apollo/client-ai-apps 0.6.0 → 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.
Files changed (85) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/dist/core/typeRegistration.d.ts +33 -0
  3. package/dist/core/typeRegistration.d.ts.map +1 -0
  4. package/dist/core/typeRegistration.js +2 -0
  5. package/dist/core/typeRegistration.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp/react/hooks/useToolInfo.d.ts +3 -0
  10. package/dist/mcp/react/hooks/useToolInfo.d.ts.map +1 -0
  11. package/dist/mcp/react/hooks/useToolInfo.js +10 -0
  12. package/dist/mcp/react/hooks/useToolInfo.js.map +1 -0
  13. package/dist/mcp/react/hooks/useToolInput.d.ts +6 -1
  14. package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -1
  15. package/dist/mcp/react/hooks/useToolInput.js +4 -0
  16. package/dist/mcp/react/hooks/useToolInput.js.map +1 -1
  17. package/dist/mcp/react/hooks/useToolName.d.ts +6 -1
  18. package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -1
  19. package/dist/mcp/react/hooks/useToolName.js +4 -0
  20. package/dist/mcp/react/hooks/useToolName.js.map +1 -1
  21. package/dist/mcp/react/index.d.ts +1 -0
  22. package/dist/mcp/react/index.d.ts.map +1 -1
  23. package/dist/mcp/react/index.js +1 -0
  24. package/dist/mcp/react/index.js.map +1 -1
  25. package/dist/openai/react/hooks/useToolInfo.d.ts +3 -0
  26. package/dist/openai/react/hooks/useToolInfo.d.ts.map +1 -0
  27. package/dist/openai/react/hooks/useToolInfo.js +10 -0
  28. package/dist/openai/react/hooks/useToolInfo.js.map +1 -0
  29. package/dist/openai/react/hooks/useToolInput.d.ts +6 -1
  30. package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -1
  31. package/dist/openai/react/hooks/useToolInput.js +4 -0
  32. package/dist/openai/react/hooks/useToolInput.js.map +1 -1
  33. package/dist/openai/react/hooks/useToolName.d.ts +6 -1
  34. package/dist/openai/react/hooks/useToolName.d.ts.map +1 -1
  35. package/dist/openai/react/hooks/useToolName.js +4 -0
  36. package/dist/openai/react/hooks/useToolName.js.map +1 -1
  37. package/dist/openai/react/index.d.ts +1 -0
  38. package/dist/openai/react/index.d.ts.map +1 -1
  39. package/dist/openai/react/index.js +1 -0
  40. package/dist/openai/react/index.js.map +1 -1
  41. package/dist/react/index.d.ts +9 -0
  42. package/dist/react/index.d.ts.map +1 -1
  43. package/dist/react/index.js +9 -0
  44. package/dist/react/index.js.map +1 -1
  45. package/dist/react/index.mcp.d.ts +1 -1
  46. package/dist/react/index.mcp.d.ts.map +1 -1
  47. package/dist/react/index.mcp.js +1 -1
  48. package/dist/react/index.mcp.js.map +1 -1
  49. package/dist/react/index.openai.d.ts +1 -1
  50. package/dist/react/index.openai.d.ts.map +1 -1
  51. package/dist/react/index.openai.js +1 -1
  52. package/dist/react/index.openai.js.map +1 -1
  53. package/dist/tsconfig/core/tsconfig.json +2 -0
  54. package/dist/tsconfig/mcp/tsconfig.json +2 -0
  55. package/dist/tsconfig/openai/tsconfig.json +2 -0
  56. package/dist/vite/apolloClientAiApps.d.ts +1 -0
  57. package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
  58. package/dist/vite/apolloClientAiApps.js +337 -41
  59. package/dist/vite/apolloClientAiApps.js.map +1 -1
  60. package/dist/vite/utilities/recast.d.ts +54 -0
  61. package/dist/vite/utilities/recast.d.ts.map +1 -0
  62. package/dist/vite/utilities/recast.js +71 -0
  63. package/dist/vite/utilities/recast.js.map +1 -0
  64. package/package.json +7 -3
  65. package/src/core/typeRegistration.ts +32 -0
  66. package/src/index.ts +7 -0
  67. package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +53 -0
  68. package/src/mcp/react/hooks/useToolInfo.ts +13 -0
  69. package/src/mcp/react/hooks/useToolInput.ts +6 -1
  70. package/src/mcp/react/hooks/useToolName.ts +6 -1
  71. package/src/mcp/react/index.ts +1 -0
  72. package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +92 -0
  73. package/src/openai/react/hooks/useToolInfo.ts +13 -0
  74. package/src/openai/react/hooks/useToolInput.ts +6 -1
  75. package/src/openai/react/hooks/useToolName.ts +6 -1
  76. package/src/openai/react/index.ts +1 -0
  77. package/src/react/index.mcp.ts +1 -0
  78. package/src/react/index.openai.ts +1 -0
  79. package/src/react/index.ts +11 -0
  80. package/src/tsconfig/core/tsconfig.json +2 -0
  81. package/src/tsconfig/mcp/tsconfig.json +2 -0
  82. package/src/tsconfig/openai/tsconfig.json +2 -0
  83. package/src/vite/__tests__/apolloClientAiApps.test.ts +744 -6
  84. package/src/vite/apolloClientAiApps.ts +552 -66
  85. 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
+ }