@effect-agent/platform-cloudflare 0.1.0-beta.94 → 0.1.0-beta.96

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.
@@ -1,5 +1,5 @@
1
1
  import { ThreadObjectNamespace, ThreadObjectRpc } from "./CloudflareBindings.mjs";
2
- import { t as AdmissionLimitExceeded } from "./CloudflareConfig-f3CqTel1.mjs";
2
+ import { t as AdmissionLimitExceeded } from "./CloudflareConfig-DKXGo8L3.mjs";
3
3
  import { DurableAlarmError } from "./Alarm.mjs";
4
4
  import { Context, Crypto, Effect, Layer, Schema } from "effect";
5
5
  import { DurableSubmitAgent, DurableSubmitOptions, Receipt } from "effect-agent/durable-agent-runtime";
@@ -264,6 +264,12 @@ declare const encodeSubmitRequest: (input: SubmitRequest, options?: import("effe
264
264
  readonly agent: string;
265
265
  readonly model: string;
266
266
  readonly tools: string;
267
+ readonly replay?: {
268
+ readonly agent: string;
269
+ readonly tools: {
270
+ readonly [x: string]: string;
271
+ };
272
+ } | undefined;
267
273
  };
268
274
  readonly policy: Schema.Json;
269
275
  readonly budget: {
@@ -305,6 +311,12 @@ declare const encodeSubmitRequest: (input: SubmitRequest, options?: import("effe
305
311
  readonly agent: string;
306
312
  readonly model: string;
307
313
  readonly tools: string;
314
+ readonly replay?: {
315
+ readonly agent: string;
316
+ readonly tools: {
317
+ readonly [x: string]: string;
318
+ };
319
+ } | undefined;
308
320
  };
309
321
  readonly destinationDelegationId?: string | undefined;
310
322
  } | undefined;
@@ -409,6 +421,12 @@ declare const encodeSubmitRequest: (input: SubmitRequest, options?: import("effe
409
421
  readonly agent: string;
410
422
  readonly model: string;
411
423
  readonly tools: string;
424
+ readonly replay?: {
425
+ readonly agent: string;
426
+ readonly tools: {
427
+ readonly [x: string]: string;
428
+ };
429
+ } | undefined;
412
430
  };
413
431
  readonly inputPayload: Schema.Json;
414
432
  }, Schema.SchemaError, never>;
@@ -454,13 +472,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
454
472
  readonly author: string;
455
473
  readonly reason: string;
456
474
  readonly resolution: {
475
+ readonly _tag: "SafeToRetry";
476
+ } | {
457
477
  readonly _tag: "CompletedWithResult";
458
478
  readonly result: Schema.Json;
459
479
  readonly isFailure: boolean;
460
480
  } | {
461
481
  readonly _tag: "NeverHappened";
462
- } | {
463
- readonly _tag: "SafeToRetry";
464
482
  } | {
465
483
  readonly _tag: "AbortSubmission";
466
484
  };
@@ -596,12 +614,23 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
596
614
  readonly createdAt: string;
597
615
  readonly deploymentId: string;
598
616
  readonly payload: {
617
+ readonly _tag: "AbortRequested";
618
+ readonly submissionId: string;
619
+ readonly author: string;
620
+ readonly reason: string;
621
+ } | {
599
622
  readonly _tag: "ThreadCreated";
600
623
  readonly agentId: string;
601
624
  readonly definitions: {
602
625
  readonly agent: string;
603
626
  readonly model: string;
604
627
  readonly tools: string;
628
+ readonly replay?: {
629
+ readonly agent: string;
630
+ readonly tools: {
631
+ readonly [x: string]: string;
632
+ };
633
+ } | undefined;
605
634
  };
606
635
  } | {
607
636
  readonly _tag: "UserInputRecorded";
@@ -703,6 +732,9 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
703
732
  readonly runId: string;
704
733
  readonly policyAccountingVersion: 1;
705
734
  readonly maxDurationMillis: number;
735
+ } | {
736
+ readonly _tag: "RunDurationExhausted";
737
+ readonly runId: string;
706
738
  } | {
707
739
  readonly _tag: "RunPolicyUsageReserved";
708
740
  readonly runId: string;
@@ -853,11 +885,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
853
885
  readonly runDisposition?: Schema.Json | undefined;
854
886
  readonly finishReason?: "budget-exhausted" | undefined;
855
887
  readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
856
- } | {
857
- readonly _tag: "AbortRequested";
858
- readonly submissionId: string;
859
- readonly author: string;
860
- readonly reason: string;
861
888
  } | {
862
889
  readonly _tag: "SubmissionSettled";
863
890
  readonly submissionId: string;
@@ -945,6 +972,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
945
972
  readonly agent: string;
946
973
  readonly model: string;
947
974
  readonly tools: string;
975
+ readonly replay?: {
976
+ readonly agent: string;
977
+ readonly tools: {
978
+ readonly [x: string]: string;
979
+ };
980
+ } | undefined;
948
981
  };
949
982
  readonly childInput: Schema.Json;
950
983
  readonly childInputDigest: string;
@@ -1038,6 +1071,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1038
1071
  readonly agent: string;
1039
1072
  readonly model: string;
1040
1073
  readonly tools: string;
1074
+ readonly replay?: {
1075
+ readonly agent: string;
1076
+ readonly tools: {
1077
+ readonly [x: string]: string;
1078
+ };
1079
+ } | undefined;
1041
1080
  };
1042
1081
  readonly childInputDigest: string;
1043
1082
  readonly grantDigest: string;
@@ -1097,6 +1136,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1097
1136
  readonly agent: string;
1098
1137
  readonly model: string;
1099
1138
  readonly tools: string;
1139
+ readonly replay?: {
1140
+ readonly agent: string;
1141
+ readonly tools: {
1142
+ readonly [x: string]: string;
1143
+ };
1144
+ } | undefined;
1100
1145
  };
1101
1146
  readonly policy: Schema.Json;
1102
1147
  readonly budget: {
@@ -1138,6 +1183,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1138
1183
  readonly agent: string;
1139
1184
  readonly model: string;
1140
1185
  readonly tools: string;
1186
+ readonly replay?: {
1187
+ readonly agent: string;
1188
+ readonly tools: {
1189
+ readonly [x: string]: string;
1190
+ };
1191
+ } | undefined;
1141
1192
  };
1142
1193
  readonly destinationDelegationId?: string | undefined;
1143
1194
  } | undefined;
@@ -1175,6 +1226,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1175
1226
  readonly agent: string;
1176
1227
  readonly model: string;
1177
1228
  readonly tools: string;
1229
+ readonly replay?: {
1230
+ readonly agent: string;
1231
+ readonly tools: {
1232
+ readonly [x: string]: string;
1233
+ };
1234
+ } | undefined;
1178
1235
  };
1179
1236
  readonly policy: Schema.Json;
1180
1237
  readonly budget: {
@@ -1216,6 +1273,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1216
1273
  readonly agent: string;
1217
1274
  readonly model: string;
1218
1275
  readonly tools: string;
1276
+ readonly replay?: {
1277
+ readonly agent: string;
1278
+ readonly tools: {
1279
+ readonly [x: string]: string;
1280
+ };
1281
+ } | undefined;
1219
1282
  };
1220
1283
  readonly destinationDelegationId?: string | undefined;
1221
1284
  } | undefined;
@@ -1251,6 +1314,12 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1251
1314
  readonly agent: string;
1252
1315
  readonly model: string;
1253
1316
  readonly tools: string;
1317
+ readonly replay?: {
1318
+ readonly agent: string;
1319
+ readonly tools: {
1320
+ readonly [x: string]: string;
1321
+ };
1322
+ } | undefined;
1254
1323
  };
1255
1324
  readonly delivery?: {
1256
1325
  readonly messageId: string;
@@ -1346,13 +1415,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1346
1415
  readonly author: string;
1347
1416
  readonly reason: string;
1348
1417
  readonly resolution: {
1418
+ readonly _tag: "SafeToRetry";
1419
+ } | {
1349
1420
  readonly _tag: "CompletedWithResult";
1350
1421
  readonly result: Schema.Json;
1351
1422
  readonly isFailure: boolean;
1352
1423
  } | {
1353
1424
  readonly _tag: "NeverHappened";
1354
- } | {
1355
- readonly _tag: "SafeToRetry";
1356
1425
  } | {
1357
1426
  readonly _tag: "AbortSubmission";
1358
1427
  };
@@ -1362,20 +1431,10 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1362
1431
  } | {
1363
1432
  readonly _tag: "HostFailed";
1364
1433
  readonly failure: {
1365
- readonly _tag: "HostProtocolError";
1366
- readonly message: string;
1367
- } | {
1368
1434
  readonly _tag: "DurableAlarmError";
1369
1435
  readonly operation: string;
1370
1436
  readonly message: string;
1371
1437
  readonly cause?: Schema.Json | undefined;
1372
- } | {
1373
- readonly _tag: "AgentInputError";
1374
- readonly message: string;
1375
- } | {
1376
- readonly _tag: "DigestError";
1377
- readonly message: string;
1378
- readonly cause?: Schema.Json | undefined;
1379
1438
  } | {
1380
1439
  readonly _tag: "AdmissionConflict";
1381
1440
  readonly threadId: string;
@@ -1391,15 +1450,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1391
1450
  readonly _tag: "SettlementConflict";
1392
1451
  readonly submissionId: string;
1393
1452
  readonly existingOutcome: "aborted" | "completed" | "failed";
1394
- } | {
1395
- readonly _tag: "ApprovalConflict";
1396
- readonly submissionId: string;
1397
- readonly toolCallId: string;
1398
- readonly existingDecision: "approved" | "denied";
1399
- } | {
1400
- readonly _tag: "UnknownResolutionConflict";
1401
- readonly submissionId: string;
1402
- readonly toolCallId: string;
1403
1453
  } | {
1404
1454
  readonly _tag: "JoinedToHost";
1405
1455
  readonly submissionId: string;
@@ -1429,9 +1479,28 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1429
1479
  readonly threadId: string;
1430
1480
  readonly actualEpoch: number;
1431
1481
  readonly attemptedEpoch: number;
1482
+ } | {
1483
+ readonly _tag: "HostProtocolError";
1484
+ readonly message: string;
1485
+ } | {
1486
+ readonly _tag: "AgentInputError";
1487
+ readonly message: string;
1488
+ } | {
1489
+ readonly _tag: "DigestError";
1490
+ readonly message: string;
1491
+ readonly cause?: Schema.Json | undefined;
1492
+ } | {
1493
+ readonly _tag: "ApprovalConflict";
1494
+ readonly submissionId: string;
1495
+ readonly toolCallId: string;
1496
+ readonly existingDecision: "approved" | "denied";
1497
+ } | {
1498
+ readonly _tag: "UnknownResolutionConflict";
1499
+ readonly submissionId: string;
1500
+ readonly toolCallId: string;
1432
1501
  } | {
1433
1502
  readonly _tag: "DurableRuntimeFailpointError";
1434
- readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "checkpoint:after-save" | "checkpoint:before-save" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-start-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "subagent:before-join-append" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:before-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append" | "update:after-canonical-append" | "update:after-delivery-insert" | "update:before-canonical-append" | "update:before-delivery-insert" | "worker:after-completion-append" | "worker:after-origin-append" | "worker:after-report-append" | "worker:after-report-delivery" | "worker:after-source-append" | "worker:after-subtree-append" | "worker:before-completion-append" | "worker:before-origin-append" | "worker:before-report-append" | "worker:before-report-delivery" | "worker:before-source-append" | "worker:before-subtree-append";
1503
+ readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "checkpoint:after-save" | "checkpoint:before-save" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-duration-append" | "run:after-start-append" | "run:before-duration-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "subagent:before-join-append" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:before-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append" | "update:after-canonical-append" | "update:after-delivery-insert" | "update:before-canonical-append" | "update:before-delivery-insert" | "worker:after-completion-append" | "worker:after-origin-append" | "worker:after-report-append" | "worker:after-report-delivery" | "worker:after-source-append" | "worker:after-subtree-append" | "worker:before-completion-append" | "worker:before-origin-append" | "worker:before-report-append" | "worker:before-report-delivery" | "worker:before-source-append" | "worker:before-subtree-append";
1435
1504
  } | {
1436
1505
  readonly _tag: "AdmissionLimitExceeded";
1437
1506
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
@@ -5,7 +5,7 @@ import { DurableAlarmError, DurableAlarmService, ThreadMaintenance, ThreadMainte
5
5
  import { AbortRecorded, ApprovalRecorded, CloudflareThreadClient, HostFailed, HostProtocolError, ObservedPage, ProgressCancelled, ProgressObserved, SettlementReached, SubmissionStatusResponse, SubmitSucceeded, UnknownResolutionRecorded, boundHostDiagnostic, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, encodeHostResponse } from "./CloudflareThreadClient.mjs";
6
6
  import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-DU0_T-ev.mjs";
7
7
  import { cloudflareWakeSchedulerLayer } from "./WakeScheduler.mjs";
8
- import { Cause, Clock, Context, Deferred, Duration, Effect, Layer, Option, Ref, Schema, Semaphore, Stream } from "effect";
8
+ import { Cause, Clock, Context, DateTime, Deferred, Duration, Effect, Fiber, Layer, Option, Ref, Schema, Semaphore, Stream } from "effect";
9
9
  import { compileRegistrations } from "effect-agent/agent-registration";
10
10
  import { DurableAgentRuntime, DurableRuntimeConfig, RecoveryReport } from "effect-agent/durable-agent-runtime";
11
11
  import { SubmissionId, ThreadId } from "effect-agent/identifiers";
@@ -75,27 +75,44 @@ const guardedMessageDeliveryStoreLayer = Layer.effect(MessageDeliveryStore, Effe
75
75
  const threadMessageDeliveryLayer = Layer.effectContext(Effect.gen(function* () {
76
76
  const driver = yield* MessageDeliveryDriver;
77
77
  const store = yield* MessageDeliveryStore;
78
- const wakes = yield* WakeScheduler;
79
- const config = yield* CloudflareDurableRuntimeConfig;
80
78
  const failure = (operation) => () => DurableAlarmError.make({
81
79
  operation,
82
80
  message: "Durable message recovery remains pending"
83
81
  });
84
- const drain = Effect.gen(function* () {
82
+ const wakes = yield* WakeScheduler;
83
+ const prepare = Effect.gen(function* () {
85
84
  const deadline = yield* store.nextDeadline();
86
- if (deadline !== null && deadline <= (yield* Clock.currentTimeMillis)) yield* driver.runDue();
87
- }).pipe(Effect.mapError(failure("drain message delivery")));
85
+ if (deadline === null || deadline > (yield* Clock.currentTimeMillis)) return {
86
+ timeoutMillis: 1,
87
+ run: Effect.void
88
+ };
89
+ const keys = yield* store.due(yield* Clock.currentTimeMillis, 4);
90
+ const records = yield* Effect.forEach(keys, (key) => store.get(key));
91
+ return {
92
+ timeoutMillis: Math.max(1, ...records.map((record) => record?.policy.attemptTimeoutMillis ?? 1)),
93
+ run: Effect.forEach(keys, (key) => driver.process(key), {
94
+ concurrency: 4,
95
+ discard: true
96
+ }).pipe(Effect.mapError(failure("dispatch message delivery")))
97
+ };
98
+ }).pipe(Effect.mapError(failure("prepare message delivery")));
88
99
  return Context.make(ThreadMessageDelivery, {
89
- drain,
90
- drainUntil: Effect.fn("ThreadMessageDelivery.drainUntil")(function* (finished) {
100
+ drainUntil: (sourceFinished, dispatchUntil) => Effect.gen(function* () {
91
101
  const notified = (yield* Stream.toPull(wakes.wakes)).pipe(Effect.catch(() => Effect.never));
92
- yield* Effect.gen(function* () {
93
- yield* drain;
94
- const deadline = yield* store.nextDeadline().pipe(Effect.mapError(failure("read message deadline")));
95
- const delay = deadline === null ? config.wakeScanInterval : Math.min(config.wakeScanInterval, Math.max(1, deadline - (yield* Clock.currentTimeMillis)));
96
- yield* Effect.raceFirst(Deferred.await(finished), Effect.raceFirst(notified, Effect.sleep(delay)));
97
- }).pipe(Effect.repeat({ until: () => Deferred.isDone(finished) }));
98
- }, Effect.scoped),
102
+ const done = yield* Effect.forkScoped(sourceFinished);
103
+ const select = (initial = false) => Effect.gen(function* () {
104
+ const wave = yield* prepare;
105
+ const now = yield* Clock.currentTimeMillis;
106
+ if (!initial && done.pollUnsafe() !== void 0 || now + wave.timeoutMillis > DateTime.toEpochMillis(dispatchUntil)) return;
107
+ yield* wave.run;
108
+ });
109
+ yield* select(true);
110
+ while (done.pollUnsafe() === void 0) {
111
+ const wake = yield* Effect.raceFirst(notified.pipe(Effect.map(Option.some)), Fiber.join(done).pipe(Effect.as(Option.none())));
112
+ if (Option.isNone(wake)) return;
113
+ yield* Effect.forEach(wake.value, () => select(), { discard: true });
114
+ }
115
+ }),
99
116
  pendingDeadline: store.nextDeadline().pipe(Effect.map(Option.fromNullishOr), Effect.mapError(failure("read message deadline")))
100
117
  });
101
118
  }));
@@ -203,6 +220,7 @@ const configFromOptions = (options) => decodeConfigValue({
203
220
  leaseRenewalInterval: options.leaseRenewalInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.leaseRenewalInterval,
204
221
  abortPollInterval: options.abortPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.abortPollInterval,
205
222
  observationPollInterval: options.observationPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.observationPollInterval,
223
+ projectionDispatchTimeoutMillis: options.projectionDispatchTimeoutMillis ?? CLOUDFLARE_RUNTIME_DEFAULTS.projectionDispatchTimeoutMillis,
206
224
  maxStoredValueBytes: options.maxStoredValueBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxStoredValueBytes,
207
225
  verifyOnOpen: options.verifyOnOpen ?? CLOUDFLARE_RUNTIME_DEFAULTS.verifyOnOpen,
208
226
  limits: {
@@ -832,4 +850,4 @@ const make = (applicationLayer, options) => {
832
850
  //#endregion
833
851
  export { layer as C, layerInHost as E, ThreadObjectPorts as S, layerHostConfig as T, encodeAdminResponse as _, AdminVerifyRequest as a, portCall as b, RetryExecuted as c, VerifiedIntegrity as d, decodeAdminExplainRequest as f, decodeRetryCommand as g, decodeObligationThresholds as h, AdminResponse as i, ThreadObject_exports as l, decodeAdminVerifyRequest as m, AdminFailed as n, ExplainedRecovery as o, decodeAdminResponse as p, AdminFailure as r, ObligationsScanned as s, AdminExplainRequest as t, ThreadRpcOperation as u, handleRpc as v, layerConfig as w, submit as x, make as y };
834
852
 
835
- //# sourceMappingURL=ThreadObject-DvRG0dDz.mjs.map
853
+ //# sourceMappingURL=ThreadObject-DXavwaU-.mjs.map