@sjawhar/pi-envoy 15.0.2 → 15.1.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/dist/dispatch.js +254 -91
- package/dist/envoy.js +169 -60
- package/dist/skills/dispatch/SKILL.md +4 -3
- package/dist/skills/envoy/SKILL.md +1 -0
- package/package.json +1 -1
package/dist/dispatch.js
CHANGED
|
@@ -14611,8 +14611,13 @@ var askEventPayloadFields = {
|
|
|
14611
14611
|
opened_event_id: number2().int().positive(),
|
|
14612
14612
|
kind: string2().optional(),
|
|
14613
14613
|
question: string2().optional(),
|
|
14614
|
-
options: array(object({ label: string2().optional() })).optional(),
|
|
14615
|
-
|
|
14614
|
+
options: array(object({ id: string2().optional(), label: string2().optional() })).optional(),
|
|
14615
|
+
revision: number2().int().positive().optional(),
|
|
14616
|
+
answer: object({
|
|
14617
|
+
id: string2().optional(),
|
|
14618
|
+
selected: array(string2()).nullish(),
|
|
14619
|
+
text: string2().nullish()
|
|
14620
|
+
}).nullish(),
|
|
14616
14621
|
previous_answer: object({
|
|
14617
14622
|
user: string2().optional(),
|
|
14618
14623
|
selected: array(string2()).nullish(),
|
|
@@ -15220,8 +15225,8 @@ var dispatchToolSpecs = [
|
|
|
15220
15225
|
quote: z.string().describe("Optional exact quoted document text.").optional(),
|
|
15221
15226
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based occurrence of quote.").optional(),
|
|
15222
15227
|
body: z.string({ max: DISPATCH_BODY_MAX }).describe(`Review comment, at most ${DISPATCH_BODY_MAX} characters.`),
|
|
15223
|
-
reply_to: z.string().describe("A comment id (uuid); replying to any comment in a thread continues that thread (an " + "ask's clarification thread included). A block reference to one block of the comment " + "(dispatch://KEY/comment/<id>#b-<block id>) replies to that comment and names the " + "passage the reply answers. To reply to an ask, use reply_to_ask with the " + "
|
|
15224
|
-
reply_to_ask: z.string().describe("Optional ask id to reply to, threading this comment under that question.
|
|
15228
|
+
reply_to: z.string().describe("A comment id (uuid); replying to any comment in a thread continues that thread (an " + "ask's clarification thread included). A block reference to one block of the comment " + "(dispatch://KEY/comment/<id>#b-<block id>) replies to that comment and names the " + "passage the reply answers. To reply to an ask, use reply_to_ask with the ask id, or " + "with a reference to one of its parts, instead.").optional(),
|
|
15229
|
+
reply_to_ask: z.string().describe("Optional ask id to reply to, threading this comment under that question. A block " + "reference to one part of the ask (dispatch://KEY/ask/<id>#b-<part id>, the id an " + "option or the answer carries) threads under that ask and names the part the reply " + "answers. Mutually exclusive with reply_to.").optional(),
|
|
15225
15230
|
turn: z.enum(["agent", "human"]).describe("Only with reply_to_ask: who holds the turn after this reply. agent: a progress note - " + "you keep the turn and the ask stays 'Waiting on agents' for the human; human (default): " + "you need the human to act - the ask returns to 'Waiting on you'.").optional(),
|
|
15226
15231
|
images: imagesArgument(z, "the issue (or the project document's project)", `the ${DISPATCH_BODY_MAX}-character body limit`)
|
|
15227
15232
|
}),
|
|
@@ -15548,7 +15553,7 @@ var ISSUE_KEY = `${PROJECT_KEY}-[1-9][0-9]*`;
|
|
|
15548
15553
|
var DOCUMENT_SLUG = "[a-z0-9]+(?:-[a-z0-9]+)*";
|
|
15549
15554
|
var ISSUE_KEY_ONLY = new RegExp(`^${ISSUE_KEY}$`);
|
|
15550
15555
|
var BLOCK_REFERENCE = new RegExp(`^dispatch://(?:(${ISSUE_KEY})/spec|(${ISSUE_KEY}|${PROJECT_KEY})/artifact/(${DOCUMENT_SLUG}))#b-(.*)$`, "s");
|
|
15551
|
-
var ITEM_BLOCK_REFERENCE = new RegExp(`^dispatch://(?:${ISSUE_KEY}/(comment|message)|${PROJECT_KEY}/artifact/${DOCUMENT_SLUG}/(comment))/([^/?#]+)#b-(.*)$`, "s");
|
|
15556
|
+
var ITEM_BLOCK_REFERENCE = new RegExp(`^dispatch://(?:${ISSUE_KEY}/(ask|comment|message)|${PROJECT_KEY}/artifact/${DOCUMENT_SLUG}/(ask|comment))/([^/?#]+)#b-(.*)$`, "s");
|
|
15552
15557
|
var atIdBound = `dispatch://CORE-1/spec#b-${"x".repeat(MAX_BLOCK_ID_BYTES)}`;
|
|
15553
15558
|
var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
15554
15559
|
{
|
|
@@ -15648,25 +15653,55 @@ var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
|
15648
15653
|
value: "dispatch://CORE-1/comment/11111111-1111-4111-8111-111111111111#b-b2",
|
|
15649
15654
|
ok: false,
|
|
15650
15655
|
why: "a block of an issue's comment",
|
|
15651
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
15656
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
15652
15657
|
},
|
|
15653
15658
|
{
|
|
15654
15659
|
value: "dispatch://CORE-1/comment/11111111-1111-4111-8111-111111111111#b-b2@v1",
|
|
15655
15660
|
ok: false,
|
|
15656
15661
|
why: "a block of a revision of an issue's comment",
|
|
15657
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
15662
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
15658
15663
|
},
|
|
15659
15664
|
{
|
|
15660
15665
|
value: "dispatch://CORE/artifact/handbook-md/comment/88888888-8888-4888-8888-888888888888#b-b2",
|
|
15661
15666
|
ok: false,
|
|
15662
15667
|
why: "a block of a project document's comment",
|
|
15663
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
15668
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
15664
15669
|
},
|
|
15665
15670
|
{
|
|
15666
15671
|
value: "dispatch://CORE-1/message/33333333-3333-4333-8333-333333333333#b-b2",
|
|
15667
15672
|
ok: false,
|
|
15668
15673
|
why: "a block of an issue message",
|
|
15669
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
15674
|
+
problem: "is a block of a message: a block[] attribute points only at a block of a document"
|
|
15675
|
+
},
|
|
15676
|
+
{
|
|
15677
|
+
value: "dispatch://CORE-1/ask/22222222-2222-4222-8222-222222222222#b-b2",
|
|
15678
|
+
ok: false,
|
|
15679
|
+
why: "a part of an issue's ask",
|
|
15680
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
15681
|
+
},
|
|
15682
|
+
{
|
|
15683
|
+
value: "dispatch://CORE-1/ask/22222222-2222-4222-8222-222222222222#b-b2@v1",
|
|
15684
|
+
ok: false,
|
|
15685
|
+
why: "a part of a revision of an issue's ask",
|
|
15686
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
15687
|
+
},
|
|
15688
|
+
{
|
|
15689
|
+
value: "dispatch://CORE/artifact/handbook-md/ask/99999999-9999-4999-8999-999999999999#b-b2",
|
|
15690
|
+
ok: false,
|
|
15691
|
+
why: "a part of a project document's ask",
|
|
15692
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
15693
|
+
},
|
|
15694
|
+
{
|
|
15695
|
+
value: "dispatch://CORE/artifact/handbook-md/ask/99999999-9999-4999-8999-999999999999#b-b2@v1",
|
|
15696
|
+
ok: false,
|
|
15697
|
+
why: "a part of a revision of a project document's ask",
|
|
15698
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
15699
|
+
},
|
|
15700
|
+
{
|
|
15701
|
+
value: "dispatch://CORE-1/artifact/notes-md/ask/a1#b-b2",
|
|
15702
|
+
ok: false,
|
|
15703
|
+
why: "an issue document's ask, a shape no reference has",
|
|
15704
|
+
problem: "is not a block reference as Dispatch writes one"
|
|
15670
15705
|
},
|
|
15671
15706
|
{
|
|
15672
15707
|
value: "dispatch://CORE-1/artifact/notes-md/comment/c1#b-x",
|
|
@@ -15684,7 +15719,7 @@ var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
|
15684
15719
|
value: "dispatch://CORE-1/spec#b-x dispatch://CORE-1/message/33333333-3333-4333-8333-333333333333#b-b2",
|
|
15685
15720
|
ok: false,
|
|
15686
15721
|
why: "a document's block, then an issue message's",
|
|
15687
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
15722
|
+
problem: "is a block of a message: a block[] attribute points only at a block of a document"
|
|
15688
15723
|
}
|
|
15689
15724
|
];
|
|
15690
15725
|
var TYPED_BLOCK_ID_SHORTCUT_EXCLUDED = `
|
|
@@ -17439,6 +17474,7 @@ function dispatchIssueRef(key) {
|
|
|
17439
17474
|
function dispatchDocumentRef(owner, slug) {
|
|
17440
17475
|
return `dispatch://${owner}/artifact/${slug}`;
|
|
17441
17476
|
}
|
|
17477
|
+
var ITEM_KINDS = ["ask", "comment", "message"];
|
|
17442
17478
|
function dispatchChildRef(ownerRef, kind, id) {
|
|
17443
17479
|
return `${ownerRef}/${kind}/${id}`;
|
|
17444
17480
|
}
|
|
@@ -17450,7 +17486,7 @@ function parseBlockRef(holder, fragment) {
|
|
|
17450
17486
|
}
|
|
17451
17487
|
const pin = target.pin === undefined ? {} : { pin: target.pin };
|
|
17452
17488
|
const artifact = parsed.artifact === undefined ? {} : { artifact: parsed.artifact };
|
|
17453
|
-
if (parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
|
|
17489
|
+
if (parsed.kind === "ask" || parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
|
|
17454
17490
|
return {
|
|
17455
17491
|
owner: parsed.owner,
|
|
17456
17492
|
kind: "block",
|
|
@@ -18612,18 +18648,23 @@ function itemBlockOf(value) {
|
|
|
18612
18648
|
const ref = parseDispatchRef(value);
|
|
18613
18649
|
return ref?.item === undefined || ref.block === undefined ? undefined : { ...ref, item: ref.item, block: ref.block };
|
|
18614
18650
|
}
|
|
18651
|
+
function article(kind) {
|
|
18652
|
+
return kind === "ask" ? "an ask" : `a ${kind}`;
|
|
18653
|
+
}
|
|
18615
18654
|
function replyBlockProblem(field, kind, value) {
|
|
18616
18655
|
if (!/^dispatch:\/\/[^#]*#b-/.test(value))
|
|
18617
18656
|
return;
|
|
18618
18657
|
const form = `dispatch://KEY/${kind}/<id>#b-<block id>`;
|
|
18619
18658
|
const ref = parseDispatchRef(value);
|
|
18620
18659
|
if (ref?.kind !== "block") {
|
|
18621
|
-
return `${field} ${value} names no block; a block of
|
|
18660
|
+
return `${field} ${value} names no block; a block of ${article(kind)} reads ${form}`;
|
|
18622
18661
|
}
|
|
18623
18662
|
const other = ref.item?.kind;
|
|
18624
18663
|
if (other !== kind) {
|
|
18625
|
-
const answer = other === "comment" ? `; answer it with ${commandLine("dispatch_comment", { reply_to: value })}` : other === "message" ? `; answer it with ${commandLine("dispatch_message", { in_reply_to: value })}` : "";
|
|
18626
|
-
|
|
18664
|
+
const answer = other === "comment" ? `; answer it with ${commandLine("dispatch_comment", { reply_to: value })}` : other === "message" ? `; answer it with ${commandLine("dispatch_message", { in_reply_to: value })}` : other === "ask" ? `; answer it with ${commandLine("dispatch_comment", { reply_to_ask: value })}` : "";
|
|
18665
|
+
const named = other === undefined ? "a document" : article(other);
|
|
18666
|
+
const answers = kind === "ask" ? "reply_to_ask answers a part of the ask it names" : `${article(kind)} reply answers a block of ${article(kind)}`;
|
|
18667
|
+
return `${field} ${value} names a block of ${named}, but ${answers} (${form})${answer}`;
|
|
18627
18668
|
}
|
|
18628
18669
|
if (ref.pin !== undefined) {
|
|
18629
18670
|
return `${field} ${value} names revision ${ref.pin} of the block, but a reply answers the block whatever its text becomes: drop @v${ref.pin}`;
|
|
@@ -18747,8 +18788,8 @@ function messageInReplyTo(args) {
|
|
|
18747
18788
|
const id = messageIdOf(block?.item.id ?? inReplyTo);
|
|
18748
18789
|
return id === undefined ? undefined : { id, ...block === undefined ? {} : { block: block.block } };
|
|
18749
18790
|
}
|
|
18750
|
-
function
|
|
18751
|
-
const replyTo = optionalString(args,
|
|
18791
|
+
function itemReplyTo(args, field) {
|
|
18792
|
+
const replyTo = optionalString(args, field);
|
|
18752
18793
|
if (replyTo === undefined)
|
|
18753
18794
|
return;
|
|
18754
18795
|
const block = itemBlockOf(replyTo);
|
|
@@ -18788,12 +18829,17 @@ function argumentProblems(tool, args) {
|
|
|
18788
18829
|
problems.push("artifact is required when quote is supplied");
|
|
18789
18830
|
}
|
|
18790
18831
|
const replyTo = optionalString(args, "reply_to");
|
|
18791
|
-
|
|
18832
|
+
const replyToAsk = optionalString(args, "reply_to_ask");
|
|
18833
|
+
if (replyTo !== undefined && replyToAsk !== undefined) {
|
|
18792
18834
|
problems.push("reply_to and reply_to_ask cannot both be set");
|
|
18793
18835
|
}
|
|
18794
|
-
const
|
|
18795
|
-
|
|
18796
|
-
|
|
18836
|
+
for (const problem of [
|
|
18837
|
+
replyTo === undefined ? undefined : replyBlockProblem("reply_to", "comment", replyTo),
|
|
18838
|
+
replyToAsk === undefined ? undefined : replyBlockProblem("reply_to_ask", "ask", replyToAsk)
|
|
18839
|
+
]) {
|
|
18840
|
+
if (problem !== undefined)
|
|
18841
|
+
problems.push(problem);
|
|
18842
|
+
}
|
|
18797
18843
|
break;
|
|
18798
18844
|
}
|
|
18799
18845
|
case "dispatch_message": {
|
|
@@ -18905,7 +18951,7 @@ function dispatchRefFromUrl(value, serverUrl) {
|
|
|
18905
18951
|
return `dispatch://${key}/artifact/${slug}${version}${blockOf("v")}`;
|
|
18906
18952
|
}
|
|
18907
18953
|
if (ask !== undefined)
|
|
18908
|
-
return `dispatch://${key}/ask/${ask}`;
|
|
18954
|
+
return `dispatch://${key}/ask/${ask}${blockOf()}`;
|
|
18909
18955
|
if (comment !== undefined)
|
|
18910
18956
|
return `dispatch://${key}/comment/${comment}${blockOf()}`;
|
|
18911
18957
|
if (message !== undefined)
|
|
@@ -18932,7 +18978,7 @@ function dispatchRefFromUrl(value, serverUrl) {
|
|
|
18932
18978
|
return;
|
|
18933
18979
|
return item === undefined ? `${document}${versionOf("version")}${blockOf("version")}` : `${document}/${item.kind}/${item.id}`;
|
|
18934
18980
|
}
|
|
18935
|
-
var refGrammarProblem = "ref must be a valid dispatch:// reference such as dispatch://KEY-1, " + "dispatch://KEY-1/ask/<uuid>, dispatch://KEY-1/comment/<uuid>, " + "dispatch://KEY-1/message/<uuid>, dispatch://KEY-1/artifact/<slug>, " + "dispatch://PROJECT/artifact/<document-ref> (an artifact id, slug, or filename), " + "dispatch://KEY-1/spec#b-<block id>, dispatch://KEY-1/artifact/<slug>#b-<block id> or " + "dispatch://PROJECT/artifact/<slug>#b-<block id> (one block of a document, its id " + "percent-encoded, optionally pinned to a version of the document with @v<N> after it; for " + "dispatch read), dispatch://KEY-1/comment/<uuid>#b-<block id>, " + "dispatch://PROJECT/artifact/<slug>/comment/<uuid>#b-<block id> or " + "dispatch://KEY-1/message/<uuid>#b-<block id> (one block of a comment or message, a " + "comment's optionally pinned to a revision of the comment with @v<N> after it; for dispatch " + "read), or " + "dispatch://agent/<session id>/artifact/<slug> (a picture in a conversation on the Agents page, " + "for dispatch doc-read); a dashboard URL on this Dispatch server is accepted too";
|
|
18981
|
+
var refGrammarProblem = "ref must be a valid dispatch:// reference such as dispatch://KEY-1, " + "dispatch://KEY-1/ask/<uuid>, dispatch://KEY-1/comment/<uuid>, " + "dispatch://KEY-1/message/<uuid>, dispatch://KEY-1/artifact/<slug>, " + "dispatch://PROJECT/artifact/<document-ref> (an artifact id, slug, or filename), " + "dispatch://KEY-1/spec#b-<block id>, dispatch://KEY-1/artifact/<slug>#b-<block id> or " + "dispatch://PROJECT/artifact/<slug>#b-<block id> (one block of a document, its id " + "percent-encoded, optionally pinned to a version of the document with @v<N> after it; for " + "dispatch read), dispatch://KEY-1/ask/<uuid>#b-<part id> or " + "dispatch://PROJECT/artifact/<slug>/ask/<uuid>#b-<part id> (one part of an ask: its question, " + "one of its options or its answer, optionally pinned to a revision of the ask's parts with " + "@v<N> after it; for dispatch read), dispatch://KEY-1/comment/<uuid>#b-<block id>, " + "dispatch://PROJECT/artifact/<slug>/comment/<uuid>#b-<block id> or " + "dispatch://KEY-1/message/<uuid>#b-<block id> (one block of a comment or message, a " + "comment's optionally pinned to a revision of the comment with @v<N> after it; for dispatch " + "read), or " + "dispatch://agent/<session id>/artifact/<slug> (a picture in a conversation on the Agents page, " + "for dispatch doc-read); a dashboard URL on this Dispatch server is accepted too";
|
|
18936
18982
|
var ownerRequiredProblem = "issue is required; supply issue or set LEGION_ISSUE";
|
|
18937
18983
|
function innerRefProblem(tool, ref, refText) {
|
|
18938
18984
|
if (ref.kind !== "ask" && ref.kind !== "comment" && ref.kind !== "message" && ref.kind !== "log" && ref.kind !== "children" && ref.kind !== "block") {
|
|
@@ -18944,8 +18990,9 @@ function innerRefProblem(tool, ref, refText) {
|
|
|
18944
18990
|
const itemKind = ref.item?.kind ?? ref.kind;
|
|
18945
18991
|
const documentArgument = ref.kind === "block" && ref.item === undefined && tool !== "dispatch_comment" ? ` and artifact ${ref.id}` : tool === "dispatch_suggest" ? " and artifact <the document's slug>" : "";
|
|
18946
18992
|
const ownerArguments = ref.owner.kind === "issue" ? `issue ${ref.owner.issue}${documentArgument}` : `project ${ref.owner.project} and artifact ${ref.artifact}`;
|
|
18947
|
-
const
|
|
18948
|
-
const
|
|
18993
|
+
const partRef = ref.pin === undefined ? refText : refText.slice(0, -`@v${ref.pin}`.length);
|
|
18994
|
+
const fix = tool === "dispatch_comment" && itemKind === "ask" ? `reply under it with reply_to_ask ${ref.item === undefined ? ref.id : partRef} and ${ownerArguments}` : tool === "dispatch_comment" && itemKind === "comment" ? `reply in its thread with reply_to ${ref.id} and ${ownerArguments}` : `read it with dispatch read, or name ${owner} with ${ownerArguments}`;
|
|
18995
|
+
const item = ref.kind === "ask" ? "an ask" : ref.kind === "log" ? "the event log" : ref.kind === "children" ? "the children" : ref.kind === "block" ? `block ${ref.block}${ref.item === undefined ? "" : ` of ${article(ref.item.kind)}`}` : `a ${ref.kind}`;
|
|
18949
18996
|
return `ref ${refText} names ${item} on ${owner}; dispatch ${commandName(tool)} would act on ${owner} and drop the ${ref.kind}: ${fix}`;
|
|
18950
18997
|
}
|
|
18951
18998
|
var documentItemPattern = /^dispatch:\/\/([A-Z][A-Z0-9]{1,9}-[1-9][0-9]*)\/artifact\/[^/@]+(?:@v\d+)?\/(ask|comment)\/([^/]+)$/;
|
|
@@ -19150,16 +19197,11 @@ function artifactByReference(artifacts, artifactReference, owner, canonical) {
|
|
|
19150
19197
|
const byId = artifacts.find((candidate) => candidate.id === artifactReference);
|
|
19151
19198
|
if (byId !== undefined)
|
|
19152
19199
|
return byId;
|
|
19153
|
-
|
|
19154
|
-
if (bySlug !== undefined) {
|
|
19155
|
-
const named = byName.filter((candidate) => candidate.id !== bySlug.id && candidate.kind === "doc");
|
|
19156
|
-
if (named.length > 0) {
|
|
19157
|
-
throw new Error(documentReferenceProblem(artifactReference, [bySlug, ...named], owner, "id"));
|
|
19158
|
-
}
|
|
19200
|
+
if (bySlug !== undefined)
|
|
19159
19201
|
return bySlug;
|
|
19160
|
-
|
|
19202
|
+
const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
|
|
19161
19203
|
if (byName.length > 1) {
|
|
19162
|
-
throw new Error(documentReferenceProblem(artifactReference, byName, owner,
|
|
19204
|
+
throw new Error(documentReferenceProblem(artifactReference, byName, owner, true));
|
|
19163
19205
|
}
|
|
19164
19206
|
const [artifact] = byName;
|
|
19165
19207
|
if (artifact === undefined) {
|
|
@@ -19214,10 +19256,10 @@ async function documentTargets(client, resolution) {
|
|
|
19214
19256
|
};
|
|
19215
19257
|
}
|
|
19216
19258
|
var documentHintLimit = 8;
|
|
19217
|
-
function documentReferenceProblem(reference, documents, owner,
|
|
19218
|
-
const hints = documents.slice(0, documentHintLimit).map((document) =>
|
|
19259
|
+
function documentReferenceProblem(reference, documents, owner, ambiguous = false) {
|
|
19260
|
+
const hints = documents.slice(0, documentHintLimit).map((document) => `${document.slug} (${document.name})`);
|
|
19219
19261
|
const list = hints.length === 0 ? "none" : hints.join(", ");
|
|
19220
|
-
return
|
|
19262
|
+
return ambiguous ? `"${reference}" names ${documents.length} documents on this ${owner}; use a slug: ${list}` : `document "${reference}" not found by slug; this ${owner}'s documents: ${list}`;
|
|
19221
19263
|
}
|
|
19222
19264
|
var askHintLimit = 8;
|
|
19223
19265
|
function askIDInputProblem(asks, scope) {
|
|
@@ -19396,14 +19438,19 @@ function referenceLines(read) {
|
|
|
19396
19438
|
return [`- ${read}`];
|
|
19397
19439
|
if (read.edges.length === 0)
|
|
19398
19440
|
return ["- none"];
|
|
19399
|
-
return read.edges.map(
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19406
|
-
}
|
|
19441
|
+
return read.edges.map(edgeLine);
|
|
19442
|
+
}
|
|
19443
|
+
function isItemKind(kind) {
|
|
19444
|
+
return ITEM_KINDS.some((item) => item === kind);
|
|
19445
|
+
}
|
|
19446
|
+
function edgeLine(edge) {
|
|
19447
|
+
const { node } = edge;
|
|
19448
|
+
const excerpt = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
|
|
19449
|
+
const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
|
|
19450
|
+
const parent = node.parent ?? undefined;
|
|
19451
|
+
const item = node.kind === "block" && node.document === undefined && isItemKind(parent?.kind) ? parent : undefined;
|
|
19452
|
+
const source = item === undefined ? `${node.kind} ${node.ref ?? node.id}` : `${item.kind} ${item.ref ?? item.id} block ${node.block_id ?? node.id}`;
|
|
19453
|
+
return `- ${edge.kind} ${source} (${excerpt}${edge.created_at})${block}`;
|
|
19407
19454
|
}
|
|
19408
19455
|
function unavailableReason(error) {
|
|
19409
19456
|
return dispatchAnswered(error, 404) ? "unavailable" : `unavailable: ${messageFor(error)}`;
|
|
@@ -19445,12 +19492,12 @@ function nodeLine(node) {
|
|
|
19445
19492
|
const made = fact(node.made_by, node.made_at);
|
|
19446
19493
|
const changed = fact(node.changed_by, node.changed_at);
|
|
19447
19494
|
const { parent } = node;
|
|
19448
|
-
const partOf = parent == null ? "" : ` \xB7 part of ${parent.ref ?? `${parent.kind} ${parent.id}`}${node.parent_version == null ? "" : ` (${parent.kind
|
|
19495
|
+
const partOf = parent == null ? "" : ` \xB7 part of ${parent.ref ?? `${parent.kind} ${parent.id}`}${node.parent_version == null ? "" : ` (${isItemKind(parent.kind) ? "revision" : "version"} ${node.parent_version})`}`;
|
|
19449
19496
|
return [
|
|
19450
19497
|
`Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
|
|
19451
19498
|
];
|
|
19452
19499
|
}
|
|
19453
|
-
function blockLines(node, ref) {
|
|
19500
|
+
function blockLines(node, ref, noun = "Block") {
|
|
19454
19501
|
const unit = ref.item === undefined ? "version" : "revision";
|
|
19455
19502
|
const blockID = node.block_id ?? ref.block;
|
|
19456
19503
|
const head = ref.item === undefined ? [
|
|
@@ -19459,7 +19506,7 @@ function blockLines(node, ref) {
|
|
|
19459
19506
|
...node.changed_version === undefined ? [] : [`Changed in version: ${node.changed_version}`],
|
|
19460
19507
|
...node.text === undefined ? [] : ["Text:", node.text]
|
|
19461
19508
|
] : [
|
|
19462
|
-
|
|
19509
|
+
`${noun} ${blockID} of ${ref.item.kind} ${ref.item.id}${node.changed_version === undefined ? "" : ` (changed in revision ${node.changed_version})`}:`,
|
|
19463
19510
|
...node.text === undefined ? [] : [node.text]
|
|
19464
19511
|
];
|
|
19465
19512
|
const { pin } = node;
|
|
@@ -19474,6 +19521,14 @@ function blockLines(node, ref) {
|
|
|
19474
19521
|
pin.text
|
|
19475
19522
|
];
|
|
19476
19523
|
}
|
|
19524
|
+
function askPartNoun(ask, node, blockID) {
|
|
19525
|
+
if (ask.answer?.id === blockID)
|
|
19526
|
+
return "Answer";
|
|
19527
|
+
if (ask.options.some((option) => option.id === blockID))
|
|
19528
|
+
return "Option";
|
|
19529
|
+
const placed = (ask.revision ?? 0) > 0 && ask.options.every((option) => option.id !== undefined) && (ask.answer === null || ask.answer.id !== undefined);
|
|
19530
|
+
return placed && node.pin?.state !== "removed" ? "Question" : "Part";
|
|
19531
|
+
}
|
|
19477
19532
|
function logSummary(issue, events) {
|
|
19478
19533
|
return [
|
|
19479
19534
|
`Key: ${issue.key}`,
|
|
@@ -19538,9 +19593,11 @@ function childrenSummary(issue) {
|
|
|
19538
19593
|
].join(`
|
|
19539
19594
|
`);
|
|
19540
19595
|
}
|
|
19541
|
-
function askSummary({ ask, replies, answers },
|
|
19596
|
+
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
19542
19597
|
const answer = ask.answer;
|
|
19543
19598
|
const earlierAnswers = answers.slice(0, -1);
|
|
19599
|
+
const parts = askPartEdges(ask, incoming);
|
|
19600
|
+
const partRef = (id) => `${askRef}#b-${encodeBlockId(id)}`;
|
|
19544
19601
|
const chain = replies.flatMap((reply) => [
|
|
19545
19602
|
`${reply.id} \xB7 ${actorText(reply.author)}`,
|
|
19546
19603
|
`Body: ${reply.body}`
|
|
@@ -19549,14 +19606,19 @@ function askSummary({ ask, replies, answers }, graph) {
|
|
|
19549
19606
|
`Question: ${ask.question}`,
|
|
19550
19607
|
...anchorLines(ask),
|
|
19551
19608
|
"Options:",
|
|
19552
|
-
...ask.options.length === 0 ? ["- none"] : ask.options.
|
|
19609
|
+
...ask.options.length === 0 ? ["- none"] : ask.options.flatMap((option) => [
|
|
19610
|
+
`- ${option.label}${option.description ? ` \u2014 ${option.description}` : ""}${option.id === undefined ? "" : ` (${partRef(option.id)})`}`,
|
|
19611
|
+
...partReferenceLines(parts.at, option.id)
|
|
19612
|
+
]),
|
|
19553
19613
|
`State: ${ask.state}`,
|
|
19554
19614
|
`Ask id: ${ask.id}`,
|
|
19555
19615
|
"Answer:",
|
|
19556
19616
|
...answer === null ? ["- none"] : [
|
|
19557
19617
|
`- By: ${answer.user}`,
|
|
19558
19618
|
`- Selected: ${answer.selected.length === 0 ? "none" : answer.selected.join(", ")}`,
|
|
19559
|
-
...answer.text === null ? [] : [`- Text: ${answer.text}`]
|
|
19619
|
+
...answer.text === null ? [] : [`- Text: ${answer.text}`],
|
|
19620
|
+
...answer.id === undefined ? [] : [`- Reference: ${partRef(answer.id)}`],
|
|
19621
|
+
...partReferenceLines(parts.at, answer.id)
|
|
19560
19622
|
],
|
|
19561
19623
|
...earlierAnswers.length === 0 ? [] : [
|
|
19562
19624
|
"Earlier answers:",
|
|
@@ -19570,10 +19632,38 @@ function askSummary({ ask, replies, answers }, graph) {
|
|
|
19570
19632
|
],
|
|
19571
19633
|
"Replies:",
|
|
19572
19634
|
...chain.length === 0 ? ["- none"] : chain,
|
|
19573
|
-
...
|
|
19635
|
+
...pictures,
|
|
19636
|
+
...graphSectionLines(parts.rest, outgoing)
|
|
19574
19637
|
].join(`
|
|
19575
19638
|
`);
|
|
19576
19639
|
}
|
|
19640
|
+
function askPartEdges(ask, incoming) {
|
|
19641
|
+
const ids = new Set([...ask.options.map((option) => option.id), ask.answer?.id].filter((id) => id !== undefined));
|
|
19642
|
+
const at = new Map;
|
|
19643
|
+
if (typeof incoming === "string" || ids.size === 0)
|
|
19644
|
+
return { at, rest: incoming };
|
|
19645
|
+
const rest = [];
|
|
19646
|
+
for (const edge of incoming.edges) {
|
|
19647
|
+
const part = edge.block?.block_id;
|
|
19648
|
+
if (part === undefined || !ids.has(part)) {
|
|
19649
|
+
rest.push(edge);
|
|
19650
|
+
continue;
|
|
19651
|
+
}
|
|
19652
|
+
const { block: _block, ...atPart } = edge;
|
|
19653
|
+
const held = at.get(part);
|
|
19654
|
+
if (held === undefined)
|
|
19655
|
+
at.set(part, [atPart]);
|
|
19656
|
+
else
|
|
19657
|
+
held.push(atPart);
|
|
19658
|
+
}
|
|
19659
|
+
return { at, rest: { node: incoming.node, edges: rest } };
|
|
19660
|
+
}
|
|
19661
|
+
function partReferenceLines(at, id) {
|
|
19662
|
+
const edges = id === undefined ? undefined : at.get(id);
|
|
19663
|
+
if (edges === undefined || edges.length === 0)
|
|
19664
|
+
return [];
|
|
19665
|
+
return [" Referenced by:", ...edges.map((edge) => ` ${edgeLine(edge)}`)];
|
|
19666
|
+
}
|
|
19577
19667
|
function openAskAge(ageSeconds) {
|
|
19578
19668
|
const seconds = Math.max(0, Math.floor(ageSeconds));
|
|
19579
19669
|
if (seconds < 60)
|
|
@@ -20547,14 +20637,15 @@ async function executeDispatchTool(input) {
|
|
|
20547
20637
|
const owner = documentOwner();
|
|
20548
20638
|
const resolved = owner.kind === "project" || artifactReference === undefined ? owner.kind === "project" ? await resolveDocument(owner, artifactReference) : undefined : await resolveDocument(owner, artifactReference);
|
|
20549
20639
|
const anchored = resolved ? anchor(resolved.artifact, args) : undefined;
|
|
20550
|
-
const replyTo =
|
|
20551
|
-
const
|
|
20552
|
-
const replyToAsk =
|
|
20553
|
-
if (
|
|
20640
|
+
const replyTo = itemReplyTo(args, "reply_to");
|
|
20641
|
+
const replyToAskTarget = itemReplyTo(args, "reply_to_ask");
|
|
20642
|
+
const replyToAsk = replyToAskTarget === undefined ? undefined : normalizeUUID(replyToAskTarget.id);
|
|
20643
|
+
if (replyToAskTarget !== undefined && replyToAsk === undefined) {
|
|
20554
20644
|
throw new ToolInputError(input.tool, [
|
|
20555
20645
|
await invalidReplyToAskProblem(client, owner, resolved)
|
|
20556
20646
|
]);
|
|
20557
20647
|
}
|
|
20648
|
+
const replyToBlock = replyTo?.block ?? replyToAskTarget?.block;
|
|
20558
20649
|
const requestedTurn = optionalString(args, "turn");
|
|
20559
20650
|
const body = await writePictures(resolved, stringArg(args, "body"), {
|
|
20560
20651
|
cap: DISPATCH_BODY_MAX,
|
|
@@ -20565,7 +20656,7 @@ async function executeDispatchTool(input) {
|
|
|
20565
20656
|
body,
|
|
20566
20657
|
...anchored === undefined ? {} : { anchor: anchored },
|
|
20567
20658
|
...replyTo === undefined ? {} : { reply_to: replyTo.id },
|
|
20568
|
-
...
|
|
20659
|
+
...replyToBlock === undefined ? {} : { reply_to_block: replyToBlock },
|
|
20569
20660
|
...replyToAsk === undefined ? {} : { ask_id: replyToAsk },
|
|
20570
20661
|
...requestedTurn === undefined ? {} : { turn: requestedTurn },
|
|
20571
20662
|
actor
|
|
@@ -20978,12 +21069,13 @@ ${handoff.body}`,
|
|
|
20978
21069
|
const askRead = await readAskRef(input.tool, ref.id, refOwnerName(ref), client, async () => ref.owner.kind === "issue" ? client.listIssueAsks(ref.owner.issue) : client.getArtifactAsks(await documentIdOf(ref), "all"));
|
|
20979
21070
|
await refuseItemOffRef(input.tool, "ask", ref, stringArg(args, "ref"), askRead.ask, () => documentIdOf(ref));
|
|
20980
21071
|
const askRef = refTarget(ref, "ask", askRead.ask.id);
|
|
20981
|
-
const [pictures,
|
|
21072
|
+
const [pictures, incoming, outgoing] = await Promise.all([
|
|
20982
21073
|
picturesOf(askTexts(askRead)),
|
|
20983
|
-
|
|
21074
|
+
graphReferences(client, { to: askRef }),
|
|
21075
|
+
graphReferences(client, { from: askRef })
|
|
20984
21076
|
]);
|
|
20985
21077
|
return {
|
|
20986
|
-
text: askSummary(askRead,
|
|
21078
|
+
text: askSummary(askRead, askRef, pictures.lines, incoming, outgoing),
|
|
20987
21079
|
details: ref.owner.kind === "project" ? { project: ref.owner.project } : { issue: ref.owner.issue },
|
|
20988
21080
|
...showImages(pictures)
|
|
20989
21081
|
};
|
|
@@ -21024,17 +21116,26 @@ ${handoff.body}`,
|
|
|
21024
21116
|
const ref = ownerArguments.ref;
|
|
21025
21117
|
const blockRef = stringArg(args, "ref");
|
|
21026
21118
|
const holder = blockRef.slice(0, blockRef.indexOf("#"));
|
|
21027
|
-
const
|
|
21119
|
+
const askOfPart = ref.item?.kind === "ask" ? client.getAsk(ref.item.id).catch(() => {
|
|
21120
|
+
return;
|
|
21121
|
+
}) : undefined;
|
|
21122
|
+
const [incoming, outgoing, partOf] = await Promise.all([
|
|
21028
21123
|
client.getReferences({ to: blockRef }).catch((error) => {
|
|
21029
21124
|
if (ref.pin === undefined && dispatchAnswered(error, 404)) {
|
|
21030
21125
|
throw new Error(`No block ${ref.block} in ${holder}.`);
|
|
21031
21126
|
}
|
|
21032
21127
|
throw error;
|
|
21033
21128
|
}),
|
|
21034
|
-
graphReferences(client, { from: blockRef })
|
|
21129
|
+
graphReferences(client, { from: blockRef }),
|
|
21130
|
+
askOfPart
|
|
21035
21131
|
]);
|
|
21132
|
+
const blockID = incoming.node.block_id ?? ref.block ?? "";
|
|
21133
|
+
const noun = ref.item?.kind !== "ask" ? undefined : partOf === undefined ? "Part" : askPartNoun(partOf.ask, incoming.node, blockID);
|
|
21036
21134
|
return {
|
|
21037
|
-
text: [
|
|
21135
|
+
text: [
|
|
21136
|
+
...blockLines(incoming.node, ref, noun),
|
|
21137
|
+
...graphSectionLines(incoming, outgoing)
|
|
21138
|
+
].join(`
|
|
21038
21139
|
`),
|
|
21039
21140
|
details: {
|
|
21040
21141
|
...ref.owner.kind === "project" ? { project: ref.owner.project } : { issue: ref.owner.issue },
|
|
@@ -22048,7 +22149,8 @@ var ErrorWireSchema = object({
|
|
|
22048
22149
|
});
|
|
22049
22150
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
22050
22151
|
recipient: string2().optional(),
|
|
22051
|
-
holder: string2().optional()
|
|
22152
|
+
holder: string2().optional(),
|
|
22153
|
+
duplicate: boolean2().optional()
|
|
22052
22154
|
});
|
|
22053
22155
|
var ReplayWireSchema = object({
|
|
22054
22156
|
stream: object({
|
|
@@ -22120,44 +22222,84 @@ class EnvoyApiError extends Error {
|
|
|
22120
22222
|
this.code = parsed?.code;
|
|
22121
22223
|
}
|
|
22122
22224
|
}
|
|
22225
|
+
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|
|
22226
|
+
|
|
22227
|
+
class EnvoySendUnconfirmedError extends Error {
|
|
22228
|
+
targetSessionID;
|
|
22229
|
+
idempotencyKey;
|
|
22230
|
+
attempts;
|
|
22231
|
+
last;
|
|
22232
|
+
name = "EnvoySendUnconfirmedError";
|
|
22233
|
+
resendSafe;
|
|
22234
|
+
constructor(targetSessionID, idempotencyKey, attempts, last) {
|
|
22235
|
+
const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
|
|
22236
|
+
const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
|
|
22237
|
+
const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
|
|
22238
|
+
const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
|
|
22239
|
+
super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
|
|
22240
|
+
this.targetSessionID = targetSessionID;
|
|
22241
|
+
this.idempotencyKey = idempotencyKey;
|
|
22242
|
+
this.attempts = attempts;
|
|
22243
|
+
this.last = last;
|
|
22244
|
+
this.resendSafe = resendSafe;
|
|
22245
|
+
}
|
|
22246
|
+
}
|
|
22123
22247
|
function createEnvoyClient(config) {
|
|
22124
22248
|
const baseUrl = normalizeEnvoyUrl(config.baseUrl);
|
|
22125
22249
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
22126
22250
|
const apiToken = config.token;
|
|
22251
|
+
const attempts = config.retry === false ? 1 : 2;
|
|
22252
|
+
const attemptOnce = async (url, init, deadlineMs) => {
|
|
22253
|
+
const headers = new Headers(init.headers);
|
|
22254
|
+
if (apiToken)
|
|
22255
|
+
headers.set("Authorization", `Bearer ${apiToken}`);
|
|
22256
|
+
let response;
|
|
22257
|
+
try {
|
|
22258
|
+
response = await config.fetch(url, {
|
|
22259
|
+
...init,
|
|
22260
|
+
headers,
|
|
22261
|
+
signal: AbortSignal.timeout(deadlineMs)
|
|
22262
|
+
});
|
|
22263
|
+
} catch (error) {
|
|
22264
|
+
return { unanswered: error };
|
|
22265
|
+
}
|
|
22266
|
+
try {
|
|
22267
|
+
return { response, body: await response.text() };
|
|
22268
|
+
} catch (error) {
|
|
22269
|
+
if (response.status >= 400 && response.status < 500) {
|
|
22270
|
+
return { response, body: `(its body did not arrive: ${String(error)})` };
|
|
22271
|
+
}
|
|
22272
|
+
return { unanswered: error };
|
|
22273
|
+
}
|
|
22274
|
+
};
|
|
22127
22275
|
const request = async (path, init, options = {}) => {
|
|
22128
22276
|
const url = `${baseUrl}${path}`;
|
|
22129
|
-
const attempts = config.retry === false ? 1 : 2;
|
|
22130
22277
|
const tries = options.retry === false ? 1 : attempts;
|
|
22131
22278
|
for (let attempt = 0;attempt < tries; attempt += 1) {
|
|
22132
|
-
|
|
22133
|
-
|
|
22134
|
-
|
|
22135
|
-
if (apiToken)
|
|
22136
|
-
headers.set("Authorization", `Bearer ${apiToken}`);
|
|
22137
|
-
response = await config.fetch(url, {
|
|
22138
|
-
...init,
|
|
22139
|
-
headers,
|
|
22140
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? timeoutMs)
|
|
22141
|
-
});
|
|
22142
|
-
} catch (error) {
|
|
22279
|
+
const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs);
|
|
22280
|
+
if ("unanswered" in outcome) {
|
|
22281
|
+
options.onUnanswered?.();
|
|
22143
22282
|
if (attempt + 1 < tries) {
|
|
22144
22283
|
await waitForRetry();
|
|
22145
22284
|
continue;
|
|
22146
22285
|
}
|
|
22147
|
-
throw
|
|
22286
|
+
throw outcome.unanswered;
|
|
22148
22287
|
}
|
|
22149
|
-
const
|
|
22288
|
+
const { response, body } = outcome;
|
|
22150
22289
|
if (response.ok)
|
|
22151
|
-
return
|
|
22290
|
+
return body;
|
|
22152
22291
|
const error = new EnvoyApiError({
|
|
22153
22292
|
method: init.method ?? "GET",
|
|
22154
22293
|
url,
|
|
22155
22294
|
status: response.status,
|
|
22156
|
-
responseBody
|
|
22295
|
+
responseBody: body
|
|
22157
22296
|
});
|
|
22158
|
-
if (response.status >= 500
|
|
22159
|
-
|
|
22160
|
-
|
|
22297
|
+
if (response.status >= 500) {
|
|
22298
|
+
options.onUnanswered?.();
|
|
22299
|
+
if (attempt + 1 < tries) {
|
|
22300
|
+
await waitForRetry();
|
|
22301
|
+
continue;
|
|
22302
|
+
}
|
|
22161
22303
|
}
|
|
22162
22304
|
throw error;
|
|
22163
22305
|
}
|
|
@@ -22193,18 +22335,33 @@ function createEnvoyClient(config) {
|
|
|
22193
22335
|
getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
|
|
22194
22336
|
send: async (input) => {
|
|
22195
22337
|
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
22196
|
-
|
|
22197
|
-
|
|
22198
|
-
|
|
22199
|
-
|
|
22200
|
-
|
|
22201
|
-
|
|
22202
|
-
|
|
22203
|
-
|
|
22338
|
+
let unanswered = false;
|
|
22339
|
+
let response;
|
|
22340
|
+
try {
|
|
22341
|
+
const answer = await post("/v1/messages/send", {
|
|
22342
|
+
source: input.source ?? "agent",
|
|
22343
|
+
...sourceSession(input.sourceSessionID),
|
|
22344
|
+
target_session: input.targetSessionID,
|
|
22345
|
+
message: input.message,
|
|
22346
|
+
idempotency_key: idempotencyKey,
|
|
22347
|
+
...messageMetadata(input)
|
|
22348
|
+
}, {
|
|
22349
|
+
onUnanswered: () => {
|
|
22350
|
+
unanswered = true;
|
|
22351
|
+
}
|
|
22352
|
+
});
|
|
22353
|
+
response = EnvelopeResponseSchema.parse(JSON.parse(answer));
|
|
22354
|
+
} catch (error) {
|
|
22355
|
+
if (error instanceof EnvoyApiError && error.details.status < 500 && !unanswered) {
|
|
22356
|
+
throw error;
|
|
22357
|
+
}
|
|
22358
|
+
throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, attempts, error);
|
|
22359
|
+
}
|
|
22204
22360
|
return {
|
|
22205
22361
|
envelope: response,
|
|
22206
22362
|
recipient: response.recipient ?? input.targetSessionID,
|
|
22207
|
-
confirmed: response.recipient !== undefined
|
|
22363
|
+
confirmed: response.recipient !== undefined,
|
|
22364
|
+
duplicate: response.duplicate === true
|
|
22208
22365
|
};
|
|
22209
22366
|
},
|
|
22210
22367
|
publish: async (input) => {
|
|
@@ -22243,7 +22400,13 @@ function createEnvoyClient(config) {
|
|
|
22243
22400
|
raw = await post("/v1/roles/set", body);
|
|
22244
22401
|
} catch (error) {
|
|
22245
22402
|
if (error instanceof EnvoyApiError && error.details.status === 409) {
|
|
22246
|
-
|
|
22403
|
+
let answer;
|
|
22404
|
+
try {
|
|
22405
|
+
answer = JSON.parse(error.details.responseBody);
|
|
22406
|
+
} catch {
|
|
22407
|
+
throw error;
|
|
22408
|
+
}
|
|
22409
|
+
const held = RoleHeldWireSchema.safeParse(answer);
|
|
22247
22410
|
if (held.success)
|
|
22248
22411
|
return { claimed: false, holder: held.data.holder };
|
|
22249
22412
|
}
|
package/dist/envoy.js
CHANGED
|
@@ -29752,8 +29752,13 @@ var askEventPayloadFields = {
|
|
|
29752
29752
|
opened_event_id: number2().int().positive(),
|
|
29753
29753
|
kind: string2().optional(),
|
|
29754
29754
|
question: string2().optional(),
|
|
29755
|
-
options: array(object({ label: string2().optional() })).optional(),
|
|
29756
|
-
|
|
29755
|
+
options: array(object({ id: string2().optional(), label: string2().optional() })).optional(),
|
|
29756
|
+
revision: number2().int().positive().optional(),
|
|
29757
|
+
answer: object({
|
|
29758
|
+
id: string2().optional(),
|
|
29759
|
+
selected: array(string2()).nullish(),
|
|
29760
|
+
text: string2().nullish()
|
|
29761
|
+
}).nullish(),
|
|
29757
29762
|
previous_answer: object({
|
|
29758
29763
|
user: string2().optional(),
|
|
29759
29764
|
selected: array(string2()).nullish(),
|
|
@@ -30340,8 +30345,8 @@ var dispatchToolSpecs = [
|
|
|
30340
30345
|
quote: z.string().describe("Optional exact quoted document text.").optional(),
|
|
30341
30346
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based occurrence of quote.").optional(),
|
|
30342
30347
|
body: z.string({ max: DISPATCH_BODY_MAX }).describe(`Review comment, at most ${DISPATCH_BODY_MAX} characters.`),
|
|
30343
|
-
reply_to: z.string().describe("A comment id (uuid); replying to any comment in a thread continues that thread (an " + "ask's clarification thread included). A block reference to one block of the comment " + "(dispatch://KEY/comment/<id>#b-<block id>) replies to that comment and names the " + "passage the reply answers. To reply to an ask, use reply_to_ask with the " + "
|
|
30344
|
-
reply_to_ask: z.string().describe("Optional ask id to reply to, threading this comment under that question.
|
|
30348
|
+
reply_to: z.string().describe("A comment id (uuid); replying to any comment in a thread continues that thread (an " + "ask's clarification thread included). A block reference to one block of the comment " + "(dispatch://KEY/comment/<id>#b-<block id>) replies to that comment and names the " + "passage the reply answers. To reply to an ask, use reply_to_ask with the ask id, or " + "with a reference to one of its parts, instead.").optional(),
|
|
30349
|
+
reply_to_ask: z.string().describe("Optional ask id to reply to, threading this comment under that question. A block " + "reference to one part of the ask (dispatch://KEY/ask/<id>#b-<part id>, the id an " + "option or the answer carries) threads under that ask and names the part the reply " + "answers. Mutually exclusive with reply_to.").optional(),
|
|
30345
30350
|
turn: z.enum(["agent", "human"]).describe("Only with reply_to_ask: who holds the turn after this reply. agent: a progress note - " + "you keep the turn and the ask stays 'Waiting on agents' for the human; human (default): " + "you need the human to act - the ask returns to 'Waiting on you'.").optional(),
|
|
30346
30351
|
images: imagesArgument(z, "the issue (or the project document's project)", `the ${DISPATCH_BODY_MAX}-character body limit`)
|
|
30347
30352
|
}),
|
|
@@ -30668,7 +30673,7 @@ var ISSUE_KEY = `${PROJECT_KEY}-[1-9][0-9]*`;
|
|
|
30668
30673
|
var DOCUMENT_SLUG = "[a-z0-9]+(?:-[a-z0-9]+)*";
|
|
30669
30674
|
var ISSUE_KEY_ONLY = new RegExp(`^${ISSUE_KEY}$`);
|
|
30670
30675
|
var BLOCK_REFERENCE = new RegExp(`^dispatch://(?:(${ISSUE_KEY})/spec|(${ISSUE_KEY}|${PROJECT_KEY})/artifact/(${DOCUMENT_SLUG}))#b-(.*)$`, "s");
|
|
30671
|
-
var ITEM_BLOCK_REFERENCE = new RegExp(`^dispatch://(?:${ISSUE_KEY}/(comment|message)|${PROJECT_KEY}/artifact/${DOCUMENT_SLUG}/(comment))/([^/?#]+)#b-(.*)$`, "s");
|
|
30676
|
+
var ITEM_BLOCK_REFERENCE = new RegExp(`^dispatch://(?:${ISSUE_KEY}/(ask|comment|message)|${PROJECT_KEY}/artifact/${DOCUMENT_SLUG}/(ask|comment))/([^/?#]+)#b-(.*)$`, "s");
|
|
30672
30677
|
var atIdBound = `dispatch://CORE-1/spec#b-${"x".repeat(MAX_BLOCK_ID_BYTES)}`;
|
|
30673
30678
|
var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
30674
30679
|
{
|
|
@@ -30768,25 +30773,55 @@ var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
|
30768
30773
|
value: "dispatch://CORE-1/comment/11111111-1111-4111-8111-111111111111#b-b2",
|
|
30769
30774
|
ok: false,
|
|
30770
30775
|
why: "a block of an issue's comment",
|
|
30771
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
30776
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
30772
30777
|
},
|
|
30773
30778
|
{
|
|
30774
30779
|
value: "dispatch://CORE-1/comment/11111111-1111-4111-8111-111111111111#b-b2@v1",
|
|
30775
30780
|
ok: false,
|
|
30776
30781
|
why: "a block of a revision of an issue's comment",
|
|
30777
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
30782
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
30778
30783
|
},
|
|
30779
30784
|
{
|
|
30780
30785
|
value: "dispatch://CORE/artifact/handbook-md/comment/88888888-8888-4888-8888-888888888888#b-b2",
|
|
30781
30786
|
ok: false,
|
|
30782
30787
|
why: "a block of a project document's comment",
|
|
30783
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
30788
|
+
problem: "is a block of a comment: a block[] attribute points only at a block of a document"
|
|
30784
30789
|
},
|
|
30785
30790
|
{
|
|
30786
30791
|
value: "dispatch://CORE-1/message/33333333-3333-4333-8333-333333333333#b-b2",
|
|
30787
30792
|
ok: false,
|
|
30788
30793
|
why: "a block of an issue message",
|
|
30789
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
30794
|
+
problem: "is a block of a message: a block[] attribute points only at a block of a document"
|
|
30795
|
+
},
|
|
30796
|
+
{
|
|
30797
|
+
value: "dispatch://CORE-1/ask/22222222-2222-4222-8222-222222222222#b-b2",
|
|
30798
|
+
ok: false,
|
|
30799
|
+
why: "a part of an issue's ask",
|
|
30800
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
30801
|
+
},
|
|
30802
|
+
{
|
|
30803
|
+
value: "dispatch://CORE-1/ask/22222222-2222-4222-8222-222222222222#b-b2@v1",
|
|
30804
|
+
ok: false,
|
|
30805
|
+
why: "a part of a revision of an issue's ask",
|
|
30806
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
30807
|
+
},
|
|
30808
|
+
{
|
|
30809
|
+
value: "dispatch://CORE/artifact/handbook-md/ask/99999999-9999-4999-8999-999999999999#b-b2",
|
|
30810
|
+
ok: false,
|
|
30811
|
+
why: "a part of a project document's ask",
|
|
30812
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
30813
|
+
},
|
|
30814
|
+
{
|
|
30815
|
+
value: "dispatch://CORE/artifact/handbook-md/ask/99999999-9999-4999-8999-999999999999#b-b2@v1",
|
|
30816
|
+
ok: false,
|
|
30817
|
+
why: "a part of a revision of a project document's ask",
|
|
30818
|
+
problem: "is a block of an ask: a block[] attribute points only at a block of a document"
|
|
30819
|
+
},
|
|
30820
|
+
{
|
|
30821
|
+
value: "dispatch://CORE-1/artifact/notes-md/ask/a1#b-b2",
|
|
30822
|
+
ok: false,
|
|
30823
|
+
why: "an issue document's ask, a shape no reference has",
|
|
30824
|
+
problem: "is not a block reference as Dispatch writes one"
|
|
30790
30825
|
},
|
|
30791
30826
|
{
|
|
30792
30827
|
value: "dispatch://CORE-1/artifact/notes-md/comment/c1#b-x",
|
|
@@ -30804,7 +30839,7 @@ var DISPATCH_BLOCK_POINTER_VALUES = [
|
|
|
30804
30839
|
value: "dispatch://CORE-1/spec#b-x dispatch://CORE-1/message/33333333-3333-4333-8333-333333333333#b-b2",
|
|
30805
30840
|
ok: false,
|
|
30806
30841
|
why: "a document's block, then an issue message's",
|
|
30807
|
-
problem: "a block[] attribute points only at a block of a document"
|
|
30842
|
+
problem: "is a block of a message: a block[] attribute points only at a block of a document"
|
|
30808
30843
|
}
|
|
30809
30844
|
];
|
|
30810
30845
|
// ../contracts/src/envelope.ts
|
|
@@ -32854,7 +32889,7 @@ function parseBlockRef(holder, fragment) {
|
|
|
32854
32889
|
}
|
|
32855
32890
|
const pin = target.pin === undefined ? {} : { pin: target.pin };
|
|
32856
32891
|
const artifact = parsed.artifact === undefined ? {} : { artifact: parsed.artifact };
|
|
32857
|
-
if (parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
|
|
32892
|
+
if (parsed.kind === "ask" || parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
|
|
32858
32893
|
return {
|
|
32859
32894
|
owner: parsed.owner,
|
|
32860
32895
|
kind: "block",
|
|
@@ -34476,7 +34511,8 @@ var ErrorWireSchema = object({
|
|
|
34476
34511
|
});
|
|
34477
34512
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
34478
34513
|
recipient: string2().optional(),
|
|
34479
|
-
holder: string2().optional()
|
|
34514
|
+
holder: string2().optional(),
|
|
34515
|
+
duplicate: boolean2().optional()
|
|
34480
34516
|
});
|
|
34481
34517
|
var ReplayWireSchema = object({
|
|
34482
34518
|
stream: object({
|
|
@@ -34562,44 +34598,84 @@ class EnvoyApiError extends Error {
|
|
|
34562
34598
|
this.code = parsed?.code;
|
|
34563
34599
|
}
|
|
34564
34600
|
}
|
|
34601
|
+
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|
|
34602
|
+
|
|
34603
|
+
class EnvoySendUnconfirmedError extends Error {
|
|
34604
|
+
targetSessionID;
|
|
34605
|
+
idempotencyKey;
|
|
34606
|
+
attempts;
|
|
34607
|
+
last;
|
|
34608
|
+
name = "EnvoySendUnconfirmedError";
|
|
34609
|
+
resendSafe;
|
|
34610
|
+
constructor(targetSessionID, idempotencyKey, attempts, last) {
|
|
34611
|
+
const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
|
|
34612
|
+
const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
|
|
34613
|
+
const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
|
|
34614
|
+
const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
|
|
34615
|
+
super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
|
|
34616
|
+
this.targetSessionID = targetSessionID;
|
|
34617
|
+
this.idempotencyKey = idempotencyKey;
|
|
34618
|
+
this.attempts = attempts;
|
|
34619
|
+
this.last = last;
|
|
34620
|
+
this.resendSafe = resendSafe;
|
|
34621
|
+
}
|
|
34622
|
+
}
|
|
34565
34623
|
function createEnvoyClient(config) {
|
|
34566
34624
|
const baseUrl = normalizeEnvoyUrl(config.baseUrl);
|
|
34567
34625
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
34568
34626
|
const apiToken = config.token;
|
|
34627
|
+
const attempts = config.retry === false ? 1 : 2;
|
|
34628
|
+
const attemptOnce = async (url, init, deadlineMs) => {
|
|
34629
|
+
const headers = new Headers(init.headers);
|
|
34630
|
+
if (apiToken)
|
|
34631
|
+
headers.set("Authorization", `Bearer ${apiToken}`);
|
|
34632
|
+
let response;
|
|
34633
|
+
try {
|
|
34634
|
+
response = await config.fetch(url, {
|
|
34635
|
+
...init,
|
|
34636
|
+
headers,
|
|
34637
|
+
signal: AbortSignal.timeout(deadlineMs)
|
|
34638
|
+
});
|
|
34639
|
+
} catch (error) {
|
|
34640
|
+
return { unanswered: error };
|
|
34641
|
+
}
|
|
34642
|
+
try {
|
|
34643
|
+
return { response, body: await response.text() };
|
|
34644
|
+
} catch (error) {
|
|
34645
|
+
if (response.status >= 400 && response.status < 500) {
|
|
34646
|
+
return { response, body: `(its body did not arrive: ${String(error)})` };
|
|
34647
|
+
}
|
|
34648
|
+
return { unanswered: error };
|
|
34649
|
+
}
|
|
34650
|
+
};
|
|
34569
34651
|
const request = async (path, init, options = {}) => {
|
|
34570
34652
|
const url = `${baseUrl}${path}`;
|
|
34571
|
-
const attempts = config.retry === false ? 1 : 2;
|
|
34572
34653
|
const tries = options.retry === false ? 1 : attempts;
|
|
34573
34654
|
for (let attempt = 0;attempt < tries; attempt += 1) {
|
|
34574
|
-
|
|
34575
|
-
|
|
34576
|
-
|
|
34577
|
-
if (apiToken)
|
|
34578
|
-
headers.set("Authorization", `Bearer ${apiToken}`);
|
|
34579
|
-
response = await config.fetch(url, {
|
|
34580
|
-
...init,
|
|
34581
|
-
headers,
|
|
34582
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? timeoutMs)
|
|
34583
|
-
});
|
|
34584
|
-
} catch (error) {
|
|
34655
|
+
const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs);
|
|
34656
|
+
if ("unanswered" in outcome) {
|
|
34657
|
+
options.onUnanswered?.();
|
|
34585
34658
|
if (attempt + 1 < tries) {
|
|
34586
34659
|
await waitForRetry();
|
|
34587
34660
|
continue;
|
|
34588
34661
|
}
|
|
34589
|
-
throw
|
|
34662
|
+
throw outcome.unanswered;
|
|
34590
34663
|
}
|
|
34591
|
-
const
|
|
34664
|
+
const { response, body } = outcome;
|
|
34592
34665
|
if (response.ok)
|
|
34593
|
-
return
|
|
34666
|
+
return body;
|
|
34594
34667
|
const error = new EnvoyApiError({
|
|
34595
34668
|
method: init.method ?? "GET",
|
|
34596
34669
|
url,
|
|
34597
34670
|
status: response.status,
|
|
34598
|
-
responseBody
|
|
34671
|
+
responseBody: body
|
|
34599
34672
|
});
|
|
34600
|
-
if (response.status >= 500
|
|
34601
|
-
|
|
34602
|
-
|
|
34673
|
+
if (response.status >= 500) {
|
|
34674
|
+
options.onUnanswered?.();
|
|
34675
|
+
if (attempt + 1 < tries) {
|
|
34676
|
+
await waitForRetry();
|
|
34677
|
+
continue;
|
|
34678
|
+
}
|
|
34603
34679
|
}
|
|
34604
34680
|
throw error;
|
|
34605
34681
|
}
|
|
@@ -34635,18 +34711,33 @@ function createEnvoyClient(config) {
|
|
|
34635
34711
|
getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
|
|
34636
34712
|
send: async (input) => {
|
|
34637
34713
|
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
34638
|
-
|
|
34639
|
-
|
|
34640
|
-
|
|
34641
|
-
|
|
34642
|
-
|
|
34643
|
-
|
|
34644
|
-
|
|
34645
|
-
|
|
34714
|
+
let unanswered = false;
|
|
34715
|
+
let response;
|
|
34716
|
+
try {
|
|
34717
|
+
const answer = await post("/v1/messages/send", {
|
|
34718
|
+
source: input.source ?? "agent",
|
|
34719
|
+
...sourceSession(input.sourceSessionID),
|
|
34720
|
+
target_session: input.targetSessionID,
|
|
34721
|
+
message: input.message,
|
|
34722
|
+
idempotency_key: idempotencyKey,
|
|
34723
|
+
...messageMetadata(input)
|
|
34724
|
+
}, {
|
|
34725
|
+
onUnanswered: () => {
|
|
34726
|
+
unanswered = true;
|
|
34727
|
+
}
|
|
34728
|
+
});
|
|
34729
|
+
response = EnvelopeResponseSchema.parse(JSON.parse(answer));
|
|
34730
|
+
} catch (error) {
|
|
34731
|
+
if (error instanceof EnvoyApiError && error.details.status < 500 && !unanswered) {
|
|
34732
|
+
throw error;
|
|
34733
|
+
}
|
|
34734
|
+
throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, attempts, error);
|
|
34735
|
+
}
|
|
34646
34736
|
return {
|
|
34647
34737
|
envelope: response,
|
|
34648
34738
|
recipient: response.recipient ?? input.targetSessionID,
|
|
34649
|
-
confirmed: response.recipient !== undefined
|
|
34739
|
+
confirmed: response.recipient !== undefined,
|
|
34740
|
+
duplicate: response.duplicate === true
|
|
34650
34741
|
};
|
|
34651
34742
|
},
|
|
34652
34743
|
publish: async (input) => {
|
|
@@ -34685,7 +34776,13 @@ function createEnvoyClient(config) {
|
|
|
34685
34776
|
raw = await post("/v1/roles/set", body);
|
|
34686
34777
|
} catch (error) {
|
|
34687
34778
|
if (error instanceof EnvoyApiError && error.details.status === 409) {
|
|
34688
|
-
|
|
34779
|
+
let answer;
|
|
34780
|
+
try {
|
|
34781
|
+
answer = JSON.parse(error.details.responseBody);
|
|
34782
|
+
} catch {
|
|
34783
|
+
throw error;
|
|
34784
|
+
}
|
|
34785
|
+
const held = RoleHeldWireSchema.safeParse(answer);
|
|
34689
34786
|
if (held.success)
|
|
34690
34787
|
return { claimed: false, holder: held.data.holder };
|
|
34691
34788
|
}
|
|
@@ -36743,6 +36840,9 @@ function optionalNumber(args, name) {
|
|
|
36743
36840
|
const value = args[name];
|
|
36744
36841
|
return typeof value === "number" ? value : undefined;
|
|
36745
36842
|
}
|
|
36843
|
+
function article(kind) {
|
|
36844
|
+
return kind === "ask" ? "an ask" : `a ${kind}`;
|
|
36845
|
+
}
|
|
36746
36846
|
function refOwnerName(ref) {
|
|
36747
36847
|
return ref.owner.kind === "issue" ? ref.owner.issue : `${ref.owner.project}/${ref.artifact ?? ref.id}`;
|
|
36748
36848
|
}
|
|
@@ -36787,7 +36887,7 @@ function dispatchRefFromUrl(value, serverUrl) {
|
|
|
36787
36887
|
return `dispatch://${key}/artifact/${slug}${version}${blockOf("v")}`;
|
|
36788
36888
|
}
|
|
36789
36889
|
if (ask !== undefined)
|
|
36790
|
-
return `dispatch://${key}/ask/${ask}`;
|
|
36890
|
+
return `dispatch://${key}/ask/${ask}${blockOf()}`;
|
|
36791
36891
|
if (comment !== undefined)
|
|
36792
36892
|
return `dispatch://${key}/comment/${comment}${blockOf()}`;
|
|
36793
36893
|
if (message !== undefined)
|
|
@@ -36814,7 +36914,7 @@ function dispatchRefFromUrl(value, serverUrl) {
|
|
|
36814
36914
|
return;
|
|
36815
36915
|
return item === undefined ? `${document}${versionOf("version")}${blockOf("version")}` : `${document}/${item.kind}/${item.id}`;
|
|
36816
36916
|
}
|
|
36817
|
-
var refGrammarProblem = "ref must be a valid dispatch:// reference such as dispatch://KEY-1, " + "dispatch://KEY-1/ask/<uuid>, dispatch://KEY-1/comment/<uuid>, " + "dispatch://KEY-1/message/<uuid>, dispatch://KEY-1/artifact/<slug>, " + "dispatch://PROJECT/artifact/<document-ref> (an artifact id, slug, or filename), " + "dispatch://KEY-1/spec#b-<block id>, dispatch://KEY-1/artifact/<slug>#b-<block id> or " + "dispatch://PROJECT/artifact/<slug>#b-<block id> (one block of a document, its id " + "percent-encoded, optionally pinned to a version of the document with @v<N> after it; for " + "dispatch read), dispatch://KEY-1/comment/<uuid>#b-<block id>, " + "dispatch://PROJECT/artifact/<slug>/comment/<uuid>#b-<block id> or " + "dispatch://KEY-1/message/<uuid>#b-<block id> (one block of a comment or message, a " + "comment's optionally pinned to a revision of the comment with @v<N> after it; for dispatch " + "read), or " + "dispatch://agent/<session id>/artifact/<slug> (a picture in a conversation on the Agents page, " + "for dispatch doc-read); a dashboard URL on this Dispatch server is accepted too";
|
|
36917
|
+
var refGrammarProblem = "ref must be a valid dispatch:// reference such as dispatch://KEY-1, " + "dispatch://KEY-1/ask/<uuid>, dispatch://KEY-1/comment/<uuid>, " + "dispatch://KEY-1/message/<uuid>, dispatch://KEY-1/artifact/<slug>, " + "dispatch://PROJECT/artifact/<document-ref> (an artifact id, slug, or filename), " + "dispatch://KEY-1/spec#b-<block id>, dispatch://KEY-1/artifact/<slug>#b-<block id> or " + "dispatch://PROJECT/artifact/<slug>#b-<block id> (one block of a document, its id " + "percent-encoded, optionally pinned to a version of the document with @v<N> after it; for " + "dispatch read), dispatch://KEY-1/ask/<uuid>#b-<part id> or " + "dispatch://PROJECT/artifact/<slug>/ask/<uuid>#b-<part id> (one part of an ask: its question, " + "one of its options or its answer, optionally pinned to a revision of the ask's parts with " + "@v<N> after it; for dispatch read), dispatch://KEY-1/comment/<uuid>#b-<block id>, " + "dispatch://PROJECT/artifact/<slug>/comment/<uuid>#b-<block id> or " + "dispatch://KEY-1/message/<uuid>#b-<block id> (one block of a comment or message, a " + "comment's optionally pinned to a revision of the comment with @v<N> after it; for dispatch " + "read), or " + "dispatch://agent/<session id>/artifact/<slug> (a picture in a conversation on the Agents page, " + "for dispatch doc-read); a dashboard URL on this Dispatch server is accepted too";
|
|
36818
36918
|
var ownerRequiredProblem = "issue is required; supply issue or set LEGION_ISSUE";
|
|
36819
36919
|
function innerRefProblem(tool, ref, refText) {
|
|
36820
36920
|
if (ref.kind !== "ask" && ref.kind !== "comment" && ref.kind !== "message" && ref.kind !== "log" && ref.kind !== "children" && ref.kind !== "block") {
|
|
@@ -36826,8 +36926,9 @@ function innerRefProblem(tool, ref, refText) {
|
|
|
36826
36926
|
const itemKind = ref.item?.kind ?? ref.kind;
|
|
36827
36927
|
const documentArgument = ref.kind === "block" && ref.item === undefined && tool !== "dispatch_comment" ? ` and artifact ${ref.id}` : tool === "dispatch_suggest" ? " and artifact <the document's slug>" : "";
|
|
36828
36928
|
const ownerArguments = ref.owner.kind === "issue" ? `issue ${ref.owner.issue}${documentArgument}` : `project ${ref.owner.project} and artifact ${ref.artifact}`;
|
|
36829
|
-
const
|
|
36830
|
-
const
|
|
36929
|
+
const partRef = ref.pin === undefined ? refText : refText.slice(0, -`@v${ref.pin}`.length);
|
|
36930
|
+
const fix = tool === "dispatch_comment" && itemKind === "ask" ? `reply under it with reply_to_ask ${ref.item === undefined ? ref.id : partRef} and ${ownerArguments}` : tool === "dispatch_comment" && itemKind === "comment" ? `reply in its thread with reply_to ${ref.id} and ${ownerArguments}` : `read it with dispatch read, or name ${owner} with ${ownerArguments}`;
|
|
36931
|
+
const item = ref.kind === "ask" ? "an ask" : ref.kind === "log" ? "the event log" : ref.kind === "children" ? "the children" : ref.kind === "block" ? `block ${ref.block}${ref.item === undefined ? "" : ` of ${article(ref.item.kind)}`}` : `a ${ref.kind}`;
|
|
36831
36932
|
return `ref ${refText} names ${item} on ${owner}; dispatch ${commandName(tool)} would act on ${owner} and drop the ${ref.kind}: ${fix}`;
|
|
36832
36933
|
}
|
|
36833
36934
|
var documentItemPattern = /^dispatch:\/\/([A-Z][A-Z0-9]{1,9}-[1-9][0-9]*)\/artifact\/[^/@]+(?:@v\d+)?\/(ask|comment)\/([^/]+)$/;
|
|
@@ -37021,16 +37122,11 @@ function artifactByReference(artifacts, artifactReference, owner, canonical) {
|
|
|
37021
37122
|
const byId = artifacts.find((candidate) => candidate.id === artifactReference);
|
|
37022
37123
|
if (byId !== undefined)
|
|
37023
37124
|
return byId;
|
|
37024
|
-
|
|
37025
|
-
if (bySlug !== undefined) {
|
|
37026
|
-
const named = byName.filter((candidate) => candidate.id !== bySlug.id && candidate.kind === "doc");
|
|
37027
|
-
if (named.length > 0) {
|
|
37028
|
-
throw new Error(documentReferenceProblem(artifactReference, [bySlug, ...named], owner, "id"));
|
|
37029
|
-
}
|
|
37125
|
+
if (bySlug !== undefined)
|
|
37030
37126
|
return bySlug;
|
|
37031
|
-
|
|
37127
|
+
const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
|
|
37032
37128
|
if (byName.length > 1) {
|
|
37033
|
-
throw new Error(documentReferenceProblem(artifactReference, byName, owner,
|
|
37129
|
+
throw new Error(documentReferenceProblem(artifactReference, byName, owner, true));
|
|
37034
37130
|
}
|
|
37035
37131
|
const [artifact] = byName;
|
|
37036
37132
|
if (artifact === undefined) {
|
|
@@ -37085,10 +37181,10 @@ async function documentTargets(client, resolution) {
|
|
|
37085
37181
|
};
|
|
37086
37182
|
}
|
|
37087
37183
|
var documentHintLimit = 8;
|
|
37088
|
-
function documentReferenceProblem(reference, documents, owner,
|
|
37089
|
-
const hints = documents.slice(0, documentHintLimit).map((document) =>
|
|
37184
|
+
function documentReferenceProblem(reference, documents, owner, ambiguous = false) {
|
|
37185
|
+
const hints = documents.slice(0, documentHintLimit).map((document) => `${document.slug} (${document.name})`);
|
|
37090
37186
|
const list = hints.length === 0 ? "none" : hints.join(", ");
|
|
37091
|
-
return
|
|
37187
|
+
return ambiguous ? `"${reference}" names ${documents.length} documents on this ${owner}; use a slug: ${list}` : `document "${reference}" not found by slug; this ${owner}'s documents: ${list}`;
|
|
37092
37188
|
}
|
|
37093
37189
|
async function liveBlocks(client, artifact) {
|
|
37094
37190
|
const before = await client.docRead(artifact.id);
|
|
@@ -37686,10 +37782,11 @@ var envoyToolSpecs = [
|
|
|
37686
37782
|
},
|
|
37687
37783
|
{
|
|
37688
37784
|
name: "envoy_send",
|
|
37689
|
-
description: `Send an Envoy agent-to-agent message directly to another session by session ID. ${DELIVERY_CONTRACT}
|
|
37785
|
+
description: `Send an Envoy agent-to-agent message directly to another session by session ID. ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within 72 hours, and Envoy drops it as a repeat if the first copy arrived.`,
|
|
37690
37786
|
arguments: (schema) => ({
|
|
37691
37787
|
session_id: schema.string().describe("Target session ID; find it with envoy_sessions or envoy_whoami."),
|
|
37692
|
-
...messageArguments(schema)
|
|
37788
|
+
...messageArguments(schema),
|
|
37789
|
+
idempotency_key: schema.string().describe("Only to send again a message whose envoy_send was not confirmed delivered: the idempotency_key that error named. Omit it for a new message.").optional()
|
|
37693
37790
|
}),
|
|
37694
37791
|
operation: EnvoyToolOperation.send
|
|
37695
37792
|
},
|
|
@@ -37739,6 +37836,9 @@ var envoyToolSpecs = [
|
|
|
37739
37836
|
}
|
|
37740
37837
|
];
|
|
37741
37838
|
function sendConfirmationText(result) {
|
|
37839
|
+
if (result.duplicate) {
|
|
37840
|
+
return `sent to ${result.recipient} once: an earlier attempt under the same idempotency_key was already stored, so this one stored no second copy`;
|
|
37841
|
+
}
|
|
37742
37842
|
return `sent ${result.envelope.event_id} to ${result.recipient}${result.confirmed ? "" : " (recipient unconfirmed by listener)"}`;
|
|
37743
37843
|
}
|
|
37744
37844
|
function sessionsOnMachine(sessions, machine) {
|
|
@@ -37747,6 +37847,7 @@ function sessionsOnMachine(sessions, machine) {
|
|
|
37747
37847
|
return sessions.filter((session) => session.host === machine || session.machine_id === machine);
|
|
37748
37848
|
}
|
|
37749
37849
|
var envoyToolSchemas = new Map;
|
|
37850
|
+
var SEND_IDEMPOTENCY_KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
37750
37851
|
function parseEnvoyToolArguments(operation, parameters) {
|
|
37751
37852
|
const spec = envoyToolSpecs.find((candidate) => candidate.operation === operation);
|
|
37752
37853
|
if (spec === undefined)
|
|
@@ -37760,7 +37861,13 @@ function parseEnvoyToolArguments(operation, parameters) {
|
|
|
37760
37861
|
if (!parsed.success) {
|
|
37761
37862
|
throw new ToolInputError(spec.name, formatZodIssues(parsed.error.issues, schema, spec.name));
|
|
37762
37863
|
}
|
|
37763
|
-
|
|
37864
|
+
const { data } = parsed;
|
|
37865
|
+
if (typeof data === "object" && data !== null && "idempotency_key" in data && typeof data.idempotency_key === "string" && !SEND_IDEMPOTENCY_KEY.test(data.idempotency_key)) {
|
|
37866
|
+
throw new ToolInputError(spec.name, [
|
|
37867
|
+
`idempotency_key must be the key an unconfirmed send named, a lower-case UUID; got ${JSON.stringify(data.idempotency_key)}`
|
|
37868
|
+
]);
|
|
37869
|
+
}
|
|
37870
|
+
return data;
|
|
37764
37871
|
}
|
|
37765
37872
|
|
|
37766
37873
|
// ../pi-shared/src/interface.ts
|
|
@@ -38053,7 +38160,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
38053
38160
|
|
|
38054
38161
|
// package.json
|
|
38055
38162
|
var name = "@sjawhar/pi-envoy";
|
|
38056
|
-
var version2 = "15.0
|
|
38163
|
+
var version2 = "15.1.0";
|
|
38057
38164
|
var package_default = {
|
|
38058
38165
|
name,
|
|
38059
38166
|
version: version2,
|
|
@@ -45729,10 +45836,12 @@ Kept (they last while this session holds role ${registrationState.heldRole()}):
|
|
|
45729
45836
|
return toolSuccess(JSON.stringify(inbox, null, 2), { count: inbox.length });
|
|
45730
45837
|
case EnvoyToolOperation.send: {
|
|
45731
45838
|
const targetSessionID = stringFor(parameters, "session_id");
|
|
45839
|
+
const idempotencyKey = parameters.idempotency_key;
|
|
45732
45840
|
const result = await client.send({
|
|
45733
45841
|
sourceSessionID: await replyAddress(context),
|
|
45734
45842
|
targetSessionID,
|
|
45735
45843
|
message: stringFor(parameters, "message"),
|
|
45844
|
+
...typeof idempotencyKey === "string" ? { idempotencyKey } : {},
|
|
45736
45845
|
...toMessageMetadata(parameters)
|
|
45737
45846
|
});
|
|
45738
45847
|
return toolSuccess(sendConfirmationText(result), {
|
|
@@ -25,7 +25,7 @@ Which machines, files or people, the numbers, then "A happens to X, or B to Y?"
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
- In Legion, fix a clear defect in code your tree uses, hand others to the controller, and ask about decisions (`skill://legion-worker/references/findings.md`).
|
|
28
|
-
- An open ask is the request
|
|
28
|
+
- An open ask is the request; never repeat it in each message.
|
|
29
29
|
- Change an open ask's block with `dispatch edit-ask`, or `doc-edit`'s `replace` or `move`. An answered ask is fixed: ask anew.
|
|
30
30
|
- Answer a person's reply to an open ask with `dispatch comment --reply-to-ask`; `--turn agent` for a note that needs nothing from them.
|
|
31
31
|
- When an answer's option and text disagree, the text wins.
|
|
@@ -69,6 +69,7 @@ dispatch://KEY
|
|
|
69
69
|
dispatch://KEY/spec
|
|
70
70
|
dispatch://KEY/artifact/<slug>[@vN]
|
|
71
71
|
dispatch://KEY/ask/<id>
|
|
72
|
+
dispatch://KEY/ask/<id>#b-<part>[@vN]
|
|
72
73
|
dispatch://KEY/comment/<id>
|
|
73
74
|
dispatch://KEY/comment/<id>#b-<block>[@vN]
|
|
74
75
|
dispatch://KEY/message/<id>
|
|
@@ -78,9 +79,9 @@ dispatch://PROJECT/artifact/<slug>/ask/<id>
|
|
|
78
79
|
dispatch://PROJECT/artifact/<slug>/comment/<id>#b-<block>[@vN]
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
A bare id, filename or
|
|
82
|
+
A bare id, filename or path is not a reference, and outside Dispatch neither is `dispatch://`: give the `https://` link `dispatch` printed. Write each id whole, from `dispatch read`'s `Ask id:` or the page URL: the command takes a prefix, a person's link does not.
|
|
82
83
|
|
|
83
84
|
## Setup and the HTTP API
|
|
84
85
|
|
|
85
|
-
- Use a personal token from
|
|
86
|
+
- Use a personal token from **Settings → Agent tokens**, as `DISPATCH_TOKEN` or `dispatch.token` in the session's `envoy.json`.
|
|
86
87
|
- `GET /api/v1` lists every route; never guess one. Branch on an error's `code`, not its text.
|
|
@@ -14,6 +14,7 @@ Envoy delivers external events and messages between sessions. Delivery is at-lea
|
|
|
14
14
|
- Take the target id from the delivery's `reply_with`, or from `envoy_sessions` (filter by `machine`, `dir` or `title`). Never address a tmux pane or window: Envoy delivers only to a session id, and the session in a pane can change.
|
|
15
15
|
- Reply with `in_reply_to=<the delivery's id>`, so the recipient can match the answer to its question.
|
|
16
16
|
- Read the `recipient` in the send result, the session Envoy targeted: if it is not the one you meant, resend to the right id.
|
|
17
|
+
- When `envoy_send` says the send is not confirmed delivered, send the same message again with the `idempotency_key` the error names, within 72 hours: Envoy drops it as a repeat if the first copy arrived, and the result says when an earlier attempt was already stored. A resend without that key can deliver the message twice. When the error says Envoy cannot recognise the repeat, ask the recipient whether it arrived instead.
|
|
17
18
|
- Put the URL or path of what you report in the message, because the recipient cannot find your files any other way.
|
|
18
19
|
- Set `expects_reply="none"` on a message that needs no answer, and set `urgency` only when the work waits on the answer, so the recipient knows whether to answer and how soon. `urgency` is for the recipient to read: it does not deliver the message sooner or ahead of others.
|
|
19
20
|
|