effect-agent 0.1.0-beta.96 → 0.1.0-beta.98
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/{AgentRuntime-B64362Id.d.mts → AgentRuntime-BMzrJos6.d.mts} +2 -2
- package/dist/{AgentRuntime-Cdvqw7l_.mjs → AgentRuntime-BWOnNc0d.mjs} +78 -42
- package/dist/AgentRuntime-BWOnNc0d.mjs.map +1 -0
- package/dist/{DurableAgentRuntime-BGwGUIT-.mjs → DurableAgentRuntime-gF4YiEj2.mjs} +485 -262
- package/dist/DurableAgentRuntime-gF4YiEj2.mjs.map +1 -0
- package/dist/{DurableFailpoint-DQJet828.d.mts → DurableFailpoint-mx3-nsxU.d.mts} +3 -3
- package/dist/{EventSource-tCO_dAff.d.mts → EventSource-BZ73J0s5.d.mts} +3 -3
- package/dist/{PreparedInputAdmission-CFSddiT8.d.mts → PreparedInputAdmission-BkeI-Xvr.d.mts} +4 -4
- package/dist/{Records-CMByd1eD.d.mts → Records-BIiRLqlz.d.mts} +93 -101
- package/dist/{Records-BEz5IFUu.mjs → Records-DR1xtbXY.mjs} +36 -7
- package/dist/Records-DR1xtbXY.mjs.map +1 -0
- package/dist/{RunJournal-B_fxe57c.mjs → RunJournal-DNs3PM4K.mjs} +80 -23
- package/dist/RunJournal-DNs3PM4K.mjs.map +1 -0
- package/dist/{RunOptions-Clj8cLsp.d.mts → RunOptions-Bruk54SE.d.mts} +13 -4
- package/dist/{Schedule-BxCfnYr0.d.mts → Schedule-BNFlluAl.d.mts} +2 -2
- package/dist/{Scheduling-BW6BD_TP.mjs → Scheduling-HFH0pST1.mjs} +2 -2
- package/dist/{Scheduling-BW6BD_TP.mjs.map → Scheduling-HFH0pST1.mjs.map} +1 -1
- package/dist/{Subagent-Cbfzylz1.mjs → Subagent-C2s8PFrd.mjs} +2 -2
- package/dist/{Subagent-Cbfzylz1.mjs.map → Subagent-C2s8PFrd.mjs.map} +1 -1
- package/dist/{Subagent-Bm1dRecN.d.mts → Subagent-m7ywTCe4.d.mts} +3 -3
- package/dist/{Subscription-CrTIQKZR.d.mts → Subscription-BCQ3L9Zp.d.mts} +3 -3
- package/dist/{SubscriptionInput-BVOeFF1L.d.mts → SubscriptionInput-Cqu4_RW3.d.mts} +3 -3
- package/dist/{ToolReconciler-DQVaJfpE.d.mts → ToolReconciler-BmVRAHKs.d.mts} +8 -4
- package/dist/{agent-registration-BTa5vmQF.mjs → agent-registration-cXpB8cBU.mjs} +40 -95
- package/dist/agent-registration-cXpB8cBU.mjs.map +1 -0
- package/dist/capabilities/Commands.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/durable/ActivityStore.d.mts +1 -1
- package/dist/durable/ActivityStore.mjs +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/Admin.mjs +12 -10
- package/dist/durable/Admin.mjs.map +1 -1
- package/dist/durable/AgentRegistration.d.mts +2 -2
- package/dist/durable/AgentRegistration.mjs +4 -7
- package/dist/durable/AgentRegistration.mjs.map +1 -1
- package/dist/durable/Certification.d.mts +2 -2
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/CommittedActivity.mjs +1 -1
- package/dist/durable/Digest.d.mts +1 -1
- package/dist/durable/Digest.mjs +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 +2 -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/EventSource.mjs +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/GitHubWorkflowSource.mjs +1 -1
- package/dist/durable/MessageDelivery.d.mts +3 -3
- package/dist/durable/MessageDelivery.mjs +1 -1
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +39 -39
- package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
- package/dist/durable/PersistentHistory.d.mts +1 -1
- package/dist/durable/PersistentHistory.mjs +2 -2
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/Records.d.mts +2 -2
- package/dist/durable/Records.mjs +2 -2
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/Recovery.mjs +9 -9
- package/dist/durable/Recovery.mjs.map +1 -1
- package/dist/durable/RunJournal.d.mts +2 -2
- package/dist/durable/RunJournal.mjs +2 -2
- package/dist/durable/Schedule.d.mts +1 -1
- package/dist/durable/Schedule.mjs +1 -1
- package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
- package/dist/durable/ScheduleStoreConformance.mjs +1 -1
- package/dist/durable/ScheduleTransition.d.mts +1 -1
- package/dist/durable/ScheduleTransition.mjs +1 -1
- package/dist/durable/Scheduling.d.mts +2 -2
- package/dist/durable/Scheduling.mjs +1 -1
- package/dist/durable/SqlStorageV2Upgrade.d.mts +2 -2
- package/dist/durable/SqlStorageV2Upgrade.mjs +1 -1
- package/dist/durable/SqlSubscriptionStore.d.mts +2 -2
- package/dist/durable/SqlSubscriptionStore.mjs +1 -1
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs +14 -13
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +9 -2
- 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 +2 -2
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionStoreConformance.mjs +1 -1
- package/dist/durable/SubscriptionTools.d.mts +3 -3
- 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 +1 -1
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.mjs +1 -1
- package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
- package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
- package/dist/durable/ThreadInvariants.d.mts +4 -2
- package/dist/durable/ThreadInvariants.mjs +49 -3
- package/dist/durable/ThreadInvariants.mjs.map +1 -1
- package/dist/durable/ThreadProjection.d.mts +1 -1
- package/dist/durable/ThreadProjection.mjs +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +1 -1
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +1 -1
- package/dist/durable/ToolReconciler.d.mts +1 -1
- package/dist/durable/ToolReconciler.mjs +9 -5
- package/dist/durable/ToolReconciler.mjs.map +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/RunOptions.d.mts +1 -1
- package/dist/engine/RunOptions.mjs.map +1 -1
- package/dist/index.d.mts +11 -11
- package/dist/index.mjs +6 -6
- package/package.json +1 -1
- package/src/durable/Admin.ts +20 -11
- package/src/durable/AgentRegistration.ts +1 -4
- package/src/durable/DurableAgentRuntime.ts +936 -462
- package/src/durable/DurableFailpoint.ts +2 -0
- package/src/durable/Records.ts +31 -4
- package/src/durable/Recovery.ts +8 -8
- package/src/durable/RunJournal.ts +128 -51
- package/src/durable/SubmissionLedger.ts +13 -12
- package/src/durable/SubmissionLedgerConformance.ts +13 -2
- package/src/durable/ThreadInvariants.ts +70 -5
- package/src/durable/ToolReconciler.ts +7 -3
- package/src/durable/internal/agent-registration.ts +77 -188
- package/src/durable/internal/messaging-host.ts +1 -6
- package/src/durable/internal/worker-host.ts +88 -116
- package/src/engine/RunOptions.ts +13 -3
- package/src/engine/internal/agent-runtime.ts +160 -106
- package/dist/AgentRuntime-Cdvqw7l_.mjs.map +0 -1
- package/dist/DurableAgentRuntime-BGwGUIT-.mjs.map +0 -1
- package/dist/Records-BEz5IFUu.mjs.map +0 -1
- package/dist/RunJournal-B_fxe57c.mjs.map +0 -1
- package/dist/agent-registration-BTa5vmQF.mjs.map +0 -1
|
@@ -13,7 +13,7 @@ import { n as WorkerBudgetScope } from "./Worker--j87JI__.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-
|
|
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-Bruk54SE.mjs";
|
|
17
17
|
import { t as MessagingHost } from "./MessagingHost-gAxs5gme.mjs";
|
|
18
18
|
import { i as SubagentHost } from "./SubagentHost-DaFMZnVR.mjs";
|
|
19
19
|
import { t as RunEventSink } from "./RunEventSink-D5aVhISG.mjs";
|
|
@@ -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-BMzrJos6.d.mts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { ReceiptId, RunId, SubmissionId, ThreadId, ToolCallId } from "./core/Identifiers.mjs";
|
|
3
3
|
import { n as utf8ByteLength } from "./utf8-DchGZRBd.mjs";
|
|
4
|
-
import { ToolParameterRejection, applyToolResultBounds, unserializableToolResult } from "./core/ToolResult.mjs";
|
|
4
|
+
import { ToolParameterRejection, TruncatedToolResult, applyToolResultBounds, unserializableToolResult } from "./core/ToolResult.mjs";
|
|
5
5
|
import { IdempotencyKey } from "./core/Receipt.mjs";
|
|
6
6
|
import { Emitter, Update, UpdateError } from "./core/AgentUpdates.mjs";
|
|
7
7
|
import { AgentApprovalDenied, AgentApprovalPending, AgentInputError, AgentOutputError, AgentPolicyError, AgentRunDispositionError, AgentToolAuthorizationDenied, ContextBudgetError, ContextOverflowError, ModelProtocolError } from "./core/AgentError.mjs";
|
|
@@ -799,6 +799,8 @@ const modelCounter = Metric.counter("effect_agent_model_calls_total", { descript
|
|
|
799
799
|
const toolCounter = Metric.counter("effect_agent_tool_calls_total", { description: "Agent tool handlers started; no content or high-cardinality identifiers are recorded." });
|
|
800
800
|
const MAX_STAGED_PROVIDER_EVENTS = 256;
|
|
801
801
|
const MAX_STAGED_PROVIDER_BYTES = 1048576;
|
|
802
|
+
/** Saved outcomes obey the canonical JSON ceiling, independently of today's display policy. */
|
|
803
|
+
const MAX_RESUMED_RESULT_BYTES = 1048576;
|
|
802
804
|
const DEFAULT_RUN_BUFFER_LIMITS = {
|
|
803
805
|
maxModelResponseParts: 16384,
|
|
804
806
|
maxModelResponseBytes: 8388608,
|
|
@@ -1004,7 +1006,7 @@ const effectiveRunBounds = (policy, options) => ({
|
|
|
1004
1006
|
maxTurns: boundedAllowance(policy.maxTurns, options.turnAllowance),
|
|
1005
1007
|
maxToolCalls: boundedAllowance(policy.maxToolCalls, options.toolCallAllowance)
|
|
1006
1008
|
});
|
|
1007
|
-
const decodeResumedSettledCall = Effect.fn("AgentRuntime.decodeResumedSettledCall")((input
|
|
1009
|
+
const decodeResumedSettledCall = Effect.fn("AgentRuntime.decodeResumedSettledCall")((input) => Effect.gen(function* () {
|
|
1008
1010
|
const raw = yield* Effect.try({
|
|
1009
1011
|
try: () => {
|
|
1010
1012
|
if (input === null || typeof input !== "object") throw new TypeError("settled Tool Call must be an object");
|
|
@@ -1027,7 +1029,7 @@ const decodeResumedSettledCall = Effect.fn("AgentRuntime.decodeResumedSettledCal
|
|
|
1027
1029
|
},
|
|
1028
1030
|
catch: () => ModelProtocolError.make({ message: "Turn resume contains an invalid settled Tool Call" })
|
|
1029
1031
|
});
|
|
1030
|
-
const result = boundedCanonicalJsonSnapshot(raw.result,
|
|
1032
|
+
const result = boundedCanonicalJsonSnapshot(raw.result, MAX_RESUMED_RESULT_BYTES);
|
|
1031
1033
|
if (result === void 0) return yield* ModelProtocolError.make({ message: "Turn resume settled Tool result is not bounded canonical JSON" });
|
|
1032
1034
|
return yield* Schema.decodeUnknownEffect(RunTurnResumeSettledCallSchema)({
|
|
1033
1035
|
...raw,
|
|
@@ -1579,7 +1581,10 @@ const executeToolBatch = (context, turnId, turn, toolkit, calls, trace, concurre
|
|
|
1579
1581
|
const visibility = yield* RunToolVisibility;
|
|
1580
1582
|
const eligible = new Set(context.toolCatalog.filter((entry) => entry.kind === "native").map((entry) => entry.nativeToolName));
|
|
1581
1583
|
if (calls.some((call) => exposed !== void 0 && !exposed.includes(call.name) || visibility !== void 0 && !settledCallIds?.has(call.id) && !eligible.has(call.name))) return yield* ModelProtocolError.make({ message: "Tool batch calls a Tool outside its request exposure or current visibility" });
|
|
1582
|
-
const prepared = yield* Effect.forEach(calls
|
|
1584
|
+
const prepared = yield* Effect.forEach(calls.flatMap((call, declarationIndex) => settledCallIds?.has(call.id) ? [] : [{
|
|
1585
|
+
call,
|
|
1586
|
+
declarationIndex
|
|
1587
|
+
}]), ({ call, declarationIndex }) => prepareToolCall(toolkit, call, declarationIndex, trace.toolParameterRejections.get(call.id)));
|
|
1583
1588
|
if (prepared.some((call) => Context.get(call.tool.annotations, ContextRolloverTool)) && trace.toolCalls.size !== 1) return yield* ModelProtocolError.make({ message: "A context rollover Tool must be the only Tool Call in its batch" });
|
|
1584
1589
|
const semaphore = yield* Semaphore.make(concurrency);
|
|
1585
1590
|
const approvalPreflight = prepared.reduce((stream, call) => stream.pipe(Stream.concat(preflightApproval(context, turnId, call, options))), Stream.empty);
|
|
@@ -3333,12 +3338,12 @@ const toolBatchContinuation = (agent, context, trace, prompt, turn, toolCalls, o
|
|
|
3333
3338
|
yield* advanceHistory(context, history, options);
|
|
3334
3339
|
yield* applyRepeatedFailurePolicy(context, trace, agent.definition.policy.repeatedFailureLimit);
|
|
3335
3340
|
const rolloverResult = orderedResults.length === 1 ? orderedResults[0] : void 0;
|
|
3336
|
-
if (rolloverResult !== void 0 && !rolloverResult.isFailure && hasTool(agent.definition.toolkit.tools, rolloverResult.name) && Context.get(agent.definition.toolkit.tools[rolloverResult.name].annotations, ContextRolloverTool)) context.pendingContextToolCallId = rolloverResult.id;
|
|
3341
|
+
if (rolloverResult !== void 0 && !rolloverResult.isFailure && trace.applicationCallDescriptors.some((call) => call.toolCallId === rolloverResult.id) && hasTool(agent.definition.toolkit.tools, rolloverResult.name) && Context.get(agent.definition.toolkit.tools[rolloverResult.name].annotations, ContextRolloverTool)) context.pendingContextToolCallId = rolloverResult.id;
|
|
3337
3342
|
const completion = agent.definition.completion;
|
|
3338
3343
|
const successfulResult = trace.applicationToolCalls.length === 1 && orderedResults.length === 1 && orderedResults[0]?.isFailure === false ? orderedResults[0] : void 0;
|
|
3339
3344
|
const actionCompletion = agent.definition.completionFromTools?.find((declaration) => declaration.tool === successfulResult?.name);
|
|
3340
3345
|
let selectedOutput = Option.none();
|
|
3341
|
-
if (successfulResult !== void 0 && (successfulResult.name === completion?.tool || actionCompletion !== void 0)) {
|
|
3346
|
+
if (successfulResult !== void 0 && trace.applicationCallDescriptors.some((call) => call.toolCallId === successfulResult.id) && (successfulResult.name === completion?.tool || actionCompletion !== void 0)) {
|
|
3342
3347
|
const call = trace.applicationCallDescriptors[0];
|
|
3343
3348
|
if (call === void 0) return failRunEventStream(ModelProtocolError.make({ message: "Completion Tool has no canonical call descriptor" }));
|
|
3344
3349
|
if (actionCompletion !== void 0) selectedOutput = yield* projectCompletionFromToolOutput(agent, actionCompletion, call.parameters, successfulResult.encodedResult);
|
|
@@ -3370,21 +3375,21 @@ const toolBatchContinuation = (agent, context, trace, prompt, turn, toolCalls, o
|
|
|
3370
3375
|
* Resume one canonically declared Tool batch without re-invoking the model
|
|
3371
3376
|
* (the durable batch-resume seam consumed via `RunOptions.resume`).
|
|
3372
3377
|
*
|
|
3373
|
-
*
|
|
3374
|
-
*
|
|
3375
|
-
*
|
|
3376
|
-
*
|
|
3377
|
-
* Calls listed in `settled` are injected as final results without starting
|
|
3378
|
-
* their handlers — recorded Tool outcomes never rerun — while approval
|
|
3379
|
-
* preflight and durable preparation still cover the complete declared batch.
|
|
3378
|
+
* Only unfinished calls are validated through their current parameter Schemas before
|
|
3379
|
+
* execution. Settled siblings retain bounded canonical JSON without looking up old Tools.
|
|
3380
|
+
* The original response and declaration order remain intact; approval, authorization and
|
|
3381
|
+
* durable preparation cover only calls that can still execute.
|
|
3380
3382
|
* No model request is made and no usage is consumed for the resumed Turn.
|
|
3381
3383
|
*/
|
|
3382
3384
|
const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, options) => Stream.unwrap(Effect.gen(function* () {
|
|
3383
3385
|
const tools = agent.definition.toolkit.tools;
|
|
3384
3386
|
const turn = resume.turn;
|
|
3385
3387
|
const turnId = resume.turnId;
|
|
3388
|
+
const settledInputs = yield* snapshotResumedSettledCalls(resume, resume.calls.length);
|
|
3389
|
+
const settledCalls = yield* Effect.forEach(settledInputs, decodeResumedSettledCall);
|
|
3390
|
+
const recordedSettledIds = new Set(settledCalls.map((call) => call.id));
|
|
3386
3391
|
const visibility = yield* RunToolVisibility;
|
|
3387
|
-
if (resume.toolExposure === void 0 && (agent.definition.toolExposure !== void 0 || context.toolSelection !== void 0 || visibility !== void 0)) return yield* ModelProtocolError.make({ message: "Resumed progressive Turn is missing its original Tool exposure" });
|
|
3392
|
+
if (resume.toolExposure === void 0 && resume.calls.some((call) => !call.providerExecuted && !recordedSettledIds.has(call.id)) && (agent.definition.toolExposure !== void 0 || context.toolSelection !== void 0 || visibility !== void 0)) return yield* ModelProtocolError.make({ message: "Resumed progressive Turn is missing its original Tool exposure" });
|
|
3388
3393
|
context.toolCatalog = yield* eligibleCatalog(agent.definition, {
|
|
3389
3394
|
threadId: context.threadId,
|
|
3390
3395
|
runId: context.runId,
|
|
@@ -3394,10 +3399,11 @@ const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, option
|
|
|
3394
3399
|
context.toolExposure = resume.toolExposure === void 0 ? void 0 : yield* decodeSnapshot(resume.toolExposure);
|
|
3395
3400
|
const originalExposure = context.toolExposure;
|
|
3396
3401
|
if (originalExposure !== void 0) {
|
|
3397
|
-
yield* validateSelection({ toolNames: originalExposure.exposedToolNames }, agent.definition, context.toolCatalog, false);
|
|
3398
|
-
if (originalExposure.selection !== void 0) yield* validateSelection(originalExposure.selection, agent.definition, context.toolCatalog, false);
|
|
3399
3402
|
if (resume.calls.some((call) => !originalExposure.exposedToolNames.includes(call.name))) return yield* ModelProtocolError.make({ message: "Resumed Tool call was not exposed in its original model request" });
|
|
3400
|
-
context.toolSelection = originalExposure.selection
|
|
3403
|
+
context.toolSelection = originalExposure.selection === void 0 ? void 0 : {
|
|
3404
|
+
...originalExposure.selection,
|
|
3405
|
+
toolNames: originalExposure.selection.toolNames.filter((name) => hasTool(tools, name))
|
|
3406
|
+
};
|
|
3401
3407
|
}
|
|
3402
3408
|
if (!Number.isInteger(turn) || turn <= 0) return failRunEventStream(ModelProtocolError.make({ message: "Turn resume requires a positive integer turn number" }));
|
|
3403
3409
|
if (resume.calls.length === 0) return failRunEventStream(ModelProtocolError.make({ message: "Turn resume requires at least one declared Tool Call" }));
|
|
@@ -3428,17 +3434,23 @@ const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, option
|
|
|
3428
3434
|
const sameJson = Schema.toEquivalence(Schema.Json);
|
|
3429
3435
|
for (const rejection of rejections) {
|
|
3430
3436
|
const call = resume.calls.find((call) => call.id === rejection.toolCallId);
|
|
3431
|
-
if (call === void 0 || call.providerExecuted || call.name !== rejection.error.reason.toolName || !sameJson(yield* decodeEventJson(call.params, "Tool parameters"), rejection.parameters) || trace.toolParameterRejections.has(call.id)
|
|
3432
|
-
const validation = yield* Effect.result(decodeToolCallParameters(tools[call.name], call.name, call.params, "resume"));
|
|
3433
|
-
if (Result.isSuccess(validation)) return yield* ModelProtocolError.make({ message: "Recorded parameter rejection contains valid arguments on resume" });
|
|
3437
|
+
if (call === void 0 || call.providerExecuted || call.name !== rejection.error.reason.toolName || !sameJson(yield* decodeEventJson(call.params, "Tool parameters"), rejection.parameters) || trace.toolParameterRejections.has(call.id)) return yield* ModelProtocolError.make({ message: "Parameter rejection does not match recorded Tool Call on resume" });
|
|
3434
3438
|
trace.toolParameterRejections.set(call.id, rejection);
|
|
3439
|
+
if (!recordedSettledIds.has(call.id)) {
|
|
3440
|
+
settledCalls.push({
|
|
3441
|
+
id: call.id,
|
|
3442
|
+
isFailure: true,
|
|
3443
|
+
result: yield* decodeEventJson(boundEncodedToolResult(rejection.error, agent.definition.policy.toolResultBounds), "Rejected Tool result")
|
|
3444
|
+
});
|
|
3445
|
+
recordedSettledIds.add(call.id);
|
|
3446
|
+
}
|
|
3435
3447
|
}
|
|
3436
3448
|
for (const call of resume.calls) {
|
|
3437
|
-
if (!hasTool(tools, call.name)) return failRunEventStream(ModelProtocolError.make({ message: `Turn resume declared unknown Tool ${call.name}` }));
|
|
3449
|
+
if (!recordedSettledIds.has(call.id) && !hasTool(tools, call.name)) return failRunEventStream(ModelProtocolError.make({ message: `Turn resume declared unknown unfinished Tool ${call.name}` }));
|
|
3438
3450
|
if (trace.toolCalls.has(call.id)) return failRunEventStream(ModelProtocolError.make({ message: `Turn resume repeated Tool Call ID ${call.id}` }));
|
|
3439
3451
|
const tool = tools[call.name];
|
|
3440
3452
|
const toolCallId = yield* decodeToolCallId(call.id);
|
|
3441
|
-
if (!
|
|
3453
|
+
if (!recordedSettledIds.has(call.id)) yield* decodeToolCallParameters(tool, call.name, call.params, "resume");
|
|
3442
3454
|
const parameters = yield* decodeEventJson(call.params, "Tool parameters");
|
|
3443
3455
|
const providerExecuted = call.providerExecuted === true;
|
|
3444
3456
|
declarationByCallId.set(call.id, {
|
|
@@ -3463,7 +3475,7 @@ const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, option
|
|
|
3463
3475
|
params: parameters,
|
|
3464
3476
|
providerExecuted: false
|
|
3465
3477
|
}));
|
|
3466
|
-
trace.applicationCallDescriptors.push({
|
|
3478
|
+
if ((!recordedSettledIds.has(call.id) || resume.settledCompletion === call.id) && hasTool(tools, call.name)) trace.applicationCallDescriptors.push({
|
|
3467
3479
|
toolCallId,
|
|
3468
3480
|
toolName: call.name,
|
|
3469
3481
|
parameters,
|
|
@@ -3472,18 +3484,18 @@ const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, option
|
|
|
3472
3484
|
});
|
|
3473
3485
|
}
|
|
3474
3486
|
const completionTool = agent.definition.completion?.tool;
|
|
3475
|
-
const
|
|
3476
|
-
|
|
3477
|
-
|
|
3487
|
+
const completionCandidates = trace.applicationToolCalls.filter((call) => !recordedSettledIds.has(call.id) || resume.settledCompletion === call.id);
|
|
3488
|
+
const actionCompletionCall = completionCandidates.find((call) => agent.definition.completionFromTools?.some((declaration) => declaration.tool === call.name));
|
|
3489
|
+
if ((actionCompletionCall !== void 0 || completionTool !== void 0 && completionCandidates.some((call) => call.name === completionTool)) && trace.applicationToolCalls.length !== 1) return failRunEventStream(ModelProtocolError.make({ message: "A completion Tool must be the only application Tool Call in its batch" }));
|
|
3490
|
+
const completionBatch = completionTool !== void 0 && trace.applicationToolCalls.length === 1 && completionCandidates[0]?.name === completionTool;
|
|
3478
3491
|
if (completionBatch && completionTool !== void 0 && Context.get(tools[completionTool].annotations, ContextRolloverTool) || actionCompletionCall !== void 0 && Context.get(tools[actionCompletionCall.name].annotations, ContextRolloverTool)) return failRunEventStream(ModelProtocolError.make({ message: "A context rollover Tool cannot complete the Run" }));
|
|
3479
3492
|
if (context.finalizationUsed && (!completionBatch || trace.toolCalls.size !== 1)) return failRunEventStream(ModelProtocolError.make({ message: "A resumed grace finalization may only execute the completion Tool" }));
|
|
3480
3493
|
const settledIds = /* @__PURE__ */ new Set();
|
|
3481
|
-
|
|
3482
|
-
const settledInputs = yield* snapshotResumedSettledCalls(resume, declarationByCallId.size);
|
|
3483
|
-
for (const settledInput of settledInputs) {
|
|
3484
|
-
const settledCall = yield* decodeResumedSettledCall(settledInput, agent.definition.policy.toolResultBounds.maxBytes, providerCallIds);
|
|
3494
|
+
for (const settledCall of settledCalls) {
|
|
3485
3495
|
const rejection = trace.toolParameterRejections.get(settledCall.id);
|
|
3486
|
-
|
|
3496
|
+
const rejectionJson = rejection === void 0 ? void 0 : JSON.stringify(rejection.error);
|
|
3497
|
+
const matchesRejection = rejection === void 0 || sameJson(settledCall.result, rejection.error) || Schema.is(Schema.toEncoded(TruncatedToolResult))(settledCall.result) && rejectionJson !== void 0 && settledCall.result.originalBytes === utf8ByteLength(rejectionJson) && rejectionJson.startsWith(settledCall.result.head) && rejectionJson.endsWith(settledCall.result.tail);
|
|
3498
|
+
if (rejection !== void 0 && (!settledCall.isFailure || settledCall.toolSelection !== void 0 || settledCall.budgetRejected !== true && !matchesRejection)) return yield* ModelProtocolError.make({ message: "Settled result contradicts parameter rejection on resume" });
|
|
3487
3499
|
const declared = declarationByCallId.get(settledCall.id);
|
|
3488
3500
|
if (declared === void 0) return failRunEventStream(ModelProtocolError.make({ message: `Turn resume settled an undeclared Tool Call ${settledCall.id}` }));
|
|
3489
3501
|
if (settledIds.has(settledCall.id)) return failRunEventStream(ModelProtocolError.make({ message: `Turn resume settled Tool Call ${settledCall.id} more than once` }));
|
|
@@ -3502,7 +3514,10 @@ const makeResumeTurn = (agent, context, prompt, resume, countedToolCalls, option
|
|
|
3502
3514
|
continue;
|
|
3503
3515
|
}
|
|
3504
3516
|
trace.applicationToolResults[declared.index] = {
|
|
3505
|
-
...settledCall.toolSelection === void 0 ? {} : { toolSelection:
|
|
3517
|
+
...settledCall.toolSelection === void 0 ? {} : { toolSelection: {
|
|
3518
|
+
...settledCall.toolSelection,
|
|
3519
|
+
toolNames: settledCall.toolSelection.toolNames.filter((name) => hasTool(tools, name))
|
|
3520
|
+
} },
|
|
3506
3521
|
id: settledCall.id,
|
|
3507
3522
|
name: declared.name,
|
|
3508
3523
|
encodedResult: settledCall.result,
|
|
@@ -3719,22 +3734,43 @@ function streamWithCompletion(agentValue, input, runOptions = {}, onCompleted, o
|
|
|
3719
3734
|
return yield* eventBase(context).pipe(Effect.map((base) => RunStarted.make(base)));
|
|
3720
3735
|
}).pipe(Effect.withLogSpan("AgentRuntime.run")));
|
|
3721
3736
|
const execution = Stream.unwrap(Effect.gen(function* () {
|
|
3722
|
-
const
|
|
3723
|
-
|
|
3724
|
-
|
|
3737
|
+
const initial = yield* Effect.gen(function* () {
|
|
3738
|
+
if (options.retainedInput !== void 0) {
|
|
3739
|
+
const encodedInput = yield* Schema.decodeEffect(Schema.Json)(options.retainedInput).pipe(Effect.mapError((cause) => AgentInputError.make({ message: `Invalid retained Agent input: ${cause.message}` })));
|
|
3740
|
+
const source = agent.definition.instructions;
|
|
3741
|
+
return {
|
|
3742
|
+
instructions: typeof source === "function" ? yield* evaluateInstructions(source, yield* decodeInput(agent, encodedInput)) : yield* evaluateInstructions(source, void 0),
|
|
3743
|
+
encodedInput,
|
|
3744
|
+
inputPrompt: yield* renderInputPrompt(void 0, void 0, encodedInput)
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
const decodedInput = yield* decodeInput(agent, input);
|
|
3748
|
+
const instructions = yield* evaluateInstructions(agent.definition.instructions, decodedInput);
|
|
3749
|
+
const encodedInput = yield* encodeInput(agent, decodedInput);
|
|
3750
|
+
return {
|
|
3751
|
+
instructions,
|
|
3752
|
+
encodedInput,
|
|
3753
|
+
inputPrompt: options.frameworkMessage === void 0 ? yield* renderInputPrompt(agent.definition.inputPrompt, decodedInput, encodedInput) : void 0
|
|
3754
|
+
};
|
|
3755
|
+
});
|
|
3756
|
+
const { instructions, encodedInput } = initial;
|
|
3725
3757
|
context.input = encodedInput;
|
|
3726
3758
|
if (retained !== void 0) yield* retained.stageInput(encodedInput);
|
|
3727
|
-
const inputPrompt = options.frameworkMessage === void 0 ?
|
|
3759
|
+
const inputPrompt = options.frameworkMessage === void 0 ? initial.inputPrompt ?? "" : yield* Schema.encodeEffect(Schema.fromJsonString(FrameworkMessage))(options.frameworkMessage).pipe(Effect.mapError(() => AgentInputError.make({ message: "Invalid worker message" })));
|
|
3728
3760
|
const priorHistoryLength = context.history.content.length;
|
|
3729
3761
|
const prompt = yield* makeInitialPrompt(instructions, inputPrompt, context.history);
|
|
3730
3762
|
if (options.context === void 0) {
|
|
3731
3763
|
context.compaction.protectedStart = priorHistoryLength;
|
|
3732
3764
|
context.compaction.protectedEnd = prompt.content.length;
|
|
3733
|
-
} else
|
|
3734
|
-
|
|
3735
|
-
protectedMessages
|
|
3736
|
-
|
|
3737
|
-
|
|
3765
|
+
} else {
|
|
3766
|
+
const currentPrefix = prompt.content.slice(priorHistoryLength);
|
|
3767
|
+
const protectedMessages = options.protectedContext === void 0 ? currentPrefix : [...currentPrefix.filter((message) => message.role === "system"), ...options.protectedContext.content.filter((message) => message.role !== "system")];
|
|
3768
|
+
context.preparedCompactionSource = {
|
|
3769
|
+
protectedReferences: protectedMessages,
|
|
3770
|
+
protectedMessages: yield* snapshotCompactionMessages(protectedMessages),
|
|
3771
|
+
prefix: []
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3738
3774
|
yield* advanceHistory(context, prompt, options);
|
|
3739
3775
|
let pending;
|
|
3740
3776
|
if (resumed !== void 0) pending = {
|
|
@@ -4651,4 +4687,4 @@ var AgentRuntime_exports = /* @__PURE__ */ __exportAll({
|
|
|
4651
4687
|
//#endregion
|
|
4652
4688
|
export { stream as _, SubagentDurability as a, withTerminalDefectEvent as b, decodeFinalOutput as c, projectCompletionOutput as d, renderInputPrompt as f, startUnknown as g, start as h, AgentSpawner as i, encodeRunDisposition as l, runUnknown as m, AgentChildPending as n, SubagentDurabilityError as o, run as p, AgentResultSchema as r, ToolCallWaiting as s, AgentRuntime_exports as t, projectCompletionFromToolOutput as u, streamUnknown as v, streamWithUsageAccountingUnknown as y };
|
|
4653
4689
|
|
|
4654
|
-
//# sourceMappingURL=AgentRuntime-
|
|
4690
|
+
//# sourceMappingURL=AgentRuntime-BWOnNc0d.mjs.map
|