effect-agent 0.1.0-beta.85 → 0.1.0-beta.87
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-CN0EWRsR.d.mts +226 -0
- package/dist/Agent-RklVROrm.mjs +83 -0
- package/dist/Agent-RklVROrm.mjs.map +1 -0
- package/dist/AgentError-CggcAQ7V.d.mts +101 -0
- package/dist/AgentPolicy-CetmQrf3.d.mts +96 -0
- package/dist/AgentRuntime-BLyETCPo.mjs +4562 -0
- package/dist/AgentRuntime-BLyETCPo.mjs.map +1 -0
- package/dist/AgentRuntime-uxR_a4VM.d.mts +346 -0
- package/dist/AgentUpdates-DMJ-_xow.d.mts +53 -0
- package/dist/ContextCompactor-Dxu5zhOL.d.mts +161 -0
- package/dist/ContextWindow-DRQ5Mbm2.d.mts +58 -0
- package/dist/DurableAgentRuntime-uggeJpv3.mjs +6368 -0
- package/dist/DurableAgentRuntime-uggeJpv3.mjs.map +1 -0
- package/dist/DurableFailpoint-Oinuuedm.d.mts +41 -0
- package/dist/DurableStep-Cry_iol4.d.mts +103 -0
- package/dist/Ephemeral.d.mts +22 -0
- package/dist/Ephemeral.mjs +22 -0
- package/dist/Ephemeral.mjs.map +1 -0
- package/dist/EventSource-OqS_P9ug.d.mts +51 -0
- package/dist/Identifiers-CN2s30fF.d.mts +40 -0
- package/dist/MemoryNamespace-BbRW5p71.d.mts +36 -0
- package/dist/MemoryReference-B8Q3UJoJ.d.mts +79 -0
- package/dist/Messaging-CkcIdt4I.d.mts +490 -0
- package/dist/MessagingHost-CRk0kXzT.d.mts +246 -0
- package/dist/MessagingHost-CWi_PP3g.mjs +137 -0
- package/dist/MessagingHost-CWi_PP3g.mjs.map +1 -0
- package/dist/OperationAuthorizer-TzcQtpX5.d.mts +61 -0
- package/dist/Output-D6SkedVx.d.mts +25 -0
- package/dist/PageCapture-Df8Xwskw.d.mts +583 -0
- package/dist/PageScreenshot-BpgZKAxl.d.mts +48 -0
- package/dist/PreparedInputAdmission-C4HbjHgl.d.mts +38 -0
- package/dist/Receipt-BAHyigAF.d.mts +33 -0
- package/dist/Records-BAGkekt8.d.mts +3570 -0
- package/dist/RunEvent-DIrzkjLr.d.mts +460 -0
- package/dist/RunEventSink-D5aVhISG.d.mts +108 -0
- package/dist/RunJournal-Cgg1kNvc.mjs +825 -0
- package/dist/RunJournal-Cgg1kNvc.mjs.map +1 -0
- package/dist/RunOptions-g1aigcKI.d.mts +915 -0
- package/dist/RunPolicyUsage-ClZxyR46.d.mts +21 -0
- package/dist/Sandbox-CEsDWBLq.d.mts +173 -0
- package/dist/Schedule-H3SEYX9g.d.mts +842 -0
- package/dist/Scheduling-C9aIP8zT.mjs +691 -0
- package/dist/Scheduling-C9aIP8zT.mjs.map +1 -0
- package/dist/Subagent-Cy_hU1tv.mjs +1469 -0
- package/dist/Subagent-Cy_hU1tv.mjs.map +1 -0
- package/dist/Subagent-DyfzHNdv.d.mts +826 -0
- package/dist/SubagentContract-DdT7Cqe6.d.mts +116 -0
- package/dist/SubagentHost-CJUBQlcc.d.mts +140 -0
- package/dist/Subscription-BEP8oQO5.d.mts +921 -0
- package/dist/SubscriptionInput-vAAOBrK7.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 +6 -5
- package/dist/ToolExposure.mjs +17 -9
- package/dist/ToolExposure.mjs.map +1 -1
- package/dist/ToolReconciler-DQVaJfpE.d.mts +76 -0
- package/dist/ToolResult-DmmgoChv.d.mts +61 -0
- package/dist/Usage-Dx0aknfk.d.mts +121 -0
- package/dist/WakeScheduler-EjUF-GhC.d.mts +56 -0
- package/dist/Worker-CaPYykpe.d.mts +228 -0
- package/dist/agent-registration-CWDMOAZA.mjs +172 -0
- package/dist/agent-registration-CWDMOAZA.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 +260 -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 +151 -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 +109 -0
- package/dist/capabilities/ToolDiscovery.mjs +211 -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 +112 -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 +117 -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/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 +140 -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 +147 -0
- package/dist/core/Worker.mjs.map +1 -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 +328 -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 +111 -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 +94 -0
- package/dist/durable/DurableFailpoint.mjs.map +1 -0
- package/dist/durable/DurableFailpointTestControl.d.mts +15 -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 +144 -0
- package/dist/durable/GitHubWorkflowSource.mjs +209 -0
- package/dist/durable/GitHubWorkflowSource.mjs.map +1 -0
- package/dist/durable/MessageDelivery.d.mts +492 -0
- package/dist/durable/MessageDelivery.mjs +495 -0
- package/dist/durable/MessageDelivery.mjs.map +1 -0
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +358 -0
- package/dist/durable/MessageDeliveryStoreConformance.mjs +243 -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 +34 -0
- package/dist/durable/PreparedInputAdmission.mjs.map +1 -0
- package/dist/durable/Records.d.mts +2 -0
- package/dist/durable/Records.mjs +795 -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 +382 -0
- package/dist/durable/Schedule.mjs.map +1 -0
- package/dist/durable/ScheduleStoreConformance.d.mts +18 -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 +30 -0
- package/dist/durable/SqlMemoryStore.mjs +435 -0
- package/dist/durable/SqlMemoryStore.mjs.map +1 -0
- package/dist/durable/SqlMessageDeliveryStore.d.mts +40 -0
- package/dist/durable/SqlMessageDeliveryStore.mjs +167 -0
- package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -0
- package/dist/durable/SqlStorageV2Upgrade.d.mts +22 -0
- package/dist/durable/SqlStorageV2Upgrade.mjs +459 -0
- package/dist/durable/SqlStorageV2Upgrade.mjs.map +1 -0
- package/dist/durable/SqlSubscriptionStore.d.mts +63 -0
- package/dist/durable/SqlSubscriptionStore.mjs +751 -0
- package/dist/durable/SqlSubscriptionStore.mjs.map +1 -0
- package/dist/durable/SubmissionLedger.d.mts +3 -0
- package/dist/durable/SubmissionLedger.mjs +914 -0
- package/dist/durable/SubmissionLedger.mjs.map +1 -0
- package/dist/durable/SubmissionLedgerConformance.d.mts +30 -0
- package/dist/durable/SubmissionLedgerConformance.mjs +1986 -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 +17 -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 +74 -0
- package/dist/durable/ThreadInvariants.mjs +200 -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 +147 -0
- package/dist/durable/ThreadStore.mjs.map +1 -0
- package/dist/durable/ThreadStoreConformance.d.mts +29 -0
- package/dist/durable/ThreadStoreConformance.mjs +248 -0
- package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
- package/dist/durable/ToolReconciler.d.mts +2 -0
- package/dist/durable/ToolReconciler.mjs +81 -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 +122 -0
- package/dist/engine/RunOptions.mjs.map +1 -0
- package/dist/engine/SubagentHost.d.mts +2 -0
- package/dist/engine/SubagentHost.mjs +72 -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 +88 -54
- package/dist/index.mjs +97 -54
- 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 +142 -0
- package/dist/sandbox/InteractiveBrowser.mjs +165 -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 +252 -0
- package/dist/sandbox/ProtectedBrowser.mjs +270 -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 -1
- package/src/Ephemeral.ts +17 -0
- package/src/ToolExposure.ts +2 -2
- 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 +427 -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 +2277 -0
- package/src/capabilities/SubagentReservations.ts +850 -0
- package/src/capabilities/ToolDiscovery.ts +339 -0
- package/src/capabilities/WebCapture.ts +722 -0
- package/src/capabilities/WebSearch.ts +184 -0
- package/src/capabilities/internal/subagent-background.ts +1106 -0
- package/src/capabilities/internal/subagent-contract.ts +142 -0
- package/src/capabilities/internal/subagent-policy.ts +235 -0
- package/src/capabilities/internal/subagent-reporting.ts +261 -0
- package/src/capabilities/internal/utf8.ts +10 -0
- package/src/core/Agent.ts +575 -0
- package/src/core/AgentError.ts +152 -0
- package/src/core/AgentPolicy.ts +153 -0
- package/src/core/AgentUpdates.ts +100 -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 +90 -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 +170 -0
- package/src/core/Usage.ts +529 -0
- package/src/core/Worker.ts +173 -0
- package/src/core/internal/agent-updates.ts +32 -0
- package/src/core/internal/utf8.ts +23 -0
- package/src/durable/ActivityStore.ts +160 -0
- package/src/durable/Admin.ts +496 -0
- package/src/durable/AgentRegistration.ts +13 -0
- package/src/durable/Certification.ts +210 -0
- package/src/durable/CommittedActivity.ts +296 -0
- package/src/durable/Digest.ts +93 -0
- package/src/durable/DurableAgentRuntime.ts +10340 -0
- package/src/durable/DurableFailpoint.ts +103 -0
- package/src/durable/DurableFailpointTestControl.ts +39 -0
- package/src/durable/EventSource.ts +172 -0
- package/src/durable/GitHubWorkflowSource.ts +453 -0
- package/src/durable/MessageDelivery.ts +708 -0
- package/src/durable/MessageDeliveryStoreConformance.ts +363 -0
- package/src/durable/OperationAuthorizer.ts +85 -0
- package/src/durable/PersistentHistory.ts +260 -0
- package/src/durable/PreparedInputAdmission.ts +44 -0
- package/src/durable/Records.ts +1010 -0
- package/src/durable/Recovery.ts +1018 -0
- package/src/durable/RunJournal.ts +1479 -0
- package/src/durable/Schedule.ts +504 -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 +774 -0
- package/src/durable/SqlMessageDeliveryStore.ts +302 -0
- package/src/durable/SqlStorageV2Upgrade.ts +500 -0
- package/src/durable/SqlSubscriptionStore.ts +1440 -0
- package/src/durable/SubmissionLedger.ts +1201 -0
- package/src/durable/SubmissionLedgerConformance.ts +4579 -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 +442 -0
- package/src/durable/ThreadProjection.ts +269 -0
- package/src/durable/ThreadProjectionMaintenance.ts +67 -0
- package/src/durable/ThreadStore.ts +242 -0
- package/src/durable/ThreadStoreConformance.ts +710 -0
- package/src/durable/ToolReconciler.ts +105 -0
- package/src/durable/WakeScheduler.ts +134 -0
- package/src/durable/WorkerHost.ts +171 -0
- package/src/durable/internal/agent-registration.ts +525 -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 +107 -0
- package/src/durable/internal/messaging-host.ts +608 -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 +2467 -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 +1077 -0
- package/src/engine/SubagentHost.ts +181 -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 +10117 -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 +96 -53
- package/src/sandbox/CodeExecutor.ts +352 -0
- package/src/sandbox/InteractiveBrowser.ts +257 -0
- package/src/sandbox/PageCapture.ts +692 -0
- package/src/sandbox/PageCrawl.ts +148 -0
- package/src/sandbox/PageScreenshot.ts +81 -0
- package/src/sandbox/ProtectedBrowser.ts +413 -0
- package/src/sandbox/Sandbox.ts +241 -0
- package/dist/Agent.d.mts +0 -5
- package/dist/Agent.mjs +0 -10
- package/dist/Agent.mjs.map +0 -1
- package/dist/AgentError.d.mts +0 -5
- package/dist/AgentError.mjs +0 -10
- package/dist/AgentError.mjs.map +0 -1
- package/dist/AgentPolicy.d.mts +0 -5
- package/dist/AgentPolicy.mjs +0 -10
- package/dist/AgentPolicy.mjs.map +0 -1
- package/dist/AgentRuntime.d.mts +0 -5
- package/dist/AgentRuntime.mjs +0 -10
- package/dist/AgentRuntime.mjs.map +0 -1
- package/dist/AgentUpdates.d.mts +0 -5
- package/dist/AgentUpdates.mjs +0 -10
- package/dist/AgentUpdates.mjs.map +0 -1
- package/dist/Approval.d.mts +0 -5
- package/dist/Approval.mjs +0 -10
- package/dist/Approval.mjs.map +0 -1
- package/dist/Budget.d.mts +0 -5
- package/dist/Budget.mjs +0 -10
- package/dist/Budget.mjs.map +0 -1
- package/dist/CodeMode.d.mts +0 -5
- package/dist/CodeMode.mjs +0 -10
- package/dist/CodeMode.mjs.map +0 -1
- package/dist/Commands.d.mts +0 -5
- package/dist/Commands.mjs +0 -10
- package/dist/Commands.mjs.map +0 -1
- package/dist/Compaction.d.mts +0 -5
- package/dist/Compaction.mjs +0 -10
- package/dist/Compaction.mjs.map +0 -1
- package/dist/ContextCompactor.d.mts +0 -5
- package/dist/ContextCompactor.mjs +0 -10
- package/dist/ContextCompactor.mjs.map +0 -1
- package/dist/ContextHistory.d.mts +0 -5
- package/dist/ContextHistory.mjs +0 -10
- package/dist/ContextHistory.mjs.map +0 -1
- package/dist/ContextTools.d.mts +0 -5
- package/dist/ContextTools.mjs +0 -10
- package/dist/ContextTools.mjs.map +0 -1
- package/dist/ContextWindow.d.mts +0 -5
- package/dist/ContextWindow.mjs +0 -10
- package/dist/ContextWindow.mjs.map +0 -1
- package/dist/DurableStep.d.mts +0 -5
- package/dist/DurableStep.mjs +0 -10
- package/dist/DurableStep.mjs.map +0 -1
- package/dist/EphemeralThreads.d.mts +0 -5
- package/dist/EphemeralThreads.mjs +0 -10
- package/dist/EphemeralThreads.mjs.map +0 -1
- package/dist/IdGenerator.d.mts +0 -5
- package/dist/IdGenerator.mjs +0 -10
- package/dist/IdGenerator.mjs.map +0 -1
- package/dist/Identifiers.d.mts +0 -5
- package/dist/Identifiers.mjs +0 -10
- package/dist/Identifiers.mjs.map +0 -1
- package/dist/Mcp.d.mts +0 -5
- package/dist/Mcp.mjs +0 -10
- package/dist/Mcp.mjs.map +0 -1
- package/dist/McpClient.d.mts +0 -5
- package/dist/McpClient.mjs +0 -10
- package/dist/McpClient.mjs.map +0 -1
- package/dist/Memory.d.mts +0 -5
- package/dist/Memory.mjs +0 -10
- package/dist/Memory.mjs.map +0 -1
- package/dist/MemoryNamespace.d.mts +0 -5
- package/dist/MemoryNamespace.mjs +0 -10
- package/dist/MemoryNamespace.mjs.map +0 -1
- package/dist/MemoryNotes.d.mts +0 -5
- package/dist/MemoryNotes.mjs +0 -10
- package/dist/MemoryNotes.mjs.map +0 -1
- package/dist/MemoryReference.d.mts +0 -5
- package/dist/MemoryReference.mjs +0 -10
- package/dist/MemoryReference.mjs.map +0 -1
- package/dist/MemoryRevalidation.d.mts +0 -5
- package/dist/MemoryRevalidation.mjs +0 -10
- package/dist/MemoryRevalidation.mjs.map +0 -1
- package/dist/MemoryStore.d.mts +0 -5
- package/dist/MemoryStore.mjs +0 -10
- package/dist/MemoryStore.mjs.map +0 -1
- package/dist/Messaging.d.mts +0 -5
- package/dist/Messaging.mjs +0 -10
- package/dist/Messaging.mjs.map +0 -1
- package/dist/MessagingHost.d.mts +0 -5
- package/dist/MessagingHost.mjs +0 -10
- package/dist/MessagingHost.mjs.map +0 -1
- package/dist/ModelContext.d.mts +0 -5
- package/dist/ModelContext.mjs +0 -10
- package/dist/ModelContext.mjs.map +0 -1
- package/dist/Receipt.d.mts +0 -5
- package/dist/Receipt.mjs +0 -10
- package/dist/Receipt.mjs.map +0 -1
- package/dist/Redaction.d.mts +0 -5
- package/dist/Redaction.mjs +0 -10
- package/dist/Redaction.mjs.map +0 -1
- package/dist/Remembering.d.mts +0 -5
- package/dist/Remembering.mjs +0 -10
- package/dist/Remembering.mjs.map +0 -1
- package/dist/RememberingStore.d.mts +0 -5
- package/dist/RememberingStore.mjs +0 -10
- package/dist/RememberingStore.mjs.map +0 -1
- package/dist/RunEvent.d.mts +0 -5
- package/dist/RunEvent.mjs +0 -10
- package/dist/RunEvent.mjs.map +0 -1
- package/dist/RunEventSink.d.mts +0 -5
- package/dist/RunEventSink.mjs +0 -10
- package/dist/RunEventSink.mjs.map +0 -1
- package/dist/RunHooks.d.mts +0 -5
- package/dist/RunHooks.mjs +0 -10
- package/dist/RunHooks.mjs.map +0 -1
- package/dist/RunOptions.d.mts +0 -5
- package/dist/RunOptions.mjs +0 -10
- package/dist/RunOptions.mjs.map +0 -1
- package/dist/RunPolicyUsage.d.mts +0 -5
- package/dist/RunPolicyUsage.mjs +0 -10
- package/dist/RunPolicyUsage.mjs.map +0 -1
- package/dist/SemanticMemory.d.mts +0 -5
- package/dist/SemanticMemory.mjs +0 -10
- package/dist/SemanticMemory.mjs.map +0 -1
- package/dist/SemanticMemoryIndex.d.mts +0 -5
- package/dist/SemanticMemoryIndex.mjs +0 -10
- package/dist/SemanticMemoryIndex.mjs.map +0 -1
- package/dist/SemanticMemoryRevalidation.d.mts +0 -5
- package/dist/SemanticMemoryRevalidation.mjs +0 -10
- package/dist/SemanticMemoryRevalidation.mjs.map +0 -1
- package/dist/Subagent.d.mts +0 -5
- package/dist/Subagent.mjs +0 -10
- package/dist/Subagent.mjs.map +0 -1
- package/dist/SubagentContract.d.mts +0 -5
- package/dist/SubagentContract.mjs +0 -10
- package/dist/SubagentContract.mjs.map +0 -1
- package/dist/SubagentHost.d.mts +0 -5
- package/dist/SubagentHost.mjs +0 -10
- package/dist/SubagentHost.mjs.map +0 -1
- package/dist/SubagentReservations.d.mts +0 -5
- package/dist/SubagentReservations.mjs +0 -10
- package/dist/SubagentReservations.mjs.map +0 -1
- package/dist/ThreadHistory.d.mts +0 -5
- package/dist/ThreadHistory.mjs +0 -10
- package/dist/ThreadHistory.mjs.map +0 -1
- package/dist/ToolBroker.d.mts +0 -5
- package/dist/ToolBroker.mjs +0 -10
- package/dist/ToolBroker.mjs.map +0 -1
- package/dist/ToolDiscovery.d.mts +0 -5
- package/dist/ToolDiscovery.mjs +0 -10
- package/dist/ToolDiscovery.mjs.map +0 -1
- package/dist/ToolResult.d.mts +0 -5
- package/dist/ToolResult.mjs +0 -10
- package/dist/ToolResult.mjs.map +0 -1
- package/dist/Usage.d.mts +0 -5
- package/dist/Usage.mjs +0 -10
- package/dist/Usage.mjs.map +0 -1
- package/dist/WebCapture.d.mts +0 -5
- package/dist/WebCapture.mjs +0 -10
- package/dist/WebCapture.mjs.map +0 -1
- package/dist/WebSearch.d.mts +0 -5
- package/dist/WebSearch.mjs +0 -10
- package/dist/WebSearch.mjs.map +0 -1
- package/dist/Worker.d.mts +0 -5
- package/dist/Worker.mjs +0 -10
- package/dist/Worker.mjs.map +0 -1
- package/dist/rolldown-runtime-BBjsoOtd.mjs +0 -27
- package/src/Agent.ts +0 -1
- package/src/AgentError.ts +0 -1
- package/src/AgentPolicy.ts +0 -1
- package/src/AgentRuntime.ts +0 -1
- package/src/AgentUpdates.ts +0 -1
- package/src/Approval.ts +0 -1
- package/src/Budget.ts +0 -1
- package/src/CodeMode.ts +0 -1
- package/src/Commands.ts +0 -1
- package/src/Compaction.ts +0 -1
- package/src/ContextCompactor.ts +0 -1
- package/src/ContextHistory.ts +0 -1
- package/src/ContextTools.ts +0 -1
- package/src/ContextWindow.ts +0 -1
- package/src/DurableStep.ts +0 -1
- package/src/EphemeralThreads.ts +0 -1
- package/src/IdGenerator.ts +0 -1
- package/src/Identifiers.ts +0 -1
- package/src/Mcp.ts +0 -1
- package/src/McpClient.ts +0 -1
- package/src/Memory.ts +0 -1
- package/src/MemoryNamespace.ts +0 -1
- package/src/MemoryNotes.ts +0 -1
- package/src/MemoryReference.ts +0 -1
- package/src/MemoryRevalidation.ts +0 -1
- package/src/MemoryStore.ts +0 -1
- package/src/Messaging.ts +0 -1
- package/src/MessagingHost.ts +0 -1
- package/src/ModelContext.ts +0 -1
- package/src/Receipt.ts +0 -1
- package/src/Redaction.ts +0 -1
- package/src/Remembering.ts +0 -1
- package/src/RememberingStore.ts +0 -1
- package/src/RunEvent.ts +0 -1
- package/src/RunEventSink.ts +0 -1
- package/src/RunHooks.ts +0 -1
- package/src/RunOptions.ts +0 -1
- package/src/RunPolicyUsage.ts +0 -1
- package/src/SemanticMemory.ts +0 -1
- package/src/SemanticMemoryIndex.ts +0 -1
- package/src/SemanticMemoryRevalidation.ts +0 -1
- package/src/Subagent.ts +0 -1
- package/src/SubagentContract.ts +0 -1
- package/src/SubagentHost.ts +0 -1
- package/src/SubagentReservations.ts +0 -1
- package/src/ThreadHistory.ts +0 -1
- package/src/ToolBroker.ts +0 -1
- package/src/ToolDiscovery.ts +0 -1
- package/src/ToolResult.ts +0 -1
- package/src/Usage.ts +0 -1
- package/src/WebCapture.ts +0 -1
- package/src/WebSearch.ts +0 -1
- package/src/Worker.ts +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { Clock, Duration, Effect, Ref, Schema } from "effect";
|
|
3
|
+
//#region src/capabilities/Budget.ts
|
|
4
|
+
var Budget_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
BudgetExceeded: () => BudgetExceeded,
|
|
6
|
+
BudgetNodeConflict: () => BudgetNodeConflict,
|
|
7
|
+
InvalidBudgetHierarchy: () => InvalidBudgetHierarchy,
|
|
8
|
+
UsageBudgetLimits: () => UsageBudgetLimits,
|
|
9
|
+
UsageBudgetNodeConfig: () => UsageBudgetNodeConfig,
|
|
10
|
+
UsageDelta: () => UsageDelta,
|
|
11
|
+
UsageTotals: () => UsageTotals,
|
|
12
|
+
makeUsageBudget: () => makeUsageBudget,
|
|
13
|
+
makeUsageBudgetRoot: () => makeUsageBudgetRoot
|
|
14
|
+
});
|
|
15
|
+
const Natural = Schema.Natural;
|
|
16
|
+
const BudgetLevel = Schema.Literals([
|
|
17
|
+
"global",
|
|
18
|
+
"tenant",
|
|
19
|
+
"agent",
|
|
20
|
+
"thread",
|
|
21
|
+
"run"
|
|
22
|
+
]);
|
|
23
|
+
/** Fixed units avoid floating-point currency accounting: costs are micro-USD. */
|
|
24
|
+
var UsageTotals = class extends Schema.Class("@effect-agent/capabilities/UsageTotals")({
|
|
25
|
+
/** Total input tokens across every model call, INCLUDING cache reads and writes at par. */
|
|
26
|
+
inputTokens: Natural,
|
|
27
|
+
outputTokens: Natural,
|
|
28
|
+
/** Informational split of `inputTokens` served from the provider prompt cache; never separately limited. */
|
|
29
|
+
cacheReadInputTokens: Natural,
|
|
30
|
+
/** Informational split of `inputTokens` written to the provider prompt cache; never separately limited. */
|
|
31
|
+
cacheWriteInputTokens: Natural,
|
|
32
|
+
/** The most recent model call's input tokens — the live model-context estimate (CAP-017). */
|
|
33
|
+
lastInputTokens: Natural,
|
|
34
|
+
/** The most recent model call's output tokens. */
|
|
35
|
+
lastOutputTokens: Natural,
|
|
36
|
+
toolCalls: Natural,
|
|
37
|
+
costMicrousd: Natural,
|
|
38
|
+
elapsedMillis: Natural
|
|
39
|
+
}) {};
|
|
40
|
+
/** Increment recorded at one model/tool accounting boundary. */
|
|
41
|
+
var UsageDelta = class extends Schema.Class("@effect-agent/capabilities/UsageDelta")({
|
|
42
|
+
/** `1` for a model-response boundary, `0` for a mid-pass tool charge; gates last-call tracking. */
|
|
43
|
+
modelCalls: Natural,
|
|
44
|
+
/** Total input tokens of this boundary, INCLUDING cache reads and writes at par. */
|
|
45
|
+
inputTokens: Natural,
|
|
46
|
+
outputTokens: Natural,
|
|
47
|
+
/** Informational split of `inputTokens` served from the provider prompt cache; never separately limited. */
|
|
48
|
+
cacheReadInputTokens: Natural,
|
|
49
|
+
/** Informational split of `inputTokens` written to the provider prompt cache; never separately limited. */
|
|
50
|
+
cacheWriteInputTokens: Natural,
|
|
51
|
+
toolCalls: Natural,
|
|
52
|
+
costMicrousd: Natural
|
|
53
|
+
}) {};
|
|
54
|
+
/** All optional limits are finite when present; absent means not configured. */
|
|
55
|
+
var UsageBudgetLimits = class extends Schema.Class("@effect-agent/capabilities/UsageBudgetLimits")({
|
|
56
|
+
maxInputTokens: Schema.optionalKey(Natural),
|
|
57
|
+
maxOutputTokens: Schema.optionalKey(Natural),
|
|
58
|
+
maxToolCalls: Schema.optionalKey(Natural),
|
|
59
|
+
maxCostMicrousd: Schema.optionalKey(Natural),
|
|
60
|
+
maxDurationMillis: Schema.optionalKey(Natural)
|
|
61
|
+
}) {};
|
|
62
|
+
/** Identity and local limits for one node in a global-to-Run budget hierarchy. */
|
|
63
|
+
var UsageBudgetNodeConfig = class extends Schema.Class("@effect-agent/capabilities/UsageBudgetNodeConfig")({
|
|
64
|
+
level: BudgetLevel,
|
|
65
|
+
id: Schema.NonEmptyString,
|
|
66
|
+
limits: UsageBudgetLimits
|
|
67
|
+
}) {};
|
|
68
|
+
/** Typed finite-budget rejection. A rejected increment is not committed at any hierarchy level. */
|
|
69
|
+
var BudgetExceeded = class extends Schema.TaggedError()("BudgetExceeded", {
|
|
70
|
+
scopeLevel: BudgetLevel,
|
|
71
|
+
scopeId: Schema.NonEmptyString,
|
|
72
|
+
limit: Schema.Literals([
|
|
73
|
+
"input-tokens",
|
|
74
|
+
"output-tokens",
|
|
75
|
+
"tool-calls",
|
|
76
|
+
"cost",
|
|
77
|
+
"duration"
|
|
78
|
+
]),
|
|
79
|
+
limitValue: Natural,
|
|
80
|
+
observedValue: Natural
|
|
81
|
+
}) {};
|
|
82
|
+
/** A child budget must move strictly inward through the declared hierarchy. */
|
|
83
|
+
var InvalidBudgetHierarchy = class extends Schema.TaggedError()("InvalidBudgetHierarchy", {
|
|
84
|
+
parentLevel: BudgetLevel,
|
|
85
|
+
childLevel: BudgetLevel
|
|
86
|
+
}) {};
|
|
87
|
+
/** A child `level:id` is already registered with different limits; neither set may win silently. */
|
|
88
|
+
var BudgetNodeConflict = class extends Schema.TaggedError()("BudgetNodeConflict", {
|
|
89
|
+
scopeLevel: BudgetLevel,
|
|
90
|
+
scopeId: Schema.NonEmptyString
|
|
91
|
+
}) {};
|
|
92
|
+
const levelOrder = {
|
|
93
|
+
global: 0,
|
|
94
|
+
tenant: 1,
|
|
95
|
+
agent: 2,
|
|
96
|
+
thread: 3,
|
|
97
|
+
run: 4
|
|
98
|
+
};
|
|
99
|
+
const emptyTotals = (elapsedMillis = 0) => UsageTotals.make({
|
|
100
|
+
inputTokens: 0,
|
|
101
|
+
outputTokens: 0,
|
|
102
|
+
cacheReadInputTokens: 0,
|
|
103
|
+
cacheWriteInputTokens: 0,
|
|
104
|
+
lastInputTokens: 0,
|
|
105
|
+
lastOutputTokens: 0,
|
|
106
|
+
toolCalls: 0,
|
|
107
|
+
costMicrousd: 0,
|
|
108
|
+
elapsedMillis
|
|
109
|
+
});
|
|
110
|
+
const withElapsed = (node, now) => UsageTotals.make({
|
|
111
|
+
...node.totals,
|
|
112
|
+
elapsedMillis: Math.max(0, now - node.startedAt)
|
|
113
|
+
});
|
|
114
|
+
const addUsage = (node, delta, now) => UsageTotals.make({
|
|
115
|
+
inputTokens: node.totals.inputTokens + delta.inputTokens,
|
|
116
|
+
outputTokens: node.totals.outputTokens + delta.outputTokens,
|
|
117
|
+
cacheReadInputTokens: node.totals.cacheReadInputTokens + delta.cacheReadInputTokens,
|
|
118
|
+
cacheWriteInputTokens: node.totals.cacheWriteInputTokens + delta.cacheWriteInputTokens,
|
|
119
|
+
lastInputTokens: delta.modelCalls > 0 ? delta.inputTokens : node.totals.lastInputTokens,
|
|
120
|
+
lastOutputTokens: delta.modelCalls > 0 ? delta.outputTokens : node.totals.lastOutputTokens,
|
|
121
|
+
toolCalls: node.totals.toolCalls + delta.toolCalls,
|
|
122
|
+
costMicrousd: node.totals.costMicrousd + delta.costMicrousd,
|
|
123
|
+
elapsedMillis: Math.max(0, now - node.startedAt)
|
|
124
|
+
});
|
|
125
|
+
const exceeded = (node, totals) => {
|
|
126
|
+
const limits = node.config.limits;
|
|
127
|
+
const checks = [
|
|
128
|
+
[
|
|
129
|
+
"input-tokens",
|
|
130
|
+
limits.maxInputTokens,
|
|
131
|
+
totals.inputTokens
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"output-tokens",
|
|
135
|
+
limits.maxOutputTokens,
|
|
136
|
+
totals.outputTokens
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
"tool-calls",
|
|
140
|
+
limits.maxToolCalls,
|
|
141
|
+
totals.toolCalls
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
"cost",
|
|
145
|
+
limits.maxCostMicrousd,
|
|
146
|
+
totals.costMicrousd
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
"duration",
|
|
150
|
+
limits.maxDurationMillis,
|
|
151
|
+
totals.elapsedMillis
|
|
152
|
+
]
|
|
153
|
+
];
|
|
154
|
+
for (const [limit, limitValue, observedValue] of checks) if (limitValue !== void 0 && observedValue > limitValue) return BudgetExceeded.make({
|
|
155
|
+
scopeLevel: node.config.level,
|
|
156
|
+
scopeId: node.config.id,
|
|
157
|
+
limit,
|
|
158
|
+
limitValue,
|
|
159
|
+
observedValue
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
const sameLimits = (a, b) => a.maxInputTokens === b.maxInputTokens && a.maxOutputTokens === b.maxOutputTokens && a.maxToolCalls === b.maxToolCalls && a.maxCostMicrousd === b.maxCostMicrousd && a.maxDurationMillis === b.maxDurationMillis;
|
|
163
|
+
const nodeKeyComponent = (config) => `${config.level}:${encodeURIComponent(JSON.stringify(config.id))}`;
|
|
164
|
+
const durationExceeded = (node, now) => {
|
|
165
|
+
const limitValue = node.config.limits.maxDurationMillis ?? 0;
|
|
166
|
+
return BudgetExceeded.make({
|
|
167
|
+
scopeLevel: node.config.level,
|
|
168
|
+
scopeId: node.config.id,
|
|
169
|
+
limit: "duration",
|
|
170
|
+
limitValue,
|
|
171
|
+
observedValue: Math.max(limitValue + 1, now - node.startedAt)
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
/** Reclaim one released leaf and any newly unowned ancestors on its fixed hierarchy path. */
|
|
175
|
+
const pruneRetiredHierarchy = (nodes, hierarchy) => {
|
|
176
|
+
for (let index = hierarchy.length - 1; index >= 0; index -= 1) {
|
|
177
|
+
const candidateKey = hierarchy[index];
|
|
178
|
+
if (candidateKey === void 0) continue;
|
|
179
|
+
const candidate = nodes.get(candidateKey);
|
|
180
|
+
if (candidate === void 0) continue;
|
|
181
|
+
if (candidate.handles.size > 0) break;
|
|
182
|
+
const childPrefix = `${candidateKey}/`;
|
|
183
|
+
if ([...nodes.keys()].some((otherKey) => otherKey.startsWith(childPrefix))) break;
|
|
184
|
+
nodes.delete(candidateKey);
|
|
185
|
+
}
|
|
186
|
+
return nodes;
|
|
187
|
+
};
|
|
188
|
+
const makeNode = (ledger, key, ancestors, config, handleId) => {
|
|
189
|
+
const hierarchy = [...ancestors, key];
|
|
190
|
+
const retiredDefect = () => Effect.die(/* @__PURE__ */ new Error(`Usage budget handle ${config.level}:${config.id} was used after retirement`));
|
|
191
|
+
const liveHierarchy = (state) => {
|
|
192
|
+
const current = state.nodes.get(key);
|
|
193
|
+
if (current === void 0 || !current.handles.has(handleId)) return void 0;
|
|
194
|
+
const nodes = [];
|
|
195
|
+
for (const ancestorKey of hierarchy) {
|
|
196
|
+
const node = state.nodes.get(ancestorKey);
|
|
197
|
+
if (node === void 0) return void 0;
|
|
198
|
+
nodes.push(node);
|
|
199
|
+
}
|
|
200
|
+
return nodes;
|
|
201
|
+
};
|
|
202
|
+
const readLiveHierarchy = Ref.modify(ledger, (state) => [liveHierarchy(state), state]);
|
|
203
|
+
const snapshot = Effect.gen(function* () {
|
|
204
|
+
const now = yield* Clock.currentTimeMillis;
|
|
205
|
+
const nodes = yield* readLiveHierarchy;
|
|
206
|
+
if (nodes === void 0) return yield* retiredDefect();
|
|
207
|
+
const node = nodes[nodes.length - 1];
|
|
208
|
+
if (node === void 0) return yield* retiredDefect();
|
|
209
|
+
return withElapsed(node, now);
|
|
210
|
+
});
|
|
211
|
+
const guard = (effect) => Effect.gen(function* () {
|
|
212
|
+
const now = yield* Clock.currentTimeMillis;
|
|
213
|
+
const nodes = yield* readLiveHierarchy;
|
|
214
|
+
if (nodes === void 0) return yield* retiredDefect();
|
|
215
|
+
let deadline;
|
|
216
|
+
for (const node of nodes) {
|
|
217
|
+
const current = withElapsed(node, now);
|
|
218
|
+
const alreadyExceeded = exceeded(node, current);
|
|
219
|
+
if (alreadyExceeded !== void 0) return yield* alreadyExceeded;
|
|
220
|
+
const maxDuration = node.config.limits.maxDurationMillis;
|
|
221
|
+
if (maxDuration !== void 0) {
|
|
222
|
+
const remaining = maxDuration - current.elapsedMillis;
|
|
223
|
+
if (remaining <= 0) return yield* durationExceeded(node, now);
|
|
224
|
+
if (deadline === void 0 || remaining < deadline.remaining) deadline = {
|
|
225
|
+
remaining,
|
|
226
|
+
node
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (deadline === void 0) return yield* effect;
|
|
231
|
+
const selected = deadline;
|
|
232
|
+
return yield* effect.pipe(Effect.timeoutOrElse({
|
|
233
|
+
duration: Duration.millis(selected.remaining),
|
|
234
|
+
orElse: () => Clock.currentTimeMillis.pipe(Effect.flatMap((timeoutAt) => Effect.fail(durationExceeded(selected.node, timeoutAt))))
|
|
235
|
+
}));
|
|
236
|
+
});
|
|
237
|
+
const child = Effect.fn("UsageBudgetNode.child")(function* (childConfig) {
|
|
238
|
+
const childKey = `${key}/${nodeKeyComponent(childConfig)}`;
|
|
239
|
+
const childHandleId = Symbol(`usage-budget:${childConfig.level}:${childConfig.id}`);
|
|
240
|
+
const now = yield* Clock.currentTimeMillis;
|
|
241
|
+
const registration = yield* Ref.modify(ledger, (state) => {
|
|
242
|
+
if (liveHierarchy(state) === void 0) return [{ _tag: "retired" }, state];
|
|
243
|
+
if (levelOrder[childConfig.level] <= levelOrder[config.level]) return [{
|
|
244
|
+
_tag: "invalid",
|
|
245
|
+
error: InvalidBudgetHierarchy.make({
|
|
246
|
+
parentLevel: config.level,
|
|
247
|
+
childLevel: childConfig.level
|
|
248
|
+
})
|
|
249
|
+
}, state];
|
|
250
|
+
const existing = state.nodes.get(childKey);
|
|
251
|
+
if (existing !== void 0) return sameLimits(existing.config.limits, childConfig.limits) ? [{ _tag: "success" }, { nodes: new Map(state.nodes).set(childKey, {
|
|
252
|
+
...existing,
|
|
253
|
+
handles: new Set(existing.handles).add(childHandleId)
|
|
254
|
+
}) }] : [{
|
|
255
|
+
_tag: "conflict",
|
|
256
|
+
error: BudgetNodeConflict.make({
|
|
257
|
+
scopeLevel: childConfig.level,
|
|
258
|
+
scopeId: childConfig.id
|
|
259
|
+
})
|
|
260
|
+
}, state];
|
|
261
|
+
return [{ _tag: "success" }, { nodes: new Map(state.nodes).set(childKey, {
|
|
262
|
+
config: childConfig,
|
|
263
|
+
startedAt: now,
|
|
264
|
+
totals: emptyTotals(),
|
|
265
|
+
handles: /* @__PURE__ */ new Set([childHandleId])
|
|
266
|
+
}) }];
|
|
267
|
+
});
|
|
268
|
+
if (registration._tag === "retired") return yield* retiredDefect();
|
|
269
|
+
if (registration._tag === "conflict" || registration._tag === "invalid") return yield* registration.error;
|
|
270
|
+
return makeNode(ledger, childKey, hierarchy, childConfig, childHandleId);
|
|
271
|
+
});
|
|
272
|
+
const retire = Effect.uninterruptible(Ref.update(ledger, (state) => {
|
|
273
|
+
const existing = state.nodes.get(key);
|
|
274
|
+
if (existing === void 0 || !existing.handles.has(handleId)) return state;
|
|
275
|
+
const handles = new Set(existing.handles);
|
|
276
|
+
handles.delete(handleId);
|
|
277
|
+
const nodes = new Map(state.nodes).set(key, {
|
|
278
|
+
...existing,
|
|
279
|
+
handles
|
|
280
|
+
});
|
|
281
|
+
return { nodes: pruneRetiredHierarchy(nodes, hierarchy) };
|
|
282
|
+
}));
|
|
283
|
+
return {
|
|
284
|
+
level: config.level,
|
|
285
|
+
id: config.id,
|
|
286
|
+
child,
|
|
287
|
+
childScoped: (childConfig) => Effect.acquireRelease(child(childConfig), (node) => node.retire),
|
|
288
|
+
retire,
|
|
289
|
+
consume: (delta) => Clock.currentTimeMillis.pipe(Effect.flatMap((now) => Ref.modify(ledger, (state) => {
|
|
290
|
+
if (liveHierarchy(state) === void 0) return [{ _tag: "retired" }, state];
|
|
291
|
+
const updates = /* @__PURE__ */ new Map();
|
|
292
|
+
for (const ancestorKey of hierarchy) {
|
|
293
|
+
const node = state.nodes.get(ancestorKey);
|
|
294
|
+
if (node === void 0) return [{ _tag: "retired" }, state];
|
|
295
|
+
const totals = addUsage(node, delta, now);
|
|
296
|
+
const error = exceeded(node, totals);
|
|
297
|
+
if (error !== void 0) return [{
|
|
298
|
+
_tag: "failure",
|
|
299
|
+
error
|
|
300
|
+
}, state];
|
|
301
|
+
updates.set(ancestorKey, {
|
|
302
|
+
...node,
|
|
303
|
+
totals
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
const nextNodes = new Map(state.nodes);
|
|
307
|
+
for (const [updatedKey, updatedNode] of updates) nextNodes.set(updatedKey, updatedNode);
|
|
308
|
+
const value = updates.get(key)?.totals;
|
|
309
|
+
return value === void 0 ? [{ _tag: "retired" }, state] : [{
|
|
310
|
+
_tag: "success",
|
|
311
|
+
value
|
|
312
|
+
}, { nodes: nextNodes }];
|
|
313
|
+
}).pipe(Effect.flatMap((result) => {
|
|
314
|
+
switch (result._tag) {
|
|
315
|
+
case "success": return Effect.succeed(result.value);
|
|
316
|
+
case "failure": return Effect.fail(result.error);
|
|
317
|
+
case "retired": return retiredDefect();
|
|
318
|
+
}
|
|
319
|
+
})))),
|
|
320
|
+
snapshot,
|
|
321
|
+
guard
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
/** Create the outermost node of a hierarchy. Child nodes share its atomic ledger. */
|
|
325
|
+
const makeUsageBudgetRoot = Effect.fn("makeUsageBudgetRoot")(function* (config) {
|
|
326
|
+
const startedAt = yield* Clock.currentTimeMillis;
|
|
327
|
+
const key = nodeKeyComponent(config);
|
|
328
|
+
const handleId = Symbol(`usage-budget:${config.level}:${config.id}`);
|
|
329
|
+
const ledger = yield* Ref.make({ nodes: /* @__PURE__ */ new Map([[key, {
|
|
330
|
+
config,
|
|
331
|
+
startedAt,
|
|
332
|
+
totals: emptyTotals(),
|
|
333
|
+
handles: /* @__PURE__ */ new Set([handleId])
|
|
334
|
+
}]]) });
|
|
335
|
+
return makeNode(ledger, key, [], config, handleId);
|
|
336
|
+
});
|
|
337
|
+
/** Compatibility constructor for a standalone Run budget. */
|
|
338
|
+
const makeUsageBudget = (limits) => makeUsageBudgetRoot(UsageBudgetNodeConfig.make({
|
|
339
|
+
level: "run",
|
|
340
|
+
id: "standalone-run",
|
|
341
|
+
limits
|
|
342
|
+
}));
|
|
343
|
+
//#endregion
|
|
344
|
+
export { BudgetExceeded, BudgetNodeConflict, InvalidBudgetHierarchy, UsageBudgetLimits, UsageBudgetNodeConfig, UsageDelta, UsageTotals, makeUsageBudget, makeUsageBudgetRoot, Budget_exports as t };
|
|
345
|
+
|
|
346
|
+
//# sourceMappingURL=Budget.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Budget.mjs","names":[],"sources":["../../src/capabilities/Budget.ts"],"sourcesContent":["import { Clock, Duration, Effect, Ref, Schema, type Scope } from \"effect\";\n\nconst Natural = Schema.Natural;\nconst BudgetLevel = Schema.Literals([\"global\", \"tenant\", \"agent\", \"thread\", \"run\"]);\n\nexport type BudgetLevel = typeof BudgetLevel.Type;\n\n/** Fixed units avoid floating-point currency accounting: costs are micro-USD. */\nexport class UsageTotals extends Schema.Class<UsageTotals>(\n \"@effect-agent/capabilities/UsageTotals\",\n)({\n /** Total input tokens across every model call, INCLUDING cache reads and writes at par. */\n inputTokens: Natural,\n outputTokens: Natural,\n /** Informational split of `inputTokens` served from the provider prompt cache; never separately limited. */\n cacheReadInputTokens: Natural,\n /** Informational split of `inputTokens` written to the provider prompt cache; never separately limited. */\n cacheWriteInputTokens: Natural,\n /** The most recent model call's input tokens — the live model-context estimate (CAP-017). */\n lastInputTokens: Natural,\n /** The most recent model call's output tokens. */\n lastOutputTokens: Natural,\n toolCalls: Natural,\n costMicrousd: Natural,\n elapsedMillis: Natural,\n}) {}\n\n/** Increment recorded at one model/tool accounting boundary. */\nexport class UsageDelta extends Schema.Class<UsageDelta>(\"@effect-agent/capabilities/UsageDelta\")({\n /** `1` for a model-response boundary, `0` for a mid-pass tool charge; gates last-call tracking. */\n modelCalls: Natural,\n /** Total input tokens of this boundary, INCLUDING cache reads and writes at par. */\n inputTokens: Natural,\n outputTokens: Natural,\n /** Informational split of `inputTokens` served from the provider prompt cache; never separately limited. */\n cacheReadInputTokens: Natural,\n /** Informational split of `inputTokens` written to the provider prompt cache; never separately limited. */\n cacheWriteInputTokens: Natural,\n toolCalls: Natural,\n costMicrousd: Natural,\n}) {}\n\n/** All optional limits are finite when present; absent means not configured. */\nexport class UsageBudgetLimits extends Schema.Class<UsageBudgetLimits>(\n \"@effect-agent/capabilities/UsageBudgetLimits\",\n)({\n maxInputTokens: Schema.optionalKey(Natural),\n maxOutputTokens: Schema.optionalKey(Natural),\n maxToolCalls: Schema.optionalKey(Natural),\n maxCostMicrousd: Schema.optionalKey(Natural),\n maxDurationMillis: Schema.optionalKey(Natural),\n}) {}\n\n/** Identity and local limits for one node in a global-to-Run budget hierarchy. */\nexport class UsageBudgetNodeConfig extends Schema.Class<UsageBudgetNodeConfig>(\n \"@effect-agent/capabilities/UsageBudgetNodeConfig\",\n)({\n level: BudgetLevel,\n id: Schema.NonEmptyString,\n limits: UsageBudgetLimits,\n}) {}\n\n/** Typed finite-budget rejection. A rejected increment is not committed at any hierarchy level. */\nexport class BudgetExceeded extends Schema.TaggedError<BudgetExceeded>()(\"BudgetExceeded\", {\n scopeLevel: BudgetLevel,\n scopeId: Schema.NonEmptyString,\n limit: Schema.Literals([\"input-tokens\", \"output-tokens\", \"tool-calls\", \"cost\", \"duration\"]),\n limitValue: Natural,\n observedValue: Natural,\n}) {}\n\n/** Hierarchical accounting authority. All ancestors share one atomic Ref-backed transaction. */\nexport interface UsageBudgetNode {\n readonly level: BudgetLevel;\n readonly id: string;\n /**\n * Register or re-attach one child node. Re-attaching an already-registered\n * `level:id` with identical limits returns a handle to the shared\n * registration; different limits fail with BudgetNodeConflict rather than\n * being silently ignored. Every returned handle owns one registration and\n * must be retired when its lifetime ends; prefer `childScoped` when the\n * lifetime already belongs to an Effect Scope.\n */\n readonly child: (\n config: UsageBudgetNodeConfig,\n ) => Effect.Effect<UsageBudgetNode, InvalidBudgetHierarchy | BudgetNodeConflict>;\n /** Register a child whose registration is retired when the current Scope closes. */\n readonly childScoped: (\n config: UsageBudgetNodeConfig,\n ) => Effect.Effect<UsageBudgetNode, InvalidBudgetHierarchy | BudgetNodeConflict, Scope.Scope>;\n /**\n * Release this handle's registration exactly once. Accumulated usage stays\n * charged to every live ancestor; a node is reclaimed only after its last\n * handle and every descendant have retired.\n */\n readonly retire: Effect.Effect<void>;\n readonly consume: (delta: UsageDelta) => Effect.Effect<UsageTotals, BudgetExceeded>;\n readonly snapshot: Effect.Effect<UsageTotals>;\n /**\n * Guard stalled model/tool work with the earliest configured ancestor deadline.\n * The timeout is driven by Effect Clock and interrupts the guarded child effect.\n */\n readonly guard: <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | BudgetExceeded, R>;\n}\n\n/** A child budget must move strictly inward through the declared hierarchy. */\nexport class InvalidBudgetHierarchy extends Schema.TaggedError<InvalidBudgetHierarchy>()(\n \"InvalidBudgetHierarchy\",\n {\n parentLevel: BudgetLevel,\n childLevel: BudgetLevel,\n },\n) {}\n\n/** A child `level:id` is already registered with different limits; neither set may win silently. */\nexport class BudgetNodeConflict extends Schema.TaggedError<BudgetNodeConflict>()(\n \"BudgetNodeConflict\",\n {\n scopeLevel: BudgetLevel,\n scopeId: Schema.NonEmptyString,\n },\n) {}\n\ninterface LedgerNode {\n readonly config: UsageBudgetNodeConfig;\n readonly startedAt: number;\n readonly totals: UsageTotals;\n /** Ledger-owned identities of the live handles for this exact registration. */\n readonly handles: ReadonlySet<symbol>;\n}\n\ninterface BudgetLedger {\n readonly nodes: ReadonlyMap<string, LedgerNode>;\n}\n\ntype ConsumptionResult =\n | { readonly _tag: \"success\"; readonly value: UsageTotals }\n | { readonly _tag: \"failure\"; readonly error: BudgetExceeded }\n | { readonly _tag: \"retired\" };\n\ntype ChildRegistrationResult =\n | { readonly _tag: \"success\" }\n | { readonly _tag: \"conflict\"; readonly error: BudgetNodeConflict }\n | { readonly _tag: \"invalid\"; readonly error: InvalidBudgetHierarchy }\n | { readonly _tag: \"retired\" };\n\nconst levelOrder: Readonly<Record<BudgetLevel, number>> = {\n global: 0,\n tenant: 1,\n agent: 2,\n thread: 3,\n run: 4,\n};\n\nconst emptyTotals = (elapsedMillis = 0): UsageTotals =>\n UsageTotals.make({\n inputTokens: 0,\n outputTokens: 0,\n cacheReadInputTokens: 0,\n cacheWriteInputTokens: 0,\n lastInputTokens: 0,\n lastOutputTokens: 0,\n toolCalls: 0,\n costMicrousd: 0,\n elapsedMillis,\n });\n\n// Spread-preserve every accumulated field so future additions cannot be\n// silently dropped by an elapsed-only snapshot.\nconst withElapsed = (node: LedgerNode, now: number): UsageTotals =>\n UsageTotals.make({\n ...node.totals,\n elapsedMillis: Math.max(0, now - node.startedAt),\n });\n\nconst addUsage = (node: LedgerNode, delta: UsageDelta, now: number): UsageTotals =>\n UsageTotals.make({\n inputTokens: node.totals.inputTokens + delta.inputTokens,\n outputTokens: node.totals.outputTokens + delta.outputTokens,\n cacheReadInputTokens: node.totals.cacheReadInputTokens + delta.cacheReadInputTokens,\n cacheWriteInputTokens: node.totals.cacheWriteInputTokens + delta.cacheWriteInputTokens,\n lastInputTokens: delta.modelCalls > 0 ? delta.inputTokens : node.totals.lastInputTokens,\n lastOutputTokens: delta.modelCalls > 0 ? delta.outputTokens : node.totals.lastOutputTokens,\n toolCalls: node.totals.toolCalls + delta.toolCalls,\n costMicrousd: node.totals.costMicrousd + delta.costMicrousd,\n elapsedMillis: Math.max(0, now - node.startedAt),\n });\n\nconst exceeded = (node: LedgerNode, totals: UsageTotals): BudgetExceeded | undefined => {\n const limits = node.config.limits;\n\n const checks: ReadonlyArray<readonly [BudgetExceeded[\"limit\"], number | undefined, number]> = [\n [\"input-tokens\", limits.maxInputTokens, totals.inputTokens],\n [\"output-tokens\", limits.maxOutputTokens, totals.outputTokens],\n [\"tool-calls\", limits.maxToolCalls, totals.toolCalls],\n [\"cost\", limits.maxCostMicrousd, totals.costMicrousd],\n [\"duration\", limits.maxDurationMillis, totals.elapsedMillis],\n ];\n\n for (const [limit, limitValue, observedValue] of checks) {\n if (limitValue !== undefined && observedValue > limitValue) {\n return BudgetExceeded.make({\n scopeLevel: node.config.level,\n scopeId: node.config.id,\n limit,\n limitValue,\n observedValue,\n });\n }\n }\n\n return undefined;\n};\n\nconst sameLimits = (a: UsageBudgetLimits, b: UsageBudgetLimits): boolean =>\n a.maxInputTokens === b.maxInputTokens &&\n a.maxOutputTokens === b.maxOutputTokens &&\n a.maxToolCalls === b.maxToolCalls &&\n a.maxCostMicrousd === b.maxCostMicrousd &&\n a.maxDurationMillis === b.maxDurationMillis;\n\n// JSON escapes lone surrogates before URI encoding; every valid string stays distinct,\n// and an ID can never introduce the path separator used by retirement.\nconst nodeKeyComponent = (config: UsageBudgetNodeConfig): string =>\n `${config.level}:${encodeURIComponent(JSON.stringify(config.id))}`;\n\nconst durationExceeded = (node: LedgerNode, now: number): BudgetExceeded => {\n const limitValue = node.config.limits.maxDurationMillis ?? 0;\n\n return BudgetExceeded.make({\n scopeLevel: node.config.level,\n scopeId: node.config.id,\n limit: \"duration\",\n limitValue,\n observedValue: Math.max(limitValue + 1, now - node.startedAt),\n });\n};\n\n/** Reclaim one released leaf and any newly unowned ancestors on its fixed hierarchy path. */\nconst pruneRetiredHierarchy = (\n nodes: Map<string, LedgerNode>,\n hierarchy: ReadonlyArray<string>,\n): Map<string, LedgerNode> => {\n for (let index = hierarchy.length - 1; index >= 0; index -= 1) {\n const candidateKey = hierarchy[index];\n\n if (candidateKey === undefined) continue;\n const candidate = nodes.get(candidateKey);\n\n if (candidate === undefined) continue;\n if (candidate.handles.size > 0) break;\n const childPrefix = `${candidateKey}/`;\n\n if ([...nodes.keys()].some((otherKey) => otherKey.startsWith(childPrefix))) {\n break;\n }\n nodes.delete(candidateKey);\n }\n\n return nodes;\n};\n\nconst makeNode = (\n ledger: Ref.Ref<BudgetLedger>,\n key: string,\n ancestors: ReadonlyArray<string>,\n config: UsageBudgetNodeConfig,\n handleId: symbol,\n): UsageBudgetNode => {\n const hierarchy = [...ancestors, key];\n\n const retiredDefect = () =>\n Effect.die(\n new Error(`Usage budget handle ${config.level}:${config.id} was used after retirement`),\n );\n\n const liveHierarchy = (state: BudgetLedger): ReadonlyArray<LedgerNode> | undefined => {\n const current = state.nodes.get(key);\n\n if (current === undefined || !current.handles.has(handleId)) return undefined;\n const nodes: Array<LedgerNode> = [];\n\n for (const ancestorKey of hierarchy) {\n const node = state.nodes.get(ancestorKey);\n\n if (node === undefined) return undefined;\n nodes.push(node);\n }\n\n return nodes;\n };\n\n const readLiveHierarchy = Ref.modify(\n ledger,\n (state): readonly [ReadonlyArray<LedgerNode> | undefined, BudgetLedger] => [\n liveHierarchy(state),\n state,\n ],\n );\n\n const snapshot = Effect.gen(function* () {\n const now = yield* Clock.currentTimeMillis;\n const nodes = yield* readLiveHierarchy;\n\n if (nodes === undefined) return yield* retiredDefect();\n const node = nodes[nodes.length - 1];\n\n if (node === undefined) return yield* retiredDefect();\n\n return withElapsed(node, now);\n });\n\n const guard = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A, E | BudgetExceeded, R> =>\n Effect.gen(function* () {\n const now = yield* Clock.currentTimeMillis;\n const nodes = yield* readLiveHierarchy;\n\n if (nodes === undefined) return yield* retiredDefect();\n let deadline: { readonly remaining: number; readonly node: LedgerNode } | undefined;\n\n for (const node of nodes) {\n const current = withElapsed(node, now);\n const alreadyExceeded = exceeded(node, current);\n\n if (alreadyExceeded !== undefined) {\n return yield* alreadyExceeded;\n }\n const maxDuration = node.config.limits.maxDurationMillis;\n\n if (maxDuration !== undefined) {\n const remaining = maxDuration - current.elapsedMillis;\n\n if (remaining <= 0) {\n return yield* durationExceeded(node, now);\n }\n if (deadline === undefined || remaining < deadline.remaining) {\n deadline = { remaining, node };\n }\n }\n }\n if (deadline === undefined) {\n return yield* effect;\n }\n const selected = deadline;\n\n return yield* effect.pipe(\n Effect.timeoutOrElse({\n duration: Duration.millis(selected.remaining),\n orElse: () =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((timeoutAt) =>\n Effect.fail(durationExceeded(selected.node, timeoutAt)),\n ),\n ),\n }),\n );\n });\n\n const child = Effect.fn(\"UsageBudgetNode.child\")(function* (childConfig: UsageBudgetNodeConfig) {\n const childKey = `${key}/${nodeKeyComponent(childConfig)}`;\n const childHandleId = Symbol(`usage-budget:${childConfig.level}:${childConfig.id}`);\n const now = yield* Clock.currentTimeMillis;\n\n const registration = yield* Ref.modify(\n ledger,\n (state): readonly [ChildRegistrationResult, BudgetLedger] => {\n if (liveHierarchy(state) === undefined) {\n return [{ _tag: \"retired\" }, state];\n }\n if (levelOrder[childConfig.level] <= levelOrder[config.level]) {\n return [\n {\n _tag: \"invalid\",\n error: InvalidBudgetHierarchy.make({\n parentLevel: config.level,\n childLevel: childConfig.level,\n }),\n },\n state,\n ];\n }\n const existing = state.nodes.get(childKey);\n\n if (existing !== undefined) {\n return sameLimits(existing.config.limits, childConfig.limits)\n ? [\n { _tag: \"success\" },\n {\n nodes: new Map(state.nodes).set(childKey, {\n ...existing,\n handles: new Set(existing.handles).add(childHandleId),\n }),\n },\n ]\n : [\n {\n _tag: \"conflict\",\n error: BudgetNodeConflict.make({\n scopeLevel: childConfig.level,\n scopeId: childConfig.id,\n }),\n },\n state,\n ];\n }\n\n return [\n { _tag: \"success\" },\n {\n nodes: new Map(state.nodes).set(childKey, {\n config: childConfig,\n startedAt: now,\n totals: emptyTotals(),\n handles: new Set([childHandleId]),\n }),\n },\n ];\n },\n );\n\n if (registration._tag === \"retired\") return yield* retiredDefect();\n if (registration._tag === \"conflict\" || registration._tag === \"invalid\") {\n return yield* registration.error;\n }\n\n return makeNode(ledger, childKey, hierarchy, childConfig, childHandleId);\n });\n\n const retire = Effect.uninterruptible(\n Ref.update(ledger, (state) => {\n const existing = state.nodes.get(key);\n\n if (existing === undefined || !existing.handles.has(handleId)) return state;\n const handles = new Set(existing.handles);\n\n handles.delete(handleId);\n const nodes = new Map(state.nodes).set(key, { ...existing, handles });\n\n return { nodes: pruneRetiredHierarchy(nodes, hierarchy) };\n }),\n );\n\n return {\n level: config.level,\n id: config.id,\n child,\n childScoped: (childConfig) => Effect.acquireRelease(child(childConfig), (node) => node.retire),\n retire,\n consume: (delta) =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((now) =>\n Ref.modify(ledger, (state): readonly [ConsumptionResult, BudgetLedger] => {\n if (liveHierarchy(state) === undefined) {\n return [{ _tag: \"retired\" }, state];\n }\n const updates = new Map<string, LedgerNode>();\n\n for (const ancestorKey of hierarchy) {\n const node = state.nodes.get(ancestorKey);\n\n if (node === undefined) return [{ _tag: \"retired\" }, state];\n const totals = addUsage(node, delta, now);\n const error = exceeded(node, totals);\n\n if (error !== undefined) {\n return [{ _tag: \"failure\", error }, state];\n }\n updates.set(ancestorKey, { ...node, totals });\n }\n const nextNodes = new Map(state.nodes);\n\n for (const [updatedKey, updatedNode] of updates) {\n nextNodes.set(updatedKey, updatedNode);\n }\n const value = updates.get(key)?.totals;\n\n return value === undefined\n ? [{ _tag: \"retired\" }, state]\n : [{ _tag: \"success\", value }, { nodes: nextNodes }];\n }).pipe(\n Effect.flatMap((result) => {\n switch (result._tag) {\n case \"success\":\n return Effect.succeed(result.value);\n case \"failure\":\n return Effect.fail(result.error);\n case \"retired\":\n return retiredDefect();\n }\n }),\n ),\n ),\n ),\n snapshot,\n guard,\n };\n};\n\n/** Create the outermost node of a hierarchy. Child nodes share its atomic ledger. */\nexport const makeUsageBudgetRoot = Effect.fn(\"makeUsageBudgetRoot\")(function* (\n config: UsageBudgetNodeConfig,\n) {\n const startedAt = yield* Clock.currentTimeMillis;\n const key = nodeKeyComponent(config);\n const handleId = Symbol(`usage-budget:${config.level}:${config.id}`);\n\n const ledger = yield* Ref.make<BudgetLedger>({\n nodes: new Map([\n [\n key,\n {\n config,\n startedAt,\n totals: emptyTotals(),\n handles: new Set([handleId]),\n },\n ],\n ]),\n });\n\n return makeNode(ledger, key, [], config, handleId);\n});\n\n/** Compatibility constructor for a standalone Run budget. */\nexport const makeUsageBudget = (limits: UsageBudgetLimits): Effect.Effect<UsageBudgetNode> =>\n makeUsageBudgetRoot(\n UsageBudgetNodeConfig.make({\n level: \"run\",\n id: \"standalone-run\",\n limits,\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;AAEA,MAAM,UAAU,OAAO;AACvB,MAAM,cAAc,OAAO,SAAS;CAAC;CAAU;CAAU;CAAS;CAAU;AAAK,CAAC;;AAKlF,IAAa,cAAb,cAAiC,OAAO,MACtC,wCACF,CAAC,CAAC;;CAEA,aAAa;CACb,cAAc;;CAEd,sBAAsB;;CAEtB,uBAAuB;;CAEvB,iBAAiB;;CAEjB,kBAAkB;CAClB,WAAW;CACX,cAAc;CACd,eAAe;AACjB,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa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AI,IAAI,MAAM,KAAK;GAErC,KAAK,MAAM,CAAC,YAAY,gBAAgB,SACtC,UAAU,IAAI,YAAY,WAAW;GAEvC,MAAM,QAAQ,QAAQ,IAAI,GAAG,CAAC,EAAE;GAEhC,OAAO,UAAU,KAAA,IACb,CAAC,EAAE,MAAM,UAAU,GAAG,KAAK,IAC3B,CAAC;IAAE,MAAM;IAAW;GAAM,GAAG,EAAE,OAAO,UAAU,CAAC;EACvD,CAAC,CAAC,CAAC,KACD,OAAO,SAAS,WAAW;GACzB,QAAQ,OAAO,MAAf;IACE,KAAK,WACH,OAAO,OAAO,QAAQ,OAAO,KAAK;IACpC,KAAK,WACH,OAAO,OAAO,KAAK,OAAO,KAAK;IACjC,KAAK,WACH,OAAO,cAAc;GACzB;EACF,CAAC,CACH,CACF,CACF;EACF;EACA;CACF;AACF;;AAGA,MAAa,sBAAsB,OAAO,GAAG,qBAAqB,CAAC,CAAC,WAClE,QACA;CACA,MAAM,YAAY,OAAO,MAAM;CAC/B,MAAM,MAAM,iBAAiB,MAAM;CACnC,MAAM,WAAW,OAAO,gBAAgB,OAAO,MAAM,GAAG,OAAO,IAAI;CAEnE,MAAM,SAAS,OAAO,IAAI,KAAmB,EAC3C,uBAAO,IAAI,IAAI,CACb,CACE,KACA;EACE;EACA;EACA,QAAQ,YAAY;EACpB,yBAAS,IAAI,IAAI,CAAC,QAAQ,CAAC;CAC7B,CACF,CACF,CAAC,EACH,CAAC;CAED,OAAO,SAAS,QAAQ,KAAK,CAAC,GAAG,QAAQ,QAAQ;AACnD,CAAC;;AAGD,MAAa,mBAAmB,WAC9B,oBACE,sBAAsB,KAAK;CACzB,OAAO;CACP,IAAI;CACJ;AACF,CAAC,CACH"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { s as ToolBroker } from "../ToolBroker-DWs4tZra.mjs";
|
|
2
|
+
import { CodeExecutionLimits, CodeExecutionNamespace, CodeExecutor } from "../sandbox/CodeExecutor.mjs";
|
|
3
|
+
import { Tool } from "effect/unstable/ai";
|
|
4
|
+
import { Cause, Effect, Layer, Schema, Scope } from "effect";
|
|
5
|
+
declare namespace CodeMode_d_exports {
|
|
6
|
+
export { CodeModeDefinition, CodeModeDescriptionError, CodeModeFailure, CodeModeLayerRequirements, CodeModeNamespaces, CodeModeOptions, CodeModeParameters, CodeModePassReport, CodeModeSelectedRecord, CodeModeSelectedTool, CodeModeSuccess, CodeModeTool, CodeModeTools, make };
|
|
7
|
+
}
|
|
8
|
+
/** A pass-local report, available to the host even when the caller interrupts execution. */
|
|
9
|
+
declare const CodeModePassReport: Schema.Struct<{
|
|
10
|
+
readonly status: Schema.Literals<readonly ["completed", "failed", "interrupted", "defect"]>;
|
|
11
|
+
readonly calls: Schema.$Array<Schema.Struct<{
|
|
12
|
+
readonly sequenceIndex: Schema.Natural;
|
|
13
|
+
readonly toolName: Schema.String;
|
|
14
|
+
readonly status: Schema.Literals<readonly ["not-started", "succeeded", "failed", "uncertain"]>;
|
|
15
|
+
readonly errorTag: Schema.optionalKey<Schema.String>;
|
|
16
|
+
}>>;
|
|
17
|
+
}>;
|
|
18
|
+
type CodeModePassReport = typeof CodeModePassReport.Type;
|
|
19
|
+
/** Model-decoded Code Mode parameters: one async function expression. */
|
|
20
|
+
declare const CodeModeParameters: Schema.Struct<{
|
|
21
|
+
readonly code: Schema.NonEmptyString;
|
|
22
|
+
}>;
|
|
23
|
+
declare const CodeModeSuccess_base: Schema.Class<CodeModeSuccess, Schema.Struct<{
|
|
24
|
+
readonly result: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
25
|
+
readonly logs: Schema.$Array<Schema.String>;
|
|
26
|
+
}>, {}>;
|
|
27
|
+
/**
|
|
28
|
+
* The bounded model-visible success: the program's JSON result plus captured
|
|
29
|
+
* logs, both already passed through the aggregate egress budget (CAP-016).
|
|
30
|
+
*/
|
|
31
|
+
declare class CodeModeSuccess extends CodeModeSuccess_base {}
|
|
32
|
+
declare const CodeModeFailure_base: Schema.Class<CodeModeFailure, Schema.TaggedStruct<"CodeModeFailure", {
|
|
33
|
+
readonly errorTag: Schema.NonEmptyString;
|
|
34
|
+
readonly message: Schema.String;
|
|
35
|
+
readonly logs: Schema.$Array<Schema.String>;
|
|
36
|
+
readonly thrown: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
37
|
+
/** Invocation-ordered evidence that fits the egress budget. This is not a replay plan. */
|
|
38
|
+
readonly calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
39
|
+
readonly sequenceIndex: Schema.Natural;
|
|
40
|
+
readonly toolName: Schema.String;
|
|
41
|
+
readonly status: Schema.Literals<readonly ["not-started", "succeeded", "failed", "uncertain"]>;
|
|
42
|
+
readonly errorTag: Schema.optionalKey<Schema.String>;
|
|
43
|
+
}>>>;
|
|
44
|
+
readonly omittedCalls: Schema.optionalKey<Schema.Natural>;
|
|
45
|
+
}>, Cause.YieldableError>;
|
|
46
|
+
/**
|
|
47
|
+
* The bounded model-visible failure envelope. `failureMode: "return"` turns
|
|
48
|
+
* it into a failed Tool result, so a model can correct a failing program
|
|
49
|
+
* without a blind retry; it carries the same bounded log capture as success
|
|
50
|
+
* plus the bounded thrown value where one exists, all inside the same
|
|
51
|
+
* aggregate egress budget (CAP-016).
|
|
52
|
+
*/
|
|
53
|
+
declare class CodeModeFailure extends CodeModeFailure_base {}
|
|
54
|
+
declare const CodeModeDescriptionError_base: Schema.Class<CodeModeDescriptionError, Schema.TaggedStruct<"CodeModeDescriptionError", {
|
|
55
|
+
readonly reason: Schema.Literals<readonly ["invalid-selection", "unknown-method", "invalid-bound", "limit-exceeded"]>;
|
|
56
|
+
readonly message: Schema.String;
|
|
57
|
+
}>, Cause.YieldableError>;
|
|
58
|
+
/** A selective documentation request is invalid or cannot fit its declared byte budget. */
|
|
59
|
+
declare class CodeModeDescriptionError extends CodeModeDescriptionError_base {}
|
|
60
|
+
/** The namespace-record shape accepted by `CodeMode.make`. */
|
|
61
|
+
type CodeModeNamespaces = Record<string, Record<string, Tool.Any>>;
|
|
62
|
+
/**
|
|
63
|
+
* Union of every Tool selected across all namespaces, computed distributively
|
|
64
|
+
* per namespace: indexing the namespace union with the INTERSECTION of method
|
|
65
|
+
* keys would erase every Tool once two namespaces have disjoint methods.
|
|
66
|
+
*/
|
|
67
|
+
type CodeModeSelectedTool<Namespaces extends CodeModeNamespaces> = { [Namespace in keyof Namespaces]: Namespaces[Namespace][keyof Namespaces[Namespace]]; }[keyof Namespaces];
|
|
68
|
+
/** The selected Tools re-keyed by their own Tool names. */
|
|
69
|
+
type CodeModeSelectedRecord<Namespaces extends CodeModeNamespaces> = { readonly [T in CodeModeSelectedTool<Namespaces> as T["name"]]: T; };
|
|
70
|
+
/**
|
|
71
|
+
* The native Effect AI Tool created by `CodeMode.make` (CAP-014). Its only
|
|
72
|
+
* per-call dependency is the engine-provided `ToolBroker`; the `CodeExecutor`
|
|
73
|
+
* and every selected handler and redaction service are construction requirements of the handler
|
|
74
|
+
* Layer instead, so they stay visible in the composed `R`.
|
|
75
|
+
*/
|
|
76
|
+
type CodeModeTool<Name extends string> = Tool.Tool<Name, {
|
|
77
|
+
readonly parameters: typeof CodeModeParameters;
|
|
78
|
+
readonly success: typeof CodeModeSuccess;
|
|
79
|
+
readonly failure: typeof CodeModeFailure;
|
|
80
|
+
readonly failureMode: "return";
|
|
81
|
+
}, ToolBroker>;
|
|
82
|
+
/** Singleton Tool record provided by one Code Mode handler Layer. */
|
|
83
|
+
type CodeModeTools<Name extends string> = { readonly [Key in Name]: CodeModeTool<Name>; };
|
|
84
|
+
/** Construction requirements of the Code Mode handler Layer. */
|
|
85
|
+
type CodeModeLayerRequirements<Namespaces extends CodeModeNamespaces, RedactionRequirements = never> = CodeExecutor | Exclude<RedactionRequirements, Scope.Scope> | Tool.HandlersFor<CodeModeSelectedRecord<Namespaces>> | Tool.HandlerServices<CodeModeSelectedTool<Namespaces>>;
|
|
86
|
+
interface CodeModeOptions<Namespaces extends CodeModeNamespaces, RedactionRequirements = never> {
|
|
87
|
+
/** Model-visible description; the builder appends the sandbox contract. */
|
|
88
|
+
readonly description: string;
|
|
89
|
+
/** Include all sandbox declarations in the model-facing description. Defaults to true. */
|
|
90
|
+
readonly includeDeclarations?: boolean | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Explicit allowlist: namespace name → method name → native Effect AI
|
|
93
|
+
* Tool. Reads and mutations are allowed; calls requiring additional approval fail closed.
|
|
94
|
+
*/
|
|
95
|
+
readonly tools: Namespaces;
|
|
96
|
+
/** Executor limits for one pass; a bounded default applies when omitted. */
|
|
97
|
+
readonly limits?: CodeExecutionLimits | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Aggregate model-visible egress budget in UTF-8 bytes across the final
|
|
100
|
+
* result, captured logs, and any thrown value (CAP-016). Default 65536.
|
|
101
|
+
*/
|
|
102
|
+
readonly maxEgressBytes?: number | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Host-only ephemeral report after executor resources and invocation fibers close, including
|
|
105
|
+
* failure, defect, and interruption. It contains no arguments/results and is never a checkpoint.
|
|
106
|
+
* Keep this total callback bounded; its services are captured with the handler Layer.
|
|
107
|
+
*/
|
|
108
|
+
readonly onPassExit?: ((report: CodeModePassReport) => Effect.Effect<void, never, RedactionRequirements>) | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Optional aggregate redaction pass applied to the model-visible egress
|
|
111
|
+
* before the byte budget. Its services are acquired with the handler Layer;
|
|
112
|
+
* temporary resources close with each redaction invocation.
|
|
113
|
+
* It must be total; a defect stays a defect.
|
|
114
|
+
*/
|
|
115
|
+
readonly redactEgress?: ((egress: {
|
|
116
|
+
readonly result: Schema.Json;
|
|
117
|
+
readonly logs: ReadonlyArray<string>;
|
|
118
|
+
}) => Effect.Effect<{
|
|
119
|
+
readonly result: Schema.Json;
|
|
120
|
+
readonly logs: ReadonlyArray<string>;
|
|
121
|
+
}, never, RedactionRequirements>) | undefined;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* An immutable Code Mode definition: one model-facing Tool over an explicit
|
|
125
|
+
* allowlist, plus the handler Layer that runs generated programs through the
|
|
126
|
+
* `CodeExecutor` port and the engine-owned broker. It owns no acquired
|
|
127
|
+
* resources.
|
|
128
|
+
*/
|
|
129
|
+
interface CodeModeDefinition<Name extends string, Namespaces extends CodeModeNamespaces, RedactionRequirements = never> {
|
|
130
|
+
readonly name: Name;
|
|
131
|
+
/** The assembled model-facing description, optionally including all declarations. */
|
|
132
|
+
readonly description: string;
|
|
133
|
+
/** Rendered TypeScript declarations of the sandbox globals (documentation only). */
|
|
134
|
+
readonly declarations: string;
|
|
135
|
+
/**
|
|
136
|
+
* Render complete encoded-schema declarations for 1–64 unique, exact namespace.method names.
|
|
137
|
+
* The UTF-8 byte limit defaults to 16384 and must be an integer from 1 through 262144.
|
|
138
|
+
* Oversized documentation fails rather than truncating a declaration. This host operation
|
|
139
|
+
* does not authorize a model to see the selected methods; filter selections by current
|
|
140
|
+
* visibility and inherited grants before returning its output to a model.
|
|
141
|
+
*/
|
|
142
|
+
readonly describe: (methods: ReadonlyArray<string>, options?: {
|
|
143
|
+
readonly maxBytes?: number | undefined;
|
|
144
|
+
}) => Effect.Effect<string, CodeModeDescriptionError>;
|
|
145
|
+
/** The executor-facing namespace catalog derived from the allowlist. */
|
|
146
|
+
readonly namespaces: ReadonlyArray<CodeExecutionNamespace>;
|
|
147
|
+
readonly limits: CodeExecutionLimits;
|
|
148
|
+
readonly maxEgressBytes: number;
|
|
149
|
+
/** The ordinary Effect AI Tool to include in the model-facing Toolkit. */
|
|
150
|
+
readonly tool: CodeModeTool<Name>;
|
|
151
|
+
/** Handler Layer; selected handler requirements stay visible in `R`. */
|
|
152
|
+
readonly handlers: Layer.Layer<Tool.HandlersFor<CodeModeTools<Name>>, never, CodeModeLayerRequirements<Namespaces, RedactionRequirements>>;
|
|
153
|
+
}
|
|
154
|
+
declare const make: <const Name extends string, Namespaces extends CodeModeNamespaces, RedactionRequirements = never>(name: Name, options: CodeModeOptions<Namespaces, RedactionRequirements>) => CodeModeDefinition<Name, Namespaces, RedactionRequirements>;
|
|
155
|
+
//#endregion
|
|
156
|
+
export { CodeModeDefinition, CodeModeDescriptionError, CodeModeFailure, CodeModeLayerRequirements, CodeModeNamespaces, CodeModeOptions, CodeModeParameters, CodeModePassReport, CodeModeSelectedRecord, CodeModeSelectedTool, CodeModeSuccess, CodeModeTool, CodeModeTools, make, CodeMode_d_exports as t };
|
|
157
|
+
//# sourceMappingURL=CodeMode.d.mts.map
|