@sjawhar/claude-envoy 5.27.1 → 5.28.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 CHANGED
@@ -1208,17 +1208,19 @@ function errorClass(error) {
1208
1208
  }
1209
1209
 
1210
1210
  // ../envoy-client/src/errors.ts
1211
- function dispatchCode(error) {
1212
- if (!("fromDispatch" in error) || !("code" in error))
1211
+ function dispatchField(error, field) {
1212
+ if (!("fromDispatch" in error))
1213
1213
  return;
1214
- const code = error.code;
1215
- return typeof code === "string" && code !== "" ? code : undefined;
1214
+ const value = Reflect.get(error, field);
1215
+ return typeof value === "string" && value !== "" ? value : undefined;
1216
1216
  }
1217
1217
  function messageFor(error) {
1218
1218
  if (!(error instanceof Error))
1219
1219
  return scrub(String(error));
1220
- const code = dispatchCode(error);
1221
- return scrub(code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`);
1220
+ const code = dispatchField(error, "code");
1221
+ const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
1222
+ const hint = dispatchField(error, "hint");
1223
+ return scrub(hint === undefined ? message : `${message}; ${hint}`);
1222
1224
  }
1223
1225
  function hasErrnoCode(error, code) {
1224
1226
  return error instanceof Error && "code" in error && error.code === code;
@@ -14254,6 +14256,7 @@ var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
14254
14256
  function uncapturedTopicRefusal(topic, sessionID) {
14255
14257
  return `${topic} was not registered: no stream subject captures it, so nothing would be delivered to ${sessionID} on it; follow a notifications.team.<name> topic instead`;
14256
14258
  }
14259
+ var MESSAGE_NOT_SENT_PREFIX = "envoy: the message was not sent, and may be sent again later";
14257
14260
 
14258
14261
  // ../contracts/src/legion-roles.ts
14259
14262
  var LEGION_ROLES = [
@@ -15088,6 +15091,25 @@ var projectKeyValidation = {
15088
15091
  message: `project is not a project key: ${PROJECT_KEY_RULE}`
15089
15092
  };
15090
15093
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
15094
+ var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
15095
+ var API_PATH_RULE = "path is a route under /api/v1: it begins /api/v1 and names no scheme or host, every character is printable ASCII other than a space, a backslash and #, and no segment before the query is . or ..";
15096
+ function apiPathProblem(value) {
15097
+ const { path } = value;
15098
+ if (typeof path !== "string")
15099
+ return;
15100
+ const named = JSON.stringify(path);
15101
+ if (!API_ROUTE_PATTERN.test(path)) {
15102
+ return `path ${named} is no route under /api/v1: give the route alone, beginning /api/v1, with no scheme or host (dispatch api --path /api/v1 lists every route).`;
15103
+ }
15104
+ if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
15105
+ return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
15106
+ }
15107
+ const route = path.split("?", 1)[0] ?? "";
15108
+ if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
15109
+ return `path ${named} holds a . or .. segment: name the route itself.`;
15110
+ }
15111
+ return;
15112
+ }
15091
15113
  var ISSUE_STATUSES = [
15092
15114
  "triage",
15093
15115
  "icebox",
@@ -15693,6 +15715,20 @@ var dispatchToolSpecs = [
15693
15715
  arguments: () => ({}),
15694
15716
  strict: true
15695
15717
  },
15718
+ {
15719
+ name: "dispatch_api",
15720
+ example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
15721
+ description: "Read one route of Dispatch's HTTP API that no other command reads, with this session's own credential, and print Dispatch's JSON answer, for jq to read. It sends one GET of path: a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. It only reads: it takes no method and no body, and every write goes through the command named for it (dispatch --help lists them). When Dispatch refuses the read, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint, and exits 1. Under Claude Code, an answer longer than the output limit is written to a file the output names.",
15722
+ arguments: (z) => ({
15723
+ path: z.string({ min: 1 }).describe("The route to read, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, and no . or .. segment.")
15724
+ }),
15725
+ validation: {
15726
+ check: (value) => apiPathProblem(value) === undefined,
15727
+ message: API_PATH_RULE,
15728
+ refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
15729
+ },
15730
+ strict: true
15731
+ },
15696
15732
  {
15697
15733
  name: "dispatch_handoff_write",
15698
15734
  example: {
@@ -20435,6 +20471,7 @@ class DispatchServiceError extends Error {
20435
20471
  mismatches;
20436
20472
  issues;
20437
20473
  changed;
20474
+ hint;
20438
20475
  constructor(code, status, message, details = {}) {
20439
20476
  super(message);
20440
20477
  this.code = code;
@@ -20444,6 +20481,7 @@ class DispatchServiceError extends Error {
20444
20481
  this.mismatches = details.mismatches;
20445
20482
  this.issues = details.issues;
20446
20483
  this.changed = details.changed;
20484
+ this.hint = details.hint;
20447
20485
  }
20448
20486
  }
20449
20487
 
@@ -20933,6 +20971,10 @@ class DispatchClient {
20933
20971
  async limits() {
20934
20972
  return this.#json("GET", ["api", "v1", "limits"]);
20935
20973
  }
20974
+ async readRoute(path) {
20975
+ const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
20976
+ return this.#response("GET", url, await this.#send("GET", url));
20977
+ }
20936
20978
  async inbox(assignee) {
20937
20979
  return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
20938
20980
  }
@@ -21621,7 +21663,7 @@ class DispatchClient {
21621
21663
  if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
21622
21664
  throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
21623
21665
  }
21624
- throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
21666
+ throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
21625
21667
  }
21626
21668
  throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
21627
21669
  }
@@ -25921,6 +25963,7 @@ var issueFreeTools = {
25921
25963
  dispatch_answers: true,
25922
25964
  dispatch_whoami: true,
25923
25965
  dispatch_limits: true,
25966
+ dispatch_api: true,
25924
25967
  dispatch_inbox: true,
25925
25968
  dispatch_send_to_agent: true,
25926
25969
  dispatch_architecture_sync: true
@@ -31251,6 +31294,10 @@ async function refreshDeviceLogin(path, login, options) {
31251
31294
  return next;
31252
31295
  }
31253
31296
 
31297
+ // ../cipher-client/src/environment.ts
31298
+ import { readFile as readFile6 } from "fs/promises";
31299
+ import { join as join6 } from "path";
31300
+
31254
31301
  // ../cipher-client/src/metadata-identity.ts
31255
31302
  import { Agent, request } from "http";
31256
31303
  var METADATA_HOST_VAR = "GCE_METADATA_HOST";
@@ -31560,6 +31607,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
31560
31607
  var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
31561
31608
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
31562
31609
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
31610
+ var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
31611
+ var ROLE_KEY_FILE = "key.pem";
31563
31612
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
31564
31613
  var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
31565
31614
  var MAX_PROJECTS = 16;
@@ -31573,6 +31622,7 @@ var BROKER_VARIABLES = [
31573
31622
  BROKER_URL_VAR,
31574
31623
  IDENTITY_VAR,
31575
31624
  MACHINE_TOKEN_FILE_VAR,
31625
+ KEY_DIR_VAR,
31576
31626
  MACHINE_AUDIENCE_VAR,
31577
31627
  SESSION_VAR,
31578
31628
  PROJECTS_VAR,
@@ -31648,6 +31698,21 @@ function tradeProjects(env) {
31648
31698
  }
31649
31699
  return sorted;
31650
31700
  }
31701
+ async function machineKey(env) {
31702
+ const dir = value(env, KEY_DIR_VAR);
31703
+ if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
31704
+ return await newDpopKey();
31705
+ const path = join6(dir, ROLE_KEY_FILE);
31706
+ let pem;
31707
+ try {
31708
+ pem = await readFile6(path, "utf8");
31709
+ } catch (error) {
31710
+ throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
31711
+ cause: error
31712
+ });
31713
+ }
31714
+ return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
31715
+ }
31651
31716
  async function brokerTokenClient(env, own = "", read) {
31652
31717
  const brokerUrl = value(env, BROKER_URL_VAR);
31653
31718
  const machine = machineIdentity(env);
@@ -31675,7 +31740,7 @@ async function brokerTokenClient(env, own = "", read) {
31675
31740
  if (record === undefined) {
31676
31741
  const client = new BrokerTokenClient({
31677
31742
  brokerUrl,
31678
- key: await newDpopKey(),
31743
+ key: await machineKey(env),
31679
31744
  subject: machine,
31680
31745
  session: tradeSession(env, own),
31681
31746
  launcherCredential: false,
@@ -32342,6 +32407,16 @@ async function commandContext(session) {
32342
32407
  };
32343
32408
  }
32344
32409
 
32410
+ // ../envoy-client/src/dispatch-commands/api.ts
32411
+ async function apiCommand(context) {
32412
+ const path = stringArg(context.args, "path");
32413
+ const answer = await context.newClient().readRoute(path);
32414
+ return {
32415
+ text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
32416
+ details: { path }
32417
+ };
32418
+ }
32419
+
32345
32420
  // ../envoy-client/src/dispatch-commands/render-item.ts
32346
32421
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
32347
32422
  const answer = ask.answer;
@@ -34419,26 +34494,26 @@ async function reviewCommand(context) {
34419
34494
 
34420
34495
  // ../envoy-client/src/session-answers.ts
34421
34496
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
34422
- import { join as join7 } from "path";
34497
+ import { join as join8 } from "path";
34423
34498
 
34424
34499
  // ../envoy-client/src/dispatch-session-directory.ts
34425
34500
  import { randomUUID as randomUUID5 } from "crypto";
34426
34501
  import { renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
34427
34502
  import { homedir as homedir2 } from "os";
34428
- import { join as join6 } from "path";
34503
+ import { join as join7 } from "path";
34429
34504
  var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
34430
34505
  var PRIVATE_FILE = 384;
34431
34506
  function sessionStateRoot(env) {
34432
34507
  const stateDir = env["DISPATCH_STATE_DIR"];
34433
34508
  if (stateDir)
34434
34509
  return stateDir;
34435
- return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
34510
+ return join7(env["XDG_STATE_HOME"] || join7(homedir2(), ".local", "state"), "dispatch");
34436
34511
  }
34437
34512
  function sessionDirectory(env, sessionId) {
34438
34513
  if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
34439
34514
  throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
34440
34515
  }
34441
- return join6(sessionStateRoot(env), "sessions", sessionId);
34516
+ return join7(sessionStateRoot(env), "sessions", sessionId);
34442
34517
  }
34443
34518
  function writeAtomically(path, text) {
34444
34519
  const temporary = `${path}.${process.pid}.${randomUUID5()}.tmp`;
@@ -34589,7 +34664,7 @@ processGlobal2[STATE_KEY] = state;
34589
34664
  var CACHE_FILE = "answers.json";
34590
34665
  function readCacheFile(directory, url) {
34591
34666
  try {
34592
- const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
34667
+ const value = JSON.parse(readFileSync3(join8(directory, CACHE_FILE), "utf-8"));
34593
34668
  if (typeof value === "object" && value !== null && "dispatch_url" in value && typeof value.dispatch_url === "string" && value.dispatch_url === url && "read_at" in value && typeof value.read_at === "string" && "total" in value && typeof value.total === "number" && "items" in value && Array.isArray(value.items)) {
34594
34669
  return {
34595
34670
  dispatch_url: value.dispatch_url,
@@ -34710,7 +34785,7 @@ async function readSessionAnswers(options) {
34710
34785
  if (directory !== undefined) {
34711
34786
  try {
34712
34787
  mkdirSync2(directory, { recursive: true, mode: 448 });
34713
- writeAtomically(join7(directory, CACHE_FILE), JSON.stringify(cache));
34788
+ writeAtomically(join8(directory, CACHE_FILE), JSON.stringify(cache));
34714
34789
  } catch {}
34715
34790
  }
34716
34791
  return { cache };
@@ -35061,6 +35136,7 @@ var dispatchCommands = {
35061
35136
  dispatch_answers: onSession(answersCommand),
35062
35137
  dispatch_whoami: onSession(whoamiCommand),
35063
35138
  dispatch_limits: onSession(limitsCommand),
35139
+ dispatch_api: onSession(apiCommand),
35064
35140
  dispatch_inbox: onSession(inboxCommand)
35065
35141
  };
35066
35142
  // ../envoy-client/src/dispatch-execute.ts
@@ -35096,7 +35172,7 @@ import {
35096
35172
  statSync as statSync2,
35097
35173
  writeFileSync as writeFileSync3
35098
35174
  } from "fs";
35099
- import { join as join8 } from "path";
35175
+ import { join as join9 } from "path";
35100
35176
  var PRIVATE_DIR = 448;
35101
35177
  var PRIVATE_FILE2 = 384;
35102
35178
  var IDLE_SESSION_MS = 14 * 86400000;
@@ -35124,7 +35200,7 @@ function stringList(value) {
35124
35200
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
35125
35201
  }
35126
35202
  function loadSessionMemory(dir, sessionId) {
35127
- const path = join8(dir, "state.json");
35203
+ const path = join9(dir, "state.json");
35128
35204
  const text = readIfPresent(path);
35129
35205
  if (text === undefined)
35130
35206
  return new Set;
@@ -35148,7 +35224,7 @@ function writeMemory(dir, sessionId, follows) {
35148
35224
  pictures: [...shownPictures(sessionId)],
35149
35225
  follows: [...follows]
35150
35226
  };
35151
- writeAtomically(join8(dir, "state.json"), `${JSON.stringify(state)}
35227
+ writeAtomically(join9(dir, "state.json"), `${JSON.stringify(state)}
35152
35228
  `);
35153
35229
  }
35154
35230
  function appendResult(dir, entry) {
@@ -35157,7 +35233,7 @@ function appendResult(dir, entry) {
35157
35233
  }
35158
35234
  function writeResult(dir, entry) {
35159
35235
  const line = { at: new Date().toISOString(), ...entry };
35160
- appendFileSync2(join8(dir, "results.jsonl"), `${JSON.stringify(line)}
35236
+ appendFileSync2(join9(dir, "results.jsonl"), `${JSON.stringify(line)}
35161
35237
  `, { mode: PRIVATE_FILE2 });
35162
35238
  }
35163
35239
  function recordOutcome(dir, sessionId, follows, entry) {
@@ -35168,8 +35244,8 @@ function recordOutcome(dir, sessionId, follows, entry) {
35168
35244
  function writePicture(dir, image) {
35169
35245
  const bytes = Buffer.from(image.data, "base64");
35170
35246
  const name = createHash3("sha256").update(bytes).digest("hex").slice(0, 16);
35171
- const pictures = join8(dir, "pictures");
35172
- const path = join8(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
35247
+ const pictures = join9(dir, "pictures");
35248
+ const path = join9(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
35173
35249
  ensureDirectory(pictures);
35174
35250
  try {
35175
35251
  writeFileSync3(path, bytes, { mode: PRIVATE_FILE2, flag: "wx" });
@@ -35180,21 +35256,21 @@ function writePicture(dir, image) {
35180
35256
  return { path, bytes: bytes.length };
35181
35257
  }
35182
35258
  function writeLongOutput(dir, text) {
35183
- const out = join8(dir, "out");
35259
+ const out = join9(dir, "out");
35184
35260
  ensureDirectory(out);
35185
- const path = join8(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
35261
+ const path = join9(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
35186
35262
  writeFileSync3(path, text, { mode: PRIVATE_FILE2 });
35187
35263
  return path;
35188
35264
  }
35189
35265
  function writeSessionTitle(dir, title) {
35190
35266
  ensureDirectory(dir);
35191
- writeAtomically(join8(dir, "title"), title);
35267
+ writeAtomically(join9(dir, "title"), title);
35192
35268
  }
35193
35269
  function readSessionTitle(dir) {
35194
- return readIfPresent(join8(dir, "title")) || undefined;
35270
+ return readIfPresent(join9(dir, "title")) || undefined;
35195
35271
  }
35196
35272
  function pruneSessions(root, now) {
35197
- const stamp = join8(root, PRUNED_STAMP);
35273
+ const stamp = join9(root, PRUNED_STAMP);
35198
35274
  try {
35199
35275
  if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
35200
35276
  return;
@@ -35202,7 +35278,7 @@ function pruneSessions(root, now) {
35202
35278
  if (!hasErrnoCode(error, "ENOENT"))
35203
35279
  throw error;
35204
35280
  }
35205
- const sessions = join8(root, "sessions");
35281
+ const sessions = join9(root, "sessions");
35206
35282
  let entries = [];
35207
35283
  try {
35208
35284
  entries = readdirSync2(sessions, { withFileTypes: true });
@@ -35213,7 +35289,7 @@ function pruneSessions(root, now) {
35213
35289
  for (const entry of entries) {
35214
35290
  if (!entry.isDirectory())
35215
35291
  continue;
35216
- const dir = join8(sessions, entry.name);
35292
+ const dir = join9(sessions, entry.name);
35217
35293
  try {
35218
35294
  const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
35219
35295
  if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
@@ -36260,6 +36336,7 @@ class EnvoyApiError extends Error {
36260
36336
  claimReleased;
36261
36337
  retryAfterSeconds;
36262
36338
  refused;
36339
+ notSent;
36263
36340
  constructor(details, shown = {}) {
36264
36341
  let parsed;
36265
36342
  try {
@@ -36268,7 +36345,9 @@ class EnvoyApiError extends Error {
36268
36345
  parsed = result.data;
36269
36346
  } catch {}
36270
36347
  const redirected = shown.redirectTo === undefined ? "" : ` (a redirect to ${shown.redirectTo}, which this client does not follow)`;
36271
- super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}${redirected}: ${bodyForText(details.responseBody, shown.tokens ?? "", "the listener's error JSON")}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
36348
+ const notSentAnswer = details.status === 503 && parsed?.error.startsWith(`${MESSAGE_NOT_SENT_PREFIX}: `) === true;
36349
+ const earlier = notSentAnswer && shown.afterUnanswered === true ? " An earlier attempt got no answer or a 5xx, so that attempt may have stored the message." : "";
36350
+ super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}${redirected}: ${bodyForText(details.responseBody, shown.tokens ?? "", "the listener's error JSON")}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}${earlier}`);
36272
36351
  this.details = details;
36273
36352
  this.expected = parsed?.expected;
36274
36353
  this.code = parsed?.code;
@@ -36279,6 +36358,7 @@ class EnvoyApiError extends Error {
36279
36358
  this.claimReleased = parsed?.claim_released;
36280
36359
  this.retryAfterSeconds = parsed?.retry_after_seconds;
36281
36360
  this.refused = parsed?.refused;
36361
+ this.notSent = notSentAnswer && shown.afterUnanswered !== true;
36282
36362
  }
36283
36363
  }
36284
36364
  var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
@@ -36372,10 +36452,12 @@ function createEnvoyClient(config) {
36372
36452
  const request = async (path, init, options = {}) => {
36373
36453
  const url = `${baseUrl}${path}`;
36374
36454
  const tries = options.retry === false ? 1 : attempts;
36455
+ let unanswered = false;
36375
36456
  for (let attempt = 0;attempt < tries; attempt += 1) {
36376
36457
  options.onAttempt?.();
36377
36458
  const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs, options.actingSession);
36378
36459
  if ("unanswered" in outcome) {
36460
+ unanswered = true;
36379
36461
  options.onUnanswered?.();
36380
36462
  if (attempt + 1 < tries) {
36381
36463
  await waitForRetry(retryDelayMs);
@@ -36400,9 +36482,16 @@ function createEnvoyClient(config) {
36400
36482
  url: shown(url),
36401
36483
  status: response.status,
36402
36484
  responseBody: body
36403
- }, { tokens: redacted, redirectTo: redirectOrigin(response, url, redacted) });
36485
+ }, {
36486
+ tokens: redacted,
36487
+ redirectTo: redirectOrigin(response, url, redacted),
36488
+ afterUnanswered: unanswered
36489
+ });
36404
36490
  if (response.status >= 500) {
36405
- options.onUnanswered?.();
36491
+ if (!error.notSent) {
36492
+ unanswered = true;
36493
+ options.onUnanswered?.();
36494
+ }
36406
36495
  if (attempt + 1 < tries) {
36407
36496
  await waitForRetry(retryDelayMs);
36408
36497
  continue;
@@ -36478,7 +36567,7 @@ function createEnvoyClient(config) {
36478
36567
  return taken;
36479
36568
  response = EnvelopeResponseSchema.parse(raw);
36480
36569
  } catch (error) {
36481
- const refused = notSent || error instanceof EnvoyApiError && error.details.status < 500;
36570
+ const refused = notSent || error instanceof EnvoyApiError && (error.details.status < 500 || error.notSent);
36482
36571
  if (refused && !unanswered)
36483
36572
  throw error;
36484
36573
  throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, made, error);