@alexkroman1/aai-cli 0.10.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { l as resolveCwd, n as fileExists, t as ensureApiKeyInEnv } from "./_discover-CbHCotwB.mjs";
2
+ import { l as resolveCwd, n as ensureApiKeyInEnv, r as fileExists } from "./_discover-a8yIuqEp.mjs";
3
3
  import { readFileSync } from "node:fs";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
@@ -16,7 +16,7 @@ const sharedArgs = {
16
16
  server: {
17
17
  type: "string",
18
18
  alias: "s",
19
- description: "Server URL"
19
+ description: "Platform server URL"
20
20
  },
21
21
  yes: {
22
22
  type: "boolean",
@@ -35,9 +35,17 @@ function findPkgJson(dir) {
35
35
  const VERSION = JSON.parse(findPkgJson(cliDir)).version;
36
36
  async function ensureAgent(cwd, yes) {
37
37
  if (!await fileExists(path.join(cwd, "agent.ts"))) {
38
- const { runInitCommand } = await import("./init-Pa-YbNnJ.mjs");
39
- await runInitCommand({ yes }, { quiet: true });
38
+ const { runInitCommand } = await import("./init-CNoNUGRN.mjs");
39
+ return runInitCommand({ yes }, { quiet: true });
40
40
  }
41
+ return cwd;
42
+ }
43
+ /** Shared command setup: resolve cwd, optionally scaffold agent and check API key. */
44
+ async function setup(args, opts) {
45
+ let cwd = resolveCwd();
46
+ if (opts?.agent) cwd = await ensureAgent(cwd, args?.yes);
47
+ if (opts?.apiKey) await ensureApiKeyInEnv();
48
+ return cwd;
41
49
  }
42
50
  const init = defineCommand({
43
51
  meta: {
@@ -58,7 +66,7 @@ const init = defineCommand({
58
66
  force: {
59
67
  type: "boolean",
60
68
  alias: "f",
61
- description: "Overwrite existing agent.ts"
69
+ description: "Overwrite existing files"
62
70
  },
63
71
  yes: sharedArgs.yes,
64
72
  skipApi: {
@@ -67,11 +75,11 @@ const init = defineCommand({
67
75
  },
68
76
  skipDeploy: {
69
77
  type: "boolean",
70
- description: "Skip post-init deploy"
78
+ description: "Skip deploy after scaffolding"
71
79
  }
72
80
  },
73
81
  async run({ args }) {
74
- const { runInitCommand } = await import("./init-Pa-YbNnJ.mjs");
82
+ const { runInitCommand } = await import("./init-CNoNUGRN.mjs");
75
83
  await runInitCommand({
76
84
  dir: args.dir,
77
85
  template: args.template,
@@ -88,31 +96,18 @@ const dev = defineCommand({
88
96
  description: "Start a local development server"
89
97
  },
90
98
  args: {
91
- port: {
92
- type: "string",
93
- alias: "p",
94
- description: "Port to listen on",
95
- default: "3000"
96
- },
97
- check: {
98
- type: "boolean",
99
- description: "Start server, verify health, then exit"
100
- },
101
- yes: {
102
- type: "boolean",
103
- alias: "y",
104
- description: "Accept defaults (no prompts)"
105
- }
99
+ port: sharedArgs.port,
100
+ yes: sharedArgs.yes
106
101
  },
107
102
  async run({ args }) {
108
- const cwd = resolveCwd();
109
- await ensureAgent(cwd, args.yes);
110
- await ensureApiKeyInEnv();
111
- const { runDevCommand } = await import("./dev-nCt6xqmm.mjs");
103
+ const cwd = await setup(args, {
104
+ agent: true,
105
+ apiKey: true
106
+ });
107
+ const { runDevCommand } = await import("./dev-DEZKrw8v.mjs");
112
108
  await runDevCommand({
113
109
  cwd,
114
- port: args.port,
115
- ...args.check ? { check: args.check } : {}
110
+ port: args.port
116
111
  });
117
112
  }
118
113
  });
@@ -122,35 +117,30 @@ const test = defineCommand({
122
117
  description: "Run agent tests"
123
118
  },
124
119
  async run() {
125
- const cwd = resolveCwd();
126
- const { runTestCommand } = await import("./test-9fFn9DCf.mjs");
120
+ const cwd = await setup();
121
+ const { runTestCommand } = await import("./test-CYoqKJP0.mjs");
127
122
  await runTestCommand(cwd);
128
123
  }
129
124
  });
130
125
  const build = defineCommand({
131
126
  meta: {
132
127
  name: "build",
133
- description: "Bundle and validate (no server or deploy)"
128
+ description: "Bundle agent without deploying"
134
129
  },
135
130
  args: {
136
- yes: {
137
- type: "boolean",
138
- alias: "y",
139
- description: "Accept defaults (no prompts)"
140
- },
131
+ yes: sharedArgs.yes,
141
132
  skipTests: {
142
133
  type: "boolean",
143
134
  description: "Skip running tests before build"
144
135
  }
145
136
  },
146
137
  async run({ args }) {
147
- const cwd = resolveCwd();
148
- await ensureAgent(cwd, args.yes);
138
+ const cwd = await setup(args, { agent: true });
149
139
  if (!args.skipTests) {
150
- const { runVitest } = await import("./test-9fFn9DCf.mjs");
140
+ const { runVitest } = await import("./test-CYoqKJP0.mjs");
151
141
  runVitest(cwd);
152
142
  }
153
- const { runBuildCommand } = await import("./_build-CElA0PJB.mjs");
143
+ const { runBuildCommand } = await import("./_bundler-BjgPrg7s.mjs");
154
144
  await runBuildCommand(cwd);
155
145
  }
156
146
  });
@@ -160,30 +150,27 @@ const deploy = defineCommand({
160
150
  description: "Bundle and deploy to production"
161
151
  },
162
152
  args: {
163
- server: {
164
- type: "string",
165
- alias: "s",
166
- description: "Server URL"
167
- },
153
+ server: sharedArgs.server,
168
154
  dryRun: {
169
155
  type: "boolean",
170
156
  description: "Validate and bundle without deploying"
171
157
  },
172
- yes: {
173
- type: "boolean",
174
- alias: "y",
175
- description: "Accept defaults (no prompts)"
176
- }
158
+ yes: sharedArgs.yes
177
159
  },
178
160
  async run({ args }) {
179
- const cwd = resolveCwd();
180
- await ensureAgent(cwd, args.yes);
181
- const { runDeployCommand } = await import("./deploy-BWF0H8UK.mjs");
182
- await runDeployCommand({
183
- cwd,
184
- ...args.server ? { server: args.server } : {},
185
- ...args.dryRun ? { dryRun: args.dryRun } : {}
186
- });
161
+ const cwd = await setup(args, { agent: true });
162
+ const { runDeployCommand } = await import("./deploy-ChUnIpu5.mjs");
163
+ try {
164
+ await runDeployCommand({
165
+ cwd,
166
+ ...args.server ? { server: args.server } : {},
167
+ ...args.dryRun ? { dryRun: args.dryRun } : {}
168
+ });
169
+ } catch (err) {
170
+ const { log } = await import("./_ui-DWGXImbO.mjs");
171
+ log.error(err instanceof Error ? err.message : String(err));
172
+ process.exit(1);
173
+ }
187
174
  }
188
175
  });
189
176
  const del = defineCommand({
@@ -191,52 +178,20 @@ const del = defineCommand({
191
178
  name: "delete",
192
179
  description: "Remove a deployed agent"
193
180
  },
194
- args: { server: {
195
- type: "string",
196
- alias: "s",
197
- description: "Server URL"
198
- } },
181
+ args: { server: sharedArgs.server },
199
182
  async run({ args }) {
200
- const cwd = resolveCwd();
201
- const { runDeleteCommand } = await import("./delete-DYUD8j8f.mjs");
183
+ const cwd = await setup();
184
+ const { runDeleteCommand } = await import("./delete-BvRel3Tw.mjs");
202
185
  await runDeleteCommand({
203
186
  cwd,
204
187
  ...args.server ? { server: args.server } : {}
205
188
  });
206
189
  }
207
190
  });
208
- const start = defineCommand({
209
- meta: {
210
- name: "start",
211
- description: "Start production server from build"
212
- },
213
- args: {
214
- port: {
215
- type: "string",
216
- alias: "p",
217
- description: "Port to listen on",
218
- default: "3000"
219
- },
220
- yes: {
221
- type: "boolean",
222
- alias: "y",
223
- description: "Accept defaults (no prompts)"
224
- }
225
- },
226
- async run({ args }) {
227
- const cwd = resolveCwd();
228
- await ensureApiKeyInEnv();
229
- const { runStartCommand } = await import("./start-BDAtcDr3.mjs");
230
- await runStartCommand({
231
- cwd,
232
- port: args.port
233
- });
234
- }
235
- });
236
191
  const secret = defineCommand({
237
192
  meta: {
238
193
  name: "secret",
239
- description: "Manage secrets"
194
+ description: "Manage agent secrets"
240
195
  },
241
196
  subCommands: {
242
197
  put: defineCommand({
@@ -250,9 +205,8 @@ const secret = defineCommand({
250
205
  required: true
251
206
  } },
252
207
  async run({ args }) {
253
- const cwd = resolveCwd();
254
- await ensureApiKeyInEnv();
255
- const { runSecretPut } = await import("./secret-BkN22eT1.mjs");
208
+ const cwd = await setup(void 0, { apiKey: true });
209
+ const { runSecretPut } = await import("./secret-DLosn47q.mjs");
256
210
  await runSecretPut(cwd, args.name);
257
211
  }
258
212
  }),
@@ -267,158 +221,24 @@ const secret = defineCommand({
267
221
  required: true
268
222
  } },
269
223
  async run({ args }) {
270
- const cwd = resolveCwd();
271
- await ensureApiKeyInEnv();
272
- const { runSecretDelete } = await import("./secret-BkN22eT1.mjs");
224
+ const cwd = await setup(void 0, { apiKey: true });
225
+ const { runSecretDelete } = await import("./secret-DLosn47q.mjs");
273
226
  await runSecretDelete(cwd, args.name);
274
227
  }
275
228
  }),
276
229
  list: defineCommand({
277
230
  meta: {
278
231
  name: "list",
279
- description: "List secret names"
232
+ description: "List all secrets"
280
233
  },
281
234
  async run() {
282
- const cwd = resolveCwd();
283
- await ensureApiKeyInEnv();
284
- const { runSecretList } = await import("./secret-BkN22eT1.mjs");
235
+ const cwd = await setup(void 0, { apiKey: true });
236
+ const { runSecretList } = await import("./secret-DLosn47q.mjs");
285
237
  await runSecretList(cwd);
286
238
  }
287
239
  })
288
240
  }
289
241
  });
290
- const rag = defineCommand({
291
- meta: {
292
- name: "rag",
293
- description: "Ingest a site's llms-full.txt into the vector store"
294
- },
295
- args: {
296
- url: {
297
- type: "positional",
298
- description: "URL to ingest",
299
- required: true
300
- },
301
- server: {
302
- type: "string",
303
- alias: "s",
304
- description: "Server URL"
305
- },
306
- chunkSize: {
307
- type: "string",
308
- description: "Max chunk size in tokens",
309
- default: "512"
310
- },
311
- yes: {
312
- type: "boolean",
313
- alias: "y",
314
- description: "Accept defaults (no prompts)"
315
- }
316
- },
317
- async run({ args }) {
318
- const cwd = resolveCwd();
319
- await ensureApiKeyInEnv();
320
- const { runRagCommand } = await import("./rag-qtN4p79Q.mjs");
321
- await runRagCommand({
322
- url: args.url,
323
- cwd,
324
- ...args.server ? { server: args.server } : {},
325
- chunkSize: args.chunkSize
326
- });
327
- }
328
- });
329
- const doctor = defineCommand({
330
- meta: {
331
- name: "doctor",
332
- description: "Check environment health and diagnose issues"
333
- },
334
- args: { port: {
335
- type: "string",
336
- alias: "p",
337
- description: "Port to check availability",
338
- default: "3000"
339
- } },
340
- async run({ args }) {
341
- const cwd = resolveCwd();
342
- const { runDoctorCommand } = await import("./doctor-Dvz0rdWo.mjs");
343
- await runDoctorCommand({
344
- cwd,
345
- port: args.port
346
- });
347
- }
348
- });
349
- const generate = defineCommand({
350
- meta: {
351
- name: "generate",
352
- description: "Generate or modify agent code using AI"
353
- },
354
- args: { prompt: {
355
- type: "positional",
356
- description: "What to generate",
357
- required: true
358
- } },
359
- async run({ args }) {
360
- const cwd = resolveCwd();
361
- await ensureApiKeyInEnv();
362
- const { runGenerateCommand } = await import("./generate-Di_Shw-X.mjs");
363
- await runGenerateCommand({
364
- cwd,
365
- prompt: args.prompt
366
- });
367
- }
368
- });
369
- const run = defineCommand({
370
- meta: {
371
- name: "run",
372
- description: "Init, generate, and deploy in one step"
373
- },
374
- args: {
375
- prompt: {
376
- type: "positional",
377
- description: "What to build",
378
- required: true
379
- },
380
- server: {
381
- type: "string",
382
- alias: "s",
383
- description: "Server URL"
384
- }
385
- },
386
- async run({ args }) {
387
- await ensureAgent(resolveCwd(), true);
388
- await ensureApiKeyInEnv();
389
- const cwd = resolveCwd();
390
- const { runGenerateCommand } = await import("./generate-Di_Shw-X.mjs");
391
- await runGenerateCommand({
392
- cwd,
393
- prompt: args.prompt
394
- });
395
- const { runDeployCommand } = await import("./deploy-BWF0H8UK.mjs");
396
- await runDeployCommand({
397
- cwd,
398
- ...args.server ? { server: args.server } : {}
399
- });
400
- }
401
- });
402
- const link = defineCommand({
403
- meta: {
404
- name: "link",
405
- description: "Link local workspace packages into the current project (dev only)"
406
- },
407
- async run() {
408
- const { runLinkCommand } = await import("./_link-D6mmDQ0B.mjs");
409
- runLinkCommand(resolveCwd());
410
- }
411
- });
412
- const unlink = defineCommand({
413
- meta: {
414
- name: "unlink",
415
- description: "Restore published package versions (reverses aai link)"
416
- },
417
- async run() {
418
- const { runUnlinkCommand } = await import("./_link-D6mmDQ0B.mjs");
419
- runUnlinkCommand(resolveCwd());
420
- }
421
- });
422
242
  const mainCommand = defineCommand({
423
243
  meta: {
424
244
  name: "aai",
@@ -432,19 +252,11 @@ const mainCommand = defineCommand({
432
252
  build,
433
253
  deploy,
434
254
  delete: del,
435
- start,
436
- secret,
437
- rag,
438
- generate,
439
- run,
440
- link,
441
- unlink,
442
- doctor
255
+ secret
443
256
  }
444
257
  });
445
258
  if (process.env.VITEST !== "true") {
446
259
  const sub = process.argv[2];
447
- const knownCommands = new Set(Object.keys(mainCommand.subCommands ?? {}));
448
260
  const helpFlags = new Set([
449
261
  "--help",
450
262
  "--version",
@@ -452,21 +264,6 @@ if (process.env.VITEST !== "true") {
452
264
  "-V"
453
265
  ]);
454
266
  if (!sub || sub.startsWith("-") && !helpFlags.has(sub)) process.argv.splice(2, 0, "init");
455
- else if (!(sub.startsWith("-") || knownCommands.has(sub))) {
456
- const promptParts = [];
457
- const flagArgs = [];
458
- for (let i = 2; i < process.argv.length; i++) if (process.argv[i]?.startsWith("-")) {
459
- flagArgs.push(process.argv[i]);
460
- if (i + 1 < process.argv.length && !process.argv[i + 1]?.startsWith("-")) flagArgs.push(process.argv[++i]);
461
- } else promptParts.push(process.argv[i]);
462
- process.argv = [
463
- process.argv[0],
464
- process.argv[1],
465
- "run",
466
- promptParts.join(" "),
467
- ...flagArgs
468
- ];
469
- }
470
267
  runMain(mainCommand);
471
268
  }
472
269
  //#endregion
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { o as getServerInfo } from "./_discover-a8yIuqEp.mjs";
3
+ import { log } from "./_ui-DWGXImbO.mjs";
4
+ import { n as apiError, r as apiRequest, t as HINT_INVALID_API_KEY } from "./_api-client-H4MFOr8j.mjs";
5
+ //#region _delete.ts
6
+ async function runDelete(opts) {
7
+ const fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
8
+ const resp = await apiRequest(`${opts.url}/${opts.slug}`, {
9
+ method: "DELETE",
10
+ apiKey: opts.apiKey,
11
+ action: "delete"
12
+ }, fetchFn);
13
+ if (resp.ok) return;
14
+ const text = await resp.text();
15
+ let hint;
16
+ if (resp.status === 401) hint = HINT_INVALID_API_KEY;
17
+ else if (resp.status === 404) hint = "The agent may not be deployed. Check `.aai/project.json` for the correct slug.";
18
+ throw apiError("delete", resp.status, text, hint);
19
+ }
20
+ //#endregion
21
+ //#region delete.ts
22
+ async function runDeleteCommand(opts) {
23
+ const { cwd } = opts;
24
+ const { serverUrl, slug, apiKey } = await getServerInfo(cwd, opts.server);
25
+ log.step(`Deleting ${slug}`);
26
+ await runDelete({
27
+ url: serverUrl,
28
+ slug,
29
+ apiKey
30
+ });
31
+ log.success(`Deleted ${serverUrl}/${slug}`);
32
+ }
33
+ //#endregion
34
+ export { runDeleteCommand };
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ import { a as getApiKey, c as readProjectConfig, d as writeProjectConfig, i as generateSlug, u as resolveServerUrl } from "./_discover-a8yIuqEp.mjs";
3
+ import { buildAgentBundle } from "./_bundler-BjgPrg7s.mjs";
4
+ import { fmtUrl, log } from "./_ui-DWGXImbO.mjs";
5
+ import { n as apiError, r as apiRequest, t as HINT_INVALID_API_KEY } from "./_api-client-H4MFOr8j.mjs";
6
+ //#region _deploy.ts
7
+ const MAX_SLUG_RETRIES = 20;
8
+ async function attempt(fetchFn, url, slug, body, apiKey) {
9
+ const resp = await apiRequest(`${url}/${slug}/deploy`, {
10
+ method: "POST",
11
+ body,
12
+ apiKey,
13
+ action: "deploy"
14
+ }, fetchFn);
15
+ if (resp.ok) return {
16
+ ok: true,
17
+ slug
18
+ };
19
+ const text = await resp.text();
20
+ if (resp.status === 403 && text.includes("owned by another")) return {
21
+ ok: false,
22
+ retry: true
23
+ };
24
+ let hint;
25
+ if (resp.status === 401) hint = HINT_INVALID_API_KEY;
26
+ else if (resp.status === 403 && text.includes("Slug")) hint = "This slug is already taken. Set a different slug in .aai/project.json.";
27
+ else if (resp.status === 413) hint = "Your bundle is too large. Try reducing dependencies or splitting your agent.";
28
+ return {
29
+ ok: false,
30
+ retry: false,
31
+ error: apiError("deploy", resp.status, text, hint).message
32
+ };
33
+ }
34
+ async function runDeploy(opts) {
35
+ const fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
36
+ const body = JSON.stringify({
37
+ env: opts.env,
38
+ worker: opts.bundle.worker,
39
+ clientFiles: opts.bundle.clientFiles
40
+ });
41
+ let slug = opts.slug;
42
+ for (let i = 0; i < MAX_SLUG_RETRIES; i++) {
43
+ const result = await attempt(fetchFn, opts.url, slug, body, opts.apiKey);
44
+ if (result.ok) return { slug: result.slug };
45
+ if (!result.retry) throw new Error(result.error);
46
+ slug = generateSlug();
47
+ }
48
+ throw new Error(`Could not find an available slug after ${MAX_SLUG_RETRIES} attempts. Set one manually in .aai/project.json.`);
49
+ }
50
+ //#endregion
51
+ //#region deploy.ts
52
+ async function deployBundle(opts) {
53
+ const { bundle, serverUrl, apiKey, cwd } = opts;
54
+ let { slug } = opts;
55
+ log.step(`Deploying ${slug}`);
56
+ slug = (await runDeploy({
57
+ url: serverUrl,
58
+ bundle,
59
+ env: { ASSEMBLYAI_API_KEY: apiKey },
60
+ slug,
61
+ apiKey
62
+ })).slug;
63
+ await writeProjectConfig(cwd, {
64
+ slug,
65
+ serverUrl
66
+ });
67
+ const agentUrl = `${serverUrl}/${slug}`;
68
+ log.success(`Deployed ${fmtUrl(agentUrl)}`);
69
+ return agentUrl;
70
+ }
71
+ async function runDeployCommand(opts) {
72
+ const { cwd } = opts;
73
+ const dryRun = opts.dryRun ?? false;
74
+ const apiKey = dryRun ? "" : await getApiKey();
75
+ const projectConfig = await readProjectConfig(cwd);
76
+ const serverUrl = resolveServerUrl(opts.server, projectConfig?.serverUrl);
77
+ const bundle = await buildAgentBundle(cwd);
78
+ const slug = projectConfig?.slug ?? bundle.slug;
79
+ if (dryRun) {
80
+ log.info(`Dry run complete — would deploy as ${slug}`);
81
+ return;
82
+ }
83
+ await deployBundle({
84
+ bundle,
85
+ serverUrl,
86
+ apiKey,
87
+ slug,
88
+ cwd
89
+ });
90
+ }
91
+ //#endregion
92
+ export { runDeployCommand };
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ import { fmtUrl, log, parsePort } from "./_ui-DWGXImbO.mjs";
3
+ import path from "node:path";
4
+ import { createServer } from "vite";
5
+ import { colorize } from "consola/utils";
6
+ //#region dev.ts
7
+ async function runDevCommand(opts) {
8
+ const port = parsePort(opts.port);
9
+ const agentName = path.basename(path.resolve(opts.cwd));
10
+ await (await createServer({
11
+ root: opts.cwd,
12
+ server: { port }
13
+ })).listen();
14
+ log.success(`${colorize("bold", agentName)} running at ${fmtUrl(`http://localhost:${port}`)}`);
15
+ log.info("Press Ctrl-C to stop");
16
+ }
17
+ //#endregion
18
+ export { runDevCommand };