@systemfsoftware/agent 0.1.0-beta.192 → 0.1.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.
Files changed (114) hide show
  1. package/dist/{Admin-BfolLkHj.d.mts → Admin-26pelcl9.d.mts} +5 -5
  2. package/dist/{Agent-DSVEpq4e.d.mts → Agent-BH_R6LOI.d.mts} +1 -1
  3. package/dist/{AgentRegistration-Dg53p6du.mjs → AgentRegistration-h07X1mZM.mjs} +2 -2
  4. package/dist/{AgentRegistration-Dg53p6du.mjs.map → AgentRegistration-h07X1mZM.mjs.map} +1 -1
  5. package/dist/{AgentRuntime-CoGy_5dm.d.mts → AgentRuntime-C3GQPdrv.d.mts} +3 -3
  6. package/dist/{AgentRuntime-CzP4I4RB.mjs → AgentRuntime-CrYYV9RF.mjs} +3 -28
  7. package/dist/AgentRuntime-CrYYV9RF.mjs.map +1 -0
  8. package/dist/{BrowserUse-C9vict2M.d.mts → BrowserUse-DgCEbTwW.d.mts} +10 -10
  9. package/dist/{CommittedActivity-LWOKXqdi.d.mts → CommittedActivity-DMfj2beT.d.mts} +1 -1
  10. package/dist/{ContextTools-917r7gpv.d.mts → ContextTools-D5jrWNNH.d.mts} +12 -12
  11. package/dist/{DurableAgentRuntime-BHXo8GPJ.mjs → DurableAgentRuntime-D3UTrNQg.mjs} +4 -4
  12. package/dist/{DurableAgentRuntime-BHXo8GPJ.mjs.map → DurableAgentRuntime-D3UTrNQg.mjs.map} +1 -1
  13. package/dist/{EventSource-C0TCBeIf.d.mts → EventSource-BWY08cyT.d.mts} +1 -1
  14. package/dist/{MemoryNotes-4CRzkPBD.d.mts → MemoryNotes-CPvcb5OX.d.mts} +6 -6
  15. package/dist/{MessageDelivery-Dh6GZBt_.d.mts → MessageDelivery-C0S-Cakt.d.mts} +2 -2
  16. package/dist/{Messaging-DhM-APnP.d.mts → Messaging-DnnpWe-H.d.mts} +17 -17
  17. package/dist/{MessagingHost-CubWeYKN.d.mts → MessagingHost-DPPHTLdT.d.mts} +1 -1
  18. package/dist/{Output-SbOdlBFL.d.mts → Output-CafxF31F.d.mts} +1 -1
  19. package/dist/{PersistentHistory-BrtZ0g2j.d.mts → PersistentHistory-h-C7avqL.d.mts} +1 -1
  20. package/dist/{PreparedInputAdmission-Ci18uY4s.d.mts → PreparedInputAdmission-DYugcCHR.d.mts} +1 -1
  21. package/dist/{RunContinuation-BVAHoYlN.d.mts → RunContinuation-Cy2W8ASl.d.mts} +2 -2
  22. package/dist/{ScheduleTransition-CjVP48I8.d.mts → ScheduleTransition-DcqokgFt.d.mts} +1 -1
  23. package/dist/{Scheduling-DYTM29s9.d.mts → Scheduling-BaJXJIVt.d.mts} +2 -2
  24. package/dist/{Subagent-CSIRUgUo.mjs → Subagent-BJJN6n0E.mjs} +2 -2
  25. package/dist/{Subagent-CSIRUgUo.mjs.map → Subagent-BJJN6n0E.mjs.map} +1 -1
  26. package/dist/{Subagent-CXEI5YZ8.d.mts → Subagent-GXU32fQt.d.mts} +18 -18
  27. package/dist/{SubagentHost-CKhz1vbH.d.mts → SubagentHost-BC9B9dNT.d.mts} +1 -1
  28. package/dist/{Subscription-CC--_OnU.d.mts → Subscription-BJ0TtZwM.d.mts} +2 -2
  29. package/dist/{SubscriptionInput-Xcd4JjEs.mjs → SubscriptionInput-BbV69oX_.mjs} +2 -2
  30. package/dist/{SubscriptionInput-Xcd4JjEs.mjs.map → SubscriptionInput-BbV69oX_.mjs.map} +1 -1
  31. package/dist/{SubscriptionInput-BEeB0Cj8.d.mts → SubscriptionInput-D6Okd6-z.d.mts} +1 -1
  32. package/dist/{SubscriptionTransition-CWt9UVH0.d.mts → SubscriptionTransition-Da9DmAr_.d.mts} +1 -1
  33. package/dist/{Subscriptions-4K_qu_2f.mjs → Subscriptions-BS3AXmQ0.mjs} +2 -2
  34. package/dist/{Subscriptions-4K_qu_2f.mjs.map → Subscriptions-BS3AXmQ0.mjs.map} +1 -1
  35. package/dist/{Subscriptions-BF3aSf8X.d.mts → Subscriptions-DgjahL6V.d.mts} +5 -5
  36. package/dist/{ThreadContextHistory-lTZ8Ftq1.d.mts → ThreadContextHistory-BVTD96Pe.d.mts} +1 -1
  37. package/dist/{ThreadImport-DaSmrlRi.d.mts → ThreadImport-BQDW9E_Y.d.mts} +3 -3
  38. package/dist/{ThreadInvariants-DyPhMeo-.d.mts → ThreadInvariants-w53c67YS.d.mts} +3 -3
  39. package/dist/{ThreadProjectionMaintenance-DjUy7kCa.d.mts → ThreadProjectionMaintenance-4ccU1auU.d.mts} +1 -1
  40. package/dist/{ThreadTransfer-BM02cbOo.d.mts → ThreadTransfer-D0KsqkSR.d.mts} +1 -1
  41. package/dist/{ToolDiscovery-VjamzX3q.d.mts → ToolDiscovery-DvcfbTBk.d.mts} +2 -2
  42. package/dist/{ToolResults-C4-HsMCp.d.mts → ToolResults-NUk_x837.d.mts} +2 -2
  43. package/dist/{WebSearch-CD0V--qh.d.mts → WebSearch-RBUUOfT8.d.mts} +1 -1
  44. package/dist/{WorkerAdmission-BnRuXLWF.d.mts → WorkerAdmission-CubQgpsl.d.mts} +1 -1
  45. package/dist/{WorkerAdmission-BhFjx86s.mjs → WorkerAdmission-D8tw_OmT.mjs} +2 -2
  46. package/dist/{WorkerAdmission-BhFjx86s.mjs.map → WorkerAdmission-D8tw_OmT.mjs.map} +1 -1
  47. package/dist/{WorkerHost-DtYzi54D.d.mts → WorkerHost-BciHCzHq.d.mts} +2 -2
  48. package/dist/{agent-registration-CNs2twrr.mjs → agent-registration-D9ofkoBa.mjs} +2 -2
  49. package/dist/{agent-registration-CNs2twrr.mjs.map → agent-registration-D9ofkoBa.mjs.map} +1 -1
  50. package/dist/capabilities/BrowserUse.d.mts +1 -1
  51. package/dist/capabilities/ContextTools.d.mts +1 -1
  52. package/dist/capabilities/MemoryNotes.d.mts +1 -1
  53. package/dist/capabilities/Messaging.d.mts +1 -1
  54. package/dist/capabilities/Subagent.d.mts +1 -1
  55. package/dist/capabilities/Subagent.mjs +1 -1
  56. package/dist/capabilities/ToolDiscovery.d.mts +1 -1
  57. package/dist/capabilities/ToolResults.d.mts +1 -1
  58. package/dist/capabilities/WebSearch.d.mts +1 -1
  59. package/dist/core/Agent.d.mts +1 -1
  60. package/dist/durable/Admin.d.mts +1 -1
  61. package/dist/durable/AgentRegistration.d.mts +1 -1
  62. package/dist/durable/AgentRegistration.mjs +2 -2
  63. package/dist/durable/CommittedActivity.d.mts +1 -1
  64. package/dist/durable/DurableAgentRuntime.d.mts +1 -1
  65. package/dist/durable/DurableAgentRuntime.mjs +2 -2
  66. package/dist/durable/EventSource.d.mts +1 -1
  67. package/dist/durable/LifecyclePublication.d.mts +1 -1
  68. package/dist/durable/MessageDelivery.d.mts +1 -1
  69. package/dist/durable/MessageDeliveryStoreConformance.d.mts +2 -2
  70. package/dist/durable/PersistentHistory.d.mts +1 -1
  71. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  72. package/dist/durable/Recovery.d.mts +1 -1
  73. package/dist/durable/RunContinuation.d.mts +2 -2
  74. package/dist/durable/RunJournal.d.mts +1 -1
  75. package/dist/durable/RunStorage.d.mts +1 -1
  76. package/dist/durable/Schedule.d.mts +1 -1
  77. package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
  78. package/dist/durable/ScheduleTransition.d.mts +1 -1
  79. package/dist/durable/Scheduling.d.mts +1 -1
  80. package/dist/durable/SettlementPublisher.d.mts +1 -1
  81. package/dist/durable/SubmissionLedger.d.mts +1 -1
  82. package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
  83. package/dist/durable/SubmissionStatus.d.mts +1 -1
  84. package/dist/durable/Subscription.d.mts +1 -1
  85. package/dist/durable/SubscriptionInput.d.mts +1 -1
  86. package/dist/durable/SubscriptionInput.mjs +1 -1
  87. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  88. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  89. package/dist/durable/Subscriptions.d.mts +1 -1
  90. package/dist/durable/Subscriptions.mjs +1 -1
  91. package/dist/durable/ThreadArchiveRange.d.mts +1 -1
  92. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  93. package/dist/durable/ThreadImport.d.mts +1 -1
  94. package/dist/durable/ThreadInvariants.d.mts +1 -1
  95. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  96. package/dist/durable/ThreadReader.d.mts +1 -1
  97. package/dist/durable/ThreadStore.d.mts +1 -1
  98. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  99. package/dist/durable/ThreadTransfer.d.mts +1 -1
  100. package/dist/durable/ThreadWork.d.mts +1 -1
  101. package/dist/durable/WorkerAdmission.d.mts +1 -1
  102. package/dist/durable/WorkerAdmission.mjs +1 -1
  103. package/dist/durable/WorkerHost.d.mts +1 -1
  104. package/dist/engine/AgentRuntime.d.mts +1 -1
  105. package/dist/engine/AgentRuntime.mjs +1 -1
  106. package/dist/engine/MessagingHost.d.mts +1 -1
  107. package/dist/engine/Output.d.mts +1 -1
  108. package/dist/engine/SubagentHost.d.mts +1 -1
  109. package/dist/index.d.mts +33 -33
  110. package/dist/index.mjs +7 -7
  111. package/dist/{run-context-reader-CHox63hg.d.mts → run-context-reader-D1Tx1G6V.d.mts} +1 -1
  112. package/package.json +6 -6
  113. package/src/engine/internal/agent-runtime.ts +4 -58
  114. package/dist/AgentRuntime-CzP4I4RB.mjs.map +0 -1
@@ -3,11 +3,11 @@ import * as Toolkit from "effect/ai/Toolkit";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Layer from "effect/Layer";
5
5
  import * as Schema from "effect/Schema";
6
- import { _ as ModelServices, g as InstructionSource, p as InputPromptSource, r as AnyDefinition, s as Definition, w as RunDispositionDeclaration } from "./Agent-DSVEpq4e.mjs";
6
+ import { _ as ModelServices, g as InstructionSource, p as InputPromptSource, r as AnyDefinition, s as Definition, w as RunDispositionDeclaration } from "./Agent-BH_R6LOI.mjs";
7
7
  import { d as ToolCallId, r as DelegationId, u as ThreadId } from "./Identifiers-qafW4EP0.mjs";
8
8
  import { c as SubagentExecutionFailureClassification, d as SubagentPolicy, f as SubagentPolicyInput, l as SubagentGrant, o as SubagentDelegationCaps, p as SubagentReservationAmounts, s as SubagentExecutionFailure } from "./SubagentContract-B7vQPueI.mjs";
9
9
  import { s as RunTotals } from "./Usage-Bc-jXe_9.mjs";
10
- import { C as SubagentDurability, E as SubagentDurabilityError, O as ToolCallWaiting, f as AgentRuntimeFailure, h as AgentSpawnerParent, m as AgentSpawner, p as AgentRuntimeRequirements, x as SpawnRunOptions, y as RuntimeBinding } from "./AgentRuntime-CoGy_5dm.mjs";
10
+ import { C as SubagentDurability, E as SubagentDurabilityError, O as ToolCallWaiting, f as AgentRuntimeFailure, h as AgentSpawnerParent, m as AgentSpawner, p as AgentRuntimeRequirements, x as SpawnRunOptions, y as RuntimeBinding } from "./AgentRuntime-C3GQPdrv.mjs";
11
11
  import { t as RunEventSink } from "./RunEventSink-f-T4jbNB.mjs";
12
12
  import { m as RunContextPreparation } from "./RunOptions-BVSa3BO2.mjs";
13
13
  import { t as ThreadHistory } from "./ThreadHistory-BkyGfv5E.mjs";
@@ -15,7 +15,7 @@ import { r as Diagnostic } from "./FailureDiagnostic-DpzYNI8f.mjs";
15
15
  import { h as SubagentReservations, i as SubagentBudgetExhausted } from "./SubagentReservations-WrmIVzO5.mjs";
16
16
  import { a as WorkerBudgetScope, c as WorkerError, f as WorkerRef, o as WorkerCompletion, p as WorkerReport } from "./Worker-xxucY_0b.mjs";
17
17
  import { a as Receipt, n as JoinedToHost, t as IdempotencyKey } from "./Receipt-B4feBxMY.mjs";
18
- import { a as SubagentHost, d as WorkerReporting, f as WorkerRunReport, u as WorkerReportPreparationFailure } from "./SubagentHost-CKhz1vbH.mjs";
18
+ import { a as SubagentHost, d as WorkerReporting, f as WorkerRunReport, u as WorkerReportPreparationFailure } from "./SubagentHost-BC9B9dNT.mjs";
19
19
  import * as Brand from "effect/Brand";
20
20
  import * as CryptoDigest from "effect/crypto/Digest";
21
21
  import * as Stream from "effect/Stream";
@@ -955,7 +955,7 @@ declare const startTool: <const Name extends string, Input extends Schema.Top, O
955
955
  }>;
956
956
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof SubagentPrestartDenied, typeof WorkerError]>;
957
957
  readonly failureMode: "error";
958
- }, CryptoDigest.Digest | SubagentHost>;
958
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>;
959
959
  layer: import("effect/Layer").Layer<Tool.HandlersFor<[Tool.Tool<`${Name}_start`, {
960
960
  readonly parameters: Parameters;
961
961
  readonly success: Schema.Struct<{
@@ -1022,7 +1022,7 @@ declare const startTool: <const Name extends string, Input extends Schema.Top, O
1022
1022
  }>;
1023
1023
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof SubagentPrestartDenied, typeof WorkerError]>;
1024
1024
  readonly failureMode: "error";
1025
- }, CryptoDigest.Digest | SubagentHost>] extends (infer T) ? T extends [Tool.Tool<`${Name}_start`, {
1025
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>] extends (infer T) ? T extends [Tool.Tool<`${Name}_start`, {
1026
1026
  readonly parameters: Parameters;
1027
1027
  readonly success: Schema.Struct<{
1028
1028
  readonly worker: Schema.refine<{
@@ -1088,7 +1088,7 @@ declare const startTool: <const Name extends string, Input extends Schema.Top, O
1088
1088
  }>;
1089
1089
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof SubagentPrestartDenied, typeof WorkerError]>;
1090
1090
  readonly failureMode: "error";
1091
- }, CryptoDigest.Digest | SubagentHost>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Prepare, import("effect/Scope").Scope> | Exclude<Input["EncodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["EncodingServices"], import("effect/Scope").Scope>>;
1091
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Prepare, import("effect/Scope").Scope> | Exclude<Input["EncodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["EncodingServices"], import("effect/Scope").Scope>>;
1092
1092
  }>;
1093
1093
  /** Retain follow-up input for an existing worker under the current Tool Call's identity. */
1094
1094
  declare const followUpTool: <const Name extends string, Input extends Schema.Top, Output extends Schema.Top, Parameters extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, Prepare, Project>(declaration: Declaration<Name, Input, Output, Parameters, Success, Failure, Prepare, Project>) => Readonly<{
@@ -1158,7 +1158,7 @@ declare const followUpTool: <const Name extends string, Input extends Schema.Top
1158
1158
  }>]>;
1159
1159
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1160
1160
  readonly failureMode: "error";
1161
- }, CryptoDigest.Digest | SubagentHost>;
1161
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>;
1162
1162
  layer: import("effect/Layer").Layer<Tool.HandlersFor<[Tool.Tool<`${Name}_follow_up`, {
1163
1163
  readonly parameters: Schema.Struct<{
1164
1164
  readonly worker: Schema.refine<{
@@ -1225,7 +1225,7 @@ declare const followUpTool: <const Name extends string, Input extends Schema.Top
1225
1225
  }>]>;
1226
1226
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1227
1227
  readonly failureMode: "error";
1228
- }, CryptoDigest.Digest | SubagentHost>] extends (infer T) ? T extends [Tool.Tool<`${Name}_follow_up`, {
1228
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>] extends (infer T) ? T extends [Tool.Tool<`${Name}_follow_up`, {
1229
1229
  readonly parameters: Schema.Struct<{
1230
1230
  readonly worker: Schema.refine<{
1231
1231
  readonly schemaVersion: 1;
@@ -1291,7 +1291,7 @@ declare const followUpTool: <const Name extends string, Input extends Schema.Top
1291
1291
  }>]>;
1292
1292
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1293
1293
  readonly failureMode: "error";
1294
- }, CryptoDigest.Digest | SubagentHost>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Prepare, import("effect/Scope").Scope> | Exclude<Input["EncodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["EncodingServices"], import("effect/Scope").Scope>>;
1294
+ }, CryptoDigest.Digest | SubagentHost, Tool.Execution>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Prepare, import("effect/Scope").Scope> | Exclude<Input["EncodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["EncodingServices"], import("effect/Scope").Scope>>;
1295
1295
  }>;
1296
1296
  /** Inspect one delivery or accepted Receipt without resending input. */
1297
1297
  declare const inspectTool: <const Name extends string, Input extends Schema.Top, Output extends Schema.Top, Parameters extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, Prepare, Project>(declaration: Declaration<Name, Input, Output, Parameters, Success, Failure, Prepare, Project>) => Readonly<{
@@ -1379,7 +1379,7 @@ declare const inspectTool: <const Name extends string, Input extends Schema.Top,
1379
1379
  }>]>]>;
1380
1380
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1381
1381
  readonly failureMode: "error";
1382
- }, SubagentHost>;
1382
+ }, SubagentHost, Tool.Execution>;
1383
1383
  layer: import("effect/Layer").Layer<Tool.HandlersFor<[Tool.Tool<`${Name}_inspect`, {
1384
1384
  readonly parameters: Schema.Struct<{
1385
1385
  readonly worker: Schema.refine<{
@@ -1464,7 +1464,7 @@ declare const inspectTool: <const Name extends string, Input extends Schema.Top,
1464
1464
  }>]>]>;
1465
1465
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1466
1466
  readonly failureMode: "error";
1467
- }, SubagentHost>] extends (infer T) ? T extends [Tool.Tool<`${Name}_inspect`, {
1467
+ }, SubagentHost, Tool.Execution>] extends (infer T) ? T extends [Tool.Tool<`${Name}_inspect`, {
1468
1468
  readonly parameters: Schema.Struct<{
1469
1469
  readonly worker: Schema.refine<{
1470
1470
  readonly schemaVersion: 1;
@@ -1548,7 +1548,7 @@ declare const inspectTool: <const Name extends string, Input extends Schema.Top,
1548
1548
  }>]>]>;
1549
1549
  readonly failure: Schema.Union<readonly [Failure, typeof SubagentProjectionFailure, typeof WorkerError]>;
1550
1550
  readonly failureMode: "error";
1551
- }, SubagentHost>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Project, import("effect/Scope").Scope> | Exclude<Output["DecodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["DecodingServices"], import("effect/Scope").Scope> | Exclude<Success["EncodingServices"], import("effect/Scope").Scope>>;
1551
+ }, SubagentHost, Tool.Execution>] ? T extends readonly Tool.Any[] ? { readonly [Tool in T[number] as Tool["name"]]: Tool; } : never : never : never>, never, Exclude<Project, import("effect/Scope").Scope> | Exclude<Output["DecodingServices"], import("effect/Scope").Scope> | Exclude<Parameters["DecodingServices"], import("effect/Scope").Scope> | Exclude<Success["EncodingServices"], import("effect/Scope").Scope>>;
1552
1552
  }>;
1553
1553
  /** Inspect a continuing worker's state and latest accepted input. */
1554
1554
  declare const summaryTool: <const Name extends string, Input extends Schema.Top, Output extends Schema.Top, Parameters extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, Prepare, Project>(declaration: Declaration<Name, Input, Output, Parameters, Success, Failure, Prepare, Project>) => Readonly<{
@@ -1653,7 +1653,7 @@ declare const summaryTool: <const Name extends string, Input extends Schema.Top,
1653
1653
  }>;
1654
1654
  readonly failure: typeof WorkerError;
1655
1655
  readonly failureMode: "error";
1656
- }, SubagentHost>;
1656
+ }, SubagentHost, Tool.Execution>;
1657
1657
  layer: import("effect/Layer").Layer<Tool.HandlersFor<{ readonly [Tool in Tool.Tool<`${Name}_summary`, {
1658
1658
  readonly parameters: Schema.Struct<{
1659
1659
  readonly worker: Schema.refine<{
@@ -1755,7 +1755,7 @@ declare const summaryTool: <const Name extends string, Input extends Schema.Top,
1755
1755
  }>;
1756
1756
  readonly failure: typeof WorkerError;
1757
1757
  readonly failureMode: "error";
1758
- }, SubagentHost> as Tool["name"]]: Tool; }>, never, never>;
1758
+ }, SubagentHost, Tool.Execution> as Tool["name"]]: Tool; }>, never, never>;
1759
1759
  }>;
1760
1760
  /** List workers visible through the current caller's host facet. */
1761
1761
  declare const listTool: <const Name extends string, Input extends Schema.Top, Output extends Schema.Top, Parameters extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, Prepare, Project>(declaration: Declaration<Name, Input, Output, Parameters, Success, Failure, Prepare, Project>) => Readonly<{
@@ -1854,7 +1854,7 @@ declare const listTool: <const Name extends string, Input extends Schema.Top, Ou
1854
1854
  }>;
1855
1855
  readonly failure: typeof WorkerError;
1856
1856
  readonly failureMode: "error";
1857
- }, SubagentHost>;
1857
+ }, SubagentHost, Tool.Execution>;
1858
1858
  layer: import("effect/Layer").Layer<Tool.HandlersFor<{ readonly [Tool in Tool.Tool<`${Name}_list`, {
1859
1859
  readonly parameters: Schema.Struct<{
1860
1860
  readonly limit: Schema.optionalKey<Schema.Int>;
@@ -1950,7 +1950,7 @@ declare const listTool: <const Name extends string, Input extends Schema.Top, Ou
1950
1950
  }>;
1951
1951
  readonly failure: typeof WorkerError;
1952
1952
  readonly failureMode: "error";
1953
- }, SubagentHost> as Tool["name"]]: Tool; }>, never, never>;
1953
+ }, SubagentHost, Tool.Execution> as Tool["name"]]: Tool; }>, never, never>;
1954
1954
  }>;
1955
1955
  /** Request cancellation of one exact worker Receipt. */
1956
1956
  declare const cancelTool: <const Name extends string, Input extends Schema.Top, Output extends Schema.Top, Parameters extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, Prepare, Project>(declaration: Declaration<Name, Input, Output, Parameters, Success, Failure, Prepare, Project>) => Readonly<{
@@ -1972,7 +1972,7 @@ declare const cancelTool: <const Name extends string, Input extends Schema.Top,
1972
1972
  readonly success: Schema.Void;
1973
1973
  readonly failure: Schema.Union<readonly [typeof WorkerError, typeof JoinedToHost]>;
1974
1974
  readonly failureMode: "error";
1975
- }, SubagentHost>;
1975
+ }, SubagentHost, Tool.Execution>;
1976
1976
  layer: import("effect/Layer").Layer<Tool.HandlersFor<{ readonly [Tool in Tool.Tool<`${Name}_cancel`, {
1977
1977
  readonly parameters: Schema.Struct<{
1978
1978
  readonly worker: Schema.refine<{
@@ -1991,7 +1991,7 @@ declare const cancelTool: <const Name extends string, Input extends Schema.Top,
1991
1991
  readonly success: Schema.Void;
1992
1992
  readonly failure: Schema.Union<readonly [typeof WorkerError, typeof JoinedToHost]>;
1993
1993
  readonly failureMode: "error";
1994
- }, SubagentHost> as Tool["name"]]: Tool; }>, never, never>;
1994
+ }, SubagentHost, Tool.Execution> as Tool["name"]]: Tool; }>, never, never>;
1995
1995
  }>;
1996
1996
  interface ReportingOptions {
1997
1997
  /**
@@ -2,7 +2,7 @@ import * as Context from "effect/Context";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Stream from "effect/Stream";
5
- import { r as AnyDefinition } from "./Agent-DSVEpq4e.mjs";
5
+ import { r as AnyDefinition } from "./Agent-BH_R6LOI.mjs";
6
6
  import { t as AgentPolicy } from "./AgentPolicy-D-GmZQex.mjs";
7
7
  import { r as Update } from "./AgentUpdates-7xT0It_R.mjs";
8
8
  import { i as Failure } from "./FailureDiagnostic-DpzYNI8f.mjs";
@@ -5,9 +5,9 @@ import * as Context from "effect/Context";
5
5
  import * as Effect from "effect/Effect";
6
6
  import * as Schema from "effect/Schema";
7
7
  import { a as Receipt, r as Principal } from "./Receipt-B4feBxMY.mjs";
8
- import { i as PreparedInputAuthorizationDecision } from "./PreparedInputAdmission-Ci18uY4s.mjs";
8
+ import { i as PreparedInputAuthorizationDecision } from "./PreparedInputAdmission-DYugcCHR.mjs";
9
9
  import { S as Digest, b as DefinitionDigests } from "./Records-C9I1nCL9.mjs";
10
- import "./Admin-BfolLkHj.mjs";
10
+ import "./Admin-26pelcl9.mjs";
11
11
  declare namespace Subscription_d_exports {
12
12
  export { AcceptedEvent, DeliveryChange, EventAcknowledgement, EventSourceVersion, SourcePartition, SourceRecovery, SubscriptionAuthorizer, SubscriptionChange, SubscriptionConfiguration, SubscriptionDelivery, SubscriptionDeliveryKey, SubscriptionDeliverySnapshot, SubscriptionError, SubscriptionFailpoint, SubscriptionFailpointError, SubscriptionKey, SubscriptionLimits, SubscriptionName, SubscriptionRecord, SubscriptionRefusal, SubscriptionRetentionPolicy, SubscriptionScanCursors, SubscriptionScope, SubscriptionSnapshot, SubscriptionSourceError, SubscriptionStore, SubscriptionStoreFailure, defaultSubscriptionLimits, subscriptionDeliveryKeyString, subscriptionKeyString };
13
13
  }
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
2
2
  import * as Context from "effect/Context";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Schema from "effect/Schema";
5
- import { o as definitionDigestsEqual } from "./agent-registration-CNs2twrr.mjs";
5
+ import { o as definitionDigestsEqual } from "./agent-registration-D9ofkoBa.mjs";
6
6
  import { U as PersistedJson } from "./Records-C645aQks.mjs";
7
7
  import { T as SubscriptionSourceError, p as SubscriptionError } from "./Subscription-BhQbmUD-.mjs";
8
8
  // src/durable/SubscriptionInput.ts
@@ -50,4 +50,4 @@ const makeSubscriptionInputBinding = Effect.fnUntraced(function* (options) {
50
50
  });
51
51
  export { resolveSubscriptionInput as i, SubscriptionInput_exports as n, makeSubscriptionInputBinding as r, SubscriptionInputBindings as t };
52
52
 
53
- //# sourceMappingURL=SubscriptionInput-Xcd4JjEs.mjs.map
53
+ //# sourceMappingURL=SubscriptionInput-BbV69oX_.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionInput-Xcd4JjEs.mjs","names":[],"sources":["../src/durable/SubscriptionInput.ts"],"sourcesContent":["import * as Context from 'effect/Context'\nimport * as Effect from 'effect/Effect'\nimport * as Schema from 'effect/Schema'\nimport type * as Scope from 'effect/Scope'\n\nimport { type AgentId } from '../core/Identifiers'\nimport { definitionDigestsEqual } from './internal/agent-registration'\nimport { type DefinitionDigests, PersistedJson } from './Records'\nimport {\n type AcceptedEvent,\n type EventSourceVersion,\n type SubscriptionConfiguration,\n SubscriptionError,\n type SubscriptionRecord,\n SubscriptionSourceError,\n} from './Subscription'\n\n/** Host-retained preparation code for one source and exact destination Agent definition. */\nexport interface SubscriptionInputBinding {\n readonly source: EventSourceVersion\n readonly agentId: AgentId\n readonly definitions: DefinitionDigests\n readonly context: (value: unknown) => Effect.Effect<PersistedJson, SubscriptionSourceError>\n readonly prepare: (\n event: AcceptedEvent,\n subscription: SubscriptionRecord,\n ) => Effect.Effect<PersistedJson, SubscriptionSourceError>\n}\n\nexport class SubscriptionInputBindings extends Context.Service<\n SubscriptionInputBindings,\n { readonly bindings: ReadonlyArray<SubscriptionInputBinding> }\n>()('@effect-agent/thread/SubscriptionInputBindings') {}\n\n/** Missing or ambiguous code stays pending. Never substitute a newer destination definition. */\nexport const resolveSubscriptionInput = (\n bindings: ReadonlyArray<SubscriptionInputBinding>,\n configuration: Pick<SubscriptionConfiguration, 'source' | 'agentId' | 'definitions'>,\n): Effect.Effect<SubscriptionInputBinding, SubscriptionError> => {\n const found = bindings.filter(\n (binding) =>\n binding.source.name === configuration.source.name &&\n binding.source.version === configuration.source.version &&\n binding.agentId === configuration.agentId &&\n definitionDigestsEqual(binding.definitions, configuration.definitions),\n )\n\n const binding = found[0]\n\n return found.length === 1 && binding !== undefined\n ? Effect.succeed(binding)\n : Effect.fail(SubscriptionError.make({ reason: 'unsupported-binding', code: 'input-binding' }))\n}\n\n/**\n * Capture explicit dependencies at host assembly. Pass the destination definition's input Schema.\n * Include the context Schema and mapper in its retained definition version; changing either\n * requires new definition digests. Preparation may repeat until its envelope is committed.\n * Each operation owns a fresh Scope for its callbacks and codecs; captured host services\n * retain their host lifetime. Operation resources finalize on success, failure, or interruption.\n */\nexport const makeSubscriptionInputBinding = Effect.fnUntraced(function*<\n Event extends Schema.Top,\n Parameters extends Schema.Top,\n Continuation extends Schema.Top,\n Input extends Schema.Top,\n R,\n>(options: {\n readonly source: EventSourceVersion\n readonly agentId: AgentId\n readonly definitions: DefinitionDigests\n readonly event: Event\n readonly parameters: Parameters\n readonly context: Continuation\n readonly input: Input\n readonly prepare: (\n event: Event['Type'],\n parameters: Parameters['Type'],\n context: Continuation['Type'],\n ) => Effect.Effect<Input['Type'], SubscriptionSourceError, R>\n}): Effect.fn.Return<\n SubscriptionInputBinding,\n never,\n Exclude<\n | R\n | Event['DecodingServices']\n | Parameters['DecodingServices']\n | Continuation['DecodingServices']\n | Continuation['EncodingServices']\n | Input['EncodingServices'],\n Scope.Scope\n >\n> {\n const services = yield* Effect.context<\n Exclude<\n | R\n | Event['DecodingServices']\n | Parameters['DecodingServices']\n | Continuation['DecodingServices']\n | Continuation['EncodingServices']\n | Input['EncodingServices'],\n Scope.Scope\n >\n >()\n\n const invalid = () => SubscriptionSourceError.make({ code: 'input-binding-schema', retryable: false })\n\n const encode = <S extends Schema.Top>(schema: S, value: S['Type']) =>\n Schema.encodeEffect(schema)(value).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(PersistedJson)),\n Effect.mapError(invalid),\n )\n\n return {\n source: options.source,\n agentId: options.agentId,\n definitions: options.definitions,\n context: (value) =>\n Schema.decodeUnknownEffect(PersistedJson)(value).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(options.context)),\n Effect.mapError(invalid),\n Effect.flatMap((decoded) => encode(options.context, decoded)),\n Effect.scoped,\n Effect.provideContext(services),\n ),\n prepare: Effect.fnUntraced(\n function*(event, subscription) {\n const e = yield* Schema.decodeEffect(options.event)(event.payload).pipe(\n Effect.mapError(invalid),\n )\n\n const p = yield* Schema.decodeEffect(options.parameters)(\n subscription.configuration.parameters,\n ).pipe(Effect.mapError(invalid))\n\n const c = yield* Schema.decodeEffect(options.context)(\n subscription.configuration.context,\n ).pipe(Effect.mapError(invalid))\n\n return yield* encode(options.input, yield* options.prepare(e, p, c))\n },\n (effect) => effect.pipe(Effect.scoped, Effect.provideContext(services)),\n ),\n }\n})\n"],"mappings":";;;;;;;;;;;;;AA6BA,IAAa,4BAAb,cAA+C,QAAQ,QAGrD,CAAC,CAAC,gDAAgD,CAAC,CAAC,CAAC;;AAGvD,MAAa,4BACX,UACA,kBAC+D;CAC/D,MAAM,QAAQ,SAAS,QACpB,YACC,QAAQ,OAAO,SAAS,cAAc,OAAO,QAC7C,QAAQ,OAAO,YAAY,cAAc,OAAO,WAChD,QAAQ,YAAY,cAAc,WAClC,uBAAuB,QAAQ,aAAa,cAAc,WAAW,CACzE;CAEA,MAAM,UAAU,MAAM;CAEtB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAA,IACrC,OAAO,QAAQ,OAAO,IACtB,OAAO,KAAK,kBAAkB,KAAK;EAAE,QAAQ;EAAuB,MAAM;CAAgB,CAAC,CAAC;AAClG;;;;;;;;AASA,MAAa,+BAA+B,OAAO,WAAW,WAM5D,SAyBA;CACA,MAAM,WAAW,OAAO,OAAO,QAU7B;CAEF,MAAM,gBAAgB,wBAAwB,KAAK;EAAE,MAAM;EAAwB,WAAW;CAAM,CAAC;CAErG,MAAM,UAAgC,QAAW,UAC/C,OAAO,aAAa,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KACjC,OAAO,QAAQ,OAAO,oBAAoB,aAAa,CAAC,GACxD,OAAO,SAAS,OAAO,CACzB;CAEF,OAAO;EACL,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,UAAU,UACR,OAAO,oBAAoB,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC,KAC/C,OAAO,QAAQ,OAAO,oBAAoB,QAAQ,OAAO,CAAC,GAC1D,OAAO,SAAS,OAAO,GACvB,OAAO,SAAS,YAAY,OAAO,QAAQ,SAAS,OAAO,CAAC,GAC5D,OAAO,QACP,OAAO,eAAe,QAAQ,CAChC;EACF,SAAS,OAAO,WACd,WAAU,OAAO,cAAc;GAC7B,MAAM,IAAI,OAAO,OAAO,aAAa,QAAQ,KAAK,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,KACjE,OAAO,SAAS,OAAO,CACzB;GAEA,MAAM,IAAI,OAAO,OAAO,aAAa,QAAQ,UAAU,CAAC,CACtD,aAAa,cAAc,UAC7B,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;GAE/B,MAAM,IAAI,OAAO,OAAO,aAAa,QAAQ,OAAO,CAAC,CACnD,aAAa,cAAc,OAC7B,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;GAE/B,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,QAAQ,QAAQ,GAAG,GAAG,CAAC,CAAC;EACrE,IACC,WAAW,OAAO,KAAK,OAAO,QAAQ,OAAO,eAAe,QAAQ,CAAC,CACxE;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"SubscriptionInput-BbV69oX_.mjs","names":[],"sources":["../src/durable/SubscriptionInput.ts"],"sourcesContent":["import * as Context from 'effect/Context'\nimport * as Effect from 'effect/Effect'\nimport * as Schema from 'effect/Schema'\nimport type * as Scope from 'effect/Scope'\n\nimport { type AgentId } from '../core/Identifiers'\nimport { definitionDigestsEqual } from './internal/agent-registration'\nimport { type DefinitionDigests, PersistedJson } from './Records'\nimport {\n type AcceptedEvent,\n type EventSourceVersion,\n type SubscriptionConfiguration,\n SubscriptionError,\n type SubscriptionRecord,\n SubscriptionSourceError,\n} from './Subscription'\n\n/** Host-retained preparation code for one source and exact destination Agent definition. */\nexport interface SubscriptionInputBinding {\n readonly source: EventSourceVersion\n readonly agentId: AgentId\n readonly definitions: DefinitionDigests\n readonly context: (value: unknown) => Effect.Effect<PersistedJson, SubscriptionSourceError>\n readonly prepare: (\n event: AcceptedEvent,\n subscription: SubscriptionRecord,\n ) => Effect.Effect<PersistedJson, SubscriptionSourceError>\n}\n\nexport class SubscriptionInputBindings extends Context.Service<\n SubscriptionInputBindings,\n { readonly bindings: ReadonlyArray<SubscriptionInputBinding> }\n>()('@effect-agent/thread/SubscriptionInputBindings') {}\n\n/** Missing or ambiguous code stays pending. Never substitute a newer destination definition. */\nexport const resolveSubscriptionInput = (\n bindings: ReadonlyArray<SubscriptionInputBinding>,\n configuration: Pick<SubscriptionConfiguration, 'source' | 'agentId' | 'definitions'>,\n): Effect.Effect<SubscriptionInputBinding, SubscriptionError> => {\n const found = bindings.filter(\n (binding) =>\n binding.source.name === configuration.source.name &&\n binding.source.version === configuration.source.version &&\n binding.agentId === configuration.agentId &&\n definitionDigestsEqual(binding.definitions, configuration.definitions),\n )\n\n const binding = found[0]\n\n return found.length === 1 && binding !== undefined\n ? Effect.succeed(binding)\n : Effect.fail(SubscriptionError.make({ reason: 'unsupported-binding', code: 'input-binding' }))\n}\n\n/**\n * Capture explicit dependencies at host assembly. Pass the destination definition's input Schema.\n * Include the context Schema and mapper in its retained definition version; changing either\n * requires new definition digests. Preparation may repeat until its envelope is committed.\n * Each operation owns a fresh Scope for its callbacks and codecs; captured host services\n * retain their host lifetime. Operation resources finalize on success, failure, or interruption.\n */\nexport const makeSubscriptionInputBinding = Effect.fnUntraced(function*<\n Event extends Schema.Top,\n Parameters extends Schema.Top,\n Continuation extends Schema.Top,\n Input extends Schema.Top,\n R,\n>(options: {\n readonly source: EventSourceVersion\n readonly agentId: AgentId\n readonly definitions: DefinitionDigests\n readonly event: Event\n readonly parameters: Parameters\n readonly context: Continuation\n readonly input: Input\n readonly prepare: (\n event: Event['Type'],\n parameters: Parameters['Type'],\n context: Continuation['Type'],\n ) => Effect.Effect<Input['Type'], SubscriptionSourceError, R>\n}): Effect.fn.Return<\n SubscriptionInputBinding,\n never,\n Exclude<\n | R\n | Event['DecodingServices']\n | Parameters['DecodingServices']\n | Continuation['DecodingServices']\n | Continuation['EncodingServices']\n | Input['EncodingServices'],\n Scope.Scope\n >\n> {\n const services = yield* Effect.context<\n Exclude<\n | R\n | Event['DecodingServices']\n | Parameters['DecodingServices']\n | Continuation['DecodingServices']\n | Continuation['EncodingServices']\n | Input['EncodingServices'],\n Scope.Scope\n >\n >()\n\n const invalid = () => SubscriptionSourceError.make({ code: 'input-binding-schema', retryable: false })\n\n const encode = <S extends Schema.Top>(schema: S, value: S['Type']) =>\n Schema.encodeEffect(schema)(value).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(PersistedJson)),\n Effect.mapError(invalid),\n )\n\n return {\n source: options.source,\n agentId: options.agentId,\n definitions: options.definitions,\n context: (value) =>\n Schema.decodeUnknownEffect(PersistedJson)(value).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(options.context)),\n Effect.mapError(invalid),\n Effect.flatMap((decoded) => encode(options.context, decoded)),\n Effect.scoped,\n Effect.provideContext(services),\n ),\n prepare: Effect.fnUntraced(\n function*(event, subscription) {\n const e = yield* Schema.decodeEffect(options.event)(event.payload).pipe(\n Effect.mapError(invalid),\n )\n\n const p = yield* Schema.decodeEffect(options.parameters)(\n subscription.configuration.parameters,\n ).pipe(Effect.mapError(invalid))\n\n const c = yield* Schema.decodeEffect(options.context)(\n subscription.configuration.context,\n ).pipe(Effect.mapError(invalid))\n\n return yield* encode(options.input, yield* options.prepare(e, p, c))\n },\n (effect) => effect.pipe(Effect.scoped, Effect.provideContext(services)),\n ),\n }\n})\n"],"mappings":";;;;;;;;;;;;;AA6BA,IAAa,4BAAb,cAA+C,QAAQ,QAGrD,CAAC,CAAC,gDAAgD,CAAC,CAAC,CAAC;;AAGvD,MAAa,4BACX,UACA,kBAC+D;CAC/D,MAAM,QAAQ,SAAS,QACpB,YACC,QAAQ,OAAO,SAAS,cAAc,OAAO,QAC7C,QAAQ,OAAO,YAAY,cAAc,OAAO,WAChD,QAAQ,YAAY,cAAc,WAClC,uBAAuB,QAAQ,aAAa,cAAc,WAAW,CACzE;CAEA,MA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AAQ,OAAO,OAAO,QAAQ,QAAQ,GAAG,GAAG,CAAC,CAAC;EACrE,IACC,WAAW,OAAO,KAAK,OAAO,QAAQ,OAAO,eAAe,QAAQ,CAAC,CACxE;CACF;AACF,CAAC"}
@@ -4,7 +4,7 @@ import * as Schema from "effect/Schema";
4
4
  import * as Scope from "effect/Scope";
5
5
  import { t as AgentId } from "./Identifiers-qafW4EP0.mjs";
6
6
  import { K as PersistedJson, b as DefinitionDigests } from "./Records-C9I1nCL9.mjs";
7
- import { T as SubscriptionSourceError, i as EventSourceVersion, l as SubscriptionConfiguration, p as SubscriptionError, t as AcceptedEvent, y as SubscriptionRecord } from "./Subscription-CC--_OnU.mjs";
7
+ import { T as SubscriptionSourceError, i as EventSourceVersion, l as SubscriptionConfiguration, p as SubscriptionError, t as AcceptedEvent, y as SubscriptionRecord } from "./Subscription-BJ0TtZwM.mjs";
8
8
  declare namespace SubscriptionInput_d_exports {
9
9
  export { SubscriptionInputBinding, SubscriptionInputBindings, makeSubscriptionInputBinding, resolveSubscriptionInput };
10
10
  }
@@ -1,5 +1,5 @@
1
1
  import * as Result from "effect/Result";
2
- import { _ as SubscriptionLimits, a as SourcePartition, c as SubscriptionChange, n as DeliveryChange, p as SubscriptionError, t as AcceptedEvent, u as SubscriptionDelivery, y as SubscriptionRecord } from "./Subscription-CC--_OnU.mjs";
2
+ import { _ as SubscriptionLimits, a as SourcePartition, c as SubscriptionChange, n as DeliveryChange, p as SubscriptionError, t as AcceptedEvent, u as SubscriptionDelivery, y as SubscriptionRecord } from "./Subscription-BJ0TtZwM.mjs";
3
3
  declare namespace SubscriptionTransition_d_exports {
4
4
  export { applySubscriptionChange, applySubscriptionDeliveryChange, sameAcceptedEventIdentity, sameSourcePartition, sameSubscriptionDelivery, subscriptionCanSelect, subscriptionDeliveryCanSelect, subscriptionDeliveryUsesCapacity, subscriptionMatchesEvent, subscriptionUsesCapacity, validateEventRetention };
5
5
  }
@@ -16,7 +16,7 @@ import { c as admitPreparedInput, n as PreparedInputAdmission, t as PreparedInpu
16
16
  import { v as DefinitionDigests } from "./Records-C645aQks.mjs";
17
17
  import { t as IdempotencyKey } from "./Receipt-B-FlCaNH.mjs";
18
18
  import { C as SubscriptionScope, E as SubscriptionStore, O as defaultSubscriptionLimits, T as SubscriptionSourceError, _ as SubscriptionLimits, g as SubscriptionKey, k as subscriptionDeliveryKeyString, l as SubscriptionConfiguration, m as SubscriptionFailpoint, p as SubscriptionError, s as SubscriptionAuthorizer, t as AcceptedEvent, u as SubscriptionDelivery } from "./Subscription-BhQbmUD-.mjs";
19
- import { i as resolveSubscriptionInput, t as SubscriptionInputBindings } from "./SubscriptionInput-Xcd4JjEs.mjs";
19
+ import { i as resolveSubscriptionInput, t as SubscriptionInputBindings } from "./SubscriptionInput-BbV69oX_.mjs";
20
20
  // src/durable/Subscriptions.ts
21
21
  var Subscriptions_exports = /* @__PURE__ */ __exportAll({
22
22
  SubscriptionDriver: () => SubscriptionDriver,
@@ -635,4 +635,4 @@ const makeDriver = Effect.fnUntraced(function* (requested) {
635
635
  });
636
636
  export { Subscriptions_exports as i, SubscriptionIntake as n, Subscriptions as r, SubscriptionDriver as t };
637
637
 
638
- //# sourceMappingURL=Subscriptions-4K_qu_2f.mjs.map
638
+ //# sourceMappingURL=Subscriptions-BS3AXmQ0.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Subscriptions-4K_qu_2f.mjs","names":[],"sources":["../src/durable/Subscriptions.ts"],"sourcesContent":["import * as Cause from 'effect/Cause'\nimport * as Context from 'effect/Context'\nimport * as CryptoDigest from 'effect/crypto/Digest'\nimport * as DateTime from 'effect/DateTime'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\nimport * as Option from 'effect/Option'\nimport * as Schema from 'effect/Schema'\nimport * as Semaphore from 'effect/Semaphore'\n\nimport { ThreadId } from '../core/Identifiers'\nimport { utf8ByteLength } from '../core/internal/utf8'\nimport { digestJson } from './Digest'\nimport { EventSources, type NormalizedEvent } from './EventSource'\nimport {\n admitPreparedInput,\n PreparedInput,\n PreparedInputAdmission,\n type PreparedInputRetryReason,\n} from './PreparedInputAdmission'\nimport { DefinitionDigests, type PersistedJson } from './Records'\nimport { type AdmissionFence, IdempotencyKey, type Principal } from './SubmissionLedger'\nimport {\n AcceptedEvent,\n defaultSubscriptionLimits,\n type EventAcknowledgement,\n type EventSourceVersion,\n SubscriptionAuthorizer,\n type SubscriptionChange,\n SubscriptionConfiguration,\n SubscriptionDelivery,\n type SubscriptionDeliveryKey,\n subscriptionDeliveryKeyString,\n type SubscriptionDeliverySnapshot,\n SubscriptionError,\n SubscriptionFailpoint,\n SubscriptionKey,\n SubscriptionLimits,\n type SubscriptionRecord,\n SubscriptionScope,\n type SubscriptionSnapshot,\n SubscriptionSourceError,\n SubscriptionStore,\n type SubscriptionStoreFailure,\n} from './Subscription'\nimport { resolveSubscriptionInput, SubscriptionInputBindings } from './SubscriptionInput'\n\nconst now = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis))\n\nconst failure = (reason: SubscriptionError['reason'], code: string) => SubscriptionError.make({ reason, code })\n\nconst bytes = (value: PersistedJson) => utf8ByteLength(JSON.stringify(value))\n\nconst sameSource = (a: EventSourceVersion, b: EventSourceVersion) => a.name === b.name && a.version === b.version\n\nconst samePartition = Schema.toEquivalence(SubscriptionScope.fields.partition)\n\nconst validate = <S extends Schema.Top>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => failure('validation', 'schema')),\n )\n\nconst snapshot = (record: SubscriptionRecord, time: number): SubscriptionSnapshot => ({\n key: record.key,\n configurationRevision: record.configurationRevision,\n configurationFingerprint: record.configurationFingerprint,\n ...(record.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: record.configuration.admissionGroup }),\n ...(record.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: record.configuration.admissionFence }),\n source: record.configuration.source,\n mode: record.configuration.mode,\n state: record.state === 'active' &&\n record.configuration.expiresAtMillis !== null &&\n record.configuration.expiresAtMillis <= time\n ? 'expired'\n : record.state,\n createdAtMillis: record.createdAtMillis,\n expiresAtMillis: record.configuration.expiresAtMillis,\n recovery: record.recovery,\n})\n\nconst deliverySnapshot = (\n record: SubscriptionDelivery,\n): typeof SubscriptionDeliverySnapshot.Type => ({\n key: record.key,\n state: record.state,\n configurationRevision: record.configurationRevision,\n ...(record.observeSettlement === undefined\n ? {}\n : { observeSettlement: record.observeSettlement }),\n ...(record.settledAtMillis === undefined ? {} : { settledAtMillis: record.settledAtMillis }),\n retry: record.retry,\n receipt: record.receipt,\n refusal: record.refusal,\n})\n\nexport interface SubscribeOptions {\n readonly subscriptionId: string\n readonly source: EventSourceVersion\n readonly parameters: PersistedJson\n readonly context: PersistedJson\n readonly mode: 'once' | 'continuous'\n readonly expiresAtMillis: number | null\n readonly destination: SubscriptionConfiguration['destination']\n readonly deliveryPrincipal: Principal\n readonly admissionGroup?: string\n readonly admissionFence?: AdmissionFence\n readonly agentId: SubscriptionConfiguration['agentId']\n readonly definitions: SubscriptionConfiguration['definitions']\n}\n\nexport type SubscriptionFailure = SubscriptionStoreFailure | SubscriptionSourceError\n\n/** Only management and redacted status. Do not provide intake or drivers to Agent Tools. */\nexport class Subscriptions extends Context.Service<\n Subscriptions,\n {\n readonly recoverSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly getSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionError>\n readonly subscribe: (\n scope: SubscriptionScope,\n options: SubscribeOptions,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>\n readonly updateSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n options: Omit<SubscribeOptions, 'subscriptionId'>,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>\n readonly pauseSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly resumeSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly listSubscriptions: (\n scope: SubscriptionScope,\n after?: number,\n limit?: number,\n ) => Effect.Effect<\n { readonly items: ReadonlyArray<SubscriptionSnapshot>; readonly next: number | null },\n SubscriptionError\n >\n readonly recoverDelivery: (\n scope: SubscriptionScope,\n key: SubscriptionDeliveryKey,\n expectedGeneration: number,\n ) => Effect.Effect<typeof SubscriptionDeliverySnapshot.Type, SubscriptionStoreFailure>\n readonly cancelSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision?: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly listDeliveries: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n after?: string,\n limit?: number,\n ) => Effect.Effect<\n {\n readonly items: ReadonlyArray<typeof SubscriptionDeliverySnapshot.Type>\n readonly next: string | null\n },\n SubscriptionError\n >\n }\n>()('@effect-agent/thread/Subscriptions') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(Subscriptions, makeManagement(limits))\n }\n}\n\n/** Trusted intake acknowledges retained routing work, never a Thread Submission Receipt. */\nexport class SubscriptionIntake extends Context.Service<\n SubscriptionIntake,\n {\n readonly accept: (\n principal: Principal,\n source: EventSourceVersion,\n payload: unknown,\n ) => Effect.Effect<EventAcknowledgement, SubscriptionFailure>\n readonly status: (\n principal: Principal,\n source: EventSourceVersion,\n eventId: string,\n ) => Effect.Effect<\n EventAcknowledgement & {\n readonly routingComplete: boolean\n readonly routingFailure: string | null\n readonly nextAttemptAtMillis: number\n },\n SubscriptionError\n >\n }\n>()('@effect-agent/thread/SubscriptionIntake') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(SubscriptionIntake, makeIntake(limits))\n }\n}\n\n/** One bounded sweep. The platform owns polling/alarm recovery; no subscription retains a Run. */\nexport class SubscriptionDriver extends Context.Service<\n SubscriptionDriver,\n {\n readonly runDue: Effect.Effect<\n { readonly processed: number; readonly failed: number },\n SubscriptionStoreFailure\n >\n readonly processDelivery: (\n key: SubscriptionDeliveryKey,\n ) => Effect.Effect<void, SubscriptionFailure>\n }\n>()('@effect-agent/thread/SubscriptionDriver') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(SubscriptionDriver, makeDriver(limits))\n }\n}\n\nconst dependencies = Effect.gen(function*() {\n const store = yield* SubscriptionStore\n const authorizer = yield* SubscriptionAuthorizer\n const sources = (yield* EventSources).sources\n const crypto = yield* CryptoDigest.Digest\n\n const digest = (value: PersistedJson) =>\n digestJson(value).pipe(\n Effect.provideService(CryptoDigest.Digest, crypto),\n Effect.mapError(() => failure('storage', 'digest')),\n )\n\n const source = (version: EventSourceVersion) => {\n const found = sources.filter((s) => sameSource(s.source, version))\n const item = found[0]\n\n return found.length === 1 && item !== undefined\n ? Effect.succeed(item)\n : Effect.fail(failure('unsupported-source', 'source-version'))\n }\n\n const scope = Effect.fnUntraced(function*(value: SubscriptionScope) {\n const decoded = yield* validate(SubscriptionScope, value)\n\n if (!samePartition(decoded.partition, store.partition)) {\n return yield* failure('unauthorized', 'partition')\n }\n\n return decoded\n })\n\n const acceptNormalized = Effect.fnUntraced(function*(\n version: EventSourceVersion,\n event: NormalizedEvent,\n limits: SubscriptionLimits,\n ) {\n const time = yield* now\n\n const record = yield* validate(AcceptedEvent, {\n schemaVersion: 1,\n partition: store.partition,\n eventId: event.eventId,\n source: version,\n matchingKey: event.matchingKey,\n payload: event.payload,\n payloadDigest: yield* digest(event.payload),\n acceptedAtMillis: time,\n ...(event.occurredAtMillis === undefined ? {} : { occurredAtMillis: event.occurredAtMillis }),\n cutoff: 0,\n cursor: 0,\n routingComplete: false,\n routingFailure: null,\n nextAttemptAtMillis: time,\n })\n\n const retained = yield* store.accept(record, limits)\n\n if (retained.tombstone !== true && (yield* digest(retained.payload)) !== retained.payloadDigest) {\n return yield* failure('corrupt', 'event-digest')\n }\n\n return retained\n })\n\n return { store, authorizer, source, digest, scope, acceptNormalized }\n})\n\nconst pageLimit = (value: number) =>\n validate(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)), value)\n\nconst makeManagement = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { bindings } = yield* SubscriptionInputBindings\n const { store, authorizer, source, digest, scope } = yield* dependencies\n\n const subscribe: Subscriptions['Service']['subscribe'] = Effect.fnUntraced(\n function*(scopeValue, options) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('subscribe', owner)\n const behavior = yield* source(options.source)\n const params = yield* behavior.parameters(options.parameters)\n const binding = yield* resolveSubscriptionInput(bindings, options)\n const context = yield* binding.context(options.context)\n\n const configuration = yield* validate(SubscriptionConfiguration, {\n ...options,\n parameters: params.parameters,\n context,\n matchingKey: params.matchingKey,\n })\n\n yield* authorizer.manage('subscribe', owner, configuration)\n\n const key = yield* validate(SubscriptionKey, {\n partition: owner.partition,\n ownerId: owner.ownerId,\n subscriptionId: options.subscriptionId,\n })\n\n const encodedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n configuration,\n ).pipe(Effect.mapError(() => failure('validation', 'configuration')))\n\n const creationFingerprint = yield* digest({\n key,\n createdBy: owner.principal,\n configuration: encodedConfiguration,\n })\n\n const existing = yield* store.get(key)\n\n if (existing !== null) {\n const retainedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n existing.creationConfiguration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'creation-configuration')))\n\n const retainedFingerprint = yield* digest({\n key: existing.key,\n createdBy: existing.createdBy,\n configuration: retainedConfiguration,\n })\n\n if (retainedFingerprint !== existing.creationFingerprint) {\n return yield* failure('corrupt', 'creation-fingerprint')\n }\n\n const currentConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n existing.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n if (\n (yield* digest({\n key: existing.key,\n createdBy: existing.createdBy,\n configuration: currentConfiguration,\n })) !== existing.configurationFingerprint\n ) {\n return yield* failure('corrupt', 'creation-fingerprint')\n }\n if (existing.creationFingerprint !== creationFingerprint) {\n return yield* failure('conflict', 'creation')\n }\n\n return snapshot(existing, yield* now)\n }\n if (\n bytes(params.parameters) > limits.maxPayloadBytes ||\n bytes(context) > limits.maxContextBytes\n ) {\n return yield* failure('validation', 'registration-bounds')\n }\n const time = yield* now\n\n if (\n configuration.expiresAtMillis !== null &&\n (configuration.expiresAtMillis <= time ||\n configuration.expiresAtMillis - time > limits.maxLifetimeMillis)\n ) {\n return yield* failure('validation', 'lifetime')\n }\n if (behavior.reconcile !== undefined && configuration.mode !== 'once') {\n return yield* failure('validation', 'reconciliation-requires-once')\n }\n\n const record = yield* store.register(\n {\n schemaVersion: 1,\n key,\n creationFingerprint,\n configurationRevision: 1,\n configurationFingerprint: creationFingerprint,\n creationConfiguration: configuration,\n createdBy: owner.principal,\n createdAtMillis: time,\n ordinal: 0,\n configuration,\n state: 'active',\n recovery: behavior.reconcile === undefined\n ? null\n : { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },\n },\n limits,\n )\n\n return snapshot(record, time)\n },\n )\n\n const listSubscriptions: Subscriptions['Service']['listSubscriptions'] = Effect.fnUntraced(\n function*(scopeValue, after = 0, requestedLimit = 50) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('list', owner)\n const limit = yield* pageLimit(requestedLimit)\n\n yield* validate(Schema.Natural, after)\n const records = yield* store.list(owner.ownerId, after, limit)\n const time = yield* now\n\n return {\n items: records.map((record) => snapshot(record, time)),\n next: records.length === limit ? (records.at(-1)?.ordinal ?? null) : null,\n }\n },\n )\n\n const ownedKey = Effect.fnUntraced(function*(owner: SubscriptionScope, key: SubscriptionKey) {\n yield* validate(SubscriptionKey, key)\n if (!samePartition(owner.partition, key.partition) || owner.ownerId !== key.ownerId) {\n return yield* failure('unauthorized', 'owner')\n }\n\n return key\n })\n\n const updateSubscription: Subscriptions['Service']['updateSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key, expectedRevision, options) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('update', owner)\n yield* ownedKey(owner, key)\n const behavior = yield* source(options.source)\n const parameters = yield* behavior.parameters(options.parameters)\n const binding = yield* resolveSubscriptionInput(bindings, options)\n const context = yield* binding.context(options.context)\n\n const configuration = yield* validate(SubscriptionConfiguration, {\n ...options,\n ...parameters,\n context,\n })\n\n yield* authorizer.manage('update', owner, configuration)\n const time = yield* now\n\n if (\n bytes(parameters.parameters) > limits.maxPayloadBytes ||\n bytes(context) > limits.maxContextBytes\n ) {\n return yield* failure('validation', 'registration-bounds')\n }\n if (\n configuration.expiresAtMillis !== null &&\n (configuration.expiresAtMillis <= time ||\n configuration.expiresAtMillis - time > limits.maxLifetimeMillis)\n ) {\n return yield* failure('validation', 'lifetime')\n }\n if (behavior.reconcile !== undefined && configuration.mode !== 'once') {\n return yield* failure('validation', 'reconciliation-requires-once')\n }\n const existing = yield* store.get(key)\n\n if (existing === null) return yield* failure('not-found', 'subscription')\n\n const encoded = yield* Schema.encodeEffect(SubscriptionConfiguration)(configuration).pipe(\n Effect.mapError(() => failure('validation', 'configuration')),\n )\n\n const configurationFingerprint = yield* digest({\n key,\n createdBy: existing.createdBy,\n configuration: encoded,\n })\n\n const updated = yield* store.change(\n key,\n expectedRevision,\n {\n _tag: 'Update',\n configuration,\n configurationFingerprint,\n recovery: behavior.reconcile === undefined\n ? null\n : { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },\n },\n limits,\n )\n\n return snapshot(updated, time)\n },\n )\n\n const changeState = Effect.fnUntraced(function*(\n scopeValue: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n change: Extract<SubscriptionChange, { readonly _tag: 'Pause' | 'Resume' }>,\n ) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage(change._tag === 'Pause' ? 'pause' : 'resume', owner)\n\n const updated = yield* store.change(\n yield* ownedKey(owner, key),\n expectedRevision,\n change,\n limits,\n )\n\n return snapshot(updated, yield* now)\n })\n\n const cancelSubscription: Subscriptions['Service']['cancelSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key, expectedRevision) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('cancel', owner)\n const record = yield* store.cancel(yield* ownedKey(owner, key), expectedRevision)\n\n return snapshot(record, yield* now)\n },\n )\n\n const listDeliveries: Subscriptions['Service']['listDeliveries'] = Effect.fnUntraced(function*(\n scopeValue,\n key,\n after = '',\n requestedLimit = 50,\n ) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('deliveries', owner)\n const limit = yield* pageLimit(requestedLimit)\n const records = yield* store.listDeliveries(yield* ownedKey(owner, key), after, limit)\n const last = records.at(-1)\n\n return {\n items: records.map(deliverySnapshot),\n next: records.length === limit && last !== undefined\n ? subscriptionDeliveryKeyString(last.key)\n : null,\n }\n })\n\n const recoverDelivery: Subscriptions['Service']['recoverDelivery'] = Effect.fn(\n 'Subscriptions.recoverDelivery',\n )(function*(scopeValue, key, expectedGeneration) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('recover', owner)\n yield* ownedKey(owner, key.subscription)\n const existing = yield* store.delivery(key)\n\n if (existing === null) return yield* failure('not-found', 'delivery')\n\n const recovered = yield* store.changeDelivery(key, existing.deliveryId, {\n _tag: 'Recover',\n expectedGeneration,\n nowMillis: yield* now,\n })\n\n return deliverySnapshot(recovered)\n })\n\n const getSubscription: Subscriptions['Service']['getSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('get', owner)\n const record = yield* store.get(yield* ownedKey(owner, key))\n\n if (record === null) return yield* failure('not-found', 'subscription')\n\n return snapshot(record, yield* now)\n },\n )\n\n return Subscriptions.of({\n getSubscription,\n recoverSubscription: Effect.fnUntraced(function*(scopeValue, key, expectedRevision) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('recover', owner)\n\n return snapshot(\n yield* store.change(\n yield* ownedKey(owner, key),\n expectedRevision,\n {\n _tag: 'Recover',\n nowMillis: yield* now,\n },\n limits,\n ),\n yield* now,\n )\n }),\n recoverDelivery,\n subscribe,\n updateSubscription,\n pauseSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Pause' }),\n resumeSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Resume' }),\n listSubscriptions,\n cancelSubscription,\n listDeliveries,\n })\n})\n\nconst makeIntake = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { store, authorizer, source, acceptNormalized } = yield* dependencies\n\n const accept: SubscriptionIntake['Service']['accept'] = Effect.fnUntraced(\n function*(principal, version, payload) {\n yield* authorizer.intake(store.partition, version, principal)\n const behavior = yield* source(version)\n const event = yield* behavior.normalize(payload)\n const accepted = yield* acceptNormalized(version, event, limits)\n\n return {\n partition: accepted.partition,\n eventId: accepted.eventId,\n acceptedAtMillis: accepted.acceptedAtMillis,\n }\n },\n )\n\n const status: SubscriptionIntake['Service']['status'] = Effect.fnUntraced(\n function*(principal, version, eventId) {\n yield* authorizer.intake(store.partition, version, principal)\n const event = yield* store.event(eventId)\n\n if (event === null) return yield* failure('not-found', 'event')\n if (!sameSource(event.source, version)) return yield* failure('conflict', 'event-source')\n\n return {\n partition: event.partition,\n eventId: event.eventId,\n acceptedAtMillis: event.acceptedAtMillis,\n routingComplete: event.routingComplete,\n routingFailure: event.routingFailure,\n nextAttemptAtMillis: event.nextAttemptAtMillis,\n }\n },\n )\n\n return SubscriptionIntake.of({ accept, status })\n})\n\nconst makeDriver = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { bindings } = yield* SubscriptionInputBindings\n const { store, authorizer, source, digest, acceptNormalized } = yield* dependencies\n const admission = yield* PreparedInputAdmission\n\n if (limits.retention !== undefined && admission.submissionStatus === undefined) {\n return yield* failure('validation', 'retention-requires-submission-status')\n }\n const failpoint = yield* SubscriptionFailpoint\n const semaphore = yield* Semaphore.make(limits.concurrency)\n const sweepSemaphore = yield* Semaphore.make(1)\n const definitionEquals = Schema.toEquivalence(DefinitionDigests)\n const nextAttempt = (time: number) => Math.min(time + limits.retryMillis, 8_640_000_000_000_000)\n\n const selected = Effect.fnUntraced(function*(\n event: AcceptedEvent,\n subscription: SubscriptionRecord,\n ) {\n const deliveryId = yield* digest({\n schemaVersion: 1,\n subscription: subscription.key,\n eventId: event.eventId,\n })\n\n const time = yield* now\n\n return yield* validate(SubscriptionDelivery, {\n schemaVersion: 1,\n key: { subscription: subscription.key, eventId: event.eventId },\n deliveryId,\n subscriptionFingerprint: subscription.configurationFingerprint,\n configurationRevision: subscription.configurationRevision,\n configuration: subscription.configuration,\n eventDigest: event.payloadDigest,\n source: event.source,\n threadId: subscription.configuration.destination._tag === 'ExistingThread'\n ? subscription.configuration.destination.threadId\n : yield* Schema.decodeEffect(ThreadId)(`subscription:${deliveryId}`).pipe(Effect.orDie),\n admissionKey: yield* Schema.decodeEffect(IdempotencyKey)(`subscription:${deliveryId}`).pipe(\n Effect.orDie,\n ),\n selectedAtMillis: time,\n ...(limits.retention === undefined ? {} : { observeSettlement: true }),\n state: 'selected',\n envelope: null,\n envelopeDigest: null,\n retry: {\n generation: 0,\n attempts: 0,\n automaticAttempts: 0,\n parked: false,\n nextAttemptAtMillis: time,\n lastAttemptAtMillis: null,\n lastFailure: null,\n },\n receipt: null,\n refusal: null,\n })\n })\n\n const route = Effect.fnUntraced(function*(event: AcceptedEvent) {\n const behavior = yield* source(event.source)\n const normalized = yield* behavior.normalize(event.payload)\n\n if (\n normalized.eventId !== event.eventId ||\n normalized.occurredAtMillis !== event.occurredAtMillis ||\n normalized.matchingKey !== event.matchingKey ||\n (yield* digest(normalized.payload)) !== event.payloadDigest ||\n (yield* digest(event.payload)) !== event.payloadDigest\n ) {\n return yield* failure('corrupt', 'event-source-bindings')\n }\n const candidates = yield* store.candidates(event, limits.batchSize)\n const deliveries: Array<SubscriptionDelivery> = []\n const time = yield* now\n\n for (const candidate of candidates) {\n if (\n candidate.state !== 'active' ||\n (candidate.configuration.expiresAtMillis !== null &&\n candidate.configuration.expiresAtMillis <= time)\n ) {\n continue\n }\n\n const config = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n candidate.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n const fingerprint = yield* digest({\n key: candidate.key,\n createdBy: candidate.createdBy,\n configuration: config,\n })\n\n const parameters = yield* behavior.parameters(candidate.configuration.parameters)\n\n if (\n fingerprint !== candidate.configurationFingerprint ||\n parameters.matchingKey !== candidate.configuration.matchingKey\n ) {\n return yield* failure('corrupt', 'registration-source-bindings')\n }\n if (yield* behavior.matches(event, candidate)) {\n deliveries.push(yield* selected(event, candidate))\n }\n }\n const cursor = candidates.at(-1)?.ordinal ?? event.cursor\n\n yield* store.select(\n event,\n deliveries,\n cursor,\n candidates.length < limits.batchSize,\n yield* now,\n limits,\n )\n })\n\n const retry = (delivery: SubscriptionDelivery, reason: PreparedInputRetryReason) =>\n now.pipe(\n Effect.flatMap((time) =>\n store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Retry',\n nowMillis: time,\n retry: {\n generation: delivery.retry.generation,\n attempts: delivery.retry.attempts + 1,\n automaticAttempts: delivery.retry.automaticAttempts + 1,\n parked: delivery.retry.automaticAttempts + 1 >= (limits.maxAutomaticAttempts ?? 8),\n lastAttemptAtMillis: time,\n nextAttemptAtMillis: nextAttempt(time),\n lastFailure: reason,\n },\n })\n ),\n Effect.asVoid,\n )\n\n const refuse = (\n delivery: SubscriptionDelivery,\n phase: 'preparation' | 'admission',\n code: string,\n ) =>\n now.pipe(\n Effect.flatMap((time) =>\n store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Refuse',\n refusal: { phase, code },\n nowMillis: time,\n })\n ),\n Effect.asVoid,\n )\n\n const verifySelected = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {\n const current = yield* store.get(delivery.key.subscription)\n\n const subscription = current === null\n ? null\n : {\n ...current,\n configuration: delivery.configuration,\n configurationRevision: delivery.configurationRevision,\n configurationFingerprint: delivery.subscriptionFingerprint,\n }\n\n const event = yield* store.event(delivery.key.eventId)\n\n if (\n subscription === null ||\n event === null ||\n !sameSource(delivery.source, event.source) ||\n !sameSource(delivery.source, subscription.configuration.source)\n ) {\n return yield* failure('corrupt', 'selected-reference')\n }\n\n const expectedId = yield* digest({\n schemaVersion: 1,\n subscription: subscription.key,\n eventId: event.eventId,\n })\n\n const configuration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n subscription.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n const fingerprint = yield* digest({\n key: subscription.key,\n createdBy: subscription.createdBy,\n configuration,\n })\n\n const destination = subscription.configuration.destination\n\n if (\n delivery.subscriptionFingerprint !== fingerprint ||\n delivery.eventDigest !== event.payloadDigest ||\n (yield* digest(event.payload)) !== event.payloadDigest ||\n delivery.deliveryId !== expectedId ||\n delivery.admissionKey !== `subscription:${expectedId}` ||\n delivery.threadId !==\n (destination._tag === 'ExistingThread'\n ? destination.threadId\n : `subscription:${expectedId}`)\n ) {\n return yield* failure('corrupt', 'selected-bindings')\n }\n\n return { subscription, event }\n })\n\n const envelopeDigest = Effect.fnUntraced(function*(\n delivery: SubscriptionDelivery,\n envelope: PreparedInput,\n ) {\n const encoded = yield* Schema.encodeEffect(PreparedInput)(envelope).pipe(\n Effect.mapError(() => failure('corrupt', 'prepared-envelope')),\n )\n\n return yield* digest({\n deliveryId: delivery.deliveryId,\n subscriptionFingerprint: delivery.subscriptionFingerprint,\n eventDigest: delivery.eventDigest,\n envelope: encoded,\n })\n })\n\n const prepare = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {\n const { subscription, event } = yield* verifySelected(delivery)\n const time = yield* now\n\n if (\n subscription.state === 'cancelled' ||\n (subscription.configuration.expiresAtMillis !== null &&\n subscription.configuration.expiresAtMillis <= time)\n ) {\n yield* refuse(\n delivery,\n 'preparation',\n subscription.state === 'cancelled' ? 'cancelled' : 'expired',\n )\n\n return null\n }\n const binding = yield* resolveSubscriptionInput(bindings, subscription.configuration)\n\n if ((yield* digest(event.payload)) !== event.payloadDigest) {\n return yield* failure('corrupt', 'event-digest')\n }\n const authorization = yield* authorizer.prepare(subscription, event)\n const input = yield* binding.prepare(event, subscription)\n\n if (bytes(input) > limits.maxPayloadBytes) {\n return yield* SubscriptionSourceError.make({ code: 'input-bounds', retryable: false })\n }\n\n const envelope = yield* validate(PreparedInput, {\n schemaVersion: 1,\n threadId: delivery.threadId,\n admissionKey: delivery.admissionKey,\n deliveryPrincipal: subscription.configuration.deliveryPrincipal,\n ...(subscription.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: subscription.configuration.admissionGroup }),\n ...(subscription.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: subscription.configuration.admissionFence }),\n agentId: subscription.configuration.agentId,\n definitions: subscription.configuration.definitions,\n input,\n inputDigest: yield* digest(input),\n authorization,\n })\n\n return yield* store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Prepare',\n envelope,\n envelopeDigest: yield* envelopeDigest(delivery, envelope),\n nowMillis: yield* now,\n })\n })\n\n const process = Effect.fnUntraced(function*(key: SubscriptionDeliveryKey) {\n let delivery = yield* store.delivery(key)\n\n if (delivery === null) return yield* failure('not-found', 'delivery')\n if (\n delivery.state === 'delivered' &&\n delivery.observeSettlement === true &&\n delivery.receipt !== null\n ) {\n const settled = admission.submissionStatus === undefined\n ? false\n : yield* admission.submissionStatus(delivery.receipt).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.map((status) => status._tag === 'settled'),\n Effect.catch((error) =>\n Effect.logWarning('Subscription settlement observation unavailable', {\n tag: error._tag,\n }).pipe(Effect.as(false))\n ),\n )\n\n const time = yield* now\n\n yield* store.changeDelivery(\n delivery.key,\n delivery.deliveryId,\n {\n _tag: 'ObserveSettlement',\n receipt: delivery.receipt,\n settled,\n nowMillis: time,\n nextAttemptAtMillis: nextAttempt(time),\n },\n limits,\n )\n\n return\n }\n if (\n delivery.retry.parked === true ||\n delivery.retry.nextAttemptAtMillis > (yield* now) ||\n delivery.state === 'delivered' ||\n delivery.state === 'refused'\n ) {\n return\n }\n if (delivery.state === 'selected') {\n const original = delivery\n\n delivery = yield* prepare(original).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.catchTags({\n SubscriptionSourceError: (error) =>\n (error.retryable\n ? retry(original, 'transport')\n : refuse(original, 'preparation', error.code)).pipe(Effect.as(null)),\n SubscriptionError: (error) =>\n error.reason === 'unauthorized'\n ? refuse(original, 'preparation', error.code).pipe(Effect.as(null))\n : Effect.fail(error),\n TimeoutError: () => retry(original, 'timeout').pipe(Effect.as(null)),\n }),\n )\n }\n if (delivery === null || delivery.state === 'refused' || delivery.state === 'delivered') return\n if (\n delivery.state !== 'prepared' ||\n delivery.envelope === null ||\n delivery.envelopeDigest === null\n ) {\n return yield* failure('corrupt', 'prepared-state')\n }\n const { subscription } = yield* verifySelected(delivery)\n const envelope = delivery.envelope\n\n if (\n (yield* digest(envelope.input)) !== envelope.inputDigest ||\n envelope.threadId !== delivery.threadId ||\n envelope.admissionKey !== delivery.admissionKey ||\n envelope.deliveryPrincipal !== subscription.configuration.deliveryPrincipal ||\n envelope.agentId !== subscription.configuration.agentId ||\n !definitionEquals(envelope.definitions, subscription.configuration.definitions) ||\n delivery.envelopeDigest !== (yield* envelopeDigest(delivery, envelope))\n ) {\n return yield* failure('corrupt', 'prepared-envelope')\n }\n\n const outcome = yield* admitPreparedInput(\n admission.submit(envelope),\n limits.operationTimeoutMillis,\n ).pipe(Effect.mapError(() => failure('corrupt', 'admission')))\n\n if (outcome._tag === 'Receipt') {\n yield* failpoint.hit('subscription:admission:after')\n if (outcome.receipt.threadId !== envelope.threadId) {\n return yield* failure('corrupt', 'receipt-destination')\n }\n yield* store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Complete',\n receipt: outcome.receipt,\n nowMillis: yield* now,\n })\n } else if (outcome._tag === 'Refused') yield* refuse(delivery, 'admission', outcome.error.code)\n else yield* retry(delivery, outcome.reason)\n })\n\n const processDelivery: SubscriptionDriver['Service']['processDelivery'] = (key) => semaphore.withPermit(process(key))\n\n const reconcile = Effect.fnUntraced(function*(subscription: SubscriptionRecord) {\n const time = yield* now\n\n if (\n subscription.state !== 'active' ||\n (subscription.configuration.expiresAtMillis !== null &&\n subscription.configuration.expiresAtMillis <= time)\n ) {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, null)\n }\n const behavior = yield* source(subscription.configuration.source)\n\n if (behavior.reconcile === undefined) {\n return yield* failure('unsupported-source', 'source-reconciliation')\n }\n yield* authorizer.reconcile(subscription)\n\n const observation = yield* behavior.reconcile(subscription).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.map((event) => ({ _tag: 'Observed' as const, event })),\n Effect.catchTag('SubscriptionSourceError', (error) => Effect.succeed({ _tag: 'Failed' as const, error })),\n )\n\n if (observation._tag === 'Failed') {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: observation.error.retryable ? nextAttempt(time) : null,\n lastFailure: observation.error.code,\n })\n }\n const observed = observation.event\n\n if (observed !== null) {\n const event = yield* acceptNormalized(behavior.source, observed, limits)\n\n if (event.tombstone === true) {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: null,\n lastFailure: 'event-reclaimed',\n })\n }\n\n if (\n event.matchingKey !== subscription.configuration.matchingKey ||\n !(yield* behavior.matches(event, subscription))\n ) {\n return yield* failure('conflict', 'reconciliation-match')\n }\n yield* store.catchUp(event, yield* selected(event, subscription), yield* now, limits)\n\n return\n }\n yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: nextAttempt(time),\n lastFailure: null,\n })\n })\n\n const runDue = Effect.gen(function*() {\n const time = yield* now\n let processed = 0\n let failed = 0\n\n const failureCode = <E>(cause: Cause.Cause<E>) =>\n Option.match(Cause.findErrorOption(cause), {\n onNone: () => 'defect',\n onSome: (error) =>\n Schema.is(SubscriptionError)(error)\n ? error.reason\n : Schema.is(SubscriptionSourceError)(error)\n ? error.code\n : Schema.is(Schema.TaggedStruct('TimeoutError', {}))(error)\n ? 'timeout'\n : 'interrupted-work',\n })\n\n const attempt = <E>(\n work: Effect.Effect<void, E>,\n recover: (code: string) => Effect.Effect<void, SubscriptionStoreFailure>,\n ) =>\n work.pipe(\n Effect.matchCauseEffect({\n onSuccess: () =>\n Effect.sync(() => {\n processed += 1\n }),\n onFailure: (cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.interrupt\n : Effect.gen(function*() {\n failed += 1\n const code = failureCode(cause)\n\n yield* recover(code).pipe(\n Effect.catchCause((c) => Cause.hasInterruptsOnly(c) ? Effect.interrupt : Effect.void),\n )\n yield* Effect.logWarning('Subscription work remains pending').pipe(\n Effect.annotateLogs({ failureCode: code }),\n )\n }),\n }),\n )\n\n // Persist progress even when one record cannot be decoded or deferred. An eviction cannot\n // send every sweep back to a corrupt first page. Each category receives one bounded page.\n const cursors = yield* store.readScanCursors\n const records = yield* store.recovering(time, cursors.recovery, limits.batchSize)\n const events = yield* store.pendingEvents(time, cursors.events, limits.batchSize)\n const deliveries = yield* store.pendingDeliveries(time, cursors.deliveries, limits.batchSize)\n const lastDelivery = deliveries.at(-1)\n\n yield* store.advanceScanCursors({\n recovery: records.length < limits.batchSize ? 0 : (records.at(-1)?.ordinal ?? 0),\n events: events.length < limits.batchSize ? '' : (events.at(-1) ?? ''),\n deliveries: deliveries.length < limits.batchSize || lastDelivery === undefined\n ? ''\n : subscriptionDeliveryKeyString(lastDelivery),\n })\n yield* Effect.forEach(\n records,\n (cursor) =>\n Effect.gen(function*() {\n let record: SubscriptionRecord | null = null\n\n yield* attempt(\n Effect.gen(function*() {\n record = yield* store.get(cursor.key)\n\n if (record !== null) yield* reconcile(record)\n }).pipe(Effect.timeout(limits.operationTimeoutMillis)),\n (code) =>\n // A failed read supplies no revision that can safely authorize a mutation.\n record === null\n ? Effect.void\n : store.deferRecovery(record.key, record.configurationRevision, {\n attempts: (record.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: code === 'unauthorized' ? null : nextAttempt(time),\n lastFailure: code,\n }),\n )\n }),\n { concurrency: limits.concurrency },\n )\n yield* Effect.forEach(\n events,\n (eventId) =>\n attempt(\n store.event(eventId).pipe(\n Effect.flatMap((event) => event === null ? failure('not-found', 'event') : route(event)),\n Effect.timeout(limits.operationTimeoutMillis),\n ),\n (code) => store.deferEvent(eventId, nextAttempt(time), code),\n ),\n { concurrency: limits.concurrency },\n )\n yield* Effect.forEach(\n deliveries,\n (key) =>\n attempt(processDelivery(key), () =>\n store\n .delivery(key)\n .pipe(\n Effect.flatMap((delivery) => delivery === null ? Effect.void : retry(delivery, 'ambiguous')),\n )),\n { concurrency: limits.concurrency },\n )\n\n if (limits.retention !== undefined) {\n yield* store.compact(yield* now, limits.retention, limits.batchSize)\n }\n\n return { processed, failed }\n })\n\n return SubscriptionDriver.of({ runDue: sweepSemaphore.withPermit(runDue), processDelivery })\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,MAAM,SAAS,IAAI,KAAK,OAAO,IAAI,SAAS,aAAa,CAAC;AAEhE,MAAM,WAAW,QAAqC,SAAiB,kBAAkB,KAAK;CAAE;CAAQ;AAAK,CAAC;AAE9G,MAAM,SA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IAAI,GAAG,IAAI,CAC7D,GACF,EAAE,aAAa,OAAO,YAAY,CACpC;EACA,OAAO,OAAO,QACZ,aACC,QACC,QAAQ,gBAAgB,GAAG,SACzB,MACG,SAAS,GAAG,CAAC,CACb,KACC,OAAO,SAAS,aAAa,aAAa,OAAO,OAAO,OAAO,MAAM,UAAU,WAAW,CAAC,CAC7F,CAAC,GACP,EAAE,aAAa,OAAO,YAAY,CACpC;EAEA,IAAI,OAAO,cAAc,KAAA,GACvB,OAAO,MAAM,QAAQ,OAAO,KAAK,OAAO,WAAW,OAAO,SAAS;EAGrE,OAAO;GAAE;GAAW;EAAO;CAC7B,CAAC;CAED,OAAO,mBAAmB,GAAG;EAAE,QAAQ,eAAe,WAAW,MAAM;EAAG;CAAgB,CAAC;AAC7F,CAAC"}
1
+ {"version":3,"file":"Subscriptions-BS3AXmQ0.mjs","names":[],"sources":["../src/durable/Subscriptions.ts"],"sourcesContent":["import * as Cause from 'effect/Cause'\nimport * as Context from 'effect/Context'\nimport * as CryptoDigest from 'effect/crypto/Digest'\nimport * as DateTime from 'effect/DateTime'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\nimport * as Option from 'effect/Option'\nimport * as Schema from 'effect/Schema'\nimport * as Semaphore from 'effect/Semaphore'\n\nimport { ThreadId } from '../core/Identifiers'\nimport { utf8ByteLength } from '../core/internal/utf8'\nimport { digestJson } from './Digest'\nimport { EventSources, type NormalizedEvent } from './EventSource'\nimport {\n admitPreparedInput,\n PreparedInput,\n PreparedInputAdmission,\n type PreparedInputRetryReason,\n} from './PreparedInputAdmission'\nimport { DefinitionDigests, type PersistedJson } from './Records'\nimport { type AdmissionFence, IdempotencyKey, type Principal } from './SubmissionLedger'\nimport {\n AcceptedEvent,\n defaultSubscriptionLimits,\n type EventAcknowledgement,\n type EventSourceVersion,\n SubscriptionAuthorizer,\n type SubscriptionChange,\n SubscriptionConfiguration,\n SubscriptionDelivery,\n type SubscriptionDeliveryKey,\n subscriptionDeliveryKeyString,\n type SubscriptionDeliverySnapshot,\n SubscriptionError,\n SubscriptionFailpoint,\n SubscriptionKey,\n SubscriptionLimits,\n type SubscriptionRecord,\n SubscriptionScope,\n type SubscriptionSnapshot,\n SubscriptionSourceError,\n SubscriptionStore,\n type SubscriptionStoreFailure,\n} from './Subscription'\nimport { resolveSubscriptionInput, SubscriptionInputBindings } from './SubscriptionInput'\n\nconst now = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis))\n\nconst failure = (reason: SubscriptionError['reason'], code: string) => SubscriptionError.make({ reason, code })\n\nconst bytes = (value: PersistedJson) => utf8ByteLength(JSON.stringify(value))\n\nconst sameSource = (a: EventSourceVersion, b: EventSourceVersion) => a.name === b.name && a.version === b.version\n\nconst samePartition = Schema.toEquivalence(SubscriptionScope.fields.partition)\n\nconst validate = <S extends Schema.Top>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => failure('validation', 'schema')),\n )\n\nconst snapshot = (record: SubscriptionRecord, time: number): SubscriptionSnapshot => ({\n key: record.key,\n configurationRevision: record.configurationRevision,\n configurationFingerprint: record.configurationFingerprint,\n ...(record.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: record.configuration.admissionGroup }),\n ...(record.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: record.configuration.admissionFence }),\n source: record.configuration.source,\n mode: record.configuration.mode,\n state: record.state === 'active' &&\n record.configuration.expiresAtMillis !== null &&\n record.configuration.expiresAtMillis <= time\n ? 'expired'\n : record.state,\n createdAtMillis: record.createdAtMillis,\n expiresAtMillis: record.configuration.expiresAtMillis,\n recovery: record.recovery,\n})\n\nconst deliverySnapshot = (\n record: SubscriptionDelivery,\n): typeof SubscriptionDeliverySnapshot.Type => ({\n key: record.key,\n state: record.state,\n configurationRevision: record.configurationRevision,\n ...(record.observeSettlement === undefined\n ? {}\n : { observeSettlement: record.observeSettlement }),\n ...(record.settledAtMillis === undefined ? {} : { settledAtMillis: record.settledAtMillis }),\n retry: record.retry,\n receipt: record.receipt,\n refusal: record.refusal,\n})\n\nexport interface SubscribeOptions {\n readonly subscriptionId: string\n readonly source: EventSourceVersion\n readonly parameters: PersistedJson\n readonly context: PersistedJson\n readonly mode: 'once' | 'continuous'\n readonly expiresAtMillis: number | null\n readonly destination: SubscriptionConfiguration['destination']\n readonly deliveryPrincipal: Principal\n readonly admissionGroup?: string\n readonly admissionFence?: AdmissionFence\n readonly agentId: SubscriptionConfiguration['agentId']\n readonly definitions: SubscriptionConfiguration['definitions']\n}\n\nexport type SubscriptionFailure = SubscriptionStoreFailure | SubscriptionSourceError\n\n/** Only management and redacted status. Do not provide intake or drivers to Agent Tools. */\nexport class Subscriptions extends Context.Service<\n Subscriptions,\n {\n readonly recoverSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly getSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionError>\n readonly subscribe: (\n scope: SubscriptionScope,\n options: SubscribeOptions,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>\n readonly updateSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n options: Omit<SubscribeOptions, 'subscriptionId'>,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>\n readonly pauseSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly resumeSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly listSubscriptions: (\n scope: SubscriptionScope,\n after?: number,\n limit?: number,\n ) => Effect.Effect<\n { readonly items: ReadonlyArray<SubscriptionSnapshot>; readonly next: number | null },\n SubscriptionError\n >\n readonly recoverDelivery: (\n scope: SubscriptionScope,\n key: SubscriptionDeliveryKey,\n expectedGeneration: number,\n ) => Effect.Effect<typeof SubscriptionDeliverySnapshot.Type, SubscriptionStoreFailure>\n readonly cancelSubscription: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision?: number,\n ) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>\n readonly listDeliveries: (\n scope: SubscriptionScope,\n key: SubscriptionKey,\n after?: string,\n limit?: number,\n ) => Effect.Effect<\n {\n readonly items: ReadonlyArray<typeof SubscriptionDeliverySnapshot.Type>\n readonly next: string | null\n },\n SubscriptionError\n >\n }\n>()('@effect-agent/thread/Subscriptions') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(Subscriptions, makeManagement(limits))\n }\n}\n\n/** Trusted intake acknowledges retained routing work, never a Thread Submission Receipt. */\nexport class SubscriptionIntake extends Context.Service<\n SubscriptionIntake,\n {\n readonly accept: (\n principal: Principal,\n source: EventSourceVersion,\n payload: unknown,\n ) => Effect.Effect<EventAcknowledgement, SubscriptionFailure>\n readonly status: (\n principal: Principal,\n source: EventSourceVersion,\n eventId: string,\n ) => Effect.Effect<\n EventAcknowledgement & {\n readonly routingComplete: boolean\n readonly routingFailure: string | null\n readonly nextAttemptAtMillis: number\n },\n SubscriptionError\n >\n }\n>()('@effect-agent/thread/SubscriptionIntake') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(SubscriptionIntake, makeIntake(limits))\n }\n}\n\n/** One bounded sweep. The platform owns polling/alarm recovery; no subscription retains a Run. */\nexport class SubscriptionDriver extends Context.Service<\n SubscriptionDriver,\n {\n readonly runDue: Effect.Effect<\n { readonly processed: number; readonly failed: number },\n SubscriptionStoreFailure\n >\n readonly processDelivery: (\n key: SubscriptionDeliveryKey,\n ) => Effect.Effect<void, SubscriptionFailure>\n }\n>()('@effect-agent/thread/SubscriptionDriver') {\n static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {\n return Layer.effect(SubscriptionDriver, makeDriver(limits))\n }\n}\n\nconst dependencies = Effect.gen(function*() {\n const store = yield* SubscriptionStore\n const authorizer = yield* SubscriptionAuthorizer\n const sources = (yield* EventSources).sources\n const crypto = yield* CryptoDigest.Digest\n\n const digest = (value: PersistedJson) =>\n digestJson(value).pipe(\n Effect.provideService(CryptoDigest.Digest, crypto),\n Effect.mapError(() => failure('storage', 'digest')),\n )\n\n const source = (version: EventSourceVersion) => {\n const found = sources.filter((s) => sameSource(s.source, version))\n const item = found[0]\n\n return found.length === 1 && item !== undefined\n ? Effect.succeed(item)\n : Effect.fail(failure('unsupported-source', 'source-version'))\n }\n\n const scope = Effect.fnUntraced(function*(value: SubscriptionScope) {\n const decoded = yield* validate(SubscriptionScope, value)\n\n if (!samePartition(decoded.partition, store.partition)) {\n return yield* failure('unauthorized', 'partition')\n }\n\n return decoded\n })\n\n const acceptNormalized = Effect.fnUntraced(function*(\n version: EventSourceVersion,\n event: NormalizedEvent,\n limits: SubscriptionLimits,\n ) {\n const time = yield* now\n\n const record = yield* validate(AcceptedEvent, {\n schemaVersion: 1,\n partition: store.partition,\n eventId: event.eventId,\n source: version,\n matchingKey: event.matchingKey,\n payload: event.payload,\n payloadDigest: yield* digest(event.payload),\n acceptedAtMillis: time,\n ...(event.occurredAtMillis === undefined ? {} : { occurredAtMillis: event.occurredAtMillis }),\n cutoff: 0,\n cursor: 0,\n routingComplete: false,\n routingFailure: null,\n nextAttemptAtMillis: time,\n })\n\n const retained = yield* store.accept(record, limits)\n\n if (retained.tombstone !== true && (yield* digest(retained.payload)) !== retained.payloadDigest) {\n return yield* failure('corrupt', 'event-digest')\n }\n\n return retained\n })\n\n return { store, authorizer, source, digest, scope, acceptNormalized }\n})\n\nconst pageLimit = (value: number) =>\n validate(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)), value)\n\nconst makeManagement = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { bindings } = yield* SubscriptionInputBindings\n const { store, authorizer, source, digest, scope } = yield* dependencies\n\n const subscribe: Subscriptions['Service']['subscribe'] = Effect.fnUntraced(\n function*(scopeValue, options) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('subscribe', owner)\n const behavior = yield* source(options.source)\n const params = yield* behavior.parameters(options.parameters)\n const binding = yield* resolveSubscriptionInput(bindings, options)\n const context = yield* binding.context(options.context)\n\n const configuration = yield* validate(SubscriptionConfiguration, {\n ...options,\n parameters: params.parameters,\n context,\n matchingKey: params.matchingKey,\n })\n\n yield* authorizer.manage('subscribe', owner, configuration)\n\n const key = yield* validate(SubscriptionKey, {\n partition: owner.partition,\n ownerId: owner.ownerId,\n subscriptionId: options.subscriptionId,\n })\n\n const encodedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n configuration,\n ).pipe(Effect.mapError(() => failure('validation', 'configuration')))\n\n const creationFingerprint = yield* digest({\n key,\n createdBy: owner.principal,\n configuration: encodedConfiguration,\n })\n\n const existing = yield* store.get(key)\n\n if (existing !== null) {\n const retainedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n existing.creationConfiguration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'creation-configuration')))\n\n const retainedFingerprint = yield* digest({\n key: existing.key,\n createdBy: existing.createdBy,\n configuration: retainedConfiguration,\n })\n\n if (retainedFingerprint !== existing.creationFingerprint) {\n return yield* failure('corrupt', 'creation-fingerprint')\n }\n\n const currentConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n existing.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n if (\n (yield* digest({\n key: existing.key,\n createdBy: existing.createdBy,\n configuration: currentConfiguration,\n })) !== existing.configurationFingerprint\n ) {\n return yield* failure('corrupt', 'creation-fingerprint')\n }\n if (existing.creationFingerprint !== creationFingerprint) {\n return yield* failure('conflict', 'creation')\n }\n\n return snapshot(existing, yield* now)\n }\n if (\n bytes(params.parameters) > limits.maxPayloadBytes ||\n bytes(context) > limits.maxContextBytes\n ) {\n return yield* failure('validation', 'registration-bounds')\n }\n const time = yield* now\n\n if (\n configuration.expiresAtMillis !== null &&\n (configuration.expiresAtMillis <= time ||\n configuration.expiresAtMillis - time > limits.maxLifetimeMillis)\n ) {\n return yield* failure('validation', 'lifetime')\n }\n if (behavior.reconcile !== undefined && configuration.mode !== 'once') {\n return yield* failure('validation', 'reconciliation-requires-once')\n }\n\n const record = yield* store.register(\n {\n schemaVersion: 1,\n key,\n creationFingerprint,\n configurationRevision: 1,\n configurationFingerprint: creationFingerprint,\n creationConfiguration: configuration,\n createdBy: owner.principal,\n createdAtMillis: time,\n ordinal: 0,\n configuration,\n state: 'active',\n recovery: behavior.reconcile === undefined\n ? null\n : { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },\n },\n limits,\n )\n\n return snapshot(record, time)\n },\n )\n\n const listSubscriptions: Subscriptions['Service']['listSubscriptions'] = Effect.fnUntraced(\n function*(scopeValue, after = 0, requestedLimit = 50) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('list', owner)\n const limit = yield* pageLimit(requestedLimit)\n\n yield* validate(Schema.Natural, after)\n const records = yield* store.list(owner.ownerId, after, limit)\n const time = yield* now\n\n return {\n items: records.map((record) => snapshot(record, time)),\n next: records.length === limit ? (records.at(-1)?.ordinal ?? null) : null,\n }\n },\n )\n\n const ownedKey = Effect.fnUntraced(function*(owner: SubscriptionScope, key: SubscriptionKey) {\n yield* validate(SubscriptionKey, key)\n if (!samePartition(owner.partition, key.partition) || owner.ownerId !== key.ownerId) {\n return yield* failure('unauthorized', 'owner')\n }\n\n return key\n })\n\n const updateSubscription: Subscriptions['Service']['updateSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key, expectedRevision, options) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('update', owner)\n yield* ownedKey(owner, key)\n const behavior = yield* source(options.source)\n const parameters = yield* behavior.parameters(options.parameters)\n const binding = yield* resolveSubscriptionInput(bindings, options)\n const context = yield* binding.context(options.context)\n\n const configuration = yield* validate(SubscriptionConfiguration, {\n ...options,\n ...parameters,\n context,\n })\n\n yield* authorizer.manage('update', owner, configuration)\n const time = yield* now\n\n if (\n bytes(parameters.parameters) > limits.maxPayloadBytes ||\n bytes(context) > limits.maxContextBytes\n ) {\n return yield* failure('validation', 'registration-bounds')\n }\n if (\n configuration.expiresAtMillis !== null &&\n (configuration.expiresAtMillis <= time ||\n configuration.expiresAtMillis - time > limits.maxLifetimeMillis)\n ) {\n return yield* failure('validation', 'lifetime')\n }\n if (behavior.reconcile !== undefined && configuration.mode !== 'once') {\n return yield* failure('validation', 'reconciliation-requires-once')\n }\n const existing = yield* store.get(key)\n\n if (existing === null) return yield* failure('not-found', 'subscription')\n\n const encoded = yield* Schema.encodeEffect(SubscriptionConfiguration)(configuration).pipe(\n Effect.mapError(() => failure('validation', 'configuration')),\n )\n\n const configurationFingerprint = yield* digest({\n key,\n createdBy: existing.createdBy,\n configuration: encoded,\n })\n\n const updated = yield* store.change(\n key,\n expectedRevision,\n {\n _tag: 'Update',\n configuration,\n configurationFingerprint,\n recovery: behavior.reconcile === undefined\n ? null\n : { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },\n },\n limits,\n )\n\n return snapshot(updated, time)\n },\n )\n\n const changeState = Effect.fnUntraced(function*(\n scopeValue: SubscriptionScope,\n key: SubscriptionKey,\n expectedRevision: number,\n change: Extract<SubscriptionChange, { readonly _tag: 'Pause' | 'Resume' }>,\n ) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage(change._tag === 'Pause' ? 'pause' : 'resume', owner)\n\n const updated = yield* store.change(\n yield* ownedKey(owner, key),\n expectedRevision,\n change,\n limits,\n )\n\n return snapshot(updated, yield* now)\n })\n\n const cancelSubscription: Subscriptions['Service']['cancelSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key, expectedRevision) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('cancel', owner)\n const record = yield* store.cancel(yield* ownedKey(owner, key), expectedRevision)\n\n return snapshot(record, yield* now)\n },\n )\n\n const listDeliveries: Subscriptions['Service']['listDeliveries'] = Effect.fnUntraced(function*(\n scopeValue,\n key,\n after = '',\n requestedLimit = 50,\n ) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('deliveries', owner)\n const limit = yield* pageLimit(requestedLimit)\n const records = yield* store.listDeliveries(yield* ownedKey(owner, key), after, limit)\n const last = records.at(-1)\n\n return {\n items: records.map(deliverySnapshot),\n next: records.length === limit && last !== undefined\n ? subscriptionDeliveryKeyString(last.key)\n : null,\n }\n })\n\n const recoverDelivery: Subscriptions['Service']['recoverDelivery'] = Effect.fn(\n 'Subscriptions.recoverDelivery',\n )(function*(scopeValue, key, expectedGeneration) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('recover', owner)\n yield* ownedKey(owner, key.subscription)\n const existing = yield* store.delivery(key)\n\n if (existing === null) return yield* failure('not-found', 'delivery')\n\n const recovered = yield* store.changeDelivery(key, existing.deliveryId, {\n _tag: 'Recover',\n expectedGeneration,\n nowMillis: yield* now,\n })\n\n return deliverySnapshot(recovered)\n })\n\n const getSubscription: Subscriptions['Service']['getSubscription'] = Effect.fnUntraced(\n function*(scopeValue, key) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('get', owner)\n const record = yield* store.get(yield* ownedKey(owner, key))\n\n if (record === null) return yield* failure('not-found', 'subscription')\n\n return snapshot(record, yield* now)\n },\n )\n\n return Subscriptions.of({\n getSubscription,\n recoverSubscription: Effect.fnUntraced(function*(scopeValue, key, expectedRevision) {\n const owner = yield* scope(scopeValue)\n\n yield* authorizer.manage('recover', owner)\n\n return snapshot(\n yield* store.change(\n yield* ownedKey(owner, key),\n expectedRevision,\n {\n _tag: 'Recover',\n nowMillis: yield* now,\n },\n limits,\n ),\n yield* now,\n )\n }),\n recoverDelivery,\n subscribe,\n updateSubscription,\n pauseSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Pause' }),\n resumeSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Resume' }),\n listSubscriptions,\n cancelSubscription,\n listDeliveries,\n })\n})\n\nconst makeIntake = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { store, authorizer, source, acceptNormalized } = yield* dependencies\n\n const accept: SubscriptionIntake['Service']['accept'] = Effect.fnUntraced(\n function*(principal, version, payload) {\n yield* authorizer.intake(store.partition, version, principal)\n const behavior = yield* source(version)\n const event = yield* behavior.normalize(payload)\n const accepted = yield* acceptNormalized(version, event, limits)\n\n return {\n partition: accepted.partition,\n eventId: accepted.eventId,\n acceptedAtMillis: accepted.acceptedAtMillis,\n }\n },\n )\n\n const status: SubscriptionIntake['Service']['status'] = Effect.fnUntraced(\n function*(principal, version, eventId) {\n yield* authorizer.intake(store.partition, version, principal)\n const event = yield* store.event(eventId)\n\n if (event === null) return yield* failure('not-found', 'event')\n if (!sameSource(event.source, version)) return yield* failure('conflict', 'event-source')\n\n return {\n partition: event.partition,\n eventId: event.eventId,\n acceptedAtMillis: event.acceptedAtMillis,\n routingComplete: event.routingComplete,\n routingFailure: event.routingFailure,\n nextAttemptAtMillis: event.nextAttemptAtMillis,\n }\n },\n )\n\n return SubscriptionIntake.of({ accept, status })\n})\n\nconst makeDriver = Effect.fnUntraced(function*(requested: SubscriptionLimits) {\n const limits = yield* validate(SubscriptionLimits, requested)\n const { bindings } = yield* SubscriptionInputBindings\n const { store, authorizer, source, digest, acceptNormalized } = yield* dependencies\n const admission = yield* PreparedInputAdmission\n\n if (limits.retention !== undefined && admission.submissionStatus === undefined) {\n return yield* failure('validation', 'retention-requires-submission-status')\n }\n const failpoint = yield* SubscriptionFailpoint\n const semaphore = yield* Semaphore.make(limits.concurrency)\n const sweepSemaphore = yield* Semaphore.make(1)\n const definitionEquals = Schema.toEquivalence(DefinitionDigests)\n const nextAttempt = (time: number) => Math.min(time + limits.retryMillis, 8_640_000_000_000_000)\n\n const selected = Effect.fnUntraced(function*(\n event: AcceptedEvent,\n subscription: SubscriptionRecord,\n ) {\n const deliveryId = yield* digest({\n schemaVersion: 1,\n subscription: subscription.key,\n eventId: event.eventId,\n })\n\n const time = yield* now\n\n return yield* validate(SubscriptionDelivery, {\n schemaVersion: 1,\n key: { subscription: subscription.key, eventId: event.eventId },\n deliveryId,\n subscriptionFingerprint: subscription.configurationFingerprint,\n configurationRevision: subscription.configurationRevision,\n configuration: subscription.configuration,\n eventDigest: event.payloadDigest,\n source: event.source,\n threadId: subscription.configuration.destination._tag === 'ExistingThread'\n ? subscription.configuration.destination.threadId\n : yield* Schema.decodeEffect(ThreadId)(`subscription:${deliveryId}`).pipe(Effect.orDie),\n admissionKey: yield* Schema.decodeEffect(IdempotencyKey)(`subscription:${deliveryId}`).pipe(\n Effect.orDie,\n ),\n selectedAtMillis: time,\n ...(limits.retention === undefined ? {} : { observeSettlement: true }),\n state: 'selected',\n envelope: null,\n envelopeDigest: null,\n retry: {\n generation: 0,\n attempts: 0,\n automaticAttempts: 0,\n parked: false,\n nextAttemptAtMillis: time,\n lastAttemptAtMillis: null,\n lastFailure: null,\n },\n receipt: null,\n refusal: null,\n })\n })\n\n const route = Effect.fnUntraced(function*(event: AcceptedEvent) {\n const behavior = yield* source(event.source)\n const normalized = yield* behavior.normalize(event.payload)\n\n if (\n normalized.eventId !== event.eventId ||\n normalized.occurredAtMillis !== event.occurredAtMillis ||\n normalized.matchingKey !== event.matchingKey ||\n (yield* digest(normalized.payload)) !== event.payloadDigest ||\n (yield* digest(event.payload)) !== event.payloadDigest\n ) {\n return yield* failure('corrupt', 'event-source-bindings')\n }\n const candidates = yield* store.candidates(event, limits.batchSize)\n const deliveries: Array<SubscriptionDelivery> = []\n const time = yield* now\n\n for (const candidate of candidates) {\n if (\n candidate.state !== 'active' ||\n (candidate.configuration.expiresAtMillis !== null &&\n candidate.configuration.expiresAtMillis <= time)\n ) {\n continue\n }\n\n const config = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n candidate.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n const fingerprint = yield* digest({\n key: candidate.key,\n createdBy: candidate.createdBy,\n configuration: config,\n })\n\n const parameters = yield* behavior.parameters(candidate.configuration.parameters)\n\n if (\n fingerprint !== candidate.configurationFingerprint ||\n parameters.matchingKey !== candidate.configuration.matchingKey\n ) {\n return yield* failure('corrupt', 'registration-source-bindings')\n }\n if (yield* behavior.matches(event, candidate)) {\n deliveries.push(yield* selected(event, candidate))\n }\n }\n const cursor = candidates.at(-1)?.ordinal ?? event.cursor\n\n yield* store.select(\n event,\n deliveries,\n cursor,\n candidates.length < limits.batchSize,\n yield* now,\n limits,\n )\n })\n\n const retry = (delivery: SubscriptionDelivery, reason: PreparedInputRetryReason) =>\n now.pipe(\n Effect.flatMap((time) =>\n store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Retry',\n nowMillis: time,\n retry: {\n generation: delivery.retry.generation,\n attempts: delivery.retry.attempts + 1,\n automaticAttempts: delivery.retry.automaticAttempts + 1,\n parked: delivery.retry.automaticAttempts + 1 >= (limits.maxAutomaticAttempts ?? 8),\n lastAttemptAtMillis: time,\n nextAttemptAtMillis: nextAttempt(time),\n lastFailure: reason,\n },\n })\n ),\n Effect.asVoid,\n )\n\n const refuse = (\n delivery: SubscriptionDelivery,\n phase: 'preparation' | 'admission',\n code: string,\n ) =>\n now.pipe(\n Effect.flatMap((time) =>\n store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Refuse',\n refusal: { phase, code },\n nowMillis: time,\n })\n ),\n Effect.asVoid,\n )\n\n const verifySelected = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {\n const current = yield* store.get(delivery.key.subscription)\n\n const subscription = current === null\n ? null\n : {\n ...current,\n configuration: delivery.configuration,\n configurationRevision: delivery.configurationRevision,\n configurationFingerprint: delivery.subscriptionFingerprint,\n }\n\n const event = yield* store.event(delivery.key.eventId)\n\n if (\n subscription === null ||\n event === null ||\n !sameSource(delivery.source, event.source) ||\n !sameSource(delivery.source, subscription.configuration.source)\n ) {\n return yield* failure('corrupt', 'selected-reference')\n }\n\n const expectedId = yield* digest({\n schemaVersion: 1,\n subscription: subscription.key,\n eventId: event.eventId,\n })\n\n const configuration = yield* Schema.encodeEffect(SubscriptionConfiguration)(\n subscription.configuration,\n ).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))\n\n const fingerprint = yield* digest({\n key: subscription.key,\n createdBy: subscription.createdBy,\n configuration,\n })\n\n const destination = subscription.configuration.destination\n\n if (\n delivery.subscriptionFingerprint !== fingerprint ||\n delivery.eventDigest !== event.payloadDigest ||\n (yield* digest(event.payload)) !== event.payloadDigest ||\n delivery.deliveryId !== expectedId ||\n delivery.admissionKey !== `subscription:${expectedId}` ||\n delivery.threadId !==\n (destination._tag === 'ExistingThread'\n ? destination.threadId\n : `subscription:${expectedId}`)\n ) {\n return yield* failure('corrupt', 'selected-bindings')\n }\n\n return { subscription, event }\n })\n\n const envelopeDigest = Effect.fnUntraced(function*(\n delivery: SubscriptionDelivery,\n envelope: PreparedInput,\n ) {\n const encoded = yield* Schema.encodeEffect(PreparedInput)(envelope).pipe(\n Effect.mapError(() => failure('corrupt', 'prepared-envelope')),\n )\n\n return yield* digest({\n deliveryId: delivery.deliveryId,\n subscriptionFingerprint: delivery.subscriptionFingerprint,\n eventDigest: delivery.eventDigest,\n envelope: encoded,\n })\n })\n\n const prepare = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {\n const { subscription, event } = yield* verifySelected(delivery)\n const time = yield* now\n\n if (\n subscription.state === 'cancelled' ||\n (subscription.configuration.expiresAtMillis !== null &&\n subscription.configuration.expiresAtMillis <= time)\n ) {\n yield* refuse(\n delivery,\n 'preparation',\n subscription.state === 'cancelled' ? 'cancelled' : 'expired',\n )\n\n return null\n }\n const binding = yield* resolveSubscriptionInput(bindings, subscription.configuration)\n\n if ((yield* digest(event.payload)) !== event.payloadDigest) {\n return yield* failure('corrupt', 'event-digest')\n }\n const authorization = yield* authorizer.prepare(subscription, event)\n const input = yield* binding.prepare(event, subscription)\n\n if (bytes(input) > limits.maxPayloadBytes) {\n return yield* SubscriptionSourceError.make({ code: 'input-bounds', retryable: false })\n }\n\n const envelope = yield* validate(PreparedInput, {\n schemaVersion: 1,\n threadId: delivery.threadId,\n admissionKey: delivery.admissionKey,\n deliveryPrincipal: subscription.configuration.deliveryPrincipal,\n ...(subscription.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: subscription.configuration.admissionGroup }),\n ...(subscription.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: subscription.configuration.admissionFence }),\n agentId: subscription.configuration.agentId,\n definitions: subscription.configuration.definitions,\n input,\n inputDigest: yield* digest(input),\n authorization,\n })\n\n return yield* store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Prepare',\n envelope,\n envelopeDigest: yield* envelopeDigest(delivery, envelope),\n nowMillis: yield* now,\n })\n })\n\n const process = Effect.fnUntraced(function*(key: SubscriptionDeliveryKey) {\n let delivery = yield* store.delivery(key)\n\n if (delivery === null) return yield* failure('not-found', 'delivery')\n if (\n delivery.state === 'delivered' &&\n delivery.observeSettlement === true &&\n delivery.receipt !== null\n ) {\n const settled = admission.submissionStatus === undefined\n ? false\n : yield* admission.submissionStatus(delivery.receipt).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.map((status) => status._tag === 'settled'),\n Effect.catch((error) =>\n Effect.logWarning('Subscription settlement observation unavailable', {\n tag: error._tag,\n }).pipe(Effect.as(false))\n ),\n )\n\n const time = yield* now\n\n yield* store.changeDelivery(\n delivery.key,\n delivery.deliveryId,\n {\n _tag: 'ObserveSettlement',\n receipt: delivery.receipt,\n settled,\n nowMillis: time,\n nextAttemptAtMillis: nextAttempt(time),\n },\n limits,\n )\n\n return\n }\n if (\n delivery.retry.parked === true ||\n delivery.retry.nextAttemptAtMillis > (yield* now) ||\n delivery.state === 'delivered' ||\n delivery.state === 'refused'\n ) {\n return\n }\n if (delivery.state === 'selected') {\n const original = delivery\n\n delivery = yield* prepare(original).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.catchTags({\n SubscriptionSourceError: (error) =>\n (error.retryable\n ? retry(original, 'transport')\n : refuse(original, 'preparation', error.code)).pipe(Effect.as(null)),\n SubscriptionError: (error) =>\n error.reason === 'unauthorized'\n ? refuse(original, 'preparation', error.code).pipe(Effect.as(null))\n : Effect.fail(error),\n TimeoutError: () => retry(original, 'timeout').pipe(Effect.as(null)),\n }),\n )\n }\n if (delivery === null || delivery.state === 'refused' || delivery.state === 'delivered') return\n if (\n delivery.state !== 'prepared' ||\n delivery.envelope === null ||\n delivery.envelopeDigest === null\n ) {\n return yield* failure('corrupt', 'prepared-state')\n }\n const { subscription } = yield* verifySelected(delivery)\n const envelope = delivery.envelope\n\n if (\n (yield* digest(envelope.input)) !== envelope.inputDigest ||\n envelope.threadId !== delivery.threadId ||\n envelope.admissionKey !== delivery.admissionKey ||\n envelope.deliveryPrincipal !== subscription.configuration.deliveryPrincipal ||\n envelope.agentId !== subscription.configuration.agentId ||\n !definitionEquals(envelope.definitions, subscription.configuration.definitions) ||\n delivery.envelopeDigest !== (yield* envelopeDigest(delivery, envelope))\n ) {\n return yield* failure('corrupt', 'prepared-envelope')\n }\n\n const outcome = yield* admitPreparedInput(\n admission.submit(envelope),\n limits.operationTimeoutMillis,\n ).pipe(Effect.mapError(() => failure('corrupt', 'admission')))\n\n if (outcome._tag === 'Receipt') {\n yield* failpoint.hit('subscription:admission:after')\n if (outcome.receipt.threadId !== envelope.threadId) {\n return yield* failure('corrupt', 'receipt-destination')\n }\n yield* store.changeDelivery(delivery.key, delivery.deliveryId, {\n _tag: 'Complete',\n receipt: outcome.receipt,\n nowMillis: yield* now,\n })\n } else if (outcome._tag === 'Refused') yield* refuse(delivery, 'admission', outcome.error.code)\n else yield* retry(delivery, outcome.reason)\n })\n\n const processDelivery: SubscriptionDriver['Service']['processDelivery'] = (key) => semaphore.withPermit(process(key))\n\n const reconcile = Effect.fnUntraced(function*(subscription: SubscriptionRecord) {\n const time = yield* now\n\n if (\n subscription.state !== 'active' ||\n (subscription.configuration.expiresAtMillis !== null &&\n subscription.configuration.expiresAtMillis <= time)\n ) {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, null)\n }\n const behavior = yield* source(subscription.configuration.source)\n\n if (behavior.reconcile === undefined) {\n return yield* failure('unsupported-source', 'source-reconciliation')\n }\n yield* authorizer.reconcile(subscription)\n\n const observation = yield* behavior.reconcile(subscription).pipe(\n Effect.timeout(limits.operationTimeoutMillis),\n Effect.map((event) => ({ _tag: 'Observed' as const, event })),\n Effect.catchTag('SubscriptionSourceError', (error) => Effect.succeed({ _tag: 'Failed' as const, error })),\n )\n\n if (observation._tag === 'Failed') {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: observation.error.retryable ? nextAttempt(time) : null,\n lastFailure: observation.error.code,\n })\n }\n const observed = observation.event\n\n if (observed !== null) {\n const event = yield* acceptNormalized(behavior.source, observed, limits)\n\n if (event.tombstone === true) {\n return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: null,\n lastFailure: 'event-reclaimed',\n })\n }\n\n if (\n event.matchingKey !== subscription.configuration.matchingKey ||\n !(yield* behavior.matches(event, subscription))\n ) {\n return yield* failure('conflict', 'reconciliation-match')\n }\n yield* store.catchUp(event, yield* selected(event, subscription), yield* now, limits)\n\n return\n }\n yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {\n attempts: (subscription.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: nextAttempt(time),\n lastFailure: null,\n })\n })\n\n const runDue = Effect.gen(function*() {\n const time = yield* now\n let processed = 0\n let failed = 0\n\n const failureCode = <E>(cause: Cause.Cause<E>) =>\n Option.match(Cause.findErrorOption(cause), {\n onNone: () => 'defect',\n onSome: (error) =>\n Schema.is(SubscriptionError)(error)\n ? error.reason\n : Schema.is(SubscriptionSourceError)(error)\n ? error.code\n : Schema.is(Schema.TaggedStruct('TimeoutError', {}))(error)\n ? 'timeout'\n : 'interrupted-work',\n })\n\n const attempt = <E>(\n work: Effect.Effect<void, E>,\n recover: (code: string) => Effect.Effect<void, SubscriptionStoreFailure>,\n ) =>\n work.pipe(\n Effect.matchCauseEffect({\n onSuccess: () =>\n Effect.sync(() => {\n processed += 1\n }),\n onFailure: (cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.interrupt\n : Effect.gen(function*() {\n failed += 1\n const code = failureCode(cause)\n\n yield* recover(code).pipe(\n Effect.catchCause((c) => Cause.hasInterruptsOnly(c) ? Effect.interrupt : Effect.void),\n )\n yield* Effect.logWarning('Subscription work remains pending').pipe(\n Effect.annotateLogs({ failureCode: code }),\n )\n }),\n }),\n )\n\n // Persist progress even when one record cannot be decoded or deferred. An eviction cannot\n // send every sweep back to a corrupt first page. Each category receives one bounded page.\n const cursors = yield* store.readScanCursors\n const records = yield* store.recovering(time, cursors.recovery, limits.batchSize)\n const events = yield* store.pendingEvents(time, cursors.events, limits.batchSize)\n const deliveries = yield* store.pendingDeliveries(time, cursors.deliveries, limits.batchSize)\n const lastDelivery = deliveries.at(-1)\n\n yield* store.advanceScanCursors({\n recovery: records.length < limits.batchSize ? 0 : (records.at(-1)?.ordinal ?? 0),\n events: events.length < limits.batchSize ? '' : (events.at(-1) ?? ''),\n deliveries: deliveries.length < limits.batchSize || lastDelivery === undefined\n ? ''\n : subscriptionDeliveryKeyString(lastDelivery),\n })\n yield* Effect.forEach(\n records,\n (cursor) =>\n Effect.gen(function*() {\n let record: SubscriptionRecord | null = null\n\n yield* attempt(\n Effect.gen(function*() {\n record = yield* store.get(cursor.key)\n\n if (record !== null) yield* reconcile(record)\n }).pipe(Effect.timeout(limits.operationTimeoutMillis)),\n (code) =>\n // A failed read supplies no revision that can safely authorize a mutation.\n record === null\n ? Effect.void\n : store.deferRecovery(record.key, record.configurationRevision, {\n attempts: (record.recovery?.attempts ?? 0) + 1,\n nextAttemptAtMillis: code === 'unauthorized' ? null : nextAttempt(time),\n lastFailure: code,\n }),\n )\n }),\n { concurrency: limits.concurrency },\n )\n yield* Effect.forEach(\n events,\n (eventId) =>\n attempt(\n store.event(eventId).pipe(\n Effect.flatMap((event) => event === null ? failure('not-found', 'event') : route(event)),\n Effect.timeout(limits.operationTimeoutMillis),\n ),\n (code) => store.deferEvent(eventId, nextAttempt(time), code),\n ),\n { concurrency: limits.concurrency },\n )\n yield* Effect.forEach(\n deliveries,\n (key) =>\n attempt(processDelivery(key), () =>\n store\n .delivery(key)\n .pipe(\n Effect.flatMap((delivery) => delivery === null ? Effect.void : retry(delivery, 'ambiguous')),\n )),\n { concurrency: limits.concurrency },\n )\n\n if (limits.retention !== undefined) {\n yield* store.compact(yield* now, limits.retention, limits.batchSize)\n }\n\n return { processed, failed }\n })\n\n return SubscriptionDriver.of({ runDue: sweepSemaphore.withPermit(runDue), processDelivery })\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,MAAM,SAAS,IAAI,KAAK,OAAO,IAAI,SAAS,aAAa,CAAC;AAEhE,MAAM,WAAW,QAAqC,SAAiB,kBAAkB,KAAK;CAAE;CAAQ;AAAK,CAAC;AAE9G,MAAM,SAAS,UAAyB,eAAe,KAAK,UAAU,KAAK,CAAC;AAE5E,MAAM,cAAc,GAAuB,MAA0B,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE;AAE1G,MAAM,gBAAgB,OAAO,cAAc,kBAAkB,OAAO,SAAS;AAE7E,MAAM,YAAkC,QAAW,UACjD,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KACxC,OAAO,eAAe,QAAQ,cAAc,QAAQ,CAAC,CACvD;AAEF,MAAM,YAAY,QAA4B,UAA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