@alexkroman1/aai-cli 16.1.0 → 17.0.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.
Files changed (183) hide show
  1. package/README.md +2 -1
  2. package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
  3. package/dist/_build-target.d.ts +98 -19
  4. package/dist/_deno-target.d.ts +15 -14
  5. package/dist/_dev-env.d.ts +19 -13
  6. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-CLU9xjH5.mjs} +25 -17
  7. package/dist/_dev-server.d.ts +4 -3
  8. package/dist/_init.d.ts +39 -0
  9. package/dist/_modal-target.d.ts +11 -6
  10. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  11. package/dist/_preflight.d.ts +110 -5
  12. package/dist/_target-bundle.d.ts +112 -0
  13. package/dist/_target-entry.d.ts +81 -0
  14. package/dist/{_templates-CuP74F8D.mjs → _templates-IMeKMVIj.mjs} +1 -1
  15. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  16. package/dist/_vitest-runner.d.ts +35 -23
  17. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  18. package/dist/build.d.ts +34 -4
  19. package/dist/cli.mjs +20 -16
  20. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  21. package/dist/deploy.d.ts +9 -0
  22. package/dist/{dev-Du8pCWFq.mjs → dev-ChsrNHpK.mjs} +1 -1
  23. package/dist/dev.d.ts +1 -1
  24. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  25. package/dist/init-W-4k-lCF.mjs +559 -0
  26. package/dist/init.d.ts +43 -3
  27. package/dist/scaffold/CLAUDE.md +51 -64
  28. package/dist/scaffold/package.json +6 -6
  29. package/dist/scaffold/vite.config.ts +29 -1
  30. package/dist/{studio-It7SRfUN.mjs → studio-DEAJGBXa.mjs} +19 -9
  31. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  32. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  33. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  34. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  35. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  36. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  37. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  38. package/dist/templates/coding-agent/agent.test.ts +109 -0
  39. package/dist/templates/coding-agent/agent.ts +45 -0
  40. package/dist/templates/coding-agent/chat.ts +63 -0
  41. package/dist/templates/coding-agent/shared.ts +46 -0
  42. package/dist/templates/coding-agent/system-prompt.md +32 -0
  43. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  44. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  45. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  46. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  47. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  48. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  49. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  50. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  51. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  52. package/dist/templates/custom-pipeline-agent/agent.ts +1 -0
  53. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  54. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  55. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  56. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  57. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  58. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +8 -1
  59. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  60. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  61. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  62. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  63. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  64. package/dist/templates/executive-inbox-agent/meeting.ts +1 -1
  65. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  66. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  67. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  68. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  69. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  70. package/dist/templates/hotel-reception-agent/agent.test.ts +2 -1
  71. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  72. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  73. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  74. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +2 -1
  75. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  76. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  77. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  78. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  79. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  80. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  81. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  82. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  83. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  84. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  85. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  86. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  87. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  88. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  89. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  90. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  91. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  92. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  93. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  94. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  95. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  96. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  97. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  98. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  99. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  100. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  101. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  102. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  105. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  106. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  107. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  108. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  109. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  114. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  116. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  117. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  118. package/dist/templates/medication-safety-agent/agent.test.ts +54 -0
  119. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  120. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  121. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  122. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  123. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  124. package/dist/templates/quickstart-agent/agent.eval.test.ts +39 -3
  125. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  126. package/dist/templates/quickstart-agent/agent.ts +18 -2
  127. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  128. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  129. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  130. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  131. package/dist/templates/research-planner-agent/agent.ts +3 -0
  132. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  133. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  134. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  135. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  136. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +37 -5
  137. package/dist/templates/roadside-assistance-agent/agent.test.ts +38 -6
  138. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  139. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  140. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  141. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  142. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  143. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  144. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  145. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  146. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  147. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  148. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  149. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  150. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  151. package/dist/templates/technical-support-agent/agent.test.ts +3 -3
  152. package/dist/templates/technical-support-agent/agent.ts +5 -1
  153. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  154. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  155. package/dist/templates/technical-support-agent/procedure.ts +4 -3
  156. package/dist/templates/technical-support-agent/shared.ts +10 -146
  157. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  158. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  159. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  160. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  161. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  162. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  163. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  164. package/dist/templates/topic-briefing-agent/agent.test.ts +23 -11
  165. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  166. package/dist/templates/topic-briefing-agent/shared.ts +10 -10
  167. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  168. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  169. package/dist/templates/transcription-workflow/agent.ts +3 -0
  170. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  171. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  172. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  173. package/dist/templates/web-research-agent/agent.ts +30 -0
  174. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  175. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  176. package/dist/templates/word-game-agent/agent.ts +20 -0
  177. package/dist/test-CjKPQ9_B.mjs +102 -0
  178. package/dist/test.d.ts +37 -12
  179. package/package.json +5 -5
  180. package/dist/_init-Bp1CjRrU.mjs +0 -199
  181. package/dist/_preflight-CcAR577V.mjs +0 -46
  182. package/dist/init-CY4NAXAA.mjs +0 -183
  183. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env node
2
- import { d as readJson, g as writeJson, i as compareCodeUnits, u as isEexist } from "./_utils-D5JGcjiW.mjs";
3
- import { r as isDevMode, t as getMonorepoRoot } from "./_agent-BzUeqOdj.mjs";
4
- import { REPO_URL, downloadAndMergeTemplate } from "./_templates-CuP74F8D.mjs";
5
- import path from "node:path";
6
- import fs from "node:fs/promises";
7
- //#region src/_init.ts
8
- /**
9
- * The README every scaffolded project gets, and the first thing a new author
10
- * reads. Three things in it are corrections rather than prose:
11
- *
12
- * - **`npm run dev`, never a bare `aai dev`.** The CLI is a devDependency, so
13
- * after `npm install` the binary is in `node_modules/.bin` and NOT on
14
- * `PATH`. The old quickstart said `aai dev`, which fails with
15
- * `command not found` for everyone who has not installed the CLI globally.
16
- * - **The key `aai dev` needs is named, with the two LOCAL ways first.** No
17
- * step of local development needs a platform account; a twenty-persona DX
18
- * audit read the account-shaped failure it used to get and concluded the
19
- * opposite, then stopped using the loop this file documents.
20
- * - **`aai login` appears where it is actually required.** It was in no
21
- * user-facing doc at all, while the quickstart's own publish step needs it.
22
- */
23
- function readmeContent(slug) {
24
- return `# ${slug}
25
-
26
- A voice agent built with [aai](${REPO_URL}).
27
-
28
- ## Getting started
29
-
30
- \`\`\`sh
31
- npm install # Install dependencies
32
- npm run dev # Run locally on http://localhost:3000 (opens browser)
33
- \`\`\`
34
-
35
- The \`aai\` CLI is a devDependency of this project, so it lives in
36
- \`node_modules/.bin\` rather than on your \`PATH\`. Run it through npm
37
- (\`npm run dev\`, \`npm test\`, \`npm run build\`) or with \`npx aai <command>\`.
38
- Installing it globally (\`npm i -g @alexkroman1/aai-cli\`) also works, and is
39
- what the project docs assume.
40
-
41
- ### The one key local development needs
42
-
43
- The default pipeline (speech-to-text → LLM → text-to-speech) runs on a single
44
- AssemblyAI key. **Any one of these is enough, and the first two need no aai
45
- account** — nothing about running this agent locally is gated on one:
46
-
47
- 1. Put \`ASSEMBLYAI_API_KEY=<your key>\` in \`.env\` (this project's \`.env.example\`
48
- documents it, and it is the same file \`aai publish\` uploads as secrets).
49
- 2. Or export it in your shell: \`export ASSEMBLYAI_API_KEY=<your key>\`.
50
- 3. Or run \`npx aai login\`, and \`aai dev\` will use your account's key.
51
-
52
- Get a key at <https://www.assemblyai.com/dashboard>.
53
-
54
- ## Publishing
55
-
56
- Publishing (and the studio it syncs to) is the one part that does need an
57
- account:
58
-
59
- \`\`\`sh
60
- npx aai login # Link your account — once per machine
61
- npm run publish:agent # Publish to production (and sync to the studio)
62
- \`\`\`
63
-
64
- You can also run this agent as a plain Node server, with no aai account and
65
- nothing managed:
66
-
67
- \`\`\`sh
68
- npm start # Builds, then serves on http://127.0.0.1:3000
69
- \`\`\`
70
-
71
- ## Secrets
72
-
73
- Access secrets in your agent via \`ctx.env.MY_KEY\`.
74
-
75
- **Local development** — add secrets to \`.env\` (auto-loaded by \`aai dev\`):
76
-
77
- \`\`\`sh
78
- ALPHA_VANTAGE_KEY=sk-abc123
79
- MY_API_KEY=secret-value
80
- \`\`\`
81
-
82
- **Production** — set secrets on the server:
83
-
84
- \`\`\`sh
85
- npx aai secret put MY_KEY # Set a secret (prompts for value)
86
- npx aai secret list # List secret names
87
- npx aai secret delete MY_KEY # Remove a secret
88
- \`\`\`
89
-
90
- `;
91
- }
92
- /**
93
- * Map from npm package name to directory name under packages/.
94
- * Used to rewrite published version ranges to link: paths in dev mode.
95
- */
96
- const WORKSPACE_PKG_DIRS = {
97
- "@alexkroman1/aai": "aai",
98
- "@alexkroman1/aai-cli": "aai-cli",
99
- "@alexkroman1/aai-runtime": "aai-runtime",
100
- "@alexkroman1/aai-ui": "aai-ui"
101
- };
102
- /** Rewrite workspace deps to link: paths so pnpm links to local source. */
103
- async function patchPackageJsonForWorkspace(targetDir) {
104
- const pkgPath = path.join(targetDir, "package.json");
105
- const pkgJson = await readJson(pkgPath);
106
- if (!pkgJson) return;
107
- pkgJson.name = path.basename(targetDir);
108
- delete pkgJson.packageManager;
109
- const root = getMonorepoRoot();
110
- if (!root) return;
111
- const packagesDir = path.join(root, "packages");
112
- for (const field of ["dependencies", "devDependencies"]) {
113
- const deps = pkgJson[field];
114
- if (!deps) continue;
115
- for (const key of Object.keys(deps)) {
116
- const dir = WORKSPACE_PKG_DIRS[key];
117
- if (dir) deps[key] = `link:${path.relative(targetDir, path.join(packagesDir, dir))}`;
118
- }
119
- }
120
- await writeJson(pkgPath, pkgJson);
121
- await pinSharedDeps(targetDir, packagesDir, pkgJson);
122
- }
123
- /**
124
- * Pin every THIRD-PARTY dependency this project shares with a linked workspace
125
- * package to the copy that workspace package resolved.
126
- *
127
- * Linking is what makes this necessary, and it only bites in dev mode. The
128
- * project's `@alexkroman1/*` deps become `link:` paths, so the SDK's types come
129
- * out of the WORKSPACE's `node_modules` — while the project installs its own
130
- * copy of anything it also declares. Two copies of a structurally identical
131
- * library are two NOMINALLY different types to TypeScript, and the error runs to
132
- * a hundred lines of `Type 'AnyActorLogic' is not assignable to type
133
- * 'AnyActorLogic'` with two absolute paths in it.
134
- *
135
- * Measured: `aai init --template technical-support-agent` produced exactly that. The
136
- * workspace lockfile pinned `xstate@5.32.5`, the fresh project resolved
137
- * `^5.32.5` to `5.32.6`, the CLI's typecheck gate failed, and the deploy was
138
- * REFUSED — `"deployed": false` with the whole error as a warning. One
139
- * `overrides` entry fixes it; verified end to end.
140
- *
141
- * A published install has no such problem, which is why this is dev-mode only:
142
- * a user's project and the published SDK both ask for `^5.32.5` and pnpm
143
- * resolves ONE copy. Nothing here changes what a user gets.
144
- *
145
- * Written to `pnpm-workspace.yaml` rather than `pnpm.overrides` in the manifest:
146
- * the scaffold ships that file, which makes the project its own workspace root,
147
- * and pnpm 10+ reads overrides from there. Verified both ways — the manifest
148
- * spelling installed `5.32.6` anyway.
149
- */
150
- async function pinSharedDeps(targetDir, packagesDir, pkgJson) {
151
- const declared = {
152
- ...pkgJson.dependencies,
153
- ...pkgJson.devDependencies
154
- };
155
- const linked = Object.entries(WORKSPACE_PKG_DIRS).filter(([name]) => name in declared).map(([, dir]) => dir);
156
- const resolved = await Promise.all(Object.keys(declared).filter((name) => !(name in WORKSPACE_PKG_DIRS)).map(async (name) => {
157
- for (const dir of linked) {
158
- const manifest = await readJson(path.join(packagesDir, dir, "node_modules", name, "package.json"));
159
- if (typeof manifest?.version === "string") return [name, manifest.version];
160
- }
161
- return null;
162
- }));
163
- const pins = new Map(resolved.filter((entry) => entry !== null));
164
- if (pins.size === 0) return;
165
- const file = path.join(targetDir, "pnpm-workspace.yaml");
166
- let existing;
167
- try {
168
- existing = await fs.readFile(file, "utf-8");
169
- } catch {
170
- return;
171
- }
172
- const block = [...pins].sort(([a], [b]) => compareCodeUnits(a, b)).map(([name, version]) => ` "${name}": "${version}"`).join("\n");
173
- await fs.writeFile(file, `${existing.trimEnd()}\n\n# Added by \`aai init\` in DEV MODE only — see pinSharedDeps in\n# packages/aai-cli/src/_init.ts. The @alexkroman1/* packages above are LINKED to
174
- # this checkout, so anything they and this project both depend on has to be
175
- # ONE copy: two copies of xstate are two incompatible sets of types, and the
176
- # typecheck gate refuses the deploy.\noverrides:\n${block}\n`);
177
- }
178
- async function runInit(opts) {
179
- const { targetDir, template } = opts;
180
- await downloadAndMergeTemplate(template, targetDir);
181
- if (isDevMode()) {
182
- await patchPackageJsonForWorkspace(targetDir);
183
- try {
184
- await fs.unlink(path.join(targetDir, ".npmrc"));
185
- } catch {}
186
- }
187
- try {
188
- await fs.copyFile(path.join(targetDir, ".env.example"), path.join(targetDir, ".env"), fs.constants.COPYFILE_EXCL);
189
- } catch {}
190
- const readmePath = path.join(targetDir, "README.md");
191
- const slug = path.basename(path.resolve(targetDir));
192
- try {
193
- await fs.writeFile(readmePath, readmeContent(slug), { flag: "wx" });
194
- } catch (err) {
195
- if (!isEexist(err)) throw err;
196
- }
197
- }
198
- //#endregion
199
- export { runInit };
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
- import { plural } from "@alexkroman1/aai/utils";
3
- import { requiredProviderEnvVars } from "@alexkroman1/aai-runtime";
4
- //#region src/_preflight.ts
5
- /**
6
- * The deploy-time credential preflight — the classic dev/prod failure, caught
7
- * before the upload instead of at the deployed agent's first session.
8
- *
9
- * An agent that ran locally on shell-exported provider keys dies after deploy
10
- * with what looks like a provider outage: `aai dev` falls back to the shell
11
- * (`withHostCredentialFallback`), and the platform never will. Naming the key
12
- * here turns that into one line of output while the developer is still in the
13
- * directory that owns the `.env`.
14
- *
15
- * **This lives in the CLI because the agent's config does.** The platform
16
- * stores no description of a bundle and never evaluates one (see "The
17
- * platform stores no agent config" in packages/aai-server/CLAUDE.md), so the
18
- * only place that knows an agent needs `CARTESIA_API_KEY` is the process that
19
- * just built it.
20
- *
21
- * **It WARNS, and must not be turned into a hard failure.** The CLI sees the
22
- * env it is about to upload; it cannot see what is already stored against the
23
- * slug from an earlier `aai secret put`, so a key the platform holds looks
24
- * missing from here. The server-side check this replaced could see both and
25
- * so could reject — moving the config to where it is authored costs that
26
- * accuracy, and a false rejection is worse than a false warning: it blocks a
27
- * deploy that would have worked.
28
- */
29
- /**
30
- * Env var names the agent needs that the env being uploaded doesn't supply.
31
- * Empty values count as missing — an empty credential authenticates nothing.
32
- *
33
- * Two sources: provider credentials derived from the stt/llm/tts/s2s
34
- * descriptors (the same registry-backed derivation the runtime resolves keys
35
- * with), and the agent's own declared `requiredEnv` — an `agent()` field for
36
- * custom keys tools read from `ctx.env`, which no static derivation can see.
37
- */
38
- function missingCredentials(config, env) {
39
- return [.../* @__PURE__ */ new Set([...requiredProviderEnvVars(config), ...config.requiredEnv ?? []])].filter((name) => !env[name]);
40
- }
41
- /** One line naming the missing keys and what to do about them. */
42
- function missingCredentialMessage(missing) {
43
- return `Missing ${plural(missing.length, "credential")} the agent needs to start: ${missing.join(", ")}. Declare ${plural(missing.length, "it", "them")} in .env and redeploy (already set on the platform with \`aai secret put\`? then this is already handled).`;
44
- }
45
- //#endregion
46
- export { missingCredentialMessage, missingCredentials };
@@ -1,183 +0,0 @@
1
- #!/usr/bin/env node
2
- import { a as ok } from "./_output-DBP9Op_d.mjs";
3
- import { n as log, s as unwrapCancel } from "./_ui-DCt4qZrk.mjs";
4
- import { c as fileExists, d as readJson, p as resolveCwd, s as errorMessage, t as AGENT_ENTRY } from "./_utils-D5JGcjiW.mjs";
5
- import { r as isDevMode, t as getMonorepoRoot } from "./_agent-BzUeqOdj.mjs";
6
- import { listTemplates } from "./_templates-CuP74F8D.mjs";
7
- import path from "node:path";
8
- import { styleText } from "node:util";
9
- import * as p from "@clack/prompts";
10
- import { execa } from "execa";
11
- //#region src/init.ts
12
- /**
13
- * Run `fn` behind a clack spinner, stopping it in EVERY outcome.
14
- *
15
- * The naked form (`s?.start(); await work(); s?.stop()`) leaks the spinner on a
16
- * failure: clack keeps its interval and its raw-mode stdin hook, so a throw
17
- * left a spinner ticking under the error message with the cursor hidden. The
18
- * `catch` label is what the terminal is left showing, so it names the step.
19
- */
20
- async function withSpinner(silent, labels, fn) {
21
- const s = silent ? void 0 : p.spinner();
22
- s?.start(labels.start);
23
- let succeeded = false;
24
- try {
25
- const value = await fn();
26
- succeeded = true;
27
- return value;
28
- } finally {
29
- s?.stop(succeeded ? labels.done : labels.failed);
30
- }
31
- }
32
- const DEFAULT_PROJECT_NAME = "my-voice-agent";
33
- /** Prompt for project name or return default when --yes is set. */
34
- async function promptProjectName(yes) {
35
- if (yes) return DEFAULT_PROJECT_NAME;
36
- return unwrapCancel(await p.text({
37
- message: "What is your project named?",
38
- placeholder: DEFAULT_PROJECT_NAME,
39
- defaultValue: DEFAULT_PROJECT_NAME
40
- }), "Setup cancelled") || DEFAULT_PROJECT_NAME;
41
- }
42
- /**
43
- * The template a non-interactive `init` gets, and the entry the selector opens
44
- * on — so an author who just presses Enter lands where they used to.
45
- */
46
- const DEFAULT_TEMPLATE = "quickstart-agent";
47
- /**
48
- * Ask which template to scaffold, listing what this CLI actually ships.
49
- *
50
- * The options are derived from {@link listTemplates} rather than a roster kept
51
- * here: that function already backs `aai templates` AND the unknown-template
52
- * error, so a template added to the package shows up in the picker with no
53
- * second list to update. {@link DEFAULT_TEMPLATE} is hoisted to the top and
54
- * pre-selected, which is what keeps a bare `aai init` a single Enter away from
55
- * the project it produced before there was a picker.
56
- *
57
- * Callers must not reach here when there is nobody to answer — `--yes` and
58
- * JSON mode (auto-detected on a pipe) resolve the default without prompting.
59
- */
60
- async function promptTemplate(list = listTemplates) {
61
- const [first, ...rest] = await list();
62
- if (first === void 0) return DEFAULT_TEMPLATE;
63
- if (rest.length === 0) return first;
64
- const names = [first, ...rest];
65
- const hasDefault = names.includes(DEFAULT_TEMPLATE);
66
- const ordered = hasDefault ? [DEFAULT_TEMPLATE, ...names.filter((name) => name !== DEFAULT_TEMPLATE)] : names;
67
- return unwrapCancel(await p.select({
68
- message: "Which template?",
69
- maxItems: 12,
70
- initialValue: hasDefault ? DEFAULT_TEMPLATE : first,
71
- options: ordered.map((name) => name === DEFAULT_TEMPLATE ? {
72
- value: name,
73
- hint: "the default starting point"
74
- } : { value: name })
75
- }), "Setup cancelled");
76
- }
77
- /** Best-effort corepack enable so pnpm is available (scaffold declares packageManager: pnpm). */
78
- async function ensurePnpm() {
79
- await execa("corepack", ["enable"], { reject: false });
80
- }
81
- /** Check if the project has any dependencies to install. */
82
- async function hasDeps(cwd) {
83
- if (await fileExists(path.join(cwd, "node_modules"))) return false;
84
- const pkgJson = await readJson(path.join(cwd, "package.json")) ?? {};
85
- const deps = Object.keys(pkgJson.dependencies ?? {});
86
- const devDeps = Object.keys(pkgJson.devDependencies ?? {});
87
- return deps.length > 0 || devDeps.length > 0;
88
- }
89
- /** Check whether the safe-chain binary is on PATH. */
90
- async function hasSafeChain() {
91
- const { failed } = await execa("safe-chain", ["--version"], { reject: false });
92
- return !failed;
93
- }
94
- /** Build the command + args for running pnpm, routing through safe-chain when available. */
95
- async function resolvePnpmCommand(checkSafeChain = hasSafeChain) {
96
- if (await checkSafeChain()) return {
97
- cmd: "safe-chain",
98
- args: ["pnpm", "--safe-chain-skip-minimum-package-age"]
99
- };
100
- return {
101
- cmd: "pnpm",
102
- args: []
103
- };
104
- }
105
- /** Run pnpm install and warn on failure. */
106
- async function runPnpmInstall(cwd) {
107
- const { cmd, args } = await resolvePnpmCommand();
108
- const pnpmArgs = isDevMode() ? ["install"] : ["install", "--ignore-workspace"];
109
- await execa(cmd, [...args, ...pnpmArgs], { cwd });
110
- }
111
- /**
112
- * Install deps with pnpm, reporting a failure through `warn` rather than
113
- * throwing: the project is scaffolded either way, and the two warnings say how
114
- * to finish the install by hand. Nothing downstream branches on the outcome —
115
- * `init` stops here — so it returns nothing.
116
- */
117
- async function installDeps(cwd, warn, silent) {
118
- if (!await hasDeps(cwd)) return;
119
- await ensurePnpm();
120
- try {
121
- await withSpinner(silent, {
122
- start: "Installing dependencies with pnpm",
123
- done: "Dependencies installed",
124
- failed: "Dependency install failed"
125
- }, () => runPnpmInstall(cwd));
126
- } catch (err) {
127
- warn(`pnpm install failed: ${errorMessage(err)}`);
128
- warn("Install pnpm (`npm install -g pnpm`), then run `pnpm install` in the project.");
129
- }
130
- }
131
- /** Resolve target directory relative to the user's current directory. */
132
- function resolveTargetDir(dir) {
133
- return path.resolve(resolveCwd(), dir);
134
- }
135
- function collectWarnings() {
136
- const warnings = [];
137
- return {
138
- warnings,
139
- warn: (message) => {
140
- warnings.push(message);
141
- log.warn(message);
142
- }
143
- };
144
- }
145
- /** Scaffold the project, optionally showing a spinner. */
146
- async function scaffoldProject(dir, cwd, template, silent) {
147
- const { runInit } = await import("./_init-Bp1CjRrU.mjs");
148
- await withSpinner(silent, {
149
- start: `Creating ${dir}`,
150
- done: "Project created",
151
- failed: `Could not create ${dir}`
152
- }, () => runInit({
153
- targetDir: cwd,
154
- template
155
- }));
156
- }
157
- /** Print post-init instructions. */
158
- function printPostInitInfo(cwd, monorepoRoot) {
159
- log.success(`Created ${cwd}`);
160
- if (monorepoRoot) log.info("Dev mode: project linked to workspace packages");
161
- log.info(`Next: cd ${cwd} && aai dev`);
162
- }
163
- async function executeInit(opts, extra) {
164
- const suppressUi = extra?.silent;
165
- if (!suppressUi) p.intro(styleText("cyanBright", "Create a new voice agent"));
166
- const dir = opts.dir ?? await promptProjectName(opts.yes);
167
- const monorepoRoot = getMonorepoRoot();
168
- const cwd = resolveTargetDir(dir);
169
- if (!opts.force && await fileExists(path.join(cwd, "agent.ts"))) throw new Error(`${AGENT_ENTRY} already exists in this directory. Use ${styleText("cyanBright", "--force")} to overwrite.`);
170
- const template = opts.template ?? (opts.yes || suppressUi ? DEFAULT_TEMPLATE : await promptTemplate());
171
- const { warn, warnings } = collectWarnings();
172
- await scaffoldProject(dir, cwd, template, suppressUi);
173
- await installDeps(cwd, warn, suppressUi);
174
- if (!suppressUi) printPostInitInfo(cwd, monorepoRoot);
175
- const data = {
176
- dir: cwd,
177
- template
178
- };
179
- if (warnings.length > 0) data.warnings = warnings;
180
- return ok(data);
181
- }
182
- //#endregion
183
- export { executeInit };
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
- import { a as ok, n as fail } from "./_output-DBP9Op_d.mjs";
3
- import { n as log } from "./_ui-DCt4qZrk.mjs";
4
- import { l as formatCappedList } from "./_utils-D5JGcjiW.mjs";
5
- import { i as unrunSpecFiles, n as classifyVitestError, r as runVitest, t as WIDEN_HINT } from "./_vitest-runner-BiAMIir1.mjs";
6
- import { omitUndefined } from "@alexkroman1/aai/utils";
7
- //#region src/test.ts
8
- /**
9
- * `aai test` — run agent tests via vitest.
10
- *
11
- * The launcher is `_vitest-runner.ts`, shared with `aai eval` and `aai build`'s
12
- * pre-build gate. What is here is the COMMAND: which files the test tier runs,
13
- * and the verdict over the ones a run did not cover.
14
- */
15
- /**
16
- * The files `aai test` runs, in preference order.
17
- *
18
- * The tier's filenames belong to the command, not to the runner — `aai eval`
19
- * declares `EVAL_FILES` the same way one module over, and neither names the
20
- * other's. `aai build` imports this one because its pre-build gate runs the
21
- * TEST tier.
22
- */
23
- const TEST_FILES = ["agent.test.ts", "agent.test.js"];
24
- /**
25
- * Execute agent tests and return structured result.
26
- *
27
- * **An incomplete run is not a pass.** For as long as this command answered
28
- * `{"ok":true,"data":{"passed":true}}` with exit 0 over specs it had not run,
29
- * the scaffold's `"test": "aai test"` was what users wired into CI — so a suite
30
- * of 25 tests could go red in the editor and green in the pipeline, and adding
31
- * one tool could break `registry.test.ts` in 17 assertions with `pnpm test` and
32
- * `pnpm build` both staying green throughout. It is the same defect
33
- * `defineExec`'s `cwd` policy exists for (a green result for a project that is
34
- * not there), one directory over, and it gets the same answer: the command
35
- * fails, names the files, and names the flag that runs them.
36
- */
37
- async function executeTest(cwd, opts = {}) {
38
- log.step(opts.all ? "Running project tests" : "Running agent tests");
39
- try {
40
- const ran = runVitest(cwd, {
41
- candidates: TEST_FILES,
42
- announceUnrun: false,
43
- ...omitUndefined({ all: opts.all })
44
- });
45
- const unrun = unrunSpecFiles(cwd, ran);
46
- if (unrun.length > 0) return incomplete(ran, unrun);
47
- if (ran === false) {
48
- log.info("No test file found. Create agent.test.ts to add tests.");
49
- return ok({
50
- passed: true,
51
- skipped: true,
52
- ran: [],
53
- unrun: [],
54
- complete: true
55
- });
56
- }
57
- log.success(`Tests passed (${ran.length} spec file(s))`);
58
- return ok({
59
- passed: true,
60
- ran,
61
- unrun: [],
62
- complete: true
63
- });
64
- } catch (err) {
65
- const { code, message } = classifyVitestError(err);
66
- return fail(code, message);
67
- }
68
- }
69
- /**
70
- * The verdict for a run that left specs uncovered.
71
- *
72
- * Both arms fail, and the `ran === false` arm is the one that had misled
73
- * longest: `aai test` printed "No test file found" while the project's specs sat
74
- * right there unrun, which reads as "this project has no tests". Measured on a
75
- * project whose only spec was `tools/echo_back.test.ts` — `{"passed":true,
76
- * "skipped":true}`, exit 0, and not a word about it.
77
- */
78
- function incomplete(ran, unrun) {
79
- const preamble = ran === false ? `\`aai test\` found no agent.test.ts, so it ran nothing, but ${unrun.length} spec file(s) exist` : `\`aai test\` ran ${ran.join(", ")} only — ${unrun.length} other spec file(s) in this project were not run`;
80
- return fail("incomplete_run", `${preamble}: ${formatCappedList(unrun)}. An unrun spec is not a passing one, so this is not a green result.`, WIDEN_HINT);
81
- }
82
- //#endregion
83
- export { TEST_FILES, executeTest };