@sjawhar/pi-envoy 17.6.1 → 17.8.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/README.md +48 -48
- package/dist/dispatch.js +105 -111
- package/dist/envoy.js +717 -1429
- package/dist/skills/envoy/SKILL.md +96 -22
- package/dist/skills/envoy/references/deliveries.md +71 -15
- package/dist/skills/envoy/references/legion.md +34 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,23 +9,23 @@ phase worker or the controller with — is the separate plugin `@sjawhar/pi-legi
|
|
|
9
9
|
beside this one in a Legion deployment; it reaches this plugin through the in-process interface
|
|
10
10
|
described in `packages/pi-shared/AGENTS.md`.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
A topic subscription is an interest registered with the listener, which filters the session's own
|
|
13
|
+
durable consumer on it; the session's NATS connection holds one subject, the relay the listener
|
|
14
|
+
serves that consumer on. A role claim is
|
|
15
|
+
different: the listener arbitrates the core-NATS role lane for the current live holder, then
|
|
16
|
+
forwards the message with its original role topic to the holder's direct agent subject.
|
|
15
17
|
`envoy_unsubscribe` manages only normal topic subscriptions; it does not relinquish a held role,
|
|
16
18
|
and it keeps open, listing them as kept, the subscriptions another plugin holds for that role.
|
|
17
|
-
The
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
one hour of the keep, and the publish answers 202 to say the listener kept it. On the core path a
|
|
28
|
-
session does not recover a role message it missed.
|
|
19
|
+
The stream captures every agent subject, so it stores each forward there, and the holder's own
|
|
20
|
+
consumer delivers it once — also after a restart or a dropped connection (below). No session
|
|
21
|
+
answers a receipt: a message sent through the listener's `POST /v1/messages/publish` waits only
|
|
22
|
+
for the stream's acknowledgement that it stored the forward, and answers the sender with an error
|
|
23
|
+
once four seconds pass without one. A role message no live holder can take is kept for the
|
|
24
|
+
session that claims the role next: that session is handed it once, within one hour of the keep,
|
|
25
|
+
and the publish answers 202 to say the listener kept it. A
|
|
26
|
+
`notifications.team.<name>` topic is stored like any other followed topic; every other
|
|
27
|
+
`notifications.` topic the stream does not capture is refused by name, at publish and at
|
|
28
|
+
subscribe, because no session would ever be delivered it.
|
|
29
29
|
|
|
30
30
|
This extension claims the role for the session the host has open, and every automatic claim is
|
|
31
31
|
soft: it names the session it continues, which is a fork's or branch's parent, or the session
|
|
@@ -87,35 +87,33 @@ details result, including subscriptions whose stream currently has no matching e
|
|
|
87
87
|
The session's messages come from a durable consumer the listener keeps for it on Envoy's
|
|
88
88
|
notification stream and relays on `notifications.envoy.deliver.<session id>`, which
|
|
89
89
|
the session subscribes before it registers: its own agent subject, the stored copies of role
|
|
90
|
-
messages to a role it holds, and every followed topic
|
|
90
|
+
messages to a role it holds, and every followed topic, in stream order. No session receives from
|
|
91
|
+
any other NATS subscription. The
|
|
91
92
|
session answers each frame `received` as it decodes and `done` once Oh My Pi wrote the card or
|
|
92
93
|
turn to the session file, so a frame not written when the session stops, or published while it
|
|
93
|
-
was down or disconnected, comes again and is shown once, for up to 72 hours.
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
was down or disconnected, comes again and is shown once, for up to 72 hours. A
|
|
95
|
+
`notifications.team.<name>` topic is stored and delivered like any other followed topic.
|
|
96
|
+
"Consumer delivery" in `AGENTS.md` has the rules, and
|
|
96
97
|
`packages/envoy/AGENTS.md`, "Session consumers", states them once for every host.
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
its listener (`POST /v1/replay`) for what the stream stored on its own agent subject and on each
|
|
103
|
-
topic it follows, after the place it last read to, and shows each missed message once, as a card
|
|
104
|
-
saying it was published while the connection was down. The session pings NATS every 10 seconds
|
|
99
|
+
A message published while the session's NATS connection was down, or while the session was not
|
|
100
|
+
running, waits in that consumer: nothing has to be fetched back. It is shown once when the
|
|
101
|
+
session returns, as a card whose last line says it was published while the connection was down.
|
|
102
|
+
The session pings NATS every 10 seconds
|
|
105
103
|
and drops a connection that leaves two pings unanswered, so a connection that stops answering
|
|
106
|
-
without closing is left within 30 seconds and redialed
|
|
107
|
-
|
|
108
|
-
delivery
|
|
109
|
-
runs nothing.
|
|
110
|
-
|
|
111
|
-
registered
|
|
112
|
-
followed the topic, or published before the session first ran this plugin. A message the session
|
|
104
|
+
without closing is left within 30 seconds and redialed, and the listener restarts the relay at
|
|
105
|
+
the consumer's ack floor. A targeted Dispatch
|
|
106
|
+
delivery shown this way (BTW, Aside, Steer, a person's Send) is shown as that card only and
|
|
107
|
+
runs nothing. What the consumer does not hold: anything older than 72 hours, anything published
|
|
108
|
+
before the session followed the topic, and anything published before the session first
|
|
109
|
+
registered. A message the session
|
|
113
110
|
fails to show three times is replaced by one card naming it and saying how to read it. The
|
|
114
|
-
session file keeps what it was shown
|
|
115
|
-
|
|
116
|
-
showing a message and recording it can show it twice, never lose it.
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
session file keeps what it was shown, so a restart shows nothing again (up to 20,000 messages
|
|
112
|
+
shown in 72 hours); a crash between
|
|
113
|
+
showing a message and recording it can show it twice, never lose it. A registration the listener
|
|
114
|
+
can give no consumer is refused by name, and the session says once that Envoy inbound is
|
|
115
|
+
unavailable and asks again at every heartbeat. "Each frame shown once" in `AGENTS.md` has the
|
|
116
|
+
full rules.
|
|
119
117
|
|
|
120
118
|
## Session identity
|
|
121
119
|
|
|
@@ -316,10 +314,12 @@ session's subscriptions, as the Envoy listener records them, covers that owner.
|
|
|
316
314
|
The shared specs in `@legion/contracts` supply each command's description and flags:
|
|
317
315
|
`@legion/envoy-client`'s `dispatch-command.ts` derives one command per spec and one flag per field.
|
|
318
316
|
|
|
319
|
-
`dispatch artifact` takes
|
|
320
|
-
|
|
321
|
-
with
|
|
322
|
-
|
|
317
|
+
`dispatch artifact` takes at most one upload source: a local `--path`, or inline `--content`.
|
|
318
|
+
With neither, it makes an empty document under `--name`, which a person or an agent writes in
|
|
319
|
+
afterwards with `dispatch doc-edit`. For example, an architect can post a specification directly,
|
|
320
|
+
its text on stdin. Every issue is created with a `spec.md`, and the command refuses an upload
|
|
321
|
+
under the name of a document the issue already holds, so this one carries `--force`, which writes
|
|
322
|
+
the next version of it:
|
|
323
323
|
|
|
324
324
|
```sh
|
|
325
325
|
dispatch artifact --issue LEGION-1 --name spec.md --content-file - --force <<'EOF'
|
|
@@ -327,12 +327,12 @@ dispatch artifact --issue LEGION-1 --name spec.md --content-file - --force <<'EO
|
|
|
327
327
|
EOF
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
Inline content is stored as a Markdown document, so `--content
|
|
331
|
-
`--name` that ends in `.md` or `.markdown` or has no extension. The
|
|
332
|
-
(`rows.jsonl`, `sizes.tsv`, `rows.jsonl.1`, `plan v1.2`) before it
|
|
333
|
-
`--path`, which stores a file whose path does not end in `.md` or
|
|
334
|
-
unchanged, under that name. A document title with a dot near its end
|
|
335
|
-
ends in `.md`.
|
|
330
|
+
Inline content is stored as a Markdown document, so `--content`, `--content-file` and a call with
|
|
331
|
+
neither flag take only a `--name` that ends in `.md` or `.markdown` or has no extension. The
|
|
332
|
+
command refuses any other name (`rows.jsonl`, `sizes.tsv`, `rows.jsonl.1`, `plan v1.2`) before it
|
|
333
|
+
sends anything and names `--path`, which stores a file whose path does not end in `.md` or
|
|
334
|
+
`.markdown` as its bytes, unchanged, under that name. A document title with a dot near its end
|
|
335
|
+
takes `--content` once it ends in `.md`.
|
|
336
336
|
|
|
337
337
|
`dispatch handoff-write --issue <KEY> --phase <phase> --body-file <path>` records a Legion phase
|
|
338
338
|
handoff on its issue as this session: the file's text, one JSON object, is stored exactly as
|
package/dist/dispatch.js
CHANGED
|
@@ -14604,6 +14604,9 @@ function isPictureType(mime) {
|
|
|
14604
14604
|
}
|
|
14605
14605
|
|
|
14606
14606
|
// ../contracts/src/subject.ts
|
|
14607
|
+
var AGENT_TOPIC_PREFIX = "notifications.agent.";
|
|
14608
|
+
var ROLE_TOPIC_PREFIX = "notifications.role.";
|
|
14609
|
+
var LEGION_NOTICE_TOPIC_PREFIX = "notifications.legion.";
|
|
14607
14610
|
var DISPATCH_TOPIC_PREFIX = "notifications.dispatch.";
|
|
14608
14611
|
var DISPATCH_ISSUE_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}issue.`;
|
|
14609
14612
|
var DISPATCH_DOCUMENT_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}document.`;
|
|
@@ -14613,6 +14616,7 @@ function dispatchIssueSubject(issueKey, type) {
|
|
|
14613
14616
|
function dispatchDocumentSubject(project, slug, type) {
|
|
14614
14617
|
return `${DISPATCH_DOCUMENT_TOPIC_PREFIX}${project}.${slug}.${type}`;
|
|
14615
14618
|
}
|
|
14619
|
+
var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
|
|
14616
14620
|
|
|
14617
14621
|
// ../contracts/src/legion-roles.ts
|
|
14618
14622
|
var GATED_STEPS = ["decisions", "criteria", "spec"];
|
|
@@ -14853,6 +14857,8 @@ var ArtifactCreatedEventPayloadSchema = object({
|
|
|
14853
14857
|
name: artifactFields.name.optional()
|
|
14854
14858
|
}).optional()
|
|
14855
14859
|
});
|
|
14860
|
+
var ArtifactRenamedEventPayloadSchema = strictObject({ artifact: ArtifactSchema, previous_name: string2() }).readonly();
|
|
14861
|
+
var ArtifactRemovedEventPayloadSchema = strictObject({ artifact: ArtifactSchema }).readonly();
|
|
14856
14862
|
var artifactVersionEventPayloadFields = {
|
|
14857
14863
|
artifact_id: string2(),
|
|
14858
14864
|
name: string2(),
|
|
@@ -14948,15 +14954,16 @@ function documentOwnerValidation(requireArtifact, alwaysRequireArtifact = false)
|
|
|
14948
14954
|
message: alwaysRequireArtifact ? "Exactly one of issue and project is required; artifact or ref must name the document." : "Exactly one of issue and project is required; with project, artifact names the document."
|
|
14949
14955
|
};
|
|
14950
14956
|
}
|
|
14951
|
-
var ARTIFACT_SOURCE_RULE = "
|
|
14957
|
+
var ARTIFACT_SOURCE_RULE = "Give at most one of path and content. A call with neither makes an empty document under the name, which a person or an agent writes in afterwards with dispatch doc-edit.";
|
|
14952
14958
|
var ARTIFACT_OWNER_AND_SOURCE_RULE = `${ARTIFACT_SOURCE_RULE} Exactly one of issue and project is required; with project, artifact names the document.`;
|
|
14953
14959
|
function brokenParts(parts) {
|
|
14954
14960
|
const broken = parts.filter(([kept]) => !kept).map(([, message]) => message);
|
|
14955
14961
|
return broken.length === 0 ? undefined : broken.join(" ");
|
|
14956
14962
|
}
|
|
14957
14963
|
var CONTENT_IS_MARKDOWN = "content is stored as a Markdown document, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
|
|
14964
|
+
var DOCUMENT_IS_MARKDOWN = "a document holds Markdown, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
|
|
14958
14965
|
var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
|
|
14959
|
-
var ARTIFACT_CONTENT_NAME_RULE = `${CONTENT_IS_MARKDOWN}, so
|
|
14966
|
+
var ARTIFACT_CONTENT_NAME_RULE = `${CONTENT_IS_MARKDOWN}, so a document's name ends in .md or .markdown or has no extension, under content and under neither flag alike; upload any other file (.jsonl, .tsv, .json, .txt) with ${PATH_KEEPS_BYTES}.`;
|
|
14960
14967
|
var ARTIFACT_NAME_EXISTS_RULE = "An upload under the name of a document the owner already holds is refused: it writes that document's next version, over the text it holds. Change a document with dispatch doc-edit. Send the upload again with force (--force) to write the next version.";
|
|
14961
14968
|
var ARTIFACT_STORED_TEXT_RULE = `content and content-file hold text Dispatch stores as Markdown, and a text the store would write under another spelling is refused. The refusal prints the text Dispatch stores: send that text. A name that does not end in .md or .markdown has a second way out, which keeps the text as it was written: send it as a file with ${PATH_KEEPS_BYTES}.`;
|
|
14962
14969
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
@@ -14970,19 +14977,16 @@ function artifactProblem(value) {
|
|
|
14970
14977
|
const input = value;
|
|
14971
14978
|
const ownerOrSourceProblem = brokenParts([
|
|
14972
14979
|
[artifactOwner.check(value), artifactOwner.message],
|
|
14973
|
-
[
|
|
14974
|
-
typeof input.path === "string" !== (typeof input.content === "string"),
|
|
14975
|
-
ARTIFACT_SOURCE_RULE
|
|
14976
|
-
]
|
|
14980
|
+
[typeof input.path !== "string" || typeof input.content !== "string", ARTIFACT_SOURCE_RULE]
|
|
14977
14981
|
]);
|
|
14978
14982
|
if (ownerOrSourceProblem !== undefined)
|
|
14979
14983
|
return ownerOrSourceProblem;
|
|
14980
|
-
if (typeof input.
|
|
14984
|
+
if (typeof input.path === "string" || typeof input.name !== "string")
|
|
14981
14985
|
return;
|
|
14982
14986
|
const extension = NAME_EXTENSION.exec(input.name.trim())?.[1];
|
|
14983
14987
|
if (extension === undefined || MARKDOWN_EXTENSION.test(extension))
|
|
14984
14988
|
return;
|
|
14985
|
-
return `${
|
|
14989
|
+
return `${DOCUMENT_IS_MARKDOWN}, and ${JSON.stringify(input.name)} is not a Markdown name. Upload the file under the same name with ${PATH_KEEPS_BYTES}; a document takes a name ending in .md or .markdown or with no extension.`;
|
|
14986
14990
|
}
|
|
14987
14991
|
var documentEditOwner = documentOwnerValidation(true);
|
|
14988
14992
|
var PRECONDITION_RULE = "A precondition selects exactly one of document or blocks.";
|
|
@@ -15533,7 +15537,7 @@ var dispatchToolSpecs = [
|
|
|
15533
15537
|
name: "dispatch_artifact",
|
|
15534
15538
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
15535
15539
|
` },
|
|
15536
|
-
description: "Attach a local file or inline text as an issue artifact or project document. Do not use it to edit a live document; use " + "dispatch doc-edit instead. Never upload a document's own name to change it (spec.md replaces the spec whole); edit it with dispatch doc-edit.
|
|
15540
|
+
description: "Attach a local file or inline text as an issue artifact or project document, or make an empty document from its name alone. Do not use it to edit a live document; use " + "dispatch doc-edit instead. Never upload a document's own name to change it (spec.md replaces the spec whole); edit it with dispatch doc-edit. " + `${ARTIFACT_SOURCE_RULE} ` + `${ARTIFACT_NAME_EXISTS_RULE} A call that stores nothing - no path, and content absent or blank - is refused under a held name even with force, so a title typed twice never empties the document that holds it. ` + "A markdown document is at most 1 MiB and any other file at most 25 MiB. " + `${ARTIFACT_CONTENT_NAME_RULE} ${ARTIFACT_STORED_TEXT_RULE} ` + "Markdown is also refused with 413 CAP_EXCEEDED when it makes more than 65,536 elements (a block weighs 3, and an empty list item, quote, footnote definition or typed block 3 more for the empty paragraph it holds; a table cell 4, a hard line break 3, an image 3, a piece of inline HTML 2, an autolink 2, a footnote reference 2; inline syntax, marks, lines of text and backslash escapes or character references 1 each), or when a new version would leave the document's stored markdown (what its text reads back as) longer than 1 MiB or making more than 65,536 elements, and longer or heavier than before; shorten it or split it across documents. " + "In a table row, write every | in a cell as \\|, in code too: a | after two backslashes ends the cell, and a row with more cells than its table is refused. " + "Markdown holding an ask block whose body breaks its content rule (one or more question paragraphs, then at most one bullet list of options, last) is refused with 400 INVALID_ASK_BLOCK; a new version of a document is held to it only for the asks it writes or changes. " + `${OWNER_REFERENCE}`,
|
|
15537
15541
|
arguments: (z) => ({
|
|
15538
15542
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15539
15543
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
@@ -19105,8 +19109,9 @@ class DispatchClient {
|
|
|
19105
19109
|
return { status: response.status, payload: await this.#response(method, url, response) };
|
|
19106
19110
|
}
|
|
19107
19111
|
async#upload(path, input, key) {
|
|
19108
|
-
if (
|
|
19112
|
+
if (input.file === undefined) {
|
|
19109
19113
|
return this.#json("POST", path, input, undefined, undefined, key);
|
|
19114
|
+
}
|
|
19110
19115
|
const form = new FormData;
|
|
19111
19116
|
form.set("name", input.name);
|
|
19112
19117
|
if (input.summary !== undefined)
|
|
@@ -22537,13 +22542,17 @@ function withoutFinalLineFeed(text) {
|
|
|
22537
22542
|
return text.endsWith(`
|
|
22538
22543
|
`) ? text.slice(0, -1) : text;
|
|
22539
22544
|
}
|
|
22545
|
+
var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
|
|
22540
22546
|
async function artifactCommand(context) {
|
|
22541
22547
|
const { args, client, actor, input, documentOwner, issue } = context;
|
|
22542
22548
|
const summary = optionalString(args, "summary");
|
|
22543
22549
|
const name = stringArg(args, "name");
|
|
22544
22550
|
const content = optionalString(args, "content");
|
|
22551
|
+
const path = optionalString(args, "path");
|
|
22552
|
+
const options = { name, ...summary === undefined ? {} : { summary }, actor };
|
|
22545
22553
|
const artifactOwner = documentOwner();
|
|
22546
|
-
|
|
22554
|
+
const blank = content === undefined || goBlankPattern.test(content);
|
|
22555
|
+
if ((path !== undefined || !blank) && optionalBoolean(args, "force") !== true) {
|
|
22547
22556
|
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
22548
22557
|
if (held !== undefined) {
|
|
22549
22558
|
throw new ToolInputError(input.tool, [
|
|
@@ -22551,7 +22560,7 @@ async function artifactCommand(context) {
|
|
|
22551
22560
|
]);
|
|
22552
22561
|
}
|
|
22553
22562
|
}
|
|
22554
|
-
if (
|
|
22563
|
+
if (!blank) {
|
|
22555
22564
|
let stored;
|
|
22556
22565
|
try {
|
|
22557
22566
|
stored = await client.markdownRoundTrip(content);
|
|
@@ -22564,19 +22573,12 @@ async function artifactCommand(context) {
|
|
|
22564
22573
|
throw new ToolInputError(input.tool, [storedTextProblem(content, stored, name)]);
|
|
22565
22574
|
}
|
|
22566
22575
|
}
|
|
22567
|
-
const artifactInput =
|
|
22568
|
-
|
|
22569
|
-
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd,
|
|
22570
|
-
type: Bun.file(resolvePath2(input.cwd,
|
|
22571
|
-
})
|
|
22572
|
-
|
|
22573
|
-
actor
|
|
22574
|
-
} : {
|
|
22575
|
-
name,
|
|
22576
|
-
content,
|
|
22577
|
-
...summary === undefined ? {} : { summary },
|
|
22578
|
-
actor
|
|
22579
|
-
};
|
|
22576
|
+
const artifactInput = path !== undefined ? {
|
|
22577
|
+
...options,
|
|
22578
|
+
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, path)) : new Blob([new Uint8Array(input.uploadBytes)], {
|
|
22579
|
+
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
22580
|
+
})
|
|
22581
|
+
} : content !== undefined ? { ...options, content } : options;
|
|
22580
22582
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
22581
22583
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
22582
22584
|
const uploadOwner = artifactOwner.kind === "project" ? documentTopic(result.artifact) : issueTopic(issue());
|
|
@@ -22585,7 +22587,7 @@ async function artifactCommand(context) {
|
|
|
22585
22587
|
});
|
|
22586
22588
|
return {
|
|
22587
22589
|
text: [
|
|
22588
|
-
`Uploaded ${result.artifact.name} as version ${result.version.number} (artifact slug ${result.artifact.slug}; ${artifactRef})${await notSubscribed(uploadOwner, input.subscriptions)}`,
|
|
22590
|
+
path === undefined && content === undefined ? `Made ${result.artifact.name} as an empty document (artifact slug ${result.artifact.slug}; ${artifactRef}). Write in it with dispatch doc-edit.${await notSubscribed(uploadOwner, input.subscriptions)}` : `Uploaded ${result.artifact.name} as version ${result.version.number} (artifact slug ${result.artifact.slug}; ${artifactRef})${await notSubscribed(uploadOwner, input.subscriptions)}`,
|
|
22589
22591
|
...adviceLines
|
|
22590
22592
|
].join(`
|
|
22591
22593
|
`),
|
|
@@ -27408,8 +27410,34 @@ function sessionEnvoySettings(file, env, options) {
|
|
|
27408
27410
|
});
|
|
27409
27411
|
}
|
|
27410
27412
|
|
|
27413
|
+
// ../envoy-client/src/stream-topics.ts
|
|
27414
|
+
var EXCEPTION_TOPIC_PREFIX = "notifications.envoy.exceptions.";
|
|
27415
|
+
var STREAM_SUBJECT_PREFIXES = [
|
|
27416
|
+
AGENT_TOPIC_PREFIX,
|
|
27417
|
+
DISPATCH_TOPIC_PREFIX,
|
|
27418
|
+
"notifications.github.",
|
|
27419
|
+
"notifications.slack.",
|
|
27420
|
+
LEGION_NOTICE_TOPIC_PREFIX,
|
|
27421
|
+
GHOSTWISPR_TOPIC_PREFIX,
|
|
27422
|
+
"notifications.whatsapp.",
|
|
27423
|
+
"notifications.team.",
|
|
27424
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}`,
|
|
27425
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.`
|
|
27426
|
+
];
|
|
27427
|
+
function streamStores(topic) {
|
|
27428
|
+
return STREAM_SUBJECT_PREFIXES.some((prefix) => topic.length > prefix.length && topic.startsWith(prefix));
|
|
27429
|
+
}
|
|
27430
|
+
function streamDeliversNothing(topic) {
|
|
27431
|
+
return topic.startsWith("notifications.") && !topic.startsWith(ROLE_TOPIC_PREFIX) && !streamStores(topic);
|
|
27432
|
+
}
|
|
27433
|
+
var PRIVATE_STREAM_SUBJECTS = [
|
|
27434
|
+
`${AGENT_TOPIC_PREFIX}>`,
|
|
27435
|
+
`${LEGION_NOTICE_TOPIC_PREFIX}>`,
|
|
27436
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}>`,
|
|
27437
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.>`
|
|
27438
|
+
];
|
|
27439
|
+
|
|
27411
27440
|
// ../envoy-client/src/transport.ts
|
|
27412
|
-
var REPLAY_TIMEOUT_MS = 1e4;
|
|
27413
27441
|
var SessionStateSchema = _enum2(["live", "unresponsive", "gone"]);
|
|
27414
27442
|
var UNRESPONSIVE_RULE = "An unresponsive session is not dead: it keeps its role claims and its issue claims, and a " + "message sent to it is stored until it answers. Start no replacement for it and take no claim " + `from it until it is gone, or until ${ISSUE_CLAIM_UNRESPONSIVE_GRACE_MS / 60000} minutes ` + "have passed since its last_seen, the time of its last registration.";
|
|
27415
27443
|
var WireStateSchema = SessionStateSchema.default("live");
|
|
@@ -27421,16 +27449,13 @@ var InterestWireSchema = object({
|
|
|
27421
27449
|
updated_at: number2().int().optional(),
|
|
27422
27450
|
warnings: array(string2()).optional()
|
|
27423
27451
|
});
|
|
27424
|
-
var DeliveryAnswerWireSchema =
|
|
27425
|
-
|
|
27426
|
-
|
|
27427
|
-
|
|
27428
|
-
|
|
27429
|
-
|
|
27430
|
-
|
|
27431
|
-
}),
|
|
27432
|
-
object({ mode: literal("core"), reason: string2() })
|
|
27433
|
-
]);
|
|
27452
|
+
var DeliveryAnswerWireSchema = object({
|
|
27453
|
+
mode: literal("consumer"),
|
|
27454
|
+
subject: string2().min(1),
|
|
27455
|
+
stream_id: string2(),
|
|
27456
|
+
gap: boolean2(),
|
|
27457
|
+
consumer_start: number2().int().nonnegative().optional()
|
|
27458
|
+
});
|
|
27434
27459
|
var SessionWireSchema = object({
|
|
27435
27460
|
session_id: string2(),
|
|
27436
27461
|
machine_id: string2(),
|
|
@@ -27445,7 +27470,8 @@ var SessionWireSchema = object({
|
|
|
27445
27470
|
last_seen: number2().int().optional(),
|
|
27446
27471
|
state: WireStateSchema,
|
|
27447
27472
|
plugin: string2().optional(),
|
|
27448
|
-
plugin_version: string2().optional()
|
|
27473
|
+
plugin_version: string2().optional(),
|
|
27474
|
+
delivery: string2().optional()
|
|
27449
27475
|
});
|
|
27450
27476
|
var RoleWireSchema = object({
|
|
27451
27477
|
role: string2(),
|
|
@@ -27465,13 +27491,13 @@ var RoleHeldWireSchema = object({
|
|
|
27465
27491
|
var ErrorWireSchema = object({
|
|
27466
27492
|
error: string2(),
|
|
27467
27493
|
code: string2().optional(),
|
|
27494
|
+
reason: string2().optional(),
|
|
27468
27495
|
expected: array(string2()).optional(),
|
|
27469
27496
|
state: SessionStateSchema.optional(),
|
|
27470
27497
|
holder: string2().optional(),
|
|
27471
27498
|
holder_state: SessionStateSchema.optional(),
|
|
27472
27499
|
last_seen: number2().int().optional(),
|
|
27473
|
-
claim_released: boolean2().optional()
|
|
27474
|
-
unresponsive: array(string2()).optional()
|
|
27500
|
+
claim_released: boolean2().optional()
|
|
27475
27501
|
});
|
|
27476
27502
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
27477
27503
|
recipient: string2().optional(),
|
|
@@ -27479,46 +27505,30 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
|
27479
27505
|
holder_state: SessionStateSchema.optional(),
|
|
27480
27506
|
recipient_state: SessionStateSchema.optional(),
|
|
27481
27507
|
last_seen: number2().int().optional(),
|
|
27482
|
-
unresponsive: array(string2()).optional(),
|
|
27483
27508
|
duplicate: boolean2().optional()
|
|
27484
27509
|
});
|
|
27485
27510
|
var PublishResponseSchema = EnvelopeResponseSchema.extend({
|
|
27486
27511
|
kept: boolean2().optional(),
|
|
27487
27512
|
kept_reason: _enum2(["unclaimed", "holder_lapsed"]).optional()
|
|
27488
27513
|
});
|
|
27489
|
-
var
|
|
27490
|
-
|
|
27491
|
-
|
|
27492
|
-
created: string2(),
|
|
27493
|
-
first_seq: number2().int().nonnegative(),
|
|
27494
|
-
last_seq: number2().int().nonnegative()
|
|
27495
|
-
}),
|
|
27496
|
-
subjects: array(object({
|
|
27497
|
-
subject: string2(),
|
|
27498
|
-
messages: array(object({
|
|
27499
|
-
seq: number2().int().positive(),
|
|
27500
|
-
subject: string2(),
|
|
27501
|
-
time: string2(),
|
|
27502
|
-
data: string2()
|
|
27503
|
-
})),
|
|
27504
|
-
next_after: number2().int().nonnegative(),
|
|
27505
|
-
more: boolean2(),
|
|
27506
|
-
refused: string2().optional()
|
|
27507
|
-
}))
|
|
27514
|
+
var DeliveryRefusalSchema = object({
|
|
27515
|
+
mode: string2(),
|
|
27516
|
+
reason: string2().optional()
|
|
27508
27517
|
});
|
|
27509
|
-
var
|
|
27510
|
-
var DELIVERY_UNREADABLE = "unreadable_answer";
|
|
27518
|
+
var DELIVERY_UNREADABLE = "answered a delivery field this build cannot read";
|
|
27511
27519
|
function parseSubscribeAnswer(body) {
|
|
27512
27520
|
const interest = InterestWireSchema.parse(body);
|
|
27513
27521
|
const raw = typeof body === "object" && body !== null && "delivery" in body ? body.delivery : undefined;
|
|
27514
27522
|
if (raw === undefined || raw === null) {
|
|
27515
|
-
|
|
27523
|
+
throw new Error(`the listener answered no delivery for ${interest.session_id}: it predates session consumers, and a session receives only what its own consumer holds`);
|
|
27516
27524
|
}
|
|
27517
27525
|
const delivery = DeliveryAnswerWireSchema.safeParse(raw);
|
|
27518
|
-
|
|
27519
|
-
|
|
27520
|
-
|
|
27521
|
-
|
|
27526
|
+
if (!delivery.success) {
|
|
27527
|
+
const named = DeliveryRefusalSchema.safeParse(raw);
|
|
27528
|
+
const said = named.success ? `answered delivery mode ${named.data.mode}${named.data.reason === undefined ? "" : ` (${named.data.reason})`}` : DELIVERY_UNREADABLE;
|
|
27529
|
+
throw new Error(`the listener gave ${interest.session_id} no consumer: it ${said}, and a session receives only what its own consumer holds`);
|
|
27530
|
+
}
|
|
27531
|
+
return { ...interest, delivery: delivery.data };
|
|
27522
27532
|
}
|
|
27523
27533
|
function expandSubscriptionTopics(topics) {
|
|
27524
27534
|
const expanded = new Set;
|
|
@@ -27532,27 +27542,20 @@ function expandSubscriptionTopics(topics) {
|
|
|
27532
27542
|
if (segments.length < 2 || segments.some((segment) => segment.length === 0)) {
|
|
27533
27543
|
throw new TypeError(`cannot expand Envoy wildcard topic "${topic}": its concrete base must have at least two non-empty segments`);
|
|
27534
27544
|
}
|
|
27535
|
-
|
|
27545
|
+
if (!streamDeliversNothing(base))
|
|
27546
|
+
expanded.add(base);
|
|
27536
27547
|
expanded.add(topic);
|
|
27537
27548
|
}
|
|
27538
27549
|
return [...expanded];
|
|
27539
27550
|
}
|
|
27540
27551
|
function refusalStateText(parsed) {
|
|
27541
|
-
const sentences = [];
|
|
27542
27552
|
const state = parsed.holder_state ?? parsed.state;
|
|
27543
|
-
if (state
|
|
27544
|
-
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
27545
|
-
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
27546
|
-
sentences.push(`${who} is ${state}${seen}.`);
|
|
27547
|
-
}
|
|
27548
|
-
const stored = parsed.unresponsive ?? [];
|
|
27549
|
-
if (stored.length > 0) {
|
|
27550
|
-
const one = stored.length === 1;
|
|
27551
|
-
sentences.push(`Envoy stored the message for ${stored.join(", ")}.`, `${one ? "That session" : "Those sessions"} stopped answering, so ${one ? "it" : "they"} did not fail this send.`);
|
|
27552
|
-
}
|
|
27553
|
-
if (sentences.length === 0)
|
|
27553
|
+
if (state === undefined)
|
|
27554
27554
|
return "";
|
|
27555
|
-
|
|
27555
|
+
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
27556
|
+
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
27557
|
+
const sentences = [`${who} is ${state}${seen}.`];
|
|
27558
|
+
if (state === "unresponsive")
|
|
27556
27559
|
sentences.push(UNRESPONSIVE_RULE);
|
|
27557
27560
|
return ` ${sentences.join(" ")}`;
|
|
27558
27561
|
}
|
|
@@ -27562,11 +27565,11 @@ class EnvoyApiError extends Error {
|
|
|
27562
27565
|
name = "EnvoyApiError";
|
|
27563
27566
|
expected;
|
|
27564
27567
|
code;
|
|
27568
|
+
reason;
|
|
27565
27569
|
holder;
|
|
27566
27570
|
sessionState;
|
|
27567
27571
|
lastSeen;
|
|
27568
27572
|
claimReleased;
|
|
27569
|
-
unresponsive;
|
|
27570
27573
|
constructor(details) {
|
|
27571
27574
|
let parsed;
|
|
27572
27575
|
try {
|
|
@@ -27574,15 +27577,15 @@ class EnvoyApiError extends Error {
|
|
|
27574
27577
|
if (result.success)
|
|
27575
27578
|
parsed = result.data;
|
|
27576
27579
|
} catch {}
|
|
27577
|
-
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
|
|
27580
|
+
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
|
|
27578
27581
|
this.details = details;
|
|
27579
27582
|
this.expected = parsed?.expected;
|
|
27580
27583
|
this.code = parsed?.code;
|
|
27584
|
+
this.reason = parsed?.reason;
|
|
27581
27585
|
this.holder = parsed?.holder;
|
|
27582
27586
|
this.sessionState = parsed?.holder_state ?? parsed?.state;
|
|
27583
27587
|
this.lastSeen = parsed?.last_seen;
|
|
27584
27588
|
this.claimReleased = parsed?.claim_released;
|
|
27585
|
-
this.unresponsive = parsed?.unresponsive;
|
|
27586
27589
|
}
|
|
27587
27590
|
}
|
|
27588
27591
|
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|
|
@@ -27692,23 +27695,24 @@ function createEnvoyClient(config) {
|
|
|
27692
27695
|
headers: { "Content-Type": "application/json" },
|
|
27693
27696
|
body: JSON.stringify(body)
|
|
27694
27697
|
}, options);
|
|
27698
|
+
const subscribeBody = (input) => ({
|
|
27699
|
+
session_id: input.sessionID,
|
|
27700
|
+
dir: input.directory,
|
|
27701
|
+
topics: expandSubscriptionTopics(input.topics),
|
|
27702
|
+
port: input.port,
|
|
27703
|
+
title: input.title,
|
|
27704
|
+
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
27705
|
+
driving: input.driving,
|
|
27706
|
+
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
27707
|
+
delivery: input.delivery,
|
|
27708
|
+
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
27709
|
+
host: machineID(),
|
|
27710
|
+
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
27711
|
+
plugin: input.plugin.name,
|
|
27712
|
+
plugin_version: input.plugin.version
|
|
27713
|
+
});
|
|
27695
27714
|
return {
|
|
27696
|
-
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", {
|
|
27697
|
-
session_id: input.sessionID,
|
|
27698
|
-
dir: input.directory,
|
|
27699
|
-
topics: expandSubscriptionTopics(input.topics),
|
|
27700
|
-
port: input.port,
|
|
27701
|
-
title: input.title,
|
|
27702
|
-
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
27703
|
-
driving: input.driving,
|
|
27704
|
-
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
27705
|
-
...input.delivery === undefined ? {} : { delivery: input.delivery },
|
|
27706
|
-
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
27707
|
-
host: machineID(),
|
|
27708
|
-
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
27709
|
-
plugin: input.plugin.name,
|
|
27710
|
-
plugin_version: input.plugin.version
|
|
27711
|
-
}, { actingSession: input.sessionID }))),
|
|
27715
|
+
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", subscribeBody(input), { actingSession: input.sessionID }))),
|
|
27712
27716
|
unsubscribe: async (input) => {
|
|
27713
27717
|
await post("/v1/interests/unsubscribe", {
|
|
27714
27718
|
session_id: input.sessionID,
|
|
@@ -27767,7 +27771,6 @@ function createEnvoyClient(config) {
|
|
|
27767
27771
|
envelope: response,
|
|
27768
27772
|
...response.holder === undefined ? {} : { holder: response.holder },
|
|
27769
27773
|
...response.holder_state === undefined ? {} : { holderState: response.holder_state },
|
|
27770
|
-
unresponsive: response.unresponsive ?? [],
|
|
27771
27774
|
...response.kept === undefined ? {} : { kept: response.kept },
|
|
27772
27775
|
...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
|
|
27773
27776
|
};
|
|
@@ -27816,16 +27819,7 @@ function createEnvoyClient(config) {
|
|
|
27816
27819
|
search.set("include", input.include);
|
|
27817
27820
|
const query = search.size === 0 ? "" : `?${search.toString()}`;
|
|
27818
27821
|
return SessionWireSchema.array().parse(JSON.parse(await request(`/v1/sessions${query}`, {})));
|
|
27819
|
-
}
|
|
27820
|
-
replay: async (input) => ReplayWireSchema.parse(JSON.parse(await post("/v1/replay", {
|
|
27821
|
-
session_id: input.sessionID,
|
|
27822
|
-
subjects: input.subjects.map((cursor) => cursor.after === undefined ? { subject: cursor.subject } : { subject: cursor.subject, after: cursor.after }),
|
|
27823
|
-
...input.maxMessages === undefined ? {} : { max_messages: input.maxMessages }
|
|
27824
|
-
}, {
|
|
27825
|
-
timeoutMs: input.timeoutMs ?? REPLAY_TIMEOUT_MS,
|
|
27826
|
-
retry: false,
|
|
27827
|
-
actingSession: input.sessionID
|
|
27828
|
-
})))
|
|
27822
|
+
}
|
|
27829
27823
|
};
|
|
27830
27824
|
}
|
|
27831
27825
|
function waitForRetry(delayMs) {
|