|
1 | | -import { CoreErrors, registerErrorDomain, type ErrorDomain } from '#/_base/errors/codes'; |
2 | | -import { Error2, isError2 } from '#/_base/errors/errors'; |
3 | | -import { |
4 | | - CONTEXT_OVERFLOW_ERROR_CODE, |
5 | | - PROVIDER_API_ERROR_CODE, |
6 | | - PROVIDER_AUTH_ERROR_CODE, |
7 | | - PROVIDER_CONNECTION_ERROR_CODE, |
8 | | - PROVIDER_FILTERED_ERROR_CODE, |
9 | | - PROVIDER_OVERLOADED_ERROR_CODE, |
10 | | - PROVIDER_RATE_LIMIT_ERROR_CODE, |
11 | | - throwIfAbortError, |
12 | | -} from '#/kosong/contract/errors'; |
13 | | - |
14 | | -export { sanitizeStatusErrorMessage } from '#/kosong/contract/errors'; |
15 | | - |
16 | | -export const ProtocolErrors = { |
17 | | - codes: { |
18 | | - PROVIDER_API_ERROR: PROVIDER_API_ERROR_CODE, |
19 | | - PROVIDER_FILTERED: PROVIDER_FILTERED_ERROR_CODE, |
20 | | - PROVIDER_RATE_LIMIT: PROVIDER_RATE_LIMIT_ERROR_CODE, |
21 | | - PROVIDER_AUTH_ERROR: PROVIDER_AUTH_ERROR_CODE, |
22 | | - PROVIDER_CONNECTION_ERROR: PROVIDER_CONNECTION_ERROR_CODE, |
23 | | - PROVIDER_OVERLOADED: PROVIDER_OVERLOADED_ERROR_CODE, |
24 | | - CONTEXT_OVERFLOW: CONTEXT_OVERFLOW_ERROR_CODE, |
25 | | - }, |
26 | | - retryable: [ |
27 | | - 'provider.rate_limit', |
28 | | - 'provider.connection_error', |
29 | | - 'provider.overloaded', |
30 | | - 'context.overflow', |
31 | | - ], |
32 | | - info: { |
33 | | - 'provider.rate_limit': { |
34 | | - title: 'Provider rate limit', |
35 | | - retryable: true, |
36 | | - public: true, |
37 | | - action: 'Retry after the provider rate limit resets.', |
38 | | - }, |
39 | | - 'provider.filtered': { |
40 | | - title: 'Provider filtered response', |
41 | | - retryable: false, |
42 | | - public: true, |
43 | | - action: 'Revise the prompt or model configuration to avoid provider safety filtering.', |
44 | | - }, |
45 | | - 'provider.auth_error': { |
46 | | - title: 'Provider authentication failed', |
47 | | - retryable: false, |
48 | | - public: true, |
49 | | - action: 'Check provider credentials and authentication configuration.', |
50 | | - }, |
51 | | - 'provider.overloaded': { |
52 | | - title: 'Provider overloaded', |
53 | | - retryable: true, |
54 | | - public: true, |
55 | | - action: 'Retry after the provider recovers from overload.', |
56 | | - }, |
57 | | - 'context.overflow': { |
58 | | - title: 'Context overflow', |
59 | | - retryable: true, |
60 | | - public: true, |
61 | | - action: 'Compact the conversation or retry with fewer tokens.', |
62 | | - }, |
63 | | - }, |
64 | | -} as const satisfies ErrorDomain; |
65 | | - |
66 | | -registerErrorDomain(ProtocolErrors); |
67 | | - |
68 | | -export function translateProviderError(error: unknown): Error2 { |
69 | | - throwIfAbortError(error); |
70 | | - if (isError2(error)) { |
71 | | - return error; |
72 | | - } |
73 | | - if (error instanceof Error) { |
74 | | - return new Error2(CoreErrors.codes.INTERNAL, error.message, { |
75 | | - name: error.name, |
76 | | - cause: error, |
77 | | - }); |
78 | | - } |
79 | | - return new Error2(CoreErrors.codes.INTERNAL, String(error), { cause: error }); |
80 | | -} |
| 1 | +export { |
| 2 | + ProtocolErrors, |
| 3 | + sanitizeStatusErrorMessage, |
| 4 | + translateProviderError, |
| 5 | +} from '#/llm-adapter/protocol/errors'; |
0 commit comments