@agentuity/cli 0.0.100 → 0.0.102

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 (264) hide show
  1. package/AGENTS.md +19 -188
  2. package/bin/cli.ts +13 -6
  3. package/dist/api.d.ts +1 -0
  4. package/dist/api.d.ts.map +1 -1
  5. package/dist/api.js +1 -1
  6. package/dist/api.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +41 -12
  9. package/dist/cli.js.map +1 -1
  10. package/dist/cmd/ai/index.d.ts.map +1 -1
  11. package/dist/cmd/ai/index.js +6 -1
  12. package/dist/cmd/ai/index.js.map +1 -1
  13. package/dist/cmd/ai/prompt/agent.d.ts +7 -0
  14. package/dist/cmd/ai/prompt/agent.d.ts.map +1 -1
  15. package/dist/cmd/ai/prompt/agent.js +12 -323
  16. package/dist/cmd/ai/prompt/agent.js.map +1 -1
  17. package/dist/cmd/ai/prompt/api.d.ts +7 -0
  18. package/dist/cmd/ai/prompt/api.d.ts.map +1 -1
  19. package/dist/cmd/ai/prompt/api.js +12 -260
  20. package/dist/cmd/ai/prompt/api.js.map +1 -1
  21. package/dist/cmd/ai/prompt/version.d.ts +35 -0
  22. package/dist/cmd/ai/prompt/version.d.ts.map +1 -0
  23. package/dist/cmd/ai/prompt/version.js +55 -0
  24. package/dist/cmd/ai/prompt/version.js.map +1 -0
  25. package/dist/cmd/ai/prompt/web.d.ts +7 -0
  26. package/dist/cmd/ai/prompt/web.d.ts.map +1 -1
  27. package/dist/cmd/ai/prompt/web.js +12 -283
  28. package/dist/cmd/ai/prompt/web.js.map +1 -1
  29. package/dist/cmd/ai/skills/generate.d.ts +3 -0
  30. package/dist/cmd/ai/skills/generate.d.ts.map +1 -0
  31. package/dist/cmd/ai/skills/generate.js +65 -0
  32. package/dist/cmd/ai/skills/generate.js.map +1 -0
  33. package/dist/cmd/ai/skills/generator.d.ts +4 -0
  34. package/dist/cmd/ai/skills/generator.d.ts.map +1 -0
  35. package/dist/cmd/ai/skills/generator.js +402 -0
  36. package/dist/cmd/ai/skills/generator.js.map +1 -0
  37. package/dist/cmd/ai/skills/index.d.ts +4 -0
  38. package/dist/cmd/ai/skills/index.d.ts.map +1 -0
  39. package/dist/cmd/ai/skills/index.js +21 -0
  40. package/dist/cmd/ai/skills/index.js.map +1 -0
  41. package/dist/cmd/auth/signup.d.ts.map +1 -1
  42. package/dist/cmd/auth/signup.js +1 -0
  43. package/dist/cmd/auth/signup.js.map +1 -1
  44. package/dist/cmd/build/ast.d.ts +2 -1
  45. package/dist/cmd/build/ast.d.ts.map +1 -1
  46. package/dist/cmd/build/ast.js +135 -47
  47. package/dist/cmd/build/ast.js.map +1 -1
  48. package/dist/cmd/build/entry-generator.d.ts.map +1 -1
  49. package/dist/cmd/build/entry-generator.js +255 -188
  50. package/dist/cmd/build/entry-generator.js.map +1 -1
  51. package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -1
  52. package/dist/cmd/build/vite/agent-discovery.js +103 -45
  53. package/dist/cmd/build/vite/agent-discovery.js.map +1 -1
  54. package/dist/cmd/build/vite/bun-dev-server.d.ts +7 -1
  55. package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
  56. package/dist/cmd/build/vite/bun-dev-server.js +52 -26
  57. package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
  58. package/dist/cmd/build/vite/docs-generator.d.ts +13 -0
  59. package/dist/cmd/build/vite/docs-generator.d.ts.map +1 -0
  60. package/dist/cmd/build/vite/docs-generator.js +81 -0
  61. package/dist/cmd/build/vite/docs-generator.js.map +1 -0
  62. package/dist/cmd/build/vite/index.d.ts +3 -3
  63. package/dist/cmd/build/vite/index.d.ts.map +1 -1
  64. package/dist/cmd/build/vite/index.js +9 -7
  65. package/dist/cmd/build/vite/index.js.map +1 -1
  66. package/dist/cmd/build/vite/lifecycle-generator.d.ts +1 -1
  67. package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +1 -1
  68. package/dist/cmd/build/vite/lifecycle-generator.js +19 -5
  69. package/dist/cmd/build/vite/lifecycle-generator.js.map +1 -1
  70. package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -1
  71. package/dist/cmd/build/vite/metadata-generator.js +203 -7
  72. package/dist/cmd/build/vite/metadata-generator.js.map +1 -1
  73. package/dist/cmd/build/vite/prompt-generator.d.ts +23 -0
  74. package/dist/cmd/build/vite/prompt-generator.d.ts.map +1 -0
  75. package/dist/cmd/build/vite/prompt-generator.js +123 -0
  76. package/dist/cmd/build/vite/prompt-generator.js.map +1 -0
  77. package/dist/cmd/build/vite/registry-generator.d.ts +3 -3
  78. package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -1
  79. package/dist/cmd/build/vite/registry-generator.js +644 -103
  80. package/dist/cmd/build/vite/registry-generator.js.map +1 -1
  81. package/dist/cmd/build/vite/route-discovery.d.ts +4 -0
  82. package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -1
  83. package/dist/cmd/build/vite/route-discovery.js.map +1 -1
  84. package/dist/cmd/build/vite/server-bundler.d.ts +4 -0
  85. package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -1
  86. package/dist/cmd/build/vite/server-bundler.js +63 -17
  87. package/dist/cmd/build/vite/server-bundler.js.map +1 -1
  88. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  89. package/dist/cmd/build/vite/vite-asset-server-config.js +4 -0
  90. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  91. package/dist/cmd/build/vite/vite-builder.d.ts +1 -1
  92. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
  93. package/dist/cmd/build/vite/vite-builder.js +118 -96
  94. package/dist/cmd/build/vite/vite-builder.js.map +1 -1
  95. package/dist/cmd/build/vite-bundler.js +6 -6
  96. package/dist/cmd/build/vite-bundler.js.map +1 -1
  97. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  98. package/dist/cmd/cloud/deploy.js +89 -32
  99. package/dist/cmd/cloud/deploy.js.map +1 -1
  100. package/dist/cmd/cloud/keyvalue/create-namespace.d.ts.map +1 -1
  101. package/dist/cmd/cloud/keyvalue/create-namespace.js +3 -1
  102. package/dist/cmd/cloud/keyvalue/create-namespace.js.map +1 -1
  103. package/dist/cmd/cloud/keyvalue/delete-namespace.d.ts.map +1 -1
  104. package/dist/cmd/cloud/keyvalue/delete-namespace.js +3 -1
  105. package/dist/cmd/cloud/keyvalue/delete-namespace.js.map +1 -1
  106. package/dist/cmd/cloud/keyvalue/delete.d.ts.map +1 -1
  107. package/dist/cmd/cloud/keyvalue/delete.js +3 -1
  108. package/dist/cmd/cloud/keyvalue/delete.js.map +1 -1
  109. package/dist/cmd/cloud/keyvalue/set.d.ts.map +1 -1
  110. package/dist/cmd/cloud/keyvalue/set.js +4 -2
  111. package/dist/cmd/cloud/keyvalue/set.js.map +1 -1
  112. package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
  113. package/dist/cmd/cloud/stream/get.js +2 -13
  114. package/dist/cmd/cloud/stream/get.js.map +1 -1
  115. package/dist/cmd/cloud/vector/delete-namespace.d.ts +3 -0
  116. package/dist/cmd/cloud/vector/delete-namespace.d.ts.map +1 -0
  117. package/dist/cmd/cloud/vector/delete-namespace.js +77 -0
  118. package/dist/cmd/cloud/vector/delete-namespace.js.map +1 -0
  119. package/dist/cmd/cloud/vector/index.d.ts.map +1 -1
  120. package/dist/cmd/cloud/vector/index.js +21 -4
  121. package/dist/cmd/cloud/vector/index.js.map +1 -1
  122. package/dist/cmd/cloud/vector/list-namespaces.d.ts +3 -0
  123. package/dist/cmd/cloud/vector/list-namespaces.d.ts.map +1 -0
  124. package/dist/cmd/cloud/vector/list-namespaces.js +42 -0
  125. package/dist/cmd/cloud/vector/list-namespaces.js.map +1 -0
  126. package/dist/cmd/cloud/vector/stats.d.ts +3 -0
  127. package/dist/cmd/cloud/vector/stats.d.ts.map +1 -0
  128. package/dist/cmd/cloud/vector/stats.js +142 -0
  129. package/dist/cmd/cloud/vector/stats.js.map +1 -0
  130. package/dist/cmd/cloud/vector/upsert.d.ts +3 -0
  131. package/dist/cmd/cloud/vector/upsert.d.ts.map +1 -0
  132. package/dist/cmd/cloud/vector/upsert.js +192 -0
  133. package/dist/cmd/cloud/vector/upsert.js.map +1 -0
  134. package/dist/cmd/dev/file-watcher.d.ts.map +1 -1
  135. package/dist/cmd/dev/file-watcher.js +94 -33
  136. package/dist/cmd/dev/file-watcher.js.map +1 -1
  137. package/dist/cmd/dev/index.d.ts.map +1 -1
  138. package/dist/cmd/dev/index.js +298 -61
  139. package/dist/cmd/dev/index.js.map +1 -1
  140. package/dist/cmd/dev/skills.d.ts +10 -0
  141. package/dist/cmd/dev/skills.d.ts.map +1 -0
  142. package/dist/cmd/dev/skills.js +57 -0
  143. package/dist/cmd/dev/skills.js.map +1 -0
  144. package/dist/cmd/dev/sync.d.ts.map +1 -1
  145. package/dist/cmd/dev/sync.js +19 -3
  146. package/dist/cmd/dev/sync.js.map +1 -1
  147. package/dist/cmd/index.d.ts.map +1 -1
  148. package/dist/cmd/index.js +1 -0
  149. package/dist/cmd/index.js.map +1 -1
  150. package/dist/cmd/project/create.d.ts.map +1 -1
  151. package/dist/cmd/project/create.js +3 -0
  152. package/dist/cmd/project/create.js.map +1 -1
  153. package/dist/cmd/project/template-flow.d.ts +1 -0
  154. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  155. package/dist/cmd/project/template-flow.js +30 -5
  156. package/dist/cmd/project/template-flow.js.map +1 -1
  157. package/dist/cmd/setup/index.d.ts.map +1 -1
  158. package/dist/cmd/setup/index.js +1 -0
  159. package/dist/cmd/setup/index.js.map +1 -1
  160. package/dist/cmd/upgrade/index.d.ts +15 -0
  161. package/dist/cmd/upgrade/index.d.ts.map +1 -1
  162. package/dist/cmd/upgrade/index.js +59 -4
  163. package/dist/cmd/upgrade/index.js.map +1 -1
  164. package/dist/config.d.ts.map +1 -1
  165. package/dist/config.js +8 -0
  166. package/dist/config.js.map +1 -1
  167. package/dist/domain.d.ts +45 -0
  168. package/dist/domain.d.ts.map +1 -0
  169. package/dist/domain.js +200 -0
  170. package/dist/domain.js.map +1 -0
  171. package/dist/index.d.ts +0 -1
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +0 -1
  174. package/dist/index.js.map +1 -1
  175. package/dist/schema-generator.d.ts +2 -0
  176. package/dist/schema-generator.d.ts.map +1 -1
  177. package/dist/schema-generator.js +18 -0
  178. package/dist/schema-generator.js.map +1 -1
  179. package/dist/steps.d.ts +1 -1
  180. package/dist/steps.d.ts.map +1 -1
  181. package/dist/steps.js +16 -5
  182. package/dist/steps.js.map +1 -1
  183. package/dist/tui/prompt.d.ts +1 -2
  184. package/dist/tui/prompt.d.ts.map +1 -1
  185. package/dist/tui/prompt.js +8 -4
  186. package/dist/tui/prompt.js.map +1 -1
  187. package/dist/tui.d.ts +16 -0
  188. package/dist/tui.d.ts.map +1 -1
  189. package/dist/tui.js +23 -2
  190. package/dist/tui.js.map +1 -1
  191. package/dist/types.d.ts +9 -2
  192. package/dist/types.d.ts.map +1 -1
  193. package/dist/types.js +3 -3
  194. package/dist/types.js.map +1 -1
  195. package/package.json +5 -8
  196. package/src/api.ts +1 -1
  197. package/src/cli.ts +47 -12
  198. package/src/cmd/ai/index.ts +6 -1
  199. package/src/cmd/ai/prompt/agent.md +306 -0
  200. package/src/cmd/ai/prompt/agent.ts +12 -322
  201. package/src/cmd/ai/prompt/api.md +360 -0
  202. package/src/cmd/ai/prompt/api.ts +13 -260
  203. package/src/cmd/ai/prompt/version.ts +61 -0
  204. package/src/cmd/ai/prompt/web.md +509 -0
  205. package/src/cmd/ai/prompt/web.ts +12 -282
  206. package/src/cmd/ai/skills/generate.ts +75 -0
  207. package/src/cmd/ai/skills/generator.ts +519 -0
  208. package/src/cmd/ai/skills/index.ts +23 -0
  209. package/src/cmd/auth/signup.ts +1 -0
  210. package/src/cmd/build/ast.ts +161 -48
  211. package/src/cmd/build/entry-generator.ts +258 -187
  212. package/src/cmd/build/vite/agent-discovery.ts +151 -58
  213. package/src/cmd/build/vite/bun-dev-server.ts +57 -27
  214. package/src/cmd/build/vite/docs-generator.ts +87 -0
  215. package/src/cmd/build/vite/index.ts +9 -7
  216. package/src/cmd/build/vite/lifecycle-generator.ts +19 -5
  217. package/src/cmd/build/vite/metadata-generator.ts +251 -7
  218. package/src/cmd/build/vite/prompt-generator.ts +169 -0
  219. package/src/cmd/build/vite/registry-generator.ts +750 -108
  220. package/src/cmd/build/vite/route-discovery.ts +4 -0
  221. package/src/cmd/build/vite/server-bundler.ts +73 -23
  222. package/src/cmd/build/vite/vite-asset-server-config.ts +5 -0
  223. package/src/cmd/build/vite/vite-builder.ts +134 -100
  224. package/src/cmd/build/vite-bundler.ts +6 -6
  225. package/src/cmd/cloud/deploy.ts +114 -36
  226. package/src/cmd/cloud/keyvalue/create-namespace.ts +3 -1
  227. package/src/cmd/cloud/keyvalue/delete-namespace.ts +3 -1
  228. package/src/cmd/cloud/keyvalue/delete.ts +3 -1
  229. package/src/cmd/cloud/keyvalue/set.ts +4 -2
  230. package/src/cmd/cloud/stream/get.ts +2 -9
  231. package/src/cmd/cloud/vector/delete-namespace.ts +89 -0
  232. package/src/cmd/cloud/vector/index.ts +21 -4
  233. package/src/cmd/cloud/vector/list-namespaces.ts +46 -0
  234. package/src/cmd/cloud/vector/stats.ts +160 -0
  235. package/src/cmd/cloud/vector/upsert.ts +216 -0
  236. package/src/cmd/dev/file-watcher.ts +109 -34
  237. package/src/cmd/dev/index.ts +364 -60
  238. package/src/cmd/dev/skills.ts +82 -0
  239. package/src/cmd/dev/sync.ts +41 -6
  240. package/src/cmd/index.ts +1 -0
  241. package/src/cmd/project/create.ts +3 -0
  242. package/src/cmd/project/template-flow.ts +37 -5
  243. package/src/cmd/setup/index.ts +1 -0
  244. package/src/cmd/upgrade/index.ts +68 -4
  245. package/src/config.ts +9 -0
  246. package/src/domain.ts +273 -0
  247. package/src/index.ts +0 -5
  248. package/src/runtime-bootstrap.md +1 -1
  249. package/src/schema-generator.ts +23 -0
  250. package/src/steps.ts +16 -5
  251. package/src/tui/prompt.ts +11 -5
  252. package/src/tui.ts +21 -2
  253. package/src/types/md.d.ts +8 -0
  254. package/src/types.ts +12 -3
  255. package/dist/cmd/cloud/domain.d.ts +0 -17
  256. package/dist/cmd/cloud/domain.d.ts.map +0 -1
  257. package/dist/cmd/cloud/domain.js +0 -79
  258. package/dist/cmd/cloud/domain.js.map +0 -1
  259. package/dist/runtime-bootstrap.d.ts +0 -56
  260. package/dist/runtime-bootstrap.d.ts.map +0 -1
  261. package/dist/runtime-bootstrap.js +0 -95
  262. package/dist/runtime-bootstrap.js.map +0 -1
  263. package/src/cmd/cloud/domain.ts +0 -100
  264. package/src/runtime-bootstrap.ts +0 -131
@@ -1173,6 +1173,37 @@ export async function parseRoute(
1173
1173
  }
1174
1174
  }
1175
1175
  }
1176
+
1177
+ // Scan for exported schemas (for WebSocket/SSE routes)
1178
+ let exportedInputSchemaName: string | undefined;
1179
+ let exportedOutputSchemaName: string | undefined;
1180
+ for (const body of ast.body) {
1181
+ if (body.type === 'ExportNamedDeclaration') {
1182
+ const exportDecl = body as {
1183
+ declaration?: {
1184
+ type: string;
1185
+ declarations?: Array<ASTVariableDeclarator>;
1186
+ };
1187
+ };
1188
+
1189
+ if (exportDecl.declaration?.type === 'VariableDeclaration') {
1190
+ const varDecl = exportDecl.declaration as {
1191
+ declarations: Array<ASTVariableDeclarator>;
1192
+ };
1193
+ for (const d of varDecl.declarations) {
1194
+ if (d.id.type === 'Identifier') {
1195
+ const name = (d.id as ASTNodeIdentifier).name;
1196
+ if (name === 'inputSchema') {
1197
+ exportedInputSchemaName = name;
1198
+ } else if (name === 'outputSchema') {
1199
+ exportedOutputSchemaName = name;
1200
+ }
1201
+ }
1202
+ }
1203
+ }
1204
+ }
1205
+ }
1206
+
1176
1207
  for (const body of ast.body) {
1177
1208
  if (body.type === 'ExportDefaultDeclaration') {
1178
1209
  const identifier = body.declaration as ASTNodeIdentifier;
@@ -1406,6 +1437,16 @@ export async function parseRoute(
1406
1437
  }
1407
1438
  }
1408
1439
 
1440
+ // For WebSocket/SSE routes that don't use validator(), fall back to exported schemas
1441
+ if (!routeConfig.hasValidator && (type === 'websocket' || type === 'sse')) {
1442
+ if (!routeConfig.inputSchemaVariable && exportedInputSchemaName) {
1443
+ routeConfig.inputSchemaVariable = exportedInputSchemaName;
1444
+ }
1445
+ if (!routeConfig.outputSchemaVariable && exportedOutputSchemaName) {
1446
+ routeConfig.outputSchemaVariable = exportedOutputSchemaName;
1447
+ }
1448
+ }
1449
+
1409
1450
  routes.push({
1410
1451
  id,
1411
1452
  method: method as 'get' | 'post' | 'put' | 'delete' | 'patch',
@@ -1528,10 +1569,17 @@ export function checkRouteConflicts(content: string, workbenchEndpoint: string):
1528
1569
  */
1529
1570
  export function extractAppStateType(content: string): string | null {
1530
1571
  try {
1531
- const sourceFile = ts.createSourceFile('app.ts', content, ts.ScriptTarget.Latest, true);
1572
+ const sourceFile = ts.createSourceFile(
1573
+ 'app.ts',
1574
+ content,
1575
+ ts.ScriptTarget.Latest,
1576
+ true,
1577
+ ts.ScriptKind.TS
1578
+ );
1532
1579
  let appStateType: string | null = null;
1533
1580
  let foundCreateApp = false;
1534
1581
  let foundSetup = false;
1582
+ let exportedSetupFunc: ts.FunctionDeclaration | undefined;
1535
1583
 
1536
1584
  function visitNode(node: ts.Node): void {
1537
1585
  // Look for createApp call expression (can be on await expression)
@@ -1584,14 +1632,49 @@ export function extractAppStateType(content: string): string | null {
1584
1632
  }
1585
1633
  }
1586
1634
 
1635
+ // Also record exported setup function
1636
+ if (
1637
+ ts.isFunctionDeclaration(node) &&
1638
+ node.name &&
1639
+ node.name.text === 'setup' &&
1640
+ node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)
1641
+ ) {
1642
+ exportedSetupFunc = node;
1643
+ }
1644
+
1587
1645
  ts.forEachChild(node, visitNode);
1588
1646
  }
1589
1647
 
1590
1648
  function findReturnObject(
1591
- func: ts.FunctionExpression | ts.ArrowFunction
1649
+ func: ts.FunctionExpression | ts.ArrowFunction | ts.FunctionDeclaration
1592
1650
  ): ts.ObjectLiteralExpression | null {
1593
1651
  let returnObject: ts.ObjectLiteralExpression | null = null;
1594
1652
 
1653
+ // Handle arrow function with expression body: () => ({ ... })
1654
+ if (ts.isArrowFunction(func) && !ts.isBlock(func.body)) {
1655
+ const bodyExpr = func.body;
1656
+ // Handle parenthesized expression: () => ({ ... })
1657
+ const expr = ts.isParenthesizedExpression(bodyExpr) ? bodyExpr.expression : bodyExpr;
1658
+
1659
+ if (ts.isObjectLiteralExpression(expr)) {
1660
+ return expr;
1661
+ }
1662
+ if (ts.isIdentifier(expr)) {
1663
+ // Support: const state = {...}; const setup = () => state;
1664
+ // Walk up to find the enclosing source file or statement list
1665
+ let scope: ts.Node = func;
1666
+ while (scope && !ts.isSourceFile(scope) && !ts.isBlock(scope)) {
1667
+ scope = scope.parent;
1668
+ }
1669
+ if (scope) {
1670
+ findVariableDeclaration(scope, expr.text);
1671
+ }
1672
+ return returnObject;
1673
+ }
1674
+ // For other expressions, can't extract type
1675
+ return null;
1676
+ }
1677
+
1595
1678
  function visitFuncNode(node: ts.Node): void {
1596
1679
  if (ts.isReturnStatement(node) && node.expression) {
1597
1680
  // Handle direct object literal
@@ -1603,7 +1686,9 @@ export function extractAppStateType(content: string): string | null {
1603
1686
  // Try to find the variable declaration
1604
1687
  const varName = node.expression.text;
1605
1688
  // Walk back through the function to find the declaration
1606
- findVariableDeclaration(func.body!, varName);
1689
+ if (func.body && ts.isBlock(func.body)) {
1690
+ findVariableDeclaration(func.body, varName);
1691
+ }
1607
1692
  }
1608
1693
  }
1609
1694
  ts.forEachChild(node, visitFuncNode);
@@ -1625,7 +1710,7 @@ export function extractAppStateType(content: string): string | null {
1625
1710
  visitForVar(body);
1626
1711
  }
1627
1712
 
1628
- if (func.body) {
1713
+ if (func.body && ts.isBlock(func.body)) {
1629
1714
  visitFuncNode(func.body);
1630
1715
  }
1631
1716
 
@@ -1682,6 +1767,17 @@ export function extractAppStateType(content: string): string | null {
1682
1767
 
1683
1768
  visitNode(sourceFile);
1684
1769
 
1770
+ // If no inline setup found but we have an exported setup function, use that
1771
+ if (foundCreateApp && !foundSetup && exportedSetupFunc) {
1772
+ foundSetup = true;
1773
+ const returnObj = findReturnObject(exportedSetupFunc);
1774
+ if (returnObj) {
1775
+ appStateType = objectLiteralToTypeDefinition(returnObj, sourceFile);
1776
+ } else {
1777
+ logger.debug('Exported setup function found but no return object');
1778
+ }
1779
+ }
1780
+
1685
1781
  if (!foundCreateApp) {
1686
1782
  logger.debug('Did not find createApp call in app.ts');
1687
1783
  } else if (!foundSetup) {
@@ -1728,17 +1824,7 @@ async function updateTsconfigPathMapping(rootDir: string, shouldAdd: boolean): P
1728
1824
 
1729
1825
  if (shouldAdd) {
1730
1826
  // Add or update the path mapping
1731
- tsconfig.compilerOptions.paths['@agentuity/runtime'] = [
1732
- './.agentuity/.agentuity_runtime.ts',
1733
- ];
1734
-
1735
- // Ensure .agentuity_types.ts is included so module augmentation works
1736
- if (!tsconfig.include) {
1737
- tsconfig.include = [];
1738
- }
1739
- if (!tsconfig.include.includes('.agentuity/.agentuity_types.ts')) {
1740
- tsconfig.include.push('.agentuity/.agentuity_types.ts');
1741
- }
1827
+ tsconfig.compilerOptions.paths['@agentuity/runtime'] = ['./src/generated/router.ts'];
1742
1828
 
1743
1829
  logger.debug('Added @agentuity/runtime path mapping to tsconfig.json');
1744
1830
  } else {
@@ -1769,9 +1855,10 @@ async function updateTsconfigPathMapping(rootDir: string, shouldAdd: boolean): P
1769
1855
  const RuntimePackageNotFound = StructuredError('RuntimePackageNotFound');
1770
1856
 
1771
1857
  /**
1772
- * Generate lifecycle type files (.agentuity/types.ts and .agentuity/.agentuity_runtime.ts)
1858
+ * Generate lifecycle type files (src/generated/state.ts and src/generated/router.ts)
1773
1859
  *
1774
1860
  * @param rootDir - Root directory of the project
1861
+ * @param outDir - Output directory (typically src/generated/)
1775
1862
  * @param appFilePath - Path to app.ts file
1776
1863
  * @returns true if files were generated, false if no setup found
1777
1864
  */
@@ -1794,44 +1881,60 @@ export async function generateLifecycleTypes(
1794
1881
  return false;
1795
1882
  }
1796
1883
 
1797
- const agentuityDir = join(rootDir, '.agentuity');
1884
+ // Ensure output directory exists (now src/generated instead of .agentuity)
1885
+ if (!existsSync(outDir)) {
1886
+ mkdirSync(outDir, { recursive: true });
1887
+ }
1888
+
1889
+ // Find @agentuity/runtime by walking up directory tree
1890
+ // This works in any project structure - monorepos, nested projects, etc.
1891
+ let runtimePkgPath: string | null = null;
1892
+ let currentDir = rootDir;
1893
+ const searchedPaths: string[] = [];
1894
+
1895
+ while (currentDir && currentDir !== '/' && currentDir !== '.') {
1896
+ const candidatePath = join(currentDir, 'node_modules', '@agentuity', 'runtime');
1897
+ searchedPaths.push(candidatePath);
1898
+
1899
+ if (existsSync(candidatePath)) {
1900
+ runtimePkgPath = candidatePath;
1901
+ logger.debug(`Found runtime package at: ${candidatePath}`);
1902
+ break;
1903
+ }
1904
+
1905
+ // Try packages/ for monorepo source layout
1906
+ const packagesPath = join(currentDir, 'packages', 'runtime');
1907
+ searchedPaths.push(packagesPath);
1908
+
1909
+ if (existsSync(packagesPath)) {
1910
+ runtimePkgPath = packagesPath;
1911
+ logger.debug(`Found runtime package (source) at: ${packagesPath}`);
1912
+ break;
1913
+ }
1798
1914
 
1799
- // Ensure .agentuity directory exists
1800
- if (!existsSync(agentuityDir)) {
1801
- mkdirSync(agentuityDir, { recursive: true });
1915
+ // Move up one directory
1916
+ const parent = dirname(currentDir);
1917
+ if (parent === currentDir) break; // Reached root
1918
+ currentDir = parent;
1802
1919
  }
1803
1920
 
1804
- // First, determine the runtime package location
1805
- // Try multiple locations: app-level node_modules, then monorepo root
1806
- const appLevelPath = join(rootDir, 'node_modules', '@agentuity', 'runtime');
1807
- // From apps/testing/auth-app to monorepo root is 3 levels up (../../..)
1808
- const rootLevelPath = join(rootDir, '..', '..', '..', 'node_modules', '@agentuity', 'runtime');
1809
-
1810
- let runtimePkgPath: string;
1811
- if (existsSync(appLevelPath)) {
1812
- runtimePkgPath = appLevelPath;
1813
- logger.debug(`Found runtime package at app level: ${appLevelPath}`);
1814
- } else if (existsSync(rootLevelPath)) {
1815
- runtimePkgPath = rootLevelPath;
1816
- logger.debug(`Found runtime package at root level: ${rootLevelPath}`);
1817
- } else {
1921
+ if (!runtimePkgPath) {
1818
1922
  throw new RuntimePackageNotFound({
1819
1923
  message:
1820
- `@agentuity/runtime package not found in:\n` +
1821
- ` - ${appLevelPath}\n` +
1822
- ` - ${rootLevelPath}\n` +
1924
+ `@agentuity/runtime package not found.\n` +
1925
+ `Searched paths:\n${searchedPaths.map((p) => ` - ${p}`).join('\n')}\n` +
1823
1926
  `Make sure dependencies are installed by running 'bun install' or 'npm install'`,
1824
1927
  });
1825
1928
  }
1826
1929
 
1827
1930
  let runtimeImportPath: string | null = null;
1828
1931
 
1829
- // Calculate relative path from .agentuity/ to the package location
1932
+ // Calculate relative path from src/generated/ to the package location
1830
1933
  // Don't resolve symlinks - we want to use the symlink path so it works in both
1831
1934
  // local dev (symlinked to packages/) and CI (actual node_modules)
1832
1935
  if (existsSync(runtimePkgPath)) {
1833
- // Calculate relative path from .agentuity/ to node_modules package
1834
- const relPath = relative(agentuityDir, runtimePkgPath);
1936
+ // Calculate relative path from src/generated/ to node_modules package
1937
+ const relPath = relative(outDir, runtimePkgPath);
1835
1938
  runtimeImportPath = relPath;
1836
1939
  logger.debug(`Using relative path to runtime package: ${relPath}`);
1837
1940
  } else {
@@ -1848,10 +1951,11 @@ export async function generateLifecycleTypes(
1848
1951
  });
1849
1952
  }
1850
1953
 
1851
- // Now generate .agentuity_types.ts
1954
+ // Now generate state.ts with AppState type
1852
1955
  // NOTE: We can ONLY augment the package name, not relative paths
1853
1956
  // TypeScript resolves @agentuity/runtime through path mapping -> wrapper -> actual package
1854
- const typesContent = `// AUTO-GENERATED from app.ts setup() return type
1957
+ const typesContent = `// @generated
1958
+ // AUTO-GENERATED from app.ts setup() return type
1855
1959
  // This file is auto-generated by the build tool - do not edit manually
1856
1960
 
1857
1961
  /**
@@ -1877,17 +1981,22 @@ export type GeneratedAppState = ${appStateType};
1877
1981
  declare module '@agentuity/runtime' {
1878
1982
  interface AppState extends GeneratedAppState {}
1879
1983
  }
1984
+
1985
+ // FOUND AN ERROR IN THIS FILE?
1986
+ // Please file an issue at https://github.com/agentuity/sdk/issues
1987
+ // or if you know the fix please submit a PR!
1880
1988
  `;
1881
- const typesPath = join(outDir, '.agentuity_types.ts');
1989
+ const typesPath = join(outDir, 'state.ts');
1882
1990
  await Bun.write(typesPath, typesContent);
1883
1991
  logger.debug(`Generated lifecycle types: ${typesPath}`);
1884
1992
 
1885
- const wrapperContent = `// AUTO-GENERATED runtime wrapper
1993
+ const wrapperContent = `// @generated
1994
+ // AUTO-GENERATED runtime wrapper
1886
1995
  // This file is auto-generated by the build tool - do not edit manually
1887
1996
 
1888
1997
  // Import augmentations file (NOT type-only) to trigger module augmentation
1889
- import type { GeneratedAppState } from './.agentuity_types';
1890
- import './.agentuity_types';
1998
+ import type { GeneratedAppState } from './state';
1999
+ import './state';
1891
2000
 
1892
2001
  // Import from actual package location
1893
2002
  import { createRouter as baseCreateRouter, type Env } from '${runtimeImportPath}/src/index';
@@ -1929,13 +2038,17 @@ type AppRouter = Hono<AppEnv>;
1929
2038
  * \`\`\`
1930
2039
  */
1931
2040
  export function createRouter(): AppRouter {
1932
- return baseCreateRouter() as any;
2041
+ return baseCreateRouter() as unknown as AppRouter;
1933
2042
  }
1934
2043
 
1935
2044
  // Re-export everything else
1936
2045
  export * from '${runtimeImportPath}/src/index';
2046
+
2047
+ // FOUND AN ERROR IN THIS FILE?
2048
+ // Please file an issue at https://github.com/agentuity/sdk/issues
2049
+ // or if you know the fix please submit a PR!
1937
2050
  `;
1938
- const wrapperPath = join(outDir, '.agentuity_runtime.ts');
2051
+ const wrapperPath = join(outDir, 'router.ts');
1939
2052
  await Bun.write(wrapperPath, wrapperContent);
1940
2053
  logger.debug(`Generated lifecycle wrapper: ${wrapperPath}`);
1941
2054