@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.
package/dist/cjs/Llm.d.ts CHANGED
@@ -1,15 +1,19 @@
1
1
  import { JsonObject } from "@jaypie/types";
2
2
  import { LlmProviderName } from "./constants.js";
3
- import { LlmFallbackConfig, LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider } from "./types/LlmProvider.interface.js";
3
+ import { LlmFallbackConfig, LlmHistory, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider } from "./types/LlmProvider.interface.js";
4
4
  import { LlmStreamChunk } from "./types/LlmStreamChunk.interface.js";
5
5
  declare class Llm implements LlmProvider {
6
6
  private _fallbackConfig?;
7
7
  private _llm;
8
8
  private _options;
9
9
  private _provider;
10
- constructor(providerName?: LlmProviderName | string, options?: LlmOptions);
10
+ constructor(providerName?: LlmProviderName | string, options?: Omit<LlmOptions, "model"> & {
11
+ model?: LlmModelOption;
12
+ });
11
13
  private createProvider;
12
- send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
14
+ send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
15
+ model?: LlmModelOption;
16
+ }): Promise<string | JsonObject>;
13
17
  /**
14
18
  * Resolves the fallback chain from instance config and per-call options.
15
19
  * Per-call options take precedence over instance config.
@@ -20,23 +24,27 @@ declare class Llm implements LlmProvider {
20
24
  * Creates a fallback Llm instance lazily when needed.
21
25
  */
22
26
  private createFallbackInstance;
23
- operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
24
- stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
25
- static send(message: string, options?: LlmMessageOptions & {
27
+ operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
28
+ model?: LlmModelOption;
29
+ }): Promise<LlmOperateResponse>;
30
+ stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
31
+ model?: LlmModelOption;
32
+ }): AsyncIterable<LlmStreamChunk>;
33
+ static send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
26
34
  llm?: LlmProviderName;
27
35
  apiKey?: string;
28
- model?: string;
36
+ model?: string | string[];
29
37
  }): Promise<string | JsonObject>;
30
- static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
38
+ static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
31
39
  apiKey?: string;
32
40
  fallback?: LlmFallbackConfig[] | false;
33
41
  llm?: LlmProviderName;
34
- model?: string;
42
+ model?: string | string[];
35
43
  }): Promise<LlmOperateResponse>;
36
- static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
44
+ static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
37
45
  llm?: LlmProviderName;
38
46
  apiKey?: string;
39
- model?: string;
47
+ model?: string | string[];
40
48
  }): AsyncIterable<LlmStreamChunk>;
41
49
  }
42
50
  export default Llm;
@@ -0,0 +1,62 @@
1
+ import { JaypieError } from "@jaypie/errors";
2
+ import { ErrorCategory } from "../operate/types.js";
3
+ export interface LlmErrorOptions {
4
+ /** Provider name that produced the error (e.g. "anthropic", "google") */
5
+ provider?: string;
6
+ /** Model in use when the error occurred */
7
+ model?: string;
8
+ /** Milliseconds to wait before retrying, when the provider suggests one */
9
+ retryAfterMs?: number;
10
+ /** The original provider error, preserved for inspection */
11
+ cause?: unknown;
12
+ }
13
+ /**
14
+ * Normalized, provider-agnostic LLM error. Thrown by the operate/stream retry
15
+ * layer when a request cannot be completed, so consumers can `catch` a stable
16
+ * type regardless of which provider failed. Extends {@link JaypieError} so
17
+ * `isJaypieError()` and `.status` continue to work; the original provider error
18
+ * is preserved on `.cause`.
19
+ */
20
+ export declare class LlmError extends JaypieError {
21
+ readonly category: ErrorCategory;
22
+ readonly provider?: string;
23
+ readonly model?: string;
24
+ readonly retryAfterMs?: number;
25
+ readonly cause?: unknown;
26
+ constructor(message: string, category: ErrorCategory, { status, title, provider, model, retryAfterMs, cause, }?: LlmErrorOptions & {
27
+ status?: number;
28
+ title?: string;
29
+ });
30
+ }
31
+ /**
32
+ * Short-term rate limiting (per-minute 429). Terminal within the request
33
+ * budget; `retryAfterMs` carries the provider's suggested wait when available.
34
+ */
35
+ export declare class LlmRateLimitError extends LlmError {
36
+ constructor(message: string, options?: LlmErrorOptions);
37
+ }
38
+ /**
39
+ * Provider quota is exhausted or the account cannot be billed. Terminal and
40
+ * actionable. `reason` distinguishes an exhausted usage quota from insufficient
41
+ * funds.
42
+ */
43
+ export declare class LlmQuotaError extends LlmError {
44
+ readonly reason: "quota" | "billing";
45
+ constructor(message: string, { reason, ...options }?: LlmErrorOptions & {
46
+ reason?: "quota" | "billing";
47
+ });
48
+ }
49
+ /**
50
+ * The request cannot be recovered from (bad request, authentication,
51
+ * permission, not found). Terminal.
52
+ */
53
+ export declare class LlmUnrecoverableError extends LlmError {
54
+ constructor(message: string, options?: LlmErrorOptions);
55
+ }
56
+ /**
57
+ * A transient or unknown error survived the retry budget. Terminal only because
58
+ * retries were exhausted; the underlying condition may succeed later.
59
+ */
60
+ export declare class LlmTransientError extends LlmError {
61
+ constructor(message: string, options?: LlmErrorOptions);
62
+ }
@@ -0,0 +1,11 @@
1
+ import { ClassifiedError } from "../operate/types.js";
2
+ import { LlmError } from "./LlmError.js";
3
+ /**
4
+ * Map a {@link ClassifiedError} to the matching {@link LlmError} subclass,
5
+ * preserving the original error as `cause`. Used by the retry layer to throw a
6
+ * stable, catchable type instead of a bare gateway error.
7
+ */
8
+ export declare function toLlmError(classified: ClassifiedError, context?: {
9
+ provider?: string;
10
+ model?: string;
11
+ }): LlmError;