@@ -18,6 +18,7 @@ import { ModelID, ProviderID } from "@/provider/schema"
1818import { Effect , Schema , Types } from "effect"
1919import { zod , ZodOverride } from "@/util/effect-zod"
2020import { withStatics } from "@/util/schema"
21+ import { namedSchemaError } from "@/util/named-schema-error"
2122import { EffectLogger } from "@/effect"
2223
2324/** Error shape thrown by Bun's fetch() when gzip/br decompression fails mid-stream */
@@ -30,38 +31,29 @@ interface FetchDecompressionError extends Error {
3031export const SYNTHETIC_ATTACHMENT_PROMPT = "Attached image(s) from tool result:"
3132export { isMedia }
3233
33- export const OutputLengthError = NamedError . create ( "MessageOutputLengthError" , z . object ( { } ) )
34- export const AbortedError = NamedError . create ( "MessageAbortedError" , z . object ( { message : z . string ( ) } ) )
35- export const StructuredOutputError = NamedError . create (
36- "StructuredOutputError" ,
37- z . object ( {
38- message : z . string ( ) ,
39- retries : z . number ( ) ,
40- } ) ,
41- )
42- export const AuthError = NamedError . create (
43- "ProviderAuthError" ,
44- z . object ( {
45- providerID : z . string ( ) ,
46- message : z . string ( ) ,
47- } ) ,
48- )
49- export const APIError = NamedError . create (
50- "APIError" ,
51- z . object ( {
52- message : z . string ( ) ,
53- statusCode : z . number ( ) . optional ( ) ,
54- isRetryable : z . boolean ( ) ,
55- responseHeaders : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
56- responseBody : z . string ( ) . optional ( ) ,
57- metadata : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
58- } ) ,
59- )
34+ export const OutputLengthError = namedSchemaError ( "MessageOutputLengthError" , { } )
35+ export const AbortedError = namedSchemaError ( "MessageAbortedError" , { message : Schema . String } )
36+ export const StructuredOutputError = namedSchemaError ( "StructuredOutputError" , {
37+ message : Schema . String ,
38+ retries : Schema . Number ,
39+ } )
40+ export const AuthError = namedSchemaError ( "ProviderAuthError" , {
41+ providerID : Schema . String ,
42+ message : Schema . String ,
43+ } )
44+ export const APIError = namedSchemaError ( "APIError" , {
45+ message : Schema . String ,
46+ statusCode : Schema . optional ( Schema . Number ) ,
47+ isRetryable : Schema . Boolean ,
48+ responseHeaders : Schema . optional ( Schema . Record ( Schema . String , Schema . String ) ) ,
49+ responseBody : Schema . optional ( Schema . String ) ,
50+ metadata : Schema . optional ( Schema . Record ( Schema . String , Schema . String ) ) ,
51+ } )
6052export type APIError = z . infer < typeof APIError . Schema >
61- export const ContextOverflowError = NamedError . create (
62- "ContextOverflowError" ,
63- z . object ( { message : z . string ( ) , responseBody : z . string ( ) . optional ( ) } ) ,
64- )
53+ export const ContextOverflowError = namedSchemaError ( "ContextOverflowError" , {
54+ message : Schema . String ,
55+ responseBody : Schema . optional ( Schema . String ) ,
56+ } )
6557
6658export class OutputFormatText extends Schema . Class < OutputFormatText > ( "OutputFormatText" ) ( {
6759 type : Schema . Literal ( "text" ) ,
0 commit comments