mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-25 22:04:22 +00:00
28 lines
893 B
TypeScript
28 lines
893 B
TypeScript
import { z, type ZodType } from "zod/v4"
|
|
|
|
export const openaiCompatibleErrorDataSchema = z.object({
|
|
error: z.object({
|
|
message: z.string(),
|
|
|
|
// The additional information below is handled loosely to support
|
|
// OpenAI-compatible providers that have slightly different error
|
|
// responses:
|
|
type: z.string().nullish(),
|
|
param: z.any().nullish(),
|
|
code: z.union([z.string(), z.number()]).nullish(),
|
|
}),
|
|
})
|
|
|
|
export type OpenAICompatibleErrorData = z.infer<typeof openaiCompatibleErrorDataSchema>
|
|
|
|
export type ProviderErrorStructure<T> = {
|
|
errorSchema: ZodType<T>
|
|
errorToMessage: (error: T) => string
|
|
isRetryable?: (response: Response, error?: T) => boolean
|
|
}
|
|
|
|
export const defaultOpenAICompatibleErrorStructure: ProviderErrorStructure<OpenAICompatibleErrorData> = {
|
|
errorSchema: openaiCompatibleErrorDataSchema,
|
|
errorToMessage: (data) => data.error.message,
|
|
}
|