effect-durable-agent 0.1.0-alpha.20 → 0.1.0-alpha.22
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 +2 -2
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{compaction-GD1cTPTZ.js → compaction-ajHZ5l7f.js} +58 -6
- package/dist/compaction-ajHZ5l7f.js.map +1 -0
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +2 -2
- package/dist/domain/message-transcript.js +9 -1
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/reduced-state.js +927 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{model-resolver-BfM5YA6A.d.ts → model-resolver-DUms5p6X.d.ts} +7 -1
- package/dist/{reduced-state-4FSWDdgT.d.ts → reduced-state-PJdig48e.d.ts} +5087 -5025
- package/dist/{reducer-registry-BIhncOHH.d.ts → reducer-registry-BAbhZs6d.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-BH2pHE0U.d.ts → run-scheduling-wakeup-QLK87OqG.d.ts} +2 -2
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -2
- 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.map +1 -1
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +48 -4
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +1 -1
- package/dist/services/run-scheduler.d.ts +1 -1
- package/dist/services/run-scheduling-wakeup.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +7 -7
- package/dist/services/runtime-layer.js +9 -9
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +2 -2
- 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 +1 -251
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/{session-state-BAzdzqV4.js → session-state-StlO5B2N.js} +51 -21
- package/dist/session-state-StlO5B2N.js.map +1 -0
- package/dist/session-store-ByDjS03N.d.ts +3184 -0
- package/dist/session-store-DcJjs4Fd.js +413 -0
- package/dist/session-store-DcJjs4Fd.js.map +1 -0
- package/dist/{sink-checkpoint-store-C-SY0cG2.d.ts → sink-checkpoint-store-BHb8YRTw.d.ts} +2 -2
- package/dist/{sink-registry-BnWfMABI.js → sink-registry-DEneTH8u.js} +4 -4
- package/dist/{sink-registry-BnWfMABI.js.map → sink-registry-DEneTH8u.js.map} +1 -1
- package/dist/testkit/layers.d.ts +7 -7
- package/dist/testkit/layers.js +9 -9
- package/dist/testkit/layers.js.map +1 -1
- package/dist/{tool-registry-wPsHagF_.d.ts → tool-registry-CxZ0iuYb.d.ts} +2 -2
- package/dist/transcript.d.ts +137 -0
- package/dist/transcript.js +178 -0
- package/dist/transcript.js.map +1 -0
- package/dist/websocket.d.ts +1 -1
- package/dist/window-read-B8aF_hDq.js +2173 -0
- package/dist/window-read-B8aF_hDq.js.map +1 -0
- package/package.json +9 -1
- package/dist/compaction-GD1cTPTZ.js.map +0 -1
- package/dist/reduced-state-Vuud6LCM.js +0 -942
- package/dist/reduced-state-Vuud6LCM.js.map +0 -1
- package/dist/services/session-store.js.map +0 -1
- package/dist/session-state-BAzdzqV4.js.map +0 -1
- package/dist/session-store-BpitF4Wg.d.ts +0 -191
|
@@ -1,252 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as DurableEventEnvelope } from "../envelope-BCzKUq_z.js";
|
|
3
|
-
import { H as DecodedDurableEvent, Nn as commandAdmittedEventType, Un as contextRebasedEventType, Wn as decodeDurableEventSync, kr as decodeRetainingExcess, mr as summaryCreatedEventType, qn as durableEventEnvelope } from "../durable-CD__3ztN.js";
|
|
4
|
-
import { CompactionSummaryArtifact } from "../domain/context-projection.js";
|
|
5
|
-
import * as Context from "effect/Context";
|
|
6
|
-
import * as Effect from "effect/Effect";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Schema from "effect/Schema";
|
|
9
|
-
import * as Stream from "effect/Stream";
|
|
10
|
-
import * as Cause from "effect/Cause";
|
|
11
|
-
import * as Ref from "effect/Ref";
|
|
12
|
-
import * as SchemaGetter from "effect/SchemaGetter";
|
|
13
|
-
//#region src/services/session-store.ts
|
|
14
|
-
/** A durable event after the store has assigned its replay position. */
|
|
15
|
-
const CommittedDurableEvent = Schema.Struct({
|
|
16
|
-
position: DurablePosition,
|
|
17
|
-
event: DurableEventEnvelope.pipe(Schema.decodeTo(Schema.declare(Schema.is(DecodedDurableEvent)), {
|
|
18
|
-
decode: SchemaGetter.transform(decodeDurableEventSync),
|
|
19
|
-
encode: SchemaGetter.transform(durableEventEnvelope)
|
|
20
|
-
}))
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Store-level failure surfaced by durable append, replay, and hydration APIs.
|
|
24
|
-
*
|
|
25
|
-
* The error intentionally stays storage-semantic rather than SQL-specific so
|
|
26
|
-
* framework services can treat SQL-backed hosts, in-memory tests, and future adapters
|
|
27
|
-
* as the same durability boundary.
|
|
28
|
-
*/
|
|
29
|
-
var EDASessionStoreError = class extends Schema.TaggedError()("EDASessionStoreError", { message: Schema.String }) {};
|
|
30
|
-
/** True when a Cause contains an escaped durable-store failure. */
|
|
31
|
-
const hasEDASessionStoreError = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && reason.error instanceof EDASessionStoreError);
|
|
32
|
-
/**
|
|
33
|
-
* One logical event to persist in the durable session log.
|
|
34
|
-
*
|
|
35
|
-
* Store adapters may split large logical payload fields into sidecar rows after
|
|
36
|
-
* the event insert assigns `seq`, but callers still provide one fat event.
|
|
37
|
-
*/
|
|
38
|
-
const DurableAppendEntry = Schema.Struct({ event: DurableEventEnvelope });
|
|
39
|
-
/**
|
|
40
|
-
* Ordered durable append intent. Adapters assign positions in entry order.
|
|
41
|
-
*
|
|
42
|
-
* This is the single write shape exposed to framework services. It avoids raw
|
|
43
|
-
* SQL and public transaction callbacks while still expressing the full atomic
|
|
44
|
-
* transition EDA needs for events, normalized bodies, and metadata.
|
|
45
|
-
*/
|
|
46
|
-
const DurableAppendBatch = Schema.Struct({ entries: Schema.Array(DurableAppendEntry) });
|
|
47
|
-
/** Indexed command-admission lookup used for idempotent ingress. */
|
|
48
|
-
const FindCommandAdmissionInput = Schema.Struct({
|
|
49
|
-
commandId: Schema.optionalKey(CommandId),
|
|
50
|
-
idempotencyKey: Schema.optionalKey(Schema.String)
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* SQL-agnostic durable storage port for one EDA session.
|
|
54
|
-
*
|
|
55
|
-
* Framework services depend on this semantic port rather than raw SQL. Host
|
|
56
|
-
* adapters own physical tables and synchronous transaction mechanics; callers
|
|
57
|
-
* only express durable append/replay/lookup intent.
|
|
58
|
-
*/
|
|
59
|
-
var EDASessionStore = class EDASessionStore extends Context.Service()("@effect-durable-agent/EDASessionStore") {
|
|
60
|
-
/** Deterministic in-memory implementation used by runtime and recovery tests. */
|
|
61
|
-
static InMemory = (sessionId) => Layer.effect(EDASessionStore, Effect.gen(function* () {
|
|
62
|
-
const data = yield* Ref.make(emptyInMemoryStoreData());
|
|
63
|
-
return makeInMemoryStore(sessionId, data);
|
|
64
|
-
}));
|
|
65
|
-
/** In-memory store seeded with a durable prefix; intended for recovery tests. */
|
|
66
|
-
static InMemorySeeded = (sessionId, events) => Layer.effect(EDASessionStore, Effect.gen(function* () {
|
|
67
|
-
const committed = seedCommittedEvents(sessionId, events);
|
|
68
|
-
const data = yield* Ref.make({
|
|
69
|
-
...emptyInMemoryStoreData(),
|
|
70
|
-
committed,
|
|
71
|
-
summaries: summariesFromCommittedEvents(committed)
|
|
72
|
-
});
|
|
73
|
-
return makeInMemoryStore(sessionId, data);
|
|
74
|
-
}));
|
|
75
|
-
};
|
|
76
|
-
const emptyInMemoryStoreData = () => ({
|
|
77
|
-
committed: [],
|
|
78
|
-
summaries: /* @__PURE__ */ new Map(),
|
|
79
|
-
reducerCheckpoints: /* @__PURE__ */ new Map()
|
|
80
|
-
});
|
|
81
|
-
const seedCommittedEvents = (sessionId, events) => {
|
|
82
|
-
const seen = /* @__PURE__ */ new Set();
|
|
83
|
-
return events.map((event, index) => {
|
|
84
|
-
if (event.sessionId !== sessionId) throw new Error(`EDASessionStore.InMemorySeeded is scoped to session ${sessionId}; received ${event.sessionId}`);
|
|
85
|
-
if (seen.has(event.eventId)) throw new Error(`Duplicate seed eventId ${event.eventId}`);
|
|
86
|
-
seen.add(event.eventId);
|
|
87
|
-
return {
|
|
88
|
-
position: durablePosition(SequenceNumber.make(index + 1)),
|
|
89
|
-
event: decodeDurableEventSync(DurableEventEnvelope.make(event))
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const summariesFromCommittedEvents = (events) => {
|
|
94
|
-
const summaries = /* @__PURE__ */ new Map();
|
|
95
|
-
for (const { event } of events) {
|
|
96
|
-
if (event.type !== summaryCreatedEventType) continue;
|
|
97
|
-
const payload = event.payload;
|
|
98
|
-
if (payload.summary !== void 0) {
|
|
99
|
-
const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);
|
|
100
|
-
summaries.set(summary.summaryId, summary);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return summaries;
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Build an in-memory store with one `Ref.modify` append critical section.
|
|
107
|
-
*
|
|
108
|
-
* The fake models the semantic atomicity of the production adapter without
|
|
109
|
-
* exposing SQL, so runtime tests exercise the same store contract.
|
|
110
|
-
*/
|
|
111
|
-
const makeInMemoryStore = (sessionId, data) => {
|
|
112
|
-
const ensureSession = (event) => Effect.gen(function* () {
|
|
113
|
-
if (event.sessionId === sessionId) return;
|
|
114
|
-
return yield* new EDASessionStoreError({ message: `EDASessionStore.InMemory is scoped to session ${sessionId}; received ${event.sessionId}` });
|
|
115
|
-
});
|
|
116
|
-
const append = (batch) => Effect.gen(function* () {
|
|
117
|
-
for (const entry of batch.entries) yield* ensureSession(entry.event);
|
|
118
|
-
return yield* Ref.modify(data, (current) => {
|
|
119
|
-
const nextEntries = [...current.committed];
|
|
120
|
-
const nextSummaries = new Map(current.summaries);
|
|
121
|
-
const committedEvents = [];
|
|
122
|
-
for (const entry of batch.entries) {
|
|
123
|
-
const { event } = entry;
|
|
124
|
-
const existing = nextEntries.find((entry) => entry.event.eventId === event.eventId);
|
|
125
|
-
if (existing !== void 0) {
|
|
126
|
-
committedEvents.push(existing);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const committed = {
|
|
130
|
-
position: durablePosition(SequenceNumber.make(nextEntries.length + 1)),
|
|
131
|
-
event: decodeDurableEventSync(DurableEventEnvelope.make(event))
|
|
132
|
-
};
|
|
133
|
-
nextEntries.push(committed);
|
|
134
|
-
committedEvents.push(committed);
|
|
135
|
-
if (committed.event.type === summaryCreatedEventType) {
|
|
136
|
-
const payload = committed.event.payload;
|
|
137
|
-
if (payload.summary === void 0) throw new Error("SummaryCreated requires summary payload");
|
|
138
|
-
const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);
|
|
139
|
-
if (payload.summaryId !== void 0 && summary.summaryId !== payload.summaryId) throw new Error("SummaryCreated summaryId does not match summary payload");
|
|
140
|
-
nextSummaries.set(summary.summaryId, summary);
|
|
141
|
-
}
|
|
142
|
-
if (committed.event.type === contextRebasedEventType) {
|
|
143
|
-
const payload = committed.event.payload;
|
|
144
|
-
if (payload.summaryId === void 0 || !nextSummaries.has(payload.summaryId)) throw new Error(`ContextRebased references unknown summaryId ${String(payload.summaryId)}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return [committedEvents, {
|
|
148
|
-
committed: nextEntries,
|
|
149
|
-
summaries: nextSummaries,
|
|
150
|
-
reducerCheckpoints: current.reducerCheckpoints
|
|
151
|
-
}];
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
append,
|
|
156
|
-
eventsAfter: (afterSeq) => Stream.fromIterableEffect(Ref.get(data).pipe(Effect.map(({ committed }) => committed.filter((entry) => entry.position.seq > afterSeq)))),
|
|
157
|
-
loadCommittedEventsBySeq: (seqs) => Ref.get(data).pipe(Effect.map(({ committed }) => {
|
|
158
|
-
const requested = new Set(seqs.map((seq) => Number(seq)));
|
|
159
|
-
return committed.filter((entry) => requested.has(Number(entry.position.seq)));
|
|
160
|
-
})),
|
|
161
|
-
findCommandAdmission: (input) => Ref.get(data).pipe(Effect.map(({ committed }) => committed.find((entry) => commandAdmissionMatches(entry, input)))),
|
|
162
|
-
loadSummaryArtifact: (summaryId) => Ref.get(data).pipe(Effect.map(({ summaries }) => summaries.get(summaryId))),
|
|
163
|
-
loadReducerCheckpoint: (name) => Ref.get(data).pipe(Effect.map(({ reducerCheckpoints }) => reducerCheckpoints.get(name))),
|
|
164
|
-
saveReducerCheckpoint: (checkpoint) => Ref.update(data, (current) => ({
|
|
165
|
-
...current,
|
|
166
|
-
reducerCheckpoints: new Map(current.reducerCheckpoints).set(checkpoint.name, checkpoint)
|
|
167
|
-
})),
|
|
168
|
-
saveReducerCheckpoints: (checkpoints) => Ref.update(data, (current) => {
|
|
169
|
-
const reducerCheckpoints = new Map(current.reducerCheckpoints);
|
|
170
|
-
for (const checkpoint of checkpoints) reducerCheckpoints.set(checkpoint.name, checkpoint);
|
|
171
|
-
return {
|
|
172
|
-
...current,
|
|
173
|
-
reducerCheckpoints
|
|
174
|
-
};
|
|
175
|
-
})
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
const commandAdmissionMatches = (entry, input) => {
|
|
179
|
-
if (entry.event.type !== commandAdmittedEventType) return false;
|
|
180
|
-
const admitted = entry.event.payload.command;
|
|
181
|
-
if (admitted === void 0) return false;
|
|
182
|
-
if (input.idempotencyKey !== void 0 && admitted.idempotencyKey === input.idempotencyKey) return true;
|
|
183
|
-
return input.commandId !== void 0 && admitted.commandId === input.commandId;
|
|
184
|
-
};
|
|
185
|
-
const eventNamespaces = (ast) => {
|
|
186
|
-
if (ast._tag === "Union") return ast.types.flatMap(eventNamespaces);
|
|
187
|
-
if (ast._tag === "Objects") {
|
|
188
|
-
const namespace = ast.propertySignatures.find((field) => field.name === "namespace")?.type;
|
|
189
|
-
if (namespace?._tag === "Literal" && typeof namespace.literal === "string") return [namespace.literal];
|
|
190
|
-
}
|
|
191
|
-
throw new Error("App event schemas must be a union of structs with literal namespaces");
|
|
192
|
-
};
|
|
193
|
-
/** Attach the app decoder to every event-returning store operation without changing storage bytes. */
|
|
194
|
-
const registerAppEvents = (store, schema) => {
|
|
195
|
-
const namespaces = new Set(eventNamespaces(schema.ast));
|
|
196
|
-
const decode = decodeRetainingExcess(schema);
|
|
197
|
-
const envelopeKey = (event) => JSON.stringify(Schema.encodeSync(DurableEventEnvelope)(event));
|
|
198
|
-
const decodeEntry = (entry, prepared) => {
|
|
199
|
-
if (entry.event.namespace !== "__foreign" || !namespaces.has(entry.event.envelope.namespace)) return entry;
|
|
200
|
-
return {
|
|
201
|
-
...entry,
|
|
202
|
-
event: {
|
|
203
|
-
...entry.event,
|
|
204
|
-
decoded: prepared?.get(envelopeKey(entry.event.envelope)) ?? decode(entry.event.envelope)
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
const decodeEntryEffect = (entry) => Effect.try({
|
|
209
|
-
try: () => decodeEntry(entry),
|
|
210
|
-
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
211
|
-
});
|
|
212
|
-
const decodeEntries = (entries) => Effect.forEach(entries, decodeEntryEffect);
|
|
213
|
-
return {
|
|
214
|
-
...store,
|
|
215
|
-
append: (batch) => Effect.gen(function* () {
|
|
216
|
-
const prepared = yield* Effect.try({
|
|
217
|
-
try: () => {
|
|
218
|
-
const decoded = /* @__PURE__ */ new Map();
|
|
219
|
-
for (const { event } of batch.entries) {
|
|
220
|
-
if (!namespaces.has(event.namespace)) continue;
|
|
221
|
-
const key = envelopeKey(event);
|
|
222
|
-
if (!decoded.has(key)) decoded.set(key, decode(event));
|
|
223
|
-
}
|
|
224
|
-
return decoded;
|
|
225
|
-
},
|
|
226
|
-
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
227
|
-
});
|
|
228
|
-
const committed = yield* store.append(batch);
|
|
229
|
-
return yield* Effect.forEach(committed, (entry) => Effect.try({
|
|
230
|
-
try: () => decodeEntry(entry, prepared),
|
|
231
|
-
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
232
|
-
}));
|
|
233
|
-
}),
|
|
234
|
-
eventsAfter: (seq) => store.eventsAfter(seq).pipe(Stream.mapEffect(decodeEntryEffect)),
|
|
235
|
-
loadCommittedEventsBySeq: (seqs) => store.loadCommittedEventsBySeq(seqs).pipe(Effect.flatMap(decodeEntries)),
|
|
236
|
-
findCommandAdmission: (input) => store.findCommandAdmission(input).pipe(Effect.flatMap((entry) => entry === void 0 ? Effect.succeed(void 0) : decodeEntryEffect(entry)))
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
/** Narrow an already decoded fact from one schema, without decoding its payload again. */
|
|
240
|
-
const selectCommittedEvent = (schema, entry) => {
|
|
241
|
-
const event = entry.event.namespace === "__foreign" ? entry.event.decoded ?? entry.event.envelope : entry.event;
|
|
242
|
-
return Schema.is(schema)(event) ? {
|
|
243
|
-
position: entry.position,
|
|
244
|
-
event
|
|
245
|
-
} : void 0;
|
|
246
|
-
};
|
|
247
|
-
/** Typed journal read available to tools and application services without private SQL access. */
|
|
248
|
-
const queryCommittedEvents = (store, schema, options = {}) => store.eventsAfter(options.afterSeq ?? SequenceNumber.make(0)).pipe(Stream.map((entry) => selectCommittedEvent(schema, entry)), Stream.filter((entry) => entry !== void 0), Stream.take(options.limit ?? Number.MAX_SAFE_INTEGER), Stream.runCollect);
|
|
249
|
-
//#endregion
|
|
1
|
+
import { a as EDASessionStoreError, c as queryCommittedEvents, i as EDASessionStore, l as registerAppEvents, n as DurableAppendBatch, o as FindCommandAdmissionInput, r as DurableAppendEntry, s as hasEDASessionStoreError, t as CommittedDurableEvent, u as selectCommittedEvent } from "../session-store-DcJjs4Fd.js";
|
|
250
2
|
export { CommittedDurableEvent, DurableAppendBatch, DurableAppendEntry, EDASessionStore, EDASessionStoreError, FindCommandAdmissionInput, hasEDASessionStoreError, queryCommittedEvents, registerAppEvents, selectCommittedEvent };
|
|
251
|
-
|
|
252
|
-
//# sourceMappingURL=session-store.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as StoredSinkCheckpoint, n as SinkCheckpointStore, r as SinkCheckpointStoreShape, t as EDASinkName } from "../sink-checkpoint-store-
|
|
1
|
+
import { i as StoredSinkCheckpoint, n as SinkCheckpointStore, r as SinkCheckpointStoreShape, t as EDASinkName } from "../sink-checkpoint-store-BHb8YRTw.js";
|
|
2
2
|
export { EDASinkName, SinkCheckpointStore, SinkCheckpointStoreShape, StoredSinkCheckpoint };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as EDAProjectedDurableSinkDefinition, Qt as EDAEphemeralSinkDefinition, Zt as EDADurableSinkDefinition, an as EDASinkContext, cn as EDASinkRawDurableBatch, dn as EDASinkRunnerStartInput, en as EDAProjectedSink, in as EDASinkCheckpoint, ln as EDASinkRegistry, nn as EDARawSink, on as EDASinkDurableBatch, rn as EDASink, sn as EDASinkInterests, tn as EDARawDurableSinkDefinition, un as EDASinkRegistryShape } from "../reduced-state-PJdig48e.js";
|
|
2
2
|
export { EDADurableSinkDefinition, EDAEphemeralSinkDefinition, EDAProjectedDurableSinkDefinition, EDAProjectedSink, EDARawDurableSinkDefinition, EDARawSink, EDASink, EDASinkCheckpoint, EDASinkContext, EDASinkDurableBatch, EDASinkInterests, EDASinkRawDurableBatch, EDASinkRegistry, EDASinkRegistryShape, EDASinkRunnerStartInput };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EDASinkRegistry, t as EDASink } from "../sink-registry-
|
|
1
|
+
import { n as EDASinkRegistry, t as EDASink } from "../sink-registry-DEneTH8u.js";
|
|
2
2
|
export { EDASink, EDASinkRegistry };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ToolParamsSchema, i as EDAToolRegistryShape, n as EDAToolExecutionContext, o as makeEDAToolkit, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-
|
|
1
|
+
import { a as ToolParamsSchema, i as EDAToolRegistryShape, n as EDAToolExecutionContext, o as makeEDAToolkit, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-CxZ0iuYb.js";
|
|
2
2
|
export { EDAModelToolkit, EDAToolExecutionContext, EDAToolRegistry, EDAToolRegistryShape, ToolParamsSchema, makeEDAToolkit };
|
|
@@ -7,19 +7,20 @@ import { makeEDARunTrace } from "./types/tracing.js";
|
|
|
7
7
|
import { d as PositionedEvent, f as ProviderPartId, h as ToolName, l as ModelSelectionPayload, m as SystemPromptText, s as FailurePayload, u as NonNegativeInt } from "./envelope-BCzKUq_z.js";
|
|
8
8
|
import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand } from "./types/commands.js";
|
|
9
9
|
import { Jn as inferenceCompletedEventType, Kt as ToolCallCreatedEvent, Sr as turnFailedEventType, Yn as inferenceFailedEventType, _ as CommandAdmittedEvent, _r as toolCallCreatedEventType, cn as TurnCompletedEvent, dn as TurnFailedEvent, hn as TurnStoppedEvent, pn as TurnStartedEvent, qn as durableEventEnvelope, yr as toolCallRejectedEventType } from "./durable-CD__3ztN.js";
|
|
10
|
-
import {
|
|
10
|
+
import { n as assertNeverError, t as assertNever } from "./assert-never-CoyUpoRB.js";
|
|
11
|
+
import { activeTurnIdentityForCommand, classifyRecoverableWork, decodeReducedStateCheckpoint, encodeReducedStateCheckpoint, foldReducedState, frameworkReducedStateReducerName, initialReducedState, reducedStateCheckpointEventSeqs } from "./domain/reduced-state.js";
|
|
11
12
|
import { ContextProjection, emptyContextProjection } from "./domain/context-projection.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { a as EDASessionStoreError, c as queryCommittedEvents, i as EDASessionStore, s as hasEDASessionStoreError, t as CommittedDurableEvent } from "./session-store-DcJjs4Fd.js";
|
|
14
|
+
import { o as CompactionRunner, p as makeUsagePayload } from "./compaction-ajHZ5l7f.js";
|
|
15
|
+
import { EDAPromptProjector, buildEDAPrompt } from "./services/prompt-projector.js";
|
|
15
16
|
import { n as SessionContext, t as EventFactory } from "./event-factory-VAci3NJb.js";
|
|
17
|
+
import { EDAToolRegistry } from "./services/tool-registry.js";
|
|
18
|
+
import { IdGenerator } from "./services/id-generator.js";
|
|
16
19
|
import { annotateEdaSpan, committedBatchAttributes, edaTraceContextFromSpan, eventBatchAttributes, toEdaExternalSpan, usageAttributes } from "./services/tracing.js";
|
|
17
20
|
import { EDAKeepAlive } from "./services/keep-alive.js";
|
|
18
21
|
import { SessionEventObserver } from "./services/session-event-observer.js";
|
|
19
|
-
import { EDAPromptProjector, buildEDAPrompt } from "./services/prompt-projector.js";
|
|
20
22
|
import { EDAReducerRegistry, decodeReducerState, encodeReducerState, reducerSchemaVersion } from "./services/reducer-registry.js";
|
|
21
|
-
import { n as EDASinkRegistry } from "./sink-registry-
|
|
22
|
-
import { EDAToolRegistry } from "./services/tool-registry.js";
|
|
23
|
+
import { n as EDASinkRegistry } from "./sink-registry-DEneTH8u.js";
|
|
23
24
|
import * as Context from "effect/Context";
|
|
24
25
|
import * as Effect from "effect/Effect";
|
|
25
26
|
import * as Layer from "effect/Layer";
|
|
@@ -1071,8 +1072,9 @@ const makeLiveInferenceRunner = Effect.gen(function* () {
|
|
|
1071
1072
|
});
|
|
1072
1073
|
const body = (started) => Effect.gen(function* () {
|
|
1073
1074
|
const toolkit = yield* toolRegistry.getModelToolkit();
|
|
1075
|
+
const prompt = models.preparePrompt?.(input.modelSelection, Prompt.make(input.prompt));
|
|
1074
1076
|
const state = yield* languageModel.streamText({
|
|
1075
|
-
prompt: input.prompt,
|
|
1077
|
+
prompt: prompt ?? input.prompt,
|
|
1076
1078
|
disableToolCallResolution: true,
|
|
1077
1079
|
...toolkit === void 0 ? {} : { toolkit }
|
|
1078
1080
|
}).pipe(Stream.map((part) => part)).pipe(Stream.catchIf(isProviderStreamFailure, (error) => Stream.make(makeProviderErrorPart(error))), Stream.runFoldEffect(() => initialState, (current, part) => recordPart(input.eventSink, current, part, (next) => Ref.set(stateRef, next)).pipe(Effect.tap((next) => Ref.set(stateRef, next)))));
|
|
@@ -1130,12 +1132,12 @@ const initialRunInferenceState = (identity) => ({
|
|
|
1130
1132
|
});
|
|
1131
1133
|
const recordResponseContext = (entries, part) => {
|
|
1132
1134
|
switch (part.type) {
|
|
1133
|
-
case "text-start":
|
|
1134
|
-
case "text-
|
|
1135
|
-
case "text-
|
|
1136
|
-
case "reasoning-start":
|
|
1137
|
-
case "reasoning-
|
|
1138
|
-
case "reasoning-
|
|
1135
|
+
case "text-start":
|
|
1136
|
+
case "text-end": return upsertTextualResponseEntry(entries, "Text", part.id, "", part.metadata);
|
|
1137
|
+
case "text-delta": return upsertTextualResponseEntry(entries, "Text", part.id, part.delta, part.metadata);
|
|
1138
|
+
case "reasoning-start":
|
|
1139
|
+
case "reasoning-end": return upsertTextualResponseEntry(entries, "Reasoning", part.id, "", part.metadata);
|
|
1140
|
+
case "reasoning-delta": return upsertTextualResponseEntry(entries, "Reasoning", part.id, part.delta, part.metadata);
|
|
1139
1141
|
case "tool-call": return part.providerExecuted ? entries : [...entries, {
|
|
1140
1142
|
_tag: "ResponsePart",
|
|
1141
1143
|
part
|
|
@@ -1153,24 +1155,50 @@ const recordResponseContext = (entries, part) => {
|
|
|
1153
1155
|
default: throw assertNeverError(part, "response context part");
|
|
1154
1156
|
}
|
|
1155
1157
|
};
|
|
1156
|
-
|
|
1158
|
+
/**
|
|
1159
|
+
* Folds one textual stream part into its entry. Provider metadata from start, delta and end parts
|
|
1160
|
+
* is merged per provider so replay keeps signatures, item ids and encrypted reasoning.
|
|
1161
|
+
*/
|
|
1162
|
+
const upsertTextualResponseEntry = (entries, tag, providerPartId, delta, metadata) => {
|
|
1157
1163
|
const index = entries.findIndex((entry) => (entry._tag === "Text" || entry._tag === "Reasoning") && entry._tag === tag && entry.providerPartId === providerPartId);
|
|
1158
1164
|
if (index === -1) return [...entries, {
|
|
1159
1165
|
_tag: tag,
|
|
1160
1166
|
providerPartId,
|
|
1161
|
-
text: delta
|
|
1167
|
+
text: delta,
|
|
1168
|
+
metadata: metadata ?? {}
|
|
1162
1169
|
}];
|
|
1163
1170
|
const current = entries[index];
|
|
1164
1171
|
if (current._tag !== tag) return entries;
|
|
1165
1172
|
return entries.map((entry, entryIndex) => entryIndex === index ? {
|
|
1166
1173
|
...current,
|
|
1167
|
-
text: `${current.text}${delta}
|
|
1174
|
+
text: `${current.text}${delta}`,
|
|
1175
|
+
metadata: mergeProviderMetadata(current.metadata, metadata)
|
|
1168
1176
|
} : entry);
|
|
1169
1177
|
};
|
|
1178
|
+
const mergeProviderMetadata = (left, right) => {
|
|
1179
|
+
if (right === void 0) return left;
|
|
1180
|
+
const merged = { ...left };
|
|
1181
|
+
for (const [provider, value] of Object.entries(right)) {
|
|
1182
|
+
const previous = merged[provider];
|
|
1183
|
+
merged[provider] = isMetadataRecord(previous) && isMetadataRecord(value) ? {
|
|
1184
|
+
...previous,
|
|
1185
|
+
...value
|
|
1186
|
+
} : value;
|
|
1187
|
+
}
|
|
1188
|
+
return merged;
|
|
1189
|
+
};
|
|
1190
|
+
const isMetadataRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1191
|
+
const hasProviderMetadata = (metadata) => Object.keys(metadata).length > 0;
|
|
1170
1192
|
const responseContextToParts = (entries) => entries.flatMap((entry) => {
|
|
1171
1193
|
switch (entry._tag) {
|
|
1172
|
-
case "Text": return entry.text.length === 0 ? [] : [Response.makePart("text", {
|
|
1173
|
-
|
|
1194
|
+
case "Text": return entry.text.length === 0 ? [] : [Response.makePart("text", {
|
|
1195
|
+
text: entry.text,
|
|
1196
|
+
metadata: entry.metadata
|
|
1197
|
+
})];
|
|
1198
|
+
case "Reasoning": return entry.text.length === 0 && !hasProviderMetadata(entry.metadata) ? [] : [Response.makePart("reasoning", {
|
|
1199
|
+
text: entry.text,
|
|
1200
|
+
metadata: entry.metadata
|
|
1201
|
+
})];
|
|
1174
1202
|
case "ResponsePart": return [entry.part];
|
|
1175
1203
|
default: throw assertNeverError(entry, "response context entry");
|
|
1176
1204
|
}
|
|
@@ -1884,9 +1912,11 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1884
1912
|
yield* requestCurrentReducerCheckpointSnapshot("startup-recovery-complete");
|
|
1885
1913
|
});
|
|
1886
1914
|
const maybeCompactAtBoundary = () => Effect.gen(function* () {
|
|
1887
|
-
const
|
|
1915
|
+
const data = yield* currentData();
|
|
1916
|
+
const current = data.reduced;
|
|
1888
1917
|
const next = (yield* compactionRunner.maybeCompact({
|
|
1889
1918
|
state: current,
|
|
1919
|
+
reducerStates: data.reducerStates,
|
|
1890
1920
|
context: yield* contextProjectionFor(current),
|
|
1891
1921
|
appendDurableEntries
|
|
1892
1922
|
})).length === 0 ? current : yield* currentReduced();
|
|
@@ -3200,4 +3230,4 @@ const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag =
|
|
|
3200
3230
|
//#endregion
|
|
3201
3231
|
export { SessionCommandOutcome as a, SessionNoRunnableReason as c, TurnRunner as d, InferenceRunner as f, SessionCommandFailed as i, SessionRunInput as l, LiveEventBus as m, SessionCommandCancelled as n, SessionForkedCommand as o, ToolExecutor as p, SessionCommandCompleted as r, SessionNoRunnableCommand as s, SessionCommandAdmissionConflict as t, SessionState as u };
|
|
3202
3232
|
|
|
3203
|
-
//# sourceMappingURL=session-state-
|
|
3233
|
+
//# sourceMappingURL=session-state-StlO5B2N.js.map
|