@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
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @alexkroman1/aai-cli
2
2
 
3
- The `aai` command — scaffold, run, test, and publish aai voice agents.
3
+ The `aai` command — scaffold, run, test, and publish voice agents built with
4
+ the AssemblyAI Agent SDK.
4
5
 
5
6
  ```sh
6
7
  npm i -g @alexkroman1/aai-cli
@@ -60,6 +60,90 @@ for (const name of ["SIGINT", "SIGTERM"]) {
60
60
  }
61
61
  `;
62
62
  //#endregion
63
+ //#region src/_target-entry.ts
64
+ /**
65
+ * The LONG-LIVED entry — one source, and every runtime that can run it.
66
+ *
67
+ * A leaf beside `_target-drain.ts` (the signal handler both long-lived entries
68
+ * carry), `_target-output.ts` (the directory they share) and
69
+ * `_target-bundle.ts` (the bundle every target's entry goes through): each is a
70
+ * thing more than one host needs and no host owns.
71
+ *
72
+ * ## Why the entry is shared, when it deliberately was not
73
+ *
74
+ * Both long-lived entries do the same four things — build the server, bind a
75
+ * port, bind it on `0.0.0.0`, drain on a signal — and the argument for keeping
76
+ * two copies was the port: `MODAL_ENTRY_SOURCE`'s own doc records it as "the
77
+ * two read the port from different runtimes, and a shared entry would be a
78
+ * template with a hole where that goes".
79
+ *
80
+ * That is true only if a runtime's env is read one runtime's way. It was: the
81
+ * Deno entry read `globalThis.Deno?.env.get("PORT")` and nothing else, and the
82
+ * Modal entry read `process.env.PORT` and nothing else — so each emitted
83
+ * artifact was pinned to its host by ONE expression, and running the Deno
84
+ * directory under `node` or `bun` bound the default port no matter what the
85
+ * host had set. Nobody decided that; it fell out of which global was in reach
86
+ * when each file was written.
87
+ *
88
+ * {@link RUNTIME_PORT_SOURCE} reads BOTH, so the artifact is portable and the
89
+ * hole in the template closes. What is left per host is a comment and a
90
+ * default, which is what {@link longLivedEntrySource} takes.
91
+ *
92
+ * ## Why portability is a property worth spending a module on
93
+ *
94
+ * A self-contained emit is a directory with no `node_modules`, no toolchain and
95
+ * one file to run — which is exactly what a container image carries, and the
96
+ * runtime in that image is the operator's choice, not ours. `deno`, `node` and
97
+ * `bun` all run this file; `_target-runtimes.scenario.test.ts` boots the emit
98
+ * under each of the three and dials a real session on it, because nothing else
99
+ * here can tell you that the same bundle serves on all three rather than only
100
+ * on the one host whose target emitted it.
101
+ */
102
+ /**
103
+ * The port expression every long-lived entry uses, reading whichever runtime
104
+ * it finds itself in.
105
+ *
106
+ * `globalThis.Deno?.env` rather than `Deno.env`, and the optional chain is
107
+ * load-bearing twice over: this file is bundled by a Node-side build and read
108
+ * by Node tooling (its own specs included), where a bare `Deno` is a
109
+ * `ReferenceError` — and under Node and Bun the chain is what falls through to
110
+ * `process.env` instead of throwing.
111
+ *
112
+ * `process.env` second rather than first, because Deno's `process` shim reads
113
+ * the same variables and asking Deno for them Deno's way is what keeps the
114
+ * Deno arm honest — a host that grants no env permission fails on the first
115
+ * read either way.
116
+ *
117
+ * `process` itself needs no guard and deliberately gets none: it is a global in
118
+ * all three runtimes, which is what lets {@link TARGET_DRAIN_SOURCE} be the
119
+ * identical text in every entry rather than a template with a hole in it.
120
+ */
121
+ const RUNTIME_PORT_SOURCE = "globalThis.Deno?.env.get(\"PORT\") ?? process.env.PORT";
122
+ /**
123
+ * The entry a long-lived host runs, bundled into that target's entry file.
124
+ *
125
+ * `0.0.0.0`, not `AgentServer.listen`'s loopback default: every host here
126
+ * reaches the process from outside it, so a loopback bind answers nothing while
127
+ * looking healthy.
128
+ *
129
+ * `import.meta.dirname` rather than `process.cwd()`: the artifacts are copied
130
+ * in BESIDE this file (see `_target-output.ts`) and the working directory
131
+ * belongs to the platform.
132
+ */
133
+ function longLivedEntrySource(entry) {
134
+ const note = entry.hostNote.map((line) => `// ${line}\n`).join("");
135
+ const drainNote = entry.drainNote === void 0 ? "" : `// ${entry.drainNote}\n`;
136
+ return `// Generated by \`aai build --target ${entry.target}\` — do not edit, and do not commit.
137
+ ${note}// See @alexkroman1/aai-cli/start.
138
+ import { createProjectServer } from "@alexkroman1/aai-cli/start";
139
+
140
+ const server = await createProjectServer({ cwd: import.meta.dirname });
141
+
142
+ await server.listen(Number(${RUNTIME_PORT_SOURCE} ?? ${entry.defaultPort}), "0.0.0.0");
143
+
144
+ ${drainNote}${TARGET_DRAIN_SOURCE}`;
145
+ }
146
+ //#endregion
63
147
  //#region src/_deno-target.ts
64
148
  /**
65
149
  * The **Deno Deploy** target — a self-contained directory under `.aai/deno/`.
@@ -69,7 +153,7 @@ for (const name of ["SIGINT", "SIGTERM"]) {
69
153
  * it goes and what goes in it.
70
154
  *
71
155
  * Deno and Modal are the two LONG-LIVED targets: each entry binds a port and
72
- * each drains on a signal ({@link TARGET_DRAIN_SOURCE}), which is what makes
156
+ * each drains on a signal (`TARGET_DRAIN_SOURCE`), which is what makes
73
157
  * them the pair that also shares `_target-output.ts`.
74
158
  */
75
159
  /**
@@ -87,6 +171,14 @@ const DENO_ENTRY_FILE = "server.mjs";
87
171
  /** Deno's own project file inside {@link DENO_OUTPUT_DIR}. */
88
172
  const DENO_CONFIG_FILE = "deno.json";
89
173
  /**
174
+ * The port the entry binds when the host set no `PORT`.
175
+ *
176
+ * Deploy sets one, so this is what a bare `deno task start` on a laptop gets —
177
+ * the same number the Modal entry defaults to, because a reader who has run
178
+ * one emit should not have to look up the other.
179
+ */
180
+ const DENO_PORT = 8e3;
181
+ /**
90
182
  * The `deno.json` written beside the entry, so the output DESCRIBES how to run
91
183
  * itself.
92
184
  *
@@ -119,30 +211,18 @@ const DENO_CONFIG_SOURCE = `${JSON.stringify({ tasks: { start: `deno run -A ./${
119
211
  * `aai start` run. Verified against a live deployment with real speech: 74
120
212
  * audio frames back, transcript and reply intact.
121
213
  *
122
- * `0.0.0.0`, not the loopback default: the platform reaches this from outside
123
- * the process, so binding loopback answers nothing.
124
- *
125
- * `import.meta.dirname` rather than `process.cwd()` — the artifacts are copied
126
- * in BESIDE this file, and the working directory belongs to the platform.
214
+ * ## The body is SHARED, and only these three lines are Deno's
127
215
  *
128
- * `globalThis.Deno?.env` rather than `Deno.env`: this file is bundled by a
129
- * Node-side build and is read by Node tooling (its own spec included), where a
130
- * bare `Deno` is a `ReferenceError` at parse-adjacent evaluation time.
131
- *
132
- * `process` needs no such guard and deliberately gets none: it is a global in
133
- * Deno as well as in Node, so {@link TARGET_DRAIN_SOURCE} is the identical text
134
- * in both long-lived entries rather than a template with a hole in it.
216
+ * {@link longLivedEntrySource} carries the bind, the `0.0.0.0`, the
217
+ * `import.meta.dirname` and the drain — see that module for why the port read
218
+ * is no longer Deno's own, which is what left this artifact runnable only under
219
+ * Deno for as long as it read `globalThis.Deno.env` and nothing else.
135
220
  */
136
- const DENO_ENTRY_SOURCE = `// Generated by \`aai build --target deno\` — do not edit, and do not commit.
137
- // Deno Deploy runs this as a long-lived process and expects it to listen.
138
- // See @alexkroman1/aai-cli/start.
139
- import { createProjectServer } from "@alexkroman1/aai-cli/start";
140
-
141
- const server = await createProjectServer({ cwd: import.meta.dirname });
142
-
143
- await server.listen(Number(globalThis.Deno?.env.get("PORT") ?? 8000), "0.0.0.0");
144
-
145
- ${TARGET_DRAIN_SOURCE}`;
221
+ const DENO_ENTRY_SOURCE = longLivedEntrySource({
222
+ target: "deno",
223
+ hostNote: ["Deno Deploy runs this as a long-lived process and expects it to listen."],
224
+ defaultPort: DENO_PORT
225
+ });
146
226
  //#endregion
147
227
  //#region src/_modal-target.ts
148
228
  /**
@@ -191,14 +271,19 @@ const MODAL_PORT = 8e3;
191
271
  * `aai start` shape rather than the serverless one — `listen()`, `0.0.0.0`
192
272
  * (the proxy reaches this from outside the process), and artifacts resolved
193
273
  * from {@link MODAL_ENTRY_FILE}'s own directory rather than from a working
194
- * directory the platform owns. The entry is still NOT shared with
195
- * {@link DENO_ENTRY_SOURCE} — the two read the port from different runtimes,
196
- * and a shared entry would be a template with a hole where that goes — but the
197
- * DRAIN below is, which is the part neither host's contract varies in.
274
+ * directory the platform owns.
275
+ *
276
+ * ## The entry IS shared with Deno's now
277
+ *
278
+ * It was not, on the reading that the two read the port from different
279
+ * runtimes and a shared entry would be a template with a hole where that goes.
280
+ * `RUNTIME_PORT_SOURCE` reads both runtimes, so the hole closed — and the
281
+ * copy cost more than duplication: it is what made each artifact runnable only
282
+ * under the runtime whose host emitted it. See `_target-entry.ts`.
198
283
  *
199
284
  * ## The drain is SHARED, and Modal supplies its other half
200
285
  *
201
- * The `SIGINT`/`SIGTERM` body is {@link TARGET_DRAIN_SOURCE}, the same text the
286
+ * The `SIGINT`/`SIGTERM` body is `TARGET_DRAIN_SOURCE`, the same text the
202
287
  * Deno entry carries — it used to live here alone, on the reading that Modal
203
288
  * stops containers and Deno Deploy does not, which is not true of either.
204
289
  *
@@ -208,18 +293,287 @@ const MODAL_PORT = 8e3;
208
293
  * platform's own deploy learned that when orphaned guest sandboxes billed ~20
209
294
  * minutes each on every release (see `run_node` in `scripts/modal_image.py`).
210
295
  */
211
- const MODAL_ENTRY_SOURCE = `// Generated by \`aai build --target modal\` — do not edit, and do not commit.
212
- // Modal runs this as a long-lived process behind \`@modal.web_server\`, which
213
- // proxies HTTP and WebSocket traffic to the port it binds.
214
- // See @alexkroman1/aai-cli/start.
215
- import { createProjectServer } from "@alexkroman1/aai-cli/start";
296
+ const MODAL_ENTRY_SOURCE = longLivedEntrySource({
297
+ target: "modal",
298
+ hostNote: ["Modal runs this as a long-lived process behind `@modal.web_server`, which", "proxies HTTP and WebSocket traffic to the port it binds."],
299
+ defaultPort: MODAL_PORT,
300
+ drainNote: "app.py forwards the container's stop signal here and waits for this process."
301
+ });
302
+ //#endregion
303
+ //#region src/_modal-app.ts
304
+ /**
305
+ * The Modal app definition `aai build --target modal` emits — `app.py`.
306
+ *
307
+ * ## Why this target is a generated PYTHON file
308
+ *
309
+ * Every other target emits the host's expected entry shape and lets the host
310
+ * hold the rest: Vercel reads a routing table it already understands, Deno
311
+ * Deploy takes a directory and an entrypoint. Modal has no such descriptor.
312
+ * Its deploy unit is a Python module — `modal.App`, an image recipe, and a
313
+ * decorated function — and `modal deploy` runs that module rather than reading
314
+ * a manifest out of it. So the "preset" for Modal is the module itself, which
315
+ * is why this is the one target whose emit generates code in another language.
316
+ *
317
+ * ## The knobs are DEPLOY-TIME ENV, not edits to this file
318
+ *
319
+ * The awkward consequence is that Modal's policy — how many containers, how
320
+ * much CPU, which secret — lives in Python arguments rather than in a platform
321
+ * dashboard. A generated file carrying policy is a file people edit, and this
322
+ * one is overwritten by the next `aai build`, so "do not edit" would be a lie
323
+ * the first time somebody wanted a warm container.
324
+ *
325
+ * Four knobs are therefore read from the environment at deploy time
326
+ * ({@link MODAL_ENV_KNOBS}), which keeps the project committing nothing
327
+ * host-specific — the property `_build-target.ts` opens by defending:
328
+ *
329
+ * ```sh
330
+ * AAI_MODAL_MIN_CONTAINERS=1 modal deploy .aai/modal/app.py
331
+ * ```
332
+ *
333
+ * The rest — cpu, memory, timeout, concurrency — stays a documented constant
334
+ * in the emitted file. Those are the numbers a reader needs to SEE to trust
335
+ * the deployment, and regenerating restates the default, which is the same
336
+ * contract every other generated artifact here has.
337
+ */
338
+ /**
339
+ * The Node major the emitted image may not go below — the SDK's own `engines`
340
+ * floor.
341
+ *
342
+ * The tag otherwise tracks the Node running the build, so the bundle runs on
343
+ * the runtime it was bundled for. Modal pulls any tag that exists on Docker
344
+ * Hub, so there is nothing to clamp from ABOVE — unlike `vercelNodeRuntime`,
345
+ * whose platform publishes a fixed list. The floor is the half that matters:
346
+ * npm does not enforce `engines` by default, so a build on Node 22 would
347
+ * otherwise emit a `node:22-slim` image in which the SDK genuinely does not
348
+ * run, and the failure would arrive as a crash-looping container.
349
+ */
350
+ const MODAL_NODE_MAJOR_FLOOR = 24;
351
+ /**
352
+ * The Python `add_python` layers beside Node.
353
+ *
354
+ * Matches `scripts/modal_image.py`, which is the same arrangement one layer up:
355
+ * the container entrypoint is Modal's own Python runtime, and it spawns node.
356
+ */
357
+ const MODAL_ADD_PYTHON = "3.13";
358
+ /** What a name sanitizes to when nothing usable survives — see {@link modalAppName}. */
359
+ const MODAL_FALLBACK_APP_NAME = "aai-agent";
360
+ /**
361
+ * Modal caps a resource name at 64 characters. Truncated rather than refused:
362
+ * the name is cosmetic (it appears in the app's URL), and failing a build over
363
+ * a long agent name would be the target's first impression.
364
+ */
365
+ const MODAL_NAME_MAX = 64;
366
+ /**
367
+ * An agent name as a Modal app name.
368
+ *
369
+ * Modal accepts a narrow character set here and the name reaches a hostname —
370
+ * a deployed function is served at `<workspace>--<app>-<function>.modal.run` —
371
+ * so anything outside `[a-z0-9-]` becomes a dash rather than being passed
372
+ * through and rejected by the platform. Agent names are free text
373
+ * (`define({ name: "Retail Support Bot" })`), which is why this is a mapping
374
+ * and not a validation.
375
+ *
376
+ * Collapsed and trimmed, because `--` is what a hostname reader sees as the
377
+ * workspace separator, and a leading or trailing dash is not a legal label.
378
+ */
379
+ function modalAppName(agentName) {
380
+ const slug = agentName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, MODAL_NAME_MAX).replace(/-+$/g, "");
381
+ return slug === "" ? MODAL_FALLBACK_APP_NAME : slug;
382
+ }
383
+ /**
384
+ * The Modal Secret the deployment reads its env from.
385
+ *
386
+ * `-env` rather than the app name alone: the secret holds exactly what
387
+ * `.env.example` declares, and a name that says so makes
388
+ * `modal secret create <name> …` self-explaining. Derived rather than
389
+ * configured, so the emitted file and the command in its docstring cannot name
390
+ * two different secrets.
391
+ */
392
+ function modalSecretName(appName) {
393
+ return `${appName}-env`.slice(0, MODAL_NAME_MAX);
394
+ }
395
+ /** `node:<major>-slim` for the Node running this build, floored at the SDK's minimum. */
396
+ function modalNodeImageTag(version = process.versions.node) {
397
+ const major = Number.parseInt(version.split(".")[0] ?? "", 10);
398
+ return `node:${Number.isNaN(major) || major < MODAL_NODE_MAJOR_FLOOR ? MODAL_NODE_MAJOR_FLOOR : major}-slim`;
399
+ }
400
+ /**
401
+ * Render `app.py` for this agent.
402
+ *
403
+ * Every number the platform needs appears ONCE and is interpolated, so the
404
+ * emitted file cannot disagree with itself or with the entry beside it — see
405
+ * {@link MODAL_PORT} for the failure that motivates it.
406
+ */
407
+ function modalAppSource(options) {
408
+ const app = modalAppName(options.name);
409
+ const secret = modalSecretName(app);
410
+ const image = options.nodeImage ?? modalNodeImageTag();
411
+ return `# Generated by \`aai build --target modal\` — do not edit, and do not commit.
412
+ """Deploys this agent to Modal.
216
413
 
217
- const server = await createProjectServer({ cwd: import.meta.dirname });
414
+ modal secret create ${secret} ASSEMBLYAI_API_KEY=... # once
415
+ modal deploy .aai/modal/${MODAL_APP_FILE}
416
+
417
+ Everything this serves is in THIS directory. \`${MODAL_ENTRY_FILE}\` is a bundle
418
+ with no imports left to resolve, so the image installs nothing, carries no
419
+ lockfile and needs no node_modules.
420
+
421
+ Policy is read from the environment at DEPLOY time rather than edited here,
422
+ because \`aai build --target modal\` overwrites this file:
423
+
424
+ AAI_MODAL_APP app name (default: ${app})
425
+ AAI_MODAL_SECRET secret holding the agent env (default: ${secret})
426
+ AAI_MODAL_MIN_CONTAINERS warm floor (default: 0, i.e. scales to zero)
427
+ AAI_MODAL_MAX_CONTAINERS autoscaler ceiling (default: 10)
428
+ """
429
+
430
+ import atexit
431
+ import contextlib
432
+ import os
433
+ import signal
434
+ import subprocess
435
+ from pathlib import Path
436
+
437
+ import modal
438
+
439
+ # This file's OWN directory, never the shell's. \`modal deploy\` resolves a
440
+ # relative local path against the directory it was invoked FROM, so an
441
+ # \`add_local_dir(".")\` here would upload the project root or nothing at all,
442
+ # depending on where the deploy was run.
443
+ HERE = Path(__file__).parent
444
+
445
+ # Bound to \`@modal.web_server\` and baked into the image env from this one
446
+ # place. The proxy routes to the port it is told about, and a node process
447
+ # reading a different number listens where nothing is routed — a deployment
448
+ # that builds, starts, reports healthy and answers no request.
449
+ PORT = ${MODAL_PORT}
450
+
451
+ # The node server, spawned by \`server()\` below.
452
+ ENTRY = "${MODAL_ENTRY_FILE}"
453
+
454
+ APP_NAME = os.environ.get("AAI_MODAL_APP", "${app}")
455
+ SECRET_NAME = os.environ.get("AAI_MODAL_SECRET", "${secret}")
456
+ MIN_CONTAINERS = int(os.environ.get("AAI_MODAL_MIN_CONTAINERS", "0"))
457
+ MAX_CONTAINERS = int(os.environ.get("AAI_MODAL_MAX_CONTAINERS", "10"))
458
+
459
+ # How long a container stop waits for node to close its sessions before the
460
+ # force-kill. Modal's own SIGKILL backstop still bounds the real grace period,
461
+ # so this is headroom rather than a budget the shutdown spends.
462
+ NODE_STOP_TIMEOUT_SECS = 30
463
+
464
+ image = (
465
+ # \`add_python\` layers Modal's own Python beside Node: the container
466
+ # entrypoint is that Python runtime, and it spawns node. The Node major
467
+ # tracks the one this was BUILT with, so the bundle runs on the runtime it
468
+ # was bundled for.
469
+ modal.Image.from_registry("${image}", add_python="${MODAL_ADD_PYTHON}")
470
+ .env({"NODE_ENV": "production", "PORT": str(PORT)})
471
+ # \`copy=True\` puts these files in an image LAYER. The default mounts them
472
+ # at container start instead, which re-uploads the browser client on every
473
+ # cold start and makes the boot slower the larger the UI gets.
474
+ .add_local_dir(
475
+ HERE,
476
+ remote_path="/app",
477
+ copy=True,
478
+ ignore=["${MODAL_APP_FILE}", "__pycache__"],
479
+ )
480
+ )
218
481
 
219
- await server.listen(Number(process.env.PORT ?? ${MODAL_PORT}), "0.0.0.0");
482
+ app = modal.App(APP_NAME)
220
483
 
221
- // app.py forwards the container's stop signal here and waits for this process.
222
- ${TARGET_DRAIN_SOURCE}`;
484
+
485
+ def _run_node(entry: str, env: dict[str, str]) -> subprocess.Popen:
486
+ """Spawn the node server and hand container stop signals to it.
487
+
488
+ Modal stops a container by signalling THIS Python process, and a child
489
+ spawned with a bare Popen receives nothing of its own — so the node
490
+ server's SIGTERM handler, the thing that closes live voice sessions, would
491
+ never run on a scale-in or a redeploy. Every call in progress would just
492
+ lose its socket.
493
+
494
+ Two hooks, because neither alone is reliable: \`signal.signal\` only works on
495
+ the main thread and Modal may call this off it, while the atexit fallback
496
+ catches the runtime handling the signal itself and exiting normally. Both
497
+ funnel into one memoized stop(), and the node handler is idempotent, so
498
+ double delivery is harmless.
499
+ """
500
+ proc = subprocess.Popen(["node", entry], cwd="/app", env=env)
501
+ stopped = False
502
+
503
+ def stop() -> None:
504
+ nonlocal stopped
505
+ if stopped or proc.poll() is not None:
506
+ return
507
+ stopped = True
508
+ with contextlib.suppress(ProcessLookupError):
509
+ proc.send_signal(signal.SIGTERM)
510
+ with contextlib.suppress(subprocess.TimeoutExpired):
511
+ proc.wait(timeout=NODE_STOP_TIMEOUT_SECS)
512
+ if proc.poll() is None:
513
+ proc.kill()
514
+
515
+ def forward(signum: int) -> None:
516
+ previous = signal.getsignal(signum)
517
+
518
+ def handler(sig: int, frame: object) -> None:
519
+ stop()
520
+ if callable(previous):
521
+ previous(sig, frame)
522
+ elif previous == signal.SIG_DFL:
523
+ # Re-deliver with the default disposition so this runtime still
524
+ # dies the way the platform expects.
525
+ signal.signal(sig, signal.SIG_DFL)
526
+ os.kill(os.getpid(), sig)
527
+
528
+ signal.signal(signum, handler)
529
+
530
+ for signum in (signal.SIGTERM, signal.SIGINT):
531
+ with contextlib.suppress(ValueError): # not the main thread
532
+ forward(signum)
533
+
534
+ atexit.register(stop)
535
+ return proc
536
+
537
+
538
+ @app.function(
539
+ image=image,
540
+ # Values live in a Modal Secret; the \`.env.example\` beside this file
541
+ # DECLARES which names reach \`ctx.env\`. Deploy FAILS when the secret does
542
+ # not exist, which is the right time to hear about it — the alternative is
543
+ # a container that starts and has no provider credential.
544
+ secrets=[modal.Secret.from_name(SECRET_NAME)],
545
+ # An audio pipeline is not a burstable workload: STT framing, the LLM turn
546
+ # and TTS playback all run in this process.
547
+ cpu=1,
548
+ memory=1024,
549
+ min_containers=MIN_CONTAINERS,
550
+ max_containers=MAX_CONTAINERS,
551
+ # Hold a container after the last call rather than paying a cold start on
552
+ # the next one.
553
+ scaledown_window=300,
554
+ # Bounds ONE input, and a WebSocket is one input for as long as the call
555
+ # lasts — so this is the longest single call this deployment will carry.
556
+ timeout=3600,
557
+ )
558
+ # Without this a container serves ONE input at a time, and a voice call holds
559
+ # its input until the caller hangs up: the second caller would wait out the
560
+ # first, and every asset request for the browser client would queue behind
561
+ # whichever call is in progress. \`target_inputs\` is the scale-out set point,
562
+ # under the cap, so a container is joined by another before it saturates.
563
+ @modal.concurrent(max_inputs=50, target_inputs=25)
564
+ @modal.web_server(port=PORT, startup_timeout=180)
565
+ def server() -> None:
566
+ env = os.environ.copy()
567
+ # Modal points this at an in-container Unix socket serving its own Python
568
+ # task runtime. The \`modal\` JS SDK prefers that variable over the public
569
+ # endpoint, so anything in node that talks to Modal would dial a socket
570
+ # that does not answer it.
571
+ env.pop("MODAL_SERVER_URL", None)
572
+ # _run_node, not a bare Popen, so the container's stop signal reaches node
573
+ # and live sessions are closed rather than dropped.
574
+ _run_node(ENTRY, env)
575
+ `;
576
+ }
223
577
  //#endregion
224
578
  //#region src/_vercel-target.ts
225
579
  /**
@@ -516,13 +870,43 @@ const VERCEL_BUILD_CONFIG_SOURCE = `${JSON.stringify({
516
870
  * reads this one — so a fourth target is a fourth file plus two lines here.
517
871
  */
518
872
  /**
519
- * What {@link TargetOutput.secret} puts where a variable NAME goes.
873
+ * What a {@link DeployStep} puts where a variable NAME goes.
520
874
  *
521
875
  * Angle brackets rather than a `$NAME` or `%s`: the string is printed for a
522
876
  * human to adapt as often as it is substituted into, and both of the other two
523
877
  * are shell-significant enough to be mistaken for something to type literally.
524
878
  */
525
879
  const SECRET_NAME_PLACEHOLDER = "<NAME>";
880
+ /**
881
+ * The placeholders {@link resolveDeploySteps} FILLS, and the ones it leaves.
882
+ *
883
+ * The line between them is who KNOWS the value at build time, and it is worth
884
+ * stating because it is the same line `.env.example` draws: this build knows
885
+ * every declared variable name and the agent's own name, so leaving those as
886
+ * placeholders would be withholding something it could have printed. It knows
887
+ * nothing about the reader's account — an org, an app that may not exist yet —
888
+ * or about a secret's VALUE, which is the whole point of declarations shipping
889
+ * while values do not.
890
+ *
891
+ * So {@link SECRET_NAME_PLACEHOLDER} and {@link MODAL_SECRET_PLACEHOLDER} are
892
+ * substituted, and these three survive into the printed command as prompts for
893
+ * the reader to fill.
894
+ */
895
+ const ORG_PLACEHOLDER = "<ORG>";
896
+ /** @see ORG_PLACEHOLDER */
897
+ const APP_PLACEHOLDER = "<APP>";
898
+ /** @see ORG_PLACEHOLDER */
899
+ const SECRET_VALUE_PLACEHOLDER = "<value>";
900
+ /**
901
+ * Where Modal's derived secret name goes — see {@link modalSecretName}.
902
+ *
903
+ * Substituted rather than left for the reader, because `app.py` DERIVES that
904
+ * name from the agent's own and a reader who invents one gets a deploy that
905
+ * fails on `Secret.from_name`. The emitted file's docstring already prints the
906
+ * resolved name; this is the same string reaching the same reader one surface
907
+ * earlier.
908
+ */
909
+ const MODAL_SECRET_PLACEHOLDER = "<secret>";
526
910
  /** The targets `aai build --target` accepts. */
527
911
  const BUILD_TARGETS = [
528
912
  "node",
@@ -640,19 +1024,96 @@ const TARGET_OUTPUTS = {
640
1024
  node: { preview: "aai start" },
641
1025
  vercel: {
642
1026
  dir: VERCEL_OUTPUT_DIR,
643
- deploy: "vercel deploy --prebuilt",
644
- secret: `vercel env add ${SECRET_NAME_PLACEHOLDER} production`
1027
+ deploy: [
1028
+ {
1029
+ when: "build",
1030
+ run: "aai build --target vercel"
1031
+ },
1032
+ {
1033
+ when: "perSecret",
1034
+ run: `vercel env add ${SECRET_NAME_PLACEHOLDER} production`
1035
+ },
1036
+ {
1037
+ when: "each",
1038
+ run: "vercel deploy --prebuilt"
1039
+ }
1040
+ ]
645
1041
  },
646
1042
  deno: {
647
1043
  dir: DENO_OUTPUT_DIR,
648
1044
  preview: `cd ${DENO_OUTPUT_DIR} && deno task start`,
649
- deploy: `cd ${DENO_OUTPUT_DIR} && deno deploy`
1045
+ deploy: [
1046
+ {
1047
+ when: "build",
1048
+ run: "aai build --target deno"
1049
+ },
1050
+ {
1051
+ when: "once",
1052
+ run: `deno deploy create --source local --region us --runtime-mode dynamic --entrypoint ${DENO_ENTRY_FILE} --do-not-use-detected-build-config --org ${ORG_PLACEHOLDER} --app ${APP_PLACEHOLDER}`
1053
+ },
1054
+ {
1055
+ when: "perSecret",
1056
+ run: `deno deploy env add ${SECRET_NAME_PLACEHOLDER} ${SECRET_VALUE_PLACEHOLDER} --org ${ORG_PLACEHOLDER} --app ${APP_PLACEHOLDER}`
1057
+ },
1058
+ {
1059
+ when: "each",
1060
+ run: `cd ${DENO_OUTPUT_DIR} && deno deploy --prod --org ${ORG_PLACEHOLDER} --app ${APP_PLACEHOLDER}`
1061
+ }
1062
+ ]
650
1063
  },
651
1064
  modal: {
652
1065
  dir: MODAL_OUTPUT_DIR,
653
1066
  preview: `modal serve ${path.join(MODAL_OUTPUT_DIR, MODAL_APP_FILE)}`,
654
- deploy: `modal deploy ${path.join(MODAL_OUTPUT_DIR, MODAL_APP_FILE)}`
1067
+ deploy: [
1068
+ {
1069
+ when: "build",
1070
+ run: "aai build --target modal"
1071
+ },
1072
+ {
1073
+ when: "perSecret",
1074
+ run: `modal secret create ${MODAL_SECRET_PLACEHOLDER} ${SECRET_NAME_PLACEHOLDER}=${SECRET_VALUE_PLACEHOLDER}`
1075
+ },
1076
+ {
1077
+ when: "each",
1078
+ run: `modal deploy ${path.join(MODAL_OUTPUT_DIR, MODAL_APP_FILE)}`
1079
+ }
1080
+ ]
655
1081
  }
656
1082
  };
1083
+ /**
1084
+ * The sequence a reader should actually run: placeholders this build can fill
1085
+ * FILLED, and the `perSecret` step expanded once per variable that needs one.
1086
+ *
1087
+ * Resolved here rather than at the log site so the `--json` result and the
1088
+ * printed lines cannot disagree — the defect that produced this whole shape was
1089
+ * a deploy instruction that lived as a string at one call site and was wrong.
1090
+ *
1091
+ * With nothing missing, the `perSecret` step is kept ONCE in placeholder form
1092
+ * rather than dropped, and that is deliberate: `missingDeployEnv` reads the
1093
+ * BUILD's environment, which says nothing about what the host has (its own doc
1094
+ * makes this point), so an empty `missing` means "your shell had these", not
1095
+ * "the platform does". Dropping the step there would quietly promise a host is
1096
+ * configured when nobody has configured it.
1097
+ */
1098
+ function resolveDeploySteps(target, options) {
1099
+ const steps = TARGET_OUTPUTS[target].deploy;
1100
+ if (steps === void 0) return [];
1101
+ const secret = modalSecretName(modalAppName(options.agentName));
1102
+ const fill = (run) => run.replaceAll(MODAL_SECRET_PLACEHOLDER, secret);
1103
+ return steps.flatMap((step) => {
1104
+ if (step.when !== "perSecret") return [{
1105
+ ...step,
1106
+ run: fill(step.run)
1107
+ }];
1108
+ if (options.missingEnv.length === 0) return [{
1109
+ ...step,
1110
+ run: fill(step.run)
1111
+ }];
1112
+ return options.missingEnv.map((name) => ({
1113
+ when: step.when,
1114
+ run: fill(step.run).replaceAll(SECRET_NAME_PLACEHOLDER, name)
1115
+ }));
1116
+ });
1117
+ }
657
1118
  //#endregion
658
- export { DENO_CONFIG_SOURCE as _, VERCEL_BUILD_CONFIG_SOURCE as a, DENO_OUTPUT_DIR as b, VERCEL_OUTPUT_DIR as c, MODAL_APP_FILE as d, MODAL_ENTRY_FILE as f, DENO_CONFIG_FILE as g, MODAL_PORT as h, resolveBuildTarget as i, VERCEL_STATIC_DIR as l, MODAL_OUTPUT_DIR as m, SECRET_NAME_PLACEHOLDER as n, VERCEL_ENTRY_SOURCE as o, MODAL_ENTRY_SOURCE as p, TARGET_OUTPUTS as r, VERCEL_FUNCTION_DIR as s, BUILD_TARGETS as t, vercelFunctionConfigSource as u, DENO_ENTRY_FILE as v, DENO_ENTRY_SOURCE as y };
1119
+ export { DENO_CONFIG_FILE as _, resolveDeploySteps as a, DENO_ENTRY_SOURCE as b, VERCEL_FUNCTION_DIR as c, vercelFunctionConfigSource as d, modalAppSource as f, MODAL_OUTPUT_DIR as g, MODAL_ENTRY_SOURCE as h, resolveBuildTarget as i, VERCEL_OUTPUT_DIR as l, MODAL_ENTRY_FILE as m, SECRET_NAME_PLACEHOLDER as n, VERCEL_BUILD_CONFIG_SOURCE as o, MODAL_APP_FILE as p, TARGET_OUTPUTS as r, VERCEL_ENTRY_SOURCE as s, BUILD_TARGETS as t, VERCEL_STATIC_DIR as u, DENO_CONFIG_SOURCE as v, DENO_OUTPUT_DIR as x, DENO_ENTRY_FILE as y };