effect-agent 0.1.0-beta.12 → 0.1.0-beta.121
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/dist/Agent-1DMSO_Fl.mjs +86 -0
- package/dist/Agent-1DMSO_Fl.mjs.map +1 -0
- package/dist/Agent-D9cXqfF3.d.mts +252 -0
- package/dist/AgentError-Bn1ytXRD.d.mts +117 -0
- package/dist/AgentPolicy-BqDoSXO6.d.mts +96 -0
- package/dist/AgentRuntime-BUxDdLpw.d.mts +346 -0
- package/dist/AgentRuntime-Cp1hAb-W.mjs +4739 -0
- package/dist/AgentRuntime-Cp1hAb-W.mjs.map +1 -0
- package/dist/AgentUpdates-DMJ-_xow.d.mts +53 -0
- package/dist/ContextCompactor-WwSIG_Z2.d.mts +161 -0
- package/dist/ContextWindow-DRQ5Mbm2.d.mts +58 -0
- package/dist/DurableAgentRuntime-B-9w7jDt.mjs +7061 -0
- package/dist/DurableAgentRuntime-B-9w7jDt.mjs.map +1 -0
- package/dist/DurableFailpoint-Cnr3wx1L.d.mts +41 -0
- package/dist/DurableStep-Cry_iol4.d.mts +103 -0
- package/dist/EventSource-CnlZ3Kma.d.mts +51 -0
- package/dist/FailureDiagnostic-BElLOoED.mjs +274 -0
- package/dist/FailureDiagnostic-BElLOoED.mjs.map +1 -0
- package/dist/FailureDiagnostic-CaAkzGHL.d.mts +223 -0
- package/dist/Identifiers-CN2s30fF.d.mts +40 -0
- package/dist/InMemory.d.mts +24 -0
- package/dist/InMemory.mjs +24 -0
- package/dist/InMemory.mjs.map +1 -0
- package/dist/MemoryNamespace-BbRW5p71.d.mts +36 -0
- package/dist/MemoryReference-B8Q3UJoJ.d.mts +79 -0
- package/dist/Messaging-Dkg87ebg.d.mts +221 -0
- package/dist/Messaging-JYYN3oYS.d.mts +1067 -0
- package/dist/MessagingHost-CqzpxbGz.d.mts +74 -0
- package/dist/MessagingHost-DfsbMPvq.mjs +110 -0
- package/dist/MessagingHost-DfsbMPvq.mjs.map +1 -0
- package/dist/OperationAuthorizer-TzcQtpX5.d.mts +61 -0
- package/dist/Output-V-6YL1_Z.d.mts +25 -0
- package/dist/PageCapture-Df8Xwskw.d.mts +583 -0
- package/dist/PageScreenshot-BpgZKAxl.d.mts +48 -0
- package/dist/PreparedInputAdmission-BQLGldl-.d.mts +42 -0
- package/dist/Receipt-BAHyigAF.d.mts +33 -0
- package/dist/Records-D88mgvyS.d.mts +4214 -0
- package/dist/RunEvent-DIrzkjLr.d.mts +460 -0
- package/dist/RunEventSink-D5aVhISG.d.mts +108 -0
- package/dist/RunJournal-BXrq0VIK.mjs +931 -0
- package/dist/RunJournal-BXrq0VIK.mjs.map +1 -0
- package/dist/RunOptions-CSBsSj0X.d.mts +935 -0
- package/dist/RunPolicyUsage-ClZxyR46.d.mts +21 -0
- package/dist/Sandbox-CEsDWBLq.d.mts +173 -0
- package/dist/Schedule-BIOHA6RR.d.mts +847 -0
- package/dist/Scheduling-DPb2QyAK.mjs +691 -0
- package/dist/Scheduling-DPb2QyAK.mjs.map +1 -0
- package/dist/Subagent-CNik9RiA.d.mts +1635 -0
- package/dist/Subagent-DCrB7an7.mjs +1498 -0
- package/dist/Subagent-DCrB7an7.mjs.map +1 -0
- package/dist/SubagentContract-DdT7Cqe6.d.mts +116 -0
- package/dist/SubagentHost-4WB8Hj0C.d.mts +164 -0
- package/dist/Subscription-CRteOKRf.d.mts +948 -0
- package/dist/SubscriptionInput-oNcwTPti.d.mts +41 -0
- package/dist/Thread-DOBQ0QUY.d.mts +96 -0
- package/dist/ThreadHistory-tS1KwxHR.d.mts +60 -0
- package/dist/ToolBroker-DWs4tZra.d.mts +133 -0
- package/dist/ToolExposure-9uF_Yo0T.mjs +10 -0
- package/dist/ToolExposure-9uF_Yo0T.mjs.map +1 -0
- package/dist/ToolExposure-C93U1sPu.mjs +30 -0
- package/dist/ToolExposure-C93U1sPu.mjs.map +1 -0
- package/dist/ToolExposure-UCN12eCd.d.mts +39 -0
- package/dist/ToolExposure-r2eOWk4F.d.mts +46 -0
- package/dist/ToolExposure.d.mts +8 -0
- package/dist/ToolExposure.mjs +21 -0
- package/dist/ToolExposure.mjs.map +1 -0
- package/dist/ToolReconciler-BmVRAHKs.d.mts +80 -0
- package/dist/ToolResult-BKdqWRff.d.mts +78 -0
- package/dist/Usage-Dx0aknfk.d.mts +121 -0
- package/dist/WakeScheduler-EjUF-GhC.d.mts +56 -0
- package/dist/Worker-CfwzMZEK.mjs +271 -0
- package/dist/Worker-CfwzMZEK.mjs.map +1 -0
- package/dist/Worker-fwWkBg12.d.mts +472 -0
- package/dist/agent-registration-CKNsrpwo.mjs +201 -0
- package/dist/agent-registration-CKNsrpwo.mjs.map +1 -0
- package/dist/capabilities/Approval.d.mts +114 -0
- package/dist/capabilities/Approval.mjs +226 -0
- package/dist/capabilities/Approval.mjs.map +1 -0
- package/dist/capabilities/Budget.d.mts +112 -0
- package/dist/capabilities/Budget.mjs +346 -0
- package/dist/capabilities/Budget.mjs.map +1 -0
- package/dist/capabilities/CodeMode.d.mts +157 -0
- package/dist/capabilities/CodeMode.mjs +522 -0
- package/dist/capabilities/CodeMode.mjs.map +1 -0
- package/dist/capabilities/Commands.d.mts +55 -0
- package/dist/capabilities/Commands.mjs +57 -0
- package/dist/capabilities/Commands.mjs.map +1 -0
- package/dist/capabilities/ContextTools.d.mts +321 -0
- package/dist/capabilities/ContextTools.mjs +126 -0
- package/dist/capabilities/ContextTools.mjs.map +1 -0
- package/dist/capabilities/Mcp.d.mts +108 -0
- package/dist/capabilities/Mcp.mjs +259 -0
- package/dist/capabilities/Mcp.mjs.map +1 -0
- package/dist/capabilities/McpClient.d.mts +115 -0
- package/dist/capabilities/McpClient.mjs +506 -0
- package/dist/capabilities/McpClient.mjs.map +1 -0
- package/dist/capabilities/MemoryNotes.d.mts +424 -0
- package/dist/capabilities/MemoryNotes.mjs +128 -0
- package/dist/capabilities/MemoryNotes.mjs.map +1 -0
- package/dist/capabilities/Messaging.d.mts +3 -0
- package/dist/capabilities/Messaging.mjs +152 -0
- package/dist/capabilities/Messaging.mjs.map +1 -0
- package/dist/capabilities/ModelContext.d.mts +89 -0
- package/dist/capabilities/ModelContext.mjs +168 -0
- package/dist/capabilities/ModelContext.mjs.map +1 -0
- package/dist/capabilities/Redaction.d.mts +37 -0
- package/dist/capabilities/Redaction.mjs +104 -0
- package/dist/capabilities/Redaction.mjs.map +1 -0
- package/dist/capabilities/Remembering.d.mts +434 -0
- package/dist/capabilities/Remembering.mjs +290 -0
- package/dist/capabilities/Remembering.mjs.map +1 -0
- package/dist/capabilities/RunHooks.d.mts +82 -0
- package/dist/capabilities/RunHooks.mjs +144 -0
- package/dist/capabilities/RunHooks.mjs.map +1 -0
- package/dist/capabilities/SemanticMemory.d.mts +431 -0
- package/dist/capabilities/SemanticMemory.mjs +315 -0
- package/dist/capabilities/SemanticMemory.mjs.map +1 -0
- package/dist/capabilities/Subagent.d.mts +4 -0
- package/dist/capabilities/Subagent.mjs +5 -0
- package/dist/capabilities/SubagentReservations.d.mts +186 -0
- package/dist/capabilities/SubagentReservations.mjs +479 -0
- package/dist/capabilities/SubagentReservations.mjs.map +1 -0
- package/dist/capabilities/ToolDiscovery.d.mts +124 -0
- package/dist/capabilities/ToolDiscovery.mjs +230 -0
- package/dist/capabilities/ToolDiscovery.mjs.map +1 -0
- package/dist/capabilities/WebCapture.d.mts +163 -0
- package/dist/capabilities/WebCapture.mjs +335 -0
- package/dist/capabilities/WebCapture.mjs.map +1 -0
- package/dist/capabilities/WebSearch.d.mts +71 -0
- package/dist/capabilities/WebSearch.mjs +115 -0
- package/dist/capabilities/WebSearch.mjs.map +1 -0
- package/dist/compaction-C2OTceKw.mjs +505 -0
- package/dist/compaction-C2OTceKw.mjs.map +1 -0
- package/dist/core/Agent.d.mts +2 -0
- package/dist/core/Agent.mjs +2 -0
- package/dist/core/AgentError.d.mts +2 -0
- package/dist/core/AgentError.mjs +134 -0
- package/dist/core/AgentError.mjs.map +1 -0
- package/dist/core/AgentPolicy.d.mts +2 -0
- package/dist/core/AgentPolicy.mjs +94 -0
- package/dist/core/AgentPolicy.mjs.map +1 -0
- package/dist/core/AgentUpdates.d.mts +2 -0
- package/dist/core/AgentUpdates.mjs +63 -0
- package/dist/core/AgentUpdates.mjs.map +1 -0
- package/dist/core/FailureDiagnostic.d.mts +2 -0
- package/dist/core/FailureDiagnostic.mjs +2 -0
- package/dist/core/IdGenerator.d.mts +26 -0
- package/dist/core/IdGenerator.mjs +27 -0
- package/dist/core/IdGenerator.mjs.map +1 -0
- package/dist/core/Identifiers.d.mts +2 -0
- package/dist/core/Identifiers.mjs +43 -0
- package/dist/core/Identifiers.mjs.map +1 -0
- package/dist/core/Memory.d.mts +57 -0
- package/dist/core/Memory.mjs +203 -0
- package/dist/core/Memory.mjs.map +1 -0
- package/dist/core/MemoryNamespace.d.mts +2 -0
- package/dist/core/MemoryNamespace.mjs +116 -0
- package/dist/core/MemoryNamespace.mjs.map +1 -0
- package/dist/core/MemoryReference.d.mts +2 -0
- package/dist/core/MemoryReference.mjs +109 -0
- package/dist/core/MemoryReference.mjs.map +1 -0
- package/dist/core/MemoryRevalidation.d.mts +65 -0
- package/dist/core/MemoryRevalidation.mjs +126 -0
- package/dist/core/MemoryRevalidation.mjs.map +1 -0
- package/dist/core/MemoryStore.d.mts +186 -0
- package/dist/core/MemoryStore.mjs +243 -0
- package/dist/core/MemoryStore.mjs.map +1 -0
- package/dist/core/Receipt.d.mts +2 -0
- package/dist/core/Receipt.mjs +36 -0
- package/dist/core/Receipt.mjs.map +1 -0
- package/dist/core/RememberingStore.d.mts +1562 -0
- package/dist/core/RememberingStore.mjs +190 -0
- package/dist/core/RememberingStore.mjs.map +1 -0
- package/dist/core/RunEvent.d.mts +2 -0
- package/dist/core/RunEvent.mjs +337 -0
- package/dist/core/RunEvent.mjs.map +1 -0
- package/dist/core/RunPolicyUsage.d.mts +2 -0
- package/dist/core/RunPolicyUsage.mjs +21 -0
- package/dist/core/RunPolicyUsage.mjs.map +1 -0
- package/dist/core/SemanticMemoryIndex.d.mts +826 -0
- package/dist/core/SemanticMemoryIndex.mjs +185 -0
- package/dist/core/SemanticMemoryIndex.mjs.map +1 -0
- package/dist/core/SemanticMemoryRevalidation.d.mts +45 -0
- package/dist/core/SemanticMemoryRevalidation.mjs +191 -0
- package/dist/core/SemanticMemoryRevalidation.mjs.map +1 -0
- package/dist/core/SubagentContract.d.mts +2 -0
- package/dist/core/SubagentContract.mjs +148 -0
- package/dist/core/SubagentContract.mjs.map +1 -0
- package/dist/core/Thread.d.mts +2 -0
- package/dist/core/Thread.mjs +250 -0
- package/dist/core/Thread.mjs.map +1 -0
- package/dist/core/ToolResult.d.mts +2 -0
- package/dist/core/ToolResult.mjs +156 -0
- package/dist/core/ToolResult.mjs.map +1 -0
- package/dist/core/Usage.d.mts +2 -0
- package/dist/core/Usage.mjs +319 -0
- package/dist/core/Usage.mjs.map +1 -0
- package/dist/core/Worker.d.mts +3 -0
- package/dist/core/Worker.mjs +3 -0
- package/dist/durable/ActivityStore.d.mts +116 -0
- package/dist/durable/ActivityStore.mjs +131 -0
- package/dist/durable/ActivityStore.mjs.map +1 -0
- package/dist/durable/Admin.d.mts +2 -0
- package/dist/durable/Admin.mjs +330 -0
- package/dist/durable/Admin.mjs.map +1 -0
- package/dist/durable/AgentRegistration.d.mts +2 -0
- package/dist/durable/AgentRegistration.mjs +14 -0
- package/dist/durable/AgentRegistration.mjs.map +1 -0
- package/dist/durable/Certification.d.mts +110 -0
- package/dist/durable/Certification.mjs +159 -0
- package/dist/durable/Certification.mjs.map +1 -0
- package/dist/durable/CommittedActivity.d.mts +62 -0
- package/dist/durable/CommittedActivity.mjs +159 -0
- package/dist/durable/CommittedActivity.mjs.map +1 -0
- package/dist/durable/Digest.d.mts +2 -0
- package/dist/durable/Digest.mjs +50 -0
- package/dist/durable/Digest.mjs.map +1 -0
- package/dist/durable/DurableAgentRuntime.d.mts +3 -0
- package/dist/durable/DurableAgentRuntime.mjs +3 -0
- package/dist/durable/DurableFailpoint.d.mts +2 -0
- package/dist/durable/DurableFailpoint.mjs +102 -0
- package/dist/durable/DurableFailpoint.mjs.map +1 -0
- package/dist/durable/DurableFailpointTestControl.d.mts +14 -0
- package/dist/durable/DurableFailpointTestControl.mjs +19 -0
- package/dist/durable/DurableFailpointTestControl.mjs.map +1 -0
- package/dist/durable/EventSource.d.mts +2 -0
- package/dist/durable/EventSource.mjs +65 -0
- package/dist/durable/EventSource.mjs.map +1 -0
- package/dist/durable/GitHubWorkflowSource.d.mts +185 -0
- package/dist/durable/GitHubWorkflowSource.mjs +209 -0
- package/dist/durable/GitHubWorkflowSource.mjs.map +1 -0
- package/dist/durable/MessageDelivery.d.mts +893 -0
- package/dist/durable/MessageDelivery.mjs +557 -0
- package/dist/durable/MessageDelivery.mjs.map +1 -0
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +378 -0
- package/dist/durable/MessageDeliveryStoreConformance.mjs +270 -0
- package/dist/durable/MessageDeliveryStoreConformance.mjs.map +1 -0
- package/dist/durable/OperationAuthorizer.d.mts +2 -0
- package/dist/durable/OperationAuthorizer.mjs +70 -0
- package/dist/durable/OperationAuthorizer.mjs.map +1 -0
- package/dist/durable/PersistentHistory.d.mts +16 -0
- package/dist/durable/PersistentHistory.mjs +125 -0
- package/dist/durable/PersistentHistory.mjs.map +1 -0
- package/dist/durable/PreparedInputAdmission.d.mts +2 -0
- package/dist/durable/PreparedInputAdmission.mjs +38 -0
- package/dist/durable/PreparedInputAdmission.mjs.map +1 -0
- package/dist/durable/Records.d.mts +2 -0
- package/dist/durable/Records.mjs +848 -0
- package/dist/durable/Records.mjs.map +1 -0
- package/dist/durable/Recovery.d.mts +2 -0
- package/dist/durable/Recovery.mjs +739 -0
- package/dist/durable/Recovery.mjs.map +1 -0
- package/dist/durable/RunJournal.d.mts +2 -0
- package/dist/durable/RunJournal.mjs +2 -0
- package/dist/durable/Schedule.d.mts +2 -0
- package/dist/durable/Schedule.mjs +391 -0
- package/dist/durable/Schedule.mjs.map +1 -0
- package/dist/durable/ScheduleStoreConformance.d.mts +17 -0
- package/dist/durable/ScheduleStoreConformance.mjs +420 -0
- package/dist/durable/ScheduleStoreConformance.mjs.map +1 -0
- package/dist/durable/ScheduleTransition.d.mts +24 -0
- package/dist/durable/ScheduleTransition.mjs +180 -0
- package/dist/durable/ScheduleTransition.mjs.map +1 -0
- package/dist/durable/Scheduling.d.mts +54 -0
- package/dist/durable/Scheduling.mjs +2 -0
- package/dist/durable/SqlMemoryStore.d.mts +29 -0
- package/dist/durable/SqlMemoryStore.mjs +436 -0
- package/dist/durable/SqlMemoryStore.mjs.map +1 -0
- package/dist/durable/SqlMessageDeliveryStore.d.mts +42 -0
- package/dist/durable/SqlMessageDeliveryStore.mjs +179 -0
- package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -0
- package/dist/durable/SqlStorageV2Upgrade.d.mts +21 -0
- package/dist/durable/SqlStorageV2Upgrade.mjs +459 -0
- package/dist/durable/SqlStorageV2Upgrade.mjs.map +1 -0
- package/dist/durable/SqlSubscriptionStore.d.mts +62 -0
- package/dist/durable/SqlSubscriptionStore.mjs +751 -0
- package/dist/durable/SqlSubscriptionStore.mjs.map +1 -0
- package/dist/durable/SqlThreadNativeReads.d.mts +53 -0
- package/dist/durable/SqlThreadNativeReads.mjs +159 -0
- package/dist/durable/SqlThreadNativeReads.mjs.map +1 -0
- package/dist/durable/SubmissionLedger.d.mts +3 -0
- package/dist/durable/SubmissionLedger.mjs +959 -0
- package/dist/durable/SubmissionLedger.mjs.map +1 -0
- package/dist/durable/SubmissionLedgerConformance.d.mts +29 -0
- package/dist/durable/SubmissionLedgerConformance.mjs +2187 -0
- package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -0
- package/dist/durable/SubmissionStatus.d.mts +2 -0
- package/dist/durable/SubmissionStatus.mjs +18 -0
- package/dist/durable/SubmissionStatus.mjs.map +1 -0
- package/dist/durable/Subscription.d.mts +2 -0
- package/dist/durable/Subscription.mjs +360 -0
- package/dist/durable/Subscription.mjs.map +1 -0
- package/dist/durable/SubscriptionInput.d.mts +2 -0
- package/dist/durable/SubscriptionInput.mjs +52 -0
- package/dist/durable/SubscriptionInput.mjs.map +1 -0
- package/dist/durable/SubscriptionStoreConformance.d.mts +16 -0
- package/dist/durable/SubscriptionStoreConformance.mjs +625 -0
- package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -0
- package/dist/durable/SubscriptionTools.d.mts +273 -0
- package/dist/durable/SubscriptionTools.mjs +190 -0
- package/dist/durable/SubscriptionTools.mjs.map +1 -0
- package/dist/durable/SubscriptionTransition.d.mts +21 -0
- package/dist/durable/SubscriptionTransition.mjs +148 -0
- package/dist/durable/SubscriptionTransition.mjs.map +1 -0
- package/dist/durable/Subscriptions.d.mts +73 -0
- package/dist/durable/Subscriptions.mjs +627 -0
- package/dist/durable/Subscriptions.mjs.map +1 -0
- package/dist/durable/ThreadContextHistory.d.mts +32 -0
- package/dist/durable/ThreadContextHistory.mjs +152 -0
- package/dist/durable/ThreadContextHistory.mjs.map +1 -0
- package/dist/durable/ThreadContextHistoryProjection.d.mts +60 -0
- package/dist/durable/ThreadContextHistoryProjection.mjs +149 -0
- package/dist/durable/ThreadContextHistoryProjection.mjs.map +1 -0
- package/dist/durable/ThreadInvariants.d.mts +76 -0
- package/dist/durable/ThreadInvariants.mjs +246 -0
- package/dist/durable/ThreadInvariants.mjs.map +1 -0
- package/dist/durable/ThreadProjection.d.mts +78 -0
- package/dist/durable/ThreadProjection.mjs +158 -0
- package/dist/durable/ThreadProjection.mjs.map +1 -0
- package/dist/durable/ThreadProjectionMaintenance.d.mts +49 -0
- package/dist/durable/ThreadProjectionMaintenance.mjs +33 -0
- package/dist/durable/ThreadProjectionMaintenance.mjs.map +1 -0
- package/dist/durable/ThreadStore.d.mts +2 -0
- package/dist/durable/ThreadStore.mjs +355 -0
- package/dist/durable/ThreadStore.mjs.map +1 -0
- package/dist/durable/ThreadStoreConformance.d.mts +28 -0
- package/dist/durable/ThreadStoreConformance.mjs +503 -0
- package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
- package/dist/durable/ToolReconciler.d.mts +2 -0
- package/dist/durable/ToolReconciler.mjs +85 -0
- package/dist/durable/ToolReconciler.mjs.map +1 -0
- package/dist/durable/WakeScheduler.d.mts +2 -0
- package/dist/durable/WakeScheduler.mjs +85 -0
- package/dist/durable/WakeScheduler.mjs.map +1 -0
- package/dist/durable/WorkerHost.d.mts +129 -0
- package/dist/durable/WorkerHost.mjs +77 -0
- package/dist/durable/WorkerHost.mjs.map +1 -0
- package/dist/engine/AgentRuntime.d.mts +2 -0
- package/dist/engine/AgentRuntime.mjs +2 -0
- package/dist/engine/Compaction.d.mts +7 -0
- package/dist/engine/Compaction.mjs +16 -0
- package/dist/engine/Compaction.mjs.map +1 -0
- package/dist/engine/ContextCompactor.d.mts +2 -0
- package/dist/engine/ContextCompactor.mjs +119 -0
- package/dist/engine/ContextCompactor.mjs.map +1 -0
- package/dist/engine/ContextHistory.d.mts +65 -0
- package/dist/engine/ContextHistory.mjs +76 -0
- package/dist/engine/ContextHistory.mjs.map +1 -0
- package/dist/engine/ContextWindow.d.mts +2 -0
- package/dist/engine/ContextWindow.mjs +59 -0
- package/dist/engine/ContextWindow.mjs.map +1 -0
- package/dist/engine/DurableStep.d.mts +2 -0
- package/dist/engine/DurableStep.mjs +62 -0
- package/dist/engine/DurableStep.mjs.map +1 -0
- package/dist/engine/MessagingHost.d.mts +2 -0
- package/dist/engine/MessagingHost.mjs +2 -0
- package/dist/engine/Output.d.mts +2 -0
- package/dist/engine/Output.mjs +8 -0
- package/dist/engine/Output.mjs.map +1 -0
- package/dist/engine/RunEventSink.d.mts +2 -0
- package/dist/engine/RunEventSink.mjs +22 -0
- package/dist/engine/RunEventSink.mjs.map +1 -0
- package/dist/engine/RunOptions.d.mts +2 -0
- package/dist/engine/RunOptions.mjs +124 -0
- package/dist/engine/RunOptions.mjs.map +1 -0
- package/dist/engine/SubagentHost.d.mts +2 -0
- package/dist/engine/SubagentHost.mjs +76 -0
- package/dist/engine/SubagentHost.mjs.map +1 -0
- package/dist/engine/ThreadHistory.d.mts +2 -0
- package/dist/engine/ThreadHistory.mjs +67 -0
- package/dist/engine/ThreadHistory.mjs.map +1 -0
- package/dist/engine/ToolBroker.d.mts +2 -0
- package/dist/engine/ToolBroker.mjs +42 -0
- package/dist/engine/ToolBroker.mjs.map +1 -0
- package/dist/foreign-diagnostic-DBQ1XHKh.mjs +37 -0
- package/dist/foreign-diagnostic-DBQ1XHKh.mjs.map +1 -0
- package/dist/index.d.mts +91 -6
- package/dist/index.mjs +100 -6
- package/dist/output-contract-BC7tjlGw.mjs +84 -0
- package/dist/output-contract-BC7tjlGw.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sandbox/CodeExecutor.d.mts +194 -0
- package/dist/sandbox/CodeExecutor.mjs +278 -0
- package/dist/sandbox/CodeExecutor.mjs.map +1 -0
- package/dist/sandbox/InteractiveBrowser.d.mts +257 -0
- package/dist/sandbox/InteractiveBrowser.mjs +236 -0
- package/dist/sandbox/InteractiveBrowser.mjs.map +1 -0
- package/dist/sandbox/PageCapture.d.mts +2 -0
- package/dist/sandbox/PageCapture.mjs +450 -0
- package/dist/sandbox/PageCapture.mjs.map +1 -0
- package/dist/sandbox/PageCrawl.d.mts +88 -0
- package/dist/sandbox/PageCrawl.mjs +124 -0
- package/dist/sandbox/PageCrawl.mjs.map +1 -0
- package/dist/sandbox/PageScreenshot.d.mts +2 -0
- package/dist/sandbox/PageScreenshot.mjs +53 -0
- package/dist/sandbox/PageScreenshot.mjs.map +1 -0
- package/dist/sandbox/ProtectedBrowser.d.mts +283 -0
- package/dist/sandbox/ProtectedBrowser.mjs +298 -0
- package/dist/sandbox/ProtectedBrowser.mjs.map +1 -0
- package/dist/sandbox/Sandbox.d.mts +2 -0
- package/dist/sandbox/Sandbox.mjs +208 -0
- package/dist/sandbox/Sandbox.mjs.map +1 -0
- package/dist/utf8-BYfhEkcj.mjs +11 -0
- package/dist/utf8-BYfhEkcj.mjs.map +1 -0
- package/dist/utf8-DchGZRBd.mjs +23 -0
- package/dist/utf8-DchGZRBd.mjs.map +1 -0
- package/package.json +1 -40
- package/src/InMemory.ts +19 -0
- package/src/ToolExposure.ts +2 -0
- package/src/capabilities/Approval.ts +352 -0
- package/src/capabilities/Budget.ts +536 -0
- package/src/capabilities/CodeMode.ts +1090 -0
- package/src/capabilities/Commands.ts +86 -0
- package/src/capabilities/ContextTools.ts +184 -0
- package/src/capabilities/Mcp.ts +426 -0
- package/src/capabilities/McpClient.ts +967 -0
- package/src/capabilities/MemoryNotes.ts +174 -0
- package/src/capabilities/Messaging.ts +261 -0
- package/src/capabilities/ModelContext.ts +354 -0
- package/src/capabilities/Redaction.ts +157 -0
- package/src/capabilities/Remembering.ts +550 -0
- package/src/capabilities/RunHooks.ts +280 -0
- package/src/capabilities/SemanticMemory.ts +447 -0
- package/src/capabilities/Subagent.ts +2489 -0
- package/src/capabilities/SubagentReservations.ts +850 -0
- package/src/capabilities/ToolDiscovery.ts +369 -0
- package/src/capabilities/WebCapture.ts +722 -0
- package/src/capabilities/WebSearch.ts +190 -0
- package/src/capabilities/internal/subagent-background.ts +1273 -0
- package/src/capabilities/internal/subagent-contract.ts +146 -0
- package/src/capabilities/internal/subagent-policy.ts +235 -0
- package/src/capabilities/internal/subagent-reporting.ts +136 -0
- package/src/capabilities/internal/utf8.ts +10 -0
- package/src/core/Agent.ts +602 -0
- package/src/core/AgentError.ts +172 -0
- package/src/core/AgentPolicy.ts +153 -0
- package/src/core/AgentUpdates.ts +100 -0
- package/src/core/FailureDiagnostic.ts +343 -0
- package/src/core/IdGenerator.ts +39 -0
- package/src/core/Identifiers.ts +48 -0
- package/src/core/Memory.ts +290 -0
- package/src/core/MemoryNamespace.ts +196 -0
- package/src/core/MemoryReference.ts +121 -0
- package/src/core/MemoryRevalidation.ts +185 -0
- package/src/core/MemoryStore.ts +368 -0
- package/src/core/Messaging.ts +72 -0
- package/src/core/Receipt.ts +42 -0
- package/src/core/RememberingStore.ts +300 -0
- package/src/core/RunEvent.ts +366 -0
- package/src/core/RunPolicyUsage.ts +17 -0
- package/src/core/SemanticMemoryIndex.ts +250 -0
- package/src/core/SemanticMemoryRevalidation.ts +254 -0
- package/src/core/SubagentContract.ts +196 -0
- package/src/core/Thread.ts +371 -0
- package/src/core/ToolExposure.ts +74 -0
- package/src/core/ToolResult.ts +190 -0
- package/src/core/Usage.ts +529 -0
- package/src/core/Worker.ts +240 -0
- package/src/core/internal/agent-updates.ts +34 -0
- package/src/core/internal/message-status.ts +60 -0
- package/src/core/internal/strict-schema.ts +14 -0
- package/src/core/internal/utf8.ts +23 -0
- package/src/durable/ActivityStore.ts +160 -0
- package/src/durable/Admin.ts +505 -0
- package/src/durable/AgentRegistration.ts +14 -0
- package/src/durable/Certification.ts +210 -0
- package/src/durable/CommittedActivity.ts +296 -0
- package/src/durable/Digest.ts +87 -0
- package/src/durable/DurableAgentRuntime.ts +11275 -0
- package/src/durable/DurableFailpoint.ts +111 -0
- package/src/durable/DurableFailpointTestControl.ts +39 -0
- package/src/durable/EventSource.ts +172 -0
- package/src/durable/GitHubWorkflowSource.ts +447 -0
- package/src/durable/MessageDelivery.ts +832 -0
- package/src/durable/MessageDeliveryStoreConformance.ts +410 -0
- package/src/durable/OperationAuthorizer.ts +85 -0
- package/src/durable/PersistentHistory.ts +260 -0
- package/src/durable/PreparedInputAdmission.ts +57 -0
- package/src/durable/Records.ts +1075 -0
- package/src/durable/Recovery.ts +1018 -0
- package/src/durable/RunJournal.ts +1631 -0
- package/src/durable/Schedule.ts +513 -0
- package/src/durable/ScheduleStoreConformance.ts +638 -0
- package/src/durable/ScheduleTransition.ts +265 -0
- package/src/durable/Scheduling.ts +1077 -0
- package/src/durable/SqlMemoryStore.ts +778 -0
- package/src/durable/SqlMessageDeliveryStore.ts +335 -0
- package/src/durable/SqlStorageV2Upgrade.ts +500 -0
- package/src/durable/SqlSubscriptionStore.ts +1440 -0
- package/src/durable/SqlThreadNativeReads.ts +270 -0
- package/src/durable/SubmissionLedger.ts +1265 -0
- package/src/durable/SubmissionLedgerConformance.ts +4820 -0
- package/src/durable/SubmissionStatus.ts +14 -0
- package/src/durable/Subscription.ts +544 -0
- package/src/durable/SubscriptionInput.ts +144 -0
- package/src/durable/SubscriptionStoreConformance.ts +945 -0
- package/src/durable/SubscriptionTools.ts +327 -0
- package/src/durable/SubscriptionTransition.ts +302 -0
- package/src/durable/Subscriptions.ts +1210 -0
- package/src/durable/ThreadContextHistory.ts +227 -0
- package/src/durable/ThreadContextHistoryProjection.ts +216 -0
- package/src/durable/ThreadInvariants.ts +507 -0
- package/src/durable/ThreadProjection.ts +269 -0
- package/src/durable/ThreadProjectionMaintenance.ts +67 -0
- package/src/durable/ThreadStore.ts +573 -0
- package/src/durable/ThreadStoreConformance.ts +1156 -0
- package/src/durable/ToolReconciler.ts +109 -0
- package/src/durable/WakeScheduler.ts +134 -0
- package/src/durable/WorkerHost.ts +171 -0
- package/src/durable/internal/agent-registration.ts +587 -0
- package/src/durable/internal/agent-updates.ts +302 -0
- package/src/durable/internal/foreign-diagnostic.ts +47 -0
- package/src/durable/internal/journal-checkpoint.ts +104 -0
- package/src/durable/internal/journal-metadata.ts +117 -0
- package/src/durable/internal/message-status.ts +20 -0
- package/src/durable/internal/messaging-host.ts +637 -0
- package/src/durable/internal/schedule-time.ts +303 -0
- package/src/durable/internal/storage-v2-layout.ts +163 -0
- package/src/durable/internal/storage-v2.ts +73 -0
- package/src/durable/internal/worker-host.ts +2885 -0
- package/src/durable/internal/worker-runtime.ts +9 -0
- package/src/engine/AgentRuntime.ts +37 -0
- package/src/engine/Compaction.ts +11 -0
- package/src/engine/ContextCompactor.ts +277 -0
- package/src/engine/ContextHistory.ts +73 -0
- package/src/engine/ContextWindow.ts +72 -0
- package/src/engine/DurableStep.ts +132 -0
- package/src/engine/MessagingHost.ts +110 -0
- package/src/engine/Output.ts +2 -0
- package/src/engine/RunEventSink.ts +132 -0
- package/src/engine/RunOptions.ts +1101 -0
- package/src/engine/SubagentHost.ts +230 -0
- package/src/engine/ThreadHistory.ts +120 -0
- package/src/engine/ToolBroker.ts +157 -0
- package/src/engine/ToolExposure.ts +48 -0
- package/src/engine/internal/agent-runtime.ts +10500 -0
- package/src/engine/internal/bounded-value.ts +315 -0
- package/src/engine/internal/compaction.ts +678 -0
- package/src/engine/internal/error-diagnostic.ts +39 -0
- package/src/engine/internal/output-contract.ts +173 -0
- package/src/engine/internal/primitive-delta.ts +80 -0
- package/src/engine/internal/provider-result-staging.ts +211 -0
- package/src/engine/internal/tool-derivative.ts +106 -0
- package/src/engine/internal/tool-exposure.ts +224 -0
- package/src/engine/internal/tool-telemetry.ts +484 -0
- package/src/index.ts +99 -21
- package/src/sandbox/CodeExecutor.ts +352 -0
- package/src/sandbox/InteractiveBrowser.ts +339 -0
- package/src/sandbox/PageCapture.ts +691 -0
- package/src/sandbox/PageCrawl.ts +148 -0
- package/src/sandbox/PageScreenshot.ts +81 -0
- package/src/sandbox/ProtectedBrowser.ts +452 -0
- package/src/sandbox/Sandbox.ts +241 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { RunId, ThreadId, ToolCallId, TurnId } from "./core/Identifiers.mjs";
|
|
3
|
+
import { IdempotencyKey } from "./core/Receipt.mjs";
|
|
4
|
+
import { ModelCallUsage, summarizeModelUsage } from "./core/Usage.mjs";
|
|
5
|
+
import { f as contextWindowId, n as COMPACTION_SUMMARY_PREFIX, p as contextWindowMessage, t as CLEARED_TOOL_RESULT } from "./compaction-C2OTceKw.mjs";
|
|
6
|
+
import { RunPolicyUsage } from "./core/RunPolicyUsage.mjs";
|
|
7
|
+
import { BatchId, CanonicalBatch, CompactionCreated, ModelResponseRecorded, PersistedJson, RecordEnvelope, RecordId, RunCompleted, ToolCallSettled } from "./durable/Records.mjs";
|
|
8
|
+
import { digestJson } from "./durable/Digest.mjs";
|
|
9
|
+
import { Prompt } from "effect/unstable/ai";
|
|
10
|
+
import { Effect, Schema, Stream } from "effect";
|
|
11
|
+
//#region src/durable/internal/journal-metadata.ts
|
|
12
|
+
const toolExecutionKey = (call) => JSON.stringify([
|
|
13
|
+
call.runId,
|
|
14
|
+
call.turn,
|
|
15
|
+
call.toolCallId
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* Attempt-local metadata collector. Feed every validated record exactly once, in canonical order,
|
|
19
|
+
* including records omitted from the control view. A snapshot is independent of later suffix
|
|
20
|
+
* additions and may only accompany a replay stream bounded at that same captured tail.
|
|
21
|
+
*/
|
|
22
|
+
const makeJournalMetadata = (ownerRunId, seed) => {
|
|
23
|
+
const firstSequenceByRun = /* @__PURE__ */ new Map();
|
|
24
|
+
if (seed?.firstSequence !== void 0) firstSequenceByRun.set(seed.runId, seed.firstSequence);
|
|
25
|
+
const lastResponseSequenceByRun = /* @__PURE__ */ new Map();
|
|
26
|
+
const terminalSequenceByRun = /* @__PURE__ */ new Map();
|
|
27
|
+
const settledSpans = [];
|
|
28
|
+
const toolExecutionEvidence = /* @__PURE__ */ new Set();
|
|
29
|
+
const settledToolCallRecordIds = /* @__PURE__ */ new Set();
|
|
30
|
+
const settledById = /* @__PURE__ */ new Map();
|
|
31
|
+
const compactions = [];
|
|
32
|
+
return {
|
|
33
|
+
add: (envelope) => {
|
|
34
|
+
const payload = envelope.record.payload;
|
|
35
|
+
if ((payload._tag === "RunCompleted" || payload._tag === "RunFailed" || payload._tag === "SubmissionSettled") && payload.runId !== void 0 && !terminalSequenceByRun.has(payload.runId)) terminalSequenceByRun.set(payload.runId, envelope.sequence);
|
|
36
|
+
if (payload._tag === "CompactionCreated") {
|
|
37
|
+
compactions.push({
|
|
38
|
+
payload,
|
|
39
|
+
sequence: envelope.sequence
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if ("runId" in payload && typeof payload.runId === "string" && !firstSequenceByRun.has(payload.runId)) firstSequenceByRun.set(payload.runId, envelope.sequence);
|
|
44
|
+
if (payload._tag === "ModelResponseRecorded") lastResponseSequenceByRun.set(payload.runId, envelope.sequence);
|
|
45
|
+
else if (payload._tag === "ToolCallPrepared" || payload._tag === "ToolCallUnknown") toolExecutionEvidence.add(toolExecutionKey(payload));
|
|
46
|
+
else if (payload._tag === "ToolCallSettled") {
|
|
47
|
+
settledToolCallRecordIds.add(envelope.record.recordId);
|
|
48
|
+
if (payload.runId === ownerRunId) settledById.set(envelope.record.recordId, {
|
|
49
|
+
isFailure: payload.isFailure,
|
|
50
|
+
...payload.toolSelection === void 0 ? {} : { toolSelection: payload.toolSelection },
|
|
51
|
+
...payload.budgetRejected === void 0 ? {} : { budgetRejected: payload.budgetRejected }
|
|
52
|
+
});
|
|
53
|
+
const from = lastResponseSequenceByRun.get(payload.runId);
|
|
54
|
+
if (from !== void 0 && from < envelope.sequence) settledSpans.push({
|
|
55
|
+
from,
|
|
56
|
+
to: envelope.sequence
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
snapshot: () => ({
|
|
61
|
+
ownerRunId,
|
|
62
|
+
seed,
|
|
63
|
+
firstSequenceByRun: new Map(firstSequenceByRun),
|
|
64
|
+
lastResponseSequenceByRun: new Map(lastResponseSequenceByRun),
|
|
65
|
+
terminalSequenceByRun: new Map(terminalSequenceByRun),
|
|
66
|
+
settledSpans: [...settledSpans],
|
|
67
|
+
toolExecutionEvidence: new Set(toolExecutionEvidence),
|
|
68
|
+
settledToolCallRecordIds: new Set(settledToolCallRecordIds),
|
|
69
|
+
settledById: new Map(settledById),
|
|
70
|
+
compactions: [...compactions]
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/durable/RunJournal.ts
|
|
76
|
+
var RunJournal_exports = /* @__PURE__ */ __exportAll({
|
|
77
|
+
RunJournalError: () => RunJournalError,
|
|
78
|
+
agentUpdateRecordId: () => agentUpdateRecordId,
|
|
79
|
+
approvalDecisionBatchId: () => approvalDecisionBatchId,
|
|
80
|
+
childIdempotencyKeyFor: () => childIdempotencyKeyFor,
|
|
81
|
+
childThreadIdFor: () => childThreadIdFor,
|
|
82
|
+
compactionBatchId: () => compactionBatchId,
|
|
83
|
+
compactionRecordId: () => compactionRecordId,
|
|
84
|
+
firstWorkerInputRecordId: () => firstWorkerInputRecordId,
|
|
85
|
+
markUnknownBatchId: () => markUnknownBatchId,
|
|
86
|
+
modelResponseInterruptedBatchId: () => modelResponseInterruptedBatchId,
|
|
87
|
+
modelResponseInterruptedRecordId: () => modelResponseInterruptedRecordId,
|
|
88
|
+
modelResponseRecordId: () => modelResponseRecordId,
|
|
89
|
+
peerMessageRecordId: () => peerMessageRecordId,
|
|
90
|
+
projectRunJournal: () => projectRunJournal,
|
|
91
|
+
projectRunJournalStream: () => projectRunJournalStream,
|
|
92
|
+
promptFromCanonicalRecords: () => promptFromCanonicalRecords,
|
|
93
|
+
runCompletedRecordId: () => runCompletedRecordId,
|
|
94
|
+
runCompletionDigest: () => runCompletionDigest,
|
|
95
|
+
runDurationBatchId: () => runDurationBatchId,
|
|
96
|
+
runDurationRecordId: () => runDurationRecordId,
|
|
97
|
+
runIdForSubmission: () => runIdForSubmission,
|
|
98
|
+
runStartedBatchId: () => runStartedBatchId,
|
|
99
|
+
runStartedRecordId: () => runStartedRecordId,
|
|
100
|
+
subagentJoinBatchId: () => subagentJoinBatchId,
|
|
101
|
+
subagentJoinedRecordId: () => subagentJoinedRecordId,
|
|
102
|
+
subagentLineageBatchId: () => subagentLineageBatchId,
|
|
103
|
+
subagentLineageRecordId: () => subagentLineageRecordId,
|
|
104
|
+
subagentRequestedBatchId: () => subagentRequestedBatchId,
|
|
105
|
+
subagentRequestedRecordId: () => subagentRequestedRecordId,
|
|
106
|
+
subagentStartedBatchId: () => subagentStartedBatchId,
|
|
107
|
+
subagentStartedRecordId: () => subagentStartedRecordId,
|
|
108
|
+
toolApprovalDecisionRecordId: () => toolApprovalDecisionRecordId,
|
|
109
|
+
toolApprovalRequestRecordId: () => toolApprovalRequestRecordId,
|
|
110
|
+
toolCallPreparedRecordId: () => toolCallPreparedRecordId,
|
|
111
|
+
toolCallResolutionBatchId: () => toolCallResolutionBatchId,
|
|
112
|
+
toolCallResolvedRecordId: () => toolCallResolvedRecordId,
|
|
113
|
+
toolCallResultBatchId: () => toolCallResultBatchId,
|
|
114
|
+
toolCallSettledRecordId: () => toolCallSettledRecordId,
|
|
115
|
+
toolCallUnknownRecordId: () => toolCallUnknownRecordId,
|
|
116
|
+
toolStepSettledBatchId: () => toolStepSettledBatchId,
|
|
117
|
+
toolStepSettledRecordId: () => toolStepSettledRecordId,
|
|
118
|
+
turnApprovalsBatchId: () => turnApprovalsBatchId,
|
|
119
|
+
turnBatchId: () => turnBatchId,
|
|
120
|
+
turnCanonicalBatch: () => turnCanonicalBatch,
|
|
121
|
+
turnIdForRun: () => turnIdForRun,
|
|
122
|
+
turnPreparedBatchId: () => turnPreparedBatchId,
|
|
123
|
+
turnResponseBatch: () => turnResponseBatch,
|
|
124
|
+
turnResponseBatchId: () => turnResponseBatchId,
|
|
125
|
+
turnResultsBatch: () => turnResultsBatch,
|
|
126
|
+
turnResultsBatchId: () => turnResultsBatchId,
|
|
127
|
+
workerInputRecordId: () => workerInputRecordId,
|
|
128
|
+
workerOriginRecordId: () => workerOriginRecordId,
|
|
129
|
+
workerReportRecordId: () => workerReportRecordId
|
|
130
|
+
});
|
|
131
|
+
/** A canonical record could not be projected into Run/Prompt state. */
|
|
132
|
+
var RunJournalError = class extends Schema.TaggedError()("RunJournalError", {
|
|
133
|
+
message: Schema.String,
|
|
134
|
+
cause: Schema.optionalKey(Schema.Defect())
|
|
135
|
+
}) {};
|
|
136
|
+
const journalError = (message, cause) => cause === void 0 ? RunJournalError.make({ message }) : RunJournalError.make({
|
|
137
|
+
message,
|
|
138
|
+
cause
|
|
139
|
+
});
|
|
140
|
+
const decodeRunId = Schema.decodeSync(RunId);
|
|
141
|
+
const decodeTurnId = Schema.decodeSync(TurnId);
|
|
142
|
+
const decodeBatchId = Schema.decodeSync(BatchId);
|
|
143
|
+
const decodeRecordId = Schema.decodeSync(RecordId);
|
|
144
|
+
/**
|
|
145
|
+
* Deterministic Run identity pinned per Submission (plan §Coordinator flow). Every Attempt of one
|
|
146
|
+
* Submission shares this Run identity, so canonical per-Turn records from different Attempts
|
|
147
|
+
* belong to one logical Run.
|
|
148
|
+
*/
|
|
149
|
+
const runIdForSubmission = (submissionId) => decodeRunId(`run:${submissionId}`);
|
|
150
|
+
/** Stable canonical clock identity shared by every Attempt of one Run. */
|
|
151
|
+
const runStartedRecordId = (runId) => decodeRecordId(`run-start:${runId}`);
|
|
152
|
+
const runStartedBatchId = (runId) => decodeBatchId(`run-start:${runId}`);
|
|
153
|
+
const runDurationRecordId = (runId) => decodeRecordId(`run-duration:${runId}`);
|
|
154
|
+
const runDurationBatchId = (runId) => decodeBatchId(`run-duration:${runId}`);
|
|
155
|
+
/** Deterministic Turn identity: Attempt-independent for one (Run, canonical turn) pair. */
|
|
156
|
+
const turnIdForRun = (runId, turn) => decodeTurnId(`turn:${runId}:${turn}`);
|
|
157
|
+
/** Deterministic batch identity of one committed canonical no-tool Turn (P4 single-batch shape). */
|
|
158
|
+
const turnBatchId = (runId, turn) => decodeBatchId(`turn:${runId}:${turn}`);
|
|
159
|
+
/**
|
|
160
|
+
* Deterministic batch identity of a tool-declaring Turn's RESPONSE commit (plan §2.1 commit 1):
|
|
161
|
+
* the assistant response plus pending steering becomes canonical BEFORE approval preflight and
|
|
162
|
+
* tool preparation, creating the durability §15 "resume tool scheduling" window.
|
|
163
|
+
*/
|
|
164
|
+
const turnResponseBatchId = (runId, turn) => decodeBatchId(`turn-response:${runId}:${turn}`);
|
|
165
|
+
/**
|
|
166
|
+
* Deterministic batch identity of a tool-declaring Turn's RESULTS commit (plan §2.1 commit 5):
|
|
167
|
+
* every `ToolCallSettled` record of the Turn, in declaration order, model-visible atomically.
|
|
168
|
+
*/
|
|
169
|
+
const turnResultsBatchId = (runId, turn) => decodeBatchId(`turn-results:${runId}:${turn}`);
|
|
170
|
+
/**
|
|
171
|
+
* Deterministic per-call late-settle batch identity used by the resolution path when one
|
|
172
|
+
* recovered/resolved call settles outside its Turn's results batch. Record identity
|
|
173
|
+
* (`tool-settled:{runId}:{turn}:{toolCallId}`) dedupes double-settles across both paths.
|
|
174
|
+
*/
|
|
175
|
+
const toolCallResultBatchId = (runId, turn, toolCallId) => decodeBatchId(`turn-results:${runId}:${turn}:${toolCallId}`);
|
|
176
|
+
/** Deterministic batch identity of one Turn's `ToolCallPrepared` commit (plan §2.1 commit 3). */
|
|
177
|
+
const turnPreparedBatchId = (runId, turn) => decodeBatchId(`turn-prepared:${runId}:${turn}`);
|
|
178
|
+
/**
|
|
179
|
+
* Deterministic identity of one pre-Turn compaction record (RUN-026,
|
|
180
|
+
* RUN-026). Keyed by Run, Turn, and kind — the engine performs at most one
|
|
181
|
+
* threshold compaction per Turn plus at most one overflow-forced summarize,
|
|
182
|
+
* so a superseding Attempt that re-decides the same compaction replays the
|
|
183
|
+
* batch identity instead of duplicating the record.
|
|
184
|
+
*/
|
|
185
|
+
const compactionRecordId = (runId, turn, kind) => decodeRecordId(`compaction:${runId}:${turn}:${kind}`);
|
|
186
|
+
/** Deterministic batch identity of one compaction append (same string as its record id). */
|
|
187
|
+
const compactionBatchId = (runId, turn, kind) => decodeBatchId(`compaction:${runId}:${turn}:${kind}`);
|
|
188
|
+
/** Deterministic canonical record identity of one Turn's `ModelResponseRecorded` record. */
|
|
189
|
+
const modelResponseRecordId = (runId, turn) => decodeRecordId(`model-response:${runId}:${turn}`);
|
|
190
|
+
/** Terminal Tool completion marker committed atomically with its settled Tool result. */
|
|
191
|
+
const runCompletedRecordId = (runId) => decodeRecordId(`run-completed:${runId}`);
|
|
192
|
+
/** Native source reservation locator, including the first admission of a continuing worker. */
|
|
193
|
+
const workerInputRecordId = (messageId) => decodeRecordId(`worker-input:${messageId}`);
|
|
194
|
+
/** Source-owned first reservation; native worker identity is minted from its first message. */
|
|
195
|
+
const firstWorkerInputRecordId = (worker) => decodeRecordId(`worker-input:${worker.threadId}`);
|
|
196
|
+
const workerOriginRecordId = (threadId) => decodeRecordId(`worker-origin:${threadId}`);
|
|
197
|
+
const workerReportRecordId = (messageId) => decodeRecordId(`worker-report:${messageId}`);
|
|
198
|
+
const peerMessageRecordId = (messageId) => decodeRecordId(messageId);
|
|
199
|
+
/** Same immutable tuple used by native update admission; callers never parse its hash. */
|
|
200
|
+
const agentUpdateRecordId = Effect.fn("RunJournal.agentUpdateRecordId")(function* (threadId, runId, updateId) {
|
|
201
|
+
return decodeRecordId(`agent-update:${yield* digestJson([
|
|
202
|
+
threadId,
|
|
203
|
+
runId,
|
|
204
|
+
updateId
|
|
205
|
+
])}`);
|
|
206
|
+
});
|
|
207
|
+
/** Deterministic canonical record identity of one Turn's `ToolCallSettled` record. */
|
|
208
|
+
const toolCallSettledRecordId = (runId, turn, toolCallId) => decodeRecordId(`tool-settled:${runId}:${turn}:${toolCallId}`);
|
|
209
|
+
/** Deterministic canonical record identity of one Tool Call's `ToolCallPrepared` record. */
|
|
210
|
+
const toolCallPreparedRecordId = (runId, turn, toolCallId) => decodeRecordId(`tool-prepared:${runId}:${turn}:${toolCallId}`);
|
|
211
|
+
/** Deterministic batch identity of one Turn's `ToolCallUnknown` marking append. */
|
|
212
|
+
const markUnknownBatchId = (submissionId, turn) => decodeBatchId(`mark-unknown:${submissionId}:${turn}`);
|
|
213
|
+
/** Deterministic canonical record identity of one Tool Call's `ToolCallUnknown` record. */
|
|
214
|
+
const toolCallUnknownRecordId = (runId, turn, toolCallId) => decodeRecordId(`tool-unknown:${runId}:${turn}:${toolCallId}`);
|
|
215
|
+
/** Deterministic batch identity of one Tool Call's resolution append (DUR-017). */
|
|
216
|
+
const toolCallResolutionBatchId = (submissionId, toolCallId) => decodeBatchId(`resolve:${submissionId}:${toolCallId}`);
|
|
217
|
+
/** Deterministic canonical record identity of one Tool Call's `ToolCallResolved` record. */
|
|
218
|
+
const toolCallResolvedRecordId = (runId, turn, toolCallId) => decodeRecordId(`tool-resolved:${runId}:${turn}:${toolCallId}`);
|
|
219
|
+
/**
|
|
220
|
+
* Deterministic identity of one accepted Durable Step result. The one-record batch reuses the
|
|
221
|
+
* SAME string, so batch idempotency plus the epoch fence realize the durability §11
|
|
222
|
+
* racing-writers rule: only the fenced winner's record commits; the loser replays it.
|
|
223
|
+
* A versioned JSON tuple keeps separator characters in each identity component distinct.
|
|
224
|
+
* Replay derives this key from the structured payload, including records with legacy IDs.
|
|
225
|
+
*/
|
|
226
|
+
const toolStepSettledRecordId = (runId, toolCallId, stepName) => decodeRecordId(JSON.stringify([
|
|
227
|
+
"step@2",
|
|
228
|
+
runId,
|
|
229
|
+
toolCallId,
|
|
230
|
+
stepName
|
|
231
|
+
]));
|
|
232
|
+
/** Deterministic batch identity of one Durable Step commit (same string as its record id). */
|
|
233
|
+
const toolStepSettledBatchId = (runId, toolCallId, stepName) => decodeBatchId(toolStepSettledRecordId(runId, toolCallId, stepName));
|
|
234
|
+
/** Deterministic batch identity of one Turn's canonical approval-request append (plan §2.6). */
|
|
235
|
+
const turnApprovalsBatchId = (runId, turn) => decodeBatchId(`turn-approvals:${runId}:${turn}`);
|
|
236
|
+
/** Deterministic canonical record identity of one Tool Call's `ToolApprovalRequested` record. */
|
|
237
|
+
const toolApprovalRequestRecordId = (runId, turn, toolCallId) => decodeRecordId(`approval-request:${runId}:${turn}:${toolCallId}`);
|
|
238
|
+
/** Deterministic batch identity of one Tool Call's canonical approval-decision append. */
|
|
239
|
+
const approvalDecisionBatchId = (submissionId, toolCallId) => decodeBatchId(`approval-decision:${submissionId}:${toolCallId}`);
|
|
240
|
+
/** Deterministic canonical record identity of one Tool Call's `ToolApprovalDecided` record. */
|
|
241
|
+
const toolApprovalDecisionRecordId = (runId, turn, toolCallId) => decodeRecordId(`approval-decision:${runId}:${turn}:${toolCallId}`);
|
|
242
|
+
/**
|
|
243
|
+
* Deterministic identity of one superseded Attempt's `ModelResponseInterrupted` audit record
|
|
244
|
+
* (durability §9). Keyed by the superseded epoch, so each interrupted ownership period is
|
|
245
|
+
* recorded at most once; the one-record batch reuses the same string.
|
|
246
|
+
*/
|
|
247
|
+
const modelResponseInterruptedRecordId = (runId, supersededEpoch) => decodeRecordId(`interrupted:${runId}:${supersededEpoch}`);
|
|
248
|
+
/** Deterministic batch identity of one `ModelResponseInterrupted` append (same string). */
|
|
249
|
+
const modelResponseInterruptedBatchId = (runId, supersededEpoch) => decodeBatchId(`interrupted:${runId}:${supersededEpoch}`);
|
|
250
|
+
const decodeThreadId = Schema.decodeSync(ThreadId);
|
|
251
|
+
const decodeIdempotencyKey = Schema.decodeSync(IdempotencyKey);
|
|
252
|
+
/**
|
|
253
|
+
* Deterministic canonical record identity of one parent Tool Call's `SubagentRequested` record.
|
|
254
|
+
* The one-record batch reuses the same string, so batch
|
|
255
|
+
* idempotency plus the parent epoch fence make the request append exactly-once-canonical.
|
|
256
|
+
*/
|
|
257
|
+
const subagentRequestedRecordId = (runId, toolCallId) => decodeRecordId(`subagent-requested:${runId}:${toolCallId}`);
|
|
258
|
+
/** Deterministic batch identity of one `SubagentRequested` append (same string). */
|
|
259
|
+
const subagentRequestedBatchId = (runId, toolCallId) => decodeBatchId(`subagent-requested:${runId}:${toolCallId}`);
|
|
260
|
+
/**
|
|
261
|
+
* Deterministic canonical record identity of one parent Tool Call's `SubagentStarted` record.
|
|
262
|
+
* Recovery's start-link repair appends the EXACT same record
|
|
263
|
+
* under this identity, so a raced repair replays instead of duplicating (SUB-016/SUB-017).
|
|
264
|
+
*/
|
|
265
|
+
const subagentStartedRecordId = (runId, toolCallId) => decodeRecordId(`subagent-started:${runId}:${toolCallId}`);
|
|
266
|
+
/** Deterministic batch identity of one `SubagentStarted` append (same string). */
|
|
267
|
+
const subagentStartedBatchId = (runId, toolCallId) => decodeBatchId(`subagent-started:${runId}:${toolCallId}`);
|
|
268
|
+
/**
|
|
269
|
+
* Deterministic batch identity of one parent Tool Call's atomic settlement join: the
|
|
270
|
+
* `SubagentJoined` record plus the parent's `ToolCallSettled` record (its existing
|
|
271
|
+
* `tool-settled:{runId}:{turn}:{toolCallId}` identity) commit as ONE canonical batch (SUB-019).
|
|
272
|
+
*/
|
|
273
|
+
const subagentJoinBatchId = (runId, toolCallId) => decodeBatchId(`subagent-join:${runId}:${toolCallId}`);
|
|
274
|
+
/** Deterministic canonical record identity of one parent Tool Call's `SubagentJoined` record. */
|
|
275
|
+
const subagentJoinedRecordId = (runId, toolCallId) => decodeRecordId(`subagent-joined:${runId}:${toolCallId}`);
|
|
276
|
+
/**
|
|
277
|
+
* Deterministic identity of one child Thread's `SubagentLineageRecorded` record.
|
|
278
|
+
* Its own single-record batch reuses the same string so the generic
|
|
279
|
+
* `thread-created:{cid}` batch identity is never contradicted.
|
|
280
|
+
*/
|
|
281
|
+
const subagentLineageRecordId = (threadId) => decodeRecordId(`subagent-lineage:${threadId}`);
|
|
282
|
+
/** Deterministic batch identity of one `SubagentLineageRecorded` append (same string). */
|
|
283
|
+
const subagentLineageBatchId = (threadId) => decodeBatchId(`subagent-lineage:${threadId}`);
|
|
284
|
+
/**
|
|
285
|
+
* Deterministic intended child Thread identity: the
|
|
286
|
+
* parent Submission and Tool Call pair addresses exactly one child Thread, so a replayed
|
|
287
|
+
* establishment converges on the one existing child (SUB-016).
|
|
288
|
+
*/
|
|
289
|
+
const childThreadIdFor = (parentSubmissionId, toolCallId) => decodeThreadId(`subagent:${parentSubmissionId}:${toolCallId}`);
|
|
290
|
+
/**
|
|
291
|
+
* Deterministic child admission idempotency key: scoped to
|
|
292
|
+
* the parent Run and Tool Call identity, so duplicate admission attempts resolve through the
|
|
293
|
+
* ledger's idempotency contract to one child Receipt (SUB-016, SUB-031). The ledger key is
|
|
294
|
+
* bounded (256); coordinator-minted Run and Tool Call identities stay far below that bound.
|
|
295
|
+
*/
|
|
296
|
+
const childIdempotencyKeyFor = (parentRunId, toolCallId) => decodeIdempotencyKey(`subagent:${parentRunId}:${toolCallId}`);
|
|
297
|
+
const decodePromptMessages = Effect.fn("RunJournal.decodePromptMessages")((messages) => Schema.decodeUnknownEffect(Prompt.Prompt)(messages).pipe(Effect.mapError((cause) => journalError("Canonical messages are not Schema-encoded Prompt messages", cause))));
|
|
298
|
+
const toolMessageFromSettled = Effect.fn("RunJournal.toolMessageFromSettled")((settled) => Effect.try({
|
|
299
|
+
try: () => Prompt.makeMessage("tool", { content: settled.map(({ record, cleared }) => Prompt.makePart("tool-result", {
|
|
300
|
+
id: record.toolCallId,
|
|
301
|
+
name: record.toolName,
|
|
302
|
+
result: cleared ? CLEARED_TOOL_RESULT : record.result,
|
|
303
|
+
isFailure: record.isFailure,
|
|
304
|
+
providerExecuted: false
|
|
305
|
+
})) }),
|
|
306
|
+
catch: (cause) => journalError("Unable to rebuild Tool message from ToolCallSettled", cause)
|
|
307
|
+
}));
|
|
308
|
+
const projectedResponseUsage = (response) => Effect.gen(function* () {
|
|
309
|
+
const calls = response.modelUsage;
|
|
310
|
+
if (calls === void 0) return {
|
|
311
|
+
modelCalls: 1,
|
|
312
|
+
inputTokens: response.inputTokens ?? 0,
|
|
313
|
+
outputTokens: response.outputTokens ?? 0,
|
|
314
|
+
costMicrousd: response.costMicrousd ?? 0,
|
|
315
|
+
modelUsage: []
|
|
316
|
+
};
|
|
317
|
+
if (calls.length === 0) return yield* journalError("A canonical modelUsage list must not be empty");
|
|
318
|
+
const summary = yield* summarizeModelUsage(calls).pipe(Effect.mapError((cause) => journalError("Canonical model usage exceeds accounting bounds", cause)));
|
|
319
|
+
if (response.inputTokens !== void 0 && response.inputTokens !== summary.inputTokens.total || response.outputTokens !== void 0 && response.outputTokens !== summary.outputTokens.total || response.costMicrousd !== void 0 && response.costMicrousd !== summary.costMicrousd) return yield* journalError("Canonical detailed and aggregate model usage disagree");
|
|
320
|
+
return {
|
|
321
|
+
modelCalls: summary.modelCalls,
|
|
322
|
+
inputTokens: summary.inputTokens.total,
|
|
323
|
+
outputTokens: summary.outputTokens.total,
|
|
324
|
+
costMicrousd: summary.costMicrousd,
|
|
325
|
+
modelUsage: calls
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
const addProjectedUsage = (field, left, right) => Schema.decodeEffect(Schema.Natural)(left + right).pipe(Effect.mapError((cause) => journalError(`Canonical projected usage exceeds safe-integer bounds at ${field}`, cause)));
|
|
329
|
+
const decodeToolCallId = Schema.decodeSync(ToolCallId);
|
|
330
|
+
const declaredApplicationToolCallIds = (prompt) => {
|
|
331
|
+
const ids = [];
|
|
332
|
+
for (const message of prompt.content) {
|
|
333
|
+
if (message.role !== "assistant") continue;
|
|
334
|
+
for (const part of message.content) if (part.type === "tool-call" && !part.providerExecuted) ids.push(part.id);
|
|
335
|
+
}
|
|
336
|
+
return ids;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Phase 5 audit tags that are prompt-transparent: they carry durability evidence (preparation,
|
|
340
|
+
* unknown marking, resolution, Step results, approvals, interruption) but contribute nothing to
|
|
341
|
+
* the model-visible Prompt, and — unlike the P4 tags — they do NOT split a contiguous
|
|
342
|
+
* `ToolCallSettled` group into separate Tool messages, so a late-settled call's audit records
|
|
343
|
+
* cannot change the replayed prompt shape.
|
|
344
|
+
*
|
|
345
|
+
* The four S2 Subagent lifecycle tags are prompt-transparent for the same reason (spec §5/§11):
|
|
346
|
+
* the parent prompt never carries child transcript or establishment evidence — the joined child
|
|
347
|
+
* result reaches the model exclusively through the paired `ToolCallSettled` record, and the
|
|
348
|
+
* child-log lineage record is not model input.
|
|
349
|
+
*/
|
|
350
|
+
const PROMPT_TRANSPARENT_TAGS = /* @__PURE__ */ new Set([
|
|
351
|
+
"RunPolicyUsageReserved",
|
|
352
|
+
"RunStarted",
|
|
353
|
+
"RunDurationExhausted",
|
|
354
|
+
"ToolCallPrepared",
|
|
355
|
+
"ToolCallUnknown",
|
|
356
|
+
"ToolCallResolved",
|
|
357
|
+
"ToolStepSettled",
|
|
358
|
+
"ToolApprovalRequested",
|
|
359
|
+
"ToolApprovalDecided",
|
|
360
|
+
"ModelResponseInterrupted",
|
|
361
|
+
"SubagentRequested",
|
|
362
|
+
"SubagentStarted",
|
|
363
|
+
"SubagentJoined",
|
|
364
|
+
"SubagentLineageRecorded",
|
|
365
|
+
"WorkerInputRequested",
|
|
366
|
+
"WorkerOriginRecorded",
|
|
367
|
+
"WorkerInputCompleted",
|
|
368
|
+
"WorkerReportPrepared",
|
|
369
|
+
"AgentUpdateEmitted",
|
|
370
|
+
"WorkerReportRefused",
|
|
371
|
+
"PeerMessagePrepared",
|
|
372
|
+
"SubtreeBudgetReserved"
|
|
373
|
+
]);
|
|
374
|
+
/**
|
|
375
|
+
* Reconstruct a fixed canonical prefix from a re-readable stream. The caller must keep the same
|
|
376
|
+
* records visible on every traversal. The first collects compaction and settlement metadata;
|
|
377
|
+
* rollovers additionally validate covered Tool batches before rebuilding Prompt and usage. Metadata and the
|
|
378
|
+
* live Prompt remain resident; covered historical message/tool payloads do not. An uncompacted Prompt still grows
|
|
379
|
+
* with its conversation, so hosts must configure an appropriate context compaction policy.
|
|
380
|
+
* Prepared metadata must describe exactly this stream and seed through the same fixed tail;
|
|
381
|
+
* it skips only the metadata scan, never covered-Tool validation or the canonical fold.
|
|
382
|
+
* @internal
|
|
383
|
+
*/
|
|
384
|
+
const projectRunJournalStream = Effect.fn("RunJournal.projectRunJournalStream")(function* (records, ownerRunId, onBoundary, seed, preparedMetadata) {
|
|
385
|
+
if (seed !== void 0 && seed.runId !== ownerRunId) return yield* journalError("Recovery checkpoint belongs to another Run");
|
|
386
|
+
let state = {
|
|
387
|
+
all: [],
|
|
388
|
+
before: [],
|
|
389
|
+
pendingTools: [],
|
|
390
|
+
pendingToolsForRun: false,
|
|
391
|
+
committedTurns: seed?.committedTurns ?? 0
|
|
392
|
+
};
|
|
393
|
+
if (preparedMetadata !== void 0 && (preparedMetadata.ownerRunId !== ownerRunId || preparedMetadata.seed !== seed)) return yield* journalError("Prepared journal metadata belongs to another replay");
|
|
394
|
+
let metadata = preparedMetadata;
|
|
395
|
+
if (metadata === void 0) {
|
|
396
|
+
const collected = makeJournalMetadata(ownerRunId, seed);
|
|
397
|
+
yield* Stream.runForEach(records, (envelope) => Effect.sync(() => collected.add(envelope)));
|
|
398
|
+
metadata = collected.snapshot();
|
|
399
|
+
}
|
|
400
|
+
const { firstSequenceByRun, lastResponseSequenceByRun, terminalSequenceByRun, settledSpans, toolExecutionEvidence, settledToolCallRecordIds, settledById, compactions } = metadata;
|
|
401
|
+
const settledCoverage = compactions.reduce((through, { payload }) => payload.kind !== "summarize" ? Math.max(through, payload.coversThrough) : through, 0);
|
|
402
|
+
const isTerminalPriorRun = (candidateRunId, compactionRunId, beforeSequence) => {
|
|
403
|
+
const terminal = terminalSequenceByRun.get(candidateRunId);
|
|
404
|
+
return candidateRunId !== compactionRunId && terminal !== void 0 && terminal < beforeSequence && terminal > (lastResponseSequenceByRun.get(candidateRunId) ?? 0);
|
|
405
|
+
};
|
|
406
|
+
const incompleteResponseSequences = [];
|
|
407
|
+
let ownerPrefixSequence = seed?.firstSequence ?? Number.POSITIVE_INFINITY;
|
|
408
|
+
let protectedContext = seed?.protectedContext === void 0 ? void 0 : yield* decodePromptMessages(seed.protectedContext);
|
|
409
|
+
if (settledCoverage > 0) yield* Stream.runForEach(records, (envelope) => Effect.gen(function* () {
|
|
410
|
+
const payload = envelope.record.payload;
|
|
411
|
+
if (payload._tag !== "ModelResponseRecorded" || envelope.sequence > settledCoverage) return;
|
|
412
|
+
const messages = yield* decodePromptMessages(payload.messages);
|
|
413
|
+
const declared = declaredApplicationToolCallIds(messages);
|
|
414
|
+
for (const id of declared) {
|
|
415
|
+
const callId = yield* Schema.decodeEffect(ToolCallId)(id).pipe(Effect.mapError((cause) => journalError("Failed to decode a declared Tool Call ID", cause)));
|
|
416
|
+
if (!settledToolCallRecordIds.has(toolCallSettledRecordId(payload.runId, payload.turn, callId))) {
|
|
417
|
+
incompleteResponseSequences.push({
|
|
418
|
+
sequence: envelope.sequence,
|
|
419
|
+
runId: payload.runId
|
|
420
|
+
});
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (payload.runId === ownerRunId && payload.turn === 1 && payload.runScopedPrefixLength !== void 0) {
|
|
425
|
+
ownerPrefixSequence = envelope.sequence;
|
|
426
|
+
protectedContext = Prompt.fromMessages(messages.content.slice(0, payload.runScopedPrefixLength));
|
|
427
|
+
}
|
|
428
|
+
}));
|
|
429
|
+
const boundIsValid = (payload, ownSequence) => {
|
|
430
|
+
const { runId, coversThrough } = payload;
|
|
431
|
+
if (coversThrough <= 0 || coversThrough >= ownSequence) return false;
|
|
432
|
+
if (seed !== void 0 && ownSequence === seed.compaction.sequence) return seed.compaction.record.payload._tag === "CompactionCreated" && Schema.toEquivalence(CompactionCreated)(payload, seed.compaction.record.payload);
|
|
433
|
+
const ownerFirst = firstSequenceByRun.get(runId);
|
|
434
|
+
if (payload.kind === "summarize" && ownerFirst !== void 0 && coversThrough >= ownerFirst) return false;
|
|
435
|
+
if (payload.kind !== "summarize" && incompleteResponseSequences.some((response) => response.sequence <= coversThrough && !isTerminalPriorRun(response.runId, runId, ownSequence))) return false;
|
|
436
|
+
for (const span of settledSpans) if (span.from <= coversThrough && coversThrough < span.to) return false;
|
|
437
|
+
return true;
|
|
438
|
+
};
|
|
439
|
+
let summarizeBound = 0;
|
|
440
|
+
let replacement;
|
|
441
|
+
let summarizeSequence = -1;
|
|
442
|
+
let clearBound = 0;
|
|
443
|
+
let latestWindowId = seed?.contextWindowId;
|
|
444
|
+
let latestWindowSequence = seed?.throughSequence ?? -1;
|
|
445
|
+
let rolloverCoveredThrough = 0;
|
|
446
|
+
for (const { payload, sequence } of compactions) {
|
|
447
|
+
if (!boundIsValid(payload, sequence)) continue;
|
|
448
|
+
if (payload.kind === "rollover" && sequence > latestWindowSequence) {
|
|
449
|
+
latestWindowId = contextWindowId(payload.runId, payload.turn);
|
|
450
|
+
latestWindowSequence = sequence;
|
|
451
|
+
}
|
|
452
|
+
if (payload.kind === "rollover") rolloverCoveredThrough = Math.max(rolloverCoveredThrough, payload.coversThrough);
|
|
453
|
+
if (payload.kind === "summarize" || payload.kind === "rollover") {
|
|
454
|
+
if (payload.kind === "summarize" && payload.summary === void 0) continue;
|
|
455
|
+
if (payload.coversThrough > summarizeBound || payload.coversThrough === summarizeBound && sequence > summarizeSequence) {
|
|
456
|
+
summarizeBound = payload.coversThrough;
|
|
457
|
+
summarizeSequence = sequence;
|
|
458
|
+
replacement = payload;
|
|
459
|
+
}
|
|
460
|
+
} else if (payload.coversThrough > clearBound) clearBound = payload.coversThrough;
|
|
461
|
+
}
|
|
462
|
+
let summaryEmitted = false;
|
|
463
|
+
const retainedPrefix = replacement?.kind === "rollover" && replacement.runId === ownerRunId && ownerPrefixSequence <= summarizeBound ? protectedContext?.content ?? [] : [];
|
|
464
|
+
const replacementLength = replacement === void 0 ? 0 : retainedPrefix.length + 1;
|
|
465
|
+
if (seed?.frontier !== void 0) onBoundary?.({
|
|
466
|
+
...seed.frontier,
|
|
467
|
+
promptLength: replacementLength
|
|
468
|
+
});
|
|
469
|
+
const emitSummary = () => {
|
|
470
|
+
if (summaryEmitted || replacement === void 0) return;
|
|
471
|
+
summaryEmitted = true;
|
|
472
|
+
const message = replacement.kind === "rollover" ? contextWindowMessage(contextWindowId(replacement.runId, replacement.turn), replacement.handoff) : Prompt.makeMessage("user", { content: [Prompt.makePart("text", { text: `${COMPACTION_SUMMARY_PREFIX}${replacement.summary}` })] });
|
|
473
|
+
state.all.push(...retainedPrefix, message);
|
|
474
|
+
if (replacement.kind !== "rollover" || replacement.runId !== ownerRunId) state.before.push(message);
|
|
475
|
+
};
|
|
476
|
+
const modelUsage = [];
|
|
477
|
+
let unobservedModelCalls = seed?.unobservedModelCalls ?? 0;
|
|
478
|
+
const usage = {
|
|
479
|
+
modelCalls: seed?.modelCalls ?? 0,
|
|
480
|
+
inputTokens: seed?.inputTokens ?? 0,
|
|
481
|
+
outputTokens: seed?.outputTokens ?? 0,
|
|
482
|
+
lastInputTokens: seed?.lastInputTokens ?? 0,
|
|
483
|
+
lastOutputTokens: seed?.lastOutputTokens ?? 0,
|
|
484
|
+
costMicrousd: seed?.costMicrousd ?? 0,
|
|
485
|
+
modelUsage,
|
|
486
|
+
...seed === void 0 ? {} : { summarizedModelUsage: seed.summarizedModelUsage }
|
|
487
|
+
};
|
|
488
|
+
let toolSelection = seed?.toolSelection;
|
|
489
|
+
let usageTurn = seed?.committedTurns ?? 0;
|
|
490
|
+
const incompleteToolTurns = /* @__PURE__ */ new Set();
|
|
491
|
+
const incompleteToolCalls = /* @__PURE__ */ new Set();
|
|
492
|
+
let pendingContextToolCallId;
|
|
493
|
+
let ownerTerminated = false;
|
|
494
|
+
const policyUsage = {
|
|
495
|
+
committedTurns: seed?.policyUsage.committedTurns ?? 0,
|
|
496
|
+
toolCalls: seed?.policyUsage.toolCalls ?? 0,
|
|
497
|
+
programmaticToolCalls: seed?.policyUsage.programmaticToolCalls ?? 0,
|
|
498
|
+
consecutiveToolFailures: seed?.policyUsage.consecutiveToolFailures ?? 0,
|
|
499
|
+
finalizationUsed: seed?.policyUsage.finalizationUsed ?? false
|
|
500
|
+
};
|
|
501
|
+
const accountResponse = Effect.fn("RunJournal.accountResponse")(function* (envelope, payload, messages) {
|
|
502
|
+
const record = envelope.record;
|
|
503
|
+
const declared = declaredApplicationToolCallIds(messages);
|
|
504
|
+
const declaredRecordIds = [];
|
|
505
|
+
for (const id of declared) {
|
|
506
|
+
const toolCallId = yield* Effect.try({
|
|
507
|
+
try: () => decodeToolCallId(id),
|
|
508
|
+
catch: (cause) => journalError("Failed to decode a declared Tool Call ID", cause)
|
|
509
|
+
});
|
|
510
|
+
declaredRecordIds.push(toolCallSettledRecordId(payload.runId, payload.turn, toolCallId));
|
|
511
|
+
}
|
|
512
|
+
if (declaredRecordIds.some((recordId) => !settledToolCallRecordIds.has(recordId))) {
|
|
513
|
+
incompleteToolTurns.add(envelope.record.recordId);
|
|
514
|
+
for (const recordId of declaredRecordIds) incompleteToolCalls.add(recordId);
|
|
515
|
+
}
|
|
516
|
+
if (payload.runId !== ownerRunId) return;
|
|
517
|
+
if (seed !== void 0 && envelope.sequence <= seed.throughSequence) return;
|
|
518
|
+
if (payload.turn === 1 && payload.runScopedPrefixLength !== void 0) protectedContext = Prompt.fromMessages(messages.content.slice(0, payload.runScopedPrefixLength));
|
|
519
|
+
const responseUsage = yield* projectedResponseUsage(payload);
|
|
520
|
+
unobservedModelCalls = yield* addProjectedUsage("unobservedModelCalls", unobservedModelCalls, payload.unobservedModelCalls ?? 0);
|
|
521
|
+
usage.modelCalls = yield* addProjectedUsage("modelCalls", usage.modelCalls, responseUsage.modelCalls);
|
|
522
|
+
usage.inputTokens = yield* addProjectedUsage("inputTokens", usage.inputTokens, responseUsage.inputTokens);
|
|
523
|
+
usage.outputTokens = yield* addProjectedUsage("outputTokens", usage.outputTokens, responseUsage.outputTokens);
|
|
524
|
+
usage.costMicrousd = yield* addProjectedUsage("costMicrousd", usage.costMicrousd, responseUsage.costMicrousd);
|
|
525
|
+
usage.modelUsage.push(...responseUsage.modelUsage);
|
|
526
|
+
if (payload.turn > usageTurn) {
|
|
527
|
+
usageTurn = payload.turn;
|
|
528
|
+
usage.lastInputTokens = responseUsage.inputTokens;
|
|
529
|
+
usage.lastOutputTokens = responseUsage.outputTokens;
|
|
530
|
+
}
|
|
531
|
+
policyUsage.committedTurns = Math.max(policyUsage.committedTurns, payload.turn);
|
|
532
|
+
const calls = messages.content.flatMap((message) => message.role === "assistant" ? message.content.filter((part) => part.type === "tool-call") : []);
|
|
533
|
+
const candidate = calls.length === 1 ? calls[0] : void 0;
|
|
534
|
+
const candidateResult = candidate === void 0 ? void 0 : settledById.get(`tool-settled:${ownerRunId}:${payload.turn}:${candidate.id}`);
|
|
535
|
+
pendingContextToolCallId = candidate !== void 0 && !candidate.providerExecuted && candidateResult?.isFailure === false && candidateResult.budgetRejected !== true && envelope.sequence > rolloverCoveredThrough ? candidate.id : void 0;
|
|
536
|
+
policyUsage.toolCalls += calls.length;
|
|
537
|
+
if (payload.toolExposure !== void 0) toolSelection = payload.toolExposure.selection;
|
|
538
|
+
if (incompleteToolTurns.has(record.recordId)) return;
|
|
539
|
+
for (const call of calls) {
|
|
540
|
+
const result = call.providerExecuted ? messages.content.flatMap((message) => message.role === "assistant" ? message.content : []).find((part) => part.type === "tool-result" && part.providerExecuted && part.id === call.id) : settledById.get(`tool-settled:${ownerRunId}:${payload.turn}:${call.id}`);
|
|
541
|
+
if (result === void 0 || "budgetRejected" in result && result.budgetRejected === true) continue;
|
|
542
|
+
if (!("isFailure" in result)) continue;
|
|
543
|
+
if (!result.isFailure && "toolSelection" in result && result.toolSelection !== void 0) toolSelection = result.toolSelection;
|
|
544
|
+
policyUsage.consecutiveToolFailures = result.isFailure ? policyUsage.consecutiveToolFailures + 1 : 0;
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
const historicalResults = /* @__PURE__ */ new Map();
|
|
548
|
+
let pendingToolOrder = /* @__PURE__ */ new Map();
|
|
549
|
+
const flushTools = Effect.fn("RunJournal.flushTools")(function* (current) {
|
|
550
|
+
if (current.pendingTools.length === 0) return current;
|
|
551
|
+
const ordered = current.pendingTools.toSorted((left, right) => (pendingToolOrder.get(left.record.toolCallId) ?? Number.MAX_SAFE_INTEGER) - (pendingToolOrder.get(right.record.toolCallId) ?? Number.MAX_SAFE_INTEGER));
|
|
552
|
+
const toolMessage = yield* toolMessageFromSettled(ordered);
|
|
553
|
+
current.all.push(toolMessage);
|
|
554
|
+
if (!current.pendingToolsForRun) current.before.push(toolMessage);
|
|
555
|
+
return {
|
|
556
|
+
...current,
|
|
557
|
+
pendingTools: [],
|
|
558
|
+
pendingToolsForRun: false
|
|
559
|
+
};
|
|
560
|
+
});
|
|
561
|
+
yield* Stream.runForEach(records, (envelope) => Effect.gen(function* () {
|
|
562
|
+
const payload = envelope.record.payload;
|
|
563
|
+
if ((payload._tag === "RunCompleted" || payload._tag === "RunFailed") && payload.runId === ownerRunId || payload._tag === "SubmissionSettled" && runIdForSubmission(payload.submissionId) === ownerRunId) ownerTerminated = true;
|
|
564
|
+
if (payload._tag === "RunPolicyUsageReserved" && payload.runId === ownerRunId) {
|
|
565
|
+
if (seed !== void 0 && envelope.sequence <= seed.throughSequence) return;
|
|
566
|
+
if (payload.programmaticToolCalls < policyUsage.programmaticToolCalls || policyUsage.finalizationUsed && !payload.finalizationUsed) return yield* journalError("Run policy reservations must be monotonic");
|
|
567
|
+
policyUsage.programmaticToolCalls = payload.programmaticToolCalls;
|
|
568
|
+
policyUsage.finalizationUsed = payload.finalizationUsed;
|
|
569
|
+
}
|
|
570
|
+
if (PROMPT_TRANSPARENT_TAGS.has(payload._tag)) return;
|
|
571
|
+
if (payload._tag === "CompactionCreated") return;
|
|
572
|
+
if (seed !== void 0 && envelope.sequence <= seed.throughSequence && (payload._tag === "ModelResponseRecorded" || payload._tag === "ToolCallSettled")) return;
|
|
573
|
+
if (envelope.sequence <= summarizeBound) {
|
|
574
|
+
if (payload._tag === "ModelResponseRecorded" && payload.runId === ownerRunId) {
|
|
575
|
+
const messages = yield* decodePromptMessages(payload.messages);
|
|
576
|
+
yield* accountResponse(envelope, payload, messages);
|
|
577
|
+
state = {
|
|
578
|
+
...state,
|
|
579
|
+
committedTurns: Math.max(state.committedTurns, payload.turn)
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
if (payload._tag === "ModelResponseRecorded" || payload._tag === "ToolCallSettled") onBoundary?.({
|
|
583
|
+
sequence: envelope.sequence,
|
|
584
|
+
tag: payload._tag,
|
|
585
|
+
promptLength: replacementLength,
|
|
586
|
+
...isTerminalPriorRun(payload.runId, ownerRunId, Number.POSITIVE_INFINITY) ? { terminalPriorRun: true } : {},
|
|
587
|
+
...incompleteToolTurns.has(envelope.record.recordId) || incompleteToolCalls.has(envelope.record.recordId) ? { incomplete: true } : {}
|
|
588
|
+
});
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
emitSummary();
|
|
592
|
+
if (payload._tag === "ToolCallSettled") {
|
|
593
|
+
if (payload.runId !== ownerRunId) {
|
|
594
|
+
const slot = historicalResults.get(envelope.record.recordId);
|
|
595
|
+
if (slot === void 0) return yield* journalError("Historical Tool result has no matching declaration");
|
|
596
|
+
const declared = slot.parts[slot.partIndex];
|
|
597
|
+
if (declared?.id !== payload.toolCallId || declared.name !== payload.toolName) return yield* journalError("Historical Tool result differs from its declaration");
|
|
598
|
+
slot.parts[slot.partIndex] = Prompt.makePart("tool-result", {
|
|
599
|
+
id: payload.toolCallId,
|
|
600
|
+
name: payload.toolName,
|
|
601
|
+
result: envelope.sequence <= clearBound ? CLEARED_TOOL_RESULT : payload.result,
|
|
602
|
+
isFailure: payload.isFailure,
|
|
603
|
+
providerExecuted: false
|
|
604
|
+
});
|
|
605
|
+
const message = Prompt.makeMessage("tool", { content: [...slot.parts] });
|
|
606
|
+
state.all[slot.allIndex] = message;
|
|
607
|
+
state.before[slot.beforeIndex] = message;
|
|
608
|
+
historicalResults.delete(envelope.record.recordId);
|
|
609
|
+
onBoundary?.({
|
|
610
|
+
sequence: envelope.sequence,
|
|
611
|
+
tag: payload._tag,
|
|
612
|
+
promptLength: state.all.length,
|
|
613
|
+
...incompleteToolCalls.has(envelope.record.recordId) ? { incomplete: true } : {},
|
|
614
|
+
...isTerminalPriorRun(payload.runId, ownerRunId, Number.POSITIVE_INFINITY) ? { terminalPriorRun: true } : {}
|
|
615
|
+
});
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (state.pendingTools.length > 0 && state.pendingToolsForRun !== (payload.runId === ownerRunId)) state = yield* flushTools(state);
|
|
619
|
+
state.pendingTools.push({
|
|
620
|
+
record: payload,
|
|
621
|
+
cleared: envelope.sequence <= clearBound
|
|
622
|
+
});
|
|
623
|
+
state = {
|
|
624
|
+
...state,
|
|
625
|
+
pendingToolsForRun: payload.runId === ownerRunId
|
|
626
|
+
};
|
|
627
|
+
onBoundary?.({
|
|
628
|
+
sequence: envelope.sequence,
|
|
629
|
+
tag: payload._tag,
|
|
630
|
+
promptLength: state.all.length + 1,
|
|
631
|
+
...isTerminalPriorRun(payload.runId, ownerRunId, Number.POSITIVE_INFINITY) ? { terminalPriorRun: true } : {},
|
|
632
|
+
...incompleteToolCalls.has(envelope.record.recordId) ? { incomplete: true } : {}
|
|
633
|
+
});
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
state = yield* flushTools(state);
|
|
637
|
+
if (payload._tag === "ModelCompleted" && payload.messages !== void 0) {
|
|
638
|
+
const messages = yield* decodePromptMessages(payload.messages);
|
|
639
|
+
for (const message of messages.content) {
|
|
640
|
+
state.all.push(message);
|
|
641
|
+
if (payload.runId !== ownerRunId) state.before.push(message);
|
|
642
|
+
}
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (payload._tag !== "ModelResponseRecorded") return;
|
|
646
|
+
const messages = yield* decodePromptMessages(payload.messages);
|
|
647
|
+
const forRun = payload.runId === ownerRunId;
|
|
648
|
+
pendingToolOrder = new Map(declaredApplicationToolCallIds(messages).map((id, index) => [id, index]));
|
|
649
|
+
yield* accountResponse(envelope, payload, messages);
|
|
650
|
+
const visibleMessages = forRun ? messages.content : messages.content.filter((message) => message.role !== "system");
|
|
651
|
+
for (const message of visibleMessages) {
|
|
652
|
+
state.all.push(message);
|
|
653
|
+
if (!forRun) state.before.push(message);
|
|
654
|
+
}
|
|
655
|
+
if (!forRun) {
|
|
656
|
+
const calls = messages.content.flatMap((message) => message.role === "assistant" ? message.content.filter((part) => part.type === "tool-call" && !part.providerExecuted) : []);
|
|
657
|
+
if (calls.length > 0) {
|
|
658
|
+
const parts = yield* Effect.forEach(calls, (call) => Effect.gen(function* () {
|
|
659
|
+
const callId = yield* Schema.decodeEffect(ToolCallId)(call.id).pipe(Effect.mapError((cause) => journalError("Invalid historical Tool Call ID", cause)));
|
|
660
|
+
const operation = payload.toolOperations?.find((operation) => operation.toolCallId === callId && operation.toolName === call.name);
|
|
661
|
+
const notExecuted = operation !== void 0 && (operation.executionClass !== "readonly" || operation.executionKind !== "ordinary") && !toolExecutionEvidence.has(toolExecutionKey({
|
|
662
|
+
runId: payload.runId,
|
|
663
|
+
turn: payload.turn,
|
|
664
|
+
toolCallId: callId
|
|
665
|
+
}));
|
|
666
|
+
return Prompt.makePart("tool-result", {
|
|
667
|
+
id: call.id,
|
|
668
|
+
name: call.name,
|
|
669
|
+
result: notExecuted ? {
|
|
670
|
+
_tag: "ToolUnavailable",
|
|
671
|
+
toolName: call.name,
|
|
672
|
+
execution: "not-executed",
|
|
673
|
+
message: "This earlier call never reached durable preparation and was not executed."
|
|
674
|
+
} : {
|
|
675
|
+
_tag: "ToolOutcomeUnknown",
|
|
676
|
+
message: "This earlier operation has no recorded outcome. It may have executed. Do not assume success or retry it; its original operation remains unresolved."
|
|
677
|
+
},
|
|
678
|
+
isFailure: true,
|
|
679
|
+
providerExecuted: false
|
|
680
|
+
});
|
|
681
|
+
}));
|
|
682
|
+
const allIndex = state.all.length;
|
|
683
|
+
const beforeIndex = state.before.length;
|
|
684
|
+
const message = Prompt.makeMessage("tool", { content: parts });
|
|
685
|
+
state.all.push(message);
|
|
686
|
+
state.before.push(message);
|
|
687
|
+
for (const [partIndex, call] of calls.entries()) {
|
|
688
|
+
const callId = yield* Schema.decodeEffect(ToolCallId)(call.id).pipe(Effect.mapError((cause) => journalError("Invalid historical Tool Call ID", cause)));
|
|
689
|
+
historicalResults.set(toolCallSettledRecordId(payload.runId, payload.turn, callId), {
|
|
690
|
+
allIndex,
|
|
691
|
+
beforeIndex,
|
|
692
|
+
parts,
|
|
693
|
+
partIndex
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
state = {
|
|
699
|
+
...state,
|
|
700
|
+
committedTurns: forRun ? Math.max(state.committedTurns, payload.turn) : state.committedTurns
|
|
701
|
+
};
|
|
702
|
+
onBoundary?.({
|
|
703
|
+
sequence: envelope.sequence,
|
|
704
|
+
tag: payload._tag,
|
|
705
|
+
promptLength: state.all.length,
|
|
706
|
+
...isTerminalPriorRun(payload.runId, ownerRunId, Number.POSITIVE_INFINITY) ? { terminalPriorRun: true } : {},
|
|
707
|
+
...incompleteToolTurns.has(envelope.record.recordId) ? { incomplete: true } : {}
|
|
708
|
+
});
|
|
709
|
+
}));
|
|
710
|
+
emitSummary();
|
|
711
|
+
state = yield* flushTools(state);
|
|
712
|
+
const validatedPolicyUsage = yield* Schema.decodeEffect(RunPolicyUsage)(policyUsage).pipe(Effect.mapError((cause) => journalError("Run policy accounting exceeds its Schema bounds", cause)));
|
|
713
|
+
return {
|
|
714
|
+
...toolSelection === void 0 ? {} : { toolSelection },
|
|
715
|
+
policyUsage: validatedPolicyUsage,
|
|
716
|
+
prompt: Prompt.fromMessages(state.all),
|
|
717
|
+
historyBefore: Prompt.fromMessages(state.before),
|
|
718
|
+
committedTurns: state.committedTurns,
|
|
719
|
+
usage: unobservedModelCalls === 0 ? usage : {
|
|
720
|
+
...usage,
|
|
721
|
+
unobservedModelCalls
|
|
722
|
+
},
|
|
723
|
+
...latestWindowId === void 0 ? {} : { contextWindowId: latestWindowId },
|
|
724
|
+
...protectedContext === void 0 ? {} : { protectedContext },
|
|
725
|
+
...ownerTerminated || pendingContextToolCallId === void 0 ? {} : { pendingContextToolCallId }
|
|
726
|
+
};
|
|
727
|
+
});
|
|
728
|
+
/** Pure projection of one Run's durable recovery state from canonical records. */
|
|
729
|
+
const projectRunJournal = Effect.fn("RunJournal.projectRunJournal")((records, runId) => projectRunJournalStream(Stream.fromIterable(records), runId));
|
|
730
|
+
/**
|
|
731
|
+
* Pure valid-prompt projection from canonical records: `UserInputRecorded` +
|
|
732
|
+
* `ModelResponseRecorded` + complete `ToolCallSettled` batches → the deterministic model-visible
|
|
733
|
+
* Prompt (plan §Coordinator flow step 3).
|
|
734
|
+
*/
|
|
735
|
+
const promptFromCanonicalRecords = Effect.fn("RunJournal.promptFromCanonicalRecords")((records) => projectRunJournalStream(Stream.fromIterable(records), void 0).pipe(Effect.map((projection) => projection.prompt)));
|
|
736
|
+
/** Everything one committed Turn contributes to its canonical batch. */
|
|
737
|
+
/**
|
|
738
|
+
* Staged usage is validated, never repaired: clamping negatives or truncating
|
|
739
|
+
* fractions would under-record canonical usage, and NaN/Infinity must fail
|
|
740
|
+
* typed instead of escaping as a record-construction defect (RUN-023).
|
|
741
|
+
*/
|
|
742
|
+
const validStagedUsage = (label, value) => Number.isSafeInteger(value) && value >= 0 ? Effect.succeed(value) : Effect.fail(journalError(`Staged ${label} must be a non-negative safe integer, got ${String(value)}`));
|
|
743
|
+
const decodePersistedJson = Schema.decodeUnknownEffect(PersistedJson);
|
|
744
|
+
const encodePrompt = Schema.encodeEffect(Prompt.Prompt);
|
|
745
|
+
const decodeModelUsage = Schema.decodeUnknownEffect(Schema.Array(ModelCallUsage));
|
|
746
|
+
const requireCanonicalTurn = (turn) => !Number.isInteger(turn) || turn <= 0 ? Effect.fail(journalError(`Canonical turn number must be a positive integer: ${turn}`)) : Effect.void;
|
|
747
|
+
const splitTurnMessages = (appended) => {
|
|
748
|
+
const promptMessages = [];
|
|
749
|
+
const toolParts = [];
|
|
750
|
+
for (const message of appended) {
|
|
751
|
+
if (message.role !== "tool") {
|
|
752
|
+
promptMessages.push(message);
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
for (const part of message.content) {
|
|
756
|
+
if (part.type !== "tool-result") continue;
|
|
757
|
+
toolParts.push(part);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
promptMessages,
|
|
762
|
+
toolParts
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
const modelResponseRecord = Effect.fn("RunJournal.modelResponseRecord")(function* (input, promptMessages) {
|
|
766
|
+
if (promptMessages.length === 0) return yield* journalError(`Turn ${input.turn} appended no model-visible Prompt messages`);
|
|
767
|
+
const runScopedPrefixLength = input.runScopedPrefixLength;
|
|
768
|
+
if (runScopedPrefixLength !== void 0 && (input.turn !== 1 || !Number.isSafeInteger(runScopedPrefixLength) || runScopedPrefixLength <= 0 || runScopedPrefixLength >= promptMessages.length || promptMessages.slice(0, runScopedPrefixLength).some((message) => message.role !== "system" && message.role !== "user"))) return yield* journalError("Run-scoped Prompt provenance must identify a non-empty system/user prefix of Turn 1 before its assistant response");
|
|
769
|
+
const encodedMessages = yield* encodePrompt(Prompt.fromMessages([...promptMessages])).pipe(Effect.mapError((cause) => journalError("Turn Prompt messages failed to encode", cause)));
|
|
770
|
+
const messages = yield* decodePersistedJson(encodedMessages).pipe(Effect.mapError((cause) => journalError("Turn Prompt messages exceed canonical persistence bounds", cause)));
|
|
771
|
+
const messagesDigest = yield* digestJson(messages);
|
|
772
|
+
const modelUsage = input.usage?.modelUsage === void 0 ? void 0 : yield* decodeModelUsage(input.usage.modelUsage).pipe(Effect.mapError((cause) => journalError("Turn model usage failed to decode", cause)));
|
|
773
|
+
if (modelUsage !== void 0) {
|
|
774
|
+
if (modelUsage.length === 0) return yield* journalError("Turn model usage must contain at least one completed call");
|
|
775
|
+
const summary = yield* summarizeModelUsage(modelUsage).pipe(Effect.mapError((cause) => journalError("Turn model usage exceeds accounting bounds", cause)));
|
|
776
|
+
if (input.usage === void 0 || input.usage.inputTokens !== summary.inputTokens.total || input.usage.outputTokens !== summary.outputTokens.total || (input.usage.costMicrousd ?? 0) !== summary.costMicrousd) return yield* journalError("Turn detailed and aggregate model usage disagree");
|
|
777
|
+
}
|
|
778
|
+
return RecordEnvelope.make({
|
|
779
|
+
recordId: modelResponseRecordId(input.runId, input.turn),
|
|
780
|
+
family: "thread",
|
|
781
|
+
schemaVersion: 1,
|
|
782
|
+
createdAt: input.createdAt,
|
|
783
|
+
deploymentId: input.deploymentId,
|
|
784
|
+
payload: ModelResponseRecorded.make({
|
|
785
|
+
...input.toolOperations === void 0 ? {} : { toolOperations: input.toolOperations },
|
|
786
|
+
...input.toolParameterRejections === void 0 || input.toolParameterRejections.length === 0 ? {} : { toolParameterRejections: input.toolParameterRejections },
|
|
787
|
+
...input.toolExposure === void 0 ? {} : { toolExposure: input.toolExposure },
|
|
788
|
+
runId: input.runId,
|
|
789
|
+
turnId: input.turnId,
|
|
790
|
+
turn: input.turn,
|
|
791
|
+
messages,
|
|
792
|
+
messagesDigest,
|
|
793
|
+
...runScopedPrefixLength === void 0 ? {} : { runScopedPrefixLength },
|
|
794
|
+
...modelUsage === void 0 ? {} : { modelUsage },
|
|
795
|
+
...input.unobservedModelCalls === void 0 || input.unobservedModelCalls === 0 ? {} : { unobservedModelCalls: yield* validStagedUsage("unobservedModelCalls", input.unobservedModelCalls) },
|
|
796
|
+
...input.usage === void 0 ? {} : {
|
|
797
|
+
inputTokens: yield* validStagedUsage("inputTokens", input.usage.inputTokens),
|
|
798
|
+
outputTokens: yield* validStagedUsage("outputTokens", input.usage.outputTokens),
|
|
799
|
+
...input.usage.costMicrousd === void 0 || input.usage.costMicrousd === 0 ? {} : { costMicrousd: yield* validStagedUsage("costMicrousd", input.usage.costMicrousd) }
|
|
800
|
+
}
|
|
801
|
+
})
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
const toolSettledRecords = Effect.fn("RunJournal.toolSettledRecords")(function* (input, toolParts) {
|
|
805
|
+
const toolRecords = [];
|
|
806
|
+
for (const part of toolParts) {
|
|
807
|
+
const result = yield* decodePersistedJson(part.result).pipe(Effect.mapError((cause) => journalError(`Tool result ${part.id} exceeds canonical persistence bounds`, cause)));
|
|
808
|
+
const toolCallId = yield* Effect.try({
|
|
809
|
+
try: () => decodeToolCallId(part.id),
|
|
810
|
+
catch: (cause) => journalError(`Invalid Tool Call ID ${part.id}`, cause)
|
|
811
|
+
});
|
|
812
|
+
toolRecords.push(RecordEnvelope.make({
|
|
813
|
+
recordId: toolCallSettledRecordId(input.runId, input.turn, toolCallId),
|
|
814
|
+
family: "thread",
|
|
815
|
+
schemaVersion: 1,
|
|
816
|
+
createdAt: input.createdAt,
|
|
817
|
+
deploymentId: input.deploymentId,
|
|
818
|
+
payload: ToolCallSettled.make({
|
|
819
|
+
...input.toolSelections?.get(part.id) === void 0 ? {} : { toolSelection: input.toolSelections.get(part.id) },
|
|
820
|
+
runId: input.runId,
|
|
821
|
+
toolCallId,
|
|
822
|
+
toolName: part.name,
|
|
823
|
+
result,
|
|
824
|
+
isFailure: part.isFailure,
|
|
825
|
+
...input.budgetRejectedCalls?.has(part.id) === true ? { budgetRejected: true } : {}
|
|
826
|
+
})
|
|
827
|
+
}));
|
|
828
|
+
}
|
|
829
|
+
return toolRecords;
|
|
830
|
+
});
|
|
831
|
+
/** Integrity of the original validated terminal values; never a current-code projection. */
|
|
832
|
+
const runCompletionDigest = (completion) => digestJson({
|
|
833
|
+
runId: completion.runId,
|
|
834
|
+
output: completion.output,
|
|
835
|
+
runDisposition: completion.runDisposition ?? null,
|
|
836
|
+
finishReason: completion.finishReason ?? null,
|
|
837
|
+
exhausted: completion.exhausted ?? null
|
|
838
|
+
});
|
|
839
|
+
const runCompletionRecord = Effect.fn("RunJournal.runCompletionRecord")(function* (input) {
|
|
840
|
+
if (input.runCompletion === void 0) return void 0;
|
|
841
|
+
const completion = {
|
|
842
|
+
runId: input.runId,
|
|
843
|
+
...input.runCompletion
|
|
844
|
+
};
|
|
845
|
+
return RecordEnvelope.make({
|
|
846
|
+
recordId: runCompletedRecordId(input.runId),
|
|
847
|
+
family: "thread",
|
|
848
|
+
schemaVersion: 1,
|
|
849
|
+
createdAt: input.createdAt,
|
|
850
|
+
deploymentId: input.deploymentId,
|
|
851
|
+
payload: RunCompleted.make({
|
|
852
|
+
...completion,
|
|
853
|
+
resultDigest: yield* runCompletionDigest(completion)
|
|
854
|
+
})
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
/**
|
|
858
|
+
* Pure per-Turn canonical batch builder (TurnCompleted seam fold, D6/D8): one
|
|
859
|
+
* `ModelResponseRecorded` record plus one `ToolCallSettled` record per terminal Tool result, all
|
|
860
|
+
* under the WP0-style deterministic identities, committed as ONE atomic batch. The same input
|
|
861
|
+
* always yields byte-identical content, so an in-Attempt append retry is an honest batch replay.
|
|
862
|
+
*
|
|
863
|
+
* Phase 5 keeps this shape for Turns that declare no application Tool calls; their terminal
|
|
864
|
+
* `RunCompleted` marker joins the response in this same atomic batch. Tool-declaring Turns split
|
|
865
|
+
* into `turnResponseBatch` + `turnResultsBatch`.
|
|
866
|
+
*/
|
|
867
|
+
const turnCanonicalBatch = Effect.fn("RunJournal.turnCanonicalBatch")(function* (input) {
|
|
868
|
+
yield* requireCanonicalTurn(input.turn);
|
|
869
|
+
const { promptMessages, toolParts } = splitTurnMessages(input.appended);
|
|
870
|
+
const modelResponse = yield* modelResponseRecord(input, promptMessages);
|
|
871
|
+
const toolRecords = yield* toolSettledRecords(input, toolParts);
|
|
872
|
+
const completionRecord = yield* runCompletionRecord(input);
|
|
873
|
+
return CanonicalBatch.make({
|
|
874
|
+
batchId: turnBatchId(input.runId, input.turn),
|
|
875
|
+
producerId: input.producerId,
|
|
876
|
+
records: completionRecord === void 0 ? [modelResponse, ...toolRecords] : [
|
|
877
|
+
modelResponse,
|
|
878
|
+
...toolRecords,
|
|
879
|
+
completionRecord
|
|
880
|
+
]
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
/**
|
|
884
|
+
* Commit 1 of a tool-declaring Turn: the Turn's `ModelResponseRecorded` record, including
|
|
885
|
+
* provider results retained in assistant content before application Tools execute.
|
|
886
|
+
* — pending steering plus the assistant response with its declared tool calls — under batch
|
|
887
|
+
* identity `turn-response:{runId}:{turn}`. Committing the response before preparation creates
|
|
888
|
+
* the provably-safe durability §15 window ("after model item commit, before tool preparation →
|
|
889
|
+
* resume tool scheduling"): a crash there resumes the declared batch with no model re-invocation
|
|
890
|
+
* and no Unknown. Tool messages in `appended` are ignored; the record identity is the same
|
|
891
|
+
* `model-response:{runId}:{turn}` as the single-batch shape, so record-id assertions and the
|
|
892
|
+
* prompt projection are unchanged.
|
|
893
|
+
*/
|
|
894
|
+
const turnResponseBatch = Effect.fn("RunJournal.turnResponseBatch")(function* (input) {
|
|
895
|
+
yield* requireCanonicalTurn(input.turn);
|
|
896
|
+
const { promptMessages } = splitTurnMessages(input.appended);
|
|
897
|
+
const modelResponse = yield* modelResponseRecord(input, promptMessages);
|
|
898
|
+
return CanonicalBatch.make({
|
|
899
|
+
batchId: turnResponseBatchId(input.runId, input.turn),
|
|
900
|
+
producerId: input.producerId,
|
|
901
|
+
records: [modelResponse]
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
/**
|
|
905
|
+
* Commit 5 of a tool-declaring Turn (plan §2.1): the Turn's `ToolCallSettled` records in
|
|
906
|
+
* declaration order under batch identity `turn-results:{runId}:{turn}` — the batch becomes
|
|
907
|
+
* model-visible atomically. Non-tool messages in `appended` are ignored; a Turn without any
|
|
908
|
+
* terminal Tool result has no results batch and fails typed.
|
|
909
|
+
*/
|
|
910
|
+
const turnResultsBatch = Effect.fn("RunJournal.turnResultsBatch")(function* (input) {
|
|
911
|
+
yield* requireCanonicalTurn(input.turn);
|
|
912
|
+
const { toolParts } = splitTurnMessages(input.appended);
|
|
913
|
+
const toolRecords = yield* toolSettledRecords(input, toolParts);
|
|
914
|
+
const first = toolRecords[0];
|
|
915
|
+
if (first === void 0) return yield* journalError(`Turn ${input.turn} has no terminal Tool results to commit`);
|
|
916
|
+
if (input.runCompletion !== void 0 && toolRecords.length !== 1) return yield* journalError("A terminal Tool completion requires exactly one settled result");
|
|
917
|
+
const completionRecord = yield* runCompletionRecord(input);
|
|
918
|
+
return CanonicalBatch.make({
|
|
919
|
+
batchId: turnResultsBatchId(input.runId, input.turn),
|
|
920
|
+
producerId: input.producerId,
|
|
921
|
+
records: completionRecord === void 0 ? [first, ...toolRecords.slice(1)] : [
|
|
922
|
+
first,
|
|
923
|
+
...toolRecords.slice(1),
|
|
924
|
+
completionRecord
|
|
925
|
+
]
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
//#endregion
|
|
929
|
+
export { workerOriginRecordId as $, subagentRequestedRecordId as A, toolCallUnknownRecordId as B, runStartedBatchId as C, subagentLineageBatchId as D, subagentJoinedRecordId as E, toolCallPreparedRecordId as F, turnCanonicalBatch as G, toolStepSettledRecordId as H, toolCallResolutionBatchId as I, turnResponseBatch as J, turnIdForRun as K, toolCallResolvedRecordId as L, subagentStartedRecordId as M, toolApprovalDecisionRecordId as N, subagentLineageRecordId as O, toolApprovalRequestRecordId as P, workerInputRecordId as Q, toolCallResultBatchId as R, runIdForSubmission as S, subagentJoinBatchId as T, turnApprovalsBatchId as U, toolStepSettledBatchId as V, turnBatchId as W, turnResultsBatch as X, turnResponseBatchId as Y, turnResultsBatchId as Z, promptFromCanonicalRecords as _, childIdempotencyKeyFor as a, runDurationBatchId as b, compactionRecordId as c, modelResponseInterruptedBatchId as d, workerReportRecordId as et, modelResponseInterruptedRecordId as f, projectRunJournalStream as g, projectRunJournal as h, approvalDecisionBatchId as i, subagentStartedBatchId as j, subagentRequestedBatchId as k, firstWorkerInputRecordId as l, peerMessageRecordId as m, RunJournal_exports as n, childThreadIdFor as o, modelResponseRecordId as p, turnPreparedBatchId as q, agentUpdateRecordId as r, compactionBatchId as s, RunJournalError as t, makeJournalMetadata as tt, markUnknownBatchId as u, runCompletedRecordId as v, runStartedRecordId as w, runDurationRecordId as x, runCompletionDigest as y, toolCallSettledRecordId as z };
|
|
930
|
+
|
|
931
|
+
//# sourceMappingURL=RunJournal-BXrq0VIK.mjs.map
|