MCPcopy Create free account
hub / github.com/cloudflare/computer / HostDO

Class HostDO

packages/computer/tests/script-runner-worker.ts:16–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16export class HostDO extends DurableObject<Env> {
17 readonly #workspace: Workspace;
18
19 constructor(ctx: DurableObjectState, env: Env) {
20 super(ctx, env);
21 this.#workspace = new Workspace({
22 storage: ctx.storage as unknown as DurableObjectStorageLike,
23 waitUntil: ctx.waitUntil.bind(ctx),
24 git: createGitClient(),
25 backends: [
26 new WorkerJavaScriptBackend({
27 loader: env.LOADER,
28 maxStdioBytes: 64,
29 maxCapabilityBytes: 1024,
30 maxConcurrentCapabilityCalls: 2,
31 modules: {
32 "math-kit": "export const double = (value) => value * 2;",
33 },
34 trustedModules: {
35 "ws:test-host": {
36 async call(method, args) {
37 if (method === "invalid-result") return new Date() as never;
38 if (method === "large-error") throw new Error("x".repeat(5000));
39 if (method === "slow") {
40 await new Promise((resolve) => setTimeout(resolve, 20));
41 return null;
42 }
43 if (method === "marker") {
44 return {
45 __workspace_codec__: { version: 1, type: "bytes", data: [1] },
46 keep: true,
47 };
48 }
49 return { method, args };
50 },
51 },
52 },
53 }),
54 ],
55 });
56 }
57
58 async writeFile(path: string, source: string) {
59 await this.#workspace.fs.mkdir(path.slice(0, path.lastIndexOf("/")) || "/workspace", {
60 recursive: true,
61 });
62 await this.#workspace.fs.writeFile(path, source);
63 }
64
65 async symlink(target: string, path: string) {
66 await this.#workspace.fs.mkdir(path.slice(0, path.lastIndexOf("/")) || "/", {
67 recursive: true,
68 });
69 await this.#workspace.fs.symlink(target, path);
70 }
71
72 getWorkspace(): WorkspaceStub {
73 return this.#workspace.stub();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected