@jaypie/llm 1.3.10 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,20 @@
1
1
  import { HookRunner, LlmHooks } from "../hooks/HookRunner.js";
2
2
  import { RetryPolicy } from "./RetryPolicy.js";
3
+ import { ClassifiedError } from "../types.js";
3
4
  export interface RetryContext {
4
5
  input: unknown;
5
6
  options?: unknown;
6
7
  providerRequest: unknown;
8
+ /** Provider name, carried onto the thrown LlmError */
9
+ provider?: string;
10
+ /** Model in use, carried onto the thrown LlmError */
11
+ model?: string;
7
12
  }
8
13
  export interface ErrorClassifier {
9
14
  isRetryable(error: unknown): boolean;
10
15
  isKnownError(error: unknown): boolean;
16
+ /** Full classification, used to throw a typed LlmError on terminal failure */
17
+ classify(error: unknown): ClassifiedError;
11
18
  }
12
19
  export interface RetryExecutorConfig {
13
20
  errorClassifier: ErrorClassifier;
@@ -27,6 +34,12 @@ export declare class RetryExecutor {
27
34
  private readonly hookRunner;
28
35
  private readonly errorClassifier;
29
36
  constructor(config: RetryExecutorConfig);
37
+ /**
38
+ * Build the typed, provider-agnostic error thrown when a request cannot be
39
+ * completed — classified (rate limit / quota / unrecoverable / transient)
40
+ * and carrying the provider, model, and original error as `cause`.
41
+ */
42
+ private toTerminalError;
30
43
  /**
31
44
  * Execute an operation with retry logic.
32
45
  * Each attempt receives an AbortSignal. On failure, the signal is aborted
@@ -97,8 +97,14 @@ export interface ProviderToolDefinition {
97
97
  export declare enum ErrorCategory {
98
98
  /** Error is transient and can be retried */
99
99
  Retryable = "retryable",
100
- /** Error is due to rate limiting */
100
+ /** Error is due to short-term rate limiting (retry after a delay) */
101
101
  RateLimit = "rate_limit",
102
+ /**
103
+ * Provider quota is exhausted or the account cannot be billed
104
+ * (insufficient funds, daily quota, plan limit). Terminal and actionable —
105
+ * retrying within the request budget will not help.
106
+ */
107
+ Quota = "quota",
102
108
  /** Error cannot be recovered from */
103
109
  Unrecoverable = "unrecoverable",
104
110
  /** Error type is unknown */
@@ -116,6 +122,11 @@ export interface ClassifiedError {
116
122
  shouldRetry: boolean;
117
123
  /** Suggested delay before retry (if applicable) */
118
124
  suggestedDelayMs?: number;
125
+ /**
126
+ * For {@link ErrorCategory.Quota}, distinguishes an exhausted usage quota
127
+ * from an account that cannot be billed (insufficient funds).
128
+ */
129
+ reason?: "quota" | "billing";
119
130
  }
120
131
  import type { ResponseBuilder } from "./response/ResponseBuilder.js";
121
132
  /**
@@ -295,6 +295,15 @@ export interface LlmOperateOptions {
295
295
  turns?: boolean | number;
296
296
  user?: string;
297
297
  }
298
+ /**
299
+ * A single model name, or a preference-ordered array of model names.
300
+ * An array is interpreted as a fallback chain: index 0 is primary, later
301
+ * entries are tried in order when earlier ones fail (provider auto-detected
302
+ * per entry). Accepted by the `Llm` constructor and static/instance
303
+ * `operate`/`send`/`stream` methods; normalized to a scalar model plus a
304
+ * derived fallback chain before reaching providers.
305
+ */
306
+ export type LlmModelOption = string | string[];
298
307
  export interface LlmOptions {
299
308
  apiKey?: string;
300
309
  /** Chain of fallback providers to try if primary fails */
@@ -0,0 +1,13 @@
1
+ import { ClassifiedError } from "../operate/types.js";
2
+ /**
3
+ * Shared, provider-agnostic first pass over an error. Returns a
4
+ * {@link ClassifiedError} when the message unambiguously identifies a
5
+ * cross-provider condition (retryable structured-output timeout, exhausted
6
+ * quota, or a billing failure), or `undefined` to defer to the adapter's own
7
+ * status/name classification.
8
+ *
9
+ * Adapters call this before their existing logic so that, for example, a
10
+ * `429` carrying a daily-quota message is classified as {@link
11
+ * ErrorCategory.Quota} rather than {@link ErrorCategory.RateLimit}.
12
+ */
13
+ export declare function classifyProviderError(error: unknown): ClassifiedError | undefined;
@@ -0,0 +1,17 @@
1
+ import { LlmFallbackConfig } from "../types/LlmProvider.interface.js";
2
+ /**
3
+ * Normalizes a `model` option that may be a single model name or a
4
+ * preference-ordered array of model names.
5
+ *
6
+ * A `string[]` is interpreted as a fallback chain: index `0` is the primary
7
+ * model, indices `1..` become fallback entries with an auto-detected provider
8
+ * (reusing `determineModelProvider`, exactly as the constructor's first
9
+ * argument does).
10
+ *
11
+ * Returns the primary model plus the derived fallback chain. A bare string
12
+ * yields an empty chain and is unchanged.
13
+ */
14
+ export declare function resolveModelChain(model?: string | string[]): {
15
+ model?: string;
16
+ fallback: LlmFallbackConfig[];
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "description": "Large language model utilities",
5
5
  "repository": {
6
6
  "type": "git",