effect-durable-agent-cloudflare 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +18 -4
- package/dist/durable-object.d.ts +2 -3
- package/dist/durable-object.js +179 -1
- package/dist/durable-object.js.map +1 -0
- package/dist/index.d.ts +4 -10
- package/dist/index.js +6 -25
- package/dist/openai.d.ts +18 -0
- package/dist/openai.js +59 -0
- package/dist/openai.js.map +1 -0
- package/dist/rpc.d.ts +16 -0
- package/dist/rpc.js +26 -0
- package/dist/rpc.js.map +1 -0
- package/dist/{durable-object-runtime-Dehm7PsO.d.ts → session-controller-BSMHhS_l.d.ts} +74 -108
- package/dist/{durable-object-runtime-LgOJbsVm.js → session-controller-Bo7DyydT.js} +495 -423
- package/dist/session-controller-Bo7DyydT.js.map +1 -0
- package/dist/session-controller.d.ts +2 -0
- package/dist/session-controller.js +2 -0
- package/package.json +20 -15
- package/dist/chunk-BBjsoOtd.js +0 -27
- package/dist/durable-object-CjWWNyek.js +0 -194
- package/dist/durable-object-CjWWNyek.js.map +0 -1
- package/dist/durable-object-runtime-LgOJbsVm.js.map +0 -1
- package/dist/durable-object-runtime.d.ts +0 -2
- package/dist/durable-object-runtime.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/websocket-protocol.d.ts +0 -1
- package/dist/websocket-protocol.js +0 -10
- package/dist/websocket-protocol.js.map +0 -1
- /package/dist/{durable-object-storage.d.ts → storage.d.ts} +0 -0
- /package/dist/{durable-object-storage.js → storage.js} +0 -0
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { t as DurableObjectSessionStorage } from "./durable-object-storage-DCL2IyUe.js";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Schema from "effect/Schema";
|
|
4
3
|
import { EDACommand } from "effect-durable-agent/types/commands";
|
|
5
4
|
import { CommandId, SequenceNumber, SessionId } from "effect-durable-agent/types/core";
|
|
6
5
|
import { EDATraceMetadata } from "effect-durable-agent/types/tracing";
|
|
7
|
-
import { OpenAiLanguageModel } from "@effect/ai-openai";
|
|
8
6
|
import * as Layer from "effect/Layer";
|
|
9
|
-
import
|
|
7
|
+
import { CommittedCommandTerminalEvent, EDARuntime, EDARuntimeConfig } from "effect-durable-agent/services/runtime";
|
|
8
|
+
import { CommittedDurableEvent } from "effect-durable-agent/services/session-store";
|
|
10
9
|
import { CompactionExecutor, CompactionPolicy } from "effect-durable-agent/services/compaction";
|
|
11
10
|
import { EDAPromptProjector } from "effect-durable-agent/services/prompt-projector";
|
|
12
11
|
import { EDAReducer } from "effect-durable-agent/services/reducer-registry";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import * as LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
12
|
+
import { SessionEventObserver } from "effect-durable-agent/services/session-event-observer";
|
|
13
|
+
import { EDAWebSocketServerFrameEncoder } from "effect-durable-agent/websocket";
|
|
16
14
|
import { DurableTranscriptMessage } from "effect-durable-agent/domain/message-transcript";
|
|
17
15
|
import { EDASessionSnapshot } from "effect-durable-agent/services/session-query";
|
|
18
16
|
import { EDASubmittable, SessionCommandAdmissionError } from "effect-durable-agent/services/session-state";
|
|
17
|
+
import * as LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
18
|
+
import * as Tracer from "effect/Tracer";
|
|
19
19
|
import { EDASink } from "effect-durable-agent/services/sink-registry";
|
|
20
20
|
import { EDAModelToolkit, EDAToolRegistryShape } from "effect-durable-agent/services/tool-registry";
|
|
21
21
|
import * as Fiber from "effect/Fiber";
|
|
22
|
-
import { EDAWebSocketServerFrameEncoder } from "effect-durable-agent/host/websocket-wire";
|
|
23
22
|
|
|
24
23
|
//#region src/durable-object-keepalive.d.ts
|
|
25
24
|
/** Minimal Durable Object storage alarm surface needed by the EDA host keepalive. */
|
|
@@ -28,7 +27,11 @@ interface DurableObjectAlarmStorage {
|
|
|
28
27
|
readonly setAlarm: (scheduledTimeMs: number) => void | Promise<void>;
|
|
29
28
|
readonly deleteAlarm: () => void | Promise<void>;
|
|
30
29
|
}
|
|
31
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Optional host hook for background alarm writes started from synchronous observers.
|
|
32
|
+
* Durable Objects already track their own async work; this hook does not keep an
|
|
33
|
+
* accepted WebSocket active or prevent WebSocket hibernation.
|
|
34
|
+
*/
|
|
32
35
|
interface DurableObjectBackgroundWaiter {
|
|
33
36
|
readonly waitUntil: (promise: Promise<unknown>) => void;
|
|
34
37
|
}
|
|
@@ -96,10 +99,10 @@ declare class DurableObjectKeepAlive {
|
|
|
96
99
|
private syncAlarm;
|
|
97
100
|
}
|
|
98
101
|
//#endregion
|
|
99
|
-
//#region src/
|
|
100
|
-
/**
|
|
102
|
+
//#region src/runtime/runtime-layer.d.ts
|
|
103
|
+
/** Storage capabilities used by one EDA session Durable Object. */
|
|
101
104
|
type EDASessionDurableObjectStorage = DurableObjectSessionStorage & DurableObjectAlarmStorage;
|
|
102
|
-
/**
|
|
105
|
+
/** Host adapters and application policy needed to build one session runtime. */
|
|
103
106
|
interface EDADurableObjectRuntimeLayerOptions {
|
|
104
107
|
readonly config: EDARuntimeConfig;
|
|
105
108
|
readonly compactionExecutorLayer?: Layer.Layer<CompactionExecutor, never, LanguageModel.LanguageModel>;
|
|
@@ -107,7 +110,8 @@ interface EDADurableObjectRuntimeLayerOptions {
|
|
|
107
110
|
readonly keepAlive?: DurableObjectKeepAlive;
|
|
108
111
|
readonly modelLayer: Layer.Layer<LanguageModel.LanguageModel>;
|
|
109
112
|
readonly promptProjectorLayer?: Layer.Layer<EDAPromptProjector>;
|
|
110
|
-
readonly reducers?: ReadonlyArray<EDAReducer
|
|
113
|
+
readonly reducers?: ReadonlyArray<EDAReducer>;
|
|
114
|
+
readonly sessionEventObserverLayer?: Layer.Layer<SessionEventObserver>;
|
|
111
115
|
readonly sessionId: SessionId;
|
|
112
116
|
readonly sinks?: ReadonlyArray<EDASink>;
|
|
113
117
|
readonly storage: EDASessionDurableObjectStorage;
|
|
@@ -115,8 +119,36 @@ interface EDADurableObjectRuntimeLayerOptions {
|
|
|
115
119
|
readonly toolRegistry?: EDAToolRegistryShape;
|
|
116
120
|
readonly tracer?: Tracer.Tracer;
|
|
117
121
|
}
|
|
118
|
-
/**
|
|
119
|
-
|
|
122
|
+
/** Compose the platform-neutral runtime with Cloudflare persistence and lifecycle adapters. */
|
|
123
|
+
declare const makeEDADurableObjectRuntimeLayer: ({
|
|
124
|
+
config,
|
|
125
|
+
compactionExecutorLayer,
|
|
126
|
+
compactionPolicyLayer,
|
|
127
|
+
keepAlive,
|
|
128
|
+
modelLayer,
|
|
129
|
+
promptProjectorLayer,
|
|
130
|
+
reducers,
|
|
131
|
+
sessionEventObserverLayer,
|
|
132
|
+
sessionId,
|
|
133
|
+
sinks,
|
|
134
|
+
storage,
|
|
135
|
+
toolkit,
|
|
136
|
+
toolRegistry,
|
|
137
|
+
tracer
|
|
138
|
+
}: EDADurableObjectRuntimeLayerOptions) => Layer.Layer<EDARuntime, SessionCommandAdmissionError>;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/runtime/session-runtime.d.ts
|
|
141
|
+
type EDAToolkitFactory = (input: {
|
|
142
|
+
readonly sessionId: SessionId;
|
|
143
|
+
}) => EDAModelToolkit;
|
|
144
|
+
type EDAToolRegistryFactory = (input: {
|
|
145
|
+
readonly sessionId: SessionId;
|
|
146
|
+
}) => EDAToolRegistryShape;
|
|
147
|
+
type EDATracerFactory = (input: {
|
|
148
|
+
readonly sessionId: SessionId;
|
|
149
|
+
}) => Tracer.Tracer;
|
|
150
|
+
/** Configuration owned by the lazy per-isolate Effect runtime. */
|
|
151
|
+
interface EDASessionRuntimeOptions {
|
|
120
152
|
readonly background?: DurableObjectBackgroundWaiter;
|
|
121
153
|
readonly config: EDARuntimeConfig;
|
|
122
154
|
readonly compactionExecutorLayer?: Layer.Layer<CompactionExecutor, never, LanguageModel.LanguageModel>;
|
|
@@ -124,142 +156,76 @@ interface EDASessionDurableObjectHostOptions {
|
|
|
124
156
|
readonly keepAlive?: DurableObjectKeepAlive;
|
|
125
157
|
readonly modelLayer: Layer.Layer<LanguageModel.LanguageModel>;
|
|
126
158
|
readonly promptProjectorLayer?: Layer.Layer<EDAPromptProjector>;
|
|
127
|
-
readonly reducers?: ReadonlyArray<EDAReducer
|
|
159
|
+
readonly reducers?: ReadonlyArray<EDAReducer>;
|
|
160
|
+
readonly sessionEventObserverLayer: Layer.Layer<SessionEventObserver>;
|
|
128
161
|
readonly sinks?: ReadonlyArray<EDASink>;
|
|
129
162
|
readonly storage: EDASessionDurableObjectStorage;
|
|
130
163
|
readonly toolkit?: EDAModelToolkit | EDAToolkitFactory;
|
|
131
164
|
readonly toolRegistry?: EDAToolRegistryShape | EDAToolRegistryFactory;
|
|
132
165
|
readonly tracer?: Tracer.Tracer | EDATracerFactory;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/session-controller.d.ts
|
|
169
|
+
/** Composition options for the session use cases and Cloudflare adapters. */
|
|
170
|
+
interface EDASessionControllerOptions extends Omit<EDASessionRuntimeOptions, "sessionEventObserverLayer"> {
|
|
171
|
+
readonly getWebSockets?: () => ReadonlyArray<WebSocket>;
|
|
133
172
|
readonly webSocketProtocol?: EDAWebSocketServerFrameEncoder;
|
|
134
173
|
}
|
|
135
|
-
/** Per-session factory for provider-visible model toolkit definitions. */
|
|
136
|
-
type EDAToolkitFactory = (input: {
|
|
137
|
-
readonly sessionId: SessionId;
|
|
138
|
-
}) => EDAModelToolkit;
|
|
139
|
-
/** Per-session factory for custom tool registry implementations. */
|
|
140
|
-
type EDAToolRegistryFactory = (input: {
|
|
141
|
-
readonly sessionId: SessionId;
|
|
142
|
-
}) => EDAToolRegistryShape;
|
|
143
|
-
type EDATracerFactory = (input: {
|
|
144
|
-
readonly sessionId: SessionId;
|
|
145
|
-
}) => Tracer.Tracer;
|
|
146
|
-
/** Typed host input for admitting one command through RPC or route code. */
|
|
147
174
|
interface EDASessionSubmitInput {
|
|
148
175
|
readonly command: EDACommand;
|
|
149
176
|
readonly sessionId: SessionId;
|
|
150
|
-
readonly trace
|
|
177
|
+
readonly trace?: EDATraceMetadata;
|
|
151
178
|
}
|
|
152
|
-
/** Typed host input for admitting commands and app events as one durable batch. */
|
|
153
179
|
interface EDASessionSubmitBatchInput {
|
|
154
180
|
readonly items: ReadonlyArray<EDASubmittable>;
|
|
155
181
|
readonly sessionId: SessionId;
|
|
156
|
-
readonly trace
|
|
182
|
+
readonly trace?: EDATraceMetadata;
|
|
157
183
|
}
|
|
158
|
-
/** Typed host input for waiting on a command terminal boundary. */
|
|
159
184
|
interface EDASessionBlockOnCommandInput {
|
|
160
185
|
readonly afterSeq?: SequenceNumber;
|
|
161
186
|
readonly commandId: CommandId;
|
|
162
187
|
readonly sessionId: SessionId;
|
|
163
|
-
readonly trace
|
|
188
|
+
readonly trace?: EDATraceMetadata;
|
|
164
189
|
}
|
|
165
|
-
/** Typed host input for operations scoped only by session identity. */
|
|
166
190
|
interface EDASessionScopedInput {
|
|
167
191
|
readonly sessionId: SessionId;
|
|
168
|
-
readonly trace
|
|
192
|
+
readonly trace?: EDATraceMetadata;
|
|
169
193
|
}
|
|
170
|
-
/** Typed host input for opening a live event stream from a durable cursor. */
|
|
171
194
|
interface EDASessionEventsInput {
|
|
172
195
|
readonly afterSeq?: SequenceNumber;
|
|
173
196
|
readonly sessionId: SessionId;
|
|
174
|
-
readonly trace
|
|
197
|
+
readonly trace?: EDATraceMetadata;
|
|
175
198
|
}
|
|
176
199
|
/**
|
|
177
|
-
*
|
|
200
|
+
* Public application-facing use cases for one EDA session.
|
|
178
201
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
202
|
+
* Runtime lifecycle belongs to EDASessionRuntime; WebSocket transport belongs
|
|
203
|
+
* to EDAWebSocketConnectionManager. This class only coordinates them.
|
|
181
204
|
*/
|
|
182
|
-
declare
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
modelLayer,
|
|
188
|
-
promptProjectorLayer,
|
|
189
|
-
reducers,
|
|
190
|
-
sessionId,
|
|
191
|
-
sinks,
|
|
192
|
-
storage,
|
|
193
|
-
toolkit,
|
|
194
|
-
toolRegistry,
|
|
195
|
-
tracer
|
|
196
|
-
}: EDADurableObjectRuntimeLayerOptions) => Layer.Layer<EDARuntime, SessionCommandAdmissionError>;
|
|
197
|
-
/** Provider request defaults accepted by EDA's OpenAI Responses model adapter. */
|
|
198
|
-
type EDAOpenAiModelConfig = Omit<typeof OpenAiLanguageModel.Config.Service, "model">;
|
|
199
|
-
/** OpenAI-backed Effect AI model layer for the default Worker host. */
|
|
200
|
-
declare const makeEDADurableObjectOpenAiModelLayer: (options: {
|
|
201
|
-
readonly aiGateway?: AiGateway;
|
|
202
|
-
readonly apiKey?: string;
|
|
203
|
-
readonly apiUrl?: string;
|
|
204
|
-
readonly config?: EDAOpenAiModelConfig;
|
|
205
|
-
readonly modelId: string;
|
|
206
|
-
}) => Layer.Layer<LanguageModel.LanguageModel>;
|
|
207
|
-
/** Raw Durable Object host controller for one EDA session object. */
|
|
208
|
-
declare class EDASessionDurableObjectHost {
|
|
209
|
-
private readonly options;
|
|
210
|
-
private readonly keepAlive;
|
|
211
|
-
private readonly eventSockets;
|
|
212
|
-
private runtimeState;
|
|
213
|
-
private runtimePromise;
|
|
214
|
-
constructor(options: EDASessionDurableObjectHostOptions);
|
|
215
|
-
/** Run idempotent host and event-store migrations. Safe from `blockConcurrencyWhile`. */
|
|
216
|
-
static readonly migrate: (storage: EDASessionDurableObjectStorage) => Effect.Effect<void, EDASessionStoreError>;
|
|
217
|
-
/** Admit one command durably. Active runtime work holds EDA keep-alive leases internally. */
|
|
205
|
+
declare class EDASessionController {
|
|
206
|
+
private readonly runtime;
|
|
207
|
+
private readonly webSockets;
|
|
208
|
+
constructor(options: EDASessionControllerOptions);
|
|
209
|
+
static readonly migrate: (storage: EDASessionDurableObjectStorage) => Effect.Effect<void, import("effect-durable-agent/services/session-store").EDASessionStoreError>;
|
|
218
210
|
submit(input: EDASessionSubmitInput): Promise<CommittedDurableEvent>;
|
|
219
|
-
/** Submit an ordered durable batch of commands and app events. */
|
|
220
211
|
submitBatch(input: EDASessionSubmitBatchInput): Promise<ReadonlyArray<CommittedDurableEvent>>;
|
|
221
|
-
/** Admit one command and wait for its terminal command boundary. */
|
|
222
212
|
submitAndBlock(input: EDASessionSubmitInput): Promise<CommittedCommandTerminalEvent>;
|
|
223
|
-
/** Wait for an existing command to reach its terminal command boundary. */
|
|
224
213
|
blockOnCommand(input: EDASessionBlockOnCommandInput): Promise<CommittedCommandTerminalEvent>;
|
|
225
|
-
/** Read the authoritative live session snapshot. */
|
|
226
214
|
snapshot(input: EDASessionScopedInput): Promise<EDASessionSnapshot>;
|
|
227
|
-
/** Read durable transcript messages in committed order. */
|
|
228
215
|
messages(input: EDASessionScopedInput): Promise<ReadonlyArray<DurableTranscriptMessage>>;
|
|
229
|
-
/** Accept one WebSocket as the live event stream for this session. */
|
|
230
216
|
acceptEventWebSocket(input: EDASessionEventsInput & {
|
|
231
217
|
readonly webSocket: WebSocket;
|
|
232
218
|
}): Promise<void>;
|
|
233
|
-
/** Restore hibernated event WebSockets whose in-memory subscriber fibers disappeared. */
|
|
234
|
-
restoreEventWebSockets(webSockets: ReadonlyArray<WebSocket>): Promise<void>;
|
|
235
|
-
/** Route one inbound WebSocket message into the subscriber ACK queue. */
|
|
236
219
|
webSocketMessage(webSocket: WebSocket, message: string | ArrayBuffer): Promise<void>;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
/** Interrupt subscriber work after a host WebSocket error. */
|
|
240
|
-
webSocketError(webSocket: WebSocket): Promise<void>;
|
|
241
|
-
/** Dispose any live runtime before the host deletes its Durable Object storage. */
|
|
220
|
+
webSocketClose(webSocket: WebSocket): void;
|
|
221
|
+
webSocketError(webSocket: WebSocket): void;
|
|
242
222
|
destroy(_input: EDASessionScopedInput): Promise<void>;
|
|
243
|
-
/** Durable Object alarm hook: wake/recover the runtime and re-arm while EDA has active work. */
|
|
244
223
|
alarm(input?: EDASessionScopedInput): Promise<void>;
|
|
245
|
-
/** Dispose the Effect runtime if the host wrapper is torn down by tests. */
|
|
246
224
|
dispose(): Promise<void>;
|
|
247
|
-
private
|
|
248
|
-
private
|
|
249
|
-
private
|
|
250
|
-
private getRuntime;
|
|
251
|
-
private buildRuntime;
|
|
225
|
+
private query;
|
|
226
|
+
private prepareSession;
|
|
227
|
+
private run;
|
|
252
228
|
}
|
|
253
|
-
/** Decode a raw RPC command payload at the Durable Object boundary. */
|
|
254
|
-
declare const encodeEdaRpcCommand: (input: EDACommand) => unknown;
|
|
255
|
-
/** Encode a command/app-event batch into structured-clone-safe RPC values. */
|
|
256
|
-
declare const encodeEdaRpcSubmittables: (input: ReadonlyArray<EDASubmittable>) => ReadonlyArray<unknown>;
|
|
257
|
-
/** Decode a raw RPC command payload at the Durable Object boundary. */
|
|
258
|
-
declare const decodeEdaRpcCommand: (input: unknown) => Effect.Effect<EDACommand, Schema.SchemaError>;
|
|
259
|
-
/** Decode a raw RPC batch item at the Durable Object boundary. */
|
|
260
|
-
declare const decodeEdaRpcSubmittable: (input: unknown) => Effect.Effect<EDASubmittable, Schema.SchemaError>;
|
|
261
|
-
/** Decode raw RPC batch items at the Durable Object boundary. */
|
|
262
|
-
declare const decodeEdaRpcSubmittables: (input: ReadonlyArray<unknown>) => Effect.Effect<ReadonlyArray<EDASubmittable>, Schema.SchemaError>;
|
|
263
229
|
//#endregion
|
|
264
|
-
export {
|
|
265
|
-
//# sourceMappingURL=
|
|
230
|
+
export { EDASessionScopedInput as a, EDADurableObjectRuntimeLayerOptions as c, EDASessionEventsInput as i, EDASessionDurableObjectStorage as l, EDASessionController as n, EDASessionSubmitBatchInput as o, EDASessionControllerOptions as r, EDASessionSubmitInput as s, EDASessionBlockOnCommandInput as t, makeEDADurableObjectRuntimeLayer as u };
|
|
231
|
+
//# sourceMappingURL=session-controller-BSMHhS_l.d.ts.map
|