effect-cf 0.26.0 → 0.28.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +8 -6
  3. package/dist/{Artifacts-DcoXcRP5.d.mts → Artifacts-DnHQA-Ax.d.mts} +42 -25
  4. package/dist/Artifacts-rq3hUKQE.mjs +257 -0
  5. package/dist/{Binding-COCtoJXa.d.mts → Binding-xJJJPmiD.d.mts} +6 -5
  6. package/dist/ComputerArtifacts.d.mts +55 -0
  7. package/dist/ComputerArtifacts.mjs +95 -0
  8. package/dist/ComputerWorkspace.d.mts +279 -0
  9. package/dist/ComputerWorkspace.mjs +577 -0
  10. package/dist/ComputerWorkspaceHost.d.mts +1 -1
  11. package/dist/ComputerWorkspaceHost.mjs +18 -16
  12. package/dist/{WorkflowBinding-D5iWzCUa.d.mts → DurableObjectState-B3uFY1eM.d.mts} +90 -141
  13. package/dist/{DurableObjectState-CEh0DVw7.mjs → DurableObjectState-BjkK2kwH.mjs} +4 -49
  14. package/dist/ErrorMessage-BM0K-Nik.mjs +46 -0
  15. package/dist/{Hyperdrive-6p59yyVk.d.mts → Hyperdrive-z-9fFz15.d.mts} +2 -2
  16. package/dist/HyperdrivePg.d.mts +2 -2
  17. package/dist/Vitest.d.mts +6 -4
  18. package/dist/Vitest.mjs +2 -1
  19. package/dist/WorkflowBinding-wZ-yGHow.d.mts +74 -0
  20. package/dist/index.d.mts +92 -398
  21. package/dist/index.mjs +323 -1105
  22. package/package.json +12 -1
  23. package/src/AiGateway.ts +62 -7
  24. package/src/AnalyticsEngine.ts +17 -13
  25. package/src/Artifacts.ts +111 -47
  26. package/src/Binding.ts +34 -23
  27. package/src/BrowserRendering.ts +72 -33
  28. package/src/CloudflareOtlp.ts +8 -5
  29. package/src/ComputerArtifacts.ts +17 -9
  30. package/src/ComputerWorkspace.ts +202 -98
  31. package/src/ComputerWorkspaceHost.ts +55 -27
  32. package/src/ContainerNamespace.ts +8 -9
  33. package/src/D1.ts +8 -14
  34. package/src/DurableObject.ts +27 -11
  35. package/src/DurableObjectAlarm.ts +17 -5
  36. package/src/DurableObjectDefinition.ts +89 -72
  37. package/src/DurableObjectNamespace.ts +26 -12
  38. package/src/DurableObjectRpcWebSocket.ts +9 -10
  39. package/src/DurableObjectState.ts +1 -0
  40. package/src/DurableObjectStorage.ts +5 -2
  41. package/src/DurableObjectWebSocket.ts +4 -1
  42. package/src/Email.ts +26 -25
  43. package/src/Hyperdrive.ts +4 -10
  44. package/src/Images.ts +12 -14
  45. package/src/Kv.ts +15 -17
  46. package/src/Queue.ts +2 -1
  47. package/src/QueueBinding.ts +7 -12
  48. package/src/QueueDefinition.ts +7 -2
  49. package/src/R2.ts +33 -24
  50. package/src/Rpc.ts +15 -21
  51. package/src/RpcDefinition.ts +33 -38
  52. package/src/ServiceBinding.ts +26 -8
  53. package/src/Vectorize.ts +45 -18
  54. package/src/Vitest.ts +9 -3
  55. package/src/WebTransport.ts +11 -5
  56. package/src/Worker.ts +91 -21
  57. package/src/WorkerDefinition.ts +143 -63
  58. package/src/WorkersAi.ts +50 -28
  59. package/src/Workflow.ts +66 -13
  60. package/src/WorkflowBinding.ts +18 -25
  61. package/src/WorkflowDefinition.ts +4 -2
  62. package/src/index.ts +0 -2
  63. package/src/internal/Entrypoint.ts +29 -13
  64. package/src/internal/ErrorMessage.ts +7 -6
  65. package/src/internal/RpcInvocation.ts +34 -11
  66. package/src/internal/Runtime.ts +33 -22
  67. package/src/internal/WorkerContext.ts +3 -3
@@ -0,0 +1,577 @@
1
+ import { t as DurableObjectState } from "./DurableObjectState-BjkK2kwH.mjs";
2
+ import { fromClient } from "./ComputerArtifacts.mjs";
3
+ import { t as lookup } from "./ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs";
4
+ import { Context, Effect, Layer, Predicate, Schema, Stream } from "effect";
5
+ //#region src/ComputerWorkspace.ts
6
+ /**
7
+ * Workspace errors use `Schema.TaggedError`, unlike most local binding errors,
8
+ * because workspace operations commonly sit behind Durable Object RPC methods.
9
+ * The schema form preserves the operation-family tags across that boundary.
10
+ */
11
+ var WorkspaceFsError = class extends Schema.TaggedError()("WorkspaceFsError", {
12
+ operation: Schema.String,
13
+ path: Schema.String,
14
+ message: Schema.String,
15
+ code: Schema.optionalKey(Schema.String),
16
+ cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
17
+ }) {};
18
+ /** Schema-serializable error for a workspace Git operation. */
19
+ var WorkspaceGitError = class extends Schema.TaggedError()("WorkspaceGitError", {
20
+ operation: Schema.String,
21
+ message: Schema.String,
22
+ code: Schema.optionalKey(Schema.String),
23
+ cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
24
+ }) {};
25
+ /** Schema-serializable error for a workspace runtime operation. */
26
+ var WorkspaceExecError = class extends Schema.TaggedError()("WorkspaceExecError", {
27
+ operation: Schema.String,
28
+ message: Schema.String,
29
+ code: Schema.optionalKey(Schema.String),
30
+ cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
31
+ }) {};
32
+ /** Schema-serializable error for a workspace Assets operation. */
33
+ var WorkspaceAssetsError = class extends Schema.TaggedError()("WorkspaceAssetsError", {
34
+ operation: Schema.String,
35
+ path: Schema.String,
36
+ message: Schema.String,
37
+ code: Schema.optionalKey(Schema.String),
38
+ cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
39
+ }) {};
40
+ const errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
41
+ const errorCode = (cause) => {
42
+ if (Predicate.hasProperty(cause, "code") && Predicate.isString(cause.code)) return cause.code;
43
+ };
44
+ const fsError = (operation, path, cause) => {
45
+ const properties = {
46
+ operation,
47
+ path,
48
+ message: errorMessage(cause),
49
+ cause
50
+ };
51
+ const code = errorCode(cause);
52
+ if (code !== void 0) properties.code = code;
53
+ return WorkspaceFsError.make(properties);
54
+ };
55
+ const gitError = (operation, cause) => {
56
+ const properties = {
57
+ operation,
58
+ message: errorMessage(cause),
59
+ cause
60
+ };
61
+ const code = errorCode(cause);
62
+ if (code !== void 0) properties.code = code;
63
+ return WorkspaceGitError.make(properties);
64
+ };
65
+ const execError = (operation, cause) => {
66
+ const properties = {
67
+ operation,
68
+ message: errorMessage(cause),
69
+ cause
70
+ };
71
+ const code = errorCode(cause);
72
+ if (code !== void 0) properties.code = code;
73
+ return WorkspaceExecError.make(properties);
74
+ };
75
+ const assetsError = (operation, path, cause) => {
76
+ const properties = {
77
+ operation,
78
+ path,
79
+ message: errorMessage(cause),
80
+ cause
81
+ };
82
+ const code = errorCode(cause);
83
+ if (code !== void 0) properties.code = code;
84
+ return WorkspaceAssetsError.make(properties);
85
+ };
86
+ const tryFs = (operation, path, evaluate) => Effect.tryPromise({
87
+ try: evaluate,
88
+ catch: (cause) => fsError(operation, path, cause)
89
+ });
90
+ const isNotFound = (error) => error.code === "ENOENT" || /ENOENT|no such/i.test(error.message);
91
+ const makeFilesystem = (fsClient) => {
92
+ const readFile = Effect.fn("ComputerWorkspace.fs.readFile", { attributes: {
93
+ family: "fs",
94
+ operation: "readFile"
95
+ } })(function* (path, options = {}) {
96
+ yield* Effect.annotateCurrentSpan("path", path);
97
+ const { encoding = "utf8", ...readOptions } = options;
98
+ if (encoding === "stream") return yield* tryFs("readFile", path, () => fsClient.readFile(path, readOptions));
99
+ return yield* tryFs("readFile", path, () => fsClient.readFile(path, {
100
+ ...readOptions,
101
+ encoding: "utf8"
102
+ }));
103
+ });
104
+ const stat = Effect.fn("ComputerWorkspace.fs.stat", { attributes: {
105
+ family: "fs",
106
+ operation: "stat"
107
+ } })(function* (path) {
108
+ yield* Effect.annotateCurrentSpan("path", path);
109
+ return yield* tryFs("stat", path, () => fsClient.stat(path));
110
+ });
111
+ return {
112
+ readFile,
113
+ stat,
114
+ lstat: Effect.fn("ComputerWorkspace.fs.lstat", { attributes: {
115
+ family: "fs",
116
+ operation: "lstat"
117
+ } })(function* (path) {
118
+ yield* Effect.annotateCurrentSpan("path", path);
119
+ return yield* tryFs("lstat", path, () => fsClient.lstat(path));
120
+ }),
121
+ exists: Effect.fn("ComputerWorkspace.fs.exists", { attributes: {
122
+ family: "fs",
123
+ operation: "exists"
124
+ } })(function* (path) {
125
+ yield* Effect.annotateCurrentSpan("path", path);
126
+ return yield* stat(path).pipe(Effect.as(true), Effect.catch((error) => isNotFound(error) ? Effect.succeed(false) : Effect.fail(error)));
127
+ }),
128
+ readlink: Effect.fn("ComputerWorkspace.fs.readlink", { attributes: {
129
+ family: "fs",
130
+ operation: "readlink"
131
+ } })(function* (path) {
132
+ yield* Effect.annotateCurrentSpan("path", path);
133
+ return yield* tryFs("readlink", path, () => fsClient.readlink(path));
134
+ }),
135
+ readdir: Effect.fn("ComputerWorkspace.fs.readdir", { attributes: {
136
+ family: "fs",
137
+ operation: "readdir"
138
+ } })(function* (path, options) {
139
+ yield* Effect.annotateCurrentSpan("path", path);
140
+ return yield* tryFs("readdir", path, () => fsClient.readdir(path, options));
141
+ }),
142
+ find: Effect.fn("ComputerWorkspace.fs.find", { attributes: {
143
+ family: "fs",
144
+ operation: "find"
145
+ } })(function* (directory, pattern, options) {
146
+ yield* Effect.annotateCurrentSpan({
147
+ path: directory,
148
+ pattern
149
+ });
150
+ return yield* tryFs("find", directory, () => fsClient.find(directory, pattern, options));
151
+ }),
152
+ ls: Effect.fn("ComputerWorkspace.fs.ls", { attributes: {
153
+ family: "fs",
154
+ operation: "ls"
155
+ } })(function* (prefix) {
156
+ yield* Effect.annotateCurrentSpan("path", prefix);
157
+ return yield* tryFs("ls", prefix, () => fsClient.ls(prefix));
158
+ }),
159
+ grep: Effect.fn("ComputerWorkspace.fs.grep", { attributes: {
160
+ family: "fs",
161
+ operation: "grep"
162
+ } })(function* (pattern, path, options) {
163
+ yield* Effect.annotateCurrentSpan({
164
+ path,
165
+ pattern
166
+ });
167
+ return yield* tryFs("grep", path, () => fsClient.grep(pattern, path, options));
168
+ }),
169
+ writeFile: Effect.fn("ComputerWorkspace.fs.writeFile", { attributes: {
170
+ family: "fs",
171
+ operation: "writeFile"
172
+ } })(function* (path, content, options) {
173
+ yield* Effect.annotateCurrentSpan("path", path);
174
+ yield* tryFs("writeFile", path, () => fsClient.writeFile(path, content, options));
175
+ }),
176
+ mkdir: Effect.fn("ComputerWorkspace.fs.mkdir", { attributes: {
177
+ family: "fs",
178
+ operation: "mkdir"
179
+ } })(function* (path, options) {
180
+ yield* Effect.annotateCurrentSpan("path", path);
181
+ yield* tryFs("mkdir", path, () => fsClient.mkdir(path, options));
182
+ }),
183
+ rm: Effect.fn("ComputerWorkspace.fs.rm", { attributes: {
184
+ family: "fs",
185
+ operation: "rm"
186
+ } })(function* (path, options) {
187
+ yield* Effect.annotateCurrentSpan("path", path);
188
+ yield* tryFs("rm", path, () => fsClient.rm(path, options));
189
+ }),
190
+ chmod: Effect.fn("ComputerWorkspace.fs.chmod", { attributes: {
191
+ family: "fs",
192
+ operation: "chmod"
193
+ } })(function* (path, mode) {
194
+ yield* Effect.annotateCurrentSpan({
195
+ path,
196
+ mode
197
+ });
198
+ yield* tryFs("chmod", path, () => fsClient.chmod(path, mode));
199
+ }),
200
+ symlink: Effect.fn("ComputerWorkspace.fs.symlink", { attributes: {
201
+ family: "fs",
202
+ operation: "symlink"
203
+ } })(function* (target, path) {
204
+ yield* Effect.annotateCurrentSpan({
205
+ path,
206
+ target
207
+ });
208
+ yield* tryFs("symlink", path, () => fsClient.symlink(target, path));
209
+ })
210
+ };
211
+ };
212
+ const gitPerson = (person) => ({
213
+ ...person,
214
+ timestampSeconds: person.timestamp
215
+ });
216
+ const gitCommit = (commit) => ({
217
+ oid: commit.oid,
218
+ message: commit.message,
219
+ tree: commit.tree,
220
+ parent: commit.parent,
221
+ parents: commit.parent,
222
+ author: gitPerson(commit.author),
223
+ committer: gitPerson(commit.committer)
224
+ });
225
+ const makeGit = (gitClient) => {
226
+ const method = (operation, evaluate) => Effect.fn(`ComputerWorkspace.git.${operation}`, { attributes: {
227
+ family: "git",
228
+ operation
229
+ } })(function* (...args) {
230
+ return yield* Effect.tryPromise({
231
+ try: () => evaluate(...args),
232
+ catch: (cause) => gitError(operation, cause)
233
+ });
234
+ });
235
+ const log = Effect.fn("ComputerWorkspace.git.log", { attributes: {
236
+ family: "git",
237
+ operation: "log"
238
+ } })(function* (options) {
239
+ const { maxCount, ...upstreamOptions } = options ?? {};
240
+ const logOptions = { ...upstreamOptions };
241
+ if (logOptions.depth === void 0 && maxCount !== void 0) logOptions.depth = maxCount;
242
+ return (yield* Effect.tryPromise({
243
+ try: () => gitClient.log(logOptions),
244
+ catch: (cause) => gitError("log", cause)
245
+ })).map(gitCommit);
246
+ });
247
+ const revParse = Effect.fn("ComputerWorkspace.git.revParse", { attributes: {
248
+ family: "git",
249
+ operation: "revParse"
250
+ } })(function* (input) {
251
+ const options = Predicate.isString(input) ? { ref: input } : input;
252
+ return yield* Effect.tryPromise({
253
+ try: () => gitClient.revParse(options),
254
+ catch: (cause) => gitError("revParse", cause)
255
+ });
256
+ });
257
+ return {
258
+ clone: method("clone", (options) => gitClient.clone(options)),
259
+ diff: method("diff", (options) => gitClient.diff(options)),
260
+ diffSummary: method("diffSummary", (options) => gitClient.diffSummary(options)),
261
+ init: method("init", (options) => gitClient.init(options)),
262
+ status: method("status", (options) => gitClient.status(options)),
263
+ add: method("add", (options) => gitClient.add(options)),
264
+ rm: method("rm", (options) => gitClient.rm(options)),
265
+ commit: method("commit", (options) => gitClient.commit(options)),
266
+ log,
267
+ show: method("show", (options) => gitClient.show(options)),
268
+ revParse,
269
+ repoRoot: method("repoRoot", (options) => gitClient.repoRoot(options)),
270
+ currentBranch: method("currentBranch", (options) => gitClient.currentBranch(options)),
271
+ lsFiles: method("lsFiles", (options) => gitClient.lsFiles(options)),
272
+ lsTree: method("lsTree", (options) => gitClient.lsTree(options)),
273
+ branch: method("branch", (options) => gitClient.branch(options)),
274
+ branchDelete: method("branchDelete", (options) => gitClient.branchDelete(options)),
275
+ branchList: method("branchList", (options) => gitClient.branchList(options)),
276
+ tag: method("tag", (options) => gitClient.tag(options)),
277
+ tagDelete: method("tagDelete", (options) => gitClient.tagDelete(options)),
278
+ tagList: method("tagList", (options) => gitClient.tagList(options)),
279
+ checkout: method("checkout", (options) => gitClient.checkout(options)),
280
+ fetch: method("fetch", (options) => gitClient.fetch(options)),
281
+ push: method("push", (options) => gitClient.push(options)),
282
+ pull: method("pull", (options) => gitClient.pull(options)),
283
+ merge: method("merge", (options) => gitClient.merge(options)),
284
+ remoteAdd: method("remoteAdd", (options) => gitClient.remoteAdd(options)),
285
+ remoteRemove: method("remoteRemove", (options) => gitClient.remoteRemove(options)),
286
+ remoteList: method("remoteList", (options) => gitClient.remoteList(options)),
287
+ hashObject: method("hashObject", (options) => gitClient.hashObject(options)),
288
+ catFile: method("catFile", (options) => gitClient.catFile(options)),
289
+ updateRef: method("updateRef", (options) => gitClient.updateRef(options)),
290
+ configGet: method("configGet", (options) => gitClient.configGet(options)),
291
+ configSet: method("configSet", (options) => gitClient.configSet(options)),
292
+ stashPush: method("stashPush", (options) => gitClient.stashPush(options)),
293
+ stashList: method("stashList", (options) => gitClient.stashList(options)),
294
+ stashPop: method("stashPop", (options) => gitClient.stashPop(options)),
295
+ reset: method("reset", (options) => gitClient.reset(options)),
296
+ clean: method("clean", (options) => gitClient.clean(options)),
297
+ cli: method("cli", (input) => gitClient.cli(input))
298
+ };
299
+ };
300
+ const runtimeExecOptions = (options) => {
301
+ const { encoding = "utf8", timeoutMillis, timeoutMs, ...rest } = options ?? {};
302
+ const runtimeOptions = { ...rest };
303
+ if (encoding === "utf8") runtimeOptions.encoding = "utf8";
304
+ const selectedTimeout = timeoutMs ?? timeoutMillis;
305
+ if (selectedTimeout !== void 0) runtimeOptions.timeoutMs = selectedTimeout;
306
+ return runtimeOptions;
307
+ };
308
+ const runtimeGetOptions = (options) => {
309
+ const { encoding = "utf8", ...rest } = options ?? {};
310
+ const runtimeOptions = { ...rest };
311
+ if (encoding === "utf8") runtimeOptions.encoding = "utf8";
312
+ return runtimeOptions;
313
+ };
314
+ const wrapRuntimeResult = (result) => {
315
+ const stdout = result.stdout;
316
+ const stderr = result.stderr;
317
+ const wrapped = {
318
+ status: result.status,
319
+ exitCode: result.exitCode,
320
+ stdout,
321
+ stderr,
322
+ pushed: result.pushed,
323
+ pulled: result.pulled,
324
+ skipped: result.skipped,
325
+ sync: result.sync
326
+ };
327
+ return result.value === void 0 ? wrapped : {
328
+ ...wrapped,
329
+ value: result.value
330
+ };
331
+ };
332
+ const wrapRuntimeEvent = (event) => {
333
+ switch (event.name) {
334
+ case "stdout": {
335
+ const chunk = event.value;
336
+ return Predicate.isString(chunk) ? {
337
+ _tag: "Stdout",
338
+ id: event.id,
339
+ sequence: event.seq,
340
+ chunk,
341
+ text: chunk
342
+ } : {
343
+ _tag: "Stdout",
344
+ id: event.id,
345
+ sequence: event.seq,
346
+ chunk,
347
+ bytes: chunk
348
+ };
349
+ }
350
+ case "stderr": {
351
+ const chunk = event.value;
352
+ return Predicate.isString(chunk) ? {
353
+ _tag: "Stderr",
354
+ id: event.id,
355
+ sequence: event.seq,
356
+ chunk,
357
+ text: chunk
358
+ } : {
359
+ _tag: "Stderr",
360
+ id: event.id,
361
+ sequence: event.seq,
362
+ chunk,
363
+ bytes: chunk
364
+ };
365
+ }
366
+ case "exit":
367
+ const exitEvent = {
368
+ _tag: "Exit",
369
+ id: event.id,
370
+ sequence: event.seq,
371
+ exitCode: event.code
372
+ };
373
+ return event.result === void 0 ? exitEvent : {
374
+ ...exitEvent,
375
+ value: event.result
376
+ };
377
+ }
378
+ };
379
+ const wrapRun = (handle) => {
380
+ const mapRuntimeEvent = wrapRuntimeEvent;
381
+ const events = Stream.fromReadableStream({
382
+ evaluate: () => handle,
383
+ onError: (cause) => execError("events", cause)
384
+ }).pipe(Stream.map(mapRuntimeEvent));
385
+ const result = Effect.tryPromise({
386
+ try: () => handle.result(),
387
+ catch: (cause) => execError("result", cause)
388
+ }).pipe(Effect.map(wrapRuntimeResult));
389
+ const kill = Effect.fn("ComputerWorkspace.runtime.run.kill", { attributes: {
390
+ family: "runtime",
391
+ operation: "run.kill",
392
+ runId: handle.id
393
+ } })(function* (signal) {
394
+ yield* Effect.tryPromise({
395
+ try: () => handle.kill(signal),
396
+ catch: (cause) => execError("run.kill", cause)
397
+ });
398
+ });
399
+ return {
400
+ id: handle.id,
401
+ backend: handle.backend,
402
+ events,
403
+ result,
404
+ kill
405
+ };
406
+ };
407
+ const releaseRun = (handle) => Effect.sync(() => handle[Symbol.dispose]());
408
+ const makeRuntime = (client) => {
409
+ const execImplementation = Effect.fn("ComputerWorkspace.runtime.exec", { attributes: {
410
+ family: "runtime",
411
+ operation: "exec"
412
+ } })(function* (source, optionsOrValue, ...remainingValues) {
413
+ const options = Predicate.isString(source) ? optionsOrValue : void 0;
414
+ yield* Effect.annotateCurrentSpan({
415
+ backend: options?.backend,
416
+ runId: options?.id
417
+ });
418
+ const handle = yield* Effect.acquireRelease(Effect.tryPromise({
419
+ try: () => {
420
+ if (Predicate.isString(source)) return client.runtime.exec(source, runtimeExecOptions(options));
421
+ const values = optionsOrValue === void 0 ? remainingValues : [optionsOrValue, ...remainingValues];
422
+ return client.runtime.exec(source, ...values);
423
+ },
424
+ catch: (cause) => execError("exec", cause)
425
+ }), releaseRun);
426
+ return wrapRun(handle);
427
+ });
428
+ const exec = execImplementation;
429
+ const getExec = Effect.fn("ComputerWorkspace.runtime.getExec", { attributes: {
430
+ family: "runtime",
431
+ operation: "getExec"
432
+ } })(function* (id, options) {
433
+ yield* Effect.annotateCurrentSpan({
434
+ backend: options?.backend,
435
+ runId: id
436
+ });
437
+ const handle = yield* Effect.acquireRelease(Effect.tryPromise({
438
+ try: () => client.runtime.getExec(id, runtimeGetOptions(options)),
439
+ catch: (cause) => execError("getExec", cause)
440
+ }), releaseRun);
441
+ return wrapRun(handle);
442
+ });
443
+ const killExec = Effect.fn("ComputerWorkspace.runtime.killExec", { attributes: {
444
+ family: "runtime",
445
+ operation: "killExec"
446
+ } })(function* (id, options) {
447
+ yield* Effect.annotateCurrentSpan({
448
+ backend: options?.backend,
449
+ runId: id
450
+ });
451
+ yield* Effect.tryPromise({
452
+ try: () => client.runtime.killExec(id, options),
453
+ catch: (cause) => execError("killExec", cause)
454
+ });
455
+ });
456
+ const disposeExec = Effect.fn("ComputerWorkspace.runtime.disposeExec", { attributes: {
457
+ family: "runtime",
458
+ operation: "disposeExec"
459
+ } })(function* (id, options) {
460
+ yield* Effect.annotateCurrentSpan({
461
+ backend: options?.backend,
462
+ runId: id
463
+ });
464
+ yield* Effect.tryPromise({
465
+ try: () => client.runtime.disposeExec(id, options),
466
+ catch: (cause) => execError("disposeExec", cause)
467
+ });
468
+ });
469
+ return {
470
+ exec,
471
+ execCollect: Effect.fn("ComputerWorkspace.runtime.execCollect", { attributes: {
472
+ family: "runtime",
473
+ operation: "execCollect"
474
+ } })(function* (source, optionsOrValue, ...remainingValues) {
475
+ return yield* Effect.scoped(Effect.gen(function* () {
476
+ return yield* (yield* execImplementation(source, optionsOrValue, ...remainingValues)).result;
477
+ }));
478
+ }),
479
+ getExec,
480
+ killExec,
481
+ disposeExec
482
+ };
483
+ };
484
+ const makeAssets = (client) => client === void 0 ? void 0 : { share: Effect.fn("ComputerWorkspace.assets.share", { attributes: {
485
+ family: "assets",
486
+ operation: "share"
487
+ } })(function* (path, options) {
488
+ yield* Effect.annotateCurrentSpan("path", path);
489
+ return yield* Effect.tryPromise({
490
+ try: () => client.share(path, options),
491
+ catch: (cause) => assetsError("share", path, cause)
492
+ });
493
+ }) };
494
+ const makeThink = (client) => {
495
+ 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;
496
+ const method = (operation, pathOf, evaluate) => Effect.fn(`ComputerWorkspace.think.${operation}`, { attributes: {
497
+ family: "think",
498
+ operation
499
+ } })(function* (...args) {
500
+ const path = pathOf(...args);
501
+ yield* Effect.annotateCurrentSpan("path", path);
502
+ return yield* tryFs(`think.${operation}`, path, () => evaluate(...args));
503
+ });
504
+ const readFile = client.readFile.bind(client);
505
+ const readFileBytes = client.readFileBytes.bind(client);
506
+ const writeFile = client.writeFile.bind(client);
507
+ const readDir = client.readDir.bind(client);
508
+ const rm = client.rm.bind(client);
509
+ const glob = client.glob.bind(client);
510
+ const mkdir = client.mkdir.bind(client);
511
+ const stat = client.stat.bind(client);
512
+ return {
513
+ readFile: method("readFile", (path) => path, (path) => readFile(path)),
514
+ readFileBytes: method("readFileBytes", (path) => path, (path) => readFileBytes(path)),
515
+ writeFile: method("writeFile", (path, _content) => path, (path, content) => writeFile(path, content)),
516
+ readDir: method("readDir", (path, _options) => path, (path, options) => readDir(path, options)),
517
+ rm: method("rm", (path, _options) => path, (path, options) => rm(path, options)),
518
+ glob: method("glob", (pattern) => pattern, (pattern) => glob(pattern)),
519
+ mkdir: method("mkdir", (path, _options) => path, (path, options) => mkdir(path, options)),
520
+ stat: method("stat", (path) => path, (path) => stat(path))
521
+ };
522
+ };
523
+ /**
524
+ * Wraps a client whose lifetime is owned by the caller. Prefer
525
+ * {@link ComputerWorkspace.layer} in Durable Objects so the parent client and
526
+ * every runtime handle are disposed by Effect `Scope`.
527
+ */
528
+ const fromWorkspaceClient = (client) => {
529
+ const fs = makeFilesystem(client.fs);
530
+ const git = makeGit(client.git);
531
+ const runtime = makeRuntime(client);
532
+ return {
533
+ fs,
534
+ git,
535
+ runtime,
536
+ artifacts: fromClient(client.artifacts, { binding: "ComputerWorkspace.artifacts" }),
537
+ assets: makeAssets(client.assets),
538
+ think: makeThink(client),
539
+ readFile: fs.readFile,
540
+ stat: fs.stat,
541
+ lstat: fs.lstat,
542
+ exists: fs.exists,
543
+ readlink: fs.readlink,
544
+ readdir: fs.readdir,
545
+ listDirectory: fs.readdir,
546
+ find: fs.find,
547
+ ls: fs.ls,
548
+ grep: fs.grep,
549
+ writeFile: fs.writeFile,
550
+ mkdir: fs.mkdir,
551
+ rm: fs.rm,
552
+ removePath: fs.rm,
553
+ chmod: fs.chmod,
554
+ symlink: fs.symlink,
555
+ exec: runtime.exec,
556
+ execCollect: runtime.execCollect,
557
+ getExec: runtime.getExec,
558
+ killExec: runtime.killExec,
559
+ disposeExec: runtime.disposeExec
560
+ };
561
+ };
562
+ /** Effect service for the workspace owned by the enclosing Durable Object. */
563
+ var ComputerWorkspace = class ComputerWorkspace extends Context.Service()("effect-cf/ComputerWorkspace") {
564
+ /**
565
+ * Acquires the single workspace registered by `withComputerWorkspace` and
566
+ * releases its RPC client when the layer scope closes.
567
+ */
568
+ static layer = Layer.effect(ComputerWorkspace, Effect.gen(function* () {
569
+ const host = lookup((yield* DurableObjectState).raw);
570
+ if (host === void 0) return yield* Effect.die("ComputerWorkspace.layer requires a Durable Object class built with withComputerWorkspace");
571
+ const computer = yield* Effect.promise(() => import("@cloudflare/computer"));
572
+ const client = yield* Effect.acquireRelease(Effect.promise(() => computer.getWorkspace(host)), (workspace) => Effect.sync(() => workspace[Symbol.dispose]()));
573
+ return ComputerWorkspace.of(fromWorkspaceClient(client));
574
+ }));
575
+ };
576
+ //#endregion
577
+ export { ComputerWorkspace, WorkspaceAssetsError, WorkspaceExecError, WorkspaceFsError, WorkspaceGitError, fromWorkspaceClient };
@@ -1,4 +1,4 @@
1
- import { t as ArtifactsBinding } from "./Artifacts-DcoXcRP5.mjs";
1
+ import { t as ArtifactsBinding } from "./Artifacts-DnHQA-Ax.mjs";
2
2
  import { GitClientFactory } from "@cloudflare/computer/git";
3
3
  import { DurableObjectStorageLike, SyncRetryIntent, SyncRetryOptions, SyncRetryScheduler, WithWorkspaceCtor, WorkspaceAttributeValue, WorkspaceAttributes, WorkspaceObserver, WorkspaceOptions, WorkspaceRegisteredBackend, WorkspaceRetryPendingSyncResult, WorkspaceServiceProxy, WorkspaceSpan } from "@cloudflare/computer";
4
4
  import { ShellModuleGroup, WorkerShellBackendOptions, WorkerShellLoader, WorkspaceEgressPolicy } from "@cloudflare/computer/backends/worker-shell";
@@ -18,24 +18,26 @@ const toWorkspaceOptions = (config) => {
18
18
  egress: egress ?? { mode: "none" }
19
19
  }));
20
20
  }
21
- return {
21
+ const options = {
22
22
  storage: config.storage,
23
- git: config.git ?? createGitClient(),
24
- ...config.gitIdentity === void 0 ? {} : { defaultGitIdentity: config.gitIdentity },
25
- ...backends.length === 0 ? {} : { backends },
26
- ...config.sessionId === void 0 ? {} : { sessionId: config.sessionId },
27
- ...config.mounts === void 0 ? {} : { mounts: config.mounts },
28
- ...config.observer === void 0 ? {} : { observer: config.observer },
29
- ...config.retryScheduler === void 0 ? {} : { retryScheduler: config.retryScheduler },
30
- ...config.retry === void 0 ? {} : { retry: config.retry },
31
- ...config.assets === void 0 ? {} : { assets: config.assets },
32
- ...config.artifacts === void 0 ? {} : { artifacts: {
33
- binding: config.artifacts.binding,
34
- ...config.artifacts.sessionId === void 0 ? {} : { sessionId: config.artifacts.sessionId }
35
- } },
36
- ...config.now === void 0 ? {} : { now: config.now },
37
- ...config.useThink === void 0 ? {} : { useThink: config.useThink }
23
+ git: config.git ?? createGitClient()
38
24
  };
25
+ if (config.gitIdentity !== void 0) options.defaultGitIdentity = config.gitIdentity;
26
+ if (backends.length !== 0) options.backends = backends;
27
+ if (config.sessionId !== void 0) options.sessionId = config.sessionId;
28
+ if (config.mounts !== void 0) options.mounts = config.mounts;
29
+ if (config.observer !== void 0) options.observer = config.observer;
30
+ if (config.retryScheduler !== void 0) options.retryScheduler = config.retryScheduler;
31
+ if (config.retry !== void 0) options.retry = config.retry;
32
+ if (config.assets !== void 0) options.assets = config.assets;
33
+ if (config.artifacts !== void 0) {
34
+ const artifacts = { binding: config.artifacts.binding };
35
+ if (config.artifacts.sessionId !== void 0) artifacts.sessionId = config.artifacts.sessionId;
36
+ options.artifacts = artifacts;
37
+ }
38
+ if (config.now !== void 0) options.now = config.now;
39
+ if (config.useThink !== void 0) options.useThink = config.useThink;
40
+ return options;
39
41
  };
40
42
  const HostArguments = Symbol("effect-cf/ComputerWorkspaceHost/arguments");
41
43
  /**