@sjawhar/pi-envoy 15.0.2 → 15.0.3

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
@@ -19150,16 +19150,11 @@ function artifactByReference(artifacts, artifactReference, owner, canonical) {
19150
19150
  const byId = artifacts.find((candidate) => candidate.id === artifactReference);
19151
19151
  if (byId !== undefined)
19152
19152
  return byId;
19153
- const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
19154
- if (bySlug !== undefined) {
19155
- const named = byName.filter((candidate) => candidate.id !== bySlug.id && candidate.kind === "doc");
19156
- if (named.length > 0) {
19157
- throw new Error(documentReferenceProblem(artifactReference, [bySlug, ...named], owner, "id"));
19158
- }
19153
+ if (bySlug !== undefined)
19159
19154
  return bySlug;
19160
- }
19155
+ const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
19161
19156
  if (byName.length > 1) {
19162
- throw new Error(documentReferenceProblem(artifactReference, byName, owner, "slug"));
19157
+ throw new Error(documentReferenceProblem(artifactReference, byName, owner, true));
19163
19158
  }
19164
19159
  const [artifact] = byName;
19165
19160
  if (artifact === undefined) {
@@ -19214,10 +19209,10 @@ async function documentTargets(client, resolution) {
19214
19209
  };
19215
19210
  }
19216
19211
  var documentHintLimit = 8;
19217
- function documentReferenceProblem(reference, documents, owner, use) {
19218
- const hints = documents.slice(0, documentHintLimit).map((document) => use === "id" ? `${document.id} (${document.slug}, ${document.name})` : `${document.slug} (${document.name})`);
19212
+ function documentReferenceProblem(reference, documents, owner, ambiguous = false) {
19213
+ const hints = documents.slice(0, documentHintLimit).map((document) => `${document.slug} (${document.name})`);
19219
19214
  const list = hints.length === 0 ? "none" : hints.join(", ");
19220
- return use === undefined ? `document "${reference}" not found by slug; this ${owner}'s documents: ${list}` : `"${reference}" names ${documents.length} documents on this ${owner}; use ${use === "id" ? "the id" : "a slug"}: ${list}`;
19215
+ return ambiguous ? `"${reference}" names ${documents.length} documents on this ${owner}; use a slug: ${list}` : `document "${reference}" not found by slug; this ${owner}'s documents: ${list}`;
19221
19216
  }
19222
19217
  var askHintLimit = 8;
19223
19218
  function askIDInputProblem(asks, scope) {
@@ -22048,7 +22043,8 @@ var ErrorWireSchema = object({
22048
22043
  });
22049
22044
  var EnvelopeResponseSchema = EnvelopeSchema.extend({
22050
22045
  recipient: string2().optional(),
22051
- holder: string2().optional()
22046
+ holder: string2().optional(),
22047
+ duplicate: boolean2().optional()
22052
22048
  });
22053
22049
  var ReplayWireSchema = object({
22054
22050
  stream: object({
@@ -22120,44 +22116,84 @@ class EnvoyApiError extends Error {
22120
22116
  this.code = parsed?.code;
22121
22117
  }
22122
22118
  }
22119
+ var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
22120
+
22121
+ class EnvoySendUnconfirmedError extends Error {
22122
+ targetSessionID;
22123
+ idempotencyKey;
22124
+ attempts;
22125
+ last;
22126
+ name = "EnvoySendUnconfirmedError";
22127
+ resendSafe;
22128
+ constructor(targetSessionID, idempotencyKey, attempts, last) {
22129
+ const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
22130
+ const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
22131
+ const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
22132
+ const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
22133
+ super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
22134
+ this.targetSessionID = targetSessionID;
22135
+ this.idempotencyKey = idempotencyKey;
22136
+ this.attempts = attempts;
22137
+ this.last = last;
22138
+ this.resendSafe = resendSafe;
22139
+ }
22140
+ }
22123
22141
  function createEnvoyClient(config) {
22124
22142
  const baseUrl = normalizeEnvoyUrl(config.baseUrl);
22125
22143
  const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
22126
22144
  const apiToken = config.token;
22145
+ const attempts = config.retry === false ? 1 : 2;
22146
+ const attemptOnce = async (url, init, deadlineMs) => {
22147
+ const headers = new Headers(init.headers);
22148
+ if (apiToken)
22149
+ headers.set("Authorization", `Bearer ${apiToken}`);
22150
+ let response;
22151
+ try {
22152
+ response = await config.fetch(url, {
22153
+ ...init,
22154
+ headers,
22155
+ signal: AbortSignal.timeout(deadlineMs)
22156
+ });
22157
+ } catch (error) {
22158
+ return { unanswered: error };
22159
+ }
22160
+ try {
22161
+ return { response, body: await response.text() };
22162
+ } catch (error) {
22163
+ if (response.status >= 400 && response.status < 500) {
22164
+ return { response, body: `(its body did not arrive: ${String(error)})` };
22165
+ }
22166
+ return { unanswered: error };
22167
+ }
22168
+ };
22127
22169
  const request = async (path, init, options = {}) => {
22128
22170
  const url = `${baseUrl}${path}`;
22129
- const attempts = config.retry === false ? 1 : 2;
22130
22171
  const tries = options.retry === false ? 1 : attempts;
22131
22172
  for (let attempt = 0;attempt < tries; attempt += 1) {
22132
- let response;
22133
- try {
22134
- const headers = new Headers(init.headers);
22135
- if (apiToken)
22136
- headers.set("Authorization", `Bearer ${apiToken}`);
22137
- response = await config.fetch(url, {
22138
- ...init,
22139
- headers,
22140
- signal: AbortSignal.timeout(options.timeoutMs ?? timeoutMs)
22141
- });
22142
- } catch (error) {
22173
+ const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs);
22174
+ if ("unanswered" in outcome) {
22175
+ options.onUnanswered?.();
22143
22176
  if (attempt + 1 < tries) {
22144
22177
  await waitForRetry();
22145
22178
  continue;
22146
22179
  }
22147
- throw error;
22180
+ throw outcome.unanswered;
22148
22181
  }
22149
- const responseBody = await response.text();
22182
+ const { response, body } = outcome;
22150
22183
  if (response.ok)
22151
- return responseBody;
22184
+ return body;
22152
22185
  const error = new EnvoyApiError({
22153
22186
  method: init.method ?? "GET",
22154
22187
  url,
22155
22188
  status: response.status,
22156
- responseBody
22189
+ responseBody: body
22157
22190
  });
22158
- if (response.status >= 500 && attempt + 1 < tries) {
22159
- await waitForRetry();
22160
- continue;
22191
+ if (response.status >= 500) {
22192
+ options.onUnanswered?.();
22193
+ if (attempt + 1 < tries) {
22194
+ await waitForRetry();
22195
+ continue;
22196
+ }
22161
22197
  }
22162
22198
  throw error;
22163
22199
  }
@@ -22193,18 +22229,33 @@ function createEnvoyClient(config) {
22193
22229
  getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
22194
22230
  send: async (input) => {
22195
22231
  const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
22196
- const response = EnvelopeResponseSchema.parse(JSON.parse(await post("/v1/messages/send", {
22197
- source: input.source ?? "agent",
22198
- ...sourceSession(input.sourceSessionID),
22199
- target_session: input.targetSessionID,
22200
- message: input.message,
22201
- idempotency_key: idempotencyKey,
22202
- ...messageMetadata(input)
22203
- })));
22232
+ let unanswered = false;
22233
+ let response;
22234
+ try {
22235
+ const answer = await post("/v1/messages/send", {
22236
+ source: input.source ?? "agent",
22237
+ ...sourceSession(input.sourceSessionID),
22238
+ target_session: input.targetSessionID,
22239
+ message: input.message,
22240
+ idempotency_key: idempotencyKey,
22241
+ ...messageMetadata(input)
22242
+ }, {
22243
+ onUnanswered: () => {
22244
+ unanswered = true;
22245
+ }
22246
+ });
22247
+ response = EnvelopeResponseSchema.parse(JSON.parse(answer));
22248
+ } catch (error) {
22249
+ if (error instanceof EnvoyApiError && error.details.status < 500 && !unanswered) {
22250
+ throw error;
22251
+ }
22252
+ throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, attempts, error);
22253
+ }
22204
22254
  return {
22205
22255
  envelope: response,
22206
22256
  recipient: response.recipient ?? input.targetSessionID,
22207
- confirmed: response.recipient !== undefined
22257
+ confirmed: response.recipient !== undefined,
22258
+ duplicate: response.duplicate === true
22208
22259
  };
22209
22260
  },
22210
22261
  publish: async (input) => {
@@ -22243,7 +22294,13 @@ function createEnvoyClient(config) {
22243
22294
  raw = await post("/v1/roles/set", body);
22244
22295
  } catch (error) {
22245
22296
  if (error instanceof EnvoyApiError && error.details.status === 409) {
22246
- const held = RoleHeldWireSchema.safeParse(JSON.parse(error.details.responseBody));
22297
+ let answer;
22298
+ try {
22299
+ answer = JSON.parse(error.details.responseBody);
22300
+ } catch {
22301
+ throw error;
22302
+ }
22303
+ const held = RoleHeldWireSchema.safeParse(answer);
22247
22304
  if (held.success)
22248
22305
  return { claimed: false, holder: held.data.holder };
22249
22306
  }
package/dist/envoy.js CHANGED
@@ -34476,7 +34476,8 @@ var ErrorWireSchema = object({
34476
34476
  });
34477
34477
  var EnvelopeResponseSchema = EnvelopeSchema.extend({
34478
34478
  recipient: string2().optional(),
34479
- holder: string2().optional()
34479
+ holder: string2().optional(),
34480
+ duplicate: boolean2().optional()
34480
34481
  });
34481
34482
  var ReplayWireSchema = object({
34482
34483
  stream: object({
@@ -34562,44 +34563,84 @@ class EnvoyApiError extends Error {
34562
34563
  this.code = parsed?.code;
34563
34564
  }
34564
34565
  }
34566
+ var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
34567
+
34568
+ class EnvoySendUnconfirmedError extends Error {
34569
+ targetSessionID;
34570
+ idempotencyKey;
34571
+ attempts;
34572
+ last;
34573
+ name = "EnvoySendUnconfirmedError";
34574
+ resendSafe;
34575
+ constructor(targetSessionID, idempotencyKey, attempts, last) {
34576
+ const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
34577
+ const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
34578
+ const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
34579
+ const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
34580
+ super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
34581
+ this.targetSessionID = targetSessionID;
34582
+ this.idempotencyKey = idempotencyKey;
34583
+ this.attempts = attempts;
34584
+ this.last = last;
34585
+ this.resendSafe = resendSafe;
34586
+ }
34587
+ }
34565
34588
  function createEnvoyClient(config) {
34566
34589
  const baseUrl = normalizeEnvoyUrl(config.baseUrl);
34567
34590
  const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
34568
34591
  const apiToken = config.token;
34592
+ const attempts = config.retry === false ? 1 : 2;
34593
+ const attemptOnce = async (url, init, deadlineMs) => {
34594
+ const headers = new Headers(init.headers);
34595
+ if (apiToken)
34596
+ headers.set("Authorization", `Bearer ${apiToken}`);
34597
+ let response;
34598
+ try {
34599
+ response = await config.fetch(url, {
34600
+ ...init,
34601
+ headers,
34602
+ signal: AbortSignal.timeout(deadlineMs)
34603
+ });
34604
+ } catch (error) {
34605
+ return { unanswered: error };
34606
+ }
34607
+ try {
34608
+ return { response, body: await response.text() };
34609
+ } catch (error) {
34610
+ if (response.status >= 400 && response.status < 500) {
34611
+ return { response, body: `(its body did not arrive: ${String(error)})` };
34612
+ }
34613
+ return { unanswered: error };
34614
+ }
34615
+ };
34569
34616
  const request = async (path, init, options = {}) => {
34570
34617
  const url = `${baseUrl}${path}`;
34571
- const attempts = config.retry === false ? 1 : 2;
34572
34618
  const tries = options.retry === false ? 1 : attempts;
34573
34619
  for (let attempt = 0;attempt < tries; attempt += 1) {
34574
- let response;
34575
- try {
34576
- const headers = new Headers(init.headers);
34577
- if (apiToken)
34578
- headers.set("Authorization", `Bearer ${apiToken}`);
34579
- response = await config.fetch(url, {
34580
- ...init,
34581
- headers,
34582
- signal: AbortSignal.timeout(options.timeoutMs ?? timeoutMs)
34583
- });
34584
- } catch (error) {
34620
+ const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs);
34621
+ if ("unanswered" in outcome) {
34622
+ options.onUnanswered?.();
34585
34623
  if (attempt + 1 < tries) {
34586
34624
  await waitForRetry();
34587
34625
  continue;
34588
34626
  }
34589
- throw error;
34627
+ throw outcome.unanswered;
34590
34628
  }
34591
- const responseBody = await response.text();
34629
+ const { response, body } = outcome;
34592
34630
  if (response.ok)
34593
- return responseBody;
34631
+ return body;
34594
34632
  const error = new EnvoyApiError({
34595
34633
  method: init.method ?? "GET",
34596
34634
  url,
34597
34635
  status: response.status,
34598
- responseBody
34636
+ responseBody: body
34599
34637
  });
34600
- if (response.status >= 500 && attempt + 1 < tries) {
34601
- await waitForRetry();
34602
- continue;
34638
+ if (response.status >= 500) {
34639
+ options.onUnanswered?.();
34640
+ if (attempt + 1 < tries) {
34641
+ await waitForRetry();
34642
+ continue;
34643
+ }
34603
34644
  }
34604
34645
  throw error;
34605
34646
  }
@@ -34635,18 +34676,33 @@ function createEnvoyClient(config) {
34635
34676
  getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
34636
34677
  send: async (input) => {
34637
34678
  const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
34638
- const response = EnvelopeResponseSchema.parse(JSON.parse(await post("/v1/messages/send", {
34639
- source: input.source ?? "agent",
34640
- ...sourceSession(input.sourceSessionID),
34641
- target_session: input.targetSessionID,
34642
- message: input.message,
34643
- idempotency_key: idempotencyKey,
34644
- ...messageMetadata(input)
34645
- })));
34679
+ let unanswered = false;
34680
+ let response;
34681
+ try {
34682
+ const answer = await post("/v1/messages/send", {
34683
+ source: input.source ?? "agent",
34684
+ ...sourceSession(input.sourceSessionID),
34685
+ target_session: input.targetSessionID,
34686
+ message: input.message,
34687
+ idempotency_key: idempotencyKey,
34688
+ ...messageMetadata(input)
34689
+ }, {
34690
+ onUnanswered: () => {
34691
+ unanswered = true;
34692
+ }
34693
+ });
34694
+ response = EnvelopeResponseSchema.parse(JSON.parse(answer));
34695
+ } catch (error) {
34696
+ if (error instanceof EnvoyApiError && error.details.status < 500 && !unanswered) {
34697
+ throw error;
34698
+ }
34699
+ throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, attempts, error);
34700
+ }
34646
34701
  return {
34647
34702
  envelope: response,
34648
34703
  recipient: response.recipient ?? input.targetSessionID,
34649
- confirmed: response.recipient !== undefined
34704
+ confirmed: response.recipient !== undefined,
34705
+ duplicate: response.duplicate === true
34650
34706
  };
34651
34707
  },
34652
34708
  publish: async (input) => {
@@ -34685,7 +34741,13 @@ function createEnvoyClient(config) {
34685
34741
  raw = await post("/v1/roles/set", body);
34686
34742
  } catch (error) {
34687
34743
  if (error instanceof EnvoyApiError && error.details.status === 409) {
34688
- const held = RoleHeldWireSchema.safeParse(JSON.parse(error.details.responseBody));
34744
+ let answer;
34745
+ try {
34746
+ answer = JSON.parse(error.details.responseBody);
34747
+ } catch {
34748
+ throw error;
34749
+ }
34750
+ const held = RoleHeldWireSchema.safeParse(answer);
34689
34751
  if (held.success)
34690
34752
  return { claimed: false, holder: held.data.holder };
34691
34753
  }
@@ -37021,16 +37083,11 @@ function artifactByReference(artifacts, artifactReference, owner, canonical) {
37021
37083
  const byId = artifacts.find((candidate) => candidate.id === artifactReference);
37022
37084
  if (byId !== undefined)
37023
37085
  return byId;
37024
- const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
37025
- if (bySlug !== undefined) {
37026
- const named = byName.filter((candidate) => candidate.id !== bySlug.id && candidate.kind === "doc");
37027
- if (named.length > 0) {
37028
- throw new Error(documentReferenceProblem(artifactReference, [bySlug, ...named], owner, "id"));
37029
- }
37086
+ if (bySlug !== undefined)
37030
37087
  return bySlug;
37031
- }
37088
+ const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
37032
37089
  if (byName.length > 1) {
37033
- throw new Error(documentReferenceProblem(artifactReference, byName, owner, "slug"));
37090
+ throw new Error(documentReferenceProblem(artifactReference, byName, owner, true));
37034
37091
  }
37035
37092
  const [artifact] = byName;
37036
37093
  if (artifact === undefined) {
@@ -37085,10 +37142,10 @@ async function documentTargets(client, resolution) {
37085
37142
  };
37086
37143
  }
37087
37144
  var documentHintLimit = 8;
37088
- function documentReferenceProblem(reference, documents, owner, use) {
37089
- const hints = documents.slice(0, documentHintLimit).map((document) => use === "id" ? `${document.id} (${document.slug}, ${document.name})` : `${document.slug} (${document.name})`);
37145
+ function documentReferenceProblem(reference, documents, owner, ambiguous = false) {
37146
+ const hints = documents.slice(0, documentHintLimit).map((document) => `${document.slug} (${document.name})`);
37090
37147
  const list = hints.length === 0 ? "none" : hints.join(", ");
37091
- return use === undefined ? `document "${reference}" not found by slug; this ${owner}'s documents: ${list}` : `"${reference}" names ${documents.length} documents on this ${owner}; use ${use === "id" ? "the id" : "a slug"}: ${list}`;
37148
+ return ambiguous ? `"${reference}" names ${documents.length} documents on this ${owner}; use a slug: ${list}` : `document "${reference}" not found by slug; this ${owner}'s documents: ${list}`;
37092
37149
  }
37093
37150
  async function liveBlocks(client, artifact) {
37094
37151
  const before = await client.docRead(artifact.id);
@@ -37686,10 +37743,11 @@ var envoyToolSpecs = [
37686
37743
  },
37687
37744
  {
37688
37745
  name: "envoy_send",
37689
- description: `Send an Envoy agent-to-agent message directly to another session by session ID. ${DELIVERY_CONTRACT}`,
37746
+ description: `Send an Envoy agent-to-agent message directly to another session by session ID. ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within 72 hours, and Envoy drops it as a repeat if the first copy arrived.`,
37690
37747
  arguments: (schema) => ({
37691
37748
  session_id: schema.string().describe("Target session ID; find it with envoy_sessions or envoy_whoami."),
37692
- ...messageArguments(schema)
37749
+ ...messageArguments(schema),
37750
+ idempotency_key: schema.string().describe("Only to send again a message whose envoy_send was not confirmed delivered: the idempotency_key that error named. Omit it for a new message.").optional()
37693
37751
  }),
37694
37752
  operation: EnvoyToolOperation.send
37695
37753
  },
@@ -37739,6 +37797,9 @@ var envoyToolSpecs = [
37739
37797
  }
37740
37798
  ];
37741
37799
  function sendConfirmationText(result) {
37800
+ if (result.duplicate) {
37801
+ return `sent to ${result.recipient} once: an earlier attempt under the same idempotency_key was already stored, so this one stored no second copy`;
37802
+ }
37742
37803
  return `sent ${result.envelope.event_id} to ${result.recipient}${result.confirmed ? "" : " (recipient unconfirmed by listener)"}`;
37743
37804
  }
37744
37805
  function sessionsOnMachine(sessions, machine) {
@@ -37747,6 +37808,7 @@ function sessionsOnMachine(sessions, machine) {
37747
37808
  return sessions.filter((session) => session.host === machine || session.machine_id === machine);
37748
37809
  }
37749
37810
  var envoyToolSchemas = new Map;
37811
+ var SEND_IDEMPOTENCY_KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
37750
37812
  function parseEnvoyToolArguments(operation, parameters) {
37751
37813
  const spec = envoyToolSpecs.find((candidate) => candidate.operation === operation);
37752
37814
  if (spec === undefined)
@@ -37760,7 +37822,13 @@ function parseEnvoyToolArguments(operation, parameters) {
37760
37822
  if (!parsed.success) {
37761
37823
  throw new ToolInputError(spec.name, formatZodIssues(parsed.error.issues, schema, spec.name));
37762
37824
  }
37763
- return parsed.data;
37825
+ const { data } = parsed;
37826
+ if (typeof data === "object" && data !== null && "idempotency_key" in data && typeof data.idempotency_key === "string" && !SEND_IDEMPOTENCY_KEY.test(data.idempotency_key)) {
37827
+ throw new ToolInputError(spec.name, [
37828
+ `idempotency_key must be the key an unconfirmed send named, a lower-case UUID; got ${JSON.stringify(data.idempotency_key)}`
37829
+ ]);
37830
+ }
37831
+ return data;
37764
37832
  }
37765
37833
 
37766
37834
  // ../pi-shared/src/interface.ts
@@ -38053,7 +38121,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
38053
38121
 
38054
38122
  // package.json
38055
38123
  var name = "@sjawhar/pi-envoy";
38056
- var version2 = "15.0.2";
38124
+ var version2 = "15.0.3";
38057
38125
  var package_default = {
38058
38126
  name,
38059
38127
  version: version2,
@@ -45729,10 +45797,12 @@ Kept (they last while this session holds role ${registrationState.heldRole()}):
45729
45797
  return toolSuccess(JSON.stringify(inbox, null, 2), { count: inbox.length });
45730
45798
  case EnvoyToolOperation.send: {
45731
45799
  const targetSessionID = stringFor(parameters, "session_id");
45800
+ const idempotencyKey = parameters.idempotency_key;
45732
45801
  const result = await client.send({
45733
45802
  sourceSessionID: await replyAddress(context),
45734
45803
  targetSessionID,
45735
45804
  message: stringFor(parameters, "message"),
45805
+ ...typeof idempotencyKey === "string" ? { idempotencyKey } : {},
45736
45806
  ...toMessageMetadata(parameters)
45737
45807
  });
45738
45808
  return toolSuccess(sendConfirmationText(result), {
@@ -14,6 +14,7 @@ Envoy delivers external events and messages between sessions. Delivery is at-lea
14
14
  - Take the target id from the delivery's `reply_with`, or from `envoy_sessions` (filter by `machine`, `dir` or `title`). Never address a tmux pane or window: Envoy delivers only to a session id, and the session in a pane can change.
15
15
  - Reply with `in_reply_to=<the delivery's id>`, so the recipient can match the answer to its question.
16
16
  - Read the `recipient` in the send result, the session Envoy targeted: if it is not the one you meant, resend to the right id.
17
+ - When `envoy_send` says the send is not confirmed delivered, send the same message again with the `idempotency_key` the error names, within 72 hours: Envoy drops it as a repeat if the first copy arrived, and the result says when an earlier attempt was already stored. A resend without that key can deliver the message twice. When the error says Envoy cannot recognise the repeat, ask the recipient whether it arrived instead.
17
18
  - Put the URL or path of what you report in the message, because the recipient cannot find your files any other way.
18
19
  - Set `expects_reply="none"` on a message that needs no answer, and set `urgency` only when the work waits on the answer, so the recipient knows whether to answer and how soon. `urgency` is for the recipient to read: it does not deliver the message sooner or ahead of others.
19
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "15.0.2",
3
+ "version": "15.0.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {