@sjawhar/pi-legion 19.24.1 → 19.25.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/legion.js CHANGED
@@ -16863,6 +16863,12 @@ var DEFAULT_ISSUE_PAGE_LIMIT = 50;
16863
16863
  var DEFAULT_ISSUE_READ_EVENTS = 10;
16864
16864
  var ASK_TURNS = ["human", "agent"];
16865
16865
  var DELIVERY_CAPABILITIES = ["aside", "btw", "steer"];
16866
+ var DELIVERY_ATTEMPT_STATES = ["pending", "sent", "queued", "failed"];
16867
+ var SETTLED_DELIVERY_STATES = [
16868
+ "sent",
16869
+ "queued",
16870
+ "failed"
16871
+ ];
16866
16872
  var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
16867
16873
  var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
16868
16874
  var IDEMPOTENCY_KEY_MAX = 128;
@@ -16879,6 +16885,7 @@ function answerNotKept(status, replayed, body) {
16879
16885
  var IDEMPOTENCY_KEY_TTL_MS = 24 * 60 * 60 * 1000;
16880
16886
  var IDEMPOTENCY_LEASE_MS = 60 * 1000;
16881
16887
  var DELIVERY_DUPLICATE_WINDOW_MS = 72 * 60 * 60 * 1000;
16888
+ var DELIVERY_DUPLICATE_WINDOW_HOURS = DELIVERY_DUPLICATE_WINDOW_MS / 3600000;
16882
16889
  var SEARCH_DEGRADED_EMBEDDER_UNAVAILABLE = "embedder_unavailable";
16883
16890
 
16884
16891
  // ../contracts/src/dispatch-api-refs.ts
@@ -18182,7 +18189,7 @@ var commentDeliveryFields = {
18182
18189
  session_id: string2().nullable(),
18183
18190
  envelope_id: string2().nullable(),
18184
18191
  duplicate: boolean2().optional(),
18185
- state: _enum2(["pending", "sent", "failed"]),
18192
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
18186
18193
  error: string2().nullable(),
18187
18194
  resolve_error: string2().nullable(),
18188
18195
  reply_id: string2().nullable(),
@@ -18270,7 +18277,7 @@ var CommentDeliveryEventPayloadSchema = strictObject({
18270
18277
  attempt: number2().int().positive(),
18271
18278
  delivery: _enum2(DELIVERY_CAPABILITIES),
18272
18279
  session_id: string2().nullable(),
18273
- state: _enum2(["sent", "failed"]),
18280
+ state: _enum2(SETTLED_DELIVERY_STATES),
18274
18281
  duplicate: boolean2().optional(),
18275
18282
  error: string2().optional(),
18276
18283
  reply_id: string2().nullable()
@@ -18305,7 +18312,7 @@ var messageDeliveryFields = {
18305
18312
  session_id: string2(),
18306
18313
  envelope_id: string2().nullable(),
18307
18314
  duplicate: boolean2().optional(),
18308
- state: _enum2(["pending", "sent", "failed"]),
18315
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
18309
18316
  error: string2().nullable(),
18310
18317
  reply_id: string2().nullable(),
18311
18318
  created_at: string2(),
@@ -18356,7 +18363,7 @@ var messageDeliveryEventPayloadFields = {
18356
18363
  session_id: string2(),
18357
18364
  target: string2().optional(),
18358
18365
  title: string2(),
18359
- state: _enum2(["sent", "failed"]),
18366
+ state: _enum2(SETTLED_DELIVERY_STATES),
18360
18367
  duplicate: boolean2().optional(),
18361
18368
  error: string2().optional()
18362
18369
  };
@@ -23112,6 +23119,19 @@ async function messageCommand(context) {
23112
23119
  }
23113
23120
  };
23114
23121
  }
23122
+ function arrivalText(attempt) {
23123
+ if (attempt === undefined)
23124
+ return "Dispatch recorded no delivery attempt for it";
23125
+ if (attempt.state === "failed") {
23126
+ return `its delivery failed: ${attempt.error ?? "the listener gave no reason"}`;
23127
+ }
23128
+ if (attempt.state === "pending")
23129
+ return "its delivery is still on its way";
23130
+ if (attempt.state === "queued") {
23131
+ return `that session is stopped, so its delivery is queued: it gets the message if it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours`;
23132
+ }
23133
+ return `it reached that session as ${attempt.delivery}`;
23134
+ }
23115
23135
  async function sendToAgentCommand(context) {
23116
23136
  const { args, client } = context;
23117
23137
  const session = stringArg(args, "session");
@@ -23123,7 +23143,7 @@ async function sendToAgentCommand(context) {
23123
23143
  });
23124
23144
  const attempt = message.deliveries?.at(-1);
23125
23145
  const readBack = conversationReadBack(message.id);
23126
- const arrival = attempt === undefined ? "Dispatch recorded no delivery attempt for it" : attempt.state === "failed" ? `its delivery failed: ${attempt.error ?? "the listener gave no reason"}` : attempt.state === "pending" ? "its delivery is still on its way" : `it reached that session as ${attempt.delivery}`;
23146
+ const arrival = arrivalText(attempt);
23127
23147
  return {
23128
23148
  text: `Sent message ${message.id} to session ${session}; ${arrival}. ${readBack}`,
23129
23149
  details: {
@@ -25505,8 +25525,11 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
25505
25525
  holder: string2().optional(),
25506
25526
  holder_state: SessionStateSchema.optional(),
25507
25527
  recipient_state: SessionStateSchema.optional(),
25528
+ state: string2().optional(),
25508
25529
  last_seen: number2().int().optional(),
25509
- duplicate: boolean2().optional()
25530
+ duplicate: boolean2().optional(),
25531
+ recipients: number2().int().nonnegative().optional(),
25532
+ recipients_connected: number2().int().nonnegative().optional()
25510
25533
  });
25511
25534
  var PublishResponseSchema = EnvelopeResponseSchema.extend({
25512
25535
  kept: boolean2().optional(),
@@ -25602,7 +25625,7 @@ class EnvoySendUnconfirmedError extends Error {
25602
25625
  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)})`;
25603
25626
  const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
25604
25627
  const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
25605
- 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.";
25628
+ const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_HOURS} 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.";
25606
25629
  super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
25607
25630
  this.targetSessionID = targetSessionID;
25608
25631
  this.idempotencyKey = idempotencyKey;
@@ -25752,6 +25775,7 @@ function createEnvoyClient(config) {
25752
25775
  recipient: response.recipient ?? input.targetSessionID,
25753
25776
  confirmed: response.recipient !== undefined,
25754
25777
  recipientState: response.recipient_state ?? "live",
25778
+ state: response.state === "stopped" ? "stopped" : "connected",
25755
25779
  ...response.last_seen === undefined || response.last_seen <= 0 ? {} : { lastSeen: response.last_seen },
25756
25780
  duplicate: response.duplicate === true
25757
25781
  };
@@ -25772,6 +25796,8 @@ function createEnvoyClient(config) {
25772
25796
  envelope: response,
25773
25797
  ...response.holder === undefined ? {} : { holder: response.holder },
25774
25798
  ...response.holder_state === undefined ? {} : { holderState: response.holder_state },
25799
+ ...response.recipients === undefined ? {} : { recipients: response.recipients },
25800
+ ...response.recipients_connected === undefined ? {} : { recipientsConnected: response.recipients_connected },
25775
25801
  ...response.kept === undefined ? {} : { kept: response.kept },
25776
25802
  ...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
25777
25803
  };
@@ -28850,7 +28876,7 @@ import { logger as logger3 } from "@oh-my-pi/pi-utils";
28850
28876
  // package.json
28851
28877
  var package_default = {
28852
28878
  name: "@sjawhar/pi-legion",
28853
- version: "19.24.1",
28879
+ version: "19.25.0",
28854
28880
  license: "Apache-2.0",
28855
28881
  type: "module",
28856
28882
  omp: {
@@ -76,7 +76,8 @@ next look of its own.
76
76
 
77
77
  The controller topic is a live wake: a message published while no controller runs reaches nobody
78
78
  at the time. `envoy_publish`'s own answer tells you whether one took it. A publish to a role
79
- answers with its live `holder`. With no claim on `legion-<project>-controller` at all, the answer
79
+ answers with its live `holder`, and with no count of recipients: the listener forwards a role
80
+ message to its holder alone. With no claim on `legion-<project>-controller` at all, the answer
80
81
  says Envoy kept the message instead (`packages/envoy/cmd/listener`, the test "unheld role is kept
81
82
  and answered 202 without publishing on the role topic"): the next session that claims the role is
82
83
  handed each kept message once, within one hour of the keep. A keep is not a delivery: a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-legion",
3
- "version": "19.24.1",
3
+ "version": "19.25.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {