omp-channel 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ and the project uses [Semantic Versioning](https://semver.org) once it reaches 1
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.3.0] - 2026-11-27
9
+
10
+ ### Added
11
+
12
+ - Activity reports: for each tool used for a message, a report when it starts and one when it ends
13
+ (`activity` event, `ChannelAdapter.activity`, `service.paths.activity`,
14
+ `schema/activity.schema.json`). A report carries the tool name and the stated intent, never
15
+ commands, paths, arguments or results. They are sent when the transport takes them;
16
+ `reports.activity: false` turns them off. Oh My Pi asks the model for intents in the interactive
17
+ terminal interface by default, so other modes report mostly tool names.
18
+
19
+ ## [0.2.1] - 2026-11-27
20
+
21
+ ### Fixed
22
+
23
+ - The `reply` tool is now among the tools sent to the model (`loadMode: "essential"`). Before,
24
+ Oh My Pi left it out, so the model could not answer and the message waited for ever.
25
+ - No message is left waiting. A run that ends without a `reply` call sends the final text of the
26
+ model as the reply (`replies.fromFinalText`, on by default), with secrets hidden. A stopped
27
+ turn, a closed or switched session and an answer the service refuses are reported as a
28
+ `failure`. Refused calls are tried again.
29
+
30
+ ### Changed
31
+
32
+ - An aborted turn is now reported as a `failure`.
33
+
8
34
  ## [0.2.0] - 2026-11-27
9
35
 
10
36
  ### Added
package/README.md CHANGED
@@ -17,7 +17,7 @@ it work and receive the answers, including while the agent is busy. It is **not*
17
17
  service, it contains **no models**, and it does **not** manage accounts. You provide the service
18
18
  and the model; omp-channel is the link between them.
19
19
 
20
- > **Status: alpha, version 0.2.0 on npm.** The behaviour is covered by automated tests that use fakes and
20
+ > **Status: alpha, version 0.3.0 on npm.** The behaviour is covered by automated tests that use fakes and
21
21
  > a loopback HTTP service. Startup, delivery to an idle session, queueing during a turn and abort
22
22
  > have passed in a live Oh My Pi session; the status report and the attribution values are not yet
23
23
  > verified. See
@@ -44,7 +44,8 @@ and the model; omp-channel is the link between them.
44
44
  the agent is busy. The text is marked as data from an outside party.
45
45
  3. The agent answers with the `reply` tool, using the `messageId` of the message. omp-channel posts
46
46
  the reply to the service.
47
- 4. While a turn runs, omp-channel reports `working` to the service; when the turn ends, `free`.
47
+ 4. While a turn runs, omp-channel reports `working` to the service; when the turn ends, `free`. A
48
+ service that takes activity reports also learns which tools the agent is using.
48
49
  5. Delivery is at least once with acknowledgements, so a message is neither lost nor handled
49
50
  twice when the extension restarts. Details are in [docs/protocol.md](docs/protocol.md).
50
51
 
@@ -214,6 +215,7 @@ the extension and writes the reason (with its path) to stderr.
214
215
  | `service.keyEnv` | `"OMP_CHANNEL_KEY"` | Environment variable holding the key (`<keyEnv>_FILE` for a file). Required with `service.url`. |
215
216
  | `service.requestTimeoutMs` | `10000` | Timeout of each request. |
216
217
  | `service.paths.*` | `/messages`, `/messages/ack`, `/replies`, `/status`, `/failures` | Endpoint paths. |
218
+ | `service.paths.activity` | none | Where activity reports are posted. Without it none are sent over HTTP. |
217
219
  | `poll.intervalMs` | `2000` | Wait between polls when the queue is empty. |
218
220
  | `poll.maxBackoffMs` | `30000` | Longest wait after failed polls. |
219
221
  | `poll.batchSize` | `10` | Deliveries requested per poll. |
@@ -222,6 +224,8 @@ the extension and writes the reason (with its path) to stderr.
222
224
  | `limits.maxPending` | `5` | Events waiting to be admitted; more are dropped and not acknowledged. |
223
225
  | `delivery.deliverAs` | `"followUp"` | How a message is queued in Oh My Pi: `steer`, `followUp` or `aside`. |
224
226
  | `failures.includeReason` | `true` | Send the cleaned error text when a turn fails and leaves a message unanswered. |
227
+ | `replies.fromFinalText` | `true` | Send the cleaned final text of the model as the reply when it did not use the `reply` tool. |
228
+ | `reports.activity` | `true` | Report the tools used for a message, when the transport takes it (docs/protocol.md 10). |
225
229
  | `adapterModule` | none | Path to a module that exports a `ChannelAdapter`. Replaces the HTTP transport. |
226
230
 
227
231
  Environment variables:
@@ -245,15 +249,19 @@ Environment variables:
245
249
  addresses, for local tests.
246
250
  - **Replies are limited.** The `reply` tool accepts only a `messageId` that was delivered in the
247
251
  current session.
252
+ - **Activity says little.** An activity report holds the tool name and the stated intent, never
253
+ commands, arguments or results as such. Secrets, paths, addresses and quoted argument values are
254
+ taken out of the intent; it is still text written by the model. See
255
+ [docs/protocol.md](docs/protocol.md), section 10, or set `reports.activity: false`.
248
256
  - **Error text is cleaned.** When a turn fails, the error from the model provider is sent with
249
257
  known secret shapes and the home folder name hidden. `failures.includeReason: false` keeps it on
250
258
  the machine.
251
259
 
252
- ## When a turn fails
260
+ ## No message is left waiting
253
261
 
254
- If the model request fails (the model is not loaded, the key is refused, the service is down) the
255
- service receives a `failure` report for each message that got no answer, so the person is not left
256
- waiting. Oh My Pi retries some errors first; the report is sent only when it gives up. See
262
+ If the model answers at the terminal without calling `reply`, its final text is sent as the reply.
263
+ If there is no answer to send (a model error, a stopped turn, a closed session) the service
264
+ receives a `failure` report with the reason. All cases are listed in
257
265
  [docs/protocol.md](docs/protocol.md), section 9.
258
266
 
259
267
  Report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
@@ -273,6 +281,8 @@ Report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
273
281
  - **Verified in a live Oh My Pi session (19.2.1, local model):** startup, delivery of a pushed
274
282
  message to an idle session, a message pushed during a turn (taken at a turn boundary, see
275
283
  [docs/protocol.md](docs/protocol.md) section 3.5), abort, and the report of a refused model request.
284
+ - **Activity reports** were checked in a live session in RPC mode with a scripted model; not yet
285
+ with a real model or in the terminal interface.
276
286
  - **Not verified yet:** the status report (`working`/`free`) to a service, and the effect of each
277
287
  `attribution` value. See [docs/omp-verification.md](docs/omp-verification.md).
278
288
  - `npm ci` also installs the Oh My Pi package for type checking; it is large.
@@ -0,0 +1,48 @@
1
+ import { type OutboundActivity } from "./protocol.js";
2
+ /** Tool uses reported for one message. */
3
+ export declare const MAX_ACTIVITIES_PER_MESSAGE = 200;
4
+ /** Reports waiting to be sent, the one in flight included. More are dropped. */
5
+ export declare const MAX_WAITING_REPORTS = 100;
6
+ /** How long one report may take before the next one is sent. */
7
+ export declare const REPORT_TIMEOUT_MS = 5000;
8
+ /** How long a reply or a failure report waits for the reports that come before it. */
9
+ export declare const FLUSH_TIMEOUT_MS = 1000;
10
+ /** The start of a tool use, as Oh My Pi announces it. */
11
+ export interface ToolStart {
12
+ readonly toolCallId: string;
13
+ readonly toolName: string;
14
+ readonly intent?: string | undefined;
15
+ readonly args?: unknown;
16
+ }
17
+ export interface ToolEnd {
18
+ readonly toolCallId: string;
19
+ readonly isError?: boolean | undefined;
20
+ }
21
+ export interface ActivityOptions {
22
+ readonly send: (activity: OutboundActivity) => Promise<void>;
23
+ /** The conversation of a message that has no reply or report yet, undefined otherwise. */
24
+ readonly conversationOfOpen: (messageId: string) => string | undefined;
25
+ /** Tools whose use is not reported. */
26
+ readonly ignored: ReadonlySet<string>;
27
+ readonly log: (line: string) => void;
28
+ readonly now?: (() => Date) | undefined;
29
+ readonly newId?: (() => string) | undefined;
30
+ }
31
+ /**
32
+ * Tells the service which tools the agent uses for its messages (docs/protocol.md, "Activity").
33
+ * The work belongs to the newest open message of the last prompt that carried one. Nothing is said
34
+ * about work for a prompt typed at the terminal. Reports leave one at a time, in order, and never
35
+ * hold the agent back.
36
+ */
37
+ export declare class ActivityReports {
38
+ #private;
39
+ constructor(options: ActivityOptions);
40
+ /** A message entered the session. */
41
+ heard(message: unknown): void;
42
+ started(tool: ToolStart): void;
43
+ ended(tool: ToolEnd): void;
44
+ /** The session goes to another conversation of its own. */
45
+ reset(): void;
46
+ /** Resolves when the reports made so far have left, or after a short wait. */
47
+ flush(): Promise<void> | undefined;
48
+ }
@@ -0,0 +1,155 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { buildActivity, messageIdsIn } from "./protocol.js";
3
+ import { activityText } from "./redact.js";
4
+ import { textsOf } from "./turn.js";
5
+ /** Tool uses reported for one message. */
6
+ export const MAX_ACTIVITIES_PER_MESSAGE = 200;
7
+ /** Reports waiting to be sent, the one in flight included. More are dropped. */
8
+ export const MAX_WAITING_REPORTS = 100;
9
+ /** How long one report may take before the next one is sent. */
10
+ export const REPORT_TIMEOUT_MS = 5_000;
11
+ /** How long a reply or a failure report waits for the reports that come before it. */
12
+ export const FLUSH_TIMEOUT_MS = 1_000;
13
+ const MAX_REMEMBERED = 1000;
14
+ /**
15
+ * Tells the service which tools the agent uses for its messages (docs/protocol.md, "Activity").
16
+ * The work belongs to the newest open message of the last prompt that carried one. Nothing is said
17
+ * about work for a prompt typed at the terminal. Reports leave one at a time, in order, and never
18
+ * hold the agent back.
19
+ */
20
+ export class ActivityReports {
21
+ #options;
22
+ /** Message ids the agent has taken and may be working on, oldest first. */
23
+ #messages = [];
24
+ #uses = new Map();
25
+ #counts = new Map();
26
+ #queue = Promise.resolve();
27
+ #waiting = 0;
28
+ #refused = false;
29
+ #dropped = false;
30
+ constructor(options) {
31
+ this.#options = options;
32
+ }
33
+ /** A message entered the session. */
34
+ heard(message) {
35
+ if (typeof message !== "object" || message === null) {
36
+ return;
37
+ }
38
+ const { role, content, synthetic } = message;
39
+ if (role !== "user" && role !== "developer") {
40
+ return;
41
+ }
42
+ const ids = textsOf(content).flatMap(messageIdsIn);
43
+ if (ids.length > 0) {
44
+ const kept = this.#messages.filter((id) => !ids.includes(id));
45
+ this.#messages = [...kept, ...ids].slice(-MAX_REMEMBERED);
46
+ }
47
+ else if (role === "user" && synthetic !== true) {
48
+ // A person typed at the terminal: what follows is not for the service.
49
+ this.#messages = [];
50
+ }
51
+ }
52
+ started(tool) {
53
+ if (this.#options.ignored.has(tool.toolName)) {
54
+ return;
55
+ }
56
+ const replyTo = [...this.#messages]
57
+ .reverse()
58
+ .find((id) => this.#options.conversationOfOpen(id) !== undefined);
59
+ const conversationId = replyTo === undefined ? undefined : this.#options.conversationOfOpen(replyTo);
60
+ if (replyTo === undefined || conversationId === undefined) {
61
+ return;
62
+ }
63
+ const count = this.#counts.get(replyTo) ?? 0;
64
+ if (count >= MAX_ACTIVITIES_PER_MESSAGE) {
65
+ return;
66
+ }
67
+ remember(this.#counts, replyTo, count + 1);
68
+ const use = {
69
+ conversationId,
70
+ replyTo,
71
+ activityId: this.#newId(),
72
+ text: activityText(tool.toolName, tool.intent, tool.args),
73
+ };
74
+ remember(this.#uses, tool.toolCallId, use);
75
+ this.#report(use, "running");
76
+ }
77
+ ended(tool) {
78
+ const use = this.#uses.get(tool.toolCallId);
79
+ this.#uses.delete(tool.toolCallId);
80
+ // After the reply or the failure report there is nothing left to say about the message.
81
+ if (use !== undefined && this.#options.conversationOfOpen(use.replyTo) !== undefined) {
82
+ this.#report(use, tool.isError === true ? "failed" : "done");
83
+ }
84
+ }
85
+ /** The session goes to another conversation of its own. */
86
+ reset() {
87
+ this.#messages = [];
88
+ this.#uses.clear();
89
+ }
90
+ /** Resolves when the reports made so far have left, or after a short wait. */
91
+ flush() {
92
+ return this.#waiting === 0 ? undefined : within(this.#queue, FLUSH_TIMEOUT_MS).catch(() => { });
93
+ }
94
+ #report(use, state) {
95
+ if (this.#waiting >= MAX_WAITING_REPORTS) {
96
+ if (!this.#dropped) {
97
+ this.#options.log("activity reports are dropped: the service is too slow");
98
+ }
99
+ this.#dropped = true;
100
+ return;
101
+ }
102
+ const activity = buildActivity(use.conversationId, use.replyTo, { activityId: use.activityId, state, text: use.text }, { messageId: this.#newId(), at: this.#options.now?.() ?? new Date() });
103
+ this.#waiting += 1;
104
+ this.#queue = this.#queue.then(() => this.#deliver(activity));
105
+ }
106
+ /** One attempt. A refusal is logged once until a report is accepted again. */
107
+ async #deliver(activity) {
108
+ try {
109
+ await within(this.#options.send(activity), REPORT_TIMEOUT_MS);
110
+ this.#refused = false;
111
+ this.#dropped = false;
112
+ }
113
+ catch (error) {
114
+ if (!this.#refused) {
115
+ const name = error instanceof Error ? error.name : "unknown";
116
+ this.#options.log(`activity was not reported (${name})`);
117
+ }
118
+ this.#refused = true;
119
+ }
120
+ finally {
121
+ this.#waiting -= 1;
122
+ }
123
+ }
124
+ #newId() {
125
+ return this.#options.newId?.() ?? randomUUID();
126
+ }
127
+ }
128
+ /** The promise, or a rejection after `ms`. */
129
+ async function within(promise, ms) {
130
+ let timer;
131
+ const late = new Promise((_resolve, reject) => {
132
+ timer = setTimeout(() => {
133
+ const error = new Error("no answer in time");
134
+ error.name = "TimeoutError";
135
+ reject(error);
136
+ }, ms);
137
+ });
138
+ try {
139
+ await Promise.race([promise, late]);
140
+ }
141
+ finally {
142
+ clearTimeout(timer);
143
+ }
144
+ }
145
+ /** Adds to a map that keeps only the newest entries. */
146
+ function remember(map, key, value) {
147
+ map.set(key, value);
148
+ if (map.size > MAX_REMEMBERED) {
149
+ const oldest = map.keys().next();
150
+ if (oldest.value !== undefined) {
151
+ map.delete(oldest.value);
152
+ }
153
+ }
154
+ }
155
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.js","sourceRoot":"","sources":["../src/activity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAyB,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,gFAAgF;AAChF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAEtC,MAAM,cAAc,GAAG,IAAI,CAAC;AAiC5B;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACjB,QAAQ,CAAkB;IACnC,2EAA2E;IAC3E,SAAS,GAAa,EAAE,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AAE,MAAM,EAAE,EAAE;QACnD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC7C,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;YAC5B,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,wDAAwD;AACxD,SAAS,QAAQ,CAAI,GAAmB,EAAE,GAAW,EAAE,KAAQ;IAC7D,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,IAAI,GAAG,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/adapter.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { InboundEvent, OutboundFailure, OutboundReply, OutboundStatus } from "./protocol.js";
1
+ import type { InboundEvent, OutboundActivity, OutboundFailure, OutboundReply, OutboundStatus } from "./protocol.js";
2
2
  /** One event from a service, with the lease id that the service uses for acknowledgement. */
3
3
  export interface Delivery {
4
4
  /** Present when the transport leases deliveries (the HTTP transport does). */
@@ -26,6 +26,11 @@ export interface ChannelAdapter {
26
26
  * service learns nothing and the message stays unanswered. Throws when it is not accepted.
27
27
  */
28
28
  failure?(failure: OutboundFailure): Promise<void>;
29
+ /**
30
+ * Reports a tool the agent is using for a message, or how that use ended. Best effort: a report
31
+ * that is refused is logged and not sent again. Without it no activity is collected.
32
+ */
33
+ activity?(activity: OutboundActivity): Promise<void>;
29
34
  /** Tells the service that an interrupt was applied. Optional. */
30
35
  interrupt?(conversationId: string): Promise<void>;
31
36
  /** Tells the service that a conversation was closed on the agent side. Optional. */
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAyCA,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAgC,CAAC;IACnD,OAAO,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF"}
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAoDA,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAgC,CAAC;IACnD,OAAO,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF"}
package/dist/config.d.ts CHANGED
@@ -23,6 +23,14 @@ export interface FailuresConfig {
23
23
  /** Whether the cleaned error text is sent with a failure report. */
24
24
  readonly includeReason: boolean;
25
25
  }
26
+ export interface RepliesConfig {
27
+ /** Send the final text of the model as the reply when it did not use the reply tool. */
28
+ readonly fromFinalText: boolean;
29
+ }
30
+ export interface ReportsConfig {
31
+ /** Tell the service which tools the agent uses for a message, when the adapter takes it. */
32
+ readonly activity: boolean;
33
+ }
26
34
  export interface ChannelConfig {
27
35
  readonly mcpServer: string;
28
36
  readonly service: ServiceConfig | undefined;
@@ -33,6 +41,8 @@ export interface ChannelConfig {
33
41
  };
34
42
  readonly delivery: DeliveryConfig;
35
43
  readonly failures: FailuresConfig;
44
+ readonly replies: RepliesConfig;
45
+ readonly reports: ReportsConfig;
36
46
  }
37
47
  export interface ConfigSources {
38
48
  readonly env: Readonly<Record<string, string | undefined>>;
@@ -52,6 +62,8 @@ interface ServicePaths {
52
62
  replies: string;
53
63
  status: string;
54
64
  failures: string;
65
+ /** No default: without it no activity is sent over HTTP. */
66
+ activity?: string;
55
67
  }
56
68
  /** https is required. Plain http is accepted only for loopback, and credentials are refused. */
57
69
  export declare function parseServiceUrl(raw: string): URL;
package/dist/config.js CHANGED
@@ -51,6 +51,8 @@ export function loadConfig(sources) {
51
51
  limits: parsed.limits,
52
52
  delivery: parsed.delivery,
53
53
  failures: parsed.failures,
54
+ replies: parsed.replies,
55
+ reports: parsed.reports,
54
56
  };
55
57
  }
56
58
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAoB,MAAM,kBAAkB,CAAC;AAG7D,MAAM,CAAC,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AAC,CAAC;AAChF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAyB;IACzC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC"}
@@ -2,6 +2,7 @@ import { type ChannelAdapter } from "./adapter.js";
2
2
  import type { ChannelConfig } from "./config.js";
3
3
  import type { SendUserMessageOptions } from "@oh-my-pi/pi-coding-agent/session/agent-session-types";
4
4
  import { type AgentStatus, type InboundEvent } from "./protocol.js";
5
+ import { type Segment } from "./turn.js";
5
6
  /** What happened to an inbound event. The outcomes marked as acknowledged may be acked. */
6
7
  export type AdmitOutcome = "admitted" | "duplicate" | "ignored" | "refused" | "rejected" | "dropped";
7
8
  export declare const ACKNOWLEDGED_OUTCOMES: ReadonlySet<AdmitOutcome>;
@@ -18,6 +19,13 @@ export interface DispatcherOptions {
18
19
  readonly log: (line: string) => void;
19
20
  readonly now?: () => Date;
20
21
  readonly newId?: () => string;
22
+ /** Waits between two attempts to deliver (tests replace it). */
23
+ readonly wait?: (ms: number) => Promise<void>;
24
+ /**
25
+ * Called before a reply or a failure report leaves: what must reach the service first. Undefined
26
+ * when there is nothing to wait for. It must settle on its own in a short time.
27
+ */
28
+ readonly beforeOutcome?: () => Promise<void> | undefined;
21
29
  }
22
30
  export type ReplyResult = {
23
31
  ok: true;
@@ -25,6 +33,11 @@ export type ReplyResult = {
25
33
  ok: false;
26
34
  reason: string;
27
35
  };
36
+ /** The reply a message gets when the answer to a later one covers it. */
37
+ export declare const ANSWERED_LATER_TEXT = "Answered together with a later message.";
38
+ export declare const UNDELIVERED_REASON = "The agent answered, but the answer could not be delivered";
39
+ export declare const CLOSED_REASON = "The agent was closed before it answered";
40
+ export declare const SWITCHED_REASON = "The agent moved to another session before it answered";
28
41
  /**
29
42
  * Applies inbound events to the agent session, one at a time and in arrival order.
30
43
  *
@@ -34,20 +47,28 @@ export type ReplyResult = {
34
47
  * without running again.
35
48
  * - Interrupt stops the current turn only. Tool results already produced stay in the session.
36
49
  * - Agent state is reported to the service for the open conversation.
37
- * - A message that a failed turn left unanswered is reported once.
50
+ * - A message is never left waiting: when a run ends, or the session goes away, every message
51
+ * without a reply gets the final answer of the model, a note, or a failure report.
38
52
  */
39
53
  export declare class Dispatcher {
40
54
  #private;
41
55
  constructor(options: DispatcherOptions);
42
56
  get activeConversation(): string | undefined;
57
+ /** The conversation of a message that has no reply or report yet, undefined otherwise. */
58
+ conversationOfOpen(messageId: string): string | undefined;
43
59
  submit(event: InboundEvent, deliveryId?: string): Promise<AdmitOutcome>;
44
60
  /** Reports the agent state for the open conversation. Best effort: errors are logged. */
45
61
  setStatus(status: AgentStatus): void;
46
62
  reply(messageId: string, text: string): Promise<ReplyResult>;
47
63
  /**
48
- * Tells the service that a failed turn left these messages unanswered. Messages that were not
49
- * admitted here, already answered or already reported are skipped. Best effort: a report that
50
- * is refused is logged, and a later failure of the same message tries again.
64
+ * Closes what a finished run left open. For each message without a reply or a report: the final
65
+ * text of the model as its reply (when the run completed with one), a note when a later message
66
+ * got the answer, or a failure report. Refused calls are tried again, and a message that could
67
+ * not be closed stays open for the end of the next run.
51
68
  */
52
- reportFailure(messageIds: readonly string[], reason: string | undefined): Promise<void>;
69
+ settle(segments: readonly Segment[]): Promise<void>;
70
+ /** The session goes away: every open message is reported, with one attempt. */
71
+ abandon(reason: string): Promise<void>;
72
+ /** True while some admitted message has neither a reply nor a report. */
73
+ get hasOpenMessages(): boolean;
53
74
  }