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

Function getWorkspace

packages/computer/src/client.ts:366–406  ·  view source on GitHub ↗
(handle: WorkspaceHandle)

Source from the content-addressed store, hash-verified

364export type WorkspaceHandle = { [WORKSPACE]?: unknown } | WorkspaceStubHost;
365
366export async function getWorkspace(handle: WorkspaceHandle): Promise<WorkspaceClient> {
367 const local = (handle as { [WORKSPACE]?: unknown })[WORKSPACE];
368 if (local instanceof Workspace) {
369 // Local path: delegate straight to the in-isolate Workspace.
370 // Nothing to dispose — the durable object owns the Workspace
371 // lifecycle.
372 await local.ready();
373 return makeClient(
374 {
375 fs: local.fs,
376 runtime: local.runtime,
377 get git() {
378 return local.git;
379 },
380 artifacts: local.artifacts,
381 assets: local.assets,
382 },
383 // Local handle is already a host ExecHandle — pass it through.
384 (h) => h,
385 () => {},
386 local.useThink,
387 );
388 }
389 // Remote path: fetch the stub over RPC and delegate to it. Handle
390 // stubs need inflating from their JSONL stream into a host-shaped
391 // ExecHandle.
392 const stub = await (handle as WorkspaceStubHost).__getWorkspaceStub();
393 try {
394 return makeClient(
395 stub,
396 (h, metadata) => rebuildExecHandle(h as RemoteExecHandle, metadata),
397 () => {
398 (stub as { [Symbol.dispose]?: () => void })[Symbol.dispose]?.();
399 },
400 await stub.useThink,
401 );
402 } catch (error) {
403 (stub as { [Symbol.dispose]?: () => void })[Symbol.dispose]?.();
404 throw error;
405 }
406}

Callers 8

handleFileFunction · 0.90
handleExecFunction · 0.90
handleFileFunction · 0.90
handleExecFunction · 0.90
handleCreateFunction · 0.90
handleFileFunction · 0.90
handleExecFunction · 0.90
client.test.tsFile · 0.70

Calls 4

rebuildExecHandleFunction · 0.85
makeClientFunction · 0.70
readyMethod · 0.65
__getWorkspaceStubMethod · 0.65

Tested by

no test coverage detected