import {z} from 'zod' export type LlmLogSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, llmProviderId?: boolean | undefined, llmProviderName?: boolean | undefined, llmType?: boolean | undefined, modelName?: boolean | undefined, isGlobalProvider?: boolean | undefined, totalTokens?: boolean | undefined, completionTokens?: boolean | undefined, cachedInputTokens?: boolean | undefined, cacheCreationTokens?: boolean | undefined, costInUSDCents?: boolean | undefined, wasBilled?: boolean | undefined, status?: boolean | undefined, statusMessage?: boolean | undefined, feature?: boolean | undefined, requestPrompt?: boolean | undefined, responsePreview?: boolean | undefined, incidentId?: boolean | undefined, alertId?: boolean | undefined, aiRunId?: boolean | undefined, scheduledMaintenanceId?: boolean | undefined, userId?: boolean | undefined, requestStartedAt?: boolean | undefined, requestCompletedAt?: boolean | undefined, durationMs?: boolean | undefined}; export type CreateApiLlmLogIdGetItemArgs = {id: string, body: {select?: LlmLogSelectSchema | undefined}}; export type CreateApiLlmLogIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const llmLog = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), llmProviderId: z.string().optional(), llmProviderName: z.string().optional(), llmType: z.enum(["OpenAI", "AzureOpenAI", "Anthropic", "Groq", "Mistral", "Ollama", "OpenAICompatible"]).optional(), modelName: z.string().optional(), isGlobalProvider: z.boolean(), totalTokens: z.number(), completionTokens: z.number(), cachedInputTokens: z.number(), cacheCreationTokens: z.number(), costInUSDCents: z.number(), wasBilled: z.boolean(), status: z.enum(["Success", "Error", "Insufficient Balance", "Budget Exceeded"]), statusMessage: z.string().optional(), feature: z.string().optional(), requestPrompt: z.string().optional(), responsePreview: z.string().optional(), incidentId: z.string().optional(), alertId: z.string().optional(), aiRunId: z.string().optional(), scheduledMaintenanceId: z.string().optional(), userId: z.string().optional(), requestStartedAt: z.object({}).optional(), requestCompletedAt: z.object({}).optional(), durationMs: z.number().optional()}); export const createApiLlmLogIdGetItemResponse = z.object({data: llmLog.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 LLM Log * * POST /llm-log/{id}/get-item */ export const createApiLlmLogIdGetItem = async (args: CreateApiLlmLogIdGetItemArgs, options?: CreateApiLlmLogIdGetItemOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/llm-log/${encodeURIComponent(String(args.id))}/get-item${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiLlmLogIdGetItemResponse, await res.json()) };