@jaypie/llm 1.2.5 → 1.2.6

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.
@@ -144,6 +144,18 @@ interface LlmItemReference {
144
144
  }
145
145
  export type LlmHistoryItem = LlmInputMessage | LlmItemReference | LlmOutputItem | LlmToolResult;
146
146
  export type LlmHistory = LlmHistoryItem[];
147
+ /**
148
+ * Configuration for a fallback provider.
149
+ * Used when the primary provider fails with an unrecoverable error.
150
+ */
151
+ export interface LlmFallbackConfig {
152
+ /** Provider name (e.g., "openai", "anthropic", "gemini") */
153
+ provider: string;
154
+ /** Model to use with this provider (optional, uses provider default if not specified) */
155
+ model?: string;
156
+ /** API key for this provider (optional, uses environment variable if not specified) */
157
+ apiKey?: string;
158
+ }
147
159
  export interface LlmMessageOptions {
148
160
  data?: NaturalMap;
149
161
  model?: string;
@@ -157,6 +169,8 @@ export interface LlmMessageOptions {
157
169
  export interface LlmOperateOptions {
158
170
  data?: NaturalMap;
159
171
  explain?: boolean;
172
+ /** Chain of fallback providers to try if primary fails. Set to false to disable instance-level fallback. */
173
+ fallback?: LlmFallbackConfig[] | false;
160
174
  format?: JsonObject | NaturalSchema | z.ZodType;
161
175
  history?: LlmHistory;
162
176
  hooks?: {
@@ -215,6 +229,8 @@ export interface LlmOperateOptions {
215
229
  }
216
230
  export interface LlmOptions {
217
231
  apiKey?: string;
232
+ /** Chain of fallback providers to try if primary fails */
233
+ fallback?: LlmFallbackConfig[];
218
234
  model?: string;
219
235
  }
220
236
  export interface LlmUsageItem {
@@ -229,9 +245,14 @@ export type LlmUsage = LlmUsageItem[];
229
245
  export interface LlmOperateResponse {
230
246
  content?: string | JsonObject;
231
247
  error?: LlmError;
248
+ /** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
249
+ fallbackAttempts?: number;
250
+ /** Whether a fallback provider was used instead of the primary */
251
+ fallbackUsed?: boolean;
232
252
  history: LlmHistory;
233
253
  model?: string;
234
254
  output: LlmOutput;
255
+ /** Which provider actually handled the request */
235
256
  provider?: string;
236
257
  reasoning: string[];
237
258
  responses: JsonReturn[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Large language model utilities",
5
5
  "repository": {
6
6
  "type": "git",