@effect-agent/platform-cloudflare 0.1.0-beta.6 → 0.1.0-beta.60

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 (95) hide show
  1. package/dist/Alarm.d.mts +168 -0
  2. package/dist/Alarm.mjs +415 -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/CloudflareBindings.d.mts +105 -0
  11. package/dist/CloudflareBindings.mjs +98 -0
  12. package/dist/CloudflareBindings.mjs.map +1 -0
  13. package/dist/CloudflareBrowser-Bj22nNUT.mjs +466 -0
  14. package/dist/CloudflareBrowser-Bj22nNUT.mjs.map +1 -0
  15. package/dist/CloudflareBrowser-DJq53niJ.d.mts +80 -0
  16. package/dist/CloudflareBrowser.d.mts +2 -0
  17. package/dist/CloudflareBrowser.mjs +2 -0
  18. package/dist/CloudflareCodeMode.d.mts +44 -0
  19. package/dist/CloudflareCodeMode.mjs +611 -0
  20. package/dist/CloudflareCodeMode.mjs.map +1 -0
  21. package/dist/CloudflareConfig-f3CqTel1.d.mts +101 -0
  22. package/dist/CloudflareConfig.d.mts +2 -0
  23. package/dist/CloudflareConfig.mjs +122 -0
  24. package/dist/CloudflareConfig.mjs.map +1 -0
  25. package/dist/CloudflareMemory.d.mts +140 -0
  26. package/dist/CloudflareMemory.mjs +168 -0
  27. package/dist/CloudflareMemory.mjs.map +1 -0
  28. package/dist/CloudflareScheduling.d.mts +52 -0
  29. package/dist/CloudflareScheduling.mjs +389 -0
  30. package/dist/CloudflareScheduling.mjs.map +1 -0
  31. package/dist/CloudflareSubscriptions.d.mts +87 -0
  32. package/dist/CloudflareSubscriptions.mjs +524 -0
  33. package/dist/CloudflareSubscriptions.mjs.map +1 -0
  34. package/dist/CloudflareThreadClient.d.mts +1214 -0
  35. package/dist/CloudflareThreadClient.mjs +386 -0
  36. package/dist/CloudflareThreadClient.mjs.map +1 -0
  37. package/dist/InteractiveBrowser.d.mts +144 -0
  38. package/dist/InteractiveBrowser.mjs +1090 -0
  39. package/dist/InteractiveBrowser.mjs.map +1 -0
  40. package/dist/ProtectedBrowser.d.mts +65 -0
  41. package/dist/ProtectedBrowser.mjs +859 -0
  42. package/dist/ProtectedBrowser.mjs.map +1 -0
  43. package/dist/ThreadObject-CvnEnVQH.d.mts +772 -0
  44. package/dist/ThreadObject-s5w3V_co.mjs +675 -0
  45. package/dist/ThreadObject-s5w3V_co.mjs.map +1 -0
  46. package/dist/ThreadObject.d.mts +2 -0
  47. package/dist/ThreadObject.mjs +3 -0
  48. package/dist/WakeScheduler.d.mts +23 -0
  49. package/dist/WakeScheduler.mjs +60 -0
  50. package/dist/WakeScheduler.mjs.map +1 -0
  51. package/dist/boundary-BguazVkh.mjs +42 -0
  52. package/dist/boundary-BguazVkh.mjs.map +1 -0
  53. package/dist/browser-session-lifecycle-CUbVfEgP.mjs +84 -0
  54. package/dist/browser-session-lifecycle-CUbVfEgP.mjs.map +1 -0
  55. package/dist/browser-session-lifecycle-DJpqLXy_.d.mts +21 -0
  56. package/dist/index.d.mts +12 -1543
  57. package/dist/index.mjs +12 -1636
  58. package/dist/prepared-admission-G7N4DDqS.mjs +73 -0
  59. package/dist/prepared-admission-G7N4DDqS.mjs.map +1 -0
  60. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  61. package/package.json +1 -53
  62. package/src/Alarm.ts +862 -0
  63. package/src/BrowserRestCapture.ts +477 -0
  64. package/src/BrowserRestCrawl.ts +540 -0
  65. package/src/CloudflareBindings.ts +171 -0
  66. package/src/CloudflareBrowser.ts +15 -0
  67. package/src/{code-mode-executor.ts → CloudflareCodeMode.ts} +367 -204
  68. package/src/{config.ts → CloudflareConfig.ts} +9 -8
  69. package/src/CloudflareMemory.ts +359 -0
  70. package/src/CloudflareScheduling.ts +733 -0
  71. package/src/CloudflareSubscriptions.ts +1045 -0
  72. package/src/CloudflareThreadClient.ts +807 -0
  73. package/src/InteractiveBrowser.ts +2357 -0
  74. package/src/ProtectedBrowser.ts +2 -0
  75. package/src/{conversation-object.ts → ThreadObject.ts} +423 -239
  76. package/src/{wake-scheduler.ts → WakeScheduler.ts} +23 -23
  77. package/src/index.ts +11 -23
  78. package/src/internal/boundary.ts +55 -0
  79. package/src/internal/browser-quick-action.ts +818 -0
  80. package/src/internal/browser-session-lifecycle.ts +160 -0
  81. package/src/internal/layers.ts +615 -0
  82. package/src/internal/message-delivery.ts +90 -0
  83. package/src/internal/prepared-admission.ts +116 -0
  84. package/src/internal/progress-wait.ts +121 -0
  85. package/src/internal/transport.ts +42 -0
  86. package/src/protected-browser/binding.ts +187 -0
  87. package/src/protected-browser/inspect-frame.ts +125 -0
  88. package/src/protected-browser/native.ts +429 -0
  89. package/src/protected-browser/policy.ts +719 -0
  90. package/dist/index.mjs.map +0 -1
  91. package/src/alarm.ts +0 -334
  92. package/src/bindings.ts +0 -145
  93. package/src/client.ts +0 -646
  94. package/src/layers.ts +0 -376
  95. package/src/transport.ts +0 -38
@@ -0,0 +1,171 @@
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
+ /**
56
+ * The `DurableObjectNamespace` binding that addresses Thread Objects. The Object
57
+ * identity rule is `namespace.idFromName(threadId)` (plan §1.2): Thread IDs are
58
+ * globally unique, so the mapping is total and deterministic and no directory service exists.
59
+ */
60
+ export class ThreadObjectNamespace extends Context.Service<
61
+ ThreadObjectNamespace,
62
+ {
63
+ readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;
64
+ /** Stable binding name for opted-in native RPC tracing; absent by default. */
65
+ readonly rpcTracing?: string;
66
+ }
67
+ >()("@effect-agent/platform-cloudflare/ThreadObjectNamespace") {
68
+ static layer(
69
+ namespace: DurableObjectNamespace<ThreadObjectRpc>,
70
+ options: { readonly rpcTracing?: string } = {},
71
+ ): Layer.Layer<ThreadObjectNamespace> {
72
+ return Layer.succeed(ThreadObjectNamespace)({
73
+ namespace,
74
+ ...(options.rpcTracing === undefined ? {} : { rpcTracing: options.rpcTracing }),
75
+ });
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Narrow one `env` member to a `DurableObjectNamespace`. `env` is an untyped platform value,
81
+ * and a namespace binding is a host object no Schema can decode, so this is the documented
82
+ * narrowest-boundary check (structural probe for the namespace surface the transport uses);
83
+ * a missing or misshaped binding fails typed before any Layer is built.
84
+ */
85
+ export const threadNamespaceFromEnv = Effect.fn("threadNamespaceFromEnv")(function* (
86
+ env: unknown,
87
+ binding: string,
88
+ ): Effect.fn.Return<DurableObjectNamespace<ThreadObjectRpc>, CloudflareBindingError> {
89
+ if (!Predicate.isObjectKeyword(env)) {
90
+ return yield* CloudflareBindingError.make({
91
+ binding,
92
+ message: "The Worker environment is not an object; no bindings are available.",
93
+ });
94
+ }
95
+
96
+ const candidate = yield* Effect.try({
97
+ try: () => {
98
+ const value: unknown = Reflect.get(env, binding);
99
+
100
+ if (!Predicate.isObjectKeyword(value)) return undefined;
101
+ const idFromName: unknown = Reflect.get(value, "idFromName");
102
+ const get: unknown = Reflect.get(value, "get");
103
+
104
+ return typeof idFromName === "function" && typeof get === "function" ? value : undefined;
105
+ },
106
+ catch: () =>
107
+ CloudflareBindingError.make({
108
+ binding,
109
+ message: `env.${binding} could not be inspected as a DurableObjectNamespace binding.`,
110
+ }),
111
+ });
112
+
113
+ if (candidate !== undefined) {
114
+ // The structural probe above is the entire runtime contract this package relies on;
115
+ // the assertion records that `idFromName`/`get` name a DurableObjectNamespace.
116
+ return candidate as unknown as DurableObjectNamespace<ThreadObjectRpc>;
117
+ }
118
+
119
+ return yield* CloudflareBindingError.make({
120
+ binding,
121
+ message:
122
+ `env.${binding} is not a DurableObjectNamespace binding; declare the Thread ` +
123
+ "Object class under this binding in the Worker configuration.",
124
+ });
125
+ });
126
+
127
+ /**
128
+ * Build the namespace from Worker `env` (fails typed). Enable `rpcTracing` only when the
129
+ * receiver also opts into the effect-cf native RPC trace-context contract.
130
+ */
131
+ export const threadNamespaceLayer = (
132
+ env: unknown,
133
+ binding: string,
134
+ options: { readonly rpcTracing?: boolean } = {},
135
+ ): Layer.Layer<ThreadObjectNamespace, CloudflareBindingError> =>
136
+ Layer.effect(ThreadObjectNamespace)(
137
+ Effect.map(threadNamespaceFromEnv(env, binding), (namespace) => ({
138
+ namespace,
139
+ ...(options.rpcTracing === true ? { rpcTracing: binding } : {}),
140
+ })),
141
+ );
142
+
143
+ /**
144
+ * The live Durable Object execution context of THIS incarnation. Only Layer construction and
145
+ * the alarm service consume it; important state never lives on it (`ctx.storage` is truth,
146
+ * everything in memory is a cache — deployment spec §11).
147
+ */
148
+ export class DurableObjectContext extends Context.Service<
149
+ DurableObjectContext,
150
+ {
151
+ readonly ctx: DurableObjectState;
152
+ readonly env: unknown;
153
+ }
154
+ >()("@effect-agent/platform-cloudflare/DurableObjectContext") {
155
+ static layer(ctx: DurableObjectState, env: unknown): Layer.Layer<DurableObjectContext> {
156
+ return Layer.succeed(DurableObjectContext)({ ctx, env });
157
+ }
158
+ }
159
+
160
+ /**
161
+ * The Thread identity this Object serializes and the producer identity its Attempts
162
+ * write with (`{producerPrefix}:{threadId}`, plan §1.4). Derived once per incarnation
163
+ * from `ctx.id.name` — the Object identity rule guarantees the name IS the Thread ID.
164
+ */
165
+ export class ThreadObjectIdentity extends Context.Service<
166
+ ThreadObjectIdentity,
167
+ {
168
+ readonly threadId: ThreadId;
169
+ readonly producerId: ProducerId;
170
+ }
171
+ >()("@effect-agent/platform-cloudflare/ThreadObjectIdentity") {}
@@ -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";