@jaypie/llm 1.3.10 → 1.3.12
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 +15 -1
- package/dist/cjs/errors/LlmError.d.ts +62 -0
- package/dist/cjs/errors/toLlmError.d.ts +11 -0
- package/dist/cjs/index.cjs +5776 -4274
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +147 -15
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/operate/adapters/FireworksAdapter.d.ts +151 -0
- package/dist/cjs/operate/adapters/index.d.ts +1 -0
- package/dist/cjs/operate/index.d.ts +1 -1
- package/dist/cjs/operate/retry/RetryExecutor.d.ts +13 -0
- package/dist/cjs/operate/types.d.ts +12 -1
- package/dist/cjs/providers/fireworks/FireworksProvider.class.d.ts +21 -0
- package/dist/cjs/providers/fireworks/client.d.ts +37 -0
- package/dist/cjs/providers/fireworks/index.d.ts +2 -0
- package/dist/cjs/providers/fireworks/utils.d.ts +15 -0
- package/dist/cjs/types/LlmProvider.interface.d.ts +9 -0
- package/dist/cjs/util/classifyProviderError.d.ts +13 -0
- package/dist/cjs/util/effort.d.ts +1 -0
- package/dist/cjs/util/resolveModelChain.d.ts +17 -0
- package/dist/esm/Llm.d.ts +19 -11
- package/dist/esm/constants.d.ts +15 -1
- package/dist/esm/errors/LlmError.d.ts +62 -0
- package/dist/esm/errors/toLlmError.d.ts +11 -0
- package/dist/esm/index.d.ts +147 -15
- package/dist/esm/index.js +5760 -4264
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operate/adapters/FireworksAdapter.d.ts +151 -0
- package/dist/esm/operate/adapters/index.d.ts +1 -0
- package/dist/esm/operate/index.d.ts +1 -1
- package/dist/esm/operate/retry/RetryExecutor.d.ts +13 -0
- package/dist/esm/operate/types.d.ts +12 -1
- package/dist/esm/providers/fireworks/FireworksProvider.class.d.ts +21 -0
- package/dist/esm/providers/fireworks/client.d.ts +37 -0
- package/dist/esm/providers/fireworks/index.d.ts +2 -0
- package/dist/esm/providers/fireworks/utils.d.ts +15 -0
- package/dist/esm/types/LlmProvider.interface.d.ts +9 -0
- package/dist/esm/util/classifyProviderError.d.ts +13 -0
- package/dist/esm/util/effort.d.ts +1 -0
- package/dist/esm/util/resolveModelChain.d.ts +17 -0
- package/package.json +1 -1
package/dist/esm/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/esm/constants.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ export declare const MODEL: {
|
|
|
21
21
|
SONNET: string;
|
|
22
22
|
HAIKU: string;
|
|
23
23
|
MYTHOS: string;
|
|
24
|
+
FIREWORKS: {
|
|
25
|
+
DEEPSEEK: string;
|
|
26
|
+
GLM: string;
|
|
27
|
+
KIMI: string;
|
|
28
|
+
MINIMAX: string;
|
|
29
|
+
QWEN: string;
|
|
30
|
+
};
|
|
24
31
|
GEMINI_FLASH: string;
|
|
25
32
|
GEMINI_FLASH_LITE: string;
|
|
26
33
|
GEMINI_PRO: string;
|
|
@@ -81,6 +88,13 @@ export declare const PROVIDER: {
|
|
|
81
88
|
readonly SCHEMA_VERSION: "v2";
|
|
82
89
|
};
|
|
83
90
|
};
|
|
91
|
+
readonly FIREWORKS: {
|
|
92
|
+
readonly API_KEY: "FIREWORKS_API_KEY";
|
|
93
|
+
readonly BASE_URL: "https://api.fireworks.ai/inference/v1";
|
|
94
|
+
readonly DEFAULT: string;
|
|
95
|
+
readonly MODEL_MATCH_WORDS: readonly ["fireworks"];
|
|
96
|
+
readonly NAME: "fireworks";
|
|
97
|
+
};
|
|
84
98
|
/** @deprecated Use PROVIDER.GOOGLE — "Google" is the provider; Gemini is the model family */
|
|
85
99
|
readonly GEMINI: {
|
|
86
100
|
readonly DEFAULT: string;
|
|
@@ -159,7 +173,7 @@ export declare const PROVIDER: {
|
|
|
159
173
|
readonly NAME: "xai";
|
|
160
174
|
};
|
|
161
175
|
};
|
|
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;
|
|
176
|
+
export type LlmProviderName = typeof PROVIDER.ANTHROPIC.NAME | typeof PROVIDER.BEDROCK.NAME | typeof PROVIDER.FIREWORKS.NAME | typeof PROVIDER.GOOGLE.NAME | typeof PROVIDER.OPENAI.NAME | typeof PROVIDER.OPENROUTER.NAME | typeof PROVIDER.XAI.NAME;
|
|
163
177
|
export declare const DEFAULT: {
|
|
164
178
|
/** @deprecated Size tiers are retired in 2.0. Use DEFAULT.PROVIDER.DEFAULT, or pick a specific model from MODEL.*. */
|
|
165
179
|
readonly MODEL: {
|
|
@@ -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;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
|
|
5
6
|
/**
|
|
6
7
|
* Provider-neutral reasoning-effort levels — a five-point relative scale that
|
|
@@ -25,6 +26,13 @@ declare const MODEL: {
|
|
|
25
26
|
SONNET: string;
|
|
26
27
|
HAIKU: string;
|
|
27
28
|
MYTHOS: string;
|
|
29
|
+
FIREWORKS: {
|
|
30
|
+
DEEPSEEK: string;
|
|
31
|
+
GLM: string;
|
|
32
|
+
KIMI: string;
|
|
33
|
+
MINIMAX: string;
|
|
34
|
+
QWEN: string;
|
|
35
|
+
};
|
|
28
36
|
GEMINI_FLASH: string;
|
|
29
37
|
GEMINI_FLASH_LITE: string;
|
|
30
38
|
GEMINI_PRO: string;
|
|
@@ -85,6 +93,13 @@ declare const PROVIDER: {
|
|
|
85
93
|
readonly SCHEMA_VERSION: "v2";
|
|
86
94
|
};
|
|
87
95
|
};
|
|
96
|
+
readonly FIREWORKS: {
|
|
97
|
+
readonly API_KEY: "FIREWORKS_API_KEY";
|
|
98
|
+
readonly BASE_URL: "https://api.fireworks.ai/inference/v1";
|
|
99
|
+
readonly DEFAULT: string;
|
|
100
|
+
readonly MODEL_MATCH_WORDS: readonly ["fireworks"];
|
|
101
|
+
readonly NAME: "fireworks";
|
|
102
|
+
};
|
|
88
103
|
/** @deprecated Use PROVIDER.GOOGLE — "Google" is the provider; Gemini is the model family */
|
|
89
104
|
readonly GEMINI: {
|
|
90
105
|
readonly DEFAULT: string;
|
|
@@ -163,7 +178,7 @@ declare const PROVIDER: {
|
|
|
163
178
|
readonly NAME: "xai";
|
|
164
179
|
};
|
|
165
180
|
};
|
|
166
|
-
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;
|
|
181
|
+
type LlmProviderName = typeof PROVIDER.ANTHROPIC.NAME | typeof PROVIDER.BEDROCK.NAME | typeof PROVIDER.FIREWORKS.NAME | typeof PROVIDER.GOOGLE.NAME | typeof PROVIDER.OPENAI.NAME | typeof PROVIDER.OPENROUTER.NAME | typeof PROVIDER.XAI.NAME;
|
|
167
182
|
declare const DEFAULT: {
|
|
168
183
|
/** @deprecated Size tiers are retired in 2.0. Use DEFAULT.PROVIDER.DEFAULT, or pick a specific model from MODEL.*. */
|
|
169
184
|
readonly MODEL: {
|
|
@@ -324,7 +339,7 @@ declare enum LlmResponseStatus {
|
|
|
324
339
|
Incomplete = "incomplete",
|
|
325
340
|
InProgress = "in_progress"
|
|
326
341
|
}
|
|
327
|
-
interface LlmError {
|
|
342
|
+
interface LlmError$1 {
|
|
328
343
|
detail?: string;
|
|
329
344
|
status: number | string;
|
|
330
345
|
title: string;
|
|
@@ -593,6 +608,15 @@ interface LlmOperateOptions {
|
|
|
593
608
|
turns?: boolean | number;
|
|
594
609
|
user?: string;
|
|
595
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* A single model name, or a preference-ordered array of model names.
|
|
613
|
+
* An array is interpreted as a fallback chain: index 0 is primary, later
|
|
614
|
+
* entries are tried in order when earlier ones fail (provider auto-detected
|
|
615
|
+
* per entry). Accepted by the `Llm` constructor and static/instance
|
|
616
|
+
* `operate`/`send`/`stream` methods; normalized to a scalar model plus a
|
|
617
|
+
* derived fallback chain before reaching providers.
|
|
618
|
+
*/
|
|
619
|
+
type LlmModelOption = string | string[];
|
|
596
620
|
interface LlmOptions {
|
|
597
621
|
apiKey?: string;
|
|
598
622
|
/** Chain of fallback providers to try if primary fails */
|
|
@@ -610,7 +634,7 @@ interface LlmUsageItem {
|
|
|
610
634
|
type LlmUsage = LlmUsageItem[];
|
|
611
635
|
interface LlmOperateResponse {
|
|
612
636
|
content?: string | JsonObject;
|
|
613
|
-
error?: LlmError;
|
|
637
|
+
error?: LlmError$1;
|
|
614
638
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
615
639
|
fallbackAttempts?: number;
|
|
616
640
|
/** Whether a fallback provider was used instead of the primary */
|
|
@@ -636,9 +660,13 @@ declare class Llm implements LlmProvider {
|
|
|
636
660
|
private _llm;
|
|
637
661
|
private _options;
|
|
638
662
|
private _provider;
|
|
639
|
-
constructor(providerName?: LlmProviderName | string, options?: LlmOptions
|
|
663
|
+
constructor(providerName?: LlmProviderName | string, options?: Omit<LlmOptions, "model"> & {
|
|
664
|
+
model?: LlmModelOption;
|
|
665
|
+
});
|
|
640
666
|
private createProvider;
|
|
641
|
-
send(message: string, options?: LlmMessageOptions
|
|
667
|
+
send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
|
|
668
|
+
model?: LlmModelOption;
|
|
669
|
+
}): Promise<string | JsonObject>;
|
|
642
670
|
/**
|
|
643
671
|
* Resolves the fallback chain from instance config and per-call options.
|
|
644
672
|
* Per-call options take precedence over instance config.
|
|
@@ -649,23 +677,27 @@ declare class Llm implements LlmProvider {
|
|
|
649
677
|
* Creates a fallback Llm instance lazily when needed.
|
|
650
678
|
*/
|
|
651
679
|
private createFallbackInstance;
|
|
652
|
-
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions
|
|
653
|
-
|
|
654
|
-
|
|
680
|
+
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
681
|
+
model?: LlmModelOption;
|
|
682
|
+
}): Promise<LlmOperateResponse>;
|
|
683
|
+
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
684
|
+
model?: LlmModelOption;
|
|
685
|
+
}): AsyncIterable<LlmStreamChunk>;
|
|
686
|
+
static send(message: string, options?: Omit<LlmMessageOptions, "model"> & {
|
|
655
687
|
llm?: LlmProviderName;
|
|
656
688
|
apiKey?: string;
|
|
657
|
-
model?: string;
|
|
689
|
+
model?: string | string[];
|
|
658
690
|
}): Promise<string | JsonObject>;
|
|
659
|
-
static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
|
|
691
|
+
static operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
660
692
|
apiKey?: string;
|
|
661
693
|
fallback?: LlmFallbackConfig[] | false;
|
|
662
694
|
llm?: LlmProviderName;
|
|
663
|
-
model?: string;
|
|
695
|
+
model?: string | string[];
|
|
664
696
|
}): Promise<LlmOperateResponse>;
|
|
665
|
-
static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions & {
|
|
697
|
+
static stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
666
698
|
llm?: LlmProviderName;
|
|
667
699
|
apiKey?: string;
|
|
668
|
-
model?: string;
|
|
700
|
+
model?: string | string[];
|
|
669
701
|
}): AsyncIterable<LlmStreamChunk>;
|
|
670
702
|
}
|
|
671
703
|
|
|
@@ -696,6 +728,87 @@ declare class JaypieToolkit extends Toolkit {
|
|
|
696
728
|
}
|
|
697
729
|
declare const toolkit: JaypieToolkit;
|
|
698
730
|
|
|
731
|
+
/**
|
|
732
|
+
* Categories of errors for retry logic
|
|
733
|
+
*/
|
|
734
|
+
declare enum ErrorCategory {
|
|
735
|
+
/** Error is transient and can be retried */
|
|
736
|
+
Retryable = "retryable",
|
|
737
|
+
/** Error is due to short-term rate limiting (retry after a delay) */
|
|
738
|
+
RateLimit = "rate_limit",
|
|
739
|
+
/**
|
|
740
|
+
* Provider quota is exhausted or the account cannot be billed
|
|
741
|
+
* (insufficient funds, daily quota, plan limit). Terminal and actionable —
|
|
742
|
+
* retrying within the request budget will not help.
|
|
743
|
+
*/
|
|
744
|
+
Quota = "quota",
|
|
745
|
+
/** Error cannot be recovered from */
|
|
746
|
+
Unrecoverable = "unrecoverable",
|
|
747
|
+
/** Error type is unknown */
|
|
748
|
+
Unknown = "unknown"
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
interface LlmErrorOptions {
|
|
752
|
+
/** Provider name that produced the error (e.g. "anthropic", "google") */
|
|
753
|
+
provider?: string;
|
|
754
|
+
/** Model in use when the error occurred */
|
|
755
|
+
model?: string;
|
|
756
|
+
/** Milliseconds to wait before retrying, when the provider suggests one */
|
|
757
|
+
retryAfterMs?: number;
|
|
758
|
+
/** The original provider error, preserved for inspection */
|
|
759
|
+
cause?: unknown;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Normalized, provider-agnostic LLM error. Thrown by the operate/stream retry
|
|
763
|
+
* layer when a request cannot be completed, so consumers can `catch` a stable
|
|
764
|
+
* type regardless of which provider failed. Extends {@link JaypieError} so
|
|
765
|
+
* `isJaypieError()` and `.status` continue to work; the original provider error
|
|
766
|
+
* is preserved on `.cause`.
|
|
767
|
+
*/
|
|
768
|
+
declare class LlmError extends JaypieError {
|
|
769
|
+
readonly category: ErrorCategory;
|
|
770
|
+
readonly provider?: string;
|
|
771
|
+
readonly model?: string;
|
|
772
|
+
readonly retryAfterMs?: number;
|
|
773
|
+
readonly cause?: unknown;
|
|
774
|
+
constructor(message: string, category: ErrorCategory, { status, title, provider, model, retryAfterMs, cause, }?: LlmErrorOptions & {
|
|
775
|
+
status?: number;
|
|
776
|
+
title?: string;
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Short-term rate limiting (per-minute 429). Terminal within the request
|
|
781
|
+
* budget; `retryAfterMs` carries the provider's suggested wait when available.
|
|
782
|
+
*/
|
|
783
|
+
declare class LlmRateLimitError extends LlmError {
|
|
784
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Provider quota is exhausted or the account cannot be billed. Terminal and
|
|
788
|
+
* actionable. `reason` distinguishes an exhausted usage quota from insufficient
|
|
789
|
+
* funds.
|
|
790
|
+
*/
|
|
791
|
+
declare class LlmQuotaError extends LlmError {
|
|
792
|
+
readonly reason: "quota" | "billing";
|
|
793
|
+
constructor(message: string, { reason, ...options }?: LlmErrorOptions & {
|
|
794
|
+
reason?: "quota" | "billing";
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* The request cannot be recovered from (bad request, authentication,
|
|
799
|
+
* permission, not found). Terminal.
|
|
800
|
+
*/
|
|
801
|
+
declare class LlmUnrecoverableError extends LlmError {
|
|
802
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* A transient or unknown error survived the retry budget. Terminal only because
|
|
806
|
+
* retries were exhausted; the underlying condition may succeed later.
|
|
807
|
+
*/
|
|
808
|
+
declare class LlmTransientError extends LlmError {
|
|
809
|
+
constructor(message: string, options?: LlmErrorOptions);
|
|
810
|
+
}
|
|
811
|
+
|
|
699
812
|
/**
|
|
700
813
|
* Extracts reasoning text from LLM history items.
|
|
701
814
|
*
|
|
@@ -741,6 +854,25 @@ declare class BedrockProvider implements LlmProvider {
|
|
|
741
854
|
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
742
855
|
}
|
|
743
856
|
|
|
857
|
+
declare class FireworksProvider implements LlmProvider {
|
|
858
|
+
private model;
|
|
859
|
+
private _client?;
|
|
860
|
+
private _operateLoop?;
|
|
861
|
+
private _streamLoop?;
|
|
862
|
+
private apiKey?;
|
|
863
|
+
private log;
|
|
864
|
+
private conversationHistory;
|
|
865
|
+
constructor(model?: string, { apiKey }?: {
|
|
866
|
+
apiKey?: string;
|
|
867
|
+
});
|
|
868
|
+
private getClient;
|
|
869
|
+
private getOperateLoop;
|
|
870
|
+
private getStreamLoop;
|
|
871
|
+
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
872
|
+
operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
|
|
873
|
+
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
874
|
+
}
|
|
875
|
+
|
|
744
876
|
declare class GoogleProvider implements LlmProvider {
|
|
745
877
|
private model;
|
|
746
878
|
private _client?;
|
|
@@ -798,5 +930,5 @@ declare class XaiProvider implements LlmProvider {
|
|
|
798
930
|
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
799
931
|
}
|
|
800
932
|
|
|
801
|
-
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 };
|
|
802
|
-
export type { LlmEffort, 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 };
|
|
933
|
+
export { BedrockProvider, ErrorCategory, FireworksProvider, 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 };
|
|
934
|
+
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 };
|