(handle: WorkspaceHandle)
| 364 | export type WorkspaceHandle = { [WORKSPACE]?: unknown } | WorkspaceStubHost; |
| 365 | |
| 366 | export 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 | } |
no test coverage detected