@sjawhar/claude-envoy 2.7.1 → 2.9.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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/AGENTS.md +67 -71
- package/README.md +26 -33
- package/dist/dispatch.js +159 -164
- package/dist/envoy-channel.js +717 -1385
- package/dist/session-hook.js +27 -78
- package/package.json +1 -1
- package/skills/envoy/SKILL.md +96 -22
- package/skills/envoy/references/deliveries.md +71 -15
- package/skills/envoy/references/legion.md +34 -8
- package/src/agent-stream-runner.ts +2 -2
- package/src/channel-topics.ts +148 -0
- package/src/envoy-channel-server.ts +279 -378
- package/src/replay-state.ts +17 -17
- package/src/channel-forwarder.ts +0 -262
package/dist/dispatch.js
CHANGED
|
@@ -14660,6 +14660,9 @@ function agentSubject(session) {
|
|
|
14660
14660
|
return `${AGENT_TOPIC_PREFIX}${session}`;
|
|
14661
14661
|
}
|
|
14662
14662
|
var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
|
|
14663
|
+
function uncapturedTopicRefusal(topic, sessionID) {
|
|
14664
|
+
return `${topic} was not registered: no stream subject captures it, so nothing would be delivered to ${sessionID} on it; follow a notifications.team.<name> topic instead`;
|
|
14665
|
+
}
|
|
14663
14666
|
|
|
14664
14667
|
// ../contracts/src/legion-roles.ts
|
|
14665
14668
|
var LEGION_ROLES = [
|
|
@@ -14945,6 +14948,8 @@ var ArtifactCreatedEventPayloadSchema = object({
|
|
|
14945
14948
|
name: artifactFields.name.optional()
|
|
14946
14949
|
}).optional()
|
|
14947
14950
|
});
|
|
14951
|
+
var ArtifactRenamedEventPayloadSchema = strictObject({ artifact: ArtifactSchema, previous_name: string2() }).readonly();
|
|
14952
|
+
var ArtifactRemovedEventPayloadSchema = strictObject({ artifact: ArtifactSchema }).readonly();
|
|
14948
14953
|
var artifactVersionEventPayloadFields = {
|
|
14949
14954
|
artifact_id: string2(),
|
|
14950
14955
|
name: string2(),
|
|
@@ -15040,15 +15045,16 @@ function documentOwnerValidation(requireArtifact, alwaysRequireArtifact = false)
|
|
|
15040
15045
|
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."
|
|
15041
15046
|
};
|
|
15042
15047
|
}
|
|
15043
|
-
var ARTIFACT_SOURCE_RULE = "
|
|
15048
|
+
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.";
|
|
15044
15049
|
var ARTIFACT_OWNER_AND_SOURCE_RULE = `${ARTIFACT_SOURCE_RULE} Exactly one of issue and project is required; with project, artifact names the document.`;
|
|
15045
15050
|
function brokenParts(parts) {
|
|
15046
15051
|
const broken = parts.filter(([kept]) => !kept).map(([, message]) => message);
|
|
15047
15052
|
return broken.length === 0 ? undefined : broken.join(" ");
|
|
15048
15053
|
}
|
|
15049
15054
|
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)";
|
|
15055
|
+
var DOCUMENT_IS_MARKDOWN = "a document holds Markdown, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
|
|
15050
15056
|
var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
|
|
15051
|
-
var ARTIFACT_CONTENT_NAME_RULE = `${CONTENT_IS_MARKDOWN}, so
|
|
15057
|
+
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}.`;
|
|
15052
15058
|
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.";
|
|
15053
15059
|
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}.`;
|
|
15054
15060
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
@@ -15062,19 +15068,16 @@ function artifactProblem(value) {
|
|
|
15062
15068
|
const input = value;
|
|
15063
15069
|
const ownerOrSourceProblem = brokenParts([
|
|
15064
15070
|
[artifactOwner.check(value), artifactOwner.message],
|
|
15065
|
-
[
|
|
15066
|
-
typeof input.path === "string" !== (typeof input.content === "string"),
|
|
15067
|
-
ARTIFACT_SOURCE_RULE
|
|
15068
|
-
]
|
|
15071
|
+
[typeof input.path !== "string" || typeof input.content !== "string", ARTIFACT_SOURCE_RULE]
|
|
15069
15072
|
]);
|
|
15070
15073
|
if (ownerOrSourceProblem !== undefined)
|
|
15071
15074
|
return ownerOrSourceProblem;
|
|
15072
|
-
if (typeof input.
|
|
15075
|
+
if (typeof input.path === "string" || typeof input.name !== "string")
|
|
15073
15076
|
return;
|
|
15074
15077
|
const extension = NAME_EXTENSION.exec(input.name.trim())?.[1];
|
|
15075
15078
|
if (extension === undefined || MARKDOWN_EXTENSION.test(extension))
|
|
15076
15079
|
return;
|
|
15077
|
-
return `${
|
|
15080
|
+
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.`;
|
|
15078
15081
|
}
|
|
15079
15082
|
var documentEditOwner = documentOwnerValidation(true);
|
|
15080
15083
|
var PRECONDITION_RULE = "A precondition selects exactly one of document or blocks.";
|
|
@@ -15625,7 +15628,7 @@ var dispatchToolSpecs = [
|
|
|
15625
15628
|
name: "dispatch_artifact",
|
|
15626
15629
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
15627
15630
|
` },
|
|
15628
|
-
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.
|
|
15631
|
+
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}`,
|
|
15629
15632
|
arguments: (z) => ({
|
|
15630
15633
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15631
15634
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
@@ -19759,8 +19762,9 @@ class DispatchClient {
|
|
|
19759
19762
|
return { status: response.status, payload: await this.#response(method, url, response) };
|
|
19760
19763
|
}
|
|
19761
19764
|
async#upload(path, input, key) {
|
|
19762
|
-
if (
|
|
19765
|
+
if (input.file === undefined) {
|
|
19763
19766
|
return this.#json("POST", path, input, undefined, undefined, key);
|
|
19767
|
+
}
|
|
19764
19768
|
const form = new FormData;
|
|
19765
19769
|
form.set("name", input.name);
|
|
19766
19770
|
if (input.summary !== undefined)
|
|
@@ -20139,58 +20143,6 @@ async function postDeliveryReply(config, sessionId, delivery, result) {
|
|
|
20139
20143
|
...reply
|
|
20140
20144
|
}, followUp === undefined ? {} : { followUp });
|
|
20141
20145
|
}
|
|
20142
|
-
function expectsLaneReceipt(frame) {
|
|
20143
|
-
return frame.reply !== undefined && frame.reply !== "" && frame.subject === frame.directSubject && frame.envelopeTopic !== undefined && frame.envelopeTopic !== frame.directSubject;
|
|
20144
|
-
}
|
|
20145
|
-
async function* readArrivals(subscription, now = Date.now) {
|
|
20146
|
-
const source = subscription[Symbol.asyncIterator]();
|
|
20147
|
-
const arrived = [];
|
|
20148
|
-
let stopped;
|
|
20149
|
-
let left = false;
|
|
20150
|
-
let wake;
|
|
20151
|
-
const signal = () => {
|
|
20152
|
-
wake?.();
|
|
20153
|
-
wake = undefined;
|
|
20154
|
-
};
|
|
20155
|
-
(async () => {
|
|
20156
|
-
try {
|
|
20157
|
-
for (;; ) {
|
|
20158
|
-
const read = await source.next();
|
|
20159
|
-
if (read.done === true || left)
|
|
20160
|
-
break;
|
|
20161
|
-
arrived.push({ message: read.value, receivedAt: now() });
|
|
20162
|
-
signal();
|
|
20163
|
-
}
|
|
20164
|
-
stopped = { failed: false };
|
|
20165
|
-
} catch (error) {
|
|
20166
|
-
stopped = { error, failed: true };
|
|
20167
|
-
}
|
|
20168
|
-
signal();
|
|
20169
|
-
})();
|
|
20170
|
-
try {
|
|
20171
|
-
for (;; ) {
|
|
20172
|
-
const next = arrived.shift();
|
|
20173
|
-
if (next !== undefined) {
|
|
20174
|
-
yield next;
|
|
20175
|
-
continue;
|
|
20176
|
-
}
|
|
20177
|
-
if (stopped?.failed === true)
|
|
20178
|
-
throw stopped.error;
|
|
20179
|
-
if (stopped !== undefined)
|
|
20180
|
-
return;
|
|
20181
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
20182
|
-
wake = resolve;
|
|
20183
|
-
await promise;
|
|
20184
|
-
}
|
|
20185
|
-
} finally {
|
|
20186
|
-
if (stopped === undefined) {
|
|
20187
|
-
left = true;
|
|
20188
|
-
Promise.resolve(source.return?.()).catch(() => {
|
|
20189
|
-
return;
|
|
20190
|
-
});
|
|
20191
|
-
}
|
|
20192
|
-
}
|
|
20193
|
-
}
|
|
20194
20146
|
var DedupeIdentitySchema = object({
|
|
20195
20147
|
event_id: string2().min(1).optional(),
|
|
20196
20148
|
dedupe_key: string2().min(1).optional(),
|
|
@@ -23956,13 +23908,17 @@ function withoutFinalLineFeed(text) {
|
|
|
23956
23908
|
return text.endsWith(`
|
|
23957
23909
|
`) ? text.slice(0, -1) : text;
|
|
23958
23910
|
}
|
|
23911
|
+
var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
|
|
23959
23912
|
async function artifactCommand(context) {
|
|
23960
23913
|
const { args, client, actor, input, documentOwner, issue } = context;
|
|
23961
23914
|
const summary = optionalString(args, "summary");
|
|
23962
23915
|
const name = stringArg(args, "name");
|
|
23963
23916
|
const content = optionalString(args, "content");
|
|
23917
|
+
const path = optionalString(args, "path");
|
|
23918
|
+
const options = { name, ...summary === undefined ? {} : { summary }, actor };
|
|
23964
23919
|
const artifactOwner = documentOwner();
|
|
23965
|
-
|
|
23920
|
+
const blank = content === undefined || goBlankPattern.test(content);
|
|
23921
|
+
if ((path !== undefined || !blank) && optionalBoolean(args, "force") !== true) {
|
|
23966
23922
|
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
23967
23923
|
if (held !== undefined) {
|
|
23968
23924
|
throw new ToolInputError(input.tool, [
|
|
@@ -23970,7 +23926,7 @@ async function artifactCommand(context) {
|
|
|
23970
23926
|
]);
|
|
23971
23927
|
}
|
|
23972
23928
|
}
|
|
23973
|
-
if (
|
|
23929
|
+
if (!blank) {
|
|
23974
23930
|
let stored;
|
|
23975
23931
|
try {
|
|
23976
23932
|
stored = await client.markdownRoundTrip(content);
|
|
@@ -23983,19 +23939,12 @@ async function artifactCommand(context) {
|
|
|
23983
23939
|
throw new ToolInputError(input.tool, [storedTextProblem(content, stored, name)]);
|
|
23984
23940
|
}
|
|
23985
23941
|
}
|
|
23986
|
-
const artifactInput =
|
|
23987
|
-
|
|
23988
|
-
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd,
|
|
23989
|
-
type: Bun.file(resolvePath2(input.cwd,
|
|
23990
|
-
})
|
|
23991
|
-
|
|
23992
|
-
actor
|
|
23993
|
-
} : {
|
|
23994
|
-
name,
|
|
23995
|
-
content,
|
|
23996
|
-
...summary === undefined ? {} : { summary },
|
|
23997
|
-
actor
|
|
23998
|
-
};
|
|
23942
|
+
const artifactInput = path !== undefined ? {
|
|
23943
|
+
...options,
|
|
23944
|
+
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, path)) : new Blob([new Uint8Array(input.uploadBytes)], {
|
|
23945
|
+
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
23946
|
+
})
|
|
23947
|
+
} : content !== undefined ? { ...options, content } : options;
|
|
23999
23948
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
24000
23949
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
24001
23950
|
const uploadOwner = artifactOwner.kind === "project" ? documentTopic(result.artifact) : issueTopic(issue());
|
|
@@ -24004,7 +23953,7 @@ async function artifactCommand(context) {
|
|
|
24004
23953
|
});
|
|
24005
23954
|
return {
|
|
24006
23955
|
text: [
|
|
24007
|
-
`Uploaded ${result.artifact.name} as version ${result.version.number} (artifact slug ${result.artifact.slug}; ${artifactRef})${await notSubscribed(uploadOwner, input.subscriptions)}`,
|
|
23956
|
+
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)}`,
|
|
24008
23957
|
...adviceLines
|
|
24009
23958
|
].join(`
|
|
24010
23959
|
`),
|
|
@@ -29138,9 +29087,89 @@ function sessionEnvoySettings(file, env, options) {
|
|
|
29138
29087
|
});
|
|
29139
29088
|
}
|
|
29140
29089
|
|
|
29090
|
+
// ../envoy-client/src/stream-topics.ts
|
|
29091
|
+
var EXCEPTION_TOPIC_PREFIX = "notifications.envoy.exceptions.";
|
|
29092
|
+
var STREAM_SUBJECT_PREFIXES = [
|
|
29093
|
+
AGENT_TOPIC_PREFIX,
|
|
29094
|
+
DISPATCH_TOPIC_PREFIX,
|
|
29095
|
+
"notifications.github.",
|
|
29096
|
+
"notifications.slack.",
|
|
29097
|
+
LEGION_NOTICE_TOPIC_PREFIX,
|
|
29098
|
+
GHOSTWISPR_TOPIC_PREFIX,
|
|
29099
|
+
"notifications.whatsapp.",
|
|
29100
|
+
"notifications.team.",
|
|
29101
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}`,
|
|
29102
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.`
|
|
29103
|
+
];
|
|
29104
|
+
function streamStores(topic) {
|
|
29105
|
+
return STREAM_SUBJECT_PREFIXES.some((prefix) => topic.length > prefix.length && topic.startsWith(prefix));
|
|
29106
|
+
}
|
|
29107
|
+
function streamDeliversNothing(topic) {
|
|
29108
|
+
return topic.startsWith("notifications.") && !topic.startsWith(ROLE_TOPIC_PREFIX) && !streamStores(topic);
|
|
29109
|
+
}
|
|
29110
|
+
function subscribeRefusesTopic(ownAgentSubject, topic) {
|
|
29111
|
+
return streamDeliversNothing(topic) && !reachesPrivateStreamSubject(ownAgentSubject, topic);
|
|
29112
|
+
}
|
|
29113
|
+
function refuseUncapturedTopics(sessionID, ownAgentSubject, topics) {
|
|
29114
|
+
const uncaptured = topics.filter((topic) => subscribeRefusesTopic(ownAgentSubject, topic));
|
|
29115
|
+
if (uncaptured.length === 0)
|
|
29116
|
+
return;
|
|
29117
|
+
throw new Error(uncaptured.map((topic) => uncapturedTopicRefusal(topic, sessionID)).join("; "));
|
|
29118
|
+
}
|
|
29119
|
+
var PRIVATE_STREAM_SUBJECTS = [
|
|
29120
|
+
`${AGENT_TOPIC_PREFIX}>`,
|
|
29121
|
+
`${LEGION_NOTICE_TOPIC_PREFIX}>`,
|
|
29122
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}>`,
|
|
29123
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.>`
|
|
29124
|
+
];
|
|
29125
|
+
var CONTROLLER_NOTICE_SUFFIX = ".controller";
|
|
29126
|
+
function controllerNoticeRole(topic) {
|
|
29127
|
+
if (!topic.startsWith(LEGION_NOTICE_TOPIC_PREFIX) || !topic.endsWith(CONTROLLER_NOTICE_SUFFIX)) {
|
|
29128
|
+
return;
|
|
29129
|
+
}
|
|
29130
|
+
const project = topic.slice(LEGION_NOTICE_TOPIC_PREFIX.length, topic.length - CONTROLLER_NOTICE_SUFFIX.length);
|
|
29131
|
+
if (project === "" || /[.*>]/.test(project))
|
|
29132
|
+
return;
|
|
29133
|
+
return `legion-${project}-controller`;
|
|
29134
|
+
}
|
|
29135
|
+
function subjectsOverlap(a, b) {
|
|
29136
|
+
const aTokens = a.split(".");
|
|
29137
|
+
const bTokens = b.split(".");
|
|
29138
|
+
for (let index = 0;index < aTokens.length && index < bTokens.length; index += 1) {
|
|
29139
|
+
const aToken = aTokens[index];
|
|
29140
|
+
const bToken = bTokens[index];
|
|
29141
|
+
if (aToken === ">" || bToken === ">")
|
|
29142
|
+
return true;
|
|
29143
|
+
if (aToken !== "*" && bToken !== "*" && aToken !== bToken)
|
|
29144
|
+
return false;
|
|
29145
|
+
}
|
|
29146
|
+
return aTokens.length === bTokens.length;
|
|
29147
|
+
}
|
|
29148
|
+
function reachesPrivateStreamSubject(ownAgentSubject, topic, roles = []) {
|
|
29149
|
+
if (!PRIVATE_STREAM_SUBJECTS.some((subject) => subjectsOverlap(topic, subject)))
|
|
29150
|
+
return false;
|
|
29151
|
+
const role = controllerNoticeRole(topic);
|
|
29152
|
+
if (role !== undefined)
|
|
29153
|
+
return !roles.includes(role);
|
|
29154
|
+
return topic !== ownAgentSubject || /[*>]/.test(ownAgentSubject);
|
|
29155
|
+
}
|
|
29156
|
+
function registrationTopics(ownAgentSubject, followed, roles = []) {
|
|
29157
|
+
return [
|
|
29158
|
+
...new Set([
|
|
29159
|
+
ownAgentSubject,
|
|
29160
|
+
...[...followed].filter((topic) => !reachesPrivateStreamSubject(ownAgentSubject, topic, roles) && !streamDeliversNothing(topic))
|
|
29161
|
+
])
|
|
29162
|
+
];
|
|
29163
|
+
}
|
|
29164
|
+
function replayFollowedSubjects(ownAgentSubject, topics, heldForRole = () => false) {
|
|
29165
|
+
const followed = [...topics].filter((topic) => !topic.startsWith(ROLE_TOPIC_PREFIX) && !reachesPrivateStreamSubject(ownAgentSubject, topic) && !heldForRole(topic));
|
|
29166
|
+
return [...new Set([ownAgentSubject, ...followed])];
|
|
29167
|
+
}
|
|
29168
|
+
function rememberedTopics(topics) {
|
|
29169
|
+
return (topics ?? []).filter((topic) => !topic.startsWith(AGENT_TOPIC_PREFIX) && !topic.startsWith(ROLE_TOPIC_PREFIX));
|
|
29170
|
+
}
|
|
29171
|
+
|
|
29141
29172
|
// ../envoy-client/src/transport.ts
|
|
29142
|
-
var REPLAY_TIMEOUT_MS = 1e4;
|
|
29143
|
-
var REPLAY_UNAVAILABLE_CODE = "REPLAY_UNAVAILABLE";
|
|
29144
29173
|
var SessionStateSchema = _enum2(["live", "unresponsive", "gone"]);
|
|
29145
29174
|
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.";
|
|
29146
29175
|
var WireStateSchema = SessionStateSchema.default("live");
|
|
@@ -29152,16 +29181,13 @@ var InterestWireSchema = object({
|
|
|
29152
29181
|
updated_at: number2().int().optional(),
|
|
29153
29182
|
warnings: array(string2()).optional()
|
|
29154
29183
|
});
|
|
29155
|
-
var DeliveryAnswerWireSchema =
|
|
29156
|
-
|
|
29157
|
-
|
|
29158
|
-
|
|
29159
|
-
|
|
29160
|
-
|
|
29161
|
-
|
|
29162
|
-
}),
|
|
29163
|
-
object({ mode: literal("core"), reason: string2() })
|
|
29164
|
-
]);
|
|
29184
|
+
var DeliveryAnswerWireSchema = object({
|
|
29185
|
+
mode: literal("consumer"),
|
|
29186
|
+
subject: string2().min(1),
|
|
29187
|
+
stream_id: string2(),
|
|
29188
|
+
gap: boolean2(),
|
|
29189
|
+
consumer_start: number2().int().nonnegative().optional()
|
|
29190
|
+
});
|
|
29165
29191
|
var SessionWireSchema = object({
|
|
29166
29192
|
session_id: string2(),
|
|
29167
29193
|
machine_id: string2(),
|
|
@@ -29176,7 +29202,8 @@ var SessionWireSchema = object({
|
|
|
29176
29202
|
last_seen: number2().int().optional(),
|
|
29177
29203
|
state: WireStateSchema,
|
|
29178
29204
|
plugin: string2().optional(),
|
|
29179
|
-
plugin_version: string2().optional()
|
|
29205
|
+
plugin_version: string2().optional(),
|
|
29206
|
+
delivery: string2().optional()
|
|
29180
29207
|
});
|
|
29181
29208
|
var RoleWireSchema = object({
|
|
29182
29209
|
role: string2(),
|
|
@@ -29196,13 +29223,13 @@ var RoleHeldWireSchema = object({
|
|
|
29196
29223
|
var ErrorWireSchema = object({
|
|
29197
29224
|
error: string2(),
|
|
29198
29225
|
code: string2().optional(),
|
|
29226
|
+
reason: string2().optional(),
|
|
29199
29227
|
expected: array(string2()).optional(),
|
|
29200
29228
|
state: SessionStateSchema.optional(),
|
|
29201
29229
|
holder: string2().optional(),
|
|
29202
29230
|
holder_state: SessionStateSchema.optional(),
|
|
29203
29231
|
last_seen: number2().int().optional(),
|
|
29204
|
-
claim_released: boolean2().optional()
|
|
29205
|
-
unresponsive: array(string2()).optional()
|
|
29232
|
+
claim_released: boolean2().optional()
|
|
29206
29233
|
});
|
|
29207
29234
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
29208
29235
|
recipient: string2().optional(),
|
|
@@ -29210,46 +29237,30 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
|
29210
29237
|
holder_state: SessionStateSchema.optional(),
|
|
29211
29238
|
recipient_state: SessionStateSchema.optional(),
|
|
29212
29239
|
last_seen: number2().int().optional(),
|
|
29213
|
-
unresponsive: array(string2()).optional(),
|
|
29214
29240
|
duplicate: boolean2().optional()
|
|
29215
29241
|
});
|
|
29216
29242
|
var PublishResponseSchema = EnvelopeResponseSchema.extend({
|
|
29217
29243
|
kept: boolean2().optional(),
|
|
29218
29244
|
kept_reason: _enum2(["unclaimed", "holder_lapsed"]).optional()
|
|
29219
29245
|
});
|
|
29220
|
-
var
|
|
29221
|
-
|
|
29222
|
-
|
|
29223
|
-
created: string2(),
|
|
29224
|
-
first_seq: number2().int().nonnegative(),
|
|
29225
|
-
last_seq: number2().int().nonnegative()
|
|
29226
|
-
}),
|
|
29227
|
-
subjects: array(object({
|
|
29228
|
-
subject: string2(),
|
|
29229
|
-
messages: array(object({
|
|
29230
|
-
seq: number2().int().positive(),
|
|
29231
|
-
subject: string2(),
|
|
29232
|
-
time: string2(),
|
|
29233
|
-
data: string2()
|
|
29234
|
-
})),
|
|
29235
|
-
next_after: number2().int().nonnegative(),
|
|
29236
|
-
more: boolean2(),
|
|
29237
|
-
refused: string2().optional()
|
|
29238
|
-
}))
|
|
29246
|
+
var DeliveryRefusalSchema = object({
|
|
29247
|
+
mode: string2(),
|
|
29248
|
+
reason: string2().optional()
|
|
29239
29249
|
});
|
|
29240
|
-
var
|
|
29241
|
-
var DELIVERY_UNREADABLE = "unreadable_answer";
|
|
29250
|
+
var DELIVERY_UNREADABLE = "answered a delivery field this build cannot read";
|
|
29242
29251
|
function parseSubscribeAnswer(body) {
|
|
29243
29252
|
const interest = InterestWireSchema.parse(body);
|
|
29244
29253
|
const raw = typeof body === "object" && body !== null && "delivery" in body ? body.delivery : undefined;
|
|
29245
29254
|
if (raw === undefined || raw === null) {
|
|
29246
|
-
|
|
29255
|
+
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`);
|
|
29247
29256
|
}
|
|
29248
29257
|
const delivery = DeliveryAnswerWireSchema.safeParse(raw);
|
|
29249
|
-
|
|
29250
|
-
|
|
29251
|
-
|
|
29252
|
-
|
|
29258
|
+
if (!delivery.success) {
|
|
29259
|
+
const named = DeliveryRefusalSchema.safeParse(raw);
|
|
29260
|
+
const said = named.success ? `answered delivery mode ${named.data.mode}${named.data.reason === undefined ? "" : ` (${named.data.reason})`}` : DELIVERY_UNREADABLE;
|
|
29261
|
+
throw new Error(`the listener gave ${interest.session_id} no consumer: it ${said}, and a session receives only what its own consumer holds`);
|
|
29262
|
+
}
|
|
29263
|
+
return { ...interest, delivery: delivery.data };
|
|
29253
29264
|
}
|
|
29254
29265
|
function mergeInterestSources(registryTopics, liveTopics) {
|
|
29255
29266
|
const interests = new Map;
|
|
@@ -29295,27 +29306,20 @@ function expandSubscriptionTopics(topics) {
|
|
|
29295
29306
|
if (segments.length < 2 || segments.some((segment) => segment.length === 0)) {
|
|
29296
29307
|
throw new TypeError(`cannot expand Envoy wildcard topic "${topic}": its concrete base must have at least two non-empty segments`);
|
|
29297
29308
|
}
|
|
29298
|
-
|
|
29309
|
+
if (!streamDeliversNothing(base))
|
|
29310
|
+
expanded.add(base);
|
|
29299
29311
|
expanded.add(topic);
|
|
29300
29312
|
}
|
|
29301
29313
|
return [...expanded];
|
|
29302
29314
|
}
|
|
29303
29315
|
function refusalStateText(parsed) {
|
|
29304
|
-
const sentences = [];
|
|
29305
29316
|
const state = parsed.holder_state ?? parsed.state;
|
|
29306
|
-
if (state
|
|
29307
|
-
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
29308
|
-
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
29309
|
-
sentences.push(`${who} is ${state}${seen}.`);
|
|
29310
|
-
}
|
|
29311
|
-
const stored = parsed.unresponsive ?? [];
|
|
29312
|
-
if (stored.length > 0) {
|
|
29313
|
-
const one = stored.length === 1;
|
|
29314
|
-
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.`);
|
|
29315
|
-
}
|
|
29316
|
-
if (sentences.length === 0)
|
|
29317
|
+
if (state === undefined)
|
|
29317
29318
|
return "";
|
|
29318
|
-
|
|
29319
|
+
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
29320
|
+
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
29321
|
+
const sentences = [`${who} is ${state}${seen}.`];
|
|
29322
|
+
if (state === "unresponsive")
|
|
29319
29323
|
sentences.push(UNRESPONSIVE_RULE);
|
|
29320
29324
|
return ` ${sentences.join(" ")}`;
|
|
29321
29325
|
}
|
|
@@ -29325,11 +29329,11 @@ class EnvoyApiError extends Error {
|
|
|
29325
29329
|
name = "EnvoyApiError";
|
|
29326
29330
|
expected;
|
|
29327
29331
|
code;
|
|
29332
|
+
reason;
|
|
29328
29333
|
holder;
|
|
29329
29334
|
sessionState;
|
|
29330
29335
|
lastSeen;
|
|
29331
29336
|
claimReleased;
|
|
29332
|
-
unresponsive;
|
|
29333
29337
|
constructor(details) {
|
|
29334
29338
|
let parsed;
|
|
29335
29339
|
try {
|
|
@@ -29337,15 +29341,15 @@ class EnvoyApiError extends Error {
|
|
|
29337
29341
|
if (result.success)
|
|
29338
29342
|
parsed = result.data;
|
|
29339
29343
|
} catch {}
|
|
29340
|
-
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
|
|
29344
|
+
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)}`);
|
|
29341
29345
|
this.details = details;
|
|
29342
29346
|
this.expected = parsed?.expected;
|
|
29343
29347
|
this.code = parsed?.code;
|
|
29348
|
+
this.reason = parsed?.reason;
|
|
29344
29349
|
this.holder = parsed?.holder;
|
|
29345
29350
|
this.sessionState = parsed?.holder_state ?? parsed?.state;
|
|
29346
29351
|
this.lastSeen = parsed?.last_seen;
|
|
29347
29352
|
this.claimReleased = parsed?.claim_released;
|
|
29348
|
-
this.unresponsive = parsed?.unresponsive;
|
|
29349
29353
|
}
|
|
29350
29354
|
}
|
|
29351
29355
|
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|
|
@@ -29455,23 +29459,24 @@ function createEnvoyClient(config) {
|
|
|
29455
29459
|
headers: { "Content-Type": "application/json" },
|
|
29456
29460
|
body: JSON.stringify(body)
|
|
29457
29461
|
}, options);
|
|
29462
|
+
const subscribeBody = (input) => ({
|
|
29463
|
+
session_id: input.sessionID,
|
|
29464
|
+
dir: input.directory,
|
|
29465
|
+
topics: expandSubscriptionTopics(input.topics),
|
|
29466
|
+
port: input.port,
|
|
29467
|
+
title: input.title,
|
|
29468
|
+
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
29469
|
+
driving: input.driving,
|
|
29470
|
+
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
29471
|
+
delivery: input.delivery,
|
|
29472
|
+
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
29473
|
+
host: machineID(),
|
|
29474
|
+
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
29475
|
+
plugin: input.plugin.name,
|
|
29476
|
+
plugin_version: input.plugin.version
|
|
29477
|
+
});
|
|
29458
29478
|
return {
|
|
29459
|
-
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", {
|
|
29460
|
-
session_id: input.sessionID,
|
|
29461
|
-
dir: input.directory,
|
|
29462
|
-
topics: expandSubscriptionTopics(input.topics),
|
|
29463
|
-
port: input.port,
|
|
29464
|
-
title: input.title,
|
|
29465
|
-
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
29466
|
-
driving: input.driving,
|
|
29467
|
-
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
29468
|
-
...input.delivery === undefined ? {} : { delivery: input.delivery },
|
|
29469
|
-
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
29470
|
-
host: machineID(),
|
|
29471
|
-
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
29472
|
-
plugin: input.plugin.name,
|
|
29473
|
-
plugin_version: input.plugin.version
|
|
29474
|
-
}, { actingSession: input.sessionID }))),
|
|
29479
|
+
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", subscribeBody(input), { actingSession: input.sessionID }))),
|
|
29475
29480
|
unsubscribe: async (input) => {
|
|
29476
29481
|
await post("/v1/interests/unsubscribe", {
|
|
29477
29482
|
session_id: input.sessionID,
|
|
@@ -29530,7 +29535,6 @@ function createEnvoyClient(config) {
|
|
|
29530
29535
|
envelope: response,
|
|
29531
29536
|
...response.holder === undefined ? {} : { holder: response.holder },
|
|
29532
29537
|
...response.holder_state === undefined ? {} : { holderState: response.holder_state },
|
|
29533
|
-
unresponsive: response.unresponsive ?? [],
|
|
29534
29538
|
...response.kept === undefined ? {} : { kept: response.kept },
|
|
29535
29539
|
...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
|
|
29536
29540
|
};
|
|
@@ -29579,16 +29583,7 @@ function createEnvoyClient(config) {
|
|
|
29579
29583
|
search.set("include", input.include);
|
|
29580
29584
|
const query = search.size === 0 ? "" : `?${search.toString()}`;
|
|
29581
29585
|
return SessionWireSchema.array().parse(JSON.parse(await request(`/v1/sessions${query}`, {})));
|
|
29582
|
-
}
|
|
29583
|
-
replay: async (input) => ReplayWireSchema.parse(JSON.parse(await post("/v1/replay", {
|
|
29584
|
-
session_id: input.sessionID,
|
|
29585
|
-
subjects: input.subjects.map((cursor) => cursor.after === undefined ? { subject: cursor.subject } : { subject: cursor.subject, after: cursor.after }),
|
|
29586
|
-
...input.maxMessages === undefined ? {} : { max_messages: input.maxMessages }
|
|
29587
|
-
}, {
|
|
29588
|
-
timeoutMs: input.timeoutMs ?? REPLAY_TIMEOUT_MS,
|
|
29589
|
-
retry: false,
|
|
29590
|
-
actingSession: input.sessionID
|
|
29591
|
-
})))
|
|
29586
|
+
}
|
|
29592
29587
|
};
|
|
29593
29588
|
}
|
|
29594
29589
|
function waitForRetry(delayMs) {
|