@relayplane/proxy 0.1.9 → 0.2.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 +113 -247
- package/__tests__/server.test.ts +512 -0
- package/__tests__/telemetry.test.ts +126 -0
- package/dist/cli.d.ts +35 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +262 -3024
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +80 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +25 -1130
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -3005
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +209 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1089 -0
- package/dist/server.js.map +1 -0
- package/dist/streaming.d.ts +80 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +271 -0
- package/dist/streaming.js.map +1 -0
- package/dist/telemetry.d.ts +111 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +315 -0
- package/dist/telemetry.js.map +1 -0
- package/package.json +21 -46
- package/src/cli.ts +341 -0
- package/src/config.ts +206 -0
- package/src/index.ts +82 -0
- package/src/server.ts +1328 -0
- package/src/streaming.ts +331 -0
- package/src/telemetry.ts +343 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +21 -0
- package/LICENSE +0 -21
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs +0 -3043
- package/dist/cli.mjs.map +0 -1
- package/dist/index.d.mts +0 -1141
- package/dist/index.mjs +0 -2948
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
DELETED
|
@@ -1,1141 +0,0 @@
|
|
|
1
|
-
import * as http from 'node:http';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* RelayPlane Core Types
|
|
6
|
-
*
|
|
7
|
-
* All TypeScript interfaces for the agent optimization layer.
|
|
8
|
-
*
|
|
9
|
-
* @packageDocumentation
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The 9 task types that RelayPlane can infer and route.
|
|
14
|
-
*/
|
|
15
|
-
declare const TaskTypes: readonly ["code_generation", "code_review", "summarization", "analysis", "creative_writing", "data_extraction", "translation", "question_answering", "general"];
|
|
16
|
-
type TaskType = (typeof TaskTypes)[number];
|
|
17
|
-
/**
|
|
18
|
-
* Zod schema for task types.
|
|
19
|
-
*/
|
|
20
|
-
declare const TaskTypeSchema: z.ZodEnum<["code_generation", "code_review", "summarization", "analysis", "creative_writing", "data_extraction", "translation", "question_answering", "general"]>;
|
|
21
|
-
/**
|
|
22
|
-
* Supported AI providers.
|
|
23
|
-
*/
|
|
24
|
-
declare const Providers: readonly ["openai", "anthropic", "google", "xai", "moonshot", "local"];
|
|
25
|
-
type Provider = (typeof Providers)[number];
|
|
26
|
-
/**
|
|
27
|
-
* Zod schema for providers.
|
|
28
|
-
*/
|
|
29
|
-
declare const ProviderSchema: z.ZodEnum<["openai", "anthropic", "google", "xai", "moonshot", "local"]>;
|
|
30
|
-
/**
|
|
31
|
-
* Provider-specific configuration.
|
|
32
|
-
*/
|
|
33
|
-
interface ProviderConfig {
|
|
34
|
-
apiKey?: string;
|
|
35
|
-
baseUrl?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* RelayPlane configuration.
|
|
39
|
-
*/
|
|
40
|
-
interface RelayPlaneConfig {
|
|
41
|
-
/**
|
|
42
|
-
* Path to SQLite database file.
|
|
43
|
-
* @default "~/.relayplane/data.db"
|
|
44
|
-
*/
|
|
45
|
-
dbPath?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Provider configurations.
|
|
48
|
-
*/
|
|
49
|
-
providers?: Partial<Record<Provider, ProviderConfig>>;
|
|
50
|
-
/**
|
|
51
|
-
* Default provider to use when routing cannot determine one.
|
|
52
|
-
* @default "local"
|
|
53
|
-
*/
|
|
54
|
-
defaultProvider?: Provider;
|
|
55
|
-
/**
|
|
56
|
-
* Default model within the default provider.
|
|
57
|
-
* @default "llama3.2"
|
|
58
|
-
*/
|
|
59
|
-
defaultModel?: string;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Input for a RelayPlane run.
|
|
63
|
-
*/
|
|
64
|
-
interface RunInput {
|
|
65
|
-
/**
|
|
66
|
-
* The prompt to send to the model.
|
|
67
|
-
*/
|
|
68
|
-
prompt: string;
|
|
69
|
-
/**
|
|
70
|
-
* Optional system prompt.
|
|
71
|
-
*/
|
|
72
|
-
systemPrompt?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Override the inferred task type.
|
|
75
|
-
*/
|
|
76
|
-
taskType?: TaskType;
|
|
77
|
-
/**
|
|
78
|
-
* Override the model selection (format: "provider:model").
|
|
79
|
-
*/
|
|
80
|
-
model?: string;
|
|
81
|
-
/**
|
|
82
|
-
* Additional metadata to attach to the run.
|
|
83
|
-
*/
|
|
84
|
-
metadata?: Record<string, unknown>;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Result of a RelayPlane run.
|
|
88
|
-
*/
|
|
89
|
-
interface RunResult {
|
|
90
|
-
/**
|
|
91
|
-
* Unique identifier for this run.
|
|
92
|
-
*/
|
|
93
|
-
runId: string;
|
|
94
|
-
/**
|
|
95
|
-
* Whether the run completed successfully.
|
|
96
|
-
*/
|
|
97
|
-
success: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* The model's output (if successful).
|
|
100
|
-
*/
|
|
101
|
-
output?: string;
|
|
102
|
-
/**
|
|
103
|
-
* Error message (if failed).
|
|
104
|
-
*/
|
|
105
|
-
error?: string;
|
|
106
|
-
/**
|
|
107
|
-
* The inferred or specified task type.
|
|
108
|
-
*/
|
|
109
|
-
taskType: TaskType;
|
|
110
|
-
/**
|
|
111
|
-
* The model used (format: "provider:model").
|
|
112
|
-
*/
|
|
113
|
-
model: string;
|
|
114
|
-
/**
|
|
115
|
-
* Execution duration in milliseconds.
|
|
116
|
-
*/
|
|
117
|
-
durationMs: number;
|
|
118
|
-
/**
|
|
119
|
-
* Input tokens used (if available).
|
|
120
|
-
*/
|
|
121
|
-
tokensIn?: number;
|
|
122
|
-
/**
|
|
123
|
-
* Output tokens used (if available).
|
|
124
|
-
*/
|
|
125
|
-
tokensOut?: number;
|
|
126
|
-
/**
|
|
127
|
-
* Timestamp of the run.
|
|
128
|
-
*/
|
|
129
|
-
timestamp: string;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Source of a routing rule.
|
|
133
|
-
*/
|
|
134
|
-
declare const RuleSources: readonly ["default", "user", "learned"];
|
|
135
|
-
type RuleSource = (typeof RuleSources)[number];
|
|
136
|
-
/**
|
|
137
|
-
* A routing rule that maps a task type to a preferred model.
|
|
138
|
-
*/
|
|
139
|
-
interface RoutingRule {
|
|
140
|
-
/**
|
|
141
|
-
* Unique identifier for this rule.
|
|
142
|
-
*/
|
|
143
|
-
id: string;
|
|
144
|
-
/**
|
|
145
|
-
* The task type this rule applies to.
|
|
146
|
-
*/
|
|
147
|
-
taskType: TaskType;
|
|
148
|
-
/**
|
|
149
|
-
* The preferred model (format: "provider:model").
|
|
150
|
-
*/
|
|
151
|
-
preferredModel: string;
|
|
152
|
-
/**
|
|
153
|
-
* How this rule was created.
|
|
154
|
-
*/
|
|
155
|
-
source: RuleSource;
|
|
156
|
-
/**
|
|
157
|
-
* Confidence score (0-1) for learned rules.
|
|
158
|
-
*/
|
|
159
|
-
confidence?: number;
|
|
160
|
-
/**
|
|
161
|
-
* Number of runs that informed this rule.
|
|
162
|
-
*/
|
|
163
|
-
sampleCount?: number;
|
|
164
|
-
/**
|
|
165
|
-
* When the rule was created.
|
|
166
|
-
*/
|
|
167
|
-
createdAt: string;
|
|
168
|
-
/**
|
|
169
|
-
* When the rule was last updated.
|
|
170
|
-
*/
|
|
171
|
-
updatedAt: string;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Outcome quality levels.
|
|
175
|
-
*/
|
|
176
|
-
declare const OutcomeQualities: readonly ["excellent", "good", "acceptable", "poor", "failed"];
|
|
177
|
-
type OutcomeQuality = (typeof OutcomeQualities)[number];
|
|
178
|
-
/**
|
|
179
|
-
* Input for recording an outcome.
|
|
180
|
-
*/
|
|
181
|
-
interface OutcomeInput {
|
|
182
|
-
/**
|
|
183
|
-
* The run ID to record outcome for.
|
|
184
|
-
*/
|
|
185
|
-
runId: string;
|
|
186
|
-
/**
|
|
187
|
-
* Whether the outcome was successful.
|
|
188
|
-
*/
|
|
189
|
-
success: boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Quality assessment.
|
|
192
|
-
*/
|
|
193
|
-
quality?: OutcomeQuality;
|
|
194
|
-
/**
|
|
195
|
-
* Latency satisfaction (was the response fast enough?).
|
|
196
|
-
*/
|
|
197
|
-
latencySatisfactory?: boolean;
|
|
198
|
-
/**
|
|
199
|
-
* Cost satisfaction (was the cost acceptable?).
|
|
200
|
-
*/
|
|
201
|
-
costSatisfactory?: boolean;
|
|
202
|
-
/**
|
|
203
|
-
* Free-form feedback.
|
|
204
|
-
*/
|
|
205
|
-
feedback?: string;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* A recorded outcome with full details.
|
|
209
|
-
*/
|
|
210
|
-
interface Outcome extends OutcomeInput {
|
|
211
|
-
/**
|
|
212
|
-
* Unique identifier for this outcome.
|
|
213
|
-
*/
|
|
214
|
-
id: string;
|
|
215
|
-
/**
|
|
216
|
-
* When the outcome was recorded.
|
|
217
|
-
*/
|
|
218
|
-
recordedAt: string;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Statistics for a specific task type.
|
|
222
|
-
*/
|
|
223
|
-
interface TaskStats {
|
|
224
|
-
/**
|
|
225
|
-
* The task type.
|
|
226
|
-
*/
|
|
227
|
-
taskType: TaskType;
|
|
228
|
-
/**
|
|
229
|
-
* Total number of runs.
|
|
230
|
-
*/
|
|
231
|
-
totalRuns: number;
|
|
232
|
-
/**
|
|
233
|
-
* Number of successful runs.
|
|
234
|
-
*/
|
|
235
|
-
successfulRuns: number;
|
|
236
|
-
/**
|
|
237
|
-
* Success rate (0-1).
|
|
238
|
-
*/
|
|
239
|
-
successRate: number;
|
|
240
|
-
/**
|
|
241
|
-
* Average duration in milliseconds.
|
|
242
|
-
*/
|
|
243
|
-
avgDurationMs: number;
|
|
244
|
-
/**
|
|
245
|
-
* Average input tokens.
|
|
246
|
-
*/
|
|
247
|
-
avgTokensIn?: number;
|
|
248
|
-
/**
|
|
249
|
-
* Average output tokens.
|
|
250
|
-
*/
|
|
251
|
-
avgTokensOut?: number;
|
|
252
|
-
/**
|
|
253
|
-
* Model breakdown.
|
|
254
|
-
*/
|
|
255
|
-
byModel: Record<string, {
|
|
256
|
-
runs: number;
|
|
257
|
-
successRate: number;
|
|
258
|
-
avgDurationMs: number;
|
|
259
|
-
}>;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Overall statistics.
|
|
263
|
-
*/
|
|
264
|
-
interface Stats {
|
|
265
|
-
/**
|
|
266
|
-
* Total runs across all task types.
|
|
267
|
-
*/
|
|
268
|
-
totalRuns: number;
|
|
269
|
-
/**
|
|
270
|
-
* Overall success rate.
|
|
271
|
-
*/
|
|
272
|
-
overallSuccessRate: number;
|
|
273
|
-
/**
|
|
274
|
-
* Statistics by task type.
|
|
275
|
-
*/
|
|
276
|
-
byTaskType: Record<TaskType, TaskStats>;
|
|
277
|
-
/**
|
|
278
|
-
* Time period covered.
|
|
279
|
-
*/
|
|
280
|
-
period: {
|
|
281
|
-
from: string;
|
|
282
|
-
to: string;
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* A suggestion for improving routing.
|
|
287
|
-
*/
|
|
288
|
-
interface Suggestion {
|
|
289
|
-
/**
|
|
290
|
-
* Unique identifier for this suggestion.
|
|
291
|
-
*/
|
|
292
|
-
id: string;
|
|
293
|
-
/**
|
|
294
|
-
* The task type this suggestion applies to.
|
|
295
|
-
*/
|
|
296
|
-
taskType: TaskType;
|
|
297
|
-
/**
|
|
298
|
-
* Current model being used.
|
|
299
|
-
*/
|
|
300
|
-
currentModel: string;
|
|
301
|
-
/**
|
|
302
|
-
* Suggested model to switch to.
|
|
303
|
-
*/
|
|
304
|
-
suggestedModel: string;
|
|
305
|
-
/**
|
|
306
|
-
* Reason for the suggestion.
|
|
307
|
-
*/
|
|
308
|
-
reason: string;
|
|
309
|
-
/**
|
|
310
|
-
* Confidence score (0-1).
|
|
311
|
-
*/
|
|
312
|
-
confidence: number;
|
|
313
|
-
/**
|
|
314
|
-
* Expected improvement.
|
|
315
|
-
*/
|
|
316
|
-
expectedImprovement: {
|
|
317
|
-
successRate?: number;
|
|
318
|
-
latency?: number;
|
|
319
|
-
cost?: number;
|
|
320
|
-
};
|
|
321
|
-
/**
|
|
322
|
-
* Number of data points this suggestion is based on.
|
|
323
|
-
*/
|
|
324
|
-
sampleCount: number;
|
|
325
|
-
/**
|
|
326
|
-
* When the suggestion was generated.
|
|
327
|
-
*/
|
|
328
|
-
createdAt: string;
|
|
329
|
-
/**
|
|
330
|
-
* Whether this suggestion has been accepted.
|
|
331
|
-
*/
|
|
332
|
-
accepted?: boolean;
|
|
333
|
-
/**
|
|
334
|
-
* When the suggestion was accepted.
|
|
335
|
-
*/
|
|
336
|
-
acceptedAt?: string;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Run record as stored in the database.
|
|
340
|
-
*/
|
|
341
|
-
interface RunRecord {
|
|
342
|
-
id: string;
|
|
343
|
-
prompt: string;
|
|
344
|
-
systemPrompt: string | null;
|
|
345
|
-
taskType: TaskType;
|
|
346
|
-
model: string;
|
|
347
|
-
success: boolean;
|
|
348
|
-
output: string | null;
|
|
349
|
-
error: string | null;
|
|
350
|
-
durationMs: number;
|
|
351
|
-
tokensIn: number | null;
|
|
352
|
-
tokensOut: number | null;
|
|
353
|
-
costUsd: number | null;
|
|
354
|
-
metadata: string | null;
|
|
355
|
-
createdAt: string;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Outcome record as stored in the database.
|
|
359
|
-
*/
|
|
360
|
-
interface OutcomeRecord {
|
|
361
|
-
id: string;
|
|
362
|
-
runId: string;
|
|
363
|
-
success: boolean;
|
|
364
|
-
quality: OutcomeQuality | null;
|
|
365
|
-
latencySatisfactory: boolean | null;
|
|
366
|
-
costSatisfactory: boolean | null;
|
|
367
|
-
feedback: string | null;
|
|
368
|
-
createdAt: string;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Routing rule record as stored in the database.
|
|
372
|
-
*/
|
|
373
|
-
interface RuleRecord {
|
|
374
|
-
id: string;
|
|
375
|
-
taskType: TaskType;
|
|
376
|
-
preferredModel: string;
|
|
377
|
-
source: RuleSource;
|
|
378
|
-
confidence: number | null;
|
|
379
|
-
sampleCount: number | null;
|
|
380
|
-
createdAt: string;
|
|
381
|
-
updatedAt: string;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Suggestion record as stored in the database.
|
|
385
|
-
*/
|
|
386
|
-
interface SuggestionRecord {
|
|
387
|
-
id: string;
|
|
388
|
-
taskType: TaskType;
|
|
389
|
-
currentModel: string;
|
|
390
|
-
suggestedModel: string;
|
|
391
|
-
reason: string;
|
|
392
|
-
confidence: number;
|
|
393
|
-
expectedImprovement: string;
|
|
394
|
-
sampleCount: number;
|
|
395
|
-
accepted: boolean | null;
|
|
396
|
-
createdAt: string;
|
|
397
|
-
acceptedAt: string | null;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* RelayPlane L2/L3 Proxy Server
|
|
402
|
-
*
|
|
403
|
-
* An OpenAI-compatible HTTP proxy that intelligently routes requests
|
|
404
|
-
* to the optimal model using @relayplane/core.
|
|
405
|
-
*
|
|
406
|
-
* Supports:
|
|
407
|
-
* - Streaming (SSE) for both OpenAI and Anthropic
|
|
408
|
-
* - Non-streaming requests
|
|
409
|
-
* - Automatic format conversion (Anthropic → OpenAI format)
|
|
410
|
-
* - Tool/function calling (planned)
|
|
411
|
-
*
|
|
412
|
-
* @packageDocumentation
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Provider endpoint configuration
|
|
417
|
-
*/
|
|
418
|
-
interface ProviderEndpoint {
|
|
419
|
-
baseUrl: string;
|
|
420
|
-
apiKeyEnv: string;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Default provider endpoints
|
|
424
|
-
*/
|
|
425
|
-
declare const DEFAULT_ENDPOINTS: Record<string, ProviderEndpoint>;
|
|
426
|
-
/**
|
|
427
|
-
* Model to provider/model mapping
|
|
428
|
-
*/
|
|
429
|
-
declare const MODEL_MAPPING: Record<string, {
|
|
430
|
-
provider: Provider;
|
|
431
|
-
model: string;
|
|
432
|
-
}>;
|
|
433
|
-
/**
|
|
434
|
-
* Proxy server configuration
|
|
435
|
-
*/
|
|
436
|
-
interface ProxyConfig {
|
|
437
|
-
port?: number;
|
|
438
|
-
host?: string;
|
|
439
|
-
dbPath?: string;
|
|
440
|
-
verbose?: boolean;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Start the RelayPlane proxy server
|
|
444
|
-
*/
|
|
445
|
-
declare function startProxy(config?: ProxyConfig): Promise<http.Server>;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Task Type Inference
|
|
449
|
-
*
|
|
450
|
-
* Infers the task type from a prompt using pattern matching.
|
|
451
|
-
* Designed for <5ms execution with no network calls.
|
|
452
|
-
*
|
|
453
|
-
* @packageDocumentation
|
|
454
|
-
*/
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Infers the task type from a prompt.
|
|
458
|
-
*
|
|
459
|
-
* @param prompt - The user's prompt
|
|
460
|
-
* @returns The inferred task type
|
|
461
|
-
*/
|
|
462
|
-
declare function inferTaskType(prompt: string): TaskType;
|
|
463
|
-
/**
|
|
464
|
-
* Gets the confidence score for an inferred task type.
|
|
465
|
-
*
|
|
466
|
-
* @param prompt - The user's prompt
|
|
467
|
-
* @param taskType - The task type to check confidence for
|
|
468
|
-
* @returns Confidence score between 0 and 1
|
|
469
|
-
*/
|
|
470
|
-
declare function getInferenceConfidence(prompt: string, taskType: TaskType): number;
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* SQLite Storage Implementation
|
|
474
|
-
*
|
|
475
|
-
* Provides persistent storage for runs, outcomes, routing rules, and suggestions.
|
|
476
|
-
*
|
|
477
|
-
* @packageDocumentation
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* SQLite storage class for RelayPlane data.
|
|
482
|
-
*/
|
|
483
|
-
declare class Store {
|
|
484
|
-
private db;
|
|
485
|
-
private readonly dbPath;
|
|
486
|
-
/**
|
|
487
|
-
* Creates a new Store instance.
|
|
488
|
-
*
|
|
489
|
-
* @param dbPath - Path to the SQLite database file. Defaults to ~/.relayplane/data.db
|
|
490
|
-
*/
|
|
491
|
-
constructor(dbPath?: string);
|
|
492
|
-
/**
|
|
493
|
-
* Initializes the database schema.
|
|
494
|
-
*/
|
|
495
|
-
private initializeSchema;
|
|
496
|
-
/**
|
|
497
|
-
* Closes the database connection.
|
|
498
|
-
*/
|
|
499
|
-
close(): void;
|
|
500
|
-
/**
|
|
501
|
-
* Gets the database path.
|
|
502
|
-
*/
|
|
503
|
-
getDbPath(): string;
|
|
504
|
-
/**
|
|
505
|
-
* Records a new run.
|
|
506
|
-
*/
|
|
507
|
-
recordRun(run: Omit<RunRecord, 'id' | 'createdAt'>): string;
|
|
508
|
-
/**
|
|
509
|
-
* Gets a run by ID.
|
|
510
|
-
*/
|
|
511
|
-
getRun(id: string): RunRecord | null;
|
|
512
|
-
/**
|
|
513
|
-
* Gets runs with optional filters.
|
|
514
|
-
*/
|
|
515
|
-
getRuns(options?: {
|
|
516
|
-
taskType?: TaskType;
|
|
517
|
-
model?: string;
|
|
518
|
-
limit?: number;
|
|
519
|
-
offset?: number;
|
|
520
|
-
from?: string;
|
|
521
|
-
to?: string;
|
|
522
|
-
}): RunRecord[];
|
|
523
|
-
/**
|
|
524
|
-
* Counts runs with optional filters.
|
|
525
|
-
*/
|
|
526
|
-
countRuns(options?: {
|
|
527
|
-
taskType?: TaskType;
|
|
528
|
-
model?: string;
|
|
529
|
-
from?: string;
|
|
530
|
-
to?: string;
|
|
531
|
-
}): number;
|
|
532
|
-
/**
|
|
533
|
-
* Records an outcome for a run.
|
|
534
|
-
*/
|
|
535
|
-
recordOutcome(outcome: Omit<OutcomeRecord, 'id' | 'createdAt'>): string;
|
|
536
|
-
/**
|
|
537
|
-
* Gets an outcome for a run.
|
|
538
|
-
*/
|
|
539
|
-
getOutcome(runId: string): OutcomeRecord | null;
|
|
540
|
-
/**
|
|
541
|
-
* Gets outcomes with optional filters.
|
|
542
|
-
*/
|
|
543
|
-
getOutcomes(options?: {
|
|
544
|
-
taskType?: TaskType;
|
|
545
|
-
model?: string;
|
|
546
|
-
limit?: number;
|
|
547
|
-
from?: string;
|
|
548
|
-
to?: string;
|
|
549
|
-
}): Array<OutcomeRecord & {
|
|
550
|
-
taskType: TaskType;
|
|
551
|
-
model: string;
|
|
552
|
-
}>;
|
|
553
|
-
/**
|
|
554
|
-
* Gets a routing rule for a task type.
|
|
555
|
-
*/
|
|
556
|
-
getRule(taskType: TaskType): RuleRecord | null;
|
|
557
|
-
/**
|
|
558
|
-
* Sets a routing rule for a task type.
|
|
559
|
-
*/
|
|
560
|
-
setRule(taskType: TaskType, preferredModel: string, source: RuleSource, confidence?: number, sampleCount?: number): string;
|
|
561
|
-
/**
|
|
562
|
-
* Lists all routing rules.
|
|
563
|
-
*/
|
|
564
|
-
listRules(): RuleRecord[];
|
|
565
|
-
/**
|
|
566
|
-
* Deletes a routing rule and resets to default.
|
|
567
|
-
*/
|
|
568
|
-
deleteRule(taskType: TaskType): boolean;
|
|
569
|
-
/**
|
|
570
|
-
* Records a suggestion.
|
|
571
|
-
*/
|
|
572
|
-
recordSuggestion(suggestion: Omit<SuggestionRecord, 'id' | 'createdAt' | 'acceptedAt'>): string;
|
|
573
|
-
/**
|
|
574
|
-
* Gets a suggestion by ID.
|
|
575
|
-
*/
|
|
576
|
-
getSuggestion(id: string): SuggestionRecord | null;
|
|
577
|
-
/**
|
|
578
|
-
* Gets pending (unaccepted) suggestions.
|
|
579
|
-
*/
|
|
580
|
-
getPendingSuggestions(): SuggestionRecord[];
|
|
581
|
-
/**
|
|
582
|
-
* Accepts a suggestion.
|
|
583
|
-
*/
|
|
584
|
-
acceptSuggestion(id: string): boolean;
|
|
585
|
-
/**
|
|
586
|
-
* Rejects a suggestion.
|
|
587
|
-
*/
|
|
588
|
-
rejectSuggestion(id: string): boolean;
|
|
589
|
-
/**
|
|
590
|
-
* Gets aggregated statistics.
|
|
591
|
-
*/
|
|
592
|
-
getStats(options?: {
|
|
593
|
-
from?: string;
|
|
594
|
-
to?: string;
|
|
595
|
-
}): {
|
|
596
|
-
totalRuns: number;
|
|
597
|
-
successfulRuns: number;
|
|
598
|
-
avgDurationMs: number;
|
|
599
|
-
byTaskType: Record<string, {
|
|
600
|
-
runs: number;
|
|
601
|
-
successRate: number;
|
|
602
|
-
avgDurationMs: number;
|
|
603
|
-
}>;
|
|
604
|
-
byModel: Record<string, {
|
|
605
|
-
runs: number;
|
|
606
|
-
successRate: number;
|
|
607
|
-
avgDurationMs: number;
|
|
608
|
-
}>;
|
|
609
|
-
};
|
|
610
|
-
/**
|
|
611
|
-
* Gets statistics for learning (outcomes joined with runs).
|
|
612
|
-
*/
|
|
613
|
-
getLearningStats(taskType: TaskType): Array<{
|
|
614
|
-
model: string;
|
|
615
|
-
runs: number;
|
|
616
|
-
successRate: number;
|
|
617
|
-
avgDurationMs: number;
|
|
618
|
-
outcomeSuccessRate: number;
|
|
619
|
-
}>;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Routing Engine
|
|
624
|
-
*
|
|
625
|
-
* Manages routing rules and model selection for tasks.
|
|
626
|
-
*
|
|
627
|
-
* @packageDocumentation
|
|
628
|
-
*/
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Routing engine for managing model selection.
|
|
632
|
-
*/
|
|
633
|
-
declare class RoutingEngine {
|
|
634
|
-
private store;
|
|
635
|
-
/**
|
|
636
|
-
* Creates a new RoutingEngine.
|
|
637
|
-
*
|
|
638
|
-
* @param store - The storage instance to use
|
|
639
|
-
*/
|
|
640
|
-
constructor(store: Store);
|
|
641
|
-
/**
|
|
642
|
-
* Infers the task type from a prompt.
|
|
643
|
-
*
|
|
644
|
-
* @param prompt - The prompt to analyze
|
|
645
|
-
* @returns The inferred task type
|
|
646
|
-
*/
|
|
647
|
-
inferTaskType(prompt: string): TaskType;
|
|
648
|
-
/**
|
|
649
|
-
* Gets the inference confidence for a task type.
|
|
650
|
-
*
|
|
651
|
-
* @param prompt - The prompt to analyze
|
|
652
|
-
* @param taskType - The task type to check
|
|
653
|
-
* @returns Confidence score (0-1)
|
|
654
|
-
*/
|
|
655
|
-
getInferenceConfidence(prompt: string, taskType: TaskType): number;
|
|
656
|
-
/**
|
|
657
|
-
* Gets the routing rule for a task type.
|
|
658
|
-
*
|
|
659
|
-
* @param taskType - The task type to get the rule for
|
|
660
|
-
* @returns The routing rule, or null if not found
|
|
661
|
-
*/
|
|
662
|
-
get(taskType: TaskType): RoutingRule | null;
|
|
663
|
-
/**
|
|
664
|
-
* Sets a routing rule for a task type.
|
|
665
|
-
*
|
|
666
|
-
* @param taskType - The task type to set the rule for
|
|
667
|
-
* @param preferredModel - The preferred model (format: "provider:model")
|
|
668
|
-
* @param source - How the rule was created
|
|
669
|
-
* @param options - Optional confidence and sample count
|
|
670
|
-
* @returns The rule ID
|
|
671
|
-
*/
|
|
672
|
-
set(taskType: TaskType, preferredModel: string, source?: RuleSource, options?: {
|
|
673
|
-
confidence?: number;
|
|
674
|
-
sampleCount?: number;
|
|
675
|
-
}): string;
|
|
676
|
-
/**
|
|
677
|
-
* Lists all routing rules.
|
|
678
|
-
*
|
|
679
|
-
* @returns Array of all routing rules
|
|
680
|
-
*/
|
|
681
|
-
list(): RoutingRule[];
|
|
682
|
-
/**
|
|
683
|
-
* Deletes a routing rule and resets to default.
|
|
684
|
-
*
|
|
685
|
-
* @param taskType - The task type to reset
|
|
686
|
-
* @returns True if the rule was reset
|
|
687
|
-
*/
|
|
688
|
-
delete(taskType: TaskType): boolean;
|
|
689
|
-
/**
|
|
690
|
-
* Gets the preferred model for a task type.
|
|
691
|
-
*
|
|
692
|
-
* @param taskType - The task type
|
|
693
|
-
* @returns The preferred model string, or a default
|
|
694
|
-
*/
|
|
695
|
-
getPreferredModel(taskType: TaskType): string;
|
|
696
|
-
/**
|
|
697
|
-
* Parses a model string into provider and model name.
|
|
698
|
-
*
|
|
699
|
-
* @param modelString - The model string (format: "provider:model")
|
|
700
|
-
* @returns Object with provider and model
|
|
701
|
-
*/
|
|
702
|
-
parseModel(modelString: string): {
|
|
703
|
-
provider: string;
|
|
704
|
-
model: string;
|
|
705
|
-
};
|
|
706
|
-
/**
|
|
707
|
-
* Resolves the model to use for a prompt.
|
|
708
|
-
*
|
|
709
|
-
* @param prompt - The prompt to analyze
|
|
710
|
-
* @param overrideTaskType - Optional task type override
|
|
711
|
-
* @param overrideModel - Optional model override
|
|
712
|
-
* @returns Object with resolved taskType, model, provider, and confidence
|
|
713
|
-
*/
|
|
714
|
-
resolve(prompt: string, overrideTaskType?: TaskType, overrideModel?: string): {
|
|
715
|
-
taskType: TaskType;
|
|
716
|
-
model: string;
|
|
717
|
-
provider: string;
|
|
718
|
-
modelName: string;
|
|
719
|
-
confidence: number;
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
* Savings Calculator
|
|
725
|
-
*
|
|
726
|
-
* Calculates cost savings from intelligent model routing vs a baseline (all-Opus).
|
|
727
|
-
*
|
|
728
|
-
* @packageDocumentation
|
|
729
|
-
*/
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* Model pricing in USD per 1M tokens.
|
|
733
|
-
*/
|
|
734
|
-
declare const MODEL_PRICING: Record<string, {
|
|
735
|
-
input: number;
|
|
736
|
-
output: number;
|
|
737
|
-
}>;
|
|
738
|
-
/**
|
|
739
|
-
* Model cost breakdown.
|
|
740
|
-
*/
|
|
741
|
-
interface ModelCostBreakdown {
|
|
742
|
-
runs: number;
|
|
743
|
-
tokensIn: number;
|
|
744
|
-
tokensOut: number;
|
|
745
|
-
cost: number;
|
|
746
|
-
successRate: number;
|
|
747
|
-
avgLatencyMs: number;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Savings report structure.
|
|
751
|
-
*/
|
|
752
|
-
interface SavingsReport {
|
|
753
|
-
/** Number of days included in the report */
|
|
754
|
-
periodDays: number;
|
|
755
|
-
/** Date range */
|
|
756
|
-
period: {
|
|
757
|
-
from: string;
|
|
758
|
-
to: string;
|
|
759
|
-
};
|
|
760
|
-
/** Total number of runs */
|
|
761
|
-
totalRuns: number;
|
|
762
|
-
/** Total tokens used */
|
|
763
|
-
totalTokensIn: number;
|
|
764
|
-
totalTokensOut: number;
|
|
765
|
-
/** Actual cost incurred */
|
|
766
|
-
actualCost: number;
|
|
767
|
-
/** Cost if all calls went to baseline model (Opus) */
|
|
768
|
-
baselineCost: number;
|
|
769
|
-
/** Total savings */
|
|
770
|
-
savings: number;
|
|
771
|
-
/** Savings as percentage */
|
|
772
|
-
savingsPercent: number;
|
|
773
|
-
/** Cost breakdown by model */
|
|
774
|
-
byModel: Record<string, ModelCostBreakdown>;
|
|
775
|
-
/** Cost breakdown by task type */
|
|
776
|
-
byTaskType: Record<string, {
|
|
777
|
-
runs: number;
|
|
778
|
-
cost: number;
|
|
779
|
-
avgCostPerRun: number;
|
|
780
|
-
}>;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Calculate cost for a specific model and token counts.
|
|
784
|
-
*/
|
|
785
|
-
declare function calculateCost(model: string, tokensIn: number, tokensOut: number): number;
|
|
786
|
-
/**
|
|
787
|
-
* Get pricing for a model.
|
|
788
|
-
*/
|
|
789
|
-
declare function getModelPricing(model: string): {
|
|
790
|
-
input: number;
|
|
791
|
-
output: number;
|
|
792
|
-
} | null;
|
|
793
|
-
/**
|
|
794
|
-
* Calculate savings report from stored runs.
|
|
795
|
-
*/
|
|
796
|
-
declare function calculateSavings(store: Store, days?: number): SavingsReport;
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* RelayPlane Main Class
|
|
800
|
-
*
|
|
801
|
-
* The main entry point for the agent optimization layer.
|
|
802
|
-
*
|
|
803
|
-
* @packageDocumentation
|
|
804
|
-
*/
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* RelayPlane - Agent Optimization Layer
|
|
808
|
-
*
|
|
809
|
-
* Provides intelligent routing, outcome tracking, and learning for AI model selection.
|
|
810
|
-
*
|
|
811
|
-
* @example Basic usage
|
|
812
|
-
* ```typescript
|
|
813
|
-
* import { RelayPlane } from '@relayplane/core';
|
|
814
|
-
*
|
|
815
|
-
* const relay = new RelayPlane();
|
|
816
|
-
*
|
|
817
|
-
* // Run a task - automatically infers type and routes to best model
|
|
818
|
-
* const result = await relay.run({
|
|
819
|
-
* prompt: 'Review this code for bugs...',
|
|
820
|
-
* });
|
|
821
|
-
*
|
|
822
|
-
* // Record the outcome for learning
|
|
823
|
-
* await relay.recordOutcome(result.runId, { success: true, quality: 'good' });
|
|
824
|
-
*
|
|
825
|
-
* // Get suggestions for routing improvements
|
|
826
|
-
* const suggestions = await relay.getSuggestions();
|
|
827
|
-
* ```
|
|
828
|
-
*/
|
|
829
|
-
declare class RelayPlane {
|
|
830
|
-
private store;
|
|
831
|
-
private _routing;
|
|
832
|
-
private outcomeRecorder;
|
|
833
|
-
private patternDetector;
|
|
834
|
-
private config;
|
|
835
|
-
private adapterRegistry;
|
|
836
|
-
/**
|
|
837
|
-
* Creates a new RelayPlane instance.
|
|
838
|
-
*
|
|
839
|
-
* @param config - Configuration options
|
|
840
|
-
*/
|
|
841
|
-
constructor(config?: RelayPlaneConfig);
|
|
842
|
-
/**
|
|
843
|
-
* Gets the routing engine for direct access.
|
|
844
|
-
*/
|
|
845
|
-
get routing(): RoutingEngine;
|
|
846
|
-
/**
|
|
847
|
-
* Runs a prompt through the appropriate model.
|
|
848
|
-
*
|
|
849
|
-
* @param input - The run input
|
|
850
|
-
* @returns The run result
|
|
851
|
-
*/
|
|
852
|
-
run(input: RunInput): Promise<RunResult>;
|
|
853
|
-
/**
|
|
854
|
-
* Gets an adapter for a provider.
|
|
855
|
-
* Note: In the standalone proxy package, adapters are not used.
|
|
856
|
-
* The proxy handles provider calls directly via HTTP.
|
|
857
|
-
*/
|
|
858
|
-
private getAdapter;
|
|
859
|
-
/**
|
|
860
|
-
* Gets an API key from environment variables.
|
|
861
|
-
*/
|
|
862
|
-
private getEnvApiKey;
|
|
863
|
-
/**
|
|
864
|
-
* Records an outcome for a run.
|
|
865
|
-
*
|
|
866
|
-
* @param runId - The run ID
|
|
867
|
-
* @param outcome - The outcome details
|
|
868
|
-
* @returns The recorded outcome
|
|
869
|
-
*/
|
|
870
|
-
recordOutcome(runId: string, outcome: Omit<OutcomeInput, 'runId'>): Outcome;
|
|
871
|
-
/**
|
|
872
|
-
* Gets an outcome for a run.
|
|
873
|
-
*
|
|
874
|
-
* @param runId - The run ID
|
|
875
|
-
* @returns The outcome, or null if not found
|
|
876
|
-
*/
|
|
877
|
-
getOutcome(runId: string): Outcome | null;
|
|
878
|
-
/**
|
|
879
|
-
* Gets statistics for runs.
|
|
880
|
-
*
|
|
881
|
-
* @param options - Optional filters
|
|
882
|
-
* @returns Statistics object
|
|
883
|
-
*/
|
|
884
|
-
stats(options?: {
|
|
885
|
-
from?: string;
|
|
886
|
-
to?: string;
|
|
887
|
-
}): Stats;
|
|
888
|
-
/**
|
|
889
|
-
* Gets a savings report.
|
|
890
|
-
*
|
|
891
|
-
* @param days - Number of days to include (default: 30)
|
|
892
|
-
* @returns Savings report
|
|
893
|
-
*/
|
|
894
|
-
savingsReport(days?: number): SavingsReport;
|
|
895
|
-
/**
|
|
896
|
-
* Gets routing improvement suggestions.
|
|
897
|
-
*
|
|
898
|
-
* @returns Array of suggestions
|
|
899
|
-
*/
|
|
900
|
-
getSuggestions(): Suggestion[];
|
|
901
|
-
/**
|
|
902
|
-
* Generates new suggestions based on current data.
|
|
903
|
-
*
|
|
904
|
-
* @returns Array of newly generated suggestions
|
|
905
|
-
*/
|
|
906
|
-
generateSuggestions(): Suggestion[];
|
|
907
|
-
/**
|
|
908
|
-
* Accepts a suggestion and updates routing.
|
|
909
|
-
*
|
|
910
|
-
* @param suggestionId - The suggestion ID to accept
|
|
911
|
-
* @returns True if successful
|
|
912
|
-
*/
|
|
913
|
-
acceptSuggestion(suggestionId: string): boolean;
|
|
914
|
-
/**
|
|
915
|
-
* Rejects a suggestion.
|
|
916
|
-
*
|
|
917
|
-
* @param suggestionId - The suggestion ID to reject
|
|
918
|
-
* @returns True if successful
|
|
919
|
-
*/
|
|
920
|
-
rejectSuggestion(suggestionId: string): boolean;
|
|
921
|
-
/**
|
|
922
|
-
* Closes the RelayPlane instance and releases resources.
|
|
923
|
-
*/
|
|
924
|
-
close(): void;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
/**
|
|
928
|
-
* Pattern Detection
|
|
929
|
-
*
|
|
930
|
-
* Analyzes run history to detect patterns and generate suggestions.
|
|
931
|
-
*
|
|
932
|
-
* @packageDocumentation
|
|
933
|
-
*/
|
|
934
|
-
|
|
935
|
-
/**
|
|
936
|
-
* Pattern detection engine for learning from outcomes.
|
|
937
|
-
*/
|
|
938
|
-
declare class PatternDetector {
|
|
939
|
-
private store;
|
|
940
|
-
/**
|
|
941
|
-
* Creates a new PatternDetector.
|
|
942
|
-
*
|
|
943
|
-
* @param store - The storage instance to use
|
|
944
|
-
*/
|
|
945
|
-
constructor(store: Store);
|
|
946
|
-
/**
|
|
947
|
-
* Analyzes a task type and generates suggestions if appropriate.
|
|
948
|
-
*
|
|
949
|
-
* @param taskType - The task type to analyze
|
|
950
|
-
* @returns Array of suggestions
|
|
951
|
-
*/
|
|
952
|
-
analyzeTaskType(taskType: TaskType): Suggestion[];
|
|
953
|
-
/**
|
|
954
|
-
* Analyzes all task types and generates suggestions.
|
|
955
|
-
*
|
|
956
|
-
* @returns Array of all suggestions across task types
|
|
957
|
-
*/
|
|
958
|
-
analyzeAll(): Suggestion[];
|
|
959
|
-
/**
|
|
960
|
-
* Stores suggestions in the database.
|
|
961
|
-
*
|
|
962
|
-
* @param suggestions - The suggestions to store
|
|
963
|
-
* @returns Array of suggestion IDs
|
|
964
|
-
*/
|
|
965
|
-
storeSuggestions(suggestions: Suggestion[]): string[];
|
|
966
|
-
/**
|
|
967
|
-
* Generates and stores new suggestions, returning only new ones.
|
|
968
|
-
*
|
|
969
|
-
* @returns Array of new suggestions
|
|
970
|
-
*/
|
|
971
|
-
generateSuggestions(): Suggestion[];
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* Outcome Recording
|
|
976
|
-
*
|
|
977
|
-
* Handles recording and processing of run outcomes.
|
|
978
|
-
*
|
|
979
|
-
* @packageDocumentation
|
|
980
|
-
*/
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* Outcome recorder for processing user feedback.
|
|
984
|
-
*/
|
|
985
|
-
declare class OutcomeRecorder {
|
|
986
|
-
private store;
|
|
987
|
-
/**
|
|
988
|
-
* Creates a new OutcomeRecorder.
|
|
989
|
-
*
|
|
990
|
-
* @param store - The storage instance to use
|
|
991
|
-
*/
|
|
992
|
-
constructor(store: Store);
|
|
993
|
-
/**
|
|
994
|
-
* Records an outcome for a run.
|
|
995
|
-
*
|
|
996
|
-
* @param input - The outcome input
|
|
997
|
-
* @returns The recorded outcome
|
|
998
|
-
* @throws If the run ID is not found
|
|
999
|
-
*/
|
|
1000
|
-
record(input: OutcomeInput): Outcome;
|
|
1001
|
-
/**
|
|
1002
|
-
* Gets an outcome for a run.
|
|
1003
|
-
*
|
|
1004
|
-
* @param runId - The run ID
|
|
1005
|
-
* @returns The outcome, or null if not found
|
|
1006
|
-
*/
|
|
1007
|
-
get(runId: string): Outcome | null;
|
|
1008
|
-
/**
|
|
1009
|
-
* Gets outcome statistics for a task type.
|
|
1010
|
-
*
|
|
1011
|
-
* @param taskType - The task type to get stats for
|
|
1012
|
-
* @returns Outcome statistics
|
|
1013
|
-
*/
|
|
1014
|
-
getTaskStats(taskType: string): {
|
|
1015
|
-
totalOutcomes: number;
|
|
1016
|
-
successRate: number;
|
|
1017
|
-
qualityDistribution: Record<string, number>;
|
|
1018
|
-
latencySatisfactionRate: number;
|
|
1019
|
-
costSatisfactionRate: number;
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
/**
|
|
1024
|
-
* Configuration Management
|
|
1025
|
-
*
|
|
1026
|
-
* Handles loading, validation, and hot-reload of the config file.
|
|
1027
|
-
*
|
|
1028
|
-
* @packageDocumentation
|
|
1029
|
-
*/
|
|
1030
|
-
|
|
1031
|
-
/**
|
|
1032
|
-
* Strategy configuration for a task type
|
|
1033
|
-
*/
|
|
1034
|
-
declare const StrategySchema: z.ZodObject<{
|
|
1035
|
-
model: z.ZodString;
|
|
1036
|
-
minConfidence: z.ZodOptional<z.ZodNumber>;
|
|
1037
|
-
fallback: z.ZodOptional<z.ZodString>;
|
|
1038
|
-
}, "strip", z.ZodTypeAny, {
|
|
1039
|
-
model: string;
|
|
1040
|
-
minConfidence?: number | undefined;
|
|
1041
|
-
fallback?: string | undefined;
|
|
1042
|
-
}, {
|
|
1043
|
-
model: string;
|
|
1044
|
-
minConfidence?: number | undefined;
|
|
1045
|
-
fallback?: string | undefined;
|
|
1046
|
-
}>;
|
|
1047
|
-
/**
|
|
1048
|
-
* Full config schema
|
|
1049
|
-
*/
|
|
1050
|
-
declare const ConfigSchema: z.ZodObject<{
|
|
1051
|
-
strategies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1052
|
-
model: z.ZodString;
|
|
1053
|
-
minConfidence: z.ZodOptional<z.ZodNumber>;
|
|
1054
|
-
fallback: z.ZodOptional<z.ZodString>;
|
|
1055
|
-
}, "strip", z.ZodTypeAny, {
|
|
1056
|
-
model: string;
|
|
1057
|
-
minConfidence?: number | undefined;
|
|
1058
|
-
fallback?: string | undefined;
|
|
1059
|
-
}, {
|
|
1060
|
-
model: string;
|
|
1061
|
-
minConfidence?: number | undefined;
|
|
1062
|
-
fallback?: string | undefined;
|
|
1063
|
-
}>>>;
|
|
1064
|
-
defaults: z.ZodOptional<z.ZodObject<{
|
|
1065
|
-
qualityModel: z.ZodOptional<z.ZodString>;
|
|
1066
|
-
costModel: z.ZodOptional<z.ZodString>;
|
|
1067
|
-
}, "strip", z.ZodTypeAny, {
|
|
1068
|
-
qualityModel?: string | undefined;
|
|
1069
|
-
costModel?: string | undefined;
|
|
1070
|
-
}, {
|
|
1071
|
-
qualityModel?: string | undefined;
|
|
1072
|
-
costModel?: string | undefined;
|
|
1073
|
-
}>>;
|
|
1074
|
-
auth: z.ZodOptional<z.ZodObject<{
|
|
1075
|
-
anthropicApiKey: z.ZodOptional<z.ZodString>;
|
|
1076
|
-
anthropicMaxToken: z.ZodOptional<z.ZodString>;
|
|
1077
|
-
useMaxForModels: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1078
|
-
}, "strip", z.ZodTypeAny, {
|
|
1079
|
-
anthropicApiKey?: string | undefined;
|
|
1080
|
-
anthropicMaxToken?: string | undefined;
|
|
1081
|
-
useMaxForModels?: string[] | undefined;
|
|
1082
|
-
}, {
|
|
1083
|
-
anthropicApiKey?: string | undefined;
|
|
1084
|
-
anthropicMaxToken?: string | undefined;
|
|
1085
|
-
useMaxForModels?: string[] | undefined;
|
|
1086
|
-
}>>;
|
|
1087
|
-
}, "strip", z.ZodTypeAny, {
|
|
1088
|
-
strategies?: Record<string, {
|
|
1089
|
-
model: string;
|
|
1090
|
-
minConfidence?: number | undefined;
|
|
1091
|
-
fallback?: string | undefined;
|
|
1092
|
-
}> | undefined;
|
|
1093
|
-
defaults?: {
|
|
1094
|
-
qualityModel?: string | undefined;
|
|
1095
|
-
costModel?: string | undefined;
|
|
1096
|
-
} | undefined;
|
|
1097
|
-
auth?: {
|
|
1098
|
-
anthropicApiKey?: string | undefined;
|
|
1099
|
-
anthropicMaxToken?: string | undefined;
|
|
1100
|
-
useMaxForModels?: string[] | undefined;
|
|
1101
|
-
} | undefined;
|
|
1102
|
-
}, {
|
|
1103
|
-
strategies?: Record<string, {
|
|
1104
|
-
model: string;
|
|
1105
|
-
minConfidence?: number | undefined;
|
|
1106
|
-
fallback?: string | undefined;
|
|
1107
|
-
}> | undefined;
|
|
1108
|
-
defaults?: {
|
|
1109
|
-
qualityModel?: string | undefined;
|
|
1110
|
-
costModel?: string | undefined;
|
|
1111
|
-
} | undefined;
|
|
1112
|
-
auth?: {
|
|
1113
|
-
anthropicApiKey?: string | undefined;
|
|
1114
|
-
anthropicMaxToken?: string | undefined;
|
|
1115
|
-
useMaxForModels?: string[] | undefined;
|
|
1116
|
-
} | undefined;
|
|
1117
|
-
}>;
|
|
1118
|
-
type StrategyConfig = z.infer<typeof StrategySchema>;
|
|
1119
|
-
type Config = z.infer<typeof ConfigSchema>;
|
|
1120
|
-
/**
|
|
1121
|
-
* Default configuration
|
|
1122
|
-
*/
|
|
1123
|
-
declare const DEFAULT_CONFIG: Config;
|
|
1124
|
-
/**
|
|
1125
|
-
* Get config file path
|
|
1126
|
-
*/
|
|
1127
|
-
declare function getConfigPath(): string;
|
|
1128
|
-
/**
|
|
1129
|
-
* Load and validate config
|
|
1130
|
-
*/
|
|
1131
|
-
declare function loadConfig(): Config;
|
|
1132
|
-
/**
|
|
1133
|
-
* Get strategy for a task type from config
|
|
1134
|
-
*/
|
|
1135
|
-
declare function getStrategy(config: Config, taskType: TaskType): StrategyConfig | null;
|
|
1136
|
-
/**
|
|
1137
|
-
* Watch config file for changes
|
|
1138
|
-
*/
|
|
1139
|
-
declare function watchConfig(onChange: (config: Config) => void): void;
|
|
1140
|
-
|
|
1141
|
-
export { type Config, DEFAULT_CONFIG, DEFAULT_ENDPOINTS, MODEL_MAPPING, MODEL_PRICING, type ModelCostBreakdown, type Outcome, type OutcomeQuality, OutcomeRecorder, PatternDetector, type Provider, type ProviderEndpoint, ProviderSchema, Providers, type ProxyConfig, RelayPlane, type RelayPlaneConfig, RoutingEngine, type RoutingRule, type RuleSource, type RunRecord, type SavingsReport, Store, type StrategyConfig, type Suggestion, type TaskType, TaskTypeSchema, TaskTypes, calculateCost, calculateSavings, getConfigPath, getInferenceConfidence, getModelPricing, getStrategy, inferTaskType, loadConfig, startProxy, watchConfig };
|