effect-durable-agent 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{compaction-63iEDHHl.js → compaction-D7WJa899.js} +3 -3
- package/dist/{compaction-63iEDHHl.js.map → compaction-D7WJa899.js.map} +1 -1
- package/dist/{delivery-2ZILvoRD.js → delivery-BoF-NZbZ.js} +3 -3
- package/dist/{delivery-2ZILvoRD.js.map → delivery-BoF-NZbZ.js.map} +1 -1
- package/dist/{delivery-D3MxW4wg.d.ts → delivery-v42MAMEP.d.ts} +153 -10
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +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 +2 -2
- package/dist/domain/reduced-state-schema.js +2 -2
- package/dist/domain/reduced-state.d.ts +2 -2
- package/dist/domain/reduced-state.js +3 -2
- package/dist/domain/reduced-state.js.map +1 -1
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/{durable-168Womqp.d.ts → durable-BXqwM70o.d.ts} +510 -3
- package/dist/{durable-D13w1Qr3.js → durable-Da57Rcml.js} +17 -3
- package/dist/durable-Da57Rcml.js.map +1 -0
- package/dist/{envelope-BCzKUq_z.js → envelope-BSI_Xh-f.js} +21 -5
- package/dist/envelope-BSI_Xh-f.js.map +1 -0
- package/dist/{envelope-Che6KatU.d.ts → envelope-CJnPfbjC.d.ts} +53 -6
- package/dist/{event-factory-_vF1bIJ7.js → event-factory-BUoBwqAy.js} +3 -3
- package/dist/{event-factory-_vF1bIJ7.js.map → event-factory-BUoBwqAy.js.map} +1 -1
- package/dist/{events-DwTARLMv.d.ts → events-AIIwZ6dS.d.ts} +3 -3
- package/dist/{in-memory-CeODnZhE.js → in-memory-E497WhtS.js} +3 -3
- package/dist/{in-memory-CeODnZhE.js.map → in-memory-E497WhtS.js.map} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/{interpreter-DKGJ1sSx.js → interpreter-BwYN2PCC.js} +5 -4
- package/dist/interpreter-BwYN2PCC.js.map +1 -0
- package/dist/{model-resolver-DeBDK8XO.d.ts → model-resolver-O8Kn27GH.d.ts} +3 -3
- package/dist/{model-usage-0GeHwaaU.d.ts → model-usage-mttrPN0j.d.ts} +2 -2
- package/dist/{records--54mZEBx.js → records-D0ZIAOzd.js} +3 -3
- package/dist/{records--54mZEBx.js.map → records-D0ZIAOzd.js.map} +1 -1
- package/dist/{reduced-state-B1cvy8N_.d.ts → reduced-state-DB_iANjR.d.ts} +50549 -48726
- package/dist/{reduced-state-schema-B98exWxQ.d.ts → reduced-state-schema-B9TYxkP9.d.ts} +2 -2
- package/dist/{reducer-registry-DhGVzHBV.d.ts → reducer-registry-Bqn5B4JO.d.ts} +5 -5
- package/dist/{run-scheduling-wakeup-Mjic4tb_.d.ts → run-scheduling-wakeup-DX2zRAxd.d.ts} +2 -2
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/compaction.js +1 -1
- package/dist/services/decider.d.ts +2 -0
- package/dist/services/decider.js +97 -0
- package/dist/services/decider.js.map +1 -0
- package/dist/services/model-call.d.ts +1 -1
- package/dist/services/model-resolver.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/reducer-registry.d.ts +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 +13 -9
- package/dist/services/runtime-layer.js +10 -7
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +4 -3
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +3 -3
- package/dist/services/session-state.d.ts +2 -2
- package/dist/services/session-state.js +2 -1
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +32 -17
- package/dist/services/session-store.js.map +1 -1
- 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/span-names.d.ts +1 -1
- package/dist/services/span-names.js +1 -0
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +2 -2
- package/dist/session-admission-WE8J_0z9.js +138 -0
- package/dist/session-admission-WE8J_0z9.js.map +1 -0
- package/dist/{session-event-observer-DlP9ITB2.d.ts → session-event-observer-BWQUJTcN.d.ts} +3 -3
- package/dist/{session-state-BehvUVyq.js → session-state-BII-Jhf-.js} +171 -19
- package/dist/session-state-BII-Jhf-.js.map +1 -0
- package/dist/{session-store-BL6sfrnn.d.ts → session-store-DaSHeg8Q.d.ts} +25 -8
- package/dist/{sink-checkpoint-store-DvuHwvx_.d.ts → sink-checkpoint-store-CUvIVvlZ.d.ts} +2 -2
- package/dist/{sink-registry-DskRcyOS.js → sink-registry-AOjX5_A1.js} +34 -10
- package/dist/sink-registry-AOjX5_A1.js.map +1 -0
- package/dist/{subscription-DZNWFDTV.d.ts → subscription-BhwUmsl4.d.ts} +2 -2
- package/dist/{subscription-DmO3BcdT.js → subscription-D7U4Tziv.js} +3 -3
- package/dist/{subscription-DmO3BcdT.js.map → subscription-D7U4Tziv.js.map} +1 -1
- package/dist/testkit/layers.d.ts +13 -10
- package/dist/testkit/layers.js +16 -9
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +10 -4
- package/dist/testkit/transcript.js +58 -7
- package/dist/testkit/transcript.js.map +1 -1
- package/dist/transcript.d.ts +5 -5
- package/dist/transcript.js +5 -5
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +4 -4
- package/dist/types/events.js +3 -3
- package/dist/websocket/events.d.ts +1 -1
- package/dist/websocket/events.js +1 -1
- package/dist/websocket.d.ts +3 -3
- package/dist/websocket.js +3 -3
- package/dist/{window-read-Brov9VdQ.d.ts → window-read-BELSkO-r.d.ts} +2 -2
- package/dist/{window-read-DPFAA1hM.js → window-read-FJTCDaSq.js} +3 -3
- package/dist/{window-read-DPFAA1hM.js.map → window-read-FJTCDaSq.js.map} +1 -1
- package/package.json +5 -1
- package/dist/durable-D13w1Qr3.js.map +0 -1
- package/dist/envelope-BCzKUq_z.js.map +0 -1
- package/dist/interpreter-DKGJ1sSx.js.map +0 -1
- package/dist/session-state-BehvUVyq.js.map +0 -1
- package/dist/sink-registry-DskRcyOS.js.map +0 -1
- package/dist/tool-registry-CHHUU9BN.d.ts +0 -87
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { RunSchedulingWakeup } from "./services/run-scheduling-wakeup.js";
|
|
2
|
-
import { CommandId, InferenceId,
|
|
2
|
+
import { CommandId, InferenceId, Position, RunId, SequenceNumber, SubSequenceNumber, TurnId } from "./types/core.js";
|
|
3
3
|
import { canGrantRun, planRunSchedulingCancellation, planWaitingRunInterruption, runSchedulingInputMessageIds, waitingRunControl } from "./domain/run-scheduling.js";
|
|
4
4
|
import { RunScheduler } from "./services/run-scheduler.js";
|
|
5
5
|
import { ModelResolver } from "./services/model-resolver.js";
|
|
6
6
|
import { makeEDARunTrace } from "./types/tracing.js";
|
|
7
|
-
import { d as
|
|
7
|
+
import { S as schemaV1, _ as UnixEpochMillis, c as FailurePayload, d as NonNegativeInt, f as PositionedEvent, g as ToolName, h as SystemPromptText, p as ProviderPartId, r as EventDedupeKey, t as DurableEventEnvelope, u as ModelSelectionPayload, y as effectDurableAgentNamespace } from "./envelope-BSI_Xh-f.js";
|
|
8
8
|
import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand } from "./types/commands.js";
|
|
9
|
-
import {
|
|
9
|
+
import { H as DeciderAcceptedEvent, Jt as ToolCallCreatedEvent, Kn as deciderAcceptedEventType, Qn as inferenceFailedEventType, Sr as toolCallRejectedEventType, Tr as turnFailedEventType, Xn as durableEventEnvelope, Zn as inferenceCompletedEventType, _ as CommandAdmittedEvent, _n as TurnStoppedEvent, br as toolCallCreatedEventType, hn as TurnStartedEvent, pn as TurnFailedEvent, un as TurnCompletedEvent } from "./durable-Da57Rcml.js";
|
|
10
10
|
import { n as assertNeverError, t as assertNever } from "./assert-never-CoyUpoRB.js";
|
|
11
11
|
import { activeTurnIdentityForCommand, classifyRecoverableWork, decodeReducedStateCheckpoint, encodeReducedStateCheckpoint, foldReducedState, frameworkReducedStateReducerName, initialReducedState, reducedStateCheckpointEventSeqs } from "./domain/reduced-state.js";
|
|
12
12
|
import { ContextProjection, emptyContextProjection } from "./domain/context-projection.js";
|
|
13
|
+
import { a as jsonBytes, n as SessionCommandAdmissionConflict, o as makeAppEventAdmission, r as appEventConflict, t as RegisteredAppEvents } from "./session-admission-WE8J_0z9.js";
|
|
13
14
|
import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError, hasEDASessionStoreError, queryCommittedEvents } from "./services/session-store.js";
|
|
14
|
-
import { o as CompactionRunner, p as makeUsagePayload } from "./compaction-
|
|
15
|
+
import { o as CompactionRunner, p as makeUsagePayload } from "./compaction-D7WJa899.js";
|
|
15
16
|
import { EDAPromptProjector, buildEDAPrompt } from "./services/prompt-projector.js";
|
|
16
|
-
import { n as SessionContext, t as EventFactory } from "./event-factory-
|
|
17
|
+
import { n as SessionContext, t as EventFactory } from "./event-factory-BUoBwqAy.js";
|
|
17
18
|
import { EDAToolRegistry, toolRecoveryPolicy } from "./services/tool-registry.js";
|
|
18
19
|
import { IdGenerator } from "./services/id-generator.js";
|
|
19
|
-
import { annotateEdaSpan, committedBatchAttributes, edaTraceContextFromSpan, eventBatchAttributes, toEdaExternalSpan, usageAttributes } from "./services/tracing.js";
|
|
20
|
+
import { annotateEdaSpan, committedBatchAttributes, currentOrRootEDAEventTrace, edaTraceContextFromSpan, eventBatchAttributes, toEdaExternalSpan, usageAttributes } from "./services/tracing.js";
|
|
20
21
|
import { EDAKeepAlive } from "./services/keep-alive.js";
|
|
21
22
|
import { SessionEventObserver } from "./services/session-event-observer.js";
|
|
22
23
|
import { EDAReducerRegistry, decodeReducerState, encodeReducerState, reducerSchemaVersion } from "./services/reducer-registry.js";
|
|
23
|
-
import { n as EDASinkRegistry } from "./sink-registry-
|
|
24
|
+
import { n as EDASinkRegistry } from "./sink-registry-AOjX5_A1.js";
|
|
25
|
+
import { EDADeciderError, EDADeciderRegistry, deciderIdempotencyKeyViolation, deciderMarkerDedupeKey, encodeDeciderJson, maxDeciderResultBytes } from "./services/decider.js";
|
|
24
26
|
import * as Context from "effect/Context";
|
|
25
27
|
import * as Effect from "effect/Effect";
|
|
26
28
|
import * as Layer from "effect/Layer";
|
|
@@ -33,6 +35,7 @@ import * as Clock from "effect/Clock";
|
|
|
33
35
|
import * as Fiber from "effect/Fiber";
|
|
34
36
|
import * as Queue from "effect/Queue";
|
|
35
37
|
import * as Ref from "effect/Ref";
|
|
38
|
+
import * as Result from "effect/Result";
|
|
36
39
|
import * as Scope from "effect/Scope";
|
|
37
40
|
import * as Semaphore from "effect/Semaphore";
|
|
38
41
|
import * as Option from "effect/Option";
|
|
@@ -420,7 +423,12 @@ const makeLiveToolExecutor = Effect.gen(function* () {
|
|
|
420
423
|
queryEvents: (schema, options) => queryCommittedEvents(store, schema, options),
|
|
421
424
|
sessionId: session.sessionId,
|
|
422
425
|
makeEventId: ids.makeEventId,
|
|
423
|
-
emitDurable: input.eventSink.
|
|
426
|
+
emitDurable: input.eventSink.appendAppDurable,
|
|
427
|
+
decide: input.eventSink.decide,
|
|
428
|
+
snapshot: () => input.eventSink.snapshotData().pipe(Effect.map((data) => ({
|
|
429
|
+
state: data.reduced,
|
|
430
|
+
reducerStates: data.reducerStates
|
|
431
|
+
}))),
|
|
424
432
|
...input.resume === void 0 ? {} : { recovery: input.resume }
|
|
425
433
|
}).pipe(Effect.map((result) => ({
|
|
426
434
|
_tag: "Succeeded",
|
|
@@ -1564,11 +1572,6 @@ const SessionNoRunnableCommand = Schema.TaggedStruct("SessionNoRunnableCommand",
|
|
|
1564
1572
|
});
|
|
1565
1573
|
/** Control result when command execution was started in an active child scope. */
|
|
1566
1574
|
const SessionForkedCommand = Schema.TaggedStruct("SessionForkedCommand", { commandId: CommandId });
|
|
1567
|
-
var SessionCommandAdmissionConflict = class extends Schema.TaggedError()("SessionCommandAdmissionConflict", {
|
|
1568
|
-
code: Schema.Literals(["queue_paused", "paused_queue_changed"]),
|
|
1569
|
-
message: Schema.String,
|
|
1570
|
-
pausedMessageIds: Schema.Array(MessageId)
|
|
1571
|
-
}) {};
|
|
1572
1575
|
/** Internal authoritative live state and root control loop for one session. */
|
|
1573
1576
|
var SessionState = class SessionState extends Context.Service()("@effect-durable-agent/SessionState") {
|
|
1574
1577
|
static Live = Layer.effect(SessionState, Effect.suspend(() => makeLiveSessionState));
|
|
@@ -1625,6 +1628,8 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1625
1628
|
const schedulingWakeup = yield* RunSchedulingWakeup;
|
|
1626
1629
|
const reducerRegistry = yield* EDAReducerRegistry;
|
|
1627
1630
|
const sinkRegistry = yield* EDASinkRegistry;
|
|
1631
|
+
const appEventAdmission = makeAppEventAdmission(yield* RegisteredAppEvents);
|
|
1632
|
+
const deciders = yield* EDADeciderRegistry;
|
|
1628
1633
|
const { hydrated, hydratedReducerStates } = yield* Effect.gen(function* () {
|
|
1629
1634
|
const hydrated = yield* hydrateFrameworkReducedState(store);
|
|
1630
1635
|
const hydratedReducerStates = yield* hydrateAppReducerStates(store, reducerRegistry.reducers);
|
|
@@ -1722,7 +1727,7 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1722
1727
|
const requestReducerCheckpointSnapshot = (snapshot) => Queue.offer(reducerCheckpointSnapshots, snapshot).pipe(Effect.asVoid);
|
|
1723
1728
|
const publishFreshDurables = (committed) => Effect.gen(function* () {
|
|
1724
1729
|
const current = yield* Ref.get(state);
|
|
1725
|
-
const fresh = Array.from(committed.filter((entry) => entry.position.seq > current.reduced.lastSeq)).sort((a, b) => a.position.seq - b.position.seq);
|
|
1730
|
+
const fresh = Array.from(new Map(committed.filter((entry) => entry.position.seq > current.reduced.lastSeq).map((entry) => [entry.position.seq, entry])).values()).sort((a, b) => a.position.seq - b.position.seq);
|
|
1726
1731
|
if (fresh.length === 0) return;
|
|
1727
1732
|
const nextReduced = foldReducedState(current.reduced, fresh);
|
|
1728
1733
|
const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);
|
|
@@ -1879,10 +1884,20 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1879
1884
|
"eda.command.count": commandCount,
|
|
1880
1885
|
"eda.event.app_owned_count": input.length - commandCount
|
|
1881
1886
|
});
|
|
1887
|
+
const admitted = [];
|
|
1888
|
+
for (const item of input) {
|
|
1889
|
+
if (isEDACommand(item)) {
|
|
1890
|
+
admitted.push(item);
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
const event = appEventAdmission.admit(item);
|
|
1894
|
+
if (Result.isFailure(event)) return yield* appEventConflict(event.failure);
|
|
1895
|
+
admitted.push(event.success);
|
|
1896
|
+
}
|
|
1882
1897
|
const committed = yield* withAppendGate(Effect.gen(function* () {
|
|
1883
1898
|
const preparedByIdempotencyKey = /* @__PURE__ */ new Map();
|
|
1884
1899
|
const preparedByCommandId = /* @__PURE__ */ new Map();
|
|
1885
|
-
const durableEvents = (yield* Effect.forEach(
|
|
1900
|
+
const durableEvents = (yield* Effect.forEach(admitted, (item) => isEDACommand(item) ? prepareCommandAdmission(item, preparedByIdempotencyKey, preparedByCommandId) : Effect.succeed([item]))).flat();
|
|
1886
1901
|
return yield* commitDurableEntriesWithinGate(durableEvents.map((event) => ({ event })));
|
|
1887
1902
|
}));
|
|
1888
1903
|
yield* annotateEdaSpan(committedBatchAttributes(committed));
|
|
@@ -1892,16 +1907,149 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1892
1907
|
const admitCommand = (command) => Effect.gen(function* () {
|
|
1893
1908
|
return (yield* submitBatch([command]))[0];
|
|
1894
1909
|
});
|
|
1910
|
+
/** A tool's app fact: the same admission rules as `submit`, then the framework path. */
|
|
1911
|
+
const appendAppDurable = (event) => Effect.gen(function* () {
|
|
1912
|
+
const admitted = appEventAdmission.admit(event);
|
|
1913
|
+
if (Result.isFailure(admitted)) return yield* appEventConflict(admitted.failure);
|
|
1914
|
+
return yield* appendDurable(admitted.success);
|
|
1915
|
+
});
|
|
1916
|
+
/**
|
|
1917
|
+
* Run a registered decider: read the committed fold and append its marker and items as one
|
|
1918
|
+
* batch under the admission and append gates `submitBatch` takes, so nothing interleaves
|
|
1919
|
+
* between the read and the write. A retry with the same key finds the marker and returns the
|
|
1920
|
+
* stored result without deciding again. No decider error is a store error, so none is fatal.
|
|
1921
|
+
*/
|
|
1922
|
+
const decide = (decider, input) => Effect.gen(function* () {
|
|
1923
|
+
const fail = (reason, message) => new EDADeciderError({
|
|
1924
|
+
decider: decider.name,
|
|
1925
|
+
reason,
|
|
1926
|
+
message
|
|
1927
|
+
});
|
|
1928
|
+
if (deciders.get(decider.name) !== decider) return yield* fail("unknown_decider", `EDA decider ${decider.name} is not registered`);
|
|
1929
|
+
const idempotencyKey = yield* Effect.try({
|
|
1930
|
+
try: () => decider.idempotencyKey(input),
|
|
1931
|
+
catch: (cause) => fail("invalid_input", `idempotencyKey threw: ${String(cause)}`)
|
|
1932
|
+
});
|
|
1933
|
+
const keyViolation = deciderIdempotencyKeyViolation(idempotencyKey);
|
|
1934
|
+
if (keyViolation !== void 0) return yield* fail("invalid_input", keyViolation);
|
|
1935
|
+
const markerKey = EventDedupeKey.make(deciderMarkerDedupeKey(decider.name, idempotencyKey));
|
|
1936
|
+
yield* annotateEdaSpan({ "eda.decider.name": decider.name });
|
|
1937
|
+
const decided = yield* admissionGate.withPermits(1)(withAppendGate(Effect.gen(function* () {
|
|
1938
|
+
const accepted = yield* store.findEventByDedupeKey({
|
|
1939
|
+
namespace: effectDurableAgentNamespace,
|
|
1940
|
+
type: deciderAcceptedEventType,
|
|
1941
|
+
dedupeKey: markerKey
|
|
1942
|
+
});
|
|
1943
|
+
if (accepted !== void 0) {
|
|
1944
|
+
const marker = durableEventEnvelope(accepted.event);
|
|
1945
|
+
const stored = Schema.is(DeciderAcceptedEvent)(marker) ? marker.payload.result : void 0;
|
|
1946
|
+
return {
|
|
1947
|
+
outcome: {
|
|
1948
|
+
_tag: "Accepted",
|
|
1949
|
+
result: yield* Schema.decodeUnknownEffect(decider.result)(stored).pipe(Effect.mapError((cause) => fail("invalid_output", `stored result does not decode: ${cause.message}`))),
|
|
1950
|
+
acceptedSeq: accepted.position.seq,
|
|
1951
|
+
replayed: true
|
|
1952
|
+
},
|
|
1953
|
+
wake: false
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
const current = yield* Ref.get(state);
|
|
1957
|
+
const nowMs = yield* Clock.currentTimeMillis;
|
|
1958
|
+
const view = {
|
|
1959
|
+
sessionId: sessionContext.sessionId,
|
|
1960
|
+
nowMs,
|
|
1961
|
+
state: current.reduced,
|
|
1962
|
+
reducerStates: current.reducerStates
|
|
1963
|
+
};
|
|
1964
|
+
const decision = yield* Effect.try({
|
|
1965
|
+
try: () => decider.decide(view, input),
|
|
1966
|
+
catch: (cause) => fail("decide_threw", `decide threw: ${String(cause)}`)
|
|
1967
|
+
});
|
|
1968
|
+
if (decision._tag === "Reject") return {
|
|
1969
|
+
outcome: {
|
|
1970
|
+
_tag: "Rejected",
|
|
1971
|
+
rejection: decision.rejection
|
|
1972
|
+
},
|
|
1973
|
+
wake: false
|
|
1974
|
+
};
|
|
1975
|
+
const storedResult = encodeDeciderJson(decider.result, decision.result);
|
|
1976
|
+
if (Result.isFailure(storedResult)) return yield* fail("invalid_output", `result ${storedResult.failure}`);
|
|
1977
|
+
const resultBytes = jsonBytes(storedResult.success);
|
|
1978
|
+
if (resultBytes > 16384) return yield* fail("invalid_output", `encoded result is ${resultBytes} bytes; the limit is ${maxDeciderResultBytes} bytes`);
|
|
1979
|
+
const result = yield* Schema.decodeUnknownEffect(decider.result)(storedResult.success).pipe(Effect.mapError((cause) => fail("invalid_output", `result does not decode from its stored JSON: ${cause.message}`)));
|
|
1980
|
+
const wireResult = encodeDeciderJson(decider.result, result);
|
|
1981
|
+
if (Result.isFailure(wireResult)) return yield* fail("invalid_output", `result decoded from its stored JSON ${wireResult.failure}`);
|
|
1982
|
+
const trace = yield* currentOrRootEDAEventTrace;
|
|
1983
|
+
const createdAtMs = UnixEpochMillis.make(nowMs);
|
|
1984
|
+
const preparedByIdempotencyKey = /* @__PURE__ */ new Map();
|
|
1985
|
+
const preparedByCommandId = /* @__PURE__ */ new Map();
|
|
1986
|
+
const items = [];
|
|
1987
|
+
let hasCommand = false;
|
|
1988
|
+
for (const [index, item] of decision.items.entries()) {
|
|
1989
|
+
if (isDecidedCommand(item)) {
|
|
1990
|
+
hasCommand = true;
|
|
1991
|
+
items.push(...yield* prepareCommandAdmission(item, preparedByIdempotencyKey, preparedByCommandId));
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
const eventId = "eventId" in item && typeof item.eventId === "string" ? item.eventId : yield* ids.makeEventId();
|
|
1995
|
+
const event = yield* Effect.try({
|
|
1996
|
+
try: () => Schema.decodeUnknownSync(DurableEventEnvelope)(decider.encodeEvent({
|
|
1997
|
+
...item,
|
|
1998
|
+
eventId,
|
|
1999
|
+
sessionId: sessionContext.sessionId,
|
|
2000
|
+
createdAtMs,
|
|
2001
|
+
trace,
|
|
2002
|
+
durability: "durable"
|
|
2003
|
+
})),
|
|
2004
|
+
catch: (cause) => fail("invalid_output", `item ${index} is not an event of the decider's events schema: ${String(cause)}`)
|
|
2005
|
+
});
|
|
2006
|
+
const admitted = appEventAdmission.admit(event);
|
|
2007
|
+
if (Result.isFailure(admitted)) return yield* fail("invalid_output", `item ${index}: ${admitted.failure.message}`);
|
|
2008
|
+
items.push(admitted.success);
|
|
2009
|
+
}
|
|
2010
|
+
const marker = yield* Schema.decodeUnknownEffect(DeciderAcceptedEvent)({
|
|
2011
|
+
namespace: effectDurableAgentNamespace,
|
|
2012
|
+
type: deciderAcceptedEventType,
|
|
2013
|
+
schemaVersion: schemaV1,
|
|
2014
|
+
durability: "durable",
|
|
2015
|
+
eventId: yield* ids.makeEventId(),
|
|
2016
|
+
sessionId: sessionContext.sessionId,
|
|
2017
|
+
createdAtMs,
|
|
2018
|
+
trace,
|
|
2019
|
+
dedupeKey: markerKey,
|
|
2020
|
+
payload: {
|
|
2021
|
+
decider: decider.name,
|
|
2022
|
+
idempotencyKey,
|
|
2023
|
+
result: storedResult.success
|
|
2024
|
+
}
|
|
2025
|
+
}).pipe(Effect.mapError((cause) => fail("invalid_output", `encoded result is not JSON: ${cause.message}`)));
|
|
2026
|
+
const acceptedSeq = (yield* commitDurableEntriesWithinGate([marker, ...items].map((event) => ({ event }))))[0]?.position.seq;
|
|
2027
|
+
if (acceptedSeq === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("decider marker was not committed"));
|
|
2028
|
+
return {
|
|
2029
|
+
outcome: {
|
|
2030
|
+
_tag: "Accepted",
|
|
2031
|
+
result,
|
|
2032
|
+
acceptedSeq,
|
|
2033
|
+
replayed: false
|
|
2034
|
+
},
|
|
2035
|
+
wake: hasCommand
|
|
2036
|
+
};
|
|
2037
|
+
})));
|
|
2038
|
+
if (decided.wake) yield* wakeAfterCommandAdmission();
|
|
2039
|
+
return decided.outcome;
|
|
2040
|
+
});
|
|
1895
2041
|
const initialize = (input) => commitInitialSystemPrompt(input.systemPrompt);
|
|
1896
2042
|
const sessionApi = {
|
|
1897
2043
|
grantRun: (command, input) => grantRun(command, input),
|
|
1898
2044
|
retryRunSchedulingDelivery: () => retryRunSchedulingDelivery(),
|
|
1899
2045
|
initialize,
|
|
1900
2046
|
submitBatch,
|
|
2047
|
+
decide,
|
|
1901
2048
|
admitCommand,
|
|
1902
2049
|
snapshot,
|
|
1903
2050
|
snapshotData,
|
|
1904
2051
|
appendDurable,
|
|
2052
|
+
appendAppDurable,
|
|
1905
2053
|
appendDurableBatch,
|
|
1906
2054
|
publishEphemeral,
|
|
1907
2055
|
drainReadyWork: (input) => drainReadyWork(input),
|
|
@@ -3189,11 +3337,12 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
3189
3337
|
yield* initialize(input);
|
|
3190
3338
|
yield* keepAlive.withActiveWork("session-recovery", runStartupRecoveryPass(input));
|
|
3191
3339
|
});
|
|
3340
|
+
/** Runs after the first drain: waits for ingress, then drains ready work to its next wait. */
|
|
3192
3341
|
const runLiveControlLoop = Effect.fn(function* (input) {
|
|
3193
3342
|
yield* annotateRunInput(input);
|
|
3194
3343
|
while (true) {
|
|
3195
|
-
yield* drainAndLog(input);
|
|
3196
3344
|
yield* waitForNextSignal();
|
|
3345
|
+
yield* drainAndLog(input);
|
|
3197
3346
|
}
|
|
3198
3347
|
});
|
|
3199
3348
|
const start = Effect.fn(function* (input) {
|
|
@@ -3201,6 +3350,7 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
3201
3350
|
if (reinvocations.length === 0) {
|
|
3202
3351
|
yield* runStartupRecovery(input);
|
|
3203
3352
|
yield* forkSchedulingDelivery();
|
|
3353
|
+
yield* drainAndLog(input).pipe(Effect.catch((error) => error._tag === "EDASessionStoreError" ? Effect.fail(error) : Effect.die(error)));
|
|
3204
3354
|
yield* runLiveControlLoop(input).pipe(Effect.forkIn(runtimeScope));
|
|
3205
3355
|
return;
|
|
3206
3356
|
}
|
|
@@ -3213,7 +3363,7 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
3213
3363
|
yield* withFatalRecording(resumeInterruptedToolCalls(reinvocations));
|
|
3214
3364
|
yield* runStartupRecoveryPass(input);
|
|
3215
3365
|
}));
|
|
3216
|
-
}).pipe(Effect.ensuring(Ref.set(recoveringInBackground, false).pipe(Effect.andThen(controlGate.release(1)))), Effect.andThen(forkSchedulingDelivery()), Effect.andThen(runLiveControlLoop(input)), Effect.catchCause((cause) => Effect.gen(function* () {
|
|
3366
|
+
}).pipe(Effect.ensuring(Ref.set(recoveringInBackground, false).pipe(Effect.andThen(controlGate.release(1)))), Effect.andThen(forkSchedulingDelivery()), Effect.andThen(drainAndLog(input)), Effect.andThen(runLiveControlLoop(input)), Effect.catchCause((cause) => Effect.gen(function* () {
|
|
3217
3367
|
const message = `EDA background startup recovery failed: ${Cause.pretty(cause)}`;
|
|
3218
3368
|
yield* markFatalIfDurable(cause);
|
|
3219
3369
|
yield* Ref.update(fatalInvariantViolation, (current) => current ?? message);
|
|
@@ -3266,6 +3416,8 @@ const hydrateAppReducerStates = (store, reducers) => Effect.gen(function* () {
|
|
|
3266
3416
|
};
|
|
3267
3417
|
});
|
|
3268
3418
|
const isEDACommand = (input) => "_tag" in input;
|
|
3419
|
+
/** Decider items are commands (tagged classes) or untagged event drafts. */
|
|
3420
|
+
const isDecidedCommand = (item) => "_tag" in item;
|
|
3269
3421
|
const commandWithId = (command, commandId) => {
|
|
3270
3422
|
switch (command._tag) {
|
|
3271
3423
|
case "SubmitMessage": return new SubmitMessageCommand({
|
|
@@ -3322,6 +3474,6 @@ const requireTurnFailed = (committed) => isTurnFailed(committed) ? Effect.succee
|
|
|
3322
3474
|
const isTurnFailed = (committed) => committed.event.type === turnFailedEventType;
|
|
3323
3475
|
const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag === "SessionNoRunnableCommand";
|
|
3324
3476
|
//#endregion
|
|
3325
|
-
export {
|
|
3477
|
+
export { SessionForkedCommand as a, SessionRunInput as c, InferenceRunner as d, ToolExecutor as f, SessionCommandOutcome as i, SessionState as l, SessionCommandCompleted as n, SessionNoRunnableCommand as o, LiveEventBus as p, SessionCommandFailed as r, SessionNoRunnableReason as s, SessionCommandCancelled as t, TurnRunner as u };
|
|
3326
3478
|
|
|
3327
|
-
//# sourceMappingURL=session-state-
|
|
3479
|
+
//# sourceMappingURL=session-state-BII-Jhf-.js.map
|