@effect-agent/platform-cloudflare 0.1.0-beta.17 → 0.1.0-beta.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-agent/platform-cloudflare",
3
- "version": "0.1.0-beta.17",
3
+ "version": "0.1.0-beta.19",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./dist/index.d.mts",
@@ -8,10 +8,11 @@
8
8
  }
9
9
  },
10
10
  "dependencies": {
11
- "@effect-agent/core": "0.1.0-beta.17",
12
- "@effect-agent/sandbox": "0.1.0-beta.17",
13
- "@effect-agent/session": "0.1.0-beta.17",
14
- "@effect-agent/storage-cloudflare": "0.1.0-beta.17",
11
+ "@effect-agent/core": "0.1.0-beta.19",
12
+ "@effect-agent/engine": "0.1.0-beta.19",
13
+ "@effect-agent/sandbox": "0.1.0-beta.19",
14
+ "@effect-agent/session": "0.1.0-beta.19",
15
+ "@effect-agent/storage-cloudflare": "0.1.0-beta.19",
15
16
  "@effect/platform-browser": "4.0.0-beta.107",
16
17
  "@effect/sql-sqlite-do": "4.0.0-beta.107",
17
18
  "effect": "4.0.0-beta.107"
@@ -43,7 +44,6 @@
43
44
  "@cloudflare/vitest-pool-workers": "0.21.3",
44
45
  "@cloudflare/workers-types": "5.20260813.1",
45
46
  "@effect-agent/capabilities": "0.1.0-beta.14",
46
- "@effect-agent/engine": "0.1.0-beta.14",
47
47
  "@effect-agent/testing": "0.1.0-beta.14",
48
48
  "@effect/vitest": "4.0.0-beta.107",
49
49
  "effect-cf": "0.27.0",
package/src/layers.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ConversationId } from "@effect-agent/core";
2
+ import { RunContextPreparation, RunContextPreparationPassthrough } from "@effect-agent/engine";
2
3
  import {
3
4
  AgentBindingResolver,
4
5
  DurableAgentRuntime,
@@ -28,7 +29,7 @@ import {
28
29
  } from "@effect-agent/storage-cloudflare";
29
30
  import { BrowserCrypto } from "@effect/platform-browser";
30
31
  import { SqliteClient } from "@effect/sql-sqlite-do";
31
- import { Context, Duration, Effect, Layer, Schema } from "effect";
32
+ import { Context, Crypto, Duration, Effect, Layer, Schema } from "effect";
32
33
 
33
34
  import {
34
35
  ConversationMaintenance,
@@ -117,16 +118,25 @@ export interface CloudflareDurableRuntimeOptions {
117
118
  * to the empty registration (every resolved claim fails closed).
118
119
  */
119
120
  readonly bindings?: CloudflareBindingSource | undefined;
121
+ /**
122
+ * Generic model-context preparation acquired with this Durable Object incarnation. The Layer
123
+ * may depend only on `Crypto.Crypto`, which this platform supplies with `BrowserCrypto`; hosts
124
+ * must close every application-specific service before passing it here. Default absent.
125
+ */
126
+ readonly runContext?: CloudflareRunContextSource | undefined;
120
127
  }
121
128
 
122
- /** Per-incarnation host values available while registered worker Bindings are captured. */
123
- export interface CloudflareBindingSourceContext {
129
+ /** Per-incarnation host values available to Effect-native runtime extension factories. */
130
+ export interface CloudflareRuntimeSourceContext {
124
131
  readonly ctx: DurableObjectState;
125
132
  readonly env: unknown;
126
133
  readonly conversationId: ConversationId;
127
134
  readonly producerId: ProducerId;
128
135
  }
129
136
 
137
+ /** Per-incarnation host values available while registered worker Bindings are captured. */
138
+ export interface CloudflareBindingSourceContext extends CloudflareRuntimeSourceContext {}
139
+
130
140
  /**
131
141
  * Registered worker Bindings, or a closed Effect/callback that captures them once for each
132
142
  * Durable Object incarnation. Callback Effects cannot require services or fail typed.
@@ -140,6 +150,14 @@ export type CloudflareBindingSource =
140
150
  | ReadonlyArray<ResolvedBinding>
141
151
  | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>);
142
152
 
153
+ /** A closed context-preparation service whose only remaining requirement is platform Crypto. */
154
+ export type CloudflareRunContextLayer = Layer.Layer<RunContextPreparation, never, Crypto.Crypto>;
155
+
156
+ /** One Layer or a per-incarnation factory over explicit Cloudflare host values. */
157
+ export type CloudflareRunContextSource =
158
+ | CloudflareRunContextLayer
159
+ | ((context: CloudflareRuntimeSourceContext) => CloudflareRunContextLayer);
160
+
143
161
  /** Every construction failure of the assembled Cloudflare durable runtime stack. */
144
162
  export type CloudflareDurableRuntimeInitializationError =
145
163
  | CloudflarePlatformConfigError
@@ -256,6 +274,11 @@ const resolveBindings = (
256
274
  })
257
275
  : Effect.succeed(source);
258
276
 
277
+ const resolveRunContext = (
278
+ source: CloudflareRunContextSource,
279
+ context: CloudflareRuntimeSourceContext,
280
+ ): CloudflareRunContextLayer => (typeof source === "function" ? source(context) : source);
281
+
259
282
  /**
260
283
  * The DC Layer assembly (deployment §12: a Layer-assembly library, not an app entrypoint;
261
284
  * plan §1.4). `layer(options)` decodes the configuration, derives this Object's Conversation
@@ -372,6 +395,12 @@ export class CloudflareDurableRuntime {
372
395
  (bindings) => AgentBindingResolver.fromBindings(bindings),
373
396
  ),
374
397
  );
398
+ const runContextLayer =
399
+ options.runContext === undefined
400
+ ? RunContextPreparationPassthrough
401
+ : resolveRunContext(options.runContext, { ctx, env, conversationId, producerId }).pipe(
402
+ Layer.provide(BrowserCrypto.layer),
403
+ );
375
404
 
376
405
  const base = Layer.mergeAll(
377
406
  identityLayer,
@@ -381,7 +410,7 @@ export class CloudflareDurableRuntime {
381
410
  ProgressWaitRegistry.layer,
382
411
  );
383
412
 
384
- const runtimeStack = DurableAgentRuntime.layer.pipe(
413
+ const runtimeStack = DurableAgentRuntime.layerWithContext.pipe(
385
414
  Layer.provideMerge(routedPorts),
386
415
  Layer.provideMerge(cloudflareWakeSchedulerLayer),
387
416
  Layer.provideMerge(runtimeConfigLayer),
@@ -391,6 +420,7 @@ export class CloudflareDurableRuntime {
391
420
  runtimeFailpointLayer,
392
421
  reconcilerLayer,
393
422
  authorizerLayer,
423
+ runContextLayer,
394
424
  BrowserCrypto.layer,
395
425
  ),
396
426
  ),