effect-agent 0.1.0-beta.113 → 0.1.0-beta.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Agent-1DMSO_Fl.mjs.map +1 -1
- package/dist/{Agent-DriBcXBN.d.mts → Agent-D9cXqfF3.d.mts} +9 -2
- package/dist/{AgentRuntime-DLwPoEVH.mjs → AgentRuntime-Cp1hAb-W.mjs} +8 -4
- package/dist/AgentRuntime-Cp1hAb-W.mjs.map +1 -0
- package/dist/{AgentRuntime-CWkHuzyt.d.mts → AgentRuntime-DyZv8uu2.d.mts} +6 -6
- package/dist/{DurableAgentRuntime-BIrgxwRl.mjs → DurableAgentRuntime-tNrkJZNo.mjs} +254 -162
- package/dist/DurableAgentRuntime-tNrkJZNo.mjs.map +1 -0
- package/dist/{DurableFailpoint-mx3-nsxU.d.mts → DurableFailpoint-Cnr3wx1L.d.mts} +3 -3
- package/dist/{EventSource-ARs56eBq.d.mts → EventSource-DPRdlvhV.d.mts} +3 -3
- package/dist/{Messaging-DaZDlBqh.d.mts → Messaging-JYYN3oYS.d.mts} +3 -3
- package/dist/{MessagingHost-e1Sbzfao.d.mts → MessagingHost-CqzpxbGz.d.mts} +3 -3
- package/dist/{MessagingHost-D89X7ma8.mjs → MessagingHost-DfsbMPvq.mjs} +2 -2
- package/dist/{MessagingHost-D89X7ma8.mjs.map → MessagingHost-DfsbMPvq.mjs.map} +1 -1
- package/dist/{Output-CAFJTAbP.d.mts → Output-V-6YL1_Z.d.mts} +2 -2
- package/dist/{PreparedInputAdmission-_WYg-D0f.d.mts → PreparedInputAdmission-DqQUjA9k.d.mts} +4 -4
- package/dist/{Records-BtxMy8xD.d.mts → Records-Byeb70tt.d.mts} +89 -31
- package/dist/{RunOptions-BoESJrxw.d.mts → RunOptions-CSBsSj0X.d.mts} +3 -3
- package/dist/{Schedule-DGPyXBzK.d.mts → Schedule-krSnBcbU.d.mts} +2 -2
- package/dist/{Subagent-D9eYdGTl.mjs → Subagent-Di8EEjWZ.mjs} +67 -105
- package/dist/Subagent-Di8EEjWZ.mjs.map +1 -0
- package/dist/{Subagent-F72tuaxy.d.mts → Subagent-gw9KD6eb.d.mts} +310 -35
- package/dist/{SubagentHost-CmiNTOBZ.d.mts → SubagentHost-P9zB_TfV.d.mts} +24 -18
- package/dist/{Subscription-B9VszlF9.d.mts → Subscription-Xnwd42Sm.d.mts} +6 -3
- package/dist/{SubscriptionInput-BJWZqCWP.d.mts → SubscriptionInput-CqtJ58vl.d.mts} +3 -3
- package/dist/{Worker-T_3RbaKc.mjs → Worker-CfwzMZEK.mjs} +66 -5
- package/dist/Worker-CfwzMZEK.mjs.map +1 -0
- package/dist/{Worker-Du9dhVnp.d.mts → Worker-fwWkBg12.d.mts} +199 -6
- package/dist/{agent-registration-B5CI-Ygk.mjs → agent-registration-CKNsrpwo.mjs} +7 -7
- package/dist/agent-registration-CKNsrpwo.mjs.map +1 -0
- package/dist/capabilities/Commands.d.mts +1 -1
- package/dist/capabilities/Messaging.d.mts +1 -1
- package/dist/capabilities/Messaging.mjs +2 -2
- package/dist/capabilities/RunHooks.d.mts +1 -1
- package/dist/capabilities/Subagent.d.mts +3 -3
- package/dist/capabilities/Subagent.mjs +3 -3
- package/dist/core/Agent.d.mts +1 -1
- package/dist/core/Worker.d.mts +2 -2
- package/dist/core/Worker.mjs +2 -2
- package/dist/durable/ActivityStore.d.mts +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/AgentRegistration.mjs +1 -1
- package/dist/durable/Certification.d.mts +2 -2
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/Digest.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +1 -1
- package/dist/durable/DurableFailpoint.d.mts +1 -1
- package/dist/durable/DurableFailpoint.mjs +4 -0
- package/dist/durable/DurableFailpoint.mjs.map +1 -1
- package/dist/durable/DurableFailpointTestControl.d.mts +1 -1
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/MessageDelivery.d.mts +20 -3
- package/dist/durable/MessageDelivery.mjs +12 -4
- package/dist/durable/MessageDelivery.mjs.map +1 -1
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +41 -39
- package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
- package/dist/durable/PersistentHistory.d.mts +1 -1
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/Records.d.mts +2 -2
- package/dist/durable/Records.mjs +12 -5
- package/dist/durable/Records.mjs.map +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/RunJournal.d.mts +1 -1
- package/dist/durable/Schedule.d.mts +1 -1
- package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
- package/dist/durable/ScheduleTransition.d.mts +1 -1
- package/dist/durable/Scheduling.d.mts +2 -2
- package/dist/durable/SqlMessageDeliveryStore.mjs +7 -1
- package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -1
- package/dist/durable/SqlStorageV2Upgrade.d.mts +2 -2
- package/dist/durable/SqlSubscriptionStore.d.mts +2 -2
- package/dist/durable/SqlThreadNativeReads.d.mts +5 -1
- package/dist/durable/SqlThreadNativeReads.mjs +6 -0
- package/dist/durable/SqlThreadNativeReads.mjs.map +1 -1
- package/dist/durable/SubmissionLedger.d.mts +2 -2
- package/dist/durable/SubmissionLedger.mjs +34 -4
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +899 -706
- package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -1
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/Subscription.mjs +1 -1
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionInput.mjs +1 -1
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionTools.d.mts +3 -3
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/Subscriptions.d.mts +5 -5
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
- package/dist/durable/ThreadInvariants.d.mts +1 -1
- package/dist/durable/ThreadProjection.d.mts +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +5 -0
- package/dist/durable/ThreadStore.mjs.map +1 -1
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/WorkerHost.d.mts +3 -3
- package/dist/durable/WorkerHost.mjs +1 -1
- package/dist/engine/AgentRuntime.d.mts +1 -1
- package/dist/engine/AgentRuntime.mjs +1 -1
- package/dist/engine/MessagingHost.d.mts +1 -1
- package/dist/engine/MessagingHost.mjs +1 -1
- package/dist/engine/Output.d.mts +1 -1
- package/dist/engine/RunOptions.d.mts +1 -1
- package/dist/engine/SubagentHost.d.mts +2 -2
- package/dist/engine/SubagentHost.mjs +5 -1
- package/dist/engine/SubagentHost.mjs.map +1 -1
- package/dist/index.d.mts +16 -16
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/src/capabilities/Subagent.ts +2 -1
- package/src/capabilities/internal/subagent-background.ts +86 -57
- package/src/capabilities/internal/subagent-reporting.ts +3 -128
- package/src/core/Agent.ts +8 -1
- package/src/core/Worker.ts +58 -2
- package/src/durable/DurableAgentRuntime.ts +2 -0
- package/src/durable/DurableFailpoint.ts +4 -0
- package/src/durable/MessageDelivery.ts +17 -2
- package/src/durable/Records.ts +12 -2
- package/src/durable/SqlMessageDeliveryStore.ts +15 -1
- package/src/durable/SqlThreadNativeReads.ts +14 -0
- package/src/durable/SubmissionLedger.ts +48 -1
- package/src/durable/SubmissionLedgerConformance.ts +260 -42
- package/src/durable/ThreadStore.ts +5 -0
- package/src/durable/internal/agent-registration.ts +13 -48
- package/src/durable/internal/worker-host.ts +490 -341
- package/src/engine/SubagentHost.ts +37 -13
- package/src/engine/internal/agent-runtime.ts +17 -2
- package/dist/AgentRuntime-DLwPoEVH.mjs.map +0 -1
- package/dist/DurableAgentRuntime-BIrgxwRl.mjs.map +0 -1
- package/dist/Subagent-D9eYdGTl.mjs.map +0 -1
- package/dist/Worker-T_3RbaKc.mjs.map +0 -1
- package/dist/agent-registration-B5CI-Ygk.mjs.map +0 -1
|
@@ -8,14 +8,14 @@ import { n as CurrentToolCatalog } from "./ToolExposure-UCN12eCd.mjs";
|
|
|
8
8
|
import { s as ToolBroker } from "./ToolBroker-DWs4tZra.mjs";
|
|
9
9
|
import { a as AgentInputError, c as AgentPolicyError, d as AgentToolAuthorizationDenied, f as ContextBudgetError, m as ModelProtocolError, n as AgentApprovalPending, p as ContextOverflowError, s as AgentOutputError, t as AgentApprovalDenied, u as AgentToolAuthorizationCheckError } from "./AgentError-Bn1ytXRD.mjs";
|
|
10
10
|
import { t as AgentPolicy } from "./AgentPolicy-BqDoSXO6.mjs";
|
|
11
|
-
import { A as ToolUnion, C as OutputSchema, D as RunDispositionFailure, E as RunDispositionDeclaration, N as UpdatesSchema, O as RunDispositionSchema, S as Output, _ as InstructionSource, a as CompletionFromToolDeclaration, c as Definition, d as EncodedInput, f as Failure, m as InputPromptSource, n as Any, r as AnyDefinition, s as CompletionToolDeclaration, t as Agent_d_exports, w as Requirements } from "./Agent-
|
|
12
|
-
import {
|
|
11
|
+
import { A as ToolUnion, C as OutputSchema, D as RunDispositionFailure, E as RunDispositionDeclaration, N as UpdatesSchema, O as RunDispositionSchema, S as Output, _ as InstructionSource, a as CompletionFromToolDeclaration, c as Definition, d as EncodedInput, f as Failure, m as InputPromptSource, n as Any, r as AnyDefinition, s as CompletionToolDeclaration, t as Agent_d_exports, w as Requirements } from "./Agent-D9cXqfF3.mjs";
|
|
12
|
+
import { a as WorkerBudgetScope } from "./Worker-fwWkBg12.mjs";
|
|
13
13
|
import { a as ContextWindow } from "./ContextWindow-DRQ5Mbm2.mjs";
|
|
14
14
|
import { n as CompactionError } from "./ContextCompactor-WwSIG_Z2.mjs";
|
|
15
15
|
import { t as DurableStep } from "./DurableStep-Cry_iol4.mjs";
|
|
16
|
-
import { B as RunSubagentChildIdentity, H as RunSubagentEstablishRequest, M as RunOptions, S as RunContextPreparationError, W as RunSubagentJoinRequest, i as ChildEstablishStatus, l as ModelUsageAccounting, t as AgentUpdateAcceptance, x as RunContextPreparation } from "./RunOptions-
|
|
17
|
-
import { t as MessagingHost } from "./MessagingHost-
|
|
18
|
-
import {
|
|
16
|
+
import { B as RunSubagentChildIdentity, H as RunSubagentEstablishRequest, M as RunOptions, S as RunContextPreparationError, W as RunSubagentJoinRequest, i as ChildEstablishStatus, l as ModelUsageAccounting, t as AgentUpdateAcceptance, x as RunContextPreparation } from "./RunOptions-CSBsSj0X.mjs";
|
|
17
|
+
import { t as MessagingHost } from "./MessagingHost-CqzpxbGz.mjs";
|
|
18
|
+
import { a as SubagentHost } from "./SubagentHost-P9zB_TfV.mjs";
|
|
19
19
|
import { t as RunEventSink } from "./RunEventSink-D5aVhISG.mjs";
|
|
20
20
|
import { AiError, LanguageModel, Model, Prompt, Tool, Toolkit } from "effect/unstable/ai";
|
|
21
21
|
import { Cause, Context, Effect, Layer, Option, Schema, Scope, Stream, Tracer } from "effect";
|
|
@@ -343,4 +343,4 @@ declare namespace AgentRuntime_d_exports {
|
|
|
343
343
|
}
|
|
344
344
|
//#endregion
|
|
345
345
|
export { start as A, decodeFinalOutput as C, renderInputPrompt as D, projectCompletionOutput as E, withTerminalDefectEvent as F, stream as M, streamUnknown as N, run as O, streamWithUsageAccountingUnknown as P, ToolCallWaiting as S, projectCompletionFromToolOutput as T, SubagentDurability as _, AgentResultSchema as a, SubagentDurabilityError as b, AgentSpawner as c, DetachedRun as d, EngineProvidedToolServices as f, SpawnedChildRun as g, SpawnRunOptions as h, AgentResult as i, startUnknown as j, runUnknown as k, AgentSpawnerParent as l, SpawnDelegation as m, AgentChildPending as n, AgentRuntimeFailure as o, RuntimeBinding as p, AgentCompletionProjectionRequirements as r, AgentRuntimeRequirements as s, AgentRuntime_d_exports as t, AgentSpawnerService as u, SubagentDurabilityDurable as v, encodeRunDisposition as w, SubagentDurabilityService as x, SubagentDurabilityEphemeral as y };
|
|
346
|
-
//# sourceMappingURL=AgentRuntime-
|
|
346
|
+
//# sourceMappingURL=AgentRuntime-DyZv8uu2.d.mts.map
|
|
@@ -10,25 +10,25 @@ import { IdGenerator as IdGenerator$1 } from "./core/IdGenerator.mjs";
|
|
|
10
10
|
import { DelegationDepth, SubagentBudgetReservation, SubagentDelegationCaps, SubagentGrant, SubagentParentLink, SubagentReservationAmounts, getToolExecutionKind } from "./core/SubagentContract.mjs";
|
|
11
11
|
import { o as Selection, s as Snapshot } from "./ToolExposure-C93U1sPu.mjs";
|
|
12
12
|
import { ChildRunUsage, InputTokenUsage, ModelUsageGroup, OutputTokenUsage, RunUsageReport, RunUsageSummary, emptyRunTotals, runTotalsFromSummary, sumRunTotals, summarizeModelUsage, unknownRunTotals } from "./core/Usage.mjs";
|
|
13
|
-
import {
|
|
14
|
-
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-
|
|
13
|
+
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-CfwzMZEK.mjs";
|
|
14
|
+
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-DfsbMPvq.mjs";
|
|
15
15
|
import { SubagentHost } from "./engine/SubagentHost.mjs";
|
|
16
16
|
import { ThreadHistory } from "./engine/ThreadHistory.mjs";
|
|
17
17
|
import { n as RunToolVisibility } from "./ToolExposure-9uF_Yo0T.mjs";
|
|
18
|
-
import { f as renderInputPrompt, n as AgentChildPending, y as streamWithUsageAccountingUnknown } from "./AgentRuntime-
|
|
18
|
+
import { f as renderInputPrompt, n as AgentChildPending, y as streamWithUsageAccountingUnknown } from "./AgentRuntime-Cp1hAb-W.mjs";
|
|
19
19
|
import { ContextRolloverTool } from "./engine/ContextWindow.mjs";
|
|
20
20
|
import { getToolExecutionClass } from "./engine/DurableStep.mjs";
|
|
21
21
|
import { CompactionError, ContextCompactor } from "./engine/ContextCompactor.mjs";
|
|
22
22
|
import { RunPolicyUsage } from "./core/RunPolicyUsage.mjs";
|
|
23
23
|
import { AgentUpdateAcceptance, CurrentToolFailureObserver, ModelUsageAccounting, RunContextPreparation, RunContextPreparationPassthrough, RunToolAuthorization, RunToolScheduling } from "./engine/RunOptions.mjs";
|
|
24
|
-
import { AbortRequested, AgentUpdateEmitted, BatchId, CanonicalBatch, CanonicalRecordEnvelope, CanonicalSequence, CompactionCreated, DefinitionDigests, Digest, ModelResponseInterrupted, PeerMessagePrepared, PersistedJson, ProducerEpoch, RecordEnvelope, RecordId, RepairAnnotated, RunDurationExhausted, RunPolicyUsageReserved, RunStartedRecord, SettlementFailureDiagnostic, SubagentJoined, SubagentLineageRecorded, SubagentRequested, SubagentStarted, SubmissionSettled, SubmissionSettledRecord, SubtreeBudgetReserved, ThreadCreated, ToolApprovalDecided, ToolApprovalRequested, ToolCallPrepared, ToolCallResolved, ToolCallSettled, ToolCallUnknown, ToolOperation, ToolStepSettled, ToolUnavailable, UserInputRecorded, WorkerAdmission, WorkerInputCompleted, WorkerInputRequested, WorkerOrigin, WorkerOriginRecorded, WorkerReportPrepared, WorkerReportRefused, WorkerReportingIntent } from "./durable/Records.mjs";
|
|
25
|
-
import { AbortCommand, AbortIntentRequest, AdmissionPolicyError, AdmissionRequest, ApprovalDecisionCommand, ApprovalPendingSuspension, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildBudgetReservationRequest, ChildReservationId, ChildSettledNotification, ClaimJoiningRequest, ClaimRequest, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipToken, ParentLinkage, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, RevertJoiningRequest, Settlement, SettlementFinalization, SettlementReservation, SubmissionLedger, SubmissionLookupById, SubmissionLookupByKey, SuspendRequest, UnknownResolutionCommand, WaitingChild, WaitingForChildSuspension, submissionAbortBatchId, submissionAbortRecordId, submissionInputBatchId, submissionInputRecordId, submissionSettlementBatchId, submissionSettlementId, submissionSettlementRecordId } from "./durable/SubmissionLedger.mjs";
|
|
24
|
+
import { AbortRequested, AgentUpdateEmitted, BatchId, CanonicalBatch, CanonicalRecordEnvelope, CanonicalSequence, CompactionCreated, DefinitionDigests, Digest, ModelResponseInterrupted, PeerMessagePrepared, PersistedJson, ProducerEpoch, RecordEnvelope, RecordId, RepairAnnotated, RunDurationExhausted, RunPolicyUsageReserved, RunStartedRecord, SettlementFailureDiagnostic, SubagentJoined, SubagentLineageRecorded, SubagentRequested, SubagentStarted, SubmissionSettled, SubmissionSettledRecord, SubtreeBudgetReserved, ThreadCreated, ToolApprovalDecided, ToolApprovalRequested, ToolCallPrepared, ToolCallResolved, ToolCallSettled, ToolCallUnknown, ToolOperation, ToolStepSettled, ToolUnavailable, UserInputRecorded, WorkerAdmission, WorkerInputCompleted, WorkerInputRequested, WorkerOrigin, WorkerOriginRecorded, WorkerReportPrepared, WorkerReportRefused, WorkerReportingIntent, WorkerStopRequested } from "./durable/Records.mjs";
|
|
25
|
+
import { AbortCommand, AbortIntentRequest, AdmissionPolicyError, AdmissionRequest, ApprovalDecisionCommand, ApprovalPendingSuspension, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildBudgetReservationRequest, ChildReservationId, ChildSettledNotification, ClaimJoiningRequest, ClaimRequest, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipToken, ParentLinkage, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, RevertJoiningRequest, Settlement, SettlementFinalization, SettlementReservation, SubmissionLedger, SubmissionLookupById, SubmissionLookupByKey, SuspendRequest, UnknownResolutionCommand, WaitingChild, WaitingForChildSuspension, WorkerLedgerState, submissionAbortBatchId, submissionAbortRecordId, submissionInputBatchId, submissionInputRecordId, submissionSettlementBatchId, submissionSettlementId, submissionSettlementRecordId } from "./durable/SubmissionLedger.mjs";
|
|
26
26
|
import { DeclaredPendingBatchEvidence, OpenDelegationCallEvidence, OpenToolCallEvidence, PendingApprovalEvidence, RecoveryDecision, RecoveryEvidence, classifyRecovery } from "./durable/Recovery.mjs";
|
|
27
27
|
import { ExplainedEvidence, ExplainedSubmission, ExplainedUnknownCall, IntegrityCheck, IntegrityReport, ObligationEntry, ObligationReport, RecoveryExplanation, RetryRefused, obligationSeverityOf, predictRecoveryDisposition, recoveryDecisionMeaning } from "./durable/Admin.mjs";
|
|
28
28
|
import { digestJson } from "./durable/Digest.mjs";
|
|
29
|
-
import { a as definitionDigestsEqual, c as resolveWorkerBinding, i as compileRegistrations, l as toolReplayContracts, o as makeLegacyWorkerBinding, s as resolveDefinitionBinding, t as BindingUnavailable } from "./agent-registration-
|
|
29
|
+
import { a as definitionDigestsEqual, c as resolveWorkerBinding, i as compileRegistrations, l as toolReplayContracts, o as makeLegacyWorkerBinding, s as resolveDefinitionBinding, t as BindingUnavailable } from "./agent-registration-CKNsrpwo.mjs";
|
|
30
30
|
import { $ as workerOriginRecordId, A as subagentRequestedRecordId, B as toolCallUnknownRecordId, C as runStartedBatchId, D as subagentLineageBatchId, E as subagentJoinedRecordId, F as toolCallPreparedRecordId, G as turnCanonicalBatch, H as toolStepSettledRecordId, I as toolCallResolutionBatchId, J as turnResponseBatch, K as turnIdForRun, L as toolCallResolvedRecordId, M as subagentStartedRecordId, N as toolApprovalDecisionRecordId, O as subagentLineageRecordId, P as toolApprovalRequestRecordId, Q as workerInputRecordId, R as toolCallResultBatchId, S as runIdForSubmission, T as subagentJoinBatchId, U as turnApprovalsBatchId, V as toolStepSettledBatchId, X as turnResultsBatch, a as childIdempotencyKeyFor, b as runDurationBatchId, c as compactionRecordId, d as modelResponseInterruptedBatchId, et as workerReportRecordId, f as modelResponseInterruptedRecordId, g as projectRunJournalStream, i as approvalDecisionBatchId, j as subagentStartedBatchId, k as subagentRequestedBatchId, l as firstWorkerInputRecordId, m as peerMessageRecordId, o as childThreadIdFor, p as modelResponseRecordId, q as turnPreparedBatchId, r as agentUpdateRecordId, s as compactionBatchId, t as RunJournalError, tt as makeJournalMetadata, u as markUnknownBatchId, v as runCompletedRecordId, w as runStartedRecordId, x as runDurationRecordId, y as runCompletionDigest, z as toolCallSettledRecordId } from "./RunJournal-BXrq0VIK.mjs";
|
|
31
|
-
import { FencedAppendRequest, LoadCheckpointRequest, MAX_THREAD_EXPORT_RECORDS, SaveRecoveryCheckpointRequest, ThreadCheckpoint, ThreadExportRequest, ThreadMaterialization, ThreadObservation, ThreadRead, ThreadStore, ThreadStoreDiagnostic, ThreadStoreError, ThreadTailRequest, getRecord, readWorkerState } from "./durable/ThreadStore.mjs";
|
|
31
|
+
import { FencedAppendRequest, LoadCheckpointRequest, MAX_THREAD_EXPORT_RECORDS, SaveRecoveryCheckpointRequest, ThreadCheckpoint, ThreadExportRequest, ThreadMaterialization, ThreadObservation, ThreadRead, ThreadStore, ThreadStoreDiagnostic, ThreadStoreError, ThreadTailRequest, getRecord, getRunInput, readWorkerState } from "./durable/ThreadStore.mjs";
|
|
32
32
|
import { DurableRuntimeFailpoint } from "./durable/DurableFailpoint.mjs";
|
|
33
33
|
import { ScheduledInputRefused, ScheduledInputRetryable } from "./durable/Schedule.mjs";
|
|
34
34
|
import { PreparedInputAdmission } from "./durable/PreparedInputAdmission.mjs";
|
|
@@ -752,26 +752,21 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
752
752
|
const reports = source.reporting?.filter((entry) => entry.delegationId === delegationId) ?? [];
|
|
753
753
|
const report = reports[0];
|
|
754
754
|
if (report === void 0) return void 0;
|
|
755
|
-
if (reports.length !== 1 || !Object.is(report.target, target.definition)
|
|
756
|
-
|
|
757
|
-
if (
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
755
|
+
if (reports.length !== 1 || !Object.is(report.target, target.definition)) return yield* failure("start", "declaration-unavailable");
|
|
756
|
+
const submission = authority.submission;
|
|
757
|
+
if (submission === void 0 || authority.depth !== 0 && submission.workerAdmission === void 0) return yield* failure("start", "denied");
|
|
758
|
+
const retained = submission.workerAdmission === void 0 ? void 0 : yield* Schema.encodeEffect(WorkerAdmission)(submission.workerAdmission).pipe(Effect.flatMap(Schema.decodeEffect(PersistedJson)), Effect.mapError(storageFailure("start")));
|
|
759
|
+
return {
|
|
760
|
+
sourceDigests: source.digests,
|
|
761
|
+
mode: "standard",
|
|
762
|
+
returnAddress: {
|
|
762
763
|
input: submission.inputPayload,
|
|
763
764
|
principal: submission.principal,
|
|
764
765
|
policy: authority.policy,
|
|
765
766
|
depth: authority.depth,
|
|
766
767
|
...authority.grant === void 0 ? {} : { grant: authority.grant },
|
|
767
768
|
...retained === void 0 ? {} : { workerAdmission: retained }
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
return {
|
|
771
|
-
sourceDigests: source.digests,
|
|
772
|
-
...report.mode === void 0 ? {} : { mode: report.mode },
|
|
773
|
-
...returnAddress === void 0 ? {} : { returnAddress },
|
|
774
|
-
...report.destination === void 0 ? {} : { destinationDelegationId: report.destination.delegationId }
|
|
769
|
+
}
|
|
775
770
|
};
|
|
776
771
|
});
|
|
777
772
|
const currentBinding = (agentId) => {
|
|
@@ -1040,7 +1035,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1040
1035
|
const sourceBinding = currentBinding(origin.source.agentId);
|
|
1041
1036
|
const targetBinding = currentBinding(origin.worker.targetAgentId);
|
|
1042
1037
|
const reports = sourceBinding?.reporting?.filter((entry) => entry.delegationId === origin.worker.delegationId) ?? [];
|
|
1043
|
-
if (sourceBinding === void 0 || targetBinding === void 0 || reports.length !== 1 || reports[0]
|
|
1038
|
+
if (sourceBinding === void 0 || targetBinding === void 0 || reports.length !== 1 || reports[0] === void 0 || reports[0].target !== targetBinding.definition || !definitionDigestsEqual(submission.agentDigests, origin.targetDigests)) return yield* failure("followUp", "declaration-unavailable");
|
|
1044
1039
|
const receivingOrigin = retained?.origin;
|
|
1045
1040
|
if (destination.depth !== 0 && receivingOrigin === void 0) return yield* failure("followUp", "denied");
|
|
1046
1041
|
const now = yield* Clock.currentTimeMillis;
|
|
@@ -1115,53 +1110,25 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1115
1110
|
messageId,
|
|
1116
1111
|
reason
|
|
1117
1112
|
});
|
|
1113
|
+
if (intent.mode !== "standard") return refused("declaration-unavailable");
|
|
1118
1114
|
const selected = yield* deps.ledger.lookup(SubmissionLookupById.make({ submissionId: host.submissionId })).pipe(Effect.mapError(storageFailure("inspect")));
|
|
1119
1115
|
if (Option.isNone(selected) || selected.value.threadId !== submission.threadId || selected.value.receiptId !== host.receiptId || selected.value.workerAdmission === void 0 || !sameOrigin(selected.value.workerAdmission.origin, origin)) return yield* failure("inspect", "corrupt");
|
|
1120
1116
|
const hostSubmission = selected.value;
|
|
1121
1117
|
const hostAdmission = selected.value.workerAdmission;
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
admission: retained,
|
|
1130
|
-
sourceSubmissionId: void 0
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
const first = Option.getOrUndefined(yield* exactRecord(origin.source.threadId, workerInputRecordId(origin.firstMessageId), "inspect"))?.record.payload;
|
|
1134
|
-
if (first?._tag !== "WorkerInputRequested" || first.admission.messageId !== origin.firstMessageId || !sameOrigin(first.admission.origin, origin)) return yield* failure("inspect", "corrupt");
|
|
1135
|
-
const authority = yield* sourceAuthority(origin.source.threadId, first.admission.sourceSubmissionId);
|
|
1136
|
-
const recorded = authority.current.records.find(({ record }) => record.payload._tag === "WorkerOriginRecorded")?.record.payload;
|
|
1137
|
-
let retained;
|
|
1138
|
-
let principal = hostSubmission.principal;
|
|
1139
|
-
if (recorded?._tag === "WorkerOriginRecorded") {
|
|
1140
|
-
if (hostAdmission.sourceSubmissionId === void 0) return yield* failure("inspect", "denied");
|
|
1141
|
-
const snapshot = yield* deps.ledger.lookup(SubmissionLookupById.make({ submissionId: hostAdmission.sourceSubmissionId })).pipe(Effect.mapError(storageFailure("inspect")));
|
|
1142
|
-
if (Option.isNone(snapshot) || snapshot.value.threadId !== origin.source.threadId || snapshot.value.workerAdmission === void 0 || !sameOrigin(snapshot.value.workerAdmission.origin, recorded.origin)) return yield* failure("inspect", "denied");
|
|
1143
|
-
retained = snapshot.value.workerAdmission;
|
|
1144
|
-
principal = snapshot.value.principal;
|
|
1145
|
-
}
|
|
1146
|
-
return {
|
|
1147
|
-
policy: authority.policy,
|
|
1148
|
-
depth: authority.depth,
|
|
1149
|
-
grant: authority.grant,
|
|
1150
|
-
input: authority.submission?.inputPayload,
|
|
1151
|
-
admission: retained,
|
|
1152
|
-
principal,
|
|
1153
|
-
sourceSubmissionId: first.admission.sourceSubmissionId
|
|
1154
|
-
};
|
|
1155
|
-
});
|
|
1118
|
+
const address = intent.returnAddress;
|
|
1119
|
+
if (address === void 0) return yield* failure("inspect", "corrupt");
|
|
1120
|
+
const retainedAdmission = address.workerAdmission === void 0 ? void 0 : yield* Schema.decodeUnknownEffect(WorkerAdmission)(address.workerAdmission).pipe(Effect.mapError((cause) => failure("inspect", "corrupt", cause)));
|
|
1121
|
+
const source = {
|
|
1122
|
+
...address,
|
|
1123
|
+
admission: retainedAdmission
|
|
1124
|
+
};
|
|
1156
1125
|
const sourceBinding = currentBinding(origin.source.agentId);
|
|
1157
1126
|
const targetBinding = currentBinding(origin.worker.targetAgentId);
|
|
1158
1127
|
const reports = sourceBinding?.reporting?.filter((entry) => entry.delegationId === origin.worker.delegationId) ?? [];
|
|
1159
1128
|
const descriptor = reports[0];
|
|
1160
|
-
if (sourceBinding === void 0 || targetBinding === void 0 || descriptor === void 0 || reports.length !== 1 || !Object.is(descriptor.target, targetBinding.definition)
|
|
1129
|
+
if (sourceBinding === void 0 || targetBinding === void 0 || descriptor === void 0 || reports.length !== 1 || !Object.is(descriptor.target, targetBinding.definition)) return refused("declaration-unavailable");
|
|
1161
1130
|
const sourceOrigin = source.admission?.origin;
|
|
1162
1131
|
if (source.depth !== 0 && sourceOrigin === void 0) return refused("destination");
|
|
1163
|
-
if (descriptor.mode !== "standard" && sourceOrigin !== void 0 && (descriptor.destination === void 0 || descriptor.destination.delegationId !== sourceOrigin.worker.delegationId || descriptor.destination.target.id !== sourceOrigin.worker.targetAgentId)) return refused("destination");
|
|
1164
|
-
if (sourceOrigin === void 0 && descriptor.destination !== void 0) return refused("destination");
|
|
1165
1132
|
const now = yield* Clock.currentTimeMillis;
|
|
1166
1133
|
const deadlineAtMillis = Math.min(origin.expiresAtMillis, sourceOrigin?.expiresAtMillis ?? Infinity);
|
|
1167
1134
|
if (now >= deadlineAtMillis) return refused("expired");
|
|
@@ -1196,13 +1163,10 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1196
1163
|
value
|
|
1197
1164
|
})), Effect.catchTag("WorkerReportPreparationFailure", (error) => Effect.succeed(refused(error.stage))), Effect.catchTag("TimeoutError", () => Effect.succeed(refused("timeout"))), Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), () => Effect.succeed(refused("defect"))));
|
|
1198
1165
|
if (projection._tag === "WorkerReportRefused") return projection;
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
} else if (projection.value.message !== void 0) return refused("input");
|
|
1204
|
-
const reportInput = descriptor.mode === "standard" ? source.input : projection.value.encodedInput;
|
|
1205
|
-
const validated = yield* (descriptor.mode === "standard" ? Schema.decodeUnknownEffect(PersistedJson)(reportInput) : Schema.decodeEffect(Schema.toEncoded(sourceBinding.definition.input))(reportInput).pipe(Effect.flatMap(() => Schema.decodeUnknownEffect(PersistedJson)(reportInput)))).pipe(Effect.option);
|
|
1166
|
+
const message = projection.value.message;
|
|
1167
|
+
if (!Schema.is(WorkerCompletion)(message)) return refused("input");
|
|
1168
|
+
if (!Schema.toEquivalence(WorkerRef)(message.report.worker, origin.worker) || !Schema.toEquivalence(Receipt)(message.report.receipt, report.observation.receipt) || message.report.runId !== runId || message.report.settlementId !== host.settlementId || message.report.outcome !== host.outcome || message.budgetExhausted !== report.observation.budgetExhausted) return refused("input");
|
|
1169
|
+
const validated = yield* Schema.decodeEffect(PersistedJson)(source.input).pipe(Effect.option);
|
|
1206
1170
|
if (Option.isNone(validated)) return refused("input");
|
|
1207
1171
|
const input = validated.value;
|
|
1208
1172
|
const inputDigest = yield* withCrypto(digestJson(input)).pipe(Effect.mapError(storageFailure("inspect")));
|
|
@@ -1211,7 +1175,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1211
1175
|
if (sourceOrigin !== void 0) {
|
|
1212
1176
|
const retained = source.admission;
|
|
1213
1177
|
if (retained === void 0) return refused("destination");
|
|
1214
|
-
const parameters = yield* Schema.
|
|
1178
|
+
const parameters = yield* Schema.decodeEffect(PersistedJson)(retained.parameters).pipe(Effect.option);
|
|
1215
1179
|
if (Option.isNone(parameters)) return refused("destination");
|
|
1216
1180
|
workerAdmission = {
|
|
1217
1181
|
origin: sourceOrigin,
|
|
@@ -1221,20 +1185,10 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1221
1185
|
...retained.sourceSubmissionId === void 0 ? {} : { sourceSubmissionId: retained.sourceSubmissionId }
|
|
1222
1186
|
};
|
|
1223
1187
|
}
|
|
1224
|
-
const authorizationSourceSubmissionId = sourceOrigin === void 0 ? source.sourceSubmissionId : workerAdmission?.sourceSubmissionId;
|
|
1225
|
-
const authorized = intent.mode === "standard" ? Option.some(principal) : yield* deps.authorizer.authorize({
|
|
1226
|
-
sourceThreadId: sourceOrigin?.source.threadId ?? origin.source.threadId,
|
|
1227
|
-
...authorizationSourceSubmissionId === void 0 ? {} : { sourceSubmissionId: authorizationSourceSubmissionId },
|
|
1228
|
-
principal,
|
|
1229
|
-
operation: "followUp",
|
|
1230
|
-
access: "send",
|
|
1231
|
-
worker: sourceOrigin?.worker ?? origin.worker
|
|
1232
|
-
}).pipe(Effect.map(Option.some), Effect.catchTag("WorkerError", (error) => error.reason === "storage" || error.reason === "unavailable" ? Effect.fail(error) : Effect.succeed(Option.none())));
|
|
1233
|
-
if (Option.isNone(authorized)) return refused("denied");
|
|
1234
1188
|
const envelope = {
|
|
1235
1189
|
schemaVersion: 1,
|
|
1236
1190
|
threadId: origin.source.threadId,
|
|
1237
|
-
deliveryPrincipal:
|
|
1191
|
+
deliveryPrincipal: principal,
|
|
1238
1192
|
agentId: origin.source.agentId,
|
|
1239
1193
|
definitions: intent.sourceDigests,
|
|
1240
1194
|
input,
|
|
@@ -1244,10 +1198,10 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1244
1198
|
policyId: "worker-report",
|
|
1245
1199
|
decisionId: messageId
|
|
1246
1200
|
},
|
|
1247
|
-
|
|
1201
|
+
messageAdmission: message,
|
|
1248
1202
|
...workerAdmission === void 0 ? {} : { workerAdmission: {
|
|
1249
1203
|
...workerAdmission,
|
|
1250
|
-
deliveryPrincipal:
|
|
1204
|
+
deliveryPrincipal: principal
|
|
1251
1205
|
} }
|
|
1252
1206
|
};
|
|
1253
1207
|
const encoded = yield* Schema.encodeEffect(PreparedInput)(envelope).pipe(Effect.flatMap(Schema.decodeUnknownEffect(PersistedJson)), Effect.mapError(storageFailure("inspect")));
|
|
@@ -1364,7 +1318,16 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1364
1318
|
if (worker.targetAgentId !== target.id) return yield* failure(operation, "worker-mismatch");
|
|
1365
1319
|
const first = Option.getOrUndefined(yield* exactRecord(context.source.threadId, firstWorkerInputRecordId(worker), operation))?.record.payload;
|
|
1366
1320
|
const origin = first?._tag === "WorkerInputRequested" ? first.admission.origin : void 0;
|
|
1367
|
-
if (origin === void 0)
|
|
1321
|
+
if (origin === void 0) {
|
|
1322
|
+
const retained = Option.isNone(deps.deliveries) ? null : yield* deps.deliveries.value.get({
|
|
1323
|
+
ownerThreadId: context.source.threadId,
|
|
1324
|
+
messageId: Schema.decodeSync(IdempotencyKey)(worker.threadId)
|
|
1325
|
+
}).pipe(Effect.mapError(storageFailure(operation)));
|
|
1326
|
+
const pendingOrigin = retained?.envelope.workerAdmission?.origin;
|
|
1327
|
+
if (pendingOrigin === void 0) return yield* failure(operation, "not-found");
|
|
1328
|
+
if (!Schema.toEquivalence(WorkerRef)(pendingOrigin.worker, worker) || pendingOrigin.firstMessageId !== retained?.key.messageId || pendingOrigin.source.threadId !== context.source.threadId) return yield* failure(operation, "worker-mismatch");
|
|
1329
|
+
return pendingOrigin;
|
|
1330
|
+
}
|
|
1368
1331
|
if (!Schema.toEquivalence(WorkerRef)(origin.worker, worker) || first?._tag !== "WorkerInputRequested" || first.admission.messageId !== origin.firstMessageId || workerInputRecordId(origin.firstMessageId) !== firstWorkerInputRecordId(worker)) return yield* failure(operation, "worker-mismatch");
|
|
1369
1332
|
return origin;
|
|
1370
1333
|
});
|
|
@@ -1470,40 +1433,99 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1470
1433
|
return yield* deliveryStatus(processed, operation);
|
|
1471
1434
|
});
|
|
1472
1435
|
const messageIdFor = (parts) => withCrypto(digestJson(parts)).pipe(Effect.map((digest) => Schema.decodeSync(IdempotencyKey)(`worker:${digest}`)), Effect.mapError(storageFailure("start")));
|
|
1473
|
-
const summarize = Effect.fn("WorkerHost.summarize")(function* (origin,
|
|
1436
|
+
const summarize = Effect.fn("WorkerHost.summarize")(function* (origin, operation) {
|
|
1474
1437
|
yield* authorize(operation, "read", origin.worker);
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1438
|
+
if (deps.ledger.inspectWorker === void 0 || Option.isNone(deps.deliveries)) return yield* failure(operation, "unavailable");
|
|
1439
|
+
const threadId = origin.worker.threadId;
|
|
1440
|
+
const deliveries = deps.deliveries.value;
|
|
1441
|
+
const pending = () => deliveries.list({
|
|
1442
|
+
ownerThreadId: context.source.threadId,
|
|
1443
|
+
pendingWorker: threadId,
|
|
1444
|
+
limit: 1
|
|
1445
|
+
}).pipe(Effect.mapError(storageFailure(operation)), Effect.map((page) => page.items[0]));
|
|
1446
|
+
const tail = () => deps.store.inspectTail(ThreadTailRequest.make({ threadId })).pipe(Effect.catchTag("ThreadNotMaterialized", () => Effect.succeed(void 0)), Effect.mapError(storageFailure(operation)));
|
|
1447
|
+
const receipt = (row) => ({
|
|
1448
|
+
threadId: row.threadId,
|
|
1449
|
+
submissionId: row.submissionId,
|
|
1450
|
+
receiptId: row.receiptId,
|
|
1451
|
+
queueSequence: row.queueSequence
|
|
1452
|
+
});
|
|
1453
|
+
const input = (row) => {
|
|
1454
|
+
if (row.workerAdmission === void 0 || !sameOrigin(row.workerAdmission.origin, origin)) return failure(operation, "corrupt");
|
|
1455
|
+
return Effect.succeed({
|
|
1456
|
+
receipt: receipt(row),
|
|
1457
|
+
messageId: row.workerAdmission.messageId
|
|
1458
|
+
});
|
|
1459
|
+
};
|
|
1460
|
+
const submission = (submissionId) => deps.ledger.lookup(SubmissionLookupById.make({ submissionId })).pipe(Effect.mapError(storageFailure(operation)), Effect.flatMap((row) => Option.isNone(row) ? failure(operation, "corrupt") : Effect.succeed(row.value)));
|
|
1461
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
1462
|
+
const delivery = yield* pending();
|
|
1463
|
+
const control = yield* deps.ledger.inspectWorker(threadId).pipe(Effect.mapError(storageFailure(operation)));
|
|
1464
|
+
const current = yield* tail();
|
|
1465
|
+
const records = current === void 0 ? [] : yield* deps.store.read({
|
|
1466
|
+
threadId,
|
|
1467
|
+
selection: {
|
|
1468
|
+
_tag: "WorkerExecution",
|
|
1469
|
+
expectedTailSequence: current.tailSequence,
|
|
1470
|
+
expectedTailDigest: current.tailDigest
|
|
1471
|
+
},
|
|
1472
|
+
page: { limit: 2 }
|
|
1473
|
+
}).pipe(Stream.runCollect, Effect.mapError(storageFailure(operation)), Effect.catch((error) => Effect.gen(function* () {
|
|
1474
|
+
const after = yield* tail().pipe(Effect.orElseSucceed(() => current));
|
|
1475
|
+
if (after !== void 0 && (current.tailSequence !== after.tailSequence || current.tailDigest !== after.tailDigest)) return void 0;
|
|
1476
|
+
return yield* error;
|
|
1477
|
+
})));
|
|
1478
|
+
if (records === void 0) continue;
|
|
1479
|
+
const applied = records.find((entry) => entry.record.payload._tag === "UserInputRecorded");
|
|
1480
|
+
const started = records.find((entry) => entry.record.payload._tag === "RunStarted")?.record.payload;
|
|
1481
|
+
const acceptedInput = control.latest === null ? null : yield* input(control.latest);
|
|
1482
|
+
let appliedInput = null;
|
|
1483
|
+
let run = null;
|
|
1484
|
+
if (applied?.record.payload._tag === "UserInputRecorded") {
|
|
1485
|
+
const value = applied.record.payload;
|
|
1486
|
+
if (value.submissionId === void 0 || value.runId === void 0) return yield* failure(operation, "corrupt");
|
|
1487
|
+
appliedInput = {
|
|
1488
|
+
...yield* input(yield* submission(value.submissionId)),
|
|
1489
|
+
runId: value.runId,
|
|
1490
|
+
sequence: applied.sequence
|
|
1491
|
+
};
|
|
1493
1492
|
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1493
|
+
if (started?._tag === "RunStarted") {
|
|
1494
|
+
const initial = Option.getOrUndefined(yield* getRunInput({
|
|
1495
|
+
threadId,
|
|
1496
|
+
runId: started.runId
|
|
1497
|
+
}).pipe(Effect.provideService(ThreadStore, deps.store), Effect.mapError(storageFailure(operation))))?.record.payload;
|
|
1498
|
+
if (initial?._tag !== "UserInputRecorded" || initial.submissionId === void 0) return yield* failure(operation, "corrupt");
|
|
1499
|
+
const host = yield* input(yield* submission(initial.submissionId));
|
|
1500
|
+
const terminal = Option.getOrUndefined(yield* exactRecord(threadId, submissionSettlementRecordId(initial.submissionId), operation))?.record.payload;
|
|
1501
|
+
if (terminal !== void 0 && (terminal._tag !== "SubmissionSettled" || terminal.runId !== started.runId)) return yield* failure(operation, "corrupt");
|
|
1502
|
+
run = {
|
|
1503
|
+
runId: started.runId,
|
|
1504
|
+
hostReceipt: host.receipt,
|
|
1505
|
+
outcome: terminal?.outcome ?? null,
|
|
1506
|
+
disposition: terminal?.runDisposition ?? null
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
const after = yield* deps.ledger.inspectWorker(threadId).pipe(Effect.mapError(storageFailure(operation)));
|
|
1510
|
+
const afterTail = yield* tail();
|
|
1511
|
+
const afterDelivery = yield* pending();
|
|
1512
|
+
if (!Schema.toEquivalence(WorkerLedgerState)(control, after) || current?.tailSequence !== afterTail?.tailSequence || current?.tailDigest !== afterTail?.tailDigest || delivery?.key.messageId !== afterDelivery?.key.messageId || delivery?.version !== afterDelivery?.version) continue;
|
|
1513
|
+
return {
|
|
1514
|
+
worker: origin.worker,
|
|
1515
|
+
latestReceipt: acceptedInput?.receipt ?? null,
|
|
1516
|
+
state: control.terminal ?? (control.stopped ? control.active === null ? "stopped" : "stopping" : control.active !== null ? "active" : delivery !== void 0 ? "starting" : "idle"),
|
|
1517
|
+
acceptedInput,
|
|
1518
|
+
appliedInput,
|
|
1519
|
+
run,
|
|
1520
|
+
pendingDelivery: delivery === void 0 ? null : yield* deliveryStatus(delivery, operation),
|
|
1521
|
+
watermark: {
|
|
1522
|
+
canonicalSequence: current?.tailSequence ?? 0,
|
|
1523
|
+
acceptedQueueSequence: control.latest?.queueSequence ?? 0,
|
|
1524
|
+
pendingDeliveryVersion: delivery?.version ?? null
|
|
1525
|
+
}
|
|
1500
1526
|
};
|
|
1501
1527
|
}
|
|
1502
|
-
return
|
|
1503
|
-
worker: origin.worker,
|
|
1504
|
-
latestReceipt,
|
|
1505
|
-
state: active ? "active" : starting || latestReceipt === null ? "starting" : "idle"
|
|
1506
|
-
};
|
|
1528
|
+
return yield* failure(operation, "storage");
|
|
1507
1529
|
});
|
|
1508
1530
|
return {
|
|
1509
1531
|
context: Effect.gen(function* () {
|
|
@@ -1519,57 +1541,83 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1519
1541
|
yield* authorize("start", "send");
|
|
1520
1542
|
return (yield* preparedTarget(request.target, request.encodedInput)).policy;
|
|
1521
1543
|
}),
|
|
1522
|
-
start: Effect.fn("WorkerHost.start")(function* (
|
|
1544
|
+
start: Effect.fn("WorkerHost.start")(function* (command) {
|
|
1523
1545
|
const principal = yield* authorize("start", "send");
|
|
1524
1546
|
if (context.depth !== 0 && sourceSubmissionId === void 0) return yield* failure("start", "denied");
|
|
1525
|
-
const
|
|
1526
|
-
const
|
|
1527
|
-
const sourcePolicy = Option.getOrElse(prepared.source.policyOverride, () => context.policy);
|
|
1528
|
-
const grant = yield* Schema.decodeUnknownEffect(SubagentGrant)(request.encodedGrant).pipe(Effect.mapError((cause) => failure("start", "corrupt", cause)));
|
|
1547
|
+
const grant = yield* Schema.decodeUnknownEffect(SubagentGrant)(command.encodedGrant).pipe(Effect.mapError((cause) => failure("start", "corrupt", cause)));
|
|
1548
|
+
const parameters = yield* decode(PersistedJson, command.encodedParameters, "start");
|
|
1529
1549
|
const messageId = yield* messageIdFor([
|
|
1530
1550
|
context.source.threadId,
|
|
1531
|
-
|
|
1532
|
-
|
|
1551
|
+
command.delegationId,
|
|
1552
|
+
command.idempotencyKey
|
|
1533
1553
|
]);
|
|
1534
1554
|
if (Option.isNone(deps.deliveries)) return yield* failure("start", "unavailable");
|
|
1535
|
-
const
|
|
1555
|
+
const deliveries = deps.deliveries.value;
|
|
1556
|
+
const retained = () => deliveries.get({
|
|
1536
1557
|
ownerThreadId: context.source.threadId,
|
|
1537
1558
|
messageId
|
|
1538
1559
|
}).pipe(Effect.mapError(storageFailure("start")));
|
|
1539
|
-
const
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1560
|
+
const replay = (saved) => Effect.gen(function* () {
|
|
1561
|
+
const replayPrincipal = yield* authorize("start", "send");
|
|
1562
|
+
yield* binding(command.target, "start");
|
|
1563
|
+
const metadata = saved.envelope.workerAdmission;
|
|
1564
|
+
if (metadata === void 0) return yield* failure("start", "idempotency-conflict");
|
|
1565
|
+
const origin = metadata.origin;
|
|
1566
|
+
if (origin.firstMessageId !== messageId || metadata.messageId !== messageId || origin.source.threadId !== context.source.threadId || origin.worker.delegationId !== command.delegationId || origin.worker.targetAgentId !== command.target.id || !sameJson(metadata.parameters, parameters) || !Schema.toEquivalence(SubagentGrant)(origin.grant, grant) || origin.budgetScope !== command.budgetScope || origin.depth !== context.depth + 1 || !("prepare" in command) && (!samePolicy(origin.policy, command.policy) || !Schema.toEquivalence(WorkerOrigin.fields.budget)(origin.budget, command.budget) || origin.toolCallAllowance !== command.toolCallAllowance)) return yield* failure("start", "idempotency-conflict");
|
|
1567
|
+
return {
|
|
1568
|
+
worker: origin.worker,
|
|
1569
|
+
delivery: yield* send(origin, messageId, "prepare" in command ? saved.envelope.input : command.encodedInput, parameters, replayPrincipal, "start")
|
|
1570
|
+
};
|
|
1571
|
+
});
|
|
1572
|
+
const existing = yield* retained();
|
|
1573
|
+
if (existing !== null) return yield* replay(existing);
|
|
1574
|
+
return yield* Effect.gen(function* () {
|
|
1575
|
+
const request = "prepare" in command ? {
|
|
1576
|
+
...yield* command.prepare,
|
|
1577
|
+
...command
|
|
1578
|
+
} : command;
|
|
1579
|
+
const prepared = yield* preparedTarget(request.target, request.encodedInput);
|
|
1580
|
+
const resolved = prepared.resolved;
|
|
1581
|
+
const sourcePolicy = Option.getOrElse(prepared.source.policyOverride, () => context.policy);
|
|
1582
|
+
const now = yield* Clock.currentTimeMillis;
|
|
1583
|
+
const sourceBinding = prepared.source.binding;
|
|
1584
|
+
if (sourceBinding === void 0) return yield* failure("start", "declaration-unavailable");
|
|
1585
|
+
const reporting = yield* reportIntent(sourceBinding, resolved, request.delegationId, prepared.source);
|
|
1586
|
+
if (reporting?.mode === "standard" && sourceSubmissionId === void 0) return yield* failure("start", "denied");
|
|
1587
|
+
const origin = yield* decode(WorkerOrigin, {
|
|
1588
|
+
worker: {
|
|
1589
|
+
schemaVersion: 1,
|
|
1590
|
+
delegationId: request.delegationId,
|
|
1591
|
+
targetAgentId: request.target.id,
|
|
1592
|
+
threadId: Schema.decodeSync(ThreadId)(messageId)
|
|
1593
|
+
},
|
|
1594
|
+
source: context.source,
|
|
1595
|
+
...resolved.definition.runDisposition?.workerLifecycle === "assignment" ? { lifecycle: "assignment" } : {},
|
|
1596
|
+
targetDigests: resolved.digests,
|
|
1597
|
+
policy: request.policy,
|
|
1598
|
+
budget: request.budget,
|
|
1599
|
+
...request.budgetScope === void 0 ? {} : { budgetScope: request.budgetScope },
|
|
1600
|
+
grant,
|
|
1601
|
+
depth: context.depth + 1,
|
|
1602
|
+
firstMessageId: messageId,
|
|
1603
|
+
createdAtMillis: now,
|
|
1604
|
+
expiresAtMillis: now + deps.limits.lifetimeMillis,
|
|
1605
|
+
...reporting === void 0 ? {} : { reporting },
|
|
1606
|
+
...request.toolCallAllowance === void 0 ? {} : { toolCallAllowance: request.toolCallAllowance }
|
|
1607
|
+
}, "start");
|
|
1608
|
+
yield* authorizeBudget(origin, principal);
|
|
1609
|
+
const targetPolicy = Option.isSome(prepared.policy) ? prepared.policy.value : origin.budgetScope === "worker-run" ? resolved.definition.policy : AgentPolicy.resolve(resolved.definition.policyOverrides ?? resolved.definition.policy, sourcePolicy);
|
|
1610
|
+
if (!withinPolicy(origin, origin.budgetScope === "worker-run" ? targetPolicy : sourcePolicy, targetPolicy)) return yield* failure("start", "capacity");
|
|
1611
|
+
const delivery = yield* send(origin, messageId, request.encodedInput, request.encodedParameters, principal, "start");
|
|
1612
|
+
return {
|
|
1613
|
+
worker: origin.worker,
|
|
1614
|
+
delivery
|
|
1615
|
+
};
|
|
1616
|
+
}).pipe(Effect.catch((error) => Effect.gen(function* () {
|
|
1617
|
+
if (!("prepare" in command)) return yield* Effect.fail(error);
|
|
1618
|
+
const saved = yield* retained();
|
|
1619
|
+
return saved === null ? yield* Effect.fail(error) : yield* replay(saved);
|
|
1620
|
+
})));
|
|
1573
1621
|
}),
|
|
1574
1622
|
followUp: Effect.fn("WorkerHost.followUp")(function* (request) {
|
|
1575
1623
|
const principal = yield* authorize("followUp", "send", request.worker);
|
|
@@ -1614,8 +1662,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1614
1662
|
summary: Effect.fn("WorkerHost.inspectWorker")(function* (request) {
|
|
1615
1663
|
yield* authorize("inspect", "read", request.worker);
|
|
1616
1664
|
const origin = yield* findOrigin(request.worker, request.target, "inspect");
|
|
1617
|
-
|
|
1618
|
-
return yield* summarize(origin, requests(source.records), "inspect");
|
|
1665
|
+
return yield* summarize(origin, "inspect");
|
|
1619
1666
|
}),
|
|
1620
1667
|
observe: (request) => Stream.unwrap(Effect.gen(function* () {
|
|
1621
1668
|
yield* authorize("observe", "read", request.worker);
|
|
@@ -1654,15 +1701,59 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
|
|
|
1654
1701
|
yield* authorize("list", "read");
|
|
1655
1702
|
yield* binding(request.target, "list");
|
|
1656
1703
|
if (!Number.isSafeInteger(request.limit) || request.limit < 1 || request.limit > 100) return yield* failure("list", "capacity");
|
|
1657
|
-
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1660
|
-
|
|
1704
|
+
if (Option.isNone(deps.deliveries)) return yield* failure("list", "unavailable");
|
|
1705
|
+
const page = yield* deps.deliveries.value.list({
|
|
1706
|
+
ownerThreadId: context.source.threadId,
|
|
1707
|
+
limit: request.limit,
|
|
1708
|
+
workerStarts: {
|
|
1709
|
+
delegationId: request.delegationId,
|
|
1710
|
+
targetAgentId: request.target.id
|
|
1711
|
+
},
|
|
1712
|
+
...request.after === void 0 ? {} : { after: Schema.decodeSync(IdempotencyKey)(request.after) }
|
|
1713
|
+
}).pipe(Effect.mapError(storageFailure("list")));
|
|
1661
1714
|
return {
|
|
1662
|
-
items: yield* Effect.forEach(
|
|
1663
|
-
|
|
1715
|
+
items: yield* Effect.forEach(page.items, (row) => {
|
|
1716
|
+
const origin = row.envelope.workerAdmission?.origin;
|
|
1717
|
+
return origin === void 0 || origin.firstMessageId !== row.key.messageId ? failure("list", "corrupt") : summarize(origin, "list");
|
|
1718
|
+
}),
|
|
1719
|
+
next: page.next === null ? null : Schema.decodeSync(ThreadId)(page.next)
|
|
1664
1720
|
};
|
|
1665
1721
|
}),
|
|
1722
|
+
stop: Effect.fn("WorkerHost.stop")(function* (request) {
|
|
1723
|
+
const principal = yield* authorize("stop", "control", request.worker);
|
|
1724
|
+
yield* findOrigin(request.worker, request.target, "stop");
|
|
1725
|
+
if (deps.ledger.stopWorker === void 0) return yield* failure("stop", "unavailable");
|
|
1726
|
+
const command = yield* decode(WorkerStop, request, "stop");
|
|
1727
|
+
const id = Schema.decodeSync(RecordId)(`worker-stop:${yield* messageIdFor([context.source.threadId, request.idempotencyKey])}`);
|
|
1728
|
+
let retained = false;
|
|
1729
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
1730
|
+
const current = yield* deps.store.inspectTail(ThreadTailRequest.make({ threadId: context.source.threadId })).pipe(Effect.mapError(storageFailure("stop")));
|
|
1731
|
+
const prior = Option.getOrUndefined(yield* exactRecord(context.source.threadId, id, "stop"))?.record.payload;
|
|
1732
|
+
if (prior !== void 0) {
|
|
1733
|
+
if (prior._tag !== "WorkerStopRequested" || !Schema.toEquivalence(WorkerStop)(prior.command, command)) return yield* failure("stop", "idempotency-conflict");
|
|
1734
|
+
retained = true;
|
|
1735
|
+
break;
|
|
1736
|
+
}
|
|
1737
|
+
if (yield* append(context.source.threadId, id, WorkerStopRequested.make({ command }), {
|
|
1738
|
+
...current,
|
|
1739
|
+
records: []
|
|
1740
|
+
}, "stop")) {
|
|
1741
|
+
retained = true;
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
if (!retained) return yield* failure("stop", "storage");
|
|
1746
|
+
while (true) {
|
|
1747
|
+
yield* hit("worker:before-stop-seal", "stop");
|
|
1748
|
+
const owned = yield* deps.ledger.stopWorker({
|
|
1749
|
+
threadId: request.worker.threadId,
|
|
1750
|
+
author: principal
|
|
1751
|
+
}).pipe(Effect.mapError(storageFailure("stop")));
|
|
1752
|
+
yield* hit("worker:after-stop-seal", "stop");
|
|
1753
|
+
if (owned === 0) return command;
|
|
1754
|
+
yield* Effect.sleep(deps.settlementPollInterval);
|
|
1755
|
+
}
|
|
1756
|
+
}),
|
|
1666
1757
|
cancel: Effect.fn("WorkerHost.cancel")(function* (request) {
|
|
1667
1758
|
const principal = yield* authorize("cancel", "control", request.worker);
|
|
1668
1759
|
yield* receiptInput(request, "cancel");
|
|
@@ -4996,6 +5087,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
|
|
|
4996
5087
|
history: pending === void 0 ? journal.historyBefore : resumeProjection.historyBefore,
|
|
4997
5088
|
onHistory,
|
|
4998
5089
|
input,
|
|
5090
|
+
commandDrainPolicy: submission.workerAdmission === void 0 ? "one" : "all",
|
|
4999
5091
|
...journal.committedTurns > 0 || Schema.is(FrameworkMessage)(submission.messageAdmission) ? { retainedInput: submission.inputPayload } : {},
|
|
5000
5092
|
...Schema.is(FrameworkMessage)(submission.messageAdmission) ? { frameworkMessage: submission.messageAdmission } : {},
|
|
5001
5093
|
approval,
|
|
@@ -6902,4 +6994,4 @@ var DurableAgentRuntime = class DurableAgentRuntime extends Context.Service()("@
|
|
|
6902
6994
|
//#endregion
|
|
6903
6995
|
export { RecoveryBlocked as a, RecoverySweepResult as c, recoveryRepairBatchId as d, recoveryRepairRecordId as f, DurableRuntimeConfig as i, childReservationIdFor as l, threadCreatedRecordId as m, DurableAgentRuntime_exports as n, RecoveryFailure as o, threadCreatedBatchId as p, DurableApprovalResolver as r, RecoveryReport as s, DurableAgentRuntime as t, isolateRecovery as u };
|
|
6904
6996
|
|
|
6905
|
-
//# sourceMappingURL=DurableAgentRuntime-
|
|
6997
|
+
//# sourceMappingURL=DurableAgentRuntime-tNrkJZNo.mjs.map
|