/** * error-codes.ts, the canonical {@link SDKErrorCode} union, its runtime-accessible * {@link SDKErrorCodes} mirror, and the two membership/narrowing helpers built on it. * * Split out of index.ts to stay under the repo's 800-line file cap (see * scripts/check-line-cap.ts), this block is self-contained (no dependency on * GoodVibesSdkError or anything else in index.ts) and index.ts re-exports it * unchanged, so this is a pure file-organization move with no API surface change. */ /** * Exhaustive string-literal union of the canonical error codes produced by the * GoodVibes SDK. Use this type when you need to pattern-match on `err.code` * without losing exhaustiveness checking. * * The `code` field on {@link GoodVibesSdkError} is typed as * `SDKErrorCode | (string & {})` so that: * - SDK-produced errors surface as one of the known literals (IDE autocomplete * and exhaustive switches work). * - Caller-supplied arbitrary string codes still type-check without casting. * * ### Consumer pattern * ```ts * import { isErrorCode, SDKErrorCodes } from '@pellux/goodvibes-errors'; * * catch (err) { * if (err instanceof GoodVibesSdkError) { * if (isErrorCode(err, SDKErrorCodes.RATE_LIMITED)) { * await delay(err.retryAfterMs ?? 1000); * } else if (isErrorCode(err, SDKErrorCodes.AUTH_REQUIRED)) { * await refreshToken(); * } else if (isErrorCode(err, SDKErrorCodes.TOKEN_EXPIRED)) { * await refreshToken(); * } * } * } * ``` */ export type SDKErrorCode = 'AUTH_REQUIRED' | 'TOKEN_EXPIRED' | 'PERMISSION_DENIED' | 'PAYMENT_REQUIRED' | 'RATE_LIMITED' | 'NETWORK_UNREACHABLE' | 'TIMEOUT' | 'CANCELLED' | 'NOT_FOUND' | 'CONFLICT' | 'SESSION_CLOSED' | 'NOT_INVOKABLE' | 'METHOD_NOT_FOUND' | 'VALIDATION_FAILED' | 'AGENT_TIMEOUT' | 'AGENT_FAILED' | 'TOOL_EXEC_FAILED' | 'SERVICE_UNAVAILABLE' | 'CONTRACT_MISMATCH' | 'PROTOCOL_ERROR' | 'INTERNAL_ERROR' | 'SDK_CONFIGURATION_ERROR' | 'SDK_CONTRACT_ERROR' | 'SDK_HTTP_STATUS_ERROR' | 'UNKNOWN'; /** * Runtime-accessible const object mirroring the {@link SDKErrorCode} union. * Prefer referencing these constants over raw string literals for refactor safety. * * @example * import { SDKErrorCodes } from '@pellux/goodvibes-errors'; * * if (err.code === SDKErrorCodes.RATE_LIMITED) { * await delay(err.retryAfterMs ?? 1000); * } */ export declare const SDKErrorCodes: { readonly AUTH_REQUIRED: "AUTH_REQUIRED"; readonly TOKEN_EXPIRED: "TOKEN_EXPIRED"; readonly PERMISSION_DENIED: "PERMISSION_DENIED"; readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED"; readonly RATE_LIMITED: "RATE_LIMITED"; readonly NETWORK_UNREACHABLE: "NETWORK_UNREACHABLE"; readonly TIMEOUT: "TIMEOUT"; readonly CANCELLED: "CANCELLED"; readonly NOT_FOUND: "NOT_FOUND"; readonly CONFLICT: "CONFLICT"; readonly SESSION_CLOSED: "SESSION_CLOSED"; readonly NOT_INVOKABLE: "NOT_INVOKABLE"; readonly METHOD_NOT_FOUND: "METHOD_NOT_FOUND"; readonly VALIDATION_FAILED: "VALIDATION_FAILED"; readonly AGENT_TIMEOUT: "AGENT_TIMEOUT"; readonly AGENT_FAILED: "AGENT_FAILED"; readonly TOOL_EXEC_FAILED: "TOOL_EXEC_FAILED"; readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE"; readonly CONTRACT_MISMATCH: "CONTRACT_MISMATCH"; readonly PROTOCOL_ERROR: "PROTOCOL_ERROR"; readonly INTERNAL_ERROR: "INTERNAL_ERROR"; readonly SDK_CONFIGURATION_ERROR: "SDK_CONFIGURATION_ERROR"; readonly SDK_CONTRACT_ERROR: "SDK_CONTRACT_ERROR"; readonly SDK_HTTP_STATUS_ERROR: "SDK_HTTP_STATUS_ERROR"; readonly UNKNOWN: "UNKNOWN"; }; /** * Returns `true` when `err.code` equals the given {@link SDKErrorCode}, * narrowing the type of `err.code` to the specific literal. * * Works with any object that has a `code?: string` field, not limited to * {@link GoodVibesSdkError} subclasses. * * @example * import { isErrorCode, SDKErrorCodes, GoodVibesSdkError } from '@pellux/goodvibes-errors'; * * if (err instanceof GoodVibesSdkError && isErrorCode(err, SDKErrorCodes.RATE_LIMITED)) { * console.log('retry after', err.retryAfterMs); * } * * @param err - Any object with an optional `code` string field. * @param code - The {@link SDKErrorCode} literal to match against. */ export declare function isErrorCode(err: { readonly code?: SDKErrorCode | (string & {}) | undefined; }, code: C): err is { readonly code: C; }; /** * Returns `true` when `value` is a known {@link SDKErrorCode} string. * Useful for discriminating structured errors received over the wire. * * @param value - The string to test. */ export declare function isKnownErrorCode(value: string): value is SDKErrorCode; //# sourceMappingURL=error-codes.d.ts.map