modelmix 4.6.10 → 4.6.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 (2) hide show
  1. package/index.d.ts +467 -0
  2. package/package.json +2 -1
package/index.d.ts ADDED
@@ -0,0 +1,467 @@
1
+ /**
2
+ * Type definitions for modelmix
3
+ * @see https://github.com/clasen/ModelMix
4
+ */
5
+
6
+ export type MessageRole = 'user' | 'assistant' | 'system' | 'tool' | string;
7
+
8
+ export type DebugLevel = 0 | 1 | 2 | 3 | 4;
9
+
10
+ /** Unified effort: -1 = adaptive, 0–100 = intensity. */
11
+ export type EffortValue = number;
12
+
13
+ export interface BottleneckConfig {
14
+ maxConcurrent?: number;
15
+ minTime?: number;
16
+ reservoir?: number;
17
+ reservoirRefreshAmount?: number;
18
+ reservoirRefreshInterval?: number;
19
+ [key: string]: unknown;
20
+ }
21
+
22
+ export interface RetryConfig {
23
+ enabled?: boolean;
24
+ retries?: number;
25
+ baseDelayMs?: number;
26
+ maxDelayMs?: number;
27
+ retryableStatusCodes?: number[];
28
+ }
29
+
30
+ export interface ModelMixOptions {
31
+ max_tokens?: number;
32
+ temperature?: number;
33
+ top_p?: number;
34
+ stream?: boolean;
35
+ model?: string;
36
+ messages?: ChatMessage[];
37
+ response_format?: { type: string; [key: string]: unknown };
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ export interface ModelMixConfig {
42
+ system?: string;
43
+ /** 0 = stateless, N = last N messages, -1 = unlimited */
44
+ max_history?: number;
45
+ /** 0=silent, 1=minimal, 2=summary, 3=full, 4=verbose */
46
+ debug?: DebugLevel | number;
47
+ bottleneck?: BottleneckConfig;
48
+ retry?: RetryConfig;
49
+ roundRobin?: boolean;
50
+ /** Unified effort (-1 adaptive, or 0–100). Not a native provider field. */
51
+ effort?: EffortValue | null;
52
+ replace?: Record<string, string>;
53
+ schema?: Record<string, unknown>;
54
+ [key: string]: unknown;
55
+ }
56
+
57
+ export interface ModelMixMixFlags {
58
+ openrouter?: boolean;
59
+ cerebras?: boolean;
60
+ groq?: boolean;
61
+ together?: boolean;
62
+ lambda?: boolean;
63
+ fireworks?: boolean;
64
+ nvidia?: boolean;
65
+ moonshot?: boolean;
66
+ minimax?: boolean;
67
+ mimo?: boolean;
68
+ [key: string]: boolean | undefined;
69
+ }
70
+
71
+ export interface ModelMixSetup {
72
+ options?: ModelMixOptions;
73
+ config?: ModelMixConfig;
74
+ mix?: ModelMixMixFlags;
75
+ }
76
+
77
+ export interface ModelAttachArgs {
78
+ options?: ModelMixOptions;
79
+ config?: ModelMixConfig;
80
+ mix?: ModelMixMixFlags;
81
+ }
82
+
83
+ export interface RoleOptions {
84
+ role?: MessageRole;
85
+ }
86
+
87
+ export interface TextContentPart {
88
+ type: 'text';
89
+ text: string;
90
+ }
91
+
92
+ export interface ImageContentPart {
93
+ type: 'image';
94
+ source: {
95
+ type: 'base64' | 'url' | 'file' | 'buffer' | string;
96
+ media_type?: string;
97
+ data: string | Buffer;
98
+ };
99
+ }
100
+
101
+ export type ContentPart = TextContentPart | ImageContentPart | Record<string, unknown>;
102
+
103
+ export interface ChatMessage {
104
+ role: MessageRole;
105
+ content?: string | ContentPart[] | null;
106
+ tool_calls?: ToolCall[];
107
+ tool_call_id?: string;
108
+ name?: string;
109
+ [key: string]: unknown;
110
+ }
111
+
112
+ export interface ToolCall {
113
+ id?: string;
114
+ type?: string;
115
+ name?: string;
116
+ input?: unknown;
117
+ arguments?: unknown;
118
+ function?: {
119
+ name: string;
120
+ arguments: string | Record<string, unknown>;
121
+ };
122
+ }
123
+
124
+ export interface TokenUsage {
125
+ input: number;
126
+ output: number;
127
+ total: number;
128
+ cached: number;
129
+ cost?: number | null;
130
+ speed?: number;
131
+ }
132
+
133
+ export interface ModelMixResult {
134
+ message?: string;
135
+ think?: string | null;
136
+ signature?: string;
137
+ toolCalls?: ToolCall[];
138
+ tokens?: TokenUsage;
139
+ response?: unknown;
140
+ assistantMessage?: ChatMessage;
141
+ [key: string]: unknown;
142
+ }
143
+
144
+ export interface StreamChunk {
145
+ response: unknown;
146
+ message: string;
147
+ delta: string;
148
+ }
149
+
150
+ export type StreamCallback = (chunk: StreamChunk) => void;
151
+
152
+ export interface SchemaFieldDescriptor {
153
+ description?: string;
154
+ required?: boolean;
155
+ enum?: unknown[];
156
+ default?: unknown;
157
+ nullable?: boolean;
158
+ [key: string]: unknown;
159
+ }
160
+
161
+ export type SchemaDescription =
162
+ | string
163
+ | SchemaFieldDescriptor
164
+ | SchemaDescription[]
165
+ | { [key: string]: SchemaDescription };
166
+
167
+ export interface JsonMethodOptions {
168
+ type?: string;
169
+ addExample?: boolean;
170
+ addSchema?: boolean;
171
+ addNote?: boolean;
172
+ }
173
+
174
+ export interface BlockOptions {
175
+ addSystemExtra?: boolean;
176
+ }
177
+
178
+ export interface ToolDefinition {
179
+ name: string;
180
+ description?: string;
181
+ inputSchema?: Record<string, unknown>;
182
+ [key: string]: unknown;
183
+ }
184
+
185
+ export type ToolCallback = (
186
+ args: Record<string, unknown>
187
+ ) => unknown | Promise<unknown>;
188
+
189
+ export interface ToolWithCallback {
190
+ tool: ToolDefinition;
191
+ callback: ToolCallback;
192
+ }
193
+
194
+ export interface ListedTools {
195
+ local: ToolDefinition[];
196
+ mcp: ToolDefinition[];
197
+ }
198
+
199
+ export interface AttachedModel {
200
+ key: string;
201
+ provider: MixCustom;
202
+ }
203
+
204
+ export interface ProviderConstructorArgs {
205
+ config?: ModelMixConfig & {
206
+ url?: string;
207
+ apiKey?: string;
208
+ [key: string]: unknown;
209
+ };
210
+ options?: ModelMixOptions;
211
+ headers?: Record<string, string>;
212
+ }
213
+
214
+ export interface CreateArgs {
215
+ config?: ModelMixConfig;
216
+ options?: ModelMixOptions;
217
+ }
218
+
219
+ export type ProviderFamily =
220
+ | 'openai'
221
+ | 'anthropic'
222
+ | 'google'
223
+ | 'deepseek'
224
+ | 'minimax'
225
+ | string;
226
+
227
+ export declare class ModelMix {
228
+ models: AttachedModel[];
229
+ messages: ChatMessage[];
230
+ tools: Record<string, ToolDefinition[]>;
231
+ toolClient: Record<string, unknown>;
232
+ mcp: Record<string, unknown>;
233
+ options: ModelMixOptions;
234
+ config: ModelMixConfig;
235
+ mix: ModelMixMixFlags;
236
+ lastRaw: ModelMixResult | null;
237
+ streamCallback: StreamCallback | null;
238
+
239
+ constructor(setup?: ModelMixSetup);
240
+
241
+ static new(setup?: ModelMixSetup): ModelMix;
242
+ static formatJSON(obj: unknown): string;
243
+ static formatMessage(message: unknown): unknown;
244
+ static truncate(str: string, maxLen?: number): string;
245
+ static calculateCost(
246
+ modelKey: string,
247
+ tokens: { input: number; output: number }
248
+ ): number | null;
249
+ static extractCacheTokens(usage?: Record<string, unknown>): number;
250
+ static formatInputSummary(
251
+ messages: ChatMessage[],
252
+ system: string,
253
+ debug?: number
254
+ ): string;
255
+ static formatOutputSummary(result: ModelMixResult, debug: number): string;
256
+ static hasToolInteraction(message: ChatMessage | null | undefined): boolean;
257
+
258
+ new(setup?: ModelMixSetup): ModelMix;
259
+ replace(keyValues: Record<string, string>): this;
260
+ effort(value: EffortValue): this;
261
+ attach(key: string, provider: MixCustom): this;
262
+
263
+ // OpenAI
264
+ gpt41(args?: ModelAttachArgs): this;
265
+ gpt41mini(args?: ModelAttachArgs): this;
266
+ gpt41nano(args?: ModelAttachArgs): this;
267
+ gpt5(args?: ModelAttachArgs): this;
268
+ gpt5mini(args?: ModelAttachArgs): this;
269
+ gpt5nano(args?: ModelAttachArgs): this;
270
+ gpt51(args?: ModelAttachArgs): this;
271
+ gpt52(args?: ModelAttachArgs): this;
272
+ gpt54(args?: ModelAttachArgs): this;
273
+ gpt54mini(args?: ModelAttachArgs): this;
274
+ gpt54nano(args?: ModelAttachArgs): this;
275
+ gpt54pro(args?: ModelAttachArgs): this;
276
+ gpt55(args?: ModelAttachArgs): this;
277
+ gpt55pro(args?: ModelAttachArgs): this;
278
+ gpt56sol(args?: ModelAttachArgs): this;
279
+ gpt56terra(args?: ModelAttachArgs): this;
280
+ gpt56luna(args?: ModelAttachArgs): this;
281
+ gptRealtime(args?: ModelAttachArgs): this;
282
+ gptRealtimeMini(args?: ModelAttachArgs): this;
283
+ gpt53codex(args?: ModelAttachArgs): this;
284
+ gpt53chat(args?: ModelAttachArgs): this;
285
+ gptOss(args?: ModelAttachArgs): this;
286
+
287
+ // Anthropic
288
+ fable5(args?: ModelAttachArgs): this;
289
+ fable5think(args?: ModelAttachArgs): this;
290
+ opus5(args?: ModelAttachArgs): this;
291
+ opus5think(args?: ModelAttachArgs): this;
292
+ opus48think(args?: ModelAttachArgs): this;
293
+ opus47think(args?: ModelAttachArgs): this;
294
+ opus46think(args?: ModelAttachArgs): this;
295
+ opus48(args?: ModelAttachArgs): this;
296
+ opus47(args?: ModelAttachArgs): this;
297
+ opus46(args?: ModelAttachArgs): this;
298
+ opus41(args?: ModelAttachArgs): this;
299
+ opus41think(args?: ModelAttachArgs): this;
300
+ sonnet5(args?: ModelAttachArgs): this;
301
+ sonnet5think(args?: ModelAttachArgs): this;
302
+ sonnet4(args?: ModelAttachArgs): this;
303
+ sonnet4think(args?: ModelAttachArgs): this;
304
+ sonnet46(args?: ModelAttachArgs): this;
305
+ sonnet46think(args?: ModelAttachArgs): this;
306
+ sonnet45(args?: ModelAttachArgs): this;
307
+ sonnet45think(args?: ModelAttachArgs): this;
308
+ haiku35(args?: ModelAttachArgs): this;
309
+ haiku45(args?: ModelAttachArgs): this;
310
+ haiku45think(args?: ModelAttachArgs): this;
311
+
312
+ // Google
313
+ gemini25flash(args?: ModelAttachArgs): this;
314
+ gemini31pro(args?: ModelAttachArgs): this;
315
+ gemini3pro(args?: ModelAttachArgs): this;
316
+ gemini3flash(args?: ModelAttachArgs): this;
317
+ gemini36flash(args?: ModelAttachArgs): this;
318
+ gemini35flash(args?: ModelAttachArgs): this;
319
+ gemini31flashLite(args?: ModelAttachArgs): this;
320
+ gemini25pro(args?: ModelAttachArgs): this;
321
+
322
+ // Perplexity
323
+ sonarPro(args?: ModelAttachArgs): this;
324
+ sonar(args?: ModelAttachArgs): this;
325
+
326
+ // Grok
327
+ grok43(args?: ModelAttachArgs): this;
328
+ grok420multiAgent(args?: ModelAttachArgs): this;
329
+ grok420think(args?: ModelAttachArgs): this;
330
+ grok420(args?: ModelAttachArgs): this;
331
+ grok41think(args?: ModelAttachArgs): this;
332
+ grok41(args?: ModelAttachArgs): this;
333
+
334
+ // Multi-provider
335
+ qwen3(args?: ModelAttachArgs): this;
336
+ qwen36plus(args?: ModelAttachArgs): this;
337
+ hermes3(args?: ModelAttachArgs): this;
338
+ kimiK26think(args?: ModelAttachArgs): this;
339
+ kimiK27Code(args?: ModelAttachArgs): this;
340
+ kimiK3(args?: ModelAttachArgs): this;
341
+ kimiK25think(args?: ModelAttachArgs): this;
342
+ lmstudio(model?: string, args?: ModelAttachArgs): this;
343
+ minimaxM25(args?: ModelAttachArgs): this;
344
+ minimaxM27(args?: ModelAttachArgs): this;
345
+ minimaxM3(args?: ModelAttachArgs): this;
346
+ mimo25(args?: ModelAttachArgs): this;
347
+ mimo25pro(args?: ModelAttachArgs): this;
348
+ deepseekV4Pro(args?: ModelAttachArgs): this;
349
+ deepseekV4Flash(args?: ModelAttachArgs): this;
350
+ GLM51(args?: ModelAttachArgs): this;
351
+ GLM52(args?: ModelAttachArgs): this;
352
+ GLM5(args?: ModelAttachArgs): this;
353
+
354
+ addText(text: string, options?: RoleOptions): this;
355
+ addTextFromFile(filePath: string, options?: RoleOptions): this;
356
+ setSystem(text: string): this;
357
+ setSystemFromFile(filePath: string): this;
358
+ addImageFromBuffer(buffer: Buffer, options?: RoleOptions): this;
359
+ addImage(filePath: string, options?: RoleOptions): this;
360
+ addImageFromUrl(url: string, options?: RoleOptions): Promise<this>;
361
+ processImages(): Promise<void>;
362
+
363
+ message(): Promise<string>;
364
+ json<T = unknown>(
365
+ schemaExample?: T | T[] | null,
366
+ schemaDescription?: SchemaDescription,
367
+ options?: JsonMethodOptions
368
+ ): Promise<T>;
369
+ block(options?: BlockOptions): Promise<string>;
370
+ raw(): Promise<ModelMixResult>;
371
+ stream(callback: StreamCallback): Promise<ModelMixResult>;
372
+
373
+ replaceKeyFromFile(key: string, filePath: string): this;
374
+ groupByRoles(messages: ChatMessage[]): ChatMessage[];
375
+ applyTemplate(): void;
376
+ prepareMessages(): Promise<void>;
377
+ readFile(filePath: string, options?: { encoding?: BufferEncoding | null }): string | Buffer;
378
+ execute(args?: CreateArgs): Promise<ModelMixResult>;
379
+ processToolCalls(toolCalls: ToolCall[]): Promise<
380
+ Array<{ name: string; tool_call_id: string; content: string }>
381
+ >;
382
+
383
+ addMCP(...npxArgs: string[]): Promise<void>;
384
+ addTool(toolDefinition: ToolDefinition, callback: ToolCallback): this;
385
+ addTools(toolsWithCallbacks: ToolWithCallback[]): this;
386
+ removeTool(toolName: string): this;
387
+ listTools(): ListedTools;
388
+ }
389
+
390
+ export declare class MixCustom {
391
+ config: ModelMixConfig & { url?: string; apiKey?: string };
392
+ options: ModelMixOptions;
393
+ headers: Record<string, string>;
394
+ streamCallback: StreamCallback | null;
395
+
396
+ constructor(args?: ProviderConstructorArgs);
397
+
398
+ getDefaultOptions(customOptions?: ModelMixOptions): ModelMixOptions;
399
+ getDefaultConfig(customConfig?: Record<string, unknown>): Record<string, unknown>;
400
+ getDefaultHeaders(customHeaders?: Record<string, string>): Record<string, string>;
401
+ convertMessages(messages: ChatMessage[], config?: ModelMixConfig): ChatMessage[];
402
+
403
+ static stripContentTypeHeader(headers?: Record<string, string>): Record<string, string>;
404
+ static createMultipartFormData(args?: {
405
+ fields?: Record<string, unknown>;
406
+ files?: unknown[];
407
+ }): { body: Buffer; headers: Record<string, string> };
408
+ static buildRequestBodyAndHeaders(
409
+ options: ModelMixOptions,
410
+ headers: Record<string, string>
411
+ ): { body: unknown; headers: Record<string, string>; options: ModelMixOptions };
412
+ static extractMessage(data: unknown): string;
413
+ static extractThink(data: unknown): string | null;
414
+ static extractToolCalls(data: unknown): ToolCall[];
415
+ static extractTokens(data: unknown): TokenUsage;
416
+
417
+ create(args?: CreateArgs): Promise<ModelMixResult>;
418
+ handleError(
419
+ error: unknown,
420
+ context: CreateArgs
421
+ ): {
422
+ message: string;
423
+ statusCode: number | null;
424
+ details: unknown;
425
+ stack?: string;
426
+ config?: ModelMixConfig;
427
+ options?: ModelMixOptions;
428
+ };
429
+ processStream(response: { data: NodeJS.ReadableStream }): Promise<ModelMixResult>;
430
+ extractDelta(data: unknown): string;
431
+ processResponse(response: { data: unknown }): ModelMixResult;
432
+ getOptionsTools(tools: Record<string, ToolDefinition[]>): Partial<ModelMixOptions>;
433
+ }
434
+
435
+ export declare class MixOpenAI extends MixCustom {}
436
+ export declare class MixOpenAIResponses extends MixOpenAI {}
437
+ export declare class MixOpenAIWebSocket extends MixOpenAIResponses {}
438
+ export declare class MixOpenRouter extends MixOpenAI {}
439
+ export declare class MixKimi extends MixOpenAI {}
440
+ export declare class MixAnthropic extends MixCustom {}
441
+ export declare class MixMiniMax extends MixOpenAI {}
442
+ export declare class MixMiMo extends MixOpenAI {}
443
+ export declare class MixPerplexity extends MixCustom {}
444
+ export declare class MixOllama extends MixCustom {}
445
+ export declare class MixGrok extends MixOpenAI {}
446
+ export declare class MixLambda extends MixCustom {}
447
+ export declare class MixLMStudio extends MixCustom {}
448
+ export declare class MixGroq extends MixCustom {}
449
+ export declare class MixTogether extends MixCustom {}
450
+ export declare class MixCerebras extends MixCustom {}
451
+ export declare class MixFireworks extends MixCustom {}
452
+ export declare class MixNVIDIA extends MixCustom {}
453
+ export declare class MixGoogle extends MixCustom {}
454
+
455
+ /** Normalize unified effort to integer -1 or 0..100. */
456
+ export function normalizeEffort(value: unknown): EffortValue;
457
+
458
+ /** Map unified effort onto provider-native option fields (no-op if native already set). */
459
+ export function applyUnifiedEffort(
460
+ options: ModelMixOptions,
461
+ config: ModelMixConfig,
462
+ providerFamily: ProviderFamily,
463
+ modelKey?: string
464
+ ): ModelMixOptions;
465
+
466
+ /** Resolve provider family from a Mix* instance. */
467
+ export function resolveProviderFamily(providerInstance: MixCustom): ProviderFamily;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "modelmix",
3
- "version": "4.6.10",
3
+ "version": "4.6.12",
4
4
  "description": "🧬 Reliable interface with automatic fallback for AI LLMs.",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/clasen/ModelMix.git"