@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.
- package/dist/bindings-BrVEOkfe.d.mts +102 -0
- package/dist/browser-quick-action.d.mts +18 -1
- package/dist/browser-quick-action.mjs +14 -1
- package/dist/browser-quick-action.mjs.map +1 -1
- package/dist/browser-rest-capture.d.mts +17 -2
- package/dist/browser-rest-capture.mjs +12 -1
- package/dist/browser-rest-capture.mjs.map +1 -1
- package/dist/browser-rest-crawl.mjs +2 -2
- package/dist/browser-rest-crawl.mjs.map +1 -1
- package/dist/index.d.mts +245 -237
- package/dist/index.mjs +168 -164
- package/dist/index.mjs.map +1 -1
- package/dist/interactive-browser.d.mts +160 -2
- package/dist/interactive-browser.mjs +1166 -2
- package/dist/interactive-browser.mjs.map +1 -0
- package/dist/{scheduling-B-OFqoS9.mjs → prepared-admission-BKp_Upw2.mjs} +134 -433
- package/dist/prepared-admission-BKp_Upw2.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/scheduling.d.mts +47 -2
- package/dist/scheduling.mjs +339 -1
- package/dist/scheduling.mjs.map +1 -0
- package/dist/subscriptions.d.mts +52 -0
- package/dist/subscriptions.mjs +346 -0
- package/dist/subscriptions.mjs.map +1 -0
- package/package.json +20 -13
- package/src/alarm.ts +264 -265
- package/src/bindings.ts +34 -30
- package/src/browser-quick-action.ts +31 -0
- package/src/browser-rest-capture.ts +27 -0
- package/src/client.ts +111 -105
- package/src/code-mode-executor.ts +19 -0
- package/src/config.ts +7 -7
- package/src/index.ts +10 -11
- package/src/interactive-browser.ts +29 -1
- package/src/layers.ts +178 -257
- package/src/prepared-admission.ts +90 -0
- package/src/scheduling.ts +19 -55
- package/src/subscriptions.ts +661 -0
- package/src/{conversation-object.ts → thread-object.ts} +167 -136
- package/src/transport.ts +15 -15
- package/src/wake-scheduler.ts +17 -22
- package/dist/interactive-browser-BRo-Bfvb.d.mts +0 -144
- package/dist/interactive-browser-Cy5q-ldl.mjs +0 -1154
- package/dist/interactive-browser-Cy5q-ldl.mjs.map +0 -1
- package/dist/scheduling-B-OFqoS9.mjs.map +0 -1
- package/dist/scheduling-BJs_kHTx.d.mts +0 -142
package/src/bindings.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ProducerId } from "@effect-agent/
|
|
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
|
|
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
|
|
23
|
-
*
|
|
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
|
|
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
|
|
56
|
-
* identity rule is `namespace.idFromName(
|
|
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
|
|
60
|
-
|
|
59
|
+
export class ThreadObjectNamespace extends Context.Service<
|
|
60
|
+
ThreadObjectNamespace,
|
|
61
61
|
{
|
|
62
|
-
readonly namespace: DurableObjectNamespace<
|
|
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/
|
|
66
|
+
>()("@effect-agent/platform-cloudflare/ThreadObjectNamespace") {
|
|
67
67
|
static layer(
|
|
68
|
-
namespace: DurableObjectNamespace<
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
84
|
+
export const threadNamespaceFromEnv = Effect.fn("threadNamespaceFromEnv")(function* (
|
|
81
85
|
env: unknown,
|
|
82
86
|
binding: string,
|
|
83
|
-
): Effect.fn.Return<DurableObjectNamespace<
|
|
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<
|
|
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
|
|
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
|
|
125
|
+
export const threadNamespaceLayer = (
|
|
122
126
|
env: unknown,
|
|
123
127
|
binding: string,
|
|
124
128
|
options: { readonly rpcTracing?: boolean } = {},
|
|
125
|
-
): Layer.Layer<
|
|
126
|
-
Layer.effect(
|
|
127
|
-
Effect.map(
|
|
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
|
|
152
|
-
* write with (`{producerPrefix}:{
|
|
153
|
-
* from `ctx.id.name` — the Object identity rule guarantees the name IS the
|
|
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
|
|
156
|
-
|
|
159
|
+
export class ThreadObjectIdentity extends Context.Service<
|
|
160
|
+
ThreadObjectIdentity,
|
|
157
161
|
{
|
|
158
|
-
readonly
|
|
162
|
+
readonly threadId: ThreadId;
|
|
159
163
|
readonly producerId: ProducerId;
|
|
160
164
|
}
|
|
161
|
-
>()("@effect-agent/platform-cloudflare/
|
|
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
|
+
};
|