@sjawhar/pi-envoy 11.2.0 → 11.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/README.md +18 -1
- package/dist/dispatch.js +88 -25
- package/dist/envoy.js +2026 -518
- package/dist/skills/envoy/SKILL.md +1 -1
- package/dist/skills/envoy/references/deliveries.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ a receipt-backed request with the original role topic to the holder's direct age
|
|
|
16
16
|
and it keeps open, listing them as kept, the subscriptions another plugin holds for that role.
|
|
17
17
|
The agent pump replies after accepting the envelope; without a receipt within two seconds the
|
|
18
18
|
listener emits a `delivery_failed` exception. Role messages are live only; they are not retained
|
|
19
|
-
for a later claimant.
|
|
19
|
+
for a later claimant, and a session does not recover one it missed.
|
|
20
20
|
|
|
21
21
|
`envoy_list()` shows the union of the local subscriptions and the listener's persisted interest
|
|
22
22
|
registry. Each reported interest identifies whether it is `live`, `registry`, or `both`, so
|
|
@@ -34,6 +34,23 @@ and `summary`) for recovery after an interrupt. `envoy_role_get` returns the cur
|
|
|
34
34
|
last-seen timestamp for a role. `envoy_subscribe` reports listener warnings in both its text and
|
|
35
35
|
details result, including subscriptions whose stream currently has no matching event.
|
|
36
36
|
|
|
37
|
+
A message published while the session's NATS connection or one of its subscriptions was down is
|
|
38
|
+
recovered from Envoy's notification stream, which keeps messages for 72 hours: the session asks
|
|
39
|
+
its listener (`POST /v1/replay`) for what the stream stored on its own agent subject and on each
|
|
40
|
+
topic it follows, after the place it last read to, and shows each missed message once, as a card
|
|
41
|
+
saying it was published while the connection was down. It asks after it reconnects, after a
|
|
42
|
+
subscription is reopened, when it starts or resumes, and on every heartbeat. A targeted Dispatch
|
|
43
|
+
delivery recovered this way (BTW, Aside, Steer, a person's Send) is shown as that card only and
|
|
44
|
+
runs nothing. Role messages and team or other ad-hoc topics are live only and are not recovered,
|
|
45
|
+
and neither is anything older than 72 hours, published before the session followed the topic, or
|
|
46
|
+
published before the session first ran this plugin. A message the session fails to show three
|
|
47
|
+
times is replaced by one card naming it and saying how to read it. The session file keeps what
|
|
48
|
+
it was shown and where it read to, so a restart skips nothing the stream still holds and shows
|
|
49
|
+
nothing again (up to 20,000 messages shown in 72 hours); a crash between showing a message and
|
|
50
|
+
recording it can show it twice, never lose it. Against a listener without the route, the session
|
|
51
|
+
warns once that missed messages are not recovered, and live delivery goes on as before. "Missed
|
|
52
|
+
messages" in `AGENTS.md` has the full rules.
|
|
53
|
+
|
|
37
54
|
## Session identity
|
|
38
55
|
|
|
39
56
|
Run `/whoami` to copy the active session ID to the clipboard. OMP copies through its host
|
package/dist/dispatch.js
CHANGED
|
@@ -13602,6 +13602,15 @@ var ArtifactVersionEventPayloadSchema = exports_external.object({
|
|
|
13602
13602
|
version: exports_external.object({ number: exports_external.number().optional(), summary: exports_external.string().nullish() }).optional(),
|
|
13603
13603
|
diff: exports_external.string().optional()
|
|
13604
13604
|
});
|
|
13605
|
+
var ArtifactHumanEditedEventPayloadSchema = exports_external.object({
|
|
13606
|
+
artifact_id: exports_external.string().optional(),
|
|
13607
|
+
name: exports_external.string().optional(),
|
|
13608
|
+
from_version: exports_external.number().int().optional(),
|
|
13609
|
+
to_version: exports_external.number().int().optional(),
|
|
13610
|
+
editors: exports_external.array(exports_external.string()).optional(),
|
|
13611
|
+
diff: exports_external.string().optional(),
|
|
13612
|
+
diff_truncated: exports_external.boolean().optional()
|
|
13613
|
+
});
|
|
13605
13614
|
var ArtifactReviewEventPayloadSchema = exports_external.object({
|
|
13606
13615
|
artifact_id: exports_external.string().optional(),
|
|
13607
13616
|
name: exports_external.string().optional(),
|
|
@@ -14312,7 +14321,7 @@ var dispatchToolSpecs = [
|
|
|
14312
14321
|
ops: [{ op: "delete_column", block: "table-123", index: 1 }],
|
|
14313
14322
|
precondition: { blocks: [{ id: "table-123", token: "sha256:current-table-token" }] }
|
|
14314
14323
|
},
|
|
14315
|
-
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " + `For replace, delete, and quote anchors, find text as rendered: inline Markdown (**bold**, \`code\`) is tolerated and must be balanced; a leading '# ' matches a heading at any level. replace is inline: with is the new text of the matched span, so a marker of a different kind from the block's own stays literal text ('4. Design' written into a heading). A with that opens with a marker of the same kind as the matched block's own would write it twice and is INVALID_OP - including prose that merely looks like one ('1999. was a year' into an ordered item), which you write as text by escaping it ('1999\\. was a year'). The exception is a heading rename whose find carried a heading marker: replace(find="## Old", with="## New") gives '## New', and a different level applies only when find named the heading's actual level (find "## Old" with "### New" makes it an h3), since '# ' selects a heading without naming its level. A task item (\`- [ ]\` / \`- [x]\`) is ticked the same way: when find matches from the start of the item's text and with opens with '[x] ' or '[ ] ', the opening sets the item's box and the rest is its new text (replace(find="Write it", with="[x] Write it") ticks it); the same opening over a plain list item or a paragraph stays literal text. Any non-empty with that renders to no text - a line indented four spaces or a tab, which markdown reads as a code block, or whitespace alone - is INVALID_OP rather than a silent deletion; pass an empty with to delete the matched text on purpose - a list item, quote, typed block or footnote definition left holding only the emptied paragraph keeps it. ` + "with cannot open a new block: after a hard line break inside with (two trailing spaces, or a backslash, before the newline) a heading, bullet, '1.'/'1)' ordered, or '>' blockquote marker is INVALID_OP too, since that line would stay escaped text inside the matched block - use insert, plus delete for what it replaces, to add the block. A hard break in with is itself INVALID_OP when the matched text is in a heading or a table cell, which are written on one line. " + "A delete whose find is a block's entire text removes the block (a list emptied of its items goes too); delete with block removes any block by id, and move with block relocates one. A delete or retype that would take an ask block out of the document while its ask is open is refused, with nothing sent. delete_row and delete_column take a table block and a zero-based index, preserving the table block id and refusing to remove cells with open asks or unresolved comments. " + `Insert and move anchors also accept "start", "end", "heading:<exact heading text>", and "block:<id>"; dispatch doc-read --blocks lists every block's id, type, opening words and token, and each table's rows and cells with the indexes delete_row and delete_column take (GET /api/v1/artifacts/{artifact UUID}/blocks serves the same list). ` + "Optionally require the state just read: precondition selects exactly one of a document token from dispatch doc-read, or block {id, token} values from dispatch doc-read --blocks. A block guard must include every block the batch changes; Dispatch resolves quote targets and rejects an uncovered batch rather than applying it. Use a document token for insert or move, which depend on document order. Prefer block tokens when the covered content blocks are independent sections. Tokens include inline marks, so a fresh human comment also makes a stale edit fail. PRECONDITION_FAILED means re-read; EDIT_QUEUE_FULL means back off before retrying. " + "The result carries the document token this edit produced, so a chain of guarded edits passes each result's token as the next edit's precondition with no dispatch doc-read between them. " + "A batch that leaves the document exactly as it was mints no version, named or not, and the result says nothing changed and names each operation that did nothing. " + "A change a browser removes while the edit is in flight is never reported as applied: EDIT_LOST_TO_CONCURRENT_CHANGE means the write was refused and nothing was written, so re-read the document and decide again, as with PRECONDITION_FAILED; lost_ops on a successful result names operations whose text the live document no longer has, because the deletion landed after the version was written. " + "One replace per paragraph: more new paragraphs go in one insert after the last one you rewrote, since two inserts at one anchor come out reversed; read the passage back with dispatch doc-read afterwards. " + "A block id written as {#id} longer than 256 bytes is stored, but its block is no graph node, so no reference reaches it. " + `The spec holds requirements, design, and decisions - never progress, status, or timestamps; a record of open items or progress is a document of its own. ${OWNER_REFERENCE} ${SPEC_WRITING_POINTER}`,
|
|
14324
|
+
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " + `For replace, delete, and quote anchors, find text as rendered: inline Markdown (**bold**, \`code\`) is tolerated and must be balanced; a leading '# ' matches a heading at any level. replace is inline: with is the new text of the matched span, so a marker of a different kind from the block's own stays literal text ('4. Design' written into a heading). A with that opens with a marker of the same kind as the matched block's own would write it twice and is INVALID_OP - including prose that merely looks like one ('1999. was a year' into an ordered item), which you write as text by escaping it ('1999\\. was a year'). The exception is a heading rename whose find carried a heading marker: replace(find="## Old", with="## New") gives '## New', and a different level applies only when find named the heading's actual level (find "## Old" with "### New" makes it an h3), since '# ' selects a heading without naming its level. A task item (\`- [ ]\` / \`- [x]\`) is ticked the same way: when find matches from the start of the item's text and with opens with '[x] ' or '[ ] ', the opening sets the item's box and the rest is its new text (replace(find="Write it", with="[x] Write it") ticks it); the same opening over a plain list item or a paragraph stays literal text. Any non-empty with that renders to no text - a line indented four spaces or a tab, which markdown reads as a code block, or whitespace alone - is INVALID_OP rather than a silent deletion; pass an empty with to delete the matched text on purpose - a list item, quote, typed block or footnote definition left holding only the emptied paragraph keeps it. ` + "with cannot open a new block: after a hard line break inside with (two trailing spaces, or a backslash, before the newline) a heading, bullet, '1.'/'1)' ordered, or '>' blockquote marker is INVALID_OP too, since that line would stay escaped text inside the matched block - use insert, plus delete for what it replaces, to add the block. A hard break in with is itself INVALID_OP when the matched text is in a heading or a table cell, which are written on one line. In a table cell, with is the cell's text: write a | in it bare, in code too, since code whose text has an odd run of backslashes right before a | cannot be stored in a cell and is INVALID_OP, naming the cell. " + "A delete whose find is a block's entire text removes the block (a list emptied of its items goes too); delete with block removes any block by id, and move with block relocates one. A delete or retype that would take an ask block out of the document while its ask is open is refused, with nothing sent. delete_row and delete_column take a table block and a zero-based index, preserving the table block id and refusing to remove cells with open asks or unresolved comments. " + `Insert and move anchors also accept "start", "end", "heading:<exact heading text>", and "block:<id>"; dispatch doc-read --blocks lists every block's id, type, opening words and token, and each table's rows and cells with the indexes delete_row and delete_column take (GET /api/v1/artifacts/{artifact UUID}/blocks serves the same list). ` + "Optionally require the state just read: precondition selects exactly one of a document token from dispatch doc-read, or block {id, token} values from dispatch doc-read --blocks. A block guard must include every block the batch changes; Dispatch resolves quote targets and rejects an uncovered batch rather than applying it. Use a document token for insert or move, which depend on document order. Prefer block tokens when the covered content blocks are independent sections. Tokens include inline marks, so a fresh human comment also makes a stale edit fail. PRECONDITION_FAILED means re-read; EDIT_QUEUE_FULL means back off before retrying. " + "The result carries the document token this edit produced, so a chain of guarded edits passes each result's token as the next edit's precondition with no dispatch doc-read between them. " + "A batch that leaves the document exactly as it was mints no version, named or not, and the result says nothing changed and names each operation that did nothing. " + "A change a browser removes while the edit is in flight is never reported as applied: EDIT_LOST_TO_CONCURRENT_CHANGE means the write was refused and nothing was written, so re-read the document and decide again, as with PRECONDITION_FAILED; lost_ops on a successful result names operations whose text the live document no longer has, because the deletion landed after the version was written. " + "One replace per paragraph: more new paragraphs go in one insert after the last one you rewrote, since two inserts at one anchor come out reversed; read the passage back with dispatch doc-read afterwards. " + "A block id written as {#id} longer than 256 bytes is stored, but its block is no graph node, so no reference reaches it. " + `The spec holds requirements, design, and decisions - never progress, status, or timestamps; a record of open items or progress is a document of its own. ${OWNER_REFERENCE} ${SPEC_WRITING_POINTER}`,
|
|
14316
14325
|
arguments: (z2) => ({
|
|
14317
14326
|
issue: z2.string().describe(ISSUE_REFERENCE).optional(),
|
|
14318
14327
|
project: z2.string().describe("Project key owning the document.").optional(),
|
|
@@ -14372,7 +14381,7 @@ var dispatchToolSpecs = [
|
|
|
14372
14381
|
name: "dispatch_artifact",
|
|
14373
14382
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
14374
14383
|
` },
|
|
14375
|
-
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. Uploading the same name again makes its next version. Exactly one of path or content is required; a markdown document is at most 1 MiB and any other file at most 25 MiB. " + "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. " + "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}`,
|
|
14384
|
+
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. Uploading the same name again makes its next version. Exactly one of path or content is required; a markdown document is at most 1 MiB and any other file at most 25 MiB. " + "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}`,
|
|
14376
14385
|
arguments: (z2) => ({
|
|
14377
14386
|
issue: z2.string().describe(ISSUE_REFERENCE).optional(),
|
|
14378
14387
|
project: z2.string().describe("Project key for an unlinked document.").optional(),
|
|
@@ -16318,6 +16327,13 @@ function subscriptionCovers(topic, owner) {
|
|
|
16318
16327
|
return false;
|
|
16319
16328
|
}
|
|
16320
16329
|
|
|
16330
|
+
// ../envoy-client/src/human-edit.ts
|
|
16331
|
+
function humanEditHead(edit) {
|
|
16332
|
+
const editors = edit.editors ?? [];
|
|
16333
|
+
const by = editors.length === 0 ? "" : `, edited by ${editors.join(", ")}`;
|
|
16334
|
+
return `${edit.name ?? "document"} v${edit.from_version ?? "?"} to v${edit.to_version ?? "?"}${by}`;
|
|
16335
|
+
}
|
|
16336
|
+
|
|
16321
16337
|
// ../envoy-client/src/search-answer.ts
|
|
16322
16338
|
function pageSummaryText(offset, count, total) {
|
|
16323
16339
|
return `showing ${offset + 1}-${offset + count} of ${total}`;
|
|
@@ -17407,12 +17423,12 @@ function issueSummary(issue2, events, references, graph, linkBase, titles) {
|
|
|
17407
17423
|
].join(`
|
|
17408
17424
|
`);
|
|
17409
17425
|
}
|
|
17410
|
-
function referenceLines(
|
|
17411
|
-
if (typeof
|
|
17412
|
-
return [`- ${
|
|
17413
|
-
if (edges.length === 0)
|
|
17426
|
+
function referenceLines(read) {
|
|
17427
|
+
if (typeof read === "string")
|
|
17428
|
+
return [`- ${read}`];
|
|
17429
|
+
if (read.edges.length === 0)
|
|
17414
17430
|
return ["- none"];
|
|
17415
|
-
return edges.map((edge) => {
|
|
17431
|
+
return read.edges.map((edge) => {
|
|
17416
17432
|
const excerpt2 = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
|
|
17417
17433
|
const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
|
|
17418
17434
|
return `- ${edge.kind} ${edge.node.kind} ${edge.node.ref ?? edge.node.id} (${excerpt2}${edge.created_at})${block}`;
|
|
@@ -17421,9 +17437,9 @@ function referenceLines(edges) {
|
|
|
17421
17437
|
function unavailableReason(error48) {
|
|
17422
17438
|
return dispatchAnswered(error48, 404) ? "unavailable" : `unavailable: ${messageFor(error48)}`;
|
|
17423
17439
|
}
|
|
17424
|
-
async function
|
|
17440
|
+
async function graphReferences(client, query) {
|
|
17425
17441
|
try {
|
|
17426
|
-
return
|
|
17442
|
+
return await client.getReferences(query);
|
|
17427
17443
|
} catch (error48) {
|
|
17428
17444
|
return unavailableReason(error48);
|
|
17429
17445
|
}
|
|
@@ -17437,13 +17453,31 @@ async function issueReferencesOrUnavailable(client, key) {
|
|
|
17437
17453
|
}
|
|
17438
17454
|
async function graphSections(client, ref) {
|
|
17439
17455
|
const [incoming, outgoing] = await Promise.all([
|
|
17440
|
-
|
|
17441
|
-
|
|
17456
|
+
graphReferences(client, { to: ref }),
|
|
17457
|
+
graphReferences(client, { from: ref })
|
|
17442
17458
|
]);
|
|
17443
17459
|
return graphSectionLines(incoming, outgoing);
|
|
17444
17460
|
}
|
|
17445
17461
|
function graphSectionLines(incoming, outgoing) {
|
|
17446
|
-
return [
|
|
17462
|
+
return [
|
|
17463
|
+
...typeof incoming === "string" ? [] : nodeLine(incoming.node),
|
|
17464
|
+
"Referenced by:",
|
|
17465
|
+
...referenceLines(incoming),
|
|
17466
|
+
"Links:",
|
|
17467
|
+
...referenceLines(outgoing)
|
|
17468
|
+
];
|
|
17469
|
+
}
|
|
17470
|
+
function nodeLine(node) {
|
|
17471
|
+
if (node.made_by === undefined)
|
|
17472
|
+
return [];
|
|
17473
|
+
const fact = (by, time3) => `${by === undefined || by.length === 0 ? "nobody recorded" : by.map(actorText).join(", ")}${time3 == null ? "" : ` at ${time3}`}`;
|
|
17474
|
+
const made = fact(node.made_by, node.made_at);
|
|
17475
|
+
const changed = fact(node.changed_by, node.changed_at);
|
|
17476
|
+
const { parent } = node;
|
|
17477
|
+
const partOf = parent == null ? "" : ` \xB7 part of ${parent.ref ?? `${parent.kind} ${parent.id}`}${node.parent_version == null ? "" : ` (version ${node.parent_version})`}`;
|
|
17478
|
+
return [
|
|
17479
|
+
`Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
|
|
17480
|
+
];
|
|
17447
17481
|
}
|
|
17448
17482
|
function blockLines(node, ref) {
|
|
17449
17483
|
const head = [
|
|
@@ -17497,6 +17531,8 @@ function eventHead(event) {
|
|
|
17497
17531
|
return textHead(event.payload.body);
|
|
17498
17532
|
case "artifact.version":
|
|
17499
17533
|
return textHead(`${event.payload.name} v${event.payload.version.number}${event.payload.version.summary ? `: ${event.payload.version.summary}` : ""}`);
|
|
17534
|
+
case "artifact.human_edited":
|
|
17535
|
+
return textHead(humanEditHead(event.payload));
|
|
17500
17536
|
case "issue.created":
|
|
17501
17537
|
case "issue.updated":
|
|
17502
17538
|
case "issue.closed":
|
|
@@ -18839,13 +18875,10 @@ ${trailer.join(`
|
|
|
18839
18875
|
}
|
|
18840
18876
|
throw error48;
|
|
18841
18877
|
}),
|
|
18842
|
-
|
|
18878
|
+
graphReferences(client, { from: blockRef })
|
|
18843
18879
|
]);
|
|
18844
18880
|
return {
|
|
18845
|
-
text: [
|
|
18846
|
-
...blockLines(incoming.node, ref),
|
|
18847
|
-
...graphSectionLines(incoming.edges, outgoing)
|
|
18848
|
-
].join(`
|
|
18881
|
+
text: [...blockLines(incoming.node, ref), ...graphSectionLines(incoming, outgoing)].join(`
|
|
18849
18882
|
`),
|
|
18850
18883
|
details: {
|
|
18851
18884
|
...ref.owner.kind === "project" ? { project: ref.owner.project } : { issue: ref.owner.issue },
|
|
@@ -19793,6 +19826,7 @@ function sessionEnvoySettings(file2, env, options) {
|
|
|
19793
19826
|
// ../envoy-client/src/transport.ts
|
|
19794
19827
|
var DEFAULT_TIMEOUT_MS = 5000;
|
|
19795
19828
|
var RETRY_DELAY_MS = 250;
|
|
19829
|
+
var REPLAY_TIMEOUT_MS = 1e4;
|
|
19796
19830
|
var InterestWireSchema = exports_external.object({
|
|
19797
19831
|
session_id: exports_external.string(),
|
|
19798
19832
|
machine_id: exports_external.string(),
|
|
@@ -19827,12 +19861,33 @@ var RoleHeldWireSchema = exports_external.object({
|
|
|
19827
19861
|
});
|
|
19828
19862
|
var ErrorWireSchema = exports_external.object({
|
|
19829
19863
|
error: exports_external.string(),
|
|
19864
|
+
code: exports_external.string().optional(),
|
|
19830
19865
|
expected: exports_external.array(exports_external.string()).optional()
|
|
19831
19866
|
});
|
|
19832
19867
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
19833
19868
|
recipient: exports_external.string().optional(),
|
|
19834
19869
|
holder: exports_external.string().optional()
|
|
19835
19870
|
});
|
|
19871
|
+
var ReplayWireSchema = exports_external.object({
|
|
19872
|
+
stream: exports_external.object({
|
|
19873
|
+
id: exports_external.string().min(1).optional(),
|
|
19874
|
+
created: exports_external.string(),
|
|
19875
|
+
first_seq: exports_external.number().int().nonnegative(),
|
|
19876
|
+
last_seq: exports_external.number().int().nonnegative()
|
|
19877
|
+
}),
|
|
19878
|
+
subjects: exports_external.array(exports_external.object({
|
|
19879
|
+
subject: exports_external.string(),
|
|
19880
|
+
messages: exports_external.array(exports_external.object({
|
|
19881
|
+
seq: exports_external.number().int().positive(),
|
|
19882
|
+
subject: exports_external.string(),
|
|
19883
|
+
time: exports_external.string(),
|
|
19884
|
+
data: exports_external.string()
|
|
19885
|
+
})),
|
|
19886
|
+
next_after: exports_external.number().int().nonnegative(),
|
|
19887
|
+
more: exports_external.boolean(),
|
|
19888
|
+
refused: exports_external.string().optional()
|
|
19889
|
+
}))
|
|
19890
|
+
});
|
|
19836
19891
|
function expandSubscriptionTopics(topics) {
|
|
19837
19892
|
const expanded = new Set;
|
|
19838
19893
|
for (const topic of topics) {
|
|
@@ -19855,6 +19910,7 @@ class EnvoyApiError extends Error {
|
|
|
19855
19910
|
details;
|
|
19856
19911
|
name = "EnvoyApiError";
|
|
19857
19912
|
expected;
|
|
19913
|
+
code;
|
|
19858
19914
|
constructor(details) {
|
|
19859
19915
|
let parsed;
|
|
19860
19916
|
try {
|
|
@@ -19865,16 +19921,18 @@ class EnvoyApiError extends Error {
|
|
|
19865
19921
|
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}`);
|
|
19866
19922
|
this.details = details;
|
|
19867
19923
|
this.expected = parsed?.expected;
|
|
19924
|
+
this.code = parsed?.code;
|
|
19868
19925
|
}
|
|
19869
19926
|
}
|
|
19870
19927
|
function createEnvoyClient(config2) {
|
|
19871
19928
|
const baseUrl = normalizeEnvoyUrl(config2.baseUrl);
|
|
19872
19929
|
const timeoutMs = config2.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
19873
19930
|
const apiToken = config2.token;
|
|
19874
|
-
const request = async (path2, init) => {
|
|
19931
|
+
const request = async (path2, init, options = {}) => {
|
|
19875
19932
|
const url2 = `${baseUrl}${path2}`;
|
|
19876
19933
|
const attempts = config2.retry === false ? 1 : 2;
|
|
19877
|
-
|
|
19934
|
+
const tries = options.retry === false ? 1 : attempts;
|
|
19935
|
+
for (let attempt = 0;attempt < tries; attempt += 1) {
|
|
19878
19936
|
let response;
|
|
19879
19937
|
try {
|
|
19880
19938
|
const headers = new Headers(init.headers);
|
|
@@ -19883,10 +19941,10 @@ function createEnvoyClient(config2) {
|
|
|
19883
19941
|
response = await config2.fetch(url2, {
|
|
19884
19942
|
...init,
|
|
19885
19943
|
headers,
|
|
19886
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
19944
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? timeoutMs)
|
|
19887
19945
|
});
|
|
19888
19946
|
} catch (error49) {
|
|
19889
|
-
if (attempt + 1 <
|
|
19947
|
+
if (attempt + 1 < tries) {
|
|
19890
19948
|
await waitForRetry();
|
|
19891
19949
|
continue;
|
|
19892
19950
|
}
|
|
@@ -19901,7 +19959,7 @@ function createEnvoyClient(config2) {
|
|
|
19901
19959
|
status: response.status,
|
|
19902
19960
|
responseBody
|
|
19903
19961
|
});
|
|
19904
|
-
if (response.status >= 500 && attempt + 1 <
|
|
19962
|
+
if (response.status >= 500 && attempt + 1 < tries) {
|
|
19905
19963
|
await waitForRetry();
|
|
19906
19964
|
continue;
|
|
19907
19965
|
}
|
|
@@ -19909,11 +19967,11 @@ function createEnvoyClient(config2) {
|
|
|
19909
19967
|
}
|
|
19910
19968
|
throw new Error("Envoy request exhausted retries");
|
|
19911
19969
|
};
|
|
19912
|
-
const post = (path2, body) => request(path2, {
|
|
19970
|
+
const post = (path2, body, options) => request(path2, {
|
|
19913
19971
|
method: "POST",
|
|
19914
19972
|
headers: { "Content-Type": "application/json" },
|
|
19915
19973
|
body: JSON.stringify(body)
|
|
19916
|
-
});
|
|
19974
|
+
}, options);
|
|
19917
19975
|
return {
|
|
19918
19976
|
subscribe: async (input) => InterestWireSchema.parse(JSON.parse(await post("/v1/interests/subscribe", {
|
|
19919
19977
|
session_id: input.sessionID,
|
|
@@ -19999,7 +20057,12 @@ function createEnvoyClient(config2) {
|
|
|
19999
20057
|
search.set("title", input.title);
|
|
20000
20058
|
const query = search.size === 0 ? "" : `?${search.toString()}`;
|
|
20001
20059
|
return SessionWireSchema.array().parse(JSON.parse(await request(`/v1/sessions${query}`, {})));
|
|
20002
|
-
}
|
|
20060
|
+
},
|
|
20061
|
+
replay: async (input) => ReplayWireSchema.parse(JSON.parse(await post("/v1/replay", {
|
|
20062
|
+
session_id: input.sessionID,
|
|
20063
|
+
subjects: input.subjects.map((cursor) => cursor.after === undefined ? { subject: cursor.subject } : { subject: cursor.subject, after: cursor.after }),
|
|
20064
|
+
...input.maxMessages === undefined ? {} : { max_messages: input.maxMessages }
|
|
20065
|
+
}, { timeoutMs: REPLAY_TIMEOUT_MS, retry: false })))
|
|
20003
20066
|
};
|
|
20004
20067
|
}
|
|
20005
20068
|
function waitForRetry() {
|