@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime, Predicate, Schema } from "effect";
|
|
1
|
+
import { DateTime, Predicate, Result, Schema } from "effect";
|
|
2
2
|
|
|
3
3
|
import type { RunId } from "../../core/Identifiers.ts";
|
|
4
4
|
import { utf8ByteLength } from "../../core/internal/utf8.ts";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
type RecordJson,
|
|
14
14
|
type RunContinuation,
|
|
15
15
|
} from "../Records.ts";
|
|
16
|
-
import { canonicalJson } from "./canonical-json.ts";
|
|
16
|
+
import { boundedCanonicalJson, canonicalJson } from "./canonical-json.ts";
|
|
17
17
|
import {
|
|
18
18
|
executionRunIds,
|
|
19
19
|
isPreContinuationFact,
|
|
@@ -31,6 +31,11 @@ const recordLimits = {
|
|
|
31
31
|
textUnits: MAX_CANONICAL_RECORD_BYTES,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
export class RecordEncodingError extends Schema.TaggedError<RecordEncodingError>()(
|
|
35
|
+
"RecordEncodingError",
|
|
36
|
+
{ message: Schema.String, cause: Schema.optionalKey(Schema.Defect()) },
|
|
37
|
+
) {}
|
|
38
|
+
|
|
34
39
|
export interface RecordEncoding {
|
|
35
40
|
readonly canonical: RecordEnvelope;
|
|
36
41
|
readonly wire: RecordJson;
|
|
@@ -39,6 +44,10 @@ export interface RecordEncoding {
|
|
|
39
44
|
readonly progress: ProgressAppendRecord;
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
interface CapturedRecordEncoding extends RecordEncoding {
|
|
48
|
+
readonly wire: typeof RecordEnvelope.Encoded;
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
/** Private capture metadata, never caller-supplied wire data or execution authority. */
|
|
43
52
|
export interface ProgressAppendRecord {
|
|
44
53
|
readonly recordId: RecordEnvelope["recordId"];
|
|
@@ -67,7 +76,40 @@ const progressRecord = (record: RecordEnvelope, bytes: number): ProgressAppendRe
|
|
|
67
76
|
});
|
|
68
77
|
};
|
|
69
78
|
|
|
70
|
-
const captured = new WeakMap<RecordEnvelope,
|
|
79
|
+
const captured = new WeakMap<RecordEnvelope, CapturedRecordEncoding>();
|
|
80
|
+
|
|
81
|
+
// Define own data properties so valid JSON keys never invoke inherited setters.
|
|
82
|
+
const setOwn = (target: object, key: PropertyKey, value: unknown): void => {
|
|
83
|
+
Object.defineProperty(target, key, {
|
|
84
|
+
value,
|
|
85
|
+
writable: true,
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** JSON arrays use indexed values, even when inherited or non-enumerable. */
|
|
92
|
+
const copyOwn = (value: object): object => {
|
|
93
|
+
if (!Array.isArray(value)) {
|
|
94
|
+
const copy = { ...value };
|
|
95
|
+
|
|
96
|
+
Object.setPrototypeOf(copy, Object.getPrototypeOf(value));
|
|
97
|
+
|
|
98
|
+
return copy;
|
|
99
|
+
}
|
|
100
|
+
const copy: Array<unknown> = [];
|
|
101
|
+
|
|
102
|
+
for (let index = 0; index < value.length; index++) setOwn(copy, index, value[index]);
|
|
103
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
104
|
+
if (
|
|
105
|
+
!Object.hasOwn(copy, key) &&
|
|
106
|
+
Object.getOwnPropertyDescriptor(value, key)?.enumerable === true
|
|
107
|
+
)
|
|
108
|
+
setOwn(copy, key, Reflect.get(value, key));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return copy;
|
|
112
|
+
};
|
|
71
113
|
|
|
72
114
|
/** Own every fact before suspension; encoded JSON fields can share these private frozen values. */
|
|
73
115
|
const capturePayload = (payload: CanonicalRecordPayload) => {
|
|
@@ -76,31 +118,26 @@ const capturePayload = (payload: CanonicalRecordPayload) => {
|
|
|
76
118
|
Object.setPrototypeOf(copy, Object.getPrototypeOf(payload));
|
|
77
119
|
const copies = new WeakMap<object, object>([[payload, copy]]);
|
|
78
120
|
|
|
79
|
-
const pending: Array<
|
|
80
|
-
{ source: payload, target: copy },
|
|
81
|
-
];
|
|
121
|
+
const pending: Array<object> = [copy];
|
|
82
122
|
|
|
83
123
|
const owned: Array<object> = [copy];
|
|
84
124
|
|
|
85
125
|
while (pending.length > 0) {
|
|
86
126
|
const next = pending.pop()!;
|
|
87
127
|
|
|
88
|
-
for (const [key, value] of Object.entries(next
|
|
89
|
-
if (!Predicate.
|
|
128
|
+
for (const [key, value] of Object.entries(next)) {
|
|
129
|
+
if (!Predicate.isObjectOrArray(value)) continue;
|
|
90
130
|
let child = copies.get(value);
|
|
91
131
|
|
|
92
132
|
if (child === undefined) {
|
|
93
|
-
const created
|
|
94
|
-
? []
|
|
95
|
-
: Object.create(Object.getPrototypeOf(value));
|
|
133
|
+
const created = copyOwn(value);
|
|
96
134
|
|
|
97
|
-
Object.assign(created, value);
|
|
98
135
|
copies.set(value, created);
|
|
99
136
|
owned.push(created);
|
|
100
|
-
pending.push(
|
|
137
|
+
pending.push(created);
|
|
101
138
|
child = created;
|
|
102
139
|
}
|
|
103
|
-
|
|
140
|
+
setOwn(next, key, child);
|
|
104
141
|
}
|
|
105
142
|
}
|
|
106
143
|
for (const value of owned) Object.freeze(value);
|
|
@@ -109,17 +146,17 @@ const capturePayload = (payload: CanonicalRecordPayload) => {
|
|
|
109
146
|
};
|
|
110
147
|
|
|
111
148
|
/** Schema-created structures are private; detach JSON pass-throughs using the same owned copy. */
|
|
112
|
-
const ownWire = (wire:
|
|
113
|
-
const pending: Array<object> = Predicate.
|
|
149
|
+
const ownWire = <Wire extends RecordJson>(wire: Wire, copies: WeakMap<object, object>): Wire => {
|
|
150
|
+
const pending: Array<object> = Predicate.isObjectOrArray(wire) ? [wire] : [];
|
|
114
151
|
|
|
115
152
|
while (pending.length > 0) {
|
|
116
153
|
const next = pending.pop()!;
|
|
117
154
|
|
|
118
155
|
for (const [key, value] of Object.entries(next)) {
|
|
119
|
-
if (!Predicate.
|
|
156
|
+
if (!Predicate.isObjectOrArray(value)) continue;
|
|
120
157
|
const copy = copies.get(value);
|
|
121
158
|
|
|
122
|
-
if (copy !== undefined)
|
|
159
|
+
if (copy !== undefined) setOwn(next, key, copy);
|
|
123
160
|
else pending.push(value);
|
|
124
161
|
}
|
|
125
162
|
Object.freeze(next);
|
|
@@ -129,66 +166,85 @@ const ownWire = (wire: RecordJson, copies: WeakMap<object, object>): RecordJson
|
|
|
129
166
|
};
|
|
130
167
|
|
|
131
168
|
/** Capture at the Schema boundary; only the privately owned result can reuse its encoding. */
|
|
132
|
-
export const captureRecord = (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Object.freeze(createdAt);
|
|
149
|
-
|
|
150
|
-
const canonical = Object.freeze(
|
|
151
|
-
new RecordEnvelope(
|
|
152
|
-
{
|
|
153
|
-
...input,
|
|
154
|
-
createdAt,
|
|
155
|
-
payload: owned.payload,
|
|
156
|
-
},
|
|
157
|
-
{ disableChecks: true },
|
|
158
|
-
),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const encoding = Object.freeze({
|
|
162
|
-
canonical,
|
|
163
|
-
wire,
|
|
164
|
-
json,
|
|
165
|
-
bytes,
|
|
166
|
-
progress: progressRecord(canonical, bytes),
|
|
167
|
-
});
|
|
169
|
+
export const captureRecord = (
|
|
170
|
+
input: RecordEnvelope,
|
|
171
|
+
): Result.Result<CapturedRecordEncoding, RecordEncodingError> => {
|
|
172
|
+
try {
|
|
173
|
+
const existing = captured.get(input);
|
|
174
|
+
|
|
175
|
+
if (existing !== undefined) return Result.succeed(existing);
|
|
176
|
+
const encoded = encodeRecord(input);
|
|
177
|
+
const owned = capturePayload(input.payload);
|
|
178
|
+
const wire = ownWire(encoded, owned.copies);
|
|
179
|
+
const serialized = boundedCanonicalJson(wire, recordLimits);
|
|
180
|
+
|
|
181
|
+
if (Result.isFailure(serialized))
|
|
182
|
+
return Result.fail(RecordEncodingError.make({ message: serialized.failure.message }));
|
|
183
|
+
const json = serialized.success;
|
|
184
|
+
const bytes = utf8ByteLength(json);
|
|
168
185
|
|
|
169
|
-
|
|
186
|
+
if (bytes > MAX_CANONICAL_RECORD_BYTES)
|
|
187
|
+
return Result.fail(
|
|
188
|
+
RecordEncodingError.make({ message: "Canonical JSON exceeds its byte bound" }),
|
|
189
|
+
);
|
|
190
|
+
const createdAt = DateTime.makeUnsafe(DateTime.toEpochMillis(input.createdAt));
|
|
191
|
+
|
|
192
|
+
// DateTime fills this cache lazily; populate it before freezing our private copy.
|
|
193
|
+
Object.freeze(DateTime.toPartsUtc(createdAt));
|
|
194
|
+
Object.freeze(createdAt);
|
|
195
|
+
|
|
196
|
+
const canonical = Object.freeze(
|
|
197
|
+
RecordEnvelope.make(
|
|
198
|
+
{
|
|
199
|
+
...input,
|
|
200
|
+
createdAt,
|
|
201
|
+
payload: owned.payload,
|
|
202
|
+
},
|
|
203
|
+
{ disableChecks: true },
|
|
204
|
+
),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const encoding = Object.freeze({
|
|
208
|
+
canonical,
|
|
209
|
+
wire,
|
|
210
|
+
json,
|
|
211
|
+
bytes,
|
|
212
|
+
progress: progressRecord(canonical, bytes),
|
|
213
|
+
});
|
|
170
214
|
|
|
171
|
-
|
|
215
|
+
captured.set(canonical, encoding);
|
|
216
|
+
|
|
217
|
+
return Result.succeed(encoding);
|
|
218
|
+
} catch (cause) {
|
|
219
|
+
return Result.fail(
|
|
220
|
+
RecordEncodingError.make({ message: "Canonical record capture failed", cause }),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
172
223
|
};
|
|
173
224
|
|
|
174
225
|
/** Read evidence retains its original wire; fresh writes use the captured Schema encoding. */
|
|
175
|
-
export const recordEncoding = (
|
|
226
|
+
export const recordEncoding = (
|
|
227
|
+
record: RecordEnvelope,
|
|
228
|
+
): Result.Result<RecordEncoding, RecordEncodingError> => {
|
|
176
229
|
const existing = captured.get(record);
|
|
177
230
|
|
|
178
|
-
if (existing !== undefined) return existing;
|
|
179
|
-
if (record instanceof ExportedRecord) {
|
|
180
|
-
const json = canonicalJson(record.wire);
|
|
231
|
+
if (existing !== undefined) return Result.succeed(existing);
|
|
181
232
|
|
|
233
|
+
try {
|
|
234
|
+
if (!(record instanceof ExportedRecord)) return captureRecord(record);
|
|
235
|
+
const json = canonicalJson(record.wire);
|
|
182
236
|
const bytes = utf8ByteLength(json);
|
|
183
237
|
|
|
184
|
-
return {
|
|
238
|
+
return Result.succeed({
|
|
185
239
|
canonical: record,
|
|
186
240
|
wire: record.wire,
|
|
187
241
|
json,
|
|
188
242
|
bytes,
|
|
189
243
|
progress: progressRecord(record, bytes),
|
|
190
|
-
};
|
|
244
|
+
});
|
|
245
|
+
} catch (cause) {
|
|
246
|
+
return Result.fail(
|
|
247
|
+
RecordEncodingError.make({ message: "Canonical record encoding failed", cause }),
|
|
248
|
+
);
|
|
191
249
|
}
|
|
192
|
-
|
|
193
|
-
return captureRecord(record);
|
|
194
250
|
};
|
|
@@ -156,14 +156,14 @@ export const scheduleNextAfter = (
|
|
|
156
156
|
while (next <= afterMillis) {
|
|
157
157
|
const following = Cron.next(cron.success, next).getTime();
|
|
158
158
|
|
|
159
|
-
if (following <= next)
|
|
159
|
+
if (following <= next) return invalid("Cron has no supported next firing");
|
|
160
160
|
next = following;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
return next;
|
|
163
|
+
return checkedInstant(next, "Next cron occurrence");
|
|
164
164
|
},
|
|
165
165
|
catch: () => ScheduleValidationError.make({ message: "Cron has no supported next firing" }),
|
|
166
|
-
}).pipe(Result.flatMap((
|
|
166
|
+
}).pipe(Result.flatMap((result) => result));
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
};
|
|
@@ -250,15 +250,15 @@ export const scheduleDueOccurrence = (
|
|
|
250
250
|
let next = Cron.next(cron.success, intended).getTime();
|
|
251
251
|
|
|
252
252
|
while (next <= nowMillis) {
|
|
253
|
-
if (next <= intended)
|
|
253
|
+
if (next <= intended) return invalid("Cron has no supported due firing");
|
|
254
254
|
intended = next;
|
|
255
255
|
next = Cron.next(cron.success, intended).getTime();
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
return { intended, next };
|
|
258
|
+
return Result.succeed({ intended, next });
|
|
259
259
|
},
|
|
260
260
|
catch: () => ScheduleValidationError.make({ message: "Cron has no supported due firing" }),
|
|
261
|
-
});
|
|
261
|
+
}).pipe(Result.flatMap((result) => result));
|
|
262
262
|
|
|
263
263
|
if (Result.isFailure(due)) return Result.fail(due.failure);
|
|
264
264
|
const next = checkedInstant(due.success.next, "Next cron occurrence");
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
|
|
3
|
+
import { summarizeModelUsage, type ModelCallUsage } from "../../core/Usage.ts";
|
|
4
|
+
|
|
5
|
+
/** Captured calls are additive and nonnegative; progress does not need attribution groups. */
|
|
6
|
+
export const continuationUsage = (calls: ReadonlyArray<ModelCallUsage>) =>
|
|
7
|
+
Effect.suspend(() => {
|
|
8
|
+
let inputTokens = 0;
|
|
9
|
+
let outputTokens = 0;
|
|
10
|
+
let costMicrousd = 0;
|
|
11
|
+
let knownWebSearchCalls = 0;
|
|
12
|
+
|
|
13
|
+
for (const call of calls) {
|
|
14
|
+
inputTokens += call.inputTokens.total;
|
|
15
|
+
outputTokens += call.outputTokens.total;
|
|
16
|
+
costMicrousd += call.costMicrousd;
|
|
17
|
+
knownWebSearchCalls += call.webSearchCalls ?? 0;
|
|
18
|
+
}
|
|
19
|
+
if (
|
|
20
|
+
Number.isSafeInteger(inputTokens) &&
|
|
21
|
+
Number.isSafeInteger(outputTokens) &&
|
|
22
|
+
Number.isSafeInteger(costMicrousd) &&
|
|
23
|
+
Number.isSafeInteger(knownWebSearchCalls)
|
|
24
|
+
)
|
|
25
|
+
return Effect.succeed({ modelCalls: calls.length, inputTokens, outputTokens, costMicrousd });
|
|
26
|
+
|
|
27
|
+
// Safe global sums bound every component/group. On overflow retain the full validator,
|
|
28
|
+
// including groups whose hosted-search coverage differs from the aggregate's coverage.
|
|
29
|
+
return Effect.map(summarizeModelUsage(calls), (summary) => ({
|
|
30
|
+
modelCalls: summary.modelCalls,
|
|
31
|
+
inputTokens: summary.inputTokens.total,
|
|
32
|
+
outputTokens: summary.outputTokens.total,
|
|
33
|
+
costMicrousd: summary.costMicrousd,
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
@@ -3207,70 +3207,66 @@ export const makeWorkerRuntime = Effect.fnUntraced(function* (options: WorkerRun
|
|
|
3207
3207
|
.get({ ownerThreadId: context.source.threadId, messageId })
|
|
3208
3208
|
.pipe(Effect.mapError(storageFailure("start")));
|
|
3209
3209
|
|
|
3210
|
-
const replay = (saved: MessageDeliveryRecord)
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
);
|
|
3222
|
-
|
|
3223
|
-
const replayPrincipal = yield* authorize(
|
|
3224
|
-
"start",
|
|
3225
|
-
"send",
|
|
3226
|
-
undefined,
|
|
3227
|
-
currentPrevious?.evidence,
|
|
3228
|
-
);
|
|
3210
|
+
const replay = Effect.fnUntraced(function* (saved: MessageDeliveryRecord) {
|
|
3211
|
+
const currentPrevious =
|
|
3212
|
+
command.continuationOf === undefined
|
|
3213
|
+
? undefined
|
|
3214
|
+
: yield* completedContinuation(
|
|
3215
|
+
context.source,
|
|
3216
|
+
command.continuationOf,
|
|
3217
|
+
command.target.id,
|
|
3218
|
+
command.delegationId,
|
|
3219
|
+
previous?.evidence,
|
|
3220
|
+
);
|
|
3229
3221
|
|
|
3230
|
-
|
|
3231
|
-
|
|
3222
|
+
const replayPrincipal = yield* authorize(
|
|
3223
|
+
"start",
|
|
3224
|
+
"send",
|
|
3225
|
+
undefined,
|
|
3226
|
+
currentPrevious?.evidence,
|
|
3227
|
+
);
|
|
3232
3228
|
|
|
3233
|
-
|
|
3234
|
-
|
|
3229
|
+
yield* binding(command.target, "start");
|
|
3230
|
+
const metadata = saved.envelope.workerAdmission;
|
|
3235
3231
|
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
origin.
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3232
|
+
if (metadata === undefined) return yield* failure("start", "idempotency-conflict");
|
|
3233
|
+
const origin = metadata.origin;
|
|
3234
|
+
|
|
3235
|
+
if (
|
|
3236
|
+
!Schema.toEquivalence(Schema.UndefinedOr(WorkerContinuation))(
|
|
3237
|
+
origin.continuationOf,
|
|
3238
|
+
currentPrevious?.evidence,
|
|
3239
|
+
) ||
|
|
3240
|
+
origin.firstMessageId !== messageId ||
|
|
3241
|
+
metadata.messageId !== messageId ||
|
|
3242
|
+
origin.source.threadId !== context.source.threadId ||
|
|
3243
|
+
origin.worker.delegationId !== command.delegationId ||
|
|
3244
|
+
origin.worker.targetAgentId !== command.target.id ||
|
|
3245
|
+
!sameJson(metadata.parameters, parameters) ||
|
|
3246
|
+
!Schema.toEquivalence(SubagentGrant)(origin.grant, grant) ||
|
|
3247
|
+
origin.budgetScope !== effectiveScope ||
|
|
3248
|
+
origin.depth !== context.depth + 1 ||
|
|
3249
|
+
(!("prepare" in command) &&
|
|
3250
|
+
(!samePolicy(origin.policy, command.policy) ||
|
|
3251
|
+
!Schema.toEquivalence(WorkerOrigin.fields.budget)(origin.budget, command.budget) ||
|
|
3252
|
+
origin.toolCallAllowance !== command.toolCallAllowance))
|
|
3253
|
+
)
|
|
3254
|
+
return yield* failure("start", "idempotency-conflict");
|
|
3255
|
+
|
|
3256
|
+
yield* verifyContinuation(origin);
|
|
3257
|
+
|
|
3258
|
+
return {
|
|
3259
|
+
worker: origin.worker,
|
|
3260
|
+
delivery: yield* send(
|
|
3261
|
+
origin,
|
|
3262
|
+
messageId,
|
|
3263
|
+
"prepare" in command ? saved.envelope.input : command.encodedInput,
|
|
3264
|
+
parameters,
|
|
3265
|
+
replayPrincipal,
|
|
3266
|
+
"start",
|
|
3267
|
+
),
|
|
3268
|
+
};
|
|
3269
|
+
});
|
|
3274
3270
|
|
|
3275
3271
|
const existing = yield* retained();
|
|
3276
3272
|
|
|
@@ -3461,21 +3457,20 @@ export const makeWorkerRuntime = Effect.fnUntraced(function* (options: WorkerRun
|
|
|
3461
3457
|
.get({ ownerThreadId: context.source.threadId, messageId })
|
|
3462
3458
|
.pipe(Effect.mapError(storageFailure("followUp")));
|
|
3463
3459
|
|
|
3464
|
-
const replay = (saved: MessageDeliveryRecord)
|
|
3465
|
-
|
|
3466
|
-
const replayPrincipal = yield* authorize("followUp", "send", command.worker);
|
|
3460
|
+
const replay = Effect.fnUntraced(function* (saved: MessageDeliveryRecord) {
|
|
3461
|
+
const replayPrincipal = yield* authorize("followUp", "send", command.worker);
|
|
3467
3462
|
|
|
3468
|
-
|
|
3463
|
+
yield* currentPolicy;
|
|
3469
3464
|
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3465
|
+
return yield* send(
|
|
3466
|
+
origin,
|
|
3467
|
+
messageId,
|
|
3468
|
+
saved.envelope.input,
|
|
3469
|
+
command.encodedParameters,
|
|
3470
|
+
replayPrincipal,
|
|
3471
|
+
"followUp",
|
|
3472
|
+
);
|
|
3473
|
+
});
|
|
3479
3474
|
|
|
3480
3475
|
const existing = "prepare" in command ? yield* retained() : null;
|
|
3481
3476
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
3
|
|
|
4
4
|
import type { AnyDefinition } from "../core/Agent.ts";
|
|
@@ -47,7 +47,9 @@ export class MessagingHost extends Context.Service<
|
|
|
47
47
|
}
|
|
48
48
|
>()("@effect-agent/engine/MessagingHost") {
|
|
49
49
|
static readonly unavailable: MessagingHost["Service"] = {
|
|
50
|
-
context:
|
|
50
|
+
context: Effect.suspend(() =>
|
|
51
|
+
MessagingError.make({ operation: "context", reason: "unavailable" }),
|
|
52
|
+
),
|
|
51
53
|
send: () => MessagingError.make({ operation: "send", reason: "unavailable" }),
|
|
52
54
|
reply: () => MessagingError.make({ operation: "reply", reason: "unavailable" }),
|
|
53
55
|
inbox: () => MessagingError.make({ operation: "inbox", reason: "unavailable" }),
|
|
@@ -75,57 +75,56 @@ export class ThreadHistory extends Context.Service<
|
|
|
75
75
|
}
|
|
76
76
|
>()("@effect-agent/engine/ThreadHistory") {
|
|
77
77
|
/** Bind incremental history to the supplied Thread.Store, including scoped ownership views. */
|
|
78
|
-
static readonly
|
|
79
|
-
|
|
80
|
-
Effect.gen(function* () {
|
|
81
|
-
const threads = yield* ConversationStore;
|
|
78
|
+
static readonly makeFromStore = Effect.gen(function* () {
|
|
79
|
+
const threads = yield* ConversationStore;
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
81
|
+
const historyError = (cause: ThreadError): ThreadHistoryError =>
|
|
82
|
+
ThreadHistoryError.make({
|
|
83
|
+
threadId: cause.threadId,
|
|
84
|
+
reason:
|
|
85
|
+
cause._tag === "ThreadNotFound"
|
|
86
|
+
? "not-found"
|
|
87
|
+
: cause._tag === "ThreadLimitExceeded"
|
|
88
|
+
? "limit"
|
|
89
|
+
: cause._tag === "ThreadHistoryDiverged"
|
|
90
|
+
? "conflict"
|
|
91
|
+
: cause._tag === "ThreadOwnershipError"
|
|
92
|
+
? cause.reason === "closed"
|
|
93
|
+
? "fenced"
|
|
94
|
+
: "conflict"
|
|
95
|
+
: "encoding",
|
|
96
|
+
message:
|
|
97
|
+
cause._tag === "ThreadNotFound"
|
|
98
|
+
? "Thread history is not present in this application Scope"
|
|
99
|
+
: cause._tag === "ThreadLimitExceeded"
|
|
100
|
+
? `In-memory history exceeds the ${cause.limit} limit of ${cause.limitValue}`
|
|
101
|
+
: cause.message,
|
|
102
|
+
cause,
|
|
103
|
+
});
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
return ThreadHistory.of({
|
|
106
|
+
retention: "incremental",
|
|
107
|
+
memoryStore: threads,
|
|
108
|
+
load: (threadId) =>
|
|
109
|
+
threads.snapshot(threadId).pipe(Effect.map(toPrompt), Effect.mapError(historyError)),
|
|
110
|
+
open: Effect.fnUntraced(function* ({ threadId, runId }) {
|
|
111
|
+
const snapshot = yield* threads.create(threadId).pipe(Effect.mapError(historyError));
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
113
|
+
return {
|
|
114
|
+
prompt: toPrompt(snapshot),
|
|
115
|
+
stageInput: () => Effect.void,
|
|
116
|
+
stageHistory: ({ source }) =>
|
|
117
|
+
threads
|
|
118
|
+
.recordHistory(threadId, runId, source)
|
|
119
|
+
.pipe(Effect.asVoid, Effect.mapError(historyError)),
|
|
120
|
+
commit: () =>
|
|
121
|
+
threads.snapshot(threadId).pipe(Effect.asVoid, Effect.mapError(historyError)),
|
|
122
|
+
};
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
static readonly layerFromStore = Layer.effect(ThreadHistory, ThreadHistory.makeFromStore);
|
|
129
128
|
|
|
130
129
|
/** Retain history for the application Scope, within message and host capacity. Separate Layer builds own separate stores. */
|
|
131
130
|
static readonly layer = ThreadHistory.layerFromStore.pipe(Layer.provideMerge(layerMemory));
|