Skip to content
Merged
10 changes: 9 additions & 1 deletion packages/computer/src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class WorkspaceRuntime {
this.#options = options;
}

// Whether the named backend accepts a structured `input` value and
// returns a structured result. Consumers such as the exec tool ask
// this to know whether a backend is callable without the caller
// having to declare it a second time.
isCallable(id: string): boolean {
return this.#options.callableBackendIds.has(id);
}

exec(source: string): Promise<WorkspaceRuntimeExecHandle<undefined>>;
exec(
source: string,
Expand All @@ -49,7 +57,7 @@ export class WorkspaceRuntime {
): Promise<WorkspaceRuntimeExecHandle<E>> {
if (options.id !== undefined) assertExecutionId(options.id);
const backend = this.#backend(options.backend);
if (options.input !== undefined && !this.#options.callableBackendIds.has(backend)) {
if (options.input !== undefined && !this.isCallable(backend)) {
throw new Error(notCallableMessage(backend));
}
const runtime = await this.#options.backendHandle(backend);
Expand Down
Loading
Loading