@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.
Files changed (42) hide show
  1. package/dist/cjs/Llm.d.ts +19 -11
  2. package/dist/cjs/constants.d.ts +15 -1
  3. package/dist/cjs/errors/LlmError.d.ts +62 -0
  4. package/dist/cjs/errors/toLlmError.d.ts +11 -0
  5. package/dist/cjs/index.cjs +5776 -4274
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +147 -15
  8. package/dist/cjs/index.d.ts +5 -1
  9. package/dist/cjs/operate/adapters/FireworksAdapter.d.ts +151 -0
  10. package/dist/cjs/operate/adapters/index.d.ts +1 -0
  11. package/dist/cjs/operate/index.d.ts +1 -1
  12. package/dist/cjs/operate/retry/RetryExecutor.d.ts +13 -0
  13. package/dist/cjs/operate/types.d.ts +12 -1
  14. package/dist/cjs/providers/fireworks/FireworksProvider.class.d.ts +21 -0
  15. package/dist/cjs/providers/fireworks/client.d.ts +37 -0
  16. package/dist/cjs/providers/fireworks/index.d.ts +2 -0
  17. package/dist/cjs/providers/fireworks/utils.d.ts +15 -0
  18. package/dist/cjs/types/LlmProvider.interface.d.ts +9 -0
  19. package/dist/cjs/util/classifyProviderError.d.ts +13 -0
  20. package/dist/cjs/util/effort.d.ts +1 -0
  21. package/dist/cjs/util/resolveModelChain.d.ts +17 -0
  22. package/dist/esm/Llm.d.ts +19 -11
  23. package/dist/esm/constants.d.ts +15 -1
  24. package/dist/esm/errors/LlmError.d.ts +62 -0
  25. package/dist/esm/errors/toLlmError.d.ts +11 -0
  26. package/dist/esm/index.d.ts +147 -15
  27. package/dist/esm/index.js +5760 -4264
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/operate/adapters/FireworksAdapter.d.ts +151 -0
  30. package/dist/esm/operate/adapters/index.d.ts +1 -0
  31. package/dist/esm/operate/index.d.ts +1 -1
  32. package/dist/esm/operate/retry/RetryExecutor.d.ts +13 -0
  33. package/dist/esm/operate/types.d.ts +12 -1
  34. package/dist/esm/providers/fireworks/FireworksProvider.class.d.ts +21 -0
  35. package/dist/esm/providers/fireworks/client.d.ts +37 -0
  36. package/dist/esm/providers/fireworks/index.d.ts +2 -0
  37. package/dist/esm/providers/fireworks/utils.d.ts +15 -0
  38. package/dist/esm/types/LlmProvider.interface.d.ts +9 -0
  39. package/dist/esm/util/classifyProviderError.d.ts +13 -0
  40. package/dist/esm/util/effort.d.ts +1 -0
  41. package/dist/esm/util/resolveModelChain.d.ts +17 -0
  42. package/package.json +1 -1
@@ -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): Promise<string | JsonObject>;
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): Promise<LlmOperateResponse>;
653
- stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
654
- static send(message: string, options?: LlmMessageOptions & {
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 };
@@ -1,16 +1,20 @@
1
1
  export { default as Llm } from "./Llm.js";
2
2
  export * as LLM from "./constants.js";
3
3
  export type { LlmEffort } from "./constants.js";
4
- export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.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";
5
5
  export { LlmMessageRole, LlmMessageType, LlmProgressEventType, } from "./types/LlmProvider.interface.js";
6
6
  export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
7
7
  export type { LlmTool } from "./types/LlmTool.interface.js";
8
8
  export type { LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, } from "./types/LlmStreamChunk.interface.js";
9
9
  export { LlmStreamChunkType } from "./types/LlmStreamChunk.interface.js";
10
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";
11
14
  export { extractReasoning } from "./util/extractReasoning.js";
12
15
  export { jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, } from "./util/jsonSchema.js";
13
16
  export { BedrockProvider } from "./providers/bedrock/index.js";
17
+ export { FireworksProvider } from "./providers/fireworks/index.js";
14
18
  /** @deprecated Use GoogleProvider — "Google" is the provider; Gemini is the model family */
15
19
  export { GoogleProvider as GeminiProvider } from "./providers/google/index.js";
16
20
  export { GoogleProvider } from "./providers/google/index.js";
@@ -0,0 +1,151 @@
1
+ import { JsonObject, NaturalSchema } from "@jaypie/types";
2
+ import { z } from "zod/v4";
3
+ import { Toolkit } from "../../tools/Toolkit.class.js";
4
+ import { LlmHistory, LlmOperateOptions, LlmUsageItem } from "../../types/LlmProvider.interface.js";
5
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
6
+ import { ClassifiedError, OperateRequest, ParsedResponse, ProviderToolDefinition, StandardToolCall, StandardToolResult } from "../types.js";
7
+ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
8
+ interface FireworksMessage {
9
+ role: "system" | "user" | "assistant" | "tool";
10
+ content?: string | FireworksContentPart[] | null;
11
+ toolCalls?: FireworksToolCall[];
12
+ toolCallId?: string;
13
+ }
14
+ interface FireworksToolCall {
15
+ id: string;
16
+ type: "function";
17
+ function: {
18
+ name: string;
19
+ arguments: string;
20
+ };
21
+ }
22
+ interface FireworksResponseMessage {
23
+ role: "assistant";
24
+ content?: string | null;
25
+ toolCalls?: FireworksToolCall[];
26
+ refusal?: string | null;
27
+ reasoning?: string | null;
28
+ reasoning_content?: string | null;
29
+ }
30
+ interface FireworksChoice {
31
+ index: number;
32
+ message: FireworksResponseMessage;
33
+ finishReason: string | null;
34
+ finish_reason?: string | null;
35
+ }
36
+ interface FireworksUsage {
37
+ promptTokens: number;
38
+ completionTokens: number;
39
+ totalTokens: number;
40
+ prompt_tokens?: number;
41
+ completion_tokens?: number;
42
+ total_tokens?: number;
43
+ completionTokensDetails?: {
44
+ reasoningTokens?: number;
45
+ };
46
+ }
47
+ interface FireworksResponse {
48
+ id: string;
49
+ object: string;
50
+ created: number;
51
+ model: string;
52
+ choices: FireworksChoice[];
53
+ usage?: FireworksUsage;
54
+ }
55
+ interface FireworksTool {
56
+ type: "function";
57
+ function: {
58
+ name: string;
59
+ description: string;
60
+ parameters: JsonObject;
61
+ };
62
+ }
63
+ interface FireworksJsonSchemaConfig {
64
+ name: string;
65
+ description?: string;
66
+ schema: JsonObject;
67
+ strict?: boolean;
68
+ }
69
+ type FireworksResponseFormat = {
70
+ type: "json_schema";
71
+ json_schema: FireworksJsonSchemaConfig;
72
+ } | {
73
+ type: "json_object";
74
+ } | {
75
+ type: "text";
76
+ };
77
+ interface FireworksRequest {
78
+ model: string;
79
+ messages: FireworksMessage[];
80
+ tools?: FireworksTool[];
81
+ tool_choice?: "auto" | "none" | "required";
82
+ response_format?: FireworksResponseFormat;
83
+ reasoning_effort?: string;
84
+ user?: string;
85
+ }
86
+ /**
87
+ * Fireworks content part types. Fireworks follows the OpenAI Chat Completions
88
+ * multimodal schema for `image_url` parts (URL or base64 data URI). There is
89
+ * no OpenAI-style `file` part, and the API rejects `data:` URIs for documents
90
+ * ("Unsupported URL scheme 'data'"), so file inputs cannot be delivered.
91
+ */
92
+ type FireworksContentPart = {
93
+ type: "text";
94
+ text: string;
95
+ } | {
96
+ type: "image_url";
97
+ imageUrl: {
98
+ url: string;
99
+ };
100
+ };
101
+ /**
102
+ * FireworksAdapter implements the ProviderAdapter interface for Fireworks AI's
103
+ * OpenAI-compatible Chat Completions API. It handles request building,
104
+ * response parsing, and error classification specific to Fireworks.
105
+ */
106
+ export declare class FireworksAdapter extends BaseProviderAdapter {
107
+ readonly name: "fireworks";
108
+ readonly defaultModel: string;
109
+ private runtimeNoStructuredOutputModels;
110
+ rememberModelRejectsStructuredOutput(model: string): void;
111
+ clearRuntimeNoStructuredOutputModels(): void;
112
+ private supportsStructuredOutput;
113
+ private runtimeNoTemperatureModels;
114
+ rememberModelRejectsTemperature(model: string): void;
115
+ clearRuntimeNoTemperatureModels(): void;
116
+ private supportsTemperature;
117
+ buildRequest(request: OperateRequest): FireworksRequest;
118
+ formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
119
+ formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
120
+ executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<FireworksResponse>;
121
+ /**
122
+ * Serialize the internal request into the OpenAI-compatible wire body for
123
+ * Fireworks' Chat Completions endpoint. Top-level fields (model, tools,
124
+ * tool_choice, response_format, reasoning_effort, user, temperature, and any
125
+ * providerOptions) are already wire-shaped (snake_case); only messages carry
126
+ * camelCase tool fields that must become snake_case on the wire.
127
+ */
128
+ private toWireBody;
129
+ /**
130
+ * Rebuild a structured-output request without `response_format`, swapping in
131
+ * the legacy fake-tool emulation. Used as a runtime fallback when a model
132
+ * rejects native json_schema.
133
+ */
134
+ private toFallbackStructuredOutputRequest;
135
+ executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
136
+ parseResponse(response: unknown, _options?: LlmOperateOptions): ParsedResponse;
137
+ extractToolCalls(response: unknown): StandardToolCall[];
138
+ extractUsage(response: unknown, model: string): LlmUsageItem;
139
+ formatToolResult(toolCall: StandardToolCall, result: StandardToolResult): FireworksMessage;
140
+ appendToolResult(request: unknown, toolCall: StandardToolCall, result: StandardToolResult): FireworksRequest;
141
+ responseToHistoryItems(response: unknown): LlmHistory;
142
+ classifyError(error: unknown): ClassifiedError;
143
+ isComplete(response: unknown): boolean;
144
+ hasStructuredOutput(response: unknown): boolean;
145
+ extractStructuredOutput(response: unknown): JsonObject | undefined;
146
+ private hasToolCalls;
147
+ private extractContent;
148
+ private convertMessagesToFireworks;
149
+ }
150
+ export declare const fireworksAdapter: FireworksAdapter;
151
+ export {};
@@ -2,6 +2,7 @@ export { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
2
2
  export type { ProviderAdapter } from "./ProviderAdapter.interface.js";
3
3
  export { AnthropicAdapter, anthropicAdapter } from "./AnthropicAdapter.js";
4
4
  export { BedrockAdapter, bedrockAdapter } from "./BedrockAdapter.js";
5
+ export { FireworksAdapter, fireworksAdapter } from "./FireworksAdapter.js";
5
6
  export { GoogleAdapter, googleAdapter } from "./GoogleAdapter.js";
6
7
  export { OpenAiAdapter, openAiAdapter } from "./OpenAiAdapter.js";
7
8
  export { OpenRouterAdapter, openRouterAdapter } from "./OpenRouterAdapter.js";
@@ -1,4 +1,4 @@
1
- export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, BedrockAdapter, bedrockAdapter, GoogleAdapter, googleAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
1
+ export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, BedrockAdapter, bedrockAdapter, FireworksAdapter, fireworksAdapter, GoogleAdapter, googleAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
2
2
  export type { ProviderAdapter } from "./adapters/index.js";
3
3
  export { createOperateLoop, OperateLoop } from "./OperateLoop.js";
4
4
  export type { OperateLoopConfig } from "./OperateLoop.js";
@@ -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
  /**
@@ -0,0 +1,21 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmOperateResponse, LlmProvider } from "../../types/LlmProvider.interface.js";
3
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
4
+ export declare class FireworksProvider implements LlmProvider {
5
+ private model;
6
+ private _client?;
7
+ private _operateLoop?;
8
+ private _streamLoop?;
9
+ private apiKey?;
10
+ private log;
11
+ private conversationHistory;
12
+ constructor(model?: string, { apiKey }?: {
13
+ apiKey?: string;
14
+ });
15
+ private getClient;
16
+ private getOperateLoop;
17
+ private getStreamLoop;
18
+ send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
19
+ operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
20
+ stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
21
+ }
@@ -0,0 +1,37 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ export interface FireworksClientOptions {
3
+ apiKey: string;
4
+ baseURL?: string;
5
+ }
6
+ export interface ChatCompletionOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ /**
10
+ * HTTP error carrying the upstream status and parsed API message. The
11
+ * FireworksAdapter classifies errors by reading `.status` / `.statusCode` and
12
+ * `.message` / `.error.message`.
13
+ */
14
+ export declare class FireworksHttpError extends Error {
15
+ readonly status: number;
16
+ readonly statusCode: number;
17
+ readonly error?: {
18
+ message?: string;
19
+ };
20
+ constructor(status: number, message: string, error?: {
21
+ message?: string;
22
+ });
23
+ }
24
+ /**
25
+ * Minimal `fetch`-based client for Fireworks AI's OpenAI-compatible Chat
26
+ * Completions endpoint. The adapter only needs a single POST (streaming and
27
+ * non-streaming), header auth, and HTTP error surfacing.
28
+ */
29
+ export declare class FireworksClient {
30
+ private readonly apiKey;
31
+ private readonly baseURL;
32
+ constructor({ apiKey, baseURL, }: FireworksClientOptions);
33
+ private headers;
34
+ private toError;
35
+ chatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): Promise<JsonObject>;
36
+ streamChatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): AsyncIterable<JsonObject>;
37
+ }
@@ -0,0 +1,2 @@
1
+ export { FireworksProvider } from "./FireworksProvider.class.js";
2
+ export * from "./utils.js";
@@ -0,0 +1,15 @@
1
+ import { createLogger } from "@jaypie/logger";
2
+ import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
3
+ import { FireworksClient } from "./client.js";
4
+ export declare const getLogger: () => ReturnType<typeof createLogger>;
5
+ export declare function initializeClient({ apiKey, }?: {
6
+ apiKey?: string;
7
+ }): Promise<FireworksClient>;
8
+ export declare function getDefaultModel(): string;
9
+ export interface ChatMessage {
10
+ role: "system" | "user" | "assistant";
11
+ content: string;
12
+ }
13
+ export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
14
+ export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
15
+ export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];
@@ -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;
@@ -39,4 +39,5 @@ export declare function toXaiEffort(effort: LlmEffort): LlmEffortMapping;
39
39
  export declare function toAnthropicEffort(effort: LlmEffort): LlmEffortMapping;
40
40
  export declare function toGeminiThinkingLevel(effort: LlmEffort): LlmEffortMapping;
41
41
  export declare function toGeminiThinkingBudget(effort: LlmEffort): LlmEffortMapping<number>;
42
+ export declare function toFireworksEffort(effort: LlmEffort): LlmEffortMapping;
42
43
  export declare function toOpenRouterEffort(effort: LlmEffort): LlmEffortMapping;
@@ -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
+ };