@agentuity/cli 0.0.95 → 0.0.96

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 (267) hide show
  1. package/AGENTS.md +54 -0
  2. package/dist/auth.d.ts +1 -1
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +8 -5
  5. package/dist/auth.js.map +1 -1
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +190 -27
  8. package/dist/cli.js.map +1 -1
  9. package/dist/cmd/build/entry-generator.d.ts +20 -0
  10. package/dist/cmd/build/entry-generator.d.ts.map +1 -0
  11. package/dist/cmd/build/entry-generator.js +366 -0
  12. package/dist/cmd/build/entry-generator.js.map +1 -0
  13. package/dist/cmd/build/index.d.ts.map +1 -1
  14. package/dist/cmd/build/index.js +5 -23
  15. package/dist/cmd/build/index.js.map +1 -1
  16. package/dist/cmd/build/vite/agent-discovery.d.ts +33 -0
  17. package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -0
  18. package/dist/cmd/build/vite/agent-discovery.js +297 -0
  19. package/dist/cmd/build/vite/agent-discovery.js.map +1 -0
  20. package/dist/cmd/build/vite/browser-env-plugin.d.ts +9 -0
  21. package/dist/cmd/build/vite/browser-env-plugin.d.ts.map +1 -0
  22. package/dist/cmd/build/vite/browser-env-plugin.js +28 -0
  23. package/dist/cmd/build/vite/browser-env-plugin.js.map +1 -0
  24. package/dist/cmd/build/vite/bun-dev-server.d.ts +29 -0
  25. package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -0
  26. package/dist/cmd/build/vite/bun-dev-server.js +54 -0
  27. package/dist/cmd/build/vite/bun-dev-server.js.map +1 -0
  28. package/dist/cmd/build/vite/config-loader.d.ts +23 -0
  29. package/dist/cmd/build/vite/config-loader.d.ts.map +1 -0
  30. package/dist/cmd/build/vite/config-loader.js +50 -0
  31. package/dist/cmd/build/vite/config-loader.js.map +1 -0
  32. package/dist/cmd/build/vite/index.d.ts +26 -0
  33. package/dist/cmd/build/vite/index.d.ts.map +1 -0
  34. package/dist/cmd/build/vite/index.js +127 -0
  35. package/dist/cmd/build/vite/index.js.map +1 -0
  36. package/dist/cmd/build/vite/lifecycle-generator.d.ts +11 -0
  37. package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +1 -0
  38. package/dist/cmd/build/vite/lifecycle-generator.js +35 -0
  39. package/dist/cmd/build/vite/lifecycle-generator.js.map +1 -0
  40. package/dist/cmd/build/vite/metadata-generator.d.ts +32 -0
  41. package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -0
  42. package/dist/cmd/build/vite/metadata-generator.js +489 -0
  43. package/dist/cmd/build/vite/metadata-generator.js.map +1 -0
  44. package/dist/cmd/build/vite/patch-plugin.d.ts +21 -0
  45. package/dist/cmd/build/vite/patch-plugin.d.ts.map +1 -0
  46. package/dist/cmd/build/vite/patch-plugin.js +70 -0
  47. package/dist/cmd/build/vite/patch-plugin.js.map +1 -0
  48. package/dist/cmd/build/vite/registry-generator.d.ts +19 -0
  49. package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -0
  50. package/dist/cmd/build/{route-registry.js → vite/registry-generator.js} +126 -48
  51. package/dist/cmd/build/vite/registry-generator.js.map +1 -0
  52. package/dist/cmd/build/vite/route-discovery.d.ts +58 -0
  53. package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -0
  54. package/dist/cmd/build/vite/route-discovery.js +125 -0
  55. package/dist/cmd/build/vite/route-discovery.js.map +1 -0
  56. package/dist/cmd/build/vite/server-bundler.d.ts +16 -0
  57. package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -0
  58. package/dist/cmd/build/vite/server-bundler.js +194 -0
  59. package/dist/cmd/build/vite/server-bundler.js.map +1 -0
  60. package/dist/cmd/build/vite/vite-asset-server-config.d.ts +19 -0
  61. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -0
  62. package/dist/cmd/build/vite/vite-asset-server-config.js +105 -0
  63. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -0
  64. package/dist/cmd/build/vite/vite-asset-server.d.ts +23 -0
  65. package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -0
  66. package/dist/cmd/build/vite/vite-asset-server.js +40 -0
  67. package/dist/cmd/build/vite/vite-asset-server.js.map +1 -0
  68. package/dist/cmd/build/vite/vite-builder.d.ts +44 -0
  69. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -0
  70. package/dist/cmd/build/vite/vite-builder.js +232 -0
  71. package/dist/cmd/build/vite/vite-builder.js.map +1 -0
  72. package/dist/cmd/build/vite/workbench-generator.d.ts +10 -0
  73. package/dist/cmd/build/vite/workbench-generator.d.ts.map +1 -0
  74. package/dist/cmd/build/vite/workbench-generator.js +135 -0
  75. package/dist/cmd/build/vite/workbench-generator.js.map +1 -0
  76. package/dist/cmd/build/vite-bundler.d.ts +23 -0
  77. package/dist/cmd/build/vite-bundler.d.ts.map +1 -0
  78. package/dist/cmd/build/vite-bundler.js +79 -0
  79. package/dist/cmd/build/vite-bundler.js.map +1 -0
  80. package/dist/cmd/cloud/agent/get.d.ts.map +1 -1
  81. package/dist/cmd/cloud/agent/get.js +1 -0
  82. package/dist/cmd/cloud/agent/get.js.map +1 -1
  83. package/dist/cmd/cloud/agent/list.d.ts.map +1 -1
  84. package/dist/cmd/cloud/agent/list.js +1 -0
  85. package/dist/cmd/cloud/agent/list.js.map +1 -1
  86. package/dist/cmd/cloud/db/get.d.ts.map +1 -1
  87. package/dist/cmd/cloud/db/get.js +1 -0
  88. package/dist/cmd/cloud/db/get.js.map +1 -1
  89. package/dist/cmd/cloud/db/list.d.ts.map +1 -1
  90. package/dist/cmd/cloud/db/list.js +1 -0
  91. package/dist/cmd/cloud/db/list.js.map +1 -1
  92. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  93. package/dist/cmd/cloud/deploy.js +152 -128
  94. package/dist/cmd/cloud/deploy.js.map +1 -1
  95. package/dist/cmd/cloud/deployment/list.d.ts.map +1 -1
  96. package/dist/cmd/cloud/deployment/list.js +4 -0
  97. package/dist/cmd/cloud/deployment/list.js.map +1 -1
  98. package/dist/cmd/cloud/env/list.d.ts.map +1 -1
  99. package/dist/cmd/cloud/env/list.js +1 -0
  100. package/dist/cmd/cloud/env/list.js.map +1 -1
  101. package/dist/cmd/cloud/keyvalue/get.d.ts.map +1 -1
  102. package/dist/cmd/cloud/keyvalue/get.js +1 -0
  103. package/dist/cmd/cloud/keyvalue/get.js.map +1 -1
  104. package/dist/cmd/cloud/keyvalue/keys.d.ts.map +1 -1
  105. package/dist/cmd/cloud/keyvalue/keys.js +1 -0
  106. package/dist/cmd/cloud/keyvalue/keys.js.map +1 -1
  107. package/dist/cmd/cloud/keyvalue/list-namespaces.d.ts.map +1 -1
  108. package/dist/cmd/cloud/keyvalue/list-namespaces.js +1 -0
  109. package/dist/cmd/cloud/keyvalue/list-namespaces.js.map +1 -1
  110. package/dist/cmd/cloud/keyvalue/stats.d.ts.map +1 -1
  111. package/dist/cmd/cloud/keyvalue/stats.js +1 -0
  112. package/dist/cmd/cloud/keyvalue/stats.js.map +1 -1
  113. package/dist/cmd/cloud/secret/list.d.ts.map +1 -1
  114. package/dist/cmd/cloud/secret/list.js +1 -0
  115. package/dist/cmd/cloud/secret/list.js.map +1 -1
  116. package/dist/cmd/cloud/session/list.d.ts.map +1 -1
  117. package/dist/cmd/cloud/session/list.js +4 -0
  118. package/dist/cmd/cloud/session/list.js.map +1 -1
  119. package/dist/cmd/cloud/storage/get.d.ts.map +1 -1
  120. package/dist/cmd/cloud/storage/get.js +1 -0
  121. package/dist/cmd/cloud/storage/get.js.map +1 -1
  122. package/dist/cmd/cloud/storage/list.d.ts.map +1 -1
  123. package/dist/cmd/cloud/storage/list.js +3 -0
  124. package/dist/cmd/cloud/storage/list.js.map +1 -1
  125. package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
  126. package/dist/cmd/cloud/stream/get.js +1 -0
  127. package/dist/cmd/cloud/stream/get.js.map +1 -1
  128. package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
  129. package/dist/cmd/cloud/stream/list.js +1 -0
  130. package/dist/cmd/cloud/stream/list.js.map +1 -1
  131. package/dist/cmd/cloud/vector/get.d.ts.map +1 -1
  132. package/dist/cmd/cloud/vector/get.js +1 -0
  133. package/dist/cmd/cloud/vector/get.js.map +1 -1
  134. package/dist/cmd/cloud/vector/search.d.ts.map +1 -1
  135. package/dist/cmd/cloud/vector/search.js +1 -0
  136. package/dist/cmd/cloud/vector/search.js.map +1 -1
  137. package/dist/cmd/dev/index.d.ts.map +1 -1
  138. package/dist/cmd/dev/index.js +289 -758
  139. package/dist/cmd/dev/index.js.map +1 -1
  140. package/dist/cmd/dev/sync.d.ts +1 -1
  141. package/dist/cmd/dev/sync.d.ts.map +1 -1
  142. package/dist/cmd/dev/sync.js +3 -0
  143. package/dist/cmd/dev/sync.js.map +1 -1
  144. package/dist/cmd/profile/show.d.ts.map +1 -1
  145. package/dist/cmd/profile/show.js +3 -4
  146. package/dist/cmd/profile/show.js.map +1 -1
  147. package/dist/cmd/project/create.d.ts.map +1 -1
  148. package/dist/cmd/project/create.js +3 -4
  149. package/dist/cmd/project/create.js.map +1 -1
  150. package/dist/cmd/project/list.d.ts.map +1 -1
  151. package/dist/cmd/project/list.js +1 -0
  152. package/dist/cmd/project/list.js.map +1 -1
  153. package/dist/cmd/project/show.d.ts.map +1 -1
  154. package/dist/cmd/project/show.js +1 -0
  155. package/dist/cmd/project/show.js.map +1 -1
  156. package/dist/cmd/upgrade/index.d.ts.map +1 -1
  157. package/dist/cmd/upgrade/index.js +5 -3
  158. package/dist/cmd/upgrade/index.js.map +1 -1
  159. package/dist/config.d.ts +1 -1
  160. package/dist/config.d.ts.map +1 -1
  161. package/dist/config.js +29 -11
  162. package/dist/config.js.map +1 -1
  163. package/dist/index.d.ts +1 -1
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js.map +1 -1
  166. package/dist/runtime-bootstrap.d.ts +3 -2
  167. package/dist/runtime-bootstrap.d.ts.map +1 -1
  168. package/dist/runtime-bootstrap.js +7 -2
  169. package/dist/runtime-bootstrap.js.map +1 -1
  170. package/dist/schemas/deploy.d.ts +1 -1
  171. package/dist/types.d.ts +40 -1
  172. package/dist/types.d.ts.map +1 -1
  173. package/dist/types.js.map +1 -1
  174. package/dist/utils/bun-version-checker.d.ts +11 -0
  175. package/dist/utils/bun-version-checker.d.ts.map +1 -0
  176. package/dist/utils/bun-version-checker.js +56 -0
  177. package/dist/utils/bun-version-checker.js.map +1 -0
  178. package/dist/version-check.d.ts.map +1 -1
  179. package/dist/version-check.js +5 -2
  180. package/dist/version-check.js.map +1 -1
  181. package/package.json +10 -3
  182. package/src/auth.ts +9 -5
  183. package/src/cli.ts +228 -29
  184. package/src/cmd/build/entry-generator.ts +404 -0
  185. package/src/cmd/build/index.ts +7 -28
  186. package/src/cmd/build/vite/agent-discovery.ts +467 -0
  187. package/src/cmd/build/vite/browser-env-plugin.ts +34 -0
  188. package/src/cmd/build/vite/bun-dev-server.ts +78 -0
  189. package/src/cmd/build/vite/config-loader.ts +70 -0
  190. package/src/cmd/build/vite/index.ts +166 -0
  191. package/src/cmd/build/vite/lifecycle-generator.ts +43 -0
  192. package/src/cmd/build/vite/metadata-generator.ts +602 -0
  193. package/src/cmd/build/vite/patch-plugin.ts +88 -0
  194. package/src/cmd/build/vite/registry-generator.ts +288 -0
  195. package/src/cmd/build/vite/route-discovery.ts +186 -0
  196. package/src/cmd/build/vite/server-bundler.ts +258 -0
  197. package/src/cmd/build/vite/vite-asset-server-config.ts +134 -0
  198. package/src/cmd/build/vite/vite-asset-server.ts +63 -0
  199. package/src/cmd/build/vite/vite-builder.ts +284 -0
  200. package/src/cmd/build/vite/workbench-generator.ts +152 -0
  201. package/src/cmd/build/vite-bundler.ts +110 -0
  202. package/src/cmd/cloud/agent/get.ts +2 -0
  203. package/src/cmd/cloud/agent/list.ts +1 -0
  204. package/src/cmd/cloud/db/get.ts +1 -0
  205. package/src/cmd/cloud/db/list.ts +1 -0
  206. package/src/cmd/cloud/deploy.ts +175 -144
  207. package/src/cmd/cloud/deployment/list.ts +4 -0
  208. package/src/cmd/cloud/env/list.ts +1 -0
  209. package/src/cmd/cloud/keyvalue/get.ts +1 -0
  210. package/src/cmd/cloud/keyvalue/keys.ts +1 -0
  211. package/src/cmd/cloud/keyvalue/list-namespaces.ts +1 -0
  212. package/src/cmd/cloud/keyvalue/stats.ts +2 -0
  213. package/src/cmd/cloud/secret/list.ts +1 -0
  214. package/src/cmd/cloud/session/list.ts +4 -0
  215. package/src/cmd/cloud/storage/get.ts +1 -0
  216. package/src/cmd/cloud/storage/list.ts +4 -0
  217. package/src/cmd/cloud/stream/get.ts +1 -0
  218. package/src/cmd/cloud/stream/list.ts +1 -0
  219. package/src/cmd/cloud/vector/get.ts +1 -0
  220. package/src/cmd/cloud/vector/search.ts +1 -0
  221. package/src/cmd/dev/index.ts +319 -921
  222. package/src/cmd/dev/sync.ts +5 -1
  223. package/src/cmd/profile/show.ts +3 -4
  224. package/src/cmd/project/create.ts +3 -4
  225. package/src/cmd/project/list.ts +1 -0
  226. package/src/cmd/project/show.ts +1 -0
  227. package/src/cmd/upgrade/index.ts +6 -3
  228. package/src/config.ts +31 -11
  229. package/src/index.ts +2 -0
  230. package/src/runtime-bootstrap.ts +8 -2
  231. package/src/types.ts +48 -1
  232. package/src/utils/bun-version-checker.ts +70 -0
  233. package/src/version-check.ts +6 -2
  234. package/dist/cmd/build/bundler.d.ts +0 -28
  235. package/dist/cmd/build/bundler.d.ts.map +0 -1
  236. package/dist/cmd/build/bundler.js +0 -800
  237. package/dist/cmd/build/bundler.js.map +0 -1
  238. package/dist/cmd/build/config-loader.d.ts +0 -16
  239. package/dist/cmd/build/config-loader.d.ts.map +0 -1
  240. package/dist/cmd/build/config-loader.js +0 -227
  241. package/dist/cmd/build/config-loader.js.map +0 -1
  242. package/dist/cmd/build/file.d.ts +0 -2
  243. package/dist/cmd/build/file.d.ts.map +0 -1
  244. package/dist/cmd/build/file.js +0 -10
  245. package/dist/cmd/build/file.js.map +0 -1
  246. package/dist/cmd/build/fix-duplicate-exports.d.ts +0 -2
  247. package/dist/cmd/build/fix-duplicate-exports.d.ts.map +0 -1
  248. package/dist/cmd/build/fix-duplicate-exports.js +0 -170
  249. package/dist/cmd/build/fix-duplicate-exports.js.map +0 -1
  250. package/dist/cmd/build/plugin.d.ts +0 -6
  251. package/dist/cmd/build/plugin.d.ts.map +0 -1
  252. package/dist/cmd/build/plugin.js +0 -645
  253. package/dist/cmd/build/plugin.js.map +0 -1
  254. package/dist/cmd/build/route-discovery.d.ts +0 -54
  255. package/dist/cmd/build/route-discovery.d.ts.map +0 -1
  256. package/dist/cmd/build/route-discovery.js +0 -148
  257. package/dist/cmd/build/route-discovery.js.map +0 -1
  258. package/dist/cmd/build/route-registry.d.ts +0 -38
  259. package/dist/cmd/build/route-registry.d.ts.map +0 -1
  260. package/dist/cmd/build/route-registry.js.map +0 -1
  261. package/src/cmd/build/bundler.ts +0 -965
  262. package/src/cmd/build/config-loader.ts +0 -268
  263. package/src/cmd/build/file.ts +0 -10
  264. package/src/cmd/build/fix-duplicate-exports.ts +0 -207
  265. package/src/cmd/build/plugin.ts +0 -782
  266. package/src/cmd/build/route-discovery.ts +0 -202
  267. package/src/cmd/build/route-registry.ts +0 -222
@@ -1,645 +0,0 @@
1
- import { dirname, join, resolve } from 'node:path';
2
- import { existsSync, writeFileSync, mkdirSync, unlinkSync } from 'node:fs';
3
- import { parseAgentMetadata, parseEvalMetadata, parseRoute, analyzeWorkbench, generateLifecycleTypes, findCreateAppEndPosition, } from './ast';
4
- import { StructuredError } from '@agentuity/core';
5
- import { applyPatch, generatePatches } from './patch';
6
- import { createLogger } from '@agentuity/server';
7
- import { toCamelCase, toPascalCase } from '../../utils/string';
8
- import { generateRouteRegistry } from './route-registry';
9
- import { discoverRouteFiles } from './route-discovery';
10
- /**
11
- * Setup lifecycle types by analyzing app.ts for setup() function
12
- */
13
- async function setupLifecycleTypes(rootDir, outDir, srcDir, logger) {
14
- // Look for app.ts in both root and src directories
15
- const rootAppFile = join(dirname(srcDir), 'app.ts');
16
- const srcAppFile = join(srcDir, 'app.ts');
17
- let appFile = '';
18
- if (await Bun.file(rootAppFile).exists()) {
19
- appFile = rootAppFile;
20
- }
21
- else if (await Bun.file(srcAppFile).exists()) {
22
- appFile = srcAppFile;
23
- }
24
- if (!appFile || !(await Bun.file(appFile).exists())) {
25
- return false;
26
- }
27
- try {
28
- return await generateLifecycleTypes(rootDir, outDir, appFile);
29
- }
30
- catch (error) {
31
- logger.fatal('Failed to generate lifecycle types:', error);
32
- }
33
- }
34
- /**
35
- * Setup workbench configuration by analyzing app.ts file
36
- */
37
- async function setupWorkbench(srcDir) {
38
- // Look for app.ts in both root and src directories
39
- const rootAppFile = join(dirname(srcDir), 'app.ts');
40
- const srcAppFile = join(srcDir, 'app.ts');
41
- let appFile = '';
42
- if (await Bun.file(rootAppFile).exists()) {
43
- appFile = rootAppFile;
44
- }
45
- else if (await Bun.file(srcAppFile).exists()) {
46
- appFile = srcAppFile;
47
- }
48
- if (!appFile || !(await Bun.file(appFile).exists())) {
49
- return null;
50
- }
51
- const appContent = await Bun.file(appFile).text();
52
- const analysis = analyzeWorkbench(appContent);
53
- if (!analysis.hasWorkbench) {
54
- return null;
55
- }
56
- const workbenchConfig = analysis.config;
57
- return workbenchConfig;
58
- }
59
- const AgentIdentifierCollisionError = StructuredError('AgentIdentifierCollisionError');
60
- function generateAgentRegistry(srcDir, agentInfo) {
61
- // Detect naming collisions in generated identifiers
62
- const generatedNames = new Set();
63
- const collisions = [];
64
- for (const agent of agentInfo) {
65
- const camelName = toCamelCase(agent.name);
66
- if (generatedNames.has(camelName)) {
67
- collisions.push(`Identifier collision detected: "${camelName}" (from "${agent.name}")`);
68
- }
69
- generatedNames.add(camelName);
70
- }
71
- if (collisions.length > 0) {
72
- throw new AgentIdentifierCollisionError({
73
- message: `Agent identifier naming collisions detected:\n${collisions.join('\n')}\n\n` +
74
- `This occurs when different agent names produce the same camelCase identifier.\n` +
75
- `Please rename your agents to avoid this collision.`,
76
- });
77
- }
78
- // Generate imports for all agents
79
- // Registry is now in .agentuity/, so imports need to go up one level and into src/
80
- const imports = agentInfo
81
- .map(({ name, path }) => {
82
- const camelName = toCamelCase(name);
83
- const relativePath = path.replace(/^\.\/agent\//, '../src/agent/');
84
- return `import ${camelName}Agent from '${relativePath}';`;
85
- })
86
- .join('\n');
87
- // Generate flat registry structure (no subagents)
88
- const registry = agentInfo
89
- .map(({ name }) => {
90
- const camelName = toCamelCase(name);
91
- return ` ${camelName}: ${camelName}Agent,`;
92
- })
93
- .join('\n');
94
- // Generate type exports for all agents
95
- const typeExports = agentInfo
96
- .map(({ name }) => {
97
- const camelName = toCamelCase(name);
98
- const pascalName = toPascalCase(name);
99
- return `export type ${pascalName}AgentRunner = AgentRunner<typeof ${camelName}Agent['inputSchema'], typeof ${camelName}Agent['outputSchema'], typeof ${camelName}Agent['stream'] extends true ? true : false>;`;
100
- })
101
- .join('\n');
102
- // Generate flat agent type definitions for AgentRegistry interface augmentation
103
- const runtimeAgentTypes = agentInfo
104
- .map(({ name }) => {
105
- const camelName = toCamelCase(name);
106
- return ` ${camelName}: AgentRunner<typeof ${camelName}Agent['inputSchema'], typeof ${camelName}Agent['outputSchema'], typeof ${camelName}Agent['stream'] extends true ? true : false>;`;
107
- })
108
- .join('\n');
109
- const generatedContent = `/// <reference types="hono" />
110
- // Auto-generated by Agentuity - do not edit manually
111
- ${imports}
112
- import type { AgentRunner, Logger } from '@agentuity/runtime';
113
- import type { KeyValueStorage, StreamStorage, VectorStorage } from '@agentuity/core';
114
-
115
- /**
116
- * Registry of all agents in this application.
117
- * Provides strongly-typed access to agent metadata and runner functions.
118
- * Auto-generated from your agent files during build.
119
- */
120
- export const agentRegistry = {
121
- ${registry}
122
- } as const;
123
-
124
- // Local type aliases for Hono augmentation
125
- type LocalAgentName = keyof typeof agentRegistry;
126
- type LocalAgentRegistry = typeof agentRegistry;
127
-
128
- // Typed runners for each agent
129
- ${typeExports}
130
-
131
- // Augment @agentuity/runtime types with strongly-typed agents from this project
132
- declare module "@agentuity/runtime" {
133
- // Augment the AgentRegistry interface with project-specific strongly-typed agents
134
- export interface AgentRegistry {
135
- ${runtimeAgentTypes}
136
- }
137
- }
138
-
139
- // NOTE: Hono Context properties are accessed via c.var (e.g., c.var.logger, c.var.kv)
140
- // The Variables interface in @agentuity/runtime defines all available context properties
141
- `;
142
- const projectRoot = join(srcDir, '..');
143
- const agentuityDir = join(projectRoot, '.agentuity');
144
- const registryPath = join(agentuityDir, 'registry.generated.ts');
145
- const agentsDir = join(srcDir, 'agent');
146
- const legacyTypesPath = join(agentsDir, 'types.generated.d.ts');
147
- // Ensure .agentuity directory exists
148
- if (!existsSync(agentuityDir)) {
149
- mkdirSync(agentuityDir, { recursive: true });
150
- }
151
- writeFileSync(registryPath, generatedContent, 'utf-8');
152
- // Remove legacy types.generated.d.ts if it exists (now consolidated into registry.generated.ts)
153
- if (existsSync(legacyTypesPath)) {
154
- unlinkSync(legacyTypesPath);
155
- }
156
- }
157
- let metadata;
158
- export function getBuildMetadata() {
159
- return metadata;
160
- }
161
- const AgentNameDuplicateError = StructuredError('AgentNameDuplicateError');
162
- const MetadataPropertyMissingError = StructuredError('MetadataPropertyMissingError')();
163
- const AgentuityBundler = {
164
- name: 'Agentuity Bundler',
165
- setup(build) {
166
- const rootDir = resolve(build.config.root ?? '.');
167
- const srcDir = join(rootDir, 'src');
168
- const outDir = build.config.outdir;
169
- if (!outDir) {
170
- throw new Error('missing outdir must be set');
171
- }
172
- const projectId = build.config.define?.['process.env.AGENTUITY_CLOUD_PROJECT_ID']
173
- ? JSON.parse(build.config.define['process.env.AGENTUITY_CLOUD_PROJECT_ID'])
174
- : '';
175
- const deploymentId = build.config.define?.['process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID']
176
- ? JSON.parse(build.config.define['process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID'])
177
- : '';
178
- const isDevMode = (build.config.define?.['process.env.NODE_ENV']
179
- ? JSON.parse(build.config.define['process.env.NODE_ENV'])
180
- : 'production') === 'development';
181
- const agentInfo = [];
182
- const agentMetadata = new Map();
183
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
184
- // Scan ALL .ts files in src/agent directory for agents
185
- build.onLoad({ filter: /\/agent\/.*\.ts$/, namespace: 'file' }, async (args) => {
186
- let newsource = await Bun.file(args.path).text();
187
- if (args.path.startsWith(srcDir)) {
188
- const contents = transpiler.transformSync(newsource);
189
- // Check if this is an eval file (eval.ts)
190
- if (args.path.endsWith('/eval.ts')) {
191
- // parseEvalMetadata will find the agent from the import statement
192
- const [ns] = await parseEvalMetadata(rootDir, args.path, contents, projectId, deploymentId, undefined, // No agentId - will be resolved from import
193
- agentMetadata);
194
- newsource = ns;
195
- }
196
- else {
197
- // Handle regular agent files
198
- const result = await parseAgentMetadata(rootDir, args.path, contents, projectId, deploymentId);
199
- // Skip files that don't have a createAgent export
200
- if (result === undefined) {
201
- return {
202
- contents: newsource,
203
- loader: 'ts',
204
- };
205
- }
206
- const [ns, md] = result;
207
- newsource = ns;
208
- // Only process files that actually export an agent
209
- if (md.has('name')) {
210
- const newAgentName = md.get('name');
211
- for (const [, kv] of agentMetadata) {
212
- const found = kv.get('name');
213
- if (newAgentName === found) {
214
- throw new AgentNameDuplicateError({
215
- message: `The agent in ${kv.get('filename')} and the agent in ${md.get('filename')} have the same name (${found}). Agent Names must be unique within a project.`,
216
- });
217
- }
218
- }
219
- agentMetadata.set(md.get('name'), md);
220
- }
221
- }
222
- }
223
- return {
224
- contents: newsource,
225
- loader: 'ts',
226
- };
227
- });
228
- const patches = generatePatches();
229
- for (const [, patch] of patches) {
230
- let modulePath = join('node_modules', patch.module, '.*');
231
- if (patch.filename) {
232
- modulePath = join('node_modules', patch.module, patch.filename + '.*');
233
- }
234
- build.onLoad({
235
- filter: new RegExp(modulePath),
236
- namespace: 'file',
237
- }, async (args) => {
238
- if (build.config.target !== 'bun') {
239
- return;
240
- }
241
- const [contents, loader] = await applyPatch(args.path, patch);
242
- return {
243
- contents,
244
- loader,
245
- };
246
- });
247
- }
248
- build.onLoad({
249
- filter: new RegExp(join(rootDir, 'app.ts')),
250
- namespace: 'file',
251
- }, async (args) => {
252
- const logger = createLogger(process.env.AGENTUITY_LOG_LEVEL || 'info');
253
- if (build.config.target !== 'bun') {
254
- return;
255
- }
256
- await args.defer();
257
- const inserts = [];
258
- const indexFile = join(srcDir, 'web', 'index.html');
259
- // Setup workbench configuration - evaluate fresh each time during builds
260
- const workbenchConfig = await setupWorkbench(srcDir);
261
- // Store web routes for later (must be registered AFTER API routes)
262
- let webRoutesInsert = null;
263
- if (existsSync(indexFile)) {
264
- webRoutesInsert = `import { serveStatic } from 'hono/bun';
265
- import { getRouter, registerDevModeRoutes } from '@agentuity/runtime';
266
- import { readFileSync, existsSync } from 'node:fs';
267
-
268
- (() => {
269
- const router = getRouter()!;
270
-
271
- // Setup workbench routes if workbench was bundled
272
- const workbenchIndexPath = import.meta.dir + '/workbench/index.html';
273
- if (existsSync(workbenchIndexPath)) {
274
- let workbenchIndex = readFileSync(workbenchIndexPath, 'utf-8');
275
-
276
- // Always serve assets at /workbench/* regardless of HTML route
277
- const workbenchStatic = serveStatic({ root: import.meta.dir + '/workbench' });
278
- router.get('/workbench/*', workbenchStatic);
279
-
280
- // Use the workbench config determined at build time
281
- const route = ${JSON.stringify(workbenchConfig?.route || '/workbench')};
282
-
283
- // If using custom route, update HTML to point to absolute /workbench/ paths
284
- if (route !== '/workbench') {
285
- workbenchIndex = workbenchIndex.replace(new RegExp('src="\\\\.\\\\/workbench\\\\/', 'g'), 'src="/workbench/');
286
- }
287
-
288
- // Serve HTML at the configured route
289
- router.get(route, (c) => c.html(workbenchIndex));
290
- }
291
-
292
- let index = readFileSync(import.meta.dir + '/web/index.html', 'utf-8');
293
- if (${isDevMode}) {
294
- const end = index.lastIndexOf('</html>');
295
- const html = registerDevModeRoutes(router);
296
- if (end > 0) {
297
- index = index.substring(0,end) + html + index.substring(end);
298
- } else {
299
- index += html;
300
- }
301
- }
302
- // make paths absolute
303
- index = index.replaceAll('./web/', '/web/');
304
- const webstatic = serveStatic({ root: import.meta.dir + '/web' });
305
- // In dev mode, serve from source; in prod, serve from build output
306
- const publicRoot = ${isDevMode} ? ${JSON.stringify(join(srcDir, 'web', 'public'))} : import.meta.dir + '/web/public';
307
- const publicstatic = serveStatic({ root: publicRoot, rewriteRequestPath: (path) => path });
308
- router.get('/', (c) => c.html(index));
309
- router.get('/web/chunk/*', webstatic);
310
- router.get('/web/asset/*', webstatic);
311
- // Serve public assets at root (e.g., /favicon.ico) - must be last
312
- router.get('/*', async (c, next) => {
313
- const path = c.req.path;
314
- // Skip API routes - let them 404 naturally
315
- if (path === '/api' || path.startsWith('/api/')) {
316
- return c.notFound();
317
- }
318
- // Prevent directory traversal attacks
319
- if (path.includes('..') || path.includes('%2e%2e')) {
320
- return c.notFound();
321
- }
322
- // Don't catch workbench routes (already handled above)
323
- if (path.startsWith('/workbench')) {
324
- return c.notFound();
325
- }
326
- // serve default for any path not explicitly matched
327
- return c.html(index);
328
- });
329
- })();`;
330
- }
331
- // Build agentInfo from all discovered agents and track directories
332
- const agentDirs = new Set();
333
- for (const [_identifier, md] of agentMetadata) {
334
- // md.get('filename') can be either absolute or relative to rootDir
335
- const filename = md.get('filename');
336
- const absolutePath = filename.startsWith('/') ? filename : join(rootDir, filename);
337
- // Track which directories have agents
338
- const dir = dirname(absolutePath);
339
- agentDirs.add(dir);
340
- // Convert to path relative to srcDir
341
- // e.g., /path/to/src/agent/my-agent.ts -> ./agent/my-agent
342
- const agentPath = absolutePath.replace(srcDir, '.').replace('.ts', '');
343
- const agentDetail = {
344
- name: md.get('name'),
345
- id: md.get('id'),
346
- path: agentPath,
347
- filename: absolutePath,
348
- description: md.get('description') ?? '',
349
- agentId: md.get('agentId'),
350
- };
351
- agentInfo.push(agentDetail);
352
- }
353
- // Validate that all directories in src/agent have at least one agent
354
- const agentBaseDir = join(srcDir, 'agent');
355
- if (existsSync(agentBaseDir)) {
356
- const { readdirSync, statSync } = await import('node:fs');
357
- const subdirs = readdirSync(agentBaseDir).filter((name) => {
358
- const fullPath = join(agentBaseDir, name);
359
- return statSync(fullPath).isDirectory();
360
- });
361
- for (const subdir of subdirs) {
362
- const fullPath = join(agentBaseDir, subdir);
363
- // Check if this directory or any subdirectory contains agents
364
- const hasAgentInTree = Array.from(agentDirs).some((agentDir) => agentDir.startsWith(fullPath));
365
- if (!hasAgentInTree) {
366
- throw new Error(`Directory ${subdir} in src/agent must contain at least one agent (a file with a createAgent export)`);
367
- }
368
- }
369
- }
370
- // Only generate registry if there are agents
371
- // Note: We don't import the registry here because:
372
- // 1. Evals are already imported when agents are registered (see line 421-422)
373
- // 2. The registry is for type definitions only, not runtime execution
374
- // 3. Importing it causes bundler resolution issues since it's generated during build
375
- generateAgentRegistry(srcDir, agentInfo);
376
- // Generate lifecycle types if setup() is present in app.ts
377
- await setupLifecycleTypes(rootDir, outDir, srcDir, logger);
378
- // Parse routes from src/api directory
379
- const apiRoutesMetadata = [];
380
- const routeInfoList = [];
381
- const apiDir = join(srcDir, 'api');
382
- // Track subdirectory routes for auto-mounting
383
- const subRouteInserts = [];
384
- if (existsSync(apiDir)) {
385
- // Use recursive route discovery to find all route files in subdirectories
386
- const discoveredRoutes = discoverRouteFiles(apiDir);
387
- // Collect all API files: index.ts and discovered subdirectory routes
388
- const apiFiles = [];
389
- // Check for root index.ts
390
- const indexFile = join(apiDir, 'index.ts');
391
- if (existsSync(indexFile)) {
392
- apiFiles.push(indexFile);
393
- }
394
- // Add all discovered route files
395
- for (const route of discoveredRoutes) {
396
- apiFiles.push(route.filepath);
397
- // Generate auto-mount code for this subdirectory route
398
- subRouteInserts.push(`await (async() => {
399
- const { getRouter } = await import('@agentuity/runtime');
400
- const router = getRouter()!;
401
- const ${route.variableName} = (await import('${route.importPath}')).default;
402
- router.route('${route.mountPath}', ${route.variableName});
403
- })();`);
404
- }
405
- for (const apiFile of apiFiles) {
406
- // Quick check: skip files that don't contain createRouter or Hono
407
- // This avoids expensive AST parsing for utility files
408
- const fileContent = await Bun.file(apiFile).text();
409
- if (!fileContent.includes('createRouter') && !fileContent.includes('new Hono')) {
410
- logger.trace(`Skipping ${apiFile}: no createRouter or Hono found`);
411
- continue;
412
- }
413
- try {
414
- const routes = await parseRoute(rootDir, apiFile, projectId, deploymentId);
415
- // Extract schemas from agents for routes that use validators
416
- for (const route of routes) {
417
- // Check if route has custom schema overrides from validator({ input, output })
418
- const hasCustomInput = route.config?.inputSchemaVariable;
419
- const hasCustomOutput = route.config?.outputSchemaVariable;
420
- // If route uses agent.validator(), get schemas from the agent (unless overridden)
421
- if (route.config?.agentImportPath &&
422
- (!hasCustomInput || !hasCustomOutput)) {
423
- const agentImportPath = route.config.agentImportPath;
424
- // Match by import path: @agent/zod-test -> src/agent/zod-test/agent.ts
425
- // Normalize import path by removing leading '@' -> agent/zod-test
426
- const importPattern = agentImportPath.replace(/^@/, '');
427
- // Escape regex special characters for safe pattern matching
428
- const escapedPattern = importPattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
429
- // Match as complete path segment to avoid false positives (e.g., "agent/hello" matching "agent/hello-world")
430
- const segmentPattern = new RegExp(`(^|/)${escapedPattern}(/|$)`);
431
- for (const [, agentMd] of agentMetadata) {
432
- const agentFilename = agentMd.get('filename');
433
- if (agentFilename && segmentPattern.test(agentFilename)) {
434
- // Use agent schemas unless overridden
435
- const inputSchemaCode = hasCustomInput
436
- ? undefined
437
- : agentMd.get('inputSchemaCode');
438
- const outputSchemaCode = hasCustomOutput
439
- ? undefined
440
- : agentMd.get('outputSchemaCode');
441
- if (inputSchemaCode || outputSchemaCode) {
442
- route.schema = {
443
- input: inputSchemaCode,
444
- output: outputSchemaCode,
445
- };
446
- }
447
- break;
448
- }
449
- }
450
- }
451
- // TODO: Extract inline schema code from custom validator({ input: z.string(), output: ... })
452
- // For now, custom schema overrides with inline code are not extracted (would require parsing the validator call's object expression)
453
- }
454
- apiRoutesMetadata.push(...routes);
455
- // Collect route info for RouteRegistry generation
456
- for (const route of routes) {
457
- routeInfoList.push({
458
- method: route.method.toUpperCase(),
459
- path: route.path,
460
- filename: route.filename,
461
- hasValidator: route.config?.hasValidator === true,
462
- routeType: route.type || 'api',
463
- agentVariable: route.config?.agentVariable,
464
- agentImportPath: route.config?.agentImportPath,
465
- inputSchemaVariable: route.config?.inputSchemaVariable,
466
- outputSchemaVariable: route.config?.outputSchemaVariable,
467
- stream: route.config?.stream !== undefined && route.config.stream !== null
468
- ? Boolean(route.config.stream)
469
- : route.type === 'stream'
470
- ? true
471
- : undefined,
472
- });
473
- }
474
- }
475
- catch (error) {
476
- // Skip files that don't have proper router setup despite containing createRouter/Hono
477
- // (e.g., files that import but don't use them, or have syntax errors)
478
- if (error instanceof Error) {
479
- if (error.message.includes('could not find default export') ||
480
- error.message.includes('could not find an proper createRouter')) {
481
- logger.trace(`Skipping ${apiFile}: ${error.message}`);
482
- }
483
- else {
484
- throw error;
485
- }
486
- }
487
- else {
488
- throw error;
489
- }
490
- }
491
- }
492
- }
493
- // Generate RouteRegistry for type-safe route access
494
- if (routeInfoList.length > 0) {
495
- logger.trace(`Generating RouteRegistry with ${routeInfoList.length} routes`);
496
- generateRouteRegistry(srcDir, routeInfoList);
497
- }
498
- // Auto-mount src/api/index.ts if it exists
499
- const apiIndexPath = join(srcDir, 'api', 'index.ts');
500
- if (existsSync(apiIndexPath)) {
501
- inserts.push(`await (async() => {
502
- const { getRouter } = await import('@agentuity/runtime');
503
- const router = getRouter()!;
504
- const api = require('./src/api/index').default;
505
- router.route('/api', api);
506
- })();`);
507
- }
508
- // Auto-mount subdirectory routes (src/api/foo/route.ts -> /api/foo)
509
- for (const subRouteInsert of subRouteInserts) {
510
- inserts.push(subRouteInsert);
511
- }
512
- // Only create the workbench routes if workbench is actually configured
513
- if (workbenchConfig) {
514
- inserts.push(`await (async() => {
515
- const { createWorkbenchRouter, getRouter } = await import('@agentuity/runtime');
516
- const router = getRouter()!;
517
- const workbenchRouter = createWorkbenchRouter();
518
- router.route('/', workbenchRouter);
519
- })();`);
520
- }
521
- // Add web routes AFTER API routes (catch-all must be last)
522
- if (webRoutesInsert) {
523
- inserts.push(webRoutesInsert);
524
- }
525
- const file = Bun.file(args.path);
526
- let contents = await file.text();
527
- // Use AST-based parsing to reliably find createApp statement end
528
- const insertPos = findCreateAppEndPosition(contents);
529
- // Add initialization call after all agent registrations
530
- const setupCall = `
531
- // Initialize providers and run agent setup callbacks after all agents are registered
532
- await (async() => {
533
- const { runAgentSetups, getThreadProvider, getSessionProvider, getAppState } = await import('@agentuity/runtime');
534
-
535
- const threadProvider = getThreadProvider();
536
- const sessionProvider = getSessionProvider();
537
-
538
- const state = getAppState();
539
-
540
- // Initialize providers first
541
- await threadProvider.initialize(state);
542
- await sessionProvider.initialize(state);
543
-
544
- // Then run agent setups
545
- await runAgentSetups(state);
546
- })();`;
547
- if (insertPos > 0) {
548
- contents =
549
- contents.slice(0, insertPos) +
550
- '\n\n' +
551
- inserts.join('\n') +
552
- setupCall +
553
- contents.slice(insertPos);
554
- }
555
- else {
556
- // Fallback: append to end if AST parsing fails
557
- logger.warn('Could not find createApp in AST, appending code to end of file');
558
- contents += `\n${inserts.join('\n')}${setupCall}`;
559
- }
560
- // generate the build metadata
561
- metadata = {
562
- routes: apiRoutesMetadata,
563
- agents: [],
564
- };
565
- // Validate required metadata properties and build agent metadata
566
- for (const [, v] of agentMetadata) {
567
- if (!v.has('filename')) {
568
- throw new MetadataPropertyMissingError({
569
- name: 'filename',
570
- message: 'agent metadata is missing expected filename property',
571
- });
572
- }
573
- if (!v.has('id')) {
574
- throw new MetadataPropertyMissingError({
575
- name: 'id',
576
- message: 'agent metadata is missing expected id property',
577
- });
578
- }
579
- if (!v.has('version')) {
580
- throw new MetadataPropertyMissingError({
581
- name: 'version',
582
- message: 'agent metadata is missing expected version property',
583
- });
584
- }
585
- if (!v.has('name')) {
586
- throw new MetadataPropertyMissingError({
587
- name: 'name',
588
- message: 'agent metadata is missing expected name property',
589
- });
590
- }
591
- if (!v.has('agentId')) {
592
- throw new MetadataPropertyMissingError({
593
- name: 'agentId',
594
- message: 'agent metadata is missing expected agentId property',
595
- });
596
- }
597
- const agentData = {
598
- filename: v.get('filename'),
599
- id: v.get('id'),
600
- agentId: v.get('agentId'),
601
- version: v.get('version'),
602
- name: v.get('name'),
603
- description: v.get('description') ?? '',
604
- projectId,
605
- };
606
- // Extract schema codes if available
607
- const inputSchemaCode = v.get('inputSchemaCode');
608
- const outputSchemaCode = v.get('outputSchemaCode');
609
- if (inputSchemaCode || outputSchemaCode) {
610
- agentData.schema = {
611
- input: inputSchemaCode,
612
- output: outputSchemaCode,
613
- };
614
- }
615
- const evalsStr = v.get('evals');
616
- if (evalsStr) {
617
- logger.trace(`[plugin] Found evals string for agent ${agentData.name}, parsing...`);
618
- try {
619
- const parsedEvals = JSON.parse(evalsStr);
620
- agentData.evals = parsedEvals.map((evalItem) => ({
621
- ...evalItem,
622
- agentIdentifier: agentData.agentId,
623
- projectId,
624
- }));
625
- logger.trace(`[plugin] Successfully parsed ${agentData.evals?.length ?? 0} eval(s) for agent ${agentData.name}`);
626
- }
627
- catch (e) {
628
- logger.trace(`[plugin] Failed to parse evals for agent ${agentData.name}: ${e}`);
629
- console.warn(`Failed to parse evals for agent ${agentData.name}: ${e}`);
630
- }
631
- }
632
- else {
633
- logger.trace(`[plugin] No evals found for agent ${agentData.name}`);
634
- }
635
- metadata.agents.push(agentData);
636
- }
637
- return {
638
- contents,
639
- loader: 'ts',
640
- };
641
- });
642
- },
643
- };
644
- export default AgentuityBundler;
645
- //# sourceMappingURL=plugin.js.map