@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/core/runtime/event-processor.js +9 -10
  3. package/dist/operator/errors.js +9 -2
  4. package/dist/operator/index.js +1 -1
  5. package/dist/operator/operator.js +382 -145
  6. package/dist/operator/render.js +28 -10
  7. package/dist/operator/session-tools.js +9 -12
  8. package/dist/operator/view.js +16 -4
  9. package/dist/protocol/conversation.js +2 -0
  10. package/dist/protocol/lifecycle.js +2 -0
  11. package/dist/protocol/reduce.js +1 -0
  12. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  13. package/dist/types/operator/errors.d.ts +3 -1
  14. package/dist/types/operator/errors.d.ts.map +1 -1
  15. package/dist/types/operator/index.d.ts +1 -1
  16. package/dist/types/operator/index.d.ts.map +1 -1
  17. package/dist/types/operator/operator.d.ts.map +1 -1
  18. package/dist/types/operator/render.d.ts +2 -0
  19. package/dist/types/operator/render.d.ts.map +1 -1
  20. package/dist/types/operator/session-tools.d.ts +1 -4
  21. package/dist/types/operator/session-tools.d.ts.map +1 -1
  22. package/dist/types/operator/types.d.ts +73 -13
  23. package/dist/types/operator/types.d.ts.map +1 -1
  24. package/dist/types/operator/view.d.ts.map +1 -1
  25. package/dist/types/protocol/conversation.d.ts +3 -0
  26. package/dist/types/protocol/conversation.d.ts.map +1 -1
  27. package/dist/types/protocol/lifecycle.d.ts +2 -0
  28. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  29. package/dist/types/protocol/reduce.d.ts.map +1 -1
  30. package/dist/types/protocol/wire-api.d.ts +1 -0
  31. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  32. package/dist/types/protocol/wire.d.ts +2 -0
  33. package/dist/types/protocol/wire.d.ts.map +1 -1
  34. package/docs/consuming.md +55 -13
  35. package/package.json +1 -1
  36. package/src/core/runtime/event-processor.ts +14 -9
  37. package/src/operator/errors.ts +12 -4
  38. package/src/operator/index.ts +1 -1
  39. package/src/operator/operator.ts +489 -146
  40. package/src/operator/render.ts +29 -8
  41. package/src/operator/session-tools.ts +9 -12
  42. package/src/operator/types.ts +77 -12
  43. package/src/operator/view.ts +26 -9
  44. package/src/protocol/conversation.ts +2 -0
  45. package/src/protocol/lifecycle.ts +2 -0
  46. package/src/protocol/reduce.ts +2 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,42 @@ and the measurements. Evidence lives in the LLP, not here. A release groups
7
7
  its bullets under Breaking, Added, Changed and Fixed, breaking first. The
8
8
  released sections below that predate this convention are kept as written.
9
9
 
10
+ ## 0.3.31
11
+
12
+ ### Breaking
13
+
14
+ - `send_message` defaults to `steer` where offered and to `queue` elsewhere. Replace
15
+ `when: "idle"` with `when: "queue"`. On a host without `steer`, only the name changes;
16
+ a caller that sends `idle` is refused `invalid_input` (LLP 0019).
17
+
18
+ ### Added
19
+
20
+ - `OperatorHost.steer` takes `SteerInput` and answers `accepted`, `queued`, `no_active_turn`
21
+ or `unsupported`. Senders learn whether their message was read, is pending, was kept in
22
+ the queue, or never reached the agent (LLP 0019).
23
+ - `OperatorHost.queue` takes a separate task even when the session is idle or stopped.
24
+ A host with `queue` must keep unread steers as separate tasks and report `queued` in
25
+ the first ended turn facts (LLP 0019).
26
+ - `message.started.steerId` survives the fold as `ConversationMessage.steerId`. The
27
+ `steers` map on `ViewTurn`, `TurnEnded` and `TurnFact` carries receipts by id.
28
+ `viewOf` and `turnOf` give the fold's `read` and `undelivered` ids (LLP 0002, LLP 0019).
29
+ - `OperatorHost.agents` supplies `AgentEntry` readiness and detail for `list_models`.
30
+ Agents with an empty model list are shown too (LLP 0019).
31
+ - Host tools can import `json` from `@zvada/agent-server/operator` to render values
32
+ losslessly on one line (LLP 0014, LLP 0019).
33
+
34
+ ### Changed
35
+
36
+ - `send_message` and `OPERATOR_GUIDANCE` explain when to steer and when to queue.
37
+ A queue send that starts at once follows its own turn. Refused sends retain the
38
+ host's reason (LLP 0019).
39
+ - `SessionView.note` carries the same state as `Entry.note` into reads, waits and send
40
+ replies. Standalone `describe` and `outcome` lines also begin with `note: ` (LLP 0019).
41
+ - Reads and waits report how many messages sent into a turn were never read. Steers
42
+ kept in the host's queue do not count (LLP 0019).
43
+ - If one `list_models` source fails, the other source's rows remain and the failed
44
+ read is reported once after them (LLP 0019).
45
+
10
46
  ## 0.3.30
11
47
 
12
48
  ### Fixed
@@ -82,7 +82,7 @@ export class EventProcessor {
82
82
  * whole echo instead of reconciling a look-alike against it.
83
83
  */
84
84
  *echoUserMessage(input, origin) {
85
- yield* this.openMessage("user", undefined, echoMessageId(this.turnId), undefined, origin);
85
+ yield* this.openMessage("user", undefined, { id: echoMessageId(this.turnId), origin });
86
86
  for (const part of createUserEchoParts(input, this.turnId)) {
87
87
  yield* this.emitPart(part);
88
88
  }
@@ -99,7 +99,11 @@ export class EventProcessor {
99
99
  const steer = this.steers.read(steerId);
100
100
  if (steer === undefined)
101
101
  return;
102
- yield* this.openMessage("user", undefined, steerMessageId(steerId), undefined, steer.origin);
102
+ yield* this.openMessage("user", undefined, {
103
+ id: steerMessageId(steerId),
104
+ steerId,
105
+ origin: steer.origin,
106
+ });
103
107
  for (const part of createSteerEchoParts(steer.input, steerId)) {
104
108
  yield* this.emitPart(part);
105
109
  }
@@ -115,7 +119,7 @@ export class EventProcessor {
115
119
  // sub-agent's output cut in), are this model's too.
116
120
  if (ev.role === "assistant" && ev.model)
117
121
  this.writtenBy.set("", ev.model);
118
- yield* this.openMessage(ev.role, undefined, undefined, ev.model);
122
+ yield* this.openMessage(ev.role, undefined, { model: ev.model });
119
123
  return;
120
124
  case "model": {
121
125
  const scope = ev.parentToolCallId ?? "";
@@ -254,13 +258,7 @@ export class EventProcessor {
254
258
  return { events, ended };
255
259
  }
256
260
  /** Opens a message, closing any open one first; returns its id. */
257
- *openMessage(role, parentToolCallId,
258
- /** Derived id for the user echo; harness messages get a fresh UUIDv7. */
259
- id,
260
- /** The model the harness said produced it. */
261
- model,
262
- /** A user message's sender, when not the person. */
263
- origin) {
261
+ *openMessage(role, parentToolCallId, { id, model, origin, steerId, } = {}) {
264
262
  if (this.openMessageId)
265
263
  yield* this.closeMessage();
266
264
  if (role === "assistant")
@@ -293,6 +291,7 @@ export class EventProcessor {
293
291
  ...named,
294
292
  // A copy: what a sink does to the event never reaches the request or the model's line.
295
293
  ...(role === "user" && sender && { origin: { ...sender } }),
294
+ ...(steerId !== undefined && { steerId }),
296
295
  timestamp: startedAt,
297
296
  };
298
297
  return messageId;
@@ -4,7 +4,7 @@
4
4
  * words, then the next call, which names only a tool that is installed.
5
5
  */
6
6
  // @ref LLP 0019#errors — one sentence per code, and a next call that exists
7
- import { json } from "./render.js";
7
+ import { json, oneLine } from "./render.js";
8
8
  /**
9
9
  * A host's refusal at its own commit (`start`, `archive`, `send`): the code
10
10
  * and the sessions it is about, by id; the package words it as its own
@@ -48,6 +48,13 @@ export class OperatorError extends Error {
48
48
  }
49
49
  }
50
50
  const NOTHING = "Nothing was done.";
51
+ const NO_ACCESS = `You may not do this here. ${NOTHING}`;
52
+ /** A host may refuse one read while another source still supplies rows. */
53
+ export function readRefusal({ code, detail, retryAfter }) {
54
+ const why = code === "access" ? NO_ACCESS : "The host refused this read.";
55
+ const retry = retryAfter === undefined ? "" : ` Try again in ${retryAfter}s.`;
56
+ return new OperatorError(code, why + retry, { detail: oneLine(detail ?? ""), retryAfter });
57
+ }
51
58
  /** Every value a refusal names: one JSON line, nothing raw (a repository's name, a setup's error). */
52
59
  const q = (text) => json(text);
53
60
  const list = (refs) => refs.map(q).join(", ") || "(none)";
@@ -64,7 +71,7 @@ export const refuse = {
64
71
  }),
65
72
  self: (what) => new OperatorError("self", `That is your own ${what}: a session cannot send to, stop, answer or archive itself. ${NOTHING}`),
66
73
  readOnly: () => new OperatorError("read_only", `You are in plan mode, so you may only list, read and wait. ${NOTHING} Put this step in your plan.`),
67
- access: (detail) => new OperatorError("access", `You may not do this here. ${NOTHING}`, { detail }),
74
+ access: (detail) => new OperatorError("access", NO_ACCESS, { detail }),
68
75
  notYoursArchive: (ref, busy) => new OperatorError("not_yours", `${q(ref)} has sessions you did not start working or waiting (${list(busy)}). Nothing was archived. Ask the person.`),
69
76
  notYoursAnswer: (ref) => new OperatorError("not_yours", `${q(ref)} was not started by you or a session you started, so its answer is the person's. Nothing was sent. Tell the person what it waits on.`),
70
77
  notYoursPermission: () => new OperatorError("not_yours", "Only a session with full access answers a permission. Nothing was sent. Tell the person."),
@@ -10,6 +10,6 @@ export { createMcpHandler, } from "./mcp.js";
10
10
  export { DEFAULT_LIMITS, DEFAULT_WAITS, createOperator, tool } from "./operator.js";
11
11
  export { refOf } from "./refs.js";
12
12
  export { OPERATOR_GUIDANCE, operatorSessionTools, } from "./session-tools.js";
13
- export { callHint, oneLine, quote, quoted } from "./render.js";
13
+ export { callHint, json, oneLine, quote, quoted } from "./render.js";
14
14
  export * from "./types.js";
15
15
  export { settledStatus, turnOf, viewOf, waitingOf, } from "./view.js";