@alexkroman1/aai-cli 16.1.0 → 18.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 (220) 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/_console-audio.d.ts +17 -0
  5. package/dist/_console-session.d.ts +70 -0
  6. package/dist/_deno-target.d.ts +15 -14
  7. package/dist/_dev-env.d.ts +19 -13
  8. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-Dtp4aAlo.mjs} +26 -18
  9. package/dist/_dev-server.d.ts +5 -3
  10. package/dist/_init.d.ts +39 -0
  11. package/dist/_modal-target.d.ts +11 -6
  12. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  13. package/dist/_preflight.d.ts +110 -5
  14. package/dist/_target-bundle.d.ts +112 -0
  15. package/dist/_target-entry.d.ts +81 -0
  16. package/dist/_templates-DXadVNsL.mjs +135 -0
  17. package/dist/_templates.d.ts +11 -34
  18. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  19. package/dist/_vitest-runner.d.ts +35 -23
  20. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  21. package/dist/build.d.ts +34 -4
  22. package/dist/cli.mjs +40 -16
  23. package/dist/console-BsyE3DyB.mjs +422 -0
  24. package/dist/console.d.ts +37 -0
  25. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  26. package/dist/deploy.d.ts +9 -0
  27. package/dist/{dev-Du8pCWFq.mjs → dev-BGWU2zPP.mjs} +1 -1
  28. package/dist/dev.d.ts +1 -1
  29. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  30. package/dist/init-CbOhyNYe.mjs +559 -0
  31. package/dist/init.d.ts +43 -3
  32. package/dist/scaffold/CLAUDE.md +161 -166
  33. package/dist/scaffold/package.json +6 -6
  34. package/dist/scaffold/vite.config.ts +29 -1
  35. package/dist/start.d.ts +3 -3
  36. package/dist/{studio-It7SRfUN.mjs → studio-BRJsw7lr.mjs} +19 -9
  37. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  38. package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
  39. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  40. package/dist/templates/applicant-screening-agent/crews.ts +4 -4
  41. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  42. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  43. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  44. package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
  45. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  46. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  47. package/dist/templates/coding-agent/agent.test.ts +109 -0
  48. package/dist/templates/coding-agent/agent.ts +45 -0
  49. package/dist/templates/coding-agent/chat.ts +63 -0
  50. package/dist/templates/coding-agent/shared.ts +46 -0
  51. package/dist/templates/coding-agent/system-prompt.md +32 -0
  52. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  53. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  54. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  55. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  56. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  57. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  58. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  59. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  60. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  61. package/dist/templates/custom-pipeline-agent/agent.ts +3 -2
  62. package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
  63. package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
  64. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  65. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
  66. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  67. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  68. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  69. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  70. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +9 -2
  71. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  72. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  73. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  74. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  75. package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
  76. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  77. package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
  78. package/dist/templates/executive-inbox-agent/meeting.ts +3 -3
  79. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  80. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  81. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  82. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  83. package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
  84. package/dist/templates/front-desk-agent/agent.test.ts +150 -0
  85. package/dist/templates/front-desk-agent/agent.ts +22 -0
  86. package/dist/templates/front-desk-agent/shared.ts +234 -0
  87. package/dist/templates/front-desk-agent/system-prompt.md +13 -0
  88. package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
  89. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  90. package/dist/templates/hotel-reception-agent/agent.test.ts +3 -3
  91. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  92. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  93. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  94. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +3 -3
  95. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  96. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  97. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  98. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  99. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  100. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  101. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  102. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  105. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  106. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  107. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  108. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  109. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  114. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  116. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  117. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  118. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  119. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  120. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  121. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  122. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  123. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  124. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  125. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  126. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  127. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  128. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  129. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  130. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  131. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  132. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  133. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  134. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  135. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  136. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  137. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  138. package/dist/templates/medication-safety-agent/agent.test.ts +57 -4
  139. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  140. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  141. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  142. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
  143. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  144. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  145. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
  146. package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
  147. package/dist/templates/push-to-talk-agent/agent.ts +22 -0
  148. package/dist/templates/push-to-talk-agent/client.tsx +124 -0
  149. package/dist/templates/push-to-talk-agent/shared.ts +34 -0
  150. package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
  151. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
  152. package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
  153. package/dist/templates/quickstart-agent/agent.eval.test.ts +91 -3
  154. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  155. package/dist/templates/quickstart-agent/agent.ts +18 -2
  156. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  157. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  158. package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
  159. package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
  160. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  161. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  162. package/dist/templates/research-planner-agent/agent.test.ts +26 -16
  163. package/dist/templates/research-planner-agent/agent.ts +3 -0
  164. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  165. package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
  166. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  167. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  168. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  169. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +124 -5
  170. package/dist/templates/roadside-assistance-agent/agent.test.ts +39 -7
  171. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  172. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  173. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  174. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  175. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  176. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  177. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  178. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  179. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  180. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  181. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  182. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  183. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  184. package/dist/templates/technical-support-agent/agent.test.ts +29 -23
  185. package/dist/templates/technical-support-agent/agent.ts +5 -1
  186. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  187. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  188. package/dist/templates/technical-support-agent/procedure.ts +7 -6
  189. package/dist/templates/technical-support-agent/shared.ts +10 -146
  190. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  191. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  192. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  193. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  194. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  195. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  196. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  197. package/dist/templates/topic-briefing-agent/agent.test.ts +61 -36
  198. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  199. package/dist/templates/topic-briefing-agent/shared.ts +19 -18
  200. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  201. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  202. package/dist/templates/transcription-workflow/agent.ts +3 -0
  203. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
  204. package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
  205. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  206. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  207. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  208. package/dist/templates/web-research-agent/agent.ts +30 -0
  209. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  210. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  211. package/dist/templates/word-game-agent/agent.test.ts +3 -1
  212. package/dist/templates/word-game-agent/agent.ts +20 -0
  213. package/dist/test-CjKPQ9_B.mjs +102 -0
  214. package/dist/test.d.ts +37 -12
  215. package/package.json +5 -5
  216. package/dist/_init-Bp1CjRrU.mjs +0 -199
  217. package/dist/_preflight-CcAR577V.mjs +0 -46
  218. package/dist/_templates-CuP74F8D.mjs +0 -291
  219. package/dist/init-CY4NAXAA.mjs +0 -183
  220. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -39,13 +39,43 @@
39
39
  * reads this one — so a fourth target is a fourth file plus two lines here.
40
40
  */
41
41
  /**
42
- * What {@link TargetOutput.secret} puts where a variable NAME goes.
42
+ * What a {@link DeployStep} puts where a variable NAME goes.
43
43
  *
44
44
  * Angle brackets rather than a `$NAME` or `%s`: the string is printed for a
45
45
  * human to adapt as often as it is substituted into, and both of the other two
46
46
  * are shell-significant enough to be mistaken for something to type literally.
47
47
  */
48
48
  export declare const SECRET_NAME_PLACEHOLDER = "<NAME>";
49
+ /**
50
+ * The placeholders {@link resolveDeploySteps} FILLS, and the ones it leaves.
51
+ *
52
+ * The line between them is who KNOWS the value at build time, and it is worth
53
+ * stating because it is the same line `.env.example` draws: this build knows
54
+ * every declared variable name and the agent's own name, so leaving those as
55
+ * placeholders would be withholding something it could have printed. It knows
56
+ * nothing about the reader's account — an org, an app that may not exist yet —
57
+ * or about a secret's VALUE, which is the whole point of declarations shipping
58
+ * while values do not.
59
+ *
60
+ * So {@link SECRET_NAME_PLACEHOLDER} and {@link MODAL_SECRET_PLACEHOLDER} are
61
+ * substituted, and these three survive into the printed command as prompts for
62
+ * the reader to fill.
63
+ */
64
+ export declare const ORG_PLACEHOLDER = "<ORG>";
65
+ /** @see ORG_PLACEHOLDER */
66
+ export declare const APP_PLACEHOLDER = "<APP>";
67
+ /** @see ORG_PLACEHOLDER */
68
+ export declare const SECRET_VALUE_PLACEHOLDER = "<value>";
69
+ /**
70
+ * Where Modal's derived secret name goes — see {@link modalSecretName}.
71
+ *
72
+ * Substituted rather than left for the reader, because `app.py` DERIVES that
73
+ * name from the agent's own and a reader who invents one gets a deploy that
74
+ * fails on `Secret.from_name`. The emitted file's docstring already prints the
75
+ * resolved name; this is the same string reaching the same reader one surface
76
+ * earlier.
77
+ */
78
+ export declare const MODAL_SECRET_PLACEHOLDER = "<secret>";
49
79
  /** The targets `aai build --target` accepts. */
50
80
  export declare const BUILD_TARGETS: readonly ["node", "vercel", "deno", "modal"];
51
81
  export type BuildTarget = (typeof BUILD_TARGETS)[number];
@@ -162,28 +192,58 @@ export interface TargetOutput {
162
192
  * different program than the one they just built.
163
193
  */
164
194
  readonly preview?: string;
165
- /** Ship what was just emitted. */
166
- readonly deploy?: string;
167
195
  /**
168
- * How this host sets ONE secret's value, with {@link SECRET_NAME_PLACEHOLDER}
169
- * standing in for the variable name.
196
+ * Ship what was just emitted — the ORDERED sequence, not one command.
170
197
  *
171
- * `.env.example` DECLARES which variables become `ctx.env` and the host
172
- * supplies the values (see `DEPLOY_ENV_FILES` and the `RUNTIME_FILES` note in
173
- * `_vercel-output.ts` — declarations ship, values do not). Nothing checked
174
- * that the host actually had them, so a deployment whose credentials were
175
- * never set built green and failed at its first session, which reads as a
176
- * provider outage rather than as an unset variable. `missingDeployEnv` in
177
- * `build.ts` is that check and this is the string it points the reader at.
198
+ * It was one string, and the string was WRONG for both hosts that have a
199
+ * local flow. Measured end to end: `cd .aai/deno && deno deploy` fails
200
+ * `APP_NOT_FOUND` because the app has to be created first; the create then
201
+ * has to override Deploy's auto-detected build config, which for this
202
+ * directory resolves to no entrypoint and fails at `building`; and the
203
+ * deployment then fails at `warming` until the declared secret is set,
204
+ * because this server crashes in `createRuntime` without a provider
205
+ * credential rather than starting and failing later. Three distinct
206
+ * failures, none of which a one-liner prepares a reader for. `modal deploy`
207
+ * has the milder version of the same shape — `app.py` resolves
208
+ * `Secret.from_name` at deploy time, so it dies unless the secret exists.
178
209
  *
179
- * Absent where there is no honest answer, the same rule {@link preview} and
180
- * {@link deploy} follow. `node` has no host to name — the deployment is a
181
- * process someone runs, reading `.env` or whatever `-e` flags a container got.
182
- * `deno` and `modal` are absent because their commands are unverified here,
183
- * not because they have none; the warning still names the variables and says
184
- * they must be set in the host's environment, which is the load-bearing half.
210
+ * Absent for a target with no honest answer — `node`, which deploys nowhere.
185
211
  */
186
- readonly secret?: string;
212
+ readonly deploy?: readonly DeployStep[];
213
+ }
214
+ /**
215
+ * WHEN a step runs, which is the whole reason the sequence is data.
216
+ *
217
+ * A reader needs three different things from these commands and a flat list
218
+ * answers none of them: which command they must re-run on every deploy, which
219
+ * one they run once per app and never again, and which one repeats per secret.
220
+ * Rendering differs per case too — see `build.ts`, where the post-build log
221
+ * omits `build` (the reader just ran one) while the `--json` result keeps it,
222
+ * because a CI job scripting a fresh checkout genuinely has to run it.
223
+ *
224
+ * - `build` — `aai build --target <t>`. **Mandatory before every deploy**, and
225
+ * the one step whose omission is silent: `deno deploy` and `modal deploy`
226
+ * both upload the emitted directory AS IT STANDS, so a forgotten rebuild
227
+ * ships the previous bundle and reports success. Deno prints "No files were
228
+ * changed, so there is nothing to upload", which reads like a no-op rather
229
+ * than like a stale deployment.
230
+ * - `once` — creating or linking the app. A LABEL and not a branch: whether
231
+ * the app exists is account state on someone else's platform, so this is
232
+ * printed with its caveat rather than conditionally hidden. Guessing would
233
+ * either hide the step a first-timer needs or nag forever.
234
+ * - `perSecret` — expanded per variable `missingDeployEnv` reported, with the
235
+ * real name substituted. This is what replaced {@link TargetOutput}'s old
236
+ * `secret` field, which was absent for `deno` and `modal` on the grounds
237
+ * that their commands were "unverified here" — so the warning for the two
238
+ * hosts that most need one said only "Set it in the deno environment".
239
+ * - `each` — the upload itself.
240
+ */
241
+ export type DeployStepWhen = "build" | "once" | "perSecret" | "each";
242
+ /** One command in a target's {@link TargetOutput.deploy} sequence. */
243
+ export interface DeployStep {
244
+ readonly when: DeployStepWhen;
245
+ /** The command, carrying any of the placeholders above. */
246
+ readonly run: string;
187
247
  }
188
248
  /**
189
249
  * Every target's output and commands.
@@ -195,3 +255,22 @@ export interface TargetOutput {
195
255
  * with the same `cd`.
196
256
  */
197
257
  export declare const TARGET_OUTPUTS: Readonly<Record<BuildTarget, TargetOutput>>;
258
+ /**
259
+ * The sequence a reader should actually run: placeholders this build can fill
260
+ * FILLED, and the `perSecret` step expanded once per variable that needs one.
261
+ *
262
+ * Resolved here rather than at the log site so the `--json` result and the
263
+ * printed lines cannot disagree — the defect that produced this whole shape was
264
+ * a deploy instruction that lived as a string at one call site and was wrong.
265
+ *
266
+ * With nothing missing, the `perSecret` step is kept ONCE in placeholder form
267
+ * rather than dropped, and that is deliberate: `missingDeployEnv` reads the
268
+ * BUILD's environment, which says nothing about what the host has (its own doc
269
+ * makes this point), so an empty `missing` means "your shell had these", not
270
+ * "the platform does". Dropping the step there would quietly promise a host is
271
+ * configured when nobody has configured it.
272
+ */
273
+ export declare function resolveDeploySteps(target: BuildTarget, options: {
274
+ readonly agentName: string;
275
+ readonly missingEnv: readonly string[];
276
+ }): DeployStep[];
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `aai console`'s audio devices, as two SoX subprocesses.
3
+ *
4
+ * SoX rather than a native addon: `rec` and `play` open the system's DEFAULT
5
+ * input and output on macOS (CoreAudio), Linux (ALSA/PulseAudio) and Windows
6
+ * with one command line, and a subprocess costs this package no install-time
7
+ * build step and no binary per platform. The price is that SoX must be
8
+ * installed, which {@link missingSoxMessage} says in so many words.
9
+ *
10
+ * Both run in raw PCM16LE mono (`-t raw -b 16 -e signed-integer -c 1 -L`),
11
+ * the format the session speaks, at the rate the session announced.
12
+ */
13
+ import type { ConsoleAudio } from "./_console-session.ts";
14
+ /** What to tell a developer whose machine has no SoX. */
15
+ export declare function missingSoxMessage(binary: string): string;
16
+ /** The SoX-backed devices. */
17
+ export declare const soxAudio: ConsoleAudio;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * `aai console`'s session wiring, with the audio devices abstracted away.
3
+ *
4
+ * The console is a {@link ClientSink} for `connectSession` — the same seam any
5
+ * embedder uses to run a session over its own audio I/O — and nothing more. It
6
+ * speaks no protocol and opens no socket: the session writes events and agent
7
+ * audio to the sink, and the microphone is fed straight into the connection.
8
+ *
9
+ * The devices are a {@link ConsoleAudio} so this module is testable without a
10
+ * sound card; `_console-audio.ts` is the SoX implementation the command uses.
11
+ */
12
+ import type { ClientSink } from "@alexkroman1/aai/protocol";
13
+ import type { SessionConnection } from "@alexkroman1/aai-runtime";
14
+ /** A running speaker: PCM16LE mono at the rate it was opened with. */
15
+ export type ConsolePlayer = {
16
+ write(pcm16: Uint8Array): void;
17
+ /**
18
+ * Drop whatever the device has not played yet. The runtime's pacer already
19
+ * discards what it is still holding on a barge-in; this is the part that
20
+ * already left it.
21
+ */
22
+ flush(): void;
23
+ stop(): void;
24
+ };
25
+ /** A running microphone. */
26
+ export type ConsoleCapture = {
27
+ stop(): void;
28
+ };
29
+ /** The two audio devices the console needs. */
30
+ export type ConsoleAudio = {
31
+ /** Start the microphone, delivering PCM16LE mono chunks at `sampleRate`. */
32
+ startCapture(sampleRate: number, onChunk: (pcm16: Uint8Array) => void, onError: (err: Error) => void): ConsoleCapture;
33
+ /** Open the speaker at `sampleRate`. */
34
+ startPlayback(sampleRate: number, onError: (err: Error) => void): ConsolePlayer;
35
+ };
36
+ /** Where the console prints a line of conversation. */
37
+ export type ConsolePrinter = {
38
+ user(text: string): void;
39
+ agent(text: string, interrupted?: boolean): void;
40
+ tool(name: string, args: Record<string, unknown>): void;
41
+ error(message: string, fatal: boolean): void;
42
+ };
43
+ /**
44
+ * The sink the session writes to: agent audio to the speaker, the transcript
45
+ * to the terminal.
46
+ *
47
+ * `onClosed` fires when the RUNTIME closes the sink — a session that failed to
48
+ * start, or one resumed elsewhere — so the command can stop the devices and
49
+ * exit rather than sit with a live microphone feeding nothing.
50
+ *
51
+ * `onFatal` fires on a FATAL `error.reported`, which the protocol defines as
52
+ * "the session is over". A browser shows the banner and the person hangs up;
53
+ * the telephony bridge ends the call; the console has to end itself too, or a
54
+ * session that can never speak (a provider refusing the key) leaves the
55
+ * developer talking to silence.
56
+ */
57
+ export declare function createConsoleSink(opts: {
58
+ player: ConsolePlayer;
59
+ print: ConsolePrinter;
60
+ onClosed: (reason?: string) => void;
61
+ onFatal: (message: string) => void;
62
+ }): ClientSink;
63
+ /**
64
+ * Feed a byte stream into a connection as whole PCM16 samples.
65
+ *
66
+ * A pipe hands over reads of whatever length it likes, and an odd one would
67
+ * split a sample across two chunks — every sample after it would then be read
68
+ * with its bytes swapped, which is loud noise rather than a subtle error.
69
+ */
70
+ export declare function createSampleAligner(connection: Pick<SessionConnection, "sendAudio">): (bytes: Uint8Array) => void;
@@ -6,7 +6,7 @@
6
6
  * it goes and what goes in it.
7
7
  *
8
8
  * Deno and Modal are the two LONG-LIVED targets: each entry binds a port and
9
- * each drains on a signal ({@link TARGET_DRAIN_SOURCE}), which is what makes
9
+ * each drains on a signal (`TARGET_DRAIN_SOURCE`), which is what makes
10
10
  * them the pair that also shares `_target-output.ts`.
11
11
  */
12
12
  /**
@@ -23,6 +23,14 @@ export declare const DENO_OUTPUT_DIR: string;
23
23
  export declare const DENO_ENTRY_FILE = "server.mjs";
24
24
  /** Deno's own project file inside {@link DENO_OUTPUT_DIR}. */
25
25
  export declare const DENO_CONFIG_FILE = "deno.json";
26
+ /**
27
+ * The port the entry binds when the host set no `PORT`.
28
+ *
29
+ * Deploy sets one, so this is what a bare `deno task start` on a laptop gets —
30
+ * the same number the Modal entry defaults to, because a reader who has run
31
+ * one emit should not have to look up the other.
32
+ */
33
+ export declare const DENO_PORT = 8000;
26
34
  /**
27
35
  * The `deno.json` written beside the entry, so the output DESCRIBES how to run
28
36
  * itself.
@@ -56,18 +64,11 @@ export declare const DENO_CONFIG_SOURCE: string;
56
64
  * `aai start` run. Verified against a live deployment with real speech: 74
57
65
  * audio frames back, transcript and reply intact.
58
66
  *
59
- * `0.0.0.0`, not the loopback default: the platform reaches this from outside
60
- * the process, so binding loopback answers nothing.
61
- *
62
- * `import.meta.dirname` rather than `process.cwd()` — the artifacts are copied
63
- * in BESIDE this file, and the working directory belongs to the platform.
64
- *
65
- * `globalThis.Deno?.env` rather than `Deno.env`: this file is bundled by a
66
- * Node-side build and is read by Node tooling (its own spec included), where a
67
- * bare `Deno` is a `ReferenceError` at parse-adjacent evaluation time.
67
+ * ## The body is SHARED, and only these three lines are Deno's
68
68
  *
69
- * `process` needs no such guard and deliberately gets none: it is a global in
70
- * Deno as well as in Node, so {@link TARGET_DRAIN_SOURCE} is the identical text
71
- * in both long-lived entries rather than a template with a hole in it.
69
+ * {@link longLivedEntrySource} carries the bind, the `0.0.0.0`, the
70
+ * `import.meta.dirname` and the drain — see that module for why the port read
71
+ * is no longer Deno's own, which is what left this artifact runnable only under
72
+ * Deno for as long as it read `globalThis.Deno.env` and nothing else.
72
73
  */
73
- export declare const DENO_ENTRY_SOURCE = "// Generated by `aai build --target deno` \u2014 do not edit, and do not commit.\n// Deno Deploy runs this as a long-lived process and expects it to listen.\n// See @alexkroman1/aai-cli/start.\nimport { createProjectServer } from \"@alexkroman1/aai-cli/start\";\n\nconst server = await createProjectServer({ cwd: import.meta.dirname });\n\nawait server.listen(Number(globalThis.Deno?.env.get(\"PORT\") ?? 8000), \"0.0.0.0\");\n\n// The host stops this process on every scale-in and every redeploy; closing the\n// server ends live sessions instead of dropping their sockets.\nfor (const name of [\"SIGINT\", \"SIGTERM\"]) {\n try {\n process.once(name, () => {\n server.close().then(\n () => process.exit(0),\n () => process.exit(1),\n );\n });\n } catch {\n // No signal support on this host \u2014 nothing will ever arrive to drain on.\n }\n}\n";
74
+ export declare const DENO_ENTRY_SOURCE: string;
@@ -30,27 +30,33 @@ export declare function hostModeEnv(providerEnv: Record<string, string>): Record
30
30
  */
31
31
  export declare function devBindHost(): string | undefined;
32
32
  /**
33
- * File watching is OPT-IN — `aai dev --watch`, or `AAI_DEV_WATCH=1`.
33
+ * File watching is on for a HUMAN and off for everything else — `--watch` /
34
+ * `--watch=false` and `AAI_DEV_WATCH` override it in either direction.
34
35
  *
35
36
  * A restart rebuilds the bundle and replaces the server, which drops nothing
36
37
  * mid-request but does end in-flight voice sessions. That is the right default
37
38
  * while editing an agent and the wrong one while a benchmark is driving the
38
39
  * host for twenty minutes: a stray formatter save, a `.env` touch, or a git
39
40
  * operation restarts the server underneath the run, and the harness reports it
40
- * as a provider failure several records deep.
41
+ * as a provider failure several records deep. That argument is why watching was
42
+ * opt-in, and it is unchanged — what changed is that it is an argument about a
43
+ * HARNESS, and every default here was paying for it.
41
44
  *
42
- * **The FLAG exists because the variable was undiscoverable**, which made the
43
- * default a defect rather than a decision: `aai dev --help` listed nothing about
44
- * watching, `AAI_DEV_WATCH` appeared in no document a user reads, and the guide
45
- * shipped into every scaffolded project opened with "Iterate in `pnpm dev` —
46
- * hot reload". So the promise was false and there was no way to find the switch
47
- * that makes it true. The variable stays for a process supervisor, which has an
48
- * environment and no argv.
45
+ * **The two TTYs are the narrowing.** `process.stdin.isTTY && stdout.isTTY` is
46
+ * already this CLI's discriminator for "a person is running this" (`cli.ts`
47
+ * confirms before an implicit publish on exactly that pair), and a harness or
48
+ * supervisor driving `aai dev` has neither — it pipes stdout, which is also
49
+ * what auto-selects JSON mode. So the twenty-minute benchmark keeps today's
50
+ * behaviour by construction, without having to know a variable exists, and the
51
+ * author editing `agent.ts` in a terminal gets the reload the guide shipped
52
+ * into every scaffolded project has always promised ("Iterate in `pnpm dev` —
53
+ * hot reload") and the quickstart's own `aai dev --watch` had to ask for.
49
54
  *
50
- * The flag WINS when passed, in both directions: `--watch` turns it on where the
51
- * variable is unset or off, and `--watch=false` turns it off where the variable
52
- * says on — an explicit argument that a stale exported variable could override
53
- * would be the same discoverability bug wearing the fix's clothes.
55
+ * The FLAG still wins when passed, in both directions, and `AAI_DEV_WATCH`
56
+ * decides whenever it carries a value — `AAI_DEV_WATCH=0` is what turns
57
+ * watching OFF at a terminal, and it has to be read explicitly for that:
58
+ * before, every value but the four truthy ones fell through to a default of
59
+ * off, so `=0` worked by coincidence rather than by being read.
54
60
  */
55
61
  export declare function devWatchEnabled(flag?: boolean | undefined): boolean;
56
62
  /**
@@ -43,31 +43,39 @@ function devBindHost() {
43
43
  return host ? host : void 0;
44
44
  }
45
45
  /**
46
- * File watching is OPT-IN — `aai dev --watch`, or `AAI_DEV_WATCH=1`.
46
+ * File watching is on for a HUMAN and off for everything else — `--watch` /
47
+ * `--watch=false` and `AAI_DEV_WATCH` override it in either direction.
47
48
  *
48
49
  * A restart rebuilds the bundle and replaces the server, which drops nothing
49
50
  * mid-request but does end in-flight voice sessions. That is the right default
50
51
  * while editing an agent and the wrong one while a benchmark is driving the
51
52
  * host for twenty minutes: a stray formatter save, a `.env` touch, or a git
52
53
  * operation restarts the server underneath the run, and the harness reports it
53
- * as a provider failure several records deep.
54
- *
55
- * **The FLAG exists because the variable was undiscoverable**, which made the
56
- * default a defect rather than a decision: `aai dev --help` listed nothing about
57
- * watching, `AAI_DEV_WATCH` appeared in no document a user reads, and the guide
58
- * shipped into every scaffolded project opened with "Iterate in `pnpm dev` —
59
- * hot reload". So the promise was false and there was no way to find the switch
60
- * that makes it true. The variable stays for a process supervisor, which has an
61
- * environment and no argv.
62
- *
63
- * The flag WINS when passed, in both directions: `--watch` turns it on where the
64
- * variable is unset or off, and `--watch=false` turns it off where the variable
65
- * says on — an explicit argument that a stale exported variable could override
66
- * would be the same discoverability bug wearing the fix's clothes.
54
+ * as a provider failure several records deep. That argument is why watching was
55
+ * opt-in, and it is unchanged — what changed is that it is an argument about a
56
+ * HARNESS, and every default here was paying for it.
57
+ *
58
+ * **The two TTYs are the narrowing.** `process.stdin.isTTY && stdout.isTTY` is
59
+ * already this CLI's discriminator for "a person is running this" (`cli.ts`
60
+ * confirms before an implicit publish on exactly that pair), and a harness or
61
+ * supervisor driving `aai dev` has neither — it pipes stdout, which is also
62
+ * what auto-selects JSON mode. So the twenty-minute benchmark keeps today's
63
+ * behaviour by construction, without having to know a variable exists, and the
64
+ * author editing `agent.ts` in a terminal gets the reload the guide shipped
65
+ * into every scaffolded project has always promised ("Iterate in `pnpm dev` —
66
+ * hot reload") and the quickstart's own `aai dev --watch` had to ask for.
67
+ *
68
+ * The FLAG still wins when passed, in both directions, and `AAI_DEV_WATCH`
69
+ * decides whenever it carries a value — `AAI_DEV_WATCH=0` is what turns
70
+ * watching OFF at a terminal, and it has to be read explicitly for that:
71
+ * before, every value but the four truthy ones fell through to a default of
72
+ * off, so `=0` worked by coincidence rather than by being read.
67
73
  */
68
74
  function devWatchEnabled(flag) {
69
75
  if (flag !== void 0) return flag;
70
- return /^(1|true|yes|on)$/i.test(process.env.AAI_DEV_WATCH?.trim() ?? "");
76
+ const declared = process.env.AAI_DEV_WATCH?.trim();
77
+ if (declared) return /^(1|true|yes|on)$/i.test(declared);
78
+ return process.stdin.isTTY === true && process.stdout.isTTY === true;
71
79
  }
72
80
  /**
73
81
  * The logger the dev server's runtime writes through.
@@ -474,7 +482,7 @@ function viteDevConfig(cwd, vitePort, backendPort) {
474
482
  *
475
483
  * Imports agent.ts directly for the full agent definition,
476
484
  * builds a runtime, and starts an HTTP+WebSocket server. File watching is
477
- * opt-in via `AAI_DEV_WATCH=1` (see devWatchEnabled). Optionally runs Vite for
485
+ * on at a terminal, off otherwise (see devWatchEnabled). Optionally runs Vite for
478
486
  * client SPA HMR.
479
487
  */
480
488
  /**
@@ -689,4 +697,4 @@ async function startDevServer(opts) {
689
697
  return supervisor.close;
690
698
  }
691
699
  //#endregion
692
- export { startDevServer };
700
+ export { loadWorker, resolveAgentEnv, startDevServer };
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Imports agent.ts directly for the full agent definition,
5
5
  * builds a runtime, and starts an HTTP+WebSocket server. File watching is
6
- * opt-in via `AAI_DEV_WATCH=1` (see devWatchEnabled). Optionally runs Vite for
6
+ * on at a terminal, off otherwise (see devWatchEnabled). Optionally runs Vite for
7
7
  * client SPA HMR.
8
8
  */
9
9
  import type { AgentDef } from "@alexkroman1/aai";
@@ -22,6 +22,7 @@ import { type FSWatcher } from "chokidar";
22
22
  * can't mask one that would be missing both here and after deploy.
23
23
  */
24
24
  export declare function agentEnvWarnings(agentDef: Pick<AgentDef, "stt" | "llm" | "tts" | "s2s" | "requiredEnv" | "page">, env: Record<string, string>, shellEnv?: Record<string, string | undefined>): string[];
25
+ export declare function resolveAgentEnv(root: string, agentDef: AgentDef): Promise<Record<string, string>>;
25
26
  /**
26
27
  * Load the agent definition by bundling agent.ts (and all its local imports)
27
28
  * into a single ESM file, then importing that. A raw `import(agent.ts?t=...)`
@@ -57,8 +58,9 @@ export type DevServerOptions = {
57
58
  cwd: string;
58
59
  port: number;
59
60
  /**
60
- * Restart on a file change. Omitted, `AAI_DEV_WATCH` decides — see
61
- * {@link devWatchEnabled} for why watching is opt-in at all.
61
+ * Restart on a file change. Omitted, `AAI_DEV_WATCH` decides, and failing
62
+ * that the TTY pair does — see {@link devWatchEnabled} for why a person gets
63
+ * a watcher and a harness does not.
62
64
  */
63
65
  watch?: boolean | undefined;
64
66
  };
package/dist/_init.d.ts CHANGED
@@ -1,6 +1,45 @@
1
+ /**
2
+ * The package managers `aai init` can install a project with, in PREFERENCE
3
+ * order — which is also the order `detectPackageManager` (`init.ts`) probes
4
+ * `PATH` in.
5
+ *
6
+ * pnpm first because it stays the preference where it is present (the scaffold
7
+ * is a pnpm workspace root and its lockfile is pnpm's), but it is no longer the
8
+ * only answer: the install instructions everywhere teach
9
+ * `npm i -g @alexkroman1/aai-cli`, and `init` then installed with pnpm alone —
10
+ * reaching it through `corepack enable`, which does not exist on Node >= 25,
11
+ * i.e. half the range `scaffold/package.json` declares.
12
+ *
13
+ * The list lives here, beside {@link PM_COMMANDS}, so the ORDER and the
14
+ * per-manager command spellings cannot disagree about which managers exist: a
15
+ * fifth entry fails to compile until that record has a row for it.
16
+ */
17
+ export declare const PACKAGE_MANAGERS: readonly ["pnpm", "npm", "bun", "yarn"];
18
+ /** One of {@link PACKAGE_MANAGERS}. */
19
+ export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
20
+ /** The manager `aai init` installed with, and the version to pin to it. */
21
+ export type PackageManagerInfo = {
22
+ readonly name: PackageManager;
23
+ /**
24
+ * What goes in the manifest's `packageManager` field. Absent means the field
25
+ * is REMOVED — see {@link stampPackageManager}.
26
+ */
27
+ readonly version?: string | undefined;
28
+ };
1
29
  export type InitOptions = {
2
30
  targetDir: string;
3
31
  template: string;
32
+ /**
33
+ * The manager the caller is about to install with — see
34
+ * {@link detectPackageManager} in `init.ts`.
35
+ *
36
+ * It reaches this far because the two files that have to AGREE with it are
37
+ * written here: the README's every command, and the manifest's
38
+ * `packageManager` pin. Omitted means npm and no pin, which is what a caller
39
+ * with no opinion should generate — npm is the one manager every Node install
40
+ * already has.
41
+ */
42
+ packageManager?: PackageManagerInfo | undefined;
4
43
  };
5
44
  /** Rewrite workspace deps to link: paths so pnpm links to local source. */
6
45
  export declare function patchPackageJsonForWorkspace(targetDir: string): Promise<void>;
@@ -44,14 +44,19 @@ export declare const MODAL_PORT = 8000;
44
44
  * `aai start` shape rather than the serverless one — `listen()`, `0.0.0.0`
45
45
  * (the proxy reaches this from outside the process), and artifacts resolved
46
46
  * from {@link MODAL_ENTRY_FILE}'s own directory rather than from a working
47
- * directory the platform owns. The entry is still NOT shared with
48
- * {@link DENO_ENTRY_SOURCE} — the two read the port from different runtimes,
49
- * and a shared entry would be a template with a hole where that goes — but the
50
- * DRAIN below is, which is the part neither host's contract varies in.
47
+ * directory the platform owns.
48
+ *
49
+ * ## The entry IS shared with Deno's now
50
+ *
51
+ * It was not, on the reading that the two read the port from different
52
+ * runtimes and a shared entry would be a template with a hole where that goes.
53
+ * `RUNTIME_PORT_SOURCE` reads both runtimes, so the hole closed — and the
54
+ * copy cost more than duplication: it is what made each artifact runnable only
55
+ * under the runtime whose host emitted it. See `_target-entry.ts`.
51
56
  *
52
57
  * ## The drain is SHARED, and Modal supplies its other half
53
58
  *
54
- * The `SIGINT`/`SIGTERM` body is {@link TARGET_DRAIN_SOURCE}, the same text the
59
+ * The `SIGINT`/`SIGTERM` body is `TARGET_DRAIN_SOURCE`, the same text the
55
60
  * Deno entry carries — it used to live here alone, on the reading that Modal
56
61
  * stops containers and Deno Deploy does not, which is not true of either.
57
62
  *
@@ -61,4 +66,4 @@ export declare const MODAL_PORT = 8000;
61
66
  * platform's own deploy learned that when orphaned guest sandboxes billed ~20
62
67
  * minutes each on every release (see `run_node` in `scripts/modal_image.py`).
63
68
  */
64
- export declare const MODAL_ENTRY_SOURCE = "// Generated by `aai build --target modal` \u2014 do not edit, and do not commit.\n// Modal runs this as a long-lived process behind `@modal.web_server`, which\n// proxies HTTP and WebSocket traffic to the port it binds.\n// See @alexkroman1/aai-cli/start.\nimport { createProjectServer } from \"@alexkroman1/aai-cli/start\";\n\nconst server = await createProjectServer({ cwd: import.meta.dirname });\n\nawait server.listen(Number(process.env.PORT ?? 8000), \"0.0.0.0\");\n\n// app.py forwards the container's stop signal here and waits for this process.\n// The host stops this process on every scale-in and every redeploy; closing the\n// server ends live sessions instead of dropping their sockets.\nfor (const name of [\"SIGINT\", \"SIGTERM\"]) {\n try {\n process.once(name, () => {\n server.close().then(\n () => process.exit(0),\n () => process.exit(1),\n );\n });\n } catch {\n // No signal support on this host \u2014 nothing will ever arrive to drain on.\n }\n}\n";
69
+ export declare const MODAL_ENTRY_SOURCE: string;
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { plural } from "@alexkroman1/aai/utils";
3
+ import { TELEPHONY_CARRIERS } from "@alexkroman1/aai/internal";
4
+ import { CARRIER_PARAM, TELEPHONY_PATH, requiredProviderEnvVars } from "@alexkroman1/aai-runtime";
5
+ //#region src/_preflight.ts
6
+ /**
7
+ * Every env var name the agent needs to start: provider credentials derived
8
+ * from the stt/llm/tts/s2s descriptors (the same registry-backed derivation the
9
+ * runtime resolves keys with), plus the agent's own declared `requiredEnv` — an
10
+ * `agent()` field for custom keys tools read from `ctx.env`, which no static
11
+ * derivation can see.
12
+ *
13
+ * **Named on its own because the CLI has TWO deploy paths and only one of them
14
+ * used to ask.** `missingDeployEnv` (`build.ts`, the `--target` hosts) derived
15
+ * its list from `.env.example` alone, so an agent declaring
16
+ * `requiredEnv: ["ORDERS_API_KEY"]` and no example entry got neither a warning
17
+ * nor an `env add` step for it — while the managed path below saw both sources.
18
+ * One derivation, two callers; each applies its own "what counts as supplied".
19
+ */
20
+ function requiredEnvNames(config) {
21
+ return [.../* @__PURE__ */ new Set([...requiredProviderEnvVars(config), ...config.requiredEnv ?? []])];
22
+ }
23
+ /**
24
+ * Env var names the agent needs that the env being uploaded doesn't supply.
25
+ * Empty values count as missing — an empty credential authenticates nothing.
26
+ */
27
+ function missingCredentials(config, env) {
28
+ return requiredEnvNames(config).filter((name) => !env[name]);
29
+ }
30
+ /** One line naming the missing keys and what to do about them. */
31
+ function missingCredentialMessage(missing) {
32
+ 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).`;
33
+ }
34
+ /**
35
+ * The webhook-signing secret each carrier's requests are verified with —
36
+ * `phone-signature.ts`'s `TWILIO_AUTH_TOKEN_SECRET` / `TELNYX_PUBLIC_KEY_SECRET`
37
+ * from the reading end.
38
+ *
39
+ * Copied rather than imported: those constants live in `aai-server`, which the
40
+ * CLI may never import (see "Dependency flow" in `AGENTS.md`). `satisfies` is
41
+ * what keeps the copy total — a carrier added to `TELEPHONY_CARRIERS` with no
42
+ * secret named here fails this package's build rather than deploying a phone
43
+ * number nothing warns about.
44
+ */
45
+ const CARRIER_SIGNING_SECRETS = {
46
+ twilio: "TWILIO_AUTH_TOKEN",
47
+ telnyx: "TELNYX_PUBLIC_KEY"
48
+ };
49
+ /**
50
+ * The carriers a declaration admits, in `TELEPHONY_CARRIERS` order.
51
+ *
52
+ * The same resolution the runtime's `enabledCarriers` performs — `false`, `[]`
53
+ * and an absent field all mean the route is not served, `true` means every
54
+ * carrier this build ships a codec for, and a name this build does not know is
55
+ * DROPPED. It is re-derived here only because that function is `@internal` to
56
+ * `aai-runtime` and reaches no published subpath; keep the two in step.
57
+ */
58
+ function declaredCarriers(config) {
59
+ const access = config.telephony;
60
+ if (access === void 0 || access === false) return [];
61
+ if (access === true) return [...TELEPHONY_CARRIERS];
62
+ const asked = new Set(access);
63
+ return TELEPHONY_CARRIERS.filter((name) => asked.has(name));
64
+ }
65
+ /**
66
+ * Declared carriers whose signing secret the env being uploaded doesn't
67
+ * supply — the phone half of {@link missingCredentials}, and a separate
68
+ * function because the failure is a separate one.
69
+ *
70
+ * A missing provider key stops the agent starting; a missing signing secret
71
+ * lets it start and serve a phone number with **verification off**. Signature
72
+ * checking is enabled BY PRESENCE (`phone-signature.ts`), so the absence is
73
+ * silent at every layer: the deploy succeeds, the call connects, and nothing
74
+ * anywhere says the webhook is unauthenticated. That is the one thing about a
75
+ * declared carrier the CLI knows and the platform cannot — the platform stores
76
+ * no agent config — so it is said here or nowhere.
77
+ *
78
+ * Empty values count as missing for the reason they do above, and for one more:
79
+ * `verifyPhoneWebhook` reads the stored value, and a blank secret is a check
80
+ * that cannot pass rather than one that is off.
81
+ */
82
+ function missingTelephonySecrets(config, env) {
83
+ return declaredCarriers(config).map((carrier) => ({
84
+ carrier,
85
+ secret: CARRIER_SIGNING_SECRETS[carrier]
86
+ })).filter(({ secret }) => !env[secret]);
87
+ }
88
+ /** One line per carrier whose signing secret is absent. */
89
+ function missingTelephonySecretWarnings(missing) {
90
+ return missing.map(({ carrier, secret }) => `telephony declares ${carrier} but ${secret} is not set — the ${carrier} webhook will be served with signature verification OFF, so anyone who knows the URL can start a call. Declare ${secret} in .env and redeploy (already set on the platform with \`aai secret put\`? then this is already handled).`);
91
+ }
92
+ /**
93
+ * The webhook URL to paste into each declared carrier's phone-number
94
+ * configuration, `?carrier=` already filled in.
95
+ *
96
+ * Printed because both halves are things a user is otherwise asked to
97
+ * reconstruct by hand, and getting either wrong produces a failure that names
98
+ * neither: the platform's phone route defaults `carrier` to `"twilio"` against
99
+ * a hardcoded set and never consults the agent's declaration, so a Telnyx
100
+ * number reached without the query parameter is verified against Twilio's
101
+ * scheme and answers `403 Invalid webhook signature`. The parameter cannot be
102
+ * inferred server-side — `BundleStore` deliberately holds no agent config — and
103
+ * it does not have to be, because the declaration is in hand right here.
104
+ *
105
+ * The path and the parameter name come from `aai-runtime`'s own constants
106
+ * rather than from string literals, so a route rename cannot leave this
107
+ * printing a URL that 404s.
108
+ */
109
+ function telephonyWebhooks(config, agentUrl) {
110
+ return declaredCarriers(config).map((carrier) => ({
111
+ carrier,
112
+ url: `${agentUrl}${TELEPHONY_PATH}?${CARRIER_PARAM}=${carrier}`
113
+ }));
114
+ }
115
+ //#endregion
116
+ export { CARRIER_SIGNING_SECRETS, declaredCarriers, missingCredentialMessage, missingCredentials, missingTelephonySecretWarnings, missingTelephonySecrets, requiredEnvNames, telephonyWebhooks };