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,1498 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { AgentId, DelegationId, RunId, SettlementId, ThreadId, ToolCallId } from "./core/Identifiers.mjs";
|
|
3
|
+
import { n as utf8ByteLength } from "./utf8-DchGZRBd.mjs";
|
|
4
|
+
import { AgentPolicy } from "./core/AgentPolicy.mjs";
|
|
5
|
+
import { IdempotencyKey, JoinedToHost, Receipt } from "./core/Receipt.mjs";
|
|
6
|
+
import { i as Failure, o as Value } from "./FailureDiagnostic-BElLOoED.mjs";
|
|
7
|
+
import { IdGenerator as IdGenerator$1 } from "./core/IdGenerator.mjs";
|
|
8
|
+
import { BackgroundSpawnTool, DelegationTool, SubagentBudgetReservation, SubagentDelegationCaps, SubagentExecutionFailure, SubagentExecutionFailureClassification, SubagentGrant, SubagentReservationAmounts, WorkerOperationTool, narrowSubagentGrant } from "./core/SubagentContract.mjs";
|
|
9
|
+
import { RunUsageReport, unknownRunTotals } from "./core/Usage.mjs";
|
|
10
|
+
import { C as MessageStatus, S as MessageRef, _ as WorkerStop, c as WorkerError, d as WorkerPage, f as WorkerRef, g as WorkerStarted, o as WorkerCompletion, p as WorkerReport, s as WorkerContext, v as WorkerStopped, y as WorkerSummary } from "./Worker-CfwzMZEK.mjs";
|
|
11
|
+
import { BackgroundReporting, SubagentHost, WorkerReportPreparationFailure } from "./engine/SubagentHost.mjs";
|
|
12
|
+
import { a as SubagentDurability, i as AgentSpawner, o as SubagentDurabilityError, s as ToolCallWaiting } from "./AgentRuntime-Cp1hAb-W.mjs";
|
|
13
|
+
import { RunEventSink } from "./engine/RunEventSink.mjs";
|
|
14
|
+
import { SubagentBudgetExhausted, SubagentObservedUsage, SubagentReservationRequest, SubagentReservations, makeBudgetReservationId } from "./capabilities/SubagentReservations.mjs";
|
|
15
|
+
import { t as utf8Bytes } from "./utf8-BYfhEkcj.mjs";
|
|
16
|
+
import { Tool, Toolkit } from "effect/unstable/ai";
|
|
17
|
+
import { Cause, Clock, Context, Crypto, Duration, Effect, Encoding, Exit, Layer, Option, Ref, Schema, Scope, Stream } from "effect";
|
|
18
|
+
//#region src/capabilities/internal/subagent-contract.ts
|
|
19
|
+
const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0));
|
|
20
|
+
const Natural = Schema.Natural;
|
|
21
|
+
const FinitePositiveDuration = Schema.Duration.pipe(Schema.refine((duration) => Duration.isFinite(duration) && Duration.isPositive(duration), { expected: "a finite positive duration" }));
|
|
22
|
+
const SubagentPolicyFields = Schema.Struct({
|
|
23
|
+
/** Total invocation slots, including reserved descendants, available through this delegation budget. */
|
|
24
|
+
maxChildren: PositiveInt,
|
|
25
|
+
/** Concurrently executing children per parent Run. */
|
|
26
|
+
maxConcurrency: PositiveInt,
|
|
27
|
+
/** Invocation slots held for the entire descendant subtree; omitted reserves zero. */
|
|
28
|
+
descendantInvocations: Schema.optionalKey(Natural),
|
|
29
|
+
/** Model turns reserved for each child invocation. */
|
|
30
|
+
maxTurns: PositiveInt,
|
|
31
|
+
/** Tool Calls reserved for each child invocation. */
|
|
32
|
+
maxToolCalls: PositiveInt,
|
|
33
|
+
/** Wall-clock duration reserved for each child invocation. */
|
|
34
|
+
maxDuration: FinitePositiveDuration,
|
|
35
|
+
maxInputTokens: Schema.optionalKey(PositiveInt),
|
|
36
|
+
maxOutputTokens: Schema.optionalKey(PositiveInt),
|
|
37
|
+
maxCostMicrousd: Schema.optionalKey(Natural),
|
|
38
|
+
maxResultBytes: Schema.optionalKey(PositiveInt)
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Finite delegation bounds declared by one Subagent capability.
|
|
42
|
+
* Structural limits are hard limits; token
|
|
43
|
+
* and cost caps are optional and enforced only as honestly as provider
|
|
44
|
+
* reporting allows.
|
|
45
|
+
*/
|
|
46
|
+
var SubagentPolicy = class extends Schema.Class("@effect-agent/capabilities/SubagentPolicy")(SubagentPolicyFields) {
|
|
47
|
+
/** Normalize and validate finite delegation bounds, throwing on invalid input. */
|
|
48
|
+
static make(input) {
|
|
49
|
+
return super.make({
|
|
50
|
+
...input,
|
|
51
|
+
maxDuration: Duration.fromInputUnsafe(input.maxDuration)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const BoundedFailureText = Schema.String.check(Schema.isMaxLength(4096));
|
|
56
|
+
/**
|
|
57
|
+
* Delegation preflight denied before any child started.
|
|
58
|
+
* No reservation, identity, or event exists for the
|
|
59
|
+
* denied invocation; retry requires a new authorized parent Tool Call.
|
|
60
|
+
*/
|
|
61
|
+
var SubagentPrestartDenied = class extends Schema.TaggedError()("SubagentPrestartDenied", {
|
|
62
|
+
delegationId: DelegationId,
|
|
63
|
+
targetAgentId: AgentId,
|
|
64
|
+
reason: Schema.Literals([
|
|
65
|
+
"nested-delegation",
|
|
66
|
+
"grant-violation",
|
|
67
|
+
"budget-conflict"
|
|
68
|
+
]),
|
|
69
|
+
message: BoundedFailureText
|
|
70
|
+
}) {};
|
|
71
|
+
/**
|
|
72
|
+
* Input or result projection failed its Schema or bounds.
|
|
73
|
+
* Fail closed: the message is a fixed description and
|
|
74
|
+
* never carries the raw child value.
|
|
75
|
+
*/
|
|
76
|
+
var SubagentProjectionFailure = class extends Schema.TaggedError()("SubagentProjectionFailure", {
|
|
77
|
+
delegationId: DelegationId,
|
|
78
|
+
stage: Schema.Literals(["input", "result"]),
|
|
79
|
+
message: BoundedFailureText,
|
|
80
|
+
/** Original validation error; detailed diagnostics are never part of the safe message. */
|
|
81
|
+
cause: Schema.optionalKey(Value),
|
|
82
|
+
stack: Schema.optionalKey(Schema.String)
|
|
83
|
+
}) {};
|
|
84
|
+
const millisOfMaxDuration = (policy) => Math.max(1, Math.ceil(Duration.toMillis(policy.maxDuration)));
|
|
85
|
+
/**
|
|
86
|
+
* Derive the parent-Run delegation caps registered with
|
|
87
|
+
* `SubagentReservations` from one delegation policy: the per-invocation
|
|
88
|
+
* bounds scaled by `maxChildren` plus the invocation and concurrency limits.
|
|
89
|
+
*/
|
|
90
|
+
const delegationCapsFromPolicy = (policy) => SubagentDelegationCaps.make({
|
|
91
|
+
maxTotalChildInvocations: policy.maxChildren,
|
|
92
|
+
maxConcurrentChildren: policy.maxConcurrency,
|
|
93
|
+
maxTurns: policy.maxChildren * policy.maxTurns,
|
|
94
|
+
maxToolCalls: policy.maxChildren * policy.maxToolCalls,
|
|
95
|
+
maxDurationMillis: policy.maxChildren * millisOfMaxDuration(policy),
|
|
96
|
+
...policy.maxInputTokens === void 0 ? {} : { maxInputTokens: policy.maxChildren * policy.maxInputTokens },
|
|
97
|
+
...policy.maxOutputTokens === void 0 ? {} : { maxOutputTokens: policy.maxChildren * policy.maxOutputTokens },
|
|
98
|
+
...policy.maxCostMicrousd === void 0 ? {} : { maxCostMicrousd: policy.maxChildren * policy.maxCostMicrousd },
|
|
99
|
+
...policy.maxResultBytes === void 0 ? {} : { maxResultBytes: policy.maxChildren * policy.maxResultBytes }
|
|
100
|
+
});
|
|
101
|
+
/** Derive the all-or-nothing per-invocation reservation from one delegation policy. */
|
|
102
|
+
const delegationAllocationFromPolicy = (policy) => SubagentReservationAmounts.make({
|
|
103
|
+
turns: policy.maxTurns,
|
|
104
|
+
toolCalls: policy.maxToolCalls,
|
|
105
|
+
durationMillis: millisOfMaxDuration(policy),
|
|
106
|
+
inputTokens: policy.maxInputTokens ?? 0,
|
|
107
|
+
outputTokens: policy.maxOutputTokens ?? 0,
|
|
108
|
+
costMicrousd: policy.maxCostMicrousd ?? 0,
|
|
109
|
+
resultBytes: policy.maxResultBytes ?? 0
|
|
110
|
+
});
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/capabilities/internal/subagent-policy.ts
|
|
113
|
+
const resolveSubagentPolicy = (delegation, parent, parentCaps, mode = "conserved", resolvedTarget) => {
|
|
114
|
+
const parentCeiling = mode === "conserved" ? parent : void 0;
|
|
115
|
+
const inherited = resolvedTarget ?? AgentPolicy.resolve(delegation.target.policyOverrides ?? delegation.target.policy, parent);
|
|
116
|
+
const policy = delegation.policy ?? SubagentPolicy.make({
|
|
117
|
+
maxChildren: parent.maxToolCalls,
|
|
118
|
+
maxConcurrency: parent.toolConcurrency,
|
|
119
|
+
maxTurns: Math.min(inherited.maxTurns, parent.maxTurns),
|
|
120
|
+
maxToolCalls: Math.min(inherited.maxToolCalls, parent.maxToolCalls),
|
|
121
|
+
maxDuration: Duration.min(inherited.maxDuration, parent.maxDuration),
|
|
122
|
+
...parent.tokenBudget === void 0 ? {} : {
|
|
123
|
+
maxInputTokens: parent.tokenBudget,
|
|
124
|
+
maxOutputTokens: parent.tokenBudget
|
|
125
|
+
},
|
|
126
|
+
...parent.costBudgetMicrousd === void 0 ? {} : { maxCostMicrousd: parent.costBudgetMicrousd },
|
|
127
|
+
maxResultBytes: parent.toolResultBounds.maxBytes
|
|
128
|
+
});
|
|
129
|
+
const tokenCeiling = policy.maxInputTokens === void 0 || policy.maxOutputTokens === void 0 ? Math.min(inherited.tokenBudget ?? Infinity, parentCeiling?.tokenBudget ?? Infinity) : Math.min(inherited.tokenBudget ?? Infinity, parentCeiling?.tokenBudget ?? Infinity, policy.maxInputTokens + policy.maxOutputTokens);
|
|
130
|
+
const childPolicy = AgentPolicy.make({
|
|
131
|
+
...inherited,
|
|
132
|
+
maxTurns: Math.min(inherited.maxTurns, policy.maxTurns, parentCeiling?.maxTurns ?? Infinity),
|
|
133
|
+
maxToolCalls: Math.min(inherited.maxToolCalls, policy.maxToolCalls, parentCeiling?.maxToolCalls ?? Infinity),
|
|
134
|
+
maxDuration: Duration.min(Duration.min(inherited.maxDuration, policy.maxDuration), parentCeiling?.maxDuration ?? Duration.infinity),
|
|
135
|
+
toolConcurrency: Math.min(inherited.toolConcurrency, parentCeiling?.toolConcurrency ?? Infinity),
|
|
136
|
+
...parentCeiling === void 0 ? {} : { toolResultBounds: { maxBytes: Math.min(inherited.toolResultBounds.maxBytes, parentCeiling.toolResultBounds.maxBytes, Math.max(256, policy.maxResultBytes ?? Infinity)) } },
|
|
137
|
+
...tokenCeiling === Infinity ? {} : {
|
|
138
|
+
tokenBudget: tokenCeiling,
|
|
139
|
+
completionReserveTokens: Math.min(inherited.completionReserveTokens, tokenCeiling)
|
|
140
|
+
},
|
|
141
|
+
...Math.min(inherited.costBudgetMicrousd ?? Infinity, parentCeiling?.costBudgetMicrousd ?? Infinity, policy.maxCostMicrousd ?? Infinity) === Infinity ? {} : { costBudgetMicrousd: Math.min(inherited.costBudgetMicrousd ?? Infinity, parentCeiling?.costBudgetMicrousd ?? Infinity, policy.maxCostMicrousd ?? Infinity) }
|
|
142
|
+
});
|
|
143
|
+
const caps = parentCaps ?? (delegation.policy === void 0 ? SubagentDelegationCaps.make({
|
|
144
|
+
maxTotalChildInvocations: parent.maxToolCalls,
|
|
145
|
+
maxConcurrentChildren: parent.toolConcurrency,
|
|
146
|
+
maxTurns: parent.maxTurns,
|
|
147
|
+
maxToolCalls: parent.maxToolCalls,
|
|
148
|
+
maxDurationMillis: Math.ceil(Duration.toMillis(parent.maxDuration)),
|
|
149
|
+
...parent.tokenBudget === void 0 ? {} : {
|
|
150
|
+
maxInputTokens: parent.tokenBudget,
|
|
151
|
+
maxOutputTokens: parent.tokenBudget
|
|
152
|
+
},
|
|
153
|
+
...parent.costBudgetMicrousd === void 0 ? {} : { maxCostMicrousd: parent.costBudgetMicrousd }
|
|
154
|
+
}) : delegationCapsFromPolicy(policy));
|
|
155
|
+
return {
|
|
156
|
+
policy,
|
|
157
|
+
childPolicy,
|
|
158
|
+
allocation: delegationAllocationFromPolicy(policy),
|
|
159
|
+
caps
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const resolveToolCallAllowance = (option, parameters, policy, childPolicy) => {
|
|
163
|
+
if (option === void 0) return childPolicy.maxToolCalls;
|
|
164
|
+
const extracted = option.fromParameters?.(parameters);
|
|
165
|
+
const requested = extracted !== void 0 && Number.isFinite(extracted) ? extracted : Number.isFinite(option.default) ? option.default : policy.maxToolCalls;
|
|
166
|
+
return Math.min(Math.max(1, Math.floor(requested)), policy.maxToolCalls, childPolicy.maxToolCalls);
|
|
167
|
+
};
|
|
168
|
+
/** Conservative subtree remainder after reserving this Run's own full execution ceiling. */
|
|
169
|
+
const residualSubagentCaps = (declared, parent, inherited, independentRun = false) => {
|
|
170
|
+
const allocation = inherited.allocation;
|
|
171
|
+
const remaining = (allocated, own, cap) => Math.min(cap ?? Infinity, Math.max(0, allocated - own));
|
|
172
|
+
return SubagentDelegationCaps.make({
|
|
173
|
+
maxTotalChildInvocations: Math.min(declared.maxTotalChildInvocations ?? Infinity, inherited.descendantInvocations ?? 0),
|
|
174
|
+
maxConcurrentChildren: Math.min(declared.maxConcurrentChildren ?? Infinity, parent.toolConcurrency, inherited.descendantInvocations ?? 0),
|
|
175
|
+
maxTurns: remaining(allocation.turns, parent.maxTurns, declared.maxTurns),
|
|
176
|
+
maxToolCalls: remaining(allocation.toolCalls, parent.maxToolCalls, declared.maxToolCalls),
|
|
177
|
+
maxDurationMillis: remaining(allocation.durationMillis, Math.ceil(Duration.toMillis(parent.maxDuration)), declared.maxDurationMillis),
|
|
178
|
+
...independentRun && inherited.caps.maxInputTokens === void 0 && allocation.inputTokens === 0 && parent.tokenBudget === void 0 ? declared.maxInputTokens === void 0 ? {} : { maxInputTokens: declared.maxInputTokens } : { maxInputTokens: remaining(allocation.inputTokens, parent.tokenBudget ?? allocation.inputTokens, declared.maxInputTokens) },
|
|
179
|
+
...independentRun && inherited.caps.maxOutputTokens === void 0 && allocation.outputTokens === 0 && parent.tokenBudget === void 0 ? declared.maxOutputTokens === void 0 ? {} : { maxOutputTokens: declared.maxOutputTokens } : { maxOutputTokens: remaining(allocation.outputTokens, parent.tokenBudget ?? allocation.outputTokens, declared.maxOutputTokens) },
|
|
180
|
+
...independentRun && inherited.caps.maxCostMicrousd === void 0 && allocation.costMicrousd === 0 && parent.costBudgetMicrousd === void 0 ? declared.maxCostMicrousd === void 0 ? {} : { maxCostMicrousd: declared.maxCostMicrousd } : { maxCostMicrousd: remaining(allocation.costMicrousd, parent.costBudgetMicrousd ?? allocation.costMicrousd, declared.maxCostMicrousd) },
|
|
181
|
+
maxResultBytes: remaining(allocation.resultBytes, parent.toolResultBounds.maxBytes, declared.maxResultBytes)
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/capabilities/internal/subagent-reporting.ts
|
|
186
|
+
const projectReport = (declaration) => Effect.fn("Subagent.projectReport")(function* (report) {
|
|
187
|
+
const { worker, observation } = report;
|
|
188
|
+
const invalid = () => WorkerReportPreparationFailure.make({ stage: "projection" });
|
|
189
|
+
if (worker.delegationId !== declaration.delegationId || worker.targetAgentId !== declaration.target.id || observation.receipt.threadId !== worker.threadId) return yield* invalid();
|
|
190
|
+
const base = {
|
|
191
|
+
_tag: "Settled",
|
|
192
|
+
worker,
|
|
193
|
+
receipt: yield* Schema.decodeEffect(Receipt)(observation.receipt).pipe(Effect.mapError(invalid)),
|
|
194
|
+
runId: observation.runId,
|
|
195
|
+
settlementId: observation.settlementId
|
|
196
|
+
};
|
|
197
|
+
let projected;
|
|
198
|
+
let encodedResult = null;
|
|
199
|
+
if (observation.outcome === "completed") {
|
|
200
|
+
const parameters = yield* Schema.decodeUnknownEffect(declaration.parameters)(observation.encodedParameters).pipe(Effect.mapError(invalid));
|
|
201
|
+
const output = yield* Schema.decodeUnknownEffect(declaration.target.output)(observation.encodedResult).pipe(Effect.mapError(invalid));
|
|
202
|
+
const result = yield* declaration.projectResult(output, { budgetExhausted: observation.budgetExhausted }, parameters);
|
|
203
|
+
const encoded = yield* Schema.encodeEffect(declaration.success)(result).pipe(Effect.mapError(invalid));
|
|
204
|
+
const json = yield* Schema.decodeUnknownEffect(Schema.Json)(encoded).pipe(Effect.mapError(invalid));
|
|
205
|
+
if (utf8ByteLength(JSON.stringify(json)) > (declaration.policy?.maxResultBytes ?? declaration.target.policy.toolResultBounds.maxBytes)) return yield* invalid();
|
|
206
|
+
projected = {
|
|
207
|
+
...base,
|
|
208
|
+
outcome: "completed",
|
|
209
|
+
result
|
|
210
|
+
};
|
|
211
|
+
encodedResult = json;
|
|
212
|
+
} else projected = {
|
|
213
|
+
...base,
|
|
214
|
+
outcome: observation.outcome,
|
|
215
|
+
failure: SubagentExecutionFailure.make({
|
|
216
|
+
delegationId: declaration.delegationId,
|
|
217
|
+
targetAgentId: declaration.target.id,
|
|
218
|
+
classification: observation.outcome === "failed" ? "child-failed" : "child-aborted",
|
|
219
|
+
childThreadId: worker.threadId,
|
|
220
|
+
childSubmissionId: observation.receipt.submissionId,
|
|
221
|
+
childRunId: observation.runId,
|
|
222
|
+
errorTag: observation.outcome === "failed" ? "WorkerFailed" : "WorkerAborted",
|
|
223
|
+
message: observation.outcome === "failed" ? "Worker input failed" : "Worker input was aborted"
|
|
224
|
+
})
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
projected,
|
|
228
|
+
encodedResult
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
/** Project a canonical child outcome into the bounded standard completion message. */
|
|
232
|
+
const automaticReporting = (declaration) => ({
|
|
233
|
+
delegationId: declaration.delegationId,
|
|
234
|
+
target: declaration.target,
|
|
235
|
+
prepare: Effect.fn("Subagent.automaticReport")(function* (report) {
|
|
236
|
+
const { projected, encodedResult } = yield* projectReport(declaration)(report);
|
|
237
|
+
const encoded = projected.outcome === "completed" ? {
|
|
238
|
+
...projected,
|
|
239
|
+
result: encodedResult
|
|
240
|
+
} : {
|
|
241
|
+
...projected,
|
|
242
|
+
failure: yield* Schema.encodeEffect(SubagentExecutionFailure)(projected.failure).pipe(Effect.mapError(() => WorkerReportPreparationFailure.make({ stage: "projection" })))
|
|
243
|
+
};
|
|
244
|
+
return { message: yield* Schema.decodeEffect(WorkerCompletion)({
|
|
245
|
+
_tag: "WorkerCompletion",
|
|
246
|
+
schemaVersion: 1,
|
|
247
|
+
report: encoded,
|
|
248
|
+
budgetExhausted: report.observation.budgetExhausted
|
|
249
|
+
}).pipe(Effect.mapError(() => WorkerReportPreparationFailure.make({ stage: "projection" }))) };
|
|
250
|
+
})
|
|
251
|
+
});
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/capabilities/internal/subagent-background.ts
|
|
254
|
+
/** Portable identity checked against this declaration; possession grants no authority. */
|
|
255
|
+
const Worker = (declaration) => WorkerRef.check(Schema.makeFilter((worker) => worker.delegationId === declaration.delegationId && worker.targetAgentId === declaration.target.id)).pipe(Schema.brand(`@effect-agent/Worker/${declaration.name}`));
|
|
256
|
+
/** Model-facing projection deliberately excludes operator-private diagnostics. */
|
|
257
|
+
const toolObservation = (success) => Schema.Union([
|
|
258
|
+
Schema.Struct({
|
|
259
|
+
_tag: Schema.Literal("Pending"),
|
|
260
|
+
receipt: Receipt
|
|
261
|
+
}),
|
|
262
|
+
Schema.Struct({
|
|
263
|
+
_tag: Schema.Literal("Settled"),
|
|
264
|
+
receipt: Receipt,
|
|
265
|
+
runId: RunId,
|
|
266
|
+
settlementId: SettlementId,
|
|
267
|
+
outcome: Schema.Literal("completed"),
|
|
268
|
+
result: success
|
|
269
|
+
}),
|
|
270
|
+
Schema.Struct({
|
|
271
|
+
_tag: Schema.Literal("Settled"),
|
|
272
|
+
receipt: Receipt,
|
|
273
|
+
runId: Schema.optionalKey(RunId),
|
|
274
|
+
settlementId: SettlementId,
|
|
275
|
+
outcome: Schema.Literals(["failed", "aborted"]),
|
|
276
|
+
failure: SubagentExecutionFailure
|
|
277
|
+
})
|
|
278
|
+
]);
|
|
279
|
+
/** One exact Receipt, including private canonical failure evidence for programmatic callers. */
|
|
280
|
+
const WorkerObservation = (success) => {
|
|
281
|
+
const projected = toolObservation(success);
|
|
282
|
+
return Schema.Union([
|
|
283
|
+
projected.members[0],
|
|
284
|
+
projected.members[1],
|
|
285
|
+
Schema.Struct({
|
|
286
|
+
...projected.members[2].fields,
|
|
287
|
+
diagnostic: Schema.optionalKey(Failure)
|
|
288
|
+
})
|
|
289
|
+
]);
|
|
290
|
+
};
|
|
291
|
+
const host = Effect.serviceOption(SubagentHost).pipe(Effect.flatMap((service) => Option.match(service, {
|
|
292
|
+
onNone: () => WorkerError.make({
|
|
293
|
+
operation: "context",
|
|
294
|
+
reason: "unavailable"
|
|
295
|
+
}),
|
|
296
|
+
onSome: Effect.succeed
|
|
297
|
+
})));
|
|
298
|
+
const receiptEqual = (left, right) => left.threadId === right.threadId && left.submissionId === right.submissionId && left.receiptId === right.receiptId && left.queueSequence === right.queueSequence;
|
|
299
|
+
const operations = (declaration) => {
|
|
300
|
+
const workerSchema = Worker(declaration);
|
|
301
|
+
const projectionFailure = (stage, cause) => SubagentProjectionFailure.make({
|
|
302
|
+
delegationId: declaration.delegationId,
|
|
303
|
+
stage,
|
|
304
|
+
...cause === void 0 ? {} : { cause },
|
|
305
|
+
message: stage === "input" ? "Worker input did not satisfy the declaration Schema" : "Worker result did not satisfy the declaration Schema"
|
|
306
|
+
});
|
|
307
|
+
const validateWorker = (worker, operation) => Schema.decodeUnknownEffect(workerSchema)(worker).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
308
|
+
operation,
|
|
309
|
+
reason: "worker-mismatch",
|
|
310
|
+
cause
|
|
311
|
+
})));
|
|
312
|
+
const validateReceipt = (worker, receipt, operation) => Schema.decodeEffect(Receipt.check(Schema.makeFilter((value) => value.threadId === worker.threadId)))(receipt).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
313
|
+
operation,
|
|
314
|
+
reason: "receipt-mismatch",
|
|
315
|
+
cause
|
|
316
|
+
})));
|
|
317
|
+
const validateDelivery = Effect.fn("Subagent.validateWorkerDelivery")(function* (worker, delivery, operation) {
|
|
318
|
+
const validated = yield* Schema.decodeEffect(MessageStatus)(delivery).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
319
|
+
operation,
|
|
320
|
+
reason: "corrupt",
|
|
321
|
+
cause
|
|
322
|
+
})));
|
|
323
|
+
if (validated.receipt !== null) yield* validateReceipt(worker, validated.receipt, operation);
|
|
324
|
+
return validated;
|
|
325
|
+
});
|
|
326
|
+
const context = host.pipe(Effect.flatMap((service) => service.context), Effect.flatMap(Schema.decodeUnknownEffect(Schema.toType(WorkerContext))), Effect.mapError((error) => Schema.is(WorkerError)(error) ? error : WorkerError.make({
|
|
327
|
+
operation: "context",
|
|
328
|
+
reason: "corrupt",
|
|
329
|
+
cause: error
|
|
330
|
+
})));
|
|
331
|
+
const prepare = Effect.fn("Subagent.prepareWorkerInput")(function* (parameters, caller) {
|
|
332
|
+
const source = caller.source;
|
|
333
|
+
const preparation = source._tag === "tool" ? {
|
|
334
|
+
source: "tool",
|
|
335
|
+
delegationId: declaration.delegationId,
|
|
336
|
+
toolCallId: source.toolCallId,
|
|
337
|
+
parent: {
|
|
338
|
+
agentId: source.agentId,
|
|
339
|
+
threadId: source.threadId,
|
|
340
|
+
runId: source.runId
|
|
341
|
+
}
|
|
342
|
+
} : {
|
|
343
|
+
source: "programmatic",
|
|
344
|
+
delegationId: declaration.delegationId,
|
|
345
|
+
parent: {
|
|
346
|
+
agentId: source.agentId,
|
|
347
|
+
threadId: source.threadId
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const input = yield* declaration.prepareInput(parameters, preparation);
|
|
351
|
+
return yield* Schema.encodeEffect(declaration.target.input)(input).pipe(Effect.mapError((cause) => projectionFailure("input", cause)));
|
|
352
|
+
});
|
|
353
|
+
const validateKey = (key, operation) => Schema.decodeEffect(IdempotencyKey)(key).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
354
|
+
operation,
|
|
355
|
+
reason: "idempotency-conflict",
|
|
356
|
+
cause
|
|
357
|
+
})));
|
|
358
|
+
return {
|
|
359
|
+
start: Effect.fn("Subagent.start")(function* (parameters, options) {
|
|
360
|
+
const service = yield* host;
|
|
361
|
+
const caller = yield* context;
|
|
362
|
+
const key = yield* validateKey(options.idempotencyKey, "start");
|
|
363
|
+
const grant = narrowSubagentGrant(declaration.grant, caller.grant);
|
|
364
|
+
if (caller.depth + 1 > grant.maxDepth) return yield* SubagentPrestartDenied.make({
|
|
365
|
+
delegationId: declaration.delegationId,
|
|
366
|
+
targetAgentId: declaration.target.id,
|
|
367
|
+
reason: "nested-delegation",
|
|
368
|
+
message: "Worker start exceeds the inherited depth ceiling"
|
|
369
|
+
});
|
|
370
|
+
if (!(caller.grant?.childLifetimes ?? ["attached", "background"]).includes("background")) return yield* SubagentPrestartDenied.make({
|
|
371
|
+
delegationId: declaration.delegationId,
|
|
372
|
+
targetAgentId: declaration.target.id,
|
|
373
|
+
reason: "grant-violation",
|
|
374
|
+
message: "The inherited grant does not permit background children"
|
|
375
|
+
});
|
|
376
|
+
const encodedParameters = yield* Schema.encodeEffect(declaration.parameters)(parameters).pipe(Effect.mapError((cause) => projectionFailure("input", cause)));
|
|
377
|
+
const encodedGrant = yield* Schema.encodeEffect(SubagentGrant)(grant).pipe(Effect.mapError((cause) => projectionFailure("input", cause)));
|
|
378
|
+
const started = yield* service.start({
|
|
379
|
+
delegationId: declaration.delegationId,
|
|
380
|
+
target: declaration.target,
|
|
381
|
+
idempotencyKey: key,
|
|
382
|
+
encodedParameters,
|
|
383
|
+
encodedGrant,
|
|
384
|
+
...options.budgetScope === void 0 ? {} : { budgetScope: options.budgetScope },
|
|
385
|
+
prepare: Effect.gen(function* () {
|
|
386
|
+
const encodedInput = yield* prepare(parameters, caller);
|
|
387
|
+
const effectiveTarget = yield* service.resolveTargetPolicy({
|
|
388
|
+
target: declaration.target,
|
|
389
|
+
encodedInput
|
|
390
|
+
});
|
|
391
|
+
const resolvedTarget = Option.getOrUndefined(effectiveTarget);
|
|
392
|
+
const resolved = resolveSubagentPolicy(declaration, options.budgetScope === "worker-run" ? resolvedTarget ?? declaration.target.policy : caller.policy, void 0, options.budgetScope === "worker-run" ? "root-attached" : "conserved", resolvedTarget);
|
|
393
|
+
return {
|
|
394
|
+
encodedInput,
|
|
395
|
+
policy: resolved.childPolicy,
|
|
396
|
+
budget: SubagentBudgetReservation.make({
|
|
397
|
+
caps: resolved.caps,
|
|
398
|
+
allocation: resolved.allocation,
|
|
399
|
+
...resolved.policy.descendantInvocations === void 0 ? {} : { descendantInvocations: resolved.policy.descendantInvocations }
|
|
400
|
+
}),
|
|
401
|
+
toolCallAllowance: resolveToolCallAllowance(declaration.toolCallAllowance, parameters, resolved.policy, resolved.childPolicy)
|
|
402
|
+
};
|
|
403
|
+
})
|
|
404
|
+
});
|
|
405
|
+
const validated = yield* Schema.decodeEffect(WorkerStarted)(started).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
406
|
+
operation: "start",
|
|
407
|
+
reason: "corrupt",
|
|
408
|
+
cause
|
|
409
|
+
})));
|
|
410
|
+
if (validated.delivery.message.ownerThreadId !== caller.source.threadId) return yield* WorkerError.make({
|
|
411
|
+
operation: "start",
|
|
412
|
+
reason: "message-mismatch"
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
worker: yield* validateWorker(validated.worker, "start"),
|
|
416
|
+
delivery: validated.delivery
|
|
417
|
+
};
|
|
418
|
+
}),
|
|
419
|
+
followUp: Effect.fn("Subagent.followUp")(function* (worker, parameters, options) {
|
|
420
|
+
const service = yield* host;
|
|
421
|
+
const validated = yield* validateWorker(worker, "followUp");
|
|
422
|
+
const caller = yield* context;
|
|
423
|
+
const key = yield* validateKey(options.idempotencyKey, "followUp");
|
|
424
|
+
const encodedParameters = yield* Schema.encodeEffect(declaration.parameters)(parameters).pipe(Effect.mapError((cause) => projectionFailure("input", cause)));
|
|
425
|
+
const delivery = yield* validateDelivery(validated, yield* service.followUp({
|
|
426
|
+
encodedParameters,
|
|
427
|
+
prepare: prepare(parameters, caller).pipe(Effect.map((encodedInput) => ({ encodedInput }))),
|
|
428
|
+
worker: validated,
|
|
429
|
+
target: declaration.target,
|
|
430
|
+
idempotencyKey: key
|
|
431
|
+
}), "followUp");
|
|
432
|
+
if (delivery.message.ownerThreadId !== caller.source.threadId) return yield* WorkerError.make({
|
|
433
|
+
operation: "followUp",
|
|
434
|
+
reason: "message-mismatch"
|
|
435
|
+
});
|
|
436
|
+
return delivery;
|
|
437
|
+
}),
|
|
438
|
+
inspectMessage: Effect.fn("Subagent.inspectWorkerMessage")(function* (worker, message) {
|
|
439
|
+
const service = yield* host;
|
|
440
|
+
const validated = yield* validateWorker(worker, "inspect");
|
|
441
|
+
const requested = yield* Schema.decodeEffect(MessageRef)(message).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
442
|
+
operation: "inspect",
|
|
443
|
+
reason: "message-mismatch",
|
|
444
|
+
cause
|
|
445
|
+
})));
|
|
446
|
+
const observed = yield* service.inspect({
|
|
447
|
+
worker: validated,
|
|
448
|
+
target: declaration.target,
|
|
449
|
+
message: requested
|
|
450
|
+
});
|
|
451
|
+
if (!("message" in observed)) return yield* WorkerError.make({
|
|
452
|
+
operation: "inspect",
|
|
453
|
+
reason: "corrupt"
|
|
454
|
+
});
|
|
455
|
+
const delivery = yield* validateDelivery(validated, observed, "inspect");
|
|
456
|
+
if (!Schema.toEquivalence(MessageRef)(delivery.message, requested)) return yield* WorkerError.make({
|
|
457
|
+
operation: "inspect",
|
|
458
|
+
reason: "message-mismatch"
|
|
459
|
+
});
|
|
460
|
+
return delivery;
|
|
461
|
+
}),
|
|
462
|
+
observe: Effect.fn("Subagent.observeWorker")(function* (operation, worker, receipt) {
|
|
463
|
+
const service = yield* host;
|
|
464
|
+
const validated = yield* validateWorker(worker, operation);
|
|
465
|
+
const requested = yield* validateReceipt(validated, receipt, operation);
|
|
466
|
+
const observed = yield* service[operation]({
|
|
467
|
+
worker: validated,
|
|
468
|
+
target: declaration.target,
|
|
469
|
+
receipt: requested
|
|
470
|
+
});
|
|
471
|
+
if (!("_tag" in observed)) return yield* WorkerError.make({
|
|
472
|
+
operation,
|
|
473
|
+
reason: "corrupt"
|
|
474
|
+
});
|
|
475
|
+
const returned = yield* validateReceipt(validated, observed.receipt, operation);
|
|
476
|
+
if (!receiptEqual(returned, requested)) return yield* WorkerError.make({
|
|
477
|
+
operation,
|
|
478
|
+
reason: "receipt-mismatch"
|
|
479
|
+
});
|
|
480
|
+
if (observed._tag === "Pending") {
|
|
481
|
+
if (operation === "await") return yield* WorkerError.make({
|
|
482
|
+
operation,
|
|
483
|
+
reason: "corrupt"
|
|
484
|
+
});
|
|
485
|
+
return {
|
|
486
|
+
_tag: "Pending",
|
|
487
|
+
receipt: returned
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
const base = {
|
|
491
|
+
_tag: "Settled",
|
|
492
|
+
receipt: returned,
|
|
493
|
+
...observed.runId === void 0 ? {} : { runId: yield* Schema.decodeEffect(RunId)(observed.runId).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
494
|
+
operation,
|
|
495
|
+
reason: "corrupt",
|
|
496
|
+
cause
|
|
497
|
+
}))) },
|
|
498
|
+
settlementId: yield* Schema.decodeEffect(SettlementId)(observed.settlementId).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
499
|
+
operation,
|
|
500
|
+
reason: "corrupt",
|
|
501
|
+
cause
|
|
502
|
+
})))
|
|
503
|
+
};
|
|
504
|
+
if (observed.outcome === "failed" || observed.outcome === "aborted") return {
|
|
505
|
+
...base,
|
|
506
|
+
outcome: observed.outcome,
|
|
507
|
+
...observed.diagnostic === void 0 ? {} : { diagnostic: yield* Schema.decodeEffect(Failure)(observed.diagnostic).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
508
|
+
operation,
|
|
509
|
+
reason: "corrupt",
|
|
510
|
+
cause
|
|
511
|
+
}))) },
|
|
512
|
+
failure: SubagentExecutionFailure.make({
|
|
513
|
+
delegationId: declaration.delegationId,
|
|
514
|
+
targetAgentId: declaration.target.id,
|
|
515
|
+
classification: observed.outcome === "failed" ? "child-failed" : "child-aborted",
|
|
516
|
+
childThreadId: worker.threadId,
|
|
517
|
+
childSubmissionId: returned.submissionId,
|
|
518
|
+
...base.runId === void 0 ? {} : { childRunId: base.runId },
|
|
519
|
+
errorTag: observed.outcome === "failed" ? "WorkerFailed" : "WorkerAborted",
|
|
520
|
+
message: observed.outcome === "failed" ? "Worker input failed" : "Worker input was aborted"
|
|
521
|
+
})
|
|
522
|
+
};
|
|
523
|
+
if (observed.outcome !== "completed" || base.runId === void 0 || typeof observed.budgetExhausted !== "boolean") return yield* WorkerError.make({
|
|
524
|
+
operation,
|
|
525
|
+
reason: "corrupt"
|
|
526
|
+
});
|
|
527
|
+
const parameters = yield* Schema.decodeUnknownEffect(declaration.parameters)(observed.encodedParameters).pipe(Effect.mapError((cause) => projectionFailure("result", cause)));
|
|
528
|
+
const output = yield* Schema.decodeUnknownEffect(declaration.target.output)(observed.encodedResult).pipe(Effect.mapError((cause) => projectionFailure("result", cause)));
|
|
529
|
+
const result = yield* declaration.projectResult(output, { budgetExhausted: observed.budgetExhausted }, parameters);
|
|
530
|
+
const encoded = yield* Schema.encodeEffect(declaration.success)(result).pipe(Effect.mapError((cause) => projectionFailure("result", cause)));
|
|
531
|
+
const json = yield* Schema.decodeUnknownEffect(Schema.Json)(encoded).pipe(Effect.mapError((cause) => projectionFailure("result", cause)));
|
|
532
|
+
const caller = yield* context;
|
|
533
|
+
if (utf8ByteLength(JSON.stringify(json)) > (declaration.policy?.maxResultBytes ?? caller.policy.toolResultBounds.maxBytes)) return yield* projectionFailure("result");
|
|
534
|
+
return yield* Schema.decodeUnknownEffect(Schema.toType(WorkerObservation(declaration.success)))({
|
|
535
|
+
...base,
|
|
536
|
+
outcome: "completed",
|
|
537
|
+
result
|
|
538
|
+
}).pipe(Effect.mapError((cause) => projectionFailure("result", cause)));
|
|
539
|
+
}),
|
|
540
|
+
list: Effect.fn("Subagent.list")(function* (options = {}) {
|
|
541
|
+
const service = yield* host;
|
|
542
|
+
const limit = yield* Schema.decodeEffect(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)))(options.limit ?? 20).pipe(Effect.mapError(() => WorkerError.make({
|
|
543
|
+
operation: "list",
|
|
544
|
+
reason: "capacity"
|
|
545
|
+
})));
|
|
546
|
+
const page = yield* service.list({
|
|
547
|
+
delegationId: declaration.delegationId,
|
|
548
|
+
target: declaration.target,
|
|
549
|
+
limit,
|
|
550
|
+
...options.after === void 0 ? {} : { after: options.after }
|
|
551
|
+
});
|
|
552
|
+
const validated = yield* Schema.decodeEffect(WorkerPage)(page).pipe(Effect.mapError(() => WorkerError.make({
|
|
553
|
+
operation: "list",
|
|
554
|
+
reason: "corrupt"
|
|
555
|
+
})));
|
|
556
|
+
if (validated.items.length > limit) return yield* WorkerError.make({
|
|
557
|
+
operation: "list",
|
|
558
|
+
reason: "corrupt"
|
|
559
|
+
});
|
|
560
|
+
const items = [];
|
|
561
|
+
for (const item of validated.items) {
|
|
562
|
+
const worker = yield* validateWorker(item.worker, "list");
|
|
563
|
+
const latestReceipt = item.latestReceipt === null ? null : yield* validateReceipt(worker, item.latestReceipt, "list");
|
|
564
|
+
items.push({
|
|
565
|
+
...item,
|
|
566
|
+
worker,
|
|
567
|
+
latestReceipt
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
items,
|
|
572
|
+
next: validated.next
|
|
573
|
+
};
|
|
574
|
+
}),
|
|
575
|
+
cancel: Effect.fn("Subagent.cancel")(function* (worker, receipt) {
|
|
576
|
+
const service = yield* host;
|
|
577
|
+
const validated = yield* validateWorker(worker, "cancel");
|
|
578
|
+
const requested = yield* validateReceipt(validated, receipt, "cancel");
|
|
579
|
+
yield* service.cancel({
|
|
580
|
+
worker: validated,
|
|
581
|
+
target: declaration.target,
|
|
582
|
+
receipt: requested
|
|
583
|
+
});
|
|
584
|
+
})
|
|
585
|
+
};
|
|
586
|
+
};
|
|
587
|
+
/** Retain a first worker input. The same explicit key reuses its durable delivery identity. */
|
|
588
|
+
const start = (declaration, parameters, options) => operations(declaration).start(parameters, options);
|
|
589
|
+
/** Retain typed follow-up parameters for the same worker Thread; inspect its MessageRef for delivery. */
|
|
590
|
+
const followUp = (declaration, worker, parameters, options) => operations(declaration).followUp(worker, parameters, options);
|
|
591
|
+
/** Inspect a continuing worker with the same summary contract returned by list. */
|
|
592
|
+
const summary = (declaration, worker) => Effect.gen(function* () {
|
|
593
|
+
const service = yield* host;
|
|
594
|
+
const validated = yield* Schema.decodeEffect(Worker(declaration))(worker).pipe(Effect.mapError(() => WorkerError.make({
|
|
595
|
+
operation: "inspect",
|
|
596
|
+
reason: "worker-mismatch"
|
|
597
|
+
})));
|
|
598
|
+
const result = yield* service.summary({
|
|
599
|
+
worker: validated,
|
|
600
|
+
target: declaration.target
|
|
601
|
+
});
|
|
602
|
+
const value = yield* Schema.decodeEffect(WorkerSummary)(result).pipe(Effect.mapError(() => WorkerError.make({
|
|
603
|
+
operation: "inspect",
|
|
604
|
+
reason: "corrupt"
|
|
605
|
+
})));
|
|
606
|
+
if (value.worker.threadId !== validated.threadId || value.worker.delegationId !== validated.delegationId || value.worker.targetAgentId !== validated.targetAgentId || value.latestReceipt !== null && value.latestReceipt.threadId !== validated.threadId) return yield* WorkerError.make({
|
|
607
|
+
operation: "inspect",
|
|
608
|
+
reason: "worker-mismatch"
|
|
609
|
+
});
|
|
610
|
+
return {
|
|
611
|
+
...value,
|
|
612
|
+
worker: validated
|
|
613
|
+
};
|
|
614
|
+
});
|
|
615
|
+
function inspect(declaration, worker, reference) {
|
|
616
|
+
return reference === void 0 ? summary(declaration, worker) : "messageId" in reference ? operations(declaration).inspectMessage(worker, reference) : operations(declaration).observe("inspect", worker, reference);
|
|
617
|
+
}
|
|
618
|
+
/** Read an authorized finite history snapshot; pass the last emitted sequence to resume. */
|
|
619
|
+
const observe = (declaration, worker, options = {}) => Stream.unwrap(Effect.gen(function* () {
|
|
620
|
+
const service = yield* host;
|
|
621
|
+
const validated = yield* Schema.decodeEffect(Worker(declaration))(worker).pipe(Effect.mapError(() => WorkerError.make({
|
|
622
|
+
operation: "observe",
|
|
623
|
+
reason: "worker-mismatch"
|
|
624
|
+
})));
|
|
625
|
+
const after = options.after === void 0 ? void 0 : yield* Schema.decodeEffect(Schema.Natural)(options.after).pipe(Effect.mapError(() => WorkerError.make({
|
|
626
|
+
operation: "observe",
|
|
627
|
+
reason: "corrupt"
|
|
628
|
+
})));
|
|
629
|
+
return service.observe({
|
|
630
|
+
worker: validated,
|
|
631
|
+
target: declaration.target,
|
|
632
|
+
...after === void 0 ? {} : { after }
|
|
633
|
+
});
|
|
634
|
+
}));
|
|
635
|
+
/** Seal a continuing worker, retaining a stable command identity across retries and Runs. */
|
|
636
|
+
const stop = (declaration, worker, options) => Effect.gen(function* () {
|
|
637
|
+
const service = yield* host;
|
|
638
|
+
const command = yield* Schema.decodeEffect(WorkerStop)({
|
|
639
|
+
worker,
|
|
640
|
+
...options
|
|
641
|
+
}).pipe(Effect.mapError((cause) => WorkerError.make({
|
|
642
|
+
operation: "stop",
|
|
643
|
+
reason: "corrupt",
|
|
644
|
+
cause
|
|
645
|
+
})));
|
|
646
|
+
if (worker.delegationId !== declaration.delegationId || worker.targetAgentId !== declaration.target.id) return yield* WorkerError.make({
|
|
647
|
+
operation: "stop",
|
|
648
|
+
reason: "worker-mismatch"
|
|
649
|
+
});
|
|
650
|
+
return yield* service.stop({
|
|
651
|
+
...command,
|
|
652
|
+
target: declaration.target
|
|
653
|
+
}).pipe(Effect.flatMap(Schema.decodeEffect(WorkerStopped)), Effect.mapError((cause) => Schema.is(WorkerError)(cause) ? cause : WorkerError.make({
|
|
654
|
+
operation: "stop",
|
|
655
|
+
reason: "corrupt",
|
|
656
|
+
cause
|
|
657
|
+
})));
|
|
658
|
+
});
|
|
659
|
+
/** Wait for the exact Receipt. Interrupting this Effect never cancels accepted work. */
|
|
660
|
+
const awaitWorker = (declaration, worker, receipt) => operations(declaration).observe("await", worker, receipt);
|
|
661
|
+
/** List only workers visible through the caller-bound host facet. */
|
|
662
|
+
const list = (declaration, options = {}) => operations(declaration).list(options);
|
|
663
|
+
/** Request cancellation of exactly one Receipt; JoinedToHost remains a typed conflict. */
|
|
664
|
+
const cancel = (declaration, worker, receipt) => operations(declaration).cancel(worker, receipt);
|
|
665
|
+
const ReceiptParameters = (declaration) => Schema.Struct({
|
|
666
|
+
worker: Worker(declaration),
|
|
667
|
+
receipt: Receipt
|
|
668
|
+
});
|
|
669
|
+
const InspectParameters = (declaration) => Schema.Struct({
|
|
670
|
+
worker: Worker(declaration),
|
|
671
|
+
message: Schema.optionalKey(MessageRef),
|
|
672
|
+
receipt: Schema.optionalKey(Receipt)
|
|
673
|
+
}).check(Schema.makeFilter(({ message, receipt }) => message === void 0 !== (receipt === void 0), { message: "Provide exactly one retained message reference or accepted receipt" }));
|
|
674
|
+
const Inspection = (success) => Schema.Union([MessageStatus, toolObservation(success)]);
|
|
675
|
+
const WorkerParameters = (declaration) => Schema.Struct({ worker: Worker(declaration) });
|
|
676
|
+
const Summary = (declaration) => Schema.Struct({
|
|
677
|
+
...WorkerSummary.fields,
|
|
678
|
+
worker: Worker(declaration)
|
|
679
|
+
});
|
|
680
|
+
const FollowUpParameters = (declaration, parameters) => Schema.Struct({
|
|
681
|
+
worker: Worker(declaration),
|
|
682
|
+
parameters
|
|
683
|
+
});
|
|
684
|
+
const ListParameters = Schema.Struct({
|
|
685
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100))),
|
|
686
|
+
after: Schema.optionalKey(ThreadId)
|
|
687
|
+
});
|
|
688
|
+
const Started = (declaration) => Schema.Struct({
|
|
689
|
+
worker: Worker(declaration),
|
|
690
|
+
delivery: MessageStatus
|
|
691
|
+
}).check(Schema.makeFilter(({ worker, delivery }) => delivery.receipt === null || worker.threadId === delivery.receipt.threadId));
|
|
692
|
+
const Page = (declaration) => Schema.Struct({
|
|
693
|
+
items: Schema.Array(Schema.Struct({
|
|
694
|
+
worker: Worker(declaration),
|
|
695
|
+
latestReceipt: Schema.NullOr(Receipt),
|
|
696
|
+
state: Schema.Literals([
|
|
697
|
+
"starting",
|
|
698
|
+
"active",
|
|
699
|
+
"idle"
|
|
700
|
+
])
|
|
701
|
+
})).check(Schema.isMaxLength(100)),
|
|
702
|
+
next: Schema.NullOr(ThreadId)
|
|
703
|
+
});
|
|
704
|
+
const preparationFailure = (failure) => Schema.Union([
|
|
705
|
+
failure,
|
|
706
|
+
SubagentProjectionFailure,
|
|
707
|
+
WorkerError
|
|
708
|
+
]);
|
|
709
|
+
const startFailure = (failure) => Schema.Union([
|
|
710
|
+
failure,
|
|
711
|
+
SubagentProjectionFailure,
|
|
712
|
+
SubagentPrestartDenied,
|
|
713
|
+
WorkerError
|
|
714
|
+
]);
|
|
715
|
+
const cancelFailure = Schema.Union([WorkerError, JoinedToHost]);
|
|
716
|
+
const modelKey = Effect.fn("Subagent.workerToolKey")(function* (operation) {
|
|
717
|
+
const caller = yield* (yield* host).context;
|
|
718
|
+
if (caller.source._tag !== "tool") return yield* WorkerError.make({
|
|
719
|
+
operation,
|
|
720
|
+
reason: "denied"
|
|
721
|
+
});
|
|
722
|
+
const source = caller.source;
|
|
723
|
+
const crypto = yield* Crypto.Crypto;
|
|
724
|
+
const bytes = utf8Bytes(JSON.stringify([
|
|
725
|
+
"worker-tool-v1",
|
|
726
|
+
operation,
|
|
727
|
+
source.agentId,
|
|
728
|
+
source.threadId,
|
|
729
|
+
source.runId,
|
|
730
|
+
source.toolCallId
|
|
731
|
+
]));
|
|
732
|
+
const digest = yield* crypto.digest("SHA-256", bytes).pipe(Effect.mapError(() => WorkerError.make({
|
|
733
|
+
operation,
|
|
734
|
+
reason: "unavailable"
|
|
735
|
+
})));
|
|
736
|
+
return yield* Schema.decodeEffect(IdempotencyKey)(`worker:${Encoding.encodeHex(digest)}`).pipe(Effect.mapError(() => WorkerError.make({
|
|
737
|
+
operation,
|
|
738
|
+
reason: "unavailable"
|
|
739
|
+
})));
|
|
740
|
+
});
|
|
741
|
+
let reportingServiceId = 0;
|
|
742
|
+
/**
|
|
743
|
+
* Derive optional native AI Tools and their handler Layer from one immutable declaration.
|
|
744
|
+
* Projection services are captured by the Layer; the host and stable-key Crypto service remain
|
|
745
|
+
* invocation dependencies. The attached `.tool` and its suspension behavior are unchanged.
|
|
746
|
+
*/
|
|
747
|
+
const background$1 = (declaration, selected) => {
|
|
748
|
+
const report = selected.reportToParent === true ? automaticReporting(declaration) : void 0;
|
|
749
|
+
const reportService = Context.Service(`@effect-agent/capabilities/BackgroundReport/${declaration.name}/${reportingServiceId++}`);
|
|
750
|
+
const descriptor = report === void 0 ? void 0 : {
|
|
751
|
+
...report,
|
|
752
|
+
prepare: (value) => Effect.flatMap(Effect.serviceOption(reportService), (service) => Option.isSome(service) ? service.value.prepare(value) : WorkerReportPreparationFailure.make({ stage: "preparation" }))
|
|
753
|
+
};
|
|
754
|
+
const ops = operations(declaration);
|
|
755
|
+
const failure = preparationFailure(declaration.failure);
|
|
756
|
+
const receiptParameters = ReceiptParameters(declaration);
|
|
757
|
+
const startTool = Tool.make(`${declaration.name}_start`, {
|
|
758
|
+
description: `Retain input for a background ${declaration.name} worker and return its delivery state. Pending confirms retention only; inspect the same message instead of starting another worker.`,
|
|
759
|
+
parameters: declaration.parameters,
|
|
760
|
+
success: Started(declaration),
|
|
761
|
+
failure: startFailure(declaration.failure)
|
|
762
|
+
}).annotate(WorkerOperationTool, true).annotate(BackgroundSpawnTool, true).addDependency(SubagentHost).addDependency(Crypto.Crypto);
|
|
763
|
+
const followUpTool = Tool.make(`${declaration.name}_follow_up`, {
|
|
764
|
+
description: `Retain typed follow-up input for an existing ${declaration.name} worker. Pending is retained, not executed: inspect the same message instead of sending the command again.`,
|
|
765
|
+
parameters: FollowUpParameters(declaration, declaration.parameters),
|
|
766
|
+
success: MessageStatus,
|
|
767
|
+
failure
|
|
768
|
+
}).annotate(WorkerOperationTool, true).addDependency(SubagentHost).addDependency(Crypto.Crypto);
|
|
769
|
+
const inspectTool = Tool.make(`${declaration.name}_inspect`, {
|
|
770
|
+
description: `Inspect one ${declaration.name} delivery by message reference, or its execution result by accepted receipt. Provide exactly one reference; inspection never resends input.`,
|
|
771
|
+
parameters: InspectParameters(declaration),
|
|
772
|
+
success: Inspection(declaration.success),
|
|
773
|
+
failure
|
|
774
|
+
}).annotate(WorkerOperationTool, true).addDependency(SubagentHost);
|
|
775
|
+
const summaryTool = Tool.make(`${declaration.name}_summary`, {
|
|
776
|
+
description: `Inspect ${declaration.name}'s continuing worker state and latest accepted input.`,
|
|
777
|
+
parameters: WorkerParameters(declaration),
|
|
778
|
+
success: Summary(declaration),
|
|
779
|
+
failure: WorkerError
|
|
780
|
+
}).annotate(WorkerOperationTool, true).addDependency(SubagentHost);
|
|
781
|
+
const listTool = Tool.make(`${declaration.name}_list`, {
|
|
782
|
+
description: `List visible ${declaration.name} workers.`,
|
|
783
|
+
parameters: ListParameters,
|
|
784
|
+
success: Page(declaration),
|
|
785
|
+
failure: WorkerError
|
|
786
|
+
}).annotate(WorkerOperationTool, true).addDependency(SubagentHost);
|
|
787
|
+
const cancelTool = Tool.make(`${declaration.name}_cancel`, {
|
|
788
|
+
description: `Request cancellation of one exact ${declaration.name} Receipt.`,
|
|
789
|
+
parameters: receiptParameters,
|
|
790
|
+
success: Schema.Void,
|
|
791
|
+
failure: cancelFailure
|
|
792
|
+
}).annotate(WorkerOperationTool, true).addDependency(SubagentHost);
|
|
793
|
+
const chosen = Object.entries({
|
|
794
|
+
start: startTool,
|
|
795
|
+
followUp: followUpTool,
|
|
796
|
+
inspect: inspectTool,
|
|
797
|
+
summary: summaryTool,
|
|
798
|
+
list: listTool,
|
|
799
|
+
cancel: cancelTool
|
|
800
|
+
}).filter(([operation]) => selected[operation] === true).map(([, tool]) => tool.annotate(BackgroundReporting, descriptor));
|
|
801
|
+
const toolkit = Toolkit.make(...chosen);
|
|
802
|
+
const build = Effect.gen(function* () {
|
|
803
|
+
const captured = yield* Effect.context();
|
|
804
|
+
return {
|
|
805
|
+
[startTool.name]: (parameters) => Effect.gen(function* () {
|
|
806
|
+
const service = yield* host;
|
|
807
|
+
const idempotencyKey = yield* modelKey("start");
|
|
808
|
+
return yield* ops.start(parameters, {
|
|
809
|
+
idempotencyKey,
|
|
810
|
+
...selected.budgetScope === void 0 ? {} : { budgetScope: selected.budgetScope }
|
|
811
|
+
}).pipe(Effect.provideService(SubagentHost, service), Effect.provide(captured));
|
|
812
|
+
}),
|
|
813
|
+
[followUpTool.name]: (parameters) => Effect.gen(function* () {
|
|
814
|
+
const service = yield* host;
|
|
815
|
+
const idempotencyKey = yield* modelKey("followUp");
|
|
816
|
+
return yield* ops.followUp(parameters.worker, parameters.parameters, { idempotencyKey }).pipe(Effect.provideService(SubagentHost, service), Effect.provide(captured));
|
|
817
|
+
}),
|
|
818
|
+
[inspectTool.name]: (parameters) => Effect.gen(function* () {
|
|
819
|
+
const service = yield* host;
|
|
820
|
+
if (parameters.message !== void 0) return yield* ops.inspectMessage(parameters.worker, parameters.message);
|
|
821
|
+
if (parameters.receipt === void 0) return yield* WorkerError.make({
|
|
822
|
+
operation: "inspect",
|
|
823
|
+
reason: "message-mismatch"
|
|
824
|
+
});
|
|
825
|
+
return yield* ops.observe("inspect", parameters.worker, parameters.receipt).pipe(Effect.map((observed) => {
|
|
826
|
+
if ("diagnostic" in observed) {
|
|
827
|
+
const { diagnostic: _diagnostic, ...projected } = observed;
|
|
828
|
+
return projected;
|
|
829
|
+
}
|
|
830
|
+
return observed;
|
|
831
|
+
}), Effect.provideService(SubagentHost, service), Effect.provide(captured));
|
|
832
|
+
}),
|
|
833
|
+
[listTool.name]: (parameters) => ops.list(parameters),
|
|
834
|
+
[summaryTool.name]: (parameters) => summary(declaration, parameters.worker),
|
|
835
|
+
[cancelTool.name]: (parameters) => ops.cancel(parameters.worker, parameters.receipt)
|
|
836
|
+
};
|
|
837
|
+
});
|
|
838
|
+
const reportingLayer = report === void 0 ? Layer.empty : Layer.effect(reportService, Effect.map(Effect.context(), (context) => ({
|
|
839
|
+
...report,
|
|
840
|
+
prepare: (value) => Effect.scoped(Effect.suspend(() => report.prepare(value))).pipe(Effect.provide(context), Effect.mapError((error) => Schema.is(WorkerReportPreparationFailure)(error) ? error : WorkerReportPreparationFailure.make({ stage: "preparation" })))
|
|
841
|
+
})));
|
|
842
|
+
const layer = Layer.merge(toolkit.toLayer(build), reportingLayer);
|
|
843
|
+
return Object.freeze({
|
|
844
|
+
tools: toolkit.tools,
|
|
845
|
+
toolkit,
|
|
846
|
+
layer
|
|
847
|
+
});
|
|
848
|
+
};
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/capabilities/Subagent.ts
|
|
851
|
+
var Subagent_exports = /* @__PURE__ */ __exportAll({
|
|
852
|
+
SubagentDurableAccounting: () => SubagentDurableAccounting,
|
|
853
|
+
SubagentExecutionFailure: () => SubagentExecutionFailure,
|
|
854
|
+
SubagentExecutionFailureClassification: () => SubagentExecutionFailureClassification,
|
|
855
|
+
SubagentGrant: () => SubagentGrant,
|
|
856
|
+
SubagentPolicy: () => SubagentPolicy,
|
|
857
|
+
SubagentPrestartDenied: () => SubagentPrestartDenied,
|
|
858
|
+
SubagentProjectionFailure: () => SubagentProjectionFailure,
|
|
859
|
+
SubagentResult: () => SubagentResult,
|
|
860
|
+
Worker: () => Worker,
|
|
861
|
+
WorkerCompletion: () => WorkerCompletion,
|
|
862
|
+
WorkerObservation: () => WorkerObservation,
|
|
863
|
+
WorkerReport: () => WorkerReport,
|
|
864
|
+
await: () => awaitWorker,
|
|
865
|
+
background: () => background,
|
|
866
|
+
cancel: () => cancel,
|
|
867
|
+
define: () => define,
|
|
868
|
+
delegationAllocationFromPolicy: () => delegationAllocationFromPolicy,
|
|
869
|
+
delegationCapsFromPolicy: () => delegationCapsFromPolicy,
|
|
870
|
+
followUp: () => followUp,
|
|
871
|
+
inspect: () => inspect,
|
|
872
|
+
layer: () => layer,
|
|
873
|
+
list: () => list,
|
|
874
|
+
make: () => make,
|
|
875
|
+
observe: () => observe,
|
|
876
|
+
start: () => start,
|
|
877
|
+
stop: () => stop
|
|
878
|
+
});
|
|
879
|
+
const decodeDelegationId = Schema.decodeSync(DelegationId);
|
|
880
|
+
/** Default delegation result, preserving partial-output information. */
|
|
881
|
+
const SubagentResult = (output) => Schema.Struct({
|
|
882
|
+
output,
|
|
883
|
+
budgetExhausted: Schema.Boolean
|
|
884
|
+
});
|
|
885
|
+
/**
|
|
886
|
+
* Declare one attached delegation as a pure value.
|
|
887
|
+
*
|
|
888
|
+
* The returned `.tool` is a native Effect AI Tool whose handler dependencies
|
|
889
|
+
* are exactly the engine-owned `AgentSpawner`, `RunEventSink`, and
|
|
890
|
+
* `SubagentDurability` (SUB-003); runtime IDs have an overridable default.
|
|
891
|
+
* The concrete child Binding arrives only through
|
|
892
|
+
* `Subagent.layer`. Throws on an invalid delegation name. Nested declarations remain inert unless the
|
|
893
|
+
* effective inherited grant and reserved subtree budget permit their lifetime and depth.
|
|
894
|
+
*/
|
|
895
|
+
const makeExplicit = (name, options) => {
|
|
896
|
+
const delegationId = decodeDelegationId(name);
|
|
897
|
+
const grant = options.grant ?? SubagentGrant.make({
|
|
898
|
+
allowedToolNames: Object.keys(options.target.toolkit.tools),
|
|
899
|
+
maxDepth: 1
|
|
900
|
+
});
|
|
901
|
+
const failureMode = options.failureMode ?? "error";
|
|
902
|
+
const containedFailure = Schema.Union([
|
|
903
|
+
options.failure,
|
|
904
|
+
SubagentPrestartDenied,
|
|
905
|
+
SubagentBudgetExhausted,
|
|
906
|
+
SubagentProjectionFailure,
|
|
907
|
+
SubagentExecutionFailure
|
|
908
|
+
]);
|
|
909
|
+
const returnModeTool = Tool.make(name, {
|
|
910
|
+
description: options.description,
|
|
911
|
+
parameters: options.parameters,
|
|
912
|
+
success: Schema.Union([options.success, containedFailure]),
|
|
913
|
+
failure: Schema.Union([ToolCallWaiting, SubagentDurabilityError]),
|
|
914
|
+
needsApproval: options.needsApproval
|
|
915
|
+
});
|
|
916
|
+
const errorModeTool = Tool.make(name, {
|
|
917
|
+
description: options.description,
|
|
918
|
+
parameters: options.parameters,
|
|
919
|
+
success: options.success,
|
|
920
|
+
failure: Schema.Union([
|
|
921
|
+
options.failure,
|
|
922
|
+
SubagentPrestartDenied,
|
|
923
|
+
SubagentBudgetExhausted,
|
|
924
|
+
SubagentProjectionFailure,
|
|
925
|
+
SubagentExecutionFailure,
|
|
926
|
+
ToolCallWaiting,
|
|
927
|
+
SubagentDurabilityError
|
|
928
|
+
]),
|
|
929
|
+
needsApproval: options.needsApproval
|
|
930
|
+
});
|
|
931
|
+
const tool = (failureMode === "return" ? returnModeTool : errorModeTool).annotate(DelegationTool, true).addDependency(AgentSpawner).addDependency(RunEventSink).addDependency(SubagentDurability).addDependency(IdGenerator$1);
|
|
932
|
+
return Object.freeze({
|
|
933
|
+
...options,
|
|
934
|
+
name,
|
|
935
|
+
delegationId,
|
|
936
|
+
grant,
|
|
937
|
+
failureMode,
|
|
938
|
+
containedFailure,
|
|
939
|
+
tool
|
|
940
|
+
});
|
|
941
|
+
};
|
|
942
|
+
function make(name, options) {
|
|
943
|
+
const success = options.success ?? SubagentResult(options.target.output);
|
|
944
|
+
const parameters = options.parameters ?? options.target.input;
|
|
945
|
+
const failure = options.failure ?? Schema.Never;
|
|
946
|
+
const inputValue = Schema.decodeUnknownEffect(Schema.toType(options.target.input));
|
|
947
|
+
const resultValue = Schema.decodeUnknownEffect(Schema.toType(success));
|
|
948
|
+
const needsApproval = options.needsApproval;
|
|
949
|
+
const prepareInput = options.prepareInput;
|
|
950
|
+
const projectResult = options.projectResult;
|
|
951
|
+
const projectionFailure = (stage) => SubagentProjectionFailure.make({
|
|
952
|
+
delegationId: decodeDelegationId(name),
|
|
953
|
+
stage,
|
|
954
|
+
message: stage === "input" ? "Delegation parameters did not satisfy the child input Schema" : "Child output did not satisfy the delegation success Schema"
|
|
955
|
+
});
|
|
956
|
+
const resolved = {
|
|
957
|
+
...options,
|
|
958
|
+
needsApproval: typeof needsApproval === "function" ? (input, context) => needsApproval(input, context) : needsApproval,
|
|
959
|
+
description: options.description ?? options.target.description,
|
|
960
|
+
parameters,
|
|
961
|
+
success,
|
|
962
|
+
failure,
|
|
963
|
+
prepareInput: (input, context) => prepareInput === void 0 ? inputValue(input).pipe(Effect.mapError(() => projectionFailure("input"))) : prepareInput(input, context),
|
|
964
|
+
projectResult: (output, context, input) => projectResult === void 0 ? resultValue({
|
|
965
|
+
output,
|
|
966
|
+
budgetExhausted: context.budgetExhausted
|
|
967
|
+
}).pipe(Effect.mapError(() => projectionFailure("result"))) : projectResult(output, context, input)
|
|
968
|
+
};
|
|
969
|
+
return options.failureMode === "return" ? makeExplicit(name, {
|
|
970
|
+
...resolved,
|
|
971
|
+
failureMode: "return"
|
|
972
|
+
}) : makeExplicit(name, {
|
|
973
|
+
...resolved,
|
|
974
|
+
failureMode: "error"
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
/** @deprecated Use `Subagent.make`. */
|
|
978
|
+
const define = make;
|
|
979
|
+
/**
|
|
980
|
+
* The conservative final accounting summary the durable delegation handler
|
|
981
|
+
* attaches to every settlement join. The handler has no live child usage stream at durable join
|
|
982
|
+
* time, so every dimension conservatively consumes its full reservation and
|
|
983
|
+
* releases nothing — unreported usage never creates budget. The coordinator
|
|
984
|
+
* owns the canonical accounting decision on `SubagentJoined` and may replace
|
|
985
|
+
* structural dimensions from canonical child evidence; this value is opaque
|
|
986
|
+
* encoded policy math to the engine and to storage adapters (D8).
|
|
987
|
+
*/
|
|
988
|
+
var SubagentDurableAccounting = class extends Schema.Class("@effect-agent/capabilities/SubagentDurableAccounting")({
|
|
989
|
+
/** The per-invocation allocation reserved at establishment. */
|
|
990
|
+
allocation: SubagentReservationAmounts,
|
|
991
|
+
/** Final consumed decision per dimension. */
|
|
992
|
+
consumed: SubagentReservationAmounts,
|
|
993
|
+
/** Amounts returned to the parent: `allocation - consumed` per dimension. */
|
|
994
|
+
released: SubagentReservationAmounts,
|
|
995
|
+
/** How the decision was computed; the handler only ever reports conservatively. */
|
|
996
|
+
basis: Schema.Literals(["reserved-conservative"])
|
|
997
|
+
}) {};
|
|
998
|
+
const maxEventTextLength = 4096;
|
|
999
|
+
const boundedEventText = (text) => text.length <= maxEventTextLength ? text : `${text.slice(0, 4095)}…`;
|
|
1000
|
+
const ErrorMessage = Schema.Struct({ message: Schema.String });
|
|
1001
|
+
const ErrorTag = Schema.Struct({ _tag: Schema.NonEmptyString });
|
|
1002
|
+
const errorMessageOf = (error) => Option.match(Schema.decodeUnknownOption(ErrorMessage)(error), {
|
|
1003
|
+
onNone: () => String(error),
|
|
1004
|
+
onSome: ({ message }) => message
|
|
1005
|
+
});
|
|
1006
|
+
const errorTagOf = (error) => Option.match(Schema.decodeUnknownOption(ErrorTag)(error), {
|
|
1007
|
+
onNone: () => "UnknownError",
|
|
1008
|
+
onSome: ({ _tag }) => _tag
|
|
1009
|
+
});
|
|
1010
|
+
const boundedErrorTag = (tag) => {
|
|
1011
|
+
const nonEmpty = tag.length === 0 ? "UnknownError" : tag;
|
|
1012
|
+
return nonEmpty.length <= 256 ? nonEmpty : nonEmpty.slice(0, 256);
|
|
1013
|
+
};
|
|
1014
|
+
/**
|
|
1015
|
+
* The coordinator's bounded projection of a failed/aborted child Settlement
|
|
1016
|
+
* result (S2 plan §1.6, D5): `{errorTag, message}`, never a raw Cause. The
|
|
1017
|
+
* fallback tolerates any other bounded shape without ever surfacing the raw
|
|
1018
|
+
* value beyond a tag and message.
|
|
1019
|
+
*/
|
|
1020
|
+
const ChildFailureProjection = Schema.Struct({
|
|
1021
|
+
errorTag: Schema.NonEmptyString,
|
|
1022
|
+
message: Schema.String
|
|
1023
|
+
});
|
|
1024
|
+
const childFailureProjectionOf = (encodedResult) => Option.match(Schema.decodeUnknownOption(ChildFailureProjection)(encodedResult), {
|
|
1025
|
+
onNone: () => ({
|
|
1026
|
+
errorTag: errorTagOf(encodedResult),
|
|
1027
|
+
message: errorMessageOf(encodedResult)
|
|
1028
|
+
}),
|
|
1029
|
+
onSome: (projection) => projection
|
|
1030
|
+
});
|
|
1031
|
+
const zeroReservationAmounts = SubagentReservationAmounts.make({
|
|
1032
|
+
turns: 0,
|
|
1033
|
+
toolCalls: 0,
|
|
1034
|
+
durationMillis: 0,
|
|
1035
|
+
inputTokens: 0,
|
|
1036
|
+
outputTokens: 0,
|
|
1037
|
+
costMicrousd: 0,
|
|
1038
|
+
resultBytes: 0
|
|
1039
|
+
});
|
|
1040
|
+
const encodeDurableAccounting = Schema.encodeEffect(SubagentDurableAccounting);
|
|
1041
|
+
const encodeProjectionFailure = Schema.encodeEffect(SubagentProjectionFailure);
|
|
1042
|
+
const encodeBudgetFailure = Schema.encodeEffect(SubagentBudgetExhausted);
|
|
1043
|
+
const encodeExecutionFailure = Schema.encodeEffect(SubagentExecutionFailure);
|
|
1044
|
+
const encodeGrant = Schema.encodeEffect(SubagentGrant);
|
|
1045
|
+
const encodeAllocationAmounts = Schema.encodeEffect(SubagentReservationAmounts);
|
|
1046
|
+
const toNatural = (value) => Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
1047
|
+
const observedUsageFromDelta = (delta) => SubagentObservedUsage.make({
|
|
1048
|
+
turns: delta.modelCalls,
|
|
1049
|
+
toolCalls: toNatural(delta.toolCalls),
|
|
1050
|
+
inputTokens: toNatural(delta.inputTokens),
|
|
1051
|
+
outputTokens: toNatural(delta.outputTokens),
|
|
1052
|
+
costMicrousd: toNatural(delta.costMicrousd)
|
|
1053
|
+
});
|
|
1054
|
+
/** A child that never started consumed nothing; observing zeros releases everything. */
|
|
1055
|
+
const neverStartedUsage = SubagentObservedUsage.make({
|
|
1056
|
+
turns: 0,
|
|
1057
|
+
toolCalls: 0,
|
|
1058
|
+
durationMillis: 0,
|
|
1059
|
+
inputTokens: 0,
|
|
1060
|
+
outputTokens: 0,
|
|
1061
|
+
costMicrousd: 0,
|
|
1062
|
+
resultBytes: 0
|
|
1063
|
+
});
|
|
1064
|
+
/**
|
|
1065
|
+
* Finalizer-driven settlement: observe honest final usage, then release the
|
|
1066
|
+
* unused allocation exactly once. Runs on every handler exit path — success,
|
|
1067
|
+
* declared failure, interruption, and defect — through the reservation's
|
|
1068
|
+
* `Effect.acquireRelease`; a missing reservation after a successful reserve
|
|
1069
|
+
* is a ledger invariant violation and therefore a defect.
|
|
1070
|
+
*/
|
|
1071
|
+
const settleReservation = (reservations, reservationId, startedAt, conservative) => Effect.gen(function* () {
|
|
1072
|
+
const started = yield* Ref.get(startedAt);
|
|
1073
|
+
if (started === void 0) yield* reservations.observe(reservationId, neverStartedUsage);
|
|
1074
|
+
else {
|
|
1075
|
+
const now = yield* Clock.currentTimeMillis;
|
|
1076
|
+
yield* reservations.observe(reservationId, SubagentObservedUsage.make({ durationMillis: Math.max(0, Math.floor(now - started)) }));
|
|
1077
|
+
}
|
|
1078
|
+
if (started !== void 0 && conservative !== void 0) {
|
|
1079
|
+
const own = (yield* reservations.parentSnapshot(conservative.parentRunId)).reservations.find((entry) => entry.reservationId === reservationId);
|
|
1080
|
+
if (own === void 0) return yield* Effect.die("Missing subtree reservation during finalization");
|
|
1081
|
+
const additional = (key) => Math.max(0, conservative.allocation[key] - (own.observedConsumed[key] ?? 0));
|
|
1082
|
+
yield* reservations.observe(reservationId, SubagentObservedUsage.make({
|
|
1083
|
+
turns: additional("turns"),
|
|
1084
|
+
toolCalls: additional("toolCalls"),
|
|
1085
|
+
durationMillis: additional("durationMillis"),
|
|
1086
|
+
inputTokens: additional("inputTokens"),
|
|
1087
|
+
outputTokens: additional("outputTokens"),
|
|
1088
|
+
costMicrousd: additional("costMicrousd"),
|
|
1089
|
+
resultBytes: additional("resultBytes")
|
|
1090
|
+
}));
|
|
1091
|
+
}
|
|
1092
|
+
yield* reservations.release(reservationId);
|
|
1093
|
+
}).pipe(Effect.orDie);
|
|
1094
|
+
/**
|
|
1095
|
+
* Module-private provenance wrapper (SUB-033 hardening): ONLY the operations
|
|
1096
|
+
* that can genuinely produce the engine signals wrap them here, so
|
|
1097
|
+
* containment classification never trusts the runtime identity of classes an
|
|
1098
|
+
* author could declare in their own failure Schema — a spoofed
|
|
1099
|
+
* `ToolCallWaiting` in author data is contained as data, never rethrown as a
|
|
1100
|
+
* suspension signal.
|
|
1101
|
+
*/
|
|
1102
|
+
var GenuineEngineSignal = class {
|
|
1103
|
+
signal;
|
|
1104
|
+
_tag = "GenuineEngineSignal";
|
|
1105
|
+
constructor(signal) {
|
|
1106
|
+
this.signal = signal;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
const wrapEngineSignal = (signal) => new GenuineEngineSignal(signal);
|
|
1110
|
+
function layer(delegation, modelOrBinding, options = {}) {
|
|
1111
|
+
const childBinding = modelOrBinding !== void 0 && "definition" in modelOrBinding ? modelOrBinding : {
|
|
1112
|
+
definition: delegation.target,
|
|
1113
|
+
model: modelOrBinding ?? Layer.effectContext(Effect.context())
|
|
1114
|
+
};
|
|
1115
|
+
if (childBinding.definition !== delegation.target) throw new Error("Subagent.layer requires the delegation's exact target Definition");
|
|
1116
|
+
const resolvePolicy = (spawner) => resolveSubagentPolicy(delegation, spawner.policy, options.parentCaps, spawner.depth === 0 && spawner.budget === void 0 ? "root-attached" : "conserved");
|
|
1117
|
+
const toolkit = Toolkit.make(delegation.tool);
|
|
1118
|
+
const contained = delegation.failureMode === "return";
|
|
1119
|
+
const encodeChildInput = Schema.encodeEffect(delegation.target.input);
|
|
1120
|
+
const encodeSuccess = Schema.encodeEffect(delegation.success);
|
|
1121
|
+
const decodeChildOutput = Schema.decodeUnknownEffect(delegation.target.output);
|
|
1122
|
+
const encodeResultProjectionFailure = Schema.encodeEffect(Schema.Union([delegation.failure, SubagentProjectionFailure]));
|
|
1123
|
+
const childToolCallAllowance = (parameters, policy, childPolicy) => resolveToolCallAllowance(delegation.toolCallAllowance, parameters, policy, childPolicy);
|
|
1124
|
+
const durableDeclaration = options.durable === void 0 ? void 0 : { targetDigests: {
|
|
1125
|
+
agent: options.durable.targetDigests.agent,
|
|
1126
|
+
model: options.durable.targetDigests.model,
|
|
1127
|
+
tools: options.durable.targetDigests.tools
|
|
1128
|
+
} };
|
|
1129
|
+
const executionFailure = (classification, errorTag, message, child) => SubagentExecutionFailure.make({
|
|
1130
|
+
delegationId: delegation.delegationId,
|
|
1131
|
+
targetAgentId: delegation.target.id,
|
|
1132
|
+
classification,
|
|
1133
|
+
errorTag: boundedErrorTag(errorTag),
|
|
1134
|
+
message: boundedEventText(message),
|
|
1135
|
+
...child === void 0 ? {} : {
|
|
1136
|
+
childThreadId: child.childThreadId,
|
|
1137
|
+
childSubmissionId: child.childSubmissionId,
|
|
1138
|
+
childRunId: child.childRunId
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
const prestartDenied = (reason, message) => SubagentPrestartDenied.make({
|
|
1142
|
+
delegationId: delegation.delegationId,
|
|
1143
|
+
targetAgentId: delegation.target.id,
|
|
1144
|
+
reason,
|
|
1145
|
+
message: boundedEventText(message)
|
|
1146
|
+
});
|
|
1147
|
+
const build = Effect.gen(function* () {
|
|
1148
|
+
const captured = yield* Effect.context();
|
|
1149
|
+
const invoke = Effect.fn(`SubagentRuntime.${delegation.name}`)(function* (parameters, handlerContext) {
|
|
1150
|
+
const spawner = yield* AgentSpawner;
|
|
1151
|
+
const resolved = resolvePolicy(spawner);
|
|
1152
|
+
const { policy, childPolicy, allocation } = resolved;
|
|
1153
|
+
const caps = spawner.budget === void 0 ? resolved.caps : residualSubagentCaps(resolved.caps, spawner.policy, spawner.budget, spawner.budgetScope === "worker-run");
|
|
1154
|
+
const sink = yield* RunEventSink;
|
|
1155
|
+
const reservations = yield* SubagentReservations;
|
|
1156
|
+
const toolCallId = yield* Schema.decodeUnknownEffect(ToolCallId)(handlerContext.toolCallId).pipe(Effect.orDie);
|
|
1157
|
+
const grant = narrowSubagentGrant(delegation.grant, spawner.grant);
|
|
1158
|
+
const depth = spawner.depth + 1;
|
|
1159
|
+
if (depth > grant.maxDepth) return yield* prestartDenied("nested-delegation", "Delegation exceeds the inherited depth ceiling");
|
|
1160
|
+
if (!(spawner.grant?.childLifetimes ?? ["attached", "background"]).includes("attached")) return yield* prestartDenied("grant-violation", "The inherited grant does not permit attached children");
|
|
1161
|
+
if (spawner.depth > 0 && spawner.budget === void 0) return yield* prestartDenied("budget-conflict", "Nested ephemeral delegation requires an inherited subtree reservation");
|
|
1162
|
+
const prepared = yield* delegation.prepareInput(parameters, {
|
|
1163
|
+
source: "tool",
|
|
1164
|
+
delegationId: delegation.delegationId,
|
|
1165
|
+
toolCallId,
|
|
1166
|
+
parent: spawner.parent
|
|
1167
|
+
});
|
|
1168
|
+
const encodedInput = yield* encodeChildInput(prepared).pipe(Effect.mapError(() => SubagentProjectionFailure.make({
|
|
1169
|
+
delegationId: delegation.delegationId,
|
|
1170
|
+
stage: "input",
|
|
1171
|
+
message: "Prepared child input did not satisfy the target Agent input Schema"
|
|
1172
|
+
})));
|
|
1173
|
+
const parentRunId = spawner.parent.runId;
|
|
1174
|
+
yield* reservations.registerParent(parentRunId, caps).pipe(Effect.catchTag("SubagentParentBudgetConflict", () => Effect.fail(prestartDenied("budget-conflict", "The parent Run is already registered with different delegation caps; supply shared parentCaps explicitly"))));
|
|
1175
|
+
const reservationId = makeBudgetReservationId(parentRunId, toolCallId);
|
|
1176
|
+
const startedAt = yield* Ref.make(void 0);
|
|
1177
|
+
yield* Effect.acquireRelease(reservations.reserve(SubagentReservationRequest.make({
|
|
1178
|
+
parentRunId,
|
|
1179
|
+
parentToolCallId: toolCallId,
|
|
1180
|
+
allocation,
|
|
1181
|
+
...policy.descendantInvocations === void 0 ? {} : { descendantInvocations: policy.descendantInvocations }
|
|
1182
|
+
})).pipe(Effect.catchTags({
|
|
1183
|
+
SubagentReservationConflict: (conflict) => Effect.die(conflict),
|
|
1184
|
+
SubagentParentBudgetUnknown: (unknown) => Effect.die(unknown)
|
|
1185
|
+
})), () => settleReservation(reservations, reservationId, startedAt, (policy.descendantInvocations ?? 0) > 0 ? {
|
|
1186
|
+
parentRunId,
|
|
1187
|
+
allocation
|
|
1188
|
+
} : void 0));
|
|
1189
|
+
yield* reservations.acquireChildSlot(parentRunId, 1 + (policy.descendantInvocations ?? 0)).pipe(Effect.catchTag("SubagentParentBudgetUnknown", (unknown) => Effect.die(unknown)));
|
|
1190
|
+
const seededChild = options.child;
|
|
1191
|
+
const seededBudget = seededChild?.budget;
|
|
1192
|
+
const budget = {
|
|
1193
|
+
guard: seededBudget === void 0 ? (effect) => effect : (effect) => seededBudget.guard(effect),
|
|
1194
|
+
consume: (delta) => reservations.observe(reservationId, observedUsageFromDelta(delta)).pipe(Effect.orDie, Effect.andThen(seededBudget === void 0 ? Effect.void : seededBudget.consume(delta)))
|
|
1195
|
+
};
|
|
1196
|
+
const toolCallAllowance = childToolCallAllowance(parameters, policy, childPolicy);
|
|
1197
|
+
const childOptions = {
|
|
1198
|
+
...seededChild,
|
|
1199
|
+
subagentGrant: grant,
|
|
1200
|
+
delegationDepth: depth,
|
|
1201
|
+
subagentBudget: SubagentBudgetReservation.make({
|
|
1202
|
+
caps,
|
|
1203
|
+
allocation,
|
|
1204
|
+
...policy.descendantInvocations === void 0 ? {} : { descendantInvocations: policy.descendantInvocations }
|
|
1205
|
+
}),
|
|
1206
|
+
budget,
|
|
1207
|
+
...toolCallAllowance === void 0 ? {} : { toolCallAllowance }
|
|
1208
|
+
};
|
|
1209
|
+
yield* Ref.set(startedAt, yield* Clock.currentTimeMillis);
|
|
1210
|
+
const childScope = yield* Scope.make();
|
|
1211
|
+
yield* Effect.addFinalizer((exit) => Scope.close(childScope, exit));
|
|
1212
|
+
const child = yield* spawner.spawn({
|
|
1213
|
+
...childBinding,
|
|
1214
|
+
definition: {
|
|
1215
|
+
...childBinding.definition,
|
|
1216
|
+
policy: childPolicy
|
|
1217
|
+
}
|
|
1218
|
+
}, encodedInput, {
|
|
1219
|
+
delegationId: delegation.delegationId,
|
|
1220
|
+
parentToolCallId: toolCallId
|
|
1221
|
+
}, childOptions).pipe(Scope.provide(childScope));
|
|
1222
|
+
const payload = {
|
|
1223
|
+
toolCallId,
|
|
1224
|
+
delegationId: delegation.delegationId,
|
|
1225
|
+
childThreadId: child.threadId,
|
|
1226
|
+
childRunId: child.runId,
|
|
1227
|
+
targetAgentId: delegation.target.id,
|
|
1228
|
+
depth: child.parentLink.depth
|
|
1229
|
+
};
|
|
1230
|
+
const emit = (event) => sink.emit(event).pipe(Effect.orDie);
|
|
1231
|
+
yield* emit({
|
|
1232
|
+
_tag: "SubagentRequested",
|
|
1233
|
+
...payload
|
|
1234
|
+
});
|
|
1235
|
+
yield* emit({
|
|
1236
|
+
_tag: "SubagentStarted",
|
|
1237
|
+
...payload
|
|
1238
|
+
});
|
|
1239
|
+
return yield* Effect.gen(function* () {
|
|
1240
|
+
const result = yield* child.await.pipe(Effect.catch((childFailure) => child.usageReport.pipe(Effect.flatMap((report) => emit({
|
|
1241
|
+
_tag: "SubagentFailed",
|
|
1242
|
+
...payload,
|
|
1243
|
+
...report,
|
|
1244
|
+
errorTag: errorTagOf(childFailure),
|
|
1245
|
+
message: boundedEventText(errorMessageOf(childFailure))
|
|
1246
|
+
})), Effect.andThen(Effect.fail(options.mapChildFailure === void 0 ? executionFailure("child-failed", errorTagOf(childFailure), "The child Run failed") : options.mapChildFailure(childFailure))))), Effect.timeoutOrElse({
|
|
1247
|
+
duration: Duration.millis(allocation.durationMillis),
|
|
1248
|
+
orElse: () => Effect.succeed(void 0)
|
|
1249
|
+
}), Effect.tapCause((cause) => Cause.hasDies(cause) ? child.usageReport.pipe(Effect.flatMap((report) => emit({
|
|
1250
|
+
_tag: "SubagentFailed",
|
|
1251
|
+
...payload,
|
|
1252
|
+
...report,
|
|
1253
|
+
errorTag: "Defect",
|
|
1254
|
+
message: "The child Run ended with a defect"
|
|
1255
|
+
})), Effect.ignore) : Effect.void));
|
|
1256
|
+
if (result === void 0) {
|
|
1257
|
+
yield* Scope.close(childScope, Exit.void);
|
|
1258
|
+
const report = yield* child.usageReport;
|
|
1259
|
+
yield* emit({
|
|
1260
|
+
_tag: "SubagentFailed",
|
|
1261
|
+
...payload,
|
|
1262
|
+
...report,
|
|
1263
|
+
errorTag: "SubagentBudgetExhausted",
|
|
1264
|
+
message: `Attached child exceeded its ${allocation.durationMillis}ms delegation duration budget`
|
|
1265
|
+
});
|
|
1266
|
+
return yield* SubagentBudgetExhausted.make({
|
|
1267
|
+
parentRunId,
|
|
1268
|
+
dimension: "duration",
|
|
1269
|
+
limitValue: allocation.durationMillis,
|
|
1270
|
+
observedValue: allocation.durationMillis
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
const report = yield* child.usageReport;
|
|
1274
|
+
yield* emit({
|
|
1275
|
+
_tag: "SubagentCompleted",
|
|
1276
|
+
...payload,
|
|
1277
|
+
...report,
|
|
1278
|
+
turns: result.turns,
|
|
1279
|
+
finishReason: result.finishReason,
|
|
1280
|
+
...result.exhausted !== void 0 ? { exhausted: result.exhausted } : {}
|
|
1281
|
+
});
|
|
1282
|
+
const projected = yield* delegation.projectResult(result.output, {
|
|
1283
|
+
budgetExhausted: result.finishReason === "budget-exhausted",
|
|
1284
|
+
...report
|
|
1285
|
+
}, parameters);
|
|
1286
|
+
const encodedResult = yield* encodeSuccess(projected).pipe(Effect.mapError(() => SubagentProjectionFailure.make({
|
|
1287
|
+
delegationId: delegation.delegationId,
|
|
1288
|
+
stage: "result",
|
|
1289
|
+
message: "Projected child result did not satisfy the delegation success Schema"
|
|
1290
|
+
})));
|
|
1291
|
+
const resultBytes = utf8ByteLength(JSON.stringify(encodedResult) ?? "");
|
|
1292
|
+
yield* reservations.observe(reservationId, SubagentObservedUsage.make({ resultBytes })).pipe(Effect.orDie);
|
|
1293
|
+
if (policy.maxResultBytes !== void 0 && resultBytes > policy.maxResultBytes) {
|
|
1294
|
+
yield* emit({
|
|
1295
|
+
_tag: "SubagentFailed",
|
|
1296
|
+
...payload,
|
|
1297
|
+
...report,
|
|
1298
|
+
errorTag: "SubagentBudgetExhausted",
|
|
1299
|
+
message: `Projected child result of ${resultBytes} bytes exceeds the ${policy.maxResultBytes}-byte delegation budget`
|
|
1300
|
+
});
|
|
1301
|
+
return yield* SubagentBudgetExhausted.make({
|
|
1302
|
+
parentRunId,
|
|
1303
|
+
dimension: "result-bytes",
|
|
1304
|
+
limitValue: policy.maxResultBytes,
|
|
1305
|
+
observedValue: resultBytes
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
yield* emit({
|
|
1309
|
+
_tag: "SubagentJoined",
|
|
1310
|
+
...payload,
|
|
1311
|
+
...report
|
|
1312
|
+
});
|
|
1313
|
+
return projected;
|
|
1314
|
+
}).pipe(Effect.onInterrupt(() => Scope.close(childScope, Exit.void).pipe(Effect.andThen(child.usageReport), Effect.flatMap((report) => sink.emit({
|
|
1315
|
+
_tag: "SubagentInterrupted",
|
|
1316
|
+
...payload,
|
|
1317
|
+
...report,
|
|
1318
|
+
reason: "Parent Run interrupted the attached child before it settled"
|
|
1319
|
+
})), Effect.ignore)));
|
|
1320
|
+
});
|
|
1321
|
+
/**
|
|
1322
|
+
* Durable branch: establishment through the
|
|
1323
|
+
* coordinator's idempotent protocol instead of an in-process spawn. No
|
|
1324
|
+
* child fiber ever starts here, and the S1 in-memory reservation service
|
|
1325
|
+
* is deliberately not consulted — its Scope-finalizer settlement
|
|
1326
|
+
* contradicts a handler that exits with the waiting signal while the
|
|
1327
|
+
* child keeps running; durable budget lives in the coordinator's fenced
|
|
1328
|
+
* ledger reservation built from `encodedAllocation`.
|
|
1329
|
+
*/
|
|
1330
|
+
const invokeDurable = Effect.fn(`SubagentRuntime.${delegation.name}.durable`)(function* (parameters, handlerContext, durability) {
|
|
1331
|
+
const spawner = yield* AgentSpawner;
|
|
1332
|
+
const { policy, childPolicy, allocation, caps } = resolvePolicy(spawner);
|
|
1333
|
+
const encodedAllocation = yield* encodeAllocationAmounts(allocation).pipe(Effect.orDie);
|
|
1334
|
+
const conservativeAccounting = yield* encodeDurableAccounting(SubagentDurableAccounting.make({
|
|
1335
|
+
allocation,
|
|
1336
|
+
consumed: allocation,
|
|
1337
|
+
released: zeroReservationAmounts,
|
|
1338
|
+
basis: "reserved-conservative"
|
|
1339
|
+
})).pipe(Effect.orDie);
|
|
1340
|
+
const sink = yield* RunEventSink;
|
|
1341
|
+
const toolCallId = yield* Schema.decodeUnknownEffect(ToolCallId)(handlerContext.toolCallId).pipe(Effect.orDie);
|
|
1342
|
+
const emit = (event) => sink.emit(event).pipe(Effect.orDie);
|
|
1343
|
+
const grant = narrowSubagentGrant(delegation.grant, spawner.grant);
|
|
1344
|
+
const depth = spawner.depth + 1;
|
|
1345
|
+
if (depth > grant.maxDepth) return yield* prestartDenied("nested-delegation", "Delegation exceeds the inherited depth ceiling");
|
|
1346
|
+
if (!(spawner.grant?.childLifetimes ?? ["attached", "background"]).includes("attached")) return yield* prestartDenied("grant-violation", "The inherited grant does not permit attached children");
|
|
1347
|
+
const encodedGrant = yield* encodeGrant(grant).pipe(Effect.orDie);
|
|
1348
|
+
const prepared = yield* delegation.prepareInput(parameters, {
|
|
1349
|
+
source: "tool",
|
|
1350
|
+
delegationId: delegation.delegationId,
|
|
1351
|
+
toolCallId,
|
|
1352
|
+
parent: spawner.parent
|
|
1353
|
+
});
|
|
1354
|
+
const encodedInput = yield* encodeChildInput(prepared).pipe(Effect.mapError(() => SubagentProjectionFailure.make({
|
|
1355
|
+
delegationId: delegation.delegationId,
|
|
1356
|
+
stage: "input",
|
|
1357
|
+
message: "Prepared child input did not satisfy the target Agent input Schema"
|
|
1358
|
+
})));
|
|
1359
|
+
const status = yield* Effect.mapError(wrapEngineSignal)(durability.establish({
|
|
1360
|
+
toolCallId,
|
|
1361
|
+
delegationId: delegation.delegationId,
|
|
1362
|
+
target: delegation.target,
|
|
1363
|
+
targetAgentId: delegation.target.id,
|
|
1364
|
+
depth,
|
|
1365
|
+
...durableDeclaration === void 0 ? {} : { targetDigests: durableDeclaration.targetDigests },
|
|
1366
|
+
encodedChildInput: encodedInput,
|
|
1367
|
+
encodedGrant,
|
|
1368
|
+
encodedAllocation,
|
|
1369
|
+
toolCallAllowance: childToolCallAllowance(parameters, policy, childPolicy),
|
|
1370
|
+
policy: childPolicy,
|
|
1371
|
+
budget: {
|
|
1372
|
+
caps,
|
|
1373
|
+
allocation,
|
|
1374
|
+
...policy.descendantInvocations === void 0 ? {} : { descendantInvocations: policy.descendantInvocations }
|
|
1375
|
+
}
|
|
1376
|
+
}));
|
|
1377
|
+
switch (status._tag) {
|
|
1378
|
+
case "denied": return yield* executionFailure("establishment-denied", status.errorTag, status.message);
|
|
1379
|
+
case "waiting": {
|
|
1380
|
+
const payload = {
|
|
1381
|
+
toolCallId,
|
|
1382
|
+
delegationId: delegation.delegationId,
|
|
1383
|
+
childThreadId: status.childThreadId,
|
|
1384
|
+
childRunId: status.childRunId,
|
|
1385
|
+
targetAgentId: delegation.target.id,
|
|
1386
|
+
depth
|
|
1387
|
+
};
|
|
1388
|
+
yield* emit({
|
|
1389
|
+
_tag: "SubagentRequested",
|
|
1390
|
+
...payload
|
|
1391
|
+
});
|
|
1392
|
+
yield* emit({
|
|
1393
|
+
_tag: "SubagentStarted",
|
|
1394
|
+
...payload
|
|
1395
|
+
});
|
|
1396
|
+
return yield* Effect.mapError(wrapEngineSignal)(durability.waiting(toolCallId, status));
|
|
1397
|
+
}
|
|
1398
|
+
case "settled": {
|
|
1399
|
+
const payload = {
|
|
1400
|
+
toolCallId,
|
|
1401
|
+
delegationId: delegation.delegationId,
|
|
1402
|
+
childThreadId: status.childThreadId,
|
|
1403
|
+
childRunId: status.childRunId,
|
|
1404
|
+
targetAgentId: delegation.target.id,
|
|
1405
|
+
depth
|
|
1406
|
+
};
|
|
1407
|
+
const report = RunUsageReport.make({
|
|
1408
|
+
usage: status.usage ?? unknownRunTotals(),
|
|
1409
|
+
delegatedUsage: status.delegatedUsage ?? unknownRunTotals()
|
|
1410
|
+
});
|
|
1411
|
+
const settleFailure = (failure, encodedFailure) => emit({
|
|
1412
|
+
_tag: "SubagentFailed",
|
|
1413
|
+
...payload,
|
|
1414
|
+
...report,
|
|
1415
|
+
errorTag: errorTagOf(failure),
|
|
1416
|
+
message: boundedEventText(errorMessageOf(failure))
|
|
1417
|
+
}).pipe(Effect.andThen(Effect.mapError(wrapEngineSignal)(durability.join({
|
|
1418
|
+
toolCallId,
|
|
1419
|
+
encodedResult: encodedFailure,
|
|
1420
|
+
isFailure: !contained,
|
|
1421
|
+
encodedAccounting: conservativeAccounting
|
|
1422
|
+
}))), Effect.andThen(Effect.fail(failure)));
|
|
1423
|
+
if (status.outcome !== "completed") {
|
|
1424
|
+
const projection = childFailureProjectionOf(status.encodedResult);
|
|
1425
|
+
const failure = executionFailure(status.outcome === "aborted" ? "child-aborted" : projection.errorTag === "ChildCompatibilityFailure" ? "child-compatibility" : "child-failed", projection.errorTag, projection.message, status);
|
|
1426
|
+
return yield* settleFailure(failure, yield* encodeExecutionFailure(failure).pipe(Effect.orDie));
|
|
1427
|
+
}
|
|
1428
|
+
const decoded = yield* decodeChildOutput(status.encodedResult).pipe(Effect.catch(() => {
|
|
1429
|
+
const failure = SubagentProjectionFailure.make({
|
|
1430
|
+
delegationId: delegation.delegationId,
|
|
1431
|
+
stage: "result",
|
|
1432
|
+
message: "Settled child output did not satisfy the target Agent output Schema"
|
|
1433
|
+
});
|
|
1434
|
+
return encodeProjectionFailure(failure).pipe(Effect.orDie, Effect.flatMap((encodedFailure) => settleFailure(failure, encodedFailure)));
|
|
1435
|
+
}));
|
|
1436
|
+
const projected = yield* delegation.projectResult(decoded, {
|
|
1437
|
+
budgetExhausted: status.finishReason === "budget-exhausted",
|
|
1438
|
+
...report
|
|
1439
|
+
}, parameters).pipe(Effect.catch((declared) => encodeResultProjectionFailure(declared).pipe(Effect.orDie, Effect.flatMap((encodedFailure) => settleFailure(declared, encodedFailure)))));
|
|
1440
|
+
const encodedResult = yield* encodeSuccess(projected).pipe(Effect.catch(() => {
|
|
1441
|
+
const failure = SubagentProjectionFailure.make({
|
|
1442
|
+
delegationId: delegation.delegationId,
|
|
1443
|
+
stage: "result",
|
|
1444
|
+
message: "Projected child result did not satisfy the delegation success Schema"
|
|
1445
|
+
});
|
|
1446
|
+
return encodeProjectionFailure(failure).pipe(Effect.orDie, Effect.flatMap((encodedFailure) => settleFailure(failure, encodedFailure)));
|
|
1447
|
+
}));
|
|
1448
|
+
const resultBytes = utf8ByteLength(JSON.stringify(encodedResult) ?? "");
|
|
1449
|
+
if (policy.maxResultBytes !== void 0 && resultBytes > policy.maxResultBytes) {
|
|
1450
|
+
const failure = SubagentBudgetExhausted.make({
|
|
1451
|
+
parentRunId: spawner.parent.runId,
|
|
1452
|
+
dimension: "result-bytes",
|
|
1453
|
+
limitValue: policy.maxResultBytes,
|
|
1454
|
+
observedValue: resultBytes
|
|
1455
|
+
});
|
|
1456
|
+
return yield* settleFailure(failure, yield* encodeBudgetFailure(failure).pipe(Effect.orDie));
|
|
1457
|
+
}
|
|
1458
|
+
yield* Effect.mapError(wrapEngineSignal)(durability.join({
|
|
1459
|
+
toolCallId,
|
|
1460
|
+
encodedResult,
|
|
1461
|
+
isFailure: false,
|
|
1462
|
+
encodedAccounting: conservativeAccounting
|
|
1463
|
+
}));
|
|
1464
|
+
yield* emit({
|
|
1465
|
+
_tag: "SubagentJoined",
|
|
1466
|
+
...payload,
|
|
1467
|
+
...report
|
|
1468
|
+
});
|
|
1469
|
+
return projected;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
const containSignals = (failure) => failure instanceof GenuineEngineSignal ? Effect.fail(failure.signal) : Effect.succeed(failure);
|
|
1474
|
+
const unwrapSignals = (failure) => failure instanceof GenuineEngineSignal ? failure.signal : failure;
|
|
1475
|
+
const handlerImpl = (parameters, handlerContext) => Effect.gen(function* () {
|
|
1476
|
+
const spawner = yield* AgentSpawner;
|
|
1477
|
+
const sink = yield* RunEventSink;
|
|
1478
|
+
const durability = yield* SubagentDurability;
|
|
1479
|
+
if (durability.mode === "durable") {
|
|
1480
|
+
const durable = invokeDurable(parameters, handlerContext, durability).pipe(Effect.scoped, Effect.provideService(AgentSpawner, spawner), Effect.provideService(RunEventSink, sink), Effect.provideService(SubagentDurability, durability), Effect.provide(captured));
|
|
1481
|
+
return yield* contained ? durable.pipe(Effect.catch(containSignals)) : durable.pipe(Effect.mapError(unwrapSignals));
|
|
1482
|
+
}
|
|
1483
|
+
const ephemeral = invoke(parameters, handlerContext).pipe(Effect.scoped, Effect.provideService(AgentSpawner, spawner), Effect.provideService(RunEventSink, sink), Effect.provideService(SubagentDurability, durability), Effect.provide(captured));
|
|
1484
|
+
return yield* contained ? ephemeral.pipe(Effect.catch(containSignals)) : ephemeral.pipe(Effect.mapError(unwrapSignals));
|
|
1485
|
+
});
|
|
1486
|
+
const handler = handlerImpl;
|
|
1487
|
+
return { [delegation.name]: handler };
|
|
1488
|
+
});
|
|
1489
|
+
return toolkit.toLayer(build);
|
|
1490
|
+
}
|
|
1491
|
+
function background(targetOrDeclaration, selected) {
|
|
1492
|
+
const declaration = "target" in targetOrDeclaration ? targetOrDeclaration : make(targetOrDeclaration.id, { target: targetOrDeclaration });
|
|
1493
|
+
return background$1(declaration, selected);
|
|
1494
|
+
}
|
|
1495
|
+
//#endregion
|
|
1496
|
+
export { delegationCapsFromPolicy as S, stop as _, define as a, SubagentProjectionFailure as b, Worker as c, cancel as d, followUp as f, start as g, observe as h, background as i, WorkerObservation as l, list as m, SubagentResult as n, layer as o, inspect as p, Subagent_exports as r, make as s, SubagentDurableAccounting as t, awaitWorker as u, SubagentPolicy as v, delegationAllocationFromPolicy as x, SubagentPrestartDenied as y };
|
|
1497
|
+
|
|
1498
|
+
//# sourceMappingURL=Subagent-DCrB7an7.mjs.map
|