effect-agent 0.1.0-beta.103 → 0.1.0-beta.106
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-CM6JubNX.d.mts → Agent-Bk-mLtov.d.mts} +2 -2
- package/dist/{AgentError-CggcAQ7V.d.mts → AgentError-Bn1ytXRD.d.mts} +20 -4
- package/dist/{AgentRuntime-B1SXMVN7.d.mts → AgentRuntime-BEXToYl1.d.mts} +8 -8
- package/dist/{AgentRuntime-BWOnNc0d.mjs → AgentRuntime-e2M5UoXn.mjs} +4 -3
- package/dist/AgentRuntime-e2M5UoXn.mjs.map +1 -0
- package/dist/{DurableAgentRuntime-C9eRZS9N.mjs → DurableAgentRuntime-wd1x0TcB.mjs} +67 -36
- package/dist/DurableAgentRuntime-wd1x0TcB.mjs.map +1 -0
- package/dist/{EventSource-K7XUzurY.d.mts → EventSource-pH-v0k42.d.mts} +3 -3
- package/dist/FailureDiagnostic-BElLOoED.mjs +274 -0
- package/dist/FailureDiagnostic-BElLOoED.mjs.map +1 -0
- package/dist/FailureDiagnostic-CaAkzGHL.d.mts +223 -0
- package/dist/{Messaging-QMYhp297.d.mts → Messaging-Bl4SBKpR.d.mts} +3 -3
- package/dist/{MessagingHost-gAxs5gme.d.mts → MessagingHost-nwBMdRoh.d.mts} +3 -3
- package/dist/{Output-CjocJzsl.d.mts → Output-B6RQ5jRU.d.mts} +2 -2
- package/dist/{PreparedInputAdmission-KLk5rGFI.d.mts → PreparedInputAdmission-D3-BgmA9.d.mts} +8 -4
- package/dist/{Records-Bidb7ByL.d.mts → Records-B4S02MX1.d.mts} +201 -14
- package/dist/{RunJournal-srpbEBEy.mjs → RunJournal-BdIlgAEj.mjs} +2 -2
- package/dist/{RunJournal-srpbEBEy.mjs.map → RunJournal-BdIlgAEj.mjs.map} +1 -1
- package/dist/{RunOptions-Bruk54SE.d.mts → RunOptions-qOcPv08p.d.mts} +10 -5
- package/dist/{Schedule-Cy9up8Uf.d.mts → Schedule-D2TVEu3W.d.mts} +7 -2
- package/dist/{Scheduling-CHCsSCGo.mjs → Scheduling-DPb2QyAK.mjs} +2 -2
- package/dist/{Scheduling-CHCsSCGo.mjs.map → Scheduling-DPb2QyAK.mjs.map} +1 -1
- package/dist/{Subagent-DP0CzO16.d.mts → Subagent-BxuDuCHt.d.mts} +172 -8
- package/dist/{Subagent-C2s8PFrd.mjs → Subagent-uXWHXiKb.mjs} +64 -29
- package/dist/Subagent-uXWHXiKb.mjs.map +1 -0
- package/dist/{SubagentHost-CYcxkpRc.d.mts → SubagentHost-DEPw4YME.d.mts} +6 -3
- package/dist/{Subscription-CHyoQelH.d.mts → Subscription-nX0rz4GQ.d.mts} +3 -3
- package/dist/{SubscriptionInput-DqrHW-Ja.d.mts → SubscriptionInput-CAG3_pyJ.d.mts} +3 -3
- package/dist/{Worker--j87JI__.d.mts → Worker-Bbj9uq5H.d.mts} +5 -2
- package/dist/{agent-registration-ByeHejH3.mjs → agent-registration-B5CI-Ygk.mjs} +7 -5
- package/dist/agent-registration-B5CI-Ygk.mjs.map +1 -0
- package/dist/capabilities/Commands.d.mts +1 -1
- package/dist/capabilities/Messaging.d.mts +2 -2
- package/dist/capabilities/RunHooks.d.mts +1 -1
- package/dist/capabilities/Subagent.d.mts +2 -2
- package/dist/capabilities/Subagent.mjs +1 -1
- package/dist/core/Agent.d.mts +1 -1
- package/dist/core/AgentError.d.mts +2 -2
- package/dist/core/AgentError.mjs +19 -2
- package/dist/core/AgentError.mjs.map +1 -1
- package/dist/core/FailureDiagnostic.d.mts +2 -0
- package/dist/core/FailureDiagnostic.mjs +2 -0
- package/dist/core/Worker.d.mts +1 -1
- package/dist/core/Worker.mjs +4 -1
- package/dist/core/Worker.mjs.map +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 +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 +1 -1
- package/dist/durable/Digest.d.mts +1 -1
- package/dist/durable/Digest.mjs +7 -7
- package/dist/durable/Digest.mjs.map +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +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 +15 -3
- package/dist/durable/MessageDelivery.mjs +44 -24
- package/dist/durable/MessageDelivery.mjs.map +1 -1
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +4 -1
- 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/PreparedInputAdmission.mjs +8 -4
- package/dist/durable/PreparedInputAdmission.mjs.map +1 -1
- package/dist/durable/Records.d.mts +1 -1
- package/dist/durable/Records.mjs +831 -2
- package/dist/durable/Records.mjs.map +1 -0
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/Recovery.mjs +1 -1
- package/dist/durable/RunJournal.d.mts +1 -1
- package/dist/durable/RunJournal.mjs +1 -1
- package/dist/durable/Schedule.d.mts +1 -1
- package/dist/durable/Schedule.mjs +12 -3
- package/dist/durable/Schedule.mjs.map +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/SqlMessageDeliveryStore.mjs +13 -11
- package/dist/durable/SqlMessageDeliveryStore.mjs.map +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/SqlThreadNativeReads.d.mts +1 -1
- package/dist/durable/SqlThreadNativeReads.mjs +2 -2
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs +6 -3
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +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 +1 -1
- package/dist/durable/ThreadInvariants.mjs +2 -2
- 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 +2 -2
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +1 -1
- package/dist/durable/ToolReconciler.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +3 -3
- 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/Output.d.mts +1 -1
- package/dist/engine/RunOptions.d.mts +1 -1
- package/dist/engine/RunOptions.mjs +2 -0
- package/dist/engine/RunOptions.mjs.map +1 -1
- package/dist/engine/SubagentHost.d.mts +1 -1
- package/dist/engine/SubagentHost.mjs.map +1 -1
- package/dist/index.d.mts +18 -17
- package/dist/index.mjs +8 -7
- package/package.json +1 -1
- package/src/capabilities/internal/subagent-background.ts +66 -23
- package/src/capabilities/internal/subagent-contract.ts +4 -0
- package/src/core/AgentError.ts +20 -0
- package/src/core/FailureDiagnostic.ts +343 -0
- package/src/core/Worker.ts +4 -1
- package/src/durable/Digest.ts +22 -28
- package/src/durable/DurableAgentRuntime.ts +37 -13
- package/src/durable/MessageDelivery.ts +82 -24
- package/src/durable/PreparedInputAdmission.ts +17 -4
- package/src/durable/Records.ts +5 -15
- package/src/durable/Schedule.ts +11 -2
- package/src/durable/SqlMessageDeliveryStore.ts +21 -9
- package/src/durable/SubmissionLedger.ts +4 -1
- package/src/durable/internal/agent-registration.ts +46 -14
- package/src/durable/internal/worker-host.ts +32 -19
- package/src/engine/RunOptions.ts +11 -3
- package/src/engine/SubagentHost.ts +3 -0
- package/src/engine/internal/agent-runtime.ts +23 -16
- package/src/index.ts +1 -0
- package/dist/AgentRuntime-BWOnNc0d.mjs.map +0 -1
- package/dist/DurableAgentRuntime-C9eRZS9N.mjs.map +0 -1
- package/dist/Records-D8167fHn.mjs +0 -844
- package/dist/Records-D8167fHn.mjs.map +0 -1
- package/dist/Subagent-C2s8PFrd.mjs.map +0 -1
- package/dist/agent-registration-ByeHejH3.mjs.map +0 -1
|
@@ -122,10 +122,14 @@ import {
|
|
|
122
122
|
} from "./agent-registration.ts";
|
|
123
123
|
import { lastWorkerReportMessageId } from "./agent-updates.ts";
|
|
124
124
|
|
|
125
|
-
const failure = (
|
|
126
|
-
WorkerError
|
|
125
|
+
const failure = (
|
|
126
|
+
operation: WorkerError["operation"],
|
|
127
|
+
reason: WorkerError["reason"],
|
|
128
|
+
cause?: unknown,
|
|
129
|
+
) => WorkerError.make({ operation, reason, ...(cause === undefined ? {} : { cause }) });
|
|
127
130
|
|
|
128
|
-
const storageFailure = (operation: WorkerError["operation"]) => () =>
|
|
131
|
+
const storageFailure = (operation: WorkerError["operation"]) => (cause: unknown) =>
|
|
132
|
+
failure(operation, "storage", cause);
|
|
129
133
|
|
|
130
134
|
const decode = <S extends Schema.Top>(
|
|
131
135
|
schema: S,
|
|
@@ -133,7 +137,7 @@ const decode = <S extends Schema.Top>(
|
|
|
133
137
|
operation: WorkerError["operation"],
|
|
134
138
|
) =>
|
|
135
139
|
Schema.decodeUnknownEffect(Schema.toType(schema))(value).pipe(
|
|
136
|
-
Effect.mapError(() => failure(operation, "corrupt")),
|
|
140
|
+
Effect.mapError((cause) => failure(operation, "corrupt", cause)),
|
|
137
141
|
);
|
|
138
142
|
|
|
139
143
|
const sameOrigin = Schema.toEquivalence(WorkerOrigin);
|
|
@@ -837,7 +841,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
837
841
|
// framework message carries the new information independently of the current input codec.
|
|
838
842
|
if (!retainedFrameworkInput)
|
|
839
843
|
yield* Schema.decodeEffect(Schema.toEncoded(targetBinding.definition.input))(input).pipe(
|
|
840
|
-
Effect.mapError(() => failure("start", "corrupt")),
|
|
844
|
+
Effect.mapError((cause) => failure("start", "corrupt", cause)),
|
|
841
845
|
);
|
|
842
846
|
|
|
843
847
|
const targetRequest = {
|
|
@@ -1239,7 +1243,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1239
1243
|
},
|
|
1240
1244
|
Effect.mapError((error) =>
|
|
1241
1245
|
error.reason === "storage" || error.reason === "corrupt"
|
|
1242
|
-
? LedgerError.make({ operation: "worker-update", message: error.reason })
|
|
1246
|
+
? LedgerError.make({ operation: "worker-update", message: error.reason, cause: error })
|
|
1243
1247
|
: UpdateError.make({ reason: error.reason === "denied" ? "denied" : "unavailable" }),
|
|
1244
1248
|
),
|
|
1245
1249
|
);
|
|
@@ -1400,6 +1404,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1400
1404
|
outcome: host.outcome,
|
|
1401
1405
|
encodedParameters: hostAdmission.parameters,
|
|
1402
1406
|
encodedResult: host.result ?? null,
|
|
1407
|
+
...(host.outcome === "failed" ? { diagnostic: host.result } : {}),
|
|
1403
1408
|
budgetExhausted: host.finishReason === "budget-exhausted",
|
|
1404
1409
|
},
|
|
1405
1410
|
};
|
|
@@ -1589,7 +1594,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1589
1594
|
if (Option.isNone(deps.deliveries)) return yield* failure("inspect", "unavailable");
|
|
1590
1595
|
|
|
1591
1596
|
const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(decision.envelope).pipe(
|
|
1592
|
-
Effect.mapError(() => failure("inspect", "corrupt")),
|
|
1597
|
+
Effect.mapError((cause) => failure("inspect", "corrupt", cause)),
|
|
1593
1598
|
);
|
|
1594
1599
|
|
|
1595
1600
|
const prepared = yield* withCrypto(
|
|
@@ -1716,7 +1721,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1716
1721
|
|
|
1717
1722
|
const binding = (target: Agent.AnyDefinition, operation: WorkerError["operation"]) =>
|
|
1718
1723
|
resolveDefinitionBinding(deps.bindings, target).pipe(
|
|
1719
|
-
Effect.mapError(() => failure(operation, "declaration-unavailable")),
|
|
1724
|
+
Effect.mapError((cause) => failure(operation, "declaration-unavailable", cause)),
|
|
1720
1725
|
);
|
|
1721
1726
|
|
|
1722
1727
|
const preparedTarget = Effect.fn("WorkerHost.preparedTarget")(function* (
|
|
@@ -1726,7 +1731,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1726
1731
|
const resolved = yield* binding(target, "start");
|
|
1727
1732
|
|
|
1728
1733
|
yield* Schema.decodeUnknownEffect(Schema.toEncoded(target.input))(encodedInput).pipe(
|
|
1729
|
-
Effect.mapError(() => failure("start", "corrupt")),
|
|
1734
|
+
Effect.mapError((cause) => failure("start", "corrupt", cause)),
|
|
1730
1735
|
);
|
|
1731
1736
|
const input = yield* decode(PersistedJson, encodedInput, "start");
|
|
1732
1737
|
|
|
@@ -1858,6 +1863,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1858
1863
|
outcome: settlement.outcome,
|
|
1859
1864
|
encodedParameters: admission.parameters,
|
|
1860
1865
|
encodedResult: result.result ?? null,
|
|
1866
|
+
...(result.outcome === "failed" ? { diagnostic: result.result } : {}),
|
|
1861
1867
|
budgetExhausted: result.finishReason === "budget-exhausted",
|
|
1862
1868
|
};
|
|
1863
1869
|
});
|
|
@@ -1937,6 +1943,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1937
1943
|
error._tag === "MessageDeliveryError" && error.reason === "capacity"
|
|
1938
1944
|
? "capacity"
|
|
1939
1945
|
: "storage",
|
|
1946
|
+
error,
|
|
1940
1947
|
),
|
|
1941
1948
|
),
|
|
1942
1949
|
);
|
|
@@ -1955,16 +1962,20 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1955
1962
|
.pipe(
|
|
1956
1963
|
Effect.mapError((error) =>
|
|
1957
1964
|
error._tag === "AdmissionConflict" || error._tag === "AgentInputError"
|
|
1958
|
-
? ScheduledInputRefused.make({ code: error._tag })
|
|
1965
|
+
? ScheduledInputRefused.make({ code: error._tag, cause: error })
|
|
1959
1966
|
: error._tag === "AdmissionPolicyError" && error.reason === "refused"
|
|
1960
|
-
? ScheduledInputRefused.make({ code: error.code })
|
|
1961
|
-
: ScheduledInputRetryable.make({ reason: "storage" }),
|
|
1967
|
+
? ScheduledInputRefused.make({ code: error.code, cause: error })
|
|
1968
|
+
: ScheduledInputRetryable.make({ reason: "storage", cause: error }),
|
|
1962
1969
|
),
|
|
1963
1970
|
),
|
|
1964
1971
|
submissionStatus: (receipt) =>
|
|
1965
1972
|
deps
|
|
1966
1973
|
.status(receipt)
|
|
1967
|
-
.pipe(
|
|
1974
|
+
.pipe(
|
|
1975
|
+
Effect.mapError((error) =>
|
|
1976
|
+
ScheduledInputRetryable.make({ reason: "storage", cause: error }),
|
|
1977
|
+
),
|
|
1978
|
+
),
|
|
1968
1979
|
}),
|
|
1969
1980
|
Effect.provideService(Crypto.Crypto, deps.crypto),
|
|
1970
1981
|
Effect.mapError(storageFailure(operation)),
|
|
@@ -1985,6 +1996,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1985
1996
|
return yield* failure(
|
|
1986
1997
|
operation,
|
|
1987
1998
|
Option.getOrElse(reason, () => "denied"),
|
|
1999
|
+
processed.lastFailureDiagnostic,
|
|
1988
2000
|
);
|
|
1989
2001
|
}
|
|
1990
2002
|
|
|
@@ -1995,6 +2007,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
1995
2007
|
processed.status === "pending" && processed.retry.lastFailure === null
|
|
1996
2008
|
? "delivery-pending"
|
|
1997
2009
|
: "storage",
|
|
2010
|
+
processed.lastFailureDiagnostic,
|
|
1998
2011
|
);
|
|
1999
2012
|
});
|
|
2000
2013
|
|
|
@@ -2093,7 +2106,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2093
2106
|
const sourcePolicy = Option.getOrElse(prepared.source.policyOverride, () => context.policy);
|
|
2094
2107
|
|
|
2095
2108
|
const grant = yield* Schema.decodeUnknownEffect(SubagentGrant)(request.encodedGrant).pipe(
|
|
2096
|
-
Effect.mapError(() => failure("start", "corrupt")),
|
|
2109
|
+
Effect.mapError((cause) => failure("start", "corrupt", cause)),
|
|
2097
2110
|
);
|
|
2098
2111
|
|
|
2099
2112
|
const messageId = yield* messageIdFor([
|
|
@@ -2196,7 +2209,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2196
2209
|
|
|
2197
2210
|
yield* Schema.decodeUnknownEffect(Schema.toEncoded(request.target.input))(
|
|
2198
2211
|
request.encodedInput,
|
|
2199
|
-
).pipe(Effect.mapError(() => failure("followUp", "corrupt")));
|
|
2212
|
+
).pipe(Effect.mapError((cause) => failure("followUp", "corrupt", cause)));
|
|
2200
2213
|
|
|
2201
2214
|
const messageId = yield* messageIdFor([
|
|
2202
2215
|
context.source.threadId,
|
|
@@ -2282,7 +2295,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2282
2295
|
record,
|
|
2283
2296
|
}),
|
|
2284
2297
|
),
|
|
2285
|
-
Effect.mapError(() => failure("observe", "corrupt")),
|
|
2298
|
+
Effect.mapError((cause) => failure("observe", "corrupt", cause)),
|
|
2286
2299
|
),
|
|
2287
2300
|
);
|
|
2288
2301
|
|
|
@@ -2358,7 +2371,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2358
2371
|
)
|
|
2359
2372
|
.pipe(
|
|
2360
2373
|
Effect.mapError((error) =>
|
|
2361
|
-
error._tag === "JoinedToHost" ? error : failure("cancel", "storage"),
|
|
2374
|
+
error._tag === "JoinedToHost" ? error : failure("cancel", "storage", error),
|
|
2362
2375
|
),
|
|
2363
2376
|
);
|
|
2364
2377
|
}),
|
|
@@ -2372,7 +2385,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2372
2385
|
inputDigest: Digest,
|
|
2373
2386
|
) {
|
|
2374
2387
|
const message = yield* Schema.decodeEffect(FrameworkMessage)(unvalidated).pipe(
|
|
2375
|
-
Effect.mapError(() => failure("followUp", "corrupt")),
|
|
2388
|
+
Effect.mapError((cause) => failure("followUp", "corrupt", cause)),
|
|
2376
2389
|
);
|
|
2377
2390
|
|
|
2378
2391
|
const childThreadId =
|
|
@@ -2409,7 +2422,7 @@ export const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (
|
|
|
2409
2422
|
if (frozen === undefined) return yield* failure("followUp", "denied");
|
|
2410
2423
|
|
|
2411
2424
|
const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(frozen).pipe(
|
|
2412
|
-
Effect.mapError(() => failure("followUp", "corrupt")),
|
|
2425
|
+
Effect.mapError((cause) => failure("followUp", "corrupt", cause)),
|
|
2413
2426
|
);
|
|
2414
2427
|
|
|
2415
2428
|
if (
|
package/src/engine/RunOptions.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Cause, Effect, Context, type DateTime, Layer, Schema } from "effec
|
|
|
2
2
|
import type { LanguageModel, Model, Prompt, Response } from "effect/unstable/ai";
|
|
3
3
|
|
|
4
4
|
import { type AnyDefinition } from "../core/Agent.ts";
|
|
5
|
-
import { type AgentInputError } from "../core/AgentError.ts";
|
|
5
|
+
import { type AgentInputError, type AgentToolAuthorizationCheckError } from "../core/AgentError.ts";
|
|
6
6
|
import { type AgentPolicy } from "../core/AgentPolicy.ts";
|
|
7
7
|
import type { Update, UpdateError } from "../core/AgentUpdates.ts";
|
|
8
8
|
import {
|
|
@@ -396,7 +396,13 @@ export interface RunToolCallDescriptor {
|
|
|
396
396
|
/** Decision returned by a host's action-time Tool authorization policy. */
|
|
397
397
|
export type RunToolAuthorizationDecision =
|
|
398
398
|
| { readonly _tag: "allowed" }
|
|
399
|
-
| {
|
|
399
|
+
| {
|
|
400
|
+
readonly _tag: "denied";
|
|
401
|
+
/** Safe model-facing explanation. */
|
|
402
|
+
readonly reason: string;
|
|
403
|
+
/** Original local policy evidence; retained privately at native Run settlement. */
|
|
404
|
+
readonly cause?: Cause.Cause<unknown>;
|
|
405
|
+
};
|
|
400
406
|
|
|
401
407
|
/**
|
|
402
408
|
* Exact authority presented before one application Tool Handler may start.
|
|
@@ -459,13 +465,15 @@ export const RunContextPreparationPassthrough: Layer.Layer<RunContextPreparation
|
|
|
459
465
|
/**
|
|
460
466
|
* Host action-time authority for native and programmatic application Tools. Implementations close over
|
|
461
467
|
* their dependencies at Layer construction and return a denial when execution is not authorized.
|
|
468
|
+
* A dependency or validation failure instead fails with AgentToolAuthorizationCheckError and
|
|
469
|
+
* retains its original Cause. Defects and interruption remain in the Effect Cause channel.
|
|
462
470
|
* Durable coordinators capture this service once and retain it across replacement Attempts.
|
|
463
471
|
* Ephemeral Runs also resolve this service at their Run boundary. A typed per-run
|
|
464
472
|
* `RunOptions.toolAuthorization` overrides it while retaining its own error and requirement channel.
|
|
465
473
|
*/
|
|
466
474
|
export class RunToolAuthorization extends Context.Service<
|
|
467
475
|
RunToolAuthorization,
|
|
468
|
-
RunToolAuthorizationHook
|
|
476
|
+
RunToolAuthorizationHook<AgentToolAuthorizationCheckError>
|
|
469
477
|
>()("@effect-agent/engine/RunToolAuthorization") {
|
|
470
478
|
/** Explicit compatibility policy: Tool execution requires no additional host authorization. */
|
|
471
479
|
static readonly allowAll: Layer.Layer<RunToolAuthorization> = Layer.succeed(
|
|
@@ -3,6 +3,7 @@ import { Context, Schema, Stream } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import type * as Agent from "../core/Agent.ts";
|
|
5
5
|
import type { AgentPolicy } from "../core/AgentPolicy.ts";
|
|
6
|
+
import type * as FailureDiagnostic from "../core/FailureDiagnostic.ts";
|
|
6
7
|
import type { DelegationId, RunId, SettlementId, ThreadId } from "../core/Identifiers.ts";
|
|
7
8
|
import { type IdempotencyKey, type JoinedToHost, type Receipt } from "../core/Receipt.ts";
|
|
8
9
|
import type { SubagentBudgetReservation } from "../core/SubagentContract.ts";
|
|
@@ -63,6 +64,8 @@ export type WorkerObservation =
|
|
|
63
64
|
readonly outcome: "completed" | "failed" | "aborted";
|
|
64
65
|
readonly encodedParameters: unknown;
|
|
65
66
|
readonly encodedResult: unknown;
|
|
67
|
+
/** Operator-private failed-settlement evidence; never part of a model Tool result. */
|
|
68
|
+
readonly diagnostic?: FailureDiagnostic.Failure;
|
|
66
69
|
readonly budgetExhausted: boolean;
|
|
67
70
|
};
|
|
68
71
|
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
AgentOutputError,
|
|
42
42
|
AgentRunDispositionError,
|
|
43
43
|
AgentToolAuthorizationDenied,
|
|
44
|
+
type AgentToolAuthorizationCheckError,
|
|
44
45
|
AgentPolicyError,
|
|
45
46
|
ContextBudgetError,
|
|
46
47
|
ContextOverflowError,
|
|
@@ -433,6 +434,7 @@ export type AgentRuntimeFailure<
|
|
|
433
434
|
| ContextOverflowError
|
|
434
435
|
| CompactionError
|
|
435
436
|
| RunContextPreparationError
|
|
437
|
+
| AgentToolAuthorizationCheckError
|
|
436
438
|
| ModelProtocolError
|
|
437
439
|
| AgentApprovalDenied
|
|
438
440
|
| AgentToolAuthorizationDenied
|
|
@@ -941,7 +943,7 @@ const modelResponseCodecFor = (toolkit: Toolkit.Any) => {
|
|
|
941
943
|
return codec;
|
|
942
944
|
};
|
|
943
945
|
|
|
944
|
-
const ownModelResponsePartGeneral = Effect.
|
|
946
|
+
const ownModelResponsePartGeneral = Effect.fnUntraced(function* <
|
|
945
947
|
Tools extends Record<string, Tool.Any>,
|
|
946
948
|
>(
|
|
947
949
|
part: unknown,
|
|
@@ -1782,20 +1784,21 @@ const preflightToolAuthorization = <HookError, HookRequirements>(
|
|
|
1782
1784
|
HookError | ModelProtocolError | AgentToolAuthorizationDenied,
|
|
1783
1785
|
HookRequirements
|
|
1784
1786
|
> => {
|
|
1785
|
-
const authorization =
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1787
|
+
const authorization: RunToolAuthorizationHook<HookError, HookRequirements> | undefined =
|
|
1788
|
+
isSubagentToolAllowed(
|
|
1789
|
+
options.subagentGrant,
|
|
1790
|
+
options.delegationDepth ?? options.parentLink?.depth ?? 0,
|
|
1791
|
+
call.toolName,
|
|
1792
|
+
annotations,
|
|
1793
|
+
)
|
|
1794
|
+
? options.toolAuthorization
|
|
1795
|
+
: {
|
|
1796
|
+
authorize: () =>
|
|
1797
|
+
Effect.succeed({
|
|
1798
|
+
_tag: "denied" as const,
|
|
1799
|
+
reason: "Tool exceeds the inherited subagent grant",
|
|
1800
|
+
}),
|
|
1801
|
+
};
|
|
1799
1802
|
|
|
1800
1803
|
if (authorization === undefined) return Stream.empty;
|
|
1801
1804
|
|
|
@@ -1817,6 +1820,7 @@ const preflightToolAuthorization = <HookError, HookRequirements>(
|
|
|
1817
1820
|
toolCallId: call.toolCallId,
|
|
1818
1821
|
toolName: call.toolName,
|
|
1819
1822
|
message: decision.reason,
|
|
1823
|
+
...(decision.cause === undefined ? {} : { cause: decision.cause }),
|
|
1820
1824
|
});
|
|
1821
1825
|
|
|
1822
1826
|
return Stream.fromEffect(
|
|
@@ -7848,7 +7852,10 @@ function streamWithCompletion<
|
|
|
7848
7852
|
}
|
|
7849
7853
|
|
|
7850
7854
|
const options: RunOptions<
|
|
7851
|
-
|
|
7855
|
+
| HookError
|
|
7856
|
+
| ThreadHistoryError
|
|
7857
|
+
| RunContextPreparationError
|
|
7858
|
+
| AgentToolAuthorizationCheckError,
|
|
7852
7859
|
HookRequirements
|
|
7853
7860
|
> = {
|
|
7854
7861
|
...runOptions,
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * as ContextHistory from "./engine/ContextHistory.ts";
|
|
|
14
14
|
export * as ContextTools from "./capabilities/ContextTools.ts";
|
|
15
15
|
export * as ContextWindow from "./engine/ContextWindow.ts";
|
|
16
16
|
export * as DurableStep from "./engine/DurableStep.ts";
|
|
17
|
+
export * as FailureDiagnostic from "./core/FailureDiagnostic.ts";
|
|
17
18
|
export * as InMemory from "./InMemory.ts";
|
|
18
19
|
export * as Thread from "./core/Thread.ts";
|
|
19
20
|
export * as IdGenerator from "./core/IdGenerator.ts";
|