omp-channel 0.1.0 → 0.2.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 +16 -0
- package/README.md +43 -33
- package/dist/adapter.d.ts +6 -1
- package/dist/adapter.js.map +1 -1
- package/dist/config.d.ts +14 -6
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/dispatcher.d.ts +7 -0
- package/dist/dispatcher.js +52 -1
- package/dist/dispatcher.js.map +1 -1
- package/dist/extension.d.ts +2 -1
- package/dist/extension.js +12 -2
- package/dist/extension.js.map +1 -1
- package/dist/http-adapter.d.ts +2 -1
- package/dist/http-adapter.js +5 -1
- package/dist/http-adapter.js.map +1 -1
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +15 -0
- package/dist/protocol.js.map +1 -1
- package/dist/redact.d.ts +11 -0
- package/dist/redact.js +65 -0
- package/dist/redact.js.map +1 -0
- package/dist/turn.d.ts +24 -0
- package/dist/turn.js +60 -0
- package/dist/turn.js.map +1 -0
- package/docs/protocol.md +60 -9
- package/package.json +3 -3
- package/schema/config.schema.json +18 -0
- package/schema/failure.schema.json +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ and the project uses [Semantic Versioning](https://semver.org) once it reaches 1
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.2.0] - 2026-11-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Failed turn report: when a run ends in a model error, each message it left unanswered is
|
|
13
|
+
reported to the service (`failure` event, `ChannelAdapter.failure`, `service.paths.failures`,
|
|
14
|
+
`schema/failure.schema.json`). `failures.includeReason` controls the error text, which is
|
|
15
|
+
cleaned of known secret shapes.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- The state stays `working` while Oh My Pi retries a request, instead of turning `free` between
|
|
20
|
+
attempts.
|
|
21
|
+
|
|
22
|
+
## [0.1.0] - 2026-11-27
|
|
23
|
+
|
|
8
24
|
### Changed
|
|
9
25
|
|
|
10
26
|
- Configuration errors name the unknown key, the allowed keys or values, and the allowed range.
|
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# omp-channel
|
|
2
2
|
|
|
3
3
|
[](https://github.com/tommasomarchionni/omp-channel/actions/workflows/ci.yml)
|
|
4
|
+
|
|
4
5
|
[](LICENSE)
|
|
5
6
|

|
|
6
7
|
|
|
8
|
+
Documentation: <https://tommasomarchionni.github.io/omp-channel/>
|
|
9
|
+
|
|
7
10
|
**omp-channel** is an extension for [Oh My Pi](https://github.com/can1357/oh-my-pi) (OMP), a
|
|
8
11
|
terminal agent harness. It delivers messages from an external service (any system that exchanges messages
|
|
9
12
|
with a person) into an agent session, and sends the agent's replies
|
|
@@ -14,7 +17,7 @@ it work and receive the answers, including while the agent is busy. It is **not*
|
|
|
14
17
|
service, it contains **no models**, and it does **not** manage accounts. You provide the service
|
|
15
18
|
and the model; omp-channel is the link between them.
|
|
16
19
|
|
|
17
|
-
> **Status: alpha,
|
|
20
|
+
> **Status: alpha, version 0.2.0 on npm.** The behaviour is covered by automated tests that use fakes and
|
|
18
21
|
> a loopback HTTP service. Startup, delivery to an idle session, queueing during a turn and abort
|
|
19
22
|
> have passed in a live Oh My Pi session; the status report and the attribution values are not yet
|
|
20
23
|
> verified. See
|
|
@@ -50,18 +53,20 @@ until the open one is closed.
|
|
|
50
53
|
|
|
51
54
|
## Connect a service in three steps
|
|
52
55
|
|
|
53
|
-
### 0. Install
|
|
54
|
-
|
|
55
|
-
The package is not published yet. Until it is, install from a clone (step 1). When it is published,
|
|
56
|
-
the command is:
|
|
56
|
+
### 0. Install the extension
|
|
57
57
|
|
|
58
58
|
```sh
|
|
59
59
|
omp install omp-channel
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
adapter
|
|
62
|
+
This installs the published package into Oh My Pi's plugin folder (`~/.omp/plugins`). The
|
|
63
|
+
extension then loads in every session: no `-e` flag and no path to set. Check it by starting a
|
|
64
|
+
session and running `/channel-status`: it shows the transport in use and, when an adapter is
|
|
65
|
+
configured, what the adapter reports.
|
|
66
|
+
|
|
67
|
+
The configuration file is read from `.omp/omp-channel.json` in the directory where Oh My Pi
|
|
68
|
+
starts, or from the path in `OMP_CHANNEL_CONFIG` when that variable is set. Without either, the
|
|
69
|
+
extension has no transport and only offers MCP push. The steps below write this file.
|
|
65
70
|
|
|
66
71
|
A service that needs its own protocol connects through an adapter module (section 6 of
|
|
67
72
|
[docs/protocol.md](docs/protocol.md)). Point `adapterModule` at it in the configuration file, and
|
|
@@ -75,11 +80,9 @@ give the adapter the environment it reads:
|
|
|
75
80
|
}
|
|
76
81
|
```
|
|
77
82
|
|
|
78
|
-
|
|
83
|
+
### 1. Install from a clone (for development)
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### 1. Install the extension from a clone
|
|
85
|
+
Use this only to change the extension itself. The steps below need the built `dist/index.js`:
|
|
83
86
|
|
|
84
87
|
```sh
|
|
85
88
|
git clone https://github.com/tommasomarchionni/omp-channel.git
|
|
@@ -88,11 +91,7 @@ npm ci
|
|
|
88
91
|
npm run build
|
|
89
92
|
```
|
|
90
93
|
|
|
91
|
-
|
|
92
|
-
the example below. You can also copy or link `dist/index.js` into one of the extension folders
|
|
93
|
-
that Oh My Pi reads (for example `<project>/.omp/extensions` or `~/.omp/agent/extensions`), or
|
|
94
|
-
list it in the `extensions` setting of your Oh My Pi configuration. Check the loading rules of
|
|
95
|
-
your Oh My Pi version.
|
|
94
|
+
Load the built file with the `-e` flag, as in the example below, instead of `omp install`.
|
|
96
95
|
|
|
97
96
|
### 2. Choose how messages arrive
|
|
98
97
|
|
|
@@ -208,21 +207,22 @@ extension still receives MCP pushes, but replies are reported as not configured.
|
|
|
208
207
|
validated against [schema/config.schema.json](schema/config.schema.json). An invalid file disables
|
|
209
208
|
the extension and writes the reason (with its path) to stderr.
|
|
210
209
|
|
|
211
|
-
| Key | Default
|
|
212
|
-
| -------------------------- |
|
|
213
|
-
| `mcpServer` | `"omp-channel"`
|
|
214
|
-
| `service.url` | none
|
|
215
|
-
| `service.keyEnv` | `"OMP_CHANNEL_KEY"`
|
|
216
|
-
| `service.requestTimeoutMs` | `10000`
|
|
217
|
-
| `service.paths.*` | `/messages`, `/messages/ack`, `/replies`, `/status` | Endpoint paths. |
|
|
218
|
-
| `poll.intervalMs` | `2000`
|
|
219
|
-
| `poll.maxBackoffMs` | `30000`
|
|
220
|
-
| `poll.batchSize` | `10`
|
|
221
|
-
| `limits.maxTextLength` | `4000`
|
|
222
|
-
| `limits.maxSenderLength` | `64`
|
|
223
|
-
| `limits.maxPending` | `5`
|
|
224
|
-
| `delivery.deliverAs` | `"followUp"`
|
|
225
|
-
| `
|
|
210
|
+
| Key | Default | Meaning |
|
|
211
|
+
| -------------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
212
|
+
| `mcpServer` | `"omp-channel"` | MCP server name that may push messages. |
|
|
213
|
+
| `service.url` | none | Base URL of the service. `https` required; `http` only for loopback. |
|
|
214
|
+
| `service.keyEnv` | `"OMP_CHANNEL_KEY"` | Environment variable holding the key (`<keyEnv>_FILE` for a file). Required with `service.url`. |
|
|
215
|
+
| `service.requestTimeoutMs` | `10000` | Timeout of each request. |
|
|
216
|
+
| `service.paths.*` | `/messages`, `/messages/ack`, `/replies`, `/status`, `/failures` | Endpoint paths. |
|
|
217
|
+
| `poll.intervalMs` | `2000` | Wait between polls when the queue is empty. |
|
|
218
|
+
| `poll.maxBackoffMs` | `30000` | Longest wait after failed polls. |
|
|
219
|
+
| `poll.batchSize` | `10` | Deliveries requested per poll. |
|
|
220
|
+
| `limits.maxTextLength` | `4000` | Longest message text, in characters. |
|
|
221
|
+
| `limits.maxSenderLength` | `64` | Longest sender name. |
|
|
222
|
+
| `limits.maxPending` | `5` | Events waiting to be admitted; more are dropped and not acknowledged. |
|
|
223
|
+
| `delivery.deliverAs` | `"followUp"` | How a message is queued in Oh My Pi: `steer`, `followUp` or `aside`. |
|
|
224
|
+
| `failures.includeReason` | `true` | Send the cleaned error text when a turn fails and leaves a message unanswered. |
|
|
225
|
+
| `adapterModule` | none | Path to a module that exports a `ChannelAdapter`. Replaces the HTTP transport. |
|
|
226
226
|
|
|
227
227
|
Environment variables:
|
|
228
228
|
|
|
@@ -245,6 +245,16 @@ Environment variables:
|
|
|
245
245
|
addresses, for local tests.
|
|
246
246
|
- **Replies are limited.** The `reply` tool accepts only a `messageId` that was delivered in the
|
|
247
247
|
current session.
|
|
248
|
+
- **Error text is cleaned.** When a turn fails, the error from the model provider is sent with
|
|
249
|
+
known secret shapes and the home folder name hidden. `failures.includeReason: false` keeps it on
|
|
250
|
+
the machine.
|
|
251
|
+
|
|
252
|
+
## When a turn fails
|
|
253
|
+
|
|
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
|
|
257
|
+
[docs/protocol.md](docs/protocol.md), section 9.
|
|
248
258
|
|
|
249
259
|
Report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
|
|
250
260
|
|
|
@@ -262,7 +272,7 @@ Report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
|
|
|
262
272
|
plain JSON Schema where Oh My Pi declares a TypeBox schema.
|
|
263
273
|
- **Verified in a live Oh My Pi session (19.2.1, local model):** startup, delivery of a pushed
|
|
264
274
|
message to an idle session, a message pushed during a turn (taken at a turn boundary, see
|
|
265
|
-
[docs/protocol.md](docs/protocol.md) section 3.5), and
|
|
275
|
+
[docs/protocol.md](docs/protocol.md) section 3.5), abort, and the report of a refused model request.
|
|
266
276
|
- **Not verified yet:** the status report (`working`/`free`) to a service, and the effect of each
|
|
267
277
|
`attribution` value. See [docs/omp-verification.md](docs/omp-verification.md).
|
|
268
278
|
- `npm ci` also installs the Oh My Pi package for type checking; it is large.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InboundEvent, OutboundReply, OutboundStatus } from "./protocol.js";
|
|
1
|
+
import type { InboundEvent, 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). */
|
|
@@ -21,6 +21,11 @@ export interface ChannelAdapter {
|
|
|
21
21
|
ack?(deliveryId: string): Promise<void>;
|
|
22
22
|
/** Reports agent state for a conversation. Best effort. */
|
|
23
23
|
status?(status: OutboundStatus): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Reports that a message got no answer because the turn ended in an error. Without it the
|
|
26
|
+
* service learns nothing and the message stays unanswered. Throws when it is not accepted.
|
|
27
|
+
*/
|
|
28
|
+
failure?(failure: OutboundFailure): Promise<void>;
|
|
24
29
|
/** Tells the service that an interrupt was applied. Optional. */
|
|
25
30
|
interrupt?(conversationId: string): Promise<void>;
|
|
26
31
|
/** Tells the service that a conversation was closed on the agent side. Optional. */
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/config.d.ts
CHANGED
|
@@ -9,12 +9,7 @@ export interface ServiceConfig {
|
|
|
9
9
|
readonly url: URL;
|
|
10
10
|
readonly key: string;
|
|
11
11
|
readonly requestTimeoutMs: number;
|
|
12
|
-
readonly paths:
|
|
13
|
-
messages: string;
|
|
14
|
-
ack: string;
|
|
15
|
-
replies: string;
|
|
16
|
-
status: string;
|
|
17
|
-
};
|
|
12
|
+
readonly paths: ServicePaths;
|
|
18
13
|
}
|
|
19
14
|
export interface PollConfig {
|
|
20
15
|
readonly intervalMs: number;
|
|
@@ -24,6 +19,10 @@ export interface PollConfig {
|
|
|
24
19
|
export interface DeliveryConfig {
|
|
25
20
|
readonly deliverAs: "steer" | "followUp" | "aside";
|
|
26
21
|
}
|
|
22
|
+
export interface FailuresConfig {
|
|
23
|
+
/** Whether the cleaned error text is sent with a failure report. */
|
|
24
|
+
readonly includeReason: boolean;
|
|
25
|
+
}
|
|
27
26
|
export interface ChannelConfig {
|
|
28
27
|
readonly mcpServer: string;
|
|
29
28
|
readonly service: ServiceConfig | undefined;
|
|
@@ -33,6 +32,7 @@ export interface ChannelConfig {
|
|
|
33
32
|
maxPending: number;
|
|
34
33
|
};
|
|
35
34
|
readonly delivery: DeliveryConfig;
|
|
35
|
+
readonly failures: FailuresConfig;
|
|
36
36
|
}
|
|
37
37
|
export interface ConfigSources {
|
|
38
38
|
readonly env: Readonly<Record<string, string | undefined>>;
|
|
@@ -46,5 +46,13 @@ export interface ConfigSources {
|
|
|
46
46
|
* by <keyEnv>_FILE. It is never read from the configuration file.
|
|
47
47
|
*/
|
|
48
48
|
export declare function loadConfig(sources: ConfigSources): ChannelConfig;
|
|
49
|
+
interface ServicePaths {
|
|
50
|
+
messages: string;
|
|
51
|
+
ack: string;
|
|
52
|
+
replies: string;
|
|
53
|
+
status: string;
|
|
54
|
+
failures: string;
|
|
55
|
+
}
|
|
49
56
|
/** https is required. Plain http is accepted only for loopback, and credentials are refused. */
|
|
50
57
|
export declare function parseServiceUrl(raw: string): URL;
|
|
58
|
+
export {};
|
package/dist/config.js
CHANGED
package/dist/config.js.map
CHANGED
|
@@ -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,MAAM,4BAA4B,GAAG,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAE7E,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;
|
|
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,MAAM,4BAA4B,GAAG,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAE7E,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AA2CD,MAAM,SAAS,GAAG,IAAI,GAA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QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC;IACzD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5D,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,GAAG,MAAM,kCAAkC,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,IAAI,WAAW,CAAC,OAAO,MAAM,QAAQ,MAAM,2BAA2B,CAAC,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"}
|
package/dist/dispatcher.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type ReplyResult = {
|
|
|
34
34
|
* without running again.
|
|
35
35
|
* - Interrupt stops the current turn only. Tool results already produced stay in the session.
|
|
36
36
|
* - Agent state is reported to the service for the open conversation.
|
|
37
|
+
* - A message that a failed turn left unanswered is reported once.
|
|
37
38
|
*/
|
|
38
39
|
export declare class Dispatcher {
|
|
39
40
|
#private;
|
|
@@ -43,4 +44,10 @@ export declare class Dispatcher {
|
|
|
43
44
|
/** Reports the agent state for the open conversation. Best effort: errors are logged. */
|
|
44
45
|
setStatus(status: AgentStatus): void;
|
|
45
46
|
reply(messageId: string, text: string): Promise<ReplyResult>;
|
|
47
|
+
/**
|
|
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.
|
|
51
|
+
*/
|
|
52
|
+
reportFailure(messageIds: readonly string[], reason: string | undefined): Promise<void>;
|
|
46
53
|
}
|
package/dist/dispatcher.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { AdapterError } from "./adapter.js";
|
|
3
|
-
import {
|
|
3
|
+
import { cleanReason } from "./redact.js";
|
|
4
|
+
import { buildFailure, buildReply, buildStatus, formatForSession, } from "./protocol.js";
|
|
4
5
|
export const ACKNOWLEDGED_OUTCOMES = new Set([
|
|
5
6
|
"admitted",
|
|
6
7
|
"duplicate",
|
|
@@ -16,6 +17,7 @@ const MAX_REMEMBERED = 1000;
|
|
|
16
17
|
* without running again.
|
|
17
18
|
* - Interrupt stops the current turn only. Tool results already produced stay in the session.
|
|
18
19
|
* - Agent state is reported to the service for the open conversation.
|
|
20
|
+
* - A message that a failed turn left unanswered is reported once.
|
|
19
21
|
*/
|
|
20
22
|
export class Dispatcher {
|
|
21
23
|
#options;
|
|
@@ -24,6 +26,8 @@ export class Dispatcher {
|
|
|
24
26
|
#active;
|
|
25
27
|
#remembered = new RecentSet(MAX_REMEMBERED);
|
|
26
28
|
#conversationOf = new RecentMap(MAX_REMEMBERED);
|
|
29
|
+
#answered = new RecentSet(MAX_REMEMBERED);
|
|
30
|
+
#reportedFailed = new RecentSet(MAX_REMEMBERED);
|
|
27
31
|
constructor(options) {
|
|
28
32
|
this.#options = options;
|
|
29
33
|
}
|
|
@@ -72,6 +76,7 @@ export class Dispatcher {
|
|
|
72
76
|
});
|
|
73
77
|
try {
|
|
74
78
|
await adapter.reply(reply);
|
|
79
|
+
this.#answered.add(messageId);
|
|
75
80
|
return { ok: true };
|
|
76
81
|
}
|
|
77
82
|
catch (error) {
|
|
@@ -79,6 +84,49 @@ export class Dispatcher {
|
|
|
79
84
|
return { ok: false, reason: `the service did not accept the reply: ${detail}` };
|
|
80
85
|
}
|
|
81
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Tells the service that a failed turn left these messages unanswered. Messages that were not
|
|
89
|
+
* admitted here, already answered or already reported are skipped. Best effort: a report that
|
|
90
|
+
* is refused is logged, and a later failure of the same message tries again.
|
|
91
|
+
*/
|
|
92
|
+
async reportFailure(messageIds, reason) {
|
|
93
|
+
const waiting = messageIds.flatMap((messageId) => {
|
|
94
|
+
const conversation = this.#conversationOf.get(messageId);
|
|
95
|
+
return conversation === undefined ||
|
|
96
|
+
this.#answered.has(messageId) ||
|
|
97
|
+
this.#reportedFailed.has(messageId)
|
|
98
|
+
? []
|
|
99
|
+
: [{ messageId, conversation }];
|
|
100
|
+
});
|
|
101
|
+
if (waiting.length === 0) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const adapter = this.#options.adapter;
|
|
105
|
+
if (adapter?.failure === undefined) {
|
|
106
|
+
this.#options.log("a turn failed and the adapter does not report failures");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const shown = this.#options.config.failures.includeReason && reason !== undefined
|
|
110
|
+
? cleanReason(reason)
|
|
111
|
+
: undefined;
|
|
112
|
+
// Marked before the first wait, so a second end of the same run does not report twice.
|
|
113
|
+
for (const { messageId } of waiting) {
|
|
114
|
+
this.#reportedFailed.add(messageId);
|
|
115
|
+
}
|
|
116
|
+
for (const { messageId, conversation } of waiting) {
|
|
117
|
+
const report = buildFailure(conversation, messageId, shown, {
|
|
118
|
+
messageId: this.#newId(),
|
|
119
|
+
at: this.#now(),
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
await adapter.failure(report);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
this.#reportedFailed.delete(messageId);
|
|
126
|
+
this.#options.log(`failure was not reported (${errorName(error)})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
82
130
|
async #apply(event, deliveryId) {
|
|
83
131
|
const { config, session } = this.#options;
|
|
84
132
|
if (event.type === "message") {
|
|
@@ -159,6 +207,9 @@ class RecentSet {
|
|
|
159
207
|
has(value) {
|
|
160
208
|
return this.#values.has(value);
|
|
161
209
|
}
|
|
210
|
+
delete(value) {
|
|
211
|
+
this.#values.delete(value);
|
|
212
|
+
}
|
|
162
213
|
add(value) {
|
|
163
214
|
this.#values.add(value);
|
|
164
215
|
if (this.#values.size > this.#capacity) {
|
package/dist/dispatcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAEL,YAAY,EACZ,UAAU,EACV,WAAW,EACX,gBAAgB,GAGjB,MAAM,eAAe,CAAC;AAWvB,MAAM,CAAC,MAAM,qBAAqB,GAA8B,IAAI,GAAG,CAAC;IACtE,UAAU;IACV,WAAW;IACX,SAAS;CACV,CAAC,CAAC;AAoBH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;;;;;;;GAU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AI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/extension.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export interface ChannelExtensionOptions {
|
|
|
13
13
|
* Creates the extension factory. It registers:
|
|
14
14
|
* - `mcp_notification`: messages pushed by the configured MCP server enter the agent;
|
|
15
15
|
* - the `reply` tool: the model answers a message by its messageId;
|
|
16
|
-
* - lifecycle hooks: agent state
|
|
16
|
+
* - lifecycle hooks: agent state and failed turns are reported to the service, and the adapter
|
|
17
|
+
* stops on shutdown;
|
|
17
18
|
* - the adapter receive loop, when an adapter is given.
|
|
18
19
|
*/
|
|
19
20
|
export declare function createChannelExtension(options: ChannelExtensionOptions): ExtensionFactory;
|
package/dist/extension.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ACKNOWLEDGED_OUTCOMES, Dispatcher } from "./dispatcher.js";
|
|
2
2
|
import { parseMcpNotification, parseReplyInput } from "./protocol.js";
|
|
3
3
|
import { jsonSchemaParameters } from "./tool-schema.js";
|
|
4
|
+
import { failedRun } from "./turn.js";
|
|
4
5
|
export const REPLY_TOOL_NAME = "reply";
|
|
5
6
|
/**
|
|
6
7
|
* Creates the extension factory. It registers:
|
|
7
8
|
* - `mcp_notification`: messages pushed by the configured MCP server enter the agent;
|
|
8
9
|
* - the `reply` tool: the model answers a message by its messageId;
|
|
9
|
-
* - lifecycle hooks: agent state
|
|
10
|
+
* - lifecycle hooks: agent state and failed turns are reported to the service, and the adapter
|
|
11
|
+
* stops on shutdown;
|
|
10
12
|
* - the adapter receive loop, when an adapter is given.
|
|
11
13
|
*/
|
|
12
14
|
export function createChannelExtension(options) {
|
|
@@ -44,8 +46,16 @@ export function createChannelExtension(options) {
|
|
|
44
46
|
context = ctx;
|
|
45
47
|
dispatcher.setStatus("working");
|
|
46
48
|
});
|
|
47
|
-
pi.on("agent_end", (
|
|
49
|
+
pi.on("agent_end", (event, ctx) => {
|
|
48
50
|
context = ctx;
|
|
51
|
+
// A run that Oh My Pi continues (a retry, for example) has not ended: still working.
|
|
52
|
+
if (event.willContinue === true) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const failed = failedRun(event);
|
|
56
|
+
if (failed !== undefined) {
|
|
57
|
+
void dispatcher.reportFailure(failed.messageIds, failed.reason);
|
|
58
|
+
}
|
|
49
59
|
dispatcher.setStatus("free");
|
|
50
60
|
});
|
|
51
61
|
if (adapter !== undefined) {
|
package/dist/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAoB,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAoB,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAUvC;;;;;;;GAOG;AACH,MA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AQ,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC7E,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxC,GAAG,CAAC,0BAA0B,OAAO,sCAAsC,CAAC,CAAC;gBAC7E,SAAS;YACX,CAAC;YACD,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;gBACnE,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;oBAChD,GAAG,CAAC,oEAAoE,CAAC,CAAC;gBAC5E,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,GAAG,CAAC,yBAAyB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAC/C,CAAC"}
|
package/dist/http-adapter.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export interface HttpAdapterOptions {
|
|
|
13
13
|
* Transport over plain HTTP with leases (see docs/protocol.md, "HTTP transport"):
|
|
14
14
|
* - GET paths.messages returns { deliveries: [{ deliveryId, leaseExpiresAt, event }] } in order;
|
|
15
15
|
* - POST paths.ack with { deliveryIds: [...] } after the agent admitted a delivery;
|
|
16
|
-
* - POST paths.replies with a reply; POST paths.status with an agent status
|
|
16
|
+
* - POST paths.replies with a reply; POST paths.status with an agent status;
|
|
17
|
+
* - POST paths.failures when a turn ended in an error and a message got no answer.
|
|
17
18
|
* A delivery that is not acknowledged before its lease ends is delivered again by the service.
|
|
18
19
|
*/
|
|
19
20
|
export declare function createHttpAdapter(options: HttpAdapterOptions): ChannelAdapter;
|
package/dist/http-adapter.js
CHANGED
|
@@ -5,7 +5,8 @@ const DELIVERY_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
|
5
5
|
* Transport over plain HTTP with leases (see docs/protocol.md, "HTTP transport"):
|
|
6
6
|
* - GET paths.messages returns { deliveries: [{ deliveryId, leaseExpiresAt, event }] } in order;
|
|
7
7
|
* - POST paths.ack with { deliveryIds: [...] } after the agent admitted a delivery;
|
|
8
|
-
* - POST paths.replies with a reply; POST paths.status with an agent status
|
|
8
|
+
* - POST paths.replies with a reply; POST paths.status with an agent status;
|
|
9
|
+
* - POST paths.failures when a turn ended in an error and a message got no answer.
|
|
9
10
|
* A delivery that is not acknowledged before its lease ends is delivered again by the service.
|
|
10
11
|
*/
|
|
11
12
|
export function createHttpAdapter(options) {
|
|
@@ -116,6 +117,9 @@ export function createHttpAdapter(options) {
|
|
|
116
117
|
async status(status) {
|
|
117
118
|
await request("POST", service.paths.status, status, undefined);
|
|
118
119
|
},
|
|
120
|
+
async failure(failure) {
|
|
121
|
+
await request("POST", service.paths.failures, failure, undefined);
|
|
122
|
+
},
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
125
|
function sleep(ms, signal) {
|
package/dist/http-adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../src/http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsC,MAAM,cAAc,CAAC;AAEhF,OAAO,
|
|
1
|
+
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../src/http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsC,MAAM,cAAc,CAAC;AAEhF,OAAO,EAML,iBAAiB,GAClB,MAAM,eAAe,CA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,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACjE,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,OAAwB;YACpC,MAAM,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QACpE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,EAAU,EAAE,MAAmB;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACvD,SAAS,IAAI;YACX,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -60,6 +60,20 @@ export interface OutboundStatus {
|
|
|
60
60
|
readonly status: AgentStatus;
|
|
61
61
|
readonly at: string;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* A turn ended in an error and a message got no answer. `reason` is the cleaned error text, absent
|
|
65
|
+
* when it is turned off or there is none.
|
|
66
|
+
*/
|
|
67
|
+
export interface OutboundFailure {
|
|
68
|
+
readonly type: "failure";
|
|
69
|
+
readonly conversationId: string;
|
|
70
|
+
/** Unique id of this report, so a retried POST can be recognized. */
|
|
71
|
+
readonly messageId: string;
|
|
72
|
+
/** The inbound message that got no answer. */
|
|
73
|
+
readonly replyTo: string;
|
|
74
|
+
readonly reason?: string;
|
|
75
|
+
readonly at: string;
|
|
76
|
+
}
|
|
63
77
|
export type ParseResult<T> = {
|
|
64
78
|
ok: true;
|
|
65
79
|
value: T;
|
|
@@ -85,7 +99,13 @@ export declare function buildReply(conversationId: string, replyTo: string, text
|
|
|
85
99
|
messageId: string;
|
|
86
100
|
at: Date;
|
|
87
101
|
}): OutboundReply;
|
|
102
|
+
export declare function buildFailure(conversationId: string, replyTo: string, reason: string | undefined, report: {
|
|
103
|
+
messageId: string;
|
|
104
|
+
at: Date;
|
|
105
|
+
}): OutboundFailure;
|
|
88
106
|
export declare function buildStatus(conversationId: string, status: AgentStatus, at: Date): OutboundStatus;
|
|
107
|
+
/** The message ids of the envelopes in a text handed to the agent (see `formatForSession`). */
|
|
108
|
+
export declare function messageIdsIn(text: string): string[];
|
|
89
109
|
/**
|
|
90
110
|
* Text handed to the agent for a message. It is marked as data written by an outside person.
|
|
91
111
|
* Angle brackets in the sender and the body are escaped, so the body cannot close the envelope.
|
package/dist/protocol.js
CHANGED
|
@@ -132,9 +132,24 @@ export function buildReply(conversationId, replyTo, text, reply) {
|
|
|
132
132
|
at: reply.at.toISOString(),
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
+
export function buildFailure(conversationId, replyTo, reason, report) {
|
|
136
|
+
return {
|
|
137
|
+
type: "failure",
|
|
138
|
+
conversationId,
|
|
139
|
+
messageId: report.messageId,
|
|
140
|
+
replyTo,
|
|
141
|
+
...(reason === undefined ? {} : { reason }),
|
|
142
|
+
at: report.at.toISOString(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
135
145
|
export function buildStatus(conversationId, status, at) {
|
|
136
146
|
return { type: "status", conversationId, status, at: at.toISOString() };
|
|
137
147
|
}
|
|
148
|
+
const ENVELOPE = /<channel-message messageId="([A-Za-z0-9._:-]{1,128})">/g;
|
|
149
|
+
/** The message ids of the envelopes in a text handed to the agent (see `formatForSession`). */
|
|
150
|
+
export function messageIdsIn(text) {
|
|
151
|
+
return [...text.matchAll(ENVELOPE)].flatMap((match) => match[1] === undefined ? [] : [match[1]]);
|
|
152
|
+
}
|
|
138
153
|
/**
|
|
139
154
|
* Text handed to the agent for a message. It is marked as data written by an outside person.
|
|
140
155
|
* Angle brackets in the sender and the body are escaped, so the body cannot close the envelope.
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAOnE,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC;AAEnF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAOnE,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC;AAEnF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAwEjC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAExC,MAAM,cAAc,GAAgD;IAClE,OAAO,EAAE;QACP,MAAM;QACN,gBAAgB;QAChB,WAAW;QACX,QAAQ;QACR,MAAM;QACN,QAAQ;QACR,SAAS;QACT,aAAa;KACd;IACD,SAAS,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC;IACrC,KAAK,EAAE,CAAC,MAAM,EAAE,gBAAgB,CA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;AAED,mFAAmF;AACnF,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAC,MAAc;IAC1B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,CACL,kEAAkE,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9E,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CACjC,CAAC;AACJ,CAAC"}
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes an error message safe to hand to a service. The text comes from a model provider and can
|
|
3
|
+
* quote a request: secrets are hidden before it leaves the machine. Known shapes, not a guarantee;
|
|
4
|
+
* `failures.includeReason: false` keeps the reason on the machine.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_REASON_LENGTH = 500;
|
|
7
|
+
/**
|
|
8
|
+
* One line, secrets hidden, at most `MAX_REASON_LENGTH` characters. Undefined when nothing is
|
|
9
|
+
* left. Secrets are hidden before the cut, so a cut never leaves part of one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cleanReason(raw: string): string | undefined;
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes an error message safe to hand to a service. The text comes from a model provider and can
|
|
3
|
+
* quote a request: secrets are hidden before it leaves the machine. Known shapes, not a guarantee;
|
|
4
|
+
* `failures.includeReason: false` keeps the reason on the machine.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_REASON_LENGTH = 500;
|
|
7
|
+
const HIDDEN = "[hidden]";
|
|
8
|
+
const SECRET_SHAPES = [
|
|
9
|
+
// A private key block, from its first line.
|
|
10
|
+
[/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----.*$/g, HIDDEN],
|
|
11
|
+
// The credentials of an address (scheme://user:password@host): the host stays.
|
|
12
|
+
[/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/:@]*:[^\s/@]+@/gi, `$1${HIDDEN}@`],
|
|
13
|
+
// The query of an address can carry keys.
|
|
14
|
+
[/\b(https?:\/\/[^\s?#]+)\?[^\s"')]+/gi, `$1?${HIDDEN}`],
|
|
15
|
+
[
|
|
16
|
+
/\b(authorization["']?\s*[:=]\s*["']?)(?:(?:bearer|basic|token)\s+)?[^\s"',;]+/gi,
|
|
17
|
+
`$1${HIDDEN}`,
|
|
18
|
+
],
|
|
19
|
+
[/\b(bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi, `$1${HIDDEN}`],
|
|
20
|
+
// key=value and key: value for names that hold secrets.
|
|
21
|
+
[
|
|
22
|
+
/\b([A-Za-z0-9_-]*(?:password|passwd|secret|token|api[_-]?key|access[_-]?key)["']?\s*[:=]\s*["']?)[^\s"',;]{3,}/gi,
|
|
23
|
+
`$1${HIDDEN}`,
|
|
24
|
+
],
|
|
25
|
+
// Tokens of known services.
|
|
26
|
+
[/\b(?:sk|rk|pk)[-_][A-Za-z0-9_*-]{8,}/g, HIDDEN],
|
|
27
|
+
[/\b(?:gh[pousr]_|github_pat_|npm_|hf_)[A-Za-z0-9_]{16,}/g, HIDDEN],
|
|
28
|
+
[/\bxox[abposr]-[A-Za-z0-9-]{10,}/g, HIDDEN],
|
|
29
|
+
[/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g, HIDDEN],
|
|
30
|
+
[/\bAIza[0-9A-Za-z_-]{30,}/g, HIDDEN],
|
|
31
|
+
[/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, HIDDEN],
|
|
32
|
+
// The home folder names the person.
|
|
33
|
+
[/(?:\/Users|\/home)\/[^\s/"':]+/g, "~"],
|
|
34
|
+
[/[A-Za-z]:\\Users\\[^\s\\"':]+/g, "~"],
|
|
35
|
+
];
|
|
36
|
+
/** A long token of random look: 32 or more characters with upper case, lower case and digits. */
|
|
37
|
+
const LONG_TOKEN = /[A-Za-z0-9_+=-]{32,}/g;
|
|
38
|
+
/**
|
|
39
|
+
* One line, secrets hidden, at most `MAX_REASON_LENGTH` characters. Undefined when nothing is
|
|
40
|
+
* left. Secrets are hidden before the cut, so a cut never leaves part of one.
|
|
41
|
+
*/
|
|
42
|
+
export function cleanReason(raw) {
|
|
43
|
+
let text = oneLine(raw);
|
|
44
|
+
for (const [pattern, replacement] of SECRET_SHAPES) {
|
|
45
|
+
text = text.replace(pattern, replacement);
|
|
46
|
+
}
|
|
47
|
+
text = text.replace(LONG_TOKEN, (token) => /[A-Z]/.test(token) && /[a-z]/.test(token) && /\d/.test(token) ? HIDDEN : token);
|
|
48
|
+
const symbols = [...text];
|
|
49
|
+
if (symbols.length === 0) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return symbols.length <= MAX_REASON_LENGTH
|
|
53
|
+
? text
|
|
54
|
+
: `${symbols.slice(0, MAX_REASON_LENGTH - 1).join("")}…`;
|
|
55
|
+
}
|
|
56
|
+
function oneLine(text) {
|
|
57
|
+
let result = "";
|
|
58
|
+
for (const symbol of text) {
|
|
59
|
+
const code = symbol.codePointAt(0) ?? 0;
|
|
60
|
+
const control = code < 32 || (code >= 127 && code <= 159) || code === 0x2028 || code === 0x2029;
|
|
61
|
+
result += control ? " " : symbol;
|
|
62
|
+
}
|
|
63
|
+
return result.replace(/\s+/g, " ").trim();
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,MAAM,aAAa,GAA6C;IAC9D,4CAA4C;IAC5C,CAAC,2CAA2C,EAAE,MAAM,CAAC;IACrD,+EAA+E;IAC/E,CAAC,iDAAiD,EAAE,KAAK,MAAM,GAAG,CAAC;IACnE,0CAA0C;IAC1C,CAAC,sCAAsC,EAAE,MAAM,MAAM,EAAE,CAAC;IACxD;QACE,iFAAiF;QACjF,KAAK,MAAM,EAAE;KACd;IACD,CAAC,uCAAuC,EAAE,KAAK,MAAM,EAAE,CAAC;IACxD,wDAAwD;IACxD;QACE,kHAAkH;QAClH,KAAK,MAAM,EAAE;KACd;IACD,4BAA4B;IAC5B,CAAC,uCAAuC,EAAE,MAAM,CAAC;IACjD,CAAC,yDAAyD,EAAE,MAAM,CAAC;IACnE,CAAC,kCAAkC,EAAE,MAAM,CAAC;IAC5C,CAAC,gCAAgC,EAAE,MAAM,CAAC;IAC1C,CAAC,2BAA2B,EAAE,MAAM,CAAC;IACrC,CAAC,+DAA+D,EAAE,MAAM,CAAC;IACzE,oCAAoC;IACpC,CAAC,iCAAiC,EAAE,GAAG,CAAC;IACxC,CAAC,gCAAgC,EAAE,GAAG,CAAC;CACxC,CAAC;AAEF,iGAAiG;AACjG,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C;;;GAGG;AACH,MA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AC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC"}
|
package/dist/turn.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the end of an Oh My Pi run. The shapes are declared loosely on purpose: only the fields
|
|
3
|
+
* used here are required, so an unexpected message is skipped instead of breaking the session.
|
|
4
|
+
*/
|
|
5
|
+
export interface RunEnd {
|
|
6
|
+
/** True when Oh My Pi continues the run on its own (a retry, for example). */
|
|
7
|
+
readonly willContinue?: boolean | undefined;
|
|
8
|
+
/** The session messages when the run ended. */
|
|
9
|
+
readonly messages?: readonly unknown[] | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface FailedRun {
|
|
12
|
+
/** The error the model provider reported, as it came. Clean it before it leaves the machine. */
|
|
13
|
+
readonly reason: string | undefined;
|
|
14
|
+
/** Ids of the channel messages the failed work was answering, oldest first. */
|
|
15
|
+
readonly messageIds: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The failure of a run that ended in a model error, or undefined for every other end: a run that
|
|
19
|
+
* goes on, a normal answer, an abort, or a run without any channel message.
|
|
20
|
+
*
|
|
21
|
+
* The messages looked at are those after the last completed answer: an older message that the
|
|
22
|
+
* model finished with is not blamed for a later error.
|
|
23
|
+
*/
|
|
24
|
+
export declare function failedRun(end: RunEnd): FailedRun | undefined;
|
package/dist/turn.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { messageIdsIn } from "./protocol.js";
|
|
2
|
+
/**
|
|
3
|
+
* The failure of a run that ended in a model error, or undefined for every other end: a run that
|
|
4
|
+
* goes on, a normal answer, an abort, or a run without any channel message.
|
|
5
|
+
*
|
|
6
|
+
* The messages looked at are those after the last completed answer: an older message that the
|
|
7
|
+
* model finished with is not blamed for a later error.
|
|
8
|
+
*/
|
|
9
|
+
export function failedRun(end) {
|
|
10
|
+
if (end.willContinue === true) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const messages = (end.messages ?? []).filter(isRecord);
|
|
14
|
+
let last = messages.length - 1;
|
|
15
|
+
while (last >= 0 && messages[last]?.role !== "assistant") {
|
|
16
|
+
last -= 1;
|
|
17
|
+
}
|
|
18
|
+
const failed = messages[last];
|
|
19
|
+
if (failed === undefined || failed.stopReason !== "error") {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const ids = [];
|
|
23
|
+
for (let index = last - 1; index >= 0; index -= 1) {
|
|
24
|
+
const message = messages[index];
|
|
25
|
+
if (message === undefined) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (message.role === "assistant") {
|
|
29
|
+
if (message.stopReason === "stop" || message.stopReason === "length") {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (message.role === "user" || message.role === "developer") {
|
|
35
|
+
ids.unshift(...textsOf(message.content).flatMap(messageIdsIn));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (ids.length === 0) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
reason: typeof failed.errorMessage === "string" ? failed.errorMessage : undefined,
|
|
43
|
+
messageIds: [...new Set(ids)],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function textsOf(content) {
|
|
47
|
+
if (typeof content === "string") {
|
|
48
|
+
return [content];
|
|
49
|
+
}
|
|
50
|
+
if (!Array.isArray(content)) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return content
|
|
54
|
+
.filter(isRecord)
|
|
55
|
+
.flatMap((part) => (typeof part.text === "string" ? [part.text] : []));
|
|
56
|
+
}
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === "object" && value !== null && !Array.isArray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|
package/docs/protocol.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
title: Integration protocol
|
|
4
|
+
description: The public contract between a service and an Oh My Pi agent session.
|
|
5
|
+
---
|
|
6
|
+
|
|
1
7
|
# Integration protocol (version 1)
|
|
2
8
|
|
|
3
9
|
This document is the public contract between an external **service** (any system that exchanges
|
|
@@ -5,13 +11,14 @@ messages with a person or with another agent) and an agent
|
|
|
5
11
|
session of [Oh My Pi](https://github.com/can1357/oh-my-pi) running omp-channel. Any service can
|
|
6
12
|
implement it. The contract is independent of any product.
|
|
7
13
|
|
|
8
|
-
The machine-readable schemas are in [`schema/`](
|
|
14
|
+
The machine-readable schemas are in [`schema/`](https://github.com/tommasomarchionni/omp-channel/tree/main/schema):
|
|
9
15
|
|
|
10
16
|
| File | Describes |
|
|
11
17
|
| ---------------------------- | ----------------------------------------------------------------------- |
|
|
12
18
|
| `inbound-event.schema.json` | events the service sends to the agent (`message`, `interrupt`, `close`) |
|
|
13
19
|
| `outbound-reply.schema.json` | a reply the agent posts to the service |
|
|
14
20
|
| `status.schema.json` | agent state the agent reports to the service |
|
|
21
|
+
| `failure.schema.json` | a turn that ended in an error and left a message unanswered |
|
|
15
22
|
| `config.schema.json` | the omp-channel configuration file |
|
|
16
23
|
|
|
17
24
|
The TypeScript module `src/protocol.ts` implements the same rules. Both must change together.
|
|
@@ -122,6 +129,7 @@ Paths are relative to `service.url` and configurable in `service.paths`. Default
|
|
|
122
129
|
| Acknowledge | `POST /messages/ack` | `{ "deliveryIds": ["d1"] }` |
|
|
123
130
|
| Reply | `POST /replies` | outbound reply (section 7) |
|
|
124
131
|
| Status | `POST /status` | agent status (section 8) |
|
|
132
|
+
| Failure | `POST /failures` | failed turn (section 9) |
|
|
125
133
|
|
|
126
134
|
All calls carry `Authorization: Bearer <key>`. A non-2xx answer is an error. The key is never
|
|
127
135
|
included in a log line, an error message or a tool result.
|
|
@@ -207,6 +215,7 @@ interface ChannelAdapter {
|
|
|
207
215
|
reply(reply: OutboundReply): Promise<void>; // required
|
|
208
216
|
ack?(deliveryId: string): Promise<void>; // after admission
|
|
209
217
|
status?(status: OutboundStatus): Promise<void>; // best effort
|
|
218
|
+
failure?(failure: OutboundFailure): Promise<void>; // a message got no answer (section 9)
|
|
210
219
|
interrupt?(conversationId: string): Promise<void>; // after an interrupt is applied
|
|
211
220
|
close?(conversationId: string): Promise<void>; // after a close is applied
|
|
212
221
|
describe?(): Promise<string> | string; // plain-text state for the /channel-status command
|
|
@@ -244,20 +253,61 @@ message text. A `describe` that throws is reported as one line; its error text i
|
|
|
244
253
|
## 8. Agent status (agent to service)
|
|
245
254
|
|
|
246
255
|
```json
|
|
247
|
-
{
|
|
256
|
+
{
|
|
257
|
+
"type": "status",
|
|
258
|
+
"conversationId": "c1",
|
|
259
|
+
"status": "working",
|
|
260
|
+
"at": "2026-11-26T10:00:00.000Z"
|
|
261
|
+
}
|
|
248
262
|
```
|
|
249
263
|
|
|
250
|
-
`status` is `working` when a turn starts and `free` when it ends, for the open conversation.
|
|
251
|
-
|
|
252
|
-
|
|
264
|
+
`status` is `working` when a turn starts and `free` when it ends, for the open conversation. A run
|
|
265
|
+
that Oh My Pi continues on its own (a retry of a model request, for example) has not ended: the
|
|
266
|
+
state stays `working`. Status is best effort: a failed report is logged and not retried. Status is
|
|
267
|
+
not part of the acknowledgement logic.
|
|
268
|
+
|
|
269
|
+
## 9. Failed turn (agent to service)
|
|
270
|
+
|
|
271
|
+
A turn can end in an error, for example because the model provider refuses the request. The agent
|
|
272
|
+
then answers nothing, so the service is told:
|
|
273
|
+
|
|
274
|
+
```json
|
|
275
|
+
{
|
|
276
|
+
"type": "failure",
|
|
277
|
+
"conversationId": "c1",
|
|
278
|
+
"messageId": "f-41c0b9e2",
|
|
279
|
+
"replyTo": "m1",
|
|
280
|
+
"reason": "404 The model is downloaded but not loaded",
|
|
281
|
+
"at": "2026-11-26T10:00:00.000Z"
|
|
282
|
+
}
|
|
283
|
+
```
|
|
253
284
|
|
|
254
|
-
|
|
285
|
+
- One report for each unanswered message: `replyTo` is its `messageId`. `messageId` is generated
|
|
286
|
+
by the agent for each report.
|
|
287
|
+
- Sent only when the run is over. Oh My Pi retries some errors by itself; while it does, nothing is
|
|
288
|
+
reported.
|
|
289
|
+
- Only a model error is reported. An aborted turn (an interrupt from the service, or from the
|
|
290
|
+
person at the terminal) is not.
|
|
291
|
+
- A message that already got a reply is never reported. The failed turn blames only the messages
|
|
292
|
+
it took after the last completed answer.
|
|
293
|
+
- `reason` is optional text for a person: one line, at most 500 characters. Common shapes of
|
|
294
|
+
secrets (tokens, credentials in headers and addresses) and the name of the home folder are
|
|
295
|
+
hidden before it is sent. The hiding covers known shapes and is no guarantee: set
|
|
296
|
+
`failures.includeReason` to `false` to send no text at all.
|
|
297
|
+
- The report is best effort. A refused report is logged and sent again only if a later turn fails
|
|
298
|
+
for the same message.
|
|
299
|
+
- A reply for the same message is still accepted afterwards, for example when a later turn
|
|
300
|
+
succeeds. A service that has shown the failure decides what to do with it.
|
|
301
|
+
- A transport without the `failure` hook only logs the event. Over MCP push there is no way back
|
|
302
|
+
to the service, so nothing is sent.
|
|
303
|
+
|
|
304
|
+
## 10. Activity (optional, not emitted in version 1)
|
|
255
305
|
|
|
256
306
|
The protocol reserves an optional `activity` report (for example, a tool started or finished)
|
|
257
307
|
for showing progress to the service. Version 1 of omp-channel does not emit it. A service must
|
|
258
308
|
not require it.
|
|
259
309
|
|
|
260
|
-
##
|
|
310
|
+
## 11. Security rules
|
|
261
311
|
|
|
262
312
|
- The service key is read from an environment variable named in the configuration
|
|
263
313
|
(`service.keyEnv`), or from a file named by `<keyEnv>_FILE`. It is never written in the
|
|
@@ -268,14 +318,15 @@ not require it.
|
|
|
268
318
|
- Inbound text is data from an outside party. It is handed to the model inside an envelope that
|
|
269
319
|
says so, and angle brackets are escaped so the text cannot close the envelope.
|
|
270
320
|
- Inbound events are validated before use. Unknown fields and out-of-range values are rejected.
|
|
321
|
+
- The error text of a failed turn is cleaned of known secret shapes before it is sent (section 9).
|
|
271
322
|
|
|
272
|
-
##
|
|
323
|
+
## 12. Versioning
|
|
273
324
|
|
|
274
325
|
`PROTOCOL_VERSION` is `1`. Version 1 is alpha: fields may still change before the first stable
|
|
275
326
|
release, and each change is recorded in CHANGELOG.md. A future incompatible change will use a
|
|
276
327
|
new version number.
|
|
277
328
|
|
|
278
|
-
##
|
|
329
|
+
## 13. Not in this contract
|
|
279
330
|
|
|
280
331
|
- Delivery of messages from the agent to a person without a reply to a message.
|
|
281
332
|
- Attachments and other non-text content.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-channel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Oh My Pi extension that delivers messages from an external console into an agent session and sends replies back.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@biomejs/biome": "^2.6.9",
|
|
66
66
|
"@oh-my-pi/pi-coding-agent": "19.2.1",
|
|
67
|
-
"@types/node": "^
|
|
67
|
+
"@types/node": "^26.6.6",
|
|
68
68
|
"tsx": "^4.23.15",
|
|
69
|
-
"typescript": "^
|
|
69
|
+
"typescript": "^7.0.2"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"ajv": "^8.20.0"
|
|
@@ -62,6 +62,11 @@
|
|
|
62
62
|
"type": "string",
|
|
63
63
|
"pattern": "^/",
|
|
64
64
|
"default": "/status"
|
|
65
|
+
},
|
|
66
|
+
"failures": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"pattern": "^/",
|
|
69
|
+
"default": "/failures"
|
|
65
70
|
}
|
|
66
71
|
},
|
|
67
72
|
"default": {}
|
|
@@ -131,6 +136,19 @@
|
|
|
131
136
|
},
|
|
132
137
|
"default": {}
|
|
133
138
|
},
|
|
139
|
+
"failures": {
|
|
140
|
+
"description": "Reports of turns that ended in an error and left a message unanswered.",
|
|
141
|
+
"type": "object",
|
|
142
|
+
"additionalProperties": false,
|
|
143
|
+
"properties": {
|
|
144
|
+
"includeReason": {
|
|
145
|
+
"description": "Send the error text, with secrets hidden, to the service.",
|
|
146
|
+
"type": "boolean",
|
|
147
|
+
"default": true
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"default": {}
|
|
151
|
+
},
|
|
134
152
|
"adapterModule": {
|
|
135
153
|
"description": "Path (relative to the working directory) of a JavaScript module whose default export implements ChannelAdapter. Replaces the HTTP service transport.",
|
|
136
154
|
"type": "string",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://example.com/omp-channel/schema/failure.schema.json",
|
|
4
|
+
"title": "Failed turn (agent to service)",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["type", "conversationId", "messageId", "replyTo", "at"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"type": { "const": "failure" },
|
|
10
|
+
"conversationId": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"minLength": 1,
|
|
13
|
+
"maxLength": 128,
|
|
14
|
+
"pattern": "^[A-Za-z0-9._:-]+$"
|
|
15
|
+
},
|
|
16
|
+
"messageId": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1,
|
|
19
|
+
"maxLength": 128,
|
|
20
|
+
"pattern": "^[A-Za-z0-9._:-]+$"
|
|
21
|
+
},
|
|
22
|
+
"replyTo": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"minLength": 1,
|
|
25
|
+
"maxLength": 128,
|
|
26
|
+
"pattern": "^[A-Za-z0-9._:-]+$"
|
|
27
|
+
},
|
|
28
|
+
"reason": { "type": "string", "minLength": 1, "maxLength": 500 },
|
|
29
|
+
"at": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|