@zvada/agent-server 0.3.30 → 0.3.31
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/CHANGELOG.md +36 -0
- package/dist/core/runtime/event-processor.js +9 -10
- package/dist/operator/errors.js +9 -2
- package/dist/operator/index.js +1 -1
- package/dist/operator/operator.js +382 -145
- package/dist/operator/render.js +28 -10
- package/dist/operator/session-tools.js +9 -12
- package/dist/operator/view.js +16 -4
- package/dist/protocol/conversation.js +2 -0
- package/dist/protocol/lifecycle.js +2 -0
- package/dist/protocol/reduce.js +1 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +3 -1
- package/dist/types/operator/errors.d.ts.map +1 -1
- package/dist/types/operator/index.d.ts +1 -1
- package/dist/types/operator/index.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +2 -0
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts +1 -4
- package/dist/types/operator/session-tools.d.ts.map +1 -1
- package/dist/types/operator/types.d.ts +73 -13
- package/dist/types/operator/types.d.ts.map +1 -1
- package/dist/types/operator/view.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +3 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +2 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/reduce.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +1 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +2 -0
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/docs/consuming.md +55 -13
- package/package.json +1 -1
- package/src/core/runtime/event-processor.ts +14 -9
- package/src/operator/errors.ts +12 -4
- package/src/operator/index.ts +1 -1
- package/src/operator/operator.ts +489 -146
- package/src/operator/render.ts +29 -8
- package/src/operator/session-tools.ts +9 -12
- package/src/operator/types.ts +77 -12
- package/src/operator/view.ts +26 -9
- package/src/protocol/conversation.ts +2 -0
- package/src/protocol/lifecycle.ts +2 -0
- package/src/protocol/reduce.ts +2 -0
package/src/operator/render.ts
CHANGED
|
@@ -44,6 +44,12 @@ export function oneLine(text: string): string {
|
|
|
44
44
|
return text.replace(BREAKS, " ").replace(CONTROLS, "").replace(/\s+/g, " ").trim();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** Each distinct line the host gives about the session or its settled turn. */
|
|
48
|
+
export function noteLines(...notes: (string | undefined)[]): string {
|
|
49
|
+
const lines = new Set(notes.map((note) => oneLine(note ?? "")).filter(Boolean));
|
|
50
|
+
return Array.from(lines, (note) => `\nnote: ${note}`).join("");
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
/** Untrusted text as a block: each of its lines carried after `QUOTE`. */
|
|
48
54
|
export function quote(text: string): string {
|
|
49
55
|
return QUOTE + text.replace(CONTROLS, "").replace(BREAKS, `\n${QUOTE}`);
|
|
@@ -382,6 +388,12 @@ const STATUS_WORDS: Record<string, string> = {
|
|
|
382
388
|
archived: "archived",
|
|
383
389
|
};
|
|
384
390
|
|
|
391
|
+
function unreadLine(steers: ViewTurn["steers"]): string | undefined {
|
|
392
|
+
const unread = steers && Object.values(steers).filter((s) => s === "undelivered").length;
|
|
393
|
+
if (unread === 1) return "1 message sent into this turn was never read.";
|
|
394
|
+
if (unread) return `${unread} messages sent into this turn were never read.`;
|
|
395
|
+
}
|
|
396
|
+
|
|
385
397
|
/** How the waits and outcomes word a view; `waited` is how long the call waited. */
|
|
386
398
|
export interface OutcomeContext extends WaitingContext {
|
|
387
399
|
waited?: number;
|
|
@@ -408,7 +420,8 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
|
|
|
408
420
|
context.waited ? `still running after ${context.waited}s` : "",
|
|
409
421
|
].filter(Boolean);
|
|
410
422
|
const next = hint("wait_for_sessions", { sessions: [ref] });
|
|
411
|
-
|
|
423
|
+
const status = `status: working${detail.length ? ` (${detail.join("; ")})` : ""}`;
|
|
424
|
+
return status + noteLines(view.note) + (next ? `\n ${next}` : "");
|
|
412
425
|
}
|
|
413
426
|
const messages = messagesOf(view);
|
|
414
427
|
const fresh = view.status === "idle" && !messages.length;
|
|
@@ -424,12 +437,16 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
|
|
|
424
437
|
const failed = view.turns.at(-1)?.error;
|
|
425
438
|
lines.push(block("error:", failed ?? "the turn failed"));
|
|
426
439
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
const ended = view.lastEnded ?? view.turns.at(-1);
|
|
441
|
+
const unread =
|
|
442
|
+
!view.running &&
|
|
443
|
+
view.status !== "needs_input" &&
|
|
444
|
+
ended &&
|
|
445
|
+
unreadLine(ended.steers ?? view.turns.find((turn) => turn.turnId === ended.turnId)?.steers);
|
|
446
|
+
if (unread) lines.push(unread);
|
|
447
|
+
const outcome = lines.join("\n") + noteLines(context.note, view.note);
|
|
448
|
+
const read = view.status === "error" && hint("read_session", { session: ref });
|
|
449
|
+
return outcome + (read ? `\n ${read}` : "");
|
|
433
450
|
}
|
|
434
451
|
|
|
435
452
|
/** Who a user message is from, as `read_session` labels it; `you` is the caller's own origin. */
|
|
@@ -529,9 +546,13 @@ export function renderConversation(view: SessionView, options: RenderOptions): s
|
|
|
529
546
|
}
|
|
530
547
|
const end = endOf(turn, you);
|
|
531
548
|
if (end) lines.push(end);
|
|
549
|
+
const unread = unreadLine(
|
|
550
|
+
turn.steers ?? (view.lastEnded?.turnId === turn.turnId ? view.lastEnded.steers : undefined),
|
|
551
|
+
);
|
|
552
|
+
if (unread) lines.push(unread);
|
|
532
553
|
}
|
|
533
554
|
if (!count && !view.turns.length) lines.push("(no messages yet)");
|
|
534
|
-
lines.push(`(status: ${view.status})`);
|
|
555
|
+
lines.push(`(status: ${view.status})${noteLines(view.note)}`);
|
|
535
556
|
for (const waiting of view.waiting)
|
|
536
557
|
lines.push(describeWaiting(waiting, perRequest(options, waiting)));
|
|
537
558
|
const total = view.turns.reduce((sum, turn) => sum + turn.messages.length, 0);
|
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
import { OperatorError, refuse } from "./errors.ts";
|
|
11
11
|
import type { Operator } from "./types.ts";
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* What a host adds to the instructions of every session that has these
|
|
15
|
-
* tools, or can receive messages from sessions that do.
|
|
16
|
-
*/
|
|
13
|
+
/** Instructions for sessions that have the tools or receive other agents' messages. */
|
|
17
14
|
export const OPERATOR_GUIDANCE = [
|
|
18
15
|
"You can see and work with other agent sessions with the session tools",
|
|
19
16
|
"(whoami, list_sessions, read_session, wait_for_sessions, start_session,",
|
|
@@ -24,14 +21,14 @@ export const OPERATOR_GUIDANCE = [
|
|
|
24
21
|
"what it did, archive it when its work is done (you cannot start more than a",
|
|
25
22
|
"few without archiving), and when it waits on something you may not answer,",
|
|
26
23
|
"tell the person. Change sessions the person started (message, stop) only",
|
|
27
|
-
"when the person asked you to.
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"requests, not the person's.",
|
|
24
|
+
"when the person asked you to. To message a working session, steer anything",
|
|
25
|
+
"about its work in progress and queue a separate task for after it, as the",
|
|
26
|
+
"tool offers. Check the reply to see what was sent or queued and whether",
|
|
27
|
+
"you need to send again. End your turn with your report for a busy starter",
|
|
28
|
+
"to receive if it is waiting for you. You cannot act on your own session,",
|
|
29
|
+
"and limits apply to how many sessions you start and how deep they nest: a",
|
|
30
|
+
"refusal says which and what to do. Messages from other agents start with",
|
|
31
|
+
"a line saying so; treat them as a colleague's requests, not the person's.",
|
|
35
32
|
].join(" ");
|
|
36
33
|
|
|
37
34
|
/** Who calls, as the engine fills it at the moment of the call (`HostToolCaller`). */
|
package/src/operator/types.ts
CHANGED
|
@@ -122,7 +122,7 @@ export interface Entry {
|
|
|
122
122
|
lastActivityAt?: number;
|
|
123
123
|
/** Why `error`, when setup failed (a failed turn's error is the view's). */
|
|
124
124
|
error?: string;
|
|
125
|
-
/**
|
|
125
|
+
/** The host's current session state in one line, the same words as SessionView.note. */
|
|
126
126
|
note?: string;
|
|
127
127
|
/** Paths in this session's tool lines are shown relative to this folder. */
|
|
128
128
|
root?: string;
|
|
@@ -135,7 +135,20 @@ export type Cursor = string & { readonly __operatorCursor: true };
|
|
|
135
135
|
|
|
136
136
|
export type TurnOutcome = "running" | "done" | "cancelled" | "failed";
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
interface SteerReceipts {
|
|
139
|
+
/**
|
|
140
|
+
* Receipts keyed by the supplied steerId, on running and ended turns. Give
|
|
141
|
+
* an empty map when no steer has a receipt yet, omit it when unknown.
|
|
142
|
+
* Each receipt is final. Only `read` can appear before the turn ends.
|
|
143
|
+
* The first ended map from turn() is complete: give `queued` for an
|
|
144
|
+
* unread steer kept in the host queue, or `undelivered` without a queue.
|
|
145
|
+
* Queue hosts using turnOf/viewOf replace the fold's `undelivered`
|
|
146
|
+
* in turn(), view rows and lastEnded before notifying onChange.
|
|
147
|
+
*/
|
|
148
|
+
steers?: Readonly<Record<string, "read" | "undelivered" | "queued">>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface ViewTurn extends SteerReceipts {
|
|
139
152
|
turnId: string;
|
|
140
153
|
outcome: TurnOutcome;
|
|
141
154
|
/** Who stopped it, when the host knows (`cancelled`). */
|
|
@@ -158,7 +171,7 @@ export type Waiting =
|
|
|
158
171
|
| { kind: "plan" | "permission"; request: DecisionRequest };
|
|
159
172
|
|
|
160
173
|
/** How a turn ended, by its id, whatever page of the transcript is read. */
|
|
161
|
-
export interface TurnEnded {
|
|
174
|
+
export interface TurnEnded extends SteerReceipts {
|
|
162
175
|
turnId: string;
|
|
163
176
|
outcome: "done" | "cancelled" | "failed";
|
|
164
177
|
/** Who stopped it, when the host knows. */
|
|
@@ -167,12 +180,14 @@ export interface TurnEnded {
|
|
|
167
180
|
|
|
168
181
|
/** One turn, looked up by id. */
|
|
169
182
|
export type TurnFact =
|
|
170
|
-
| { state: "running" }
|
|
183
|
+
| ({ state: "running" } & SteerReceipts)
|
|
171
184
|
| ({ state: "ended" } & Omit<TurnEnded, "turnId">)
|
|
172
185
|
| { state: "unknown" };
|
|
173
186
|
|
|
174
187
|
export interface SessionView {
|
|
175
188
|
status: SessionStatus;
|
|
189
|
+
/** The host's current state line, as on Entry.note (for example, how many tasks wait and why). */
|
|
190
|
+
note?: string;
|
|
176
191
|
/** The running turn's id, if one runs: independent of `turns`' page. */
|
|
177
192
|
running?: string;
|
|
178
193
|
/** The last turn that ended, and how: independent of `turns`' page. */
|
|
@@ -225,6 +240,13 @@ export interface SendInput {
|
|
|
225
240
|
origin: Origin;
|
|
226
241
|
}
|
|
227
242
|
|
|
243
|
+
export interface SteerInput extends Pick<SendInput, "message" | "origin"> {
|
|
244
|
+
/** The turn the host reported running. */
|
|
245
|
+
turnId: string;
|
|
246
|
+
/** Minted for this message and reused when retrying it in the same turn. */
|
|
247
|
+
steerId: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
228
250
|
/**
|
|
229
251
|
* What a cancel did: the turn stopped (it has ended: a host whose stop is
|
|
230
252
|
* asynchronous waits for the end, briefly, before saying so), there was none,
|
|
@@ -235,6 +257,15 @@ export type CancelOutcome = "stopped" | "not_running" | "unconfirmed" | "first_t
|
|
|
235
257
|
|
|
236
258
|
export type ArchiveTarget = { kind: "session"; id: string } | { kind: "workspace"; id: string };
|
|
237
259
|
|
|
260
|
+
/** Whether a new session can run on this agent, as the host last saw it. */
|
|
261
|
+
export interface AgentEntry {
|
|
262
|
+
harness: AgentHarness;
|
|
263
|
+
/** Open: a state this build does not know reads as unknown. */
|
|
264
|
+
state: "ready" | "not_installed" | "signed_out" | "unknown" | (string & {});
|
|
265
|
+
/** The host's words on what to do, or why it could not tell. */
|
|
266
|
+
detail?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
238
269
|
export interface ModelEntry {
|
|
239
270
|
harness: AgentHarness;
|
|
240
271
|
id: string;
|
|
@@ -355,13 +386,41 @@ export interface OperatorHost<Auth = unknown> {
|
|
|
355
386
|
view(caller: Caller<Auth>, sessionId: string, options: ViewOptions): Promise<SessionView>;
|
|
356
387
|
/**
|
|
357
388
|
* Start the turn `input.turnId` now, carrying `origin` to the wire. The
|
|
358
|
-
* same turn id again converges on the first (the engine's rule).
|
|
359
|
-
*
|
|
360
|
-
* `
|
|
361
|
-
*
|
|
362
|
-
* again with the same turn id.
|
|
389
|
+
* same turn id again converges on the first (the engine's rule). Throw
|
|
390
|
+
* `new Refused({ code: "busy" })` for a bare busy. A `busy` with `detail`,
|
|
391
|
+
* `retryAfter`, `state` or `sessions` is a host refusal. An `OperatorError`
|
|
392
|
+
* supplies the host's own refusal. If the outcome is unknown, throw a
|
|
393
|
+
* plain error so the package tries again with the same turn id.
|
|
363
394
|
*/
|
|
364
395
|
send(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<void>;
|
|
396
|
+
/**
|
|
397
|
+
* Pass input.steerId to the engine for exactly input.turnId. A repeat of
|
|
398
|
+
* that id and input converges on the first dispatch, as for send. Report
|
|
399
|
+
* each receipt through turn() once known. It is final, and the first
|
|
400
|
+
* ended map is complete. A host with queue keeps an unread steer as
|
|
401
|
+
* its own turn. Before onChange, replace the fold's `undelivered` with
|
|
402
|
+
* `queued` in turn(), view rows and lastEnded. The host can also answer
|
|
403
|
+
* `queued` here if the named turn cannot take the steer. Without queue,
|
|
404
|
+
* an unread steer ends with its turn.
|
|
405
|
+
* Throw Refused with the host's reason for a definite refusal.
|
|
406
|
+
*/
|
|
407
|
+
steer?(
|
|
408
|
+
caller: Caller<Auth>,
|
|
409
|
+
sessionId: string,
|
|
410
|
+
input: SteerInput,
|
|
411
|
+
): Promise<{
|
|
412
|
+
outcome: "accepted" | "queued" | "no_active_turn" | "unsupported";
|
|
413
|
+
}>;
|
|
414
|
+
/**
|
|
415
|
+
* Take every queue send, even when the session is idle or stopped.
|
|
416
|
+
* If it starts at once, the view names input.turnId in running or,
|
|
417
|
+
* if it has already finished, in lastEnded.turnId.
|
|
418
|
+
* Keep the task as turn input.turnId. A repeated input.turnId converges
|
|
419
|
+
* while the host still knows it. Return its position if known.
|
|
420
|
+
* The host owns delivery and can refuse a full queue with busy or
|
|
421
|
+
* limit_resources. As for send, a lost answer gets one retry.
|
|
422
|
+
*/
|
|
423
|
+
queue?(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<{ position?: number }>;
|
|
365
424
|
/** One turn by id: running, ended (how, and by whom when stopped), or unknown. */
|
|
366
425
|
turn(caller: Caller<Auth>, sessionId: string, turnId: string): Promise<TurnFact>;
|
|
367
426
|
/**
|
|
@@ -410,10 +469,12 @@ export interface OperatorHost<Auth = unknown> {
|
|
|
410
469
|
archive?(caller: Caller<Auth>, target: ArchiveTarget): Promise<{ note?: string }>;
|
|
411
470
|
/** The models a new session can run. Enables `list_models`. */
|
|
412
471
|
models?(caller: Caller<Auth>): Promise<ModelEntry[]>;
|
|
472
|
+
/** The agents this caller can choose, including those without models. Enables `list_models`. */
|
|
473
|
+
agents?(caller: Caller<Auth>): Promise<AgentEntry[]>;
|
|
413
474
|
/**
|
|
414
475
|
* Whether this outside caller may run this tool now, read from the host's
|
|
415
476
|
* store at the call: asked before every tool and again just before every
|
|
416
|
-
* write the package makes (each send, cancel, answer, start, archive). The tool's
|
|
477
|
+
* write the package makes (each send, steer, queue, cancel, answer, start, archive). The tool's
|
|
417
478
|
* name lets a host allow one write tool to a low-access caller.
|
|
418
479
|
*/
|
|
419
480
|
authorize?(
|
|
@@ -426,7 +487,7 @@ export interface OperatorHost<Auth = unknown> {
|
|
|
426
487
|
admit?(caller: Caller<Auth>, request: AdmitRequest): Promise<Refusal | undefined>;
|
|
427
488
|
/** One line of host facts once a turn settles ("changes: a.ts (+4 -0)"). */
|
|
428
489
|
outcome?(caller: Caller<Auth>, entry: Entry): Promise<string | undefined>;
|
|
429
|
-
/** One line `whoami` adds for this caller ("access: read"). */
|
|
490
|
+
/** One line `whoami` adds as a note for this caller ("access: read"). */
|
|
430
491
|
describe?(caller: Caller<Auth>): Promise<string | undefined>;
|
|
431
492
|
}
|
|
432
493
|
|
|
@@ -435,7 +496,11 @@ export interface OperatorHost<Auth = unknown> {
|
|
|
435
496
|
/**
|
|
436
497
|
* A tool the host adds beside the package's. It declares only its effect;
|
|
437
498
|
* the package applies plan mode and `authorize` (with its name) to it and
|
|
438
|
-
* nothing else. It may not
|
|
499
|
+
* nothing else. It may not start, message, stop or archive sessions: those
|
|
500
|
+
* are the package's tools'. It may manage what the host itself holds for
|
|
501
|
+
* a session, such as its queue. A tool that releases, reorders or removes
|
|
502
|
+
* queued work enforces the self and person-session rules itself. It
|
|
503
|
+
* declares `destructive` when it removes tasks.
|
|
439
504
|
*/
|
|
440
505
|
export interface ExtraTool<Auth = unknown> {
|
|
441
506
|
name: string;
|
package/src/operator/view.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
type ConversationElicitation,
|
|
10
|
+
type ConversationMessage,
|
|
10
11
|
type ConversationPermission,
|
|
11
12
|
type ConversationState,
|
|
13
|
+
type ConversationTurn,
|
|
12
14
|
conversationMessages,
|
|
13
15
|
pendingElicitations,
|
|
14
16
|
pendingPermissions,
|
|
@@ -62,14 +64,28 @@ export function viewOf(state: ConversationState): SessionView {
|
|
|
62
64
|
return viewWithFacts(state);
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
function steersOf(turn: ConversationTurn, messages: readonly ConversationMessage[]) {
|
|
68
|
+
const receipts: [string, "read" | "undelivered"][] = [];
|
|
69
|
+
for (const message of messages)
|
|
70
|
+
if (message.role === "user" && message.steerId !== undefined)
|
|
71
|
+
receipts.push([message.steerId, "read"]);
|
|
72
|
+
for (const id of turn.undeliveredSteers ?? []) receipts.push([id, "undelivered"]);
|
|
73
|
+
return Object.fromEntries(receipts);
|
|
74
|
+
}
|
|
75
|
+
|
|
65
76
|
/** One turn of a folded state, by id: the host's `turn`, for a host that folds. */
|
|
66
77
|
export function turnOf(state: ConversationState, turnId: string): TurnFact {
|
|
67
78
|
const turn = state.turns.find((t) => t.turnId === turnId);
|
|
68
79
|
if (!turn) return { state: "unknown" };
|
|
69
|
-
|
|
80
|
+
const steers = steersOf(
|
|
81
|
+
turn,
|
|
82
|
+
conversationMessages(state).filter((m) => m.turnId === turnId),
|
|
83
|
+
);
|
|
84
|
+
if (turn.status === "active") return { state: "running", steers };
|
|
70
85
|
return {
|
|
71
86
|
state: "ended",
|
|
72
87
|
outcome: turn.error ? "failed" : turn.stopReason === "cancelled" ? "cancelled" : "done",
|
|
88
|
+
steers,
|
|
73
89
|
};
|
|
74
90
|
}
|
|
75
91
|
|
|
@@ -88,18 +104,18 @@ function viewWithFacts(state: ConversationState): SessionView {
|
|
|
88
104
|
: turn.stopReason === "cancelled"
|
|
89
105
|
? "cancelled"
|
|
90
106
|
: "done";
|
|
107
|
+
const mine = messages.filter((message) => message.turnId === turn.turnId);
|
|
91
108
|
return {
|
|
92
109
|
turnId: turn.turnId,
|
|
93
110
|
outcome,
|
|
111
|
+
steers: steersOf(turn, mine),
|
|
94
112
|
...(turn.error ? { error: turn.error.message } : {}),
|
|
95
|
-
messages:
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
...(message.origin ? { origin: message.origin } : {}),
|
|
102
|
-
})),
|
|
113
|
+
messages: mine.map((message) => ({
|
|
114
|
+
role: message.role,
|
|
115
|
+
parts: message.parts,
|
|
116
|
+
...(message.parentToolCallId ? { nested: true } : {}),
|
|
117
|
+
...(message.origin ? { origin: message.origin } : {}),
|
|
118
|
+
})),
|
|
103
119
|
startedAt: turn.startedAt,
|
|
104
120
|
...(turn.endedAt !== undefined ? { endedAt: turn.endedAt } : {}),
|
|
105
121
|
};
|
|
@@ -126,6 +142,7 @@ function viewWithFacts(state: ConversationState): SessionView {
|
|
|
126
142
|
lastEnded: {
|
|
127
143
|
turnId: ended.turnId,
|
|
128
144
|
outcome: ended.outcome as "done" | "cancelled" | "failed",
|
|
145
|
+
steers: ended.steers,
|
|
129
146
|
},
|
|
130
147
|
}
|
|
131
148
|
: {}),
|
|
@@ -42,6 +42,8 @@ export const ConversationMessageSchema = z.object({
|
|
|
42
42
|
model: z.string().optional(),
|
|
43
43
|
/** A user message's sender when it is not the person (`message.started`'s `origin`). */
|
|
44
44
|
origin: ReportedOriginSchema.optional(),
|
|
45
|
+
/** A steer's read receipt, from its user message's `message.started`. */
|
|
46
|
+
steerId: z.string().optional(),
|
|
45
47
|
parts: z.array(z.union([PartSchema, UnknownPartSchema])),
|
|
46
48
|
startedAt: EpochMsSchema,
|
|
47
49
|
endedAt: EpochMsSchema.optional(),
|
|
@@ -285,6 +285,8 @@ export const MessageStartedEventSchema = z.object({
|
|
|
285
285
|
* messages and on every assistant message.
|
|
286
286
|
*/
|
|
287
287
|
origin: ReportedOriginSchema.optional(),
|
|
288
|
+
/** On a steer's user echo, the id of the steer the agent read. Absent on older streams. */
|
|
289
|
+
steerId: z.string().optional(),
|
|
288
290
|
...stamped,
|
|
289
291
|
});
|
|
290
292
|
export type MessageStartedEvent = z.infer<typeof MessageStartedEventSchema>;
|
package/src/protocol/reduce.ts
CHANGED
|
@@ -120,6 +120,7 @@ function openMessage(
|
|
|
120
120
|
parentToolCallId?: string;
|
|
121
121
|
model?: string;
|
|
122
122
|
origin?: ReportedOrigin;
|
|
123
|
+
steerId?: string;
|
|
123
124
|
},
|
|
124
125
|
record: ChangeRecorder,
|
|
125
126
|
): ConversationState {
|
|
@@ -142,6 +143,7 @@ function openMessage(
|
|
|
142
143
|
...(init.role === "assistant" && init.model !== undefined && { model: init.model }),
|
|
143
144
|
// Who sent a user message, when not the person; never on the agent's own.
|
|
144
145
|
...(init.role === "user" && init.origin !== undefined && { origin: init.origin }),
|
|
146
|
+
...(init.role === "user" && init.steerId !== undefined && { steerId: init.steerId }),
|
|
145
147
|
parts: [],
|
|
146
148
|
startedAt: init.timestamp,
|
|
147
149
|
};
|