@systemfsoftware/agent 0.0.0-bootstrap.0 → 0.1.0-beta.192
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/ActivityStore-CEy3oY41.mjs +90 -0
- package/dist/ActivityStore-CEy3oY41.mjs.map +1 -0
- package/dist/ActivityStore-CPXWRHGz.d.mts +91 -0
- package/dist/Admin-BcQDrWKY.mjs +329 -0
- package/dist/Admin-BcQDrWKY.mjs.map +1 -0
- package/dist/Admin-BfolLkHj.d.mts +5678 -0
- package/dist/Agent-Bn3zMhDH.mjs +60 -0
- package/dist/Agent-Bn3zMhDH.mjs.map +1 -0
- package/dist/Agent-DSVEpq4e.d.mts +219 -0
- package/dist/AgentError-RkUaetX8.d.mts +128 -0
- package/dist/AgentError-yFdnS9bl.mjs +141 -0
- package/dist/AgentError-yFdnS9bl.mjs.map +1 -0
- package/dist/AgentPolicy-CI7LRBQa.mjs +116 -0
- package/dist/AgentPolicy-CI7LRBQa.mjs.map +1 -0
- package/dist/AgentPolicy-D-GmZQex.d.mts +128 -0
- package/dist/AgentRegistration-Dg53p6du.mjs +14 -0
- package/dist/AgentRegistration-Dg53p6du.mjs.map +1 -0
- package/dist/AgentRuntime-CoGy_5dm.d.mts +751 -0
- package/dist/AgentRuntime-CzP4I4RB.mjs +5249 -0
- package/dist/AgentRuntime-CzP4I4RB.mjs.map +1 -0
- package/dist/AgentUpdates-7xT0It_R.d.mts +54 -0
- package/dist/AgentUpdates-BS_6gR5K.mjs +66 -0
- package/dist/AgentUpdates-BS_6gR5K.mjs.map +1 -0
- package/dist/BrowserUse-C9vict2M.d.mts +196 -0
- package/dist/BrowserUse-DjEyFDLZ.mjs +156 -0
- package/dist/BrowserUse-DjEyFDLZ.mjs.map +1 -0
- package/dist/Budget-CXh_ChFJ.d.mts +112 -0
- package/dist/Budget-j1UkthgY.mjs +351 -0
- package/dist/Budget-j1UkthgY.mjs.map +1 -0
- package/dist/CodeExecutor-B_Vt1Ghy.mjs +281 -0
- package/dist/CodeExecutor-B_Vt1Ghy.mjs.map +1 -0
- package/dist/CodeExecutor-D5-Rda75.d.mts +198 -0
- package/dist/CodeMode-B7JvfKAD.d.mts +159 -0
- package/dist/CodeMode-BI7WhUkr.mjs +555 -0
- package/dist/CodeMode-BI7WhUkr.mjs.map +1 -0
- package/dist/CommittedActivity-DXyCKCtX.mjs +146 -0
- package/dist/CommittedActivity-DXyCKCtX.mjs.map +1 -0
- package/dist/CommittedActivity-LWOKXqdi.d.mts +62 -0
- package/dist/Compaction-C0hWAmOG.mjs +15 -0
- package/dist/Compaction-C0hWAmOG.mjs.map +1 -0
- package/dist/Compaction-e5cNeFmY.d.mts +5 -0
- package/dist/ContextCompactor-Chm9BLrD.d.mts +165 -0
- package/dist/ContextCompactor-DV4NOQvg.mjs +134 -0
- package/dist/ContextCompactor-DV4NOQvg.mjs.map +1 -0
- package/dist/ContextHistory-C80rW5M7.mjs +76 -0
- package/dist/ContextHistory-C80rW5M7.mjs.map +1 -0
- package/dist/ContextHistory-akQ1Td7a.d.mts +65 -0
- package/dist/ContextTools-917r7gpv.d.mts +186 -0
- package/dist/ContextTools-p8JDPo-W.mjs +88 -0
- package/dist/ContextTools-p8JDPo-W.mjs.map +1 -0
- package/dist/ContextWindow-BJZI4MMt.d.mts +61 -0
- package/dist/ContextWindow-kbFcs1IF.mjs +63 -0
- package/dist/ContextWindow-kbFcs1IF.mjs.map +1 -0
- package/dist/Digest-BDToAbaX.d.mts +25 -0
- package/dist/Digest-CU6IWj-2.mjs +106 -0
- package/dist/Digest-CU6IWj-2.mjs.map +1 -0
- package/dist/DurableAgentRuntime-BHXo8GPJ.mjs +8432 -0
- package/dist/DurableAgentRuntime-BHXo8GPJ.mjs.map +1 -0
- package/dist/DurableFailpoint-BD5nowNl.mjs +98 -0
- package/dist/DurableFailpoint-BD5nowNl.mjs.map +1 -0
- package/dist/DurableFailpoint-Cqi5tyof.d.mts +42 -0
- package/dist/DurableStep-CzVIho7y.mjs +54 -0
- package/dist/DurableStep-CzVIho7y.mjs.map +1 -0
- package/dist/DurableStep-cI_Ho_rU.d.mts +109 -0
- package/dist/EventSource-BwZVkEQi.mjs +66 -0
- package/dist/EventSource-BwZVkEQi.mjs.map +1 -0
- package/dist/EventSource-C0TCBeIf.d.mts +52 -0
- package/dist/FailureDiagnostic-DdHV2eFs.mjs +304 -0
- package/dist/FailureDiagnostic-DdHV2eFs.mjs.map +1 -0
- package/dist/FailureDiagnostic-DpzYNI8f.d.mts +232 -0
- package/dist/IdGenerator-BCzwV0ZI.mjs +29 -0
- package/dist/IdGenerator-BCzwV0ZI.mjs.map +1 -0
- package/dist/IdGenerator-BY8NH74o.d.mts +26 -0
- package/dist/Identifiers-LWd4837I.mjs +41 -0
- package/dist/Identifiers-LWd4837I.mjs.map +1 -0
- package/dist/Identifiers-qafW4EP0.d.mts +38 -0
- package/dist/InMemory-BrTm6XEO.mjs +57 -0
- package/dist/InMemory-BrTm6XEO.mjs.map +1 -0
- package/dist/InMemory-C3qXFT5k.d.mts +46 -0
- package/dist/InMemory.d.mts +2 -0
- package/dist/InMemory.mjs +1 -0
- package/dist/InteractiveBrowser-B-hlNJy5.mjs +237 -0
- package/dist/InteractiveBrowser-B-hlNJy5.mjs.map +1 -0
- package/dist/InteractiveBrowser-nnML0r7w.d.mts +258 -0
- package/dist/LifecyclePublication-BDc_ug5v.mjs +204 -0
- package/dist/LifecyclePublication-BDc_ug5v.mjs.map +1 -0
- package/dist/Memory-CT5bDZqi.d.mts +57 -0
- package/dist/Memory-Dl9ecPpm.mjs +204 -0
- package/dist/Memory-Dl9ecPpm.mjs.map +1 -0
- package/dist/MemoryNamespace-BtnlH_E6.d.mts +35 -0
- package/dist/MemoryNamespace-DZSpjLj9.mjs +116 -0
- package/dist/MemoryNamespace-DZSpjLj9.mjs.map +1 -0
- package/dist/MemoryNotes-4CRzkPBD.d.mts +425 -0
- package/dist/MemoryNotes-i41TsH11.mjs +132 -0
- package/dist/MemoryNotes-i41TsH11.mjs.map +1 -0
- package/dist/MemoryReference-Dd3KSMa7.d.mts +77 -0
- package/dist/MemoryReference-RFU0HQJG.mjs +108 -0
- package/dist/MemoryReference-RFU0HQJG.mjs.map +1 -0
- package/dist/MemoryRevalidation--aAh_Pfq.mjs +136 -0
- package/dist/MemoryRevalidation--aAh_Pfq.mjs.map +1 -0
- package/dist/MemoryRevalidation-FsJ8E61W.d.mts +64 -0
- package/dist/MemoryStore-Bg5RunTk.d.mts +187 -0
- package/dist/MemoryStore-E0J99hb2.mjs +245 -0
- package/dist/MemoryStore-E0J99hb2.mjs.map +1 -0
- package/dist/MessageDelivery-BE2Yf3FC.mjs +615 -0
- package/dist/MessageDelivery-BE2Yf3FC.mjs.map +1 -0
- package/dist/MessageDelivery-Dh6GZBt_.d.mts +1129 -0
- package/dist/Messaging-BqWHYf93.d.mts +216 -0
- package/dist/Messaging-DgSiv4f4.mjs +154 -0
- package/dist/Messaging-DgSiv4f4.mjs.map +1 -0
- package/dist/Messaging-DhM-APnP.d.mts +1074 -0
- package/dist/MessagingHost-Bm5e-kAX.mjs +117 -0
- package/dist/MessagingHost-Bm5e-kAX.mjs.map +1 -0
- package/dist/MessagingHost-CubWeYKN.d.mts +80 -0
- package/dist/OperationAuthorizer-VSiHCC2S.mjs +72 -0
- package/dist/OperationAuthorizer-VSiHCC2S.mjs.map +1 -0
- package/dist/OperationAuthorizer-y-F-Ox_Q.d.mts +62 -0
- package/dist/Output-DQ8mWcgf.mjs +7 -0
- package/dist/Output-DQ8mWcgf.mjs.map +1 -0
- package/dist/Output-SbOdlBFL.d.mts +22 -0
- package/dist/PageCapture-BfRURUOA.mjs +275 -0
- package/dist/PageCapture-BfRURUOA.mjs.map +1 -0
- package/dist/PageCapture-C_mE72Sd.d.mts +216 -0
- package/dist/PageScreenshot-BJTASs4o.mjs +53 -0
- package/dist/PageScreenshot-BJTASs4o.mjs.map +1 -0
- package/dist/PageScreenshot-CaoaH7mc.d.mts +48 -0
- package/dist/PersistentHistory-BrtZ0g2j.d.mts +14 -0
- package/dist/PersistentHistory-CTAVhHKH.mjs +147 -0
- package/dist/PersistentHistory-CTAVhHKH.mjs.map +1 -0
- package/dist/PreparedInputAdmission-Ci18uY4s.d.mts +973 -0
- package/dist/PreparedInputAdmission-adqVJJa6.mjs +95 -0
- package/dist/PreparedInputAdmission-adqVJJa6.mjs.map +1 -0
- package/dist/ProvisionalText-BcKpPYKQ.d.mts +70 -0
- package/dist/ProvisionalText-DXddTK4c.mjs +47 -0
- package/dist/ProvisionalText-DXddTK4c.mjs.map +1 -0
- package/dist/Receipt-B-FlCaNH.mjs +35 -0
- package/dist/Receipt-B-FlCaNH.mjs.map +1 -0
- package/dist/Receipt-B4feBxMY.d.mts +31 -0
- package/dist/RecordFormat-DoNh-AFe.mjs +79 -0
- package/dist/RecordFormat-DoNh-AFe.mjs.map +1 -0
- package/dist/RecordFormat-ZMus8Dx8.d.mts +52 -0
- package/dist/Records-C645aQks.mjs +1145 -0
- package/dist/Records-C645aQks.mjs.map +1 -0
- package/dist/Records-C9I1nCL9.d.mts +1423 -0
- package/dist/Recovery-zWy_kmZq.mjs +736 -0
- package/dist/Recovery-zWy_kmZq.mjs.map +1 -0
- package/dist/Redaction-C0zLBAn6.d.mts +28 -0
- package/dist/Redaction-CtyCBMEj.mjs +116 -0
- package/dist/Redaction-CtyCBMEj.mjs.map +1 -0
- package/dist/RememberingStore-BO-OnCgP.mjs +23 -0
- package/dist/RememberingStore-BO-OnCgP.mjs.map +1 -0
- package/dist/RememberingStore-DgqXmILx.d.mts +14 -0
- package/dist/RunContinuation-BVAHoYlN.d.mts +127 -0
- package/dist/RunContinuation-Bpfp087i.mjs +1060 -0
- package/dist/RunContinuation-Bpfp087i.mjs.map +1 -0
- package/dist/RunEvent-CwgDzXcH.d.mts +465 -0
- package/dist/RunEvent-DJxENnJi.mjs +345 -0
- package/dist/RunEvent-DJxENnJi.mjs.map +1 -0
- package/dist/RunEventSink-B8uM8bw2.mjs +22 -0
- package/dist/RunEventSink-B8uM8bw2.mjs.map +1 -0
- package/dist/RunEventSink-f-T4jbNB.d.mts +105 -0
- package/dist/RunHooks-Bob22Bcj.d.mts +40 -0
- package/dist/RunHooks-DWuLBVdU.mjs +60 -0
- package/dist/RunHooks-DWuLBVdU.mjs.map +1 -0
- package/dist/RunJournal-C_1eqQdr.mjs +1107 -0
- package/dist/RunJournal-C_1eqQdr.mjs.map +1 -0
- package/dist/RunOptions-BVSa3BO2.d.mts +560 -0
- package/dist/RunOptions-COEUCrx4.mjs +61 -0
- package/dist/RunOptions-COEUCrx4.mjs.map +1 -0
- package/dist/RunPolicyUsage-B-JXRZYO.mjs +25 -0
- package/dist/RunPolicyUsage-B-JXRZYO.mjs.map +1 -0
- package/dist/RunPolicyUsage-jvJo0vJp.d.mts +21 -0
- package/dist/RunStorage-CsQQ0Y5u.mjs +304 -0
- package/dist/RunStorage-CsQQ0Y5u.mjs.map +1 -0
- package/dist/Sandbox-37vXP0BV.d.mts +24 -0
- package/dist/Sandbox-Bze6pHYc.mjs +30 -0
- package/dist/Sandbox-Bze6pHYc.mjs.map +1 -0
- package/dist/Schedule-BY0lzbij.mjs +336 -0
- package/dist/Schedule-BY0lzbij.mjs.map +1 -0
- package/dist/ScheduleTransition-CjVP48I8.d.mts +22 -0
- package/dist/ScheduleTransition-DtNzlN9k.mjs +180 -0
- package/dist/ScheduleTransition-DtNzlN9k.mjs.map +1 -0
- package/dist/Scheduling-BpJN9E1j.mjs +699 -0
- package/dist/Scheduling-BpJN9E1j.mjs.map +1 -0
- package/dist/Scheduling-DYTM29s9.d.mts +57 -0
- package/dist/SemanticMemory-BRV0cuWg.mjs +300 -0
- package/dist/SemanticMemory-BRV0cuWg.mjs.map +1 -0
- package/dist/SemanticMemory-rgWlhW87.d.mts +431 -0
- package/dist/SemanticMemoryIndex-D7yNEWpt.d.mts +826 -0
- package/dist/SemanticMemoryIndex-godQDjNx.mjs +186 -0
- package/dist/SemanticMemoryIndex-godQDjNx.mjs.map +1 -0
- package/dist/SemanticMemoryRevalidation-Bm3_pfsI.d.mts +44 -0
- package/dist/SemanticMemoryRevalidation-D8VV-eU6.mjs +179 -0
- package/dist/SemanticMemoryRevalidation-D8VV-eU6.mjs.map +1 -0
- package/dist/Subagent-CSIRUgUo.mjs +1315 -0
- package/dist/Subagent-CSIRUgUo.mjs.map +1 -0
- package/dist/Subagent-CXEI5YZ8.d.mts +2368 -0
- package/dist/SubagentContract-B7vQPueI.d.mts +176 -0
- package/dist/SubagentContract-C-7AxTm_.mjs +187 -0
- package/dist/SubagentContract-C-7AxTm_.mjs.map +1 -0
- package/dist/SubagentHost-BEnICu7g.mjs +70 -0
- package/dist/SubagentHost-BEnICu7g.mjs.map +1 -0
- package/dist/SubagentHost-CKhz1vbH.d.mts +167 -0
- package/dist/SubagentReservations-BYNAHPpm.mjs +465 -0
- package/dist/SubagentReservations-BYNAHPpm.mjs.map +1 -0
- package/dist/SubagentReservations-WrmIVzO5.d.mts +185 -0
- package/dist/SubmissionLedger-WG0beEyt.mjs +921 -0
- package/dist/SubmissionLedger-WG0beEyt.mjs.map +1 -0
- package/dist/SubmissionStatus-CPZsOM5a.mjs +17 -0
- package/dist/SubmissionStatus-CPZsOM5a.mjs.map +1 -0
- package/dist/Subscription-BhQbmUD-.mjs +340 -0
- package/dist/Subscription-BhQbmUD-.mjs.map +1 -0
- package/dist/Subscription-CC--_OnU.d.mts +815 -0
- package/dist/SubscriptionInput-BEeB0Cj8.d.mts +42 -0
- package/dist/SubscriptionInput-Xcd4JjEs.mjs +53 -0
- package/dist/SubscriptionInput-Xcd4JjEs.mjs.map +1 -0
- package/dist/SubscriptionTransition-CWt9UVH0.d.mts +23 -0
- package/dist/SubscriptionTransition-lrf733c8.mjs +154 -0
- package/dist/SubscriptionTransition-lrf733c8.mjs.map +1 -0
- package/dist/Subscriptions-4K_qu_2f.mjs +638 -0
- package/dist/Subscriptions-4K_qu_2f.mjs.map +1 -0
- package/dist/Subscriptions-BF3aSf8X.d.mts +75 -0
- package/dist/Thread-B8JApGHa.mjs +283 -0
- package/dist/Thread-B8JApGHa.mjs.map +1 -0
- package/dist/Thread-BnAtkJl4.d.mts +116 -0
- package/dist/ThreadArchiveRange-1PMdjpdJ.mjs +64 -0
- package/dist/ThreadArchiveRange-1PMdjpdJ.mjs.map +1 -0
- package/dist/ThreadContextHistory-BSStMOLX.mjs +211 -0
- package/dist/ThreadContextHistory-BSStMOLX.mjs.map +1 -0
- package/dist/ThreadContextHistory-lTZ8Ftq1.d.mts +33 -0
- package/dist/ThreadContextHistoryProjection-Cp7_RR6V.d.mts +59 -0
- package/dist/ThreadContextHistoryProjection-_8uNz-h1.mjs +149 -0
- package/dist/ThreadContextHistoryProjection-_8uNz-h1.mjs.map +1 -0
- package/dist/ThreadHistory-BkyGfv5E.d.mts +76 -0
- package/dist/ThreadHistory-Blt_W31N.mjs +69 -0
- package/dist/ThreadHistory-Blt_W31N.mjs.map +1 -0
- package/dist/ThreadImport-C8Tqiezd.mjs +491 -0
- package/dist/ThreadImport-C8Tqiezd.mjs.map +1 -0
- package/dist/ThreadImport-DaSmrlRi.d.mts +843 -0
- package/dist/ThreadInvariants-DyPhMeo-.d.mts +23 -0
- package/dist/ThreadInvariants-fniroLRY.mjs +154 -0
- package/dist/ThreadInvariants-fniroLRY.mjs.map +1 -0
- package/dist/ThreadProjectionMaintenance-D6fBjr1q.mjs +37 -0
- package/dist/ThreadProjectionMaintenance-D6fBjr1q.mjs.map +1 -0
- package/dist/ThreadProjectionMaintenance-DjUy7kCa.d.mts +51 -0
- package/dist/ThreadStore-BMUAp5Ta.mjs +937 -0
- package/dist/ThreadStore-BMUAp5Ta.mjs.map +1 -0
- package/dist/ThreadTransfer-B3NkyO_y.mjs +154 -0
- package/dist/ThreadTransfer-B3NkyO_y.mjs.map +1 -0
- package/dist/ThreadTransfer-BM02cbOo.d.mts +63 -0
- package/dist/ThreadWork-C-xa2Boi.mjs +484 -0
- package/dist/ThreadWork-C-xa2Boi.mjs.map +1 -0
- package/dist/ToolBroker-DkoVyx6T.mjs +42 -0
- package/dist/ToolBroker-DkoVyx6T.mjs.map +1 -0
- package/dist/ToolBroker-Dy2xM6ht.d.mts +134 -0
- package/dist/ToolDiscovery-DHySvLQd.mjs +211 -0
- package/dist/ToolDiscovery-DHySvLQd.mjs.map +1 -0
- package/dist/ToolDiscovery-VjamzX3q.d.mts +119 -0
- package/dist/ToolExposure-Cn7xETn5.d.mts +6 -0
- package/dist/ToolExposure-D7id9Gt5.d.mts +37 -0
- package/dist/ToolExposure-DCvQWFIa.mjs +9 -0
- package/dist/ToolExposure-DCvQWFIa.mjs.map +1 -0
- package/dist/ToolExposure-DNME8BkG.d.mts +44 -0
- package/dist/ToolExposure-DPnq8Won.mjs +30 -0
- package/dist/ToolExposure-DPnq8Won.mjs.map +1 -0
- package/dist/ToolExposure-DaGaF5tj.mjs +20 -0
- package/dist/ToolExposure-DaGaF5tj.mjs.map +1 -0
- package/dist/ToolExposure.d.mts +4 -0
- package/dist/ToolExposure.mjs +4 -0
- package/dist/ToolReconciler-6bb7xlip.d.mts +81 -0
- package/dist/ToolReconciler-DJQd3SZA.mjs +87 -0
- package/dist/ToolReconciler-DJQd3SZA.mjs.map +1 -0
- package/dist/ToolResult-By5KAje4.d.mts +79 -0
- package/dist/ToolResult-DwZxjlHw.mjs +160 -0
- package/dist/ToolResult-DwZxjlHw.mjs.map +1 -0
- package/dist/ToolResultStorage-BmoRewhh.mjs +46 -0
- package/dist/ToolResultStorage-BmoRewhh.mjs.map +1 -0
- package/dist/ToolResultStorage-Bp5fm0do.d.mts +49 -0
- package/dist/ToolResults-C4-HsMCp.d.mts +33 -0
- package/dist/ToolResults-nCgBlTp2.mjs +45 -0
- package/dist/ToolResults-nCgBlTp2.mjs.map +1 -0
- package/dist/Usage-B0xgME5f.mjs +340 -0
- package/dist/Usage-B0xgME5f.mjs.map +1 -0
- package/dist/Usage-Bc-jXe_9.d.mts +128 -0
- package/dist/WakeScheduler-DVYj66C-.mjs +74 -0
- package/dist/WakeScheduler-DVYj66C-.mjs.map +1 -0
- package/dist/WakeScheduler-SFqj67Sk.d.mts +74 -0
- package/dist/WebCapture-CA4ZarW2.mjs +64 -0
- package/dist/WebCapture-CA4ZarW2.mjs.map +1 -0
- package/dist/WebCapture-pzIeUJ5W.d.mts +49 -0
- package/dist/WebSearch-CD0V--qh.d.mts +18 -0
- package/dist/WebSearch-DnbOzRL_.mjs +30 -0
- package/dist/WebSearch-DnbOzRL_.mjs.map +1 -0
- package/dist/Worker-CQu8Qp1j.mjs +267 -0
- package/dist/Worker-CQu8Qp1j.mjs.map +1 -0
- package/dist/Worker-xxucY_0b.d.mts +468 -0
- package/dist/WorkerAdmission-BhFjx86s.mjs +162 -0
- package/dist/WorkerAdmission-BhFjx86s.mjs.map +1 -0
- package/dist/WorkerAdmission-BnRuXLWF.d.mts +171 -0
- package/dist/WorkerHost-DtYzi54D.d.mts +150 -0
- package/dist/WorkerHost-DuQug9Bq.mjs +73 -0
- package/dist/WorkerHost-DuQug9Bq.mjs.map +1 -0
- package/dist/agent-registration-CNs2twrr.mjs +262 -0
- package/dist/agent-registration-CNs2twrr.mjs.map +1 -0
- package/dist/capabilities/BrowserUse.d.mts +2 -0
- package/dist/capabilities/BrowserUse.mjs +1 -0
- package/dist/capabilities/Budget.d.mts +2 -0
- package/dist/capabilities/Budget.mjs +1 -0
- package/dist/capabilities/CodeMode.d.mts +2 -0
- package/dist/capabilities/CodeMode.mjs +1 -0
- package/dist/capabilities/ContextTools.d.mts +2 -0
- package/dist/capabilities/ContextTools.mjs +1 -0
- package/dist/capabilities/MemoryNotes.d.mts +2 -0
- package/dist/capabilities/MemoryNotes.mjs +1 -0
- package/dist/capabilities/Messaging.d.mts +3 -0
- package/dist/capabilities/Messaging.mjs +4 -0
- package/dist/capabilities/Redaction.d.mts +2 -0
- package/dist/capabilities/Redaction.mjs +1 -0
- package/dist/capabilities/RunHooks.d.mts +2 -0
- package/dist/capabilities/RunHooks.mjs +1 -0
- package/dist/capabilities/SemanticMemory.d.mts +2 -0
- package/dist/capabilities/SemanticMemory.mjs +1 -0
- package/dist/capabilities/Subagent.d.mts +4 -0
- package/dist/capabilities/Subagent.mjs +6 -0
- package/dist/capabilities/SubagentReservations.d.mts +2 -0
- package/dist/capabilities/SubagentReservations.mjs +1 -0
- package/dist/capabilities/ToolDiscovery.d.mts +2 -0
- package/dist/capabilities/ToolDiscovery.mjs +1 -0
- package/dist/capabilities/ToolResults.d.mts +2 -0
- package/dist/capabilities/ToolResults.mjs +1 -0
- package/dist/capabilities/WebCapture.d.mts +2 -0
- package/dist/capabilities/WebCapture.mjs +1 -0
- package/dist/capabilities/WebSearch.d.mts +2 -0
- package/dist/capabilities/WebSearch.mjs +1 -0
- package/dist/compaction-C3hXuO4Z.mjs +539 -0
- package/dist/compaction-C3hXuO4Z.mjs.map +1 -0
- package/dist/completion-B_WDnSg-.d.mts +11 -0
- package/dist/core/Agent.d.mts +2 -0
- package/dist/core/Agent.mjs +1 -0
- package/dist/core/AgentError.d.mts +2 -0
- package/dist/core/AgentError.mjs +1 -0
- package/dist/core/AgentPolicy.d.mts +2 -0
- package/dist/core/AgentPolicy.mjs +1 -0
- package/dist/core/AgentUpdates.d.mts +2 -0
- package/dist/core/AgentUpdates.mjs +1 -0
- package/dist/core/FailureDiagnostic.d.mts +2 -0
- package/dist/core/FailureDiagnostic.mjs +1 -0
- package/dist/core/IdGenerator.d.mts +2 -0
- package/dist/core/IdGenerator.mjs +1 -0
- package/dist/core/Identifiers.d.mts +2 -0
- package/dist/core/Identifiers.mjs +1 -0
- package/dist/core/Memory.d.mts +2 -0
- package/dist/core/Memory.mjs +1 -0
- package/dist/core/MemoryNamespace.d.mts +2 -0
- package/dist/core/MemoryNamespace.mjs +1 -0
- package/dist/core/MemoryReference.d.mts +2 -0
- package/dist/core/MemoryReference.mjs +1 -0
- package/dist/core/MemoryRevalidation.d.mts +2 -0
- package/dist/core/MemoryRevalidation.mjs +1 -0
- package/dist/core/MemoryStore.d.mts +2 -0
- package/dist/core/MemoryStore.mjs +1 -0
- package/dist/core/ProvisionalText.d.mts +2 -0
- package/dist/core/ProvisionalText.mjs +1 -0
- package/dist/core/Receipt.d.mts +2 -0
- package/dist/core/Receipt.mjs +1 -0
- package/dist/core/RememberingStore.d.mts +2 -0
- package/dist/core/RememberingStore.mjs +1 -0
- package/dist/core/RunEvent.d.mts +3 -0
- package/dist/core/RunEvent.mjs +1 -0
- package/dist/core/RunPolicyUsage.d.mts +2 -0
- package/dist/core/RunPolicyUsage.mjs +1 -0
- package/dist/core/SemanticMemoryIndex.d.mts +2 -0
- package/dist/core/SemanticMemoryIndex.mjs +1 -0
- package/dist/core/SemanticMemoryRevalidation.d.mts +2 -0
- package/dist/core/SemanticMemoryRevalidation.mjs +1 -0
- package/dist/core/SubagentContract.d.mts +2 -0
- package/dist/core/SubagentContract.mjs +1 -0
- package/dist/core/Thread.d.mts +2 -0
- package/dist/core/Thread.mjs +1 -0
- package/dist/core/ToolResult.d.mts +2 -0
- package/dist/core/ToolResult.mjs +1 -0
- package/dist/core/ToolResultStorage.d.mts +2 -0
- package/dist/core/ToolResultStorage.mjs +1 -0
- package/dist/core/Usage.d.mts +2 -0
- package/dist/core/Usage.mjs +1 -0
- package/dist/core/Worker.d.mts +3 -0
- package/dist/core/Worker.mjs +3 -0
- package/dist/durable/ActivityStore.d.mts +2 -0
- package/dist/durable/ActivityStore.mjs +1 -0
- package/dist/durable/Admin.d.mts +2 -0
- package/dist/durable/Admin.mjs +1 -0
- package/dist/durable/AgentRegistration.d.mts +3 -0
- package/dist/durable/AgentRegistration.mjs +2 -0
- package/dist/durable/CommittedActivity.d.mts +2 -0
- package/dist/durable/CommittedActivity.mjs +1 -0
- package/dist/durable/Digest.d.mts +2 -0
- package/dist/durable/Digest.mjs +3 -0
- package/dist/durable/DurableAgentRuntime.d.mts +3 -0
- package/dist/durable/DurableAgentRuntime.mjs +4 -0
- package/dist/durable/DurableFailpoint.d.mts +2 -0
- package/dist/durable/DurableFailpoint.mjs +1 -0
- package/dist/durable/DurableFailpointTestControl.d.mts +14 -0
- package/dist/durable/DurableFailpointTestControl.mjs +21 -0
- package/dist/durable/DurableFailpointTestControl.mjs.map +1 -0
- package/dist/durable/EventSource.d.mts +2 -0
- package/dist/durable/EventSource.mjs +1 -0
- package/dist/durable/LifecyclePublication.d.mts +2 -0
- package/dist/durable/LifecyclePublication.mjs +1 -0
- package/dist/durable/MessageDelivery.d.mts +2 -0
- package/dist/durable/MessageDelivery.mjs +1 -0
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +401 -0
- package/dist/durable/MessageDeliveryStoreConformance.mjs +273 -0
- package/dist/durable/MessageDeliveryStoreConformance.mjs.map +1 -0
- package/dist/durable/OperationAuthorizer.d.mts +2 -0
- package/dist/durable/OperationAuthorizer.mjs +1 -0
- package/dist/durable/PersistentHistory.d.mts +2 -0
- package/dist/durable/PersistentHistory.mjs +1 -0
- package/dist/durable/PreparedInputAdmission.d.mts +2 -0
- package/dist/durable/PreparedInputAdmission.mjs +1 -0
- package/dist/durable/RecordFormat.d.mts +2 -0
- package/dist/durable/RecordFormat.mjs +1 -0
- package/dist/durable/Records.d.mts +2 -0
- package/dist/durable/Records.mjs +1 -0
- package/dist/durable/Recovery.d.mts +2 -0
- package/dist/durable/Recovery.mjs +1 -0
- package/dist/durable/RunContinuation.d.mts +4 -0
- package/dist/durable/RunContinuation.mjs +4 -0
- package/dist/durable/RunJournal.d.mts +2 -0
- package/dist/durable/RunJournal.mjs +1 -0
- package/dist/durable/RunStorage.d.mts +2 -0
- package/dist/durable/RunStorage.mjs +1 -0
- package/dist/durable/Schedule.d.mts +2 -0
- package/dist/durable/Schedule.mjs +1 -0
- package/dist/durable/ScheduleStoreConformance.d.mts +16 -0
- package/dist/durable/ScheduleStoreConformance.mjs +421 -0
- package/dist/durable/ScheduleStoreConformance.mjs.map +1 -0
- package/dist/durable/ScheduleTransition.d.mts +2 -0
- package/dist/durable/ScheduleTransition.mjs +1 -0
- package/dist/durable/Scheduling.d.mts +2 -0
- package/dist/durable/Scheduling.mjs +1 -0
- package/dist/durable/SettlementPublisher.d.mts +2 -0
- package/dist/durable/SettlementPublisher.mjs +99 -0
- package/dist/durable/SettlementPublisher.mjs.map +1 -0
- package/dist/durable/SqlMemoryStore.d.mts +729 -0
- package/dist/durable/SqlMemoryStore.mjs +626 -0
- package/dist/durable/SqlMemoryStore.mjs.map +1 -0
- package/dist/durable/SqlStorageOwner.d.mts +18 -0
- package/dist/durable/SqlStorageOwner.mjs +6 -0
- package/dist/durable/SqlStorageOwner.mjs.map +1 -0
- package/dist/durable/SubmissionLedger.d.mts +3 -0
- package/dist/durable/SubmissionLedger.mjs +3 -0
- package/dist/durable/SubmissionLedgerConformance.d.mts +31 -0
- package/dist/durable/SubmissionLedgerConformance.mjs +2090 -0
- package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -0
- package/dist/durable/SubmissionStatus.d.mts +2 -0
- package/dist/durable/SubmissionStatus.mjs +1 -0
- package/dist/durable/Subscription.d.mts +2 -0
- package/dist/durable/Subscription.mjs +1 -0
- package/dist/durable/SubscriptionInput.d.mts +2 -0
- package/dist/durable/SubscriptionInput.mjs +1 -0
- package/dist/durable/SubscriptionStoreConformance.d.mts +15 -0
- package/dist/durable/SubscriptionStoreConformance.mjs +816 -0
- package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -0
- package/dist/durable/SubscriptionTransition.d.mts +2 -0
- package/dist/durable/SubscriptionTransition.mjs +1 -0
- package/dist/durable/Subscriptions.d.mts +2 -0
- package/dist/durable/Subscriptions.mjs +1 -0
- package/dist/durable/ThreadArchiveRange.d.mts +2 -0
- package/dist/durable/ThreadArchiveRange.mjs +1 -0
- package/dist/durable/ThreadContextHistory.d.mts +2 -0
- package/dist/durable/ThreadContextHistory.mjs +1 -0
- package/dist/durable/ThreadContextHistoryProjection.d.mts +2 -0
- package/dist/durable/ThreadContextHistoryProjection.mjs +1 -0
- package/dist/durable/ThreadImport.d.mts +2 -0
- package/dist/durable/ThreadImport.mjs +1 -0
- package/dist/durable/ThreadInvariants.d.mts +2 -0
- package/dist/durable/ThreadInvariants.mjs +1 -0
- package/dist/durable/ThreadProjectionMaintenance.d.mts +2 -0
- package/dist/durable/ThreadProjectionMaintenance.mjs +1 -0
- package/dist/durable/ThreadReader.d.mts +2 -0
- package/dist/durable/ThreadReader.mjs +1 -0
- package/dist/durable/ThreadStore.d.mts +3 -0
- package/dist/durable/ThreadStore.mjs +3 -0
- package/dist/durable/ThreadStoreConformance.d.mts +53 -0
- package/dist/durable/ThreadStoreConformance.mjs +402 -0
- package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
- package/dist/durable/ThreadTransfer.d.mts +2 -0
- package/dist/durable/ThreadTransfer.mjs +1 -0
- package/dist/durable/ThreadWork.d.mts +2 -0
- package/dist/durable/ThreadWork.mjs +1 -0
- package/dist/durable/ToolReconciler.d.mts +2 -0
- package/dist/durable/ToolReconciler.mjs +1 -0
- package/dist/durable/WakeScheduler.d.mts +2 -0
- package/dist/durable/WakeScheduler.mjs +1 -0
- package/dist/durable/WorkerAdmission.d.mts +2 -0
- package/dist/durable/WorkerAdmission.mjs +1 -0
- package/dist/durable/WorkerHost.d.mts +2 -0
- package/dist/durable/WorkerHost.mjs +1 -0
- package/dist/engine/AgentRuntime.d.mts +2 -0
- package/dist/engine/AgentRuntime.mjs +1 -0
- package/dist/engine/Compaction.d.mts +4 -0
- package/dist/engine/Compaction.mjs +2 -0
- package/dist/engine/ContextCompactor.d.mts +2 -0
- package/dist/engine/ContextCompactor.mjs +1 -0
- package/dist/engine/ContextHistory.d.mts +2 -0
- package/dist/engine/ContextHistory.mjs +1 -0
- package/dist/engine/ContextWindow.d.mts +2 -0
- package/dist/engine/ContextWindow.mjs +1 -0
- package/dist/engine/DurableStep.d.mts +2 -0
- package/dist/engine/DurableStep.mjs +3 -0
- package/dist/engine/MessagingHost.d.mts +2 -0
- package/dist/engine/MessagingHost.mjs +1 -0
- package/dist/engine/Output.d.mts +3 -0
- package/dist/engine/Output.mjs +2 -0
- package/dist/engine/RunEventSink.d.mts +2 -0
- package/dist/engine/RunEventSink.mjs +1 -0
- package/dist/engine/RunOptions.d.mts +2 -0
- package/dist/engine/RunOptions.mjs +1 -0
- package/dist/engine/SubagentHost.d.mts +2 -0
- package/dist/engine/SubagentHost.mjs +1 -0
- package/dist/engine/ThreadHistory.d.mts +2 -0
- package/dist/engine/ThreadHistory.mjs +1 -0
- package/dist/engine/ToolBroker.d.mts +2 -0
- package/dist/engine/ToolBroker.mjs +1 -0
- package/dist/index.d.mts +90 -0
- package/dist/index.mjs +101 -0
- package/dist/output-contract-CYA4oBhe.mjs +128 -0
- package/dist/output-contract-CYA4oBhe.mjs.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/dist/run-context-reader-CHox63hg.d.mts +17 -0
- package/dist/sandbox/CodeExecutor.d.mts +2 -0
- package/dist/sandbox/CodeExecutor.mjs +1 -0
- package/dist/sandbox/InteractiveBrowser.d.mts +2 -0
- package/dist/sandbox/InteractiveBrowser.mjs +1 -0
- package/dist/sandbox/PageCapture.d.mts +2 -0
- package/dist/sandbox/PageCapture.mjs +1 -0
- package/dist/sandbox/PageScreenshot.d.mts +2 -0
- package/dist/sandbox/PageScreenshot.mjs +1 -0
- package/dist/sandbox/Sandbox.d.mts +2 -0
- package/dist/sandbox/Sandbox.mjs +1 -0
- package/dist/subagent-policy-xRJhrc0a.mjs +133 -0
- package/dist/subagent-policy-xRJhrc0a.mjs.map +1 -0
- package/dist/tool-execution-Cl7v8fXU.mjs +16 -0
- package/dist/tool-execution-Cl7v8fXU.mjs.map +1 -0
- package/dist/tool-operations-CauPonM8.mjs +84 -0
- package/dist/tool-operations-CauPonM8.mjs.map +1 -0
- package/dist/utf8-Bl0ZhhGe.mjs +27 -0
- package/dist/utf8-Bl0ZhhGe.mjs.map +1 -0
- package/package.json +489 -5
- package/src/InMemory.ts +79 -0
- package/src/ToolExposure.ts +2 -0
- package/src/capabilities/BrowserUse.ts +212 -0
- package/src/capabilities/Budget.ts +544 -0
- package/src/capabilities/CodeMode.ts +1129 -0
- package/src/capabilities/ContextTools.ts +131 -0
- package/src/capabilities/MemoryNotes.ts +177 -0
- package/src/capabilities/Messaging.ts +260 -0
- package/src/capabilities/Redaction.ts +163 -0
- package/src/capabilities/RunHooks.ts +116 -0
- package/src/capabilities/SemanticMemory.ts +402 -0
- package/src/capabilities/Subagent.ts +2343 -0
- package/src/capabilities/SubagentReservations.ts +807 -0
- package/src/capabilities/ToolDiscovery.ts +291 -0
- package/src/capabilities/ToolResults.ts +50 -0
- package/src/capabilities/WebCapture.ts +64 -0
- package/src/capabilities/WebSearch.ts +45 -0
- package/src/capabilities/internal/subagent-background.ts +1137 -0
- package/src/capabilities/internal/subagent-contract.ts +92 -0
- package/src/capabilities/internal/subagent-policy.ts +205 -0
- package/src/capabilities/internal/subagent-reporting.ts +152 -0
- package/src/core/Agent.ts +528 -0
- package/src/core/AgentError.ts +189 -0
- package/src/core/AgentPolicy.ts +194 -0
- package/src/core/AgentUpdates.ts +104 -0
- package/src/core/FailureDiagnostic.ts +392 -0
- package/src/core/IdGenerator.ts +42 -0
- package/src/core/Identifiers.ts +64 -0
- package/src/core/Memory.ts +283 -0
- package/src/core/MemoryNamespace.ts +202 -0
- package/src/core/MemoryReference.ts +120 -0
- package/src/core/MemoryRevalidation.ts +151 -0
- package/src/core/MemoryStore.ts +371 -0
- package/src/core/Messaging.ts +72 -0
- package/src/core/ProvisionalText.ts +53 -0
- package/src/core/Receipt.ts +42 -0
- package/src/core/RememberingStore.ts +22 -0
- package/src/core/RunEvent.ts +345 -0
- package/src/core/RunPolicyUsage.ts +19 -0
- package/src/core/SemanticMemoryIndex.ts +259 -0
- package/src/core/SemanticMemoryRevalidation.ts +220 -0
- package/src/core/SubagentContract.ts +263 -0
- package/src/core/Thread.ts +447 -0
- package/src/core/ToolExposure.ts +75 -0
- package/src/core/ToolResult.ts +204 -0
- package/src/core/ToolResultStorage.ts +56 -0
- package/src/core/Usage.ts +562 -0
- package/src/core/Worker.ts +236 -0
- package/src/core/internal/agent-updates.ts +42 -0
- package/src/core/internal/completion.ts +33 -0
- package/src/core/internal/json.ts +17 -0
- package/src/core/internal/memory-document.ts +39 -0
- package/src/core/internal/message-status.ts +60 -0
- package/src/core/internal/strict-schema.ts +14 -0
- package/src/core/internal/tool-execution.ts +33 -0
- package/src/core/internal/utf8.ts +32 -0
- package/src/durable/ActivityStore.ts +131 -0
- package/src/durable/Admin.ts +504 -0
- package/src/durable/AgentRegistration.ts +16 -0
- package/src/durable/CommittedActivity.ts +262 -0
- package/src/durable/Digest.ts +57 -0
- package/src/durable/DurableAgentRuntime.ts +12758 -0
- package/src/durable/DurableFailpoint.ts +108 -0
- package/src/durable/DurableFailpointTestControl.ts +39 -0
- package/src/durable/EventSource.ts +179 -0
- package/src/durable/LifecyclePublication.ts +343 -0
- package/src/durable/MessageDelivery.ts +949 -0
- package/src/durable/MessageDeliveryStoreConformance.ts +407 -0
- package/src/durable/OperationAuthorizer.ts +89 -0
- package/src/durable/PersistentHistory.ts +322 -0
- package/src/durable/PreparedInputAdmission.ts +128 -0
- package/src/durable/RecordFormat.ts +113 -0
- package/src/durable/Records.ts +1396 -0
- package/src/durable/Recovery.ts +1022 -0
- package/src/durable/RunContinuation.ts +1946 -0
- package/src/durable/RunJournal.ts +1926 -0
- package/src/durable/RunStorage.ts +533 -0
- package/src/durable/Schedule.ts +445 -0
- package/src/durable/ScheduleStoreConformance.ts +642 -0
- package/src/durable/ScheduleTransition.ts +267 -0
- package/src/durable/Scheduling.ts +1031 -0
- package/src/durable/SettlementPublisher.ts +172 -0
- package/src/durable/SqlMemoryStore.ts +1042 -0
- package/src/durable/SqlStorageOwner.ts +25 -0
- package/src/durable/SubmissionLedger.ts +1247 -0
- package/src/durable/SubmissionLedgerConformance.ts +4695 -0
- package/src/durable/SubmissionStatus.ts +14 -0
- package/src/durable/Subscription.ts +527 -0
- package/src/durable/SubscriptionInput.ts +145 -0
- package/src/durable/SubscriptionStoreConformance.ts +1275 -0
- package/src/durable/SubscriptionTransition.ts +330 -0
- package/src/durable/Subscriptions.ts +1245 -0
- package/src/durable/ThreadArchiveRange.ts +91 -0
- package/src/durable/ThreadContextHistory.ts +338 -0
- package/src/durable/ThreadContextHistoryProjection.ts +219 -0
- package/src/durable/ThreadImport.ts +1199 -0
- package/src/durable/ThreadInvariants.ts +312 -0
- package/src/durable/ThreadProjectionMaintenance.ts +72 -0
- package/src/durable/ThreadReader.ts +21 -0
- package/src/durable/ThreadStore.ts +1258 -0
- package/src/durable/ThreadStoreConformance.ts +877 -0
- package/src/durable/ThreadTransfer.ts +263 -0
- package/src/durable/ThreadWork.ts +713 -0
- package/src/durable/ToolReconciler.ts +112 -0
- package/src/durable/WakeScheduler.ts +125 -0
- package/src/durable/WorkerAdmission.ts +98 -0
- package/src/durable/WorkerHost.ts +204 -0
- package/src/durable/internal/StorageOwner.ts +181 -0
- package/src/durable/internal/agent-registration.ts +713 -0
- package/src/durable/internal/agent-updates.ts +338 -0
- package/src/durable/internal/canonical-json.ts +110 -0
- package/src/durable/internal/evidence.ts +29 -0
- package/src/durable/internal/foreign-diagnostic.ts +48 -0
- package/src/durable/internal/history-prompt.ts +87 -0
- package/src/durable/internal/initial-context.ts +215 -0
- package/src/durable/internal/journal-metadata.ts +188 -0
- package/src/durable/internal/message-status.ts +18 -0
- package/src/durable/internal/messaging-host.ts +615 -0
- package/src/durable/internal/prompt-footprint.ts +47 -0
- package/src/durable/internal/prompt-history-cache.ts +604 -0
- package/src/durable/internal/record-encoding.ts +258 -0
- package/src/durable/internal/record-ownership.ts +68 -0
- package/src/durable/internal/run-context-reader.ts +51 -0
- package/src/durable/internal/run-context.ts +211 -0
- package/src/durable/internal/schedule-time.ts +304 -0
- package/src/durable/internal/thread-import-reader.ts +85 -0
- package/src/durable/internal/thread-initialization.ts +181 -0
- package/src/durable/internal/thread-transfer-source.ts +7 -0
- package/src/durable/internal/tool-operations.ts +138 -0
- package/src/durable/internal/transfer-dependencies.ts +40 -0
- package/src/durable/internal/usage-totals.ts +36 -0
- package/src/durable/internal/worker-host.ts +4041 -0
- package/src/durable/internal/worker-runtime.ts +10 -0
- package/src/engine/AgentRuntime.ts +100 -0
- package/src/engine/Compaction.ts +11 -0
- package/src/engine/ContextCompactor.ts +302 -0
- package/src/engine/ContextHistory.ts +75 -0
- package/src/engine/ContextWindow.ts +81 -0
- package/src/engine/DurableStep.ts +115 -0
- package/src/engine/MessagingHost.ts +118 -0
- package/src/engine/Output.ts +2 -0
- package/src/engine/RunEventSink.ts +124 -0
- package/src/engine/RunOptions.ts +664 -0
- package/src/engine/SubagentHost.ts +231 -0
- package/src/engine/ThreadHistory.ts +125 -0
- package/src/engine/ToolBroker.ts +159 -0
- package/src/engine/ToolExposure.ts +49 -0
- package/src/engine/internal/agent-runtime.ts +11137 -0
- package/src/engine/internal/bounded-value.ts +312 -0
- package/src/engine/internal/compaction.ts +673 -0
- package/src/engine/internal/error-diagnostic.ts +39 -0
- package/src/engine/internal/image-tokens.ts +61 -0
- package/src/engine/internal/interpreter-options.ts +569 -0
- package/src/engine/internal/output-contract.ts +226 -0
- package/src/engine/internal/primitive-delta.ts +103 -0
- package/src/engine/internal/provider-result-staging.ts +211 -0
- package/src/engine/internal/provisional-text.ts +107 -0
- package/src/engine/internal/tool-derivative.ts +47 -0
- package/src/engine/internal/tool-exposure.ts +228 -0
- package/src/engine/internal/tool-telemetry.ts +488 -0
- package/src/index.ts +100 -0
- package/src/sandbox/CodeExecutor.ts +352 -0
- package/src/sandbox/InteractiveBrowser.ts +343 -0
- package/src/sandbox/PageCapture.ts +391 -0
- package/src/sandbox/PageScreenshot.ts +83 -0
- package/src/sandbox/Sandbox.ts +29 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1245 @@
|
|
|
1
|
+
import * as Cause from 'effect/Cause'
|
|
2
|
+
import * as Context from 'effect/Context'
|
|
3
|
+
import * as CryptoDigest from 'effect/crypto/Digest'
|
|
4
|
+
import * as DateTime from 'effect/DateTime'
|
|
5
|
+
import * as Effect from 'effect/Effect'
|
|
6
|
+
import * as Layer from 'effect/Layer'
|
|
7
|
+
import * as Option from 'effect/Option'
|
|
8
|
+
import * as Schema from 'effect/Schema'
|
|
9
|
+
import * as Semaphore from 'effect/Semaphore'
|
|
10
|
+
|
|
11
|
+
import { ThreadId } from '../core/Identifiers'
|
|
12
|
+
import { utf8ByteLength } from '../core/internal/utf8'
|
|
13
|
+
import { digestJson } from './Digest'
|
|
14
|
+
import { EventSources, type NormalizedEvent } from './EventSource'
|
|
15
|
+
import {
|
|
16
|
+
admitPreparedInput,
|
|
17
|
+
PreparedInput,
|
|
18
|
+
PreparedInputAdmission,
|
|
19
|
+
type PreparedInputRetryReason,
|
|
20
|
+
} from './PreparedInputAdmission'
|
|
21
|
+
import { DefinitionDigests, type PersistedJson } from './Records'
|
|
22
|
+
import { type AdmissionFence, IdempotencyKey, type Principal } from './SubmissionLedger'
|
|
23
|
+
import {
|
|
24
|
+
AcceptedEvent,
|
|
25
|
+
defaultSubscriptionLimits,
|
|
26
|
+
type EventAcknowledgement,
|
|
27
|
+
type EventSourceVersion,
|
|
28
|
+
SubscriptionAuthorizer,
|
|
29
|
+
type SubscriptionChange,
|
|
30
|
+
SubscriptionConfiguration,
|
|
31
|
+
SubscriptionDelivery,
|
|
32
|
+
type SubscriptionDeliveryKey,
|
|
33
|
+
subscriptionDeliveryKeyString,
|
|
34
|
+
type SubscriptionDeliverySnapshot,
|
|
35
|
+
SubscriptionError,
|
|
36
|
+
SubscriptionFailpoint,
|
|
37
|
+
SubscriptionKey,
|
|
38
|
+
SubscriptionLimits,
|
|
39
|
+
type SubscriptionRecord,
|
|
40
|
+
SubscriptionScope,
|
|
41
|
+
type SubscriptionSnapshot,
|
|
42
|
+
SubscriptionSourceError,
|
|
43
|
+
SubscriptionStore,
|
|
44
|
+
type SubscriptionStoreFailure,
|
|
45
|
+
} from './Subscription'
|
|
46
|
+
import { resolveSubscriptionInput, SubscriptionInputBindings } from './SubscriptionInput'
|
|
47
|
+
|
|
48
|
+
const now = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis))
|
|
49
|
+
|
|
50
|
+
const failure = (reason: SubscriptionError['reason'], code: string) => SubscriptionError.make({ reason, code })
|
|
51
|
+
|
|
52
|
+
const bytes = (value: PersistedJson) => utf8ByteLength(JSON.stringify(value))
|
|
53
|
+
|
|
54
|
+
const sameSource = (a: EventSourceVersion, b: EventSourceVersion) => a.name === b.name && a.version === b.version
|
|
55
|
+
|
|
56
|
+
const samePartition = Schema.toEquivalence(SubscriptionScope.fields.partition)
|
|
57
|
+
|
|
58
|
+
const validate = <S extends Schema.Top>(schema: S, value: unknown) =>
|
|
59
|
+
Schema.decodeUnknownEffect(schema)(value).pipe(
|
|
60
|
+
Effect.mapError(() => failure('validation', 'schema')),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const snapshot = (record: SubscriptionRecord, time: number): SubscriptionSnapshot => ({
|
|
64
|
+
key: record.key,
|
|
65
|
+
configurationRevision: record.configurationRevision,
|
|
66
|
+
configurationFingerprint: record.configurationFingerprint,
|
|
67
|
+
...(record.configuration.admissionGroup === undefined
|
|
68
|
+
? {}
|
|
69
|
+
: { admissionGroup: record.configuration.admissionGroup }),
|
|
70
|
+
...(record.configuration.admissionFence === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: { admissionFence: record.configuration.admissionFence }),
|
|
73
|
+
source: record.configuration.source,
|
|
74
|
+
mode: record.configuration.mode,
|
|
75
|
+
state: record.state === 'active' &&
|
|
76
|
+
record.configuration.expiresAtMillis !== null &&
|
|
77
|
+
record.configuration.expiresAtMillis <= time
|
|
78
|
+
? 'expired'
|
|
79
|
+
: record.state,
|
|
80
|
+
createdAtMillis: record.createdAtMillis,
|
|
81
|
+
expiresAtMillis: record.configuration.expiresAtMillis,
|
|
82
|
+
recovery: record.recovery,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const deliverySnapshot = (
|
|
86
|
+
record: SubscriptionDelivery,
|
|
87
|
+
): typeof SubscriptionDeliverySnapshot.Type => ({
|
|
88
|
+
key: record.key,
|
|
89
|
+
state: record.state,
|
|
90
|
+
configurationRevision: record.configurationRevision,
|
|
91
|
+
...(record.observeSettlement === undefined
|
|
92
|
+
? {}
|
|
93
|
+
: { observeSettlement: record.observeSettlement }),
|
|
94
|
+
...(record.settledAtMillis === undefined ? {} : { settledAtMillis: record.settledAtMillis }),
|
|
95
|
+
retry: record.retry,
|
|
96
|
+
receipt: record.receipt,
|
|
97
|
+
refusal: record.refusal,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
export interface SubscribeOptions {
|
|
101
|
+
readonly subscriptionId: string
|
|
102
|
+
readonly source: EventSourceVersion
|
|
103
|
+
readonly parameters: PersistedJson
|
|
104
|
+
readonly context: PersistedJson
|
|
105
|
+
readonly mode: 'once' | 'continuous'
|
|
106
|
+
readonly expiresAtMillis: number | null
|
|
107
|
+
readonly destination: SubscriptionConfiguration['destination']
|
|
108
|
+
readonly deliveryPrincipal: Principal
|
|
109
|
+
readonly admissionGroup?: string
|
|
110
|
+
readonly admissionFence?: AdmissionFence
|
|
111
|
+
readonly agentId: SubscriptionConfiguration['agentId']
|
|
112
|
+
readonly definitions: SubscriptionConfiguration['definitions']
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type SubscriptionFailure = SubscriptionStoreFailure | SubscriptionSourceError
|
|
116
|
+
|
|
117
|
+
/** Only management and redacted status. Do not provide intake or drivers to Agent Tools. */
|
|
118
|
+
export class Subscriptions extends Context.Service<
|
|
119
|
+
Subscriptions,
|
|
120
|
+
{
|
|
121
|
+
readonly recoverSubscription: (
|
|
122
|
+
scope: SubscriptionScope,
|
|
123
|
+
key: SubscriptionKey,
|
|
124
|
+
expectedRevision: number,
|
|
125
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>
|
|
126
|
+
readonly getSubscription: (
|
|
127
|
+
scope: SubscriptionScope,
|
|
128
|
+
key: SubscriptionKey,
|
|
129
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionError>
|
|
130
|
+
readonly subscribe: (
|
|
131
|
+
scope: SubscriptionScope,
|
|
132
|
+
options: SubscribeOptions,
|
|
133
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>
|
|
134
|
+
readonly updateSubscription: (
|
|
135
|
+
scope: SubscriptionScope,
|
|
136
|
+
key: SubscriptionKey,
|
|
137
|
+
expectedRevision: number,
|
|
138
|
+
options: Omit<SubscribeOptions, 'subscriptionId'>,
|
|
139
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionFailure>
|
|
140
|
+
readonly pauseSubscription: (
|
|
141
|
+
scope: SubscriptionScope,
|
|
142
|
+
key: SubscriptionKey,
|
|
143
|
+
expectedRevision: number,
|
|
144
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>
|
|
145
|
+
readonly resumeSubscription: (
|
|
146
|
+
scope: SubscriptionScope,
|
|
147
|
+
key: SubscriptionKey,
|
|
148
|
+
expectedRevision: number,
|
|
149
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>
|
|
150
|
+
readonly listSubscriptions: (
|
|
151
|
+
scope: SubscriptionScope,
|
|
152
|
+
after?: number,
|
|
153
|
+
limit?: number,
|
|
154
|
+
) => Effect.Effect<
|
|
155
|
+
{ readonly items: ReadonlyArray<SubscriptionSnapshot>; readonly next: number | null },
|
|
156
|
+
SubscriptionError
|
|
157
|
+
>
|
|
158
|
+
readonly recoverDelivery: (
|
|
159
|
+
scope: SubscriptionScope,
|
|
160
|
+
key: SubscriptionDeliveryKey,
|
|
161
|
+
expectedGeneration: number,
|
|
162
|
+
) => Effect.Effect<typeof SubscriptionDeliverySnapshot.Type, SubscriptionStoreFailure>
|
|
163
|
+
readonly cancelSubscription: (
|
|
164
|
+
scope: SubscriptionScope,
|
|
165
|
+
key: SubscriptionKey,
|
|
166
|
+
expectedRevision?: number,
|
|
167
|
+
) => Effect.Effect<SubscriptionSnapshot, SubscriptionStoreFailure>
|
|
168
|
+
readonly listDeliveries: (
|
|
169
|
+
scope: SubscriptionScope,
|
|
170
|
+
key: SubscriptionKey,
|
|
171
|
+
after?: string,
|
|
172
|
+
limit?: number,
|
|
173
|
+
) => Effect.Effect<
|
|
174
|
+
{
|
|
175
|
+
readonly items: ReadonlyArray<typeof SubscriptionDeliverySnapshot.Type>
|
|
176
|
+
readonly next: string | null
|
|
177
|
+
},
|
|
178
|
+
SubscriptionError
|
|
179
|
+
>
|
|
180
|
+
}
|
|
181
|
+
>()('@effect-agent/thread/Subscriptions') {
|
|
182
|
+
static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {
|
|
183
|
+
return Layer.effect(Subscriptions, makeManagement(limits))
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Trusted intake acknowledges retained routing work, never a Thread Submission Receipt. */
|
|
188
|
+
export class SubscriptionIntake extends Context.Service<
|
|
189
|
+
SubscriptionIntake,
|
|
190
|
+
{
|
|
191
|
+
readonly accept: (
|
|
192
|
+
principal: Principal,
|
|
193
|
+
source: EventSourceVersion,
|
|
194
|
+
payload: unknown,
|
|
195
|
+
) => Effect.Effect<EventAcknowledgement, SubscriptionFailure>
|
|
196
|
+
readonly status: (
|
|
197
|
+
principal: Principal,
|
|
198
|
+
source: EventSourceVersion,
|
|
199
|
+
eventId: string,
|
|
200
|
+
) => Effect.Effect<
|
|
201
|
+
EventAcknowledgement & {
|
|
202
|
+
readonly routingComplete: boolean
|
|
203
|
+
readonly routingFailure: string | null
|
|
204
|
+
readonly nextAttemptAtMillis: number
|
|
205
|
+
},
|
|
206
|
+
SubscriptionError
|
|
207
|
+
>
|
|
208
|
+
}
|
|
209
|
+
>()('@effect-agent/thread/SubscriptionIntake') {
|
|
210
|
+
static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {
|
|
211
|
+
return Layer.effect(SubscriptionIntake, makeIntake(limits))
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** One bounded sweep. The platform owns polling/alarm recovery; no subscription retains a Run. */
|
|
216
|
+
export class SubscriptionDriver extends Context.Service<
|
|
217
|
+
SubscriptionDriver,
|
|
218
|
+
{
|
|
219
|
+
readonly runDue: Effect.Effect<
|
|
220
|
+
{ readonly processed: number; readonly failed: number },
|
|
221
|
+
SubscriptionStoreFailure
|
|
222
|
+
>
|
|
223
|
+
readonly processDelivery: (
|
|
224
|
+
key: SubscriptionDeliveryKey,
|
|
225
|
+
) => Effect.Effect<void, SubscriptionFailure>
|
|
226
|
+
}
|
|
227
|
+
>()('@effect-agent/thread/SubscriptionDriver') {
|
|
228
|
+
static layer(limits: SubscriptionLimits = defaultSubscriptionLimits) {
|
|
229
|
+
return Layer.effect(SubscriptionDriver, makeDriver(limits))
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const dependencies = Effect.gen(function*() {
|
|
234
|
+
const store = yield* SubscriptionStore
|
|
235
|
+
const authorizer = yield* SubscriptionAuthorizer
|
|
236
|
+
const sources = (yield* EventSources).sources
|
|
237
|
+
const crypto = yield* CryptoDigest.Digest
|
|
238
|
+
|
|
239
|
+
const digest = (value: PersistedJson) =>
|
|
240
|
+
digestJson(value).pipe(
|
|
241
|
+
Effect.provideService(CryptoDigest.Digest, crypto),
|
|
242
|
+
Effect.mapError(() => failure('storage', 'digest')),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
const source = (version: EventSourceVersion) => {
|
|
246
|
+
const found = sources.filter((s) => sameSource(s.source, version))
|
|
247
|
+
const item = found[0]
|
|
248
|
+
|
|
249
|
+
return found.length === 1 && item !== undefined
|
|
250
|
+
? Effect.succeed(item)
|
|
251
|
+
: Effect.fail(failure('unsupported-source', 'source-version'))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const scope = Effect.fnUntraced(function*(value: SubscriptionScope) {
|
|
255
|
+
const decoded = yield* validate(SubscriptionScope, value)
|
|
256
|
+
|
|
257
|
+
if (!samePartition(decoded.partition, store.partition)) {
|
|
258
|
+
return yield* failure('unauthorized', 'partition')
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return decoded
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
const acceptNormalized = Effect.fnUntraced(function*(
|
|
265
|
+
version: EventSourceVersion,
|
|
266
|
+
event: NormalizedEvent,
|
|
267
|
+
limits: SubscriptionLimits,
|
|
268
|
+
) {
|
|
269
|
+
const time = yield* now
|
|
270
|
+
|
|
271
|
+
const record = yield* validate(AcceptedEvent, {
|
|
272
|
+
schemaVersion: 1,
|
|
273
|
+
partition: store.partition,
|
|
274
|
+
eventId: event.eventId,
|
|
275
|
+
source: version,
|
|
276
|
+
matchingKey: event.matchingKey,
|
|
277
|
+
payload: event.payload,
|
|
278
|
+
payloadDigest: yield* digest(event.payload),
|
|
279
|
+
acceptedAtMillis: time,
|
|
280
|
+
...(event.occurredAtMillis === undefined ? {} : { occurredAtMillis: event.occurredAtMillis }),
|
|
281
|
+
cutoff: 0,
|
|
282
|
+
cursor: 0,
|
|
283
|
+
routingComplete: false,
|
|
284
|
+
routingFailure: null,
|
|
285
|
+
nextAttemptAtMillis: time,
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
const retained = yield* store.accept(record, limits)
|
|
289
|
+
|
|
290
|
+
if (retained.tombstone !== true && (yield* digest(retained.payload)) !== retained.payloadDigest) {
|
|
291
|
+
return yield* failure('corrupt', 'event-digest')
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return retained
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
return { store, authorizer, source, digest, scope, acceptNormalized }
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
const pageLimit = (value: number) =>
|
|
301
|
+
validate(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)), value)
|
|
302
|
+
|
|
303
|
+
const makeManagement = Effect.fnUntraced(function*(requested: SubscriptionLimits) {
|
|
304
|
+
const limits = yield* validate(SubscriptionLimits, requested)
|
|
305
|
+
const { bindings } = yield* SubscriptionInputBindings
|
|
306
|
+
const { store, authorizer, source, digest, scope } = yield* dependencies
|
|
307
|
+
|
|
308
|
+
const subscribe: Subscriptions['Service']['subscribe'] = Effect.fnUntraced(
|
|
309
|
+
function*(scopeValue, options) {
|
|
310
|
+
const owner = yield* scope(scopeValue)
|
|
311
|
+
|
|
312
|
+
yield* authorizer.manage('subscribe', owner)
|
|
313
|
+
const behavior = yield* source(options.source)
|
|
314
|
+
const params = yield* behavior.parameters(options.parameters)
|
|
315
|
+
const binding = yield* resolveSubscriptionInput(bindings, options)
|
|
316
|
+
const context = yield* binding.context(options.context)
|
|
317
|
+
|
|
318
|
+
const configuration = yield* validate(SubscriptionConfiguration, {
|
|
319
|
+
...options,
|
|
320
|
+
parameters: params.parameters,
|
|
321
|
+
context,
|
|
322
|
+
matchingKey: params.matchingKey,
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
yield* authorizer.manage('subscribe', owner, configuration)
|
|
326
|
+
|
|
327
|
+
const key = yield* validate(SubscriptionKey, {
|
|
328
|
+
partition: owner.partition,
|
|
329
|
+
ownerId: owner.ownerId,
|
|
330
|
+
subscriptionId: options.subscriptionId,
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
const encodedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(
|
|
334
|
+
configuration,
|
|
335
|
+
).pipe(Effect.mapError(() => failure('validation', 'configuration')))
|
|
336
|
+
|
|
337
|
+
const creationFingerprint = yield* digest({
|
|
338
|
+
key,
|
|
339
|
+
createdBy: owner.principal,
|
|
340
|
+
configuration: encodedConfiguration,
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const existing = yield* store.get(key)
|
|
344
|
+
|
|
345
|
+
if (existing !== null) {
|
|
346
|
+
const retainedConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(
|
|
347
|
+
existing.creationConfiguration,
|
|
348
|
+
).pipe(Effect.mapError(() => failure('corrupt', 'creation-configuration')))
|
|
349
|
+
|
|
350
|
+
const retainedFingerprint = yield* digest({
|
|
351
|
+
key: existing.key,
|
|
352
|
+
createdBy: existing.createdBy,
|
|
353
|
+
configuration: retainedConfiguration,
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
if (retainedFingerprint !== existing.creationFingerprint) {
|
|
357
|
+
return yield* failure('corrupt', 'creation-fingerprint')
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const currentConfiguration = yield* Schema.encodeEffect(SubscriptionConfiguration)(
|
|
361
|
+
existing.configuration,
|
|
362
|
+
).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))
|
|
363
|
+
|
|
364
|
+
if (
|
|
365
|
+
(yield* digest({
|
|
366
|
+
key: existing.key,
|
|
367
|
+
createdBy: existing.createdBy,
|
|
368
|
+
configuration: currentConfiguration,
|
|
369
|
+
})) !== existing.configurationFingerprint
|
|
370
|
+
) {
|
|
371
|
+
return yield* failure('corrupt', 'creation-fingerprint')
|
|
372
|
+
}
|
|
373
|
+
if (existing.creationFingerprint !== creationFingerprint) {
|
|
374
|
+
return yield* failure('conflict', 'creation')
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return snapshot(existing, yield* now)
|
|
378
|
+
}
|
|
379
|
+
if (
|
|
380
|
+
bytes(params.parameters) > limits.maxPayloadBytes ||
|
|
381
|
+
bytes(context) > limits.maxContextBytes
|
|
382
|
+
) {
|
|
383
|
+
return yield* failure('validation', 'registration-bounds')
|
|
384
|
+
}
|
|
385
|
+
const time = yield* now
|
|
386
|
+
|
|
387
|
+
if (
|
|
388
|
+
configuration.expiresAtMillis !== null &&
|
|
389
|
+
(configuration.expiresAtMillis <= time ||
|
|
390
|
+
configuration.expiresAtMillis - time > limits.maxLifetimeMillis)
|
|
391
|
+
) {
|
|
392
|
+
return yield* failure('validation', 'lifetime')
|
|
393
|
+
}
|
|
394
|
+
if (behavior.reconcile !== undefined && configuration.mode !== 'once') {
|
|
395
|
+
return yield* failure('validation', 'reconciliation-requires-once')
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const record = yield* store.register(
|
|
399
|
+
{
|
|
400
|
+
schemaVersion: 1,
|
|
401
|
+
key,
|
|
402
|
+
creationFingerprint,
|
|
403
|
+
configurationRevision: 1,
|
|
404
|
+
configurationFingerprint: creationFingerprint,
|
|
405
|
+
creationConfiguration: configuration,
|
|
406
|
+
createdBy: owner.principal,
|
|
407
|
+
createdAtMillis: time,
|
|
408
|
+
ordinal: 0,
|
|
409
|
+
configuration,
|
|
410
|
+
state: 'active',
|
|
411
|
+
recovery: behavior.reconcile === undefined
|
|
412
|
+
? null
|
|
413
|
+
: { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },
|
|
414
|
+
},
|
|
415
|
+
limits,
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
return snapshot(record, time)
|
|
419
|
+
},
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
const listSubscriptions: Subscriptions['Service']['listSubscriptions'] = Effect.fnUntraced(
|
|
423
|
+
function*(scopeValue, after = 0, requestedLimit = 50) {
|
|
424
|
+
const owner = yield* scope(scopeValue)
|
|
425
|
+
|
|
426
|
+
yield* authorizer.manage('list', owner)
|
|
427
|
+
const limit = yield* pageLimit(requestedLimit)
|
|
428
|
+
|
|
429
|
+
yield* validate(Schema.Natural, after)
|
|
430
|
+
const records = yield* store.list(owner.ownerId, after, limit)
|
|
431
|
+
const time = yield* now
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
items: records.map((record) => snapshot(record, time)),
|
|
435
|
+
next: records.length === limit ? (records.at(-1)?.ordinal ?? null) : null,
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
const ownedKey = Effect.fnUntraced(function*(owner: SubscriptionScope, key: SubscriptionKey) {
|
|
441
|
+
yield* validate(SubscriptionKey, key)
|
|
442
|
+
if (!samePartition(owner.partition, key.partition) || owner.ownerId !== key.ownerId) {
|
|
443
|
+
return yield* failure('unauthorized', 'owner')
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return key
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
const updateSubscription: Subscriptions['Service']['updateSubscription'] = Effect.fnUntraced(
|
|
450
|
+
function*(scopeValue, key, expectedRevision, options) {
|
|
451
|
+
const owner = yield* scope(scopeValue)
|
|
452
|
+
|
|
453
|
+
yield* authorizer.manage('update', owner)
|
|
454
|
+
yield* ownedKey(owner, key)
|
|
455
|
+
const behavior = yield* source(options.source)
|
|
456
|
+
const parameters = yield* behavior.parameters(options.parameters)
|
|
457
|
+
const binding = yield* resolveSubscriptionInput(bindings, options)
|
|
458
|
+
const context = yield* binding.context(options.context)
|
|
459
|
+
|
|
460
|
+
const configuration = yield* validate(SubscriptionConfiguration, {
|
|
461
|
+
...options,
|
|
462
|
+
...parameters,
|
|
463
|
+
context,
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
yield* authorizer.manage('update', owner, configuration)
|
|
467
|
+
const time = yield* now
|
|
468
|
+
|
|
469
|
+
if (
|
|
470
|
+
bytes(parameters.parameters) > limits.maxPayloadBytes ||
|
|
471
|
+
bytes(context) > limits.maxContextBytes
|
|
472
|
+
) {
|
|
473
|
+
return yield* failure('validation', 'registration-bounds')
|
|
474
|
+
}
|
|
475
|
+
if (
|
|
476
|
+
configuration.expiresAtMillis !== null &&
|
|
477
|
+
(configuration.expiresAtMillis <= time ||
|
|
478
|
+
configuration.expiresAtMillis - time > limits.maxLifetimeMillis)
|
|
479
|
+
) {
|
|
480
|
+
return yield* failure('validation', 'lifetime')
|
|
481
|
+
}
|
|
482
|
+
if (behavior.reconcile !== undefined && configuration.mode !== 'once') {
|
|
483
|
+
return yield* failure('validation', 'reconciliation-requires-once')
|
|
484
|
+
}
|
|
485
|
+
const existing = yield* store.get(key)
|
|
486
|
+
|
|
487
|
+
if (existing === null) return yield* failure('not-found', 'subscription')
|
|
488
|
+
|
|
489
|
+
const encoded = yield* Schema.encodeEffect(SubscriptionConfiguration)(configuration).pipe(
|
|
490
|
+
Effect.mapError(() => failure('validation', 'configuration')),
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
const configurationFingerprint = yield* digest({
|
|
494
|
+
key,
|
|
495
|
+
createdBy: existing.createdBy,
|
|
496
|
+
configuration: encoded,
|
|
497
|
+
})
|
|
498
|
+
|
|
499
|
+
const updated = yield* store.change(
|
|
500
|
+
key,
|
|
501
|
+
expectedRevision,
|
|
502
|
+
{
|
|
503
|
+
_tag: 'Update',
|
|
504
|
+
configuration,
|
|
505
|
+
configurationFingerprint,
|
|
506
|
+
recovery: behavior.reconcile === undefined
|
|
507
|
+
? null
|
|
508
|
+
: { attempts: 0, nextAttemptAtMillis: time, lastFailure: null },
|
|
509
|
+
},
|
|
510
|
+
limits,
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
return snapshot(updated, time)
|
|
514
|
+
},
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
const changeState = Effect.fnUntraced(function*(
|
|
518
|
+
scopeValue: SubscriptionScope,
|
|
519
|
+
key: SubscriptionKey,
|
|
520
|
+
expectedRevision: number,
|
|
521
|
+
change: Extract<SubscriptionChange, { readonly _tag: 'Pause' | 'Resume' }>,
|
|
522
|
+
) {
|
|
523
|
+
const owner = yield* scope(scopeValue)
|
|
524
|
+
|
|
525
|
+
yield* authorizer.manage(change._tag === 'Pause' ? 'pause' : 'resume', owner)
|
|
526
|
+
|
|
527
|
+
const updated = yield* store.change(
|
|
528
|
+
yield* ownedKey(owner, key),
|
|
529
|
+
expectedRevision,
|
|
530
|
+
change,
|
|
531
|
+
limits,
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
return snapshot(updated, yield* now)
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
const cancelSubscription: Subscriptions['Service']['cancelSubscription'] = Effect.fnUntraced(
|
|
538
|
+
function*(scopeValue, key, expectedRevision) {
|
|
539
|
+
const owner = yield* scope(scopeValue)
|
|
540
|
+
|
|
541
|
+
yield* authorizer.manage('cancel', owner)
|
|
542
|
+
const record = yield* store.cancel(yield* ownedKey(owner, key), expectedRevision)
|
|
543
|
+
|
|
544
|
+
return snapshot(record, yield* now)
|
|
545
|
+
},
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
const listDeliveries: Subscriptions['Service']['listDeliveries'] = Effect.fnUntraced(function*(
|
|
549
|
+
scopeValue,
|
|
550
|
+
key,
|
|
551
|
+
after = '',
|
|
552
|
+
requestedLimit = 50,
|
|
553
|
+
) {
|
|
554
|
+
const owner = yield* scope(scopeValue)
|
|
555
|
+
|
|
556
|
+
yield* authorizer.manage('deliveries', owner)
|
|
557
|
+
const limit = yield* pageLimit(requestedLimit)
|
|
558
|
+
const records = yield* store.listDeliveries(yield* ownedKey(owner, key), after, limit)
|
|
559
|
+
const last = records.at(-1)
|
|
560
|
+
|
|
561
|
+
return {
|
|
562
|
+
items: records.map(deliverySnapshot),
|
|
563
|
+
next: records.length === limit && last !== undefined
|
|
564
|
+
? subscriptionDeliveryKeyString(last.key)
|
|
565
|
+
: null,
|
|
566
|
+
}
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
const recoverDelivery: Subscriptions['Service']['recoverDelivery'] = Effect.fn(
|
|
570
|
+
'Subscriptions.recoverDelivery',
|
|
571
|
+
)(function*(scopeValue, key, expectedGeneration) {
|
|
572
|
+
const owner = yield* scope(scopeValue)
|
|
573
|
+
|
|
574
|
+
yield* authorizer.manage('recover', owner)
|
|
575
|
+
yield* ownedKey(owner, key.subscription)
|
|
576
|
+
const existing = yield* store.delivery(key)
|
|
577
|
+
|
|
578
|
+
if (existing === null) return yield* failure('not-found', 'delivery')
|
|
579
|
+
|
|
580
|
+
const recovered = yield* store.changeDelivery(key, existing.deliveryId, {
|
|
581
|
+
_tag: 'Recover',
|
|
582
|
+
expectedGeneration,
|
|
583
|
+
nowMillis: yield* now,
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
return deliverySnapshot(recovered)
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
const getSubscription: Subscriptions['Service']['getSubscription'] = Effect.fnUntraced(
|
|
590
|
+
function*(scopeValue, key) {
|
|
591
|
+
const owner = yield* scope(scopeValue)
|
|
592
|
+
|
|
593
|
+
yield* authorizer.manage('get', owner)
|
|
594
|
+
const record = yield* store.get(yield* ownedKey(owner, key))
|
|
595
|
+
|
|
596
|
+
if (record === null) return yield* failure('not-found', 'subscription')
|
|
597
|
+
|
|
598
|
+
return snapshot(record, yield* now)
|
|
599
|
+
},
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
return Subscriptions.of({
|
|
603
|
+
getSubscription,
|
|
604
|
+
recoverSubscription: Effect.fnUntraced(function*(scopeValue, key, expectedRevision) {
|
|
605
|
+
const owner = yield* scope(scopeValue)
|
|
606
|
+
|
|
607
|
+
yield* authorizer.manage('recover', owner)
|
|
608
|
+
|
|
609
|
+
return snapshot(
|
|
610
|
+
yield* store.change(
|
|
611
|
+
yield* ownedKey(owner, key),
|
|
612
|
+
expectedRevision,
|
|
613
|
+
{
|
|
614
|
+
_tag: 'Recover',
|
|
615
|
+
nowMillis: yield* now,
|
|
616
|
+
},
|
|
617
|
+
limits,
|
|
618
|
+
),
|
|
619
|
+
yield* now,
|
|
620
|
+
)
|
|
621
|
+
}),
|
|
622
|
+
recoverDelivery,
|
|
623
|
+
subscribe,
|
|
624
|
+
updateSubscription,
|
|
625
|
+
pauseSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Pause' }),
|
|
626
|
+
resumeSubscription: (scope, key, revision) => changeState(scope, key, revision, { _tag: 'Resume' }),
|
|
627
|
+
listSubscriptions,
|
|
628
|
+
cancelSubscription,
|
|
629
|
+
listDeliveries,
|
|
630
|
+
})
|
|
631
|
+
})
|
|
632
|
+
|
|
633
|
+
const makeIntake = Effect.fnUntraced(function*(requested: SubscriptionLimits) {
|
|
634
|
+
const limits = yield* validate(SubscriptionLimits, requested)
|
|
635
|
+
const { store, authorizer, source, acceptNormalized } = yield* dependencies
|
|
636
|
+
|
|
637
|
+
const accept: SubscriptionIntake['Service']['accept'] = Effect.fnUntraced(
|
|
638
|
+
function*(principal, version, payload) {
|
|
639
|
+
yield* authorizer.intake(store.partition, version, principal)
|
|
640
|
+
const behavior = yield* source(version)
|
|
641
|
+
const event = yield* behavior.normalize(payload)
|
|
642
|
+
const accepted = yield* acceptNormalized(version, event, limits)
|
|
643
|
+
|
|
644
|
+
return {
|
|
645
|
+
partition: accepted.partition,
|
|
646
|
+
eventId: accepted.eventId,
|
|
647
|
+
acceptedAtMillis: accepted.acceptedAtMillis,
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
const status: SubscriptionIntake['Service']['status'] = Effect.fnUntraced(
|
|
653
|
+
function*(principal, version, eventId) {
|
|
654
|
+
yield* authorizer.intake(store.partition, version, principal)
|
|
655
|
+
const event = yield* store.event(eventId)
|
|
656
|
+
|
|
657
|
+
if (event === null) return yield* failure('not-found', 'event')
|
|
658
|
+
if (!sameSource(event.source, version)) return yield* failure('conflict', 'event-source')
|
|
659
|
+
|
|
660
|
+
return {
|
|
661
|
+
partition: event.partition,
|
|
662
|
+
eventId: event.eventId,
|
|
663
|
+
acceptedAtMillis: event.acceptedAtMillis,
|
|
664
|
+
routingComplete: event.routingComplete,
|
|
665
|
+
routingFailure: event.routingFailure,
|
|
666
|
+
nextAttemptAtMillis: event.nextAttemptAtMillis,
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
return SubscriptionIntake.of({ accept, status })
|
|
672
|
+
})
|
|
673
|
+
|
|
674
|
+
const makeDriver = Effect.fnUntraced(function*(requested: SubscriptionLimits) {
|
|
675
|
+
const limits = yield* validate(SubscriptionLimits, requested)
|
|
676
|
+
const { bindings } = yield* SubscriptionInputBindings
|
|
677
|
+
const { store, authorizer, source, digest, acceptNormalized } = yield* dependencies
|
|
678
|
+
const admission = yield* PreparedInputAdmission
|
|
679
|
+
|
|
680
|
+
if (limits.retention !== undefined && admission.submissionStatus === undefined) {
|
|
681
|
+
return yield* failure('validation', 'retention-requires-submission-status')
|
|
682
|
+
}
|
|
683
|
+
const failpoint = yield* SubscriptionFailpoint
|
|
684
|
+
const semaphore = yield* Semaphore.make(limits.concurrency)
|
|
685
|
+
const sweepSemaphore = yield* Semaphore.make(1)
|
|
686
|
+
const definitionEquals = Schema.toEquivalence(DefinitionDigests)
|
|
687
|
+
const nextAttempt = (time: number) => Math.min(time + limits.retryMillis, 8_640_000_000_000_000)
|
|
688
|
+
|
|
689
|
+
const selected = Effect.fnUntraced(function*(
|
|
690
|
+
event: AcceptedEvent,
|
|
691
|
+
subscription: SubscriptionRecord,
|
|
692
|
+
) {
|
|
693
|
+
const deliveryId = yield* digest({
|
|
694
|
+
schemaVersion: 1,
|
|
695
|
+
subscription: subscription.key,
|
|
696
|
+
eventId: event.eventId,
|
|
697
|
+
})
|
|
698
|
+
|
|
699
|
+
const time = yield* now
|
|
700
|
+
|
|
701
|
+
return yield* validate(SubscriptionDelivery, {
|
|
702
|
+
schemaVersion: 1,
|
|
703
|
+
key: { subscription: subscription.key, eventId: event.eventId },
|
|
704
|
+
deliveryId,
|
|
705
|
+
subscriptionFingerprint: subscription.configurationFingerprint,
|
|
706
|
+
configurationRevision: subscription.configurationRevision,
|
|
707
|
+
configuration: subscription.configuration,
|
|
708
|
+
eventDigest: event.payloadDigest,
|
|
709
|
+
source: event.source,
|
|
710
|
+
threadId: subscription.configuration.destination._tag === 'ExistingThread'
|
|
711
|
+
? subscription.configuration.destination.threadId
|
|
712
|
+
: yield* Schema.decodeEffect(ThreadId)(`subscription:${deliveryId}`).pipe(Effect.orDie),
|
|
713
|
+
admissionKey: yield* Schema.decodeEffect(IdempotencyKey)(`subscription:${deliveryId}`).pipe(
|
|
714
|
+
Effect.orDie,
|
|
715
|
+
),
|
|
716
|
+
selectedAtMillis: time,
|
|
717
|
+
...(limits.retention === undefined ? {} : { observeSettlement: true }),
|
|
718
|
+
state: 'selected',
|
|
719
|
+
envelope: null,
|
|
720
|
+
envelopeDigest: null,
|
|
721
|
+
retry: {
|
|
722
|
+
generation: 0,
|
|
723
|
+
attempts: 0,
|
|
724
|
+
automaticAttempts: 0,
|
|
725
|
+
parked: false,
|
|
726
|
+
nextAttemptAtMillis: time,
|
|
727
|
+
lastAttemptAtMillis: null,
|
|
728
|
+
lastFailure: null,
|
|
729
|
+
},
|
|
730
|
+
receipt: null,
|
|
731
|
+
refusal: null,
|
|
732
|
+
})
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
const route = Effect.fnUntraced(function*(event: AcceptedEvent) {
|
|
736
|
+
const behavior = yield* source(event.source)
|
|
737
|
+
const normalized = yield* behavior.normalize(event.payload)
|
|
738
|
+
|
|
739
|
+
if (
|
|
740
|
+
normalized.eventId !== event.eventId ||
|
|
741
|
+
normalized.occurredAtMillis !== event.occurredAtMillis ||
|
|
742
|
+
normalized.matchingKey !== event.matchingKey ||
|
|
743
|
+
(yield* digest(normalized.payload)) !== event.payloadDigest ||
|
|
744
|
+
(yield* digest(event.payload)) !== event.payloadDigest
|
|
745
|
+
) {
|
|
746
|
+
return yield* failure('corrupt', 'event-source-bindings')
|
|
747
|
+
}
|
|
748
|
+
const candidates = yield* store.candidates(event, limits.batchSize)
|
|
749
|
+
const deliveries: Array<SubscriptionDelivery> = []
|
|
750
|
+
const time = yield* now
|
|
751
|
+
|
|
752
|
+
for (const candidate of candidates) {
|
|
753
|
+
if (
|
|
754
|
+
candidate.state !== 'active' ||
|
|
755
|
+
(candidate.configuration.expiresAtMillis !== null &&
|
|
756
|
+
candidate.configuration.expiresAtMillis <= time)
|
|
757
|
+
) {
|
|
758
|
+
continue
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const config = yield* Schema.encodeEffect(SubscriptionConfiguration)(
|
|
762
|
+
candidate.configuration,
|
|
763
|
+
).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))
|
|
764
|
+
|
|
765
|
+
const fingerprint = yield* digest({
|
|
766
|
+
key: candidate.key,
|
|
767
|
+
createdBy: candidate.createdBy,
|
|
768
|
+
configuration: config,
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
const parameters = yield* behavior.parameters(candidate.configuration.parameters)
|
|
772
|
+
|
|
773
|
+
if (
|
|
774
|
+
fingerprint !== candidate.configurationFingerprint ||
|
|
775
|
+
parameters.matchingKey !== candidate.configuration.matchingKey
|
|
776
|
+
) {
|
|
777
|
+
return yield* failure('corrupt', 'registration-source-bindings')
|
|
778
|
+
}
|
|
779
|
+
if (yield* behavior.matches(event, candidate)) {
|
|
780
|
+
deliveries.push(yield* selected(event, candidate))
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const cursor = candidates.at(-1)?.ordinal ?? event.cursor
|
|
784
|
+
|
|
785
|
+
yield* store.select(
|
|
786
|
+
event,
|
|
787
|
+
deliveries,
|
|
788
|
+
cursor,
|
|
789
|
+
candidates.length < limits.batchSize,
|
|
790
|
+
yield* now,
|
|
791
|
+
limits,
|
|
792
|
+
)
|
|
793
|
+
})
|
|
794
|
+
|
|
795
|
+
const retry = (delivery: SubscriptionDelivery, reason: PreparedInputRetryReason) =>
|
|
796
|
+
now.pipe(
|
|
797
|
+
Effect.flatMap((time) =>
|
|
798
|
+
store.changeDelivery(delivery.key, delivery.deliveryId, {
|
|
799
|
+
_tag: 'Retry',
|
|
800
|
+
nowMillis: time,
|
|
801
|
+
retry: {
|
|
802
|
+
generation: delivery.retry.generation,
|
|
803
|
+
attempts: delivery.retry.attempts + 1,
|
|
804
|
+
automaticAttempts: delivery.retry.automaticAttempts + 1,
|
|
805
|
+
parked: delivery.retry.automaticAttempts + 1 >= (limits.maxAutomaticAttempts ?? 8),
|
|
806
|
+
lastAttemptAtMillis: time,
|
|
807
|
+
nextAttemptAtMillis: nextAttempt(time),
|
|
808
|
+
lastFailure: reason,
|
|
809
|
+
},
|
|
810
|
+
})
|
|
811
|
+
),
|
|
812
|
+
Effect.asVoid,
|
|
813
|
+
)
|
|
814
|
+
|
|
815
|
+
const refuse = (
|
|
816
|
+
delivery: SubscriptionDelivery,
|
|
817
|
+
phase: 'preparation' | 'admission',
|
|
818
|
+
code: string,
|
|
819
|
+
) =>
|
|
820
|
+
now.pipe(
|
|
821
|
+
Effect.flatMap((time) =>
|
|
822
|
+
store.changeDelivery(delivery.key, delivery.deliveryId, {
|
|
823
|
+
_tag: 'Refuse',
|
|
824
|
+
refusal: { phase, code },
|
|
825
|
+
nowMillis: time,
|
|
826
|
+
})
|
|
827
|
+
),
|
|
828
|
+
Effect.asVoid,
|
|
829
|
+
)
|
|
830
|
+
|
|
831
|
+
const verifySelected = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {
|
|
832
|
+
const current = yield* store.get(delivery.key.subscription)
|
|
833
|
+
|
|
834
|
+
const subscription = current === null
|
|
835
|
+
? null
|
|
836
|
+
: {
|
|
837
|
+
...current,
|
|
838
|
+
configuration: delivery.configuration,
|
|
839
|
+
configurationRevision: delivery.configurationRevision,
|
|
840
|
+
configurationFingerprint: delivery.subscriptionFingerprint,
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const event = yield* store.event(delivery.key.eventId)
|
|
844
|
+
|
|
845
|
+
if (
|
|
846
|
+
subscription === null ||
|
|
847
|
+
event === null ||
|
|
848
|
+
!sameSource(delivery.source, event.source) ||
|
|
849
|
+
!sameSource(delivery.source, subscription.configuration.source)
|
|
850
|
+
) {
|
|
851
|
+
return yield* failure('corrupt', 'selected-reference')
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const expectedId = yield* digest({
|
|
855
|
+
schemaVersion: 1,
|
|
856
|
+
subscription: subscription.key,
|
|
857
|
+
eventId: event.eventId,
|
|
858
|
+
})
|
|
859
|
+
|
|
860
|
+
const configuration = yield* Schema.encodeEffect(SubscriptionConfiguration)(
|
|
861
|
+
subscription.configuration,
|
|
862
|
+
).pipe(Effect.mapError(() => failure('corrupt', 'configuration')))
|
|
863
|
+
|
|
864
|
+
const fingerprint = yield* digest({
|
|
865
|
+
key: subscription.key,
|
|
866
|
+
createdBy: subscription.createdBy,
|
|
867
|
+
configuration,
|
|
868
|
+
})
|
|
869
|
+
|
|
870
|
+
const destination = subscription.configuration.destination
|
|
871
|
+
|
|
872
|
+
if (
|
|
873
|
+
delivery.subscriptionFingerprint !== fingerprint ||
|
|
874
|
+
delivery.eventDigest !== event.payloadDigest ||
|
|
875
|
+
(yield* digest(event.payload)) !== event.payloadDigest ||
|
|
876
|
+
delivery.deliveryId !== expectedId ||
|
|
877
|
+
delivery.admissionKey !== `subscription:${expectedId}` ||
|
|
878
|
+
delivery.threadId !==
|
|
879
|
+
(destination._tag === 'ExistingThread'
|
|
880
|
+
? destination.threadId
|
|
881
|
+
: `subscription:${expectedId}`)
|
|
882
|
+
) {
|
|
883
|
+
return yield* failure('corrupt', 'selected-bindings')
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
return { subscription, event }
|
|
887
|
+
})
|
|
888
|
+
|
|
889
|
+
const envelopeDigest = Effect.fnUntraced(function*(
|
|
890
|
+
delivery: SubscriptionDelivery,
|
|
891
|
+
envelope: PreparedInput,
|
|
892
|
+
) {
|
|
893
|
+
const encoded = yield* Schema.encodeEffect(PreparedInput)(envelope).pipe(
|
|
894
|
+
Effect.mapError(() => failure('corrupt', 'prepared-envelope')),
|
|
895
|
+
)
|
|
896
|
+
|
|
897
|
+
return yield* digest({
|
|
898
|
+
deliveryId: delivery.deliveryId,
|
|
899
|
+
subscriptionFingerprint: delivery.subscriptionFingerprint,
|
|
900
|
+
eventDigest: delivery.eventDigest,
|
|
901
|
+
envelope: encoded,
|
|
902
|
+
})
|
|
903
|
+
})
|
|
904
|
+
|
|
905
|
+
const prepare = Effect.fnUntraced(function*(delivery: SubscriptionDelivery) {
|
|
906
|
+
const { subscription, event } = yield* verifySelected(delivery)
|
|
907
|
+
const time = yield* now
|
|
908
|
+
|
|
909
|
+
if (
|
|
910
|
+
subscription.state === 'cancelled' ||
|
|
911
|
+
(subscription.configuration.expiresAtMillis !== null &&
|
|
912
|
+
subscription.configuration.expiresAtMillis <= time)
|
|
913
|
+
) {
|
|
914
|
+
yield* refuse(
|
|
915
|
+
delivery,
|
|
916
|
+
'preparation',
|
|
917
|
+
subscription.state === 'cancelled' ? 'cancelled' : 'expired',
|
|
918
|
+
)
|
|
919
|
+
|
|
920
|
+
return null
|
|
921
|
+
}
|
|
922
|
+
const binding = yield* resolveSubscriptionInput(bindings, subscription.configuration)
|
|
923
|
+
|
|
924
|
+
if ((yield* digest(event.payload)) !== event.payloadDigest) {
|
|
925
|
+
return yield* failure('corrupt', 'event-digest')
|
|
926
|
+
}
|
|
927
|
+
const authorization = yield* authorizer.prepare(subscription, event)
|
|
928
|
+
const input = yield* binding.prepare(event, subscription)
|
|
929
|
+
|
|
930
|
+
if (bytes(input) > limits.maxPayloadBytes) {
|
|
931
|
+
return yield* SubscriptionSourceError.make({ code: 'input-bounds', retryable: false })
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const envelope = yield* validate(PreparedInput, {
|
|
935
|
+
schemaVersion: 1,
|
|
936
|
+
threadId: delivery.threadId,
|
|
937
|
+
admissionKey: delivery.admissionKey,
|
|
938
|
+
deliveryPrincipal: subscription.configuration.deliveryPrincipal,
|
|
939
|
+
...(subscription.configuration.admissionGroup === undefined
|
|
940
|
+
? {}
|
|
941
|
+
: { admissionGroup: subscription.configuration.admissionGroup }),
|
|
942
|
+
...(subscription.configuration.admissionFence === undefined
|
|
943
|
+
? {}
|
|
944
|
+
: { admissionFence: subscription.configuration.admissionFence }),
|
|
945
|
+
agentId: subscription.configuration.agentId,
|
|
946
|
+
definitions: subscription.configuration.definitions,
|
|
947
|
+
input,
|
|
948
|
+
inputDigest: yield* digest(input),
|
|
949
|
+
authorization,
|
|
950
|
+
})
|
|
951
|
+
|
|
952
|
+
return yield* store.changeDelivery(delivery.key, delivery.deliveryId, {
|
|
953
|
+
_tag: 'Prepare',
|
|
954
|
+
envelope,
|
|
955
|
+
envelopeDigest: yield* envelopeDigest(delivery, envelope),
|
|
956
|
+
nowMillis: yield* now,
|
|
957
|
+
})
|
|
958
|
+
})
|
|
959
|
+
|
|
960
|
+
const process = Effect.fnUntraced(function*(key: SubscriptionDeliveryKey) {
|
|
961
|
+
let delivery = yield* store.delivery(key)
|
|
962
|
+
|
|
963
|
+
if (delivery === null) return yield* failure('not-found', 'delivery')
|
|
964
|
+
if (
|
|
965
|
+
delivery.state === 'delivered' &&
|
|
966
|
+
delivery.observeSettlement === true &&
|
|
967
|
+
delivery.receipt !== null
|
|
968
|
+
) {
|
|
969
|
+
const settled = admission.submissionStatus === undefined
|
|
970
|
+
? false
|
|
971
|
+
: yield* admission.submissionStatus(delivery.receipt).pipe(
|
|
972
|
+
Effect.timeout(limits.operationTimeoutMillis),
|
|
973
|
+
Effect.map((status) => status._tag === 'settled'),
|
|
974
|
+
Effect.catch((error) =>
|
|
975
|
+
Effect.logWarning('Subscription settlement observation unavailable', {
|
|
976
|
+
tag: error._tag,
|
|
977
|
+
}).pipe(Effect.as(false))
|
|
978
|
+
),
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
const time = yield* now
|
|
982
|
+
|
|
983
|
+
yield* store.changeDelivery(
|
|
984
|
+
delivery.key,
|
|
985
|
+
delivery.deliveryId,
|
|
986
|
+
{
|
|
987
|
+
_tag: 'ObserveSettlement',
|
|
988
|
+
receipt: delivery.receipt,
|
|
989
|
+
settled,
|
|
990
|
+
nowMillis: time,
|
|
991
|
+
nextAttemptAtMillis: nextAttempt(time),
|
|
992
|
+
},
|
|
993
|
+
limits,
|
|
994
|
+
)
|
|
995
|
+
|
|
996
|
+
return
|
|
997
|
+
}
|
|
998
|
+
if (
|
|
999
|
+
delivery.retry.parked === true ||
|
|
1000
|
+
delivery.retry.nextAttemptAtMillis > (yield* now) ||
|
|
1001
|
+
delivery.state === 'delivered' ||
|
|
1002
|
+
delivery.state === 'refused'
|
|
1003
|
+
) {
|
|
1004
|
+
return
|
|
1005
|
+
}
|
|
1006
|
+
if (delivery.state === 'selected') {
|
|
1007
|
+
const original = delivery
|
|
1008
|
+
|
|
1009
|
+
delivery = yield* prepare(original).pipe(
|
|
1010
|
+
Effect.timeout(limits.operationTimeoutMillis),
|
|
1011
|
+
Effect.catchTags({
|
|
1012
|
+
SubscriptionSourceError: (error) =>
|
|
1013
|
+
(error.retryable
|
|
1014
|
+
? retry(original, 'transport')
|
|
1015
|
+
: refuse(original, 'preparation', error.code)).pipe(Effect.as(null)),
|
|
1016
|
+
SubscriptionError: (error) =>
|
|
1017
|
+
error.reason === 'unauthorized'
|
|
1018
|
+
? refuse(original, 'preparation', error.code).pipe(Effect.as(null))
|
|
1019
|
+
: Effect.fail(error),
|
|
1020
|
+
TimeoutError: () => retry(original, 'timeout').pipe(Effect.as(null)),
|
|
1021
|
+
}),
|
|
1022
|
+
)
|
|
1023
|
+
}
|
|
1024
|
+
if (delivery === null || delivery.state === 'refused' || delivery.state === 'delivered') return
|
|
1025
|
+
if (
|
|
1026
|
+
delivery.state !== 'prepared' ||
|
|
1027
|
+
delivery.envelope === null ||
|
|
1028
|
+
delivery.envelopeDigest === null
|
|
1029
|
+
) {
|
|
1030
|
+
return yield* failure('corrupt', 'prepared-state')
|
|
1031
|
+
}
|
|
1032
|
+
const { subscription } = yield* verifySelected(delivery)
|
|
1033
|
+
const envelope = delivery.envelope
|
|
1034
|
+
|
|
1035
|
+
if (
|
|
1036
|
+
(yield* digest(envelope.input)) !== envelope.inputDigest ||
|
|
1037
|
+
envelope.threadId !== delivery.threadId ||
|
|
1038
|
+
envelope.admissionKey !== delivery.admissionKey ||
|
|
1039
|
+
envelope.deliveryPrincipal !== subscription.configuration.deliveryPrincipal ||
|
|
1040
|
+
envelope.agentId !== subscription.configuration.agentId ||
|
|
1041
|
+
!definitionEquals(envelope.definitions, subscription.configuration.definitions) ||
|
|
1042
|
+
delivery.envelopeDigest !== (yield* envelopeDigest(delivery, envelope))
|
|
1043
|
+
) {
|
|
1044
|
+
return yield* failure('corrupt', 'prepared-envelope')
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
const outcome = yield* admitPreparedInput(
|
|
1048
|
+
admission.submit(envelope),
|
|
1049
|
+
limits.operationTimeoutMillis,
|
|
1050
|
+
).pipe(Effect.mapError(() => failure('corrupt', 'admission')))
|
|
1051
|
+
|
|
1052
|
+
if (outcome._tag === 'Receipt') {
|
|
1053
|
+
yield* failpoint.hit('subscription:admission:after')
|
|
1054
|
+
if (outcome.receipt.threadId !== envelope.threadId) {
|
|
1055
|
+
return yield* failure('corrupt', 'receipt-destination')
|
|
1056
|
+
}
|
|
1057
|
+
yield* store.changeDelivery(delivery.key, delivery.deliveryId, {
|
|
1058
|
+
_tag: 'Complete',
|
|
1059
|
+
receipt: outcome.receipt,
|
|
1060
|
+
nowMillis: yield* now,
|
|
1061
|
+
})
|
|
1062
|
+
} else if (outcome._tag === 'Refused') yield* refuse(delivery, 'admission', outcome.error.code)
|
|
1063
|
+
else yield* retry(delivery, outcome.reason)
|
|
1064
|
+
})
|
|
1065
|
+
|
|
1066
|
+
const processDelivery: SubscriptionDriver['Service']['processDelivery'] = (key) => semaphore.withPermit(process(key))
|
|
1067
|
+
|
|
1068
|
+
const reconcile = Effect.fnUntraced(function*(subscription: SubscriptionRecord) {
|
|
1069
|
+
const time = yield* now
|
|
1070
|
+
|
|
1071
|
+
if (
|
|
1072
|
+
subscription.state !== 'active' ||
|
|
1073
|
+
(subscription.configuration.expiresAtMillis !== null &&
|
|
1074
|
+
subscription.configuration.expiresAtMillis <= time)
|
|
1075
|
+
) {
|
|
1076
|
+
return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, null)
|
|
1077
|
+
}
|
|
1078
|
+
const behavior = yield* source(subscription.configuration.source)
|
|
1079
|
+
|
|
1080
|
+
if (behavior.reconcile === undefined) {
|
|
1081
|
+
return yield* failure('unsupported-source', 'source-reconciliation')
|
|
1082
|
+
}
|
|
1083
|
+
yield* authorizer.reconcile(subscription)
|
|
1084
|
+
|
|
1085
|
+
const observation = yield* behavior.reconcile(subscription).pipe(
|
|
1086
|
+
Effect.timeout(limits.operationTimeoutMillis),
|
|
1087
|
+
Effect.map((event) => ({ _tag: 'Observed' as const, event })),
|
|
1088
|
+
Effect.catchTag('SubscriptionSourceError', (error) => Effect.succeed({ _tag: 'Failed' as const, error })),
|
|
1089
|
+
)
|
|
1090
|
+
|
|
1091
|
+
if (observation._tag === 'Failed') {
|
|
1092
|
+
return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {
|
|
1093
|
+
attempts: (subscription.recovery?.attempts ?? 0) + 1,
|
|
1094
|
+
nextAttemptAtMillis: observation.error.retryable ? nextAttempt(time) : null,
|
|
1095
|
+
lastFailure: observation.error.code,
|
|
1096
|
+
})
|
|
1097
|
+
}
|
|
1098
|
+
const observed = observation.event
|
|
1099
|
+
|
|
1100
|
+
if (observed !== null) {
|
|
1101
|
+
const event = yield* acceptNormalized(behavior.source, observed, limits)
|
|
1102
|
+
|
|
1103
|
+
if (event.tombstone === true) {
|
|
1104
|
+
return yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {
|
|
1105
|
+
attempts: (subscription.recovery?.attempts ?? 0) + 1,
|
|
1106
|
+
nextAttemptAtMillis: null,
|
|
1107
|
+
lastFailure: 'event-reclaimed',
|
|
1108
|
+
})
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
if (
|
|
1112
|
+
event.matchingKey !== subscription.configuration.matchingKey ||
|
|
1113
|
+
!(yield* behavior.matches(event, subscription))
|
|
1114
|
+
) {
|
|
1115
|
+
return yield* failure('conflict', 'reconciliation-match')
|
|
1116
|
+
}
|
|
1117
|
+
yield* store.catchUp(event, yield* selected(event, subscription), yield* now, limits)
|
|
1118
|
+
|
|
1119
|
+
return
|
|
1120
|
+
}
|
|
1121
|
+
yield* store.deferRecovery(subscription.key, subscription.configurationRevision, {
|
|
1122
|
+
attempts: (subscription.recovery?.attempts ?? 0) + 1,
|
|
1123
|
+
nextAttemptAtMillis: nextAttempt(time),
|
|
1124
|
+
lastFailure: null,
|
|
1125
|
+
})
|
|
1126
|
+
})
|
|
1127
|
+
|
|
1128
|
+
const runDue = Effect.gen(function*() {
|
|
1129
|
+
const time = yield* now
|
|
1130
|
+
let processed = 0
|
|
1131
|
+
let failed = 0
|
|
1132
|
+
|
|
1133
|
+
const failureCode = <E>(cause: Cause.Cause<E>) =>
|
|
1134
|
+
Option.match(Cause.findErrorOption(cause), {
|
|
1135
|
+
onNone: () => 'defect',
|
|
1136
|
+
onSome: (error) =>
|
|
1137
|
+
Schema.is(SubscriptionError)(error)
|
|
1138
|
+
? error.reason
|
|
1139
|
+
: Schema.is(SubscriptionSourceError)(error)
|
|
1140
|
+
? error.code
|
|
1141
|
+
: Schema.is(Schema.TaggedStruct('TimeoutError', {}))(error)
|
|
1142
|
+
? 'timeout'
|
|
1143
|
+
: 'interrupted-work',
|
|
1144
|
+
})
|
|
1145
|
+
|
|
1146
|
+
const attempt = <E>(
|
|
1147
|
+
work: Effect.Effect<void, E>,
|
|
1148
|
+
recover: (code: string) => Effect.Effect<void, SubscriptionStoreFailure>,
|
|
1149
|
+
) =>
|
|
1150
|
+
work.pipe(
|
|
1151
|
+
Effect.matchCauseEffect({
|
|
1152
|
+
onSuccess: () =>
|
|
1153
|
+
Effect.sync(() => {
|
|
1154
|
+
processed += 1
|
|
1155
|
+
}),
|
|
1156
|
+
onFailure: (cause) =>
|
|
1157
|
+
Cause.hasInterruptsOnly(cause)
|
|
1158
|
+
? Effect.interrupt
|
|
1159
|
+
: Effect.gen(function*() {
|
|
1160
|
+
failed += 1
|
|
1161
|
+
const code = failureCode(cause)
|
|
1162
|
+
|
|
1163
|
+
yield* recover(code).pipe(
|
|
1164
|
+
Effect.catchCause((c) => Cause.hasInterruptsOnly(c) ? Effect.interrupt : Effect.void),
|
|
1165
|
+
)
|
|
1166
|
+
yield* Effect.logWarning('Subscription work remains pending').pipe(
|
|
1167
|
+
Effect.annotateLogs({ failureCode: code }),
|
|
1168
|
+
)
|
|
1169
|
+
}),
|
|
1170
|
+
}),
|
|
1171
|
+
)
|
|
1172
|
+
|
|
1173
|
+
// Persist progress even when one record cannot be decoded or deferred. An eviction cannot
|
|
1174
|
+
// send every sweep back to a corrupt first page. Each category receives one bounded page.
|
|
1175
|
+
const cursors = yield* store.readScanCursors
|
|
1176
|
+
const records = yield* store.recovering(time, cursors.recovery, limits.batchSize)
|
|
1177
|
+
const events = yield* store.pendingEvents(time, cursors.events, limits.batchSize)
|
|
1178
|
+
const deliveries = yield* store.pendingDeliveries(time, cursors.deliveries, limits.batchSize)
|
|
1179
|
+
const lastDelivery = deliveries.at(-1)
|
|
1180
|
+
|
|
1181
|
+
yield* store.advanceScanCursors({
|
|
1182
|
+
recovery: records.length < limits.batchSize ? 0 : (records.at(-1)?.ordinal ?? 0),
|
|
1183
|
+
events: events.length < limits.batchSize ? '' : (events.at(-1) ?? ''),
|
|
1184
|
+
deliveries: deliveries.length < limits.batchSize || lastDelivery === undefined
|
|
1185
|
+
? ''
|
|
1186
|
+
: subscriptionDeliveryKeyString(lastDelivery),
|
|
1187
|
+
})
|
|
1188
|
+
yield* Effect.forEach(
|
|
1189
|
+
records,
|
|
1190
|
+
(cursor) =>
|
|
1191
|
+
Effect.gen(function*() {
|
|
1192
|
+
let record: SubscriptionRecord | null = null
|
|
1193
|
+
|
|
1194
|
+
yield* attempt(
|
|
1195
|
+
Effect.gen(function*() {
|
|
1196
|
+
record = yield* store.get(cursor.key)
|
|
1197
|
+
|
|
1198
|
+
if (record !== null) yield* reconcile(record)
|
|
1199
|
+
}).pipe(Effect.timeout(limits.operationTimeoutMillis)),
|
|
1200
|
+
(code) =>
|
|
1201
|
+
// A failed read supplies no revision that can safely authorize a mutation.
|
|
1202
|
+
record === null
|
|
1203
|
+
? Effect.void
|
|
1204
|
+
: store.deferRecovery(record.key, record.configurationRevision, {
|
|
1205
|
+
attempts: (record.recovery?.attempts ?? 0) + 1,
|
|
1206
|
+
nextAttemptAtMillis: code === 'unauthorized' ? null : nextAttempt(time),
|
|
1207
|
+
lastFailure: code,
|
|
1208
|
+
}),
|
|
1209
|
+
)
|
|
1210
|
+
}),
|
|
1211
|
+
{ concurrency: limits.concurrency },
|
|
1212
|
+
)
|
|
1213
|
+
yield* Effect.forEach(
|
|
1214
|
+
events,
|
|
1215
|
+
(eventId) =>
|
|
1216
|
+
attempt(
|
|
1217
|
+
store.event(eventId).pipe(
|
|
1218
|
+
Effect.flatMap((event) => event === null ? failure('not-found', 'event') : route(event)),
|
|
1219
|
+
Effect.timeout(limits.operationTimeoutMillis),
|
|
1220
|
+
),
|
|
1221
|
+
(code) => store.deferEvent(eventId, nextAttempt(time), code),
|
|
1222
|
+
),
|
|
1223
|
+
{ concurrency: limits.concurrency },
|
|
1224
|
+
)
|
|
1225
|
+
yield* Effect.forEach(
|
|
1226
|
+
deliveries,
|
|
1227
|
+
(key) =>
|
|
1228
|
+
attempt(processDelivery(key), () =>
|
|
1229
|
+
store
|
|
1230
|
+
.delivery(key)
|
|
1231
|
+
.pipe(
|
|
1232
|
+
Effect.flatMap((delivery) => delivery === null ? Effect.void : retry(delivery, 'ambiguous')),
|
|
1233
|
+
)),
|
|
1234
|
+
{ concurrency: limits.concurrency },
|
|
1235
|
+
)
|
|
1236
|
+
|
|
1237
|
+
if (limits.retention !== undefined) {
|
|
1238
|
+
yield* store.compact(yield* now, limits.retention, limits.batchSize)
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
return { processed, failed }
|
|
1242
|
+
})
|
|
1243
|
+
|
|
1244
|
+
return SubscriptionDriver.of({ runDue: sweepSemaphore.withPermit(runDue), processDelivery })
|
|
1245
|
+
})
|