@yielded/agent 0.1.0-beta.173 → 0.1.0-beta.175
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Admin-BX9ns28E.d.mts → Admin-Qa3I1oA5.d.mts} +61 -21
- package/dist/{Agent-9aBoIi74.d.mts → Agent-B39jRnFv.d.mts} +2 -2
- package/dist/{Agent-0WvBWWbM.mjs → Agent-BiRbr73L.mjs} +7 -6
- package/dist/Agent-BiRbr73L.mjs.map +1 -0
- package/dist/{AgentRuntime-BfP14534.d.mts → AgentRuntime-CHDyRbSf.d.mts} +12 -12
- package/dist/{AgentRuntime-CQ-qcETl.mjs → AgentRuntime-DaDKMasp.mjs} +290 -273
- package/dist/AgentRuntime-DaDKMasp.mjs.map +1 -0
- package/dist/{Digest-DCuPlhNk.mjs → Digest-C3EODOee.mjs} +42 -15
- package/dist/Digest-C3EODOee.mjs.map +1 -0
- package/dist/{DurableAgentRuntime-BAmSkWYr.mjs → DurableAgentRuntime-CPlw5_7e.mjs} +1557 -1458
- package/dist/DurableAgentRuntime-CPlw5_7e.mjs.map +1 -0
- package/dist/{EventSource-BwliwQz9.d.mts → EventSource-BTu68yDW.d.mts} +2 -2
- package/dist/InMemory.d.mts +2 -2
- package/dist/{MessageDelivery-B943ebI_.d.mts → MessageDelivery-DjAZJ4Fd.d.mts} +42 -42
- package/dist/{Messaging-C_6OOg_s.d.mts → Messaging-SVu6rWV8.d.mts} +12 -6
- package/dist/{MessagingHost-B8oKM7AC.d.mts → MessagingHost-C6SOAcoG.d.mts} +2 -2
- package/dist/{MessagingHost-CRUK4JBi.mjs → MessagingHost-CZCyrnvJ.mjs} +27 -26
- package/dist/MessagingHost-CZCyrnvJ.mjs.map +1 -0
- package/dist/{Output-Dsx6k52t.d.mts → Output-CRamN1Fy.d.mts} +2 -2
- package/dist/{PreparedInputAdmission-CxSJSiTl.d.mts → PreparedInputAdmission-wgY4JMZY.d.mts} +3 -3
- package/dist/{Records-BiuJDWNe.mjs → Records-DzL4Kbtw.mjs} +2 -2
- package/dist/{Records-BiuJDWNe.mjs.map → Records-DzL4Kbtw.mjs.map} +1 -1
- package/dist/{RunContinuation-FHM7XPjq.d.mts → RunContinuation-3jB5pULC.d.mts} +13 -7
- package/dist/{RunContinuation-DHYNAQFi.mjs → RunContinuation-BiyKJK32.mjs} +173 -82
- package/dist/RunContinuation-BiyKJK32.mjs.map +1 -0
- package/dist/{RunJournal-kfKVxJj7.mjs → RunJournal-CPMKcfd0.mjs} +106 -73
- package/dist/RunJournal-CPMKcfd0.mjs.map +1 -0
- package/dist/{RunOptions-D8zxFIrZ.d.mts → RunOptions-Be77lKVZ.d.mts} +2 -2
- package/dist/{RunStorage-uqPxps09.mjs → RunStorage-CzutHJBE.mjs} +10 -6
- package/dist/RunStorage-CzutHJBE.mjs.map +1 -0
- package/dist/{Scheduling-CVyfXlBR.mjs → Scheduling-07_dsGED.mjs} +12 -12
- package/dist/Scheduling-07_dsGED.mjs.map +1 -0
- package/dist/{Subagent-vpffemql.mjs → Subagent-CexndZSp.mjs} +53 -40
- package/dist/Subagent-CexndZSp.mjs.map +1 -0
- package/dist/{Subagent-E6tvd7-k.d.mts → Subagent-xhN_aD1r.d.mts} +20 -9
- package/dist/{SubagentHost-B6w2m-SI.d.mts → SubagentHost-D1xBgn9g.d.mts} +2 -2
- package/dist/{Subscription-DONig54Q.d.mts → Subscription-DmIHlOJK.d.mts} +2 -2
- package/dist/{SubscriptionInput-mJIRxWJM.d.mts → SubscriptionInput-DgcQhvbe.d.mts} +2 -2
- package/dist/{Thread-dk-QiNml.d.mts → Thread-DzdJAY4J.d.mts} +4 -3
- package/dist/{ThreadHistory-ByxS8HU1.d.mts → ThreadHistory-KPPBJLJb.d.mts} +12 -2
- package/dist/{ThreadImport-DckUMEqJ.mjs → ThreadImport-CjlG57vH.mjs} +9 -9
- package/dist/ThreadImport-CjlG57vH.mjs.map +1 -0
- package/dist/{ThreadImport-DpHxjBrA.d.mts → ThreadImport-DP-vOk2F.d.mts} +5 -5
- package/dist/{ThreadStore-CEekRa80.mjs → ThreadStore-EuUilthA.mjs} +162 -85
- package/dist/ThreadStore-EuUilthA.mjs.map +1 -0
- package/dist/{ThreadTransfer-B4gTQLIl.mjs → ThreadTransfer-DB_zsrtJ.mjs} +4 -4
- package/dist/{ThreadTransfer-B4gTQLIl.mjs.map → ThreadTransfer-DB_zsrtJ.mjs.map} +1 -1
- package/dist/{WorkerAdmission-DFVbbVh2.mjs → WorkerAdmission-eBeXt_mu.mjs} +5 -5
- package/dist/{WorkerAdmission-DFVbbVh2.mjs.map → WorkerAdmission-eBeXt_mu.mjs.map} +1 -1
- package/dist/{agent-registration-ByMZ_cK5.mjs → agent-registration-a6QYaG3h.mjs} +70 -57
- package/dist/agent-registration-a6QYaG3h.mjs.map +1 -0
- package/dist/capabilities/Approval.mjs +2 -2
- package/dist/capabilities/Approval.mjs.map +1 -1
- package/dist/capabilities/BrowserUse.d.mts +102 -1867
- package/dist/capabilities/BrowserUse.mjs +74 -798
- package/dist/capabilities/BrowserUse.mjs.map +1 -1
- package/dist/capabilities/Budget.mjs +3 -1
- package/dist/capabilities/Budget.mjs.map +1 -1
- package/dist/capabilities/CodeMode.d.mts +1 -1
- package/dist/capabilities/CodeMode.mjs +16 -9
- package/dist/capabilities/CodeMode.mjs.map +1 -1
- package/dist/capabilities/Commands.d.mts +1 -1
- package/dist/capabilities/McpClient.mjs +1 -1
- package/dist/capabilities/McpClient.mjs.map +1 -1
- package/dist/capabilities/Messaging.d.mts +1 -1
- package/dist/capabilities/Messaging.mjs +5 -5
- package/dist/capabilities/Messaging.mjs.map +1 -1
- package/dist/capabilities/ModelContext.d.mts +1 -1
- package/dist/capabilities/ModelContext.mjs +7 -5
- package/dist/capabilities/ModelContext.mjs.map +1 -1
- package/dist/capabilities/Redaction.mjs +49 -19
- package/dist/capabilities/Redaction.mjs.map +1 -1
- package/dist/capabilities/RunHooks.d.mts +2 -2
- package/dist/capabilities/RunHooks.mjs +1 -1
- package/dist/capabilities/RunHooks.mjs.map +1 -1
- package/dist/capabilities/Subagent.d.mts +1 -1
- package/dist/capabilities/Subagent.mjs +1 -1
- package/dist/capabilities/SubagentReservations.mjs +3 -1
- package/dist/capabilities/SubagentReservations.mjs.map +1 -1
- package/dist/capabilities/WebCapture.mjs.map +1 -1
- package/dist/capabilities/WebSearch.mjs +7 -7
- package/dist/capabilities/WebSearch.mjs.map +1 -1
- package/dist/core/Agent.d.mts +1 -1
- package/dist/core/Agent.mjs +1 -1
- package/dist/core/AgentUpdates.mjs +8 -8
- package/dist/core/AgentUpdates.mjs.map +1 -1
- package/dist/core/Thread.d.mts +2 -2
- package/dist/core/Thread.mjs +6 -4
- package/dist/core/Thread.mjs.map +1 -1
- package/dist/core/Usage.mjs +2 -2
- package/dist/core/Usage.mjs.map +1 -1
- package/dist/durable/ActivityStore.mjs +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/Admin.mjs +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/AgentRegistration.mjs +1 -1
- package/dist/durable/Certification.d.mts +1 -1
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/CommittedActivity.mjs +3 -3
- package/dist/durable/Digest.mjs +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +2 -2
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/EventSource.mjs +7 -7
- package/dist/durable/EventSource.mjs.map +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/LifecyclePublication.d.mts +1 -1
- package/dist/durable/LifecyclePublication.mjs +2 -2
- package/dist/durable/MessageDelivery.d.mts +1 -1
- package/dist/durable/MessageDelivery.mjs +2 -2
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +40 -40
- package/dist/durable/MessageDeliveryStoreConformance.mjs +2 -2
- package/dist/durable/PersistentHistory.d.mts +2 -2
- package/dist/durable/PersistentHistory.mjs +4 -4
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/RecordFormat.mjs +3 -3
- package/dist/durable/RecordFormat.mjs.map +1 -1
- package/dist/durable/Records.mjs +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/Recovery.mjs +1 -1
- package/dist/durable/RunContinuation.d.mts +2 -2
- package/dist/durable/RunContinuation.mjs +3 -3
- package/dist/durable/RunJournal.d.mts +2 -2
- package/dist/durable/RunJournal.mjs +2 -2
- package/dist/durable/RunStorage.d.mts +1 -1
- package/dist/durable/RunStorage.mjs +1 -1
- package/dist/durable/Schedule.mjs +1 -1
- package/dist/durable/ScheduleStoreConformance.mjs +1 -1
- package/dist/durable/ScheduleTransition.mjs +1 -1
- package/dist/durable/Scheduling.d.mts +1 -1
- package/dist/durable/Scheduling.mjs +1 -1
- package/dist/durable/SettlementPublisher.d.mts +1 -1
- package/dist/durable/SettlementPublisher.mjs +3 -3
- package/dist/durable/SqlMemoryStore.mjs +5 -3
- package/dist/durable/SqlMemoryStore.mjs.map +1 -1
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs +11 -3
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +6 -6
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/Subscription.mjs +2 -2
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionInput.mjs +4 -4
- package/dist/durable/SubscriptionInput.mjs.map +1 -1
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionStoreConformance.mjs +3 -3
- package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -1
- package/dist/durable/SubscriptionTools.d.mts +2 -2
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/SubscriptionTransition.mjs +1 -1
- package/dist/durable/Subscriptions.d.mts +5 -5
- package/dist/durable/Subscriptions.mjs +3 -3
- package/dist/durable/Subscriptions.mjs.map +1 -1
- package/dist/durable/ThreadArchiveRange.d.mts +1 -1
- package/dist/durable/ThreadArchiveRange.mjs +1 -1
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.mjs +2 -2
- package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
- package/dist/durable/ThreadImport.d.mts +1 -1
- package/dist/durable/ThreadImport.mjs +1 -1
- package/dist/durable/ThreadInvariants.d.mts +3 -3
- package/dist/durable/ThreadInvariants.mjs +5 -5
- package/dist/durable/ThreadInvariants.mjs.map +1 -1
- package/dist/durable/ThreadProjection.mjs +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadReader.d.mts +1 -1
- package/dist/durable/ThreadReader.mjs +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +2 -2
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +4 -4
- package/dist/durable/ThreadTransfer.d.mts +1 -1
- package/dist/durable/ThreadTransfer.mjs +1 -1
- package/dist/durable/ThreadWork.d.mts +2 -2
- package/dist/durable/ThreadWork.mjs +12 -6
- package/dist/durable/ThreadWork.mjs.map +1 -1
- package/dist/durable/ToolReconciler.mjs +1 -1
- package/dist/durable/WakeScheduler.mjs +23 -39
- package/dist/durable/WakeScheduler.mjs.map +1 -1
- package/dist/durable/WorkerAdmission.d.mts +1 -1
- package/dist/durable/WorkerAdmission.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +2 -2
- 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/Output.mjs +1 -1
- package/dist/engine/RunOptions.d.mts +1 -1
- package/dist/engine/SubagentHost.d.mts +1 -1
- package/dist/engine/ThreadHistory.d.mts +1 -1
- package/dist/engine/ThreadHistory.mjs +3 -2
- package/dist/engine/ThreadHistory.mjs.map +1 -1
- package/dist/index.d.mts +21 -21
- package/dist/index.mjs +16 -16
- package/dist/{output-contract-CMIhu4Cw.mjs → output-contract-DCnLYCdp.mjs} +12 -15
- package/dist/{output-contract-CMIhu4Cw.mjs.map → output-contract-DCnLYCdp.mjs.map} +1 -1
- package/dist/{run-context-reader-OcsZr4bk.d.mts → run-context-reader-DVhJZ1Qe.d.mts} +2 -2
- package/package.json +1 -1
- package/src/capabilities/Approval.ts +58 -60
- package/src/capabilities/BrowserUse.ts +89 -944
- package/src/capabilities/Budget.ts +8 -1
- package/src/capabilities/CodeMode.ts +57 -33
- package/src/capabilities/McpClient.ts +2 -2
- package/src/capabilities/Messaging.ts +51 -55
- package/src/capabilities/ModelContext.ts +5 -2
- package/src/capabilities/Redaction.ts +64 -34
- package/src/capabilities/RunHooks.ts +52 -55
- package/src/capabilities/Subagent.ts +33 -33
- package/src/capabilities/SubagentReservations.ts +9 -1
- package/src/capabilities/WebCapture.ts +6 -0
- package/src/capabilities/WebSearch.ts +10 -7
- package/src/capabilities/internal/subagent-background.ts +202 -158
- package/src/core/Agent.ts +11 -6
- package/src/core/AgentUpdates.ts +8 -8
- package/src/core/Thread.ts +142 -146
- package/src/core/Usage.ts +7 -8
- package/src/core/internal/agent-updates.ts +1 -0
- package/src/durable/DurableAgentRuntime.ts +1024 -829
- package/src/durable/EventSource.ts +15 -9
- package/src/durable/RecordFormat.ts +5 -3
- package/src/durable/RunContinuation.ts +316 -113
- package/src/durable/RunJournal.ts +106 -114
- package/src/durable/RunStorage.ts +129 -124
- package/src/durable/Scheduling.ts +639 -651
- package/src/durable/SqlMemoryStore.ts +8 -6
- package/src/durable/SubmissionLedger.ts +11 -0
- package/src/durable/SubscriptionInput.ts +5 -3
- package/src/durable/SubscriptionStoreConformance.ts +23 -23
- package/src/durable/Subscriptions.ts +18 -19
- package/src/durable/ThreadImport.ts +18 -19
- package/src/durable/ThreadInvariants.ts +2 -1
- package/src/durable/ThreadStore.ts +217 -111
- package/src/durable/ThreadWork.ts +11 -2
- package/src/durable/WakeScheduler.ts +34 -66
- package/src/durable/internal/StorageOwner.ts +10 -4
- package/src/durable/internal/agent-registration.ts +96 -89
- package/src/durable/internal/canonical-json.ts +61 -20
- package/src/durable/internal/prompt-history-cache.ts +13 -4
- package/src/durable/internal/record-encoding.ts +120 -64
- package/src/durable/internal/schedule-time.ts +6 -6
- package/src/durable/internal/usage-totals.ts +35 -0
- package/src/durable/internal/worker-host.ts +69 -74
- package/src/engine/MessagingHost.ts +4 -2
- package/src/engine/ThreadHistory.ts +47 -48
- package/src/engine/internal/agent-runtime.ts +1298 -1217
- package/src/engine/internal/output-contract.ts +15 -15
- package/src/engine/internal/primitive-delta.ts +2 -3
- package/src/engine/internal/provisional-text.ts +12 -10
- package/src/engine/internal/tool-exposure.ts +22 -18
- package/src/engine/internal/tool-telemetry.ts +15 -12
- package/dist/Agent-0WvBWWbM.mjs.map +0 -1
- package/dist/AgentRuntime-CQ-qcETl.mjs.map +0 -1
- package/dist/Digest-DCuPlhNk.mjs.map +0 -1
- package/dist/DurableAgentRuntime-BAmSkWYr.mjs.map +0 -1
- package/dist/MessagingHost-CRUK4JBi.mjs.map +0 -1
- package/dist/RunContinuation-DHYNAQFi.mjs.map +0 -1
- package/dist/RunJournal-kfKVxJj7.mjs.map +0 -1
- package/dist/RunStorage-uqPxps09.mjs.map +0 -1
- package/dist/Scheduling-CVyfXlBR.mjs.map +0 -1
- package/dist/Subagent-vpffemql.mjs.map +0 -1
- package/dist/ThreadImport-DckUMEqJ.mjs.map +0 -1
- package/dist/ThreadStore-CEekRa80.mjs.map +0 -1
- package/dist/agent-registration-ByMZ_cK5.mjs.map +0 -1
package/src/core/Agent.ts
CHANGED
|
@@ -570,9 +570,11 @@ export function make(
|
|
|
570
570
|
|
|
571
571
|
for (const declaration of options.completionFromTools ?? []) {
|
|
572
572
|
if (declaration.tool === options.completion?.tool || completionNames.has(declaration.tool)) {
|
|
573
|
+
// oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects duplicate completion declarations before constructing the Definition.
|
|
573
574
|
throw new Error(`Tool ${declaration.tool} has more than one completion declaration`);
|
|
574
575
|
}
|
|
575
576
|
if (!Object.hasOwn(options.toolkit.tools, declaration.tool)) {
|
|
577
|
+
// oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects completion declarations for absent Tools.
|
|
576
578
|
throw new Error(`Unknown completion Tool ${declaration.tool}`);
|
|
577
579
|
}
|
|
578
580
|
completionNames.add(declaration.tool);
|
|
@@ -622,11 +624,14 @@ export function make(
|
|
|
622
624
|
}
|
|
623
625
|
|
|
624
626
|
/** Bind a native model or thread resolver without acquiring or hiding its requirements. */
|
|
625
|
-
export
|
|
627
|
+
export function withModel<DefinitionValue extends AnyDefinition, ModelValue>(
|
|
626
628
|
definition: DefinitionValue,
|
|
627
629
|
model: NativeModel<ModelValue>,
|
|
628
|
-
): Binding<DefinitionValue, ModelValue
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
630
|
+
): Binding<DefinitionValue, ModelValue>;
|
|
631
|
+
|
|
632
|
+
export function withModel<DefinitionValue extends AnyDefinition, ModelValue>(
|
|
633
|
+
definition: DefinitionValue,
|
|
634
|
+
model: ModelValue,
|
|
635
|
+
) {
|
|
636
|
+
return Object.freeze({ definition, model });
|
|
637
|
+
}
|
package/src/core/AgentUpdates.ts
CHANGED
|
@@ -59,20 +59,20 @@ export const emit = Effect.fnUntraced(function* <S extends Schema.Top>(
|
|
|
59
59
|
): Effect.fn.Return<Update, UpdateError, Emitter | S["EncodingServices"]> {
|
|
60
60
|
const target = "definition" in agent ? agent.definition : agent;
|
|
61
61
|
|
|
62
|
-
if (target.updates === undefined) return yield*
|
|
62
|
+
if (target.updates === undefined) return yield* UpdateError.make({ reason: "unavailable" });
|
|
63
63
|
|
|
64
64
|
const updateId = yield* Schema.decodeEffect(IdempotencyKey)(options.idempotencyKey).pipe(
|
|
65
|
-
Effect.mapError(() =>
|
|
65
|
+
Effect.mapError(() => UpdateError.make({ reason: "validation" })),
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
const encoded = yield* Schema.encodeEffect(target.updates)(value).pipe(
|
|
69
69
|
Effect.flatMap(Schema.decodeUnknownEffect(Schema.Json)),
|
|
70
|
-
Effect.mapError(() =>
|
|
70
|
+
Effect.mapError(() => UpdateError.make({ reason: "validation" })),
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
const emitter = yield* Effect.serviceOption(Emitter);
|
|
74
74
|
|
|
75
|
-
if (Option.isNone(emitter)) return yield*
|
|
75
|
+
if (Option.isNone(emitter)) return yield* UpdateError.make({ reason: "unavailable" });
|
|
76
76
|
|
|
77
77
|
return yield* emitter.value.emit({ target, updateId, value: encoded });
|
|
78
78
|
});
|
|
@@ -84,16 +84,16 @@ export const decode = Effect.fnUntraced(function* <S extends Schema.Top>(
|
|
|
84
84
|
): Effect.fn.Return<S["Type"], UpdateError, S["DecodingServices"]> {
|
|
85
85
|
const definition = "definition" in agent ? agent.definition : agent;
|
|
86
86
|
|
|
87
|
-
if (definition.updates === undefined) return yield*
|
|
87
|
+
if (definition.updates === undefined) return yield* UpdateError.make({ reason: "unavailable" });
|
|
88
88
|
|
|
89
89
|
const decoded = yield* Schema.decodeEffect(Update)(update).pipe(
|
|
90
|
-
Effect.mapError(() =>
|
|
90
|
+
Effect.mapError(() => UpdateError.make({ reason: "validation" })),
|
|
91
91
|
);
|
|
92
92
|
|
|
93
|
-
if (decoded.agentId !== definition.id) return yield*
|
|
93
|
+
if (decoded.agentId !== definition.id) return yield* UpdateError.make({ reason: "identity" });
|
|
94
94
|
|
|
95
95
|
return yield* Schema.decodeEffect(definition.updates)(decoded.value).pipe(
|
|
96
|
-
Effect.mapError(() =>
|
|
96
|
+
Effect.mapError(() => UpdateError.make({ reason: "validation" })),
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
99
|
|
package/src/core/Thread.ts
CHANGED
|
@@ -287,164 +287,160 @@ const appendEncoded = Effect.fnUntraced(function* (
|
|
|
287
287
|
});
|
|
288
288
|
|
|
289
289
|
/** In-memory storage shared for the consumer's Scope; it does not survive process loss. */
|
|
290
|
-
export const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
threads.delete(id);
|
|
305
|
-
contentBytes -= entry.snapshot.contentBytes;
|
|
306
|
-
}
|
|
290
|
+
export const makeMemoryStore = Effect.gen(function* () {
|
|
291
|
+
const state = yield* SynchronizedRef.make<State>({ threads: new Map(), contentBytes: 0 });
|
|
292
|
+
const root: Owner = { closed: false };
|
|
293
|
+
|
|
294
|
+
const release = (owner: Owner) =>
|
|
295
|
+
SynchronizedRef.update(state, (current) => {
|
|
296
|
+
owner.closed = true;
|
|
297
|
+
const threads = new Map(current.threads);
|
|
298
|
+
let contentBytes = current.contentBytes;
|
|
299
|
+
|
|
300
|
+
for (const [id, entry] of threads) {
|
|
301
|
+
if (belongsTo(entry.owner, owner)) {
|
|
302
|
+
threads.delete(id);
|
|
303
|
+
contentBytes -= entry.snapshot.contentBytes;
|
|
307
304
|
}
|
|
305
|
+
}
|
|
308
306
|
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
return { threads, contentBytes };
|
|
308
|
+
});
|
|
311
309
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
310
|
+
yield* Effect.addFinalizer(() => release(root));
|
|
311
|
+
|
|
312
|
+
const view = (owner: Owner): StoreService => ({
|
|
313
|
+
scoped: Effect.acquireRelease(
|
|
314
|
+
Effect.sync((): Owner => ({ closed: false, parent: owner })),
|
|
315
|
+
release,
|
|
316
|
+
).pipe(Effect.map(view)),
|
|
317
|
+
create: (threadId) =>
|
|
318
|
+
SynchronizedRef.modifyEffect(
|
|
319
|
+
state,
|
|
320
|
+
Effect.fnUntraced(function* (threads) {
|
|
321
|
+
const existing = yield* access(threads, owner, threadId);
|
|
322
|
+
|
|
323
|
+
if (existing !== undefined) return [existing, threads] as const;
|
|
324
|
+
if (threads.threads.size >= MAX_THREADS) {
|
|
325
|
+
return yield* ThreadLimitExceeded.make({
|
|
326
|
+
threadId,
|
|
327
|
+
limit: "threads",
|
|
328
|
+
limitValue: MAX_THREADS,
|
|
329
|
+
observedValue: threads.threads.size + 1,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
334
332
|
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
const created = Thread.make({
|
|
334
|
+
version: 1,
|
|
335
|
+
threadId,
|
|
336
|
+
nextSequence: 0,
|
|
337
|
+
contentBytes: 0,
|
|
338
|
+
messages: [],
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return [created, put(threads, owner, created)] as const;
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
append: Effect.fnUntraced(function* (threadId, message) {
|
|
345
|
+
const encoded = yield* encodeMessage(threadId, message.message);
|
|
346
|
+
const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
|
|
347
|
+
|
|
348
|
+
return yield* SynchronizedRef.modifyEffect(
|
|
349
|
+
state,
|
|
350
|
+
Effect.fnUntraced(function* (threads) {
|
|
351
|
+
const current = yield* findSnapshot(threads, owner, threadId);
|
|
352
|
+
|
|
353
|
+
return yield* appendEncoded(threads, owner, current, message, encoded, timestamp);
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
}),
|
|
357
|
+
recordHistory: Effect.fnUntraced(function* (threadId, historyRunId, history) {
|
|
358
|
+
const incoming = yield* Effect.forEach(history.content, (message) =>
|
|
359
|
+
encodeMessage(threadId, message).pipe(Effect.map((encoded) => ({ message, encoded }))),
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
// Publish the complete suffix only after verification and every bounded append succeed.
|
|
363
|
+
return yield* SynchronizedRef.modifyEffect(
|
|
364
|
+
state,
|
|
365
|
+
Effect.fnUntraced(function* (threads) {
|
|
366
|
+
const current = yield* findSnapshot(threads, owner, threadId);
|
|
367
|
+
|
|
368
|
+
const currentEncoded = yield* Effect.forEach(current.messages, (entry) =>
|
|
369
|
+
encodeMessage(threadId, entry.message),
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
if (
|
|
373
|
+
incoming.length < currentEncoded.length ||
|
|
374
|
+
currentEncoded.some((encoded, index) => encoded !== incoming[index]?.encoded)
|
|
375
|
+
) {
|
|
376
|
+
return yield* ThreadHistoryDiverged.make({
|
|
337
377
|
threadId,
|
|
338
|
-
|
|
339
|
-
contentBytes: 0,
|
|
340
|
-
messages: [],
|
|
378
|
+
message: "Engine history is not an append-only extension of official history",
|
|
341
379
|
});
|
|
380
|
+
}
|
|
381
|
+
const timestamp = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
|
|
342
382
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
Effect.fnUntraced(function* (threads) {
|
|
353
|
-
const current = yield* findSnapshot(threads, owner, threadId);
|
|
354
|
-
|
|
355
|
-
return yield* appendEncoded(threads, owner, current, message, encoded, timestamp);
|
|
356
|
-
}),
|
|
357
|
-
);
|
|
358
|
-
}),
|
|
359
|
-
recordHistory: Effect.fnUntraced(function* (threadId, historyRunId, history) {
|
|
360
|
-
const incoming = yield* Effect.forEach(history.content, (message) =>
|
|
361
|
-
encodeMessage(threadId, message).pipe(Effect.map((encoded) => ({ message, encoded }))),
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
// Publish the complete suffix only after verification and every bounded append succeed.
|
|
365
|
-
return yield* SynchronizedRef.modifyEffect(
|
|
366
|
-
state,
|
|
367
|
-
Effect.fnUntraced(function* (threads) {
|
|
368
|
-
const current = yield* findSnapshot(threads, owner, threadId);
|
|
369
|
-
|
|
370
|
-
const currentEncoded = yield* Effect.forEach(current.messages, (entry) =>
|
|
371
|
-
encodeMessage(threadId, entry.message),
|
|
372
|
-
);
|
|
383
|
+
if (incoming.length === currentEncoded.length) return [current, threads] as const;
|
|
384
|
+
|
|
385
|
+
const messages = [...current.messages];
|
|
386
|
+
let contentBytes = current.contentBytes;
|
|
387
|
+
let storeBytes = threads.contentBytes;
|
|
388
|
+
let nextSequence = current.nextSequence;
|
|
389
|
+
|
|
390
|
+
for (const entry of incoming.slice(currentEncoded.length)) {
|
|
391
|
+
const append = ThreadAppend.make({ runId: historyRunId, message: entry.message });
|
|
373
392
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
393
|
+
const messageBytes = yield* messageSize(threadId, entry.encoded);
|
|
394
|
+
|
|
395
|
+
contentBytes += messageBytes;
|
|
396
|
+
storeBytes += messageBytes;
|
|
397
|
+
if (storeBytes > MAX_STORE_CONTENT_BYTES) {
|
|
398
|
+
return yield* ThreadLimitExceeded.make({
|
|
379
399
|
threadId,
|
|
380
|
-
|
|
400
|
+
limit: "store-content-bytes",
|
|
401
|
+
limitValue: MAX_STORE_CONTENT_BYTES,
|
|
402
|
+
observedValue: storeBytes,
|
|
381
403
|
});
|
|
382
404
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const messageBytes = yield* messageSize(threadId, entry.encoded);
|
|
396
|
-
|
|
397
|
-
contentBytes += messageBytes;
|
|
398
|
-
storeBytes += messageBytes;
|
|
399
|
-
if (storeBytes > MAX_STORE_CONTENT_BYTES) {
|
|
400
|
-
return yield* ThreadLimitExceeded.make({
|
|
401
|
-
threadId,
|
|
402
|
-
limit: "store-content-bytes",
|
|
403
|
-
limitValue: MAX_STORE_CONTENT_BYTES,
|
|
404
|
-
observedValue: storeBytes,
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
messages.push(
|
|
408
|
-
ThreadMessage.make({
|
|
409
|
-
threadId,
|
|
410
|
-
sequence: nextSequence,
|
|
411
|
-
...(append.runId === undefined ? {} : { runId: append.runId }),
|
|
412
|
-
message: append.message,
|
|
413
|
-
encodedBytes: messageBytes,
|
|
414
|
-
timestamp,
|
|
415
|
-
}),
|
|
416
|
-
);
|
|
417
|
-
nextSequence += 1;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const snapshot = Thread.make({
|
|
421
|
-
version: current.version,
|
|
422
|
-
threadId,
|
|
423
|
-
nextSequence,
|
|
424
|
-
contentBytes,
|
|
425
|
-
messages,
|
|
426
|
-
});
|
|
405
|
+
messages.push(
|
|
406
|
+
ThreadMessage.make({
|
|
407
|
+
threadId,
|
|
408
|
+
sequence: nextSequence,
|
|
409
|
+
...(append.runId === undefined ? {} : { runId: append.runId }),
|
|
410
|
+
message: append.message,
|
|
411
|
+
encodedBytes: messageBytes,
|
|
412
|
+
timestamp,
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
415
|
+
nextSequence += 1;
|
|
416
|
+
}
|
|
427
417
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
Effect.flatMap((all) => findSnapshot(all, owner, threadId)),
|
|
435
|
-
),
|
|
436
|
-
export: (threadId) =>
|
|
437
|
-
Effect.gen(function* () {
|
|
438
|
-
const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), owner, threadId);
|
|
439
|
-
|
|
440
|
-
return ThreadExport.make({
|
|
441
|
-
format: "effect-agent/ephemeral-thread@1",
|
|
442
|
-
exportedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),
|
|
443
|
-
snapshot,
|
|
418
|
+
const snapshot = Thread.make({
|
|
419
|
+
version: current.version,
|
|
420
|
+
threadId,
|
|
421
|
+
nextSequence,
|
|
422
|
+
contentBytes,
|
|
423
|
+
messages,
|
|
444
424
|
});
|
|
425
|
+
|
|
426
|
+
return [snapshot, put(threads, owner, snapshot)] as const;
|
|
445
427
|
}),
|
|
446
|
-
|
|
428
|
+
);
|
|
429
|
+
}),
|
|
430
|
+
snapshot: (threadId) =>
|
|
431
|
+
SynchronizedRef.get(state).pipe(Effect.flatMap((all) => findSnapshot(all, owner, threadId))),
|
|
432
|
+
export: Effect.fnUntraced(function* (threadId) {
|
|
433
|
+
const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), owner, threadId);
|
|
434
|
+
|
|
435
|
+
return ThreadExport.make({
|
|
436
|
+
format: "effect-agent/ephemeral-thread@1",
|
|
437
|
+
exportedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),
|
|
438
|
+
snapshot,
|
|
439
|
+
});
|
|
440
|
+
}),
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
return view(root);
|
|
444
|
+
});
|
|
447
445
|
|
|
448
|
-
|
|
449
|
-
}),
|
|
450
|
-
);
|
|
446
|
+
export const layerMemory = Layer.effect(Store, makeMemoryStore);
|
package/src/core/Usage.ts
CHANGED
|
@@ -293,8 +293,8 @@ export const sumRunTotals = Effect.fnUntraced(function* (
|
|
|
293
293
|
|
|
294
294
|
for (const contribution of contributions) {
|
|
295
295
|
const value = yield* Schema.decodeEffect(RunTotals)(contribution).pipe(
|
|
296
|
-
Effect.mapError(
|
|
297
|
-
|
|
296
|
+
Effect.mapError(() =>
|
|
297
|
+
UsageAggregationError.make({ field: "totals", message: "Invalid Run totals" }),
|
|
298
298
|
),
|
|
299
299
|
);
|
|
300
300
|
|
|
@@ -376,12 +376,11 @@ export const summarizeModelUsage = Effect.fnUntraced(function* (
|
|
|
376
376
|
seed === undefined
|
|
377
377
|
? undefined
|
|
378
378
|
: yield* Schema.decodeEffect(RunUsageSummary)(seed).pipe(
|
|
379
|
-
Effect.mapError(
|
|
380
|
-
(
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}),
|
|
379
|
+
Effect.mapError(() =>
|
|
380
|
+
UsageAggregationError.make({
|
|
381
|
+
field: "seed",
|
|
382
|
+
message: "Canonical usage seed does not satisfy the RunUsageSummary Schema",
|
|
383
|
+
}),
|
|
385
384
|
),
|
|
386
385
|
);
|
|
387
386
|
|
|
@@ -29,6 +29,7 @@ export const withUpdateTool = (
|
|
|
29
29
|
): Toolkit.Any => {
|
|
30
30
|
if (schema === undefined) return toolkit;
|
|
31
31
|
if (Object.hasOwn(toolkit.tools, "emit_update"))
|
|
32
|
+
// oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- Agent.make synchronously rejects a toolkit that occupies the reserved update Tool name.
|
|
32
33
|
throw new TypeError("emit_update is reserved for Agent updates");
|
|
33
34
|
|
|
34
35
|
return Toolkit.make(...Object.values(toolkit.tools), updateTool(schema));
|