@sjawhar/claude-envoy 2.22.0 → 2.23.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.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "2.22.0"
5
+ "version": "2.23.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
package/dist/dispatch.js CHANGED
@@ -15662,7 +15662,7 @@ var dispatchToolSpecs = [
15662
15662
  {
15663
15663
  name: "dispatch_read",
15664
15664
  example: { issue: "DSP-1" },
15665
- description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOCUMENT_UNLOADABLE` (the document " + "needs a rebuild) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
15665
+ description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOC_NEWER_CONTENT` (this Dispatch " + "build cannot read an element of the document; try again in one minute), `DOCUMENT_UNLOADABLE` (the " + "document's stored history cannot load; a person decides whether to rebuild it) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
15666
15666
  arguments: (z) => ({
15667
15667
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
15668
15668
  project: z.string().describe("Project key owning the document.").optional(),
@@ -16361,6 +16361,45 @@ var MessageAcceptedEventPayloadSchema = strictObject({
16361
16361
  accepted_as: literal("user_turn"),
16362
16362
  target: string2()
16363
16363
  }).readonly();
16364
+ // ../contracts/src/dispatch-api-requests.ts
16365
+ var NO_ROUTE_MESSAGE_PREFIX = "no route for ";
16366
+ var NO_ROUTE_RETRY_DELAYS_MS = [1000, 2000, 4000];
16367
+ var NO_ROUTE_ROLLING_RELEASE_MESSAGE = "The Dispatch process that answered does not offer this action yet, because a new release of " + "Dispatch is in progress. Try again in one minute.";
16368
+ var sleep = (ms, signal) => {
16369
+ const { promise, resolve, reject } = Promise.withResolvers();
16370
+ if (signal?.aborted) {
16371
+ reject(signal.reason);
16372
+ return promise;
16373
+ }
16374
+ const abort = () => {
16375
+ clearTimeout(timer);
16376
+ reject(signal?.reason);
16377
+ };
16378
+ const timer = setTimeout(() => {
16379
+ signal?.removeEventListener("abort", abort);
16380
+ resolve();
16381
+ }, ms);
16382
+ signal?.addEventListener("abort", abort, { once: true });
16383
+ return promise;
16384
+ };
16385
+ function jitteredDelay(ms) {
16386
+ return ms * (0.75 + Math.random() * 0.5);
16387
+ }
16388
+ async function retryNoRoute(attempt, isNoRoute, options) {
16389
+ const wait = options.sleep ?? sleep;
16390
+ for (const delay of [...NO_ROUTE_RETRY_DELAYS_MS, undefined]) {
16391
+ try {
16392
+ return await attempt();
16393
+ } catch (error) {
16394
+ if (!isNoRoute(error))
16395
+ throw error;
16396
+ if (delay === undefined)
16397
+ break;
16398
+ }
16399
+ await wait(jitteredDelay(delay), options.signal);
16400
+ }
16401
+ throw options.exhausted();
16402
+ }
16364
16403
  // ../contracts/src/dispatch-api-search.ts
16365
16404
  var SEARCH_MEMBERS_EVERY_BUILD_READS = [
16366
16405
  "q",
@@ -18392,7 +18431,13 @@ function isJson(response) {
18392
18431
  return response.headers.get("content-type")?.includes("application/json") ?? false;
18393
18432
  }
18394
18433
  function isNoRoute(error) {
18395
- return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith("no route for ");
18434
+ return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith(NO_ROUTE_MESSAGE_PREFIX);
18435
+ }
18436
+
18437
+ class DispatchNoRouteError extends DispatchServiceError {
18438
+ constructor() {
18439
+ super("NOT_FOUND", 404, NO_ROUTE_ROLLING_RELEASE_MESSAGE);
18440
+ }
18396
18441
  }
18397
18442
  var ISSUE_EVENTS_PAGE_MAX = 200;
18398
18443
  var DISPATCH_TOOL_DEADLINE_MS = 60000;
@@ -18610,18 +18655,22 @@ function excerpt(text, token) {
18610
18655
 
18611
18656
  class DispatchClient {
18612
18657
  fetchImpl;
18613
- writeRetry;
18614
18658
  #baseUrl;
18615
18659
  #resolvedIssues = new Map;
18616
18660
  #signal;
18617
18661
  #credential;
18662
+ #sleep;
18663
+ #retryNoRoute;
18664
+ writeRetry;
18618
18665
  #madeAt;
18619
- constructor(baseUrl, credential, fetchImpl = fetch, signal, writeRetry = DISPATCH_WRITE_RETRY) {
18666
+ constructor(baseUrl, credential, fetchImpl = fetch, options = {}) {
18620
18667
  this.fetchImpl = fetchImpl;
18621
- this.writeRetry = writeRetry;
18622
18668
  this.#credential = credential;
18623
18669
  this.#baseUrl = withoutTrailingSlashes(baseUrl);
18624
- this.#signal = requestSignal(signal);
18670
+ this.#signal = requestSignal(options.signal);
18671
+ this.writeRetry = options.writeRetry ?? DISPATCH_WRITE_RETRY;
18672
+ this.#sleep = options.sleep ?? sleep;
18673
+ this.#retryNoRoute = options.retryNoRoute ?? true;
18625
18674
  this.#madeAt = this.#now();
18626
18675
  }
18627
18676
  get token() {
@@ -18776,7 +18825,7 @@ class DispatchClient {
18776
18825
  try {
18777
18826
  return await this.#json("GET", ["api", "v1", "projects", project, "architecture-sources"]);
18778
18827
  } catch (error) {
18779
- if (!isNoRoute(error))
18828
+ if (!(error instanceof DispatchNoRouteError))
18780
18829
  throw error;
18781
18830
  }
18782
18831
  try {
@@ -18806,7 +18855,7 @@ class DispatchClient {
18806
18855
  "sync"
18807
18856
  ]);
18808
18857
  } catch (error) {
18809
- if (!isNoRoute(error))
18858
+ if (!(error instanceof DispatchNoRouteError))
18810
18859
  throw error;
18811
18860
  }
18812
18861
  const source = await this.#json("POST", [
@@ -18932,13 +18981,15 @@ class DispatchClient {
18932
18981
  }
18933
18982
  async fileVersion(id, version) {
18934
18983
  const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
18935
- const response = await this.#send("GET", url, undefined, "*/*");
18936
- if (!response.ok)
18937
- return this.#response("GET", url, response);
18938
- return {
18939
- mime: response.headers.get("Content-Type") ?? "application/octet-stream",
18940
- bytes: new Uint8Array(await response.arrayBuffer())
18941
- };
18984
+ return this.#noRoute(async () => {
18985
+ const response = await this.#send("GET", url, undefined, "*/*");
18986
+ if (!response.ok)
18987
+ return this.#response("GET", url, response);
18988
+ return {
18989
+ mime: response.headers.get("Content-Type") ?? "application/octet-stream",
18990
+ bytes: new Uint8Array(await response.arrayBuffer())
18991
+ };
18992
+ });
18942
18993
  }
18943
18994
  async artifactBlocks(id) {
18944
18995
  return this.#json("GET", ["api", "v1", "artifacts", id, "blocks"]);
@@ -19040,8 +19091,19 @@ class DispatchClient {
19040
19091
  }
19041
19092
  async#jsonAnswer(method, path, body, query, signal, key) {
19042
19093
  const url = this.#url(path, query);
19043
- const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
19044
- return { status: response.status, payload: await this.#response(method, url, response) };
19094
+ return this.#noRoute(async () => {
19095
+ const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
19096
+ return { status: response.status, payload: await this.#response(method, url, response) };
19097
+ }, signal);
19098
+ }
19099
+ #noRoute(attempt, signal) {
19100
+ if (!this.#retryNoRoute)
19101
+ return attempt();
19102
+ return retryNoRoute(attempt, isNoRoute, {
19103
+ exhausted: () => new DispatchNoRouteError,
19104
+ signal: signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]),
19105
+ sleep: this.#sleep
19106
+ });
19045
19107
  }
19046
19108
  async#upload(path, input, key) {
19047
19109
  if (input.file === undefined) {
@@ -19058,11 +19120,13 @@ class DispatchClient {
19058
19120
  }
19059
19121
  async#form(method, path, form, key) {
19060
19122
  const url = this.#url(path);
19061
- const encoded = new Response(form);
19062
- const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
19063
- const content = new Uint8Array(await encoded.arrayBuffer());
19064
- const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
19065
- return this.#response(method, url, response);
19123
+ return this.#noRoute(async () => {
19124
+ const encoded = new Response(form);
19125
+ const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
19126
+ const content = new Uint8Array(await encoded.arrayBuffer());
19127
+ const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
19128
+ return this.#response(method, url, response);
19129
+ });
19066
19130
  }
19067
19131
  async#send(method, url, body, accept = "application/json", signal, callerKey) {
19068
19132
  const headers = { Accept: accept };
@@ -19357,7 +19421,11 @@ function sessionContext(input, checked) {
19357
19421
  configUrl,
19358
19422
  linkBase: input.config.publicUrl ?? configUrl,
19359
19423
  hostSession: input.sessionId?.trim(),
19360
- newClient: () => new DispatchClient(configUrl, credential, fetchImpl, input.signal, input.writeRetry)
19424
+ newClient: () => new DispatchClient(configUrl, credential, fetchImpl, {
19425
+ signal: input.signal,
19426
+ writeRetry: input.writeRetry,
19427
+ sleep: input.sleep
19428
+ })
19361
19429
  };
19362
19430
  }
19363
19431
 
@@ -25317,7 +25385,7 @@ function isSessionAnswerRelation(value) {
25317
25385
  return Object.hasOwn(RELATION_PHRASES, value);
25318
25386
  }
25319
25387
  function isNoAnswersRoute(error) {
25320
- return isNoRoute(error);
25388
+ return isNoRoute(error) || error instanceof DispatchNoRouteError;
25321
25389
  }
25322
25390
  function renderSessionAnswerItem(item) {
25323
25391
  const phrase = isSessionAnswerRelation(item.relation) ? RELATION_PHRASES[item.relation] : item.relation;
@@ -25518,7 +25586,9 @@ async function readSessionAnswers(options) {
25518
25586
  }
25519
25587
  let read = current.inFlight;
25520
25588
  if (read === undefined) {
25521
- const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch);
25589
+ const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch, {
25590
+ retryNoRoute: false
25591
+ });
25522
25592
  const started = client.sessionAnswers(session, {
25523
25593
  maxChars: SESSION_ANSWERS_MAX_CHARS,
25524
25594
  signal: AbortSignal.timeout(READ_TIMEOUT_MS)
@@ -37302,7 +37302,7 @@ var dispatchToolSpecs = [
37302
37302
  {
37303
37303
  name: "dispatch_read",
37304
37304
  example: { issue: "DSP-1" },
37305
- description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOCUMENT_UNLOADABLE` (the document " + "needs a rebuild) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
37305
+ description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOC_NEWER_CONTENT` (this Dispatch " + "build cannot read an element of the document; try again in one minute), `DOCUMENT_UNLOADABLE` (the " + "document's stored history cannot load; a person decides whether to rebuild it) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
37306
37306
  arguments: (z) => ({
37307
37307
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
37308
37308
  project: z.string().describe("Project key owning the document.").optional(),
@@ -38001,6 +38001,45 @@ var MessageAcceptedEventPayloadSchema = strictObject({
38001
38001
  accepted_as: literal("user_turn"),
38002
38002
  target: string2()
38003
38003
  }).readonly();
38004
+ // ../contracts/src/dispatch-api-requests.ts
38005
+ var NO_ROUTE_MESSAGE_PREFIX = "no route for ";
38006
+ var NO_ROUTE_RETRY_DELAYS_MS = [1000, 2000, 4000];
38007
+ var NO_ROUTE_ROLLING_RELEASE_MESSAGE = "The Dispatch process that answered does not offer this action yet, because a new release of " + "Dispatch is in progress. Try again in one minute.";
38008
+ var sleep = (ms, signal) => {
38009
+ const { promise, resolve, reject } = Promise.withResolvers();
38010
+ if (signal?.aborted) {
38011
+ reject(signal.reason);
38012
+ return promise;
38013
+ }
38014
+ const abort = () => {
38015
+ clearTimeout(timer);
38016
+ reject(signal?.reason);
38017
+ };
38018
+ const timer = setTimeout(() => {
38019
+ signal?.removeEventListener("abort", abort);
38020
+ resolve();
38021
+ }, ms);
38022
+ signal?.addEventListener("abort", abort, { once: true });
38023
+ return promise;
38024
+ };
38025
+ function jitteredDelay(ms) {
38026
+ return ms * (0.75 + Math.random() * 0.5);
38027
+ }
38028
+ async function retryNoRoute(attempt, isNoRoute, options) {
38029
+ const wait = options.sleep ?? sleep;
38030
+ for (const delay of [...NO_ROUTE_RETRY_DELAYS_MS, undefined]) {
38031
+ try {
38032
+ return await attempt();
38033
+ } catch (error) {
38034
+ if (!isNoRoute(error))
38035
+ throw error;
38036
+ if (delay === undefined)
38037
+ break;
38038
+ }
38039
+ await wait(jitteredDelay(delay), options.signal);
38040
+ }
38041
+ throw options.exhausted();
38042
+ }
38004
38043
  // ../contracts/src/dispatch-api-search.ts
38005
38044
  var SEARCH_MEMBERS_EVERY_BUILD_READS = [
38006
38045
  "q",
@@ -42992,7 +43031,13 @@ function isJson(response) {
42992
43031
  return response.headers.get("content-type")?.includes("application/json") ?? false;
42993
43032
  }
42994
43033
  function isNoRoute(error) {
42995
- return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith("no route for ");
43034
+ return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith(NO_ROUTE_MESSAGE_PREFIX);
43035
+ }
43036
+
43037
+ class DispatchNoRouteError extends DispatchServiceError {
43038
+ constructor() {
43039
+ super("NOT_FOUND", 404, NO_ROUTE_ROLLING_RELEASE_MESSAGE);
43040
+ }
42996
43041
  }
42997
43042
  var ISSUE_EVENTS_PAGE_MAX = 200;
42998
43043
  var DISPATCH_TOOL_DEADLINE_MS = 60000;
@@ -43210,18 +43255,22 @@ function excerpt(text, token) {
43210
43255
 
43211
43256
  class DispatchClient {
43212
43257
  fetchImpl;
43213
- writeRetry;
43214
43258
  #baseUrl;
43215
43259
  #resolvedIssues = new Map;
43216
43260
  #signal;
43217
43261
  #credential;
43262
+ #sleep;
43263
+ #retryNoRoute;
43264
+ writeRetry;
43218
43265
  #madeAt;
43219
- constructor(baseUrl, credential, fetchImpl = fetch, signal, writeRetry = DISPATCH_WRITE_RETRY) {
43266
+ constructor(baseUrl, credential, fetchImpl = fetch, options = {}) {
43220
43267
  this.fetchImpl = fetchImpl;
43221
- this.writeRetry = writeRetry;
43222
43268
  this.#credential = credential;
43223
43269
  this.#baseUrl = withoutTrailingSlashes(baseUrl);
43224
- this.#signal = requestSignal(signal);
43270
+ this.#signal = requestSignal(options.signal);
43271
+ this.writeRetry = options.writeRetry ?? DISPATCH_WRITE_RETRY;
43272
+ this.#sleep = options.sleep ?? sleep;
43273
+ this.#retryNoRoute = options.retryNoRoute ?? true;
43225
43274
  this.#madeAt = this.#now();
43226
43275
  }
43227
43276
  get token() {
@@ -43376,7 +43425,7 @@ class DispatchClient {
43376
43425
  try {
43377
43426
  return await this.#json("GET", ["api", "v1", "projects", project, "architecture-sources"]);
43378
43427
  } catch (error) {
43379
- if (!isNoRoute(error))
43428
+ if (!(error instanceof DispatchNoRouteError))
43380
43429
  throw error;
43381
43430
  }
43382
43431
  try {
@@ -43406,7 +43455,7 @@ class DispatchClient {
43406
43455
  "sync"
43407
43456
  ]);
43408
43457
  } catch (error) {
43409
- if (!isNoRoute(error))
43458
+ if (!(error instanceof DispatchNoRouteError))
43410
43459
  throw error;
43411
43460
  }
43412
43461
  const source = await this.#json("POST", [
@@ -43532,13 +43581,15 @@ class DispatchClient {
43532
43581
  }
43533
43582
  async fileVersion(id, version) {
43534
43583
  const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
43535
- const response = await this.#send("GET", url, undefined, "*/*");
43536
- if (!response.ok)
43537
- return this.#response("GET", url, response);
43538
- return {
43539
- mime: response.headers.get("Content-Type") ?? "application/octet-stream",
43540
- bytes: new Uint8Array(await response.arrayBuffer())
43541
- };
43584
+ return this.#noRoute(async () => {
43585
+ const response = await this.#send("GET", url, undefined, "*/*");
43586
+ if (!response.ok)
43587
+ return this.#response("GET", url, response);
43588
+ return {
43589
+ mime: response.headers.get("Content-Type") ?? "application/octet-stream",
43590
+ bytes: new Uint8Array(await response.arrayBuffer())
43591
+ };
43592
+ });
43542
43593
  }
43543
43594
  async artifactBlocks(id) {
43544
43595
  return this.#json("GET", ["api", "v1", "artifacts", id, "blocks"]);
@@ -43640,8 +43691,19 @@ class DispatchClient {
43640
43691
  }
43641
43692
  async#jsonAnswer(method, path, body, query, signal, key) {
43642
43693
  const url = this.#url(path, query);
43643
- const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
43644
- return { status: response.status, payload: await this.#response(method, url, response) };
43694
+ return this.#noRoute(async () => {
43695
+ const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
43696
+ return { status: response.status, payload: await this.#response(method, url, response) };
43697
+ }, signal);
43698
+ }
43699
+ #noRoute(attempt, signal) {
43700
+ if (!this.#retryNoRoute)
43701
+ return attempt();
43702
+ return retryNoRoute(attempt, isNoRoute, {
43703
+ exhausted: () => new DispatchNoRouteError,
43704
+ signal: signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]),
43705
+ sleep: this.#sleep
43706
+ });
43645
43707
  }
43646
43708
  async#upload(path, input, key) {
43647
43709
  if (input.file === undefined) {
@@ -43658,11 +43720,13 @@ class DispatchClient {
43658
43720
  }
43659
43721
  async#form(method, path, form, key) {
43660
43722
  const url = this.#url(path);
43661
- const encoded = new Response(form);
43662
- const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
43663
- const content = new Uint8Array(await encoded.arrayBuffer());
43664
- const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
43665
- return this.#response(method, url, response);
43723
+ return this.#noRoute(async () => {
43724
+ const encoded = new Response(form);
43725
+ const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
43726
+ const content = new Uint8Array(await encoded.arrayBuffer());
43727
+ const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
43728
+ return this.#response(method, url, response);
43729
+ });
43666
43730
  }
43667
43731
  async#send(method, url, body, accept = "application/json", signal, callerKey) {
43668
43732
  const headers = { Accept: accept };
@@ -47748,7 +47812,11 @@ function sessionContext(input, checked) {
47748
47812
  configUrl,
47749
47813
  linkBase: input.config.publicUrl ?? configUrl,
47750
47814
  hostSession: input.sessionId?.trim(),
47751
- newClient: () => new DispatchClient(configUrl, credential, fetchImpl, input.signal, input.writeRetry)
47815
+ newClient: () => new DispatchClient(configUrl, credential, fetchImpl, {
47816
+ signal: input.signal,
47817
+ writeRetry: input.writeRetry,
47818
+ sleep: input.sleep
47819
+ })
47752
47820
  };
47753
47821
  }
47754
47822
 
@@ -51622,7 +51690,7 @@ function isSessionAnswerRelation(value) {
51622
51690
  return Object.hasOwn(RELATION_PHRASES, value);
51623
51691
  }
51624
51692
  function isNoAnswersRoute(error) {
51625
- return isNoRoute(error);
51693
+ return isNoRoute(error) || error instanceof DispatchNoRouteError;
51626
51694
  }
51627
51695
  function renderSessionAnswerItem(item) {
51628
51696
  const phrase = isSessionAnswerRelation(item.relation) ? RELATION_PHRASES[item.relation] : item.relation;
@@ -51823,7 +51891,9 @@ async function readSessionAnswers(options) {
51823
51891
  }
51824
51892
  let read = current.inFlight;
51825
51893
  if (read === undefined) {
51826
- const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch);
51894
+ const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch, {
51895
+ retryNoRoute: false
51896
+ });
51827
51897
  const started = client.sessionAnswers(session, {
51828
51898
  maxChars: SESSION_ANSWERS_MAX_CHARS,
51829
51899
  signal: AbortSignal.timeout(READ_TIMEOUT_MS)
@@ -56426,7 +56496,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
56426
56496
 
56427
56497
  // package.json
56428
56498
  var name = "@sjawhar/claude-envoy";
56429
- var version2 = "2.22.0";
56499
+ var version2 = "2.23.0";
56430
56500
  var legion = {
56431
56501
  daemonApiVersion: 133
56432
56502
  };
@@ -61287,7 +61357,9 @@ async function runEnvoyChannelServer() {
61287
61357
  const options = {
61288
61358
  dispatch: (ms) => {
61289
61359
  const active = activeDispatchSettings(sessionDispatchSettings(configFile, process.env, { cwd: directory }).dispatch);
61290
- return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, AbortSignal.timeout(ms));
61360
+ return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
61361
+ signal: AbortSignal.timeout(ms)
61362
+ });
61291
61363
  },
61292
61364
  effortPicked: (effort) => agentStream?.pickedEffort(effort),
61293
61365
  refreshSettings: () => agentStream?.refresh(),
@@ -14649,7 +14649,7 @@ var dispatchToolSpecs = [
14649
14649
  {
14650
14650
  name: "dispatch_read",
14651
14651
  example: { issue: "DSP-1" },
14652
- description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOCUMENT_UNLOADABLE` (the document " + "needs a rebuild) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
14652
+ description: "Read an issue or document summary, targeted ask, or targeted comment reply chain, or the conversation " + "a message belongs to. Do not use it for document contents; use dispatch doc-read instead. Supply ref, issue, " + "issue plus artifact (one of its documents), project plus artifact, or project alone, which lists the project's documents on no issue and nothing more; or message alone, which reads a human's direct message to this session and every " + "reply to it (they belong to no issue). A document summary names its issue, reference, versions and approval. " + "An issue read lists every document, picture and file the issue holds under `Documents:`, each by slug, filename and kind. " + "An anchored comment or ask also says where its quote sits, as `Position:`: the block's path from the top, " + "and in a table the row (0 is the header), the cells before the anchored one, and the column's header; " + "`Position: unavailable (<code>)` when Dispatch could not read the document: `DOC_SERVICE_UNAVAILABLE` " + "(try again shortly), `DOC_SCHEMA` (the document needs repair), `DOC_NEWER_CONTENT` (this Dispatch " + "build cannot read an element of the document; try again in one minute), `DOCUMENT_UNLOADABLE` (the " + "document's stored history cannot load; a person decides whether to rebuild it) or `INTERNAL`. " + "An issue read carries a `Progress:` line, `tasks 3/7, children 2/5`: its spec's task-list items " + "(`- [ ]` / `- [x]`, nested lists included) and its direct children, each done of total and each only " + "when it has any (`Progress: none` otherwise). " + "An issue whose spec marks requirements carries one `Coverage:` line per gap, `Coverage: R3 has no check` or " + "`Coverage: R3 has no plan task` (the second only once the issue has a plan document), counting the `check` and " + "`plan_task` blocks of every document of the issue and of its descendants; a spec that marks none reads " + "`Coverage: the spec marks no requirements`. Nothing is refused for a gap. " + `An issue read, and its dispatch://KEY/log, lists the issue's last ${DEFAULT_ISSUE_READ_EVENTS} events, oldest first; ` + "--events N lists the last N, and --all-events every one. " + "A comment reply chain names the comment each nested reply answers as `Answers: <comment id>`. " + "Every read ends with `Referenced by:` (what cites or hangs off this node, each with its dispatch:// address, " + "an excerpt, and when) and `Links:` (what it cites), so tracing provenance is one call. " + "A block read prints `Block:`, `Type:` for a block of a document, `Document:`, every attribute a typed block carries " + "(a `check`'s serves, surface, run, when, negative_control and ci_check; a `plan_task`'s serves and needs), `Changed in version:` " + "and `Text:`, then those two sections; a pinned one adds " + "the block's text at that version and whether it is unchanged, changed or removed since, and an absent block, unpinned, " + "reads `No block <id> in <document>.` " + "The pictures the shown messages, asks and comments embed come back as images you see, newest first, at most 8 " + "and 10 MiB of them per read, each a PNG, JPEG, GIF or WebP of at most 3,750,000 bytes (5 MB of base64); a `Pictures:` section names each " + "one shown, in order, and the rest by reference, for dispatch doc-read. A picture this session was already shown is named, not sent again " + "(every request carries the session's history, and the provider refuses one over 32 MB); dispatch doc-read shows it again. " + OWNER_REFERENCE,
14653
14653
  arguments: (z) => ({
14654
14654
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
14655
14655
  project: z.string().describe("Project key owning the document.").optional(),
@@ -15348,6 +15348,45 @@ var MessageAcceptedEventPayloadSchema = strictObject({
15348
15348
  accepted_as: literal("user_turn"),
15349
15349
  target: string2()
15350
15350
  }).readonly();
15351
+ // ../contracts/src/dispatch-api-requests.ts
15352
+ var NO_ROUTE_MESSAGE_PREFIX = "no route for ";
15353
+ var NO_ROUTE_RETRY_DELAYS_MS = [1000, 2000, 4000];
15354
+ var NO_ROUTE_ROLLING_RELEASE_MESSAGE = "The Dispatch process that answered does not offer this action yet, because a new release of " + "Dispatch is in progress. Try again in one minute.";
15355
+ var sleep = (ms, signal) => {
15356
+ const { promise, resolve, reject } = Promise.withResolvers();
15357
+ if (signal?.aborted) {
15358
+ reject(signal.reason);
15359
+ return promise;
15360
+ }
15361
+ const abort = () => {
15362
+ clearTimeout(timer);
15363
+ reject(signal?.reason);
15364
+ };
15365
+ const timer = setTimeout(() => {
15366
+ signal?.removeEventListener("abort", abort);
15367
+ resolve();
15368
+ }, ms);
15369
+ signal?.addEventListener("abort", abort, { once: true });
15370
+ return promise;
15371
+ };
15372
+ function jitteredDelay(ms) {
15373
+ return ms * (0.75 + Math.random() * 0.5);
15374
+ }
15375
+ async function retryNoRoute(attempt, isNoRoute, options) {
15376
+ const wait = options.sleep ?? sleep;
15377
+ for (const delay of [...NO_ROUTE_RETRY_DELAYS_MS, undefined]) {
15378
+ try {
15379
+ return await attempt();
15380
+ } catch (error) {
15381
+ if (!isNoRoute(error))
15382
+ throw error;
15383
+ if (delay === undefined)
15384
+ break;
15385
+ }
15386
+ await wait(jitteredDelay(delay), options.signal);
15387
+ }
15388
+ throw options.exhausted();
15389
+ }
15351
15390
  // ../contracts/src/dispatch-api-search.ts
15352
15391
  var SEARCH_MEMBERS_EVERY_BUILD_READS = [
15353
15392
  "q",
@@ -18151,7 +18190,13 @@ function isJson(response) {
18151
18190
  return response.headers.get("content-type")?.includes("application/json") ?? false;
18152
18191
  }
18153
18192
  function isNoRoute(error) {
18154
- return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith("no route for ");
18193
+ return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith(NO_ROUTE_MESSAGE_PREFIX);
18194
+ }
18195
+
18196
+ class DispatchNoRouteError extends DispatchServiceError {
18197
+ constructor() {
18198
+ super("NOT_FOUND", 404, NO_ROUTE_ROLLING_RELEASE_MESSAGE);
18199
+ }
18155
18200
  }
18156
18201
  var ISSUE_EVENTS_PAGE_MAX = 200;
18157
18202
  var DISPATCH_TOOL_DEADLINE_MS = 60000;
@@ -18369,18 +18414,22 @@ function excerpt(text, token) {
18369
18414
 
18370
18415
  class DispatchClient {
18371
18416
  fetchImpl;
18372
- writeRetry;
18373
18417
  #baseUrl;
18374
18418
  #resolvedIssues = new Map;
18375
18419
  #signal;
18376
18420
  #credential;
18421
+ #sleep;
18422
+ #retryNoRoute;
18423
+ writeRetry;
18377
18424
  #madeAt;
18378
- constructor(baseUrl, credential, fetchImpl = fetch, signal, writeRetry = DISPATCH_WRITE_RETRY) {
18425
+ constructor(baseUrl, credential, fetchImpl = fetch, options = {}) {
18379
18426
  this.fetchImpl = fetchImpl;
18380
- this.writeRetry = writeRetry;
18381
18427
  this.#credential = credential;
18382
18428
  this.#baseUrl = withoutTrailingSlashes(baseUrl);
18383
- this.#signal = requestSignal(signal);
18429
+ this.#signal = requestSignal(options.signal);
18430
+ this.writeRetry = options.writeRetry ?? DISPATCH_WRITE_RETRY;
18431
+ this.#sleep = options.sleep ?? sleep;
18432
+ this.#retryNoRoute = options.retryNoRoute ?? true;
18384
18433
  this.#madeAt = this.#now();
18385
18434
  }
18386
18435
  get token() {
@@ -18535,7 +18584,7 @@ class DispatchClient {
18535
18584
  try {
18536
18585
  return await this.#json("GET", ["api", "v1", "projects", project, "architecture-sources"]);
18537
18586
  } catch (error) {
18538
- if (!isNoRoute(error))
18587
+ if (!(error instanceof DispatchNoRouteError))
18539
18588
  throw error;
18540
18589
  }
18541
18590
  try {
@@ -18565,7 +18614,7 @@ class DispatchClient {
18565
18614
  "sync"
18566
18615
  ]);
18567
18616
  } catch (error) {
18568
- if (!isNoRoute(error))
18617
+ if (!(error instanceof DispatchNoRouteError))
18569
18618
  throw error;
18570
18619
  }
18571
18620
  const source = await this.#json("POST", [
@@ -18691,13 +18740,15 @@ class DispatchClient {
18691
18740
  }
18692
18741
  async fileVersion(id, version) {
18693
18742
  const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
18694
- const response = await this.#send("GET", url, undefined, "*/*");
18695
- if (!response.ok)
18696
- return this.#response("GET", url, response);
18697
- return {
18698
- mime: response.headers.get("Content-Type") ?? "application/octet-stream",
18699
- bytes: new Uint8Array(await response.arrayBuffer())
18700
- };
18743
+ return this.#noRoute(async () => {
18744
+ const response = await this.#send("GET", url, undefined, "*/*");
18745
+ if (!response.ok)
18746
+ return this.#response("GET", url, response);
18747
+ return {
18748
+ mime: response.headers.get("Content-Type") ?? "application/octet-stream",
18749
+ bytes: new Uint8Array(await response.arrayBuffer())
18750
+ };
18751
+ });
18701
18752
  }
18702
18753
  async artifactBlocks(id) {
18703
18754
  return this.#json("GET", ["api", "v1", "artifacts", id, "blocks"]);
@@ -18799,8 +18850,19 @@ class DispatchClient {
18799
18850
  }
18800
18851
  async#jsonAnswer(method, path, body, query, signal, key) {
18801
18852
  const url = this.#url(path, query);
18802
- const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
18803
- return { status: response.status, payload: await this.#response(method, url, response) };
18853
+ return this.#noRoute(async () => {
18854
+ const response = await this.#send(method, url, body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" }, undefined, signal, key);
18855
+ return { status: response.status, payload: await this.#response(method, url, response) };
18856
+ }, signal);
18857
+ }
18858
+ #noRoute(attempt, signal) {
18859
+ if (!this.#retryNoRoute)
18860
+ return attempt();
18861
+ return retryNoRoute(attempt, isNoRoute, {
18862
+ exhausted: () => new DispatchNoRouteError,
18863
+ signal: signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]),
18864
+ sleep: this.#sleep
18865
+ });
18804
18866
  }
18805
18867
  async#upload(path, input, key) {
18806
18868
  if (input.file === undefined) {
@@ -18817,11 +18879,13 @@ class DispatchClient {
18817
18879
  }
18818
18880
  async#form(method, path, form, key) {
18819
18881
  const url = this.#url(path);
18820
- const encoded = new Response(form);
18821
- const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
18822
- const content = new Uint8Array(await encoded.arrayBuffer());
18823
- const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
18824
- return this.#response(method, url, response);
18882
+ return this.#noRoute(async () => {
18883
+ const encoded = new Response(form);
18884
+ const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
18885
+ const content = new Uint8Array(await encoded.arrayBuffer());
18886
+ const response = await this.#send(method, url, { content, type }, undefined, undefined, key);
18887
+ return this.#response(method, url, response);
18888
+ });
18825
18889
  }
18826
18890
  async#send(method, url, body, accept = "application/json", signal, callerKey) {
18827
18891
  const headers = { Accept: accept };
@@ -20350,7 +20414,11 @@ function sessionContext(input, checked) {
20350
20414
  configUrl,
20351
20415
  linkBase: input.config.publicUrl ?? configUrl,
20352
20416
  hostSession: input.sessionId?.trim(),
20353
- newClient: () => new DispatchClient(configUrl, credential, fetchImpl, input.signal, input.writeRetry)
20417
+ newClient: () => new DispatchClient(configUrl, credential, fetchImpl, {
20418
+ signal: input.signal,
20419
+ writeRetry: input.writeRetry,
20420
+ sleep: input.sleep
20421
+ })
20354
20422
  };
20355
20423
  }
20356
20424
 
@@ -24321,7 +24389,7 @@ function isSessionAnswerRelation(value) {
24321
24389
  return Object.hasOwn(RELATION_PHRASES, value);
24322
24390
  }
24323
24391
  function isNoAnswersRoute(error) {
24324
- return isNoRoute(error);
24392
+ return isNoRoute(error) || error instanceof DispatchNoRouteError;
24325
24393
  }
24326
24394
  function renderSessionAnswerItem(item) {
24327
24395
  const phrase = isSessionAnswerRelation(item.relation) ? RELATION_PHRASES[item.relation] : item.relation;
@@ -24522,7 +24590,9 @@ async function readSessionAnswers(options) {
24522
24590
  }
24523
24591
  let read = current.inFlight;
24524
24592
  if (read === undefined) {
24525
- const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch);
24593
+ const client = new DispatchClient(url, dispatch.credential, options.fetchImpl ?? fetch, {
24594
+ retryNoRoute: false
24595
+ });
24526
24596
  const started = client.sessionAnswers(session, {
24527
24597
  maxChars: SESSION_ANSWERS_MAX_CHARS,
24528
24598
  signal: AbortSignal.timeout(READ_TIMEOUT_MS)
@@ -28603,7 +28673,9 @@ async function openAsks(raw) {
28603
28673
  `);
28604
28674
  if (dispatch.enabled) {
28605
28675
  try {
28606
- const snapshot = await new DispatchClient(dispatch.url, dispatch.credential, fetch, AbortSignal.timeout(OPEN_ASKS_TIMEOUT_MS)).openAsks(input.session_id);
28676
+ const snapshot = await new DispatchClient(dispatch.url, dispatch.credential, fetch, {
28677
+ signal: AbortSignal.timeout(OPEN_ASKS_TIMEOUT_MS)
28678
+ }).openAsks(input.session_id);
28607
28679
  process.stdout.write(`Dispatch authored-ask summary:
28608
28680
  ${formatOpenAsksSummary(snapshot, dispatch.publicUrl ?? dispatch.url)}
28609
28681
  `);
@@ -307,12 +307,9 @@ async function openAsks(raw: unknown): Promise<void> {
307
307
  for (const warning of warnings) process.stdout.write(`envoy: ${warning}\n`)
308
308
  if (dispatch.enabled) {
309
309
  try {
310
- const snapshot = await new DispatchClient(
311
- dispatch.url,
312
- dispatch.credential,
313
- fetch,
314
- AbortSignal.timeout(OPEN_ASKS_TIMEOUT_MS),
315
- ).openAsks(input.session_id)
310
+ const snapshot = await new DispatchClient(dispatch.url, dispatch.credential, fetch, {
311
+ signal: AbortSignal.timeout(OPEN_ASKS_TIMEOUT_MS),
312
+ }).openAsks(input.session_id)
316
313
  process.stdout.write(
317
314
  `Dispatch authored-ask summary:\n${formatOpenAsksSummary(snapshot, dispatch.publicUrl ?? dispatch.url)}\n`,
318
315
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -2261,7 +2261,9 @@ export async function runEnvoyChannelServer(): Promise<void> {
2261
2261
  )
2262
2262
  return active === null
2263
2263
  ? undefined
2264
- : new DispatchClient(active.url, active.credential, fetch, AbortSignal.timeout(ms))
2264
+ : new DispatchClient(active.url, active.credential, fetch, {
2265
+ signal: AbortSignal.timeout(ms),
2266
+ })
2265
2267
  },
2266
2268
  effortPicked: (effort) => agentStream?.pickedEffort(effort),
2267
2269
  refreshSettings: () => agentStream?.refresh(),