@effect-agent/platform-cloudflare 0.1.0-beta.38 → 0.1.0-beta.40

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.
Files changed (46) hide show
  1. package/dist/bindings-BrVEOkfe.d.mts +102 -0
  2. package/dist/browser-quick-action.d.mts +18 -1
  3. package/dist/browser-quick-action.mjs +14 -1
  4. package/dist/browser-quick-action.mjs.map +1 -1
  5. package/dist/browser-rest-capture.d.mts +17 -2
  6. package/dist/browser-rest-capture.mjs +12 -1
  7. package/dist/browser-rest-capture.mjs.map +1 -1
  8. package/dist/browser-rest-crawl.mjs +2 -2
  9. package/dist/browser-rest-crawl.mjs.map +1 -1
  10. package/dist/index.d.mts +245 -237
  11. package/dist/index.mjs +168 -164
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/interactive-browser.d.mts +160 -2
  14. package/dist/interactive-browser.mjs +1166 -2
  15. package/dist/interactive-browser.mjs.map +1 -0
  16. package/dist/{scheduling-B-OFqoS9.mjs → prepared-admission-BKp_Upw2.mjs} +134 -433
  17. package/dist/prepared-admission-BKp_Upw2.mjs.map +1 -0
  18. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  19. package/dist/scheduling.d.mts +47 -2
  20. package/dist/scheduling.mjs +339 -1
  21. package/dist/scheduling.mjs.map +1 -0
  22. package/dist/subscriptions.d.mts +52 -0
  23. package/dist/subscriptions.mjs +346 -0
  24. package/dist/subscriptions.mjs.map +1 -0
  25. package/package.json +20 -13
  26. package/src/alarm.ts +264 -265
  27. package/src/bindings.ts +34 -30
  28. package/src/browser-quick-action.ts +31 -0
  29. package/src/browser-rest-capture.ts +27 -0
  30. package/src/client.ts +111 -105
  31. package/src/code-mode-executor.ts +19 -0
  32. package/src/config.ts +7 -7
  33. package/src/index.ts +10 -11
  34. package/src/interactive-browser.ts +29 -1
  35. package/src/layers.ts +178 -257
  36. package/src/prepared-admission.ts +90 -0
  37. package/src/scheduling.ts +19 -55
  38. package/src/subscriptions.ts +661 -0
  39. package/src/{conversation-object.ts → thread-object.ts} +167 -136
  40. package/src/transport.ts +15 -15
  41. package/src/wake-scheduler.ts +17 -22
  42. package/dist/interactive-browser-BRo-Bfvb.d.mts +0 -144
  43. package/dist/interactive-browser-Cy5q-ldl.mjs +0 -1154
  44. package/dist/interactive-browser-Cy5q-ldl.mjs.map +0 -1
  45. package/dist/scheduling-B-OFqoS9.mjs.map +0 -1
  46. package/dist/scheduling-BJs_kHTx.d.mts +0 -142
package/src/bindings.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { ConversationId } from "@effect-agent/core";
2
- import type { ProducerId } from "@effect-agent/session";
1
+ import type { ThreadId } from "@effect-agent/core";
2
+ import type { ProducerId } from "@effect-agent/thread";
3
3
  import { Context, Effect, Layer, Predicate, Schema } from "effect";
4
4
 
5
5
  /**
6
6
  * Cloudflare platform bindings as Effect services (DEPLOY-010: "Cloudflare platform bindings
7
7
  * are supplied as Effect services/Layers"). Application code never reads `env` or touches a
8
- * `DurableObjectState` directly — the Conversation Object class constructs these Layers once
8
+ * `DurableObjectState` directly — the Thread Object class constructs these Layers once
9
9
  * per incarnation and everything downstream consumes the services.
10
10
  */
11
11
 
@@ -19,8 +19,8 @@ export class CloudflareBindingError extends Schema.TaggedError<CloudflareBinding
19
19
  ) {}
20
20
 
21
21
  /**
22
- * The RPC surface one Conversation Durable Object exposes to Workers and to sibling
23
- * Conversation Objects. `makeConversationObjectClass` implements it; the Worker-side client
22
+ * The RPC surface one Thread Durable Object exposes to Workers and to sibling
23
+ * Thread Objects. `ThreadObject.make` implements it; the Worker-side client
24
24
  * and the cross-Object transport call it through `DurableObjectNamespace` stubs. Every
25
25
  * `encoded` value is a Schema-encoded envelope (`client.ts` wire schemas for host entry
26
26
  * points, `@effect-agent/storage-cloudflare` port envelopes for `portCall`), so the RPC
@@ -28,7 +28,7 @@ export class CloudflareBindingError extends Schema.TaggedError<CloudflareBinding
28
28
  * transient native RPC metadata, stripped by an opted-in effect-cf receiver before decoding
29
29
  * the host envelope. It never enters durable state.
30
30
  */
31
- export interface ConversationObjectRpc extends Rpc.DurableObjectBranded {
31
+ export interface ThreadObjectRpc extends Rpc.DurableObjectBranded {
32
32
  /** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */
33
33
  submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
34
34
  /** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */
@@ -52,22 +52,26 @@ export interface ConversationObjectRpc extends Rpc.DurableObjectBranded {
52
52
  }
53
53
 
54
54
  /**
55
- * The `DurableObjectNamespace` binding that addresses Conversation Objects. The Object
56
- * identity rule is `namespace.idFromName(conversationId)` (plan §1.2): Conversation IDs are
55
+ * The `DurableObjectNamespace` binding that addresses Thread Objects. The Object
56
+ * identity rule is `namespace.idFromName(threadId)` (plan §1.2): Thread IDs are
57
57
  * globally unique, so the mapping is total and deterministic and no directory service exists.
58
58
  */
59
- export class ConversationObjectNamespace extends Context.Service<
60
- ConversationObjectNamespace,
59
+ export class ThreadObjectNamespace extends Context.Service<
60
+ ThreadObjectNamespace,
61
61
  {
62
- readonly namespace: DurableObjectNamespace<ConversationObjectRpc>;
62
+ readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;
63
63
  /** Stable binding name for opted-in native RPC tracing; absent by default. */
64
64
  readonly rpcTracing?: string;
65
65
  }
66
- >()("@effect-agent/platform-cloudflare/ConversationObjectNamespace") {
66
+ >()("@effect-agent/platform-cloudflare/ThreadObjectNamespace") {
67
67
  static layer(
68
- namespace: DurableObjectNamespace<ConversationObjectRpc>,
69
- ): Layer.Layer<ConversationObjectNamespace> {
70
- return Layer.succeed(ConversationObjectNamespace)({ namespace });
68
+ namespace: DurableObjectNamespace<ThreadObjectRpc>,
69
+ options: { readonly rpcTracing?: string } = {},
70
+ ): Layer.Layer<ThreadObjectNamespace> {
71
+ return Layer.succeed(ThreadObjectNamespace)({
72
+ namespace,
73
+ ...(options.rpcTracing === undefined ? {} : { rpcTracing: options.rpcTracing }),
74
+ });
71
75
  }
72
76
  }
73
77
 
@@ -77,10 +81,10 @@ export class ConversationObjectNamespace extends Context.Service<
77
81
  * narrowest-boundary check (structural probe for the namespace surface the transport uses);
78
82
  * a missing or misshaped binding fails typed before any Layer is built.
79
83
  */
80
- export const conversationNamespaceFromEnv = Effect.fn("conversationNamespaceFromEnv")(function* (
84
+ export const threadNamespaceFromEnv = Effect.fn("threadNamespaceFromEnv")(function* (
81
85
  env: unknown,
82
86
  binding: string,
83
- ): Effect.fn.Return<DurableObjectNamespace<ConversationObjectRpc>, CloudflareBindingError> {
87
+ ): Effect.fn.Return<DurableObjectNamespace<ThreadObjectRpc>, CloudflareBindingError> {
84
88
  if (!Predicate.isObjectKeyword(env)) {
85
89
  return yield* CloudflareBindingError.make({
86
90
  binding,
@@ -104,12 +108,12 @@ export const conversationNamespaceFromEnv = Effect.fn("conversationNamespaceFrom
104
108
  if (candidate !== undefined) {
105
109
  // The structural probe above is the entire runtime contract this package relies on;
106
110
  // the assertion records that `idFromName`/`get` name a DurableObjectNamespace.
107
- return candidate as unknown as DurableObjectNamespace<ConversationObjectRpc>;
111
+ return candidate as unknown as DurableObjectNamespace<ThreadObjectRpc>;
108
112
  }
109
113
  return yield* CloudflareBindingError.make({
110
114
  binding,
111
115
  message:
112
- `env.${binding} is not a DurableObjectNamespace binding; declare the Conversation ` +
116
+ `env.${binding} is not a DurableObjectNamespace binding; declare the Thread ` +
113
117
  "Object class under this binding in the Worker configuration.",
114
118
  });
115
119
  });
@@ -118,13 +122,13 @@ export const conversationNamespaceFromEnv = Effect.fn("conversationNamespaceFrom
118
122
  * Build the namespace from Worker `env` (fails typed). Enable `rpcTracing` only when the
119
123
  * receiver also opts into the effect-cf native RPC trace-context contract.
120
124
  */
121
- export const conversationNamespaceLayer = (
125
+ export const threadNamespaceLayer = (
122
126
  env: unknown,
123
127
  binding: string,
124
128
  options: { readonly rpcTracing?: boolean } = {},
125
- ): Layer.Layer<ConversationObjectNamespace, CloudflareBindingError> =>
126
- Layer.effect(ConversationObjectNamespace)(
127
- Effect.map(conversationNamespaceFromEnv(env, binding), (namespace) => ({
129
+ ): Layer.Layer<ThreadObjectNamespace, CloudflareBindingError> =>
130
+ Layer.effect(ThreadObjectNamespace)(
131
+ Effect.map(threadNamespaceFromEnv(env, binding), (namespace) => ({
128
132
  namespace,
129
133
  ...(options.rpcTracing === true ? { rpcTracing: binding } : {}),
130
134
  })),
@@ -148,14 +152,14 @@ export class DurableObjectContext extends Context.Service<
148
152
  }
149
153
 
150
154
  /**
151
- * The Conversation identity this Object serializes and the producer identity its Attempts
152
- * write with (`{producerPrefix}:{conversationId}`, plan §1.4). Derived once per incarnation
153
- * from `ctx.id.name` — the Object identity rule guarantees the name IS the Conversation ID.
155
+ * The Thread identity this Object serializes and the producer identity its Attempts
156
+ * write with (`{producerPrefix}:{threadId}`, plan §1.4). Derived once per incarnation
157
+ * from `ctx.id.name` — the Object identity rule guarantees the name IS the Thread ID.
154
158
  */
155
- export class ConversationObjectIdentity extends Context.Service<
156
- ConversationObjectIdentity,
159
+ export class ThreadObjectIdentity extends Context.Service<
160
+ ThreadObjectIdentity,
157
161
  {
158
- readonly conversationId: ConversationId;
162
+ readonly threadId: ThreadId;
159
163
  readonly producerId: ProducerId;
160
164
  }
161
- >()("@effect-agent/platform-cloudflare/ConversationObjectIdentity") {}
165
+ >()("@effect-agent/platform-cloudflare/ThreadObjectIdentity") {}
@@ -547,6 +547,37 @@ export const browserQuickActionWorkersAiCaptureLayer = (): Layer.Layer<
547
547
  }),
548
548
  );
549
549
 
550
+ /** Host-owned Quick Action binding and optional, separately billed extraction authority. */
551
+ export interface CloudflareBrowserOptions extends BrowserQuickActionCaptureOptions {
552
+ readonly workersAi?: BrowserQuickActionWorkersAiPolicy;
553
+ }
554
+
555
+ /** Compose WebCapture handlers with the Cloudflare Quick Action adapter. */
556
+ export const CloudflareBrowser = {
557
+ /**
558
+ * Supply a WebCapture definition and the resolved Worker browser binding.
559
+ * Supports capture, scrape, and extraction definitions without importing capabilities.
560
+ * Only PageCapture is provided; other handler requirements and errors stay visible.
561
+ * Extraction fails closed unless workersAi explicitly authorizes and accounts for it.
562
+ * Capture limits, typed failures, tracing, and scoped response cleanup are unchanged.
563
+ */
564
+ layer: <A, E, R>(
565
+ definition: { readonly handlers: Layer.Layer<A, E, R> },
566
+ options: CloudflareBrowserOptions,
567
+ ): Layer.Layer<A, E, Exclude<R, PageCapture>> => {
568
+ const capture =
569
+ options.workersAi === undefined
570
+ ? browserQuickActionCaptureLayer()
571
+ : browserQuickActionWorkersAiCaptureLayer().pipe(
572
+ Layer.provide(BrowserQuickActionWorkersAi.layer(options.workersAi)),
573
+ );
574
+
575
+ return definition.handlers.pipe(
576
+ Layer.provide(capture.pipe(Layer.provide(BrowserQuickActionBrowserBinding.layer(options)))),
577
+ );
578
+ },
579
+ };
580
+
550
581
  const screenshotOptions = (request: PageScreenshotRequest): BrowserRunScreenshotOptions => {
551
582
  const options: BrowserRunBaseOptions = {};
552
583
  if (
@@ -418,3 +418,30 @@ export const browserRestWorkersAiCaptureLayer = (
418
418
  return PageCapture.of({ capture: makeCapture(client, options, workersAi) });
419
419
  }),
420
420
  );
421
+
422
+ /** Explicit REST credentials and optional authorization for separately billed extraction. */
423
+ export interface CloudflareBrowserRestOptions extends BrowserRestCaptureOptions {
424
+ readonly workersAi?: BrowserQuickActionWorkersAiPolicy;
425
+ }
426
+
427
+ /** Node-safe WebCapture handler assembly; the application supplies its HttpClient. */
428
+ export const CloudflareBrowserRest = {
429
+ /**
430
+ * Supports capture, scrape, and extraction definitions. Only PageCapture is supplied;
431
+ * handler errors and other services remain visible. Extraction fails closed without
432
+ * workersAi. Existing host policies, response limits, and scoped cleanup are unchanged.
433
+ */
434
+ layer: <A, E, R>(
435
+ definition: { readonly handlers: Layer.Layer<A, E, R> },
436
+ options: CloudflareBrowserRestOptions,
437
+ ): Layer.Layer<A, E, Exclude<R, PageCapture> | HttpClient.HttpClient> => {
438
+ const capture =
439
+ options.workersAi === undefined
440
+ ? browserRestCaptureLayer(options)
441
+ : browserRestWorkersAiCaptureLayer(options).pipe(
442
+ Layer.provide(BrowserQuickActionWorkersAi.layer(options.workersAi)),
443
+ );
444
+
445
+ return definition.handlers.pipe(Layer.provide(capture));
446
+ },
447
+ };