diff --git a/.changeset/bright-waves-98e80b.md b/.changeset/bright-waves-98e80b.md new file mode 100644 index 0000000..d32e098 --- /dev/null +++ b/.changeset/bright-waves-98e80b.md @@ -0,0 +1,5 @@ +--- +"@vercel/sandbox": patch +--- + +Add `wait` option to `getCommand` to allow fetching command state without waiting for completion diff --git a/packages/vercel-sandbox/src/sandbox.ts b/packages/vercel-sandbox/src/sandbox.ts index 3582d12..9d5a2ef 100644 --- a/packages/vercel-sandbox/src/sandbox.ts +++ b/packages/vercel-sandbox/src/sandbox.ts @@ -12,10 +12,7 @@ import { WithFetchOptions } from "./api-client/api-client"; import { RUNTIMES } from "./constants"; import { Snapshot } from "./snapshot"; import { consumeReadable } from "./utils/consume-readable"; -import { - toAPINetworkPolicy, - type NetworkPolicy, -} from "./utils/network-policy"; +import { toAPINetworkPolicy, type NetworkPolicy } from "./utils/network-policy"; export type { NetworkPolicy }; @@ -323,15 +320,23 @@ export class Sandbox { * @param cmdId - ID of the command to retrieve * @param opts - Optional parameters. * @param opts.signal - An AbortSignal to cancel the operation. + * @param opts.wait - If false, will not wait for the command to complete. * @returns A {@link Command} instance representing the command */ async getCommand( cmdId: string, - opts?: { signal?: AbortSignal }, + opts?: { + signal?: AbortSignal; + /** + * If false, will not wait for the command to complete. + */ + wait?: boolean; + }, ): Promise { const command = await this.client.getCommand({ sandboxId: this.sandbox.id, cmdId, + wait: opts?.wait, signal: opts?.signal, }); @@ -413,7 +418,7 @@ export class Sandbox { } })(); } - } + }; if (wait) { const commandStream = await this.client.runCommand({ @@ -433,7 +438,7 @@ export class Sandbox { cmd: commandStream.command, }); - getLogs(command); + getLogs(command); const finished = await commandStream.finished; return new CommandFinished({ @@ -562,7 +567,7 @@ export class Sandbox { }); return dstPath; } finally { - stream.destroy() + stream.destroy(); } }