effect-cf 0.25.2 → 0.26.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/CHANGELOG.md +16 -0
- package/README.md +211 -1
- package/dist/Artifacts-DcoXcRP5.d.mts +231 -0
- package/dist/ComputerWorkspaceHost.d.mts +71 -0
- package/dist/ComputerWorkspaceHost.mjs +74 -0
- package/dist/ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs +8 -0
- package/dist/index.d.mts +424 -12
- package/dist/index.mjs +898 -69
- package/package.json +12 -1
- package/src/Artifacts.ts +519 -0
- package/src/CloudflareOtlp.ts +3 -2
- package/src/ComputerArtifacts.ts +255 -0
- package/src/ComputerWorkspace.ts +1098 -0
- package/src/ComputerWorkspaceHost.ts +216 -0
- package/src/DurableObject.ts +16 -16
- package/src/WebTransport.ts +123 -0
- package/src/index.ts +4 -0
- package/src/internal/ComputerWorkspaceHostRegistry.ts +10 -0
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { a as DurableObjectWebSocket_exports, c as causeMessage, d as WorkerConfig, f as WorkerEnvironment, i as fromExecutionContext, l as violationsMessage, n as DurableObjectState_exports, o as fromWebSocket, r as fromDurableObjectState, s as DurableObjectStorage_exports, t as DurableObjectState, u as Environment_exports } from "./DurableObjectState-CEh0DVw7.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { t as lookup } from "./ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs";
|
|
4
|
+
import { Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Function as Function$1, Layer, ManagedRuntime, Option, Predicate, Queue, Result, Schema, Stream } from "effect";
|
|
4
5
|
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
5
6
|
import { OtlpExporter, OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
|
6
7
|
import { D1Client } from "@effect/sql-d1";
|
|
@@ -15,7 +16,7 @@ var Binding_exports = /* @__PURE__ */ __exportAll({
|
|
|
15
16
|
BindingValidationError: () => BindingValidationError,
|
|
16
17
|
Service: () => Service$2,
|
|
17
18
|
TypeId: () => TypeId$3,
|
|
18
|
-
layer: () => layer$
|
|
19
|
+
layer: () => layer$20
|
|
19
20
|
});
|
|
20
21
|
/** Internal type id marker used by binding helper services. */
|
|
21
22
|
const TypeId$3 = "~effect-cf/Binding";
|
|
@@ -110,7 +111,7 @@ const makeBindingLayer = (tag, binding, isResource, wrap, options) => Layer.effe
|
|
|
110
111
|
const resource = yield* getBinding(env, binding, isResource, options);
|
|
111
112
|
return wrap === void 0 ? resource : wrap(resource);
|
|
112
113
|
}));
|
|
113
|
-
function layer$
|
|
114
|
+
function layer$20(tag, binding, isResource, wrap, options) {
|
|
114
115
|
return makeBindingLayer(tag, binding, isResource, wrap, options);
|
|
115
116
|
}
|
|
116
117
|
const Service$2 = () => {
|
|
@@ -129,13 +130,13 @@ const Service$2 = () => {
|
|
|
129
130
|
//#endregion
|
|
130
131
|
//#region src/WorkersAi.ts
|
|
131
132
|
var WorkersAi_exports = /* @__PURE__ */ __exportAll({
|
|
132
|
-
Tag: () => Tag$
|
|
133
|
+
Tag: () => Tag$17,
|
|
133
134
|
WorkersAiOperationError: () => WorkersAiOperationError,
|
|
134
135
|
embeddingResponse: () => embeddingResponse,
|
|
135
136
|
isWorkersAiBinding: () => isWorkersAiBinding,
|
|
136
|
-
layer: () => layer$
|
|
137
|
-
make: () => make$
|
|
138
|
-
makeClient: () => makeClient$
|
|
137
|
+
layer: () => layer$19,
|
|
138
|
+
make: () => make$19,
|
|
139
|
+
makeClient: () => makeClient$17
|
|
139
140
|
});
|
|
140
141
|
const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
|
|
141
142
|
/** Error raised when a Workers AI operation fails. */
|
|
@@ -157,13 +158,13 @@ const tryWorkersAiSync = (binding, operation, evaluate) => Effect.try({
|
|
|
157
158
|
try: evaluate,
|
|
158
159
|
catch: (cause) => workersAiError(binding, operation, cause)
|
|
159
160
|
});
|
|
160
|
-
const hasFunction$
|
|
161
|
-
const isWorkersAiBinding = (value) => typeof value === "object" && value !== null && hasFunction$
|
|
161
|
+
const hasFunction$4 = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
162
|
+
const isWorkersAiBinding = (value) => typeof value === "object" && value !== null && hasFunction$4(value, "run") && hasFunction$4(value, "gateway") && hasFunction$4(value, "models");
|
|
162
163
|
const embeddingResponse = (value) => ({
|
|
163
164
|
data: value.data ?? [],
|
|
164
165
|
shape: value.shape ?? []
|
|
165
166
|
});
|
|
166
|
-
const makeClient$
|
|
167
|
+
const makeClient$17 = (definition) => (ai) => {
|
|
167
168
|
const run = Effect.fn("WorkersAi.run")((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => ai.run(model, input, options)));
|
|
168
169
|
return {
|
|
169
170
|
definition,
|
|
@@ -175,11 +176,11 @@ const makeClient$15 = (definition) => (ai) => {
|
|
|
175
176
|
rawUnsafe: Effect.succeed(ai)
|
|
176
177
|
};
|
|
177
178
|
};
|
|
178
|
-
const layer$
|
|
179
|
-
const make$
|
|
180
|
-
const Tag$
|
|
179
|
+
const layer$19 = (tag, definition) => layer$20(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$17(definition), { expected: expectedWorkersAiBinding });
|
|
180
|
+
const make$19 = (id) => Tag$17()(id);
|
|
181
|
+
const Tag$17 = () => (id) => {
|
|
181
182
|
const tag = Context.Service()(id);
|
|
182
|
-
const makeLayer = (definition) => layer$
|
|
183
|
+
const makeLayer = (definition) => layer$19(tag, definition);
|
|
183
184
|
return Object.assign(tag, {
|
|
184
185
|
id,
|
|
185
186
|
layer: makeLayer
|
|
@@ -189,11 +190,11 @@ const Tag$16 = () => (id) => {
|
|
|
189
190
|
//#region src/AiGateway.ts
|
|
190
191
|
var AiGateway_exports = /* @__PURE__ */ __exportAll({
|
|
191
192
|
AiGatewayOperationError: () => AiGatewayOperationError,
|
|
192
|
-
Tag: () => Tag$
|
|
193
|
+
Tag: () => Tag$16,
|
|
193
194
|
isAiGatewayBinding: () => isAiGatewayBinding,
|
|
194
|
-
layer: () => layer$
|
|
195
|
-
make: () => make$
|
|
196
|
-
makeClient: () => makeClient$
|
|
195
|
+
layer: () => layer$18,
|
|
196
|
+
make: () => make$18,
|
|
197
|
+
makeClient: () => makeClient$16,
|
|
197
198
|
makeClientFromAi: () => makeClientFromAi,
|
|
198
199
|
makeHttpClient: () => makeHttpClient
|
|
199
200
|
});
|
|
@@ -225,7 +226,7 @@ const providerUrl = (baseUrl, path = "") => {
|
|
|
225
226
|
};
|
|
226
227
|
const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
|
|
227
228
|
const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
|
|
228
|
-
const makeClient$
|
|
229
|
+
const makeClient$16 = (definition, gateway) => ({
|
|
229
230
|
definition,
|
|
230
231
|
run: Effect.fn("AiGateway.run")((data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options))),
|
|
231
232
|
getUrl: Effect.fn("AiGateway.getUrl")((provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider))),
|
|
@@ -245,11 +246,11 @@ const makeClientFromAi = (definition, ai) => {
|
|
|
245
246
|
const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
|
|
246
247
|
return {
|
|
247
248
|
definition,
|
|
248
|
-
run: (data, options) => withGateway((raw) => makeClient$
|
|
249
|
-
getUrl: (provider) => withGateway((raw) => makeClient$
|
|
250
|
-
fetch: (options) => withGateway((raw) => makeClient$
|
|
251
|
-
patchLog: (logId, data) => withGateway((raw) => makeClient$
|
|
252
|
-
getLog: (logId) => withGateway((raw) => makeClient$
|
|
249
|
+
run: (data, options) => withGateway((raw) => makeClient$16(definition, raw).run(data, options)),
|
|
250
|
+
getUrl: (provider) => withGateway((raw) => makeClient$16(definition, raw).getUrl(provider)),
|
|
251
|
+
fetch: (options) => withGateway((raw) => makeClient$16(definition, raw).fetch(options)),
|
|
252
|
+
patchLog: (logId, data) => withGateway((raw) => makeClient$16(definition, raw).patchLog(logId, data)),
|
|
253
|
+
getLog: (logId) => withGateway((raw) => makeClient$16(definition, raw).getLog(logId)),
|
|
253
254
|
rawUnsafe: gateway
|
|
254
255
|
};
|
|
255
256
|
};
|
|
@@ -293,11 +294,11 @@ const makeHttpClient = (definition, request = fetch) => {
|
|
|
293
294
|
rawUnsafe: Effect.fail(aiGatewayError(binding, "rawUnsafe", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
|
|
294
295
|
};
|
|
295
296
|
};
|
|
296
|
-
const layer$
|
|
297
|
-
const make$
|
|
298
|
-
const Tag$
|
|
297
|
+
const layer$18 = (tag, definition) => layer$20(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
|
|
298
|
+
const make$18 = (id) => Tag$16()(id);
|
|
299
|
+
const Tag$16 = () => (id) => {
|
|
299
300
|
const tag = Context.Service()(id);
|
|
300
|
-
const makeLayer = (definition) => layer$
|
|
301
|
+
const makeLayer = (definition) => layer$18(tag, definition);
|
|
301
302
|
return Object.assign(tag, {
|
|
302
303
|
id,
|
|
303
304
|
layer: makeLayer
|
|
@@ -312,13 +313,13 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
312
313
|
AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
|
|
313
314
|
AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
|
|
314
315
|
QueryTag: () => QueryTag,
|
|
315
|
-
Tag: () => Tag$
|
|
316
|
+
Tag: () => Tag$15,
|
|
316
317
|
isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
|
|
317
|
-
layer: () => layer$
|
|
318
|
+
layer: () => layer$17,
|
|
318
319
|
layerFetch: () => layerFetch,
|
|
319
320
|
layerFetchConfig: () => layerFetchConfig,
|
|
320
|
-
make: () => make$
|
|
321
|
-
makeClient: () => makeClient$
|
|
321
|
+
make: () => make$17,
|
|
322
|
+
makeClient: () => makeClient$15,
|
|
322
323
|
makeQuery: () => makeQuery,
|
|
323
324
|
makeQueryClient: () => makeQueryClient,
|
|
324
325
|
queryConfig: () => queryConfig,
|
|
@@ -507,7 +508,7 @@ const isAnalyticsEngineDataset = (value) => {
|
|
|
507
508
|
if (typeof value !== "object" || value === null) return false;
|
|
508
509
|
return typeof Reflect.get(value, "writeDataPoint") === "function";
|
|
509
510
|
};
|
|
510
|
-
const makeClient$
|
|
511
|
+
const makeClient$15 = (definition, defaults) => (dataset) => {
|
|
511
512
|
return {
|
|
512
513
|
definition,
|
|
513
514
|
writeDataPoint: Effect.fn("AnalyticsEngine.writeDataPoint")((dataPoint, options) => {
|
|
@@ -537,12 +538,12 @@ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effe
|
|
|
537
538
|
return yield* makeQueryClient(definition);
|
|
538
539
|
}));
|
|
539
540
|
const layerFetchConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
540
|
-
const layer$
|
|
541
|
-
const make$
|
|
541
|
+
const layer$17 = (tag, definition) => layer$20(tag, definition.binding, isAnalyticsEngineDataset, makeClient$15(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
|
|
542
|
+
const make$17 = (id) => Tag$15()(id);
|
|
542
543
|
const makeQuery = (id) => QueryTag()(id);
|
|
543
|
-
const Tag$
|
|
544
|
+
const Tag$15 = () => (id) => {
|
|
544
545
|
const tag = Context.Service()(id);
|
|
545
|
-
const makeLayer = (definition) => layer$
|
|
546
|
+
const makeLayer = (definition) => layer$17(tag, definition);
|
|
546
547
|
return Object.assign(tag, {
|
|
547
548
|
id,
|
|
548
549
|
layer: makeLayer
|
|
@@ -563,6 +564,125 @@ const QueryTag = () => (id) => {
|
|
|
563
564
|
});
|
|
564
565
|
};
|
|
565
566
|
//#endregion
|
|
567
|
+
//#region src/Artifacts.ts
|
|
568
|
+
var Artifacts_exports = /* @__PURE__ */ __exportAll({
|
|
569
|
+
ArtifactsOperationError: () => ArtifactsOperationError,
|
|
570
|
+
Tag: () => Tag$14,
|
|
571
|
+
artifactsErrorCodes: () => artifactsErrorCodes,
|
|
572
|
+
artifactsErrorNumericCodes: () => artifactsErrorNumericCodes,
|
|
573
|
+
isArtifactsBinding: () => isArtifactsBinding,
|
|
574
|
+
isArtifactsRepoBinding: () => isArtifactsRepoBinding,
|
|
575
|
+
layer: () => layer$16,
|
|
576
|
+
make: () => make$16,
|
|
577
|
+
makeClient: () => makeClient$14
|
|
578
|
+
});
|
|
579
|
+
const expectedArtifactsBinding = "Artifacts binding with create(), get(), import(), list(), and delete()";
|
|
580
|
+
const expectedArtifactsRepo = "Artifacts repo handle with createToken(), listTokens(), revokeToken(), fork(), log(), readCommit(), and readTree()";
|
|
581
|
+
/** Documented string error codes returned by Cloudflare Artifacts. */
|
|
582
|
+
const artifactsErrorCodes = [
|
|
583
|
+
"ALREADY_EXISTS",
|
|
584
|
+
"NOT_FOUND",
|
|
585
|
+
"IMPORT_IN_PROGRESS",
|
|
586
|
+
"FORK_IN_PROGRESS",
|
|
587
|
+
"INVALID_INPUT",
|
|
588
|
+
"INVALID_REPO_NAME",
|
|
589
|
+
"INVALID_TTL",
|
|
590
|
+
"INVALID_URL",
|
|
591
|
+
"REMOTE_AUTH_REQUIRED",
|
|
592
|
+
"UPSTREAM_UNAVAILABLE",
|
|
593
|
+
"MEMORY_LIMIT",
|
|
594
|
+
"INTERNAL_ERROR"
|
|
595
|
+
];
|
|
596
|
+
/** Documented numeric error codes returned by Cloudflare Artifacts. */
|
|
597
|
+
const artifactsErrorNumericCodes = {
|
|
598
|
+
ALREADY_EXISTS: 10201,
|
|
599
|
+
NOT_FOUND: 10200,
|
|
600
|
+
IMPORT_IN_PROGRESS: 10302,
|
|
601
|
+
FORK_IN_PROGRESS: 10303,
|
|
602
|
+
INVALID_INPUT: 10100,
|
|
603
|
+
INVALID_REPO_NAME: 10101,
|
|
604
|
+
INVALID_TTL: 10103,
|
|
605
|
+
INVALID_URL: 10104,
|
|
606
|
+
REMOTE_AUTH_REQUIRED: 10106,
|
|
607
|
+
UPSTREAM_UNAVAILABLE: 10401,
|
|
608
|
+
MEMORY_LIMIT: 10402,
|
|
609
|
+
INTERNAL_ERROR: 10400
|
|
610
|
+
};
|
|
611
|
+
/** Error raised when a Cloudflare Artifacts operation fails. */
|
|
612
|
+
var ArtifactsOperationError = class extends Data.TaggedError("ArtifactsOperationError") {
|
|
613
|
+
get message() {
|
|
614
|
+
const code = this.code === void 0 ? "" : ` (${this.code})`;
|
|
615
|
+
return `Artifacts ${this.operation} failed for binding "${this.binding}"${code}: ${causeMessage(this.cause)}`;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
const artifactsErrorDetails$1 = (cause) => {
|
|
619
|
+
if (typeof cause !== "object" || cause === null) return {};
|
|
620
|
+
const code = Reflect.get(cause, "code");
|
|
621
|
+
const numericCode = Reflect.get(cause, "numericCode");
|
|
622
|
+
return {
|
|
623
|
+
...typeof code === "string" ? { code } : {},
|
|
624
|
+
...typeof numericCode === "number" ? { numericCode } : {}
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
const artifactsError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
628
|
+
binding,
|
|
629
|
+
operation,
|
|
630
|
+
cause,
|
|
631
|
+
...artifactsErrorDetails$1(cause)
|
|
632
|
+
});
|
|
633
|
+
const tryArtifactsPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
634
|
+
try: evaluate,
|
|
635
|
+
catch: (cause) => artifactsError(binding, operation, cause)
|
|
636
|
+
});
|
|
637
|
+
const spanOptions$4 = (binding, operation) => ({ attributes: {
|
|
638
|
+
binding,
|
|
639
|
+
operation
|
|
640
|
+
} });
|
|
641
|
+
const hasFunction$3 = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
642
|
+
/** Tests whether a value exposes the complete documented Artifacts repo handle API. */
|
|
643
|
+
const isArtifactsRepoBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "createToken") && hasFunction$3(value, "listTokens") && hasFunction$3(value, "revokeToken") && hasFunction$3(value, "fork") && hasFunction$3(value, "log") && hasFunction$3(value, "readCommit") && hasFunction$3(value, "readTree");
|
|
644
|
+
/** Tests whether a value exposes the complete documented Artifacts namespace API. */
|
|
645
|
+
const isArtifactsBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "create") && hasFunction$3(value, "get") && hasFunction$3(value, "import") && hasFunction$3(value, "list") && hasFunction$3(value, "delete");
|
|
646
|
+
const wrapRepo = (binding, repo) => ({
|
|
647
|
+
id: repo.id,
|
|
648
|
+
name: repo.name,
|
|
649
|
+
description: repo.description,
|
|
650
|
+
defaultBranch: repo.defaultBranch,
|
|
651
|
+
createdAt: repo.createdAt,
|
|
652
|
+
updatedAt: repo.updatedAt,
|
|
653
|
+
lastPushAt: repo.lastPushAt,
|
|
654
|
+
source: repo.source,
|
|
655
|
+
readOnly: repo.readOnly,
|
|
656
|
+
remote: repo.remote,
|
|
657
|
+
createToken: Effect.fn("Artifacts.createToken", spanOptions$4(binding, "createToken"))((scope, ttl) => tryArtifactsPromise(binding, "createToken", () => repo.createToken(scope, ttl))),
|
|
658
|
+
listTokens: tryArtifactsPromise(binding, "listTokens", () => repo.listTokens()).pipe(Effect.withSpan("Artifacts.listTokens", spanOptions$4(binding, "listTokens"))),
|
|
659
|
+
revokeToken: Effect.fn("Artifacts.revokeToken", spanOptions$4(binding, "revokeToken"))((tokenOrId) => tryArtifactsPromise(binding, "revokeToken", () => repo.revokeToken(tokenOrId))),
|
|
660
|
+
fork: Effect.fn("Artifacts.fork", spanOptions$4(binding, "fork"))((name, options) => tryArtifactsPromise(binding, "fork", () => repo.fork(name, options))),
|
|
661
|
+
log: Effect.fn("Artifacts.log", spanOptions$4(binding, "log"))((options) => tryArtifactsPromise(binding, "log", () => repo.log(options))),
|
|
662
|
+
readCommit: Effect.fn("Artifacts.readCommit", spanOptions$4(binding, "readCommit"))((hash) => tryArtifactsPromise(binding, "readCommit", () => repo.readCommit(hash))),
|
|
663
|
+
readTree: Effect.fn("Artifacts.readTree", spanOptions$4(binding, "readTree"))((hash) => tryArtifactsPromise(binding, "readTree", () => repo.readTree(hash))),
|
|
664
|
+
raw: repo
|
|
665
|
+
});
|
|
666
|
+
const makeClient$14 = (definition) => (artifacts) => ({
|
|
667
|
+
definition,
|
|
668
|
+
create: Effect.fn("Artifacts.create", spanOptions$4(definition.binding, "create"))((name, options) => tryArtifactsPromise(definition.binding, "create", () => artifacts.create(name, options))),
|
|
669
|
+
get: Effect.fn("Artifacts.get", spanOptions$4(definition.binding, "get"))((name) => tryArtifactsPromise(definition.binding, "get", () => artifacts.get(name)).pipe(Effect.flatMap((repo) => isArtifactsRepoBinding(repo) ? Effect.succeed(wrapRepo(definition.binding, repo)) : Effect.fail(artifactsError(definition.binding, "get", /* @__PURE__ */ new TypeError(`Expected ${expectedArtifactsRepo}`)))))),
|
|
670
|
+
import: Effect.fn("Artifacts.import", spanOptions$4(definition.binding, "import"))((params) => tryArtifactsPromise(definition.binding, "import", () => artifacts.import(params))),
|
|
671
|
+
list: Effect.fn("Artifacts.list", spanOptions$4(definition.binding, "list"))((options) => tryArtifactsPromise(definition.binding, "list", () => artifacts.list(options))),
|
|
672
|
+
delete: Effect.fn("Artifacts.delete", spanOptions$4(definition.binding, "delete"))((name) => tryArtifactsPromise(definition.binding, "delete", () => artifacts.delete(name))),
|
|
673
|
+
rawUnsafe: Effect.succeed(artifacts)
|
|
674
|
+
});
|
|
675
|
+
const layer$16 = (tag, definition) => layer$20(tag, definition.binding, isArtifactsBinding, makeClient$14(definition), { expected: expectedArtifactsBinding });
|
|
676
|
+
const make$16 = (id) => Tag$14()(id);
|
|
677
|
+
const Tag$14 = () => (id) => {
|
|
678
|
+
const tag = Context.Service()(id);
|
|
679
|
+
const makeLayer = (definition) => layer$16(tag, definition);
|
|
680
|
+
return Object.assign(tag, {
|
|
681
|
+
id,
|
|
682
|
+
layer: makeLayer
|
|
683
|
+
});
|
|
684
|
+
};
|
|
685
|
+
//#endregion
|
|
566
686
|
//#region src/BrowserRendering.ts
|
|
567
687
|
var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
568
688
|
BrowserRenderingOperationError: () => BrowserRenderingOperationError,
|
|
@@ -570,7 +690,7 @@ var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
|
570
690
|
isBrowserRenderingBinding: () => isBrowserRenderingBinding,
|
|
571
691
|
layer: () => layer$15,
|
|
572
692
|
make: () => make$15,
|
|
573
|
-
makeClient: () => makeClient$
|
|
693
|
+
makeClient: () => makeClient$13
|
|
574
694
|
});
|
|
575
695
|
const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
|
|
576
696
|
/** Error raised when a Browser Rendering operation fails. */
|
|
@@ -611,13 +731,13 @@ const wrapBrowser = (binding, browser) => ({
|
|
|
611
731
|
disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
|
|
612
732
|
});
|
|
613
733
|
const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
614
|
-
const makeClient$
|
|
734
|
+
const makeClient$13 = (definition) => (binding) => ({
|
|
615
735
|
definition,
|
|
616
736
|
launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.launchWith")),
|
|
617
737
|
connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.connectWith")),
|
|
618
738
|
rawUnsafe: Effect.succeed(binding)
|
|
619
739
|
});
|
|
620
|
-
const layer$15 = (tag, definition) => layer$
|
|
740
|
+
const layer$15 = (tag, definition) => layer$20(tag, definition.binding, isBrowserRenderingBinding, makeClient$13(definition), { expected: expectedBrowserRenderingBinding });
|
|
621
741
|
const make$15 = (id) => Tag$13()(id);
|
|
622
742
|
const Tag$13 = () => (id) => {
|
|
623
743
|
const tag = Context.Service()(id);
|
|
@@ -635,7 +755,7 @@ var Cache_exports = /* @__PURE__ */ __exportAll({
|
|
|
635
755
|
layer: () => layer$14,
|
|
636
756
|
layerFrom: () => layerFrom,
|
|
637
757
|
makeCacheClient: () => makeCacheClient,
|
|
638
|
-
makeClient: () => makeClient$
|
|
758
|
+
makeClient: () => makeClient$12
|
|
639
759
|
});
|
|
640
760
|
/** Error raised when a Cloudflare Cache API operation fails. */
|
|
641
761
|
var CacheOperationError = class extends Data.TaggedError("CacheOperationError") {
|
|
@@ -654,28 +774,28 @@ const tryCachePromise = (cache, operation, evaluate) => Effect.tryPromise({
|
|
|
654
774
|
try: evaluate,
|
|
655
775
|
catch: (cause) => cacheError(cache, operation, cause)
|
|
656
776
|
});
|
|
657
|
-
const spanOptions$
|
|
777
|
+
const spanOptions$3 = (cache, operation) => ({ attributes: {
|
|
658
778
|
cache,
|
|
659
779
|
operation
|
|
660
780
|
} });
|
|
661
781
|
/** Wraps a native Cloudflare `Cache` instance. */
|
|
662
782
|
const makeCacheClient = (cache, name = "default") => ({
|
|
663
783
|
name,
|
|
664
|
-
match: Effect.fn("Cache.match", spanOptions$
|
|
665
|
-
put: Effect.fn("Cache.put", spanOptions$
|
|
666
|
-
delete: Effect.fn("Cache.delete", spanOptions$
|
|
784
|
+
match: Effect.fn("Cache.match", spanOptions$3(name, "match"))((request, options) => tryCachePromise(name, "match", () => cache.match(request, options)).pipe(Effect.map(Option.fromUndefinedOr))),
|
|
785
|
+
put: Effect.fn("Cache.put", spanOptions$3(name, "put"))((request, response) => tryCachePromise(name, "put", () => cache.put(request, response))),
|
|
786
|
+
delete: Effect.fn("Cache.delete", spanOptions$3(name, "delete"))((request, options) => tryCachePromise(name, "delete", () => cache.delete(request, options))),
|
|
667
787
|
rawUnsafe: Effect.succeed(cache)
|
|
668
788
|
});
|
|
669
789
|
/** Wraps a native Cloudflare `CacheStorage` instance. */
|
|
670
|
-
const makeClient$
|
|
790
|
+
const makeClient$12 = (storage) => ({
|
|
671
791
|
default: makeCacheClient(storage.default),
|
|
672
|
-
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name)), Effect.withSpan("Cache.open", spanOptions$
|
|
792
|
+
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name)), Effect.withSpan("Cache.open", spanOptions$3(name, "open"))),
|
|
673
793
|
rawUnsafe: Effect.succeed(storage)
|
|
674
794
|
});
|
|
675
795
|
/** Provides Cache API services from an explicit native `CacheStorage` instance. */
|
|
676
|
-
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$
|
|
796
|
+
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$12(storage));
|
|
677
797
|
/** Provides Cache API services from Cloudflare's global `caches` object. */
|
|
678
|
-
const layer$14 = Layer.sync(CacheStorage, () => makeClient$
|
|
798
|
+
const layer$14 = Layer.sync(CacheStorage, () => makeClient$12(caches));
|
|
679
799
|
//#endregion
|
|
680
800
|
//#region src/CloudflareOtlp.ts
|
|
681
801
|
/**
|
|
@@ -683,8 +803,9 @@ const layer$14 = Layer.sync(CacheStorage, () => makeClient$11(caches));
|
|
|
683
803
|
*
|
|
684
804
|
* Every layer exposes {@link OtlpExporter.Flusher}, which drains buffered
|
|
685
805
|
* telemetry on demand. Cloudflare isolates can freeze before the periodic
|
|
686
|
-
* export interval fires. Effect-backed Worker fetch handlers
|
|
687
|
-
* Durable Object native RPC handlers
|
|
806
|
+
* export interval fires. Effect-backed Worker fetch handlers, Worker or
|
|
807
|
+
* Durable Object native RPC handlers, and Durable Object alarm handlers
|
|
808
|
+
* schedule this flusher automatically.
|
|
688
809
|
* Flush or scheduling failures do not replace the handler outcome and emit
|
|
689
810
|
* only bounded framework diagnostics without attaching the foreign cause.
|
|
690
811
|
* Other entrypoint lifecycles can flush explicitly or hand the flush to their
|
|
@@ -798,6 +919,650 @@ const layerDurableObject = (options = {}) => Layer.unwrap(Effect.map(DurableObje
|
|
|
798
919
|
"cloudflare.durable_object.id": options.includeObjectId ? state.id.toString() : void 0
|
|
799
920
|
})));
|
|
800
921
|
//#endregion
|
|
922
|
+
//#region src/ComputerArtifacts.ts
|
|
923
|
+
var ComputerArtifacts_exports = /* @__PURE__ */ __exportAll({
|
|
924
|
+
fromClient: () => fromClient,
|
|
925
|
+
makeClient: () => makeClient$11
|
|
926
|
+
});
|
|
927
|
+
const artifactsErrorDetails = (cause) => {
|
|
928
|
+
if (typeof cause !== "object" || cause === null) return {};
|
|
929
|
+
const code = Reflect.get(cause, "code");
|
|
930
|
+
const numericCode = Reflect.get(cause, "numericCode");
|
|
931
|
+
return {
|
|
932
|
+
...typeof code === "string" ? { code } : {},
|
|
933
|
+
...typeof numericCode === "number" ? { numericCode } : {}
|
|
934
|
+
};
|
|
935
|
+
};
|
|
936
|
+
const operationError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
937
|
+
binding,
|
|
938
|
+
operation,
|
|
939
|
+
cause,
|
|
940
|
+
...artifactsErrorDetails(cause)
|
|
941
|
+
});
|
|
942
|
+
const tryOperation = (binding, operation, evaluate) => Effect.tryPromise({
|
|
943
|
+
try: evaluate,
|
|
944
|
+
catch: (cause) => operationError(binding, operation, cause)
|
|
945
|
+
});
|
|
946
|
+
const spanOptions$2 = (binding, sessionId, operation) => ({ attributes: {
|
|
947
|
+
binding,
|
|
948
|
+
sessionId,
|
|
949
|
+
operation
|
|
950
|
+
} });
|
|
951
|
+
/** Wraps an already-created upstream session client. */
|
|
952
|
+
const fromClient = (client, options = {}) => {
|
|
953
|
+
const binding = options.binding ?? "ARTIFACTS";
|
|
954
|
+
const { sessionId } = client;
|
|
955
|
+
return {
|
|
956
|
+
sessionId,
|
|
957
|
+
create: Effect.fn("ComputerArtifacts.create", spanOptions$2(binding, sessionId, "create"))(function* (name, createOptions) {
|
|
958
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
959
|
+
return yield* tryOperation(binding, "create", () => client.create(name, createOptions));
|
|
960
|
+
}),
|
|
961
|
+
get: Effect.fn("ComputerArtifacts.get", spanOptions$2(binding, sessionId, "get"))(function* (name) {
|
|
962
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
963
|
+
return yield* tryOperation(binding, "get", () => client.get(name));
|
|
964
|
+
}),
|
|
965
|
+
list: tryOperation(binding, "list", () => client.list()).pipe(Effect.withSpan("ComputerArtifacts.list", spanOptions$2(binding, sessionId, "list"))),
|
|
966
|
+
import: Effect.fn("ComputerArtifacts.import", spanOptions$2(binding, sessionId, "import"))(function* (name, source, importOptions) {
|
|
967
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
968
|
+
return yield* tryOperation(binding, "import", () => client.import(name, source, importOptions));
|
|
969
|
+
}),
|
|
970
|
+
delete: Effect.fn("ComputerArtifacts.delete", spanOptions$2(binding, sessionId, "delete"))(function* (name) {
|
|
971
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
972
|
+
return yield* tryOperation(binding, "delete", () => client.delete(name));
|
|
973
|
+
}),
|
|
974
|
+
createToken: Effect.fn("ComputerArtifacts.createToken", spanOptions$2(binding, sessionId, "createToken"))(function* (name, scope, ttl) {
|
|
975
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
976
|
+
return yield* tryOperation(binding, "createToken", () => client.createToken(name, scope, ttl));
|
|
977
|
+
}),
|
|
978
|
+
listTokens: Effect.fn("ComputerArtifacts.listTokens", spanOptions$2(binding, sessionId, "listTokens"))(function* (name) {
|
|
979
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
980
|
+
return yield* tryOperation(binding, "listTokens", () => client.listTokens(name));
|
|
981
|
+
}),
|
|
982
|
+
getToken: Effect.fn("ComputerArtifacts.getToken", spanOptions$2(binding, sessionId, "getToken"))(function* (name, id) {
|
|
983
|
+
yield* Effect.annotateCurrentSpan({
|
|
984
|
+
repo: name,
|
|
985
|
+
tokenId: id
|
|
986
|
+
});
|
|
987
|
+
return yield* tryOperation(binding, "getToken", () => client.getToken(name, id));
|
|
988
|
+
}),
|
|
989
|
+
revokeToken: Effect.fn("ComputerArtifacts.revokeToken", spanOptions$2(binding, sessionId, "revokeToken"))(function* (name, tokenOrId) {
|
|
990
|
+
yield* Effect.annotateCurrentSpan("repo", name);
|
|
991
|
+
return yield* tryOperation(binding, "revokeToken", () => client.revokeToken(name, tokenOrId));
|
|
992
|
+
}),
|
|
993
|
+
cli: Effect.fn("ComputerArtifacts.cli", spanOptions$2(binding, sessionId, "cli"))(function* (input) {
|
|
994
|
+
yield* Effect.annotateCurrentSpan("argv", input.argv.join(" "));
|
|
995
|
+
return yield* tryOperation(binding, "cli", () => client.cli(input));
|
|
996
|
+
}),
|
|
997
|
+
rawUnsafe: Effect.succeed(client)
|
|
998
|
+
};
|
|
999
|
+
};
|
|
1000
|
+
/**
|
|
1001
|
+
* Creates an Effect-native session client directly from a Worker Artifacts
|
|
1002
|
+
* binding. `@cloudflare/computer` is loaded only when this Effect runs, keeping
|
|
1003
|
+
* the optional peer out of applications that do not use this integration.
|
|
1004
|
+
*/
|
|
1005
|
+
const makeClient$11 = Effect.fn("ComputerArtifacts.makeClient")(function* (bindingValue, sessionId, options = {}) {
|
|
1006
|
+
const binding = options.binding ?? "ARTIFACTS";
|
|
1007
|
+
const computerArtifacts = yield* Effect.tryPromise({
|
|
1008
|
+
try: () => import("@cloudflare/computer/artifacts"),
|
|
1009
|
+
catch: (cause) => operationError(binding, "createClient", cause)
|
|
1010
|
+
});
|
|
1011
|
+
const client = yield* Effect.try({
|
|
1012
|
+
try: () => computerArtifacts.createArtifact(bindingValue, sessionId),
|
|
1013
|
+
catch: (cause) => operationError(binding, "createClient", cause)
|
|
1014
|
+
});
|
|
1015
|
+
return fromClient(client, { binding });
|
|
1016
|
+
});
|
|
1017
|
+
//#endregion
|
|
1018
|
+
//#region src/ComputerWorkspace.ts
|
|
1019
|
+
var ComputerWorkspace_exports = /* @__PURE__ */ __exportAll({
|
|
1020
|
+
ComputerWorkspace: () => ComputerWorkspace,
|
|
1021
|
+
WorkspaceAssetsError: () => WorkspaceAssetsError,
|
|
1022
|
+
WorkspaceExecError: () => WorkspaceExecError,
|
|
1023
|
+
WorkspaceFsError: () => WorkspaceFsError,
|
|
1024
|
+
WorkspaceGitError: () => WorkspaceGitError,
|
|
1025
|
+
fromWorkspaceClient: () => fromWorkspaceClient
|
|
1026
|
+
});
|
|
1027
|
+
/**
|
|
1028
|
+
* Workspace errors use `Schema.TaggedError`, unlike most local binding errors,
|
|
1029
|
+
* because workspace operations commonly sit behind Durable Object RPC methods.
|
|
1030
|
+
* The schema form preserves the operation-family tags across that boundary.
|
|
1031
|
+
*/
|
|
1032
|
+
var WorkspaceFsError = class extends Schema.TaggedError()("WorkspaceFsError", {
|
|
1033
|
+
operation: Schema.String,
|
|
1034
|
+
path: Schema.String,
|
|
1035
|
+
message: Schema.String,
|
|
1036
|
+
code: Schema.optionalKey(Schema.String),
|
|
1037
|
+
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1038
|
+
}) {};
|
|
1039
|
+
/** Schema-serializable error for a workspace Git operation. */
|
|
1040
|
+
var WorkspaceGitError = class extends Schema.TaggedError()("WorkspaceGitError", {
|
|
1041
|
+
operation: Schema.String,
|
|
1042
|
+
message: Schema.String,
|
|
1043
|
+
code: Schema.optionalKey(Schema.String),
|
|
1044
|
+
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1045
|
+
}) {};
|
|
1046
|
+
/** Schema-serializable error for a workspace runtime operation. */
|
|
1047
|
+
var WorkspaceExecError = class extends Schema.TaggedError()("WorkspaceExecError", {
|
|
1048
|
+
operation: Schema.String,
|
|
1049
|
+
message: Schema.String,
|
|
1050
|
+
code: Schema.optionalKey(Schema.String),
|
|
1051
|
+
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1052
|
+
}) {};
|
|
1053
|
+
/** Schema-serializable error for a workspace Assets operation. */
|
|
1054
|
+
var WorkspaceAssetsError = class extends Schema.TaggedError()("WorkspaceAssetsError", {
|
|
1055
|
+
operation: Schema.String,
|
|
1056
|
+
path: Schema.String,
|
|
1057
|
+
message: Schema.String,
|
|
1058
|
+
code: Schema.optionalKey(Schema.String),
|
|
1059
|
+
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1060
|
+
}) {};
|
|
1061
|
+
const errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
1062
|
+
const errorCode = (cause) => {
|
|
1063
|
+
if (typeof cause !== "object" || cause === null) return;
|
|
1064
|
+
const code = Reflect.get(cause, "code");
|
|
1065
|
+
return typeof code === "string" ? code : void 0;
|
|
1066
|
+
};
|
|
1067
|
+
const fsError = (operation, path, cause) => WorkspaceFsError.make({
|
|
1068
|
+
operation,
|
|
1069
|
+
path,
|
|
1070
|
+
message: errorMessage(cause),
|
|
1071
|
+
cause,
|
|
1072
|
+
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1073
|
+
});
|
|
1074
|
+
const gitError = (operation, cause) => WorkspaceGitError.make({
|
|
1075
|
+
operation,
|
|
1076
|
+
message: errorMessage(cause),
|
|
1077
|
+
cause,
|
|
1078
|
+
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1079
|
+
});
|
|
1080
|
+
const execError = (operation, cause) => WorkspaceExecError.make({
|
|
1081
|
+
operation,
|
|
1082
|
+
message: errorMessage(cause),
|
|
1083
|
+
cause,
|
|
1084
|
+
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1085
|
+
});
|
|
1086
|
+
const assetsError = (operation, path, cause) => WorkspaceAssetsError.make({
|
|
1087
|
+
operation,
|
|
1088
|
+
path,
|
|
1089
|
+
message: errorMessage(cause),
|
|
1090
|
+
cause,
|
|
1091
|
+
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1092
|
+
});
|
|
1093
|
+
const tryFs = (operation, path, evaluate) => Effect.tryPromise({
|
|
1094
|
+
try: evaluate,
|
|
1095
|
+
catch: (cause) => fsError(operation, path, cause)
|
|
1096
|
+
});
|
|
1097
|
+
const isNotFound = (error) => error.code === "ENOENT" || /ENOENT|no such/i.test(error.message);
|
|
1098
|
+
const makeFilesystem = (fsClient) => {
|
|
1099
|
+
const readFile = Effect.fn("ComputerWorkspace.fs.readFile", { attributes: {
|
|
1100
|
+
family: "fs",
|
|
1101
|
+
operation: "readFile"
|
|
1102
|
+
} })(function* (path, options = {}) {
|
|
1103
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1104
|
+
const { encoding = "utf8", ...readOptions } = options;
|
|
1105
|
+
if (encoding === "stream") return yield* tryFs("readFile", path, () => fsClient.readFile(path, readOptions));
|
|
1106
|
+
return yield* tryFs("readFile", path, () => fsClient.readFile(path, {
|
|
1107
|
+
...readOptions,
|
|
1108
|
+
encoding: "utf8"
|
|
1109
|
+
}));
|
|
1110
|
+
});
|
|
1111
|
+
const stat = Effect.fn("ComputerWorkspace.fs.stat", { attributes: {
|
|
1112
|
+
family: "fs",
|
|
1113
|
+
operation: "stat"
|
|
1114
|
+
} })(function* (path) {
|
|
1115
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1116
|
+
return yield* tryFs("stat", path, () => fsClient.stat(path));
|
|
1117
|
+
});
|
|
1118
|
+
return {
|
|
1119
|
+
readFile,
|
|
1120
|
+
stat,
|
|
1121
|
+
lstat: Effect.fn("ComputerWorkspace.fs.lstat", { attributes: {
|
|
1122
|
+
family: "fs",
|
|
1123
|
+
operation: "lstat"
|
|
1124
|
+
} })(function* (path) {
|
|
1125
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1126
|
+
return yield* tryFs("lstat", path, () => fsClient.lstat(path));
|
|
1127
|
+
}),
|
|
1128
|
+
exists: Effect.fn("ComputerWorkspace.fs.exists", { attributes: {
|
|
1129
|
+
family: "fs",
|
|
1130
|
+
operation: "exists"
|
|
1131
|
+
} })(function* (path) {
|
|
1132
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1133
|
+
return yield* stat(path).pipe(Effect.as(true), Effect.catch((error) => isNotFound(error) ? Effect.succeed(false) : Effect.fail(error)));
|
|
1134
|
+
}),
|
|
1135
|
+
readlink: Effect.fn("ComputerWorkspace.fs.readlink", { attributes: {
|
|
1136
|
+
family: "fs",
|
|
1137
|
+
operation: "readlink"
|
|
1138
|
+
} })(function* (path) {
|
|
1139
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1140
|
+
return yield* tryFs("readlink", path, () => fsClient.readlink(path));
|
|
1141
|
+
}),
|
|
1142
|
+
readdir: Effect.fn("ComputerWorkspace.fs.readdir", { attributes: {
|
|
1143
|
+
family: "fs",
|
|
1144
|
+
operation: "readdir"
|
|
1145
|
+
} })(function* (path, options) {
|
|
1146
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1147
|
+
return yield* tryFs("readdir", path, () => fsClient.readdir(path, options));
|
|
1148
|
+
}),
|
|
1149
|
+
find: Effect.fn("ComputerWorkspace.fs.find", { attributes: {
|
|
1150
|
+
family: "fs",
|
|
1151
|
+
operation: "find"
|
|
1152
|
+
} })(function* (directory, pattern, options) {
|
|
1153
|
+
yield* Effect.annotateCurrentSpan({
|
|
1154
|
+
path: directory,
|
|
1155
|
+
pattern
|
|
1156
|
+
});
|
|
1157
|
+
return yield* tryFs("find", directory, () => fsClient.find(directory, pattern, options));
|
|
1158
|
+
}),
|
|
1159
|
+
ls: Effect.fn("ComputerWorkspace.fs.ls", { attributes: {
|
|
1160
|
+
family: "fs",
|
|
1161
|
+
operation: "ls"
|
|
1162
|
+
} })(function* (prefix) {
|
|
1163
|
+
yield* Effect.annotateCurrentSpan("path", prefix);
|
|
1164
|
+
return yield* tryFs("ls", prefix, () => fsClient.ls(prefix));
|
|
1165
|
+
}),
|
|
1166
|
+
grep: Effect.fn("ComputerWorkspace.fs.grep", { attributes: {
|
|
1167
|
+
family: "fs",
|
|
1168
|
+
operation: "grep"
|
|
1169
|
+
} })(function* (pattern, path, options) {
|
|
1170
|
+
yield* Effect.annotateCurrentSpan({
|
|
1171
|
+
path,
|
|
1172
|
+
pattern
|
|
1173
|
+
});
|
|
1174
|
+
return yield* tryFs("grep", path, () => fsClient.grep(pattern, path, options));
|
|
1175
|
+
}),
|
|
1176
|
+
writeFile: Effect.fn("ComputerWorkspace.fs.writeFile", { attributes: {
|
|
1177
|
+
family: "fs",
|
|
1178
|
+
operation: "writeFile"
|
|
1179
|
+
} })(function* (path, content, options) {
|
|
1180
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1181
|
+
yield* tryFs("writeFile", path, () => fsClient.writeFile(path, content, options));
|
|
1182
|
+
}),
|
|
1183
|
+
mkdir: Effect.fn("ComputerWorkspace.fs.mkdir", { attributes: {
|
|
1184
|
+
family: "fs",
|
|
1185
|
+
operation: "mkdir"
|
|
1186
|
+
} })(function* (path, options) {
|
|
1187
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1188
|
+
yield* tryFs("mkdir", path, () => fsClient.mkdir(path, options));
|
|
1189
|
+
}),
|
|
1190
|
+
rm: Effect.fn("ComputerWorkspace.fs.rm", { attributes: {
|
|
1191
|
+
family: "fs",
|
|
1192
|
+
operation: "rm"
|
|
1193
|
+
} })(function* (path, options) {
|
|
1194
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1195
|
+
yield* tryFs("rm", path, () => fsClient.rm(path, options));
|
|
1196
|
+
}),
|
|
1197
|
+
chmod: Effect.fn("ComputerWorkspace.fs.chmod", { attributes: {
|
|
1198
|
+
family: "fs",
|
|
1199
|
+
operation: "chmod"
|
|
1200
|
+
} })(function* (path, mode) {
|
|
1201
|
+
yield* Effect.annotateCurrentSpan({
|
|
1202
|
+
path,
|
|
1203
|
+
mode
|
|
1204
|
+
});
|
|
1205
|
+
yield* tryFs("chmod", path, () => fsClient.chmod(path, mode));
|
|
1206
|
+
}),
|
|
1207
|
+
symlink: Effect.fn("ComputerWorkspace.fs.symlink", { attributes: {
|
|
1208
|
+
family: "fs",
|
|
1209
|
+
operation: "symlink"
|
|
1210
|
+
} })(function* (target, path) {
|
|
1211
|
+
yield* Effect.annotateCurrentSpan({
|
|
1212
|
+
path,
|
|
1213
|
+
target
|
|
1214
|
+
});
|
|
1215
|
+
yield* tryFs("symlink", path, () => fsClient.symlink(target, path));
|
|
1216
|
+
})
|
|
1217
|
+
};
|
|
1218
|
+
};
|
|
1219
|
+
const gitPerson = (person) => ({
|
|
1220
|
+
...person,
|
|
1221
|
+
timestampSeconds: person.timestamp
|
|
1222
|
+
});
|
|
1223
|
+
const gitCommit = (commit) => ({
|
|
1224
|
+
oid: commit.oid,
|
|
1225
|
+
message: commit.message,
|
|
1226
|
+
tree: commit.tree,
|
|
1227
|
+
parent: commit.parent,
|
|
1228
|
+
parents: commit.parent,
|
|
1229
|
+
author: gitPerson(commit.author),
|
|
1230
|
+
committer: gitPerson(commit.committer)
|
|
1231
|
+
});
|
|
1232
|
+
const makeGit = (gitClient) => {
|
|
1233
|
+
const method = (operation, evaluate) => Effect.fn(`ComputerWorkspace.git.${operation}`, { attributes: {
|
|
1234
|
+
family: "git",
|
|
1235
|
+
operation
|
|
1236
|
+
} })(function* (...args) {
|
|
1237
|
+
return yield* Effect.tryPromise({
|
|
1238
|
+
try: () => evaluate(...args),
|
|
1239
|
+
catch: (cause) => gitError(operation, cause)
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
const log = Effect.fn("ComputerWorkspace.git.log", { attributes: {
|
|
1243
|
+
family: "git",
|
|
1244
|
+
operation: "log"
|
|
1245
|
+
} })(function* (options) {
|
|
1246
|
+
const { maxCount, ...upstreamOptions } = options ?? {};
|
|
1247
|
+
return (yield* Effect.tryPromise({
|
|
1248
|
+
try: () => gitClient.log({
|
|
1249
|
+
...upstreamOptions,
|
|
1250
|
+
...upstreamOptions.depth === void 0 && maxCount !== void 0 ? { depth: maxCount } : {}
|
|
1251
|
+
}),
|
|
1252
|
+
catch: (cause) => gitError("log", cause)
|
|
1253
|
+
})).map(gitCommit);
|
|
1254
|
+
});
|
|
1255
|
+
const revParse = Effect.fn("ComputerWorkspace.git.revParse", { attributes: {
|
|
1256
|
+
family: "git",
|
|
1257
|
+
operation: "revParse"
|
|
1258
|
+
} })(function* (input) {
|
|
1259
|
+
const options = typeof input === "string" ? { ref: input } : input;
|
|
1260
|
+
return yield* Effect.tryPromise({
|
|
1261
|
+
try: () => gitClient.revParse(options),
|
|
1262
|
+
catch: (cause) => gitError("revParse", cause)
|
|
1263
|
+
});
|
|
1264
|
+
});
|
|
1265
|
+
return {
|
|
1266
|
+
clone: method("clone", (options) => gitClient.clone(options)),
|
|
1267
|
+
diff: method("diff", (options) => gitClient.diff(options)),
|
|
1268
|
+
diffSummary: method("diffSummary", (options) => gitClient.diffSummary(options)),
|
|
1269
|
+
init: method("init", (options) => gitClient.init(options)),
|
|
1270
|
+
status: method("status", (options) => gitClient.status(options)),
|
|
1271
|
+
add: method("add", (options) => gitClient.add(options)),
|
|
1272
|
+
rm: method("rm", (options) => gitClient.rm(options)),
|
|
1273
|
+
commit: method("commit", (options) => gitClient.commit(options)),
|
|
1274
|
+
log,
|
|
1275
|
+
show: method("show", (options) => gitClient.show(options)),
|
|
1276
|
+
revParse,
|
|
1277
|
+
repoRoot: method("repoRoot", (options) => gitClient.repoRoot(options)),
|
|
1278
|
+
currentBranch: method("currentBranch", (options) => gitClient.currentBranch(options)),
|
|
1279
|
+
lsFiles: method("lsFiles", (options) => gitClient.lsFiles(options)),
|
|
1280
|
+
lsTree: method("lsTree", (options) => gitClient.lsTree(options)),
|
|
1281
|
+
branch: method("branch", (options) => gitClient.branch(options)),
|
|
1282
|
+
branchDelete: method("branchDelete", (options) => gitClient.branchDelete(options)),
|
|
1283
|
+
branchList: method("branchList", (options) => gitClient.branchList(options)),
|
|
1284
|
+
tag: method("tag", (options) => gitClient.tag(options)),
|
|
1285
|
+
tagDelete: method("tagDelete", (options) => gitClient.tagDelete(options)),
|
|
1286
|
+
tagList: method("tagList", (options) => gitClient.tagList(options)),
|
|
1287
|
+
checkout: method("checkout", (options) => gitClient.checkout(options)),
|
|
1288
|
+
fetch: method("fetch", (options) => gitClient.fetch(options)),
|
|
1289
|
+
push: method("push", (options) => gitClient.push(options)),
|
|
1290
|
+
pull: method("pull", (options) => gitClient.pull(options)),
|
|
1291
|
+
merge: method("merge", (options) => gitClient.merge(options)),
|
|
1292
|
+
remoteAdd: method("remoteAdd", (options) => gitClient.remoteAdd(options)),
|
|
1293
|
+
remoteRemove: method("remoteRemove", (options) => gitClient.remoteRemove(options)),
|
|
1294
|
+
remoteList: method("remoteList", (options) => gitClient.remoteList(options)),
|
|
1295
|
+
hashObject: method("hashObject", (options) => gitClient.hashObject(options)),
|
|
1296
|
+
catFile: method("catFile", (options) => gitClient.catFile(options)),
|
|
1297
|
+
updateRef: method("updateRef", (options) => gitClient.updateRef(options)),
|
|
1298
|
+
configGet: method("configGet", (options) => gitClient.configGet(options)),
|
|
1299
|
+
configSet: method("configSet", (options) => gitClient.configSet(options)),
|
|
1300
|
+
stashPush: method("stashPush", (options) => gitClient.stashPush(options)),
|
|
1301
|
+
stashList: method("stashList", (options) => gitClient.stashList(options)),
|
|
1302
|
+
stashPop: method("stashPop", (options) => gitClient.stashPop(options)),
|
|
1303
|
+
reset: method("reset", (options) => gitClient.reset(options)),
|
|
1304
|
+
clean: method("clean", (options) => gitClient.clean(options)),
|
|
1305
|
+
cli: method("cli", (input) => gitClient.cli(input))
|
|
1306
|
+
};
|
|
1307
|
+
};
|
|
1308
|
+
const runtimeExecOptions = (options) => {
|
|
1309
|
+
const { encoding = "utf8", timeoutMillis, timeoutMs, ...rest } = options ?? {};
|
|
1310
|
+
return {
|
|
1311
|
+
...rest,
|
|
1312
|
+
...encoding === "utf8" ? { encoding: "utf8" } : {},
|
|
1313
|
+
...timeoutMs === void 0 && timeoutMillis === void 0 ? {} : { timeoutMs: timeoutMs ?? timeoutMillis }
|
|
1314
|
+
};
|
|
1315
|
+
};
|
|
1316
|
+
const runtimeGetOptions = (options) => {
|
|
1317
|
+
const { encoding = "utf8", ...rest } = options ?? {};
|
|
1318
|
+
return {
|
|
1319
|
+
...rest,
|
|
1320
|
+
...encoding === "utf8" ? { encoding: "utf8" } : {}
|
|
1321
|
+
};
|
|
1322
|
+
};
|
|
1323
|
+
const wrapRuntimeResult = (result) => ({
|
|
1324
|
+
status: result.status,
|
|
1325
|
+
exitCode: result.exitCode,
|
|
1326
|
+
stdout: result.stdout,
|
|
1327
|
+
stderr: result.stderr,
|
|
1328
|
+
...result.value === void 0 ? {} : { value: result.value },
|
|
1329
|
+
pushed: result.pushed,
|
|
1330
|
+
pulled: result.pulled,
|
|
1331
|
+
skipped: result.skipped,
|
|
1332
|
+
sync: result.sync
|
|
1333
|
+
});
|
|
1334
|
+
const wrapRuntimeEvent = (event) => {
|
|
1335
|
+
switch (event.name) {
|
|
1336
|
+
case "stdout": {
|
|
1337
|
+
const chunk = event.value;
|
|
1338
|
+
return typeof chunk === "string" ? {
|
|
1339
|
+
_tag: "Stdout",
|
|
1340
|
+
id: event.id,
|
|
1341
|
+
sequence: event.seq,
|
|
1342
|
+
chunk,
|
|
1343
|
+
text: chunk
|
|
1344
|
+
} : {
|
|
1345
|
+
_tag: "Stdout",
|
|
1346
|
+
id: event.id,
|
|
1347
|
+
sequence: event.seq,
|
|
1348
|
+
chunk,
|
|
1349
|
+
bytes: chunk
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
case "stderr": {
|
|
1353
|
+
const chunk = event.value;
|
|
1354
|
+
return typeof chunk === "string" ? {
|
|
1355
|
+
_tag: "Stderr",
|
|
1356
|
+
id: event.id,
|
|
1357
|
+
sequence: event.seq,
|
|
1358
|
+
chunk,
|
|
1359
|
+
text: chunk
|
|
1360
|
+
} : {
|
|
1361
|
+
_tag: "Stderr",
|
|
1362
|
+
id: event.id,
|
|
1363
|
+
sequence: event.seq,
|
|
1364
|
+
chunk,
|
|
1365
|
+
bytes: chunk
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
case "exit": return {
|
|
1369
|
+
_tag: "Exit",
|
|
1370
|
+
id: event.id,
|
|
1371
|
+
sequence: event.seq,
|
|
1372
|
+
exitCode: event.code,
|
|
1373
|
+
...event.result === void 0 ? {} : { value: event.result }
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const wrapRun = (handle) => {
|
|
1378
|
+
const events = Stream.fromReadableStream({
|
|
1379
|
+
evaluate: () => handle,
|
|
1380
|
+
onError: (cause) => execError("events", cause)
|
|
1381
|
+
}).pipe(Stream.map(wrapRuntimeEvent));
|
|
1382
|
+
const result = Effect.tryPromise({
|
|
1383
|
+
try: () => handle.result(),
|
|
1384
|
+
catch: (cause) => execError("result", cause)
|
|
1385
|
+
}).pipe(Effect.map(wrapRuntimeResult));
|
|
1386
|
+
const kill = Effect.fn("ComputerWorkspace.runtime.run.kill", { attributes: {
|
|
1387
|
+
family: "runtime",
|
|
1388
|
+
operation: "run.kill",
|
|
1389
|
+
runId: handle.id
|
|
1390
|
+
} })(function* (signal) {
|
|
1391
|
+
yield* Effect.tryPromise({
|
|
1392
|
+
try: () => handle.kill(signal),
|
|
1393
|
+
catch: (cause) => execError("run.kill", cause)
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1396
|
+
return {
|
|
1397
|
+
id: handle.id,
|
|
1398
|
+
backend: handle.backend,
|
|
1399
|
+
events,
|
|
1400
|
+
result,
|
|
1401
|
+
kill
|
|
1402
|
+
};
|
|
1403
|
+
};
|
|
1404
|
+
const releaseRun = (handle) => Effect.sync(() => handle[Symbol.dispose]());
|
|
1405
|
+
const makeRuntime = (client) => {
|
|
1406
|
+
const execImplementation = Effect.fn("ComputerWorkspace.runtime.exec", { attributes: {
|
|
1407
|
+
family: "runtime",
|
|
1408
|
+
operation: "exec"
|
|
1409
|
+
} })(function* (source, optionsOrValue, ...remainingValues) {
|
|
1410
|
+
const options = typeof source === "string" ? optionsOrValue : void 0;
|
|
1411
|
+
yield* Effect.annotateCurrentSpan({
|
|
1412
|
+
backend: options?.backend,
|
|
1413
|
+
runId: options?.id
|
|
1414
|
+
});
|
|
1415
|
+
const handle = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
1416
|
+
try: () => {
|
|
1417
|
+
if (typeof source === "string") return client.runtime.exec(source, runtimeExecOptions(options));
|
|
1418
|
+
const values = optionsOrValue === void 0 ? remainingValues : [optionsOrValue, ...remainingValues];
|
|
1419
|
+
return client.runtime.exec(source, ...values);
|
|
1420
|
+
},
|
|
1421
|
+
catch: (cause) => execError("exec", cause)
|
|
1422
|
+
}), releaseRun);
|
|
1423
|
+
return wrapRun(handle);
|
|
1424
|
+
});
|
|
1425
|
+
const exec = execImplementation;
|
|
1426
|
+
const getExec = Effect.fn("ComputerWorkspace.runtime.getExec", { attributes: {
|
|
1427
|
+
family: "runtime",
|
|
1428
|
+
operation: "getExec"
|
|
1429
|
+
} })(function* (id, options) {
|
|
1430
|
+
yield* Effect.annotateCurrentSpan({
|
|
1431
|
+
backend: options?.backend,
|
|
1432
|
+
runId: id
|
|
1433
|
+
});
|
|
1434
|
+
const handle = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
1435
|
+
try: () => client.runtime.getExec(id, runtimeGetOptions(options)),
|
|
1436
|
+
catch: (cause) => execError("getExec", cause)
|
|
1437
|
+
}), releaseRun);
|
|
1438
|
+
return wrapRun(handle);
|
|
1439
|
+
});
|
|
1440
|
+
const killExec = Effect.fn("ComputerWorkspace.runtime.killExec", { attributes: {
|
|
1441
|
+
family: "runtime",
|
|
1442
|
+
operation: "killExec"
|
|
1443
|
+
} })(function* (id, options) {
|
|
1444
|
+
yield* Effect.annotateCurrentSpan({
|
|
1445
|
+
backend: options?.backend,
|
|
1446
|
+
runId: id
|
|
1447
|
+
});
|
|
1448
|
+
yield* Effect.tryPromise({
|
|
1449
|
+
try: () => client.runtime.killExec(id, options),
|
|
1450
|
+
catch: (cause) => execError("killExec", cause)
|
|
1451
|
+
});
|
|
1452
|
+
});
|
|
1453
|
+
const disposeExec = Effect.fn("ComputerWorkspace.runtime.disposeExec", { attributes: {
|
|
1454
|
+
family: "runtime",
|
|
1455
|
+
operation: "disposeExec"
|
|
1456
|
+
} })(function* (id, options) {
|
|
1457
|
+
yield* Effect.annotateCurrentSpan({
|
|
1458
|
+
backend: options?.backend,
|
|
1459
|
+
runId: id
|
|
1460
|
+
});
|
|
1461
|
+
yield* Effect.tryPromise({
|
|
1462
|
+
try: () => client.runtime.disposeExec(id, options),
|
|
1463
|
+
catch: (cause) => execError("disposeExec", cause)
|
|
1464
|
+
});
|
|
1465
|
+
});
|
|
1466
|
+
return {
|
|
1467
|
+
exec,
|
|
1468
|
+
execCollect: Effect.fn("ComputerWorkspace.runtime.execCollect", { attributes: {
|
|
1469
|
+
family: "runtime",
|
|
1470
|
+
operation: "execCollect"
|
|
1471
|
+
} })(function* (source, optionsOrValue, ...remainingValues) {
|
|
1472
|
+
return yield* Effect.scoped(Effect.gen(function* () {
|
|
1473
|
+
return yield* (yield* execImplementation(source, optionsOrValue, ...remainingValues)).result;
|
|
1474
|
+
}));
|
|
1475
|
+
}),
|
|
1476
|
+
getExec,
|
|
1477
|
+
killExec,
|
|
1478
|
+
disposeExec
|
|
1479
|
+
};
|
|
1480
|
+
};
|
|
1481
|
+
const makeAssets = (client) => client === void 0 ? void 0 : { share: Effect.fn("ComputerWorkspace.assets.share", { attributes: {
|
|
1482
|
+
family: "assets",
|
|
1483
|
+
operation: "share"
|
|
1484
|
+
} })(function* (path, options) {
|
|
1485
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1486
|
+
return yield* Effect.tryPromise({
|
|
1487
|
+
try: () => client.share(path, options),
|
|
1488
|
+
catch: (cause) => assetsError("share", path, cause)
|
|
1489
|
+
});
|
|
1490
|
+
}) };
|
|
1491
|
+
const makeThink = (client) => {
|
|
1492
|
+
if (client.readFile === void 0 || client.readFileBytes === void 0 || client.writeFile === void 0 || client.readDir === void 0 || client.rm === void 0 || client.glob === void 0 || client.mkdir === void 0 || client.stat === void 0) return;
|
|
1493
|
+
const method = (operation, pathOf, evaluate) => Effect.fn(`ComputerWorkspace.think.${operation}`, { attributes: {
|
|
1494
|
+
family: "think",
|
|
1495
|
+
operation
|
|
1496
|
+
} })(function* (...args) {
|
|
1497
|
+
const path = pathOf(...args);
|
|
1498
|
+
yield* Effect.annotateCurrentSpan("path", path);
|
|
1499
|
+
return yield* tryFs(`think.${operation}`, path, () => evaluate(...args));
|
|
1500
|
+
});
|
|
1501
|
+
return {
|
|
1502
|
+
readFile: method("readFile", (path) => path, (path) => client.readFile(path)),
|
|
1503
|
+
readFileBytes: method("readFileBytes", (path) => path, (path) => client.readFileBytes(path)),
|
|
1504
|
+
writeFile: method("writeFile", (path, _content) => path, (path, content) => client.writeFile(path, content)),
|
|
1505
|
+
readDir: method("readDir", (path, _options) => path, (path, options) => client.readDir(path, options)),
|
|
1506
|
+
rm: method("rm", (path, _options) => path, (path, options) => client.rm(path, options)),
|
|
1507
|
+
glob: method("glob", (pattern) => pattern, (pattern) => client.glob(pattern)),
|
|
1508
|
+
mkdir: method("mkdir", (path, _options) => path, (path, options) => client.mkdir(path, options)),
|
|
1509
|
+
stat: method("stat", (path) => path, (path) => client.stat(path))
|
|
1510
|
+
};
|
|
1511
|
+
};
|
|
1512
|
+
/**
|
|
1513
|
+
* Wraps a client whose lifetime is owned by the caller. Prefer
|
|
1514
|
+
* {@link ComputerWorkspace.layer} in Durable Objects so the parent client and
|
|
1515
|
+
* every runtime handle are disposed by Effect `Scope`.
|
|
1516
|
+
*/
|
|
1517
|
+
const fromWorkspaceClient = (client) => {
|
|
1518
|
+
const fs = makeFilesystem(client.fs);
|
|
1519
|
+
const git = makeGit(client.git);
|
|
1520
|
+
const runtime = makeRuntime(client);
|
|
1521
|
+
return {
|
|
1522
|
+
fs,
|
|
1523
|
+
git,
|
|
1524
|
+
runtime,
|
|
1525
|
+
artifacts: fromClient(client.artifacts, { binding: "ComputerWorkspace.artifacts" }),
|
|
1526
|
+
assets: makeAssets(client.assets),
|
|
1527
|
+
think: makeThink(client),
|
|
1528
|
+
readFile: fs.readFile,
|
|
1529
|
+
stat: fs.stat,
|
|
1530
|
+
lstat: fs.lstat,
|
|
1531
|
+
exists: fs.exists,
|
|
1532
|
+
readlink: fs.readlink,
|
|
1533
|
+
readdir: fs.readdir,
|
|
1534
|
+
listDirectory: fs.readdir,
|
|
1535
|
+
find: fs.find,
|
|
1536
|
+
ls: fs.ls,
|
|
1537
|
+
grep: fs.grep,
|
|
1538
|
+
writeFile: fs.writeFile,
|
|
1539
|
+
mkdir: fs.mkdir,
|
|
1540
|
+
rm: fs.rm,
|
|
1541
|
+
removePath: fs.rm,
|
|
1542
|
+
chmod: fs.chmod,
|
|
1543
|
+
symlink: fs.symlink,
|
|
1544
|
+
exec: runtime.exec,
|
|
1545
|
+
execCollect: runtime.execCollect,
|
|
1546
|
+
getExec: runtime.getExec,
|
|
1547
|
+
killExec: runtime.killExec,
|
|
1548
|
+
disposeExec: runtime.disposeExec
|
|
1549
|
+
};
|
|
1550
|
+
};
|
|
1551
|
+
/** Effect service for the workspace owned by the enclosing Durable Object. */
|
|
1552
|
+
var ComputerWorkspace = class ComputerWorkspace extends Context.Service()("effect-cf/ComputerWorkspace") {
|
|
1553
|
+
/**
|
|
1554
|
+
* Acquires the single workspace registered by `withComputerWorkspace` and
|
|
1555
|
+
* releases its RPC client when the layer scope closes.
|
|
1556
|
+
*/
|
|
1557
|
+
static layer = Layer.effect(ComputerWorkspace, Effect.gen(function* () {
|
|
1558
|
+
const host = lookup((yield* DurableObjectState).raw);
|
|
1559
|
+
if (host === void 0) return yield* Effect.die("ComputerWorkspace.layer requires a Durable Object class built with withComputerWorkspace");
|
|
1560
|
+
const computer = yield* Effect.promise(() => import("@cloudflare/computer"));
|
|
1561
|
+
const client = yield* Effect.acquireRelease(Effect.promise(() => computer.getWorkspace(host)), (workspace) => Effect.sync(() => workspace[Symbol.dispose]()));
|
|
1562
|
+
return ComputerWorkspace.of(fromWorkspaceClient(client));
|
|
1563
|
+
}));
|
|
1564
|
+
};
|
|
1565
|
+
//#endregion
|
|
801
1566
|
//#region src/ContainerNamespace.ts
|
|
802
1567
|
var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
803
1568
|
ContainerNamespace: () => ContainerNamespace,
|
|
@@ -920,7 +1685,7 @@ const makeClient$10 = (definition) => (namespace) => {
|
|
|
920
1685
|
rawUnsafe: Effect.succeed(namespace)
|
|
921
1686
|
};
|
|
922
1687
|
};
|
|
923
|
-
const layer$12 = (tag, definition) => layer$
|
|
1688
|
+
const layer$12 = (tag, definition) => layer$20(tag, definition.binding, isContainerNamespaceResource, makeClient$10(definition), { expected: expectedContainerNamespace });
|
|
924
1689
|
const make$14 = (id) => Tag$12()(id);
|
|
925
1690
|
/** Creates a typed Effect service for a Cloudflare Container namespace. */
|
|
926
1691
|
const Tag$12 = () => (id) => {
|
|
@@ -1066,7 +1831,7 @@ const makeClient$9 = (definition) => {
|
|
|
1066
1831
|
rawUnsafe: Effect.succeed(queue)
|
|
1067
1832
|
});
|
|
1068
1833
|
};
|
|
1069
|
-
const layer$11 = (tag, definition) => layer$
|
|
1834
|
+
const layer$11 = (tag, definition) => layer$20(tag, definition.binding, (value) => isQueue(value), makeClient$9(definition), { expected: expectedQueueProducer });
|
|
1070
1835
|
//#endregion
|
|
1071
1836
|
//#region src/QueueDefinition.ts
|
|
1072
1837
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1527,7 +2292,7 @@ const makeClient$8 = (definition) => {
|
|
|
1527
2292
|
});
|
|
1528
2293
|
};
|
|
1529
2294
|
};
|
|
1530
|
-
const layer$10 = (tag, definition) => layer$
|
|
2295
|
+
const layer$10 = (tag, definition) => layer$20(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$8(definition), { expected: expectedServiceBinding });
|
|
1531
2296
|
/**
|
|
1532
2297
|
* Creates a typed Effect service for a Worker service binding.
|
|
1533
2298
|
*
|
|
@@ -1928,7 +2693,7 @@ const makeClient$7 = (definition) => {
|
|
|
1928
2693
|
});
|
|
1929
2694
|
};
|
|
1930
2695
|
};
|
|
1931
|
-
const layer$9 = (tag, definition) => layer$
|
|
2696
|
+
const layer$9 = (tag, definition) => layer$20(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$7(definition), { expected: expectedDurableObjectNamespace });
|
|
1932
2697
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1933
2698
|
const methods = {};
|
|
1934
2699
|
if (rpcDefinition !== void 0) {
|
|
@@ -2118,12 +2883,11 @@ const make$7 = (layer, options = {}) => {
|
|
|
2118
2883
|
alarm(alarmInfo) {
|
|
2119
2884
|
const logicalAlarms = options.alarms?.pipe(Effect.asVoid);
|
|
2120
2885
|
const rawAlarm = options.alarm?.(alarmInfo);
|
|
2121
|
-
|
|
2886
|
+
const alarmEffect = logicalAlarms !== void 0 && rawAlarm !== void 0 ? Effect.gen(function* () {
|
|
2122
2887
|
yield* logicalAlarms;
|
|
2123
2888
|
yield* rawAlarm;
|
|
2124
|
-
})
|
|
2125
|
-
if (
|
|
2126
|
-
if (rawAlarm !== void 0) return this[RunSymbol](rawAlarm);
|
|
2889
|
+
}) : logicalAlarms ?? rawAlarm;
|
|
2890
|
+
if (alarmEffect !== void 0) return this[RunSymbol](alarmEffect.pipe(Effect.onExit(() => scheduleTelemetryFlush)));
|
|
2127
2891
|
}
|
|
2128
2892
|
webSocketMessage(socket, message) {
|
|
2129
2893
|
if (options.webSocketMessage !== void 0) return this[RunSymbol](options.webSocketMessage(fromWebSocket(socket), message));
|
|
@@ -2865,7 +3629,7 @@ const makeClient$6 = (definition, options) => (email) => {
|
|
|
2865
3629
|
rawUnsafe: Effect.succeed(email)
|
|
2866
3630
|
};
|
|
2867
3631
|
};
|
|
2868
|
-
const layer$6 = (tag, definition) => layer$
|
|
3632
|
+
const layer$6 = (tag, definition) => layer$20(tag, definition.binding, isEmailBinding, makeClient$6(definition, definition.send), { expected: expectedSendEmailBinding });
|
|
2869
3633
|
const make$6 = (id) => Tag$7()(id);
|
|
2870
3634
|
const Tag$7 = () => (id) => {
|
|
2871
3635
|
const tag = Context.Service()(id);
|
|
@@ -2894,7 +3658,7 @@ const makeClient$5 = (definition) => (hyperdrive) => ({
|
|
|
2894
3658
|
connectionString: hyperdrive.connectionString,
|
|
2895
3659
|
rawUnsafe: Effect.succeed(hyperdrive)
|
|
2896
3660
|
});
|
|
2897
|
-
const layer$5 = (tag, definition) => layer$
|
|
3661
|
+
const layer$5 = (tag, definition) => layer$20(tag, definition.binding, isHyperdrive, makeClient$5(definition), { expected: expectedHyperdrive });
|
|
2898
3662
|
const make$5 = (id) => Tag$6()(id);
|
|
2899
3663
|
const Tag$6 = () => (id) => {
|
|
2900
3664
|
const tag = Context.Service()(id);
|
|
@@ -2991,7 +3755,7 @@ const makeClient$4 = (definition) => (images) => {
|
|
|
2991
3755
|
rawUnsafe: Effect.succeed(images)
|
|
2992
3756
|
};
|
|
2993
3757
|
};
|
|
2994
|
-
const layer$4 = (tag, definition) => layer$
|
|
3758
|
+
const layer$4 = (tag, definition) => layer$20(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
|
|
2995
3759
|
const make$4 = (id) => Tag$5()(id);
|
|
2996
3760
|
const Tag$5 = () => (id) => {
|
|
2997
3761
|
const tag = Context.Service()(id);
|
|
@@ -3104,7 +3868,7 @@ const makeClient$3 = (definition) => {
|
|
|
3104
3868
|
rawUnsafe: Effect.succeed(kv)
|
|
3105
3869
|
});
|
|
3106
3870
|
};
|
|
3107
|
-
const layer$3 = (tag, definition) => layer$
|
|
3871
|
+
const layer$3 = (tag, definition) => layer$20(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
|
|
3108
3872
|
const makeDefinition$1 = (id, definition) => {
|
|
3109
3873
|
const kvDefinition = {
|
|
3110
3874
|
id,
|
|
@@ -3228,7 +3992,7 @@ const makeClient$2 = (definition) => {
|
|
|
3228
3992
|
};
|
|
3229
3993
|
};
|
|
3230
3994
|
};
|
|
3231
|
-
const layer$2 = (tag, definition) => layer$
|
|
3995
|
+
const layer$2 = (tag, definition) => layer$20(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
|
|
3232
3996
|
const make$3 = (id) => Tag$3()(id);
|
|
3233
3997
|
const Tag$3 = () => (id) => {
|
|
3234
3998
|
const tag = Context.Service()(id);
|
|
@@ -3286,7 +4050,7 @@ const makeClient$1 = (definition) => (index) => {
|
|
|
3286
4050
|
rawUnsafe: Effect.succeed(index)
|
|
3287
4051
|
};
|
|
3288
4052
|
};
|
|
3289
|
-
const layer$1 = (tag, definition) => layer$
|
|
4053
|
+
const layer$1 = (tag, definition) => layer$20(tag, definition.binding, isVectorizeBinding, makeClient$1(definition), { expected: expectedVectorizeBinding });
|
|
3290
4054
|
const make$2 = (id) => Tag$2()(id);
|
|
3291
4055
|
const Tag$2 = () => (id) => {
|
|
3292
4056
|
const tag = Context.Service()(id);
|
|
@@ -3297,6 +4061,71 @@ const Tag$2 = () => (id) => {
|
|
|
3297
4061
|
});
|
|
3298
4062
|
};
|
|
3299
4063
|
//#endregion
|
|
4064
|
+
//#region src/WebTransport.ts
|
|
4065
|
+
var WebTransport_exports = /* @__PURE__ */ __exportAll({
|
|
4066
|
+
InboundTransport: () => InboundTransport,
|
|
4067
|
+
WebTransportUnsupportedError: () => WebTransportUnsupportedError,
|
|
4068
|
+
capabilities: () => capabilities,
|
|
4069
|
+
inboundSessionsUnsupported: () => inboundSessionsUnsupported,
|
|
4070
|
+
inboundTransport: () => inboundTransport,
|
|
4071
|
+
isHttp3: () => isHttp3
|
|
4072
|
+
});
|
|
4073
|
+
/**
|
|
4074
|
+
* Metadata Cloudflare's edge reports about the inbound client connection.
|
|
4075
|
+
*
|
|
4076
|
+
* `httpProtocol` and `clientTcpRtt` are declared in
|
|
4077
|
+
* `@cloudflare/workers-types`; `clientQuicRtt` is documented by Cloudflare
|
|
4078
|
+
* ("only present when the client connected over QUIC (HTTP/3)") but not yet
|
|
4079
|
+
* present in the published types, so it is decoded from the open
|
|
4080
|
+
* `Record<string, unknown>` side of `request.cf`.
|
|
4081
|
+
*/
|
|
4082
|
+
var InboundTransport = class extends Schema.Class("InboundTransport")({
|
|
4083
|
+
/** The HTTP protocol the client used, e.g. `"HTTP/2"` or `"HTTP/3"`. */
|
|
4084
|
+
httpProtocol: Schema.String,
|
|
4085
|
+
/** Client round-trip time; only present for QUIC (HTTP/3) connections. */
|
|
4086
|
+
clientQuicRtt: Schema.optional(Schema.Number),
|
|
4087
|
+
/** Client round-trip time; only present for TCP (HTTP/1.x, HTTP/2) connections. */
|
|
4088
|
+
clientTcpRtt: Schema.optional(Schema.Number)
|
|
4089
|
+
}) {};
|
|
4090
|
+
const decodeInboundTransport = Schema.decodeUnknownResult(InboundTransport);
|
|
4091
|
+
/**
|
|
4092
|
+
* Decodes the inbound transport metadata from `request.cf`.
|
|
4093
|
+
*
|
|
4094
|
+
* Returns `None` when the metadata is absent (for example in local `wrangler
|
|
4095
|
+
* dev` or when a Worker invokes another Worker directly) or does not match
|
|
4096
|
+
* the expected shape.
|
|
4097
|
+
*/
|
|
4098
|
+
const inboundTransport = (request) => Result.getSuccess(decodeInboundTransport(request.cf));
|
|
4099
|
+
/**
|
|
4100
|
+
* Returns `true` when the client reached Cloudflare's edge over QUIC
|
|
4101
|
+
* (HTTP/3). Prefers the documented QUIC signal (`clientQuicRtt` is only
|
|
4102
|
+
* present for QUIC connections) and falls back to the `httpProtocol` string.
|
|
4103
|
+
*
|
|
4104
|
+
* Note this describes the browser→edge hop only: the edge always terminates
|
|
4105
|
+
* QUIC, and the Worker still handles an ordinary `fetch` Request.
|
|
4106
|
+
*/
|
|
4107
|
+
const isHttp3 = (transport) => transport.clientQuicRtt !== void 0 || transport.httpProtocol === "HTTP/3";
|
|
4108
|
+
/** Feature-detects the WebTransport capabilities of the current runtime. */
|
|
4109
|
+
const capabilities = Effect.sync(() => ({
|
|
4110
|
+
inboundSessions: false,
|
|
4111
|
+
outboundSessions: typeof globalThis["WebTransport"] === "function"
|
|
4112
|
+
}));
|
|
4113
|
+
/** Raised when a WebTransport capability is unavailable in this runtime. */
|
|
4114
|
+
var WebTransportUnsupportedError = class extends Data.TaggedError("WebTransportUnsupportedError") {
|
|
4115
|
+
get message() {
|
|
4116
|
+
return this.capability === "inbound-sessions" ? "Cloudflare Workers cannot accept inbound WebTransport sessions: the edge terminates QUIC and no runtime session API exists (cloudflare/workerd#6451). Use Durable Object WebSockets for bidirectional push." : "This Workers runtime provides no WebTransport client: workerd has no QUIC stack and cloudflare:sockets is TCP-only.";
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
/**
|
|
4120
|
+
* The explicit typed boundary for inbound WebTransport sessions.
|
|
4121
|
+
*
|
|
4122
|
+
* Always fails with {@link WebTransportUnsupportedError} today. Route the
|
|
4123
|
+
* code path that would accept a session through this effect so the
|
|
4124
|
+
* limitation is visible in the type system and greppable when Cloudflare
|
|
4125
|
+
* ships a real API.
|
|
4126
|
+
*/
|
|
4127
|
+
const inboundSessionsUnsupported = Effect.fail(new WebTransportUnsupportedError({ capability: "inbound-sessions" }));
|
|
4128
|
+
//#endregion
|
|
3300
4129
|
//#region src/WorkflowBinding.ts
|
|
3301
4130
|
var WorkflowBinding_exports = /* @__PURE__ */ __exportAll({
|
|
3302
4131
|
WorkflowOperationError: () => WorkflowOperationError,
|
|
@@ -3387,7 +4216,7 @@ const makeClient = (definition) => {
|
|
|
3387
4216
|
rawUnsafe: Effect.succeed(workflow)
|
|
3388
4217
|
});
|
|
3389
4218
|
};
|
|
3390
|
-
const layer = (tag, definition) => layer$
|
|
4219
|
+
const layer = (tag, definition) => layer$20(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition), { expected: expectedWorkflow });
|
|
3391
4220
|
//#endregion
|
|
3392
4221
|
//#region src/WorkflowDefinition.ts
|
|
3393
4222
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -3408,7 +4237,7 @@ const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
|
3408
4237
|
const Tag$1 = () => (id, definition) => {
|
|
3409
4238
|
const workflowDefinition = makeDefinition(id, definition);
|
|
3410
4239
|
const tag = Context.Service()(`effect-cf/Workflow/${id}`);
|
|
3411
|
-
const layer$
|
|
4240
|
+
const layer$21 = (binding) => layer(tag, {
|
|
3412
4241
|
...binding,
|
|
3413
4242
|
payload: definition.payload,
|
|
3414
4243
|
result: definition.result
|
|
@@ -3428,7 +4257,7 @@ const Tag$1 = () => (id, definition) => {
|
|
|
3428
4257
|
payload: workflowDefinition.payload,
|
|
3429
4258
|
result: workflowDefinition.result,
|
|
3430
4259
|
make: workflowDefinition.make,
|
|
3431
|
-
layer: layer$
|
|
4260
|
+
layer: layer$21,
|
|
3432
4261
|
create,
|
|
3433
4262
|
createBatch,
|
|
3434
4263
|
get,
|
|
@@ -3546,4 +4375,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1, (workflow
|
|
|
3546
4375
|
const Tag = Tag$1;
|
|
3547
4376
|
const implement = implement$1;
|
|
3548
4377
|
//#endregion
|
|
3549
|
-
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp, ContainerNamespace_exports as ContainerNamespace, 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, Email_exports as Email, Environment_exports as Environment, 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 };
|
|
4378
|
+
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Artifacts_exports as Artifacts, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp, ComputerArtifacts_exports as ComputerArtifacts, ComputerWorkspace_exports as ComputerWorkspace, ContainerNamespace_exports as ContainerNamespace, 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, Email_exports as Email, Environment_exports as Environment, 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, WebTransport_exports as WebTransport, 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 };
|