@alexkroman1/aai-cli 0.16.0 → 0.17.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.
@@ -14,8 +14,8 @@ import { existsSync, statSync } from "node:fs";
14
14
  import path from "node:path";
15
15
  import { omitUndefined, plural } from "@alexkroman1/aai/utils";
16
16
  import { agentRequiredEnv, createCoalescingRunner, frontDoorOf, parseWsUpgradeParams, requestPath, sleep } from "@alexkroman1/aai/internal";
17
- import { DEFAULT_LISTEN_HOST, createRuntime, createServerForRuntime, ensureSessionStateSchema, ensureWorkflowJournalSchema } from "@alexkroman1/aai-runtime";
18
- import { SERVER_ROUTES, WORKFLOW_DATA_DIR_ENV, createMemoryJournal, handleWorkflowRequest, isPathInside, publishClientInboxDefaults, publishStepEnv, requiredProviderEnvVars, withHostCredentialFallback } from "@alexkroman1/aai-runtime/internal";
17
+ import { DEFAULT_LISTEN_HOST, createMemoryJournal, createRuntime, createServerForRuntime, ensureSessionStateSchema, ensureWorkflowJournalSchema } from "@alexkroman1/aai-runtime";
18
+ import { SERVER_ROUTES, WORKFLOW_DATA_DIR_ENV, handleWorkflowRequest, isPathInside, publishClientInboxDefaults, publishStepEnv, requiredProviderEnvVars, withHostCredentialFallback } from "@alexkroman1/aai-runtime/internal";
19
19
  import { defaultClientDir } from "@alexkroman1/aai-ui/client-dir";
20
20
  import { watch } from "chokidar";
21
21
  import getPort, { portNumbers } from "get-port";
package/dist/cli.mjs CHANGED
@@ -892,7 +892,7 @@ const dev = defineExec({
892
892
  },
893
893
  cwd: "agent",
894
894
  async run({ args, cwd, ui }) {
895
- const { executeDev } = await import("./dev-CxZsZsOL.mjs");
895
+ const { executeDev } = await import("./dev-CT_QHHZL.mjs");
896
896
  return executeDev({
897
897
  cwd,
898
898
  port: args.port,
@@ -913,7 +913,7 @@ const consoleCommand = defineExec({
913
913
  } },
914
914
  cwd: "agent",
915
915
  async run({ args, cwd, mode, ui }) {
916
- const { executeConsole } = await import("./console-Bp1kSqz_.mjs");
916
+ const { executeConsole } = await import("./console-tVBjfKyR.mjs");
917
917
  return executeConsole({
918
918
  cwd,
919
919
  verbose: args.verbose,
@@ -3,7 +3,7 @@ import { a as ok, n as fail } from "./_output-DBP9Op_d.mjs";
3
3
  import { t as defaultUi } from "./_ui-Coe0zwmm.mjs";
4
4
  import { o as errorDetail, s as errorMessage } from "./_utils-BVLdBvdT.mjs";
5
5
  import { n as createWorkerEvaluator } from "./_bundler-DCuNHjDF.mjs";
6
- import { loadWorker, t as resolveAgentEnv } from "./_dev-server-B4ZiXbZj.mjs";
6
+ import { loadWorker, t as resolveAgentEnv } from "./_dev-server-D6VSQbYW.mjs";
7
7
  import { styleText } from "node:util";
8
8
  import { spawn } from "node:child_process";
9
9
  import { connectSession, createRuntime, ensureSessionStateSchema, ensureWorkflowJournalSchema } from "@alexkroman1/aai-runtime";
@@ -164,7 +164,7 @@ async function resolveDevDeps(deps) {
164
164
  ui: deps.ui ?? defaultUi,
165
165
  startQuickTunnel: deps.startQuickTunnel ?? startQuickTunnel,
166
166
  runPublicUrlHook: deps.runPublicUrlHook ?? runPublicUrlHook,
167
- startDevServer: deps.startDevServer ?? (await import("./_dev-server-B4ZiXbZj.mjs")).startDevServer
167
+ startDevServer: deps.startDevServer ?? (await import("./_dev-server-D6VSQbYW.mjs")).startDevServer
168
168
  };
169
169
  }
170
170
  /**
@@ -106,7 +106,9 @@ export default agent({
106
106
  // name: { cart: cartSlot.projected } (read it
107
107
  // with useAgentState; see UI.md)
108
108
  events?: SessionEventHandlers; // observe the session; "metrics.collected" is each
109
- // reply's latency/tokens: createMetricsCollector()
109
+ // reply's latency/tokens: createMetricsCollector();
110
+ // "error.reported" carries a SessionErrorCode (open:
111
+ // switch with a default); "*" gets AnySessionEvent
110
112
  sessionContext?: (args) => SessionContext; // fetched once per connect, before the first model
111
113
  // call: extra instructions, history cut-off, refusal
112
114
  onSessionEnd?: (ctx) => unknown; // after every hang-up / disconnect / idle close
@@ -176,8 +178,9 @@ export default agent({
176
178
  `sessionContext` is bounded (1.5 s) and a throw, a timeout or `undefined` starts
177
179
  the session without it; `onSessionEnd` is fire-and-forget and at-least-once, so
178
180
  key any run it starts. A `routes` handler's return value is the JSON body;
179
- `routeResponse(status, body)` picks another status and a thrown
180
- `routeError(status, message)` answers `{ error: message }`.
181
+ `routeResponse(status, body, { headers })` picks another status (and any headers
182
+ — a `Location`, a `Retry-After`) and a thrown `routeError(status, message)`
183
+ answers `{ error: message }`.
181
184
 
182
185
  ## Composing a system prompt
183
186
 
@@ -15,10 +15,10 @@
15
15
  "publish:agent": "aai publish"
16
16
  },
17
17
  "dependencies": {
18
- "@alexkroman1/aai": "^0.16.0",
19
- "@alexkroman1/aai-cli": "^0.16.0",
20
- "@alexkroman1/aai-runtime": "^0.16.0",
21
- "@alexkroman1/aai-ui": "^0.16.0",
18
+ "@alexkroman1/aai": "^0.17.0",
19
+ "@alexkroman1/aai-cli": "^0.17.0",
20
+ "@alexkroman1/aai-runtime": "^0.17.0",
21
+ "@alexkroman1/aai-ui": "^0.17.0",
22
22
  "react": "^19.3.0",
23
23
  "react-dom": "^19.3.0",
24
24
  "tailwindcss": "^4.0.0",
@@ -42,7 +42,6 @@ import {
42
42
  ASSEMBLYAI_STT_EU_URL,
43
43
  type AssemblyAISttOptions,
44
44
  assemblyAIStt,
45
- DEEPGRAM_DEFAULT_ENDPOINTING_MS,
46
45
  type DeepgramSttOptions,
47
46
  deepgramStt,
48
47
  type ElevenLabsSttOptions,
@@ -223,16 +222,13 @@ describe("the STT stage", () => {
223
222
  }
224
223
  });
225
224
 
226
- test("Deepgram's endpointing window is a published default, not a hidden one", () => {
227
- // The descriptor carries only what you set — the host fills the rest — so
228
- // the number is published rather than buried in the opener. It is worth
229
- // knowing before you move it: 1500ms is matched to the AssemblyAI opener's
225
+ test("Deepgram's endpointing window is the host's default unless you set one", () => {
226
+ // The descriptor carries only what you set — the host fills the rest. It is
227
+ // worth knowing before you move it: the host default, 1500ms, is matched to the AssemblyAI opener's
230
228
  // 1600ms `min_turn_silence`, and Deepgram exposes no pause-tolerance
231
229
  // counterpart, so this one window is the whole end-of-turn policy there.
232
230
  expect(deepgramStt().options.endpointing).toBeUndefined();
233
- expect(deepgramStt({ endpointing: DEEPGRAM_DEFAULT_ENDPOINTING_MS }).options.endpointing).toBe(
234
- DEEPGRAM_DEFAULT_ENDPOINTING_MS,
235
- );
231
+ expect(deepgramStt({ endpointing: 1500 }).options.endpointing).toBe(1500);
236
232
  // Deepgram is also the one STT here that does NOT auto-detect: it defaults
237
233
  // to English, so an agent moved to it silently loses non-English
238
234
  // transcription unless it names a code.
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { omitUndefined } from "@alexkroman1/aai/utils";
17
17
  import type { WorkflowInputOf } from "@alexkroman1/aai/workflow-api";
18
- import type { FileValue, FormValues } from "@alexkroman1/aai-ui";
18
+ import { type FormValues, isFileValue } from "@alexkroman1/aai-ui";
19
19
  import type { redline } from "./agent.ts";
20
20
 
21
21
  /** What the desk is asked for, derived from the declaration rather than restated. */
@@ -54,7 +54,7 @@ export function toInput(values: FormValues): RedlineFormInput {
54
54
  /**
55
55
  * The chosen file as the schema's `source`, or nothing at all.
56
56
  *
57
- * `<FileField read="text">` contributes a {@link FileValue} — the file's
57
+ * `<FileField read="text">` contributes a `FileValue` — the file's
58
58
  * metadata plus its text, read in the BROWSER — and contributes no key at all
59
59
  * when nothing was chosen, which is why this takes `unknown` and why the absent
60
60
  * case is the ordinary one rather than an error. Nothing is uploaded: a draft is
@@ -63,12 +63,11 @@ export function toInput(values: FormValues): RedlineFormInput {
63
63
  * and `transcription-workflow` is where it is answered.
64
64
  */
65
65
  export function attachedDraft(value: unknown): { name: string; text: string } | undefined {
66
- const file = value as FileValue | undefined;
67
- if (file === undefined || typeof file.content !== "string") return undefined;
66
+ if (!isFileValue(value) || value.content === undefined) return undefined;
68
67
  // Passed through UNTRIMMED, deliberately: a file somebody chose is a file they
69
68
  // meant to redline, so an empty one has to come back as the schema refusing it
70
69
  // by name rather than as a draft written from scratch that they did not ask
71
70
  // for. It is the same layering as `brief` — the schema counts CHARACTERS, and
72
71
  // `acceptDraft` catches the whitespace that gets past it.
73
- return { name: file.name, text: file.content };
72
+ return { name: value.name, text: value.content };
74
73
  }
@@ -18,19 +18,17 @@ function refusal(result: unknown): string {
18
18
  describe("the roster", () => {
19
19
  test("triage answers the phone, and every persona's tools plus `handoff` are on the agent", () => {
20
20
  expect(desk.list.map((one) => one.name)).toEqual(["triage", "billing", "support"]);
21
- // The `tools/` files, plus the toolset the roster minted.
22
- const served = [
23
- ...Object.keys(agentDef.tools),
24
- ...(agentDef.toolsets ?? []).flatMap((set) => Object.keys(set.list())),
25
- ];
26
- expect(served.sort()).toEqual([
21
+ // The `tools/` files are the shared ones; the roster minted the rest.
22
+ expect(Object.keys(agentDef.tools).sort()).toEqual(["verify_account"]);
23
+ for (const name of [
27
24
  HANDOFF_TOOL_NAME,
28
25
  "issue_refund",
29
26
  "lookup_invoice",
30
27
  "run_diagnostic",
31
28
  "schedule_technician",
32
- "verify_account",
33
- ]);
29
+ ]) {
30
+ expect(toolOf(agentDef, name).description).not.toBe("");
31
+ }
34
32
  expect(desk.active(createToolContext())).toBe(triage);
35
33
  });
36
34
 
@@ -1,6 +1,7 @@
1
1
  /// <reference types="vite/client" />
2
2
  import "@alexkroman1/aai-ui/styles.css";
3
3
  import {
4
+ type ChatMessage,
4
5
  ConversationView,
5
6
  mountClient,
6
7
  SessionErrorBanner,
@@ -102,15 +103,7 @@ function App() {
102
103
  );
103
104
  }
104
105
 
105
- function Bubble({
106
- from,
107
- text,
108
- live,
109
- }: {
110
- from: "user" | "assistant";
111
- text: string;
112
- live?: boolean;
113
- }) {
106
+ function Bubble({ from, text, live }: { from: ChatMessage["role"]; text: string; live?: boolean }) {
114
107
  const mine = from === "user";
115
108
  return (
116
109
  <p
@@ -50,13 +50,11 @@ import {
50
50
  createStubWorkflows,
51
51
  createToolContext,
52
52
  createWorkflowContext,
53
- type JournalStore,
54
53
  parseSchemaInput,
55
54
  type RecordedStep,
56
55
  type RunWorkflowOptions,
57
56
  runTool,
58
57
  runWorkflow,
59
- type SleepRecord,
60
58
  schemaInputIssues,
61
59
  stubGatewayRoute,
62
60
  toolRunner,
@@ -64,6 +62,7 @@ import {
64
62
  type WorkflowTestHandle,
65
63
  type WorkflowTestRun,
66
64
  type WorkflowTestStep,
65
+ type WorkflowTestWait,
67
66
  } from "@alexkroman1/aai-runtime/testing";
68
67
  import {
69
68
  installStubGateway,
@@ -1208,8 +1207,8 @@ describe("the run is DURABLE", () => {
1208
1207
  }
1209
1208
 
1210
1209
  /** What each of a run's parks IS — an ordinary sleep, or a window's deadline. */
1211
- function parkKinds(sleeps: readonly SleepRecord[]): SleepRecord["kind"][] {
1212
- return sleeps.map((sleep) => sleep.kind);
1210
+ function parkKinds(waits: readonly WorkflowTestWait[]): WorkflowTestWait["kind"][] {
1211
+ return waits.map((wait) => wait.kind);
1213
1212
  }
1214
1213
 
1215
1214
  beforeEach(() => {
@@ -1286,7 +1285,7 @@ describe("the run is DURABLE", () => {
1286
1285
  test("journals the gate as a hook DEADLINE and the poll as a sleep", async () => {
1287
1286
  // The distinction the whole retention pattern rests on, read off the
1288
1287
  // journal rather than inferred from behaviour. A run parks twice for two
1289
- // different reasons, and `SleepRecord.kind` is what keeps them apart:
1288
+ // different reasons, and `WorkflowTestWait.kind` is what keeps them apart:
1290
1289
  // `wakeUp` (with no correlation ids) reaches only `sleep`, which is why
1291
1290
  // `expireWaits` exists at all and why "send it now" cannot be made to
1292
1291
  // answer an approval window it was never told the answer to.
@@ -1294,13 +1293,11 @@ describe("the run is DURABLE", () => {
1294
1293
  const run = await startRecap();
1295
1294
  await run.advanceSleep();
1296
1295
 
1297
- // `JournalStore` is the store the run really lives in — the same interface
1298
- // the platform's Postgres backend implements — so this is the durable
1299
- // record and not the driver's view of it.
1300
- const journal: JournalStore = run.journal;
1301
- // One of each, without a claim about the order: the journal answers by KEY
1302
- // rather than by when the run reached each park.
1303
- const kinds = parkKinds(await journal.readSleeps(run.runId));
1296
+ // `waits` is read off the journal the run really lives in, so this is the
1297
+ // durable record and not the driver's view of it. One of each, without a
1298
+ // claim about the order: the list is by KEY rather than by when the run
1299
+ // reached each park.
1300
+ const kinds = parkKinds(run.waits);
1304
1301
  expect(kinds).toHaveLength(2);
1305
1302
  expect(kinds).toContain("sleep");
1306
1303
  expect(kinds).toContain("hookTimeout");
@@ -142,10 +142,14 @@ function connected(status: PlacedCallStatus): boolean {
142
142
  /** The carrier's word for a call that never reached a session. */
143
143
  function unansweredOutcome(status: PlacedCallStatus): CallOutcome {
144
144
  switch (status) {
145
+ // Spelled per case: `PlacedCallStatus` is OPEN (a carrier may report a status
146
+ // this SDK has not named yet), so a matched case does not narrow `status`.
145
147
  case "busy":
148
+ return "busy";
146
149
  case "failed":
150
+ return "failed";
147
151
  case "canceled":
148
- return status;
152
+ return "canceled";
149
153
  default:
150
154
  // Still `queued`/`ringing` after every poll reads as nobody picking up.
151
155
  return "no-answer";
@@ -30,13 +30,10 @@ import {
30
30
  import { FatalError, RetryableError } from "@alexkroman1/aai/step-errors";
31
31
  import type { WorkflowRunSnapshot } from "@alexkroman1/aai/workflow-api";
32
32
  import type {
33
- JournalStore,
34
- ResumableRun,
35
33
  RunWorkflowOptions,
36
- SleepRecord,
37
- StepEntry,
38
- WorkflowTestHandle,
39
34
  WorkflowTestRun,
35
+ WorkflowTestStep,
36
+ WorkflowTestWait,
40
37
  } from "@alexkroman1/aai-runtime/testing";
41
38
  import {
42
39
  createRunSnapshot,
@@ -697,22 +694,13 @@ describe("the run is DURABLE", () => {
697
694
  * The run's snapshot carries `wakeAt` and nothing about WHICH wait it is, so
698
695
  * the correlation id `file_it_now` names is only visible here.
699
696
  */
700
- async function reviewSleep(run: WorkflowTestHandle<unknown>): Promise<SleepRecord | undefined> {
701
- const sleeps = await run.journal.readSleeps(run.runId);
702
- return sleeps.find((sleep) => sleep.correlationId === REVIEW_SLEEP_ID);
697
+ function reviewSleep(run: WorkflowTestRun<unknown>): WorkflowTestWait | undefined {
698
+ return run.waits.find((wait) => wait.correlationId === REVIEW_SLEEP_ID);
703
699
  }
704
700
 
705
701
  /** What an `investigate` left in the journal for a resume to reuse. */
706
- async function journaledResearch(
707
- journal: JournalStore,
708
- runId: string,
709
- ): Promise<StepEntry | undefined> {
710
- return (await journal.readSteps(runId)).find((step) => step.name === "investigate");
711
- }
712
-
713
- /** What a boot sweep would still owe — the query a stranded run is found by. */
714
- async function resumable(journal: JournalStore): Promise<ResumableRun[]> {
715
- return (await journal.resumableRuns?.(10)) ?? [];
702
+ function journaledResearch(run: WorkflowTestRun<unknown>): WorkflowTestStep | undefined {
703
+ return run.steps.find((step) => step.name === "investigate");
716
704
  }
717
705
 
718
706
  test("suspends on the review wait with the whole report already journaled", async () => {
@@ -742,7 +730,7 @@ describe("the run is DURABLE", () => {
742
730
  installStubGateway(SCRIPT);
743
731
  const run = await runWorkflow(research, INPUT, RUN);
744
732
 
745
- const sleep = await reviewSleep(run);
733
+ const sleep = reviewSleep(run);
746
734
  expect(sleep, "the run holds no sleep under the review correlation id").toBeDefined();
747
735
  expect(sleep?.woken).toBe(false);
748
736
  expect(sleep?.kind).toBe("sleep");
@@ -799,13 +787,13 @@ describe("the run is DURABLE", () => {
799
787
  // WHY the resume is free, read off the store rather than inferred from a
800
788
  // call count: the finished angle's own result is sitting in the journal,
801
789
  // which is what the second walk answers `investigate#0` from.
802
- const done = await journaledResearch(run.journal, run.runId);
790
+ const done = journaledResearch(run);
803
791
  expect(done?.status).toBe("ok");
804
792
  expect(done?.output).toMatchObject({ angle: "Tool use" });
805
793
  // And the run is still FINDABLE: a dead worker leaves it for a boot sweep,
806
794
  // which is what makes "resume" a platform behaviour rather than a promise
807
795
  // this handle keeps.
808
- expect((await resumable(run.journal)).map((one) => one.runId)).toContain(run.runId);
796
+ expect(run.resumable).toBe(true);
809
797
 
810
798
  await run.restart();
811
799
  await run.advanceSleep([REVIEW_SLEEP_ID]);
@@ -1,6 +1,6 @@
1
1
  /** The def a DEPLOYED agent runs: authored, plus what `system-prompt.md` says. */
2
2
  import agentDef from "virtual:aai/agent";
3
- import { MCP_TOOL_NAME_MAX, MCP_TOOL_PREFIX, mcpToolName } from "@alexkroman1/aai";
3
+ import { MCP_TOOL_PREFIX, mcpToolName } from "@alexkroman1/aai";
4
4
  import { expectDeployable, expectPromptBuiltinsDeclared } from "@alexkroman1/aai-runtime/testing";
5
5
  import { afterEach, describe, expect, test, vi } from "vitest";
6
6
  import { ARCHIVE_KEY, ARCHIVE_TOKEN_ENV, ARCHIVE_URL_ENV } from "./agent.ts";
@@ -172,11 +172,11 @@ describe("the archive MCP server", () => {
172
172
  // the archive publishing its own `web_search` cannot land where Scout's
173
173
  // builtin of that name stood. The key is the first segment of that name and
174
174
  // is the template's own choice, so this is where its length is spent —
175
- // `MCP_TOOL_NAME_MAX` is a hard cap and a name that exceeds it is TRUNCATED,
175
+ // the 64-character tool-name cap providers enforce is hard and a name that exceeds it is TRUNCATED,
176
176
  // which is how two of a server's tools collapse onto one name and one of
177
177
  // them is silently dropped.
178
178
  const name = mcpToolName(ARCHIVE_KEY, "web_search");
179
179
  expect(name).toBe(`${MCP_TOOL_PREFIX}${ARCHIVE_KEY}_web_search`);
180
- expect(name.length).toBeLessThanOrEqual(MCP_TOOL_NAME_MAX);
180
+ expect(name.length).toBeLessThanOrEqual(64);
181
181
  });
182
182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexkroman1/aai-cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -58,9 +58,9 @@
58
58
  "vite": "^8.3.1",
59
59
  "xstate": "^5.33.2",
60
60
  "zod": "^4.6.5",
61
- "@alexkroman1/aai": "0.16.0",
62
- "@alexkroman1/aai-runtime": "0.16.0",
63
- "@alexkroman1/aai-ui": "0.16.0"
61
+ "@alexkroman1/aai": "0.17.0",
62
+ "@alexkroman1/aai-runtime": "0.17.0",
63
+ "@alexkroman1/aai-ui": "0.17.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "playwright": "^1.63.0",