glove-foundry 0.10.0 → 0.11.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.
@@ -576,6 +576,7 @@ function openRunMailbox(options) {
576
576
  const meshWaiters = /* @__PURE__ */ new Map();
577
577
  const handlers = /* @__PURE__ */ new Set();
578
578
  const meshHandlers = /* @__PURE__ */ new Set();
579
+ const eventRoutes = /* @__PURE__ */ new Set();
579
580
  let closed = false;
580
581
  const toHandlers = async (updates) => {
581
582
  for (const handler of [...handlers]) await handler(updates);
@@ -590,6 +591,7 @@ function openRunMailbox(options) {
590
591
  const meshAnswers = /* @__PURE__ */ new Map();
591
592
  const heardMesh = [];
592
593
  const updates = [];
594
+ const routed = [];
593
595
  const rest = [];
594
596
  for (const delivery of deliveries) {
595
597
  if (delivery.durable?.event.expiresAt && Date.parse(delivery.durable.event.expiresAt) <= Date.now()) {
@@ -609,7 +611,9 @@ function openRunMailbox(options) {
609
611
  } else if (isDelegationUpdate(delivery) && handlers.size > 0) {
610
612
  updates.push(delivery);
611
613
  } else {
612
- rest.push(delivery);
614
+ const route = [...eventRoutes].find((candidate) => candidate.match(delivery));
615
+ if (route) routed.push({ route, delivery });
616
+ else rest.push(delivery);
613
617
  }
614
618
  }
615
619
  for (const [delegationId, batch] of replies) {
@@ -622,6 +626,7 @@ function openRunMailbox(options) {
622
626
  if (updates.length > 0) await toHandlers(updates);
623
627
  if (heardMesh.length > 0) for (const handler of [...meshHandlers]) await handler(heardMesh.map((item) => item.message));
624
628
  options.consumed?.([...[...replies.values()].flat(), ...[...meshAnswers.values()].flat(), ...updates, ...heardMesh]);
629
+ for (const { route, delivery } of routed) await route.take(delivery);
625
630
  if (rest.length > 0) await options.sink.forward(rest);
626
631
  }
627
632
  });
@@ -687,13 +692,25 @@ function openRunMailbox(options) {
687
692
  await waiting;
688
693
  };
689
694
  },
695
+ onEvents(match, take) {
696
+ const route = { match, take };
697
+ eventRoutes.add(route);
698
+ const waiting = options.sink.reclaim(match).then(async (taken) => {
699
+ for (const delivery of taken) await take(delivery);
700
+ });
701
+ return async () => {
702
+ eventRoutes.delete(route);
703
+ await waiting;
704
+ };
705
+ },
690
706
  async close() {
691
707
  if (closed) return;
692
708
  closed = true;
693
709
  for (const finish of [...waiters.values()]) finish(null);
694
710
  for (const finish of [...meshWaiters.values()]) finish(null);
695
711
  await listener.stop(async () => {
696
- for (const delivery of await options.sink.reclaim(() => true)) {
712
+ const unused = options.sink.release ? await options.sink.release() : await options.sink.reclaim(() => true);
713
+ for (const delivery of unused) {
697
714
  await writeMailboxDelivery(options.directory, options.conversationId, delivery);
698
715
  }
699
716
  });
@@ -736,6 +753,9 @@ function deliveryOf(event) {
736
753
  }
737
754
  var formatRunEvents = defaultEventFormatter;
738
755
  var RunEventQueue = class {
756
+ constructor(preparation) {
757
+ this.preparation = preparation;
758
+ }
739
759
  events = [];
740
760
  async push(event) {
741
761
  if (this.events.some((queued) => queued.id === event.id)) return false;
@@ -748,7 +768,26 @@ var RunEventQueue = class {
748
768
  async take() {
749
769
  const taken = this.events;
750
770
  this.events = [];
751
- return taken;
771
+ if (!this.preparation) return taken;
772
+ const ready = [];
773
+ const kept = [];
774
+ for (const event of taken) {
775
+ const delivery = deliveryOf(event);
776
+ if (!delivery || !this.preparation.applies(delivery)) {
777
+ ready.push(event);
778
+ continue;
779
+ }
780
+ try {
781
+ const prepared = await this.preparation.prepare(event, delivery);
782
+ if ("suppress" in prepared) this.preparation.suppressed(delivery, prepared.suppress);
783
+ else ready.push({ ...event, content: prepared.say });
784
+ } catch (cause) {
785
+ kept.push(event);
786
+ this.preparation.failed(event, cause);
787
+ }
788
+ }
789
+ this.events = [...kept, ...this.events];
790
+ return ready;
752
791
  }
753
792
  async remove(ids) {
754
793
  const drop = new Set(ids);
@@ -787,6 +826,60 @@ async function waitForConversationLease(directory, runId, signal, pollMs = 25) {
787
826
  }
788
827
  }
789
828
 
829
+ // src/event-receipts.ts
830
+ import { createHash as createHash2 } from "node:crypto";
831
+ import { Effect } from "effect";
832
+ function matchesReceiptFilter(receipt, filter = {}) {
833
+ if (filter.agentId && receipt.agentId !== filter.agentId) return false;
834
+ if (filter.conversationId && receipt.conversationId !== filter.conversationId) return false;
835
+ if (filter.status) {
836
+ const statuses = typeof filter.status === "string" ? [filter.status] : filter.status;
837
+ if (!statuses.includes(receipt.status)) return false;
838
+ }
839
+ return true;
840
+ }
841
+ function assertEventReceipt(receipt) {
842
+ if (!receipt.id || !receipt.eventId) throw new Error("Event receipt must name its event.");
843
+ if (!receipt.agentId || !receipt.conversationId) throw new Error("Event receipt must name its conversation.");
844
+ }
845
+ function lateChatEffectId(receiptId) {
846
+ return `effect_${createHash2("sha256").update(`late-chat\0${receiptId}`).digest("hex")}`;
847
+ }
848
+ function eventTranscriptMessageId(receiptId) {
849
+ return `foundry-event:${receiptId}`;
850
+ }
851
+ var processReceipts = /* @__PURE__ */ new WeakMap();
852
+ function eventReceiptStore(data) {
853
+ if (data.claimEventReceipt && data.putEventReceipt && data.getEventReceipt) {
854
+ return {
855
+ durable: true,
856
+ get: (id) => Effect.runPromise(data.getEventReceipt(id)),
857
+ claim: (receipt) => Effect.runPromise(data.claimEventReceipt(receipt)),
858
+ put: (receipt) => Effect.runPromise(data.putEventReceipt(receipt))
859
+ };
860
+ }
861
+ let local = processReceipts.get(data);
862
+ if (!local) processReceipts.set(data, local = /* @__PURE__ */ new Map());
863
+ const memory = local;
864
+ return {
865
+ durable: false,
866
+ async get(id) {
867
+ const receipt = memory.get(id);
868
+ return receipt ? structuredClone(receipt) : null;
869
+ },
870
+ async claim(receipt) {
871
+ assertEventReceipt(receipt);
872
+ if (memory.has(receipt.id)) return false;
873
+ memory.set(receipt.id, structuredClone(receipt));
874
+ return true;
875
+ },
876
+ async put(receipt) {
877
+ assertEventReceipt(receipt);
878
+ memory.set(receipt.id, structuredClone(receipt));
879
+ }
880
+ };
881
+ }
882
+
790
883
  export {
791
884
  meshIdentity,
792
885
  isThreadId,
@@ -819,8 +912,14 @@ export {
819
912
  drainMailbox,
820
913
  openRunMailbox,
821
914
  deliveryEvent,
915
+ deliveryOf,
822
916
  formatRunEvents,
823
917
  RunEventQueue,
824
918
  writeConversationLease,
825
- waitForConversationLease
919
+ waitForConversationLease,
920
+ matchesReceiptFilter,
921
+ assertEventReceipt,
922
+ lateChatEffectId,
923
+ eventTranscriptMessageId,
924
+ eventReceiptStore
826
925
  };
@@ -1,3 +1,7 @@
1
+ import {
2
+ assertEventReceipt,
3
+ matchesReceiptFilter
4
+ } from "./chunk-2JCISE2U.js";
1
5
  import {
2
6
  DURABLE_SEGMENT,
3
7
  EMPTY_CAPABILITY_REGISTRY,
@@ -21,7 +25,7 @@ import {
21
25
  installationKey,
22
26
  internalAgentName,
23
27
  waitForFoundryCoreCommandResult
24
- } from "./chunk-CYOIHSUX.js";
28
+ } from "./chunk-NWFOY3L7.js";
25
29
 
26
30
  // src/application.ts
27
31
  var FOUNDRY_APPLICATION_BRAND = /* @__PURE__ */ Symbol.for(
@@ -67,15 +71,45 @@ import { nextCronOccurrence } from "station-schedules";
67
71
  var TERMINAL_OCCURRENCE_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "skipped", "cancelled"]);
68
72
  var SCHEDULE_MISFIRE_GRACE_MS = 6e4;
69
73
  var RETAINED_TERMINAL_OCCURRENCES = 100;
70
- function activationScheduleRevision(activation) {
71
- return createHash("sha256").update(JSON.stringify({
74
+ function canonicalJson(value) {
75
+ const text = JSON.stringify(value);
76
+ if (text === void 0) return "null";
77
+ const sort = (item) => {
78
+ if (Array.isArray(item)) return item.map(sort);
79
+ if (item && typeof item === "object") {
80
+ const record = item;
81
+ return Object.fromEntries(Object.keys(record).sort().map((key) => [key, sort(record[key])]));
82
+ }
83
+ return item;
84
+ };
85
+ return JSON.stringify(sort(JSON.parse(text)));
86
+ }
87
+ function configuration(activation) {
88
+ return {
72
89
  definitionId: activation.definitionId,
73
90
  agentId: activation.agentId,
74
91
  conversationId: activation.conversationId,
75
92
  message: activation.message,
76
93
  payload: activation.payload ?? null,
77
94
  timing: activation.timing
78
- })).digest("hex");
95
+ };
96
+ }
97
+ function activationScheduleRevision(activation) {
98
+ return createHash("sha256").update(canonicalJson(configuration(activation))).digest("hex");
99
+ }
100
+ function permutations(items) {
101
+ if (items.length <= 1) return [[...items]];
102
+ return items.flatMap((item, index) => permutations([...items.slice(0, index), ...items.slice(index + 1)]).map((rest) => [item, ...rest]));
103
+ }
104
+ function legacyScheduleRevisions(activation) {
105
+ const timing = activation.timing;
106
+ return permutations(Object.keys(timing)).map((keys) => createHash("sha256").update(JSON.stringify({
107
+ ...configuration(activation),
108
+ timing: Object.fromEntries(keys.map((key) => [key, timing[key]]))
109
+ })).digest("hex"));
110
+ }
111
+ function scheduleRevisionMatches(activation, revision) {
112
+ return revision === activationScheduleRevision(activation) || legacyScheduleRevisions(activation).includes(revision);
79
113
  }
80
114
  function scheduleOccurrenceId(activationId, revision, scheduledFor) {
81
115
  const instant = new Date(scheduledFor).toISOString();
@@ -913,6 +947,7 @@ var MemoryFoundryDataAdapter = class {
913
947
  approvals = /* @__PURE__ */ new Map();
914
948
  activations = /* @__PURE__ */ new Map();
915
949
  occurrences = /* @__PURE__ */ new Map();
950
+ receipts = /* @__PURE__ */ new Map();
916
951
  conversations = /* @__PURE__ */ new Map();
917
952
  workspace = /* @__PURE__ */ new Map();
918
953
  workingEnvironments = /* @__PURE__ */ new Map();
@@ -998,6 +1033,7 @@ var MemoryFoundryDataAdapter = class {
998
1033
  for (const [id2, item] of this.approvals) if (item.agentId === agentId) this.approvals.delete(id2);
999
1034
  for (const [id2, item] of this.activations) if (item.agentId === agentId) this.activations.delete(id2);
1000
1035
  for (const [id2, item] of this.occurrences) if (item.agentId === agentId) this.occurrences.delete(id2);
1036
+ for (const [id2, item] of this.receipts) if (item.agentId === agentId) this.receipts.delete(id2);
1001
1037
  for (const id2 of conversationIds) this.conversations.delete(id2);
1002
1038
  for (const [id2, item] of this.inbox) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.inbox.delete(id2);
1003
1039
  for (const [id2, item] of this.tasks) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.tasks.delete(id2);
@@ -1083,6 +1119,29 @@ var MemoryFoundryDataAdapter = class {
1083
1119
  listEvents() {
1084
1120
  return Effect2.sync(() => [...this.events.values()].map((record) => structuredClone(record)));
1085
1121
  }
1122
+ claimEventReceipt(receipt) {
1123
+ return Effect2.sync(() => {
1124
+ assertEventReceipt(receipt);
1125
+ if (this.receipts.has(receipt.id)) return false;
1126
+ this.receipts.set(receipt.id, structuredClone(receipt));
1127
+ return true;
1128
+ });
1129
+ }
1130
+ putEventReceipt(receipt) {
1131
+ return Effect2.sync(() => {
1132
+ assertEventReceipt(receipt);
1133
+ this.receipts.set(receipt.id, structuredClone(receipt));
1134
+ });
1135
+ }
1136
+ getEventReceipt(id2) {
1137
+ return Effect2.sync(() => {
1138
+ const receipt = this.receipts.get(id2);
1139
+ return receipt ? structuredClone(receipt) : null;
1140
+ });
1141
+ }
1142
+ listEventReceipts(filter) {
1143
+ return Effect2.sync(() => [...this.receipts.values()].filter((item) => matchesReceiptFilter(item, filter)).map((item) => structuredClone(item)));
1144
+ }
1086
1145
  claimScheduleOccurrence(occurrence) {
1087
1146
  return Effect2.sync(() => {
1088
1147
  assertScheduleOccurrence(occurrence);
@@ -2533,6 +2592,7 @@ export {
2533
2592
  EMPTY_FOUNDRY_APPLICATION,
2534
2593
  TERMINAL_OCCURRENCE_STATUSES,
2535
2594
  activationScheduleRevision,
2595
+ scheduleRevisionMatches,
2536
2596
  scheduleOccurrenceId,
2537
2597
  firstScheduledTime,
2538
2598
  planScheduleOccurrence,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveResolvable
3
- } from "./chunk-CYOIHSUX.js";
3
+ } from "./chunk-NWFOY3L7.js";
4
4
 
5
5
  // src/guidance.ts
6
6
  import { createHash } from "node:crypto";
@@ -226,6 +226,9 @@ function eventRecordId(target, eventId) {
226
226
  function eventDue(record, now = Date.now()) {
227
227
  return record.policy.whenIdle !== "defer" || record.policy.deferTimeoutMs !== void 0 && now >= Date.parse(record.createdAt) + record.policy.deferTimeoutMs;
228
228
  }
229
+ function isGenericDelivery(delivery) {
230
+ return delivery.kind === "agent-message" || delivery.kind === "transmission";
231
+ }
229
232
 
230
233
  // src/core-command-result.ts
231
234
  import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
@@ -1151,6 +1154,7 @@ var CONVENTION_EXPORTS = [
1151
1154
  "delegates",
1152
1155
  "durableSubagents",
1153
1156
  "eventDelivery",
1157
+ "prepareEvent",
1154
1158
  "answerWaitMs",
1155
1159
  "memory",
1156
1160
  "goals",
@@ -1295,6 +1299,7 @@ export {
1295
1299
  foundryEventSchema,
1296
1300
  eventRecordId,
1297
1301
  eventDue,
1302
+ isGenericDelivery,
1298
1303
  FOUNDRY_CORE_COMMAND_DIRECTORY_ENV,
1299
1304
  createFoundryCoreCommandRequest,
1300
1305
  getFoundryCoreCommandRequest,
@@ -38,8 +38,9 @@ import {
38
38
  reconstructPlaybookSubscription,
39
39
  resolveFoundryApproval,
40
40
  scheduleOccurrenceId,
41
+ scheduleRevisionMatches,
41
42
  transmissionPredicate
42
- } from "./chunk-T6YLIGER.js";
43
+ } from "./chunk-4WBQ7XVF.js";
43
44
  import {
44
45
  FOUNDRY_CONVERSATION_LEASE_EVENT,
45
46
  FOUNDRY_CONVERSATION_LISTEN_EVENT,
@@ -63,7 +64,7 @@ import {
63
64
  workerAgentId,
64
65
  writeConversationLease,
65
66
  writeMailboxDelivery
66
- } from "./chunk-J6NHL4SM.js";
67
+ } from "./chunk-2JCISE2U.js";
67
68
  import {
68
69
  EMPTY_CAPABILITY_REGISTRY,
69
70
  EMPTY_NATIVE_REGISTRY,
@@ -96,7 +97,7 @@ import {
96
97
  messageOptionsSchema,
97
98
  monitorFoundryCoreCommandRequest,
98
99
  settleFoundryCoreCommandRequest
99
- } from "./chunk-CYOIHSUX.js";
100
+ } from "./chunk-NWFOY3L7.js";
100
101
 
101
102
  // src/codegen.ts
102
103
  import { mkdir, writeFile } from "node:fs/promises";
@@ -1788,6 +1789,8 @@ var FoundryRuntime = class _FoundryRuntime {
1788
1789
  });
1789
1790
  /** Pending inbound records each run is handling, so they are cleared when it settles. */
1790
1791
  eventTimers = /* @__PURE__ */ new Map();
1792
+ /** Events a run withheld because preparing them failed: attempts so far and the pending retry. */
1793
+ eventRetries = /* @__PURE__ */ new Map();
1791
1794
  completedEventRuns = /* @__PURE__ */ new Map();
1792
1795
  pendingInboundByRun = /* @__PURE__ */ new Map();
1793
1796
  /** Recently settled runs, for a record assigned to a run that already finished. */
@@ -2076,6 +2079,8 @@ var FoundryRuntime = class _FoundryRuntime {
2076
2079
  this.stopping = true;
2077
2080
  for (const timer of this.eventTimers.values()) clearTimeout(timer);
2078
2081
  this.eventTimers.clear();
2082
+ for (const retry of this.eventRetries.values()) if (retry.timer) clearTimeout(retry.timer);
2083
+ this.eventRetries.clear();
2079
2084
  for (const timer of this.activationTimers.values()) clearTimeout(timer);
2080
2085
  this.activationTimers.clear();
2081
2086
  this.activationDispatches.clear();
@@ -4127,6 +4132,49 @@ var FoundryRuntime = class _FoundryRuntime {
4127
4132
  await Effect5.runPromise(this.data.putEvent({ ...record, runId, ...acknowledged ? { status: "acknowledged" } : {} }));
4128
4133
  }
4129
4134
  }
4135
+ /**
4136
+ * Deliver events again after a delay that doubles each time (1s up to 5
4137
+ * minutes), when a run withheld them because preparing them failed. They
4138
+ * stay pending meanwhile; a restart delivers them as usual.
4139
+ */
4140
+ scheduleEventRetries(ids) {
4141
+ if (this.stopping) return;
4142
+ for (const id2 of ids) {
4143
+ const retry = this.eventRetries.get(id2) ?? { attempts: 0 };
4144
+ if (retry.timer) continue;
4145
+ retry.attempts++;
4146
+ const delay = Math.min(1e3 * 2 ** (retry.attempts - 1), 3e5);
4147
+ retry.timer = setTimeout(() => {
4148
+ retry.timer = void 0;
4149
+ void this.retryEvent(id2).catch((cause) => this.reportDeliveryFailure("event-retry", cause));
4150
+ }, delay);
4151
+ retry.timer.unref?.();
4152
+ this.eventRetries.set(id2, retry);
4153
+ }
4154
+ }
4155
+ async retryEvent(id2) {
4156
+ if (this.stopping || !this.data.listEvents) return;
4157
+ const record = (await Effect5.runPromise(this.data.listEvents())).find((item) => item.id === id2);
4158
+ if (!record || record.status !== "pending") {
4159
+ this.eventRetries.delete(id2);
4160
+ return;
4161
+ }
4162
+ const owner = await Effect5.runPromise(this.data.getAgent(record.target.agentId));
4163
+ if (!owner) {
4164
+ this.eventRetries.delete(id2);
4165
+ return;
4166
+ }
4167
+ try {
4168
+ await this.assertDurableActive(owner);
4169
+ } catch {
4170
+ return;
4171
+ }
4172
+ await this.deliver(
4173
+ { ...record.target, definitionId: record.definitionId, workspaceId: record.workspaceId },
4174
+ [{ ...record.delivery, durable: { id: record.id, event: record.event, policy: record.policy } }],
4175
+ true
4176
+ );
4177
+ }
4130
4178
  async finishEvents(runId, consumed) {
4131
4179
  if (!this.data.listEvents || !this.data.putEvent || this.stopping) return;
4132
4180
  const run = await this.getRun(runId);
@@ -4143,6 +4191,9 @@ var FoundryRuntime = class _FoundryRuntime {
4143
4191
  continue;
4144
4192
  }
4145
4193
  await Effect5.runPromise(this.data.putEvent({ ...record, status: record.event.expiresAt && Date.parse(record.event.expiresAt) <= Date.now() ? "expired" : "acknowledged", runId }));
4194
+ const retry = this.eventRetries.get(record.id);
4195
+ if (retry?.timer) clearTimeout(retry.timer);
4196
+ this.eventRetries.delete(record.id);
4146
4197
  if ((record.delivery.kind === "transmission" || record.delivery.kind === "agent-message") && this.data.deletePendingInbound) {
4147
4198
  await Effect5.runPromise(this.data.deletePendingInbound(record.delivery.pendingId));
4148
4199
  }
@@ -4857,6 +4908,7 @@ var FoundryRuntime = class _FoundryRuntime {
4857
4908
  if (event.status === "completed") {
4858
4909
  const result = parseJson(event.output);
4859
4910
  await this.finishEvents(event.run.id, result?.consumedEventIds ?? []);
4911
+ if (result?.retryEventIds?.length) this.scheduleEventRetries(result.retryEventIds);
4860
4912
  }
4861
4913
  await this.finishPendingInbound(event.run.id).catch((cause) => this.reportDeliveryFailure(this.toFoundryRun(event.run).conversationId ?? "settle", cause));
4862
4914
  };
@@ -5425,9 +5477,10 @@ var FoundryRuntime = class _FoundryRuntime {
5425
5477
  if (activation.timing.kind === "at" && Number.isNaN(new Date(activation.timing.at).getTime())) {
5426
5478
  throw new Error(`Activation "${activation.id}" has an invalid wake time.`);
5427
5479
  }
5428
- const revision = activationScheduleRevision(activation);
5429
5480
  const now = /* @__PURE__ */ new Date();
5430
- const resumes = activation.scheduleRevision === revision;
5481
+ const stored = activation.scheduleRevision;
5482
+ const resumes = stored !== void 0 && scheduleRevisionMatches(activation, stored);
5483
+ const revision = resumes ? stored : activationScheduleRevision(activation);
5431
5484
  const cursor = resumes ? activation.nextOccurrenceAt : firstScheduledTime(activation.timing, now).toISOString();
5432
5485
  const { nextOccurrenceAt: _previous, ...rest } = activation;
5433
5486
  const active = {
@@ -5672,7 +5725,7 @@ var FoundryRuntime = class _FoundryRuntime {
5672
5725
  if (this.occurrencesInHand.has(occurrence.id)) continue;
5673
5726
  if (occurrence.runId && await this.signalRunner.getRun(occurrence.runId)) continue;
5674
5727
  const activation = await Effect5.runPromise(this.data.getActivation(occurrence.activationId));
5675
- const reason = !activation || activation.status === "cancelled" || activation.status === "completed" ? "cancelled" : activation.status === "paused" ? "paused" : activationScheduleRevision(activation) !== occurrence.revision ? "superseded" : void 0;
5728
+ const reason = !activation || activation.status === "cancelled" || activation.status === "completed" ? "cancelled" : activation.status === "paused" ? "paused" : !scheduleRevisionMatches(activation, occurrence.revision) ? "superseded" : void 0;
5676
5729
  if (reason) {
5677
5730
  const now = (/* @__PURE__ */ new Date()).toISOString();
5678
5731
  await this.putOccurrence({ ...occurrence, status: "cancelled", reason, updatedAt: now, settledAt: now });
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  FoundryRuntime,
4
4
  FoundryServer,
5
5
  writeGeneratedTypes
6
- } from "./chunk-PMNRLJIQ.js";
6
+ } from "./chunk-YCW66WKQ.js";
7
7
  import {
8
8
  DEFAULT_FOUNDRY_CONFIG
9
9
  } from "./chunk-ZFNMFE3T.js";
@@ -11,9 +11,9 @@ import "./chunk-J7ZBJM54.js";
11
11
  import {
12
12
  EMPTY_FOUNDRY_APPLICATION,
13
13
  isFoundryApplication
14
- } from "./chunk-T6YLIGER.js";
15
- import "./chunk-J6NHL4SM.js";
16
- import "./chunk-CYOIHSUX.js";
14
+ } from "./chunk-4WBQ7XVF.js";
15
+ import "./chunk-2JCISE2U.js";
16
+ import "./chunk-NWFOY3L7.js";
17
17
 
18
18
  // src/cli.ts
19
19
  import { watch } from "node:fs";
@@ -1,5 +1,5 @@
1
1
  import { StoreAdapter, AgentEvent, Message, TokenConsumptionCounter } from 'glove-core';
2
- import { x as AccountId, o as AccountReference, y as AccountNotFound, d1 as TransmissionId, cV as RouteId, cU as Route, cW as RouteNotFound, c_ as TopologyConflict, a3 as BindingId, q as AgentBinding, a4 as BindingNotFound, Q as AgentId, ax as EventReference, av as EventId, aw as EventNotFound, cY as RunId, z as AccountSessionUnavailable, b as FoundryDataAdapter, bB as FoundryInstanceProvisioner, j as FoundryApproval, a$ as FoundryAgentDefinition, cX as RunGrant, cx as GrantResolutionError, n as AnyFoundryTransmission, bg as FoundryCapabilityRegistry, bZ as FoundryNativeRegistry, c5 as FoundryRequest, a9 as CreateAgentInstanceOptions, c as AgentInstance, bV as FoundryMessageOptions, V as AgentMessageReceipt, br as FoundryEventTarget, bq as FoundryEventPolicy, C as Conversation, f as FoundryEventRecord, d as FoundryActivationRecord, i as FoundryPendingInbound, l as FoundryTask, S as SharedInboxItem, aa as CreateConversationOptions, m as AgentPlaybook, P as PlaybookSubscription, al as DefinePlaybookSubscriptionOptions, a1 as ApplicationConnectionState, d5 as UpdateAgentInstanceOptions, d6 as UpdateConversationOptions, W as WorkspaceEntry, E as EnvironmentValue, bU as FoundryMessageInput, c8 as FoundryResult, b9 as FoundryApprovalStatus, b6 as FoundryApprovalDecision, be as FoundryCapabilityManifest, bX as FoundryNativeManifest, T as AgentInstallation, bo as FoundryDelegationStatus, bm as FoundryDelegation, bT as FoundryMeshThreadStatus, bS as FoundryMeshThread, h as FoundryScheduleOccurrenceFilter, g as FoundryScheduleOccurrence, c9 as FoundryRouteMap, B as AccountSummary, _ as AnyFoundryAgent } from './event-delivery-a9B1Qq_u.js';
2
+ import { B as AccountId, r as AccountReference, D as AccountNotFound, d8 as TransmissionId, d0 as RouteId, c$ as Route, d1 as RouteNotFound, d5 as TopologyConflict, a6 as BindingId, t as AgentBinding, a7 as BindingNotFound, U as AgentId, aB as EventReference, ay as EventId, az as EventNotFound, d3 as RunId, G as AccountSessionUnavailable, d as FoundryDataAdapter, bI as FoundryInstanceProvisioner, m as FoundryApproval, b3 as FoundryAgentDefinition, d2 as RunGrant, cE as GrantResolutionError, q as AnyFoundryTransmission, bk as FoundryCapabilityRegistry, c4 as FoundryNativeRegistry, cc as FoundryRequest, ac as CreateAgentInstanceOptions, e as AgentInstance, c0 as FoundryMessageOptions, Z as AgentMessageReceipt, bx as FoundryEventTarget, bu as FoundryEventPolicy, C as Conversation, h as FoundryEventRecord, f as FoundryActivationRecord, l as FoundryPendingInbound, o as FoundryTask, S as SharedInboxItem, ad as CreateConversationOptions, p as AgentPlaybook, P as PlaybookSubscription, ao as DefinePlaybookSubscriptionOptions, a4 as ApplicationConnectionState, dc as UpdateAgentInstanceOptions, dd as UpdateConversationOptions, W as WorkspaceEntry, E as EnvironmentValue, b$ as FoundryMessageInput, cf as FoundryResult, bd as FoundryApprovalStatus, ba as FoundryApprovalDecision, bi as FoundryCapabilityManifest, c2 as FoundryNativeManifest, X as AgentInstallation, bs as FoundryDelegationStatus, bq as FoundryDelegation, b_ as FoundryMeshThreadStatus, bZ as FoundryMeshThread, k as FoundryScheduleOccurrenceFilter, j as FoundryScheduleOccurrence, cg as FoundryRouteMap, H as AccountSummary, a1 as AnyFoundryAgent } from './event-delivery-BfSL9sGo.js';
3
3
  import * as effect_Brand from 'effect/Brand';
4
4
  import { Context, Effect, Layer, Schema } from 'effect';
5
5
  import { FoundryStationDaemonAdapter } from './station.js';
@@ -456,6 +456,8 @@ declare class FoundryRuntime {
456
456
  private readonly gate;
457
457
  /** Pending inbound records each run is handling, so they are cleared when it settles. */
458
458
  private readonly eventTimers;
459
+ /** Events a run withheld because preparing them failed: attempts so far and the pending retry. */
460
+ private readonly eventRetries;
459
461
  private readonly completedEventRuns;
460
462
  private readonly pendingInboundByRun;
461
463
  /** Recently settled runs, for a record assigned to a run that already finished. */
@@ -727,6 +729,13 @@ declare class FoundryRuntime {
727
729
  /** Start one run with everything held for a conversation, once nothing else holds it. */
728
730
  private flushHeldDeliveries;
729
731
  private markHandedOver;
732
+ /**
733
+ * Deliver events again after a delay that doubles each time (1s up to 5
734
+ * minutes), when a run withheld them because preparing them failed. They
735
+ * stay pending meanwhile; a restart delivers them as usual.
736
+ */
737
+ private scheduleEventRetries;
738
+ private retryEvent;
730
739
  private finishEvents;
731
740
  private redeliverEvents;
732
741
  /** Clear the bookkeeping that lets a restart hand these deliveries over again. */
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'glove-core';
2
- import './event-delivery-a9B1Qq_u.js';
3
- export { k as FoundryClient, l as FoundryClientAuthorizationAdapter, m as FoundryClientOptions, q as FoundryHealth, y as FoundryRunHandle, G as FoundrySteerHandleResult, W as WaitOptions, N as createFoundryClient } from './client-Cj2wDXuc.js';
2
+ import './event-delivery-BfSL9sGo.js';
3
+ export { k as FoundryClient, l as FoundryClientAuthorizationAdapter, m as FoundryClientOptions, q as FoundryHealth, y as FoundryRunHandle, G as FoundrySteerHandleResult, W as WaitOptions, N as createFoundryClient } from './client-B4Emyeek.js';
4
4
  import 'effect';
5
5
  import 'zod';
6
6
  import 'glove-mesh';