@jaypie/llm 1.3.9 → 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 +19 -11
- package/dist/cjs/constants.d.ts +53 -4
- package/dist/cjs/errors/LlmError.d.ts +62 -0
- package/dist/cjs/errors/toLlmError.d.ts +11 -0
- package/dist/cjs/index.cjs +739 -177
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +177 -19
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/operate/adapters/AnthropicAdapter.d.ts +3 -2
- package/dist/cjs/operate/adapters/BedrockAdapter.d.ts +1 -1
- package/dist/cjs/operate/adapters/GoogleAdapter.d.ts +1 -1
- package/dist/cjs/operate/adapters/OpenAiAdapter.d.ts +7 -1
- package/dist/cjs/operate/adapters/OpenRouterAdapter.d.ts +5 -1
- package/dist/cjs/operate/adapters/XaiAdapter.d.ts +11 -1
- package/dist/cjs/operate/retry/RetryExecutor.d.ts +13 -0
- package/dist/cjs/operate/types.d.ts +15 -1
- package/dist/cjs/providers/google/types.d.ts +5 -0
- package/dist/cjs/types/LlmProvider.interface.d.ts +18 -0
- package/dist/cjs/util/classifyProviderError.d.ts +13 -0
- package/dist/cjs/util/effort.d.ts +42 -0
- package/dist/cjs/util/resolveModelChain.d.ts +17 -0
- package/dist/esm/Llm.d.ts +19 -11
- package/dist/esm/constants.d.ts +53 -4
- package/dist/esm/errors/LlmError.d.ts +62 -0
- package/dist/esm/errors/toLlmError.d.ts +11 -0
- package/dist/esm/index.d.ts +177 -19
- package/dist/esm/index.js +705 -148
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operate/adapters/AnthropicAdapter.d.ts +3 -2
- package/dist/esm/operate/adapters/BedrockAdapter.d.ts +1 -1
- package/dist/esm/operate/adapters/GoogleAdapter.d.ts +1 -1
- package/dist/esm/operate/adapters/OpenAiAdapter.d.ts +7 -1
- package/dist/esm/operate/adapters/OpenRouterAdapter.d.ts +5 -1
- package/dist/esm/operate/adapters/XaiAdapter.d.ts +11 -1
- package/dist/esm/operate/retry/RetryExecutor.d.ts +13 -0
- package/dist/esm/operate/types.d.ts +15 -1
- package/dist/esm/providers/google/types.d.ts +5 -0
- package/dist/esm/types/LlmProvider.interface.d.ts +18 -0
- package/dist/esm/util/classifyProviderError.d.ts +13 -0
- package/dist/esm/util/effort.d.ts +42 -0
- package/dist/esm/util/resolveModelChain.d.ts +17 -0
- package/package.json +1 -1
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
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
package/dist/cjs/constants.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-neutral reasoning-effort levels — a five-point relative scale that
|
|
3
|
+
* deliberately borrows no provider's vocabulary. Each adapter translates these
|
|
4
|
+
* to its provider's native control (OpenAI `reasoning.effort`, Anthropic
|
|
5
|
+
* `output_config.effort`, Gemini `thinkingLevel`/`thinkingBudget`, Grok
|
|
6
|
+
* `reasoning_effort`, OpenRouter `reasoning.effort`), spreading the scale across
|
|
7
|
+
* the provider's available range. Omitting `effort` leaves the provider default
|
|
8
|
+
* untouched, so it is safe to set across a fallback chain.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EFFORT: {
|
|
11
|
+
readonly LOWEST: "lowest";
|
|
12
|
+
readonly LOW: "low";
|
|
13
|
+
readonly MEDIUM: "medium";
|
|
14
|
+
readonly HIGH: "high";
|
|
15
|
+
readonly HIGHEST: "highest";
|
|
16
|
+
};
|
|
17
|
+
export type LlmEffort = (typeof EFFORT)[keyof typeof EFFORT];
|
|
1
18
|
export declare const MODEL: {
|
|
2
19
|
FABLE: string;
|
|
3
20
|
OPUS: string;
|
|
@@ -7,13 +24,26 @@ export declare const MODEL: {
|
|
|
7
24
|
GEMINI_FLASH: string;
|
|
8
25
|
GEMINI_FLASH_LITE: string;
|
|
9
26
|
GEMINI_PRO: string;
|
|
27
|
+
SOL: string;
|
|
28
|
+
TERRA: string;
|
|
29
|
+
LUNA: string;
|
|
30
|
+
/** @deprecated use MODEL.SOL (gpt-5.6-sol) */
|
|
10
31
|
GPT: string;
|
|
32
|
+
/** @deprecated use MODEL.TERRA (gpt-5.6-terra) */
|
|
11
33
|
GPT_MINI: string;
|
|
34
|
+
/** @deprecated use MODEL.LUNA (gpt-5.6-luna) */
|
|
12
35
|
GPT_NANO: string;
|
|
13
36
|
GROK: string;
|
|
37
|
+
OPENROUTER: {
|
|
38
|
+
GLM: string;
|
|
39
|
+
LUNA: string;
|
|
40
|
+
SONNET: string;
|
|
41
|
+
};
|
|
14
42
|
};
|
|
15
43
|
export declare const PROVIDER: {
|
|
16
44
|
readonly BEDROCK: {
|
|
45
|
+
readonly DEFAULT: "amazon.nova-pro-v1:0";
|
|
46
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.BEDROCK.DEFAULT. */
|
|
17
47
|
readonly MODEL: {
|
|
18
48
|
readonly DEFAULT: "amazon.nova-lite-v1:0";
|
|
19
49
|
readonly LARGE: "amazon.nova-pro-v1:0";
|
|
@@ -25,16 +55,18 @@ export declare const PROVIDER: {
|
|
|
25
55
|
readonly REGION: "AWS_REGION";
|
|
26
56
|
};
|
|
27
57
|
readonly ANTHROPIC: {
|
|
58
|
+
readonly DEFAULT: string;
|
|
28
59
|
readonly MAX_TOKENS: {
|
|
29
60
|
readonly DEFAULT: 16384;
|
|
30
61
|
};
|
|
62
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.ANTHROPIC.DEFAULT, or pick a specific model from MODEL.*. */
|
|
31
63
|
readonly MODEL: {
|
|
32
64
|
readonly DEFAULT: "claude-sonnet-4-6";
|
|
33
65
|
readonly LARGE: "claude-opus-4-8";
|
|
34
66
|
readonly SMALL: "claude-sonnet-4-6";
|
|
35
67
|
readonly TINY: "claude-haiku-4-5";
|
|
36
68
|
};
|
|
37
|
-
readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "haiku", "opus", "sonnet"];
|
|
69
|
+
readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "fable", "haiku", "mythos", "opus", "sonnet"];
|
|
38
70
|
readonly NAME: "anthropic";
|
|
39
71
|
readonly PROMPT: {
|
|
40
72
|
readonly AI: "\n\nAssistant:";
|
|
@@ -51,6 +83,8 @@ export declare const PROVIDER: {
|
|
|
51
83
|
};
|
|
52
84
|
/** @deprecated Use PROVIDER.GOOGLE — "Google" is the provider; Gemini is the model family */
|
|
53
85
|
readonly GEMINI: {
|
|
86
|
+
readonly DEFAULT: string;
|
|
87
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.GOOGLE.DEFAULT, or pick a specific model from MODEL.*. */
|
|
54
88
|
readonly MODEL: {
|
|
55
89
|
readonly DEFAULT: "gemini-3.1-pro-preview";
|
|
56
90
|
readonly LARGE: "gemini-3.1-pro-preview";
|
|
@@ -65,6 +99,8 @@ export declare const PROVIDER: {
|
|
|
65
99
|
};
|
|
66
100
|
};
|
|
67
101
|
readonly GOOGLE: {
|
|
102
|
+
readonly DEFAULT: string;
|
|
103
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.GOOGLE.DEFAULT, or pick a specific model from MODEL.*. */
|
|
68
104
|
readonly MODEL: {
|
|
69
105
|
readonly DEFAULT: "gemini-3.1-pro-preview";
|
|
70
106
|
readonly LARGE: "gemini-3.1-pro-preview";
|
|
@@ -79,16 +115,20 @@ export declare const PROVIDER: {
|
|
|
79
115
|
};
|
|
80
116
|
};
|
|
81
117
|
readonly OPENAI: {
|
|
118
|
+
readonly DEFAULT: string;
|
|
119
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
82
120
|
readonly MODEL: {
|
|
83
121
|
readonly DEFAULT: "gpt-5.4";
|
|
84
122
|
readonly LARGE: "gpt-5.5";
|
|
85
123
|
readonly SMALL: "gpt-5.4-mini";
|
|
86
124
|
readonly TINY: "gpt-5.4-nano";
|
|
87
125
|
};
|
|
88
|
-
readonly MODEL_MATCH_WORDS: readonly ["openai", "
|
|
126
|
+
readonly MODEL_MATCH_WORDS: readonly ["gpt", "luna", "openai", "sol", "terra", RegExp];
|
|
89
127
|
readonly NAME: "openai";
|
|
90
128
|
};
|
|
91
129
|
readonly OPENROUTER: {
|
|
130
|
+
readonly DEFAULT: string;
|
|
131
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENROUTER.DEFAULT, or pick a specific route from MODEL.OPENROUTER.*. */
|
|
92
132
|
readonly MODEL: {
|
|
93
133
|
readonly DEFAULT: "anthropic/claude-sonnet-4-6";
|
|
94
134
|
readonly LARGE: "anthropic/claude-opus-4-8";
|
|
@@ -107,6 +147,8 @@ export declare const PROVIDER: {
|
|
|
107
147
|
readonly XAI: {
|
|
108
148
|
readonly API_KEY: "XAI_API_KEY";
|
|
109
149
|
readonly BASE_URL: "https://api.x.ai/v1";
|
|
150
|
+
readonly DEFAULT: string;
|
|
151
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.XAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
110
152
|
readonly MODEL: {
|
|
111
153
|
readonly DEFAULT: "grok-latest";
|
|
112
154
|
readonly LARGE: "grok-latest";
|
|
@@ -119,6 +161,7 @@ export declare const PROVIDER: {
|
|
|
119
161
|
};
|
|
120
162
|
export type LlmProviderName = typeof PROVIDER.ANTHROPIC.NAME | typeof PROVIDER.BEDROCK.NAME | typeof PROVIDER.GOOGLE.NAME | typeof PROVIDER.OPENAI.NAME | typeof PROVIDER.OPENROUTER.NAME | typeof PROVIDER.XAI.NAME;
|
|
121
163
|
export declare const DEFAULT: {
|
|
164
|
+
/** @deprecated Size tiers are retired in 2.0. Use DEFAULT.PROVIDER.DEFAULT, or pick a specific model from MODEL.*. */
|
|
122
165
|
readonly MODEL: {
|
|
123
166
|
readonly BASE: "gpt-5.4";
|
|
124
167
|
readonly LARGE: "gpt-5.5";
|
|
@@ -126,19 +169,25 @@ export declare const DEFAULT: {
|
|
|
126
169
|
readonly TINY: "gpt-5.4-nano";
|
|
127
170
|
};
|
|
128
171
|
readonly PROVIDER: {
|
|
172
|
+
readonly DEFAULT: string;
|
|
173
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
129
174
|
readonly MODEL: {
|
|
130
175
|
readonly DEFAULT: "gpt-5.4";
|
|
131
176
|
readonly LARGE: "gpt-5.5";
|
|
132
177
|
readonly SMALL: "gpt-5.4-mini";
|
|
133
178
|
readonly TINY: "gpt-5.4-nano";
|
|
134
179
|
};
|
|
135
|
-
readonly MODEL_MATCH_WORDS: readonly ["openai", "
|
|
180
|
+
readonly MODEL_MATCH_WORDS: readonly ["gpt", "luna", "openai", "sol", "terra", RegExp];
|
|
136
181
|
readonly NAME: "openai";
|
|
137
182
|
};
|
|
138
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Size-tier catalogs are retired in 2.0. Pick specific models from
|
|
186
|
+
* MODEL.* (grouped by provider via MODEL_MATCH_WORDS / determineModelProvider).
|
|
187
|
+
*/
|
|
139
188
|
export declare const ALL: {
|
|
140
189
|
readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-latest"];
|
|
141
|
-
readonly COMBINED: readonly ("claude-
|
|
190
|
+
readonly COMBINED: readonly ("claude-opus-4-8" | "claude-haiku-4-5" | "gemini-3.5-flash" | "gemini-3.1-flash-lite" | "gemini-3.1-pro-preview" | "gpt-5.5" | "gpt-5.4-mini" | "gpt-5.4-nano" | "grok-latest" | "claude-sonnet-4-6" | "gpt-5.4" | "grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning")[];
|
|
142
191
|
readonly LARGE: readonly ["claude-opus-4-8", "gemini-3.1-pro-preview", "gpt-5.5", "grok-latest"];
|
|
143
192
|
readonly SMALL: readonly ["claude-sonnet-4-6", "gemini-3.5-flash", "gpt-5.4-mini", "grok-4-1-fast-reasoning"];
|
|
144
193
|
readonly TINY: readonly ["claude-haiku-4-5", "gemini-3.1-flash-lite", "gpt-5.4-nano", "grok-4-1-fast-non-reasoning"];
|
|
@@ -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;
|