effect-durable-agent 0.1.0-alpha.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/CHANGELOG.md +10 -0
- package/CONTRIBUTING.md +26 -0
- package/LICENSE +21 -0
- package/README.md +305 -0
- package/SECURITY.md +8 -0
- package/dist/command-queues-CQ9cwRP7.d.ts +468 -0
- package/dist/commands-Ce1ec6kH.d.ts +104 -0
- package/dist/compaction-YayFKo_1.d.ts +144 -0
- package/dist/core-Hv3cFydL.d.ts +81 -0
- package/dist/domain/command-queues.d.ts +2 -0
- package/dist/domain/command-queues.js +97 -0
- package/dist/domain/command-queues.js.map +1 -0
- package/dist/domain/message-transcript.d.ts +2 -0
- package/dist/domain/message-transcript.js +111 -0
- package/dist/domain/message-transcript.js.map +1 -0
- package/dist/domain/reduced-state-schema.d.ts +996 -0
- package/dist/domain/reduced-state-schema.js +286 -0
- package/dist/domain/reduced-state-schema.js.map +1 -0
- package/dist/domain/reduced-state.d.ts +2 -0
- package/dist/domain/reduced-state.js +2 -0
- package/dist/durable-C3Rz7kg3.js +625 -0
- package/dist/durable-C3Rz7kg3.js.map +1 -0
- package/dist/durable-DlScwmCy.d.ts +7424 -0
- package/dist/durable-object-runtime-B7jwBY2R.js +1494 -0
- package/dist/durable-object-runtime-B7jwBY2R.js.map +1 -0
- package/dist/durable-object-runtime-pWv0ohlz.d.ts +257 -0
- package/dist/durable-object-storage-Czy7IPrh.d.ts +41 -0
- package/dist/events-Bb9-Cu-7.d.ts +918 -0
- package/dist/host/durable-object-runtime.d.ts +2 -0
- package/dist/host/durable-object-runtime.js +2 -0
- package/dist/host/durable-object-storage.d.ts +2 -0
- package/dist/host/durable-object-storage.js +0 -0
- package/dist/host/durable-object.d.ts +83 -0
- package/dist/host/durable-object.js +191 -0
- package/dist/host/durable-object.js.map +1 -0
- package/dist/host/websocket-wire.d.ts +2 -0
- package/dist/host/websocket-wire.js +88 -0
- package/dist/host/websocket-wire.js.map +1 -0
- package/dist/id-generator-C2Q15uZM.d.ts +33 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/keep-alive-DYDsH6qN.d.ts +111 -0
- package/dist/keep-alive-p8dIcSVy.js +109 -0
- package/dist/keep-alive-p8dIcSVy.js.map +1 -0
- package/dist/message-transcript-BCHdHAe2.d.ts +32 -0
- package/dist/prompt-projector-9_02lk5-.d.ts +40 -0
- package/dist/reduced-state-C4nVVzz9.js +910 -0
- package/dist/reduced-state-C4nVVzz9.js.map +1 -0
- package/dist/reducer-registry-C0svUa63.d.ts +69 -0
- package/dist/runtime-C56FQxiL.d.ts +60 -0
- package/dist/services/compaction.d.ts +2 -0
- package/dist/services/compaction.js +426 -0
- package/dist/services/compaction.js.map +1 -0
- package/dist/services/id-generator.d.ts +2 -0
- package/dist/services/id-generator.js +56 -0
- package/dist/services/id-generator.js.map +1 -0
- package/dist/services/prompt-projector.d.ts +2 -0
- package/dist/services/prompt-projector.js +27 -0
- package/dist/services/prompt-projector.js.map +1 -0
- package/dist/services/reducer-registry.d.ts +2 -0
- package/dist/services/reducer-registry.js +71 -0
- package/dist/services/reducer-registry.js.map +1 -0
- package/dist/services/runtime.d.ts +2 -0
- package/dist/services/runtime.js +84 -0
- package/dist/services/runtime.js.map +1 -0
- package/dist/services/session-query.d.ts +2 -0
- package/dist/services/session-query.js +2 -0
- package/dist/services/session-store.d.ts +2 -0
- package/dist/services/session-store.js +2 -0
- package/dist/services/sink-registry.d.ts +2 -0
- package/dist/services/sink-registry.js +2 -0
- package/dist/services/span-names.d.ts +28 -0
- package/dist/services/span-names.js +42 -0
- package/dist/services/span-names.js.map +1 -0
- package/dist/services/tool-registry.d.ts +2 -0
- package/dist/services/tool-registry.js +46 -0
- package/dist/services/tool-registry.js.map +1 -0
- package/dist/services/tracing.d.ts +76 -0
- package/dist/services/tracing.js +116 -0
- package/dist/services/tracing.js.map +1 -0
- package/dist/session-query-DOc1KanA.js +2930 -0
- package/dist/session-query-DOc1KanA.js.map +1 -0
- package/dist/session-query-DlRo5Ufc.d.ts +769 -0
- package/dist/session-store-D2Ore1QC.d.ts +295 -0
- package/dist/session-store-pYxQW9qh.js +214 -0
- package/dist/session-store-pYxQW9qh.js.map +1 -0
- package/dist/sink-registry-CFC6xjsN.js +312 -0
- package/dist/sink-registry-CFC6xjsN.js.map +1 -0
- package/dist/sink-registry-CIU0LD3m.d.ts +158 -0
- package/dist/testkit/layers.d.ts +101 -0
- package/dist/testkit/layers.js +108 -0
- package/dist/testkit/layers.js.map +1 -0
- package/dist/tool-registry-CcnkAAQK.d.ts +51 -0
- package/dist/tracing-BXHAkxkx.d.ts +111 -0
- package/dist/types/commands.d.ts +2 -0
- package/dist/types/commands.js +60 -0
- package/dist/types/commands.js.map +1 -0
- package/dist/types/core.d.ts +2 -0
- package/dist/types/core.js +68 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/events/durable.d.ts +2 -0
- package/dist/types/events/durable.js +2 -0
- package/dist/types/events.d.ts +4 -0
- package/dist/types/events.js +90 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/tracing.d.ts +2 -0
- package/dist/types/tracing.js +99 -0
- package/dist/types/tracing.js.map +1 -0
- package/dist/websocket-wire-DvOu_6BJ.d.ts +16773 -0
- package/docs/assets/architecture.svg +106 -0
- package/docs/assets/event-sequence.svg +143 -0
- package/docs/assets/gcp-trace.png +0 -0
- package/docs/message-steering.md +831 -0
- package/docs/releasing.md +57 -0
- package/docs/spec.md +774 -0
- package/docs/subagents.md +725 -0
- package/docs/testing.md +64 -0
- package/docs/ui-projection.md +742 -0
- package/docs/websocket-protocol.md +613 -0
- package/examples/001-no-tools/README.md +65 -0
- package/examples/001-no-tools/worker.ts +79 -0
- package/examples/002-slack-bridge/README.md +134 -0
- package/examples/002-slack-bridge/events.ts +115 -0
- package/examples/002-slack-bridge/reducer.ts +216 -0
- package/examples/002-slack-bridge/scenario.test.ts +223 -0
- package/examples/002-slack-bridge/sinks.ts +109 -0
- package/examples/002-slack-bridge/worker.ts +140 -0
- package/examples/003-sandbox-lifecycle/README.md +78 -0
- package/examples/003-sandbox-lifecycle/events.ts +203 -0
- package/examples/003-sandbox-lifecycle/reducer.ts +305 -0
- package/examples/003-sandbox-lifecycle/scenario.test.ts +202 -0
- package/examples/_shared/event-id.ts +12 -0
- package/examples/_shared/http.ts +27 -0
- package/examples/_shared/openai.ts +33 -0
- package/package.json +181 -0
- package/testing/offline-trace/README.md +63 -0
- package/tooling/oxlint/index.mjs +15 -0
- package/tooling/oxlint/rules/effect-span-from-catalog.mjs +152 -0
- package/tooling/oxlint/rules/span-catalog-format.mjs +74 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { f as CompactionExecutorId, m as ContextProjection, o as EDASessionStoreError, p as CompactionPolicyId, r as DurableAppendEntry, t as CommittedDurableEvent } from "./session-store-D2Ore1QC.js";
|
|
2
|
+
import { S as ReducedState } from "./command-queues-CQ9cwRP7.js";
|
|
3
|
+
import { t as IdGenerator } from "./id-generator-C2Q15uZM.js";
|
|
4
|
+
import { n as EventFactory, t as EDAKeepAlive } from "./keep-alive-DYDsH6qN.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 LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
10
|
+
|
|
11
|
+
//#region src/services/compaction.d.ts
|
|
12
|
+
/** Candidate durable range and retained cursor selected by compaction policy. */
|
|
13
|
+
declare const CompactionPlan: Schema.Struct<{
|
|
14
|
+
readonly policyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
|
|
15
|
+
readonly sourceFromSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
16
|
+
readonly sourceToSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
17
|
+
readonly retainedFromContextSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
18
|
+
}>;
|
|
19
|
+
type CompactionPlan = typeof CompactionPlan.Type;
|
|
20
|
+
/** Rough token heuristic used by the built-in compaction presets. */
|
|
21
|
+
declare const defaultCompactionCharsPerToken = 4;
|
|
22
|
+
/** Production-oriented context threshold for the built-in approximate-token policy. */
|
|
23
|
+
declare const defaultCompactionThresholdTokens = 220000;
|
|
24
|
+
/** Recent model-facing tail retained verbatim by the built-in approximate-token policy. */
|
|
25
|
+
declare const defaultCompactionRetainTailTokens = 40000;
|
|
26
|
+
/** Minimum newly summarizable prefix needed before the approximate-token policy plans work. */
|
|
27
|
+
declare const defaultCompactionMinSummarizableTokens = 10000;
|
|
28
|
+
/** Approximate-token policy options for common production compaction. */
|
|
29
|
+
interface ApproximateTokenThresholdCompactionPolicyOptions {
|
|
30
|
+
/** Stable policy id stored on summary artifacts. */
|
|
31
|
+
readonly policyId?: string;
|
|
32
|
+
/** Context-size threshold that triggers compaction. Defaults to 220k tokens. */
|
|
33
|
+
readonly thresholdTokens?: number;
|
|
34
|
+
/** Recent tail retained verbatim after compaction. Defaults to 40k tokens. */
|
|
35
|
+
readonly retainTailTokens?: number;
|
|
36
|
+
/** Smallest prefix worth summarizing. Defaults to 10k tokens. */
|
|
37
|
+
readonly minSummarizableTokens?: number;
|
|
38
|
+
/** Character-to-token divisor for the approximate estimator. Defaults to 4. */
|
|
39
|
+
readonly charsPerToken?: number;
|
|
40
|
+
}
|
|
41
|
+
/** LanguageModel-backed summary executor options. */
|
|
42
|
+
interface LanguageModelSummaryCompactionExecutorOptions {
|
|
43
|
+
/** Stable executor id stored on summary artifacts. */
|
|
44
|
+
readonly executorId?: string;
|
|
45
|
+
/** Prefix used for the synthetic prompt message inserted into future context. */
|
|
46
|
+
readonly summaryMessagePrefix?: string;
|
|
47
|
+
}
|
|
48
|
+
/** Input visible to policy decisions. */
|
|
49
|
+
interface CompactionPolicyInput {
|
|
50
|
+
readonly state: ReducedState;
|
|
51
|
+
readonly context: ContextProjection;
|
|
52
|
+
}
|
|
53
|
+
/** Result produced by the summary executor before the framework commits it. */
|
|
54
|
+
declare const CompactionOutput: Schema.Struct<{
|
|
55
|
+
readonly text: Schema.NonEmptyString;
|
|
56
|
+
readonly promptMessage: Schema.Struct<{
|
|
57
|
+
readonly role: Schema.Literal<"user">;
|
|
58
|
+
readonly content: Schema.Union<readonly [Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
|
|
59
|
+
readonly type: Schema.Literal<"text">;
|
|
60
|
+
readonly text: Schema.String;
|
|
61
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
62
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
63
|
+
}>>>, Schema.String, never, never>, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"text">;
|
|
65
|
+
readonly text: Schema.String;
|
|
66
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
67
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
68
|
+
}>, Schema.Struct<{
|
|
69
|
+
readonly type: Schema.Literal<"file">;
|
|
70
|
+
readonly mediaType: Schema.String;
|
|
71
|
+
readonly fileName: Schema.optional<Schema.String>;
|
|
72
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array, Schema.URL]>;
|
|
73
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
74
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
75
|
+
}>]>>]>;
|
|
76
|
+
readonly "~effect/ai/Prompt/Message": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Message">>;
|
|
77
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
78
|
+
}>;
|
|
79
|
+
readonly executorId: Schema.optionalKey<Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">>;
|
|
80
|
+
}>;
|
|
81
|
+
type CompactionOutput = typeof CompactionOutput.Type;
|
|
82
|
+
/** Executor input with framework-minted lifecycle identities. */
|
|
83
|
+
interface CompactionExecutorInput extends CompactionPolicyInput {
|
|
84
|
+
readonly plan: CompactionPlan;
|
|
85
|
+
}
|
|
86
|
+
declare const CompactionError_base: Schema.Class<CompactionError, Schema.TaggedStruct<"CompactionError", {
|
|
87
|
+
readonly message: Schema.String;
|
|
88
|
+
}>, import("effect/Cause").YieldableError>;
|
|
89
|
+
/** Typed failure from policy planning or summary generation. */
|
|
90
|
+
declare class CompactionError extends CompactionError_base {}
|
|
91
|
+
/** Service contract for deciding whether the current context should be compacted. */
|
|
92
|
+
interface CompactionPolicyShape {
|
|
93
|
+
readonly id: CompactionPolicyId;
|
|
94
|
+
readonly plan: (input: CompactionPolicyInput) => Effect.Effect<CompactionPlan | undefined, CompactionError>;
|
|
95
|
+
}
|
|
96
|
+
declare const CompactionPolicy_base: Context.ServiceClass<CompactionPolicy, "@effect-durable-agent/CompactionPolicy", CompactionPolicyShape>;
|
|
97
|
+
/** Decides whether a safe prompt-context rebase should be attempted. */
|
|
98
|
+
declare class CompactionPolicy extends CompactionPolicy_base {
|
|
99
|
+
/** Default policy: compaction is disabled and commits no skip events. */
|
|
100
|
+
static readonly Disabled: Layer.Layer<CompactionPolicy, never, never>;
|
|
101
|
+
/** Test/app hook for replacing the policy with a concrete planner. */
|
|
102
|
+
static readonly FromFunction: (id: string, plan: CompactionPolicyShape["plan"]) => Layer.Layer<CompactionPolicy>;
|
|
103
|
+
/**
|
|
104
|
+
* Common production policy: compact when approximate prompt context exceeds a token threshold.
|
|
105
|
+
*
|
|
106
|
+
* The policy keeps a recent tail verbatim, summarizes the older prefix, and advances from the
|
|
107
|
+
* current summary cursor so repeated compactions behave like the first one.
|
|
108
|
+
*/
|
|
109
|
+
static readonly ApproximateTokenThreshold: (options?: ApproximateTokenThresholdCompactionPolicyOptions) => Layer.Layer<CompactionPolicy>;
|
|
110
|
+
}
|
|
111
|
+
/** Service contract for turning a selected compaction range into a summary artifact. */
|
|
112
|
+
interface CompactionExecutorShape {
|
|
113
|
+
readonly id: CompactionExecutorId;
|
|
114
|
+
readonly execute: (input: CompactionExecutorInput) => Effect.Effect<CompactionOutput, CompactionError>;
|
|
115
|
+
}
|
|
116
|
+
declare const CompactionExecutor_base: Context.ServiceClass<CompactionExecutor, "@effect-durable-agent/CompactionExecutor", CompactionExecutorShape>;
|
|
117
|
+
/** Produces a cumulative summary artifact for a selected compaction plan. */
|
|
118
|
+
declare class CompactionExecutor extends CompactionExecutor_base {
|
|
119
|
+
/** Placeholder executor for the disabled default policy. It should never be called. */
|
|
120
|
+
static readonly Disabled: Layer.Layer<CompactionExecutor, never, never>;
|
|
121
|
+
/** Test/app hook for replacing summary generation. */
|
|
122
|
+
static readonly FromFunction: (id: string, execute: CompactionExecutorShape["execute"]) => Layer.Layer<CompactionExecutor>;
|
|
123
|
+
/** Summary executor backed by the configured Effect AI LanguageModel. */
|
|
124
|
+
static readonly LanguageModelSummary: (options?: LanguageModelSummaryCompactionExecutorOptions) => Layer.Layer<CompactionExecutor, never, LanguageModel.LanguageModel>;
|
|
125
|
+
}
|
|
126
|
+
/** Inputs needed by the framework-owned compaction lifecycle runner. */
|
|
127
|
+
interface CompactionRunnerInput {
|
|
128
|
+
readonly state: ReducedState;
|
|
129
|
+
readonly context: ContextProjection;
|
|
130
|
+
readonly appendDurableEntries: (entries: ReadonlyArray<DurableAppendEntry>) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
131
|
+
}
|
|
132
|
+
/** Runtime service that executes framework-owned compaction lifecycles. */
|
|
133
|
+
interface CompactionRunnerShape {
|
|
134
|
+
/** Evaluate policy and run one compaction if a plan is selected. */
|
|
135
|
+
readonly maybeCompact: (input: CompactionRunnerInput) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
136
|
+
}
|
|
137
|
+
declare const CompactionRunner_base: Context.ServiceClass<CompactionRunner, "@effect-durable-agent/CompactionRunner", CompactionRunnerShape>;
|
|
138
|
+
/** Framework-owned compaction lifecycle runner. */
|
|
139
|
+
declare class CompactionRunner extends CompactionRunner_base {
|
|
140
|
+
static readonly Live: Layer.Layer<CompactionRunner, never, IdGenerator | CompactionPolicy | CompactionExecutor | EventFactory | EDAKeepAlive>;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { defaultCompactionRetainTailTokens as _, CompactionExecutorShape as a, CompactionPolicy as c, CompactionRunner as d, CompactionRunnerInput as f, defaultCompactionMinSummarizableTokens as g, defaultCompactionCharsPerToken as h, CompactionExecutorInput as i, CompactionPolicyInput as l, LanguageModelSummaryCompactionExecutorOptions as m, CompactionError as n, CompactionOutput as o, CompactionRunnerShape as p, CompactionExecutor as r, CompactionPlan as s, ApproximateTokenThresholdCompactionPolicyOptions as t, CompactionPolicyShape as u, defaultCompactionThresholdTokens as v };
|
|
144
|
+
//# sourceMappingURL=compaction-YayFKo_1.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Order from "effect/Order";
|
|
3
|
+
|
|
4
|
+
//#region src/types/core.d.ts
|
|
5
|
+
/** Durable conversation identity; one Durable Object stores one session.
|
|
6
|
+
*
|
|
7
|
+
* New EDA sessions are minted as UUIDv7. Migrated sessions may retain UUIDv4
|
|
8
|
+
* identities, so runtime identity accepts any RFC UUID without changing app
|
|
9
|
+
* URLs or R2 keys.
|
|
10
|
+
*/
|
|
11
|
+
declare const SessionId: Schema.brand<Schema.String, "SessionId">;
|
|
12
|
+
type SessionId = typeof SessionId.Type;
|
|
13
|
+
/** Durable event identity; `(sessionId, eventId)` is the idempotency key. */
|
|
14
|
+
declare const EventId: Schema.brand<Schema.String, "EventId">;
|
|
15
|
+
type EventId = typeof EventId.Type;
|
|
16
|
+
/** User input command identity. */
|
|
17
|
+
declare const CommandId: Schema.brand<Schema.String, "CommandId">;
|
|
18
|
+
type CommandId = typeof CommandId.Type;
|
|
19
|
+
/** Processing lifecycle identity triggered by one or more commands. */
|
|
20
|
+
declare const RunId: Schema.brand<Schema.String, "RunId">;
|
|
21
|
+
type RunId = typeof RunId.Type;
|
|
22
|
+
/** One LLM invocation within a run. */
|
|
23
|
+
declare const TurnId: Schema.brand<Schema.String, "TurnId">;
|
|
24
|
+
type TurnId = typeof TurnId.Type;
|
|
25
|
+
/** One concrete model inference for a turn. */
|
|
26
|
+
declare const InferenceId: Schema.brand<Schema.String, "InferenceId">;
|
|
27
|
+
type InferenceId = typeof InferenceId.Type;
|
|
28
|
+
/** One framework-owned tool invocation requested by the model. */
|
|
29
|
+
declare const ToolCallId: Schema.brand<Schema.String, "ToolCallId">;
|
|
30
|
+
type ToolCallId = typeof ToolCallId.Type;
|
|
31
|
+
/** Retained message body identity. */
|
|
32
|
+
declare const MessageId: Schema.brand<Schema.String, "MessageId">;
|
|
33
|
+
type MessageId = typeof MessageId.Type;
|
|
34
|
+
/** Optional live-stream demux identity, such as a `toolCallId`. */
|
|
35
|
+
declare const CorrelationId: Schema.brand<Schema.String, "CorrelationId">;
|
|
36
|
+
type CorrelationId = typeof CorrelationId.Type;
|
|
37
|
+
/** One compaction workflow identity. */
|
|
38
|
+
declare const CompactionId: Schema.brand<Schema.String, "CompactionId">;
|
|
39
|
+
type CompactionId = typeof CompactionId.Type;
|
|
40
|
+
/** One retained summary artifact identity. */
|
|
41
|
+
declare const SummaryId: Schema.brand<Schema.String, "SummaryId">;
|
|
42
|
+
type SummaryId = typeof SummaryId.Type;
|
|
43
|
+
/** One BaseState lifecycle identity. */
|
|
44
|
+
declare const BaseStateId: Schema.brand<Schema.String, "BaseStateId">;
|
|
45
|
+
type BaseStateId = typeof BaseStateId.Type;
|
|
46
|
+
/** Durable context projection version. */
|
|
47
|
+
declare const ContextVersion: Schema.brand<Schema.Int, "ContextVersion">;
|
|
48
|
+
type ContextVersion = typeof ContextVersion.Type;
|
|
49
|
+
/** Durable sequence number; `0` is the genesis/resume-before-first-event position. */
|
|
50
|
+
declare const SequenceNumber: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
51
|
+
type SequenceNumber = typeof SequenceNumber.Type;
|
|
52
|
+
/** In-memory ordering slot for ephemeral events anchored to a durable sequence. */
|
|
53
|
+
declare const SubSequenceNumber: Schema.brand<Schema.Int, "SubSequenceNumber">;
|
|
54
|
+
type SubSequenceNumber = typeof SubSequenceNumber.Type;
|
|
55
|
+
/** The only valid sub-sequence for durable events. */
|
|
56
|
+
declare const DurableSubSequenceNumber: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
|
|
57
|
+
type DurableSubSequenceNumber = typeof DurableSubSequenceNumber.Type;
|
|
58
|
+
/** Total live-stream order: durable events are `(seq, 0)`, ephemerals are `(anchorSeq, subSeq > 0)`. */
|
|
59
|
+
declare const Position: Schema.Struct<{
|
|
60
|
+
readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
61
|
+
readonly subSeq: Schema.brand<Schema.Int, "SubSequenceNumber">;
|
|
62
|
+
}>;
|
|
63
|
+
type Position = typeof Position.Type;
|
|
64
|
+
/** Position for committed durable events; `subSeq` is literally zero. */
|
|
65
|
+
declare const DurablePosition: Schema.Struct<{
|
|
66
|
+
readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
67
|
+
readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
|
|
68
|
+
}>;
|
|
69
|
+
type DurablePosition = typeof DurablePosition.Type;
|
|
70
|
+
/** Construct the live position for a committed durable event. */
|
|
71
|
+
declare const durablePosition: (seq: SequenceNumber) => DurablePosition;
|
|
72
|
+
/** Total ordering for live positions: compare durable `seq` first, then live `subSeq`. */
|
|
73
|
+
declare const PositionOrder: Order.Order<Position>;
|
|
74
|
+
/** Compare live positions lexicographically. */
|
|
75
|
+
declare const comparePosition: Order.Order<{
|
|
76
|
+
readonly seq: number & import("effect/Brand").Brand<"SequenceNumber">;
|
|
77
|
+
readonly subSeq: number & import("effect/Brand").Brand<"SubSequenceNumber">;
|
|
78
|
+
}>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { SummaryId as _, CorrelationId as a, comparePosition as b, EventId as c, Position as d, PositionOrder as f, SubSequenceNumber as g, SessionId as h, ContextVersion as i, InferenceId as l, SequenceNumber as m, CommandId as n, DurablePosition as o, RunId as p, CompactionId as r, DurableSubSequenceNumber as s, BaseStateId as t, MessageId as u, ToolCallId as v, durablePosition as x, TurnId as y };
|
|
81
|
+
//# sourceMappingURL=core-Hv3cFydL.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as deriveCommandQueues, i as PendingUserMessage, n as CommandQueues, o as emptyCommandQueues, r as PendingSteeringMessage, t as CommandQueueSource } from "../command-queues-CQ9cwRP7.js";
|
|
2
|
+
export { CommandQueueSource, CommandQueues, PendingSteeringMessage, PendingUserMessage, deriveCommandQueues, emptyCommandQueues };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/domain/command-queues.ts
|
|
2
|
+
/** Empty queue view for `initialReducedState` before any durable events exist. */
|
|
3
|
+
const emptyCommandQueues = {
|
|
4
|
+
pendingCommands: [],
|
|
5
|
+
queuedCommands: [],
|
|
6
|
+
activeControlCommands: [],
|
|
7
|
+
steeringByRun: /* @__PURE__ */ new Map(),
|
|
8
|
+
pendingQueue: [],
|
|
9
|
+
pendingSteers: [],
|
|
10
|
+
pausedQueue: []
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Derive scheduler queues from durable replay state.
|
|
14
|
+
*
|
|
15
|
+
* These queues are cached inside `ReducedState` for clarity and fast scheduler
|
|
16
|
+
* reads, but durable command/message/run records remain the source of truth.
|
|
17
|
+
* Never mutate a queue directly; fold durable events and derive again.
|
|
18
|
+
*/
|
|
19
|
+
const deriveCommandQueues = (state) => {
|
|
20
|
+
const pendingCommands = Array.from(state.commands.values()).filter(isPendingCommandRecord).map((record) => ({
|
|
21
|
+
commandId: record.commandId,
|
|
22
|
+
command: record.command,
|
|
23
|
+
admittedSeq: record.admittedSeq,
|
|
24
|
+
...record.admissionTrace === void 0 ? {} : { admissionTrace: record.admissionTrace }
|
|
25
|
+
})).sort((a, b) => a.admittedSeq - b.admittedSeq);
|
|
26
|
+
const pendingMessages = derivePendingUserMessages(state.messages);
|
|
27
|
+
const pendingMessageByCommandId = new Map(pendingMessages.map((message) => [message.commandId, message]));
|
|
28
|
+
return {
|
|
29
|
+
active: deriveActiveCommand(state),
|
|
30
|
+
pendingCommands,
|
|
31
|
+
queuedCommands: pendingCommands.filter((command) => {
|
|
32
|
+
if (command.command._tag !== "SubmitMessage") return false;
|
|
33
|
+
const message = pendingMessageByCommandId.get(command.commandId);
|
|
34
|
+
return message?.disposition === "queue" || message === void 0 && command.command.disposition === "queue";
|
|
35
|
+
}),
|
|
36
|
+
activeControlCommands: pendingCommands.filter((command) => isActiveControlCommand(command, pendingMessageByCommandId)),
|
|
37
|
+
steeringByRun: derivePendingSteeringByRun(state.messages),
|
|
38
|
+
pendingQueue: pendingMessages.filter((message) => message.disposition === "queue" && message.pausedByCommandId === void 0),
|
|
39
|
+
pendingSteers: pendingMessages.filter((message) => message.disposition === "steer"),
|
|
40
|
+
pausedQueue: pendingMessages.filter((message) => message.disposition === "queue" && message.pausedByCommandId !== void 0)
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const derivePendingUserMessages = (messages) => Array.from(messages.values()).flatMap((message) => {
|
|
44
|
+
if (message._tag !== "User" && message._tag !== "Steering" || message.consumedSeq !== void 0 || message.cancelledSeq !== void 0) return [];
|
|
45
|
+
return [{
|
|
46
|
+
messageId: message.messageId,
|
|
47
|
+
commandId: message.commandId,
|
|
48
|
+
content: message.content,
|
|
49
|
+
submittedSeq: message.seq,
|
|
50
|
+
effectiveSeq: message.promotedSeq ?? message.seq,
|
|
51
|
+
disposition: message.pausedByCommandId !== void 0 ? "queue" : message._tag === "Steering" ? "steer" : message.disposition ?? "queue",
|
|
52
|
+
...message._tag === "Steering" ? { targetRunId: message.runId } : {},
|
|
53
|
+
...message.pausedByCommandId === void 0 ? {} : { pausedByCommandId: message.pausedByCommandId }
|
|
54
|
+
}];
|
|
55
|
+
}).sort((left, right) => left.effectiveSeq - right.effectiveSeq);
|
|
56
|
+
const isPendingCommandRecord = (record) => record.command !== void 0 && record.admittedSeq !== void 0 && record.startedSeq === void 0;
|
|
57
|
+
const isActiveControlCommand = (command, pendingMessageByCommandId) => {
|
|
58
|
+
switch (command.command._tag) {
|
|
59
|
+
case "StopTurn":
|
|
60
|
+
case "CancelPendingMessage":
|
|
61
|
+
case "PromotePendingMessage": return true;
|
|
62
|
+
case "ResumePendingMessages": return false;
|
|
63
|
+
case "SubmitMessage": return command.command.disposition === "interrupt" || pendingMessageByCommandId.get(command.commandId)?.disposition === "steer" || pendingMessageByCommandId.get(command.commandId) === void 0 && command.command.disposition === "steer";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const deriveActiveCommand = (state) => {
|
|
67
|
+
for (const command of state.commands.values()) if (command.startedSeq !== void 0 && command.terminal === void 0) {
|
|
68
|
+
const activeRun = Array.from(state.runs.values()).find((run) => run.commandIds.includes(command.commandId) && run.terminal === void 0);
|
|
69
|
+
return activeRun === void 0 ? { commandId: command.commandId } : {
|
|
70
|
+
commandId: command.commandId,
|
|
71
|
+
runId: activeRun.runId
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const derivePendingSteeringByRun = (messages) => {
|
|
76
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const message of messages.values()) {
|
|
78
|
+
if (message._tag !== "Steering" || message.consumedSeq !== void 0 || message.cancelledSeq !== void 0) continue;
|
|
79
|
+
const existing = grouped.get(message.runId) ?? [];
|
|
80
|
+
existing.push({
|
|
81
|
+
messageId: message.messageId,
|
|
82
|
+
commandId: message.commandId,
|
|
83
|
+
runId: message.runId,
|
|
84
|
+
content: message.content,
|
|
85
|
+
queuedSeq: message.seq,
|
|
86
|
+
...message.consumedSeq === void 0 ? {} : { consumedSeq: message.consumedSeq },
|
|
87
|
+
...message.consumedTurnId === void 0 ? {} : { consumedTurnId: message.consumedTurnId }
|
|
88
|
+
});
|
|
89
|
+
grouped.set(message.runId, existing);
|
|
90
|
+
}
|
|
91
|
+
for (const [runId, entries] of grouped) grouped.set(runId, entries.sort((a, b) => a.queuedSeq - b.queuedSeq));
|
|
92
|
+
return grouped;
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { deriveCommandQueues, emptyCommandQueues };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=command-queues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-queues.js","names":[],"sources":["../../src/domain/command-queues.ts"],"sourcesContent":["import type {\n ActiveCommandEvidence,\n CommandRecord,\n MessageRecord,\n PendingCommand,\n RunRecord,\n} from \"./reduced-state\";\nimport type { MessageId, RunId, SequenceNumber, TurnId } from \"../types/core\";\nimport type { UserMessageContent } from \"../types/commands\";\n\n/**\n * A steering message admitted for an active run but not necessarily consumed\n * by a later turn yet.\n */\nexport interface PendingSteeringMessage {\n /** Durable message identity used by `TurnStarted.inputMessageIds` when consumed. */\n readonly messageId: MessageId;\n /** Command that admitted this steering message. */\n readonly commandId: PendingCommand[\"commandId\"];\n /** Active run this steering message may continue. */\n readonly runId: RunId;\n /** User content to append to the next continuation prompt when selected. */\n readonly content: UserMessageContent;\n /** Sequence where `SteeringMessageQueued` committed; used for one-by-one ordering. */\n readonly queuedSeq: SequenceNumber;\n /** Sequence where a later `TurnStarted` consumed this steering message. */\n readonly consumedSeq?: SequenceNumber;\n /** Turn that consumed this steering message. */\n readonly consumedTurnId?: TurnId;\n}\n\n/**\n * Materialized command scheduler view derived from durable `ReducedState`.\n *\n * `pendingCommands` means admitted commands with no `CommandStarted` yet.\n * `queuedCommands` is the FIFO subset that should wait for idle session work\n * (`SubmitMessage{disposition:\"queue\"}`). `activeControlCommands` is the\n * subset that may affect an active run (`StopTurn`, `steer`, `interrupt`).\n * `steeringByRun` is not a command queue; it is queued steering content already\n * admitted/completed as commands but not yet consumed by a turn.\n */\nexport interface CommandQueues {\n /** Started command without terminal command evidence, plus active run when known. */\n readonly active?: ActiveCommandEvidence;\n /** All admitted commands that have not yet crossed `CommandStarted`. */\n readonly pendingCommands: ReadonlyArray<PendingCommand>;\n /** FIFO user-message work that waits until no command/run is active. */\n readonly queuedCommands: ReadonlyArray<PendingCommand>;\n /** Stop/steer/interrupt work that can be interpreted while a run is active. */\n readonly activeControlCommands: ReadonlyArray<PendingCommand>;\n /** Unconsumed steering messages grouped by target run and sorted by queued seq. */\n readonly steeringByRun: ReadonlyMap<RunId, ReadonlyArray<PendingSteeringMessage>>;\n /** Admission-time queue messages eligible for separate work. */\n readonly pendingQueue: ReadonlyArray<PendingUserMessage>;\n /** Admission-time steer messages eligible at the next boundary. */\n readonly pendingSteers: ReadonlyArray<PendingUserMessage>;\n /** Queue messages held by an explicit interruption pause. */\n readonly pausedQueue: ReadonlyArray<PendingUserMessage>;\n}\n\nexport interface PendingUserMessage {\n readonly messageId: MessageId;\n readonly commandId: PendingCommand[\"commandId\"];\n readonly content: UserMessageContent;\n readonly submittedSeq: SequenceNumber;\n readonly effectiveSeq: SequenceNumber;\n readonly disposition: \"queue\" | \"steer\";\n readonly targetRunId?: RunId;\n readonly pausedByCommandId?: PendingCommand[\"commandId\"];\n}\n\n/** Durable records needed to derive `CommandQueues` without services or refs. */\nexport interface CommandQueueSource {\n readonly commands: ReadonlyMap<PendingCommand[\"commandId\"], CommandRecord>;\n readonly runs: ReadonlyMap<RunId, RunRecord>;\n readonly messages: ReadonlyMap<MessageId, MessageRecord>;\n}\n\n/** Empty queue view for `initialReducedState` before any durable events exist. */\nexport const emptyCommandQueues: CommandQueues = {\n pendingCommands: [],\n queuedCommands: [],\n activeControlCommands: [],\n steeringByRun: new Map(),\n pendingQueue: [],\n pendingSteers: [],\n pausedQueue: [],\n};\n\n/**\n * Derive scheduler queues from durable replay state.\n *\n * These queues are cached inside `ReducedState` for clarity and fast scheduler\n * reads, but durable command/message/run records remain the source of truth.\n * Never mutate a queue directly; fold durable events and derive again.\n */\nexport const deriveCommandQueues = (state: CommandQueueSource): CommandQueues => {\n const pendingCommands = Array.from(state.commands.values())\n .filter(isPendingCommandRecord)\n .map((record) => ({\n commandId: record.commandId,\n command: record.command,\n admittedSeq: record.admittedSeq,\n ...(record.admissionTrace === undefined ? {} : { admissionTrace: record.admissionTrace }),\n }))\n .sort((a, b) => a.admittedSeq - b.admittedSeq);\n\n const pendingMessages = derivePendingUserMessages(state.messages);\n const pendingMessageByCommandId = new Map(\n pendingMessages.map((message) => [message.commandId, message] as const),\n );\n return {\n active: deriveActiveCommand(state),\n pendingCommands,\n queuedCommands: pendingCommands.filter((command) => {\n if (command.command._tag !== \"SubmitMessage\") return false;\n const message = pendingMessageByCommandId.get(command.commandId);\n return (\n message?.disposition === \"queue\" ||\n (message === undefined && command.command.disposition === \"queue\")\n );\n }),\n activeControlCommands: pendingCommands.filter((command) =>\n isActiveControlCommand(command, pendingMessageByCommandId),\n ),\n steeringByRun: derivePendingSteeringByRun(state.messages),\n pendingQueue: pendingMessages.filter(\n (message) => message.disposition === \"queue\" && message.pausedByCommandId === undefined,\n ),\n pendingSteers: pendingMessages.filter((message) => message.disposition === \"steer\"),\n pausedQueue: pendingMessages.filter(\n (message) => message.disposition === \"queue\" && message.pausedByCommandId !== undefined,\n ),\n };\n};\n\nconst derivePendingUserMessages = (\n messages: ReadonlyMap<MessageId, MessageRecord>,\n): ReadonlyArray<PendingUserMessage> =>\n Array.from(messages.values())\n .flatMap((message): ReadonlyArray<PendingUserMessage> => {\n if (\n (message._tag !== \"User\" && message._tag !== \"Steering\") ||\n message.consumedSeq !== undefined ||\n message.cancelledSeq !== undefined\n ) {\n return [];\n }\n return [\n {\n messageId: message.messageId,\n commandId: message.commandId,\n content: message.content,\n submittedSeq: message.seq,\n effectiveSeq: message.promotedSeq ?? message.seq,\n disposition:\n message.pausedByCommandId !== undefined\n ? \"queue\"\n : message._tag === \"Steering\"\n ? \"steer\"\n : (message.disposition ?? \"queue\"),\n ...(message._tag === \"Steering\" ? { targetRunId: message.runId } : {}),\n ...(message.pausedByCommandId === undefined\n ? {}\n : { pausedByCommandId: message.pausedByCommandId }),\n },\n ];\n })\n .sort((left, right) => left.effectiveSeq - right.effectiveSeq);\n\nconst isPendingCommandRecord = (\n record: CommandRecord,\n): record is CommandRecord & {\n readonly command: NonNullable<CommandRecord[\"command\"]>;\n readonly admittedSeq: SequenceNumber;\n} =>\n record.command !== undefined &&\n record.admittedSeq !== undefined &&\n record.startedSeq === undefined;\n\nconst isActiveControlCommand = (\n command: PendingCommand,\n pendingMessageByCommandId: ReadonlyMap<PendingCommand[\"commandId\"], PendingUserMessage>,\n): boolean => {\n switch (command.command._tag) {\n case \"StopTurn\":\n case \"CancelPendingMessage\":\n case \"PromotePendingMessage\":\n return true;\n case \"ResumePendingMessages\":\n return false;\n case \"SubmitMessage\":\n return (\n command.command.disposition === \"interrupt\" ||\n pendingMessageByCommandId.get(command.commandId)?.disposition === \"steer\" ||\n (pendingMessageByCommandId.get(command.commandId) === undefined &&\n command.command.disposition === \"steer\")\n );\n }\n};\n\nconst deriveActiveCommand = (state: CommandQueueSource): ActiveCommandEvidence | undefined => {\n for (const command of state.commands.values()) {\n if (command.startedSeq !== undefined && command.terminal === undefined) {\n const activeRun = Array.from(state.runs.values()).find(\n (run) => run.commandIds.includes(command.commandId) && run.terminal === undefined,\n );\n return activeRun === undefined\n ? { commandId: command.commandId }\n : { commandId: command.commandId, runId: activeRun.runId };\n }\n }\n return undefined;\n};\n\nconst derivePendingSteeringByRun = (\n messages: ReadonlyMap<MessageId, MessageRecord>,\n): ReadonlyMap<RunId, ReadonlyArray<PendingSteeringMessage>> => {\n const grouped = new Map<RunId, Array<PendingSteeringMessage>>();\n for (const message of messages.values()) {\n if (\n message._tag !== \"Steering\" ||\n message.consumedSeq !== undefined ||\n message.cancelledSeq !== undefined\n ) {\n continue;\n }\n const existing = grouped.get(message.runId) ?? [];\n existing.push({\n messageId: message.messageId,\n commandId: message.commandId,\n runId: message.runId,\n content: message.content,\n queuedSeq: message.seq,\n ...(message.consumedSeq === undefined ? {} : { consumedSeq: message.consumedSeq }),\n ...(message.consumedTurnId === undefined ? {} : { consumedTurnId: message.consumedTurnId }),\n });\n grouped.set(message.runId, existing);\n }\n for (const [runId, entries] of grouped) {\n grouped.set(\n runId,\n entries.sort((a, b) => a.queuedSeq - b.queuedSeq),\n );\n }\n return grouped;\n};\n"],"mappings":";;AA+EA,MAAa,qBAAoC;CAC/C,iBAAiB,CAAC;CAClB,gBAAgB,CAAC;CACjB,uBAAuB,CAAC;CACxB,+BAAe,IAAI,IAAI;CACvB,cAAc,CAAC;CACf,eAAe,CAAC;CAChB,aAAa,CAAC;AAChB;;;;;;;;AASA,MAAa,uBAAuB,UAA6C;CAC/E,MAAM,kBAAkB,MAAM,KAAK,MAAM,SAAS,OAAO,CAAC,EACvD,OAAO,sBAAsB,EAC7B,KAAK,YAAY;EAChB,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,aAAa,OAAO;EACpB,GAAI,OAAO,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,OAAO,eAAe;CACzF,EAAE,EACD,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,WAAW;CAE/C,MAAM,kBAAkB,0BAA0B,MAAM,QAAQ;CAChE,MAAM,4BAA4B,IAAI,IACpC,gBAAgB,KAAK,YA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a,QAAQ,YAAY;GAChF,GAAI,QAAQ,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,QAAQ,eAAe;EAC3F,CAAC;EACD,QAAQ,IAAI,QAAQ,OAAO,QAAQ;CACrC;CACA,KAAK,MAAM,CAAC,OAAO,YAAY,SAC7B,QAAQ,IACN,OACA,QAAQ,MAAM,GAAG,MAAM,EAAE,YAAY,EAAE,SAAS,CAClD;CAEF,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as durableMessageTranscript, i as contextProjectionPromptWithUserContents, n as contextProjectionPrompt, o as durableTranscriptPrompt, r as contextProjectionPromptWithUserContent, s as durableTranscriptPromptWithUserContent, t as DurableTranscriptMessage } from "../message-transcript-BCHdHAe2.js";
|
|
2
|
+
export { DurableTranscriptMessage, contextProjectionPrompt, contextProjectionPromptWithUserContent, contextProjectionPromptWithUserContents, durableMessageTranscript, durableTranscriptPrompt, durableTranscriptPromptWithUserContent };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as Prompt from "effect/unstable/ai/Prompt";
|
|
2
|
+
//#region src/domain/message-transcript.ts
|
|
3
|
+
/** Derive the durable user/assistant transcript in committed sequence order. */
|
|
4
|
+
const durableMessageTranscript = (state) => Array.from(state.messages.values()).filter(isDurableTranscriptMessage).sort(compareBySeq);
|
|
5
|
+
const isDurableTranscriptMessage = (message) => message._tag === "User" && message.cancelledSeq === void 0 || message._tag === "Assistant" || message._tag === "AssistantPartial" || message._tag === "Steering" && message.consumedSeq !== void 0;
|
|
6
|
+
/** Convert all durable transcript messages and exact tool-result parts into provider prompt history. */
|
|
7
|
+
const durableTranscriptPrompt = (state) => contextProjectionPrompt(state, void 0);
|
|
8
|
+
/** Convert the current compacted context into provider prompt history. */
|
|
9
|
+
const contextProjectionPrompt = (state, context) => {
|
|
10
|
+
const messages = promptTranscriptItems(state, context).flatMap((item) => {
|
|
11
|
+
switch (item._tag) {
|
|
12
|
+
case "Message": return [transcriptMessageToPromptMessage(item.message)];
|
|
13
|
+
case "Summary": return [item.message];
|
|
14
|
+
case "ToolResult": return [Prompt.makeMessage("tool", { content: [item.part] })];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
validateToolCallPairing(messages);
|
|
18
|
+
return Prompt.fromMessages(messages);
|
|
19
|
+
};
|
|
20
|
+
/** Build a provider prompt with extra user content selected by the scheduler but not yet folded. */
|
|
21
|
+
const durableTranscriptPromptWithUserContent = (state, content) => contextProjectionPromptWithUserContent(state, void 0, content);
|
|
22
|
+
/** Build a compacted provider prompt with extra user content selected by the scheduler. */
|
|
23
|
+
const contextProjectionPromptWithUserContent = (state, context, content) => Prompt.fromMessages([...contextProjectionPrompt(state, context).content, Prompt.makeMessage("user", { content })]);
|
|
24
|
+
/** Build a compacted provider prompt with multiple scheduler-selected user messages. */
|
|
25
|
+
const contextProjectionPromptWithUserContents = (state, context, contents) => Prompt.fromMessages([...contextProjectionPrompt(state, context).content, ...contents.map((content) => Prompt.makeMessage("user", { content }))]);
|
|
26
|
+
const compareBySeq = (left, right) => messageTranscriptSeq(left) - messageTranscriptSeq(right) || left.seq - right.seq;
|
|
27
|
+
const promptTranscriptItems = (state, context) => {
|
|
28
|
+
const messages = promptContextMessages(state, context);
|
|
29
|
+
const assistantInfoByInference = new Map(messages.flatMap((message) => message._tag === "Assistant" || message._tag === "AssistantPartial" ? [[message.inferenceId, assistantPromptInfo(message)]] : []));
|
|
30
|
+
const messageItems = messages.map((message) => ({
|
|
31
|
+
_tag: "Message",
|
|
32
|
+
order: promptContextMessageSeq(message),
|
|
33
|
+
message
|
|
34
|
+
}));
|
|
35
|
+
const summaryItem = context?.currentSummary === void 0 ? [] : [{
|
|
36
|
+
_tag: "Summary",
|
|
37
|
+
order: Number.MIN_SAFE_INTEGER,
|
|
38
|
+
message: context.currentSummary.promptMessage
|
|
39
|
+
}];
|
|
40
|
+
const toolItems = Array.from(state.toolCalls?.values() ?? []).flatMap((tool) => toolPromptItems(tool, assistantInfoByInference));
|
|
41
|
+
return [
|
|
42
|
+
...messageItems,
|
|
43
|
+
...summaryItem,
|
|
44
|
+
...toolItems
|
|
45
|
+
].sort((left, right) => left.order - right.order);
|
|
46
|
+
};
|
|
47
|
+
const toolPromptItems = (tool, assistantInfoByInference) => {
|
|
48
|
+
const { decision } = tool;
|
|
49
|
+
if (decision === void 0) return [];
|
|
50
|
+
const assistant = assistantInfoByInference.get(decision.inferenceId);
|
|
51
|
+
if (assistant === void 0) return [];
|
|
52
|
+
if (decision._tag === "Rejected") return decision.promptPart === void 0 ? [] : [{
|
|
53
|
+
_tag: "ToolResult",
|
|
54
|
+
order: syntheticToolResultOrder(assistant, decision.providerPartId),
|
|
55
|
+
part: decision.promptPart
|
|
56
|
+
}];
|
|
57
|
+
const terminal = tool.terminal;
|
|
58
|
+
if (terminal === void 0 || terminal.promptPart === void 0) return [];
|
|
59
|
+
return [{
|
|
60
|
+
_tag: "ToolResult",
|
|
61
|
+
order: syntheticToolResultOrder(assistant, decision.providerPartId),
|
|
62
|
+
part: terminal.promptPart
|
|
63
|
+
}];
|
|
64
|
+
};
|
|
65
|
+
const assistantPromptInfo = (message) => ({
|
|
66
|
+
order: messageTranscriptSeq(message),
|
|
67
|
+
toolCallOrderByProviderPartId: new Map(assistantToolCallParts(message).map(({ part, index }) => [part.id, index]))
|
|
68
|
+
});
|
|
69
|
+
const assistantToolCallParts = (message) => (message.promptParts ?? []).flatMap((part, index) => part.type === "tool-call" ? [{
|
|
70
|
+
part,
|
|
71
|
+
index
|
|
72
|
+
}] : []);
|
|
73
|
+
const syntheticToolResultOrder = (assistant, providerPartId) => assistant.order + .1 + (assistant.toolCallOrderByProviderPartId.get(providerPartId) ?? 0) * .001;
|
|
74
|
+
const validateToolCallPairing = (messages) => {
|
|
75
|
+
const pending = /* @__PURE__ */ new Set();
|
|
76
|
+
for (const message of messages) {
|
|
77
|
+
if (pending.size > 0 && message.role !== "tool") throw new Error(unpairedToolCallMessage(pending));
|
|
78
|
+
if (message.role === "tool") {
|
|
79
|
+
for (const part of message.content) if (part.type === "tool-result") pending.delete(part.id);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (message.role === "assistant") {
|
|
83
|
+
for (const part of message.content) if (part.type === "tool-call" && !part.providerExecuted) pending.add(part.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (pending.size > 0) throw new Error(unpairedToolCallMessage(pending));
|
|
87
|
+
};
|
|
88
|
+
const unpairedToolCallMessage = (pending) => `Prompt transcript contains assistant tool-call(s) without matching tool result(s): ${Array.from(pending).join(", ")}`;
|
|
89
|
+
const promptContextMessages = (state, context) => {
|
|
90
|
+
const retainedFromContextSeq = context?.currentSummary?.retainedFromContextSeq ?? 0;
|
|
91
|
+
const messages = durableMessageTranscript(state).filter((message) => isConsumedForPrompt(message) && messageTranscriptSeq(message) >= retainedFromContextSeq);
|
|
92
|
+
const system = Array.from(state.messages.values()).find((message) => message._tag === "System");
|
|
93
|
+
return system === void 0 ? messages : [system, ...messages];
|
|
94
|
+
};
|
|
95
|
+
const isConsumedForPrompt = (message) => message._tag !== "User" || message.requestedDisposition === void 0 || message.consumedSeq !== void 0;
|
|
96
|
+
const transcriptMessageToPromptMessage = (message) => {
|
|
97
|
+
switch (message._tag) {
|
|
98
|
+
case "System": return Prompt.makeMessage("system", { content: message.content });
|
|
99
|
+
case "User":
|
|
100
|
+
case "Steering": return Prompt.makeMessage("user", { content: message.content });
|
|
101
|
+
case "Assistant":
|
|
102
|
+
case "AssistantPartial": return Prompt.makeMessage("assistant", { content: message.promptParts ?? assistantParts(message.content) });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const messageTranscriptSeq = (message) => message._tag === "User" || message._tag === "Steering" ? message.consumedSeq ?? message.seq : message.seq;
|
|
106
|
+
const promptContextMessageSeq = (message) => message._tag === "System" ? Number.NEGATIVE_INFINITY : messageTranscriptSeq(message);
|
|
107
|
+
const assistantParts = (content) => [...content.reasoning === void 0 ? [] : [Prompt.reasoningPart({ text: content.reasoning })], ...content.text.length === 0 ? [] : [Prompt.textPart({ text: content.text })]];
|
|
108
|
+
//#endregion
|
|
109
|
+
export { contextProjectionPrompt, contextProjectionPromptWithUserContent, contextProjectionPromptWithUserContents, durableMessageTranscript, durableTranscriptPrompt, durableTranscriptPromptWithUserContent };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=message-transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-transcript.js","names":[],"sources":["../../src/domain/message-transcript.ts"],"sourcesContent":["import * as Prompt from \"effect/unstable/ai/Prompt\";\n\nimport type { ContextProjection } from \"./context-projection\";\nimport type { MessageRecord, ReducedState, ToolCallRecord } from \"./reduced-state\";\nimport type { UserMessageContent } from \"../types/commands\";\n\n/** Durable user/assistant message records suitable for a session transcript. */\nexport type DurableTranscriptMessage =\n | Extract<MessageRecord, { readonly _tag: \"User\" | \"Assistant\" | \"AssistantPartial\" }>\n | (Extract<MessageRecord, { readonly _tag: \"Steering\" }> & {\n readonly consumedSeq: NonNullable<\n Extract<MessageRecord, { readonly _tag: \"Steering\" }>[\"consumedSeq\"]\n >;\n });\n\n/** Derive the durable user/assistant transcript in committed sequence order. */\nexport const durableMessageTranscript = (\n state: Pick<ReducedState, \"messages\">,\n): ReadonlyArray<DurableTranscriptMessage> =>\n Array.from(state.messages.values()).filter(isDurableTranscriptMessage).sort(compareBySeq);\n\nconst isDurableTranscriptMessage = (message: MessageRecord): message is DurableTranscriptMessage =>\n (message._tag === \"User\" && message.cancelledSeq === undefined) ||\n message._tag === \"Assistant\" ||\n message._tag === \"AssistantPartial\" ||\n (message._tag === \"Steering\" && message.consumedSeq !== undefined);\n\ntype SystemContextMessage = Extract<MessageRecord, { readonly _tag: \"System\" }>;\ntype PromptContextMessage = DurableTranscriptMessage | SystemContextMessage;\ntype PromptProjectionState = Pick<ReducedState, \"messages\"> &\n Partial<Pick<ReducedState, \"toolCalls\">>;\n\ntype AssistantPromptInfo = {\n readonly order: number;\n readonly toolCallOrderByProviderPartId: ReadonlyMap<string, number>;\n};\n\ntype PromptTranscriptItem =\n | {\n readonly _tag: \"Message\";\n readonly order: number;\n readonly message: PromptContextMessage;\n }\n | {\n readonly _tag: \"Summary\";\n readonly order: number;\n readonly message: Prompt.UserMessage;\n }\n | {\n readonly _tag: \"ToolResult\";\n readonly order: number;\n readonly part: Prompt.ToolResultPart;\n };\n\ntype ToolResultPromptTranscriptItem = Extract<\n PromptTranscriptItem,\n { readonly _tag: \"ToolResult\" }\n>;\n\n/** Convert all durable transcript messages and exact tool-result parts into provider prompt history. */\nexport const durableTranscriptPrompt = (state: PromptProjectionState): Prompt.Prompt =>\n contextProjectionPrompt(state, undefined);\n\n/** Convert the current compacted context into provider prompt history. */\nexport const contextProjectionPrompt = (\n state: PromptProjectionState,\n context: ContextProjection | undefined,\n): Prompt.Prompt => {\n const messages = promptTranscriptItems(state, context).flatMap(\n (item): ReadonlyArray<Prompt.Message> => {\n switch (item._tag) {\n case \"Message\":\n return [transcriptMessageToPromptMessage(item.message)];\n case \"Summary\":\n return [item.message];\n case \"ToolResult\":\n return [Prompt.makeMessage(\"tool\", { content: [item.part] })];\n }\n },\n );\n validateToolCallPairing(messages);\n return Prompt.fromMessages(messages);\n};\n\n/** Build a provider prompt with extra user content selected by the scheduler but not yet folded. */\nexport const durableTranscriptPromptWithUserContent = (\n state: PromptProjectionState,\n content: UserMessageContent,\n): Prompt.Prompt => contextProjectionPromptWithUserContent(state, undefined, content);\n\n/** Build a compacted provider prompt with extra user content selected by the scheduler. */\nexport const contextProjectionPromptWithUserContent = (\n state: PromptProjectionState,\n context: ContextProjection | undefined,\n content: UserMessageContent,\n): Prompt.Prompt =>\n Prompt.fromMessages([\n ...contextProjectionPrompt(state, context).content,\n Prompt.makeMessage(\"user\", { content }),\n ]);\n\n/** Build a compacted provider prompt with multiple scheduler-selected user messages. */\nexport const contextProjectionPromptWithUserContents = (\n state: PromptProjectionState,\n context: ContextProjection | undefined,\n contents: ReadonlyArray<UserMessageContent>,\n): Prompt.Prompt =>\n Prompt.fromMessages([\n ...contextProjectionPrompt(state, context).content,\n ...contents.map((content) => Prompt.makeMessage(\"user\", { content })),\n ]);\n\nconst compareBySeq = (left: DurableTranscriptMessage, right: DurableTranscriptMessage): number =>\n messageTranscriptSeq(left) - messageTranscriptSeq(right) || left.seq - right.seq;\n\nconst promptTranscriptItems = (\n state: PromptProjectionState,\n context: ContextProjection | undefined,\n): ReadonlyArray<PromptTranscriptItem> => {\n const messages = promptContextMessages(state, context);\n const assistantInfoByInference = new Map(\n messages.flatMap((message) =>\n message._tag === \"Assistant\" || message._tag === \"AssistantPartial\"\n ? [[message.inferenceId, assistantPromptInfo(message)] as const]\n : [],\n ),\n );\n const messageItems = messages.map((message) => ({\n _tag: \"Message\" as const,\n order: promptContextMessageSeq(message),\n message,\n }));\n const summaryItem =\n context?.currentSummary === undefined\n ? []\n : [\n {\n _tag: \"Summary\" as const,\n order: Number.MIN_SAFE_INTEGER,\n message: context.currentSummary.promptMessage,\n },\n ];\n const toolItems = Array.from(state.toolCalls?.values() ?? []).flatMap((tool) =>\n toolPromptItems(tool, assistantInfoByInference),\n );\n return [...messageItems, ...summaryItem, ...toolItems].sort(\n (left, right) => left.order - right.order,\n );\n};\n\nconst toolPromptItems = (\n tool: ToolCallRecord,\n assistantInfoByInference: ReadonlyMap<unknown, AssistantPromptInfo>,\n): ReadonlyArray<ToolResultPromptTranscriptItem> => {\n const { decision } = tool;\n if (decision === undefined) {\n return [];\n }\n const assistant = assistantInfoByInference.get(decision.inferenceId);\n if (assistant === undefined) {\n return [];\n }\n if (decision._tag === \"Rejected\") {\n return decision.promptPart === undefined\n ? []\n : [\n {\n _tag: \"ToolResult\",\n order: syntheticToolResultOrder(assistant, decision.providerPartId),\n part: decision.promptPart,\n },\n ];\n }\n const terminal = tool.terminal;\n if (terminal === undefined || terminal.promptPart === undefined) {\n return [];\n }\n return [\n {\n _tag: \"ToolResult\",\n order: syntheticToolResultOrder(assistant, decision.providerPartId),\n part: terminal.promptPart,\n },\n ];\n};\n\nconst assistantPromptInfo = (\n message: Extract<PromptContextMessage, { readonly _tag: \"Assistant\" | \"AssistantPartial\" }>,\n): AssistantPromptInfo => ({\n order: messageTranscriptSeq(message),\n toolCallOrderByProviderPartId: new Map(\n assistantToolCallParts(message).map(({ part, index }) => [part.id, index] as const),\n ),\n});\n\nconst assistantToolCallParts = (\n message: Extract<PromptContextMessage, { readonly _tag: \"Assistant\" | \"AssistantPartial\" }>,\n): ReadonlyArray<{ readonly part: Prompt.ToolCallPart; readonly index: number }> =>\n (message.promptParts ?? []).flatMap((part, index) =>\n part.type === \"tool-call\" ? [{ part, index }] : [],\n );\n\nconst syntheticToolResultOrder = (assistant: AssistantPromptInfo, providerPartId: string): number =>\n assistant.order +\n 0.1 +\n (assistant.toolCallOrderByProviderPartId.get(providerPartId) ?? 0) * 0.001;\n\nconst validateToolCallPairing = (messages: ReadonlyArray<Prompt.Message>): void => {\n const pending = new Set<string>();\n for (const message of messages) {\n if (pending.size > 0 && message.role !== \"tool\") {\n throw new Error(unpairedToolCallMessage(pending));\n }\n if (message.role === \"tool\") {\n for (const part of message.content) {\n if (part.type === \"tool-result\") {\n pending.delete(part.id);\n }\n }\n continue;\n }\n if (message.role === \"assistant\") {\n for (const part of message.content) {\n if (part.type === \"tool-call\" && !part.providerExecuted) {\n pending.add(part.id);\n }\n }\n }\n }\n if (pending.size > 0) {\n throw new Error(unpairedToolCallMessage(pending));\n }\n};\n\nconst unpairedToolCallMessage = (pending: ReadonlySet<string>): string =>\n `Prompt transcript contains assistant tool-call(s) without matching tool result(s): ${Array.from(\n pending,\n ).join(\", \")}`;\n\nconst promptContextMessages = (\n state: Pick<ReducedState, \"messages\">,\n context: ContextProjection | undefined,\n): ReadonlyArray<PromptContextMessage> => {\n const retainedFromContextSeq = context?.currentSummary?.retainedFromContextSeq ?? 0;\n const messages = durableMessageTranscript(state).filter(\n (message) =>\n isConsumedForPrompt(message) && messageTranscriptSeq(message) >= retainedFromContextSeq,\n );\n const system = Array.from(state.messages.values()).find(\n (message): message is SystemContextMessage => message._tag === \"System\",\n );\n return system === undefined ? messages : [system, ...messages];\n};\n\nconst isConsumedForPrompt = (message: DurableTranscriptMessage): boolean =>\n message._tag !== \"User\" ||\n message.requestedDisposition === undefined ||\n message.consumedSeq !== undefined;\n\nconst transcriptMessageToPromptMessage = (\n message: PromptContextMessage,\n): Prompt.SystemMessage | Prompt.UserMessage | Prompt.AssistantMessage => {\n switch (message._tag) {\n case \"System\":\n return Prompt.makeMessage(\"system\", { content: message.content });\n case \"User\":\n case \"Steering\":\n return Prompt.makeMessage(\"user\", { content: message.content });\n case \"Assistant\":\n case \"AssistantPartial\":\n return Prompt.makeMessage(\"assistant\", {\n content: message.promptParts ?? assistantParts(message.content),\n });\n }\n};\n\nconst messageTranscriptSeq = (message: DurableTranscriptMessage): number =>\n message._tag === \"User\" || message._tag === \"Steering\"\n ? (message.consumedSeq ?? message.seq)\n : message.seq;\n\nconst promptContextMessageSeq = (message: PromptContextMessage): number =>\n message._tag === \"System\" ? Number.NEGATIVE_INFINITY : messageTranscriptSeq(message);\n\nconst assistantParts = (\n content: Extract<\n DurableTranscriptMessage,\n { readonly _tag: \"Assistant\" | \"AssistantPartial\" }\n >[\"content\"],\n): ReadonlyArray<Prompt.AssistantMessagePart> => [\n ...(content.reasoning === undefined ? [] : [Prompt.reasoningPart({ text: content.reasoning })]),\n ...(content.text.length === 0 ? [] : [Prompt.textPart({ text: content.text })]),\n];\n"],"mappings":";;;AAgBA,MAAa,4BACX,UAEA,MAAM,KAAK,MAAM,SAAS,OAAO,CAAC,EAAE,OAAO,0BAA0B,EAAE,KAAK,YAAY;AAE1F,MAAM,8BAA8B,YACjC,QAAQ,SAAS,UAAU,QAAQ,iBAAiB,KAAA,KACrD,QAAQ,SAAS,eACjB,QAAQ,SAAS,sBAChB,QAAQ,SAAS,cAAc,QAAQ,gBAAgB,KAAA;;AAmC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