@probeo/anymodel 0.3.0 → 0.4.0
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/README.md +5 -8
- package/dist/cli.cjs +1016 -110
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +2972 -30
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1037 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -22
- package/dist/index.d.ts +632 -14
- package/dist/index.js +2969 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/batch/index.d.ts +0 -4
- package/dist/batch/index.d.ts.map +0 -1
- package/dist/batch/index.js +0 -3
- package/dist/batch/index.js.map +0 -1
- package/dist/batch/manager.d.ts +0 -72
- package/dist/batch/manager.d.ts.map +0 -1
- package/dist/batch/manager.js +0 -328
- package/dist/batch/manager.js.map +0 -1
- package/dist/batch/store.d.ts +0 -54
- package/dist/batch/store.d.ts.map +0 -1
- package/dist/batch/store.js +0 -109
- package/dist/batch/store.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client.d.ts +0 -42
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -181
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -6
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -120
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/providers/adapter.d.ts +0 -33
- package/dist/providers/adapter.d.ts.map +0 -1
- package/dist/providers/adapter.js +0 -2
- package/dist/providers/adapter.js.map +0 -1
- package/dist/providers/anthropic-batch.d.ts +0 -3
- package/dist/providers/anthropic-batch.d.ts.map +0 -1
- package/dist/providers/anthropic-batch.js +0 -228
- package/dist/providers/anthropic-batch.js.map +0 -1
- package/dist/providers/anthropic.d.ts +0 -3
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -358
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/custom.d.ts +0 -8
- package/dist/providers/custom.d.ts.map +0 -1
- package/dist/providers/custom.js +0 -61
- package/dist/providers/custom.js.map +0 -1
- package/dist/providers/google.d.ts +0 -3
- package/dist/providers/google.d.ts.map +0 -1
- package/dist/providers/google.js +0 -331
- package/dist/providers/google.js.map +0 -1
- package/dist/providers/index.d.ts +0 -6
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -5
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/openai-batch.d.ts +0 -3
- package/dist/providers/openai-batch.d.ts.map +0 -1
- package/dist/providers/openai-batch.js +0 -208
- package/dist/providers/openai-batch.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -3
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -221
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/registry.d.ts +0 -10
- package/dist/providers/registry.d.ts.map +0 -1
- package/dist/providers/registry.js +0 -27
- package/dist/providers/registry.js.map +0 -1
- package/dist/router.d.ts +0 -29
- package/dist/router.d.ts.map +0 -1
- package/dist/router.js +0 -212
- package/dist/router.js.map +0 -1
- package/dist/server.d.ts +0 -10
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -149
- package/dist/server.js.map +0 -1
- package/dist/types.d.ts +0 -283
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -21
- package/dist/types.js.map +0 -1
- package/dist/utils/fs-io.d.ts +0 -40
- package/dist/utils/fs-io.d.ts.map +0 -1
- package/dist/utils/fs-io.js +0 -203
- package/dist/utils/fs-io.js.map +0 -1
- package/dist/utils/generation-stats.d.ts +0 -25
- package/dist/utils/generation-stats.d.ts.map +0 -1
- package/dist/utils/generation-stats.js +0 -46
- package/dist/utils/generation-stats.js.map +0 -1
- package/dist/utils/id.d.ts +0 -2
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -6
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/model-parser.d.ts +0 -6
- package/dist/utils/model-parser.d.ts.map +0 -1
- package/dist/utils/model-parser.js +0 -21
- package/dist/utils/model-parser.js.map +0 -1
- package/dist/utils/rate-limiter.d.ts +0 -36
- package/dist/utils/rate-limiter.d.ts.map +0 -1
- package/dist/utils/rate-limiter.js +0 -80
- package/dist/utils/rate-limiter.js.map +0 -1
- package/dist/utils/retry.d.ts +0 -7
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js +0 -54
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/transforms.d.ts +0 -7
- package/dist/utils/transforms.d.ts.map +0 -1
- package/dist/utils/transforms.js +0 -66
- package/dist/utils/transforms.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -3
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js +0 -31
- package/dist/utils/validate.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,632 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
|
|
3
|
+
type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
4
|
+
interface Message {
|
|
5
|
+
role: Role;
|
|
6
|
+
content: string | ContentPart[];
|
|
7
|
+
name?: string;
|
|
8
|
+
tool_calls?: ToolCall[];
|
|
9
|
+
tool_call_id?: string;
|
|
10
|
+
}
|
|
11
|
+
interface ContentPart {
|
|
12
|
+
type: 'text' | 'image_url';
|
|
13
|
+
text?: string;
|
|
14
|
+
image_url?: {
|
|
15
|
+
url: string;
|
|
16
|
+
detail?: 'auto' | 'low' | 'high';
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface Tool {
|
|
20
|
+
type: 'function';
|
|
21
|
+
function: {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
parameters?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type ToolChoice = 'none' | 'auto' | 'required' | {
|
|
28
|
+
type: 'function';
|
|
29
|
+
function: {
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
interface ToolCall {
|
|
34
|
+
id: string;
|
|
35
|
+
type: 'function';
|
|
36
|
+
function: {
|
|
37
|
+
name: string;
|
|
38
|
+
arguments: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
type ResponseFormat = {
|
|
42
|
+
type: 'text';
|
|
43
|
+
} | {
|
|
44
|
+
type: 'json_object';
|
|
45
|
+
} | {
|
|
46
|
+
type: 'json_schema';
|
|
47
|
+
json_schema: {
|
|
48
|
+
name: string;
|
|
49
|
+
schema: Record<string, unknown>;
|
|
50
|
+
strict?: boolean;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
interface ProviderPreferences {
|
|
54
|
+
order?: string[];
|
|
55
|
+
only?: string[];
|
|
56
|
+
ignore?: string[];
|
|
57
|
+
allow_fallbacks?: boolean;
|
|
58
|
+
require_parameters?: boolean;
|
|
59
|
+
sort?: 'price' | 'throughput' | 'latency';
|
|
60
|
+
}
|
|
61
|
+
interface ChatCompletionRequest {
|
|
62
|
+
model: string;
|
|
63
|
+
messages: Message[];
|
|
64
|
+
max_tokens?: number;
|
|
65
|
+
temperature?: number;
|
|
66
|
+
top_p?: number;
|
|
67
|
+
top_k?: number;
|
|
68
|
+
frequency_penalty?: number;
|
|
69
|
+
presence_penalty?: number;
|
|
70
|
+
repetition_penalty?: number;
|
|
71
|
+
seed?: number;
|
|
72
|
+
stop?: string | string[];
|
|
73
|
+
stream?: boolean;
|
|
74
|
+
logprobs?: boolean;
|
|
75
|
+
top_logprobs?: number;
|
|
76
|
+
response_format?: ResponseFormat;
|
|
77
|
+
tools?: Tool[];
|
|
78
|
+
tool_choice?: ToolChoice;
|
|
79
|
+
user?: string;
|
|
80
|
+
models?: string[];
|
|
81
|
+
route?: 'fallback';
|
|
82
|
+
transforms?: string[];
|
|
83
|
+
provider?: ProviderPreferences;
|
|
84
|
+
}
|
|
85
|
+
type FinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error';
|
|
86
|
+
interface Usage {
|
|
87
|
+
prompt_tokens: number;
|
|
88
|
+
completion_tokens: number;
|
|
89
|
+
total_tokens: number;
|
|
90
|
+
}
|
|
91
|
+
interface ChatCompletionChoice {
|
|
92
|
+
index: number;
|
|
93
|
+
message: Message;
|
|
94
|
+
finish_reason: FinishReason;
|
|
95
|
+
logprobs?: unknown;
|
|
96
|
+
}
|
|
97
|
+
interface ChatCompletion {
|
|
98
|
+
id: string;
|
|
99
|
+
object: 'chat.completion';
|
|
100
|
+
created: number;
|
|
101
|
+
model: string;
|
|
102
|
+
choices: ChatCompletionChoice[];
|
|
103
|
+
usage: Usage;
|
|
104
|
+
}
|
|
105
|
+
interface ChunkDelta {
|
|
106
|
+
role?: Role;
|
|
107
|
+
content?: string;
|
|
108
|
+
tool_calls?: Partial<ToolCall>[];
|
|
109
|
+
}
|
|
110
|
+
interface ChunkChoice {
|
|
111
|
+
index: number;
|
|
112
|
+
delta: ChunkDelta;
|
|
113
|
+
finish_reason: FinishReason | null;
|
|
114
|
+
logprobs?: unknown;
|
|
115
|
+
}
|
|
116
|
+
interface ChatCompletionChunk {
|
|
117
|
+
id: string;
|
|
118
|
+
object: 'chat.completion.chunk';
|
|
119
|
+
created: number;
|
|
120
|
+
model: string;
|
|
121
|
+
choices: ChunkChoice[];
|
|
122
|
+
usage?: Usage;
|
|
123
|
+
}
|
|
124
|
+
interface ModelPricing {
|
|
125
|
+
prompt: string;
|
|
126
|
+
completion: string;
|
|
127
|
+
}
|
|
128
|
+
interface ModelArchitecture {
|
|
129
|
+
modality: string;
|
|
130
|
+
input_modalities: string[];
|
|
131
|
+
output_modalities: string[];
|
|
132
|
+
tokenizer: string;
|
|
133
|
+
}
|
|
134
|
+
interface ModelTopProvider {
|
|
135
|
+
context_length: number;
|
|
136
|
+
max_completion_tokens: number;
|
|
137
|
+
is_moderated: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface ModelInfo {
|
|
140
|
+
id: string;
|
|
141
|
+
name: string;
|
|
142
|
+
created: number;
|
|
143
|
+
description: string;
|
|
144
|
+
context_length: number;
|
|
145
|
+
pricing: ModelPricing;
|
|
146
|
+
architecture: ModelArchitecture;
|
|
147
|
+
top_provider: ModelTopProvider;
|
|
148
|
+
supported_parameters: string[];
|
|
149
|
+
}
|
|
150
|
+
interface GenerationStats {
|
|
151
|
+
id: string;
|
|
152
|
+
model: string;
|
|
153
|
+
provider_name: string;
|
|
154
|
+
total_cost: number;
|
|
155
|
+
tokens_prompt: number;
|
|
156
|
+
tokens_completion: number;
|
|
157
|
+
latency: number;
|
|
158
|
+
generation_time: number;
|
|
159
|
+
created_at: string;
|
|
160
|
+
finish_reason: FinishReason;
|
|
161
|
+
streamed: boolean;
|
|
162
|
+
}
|
|
163
|
+
interface AnyModelErrorMetadata {
|
|
164
|
+
provider_name?: string;
|
|
165
|
+
raw?: unknown;
|
|
166
|
+
}
|
|
167
|
+
declare class AnyModelError extends Error {
|
|
168
|
+
readonly code: number;
|
|
169
|
+
readonly metadata: AnyModelErrorMetadata;
|
|
170
|
+
constructor(code: number, message: string, metadata?: AnyModelErrorMetadata);
|
|
171
|
+
toJSON(): {
|
|
172
|
+
error: {
|
|
173
|
+
code: number;
|
|
174
|
+
message: string;
|
|
175
|
+
metadata: AnyModelErrorMetadata;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
type BatchStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
180
|
+
type BatchMode = 'native' | 'concurrent';
|
|
181
|
+
interface BatchRequestItem {
|
|
182
|
+
custom_id: string;
|
|
183
|
+
messages: Message[];
|
|
184
|
+
max_tokens?: number;
|
|
185
|
+
temperature?: number;
|
|
186
|
+
top_p?: number;
|
|
187
|
+
top_k?: number;
|
|
188
|
+
stop?: string | string[];
|
|
189
|
+
response_format?: ResponseFormat;
|
|
190
|
+
tools?: Tool[];
|
|
191
|
+
tool_choice?: ToolChoice;
|
|
192
|
+
}
|
|
193
|
+
interface BatchCreateRequest {
|
|
194
|
+
model: string;
|
|
195
|
+
requests: BatchRequestItem[];
|
|
196
|
+
options?: {
|
|
197
|
+
temperature?: number;
|
|
198
|
+
max_tokens?: number;
|
|
199
|
+
top_p?: number;
|
|
200
|
+
top_k?: number;
|
|
201
|
+
stop?: string | string[];
|
|
202
|
+
response_format?: ResponseFormat;
|
|
203
|
+
tools?: Tool[];
|
|
204
|
+
tool_choice?: ToolChoice;
|
|
205
|
+
};
|
|
206
|
+
webhook?: string;
|
|
207
|
+
}
|
|
208
|
+
interface BatchObject {
|
|
209
|
+
id: string;
|
|
210
|
+
object: 'batch';
|
|
211
|
+
status: BatchStatus;
|
|
212
|
+
model: string;
|
|
213
|
+
provider_name: string;
|
|
214
|
+
batch_mode: BatchMode;
|
|
215
|
+
total: number;
|
|
216
|
+
completed: number;
|
|
217
|
+
failed: number;
|
|
218
|
+
created_at: string;
|
|
219
|
+
completed_at: string | null;
|
|
220
|
+
expires_at: string | null;
|
|
221
|
+
}
|
|
222
|
+
interface BatchResultItem {
|
|
223
|
+
custom_id: string;
|
|
224
|
+
status: 'success' | 'error';
|
|
225
|
+
response: ChatCompletion | null;
|
|
226
|
+
error: {
|
|
227
|
+
code: number;
|
|
228
|
+
message: string;
|
|
229
|
+
} | null;
|
|
230
|
+
}
|
|
231
|
+
interface BatchUsageSummary {
|
|
232
|
+
total_prompt_tokens: number;
|
|
233
|
+
total_completion_tokens: number;
|
|
234
|
+
estimated_cost: number;
|
|
235
|
+
}
|
|
236
|
+
interface BatchResults {
|
|
237
|
+
id: string;
|
|
238
|
+
status: BatchStatus;
|
|
239
|
+
results: BatchResultItem[];
|
|
240
|
+
usage_summary: BatchUsageSummary;
|
|
241
|
+
}
|
|
242
|
+
interface ProviderConfig {
|
|
243
|
+
apiKey?: string;
|
|
244
|
+
defaultModel?: string;
|
|
245
|
+
}
|
|
246
|
+
interface CustomProviderConfig {
|
|
247
|
+
baseURL: string;
|
|
248
|
+
apiKey?: string;
|
|
249
|
+
models?: string[];
|
|
250
|
+
}
|
|
251
|
+
interface AnyModelConfig {
|
|
252
|
+
anthropic?: ProviderConfig;
|
|
253
|
+
openai?: ProviderConfig;
|
|
254
|
+
google?: ProviderConfig;
|
|
255
|
+
mistral?: ProviderConfig;
|
|
256
|
+
groq?: ProviderConfig;
|
|
257
|
+
deepseek?: ProviderConfig;
|
|
258
|
+
xai?: ProviderConfig;
|
|
259
|
+
together?: ProviderConfig;
|
|
260
|
+
fireworks?: ProviderConfig;
|
|
261
|
+
perplexity?: ProviderConfig;
|
|
262
|
+
ollama?: ProviderConfig & {
|
|
263
|
+
baseURL?: string;
|
|
264
|
+
};
|
|
265
|
+
custom?: Record<string, CustomProviderConfig>;
|
|
266
|
+
aliases?: Record<string, string>;
|
|
267
|
+
defaults?: {
|
|
268
|
+
temperature?: number;
|
|
269
|
+
max_tokens?: number;
|
|
270
|
+
retries?: number;
|
|
271
|
+
timeout?: number;
|
|
272
|
+
transforms?: string[];
|
|
273
|
+
};
|
|
274
|
+
routing?: {
|
|
275
|
+
fallback_order?: string[];
|
|
276
|
+
allow_fallbacks?: boolean;
|
|
277
|
+
};
|
|
278
|
+
batch?: {
|
|
279
|
+
dir?: string;
|
|
280
|
+
pollInterval?: number;
|
|
281
|
+
concurrencyFallback?: number;
|
|
282
|
+
retentionDays?: number;
|
|
283
|
+
};
|
|
284
|
+
io?: {
|
|
285
|
+
readConcurrency?: number;
|
|
286
|
+
writeConcurrency?: number;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface ProviderAdapter {
|
|
291
|
+
readonly name: string;
|
|
292
|
+
translateRequest(request: ChatCompletionRequest): unknown;
|
|
293
|
+
translateResponse(response: unknown): ChatCompletion;
|
|
294
|
+
translateStream(stream: ReadableStream<Uint8Array>): AsyncIterable<ChatCompletionChunk>;
|
|
295
|
+
translateError(error: unknown): {
|
|
296
|
+
code: number;
|
|
297
|
+
message: string;
|
|
298
|
+
metadata: AnyModelErrorMetadata;
|
|
299
|
+
};
|
|
300
|
+
listModels(): Promise<ModelInfo[]>;
|
|
301
|
+
supportsParameter(param: string): boolean;
|
|
302
|
+
supportsBatch(): boolean;
|
|
303
|
+
sendRequest(request: ChatCompletionRequest): Promise<ChatCompletion>;
|
|
304
|
+
sendStreamingRequest(request: ChatCompletionRequest): Promise<AsyncIterable<ChatCompletionChunk>>;
|
|
305
|
+
}
|
|
306
|
+
interface NativeBatchStatus {
|
|
307
|
+
status: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
308
|
+
total: number;
|
|
309
|
+
completed: number;
|
|
310
|
+
failed: number;
|
|
311
|
+
}
|
|
312
|
+
interface BatchAdapter {
|
|
313
|
+
createBatch(model: string, requests: BatchRequestItem[], options?: Record<string, unknown>): Promise<{
|
|
314
|
+
providerBatchId: string;
|
|
315
|
+
metadata?: Record<string, unknown>;
|
|
316
|
+
}>;
|
|
317
|
+
pollBatch(providerBatchId: string): Promise<NativeBatchStatus>;
|
|
318
|
+
getBatchResults(providerBatchId: string): Promise<BatchResultItem[]>;
|
|
319
|
+
cancelBatch(providerBatchId: string): Promise<void>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
declare class ProviderRegistry {
|
|
323
|
+
private adapters;
|
|
324
|
+
register(slug: string, adapter: ProviderAdapter): void;
|
|
325
|
+
get(slug: string): ProviderAdapter;
|
|
326
|
+
has(slug: string): boolean;
|
|
327
|
+
list(): string[];
|
|
328
|
+
all(): ProviderAdapter[];
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Per-provider rate limit tracker.
|
|
333
|
+
* Tracks rate limit state from provider response headers and 429 errors.
|
|
334
|
+
*/
|
|
335
|
+
interface RateLimitState {
|
|
336
|
+
provider: string;
|
|
337
|
+
remaining: number | null;
|
|
338
|
+
resetAt: number | null;
|
|
339
|
+
retryAfter: number | null;
|
|
340
|
+
lastUpdated: number;
|
|
341
|
+
}
|
|
342
|
+
declare class RateLimitTracker {
|
|
343
|
+
private state;
|
|
344
|
+
/**
|
|
345
|
+
* Update rate limit state from response headers.
|
|
346
|
+
*/
|
|
347
|
+
updateFromHeaders(provider: string, headers: Record<string, string>): void;
|
|
348
|
+
/**
|
|
349
|
+
* Record a 429 for a provider.
|
|
350
|
+
*/
|
|
351
|
+
recordRateLimit(provider: string, retryAfterMs?: number): void;
|
|
352
|
+
/**
|
|
353
|
+
* Check if a provider is currently rate-limited.
|
|
354
|
+
*/
|
|
355
|
+
isRateLimited(provider: string): boolean;
|
|
356
|
+
/**
|
|
357
|
+
* Get ms until rate limit resets for a provider.
|
|
358
|
+
*/
|
|
359
|
+
getWaitTime(provider: string): number;
|
|
360
|
+
/**
|
|
361
|
+
* Get state for a provider.
|
|
362
|
+
*/
|
|
363
|
+
getState(provider: string): RateLimitState | undefined;
|
|
364
|
+
private getOrCreate;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
declare class Router {
|
|
368
|
+
private registry;
|
|
369
|
+
private aliases?;
|
|
370
|
+
private config?;
|
|
371
|
+
private rateLimiter;
|
|
372
|
+
constructor(registry: ProviderRegistry, aliases?: Record<string, string> | undefined, config?: AnyModelConfig | undefined);
|
|
373
|
+
/**
|
|
374
|
+
* Strip parameters that the target provider doesn't support.
|
|
375
|
+
*/
|
|
376
|
+
private stripUnsupported;
|
|
377
|
+
/**
|
|
378
|
+
* Apply transforms (e.g., middle-out) to the request messages.
|
|
379
|
+
*/
|
|
380
|
+
private applyTransforms;
|
|
381
|
+
/**
|
|
382
|
+
* Order models based on provider preferences.
|
|
383
|
+
*/
|
|
384
|
+
private applyProviderPreferences;
|
|
385
|
+
private getRetryOptions;
|
|
386
|
+
complete(request: ChatCompletionRequest): Promise<ChatCompletion>;
|
|
387
|
+
stream(request: ChatCompletionRequest): Promise<AsyncIterable<ChatCompletionChunk>>;
|
|
388
|
+
private completeWithFallback;
|
|
389
|
+
private streamWithFallback;
|
|
390
|
+
getRateLimiter(): RateLimitTracker;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
interface BatchPollOptions {
|
|
394
|
+
/** Poll interval in ms. Default: 5000 */
|
|
395
|
+
interval?: number;
|
|
396
|
+
/** Timeout in ms. 0 = indefinite. Default: 0 */
|
|
397
|
+
timeout?: number;
|
|
398
|
+
/** Progress callback */
|
|
399
|
+
onProgress?: (batch: BatchObject) => void;
|
|
400
|
+
}
|
|
401
|
+
declare class BatchManager {
|
|
402
|
+
private store;
|
|
403
|
+
private router;
|
|
404
|
+
private concurrencyLimit;
|
|
405
|
+
private defaultPollInterval;
|
|
406
|
+
private batchAdapters;
|
|
407
|
+
constructor(router: Router, options?: {
|
|
408
|
+
dir?: string;
|
|
409
|
+
concurrency?: number;
|
|
410
|
+
pollInterval?: number;
|
|
411
|
+
});
|
|
412
|
+
/**
|
|
413
|
+
* Register a native batch adapter for a provider.
|
|
414
|
+
*/
|
|
415
|
+
registerBatchAdapter(providerName: string, adapter: BatchAdapter): void;
|
|
416
|
+
/**
|
|
417
|
+
* Check if a provider has native batch support.
|
|
418
|
+
*/
|
|
419
|
+
private getNativeBatchAdapter;
|
|
420
|
+
/**
|
|
421
|
+
* Create a batch and return immediately (no polling).
|
|
422
|
+
*/
|
|
423
|
+
create(request: BatchCreateRequest): Promise<BatchObject>;
|
|
424
|
+
/**
|
|
425
|
+
* Create a batch and poll until completion.
|
|
426
|
+
*/
|
|
427
|
+
createAndPoll(request: BatchCreateRequest, options?: BatchPollOptions): Promise<BatchResults>;
|
|
428
|
+
/**
|
|
429
|
+
* Poll an existing batch until completion.
|
|
430
|
+
*/
|
|
431
|
+
poll(id: string, options?: BatchPollOptions): Promise<BatchResults>;
|
|
432
|
+
/**
|
|
433
|
+
* Get the current status of a batch.
|
|
434
|
+
*/
|
|
435
|
+
get(id: string): Promise<BatchObject | null>;
|
|
436
|
+
/**
|
|
437
|
+
* Get results for a completed batch.
|
|
438
|
+
*/
|
|
439
|
+
getResults(id: string): Promise<BatchResults>;
|
|
440
|
+
/**
|
|
441
|
+
* List all batches.
|
|
442
|
+
*/
|
|
443
|
+
list(): Promise<BatchObject[]>;
|
|
444
|
+
/**
|
|
445
|
+
* Cancel a batch.
|
|
446
|
+
*/
|
|
447
|
+
cancel(id: string): Promise<BatchObject>;
|
|
448
|
+
/**
|
|
449
|
+
* Process batch via native provider batch API.
|
|
450
|
+
*/
|
|
451
|
+
private processNativeBatch;
|
|
452
|
+
/**
|
|
453
|
+
* Sync native batch status from provider.
|
|
454
|
+
*/
|
|
455
|
+
private syncNativeBatchStatus;
|
|
456
|
+
/**
|
|
457
|
+
* Process batch requests concurrently (fallback path).
|
|
458
|
+
*/
|
|
459
|
+
private processConcurrentBatch;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
declare class AnyModel {
|
|
463
|
+
private registry;
|
|
464
|
+
private router;
|
|
465
|
+
private config;
|
|
466
|
+
private modelCache;
|
|
467
|
+
private statsStore;
|
|
468
|
+
private batchManager;
|
|
469
|
+
readonly chat: {
|
|
470
|
+
completions: {
|
|
471
|
+
create: (request: ChatCompletionRequest) => Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>>;
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
readonly models: {
|
|
475
|
+
list: (opts?: {
|
|
476
|
+
provider?: string;
|
|
477
|
+
}) => Promise<ModelInfo[]>;
|
|
478
|
+
refresh: () => Promise<ModelInfo[]>;
|
|
479
|
+
};
|
|
480
|
+
readonly generation: {
|
|
481
|
+
get: (id: string) => GenerationStats | undefined;
|
|
482
|
+
list: (limit?: number) => GenerationStats[];
|
|
483
|
+
};
|
|
484
|
+
readonly batches: {
|
|
485
|
+
create: (request: BatchCreateRequest) => Promise<BatchObject>;
|
|
486
|
+
createAndPoll: (request: BatchCreateRequest, options?: BatchPollOptions) => Promise<BatchResults>;
|
|
487
|
+
poll: (id: string, options?: BatchPollOptions) => Promise<BatchResults>;
|
|
488
|
+
get: (id: string) => Promise<BatchObject | null>;
|
|
489
|
+
list: () => Promise<BatchObject[]>;
|
|
490
|
+
cancel: (id: string) => Promise<BatchObject>;
|
|
491
|
+
results: (id: string) => Promise<BatchResults>;
|
|
492
|
+
};
|
|
493
|
+
constructor(config?: AnyModelConfig);
|
|
494
|
+
private registerProviders;
|
|
495
|
+
private registerBatchAdapters;
|
|
496
|
+
private applyDefaults;
|
|
497
|
+
private fetchModels;
|
|
498
|
+
getRegistry(): ProviderRegistry;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Resolve config with precedence: programmatic → local → global → env vars.
|
|
503
|
+
*/
|
|
504
|
+
declare function resolveConfig(programmatic?: AnyModelConfig, cwd?: string): AnyModelConfig;
|
|
505
|
+
|
|
506
|
+
interface GenerationRecord {
|
|
507
|
+
id: string;
|
|
508
|
+
model: string;
|
|
509
|
+
providerName: string;
|
|
510
|
+
promptTokens: number;
|
|
511
|
+
completionTokens: number;
|
|
512
|
+
startTime: number;
|
|
513
|
+
endTime: number;
|
|
514
|
+
finishReason: FinishReason;
|
|
515
|
+
streamed: boolean;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* In-memory generation stats store.
|
|
519
|
+
* Tracks recent completions for the generation stats endpoint.
|
|
520
|
+
*/
|
|
521
|
+
declare class GenerationStatsStore {
|
|
522
|
+
private records;
|
|
523
|
+
private maxRecords;
|
|
524
|
+
constructor(maxRecords?: number);
|
|
525
|
+
record(entry: GenerationRecord): void;
|
|
526
|
+
get(id: string): GenerationStats | undefined;
|
|
527
|
+
list(limit?: number): GenerationStats[];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Disk-based batch persistence store.
|
|
532
|
+
* Uses queued, concurrency-limited IO for high-volume operations.
|
|
533
|
+
* Structure: {dir}/{batchId}/meta.json, requests.jsonl, results.jsonl, provider.json
|
|
534
|
+
*/
|
|
535
|
+
declare class BatchStore {
|
|
536
|
+
private dir;
|
|
537
|
+
private initialized;
|
|
538
|
+
constructor(dir?: string);
|
|
539
|
+
private init;
|
|
540
|
+
private batchDir;
|
|
541
|
+
/**
|
|
542
|
+
* Create a new batch directory and save initial metadata.
|
|
543
|
+
*/
|
|
544
|
+
create(batch: BatchObject): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* Update batch metadata (atomic write).
|
|
547
|
+
*/
|
|
548
|
+
updateMeta(batch: BatchObject): Promise<void>;
|
|
549
|
+
/**
|
|
550
|
+
* Save requests as JSONL.
|
|
551
|
+
*/
|
|
552
|
+
saveRequests(id: string, requests: unknown[]): Promise<void>;
|
|
553
|
+
/**
|
|
554
|
+
* Append a result to results.jsonl.
|
|
555
|
+
*/
|
|
556
|
+
appendResult(id: string, result: BatchResultItem): Promise<void>;
|
|
557
|
+
/**
|
|
558
|
+
* Save provider-specific state (e.g., provider batch ID).
|
|
559
|
+
*/
|
|
560
|
+
saveProviderState(id: string, state: Record<string, unknown>): Promise<void>;
|
|
561
|
+
/**
|
|
562
|
+
* Load provider state.
|
|
563
|
+
*/
|
|
564
|
+
loadProviderState(id: string): Promise<Record<string, unknown> | null>;
|
|
565
|
+
/**
|
|
566
|
+
* Get batch metadata.
|
|
567
|
+
*/
|
|
568
|
+
getMeta(id: string): Promise<BatchObject | null>;
|
|
569
|
+
/**
|
|
570
|
+
* Get all results for a batch.
|
|
571
|
+
*/
|
|
572
|
+
getResults(id: string): Promise<BatchResultItem[]>;
|
|
573
|
+
/**
|
|
574
|
+
* List all batch IDs.
|
|
575
|
+
*/
|
|
576
|
+
listBatches(): Promise<string[]>;
|
|
577
|
+
/**
|
|
578
|
+
* Check if a batch exists.
|
|
579
|
+
*/
|
|
580
|
+
exists(id: string): Promise<boolean>;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
interface ServerOptions {
|
|
584
|
+
port?: number;
|
|
585
|
+
host?: string;
|
|
586
|
+
config?: AnyModelConfig;
|
|
587
|
+
}
|
|
588
|
+
declare function createAnyModelServer(options?: ServerOptions): ReturnType<typeof createServer>;
|
|
589
|
+
declare function startServer(options?: ServerOptions): void;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Concurrency-limited filesystem helpers for high-volume file operations.
|
|
593
|
+
*
|
|
594
|
+
* Based on probeo-core/common/fs-io. Provides queued reads/writes,
|
|
595
|
+
* atomic durable writes, directory caching, and path memoization.
|
|
596
|
+
*/
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Configure the filesystem IO concurrency limits.
|
|
600
|
+
* Call before any IO operations to adjust defaults.
|
|
601
|
+
*/
|
|
602
|
+
declare function configureFsIO(options: {
|
|
603
|
+
readConcurrency?: number;
|
|
604
|
+
writeConcurrency?: number;
|
|
605
|
+
}): void;
|
|
606
|
+
declare function ensureDir(dir: string): Promise<void>;
|
|
607
|
+
declare function readFileQueued(filePath: string, encoding?: BufferEncoding | null): Promise<string | Buffer>;
|
|
608
|
+
declare function writeFileQueued(filePath: string, data: string | Buffer): Promise<void>;
|
|
609
|
+
declare function appendFileQueued(filePath: string, data: string | Buffer): Promise<void>;
|
|
610
|
+
/**
|
|
611
|
+
* Atomically write a file with fsync to ensure data hits disk.
|
|
612
|
+
* Uses temp file + rename + directory fsync.
|
|
613
|
+
*/
|
|
614
|
+
declare function writeFileFlushedQueued(filePath: string, data: string | Buffer): Promise<void>;
|
|
615
|
+
declare function joinPath(...segments: string[]): string;
|
|
616
|
+
declare function getFsQueueStatus(): {
|
|
617
|
+
read: {
|
|
618
|
+
size: number;
|
|
619
|
+
pending: number;
|
|
620
|
+
};
|
|
621
|
+
write: {
|
|
622
|
+
size: number;
|
|
623
|
+
pending: number;
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
declare function waitForFsQueuesIdle(): Promise<void>;
|
|
627
|
+
|
|
628
|
+
declare function createOpenAIBatchAdapter(apiKey: string): BatchAdapter;
|
|
629
|
+
|
|
630
|
+
declare function createAnthropicBatchAdapter(apiKey: string): BatchAdapter;
|
|
631
|
+
|
|
632
|
+
export { AnyModel, type AnyModelConfig, AnyModelError, type AnyModelErrorMetadata, type BatchAdapter, type BatchCreateRequest, BatchManager, type BatchMode, type BatchObject, type BatchPollOptions, type BatchRequestItem, type BatchResultItem, type BatchResults, type BatchStatus, BatchStore, type BatchUsageSummary, type ChatCompletion, type ChatCompletionChoice, type ChatCompletionChunk, type ChatCompletionRequest, type ChunkChoice, type ChunkDelta, type ContentPart, type CustomProviderConfig, type FinishReason, type GenerationStats, GenerationStatsStore, type Message, type ModelArchitecture, type ModelInfo, type ModelPricing, type ModelTopProvider, type NativeBatchStatus, type ProviderAdapter, type ProviderConfig, type ProviderPreferences, type ResponseFormat, type Role, type ServerOptions, type Tool, type ToolCall, type ToolChoice, type Usage, appendFileQueued, configureFsIO, createAnthropicBatchAdapter, createAnyModelServer, createOpenAIBatchAdapter, ensureDir, getFsQueueStatus, joinPath, readFileQueued, resolveConfig, startServer, waitForFsQueuesIdle, writeFileFlushedQueued, writeFileQueued };
|