@yielded/agent-platform-cloudflare 0.1.0-beta.182 → 0.1.0-beta.185

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.
Files changed (49) hide show
  1. package/dist/{BrowserCredentials-C5IWfi7f.d.mts → BrowserCredentials-C2rBhlUI.d.mts} +30 -5
  2. package/dist/BrowserCredentials.d.mts +2 -2
  3. package/dist/BrowserCredentials.mjs +28 -8
  4. package/dist/BrowserCredentials.mjs.map +1 -1
  5. package/dist/{BrowserSession-aovMjfL4.mjs → BrowserSession-CfivQ5JY.mjs} +150 -65
  6. package/dist/BrowserSession-CfivQ5JY.mjs.map +1 -0
  7. package/dist/{BrowserSession-Cojp7nth.d.mts → BrowserSession-mKnLSc3p.d.mts} +8 -2
  8. package/dist/BrowserSession.d.mts +1 -1
  9. package/dist/BrowserSession.mjs +2 -2
  10. package/dist/BrowserUse.d.mts +1 -1
  11. package/dist/BrowserUse.mjs +31 -4
  12. package/dist/BrowserUse.mjs.map +1 -1
  13. package/dist/CloudflareBindings.d.mts +6 -2
  14. package/dist/CloudflareBindings.mjs.map +1 -1
  15. package/dist/CloudflareScheduling.mjs +2 -2
  16. package/dist/CloudflareSubscriptions.mjs +2 -2
  17. package/dist/{CloudflareThreadClient-B9ODixhk.d.mts → CloudflareThreadClient-CmlojpjC.d.mts} +205 -199
  18. package/dist/{CloudflareThreadClient-CEUjVwis.mjs → CloudflareThreadClient-CnvMXPmV.mjs} +17 -6
  19. package/dist/CloudflareThreadClient-CnvMXPmV.mjs.map +1 -0
  20. package/dist/CloudflareThreadClient.d.mts +1 -1
  21. package/dist/CloudflareThreadClient.mjs +1 -1
  22. package/dist/{InteractiveBrowser-BHNlwjZL.mjs → InteractiveBrowser-nukKxc87.mjs} +4 -45
  23. package/dist/InteractiveBrowser-nukKxc87.mjs.map +1 -0
  24. package/dist/InteractiveBrowser.mjs +1 -1
  25. package/dist/{ThreadObject-vmc0jRTS.mjs → ThreadObject-Cr1CFWXb.mjs} +98 -60
  26. package/dist/ThreadObject-Cr1CFWXb.mjs.map +1 -0
  27. package/dist/{ThreadObject-wS46Yxq3.d.mts → ThreadObject-Osn-FmcF.d.mts} +3 -3
  28. package/dist/ThreadObject.d.mts +1 -1
  29. package/dist/ThreadObject.mjs +1 -1
  30. package/dist/browser-failure-DECzRY3H.mjs +50 -0
  31. package/dist/browser-failure-DECzRY3H.mjs.map +1 -0
  32. package/dist/index.d.mts +4 -4
  33. package/dist/index.mjs +3 -3
  34. package/dist/{prepared-admission-C3uBqIz0.mjs → prepared-admission-w2Kq32_k.mjs} +2 -2
  35. package/dist/{prepared-admission-C3uBqIz0.mjs.map → prepared-admission-w2Kq32_k.mjs.map} +1 -1
  36. package/package.json +1 -1
  37. package/src/BrowserCredentials.ts +42 -9
  38. package/src/BrowserSession.ts +88 -8
  39. package/src/BrowserUse.ts +51 -4
  40. package/src/CloudflareBindings.ts +6 -2
  41. package/src/CloudflareThreadClient.ts +18 -4
  42. package/src/internal/browser-credentials.ts +205 -98
  43. package/src/internal/browser-failure.ts +3 -0
  44. package/src/internal/live-text-protocol.ts +7 -0
  45. package/src/internal/live-text.ts +129 -91
  46. package/dist/BrowserSession-aovMjfL4.mjs.map +0 -1
  47. package/dist/CloudflareThreadClient-CEUjVwis.mjs.map +0 -1
  48. package/dist/InteractiveBrowser-BHNlwjZL.mjs.map +0 -1
  49. package/dist/ThreadObject-vmc0jRTS.mjs.map +0 -1
@@ -4,6 +4,7 @@ import { DurableSubmitAgent, DurableSubmitOptions } from "@yielded/agent/durable
4
4
  import { ThreadId } from "@yielded/agent/identifiers";
5
5
  import { AbortCommand, AbortIntent, AdmissionConflict, AdmissionPolicyError, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, JoinedToHost, LedgerError, OwnershipLost, Settlement, SettlementConflict, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent } from "@yielded/agent/submission-ledger";
6
6
  import { Context, Crypto, Effect, Layer, Schema, Stream } from "effect";
7
+ import { Rpc } from "effect-cf";
7
8
  import { CanonicalRecordEnvelope, CanonicalSequence, DefinitionDigests, SubmissionSettledRecord } from "@yielded/agent/records";
8
9
  import { AgentInputError } from "@yielded/agent/agent-error";
9
10
  import { DigestError } from "@yielded/agent/digest";
@@ -14,6 +15,11 @@ import { SubmissionStatus } from "@yielded/agent/submission-status";
14
15
  import { AppendConflict, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
15
16
  import { Event } from "@yielded/agent/provisional-text";
16
17
  //#region src/internal/live-text-protocol.d.ts
18
+ /** The RPC lifetime survives an idle byte stream and is disposed on caller disconnect. */
19
+ declare const Observation: Schema.Struct<{
20
+ readonly stream: Schema.instanceOf<ReadableStream<Uint8Array<ArrayBufferLike>>, unknown>;
21
+ readonly lifetime: Schema.declare<Rpc.DisposableValue, unknown>;
22
+ }>;
17
23
  /**
18
24
  * Reset replaces all drafts with a snapshot, streamed as native Text parts before live deltas.
19
25
  * Each snapshot starts a fresh streamId. Its sequences are unrelated to canonical sequences.
@@ -394,6 +400,25 @@ declare const encodeSubmitRequest: (input: {
394
400
  readonly reportKind?: "update" | undefined;
395
401
  } | undefined;
396
402
  readonly messageAdmission?: {
403
+ readonly schemaVersion: 1;
404
+ readonly message: {
405
+ readonly ownerThreadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
406
+ readonly messageId: string & import("effect/Brand").Brand<"@effect-agent/thread/IdempotencyKey">;
407
+ };
408
+ readonly peerName: string;
409
+ readonly sender: {
410
+ readonly threadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
411
+ readonly agentId: string & import("effect/Brand").Brand<"@effect-agent/core/AgentId">;
412
+ };
413
+ readonly returnAddress: {
414
+ readonly threadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
415
+ readonly agentId: string & import("effect/Brand").Brand<"@effect-agent/core/AgentId">;
416
+ };
417
+ readonly inReplyTo?: {
418
+ readonly ownerThreadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
419
+ readonly messageId: string & import("effect/Brand").Brand<"@effect-agent/thread/IdempotencyKey">;
420
+ } | undefined;
421
+ } | {
397
422
  readonly _tag: "WorkerCompletion";
398
423
  readonly budgetExhausted: boolean;
399
424
  readonly schemaVersion: 1;
@@ -434,25 +459,6 @@ declare const encodeSubmitRequest: (input: {
434
459
  readonly threadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
435
460
  };
436
461
  readonly update: import("@yielded/agent/agent-updates").Update;
437
- } | {
438
- readonly schemaVersion: 1;
439
- readonly message: {
440
- readonly ownerThreadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
441
- readonly messageId: string & import("effect/Brand").Brand<"@effect-agent/thread/IdempotencyKey">;
442
- };
443
- readonly peerName: string;
444
- readonly sender: {
445
- readonly threadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
446
- readonly agentId: string & import("effect/Brand").Brand<"@effect-agent/core/AgentId">;
447
- };
448
- readonly returnAddress: {
449
- readonly threadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
450
- readonly agentId: string & import("effect/Brand").Brand<"@effect-agent/core/AgentId">;
451
- };
452
- readonly inReplyTo?: {
453
- readonly ownerThreadId: string & import("effect/Brand").Brand<"@effect-agent/core/ThreadId">;
454
- readonly messageId: string & import("effect/Brand").Brand<"@effect-agent/thread/IdempotencyKey">;
455
- } | undefined;
456
462
  } | undefined;
457
463
  readonly definitions: DefinitionDigests;
458
464
  readonly inputPayload: Schema.Json;
@@ -738,13 +744,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
738
744
  readonly author: string;
739
745
  readonly reason: string;
740
746
  readonly resolution: {
741
- readonly _tag: "SafeToRetry";
742
- } | {
743
747
  readonly _tag: "CompletedWithResult";
744
748
  readonly result: Schema.Json;
745
749
  readonly isFailure: boolean;
746
750
  } | {
747
751
  readonly _tag: "NeverHappened";
752
+ } | {
753
+ readonly _tag: "SafeToRetry";
748
754
  } | {
749
755
  readonly _tag: "AbortSubmission";
750
756
  };
@@ -994,6 +1000,100 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
994
1000
  readonly createdAt: string;
995
1001
  readonly deploymentId: string;
996
1002
  readonly payload: {
1003
+ readonly _tag: "SubmissionSettled";
1004
+ readonly submissionId: string;
1005
+ readonly settlementId: string;
1006
+ readonly receiptId: string;
1007
+ readonly outcome: "aborted" | "completed" | "failed";
1008
+ readonly runId?: string | undefined;
1009
+ readonly historyRecordCount?: number | undefined;
1010
+ readonly result?: Schema.Json | undefined;
1011
+ readonly runDisposition?: Schema.Json | undefined;
1012
+ readonly finishReason?: "budget-exhausted" | undefined;
1013
+ readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
1014
+ readonly policyLimit?: "cost" | "duration" | "repeated-failures" | "tokens" | "tool-calls" | "turns" | "usage" | undefined;
1015
+ readonly usageSummary?: {
1016
+ readonly modelCalls: number;
1017
+ readonly inputTokens: {
1018
+ readonly total: number;
1019
+ readonly uncached: number;
1020
+ readonly cacheRead: number;
1021
+ readonly cacheWrite: number;
1022
+ };
1023
+ readonly outputTokens: {
1024
+ readonly total: number;
1025
+ readonly text: number;
1026
+ readonly reasoning: number;
1027
+ };
1028
+ readonly webSearchCalls?: number | undefined;
1029
+ readonly costMicrousd: number;
1030
+ readonly byModel: readonly {
1031
+ readonly provider: string;
1032
+ readonly model: string;
1033
+ readonly responseModel?: string | undefined;
1034
+ readonly serviceTier?: string | undefined;
1035
+ readonly pricingVersion?: string | undefined;
1036
+ readonly modelCalls: number;
1037
+ readonly inputTokens: {
1038
+ readonly total: number;
1039
+ readonly uncached: number;
1040
+ readonly cacheRead: number;
1041
+ readonly cacheWrite: number;
1042
+ };
1043
+ readonly outputTokens: {
1044
+ readonly total: number;
1045
+ readonly text: number;
1046
+ readonly reasoning: number;
1047
+ };
1048
+ readonly webSearchCalls?: number | undefined;
1049
+ readonly costMicrousd: number;
1050
+ }[];
1051
+ readonly usageStatus?: "complete" | "partial" | "unknown" | undefined;
1052
+ readonly pricingStatus?: "complete" | "partial" | "unknown" | undefined;
1053
+ readonly unobservedModelCalls?: number | undefined;
1054
+ } | undefined;
1055
+ readonly uncommittedModelUsage?: readonly {
1056
+ readonly provider: string;
1057
+ readonly model: string;
1058
+ readonly serviceTier?: string | undefined;
1059
+ readonly pricingVersion?: string | undefined;
1060
+ readonly response?: {
1061
+ readonly id?: string | undefined;
1062
+ readonly model?: string | undefined;
1063
+ } | undefined;
1064
+ readonly purpose?: "summary" | "turn" | undefined;
1065
+ readonly usageStatus?: "complete" | "partial" | "unknown" | undefined;
1066
+ readonly pricingStatus?: "estimated" | "unknown" | undefined;
1067
+ readonly inputTokens: {
1068
+ readonly total: number;
1069
+ readonly uncached: number;
1070
+ readonly cacheRead: number;
1071
+ readonly cacheWrite: number;
1072
+ };
1073
+ readonly outputTokens: {
1074
+ readonly total: number;
1075
+ readonly text: number;
1076
+ readonly reasoning: number;
1077
+ };
1078
+ readonly webSearchCalls?: number | undefined;
1079
+ readonly costMicrousd: number;
1080
+ }[] | undefined;
1081
+ } | {
1082
+ readonly _tag: "ThreadCreated";
1083
+ readonly agentId: string;
1084
+ readonly definitions: {
1085
+ readonly agent: string;
1086
+ readonly model: string;
1087
+ readonly tools: string;
1088
+ readonly replay?: {
1089
+ readonly agent: string;
1090
+ readonly agentBehavior?: string | undefined;
1091
+ readonly tools: {
1092
+ readonly [x: string]: string;
1093
+ };
1094
+ } | undefined;
1095
+ };
1096
+ } | {
997
1097
  readonly _tag: "UserInputRecorded";
998
1098
  readonly submissionId?: string | undefined;
999
1099
  readonly kind: "follow-up" | "steering" | "user";
@@ -1088,6 +1188,25 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1088
1188
  readonly value: Schema.Json;
1089
1189
  };
1090
1190
  } | undefined;
1191
+ } | {
1192
+ readonly _tag: "RunStarted";
1193
+ readonly runId: string;
1194
+ readonly policyAccountingVersion: 1;
1195
+ readonly maxDurationMillis: number;
1196
+ } | {
1197
+ readonly _tag: "RunDurationExhausted";
1198
+ readonly runId: string;
1199
+ } | {
1200
+ readonly _tag: "RunPolicyUsageReserved";
1201
+ readonly runId: string;
1202
+ readonly programmaticToolCalls: number;
1203
+ readonly finalizationUsed: boolean;
1204
+ } | {
1205
+ readonly _tag: "ModelCompleted";
1206
+ readonly runId: string;
1207
+ readonly output: Schema.Json;
1208
+ readonly messages?: Schema.Json | undefined;
1209
+ readonly history?: Schema.Json | undefined;
1091
1210
  } | {
1092
1211
  readonly _tag: "ModelResponseRecorded";
1093
1212
  readonly toolResultMaxBytes: number;
@@ -1154,48 +1273,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1154
1273
  readonly inputTokens?: number | undefined;
1155
1274
  readonly outputTokens?: number | undefined;
1156
1275
  readonly costMicrousd?: number | undefined;
1157
- } | {
1158
- readonly _tag: "CompactionCreated";
1159
- readonly runId: string;
1160
- readonly turn: number;
1161
- readonly kind: "clear-tool-results" | "rollover" | "summarize";
1162
- readonly coversThrough: number;
1163
- readonly summary?: string | undefined;
1164
- readonly handoff?: string | undefined;
1165
- } | {
1166
- readonly _tag: "ThreadCreated";
1167
- readonly agentId: string;
1168
- readonly definitions: {
1169
- readonly agent: string;
1170
- readonly model: string;
1171
- readonly tools: string;
1172
- readonly replay?: {
1173
- readonly agent: string;
1174
- readonly agentBehavior?: string | undefined;
1175
- readonly tools: {
1176
- readonly [x: string]: string;
1177
- };
1178
- } | undefined;
1179
- };
1180
- } | {
1181
- readonly _tag: "RunStarted";
1182
- readonly runId: string;
1183
- readonly policyAccountingVersion: 1;
1184
- readonly maxDurationMillis: number;
1185
- } | {
1186
- readonly _tag: "RunDurationExhausted";
1187
- readonly runId: string;
1188
- } | {
1189
- readonly _tag: "RunPolicyUsageReserved";
1190
- readonly runId: string;
1191
- readonly programmaticToolCalls: number;
1192
- readonly finalizationUsed: boolean;
1193
- } | {
1194
- readonly _tag: "ModelCompleted";
1195
- readonly runId: string;
1196
- readonly output: Schema.Json;
1197
- readonly messages?: Schema.Json | undefined;
1198
- readonly history?: Schema.Json | undefined;
1199
1276
  } | {
1200
1277
  readonly _tag: "ToolCallSettled";
1201
1278
  readonly toolSelection?: {
@@ -1282,6 +1359,14 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1282
1359
  readonly costMicrousd: number;
1283
1360
  }[];
1284
1361
  readonly unobservedModelCalls: number;
1362
+ } | {
1363
+ readonly _tag: "CompactionCreated";
1364
+ readonly runId: string;
1365
+ readonly turn: number;
1366
+ readonly kind: "clear-tool-results" | "rollover" | "summarize";
1367
+ readonly coversThrough: number;
1368
+ readonly summary?: string | undefined;
1369
+ readonly handoff?: string | undefined;
1285
1370
  } | {
1286
1371
  readonly _tag: "RunFailed";
1287
1372
  readonly runId: string;
@@ -1298,85 +1383,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
1298
1383
  readonly submissionId: string;
1299
1384
  readonly author: string;
1300
1385
  readonly reason: string;
1301
- } | {
1302
- readonly _tag: "SubmissionSettled";
1303
- readonly submissionId: string;
1304
- readonly settlementId: string;
1305
- readonly receiptId: string;
1306
- readonly outcome: "aborted" | "completed" | "failed";
1307
- readonly runId?: string | undefined;
1308
- readonly historyRecordCount?: number | undefined;
1309
- readonly result?: Schema.Json | undefined;
1310
- readonly runDisposition?: Schema.Json | undefined;
1311
- readonly finishReason?: "budget-exhausted" | undefined;
1312
- readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
1313
- readonly policyLimit?: "cost" | "duration" | "repeated-failures" | "tokens" | "tool-calls" | "turns" | "usage" | undefined;
1314
- readonly usageSummary?: {
1315
- readonly modelCalls: number;
1316
- readonly inputTokens: {
1317
- readonly total: number;
1318
- readonly uncached: number;
1319
- readonly cacheRead: number;
1320
- readonly cacheWrite: number;
1321
- };
1322
- readonly outputTokens: {
1323
- readonly total: number;
1324
- readonly text: number;
1325
- readonly reasoning: number;
1326
- };
1327
- readonly webSearchCalls?: number | undefined;
1328
- readonly costMicrousd: number;
1329
- readonly byModel: readonly {
1330
- readonly provider: string;
1331
- readonly model: string;
1332
- readonly responseModel?: string | undefined;
1333
- readonly serviceTier?: string | undefined;
1334
- readonly pricingVersion?: string | undefined;
1335
- readonly modelCalls: number;
1336
- readonly inputTokens: {
1337
- readonly total: number;
1338
- readonly uncached: number;
1339
- readonly cacheRead: number;
1340
- readonly cacheWrite: number;
1341
- };
1342
- readonly outputTokens: {
1343
- readonly total: number;
1344
- readonly text: number;
1345
- readonly reasoning: number;
1346
- };
1347
- readonly webSearchCalls?: number | undefined;
1348
- readonly costMicrousd: number;
1349
- }[];
1350
- readonly usageStatus?: "complete" | "partial" | "unknown" | undefined;
1351
- readonly pricingStatus?: "complete" | "partial" | "unknown" | undefined;
1352
- readonly unobservedModelCalls?: number | undefined;
1353
- } | undefined;
1354
- readonly uncommittedModelUsage?: readonly {
1355
- readonly provider: string;
1356
- readonly model: string;
1357
- readonly serviceTier?: string | undefined;
1358
- readonly pricingVersion?: string | undefined;
1359
- readonly response?: {
1360
- readonly id?: string | undefined;
1361
- readonly model?: string | undefined;
1362
- } | undefined;
1363
- readonly purpose?: "summary" | "turn" | undefined;
1364
- readonly usageStatus?: "complete" | "partial" | "unknown" | undefined;
1365
- readonly pricingStatus?: "estimated" | "unknown" | undefined;
1366
- readonly inputTokens: {
1367
- readonly total: number;
1368
- readonly uncached: number;
1369
- readonly cacheRead: number;
1370
- readonly cacheWrite: number;
1371
- };
1372
- readonly outputTokens: {
1373
- readonly total: number;
1374
- readonly text: number;
1375
- readonly reasoning: number;
1376
- };
1377
- readonly webSearchCalls?: number | undefined;
1378
- readonly costMicrousd: number;
1379
- }[] | undefined;
1380
1386
  } | {
1381
1387
  readonly _tag: "SubagentRequested";
1382
1388
  readonly runId: string;
@@ -2005,13 +2011,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
2005
2011
  readonly author: string;
2006
2012
  readonly reason: string;
2007
2013
  readonly resolution: {
2008
- readonly _tag: "SafeToRetry";
2009
- } | {
2010
2014
  readonly _tag: "CompletedWithResult";
2011
2015
  readonly result: Schema.Json;
2012
2016
  readonly isFailure: boolean;
2013
2017
  } | {
2014
2018
  readonly _tag: "NeverHappened";
2019
+ } | {
2020
+ readonly _tag: "SafeToRetry";
2015
2021
  } | {
2016
2022
  readonly _tag: "AbortSubmission";
2017
2023
  };
@@ -2026,8 +2032,53 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
2026
2032
  readonly message: string;
2027
2033
  readonly cause?: Schema.Json | undefined;
2028
2034
  } | {
2029
- readonly _tag: "ThreadNotMaterialized";
2035
+ readonly _tag: "HostProtocolError";
2036
+ readonly message: string;
2037
+ } | {
2038
+ readonly _tag: "AgentInputError";
2039
+ readonly message: string;
2040
+ } | {
2041
+ readonly _tag: "DigestError";
2042
+ readonly message: string;
2043
+ readonly cause?: Schema.Json | undefined;
2044
+ } | {
2045
+ readonly _tag: "AdmissionConflict";
2030
2046
  readonly threadId: string;
2047
+ readonly principal: string;
2048
+ readonly idempotencyKey: string;
2049
+ readonly existingInputDigest: string;
2050
+ readonly attemptedInputDigest: string;
2051
+ } | {
2052
+ readonly _tag: "AdmissionPolicyError";
2053
+ readonly reason: "occupied" | "refused" | "unavailable";
2054
+ readonly code: string;
2055
+ readonly cause?: import("@yielded/agent/failure-diagnostic").Diagnostic | undefined;
2056
+ readonly stack?: string | undefined;
2057
+ } | {
2058
+ readonly _tag: "SettlementConflict";
2059
+ readonly submissionId: string;
2060
+ readonly existingOutcome: "aborted" | "completed" | "failed";
2061
+ } | {
2062
+ readonly _tag: "ApprovalConflict";
2063
+ readonly submissionId: string;
2064
+ readonly toolCallId: string;
2065
+ readonly existingDecision: "approved" | "denied";
2066
+ } | {
2067
+ readonly _tag: "UnknownResolutionConflict";
2068
+ readonly submissionId: string;
2069
+ readonly toolCallId: string;
2070
+ } | {
2071
+ readonly _tag: "JoinedToHost";
2072
+ readonly submissionId: string;
2073
+ readonly hostSubmissionId: string;
2074
+ } | {
2075
+ readonly _tag: "LedgerError";
2076
+ readonly operation: string;
2077
+ readonly message: string;
2078
+ readonly cause?: import("@yielded/agent/failure-diagnostic").Diagnostic | undefined;
2079
+ } | {
2080
+ readonly _tag: "OwnershipLost";
2081
+ readonly submissionId: string;
2031
2082
  } | {
2032
2083
  readonly _tag: "ThreadStoreError";
2033
2084
  readonly operation: string;
@@ -2041,73 +2092,28 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
2041
2092
  readonly sequence?: number | undefined;
2042
2093
  } | undefined;
2043
2094
  } | {
2044
- readonly _tag: "LedgerError";
2045
- readonly operation: string;
2046
- readonly message: string;
2047
- readonly cause?: import("@yielded/agent/failure-diagnostic").Diagnostic | undefined;
2095
+ readonly _tag: "ThreadNotMaterialized";
2096
+ readonly threadId: string;
2048
2097
  } | {
2049
2098
  readonly _tag: "AppendConflict";
2050
2099
  readonly threadId: string;
2051
2100
  readonly batchId: string;
2052
2101
  readonly reason: "batch-content" | "record-identity" | "stale-command" | "tail";
2053
2102
  readonly actualTailSequence?: number | undefined;
2054
- } | {
2055
- readonly _tag: "OwnershipLost";
2056
- readonly submissionId: string;
2057
- } | {
2058
- readonly _tag: "OperationDenied";
2059
- readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
2060
- readonly reason: string;
2061
- readonly threadId?: string | undefined;
2062
- readonly submissionId?: string | undefined;
2063
- } | {
2064
- readonly _tag: "SettlementConflict";
2065
- readonly submissionId: string;
2066
- readonly existingOutcome: "aborted" | "completed" | "failed";
2067
- } | {
2068
- readonly _tag: "AdmissionPolicyError";
2069
- readonly reason: "occupied" | "refused" | "unavailable";
2070
- readonly code: string;
2071
- readonly cause?: import("@yielded/agent/failure-diagnostic").Diagnostic | undefined;
2072
- readonly stack?: string | undefined;
2073
- } | {
2074
- readonly _tag: "DigestError";
2075
- readonly message: string;
2076
- readonly cause?: Schema.Json | undefined;
2077
2103
  } | {
2078
2104
  readonly _tag: "DurableRuntimeFailpointError";
2079
2105
  readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "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:before-publication" | "tools:after-dispatch-fence" | "tools:after-unavailable-append" | "tools:before-dispatch-fence" | "tools:before-unavailable-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-stop-append" | "worker:after-stop-seal" | "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-stop-append" | "worker:before-stop-seal" | "worker:before-subtree-append";
2080
- } | {
2081
- readonly _tag: "AdmissionConflict";
2082
- readonly threadId: string;
2083
- readonly principal: string;
2084
- readonly idempotencyKey: string;
2085
- readonly existingInputDigest: string;
2086
- readonly attemptedInputDigest: string;
2087
- } | {
2088
- readonly _tag: "AgentInputError";
2089
- readonly message: string;
2090
2106
  } | {
2091
2107
  readonly _tag: "AdmissionLimitExceeded";
2092
2108
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
2093
2109
  readonly actual: number;
2094
2110
  readonly maximum: number;
2095
2111
  } | {
2096
- readonly _tag: "HostProtocolError";
2097
- readonly message: string;
2098
- } | {
2099
- readonly _tag: "JoinedToHost";
2100
- readonly submissionId: string;
2101
- readonly hostSubmissionId: string;
2102
- } | {
2103
- readonly _tag: "ApprovalConflict";
2104
- readonly submissionId: string;
2105
- readonly toolCallId: string;
2106
- readonly existingDecision: "approved" | "denied";
2107
- } | {
2108
- readonly _tag: "UnknownResolutionConflict";
2109
- readonly submissionId: string;
2110
- readonly toolCallId: string;
2112
+ readonly _tag: "OperationDenied";
2113
+ readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
2114
+ readonly reason: string;
2115
+ readonly threadId?: string | undefined;
2116
+ readonly submissionId?: string | undefined;
2111
2117
  };
2112
2118
  }, Schema.SchemaError, never>;
2113
2119
  declare const decodeHostResponse: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<AbortRecorded | ApprovalRecorded | HostFailed | ObservedPage | ProgressCancelled | ProgressObserved | SettlementReached | SettlementRecordReached | SubmissionStatusResponse | SubmitSucceeded | UnknownResolutionRecorded, Schema.SchemaError, never>;
@@ -2201,5 +2207,5 @@ declare class CloudflareThreadClient extends CloudflareThreadClient_base {
2201
2207
  static readonly layer: Layer.Layer<CloudflareThreadClient, never, ThreadObjectNamespace | Crypto.Crypto>;
2202
2208
  }
2203
2209
  //#endregion
2204
- export { boundHostDiagnostic as A, decodeSubmitRequest as B, SettlementReached as C, SubmitSucceeded as D, SubmitRequest as E, decodeCancelProgressRequest as F, encodeAwaitSettlementRequest as G, encodeAbortCommand as H, decodeHostResponse as I, encodeObservePageRequest as J, encodeCancelProgressRequest as K, decodeLiveText as L, decodeApprovalDecisionCommand as M, decodeAwaitProgressRequest as N, ThreadClientError as O, decodeAwaitSettlementRequest as P, Frame as Q, decodeObservePageRequest as R, ProgressObserved as S, SubmissionStatusResponse as T, encodeApprovalDecisionCommand as U, decodeUnknownResolutionCommand as V, encodeAwaitProgressRequest as W, encodeSubmitRequest as X, encodeReceipt as Y, encodeUnknownResolutionCommand as Z, HostProtocolError as _, CancelProgressRequest as a, ObservedPage as b, ClientAwaitFailure as c, ClientSubmitFailure as d, ClientUnknownFailure as f, HostFailure as g, HostFailed as h, AwaitSettlementRequest as i, decodeAbortCommand as j, UnknownResolutionRecorded as k, ClientObserveFailure as l, CloudflareThreadClient_d_exports as m, ApprovalRecorded as n, ClientAbortFailure as o, CloudflareThreadClient as p, encodeHostResponse as q, AwaitProgressRequest as r, ClientApprovalFailure as s, AbortRecorded as t, ClientProgressFailure as u, HostResponse as v, SettlementRecordReached as w, ProgressCancelled as x, ObservePageRequest as y, decodeReceipt as z };
2205
- //# sourceMappingURL=CloudflareThreadClient-B9ODixhk.d.mts.map
2210
+ export { Observation as $, boundHostDiagnostic as A, decodeSubmitRequest as B, SettlementReached as C, SubmitSucceeded as D, SubmitRequest as E, decodeCancelProgressRequest as F, encodeAwaitSettlementRequest as G, encodeAbortCommand as H, decodeHostResponse as I, encodeObservePageRequest as J, encodeCancelProgressRequest as K, decodeLiveText as L, decodeApprovalDecisionCommand as M, decodeAwaitProgressRequest as N, ThreadClientError as O, decodeAwaitSettlementRequest as P, Frame as Q, decodeObservePageRequest as R, ProgressObserved as S, SubmissionStatusResponse as T, encodeApprovalDecisionCommand as U, decodeUnknownResolutionCommand as V, encodeAwaitProgressRequest as W, encodeSubmitRequest as X, encodeReceipt as Y, encodeUnknownResolutionCommand as Z, HostProtocolError as _, CancelProgressRequest as a, ObservedPage as b, ClientAwaitFailure as c, ClientSubmitFailure as d, ClientUnknownFailure as f, HostFailure as g, HostFailed as h, AwaitSettlementRequest as i, decodeAbortCommand as j, UnknownResolutionRecorded as k, ClientObserveFailure as l, CloudflareThreadClient_d_exports as m, ApprovalRecorded as n, ClientAbortFailure as o, CloudflareThreadClient as p, encodeHostResponse as q, AwaitProgressRequest as r, ClientApprovalFailure as s, AbortRecorded as t, ClientProgressFailure as u, HostResponse as v, SettlementRecordReached as w, ProgressCancelled as x, ObservePageRequest as y, decodeReceipt as z };
2211
+ //# sourceMappingURL=CloudflareThreadClient-CmlojpjC.d.mts.map
@@ -6,7 +6,7 @@ import "@yielded/agent/durable-agent-runtime";
6
6
  import { AgentId, ThreadId } from "@yielded/agent/identifiers";
7
7
  import { AbortCommand, AbortIntent, AdmissionConflict, AdmissionFence, AdmissionGroup, AdmissionPolicyError, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, IdempotencyKey, JoinedToHost, LedgerError, OwnershipLost, Principal, Settlement, SettlementConflict, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent } from "@yielded/agent/submission-ledger";
8
8
  import { Context, Crypto, Duration, Effect, Layer, PlatformError, Predicate, Schema, Stream } from "effect";
9
- import { RpcTargets, RpcTracing } from "effect-cf";
9
+ import { Rpc, RpcTargets, RpcTracing } from "effect-cf";
10
10
  import { CanonicalRecordEnvelope, CanonicalSequence, DefinitionDigests, PersistedJson, SubmissionSettledRecord, WorkerAdmission } from "@yielded/agent/records";
11
11
  import { AgentInputError } from "@yielded/agent/agent-error";
12
12
  import { DigestError } from "@yielded/agent/digest";
@@ -49,6 +49,11 @@ const MAX_DELTA_LENGTH = 4096;
49
49
  const MAX_DRAFT_LENGTH = 2097152;
50
50
  const streamId = Schema.NonEmptyString.check(Schema.isMaxLength(256));
51
51
  const Request = Schema.Struct({ schemaVersion: Schema.Literal(1) });
52
+ /** The RPC lifetime survives an idle byte stream and is disposed on caller disconnect. */
53
+ const Observation = Schema.Struct({
54
+ stream: Schema.instanceOf(ReadableStream),
55
+ lifetime: Schema.declare(Rpc.isDisposable)
56
+ });
52
57
  /**
53
58
  * Reset replaces all drafts with a snapshot, streamed as native Text parts before live deltas.
54
59
  * Each snapshot starts a fresh streamId. Its sequences are unrelated to canonical sequences.
@@ -490,7 +495,12 @@ var CloudflareThreadClient = class CloudflareThreadClient extends Context.Servic
490
495
  const cancel = () => {
491
496
  const value = received;
492
497
  received = void 0;
493
- return value instanceof ReadableStream && !value.locked ? value.cancel().catch(() => void 0) : Promise.resolve();
498
+ const observation = Schema.is(Observation)(value) ? value : void 0;
499
+ try {
500
+ observation?.lifetime[Symbol.dispose]();
501
+ } catch {}
502
+ const stream = observation?.stream ?? value;
503
+ return stream instanceof ReadableStream && !stream.locked ? stream.cancel().catch(() => void 0) : Promise.resolve();
494
504
  };
495
505
  yield* Effect.addFinalizer(() => Effect.try({
496
506
  try: () => {
@@ -515,8 +525,9 @@ var CloudflareThreadClient = class CloudflareThreadClient extends Context.Servic
515
525
  },
516
526
  catch: openingFailure
517
527
  }).pipe(Effect.interruptible, Effect.tapCause(() => RpcTargets.invalidate(target)));
518
- if (raw instanceof ReadableStream) return Stream.fromReadableStream({
519
- evaluate: () => raw,
528
+ const stream = Schema.is(Observation)(raw) ? raw.stream : raw;
529
+ if (stream instanceof ReadableStream) return Stream.fromReadableStream({
530
+ evaluate: () => stream,
520
531
  releaseLockOnEnd: true,
521
532
  onError: (cause) => ThreadClientError.make({
522
533
  threadId,
@@ -606,6 +617,6 @@ var CloudflareThreadClient = class CloudflareThreadClient extends Context.Servic
606
617
  }));
607
618
  };
608
619
  //#endregion
609
- export { decodeLiveText as A, encodeHostResponse as B, boundHostDiagnostic as C, decodeAwaitSettlementRequest as D, decodeAwaitProgressRequest as E, encodeAbortCommand as F, Frame as G, encodeReceipt as H, encodeApprovalDecisionCommand as I, MAX_FRAME_BYTES as J, MAX_DELTA_LENGTH as K, encodeAwaitProgressRequest as L, decodeReceipt as M, decodeSubmitRequest as N, decodeCancelProgressRequest as O, decodeUnknownResolutionCommand as P, encodeAwaitSettlementRequest as R, UnknownResolutionRecorded as S, decodeApprovalDecisionCommand as T, encodeSubmitRequest as U, encodeObservePageRequest as V, encodeUnknownResolutionCommand as W, isBoundedEvent as X, Request as Y, cloudflareCryptoLayer as Z, SettlementRecordReached as _, CancelProgressRequest as a, SubmitSucceeded as b, HostFailed as c, HostResponse as d, ObservePageRequest as f, SettlementReached as g, ProgressObserved as h, AwaitSettlementRequest as i, decodeObservePageRequest as j, decodeHostResponse as k, HostFailure as l, ProgressCancelled as m, ApprovalRecorded as n, CloudflareThreadClient as o, ObservedPage as p, MAX_DRAFT_LENGTH as q, AwaitProgressRequest as r, CloudflareThreadClient_exports as s, AbortRecorded as t, HostProtocolError as u, SubmissionStatusResponse as v, decodeAbortCommand as w, ThreadClientError as x, SubmitRequest as y, encodeCancelProgressRequest as z };
620
+ export { decodeLiveText as A, encodeHostResponse as B, boundHostDiagnostic as C, decodeAwaitSettlementRequest as D, decodeAwaitProgressRequest as E, encodeAbortCommand as F, Frame as G, encodeReceipt as H, encodeApprovalDecisionCommand as I, MAX_FRAME_BYTES as J, MAX_DELTA_LENGTH as K, encodeAwaitProgressRequest as L, decodeReceipt as M, decodeSubmitRequest as N, decodeCancelProgressRequest as O, decodeUnknownResolutionCommand as P, cloudflareCryptoLayer as Q, encodeAwaitSettlementRequest as R, UnknownResolutionRecorded as S, decodeApprovalDecisionCommand as T, encodeSubmitRequest as U, encodeObservePageRequest as V, encodeUnknownResolutionCommand as W, Request as X, Observation as Y, isBoundedEvent as Z, SettlementRecordReached as _, CancelProgressRequest as a, SubmitSucceeded as b, HostFailed as c, HostResponse as d, ObservePageRequest as f, SettlementReached as g, ProgressObserved as h, AwaitSettlementRequest as i, decodeObservePageRequest as j, decodeHostResponse as k, HostFailure as l, ProgressCancelled as m, ApprovalRecorded as n, CloudflareThreadClient as o, ObservedPage as p, MAX_DRAFT_LENGTH as q, AwaitProgressRequest as r, CloudflareThreadClient_exports as s, AbortRecorded as t, HostProtocolError as u, SubmissionStatusResponse as v, decodeAbortCommand as w, ThreadClientError as x, SubmitRequest as y, encodeCancelProgressRequest as z };
610
621
 
611
- //# sourceMappingURL=CloudflareThreadClient-CEUjVwis.mjs.map
622
+ //# sourceMappingURL=CloudflareThreadClient-CnvMXPmV.mjs.map