@yielded/agent 0.1.0-beta.174 → 0.1.0-beta.176
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/{Admin-BHmp2V9p.d.mts → Admin-DTDihBra.d.mts} +50 -13
- package/dist/{AgentRuntime-BD3ZHAMq.d.mts → AgentRuntime-CHDyRbSf.d.mts} +3 -3
- package/dist/{AgentRuntime-B6qZlD3f.mjs → AgentRuntime-DaDKMasp.mjs} +123 -114
- package/dist/AgentRuntime-DaDKMasp.mjs.map +1 -0
- package/dist/{Digest-EpeqWEdv.mjs → Digest-C3EODOee.mjs} +2 -2
- package/dist/{Digest-EpeqWEdv.mjs.map → Digest-C3EODOee.mjs.map} +1 -1
- package/dist/{DurableAgentRuntime-CBBjRNJN.mjs → DurableAgentRuntime-BJbuIqQq.mjs} +237 -114
- package/dist/DurableAgentRuntime-BJbuIqQq.mjs.map +1 -0
- package/dist/{EventSource-C9aaJaXT.d.mts → EventSource-Cc58uEso.d.mts} +2 -2
- package/dist/InMemory.d.mts +2 -2
- package/dist/{MessageDelivery-BGDm-c46.d.mts → MessageDelivery-ClHg7c0O.d.mts} +42 -42
- package/dist/{MessagingHost-CRUK4JBi.mjs → MessagingHost-CZCyrnvJ.mjs} +27 -26
- package/dist/MessagingHost-CZCyrnvJ.mjs.map +1 -0
- package/dist/{PreparedInputAdmission-BvDqlgiP.d.mts → PreparedInputAdmission-CjcX1OP0.d.mts} +3 -3
- package/dist/{Records-BiuJDWNe.mjs → Records-DzL4Kbtw.mjs} +2 -2
- package/dist/{Records-BiuJDWNe.mjs.map → Records-DzL4Kbtw.mjs.map} +1 -1
- package/dist/{RunContinuation-4ZATcVLB.mjs → RunContinuation-CWHuciup.mjs} +74 -40
- package/dist/RunContinuation-CWHuciup.mjs.map +1 -0
- package/dist/{RunContinuation-CTJ1jGrO.d.mts → RunContinuation-DSnUTSSb.d.mts} +11 -5
- package/dist/{RunJournal-CNZqA3Ge.mjs → RunJournal-DGblbFas.mjs} +86 -81
- package/dist/RunJournal-DGblbFas.mjs.map +1 -0
- package/dist/{RunStorage-BHjuuERI.mjs → RunStorage-BF2YgWkg.mjs} +44 -33
- package/dist/RunStorage-BF2YgWkg.mjs.map +1 -0
- package/dist/{Scheduling-NG8slKdI.mjs → Scheduling-07_dsGED.mjs} +3 -3
- package/dist/{Scheduling-NG8slKdI.mjs.map → Scheduling-07_dsGED.mjs.map} +1 -1
- package/dist/{Subagent-CTIpnzlB.mjs → Subagent-CexndZSp.mjs} +2 -2
- package/dist/{Subagent-CTIpnzlB.mjs.map → Subagent-CexndZSp.mjs.map} +1 -1
- package/dist/{Subagent-DKhZA72u.d.mts → Subagent-xhN_aD1r.d.mts} +3 -3
- package/dist/{Subscription-BNg9VCRl.d.mts → Subscription-DuC_PcGx.d.mts} +2 -2
- package/dist/{SubscriptionInput-BUoXv-_K.d.mts → SubscriptionInput-B1IeAEDi.d.mts} +2 -2
- package/dist/{Thread-dk-QiNml.d.mts → Thread-DzdJAY4J.d.mts} +4 -3
- package/dist/{ThreadHistory-ByxS8HU1.d.mts → ThreadHistory-KPPBJLJb.d.mts} +12 -2
- package/dist/{ThreadImport-CMgzttvr.d.mts → ThreadImport-D_Biid6w.d.mts} +42 -42
- package/dist/{ThreadImport-CodYoJoa.mjs → ThreadImport-ZgWxf7bB.mjs} +8 -8
- package/dist/{ThreadImport-CodYoJoa.mjs.map → ThreadImport-ZgWxf7bB.mjs.map} +1 -1
- package/dist/{ThreadStore-59uDGXul.mjs → ThreadStore-BC4V-mY-.mjs} +42 -23
- package/dist/ThreadStore-BC4V-mY-.mjs.map +1 -0
- package/dist/{ThreadTransfer-3jigUl3g.mjs → ThreadTransfer-S7FnTRHt.mjs} +4 -4
- package/dist/{ThreadTransfer-3jigUl3g.mjs.map → ThreadTransfer-S7FnTRHt.mjs.map} +1 -1
- package/dist/{WorkerAdmission-DDYJdOsU.mjs → WorkerAdmission-C47Vy_cK.mjs} +5 -5
- package/dist/{WorkerAdmission-DDYJdOsU.mjs.map → WorkerAdmission-C47Vy_cK.mjs.map} +1 -1
- package/dist/{agent-registration-DRbyhAu-.mjs → agent-registration-a6QYaG3h.mjs} +4 -4
- package/dist/{agent-registration-DRbyhAu-.mjs.map → agent-registration-a6QYaG3h.mjs.map} +1 -1
- package/dist/capabilities/Messaging.mjs +1 -1
- package/dist/capabilities/ModelContext.d.mts +1 -1
- package/dist/capabilities/RunHooks.d.mts +1 -1
- package/dist/capabilities/Subagent.d.mts +1 -1
- package/dist/capabilities/Subagent.mjs +1 -1
- package/dist/core/Thread.d.mts +2 -2
- package/dist/core/Thread.mjs +5 -3
- package/dist/core/Thread.mjs.map +1 -1
- package/dist/durable/ActivityStore.mjs +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/Admin.mjs +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/AgentRegistration.mjs +1 -1
- package/dist/durable/Certification.d.mts +1 -1
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/CommittedActivity.mjs +3 -3
- package/dist/durable/Digest.mjs +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +2 -2
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/EventSource.mjs +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/LifecyclePublication.d.mts +1 -1
- package/dist/durable/LifecyclePublication.mjs +2 -2
- package/dist/durable/MessageDelivery.d.mts +1 -1
- package/dist/durable/MessageDelivery.mjs +2 -2
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +40 -40
- package/dist/durable/MessageDeliveryStoreConformance.mjs +2 -2
- package/dist/durable/PersistentHistory.d.mts +2 -2
- package/dist/durable/PersistentHistory.mjs +4 -4
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/RecordFormat.mjs +1 -1
- package/dist/durable/Records.mjs +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/Recovery.mjs +1 -1
- package/dist/durable/RunContinuation.d.mts +2 -2
- package/dist/durable/RunContinuation.mjs +3 -3
- package/dist/durable/RunJournal.d.mts +2 -2
- package/dist/durable/RunJournal.mjs +2 -2
- package/dist/durable/RunStorage.d.mts +1 -1
- package/dist/durable/RunStorage.mjs +1 -1
- package/dist/durable/Schedule.mjs +1 -1
- package/dist/durable/ScheduleStoreConformance.mjs +1 -1
- package/dist/durable/ScheduleTransition.mjs +1 -1
- package/dist/durable/Scheduling.d.mts +1 -1
- package/dist/durable/Scheduling.mjs +1 -1
- package/dist/durable/SettlementPublisher.d.mts +1 -1
- package/dist/durable/SettlementPublisher.mjs +3 -3
- package/dist/durable/SqlMemoryStore.mjs +5 -3
- package/dist/durable/SqlMemoryStore.mjs.map +1 -1
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs +7 -3
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +6 -6
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/Subscription.mjs +2 -2
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionInput.mjs +2 -2
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionStoreConformance.mjs +1 -1
- package/dist/durable/SubscriptionTools.d.mts +2 -2
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/SubscriptionTransition.mjs +1 -1
- package/dist/durable/Subscriptions.d.mts +5 -5
- package/dist/durable/Subscriptions.mjs +2 -2
- package/dist/durable/ThreadArchiveRange.d.mts +1 -1
- package/dist/durable/ThreadArchiveRange.mjs +1 -1
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.mjs +2 -2
- package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
- package/dist/durable/ThreadImport.d.mts +1 -1
- package/dist/durable/ThreadImport.mjs +1 -1
- package/dist/durable/ThreadInvariants.d.mts +3 -3
- package/dist/durable/ThreadInvariants.mjs +4 -4
- package/dist/durable/ThreadProjection.mjs +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadReader.d.mts +1 -1
- package/dist/durable/ThreadReader.mjs +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +2 -2
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +4 -4
- package/dist/durable/ThreadTransfer.d.mts +1 -1
- package/dist/durable/ThreadTransfer.mjs +1 -1
- package/dist/durable/ThreadWork.d.mts +2 -2
- package/dist/durable/ThreadWork.mjs +12 -6
- package/dist/durable/ThreadWork.mjs.map +1 -1
- package/dist/durable/ToolReconciler.mjs +1 -1
- package/dist/durable/WakeScheduler.mjs +23 -39
- package/dist/durable/WakeScheduler.mjs.map +1 -1
- package/dist/durable/WorkerAdmission.d.mts +68 -68
- package/dist/durable/WorkerAdmission.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +1 -1
- package/dist/engine/AgentRuntime.d.mts +1 -1
- package/dist/engine/AgentRuntime.mjs +1 -1
- package/dist/engine/MessagingHost.mjs +1 -1
- package/dist/engine/Output.mjs +1 -1
- package/dist/engine/ThreadHistory.d.mts +1 -1
- package/dist/engine/ThreadHistory.mjs +3 -2
- package/dist/engine/ThreadHistory.mjs.map +1 -1
- package/dist/index.d.mts +12 -12
- package/dist/index.mjs +13 -13
- package/dist/{output-contract-CMIhu4Cw.mjs → output-contract-DCnLYCdp.mjs} +12 -15
- package/dist/{output-contract-CMIhu4Cw.mjs.map → output-contract-DCnLYCdp.mjs.map} +1 -1
- package/dist/{run-context-reader-CC7ZD95F.d.mts → run-context-reader-DvTEq2RC.d.mts} +2 -2
- package/package.json +1 -1
- package/src/core/Thread.ts +143 -146
- package/src/durable/DurableAgentRuntime.ts +549 -260
- package/src/durable/RunContinuation.ts +115 -64
- package/src/durable/RunJournal.ts +107 -112
- package/src/durable/RunStorage.ts +90 -61
- package/src/durable/SqlMemoryStore.ts +8 -6
- package/src/durable/SubmissionLedger.ts +15 -0
- package/src/durable/ThreadStore.ts +48 -26
- package/src/durable/ThreadWork.ts +10 -0
- package/src/durable/WakeScheduler.ts +34 -66
- package/src/durable/internal/initial-context.ts +17 -2
- package/src/durable/internal/prompt-history-cache.ts +13 -8
- package/src/durable/internal/usage-totals.ts +28 -31
- package/src/engine/MessagingHost.ts +4 -2
- package/src/engine/ThreadHistory.ts +47 -48
- package/src/engine/internal/agent-runtime.ts +234 -202
- package/src/engine/internal/output-contract.ts +15 -15
- package/src/engine/internal/primitive-delta.ts +2 -3
- package/src/engine/internal/tool-telemetry.ts +3 -5
- package/dist/AgentRuntime-B6qZlD3f.mjs.map +0 -1
- package/dist/DurableAgentRuntime-CBBjRNJN.mjs.map +0 -1
- package/dist/MessagingHost-CRUK4JBi.mjs.map +0 -1
- package/dist/RunContinuation-4ZATcVLB.mjs.map +0 -1
- package/dist/RunJournal-CNZqA3Ge.mjs.map +0 -1
- package/dist/RunStorage-BHjuuERI.mjs.map +0 -1
- package/dist/ThreadStore-59uDGXul.mjs.map +0 -1
|
@@ -12,37 +12,38 @@ import { DelegationDepth, SubagentBudgetReservation, SubagentDelegationCaps, Sub
|
|
|
12
12
|
import { o as Selection, s as Snapshot } from "./ToolExposure-hTJT2ekj.mjs";
|
|
13
13
|
import { ChildRunUsage, InputTokenUsage, ModelCallUsage, ModelResponseIdentity, ModelUsageGroup, OutputTokenUsage, RunUsageReport, RunUsageSummary, emptyRunTotals, runTotalsFromSummary, sumRunTotals, summarizeModelUsage, unknownRunTotals } from "./core/Usage.mjs";
|
|
14
14
|
import { C as MessageStatus, S as MessageRef, _ as WorkerStop, b as WorkerUpdate, c as WorkerError, f as WorkerRef, l as WorkerHistoryEntry, o as WorkerCompletion, r as FrameworkMessage } from "./Worker-DZjdMjZn.mjs";
|
|
15
|
-
import { a as PeerMessageCapacity, d as MessageAdmission, f as MessagingError, i as PeerDeliveryLifetime, o as PeerRoutes, p as PeerName, r as PeerAuthorizer, t as MessagingHost } from "./MessagingHost-
|
|
15
|
+
import { a as PeerMessageCapacity, d as MessageAdmission, f as MessagingError, i as PeerDeliveryLifetime, o as PeerRoutes, p as PeerName, r as PeerAuthorizer, t as MessagingHost } from "./MessagingHost-CZCyrnvJ.mjs";
|
|
16
16
|
import { SubagentHost } from "./engine/SubagentHost.mjs";
|
|
17
|
+
import { Store, makeMemoryStore } from "./core/Thread.mjs";
|
|
17
18
|
import { ThreadHistory } from "./engine/ThreadHistory.mjs";
|
|
18
19
|
import { n as RunToolVisibility } from "./ToolExposure-DBATXxmL.mjs";
|
|
19
|
-
import { C as boundedValueFootprint, n as AgentChildPending, p as renderInputPrompt, u as executeWithUsageAccountingUnknown } from "./AgentRuntime-
|
|
20
|
+
import { C as boundedValueFootprint, n as AgentChildPending, p as renderInputPrompt, u as executeWithUsageAccountingUnknown } from "./AgentRuntime-DaDKMasp.mjs";
|
|
20
21
|
import { ContextRolloverTool } from "./engine/ContextWindow.mjs";
|
|
21
22
|
import { getToolExecutionClass } from "./engine/DurableStep.mjs";
|
|
22
23
|
import { CompactionError, ContextCompactor } from "./engine/ContextCompactor.mjs";
|
|
23
24
|
import { AgentUpdateAcceptance, CurrentToolFailureObserver, ModelUsageAccounting, RunContextPreparation, RunContextPreparationPassthrough, RunToolAuthorization, RunToolScheduling } from "./engine/RunOptions.mjs";
|
|
24
|
-
import { A as MAX_RUN_EVIDENCE_RECORDS, At as WorkHandoffCompleted, Bt as WorkerReportingIntent, Ct as ToolCallResolved, Dt as ToolStepSettled, Et as ToolOperation, Ft as WorkerInputRequested, G as PromptRecord, H as PeerMessagePrepared, I as ModelCallAborted, It as WorkerOrigin, Mt as WorkerContinuation, Nt as WorkerInputCompleted, O as MAX_RUN_CONTINUATION_BYTES, Ot as ToolUnavailable, P as MAX_RUN_TOOL_CALL_IDENTITIES, Pt as WorkerInputRefused, R as ModelResponseInterrupted, Rt as WorkerReportPrepared, Tt as ToolCallUnknown, U as PersistedJson, V as PROMPT_EVIDENCE_TAGS, Vt as WorkerStopRequested, X as RecordEnvelope, Z as RecordId, _t as SubmissionSettledRecord, at as RunDurationExhausted, bt as ToolApprovalDecided, c as CanonicalBatch, et as RepairAnnotated, f as CanonicalSequence, ft as SubagentJoined, g as DeclaredToolCall, gt as SubmissionSettled, ht as SubagentStarted, i as BatchId, jt as WorkerAdmission, kt as UserInputRecorded, lt as RunStartedRecord, mt as SubagentRequested, n as AgentUpdateEmitted, o as CURRENT_RECORD_FORMAT, p as CompactionCreated, pt as SubagentLineageRecorded, rt as RunContextRecorded, st as RunPolicyUsageReserved, t as AbortRequested, ut as SettlementFailureDiagnostic, v as DefinitionDigests, vt as SubtreeBudgetReserved, w as MAX_PERSISTED_JSON_BYTES, wt as ToolCallSettled, xt as ToolApprovalRequested, zt as WorkerReportRefused } from "./Records-
|
|
25
|
-
import { i as digestCanonicalJson, r as canonicalJson, s as digestJson } from "./Digest-
|
|
25
|
+
import { A as MAX_RUN_EVIDENCE_RECORDS, At as WorkHandoffCompleted, Bt as WorkerReportingIntent, Ct as ToolCallResolved, Dt as ToolStepSettled, Et as ToolOperation, Ft as WorkerInputRequested, G as PromptRecord, H as PeerMessagePrepared, I as ModelCallAborted, It as WorkerOrigin, Mt as WorkerContinuation, Nt as WorkerInputCompleted, O as MAX_RUN_CONTINUATION_BYTES, Ot as ToolUnavailable, P as MAX_RUN_TOOL_CALL_IDENTITIES, Pt as WorkerInputRefused, R as ModelResponseInterrupted, Rt as WorkerReportPrepared, Tt as ToolCallUnknown, U as PersistedJson, V as PROMPT_EVIDENCE_TAGS, Vt as WorkerStopRequested, X as RecordEnvelope, Z as RecordId, _t as SubmissionSettledRecord, at as RunDurationExhausted, bt as ToolApprovalDecided, c as CanonicalBatch, et as RepairAnnotated, f as CanonicalSequence, ft as SubagentJoined, g as DeclaredToolCall, gt as SubmissionSettled, ht as SubagentStarted, i as BatchId, jt as WorkerAdmission, kt as UserInputRecorded, lt as RunStartedRecord, mt as SubagentRequested, n as AgentUpdateEmitted, o as CURRENT_RECORD_FORMAT, p as CompactionCreated, pt as SubagentLineageRecorded, rt as RunContextRecorded, st as RunPolicyUsageReserved, t as AbortRequested, ut as SettlementFailureDiagnostic, v as DefinitionDigests, vt as SubtreeBudgetReserved, w as MAX_PERSISTED_JSON_BYTES, wt as ToolCallSettled, xt as ToolApprovalRequested, zt as WorkerReportRefused } from "./Records-DzL4Kbtw.mjs";
|
|
26
|
+
import { i as digestCanonicalJson, r as canonicalJson, s as digestJson } from "./Digest-C3EODOee.mjs";
|
|
26
27
|
import { AbortCommand, AbortIntentRequest, AdmissionPolicyError, AdmissionRequest, ApprovalDecisionCommand, ApprovalPendingSuspension, BeginChildBudgetReleaseRequest, ChildReservationId, ChildSettledNotification, ClaimHandoff, ClaimRequest, FundingOwnerRequest, LedgerError, MarkReadyRequest, MarkUnknownRequest, ParentLinkage, RecoverySnapshotRequest, ReleaseChildBudgetRequest, RevertJoiningRequest, Settlement, SettlementFinalization, SubmissionLedger, SubmissionLookupById, SubmissionLookupByKey, SubmissionScheduling, UnknownResolutionCommand, WaitingChild, WaitingForChildSuspension, WorkerLedgerState, submissionAbortBatchId, submissionAbortRecordId, submissionInputBatchId, submissionInputRecordId, submissionSettlementBatchId, submissionSettlementId, submissionSettlementRecordId, unknownResolutionKind } from "./durable/SubmissionLedger.mjs";
|
|
27
28
|
import { DeclaredPendingBatchEvidence, OpenDelegationCallEvidence, OpenToolCallEvidence, PendingApprovalEvidence, RecoveryDecision, RecoveryEvidence, classifyRecovery, pendingApprovalForRecovery } from "./durable/Recovery.mjs";
|
|
28
29
|
import { ExplainedEvidence, ExplainedSubmission, ExplainedUnknownCall, ObligationEntry, ObligationReport, RecoveryExplanation, RetryRefused, obligationSeverityOf, predictRecoveryDisposition, recoveryDecisionMeaning } from "./durable/Admin.mjs";
|
|
29
|
-
import { a as compileRegistrations, c as resolveDefinitionBinding, l as resolveWorkerBinding, n as CurrentBindingSelection, o as definitionDigestsEqual, s as makeLegacyWorkerBinding, t as BindingUnavailable, u as toolReplayContracts } from "./agent-registration-
|
|
30
|
-
import { $ as
|
|
31
|
-
import { $ as ThreadTailRequest, B as ThreadPromptRead, F as ThreadIdentityRequest, I as ThreadMaterialization, J as ThreadStore, R as ThreadObservation, U as ThreadReader, V as ThreadRead, X as ThreadStoreError, Y as ThreadStoreDiagnostic, _t as isPreContinuationFact, bt as terminalUsageCharge, gt as executionRunIds, ht as canonicalRunIds, lt as readWorkerState, n as AppendRequest, ot as getRecord, p as MAX_THREAD_EXPORT_PAGE_BYTES, pt as captureRecord, st as getRunInput } from "./ThreadStore-
|
|
30
|
+
import { a as compileRegistrations, c as resolveDefinitionBinding, l as resolveWorkerBinding, n as CurrentBindingSelection, o as definitionDigestsEqual, s as makeLegacyWorkerBinding, t as BindingUnavailable, u as toolReplayContracts } from "./agent-registration-a6QYaG3h.mjs";
|
|
31
|
+
import { $ as makeJournalMetadata, A as subagentRequestedRecordId, B as toolStepSettledRecordId, C as runStartedBatchId, D as subagentLineageBatchId, E as subagentJoinedRecordId, F as toolCallResolutionBatchId, G as turnResponseBatch, I as toolCallResolvedRecordId, K as turnResponseBatchId, L as toolCallResultBatchId, M as subagentStartedRecordId, N as toolApprovalDecisionRecordId, O as subagentLineageRecordId, P as toolApprovalRequestRecordId, R as toolCallUnknownRecordId, S as runIdForSubmission, T as subagentJoinBatchId, U as turnCanonicalBatch, V as turnApprovalsBatchId, W as turnIdForRun, X as workerOriginRecordId, Y as workerInputRecordId, Z as workerReportRecordId, _ as projectRunJournalStream, a as childIdempotencyKeyFor, b as runDurationBatchId, c as compactionRecordId, d as markUnknownBatchId, et as toolCallSettledRecordId, f as modelResponseInterruptedBatchId, h as peerMessageRecordId, i as approvalDecisionBatchId, j as subagentStartedBatchId, k as subagentRequestedBatchId, l as firstWorkerInputRecordId, m as modelResponseRecordId, o as childThreadIdFor, p as modelResponseInterruptedRecordId, q as turnResultsBatch, r as agentUpdateRecordId, s as compactionBatchId, t as RunJournalError, u as initialRunJournal, w as runStartedRecordId, x as runDurationRecordId, y as runCompletedRecordId, z as toolStepSettledBatchId } from "./RunJournal-DGblbFas.mjs";
|
|
32
|
+
import { $ as ThreadTailRequest, B as ThreadPromptRead, F as ThreadIdentityRequest, I as ThreadMaterialization, J as ThreadStore, R as ThreadObservation, U as ThreadReader, V as ThreadRead, X as ThreadStoreError, Y as ThreadStoreDiagnostic, _t as isPreContinuationFact, bt as terminalUsageCharge, gt as executionRunIds, h as PreparedAppend, ht as canonicalRunIds, lt as readWorkerState, n as AppendRequest, ot as getRecord, p as MAX_THREAD_EXPORT_PAGE_BYTES, pt as captureRecord, st as getRunInput } from "./ThreadStore-BC4V-mY-.mjs";
|
|
32
33
|
import { ScheduledInputRefused, ScheduledInputRetryable } from "./durable/Schedule.mjs";
|
|
33
34
|
import { PreparedInputAdmission } from "./durable/PreparedInputAdmission.mjs";
|
|
34
35
|
import { PreparedInput } from "./durable/Subscription.mjs";
|
|
35
36
|
import { MessageDeliveryDriver, MessageDeliveryFailpoint, MessageDeliveryRecord, MessageDeliveryStore, prepareMessageDelivery } from "./durable/MessageDelivery.mjs";
|
|
36
37
|
import { DurableRuntimeFailpoint } from "./durable/DurableFailpoint.mjs";
|
|
37
|
-
import { _ as readRunContext, a as canonicalRecordBytes, b as reference, f as runEvidence, g as digestRunHistory, l as readContinuation, m as validateSuffix, n as CurrentRunWriter, s as makeProgressWriter, t as CurrentRunSettlement, u as readRunEvidenceSnapshot, x as resolveEvidence, y as RunContextReader } from "./RunContinuation-
|
|
38
|
+
import { _ as readRunContext, a as canonicalRecordBytes, b as reference, f as runEvidence, g as digestRunHistory, l as readContinuation, m as validateSuffix, n as CurrentRunWriter, s as makeProgressWriter, t as CurrentRunSettlement, u as readRunEvidenceSnapshot, x as resolveEvidence, y as RunContextReader } from "./RunContinuation-CWHuciup.mjs";
|
|
38
39
|
import { MAX_WORK_CURSOR_CHARS, ThreadWorkDiscovery, ThreadWorkEntry, ThreadWorkRequest, WorkDiscoveryUnavailable, decodeWorkCursor, deliveryPredecessor, encodeWorkCursor, operationEvidence, resolveWorkEvidence, validateWorkPage, workId } from "./durable/ThreadWork.mjs";
|
|
39
40
|
import { WakeScheduler } from "./durable/WakeScheduler.mjs";
|
|
40
41
|
import { n as safeUnknownString, t as inspectForeignDiagnostic } from "./foreign-diagnostic-DBQ1XHKh.mjs";
|
|
41
|
-
import { c as threadCreatedBatchId, l as threadCreatedRecordId, n as WorkerAdmissionPort, o as ensureThreadCreated, r as WorkerAdmissionRequest, s as ensureWorkerOrigin } from "./WorkerAdmission-
|
|
42
|
+
import { c as threadCreatedBatchId, l as threadCreatedRecordId, n as WorkerAdmissionPort, o as ensureThreadCreated, r as WorkerAdmissionRequest, s as ensureWorkerOrigin } from "./WorkerAdmission-C47Vy_cK.mjs";
|
|
42
43
|
import { i as unresolvedToolOperations, n as isUnresolvedToolOperation, r as toolOperationStates, t as initialDispatchBlockedTurns } from "./tool-operations-BXBmagY1.mjs";
|
|
43
44
|
import { WorkerBudgetAuthorizer, WorkerConcurrencyLimit, WorkerConcurrencyResolver, WorkerHostAuthorizer, WorkerHostConfig, WorkerPolicyResolver } from "./durable/WorkerHost.mjs";
|
|
44
45
|
import { OperationAuthorizationRequest, OperationAuthorizer, OperationDenied } from "./durable/OperationAuthorizer.mjs";
|
|
45
|
-
import { o as makeRunWriter, r as RunStorage, s as StorageOwner } from "./RunStorage-
|
|
46
|
+
import { o as makeRunWriter, r as RunStorage, s as StorageOwner } from "./RunStorage-BF2YgWkg.mjs";
|
|
46
47
|
import { SettlementPublication } from "./durable/SettlementPublisher.mjs";
|
|
47
48
|
import { PendingSubmission, SettledSubmission } from "./durable/SubmissionStatus.mjs";
|
|
48
49
|
import { DeclaredToolCallEvidence, ToolReconciler } from "./durable/ToolReconciler.mjs";
|
|
@@ -768,14 +769,13 @@ const retainedBytes = (value, json, allowance) => {
|
|
|
768
769
|
const footprint = promptJsonFootprint(value, Math.floor((allowance - encodedBytes) / 2));
|
|
769
770
|
return footprint === void 0 ? void 0 : encodedBytes + 2 * footprint;
|
|
770
771
|
};
|
|
771
|
-
const encodeHistory = Effect.
|
|
772
|
-
const value = yield* encodePrompt(prompt);
|
|
772
|
+
const encodeHistory = (prompt, allowance) => Effect.suspend(() => Effect.mapEager(encodePrompt(prompt), (value) => {
|
|
773
773
|
const encoded = canonicalJson(value);
|
|
774
774
|
return {
|
|
775
775
|
encoded,
|
|
776
776
|
bytes: retainedBytes(value, encoded, allowance)
|
|
777
777
|
};
|
|
778
|
-
});
|
|
778
|
+
}));
|
|
779
779
|
const decodeCheckpointPrefix = Effect.fnUntraced(function* (encoded, length) {
|
|
780
780
|
const value = yield* parseJson(encoded);
|
|
781
781
|
const bytes = retainedBytes(value, encoded, MAX_BYTES);
|
|
@@ -2829,6 +2829,7 @@ const childUsageReportsOf = (state) => [...state.started.entries()].map(([toolCa
|
|
|
2829
2829
|
});
|
|
2830
2830
|
/** Deterministic batch identity of one executed recovery decision's audit append (DUR-013). */
|
|
2831
2831
|
const recoveryRepairBatchId = (submissionId, decisionTag) => decodeBatchId(`repair:${submissionId}:${decisionTag}`);
|
|
2832
|
+
const isOriginalInputRecord = (record) => record.payload._tag === "UserInputRecorded";
|
|
2832
2833
|
/** Deterministic record identity of one executed recovery decision's `RepairAnnotated` record. */
|
|
2833
2834
|
const recoveryRepairRecordId = (submissionId, decisionTag) => decodeRecordId(`repair:${submissionId}:${decisionTag}`);
|
|
2834
2835
|
const RecoveryCauseTag = Schema.Literals([
|
|
@@ -3152,6 +3153,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3152
3153
|
const store = yield* ThreadStore;
|
|
3153
3154
|
const reader = ThreadReader.fromStore(store);
|
|
3154
3155
|
const promptHistory = yield* makePromptHistoryCache();
|
|
3156
|
+
const unclaimedAdmissions = /* @__PURE__ */ new Map();
|
|
3155
3157
|
const workDiscovery = yield* ThreadWorkDiscovery.pipe(Effect.provide(ThreadWorkDiscovery.layer), Effect.provideService(ThreadStore, store));
|
|
3156
3158
|
const runStorage = yield* RunStorage;
|
|
3157
3159
|
const storageOwner = yield* StorageOwner;
|
|
@@ -3175,8 +3177,10 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3175
3177
|
})));
|
|
3176
3178
|
const operationAuthorizer = yield* OperationAuthorizer;
|
|
3177
3179
|
const toolFailureObserver = yield* CurrentToolFailureObserver;
|
|
3180
|
+
const runServices = Context.make(CurrentToolFailureObserver, toolFailureObserver).pipe(Context.add(RunToolVisibility, runToolVisibility), Context.add(RunToolScheduling, runToolScheduling), Context.add(ContextCompactor, compactor), Context.add(RunContextPreparation, runContextPreparation));
|
|
3181
|
+
const journalServices = Context.make(ThreadReader, reader).pipe(Context.add(Crypto.Crypto, crypto));
|
|
3178
3182
|
const withCrypto = (effect) => Effect.provideService(effect, Crypto.Crypto, crypto);
|
|
3179
|
-
const readInitialJournal = (original, suffix) => initialContext(original).pipe(Effect.
|
|
3183
|
+
const readInitialJournal = (original, suffix) => initialContext(original).pipe(Effect.provideContext(journalServices), Effect.map((history) => history.concat(suffix)));
|
|
3180
3184
|
const resolutionIntentsFor = (snapshot) => {
|
|
3181
3185
|
const intents = /* @__PURE__ */ new Map();
|
|
3182
3186
|
for (const intent of snapshot.unknownResolutions) if (!intents.has(intent.toolCallId) || unknownResolutionKind(intent.resolution) === "factual") intents.set(intent.toolCallId, intent);
|
|
@@ -3286,7 +3290,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3286
3290
|
const resolve = Effect.fnUntraced(function* (ref) {
|
|
3287
3291
|
const found = byId.get(ref.recordId);
|
|
3288
3292
|
if (found === void 0) {
|
|
3289
|
-
yield* resolveEvidence(threadId, ref).pipe(Effect.
|
|
3293
|
+
yield* resolveEvidence(threadId, ref).pipe(Effect.provideContext(journalServices));
|
|
3290
3294
|
return yield* invalid("Required Run evidence is absent from its locator; rebuild the index explicitly");
|
|
3291
3295
|
}
|
|
3292
3296
|
if (!canonicalRunIds(found.record).includes(runId)) return yield* invalid("Run continuation references another owner");
|
|
@@ -3310,7 +3314,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3310
3314
|
const cachedContext = resolvedContext;
|
|
3311
3315
|
if (cachedContext?.threadId === threadId && cachedContext.recordId === cursor.savedContext.recordId) saved = cachedContext.value;
|
|
3312
3316
|
else {
|
|
3313
|
-
saved = yield* readRunContext(initial, input, cursor.savedContext.recordId).pipe(Effect.provide(RunContextReader.layer(threadId)), Effect.
|
|
3317
|
+
saved = yield* readRunContext(initial, input, cursor.savedContext.recordId).pipe(Effect.provide(RunContextReader.layer(threadId)), Effect.provideContext(journalServices), Effect.mapError(() => invalid("Saved original context cannot be resolved from its evidence")));
|
|
3314
3318
|
resolvedContext = {
|
|
3315
3319
|
threadId,
|
|
3316
3320
|
recordId: cursor.savedContext.recordId,
|
|
@@ -3725,7 +3729,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3725
3729
|
const progressWriters = /* @__PURE__ */ new WeakMap();
|
|
3726
3730
|
const activeProgress = /* @__PURE__ */ new Map();
|
|
3727
3731
|
const withProgress = Effect.fnUntraced(function* (writer) {
|
|
3728
|
-
const progress = activeProgress.get(writer.threadId)?.writer ?? (yield* makeProgressWriter(writer.threadId, config.deploymentId).pipe(Effect.
|
|
3732
|
+
const progress = activeProgress.get(writer.threadId)?.writer ?? (yield* makeProgressWriter(writer.threadId, config.deploymentId).pipe(Effect.provideContext(journalServices)));
|
|
3729
3733
|
const owned = {
|
|
3730
3734
|
...writer,
|
|
3731
3735
|
append: (batch) => progress.commit(batch).pipe(Effect.provideService(CurrentRunWriter, writer), Effect.tapError(() => writer.checkActive))
|
|
@@ -3737,15 +3741,25 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3737
3741
|
};
|
|
3738
3742
|
});
|
|
3739
3743
|
const attemptContextAtTail = (threadId) => makeRunWriter(threadId).pipe(Effect.provideService(ThreadStore, store), Effect.provideService(StorageOwner, storageOwner), Effect.flatMap(withProgress), Effect.map(({ owned }) => owned));
|
|
3740
|
-
const withProgressSession = Effect.fnUntraced(function* (session) {
|
|
3744
|
+
const withProgressSession = Effect.fnUntraced(function* (session, originalInput) {
|
|
3741
3745
|
const { owned, progress } = yield* withProgress(session);
|
|
3742
3746
|
activeProgress.set(session.threadId, { writer: progress });
|
|
3743
3747
|
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
3744
3748
|
if (activeProgress.get(session.threadId)?.writer === progress) activeProgress.delete(session.threadId);
|
|
3745
3749
|
}));
|
|
3750
|
+
const inputWriter = session.appendInput === void 0 ? void 0 : {
|
|
3751
|
+
...session,
|
|
3752
|
+
append: session.appendInput
|
|
3753
|
+
};
|
|
3746
3754
|
const wrapped = {
|
|
3747
3755
|
...session,
|
|
3748
3756
|
append: owned.append,
|
|
3757
|
+
...inputWriter === void 0 ? {} : { appendInput: (batch) => storageOwner.withProgress(session.threadId, storageOwner.withMutation(Effect.gen(function* () {
|
|
3758
|
+
yield* session.checkActive;
|
|
3759
|
+
const original = originalInput?.();
|
|
3760
|
+
const commit = progress.commit(batch);
|
|
3761
|
+
return yield* (original === void 0 ? commit : progress.withVerifiedEmptyRun(runIdForSubmission(session.claim.submissionId), CanonicalSequence.make(original.sequence - 1), commit)).pipe(Effect.provideService(CurrentRunWriter, inputWriter));
|
|
3762
|
+
}))) },
|
|
3749
3763
|
publishSettlement: (batch) => progress.publish(batch).pipe(Effect.provideService(CurrentRunSettlement, session))
|
|
3750
3764
|
};
|
|
3751
3765
|
progressWriters.set(wrapped, progress);
|
|
@@ -3754,7 +3768,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
3754
3768
|
const progressStore = ThreadStore.of({
|
|
3755
3769
|
...store,
|
|
3756
3770
|
append: Effect.fnUntraced(function* (request) {
|
|
3757
|
-
const progress = activeProgress.get(request.threadId)?.writer ?? (yield* makeProgressWriter(request.threadId, config.deploymentId).pipe(Effect.
|
|
3771
|
+
const progress = activeProgress.get(request.threadId)?.writer ?? (yield* makeProgressWriter(request.threadId, config.deploymentId).pipe(Effect.provideContext(journalServices)));
|
|
3758
3772
|
let tail = { sequence: request.expectedTailSequence };
|
|
3759
3773
|
return yield* progress.commit(request.batch).pipe(Effect.provideService(CurrentRunWriter, {
|
|
3760
3774
|
threadId: request.threadId,
|
|
@@ -4050,6 +4064,13 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
4050
4064
|
reason
|
|
4051
4065
|
}));
|
|
4052
4066
|
});
|
|
4067
|
+
const prepareOriginalInput = (submission) => makeEnvelope(submissionInputRecordId(submission.submissionId), UserInputRecorded.make({
|
|
4068
|
+
submissionId: submission.submissionId,
|
|
4069
|
+
kind: "user",
|
|
4070
|
+
runId: runIdForSubmission(submission.submissionId),
|
|
4071
|
+
input: submission.inputPayload,
|
|
4072
|
+
...submission.messageAdmission === void 0 ? {} : { messageAdmission: submission.messageAdmission }
|
|
4073
|
+
}));
|
|
4053
4074
|
/**
|
|
4054
4075
|
* Plan step 2: append the deterministic `UserInputRecorded` record (batch idempotency makes it
|
|
4055
4076
|
* exactly-once canonical, DUR-007) and mark it applied. When canonical history already carries
|
|
@@ -4067,13 +4088,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
4067
4088
|
});
|
|
4068
4089
|
return;
|
|
4069
4090
|
}
|
|
4070
|
-
const envelope = yield*
|
|
4071
|
-
submissionId,
|
|
4072
|
-
kind: "user",
|
|
4073
|
-
runId: runIdForSubmission(submissionId),
|
|
4074
|
-
input: submission.inputPayload,
|
|
4075
|
-
...submission.messageAdmission === void 0 ? {} : { messageAdmission: submission.messageAdmission }
|
|
4076
|
-
}));
|
|
4091
|
+
const envelope = yield* prepareOriginalInput(submission);
|
|
4077
4092
|
const result = yield* appendBatch(ctx, CanonicalBatch.make({
|
|
4078
4093
|
batchId: submissionInputBatchId(submissionId),
|
|
4079
4094
|
producerId: config.producerId,
|
|
@@ -4100,8 +4115,10 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
4100
4115
|
if (starts.length > 1 || starts.length === 1 && starts[0]?.recordId !== recordId || existing !== void 0 && (existing.payload._tag !== "RunStarted" || existing.payload.runId !== runId)) return yield* RunJournalError.make({ message: `Run ${runId} has conflicting active start state` });
|
|
4101
4116
|
return existing;
|
|
4102
4117
|
});
|
|
4103
|
-
const makeRunStart = Effect.fnUntraced(function* (submission, maxDurationMillis, records, operational) {
|
|
4118
|
+
const makeRunStart = Effect.fnUntraced(function* (submission, maxDurationMillis, records, operational, input) {
|
|
4104
4119
|
const writer = yield* CurrentRunWriter;
|
|
4120
|
+
const append = input === void 0 ? writer.append : writer.appendInput;
|
|
4121
|
+
if (append === void 0) return yield* RunJournalError.make({ message: "Fresh startup requires an input publisher" });
|
|
4105
4122
|
const runId = runIdForSubmission(submission.submissionId);
|
|
4106
4123
|
const recordId = runStartedRecordId(runId);
|
|
4107
4124
|
const existing = yield* readRunStart(submission.threadId, runId, operational);
|
|
@@ -4129,11 +4146,19 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
4129
4146
|
return;
|
|
4130
4147
|
}
|
|
4131
4148
|
yield* hit("run:before-start-append");
|
|
4132
|
-
yield* appendBatch(
|
|
4133
|
-
|
|
4149
|
+
yield* appendBatch({
|
|
4150
|
+
threadId: writer.threadId,
|
|
4151
|
+
append
|
|
4152
|
+
}, CanonicalBatch.make({
|
|
4153
|
+
batchId: input === void 0 ? runStartedBatchId(runId) : submissionInputBatchId(submission.submissionId),
|
|
4134
4154
|
producerId: config.producerId,
|
|
4135
|
-
records: [
|
|
4155
|
+
records: [
|
|
4156
|
+
input ?? start,
|
|
4157
|
+
...input === void 0 ? [] : [start],
|
|
4158
|
+
...context === void 0 ? [] : [context]
|
|
4159
|
+
]
|
|
4136
4160
|
}));
|
|
4161
|
+
if (input !== void 0) yield* hit("input:after-canonical-append");
|
|
4137
4162
|
committed = true;
|
|
4138
4163
|
yield* hit("run:after-start-append");
|
|
4139
4164
|
});
|
|
@@ -4970,13 +4995,14 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
4970
4995
|
const boundaries = [];
|
|
4971
4996
|
const cached = projectedJournal;
|
|
4972
4997
|
const projectionThrough = Math.max(progressThrough ?? 0, records.at(-1)?.sequence ?? 0);
|
|
4973
|
-
const originalInput = records.find(({ record: { payload } }) => payload._tag === "UserInputRecorded" && payload.kind === "user" && payload.submissionId === submissionId);
|
|
4998
|
+
const originalInput = initialJournal?.original ?? records.find(({ record: { payload } }) => payload._tag === "UserInputRecorded" && payload.kind === "user" && payload.submissionId === submissionId);
|
|
4974
4999
|
if (originalInput === void 0) return yield* RunJournalError.make({ message: "Run has no original context boundary" });
|
|
4975
5000
|
const historyEvidence = /* @__PURE__ */ new Map();
|
|
4976
5001
|
const retainHistory = (entry) => {
|
|
4977
5002
|
if (priorContext === void 0 && entry.sequence < originalInput.sequence) historyEvidence.set(entry.record.recordId, entry);
|
|
4978
5003
|
};
|
|
4979
|
-
|
|
5004
|
+
const freshPrefix = priorContext === void 0 && initialJournal?.prefix !== void 0 && initialJournal.records?.length === 1 && initialJournal.records[0] === originalInput ? initialJournal.prefix.prompt : void 0;
|
|
5005
|
+
let journal = freshPrefix !== void 0 ? initialRunJournal(freshPrefix) : cached !== void 0 && cached.threadId === ctx.threadId && cached.through === projectionThrough && cached.runId === runId && cached.contextRecordId === priorContext?.recordId ? (boundaries.push(...cached.boundaries), cached.contextEvidence.forEach(retainHistory), cached.journal) : yield* projectRunJournalStream(canonical, runId, (boundary) => boundaries.push(boundary), priorContext, journalMetadata, priorContext === void 0 ? retainHistory : void 0);
|
|
4980
5006
|
if (initialJournal?.prefix !== void 0) {
|
|
4981
5007
|
const prompt = initialJournal.prefix.prompt;
|
|
4982
5008
|
journal = {
|
|
@@ -5096,12 +5122,11 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5096
5122
|
message: `Run usage summary exceeds safe-integer bounds at ${field}`,
|
|
5097
5123
|
cause
|
|
5098
5124
|
})));
|
|
5099
|
-
const addUsageTotal = (field, left, right) => checkedUsageTotal(field, left + right);
|
|
5100
5125
|
const subtractUsageTotal = (field, left, right) => checkedUsageTotal(field, left - right);
|
|
5101
5126
|
const currentUsageSummary = () => Effect.gen(function* () {
|
|
5102
5127
|
const stagedCalls = [...stagedUsage.values()].flatMap((usage) => usage.modelUsage);
|
|
5103
5128
|
let unobservedModelCalls = journal.usage.unobservedModelCalls ?? 0;
|
|
5104
|
-
for (const count of stagedUnobservedCalls.values()) unobservedModelCalls
|
|
5129
|
+
for (const count of stagedUnobservedCalls.values()) unobservedModelCalls += count;
|
|
5105
5130
|
const detailedCalls = [...journal.usage.modelUsage, ...stagedCalls];
|
|
5106
5131
|
const detailed = yield* summarizeModelUsage(detailedCalls, journal.usage.summarizedModelUsage).pipe(Effect.mapError((cause) => RunJournalError.make({
|
|
5107
5132
|
message: "Run detailed usage exceeds safe-integer accounting bounds",
|
|
@@ -5111,11 +5136,11 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5111
5136
|
let outputTokens = journal.usage.outputTokens;
|
|
5112
5137
|
let costMicrousd = journal.usage.costMicrousd;
|
|
5113
5138
|
for (const usage of stagedUsage.values()) {
|
|
5114
|
-
inputTokens
|
|
5115
|
-
outputTokens
|
|
5116
|
-
costMicrousd
|
|
5139
|
+
inputTokens += usage.inputTokens;
|
|
5140
|
+
outputTokens += usage.outputTokens;
|
|
5141
|
+
costMicrousd += usage.costMicrousd;
|
|
5117
5142
|
}
|
|
5118
|
-
const modelCalls =
|
|
5143
|
+
const modelCalls = journal.usage.modelCalls + stagedCalls.length;
|
|
5119
5144
|
const legacyCalls = yield* subtractUsageTotal("legacy.modelCalls", modelCalls, detailed.modelCalls);
|
|
5120
5145
|
const legacyInput = yield* subtractUsageTotal("legacy.inputTokens", inputTokens, detailed.inputTokens.total);
|
|
5121
5146
|
const legacyOutput = yield* subtractUsageTotal("legacy.outputTokens", outputTokens, detailed.outputTokens.total);
|
|
@@ -5125,48 +5150,52 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5125
5150
|
if (legacyCalls > 0) {
|
|
5126
5151
|
const existingIndex = byModel.findIndex((group) => group.provider === "unknown" && group.model === "legacy-record" && group.responseModel === void 0 && group.serviceTier === void 0 && group.pricingVersion === void 0);
|
|
5127
5152
|
const existing = existingIndex < 0 ? void 0 : byModel[existingIndex];
|
|
5128
|
-
const legacyGroup = ModelUsageGroup.
|
|
5153
|
+
const legacyGroup = yield* ModelUsageGroup.makeEffect({
|
|
5129
5154
|
provider: "unknown",
|
|
5130
5155
|
model: "legacy-record",
|
|
5131
|
-
modelCalls:
|
|
5132
|
-
inputTokens:
|
|
5133
|
-
total:
|
|
5134
|
-
uncached:
|
|
5156
|
+
modelCalls: (existing?.modelCalls ?? 0) + legacyCalls,
|
|
5157
|
+
inputTokens: {
|
|
5158
|
+
total: (existing?.inputTokens.total ?? 0) + legacyInput,
|
|
5159
|
+
uncached: (existing?.inputTokens.uncached ?? 0) + legacyInput,
|
|
5135
5160
|
cacheRead: existing?.inputTokens.cacheRead ?? 0,
|
|
5136
5161
|
cacheWrite: existing?.inputTokens.cacheWrite ?? 0
|
|
5137
|
-
}
|
|
5138
|
-
outputTokens:
|
|
5139
|
-
total:
|
|
5140
|
-
text:
|
|
5162
|
+
},
|
|
5163
|
+
outputTokens: {
|
|
5164
|
+
total: (existing?.outputTokens.total ?? 0) + legacyOutput,
|
|
5165
|
+
text: (existing?.outputTokens.text ?? 0) + legacyOutput,
|
|
5141
5166
|
reasoning: existing?.outputTokens.reasoning ?? 0
|
|
5142
|
-
}
|
|
5143
|
-
costMicrousd:
|
|
5144
|
-
})
|
|
5167
|
+
},
|
|
5168
|
+
costMicrousd: (existing?.costMicrousd ?? 0) + legacyCost
|
|
5169
|
+
}).pipe(Effect.mapError((cause) => RunJournalError.make({
|
|
5170
|
+
message: "Run legacy usage exceeds safe-integer accounting bounds",
|
|
5171
|
+
cause
|
|
5172
|
+
})));
|
|
5145
5173
|
if (existingIndex < 0) byModel.push(legacyGroup);
|
|
5146
5174
|
else byModel[existingIndex] = legacyGroup;
|
|
5147
5175
|
}
|
|
5148
|
-
|
|
5149
|
-
const text = yield* addUsageTotal("outputTokens.text", detailed.outputTokens.text, legacyOutput);
|
|
5150
|
-
return RunUsageSummary.make({
|
|
5176
|
+
return yield* RunUsageSummary.makeEffect({
|
|
5151
5177
|
...legacyCalls === 0 && detailed.webSearchCalls !== void 0 ? { webSearchCalls: detailed.webSearchCalls } : {},
|
|
5152
5178
|
modelCalls,
|
|
5153
|
-
inputTokens:
|
|
5179
|
+
inputTokens: {
|
|
5154
5180
|
total: inputTokens,
|
|
5155
|
-
uncached,
|
|
5181
|
+
uncached: detailed.inputTokens.uncached + legacyInput,
|
|
5156
5182
|
cacheRead: detailed.inputTokens.cacheRead,
|
|
5157
5183
|
cacheWrite: detailed.inputTokens.cacheWrite
|
|
5158
|
-
}
|
|
5159
|
-
outputTokens:
|
|
5184
|
+
},
|
|
5185
|
+
outputTokens: {
|
|
5160
5186
|
total: outputTokens,
|
|
5161
|
-
text,
|
|
5187
|
+
text: detailed.outputTokens.text + legacyOutput,
|
|
5162
5188
|
reasoning: detailed.outputTokens.reasoning
|
|
5163
|
-
}
|
|
5189
|
+
},
|
|
5164
5190
|
costMicrousd,
|
|
5165
5191
|
byModel,
|
|
5166
5192
|
unobservedModelCalls,
|
|
5167
5193
|
usageStatus: legacyCalls > 0 || unobservedModelCalls > 0 || interruptedUsage ? detailed.usageStatus === "unknown" ? "unknown" : "partial" : detailed.usageStatus,
|
|
5168
5194
|
pricingStatus: legacyCalls > 0 || unobservedModelCalls > 0 || interruptedUsage ? detailed.pricingStatus === "unknown" ? "unknown" : "partial" : detailed.pricingStatus
|
|
5169
|
-
})
|
|
5195
|
+
}).pipe(Effect.mapError((cause) => RunJournalError.make({
|
|
5196
|
+
message: "Run usage summary exceeds safe-integer accounting bounds",
|
|
5197
|
+
cause
|
|
5198
|
+
})));
|
|
5170
5199
|
});
|
|
5171
5200
|
const activeExecution = yield* reader.readExecution({
|
|
5172
5201
|
threadId: ctx.threadId,
|
|
@@ -5192,14 +5221,6 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5192
5221
|
usageSummary: yield* currentUsageSummary()
|
|
5193
5222
|
};
|
|
5194
5223
|
}
|
|
5195
|
-
let ownerFirstSequence;
|
|
5196
|
-
for (const envelope of records) {
|
|
5197
|
-
const payload = envelope.record.payload;
|
|
5198
|
-
if ("runId" in payload && payload.runId === runId) {
|
|
5199
|
-
ownerFirstSequence = envelope.sequence;
|
|
5200
|
-
break;
|
|
5201
|
-
}
|
|
5202
|
-
}
|
|
5203
5224
|
/** Only canonical joined inputs can require restoration from an earlier Attempt. */
|
|
5204
5225
|
let joinBacklog = joinedInputEnvelopes.size === 0 ? [] : void 0;
|
|
5205
5226
|
/** Joined inputs already handed to the engine during THIS Attempt (never re-deliver). */
|
|
@@ -5232,13 +5253,14 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5232
5253
|
};
|
|
5233
5254
|
const haltRef = yield* Ref.make(void 0);
|
|
5234
5255
|
const yieldSignal = yield* Deferred.make();
|
|
5235
|
-
const recordHalt = (effect) =>
|
|
5236
|
-
|
|
5237
|
-
const failure =
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5256
|
+
const recordHalt = (effect) => Effect.catchCause(effect, (cause) => {
|
|
5257
|
+
const first = Cause.findErrorOption(cause);
|
|
5258
|
+
const failure = Effect.failCause(Cause.map(cause, (error) => error instanceof ThreadStoreError && error.cause instanceof AgentPersistenceCapacityError ? error.cause : new CoordinatorHalt(error)));
|
|
5259
|
+
return Option.isNone(first) || first.value instanceof ThreadStoreError && first.value.cause instanceof AgentPersistenceCapacityError ? failure : Effect.andThen(Ref.set(haltRef, first.value), failure);
|
|
5260
|
+
});
|
|
5261
|
+
const progress = progressWriters.get(ctx);
|
|
5262
|
+
const checkProgress = progress === void 0 ? Effect.void : progress.check(runId).pipe(Effect.provideService(CurrentRunWriter, ctx));
|
|
5263
|
+
const checkpoint = recordHalt(Effect.flatMap(Ref.get(haltRef), (failure) => failure === void 0 ? checkProgress : Effect.fail(failure)));
|
|
5242
5264
|
const responseGate = yield* Semaphore.make(1);
|
|
5243
5265
|
let deferredResponse;
|
|
5244
5266
|
const acceptResponseDeclarations = (batch) => {
|
|
@@ -5360,6 +5382,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5360
5382
|
cause
|
|
5361
5383
|
})));
|
|
5362
5384
|
yield* (yield* CurrentRunStart).commit(yield* makeEnvelope(recordId, payload));
|
|
5385
|
+
knownIds.add(originalInput.record.recordId);
|
|
5363
5386
|
knownIds.add(runStartedRecordId(runId));
|
|
5364
5387
|
knownIds.add(recordId);
|
|
5365
5388
|
historyEvidence.clear();
|
|
@@ -5656,7 +5679,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
5656
5679
|
sourceBoundaries = [];
|
|
5657
5680
|
sourceJournal = yield* recordHalt(projectRunJournalStream(Stream.concat(source, Stream.fromIterable(yield* recordHalt(selectedRange(ctx.threadId, [submissionId], tail.sequence, canonicalThrough)))).pipe(Stream.filter((envelope) => envelope.record.payload._tag !== "CompactionCreated" || envelope.sequence <= canonicalThrough)), runId, (boundary) => sourceBoundaries.push(boundary), priorContext));
|
|
5658
5681
|
}
|
|
5659
|
-
const coverable = sourceBoundaries.filter((boundary) => commit.kind !== "summarize" ||
|
|
5682
|
+
const coverable = sourceBoundaries.filter((boundary) => commit.kind !== "summarize" || boundary.sequence < originalInput.sequence);
|
|
5660
5683
|
if (coverable.length === 0) return yield* CompactionError.make({ message: commit.kind === "rollover" ? "Durable rollover requires complete canonical records" : "Durable compaction requires eligible canonical records" });
|
|
5661
5684
|
const comparisonView = instructionView(sourceJournal.prompt.content, initialInstructions, false, sourceJournal.historyBefore.content.length);
|
|
5662
5685
|
let matchingPrefix = 0;
|
|
@@ -6321,12 +6344,12 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6321
6344
|
definitions: submission.agentDigests
|
|
6322
6345
|
}).pipe(Effect.provideService(CurrentRunWriter, ctx))), Effect.catchTag(["LedgerError", "DurableRuntimeFailpointError"], (failure) => Ref.set(haltRef, failure).pipe(Effect.andThen(Effect.fail(UpdateError.make({ reason: "storage" })))))) }), Effect.provideService(ModelUsageAccounting, { noteIncompleteUsage: (turn) => Effect.sync(() => {
|
|
6323
6346
|
stagedUnobservedCalls.set(turn, (stagedUnobservedCalls.get(turn) ?? 0) + 1);
|
|
6324
|
-
}) }), Effect.
|
|
6347
|
+
}) }), (body) => body.pipe(Effect.provideServiceEffect(ThreadHistory, ThreadHistory.makeFromStore), Effect.provideServiceEffect(Store, makeMemoryStore), Effect.scoped), Effect.provideContext(runServices.pipe(Context.add(SubagentHost.forTool, (source) => source.threadId !== submission.threadId || source.agentId !== submission.agentId || source.runId !== runId ? SubagentHost.unavailable : workerRuntime.facet({
|
|
6325
6348
|
source,
|
|
6326
6349
|
policy: agent.definition.policy,
|
|
6327
6350
|
depth: delegationDepth,
|
|
6328
6351
|
...inheritedGrant === void 0 ? {} : { grant: inheritedGrant }
|
|
6329
|
-
}, submission.principal, submission.submissionId)),
|
|
6352
|
+
}, submission.principal, submission.submissionId)), Context.add(MessagingHost.forTool, (source) => source.threadId !== submission.threadId || source.agentId !== submission.agentId || source.runId !== runId ? MessagingHost.unavailable : messagingRuntime.forTool(source, submission.principal)))), Effect.andThen(checkpoint), Effect.catchCause((cause) => Ref.get(haltRef).pipe(Effect.flatMap((failure) => failure === void 0 ? Effect.failCause(cause) : Effect.failCause(Cause.map(cause, (error) => error instanceof CoordinatorHalt ? error : new CoordinatorHalt(failure)))))), Effect.tapCause((cause) => Option.isSome(agentApprovalPendingOption(cause)) && cause.reasons.every(Cause.isFailReason) ? Effect.flatMap(DurableApprovalSuspension, (retain) => retain === void 0 ? Effect.void : halt(retain)) : Effect.void), Effect.as({ _tag: "run" }));
|
|
6330
6353
|
const abortWatcher = halt(Effect.gen(function* () {
|
|
6331
6354
|
while (true) {
|
|
6332
6355
|
yield* Effect.sleep(config.abortPollInterval);
|
|
@@ -6336,11 +6359,14 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6336
6359
|
return { _tag: "aborted" };
|
|
6337
6360
|
}
|
|
6338
6361
|
}));
|
|
6339
|
-
const
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
...
|
|
6343
|
-
|
|
6362
|
+
const result = yield* Effect.raceAllFirst([
|
|
6363
|
+
consume,
|
|
6364
|
+
abortWatcher,
|
|
6365
|
+
...yieldAfter === void 0 && submissionScheduling.yieldTo === void 0 ? [] : [Deferred.await(yieldSignal).pipe(Effect.map((nextSubmissionId) => ({
|
|
6366
|
+
_tag: "yielded",
|
|
6367
|
+
...nextSubmissionId === void 0 ? {} : { nextSubmissionId }
|
|
6368
|
+
})))]
|
|
6369
|
+
]).pipe(Effect.provideService(IdGenerator$1, idGenerator)).pipe(Effect.catchCauseFilter(Cause.findError, (error, cause) => {
|
|
6344
6370
|
if (isCoordinatorHaltCause(cause)) return Effect.failCause(Cause.map(cause, (halt) => halt.failure));
|
|
6345
6371
|
if (cause.reasons.some((reason) => reason._tag === "Fail" && reason.error instanceof AgentInputDecodeError)) return Effect.failCause(Cause.map(cause, () => BindingUnavailable.make({
|
|
6346
6372
|
agentId: agent.definition.id,
|
|
@@ -6428,17 +6454,25 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6428
6454
|
* (Unknown Outcomes, or a durable approval suspension) — no settlement occurs and the
|
|
6429
6455
|
* obligation stays owed.
|
|
6430
6456
|
*/
|
|
6431
|
-
const runAttempt = Effect.fnUntraced(function* (registeredAgent, session, resumeAfterRetention, onHandoff, yieldAfter) {
|
|
6457
|
+
const runAttempt = Effect.fnUntraced(function* (registeredAgent, session, resumeAfterRetention, onHandoff, yieldAfter, freshlyAdmitted = false) {
|
|
6432
6458
|
yield* session.checkActive;
|
|
6433
|
-
const checkpointPrompt = yield* promptHistory.take({ threadId: session.threadId }).pipe(Effect.provideService(ThreadStore, store), Effect.
|
|
6459
|
+
const checkpointPrompt = yield* promptHistory.take({ threadId: session.threadId }).pipe(Effect.provideService(ThreadStore, store), Effect.provideContext(journalServices));
|
|
6434
6460
|
let committedPromptSuffix;
|
|
6435
6461
|
const storageSession = session;
|
|
6462
|
+
let pendingOriginal;
|
|
6436
6463
|
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
6437
6464
|
committedPromptSuffix?.discard();
|
|
6438
6465
|
committedPromptSuffix = void 0;
|
|
6439
6466
|
}));
|
|
6440
|
-
|
|
6467
|
+
const promptSession = {
|
|
6441
6468
|
...storageSession,
|
|
6469
|
+
...storageSession.appendInput === void 0 ? {} : { appendInput: (batch, executions) => storageSession.appendInput(batch, executions).pipe(Effect.tap((result) => Effect.sync(() => {
|
|
6470
|
+
if (pendingOriginal !== void 0 && !result.replayed && result.firstSequence === pendingOriginal.sequence) committedPromptSuffix = makeCommittedPromptSuffix({
|
|
6471
|
+
threadId: storageSession.threadId,
|
|
6472
|
+
sequence: result.firstSequence,
|
|
6473
|
+
record: batch.records[0]
|
|
6474
|
+
});
|
|
6475
|
+
}))) },
|
|
6442
6476
|
append: (batch, executions) => {
|
|
6443
6477
|
const suffix = committedPromptSuffix;
|
|
6444
6478
|
const append = storageSession.append(batch, executions);
|
|
@@ -6456,12 +6490,70 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6456
6490
|
replayed: result.replayed
|
|
6457
6491
|
}))), Effect.tapCause(() => Effect.sync(() => suffix.discard())));
|
|
6458
6492
|
}
|
|
6459
|
-
}
|
|
6493
|
+
};
|
|
6494
|
+
session = yield* withProgressSession(promptSession, () => pendingOriginal);
|
|
6460
6495
|
const { claim, threadId } = session;
|
|
6461
6496
|
const submissionId = claim.submissionId;
|
|
6462
|
-
|
|
6497
|
+
let prepared = freshlyAdmitted && session.withInitialization !== void 0 ? yield* session.withInitialization(Effect.gen(function* () {
|
|
6498
|
+
const snapshot = yield* ledger.loadRecoverySnapshot(RecoverySnapshotRequest.make({ submissionId }));
|
|
6499
|
+
const submission = snapshot.submission;
|
|
6500
|
+
if (submission.state !== "ready" || submission.workerAdmission !== void 0 || submission.messageAdmission !== void 0 || submission.parentLinkage !== void 0 || snapshot.inputApplied !== void 0 || snapshot.abortIntent !== void 0 || snapshot.approvalDecisions.length !== 0) return void 0;
|
|
6501
|
+
yield* ensureThreadCreated$1(threadId, submission.agentId, submission.agentDigests);
|
|
6502
|
+
yield* session.refresh;
|
|
6503
|
+
const before = (yield* session.tail).sequence;
|
|
6504
|
+
const view = yield* recoveryView(threadId, before, [submissionId], runIdForSubmission(submissionId));
|
|
6505
|
+
if (view.progress !== void 0 || view.context !== void 0 || view.operational.length !== 0 || view.records.some(({ record }) => record.payload._tag !== "ThreadCreated")) return void 0;
|
|
6506
|
+
if (session.appendInput !== void 0) {
|
|
6507
|
+
const record = (yield* PreparedAppend.capture(AppendRequest.make({
|
|
6508
|
+
threadId,
|
|
6509
|
+
expectedTailSequence: before,
|
|
6510
|
+
batch: CanonicalBatch.make({
|
|
6511
|
+
batchId: submissionInputBatchId(submissionId),
|
|
6512
|
+
producerId: config.producerId,
|
|
6513
|
+
records: [yield* prepareOriginalInput(submission)]
|
|
6514
|
+
})
|
|
6515
|
+
}))).records[0].canonical;
|
|
6516
|
+
if (!isOriginalInputRecord(record)) return yield* RunJournalError.make({ message: "Captured startup has no original input" });
|
|
6517
|
+
pendingOriginal = {
|
|
6518
|
+
threadId,
|
|
6519
|
+
sequence: CanonicalSequence.make(before + 1),
|
|
6520
|
+
record
|
|
6521
|
+
};
|
|
6522
|
+
return {
|
|
6523
|
+
snapshot,
|
|
6524
|
+
through: before,
|
|
6525
|
+
view,
|
|
6526
|
+
start: yield* makeRunStart(submission, Duration.toMillis(registeredAgent.definition.policy.maxDuration), view.records, view.operational, record).pipe(Effect.provideService(CurrentRunWriter, session)),
|
|
6527
|
+
input: pendingOriginal
|
|
6528
|
+
};
|
|
6529
|
+
}
|
|
6530
|
+
const progress = progressWriters.get(session);
|
|
6531
|
+
const applyInput = applyCanonicalInput(session, submission, session, view.records, void 0);
|
|
6532
|
+
yield* progress === void 0 ? applyInput : progress.withVerifiedEmptyRun(runIdForSubmission(submissionId), before, applyInput).pipe(Effect.provideService(CurrentRunWriter, promptSession));
|
|
6533
|
+
const through = (yield* session.tail).sequence;
|
|
6534
|
+
const added = yield* selectedRange(threadId, [submissionId], through, before);
|
|
6535
|
+
const records = [...view.records, ...added];
|
|
6536
|
+
const accepted = progressWriters.get(session)?.acceptedCheckpoint(runIdForSubmission(submissionId));
|
|
6537
|
+
if (accepted === void 0 || accepted.throughSequence !== through || accepted.progress.runId !== runIdForSubmission(submissionId) || accepted.progress.submissionId !== submissionId) return void 0;
|
|
6538
|
+
const start = yield* makeRunStart(submission, Duration.toMillis(registeredAgent.definition.policy.maxDuration), records, view.operational).pipe(Effect.provideService(CurrentRunWriter, session));
|
|
6539
|
+
return {
|
|
6540
|
+
snapshot,
|
|
6541
|
+
through,
|
|
6542
|
+
view: {
|
|
6543
|
+
...view,
|
|
6544
|
+
records,
|
|
6545
|
+
progress: accepted.progress,
|
|
6546
|
+
progressThrough: accepted.throughSequence,
|
|
6547
|
+
operational: accepted.operational
|
|
6548
|
+
},
|
|
6549
|
+
start,
|
|
6550
|
+
input: void 0
|
|
6551
|
+
};
|
|
6552
|
+
})) : void 0;
|
|
6553
|
+
const preparedInput = prepared !== void 0;
|
|
6554
|
+
const snapshot = prepared?.snapshot ?? (yield* ledger.loadRecoverySnapshot(RecoverySnapshotRequest.make({ submissionId })));
|
|
6463
6555
|
const submission = snapshot.submission;
|
|
6464
|
-
yield* ensureThreadCreated$1(threadId, submission.agentId, submission.agentDigests);
|
|
6556
|
+
if (prepared === void 0) yield* ensureThreadCreated$1(threadId, submission.agentId, submission.agentDigests);
|
|
6465
6557
|
if (submission.workerAdmission?.origin.reporting?.mode === "standard") yield* updateRuntime.repairRun(threadId, submissionId);
|
|
6466
6558
|
if (submission.workerAdmission !== void 0) yield* workerRuntime.ensureOrigin(submission.workerAdmission.origin).pipe(Effect.mapError((cause) => LedgerError.make({
|
|
6467
6559
|
operation: "worker-origin",
|
|
@@ -6469,10 +6561,11 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6469
6561
|
cause
|
|
6470
6562
|
})));
|
|
6471
6563
|
if (submission.state === "admitted") yield* ledger.markReady(MarkReadyRequest.make({ submissionId }));
|
|
6472
|
-
yield* session.refresh;
|
|
6564
|
+
if (prepared === void 0) yield* session.refresh;
|
|
6473
6565
|
const ctx = session;
|
|
6474
|
-
let controlThrough = (yield* session.tail).sequence;
|
|
6475
|
-
const
|
|
6566
|
+
let controlThrough = prepared?.through ?? (yield* session.tail).sequence;
|
|
6567
|
+
const initialThrough = controlThrough;
|
|
6568
|
+
const initialView = prepared?.view ?? (yield* recoveryView(threadId, initialThrough, [submissionId], runIdForSubmission(submissionId)));
|
|
6476
6569
|
let journalMetadata;
|
|
6477
6570
|
const retainControl = controlRecords([submissionId]);
|
|
6478
6571
|
const collectControl = (record) => {
|
|
@@ -6523,8 +6616,8 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6523
6616
|
}
|
|
6524
6617
|
return Option.some(yield* settleAborted(ctx, submission, session.publishSettlement, snapshot.abortIntent, evidence, knownIds));
|
|
6525
6618
|
}
|
|
6526
|
-
yield* applyCanonicalInput(ctx, submission, session, records, snapshot.inputApplied);
|
|
6527
|
-
const start = yield* makeRunStart(submission, Duration.toMillis(agent.definition.policy.maxDuration), yield* refreshControl(), initialView.operational).pipe(Effect.provideService(CurrentRunWriter, ctx));
|
|
6619
|
+
if (prepared === void 0) yield* applyCanonicalInput(ctx, submission, session, records, snapshot.inputApplied);
|
|
6620
|
+
const start = prepared?.start ?? (yield* makeRunStart(submission, Duration.toMillis(agent.definition.policy.maxDuration), yield* refreshControl(), initialView.operational).pipe(Effect.provideService(CurrentRunWriter, ctx)));
|
|
6528
6621
|
const savedRunTiming = start.timing;
|
|
6529
6622
|
const commitStart = Effect.flatMap(CurrentRunStart, (publication) => publication.commit()).pipe(Effect.provideService(CurrentRunStart, start.publication));
|
|
6530
6623
|
const runTiming = workerOrigin === void 0 ? savedRunTiming : {
|
|
@@ -6532,13 +6625,17 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6532
6625
|
deadline: DateTime.makeUnsafe(Math.min(DateTime.toEpochMillis(savedRunTiming.deadline), workerOrigin.expiresAtMillis))
|
|
6533
6626
|
};
|
|
6534
6627
|
let expiredChildObligation = false;
|
|
6628
|
+
let preparedControl = prepared !== void 0;
|
|
6535
6629
|
if ((yield* Clock.currentTimeMillis) >= DateTime.toEpochMillis(runTiming.deadline)) {
|
|
6630
|
+
prepared = void 0;
|
|
6631
|
+
preparedControl = false;
|
|
6536
6632
|
yield* commitStart;
|
|
6537
6633
|
yield* reconcileRetainedChildren(ctx, submission, session);
|
|
6538
6634
|
expiredChildObligation = yield* completeJoinedReleases(submission);
|
|
6539
6635
|
}
|
|
6540
6636
|
const ordinaryCallsResolved = Effect.gen(function* () {
|
|
6541
|
-
const reconciliationRecords = yield* refreshControl();
|
|
6637
|
+
const reconciliationRecords = preparedControl ? records : yield* refreshControl();
|
|
6638
|
+
preparedControl = false;
|
|
6542
6639
|
const reconciliationEvidence = yield* evidenceFor(reconciliationRecords, submissionId, true, snapshot.hostSubmissionId);
|
|
6543
6640
|
if (reconciliationEvidence.openToolCalls.length === 0) return true;
|
|
6544
6641
|
const reconciliationSnapshot = yield* ledger.loadRecoverySnapshot(RecoverySnapshotRequest.make({ submissionId }));
|
|
@@ -6555,7 +6652,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6555
6652
|
return true;
|
|
6556
6653
|
});
|
|
6557
6654
|
if (!expiredChildObligation && !(yield* ordinaryCallsResolved)) return Option.none();
|
|
6558
|
-
const continuationRecords = yield* refreshControl();
|
|
6655
|
+
const continuationRecords = prepared === void 0 ? yield* refreshControl() : records;
|
|
6559
6656
|
const continuation = yield* pendingToolBatchFor(continuationRecords, runIdForSubmission(submissionId));
|
|
6560
6657
|
if (continuation !== void 0) {
|
|
6561
6658
|
const current = {
|
|
@@ -6626,21 +6723,23 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6626
6723
|
}
|
|
6627
6724
|
const lineage = {
|
|
6628
6725
|
attemptId: claim.attemptId,
|
|
6629
|
-
inputWasRecorded: evidence.inputRecorded
|
|
6726
|
+
inputWasRecorded: !preparedInput && evidence.inputRecorded
|
|
6630
6727
|
};
|
|
6631
6728
|
let approvalDecisionIntents = snapshot.approvalDecisions;
|
|
6632
6729
|
while (true) {
|
|
6633
|
-
|
|
6730
|
+
const initialization = prepared;
|
|
6731
|
+
prepared = void 0;
|
|
6732
|
+
if (initialization === void 0) yield* session.refresh;
|
|
6634
6733
|
const tail = yield* session.tail;
|
|
6635
|
-
const currentRecords = yield* refreshControl(tail.sequence);
|
|
6636
|
-
const view = yield* recoveryView(threadId, tail.sequence, [submissionId], runIdForSubmission(submissionId), currentRecords);
|
|
6734
|
+
const currentRecords = initialization === void 0 ? yield* refreshControl(tail.sequence) : records;
|
|
6735
|
+
const view = initialization?.view ?? (yield* recoveryView(threadId, tail.sequence, [submissionId], runIdForSubmission(submissionId), currentRecords));
|
|
6637
6736
|
let canonical = Stream.fromIterable(view.records);
|
|
6638
6737
|
let initialJournal;
|
|
6639
6738
|
if (view.context === void 0) {
|
|
6640
|
-
const original = currentRecords.find(({ record }) => record.payload._tag === "UserInputRecorded" && record.payload.kind === "user" && record.payload.submissionId === submissionId);
|
|
6739
|
+
const original = initialization?.input ?? currentRecords.find(({ record }) => record.payload._tag === "UserInputRecorded" && record.payload.kind === "user" && record.payload.submissionId === submissionId);
|
|
6641
6740
|
if (original === void 0) return yield* RunJournalError.make({ message: "Run has no exact original input context boundary" });
|
|
6642
6741
|
const suffix = currentRecords.filter((entry) => entry.sequence > original.sequence);
|
|
6643
|
-
const fresh = !lineage.inputWasRecorded && tail.sequence === original.sequence && suffix.length === 0;
|
|
6742
|
+
const fresh = initialization?.input !== void 0 || !lineage.inputWasRecorded && tail.sequence === original.sequence && suffix.length === 0;
|
|
6644
6743
|
const source = yield* Effect.gen(function* () {
|
|
6645
6744
|
if (checkpointPrompt !== void 0 && fresh && original.sequence === checkpointPrompt.through + 1) {
|
|
6646
6745
|
const records = [original, ...suffix];
|
|
@@ -6672,8 +6771,8 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6672
6771
|
canonical = Stream.fromIterableEffect(Effect.suspend(() => source.records === void 0 ? readInitialJournal(source.original, source.suffix) : Effect.succeed(source.records)));
|
|
6673
6772
|
}
|
|
6674
6773
|
committedPromptSuffix?.discard();
|
|
6675
|
-
committedPromptSuffix = initialJournal?.cacheable ? makeCommittedPromptSuffix(initialJournal.original) : void 0;
|
|
6676
|
-
const outcome = yield* runModel(agent, ctx, submission, session, currentRecords, canonical, initialJournal, tail.sequence, view.progressThrough, view.progress, view.context, takeJournalMetadata(), lineage, approvalDecisionIntents, currentContracts, runTiming, yieldAfter).pipe(Effect.provideService(CurrentRunStart, start.publication), Effect.ensuring(Effect.sync(() => {
|
|
6774
|
+
committedPromptSuffix = initialJournal?.cacheable && initialization?.input === void 0 ? makeCommittedPromptSuffix(initialJournal.original) : void 0;
|
|
6775
|
+
const outcome = yield* runModel(agent, ctx, submission, session, currentRecords, canonical, initialJournal, initialization?.input?.sequence ?? tail.sequence, view.progressThrough, view.progress, view.context, takeJournalMetadata(), lineage, approvalDecisionIntents, currentContracts, runTiming, yieldAfter).pipe(Effect.provideService(CurrentRunStart, start.publication), Effect.ensuring(Effect.sync(() => {
|
|
6677
6776
|
if (initialJournal !== void 0) initialJournal.records = void 0;
|
|
6678
6777
|
})));
|
|
6679
6778
|
if (outcome._tag === "yielded") {
|
|
@@ -6762,6 +6861,8 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6762
6861
|
if (Option.isNone(claimed)) return Option.none();
|
|
6763
6862
|
const session = claimed.value;
|
|
6764
6863
|
const { claim } = session;
|
|
6864
|
+
const freshlyAdmitted = unclaimedAdmissions.get(claim.submissionId) === threadId;
|
|
6865
|
+
unclaimedAdmissions.delete(claim.submissionId);
|
|
6765
6866
|
firstClaimedSubmissionId ??= claim.submissionId;
|
|
6766
6867
|
const attributes = {
|
|
6767
6868
|
threadId,
|
|
@@ -6800,7 +6901,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
6800
6901
|
deferredSubmissionIds: [...handoff?.deferredSubmissionIds ?? [], claim.submissionId],
|
|
6801
6902
|
submissionId: nextSubmissionId
|
|
6802
6903
|
});
|
|
6803
|
-
}, options?.yieldAfter), threadId, claim);
|
|
6904
|
+
}, options?.yieldAfter, freshlyAdmitted), threadId, claim);
|
|
6804
6905
|
}));
|
|
6805
6906
|
while (true) {
|
|
6806
6907
|
resumeAfterRetention = false;
|
|
@@ -7393,7 +7494,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7393
7494
|
cause
|
|
7394
7495
|
})));
|
|
7395
7496
|
});
|
|
7396
|
-
const recoverOwnedWork = Effect.fnUntraced(function* (request, recoveredAdmissions = /* @__PURE__ */ new Map()) {
|
|
7497
|
+
const recoverOwnedWork = Effect.fnUntraced(function* (request, recoveredAdmissions = /* @__PURE__ */ new Map(), deferUnclaimedAdmissions = false) {
|
|
7397
7498
|
const { threadId, work: entry } = yield* Schema.decodeEffect(WorkRecoveryRequest)(request).pipe(Effect.mapError((cause) => ThreadStoreError.make({
|
|
7398
7499
|
operation: "recover work",
|
|
7399
7500
|
message: "Invalid selected work",
|
|
@@ -7420,7 +7521,10 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7420
7521
|
});
|
|
7421
7522
|
if (owner._tag === "Admission") {
|
|
7422
7523
|
if (entry.id !== workId("admission", owner.submissionId) || entry.stateReference._tag !== "Submission" || entry.stateReference.submissionId !== owner.submissionId) return yield* invalid();
|
|
7423
|
-
|
|
7524
|
+
const original = yield* lookupKnownSubmission("recover work", owner.submissionId);
|
|
7525
|
+
if (original.threadId !== threadId) return yield* invalid();
|
|
7526
|
+
if (deferUnclaimedAdmissions && unclaimedAdmissions.get(owner.submissionId) === threadId && original.state === "ready" && !storageOwner.hasOwner(threadId) && (yield* ledger.readAbortIntent(AbortIntentRequest.make({ submissionId: owner.submissionId }))) === void 0) return report("deferred");
|
|
7527
|
+
unclaimedAdmissions.delete(owner.submissionId);
|
|
7424
7528
|
const submission = yield* recoverAdmission(owner.submissionId);
|
|
7425
7529
|
return report(submission.disposition, submission);
|
|
7426
7530
|
}
|
|
@@ -7626,6 +7730,16 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7626
7730
|
let complete = false;
|
|
7627
7731
|
let phase = "history";
|
|
7628
7732
|
const outcome = yield* isolateRecovery(Effect.gen(function* () {
|
|
7733
|
+
if (workCursor === void 0 && options?.deferUnclaimedAdmissions === true && workDiscovery.isOnlyFreshAdmission !== void 0 && !storageOwner.hasOwner(threadId)) {
|
|
7734
|
+
const fresh = [...unclaimedAdmissions].find(([, owner]) => owner === threadId);
|
|
7735
|
+
if (fresh !== void 0 && (yield* workDiscovery.isOnlyFreshAdmission({
|
|
7736
|
+
threadId,
|
|
7737
|
+
submissionId: fresh[0]
|
|
7738
|
+
}))) {
|
|
7739
|
+
complete = true;
|
|
7740
|
+
return;
|
|
7741
|
+
}
|
|
7742
|
+
}
|
|
7629
7743
|
for (let pages = 0; pages < 8 && workReports.length < 32; pages++) {
|
|
7630
7744
|
phase = "history";
|
|
7631
7745
|
const workPage = yield* discoverWork({
|
|
@@ -7638,7 +7752,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7638
7752
|
const repaired = yield* recoverOwnedWork({
|
|
7639
7753
|
threadId,
|
|
7640
7754
|
work
|
|
7641
|
-
}, recoveredAdmissions);
|
|
7755
|
+
}, recoveredAdmissions, options?.deferUnclaimedAdmissions === true);
|
|
7642
7756
|
workReports.push(repaired);
|
|
7643
7757
|
if (repaired.submission !== void 0 && !reportedAdmissions.has(repaired.submission.submissionId)) {
|
|
7644
7758
|
reportedAdmissions.add(repaired.submission.submissionId);
|
|
@@ -7745,7 +7859,7 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7745
7859
|
queueSequence: admitted.queueSequence
|
|
7746
7860
|
});
|
|
7747
7861
|
}
|
|
7748
|
-
const admitted = yield* ledger.admit(request);
|
|
7862
|
+
const admitted = yield* ledger.admit(request, { readyIfInitialized: true });
|
|
7749
7863
|
yield* hit("submit:after-admit");
|
|
7750
7864
|
const receipt = Receipt.make({
|
|
7751
7865
|
receiptId: admitted.receiptId,
|
|
@@ -7754,10 +7868,19 @@ const make = Effect.fnUntraced(function* (bindings) {
|
|
|
7754
7868
|
queueSequence: admitted.queueSequence
|
|
7755
7869
|
});
|
|
7756
7870
|
if (admitted.replayed && admitted.state !== "admitted") return receipt;
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7871
|
+
if (admitted.state === "admitted") {
|
|
7872
|
+
yield* materializeThread(options.threadId);
|
|
7873
|
+
yield* ensureThreadCreated$1(options.threadId, agent.definition.id, options.definitions);
|
|
7874
|
+
yield* hit("submit:after-materialize");
|
|
7875
|
+
yield* ledger.markReady(MarkReadyRequest.make({ submissionId: admitted.submissionId }));
|
|
7876
|
+
}
|
|
7877
|
+
if (!admitted.replayed && messageAdmission === void 0 && options.workerAdmission === void 0) {
|
|
7878
|
+
unclaimedAdmissions.set(admitted.submissionId, options.threadId);
|
|
7879
|
+
if (unclaimedAdmissions.size > 128) {
|
|
7880
|
+
const oldest = unclaimedAdmissions.keys().next().value;
|
|
7881
|
+
if (oldest !== void 0) unclaimedAdmissions.delete(oldest);
|
|
7882
|
+
}
|
|
7883
|
+
}
|
|
7761
7884
|
yield* wake.notify(options.threadId);
|
|
7762
7885
|
return receipt;
|
|
7763
7886
|
});
|
|
@@ -8371,4 +8494,4 @@ var DurableAgentRuntime = class DurableAgentRuntime extends Context.Service()("@
|
|
|
8371
8494
|
//#endregion
|
|
8372
8495
|
export { DurableApprovalSuspension as a, RecoveryFailure as c, WorkRecoveryReport as d, WorkRecoveryRequest as f, recoveryRepairRecordId as g, recoveryRepairBatchId as h, DurableApprovalResolver as i, RecoveryReport as l, isolateRecovery as m, DurableAgentRuntime as n, DurableRuntimeConfig as o, childReservationIdFor as p, DurableAgentRuntime_exports as r, RecoveryBlocked as s, ApprovalSuspensionError as t, RecoverySweepResult as u };
|
|
8373
8496
|
|
|
8374
|
-
//# sourceMappingURL=DurableAgentRuntime-
|
|
8497
|
+
//# sourceMappingURL=DurableAgentRuntime-BJbuIqQq.mjs.map
|