@effect-agent/platform-cloudflare 0.1.0-beta.9 → 0.1.0-beta.90

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