@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/index.d.cts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import * as _jaypie_types from '@jaypie/types';
|
|
2
2
|
import { JsonObject, AnyValue, NaturalMap, NaturalSchema, JsonReturn } from '@jaypie/types';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
|
+
import { JaypieError } from '@jaypie/errors';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Provider-neutral reasoning-effort levels — a five-point relative scale that
|
|
8
|
+
* deliberately borrows no provider's vocabulary. Each adapter translates these
|
|
9
|
+
* to its provider's native control (OpenAI `reasoning.effort`, Anthropic
|
|
10
|
+
* `output_config.effort`, Gemini `thinkingLevel`/`thinkingBudget`, Grok
|
|
11
|
+
* `reasoning_effort`, OpenRouter `reasoning.effort`), spreading the scale across
|
|
12
|
+
* the provider's available range. Omitting `effort` leaves the provider default
|
|
13
|
+
* untouched, so it is safe to set across a fallback chain.
|
|
14
|
+
*/
|
|
15
|
+
declare const EFFORT: {
|
|
16
|
+
readonly LOWEST: "lowest";
|
|
17
|
+
readonly LOW: "low";
|
|
18
|
+
readonly MEDIUM: "medium";
|
|
19
|
+
readonly HIGH: "high";
|
|
20
|
+
readonly HIGHEST: "highest";
|
|
21
|
+
};
|
|
22
|
+
type LlmEffort = (typeof EFFORT)[keyof typeof EFFORT];
|
|
5
23
|
declare const MODEL: {
|
|
6
24
|
FABLE: string;
|
|
7
25
|
OPUS: string;
|
|
@@ -11,13 +29,26 @@ declare const MODEL: {
|
|
|
11
29
|
GEMINI_FLASH: string;
|
|
12
30
|
GEMINI_FLASH_LITE: string;
|
|
13
31
|
GEMINI_PRO: string;
|
|
32
|
+
SOL: string;
|
|
33
|
+
TERRA: string;
|
|
34
|
+
LUNA: string;
|
|
35
|
+
/** @deprecated use MODEL.SOL (gpt-5.6-sol) */
|
|
14
36
|
GPT: string;
|
|
37
|
+
/** @deprecated use MODEL.TERRA (gpt-5.6-terra) */
|
|
15
38
|
GPT_MINI: string;
|
|
39
|
+
/** @deprecated use MODEL.LUNA (gpt-5.6-luna) */
|
|
16
40
|
GPT_NANO: string;
|
|
17
41
|
GROK: string;
|
|
42
|
+
OPENROUTER: {
|
|
43
|
+
GLM: string;
|
|
44
|
+
LUNA: string;
|
|
45
|
+
SONNET: string;
|
|
46
|
+
};
|
|
18
47
|
};
|
|
19
48
|
declare const PROVIDER: {
|
|
20
49
|
readonly BEDROCK: {
|
|
50
|
+
readonly DEFAULT: "amazon.nova-pro-v1:0";
|
|
51
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.BEDROCK.DEFAULT. */
|
|
21
52
|
readonly MODEL: {
|
|
22
53
|
readonly DEFAULT: "amazon.nova-lite-v1:0";
|
|
23
54
|
readonly LARGE: "amazon.nova-pro-v1:0";
|
|
@@ -29,16 +60,18 @@ declare const PROVIDER: {
|
|
|
29
60
|
readonly REGION: "AWS_REGION";
|
|
30
61
|
};
|
|
31
62
|
readonly ANTHROPIC: {
|
|
63
|
+
readonly DEFAULT: string;
|
|
32
64
|
readonly MAX_TOKENS: {
|
|
33
65
|
readonly DEFAULT: 16384;
|
|
34
66
|
};
|
|
67
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.ANTHROPIC.DEFAULT, or pick a specific model from MODEL.*. */
|
|
35
68
|
readonly MODEL: {
|
|
36
69
|
readonly DEFAULT: "claude-sonnet-4-6";
|
|
37
70
|
readonly LARGE: "claude-opus-4-8";
|
|
38
71
|
readonly SMALL: "claude-sonnet-4-6";
|
|
39
72
|
readonly TINY: "claude-haiku-4-5";
|
|
40
73
|
};
|
|
41
|
-
readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "haiku", "opus", "sonnet"];
|
|
74
|
+
readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "fable", "haiku", "mythos", "opus", "sonnet"];
|
|
42
75
|
readonly NAME: "anthropic";
|
|
43
76
|
readonly PROMPT: {
|
|
44
77
|
readonly AI: "\n\nAssistant:";
|
|
@@ -55,6 +88,8 @@ declare const PROVIDER: {
|
|
|
55
88
|
};
|
|
56
89
|
/** @deprecated Use PROVIDER.GOOGLE — "Google" is the provider; Gemini is the model family */
|
|
57
90
|
readonly GEMINI: {
|
|
91
|
+
readonly DEFAULT: string;
|
|
92
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.GOOGLE.DEFAULT, or pick a specific model from MODEL.*. */
|
|
58
93
|
readonly MODEL: {
|
|
59
94
|
readonly DEFAULT: "gemini-3.1-pro-preview";
|
|
60
95
|
readonly LARGE: "gemini-3.1-pro-preview";
|
|
@@ -69,6 +104,8 @@ declare const PROVIDER: {
|
|
|
69
104
|
};
|
|
70
105
|
};
|
|
71
106
|
readonly GOOGLE: {
|
|
107
|
+
readonly DEFAULT: string;
|
|
108
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.GOOGLE.DEFAULT, or pick a specific model from MODEL.*. */
|
|
72
109
|
readonly MODEL: {
|
|
73
110
|
readonly DEFAULT: "gemini-3.1-pro-preview";
|
|
74
111
|
readonly LARGE: "gemini-3.1-pro-preview";
|
|
@@ -83,16 +120,20 @@ declare const PROVIDER: {
|
|
|
83
120
|
};
|
|
84
121
|
};
|
|
85
122
|
readonly OPENAI: {
|
|
123
|
+
readonly DEFAULT: string;
|
|
124
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
86
125
|
readonly MODEL: {
|
|
87
126
|
readonly DEFAULT: "gpt-5.4";
|
|
88
127
|
readonly LARGE: "gpt-5.5";
|
|
89
128
|
readonly SMALL: "gpt-5.4-mini";
|
|
90
129
|
readonly TINY: "gpt-5.4-nano";
|
|
91
130
|
};
|
|
92
|
-
readonly MODEL_MATCH_WORDS: readonly ["openai", "
|
|
131
|
+
readonly MODEL_MATCH_WORDS: readonly ["gpt", "luna", "openai", "sol", "terra", RegExp];
|
|
93
132
|
readonly NAME: "openai";
|
|
94
133
|
};
|
|
95
134
|
readonly OPENROUTER: {
|
|
135
|
+
readonly DEFAULT: string;
|
|
136
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENROUTER.DEFAULT, or pick a specific route from MODEL.OPENROUTER.*. */
|
|
96
137
|
readonly MODEL: {
|
|
97
138
|
readonly DEFAULT: "anthropic/claude-sonnet-4-6";
|
|
98
139
|
readonly LARGE: "anthropic/claude-opus-4-8";
|
|
@@ -111,6 +152,8 @@ declare const PROVIDER: {
|
|
|
111
152
|
readonly XAI: {
|
|
112
153
|
readonly API_KEY: "XAI_API_KEY";
|
|
113
154
|
readonly BASE_URL: "https://api.x.ai/v1";
|
|
155
|
+
readonly DEFAULT: string;
|
|
156
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.XAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
114
157
|
readonly MODEL: {
|
|
115
158
|
readonly DEFAULT: "grok-latest";
|
|
116
159
|
readonly LARGE: "grok-latest";
|
|
@@ -123,6 +166,7 @@ declare const PROVIDER: {
|
|
|
123
166
|
};
|
|
124
167
|
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;
|
|
125
168
|
declare const DEFAULT: {
|
|
169
|
+
/** @deprecated Size tiers are retired in 2.0. Use DEFAULT.PROVIDER.DEFAULT, or pick a specific model from MODEL.*. */
|
|
126
170
|
readonly MODEL: {
|
|
127
171
|
readonly BASE: "gpt-5.4";
|
|
128
172
|
readonly LARGE: "gpt-5.5";
|
|
@@ -130,16 +174,22 @@ declare const DEFAULT: {
|
|
|
130
174
|
readonly TINY: "gpt-5.4-nano";
|
|
131
175
|
};
|
|
132
176
|
readonly PROVIDER: {
|
|
177
|
+
readonly DEFAULT: string;
|
|
178
|
+
/** @deprecated Size tiers are retired in 2.0. Use PROVIDER.OPENAI.DEFAULT, or pick a specific model from MODEL.*. */
|
|
133
179
|
readonly MODEL: {
|
|
134
180
|
readonly DEFAULT: "gpt-5.4";
|
|
135
181
|
readonly LARGE: "gpt-5.5";
|
|
136
182
|
readonly SMALL: "gpt-5.4-mini";
|
|
137
183
|
readonly TINY: "gpt-5.4-nano";
|
|
138
184
|
};
|
|
139
|
-
readonly MODEL_MATCH_WORDS: readonly ["openai", "
|
|
185
|
+
readonly MODEL_MATCH_WORDS: readonly ["gpt", "luna", "openai", "sol", "terra", RegExp];
|
|
140
186
|
readonly NAME: "openai";
|
|
141
187
|
};
|
|
142
188
|
};
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Size-tier catalogs are retired in 2.0. Pick specific models from
|
|
191
|
+
* MODEL.* (grouped by provider via MODEL_MATCH_WORDS / determineModelProvider).
|
|
192
|
+
*/
|
|
143
193
|
declare const ALL: {
|
|
144
194
|
readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-latest"];
|
|
145
195
|
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")[];
|
|
@@ -150,12 +200,14 @@ declare const ALL: {
|
|
|
150
200
|
|
|
151
201
|
declare const constants_ALL: typeof ALL;
|
|
152
202
|
declare const constants_DEFAULT: typeof DEFAULT;
|
|
203
|
+
declare const constants_EFFORT: typeof EFFORT;
|
|
204
|
+
type constants_LlmEffort = LlmEffort;
|
|
153
205
|
type constants_LlmProviderName = LlmProviderName;
|
|
154
206
|
declare const constants_MODEL: typeof MODEL;
|
|
155
207
|
declare const constants_PROVIDER: typeof PROVIDER;
|
|
156
208
|
declare namespace constants {
|
|
157
|
-
export { constants_ALL as ALL, constants_DEFAULT as DEFAULT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
|
|
158
|
-
export type { constants_LlmProviderName as LlmProviderName };
|
|
209
|
+
export { constants_ALL as ALL, constants_DEFAULT as DEFAULT, constants_EFFORT as EFFORT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
|
|
210
|
+
export type { constants_LlmEffort as LlmEffort, constants_LlmProviderName as LlmProviderName };
|
|
159
211
|
}
|
|
160
212
|
|
|
161
213
|
interface LlmTool {
|
|
@@ -273,7 +325,7 @@ declare enum LlmResponseStatus {
|
|
|
273
325
|
Incomplete = "incomplete",
|
|
274
326
|
InProgress = "in_progress"
|
|
275
327
|
}
|
|
276
|
-
interface LlmError {
|
|
328
|
+
interface LlmError$1 {
|
|
277
329
|
detail?: string;
|
|
278
330
|
status: number | string;
|
|
279
331
|
title: string;
|
|
@@ -461,6 +513,14 @@ interface LlmProgressEvent {
|
|
|
461
513
|
type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
462
514
|
interface LlmOperateOptions {
|
|
463
515
|
data?: NaturalMap;
|
|
516
|
+
/**
|
|
517
|
+
* Provider-neutral reasoning effort (lowest | low | medium | high | highest).
|
|
518
|
+
* Each provider translates it to its native control, spreading the scale
|
|
519
|
+
* across the provider's range; omitting it leaves the provider default
|
|
520
|
+
* untouched, so it is safe across a fallback chain. Providers without
|
|
521
|
+
* reasoning control ignore it.
|
|
522
|
+
*/
|
|
523
|
+
effort?: LlmEffort;
|
|
464
524
|
explain?: boolean;
|
|
465
525
|
/** Chain of fallback providers to try if primary fails. Set to false to disable instance-level fallback. */
|
|
466
526
|
fallback?: LlmFallbackConfig[] | false;
|
|
@@ -534,6 +594,15 @@ interface LlmOperateOptions {
|
|
|
534
594
|
turns?: boolean | number;
|
|
535
595
|
user?: string;
|
|
536
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* A single model name, or a preference-ordered array of model names.
|
|
599
|
+
* An array is interpreted as a fallback chain: index 0 is primary, later
|
|
600
|
+
* entries are tried in order when earlier ones fail (provider auto-detected
|
|
601
|
+
* per entry). Accepted by the `Llm` constructor and static/instance
|
|
602
|
+
* `operate`/`send`/`stream` methods; normalized to a scalar model plus a
|
|
603
|
+
* derived fallback chain before reaching providers.
|
|
604
|
+
*/
|
|
605
|
+
type LlmModelOption = string | string[];
|
|
537
606
|
interface LlmOptions {
|
|
538
607
|
apiKey?: string;
|
|
539
608
|
/** Chain of fallback providers to try if primary fails */
|
|
@@ -551,7 +620,7 @@ interface LlmUsageItem {
|
|
|
551
620
|
type LlmUsage = LlmUsageItem[];
|
|
552
621
|
interface LlmOperateResponse {
|
|
553
622
|
content?: string | JsonObject;
|
|
554
|
-
error?: LlmError;
|
|
623
|
+
error?: LlmError$1;
|
|
555
624
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
556
625
|
fallbackAttempts?: number;
|
|
557
626
|
/** Whether a fallback provider was used instead of the primary */
|
|
@@ -577,9 +646,13 @@ declare class Llm implements LlmProvider {
|
|
|
577
646
|
private _llm;
|
|
578
647
|
private _options;
|
|
579
648
|
private _provider;
|
|
580
|
-
constructor(providerName?: LlmProviderName | string, options?: LlmOptions
|
|
649
|
+
constructor(providerName?: LlmProviderName | string, options?: Omit<LlmOptions, "model"> & {
|
|
650
|
+
model?: LlmModelOption;
|
|
651
|
+
});
|
|
581
652
|
private createProvider;
|
|
582
|
-
send(message: string, options?: LlmMessageOptions
|
|
653
|
+
send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
|
|
654
|
+
model?: LlmModelOption;
|
|
655
|
+
}): Promise<string | JsonObject>;
|
|
583
656
|
/**
|
|
584
657
|
* Resolves the fallback chain from instance config and per-call options.
|
|
585
658
|
* Per-call options take precedence over instance config.
|
|
@@ -590,23 +663,27 @@ declare class Llm implements LlmProvider {
|
|
|
590
663
|
* Creates a fallback Llm instance lazily when needed.
|
|
591
664
|
*/
|
|
592
665
|
private createFallbackInstance;
|
|
593
|
-
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions
|
|
594
|
-
|
|
595
|
-
|
|
666
|
+
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
667
|
+
model?: LlmModelOption;
|
|
668
|
+
}): Promise<LlmOperateResponse>;
|
|
669
|
+
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
670
|
+
model?: LlmModelOption;
|
|
671
|
+
}): AsyncIterable<LlmStreamChunk>;
|
|
672
|
+
static send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
|
|
596
673
|
llm?: LlmProviderName;
|
|
597
674
|
apiKey?: string;
|
|
598
|
-
model?: string;
|
|
675
|
+
model?: string | string[];
|
|
599
676
|
}): Promise<string | JsonObject>;
|
|
600
|
-
static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
|
|
677
|
+
static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
601
678
|
apiKey?: string;
|
|
602
679
|
fallback?: LlmFallbackConfig[] | false;
|
|
603
680
|
llm?: LlmProviderName;
|
|
604
|
-
model?: string;
|
|
681
|
+
model?: string | string[];
|
|
605
682
|
}): Promise<LlmOperateResponse>;
|
|
606
|
-
static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
|
|
683
|
+
static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
607
684
|
llm?: LlmProviderName;
|
|
608
685
|
apiKey?: string;
|
|
609
|
-
model?: string;
|
|
686
|
+
model?: string | string[];
|
|
610
687
|
}): AsyncIterable<LlmStreamChunk>;
|
|
611
688
|
}
|
|
612
689
|
|
|
@@ -637,6 +714,87 @@ declare class JaypieToolkit extends Toolkit {
|
|
|
637
714
|
}
|
|
638
715
|
declare const toolkit: JaypieToolkit;
|
|
639
716
|
|
|
717
|
+
/**
|
|
718
|
+
* Categories of errors for retry logic
|
|
719
|
+
*/
|
|
720
|
+
declare enum ErrorCategory {
|
|
721
|
+
/** Error is transient and can be retried */
|
|
722
|
+
Retryable = "retryable",
|
|
723
|
+
/** Error is due to short-term rate limiting (retry after a delay) */
|
|
724
|
+
RateLimit = "rate_limit",
|
|
725
|
+
/**
|
|
726
|
+
* Provider quota is exhausted or the account cannot be billed
|
|
727
|
+
* (insufficient funds, daily quota, plan limit). Terminal and actionable —
|
|
728
|
+
* retrying within the request budget will not help.
|
|
729
|
+
*/
|
|
730
|
+
Quota = "quota",
|
|
731
|
+
/** Error cannot be recovered from */
|
|
732
|
+
Unrecoverable = "unrecoverable",
|
|
733
|
+
/** Error type is unknown */
|
|
734
|
+
Unknown = "unknown"
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
interface LlmErrorOptions {
|
|
738
|
+
/** Provider name that produced the error (e.g. "anthropic", "google") */
|
|
739
|
+
provider?: string;
|
|
740
|
+
/** Model in use when the error occurred */
|
|
741
|
+
model?: string;
|
|
742
|
+
/** Milliseconds to wait before retrying, when the provider suggests one */
|
|
743
|
+
retryAfterMs?: number;
|
|
744
|
+
/** The original provider error, preserved for inspection */
|
|
745
|
+
cause?: unknown;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Normalized, provider-agnostic LLM error. Thrown by the operate/stream retry
|
|
749
|
+
* layer when a request cannot be completed, so consumers can `catch` a stable
|
|
750
|
+
* type regardless of which provider failed. Extends {@link JaypieError} so
|
|
751
|
+
* `isJaypieError()` and `.status` continue to work; the original provider error
|
|
752
|
+
* is preserved on `.cause`.
|
|
753
|
+
*/
|
|
754
|
+
declare class LlmError extends JaypieError {
|
|
755
|
+
readonly category: ErrorCategory;
|
|
756
|
+
readonly provider?: string;
|
|
757
|
+
readonly model?: string;
|
|
758
|
+
readonly retryAfterMs?: number;
|
|
759
|
+
readonly cause?: unknown;
|
|
760
|
+
constructor(message: string, category: ErrorCategory, { status, title, provider, model, retryAfterMs, cause, }?: LlmErrorOptions & {
|
|
761
|
+
status?: number;
|
|
762
|
+
title?: string;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Short-term rate limiting (per-minute 429). Terminal within the request
|
|
767
|
+
* budget; `retryAfterMs` carries the provider's suggested wait when available.
|
|
768
|
+
*/
|
|
769
|
+
declare class LlmRateLimitError extends LlmError {
|
|
770
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Provider quota is exhausted or the account cannot be billed. Terminal and
|
|
774
|
+
* actionable. `reason` distinguishes an exhausted usage quota from insufficient
|
|
775
|
+
* funds.
|
|
776
|
+
*/
|
|
777
|
+
declare class LlmQuotaError extends LlmError {
|
|
778
|
+
readonly reason: "quota" | "billing";
|
|
779
|
+
constructor(message: string, { reason, ...options }?: LlmErrorOptions & {
|
|
780
|
+
reason?: "quota" | "billing";
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* The request cannot be recovered from (bad request, authentication,
|
|
785
|
+
* permission, not found). Terminal.
|
|
786
|
+
*/
|
|
787
|
+
declare class LlmUnrecoverableError extends LlmError {
|
|
788
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* A transient or unknown error survived the retry budget. Terminal only because
|
|
792
|
+
* retries were exhausted; the underlying condition may succeed later.
|
|
793
|
+
*/
|
|
794
|
+
declare class LlmTransientError extends LlmError {
|
|
795
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
796
|
+
}
|
|
797
|
+
|
|
640
798
|
/**
|
|
641
799
|
* Extracts reasoning text from LLM history items.
|
|
642
800
|
*
|
|
@@ -739,5 +897,5 @@ declare class XaiProvider implements LlmProvider {
|
|
|
739
897
|
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
740
898
|
}
|
|
741
899
|
|
|
742
|
-
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
743
|
-
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
|
900
|
+
export { BedrockProvider, ErrorCategory, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmError, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmQuotaError, LlmRateLimitError, LlmStreamChunkType, LlmTransientError, LlmUnrecoverableError, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
901
|
+
export type { LlmEffort, LlmErrorOptions, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export { default as Llm } from "./Llm.js";
|
|
2
2
|
export * as LLM from "./constants.js";
|
|
3
|
-
export type {
|
|
3
|
+
export type { LlmEffort } from "./constants.js";
|
|
4
|
+
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
|
|
4
5
|
export { LlmMessageRole, LlmMessageType, LlmProgressEventType, } from "./types/LlmProvider.interface.js";
|
|
5
6
|
export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
|
|
6
7
|
export type { LlmTool } from "./types/LlmTool.interface.js";
|
|
7
8
|
export type { LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, } from "./types/LlmStreamChunk.interface.js";
|
|
8
9
|
export { LlmStreamChunkType } from "./types/LlmStreamChunk.interface.js";
|
|
9
10
|
export { JaypieToolkit, toolkit, Toolkit, tools } from "./tools/index.js";
|
|
11
|
+
export { LlmError, LlmQuotaError, LlmRateLimitError, LlmTransientError, LlmUnrecoverableError, } from "./errors/LlmError.js";
|
|
12
|
+
export type { LlmErrorOptions } from "./errors/LlmError.js";
|
|
13
|
+
export { ErrorCategory } from "./operate/types.js";
|
|
10
14
|
export { extractReasoning } from "./util/extractReasoning.js";
|
|
11
15
|
export { jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, } from "./util/jsonSchema.js";
|
|
12
16
|
export { BedrockProvider } from "./providers/bedrock/index.js";
|
|
@@ -16,7 +16,8 @@ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
|
|
|
16
16
|
*/
|
|
17
17
|
type AnthropicRequestParams = Anthropic.MessageCreateParams & {
|
|
18
18
|
output_config?: {
|
|
19
|
-
|
|
19
|
+
effort?: string;
|
|
20
|
+
format?: {
|
|
20
21
|
type: "json_schema";
|
|
21
22
|
schema: JsonObject;
|
|
22
23
|
};
|
|
@@ -29,7 +30,7 @@ type AnthropicRequestParams = Anthropic.MessageCreateParams & {
|
|
|
29
30
|
*/
|
|
30
31
|
export declare class AnthropicAdapter extends BaseProviderAdapter {
|
|
31
32
|
readonly name: "anthropic";
|
|
32
|
-
readonly defaultModel:
|
|
33
|
+
readonly defaultModel: string;
|
|
33
34
|
private runtimeNoTemperatureModels;
|
|
34
35
|
private runtimeNoStructuredOutputModels;
|
|
35
36
|
rememberModelRejectsTemperature(model: string): void;
|
|
@@ -49,7 +49,7 @@ type AnnotatedBedrockResponse = ConverseCommandOutput & {
|
|
|
49
49
|
};
|
|
50
50
|
export declare class BedrockAdapter extends BaseProviderAdapter {
|
|
51
51
|
readonly name: "bedrock";
|
|
52
|
-
readonly defaultModel: "amazon.nova-
|
|
52
|
+
readonly defaultModel: "amazon.nova-pro-v1:0";
|
|
53
53
|
private _modelsFallbackToStructuredOutputTool;
|
|
54
54
|
private _modelsWithoutTemperature;
|
|
55
55
|
private rememberModelRejectsOutputConfig;
|
|
@@ -13,7 +13,7 @@ import { GeminiPart, GeminiRawResponse, GeminiRequest } from "../../providers/go
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class GoogleAdapter extends BaseProviderAdapter {
|
|
15
15
|
readonly name: "google";
|
|
16
|
-
readonly defaultModel:
|
|
16
|
+
readonly defaultModel: string;
|
|
17
17
|
private runtimeNoStructuredOutputComboModels;
|
|
18
18
|
rememberModelRejectsStructuredOutputCombo(model: string): void;
|
|
19
19
|
clearRuntimeNoStructuredOutputComboModels(): void;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { JsonObject, NaturalSchema } from "@jaypie/types";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
+
import { type LlmEffort } from "../../constants.js";
|
|
4
|
+
import { type LlmEffortMapping } from "../../util/effort.js";
|
|
3
5
|
import { Toolkit } from "../../tools/Toolkit.class.js";
|
|
4
6
|
import { LlmHistory, LlmOperateOptions, LlmToolResult, LlmUsageItem } from "../../types/LlmProvider.interface.js";
|
|
5
7
|
import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
|
|
@@ -12,11 +14,15 @@ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
|
|
|
12
14
|
*/
|
|
13
15
|
export declare class OpenAiAdapter extends BaseProviderAdapter {
|
|
14
16
|
readonly name: "openai";
|
|
15
|
-
readonly defaultModel:
|
|
17
|
+
readonly defaultModel: string;
|
|
16
18
|
private runtimeNoTemperatureModels;
|
|
17
19
|
rememberModelRejectsTemperature(model: string): void;
|
|
18
20
|
clearRuntimeNoTemperatureModels(): void;
|
|
19
21
|
private supportsTemperature;
|
|
22
|
+
/** Whether `reasoning.effort` may be sent for this model. Overridden by xAI. */
|
|
23
|
+
protected supportsReasoningEffort(model: string): boolean;
|
|
24
|
+
/** Translate a normalized effort to this provider's `reasoning.effort` value. */
|
|
25
|
+
protected mapReasoningEffort(effort: LlmEffort, model: string): LlmEffortMapping;
|
|
20
26
|
buildRequest(request: OperateRequest): unknown;
|
|
21
27
|
formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
|
|
22
28
|
formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
|
|
@@ -79,6 +79,10 @@ interface OpenRouterRequest {
|
|
|
79
79
|
tools?: OpenRouterTool[];
|
|
80
80
|
tool_choice?: "auto" | "none" | "required";
|
|
81
81
|
response_format?: OpenRouterResponseFormat;
|
|
82
|
+
reasoning?: {
|
|
83
|
+
effort?: string;
|
|
84
|
+
max_tokens?: number;
|
|
85
|
+
};
|
|
82
86
|
user?: string;
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
@@ -111,7 +115,7 @@ type OpenRouterContentPart = {
|
|
|
111
115
|
*/
|
|
112
116
|
export declare class OpenRouterAdapter extends BaseProviderAdapter {
|
|
113
117
|
readonly name: "openrouter";
|
|
114
|
-
readonly defaultModel:
|
|
118
|
+
readonly defaultModel: string;
|
|
115
119
|
private runtimeNoStructuredOutputModels;
|
|
116
120
|
rememberModelRejectsStructuredOutput(model: string): void;
|
|
117
121
|
clearRuntimeNoStructuredOutputModels(): void;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type LlmEffort } from "../../constants.js";
|
|
2
|
+
import { type LlmEffortMapping } from "../../util/effort.js";
|
|
1
3
|
import { ClassifiedError } from "../types.js";
|
|
2
4
|
import { OpenAiAdapter } from "./OpenAiAdapter.js";
|
|
3
5
|
/**
|
|
@@ -8,7 +10,15 @@ import { OpenAiAdapter } from "./OpenAiAdapter.js";
|
|
|
8
10
|
*/
|
|
9
11
|
export declare class XaiAdapter extends OpenAiAdapter {
|
|
10
12
|
readonly name: "xai";
|
|
11
|
-
readonly defaultModel:
|
|
13
|
+
readonly defaultModel: string;
|
|
14
|
+
/**
|
|
15
|
+
* Grok gates reasoning effort by model, not by the OpenAI `gpt-*`/`o*`
|
|
16
|
+
* patterns. Only explicit `*-reasoning` models accept `reasoning_effort`;
|
|
17
|
+
* bare grok-4 reasons implicitly and rejects it, so we stay conservative and
|
|
18
|
+
* only opt in models whose name advertises reasoning.
|
|
19
|
+
*/
|
|
20
|
+
protected supportsReasoningEffort(model: string): boolean;
|
|
21
|
+
protected mapReasoningEffort(effort: LlmEffort): LlmEffortMapping;
|
|
12
22
|
classifyError(error: unknown): ClassifiedError;
|
|
13
23
|
}
|
|
14
24
|
export declare const xaiAdapter: XaiAdapter;
|
|
@@ -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
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JsonObject } from "@jaypie/types";
|
|
2
|
+
import { type LlmEffort } from "../constants.js";
|
|
2
3
|
import { LlmHistory, LlmMessageType, LlmOperateOptions, LlmUsageItem } from "../types/LlmProvider.interface.js";
|
|
3
4
|
import { Toolkit } from "../tools/Toolkit.class.js";
|
|
4
5
|
/**
|
|
@@ -68,6 +69,8 @@ export interface OperateRequest {
|
|
|
68
69
|
tools?: ProviderToolDefinition[];
|
|
69
70
|
/** Structured output format */
|
|
70
71
|
format?: JsonObject;
|
|
72
|
+
/** Normalized reasoning effort; adapters translate to provider-native control */
|
|
73
|
+
effort?: LlmEffort;
|
|
71
74
|
/** Provider-specific options */
|
|
72
75
|
providerOptions?: JsonObject;
|
|
73
76
|
/** Whether the request will execute over a streaming transport */
|
|
@@ -94,8 +97,14 @@ export interface ProviderToolDefinition {
|
|
|
94
97
|
export declare enum ErrorCategory {
|
|
95
98
|
/** Error is transient and can be retried */
|
|
96
99
|
Retryable = "retryable",
|
|
97
|
-
/** Error is due to rate limiting */
|
|
100
|
+
/** Error is due to short-term rate limiting (retry after a delay) */
|
|
98
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",
|
|
99
108
|
/** Error cannot be recovered from */
|
|
100
109
|
Unrecoverable = "unrecoverable",
|
|
101
110
|
/** Error type is unknown */
|
|
@@ -113,6 +122,11 @@ export interface ClassifiedError {
|
|
|
113
122
|
shouldRetry: boolean;
|
|
114
123
|
/** Suggested delay before retry (if applicable) */
|
|
115
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";
|
|
116
130
|
}
|
|
117
131
|
import type { ResponseBuilder } from "./response/ResponseBuilder.js";
|
|
118
132
|
/**
|
|
@@ -73,6 +73,11 @@ export interface GeminiGenerateContentConfig {
|
|
|
73
73
|
responseMimeType?: string;
|
|
74
74
|
responseJsonSchema?: JsonObject;
|
|
75
75
|
responseSchema?: JsonObject;
|
|
76
|
+
thinkingConfig?: {
|
|
77
|
+
thinkingLevel?: string;
|
|
78
|
+
thinkingBudget?: number;
|
|
79
|
+
includeThoughts?: boolean;
|
|
80
|
+
};
|
|
76
81
|
temperature?: number;
|
|
77
82
|
topP?: number;
|
|
78
83
|
topK?: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnyValue, JsonObject, JsonReturn, NaturalMap, NaturalSchema } from "@jaypie/types";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
+
import { type LlmEffort } from "../constants.js";
|
|
3
4
|
import { LlmTool } from "./LlmTool.interface.js";
|
|
4
5
|
import { LlmStreamChunk } from "./LlmStreamChunk.interface.js";
|
|
5
6
|
import { Toolkit } from "../tools/Toolkit.class.js";
|
|
@@ -213,6 +214,14 @@ export interface LlmProgressEvent {
|
|
|
213
214
|
export type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
214
215
|
export interface LlmOperateOptions {
|
|
215
216
|
data?: NaturalMap;
|
|
217
|
+
/**
|
|
218
|
+
* Provider-neutral reasoning effort (lowest | low | medium | high | highest).
|
|
219
|
+
* Each provider translates it to its native control, spreading the scale
|
|
220
|
+
* across the provider's range; omitting it leaves the provider default
|
|
221
|
+
* untouched, so it is safe across a fallback chain. Providers without
|
|
222
|
+
* reasoning control ignore it.
|
|
223
|
+
*/
|
|
224
|
+
effort?: LlmEffort;
|
|
216
225
|
explain?: boolean;
|
|
217
226
|
/** Chain of fallback providers to try if primary fails. Set to false to disable instance-level fallback. */
|
|
218
227
|
fallback?: LlmFallbackConfig[] | false;
|
|
@@ -286,6 +295,15 @@ export interface LlmOperateOptions {
|
|
|
286
295
|
turns?: boolean | number;
|
|
287
296
|
user?: string;
|
|
288
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[];
|
|
289
307
|
export interface LlmOptions {
|
|
290
308
|
apiKey?: string;
|
|
291
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;
|