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

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 (102) 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 +1600 -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-CMQiW2uX.d.mts +827 -0
  49. package/dist/ThreadObject-DXavwaU-.mjs +853 -0
  50. package/dist/ThreadObject-DXavwaU-.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 -1580
  59. package/dist/index.mjs +13 -1941
  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 -52
  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 -15
  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 +1179 -0
  79. package/src/{wake-scheduler.ts → WakeScheduler.ts} +32 -26
  80. package/src/index.ts +12 -24
  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 +756 -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 -847
  99. package/src/layers.ts +0 -385
  100. package/src/telemetry-internal.ts +0 -432
  101. package/src/telemetry.ts +0 -37
  102. package/src/transport.ts +0 -38
package/src/layers.ts DELETED
@@ -1,385 +0,0 @@
1
- import { ConversationId } from "@effect-agent/core";
2
- import {
3
- AgentBindingResolver,
4
- ConversationStore,
5
- DurableAgentRuntime,
6
- DurableRuntimeConfig,
7
- DurableRuntimeFailpoint,
8
- ProducerId,
9
- SubmissionLedger,
10
- ToolReconciler,
11
- WakeScheduler,
12
- type DurableRuntimeFailpointHandler,
13
- type ResolvedBinding,
14
- } from "@effect-agent/session";
15
- import {
16
- conversationStoreLayer,
17
- handleEncodedPortRequest,
18
- routedConversationStoreLayer,
19
- routedSubmissionLedgerLayer,
20
- storageConfigLayer,
21
- storageFailpointLayer,
22
- submissionLedgerLayer,
23
- type DoStorageFailpointHandler,
24
- type DoStorageInitializationError,
25
- type DoStorageOptions,
26
- } from "@effect-agent/storage-cloudflare";
27
- import { BrowserCrypto } from "@effect/platform-browser";
28
- import { SqliteClient } from "@effect/sql-sqlite-do";
29
- import { Context, Duration, Effect, Layer, Schema } from "effect";
30
-
31
- import { ConversationMaintenance, DurableAlarmService } from "./alarm.ts";
32
- import {
33
- ConversationObjectIdentity,
34
- DurableObjectContext,
35
- type ConversationObjectNamespace,
36
- } from "./bindings.ts";
37
- import {
38
- CLOUDFLARE_RUNTIME_DEFAULTS,
39
- CloudflareDurableRuntimeConfig,
40
- CloudflareDurableRuntimeConfigValue,
41
- CloudflarePlatformConfigError,
42
- } from "./config.ts";
43
- import { conversationPortTransportLayer } from "./transport.ts";
44
- import { cloudflareWakeSchedulerLayer } from "./wake-scheduler.ts";
45
-
46
- /**
47
- * Raw (unvalidated) construction options for `CloudflareDurableRuntime.layer`, mirroring
48
- * `NodeDurableRuntimeOptions`. Optional fields default to the documented production values
49
- * (`CLOUDFLARE_RUNTIME_DEFAULTS`); everything is schema-decoded into
50
- * `CloudflareDurableRuntimeConfigValue` before any resource opens (deployment §5 gate 1).
51
- */
52
- export interface CloudflareDurableRuntimeOptions {
53
- readonly deploymentId: string;
54
- /** Head of the minted producer identity `{producerPrefix}:{conversationId}`. */
55
- readonly producerPrefix: string;
56
- /** Milliseconds; default 30s (D5). */
57
- readonly ownershipLeaseDuration?: number | undefined;
58
- /** Milliseconds; default 100. */
59
- readonly alarmBackoffBase?: number | undefined;
60
- /** Milliseconds; default 5000. */
61
- readonly alarmBackoffCap?: number | undefined;
62
- /** Milliseconds; default 1000. Bounds every alarm re-arm delay. */
63
- readonly wakeScanInterval?: number | undefined;
64
- /** Milliseconds; default 500. */
65
- readonly settlementPollInterval?: number | undefined;
66
- /** Milliseconds; default 10000. */
67
- readonly leaseRenewalInterval?: number | undefined;
68
- /** Milliseconds; default 500. */
69
- readonly abortPollInterval?: number | undefined;
70
- /** Milliseconds; default 25. */
71
- readonly observationPollInterval?: number | undefined;
72
- /**
73
- * Milliseconds; default 2000. Cooperative budget for the background exporter flush registered
74
- * after each native RPC, wake, or alarm span. Delivery never awaits the flush.
75
- */
76
- readonly telemetryFlushTimeout?: number | undefined;
77
- /** Bytes; default just under the 2 MB platform value limit. */
78
- readonly maxStoredValueBytes?: number | undefined;
79
- /** Default false. */
80
- readonly verifyOnOpen?: boolean | undefined;
81
- /** Nonterminal Submissions per lane before admission refuses; default 256. */
82
- readonly maxQueueDepthPerLane?: number | undefined;
83
- /** Encoded input bytes per Submission; default = the stored-value bound. */
84
- readonly maxInputBytes?: number | undefined;
85
- /** `ctx.storage.sql.databaseSize` ceiling at admission; default 9 GB (10 GB platform cap). */
86
- readonly maxDatabaseBytes?: number | undefined;
87
- /**
88
- * Durable Object storage fault injection (`ledger:*` / `append:*` locations). Handlers are
89
- * constructed per incarnation WITH the live `DurableObjectState`, so eviction harnesses can
90
- * map an armed hit to `ctx.abort()` — the platform's real failure mode. Default none.
91
- */
92
- readonly storageFailpoint?: ((ctx: DurableObjectState) => DoStorageFailpointHandler) | undefined;
93
- /** Coordinator fault injection (`submit:*` / `terminalize:*` locations); default none. */
94
- readonly runtimeFailpoint?:
95
- | ((ctx: DurableObjectState) => DurableRuntimeFailpointHandler)
96
- | undefined;
97
- /**
98
- * Reconciliation policy consulted for open ordinary Tool Calls before an Unknown Outcome
99
- * is recorded (durability §10, DUR-009). Defaults to the fail-closed
100
- * `ToolReconciler.uncertain`.
101
- */
102
- readonly toolReconciler?: Layer.Layer<ToolReconciler> | undefined;
103
- /**
104
- * Registered worker Bindings resolved at durable claim time (S2, spec/subagents.md §11):
105
- * build each with `DurableWorkerBinding.make(binding, digests)`. An Effect or callback form is
106
- * accepted because capture can be effectful. The callback receives the live Object context and
107
- * derived identities and is evaluated once per incarnation during Layer construction. Defaults
108
- * to the empty registration (every resolved claim fails closed).
109
- */
110
- readonly bindings?: CloudflareBindingSource | undefined;
111
- }
112
-
113
- /** Per-incarnation host values available while registered worker Bindings are captured. */
114
- export interface CloudflareBindingSourceContext {
115
- readonly ctx: DurableObjectState;
116
- readonly env: unknown;
117
- readonly conversationId: ConversationId;
118
- readonly producerId: ProducerId;
119
- }
120
-
121
- /**
122
- * Registered worker Bindings, or a closed Effect/callback that captures them once for each
123
- * Durable Object incarnation. Callback Effects cannot require services or fail typed.
124
- */
125
- export type CloudflareBindingSource =
126
- | ReadonlyArray<ResolvedBinding>
127
- | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>
128
- | ((
129
- context: CloudflareBindingSourceContext,
130
- ) =>
131
- | ReadonlyArray<ResolvedBinding>
132
- | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>);
133
-
134
- /** Every construction failure of the assembled Cloudflare durable runtime stack. */
135
- export type CloudflareDurableRuntimeInitializationError =
136
- | CloudflarePlatformConfigError
137
- | DoStorageInitializationError;
138
-
139
- /** The services `CloudflareDurableRuntime.layer` provides. */
140
- export type CloudflareDurableRuntimeServices =
141
- | DurableAgentRuntime
142
- | SubmissionLedger
143
- | ConversationStore
144
- | WakeScheduler
145
- | DurableRuntimeConfig
146
- | AgentBindingResolver
147
- | CloudflareDurableRuntimeConfig
148
- | ConversationObjectIdentity
149
- | DurableAlarmService
150
- | ConversationMaintenance
151
- | ConversationObjectPorts;
152
-
153
- /**
154
- * Owner-side endpoint body for the Conversation Object's `portCall` (plan §1.3): decode,
155
- * execute against THIS Object's LOCAL port facets — never the routed decorators, so a
156
- * request cannot bounce between Objects — and answer the encoded response envelope. Total by
157
- * construction (protocol anomalies answer `PortFailed(PortProtocolError)`).
158
- */
159
- export class ConversationObjectPorts extends Context.Service<
160
- ConversationObjectPorts,
161
- {
162
- readonly handle: (encoded: unknown) => Effect.Effect<unknown>;
163
- }
164
- >()("@effect-agent/platform-cloudflare/ConversationObjectPorts") {}
165
-
166
- const decodeConfigValue = Schema.decodeUnknownEffect(CloudflareDurableRuntimeConfigValue);
167
- const decodeConversationId = Schema.decodeUnknownEffect(ConversationId);
168
- const decodeProducerId = Schema.decodeUnknownEffect(ProducerId);
169
-
170
- const configFromOptions = (
171
- options: CloudflareDurableRuntimeOptions,
172
- ): Effect.Effect<CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError> =>
173
- decodeConfigValue({
174
- deploymentId: options.deploymentId,
175
- producerPrefix: options.producerPrefix,
176
- ownershipLeaseDuration:
177
- options.ownershipLeaseDuration ?? CLOUDFLARE_RUNTIME_DEFAULTS.ownershipLeaseDuration,
178
- alarmBackoffBase: options.alarmBackoffBase ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffBase,
179
- alarmBackoffCap: options.alarmBackoffCap ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffCap,
180
- wakeScanInterval: options.wakeScanInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.wakeScanInterval,
181
- settlementPollInterval:
182
- options.settlementPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.settlementPollInterval,
183
- leaseRenewalInterval:
184
- options.leaseRenewalInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.leaseRenewalInterval,
185
- abortPollInterval: options.abortPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.abortPollInterval,
186
- observationPollInterval:
187
- options.observationPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.observationPollInterval,
188
- telemetryFlushTimeout:
189
- options.telemetryFlushTimeout ?? CLOUDFLARE_RUNTIME_DEFAULTS.telemetryFlushTimeout,
190
- maxStoredValueBytes:
191
- options.maxStoredValueBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxStoredValueBytes,
192
- verifyOnOpen: options.verifyOnOpen ?? CLOUDFLARE_RUNTIME_DEFAULTS.verifyOnOpen,
193
- limits: {
194
- maxQueueDepthPerLane:
195
- options.maxQueueDepthPerLane ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxQueueDepthPerLane,
196
- maxInputBytes: Math.min(
197
- options.maxInputBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxInputBytes,
198
- options.maxStoredValueBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxStoredValueBytes,
199
- ),
200
- maxDatabaseBytes: options.maxDatabaseBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxDatabaseBytes,
201
- },
202
- }).pipe(
203
- Effect.mapError((error) =>
204
- CloudflarePlatformConfigError.make({
205
- message: `Invalid Cloudflare durable runtime configuration: ${error.message}`,
206
- cause: error,
207
- }),
208
- ),
209
- );
210
-
211
- /**
212
- * The Conversation this Object owns, from the Object identity rule (plan §1.2): Conversation
213
- * Objects are addressed exclusively by `idFromName(conversationId)`, so `ctx.id.name` IS the
214
- * Conversation ID. An unnamed Object (from `newUniqueId`) is a deployment error, not a lane.
215
- */
216
- const conversationIdFromState = (
217
- ctx: DurableObjectState,
218
- ): Effect.Effect<ConversationId, CloudflarePlatformConfigError> =>
219
- ctx.id.name === undefined
220
- ? Effect.fail(
221
- CloudflarePlatformConfigError.make({
222
- message:
223
- "This Durable Object was not created via idFromName(conversationId); Conversation " +
224
- "Objects must be addressed by their Conversation identity (plan §1.2).",
225
- }),
226
- )
227
- : decodeConversationId(ctx.id.name).pipe(
228
- Effect.mapError((error) =>
229
- CloudflarePlatformConfigError.make({
230
- message: `The Durable Object name is not a valid ConversationId: ${error.message}`,
231
- cause: error,
232
- }),
233
- ),
234
- );
235
-
236
- const resolveBindings = (
237
- source: CloudflareDurableRuntimeOptions["bindings"],
238
- context: CloudflareBindingSourceContext,
239
- ): Effect.Effect<ReadonlyArray<ResolvedBinding>> =>
240
- source === undefined
241
- ? Effect.succeed([])
242
- : Effect.isEffect(source)
243
- ? source
244
- : typeof source === "function"
245
- ? Effect.suspend(() => {
246
- const bindings = source(context);
247
- return Effect.isEffect(bindings) ? bindings : Effect.succeed(bindings);
248
- })
249
- : Effect.succeed(source);
250
-
251
- /**
252
- * The DC Layer assembly (deployment §12: a Layer-assembly library, not an app entrypoint;
253
- * plan §1.4). `layer(options)` decodes the configuration, derives this Object's Conversation
254
- * and producer identities, opens the Object's private SQLite database through
255
- * `@effect/sql-sqlite-do` for BOTH the Conversation Log and the Submission Ledger (so claims
256
- * fence the same producer epochs — ADR-0011 D7 transposed), wraps the local port facets with
257
- * the WP2 cross-Object routing decorators over the Durable Object RPC transport, wires the
258
- * alarm-backed wake scheduler and the maintenance pass, defaults reconciliation to the
259
- * fail-closed `ToolReconciler.uncertain`, and provides a ready `DurableAgentRuntime` on top.
260
- *
261
- * Storage compatibility is verified during construction: an incompatible database fails the
262
- * Layer typed (`DoStorageCompatibilityError`) before anything is mutated (DEPLOY-008).
263
- *
264
- * Requires the two binding services (`DurableObjectContext`, `ConversationObjectNamespace`).
265
- * Host observability belongs to the Worker composition edge because native entrypoint lifecycle
266
- * instrumentation, rather than this durable runtime assembly, consumes it (DEPLOY-010).
267
- */
268
- export class CloudflareDurableRuntime {
269
- static layer(
270
- options: CloudflareDurableRuntimeOptions,
271
- ): Layer.Layer<
272
- CloudflareDurableRuntimeServices,
273
- CloudflareDurableRuntimeInitializationError,
274
- DurableObjectContext | ConversationObjectNamespace
275
- > {
276
- return Layer.unwrap(
277
- Effect.gen(function* () {
278
- const { ctx, env } = yield* DurableObjectContext;
279
- const config = yield* configFromOptions(options);
280
- const conversationId = yield* conversationIdFromState(ctx);
281
- const producerId = yield* decodeProducerId(
282
- `${config.producerPrefix}:${conversationId}`,
283
- ).pipe(
284
- Effect.mapError((error) =>
285
- CloudflarePlatformConfigError.make({
286
- message: `The minted producer identity is invalid: ${error.message}`,
287
- cause: error,
288
- }),
289
- ),
290
- );
291
-
292
- const identityLayer = Layer.succeed(ConversationObjectIdentity)({
293
- conversationId,
294
- producerId,
295
- });
296
- const cloudflareConfigLayer = Layer.succeed(CloudflareDurableRuntimeConfig)(config);
297
-
298
- const storageOptions: DoStorageOptions = {
299
- storage: ctx.storage,
300
- observationPollInterval: config.observationPollInterval,
301
- ownershipLeaseDuration: config.ownershipLeaseDuration,
302
- maxStoredValueBytes: config.maxStoredValueBytes,
303
- verifyOnOpen: config.verifyOnOpen,
304
- failpoint: options.storageFailpoint?.(ctx),
305
- };
306
- const infrastructure = Layer.mergeAll(
307
- storageConfigLayer(storageOptions),
308
- storageFailpointLayer(storageOptions),
309
- SqliteClient.layer({ storage: ctx.storage }),
310
- BrowserCrypto.layer,
311
- );
312
-
313
- /**
314
- * ONE local-facet instance (a shared Layer value) serves both the routed decorators
315
- * and the owner-side `portCall` executor — the executor must never see the routed
316
- * ports (plan §1.3: re-routing could bounce a request between Objects).
317
- */
318
- const localPorts = Layer.mergeAll(conversationStoreLayer, submissionLedgerLayer).pipe(
319
- Layer.provide(infrastructure),
320
- );
321
-
322
- const portsEndpointLayer = Layer.effect(ConversationObjectPorts)(
323
- Effect.gen(function* () {
324
- const local = yield* Effect.context<SubmissionLedger | ConversationStore>();
325
- return ConversationObjectPorts.of({
326
- handle: (encoded) => handleEncodedPortRequest(encoded).pipe(Effect.provide(local)),
327
- });
328
- }),
329
- ).pipe(Layer.provide(localPorts));
330
-
331
- const routedPorts = Layer.mergeAll(
332
- routedSubmissionLedgerLayer({ localConversationId: conversationId }),
333
- routedConversationStoreLayer({ localConversationId: conversationId }),
334
- ).pipe(Layer.provide(localPorts), Layer.provide(conversationPortTransportLayer));
335
-
336
- const runtimeConfigLayer = Layer.succeed(DurableRuntimeConfig)(
337
- DurableRuntimeConfig.make({
338
- deploymentId: config.deploymentId,
339
- producerId,
340
- settlementPollInterval: Duration.millis(config.settlementPollInterval),
341
- leaseRenewalInterval: Duration.millis(config.leaseRenewalInterval),
342
- abortPollInterval: Duration.millis(config.abortPollInterval),
343
- }),
344
- );
345
-
346
- const runtimeFailpointLayer =
347
- options.runtimeFailpoint === undefined
348
- ? DurableRuntimeFailpoint.layer
349
- : Layer.succeed(DurableRuntimeFailpoint)({ hit: options.runtimeFailpoint(ctx) });
350
- const reconcilerLayer = options.toolReconciler ?? ToolReconciler.uncertain;
351
- const bindingResolverLayer = Layer.effect(AgentBindingResolver)(
352
- Effect.map(
353
- resolveBindings(options.bindings, { ctx, env, conversationId, producerId }),
354
- (bindings) => AgentBindingResolver.fromBindings(bindings),
355
- ),
356
- );
357
-
358
- const base = Layer.mergeAll(
359
- identityLayer,
360
- cloudflareConfigLayer,
361
- DurableAlarmService.layer,
362
- );
363
-
364
- const runtimeStack = DurableAgentRuntime.layer.pipe(
365
- Layer.provideMerge(routedPorts),
366
- Layer.provideMerge(cloudflareWakeSchedulerLayer),
367
- Layer.provideMerge(runtimeConfigLayer),
368
- Layer.provideMerge(bindingResolverLayer),
369
- Layer.provide(
370
- Layer.mergeAll(runtimeFailpointLayer, reconcilerLayer, BrowserCrypto.layer),
371
- ),
372
- Layer.provideMerge(base),
373
- );
374
-
375
- const application = Layer.mergeAll(
376
- runtimeStack,
377
- ConversationMaintenance.layer.pipe(Layer.provide(runtimeStack)),
378
- portsEndpointLayer,
379
- );
380
-
381
- return application;
382
- }),
383
- );
384
- }
385
- }