effect-durable-agent 0.1.0-alpha.8 → 0.1.0
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/README.md +5 -5
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{commands-Ce1ec6kH.d.ts → commands-BUquEZVP.d.ts} +31 -12
- package/dist/{compaction-BgDr5VJy.js → compaction-63iEDHHl.js} +63 -13
- package/dist/compaction-63iEDHHl.js.map +1 -0
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-Bezx3drD.d.ts} +16 -40
- package/dist/{core-CYT6DBaS.d.ts → core-BcimKMIv.d.ts} +5 -3
- package/dist/delivery-2ZILvoRD.js +507 -0
- package/dist/delivery-2ZILvoRD.js.map +1 -0
- package/dist/delivery-D3MxW4wg.d.ts +3026 -0
- package/dist/domain/command-queues.d.ts +81 -2
- package/dist/domain/command-queues.js +1 -1
- package/dist/domain/command-queues.js.map +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/context-projection.js +1 -1
- package/dist/domain/context-projection.js.map +1 -1
- package/dist/domain/message-transcript.d.ts +36 -2
- package/dist/domain/message-transcript.js +10 -2
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/model-usage.d.ts +1 -1
- package/dist/domain/model-usage.js +1 -1
- package/dist/domain/reduced-state-schema.d.ts +3 -992
- package/dist/domain/reduced-state-schema.js +126 -7
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +2 -2
- package/dist/domain/reduced-state.js +936 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +2 -0
- package/dist/domain/run-scheduling.js +127 -0
- package/dist/domain/run-scheduling.js.map +1 -0
- package/dist/{durable-br2C1bWK.d.ts → durable-168Womqp.d.ts} +8535 -2859
- package/dist/{durable-BGFvX7Mh.js → durable-D13w1Qr3.js} +229 -15
- package/dist/durable-D13w1Qr3.js.map +1 -0
- package/dist/{envelope-DxQzo5rN.js → envelope-BCzKUq_z.js} +12 -3
- package/dist/envelope-BCzKUq_z.js.map +1 -0
- package/dist/{envelope-DkZyMIgp.d.ts → envelope-Che6KatU.d.ts} +70 -7
- package/dist/{event-factory-DTFdy0Cb.js → event-factory-_vF1bIJ7.js} +7 -3
- package/dist/event-factory-_vF1bIJ7.js.map +1 -0
- package/dist/{events-LZFNoESe.d.ts → events-DwTARLMv.d.ts} +139 -137
- package/dist/{id-generator-Ckl8_XWW.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
- package/dist/in-memory-CeODnZhE.js +150 -0
- package/dist/in-memory-CeODnZhE.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/interpreter-DKGJ1sSx.js +1452 -0
- package/dist/interpreter-DKGJ1sSx.js.map +1 -0
- package/dist/{keep-alive-Chl5SJxy.d.ts → keep-alive-_zFCUvt3.d.ts} +1 -2
- package/dist/{model-resolver-BPPJAsuh.d.ts → model-resolver-DeBDK8XO.d.ts} +11 -5
- package/dist/{model-usage-CdBEkTwU.d.ts → model-usage-0GeHwaaU.d.ts} +2 -3
- package/dist/records--54mZEBx.js +675 -0
- package/dist/records--54mZEBx.js.map +1 -0
- package/dist/reduced-state-B1cvy8N_.d.ts +51110 -0
- package/dist/reduced-state-schema-B98exWxQ.d.ts +2338 -0
- package/dist/{reducer-registry-aFjz_ZLT.d.ts → reducer-registry-DhGVzHBV.d.ts} +12 -6
- package/dist/run-scheduling-wakeup-Mjic4tb_.d.ts +24 -0
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -2
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/id-generator.js +6 -12
- package/dist/services/id-generator.js.map +1 -1
- package/dist/services/keep-alive.d.ts +1 -1
- package/dist/services/keep-alive.js.map +1 -1
- package/dist/services/model-call.d.ts +15 -0
- package/dist/services/model-call.js +15 -0
- package/dist/services/model-call.js.map +1 -0
- package/dist/services/model-resolver.d.ts +1 -1
- package/dist/services/model-resolver.js +1 -1
- package/dist/services/model-resolver.js.map +1 -1
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +49 -5
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +19 -6
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -0
- package/dist/services/run-scheduler.js +25 -0
- package/dist/services/run-scheduler.js.map +1 -0
- package/dist/services/run-scheduling-wakeup.d.ts +2 -0
- package/dist/services/run-scheduling-wakeup.js +13 -0
- package/dist/services/run-scheduling-wakeup.js.map +1 -0
- package/dist/services/runtime-layer.d.ts +18 -31
- package/dist/services/runtime-layer.js +19 -13
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +31 -20
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +1 -1
- package/dist/services/session-event-observer.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +57 -10
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +127 -37
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.js +2 -1
- package/dist/services/sink-checkpoint-store.js.map +1 -1
- package/dist/services/sink-registry.d.ts +2 -2
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +6 -1
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +2 -2
- package/dist/services/tool-registry.js +12 -3
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +3 -3
- package/dist/services/tracing.js +2 -2
- package/dist/services/tracing.js.map +1 -1
- package/dist/{session-event-observer-DaFMKKNc.d.ts → session-event-observer-DlP9ITB2.d.ts} +3 -3
- package/dist/{session-state-aIqe9CLa.js → session-state-BehvUVyq.js} +669 -160
- package/dist/session-state-BehvUVyq.js.map +1 -0
- package/dist/session-store-BL6sfrnn.d.ts +3326 -0
- package/dist/{sink-checkpoint-store-M7qIxoSH.d.ts → sink-checkpoint-store-DvuHwvx_.d.ts} +3 -4
- package/dist/sink-registry-DskRcyOS.js +345 -0
- package/dist/sink-registry-DskRcyOS.js.map +1 -0
- package/dist/subscription-DZNWFDTV.d.ts +966 -0
- package/dist/subscription-DmO3BcdT.js +505 -0
- package/dist/subscription-DmO3BcdT.js.map +1 -0
- package/dist/testkit/layers.d.ts +31 -22
- package/dist/testkit/layers.js +23 -14
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +226 -0
- package/dist/testkit/transcript.js +1475 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tool-registry-BJaVNtw4.d.ts → tool-registry-CHHUU9BN.d.ts} +44 -8
- package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
- package/dist/transcript.d.ts +101 -0
- package/dist/transcript.js +107 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/commands.js +8 -3
- package/dist/types/commands.js.map +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/core.js +3 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +5 -5
- package/dist/types/events.js +3 -3
- package/dist/types/tracing.d.ts +1 -1
- package/dist/types/tracing.js.map +1 -1
- package/dist/websocket/events.d.ts +2 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket.d.ts +2123 -2552
- package/dist/websocket.js +628 -442
- package/dist/websocket.js.map +1 -1
- package/dist/window-read-Brov9VdQ.d.ts +113 -0
- package/dist/window-read-DPFAA1hM.js +264 -0
- package/dist/window-read-DPFAA1hM.js.map +1 -0
- package/package.json +42 -14
- package/dist/command-queues-DdDB_aYM.d.ts +0 -462
- package/dist/compaction-BEor3jKv.d.ts +0 -165
- package/dist/compaction-BgDr5VJy.js.map +0 -1
- package/dist/durable-BGFvX7Mh.js.map +0 -1
- package/dist/envelope-DxQzo5rN.js.map +0 -1
- package/dist/event-factory-DTFdy0Cb.js.map +0 -1
- package/dist/event-factory-pFzsPlDs.d.ts +0 -87
- package/dist/index-BVVgDSdq.d.ts +0 -1
- package/dist/message-transcript-DQNlzxle.d.ts +0 -32
- package/dist/prompt-projector-f4ElyXCE.d.ts +0 -39
- package/dist/reduced-state-DF0-6mbR.js +0 -921
- package/dist/reduced-state-DF0-6mbR.js.map +0 -1
- package/dist/runtime-DbTCb32-.d.ts +0 -63
- package/dist/session-query-l8xpJYp8.d.ts +0 -45
- package/dist/session-state-YHFzOGDf.d.ts +0 -861
- package/dist/session-state-aIqe9CLa.js.map +0 -1
- package/dist/session-store-Cpi_NwTR.d.ts +0 -206
- package/dist/sink-registry-NDgeyzO0.js +0 -272
- package/dist/sink-registry-NDgeyzO0.js.map +0 -1
- package/dist/sink-registry-T1wOUuzq.d.ts +0 -133
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as DurableEventEnvelope } from "./envelope-Che6KatU.js";
|
|
2
|
+
import { H as DecodedDurableEvent } from "./durable-168Womqp.js";
|
|
3
|
+
import "./events-DwTARLMv.js";
|
|
4
|
+
import { t as CommittedDurableEvent } from "./session-store-BL6sfrnn.js";
|
|
2
5
|
import * as Context from "effect/Context";
|
|
3
6
|
import * as Layer from "effect/Layer";
|
|
4
7
|
import * as Schema from "effect/Schema";
|
|
5
|
-
|
|
6
8
|
//#region src/services/reducer-registry.d.ts
|
|
7
9
|
/** Input accepted by the reducer constructor before schema codecs are materialized. */
|
|
8
|
-
interface EDAReducerDefinition<State, Name extends string = string> {
|
|
10
|
+
interface EDAReducerDefinition<State, Name extends string = string, E = DecodedDurableEvent> {
|
|
9
11
|
readonly name: Name;
|
|
10
12
|
readonly initial: State;
|
|
11
13
|
readonly stateSchema: Schema.Codec<State, unknown, never, never>;
|
|
12
14
|
readonly schemaVersion?: number;
|
|
13
15
|
readonly encode?: (state: State) => unknown;
|
|
14
16
|
readonly decode?: (payload: unknown) => State;
|
|
15
|
-
|
|
17
|
+
/** Return the next state without mutating the input; projections may be shared across sinks. */
|
|
18
|
+
reduce(state: State, event: CommittedDurableEvent<E>): State;
|
|
16
19
|
}
|
|
17
20
|
/** App-specific pure reducer over the durable session event log. */
|
|
18
21
|
interface EDAReducer<State = unknown, Name extends string = string> {
|
|
@@ -22,10 +25,13 @@ interface EDAReducer<State = unknown, Name extends string = string> {
|
|
|
22
25
|
readonly schemaVersion?: number;
|
|
23
26
|
encode(state: State): unknown;
|
|
24
27
|
decode(payload: unknown): State;
|
|
28
|
+
/** Return the next state without mutating the input; projections may be shared across sinks. */
|
|
25
29
|
reduce(state: State, event: CommittedDurableEvent): State;
|
|
26
30
|
}
|
|
27
31
|
/** Convenience constructor preserving a reducer's literal name and schema-derived state type. */
|
|
28
32
|
declare const EDAReducer: {
|
|
33
|
+
/** Select and narrow reducer input from one event schema; malformed registered events fail in the store. */
|
|
34
|
+
forEvents: <E extends DurableEventEnvelope, State, const Name extends string>(events: Schema.Codec<E, unknown, never, never>, reducer: EDAReducerDefinition<State, Name, E>) => EDAReducer<State, Name>;
|
|
29
35
|
make: <State, const Name extends string = string>(reducer: EDAReducerDefinition<State, Name>) => EDAReducer<State, Name>;
|
|
30
36
|
};
|
|
31
37
|
/** Snapshot of all app reducer states, keyed by reducer name. */
|
|
@@ -38,7 +44,7 @@ type EDAReducerStateForName<Entry extends EDASerializedReducerState, Name extend
|
|
|
38
44
|
readonly name: Name;
|
|
39
45
|
}>["state"];
|
|
40
46
|
/** Exact reducer object required for every member of a serialized state union. */
|
|
41
|
-
type EDAReducersFor<Entry extends EDASerializedReducerState> = { readonly [Name in Entry["name"]]: EDAReducer<EDAReducerStateForName<Entry, Name>, Name
|
|
47
|
+
type EDAReducersFor<Entry extends EDASerializedReducerState> = { readonly [Name in Entry["name"]]: EDAReducer<EDAReducerStateForName<Entry, Name>, Name>; };
|
|
42
48
|
/** Schema-backed app reducer registry used by both runtime folding and snapshot serialization. */
|
|
43
49
|
interface EDATypedReducerRegistry<EntrySchema extends Schema.Codec<EDASerializedReducerState, unknown, never, never>> {
|
|
44
50
|
readonly entrySchema: EntrySchema;
|
|
@@ -76,4 +82,4 @@ declare class EDAReducerRegistry extends EDAReducerRegistry_base {
|
|
|
76
82
|
declare const getEDAReducerState: <State, Name extends string>(snapshot: EDAReducerStateSnapshot, reducer: EDAReducer<State, Name>) => State;
|
|
77
83
|
//#endregion
|
|
78
84
|
export { EDAReducerStateSnapshot as a, decodeReducerState as c, encodeReducerState as d, getEDAReducerState as f, EDAReducerRegistryShape as i, defineEDAReducerRegistry as l, EDAReducerDefinition as n, EDAReducersFor as o, reducerSchemaVersion as p, EDAReducerRegistry as r, EDATypedReducerRegistry as s, EDAReducer as t, edaReservedReducerNamePrefix as u };
|
|
79
|
-
//# sourceMappingURL=reducer-registry-
|
|
85
|
+
//# sourceMappingURL=reducer-registry-DhGVzHBV.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { s as EDASessionStoreError } from "./session-store-BL6sfrnn.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
//#region src/services/run-scheduling-wakeup.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Host-owned durable retry obligation for undelivered run authorization requests.
|
|
8
|
+
* setPending(true) must arm a wakeup before returning, survive eviction, and keep
|
|
9
|
+
* retrying until setPending(false). The callback invokes retryRunSchedulingDelivery.
|
|
10
|
+
* Hosts must reconcile this obligation with their active-work alarms, never delete
|
|
11
|
+
* it when an unrelated lease ends, and reconstruct it before recovery releases work.
|
|
12
|
+
*/
|
|
13
|
+
interface RunSchedulingWakeupShape {
|
|
14
|
+
readonly setPending: (pending: boolean) => Effect.Effect<void, EDASessionStoreError>;
|
|
15
|
+
}
|
|
16
|
+
declare const RunSchedulingWakeup_base: Context.ServiceClass<RunSchedulingWakeup, "@effect-durable-agent/RunSchedulingWakeup", RunSchedulingWakeupShape>;
|
|
17
|
+
/** Required durable host capability when a scheduler can resolve Deferred. */
|
|
18
|
+
declare class RunSchedulingWakeup extends RunSchedulingWakeup_base {
|
|
19
|
+
/** Immediate runtimes need no wakeup; fail before persisting unsupported deferral. */
|
|
20
|
+
static readonly Unsupported: Layer.Layer<RunSchedulingWakeup, never, never>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { RunSchedulingWakeupShape as n, RunSchedulingWakeup as t };
|
|
24
|
+
//# sourceMappingURL=run-scheduling-wakeup-Mjic4tb_.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ApproximateTokenThresholdCompactionPolicyOptions, CompactionError, CompactionExecutor, CompactionExecutorInput, CompactionExecutorShape, CompactionOutput, CompactionPlan, CompactionPolicy, CompactionPolicyInput, CompactionPolicyShape, CompactionRunner, CompactionRunnerInput, CompactionRunnerShape, LanguageModelSummaryCompactionExecutorOptions, defaultCompactionCharsPerToken, defaultCompactionMinSummarizableTokens, defaultCompactionRetainTailTokens, defaultCompactionThresholdTokens };
|
|
1
|
+
import { Cn as defaultCompactionThresholdTokens, Sn as defaultCompactionSummaryInstructions, _n as LanguageModelSummaryCompactionExecutorOptions, an as CompactionError, bn as defaultCompactionMinSummarizableTokens, cn as CompactionExecutorShape, dn as CompactionPolicy, fn as CompactionPolicyInput, gn as CompactionRunnerShape, hn as CompactionRunnerInput, in as ApproximateTokenThresholdCompactionPolicyOptions, ln as CompactionOutput, mn as CompactionRunner, on as CompactionExecutor, pn as CompactionPolicyShape, sn as CompactionExecutorInput, un as CompactionPlan, vn as PromptPrefixSummaryCompactionExecutorOptions, wn as promptPrefixSummaryCompactionExecutor, xn as defaultCompactionRetainTailTokens, yn as defaultCompactionCharsPerToken } from "../reduced-state-B1cvy8N_.js";
|
|
2
|
+
export { ApproximateTokenThresholdCompactionPolicyOptions, CompactionError, CompactionExecutor, CompactionExecutorInput, CompactionExecutorShape, CompactionOutput, CompactionPlan, CompactionPolicy, CompactionPolicyInput, CompactionPolicyShape, CompactionRunner, CompactionRunnerInput, CompactionRunnerShape, LanguageModelSummaryCompactionExecutorOptions, PromptPrefixSummaryCompactionExecutorOptions, defaultCompactionCharsPerToken, defaultCompactionMinSummarizableTokens, defaultCompactionRetainTailTokens, defaultCompactionSummaryInstructions, defaultCompactionThresholdTokens, promptPrefixSummaryCompactionExecutor };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as CompactionPolicy, c as defaultCompactionMinSummarizableTokens, i as CompactionPlan, l as defaultCompactionRetainTailTokens, n as CompactionExecutor, o as CompactionRunner, r as CompactionOutput, s as defaultCompactionCharsPerToken, t as CompactionError, u as
|
|
2
|
-
export { CompactionError, CompactionExecutor, CompactionOutput, CompactionPlan, CompactionPolicy, CompactionRunner, defaultCompactionCharsPerToken, defaultCompactionMinSummarizableTokens, defaultCompactionRetainTailTokens, defaultCompactionThresholdTokens };
|
|
1
|
+
import { a as CompactionPolicy, c as defaultCompactionMinSummarizableTokens, d as defaultCompactionThresholdTokens, f as promptPrefixSummaryCompactionExecutor, i as CompactionPlan, l as defaultCompactionRetainTailTokens, n as CompactionExecutor, o as CompactionRunner, r as CompactionOutput, s as defaultCompactionCharsPerToken, t as CompactionError, u as defaultCompactionSummaryInstructions } from "../compaction-63iEDHHl.js";
|
|
2
|
+
export { CompactionError, CompactionExecutor, CompactionOutput, CompactionPlan, CompactionPolicy, CompactionRunner, defaultCompactionCharsPerToken, defaultCompactionMinSummarizableTokens, defaultCompactionRetainTailTokens, defaultCompactionSummaryInstructions, defaultCompactionThresholdTokens, promptPrefixSummaryCompactionExecutor };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as IdGeneratorShape, r as sequentialUuidV7, t as IdGenerator } from "../id-generator-
|
|
1
|
+
import { n as IdGeneratorShape, r as sequentialUuidV7, t as IdGenerator } from "../id-generator-BKGoKjt-.js";
|
|
2
2
|
export { IdGenerator, IdGeneratorShape, sequentialUuidV7 };
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import { CommandId, CompactionId, CorrelationId, EventId, InferenceId, MessageId, RunId, SessionId, SummaryId, ToolCallId, TurnId } from "../types/core.js";
|
|
1
|
+
import { CommandId, CompactionId, CorrelationId, EventId, InferenceId, MessageId, RunId, RunRequestId, SessionId, SummaryId, ToolCallId, TurnId } from "../types/core.js";
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
|
-
import
|
|
5
|
+
import { SecureRandom } from "effect/crypto";
|
|
6
6
|
//#region src/services/id-generator.ts
|
|
7
|
-
const WebCryptoLive = Layer.succeed(Crypto.Crypto, Crypto.make({
|
|
8
|
-
randomBytes: (size) => {
|
|
9
|
-
const bytes = new Uint8Array(size);
|
|
10
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
11
|
-
return bytes;
|
|
12
|
-
},
|
|
13
|
-
digest: () => Effect.die(/* @__PURE__ */ new Error("IdGenerator does not use Crypto.digest"))
|
|
14
|
-
}));
|
|
15
7
|
/** Mints framework-owned UUIDv7 lifecycle IDs for effect-durable-agent. */
|
|
16
8
|
var IdGenerator = class IdGenerator extends Context.Service()("@effect-durable-agent/IdGenerator") {
|
|
17
9
|
static Live = Layer.effect(IdGenerator, Effect.gen(function* () {
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
11
|
+
return makeIdGenerator(random.uuidV7());
|
|
12
|
+
})).pipe(Layer.provide(SecureRandom.layerWebCrypto));
|
|
20
13
|
static Deterministic = (ids) => Layer.sync(IdGenerator, () => {
|
|
21
14
|
let index = 0;
|
|
22
15
|
return makeIdGenerator(Effect.sync(() => {
|
|
@@ -42,6 +35,7 @@ const makeIdGenerator = (nextUuidV7) => ({
|
|
|
42
35
|
makeEventId: () => nextUuidV7.pipe(Effect.map((id) => EventId.make(id))),
|
|
43
36
|
makeCommandId: () => nextUuidV7.pipe(Effect.map((id) => CommandId.make(id))),
|
|
44
37
|
makeRunId: () => nextUuidV7.pipe(Effect.map((id) => RunId.make(id))),
|
|
38
|
+
makeRunRequestId: () => nextUuidV7.pipe(Effect.map((id) => RunRequestId.make(id))),
|
|
45
39
|
makeTurnId: () => nextUuidV7.pipe(Effect.map((id) => TurnId.make(id))),
|
|
46
40
|
makeInferenceId: () => nextUuidV7.pipe(Effect.map((id) => InferenceId.make(id))),
|
|
47
41
|
makeToolCallId: () => nextUuidV7.pipe(Effect.map((id) => ToolCallId.make(id))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-generator.js","names":[],"sources":["../../src/services/id-generator.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport
|
|
1
|
+
{"version":3,"file":"id-generator.js","names":[],"sources":["../../src/services/id-generator.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport { SecureRandom } from \"effect/crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nimport {\n InferenceId,\n CommandId,\n CompactionId,\n CorrelationId,\n EventId,\n MessageId,\n RunId,\n RunRequestId,\n SessionId,\n SummaryId,\n ToolCallId,\n TurnId,\n} from \"../types/core\";\n\n/** UUIDv7 minting capability for all framework-owned lifecycle identities. */\nexport interface IdGeneratorShape {\n readonly makeSessionId: () => Effect.Effect<SessionId>;\n readonly makeEventId: () => Effect.Effect<EventId>;\n readonly makeCommandId: () => Effect.Effect<CommandId>;\n readonly makeRunId: () => Effect.Effect<RunId>;\n readonly makeRunRequestId: () => Effect.Effect<RunRequestId>;\n readonly makeTurnId: () => Effect.Effect<TurnId>;\n readonly makeInferenceId: () => Effect.Effect<InferenceId>;\n readonly makeToolCallId: () => Effect.Effect<ToolCallId>;\n readonly makeMessageId: () => Effect.Effect<MessageId>;\n readonly makeCompactionId: () => Effect.Effect<CompactionId>;\n readonly makeSummaryId: () => Effect.Effect<SummaryId>;\n readonly makeCorrelationId: () => Effect.Effect<CorrelationId>;\n}\n\n/** Mints framework-owned UUIDv7 lifecycle IDs for effect-durable-agent. */\nexport class IdGenerator extends Context.Service<IdGenerator, IdGeneratorShape>()(\n \"@effect-durable-agent/IdGenerator\",\n) {\n static readonly Live = Layer.effect(\n IdGenerator,\n Effect.gen(function* () {\n const random = yield* SecureRandom.SecureRandom;\n return makeIdGenerator(random.uuidV7());\n }),\n ).pipe(Layer.provide(SecureRandom.layerWebCrypto));\n\n static readonly Deterministic = (ids: ReadonlyArray<string>) =>\n Layer.sync(IdGenerator, () => {\n let index = 0;\n return makeIdGenerator(\n Effect.sync(() => {\n const next = ids[index];\n if (next === undefined) {\n throw new Error(\"deterministic IdGenerator exhausted\");\n }\n index += 1;\n return next;\n }),\n );\n });\n\n /** Counter-based deterministic IDs; the nth minted ID is `sequentialUuidV7(n)`. */\n static readonly Sequential = Layer.sync(IdGenerator, () => {\n let counter = 0;\n return makeIdGenerator(\n Effect.sync(() => {\n counter += 1;\n return sequentialUuidV7(counter);\n }),\n );\n });\n}\n\n/** The UUIDv7-shaped value minted by `IdGenerator.Sequential` for counter `n` (1-based). */\nexport const sequentialUuidV7 = (n: number): string =>\n `00000000-0000-7000-8000-${n.toString(16).padStart(12, \"0\")}`;\n\nconst makeIdGenerator = (nextUuidV7: Effect.Effect<string>): IdGeneratorShape => ({\n makeSessionId: () => nextUuidV7.pipe(Effect.map((id) => SessionId.make(id))),\n makeEventId: () => nextUuidV7.pipe(Effect.map((id) => EventId.make(id))),\n makeCommandId: () => nextUuidV7.pipe(Effect.map((id) => CommandId.make(id))),\n makeRunId: () => nextUuidV7.pipe(Effect.map((id) => RunId.make(id))),\n makeRunRequestId: () => nextUuidV7.pipe(Effect.map((id) => RunRequestId.make(id))),\n makeTurnId: () => nextUuidV7.pipe(Effect.map((id) => TurnId.make(id))),\n makeInferenceId: () => nextUuidV7.pipe(Effect.map((id) => InferenceId.make(id))),\n makeToolCallId: () => nextUuidV7.pipe(Effect.map((id) => ToolCallId.make(id))),\n makeMessageId: () => nextUuidV7.pipe(Effect.map((id) => MessageId.make(id))),\n makeCompactionId: () => nextUuidV7.pipe(Effect.map((id) => CompactionId.make(id))),\n makeSummaryId: () => nextUuidV7.pipe(Effect.map((id) => SummaryId.make(id))),\n makeCorrelationId: () => nextUuidV7.pipe(Effect.map((id) => CorrelationId.make(id))),\n});\n"],"mappings":";;;;;;;AAqCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ,QAAuC,CAAC,CAC/E,mCACF,CAAC,CAAC;CACA,OAAgB,OAAO,MAAM,OAC3B,aACA,OAAO,IAAI,aAAa;EACtB,MAAM,SAAS,OAAO,aAAa;EACnC,OAAO,gBAAgB,OAAO,OAAO,CAAC;CACxC,CAAC,CACH,CAAC,CAAC,KAAK,MAAM,QAAQ,aAAa,cAAc,CAAC;CAEjD,OAAgB,iBAAiB,QAC/B,MAAM,KAAK,mBAAmB;EAC5B,IAAI,QAAQ;EACZ,OAAO,gBACL,OAAO,WAAW;GAChB,MAAM,OAAO,IAAI;GACjB,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,qCAAqC;GAEvD,SAAS;GACT,OAAO;EACT,CAAC,CACH;CACF,CAAC;;CAGH,OAAgB,aAAa,MAAM,KAAK,mBAAmB;EACzD,IAAI,UAAU;EACd,OAAO,gBACL,OAAO,WAAW;GAChB,WAAW;GACX,OAAO,iBAAiB,OAAO;EACjC,CAAC,CACH;CACF,CAAC;AACH;;AAGA,MAAa,oBAAoB,MAC/B,2BAA2B,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG;AAE5D,MAAM,mBAAmB,gBAAyD;CAChF,qBAAqB,WAAW,KAAK,OAAO,KAAK,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC;CAC3E,mBAAmB,WAAW,KAAK,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,CAAC,CAAC;CACvE,qBAAqB,WAAW,KAAK,OAAO,KAAK,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC;CAC3E,iBAAiB,WAAW,KAAK,OAAO,KAAK,OAAO,MAAM,KAAK,EAAE,CAAC,CAAC;CACnE,wBAAwB,WAAW,KAAK,OAAO,KAAK,OAAO,aAAa,KAAK,EAAE,CAAC,CAAC;CACjF,kBAAkB,WAAW,KAAK,OAAO,KAAK,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC;CACrE,uBAAuB,WAAW,KAAK,OAAO,KAAK,OAAO,YAAY,KAAK,EAAE,CAAC,CAAC;CAC/E,sBAAsB,WAAW,KAAK,OAAO,KAAK,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC;CAC7E,qBAAqB,WAAW,KAAK,OAAO,KAAK,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC;CAC3E,wBAAwB,WAAW,KAAK,OAAO,KAAK,OAAO,aAAa,KAAK,EAAE,CAAC,CAAC;CACjF,qBAAqB,WAAW,KAAK,OAAO,KAAK,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC;CAC3E,yBAAyB,WAAW,KAAK,OAAO,KAAK,OAAO,cAAc,KAAK,EAAE,CAAC,CAAC;AACrF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EDAKeepAliveLease, r as EDAKeepAliveShape, t as EDAKeepAlive } from "../keep-alive-
|
|
1
|
+
import { n as EDAKeepAliveLease, r as EDAKeepAliveShape, t as EDAKeepAlive } from "../keep-alive-_zFCUvt3.js";
|
|
2
2
|
export { EDAKeepAlive, EDAKeepAliveLease, EDAKeepAliveShape };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keep-alive.js","names":[],"sources":["../../src/services/keep-alive.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\n/** Host lifecycle lease held while finite EDA work is actively running. */\nexport interface EDAKeepAliveLease {\n readonly release: () => Promise<void>;\n}\n\n/** Host-provided wrapper for keeping finite active work alive. */\nexport interface EDAKeepAliveShape {\n /**\n * A host may suspend an idle session after ingress returns while model turns,\n * recovery drains, and durable sink catch-up still run in Effect fibers. Wrap\n * those finite active-work regions so the host can retain or schedule the\n * session until work completes, parks durably, fails, or is interrupted.\n * Long-lived fibers blocked on queues should not hold a lease.\n */\n readonly withActiveWork: <A, E, R>(\n label: string,\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E, R>;\n}\n\n/** Host keep-alive service for finite active EDA work roots. */\nexport class EDAKeepAlive extends Context.Service<EDAKeepAlive, EDAKeepAliveShape>()(\n \"@effect-durable-agent/EDAKeepAlive\",\n) {\n static readonly Noop = Layer.succeed(EDAKeepAlive, {\n withActiveWork: (_label, effect) => effect,\n } satisfies EDAKeepAliveShape);\n\n static readonly FromAcquire = (\n acquire: (label: string) => Promise<EDAKeepAliveLease>,\n ): Layer.Layer<EDAKeepAlive> =>\n Layer.succeed(EDAKeepAlive, {\n withActiveWork: (label, effect) =>\n Effect.acquireUseRelease(\n Effect.promise(() => acquire(label)),\n () => effect,\n (lease) => Effect.promise(() => lease.release()),\n ),\n } satisfies EDAKeepAliveShape);\n}\n"],"mappings":";;;;;AAyBA,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,
|
|
1
|
+
{"version":3,"file":"keep-alive.js","names":[],"sources":["../../src/services/keep-alive.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\n/** Host lifecycle lease held while finite EDA work is actively running. */\nexport interface EDAKeepAliveLease {\n readonly release: () => Promise<void>;\n}\n\n/** Host-provided wrapper for keeping finite active work alive. */\nexport interface EDAKeepAliveShape {\n /**\n * A host may suspend an idle session after ingress returns while model turns,\n * recovery drains, and durable sink catch-up still run in Effect fibers. Wrap\n * those finite active-work regions so the host can retain or schedule the\n * session until work completes, parks durably, fails, or is interrupted.\n * Long-lived fibers blocked on queues should not hold a lease.\n */\n readonly withActiveWork: <A, E, R>(\n label: string,\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E, R>;\n}\n\n/** Host keep-alive service for finite active EDA work roots. */\nexport class EDAKeepAlive extends Context.Service<EDAKeepAlive, EDAKeepAliveShape>()(\n \"@effect-durable-agent/EDAKeepAlive\",\n) {\n static readonly Noop = Layer.succeed(EDAKeepAlive, {\n withActiveWork: (_label, effect) => effect,\n } satisfies EDAKeepAliveShape);\n\n static readonly FromAcquire = (\n acquire: (label: string) => Promise<EDAKeepAliveLease>,\n ): Layer.Layer<EDAKeepAlive> =>\n Layer.succeed(EDAKeepAlive, {\n withActiveWork: (label, effect) =>\n Effect.acquireUseRelease(\n Effect.promise(() => acquire(label)),\n () => effect,\n (lease) => Effect.promise(() => lease.release()),\n ),\n } satisfies EDAKeepAliveShape);\n}\n"],"mappings":";;;;;AAyBA,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,CAAC,CAClF,oCACF,CAAC,CAAC;CACA,OAAgB,OAAO,MAAM,QAAQ,cAAc,EACjD,iBAAiB,QAAQ,WAAW,OACtC,CAA6B;CAE7B,OAAgB,eACd,YAEA,MAAM,QAAQ,cAAc,EAC1B,iBAAiB,OAAO,WACtB,OAAO,kBACL,OAAO,cAAc,QAAQ,KAAK,CAAC,SAC7B,SACL,UAAU,OAAO,cAAc,MAAM,QAAQ,CAAC,CACjD,EACJ,CAA6B;AACjC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as EDAModelToolkit } from "../tool-registry-CHHUU9BN.js";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as LanguageModel from "effect/ai/LanguageModel";
|
|
4
|
+
import * as Prompt from "effect/ai/Prompt";
|
|
5
|
+
import * as AiError from "effect/ai/AiError";
|
|
6
|
+
//#region src/services/model-call.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* One non-streaming model call that offers EDA's tools without executing them, so the request's
|
|
9
|
+
* tool definitions match every inference in the session (and therefore its provider cache).
|
|
10
|
+
* EDA owns tool execution; with resolution disabled the handlers' requirements are never used.
|
|
11
|
+
*/
|
|
12
|
+
declare const generateTextOfferingTools: (model: LanguageModel.LanguageModel, prompt: Prompt.RawInput, toolkit: EDAModelToolkit | undefined) => Effect.Effect<LanguageModel.GenerateTextResponse<{}>, AiError.AiError>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { generateTextOfferingTools };
|
|
15
|
+
//# sourceMappingURL=model-call.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/services/model-call.ts
|
|
2
|
+
/**
|
|
3
|
+
* One non-streaming model call that offers EDA's tools without executing them, so the request's
|
|
4
|
+
* tool definitions match every inference in the session (and therefore its provider cache).
|
|
5
|
+
* EDA owns tool execution; with resolution disabled the handlers' requirements are never used.
|
|
6
|
+
*/
|
|
7
|
+
const generateTextOfferingTools = (model, prompt, toolkit) => toolkit === void 0 ? model.generateText({ prompt }) : model.generateText({
|
|
8
|
+
prompt,
|
|
9
|
+
toolkit,
|
|
10
|
+
disableToolCallResolution: true
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { generateTextOfferingTools };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=model-call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-call.js","names":[],"sources":["../../src/services/model-call.ts"],"sourcesContent":["import type * as Effect from \"effect/Effect\";\nimport type * as AiError from \"effect/ai/AiError\";\nimport type * as LanguageModel from \"effect/ai/LanguageModel\";\nimport type * as Prompt from \"effect/ai/Prompt\";\n\nimport type { EDAModelToolkit } from \"./tool-registry\";\n\n/**\n * One non-streaming model call that offers EDA's tools without executing them, so the request's\n * tool definitions match every inference in the session (and therefore its provider cache).\n * EDA owns tool execution; with resolution disabled the handlers' requirements are never used.\n */\nexport const generateTextOfferingTools = (\n model: LanguageModel.LanguageModel,\n prompt: Prompt.RawInput,\n toolkit: EDAModelToolkit | undefined,\n): Effect.Effect<LanguageModel.GenerateTextResponse<{}>, AiError.AiError> =>\n (toolkit === undefined\n ? model.generateText({ prompt })\n : model.generateText({\n prompt,\n toolkit,\n disableToolCallResolution: true,\n } as never)) as Effect.Effect<LanguageModel.GenerateTextResponse<{}>, AiError.AiError>;\n"],"mappings":";;;;;;AAYA,MAAa,6BACX,OACA,QACA,YAEC,YAAY,KAAA,IACT,MAAM,aAAa,EAAE,OAAO,CAAC,IAC7B,MAAM,aAAa;CACjB;CACA;CACA,2BAA2B;AAC7B,CAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as ModelResolver } from "../model-resolver-
|
|
1
|
+
import { t as ModelResolver } from "../model-resolver-DeBDK8XO.js";
|
|
2
2
|
export { ModelResolver };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Layer from "effect/Layer";
|
|
4
|
-
import * as LanguageModel from "effect/
|
|
4
|
+
import * as LanguageModel from "effect/ai/LanguageModel";
|
|
5
5
|
//#region src/services/model-resolver.ts
|
|
6
6
|
/** Resolves a recorded selection into an executable provider service at a model-call boundary. */
|
|
7
7
|
var ModelResolver = class ModelResolver extends Context.Service()("@effect-durable-agent/ModelResolver") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver.js","names":[],"sources":["../../src/services/model-resolver.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as LanguageModel from \"effect/
|
|
1
|
+
{"version":3,"file":"model-resolver.js","names":[],"sources":["../../src/services/model-resolver.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as LanguageModel from \"effect/ai/LanguageModel\";\nimport type * as Prompt from \"effect/ai/Prompt\";\nimport type { ModelSelectionPayload } from \"../types/events\";\n\n/** Resolves a recorded selection into an executable provider service at a model-call boundary. */\nexport class ModelResolver extends Context.Service<\n ModelResolver,\n {\n readonly resolve: (\n selection: ModelSelectionPayload | undefined,\n ) => Effect.Effect<LanguageModel.LanguageModel>;\n /**\n * Rewrites an EDA prompt into the selected provider's request shape just before a model call,\n * for example turning EDA cache hints into provider cache breakpoints. Defaults to identity.\n */\n readonly preparePrompt?: (\n selection: ModelSelectionPayload | undefined,\n prompt: Prompt.Prompt,\n ) => Prompt.Prompt;\n }\n>()(\"@effect-durable-agent/ModelResolver\") {\n /** Fixed provider implementation for deterministic tests and single-model hosts. */\n static readonly Fixed = Layer.effect(\n ModelResolver,\n Effect.gen(function* () {\n const model = yield* LanguageModel.LanguageModel;\n return { resolve: () => Effect.succeed(model) };\n }),\n );\n}\n"],"mappings":";;;;;;AAQA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ,QAezC,CAAC,CAAC,qCAAqC,CAAC,CAAC;;CAEzC,OAAgB,QAAQ,MAAM,OAC5B,eACA,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,cAAc;EACnC,OAAO,EAAE,eAAe,OAAO,QAAQ,KAAK,EAAE;CAChD,CAAC,CACH;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { EDAProjectedPromptContext, EDAPromptProjectionInput, EDAPromptProjector, EDAPromptProjectorShape, buildEDAPrompt };
|
|
1
|
+
import { An as EDAPromptProjector, Dn as EDANativeCompaction, Fn as isEDACacheBreakpoint, In as nativeCompactionSummaryMessage, Mn as EDA_PROMPT_OPTIONS_KEY, Nn as buildEDAPrompt, On as EDAProjectedPromptContext, Pn as getNativeCompaction, jn as EDAPromptProjectorShape, kn as EDAPromptProjectionInput } from "../reduced-state-B1cvy8N_.js";
|
|
2
|
+
export { EDANativeCompaction, EDAProjectedPromptContext, EDAPromptProjectionInput, EDAPromptProjector, EDAPromptProjectorShape, EDA_PROMPT_OPTIONS_KEY, buildEDAPrompt, getNativeCompaction, isEDACacheBreakpoint, nativeCompactionSummaryMessage };
|
|
@@ -2,7 +2,7 @@ import { contextProjectionPrompt } from "../domain/message-transcript.js";
|
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
|
-
import * as Prompt from "effect/
|
|
5
|
+
import * as Prompt from "effect/ai/Prompt";
|
|
6
6
|
//#region src/services/prompt-projector.ts
|
|
7
7
|
/** Build a provider prompt entirely from the current durable state projection. */
|
|
8
8
|
const buildEDAPrompt = (projector, input) => Effect.gen(function* () {
|
|
@@ -10,13 +10,33 @@ const buildEDAPrompt = (projector, input) => Effect.gen(function* () {
|
|
|
10
10
|
const context = yield* projector.projectContext(input);
|
|
11
11
|
const transcript = contextProjectionPrompt(state, input.context);
|
|
12
12
|
const instructionBoundary = firstNonSystemMessageIndex(transcript.content);
|
|
13
|
+
const instructions = [...transcript.content.slice(0, instructionBoundary), ...context.instructions];
|
|
14
|
+
const history = transcript.content.slice(instructionBoundary);
|
|
13
15
|
return Prompt.fromMessages([
|
|
14
|
-
...
|
|
15
|
-
...
|
|
16
|
-
...transcript.content.slice(instructionBoundary),
|
|
16
|
+
...markLast(instructions),
|
|
17
|
+
...markLast(history),
|
|
17
18
|
...context.messages
|
|
18
19
|
]);
|
|
19
20
|
});
|
|
21
|
+
/** Prompt option namespace EDA uses for provider-neutral request hints. */
|
|
22
|
+
const EDA_PROMPT_OPTIONS_KEY = "effect-durable-agent";
|
|
23
|
+
/**
|
|
24
|
+
* Whether a message ends a stable prefix worth caching. EDA marks the end of the instruction
|
|
25
|
+
* prefix and the end of durable history, never the per-request data messages after it; provider
|
|
26
|
+
* adapters translate the hint into their own cache breakpoints.
|
|
27
|
+
*/
|
|
28
|
+
const isEDACacheBreakpoint = (message) => {
|
|
29
|
+
const hint = message.options[EDA_PROMPT_OPTIONS_KEY];
|
|
30
|
+
return isHintRecord(hint) && hint.cacheBreakpoint === true;
|
|
31
|
+
};
|
|
32
|
+
const isHintRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
const markLast = (messages) => messages.map((message, index) => index === messages.length - 1 ? {
|
|
34
|
+
...message,
|
|
35
|
+
options: {
|
|
36
|
+
...message.options,
|
|
37
|
+
[EDA_PROMPT_OPTIONS_KEY]: { cacheBreakpoint: true }
|
|
38
|
+
}
|
|
39
|
+
} : message);
|
|
20
40
|
const firstNonSystemMessageIndex = (messages) => {
|
|
21
41
|
const index = messages.findIndex((message) => message.role !== "system");
|
|
22
42
|
return index === -1 ? messages.length : index;
|
|
@@ -31,7 +51,31 @@ var EDAPromptProjector = class EDAPromptProjector extends Context.Service()("@ef
|
|
|
31
51
|
projectState: (input) => Effect.succeed(input.state)
|
|
32
52
|
});
|
|
33
53
|
};
|
|
54
|
+
/** Summary prompt message carrying readable text plus the provider-native compaction items. */
|
|
55
|
+
const nativeCompactionSummaryMessage = (text, native) => Prompt.makeMessage("user", {
|
|
56
|
+
content: [Prompt.textPart({ text })],
|
|
57
|
+
options: { [EDA_PROMPT_OPTIONS_KEY]: { nativeCompaction: {
|
|
58
|
+
provider: native.provider,
|
|
59
|
+
modelId: native.modelId,
|
|
60
|
+
items: [...native.items]
|
|
61
|
+
} } }
|
|
62
|
+
});
|
|
63
|
+
/** Native compaction items stored on a prompt message, if any. */
|
|
64
|
+
const getNativeCompaction = (message) => {
|
|
65
|
+
const hint = message.options[EDA_PROMPT_OPTIONS_KEY];
|
|
66
|
+
if (!isHintRecord(hint)) return void 0;
|
|
67
|
+
const native = hint.nativeCompaction;
|
|
68
|
+
if (!isHintRecord(native)) return void 0;
|
|
69
|
+
const { provider, modelId, items } = native;
|
|
70
|
+
if (typeof provider !== "string" || typeof modelId !== "string" || !isJsonArray(items)) return;
|
|
71
|
+
return {
|
|
72
|
+
provider,
|
|
73
|
+
modelId,
|
|
74
|
+
items
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const isJsonArray = (value) => Array.isArray(value);
|
|
34
78
|
//#endregion
|
|
35
|
-
export { EDAPromptProjector, buildEDAPrompt };
|
|
79
|
+
export { EDAPromptProjector, EDA_PROMPT_OPTIONS_KEY, buildEDAPrompt, getNativeCompaction, isEDACacheBreakpoint, nativeCompactionSummaryMessage };
|
|
36
80
|
|
|
37
81
|
//# sourceMappingURL=prompt-projector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-projector.js","names":[],"sources":["../../src/services/prompt-projector.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Prompt from \"effect/
|
|
1
|
+
{"version":3,"file":"prompt-projector.js","names":[],"sources":["../../src/services/prompt-projector.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Prompt from \"effect/ai/Prompt\";\nimport type * as Schema from \"effect/Schema\";\n\nimport { contextProjectionPrompt } from \"../domain/message-transcript\";\nimport type { ContextProjection } from \"../domain/context-projection\";\nimport type { ReducedState } from \"../domain/reduced-state\";\nimport type { SessionId } from \"../types/core\";\nimport type { EDAReducerStateSnapshot } from \"./reducer-registry\";\n\n/** Input for app-extensible state-to-LLM prompt projection. */\nexport interface EDAPromptProjectionInput {\n readonly sessionId: SessionId;\n readonly state: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n readonly context?: ContextProjection;\n}\n\n/** App-derived instructions and data inserted around the durable transcript. */\nexport interface EDAProjectedPromptContext {\n /** Instruction messages placed after durable system context and before transcript history. */\n readonly instructions: ReadonlyArray<Prompt.SystemMessage>;\n /** Data messages placed after transcript history and before scheduler-selected user messages. */\n readonly messages: ReadonlyArray<Prompt.UserMessage>;\n}\n\n/** Host-extensible projection from durable state into provider prompt context. */\nexport interface EDAPromptProjectorShape {\n readonly projectContext: (\n input: EDAPromptProjectionInput,\n ) => Effect.Effect<EDAProjectedPromptContext>;\n readonly projectState: (input: EDAPromptProjectionInput) => Effect.Effect<ReducedState>;\n}\n\n/** Build a provider prompt entirely from the current durable state projection. */\nexport const buildEDAPrompt = (\n projector: EDAPromptProjectorShape,\n input: EDAPromptProjectionInput,\n): Effect.Effect<Prompt.Prompt> =>\n Effect.gen(function* () {\n const state = yield* projector.projectState(input);\n const context = yield* projector.projectContext(input);\n const transcript = contextProjectionPrompt(state, input.context);\n const instructionBoundary = firstNonSystemMessageIndex(transcript.content);\n const instructions = [\n ...transcript.content.slice(0, instructionBoundary),\n ...context.instructions,\n ];\n const history = transcript.content.slice(instructionBoundary);\n return Prompt.fromMessages([\n ...markLast(instructions),\n ...markLast(history),\n ...context.messages,\n ]);\n });\n\n/** Prompt option namespace EDA uses for provider-neutral request hints. */\nexport const EDA_PROMPT_OPTIONS_KEY = \"effect-durable-agent\";\n\n/**\n * Whether a message ends a stable prefix worth caching. EDA marks the end of the instruction\n * prefix and the end of durable history, never the per-request data messages after it; provider\n * adapters translate the hint into their own cache breakpoints.\n */\nexport const isEDACacheBreakpoint = (message: Prompt.Message): boolean => {\n const hint: unknown = message.options[EDA_PROMPT_OPTIONS_KEY];\n return isHintRecord(hint) && hint.cacheBreakpoint === true;\n};\n\nconst isHintRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst markLast = <M extends Prompt.Message>(messages: ReadonlyArray<M>): ReadonlyArray<M> =>\n messages.map((message, index) =>\n index === messages.length - 1\n ? {\n ...message,\n options: { ...message.options, [EDA_PROMPT_OPTIONS_KEY]: { cacheBreakpoint: true } },\n }\n : message,\n );\n\nconst firstNonSystemMessageIndex = (messages: ReadonlyArray<Prompt.Message>): number => {\n const index = messages.findIndex((message) => message.role !== \"system\");\n return index === -1 ? messages.length : index;\n};\n\n/** Service that lets apps derive LLM context independently from UI projections. */\nexport class EDAPromptProjector extends Context.Service<\n EDAPromptProjector,\n EDAPromptProjectorShape\n>()(\"@effect-durable-agent/EDAPromptProjector\") {\n static readonly Default = Layer.succeed(EDAPromptProjector, {\n projectContext: () => Effect.succeed({ instructions: [], messages: [] }),\n projectState: (input) => Effect.succeed(input.state),\n } satisfies EDAPromptProjectorShape);\n}\n\n/**\n * Provider-native compaction output (an Anthropic `compaction` block, an OpenAI compacted window)\n * stored on the summary prompt message. The provider that produced it replays `items` verbatim in\n * place of the message; any other provider sees the message's readable summary text.\n */\nexport interface EDANativeCompaction {\n readonly provider: string;\n readonly modelId: string;\n readonly items: ReadonlyArray<Schema.Json>;\n}\n\n/** Summary prompt message carrying readable text plus the provider-native compaction items. */\nexport const nativeCompactionSummaryMessage = (\n text: string,\n native: EDANativeCompaction,\n): Prompt.UserMessage =>\n Prompt.makeMessage(\"user\", {\n content: [Prompt.textPart({ text })],\n options: {\n [EDA_PROMPT_OPTIONS_KEY]: {\n nativeCompaction: {\n provider: native.provider,\n modelId: native.modelId,\n items: [...native.items],\n },\n },\n },\n });\n\n/** Native compaction items stored on a prompt message, if any. */\nexport const getNativeCompaction = (message: Prompt.Message): EDANativeCompaction | undefined => {\n const hint: unknown = message.options[EDA_PROMPT_OPTIONS_KEY];\n if (!isHintRecord(hint)) return undefined;\n const native: unknown = hint.nativeCompaction;\n if (!isHintRecord(native)) return undefined;\n const { provider, modelId, items } = native;\n if (typeof provider !== \"string\" || typeof modelId !== \"string\" || !isJsonArray(items)) {\n return undefined;\n }\n return { provider, modelId, items };\n};\n\nconst isJsonArray = (value: unknown): value is ReadonlyArray<Schema.Json> => Array.isArray(value);\n"],"mappings":";;;;;;;AAqCA,MAAa,kBACX,WACA,UAEA,OAAO,IAAI,aAAa;CACtB,MAAM,QAAQ,OAAO,UAAU,aAAa,KAAK;CACjD,MAAM,UAAU,OAAO,UAAU,eAAe,KAAK;CACrD,MAAM,aAAa,wBAAwB,OAAO,MAAM,OAAO;CAC/D,MAAM,sBAAsB,2BAA2B,WAAW,OAAO;CACzE,MAAM,eAAe,CACnB,GAAG,WAAW,QAAQ,MAAM,GAAG,mBAAmB,GAClD,GAAG,QAAQ,YACb;CACA,MAAM,UAAU,WAAW,QAAQ,MAAM,mBAAmB;CAC5D,OAAO,OAAO,aAAa;EACzB,GAAG,SAAS,YAAY;EACxB,GAAG,SAAS,OAAO;EACnB,GAAG,QAAQ;CACb,CAAC;AACH,CAAC;;AAGH,MAAa,yBAAyB;;;;;;AAOtC,MAAa,wBAAwB,YAAqC;CACxE,MAAM,OAAgB,QAAQ,QAAQ;CACtC,OAAO,aAAa,IAAI,KAAK,KAAK,oBAAoB;AACxD;AAEA,MAAM,gBAAgB,UACpB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAErE,MAAM,YAAsC,aAC1C,SAAS,KAAK,SAAS,UACrB,UAAU,SAAS,SAAS,IACxB;CACE,GAAG;CACH,SAAS;EAAE,GAAG,QAAQ;GAAU,yBAAyB,EAAE,iBAAiB,KAAK;CAAE;AACrF,IACA,OACN;AAEF,MAAM,8BAA8B,aAAoD;CACtF,MAAM,QAAQ,SAAS,WAAW,YAAY,QAAQ,SAAS,QAAQ;CACvE,OAAO,UAAU,KAAK,SAAS,SAAS;AAC1C;;AAGA,IAAa,qBAAb,MAAa,2BAA2B,QAAQ,QAG9C,CAAC,CAAC,0CAA0C,CAAC,CAAC;CAC9C,OAAgB,UAAU,MAAM,QAAQ,oBAAoB;EAC1D,sBAAsB,OAAO,QAAQ;GAAE,cAAc,CAAC;GAAG,UAAU,CAAC;EAAE,CAAC;EACvE,eAAe,UAAU,OAAO,QAAQ,MAAM,KAAK;CACrD,CAAmC;AACrC;;AAcA,MAAa,kCACX,MACA,WAEA,OAAO,YAAY,QAAQ;CACzB,SAAS,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,CAAC;CACnC,SAAS,GACN,yBAAyB,EACxB,kBAAkB;EAChB,UAAU,OAAO;EACjB,SAAS,OAAO;EAChB,OAAO,CAAC,GAAG,OAAO,KAAK;CACzB,EACF,EACF;AACF,CAAC;;AAGH,MAAa,uBAAuB,YAA6D;CAC/F,MAAM,OAAgB,QAAQ,QAAQ;CACtC,IAAI,CAAC,aAAa,IAAI,GAAG,OAAO,KAAA;CAChC,MAAM,SAAkB,KAAK;CAC7B,IAAI,CAAC,aAAa,MAAM,GAAG,OAAO,KAAA;CAClC,MAAM,EAAE,UAAU,SAAS,UAAU;CACrC,IAAI,OAAO,aAAa,YAAY,OAAO,YAAY,YAAY,CAAC,YAAY,KAAK,GACnF;CAEF,OAAO;EAAE;EAAU;EAAS;CAAM;AACpC;AAEA,MAAM,eAAe,UAAwD,MAAM,QAAQ,KAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as EDAReducerStateSnapshot, c as decodeReducerState, d as encodeReducerState, f as getEDAReducerState, i as EDAReducerRegistryShape, l as defineEDAReducerRegistry, n as EDAReducerDefinition, o as EDAReducersFor, p as reducerSchemaVersion, r as EDAReducerRegistry, s as EDATypedReducerRegistry, t as EDAReducer, u as edaReservedReducerNamePrefix } from "../reducer-registry-
|
|
1
|
+
import { a as EDAReducerStateSnapshot, c as decodeReducerState, d as encodeReducerState, f as getEDAReducerState, i as EDAReducerRegistryShape, l as defineEDAReducerRegistry, n as EDAReducerDefinition, o as EDAReducersFor, p as reducerSchemaVersion, r as EDAReducerRegistry, s as EDATypedReducerRegistry, t as EDAReducer, u as edaReservedReducerNamePrefix } from "../reducer-registry-DhGVzHBV.js";
|
|
2
2
|
export { EDAReducer, EDAReducerDefinition, EDAReducerRegistry, EDAReducerRegistryShape, EDAReducerStateSnapshot, EDAReducersFor, EDATypedReducerRegistry, decodeReducerState, defineEDAReducerRegistry, edaReservedReducerNamePrefix, encodeReducerState, getEDAReducerState, reducerSchemaVersion };
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import { selectCommittedEvent } from "./session-store.js";
|
|
1
2
|
import * as Context from "effect/Context";
|
|
2
3
|
import * as Layer from "effect/Layer";
|
|
3
4
|
import * as Schema from "effect/Schema";
|
|
4
5
|
//#region src/services/reducer-registry.ts
|
|
5
6
|
/** Convenience constructor preserving a reducer's literal name and schema-derived state type. */
|
|
6
|
-
const EDAReducer = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const EDAReducer = {
|
|
8
|
+
/** Select and narrow reducer input from one event schema; malformed registered events fail in the store. */
|
|
9
|
+
forEvents: (events, reducer) => EDAReducer.make({
|
|
10
|
+
...reducer,
|
|
11
|
+
reduce: (state, entry) => {
|
|
12
|
+
const selected = selectCommittedEvent(events, entry);
|
|
13
|
+
return selected === void 0 ? state : reducer.reduce(state, selected);
|
|
14
|
+
}
|
|
15
|
+
}),
|
|
16
|
+
make: (reducer) => ({
|
|
17
|
+
...reducer,
|
|
18
|
+
encode: reducer.encode ?? ((state) => Schema.encodeUnknownSync(reducer.stateSchema)(state)),
|
|
19
|
+
decode: reducer.decode ?? ((payload) => Schema.decodeUnknownSync(reducer.stateSchema)(payload))
|
|
20
|
+
})
|
|
21
|
+
};
|
|
11
22
|
const reducerValues = (reducers) => Object.values(reducers);
|
|
12
23
|
/**
|
|
13
24
|
* Register an app's complete reducer set against its public serialized-state union.
|
|
@@ -43,7 +54,9 @@ var EDAReducerRegistry = class EDAReducerRegistry extends Context.Service()("@ef
|
|
|
43
54
|
/** Read one typed reducer state from a snapshot. */
|
|
44
55
|
const getEDAReducerState = (snapshot, reducer) => {
|
|
45
56
|
const state = snapshot.get(reducer.name);
|
|
46
|
-
|
|
57
|
+
if (state === void 0) return reducer.initial;
|
|
58
|
+
if (Schema.is(reducer.stateSchema)(state)) return state;
|
|
59
|
+
throw new Error(`Invalid in-memory reducer state for ${reducer.name}`);
|
|
47
60
|
};
|
|
48
61
|
function makeReducerRegistry(reducers) {
|
|
49
62
|
validateReducerNames(reducers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer-registry.js","names":[],"sources":["../../src/services/reducer-registry.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\n\nimport type
|
|
1
|
+
{"version":3,"file":"reducer-registry.js","names":[],"sources":["../../src/services/reducer-registry.ts"],"sourcesContent":["import type { DurableEventEnvelope } from \"../types/events\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\n\nimport { selectCommittedEvent, type CommittedDurableEvent } from \"./session-store\";\n\n/** Input accepted by the reducer constructor before schema codecs are materialized. */\nexport interface EDAReducerDefinition<\n State,\n Name extends string = string,\n E = import(\"../types/events/durable\").DecodedDurableEvent,\n> {\n readonly name: Name;\n readonly initial: State;\n readonly stateSchema: Schema.Codec<State, unknown, never, never>;\n readonly schemaVersion?: number;\n readonly encode?: (state: State) => unknown;\n readonly decode?: (payload: unknown) => State;\n /** Return the next state without mutating the input; projections may be shared across sinks. */\n reduce(state: State, event: CommittedDurableEvent<E>): State;\n}\n\n/** App-specific pure reducer over the durable session event log. */\nexport interface EDAReducer<State = unknown, Name extends string = string> {\n readonly name: Name;\n readonly initial: State;\n readonly stateSchema: Schema.Codec<State, unknown, never, never>;\n readonly schemaVersion?: number;\n encode(state: State): unknown;\n decode(payload: unknown): State;\n /** Return the next state without mutating the input; projections may be shared across sinks. */\n reduce(state: State, event: CommittedDurableEvent): State;\n}\n\n/** Convenience constructor preserving a reducer's literal name and schema-derived state type. */\nexport const EDAReducer = {\n /** Select and narrow reducer input from one event schema; malformed registered events fail in the store. */\n forEvents: <E extends DurableEventEnvelope, State, const Name extends string>(\n events: Schema.Codec<E, unknown, never, never>,\n reducer: EDAReducerDefinition<State, Name, E>,\n ): EDAReducer<State, Name> =>\n EDAReducer.make({\n ...reducer,\n reduce: (state, entry) => {\n const selected = selectCommittedEvent(events, entry);\n return selected === undefined ? state : reducer.reduce(state, selected);\n },\n }),\n make: <State, const Name extends string = string>(\n reducer: EDAReducerDefinition<State, Name>,\n ): EDAReducer<State, Name> => ({\n ...reducer,\n encode: reducer.encode ?? ((state) => Schema.encodeUnknownSync(reducer.stateSchema)(state)),\n decode: reducer.decode ?? ((payload) => Schema.decodeUnknownSync(reducer.stateSchema)(payload)),\n }),\n};\n\n/** Snapshot of all app reducer states, keyed by reducer name. */\nexport type EDAReducerStateSnapshot = ReadonlyMap<string, unknown>;\n\ninterface EDASerializedReducerState {\n readonly name: string;\n readonly state: unknown;\n}\n\ntype EDAReducerStateForName<\n Entry extends EDASerializedReducerState,\n Name extends Entry[\"name\"],\n> = Extract<Entry, { readonly name: Name }>[\"state\"];\n\n/** Exact reducer object required for every member of a serialized state union. */\nexport type EDAReducersFor<Entry extends EDASerializedReducerState> = {\n readonly [Name in Entry[\"name\"]]: EDAReducer<EDAReducerStateForName<Entry, Name>, Name>;\n};\n\n/** Schema-backed app reducer registry used by both runtime folding and snapshot serialization. */\nexport interface EDATypedReducerRegistry<\n EntrySchema extends Schema.Codec<EDASerializedReducerState, unknown, never, never>,\n> {\n readonly entrySchema: EntrySchema;\n readonly reducers: ReadonlyArray<EDAReducer>;\n readonly serialize: (snapshot: EDAReducerStateSnapshot) => ReadonlyArray<EntrySchema[\"Type\"]>;\n}\n\nconst reducerValues = (reducers: Readonly<Record<string, EDAReducer>>): ReadonlyArray<EDAReducer> =>\n Object.values(reducers);\n\n/**\n * Register an app's complete reducer set against its public serialized-state union.\n *\n * Missing reducers, extra reducers, reducer-name drift, and state-schema drift are\n * rejected by TypeScript at the registration site.\n */\nexport const defineEDAReducerRegistry = <\n EntrySchema extends Schema.Codec<EDASerializedReducerState, unknown, never, never>,\n>(\n entrySchema: EntrySchema,\n reducers: EDAReducersFor<EntrySchema[\"Type\"]>,\n): EDATypedReducerRegistry<EntrySchema> => {\n const values = reducerValues(reducers);\n const serializedStatesSchema = Schema.Array(entrySchema);\n return {\n entrySchema,\n reducers: values,\n serialize: (snapshot) =>\n Schema.decodeUnknownSync(serializedStatesSchema)(\n values.map((reducer) => ({\n name: reducer.name,\n state: snapshot.get(reducer.name) ?? reducer.initial,\n })),\n ),\n };\n};\n\n/** Registry that folds app-specific read-model state beside EDA reduced state. */\nexport interface EDAReducerRegistryShape {\n readonly reducers: ReadonlyArray<EDAReducer>;\n readonly initial: EDAReducerStateSnapshot;\n readonly reduce: (\n state: EDAReducerStateSnapshot,\n events: ReadonlyArray<CommittedDurableEvent>,\n ) => EDAReducerStateSnapshot;\n}\n\n/** Prefix reserved for framework-owned reducer checkpoints. */\nexport const edaReservedReducerNamePrefix = \"_eda.\";\n\n/** Return the persisted schema version for one reducer. */\nexport const reducerSchemaVersion = (reducer: EDAReducer): number => reducer.schemaVersion ?? 1;\n\n/** Encode one reducer state for durable checkpoint storage. */\nexport const encodeReducerState = <State, Name extends string>(\n reducer: EDAReducer<State, Name>,\n state: State,\n): unknown => reducer.encode(state);\n\n/** Decode one reducer state from durable checkpoint storage. */\nexport const decodeReducerState = <State, Name extends string>(\n reducer: EDAReducer<State, Name>,\n payload: unknown,\n): State => reducer.decode(payload);\n\n/** Registry for app-specific durable metadata reducers. */\nexport class EDAReducerRegistry extends Context.Service<\n EDAReducerRegistry,\n EDAReducerRegistryShape\n>()(\"@effect-durable-agent/EDAReducerRegistry\") {\n static readonly Empty = Layer.succeed(EDAReducerRegistry, makeReducerRegistry([]));\n\n static readonly Live = (reducers: ReadonlyArray<EDAReducer>) =>\n Layer.succeed(EDAReducerRegistry, makeReducerRegistry(reducers));\n}\n\n/** Read one typed reducer state from a snapshot. */\nexport const getEDAReducerState = <State, Name extends string>(\n snapshot: EDAReducerStateSnapshot,\n reducer: EDAReducer<State, Name>,\n): State => {\n const state = snapshot.get(reducer.name);\n if (state === undefined) return reducer.initial;\n if (Schema.is(reducer.stateSchema)(state)) return state;\n throw new Error(`Invalid in-memory reducer state for ${reducer.name}`);\n};\n\nfunction makeReducerRegistry(reducers: ReadonlyArray<EDAReducer>): EDAReducerRegistryShape {\n validateReducerNames(reducers);\n const initial = new Map(reducers.map((reducer) => [reducer.name, reducer.initial]));\n return {\n reducers,\n initial,\n reduce: (state, events) => {\n if (events.length === 0 || reducers.length === 0) {\n return state;\n }\n const next = new Map(state);\n for (const event of events) {\n for (const reducer of reducers) {\n const current = next.get(reducer.name) ?? reducer.initial;\n next.set(reducer.name, reducer.reduce(current, event));\n }\n }\n return next;\n },\n };\n}\n\nfunction validateReducerNames(reducers: ReadonlyArray<EDAReducer>): void {\n const seen = new Set<string>();\n for (const reducer of reducers) {\n if (reducer.name.startsWith(edaReservedReducerNamePrefix)) {\n throw new Error(\n `Reducer name ${reducer.name} uses reserved EDA prefix ${edaReservedReducerNamePrefix}`,\n );\n }\n if (seen.has(reducer.name)) {\n throw new Error(`Duplicate EDA reducer name ${reducer.name}`);\n }\n seen.add(reducer.name);\n }\n}\n"],"mappings":";;;;;;AAoCA,MAAa,aAAa;;CAExB,YACE,QACA,YAEA,WAAW,KAAK;EACd,GAAG;EACH,SAAS,OAAO,UAAU;GACxB,MAAM,WAAW,qBAAqB,QAAQ,KAAK;GACnD,OAAO,aAAa,KAAA,IAAY,QAAQ,QAAQ,OAAO,OAAO,QAAQ;EACxE;CACF,CAAC;CACH,OACE,aAC6B;EAC7B,GAAG;EACH,QAAQ,QAAQ,YAAY,UAAU,OAAO,kBAAkB,QAAQ,WAAW,CAAC,CAAC,KAAK;EACzF,QAAQ,QAAQ,YAAY,YAAY,OAAO,kBAAkB,QAAQ,WAAW,CAAC,CAAC,OAAO;CAC/F;AACF;AA6BA,MAAM,iBAAiB,aACrB,OAAO,OAAO,QAAQ;;;;;;;AAQxB,MAAa,4BAGX,aACA,aACyC;CACzC,MAAM,SAAS,cAAc,QAAQ;CACrC,MAAM,yBAAyB,OAAO,MAAM,WAAW;CACvD,OAAO;EACL;EACA,UAAU;EACV,YAAY,aACV,OAAO,kBAAkB,sBAAsB,CAAC,CAC9C,OAAO,KAAK,aAAa;GACvB,MAAM,QAAQ;GACd,OAAO,SAAS,IAAI,QAAQ,IAAI,KAAK,QAAQ;EAC/C,EAAE,CACJ;CACJ;AACF;;AAaA,MAAa,+BAA+B;;AAG5C,MAAa,wBAAwB,YAAgC,QAAQ,iBAAiB;;AAG9F,MAAa,sBACX,SACA,UACY,QAAQ,OAAO,KAAK;;AAGlC,MAAa,sBACX,SACA,YACU,QAAQ,OAAO,OAAO;;AAGlC,IAAa,qBAAb,MAAa,2BAA2B,QAAQ,QAG9C,CAAC,CAAC,0CAA0C,CAAC,CAAC;CAC9C,OAAgB,QAAQ,MAAM,QAAQ,oBAAoB,oBAAoB,CAAC,CAAC,CAAC;CAEjF,OAAgB,QAAQ,aACtB,MAAM,QAAQ,oBAAoB,oBAAoB,QAAQ,CAAC;AACnE;;AAGA,MAAa,sBACX,UACA,YACU;CACV,MAAM,QAAQ,SAAS,IAAI,QAAQ,IAAI;CACvC,IAAI,UAAU,KAAA,GAAW,OAAO,QAAQ;CACxC,IAAI,OAAO,GAAG,QAAQ,WAAW,CAAC,CAAC,KAAK,GAAG,OAAO;CAClD,MAAM,IAAI,MAAM,uCAAuC,QAAQ,MAAM;AACvE;AAEA,SAAS,oBAAoB,UAA8D;CACzF,qBAAqB,QAAQ;CAE7B,OAAO;EACL;EACA,SAAA,IAHkB,IAAI,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,QAAQ,OAAO,CAAC,CAGzE;EACN,SAAS,OAAO,WAAW;GACzB,IAAI,OAAO,WAAW,KAAK,SAAS,WAAW,GAC7C,OAAO;GAET,MAAM,OAAO,IAAI,IAAI,KAAK;GAC1B,KAAK,MAAM,SAAS,QAClB,KAAK,MAAM,WAAW,UAAU;IAC9B,MAAM,UAAU,KAAK,IAAI,QAAQ,IAAI,KAAK,QAAQ;IAClD,KAAK,IAAI,QAAQ,MAAM,QAAQ,OAAO,SAAS,KAAK,CAAC;GACvD;GAEF,OAAO;EACT;CACF;AACF;AAEA,SAAS,qBAAqB,UAA2C;CACvE,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,QAAQ,KAAK,WAAA,OAAuC,GACtD,MAAM,IAAI,MACR,gBAAgB,QAAQ,KAAK,4BAA4B,8BAC3D;EAEF,IAAI,KAAK,IAAI,QAAQ,IAAI,GACvB,MAAM,IAAI,MAAM,8BAA8B,QAAQ,MAAM;EAE9D,KAAK,IAAI,QAAQ,IAAI;CACvB;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Ct as RunScheduler, Dt as DeferredRunResolution, Et as RunSchedulingDeliveryError, Nt as RunSchedulingInput, Ot as LocalRunResolution, Tt as RunSchedulingDelivery, jt as RunResolution, wt as RunSchedulerShape } from "../reduced-state-B1cvy8N_.js";
|
|
2
|
+
export { DeferredRunResolution, LocalRunResolution, type RunResolution, RunScheduler, RunSchedulerShape, RunSchedulingDelivery, RunSchedulingDeliveryError, type RunSchedulingInput };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DeferredRunResolution, LocalRunResolution } from "../domain/run-scheduling.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
//#region src/services/run-scheduler.ts
|
|
7
|
+
/** Recoverable failure delivering a persisted request; it never acknowledges that request. */
|
|
8
|
+
var RunSchedulingDeliveryError = class extends Schema.TaggedError()("RunSchedulingDeliveryError", { message: Schema.String }) {};
|
|
9
|
+
/** Replaceable run-start integration, independent of persistence and host SDKs. */
|
|
10
|
+
var RunScheduler = class RunScheduler extends Context.Service()("@effect-durable-agent/RunScheduler") {
|
|
11
|
+
/** Preserve local execution without allocating IDs, issuing commands, or writing events. */
|
|
12
|
+
static Immediate = Layer.succeed(RunScheduler, {
|
|
13
|
+
resolve: () => Effect.succeed(LocalRunResolution.make({})),
|
|
14
|
+
deliver: () => Effect.die(/* @__PURE__ */ new Error("Immediate RunScheduler cannot deliver deferred requests"))
|
|
15
|
+
});
|
|
16
|
+
/** Defer every new run to a durable, idempotent external authorizer. */
|
|
17
|
+
static Deferred = (deliver) => Layer.succeed(RunScheduler, {
|
|
18
|
+
resolve: () => Effect.succeed(DeferredRunResolution.make({})),
|
|
19
|
+
deliver
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DeferredRunResolution, LocalRunResolution, RunScheduler, RunSchedulingDeliveryError };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=run-scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-scheduler.js","names":[],"sources":["../../src/services/run-scheduler.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schema from \"effect/Schema\";\n\nimport {\n DeferredRunResolution,\n LocalRunResolution,\n type RunResolution,\n type RunSchedulingInput,\n type RunSchedulingRequest,\n} from \"../domain/run-scheduling\";\nimport type { SessionId } from \"../types/core\";\n\nexport {\n DeferredRunResolution,\n LocalRunResolution,\n type RunResolution,\n type RunSchedulingInput,\n} from \"../domain/run-scheduling\";\n\n/** Recoverable failure delivering a persisted request; it never acknowledges that request. */\nexport class RunSchedulingDeliveryError extends Schema.TaggedError<RunSchedulingDeliveryError>()(\n \"RunSchedulingDeliveryError\",\n {\n message: Schema.String,\n },\n) {}\n\n/** At-least-once outbound delivery, separate from the serialized run-start decision. */\nexport type RunSchedulingDelivery = (input: {\n readonly sessionId: SessionId;\n readonly request: RunSchedulingRequest;\n}) => Effect.Effect<void, RunSchedulingDeliveryError>;\n\n/**\n * Run-start boundary called by SessionState after pure dispatch or recovery policy\n * selects work, before allocating its run ID or committing RunStarted.\n *\n * Resolution must finish promptly with Local or Deferred intent and must not contact\n * an external scheduler. SessionState persists Deferred intent before calling deliver\n * outside the control loop. A successful delivery must mean the scheduler durably\n * accepted responsibility for the request and will retry its trusted grant callback.\n * Calls may repeat after a restart; command identity is not an exactly-once key.\n */\nexport interface RunSchedulerShape {\n readonly resolve: (input: RunSchedulingInput) => Effect.Effect<RunResolution>;\n readonly deliver: RunSchedulingDelivery;\n}\n\n/** Replaceable run-start integration, independent of persistence and host SDKs. */\nexport class RunScheduler extends Context.Service<RunScheduler, RunSchedulerShape>()(\n \"@effect-durable-agent/RunScheduler\",\n) {\n /** Preserve local execution without allocating IDs, issuing commands, or writing events. */\n static readonly Immediate = Layer.succeed(RunScheduler, {\n resolve: () => Effect.succeed(LocalRunResolution.make({})),\n deliver: () => Effect.die(new Error(\"Immediate RunScheduler cannot deliver deferred requests\")),\n });\n\n /** Defer every new run to a durable, idempotent external authorizer. */\n static readonly Deferred = (deliver: RunSchedulingDelivery) =>\n Layer.succeed(RunScheduler, {\n resolve: () => Effect.succeed(DeferredRunResolution.make({})),\n deliver,\n });\n}\n"],"mappings":";;;;;;;AAsBA,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EACE,SAAS,OAAO,OAClB,CACF,CAAC,CAAC,CAAC;;AAwBH,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,CAAC,CAClF,oCACF,CAAC,CAAC;;CAEA,OAAgB,YAAY,MAAM,QAAQ,cAAc;EACtD,eAAe,OAAO,QAAQ,mBAAmB,KAAK,CAAC,CAAC,CAAC;EACzD,eAAe,OAAO,oBAAI,IAAI,MAAM,yDAAyD,CAAC;CAChG,CAAC;;CAGD,OAAgB,YAAY,YAC1B,MAAM,QAAQ,cAAc;EAC1B,eAAe,OAAO,QAAQ,sBAAsB,KAAK,CAAC,CAAC,CAAC;EAC5D;CACF,CAAC;AACL"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
//#region src/services/run-scheduling-wakeup.ts
|
|
5
|
+
/** Required durable host capability when a scheduler can resolve Deferred. */
|
|
6
|
+
var RunSchedulingWakeup = class RunSchedulingWakeup extends Context.Service()("@effect-durable-agent/RunSchedulingWakeup") {
|
|
7
|
+
/** Immediate runtimes need no wakeup; fail before persisting unsupported deferral. */
|
|
8
|
+
static Unsupported = Layer.succeed(RunSchedulingWakeup, { setPending: (pending) => pending ? Effect.die(/* @__PURE__ */ new Error("Deferred run scheduling requires a durable RunSchedulingWakeup host adapter")) : Effect.void });
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { RunSchedulingWakeup };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=run-scheduling-wakeup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-scheduling-wakeup.js","names":[],"sources":["../../src/services/run-scheduling-wakeup.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nimport type { EDASessionStoreError } from \"./session-store\";\n\n/**\n * Host-owned durable retry obligation for undelivered run authorization requests.\n * setPending(true) must arm a wakeup before returning, survive eviction, and keep\n * retrying until setPending(false). The callback invokes retryRunSchedulingDelivery.\n * Hosts must reconcile this obligation with their active-work alarms, never delete\n * it when an unrelated lease ends, and reconstruct it before recovery releases work.\n */\nexport interface RunSchedulingWakeupShape {\n readonly setPending: (pending: boolean) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/** Required durable host capability when a scheduler can resolve Deferred. */\nexport class RunSchedulingWakeup extends Context.Service<\n RunSchedulingWakeup,\n RunSchedulingWakeupShape\n>()(\"@effect-durable-agent/RunSchedulingWakeup\") {\n /** Immediate runtimes need no wakeup; fail before persisting unsupported deferral. */\n static readonly Unsupported = Layer.succeed(RunSchedulingWakeup, {\n setPending: (pending) =>\n pending\n ? Effect.die(\n new Error(\n \"Deferred run scheduling requires a durable RunSchedulingWakeup host adapter\",\n ),\n )\n : Effect.void,\n });\n}\n"],"mappings":";;;;;AAkBA,IAAa,sBAAb,MAAa,4BAA4B,QAAQ,QAG/C,CAAC,CAAC,2CAA2C,CAAC,CAAC;;CAE/C,OAAgB,cAAc,MAAM,QAAQ,qBAAqB,EAC/D,aAAa,YACX,UACI,OAAO,oBACL,IAAI,MACF,6EACF,CACF,IACA,OAAO,KACf,CAAC;AACH"}
|