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,151 @@
|
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { IdempotencyKey } from "../core/Receipt.mjs";
|
|
3
|
+
import { WorkerOperationTool } from "../core/SubagentContract.mjs";
|
|
4
|
+
import { c as InboxPage, d as MessageAdmission, f as MessageRef, h as PeerName, l as InputMessage, m as MessagingError, p as MessageStatus, s as InboxEntry, t as MessagingHost, u as MessageAddress } from "../MessagingHost-CWi_PP3g.mjs";
|
|
5
|
+
import { t as utf8Bytes } from "../utf8-BYfhEkcj.mjs";
|
|
6
|
+
import { Tool, Toolkit } from "effect/unstable/ai";
|
|
7
|
+
import { Crypto, Effect, Encoding, Option, Schema } from "effect";
|
|
8
|
+
//#region src/capabilities/Messaging.ts
|
|
9
|
+
var Messaging_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
InboxEntry: () => InboxEntry,
|
|
11
|
+
InboxPage: () => InboxPage,
|
|
12
|
+
InputMessage: () => InputMessage,
|
|
13
|
+
MessageAddress: () => MessageAddress,
|
|
14
|
+
MessageAdmission: () => MessageAdmission,
|
|
15
|
+
MessageRef: () => MessageRef,
|
|
16
|
+
MessageStatus: () => MessageStatus,
|
|
17
|
+
MessagingError: () => MessagingError,
|
|
18
|
+
PeerName: () => PeerName,
|
|
19
|
+
inbox: () => inbox,
|
|
20
|
+
inboxTool: () => inboxTool,
|
|
21
|
+
inspect: () => inspect,
|
|
22
|
+
inspectTool: () => inspectTool,
|
|
23
|
+
peer: () => peer,
|
|
24
|
+
reply: () => reply,
|
|
25
|
+
replyTool: () => replyTool,
|
|
26
|
+
retry: () => retry,
|
|
27
|
+
retryTool: () => retryTool,
|
|
28
|
+
send: () => send,
|
|
29
|
+
sendTool: () => sendTool
|
|
30
|
+
});
|
|
31
|
+
const peer = (name, options) => {
|
|
32
|
+
Schema.decodeSync(PeerName)(name);
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
name,
|
|
35
|
+
target: options.target
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const host = Effect.serviceOption(MessagingHost).pipe(Effect.flatMap((value) => Option.isSome(value) ? Effect.succeed(value.value) : MessagingError.make({
|
|
39
|
+
operation: "context",
|
|
40
|
+
reason: "unavailable"
|
|
41
|
+
})));
|
|
42
|
+
const dispatch = (declaration, input, options, operation) => Effect.gen(function* () {
|
|
43
|
+
const service = yield* host;
|
|
44
|
+
const invalid = () => MessagingError.make({
|
|
45
|
+
operation,
|
|
46
|
+
reason: "invalid-input"
|
|
47
|
+
});
|
|
48
|
+
const idempotencyKey = yield* Schema.decodeEffect(IdempotencyKey)(options.idempotencyKey).pipe(Effect.mapError(invalid));
|
|
49
|
+
const encodedInput = yield* Schema.encodeEffect(declaration.target.input)(input).pipe(Effect.mapError(invalid));
|
|
50
|
+
const inReplyTo = options.inReplyTo === void 0 ? void 0 : yield* Schema.decodeEffect(MessageRef)(options.inReplyTo).pipe(Effect.mapError(invalid));
|
|
51
|
+
const request = {
|
|
52
|
+
...declaration,
|
|
53
|
+
encodedInput,
|
|
54
|
+
idempotencyKey,
|
|
55
|
+
...inReplyTo === void 0 ? {} : { inReplyTo }
|
|
56
|
+
};
|
|
57
|
+
const result = operation === "reply" ? inReplyTo === void 0 ? yield* invalid() : yield* service.reply({
|
|
58
|
+
...request,
|
|
59
|
+
inReplyTo
|
|
60
|
+
}) : yield* service.send(request);
|
|
61
|
+
return yield* Schema.decodeEffect(MessageStatus)(result).pipe(Effect.mapError(() => MessagingError.make({
|
|
62
|
+
operation,
|
|
63
|
+
reason: "corrupt"
|
|
64
|
+
})));
|
|
65
|
+
});
|
|
66
|
+
/** Retain a durable message. Its status distinguishes outbound retention from destination acceptance. */
|
|
67
|
+
const send = (declaration, input, options) => dispatch(declaration, input, options, "send");
|
|
68
|
+
/** Reply to an authenticated inbound message; return routing still requires independent send authority. */
|
|
69
|
+
const reply = (declaration, inReplyTo, input, options) => dispatch(declaration, input, {
|
|
70
|
+
...options,
|
|
71
|
+
inReplyTo
|
|
72
|
+
}, "reply");
|
|
73
|
+
/** Return bounded provenance for messages from this peer, without granting permission to reply. */
|
|
74
|
+
const inbox = (declaration, options = {}) => Effect.gen(function* () {
|
|
75
|
+
return yield* (yield* host).inbox({
|
|
76
|
+
...declaration,
|
|
77
|
+
...options,
|
|
78
|
+
limit: options.limit ?? 20
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const inspect = (declaration, message) => Effect.gen(function* () {
|
|
82
|
+
return yield* (yield* host).inspect({
|
|
83
|
+
...declaration,
|
|
84
|
+
message
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
/** Explicitly renew a parked delivery's bounded retry budget, retaining its complete frozen envelope. */
|
|
88
|
+
const retry = (declaration, message) => Effect.gen(function* () {
|
|
89
|
+
return yield* (yield* host).retry({
|
|
90
|
+
...declaration,
|
|
91
|
+
message
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const modelKey = Effect.fn("Messaging.modelKey")(function* () {
|
|
95
|
+
const source = yield* (yield* host).context;
|
|
96
|
+
if (source._tag !== "tool") return yield* MessagingError.make({
|
|
97
|
+
operation: "send",
|
|
98
|
+
reason: "denied"
|
|
99
|
+
});
|
|
100
|
+
const digest = yield* (yield* Crypto.Crypto).digest("SHA-256", utf8Bytes(JSON.stringify(source))).pipe(Effect.mapError(() => MessagingError.make({
|
|
101
|
+
operation: "send",
|
|
102
|
+
reason: "unavailable"
|
|
103
|
+
})));
|
|
104
|
+
return Schema.decodeSync(IdempotencyKey)(`peer-tool:${Encoding.encodeHex(digest)}`);
|
|
105
|
+
});
|
|
106
|
+
const native = (name, parameters, success, description, handler) => {
|
|
107
|
+
const tool = Tool.make(name, {
|
|
108
|
+
parameters,
|
|
109
|
+
success,
|
|
110
|
+
failure: MessagingError,
|
|
111
|
+
description
|
|
112
|
+
}).annotate(WorkerOperationTool, true).addDependency(MessagingHost).addDependency(Crypto.Crypto);
|
|
113
|
+
const toolkit = Toolkit.make(tool);
|
|
114
|
+
const build = Effect.gen(function* () {
|
|
115
|
+
const captured = yield* Effect.context();
|
|
116
|
+
const invoke = Effect.fn("Messaging.tool")(function* (value) {
|
|
117
|
+
const service = yield* host;
|
|
118
|
+
const crypto = yield* Crypto.Crypto;
|
|
119
|
+
return yield* handler(value).pipe(Effect.provideService(MessagingHost, service), Effect.provideService(Crypto.Crypto, crypto), Effect.provide(captured));
|
|
120
|
+
});
|
|
121
|
+
return { [name]: invoke };
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
tool,
|
|
125
|
+
toolkit,
|
|
126
|
+
layer: toolkit.toLayer(build)
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/** Install only the native operations chosen by the host; schemas come from the Peer declaration. */
|
|
130
|
+
const sendTool = (declaration) => native(`${declaration.name}_send`, declaration.target.input, MessageStatus, `Send input to ${declaration.name} through its authorized durable route.`, (input) => Effect.gen(function* () {
|
|
131
|
+
return yield* send(declaration, input, { idempotencyKey: yield* modelKey() });
|
|
132
|
+
}));
|
|
133
|
+
const replyTool = (declaration) => {
|
|
134
|
+
const inputSchema = declaration.target.input;
|
|
135
|
+
return native(`${declaration.name}_reply`, Schema.Struct({
|
|
136
|
+
inReplyTo: MessageRef,
|
|
137
|
+
input: inputSchema
|
|
138
|
+
}), MessageStatus, `Reply to a recorded inbound message from ${declaration.name}.`, ({ inReplyTo, input }) => Effect.gen(function* () {
|
|
139
|
+
return yield* reply(declaration, inReplyTo, input, { idempotencyKey: yield* modelKey() });
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
const inboxTool = (declaration) => native(`${declaration.name}_inbox`, Schema.Struct({
|
|
143
|
+
after: Schema.optionalKey(Schema.Natural),
|
|
144
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)))
|
|
145
|
+
}), InboxPage, `Read a bounded page of message provenance from ${declaration.name}.`, (options) => inbox(declaration, options));
|
|
146
|
+
const inspectTool = (declaration) => native(`${declaration.name}_message_status`, Schema.Struct({ message: MessageRef }), MessageStatus, `Inspect delivery status of a message sent to ${declaration.name}.`, ({ message }) => inspect(declaration, message));
|
|
147
|
+
const retryTool = (declaration) => native(`${declaration.name}_retry_message`, Schema.Struct({ message: MessageRef }), MessageStatus, `Renew bounded automatic retries for a parked message to ${declaration.name}.`, ({ message }) => retry(declaration, message));
|
|
148
|
+
//#endregion
|
|
149
|
+
export { InboxEntry, InboxPage, InputMessage, MessageAddress, MessageAdmission, MessageRef, MessageStatus, MessagingError, PeerName, inbox, inboxTool, inspect, inspectTool, peer, reply, replyTool, retry, retryTool, send, sendTool, Messaging_exports as t };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=Messaging.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Messaging.mjs","names":[],"sources":["../../src/capabilities/Messaging.ts"],"sourcesContent":["import { Crypto, Effect, Encoding, Option, Schema } from \"effect\";\nimport { Tool, Toolkit } from \"effect/unstable/ai\";\n\nimport type { AnyDefinition } from \"../core/Agent.ts\";\nimport {\n InboxPage,\n MessageRef,\n MessageStatus,\n MessagingError,\n PeerName,\n} from \"../core/Messaging.ts\";\nimport { IdempotencyKey } from \"../core/Receipt.ts\";\nimport { WorkerOperationTool } from \"../core/SubagentContract.ts\";\nimport { MessagingHost } from \"../engine/MessagingHost.ts\";\nimport { utf8Bytes } from \"./internal/utf8.ts\";\n\nexport * from \"../core/Messaging.ts\";\n\n/** A fixed host route and its destination-owned input Schema. Construction acquires no resources. */\nexport interface Peer<Name extends string, Input extends Schema.Top> {\n readonly name: Name;\n readonly target: AnyDefinition & { readonly input: Input };\n}\n\nexport const peer = <const Name extends string, Input extends Schema.Top>(\n name: Name,\n options: { readonly target: AnyDefinition & { readonly input: Input } },\n): Peer<Name, Input> => {\n Schema.decodeSync(PeerName)(name);\n\n return Object.freeze({ name, target: options.target });\n};\n\nconst host: Effect.Effect<MessagingHost[\"Service\"], MessagingError, MessagingHost> =\n Effect.serviceOption(MessagingHost).pipe(\n Effect.flatMap((value) =>\n Option.isSome(value)\n ? Effect.succeed(value.value)\n : MessagingError.make({ operation: \"context\", reason: \"unavailable\" }),\n ),\n );\n\nconst dispatch = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n input: Input[\"Type\"],\n options: { readonly idempotencyKey: IdempotencyKey; readonly inReplyTo?: MessageRef },\n operation: \"send\" | \"reply\",\n) =>\n Effect.gen(function* () {\n const service = yield* host;\n const invalid = () => MessagingError.make({ operation, reason: \"invalid-input\" });\n\n const idempotencyKey = yield* Schema.decodeEffect(IdempotencyKey)(options.idempotencyKey).pipe(\n Effect.mapError(invalid),\n );\n\n const encodedInput = yield* Schema.encodeEffect(declaration.target.input)(input).pipe(\n Effect.mapError(invalid),\n );\n\n const inReplyTo =\n options.inReplyTo === undefined\n ? undefined\n : yield* Schema.decodeEffect(MessageRef)(options.inReplyTo).pipe(Effect.mapError(invalid));\n\n const request = {\n ...declaration,\n encodedInput,\n idempotencyKey,\n ...(inReplyTo === undefined ? {} : { inReplyTo }),\n };\n\n const result =\n operation === \"reply\"\n ? inReplyTo === undefined\n ? yield* invalid()\n : yield* service.reply({ ...request, inReplyTo })\n : yield* service.send(request);\n\n return yield* Schema.decodeEffect(MessageStatus)(result).pipe(\n Effect.mapError(() => MessagingError.make({ operation, reason: \"corrupt\" })),\n );\n });\n\n/** Retain a durable message. Its status distinguishes outbound retention from destination acceptance. */\nexport const send = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n input: Input[\"Type\"],\n options: { readonly idempotencyKey: IdempotencyKey; readonly inReplyTo?: MessageRef },\n) => dispatch(declaration, input, options, \"send\");\n\n/** Reply to an authenticated inbound message; return routing still requires independent send authority. */\nexport const reply = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n inReplyTo: MessageRef,\n input: Input[\"Type\"],\n options: { readonly idempotencyKey: IdempotencyKey },\n) => dispatch(declaration, input, { ...options, inReplyTo }, \"reply\");\n\n/** Return bounded provenance for messages from this peer, without granting permission to reply. */\nexport const inbox = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n options: { readonly after?: number; readonly limit?: number } = {},\n) =>\n Effect.gen(function* () {\n const service = yield* host;\n\n return yield* service.inbox({ ...declaration, ...options, limit: options.limit ?? 20 });\n });\n\nexport const inspect = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n message: MessageRef,\n) =>\n Effect.gen(function* () {\n const service = yield* host;\n\n return yield* service.inspect({ ...declaration, message });\n });\n\n/** Explicitly renew a parked delivery's bounded retry budget, retaining its complete frozen envelope. */\nexport const retry = <Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n message: MessageRef,\n) =>\n Effect.gen(function* () {\n const service = yield* host;\n\n return yield* service.retry({ ...declaration, message });\n });\n\nconst modelKey = Effect.fn(\"Messaging.modelKey\")(function* () {\n const source = yield* (yield* host).context;\n\n if (source._tag !== \"tool\")\n return yield* MessagingError.make({ operation: \"send\", reason: \"denied\" });\n const crypto = yield* Crypto.Crypto;\n\n const digest = yield* crypto\n .digest(\"SHA-256\", utf8Bytes(JSON.stringify(source)))\n .pipe(Effect.mapError(() => MessagingError.make({ operation: \"send\", reason: \"unavailable\" })));\n\n return Schema.decodeSync(IdempotencyKey)(`peer-tool:${Encoding.encodeHex(digest)}`);\n});\n\nconst native = <\n const Name extends string,\n Parameters extends Schema.Top,\n Success extends Schema.Top,\n R,\n>(\n name: Name,\n parameters: Parameters,\n success: Success,\n description: string,\n handler: (\n parameters: Parameters[\"Type\"],\n ) => Effect.Effect<Success[\"Type\"], MessagingError, R | MessagingHost | Crypto.Crypto>,\n) => {\n const tool = Tool.make(name, { parameters, success, failure: MessagingError, description })\n .annotate(WorkerOperationTool, true)\n .addDependency(MessagingHost)\n .addDependency(Crypto.Crypto);\n\n const toolkit = Toolkit.make(tool);\n\n const build = Effect.gen(function* () {\n const captured = yield* Effect.context<Exclude<R, MessagingHost | Crypto.Crypto>>();\n\n const invoke = Effect.fn(\"Messaging.tool\")(function* (value: Parameters[\"Type\"]) {\n const service = yield* host;\n const crypto = yield* Crypto.Crypto;\n\n return yield* handler(value).pipe(\n Effect.provideService(MessagingHost, service),\n Effect.provideService(Crypto.Crypto, crypto),\n Effect.provide(captured),\n );\n });\n\n // The computed single key is precisely the native Tool's literal name.\n return { [name]: invoke } as unknown as Toolkit.HandlersFrom<typeof toolkit.tools>;\n });\n\n return { tool, toolkit, layer: toolkit.toLayer(build) };\n};\n\n/** Install only the native operations chosen by the host; schemas come from the Peer declaration. */\nexport const sendTool = <const Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n) =>\n native(\n `${declaration.name}_send` as const,\n declaration.target.input,\n MessageStatus,\n `Send input to ${declaration.name} through its authorized durable route.`,\n (input) =>\n Effect.gen(function* () {\n return yield* send(declaration, input, { idempotencyKey: yield* modelKey() });\n }),\n );\n\nexport const replyTool = <const Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n) => {\n const inputSchema: Schema.Codec<\n Input[\"Type\"],\n Input[\"Encoded\"],\n Input[\"DecodingServices\"],\n Input[\"EncodingServices\"]\n > = declaration.target.input;\n\n return native(\n `${declaration.name}_reply` as const,\n Schema.Struct({ inReplyTo: MessageRef, input: inputSchema }),\n MessageStatus,\n `Reply to a recorded inbound message from ${declaration.name}.`,\n ({ inReplyTo, input }) =>\n Effect.gen(function* () {\n return yield* reply(declaration, inReplyTo, input, { idempotencyKey: yield* modelKey() });\n }),\n );\n};\n\nexport const inboxTool = <const Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n) =>\n native(\n `${declaration.name}_inbox` as const,\n Schema.Struct({\n after: Schema.optionalKey(Schema.Natural),\n limit: Schema.optionalKey(\n Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)),\n ),\n }),\n InboxPage,\n `Read a bounded page of message provenance from ${declaration.name}.`,\n (options) => inbox(declaration, options),\n );\n\nexport const inspectTool = <const Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n) =>\n native(\n `${declaration.name}_message_status` as const,\n Schema.Struct({ message: MessageRef }),\n MessageStatus,\n `Inspect delivery status of a message sent to ${declaration.name}.`,\n ({ message }) => inspect(declaration, message),\n );\n\nexport const retryTool = <const Name extends string, Input extends Schema.Top>(\n declaration: Peer<Name, Input>,\n) =>\n native(\n `${declaration.name}_retry_message` as const,\n Schema.Struct({ message: MessageRef }),\n MessageStatus,\n `Renew bounded automatic retries for a parked message to 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AAK,SACpB,OAAO,OAAO;CACZ,OAAO,OAAO,YAAY,OAAO,OAAO;CACxC,OAAO,OAAO,YACZ,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,GAAG,OAAO,oBAAoB,GAAG,CAAC,CAC3E;AACF,CAAC,GACD,WACA,kDAAkD,YAAY,KAAK,KAClE,YAAY,MAAM,aAAa,OAAO,CACzC;AAEF,MAAa,eACX,gBAEA,OACE,GAAG,YAAY,KAAK,kBACpB,OAAO,OAAO,EAAE,SAAS,WAAW,CAAC,GACrC,eACA,gDAAgD,YAAY,KAAK,KAChE,EAAE,cAAc,QAAQ,aAAa,OAAO,CAC/C;AAEF,MAAa,aACX,gBAEA,OACE,GAAG,YAAY,KAAK,iBACpB,OAAO,OAAO,EAAE,SAAS,WAAW,CAAC,GACrC,eACA,2DAA2D,YAAY,KAAK,KAC3E,EAAE,cAAc,MAAM,aAAa,OAAO,CAC7C"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { n as Thread } from "../Thread-DOBQ0QUY.mjs";
|
|
2
|
+
import { Crypto, Effect, Schema } from "effect";
|
|
3
|
+
declare namespace ModelContext_d_exports {
|
|
4
|
+
export { CompactionArtifact, CompactionDigestError, ContextLimitExceeded, ContextTransform, ContextTransformError, InvalidCompactionArtifact, ModelContextMessage, PreparedModelContext, RetainedFact, applyCompaction, digestCompactionSource, prepareModelContext };
|
|
5
|
+
}
|
|
6
|
+
declare const ModelContextMessage_base: Schema.Class<ModelContextMessage, Schema.Struct<{
|
|
7
|
+
readonly role: Schema.Literals<readonly ["system", "user", "assistant", "tool"]>;
|
|
8
|
+
readonly content: Schema.String;
|
|
9
|
+
readonly sourceSequences: Schema.$Array<Schema.Natural>;
|
|
10
|
+
}>, {}>;
|
|
11
|
+
/** A model-context message derived from, but never replacing, source history. */
|
|
12
|
+
declare class ModelContextMessage extends ModelContextMessage_base {}
|
|
13
|
+
declare const RetainedFact_base: Schema.Class<RetainedFact, Schema.Struct<{
|
|
14
|
+
readonly fact: Schema.String;
|
|
15
|
+
readonly sourceSequences: Schema.$Array<Schema.Natural>;
|
|
16
|
+
}>, {}>;
|
|
17
|
+
/** A fact retained explicitly by compaction, independent of the generated prose summary. */
|
|
18
|
+
declare class RetainedFact extends RetainedFact_base {}
|
|
19
|
+
declare const CompactionArtifact_base: Schema.Class<CompactionArtifact, Schema.Struct<{
|
|
20
|
+
readonly version: Schema.Literal<1>;
|
|
21
|
+
readonly threadId: Schema.brand<Schema.NonEmptyString, "@effect-agent/core/ThreadId">;
|
|
22
|
+
readonly coversFrom: Schema.Natural;
|
|
23
|
+
readonly coversThrough: Schema.Natural;
|
|
24
|
+
readonly summary: typeof ModelContextMessage;
|
|
25
|
+
readonly retainedFacts: Schema.refine<readonly RetainedFact[], Schema.$Array<typeof RetainedFact>>;
|
|
26
|
+
readonly tokenEstimate: Schema.Natural;
|
|
27
|
+
readonly sourceDigest: Schema.String;
|
|
28
|
+
readonly compactorVersion: Schema.NonEmptyString;
|
|
29
|
+
}>, {}>;
|
|
30
|
+
/** Versioned, replayable artifact that covers a prefix or middle range without deleting source. */
|
|
31
|
+
declare class CompactionArtifact extends CompactionArtifact_base {}
|
|
32
|
+
declare const PreparedModelContext_base: Schema.Class<PreparedModelContext, Schema.Struct<{
|
|
33
|
+
readonly source: typeof Thread;
|
|
34
|
+
readonly messages: Schema.refine<readonly ModelContextMessage[], Schema.$Array<typeof ModelContextMessage>>;
|
|
35
|
+
readonly compactions: Schema.$Array<typeof CompactionArtifact>;
|
|
36
|
+
}>, {}>;
|
|
37
|
+
/** Context exposed to a model, with source history kept intact for audit and reconstruction. */
|
|
38
|
+
declare class PreparedModelContext extends PreparedModelContext_base {}
|
|
39
|
+
declare const ContextTransformError_base: Schema.Class<ContextTransformError, Schema.TaggedStruct<"ContextTransformError", {
|
|
40
|
+
readonly transformId: Schema.NonEmptyString;
|
|
41
|
+
readonly message: Schema.String;
|
|
42
|
+
}>, import("effect/Cause").YieldableError>;
|
|
43
|
+
/** Transform failure is named and bounded so model context preparation has a closed error channel. */
|
|
44
|
+
declare class ContextTransformError extends ContextTransformError_base {}
|
|
45
|
+
declare const CompactionDigestError_base: Schema.Class<CompactionDigestError, Schema.TaggedStruct<"CompactionDigestError", {
|
|
46
|
+
readonly message: Schema.String;
|
|
47
|
+
}>, import("effect/Cause").YieldableError>;
|
|
48
|
+
/** Source encoding or hashing failed before an artifact could be trusted. */
|
|
49
|
+
declare class CompactionDigestError extends CompactionDigestError_base {}
|
|
50
|
+
declare const InvalidCompactionArtifact_base: Schema.Class<InvalidCompactionArtifact, Schema.TaggedStruct<"InvalidCompactionArtifact", {
|
|
51
|
+
readonly message: Schema.String;
|
|
52
|
+
}>, import("effect/Cause").YieldableError>;
|
|
53
|
+
/** Compaction artifacts that do not bind to the exact source range are rejected before use. */
|
|
54
|
+
declare class InvalidCompactionArtifact extends InvalidCompactionArtifact_base {}
|
|
55
|
+
declare const ContextLimitExceeded_base: Schema.Class<ContextLimitExceeded, Schema.TaggedStruct<"ContextLimitExceeded", {
|
|
56
|
+
readonly limit: Schema.Literals<readonly ["messages", "message-bytes", "compactions"]>;
|
|
57
|
+
readonly limitValue: Schema.Natural;
|
|
58
|
+
readonly observedValue: Schema.Natural;
|
|
59
|
+
}>, import("effect/Cause").YieldableError>;
|
|
60
|
+
/** A transform or compaction exceeded the finite model-view collection bounds. */
|
|
61
|
+
declare class ContextLimitExceeded extends ContextLimitExceeded_base {}
|
|
62
|
+
/**
|
|
63
|
+
* Ordered context transform. It receives and returns only the model-visible
|
|
64
|
+
* message view, making replacement of the authoritative source impossible.
|
|
65
|
+
* Required services remain visible in prepareModelContext; expected failures
|
|
66
|
+
* are translated by the transform into ContextTransformError.
|
|
67
|
+
*/
|
|
68
|
+
interface ContextTransform<Requirements = never> {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly version: string;
|
|
71
|
+
readonly apply: (messages: ReadonlyArray<ModelContextMessage>) => Effect.Effect<ReadonlyArray<ModelContextMessage>, ContextTransformError, Requirements>;
|
|
72
|
+
}
|
|
73
|
+
/** Apply transforms in declaration order, always restoring the original source snapshot. */
|
|
74
|
+
declare const prepareModelContext: <const Requirements extends ReadonlyArray<unknown> = readonly []>(snapshot: Thread, transforms?: { readonly [Index in keyof Requirements]: ContextTransform<Requirements[Index]>; }) => Effect.Effect<PreparedModelContext, ContextTransformError, Requirements[number]>;
|
|
75
|
+
/** Compute a cryptographic digest over the canonical encoded exact source range. */
|
|
76
|
+
declare const digestCompactionSource: (snapshot: Thread, coversFrom: number, coversThrough: number) => Effect.Effect<string, CompactionDigestError | InvalidCompactionArtifact, Crypto.Crypto>;
|
|
77
|
+
/**
|
|
78
|
+
* Replace only the model-view messages fully covered by the artifact range
|
|
79
|
+
* with its summary. The digest is recomputed against the exact source slice
|
|
80
|
+
* before the artifact can influence context. Messages that are not fully
|
|
81
|
+
* covered — including transform-synthesized messages without provenance and
|
|
82
|
+
* messages whose provenance only partially overlaps the range — remain
|
|
83
|
+
* visible, and the summary is inserted before the first message derived
|
|
84
|
+
* entirely from later source.
|
|
85
|
+
*/
|
|
86
|
+
declare const applyCompaction: (context: PreparedModelContext, artifact: CompactionArtifact) => Effect.Effect<PreparedModelContext, CompactionDigestError | ContextLimitExceeded | ContextTransformError | InvalidCompactionArtifact, Crypto.Crypto>;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { CompactionArtifact, CompactionDigestError, ContextLimitExceeded, ContextTransform, ContextTransformError, InvalidCompactionArtifact, ModelContextMessage, PreparedModelContext, RetainedFact, applyCompaction, digestCompactionSource, prepareModelContext, ModelContext_d_exports as t };
|
|
89
|
+
//# sourceMappingURL=ModelContext.d.mts.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { n as utf8ByteLength } from "../utf8-DchGZRBd.mjs";
|
|
3
|
+
import { ThreadId } from "../core/Identifiers.mjs";
|
|
4
|
+
import { Thread, ThreadMessage, ThreadText } from "../core/Thread.mjs";
|
|
5
|
+
import { Crypto, Effect, Encoding, Schema } from "effect";
|
|
6
|
+
//#region src/capabilities/ModelContext.ts
|
|
7
|
+
var ModelContext_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
CompactionArtifact: () => CompactionArtifact,
|
|
9
|
+
CompactionDigestError: () => CompactionDigestError,
|
|
10
|
+
ContextLimitExceeded: () => ContextLimitExceeded,
|
|
11
|
+
ContextTransformError: () => ContextTransformError,
|
|
12
|
+
InvalidCompactionArtifact: () => InvalidCompactionArtifact,
|
|
13
|
+
ModelContextMessage: () => ModelContextMessage,
|
|
14
|
+
PreparedModelContext: () => PreparedModelContext,
|
|
15
|
+
RetainedFact: () => RetainedFact,
|
|
16
|
+
applyCompaction: () => applyCompaction,
|
|
17
|
+
digestCompactionSource: () => digestCompactionSource,
|
|
18
|
+
prepareModelContext: () => prepareModelContext
|
|
19
|
+
});
|
|
20
|
+
const MAX_CONTEXT_MESSAGES = 1024;
|
|
21
|
+
const MAX_CONTEXT_MESSAGE_BYTES = 4194304;
|
|
22
|
+
const MAX_SOURCE_SEQUENCES = 1024;
|
|
23
|
+
const MAX_RETAINED_FACTS = 256;
|
|
24
|
+
const MAX_RETAINED_FACT_BYTES = 1048576;
|
|
25
|
+
const MAX_COMPACTIONS = 16;
|
|
26
|
+
const SourceSequences = Schema.Array(Schema.Natural).check(Schema.isMaxLength(MAX_SOURCE_SEQUENCES));
|
|
27
|
+
/** A model-context message derived from, but never replacing, source history. */
|
|
28
|
+
var ModelContextMessage = class extends Schema.Class("@effect-agent/capabilities/ModelContextMessage")({
|
|
29
|
+
role: Schema.Literals([
|
|
30
|
+
"system",
|
|
31
|
+
"user",
|
|
32
|
+
"assistant",
|
|
33
|
+
"tool"
|
|
34
|
+
]),
|
|
35
|
+
content: ThreadText,
|
|
36
|
+
sourceSequences: SourceSequences
|
|
37
|
+
}) {};
|
|
38
|
+
/** A fact retained explicitly by compaction, independent of the generated prose summary. */
|
|
39
|
+
var RetainedFact = class extends Schema.Class("@effect-agent/capabilities/RetainedFact")({
|
|
40
|
+
fact: Schema.String.check(Schema.isMaxLength(4096)),
|
|
41
|
+
sourceSequences: SourceSequences
|
|
42
|
+
}) {};
|
|
43
|
+
const ModelContextMessages = Schema.Array(ModelContextMessage).check(Schema.isMaxLength(MAX_CONTEXT_MESSAGES)).pipe(Schema.refine((messages) => messages.reduce((total, message) => total + utf8ByteLength(message.content), 0) <= MAX_CONTEXT_MESSAGE_BYTES, { expected: `model context totaling at most ${MAX_CONTEXT_MESSAGE_BYTES} UTF-8 bytes` }));
|
|
44
|
+
const RetainedFacts = Schema.Array(RetainedFact).check(Schema.isMaxLength(MAX_RETAINED_FACTS)).pipe(Schema.refine((facts) => facts.reduce((total, retained) => total + utf8ByteLength(retained.fact), 0) <= MAX_RETAINED_FACT_BYTES, { expected: `retained facts totaling at most ${MAX_RETAINED_FACT_BYTES} UTF-8 bytes` }));
|
|
45
|
+
const SourceDigest = Schema.String.check(Schema.isPattern(/^sha256:[a-f0-9]{64}$/));
|
|
46
|
+
/** Versioned, replayable artifact that covers a prefix or middle range without deleting source. */
|
|
47
|
+
var CompactionArtifact = class extends Schema.Class("@effect-agent/capabilities/CompactionArtifact")({
|
|
48
|
+
version: Schema.Literal(1),
|
|
49
|
+
threadId: ThreadId,
|
|
50
|
+
coversFrom: Schema.Natural,
|
|
51
|
+
coversThrough: Schema.Natural,
|
|
52
|
+
summary: ModelContextMessage,
|
|
53
|
+
retainedFacts: RetainedFacts,
|
|
54
|
+
tokenEstimate: Schema.Natural,
|
|
55
|
+
sourceDigest: SourceDigest,
|
|
56
|
+
compactorVersion: Schema.NonEmptyString
|
|
57
|
+
}) {};
|
|
58
|
+
/** Context exposed to a model, with source history kept intact for audit and reconstruction. */
|
|
59
|
+
var PreparedModelContext = class extends Schema.Class("@effect-agent/capabilities/PreparedModelContext")({
|
|
60
|
+
source: Thread,
|
|
61
|
+
messages: ModelContextMessages,
|
|
62
|
+
compactions: Schema.Array(CompactionArtifact).check(Schema.isMaxLength(MAX_COMPACTIONS))
|
|
63
|
+
}) {};
|
|
64
|
+
/** Transform failure is named and bounded so model context preparation has a closed error channel. */
|
|
65
|
+
var ContextTransformError = class extends Schema.TaggedError()("ContextTransformError", {
|
|
66
|
+
transformId: Schema.NonEmptyString,
|
|
67
|
+
message: Schema.String
|
|
68
|
+
}) {};
|
|
69
|
+
/** Source encoding or hashing failed before an artifact could be trusted. */
|
|
70
|
+
var CompactionDigestError = class extends Schema.TaggedError()("CompactionDigestError", { message: Schema.String }) {};
|
|
71
|
+
/** Compaction artifacts that do not bind to the exact source range are rejected before use. */
|
|
72
|
+
var InvalidCompactionArtifact = class extends Schema.TaggedError()("InvalidCompactionArtifact", { message: Schema.String }) {};
|
|
73
|
+
/** A transform or compaction exceeded the finite model-view collection bounds. */
|
|
74
|
+
var ContextLimitExceeded = class extends Schema.TaggedError()("ContextLimitExceeded", {
|
|
75
|
+
limit: Schema.Literals([
|
|
76
|
+
"messages",
|
|
77
|
+
"message-bytes",
|
|
78
|
+
"compactions"
|
|
79
|
+
]),
|
|
80
|
+
limitValue: Schema.Natural,
|
|
81
|
+
observedValue: Schema.Natural
|
|
82
|
+
}) {};
|
|
83
|
+
const messageText = (message) => {
|
|
84
|
+
if (message.role === "system") return message.content;
|
|
85
|
+
return message.content.map((part) => {
|
|
86
|
+
if (part.type === "text" || part.type === "reasoning") return part.text;
|
|
87
|
+
return `[${part.type}]`;
|
|
88
|
+
}).join("\n").slice(0, 65536);
|
|
89
|
+
};
|
|
90
|
+
const asModelMessages = (snapshot) => snapshot.messages.map((entry) => ModelContextMessage.make({
|
|
91
|
+
role: entry.message.role,
|
|
92
|
+
content: messageText(entry.message),
|
|
93
|
+
sourceSequences: [entry.sequence]
|
|
94
|
+
}));
|
|
95
|
+
const validateModelView = (messages, transformId) => {
|
|
96
|
+
if (messages.length > MAX_CONTEXT_MESSAGES) return Effect.fail(ContextTransformError.make({
|
|
97
|
+
transformId,
|
|
98
|
+
message: `Transform produced ${messages.length} messages; maximum is ${MAX_CONTEXT_MESSAGES}`
|
|
99
|
+
}));
|
|
100
|
+
const bytes = messages.reduce((total, message) => total + utf8ByteLength(message.content), 0);
|
|
101
|
+
return bytes > MAX_CONTEXT_MESSAGE_BYTES ? Effect.fail(ContextTransformError.make({
|
|
102
|
+
transformId,
|
|
103
|
+
message: `Transform produced ${bytes} UTF-8 bytes; maximum is ${MAX_CONTEXT_MESSAGE_BYTES}`
|
|
104
|
+
})) : Effect.succeed(messages);
|
|
105
|
+
};
|
|
106
|
+
/** Apply transforms in declaration order, always restoring the original source snapshot. */
|
|
107
|
+
const prepareModelContext = (snapshot, transforms) => (transforms ?? []).reduce((messages, transform) => messages.pipe(Effect.flatMap(transform.apply), Effect.flatMap((transformed) => validateModelView(transformed, transform.id))), Effect.succeed(asModelMessages(snapshot))).pipe(Effect.map((messages) => PreparedModelContext.make({
|
|
108
|
+
source: snapshot,
|
|
109
|
+
messages,
|
|
110
|
+
compactions: []
|
|
111
|
+
})));
|
|
112
|
+
const exactSourceRange = (snapshot, coversFrom, coversThrough) => {
|
|
113
|
+
if (coversFrom > coversThrough || coversThrough >= snapshot.nextSequence) return Effect.fail(InvalidCompactionArtifact.make({ message: "Compaction artifact covers an invalid source range" }));
|
|
114
|
+
const selected = snapshot.messages.filter((message) => message.sequence >= coversFrom && message.sequence <= coversThrough);
|
|
115
|
+
const expectedCount = coversThrough - coversFrom + 1;
|
|
116
|
+
if (selected.length !== expectedCount || selected[0]?.sequence !== coversFrom || selected[selected.length - 1]?.sequence !== coversThrough) return Effect.fail(InvalidCompactionArtifact.make({ message: "Compaction source range is not contiguous in authoritative history" }));
|
|
117
|
+
return Effect.succeed(selected);
|
|
118
|
+
};
|
|
119
|
+
const utf8Bytes = (value) => {
|
|
120
|
+
const hex = Encoding.encodeHex(value);
|
|
121
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
122
|
+
for (let index = 0; index < bytes.length; index += 1) bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
123
|
+
return bytes;
|
|
124
|
+
};
|
|
125
|
+
/** Compute a cryptographic digest over the canonical encoded exact source range. */
|
|
126
|
+
const digestCompactionSource = Effect.fn("digestCompactionSource")(function* (snapshot, coversFrom, coversThrough) {
|
|
127
|
+
const selected = yield* exactSourceRange(snapshot, coversFrom, coversThrough);
|
|
128
|
+
const encoded = yield* Schema.encodeEffect(Schema.Array(ThreadMessage))(selected).pipe(Effect.mapError((error) => CompactionDigestError.make({ message: `Could not encode compaction source: ${error.message}` })));
|
|
129
|
+
const digest = yield* (yield* Crypto.Crypto).digest("SHA-256", utf8Bytes(JSON.stringify(encoded))).pipe(Effect.mapError((error) => CompactionDigestError.make({ message: `Could not digest compaction source: ${error.message}` })));
|
|
130
|
+
return `sha256:${Encoding.encodeHex(digest)}`;
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Replace only the model-view messages fully covered by the artifact range
|
|
134
|
+
* with its summary. The digest is recomputed against the exact source slice
|
|
135
|
+
* before the artifact can influence context. Messages that are not fully
|
|
136
|
+
* covered — including transform-synthesized messages without provenance and
|
|
137
|
+
* messages whose provenance only partially overlaps the range — remain
|
|
138
|
+
* visible, and the summary is inserted before the first message derived
|
|
139
|
+
* entirely from later source.
|
|
140
|
+
*/
|
|
141
|
+
const applyCompaction = Effect.fn("applyCompaction")(function* (context, artifact) {
|
|
142
|
+
if (artifact.threadId !== context.source.threadId) return yield* InvalidCompactionArtifact.make({ message: "Compaction artifact belongs to another Thread" });
|
|
143
|
+
if ((yield* digestCompactionSource(context.source, artifact.coversFrom, artifact.coversThrough)) !== artifact.sourceDigest) return yield* InvalidCompactionArtifact.make({ message: "Compaction source digest does not match authoritative history" });
|
|
144
|
+
const provenanceInRange = (sequences) => sequences.length > 0 && sequences.every((sequence) => sequence >= artifact.coversFrom && sequence <= artifact.coversThrough);
|
|
145
|
+
if (!provenanceInRange(artifact.summary.sourceSequences) || artifact.retainedFacts.some((fact) => !provenanceInRange(fact.sourceSequences))) return yield* InvalidCompactionArtifact.make({ message: "Compaction summary or retained-fact provenance falls outside its covered range" });
|
|
146
|
+
if (context.compactions.length >= MAX_COMPACTIONS) return yield* ContextLimitExceeded.make({
|
|
147
|
+
limit: "compactions",
|
|
148
|
+
limitValue: MAX_COMPACTIONS,
|
|
149
|
+
observedValue: context.compactions.length + 1
|
|
150
|
+
});
|
|
151
|
+
const fullyCovered = (message) => message.sourceSequences.length > 0 && message.sourceSequences.every((sequence) => sequence >= artifact.coversFrom && sequence <= artifact.coversThrough);
|
|
152
|
+
const kept = context.messages.filter((message) => !fullyCovered(message));
|
|
153
|
+
const summaryAt = kept.findIndex((message) => message.sourceSequences.length > 0 && message.sourceSequences.every((sequence) => sequence > artifact.coversThrough));
|
|
154
|
+
const messages = yield* validateModelView(summaryAt === -1 ? [...kept, artifact.summary] : [
|
|
155
|
+
...kept.slice(0, summaryAt),
|
|
156
|
+
artifact.summary,
|
|
157
|
+
...kept.slice(summaryAt)
|
|
158
|
+
], `compaction:${artifact.compactorVersion}`);
|
|
159
|
+
return PreparedModelContext.make({
|
|
160
|
+
source: context.source,
|
|
161
|
+
messages,
|
|
162
|
+
compactions: [...context.compactions, artifact]
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
//#endregion
|
|
166
|
+
export { CompactionArtifact, CompactionDigestError, ContextLimitExceeded, ContextTransformError, InvalidCompactionArtifact, ModelContextMessage, PreparedModelContext, RetainedFact, applyCompaction, digestCompactionSource, prepareModelContext, ModelContext_exports as t };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=ModelContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelContext.mjs","names":["ThreadSnapshot"],"sources":["../../src/capabilities/ModelContext.ts"],"sourcesContent":["import { Crypto, Effect, Encoding, Schema } from \"effect\";\nimport type { Prompt } from \"effect/unstable/ai\";\n\nimport { ThreadId } from \"../core/Identifiers.ts\";\nimport { utf8ByteLength } from \"../core/internal/utf8.ts\";\nimport { ThreadMessage, Thread as ThreadSnapshot, ThreadText } from \"../core/Thread.ts\";\n\nconst MAX_CONTEXT_MESSAGES = 1_024;\nconst MAX_CONTEXT_MESSAGE_BYTES = 4 * 1024 * 1024;\nconst MAX_SOURCE_SEQUENCES = 1_024;\nconst MAX_RETAINED_FACTS = 256;\nconst MAX_RETAINED_FACT_BYTES = 1024 * 1024;\nconst MAX_COMPACTIONS = 16;\n\nconst SourceSequences = Schema.Array(Schema.Natural).check(\n Schema.isMaxLength(MAX_SOURCE_SEQUENCES),\n);\n\n/** A model-context message derived from, but never replacing, source history. */\nexport class ModelContextMessage extends Schema.Class<ModelContextMessage>(\n \"@effect-agent/capabilities/ModelContextMessage\",\n)({\n role: Schema.Literals([\"system\", \"user\", \"assistant\", \"tool\"]),\n content: ThreadText,\n sourceSequences: SourceSequences,\n}) {}\n\n/** A fact retained explicitly by compaction, independent of the generated prose summary. */\nexport class RetainedFact extends Schema.Class<RetainedFact>(\n \"@effect-agent/capabilities/RetainedFact\",\n)({\n fact: Schema.String.check(Schema.isMaxLength(4 * 1024)),\n sourceSequences: SourceSequences,\n}) {}\n\nconst ModelContextMessages = Schema.Array(ModelContextMessage)\n .check(Schema.isMaxLength(MAX_CONTEXT_MESSAGES))\n .pipe(\n Schema.refine(\n (messages): messages is ReadonlyArray<ModelContextMessage> =>\n messages.reduce((total, message) => total + utf8ByteLength(message.content), 0) <=\n MAX_CONTEXT_MESSAGE_BYTES,\n { expected: `model context totaling at most ${MAX_CONTEXT_MESSAGE_BYTES} UTF-8 bytes` },\n ),\n );\n\nconst RetainedFacts = Schema.Array(RetainedFact)\n .check(Schema.isMaxLength(MAX_RETAINED_FACTS))\n .pipe(\n Schema.refine(\n (facts): facts is ReadonlyArray<RetainedFact> =>\n facts.reduce((total, retained) => total + utf8ByteLength(retained.fact), 0) <=\n MAX_RETAINED_FACT_BYTES,\n { expected: `retained facts totaling at most ${MAX_RETAINED_FACT_BYTES} UTF-8 bytes` },\n ),\n );\n\nconst SourceDigest = Schema.String.check(Schema.isPattern(/^sha256:[a-f0-9]{64}$/));\n\n/** Versioned, replayable artifact that covers a prefix or middle range without deleting source. */\nexport class CompactionArtifact extends Schema.Class<CompactionArtifact>(\n \"@effect-agent/capabilities/CompactionArtifact\",\n)({\n version: Schema.Literal(1),\n threadId: ThreadId,\n coversFrom: Schema.Natural,\n coversThrough: Schema.Natural,\n summary: ModelContextMessage,\n retainedFacts: RetainedFacts,\n tokenEstimate: Schema.Natural,\n sourceDigest: SourceDigest,\n compactorVersion: Schema.NonEmptyString,\n}) {}\n\n/** Context exposed to a model, with source history kept intact for audit and reconstruction. */\nexport class PreparedModelContext extends Schema.Class<PreparedModelContext>(\n \"@effect-agent/capabilities/PreparedModelContext\",\n)({\n source: ThreadSnapshot,\n messages: ModelContextMessages,\n compactions: Schema.Array(CompactionArtifact).check(Schema.isMaxLength(MAX_COMPACTIONS)),\n}) {}\n\n/** Transform failure is named and bounded so model context preparation has a closed error channel. */\nexport class ContextTransformError extends Schema.TaggedError<ContextTransformError>()(\n \"ContextTransformError\",\n { transformId: Schema.NonEmptyString, message: Schema.String },\n) {}\n\n/** Source encoding or hashing failed before an artifact could be trusted. */\nexport class CompactionDigestError extends Schema.TaggedError<CompactionDigestError>()(\n \"CompactionDigestError\",\n { message: Schema.String },\n) {}\n\n/** Compaction artifacts that do not bind to the exact source range are rejected before use. */\nexport class InvalidCompactionArtifact extends Schema.TaggedError<InvalidCompactionArtifact>()(\n \"InvalidCompactionArtifact\",\n { message: Schema.String },\n) {}\n\n/** A transform or compaction exceeded the finite model-view collection bounds. */\nexport class ContextLimitExceeded extends Schema.TaggedError<ContextLimitExceeded>()(\n \"ContextLimitExceeded\",\n {\n limit: Schema.Literals([\"messages\", \"message-bytes\", \"compactions\"]),\n limitValue: Schema.Natural,\n observedValue: Schema.Natural,\n },\n) {}\n\n/**\n * Ordered context transform. It receives and returns only the model-visible\n * message view, making replacement of the authoritative source impossible.\n * Required services remain visible in prepareModelContext; expected failures\n * are translated by the transform into ContextTransformError.\n */\nexport interface ContextTransform<Requirements = never> {\n readonly id: string;\n readonly version: string;\n readonly apply: (\n messages: ReadonlyArray<ModelContextMessage>,\n ) => Effect.Effect<ReadonlyArray<ModelContextMessage>, ContextTransformError, Requirements>;\n}\n\nconst messageText = (message: Prompt.Message): string => {\n if (message.role === \"system\") return message.content;\n\n const content = message.content\n .map((part) => {\n if (part.type === \"text\" || part.type === \"reasoning\") return part.text;\n\n return `[${part.type}]`;\n })\n .join(\"\\n\");\n\n return content.slice(0, 64 * 1024);\n};\n\nconst asModelMessages = (snapshot: ThreadSnapshot): ReadonlyArray<ModelContextMessage> =>\n snapshot.messages.map((entry) =>\n ModelContextMessage.make({\n role: entry.message.role,\n content: messageText(entry.message),\n sourceSequences: [entry.sequence],\n }),\n );\n\nconst validateModelView = (\n messages: ReadonlyArray<ModelContextMessage>,\n transformId: string,\n): Effect.Effect<ReadonlyArray<ModelContextMessage>, ContextTransformError> => {\n if (messages.length > MAX_CONTEXT_MESSAGES) {\n return Effect.fail(\n ContextTransformError.make({\n transformId,\n message: `Transform produced ${messages.length} messages; maximum is ${MAX_CONTEXT_MESSAGES}`,\n }),\n );\n }\n const bytes = messages.reduce((total, message) => total + utf8ByteLength(message.content), 0);\n\n return bytes > MAX_CONTEXT_MESSAGE_BYTES\n ? Effect.fail(\n ContextTransformError.make({\n transformId,\n message: `Transform produced ${bytes} UTF-8 bytes; maximum is ${MAX_CONTEXT_MESSAGE_BYTES}`,\n }),\n )\n : Effect.succeed(messages);\n};\n\n/** Apply transforms in declaration order, always restoring the original source snapshot. */\nexport const prepareModelContext = <\n const Requirements extends ReadonlyArray<unknown> = readonly [],\n>(\n snapshot: ThreadSnapshot,\n transforms?: { readonly [Index in keyof Requirements]: ContextTransform<Requirements[Index]> },\n): Effect.Effect<PreparedModelContext, ContextTransformError, Requirements[number]> =>\n (transforms ?? [])\n .reduce<\n Effect.Effect<ReadonlyArray<ModelContextMessage>, ContextTransformError, Requirements[number]>\n >(\n (messages, transform) =>\n messages.pipe(\n Effect.flatMap(transform.apply),\n Effect.flatMap((transformed) => validateModelView(transformed, transform.id)),\n ),\n Effect.succeed(asModelMessages(snapshot)),\n )\n .pipe(\n Effect.map((messages) =>\n PreparedModelContext.make({\n source: snapshot,\n messages,\n compactions: [],\n }),\n ),\n );\n\nconst exactSourceRange = (\n snapshot: ThreadSnapshot,\n coversFrom: number,\n coversThrough: number,\n): Effect.Effect<ReadonlyArray<ThreadMessage>, InvalidCompactionArtifact> => {\n if (coversFrom > coversThrough || coversThrough >= snapshot.nextSequence) {\n return Effect.fail(\n InvalidCompactionArtifact.make({\n message: \"Compaction artifact covers an invalid source range\",\n }),\n );\n }\n\n const selected = snapshot.messages.filter(\n (message) => message.sequence >= coversFrom && message.sequence <= coversThrough,\n );\n\n const expectedCount = coversThrough - coversFrom + 1;\n\n if (\n selected.length !== expectedCount ||\n selected[0]?.sequence !== coversFrom ||\n selected[selected.length - 1]?.sequence !== coversThrough\n ) {\n return Effect.fail(\n InvalidCompactionArtifact.make({\n message: \"Compaction source range is not contiguous in authoritative history\",\n }),\n );\n }\n\n return Effect.succeed(selected);\n};\n\nconst utf8Bytes = (value: string): Uint8Array => {\n const hex = Encoding.encodeHex(value);\n const bytes = new Uint8Array(hex.length / 2);\n\n for (let index = 0; index < bytes.length; index += 1) {\n bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);\n }\n\n return bytes;\n};\n\n/** Compute a cryptographic digest over the canonical encoded exact source range. */\nexport const digestCompactionSource = Effect.fn(\"digestCompactionSource\")(function* (\n snapshot: ThreadSnapshot,\n coversFrom: number,\n coversThrough: number,\n) {\n const selected = yield* exactSourceRange(snapshot, coversFrom, coversThrough);\n\n const encoded = yield* Schema.encodeEffect(Schema.Array(ThreadMessage))(selected).pipe(\n Effect.mapError((error) =>\n CompactionDigestError.make({\n message: `Could not encode compaction source: ${error.message}`,\n }),\n ),\n );\n\n const crypto = yield* Crypto.Crypto;\n\n const digest = yield* crypto.digest(\"SHA-256\", utf8Bytes(JSON.stringify(encoded))).pipe(\n Effect.mapError((error) =>\n CompactionDigestError.make({\n message: `Could not digest compaction source: ${error.message}`,\n }),\n ),\n );\n\n return `sha256:${Encoding.encodeHex(digest)}`;\n});\n\n/**\n * Replace only the model-view messages fully covered by the artifact range\n * with its summary. The digest is recomputed against the exact source slice\n * before the artifact can influence context. Messages that are not fully\n * covered — including transform-synthesized messages without provenance and\n * messages whose provenance only partially overlaps the range — remain\n * visible, and the summary is inserted before the first message derived\n * entirely from later source.\n */\nexport const applyCompaction = Effect.fn(\"applyCompaction\")(function* (\n context: PreparedModelContext,\n artifact: CompactionArtifact,\n) {\n if (artifact.threadId !== context.source.threadId) {\n return yield* InvalidCompactionArtifact.make({\n message: \"Compaction artifact belongs to another Thread\",\n });\n }\n\n const actualDigest = yield* digestCompactionSource(\n context.source,\n artifact.coversFrom,\n artifact.coversThrough,\n );\n\n if (actualDigest !== artifact.sourceDigest) {\n return yield* InvalidCompactionArtifact.make({\n message: \"Compaction source digest does not match authoritative history\",\n });\n }\n\n const provenanceInRange = (sequences: ReadonlyArray<number>): boolean =>\n sequences.length > 0 &&\n sequences.every(\n (sequence) => sequence >= artifact.coversFrom && sequence <= artifact.coversThrough,\n );\n\n if (\n !provenanceInRange(artifact.summary.sourceSequences) ||\n artifact.retainedFacts.some((fact) => !provenanceInRange(fact.sourceSequences))\n ) {\n return yield* InvalidCompactionArtifact.make({\n message: \"Compaction summary or retained-fact provenance falls outside its covered range\",\n });\n }\n if (context.compactions.length >= MAX_COMPACTIONS) {\n return yield* ContextLimitExceeded.make({\n limit: \"compactions\",\n limitValue: MAX_COMPACTIONS,\n observedValue: context.compactions.length + 1,\n });\n }\n\n const fullyCovered = (message: ModelContextMessage): boolean =>\n message.sourceSequences.length > 0 &&\n message.sourceSequences.every(\n (sequence) => sequence >= artifact.coversFrom && sequence <= artifact.coversThrough,\n );\n\n const kept = context.messages.filter((message) => !fullyCovered(message));\n\n const summaryAt = kept.findIndex(\n (message) =>\n message.sourceSequences.length > 0 &&\n message.sourceSequences.every((sequence) => sequence > artifact.coversThrough),\n );\n\n const messages = yield* validateModelView(\n summaryAt === -1\n ? [...kept, artifact.summary]\n : [...kept.slice(0, summaryAt), artifact.summary, ...kept.slice(summaryAt)],\n `compaction:${artifact.compactorVersion}`,\n );\n\n return PreparedModelContext.make({\n source: context.source,\n messages,\n compactions: [...context.compactions, artifact],\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAOA,MAAM,uBAAuB;AAC7B,MAAM,4BAA4B;AAClC,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB;AAC3B,MAAM,0BAA0B;AAChC,MAAM,kBAAkB;AAExB,MAAM,kBAAkB,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,MACnD,OAAO,YAAY,oBAAoB,CACzC;;AAGA,IAAa,sBAAb,cAAyC,OAAO,MAC9C,gDACF,CAAC,CAAC;CACA,MAAM,OAAO,SAAS;EAAC;EAAU;EAAQ;EAAa;CAAM,CAAC;CAC7D,SAAS;CACT,iBAAiB;AACnB,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,eAAb,cAAkC,OAAO,MACvC,yCACF,CAAC,CAAC;CACA,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,IAAQ,CAAC;CACtD,iBAAiB;AACnB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,uBAAuB,OAAO,MAAM,mBAAmB,CAAC,CAC3D,MAAM,OAAO,YAAY,oBAAoB,CAAC,CAAC,CAC/C,KACC,OAAO,QACJ,aACC,SAAS,QAAQ,OAAO,YAAY,QAAQ,eAAe,QAAQ,OAAO,GAAG,CAAC,KAC9E,2BACF,EAAE,UAAU,kCAAkC,0BAA0B,cAAc,CACxF,CACF;AAEF,MAAM,gBAAgB,OAAO,MAAM,YAAY,CAAC,CAC7C,MAAM,OAAO,YAAY,kBAAkB,CAAC,CAAC,CAC7C,K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 +1,37 @@
|
|
|
1
|
+
import { l as RunEvent } from "../RunEvent-DIrzkjLr.mjs";
|
|
2
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
3
|
+
declare namespace Redaction_d_exports {
|
|
4
|
+
export { RedactedPreview, RedactionError, Redactor, StructuralRedactorLive, redactedTranscript };
|
|
5
|
+
}
|
|
6
|
+
/** Branded evidence that a preview passed through the configured structural Redactor. */
|
|
7
|
+
declare const RedactedPreview: Schema.brand<Schema.refine<string, Schema.String>, "@effect-agent/capabilities/RedactedPreview">;
|
|
8
|
+
type RedactedPreview = typeof RedactedPreview.Type;
|
|
9
|
+
declare const RedactionError_base: Schema.Class<RedactionError, Schema.TaggedStruct<"RedactionError", {
|
|
10
|
+
readonly reason: Schema.Literals<readonly ["input-too-deep", "input-too-large", "encoding-failed"]>;
|
|
11
|
+
readonly message: Schema.String;
|
|
12
|
+
}>, import("effect/Cause").YieldableError>;
|
|
13
|
+
/** Structural redaction failed closed rather than returning unreviewed caller text. */
|
|
14
|
+
declare class RedactionError extends RedactionError_base {}
|
|
15
|
+
declare const Redactor_base: Context.ServiceClass<Redactor, "@effect-agent/capabilities/Redactor", {
|
|
16
|
+
readonly redact: (decodedValue: unknown) => Effect.Effect<RedactedPreview, RedactionError>;
|
|
17
|
+
}>;
|
|
18
|
+
/** Redaction owns the boundary from decoded Tool values to bounded audit/model previews. */
|
|
19
|
+
declare class Redactor extends Redactor_base {}
|
|
20
|
+
/**
|
|
21
|
+
* One composed step from live Run Events to structurally redacted transcript lines
|
|
22
|
+
* (P7 WP7 friction fix; SEC-008/testing.md §12 "structurally redacted" live transcripts):
|
|
23
|
+
* Schema-encode each event through the canonical `RunEvent` union, then pass the encoded
|
|
24
|
+
* value through the configured `Redactor` — so the safe path is the short path and no live
|
|
25
|
+
* suite hand-assembles (or accidentally skips) the encode→redact pair. Engine-constructed
|
|
26
|
+
* events always encode, so an encode failure is a defect, never a silent omission.
|
|
27
|
+
*/
|
|
28
|
+
declare const redactedTranscript: (events: Iterable<RunEvent>) => Effect.Effect<ReadonlyArray<RedactedPreview>, RedactionError, Redactor>;
|
|
29
|
+
/**
|
|
30
|
+
* Default structural implementation. It exposes only collection shape and
|
|
31
|
+
* scalar types, so an ordinary field such as `note` cannot bypass redaction.
|
|
32
|
+
* Tool-specific Layers may expose explicitly reviewed fields instead.
|
|
33
|
+
*/
|
|
34
|
+
declare const StructuralRedactorLive: Layer.Layer<Redactor, never, never>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { RedactedPreview, RedactionError, Redactor, StructuralRedactorLive, redactedTranscript, Redaction_d_exports as t };
|
|
37
|
+
//# sourceMappingURL=Redaction.d.mts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { n as utf8ByteLength } from "../utf8-DchGZRBd.mjs";
|
|
3
|
+
import { RunEvent } from "../core/RunEvent.mjs";
|
|
4
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
5
|
+
//#region src/capabilities/Redaction.ts
|
|
6
|
+
var Redaction_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
RedactedPreview: () => RedactedPreview,
|
|
8
|
+
RedactionError: () => RedactionError,
|
|
9
|
+
Redactor: () => Redactor,
|
|
10
|
+
StructuralRedactorLive: () => StructuralRedactorLive,
|
|
11
|
+
redactedTranscript: () => redactedTranscript
|
|
12
|
+
});
|
|
13
|
+
const MAX_REDACTED_PREVIEW_BYTES = 8192;
|
|
14
|
+
const MAX_REDACTION_NODES = 4096;
|
|
15
|
+
const MAX_REDACTION_DEPTH = 16;
|
|
16
|
+
/** Branded evidence that a preview passed through the configured structural Redactor. */
|
|
17
|
+
const RedactedPreview = Schema.String.pipe(Schema.refine((value) => utf8ByteLength(value) <= MAX_REDACTED_PREVIEW_BYTES, { expected: `redacted preview of at most ${MAX_REDACTED_PREVIEW_BYTES} UTF-8 bytes` }), Schema.brand("@effect-agent/capabilities/RedactedPreview"));
|
|
18
|
+
/** Structural redaction failed closed rather than returning unreviewed caller text. */
|
|
19
|
+
var RedactionError = class extends Schema.TaggedError()("RedactionError", {
|
|
20
|
+
reason: Schema.Literals([
|
|
21
|
+
"input-too-deep",
|
|
22
|
+
"input-too-large",
|
|
23
|
+
"encoding-failed"
|
|
24
|
+
]),
|
|
25
|
+
message: Schema.String
|
|
26
|
+
}) {};
|
|
27
|
+
/** Redaction owns the boundary from decoded Tool values to bounded audit/model previews. */
|
|
28
|
+
var Redactor = class extends Context.Service()("@effect-agent/capabilities/Redactor") {};
|
|
29
|
+
const redactValue = (value, depth, counter) => {
|
|
30
|
+
if (depth > MAX_REDACTION_DEPTH) throw RedactionError.make({
|
|
31
|
+
reason: "input-too-deep",
|
|
32
|
+
message: `Decoded value exceeds redaction depth ${MAX_REDACTION_DEPTH}`
|
|
33
|
+
});
|
|
34
|
+
counter.nodes += 1;
|
|
35
|
+
if (counter.nodes > MAX_REDACTION_NODES) throw RedactionError.make({
|
|
36
|
+
reason: "input-too-large",
|
|
37
|
+
message: `Decoded value exceeds redaction node count ${MAX_REDACTION_NODES}`
|
|
38
|
+
});
|
|
39
|
+
if (Array.isArray(value)) return value.map((item) => redactValue(item, depth + 1, counter));
|
|
40
|
+
if (value !== null && typeof value === "object") {
|
|
41
|
+
const redacted = {};
|
|
42
|
+
for (const [key, item] of Object.entries(value)) redacted[key] = redactValue(item, depth + 1, counter);
|
|
43
|
+
return redacted;
|
|
44
|
+
}
|
|
45
|
+
if (value === null) return "[REDACTED:null]";
|
|
46
|
+
if (typeof value === "string") return "[REDACTED:string]";
|
|
47
|
+
if (typeof value === "number") return "[REDACTED:number]";
|
|
48
|
+
if (typeof value === "boolean") return "[REDACTED:boolean]";
|
|
49
|
+
return "[REDACTED:unsupported]";
|
|
50
|
+
};
|
|
51
|
+
const truncateUtf8 = (value, maxBytes) => {
|
|
52
|
+
if (utf8ByteLength(value) <= maxBytes) return value;
|
|
53
|
+
const suffix = "…";
|
|
54
|
+
const suffixBytes = utf8ByteLength(suffix);
|
|
55
|
+
let output = "";
|
|
56
|
+
let bytes = 0;
|
|
57
|
+
for (const character of value) {
|
|
58
|
+
const characterBytes = utf8ByteLength(character);
|
|
59
|
+
if (bytes + characterBytes + suffixBytes > maxBytes) break;
|
|
60
|
+
output += character;
|
|
61
|
+
bytes += characterBytes;
|
|
62
|
+
}
|
|
63
|
+
return `${output}${suffix}`;
|
|
64
|
+
};
|
|
65
|
+
const encodeRunEvent = Schema.encodeEffect(RunEvent);
|
|
66
|
+
/**
|
|
67
|
+
* One composed step from live Run Events to structurally redacted transcript lines
|
|
68
|
+
* (P7 WP7 friction fix; SEC-008/testing.md §12 "structurally redacted" live transcripts):
|
|
69
|
+
* Schema-encode each event through the canonical `RunEvent` union, then pass the encoded
|
|
70
|
+
* value through the configured `Redactor` — so the safe path is the short path and no live
|
|
71
|
+
* suite hand-assembles (or accidentally skips) the encode→redact pair. Engine-constructed
|
|
72
|
+
* events always encode, so an encode failure is a defect, never a silent omission.
|
|
73
|
+
*/
|
|
74
|
+
const redactedTranscript = (events) => Effect.gen(function* () {
|
|
75
|
+
const redactor = yield* Redactor;
|
|
76
|
+
const lines = [];
|
|
77
|
+
for (const event of events) {
|
|
78
|
+
const encoded = yield* encodeRunEvent(event).pipe(Effect.orDie);
|
|
79
|
+
lines.push(yield* redactor.redact(encoded));
|
|
80
|
+
}
|
|
81
|
+
return lines;
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Default structural implementation. It exposes only collection shape and
|
|
85
|
+
* scalar types, so an ordinary field such as `note` cannot bypass redaction.
|
|
86
|
+
* Tool-specific Layers may expose explicitly reviewed fields instead.
|
|
87
|
+
*/
|
|
88
|
+
const StructuralRedactorLive = Layer.succeed(Redactor)({ redact: (decodedValue) => Effect.try({
|
|
89
|
+
try: () => {
|
|
90
|
+
const structurallyRedacted = redactValue(decodedValue, 0, { nodes: 0 });
|
|
91
|
+
return truncateUtf8(JSON.stringify(structurallyRedacted), MAX_REDACTED_PREVIEW_BYTES);
|
|
92
|
+
},
|
|
93
|
+
catch: (cause) => Schema.is(RedactionError)(cause) ? cause : RedactionError.make({
|
|
94
|
+
reason: "encoding-failed",
|
|
95
|
+
message: "Could not encode the structurally redacted preview"
|
|
96
|
+
})
|
|
97
|
+
}).pipe(Effect.flatMap((preview) => Schema.decodeEffect(RedactedPreview)(preview).pipe(Effect.mapError(() => RedactionError.make({
|
|
98
|
+
reason: "encoding-failed",
|
|
99
|
+
message: "Redacted preview did not satisfy its bounded schema"
|
|
100
|
+
}))))) });
|
|
101
|
+
//#endregion
|
|
102
|
+
export { RedactedPreview, RedactionError, Redactor, StructuralRedactorLive, redactedTranscript, Redaction_exports as t };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=Redaction.mjs.map
|