import {z} from 'zod' export type GetApiV1NameReadOutputFramesArgs = {name: string}; export type GetApiV1NameReadOutputFramesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1OutputStream = z.enum(["OUTPUT_STREAM_UNSPECIFIED", "OUTPUT_STREAM_STDOUT", "OUTPUT_STREAM_STDERR", "OUTPUT_STREAM_COMBINED"]); export const v1OutputFrame = z.object({stream: v1OutputStream.optional(), data: z.string().optional()}); export const v1ReadOutputFramesResponse = z.object({frames: z.array(v1OutputFrame).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 }; /** * (-- api-linter: core::0131::synonyms=disabled * aip.dev/not-precedent: ReadOutputFrames reads structured output * frames, not a resource. --) * Reads the structured output of a process as ordered, per-stream-tagged * frames. Returns the same byte content as ReadOutput(COMBINED) but * preserves the chunk boundaries and per-stream identity that * StreamOutput emits live — without requiring a live subscription. * * GET /v1/{name}:readOutputFrames */ export const getApiV1NameReadOutputFrames = async (args: GetApiV1NameReadOutputFramesArgs, options: GetApiV1NameReadOutputFramesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.name))}:readOutputFrames${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(v1ReadOutputFramesResponse, await res.json()) };