effect-cf 0.13.0 → 0.14.0

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.
package/dist/index.mjs CHANGED
@@ -1,14 +1,236 @@
1
1
  import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { a as WorkerConfig, i as layer$10, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
3
- import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
2
+ import { a as WorkerConfig, i as layer$15, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
3
+ import { Cause, Clock, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
4
4
  import { FetchHttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
5
- import { Otlp, OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
5
+ import { OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
6
6
  import { D1Client } from "@effect/sql-d1";
7
7
  import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
8
8
  import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
9
9
  import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
10
10
  import * as RpcServer from "effect/unstable/rpc/RpcServer";
11
11
  import { SqliteClient } from "@effect/sql-sqlite-do";
12
+ //#region src/WorkersAi.ts
13
+ var WorkersAi_exports = /* @__PURE__ */ __exportAll({
14
+ Tag: () => Tag$14,
15
+ WorkersAiOperationError: () => WorkersAiOperationError,
16
+ embeddingResponse: () => embeddingResponse,
17
+ isWorkersAiBinding: () => isWorkersAiBinding,
18
+ layer: () => layer$14,
19
+ make: () => make$14,
20
+ makeClient: () => makeClient$10
21
+ });
22
+ const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
23
+ /** Error raised when a Workers AI operation fails. */
24
+ var WorkersAiOperationError = class extends Data.TaggedError("WorkersAiOperationError") {};
25
+ const workersAiError = (binding, operation, cause) => new WorkersAiOperationError({
26
+ binding,
27
+ operation,
28
+ cause
29
+ });
30
+ const tryWorkersAiPromise = (binding, operation, evaluate) => Effect.tryPromise({
31
+ try: evaluate,
32
+ catch: (cause) => workersAiError(binding, operation, cause)
33
+ });
34
+ const tryWorkersAiSync = (binding, operation, evaluate) => Effect.try({
35
+ try: evaluate,
36
+ catch: (cause) => workersAiError(binding, operation, cause)
37
+ });
38
+ const hasFunction$3 = (value, key) => typeof Reflect.get(value, key) === "function";
39
+ const isWorkersAiBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "run") && hasFunction$3(value, "gateway") && hasFunction$3(value, "models");
40
+ const embeddingResponse = (value) => ({
41
+ data: value.data ?? [],
42
+ shape: value.shape ?? []
43
+ });
44
+ const makeClient$10 = (definition) => (ai) => {
45
+ const run = ((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => ai.run(model, input, options)));
46
+ return {
47
+ definition,
48
+ aiGatewayLogId: tryWorkersAiSync(definition.binding, "aiGatewayLogId", () => ai.aiGatewayLogId),
49
+ run,
50
+ runEmbedding: (model, input, options) => run(model, input, options).pipe(Effect.map((response) => embeddingResponse(response))),
51
+ models: (params) => tryWorkersAiPromise(definition.binding, "models", () => ai.models(params)),
52
+ gateway: (gatewayId) => tryWorkersAiSync(definition.binding, "gateway", () => ai.gateway(gatewayId)),
53
+ unsafeRaw: Effect.succeed(ai)
54
+ };
55
+ };
56
+ const layer$14 = (tag, definition) => layer$15(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$10(definition), { expected: expectedWorkersAiBinding });
57
+ const make$14 = (id) => Tag$14()(id);
58
+ const Tag$14 = () => (id) => {
59
+ const tag = Context.Service()(id);
60
+ const makeLayer = (definition) => layer$14(tag, definition);
61
+ return Object.assign(tag, {
62
+ id,
63
+ layer: makeLayer
64
+ });
65
+ };
66
+ //#endregion
67
+ //#region src/AiGateway.ts
68
+ var AiGateway_exports = /* @__PURE__ */ __exportAll({
69
+ AiGatewayOperationError: () => AiGatewayOperationError,
70
+ Tag: () => Tag$13,
71
+ isAiGatewayBinding: () => isAiGatewayBinding,
72
+ layer: () => layer$13,
73
+ make: () => make$13,
74
+ makeClient: () => makeClient$9,
75
+ makeClientFromAi: () => makeClientFromAi,
76
+ makeHttpClient: () => makeHttpClient
77
+ });
78
+ const expectedAiGatewayBinding = "Workers AI binding with gateway()";
79
+ /** Error raised when an AI Gateway operation fails. */
80
+ var AiGatewayOperationError = class extends Data.TaggedError("AiGatewayOperationError") {};
81
+ const aiGatewayError = (binding, operation, cause) => new AiGatewayOperationError({
82
+ binding,
83
+ operation,
84
+ cause
85
+ });
86
+ const tryAiGatewayPromise = (binding, operation, evaluate) => Effect.tryPromise({
87
+ try: evaluate,
88
+ catch: (cause) => aiGatewayError(binding, operation, cause)
89
+ });
90
+ const tryAiGatewaySync = (binding, operation, evaluate) => Effect.try({
91
+ try: evaluate,
92
+ catch: (cause) => aiGatewayError(binding, operation, cause)
93
+ });
94
+ const providerUrl = (baseUrl, path = "") => {
95
+ const url = new URL(baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`);
96
+ const normalizedPath = path.replace(/^\/+/, "");
97
+ return normalizedPath === "" ? url : new URL(normalizedPath, url);
98
+ };
99
+ const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
100
+ const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
101
+ const makeClient$9 = (definition, gateway) => ({
102
+ definition,
103
+ run: (data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options)),
104
+ getUrl: (provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider)),
105
+ fetch: (options) => Effect.gen(function* () {
106
+ const baseUrl = yield* tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(options.provider));
107
+ return yield* tryAiGatewayPromise(definition.binding, "fetch", () => fetch(providerUrl(baseUrl, options.path).href, options.init));
108
+ }),
109
+ patchLog: (logId, data) => tryAiGatewayPromise(definition.binding, "patchLog", () => gateway.patchLog(logId, data)),
110
+ getLog: (logId) => tryAiGatewayPromise(definition.binding, "getLog", () => gateway.getLog(logId)),
111
+ unsafeRaw: Effect.succeed(gateway)
112
+ });
113
+ const makeClientFromAi = (definition, ai) => {
114
+ const gateway = tryAiGatewaySync(definition.binding, "gateway", () => ai.gateway(definition.gatewayId));
115
+ const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
116
+ return {
117
+ definition,
118
+ run: (data, options) => withGateway((raw) => makeClient$9(definition, raw).run(data, options)),
119
+ getUrl: (provider) => withGateway((raw) => makeClient$9(definition, raw).getUrl(provider)),
120
+ fetch: (options) => withGateway((raw) => makeClient$9(definition, raw).fetch(options)),
121
+ patchLog: (logId, data) => withGateway((raw) => makeClient$9(definition, raw).patchLog(logId, data)),
122
+ getLog: (logId) => withGateway((raw) => makeClient$9(definition, raw).getLog(logId)),
123
+ unsafeRaw: gateway
124
+ };
125
+ };
126
+ const makeHttpClient = (definition, request = fetch) => {
127
+ const binding = definition.binding ?? "AI_GATEWAY";
128
+ const clientDefinition = {
129
+ binding,
130
+ gatewayId: definition.gatewayId,
131
+ accountId: definition.accountId
132
+ };
133
+ const getUrl = (provider) => Effect.succeed(provider === void 0 ? gatewayUrl(definition) : providerUrl(gatewayUrl(definition), provider).href.replace(/\/$/, ""));
134
+ const extraHeaders = (options) => {
135
+ if (options?.extraHeaders === void 0 || Array.isArray(options.extraHeaders) || options.extraHeaders instanceof Headers) return options?.extraHeaders;
136
+ return Object.fromEntries(Object.entries(options.extraHeaders).map(([key, value]) => [key, String(value)]));
137
+ };
138
+ return {
139
+ definition: clientDefinition,
140
+ run: (data, options) => tryAiGatewayPromise(binding, "run", () => request(gatewayUrl(definition), {
141
+ method: "POST",
142
+ body: JSON.stringify(data),
143
+ headers: new Headers({
144
+ "content-type": "application/json",
145
+ ...Object.fromEntries(new Headers(extraHeaders(options)).entries())
146
+ }),
147
+ signal: options?.signal
148
+ })),
149
+ getUrl,
150
+ fetch: (options) => getUrl(options.provider).pipe(Effect.flatMap((baseUrl) => tryAiGatewayPromise(binding, "fetch", () => request(providerUrl(baseUrl, options.path).href, options.init)))),
151
+ patchLog: (logId, data) => tryAiGatewayPromise(binding, "patchLog", () => request(providerUrl(gatewayUrl(definition), `logs/${logId}`).href, {
152
+ method: "PATCH",
153
+ body: JSON.stringify(data),
154
+ headers: { "content-type": "application/json" }
155
+ }).then(() => void 0)),
156
+ getLog: (logId) => tryAiGatewayPromise(binding, "getLog", async () => {
157
+ return await (await request(providerUrl(gatewayUrl(definition), `logs/${logId}`).href)).json();
158
+ }),
159
+ unsafeRaw: Effect.fail(aiGatewayError(binding, "unsafeRaw", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
160
+ };
161
+ };
162
+ const layer$13 = (tag, definition) => layer$15(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
163
+ const make$13 = (id) => Tag$13()(id);
164
+ const Tag$13 = () => (id) => {
165
+ const tag = Context.Service()(id);
166
+ const makeLayer = (definition) => layer$13(tag, definition);
167
+ return Object.assign(tag, {
168
+ id,
169
+ layer: makeLayer
170
+ });
171
+ };
172
+ //#endregion
173
+ //#region src/BrowserRendering.ts
174
+ var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
175
+ BrowserRenderingOperationError: () => BrowserRenderingOperationError,
176
+ Tag: () => Tag$12,
177
+ isBrowserRenderingBinding: () => isBrowserRenderingBinding,
178
+ layer: () => layer$12,
179
+ make: () => make$12,
180
+ makeClient: () => makeClient$8
181
+ });
182
+ const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
183
+ /** Error raised when a Browser Rendering operation fails. */
184
+ var BrowserRenderingOperationError = class extends Data.TaggedError("BrowserRenderingOperationError") {};
185
+ const browserRenderingError = (binding, operation, cause) => new BrowserRenderingOperationError({
186
+ binding,
187
+ operation,
188
+ cause
189
+ });
190
+ const tryBrowserRenderingPromise = (binding, operation, evaluate) => Effect.tryPromise({
191
+ try: evaluate,
192
+ catch: (cause) => browserRenderingError(binding, operation, cause)
193
+ });
194
+ const tryBrowserRenderingSync = (binding, operation, evaluate) => Effect.try({
195
+ try: evaluate,
196
+ catch: (cause) => browserRenderingError(binding, operation, cause)
197
+ });
198
+ const missingMethod = (binding, operation) => Effect.fail(browserRenderingError(binding, operation, /* @__PURE__ */ new TypeError(`Browser Rendering object does not expose ${operation}()`)));
199
+ const wrapPage = (binding, page) => ({
200
+ raw: page,
201
+ goto: (url, options) => page.goto === void 0 ? missingMethod(binding, "goto") : tryBrowserRenderingPromise(binding, "goto", () => page.goto(url, options)),
202
+ setContent: (html, options) => page.setContent === void 0 ? missingMethod(binding, "setContent") : tryBrowserRenderingPromise(binding, "setContent", () => page.setContent(html, options)),
203
+ content: page.content === void 0 ? missingMethod(binding, "content") : tryBrowserRenderingPromise(binding, "content", () => page.content()),
204
+ screenshot: (options) => page.screenshot === void 0 ? missingMethod(binding, "screenshot") : tryBrowserRenderingPromise(binding, "screenshot", () => page.screenshot(options)),
205
+ pdf: (options) => page.pdf === void 0 ? missingMethod(binding, "pdf") : tryBrowserRenderingPromise(binding, "pdf", () => page.pdf(options)),
206
+ evaluate: (pageFunction, ...args) => page.evaluate === void 0 ? missingMethod(binding, "evaluate") : tryBrowserRenderingPromise(binding, "evaluate", () => page.evaluate(pageFunction, ...args)),
207
+ close: (options) => page.close === void 0 ? Effect.void : tryBrowserRenderingPromise(binding, "closePage", () => page.close(options))
208
+ });
209
+ const wrapBrowser = (binding, browser) => ({
210
+ raw: browser,
211
+ newPage: tryBrowserRenderingPromise(binding, "newPage", () => browser.newPage()).pipe(Effect.map((page) => wrapPage(binding, page))),
212
+ version: browser.version === void 0 ? missingMethod(binding, "version") : tryBrowserRenderingPromise(binding, "version", () => browser.version()),
213
+ close: browser.close === void 0 ? Effect.void : tryBrowserRenderingPromise(binding, "closeBrowser", () => browser.close()),
214
+ disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
215
+ });
216
+ const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
217
+ const makeClient$8 = (definition) => (binding) => ({
218
+ definition,
219
+ launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
220
+ connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
221
+ unsafeRaw: Effect.succeed(binding)
222
+ });
223
+ const layer$12 = (tag, definition) => layer$15(tag, definition.binding, isBrowserRenderingBinding, makeClient$8(definition), { expected: expectedBrowserRenderingBinding });
224
+ const make$12 = (id) => Tag$12()(id);
225
+ const Tag$12 = () => (id) => {
226
+ const tag = Context.Service()(id);
227
+ const makeLayer = (definition) => layer$12(tag, definition);
228
+ return Object.assign(tag, {
229
+ id,
230
+ layer: makeLayer
231
+ });
232
+ };
233
+ //#endregion
12
234
  //#region src/DurableObjectStorage.ts
13
235
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
14
236
  StorageOperationError: () => StorageOperationError,
@@ -300,251 +522,77 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
300
522
  //#endregion
301
523
  //#region src/CloudflareOtlp.ts
302
524
  var CloudflareOtlp_exports = /* @__PURE__ */ __exportAll({
303
- CloudflareOtlpSettings: () => CloudflareOtlpSettings,
304
525
  durableObjectLayer: () => durableObjectLayer,
305
- layer: () => layer$9,
526
+ layer: () => layer$11,
306
527
  layerJson: () => layerJson,
307
528
  layerProtobuf: () => layerProtobuf,
308
- settingsConfig: () => settingsConfig,
309
- settingsLayer: () => settingsLayer,
310
529
  workerLayer: () => workerLayer
311
530
  });
312
- /**
313
- * Supported OpenTelemetry environment configuration for Cloudflare OTLP export.
314
- *
315
- * This config intentionally uses the conventional `OTEL_*` variable names so
316
- * deployments can share the same settings used by other OpenTelemetry SDKs.
317
- * It covers the OTLP HTTP settings supported by the Effect OTLP layers:
318
- *
319
- * - `OTEL_EXPORTER_OTLP_ENDPOINT`
320
- * - `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`
321
- * - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
322
- * - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
323
- * - `OTEL_EXPORTER_OTLP_HEADERS`
324
- * - `OTEL_EXPORTER_OTLP_LOGS_HEADERS`
325
- * - `OTEL_EXPORTER_OTLP_TRACES_HEADERS`
326
- * - `OTEL_EXPORTER_OTLP_METRICS_HEADERS`
327
- * - `OTEL_SERVICE_NAME`
328
- * - `OTEL_RESOURCE_ATTRIBUTES`
329
- *
330
- * `OTEL_SERVICE_VERSION` is also accepted as an effect-cf convenience alias.
331
- * The standard OpenTelemetry way to configure service version is
332
- * `OTEL_RESOURCE_ATTRIBUTES=service.version=...`.
333
- *
334
- * Consumers with non-standard binding names should map those names into
335
- * {@link CloudflareOtlpSettings} rather than changing this config globally.
336
- */
337
- const settingsConfig = Config.all({
338
- endpoint: Config.string("OTEL_EXPORTER_OTLP_ENDPOINT").pipe(Config.option),
339
- logsEndpoint: Config.string("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT").pipe(Config.option),
340
- tracesEndpoint: Config.string("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT").pipe(Config.option),
341
- metricsEndpoint: Config.string("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT").pipe(Config.option),
342
- headers: Config.string("OTEL_EXPORTER_OTLP_HEADERS").pipe(Config.option),
343
- logsHeaders: Config.string("OTEL_EXPORTER_OTLP_LOGS_HEADERS").pipe(Config.option),
344
- tracesHeaders: Config.string("OTEL_EXPORTER_OTLP_TRACES_HEADERS").pipe(Config.option),
345
- metricsHeaders: Config.string("OTEL_EXPORTER_OTLP_METRICS_HEADERS").pipe(Config.option),
346
- serviceName: Config.string("OTEL_SERVICE_NAME").pipe(Config.option),
347
- serviceVersion: Config.string("OTEL_SERVICE_VERSION").pipe(Config.option),
348
- resourceAttributes: Config.schema(Config.Record(Schema.String, Schema.String), "OTEL_RESOURCE_ATTRIBUTES").pipe(Config.option)
349
- });
350
- /**
351
- * Service carrying already-resolved Cloudflare OTLP settings.
352
- *
353
- * Provide this service directly when an application needs to map custom
354
- * Cloudflare binding names, compute settings dynamically, or override settings
355
- * in tests. When this service is present, the OTLP layers use it instead of
356
- * reading {@link settingsConfig}.
357
- *
358
- * @example
359
- * ```ts
360
- * const CustomOtlpSettings = Layer.effect(
361
- * CloudflareOtlp.CloudflareOtlpSettings,
362
- * Config.all({
363
- * ...CloudflareOtlp.settingsConfig,
364
- * endpoint: Config.string("MY_OTLP_ENDPOINT").pipe(Config.option),
365
- * }),
366
- * ).pipe(Layer.provide(WorkerConfig.layer));
367
- * ```
368
- */
369
- var CloudflareOtlpSettings = class extends Context.Service()("effect-cf/CloudflareOtlpSettings") {};
370
531
  const allSignals = [
371
532
  "logs",
372
533
  "traces",
373
534
  "metrics"
374
535
  ];
375
- const optionToUndefined = (option) => Option.isSome(option) ? option.value : void 0;
376
- const nonEmptyStringOption = (option) => Option.flatMap(option, (value) => {
377
- const trimmed = value.trim();
378
- return trimmed === "" ? Option.none() : Option.some(trimmed);
379
- });
380
- const nonEmptyRecordOption = (option) => Option.filter(option, (value) => Object.keys(value).length > 0);
381
- const normalizeSettings = (settings) => ({
382
- endpoint: nonEmptyStringOption(settings.endpoint),
383
- logsEndpoint: nonEmptyStringOption(settings.logsEndpoint),
384
- tracesEndpoint: nonEmptyStringOption(settings.tracesEndpoint),
385
- metricsEndpoint: nonEmptyStringOption(settings.metricsEndpoint),
386
- headers: nonEmptyStringOption(settings.headers),
387
- logsHeaders: nonEmptyStringOption(settings.logsHeaders),
388
- tracesHeaders: nonEmptyStringOption(settings.tracesHeaders),
389
- metricsHeaders: nonEmptyStringOption(settings.metricsHeaders),
390
- serviceName: nonEmptyStringOption(settings.serviceName),
391
- serviceVersion: nonEmptyStringOption(settings.serviceVersion),
392
- resourceAttributes: nonEmptyRecordOption(settings.resourceAttributes)
393
- });
394
- /**
395
- * Layer that reads standard OpenTelemetry settings from the current Cloudflare
396
- * `env` object.
397
- *
398
- * The layer depends on {@link WorkerEnvironment} and installs a
399
- * Cloudflare-backed Effect `ConfigProvider`, so `settingsConfig` reads from
400
- * Worker vars/secrets instead of Node process environment variables.
401
- */
402
- const settingsLayer = Layer.effect(CloudflareOtlpSettings, settingsConfig.pipe(Config.map(normalizeSettings))).pipe(Layer.provide(WorkerConfig.layer));
536
+ const emptyConfigProvider = ConfigProvider.fromUnknown({});
537
+ const cloudflareConfigProviderLayer = ConfigProvider.layerAdd(Effect.map(Effect.serviceOption(WorkerEnvironment), (env) => Option.isSome(env) ? WorkerConfig.providerFromEnv(env.value) : emptyConfigProvider), { asPrimary: true });
403
538
  const selectedSignals = (signals) => new Set(signals ?? allSignals);
404
539
  const withDefinedAttributes = (attributes) => {
405
540
  const out = {};
406
541
  for (const [key, value] of Object.entries(attributes)) if (value !== void 0) out[key] = value;
407
542
  return out;
408
543
  };
409
- const parseHeaders = (input) => {
410
- if (Option.isNone(input) || input.value.trim() === "") return;
411
- const headers = {};
412
- for (const part of input.value.split(",")) {
413
- const index = part.indexOf("=");
414
- if (index <= 0) continue;
415
- const key = part.slice(0, index).trim();
416
- const value = part.slice(index + 1).trim();
417
- if (key !== "") headers[decodeHeaderComponent(key)] = decodeHeaderComponent(value);
418
- }
419
- return headers;
420
- };
421
- const mergeHeaders = (common, signalSpecific) => {
422
- const commonHeaders = parseHeaders(common);
423
- const signalHeaders = parseHeaders(signalSpecific);
424
- if (commonHeaders === void 0 && signalHeaders === void 0) return;
425
- return {
426
- ...commonHeaders,
427
- ...signalHeaders
428
- };
429
- };
430
- const decodeHeaderComponent = (value) => {
431
- try {
432
- return decodeURIComponent(value);
433
- } catch {
434
- return value;
435
- }
436
- };
437
- const appendOtlpPath = (baseUrl, path) => `${baseUrl.replace(/\/+$/, "")}${path}`;
438
- const makeResource = (settings, options, runtimeAttributes) => ({
439
- serviceName: options.serviceName ?? optionToUndefined(settings.serviceName),
440
- serviceVersion: options.serviceVersion ?? optionToUndefined(settings.serviceVersion),
544
+ const makeResource = (options, runtimeAttributes) => ({
545
+ serviceName: options.resource?.serviceName,
546
+ serviceVersion: options.resource?.serviceVersion,
441
547
  attributes: {
442
- ...optionToUndefined(settings.resourceAttributes),
443
548
  ...withDefinedAttributes(runtimeAttributes),
444
- ...options.attributes
549
+ ...options.resource?.attributes
445
550
  }
446
551
  });
447
- const commonOtlpOptions = (settings, options, runtimeAttributes) => ({
448
- resource: makeResource(settings, options, runtimeAttributes),
449
- maxBatchSize: options.maxBatchSize,
450
- loggerExportInterval: options.loggerExportInterval,
451
- loggerExcludeLogSpans: options.loggerExcludeLogSpans,
452
- loggerMergeWithExisting: options.loggerMergeWithExisting,
453
- tracerExportInterval: options.tracerExportInterval,
454
- tracerContext: options.tracerContext,
455
- metricsExportInterval: options.metricsExportInterval,
456
- metricsTemporality: options.metricsTemporality,
457
- shutdownTimeout: options.shutdownTimeout
458
- });
459
552
  const serializationLayer = (serialization) => serialization === "json" ? OtlpSerialization.layerJson : OtlpSerialization.layerProtobuf;
460
- const resolveSettings = Effect.gen(function* () {
461
- const settings = yield* Effect.serviceOption(CloudflareOtlpSettings);
462
- if (Option.isSome(settings)) return normalizeSettings(settings.value);
463
- const env = yield* Effect.serviceOption(WorkerEnvironment);
464
- if (Option.isSome(env)) return normalizeSettings(yield* settingsConfig.pipe(Effect.provide(ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env.value))))));
465
- return normalizeSettings(yield* settingsConfig);
466
- });
467
553
  const mergeSignalLayers = (layers) => {
468
554
  if (layers.length === 0) return Layer.empty;
469
555
  let merged = layers[0];
470
556
  for (let index = 1; index < layers.length; index++) merged = Layer.mergeAll(merged, layers[index]);
471
557
  return merged;
472
558
  };
473
- const emptyLayer = Layer.empty;
474
- const makeLayerFromSettings = (options = {}, runtimeAttributes = {}) => Layer.unwrap(Effect.map(resolveSettings, (settings) => {
559
+ const makeLayer = (options = {}, runtimeAttributes = {}) => {
475
560
  const signals = selectedSignals(options.signals);
476
- const endpoint = optionToUndefined(settings.endpoint);
477
- const logsEndpoint = optionToUndefined(settings.logsEndpoint);
478
- const tracesEndpoint = optionToUndefined(settings.tracesEndpoint);
479
- const metricsEndpoint = optionToUndefined(settings.metricsEndpoint);
480
- const hasSpecificEndpoint = logsEndpoint !== void 0 || tracesEndpoint !== void 0 || metricsEndpoint !== void 0;
481
- const hasSpecificHeaders = Option.isSome(settings.logsHeaders) || Option.isSome(settings.tracesHeaders) || Option.isSome(settings.metricsHeaders);
482
- const common = commonOtlpOptions(settings, options, runtimeAttributes);
483
- if (endpoint !== void 0 && !hasSpecificEndpoint && !hasSpecificHeaders && signals.size === 3) return Otlp.layer({
484
- baseUrl: endpoint,
485
- headers: parseHeaders(settings.headers),
486
- ...common
487
- }).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer));
561
+ const resource = makeResource(options, runtimeAttributes);
488
562
  const layers = [];
489
- if (signals.has("logs")) {
490
- const url = logsEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/logs"));
491
- if (url !== void 0) layers.push(OtlpLogger.layer({
492
- url,
493
- resource: common.resource,
494
- headers: mergeHeaders(settings.headers, settings.logsHeaders),
495
- exportInterval: common.loggerExportInterval,
496
- maxBatchSize: common.maxBatchSize,
497
- shutdownTimeout: common.shutdownTimeout,
498
- excludeLogSpans: common.loggerExcludeLogSpans,
499
- mergeWithExisting: common.loggerMergeWithExisting
500
- }).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
501
- }
502
- if (signals.has("traces")) {
503
- const url = tracesEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/traces"));
504
- if (url !== void 0) layers.push(OtlpTracer.layer({
505
- url,
506
- resource: common.resource,
507
- headers: mergeHeaders(settings.headers, settings.tracesHeaders),
508
- exportInterval: common.tracerExportInterval,
509
- maxBatchSize: common.maxBatchSize,
510
- context: common.tracerContext,
511
- shutdownTimeout: common.shutdownTimeout
512
- }).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
513
- }
514
- if (signals.has("metrics")) {
515
- const url = metricsEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/metrics"));
516
- if (url !== void 0) layers.push(OtlpMetrics.layer({
517
- url,
518
- resource: common.resource,
519
- headers: mergeHeaders(settings.headers, settings.metricsHeaders),
520
- exportInterval: common.metricsExportInterval,
521
- shutdownTimeout: common.shutdownTimeout,
522
- temporality: common.metricsTemporality
523
- }).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
524
- }
525
- return mergeSignalLayers(layers);
526
- }).pipe(Effect.catch((error) => Effect.logWarning("CloudflareOtlp disabled because OTLP configuration is invalid", { error: String(error) }).pipe(Effect.as(emptyLayer)))));
527
- const makeLayer = (options = {}, runtimeAttributes = {}) => makeLayerFromSettings(options, runtimeAttributes);
563
+ if (signals.has("logs")) layers.push(OtlpLogger.layerFromConfig({
564
+ resource,
565
+ headers: options.headers,
566
+ excludeLogSpans: options.loggerExcludeLogSpans,
567
+ mergeWithExisting: options.loggerMergeWithExisting
568
+ }));
569
+ if (signals.has("traces")) layers.push(OtlpTracer.layerFromConfig({
570
+ resource,
571
+ headers: options.headers,
572
+ context: options.tracerContext
573
+ }));
574
+ if (signals.has("metrics")) layers.push(OtlpMetrics.layerFromConfig({
575
+ resource,
576
+ headers: options.headers
577
+ }));
578
+ return mergeSignalLayers(layers).pipe(Layer.provide(cloudflareConfigProviderLayer), Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer));
579
+ };
528
580
  /**
529
581
  * Base OTLP telemetry layer for Cloudflare-compatible runtimes.
530
582
  *
531
- * The layer reads {@link CloudflareOtlpSettings} when provided. Otherwise it
532
- * reads standard OpenTelemetry config from `WorkerEnvironment` when available,
533
- * then falls back to the ambient Effect `ConfigProvider`.
534
- *
535
- * When only `OTEL_EXPORTER_OTLP_ENDPOINT` is configured, per-signal paths are
536
- * derived by appending `/v1/logs`, `/v1/traces`, and `/v1/metrics`. Signal
537
- * specific endpoints are used as-is, matching the OpenTelemetry OTLP exporter
538
- * convention.
583
+ * Standard OpenTelemetry environment variables are resolved by Effect's OTLP
584
+ * layers. In Cloudflare Workers and Durable Objects, the current `env` object is
585
+ * installed as the primary `ConfigProvider`; outside Cloudflare, the ambient
586
+ * Effect `ConfigProvider` remains the fallback.
539
587
  */
540
- const layer$9 = (options = {}) => makeLayer(options);
588
+ const layer$11 = (options = {}) => makeLayer(options);
541
589
  /** Base OTLP telemetry layer forced to JSON serialization. */
542
- const layerJson = (options = {}) => layer$9({
590
+ const layerJson = (options = {}) => layer$11({
543
591
  ...options,
544
592
  serialization: "json"
545
593
  });
546
594
  /** Base OTLP telemetry layer forced to protobuf serialization. */
547
- const layerProtobuf = (options = {}) => layer$9({
595
+ const layerProtobuf = (options = {}) => layer$11({
548
596
  ...options,
549
597
  serialization: "protobuf"
550
598
  });
@@ -574,7 +622,7 @@ const durableObjectLayer = (options = {}) => Layer.unwrap(Effect.map(DurableObje
574
622
  //#region src/D1.ts
575
623
  var D1_exports = /* @__PURE__ */ __exportAll({
576
624
  Service: () => Service$1,
577
- make: () => make$10
625
+ make: () => make$11
578
626
  });
579
627
  const TypeId$2 = "effect-cf/D1";
580
628
  const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
@@ -586,7 +634,7 @@ const isD1Database = (value) => {
586
634
  /**
587
635
  * Creates a typed D1 service tag plus Effect helpers.
588
636
  */
589
- const make$10 = (id, definition) => Service$1()(id, definition);
637
+ const make$11 = (id, definition) => Service$1()(id, definition);
590
638
  /**
591
639
  * Builds a D1 service around a Cloudflare D1 database binding.
592
640
  *
@@ -622,8 +670,8 @@ const Service$1 = () => (id, definition) => {
622
670
  var QueueBinding_exports = /* @__PURE__ */ __exportAll({
623
671
  QueueOperationError: () => QueueOperationError,
624
672
  isQueue: () => isQueue,
625
- layer: () => layer$8,
626
- makeClient: () => makeClient$6
673
+ layer: () => layer$10,
674
+ makeClient: () => makeClient$7
627
675
  });
628
676
  const expectedQueueProducer = "Queue producer binding with send(); optional sendBatch()/metrics()";
629
677
  var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
@@ -640,7 +688,7 @@ const isQueue = (value) => {
640
688
  if (typeof value !== "object" || value === null) return false;
641
689
  return typeof value.send === "function";
642
690
  };
643
- const makeClient$6 = (definition) => {
691
+ const makeClient$7 = (definition) => {
644
692
  const encodeMessage = Schema.encodeEffect(definition.message);
645
693
  return (queue) => ({
646
694
  send: Effect.fnUntraced(function* (message, options) {
@@ -678,30 +726,30 @@ const makeClient$6 = (definition) => {
678
726
  unsafeRaw: Effect.succeed(queue)
679
727
  });
680
728
  };
681
- const layer$8 = (tag, definition) => layer$10(tag, definition.binding, (value) => isQueue(value), makeClient$6(definition), { expected: expectedQueueProducer });
729
+ const layer$10 = (tag, definition) => layer$15(tag, definition.binding, (value) => isQueue(value), makeClient$7(definition), { expected: expectedQueueProducer });
682
730
  //#endregion
683
731
  //#region src/QueueDefinition.ts
684
732
  var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
685
733
  Queue: () => Queue$1,
686
- Tag: () => Tag$10,
734
+ Tag: () => Tag$11,
687
735
  implement: () => implement$7,
688
- make: () => make$9
736
+ make: () => make$10
689
737
  });
690
738
  const makeDefinition$4 = (id, definition) => {
691
739
  const queueDefinition = {
692
740
  id,
693
741
  message: definition.message
694
742
  };
695
- return Object.assign(queueDefinition, { make: (layer, options) => make$6(layer, {
743
+ return Object.assign(queueDefinition, { make: (layer, options) => make$7(layer, {
696
744
  ...options,
697
745
  queue: wrapHandler$1(queueDefinition, options.queue)
698
746
  }) });
699
747
  };
700
- const make$9 = (id, definition) => Tag$10()(id, definition);
701
- const Tag$10 = () => (id, definition) => {
748
+ const make$10 = (id, definition) => Tag$11()(id, definition);
749
+ const Tag$11 = () => (id, definition) => {
702
750
  const queueDefinition = makeDefinition$4(id, definition);
703
751
  const tag = Context.Service()(id);
704
- const layer = (binding) => layer$8(tag, {
752
+ const layer = (binding) => layer$10(tag, {
705
753
  ...binding,
706
754
  message: definition.message
707
755
  });
@@ -728,7 +776,7 @@ const Tag$10 = () => (id, definition) => {
728
776
  unsafeRaw
729
777
  });
730
778
  };
731
- const Queue$1 = Tag$10;
779
+ const Queue$1 = Tag$11;
732
780
  const wrapHandler$1 = (definition, handler) => {
733
781
  const decodeBody = Schema.decodeUnknownEffect(definition.message);
734
782
  return (batch) => Effect.gen(function* () {
@@ -740,7 +788,7 @@ const implement$7 = (_definition, handler) => handler;
740
788
  //#region src/Queue.ts
741
789
  var Queue_exports = /* @__PURE__ */ __exportAll({
742
790
  QueueMessageDecodeError: () => QueueMessageDecodeError,
743
- Tag: () => Tag$9,
791
+ Tag: () => Tag$10,
744
792
  decodeBatch: () => decodeBatch,
745
793
  fromMessage: () => fromMessage,
746
794
  fromMessageBatch: () => fromMessageBatch,
@@ -778,7 +826,7 @@ const decodeBatch = (batch, decodeBody) => Effect.gen(function* () {
778
826
  }
779
827
  return fromMessageBatch(batch, messages);
780
828
  });
781
- const Tag$9 = Tag$10;
829
+ const Tag$10 = Tag$11;
782
830
  const implement$6 = implement$7;
783
831
  //#endregion
784
832
  //#region src/RpcDefinition.ts
@@ -796,7 +844,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
796
844
  decodeSuccess: () => decodeSuccess,
797
845
  encodeArgs: () => encodeArgs,
798
846
  encodeSuccess: () => encodeSuccess,
799
- make: () => make$8,
847
+ make: () => make$9,
800
848
  method: () => method$4,
801
849
  reservedMethodNames: () => reservedMethodNames$4
802
850
  });
@@ -899,7 +947,7 @@ const decodeSuccess = (definition, methodName, value) => {
899
947
  cause
900
948
  })));
901
949
  };
902
- const make$8 = (id, methods) => {
950
+ const make$9 = (id, methods) => {
903
951
  const definition = {
904
952
  id,
905
953
  methods
@@ -957,8 +1005,8 @@ var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
957
1005
  ServiceBindingFetchError: () => ServiceBindingFetchError,
958
1006
  ServiceBindingRpcError: () => ServiceBindingRpcError,
959
1007
  isServiceBindingClient: () => isServiceBindingClient,
960
- layer: () => layer$7,
961
- makeClient: () => makeClient$5,
1008
+ layer: () => layer$9,
1009
+ makeClient: () => makeClient$6,
962
1010
  makeDirectMethods: () => makeDirectMethods$1
963
1011
  });
964
1012
  const TypeId$1 = "effect-cf/ServiceBinding";
@@ -972,7 +1020,7 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
972
1020
  */
973
1021
  var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
974
1022
  const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
975
- const makeClient$5 = (definition) => {
1023
+ const makeClient$6 = (definition) => {
976
1024
  return (service) => {
977
1025
  const fetch = (input, init) => Effect.tryPromise({
978
1026
  try: () => service.fetch(input, init),
@@ -1021,7 +1069,7 @@ const makeClient$5 = (definition) => {
1021
1069
  });
1022
1070
  };
1023
1071
  };
1024
- const layer$7 = (tag, definition) => layer$10(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition), { expected: expectedServiceBinding });
1072
+ const layer$9 = (tag, definition) => layer$15(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$6(definition), { expected: expectedServiceBinding });
1025
1073
  /**
1026
1074
  * Creates a typed Effect service for a Worker service binding.
1027
1075
  *
@@ -1052,7 +1100,7 @@ const layer$7 = (tag, definition) => layer$10(tag, definition.binding, (value) =
1052
1100
  * ```
1053
1101
  */
1054
1102
  const Service = () => (id, definition) => {
1055
- const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
1103
+ const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$6(definition));
1056
1104
  const fetch = (input, init) => Effect.gen(function* () {
1057
1105
  return yield* (yield* tag).fetch(input, init);
1058
1106
  });
@@ -1083,10 +1131,10 @@ const makeDirectMethods$1 = (rpcDefinition, call) => {
1083
1131
  //#endregion
1084
1132
  //#region src/WorkerDefinition.ts
1085
1133
  var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
1086
- Tag: () => Tag$8,
1134
+ Tag: () => Tag$9,
1087
1135
  Worker: () => Worker,
1088
1136
  implement: () => implement$5,
1089
- make: () => make$7,
1137
+ make: () => make$8,
1090
1138
  method: () => method$3
1091
1139
  });
1092
1140
  const reservedMethodNames$3 = new Set([
@@ -1124,21 +1172,21 @@ const method$3 = method$4;
1124
1172
  */
1125
1173
  const makeDefinition$3 = (id, methods) => {
1126
1174
  assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
1127
- const definition = make$8(id, methods);
1128
- return Object.assign(definition, { make: (layer, options) => make$6(layer, {
1175
+ const definition = make$9(id, methods);
1176
+ return Object.assign(definition, { make: (layer, options) => make$7(layer, {
1129
1177
  ...options,
1130
1178
  rpc: wrapHandlers$1(definition, options.rpc)
1131
1179
  }) });
1132
1180
  };
1133
- const make$7 = (id, methods) => Tag$8()(id, methods);
1134
- const Tag$8 = () => (id, methods) => {
1181
+ const make$8 = (id, methods) => Tag$9()(id, methods);
1182
+ const Tag$9 = () => (id, methods) => {
1135
1183
  const definition = makeDefinition$3(id, methods);
1136
1184
  const tag = Context.Service()(id);
1137
1185
  const bindingDefinition = (binding) => ({
1138
1186
  ...binding,
1139
1187
  definition
1140
1188
  });
1141
- const layer = (binding) => layer$7(tag, bindingDefinition(binding));
1189
+ const layer = (binding) => layer$9(tag, bindingDefinition(binding));
1142
1190
  const fetch = (input, init) => Effect.gen(function* () {
1143
1191
  return yield* (yield* tag).fetch(input, init);
1144
1192
  });
@@ -1163,7 +1211,7 @@ const Tag$8 = () => (id, methods) => {
1163
1211
  scopedCall
1164
1212
  });
1165
1213
  };
1166
- const Worker = Tag$8;
1214
+ const Worker = Tag$9;
1167
1215
  const wrapHandlers$1 = (definition, handlers) => {
1168
1216
  const wrapped = {};
1169
1217
  for (const key of Object.keys(definition.methods)) {
@@ -1179,6 +1227,26 @@ const wrapHandlers$1 = (definition, handlers) => {
1179
1227
  */
1180
1228
  const implement$5 = (_definition, handlers) => handlers;
1181
1229
  //#endregion
1230
+ //#region src/internal/Clock.ts
1231
+ const maxTimerMillis = 2 ** 31 - 1;
1232
+ const nanosPerMilli = BigInt(1e6);
1233
+ const clock = {
1234
+ currentTimeMillisUnsafe: () => Date.now(),
1235
+ currentTimeMillis: Effect.sync(() => clock.currentTimeMillisUnsafe()),
1236
+ currentTimeNanosUnsafe: () => BigInt(Date.now()) * nanosPerMilli,
1237
+ currentTimeNanos: Effect.sync(() => clock.currentTimeNanosUnsafe()),
1238
+ sleep: (duration) => {
1239
+ const millis = Duration.toMillis(duration);
1240
+ if (millis <= 0) return Effect.yieldNow;
1241
+ return Effect.callback((resume) => {
1242
+ if (millis > maxTimerMillis) return;
1243
+ const handle = setTimeout(() => resume(Effect.void), millis);
1244
+ return Effect.sync(() => clearTimeout(handle));
1245
+ });
1246
+ }
1247
+ };
1248
+ const layer$8 = Layer.effect(Clock.Clock, Effect.succeed(clock));
1249
+ //#endregion
1182
1250
  //#region src/internal/Entrypoint.ts
1183
1251
  const provideEntrypointServices = (layer, services) => layer.pipe(Layer.provideMerge(services));
1184
1252
  const defineEntrypointRpcMethods = (target, prototype, rpc, reservedMethodNames, run) => {
@@ -1219,11 +1287,11 @@ const fromExecutionContext = (ctx, runPromiseExit) => {
1219
1287
  var Worker_exports = /* @__PURE__ */ __exportAll({
1220
1288
  ExecutionContext: () => ExecutionContext,
1221
1289
  NativeRequest: () => NativeRequest,
1222
- Tag: () => Tag$7,
1290
+ Tag: () => Tag$8,
1223
1291
  WorkerContext: () => WorkerContext,
1224
1292
  implement: () => implement$4,
1225
1293
  isWebSocketUpgrade: () => isWebSocketUpgrade,
1226
- make: () => make$6,
1294
+ make: () => make$7,
1227
1295
  makeFetchHandler: () => makeFetchHandler,
1228
1296
  method: () => method$2,
1229
1297
  renderHttpResponse: () => renderHttpResponse
@@ -1252,14 +1320,14 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
1252
1320
  const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
1253
1321
  const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
1254
1322
  const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("eventLayer" in options || "fetch" in options || "queue" in options || "rpc" in options);
1255
- function make$6(layer, optionsOrFetch) {
1323
+ function make$7(layer, optionsOrFetch) {
1256
1324
  const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
1257
1325
  class EffectWorker extends WorkerEntrypoint {
1258
1326
  runtime;
1259
1327
  constructor(ctx, env) {
1260
1328
  super(ctx, env);
1261
1329
  let runWaitUntilEffect = () => Promise.reject(/* @__PURE__ */ new Error("WorkerContext runtime is not initialized"));
1262
- const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env)));
1330
+ const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$8, Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env)));
1263
1331
  this.runtime = ManagedRuntime.make(runtimeLayer);
1264
1332
  runWaitUntilEffect = (effect) => this.runtime.runPromiseExit(effect);
1265
1333
  }
@@ -1284,10 +1352,10 @@ function make$6(layer, optionsOrFetch) {
1284
1352
  return assumeEntrypointClass(EffectWorker);
1285
1353
  }
1286
1354
  const makeFetchHandler = (layer, options) => {
1287
- const WorkerClass = make$6(layer, options);
1355
+ const WorkerClass = make$7(layer, options);
1288
1356
  return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
1289
1357
  };
1290
- const Tag$7 = Tag$8;
1358
+ const Tag$8 = Tag$9;
1291
1359
  const method$2 = method$3;
1292
1360
  const implement$4 = implement$5;
1293
1361
  //#endregion
@@ -1296,8 +1364,8 @@ var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
1296
1364
  DurableObjectFetchError: () => DurableObjectFetchError,
1297
1365
  DurableObjectRpcError: () => DurableObjectRpcError,
1298
1366
  isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
1299
- layer: () => layer$6,
1300
- makeClient: () => makeClient$4,
1367
+ layer: () => layer$7,
1368
+ makeClient: () => makeClient$5,
1301
1369
  makeDirectMethods: () => makeDirectMethods
1302
1370
  });
1303
1371
  const expectedDurableObjectNamespace = "Durable Object namespace binding with getByName(), get(), idFromName(), idFromString(), newUniqueId(), and jurisdiction()";
@@ -1309,9 +1377,9 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
1309
1377
  * Failure raised when forwarding a request to a Durable Object stub.
1310
1378
  */
1311
1379
  var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
1312
- const hasFunction$1 = (value, key) => typeof Reflect.get(value, key) === "function";
1313
- const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction$1(value, "getByName") && hasFunction$1(value, "get") && hasFunction$1(value, "idFromName") && hasFunction$1(value, "idFromString") && hasFunction$1(value, "newUniqueId") && hasFunction$1(value, "jurisdiction");
1314
- const makeClient$4 = (definition) => {
1380
+ const hasFunction$2 = (value, key) => typeof Reflect.get(value, key) === "function";
1381
+ const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction$2(value, "getByName") && hasFunction$2(value, "get") && hasFunction$2(value, "idFromName") && hasFunction$2(value, "idFromString") && hasFunction$2(value, "newUniqueId") && hasFunction$2(value, "jurisdiction");
1382
+ const makeClient$5 = (definition) => {
1315
1383
  return (namespace) => {
1316
1384
  const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
1317
1385
  const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
@@ -1378,7 +1446,7 @@ const makeClient$4 = (definition) => {
1378
1446
  });
1379
1447
  };
1380
1448
  };
1381
- const layer$6 = (tag, definition) => layer$10(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$4(definition), { expected: expectedDurableObjectNamespace });
1449
+ const layer$7 = (tag, definition) => layer$15(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$5(definition), { expected: expectedDurableObjectNamespace });
1382
1450
  const makeDirectMethods = (rpcDefinition, helpers) => {
1383
1451
  const methods = {};
1384
1452
  if (rpcDefinition !== void 0) {
@@ -1403,9 +1471,9 @@ const makeDirectMethods = (rpcDefinition, helpers) => {
1403
1471
  //#region src/DurableObjectDefinition.ts
1404
1472
  var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
1405
1473
  DurableObject: () => DurableObject$1,
1406
- Tag: () => Tag$6,
1474
+ Tag: () => Tag$7,
1407
1475
  implement: () => implement$3,
1408
- make: () => make$5,
1476
+ make: () => make$6,
1409
1477
  method: () => method$1
1410
1478
  });
1411
1479
  const reservedMethodNames$1 = new Set([
@@ -1436,21 +1504,21 @@ const method$1 = method$4;
1436
1504
  */
1437
1505
  const makeDefinition$2 = (id, methods) => {
1438
1506
  assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
1439
- const definition = make$8(id, methods);
1440
- return Object.assign(definition, { make: (layer, options) => make$4(layer, {
1507
+ const definition = make$9(id, methods);
1508
+ return Object.assign(definition, { make: (layer, options) => make$5(layer, {
1441
1509
  ...options,
1442
1510
  rpc: wrapHandlers(definition, options.rpc)
1443
1511
  }) });
1444
1512
  };
1445
- const make$5 = (id, methods) => Tag$6()(id, methods);
1446
- const Tag$6 = () => (id, methods) => {
1513
+ const make$6 = (id, methods) => Tag$7()(id, methods);
1514
+ const Tag$7 = () => (id, methods) => {
1447
1515
  const definition = makeDefinition$2(id, methods);
1448
1516
  const tag = Context.Service()(id);
1449
1517
  const bindingDefinition = (binding) => ({
1450
1518
  ...binding,
1451
1519
  definition
1452
1520
  });
1453
- const layer = (binding) => layer$6(tag, bindingDefinition(binding));
1521
+ const layer = (binding) => layer$7(tag, bindingDefinition(binding));
1454
1522
  const newUniqueId = Effect.fnUntraced(function* (options) {
1455
1523
  return yield* (yield* tag).newUniqueId(options);
1456
1524
  });
@@ -1508,7 +1576,7 @@ const Tag$6 = () => (id, methods) => {
1508
1576
  unsafeRaw
1509
1577
  });
1510
1578
  };
1511
- const DurableObject$1 = Tag$6;
1579
+ const DurableObject$1 = Tag$7;
1512
1580
  const wrapHandlers = (definition, handlers) => {
1513
1581
  const wrapped = {};
1514
1582
  for (const key of Object.keys(definition.methods)) {
@@ -1526,9 +1594,9 @@ const implement$3 = (_definition, handlers) => handlers;
1526
1594
  //#endregion
1527
1595
  //#region src/DurableObject.ts
1528
1596
  var DurableObject_exports = /* @__PURE__ */ __exportAll({
1529
- Tag: () => Tag$5,
1597
+ Tag: () => Tag$6,
1530
1598
  implement: () => implement$2,
1531
- make: () => make$4,
1599
+ make: () => make$5,
1532
1600
  method: () => method
1533
1601
  });
1534
1602
  const reservedMethodNames = new Set([
@@ -1544,12 +1612,12 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
1544
1612
  /**
1545
1613
  * Creates a Durable Object class backed by a single managed Effect runtime.
1546
1614
  */
1547
- const make$4 = (layer, options = {}) => {
1615
+ const make$5 = (layer, options = {}) => {
1548
1616
  class EffectDurableObject extends DurableObject {
1549
1617
  runtime;
1550
1618
  constructor(state, env) {
1551
1619
  super(state, env);
1552
- const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env)));
1620
+ const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$8, ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env)));
1553
1621
  this.runtime = ManagedRuntime.make(runtimeLayer);
1554
1622
  const initialize = options.initialize;
1555
1623
  if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
@@ -1586,7 +1654,7 @@ const make$4 = (layer, options = {}) => {
1586
1654
  defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect));
1587
1655
  return assumeEntrypointClass(EffectDurableObject);
1588
1656
  };
1589
- const Tag$5 = Tag$6;
1657
+ const Tag$6 = Tag$7;
1590
1658
  const method = method$1;
1591
1659
  const implement$2 = implement$3;
1592
1660
  //#endregion
@@ -1915,7 +1983,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
1915
1983
  //#region src/DurableObjectRpcWebSocket.ts
1916
1984
  var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
1917
1985
  DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
1918
- layer: () => layer$5
1986
+ layer: () => layer$6
1919
1987
  });
1920
1988
  const defaultAttachmentKey = "effectCloudflareRpcClientId";
1921
1989
  const defaultTag = "effect-cf-rpc";
@@ -1926,7 +1994,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
1926
1994
  /**
1927
1995
  * Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
1928
1996
  */
1929
- const layer$5 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1997
+ const layer$6 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1930
1998
  const tag = options.tag ?? defaultTag;
1931
1999
  const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
1932
2000
  const durableObjectState = yield* DurableObjectState;
@@ -2039,7 +2107,7 @@ const writeAttachment = (socket, key, clientId) => {
2039
2107
  };
2040
2108
  //#endregion
2041
2109
  //#region src/DurableObjectSqlite.ts
2042
- var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$4 });
2110
+ var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$5 });
2043
2111
  /**
2044
2112
  * Provides `effect/unstable/sql` from the current Durable Object SQLite storage.
2045
2113
  *
@@ -2051,7 +2119,7 @@ var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => lay
2051
2119
  * );
2052
2120
  * ```
2053
2121
  */
2054
- const layer$4 = (options) => Layer.unwrap(Effect.gen(function* () {
2122
+ const layer$5 = (options) => Layer.unwrap(Effect.gen(function* () {
2055
2123
  const state = yield* DurableObjectState;
2056
2124
  return SqliteClient.layer({
2057
2125
  ...options,
@@ -2062,13 +2130,13 @@ const layer$4 = (options) => Layer.unwrap(Effect.gen(function* () {
2062
2130
  //#region src/Images.ts
2063
2131
  var Images_exports = /* @__PURE__ */ __exportAll({
2064
2132
  ImagesOperationError: () => ImagesOperationError,
2065
- Tag: () => Tag$4,
2133
+ Tag: () => Tag$5,
2066
2134
  draw: () => draw,
2067
2135
  empty: () => empty,
2068
2136
  isImagesBinding: () => isImagesBinding,
2069
- layer: () => layer$3,
2070
- make: () => make$3,
2071
- makeClient: () => makeClient$3,
2137
+ layer: () => layer$4,
2138
+ make: () => make$4,
2139
+ makeClient: () => makeClient$4,
2072
2140
  transform: () => transform
2073
2141
  });
2074
2142
  const TypeId = "effect-cf/Images/Steps";
@@ -2109,9 +2177,9 @@ const tryImagesSync = (binding, operation, evaluate) => Effect.try({
2109
2177
  catch: (cause) => imagesError(binding, operation, cause)
2110
2178
  });
2111
2179
  const maybe$1 = (value) => value === null ? Option.none() : Option.some(value);
2112
- const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
2113
- const isHostedImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "image") && hasFunction(value, "upload") && hasFunction(value, "list");
2114
- const isImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "info") && hasFunction(value, "input");
2180
+ const hasFunction$1 = (value, key) => typeof Reflect.get(value, key) === "function";
2181
+ const isHostedImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction$1(value, "image") && hasFunction$1(value, "upload") && hasFunction$1(value, "list");
2182
+ const isImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction$1(value, "info") && hasFunction$1(value, "input");
2115
2183
  const wrapResult = (binding, result) => ({
2116
2184
  raw: result,
2117
2185
  response: tryImagesSync(binding, "response", () => result.response()),
@@ -2131,7 +2199,7 @@ const wrapHosted = (binding, hosted) => ({
2131
2199
  list: (options) => tryImagesPromise(binding, "list", () => hosted.list(options)),
2132
2200
  unsafeRaw: Effect.succeed(hosted)
2133
2201
  });
2134
- const makeClient$3 = (definition) => (images) => {
2202
+ const makeClient$4 = (definition) => (images) => {
2135
2203
  const input = (image, options) => tryImagesSync(definition.binding, "input", () => images.input(image, options));
2136
2204
  const process = (steps, options) => Effect.gen(function* () {
2137
2205
  let transformer = yield* input(options.stream, options.inputOptions);
@@ -2155,11 +2223,11 @@ const makeClient$3 = (definition) => (images) => {
2155
2223
  unsafeRaw: Effect.succeed(images)
2156
2224
  };
2157
2225
  };
2158
- const layer$3 = (tag, definition) => layer$10(tag, definition.binding, isImagesBinding, makeClient$3(definition), { expected: expectedImagesBinding });
2159
- const make$3 = (id) => Tag$4()(id);
2160
- const Tag$4 = () => (id) => {
2226
+ const layer$4 = (tag, definition) => layer$15(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
2227
+ const make$4 = (id) => Tag$5()(id);
2228
+ const Tag$5 = () => (id) => {
2161
2229
  const tag = Context.Service()(id);
2162
- const makeLayer = (definition) => layer$3(tag, definition);
2230
+ const makeLayer = (definition) => layer$4(tag, definition);
2163
2231
  return Object.assign(tag, {
2164
2232
  id,
2165
2233
  layer: makeLayer
@@ -2169,10 +2237,10 @@ const Tag$4 = () => (id) => {
2169
2237
  //#region src/Kv.ts
2170
2238
  var Kv_exports = /* @__PURE__ */ __exportAll({
2171
2239
  KvOperationError: () => KvOperationError,
2172
- Tag: () => Tag$3,
2240
+ Tag: () => Tag$4,
2173
2241
  isKvNamespace: () => isKvNamespace,
2174
- layer: () => layer$2,
2175
- makeClient: () => makeClient$2
2242
+ layer: () => layer$3,
2243
+ makeClient: () => makeClient$3
2176
2244
  });
2177
2245
  const expectedKvNamespace = "KV namespace binding with get(), put(), delete(), getWithMetadata(), and list()";
2178
2246
  /** Error raised when a KV operation fails. */
@@ -2193,7 +2261,7 @@ const isKvNamespace = (value) => {
2193
2261
  const resource = value;
2194
2262
  return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
2195
2263
  };
2196
- const makeClient$2 = (definition) => {
2264
+ const makeClient$3 = (definition) => {
2197
2265
  const encodeKey = Schema.encodeEffect(definition.key);
2198
2266
  const decodeKey = Schema.decodeUnknownEffect(definition.key);
2199
2267
  const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
@@ -2250,20 +2318,20 @@ const makeClient$2 = (definition) => {
2250
2318
  unsafeRaw: Effect.succeed(kv)
2251
2319
  });
2252
2320
  };
2253
- const layer$2 = (tag, definition) => layer$10(tag, definition.binding, isKvNamespace, makeClient$2(definition), { expected: expectedKvNamespace });
2321
+ const layer$3 = (tag, definition) => layer$15(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
2254
2322
  const makeDefinition$1 = (id, definition) => {
2255
2323
  const kvDefinition = {
2256
2324
  id,
2257
2325
  key: definition.key,
2258
2326
  value: definition.value
2259
2327
  };
2260
- return Object.assign(kvDefinition, { layer: (tag, binding) => layer$2(tag, {
2328
+ return Object.assign(kvDefinition, { layer: (tag, binding) => layer$3(tag, {
2261
2329
  ...binding,
2262
2330
  key: definition.key,
2263
2331
  value: definition.value
2264
2332
  }) });
2265
2333
  };
2266
- const Tag$3 = () => (id, definition) => {
2334
+ const Tag$4 = () => (id, definition) => {
2267
2335
  const kvDefinition = makeDefinition$1(id, definition);
2268
2336
  const tag = Context.Service()(id);
2269
2337
  const makeLayer = (binding) => kvDefinition.layer(tag, binding);
@@ -2278,11 +2346,11 @@ const Tag$3 = () => (id, definition) => {
2278
2346
  //#region src/R2.ts
2279
2347
  var R2_exports = /* @__PURE__ */ __exportAll({
2280
2348
  R2OperationError: () => R2OperationError,
2281
- Tag: () => Tag$2,
2349
+ Tag: () => Tag$3,
2282
2350
  isR2Bucket: () => isR2Bucket,
2283
- layer: () => layer$1,
2284
- make: () => make$2,
2285
- makeClient: () => makeClient$1
2351
+ layer: () => layer$2,
2352
+ make: () => make$3,
2353
+ makeClient: () => makeClient$2
2286
2354
  });
2287
2355
  const expectedR2Bucket = "R2 bucket binding with head(), get(), put(), createMultipartUpload(), resumeMultipartUpload(), delete(), and list()";
2288
2356
  /** Error raised when an R2 operation fails. */
@@ -2336,7 +2404,7 @@ const isR2Bucket = (value) => {
2336
2404
  const resource = value;
2337
2405
  return typeof resource.head === "function" && typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.createMultipartUpload === "function" && typeof resource.resumeMultipartUpload === "function" && typeof resource.delete === "function" && typeof resource.list === "function";
2338
2406
  };
2339
- const makeClient$1 = (definition) => {
2407
+ const makeClient$2 = (definition) => {
2340
2408
  const wrapUpload = (upload) => ({
2341
2409
  raw: upload,
2342
2410
  key: upload.key,
@@ -2367,11 +2435,11 @@ const makeClient$1 = (definition) => {
2367
2435
  };
2368
2436
  };
2369
2437
  };
2370
- const layer$1 = (tag, definition) => layer$10(tag, definition.binding, isR2Bucket, makeClient$1(definition), { expected: expectedR2Bucket });
2371
- const make$2 = (id) => Tag$2()(id);
2372
- const Tag$2 = () => (id) => {
2438
+ const layer$2 = (tag, definition) => layer$15(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
2439
+ const make$3 = (id) => Tag$3()(id);
2440
+ const Tag$3 = () => (id) => {
2373
2441
  const tag = Context.Service()(id);
2374
- const makeLayer = (definition) => layer$1(tag, definition);
2442
+ const makeLayer = (definition) => layer$2(tag, definition);
2375
2443
  return Object.assign(tag, {
2376
2444
  id,
2377
2445
  layer: makeLayer
@@ -2383,8 +2451,8 @@ var WorkflowBinding_exports = /* @__PURE__ */ __exportAll({
2383
2451
  WorkflowOperationError: () => WorkflowOperationError,
2384
2452
  WorkflowResultDecodeError: () => WorkflowResultDecodeError,
2385
2453
  isWorkflow: () => isWorkflow,
2386
- layer: () => layer,
2387
- makeClient: () => makeClient
2454
+ layer: () => layer$1,
2455
+ makeClient: () => makeClient$1
2388
2456
  });
2389
2457
  const expectedWorkflow = "Workflow binding with create(), createBatch(), and get()";
2390
2458
  var WorkflowOperationError = class extends Data.TaggedError("WorkflowOperationError") {};
@@ -2403,7 +2471,7 @@ const isWorkflow = (value) => {
2403
2471
  const resource = value;
2404
2472
  return typeof resource.create === "function" && typeof resource.createBatch === "function" && typeof resource.get === "function";
2405
2473
  };
2406
- const makeClient = (definition) => {
2474
+ const makeClient$1 = (definition) => {
2407
2475
  const encodePayload = Schema.encodeEffect(definition.payload);
2408
2476
  const decodeResult = Schema.decodeUnknownEffect(definition.result);
2409
2477
  const wrapInstance = (raw) => {
@@ -2453,14 +2521,14 @@ const makeClient = (definition) => {
2453
2521
  unsafeRaw: Effect.succeed(workflow)
2454
2522
  });
2455
2523
  };
2456
- const layer = (tag, definition) => layer$10(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition), { expected: expectedWorkflow });
2524
+ const layer$1 = (tag, definition) => layer$15(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
2457
2525
  //#endregion
2458
2526
  //#region src/WorkflowDefinition.ts
2459
2527
  var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
2460
- Tag: () => Tag$1,
2528
+ Tag: () => Tag$2,
2461
2529
  Workflow: () => Workflow,
2462
2530
  implement: () => implement$1,
2463
- make: () => make$1
2531
+ make: () => make$2
2464
2532
  });
2465
2533
  const makeDefinition = (id, definition) => {
2466
2534
  const workflowDefinition = {
@@ -2468,13 +2536,13 @@ const makeDefinition = (id, definition) => {
2468
2536
  payload: definition.payload,
2469
2537
  result: definition.result
2470
2538
  };
2471
- return Object.assign(workflowDefinition, { make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }) });
2539
+ return Object.assign(workflowDefinition, { make: (layer, options) => make$1(layer, { run: wrapHandler(workflowDefinition, options.run) }) });
2472
2540
  };
2473
- const make$1 = (id, definition) => Tag$1()(id, definition);
2474
- const Tag$1 = () => (id, definition) => {
2541
+ const make$2 = (id, definition) => Tag$2()(id, definition);
2542
+ const Tag$2 = () => (id, definition) => {
2475
2543
  const workflowDefinition = makeDefinition(id, definition);
2476
2544
  const tag = Context.Service()(id);
2477
- const layer$11 = (binding) => layer(tag, {
2545
+ const layer = (binding) => layer$1(tag, {
2478
2546
  ...binding,
2479
2547
  payload: definition.payload,
2480
2548
  result: definition.result
@@ -2496,14 +2564,14 @@ const Tag$1 = () => (id, definition) => {
2496
2564
  payload: workflowDefinition.payload,
2497
2565
  result: workflowDefinition.result,
2498
2566
  make: workflowDefinition.make,
2499
- layer: layer$11,
2567
+ layer,
2500
2568
  create,
2501
2569
  createBatch,
2502
2570
  get,
2503
2571
  unsafeRaw
2504
2572
  });
2505
2573
  };
2506
- const Workflow = Tag$1;
2574
+ const Workflow = Tag$2;
2507
2575
  const wrapHandler = (definition, handler) => {
2508
2576
  const decodePayload = Schema.decodeUnknownEffect(definition.payload);
2509
2577
  const encodeResult = Schema.encodeEffect(definition.result);
@@ -2520,12 +2588,12 @@ const implement$1 = (_definition, handler) => handler;
2520
2588
  //#endregion
2521
2589
  //#region src/Workflow.ts
2522
2590
  var Workflow_exports = /* @__PURE__ */ __exportAll({
2523
- Tag: () => Tag,
2591
+ Tag: () => Tag$1,
2524
2592
  WorkflowEvent: () => WorkflowEvent$1,
2525
2593
  WorkflowStep: () => WorkflowStep$1,
2526
2594
  WorkflowStepContext: () => WorkflowStepContext$1,
2527
2595
  implement: () => implement,
2528
- make: () => make,
2596
+ make: () => make$1,
2529
2597
  sleep: () => sleep,
2530
2598
  sleepUntil: () => sleepUntil,
2531
2599
  step: () => step,
@@ -2538,7 +2606,8 @@ const fromWorkflowEvent = (event) => ({
2538
2606
  raw: event,
2539
2607
  payload: event.payload,
2540
2608
  timestamp: event.timestamp,
2541
- instanceId: event.instanceId
2609
+ instanceId: event.instanceId,
2610
+ workflowName: event.workflowName
2542
2611
  });
2543
2612
  const fromWorkflowStep = (step, runPromise) => ({
2544
2613
  raw: step,
@@ -2563,7 +2632,7 @@ const fromWorkflowStep = (step, runPromise) => ({
2563
2632
  catch: (cause) => cause
2564
2633
  })
2565
2634
  });
2566
- const make = (layer, options) => {
2635
+ const make$1 = (layer, options) => {
2567
2636
  class EffectWorkflow extends WorkflowEntrypoint {
2568
2637
  runtime;
2569
2638
  constructor(ctx, env) {
@@ -2584,7 +2653,57 @@ const step = (name, effect, config) => Effect.flatMap(WorkflowStep$1, (workflowS
2584
2653
  const sleep = (name, duration) => Effect.flatMap(WorkflowStep$1, (workflowStep) => workflowStep.sleep(name, duration));
2585
2654
  const sleepUntil = (name, timestamp) => Effect.flatMap(WorkflowStep$1, (workflowStep) => workflowStep.sleepUntil(name, timestamp));
2586
2655
  const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1, (workflowStep) => workflowStep.waitForEvent(name, options));
2587
- const Tag = Tag$1;
2656
+ const Tag$1 = Tag$2;
2588
2657
  const implement = implement$1;
2589
2658
  //#endregion
2590
- export { Binding_exports as Binding, CloudflareOtlp_exports as CloudflareOtlp, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, ServiceBinding_exports as ServiceBinding, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
2659
+ //#region src/Vectorize.ts
2660
+ var Vectorize_exports = /* @__PURE__ */ __exportAll({
2661
+ Tag: () => Tag,
2662
+ VectorizeOperationError: () => VectorizeOperationError,
2663
+ isVectorizeBinding: () => isVectorizeBinding,
2664
+ layer: () => layer,
2665
+ make: () => make,
2666
+ makeClient: () => makeClient
2667
+ });
2668
+ const expectedVectorizeBinding = "Vectorize index binding with describe(), query(), insert(), upsert(), deleteByIds(), and getByIds()";
2669
+ /** Error raised when a Vectorize operation fails. */
2670
+ var VectorizeOperationError = class extends Data.TaggedError("VectorizeOperationError") {};
2671
+ const vectorizeError = (binding, operation, cause) => new VectorizeOperationError({
2672
+ binding,
2673
+ operation,
2674
+ cause
2675
+ });
2676
+ const tryVectorizePromise = (binding, operation, evaluate) => Effect.tryPromise({
2677
+ try: evaluate,
2678
+ catch: (cause) => vectorizeError(binding, operation, cause)
2679
+ });
2680
+ const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
2681
+ const isVectorizeBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "describe") && hasFunction(value, "query") && hasFunction(value, "insert") && hasFunction(value, "upsert") && hasFunction(value, "deleteByIds") && hasFunction(value, "getByIds");
2682
+ const makeClient = (definition) => (index) => {
2683
+ const runtime = index;
2684
+ const deleteByIds = (ids) => tryVectorizePromise(definition.binding, "deleteByIds", () => runtime.deleteByIds([...ids]));
2685
+ return {
2686
+ definition,
2687
+ describe: tryVectorizePromise(definition.binding, "describe", () => runtime.describe()),
2688
+ query: (vector, options) => tryVectorizePromise(definition.binding, "query", () => runtime.query(vector, options)),
2689
+ queryById: (vectorId, options) => runtime.queryById !== void 0 ? tryVectorizePromise(definition.binding, "queryById", () => runtime.queryById(vectorId, options)) : Effect.fail(vectorizeError(definition.binding, "queryById", /* @__PURE__ */ new TypeError("Vectorize binding does not expose queryById()"))),
2690
+ insert: (vectors) => tryVectorizePromise(definition.binding, "insert", () => runtime.insert([...vectors])),
2691
+ upsert: (vectors) => tryVectorizePromise(definition.binding, "upsert", () => runtime.upsert([...vectors])),
2692
+ deleteByIds,
2693
+ delete: deleteByIds,
2694
+ getByIds: (ids) => tryVectorizePromise(definition.binding, "getByIds", () => runtime.getByIds([...ids])),
2695
+ unsafeRaw: Effect.succeed(index)
2696
+ };
2697
+ };
2698
+ const layer = (tag, definition) => layer$15(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
2699
+ const make = (id) => Tag()(id);
2700
+ const Tag = () => (id) => {
2701
+ const tag = Context.Service()(id);
2702
+ const makeLayer = (definition) => layer(tag, definition);
2703
+ return Object.assign(tag, {
2704
+ id,
2705
+ layer: makeLayer
2706
+ });
2707
+ };
2708
+ //#endregion
2709
+ export { AiGateway_exports as AiGateway, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, CloudflareOtlp_exports as CloudflareOtlp, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, ServiceBinding_exports as ServiceBinding, Vectorize_exports as Vectorize, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, WorkersAi_exports as WorkersAi, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };