@effect-agent/platform-cloudflare 0.1.0-beta.8 → 0.1.0-beta.81
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/Alarm.d.mts +184 -0
- package/dist/Alarm.mjs +451 -0
- package/dist/Alarm.mjs.map +1 -0
- package/dist/BrowserRestCapture.d.mts +35 -0
- package/dist/BrowserRestCapture.mjs +238 -0
- package/dist/BrowserRestCapture.mjs.map +1 -0
- package/dist/BrowserRestCrawl.d.mts +17 -0
- package/dist/BrowserRestCrawl.mjs +244 -0
- package/dist/BrowserRestCrawl.mjs.map +1 -0
- package/dist/CloudflareAiGateway.d.mts +64 -0
- package/dist/CloudflareAiGateway.mjs +70 -0
- package/dist/CloudflareAiGateway.mjs.map +1 -0
- package/dist/CloudflareBindings.d.mts +112 -0
- package/dist/CloudflareBindings.mjs +101 -0
- package/dist/CloudflareBindings.mjs.map +1 -0
- package/dist/CloudflareBrowser-D4YqaTAl.mjs +495 -0
- package/dist/CloudflareBrowser-D4YqaTAl.mjs.map +1 -0
- package/dist/CloudflareBrowser-DJq53niJ.d.mts +80 -0
- package/dist/CloudflareBrowser.d.mts +2 -0
- package/dist/CloudflareBrowser.mjs +2 -0
- package/dist/CloudflareCodeMode.d.mts +44 -0
- package/dist/CloudflareCodeMode.mjs +616 -0
- package/dist/CloudflareCodeMode.mjs.map +1 -0
- package/dist/CloudflareConfig-f3CqTel1.d.mts +101 -0
- package/dist/CloudflareConfig.d.mts +2 -0
- package/dist/CloudflareConfig.mjs +122 -0
- package/dist/CloudflareConfig.mjs.map +1 -0
- package/dist/CloudflareMemory.d.mts +142 -0
- package/dist/CloudflareMemory.mjs +195 -0
- package/dist/CloudflareMemory.mjs.map +1 -0
- package/dist/CloudflareScheduling.d.mts +52 -0
- package/dist/CloudflareScheduling.mjs +389 -0
- package/dist/CloudflareScheduling.mjs.map +1 -0
- package/dist/CloudflareSubscriptions.d.mts +87 -0
- package/dist/CloudflareSubscriptions.mjs +524 -0
- package/dist/CloudflareSubscriptions.mjs.map +1 -0
- package/dist/CloudflareThreadClient.d.mts +1286 -0
- package/dist/CloudflareThreadClient.mjs +386 -0
- package/dist/CloudflareThreadClient.mjs.map +1 -0
- package/dist/InteractiveBrowser.d.mts +144 -0
- package/dist/InteractiveBrowser.mjs +1090 -0
- package/dist/InteractiveBrowser.mjs.map +1 -0
- package/dist/ProtectedBrowser.d.mts +65 -0
- package/dist/ProtectedBrowser.mjs +859 -0
- package/dist/ProtectedBrowser.mjs.map +1 -0
- package/dist/ThreadObject-BpwkEc5E.mjs +836 -0
- package/dist/ThreadObject-BpwkEc5E.mjs.map +1 -0
- package/dist/ThreadObject-NbFOWK1I.d.mts +816 -0
- package/dist/ThreadObject.d.mts +2 -0
- package/dist/ThreadObject.mjs +3 -0
- package/dist/WakeScheduler.d.mts +23 -0
- package/dist/WakeScheduler.mjs +60 -0
- package/dist/WakeScheduler.mjs.map +1 -0
- package/dist/boundary-BguazVkh.mjs +42 -0
- package/dist/boundary-BguazVkh.mjs.map +1 -0
- package/dist/browser-session-lifecycle-CUbVfEgP.mjs +84 -0
- package/dist/browser-session-lifecycle-CUbVfEgP.mjs.map +1 -0
- package/dist/browser-session-lifecycle-DJpqLXy_.d.mts +21 -0
- package/dist/index.d.mts +13 -1547
- package/dist/index.mjs +13 -1636
- package/dist/prepared-admission-DSi55W-7.mjs +73 -0
- package/dist/prepared-admission-DSi55W-7.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +1 -53
- package/src/Alarm.ts +967 -0
- package/src/BrowserRestCapture.ts +477 -0
- package/src/BrowserRestCrawl.ts +540 -0
- package/src/CloudflareAiGateway.ts +170 -0
- package/src/CloudflareBindings.ts +180 -0
- package/src/CloudflareBrowser.ts +15 -0
- package/src/{code-mode-executor.ts → CloudflareCodeMode.ts} +372 -204
- package/src/{config.ts → CloudflareConfig.ts} +9 -8
- package/src/CloudflareMemory.ts +406 -0
- package/src/CloudflareScheduling.ts +733 -0
- package/src/CloudflareSubscriptions.ts +1045 -0
- package/src/CloudflareThreadClient.ts +807 -0
- package/src/InteractiveBrowser.ts +2357 -0
- package/src/ProtectedBrowser.ts +2 -0
- package/src/ThreadObject.ts +1179 -0
- package/src/{wake-scheduler.ts → WakeScheduler.ts} +23 -23
- package/src/index.ts +12 -23
- package/src/internal/boundary.ts +55 -0
- package/src/internal/browser-quick-action.ts +857 -0
- package/src/internal/browser-session-lifecycle.ts +160 -0
- package/src/internal/layers.ts +751 -0
- package/src/internal/message-delivery.ts +148 -0
- package/src/internal/prepared-admission.ts +116 -0
- package/src/internal/progress-wait.ts +121 -0
- package/src/internal/transport.ts +42 -0
- package/src/protected-browser/binding.ts +187 -0
- package/src/protected-browser/inspect-frame.ts +125 -0
- package/src/protected-browser/native.ts +429 -0
- package/src/protected-browser/policy.ts +719 -0
- package/dist/index.mjs.map +0 -1
- package/src/alarm.ts +0 -334
- package/src/bindings.ts +0 -145
- package/src/client.ts +0 -646
- package/src/conversation-object.ts +0 -768
- package/src/layers.ts +0 -376
- package/src/transport.ts +0 -38
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type ThreadId } from "@effect-agent/core/Identifiers";
|
|
2
|
+
import { type ProducerId } from "@effect-agent/thread/Records";
|
|
3
|
+
import { Context, Effect, Layer, Predicate, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cloudflare platform bindings as Effect services (DEPLOY-010: "Cloudflare platform bindings
|
|
7
|
+
* are supplied as Effect services/Layers"). Application code never reads `env` or touches a
|
|
8
|
+
* `DurableObjectState` directly — the Thread Object class constructs these Layers once
|
|
9
|
+
* per incarnation and everything downstream consumes the services.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** A Cloudflare platform binding was missing or carried the wrong shape (DEPLOY-003/010). */
|
|
13
|
+
export class CloudflareBindingError extends Schema.TaggedError<CloudflareBindingError>()(
|
|
14
|
+
"CloudflareBindingError",
|
|
15
|
+
{
|
|
16
|
+
binding: Schema.String,
|
|
17
|
+
message: Schema.String,
|
|
18
|
+
},
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
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
|
+
* and the cross-Object transport call it through `DurableObjectNamespace` stubs. Every
|
|
25
|
+
* `encoded` value is a Schema-encoded envelope (`client.ts` wire schemas for host entry
|
|
26
|
+
* points, `@effect-agent/storage-cloudflare` port envelopes for `portCall`), so the RPC
|
|
27
|
+
* boundary carries only structured-cloneable JSON. The optional trailing trace context is
|
|
28
|
+
* transient native RPC metadata, stripped by an opted-in effect-cf receiver before decoding
|
|
29
|
+
* the host envelope. It never enters durable state.
|
|
30
|
+
*/
|
|
31
|
+
export interface ThreadObjectRpc extends Rpc.DurableObjectBranded {
|
|
32
|
+
/** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */
|
|
33
|
+
submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
34
|
+
/** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */
|
|
35
|
+
submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
36
|
+
awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
37
|
+
/** Event-driven durable progress wait; answers a `ProgressObserved` host response. */
|
|
38
|
+
awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
39
|
+
/** Best-effort cancellation for one in-flight progress wait. */
|
|
40
|
+
cancelProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
41
|
+
/** One bounded page of canonical records; answers an `ObservePageResponse`. */
|
|
42
|
+
observePage(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
43
|
+
/** Durable abort intent; answers an `AbortResponse`. */
|
|
44
|
+
abortEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
45
|
+
/** Durable approval decision (plan §2.6); answers a `ResolveApprovalResponse`. */
|
|
46
|
+
resolveApprovalEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
47
|
+
/** Authorized DUR-017 Unknown-Outcome resolution; answers a `ResolveUnknownResponse`. */
|
|
48
|
+
resolveUnknownEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
49
|
+
/** Owner-side cross-Object port endpoint (WP2 envelopes, executed on LOCAL facets). */
|
|
50
|
+
portCall(encoded: unknown): Promise<unknown>;
|
|
51
|
+
/** Droppable liveness hint from another Object: arms an immediate alarm. */
|
|
52
|
+
wake(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A logical Thread endpoint may be bound to an application Object without forging its brand. */
|
|
56
|
+
export type ThreadObjectClient = Omit<ThreadObjectRpc, keyof Rpc.DurableObjectBranded>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deterministic logical Thread placement. The native adapter uses `idFromName(threadId)`;
|
|
60
|
+
* a shared application owner can bind that logical identity into its RPC adapter instead.
|
|
61
|
+
* Lookup performs no I/O and grants no authority. Every call resolves its target afresh.
|
|
62
|
+
*/
|
|
63
|
+
export class ThreadObjectNamespace extends Context.Service<
|
|
64
|
+
ThreadObjectNamespace,
|
|
65
|
+
{
|
|
66
|
+
readonly get: (threadId: ThreadId) => ThreadObjectClient;
|
|
67
|
+
/** Stable binding name for opted-in native RPC tracing; absent by default. */
|
|
68
|
+
readonly rpcTracing?: string;
|
|
69
|
+
}
|
|
70
|
+
>()("@effect-agent/platform-cloudflare/ThreadObjectNamespace") {
|
|
71
|
+
static layer(
|
|
72
|
+
namespace: DurableObjectNamespace<ThreadObjectRpc>,
|
|
73
|
+
options: { readonly rpcTracing?: string } = {},
|
|
74
|
+
): Layer.Layer<ThreadObjectNamespace> {
|
|
75
|
+
return Layer.succeed(ThreadObjectNamespace)({
|
|
76
|
+
get: (threadId) => namespace.get(namespace.idFromName(threadId)),
|
|
77
|
+
...(options.rpcTracing === undefined ? {} : { rpcTracing: options.rpcTracing }),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Narrow one `env` member to a `DurableObjectNamespace`. `env` is an untyped platform value,
|
|
84
|
+
* and a namespace binding is a host object no Schema can decode, so this is the documented
|
|
85
|
+
* narrowest-boundary check (structural probe for the namespace surface the transport uses);
|
|
86
|
+
* a missing or misshaped binding fails typed before any Layer is built.
|
|
87
|
+
*/
|
|
88
|
+
export const threadNamespaceFromEnv = Effect.fn("threadNamespaceFromEnv")(function* (
|
|
89
|
+
env: unknown,
|
|
90
|
+
binding: string,
|
|
91
|
+
): Effect.fn.Return<DurableObjectNamespace<ThreadObjectRpc>, CloudflareBindingError> {
|
|
92
|
+
if (!Predicate.isObjectKeyword(env)) {
|
|
93
|
+
return yield* CloudflareBindingError.make({
|
|
94
|
+
binding,
|
|
95
|
+
message: "The Worker environment is not an object; no bindings are available.",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const candidate = yield* Effect.try({
|
|
100
|
+
try: () => {
|
|
101
|
+
const value: unknown = Reflect.get(env, binding);
|
|
102
|
+
|
|
103
|
+
if (!Predicate.isObjectKeyword(value)) return undefined;
|
|
104
|
+
const idFromName: unknown = Reflect.get(value, "idFromName");
|
|
105
|
+
const get: unknown = Reflect.get(value, "get");
|
|
106
|
+
|
|
107
|
+
return typeof idFromName === "function" && typeof get === "function" ? value : undefined;
|
|
108
|
+
},
|
|
109
|
+
catch: () =>
|
|
110
|
+
CloudflareBindingError.make({
|
|
111
|
+
binding,
|
|
112
|
+
message: `env.${binding} could not be inspected as a DurableObjectNamespace binding.`,
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (candidate !== undefined) {
|
|
117
|
+
// The structural probe above is the entire runtime contract this package relies on;
|
|
118
|
+
// the assertion records that `idFromName`/`get` name a DurableObjectNamespace.
|
|
119
|
+
return candidate as unknown as DurableObjectNamespace<ThreadObjectRpc>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return yield* CloudflareBindingError.make({
|
|
123
|
+
binding,
|
|
124
|
+
message:
|
|
125
|
+
`env.${binding} is not a DurableObjectNamespace binding; declare the Thread ` +
|
|
126
|
+
"Object class under this binding in the Worker configuration.",
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build the namespace from Worker `env` (fails typed). Enable `rpcTracing` only when the
|
|
132
|
+
* receiver also opts into the effect-cf native RPC trace-context contract.
|
|
133
|
+
*/
|
|
134
|
+
export const threadNamespaceLayer = (
|
|
135
|
+
env: unknown,
|
|
136
|
+
binding: string,
|
|
137
|
+
options: { readonly rpcTracing?: boolean } = {},
|
|
138
|
+
): Layer.Layer<ThreadObjectNamespace, CloudflareBindingError> =>
|
|
139
|
+
Layer.effect(ThreadObjectNamespace)(
|
|
140
|
+
Effect.map(threadNamespaceFromEnv(env, binding), (namespace) => ({
|
|
141
|
+
get: (threadId) => namespace.get(namespace.idFromName(threadId)),
|
|
142
|
+
...(options.rpcTracing === true ? { rpcTracing: binding } : {}),
|
|
143
|
+
})),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The live Durable Object execution context of THIS incarnation. Only Layer construction and
|
|
148
|
+
* the alarm service consume it; important state never lives on it (`ctx.storage` is truth,
|
|
149
|
+
* everything in memory is a cache — deployment spec §11).
|
|
150
|
+
*/
|
|
151
|
+
export class DurableObjectContext extends Context.Service<
|
|
152
|
+
DurableObjectContext,
|
|
153
|
+
{
|
|
154
|
+
readonly ctx: DurableObjectState;
|
|
155
|
+
readonly env: unknown;
|
|
156
|
+
}
|
|
157
|
+
>()("@effect-agent/platform-cloudflare/DurableObjectContext") {
|
|
158
|
+
static layer(ctx: DurableObjectState, env: unknown): Layer.Layer<DurableObjectContext> {
|
|
159
|
+
return Layer.succeed(DurableObjectContext)({ ctx, env });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The Thread identity this Object serializes and the producer identity its Attempts
|
|
165
|
+
* write with (`{producerPrefix}:{threadId}`, plan §1.4). Derived once per incarnation
|
|
166
|
+
* from `ctx.id.name` — the Object identity rule guarantees the name IS the Thread ID.
|
|
167
|
+
*/
|
|
168
|
+
export class ThreadObjectIdentity extends Context.Service<
|
|
169
|
+
ThreadObjectIdentity,
|
|
170
|
+
{
|
|
171
|
+
readonly threadId: ThreadId;
|
|
172
|
+
readonly producerId: ProducerId;
|
|
173
|
+
}
|
|
174
|
+
>()("@effect-agent/platform-cloudflare/ThreadObjectIdentity") {}
|
|
175
|
+
|
|
176
|
+
/** Logical Threads whose canonical stores and admission ledger live in this physical Object. */
|
|
177
|
+
export class ThreadObjectPlacement extends Context.Service<
|
|
178
|
+
ThreadObjectPlacement,
|
|
179
|
+
{ readonly ownsThread: (threadId: ThreadId) => boolean }
|
|
180
|
+
>()("@effect-agent/platform-cloudflare/ThreadObjectPlacement") {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Public CloudflareBrowser API. Implementation helpers remain private. */
|
|
2
|
+
export {
|
|
3
|
+
BrowserQuickActionBrowserBinding,
|
|
4
|
+
BrowserQuickActionRpcError,
|
|
5
|
+
BrowserQuickActionWorkersAi,
|
|
6
|
+
BrowserQuickActionWorkersAiPolicyError,
|
|
7
|
+
browserQuickActionCaptureLayer,
|
|
8
|
+
browserQuickActionWorkersAiCaptureLayer,
|
|
9
|
+
browserQuickActionScreenshotLayer,
|
|
10
|
+
CloudflareBrowser,
|
|
11
|
+
type BrowserQuickActionCaptureOptions,
|
|
12
|
+
type BrowserQuickActionClient,
|
|
13
|
+
type BrowserQuickActionWorkersAiPolicy,
|
|
14
|
+
type CloudflareBrowserOptions,
|
|
15
|
+
} from "./internal/browser-quick-action.ts";
|