@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.
- package/README.md +2 -1
- package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
- package/dist/_build-target.d.ts +98 -19
- package/dist/_console-audio.d.ts +17 -0
- package/dist/_console-session.d.ts +70 -0
- package/dist/_deno-target.d.ts +15 -14
- package/dist/_dev-env.d.ts +19 -13
- package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-Dtp4aAlo.mjs} +26 -18
- package/dist/_dev-server.d.ts +5 -3
- package/dist/_init.d.ts +39 -0
- package/dist/_modal-target.d.ts +11 -6
- package/dist/_preflight-CnW9QiE7.mjs +116 -0
- package/dist/_preflight.d.ts +110 -5
- package/dist/_target-bundle.d.ts +112 -0
- package/dist/_target-entry.d.ts +81 -0
- package/dist/_templates-DXadVNsL.mjs +135 -0
- package/dist/_templates.d.ts +11 -34
- package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
- package/dist/_vitest-runner.d.ts +35 -23
- package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
- package/dist/build.d.ts +34 -4
- package/dist/cli.mjs +40 -16
- package/dist/console-BsyE3DyB.mjs +422 -0
- package/dist/console.d.ts +37 -0
- package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
- package/dist/deploy.d.ts +9 -0
- package/dist/{dev-Du8pCWFq.mjs → dev-BGWU2zPP.mjs} +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
- package/dist/init-CbOhyNYe.mjs +559 -0
- package/dist/init.d.ts +43 -3
- package/dist/scaffold/CLAUDE.md +161 -166
- package/dist/scaffold/package.json +6 -6
- package/dist/scaffold/vite.config.ts +29 -1
- package/dist/start.d.ts +3 -3
- package/dist/{studio-It7SRfUN.mjs → studio-BRJsw7lr.mjs} +19 -9
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
- package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
- package/dist/templates/applicant-screening-agent/agent.ts +28 -0
- package/dist/templates/applicant-screening-agent/crews.ts +4 -4
- package/dist/templates/applicant-screening-agent/shared.ts +11 -11
- package/dist/templates/call-audit-workflow/agent.ts +2 -0
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
- package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
- package/dist/templates/code-interpreter-agent/agent.ts +1 -0
- package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
- package/dist/templates/coding-agent/agent.test.ts +109 -0
- package/dist/templates/coding-agent/agent.ts +45 -0
- package/dist/templates/coding-agent/chat.ts +63 -0
- package/dist/templates/coding-agent/shared.ts +46 -0
- package/dist/templates/coding-agent/system-prompt.md +32 -0
- package/dist/templates/coding-agent/tools/bash.ts +6 -0
- package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
- package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
- package/dist/templates/coding-agent/tools/glob.ts +6 -0
- package/dist/templates/coding-agent/tools/grep.ts +6 -0
- package/dist/templates/coding-agent/tools/list_files.ts +6 -0
- package/dist/templates/coding-agent/tools/read_file.ts +6 -0
- package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
- package/dist/templates/coding-agent/tools/write_file.ts +6 -0
- package/dist/templates/custom-pipeline-agent/agent.ts +3 -2
- package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
- package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
- package/dist/templates/document-redline-workflow/agent.ts +2 -0
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
- package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
- package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
- package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +9 -2
- package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
- package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
- package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
- package/dist/templates/executive-inbox-agent/agent.ts +1 -0
- package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
- package/dist/templates/executive-inbox-agent/meeting.ts +3 -3
- package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
- package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
- package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
- package/dist/templates/front-desk-agent/agent.test.ts +150 -0
- package/dist/templates/front-desk-agent/agent.ts +22 -0
- package/dist/templates/front-desk-agent/shared.ts +234 -0
- package/dist/templates/front-desk-agent/system-prompt.md +13 -0
- package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
- package/dist/templates/hotel-reception-agent/agent.test.ts +3 -3
- package/dist/templates/hotel-reception-agent/agent.ts +6 -3
- package/dist/templates/hotel-reception-agent/client.tsx +14 -2
- package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +3 -3
- package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
- package/dist/templates/hotel-reception-agent/events.ts +2 -1
- package/dist/templates/hotel-reception-agent/session.ts +56 -0
- package/dist/templates/hotel-reception-agent/shared.ts +20 -21
- package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
- package/dist/templates/link-digest-workflow/agent.ts +5 -0
- package/dist/templates/medication-safety-agent/agent.test.ts +57 -4
- package/dist/templates/medication-safety-agent/agent.ts +48 -1
- package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
- package/dist/templates/meeting-recap-agent/agent.ts +4 -0
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
- package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
- package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
- package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
- package/dist/templates/push-to-talk-agent/agent.ts +22 -0
- package/dist/templates/push-to-talk-agent/client.tsx +124 -0
- package/dist/templates/push-to-talk-agent/shared.ts +34 -0
- package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +91 -3
- package/dist/templates/quickstart-agent/agent.test.ts +22 -0
- package/dist/templates/quickstart-agent/agent.ts +18 -2
- package/dist/templates/quickstart-agent/system-prompt.md +8 -0
- package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
- package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
- package/dist/templates/research-handoff-agent/agent.ts +4 -0
- package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
- package/dist/templates/research-planner-agent/agent.test.ts +26 -16
- package/dist/templates/research-planner-agent/agent.ts +3 -0
- package/dist/templates/research-planner-agent/system-prompt.md +1 -1
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
- package/dist/templates/retail-orders-agent/agent.ts +32 -3
- package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
- package/dist/templates/retail-orders-agent/resolve.ts +18 -3
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +124 -5
- package/dist/templates/roadside-assistance-agent/agent.test.ts +39 -7
- package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
- package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
- package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
- package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
- package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
- package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
- package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
- package/dist/templates/technical-support-agent/agent.test.ts +29 -23
- package/dist/templates/technical-support-agent/agent.ts +5 -1
- package/dist/templates/technical-support-agent/knowledge.ts +165 -0
- package/dist/templates/technical-support-agent/nodes.ts +3 -2
- package/dist/templates/technical-support-agent/procedure.ts +7 -6
- package/dist/templates/technical-support-agent/shared.ts +10 -146
- package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
- package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
- package/dist/templates/text-adventure-agent/agent.ts +30 -1
- package/dist/templates/text-adventure-agent/shared.ts +37 -0
- package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
- package/dist/templates/topic-briefing-agent/agent.test.ts +61 -36
- package/dist/templates/topic-briefing-agent/agent.ts +4 -1
- package/dist/templates/topic-briefing-agent/shared.ts +19 -18
- package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
- package/dist/templates/transcription-workflow/agent.ts +3 -0
- package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
- package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
- package/dist/templates/travel-concierge-agent/agent.ts +4 -0
- package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
- package/dist/templates/web-research-agent/agent.test.ts +16 -0
- package/dist/templates/web-research-agent/agent.ts +30 -0
- package/dist/templates/web-research-agent/system-prompt.md +8 -2
- package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
- package/dist/templates/word-game-agent/agent.test.ts +3 -1
- package/dist/templates/word-game-agent/agent.ts +20 -0
- package/dist/test-CjKPQ9_B.mjs +102 -0
- package/dist/test.d.ts +37 -12
- package/package.json +5 -5
- package/dist/_init-Bp1CjRrU.mjs +0 -199
- package/dist/_preflight-CcAR577V.mjs +0 -46
- package/dist/_templates-CuP74F8D.mjs +0 -291
- package/dist/init-CY4NAXAA.mjs +0 -183
- package/dist/test-PHHv0Vj6.mjs +0 -83
package/dist/build.d.ts
CHANGED
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*
|
|
12
12
|
* `--target` decides what else it emits — see `_build-target.ts`.
|
|
13
13
|
*/
|
|
14
|
-
import { type BuildTarget } from "./_build-target.ts";
|
|
14
|
+
import { type BuildTarget, type DeployStep } from "./_build-target.ts";
|
|
15
15
|
import { type CommandResult } from "./_output.ts";
|
|
16
|
+
import type { PreflightConfig } from "./_preflight.ts";
|
|
16
17
|
/**
|
|
17
18
|
* Where the built worker lands, relative to the project root — under `.aai/`,
|
|
18
19
|
* beside the built client, so one gitignore rule covers every build output.
|
|
@@ -43,9 +44,13 @@ type BuildData = {
|
|
|
43
44
|
* above is: `log` is silenced under `--json`, so a CI job that builds and
|
|
44
45
|
* then deploys could read neither the directory it should upload nor the
|
|
45
46
|
* command that uploads it, and had to restate both from this file.
|
|
47
|
+
*
|
|
48
|
+
* `deploy` is the RESOLVED sequence — see {@link resolveDeploySteps} — so a
|
|
49
|
+
* CI job can execute it in order rather than re-encoding each host's
|
|
50
|
+
* prerequisites. Empty for a target that deploys nowhere.
|
|
46
51
|
*/
|
|
47
52
|
outputDir: string | undefined;
|
|
48
|
-
deploy:
|
|
53
|
+
deploy: DeployStep[];
|
|
49
54
|
/**
|
|
50
55
|
* Variables the deployment DECLARES and this build's host had no value for —
|
|
51
56
|
* see {@link missingDeployEnv}. Empty for a target that deploys nowhere.
|
|
@@ -70,6 +75,27 @@ export declare function executeBuild(opts: {
|
|
|
70
75
|
* Which variables the DEPLOYMENT declares that this build's host has no value
|
|
71
76
|
* for — the check behind the warning `aai build` prints for a host target.
|
|
72
77
|
*
|
|
78
|
+
* ## Where the DECLARATIONS come from
|
|
79
|
+
*
|
|
80
|
+
* Two sources, and for a long time only the first: `.env.example`, the one
|
|
81
|
+
* dotenv file that ships, plus — when the caller has the built bundle's
|
|
82
|
+
* normalized config — {@link requiredEnvNames}, i.e. the provider credentials
|
|
83
|
+
* the stt/llm/tts/s2s descriptors imply and the agent's own `requiredEnv`.
|
|
84
|
+
*
|
|
85
|
+
* The example file alone was the wrong half of a pair. `anywhere.md` told
|
|
86
|
+
* authors to "list what your tools read in `requiredEnv`" and promised the
|
|
87
|
+
* build would warn by name about anything the deployment was missing, which was
|
|
88
|
+
* true of the MANAGED path (`_preflight.ts`, which has always derived both) and
|
|
89
|
+
* false here — so an agent declaring `requiredEnv: ["ORDERS_API_KEY"]` and no
|
|
90
|
+
* matching example entry got neither the warning nor the `env add` step the
|
|
91
|
+
* `perSecret` sequence expands from this same list. Both paths now read one
|
|
92
|
+
* derivation.
|
|
93
|
+
*
|
|
94
|
+
* `.env.example` stays a source rather than becoming redundant: it is where a
|
|
95
|
+
* variable that nothing static can see gets declared — one a tool reads
|
|
96
|
+
* straight off `process.env`, or a host setting like `PORT` — and it is what a
|
|
97
|
+
* user editing a deployment's configuration actually reads.
|
|
98
|
+
*
|
|
73
99
|
* ## Why the host environment and not `resolveServerEnv`
|
|
74
100
|
*
|
|
75
101
|
* The obvious implementation resolves {@link DEPLOY_ENV_FILES} the way the
|
|
@@ -102,8 +128,12 @@ export declare function executeBuild(opts: {
|
|
|
102
128
|
*
|
|
103
129
|
* @param env - Where values are read from. Defaults to the build's own
|
|
104
130
|
* environment; a parameter so a spec need not mutate `process.env`.
|
|
131
|
+
* @param config - The built bundle's `__aaiConfig`, when the caller has it.
|
|
132
|
+
* Omitted, only `.env.example` is read — which is what a spec asserting the
|
|
133
|
+
* file-declaration half wants, and what an older bundle carrying no such
|
|
134
|
+
* export leaves the caller with.
|
|
105
135
|
*/
|
|
106
|
-
export declare function missingDeployEnv(cwd: string, target: BuildTarget, env?: Record<string, string | undefined
|
|
136
|
+
export declare function missingDeployEnv(cwd: string, target: BuildTarget, env?: Record<string, string | undefined>, config?: PreflightConfig): Promise<string[]>;
|
|
107
137
|
/**
|
|
108
138
|
* One warning sentence per variable {@link missingDeployEnv} reported, naming
|
|
109
139
|
* the command that sets it where the target knows one.
|
|
@@ -112,4 +142,4 @@ export declare function missingDeployEnv(cwd: string, target: BuildTarget, env?:
|
|
|
112
142
|
* and `determinismWarnings`: each is independently actionable, and the command
|
|
113
143
|
* differs per name.
|
|
114
144
|
*/
|
|
115
|
-
export declare function missingEnvWarnings(missing: readonly string[], target: BuildTarget): string[];
|
|
145
|
+
export declare function missingEnvWarnings(missing: readonly string[], target: BuildTarget, agentName: string): string[];
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as BUILD_TARGETS } from "./_build-target-
|
|
2
|
+
import { t as BUILD_TARGETS } from "./_build-target-C08aM-Es.mjs";
|
|
3
3
|
import { i as installStdoutGuard, n as fail, o as writeLine, r as getOutputMode, t as CliError } from "./_output-DBP9Op_d.mjs";
|
|
4
4
|
import { a as parsePort, n as log, o as silenceOutput } from "./_ui-DCt4qZrk.mjs";
|
|
5
5
|
import { c as fileExists, f as readPackageJson, p as resolveCwd, s as errorMessage$1, t as AGENT_ENTRY } from "./_utils-D5JGcjiW.mjs";
|
|
@@ -396,7 +396,7 @@ const list = defineExec({
|
|
|
396
396
|
args: { ...platformArgs },
|
|
397
397
|
cwd: "any",
|
|
398
398
|
async run({ args, cwd }) {
|
|
399
|
-
const { executeList } = await import("./studio-
|
|
399
|
+
const { executeList } = await import("./studio-BRJsw7lr.mjs");
|
|
400
400
|
return executeList({
|
|
401
401
|
cwd,
|
|
402
402
|
server: args.server
|
|
@@ -428,7 +428,7 @@ const pull = defineExec({
|
|
|
428
428
|
},
|
|
429
429
|
cwd: "any",
|
|
430
430
|
async run({ args, cwd }) {
|
|
431
|
-
const { executePull } = await import("./studio-
|
|
431
|
+
const { executePull } = await import("./studio-BRJsw7lr.mjs");
|
|
432
432
|
return executePull({
|
|
433
433
|
cwd,
|
|
434
434
|
project: args.project,
|
|
@@ -449,7 +449,7 @@ const push = defineExec({
|
|
|
449
449
|
},
|
|
450
450
|
cwd: "agent",
|
|
451
451
|
async run({ args, cwd }) {
|
|
452
|
-
const { executePush } = await import("./studio-
|
|
452
|
+
const { executePush } = await import("./studio-BRJsw7lr.mjs");
|
|
453
453
|
return executePush({
|
|
454
454
|
cwd,
|
|
455
455
|
server: args.server,
|
|
@@ -472,7 +472,7 @@ const publish = defineExec({
|
|
|
472
472
|
},
|
|
473
473
|
cwd: "agent",
|
|
474
474
|
async run({ args, cwd }) {
|
|
475
|
-
const { executePublish } = await import("./studio-
|
|
475
|
+
const { executePublish } = await import("./studio-BRJsw7lr.mjs");
|
|
476
476
|
return executePublish({
|
|
477
477
|
cwd,
|
|
478
478
|
server: args.server,
|
|
@@ -701,7 +701,7 @@ const init = defineExec({
|
|
|
701
701
|
},
|
|
702
702
|
cwd: "none",
|
|
703
703
|
async run({ args, mode }) {
|
|
704
|
-
const { executeInit } = await import("./init-
|
|
704
|
+
const { executeInit } = await import("./init-CbOhyNYe.mjs");
|
|
705
705
|
return executeInit({
|
|
706
706
|
dir: args.dir,
|
|
707
707
|
force: args.force,
|
|
@@ -724,13 +724,13 @@ const dev = defineExec({
|
|
|
724
724
|
},
|
|
725
725
|
watch: {
|
|
726
726
|
type: "boolean",
|
|
727
|
-
description: "Restart on file changes (
|
|
727
|
+
description: "Restart on file changes (default at a terminal; AAI_DEV_WATCH=0 disables)"
|
|
728
728
|
},
|
|
729
729
|
json: sharedArgs.json
|
|
730
730
|
},
|
|
731
731
|
cwd: "agent",
|
|
732
732
|
async run({ args, cwd }) {
|
|
733
|
-
const { executeDev } = await import("./dev-
|
|
733
|
+
const { executeDev } = await import("./dev-BGWU2zPP.mjs");
|
|
734
734
|
return executeDev({
|
|
735
735
|
cwd,
|
|
736
736
|
port: args.port,
|
|
@@ -738,6 +738,25 @@ const dev = defineExec({
|
|
|
738
738
|
});
|
|
739
739
|
}
|
|
740
740
|
});
|
|
741
|
+
const consoleCommand = defineExec({
|
|
742
|
+
meta: {
|
|
743
|
+
name: "console",
|
|
744
|
+
description: "Talk to the agent through your microphone and speakers"
|
|
745
|
+
},
|
|
746
|
+
args: { verbose: {
|
|
747
|
+
type: "boolean",
|
|
748
|
+
description: "Print the runtime's session log to stderr"
|
|
749
|
+
} },
|
|
750
|
+
cwd: "agent",
|
|
751
|
+
async run({ args, cwd, mode }) {
|
|
752
|
+
const { executeConsole } = await import("./console-BsyE3DyB.mjs");
|
|
753
|
+
return executeConsole({
|
|
754
|
+
cwd,
|
|
755
|
+
verbose: args.verbose,
|
|
756
|
+
mode
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
});
|
|
741
760
|
const start = defineExec({
|
|
742
761
|
meta: {
|
|
743
762
|
name: "start",
|
|
@@ -770,19 +789,23 @@ const start = defineExec({
|
|
|
770
789
|
const test = defineExec({
|
|
771
790
|
meta: {
|
|
772
791
|
name: "test",
|
|
773
|
-
description: "Run
|
|
792
|
+
description: "Run the project's tests"
|
|
774
793
|
},
|
|
775
794
|
args: {
|
|
776
795
|
json: sharedArgs.json,
|
|
796
|
+
only: {
|
|
797
|
+
type: "boolean",
|
|
798
|
+
description: "Run agent.test.ts alone, not every spec in the project"
|
|
799
|
+
},
|
|
777
800
|
all: {
|
|
778
801
|
type: "boolean",
|
|
779
|
-
description: "
|
|
802
|
+
description: "Deprecated: every spec in the project is the default"
|
|
780
803
|
}
|
|
781
804
|
},
|
|
782
805
|
cwd: "agent",
|
|
783
806
|
async run({ args, cwd }) {
|
|
784
|
-
const { executeTest } = await import("./test-
|
|
785
|
-
return executeTest(cwd, {
|
|
807
|
+
const { executeTest } = await import("./test-CjKPQ9_B.mjs");
|
|
808
|
+
return executeTest(cwd, { only: args.only === true });
|
|
786
809
|
}
|
|
787
810
|
});
|
|
788
811
|
const evalCommand = defineExec({
|
|
@@ -793,7 +816,7 @@ const evalCommand = defineExec({
|
|
|
793
816
|
args: { json: sharedArgs.json },
|
|
794
817
|
cwd: "agent",
|
|
795
818
|
async run({ cwd }) {
|
|
796
|
-
const { executeEval } = await import("./eval-
|
|
819
|
+
const { executeEval } = await import("./eval-DB07kTxO.mjs");
|
|
797
820
|
return executeEval(cwd);
|
|
798
821
|
}
|
|
799
822
|
});
|
|
@@ -819,7 +842,7 @@ const build = defineExec({
|
|
|
819
842
|
},
|
|
820
843
|
cwd: "agent",
|
|
821
844
|
async run({ args, cwd }) {
|
|
822
|
-
const { executeBuild } = await import("./build-
|
|
845
|
+
const { executeBuild } = await import("./build-DrQTSc2R.mjs");
|
|
823
846
|
return executeBuild({
|
|
824
847
|
cwd,
|
|
825
848
|
skipTests: args.skipTests,
|
|
@@ -847,7 +870,7 @@ const deploy = defineExec({
|
|
|
847
870
|
},
|
|
848
871
|
cwd: "agent",
|
|
849
872
|
async run({ args, cwd }) {
|
|
850
|
-
const { executeDeploy } = await import("./deploy-
|
|
873
|
+
const { executeDeploy } = await import("./deploy-B68-x7xM.mjs");
|
|
851
874
|
return executeDeploy({
|
|
852
875
|
cwd,
|
|
853
876
|
server: args.server,
|
|
@@ -891,7 +914,7 @@ const templates = defineExec({
|
|
|
891
914
|
args: { json: sharedArgs.json },
|
|
892
915
|
cwd: "none",
|
|
893
916
|
async run({ mode }) {
|
|
894
|
-
const { listTemplates } = await import("./_templates-
|
|
917
|
+
const { listTemplates } = await import("./_templates-DXadVNsL.mjs");
|
|
895
918
|
const names = await listTemplates();
|
|
896
919
|
if (mode === "human") {
|
|
897
920
|
for (const name of names) log.message(name);
|
|
@@ -908,6 +931,7 @@ const mainCommand = defineCommand({
|
|
|
908
931
|
subCommands: {
|
|
909
932
|
init,
|
|
910
933
|
dev,
|
|
934
|
+
console: consoleCommand,
|
|
911
935
|
start,
|
|
912
936
|
test,
|
|
913
937
|
eval: evalCommand,
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as ok, n as fail } from "./_output-DBP9Op_d.mjs";
|
|
3
|
+
import { n as log } from "./_ui-DCt4qZrk.mjs";
|
|
4
|
+
import { o as errorDetail, s as errorMessage } from "./_utils-D5JGcjiW.mjs";
|
|
5
|
+
import { n as createWorkerEvaluator } from "./_bundler-DM0d0M7m.mjs";
|
|
6
|
+
import { loadWorker, resolveAgentEnv } from "./_dev-server-Dtp4aAlo.mjs";
|
|
7
|
+
import { styleText } from "node:util";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import { connectSession, createRuntime, ensureSessionStateSchema, ensureWorkflowJournalSchema, withHostCredentialFallback } from "@alexkroman1/aai-runtime";
|
|
10
|
+
import pTimeout from "p-timeout";
|
|
11
|
+
//#region src/_console-audio.ts
|
|
12
|
+
/**
|
|
13
|
+
* `aai console`'s audio devices, as two SoX subprocesses.
|
|
14
|
+
*
|
|
15
|
+
* SoX rather than a native addon: `rec` and `play` open the system's DEFAULT
|
|
16
|
+
* input and output on macOS (CoreAudio), Linux (ALSA/PulseAudio) and Windows
|
|
17
|
+
* with one command line, and a subprocess costs this package no install-time
|
|
18
|
+
* build step and no binary per platform. The price is that SoX must be
|
|
19
|
+
* installed, which {@link missingSoxMessage} says in so many words.
|
|
20
|
+
*
|
|
21
|
+
* Both run in raw PCM16LE mono (`-t raw -b 16 -e signed-integer -c 1 -L`),
|
|
22
|
+
* the format the session speaks, at the rate the session announced.
|
|
23
|
+
*/
|
|
24
|
+
const RAW_PCM16 = [
|
|
25
|
+
"-t",
|
|
26
|
+
"raw",
|
|
27
|
+
"-b",
|
|
28
|
+
"16",
|
|
29
|
+
"-e",
|
|
30
|
+
"signed-integer",
|
|
31
|
+
"-c",
|
|
32
|
+
"1",
|
|
33
|
+
"-L"
|
|
34
|
+
];
|
|
35
|
+
/** What to tell a developer whose machine has no SoX. */
|
|
36
|
+
function missingSoxMessage(binary) {
|
|
37
|
+
return `\`aai console\` needs SoX for microphone and speaker access, and \`${binary}\` was not found. Install it (macOS: \`brew install sox\`; Debian/Ubuntu: \`sudo apt install sox\`; Windows: https://sourceforge.net/projects/sox/) and try again.`;
|
|
38
|
+
}
|
|
39
|
+
function spawnError(binary, err) {
|
|
40
|
+
return err.code === "ENOENT" ? new Error(missingSoxMessage(binary)) : err;
|
|
41
|
+
}
|
|
42
|
+
function kill(child, signal) {
|
|
43
|
+
if (child.exitCode === null && !child.killed) child.kill(signal);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Spawn `play` so that its stdin is a real PIPE.
|
|
47
|
+
*
|
|
48
|
+
* libuv backs `stdio: "pipe"` with a socketpair, and SoX treats a socket stdin
|
|
49
|
+
* with no bytes ready as end of input: the moment the device drains — the end
|
|
50
|
+
* of the greeting, i.e. the first time the agent stops talking — `play` exits
|
|
51
|
+
* 0 with its stdin still open. Measured on macOS with SoX 14.4.2: a 100 ms gap
|
|
52
|
+
* is enough. A shell pipe does not do it, so bash puts one in between.
|
|
53
|
+
* The `exec` makes the PID we hold `play` itself, so kills and exit codes
|
|
54
|
+
* are its own; the `cat` exits on EOF once Node closes the socket at exit.
|
|
55
|
+
*
|
|
56
|
+
* Windows keeps the direct spawn: it has no bash, and its stdio pipes are
|
|
57
|
+
* named pipes rather than sockets.
|
|
58
|
+
*/
|
|
59
|
+
function spawnPlay(args) {
|
|
60
|
+
const stdio = [
|
|
61
|
+
"pipe",
|
|
62
|
+
"ignore",
|
|
63
|
+
"ignore"
|
|
64
|
+
];
|
|
65
|
+
if (process.platform === "win32") return spawn("play", args, { stdio });
|
|
66
|
+
return spawn("bash", [
|
|
67
|
+
"-c",
|
|
68
|
+
"exec play \"$@\" < <(exec cat)",
|
|
69
|
+
"play",
|
|
70
|
+
...args
|
|
71
|
+
], { stdio });
|
|
72
|
+
}
|
|
73
|
+
/** bash's exit status for a command it could not find — the spawn's ENOENT, one shell down. */
|
|
74
|
+
const COMMAND_NOT_FOUND = 127;
|
|
75
|
+
/** Open the default microphone. */
|
|
76
|
+
function startCapture(sampleRate, onChunk, onError) {
|
|
77
|
+
const child = spawn("rec", [
|
|
78
|
+
"-q",
|
|
79
|
+
...RAW_PCM16,
|
|
80
|
+
"-r",
|
|
81
|
+
String(sampleRate),
|
|
82
|
+
"-"
|
|
83
|
+
], { stdio: [
|
|
84
|
+
"ignore",
|
|
85
|
+
"pipe",
|
|
86
|
+
"ignore"
|
|
87
|
+
] });
|
|
88
|
+
let stopped = false;
|
|
89
|
+
child.on("error", (err) => onError(spawnError("rec", err)));
|
|
90
|
+
child.stdout?.on("data", (chunk) => {
|
|
91
|
+
onChunk(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
92
|
+
});
|
|
93
|
+
child.on("exit", (code) => {
|
|
94
|
+
if (!stopped && code !== 0 && code !== null) onError(/* @__PURE__ */ new Error(`the microphone process exited with code ${code}`));
|
|
95
|
+
});
|
|
96
|
+
return { stop() {
|
|
97
|
+
stopped = true;
|
|
98
|
+
kill(child);
|
|
99
|
+
} };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Open the default speaker.
|
|
103
|
+
*
|
|
104
|
+
* `flush` KILLS the process and opens a new one, because that is the only way
|
|
105
|
+
* to empty what SoX and the device already hold: there is no "discard buffer"
|
|
106
|
+
* verb on a pipe. The respawn costs a few tens of ms of device open, paid only
|
|
107
|
+
* on a barge-in, when the agent has just stopped talking anyway.
|
|
108
|
+
*
|
|
109
|
+
* The kill is a SIGKILL. SoX traps SIGTERM and only looks at the flag
|
|
110
|
+
* between reads, so a `play` blocked on an idle pipe — every moment the agent
|
|
111
|
+
* is not talking — ignores it and outlives the console.
|
|
112
|
+
*/
|
|
113
|
+
function startPlayback(sampleRate, onError) {
|
|
114
|
+
let stopped = false;
|
|
115
|
+
let child = open();
|
|
116
|
+
function open() {
|
|
117
|
+
const next = spawnPlay([
|
|
118
|
+
"-q",
|
|
119
|
+
...RAW_PCM16,
|
|
120
|
+
"-r",
|
|
121
|
+
String(sampleRate),
|
|
122
|
+
"-"
|
|
123
|
+
]);
|
|
124
|
+
next.on("error", (err) => onError(spawnError("play", err)));
|
|
125
|
+
next.on("exit", (code) => {
|
|
126
|
+
if (stopped || next !== child) return;
|
|
127
|
+
if (code === COMMAND_NOT_FOUND) return onError(new Error(missingSoxMessage("play")));
|
|
128
|
+
onError(/* @__PURE__ */ new Error(`the speaker process exited${code === null ? "" : ` with code ${code}`}`));
|
|
129
|
+
});
|
|
130
|
+
next.stdin?.on("error", () => void 0);
|
|
131
|
+
return next;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
write(pcm16) {
|
|
135
|
+
if (stopped) return;
|
|
136
|
+
child.stdin?.write(pcm16);
|
|
137
|
+
},
|
|
138
|
+
flush() {
|
|
139
|
+
if (stopped) return;
|
|
140
|
+
const old = child;
|
|
141
|
+
child = open();
|
|
142
|
+
kill(old, "SIGKILL");
|
|
143
|
+
},
|
|
144
|
+
stop() {
|
|
145
|
+
stopped = true;
|
|
146
|
+
child.stdin?.end();
|
|
147
|
+
kill(child, "SIGKILL");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** The SoX-backed devices. */
|
|
152
|
+
const soxAudio = {
|
|
153
|
+
startCapture,
|
|
154
|
+
startPlayback
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/_console-session.ts
|
|
158
|
+
/**
|
|
159
|
+
* The sink the session writes to: agent audio to the speaker, the transcript
|
|
160
|
+
* to the terminal.
|
|
161
|
+
*
|
|
162
|
+
* `onClosed` fires when the RUNTIME closes the sink — a session that failed to
|
|
163
|
+
* start, or one resumed elsewhere — so the command can stop the devices and
|
|
164
|
+
* exit rather than sit with a live microphone feeding nothing.
|
|
165
|
+
*
|
|
166
|
+
* `onFatal` fires on a FATAL `error.reported`, which the protocol defines as
|
|
167
|
+
* "the session is over". A browser shows the banner and the person hangs up;
|
|
168
|
+
* the telephony bridge ends the call; the console has to end itself too, or a
|
|
169
|
+
* session that can never speak (a provider refusing the key) leaves the
|
|
170
|
+
* developer talking to silence.
|
|
171
|
+
*/
|
|
172
|
+
function createConsoleSink(opts) {
|
|
173
|
+
const { player, print } = opts;
|
|
174
|
+
let open = true;
|
|
175
|
+
/** The reply's text so far — what to print if it is cut off before it commits. */
|
|
176
|
+
let pendingAgentText = "";
|
|
177
|
+
return {
|
|
178
|
+
get open() {
|
|
179
|
+
return open;
|
|
180
|
+
},
|
|
181
|
+
event(e) {
|
|
182
|
+
switch (e.type) {
|
|
183
|
+
case "user-transcript.committed":
|
|
184
|
+
if (e.text.trim()) print.user(e.text);
|
|
185
|
+
return;
|
|
186
|
+
case "agent-transcript.updated":
|
|
187
|
+
pendingAgentText = e.text;
|
|
188
|
+
return;
|
|
189
|
+
case "agent-transcript.committed":
|
|
190
|
+
pendingAgentText = "";
|
|
191
|
+
if (e.text.trim()) print.agent(e.text);
|
|
192
|
+
return;
|
|
193
|
+
case "reply.cancelled":
|
|
194
|
+
player.flush();
|
|
195
|
+
if (pendingAgentText.trim()) print.agent(pendingAgentText, true);
|
|
196
|
+
pendingAgentText = "";
|
|
197
|
+
return;
|
|
198
|
+
case "session.reset":
|
|
199
|
+
player.flush();
|
|
200
|
+
pendingAgentText = "";
|
|
201
|
+
return;
|
|
202
|
+
case "tool.called":
|
|
203
|
+
print.tool(e.toolName, e.args);
|
|
204
|
+
return;
|
|
205
|
+
case "error.reported":
|
|
206
|
+
print.error(e.message, e.fatal);
|
|
207
|
+
if (e.fatal) opts.onFatal(e.message);
|
|
208
|
+
return;
|
|
209
|
+
default: return;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
playAudioChunk(chunk) {
|
|
213
|
+
player.write(chunk);
|
|
214
|
+
},
|
|
215
|
+
close(reason) {
|
|
216
|
+
if (!open) return;
|
|
217
|
+
open = false;
|
|
218
|
+
opts.onClosed(reason);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Feed a byte stream into a connection as whole PCM16 samples.
|
|
224
|
+
*
|
|
225
|
+
* A pipe hands over reads of whatever length it likes, and an odd one would
|
|
226
|
+
* split a sample across two chunks — every sample after it would then be read
|
|
227
|
+
* with its bytes swapped, which is loud noise rather than a subtle error.
|
|
228
|
+
*/
|
|
229
|
+
function createSampleAligner(connection) {
|
|
230
|
+
let carry = null;
|
|
231
|
+
return (bytes) => {
|
|
232
|
+
if (bytes.byteLength === 0) return;
|
|
233
|
+
let data = bytes;
|
|
234
|
+
if (carry !== null) {
|
|
235
|
+
const joined = new Uint8Array(bytes.byteLength + 1);
|
|
236
|
+
joined[0] = carry;
|
|
237
|
+
joined.set(bytes, 1);
|
|
238
|
+
data = joined;
|
|
239
|
+
carry = null;
|
|
240
|
+
}
|
|
241
|
+
const whole = data.byteLength - data.byteLength % 2;
|
|
242
|
+
if (whole < data.byteLength) carry = data[data.byteLength - 1] ?? null;
|
|
243
|
+
if (whole > 0) connection.sendAudio(data.subarray(0, whole));
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/console.ts
|
|
248
|
+
/**
|
|
249
|
+
* `aai console` — talk to the agent through this machine's microphone and
|
|
250
|
+
* speakers, with the conversation printed in the terminal. No server, no
|
|
251
|
+
* browser, no socket.
|
|
252
|
+
*
|
|
253
|
+
* It is the smallest real consumer of `connectSession`: the agent is loaded
|
|
254
|
+
* exactly as `aai dev` loads it (same bundle, same `.env` resolution, same
|
|
255
|
+
* shell-credential fallback), a runtime is built in-process, and the session
|
|
256
|
+
* runs over a {@link ClientSink} that plays audio and prints transcripts. Every
|
|
257
|
+
* behaviour a browser session has — turn-taking, barge-in, tools, pacing —
|
|
258
|
+
* comes from the runtime, not from here.
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* The pacing lead for a speaker on this machine, in ms.
|
|
262
|
+
*
|
|
263
|
+
* Well under the browser's `CLIENT_AUDIO_LEAD_MS` (1500), because what that
|
|
264
|
+
* lead buys — riding out a lossy network — does not exist between a process
|
|
265
|
+
* and its own sound card, while what it costs does: audio already handed to
|
|
266
|
+
* the device is audio a barge-in has to kill the player to discard.
|
|
267
|
+
*/
|
|
268
|
+
const CONSOLE_AUDIO_LEAD_MS = 400;
|
|
269
|
+
/**
|
|
270
|
+
* How long to wait for the microphone's first bytes before opening the speaker
|
|
271
|
+
* anyway, in ms. Measured on AirPods: 0.74 s. Past this the speaker opens
|
|
272
|
+
* regardless — a slow mic is a possibly-wrong rate, a hang is certainly wrong.
|
|
273
|
+
*/
|
|
274
|
+
const MIC_OPEN_TIMEOUT_MS = 3e3;
|
|
275
|
+
/** The runtime's own lines go to stderr, and its chatty ones only when asked. */
|
|
276
|
+
function consoleRuntimeLogger(verbose) {
|
|
277
|
+
const write = (msg, ctx) => {
|
|
278
|
+
process.stderr.write(`${styleText("dim", msg)}${ctx === void 0 ? "" : ` ${styleText("dim", JSON.stringify(ctx))}`}\n`);
|
|
279
|
+
};
|
|
280
|
+
const quiet = () => void 0;
|
|
281
|
+
return {
|
|
282
|
+
info: verbose ? write : quiet,
|
|
283
|
+
debug: verbose ? write : quiet,
|
|
284
|
+
warn: write,
|
|
285
|
+
error: write
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/** Print the conversation to stdout. */
|
|
289
|
+
function terminalPrinter(write) {
|
|
290
|
+
return {
|
|
291
|
+
user: (text) => write(`${styleText(["bold", "cyan"], "you ")} ${text}`),
|
|
292
|
+
agent: (text, interrupted) => write(`${styleText(["bold", "green"], "agent ")} ${text}${interrupted ? styleText("dim", " [interrupted]") : ""}`),
|
|
293
|
+
tool: (name, args) => write(styleText("dim", ` → ${name}(${JSON.stringify(args)})`)),
|
|
294
|
+
error: (message, fatal) => write(styleText(fatal ? "red" : "yellow", ` ${fatal ? "error" : "warning"}: ${message}`))
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Run one console session until Ctrl-C, or until the session ends itself.
|
|
299
|
+
*
|
|
300
|
+
* `audio` is a parameter so the spec can drive it without a sound card.
|
|
301
|
+
*/
|
|
302
|
+
async function executeConsole(opts) {
|
|
303
|
+
const audio = opts.audio ?? soxAudio;
|
|
304
|
+
const logger = consoleRuntimeLogger(opts.verbose === true);
|
|
305
|
+
log.step("Bundling agent…");
|
|
306
|
+
let agentDef;
|
|
307
|
+
try {
|
|
308
|
+
agentDef = await loadWorker(opts.cwd, createWorkerEvaluator());
|
|
309
|
+
} catch (err) {
|
|
310
|
+
return fail("build_failed", `Could not load agent.ts: ${errorMessage(err)}`);
|
|
311
|
+
}
|
|
312
|
+
if (agentDef.page === "static") return fail("not_a_voice_agent", "This agent declares `page: \"static\"` — a workflow app has no voice session to talk to.", "Run `aai dev` and open the page instead.");
|
|
313
|
+
const env = await resolveAgentEnv(opts.cwd, agentDef);
|
|
314
|
+
if (env.DATABASE_URL) {
|
|
315
|
+
await ensureSessionStateSchema({
|
|
316
|
+
url: env.DATABASE_URL,
|
|
317
|
+
logger
|
|
318
|
+
});
|
|
319
|
+
await ensureWorkflowJournalSchema({
|
|
320
|
+
url: env.DATABASE_URL,
|
|
321
|
+
logger
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const runtime = createRuntime({
|
|
325
|
+
agent: agentDef,
|
|
326
|
+
env,
|
|
327
|
+
providerEnv: withHostCredentialFallback(env),
|
|
328
|
+
logger
|
|
329
|
+
});
|
|
330
|
+
const { sampleRate, ttsSampleRate } = runtime.readyConfig;
|
|
331
|
+
let deviceError;
|
|
332
|
+
let endNow = () => void 0;
|
|
333
|
+
const ended = new Promise((resolve) => {
|
|
334
|
+
endNow = resolve;
|
|
335
|
+
});
|
|
336
|
+
const onDeviceError = (err) => {
|
|
337
|
+
deviceError ??= err;
|
|
338
|
+
endNow();
|
|
339
|
+
};
|
|
340
|
+
let forward = () => void 0;
|
|
341
|
+
let micOpened = () => void 0;
|
|
342
|
+
const micReady = new Promise((resolve) => {
|
|
343
|
+
micOpened = resolve;
|
|
344
|
+
});
|
|
345
|
+
const capture = audio.startCapture(sampleRate, (bytes) => {
|
|
346
|
+
micOpened();
|
|
347
|
+
forward(bytes);
|
|
348
|
+
}, onDeviceError);
|
|
349
|
+
await pTimeout(Promise.race([micReady, ended]), {
|
|
350
|
+
milliseconds: MIC_OPEN_TIMEOUT_MS,
|
|
351
|
+
fallback: () => void 0
|
|
352
|
+
});
|
|
353
|
+
const player = audio.startPlayback(ttsSampleRate, onDeviceError);
|
|
354
|
+
const out = opts.mode === "json" ? process.stderr : process.stdout;
|
|
355
|
+
const print = terminalPrinter((line) => out.write(`${line}\n`));
|
|
356
|
+
let closedReason;
|
|
357
|
+
let fatalMessage;
|
|
358
|
+
const sink = createConsoleSink({
|
|
359
|
+
player,
|
|
360
|
+
print,
|
|
361
|
+
onClosed: (reason) => {
|
|
362
|
+
closedReason = reason;
|
|
363
|
+
endNow();
|
|
364
|
+
},
|
|
365
|
+
onFatal: (message) => {
|
|
366
|
+
fatalMessage ??= message;
|
|
367
|
+
endNow();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
const connection = connectSession(runtime, sink, {
|
|
371
|
+
audioLeadMs: CONSOLE_AUDIO_LEAD_MS,
|
|
372
|
+
logContext: { transport: "console" }
|
|
373
|
+
});
|
|
374
|
+
forward = createSampleAligner(connection);
|
|
375
|
+
connection.sendCommand({ type: "audio_ready" });
|
|
376
|
+
log.success(`Talking to ${agentDef.name}. Press Ctrl-C to hang up.`);
|
|
377
|
+
log.info("Use headphones: without echo cancellation the agent hears itself and interrupts.");
|
|
378
|
+
const quit = opts.untilQuit === void 0 ? signalled() : void 0;
|
|
379
|
+
try {
|
|
380
|
+
await Promise.race([
|
|
381
|
+
opts.untilQuit ?? quit?.signal,
|
|
382
|
+
ended,
|
|
383
|
+
connection.ended
|
|
384
|
+
]);
|
|
385
|
+
} finally {
|
|
386
|
+
quit?.dispose();
|
|
387
|
+
}
|
|
388
|
+
capture.stop();
|
|
389
|
+
connection.close();
|
|
390
|
+
await connection.ended;
|
|
391
|
+
player.stop();
|
|
392
|
+
try {
|
|
393
|
+
await runtime.shutdown();
|
|
394
|
+
} catch (err) {
|
|
395
|
+
logger.warn(`Runtime shutdown failed: ${errorDetail(err)}`);
|
|
396
|
+
}
|
|
397
|
+
if (deviceError) return fail("audio_device", deviceError.message);
|
|
398
|
+
if (fatalMessage !== void 0) return fail("session_failed", fatalMessage);
|
|
399
|
+
if (closedReason === "session start failed") return fail("session_failed", "The session failed to start — see the error above.");
|
|
400
|
+
return ok({ sessionId: connection.id });
|
|
401
|
+
}
|
|
402
|
+
/** The first SIGINT or SIGTERM, and a way to stop listening for it. */
|
|
403
|
+
function signalled() {
|
|
404
|
+
let dispose = () => void 0;
|
|
405
|
+
return {
|
|
406
|
+
signal: new Promise((resolve) => {
|
|
407
|
+
const done = () => {
|
|
408
|
+
dispose();
|
|
409
|
+
resolve();
|
|
410
|
+
};
|
|
411
|
+
dispose = () => {
|
|
412
|
+
process.off("SIGINT", done);
|
|
413
|
+
process.off("SIGTERM", done);
|
|
414
|
+
};
|
|
415
|
+
process.on("SIGINT", done);
|
|
416
|
+
process.on("SIGTERM", done);
|
|
417
|
+
}),
|
|
418
|
+
dispose
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
export { executeConsole };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aai console` — talk to the agent through this machine's microphone and
|
|
3
|
+
* speakers, with the conversation printed in the terminal. No server, no
|
|
4
|
+
* browser, no socket.
|
|
5
|
+
*
|
|
6
|
+
* It is the smallest real consumer of `connectSession`: the agent is loaded
|
|
7
|
+
* exactly as `aai dev` loads it (same bundle, same `.env` resolution, same
|
|
8
|
+
* shell-credential fallback), a runtime is built in-process, and the session
|
|
9
|
+
* runs over a {@link ClientSink} that plays audio and prints transcripts. Every
|
|
10
|
+
* behaviour a browser session has — turn-taking, barge-in, tools, pacing —
|
|
11
|
+
* comes from the runtime, not from here.
|
|
12
|
+
*/
|
|
13
|
+
import { type ConsoleAudio, type ConsolePrinter } from "./_console-session.ts";
|
|
14
|
+
import { type CommandResult, type OutputMode } from "./_output.ts";
|
|
15
|
+
type ConsoleData = {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
};
|
|
18
|
+
/** Print the conversation to stdout. */
|
|
19
|
+
export declare function terminalPrinter(write: (line: string) => void): ConsolePrinter;
|
|
20
|
+
/**
|
|
21
|
+
* Run one console session until Ctrl-C, or until the session ends itself.
|
|
22
|
+
*
|
|
23
|
+
* `audio` is a parameter so the spec can drive it without a sound card.
|
|
24
|
+
*/
|
|
25
|
+
export declare function executeConsole(opts: {
|
|
26
|
+
cwd: string;
|
|
27
|
+
verbose?: boolean | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* JSON mode owes stdout exactly one result line, and JSON mode is
|
|
30
|
+
* auto-selected on a pipe — so there the conversation goes to stderr.
|
|
31
|
+
*/
|
|
32
|
+
mode?: OutputMode;
|
|
33
|
+
audio?: ConsoleAudio;
|
|
34
|
+
/** Resolves when the user asks to quit. Defaults to the first SIGINT/SIGTERM. */
|
|
35
|
+
untilQuit?: Promise<void>;
|
|
36
|
+
}): Promise<CommandResult<ConsoleData>>;
|
|
37
|
+
export {};
|