@alexkroman1/aai-cli 0.19.1 → 0.21.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/dist/scaffold/agent-guide/TESTING-EVALS.md +72 -2
- package/dist/scaffold/agent-guide/TOOLS.md +2 -1
- package/dist/scaffold/agent-guide/UI.md +22 -6
- package/dist/scaffold/package.json +4 -4
- package/dist/templates/applicant-screening-agent/client.tsx +1 -1
- package/dist/templates/entertainment-picks-agent/client.tsx +1 -1
- package/dist/templates/front-door-agent/agent.test.ts +10 -14
- package/dist/templates/kitchen-coach-agent/agent.test.ts +11 -11
- package/dist/templates/outbound-call-agent/agent.test.ts +29 -42
- package/dist/templates/podcast-digest-workflow/agent.test.ts +8 -7
- package/dist/templates/research-planner-agent/agent.test.ts +14 -4
- package/dist/templates/research-planner-agent/procedure.ts +8 -5
- package/package.json +4 -4
|
@@ -31,7 +31,20 @@ pass.
|
|
|
31
31
|
**A spec that needs the agent as DEPLOYED imports one module:**
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import
|
|
34
|
+
import {
|
|
35
|
+
createRecordingSpeech,
|
|
36
|
+
createRouteContext,
|
|
37
|
+
createTranscriptSession,
|
|
38
|
+
} from "@alexkroman1/aai-runtime/testing";
|
|
39
|
+
|
|
40
|
+
const speech = createRecordingSpeech();
|
|
41
|
+
export const ctx = createRouteContext({
|
|
42
|
+
clientTranscript: async (clientId) => ({
|
|
43
|
+
sessions: clientId === "u_me" ? [createTranscriptSession({ sessionId: "s1" })] : [],
|
|
44
|
+
}),
|
|
45
|
+
speech: (sessionId) => (sessionId === "s1" ? speech : undefined),
|
|
46
|
+
});
|
|
47
|
+
// Call a route handler with `ctx`; what it said is `speech.said`.
|
|
35
48
|
```
|
|
36
49
|
|
|
37
50
|
That is `agent.ts` with its `tools/` directory discovered and its
|
|
@@ -136,7 +149,64 @@ transcribes installs them all at once:
|
|
|
136
149
|
`installStubWorld({ model, pages, transcribe, speech, uploads })` (with
|
|
137
150
|
`uploads: { files, writable }`) composes the seams in the one order that works
|
|
138
151
|
and hands back every fake's call log (`world.model`, `world.provider`,
|
|
139
|
-
`world.reported`, …).
|
|
152
|
+
`world.reported`, …). Plain HTTP is `installStubFetchRoutes(table)`, restored
|
|
153
|
+
when the test finishes — never `stubFetchRoutes` with a trailing `restore()`,
|
|
154
|
+
which leaks into every later test once an assertion fails first.
|
|
155
|
+
|
|
156
|
+
**Never cast a context.** Every context a spec needs has a builder that fills
|
|
157
|
+
what the spec does not care about, so a partial object cast to the whole
|
|
158
|
+
(`{ … } as never`) is always avoidable:
|
|
159
|
+
|
|
160
|
+
- `fireEvent(agentDef, event, { sessionId, env })` completes a PARTIAL context;
|
|
161
|
+
pass a `createToolContext()` instead when you read back what the handler wrote
|
|
162
|
+
or said.
|
|
163
|
+
- `runSessionContext(agentDef, { clientId, env })` and
|
|
164
|
+
`runSessionEnd(agentDef, { sessionId, workflows, transcript })` run the two
|
|
165
|
+
lifecycle hooks. Each FAILS if the agent stops declaring the hook, where
|
|
166
|
+
`agentDef.onSessionEnd?.(…)` would pass against nothing.
|
|
167
|
+
- `createTranscriptSession({ sessionId, messages })` builds one session for a
|
|
168
|
+
`stubClientTranscript` answer or a route's `clientTranscript`;
|
|
169
|
+
`createRecordingSpeech()` is a route's `speech` handle and records `said`.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import agentDef from "virtual:aai/agent";
|
|
173
|
+
import {
|
|
174
|
+
createRecordingSpeech,
|
|
175
|
+
createRouteContext,
|
|
176
|
+
createTranscriptSession,
|
|
177
|
+
} from "@alexkroman1/aai-runtime/testing";
|
|
178
|
+
|
|
179
|
+
const speech = createRecordingSpeech();
|
|
180
|
+
const ctx = createRouteContext({
|
|
181
|
+
clientTranscript: async (clientId) => ({
|
|
182
|
+
sessions: clientId === "u_me" ? [createTranscriptSession({ sessionId: "s1" })] : [],
|
|
183
|
+
}),
|
|
184
|
+
speech: (sessionId) => (sessionId === "s1" ? speech : undefined),
|
|
185
|
+
});
|
|
186
|
+
// …call a route with ctx, then read speech.said
|
|
187
|
+
void agentDef;
|
|
188
|
+
void ctx;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `client.tsx` specs
|
|
192
|
+
|
|
193
|
+
A page under test reads its session through the hooks, and a real session needs
|
|
194
|
+
a microphone and the agent's socket. `createTestSession()` from
|
|
195
|
+
`@alexkroman1/aai-ui/testing` is one with neither, rendered under its own
|
|
196
|
+
`wrapper` so the REAL hooks run over it — do not `vi.mock` the hooks. Move it
|
|
197
|
+
with `session.update({ state: "listening" })` (a custom event is
|
|
198
|
+
`update({ customEvents: [{ id, event, data }] })`), and read what the page
|
|
199
|
+
called from `session.calls`.
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { createTestSession } from "@alexkroman1/aai-ui/testing";
|
|
203
|
+
|
|
204
|
+
const session = createTestSession({ snapshot: { state: "listening" } });
|
|
205
|
+
// In a spec: render(<Page />, { wrapper: session.wrapper }), then act on the page.
|
|
206
|
+
session.start();
|
|
207
|
+
session.update({ customEvents: [{ id: 1, event: "order", data: { total: "$14.99" } }] });
|
|
208
|
+
console.log(session.getSnapshot().started, session.calls); // true [{ method: "start", args: [] }]
|
|
209
|
+
```
|
|
140
210
|
|
|
141
211
|
## Evals: `agent.eval.test.ts`
|
|
142
212
|
|
|
@@ -59,7 +59,8 @@ ctx.send(event, data): void // push custom event to browser c
|
|
|
59
59
|
ctx.generate(opts): Promise<{ text, object? }> // one-shot LLM call (host-side)
|
|
60
60
|
// with a `schema`, `object` is REQUIRED and typed by it
|
|
61
61
|
ctx.delegate(sub, opts): Promise<DelegateResult> // run a subagent — a whole tool loop with its own
|
|
62
|
-
// context window (see "Speakers")
|
|
62
|
+
// context window (see "Speakers"); a `schema` speaker's
|
|
63
|
+
// `object` is typed, but read it behind `accepted`
|
|
63
64
|
ctx.signal: AbortSignal // aborts on barge-in, reset, session stop, or this call's timeout
|
|
64
65
|
ctx.speech: SessionSpeech // say(text) verbatim LATER, or interrupt() — see "Saying
|
|
65
66
|
// something from outside a turn" in PIPELINE-TUNING.md;
|
|
@@ -32,8 +32,11 @@ import { useState } from "react";
|
|
|
32
32
|
|
|
33
33
|
function Sidebar() {
|
|
34
34
|
const [items, setItems] = useState<string[]>([]);
|
|
35
|
-
useEvent
|
|
36
|
-
|
|
35
|
+
useEvent("new_item", (data) => {
|
|
36
|
+
// `data` is `unknown` until the event is declared (see `useEvent` below).
|
|
37
|
+
if (typeof data === "object" && data !== null && "item" in data) {
|
|
38
|
+
setItems((prev) => [...prev, String(data.item)]);
|
|
39
|
+
}
|
|
37
40
|
});
|
|
38
41
|
return (
|
|
39
42
|
<div className="p-4">
|
|
@@ -176,14 +179,27 @@ PINs, scratch) or cannot be serialized. Whatever it returns is exactly what the
|
|
|
176
179
|
client receives. It runs after every tool call and is sent only when the result
|
|
177
180
|
changed.
|
|
178
181
|
|
|
179
|
-
**`useEvent`** — fires for custom events from `ctx.send()
|
|
182
|
+
**`useEvent`** — fires for custom events from `ctx.send()`. **Declare the event
|
|
183
|
+
once, in a file both sides import**, and the tool's `ctx.send` and the page's
|
|
184
|
+
`useEvent` are both typed from it — nothing restated, and a wrong payload on
|
|
185
|
+
either side is a compile error:
|
|
180
186
|
|
|
181
187
|
```ts no-check
|
|
182
|
-
|
|
188
|
+
// shared.ts
|
|
189
|
+
declare module "@alexkroman1/aai" {
|
|
190
|
+
interface ClientEventMap {
|
|
191
|
+
order: { total: string };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// tool: ctx.send("order", { total: "$14.99" })
|
|
195
|
+
// page: useEvent("order", ({ total }) => setTotal(total))
|
|
183
196
|
```
|
|
184
197
|
|
|
185
|
-
|
|
186
|
-
`useEvent("order", (
|
|
198
|
+
To CHECK the payload at runtime too, pass a schema:
|
|
199
|
+
`useEvent("order", z.object({ total: z.string() }), (order) => …)` — an event
|
|
200
|
+
that fails it never reaches the callback. An undeclared event's `data` is
|
|
201
|
+
`unknown`; annotating the callback (`(item: Item) => …`) is an unchecked
|
|
202
|
+
assertion, so prefer either form above. There is no `useEvent<T>(…)` form.
|
|
187
203
|
|
|
188
204
|
**`useTheme`** — returns the resolved `{ bg, primary, text, surface, border }`.
|
|
189
205
|
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"publish:agent": "aai publish"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@alexkroman1/aai": "^0.
|
|
19
|
-
"@alexkroman1/aai-cli": "^0.
|
|
20
|
-
"@alexkroman1/aai-runtime": "^0.
|
|
21
|
-
"@alexkroman1/aai-ui": "^0.
|
|
18
|
+
"@alexkroman1/aai": "^0.21.0",
|
|
19
|
+
"@alexkroman1/aai-cli": "^0.21.0",
|
|
20
|
+
"@alexkroman1/aai-runtime": "^0.21.0",
|
|
21
|
+
"@alexkroman1/aai-ui": "^0.21.0",
|
|
22
22
|
"react": "^19.3.1",
|
|
23
23
|
"react-dom": "^19.3.1",
|
|
24
24
|
"tailwindcss": "^4.0.0",
|
|
@@ -123,7 +123,7 @@ function HiringSidebar() {
|
|
|
123
123
|
* not reached its total yet, and nothing once it has. */
|
|
124
124
|
function ScreeningTicker() {
|
|
125
125
|
const [progress, setProgress] = useState<ScreeningProgress | null>(null);
|
|
126
|
-
useEvent
|
|
126
|
+
useEvent(SCREENING_PROGRESS, setProgress);
|
|
127
127
|
if (!progress || progress.done >= progress.total) return null;
|
|
128
128
|
const verb = progress.phase === "scoring" ? "Scoring" : "Writing";
|
|
129
129
|
return (
|
|
@@ -66,7 +66,7 @@ function RecSidebar() {
|
|
|
66
66
|
// something chill…" pulsing for the rest of the call.
|
|
67
67
|
useToolCallStart("recommend", (tc) => setPendingMood(String(tc.args.mood)));
|
|
68
68
|
useToolResult("recommend", () => setPendingMood(null));
|
|
69
|
-
useEvent
|
|
69
|
+
useEvent("wind_down", (text: string) => setNudge(text));
|
|
70
70
|
|
|
71
71
|
// A read-back names a pick the sidebar is ALREADY showing, so there is
|
|
72
72
|
// nothing to add to the list — the line just says which one is being read
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createRouteContext,
|
|
11
11
|
createRunSnapshot,
|
|
12
12
|
createToolContext,
|
|
13
|
+
createTranscriptSession,
|
|
13
14
|
createWorkflowContext,
|
|
14
15
|
expectDeployable,
|
|
15
16
|
runWorkflow,
|
|
@@ -264,16 +265,13 @@ describeAgent(deployedDef, (run) => {
|
|
|
264
265
|
});
|
|
265
266
|
|
|
266
267
|
describe("digestOf", () => {
|
|
267
|
-
const session = (
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
messages: said.map((text, i) => ({ role: i % 2 ? "user" : "assistant", text, at: i })),
|
|
275
|
-
tools,
|
|
276
|
-
});
|
|
268
|
+
const session = (said: string[], tools: ClientTranscript["sessions"][number]["tools"] = []) =>
|
|
269
|
+
createTranscriptSession({
|
|
270
|
+
sessionId: `s${said.length}${tools.length}`,
|
|
271
|
+
startedAt: 0,
|
|
272
|
+
messages: said.map((text, i) => ({ role: i % 2 ? "user" : "assistant", text, at: i })),
|
|
273
|
+
tools,
|
|
274
|
+
});
|
|
277
275
|
const left = (name: string, message: string) => ({
|
|
278
276
|
name: "leave_message",
|
|
279
277
|
args: { name, message },
|
|
@@ -357,16 +355,14 @@ describeAgent(deployedDef, (run) => {
|
|
|
357
355
|
test("digest reads the day once, even when the worker dies before telling the phone", async () => {
|
|
358
356
|
const transcript = stubClientTranscript({
|
|
359
357
|
sessions: [
|
|
360
|
-
{
|
|
358
|
+
createTranscriptSession({
|
|
361
359
|
sessionId: "s1",
|
|
362
360
|
startedAt: 0,
|
|
363
|
-
lastEventIndex: 3,
|
|
364
361
|
messages: [
|
|
365
362
|
{ role: "assistant", text: "Hello", at: 0 },
|
|
366
363
|
{ role: "user", text: "Delivery", at: 1 },
|
|
367
364
|
],
|
|
368
|
-
|
|
369
|
-
},
|
|
365
|
+
}),
|
|
370
366
|
],
|
|
371
367
|
});
|
|
372
368
|
onTestFinished(transcript.restore);
|
|
@@ -4,6 +4,7 @@ import { omitUndefined } from "@alexkroman1/aai/utils";
|
|
|
4
4
|
import {
|
|
5
5
|
createRouteContext,
|
|
6
6
|
createToolContext,
|
|
7
|
+
createTranscriptSession,
|
|
7
8
|
expectDeployable,
|
|
8
9
|
} from "@alexkroman1/aai-runtime/testing";
|
|
9
10
|
import { describeAgent } from "@alexkroman1/aai-runtime/testing/vitest";
|
|
@@ -142,17 +143,16 @@ describeAgent(agentDef, (run) => {
|
|
|
142
143
|
body: undefined,
|
|
143
144
|
...omitUndefined({ clientId }),
|
|
144
145
|
});
|
|
145
|
-
const session = (sessionId: string, startedAt: number, said: string[]) =>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
146
|
+
const session = (sessionId: string, startedAt: number, said: string[]) =>
|
|
147
|
+
createTranscriptSession({
|
|
148
|
+
sessionId,
|
|
149
|
+
startedAt,
|
|
150
|
+
messages: said.map((text, i) => ({
|
|
151
|
+
role: i % 2 === 0 ? "assistant" : "user",
|
|
152
|
+
text,
|
|
153
|
+
at: startedAt + i,
|
|
154
|
+
})),
|
|
155
|
+
});
|
|
156
156
|
|
|
157
157
|
test("lists this browser's conversations newest first, by what the cook said first", async () => {
|
|
158
158
|
const asked: string[] = [];
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
type RouteRequest,
|
|
22
22
|
readCallBrief,
|
|
23
23
|
type SessionCall,
|
|
24
|
-
type SessionEndContext,
|
|
25
24
|
sessionCall,
|
|
26
25
|
signCallBrief,
|
|
27
26
|
} from "@alexkroman1/aai";
|
|
@@ -32,7 +31,11 @@ import {
|
|
|
32
31
|
createToolContext,
|
|
33
32
|
endSessionCalls,
|
|
34
33
|
type RunWorkflowOptions,
|
|
34
|
+
runSessionContext,
|
|
35
|
+
runSessionEnd,
|
|
35
36
|
runWorkflow,
|
|
37
|
+
type SessionContextOverrides,
|
|
38
|
+
type SessionEndOverrides,
|
|
36
39
|
stubGatewayRoute,
|
|
37
40
|
stubPlaceCall,
|
|
38
41
|
type TestToolContext,
|
|
@@ -102,24 +105,18 @@ async function placedCall(id: string, prompt = PROMPT, secret = SECRET): Promise
|
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* `SessionEndContext` lands here once.
|
|
108
|
+
* Run `onSessionEnd` as the session `ctx` was on ends: the session's own id and
|
|
109
|
+
* slots (so a fact a tool wrote during the call is readable), the agent's
|
|
110
|
+
* secret, and whatever the case adds. `runSessionEnd` fills the rest and fails
|
|
111
|
+
* if the agent stops declaring the hook.
|
|
110
112
|
*/
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
over: Partial<SessionEndContext> & Pick<SessionEndContext, "workflows">,
|
|
114
|
-
): SessionEndContext {
|
|
115
|
-
return {
|
|
113
|
+
function endSession(ctx: TestToolContext, over: SessionEndOverrides) {
|
|
114
|
+
return runSessionEnd(agentDef, {
|
|
116
115
|
sessionId: ctx.sessionId,
|
|
117
116
|
env: { CALLS_API_KEY: SECRET },
|
|
118
117
|
slots: ctx.slots,
|
|
119
|
-
transcript: [],
|
|
120
|
-
lastEventIndex: -1,
|
|
121
118
|
...over,
|
|
122
|
-
};
|
|
119
|
+
});
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
describeAgent(agentDef, (run) => {
|
|
@@ -263,23 +260,21 @@ describeAgent(agentDef, (run) => {
|
|
|
263
260
|
|
|
264
261
|
describe("the call brief", () => {
|
|
265
262
|
test("sessionContext refuses an unsigned stream and briefs a signed one", async () => {
|
|
266
|
-
const sessionContext =
|
|
267
|
-
|
|
268
|
-
const args = { env: { CALLS_API_KEY: SECRET }, signal: new AbortController().signal };
|
|
263
|
+
const sessionContext = (over: SessionContextOverrides) =>
|
|
264
|
+
runSessionContext(agentDef, { env: { CALLS_API_KEY: SECRET }, ...over });
|
|
269
265
|
|
|
270
|
-
expect(await sessionContext({
|
|
266
|
+
expect(await sessionContext({ sessionId: "s_web" })).toMatchObject({
|
|
271
267
|
refuse: expect.any(String),
|
|
272
268
|
});
|
|
273
269
|
expect(
|
|
274
270
|
await sessionContext({
|
|
275
|
-
...args,
|
|
276
271
|
sessionId: "s_stranger",
|
|
277
272
|
call: await placedCall("call_1", PROMPT, "another-key"),
|
|
278
273
|
}),
|
|
279
274
|
).toMatchObject({ refuse: expect.any(String) });
|
|
280
275
|
|
|
281
276
|
expect(
|
|
282
|
-
await sessionContext({
|
|
277
|
+
await sessionContext({ sessionId: "s_signed", call: await placedCall("call_1") }),
|
|
283
278
|
).toMatchObject({ greeting: "", instructions: expect.stringContaining(PROMPT) });
|
|
284
279
|
});
|
|
285
280
|
});
|
|
@@ -337,17 +332,14 @@ describeAgent(agentDef, (run) => {
|
|
|
337
332
|
const workflows = installStubWorkflows({ agent: agentDef });
|
|
338
333
|
const ctx = createToolContext({ sessionId: "s_1" });
|
|
339
334
|
|
|
340
|
-
await
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
lastEventIndex: 1,
|
|
349
|
-
}),
|
|
350
|
-
);
|
|
335
|
+
await endSession(ctx, {
|
|
336
|
+
call: await placedCall("call_42"),
|
|
337
|
+
workflows,
|
|
338
|
+
transcript: [
|
|
339
|
+
{ role: "user", text: "Hello?", at: 1000 },
|
|
340
|
+
{ role: "assistant", text: "Hi, is this Maria?", at: 75_000 },
|
|
341
|
+
],
|
|
342
|
+
});
|
|
351
343
|
|
|
352
344
|
// `signalRun` holds the payload for the run by default, so a call shorter
|
|
353
345
|
// than one ring poll still reaches a run not yet parked on it.
|
|
@@ -366,14 +358,11 @@ describeAgent(agentDef, (run) => {
|
|
|
366
358
|
const ctx = createToolContext({ sessionId: "s_vm" });
|
|
367
359
|
await run(endCall, { voicemail: true }, ctx);
|
|
368
360
|
|
|
369
|
-
await
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
lastEventIndex: 0,
|
|
375
|
-
}),
|
|
376
|
-
);
|
|
361
|
+
await endSession(ctx, {
|
|
362
|
+
call: await placedCall("call_43"),
|
|
363
|
+
workflows,
|
|
364
|
+
transcript: [{ role: "assistant", text: "Hi Maria, please call us back.", at: 1000 }],
|
|
365
|
+
});
|
|
377
366
|
|
|
378
367
|
expect(workflows.signalRun).toHaveBeenCalledWith(
|
|
379
368
|
call,
|
|
@@ -385,9 +374,7 @@ describeAgent(agentDef, (run) => {
|
|
|
385
374
|
|
|
386
375
|
test("a session that was never a placed call hands nothing over", async () => {
|
|
387
376
|
const workflows = installStubWorkflows({ agent: agentDef });
|
|
388
|
-
await
|
|
389
|
-
sessionEnd(createToolContext({ sessionId: "s_none" }), { workflows }),
|
|
390
|
-
);
|
|
377
|
+
await endSession(createToolContext({ sessionId: "s_none" }), { workflows });
|
|
391
378
|
expect(workflows.signalRun).not.toHaveBeenCalled();
|
|
392
379
|
});
|
|
393
380
|
});
|
|
@@ -28,11 +28,14 @@ import {
|
|
|
28
28
|
runWorkflow,
|
|
29
29
|
type StubTranscribeOptions,
|
|
30
30
|
schemaInputIssues,
|
|
31
|
-
stubFetchRoutes,
|
|
32
31
|
type WorkflowContextRecorder,
|
|
33
32
|
} from "@alexkroman1/aai-runtime/testing";
|
|
34
|
-
import {
|
|
35
|
-
|
|
33
|
+
import {
|
|
34
|
+
installStubFetchRoutes,
|
|
35
|
+
installStubStepFetch,
|
|
36
|
+
installStubWorld,
|
|
37
|
+
} from "@alexkroman1/aai-runtime/testing/vitest";
|
|
38
|
+
import { describe, expect, test } from "vitest";
|
|
36
39
|
import agentDef, { dailyDigest } from "./agent.ts";
|
|
37
40
|
import {
|
|
38
41
|
dailyDigestFlow,
|
|
@@ -434,12 +437,12 @@ const THREE_EPISODES = feedXml(
|
|
|
434
437
|
/**
|
|
435
438
|
* Route by URL, so one stub can answer a whole resolution chain.
|
|
436
439
|
*
|
|
437
|
-
*
|
|
440
|
+
* `installStubFetchRoutes` restores it when the test finishes, which is why no
|
|
438
441
|
* describe block below keeps a `restore` of its own — a hand-kept registry is
|
|
439
442
|
* the thing that forgets, and a step fetch left published reaches the next file.
|
|
440
443
|
*/
|
|
441
444
|
function stubRoutes(routes: Record<string, { status?: number; body?: unknown }>) {
|
|
442
|
-
|
|
445
|
+
return installStubFetchRoutes(
|
|
443
446
|
Object.entries(routes).map(
|
|
444
447
|
([fragment, answer]) =>
|
|
445
448
|
(request) =>
|
|
@@ -451,8 +454,6 @@ function stubRoutes(routes: Record<string, { status?: number; body?: unknown }>)
|
|
|
451
454
|
// finding instead, the default is what says so at the call.
|
|
452
455
|
{ unmatched: "notFound" },
|
|
453
456
|
);
|
|
454
|
-
onTestFinished(net.restore);
|
|
455
|
-
return net;
|
|
456
457
|
}
|
|
457
458
|
|
|
458
459
|
describe("discoverEpisodes", () => {
|
|
@@ -63,10 +63,10 @@ interface Script {
|
|
|
63
63
|
* One executor run's final message.
|
|
64
64
|
*
|
|
65
65
|
* The executor declares a `schema`, so its reply really is JSON on the wire and
|
|
66
|
-
* `stubDelegate` really parses it against that schema
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* which is what most of these tests want to say.
|
|
66
|
+
* `stubDelegate` really parses it against that schema, with the runner's own
|
|
67
|
+
* check — a script that drifted from the shape comes back `accepted: false`
|
|
68
|
+
* with no `object`, exactly as a real reply that drifted does. A bare string is
|
|
69
|
+
* the settled case, which is what most of these tests want to say.
|
|
70
70
|
*/
|
|
71
71
|
function stepReply(answer: string | StepAnswer): string {
|
|
72
72
|
return JSON.stringify(typeof answer === "string" ? { finding: answer, settled: true } : answer);
|
|
@@ -213,6 +213,16 @@ describeAgent(agentDef, (run) => {
|
|
|
213
213
|
expect(outcome.settled).toBe(false);
|
|
214
214
|
expect(outcome.result).toBe("Flights are cheap in May.");
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
test("a reply that never had the schema's shape is recorded raw and unsettled", async () => {
|
|
218
|
+
// Every revision came back prose, so the runtime gives up with NO
|
|
219
|
+
// `object` — reading `object.finding` here was a TypeError mid-call.
|
|
220
|
+
const desk = stubDelegate({ routes: { executor: "Flights look cheap in May." } });
|
|
221
|
+
|
|
222
|
+
const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
|
|
223
|
+
|
|
224
|
+
expect(outcome).toMatchObject({ result: "Flights look cheap in May.", settled: false });
|
|
225
|
+
});
|
|
216
226
|
});
|
|
217
227
|
|
|
218
228
|
describe("the executor's guardrail", () => {
|
|
@@ -215,11 +215,14 @@ export async function executeStep(
|
|
|
215
215
|
),
|
|
216
216
|
});
|
|
217
217
|
return {
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
|
|
218
|
+
// A run that never produced the schema's shape has no `object`, so the raw
|
|
219
|
+
// reply is the most the plan can record of what the executor found.
|
|
220
|
+
result: result.object?.finding ?? result.text,
|
|
221
|
+
// An answer the runtime never accepted is not a settled step, whatever it
|
|
222
|
+
// says about itself: the run had its revisions and still reported a step it
|
|
223
|
+
// never looked into, or never answered in shape. `accepted` is the
|
|
224
|
+
// runtime's own verdict on that — and it is what makes `object` readable.
|
|
225
|
+
settled: result.accepted && result.object.settled,
|
|
223
226
|
// What the wait bought, read off the calls the run made — the desk renders
|
|
224
227
|
// these, and `toolCalls` is the only honest source for them: a search's
|
|
225
228
|
// RESULTS stayed inside the executor's context, which is the point.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexkroman1/aai-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"vite": "^8.3.8",
|
|
59
59
|
"xstate": "^5.33.4",
|
|
60
60
|
"zod": "^4.6.7",
|
|
61
|
-
"@alexkroman1/aai": "0.
|
|
62
|
-
"@alexkroman1/aai-runtime": "0.
|
|
63
|
-
"@alexkroman1/aai-ui": "0.
|
|
61
|
+
"@alexkroman1/aai": "0.21.0",
|
|
62
|
+
"@alexkroman1/aai-runtime": "0.21.0",
|
|
63
|
+
"@alexkroman1/aai-ui": "0.21.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"playwright": "^1.65.1",
|