@alexkroman1/aai-cli 6.11.0 → 7.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 (162) hide show
  1. package/dist/{_agent-DpH2pBJd.mjs → _agent-BTwZJu4P.mjs} +2 -2
  2. package/dist/{_bundler-C2BDwU7r.mjs → _bundler-B4RqNF5Z.mjs} +2 -2
  3. package/dist/_dev-env.d.ts +22 -2
  4. package/dist/{_dev-server-LLLWnFBs.mjs → _dev-server-CiKFH9qw.mjs} +38 -47
  5. package/dist/_dev-server.d.ts +0 -17
  6. package/dist/{_init-C57bWAQ8.mjs → _init-CE4HKdgV.mjs} +3 -2
  7. package/dist/{_preflight-BtfaYtbE.mjs → _preflight-Co1G9Jww.mjs} +1 -1
  8. package/dist/_preflight.d.ts +1 -1
  9. package/dist/{_slug-api-BxrsJXVI.mjs → _slug-api-nRFaBEPJ.mjs} +2 -2
  10. package/dist/{_studio-U3jhKlA3.mjs → _studio-DR5yzZ1T.mjs} +2 -1
  11. package/dist/{_templates-Dxb_P2Wz.mjs → _templates-FI3xPEMj.mjs} +1 -1
  12. package/dist/_workflow-scan.d.ts +108 -0
  13. package/dist/{build-Dfza2pRI.mjs → build-6jfaakgc.mjs} +5 -2
  14. package/dist/cli.mjs +30 -25
  15. package/dist/{client-bundler-BEIqgOtd.mjs → client-bundler-CWnG42cU.mjs} +2 -1
  16. package/dist/client-bundler.mjs +1 -1
  17. package/dist/{delete-vbpjGzqs.mjs → delete-Dl_LSfvI.mjs} +3 -3
  18. package/dist/{deploy-B8lubiRT.mjs → deploy-DvYeD8ia.mjs} +5 -5
  19. package/dist/{dev-Uq5ujP8a.mjs → dev-B59JIfWO.mjs} +1 -1
  20. package/dist/{eject-31gjtaHF.mjs → eject-C9WJyyr2.mjs} +1 -1
  21. package/dist/{init-l6xfU4xX.mjs → init-CpJVjEg0.mjs} +3 -3
  22. package/dist/{login-C71-qz8F.mjs → login-BBuM1sxH.mjs} +3 -4
  23. package/dist/{logs-BWVGSjLR.mjs → logs-9q-psa4q.mjs} +2 -2
  24. package/dist/project-config.mjs +1 -1
  25. package/dist/scaffold/CLAUDE.md +40 -19
  26. package/dist/scaffold/package.json +5 -3
  27. package/dist/scaffold/server.mjs +1 -1
  28. package/dist/{secret-BuMuFR4B.mjs → secret-CVvSLIDV.mjs} +2 -2
  29. package/dist/{storage-DzRZ-eCw.mjs → storage-BvUrnvM3.mjs} +2 -2
  30. package/dist/{studio-BCNUpDgP.mjs → studio--MUV0cid.mjs} +4 -4
  31. package/dist/templates/call-audit/agent.test.ts +57 -204
  32. package/dist/templates/call-audit/agent.ts +32 -19
  33. package/dist/templates/call-audit/client.tsx +17 -54
  34. package/dist/templates/call-audit/workflows/audit.ts +11 -18
  35. package/dist/templates/call-audit/workflows/ingest.ts +106 -114
  36. package/dist/templates/call-audit/workflows/media.ts +2 -12
  37. package/dist/templates/call-audit/workflows/summarize.ts +47 -52
  38. package/dist/templates/call-audit/workflows/sync-api.ts +7 -7
  39. package/dist/templates/dispatch-center/agent.test.ts +149 -25
  40. package/dist/templates/dispatch-center/client.tsx +239 -129
  41. package/dist/templates/dispatch-center/shared.ts +99 -1
  42. package/dist/templates/dispatch-center/system-prompt.md +3 -1
  43. package/dist/templates/dispatch-center/tools/incident_add_note.ts +16 -13
  44. package/dist/templates/dispatch-center/tools/incident_create.ts +19 -1
  45. package/dist/templates/dispatch-center/tools/incident_escalate.ts +68 -59
  46. package/dist/templates/dispatch-center/tools/incident_triage.ts +57 -43
  47. package/dist/templates/dispatch-center/tools/incident_update_status.ts +49 -40
  48. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +8 -2
  49. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +69 -52
  50. package/dist/templates/dispatch-center/tools/resources_update_status.ts +45 -41
  51. package/dist/templates/embedded-assets/agent.test.ts +17 -14
  52. package/dist/templates/health-assistant/agent.test.ts +22 -4
  53. package/dist/templates/infocom-adventure/agent.test.ts +4 -6
  54. package/dist/templates/infocom-adventure/client.tsx +246 -164
  55. package/dist/templates/link-digest/agent.test.ts +24 -19
  56. package/dist/templates/link-digest/client.tsx +47 -61
  57. package/dist/templates/link-digest/workflows/digest.ts +19 -31
  58. package/dist/templates/night-owl/agent.test.ts +70 -19
  59. package/dist/templates/night-owl/agent.ts +5 -0
  60. package/dist/templates/night-owl/client.tsx +56 -56
  61. package/dist/templates/night-owl/shared.ts +24 -0
  62. package/dist/templates/night-owl/tools/recommend.ts +18 -6
  63. package/dist/templates/pizza-ordering/agent.test.ts +27 -27
  64. package/dist/templates/pizza-ordering/client.tsx +9 -26
  65. package/dist/templates/plan-and-execute/agent.test.ts +99 -58
  66. package/dist/templates/plan-and-execute/agent.ts +1 -1
  67. package/dist/templates/plan-and-execute/client.tsx +12 -15
  68. package/dist/templates/plan-and-execute/shared.ts +71 -2
  69. package/dist/templates/plan-and-execute/tools/plan_status.ts +18 -6
  70. package/dist/templates/plan-and-execute/tools/revise_plan.ts +18 -10
  71. package/dist/templates/plan-and-execute/tools/start_plan.ts +13 -2
  72. package/dist/templates/plan-and-execute/tools/work_next_step.ts +70 -22
  73. package/dist/templates/podcast-digest/agent.test.ts +746 -0
  74. package/dist/templates/podcast-digest/agent.ts +139 -0
  75. package/dist/templates/podcast-digest/client.tsx +154 -0
  76. package/dist/templates/podcast-digest/workflows/digest.ts +411 -0
  77. package/dist/templates/podcast-digest/workflows/feeds.ts +507 -0
  78. package/dist/templates/podcast-digest/workflows/slack.ts +209 -0
  79. package/dist/templates/recap-workflow/agent.test.ts +97 -94
  80. package/dist/templates/recap-workflow/tools/recap_progress.ts +9 -12
  81. package/dist/templates/recap-workflow/tools/recap_status.ts +8 -9
  82. package/dist/templates/recap-workflow/tools/request_recap.ts +2 -1
  83. package/dist/templates/recap-workflow/workflows/recap.ts +36 -40
  84. package/dist/templates/redline/agent.test.ts +17 -15
  85. package/dist/templates/redline/client.tsx +12 -12
  86. package/dist/templates/redline/workflows/redline.ts +19 -31
  87. package/dist/templates/research-workflow/agent.test.ts +60 -59
  88. package/dist/templates/research-workflow/tools/research_progress.ts +9 -12
  89. package/dist/templates/research-workflow/tools/research_status.ts +9 -11
  90. package/dist/templates/research-workflow/workflows/research.ts +44 -61
  91. package/dist/templates/retail/agent.test.ts +26 -23
  92. package/dist/templates/retail/client.tsx +226 -117
  93. package/dist/templates/retail/registry.test.ts +38 -6
  94. package/dist/templates/retail/store.test.ts +82 -15
  95. package/dist/templates/retail/store.ts +174 -47
  96. package/dist/templates/retail/system-prompt.md +11 -2
  97. package/dist/templates/retail/tools/cancel_pending_order.ts +2 -2
  98. package/dist/templates/retail/tools/exchange_delivered_order_items.ts +2 -2
  99. package/dist/templates/retail/tools/find_user_id_by_email.ts +8 -5
  100. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +4 -5
  101. package/dist/templates/retail/tools/get_item_details.ts +3 -4
  102. package/dist/templates/retail/tools/get_order_details.ts +3 -4
  103. package/dist/templates/retail/tools/get_product_details.ts +3 -4
  104. package/dist/templates/retail/tools/get_user_details.ts +2 -2
  105. package/dist/templates/retail/tools/list_all_product_types.ts +5 -5
  106. package/dist/templates/retail/tools/modify_pending_order_address.ts +2 -2
  107. package/dist/templates/retail/tools/modify_pending_order_items.ts +2 -3
  108. package/dist/templates/retail/tools/modify_pending_order_payment.ts +2 -2
  109. package/dist/templates/retail/tools/modify_user_address.ts +2 -2
  110. package/dist/templates/retail/tools/return_delivered_order_items.ts +2 -2
  111. package/dist/templates/retail/tools/transfer_to_human_agents.ts +8 -4
  112. package/dist/templates/solo-rpg/agent.test.ts +227 -48
  113. package/dist/templates/solo-rpg/client.tsx +38 -37
  114. package/dist/templates/solo-rpg/shared.ts +145 -19
  115. package/dist/templates/solo-rpg/system-prompt.md +3 -2
  116. package/dist/templates/solo-rpg/tools/action_roll.ts +82 -63
  117. package/dist/templates/solo-rpg/tools/burn_momentum.ts +85 -50
  118. package/dist/templates/solo-rpg/tools/check_state.ts +24 -7
  119. package/dist/templates/solo-rpg/tools/load_game.ts +13 -1
  120. package/dist/templates/solo-rpg/tools/save_game.ts +16 -7
  121. package/dist/templates/solo-rpg/tools/setup_character.ts +22 -2
  122. package/dist/templates/solo-rpg/tools/update_state.ts +113 -100
  123. package/dist/templates/spoken-summary/agent.test.ts +68 -97
  124. package/dist/templates/spoken-summary/agent.ts +30 -17
  125. package/dist/templates/spoken-summary/client.tsx +10 -50
  126. package/dist/templates/spoken-summary/workflows/summarize.ts +17 -22
  127. package/dist/templates/spoken-summary/workflows/transcribe.ts +19 -26
  128. package/dist/templates/support-line/agent.test.ts +11 -16
  129. package/dist/templates/support-line/agent.ts +1 -1
  130. package/dist/templates/support-line/client.tsx +9 -9
  131. package/dist/templates/support-line/nodes.ts +100 -0
  132. package/dist/templates/support-line/procedure.ts +407 -0
  133. package/dist/templates/support-line/tools/answer_question.ts +17 -4
  134. package/dist/templates/transcription-workflow/agent.test.ts +94 -194
  135. package/dist/templates/transcription-workflow/agent.ts +1 -1
  136. package/dist/templates/transcription-workflow/client.tsx +17 -42
  137. package/dist/templates/transcription-workflow/workflows/batch.ts +19 -22
  138. package/dist/templates/transcription-workflow/workflows/normalize.ts +90 -186
  139. package/dist/templates/transcription-workflow/workflows/stitch.ts +0 -11
  140. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -5
  141. package/dist/templates/transcription-workflow/workflows/sync-api.ts +6 -6
  142. package/dist/templates/transcription-workflow/workflows/transcribe.ts +32 -26
  143. package/dist/templates/transcription-workflow/workflows/wav.ts +0 -31
  144. package/dist/templates/travel-concierge/agent.test.ts +64 -33
  145. package/dist/templates/travel-concierge/client.tsx +11 -23
  146. package/dist/templates/travel-concierge/routing.ts +34 -15
  147. package/dist/templates/travel-concierge/shared.ts +70 -3
  148. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -2
  149. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -2
  150. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -2
  151. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +2 -2
  152. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -2
  153. package/dist/{worker-bundler-CGD4r8Kc.mjs → worker-bundler-COxnqstQ.mjs} +221 -3
  154. package/dist/worker-bundler.mjs +1 -1
  155. package/dist/{workflow-CFpxOFfQ.mjs → workflow-D2AQf2Pl.mjs} +28 -1
  156. package/dist/workflow-bundler.d.ts +6 -1
  157. package/dist/workflow.d.ts +1 -1
  158. package/package.json +5 -4
  159. package/dist/templates/call-audit/workflows/temp-media.ts +0 -138
  160. package/dist/templates/support-line/graph.ts +0 -224
  161. package/dist/{_config-D_s09e7g.mjs → _config-CmJOFsAP.mjs} +1 -1
  162. /package/dist/templates/plan-and-execute/{graph.ts → procedure.ts} +0 -0
@@ -1,224 +0,0 @@
1
- /**
2
- * The corrective-RAG loop, node by node.
3
- *
4
- * This is the port of the self-RAG / CRAG graph (see `prompts.ts` for the
5
- * attribution). Their control flow is edges between nodes; here it is a `while`
6
- * loop in one tool body, and the node names survive in {@link AnswerTrace.steps}
7
- * so a run is still readable as the graph it came from:
8
- *
9
- * ```text
10
- * retrieve → grade_documents → decide_to_generate
11
- * ├─ no relevant docs → transform_query → retrieve
12
- * └─ generate → grade_generation_v_documents
13
- * ├─ not grounded → generate (once)
14
- * └─ grade_generation_v_question
15
- * ├─ not useful → transform_query
16
- * └─ done
17
- * ```
18
- *
19
- * **The budget is the mechanism, not the prompt.** A graph with a
20
- * `transform_query` edge can cycle, and their notebooks bound it with a recursion
21
- * limit that raises on hit. A caller is holding the line, so the bound here is
22
- * two attempts and one regeneration — {@link MAX_ATTEMPTS} — and running out is
23
- * an ANSWER (`exhausted`, the caller is offered a ticket) rather than an error.
24
- * An agent that cannot say "I don't have that documented" is the failure the
25
- * whole grading apparatus exists to prevent, so it has to be a reachable state.
26
- *
27
- * **Documents are graded CONCURRENTLY.** Their loop is sequential because a
28
- * notebook does not care; four serial grader calls is four round trips of dead
29
- * air on a phone. The grades are independent, so the fan-out is free.
30
- */
31
-
32
- import type { GenerateFn } from "@alexkroman1/aai";
33
- import {
34
- ANSWER_SYSTEM,
35
- ANSWERS_SYSTEM,
36
- binaryScore,
37
- DOC_GRADER_SYSTEM,
38
- GROUNDED_SYSTEM,
39
- REWRITE_SYSTEM,
40
- } from "./prompts.ts";
41
- import type { AnswerTrace, Doc, GradedDoc, TraceStep } from "./shared.ts";
42
- import { formatDoc, retrieve } from "./shared.ts";
43
-
44
- /** Retrieve-and-answer attempts, i.e. one query rewrite. */
45
- export const MAX_ATTEMPTS = 2;
46
- /** Regenerations after a "not grounded" verdict, within one attempt. */
47
- export const MAX_REGENERATIONS = 1;
48
-
49
- function step(trace: AnswerTrace, node: string, detail: string): void {
50
- const entry: TraceStep = { node, detail };
51
- trace.steps.push(entry);
52
- }
53
-
54
- /** `grade_documents` — one closed question per document, all at once. */
55
- async function gradeDocuments(
56
- generate: GenerateFn,
57
- question: string,
58
- docs: Doc[],
59
- ): Promise<GradedDoc[]> {
60
- return await Promise.all(
61
- docs.map(async (doc) => {
62
- const { object } = await generate({
63
- system: DOC_GRADER_SYSTEM,
64
- prompt: `Caller's question: ${question}\n\nDocument:\n${formatDoc(doc)}`,
65
- schema: binaryScore,
66
- });
67
- return {
68
- id: doc.id,
69
- title: doc.title,
70
- relevant: object.score === "yes",
71
- reason: object.reason,
72
- };
73
- }),
74
- );
75
- }
76
-
77
- /** `transform_query` — their question re-writer, aimed at a keyword index. */
78
- async function transformQuery(generate: GenerateFn, question: string): Promise<string> {
79
- const { text } = await generate({
80
- system: REWRITE_SYSTEM,
81
- prompt: `Caller's question: ${question}`,
82
- });
83
- const rewritten = text.trim().replace(/^["']|["']$/g, "");
84
- // A rewriter that returns nothing usable must not empty the query — that
85
- // would retrieve zero documents and read as "we have nothing on this".
86
- return rewritten.length > 0 ? rewritten : question;
87
- }
88
-
89
- /** `generate` — the answer, from the graded-relevant documents only. */
90
- async function generateAnswer(
91
- generate: GenerateFn,
92
- question: string,
93
- docs: Doc[],
94
- ): Promise<string> {
95
- const { text } = await generate({
96
- system: ANSWER_SYSTEM,
97
- prompt: `Documents:\n\n${docs.map(formatDoc).join("\n\n")}\n\nCaller's question: ${question}`,
98
- });
99
- return text.trim();
100
- }
101
-
102
- /** The two generation graders — same closed question, different subject. */
103
- async function grade(
104
- generate: GenerateFn,
105
- system: string,
106
- prompt: string,
107
- ): Promise<{ pass: boolean; reason: string }> {
108
- const { object } = await generate({ system, prompt, schema: binaryScore });
109
- return { pass: object.score === "yes", reason: object.reason };
110
- }
111
-
112
- /**
113
- * Run the graph for one caller question. Never throws for a bad ANSWER — only
114
- * for a broken model call, which is the tool's to report.
115
- */
116
- export async function runCorrectiveRag(
117
- generate: GenerateFn,
118
- question: string,
119
- ): Promise<AnswerTrace> {
120
- const trace: AnswerTrace = {
121
- question,
122
- query: question,
123
- rewrites: 0,
124
- steps: [],
125
- docs: [],
126
- answer: null,
127
- grounded: null,
128
- useful: null,
129
- exhausted: false,
130
- };
131
-
132
- for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
133
- const retrieved = retrieve(trace.query);
134
- step(trace, "retrieve", `${retrieved.length} document(s) for "${trace.query}"`);
135
-
136
- const graded = await gradeDocuments(
137
- generate,
138
- question,
139
- retrieved.map((one) => one.doc),
140
- );
141
- trace.docs = graded;
142
- const relevant = retrieved.filter((one) => graded.find((g) => g.id === one.doc.id)?.relevant);
143
- step(trace, "grade_documents", `${relevant.length} of ${graded.length} relevant`);
144
-
145
- // `decide_to_generate`: nothing relevant means the retrieval was wrong, not
146
- // that the answer is unknown — so rewrite and try once more before giving up.
147
- if (relevant.length === 0) {
148
- if (attempt < MAX_ATTEMPTS) {
149
- trace.query = await transformQuery(generate, question);
150
- trace.rewrites++;
151
- step(trace, "transform_query", `retrying as "${trace.query}"`);
152
- continue;
153
- }
154
- trace.exhausted = true;
155
- step(trace, "decide_to_generate", "no relevant documents, and no attempts left");
156
- return trace;
157
- }
158
-
159
- const docs = relevant.map((one) => one.doc);
160
- const facts = docs.map(formatDoc).join("\n\n");
161
- let answer = await generateAnswer(generate, question, docs);
162
- step(trace, "generate", `answered from ${docs.map((d) => d.id).join(", ")}`);
163
-
164
- // `grade_generation_v_documents`: is it grounded? A regeneration is worth
165
- // one shot — the same documents with the ungrounded attempt now visible.
166
- let grounded = await grade(
167
- generate,
168
- GROUNDED_SYSTEM,
169
- `Facts:\n\n${facts}\n\nAnswer: ${answer}`,
170
- );
171
- for (let redo = 0; !grounded.pass && redo < MAX_REGENERATIONS; redo++) {
172
- step(trace, "grade_generation_v_documents", `not grounded: ${grounded.reason}`);
173
- answer = await generateAnswer(generate, question, docs);
174
- step(trace, "generate", "regenerated");
175
- grounded = await grade(generate, GROUNDED_SYSTEM, `Facts:\n\n${facts}\n\nAnswer: ${answer}`);
176
- }
177
- trace.answer = answer;
178
- trace.grounded = grounded.pass;
179
- step(
180
- trace,
181
- "grade_generation_v_documents",
182
- grounded.pass ? "grounded" : `still not grounded: ${grounded.reason}`,
183
- );
184
- if (!grounded.pass) {
185
- // An ungrounded answer is never spoken. Two regenerations that both
186
- // invented something is a signal about the documents, not the phrasing.
187
- trace.answer = null;
188
- trace.exhausted = true;
189
- return trace;
190
- }
191
-
192
- // `grade_generation_v_question`: grounded is not the same as useful.
193
- const useful = await grade(
194
- generate,
195
- ANSWERS_SYSTEM,
196
- `Question: ${question}\n\nAnswer: ${answer}`,
197
- );
198
- trace.useful = useful.pass;
199
- step(
200
- trace,
201
- "grade_generation_v_question",
202
- useful.pass ? "useful" : `not useful: ${useful.reason}`,
203
- );
204
- if (useful.pass) return trace;
205
-
206
- if (attempt < MAX_ATTEMPTS) {
207
- trace.query = await transformQuery(generate, question);
208
- trace.rewrites++;
209
- step(trace, "transform_query", `retrying as "${trace.query}"`);
210
- trace.answer = null;
211
- trace.grounded = null;
212
- trace.useful = null;
213
- continue;
214
- }
215
- // Out of attempts holding an answer that is grounded but beside the point.
216
- // It is still the best thing we have, so it is returned WITH its verdict —
217
- // the tool tells the model to offer a ticket alongside it.
218
- trace.exhausted = true;
219
- return trace;
220
- }
221
-
222
- trace.exhausted = true;
223
- return trace;
224
- }
@@ -4,8 +4,8 @@ import { c as isEexist, l as readJson, o as errorMessage, p as writeJson } from
4
4
  import { mkdtempSync } from "node:fs";
5
5
  import path from "node:path";
6
6
  import fs from "node:fs/promises";
7
- import { tmpdir } from "node:os";
8
7
  import { sleep } from "@alexkroman1/aai/internal";
8
+ import { tmpdir } from "node:os";
9
9
  import envPaths from "env-paths";
10
10
  import { z } from "zod";
11
11
  //#region _config.ts