@sjawhar/pi-envoy 17.30.0 → 17.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -7
- package/dist/dispatch.js +34 -13
- package/dist/envoy.js +161 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ threads, comments on its documents and routed issues, mentions, and messages, ne
|
|
|
138
138
|
word for word. A subagent reads its parent's list. The list stays under 8,000 characters (at most 7,999): the oldest
|
|
139
139
|
items that do not fit are left out, and its last line says how many and that `dispatch answers`
|
|
140
140
|
prints them all. It is read on every request and waits at most 800 ms for Dispatch. Past that,
|
|
141
|
-
or when the read fails, the
|
|
141
|
+
or when the read fails, the read gives the last list read, with the time it was read and why
|
|
142
142
|
this read failed, or, when no list read has an item from the last 72 hours, one line saying the
|
|
143
143
|
list could not be read and why. A Dispatch build older than the answers route answers it with its
|
|
144
144
|
own `404 NOT_FOUND` "no route for …". Against that Dispatch a request carries no such line, since
|
|
@@ -148,12 +148,31 @@ route; and that Dispatch is not asked again for 5 minutes. Any other answer, a p
|
|
|
148
148
|
a 200 that is no answers list included, is a failed read.
|
|
149
149
|
|
|
150
150
|
The list goes after the request's last message only on the request where it first shows an item,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
new words in one, or an item taken back. Items the 8,000-character limit leaves out count too: a
|
|
152
|
+
new message longer than the limit, or a comment an edit made too long to fit, moves the list,
|
|
153
|
+
whose last line then says how many items were left out. An answer a person retracted leaves the
|
|
154
|
+
list while its time is still inside the 72 hours, and that moves the list too; an item that only
|
|
155
|
+
aged out of the 72 hours does not. On every request after that the list stays right after the
|
|
156
|
+
message it followed there, with the bytes it had then, so the request ends with its own last
|
|
157
|
+
message and the model does not take a list with nothing new in it for a new turn. It keeps that
|
|
158
|
+
place and those bytes when it only loses items to the 72 hours or names another read, so a kept
|
|
159
|
+
list can name an older read than the request's own and still show an item that has since left
|
|
160
|
+
the 72 hours. A list an older copy of the extension added keeps its place only when nothing but
|
|
161
|
+
its read time and reason changed. A read with no list to give, the line saying the list could not
|
|
162
|
+
be read, is never hidden behind a kept list: that line goes after the last message, and the list
|
|
163
|
+
goes there again once a read gives it. A read that fails but still gives the last list read, with
|
|
164
|
+
the same items, keeps the kept list's place and bytes, so that request does not say that its read
|
|
165
|
+
failed, unless the kept bytes are that read's own text, which say it; otherwise the log says it
|
|
166
|
+
instead, with the reason, on the first such request and not again until a read has answered, so a
|
|
167
|
+
failure that lasts is one line. A read that finds nothing for the session takes a kept list out of
|
|
168
|
+
the request when an item it shows was taken back inside the 72 hours, as when a person retracts
|
|
169
|
+
the only answer, and leaves it where it is when its items only aged out; it takes a kept failure
|
|
170
|
+
line out. A Dispatch with no answers route, when no list read before from it has an item from the
|
|
171
|
+
last 72 hours (none was read, or every item of it has aged out), or no Dispatch at all, leaves a
|
|
172
|
+
kept list where it is. Moving the list empties its old place.
|
|
173
|
+
After a compaction summarizes the message it followed, or in a new process, the list goes after
|
|
174
|
+
the last message once more. It is never at the head, so a change in it costs only the bytes from
|
|
175
|
+
its place on, and a list that keeps its place is inside the cached prefix of the next request.
|
|
157
176
|
|
|
158
177
|
Oh My Pi also builds requests that are not turns of the conversation from it; those carry the
|
|
159
178
|
skill but no list, and wait on no read: a side turn (a Dispatch BTW, the stop-time self-check,
|
package/dist/dispatch.js
CHANGED
|
@@ -987,6 +987,20 @@ function messageFor(error) {
|
|
|
987
987
|
function hasErrnoCode(error, code) {
|
|
988
988
|
return error instanceof Error && "code" in error && error.code === code;
|
|
989
989
|
}
|
|
990
|
+
function withoutUserinfo(url) {
|
|
991
|
+
let parsed;
|
|
992
|
+
try {
|
|
993
|
+
parsed = new URL(url);
|
|
994
|
+
} catch {
|
|
995
|
+
return url.slice(url.lastIndexOf("@") + 1);
|
|
996
|
+
}
|
|
997
|
+
if (parsed.username === "" && parsed.password === "")
|
|
998
|
+
return url;
|
|
999
|
+
parsed.username = "";
|
|
1000
|
+
parsed.password = "";
|
|
1001
|
+
const shown = parsed.toString();
|
|
1002
|
+
return shown.endsWith("/") && !url.endsWith("/") ? shown.slice(0, -1) : shown;
|
|
1003
|
+
}
|
|
990
1004
|
|
|
991
1005
|
// ../envoy-client/src/askgate-marker.ts
|
|
992
1006
|
var ASKGATE_RECORD = "askgate";
|
|
@@ -18351,7 +18365,8 @@ class DispatchWriteLandedError extends Error {
|
|
|
18351
18365
|
name = "DispatchWriteLandedError";
|
|
18352
18366
|
constructor(code, status, method, url) {
|
|
18353
18367
|
const lost = code === IDEMPOTENCY_ANSWER_NOT_KEPT ? "Dispatch kept no copy of its answer, which was too large" : "its answer was lost on the way back";
|
|
18354
|
-
|
|
18368
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
18369
|
+
super(`${request} was made, but ${lost} (${code}), so this command cannot print what it ` + "made: read it back with `dispatch read`, or with the matching list for something it created.");
|
|
18355
18370
|
this.code = code;
|
|
18356
18371
|
this.status = status;
|
|
18357
18372
|
}
|
|
@@ -18372,7 +18387,8 @@ class DispatchNoRouteError extends DispatchServiceError {
|
|
|
18372
18387
|
}
|
|
18373
18388
|
}
|
|
18374
18389
|
function reviewNoRouteRefusal(baseUrl, route, version) {
|
|
18375
|
-
|
|
18390
|
+
const shown = withoutUserinfo(baseUrl);
|
|
18391
|
+
return new DispatchServiceError("NOT_FOUND", 404, `Dispatch at ${shown} answered no route for ${route} each time the review was sent, and an ` + "answer of no route records no review. This build is older than that route. No other review " + "route was asked: the review route an older build serves takes no version, and it " + `would record the review at a version that build chooses, which may not be version ${version}. ` + `The no-route answer does not name the build; GET ${shown}/healthz names the commit of the ` + "build that answers it, when that build was stamped with one.");
|
|
18376
18392
|
}
|
|
18377
18393
|
var ISSUE_EVENTS_PAGE_MAX = 200;
|
|
18378
18394
|
var DISPATCH_TOOL_DEADLINE_MS = 60000;
|
|
@@ -18634,7 +18650,8 @@ class DispatchClient {
|
|
|
18634
18650
|
const refusal = whyNotAPage(answer);
|
|
18635
18651
|
if (refusal === undefined)
|
|
18636
18652
|
return answer;
|
|
18637
|
-
|
|
18653
|
+
const url = withoutUserinfo(this.#url(path, query));
|
|
18654
|
+
throw new Error(`GET ${url} asked for a page ({issues, total, limit, offset}) and got ${refusal}`);
|
|
18638
18655
|
}
|
|
18639
18656
|
async listAllIssues(options) {
|
|
18640
18657
|
const path = ["api", "v1", "issues"];
|
|
@@ -18642,7 +18659,8 @@ class DispatchClient {
|
|
|
18642
18659
|
const answer = await this.#json("GET", path, undefined, query);
|
|
18643
18660
|
if (Array.isArray(answer))
|
|
18644
18661
|
return answer;
|
|
18645
|
-
|
|
18662
|
+
const url = withoutUserinfo(this.#url(path, query));
|
|
18663
|
+
throw new Error(`GET ${url} asked for the unpaged listing and got ${whyNotAnArray(answer)}.`);
|
|
18646
18664
|
}
|
|
18647
18665
|
async listIssueArtifacts(issue) {
|
|
18648
18666
|
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
@@ -19109,7 +19127,7 @@ class DispatchClient {
|
|
|
19109
19127
|
headers[IDEMPOTENCY_KEY_HEADER] = key;
|
|
19110
19128
|
const { pausesMs, withinMs, silenceMs, inFlightPauseMs, inFlightWithinMs } = this.writeRetry;
|
|
19111
19129
|
const pause = this.writeRetry.pause ?? pauseFor;
|
|
19112
|
-
const request = `${method} ${url}`;
|
|
19130
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
19113
19131
|
const started = this.#now();
|
|
19114
19132
|
const bodyBytes = body === undefined ? 0 : typeof body.content === "string" ? Buffer.byteLength(body.content) : body.content.byteLength;
|
|
19115
19133
|
const upload = bodyBytes >= STREAMED_BODY_MIN;
|
|
@@ -19292,7 +19310,8 @@ class DispatchClient {
|
|
|
19292
19310
|
}
|
|
19293
19311
|
const reasonPhrase = excerpt(response.statusText, this.token);
|
|
19294
19312
|
const reason = reasonPhrase === "" ? "" : ` ${reasonPhrase}`;
|
|
19295
|
-
|
|
19313
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
19314
|
+
throw new DispatchGatewayError(response.status, `${request} answered ${response.status}${reason} with ${body}, ${GATEWAY_PAGE}`, gatewayAdvice(method, response.status));
|
|
19296
19315
|
}
|
|
19297
19316
|
const replayed = response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1";
|
|
19298
19317
|
if (answerNotKept(response.status, replayed, payload)) {
|
|
@@ -19365,7 +19384,8 @@ function asObject(value) {
|
|
|
19365
19384
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
19366
19385
|
}
|
|
19367
19386
|
function sessionContext(input, checked) {
|
|
19368
|
-
const { url
|
|
19387
|
+
const { url, credential } = input.config;
|
|
19388
|
+
const configUrl = withoutUserinfo(url);
|
|
19369
19389
|
const baseFetch = input.fetchImpl ?? fetch;
|
|
19370
19390
|
const fetchImpl = Object.assign(async (...args) => {
|
|
19371
19391
|
try {
|
|
@@ -19383,9 +19403,9 @@ function sessionContext(input, checked) {
|
|
|
19383
19403
|
ownerArguments: checked.owner,
|
|
19384
19404
|
pictures: checked.pictures,
|
|
19385
19405
|
configUrl,
|
|
19386
|
-
linkBase: input.config.publicUrl ??
|
|
19406
|
+
linkBase: withoutUserinfo(input.config.publicUrl ?? url),
|
|
19387
19407
|
hostSession: input.sessionId?.trim(),
|
|
19388
|
-
newClient: () => new DispatchClient(
|
|
19408
|
+
newClient: () => new DispatchClient(url, credential, fetchImpl, {
|
|
19389
19409
|
signal: input.signal,
|
|
19390
19410
|
writeRetry: input.writeRetry,
|
|
19391
19411
|
sleep: input.sleep
|
|
@@ -21622,6 +21642,7 @@ function openAskLine(ask, baseUrl) {
|
|
|
21622
21642
|
return `- ${openAskAge(ask.age_seconds)} \xB7 ${priority}${ownerTitle(ask.owner)} \xB7 asked of ${waitsOnPerson(ask) ?? "nobody"} \xB7 ${ask.question} \xB7 ${new URL(ask.ref, baseUrl).toString()}`;
|
|
21623
21643
|
}
|
|
21624
21644
|
function formatOpenAsksSummary(response, baseUrl) {
|
|
21645
|
+
const linkBase = withoutUserinfo(baseUrl);
|
|
21625
21646
|
const scope = "active open asks you authored on open issues and project documents";
|
|
21626
21647
|
if (response.count === 0) {
|
|
21627
21648
|
return ["There are no unanswered asks for this session.", `Scope: ${scope}.`].join(`
|
|
@@ -21633,10 +21654,10 @@ function formatOpenAsksSummary(response, baseUrl) {
|
|
|
21633
21654
|
`${response.count} unanswered ${response.count === 1 ? "ask" : "asks"} you authored on active issues and project documents.`,
|
|
21634
21655
|
"",
|
|
21635
21656
|
`Waiting on human (${waitingOnHuman.length}):`,
|
|
21636
|
-
...waitingOnHuman.map((ask) => openAskLine(ask,
|
|
21657
|
+
...waitingOnHuman.map((ask) => openAskLine(ask, linkBase)),
|
|
21637
21658
|
"",
|
|
21638
21659
|
`Waiting on agent (${waitingOnAgent.length}):`,
|
|
21639
|
-
...waitingOnAgent.map((ask) => openAskLine(ask,
|
|
21660
|
+
...waitingOnAgent.map((ask) => openAskLine(ask, linkBase))
|
|
21640
21661
|
].join(`
|
|
21641
21662
|
`);
|
|
21642
21663
|
}
|
|
@@ -28809,7 +28830,7 @@ function createEnvoyClient(config) {
|
|
|
28809
28830
|
}
|
|
28810
28831
|
if (unminted !== undefined && (response.status === 401 || response.status === 403)) {
|
|
28811
28832
|
return {
|
|
28812
|
-
unanswered: new Error(`${init.method ?? "GET"} ${url} answered ${response.status}, and this machine's Envoy credential could not be minted: ${messageFor(unminted)}`, { cause: unminted })
|
|
28833
|
+
unanswered: new Error(`${init.method ?? "GET"} ${withoutUserinfo(url)} answered ${response.status}, and this machine's Envoy credential could not be minted: ${messageFor(unminted)}`, { cause: unminted })
|
|
28813
28834
|
};
|
|
28814
28835
|
}
|
|
28815
28836
|
try {
|
|
@@ -28839,7 +28860,7 @@ function createEnvoyClient(config) {
|
|
|
28839
28860
|
return body;
|
|
28840
28861
|
const error = new EnvoyApiError({
|
|
28841
28862
|
method: init.method ?? "GET",
|
|
28842
|
-
url,
|
|
28863
|
+
url: withoutUserinfo(url),
|
|
28843
28864
|
status: response.status,
|
|
28844
28865
|
responseBody: body
|
|
28845
28866
|
});
|
package/dist/envoy.js
CHANGED
|
@@ -32871,6 +32871,20 @@ function messageFor(error) {
|
|
|
32871
32871
|
function hasErrnoCode(error, code) {
|
|
32872
32872
|
return error instanceof Error && "code" in error && error.code === code;
|
|
32873
32873
|
}
|
|
32874
|
+
function withoutUserinfo(url) {
|
|
32875
|
+
let parsed;
|
|
32876
|
+
try {
|
|
32877
|
+
parsed = new URL(url);
|
|
32878
|
+
} catch {
|
|
32879
|
+
return url.slice(url.lastIndexOf("@") + 1);
|
|
32880
|
+
}
|
|
32881
|
+
if (parsed.username === "" && parsed.password === "")
|
|
32882
|
+
return url;
|
|
32883
|
+
parsed.username = "";
|
|
32884
|
+
parsed.password = "";
|
|
32885
|
+
const shown = parsed.toString();
|
|
32886
|
+
return shown.endsWith("/") && !url.endsWith("/") ? shown.slice(0, -1) : shown;
|
|
32887
|
+
}
|
|
32874
32888
|
|
|
32875
32889
|
// ../envoy-client/src/askgate-marker.ts
|
|
32876
32890
|
var ASKGATE_RECORD = "askgate";
|
|
@@ -37189,7 +37203,8 @@ class DispatchWriteLandedError extends Error {
|
|
|
37189
37203
|
name = "DispatchWriteLandedError";
|
|
37190
37204
|
constructor(code, status, method, url) {
|
|
37191
37205
|
const lost = code === IDEMPOTENCY_ANSWER_NOT_KEPT ? "Dispatch kept no copy of its answer, which was too large" : "its answer was lost on the way back";
|
|
37192
|
-
|
|
37206
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
37207
|
+
super(`${request} was made, but ${lost} (${code}), so this command cannot print what it ` + "made: read it back with `dispatch read`, or with the matching list for something it created.");
|
|
37193
37208
|
this.code = code;
|
|
37194
37209
|
this.status = status;
|
|
37195
37210
|
}
|
|
@@ -37210,7 +37225,8 @@ class DispatchNoRouteError extends DispatchServiceError {
|
|
|
37210
37225
|
}
|
|
37211
37226
|
}
|
|
37212
37227
|
function reviewNoRouteRefusal(baseUrl, route, version) {
|
|
37213
|
-
|
|
37228
|
+
const shown = withoutUserinfo(baseUrl);
|
|
37229
|
+
return new DispatchServiceError("NOT_FOUND", 404, `Dispatch at ${shown} answered no route for ${route} each time the review was sent, and an ` + "answer of no route records no review. This build is older than that route. No other review " + "route was asked: the review route an older build serves takes no version, and it " + `would record the review at a version that build chooses, which may not be version ${version}. ` + `The no-route answer does not name the build; GET ${shown}/healthz names the commit of the ` + "build that answers it, when that build was stamped with one.");
|
|
37214
37230
|
}
|
|
37215
37231
|
var ISSUE_EVENTS_PAGE_MAX = 200;
|
|
37216
37232
|
var DISPATCH_TOOL_DEADLINE_MS = 60000;
|
|
@@ -37443,7 +37459,8 @@ class DispatchClient {
|
|
|
37443
37459
|
const refusal = whyNotAPage(answer);
|
|
37444
37460
|
if (refusal === undefined)
|
|
37445
37461
|
return answer;
|
|
37446
|
-
|
|
37462
|
+
const url = withoutUserinfo(this.#url(path, query));
|
|
37463
|
+
throw new Error(`GET ${url} asked for a page ({issues, total, limit, offset}) and got ${refusal}`);
|
|
37447
37464
|
}
|
|
37448
37465
|
async listAllIssues(options) {
|
|
37449
37466
|
const path = ["api", "v1", "issues"];
|
|
@@ -37451,7 +37468,8 @@ class DispatchClient {
|
|
|
37451
37468
|
const answer = await this.#json("GET", path, undefined, query);
|
|
37452
37469
|
if (Array.isArray(answer))
|
|
37453
37470
|
return answer;
|
|
37454
|
-
|
|
37471
|
+
const url = withoutUserinfo(this.#url(path, query));
|
|
37472
|
+
throw new Error(`GET ${url} asked for the unpaged listing and got ${whyNotAnArray(answer)}.`);
|
|
37455
37473
|
}
|
|
37456
37474
|
async listIssueArtifacts(issue) {
|
|
37457
37475
|
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
@@ -37918,7 +37936,7 @@ class DispatchClient {
|
|
|
37918
37936
|
headers[IDEMPOTENCY_KEY_HEADER] = key;
|
|
37919
37937
|
const { pausesMs, withinMs, silenceMs, inFlightPauseMs, inFlightWithinMs } = this.writeRetry;
|
|
37920
37938
|
const pause = this.writeRetry.pause ?? pauseFor;
|
|
37921
|
-
const request = `${method} ${url}`;
|
|
37939
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
37922
37940
|
const started = this.#now();
|
|
37923
37941
|
const bodyBytes = body === undefined ? 0 : typeof body.content === "string" ? Buffer.byteLength(body.content) : body.content.byteLength;
|
|
37924
37942
|
const upload = bodyBytes >= STREAMED_BODY_MIN;
|
|
@@ -38101,7 +38119,8 @@ class DispatchClient {
|
|
|
38101
38119
|
}
|
|
38102
38120
|
const reasonPhrase = excerpt(response.statusText, this.token);
|
|
38103
38121
|
const reason = reasonPhrase === "" ? "" : ` ${reasonPhrase}`;
|
|
38104
|
-
|
|
38122
|
+
const request = `${method} ${withoutUserinfo(url)}`;
|
|
38123
|
+
throw new DispatchGatewayError(response.status, `${request} answered ${response.status}${reason} with ${body}, ${GATEWAY_PAGE}`, gatewayAdvice(method, response.status));
|
|
38105
38124
|
}
|
|
38106
38125
|
const replayed = response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1";
|
|
38107
38126
|
if (answerNotKept(response.status, replayed, payload)) {
|
|
@@ -39701,7 +39720,7 @@ function createEnvoyClient(config) {
|
|
|
39701
39720
|
}
|
|
39702
39721
|
if (unminted !== undefined && (response.status === 401 || response.status === 403)) {
|
|
39703
39722
|
return {
|
|
39704
|
-
unanswered: new Error(`${init.method ?? "GET"} ${url} answered ${response.status}, and this machine's Envoy credential could not be minted: ${messageFor(unminted)}`, { cause: unminted })
|
|
39723
|
+
unanswered: new Error(`${init.method ?? "GET"} ${withoutUserinfo(url)} answered ${response.status}, and this machine's Envoy credential could not be minted: ${messageFor(unminted)}`, { cause: unminted })
|
|
39705
39724
|
};
|
|
39706
39725
|
}
|
|
39707
39726
|
try {
|
|
@@ -39731,7 +39750,7 @@ function createEnvoyClient(config) {
|
|
|
39731
39750
|
return body;
|
|
39732
39751
|
const error = new EnvoyApiError({
|
|
39733
39752
|
method: init.method ?? "GET",
|
|
39734
|
-
url,
|
|
39753
|
+
url: withoutUserinfo(url),
|
|
39735
39754
|
status: response.status,
|
|
39736
39755
|
responseBody: body
|
|
39737
39756
|
});
|
|
@@ -42852,6 +42871,7 @@ function openAskLine(ask, baseUrl) {
|
|
|
42852
42871
|
return `- ${openAskAge(ask.age_seconds)} \xB7 ${priority}${ownerTitle(ask.owner)} \xB7 asked of ${waitsOnPerson(ask) ?? "nobody"} \xB7 ${ask.question} \xB7 ${new URL(ask.ref, baseUrl).toString()}`;
|
|
42853
42872
|
}
|
|
42854
42873
|
function formatOpenAsksSummary(response, baseUrl) {
|
|
42874
|
+
const linkBase = withoutUserinfo(baseUrl);
|
|
42855
42875
|
const scope = "active open asks you authored on open issues and project documents";
|
|
42856
42876
|
if (response.count === 0) {
|
|
42857
42877
|
return ["There are no unanswered asks for this session.", `Scope: ${scope}.`].join(`
|
|
@@ -42863,10 +42883,10 @@ function formatOpenAsksSummary(response, baseUrl) {
|
|
|
42863
42883
|
`${response.count} unanswered ${response.count === 1 ? "ask" : "asks"} you authored on active issues and project documents.`,
|
|
42864
42884
|
"",
|
|
42865
42885
|
`Waiting on human (${waitingOnHuman.length}):`,
|
|
42866
|
-
...waitingOnHuman.map((ask) => openAskLine(ask,
|
|
42886
|
+
...waitingOnHuman.map((ask) => openAskLine(ask, linkBase)),
|
|
42867
42887
|
"",
|
|
42868
42888
|
`Waiting on agent (${waitingOnAgent.length}):`,
|
|
42869
|
-
...waitingOnAgent.map((ask) => openAskLine(ask,
|
|
42889
|
+
...waitingOnAgent.map((ask) => openAskLine(ask, linkBase))
|
|
42870
42890
|
].join(`
|
|
42871
42891
|
`);
|
|
42872
42892
|
}
|
|
@@ -45380,6 +45400,12 @@ function withinWindow(items, now) {
|
|
|
45380
45400
|
const start = now - SESSION_ANSWERS_WINDOW_MS;
|
|
45381
45401
|
return items.filter((item) => Date.parse(item.at) >= start);
|
|
45382
45402
|
}
|
|
45403
|
+
function windowOf(items, now) {
|
|
45404
|
+
return {
|
|
45405
|
+
words: sessionAnswersWords(withinWindow(items, now)),
|
|
45406
|
+
since: new Date(now - SESSION_ANSWERS_WINDOW_MS).toISOString()
|
|
45407
|
+
};
|
|
45408
|
+
}
|
|
45383
45409
|
function sessionAnswersWords(items) {
|
|
45384
45410
|
return items.map((item) => JSON.stringify([
|
|
45385
45411
|
item.kind,
|
|
@@ -45391,12 +45417,33 @@ function sessionAnswersWords(items) {
|
|
|
45391
45417
|
item.text
|
|
45392
45418
|
]));
|
|
45393
45419
|
}
|
|
45420
|
+
function wordTime(word) {
|
|
45421
|
+
try {
|
|
45422
|
+
const fields = JSON.parse(word);
|
|
45423
|
+
return Array.isArray(fields) && typeof fields[3] === "string" ? Date.parse(fields[3]) : Number.NaN;
|
|
45424
|
+
} catch {
|
|
45425
|
+
return Number.NaN;
|
|
45426
|
+
}
|
|
45427
|
+
}
|
|
45428
|
+
function sessionAnswersChanged(shown, next, since) {
|
|
45429
|
+
const before = new Set(shown);
|
|
45430
|
+
if (next.some((word) => !before.has(word)))
|
|
45431
|
+
return true;
|
|
45432
|
+
const after = new Set(next);
|
|
45433
|
+
const start = since === undefined ? Number.NaN : Date.parse(since);
|
|
45434
|
+
return shown.some((word) => {
|
|
45435
|
+
if (after.has(word))
|
|
45436
|
+
return false;
|
|
45437
|
+
const at = wordTime(word);
|
|
45438
|
+
return Number.isNaN(at) || Number.isNaN(start) || at >= start;
|
|
45439
|
+
});
|
|
45440
|
+
}
|
|
45394
45441
|
var MAX_CHARS_TEXT = SESSION_ANSWERS_MAX_CHARS.toLocaleString("en-US");
|
|
45395
45442
|
function leftOutLine(count, namesCommand) {
|
|
45396
45443
|
const counted = `${count} older ${count === 1 ? "item" : "items"} left out to stay under ${MAX_CHARS_TEXT} characters`;
|
|
45397
45444
|
return namesCommand ? `${counted}: run \`dispatch answers\` to read every one in full.` : `${counted}.`;
|
|
45398
45445
|
}
|
|
45399
|
-
function
|
|
45446
|
+
function renderSessionAnswers(items, options) {
|
|
45400
45447
|
const inWindow = withinWindow(items, Number(options.now));
|
|
45401
45448
|
const unsent = inWindow.length === items.length ? Math.max(0, (options.total ?? items.length) - items.length) : 0;
|
|
45402
45449
|
const count = inWindow.length + unsent;
|
|
@@ -45424,7 +45471,7 @@ As read at ${options.cached.readAt}; this read failed: ${failureSentence(options
|
|
|
45424
45471
|
].join(`
|
|
45425
45472
|
|
|
45426
45473
|
`);
|
|
45427
|
-
return
|
|
45474
|
+
return text;
|
|
45428
45475
|
}
|
|
45429
45476
|
function renderSessionAnswersList(items, options) {
|
|
45430
45477
|
const shown = withinWindow(items, Number(options.now));
|
|
@@ -45497,24 +45544,19 @@ async function readSessionAnswers(options) {
|
|
|
45497
45544
|
const entries = state.sessions.get(session) ?? new Map;
|
|
45498
45545
|
state.sessions.set(session, entries);
|
|
45499
45546
|
const carry = (cache, reason, noRoute = false) => {
|
|
45500
|
-
const
|
|
45501
|
-
|
|
45547
|
+
const at = now();
|
|
45548
|
+
const text = cache === undefined ? undefined : renderSessionAnswers(cache.items, {
|
|
45549
|
+
now: at,
|
|
45502
45550
|
total: cache.total,
|
|
45503
45551
|
cached: { readAt: cache.read_at, reason },
|
|
45504
45552
|
withoutCommand: noRoute
|
|
45505
45553
|
});
|
|
45506
|
-
if (cache === undefined ||
|
|
45554
|
+
if (cache === undefined || text === undefined) {
|
|
45507
45555
|
if (noRoute)
|
|
45508
45556
|
return { text: undefined, source: "unavailable", reason };
|
|
45509
45557
|
return { text: sessionAnswersFailureLine(reason), source: "failure", reason };
|
|
45510
45558
|
}
|
|
45511
|
-
return {
|
|
45512
|
-
text: rendered.text,
|
|
45513
|
-
source: "cache",
|
|
45514
|
-
readAt: cache.read_at,
|
|
45515
|
-
words: sessionAnswersWords(rendered.shown),
|
|
45516
|
-
reason
|
|
45517
|
-
};
|
|
45559
|
+
return { text, source: "cache", readAt: cache.read_at, ...windowOf(cache.items, at), reason };
|
|
45518
45560
|
};
|
|
45519
45561
|
if (!dispatch.enabled) {
|
|
45520
45562
|
const url = options.dispatchUrl;
|
|
@@ -45541,7 +45583,7 @@ async function readSessionAnswers(options) {
|
|
|
45541
45583
|
current.noRouteReported = true;
|
|
45542
45584
|
return {
|
|
45543
45585
|
...read,
|
|
45544
|
-
notice: `Dispatch at ${url} has no answers route (its build is older than the route), so people's answers cannot be read from it`
|
|
45586
|
+
notice: `Dispatch at ${withoutUserinfo(url)} has no answers route (its build is older than the route), so people's answers cannot be read from it`
|
|
45545
45587
|
};
|
|
45546
45588
|
};
|
|
45547
45589
|
if ((state.noRouteUntil.get(url) ?? 0) > now())
|
|
@@ -45555,6 +45597,7 @@ async function readSessionAnswers(options) {
|
|
|
45555
45597
|
retryNoRoute: false
|
|
45556
45598
|
});
|
|
45557
45599
|
const started = client.sessionAnswers(session, {
|
|
45600
|
+
since: new Date(now() - SESSION_ANSWERS_WINDOW_MS).toISOString(),
|
|
45558
45601
|
maxChars: SESSION_ANSWERS_MAX_CHARS,
|
|
45559
45602
|
signal: AbortSignal.timeout(READ_TIMEOUT_MS)
|
|
45560
45603
|
}).then((response) => {
|
|
@@ -45606,12 +45649,12 @@ async function readSessionAnswers(options) {
|
|
|
45606
45649
|
return noRoute();
|
|
45607
45650
|
if ("failure" in outcome)
|
|
45608
45651
|
return carry(current.cache, outcome.failure);
|
|
45609
|
-
const
|
|
45652
|
+
const at = now();
|
|
45610
45653
|
return {
|
|
45611
|
-
text:
|
|
45654
|
+
text: renderSessionAnswers(outcome.cache.items, { now: at, total: outcome.cache.total }),
|
|
45612
45655
|
source: "fresh",
|
|
45613
45656
|
readAt: outcome.cache.read_at,
|
|
45614
|
-
|
|
45657
|
+
...windowOf(outcome.cache.items, at)
|
|
45615
45658
|
};
|
|
45616
45659
|
}
|
|
45617
45660
|
|
|
@@ -47651,7 +47694,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
47651
47694
|
|
|
47652
47695
|
// package.json
|
|
47653
47696
|
var name = "@sjawhar/pi-envoy";
|
|
47654
|
-
var version2 = "17.30.
|
|
47697
|
+
var version2 = "17.30.2";
|
|
47655
47698
|
var package_default = {
|
|
47656
47699
|
name,
|
|
47657
47700
|
version: version2,
|
|
@@ -48993,32 +49036,96 @@ var CONVERSIONS_KEY = Symbol.for("legion.pi-envoy.session-answers-conversions.v1
|
|
|
48993
49036
|
var conversionsGlobal = globalThis;
|
|
48994
49037
|
var conversions = conversionsGlobal[CONVERSIONS_KEY] ?? new WeakMap;
|
|
48995
49038
|
conversionsGlobal[CONVERSIONS_KEY] = conversions;
|
|
49039
|
+
function carriedAnswers(read) {
|
|
49040
|
+
if (read.text === undefined && read.words === undefined)
|
|
49041
|
+
return;
|
|
49042
|
+
const reason = read.source === "cache" ? read.reason : undefined;
|
|
49043
|
+
const answered = read.source === "fresh";
|
|
49044
|
+
return { text: read.text, words: read.words, since: read.since, reason, answered };
|
|
49045
|
+
}
|
|
48996
49046
|
var PLACEMENTS_KEY = Symbol.for("legion.pi-envoy.session-answers-placements.v1");
|
|
48997
49047
|
var placementsGlobal = globalThis;
|
|
48998
49048
|
var placements = placementsGlobal[PLACEMENTS_KEY] ?? new WeakMap;
|
|
48999
49049
|
placementsGlobal[PLACEMENTS_KEY] = placements;
|
|
49050
|
+
var UNSHOWN_KEY = Symbol.for("legion.pi-envoy.session-answers-unshown.v1");
|
|
49051
|
+
var unshownGlobal = globalThis;
|
|
49052
|
+
var unshown = unshownGlobal[UNSHOWN_KEY] ?? new WeakMap;
|
|
49053
|
+
unshownGlobal[UNSHOWN_KEY] = unshown;
|
|
49054
|
+
var READ_LINE_PREFIX = "As read at ";
|
|
49055
|
+
function withoutReadLine(text) {
|
|
49056
|
+
const lines = text.split(`
|
|
49057
|
+
`);
|
|
49058
|
+
return lines[1]?.startsWith(READ_LINE_PREFIX) === true ? [lines[0], ...lines.slice(2)].join(`
|
|
49059
|
+
`) : text;
|
|
49060
|
+
}
|
|
49061
|
+
function failedRead(text) {
|
|
49062
|
+
const line = text.split(`
|
|
49063
|
+
`)[1];
|
|
49064
|
+
if (line?.startsWith(READ_LINE_PREFIX) !== true)
|
|
49065
|
+
return;
|
|
49066
|
+
const failed = "; this read failed: ";
|
|
49067
|
+
const at = line.indexOf(failed);
|
|
49068
|
+
return at < 0 ? undefined : line.slice(at + failed.length);
|
|
49069
|
+
}
|
|
49070
|
+
function isList(carried) {
|
|
49071
|
+
return carried.text.startsWith(SESSION_ANSWERS_MARKER);
|
|
49072
|
+
}
|
|
49000
49073
|
function showsNew(shown, next) {
|
|
49001
|
-
if (shown
|
|
49002
|
-
return
|
|
49003
|
-
|
|
49004
|
-
|
|
49074
|
+
if (isList(shown) !== isList(next))
|
|
49075
|
+
return true;
|
|
49076
|
+
if (!isList(next))
|
|
49077
|
+
return false;
|
|
49078
|
+
if (shown.words === undefined || next.words === undefined) {
|
|
49079
|
+
return withoutReadLine(shown.text) !== withoutReadLine(next.text);
|
|
49080
|
+
}
|
|
49081
|
+
return sessionAnswersChanged(shown.words, next.words, next.since);
|
|
49082
|
+
}
|
|
49083
|
+
function keepPlaced(messages, placed) {
|
|
49084
|
+
const index = messages.findLastIndex((message) => messageKey(message) === placed.after);
|
|
49085
|
+
if (index < 0)
|
|
49086
|
+
return;
|
|
49087
|
+
return [
|
|
49088
|
+
...messages.slice(0, index + 1),
|
|
49089
|
+
userTextMessage(placed.carried.text),
|
|
49090
|
+
...messages.slice(index + 1)
|
|
49091
|
+
];
|
|
49092
|
+
}
|
|
49093
|
+
function keptWithoutText(messages, carried, request, compacting) {
|
|
49094
|
+
const sessions = placements.get(request.session);
|
|
49095
|
+
const placed = sessions?.get(request.id);
|
|
49096
|
+
if (sessions === undefined || placed === undefined)
|
|
49097
|
+
return;
|
|
49098
|
+
const shown = placed.carried.words;
|
|
49099
|
+
const next = carried?.words;
|
|
49100
|
+
const withdrawn = next !== undefined && (shown === undefined || sessionAnswersChanged(shown, next, carried?.since));
|
|
49101
|
+
if (!isList(placed.carried) || withdrawn) {
|
|
49102
|
+
sessions.delete(request.id);
|
|
49103
|
+
return;
|
|
49104
|
+
}
|
|
49105
|
+
return compacting ? undefined : keepPlaced(messages, placed);
|
|
49005
49106
|
}
|
|
49006
49107
|
function placeList(messages, carried, request, compacting) {
|
|
49007
|
-
const list = userTextMessage(carried.text);
|
|
49008
49108
|
if (compacting)
|
|
49009
|
-
return [...messages,
|
|
49109
|
+
return [...messages, userTextMessage(carried.text)];
|
|
49010
49110
|
const sessions = placements.get(request.session) ?? new Map;
|
|
49011
49111
|
placements.set(request.session, sessions);
|
|
49012
49112
|
const placed = sessions.get(request.id);
|
|
49013
49113
|
if (placed !== undefined && !showsNew(placed.carried, carried)) {
|
|
49014
|
-
const
|
|
49015
|
-
if (
|
|
49016
|
-
|
|
49017
|
-
|
|
49114
|
+
const kept = keepPlaced(messages, placed);
|
|
49115
|
+
if (kept !== undefined) {
|
|
49116
|
+
if (carried.reason !== undefined && carried.text !== placed.carried.text) {
|
|
49117
|
+
const told = unshown.get(request.session) ?? new Set;
|
|
49118
|
+
unshown.set(request.session, told);
|
|
49119
|
+
if (!told.has(request.id)) {
|
|
49120
|
+
told.add(request.id);
|
|
49121
|
+
request.unshownFailure(carried.reason);
|
|
49122
|
+
}
|
|
49123
|
+
}
|
|
49124
|
+
return kept;
|
|
49018
49125
|
}
|
|
49019
49126
|
}
|
|
49020
49127
|
sessions.set(request.id, { after: messageKey(messages.at(-1)), carried });
|
|
49021
|
-
return [...messages,
|
|
49128
|
+
return [...messages, userTextMessage(carried.text)];
|
|
49022
49129
|
}
|
|
49023
49130
|
async function withSessionAnswers(messages, request) {
|
|
49024
49131
|
if (decided.has(messages))
|
|
@@ -49042,10 +49149,13 @@ async function withSessionAnswers(messages, request) {
|
|
|
49042
49149
|
return;
|
|
49043
49150
|
}
|
|
49044
49151
|
const carried = await request.read();
|
|
49045
|
-
if (carried ===
|
|
49046
|
-
|
|
49047
|
-
const
|
|
49048
|
-
|
|
49152
|
+
if (carried?.answered === true)
|
|
49153
|
+
unshown.get(request.session)?.delete(request.id);
|
|
49154
|
+
const compacting = previous === "cut" || request.compacting();
|
|
49155
|
+
const text = carried?.text;
|
|
49156
|
+
const placed = carried === undefined || text === undefined ? keptWithoutText(messages, carried, request, compacting) : placeList(messages, { ...carried, text }, request, compacting);
|
|
49157
|
+
if (placed !== undefined)
|
|
49158
|
+
decided.add(placed);
|
|
49049
49159
|
return placed;
|
|
49050
49160
|
}
|
|
49051
49161
|
function placedLegacy(messages, request) {
|
|
@@ -49056,7 +49166,11 @@ function placedLegacy(messages, request) {
|
|
|
49056
49166
|
return;
|
|
49057
49167
|
const recorded = conversions.get(request.session);
|
|
49058
49168
|
const compacting = typeof recorded === "object" && recorded.afterCut || request.compacting();
|
|
49059
|
-
const
|
|
49169
|
+
const reason = failedRead(text);
|
|
49170
|
+
if (reason === undefined && text.startsWith(SESSION_ANSWERS_MARKER)) {
|
|
49171
|
+
unshown.get(request.session)?.delete(request.id);
|
|
49172
|
+
}
|
|
49173
|
+
const placed = placeList(messages.slice(0, -1), { text, reason }, request, compacting);
|
|
49060
49174
|
decided.add(placed);
|
|
49061
49175
|
return placed;
|
|
49062
49176
|
}
|
|
@@ -55243,10 +55357,10 @@ ${LATE_BTW_NOTE}`, "inert", identity, claim);
|
|
|
55243
55357
|
});
|
|
55244
55358
|
if (read.notice !== undefined)
|
|
55245
55359
|
logger3.warn(`envoy: ${read.notice}`);
|
|
55246
|
-
return read
|
|
55360
|
+
return carriedAnswers(read);
|
|
55247
55361
|
} catch (error) {
|
|
55248
55362
|
logger3.warn(`envoy: people's answers could not be read: ${messageFor(error)}`);
|
|
55249
|
-
return { text: sessionAnswersFailureLine(messageFor(error))
|
|
55363
|
+
return { text: sessionAnswersFailureLine(messageFor(error)) };
|
|
55250
55364
|
}
|
|
55251
55365
|
};
|
|
55252
55366
|
if (atStart.dispatch.enabled || inbound) {
|
|
@@ -55263,7 +55377,8 @@ ${LATE_BTW_NOTE}`, "inert", identity, claim);
|
|
|
55263
55377
|
const live = liveAgentSession(context.sessionManager.getSessionId());
|
|
55264
55378
|
return live !== undefined && (("isCompacting" in live) && live.isCompacting === true || ("compactionSpeculation" in live) && live.compactionSpeculation === "running");
|
|
55265
55379
|
},
|
|
55266
|
-
read: () => sessionAnswersText(context)
|
|
55380
|
+
read: () => sessionAnswersText(context),
|
|
55381
|
+
unshownFailure: (reason) => logger3.warn(`envoy: people's answers could not be read (${reason}); the request keeps the list placed before, which does not name this read's failure`)
|
|
55267
55382
|
});
|
|
55268
55383
|
const result = messages ?? withSkill ?? aged;
|
|
55269
55384
|
return result === undefined ? undefined : { messages: result };
|