@effect-agent/platform-cloudflare 0.1.0-beta.10 → 0.1.0-beta.101

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