@effect-agent/platform-cloudflare 0.1.0-beta.11 → 0.1.0-beta.110

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 (103) hide show
  1. package/dist/Alarm.d.mts +208 -0
  2. package/dist/Alarm.mjs +601 -0
  3. package/dist/Alarm.mjs.map +1 -0
  4. package/dist/BrowserRestCapture.d.mts +34 -0
  5. package/dist/BrowserRestCapture.mjs +238 -0
  6. package/dist/BrowserRestCapture.mjs.map +1 -0
  7. package/dist/BrowserRestCrawl.d.mts +16 -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-DKXGo8L3.d.mts +106 -0
  25. package/dist/CloudflareConfig.d.mts +2 -0
  26. package/dist/CloudflareConfig.mjs +128 -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 +1675 -0
  38. package/dist/CloudflareThreadClient.mjs +382 -0
  39. package/dist/CloudflareThreadClient.mjs.map +1 -0
  40. package/dist/InteractiveBrowser-CKp6pqmw.d.mts +171 -0
  41. package/dist/InteractiveBrowser-l6J4eP6T.mjs +1427 -0
  42. package/dist/InteractiveBrowser-l6J4eP6T.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 +1161 -0
  47. package/dist/ProtectedBrowser.mjs.map +1 -0
  48. package/dist/ThreadObject-BGla_Obk.mjs +858 -0
  49. package/dist/ThreadObject-BGla_Obk.mjs.map +1 -0
  50. package/dist/ThreadObject-MSlpVBUD.d.mts +829 -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 +1323 -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} +19 -12
  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 +2612 -0
  77. package/src/ProtectedBrowser.ts +9 -0
  78. package/src/ThreadObject.ts +1184 -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-binding.ts +82 -0
  83. package/src/internal/browser-failure.ts +92 -0
  84. package/src/internal/browser-file-selection.ts +126 -0
  85. package/src/internal/browser-quick-action.ts +857 -0
  86. package/src/internal/browser-session-lifecycle.ts +193 -0
  87. package/src/internal/layers.ts +765 -0
  88. package/src/internal/message-delivery.ts +181 -0
  89. package/src/internal/prepared-admission.ts +116 -0
  90. package/src/internal/progress-wait.ts +121 -0
  91. package/src/internal/transport.ts +44 -0
  92. package/src/protected-browser/binding.ts +354 -0
  93. package/src/protected-browser/host.ts +379 -0
  94. package/src/protected-browser/inspect-frame.ts +125 -0
  95. package/src/protected-browser/native.ts +473 -0
  96. package/src/protected-browser/policy.ts +857 -0
  97. package/dist/index.mjs.map +0 -1
  98. package/src/alarm.ts +0 -334
  99. package/src/bindings.ts +0 -145
  100. package/src/client.ts +0 -646
  101. package/src/conversation-object.ts +0 -768
  102. package/src/layers.ts +0 -376
  103. package/src/transport.ts +0 -38
@@ -0,0 +1,208 @@
1
+ import { DurableObjectContext } from "./CloudflareBindings.mjs";
2
+ import { s as CloudflareDurableRuntimeConfig } from "./CloudflareConfig-DKXGo8L3.mjs";
3
+ import { Cause, Context, DateTime, Effect, Layer, Option, Schema, Scope } from "effect";
4
+ import { DurableBindingFailure } from "effect-agent/agent-registration";
5
+ import { DurableAgentRuntime, DurableWorkerFailure } from "effect-agent/durable-agent-runtime";
6
+ import { SubmissionLedger } from "effect-agent/submission-ledger";
7
+ import { ThreadProjectionError, ThreadProjectionMaintenance } from "effect-agent/thread-projection-maintenance";
8
+ import { WakeScheduler } from "effect-agent/wake-scheduler";
9
+ import { SqlClient } from "effect/unstable/sql/SqlClient";
10
+ declare namespace Alarm_d_exports {
11
+ export { DurableAlarmError, DurableAlarmService, MaintenancePassFailure, MaintenancePassReport, ThreadHostMaintenance, ThreadMaintenance, ThreadMaintenanceFailpoint, ThreadMaintenanceFailpointHandler, ThreadMaintenanceFailpointLocation, ThreadMessageDelivery, ThreadMutationGate, ThreadPublication, ThreadPublicationService, publishCommitted };
12
+ }
13
+ declare const DurableAlarmError_base: Schema.Class<DurableAlarmError, Schema.TaggedStruct<"DurableAlarmError", {
14
+ readonly operation: Schema.String;
15
+ readonly message: Schema.String;
16
+ readonly cause: Schema.optionalKey<Schema.Defect>;
17
+ }>, Cause.YieldableError>;
18
+ /**
19
+ * The single multiplexed Durable Object alarm (decision D-P6-2). A Durable Object has ONE
20
+ * alarm slot; every cadence the Node host ran on fibers (wake scan, lease expiry, settlement
21
+ * and abort re-checks, retry backoff) multiplexes into one idempotent maintenance pass, and
22
+ * the slot always holds the EARLIEST deadline any caller asked for.
23
+ *
24
+ * The alarm invariant (plan §1.4): every committed actionable mutation carries a newer durable
25
+ * maintenance generation and a committed alarm. Stable externally-driven waits may be
26
+ * nonterminal without retaining an alarm; their resolving mutation advances the generation and
27
+ * restores the alarm atomically.
28
+ */
29
+ /** The Durable Object alarm API failed; surfaces on host entry points as a typed refusal. */
30
+ export declare class DurableAlarmError extends DurableAlarmError_base {}
31
+ declare const DurableAlarmService_base: Context.ServiceClass<DurableAlarmService, "@effect-agent/platform-cloudflare/DurableAlarmService", {
32
+ /** The scheduled deadline in epoch milliseconds, if any. */
33
+ readonly scheduled: Effect.Effect<Option.Option<number>, DurableAlarmError>;
34
+ /** Replace the slot with this deadline. */
35
+ readonly scheduleAt: (epochMillis: number) => Effect.Effect<void, DurableAlarmError>;
36
+ /** Keep the EARLIER of the existing deadline and this one (the multiplexing rule). */
37
+ readonly ensureScheduledBy: (epochMillis: number) => Effect.Effect<void, DurableAlarmError>;
38
+ /**
39
+ * Arm an immediate alarm (the durable, coalescing local wake) — DEFERRED while a
40
+ * maintenance pass is executing. Workerd cancels an in-flight alarm handler when a new
41
+ * EARLIER deadline is written during its execution (`requestScheduledAlarm`), and the
42
+ * maintenance pass runs INSIDE the alarm handler: an immediate wake landing mid-pass
43
+ * (a routed port mutation, a sibling's `wake()`, the coordinator's own local notify)
44
+ * would kill the running Attempt — manufacturing an ownership loss no real eviction
45
+ * caused, and routing open uncertain-class Tool Calls into spurious Unknown Outcomes.
46
+ * Deferral is contract-safe: wakes are droppable hints, every mutating entry point
47
+ * pre-arms BEFORE its first durable mutation (the alarm invariant never rests on this
48
+ * call). The pass's durable generation check observes any racing mutation, so the
49
+ * in-memory hint does not need to be flushed after a stable wait is acknowledged.
50
+ */
51
+ readonly scheduleNow: Effect.Effect<void, DurableAlarmError>;
52
+ /**
53
+ * Run one maintenance pass with wake deferral (see `scheduleNow`). Calls made while `body`
54
+ * executes are droppable promptness hints; correctness rests on the durable generation.
55
+ */
56
+ readonly withWakesDeferred: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
57
+ /** Clear the slot; correctness-sensitive clears live in maintenance generation transactions. */
58
+ readonly cancel: Effect.Effect<void, DurableAlarmError>;
59
+ }>;
60
+ /** `ctx.storage` alarm slot as an Effect service; storage is truth, never a memory field. */
61
+ export declare class DurableAlarmService extends DurableAlarmService_base {
62
+ static readonly layer: Layer.Layer<DurableAlarmService, never, DurableObjectContext | SqlClient>;
63
+ }
64
+ declare const MaintenancePassReport_base: Schema.Class<MaintenancePassReport, Schema.Struct<{
65
+ /** `caught-up` ran no runtime work (publication may be pending); `actionable` ran recovery. */
66
+ readonly phase: Schema.Literals<readonly ["caught-up", "actionable"]>;
67
+ /** Recovery decisions executed (or deferred) BEFORE any new claim in this pass. */
68
+ readonly recovered: Schema.Int;
69
+ /** Head Attempts settled during the event. Joined input may settle with each head. */
70
+ readonly settled: Schema.Int;
71
+ /** Submissions still nonterminal after the pass (suspended/unknown lanes stay honest). */
72
+ readonly nonterminal: Schema.Int;
73
+ /** `rearmed` for dirty/autonomous work, `cleared` for stable waits or settlement. */
74
+ readonly alarm: Schema.Literals<readonly ["rearmed", "cleared"]>;
75
+ }>, {}>;
76
+ /** What one maintenance pass did — auditable evidence mirroring `NodeDurableHost`'s report. */
77
+ export declare class MaintenancePassReport extends MaintenancePassReport_base {}
78
+ /** Fault boundaries around every maintenance-owned durable mutation. */
79
+ export type ThreadMaintenanceFailpointLocation = "maintenance:dirty:before" | "maintenance:dirty:after" | "maintenance:mutation:armed" | "maintenance:mutation:finished" | "maintenance:ensure:before" | "maintenance:ensure:after" | "maintenance:begin:before" | "maintenance:begin:after" | "maintenance:select:before" | "maintenance:select:after" | "maintenance:binding-retry:before" | "maintenance:binding-retry:after" | "maintenance:retry:before" | "maintenance:retry:after" | "maintenance:checkpoint:before" | "maintenance:checkpoint:after" | "maintenance:finish:before" | "maintenance:finish:after";
80
+ export type ThreadMaintenanceFailpointHandler = (location: ThreadMaintenanceFailpointLocation) => Effect.Effect<void>;
81
+ declare const ThreadMaintenanceFailpoint_base: Context.ServiceClass<ThreadMaintenanceFailpoint, "@effect-agent/platform-cloudflare/ThreadMaintenanceFailpoint", {
82
+ readonly hit: ThreadMaintenanceFailpointHandler;
83
+ }>;
84
+ /** Test-only fault authority; production uses the inert layer. */
85
+ export declare class ThreadMaintenanceFailpoint extends ThreadMaintenanceFailpoint_base {
86
+ static readonly layer: Layer.Layer<ThreadMaintenanceFailpoint, never, never>;
87
+ }
88
+ /**
89
+ * Durable host publication of canonical records and ledger approval/abort/resolution intents.
90
+ * The host owns schema-versioned cursors, destination idempotency and acknowledgement. Delivery
91
+ * is at least once. Hooks must not write the alarm slot or mutate the supplied raw source ports.
92
+ *
93
+ * `invalidate`, `prepareGeneration` and `pendingDeadline` must be bounded local operations.
94
+ * `prepareGeneration` durably invalidates a scan only when its generation changes; repeated
95
+ * calls must preserve partial scan progress. It runs with no source mutation in flight.
96
+ * Use this gate only for publication required before dependent native execution. Independent
97
+ * UI relays and outboxes belong to ThreadHostMaintenance.
98
+ * `drain` performs bounded delivery and persists retries before returning. A pending deadline
99
+ * defers runtime recovery/Attempts, allowing committed host publications to drain first.
100
+ * Unexpected hook failures leave the prearmed generation for retry. Hooks acquire per-call
101
+ * resources with Effect.scoped; Layer construction owns incarnation resources (eviction need
102
+ * not run finalizers). Do not hold a local hook behind network I/O or call back into producers.
103
+ */
104
+ export interface ThreadPublicationService {
105
+ readonly invalidate: Effect.Effect<void, DurableAlarmError>;
106
+ readonly prepareGeneration: (generation: bigint) => Effect.Effect<void, DurableAlarmError>;
107
+ readonly drain: Effect.Effect<void, DurableAlarmError>;
108
+ readonly pendingDeadline: Effect.Effect<Option.Option<number>, DurableAlarmError>;
109
+ }
110
+ declare const ThreadPublication_base: Context.ServiceClass<ThreadPublication, "@effect-agent/platform-cloudflare/ThreadPublication", ThreadPublicationService>;
111
+ /** Opt in with `ThreadObject.layer(registrations, { publication: Layer.effect(ThreadPublication)(...) })`. */
112
+ export declare class ThreadPublication extends ThreadPublication_base {
113
+ static readonly layer: Layer.Layer<ThreadPublication, never, never>;
114
+ }
115
+ /**
116
+ * Host-assembled native message recovery. The driver bounds each actual Claim and persists its
117
+ * timeout/retry before this pump returns. Do not add a second timer starting at batch selection:
118
+ * local Claim setup may take time, and expiration still owes the driver's local retry commit.
119
+ */
120
+ export declare const ThreadMessageDelivery: Context.Reference<{
121
+ readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope>;
122
+ readonly pendingDeadline: Effect.Effect<Option.Option<number>, DurableAlarmError>;
123
+ }>;
124
+ /**
125
+ * Application obligations sharing this Object's alarm. Admit one initial external wave even on
126
+ * a caught-up pass, then respond to wakes until dispatchClosed. This closes only admission
127
+ * of NEW external waves; native work can continue while admitted waves finish. Keep local
128
+ * admission/hub subscriptions in the event Scope until maintenance tears it down.
129
+ * No deadline sleeps or automatic retry loops. Return after already-admitted waves finish.
130
+ *
131
+ * Declare a finite whole-wave allowance (1..300000ms): maximum for parallel lanes, sum for
132
+ * sequential operations. Admit a wave only if its allowance fits before dispatchUntil. Later
133
+ * arrivals cannot renew the retirement window. Maintenance bounds the join after dispatchClosed,
134
+ * interrupts and joins event Scope, then reads local deadlines under the mutation gate.
135
+ *
136
+ * Setup and pendingDeadline are bounded local operations. Persist claims/envelopes before
137
+ * dispatch; interrupted waits leave exact retries/receipts recoverable. Cancellation is local,
138
+ * not remote rollback. Retry accounting is unchanged. Network waits/finalizers must be
139
+ * interruptible; short local atomic commits may be uninterruptible. Hooks never write the raw
140
+ * alarm slot. Required native publication gates belong to ThreadPublication.
141
+ */
142
+ export declare const ThreadHostMaintenance: Context.Reference<{
143
+ readonly dispatchTimeoutMillis: number;
144
+ readonly drainUntil: (dispatchClosed: Effect.Effect<void>, dispatchUntil: DateTime.Utc) => Effect.Effect<void, DurableAlarmError, Scope.Scope>;
145
+ readonly pendingDeadline: Effect.Effect<Option.Option<number>, DurableAlarmError>;
146
+ }>;
147
+ /** @internal A committed source operation must not become a failed operation because delivery failed. */
148
+ export declare const publishCommitted: Effect.Effect<void, never, ThreadPublication>;
149
+ declare const ThreadMutationGate_base: Context.ServiceClass<ThreadMutationGate, "@effect-agent/platform-cloudflare/internal/ThreadMutationGate", {
150
+ readonly withMutation: <A, E, R>(body: Effect.Effect<A, E, R>,
151
+ /**
152
+ * Native admission, approval, abort and unknown resolution keep the default true.
153
+ * Projection/relay/reply receipt-only bookkeeping must use false: its local durable
154
+ * pendingDeadline owns scheduling without creating native recovery debt.
155
+ */
156
+ options?: {
157
+ readonly invalidatesRecovery: boolean;
158
+ }) => Effect.Effect<A, E | DurableAlarmError, R>;
159
+ readonly withSnapshot: <A, E, R>(body: (active: number) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
160
+ }>;
161
+ /**
162
+ * Shared prearm/acknowledgement boundary for ingress and runtime-owned producers.
163
+ * `ThreadObject.layer` provides this same instance in its Services. Rebuilt runtime/maintenance
164
+ * Layers must reuse that instance; a second gate cannot observe the native producers' activity.
165
+ */
166
+ export declare class ThreadMutationGate extends ThreadMutationGate_base {
167
+ static readonly layer: Layer.Layer<ThreadMutationGate, never, CloudflareDurableRuntimeConfig | DurableObjectContext | SqlClient | ThreadMaintenanceFailpoint>;
168
+ }
169
+ export type MaintenancePassFailure = DurableWorkerFailure | DurableBindingFailure | DurableAlarmError | ThreadProjectionError;
170
+ declare const ThreadMaintenance_base: Context.ServiceClass<ThreadMaintenance, "@effect-agent/platform-cloudflare/ThreadMaintenance", {
171
+ /** One idempotent pass; failures propagate after durably scheduling bounded recovery. */
172
+ readonly pass: Effect.Effect<MaintenancePassReport, MaintenancePassFailure>;
173
+ /**
174
+ * Constructor gate: initialize/inspect only the O(1) maintenance record and ensure a dirty
175
+ * generation has an alarm. It never scans the ledger or canonical history.
176
+ */
177
+ readonly ensureAlarm: Effect.Effect<void, MaintenancePassFailure>;
178
+ /**
179
+ * Serialize the pre-arm boundary with pass acknowledgement, advance the durable dirty
180
+ * generation and arm the alarm in one transaction BEFORE running the caller's mutation.
181
+ * A pass cannot acknowledge while that mutation remains in flight.
182
+ */
183
+ readonly withMutation: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | DurableAlarmError, R>;
184
+ }>;
185
+ /**
186
+ * Incremental, quiescent maintenance over a durable dirty/processed generation (issue #93).
187
+ *
188
+ * One physical event owns native scheduling, auxiliary delivery and final alarm rearming.
189
+ *
190
+ * 1. Prearm before any work. A caught-up native step uses the O(1) generation record without
191
+ * recovery, ledger scans or canonical-history reads.
192
+ * 2. Reconcile before each head Attempt, then checkpoint only the observed generation. A racing
193
+ * producer keeps its newer generation dirty. Native retries retain their durable backoff.
194
+ * 3. After the initial native opportunity, stop admitting new external waves and let the
195
+ * active waves finish. While they remain in flight, native wakes and bounded scans can
196
+ * advance more heads. All Attempts share the event's original ten-minute yield deadline.
197
+ * 4. Native message delivery retains its driver-owned Claim deadline. Host/backfill joins are
198
+ * bounded independently; incoming native work never restarts or cancels their attempts.
199
+ * Auxiliary failures are reported after the current native opportunity.
200
+ * 5. Close every event resource before the final gated deadline snapshot and alarm decision.
201
+ * The whole event retains one fourteen-minute cooperative timeout.
202
+ */
203
+ export declare class ThreadMaintenance extends ThreadMaintenance_base {
204
+ static readonly layer: Layer.Layer<ThreadMaintenance, never, ThreadMutationGate | ThreadPublication | ThreadProjectionMaintenance | DurableAgentRuntime | SubmissionLedger | WakeScheduler | DurableAlarmService | ThreadMaintenanceFailpoint | CloudflareDurableRuntimeConfig | DurableObjectContext | SqlClient>;
205
+ }
206
+ //#endregion
207
+ export { Alarm_d_exports as t };
208
+ //# sourceMappingURL=Alarm.d.mts.map