@agentuity/cli 0.1.9 → 0.1.10

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 (311) hide show
  1. package/README.md +2 -2
  2. package/bin/cli.ts +8 -0
  3. package/dist/cache/index.d.ts +2 -0
  4. package/dist/cache/index.d.ts.map +1 -0
  5. package/dist/cache/index.js +2 -0
  6. package/dist/cache/index.js.map +1 -0
  7. package/dist/cache/resource-region.d.ts +46 -0
  8. package/dist/cache/resource-region.d.ts.map +1 -0
  9. package/dist/cache/resource-region.js +115 -0
  10. package/dist/cache/resource-region.js.map +1 -0
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +44 -32
  13. package/dist/cli.js.map +1 -1
  14. package/dist/cmd/ai/capabilities/show.d.ts.map +1 -1
  15. package/dist/cmd/ai/capabilities/show.js +12 -15
  16. package/dist/cmd/ai/capabilities/show.js.map +1 -1
  17. package/dist/cmd/ai/prompt/llm.js +5 -5
  18. package/dist/cmd/ai/prompt/llm.js.map +1 -1
  19. package/dist/cmd/auth/logout.d.ts.map +1 -1
  20. package/dist/cmd/auth/logout.js +5 -2
  21. package/dist/cmd/auth/logout.js.map +1 -1
  22. package/dist/cmd/build/ast.d.ts.map +1 -1
  23. package/dist/cmd/build/ast.js +87 -1
  24. package/dist/cmd/build/ast.js.map +1 -1
  25. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  26. package/dist/cmd/build/vite/vite-asset-server-config.js +8 -3
  27. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  28. package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -1
  29. package/dist/cmd/build/vite/vite-asset-server.js +5 -3
  30. package/dist/cmd/build/vite/vite-asset-server.js.map +1 -1
  31. package/dist/cmd/cloud/db/delete.d.ts.map +1 -1
  32. package/dist/cmd/cloud/db/delete.js +69 -11
  33. package/dist/cmd/cloud/db/delete.js.map +1 -1
  34. package/dist/cmd/cloud/db/get.d.ts.map +1 -1
  35. package/dist/cmd/cloud/db/get.js +23 -7
  36. package/dist/cmd/cloud/db/get.js.map +1 -1
  37. package/dist/cmd/cloud/db/list.d.ts.map +1 -1
  38. package/dist/cmd/cloud/db/list.js +15 -7
  39. package/dist/cmd/cloud/db/list.js.map +1 -1
  40. package/dist/cmd/cloud/db/logs.d.ts.map +1 -1
  41. package/dist/cmd/cloud/db/logs.js +24 -4
  42. package/dist/cmd/cloud/db/logs.js.map +1 -1
  43. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  44. package/dist/cmd/cloud/deploy.js +38 -0
  45. package/dist/cmd/cloud/deploy.js.map +1 -1
  46. package/dist/cmd/cloud/env/delete.d.ts.map +1 -1
  47. package/dist/cmd/cloud/env/delete.js +30 -13
  48. package/dist/cmd/cloud/env/delete.js.map +1 -1
  49. package/dist/cmd/cloud/env/get.d.ts.map +1 -1
  50. package/dist/cmd/cloud/env/get.js +27 -30
  51. package/dist/cmd/cloud/env/get.js.map +1 -1
  52. package/dist/cmd/cloud/env/import.d.ts.map +1 -1
  53. package/dist/cmd/cloud/env/import.js +41 -48
  54. package/dist/cmd/cloud/env/import.js.map +1 -1
  55. package/dist/cmd/cloud/env/index.d.ts.map +1 -1
  56. package/dist/cmd/cloud/env/index.js +6 -2
  57. package/dist/cmd/cloud/env/index.js.map +1 -1
  58. package/dist/cmd/cloud/env/list.d.ts.map +1 -1
  59. package/dist/cmd/cloud/env/list.js +51 -28
  60. package/dist/cmd/cloud/env/list.js.map +1 -1
  61. package/dist/cmd/cloud/env/pull.d.ts.map +1 -1
  62. package/dist/cmd/cloud/env/pull.js +3 -3
  63. package/dist/cmd/cloud/env/pull.js.map +1 -1
  64. package/dist/cmd/cloud/env/push.d.ts.map +1 -1
  65. package/dist/cmd/cloud/env/push.js +31 -11
  66. package/dist/cmd/cloud/env/push.js.map +1 -1
  67. package/dist/cmd/cloud/env/set.d.ts.map +1 -1
  68. package/dist/cmd/cloud/env/set.js +41 -26
  69. package/dist/cmd/cloud/env/set.js.map +1 -1
  70. package/dist/cmd/cloud/index.d.ts.map +1 -1
  71. package/dist/cmd/cloud/index.js +0 -2
  72. package/dist/cmd/cloud/index.js.map +1 -1
  73. package/dist/cmd/cloud/region-lookup.d.ts +18 -0
  74. package/dist/cmd/cloud/region-lookup.d.ts.map +1 -0
  75. package/dist/cmd/cloud/region-lookup.js +64 -0
  76. package/dist/cmd/cloud/region-lookup.js.map +1 -0
  77. package/dist/cmd/cloud/sandbox/cp.d.ts.map +1 -1
  78. package/dist/cmd/cloud/sandbox/cp.js +5 -3
  79. package/dist/cmd/cloud/sandbox/cp.js.map +1 -1
  80. package/dist/cmd/cloud/sandbox/create.d.ts.map +1 -1
  81. package/dist/cmd/cloud/sandbox/create.js +43 -6
  82. package/dist/cmd/cloud/sandbox/create.js.map +1 -1
  83. package/dist/cmd/cloud/sandbox/delete.d.ts.map +1 -1
  84. package/dist/cmd/cloud/sandbox/delete.js +5 -3
  85. package/dist/cmd/cloud/sandbox/delete.js.map +1 -1
  86. package/dist/cmd/cloud/sandbox/download.d.ts.map +1 -1
  87. package/dist/cmd/cloud/sandbox/download.js +4 -3
  88. package/dist/cmd/cloud/sandbox/download.js.map +1 -1
  89. package/dist/cmd/cloud/sandbox/env.d.ts.map +1 -1
  90. package/dist/cmd/cloud/sandbox/env.js +4 -3
  91. package/dist/cmd/cloud/sandbox/env.js.map +1 -1
  92. package/dist/cmd/cloud/sandbox/exec.d.ts.map +1 -1
  93. package/dist/cmd/cloud/sandbox/exec.js +4 -3
  94. package/dist/cmd/cloud/sandbox/exec.js.map +1 -1
  95. package/dist/cmd/cloud/sandbox/execution/get.js +4 -4
  96. package/dist/cmd/cloud/sandbox/execution/get.js.map +1 -1
  97. package/dist/cmd/cloud/sandbox/execution/index.js +1 -1
  98. package/dist/cmd/cloud/sandbox/execution/index.js.map +1 -1
  99. package/dist/cmd/cloud/sandbox/execution/list.d.ts.map +1 -1
  100. package/dist/cmd/cloud/sandbox/execution/list.js +4 -3
  101. package/dist/cmd/cloud/sandbox/execution/list.js.map +1 -1
  102. package/dist/cmd/cloud/sandbox/get.d.ts.map +1 -1
  103. package/dist/cmd/cloud/sandbox/get.js +9 -4
  104. package/dist/cmd/cloud/sandbox/get.js.map +1 -1
  105. package/dist/cmd/cloud/sandbox/index.js +1 -1
  106. package/dist/cmd/cloud/sandbox/index.js.map +1 -1
  107. package/dist/cmd/cloud/sandbox/list.js +4 -4
  108. package/dist/cmd/cloud/sandbox/list.js.map +1 -1
  109. package/dist/cmd/cloud/sandbox/ls.d.ts.map +1 -1
  110. package/dist/cmd/cloud/sandbox/ls.js +4 -3
  111. package/dist/cmd/cloud/sandbox/ls.js.map +1 -1
  112. package/dist/cmd/cloud/sandbox/mkdir.d.ts.map +1 -1
  113. package/dist/cmd/cloud/sandbox/mkdir.js +4 -3
  114. package/dist/cmd/cloud/sandbox/mkdir.js.map +1 -1
  115. package/dist/cmd/cloud/sandbox/rm.d.ts.map +1 -1
  116. package/dist/cmd/cloud/sandbox/rm.js +4 -3
  117. package/dist/cmd/cloud/sandbox/rm.js.map +1 -1
  118. package/dist/cmd/cloud/sandbox/rmdir.d.ts.map +1 -1
  119. package/dist/cmd/cloud/sandbox/rmdir.js +4 -3
  120. package/dist/cmd/cloud/sandbox/rmdir.js.map +1 -1
  121. package/dist/cmd/cloud/sandbox/run.d.ts.map +1 -1
  122. package/dist/cmd/cloud/sandbox/run.js +44 -6
  123. package/dist/cmd/cloud/sandbox/run.js.map +1 -1
  124. package/dist/cmd/cloud/sandbox/runtime/index.js +1 -1
  125. package/dist/cmd/cloud/sandbox/runtime/index.js.map +1 -1
  126. package/dist/cmd/cloud/sandbox/runtime/list.js +4 -4
  127. package/dist/cmd/cloud/sandbox/runtime/list.js.map +1 -1
  128. package/dist/cmd/cloud/sandbox/snapshot/create.d.ts.map +1 -1
  129. package/dist/cmd/cloud/sandbox/snapshot/create.js +5 -3
  130. package/dist/cmd/cloud/sandbox/snapshot/create.js.map +1 -1
  131. package/dist/cmd/cloud/sandbox/snapshot/delete.js +4 -4
  132. package/dist/cmd/cloud/sandbox/snapshot/delete.js.map +1 -1
  133. package/dist/cmd/cloud/sandbox/snapshot/get.js +4 -4
  134. package/dist/cmd/cloud/sandbox/snapshot/get.js.map +1 -1
  135. package/dist/cmd/cloud/sandbox/snapshot/index.js +1 -1
  136. package/dist/cmd/cloud/sandbox/snapshot/index.js.map +1 -1
  137. package/dist/cmd/cloud/sandbox/snapshot/list.js +4 -4
  138. package/dist/cmd/cloud/sandbox/snapshot/list.js.map +1 -1
  139. package/dist/cmd/cloud/sandbox/snapshot/tag.d.ts.map +1 -1
  140. package/dist/cmd/cloud/sandbox/snapshot/tag.js +4 -4
  141. package/dist/cmd/cloud/sandbox/snapshot/tag.js.map +1 -1
  142. package/dist/cmd/cloud/sandbox/upload.d.ts.map +1 -1
  143. package/dist/cmd/cloud/sandbox/upload.js +4 -3
  144. package/dist/cmd/cloud/sandbox/upload.js.map +1 -1
  145. package/dist/cmd/cloud/sandbox/util.d.ts +13 -0
  146. package/dist/cmd/cloud/sandbox/util.d.ts.map +1 -1
  147. package/dist/cmd/cloud/sandbox/util.js +40 -1
  148. package/dist/cmd/cloud/sandbox/util.js.map +1 -1
  149. package/dist/cmd/cloud/scp/download.d.ts.map +1 -1
  150. package/dist/cmd/cloud/scp/download.js +6 -2
  151. package/dist/cmd/cloud/scp/download.js.map +1 -1
  152. package/dist/cmd/cloud/scp/upload.d.ts.map +1 -1
  153. package/dist/cmd/cloud/scp/upload.js +6 -2
  154. package/dist/cmd/cloud/scp/upload.js.map +1 -1
  155. package/dist/cmd/cloud/session/get.js +4 -4
  156. package/dist/cmd/cloud/session/get.js.map +1 -1
  157. package/dist/cmd/cloud/session/list.js +4 -4
  158. package/dist/cmd/cloud/session/list.js.map +1 -1
  159. package/dist/cmd/cloud/ssh.d.ts.map +1 -1
  160. package/dist/cmd/cloud/ssh.js +7 -2
  161. package/dist/cmd/cloud/ssh.js.map +1 -1
  162. package/dist/cmd/cloud/storage/delete.d.ts.map +1 -1
  163. package/dist/cmd/cloud/storage/delete.js +46 -10
  164. package/dist/cmd/cloud/storage/delete.js.map +1 -1
  165. package/dist/cmd/cloud/storage/download.d.ts.map +1 -1
  166. package/dist/cmd/cloud/storage/download.js +19 -6
  167. package/dist/cmd/cloud/storage/download.js.map +1 -1
  168. package/dist/cmd/cloud/storage/get.d.ts.map +1 -1
  169. package/dist/cmd/cloud/storage/get.js +19 -6
  170. package/dist/cmd/cloud/storage/get.js.map +1 -1
  171. package/dist/cmd/cloud/storage/list.d.ts.map +1 -1
  172. package/dist/cmd/cloud/storage/list.js +17 -7
  173. package/dist/cmd/cloud/storage/list.js.map +1 -1
  174. package/dist/cmd/cloud/storage/upload.d.ts.map +1 -1
  175. package/dist/cmd/cloud/storage/upload.js +19 -6
  176. package/dist/cmd/cloud/storage/upload.js.map +1 -1
  177. package/dist/cmd/cloud/thread/delete.js +4 -4
  178. package/dist/cmd/cloud/thread/delete.js.map +1 -1
  179. package/dist/cmd/cloud/thread/get.js +4 -4
  180. package/dist/cmd/cloud/thread/get.js.map +1 -1
  181. package/dist/cmd/cloud/thread/list.js +4 -4
  182. package/dist/cmd/cloud/thread/list.js.map +1 -1
  183. package/dist/cmd/project/auth/init.d.ts.map +1 -1
  184. package/dist/cmd/project/auth/init.js +6 -3
  185. package/dist/cmd/project/auth/init.js.map +1 -1
  186. package/dist/cmd/project/auth/shared.d.ts +6 -2
  187. package/dist/cmd/project/auth/shared.d.ts.map +1 -1
  188. package/dist/cmd/project/auth/shared.js +40 -12
  189. package/dist/cmd/project/auth/shared.js.map +1 -1
  190. package/dist/config.d.ts +37 -0
  191. package/dist/config.d.ts.map +1 -1
  192. package/dist/config.js +51 -8
  193. package/dist/config.js.map +1 -1
  194. package/dist/env-util.d.ts +25 -2
  195. package/dist/env-util.d.ts.map +1 -1
  196. package/dist/env-util.js +44 -4
  197. package/dist/env-util.js.map +1 -1
  198. package/dist/utils/apt-validator.d.ts +20 -0
  199. package/dist/utils/apt-validator.d.ts.map +1 -0
  200. package/dist/utils/apt-validator.js +157 -0
  201. package/dist/utils/apt-validator.js.map +1 -0
  202. package/package.json +6 -6
  203. package/src/cache/index.ts +11 -0
  204. package/src/cache/resource-region.ts +183 -0
  205. package/src/cli.ts +47 -38
  206. package/src/cmd/ai/capabilities/show.ts +12 -15
  207. package/src/cmd/ai/prompt/llm.ts +5 -5
  208. package/src/cmd/auth/logout.ts +5 -2
  209. package/src/cmd/build/ast.ts +160 -1
  210. package/src/cmd/build/vite/vite-asset-server-config.ts +7 -3
  211. package/src/cmd/build/vite/vite-asset-server.ts +6 -3
  212. package/src/cmd/cloud/db/delete.ts +83 -11
  213. package/src/cmd/cloud/db/get.ts +29 -7
  214. package/src/cmd/cloud/db/list.ts +16 -7
  215. package/src/cmd/cloud/db/logs.ts +33 -4
  216. package/src/cmd/cloud/deploy.ts +49 -0
  217. package/src/cmd/cloud/env/delete.ts +36 -12
  218. package/src/cmd/cloud/env/get.ts +28 -27
  219. package/src/cmd/cloud/env/import.ts +43 -56
  220. package/src/cmd/cloud/env/index.ts +6 -2
  221. package/src/cmd/cloud/env/list.ts +57 -30
  222. package/src/cmd/cloud/env/pull.ts +9 -3
  223. package/src/cmd/cloud/env/push.ts +44 -11
  224. package/src/cmd/cloud/env/set.ts +49 -30
  225. package/src/cmd/cloud/index.ts +0 -2
  226. package/src/cmd/cloud/region-lookup.ts +89 -0
  227. package/src/cmd/cloud/sandbox/cp.ts +5 -3
  228. package/src/cmd/cloud/sandbox/create.ts +50 -6
  229. package/src/cmd/cloud/sandbox/delete.ts +6 -3
  230. package/src/cmd/cloud/sandbox/download.ts +4 -3
  231. package/src/cmd/cloud/sandbox/env.ts +4 -3
  232. package/src/cmd/cloud/sandbox/exec.ts +4 -3
  233. package/src/cmd/cloud/sandbox/execution/get.ts +4 -4
  234. package/src/cmd/cloud/sandbox/execution/index.ts +1 -1
  235. package/src/cmd/cloud/sandbox/execution/list.ts +4 -3
  236. package/src/cmd/cloud/sandbox/get.ts +10 -4
  237. package/src/cmd/cloud/sandbox/index.ts +1 -1
  238. package/src/cmd/cloud/sandbox/list.ts +4 -4
  239. package/src/cmd/cloud/sandbox/ls.ts +4 -3
  240. package/src/cmd/cloud/sandbox/mkdir.ts +4 -3
  241. package/src/cmd/cloud/sandbox/rm.ts +4 -3
  242. package/src/cmd/cloud/sandbox/rmdir.ts +4 -3
  243. package/src/cmd/cloud/sandbox/run.ts +51 -6
  244. package/src/cmd/cloud/sandbox/runtime/index.ts +1 -1
  245. package/src/cmd/cloud/sandbox/runtime/list.ts +4 -4
  246. package/src/cmd/cloud/sandbox/snapshot/create.ts +11 -5
  247. package/src/cmd/cloud/sandbox/snapshot/delete.ts +4 -4
  248. package/src/cmd/cloud/sandbox/snapshot/get.ts +4 -4
  249. package/src/cmd/cloud/sandbox/snapshot/index.ts +1 -1
  250. package/src/cmd/cloud/sandbox/snapshot/list.ts +4 -4
  251. package/src/cmd/cloud/sandbox/snapshot/tag.ts +7 -5
  252. package/src/cmd/cloud/sandbox/upload.ts +4 -3
  253. package/src/cmd/cloud/sandbox/util.ts +60 -1
  254. package/src/cmd/cloud/scp/download.ts +14 -2
  255. package/src/cmd/cloud/scp/upload.ts +14 -2
  256. package/src/cmd/cloud/session/get.ts +4 -4
  257. package/src/cmd/cloud/session/list.ts +4 -4
  258. package/src/cmd/cloud/ssh.ts +15 -2
  259. package/src/cmd/cloud/storage/delete.ts +61 -10
  260. package/src/cmd/cloud/storage/download.ts +31 -6
  261. package/src/cmd/cloud/storage/get.ts +31 -6
  262. package/src/cmd/cloud/storage/list.ts +18 -7
  263. package/src/cmd/cloud/storage/upload.ts +31 -6
  264. package/src/cmd/cloud/thread/delete.ts +4 -4
  265. package/src/cmd/cloud/thread/get.ts +4 -4
  266. package/src/cmd/cloud/thread/list.ts +4 -4
  267. package/src/cmd/project/auth/init.ts +7 -3
  268. package/src/cmd/project/auth/shared.ts +52 -13
  269. package/src/config.ts +64 -8
  270. package/src/env-util.ts +50 -5
  271. package/src/utils/apt-validator.ts +215 -0
  272. package/dist/cmd/cloud/secret/delete.d.ts +0 -2
  273. package/dist/cmd/cloud/secret/delete.d.ts.map +0 -1
  274. package/dist/cmd/cloud/secret/delete.js +0 -53
  275. package/dist/cmd/cloud/secret/delete.js.map +0 -1
  276. package/dist/cmd/cloud/secret/get.d.ts +0 -2
  277. package/dist/cmd/cloud/secret/get.d.ts.map +0 -1
  278. package/dist/cmd/cloud/secret/get.js +0 -73
  279. package/dist/cmd/cloud/secret/get.js.map +0 -1
  280. package/dist/cmd/cloud/secret/import.d.ts +0 -2
  281. package/dist/cmd/cloud/secret/import.d.ts.map +0 -1
  282. package/dist/cmd/cloud/secret/import.js +0 -91
  283. package/dist/cmd/cloud/secret/import.js.map +0 -1
  284. package/dist/cmd/cloud/secret/index.d.ts +0 -3
  285. package/dist/cmd/cloud/secret/index.d.ts.map +0 -1
  286. package/dist/cmd/cloud/secret/index.js +0 -33
  287. package/dist/cmd/cloud/secret/index.js.map +0 -1
  288. package/dist/cmd/cloud/secret/list.d.ts +0 -2
  289. package/dist/cmd/cloud/secret/list.d.ts.map +0 -1
  290. package/dist/cmd/cloud/secret/list.js +0 -65
  291. package/dist/cmd/cloud/secret/list.js.map +0 -1
  292. package/dist/cmd/cloud/secret/pull.d.ts +0 -2
  293. package/dist/cmd/cloud/secret/pull.d.ts.map +0 -1
  294. package/dist/cmd/cloud/secret/pull.js +0 -82
  295. package/dist/cmd/cloud/secret/pull.js.map +0 -1
  296. package/dist/cmd/cloud/secret/push.d.ts +0 -2
  297. package/dist/cmd/cloud/secret/push.d.ts.map +0 -1
  298. package/dist/cmd/cloud/secret/push.js +0 -61
  299. package/dist/cmd/cloud/secret/push.js.map +0 -1
  300. package/dist/cmd/cloud/secret/set.d.ts +0 -2
  301. package/dist/cmd/cloud/secret/set.d.ts.map +0 -1
  302. package/dist/cmd/cloud/secret/set.js +0 -63
  303. package/dist/cmd/cloud/secret/set.js.map +0 -1
  304. package/src/cmd/cloud/secret/delete.ts +0 -65
  305. package/src/cmd/cloud/secret/get.ts +0 -77
  306. package/src/cmd/cloud/secret/import.ts +0 -110
  307. package/src/cmd/cloud/secret/index.ts +0 -33
  308. package/src/cmd/cloud/secret/list.ts +0 -70
  309. package/src/cmd/cloud/secret/pull.ts +0 -92
  310. package/src/cmd/cloud/secret/push.ts +0 -69
  311. package/src/cmd/cloud/secret/set.ts +0 -76
@@ -191,7 +191,7 @@ ${getCommand('project create')}
191
191
  ${getCommand('auth signup')}
192
192
  ${getCommand('auth login')}
193
193
  ${getCommand('project create')}
194
- ${getCommand('secret set API_KEY <value>')}
194
+ ${getCommand('env set API_KEY <value> --secret')}
195
195
  \`\`\`
196
196
 
197
197
  ### 2. Deploy Application
@@ -211,12 +211,12 @@ ${getCommand('cloud deploy')}
211
211
  ${getCommand('--json cloud deployment show')}
212
212
  \`\`\`
213
213
 
214
- ### 3. Manage Secrets
214
+ ### 3. Manage Environment Variables & Secrets
215
215
 
216
216
  \`\`\`bash
217
- ${getCommand('--json secret list')}
218
- ${getCommand('secret set DATABASE_URL <value>')}
219
- ${getCommand('secret get DATABASE_URL')}
217
+ ${getCommand('--json env list')}
218
+ ${getCommand('env set DATABASE_URL <value> --secret')}
219
+ ${getCommand('env get DATABASE_URL')}
220
220
  \`\`\`
221
221
 
222
222
  ### 4. List Resources
@@ -14,8 +14,11 @@ export const logoutCommand = createSubcommand({
14
14
  { command: getCommand('logout'), description: 'Logout from account' },
15
15
  ],
16
16
 
17
- async handler() {
17
+ async handler(ctx) {
18
+ const { options } = ctx;
18
19
  await clearAuth();
19
- tui.success('You have been logged out');
20
+ if (!options.json) {
21
+ tui.success('You have been logged out');
22
+ }
20
23
  },
21
24
  });
@@ -941,6 +941,102 @@ const InvalidRouterConfigError = StructuredError('InvalidRouterConfigError')<{
941
941
  line?: number;
942
942
  }>();
943
943
 
944
+ const SchemaNotExportedError = StructuredError('SchemaNotExportedError')<{
945
+ filename: string;
946
+ schemaName: string;
947
+ kind: 'input' | 'output';
948
+ method?: string;
949
+ path?: string;
950
+ }>();
951
+
952
+ /**
953
+ * Build a set of exported identifiers from the top-level program.
954
+ * Handles both `export const X = ...` and `export { X }` patterns.
955
+ */
956
+ function buildExportedIdentifierSet(program: ASTProgram): Set<string> {
957
+ const exported = new Set<string>();
958
+
959
+ for (const node of program.body) {
960
+ if (node.type === 'ExportNamedDeclaration') {
961
+ const exp = node as unknown as {
962
+ declaration?: ASTNode;
963
+ specifiers?: Array<{ local?: ASTNodeIdentifier; exported?: ASTNodeIdentifier }>;
964
+ };
965
+
966
+ // Handle `export const X = ...` or `export function X() { ... }` or `export class X { ... }`
967
+ if (exp.declaration) {
968
+ if (exp.declaration.type === 'VariableDeclaration') {
969
+ const decl = exp.declaration as unknown as { declarations: ASTVariableDeclarator[] };
970
+ for (const d of decl.declarations) {
971
+ if (d.id.type === 'Identifier') {
972
+ const id = d.id as ASTNodeIdentifier;
973
+ exported.add(id.name);
974
+ }
975
+ }
976
+ } else if (exp.declaration.type === 'FunctionDeclaration') {
977
+ const funcDecl = exp.declaration as unknown as { id?: ASTNodeIdentifier };
978
+ if (funcDecl.id?.name) {
979
+ exported.add(funcDecl.id.name);
980
+ }
981
+ } else if (exp.declaration.type === 'ClassDeclaration') {
982
+ const classDecl = exp.declaration as unknown as { id?: ASTNodeIdentifier };
983
+ if (classDecl.id?.name) {
984
+ exported.add(classDecl.id.name);
985
+ }
986
+ }
987
+ }
988
+
989
+ // Handle `export { X }` or `export { X as Y }`
990
+ if (exp.specifiers && Array.isArray(exp.specifiers)) {
991
+ for (const spec of exp.specifiers) {
992
+ // For `export { X }`, local.name is the variable name in this file
993
+ if (spec.local?.name) {
994
+ exported.add(spec.local.name);
995
+ }
996
+ }
997
+ }
998
+ }
999
+ }
1000
+
1001
+ return exported;
1002
+ }
1003
+
1004
+ /**
1005
+ * Validate that schema variables used in validators are either imported or exported.
1006
+ * Throws SchemaNotExportedError if a locally-defined schema is not exported.
1007
+ */
1008
+ function validateSchemaExports(
1009
+ schemaVariable: string | undefined,
1010
+ kind: 'input' | 'output',
1011
+ importedNames: Set<string>,
1012
+ exportedNames: Set<string>,
1013
+ filename: string,
1014
+ method?: string,
1015
+ path?: string
1016
+ ): void {
1017
+ if (!schemaVariable) return;
1018
+
1019
+ // If the schema is imported from another file, it's already exported from its source
1020
+ if (importedNames.has(schemaVariable)) return;
1021
+
1022
+ // If the schema is defined locally, it must be exported
1023
+ if (!exportedNames.has(schemaVariable)) {
1024
+ const routeDesc = method && path ? ` for route "${method.toUpperCase()} ${path}"` : '';
1025
+ throw new SchemaNotExportedError({
1026
+ filename,
1027
+ schemaName: schemaVariable,
1028
+ kind,
1029
+ method,
1030
+ path,
1031
+ message:
1032
+ `Schema "${schemaVariable}" used as the ${kind} validator${routeDesc} in ${filename} is not exported.\n\n` +
1033
+ `Agentuity generates a route registry that imports schema types by name, so the schema must be exported.\n\n` +
1034
+ `To fix this, add "export" to the schema declaration:\n\n` +
1035
+ ` export const ${schemaVariable} = s.object({ ... });\n`,
1036
+ });
1037
+ }
1038
+ }
1039
+
944
1040
  /**
945
1041
  * Check if an AST node contains a validator() call
946
1042
  */
@@ -1292,6 +1388,12 @@ export async function parseRoute(
1292
1388
  }
1293
1389
  }
1294
1390
 
1391
+ // Build set of imported names for schema export validation
1392
+ const importedNames = new Set(importMap.keys());
1393
+
1394
+ // Build set of exported identifiers for schema export validation
1395
+ const exportedNames = buildExportedIdentifierSet(ast as ASTProgram);
1396
+
1295
1397
  // Scan for exported schemas (for WebSocket/SSE routes)
1296
1398
  let exportedInputSchemaName: string | undefined;
1297
1399
  let exportedOutputSchemaName: string | undefined;
@@ -1496,6 +1598,25 @@ export async function parseRoute(
1496
1598
  routeConfig.agentImportPath = agentImportPath;
1497
1599
  }
1498
1600
  }
1601
+ // Validate that schema variables are exported (if defined locally)
1602
+ validateSchemaExports(
1603
+ validatorInfo.inputSchemaVariable,
1604
+ 'input',
1605
+ importedNames,
1606
+ exportedNames,
1607
+ rel,
1608
+ httpMethod,
1609
+ thepath
1610
+ );
1611
+ validateSchemaExports(
1612
+ validatorInfo.outputSchemaVariable,
1613
+ 'output',
1614
+ importedNames,
1615
+ exportedNames,
1616
+ rel,
1617
+ httpMethod,
1618
+ thepath
1619
+ );
1499
1620
  if (validatorInfo.inputSchemaVariable) {
1500
1621
  routeConfig.inputSchemaVariable =
1501
1622
  validatorInfo.inputSchemaVariable;
@@ -1557,6 +1678,25 @@ export async function parseRoute(
1557
1678
  routeConfig.agentImportPath = agentImportPath;
1558
1679
  }
1559
1680
  }
1681
+ // Validate that schema variables are exported (if defined locally)
1682
+ validateSchemaExports(
1683
+ validatorInfo.inputSchemaVariable,
1684
+ 'input',
1685
+ importedNames,
1686
+ exportedNames,
1687
+ rel,
1688
+ httpMethod,
1689
+ thepath
1690
+ );
1691
+ validateSchemaExports(
1692
+ validatorInfo.outputSchemaVariable,
1693
+ 'output',
1694
+ importedNames,
1695
+ exportedNames,
1696
+ rel,
1697
+ httpMethod,
1698
+ thepath
1699
+ );
1560
1700
  if (validatorInfo.inputSchemaVariable) {
1561
1701
  routeConfig.inputSchemaVariable =
1562
1702
  validatorInfo.inputSchemaVariable;
@@ -1718,6 +1858,25 @@ export async function parseRoute(
1718
1858
  routeConfig.agentImportPath = agentImportPath;
1719
1859
  }
1720
1860
  }
1861
+ // Validate that schema variables are exported (if defined locally)
1862
+ validateSchemaExports(
1863
+ validatorInfo.inputSchemaVariable,
1864
+ 'input',
1865
+ importedNames,
1866
+ exportedNames,
1867
+ rel,
1868
+ method,
1869
+ thepath
1870
+ );
1871
+ validateSchemaExports(
1872
+ validatorInfo.outputSchemaVariable,
1873
+ 'output',
1874
+ importedNames,
1875
+ exportedNames,
1876
+ rel,
1877
+ method,
1878
+ thepath
1879
+ );
1721
1880
  if (validatorInfo.inputSchemaVariable) {
1722
1881
  routeConfig.inputSchemaVariable = validatorInfo.inputSchemaVariable;
1723
1882
  }
@@ -1754,7 +1913,7 @@ export async function parseRoute(
1754
1913
  }
1755
1914
  }
1756
1915
  } catch (error) {
1757
- if (error instanceof InvalidRouterConfigError) {
1916
+ if (error instanceof InvalidRouterConfigError || error instanceof SchemaNotExportedError) {
1758
1917
  throw error;
1759
1918
  }
1760
1919
  throw new InvalidRouterConfigError({
@@ -94,11 +94,11 @@ export async function generateAssetServerConfig(
94
94
  },
95
95
 
96
96
  // HMR configuration - client must connect to Vite asset server directly
97
+ // Do NOT set port/clientPort - let Vite use the actual server port it binds to
98
+ // (important when strictPort: false and Vite falls back to an alternate port)
97
99
  hmr: {
98
100
  protocol: 'ws',
99
101
  host: '127.0.0.1',
100
- port, // HMR WebSocket on same port as HTTP
101
- clientPort: port, // Tell client to connect to this port (not origin 3500)
102
102
  },
103
103
 
104
104
  // Don't open browser - Bun server will be the entry point
@@ -151,7 +151,11 @@ export async function generateAssetServerConfig(
151
151
  // Custom logger to integrate with our logger
152
152
  customLogger: {
153
153
  info(msg: string) {
154
- if (!msg.includes('[vite]')) {
154
+ // Show port-related messages at info level (important for debugging port conflicts)
155
+ // Keep other Vite info messages (like HMR updates) at debug to avoid noise
156
+ if (msg.includes('Port') || msg.includes('port')) {
157
+ logger.info(`[Vite Asset] ${msg}`);
158
+ } else {
155
159
  logger.debug(`[Vite Asset] ${msg}`);
156
160
  }
157
161
  },
@@ -111,9 +111,12 @@ export async function startViteAssetServer(
111
111
  actualPort = getPortFromHttpServer() ?? preferredPort;
112
112
  }
113
113
 
114
- logger.debug(`✅ Vite asset server started on port ${actualPort}`);
115
- if (actualPort !== preferredPort) {
116
- logger.debug(`Port ${preferredPort} was taken, using ${actualPort} instead`);
114
+ if (actualPort === preferredPort) {
115
+ logger.info(`Vite asset server running on port ${actualPort}`);
116
+ } else {
117
+ logger.warn(
118
+ `Vite asset server running on port ${actualPort} (preferred port ${preferredPort} was in use)`
119
+ );
117
120
  }
118
121
  logger.debug(`Asset server will handle: HMR, React transformation, source maps`);
119
122
  logger.debug(`HMR WebSocket configured to connect to ws://127.0.0.1:${actualPort}`);
@@ -1,13 +1,14 @@
1
1
  import { z } from 'zod';
2
- import { listResources, deleteResources, APIError } from '@agentuity/server';
2
+ import { listOrgResources, listOrganizations, deleteResources, APIError } from '@agentuity/server';
3
3
  import enquirer from 'enquirer';
4
4
  import { createSubcommand } from '../../../types';
5
5
  import * as tui from '../../../tui';
6
- import { getCatalystAPIClient } from '../../../config';
6
+ import { getGlobalCatalystAPIClient, getCatalystAPIClient } from '../../../config';
7
7
  import { getCommand } from '../../../command-prefix';
8
8
  import { isDryRunMode, outputDryRun } from '../../../explain';
9
9
  import { ErrorCode } from '../../../errors';
10
10
  import { removeResourceEnvVars } from '../../../env-util';
11
+ import { getResourceInfo, setResourceInfo, deleteResourceRegion } from '../../../cache';
11
12
 
12
13
  export const deleteSubcommand = createSubcommand({
13
14
  name: 'delete',
@@ -15,7 +16,8 @@ export const deleteSubcommand = createSubcommand({
15
16
  description: 'Delete a database resource',
16
17
  tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth', 'requires-deployment'],
17
18
  idempotent: false,
18
- requires: { auth: true, org: true, region: true },
19
+ requires: { auth: true },
20
+ optional: { org: true },
19
21
  examples: [
20
22
  { command: getCommand('cloud db delete my-database'), description: 'Delete item' },
21
23
  { command: getCommand('cloud db rm my-database'), description: 'Delete item' },
@@ -36,21 +38,79 @@ export const deleteSubcommand = createSubcommand({
36
38
  },
37
39
 
38
40
  async handler(ctx) {
39
- const { logger, args, opts, orgId, region, auth, options } = ctx;
41
+ const { logger, args, opts, auth, options, config } = ctx;
40
42
 
41
- const catalystClient = getCatalystAPIClient(logger, auth, region);
43
+ const profileName = config?.name ?? 'production';
44
+ const catalystClient = await getGlobalCatalystAPIClient(logger, auth, profileName);
42
45
 
43
46
  let dbName = args.name;
44
47
 
45
- if (!dbName) {
46
- const resources = await tui.spinner({
47
- message: `Fetching databases for ${orgId} in ${region}`,
48
+ // If db name provided, try cache first for orgId
49
+ let orgId = ctx.orgId;
50
+ if (dbName && !orgId) {
51
+ const cachedInfo = await getResourceInfo('db', profileName, dbName);
52
+ orgId = cachedInfo?.orgId;
53
+ }
54
+
55
+ // For interactive selection (no db name), we need orgId
56
+ if (!dbName && !orgId) {
57
+ tui.fatal(
58
+ 'Organization required for interactive database selection. Specify --org-id or provide database name.',
59
+ ErrorCode.INVALID_ARGUMENT
60
+ );
61
+ }
62
+
63
+ // If we have a db name but no orgId, search across all user's orgs
64
+ let resources: Awaited<ReturnType<typeof listOrgResources>> | undefined;
65
+ if (dbName && !orgId) {
66
+ const orgs = await tui.spinner({
67
+ message: 'Searching for database across organizations...',
68
+ clearOnSuccess: true,
69
+ callback: async () => listOrganizations(catalystClient),
70
+ });
71
+
72
+ for (const org of orgs) {
73
+ const orgResources = await listOrgResources(catalystClient, {
74
+ type: 'db',
75
+ orgId: org.id,
76
+ });
77
+ // Cache all fetched databases
78
+ for (const db of orgResources.db) {
79
+ await setResourceInfo('db', profileName, db.name, db.cloud_region, org.id);
80
+ }
81
+ const found = orgResources.db.find((db) => db.name === dbName);
82
+ if (found) {
83
+ orgId = org.id;
84
+ resources = orgResources;
85
+ break;
86
+ }
87
+ }
88
+
89
+ if (!orgId) {
90
+ tui.fatal(
91
+ `Database '${dbName}' not found in any of your organizations.`,
92
+ ErrorCode.RESOURCE_NOT_FOUND
93
+ );
94
+ }
95
+ }
96
+
97
+ // Fetch databases if we haven't already (when orgId was known upfront)
98
+ if (!resources) {
99
+ resources = await tui.spinner({
100
+ message: `Fetching databases for ${orgId}`,
48
101
  clearOnSuccess: true,
49
102
  callback: async () => {
50
- return listResources(catalystClient, orgId, region!);
103
+ return listOrgResources(catalystClient, { type: 'db', orgId: orgId! });
51
104
  },
52
105
  });
53
106
 
107
+ // Cache all fetched databases
108
+ for (const db of resources.db) {
109
+ await setResourceInfo('db', profileName, db.name, db.cloud_region, orgId!);
110
+ }
111
+ }
112
+
113
+ if (!dbName) {
54
114
  if (resources.db.length === 0) {
55
115
  tui.info('No databases found to delete');
56
116
  return { success: false, name: '' };
@@ -69,9 +129,16 @@ export const deleteSubcommand = createSubcommand({
69
129
  dbName = response.db;
70
130
  }
71
131
 
132
+ // Find the database to get its region
133
+ const database = resources.db.find((db) => db.name === dbName);
134
+ if (!database) {
135
+ tui.fatal(`Database '${dbName}' not found`, ErrorCode.RESOURCE_NOT_FOUND);
136
+ }
137
+ const region = database.cloud_region;
138
+
72
139
  // Handle dry-run mode
73
140
  if (isDryRunMode(options)) {
74
- outputDryRun(`Would delete database: ${dbName}`, options);
141
+ outputDryRun(`Would delete database: ${dbName} (region: ${region})`, options);
75
142
  if (!options.json) {
76
143
  tui.newline();
77
144
  tui.info('[DRY RUN] Database deletion skipped');
@@ -99,11 +166,13 @@ export const deleteSubcommand = createSubcommand({
99
166
  }
100
167
 
101
168
  try {
169
+ // Use regional client for the delete operation
170
+ const regionalClient = getCatalystAPIClient(logger, auth, region);
102
171
  const deleted = await tui.spinner({
103
172
  message: `Deleting database ${dbName}`,
104
173
  clearOnSuccess: true,
105
174
  callback: async () => {
106
- return deleteResources(catalystClient, orgId, region!, [
175
+ return deleteResources(regionalClient, orgId!, region, [
107
176
  { type: 'db', name: dbName },
108
177
  ]);
109
178
  },
@@ -112,6 +181,9 @@ export const deleteSubcommand = createSubcommand({
112
181
  if (deleted.length > 0) {
113
182
  const resource = deleted[0];
114
183
 
184
+ // Clear cache entry for deleted database
185
+ await deleteResourceRegion('db', profileName, resource.name);
186
+
115
187
  // Remove env vars from .env if running inside a project
116
188
  if (ctx.projectDir && resource.env_keys.length > 0) {
117
189
  await removeResourceEnvVars(ctx.projectDir, resource.env_keys);
@@ -1,10 +1,11 @@
1
1
  import { z } from 'zod';
2
- import { listResources, dbTables, generateCreateTableSQL } from '@agentuity/server';
2
+ import { listOrgResources, dbTables, generateCreateTableSQL } from '@agentuity/server';
3
3
  import { createSubcommand } from '../../../types';
4
4
  import * as tui from '../../../tui';
5
- import { getCatalystAPIClient } from '../../../config';
5
+ import { getGlobalCatalystAPIClient, getCatalystAPIClient } from '../../../config';
6
6
  import { getCommand } from '../../../command-prefix';
7
7
  import { ErrorCode } from '../../../errors';
8
+ import { getResourceInfo, setResourceInfo } from '../../../cache';
8
9
 
9
10
  const DBGetResponseSchema = z
10
11
  .object({
@@ -22,7 +23,8 @@ export const getSubcommand = createSubcommand({
22
23
  aliases: ['show'],
23
24
  description: 'Show details about a specific database',
24
25
  tags: ['read-only', 'fast', 'requires-auth'],
25
- requires: { auth: true, org: true, region: true },
26
+ requires: { auth: true },
27
+ optional: { org: true },
26
28
  idempotent: true,
27
29
  examples: [
28
30
  { command: `${getCommand('cloud db get')} my-database`, description: 'Get database details' },
@@ -66,31 +68,51 @@ export const getSubcommand = createSubcommand({
66
68
  webUrl: (ctx) => `/services/database/${encodeURIComponent(ctx.args.name)}`,
67
69
 
68
70
  async handler(ctx) {
69
- const { logger, args, opts, options, orgId, region, auth } = ctx;
71
+ const { logger, args, opts, options, auth, config } = ctx;
70
72
 
71
- const catalystClient = getCatalystAPIClient(logger, auth, region);
73
+ const profileName = config?.name ?? 'production';
74
+ const globalClient = await getGlobalCatalystAPIClient(logger, auth, profileName);
75
+
76
+ // Check cache first for orgId
77
+ const cachedInfo = await getResourceInfo('db', profileName, args.name);
78
+ const orgId = ctx.orgId ?? cachedInfo?.orgId;
79
+
80
+ if (!orgId) {
81
+ tui.fatal(
82
+ `Organization not found for database '${args.name}'. Run 'agentuity cloud db list' first or specify --org-id.`,
83
+ ErrorCode.INVALID_ARGUMENT
84
+ );
85
+ }
72
86
 
73
87
  const resources = await tui.spinner({
74
88
  message: `Fetching database ${args.name}`,
75
89
  clearOnSuccess: true,
76
90
  callback: async () => {
77
- return listResources(catalystClient, orgId, region);
91
+ return listOrgResources(globalClient, { type: 'db', orgId });
78
92
  },
79
93
  });
80
94
 
81
95
  const db = resources.db.find((d) => d.name === args.name);
82
96
 
97
+ // Cache the database info for future lookups
98
+ if (db?.cloud_region) {
99
+ await setResourceInfo('db', profileName, db.name, db.cloud_region, orgId);
100
+ }
101
+
83
102
  if (!db) {
84
103
  tui.fatal(`Database '${args.name}' not found`, ErrorCode.RESOURCE_NOT_FOUND);
85
104
  }
86
105
 
87
106
  // If --tables flag is provided, fetch table schemas
107
+ // Need regional Catalyst for database operations
88
108
  if (opts.showTables) {
109
+ const region = db.cloud_region;
110
+ const regionalClient = getCatalystAPIClient(logger, auth, region);
89
111
  const tables = await tui.spinner({
90
112
  message: `Fetching table schemas for ${args.name}`,
91
113
  clearOnSuccess: true,
92
114
  callback: async () => {
93
- return dbTables(catalystClient, {
115
+ return dbTables(regionalClient, {
94
116
  database: args.name,
95
117
  orgId,
96
118
  region,
@@ -1,9 +1,10 @@
1
1
  import { z } from 'zod';
2
- import { listResources } from '@agentuity/server';
2
+ import { listOrgResources } from '@agentuity/server';
3
3
  import { createSubcommand } from '../../../types';
4
4
  import * as tui from '../../../tui';
5
- import { getCatalystAPIClient } from '../../../config';
5
+ import { getGlobalCatalystAPIClient } from '../../../config';
6
6
  import { getCommand } from '../../../command-prefix';
7
+ import { setResourceInfo } from '../../../cache';
7
8
 
8
9
  const DBListResponseSchema = z.object({
9
10
  databases: z
@@ -11,6 +12,7 @@ const DBListResponseSchema = z.object({
11
12
  z.object({
12
13
  name: z.string().describe('Database name'),
13
14
  url: z.string().optional().describe('Database connection URL'),
15
+ cloud_region: z.string().optional().describe('Cloud region where database is hosted'),
14
16
  })
15
17
  )
16
18
  .describe('List of database resources'),
@@ -21,7 +23,7 @@ export const listSubcommand = createSubcommand({
21
23
  aliases: ['ls'],
22
24
  description: 'List database resources',
23
25
  tags: ['read-only', 'fast', 'requires-auth'],
24
- requires: { auth: true, org: true, region: true },
26
+ requires: { auth: true, org: true },
25
27
  idempotent: true,
26
28
  examples: [
27
29
  { command: getCommand('cloud db list'), description: 'List items' },
@@ -47,18 +49,24 @@ export const listSubcommand = createSubcommand({
47
49
  webUrl: '/services/database',
48
50
 
49
51
  async handler(ctx) {
50
- const { logger, opts, options, orgId, region, auth } = ctx;
52
+ const { logger, opts, options, orgId, auth, config } = ctx;
51
53
 
52
- const catalystClient = getCatalystAPIClient(logger, auth, region);
54
+ const catalystClient = await getGlobalCatalystAPIClient(logger, auth, config?.name);
53
55
 
56
+ const profileName = config?.name ?? 'production';
54
57
  const resources = await tui.spinner({
55
- message: `Fetching databases for ${orgId} in ${region}`,
58
+ message: `Fetching databases for ${orgId}`,
56
59
  clearOnSuccess: true,
57
60
  callback: async () => {
58
- return listResources(catalystClient, orgId, region);
61
+ return listOrgResources(catalystClient, { type: 'db', orgId });
59
62
  },
60
63
  });
61
64
 
65
+ // Cache each database with its region and orgId for future lookups
66
+ for (const db of resources.db) {
67
+ await setResourceInfo('db', profileName, db.name, db.cloud_region, orgId);
68
+ }
69
+
62
70
  // Mask credentials in terminal output by default, unless --show-credentials is passed
63
71
  const shouldShowCredentials = opts.showCredentials === true;
64
72
  const shouldMask = !options.json && !shouldShowCredentials;
@@ -90,6 +98,7 @@ export const listSubcommand = createSubcommand({
90
98
  databases: resources.db.map((db) => ({
91
99
  name: db.name,
92
100
  url: db.url ?? undefined,
101
+ cloud_region: db.cloud_region,
93
102
  })),
94
103
  };
95
104
  },
@@ -1,10 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { createSubcommand } from '../../../types';
3
3
  import * as tui from '../../../tui';
4
- import { dbLogs, DbQueryLogSchema } from '@agentuity/server';
5
- import { getCatalystAPIClient } from '../../../config';
4
+ import { dbLogs, DbQueryLogSchema, listOrgResources } from '@agentuity/server';
5
+ import { getGlobalCatalystAPIClient, getCatalystAPIClient } from '../../../config';
6
6
  import { getCommand } from '../../../command-prefix';
7
7
  import { ErrorCode } from '../../../errors';
8
+ import { getResourceInfo, setResourceInfo } from '../../../cache';
8
9
 
9
10
  const DbLogsResponseSchema = z.array(DbQueryLogSchema);
10
11
 
@@ -51,7 +52,8 @@ export const logsSubcommand = createSubcommand({
51
52
  description: 'Show full formatted SQL on separate lines',
52
53
  },
53
54
  ],
54
- requires: { auth: true, org: true, region: true },
55
+ requires: { auth: true },
56
+ optional: { org: true },
55
57
  idempotent: true,
56
58
  schema: {
57
59
  args: z.object({
@@ -78,13 +80,40 @@ export const logsSubcommand = createSubcommand({
78
80
  response: DbLogsResponseSchema,
79
81
  },
80
82
  async handler(ctx) {
81
- const { args, options, orgId, region, logger, auth } = ctx;
83
+ const { args, options, logger, auth, config } = ctx;
82
84
  const showTimestamps = ctx.opts.timestamps ?? true;
83
85
  const showSessionId = ctx.opts.showSessionId ?? false;
84
86
  const showUsername = ctx.opts.showUsername ?? false;
85
87
  const prettySQL = ctx.opts.pretty ?? false;
86
88
 
89
+ const profileName = config?.name ?? 'production';
90
+
87
91
  try {
92
+ const globalClient = await getGlobalCatalystAPIClient(logger, auth, profileName);
93
+
94
+ // Check cache first for orgId
95
+ const cachedInfo = await getResourceInfo('db', profileName, args.database);
96
+ const orgId = ctx.orgId ?? cachedInfo?.orgId;
97
+
98
+ if (!orgId) {
99
+ tui.fatal(
100
+ `Organization not found for database '${args.database}'. Run 'agentuity cloud db list' first or specify --org-id.`,
101
+ ErrorCode.INVALID_ARGUMENT
102
+ );
103
+ }
104
+
105
+ // Look up the database to get its region
106
+ const resources = await listOrgResources(globalClient, { type: 'db', orgId });
107
+ const database = resources.db.find((db) => db.name === args.database);
108
+ if (!database) {
109
+ tui.fatal(`Database '${args.database}' not found`, ErrorCode.RESOURCE_NOT_FOUND);
110
+ }
111
+ const region = database.cloud_region;
112
+
113
+ // Cache the database info for future lookups
114
+ await setResourceInfo('db', profileName, database.name, region, orgId);
115
+
116
+ // Use regional client for logs (ClickHouse queries are region-specific)
88
117
  const catalystClient = getCatalystAPIClient(logger, auth, region);
89
118
 
90
119
  const logs = await dbLogs(catalystClient, {