import {z} from 'zod' export type GetApiV1RunsIdRelatedArgs = {id: string}; export type GetApiV1RunsIdRelatedOptions = {baseUrl?: string | undefined, ProjectPrivateApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const feedback = z.object({thumb: z.enum(["up", "down"]).optional(), comment: z.string().optional()}); export const run = z.object({id: z.string().optional(), projectId: z.string().optional(), isPublic: z.boolean().optional(), feedback: feedback.optional(), parentFeedback: feedback.optional(), type: z.string().optional(), name: z.string().optional(), createdAt: z.string().optional(), endedAt: z.string().optional(), duration: z.number().optional(), templateVersionId: z.string().optional(), templateSlug: z.string().optional(), cost: z.number().optional(), tokens: z.object({completion: z.number().optional(), prompt: z.number().optional(), total: z.number().optional()}).optional(), tags: z.array(z.string()).optional(), input: z.object({}).optional(), output: z.object({}).optional(), error: z.object({}).optional(), status: z.string().optional(), siblingRunId: z.string().optional(), params: z.object({}).optional(), metadata: z.object({}).optional(), firstMessage: z.object({}).optional(), messagesCount: z.number().int().optional(), user: z.object({id: z.string().optional(), externalId: z.string().optional(), createdAt: z.string().optional(), lastSeen: z.string().optional(), props: z.object({}).optional()}).optional()}); export const getApiV1RunsIdRelatedResponse = z.array(run); 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 related runs * * GET /v1/runs/{id}/related */ export const getApiV1RunsIdRelated = async (args: GetApiV1RunsIdRelatedArgs, options?: GetApiV1RunsIdRelatedOptions) => { const {baseUrl = "https://api.lunary.ai", fetch: fetchFn = fetch, ProjectPrivateApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ProjectPrivateApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ProjectPrivateApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/runs/${encodeURIComponent(String(args.id))}/related${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(getApiV1RunsIdRelatedResponse, await res.json()) };