import {z} from 'zod' export type GetApiV1PrivateLocalRunnersRunnerIdBridgeCommandsCommandIdArgs = {runnerId: string, commandId: string, wait?: boolean | undefined, timeout?: number | undefined}; export type GetApiV1PrivateLocalRunnersRunnerIdBridgeCommandsCommandIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jsonNode = z.object({}); export const bridgeCommand = z.object({command_id: z.string().optional(), runner_id: z.string().optional(), type: z.enum(["ReadFile", "WriteFile", "EditFile", "ListFiles", "SearchFiles", "Exec"]).optional(), status: z.enum(["pending", "picked_up", "completed", "failed", "timed_out"]).optional(), args: jsonNode.optional(), result: jsonNode.optional(), error: jsonNode.optional(), timeout_seconds: z.number().int().optional(), submitted_at: z.string().optional(), picked_up_at: z.string().optional(), completed_at: z.string().optional(), duration_ms: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get bridge command * * GET /v1/private/local-runners/{runnerId}/bridge/commands/{commandId} */ export const getApiV1PrivateLocalRunnersRunnerIdBridgeCommandsCommandId = async (args: GetApiV1PrivateLocalRunnersRunnerIdBridgeCommandsCommandIdArgs, options?: GetApiV1PrivateLocalRunnersRunnerIdBridgeCommandsCommandIdOptions) => { const {baseUrl = "http://localhost:5173/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.wait != null) query.append("wait", String(args.wait)) if (args.timeout != null) query.append("timeout", String(args.timeout)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/private/local-runners/${encodeURIComponent(String(args.runnerId))}/bridge/commands/${encodeURIComponent(String(args.commandId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(bridgeCommand, await res.json()) };