@broberg/ai-sdk 0.1.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.
@@ -0,0 +1,1146 @@
1
+ import { z } from 'zod';
2
+
3
+ /** How a call reaches the model. `http` = provider REST API; `subprocess` = local
4
+ * `claude -p` CLI (Max plan, costUsd 0). */
5
+ type Transport = "http" | "subprocess";
6
+ /** Named capability tier. Resolves to a (provider, model, transport) triple via
7
+ * the tier map, overridable per call. */
8
+ type Tier = "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding";
9
+ /** The concrete routing target a Tier (or a per-call override) resolves to. */
10
+ interface TierSpec {
11
+ provider: string;
12
+ model: string;
13
+ transport: Transport;
14
+ }
15
+ /** High-level capability a call exercises. Mirrors the capability layer (F5). */
16
+ type Capability = "chat" | "vision" | "translate" | "image" | "embedding" | "transcribe" | "mockup" | "design" | "extract" | "classify" | "rerank";
17
+ type Role = "system" | "user" | "assistant" | "tool";
18
+ /** A piece of message content. Text everywhere; image parts feed vision. */
19
+ type ContentPart = {
20
+ type: "text";
21
+ text: string;
22
+ } | {
23
+ type: "image";
24
+ image: string | Uint8Array;
25
+ mimeType?: string;
26
+ };
27
+ interface Message {
28
+ role: Role;
29
+ content: string | ContentPart[];
30
+ /** Set on assistant messages that called tools. */
31
+ toolCalls?: ToolCall[];
32
+ /** Set on `tool` role messages — which call this result answers. */
33
+ toolCallId?: string;
34
+ }
35
+ /** SDK-level tool definition. Adapters convert this to each provider's format
36
+ * (F4.5). `parameters` is a JSON Schema object. */
37
+ interface Tool {
38
+ name: string;
39
+ description: string;
40
+ parameters: Record<string, unknown>;
41
+ }
42
+ /** A model's request to invoke a tool, normalized across providers (F4.5). */
43
+ interface ToolCall {
44
+ id: string;
45
+ name: string;
46
+ arguments: Record<string, unknown>;
47
+ }
48
+ /** Per-call usage. Fields mirror the upmetrics `agent_runs` schema 1:1 so the
49
+ * upmetricsSink (F3.7) forwards without re-mapping. `costUsd` is 0 for
50
+ * subprocess (Max plan); `subprocess:true` lets dashboards split free vs paid. */
51
+ interface Usage {
52
+ provider: string;
53
+ model: string;
54
+ tier?: Tier;
55
+ transport: Transport;
56
+ inputTokens: number;
57
+ outputTokens: number;
58
+ cacheReadTokens: number;
59
+ cacheCreationTokens: number;
60
+ costUsd: number;
61
+ toolCalls?: {
62
+ name: string;
63
+ count: number;
64
+ errorCount?: number;
65
+ }[];
66
+ latencyMs: number;
67
+ capability: Capability;
68
+ purpose?: string;
69
+ ts: string;
70
+ subprocess?: true;
71
+ }
72
+ /** A cost reporter. Fans `Usage` out to Upmetrics / Discord / sqlite / etc.
73
+ * Implementations must never throw into the caller (F3.3). */
74
+ interface CostSink {
75
+ record(usage: Usage): void | Promise<void>;
76
+ }
77
+ /** Pre-flight budget ceilings, enforced before a call fires (F3.2). */
78
+ interface BudgetConfig {
79
+ /** Reject a single call whose estimated cost exceeds this many USD. */
80
+ perCallUsd?: number;
81
+ /** Reject once cumulative spend on this client instance exceeds this many USD. */
82
+ rollingUsd?: number;
83
+ }
84
+ /** Per-call options shared by every capability: which tier, optional routing
85
+ * override, optional fallback chain, and a free-text purpose for cost reports. */
86
+ interface CallOptions {
87
+ tier?: Tier;
88
+ /** Override any part of the resolved TierSpec for this call only. */
89
+ override?: Partial<TierSpec>;
90
+ /** Ordered fallbacks tried if the primary route errors (inventory finding:
91
+ * cms/trail/sanne/xrt81 all hand-roll this — make it first-class). */
92
+ fallback?: (Tier | TierSpec)[];
93
+ purpose?: string;
94
+ }
95
+ interface ChatRequest {
96
+ messages: Message[];
97
+ spec: TierSpec;
98
+ tools?: Tool[];
99
+ maxTokens?: number;
100
+ temperature?: number;
101
+ }
102
+ interface ChatResult {
103
+ text: string;
104
+ toolCalls?: ToolCall[];
105
+ usage: Usage;
106
+ }
107
+ interface ImageRequest {
108
+ prompt: string;
109
+ spec: TierSpec;
110
+ width?: number;
111
+ height?: number;
112
+ }
113
+ interface ImageResult {
114
+ url: string;
115
+ usage: Usage;
116
+ }
117
+ interface EmbeddingRequest {
118
+ input: string[];
119
+ spec: TierSpec;
120
+ }
121
+ interface EmbeddingResult {
122
+ vectors: number[][];
123
+ usage: Usage;
124
+ }
125
+ interface TranscribeRequest {
126
+ /** Raw audio bytes (the client resolves a URL to bytes before calling). */
127
+ audio: Uint8Array;
128
+ language?: string;
129
+ spec: TierSpec;
130
+ }
131
+ interface TranscribeResult {
132
+ text: string;
133
+ usage: Usage;
134
+ }
135
+ /** The thin contract every provider implements (F4). A provider need only
136
+ * support the capabilities it offers — `chat` is the baseline; vision/image/
137
+ * embedding are optional and absence is a typed capability gap. */
138
+ interface ProviderAdapter {
139
+ readonly name: string;
140
+ /** Every capability is optional — an adapter implements only what it supports
141
+ * (e.g. fal does image only). The client guards each call and throws a clear
142
+ * "provider X does not support Y" when a capability is absent. */
143
+ chat?(req: ChatRequest): Promise<ChatResult>;
144
+ vision?(req: ChatRequest): Promise<ChatResult>;
145
+ image?(req: ImageRequest): Promise<ImageResult>;
146
+ embedding?(req: EmbeddingRequest): Promise<EmbeddingResult>;
147
+ transcribe?(req: TranscribeRequest): Promise<TranscribeResult>;
148
+ }
149
+ interface TranslateResult {
150
+ text: string;
151
+ usage: Usage;
152
+ }
153
+
154
+ interface MockupInput {
155
+ description: string;
156
+ constraints?: string;
157
+ tier?: Tier;
158
+ purpose?: string;
159
+ }
160
+ interface MockupResult {
161
+ html: string;
162
+ usage: Usage;
163
+ }
164
+ interface DesignInput {
165
+ /** Screenshot URL or raw bytes to iterate on. */
166
+ screenshot: string | Uint8Array;
167
+ instructions: string;
168
+ tier?: Tier;
169
+ purpose?: string;
170
+ }
171
+ interface DesignResult {
172
+ html: string;
173
+ usage: Usage;
174
+ }
175
+ interface ExtractInput<T> {
176
+ text: string;
177
+ /** Zod schema the extracted data must satisfy. */
178
+ schema: z.ZodType<T>;
179
+ instructions?: string;
180
+ tier?: Tier;
181
+ purpose?: string;
182
+ }
183
+ interface ExtractResult<T> {
184
+ data: T;
185
+ usage: Usage;
186
+ }
187
+ interface ClassifyInput {
188
+ text: string;
189
+ labels: string[];
190
+ tier?: Tier;
191
+ purpose?: string;
192
+ }
193
+ interface ClassifyResult {
194
+ label: string;
195
+ confidence: number;
196
+ usage: Usage;
197
+ }
198
+ interface RerankInput {
199
+ query: string;
200
+ items: string[];
201
+ tier?: Tier;
202
+ purpose?: string;
203
+ }
204
+ interface RerankResult {
205
+ ranked: {
206
+ item: string;
207
+ score: number;
208
+ }[];
209
+ usage: Usage;
210
+ }
211
+ interface Contracts {
212
+ mockup(input: MockupInput): Promise<MockupResult>;
213
+ design(input: DesignInput): Promise<DesignResult>;
214
+ extract<T>(input: ExtractInput<T>): Promise<ExtractResult<T>>;
215
+ classify(input: ClassifyInput): Promise<ClassifyResult>;
216
+ rerank(input: RerankInput): Promise<RerankResult>;
217
+ }
218
+
219
+ declare const tierSpecSchema: z.ZodObject<{
220
+ provider: z.ZodString;
221
+ model: z.ZodString;
222
+ transport: z.ZodEnum<["http", "subprocess"]>;
223
+ }, "strip", z.ZodTypeAny, {
224
+ provider: string;
225
+ model: string;
226
+ transport: "http" | "subprocess";
227
+ }, {
228
+ provider: string;
229
+ model: string;
230
+ transport: "http" | "subprocess";
231
+ }>;
232
+ declare const toolSchema: z.ZodObject<{
233
+ name: z.ZodString;
234
+ description: z.ZodString;
235
+ parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
236
+ }, "strip", z.ZodTypeAny, {
237
+ name: string;
238
+ description: string;
239
+ parameters: Record<string, unknown>;
240
+ }, {
241
+ name: string;
242
+ description: string;
243
+ parameters: Record<string, unknown>;
244
+ }>;
245
+ declare const messageSchema: z.ZodObject<{
246
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
247
+ content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodObject<{
248
+ type: z.ZodLiteral<"text">;
249
+ text: z.ZodString;
250
+ }, "strip", z.ZodTypeAny, {
251
+ text: string;
252
+ type: "text";
253
+ }, {
254
+ text: string;
255
+ type: "text";
256
+ }>, z.ZodObject<{
257
+ type: z.ZodLiteral<"image">;
258
+ image: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
259
+ mimeType: z.ZodOptional<z.ZodString>;
260
+ }, "strip", z.ZodTypeAny, {
261
+ image: string | Uint8Array<ArrayBuffer>;
262
+ type: "image";
263
+ mimeType?: string | undefined;
264
+ }, {
265
+ image: string | Uint8Array<ArrayBuffer>;
266
+ type: "image";
267
+ mimeType?: string | undefined;
268
+ }>]>, "many">]>;
269
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
270
+ id: z.ZodString;
271
+ name: z.ZodString;
272
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
273
+ }, "strip", z.ZodTypeAny, {
274
+ id: string;
275
+ name: string;
276
+ arguments: Record<string, unknown>;
277
+ }, {
278
+ id: string;
279
+ name: string;
280
+ arguments: Record<string, unknown>;
281
+ }>, "many">>;
282
+ toolCallId: z.ZodOptional<z.ZodString>;
283
+ }, "strip", z.ZodTypeAny, {
284
+ role: "system" | "user" | "assistant" | "tool";
285
+ content: string | ({
286
+ text: string;
287
+ type: "text";
288
+ } | {
289
+ image: string | Uint8Array<ArrayBuffer>;
290
+ type: "image";
291
+ mimeType?: string | undefined;
292
+ })[];
293
+ toolCalls?: {
294
+ id: string;
295
+ name: string;
296
+ arguments: Record<string, unknown>;
297
+ }[] | undefined;
298
+ toolCallId?: string | undefined;
299
+ }, {
300
+ role: "system" | "user" | "assistant" | "tool";
301
+ content: string | ({
302
+ text: string;
303
+ type: "text";
304
+ } | {
305
+ image: string | Uint8Array<ArrayBuffer>;
306
+ type: "image";
307
+ mimeType?: string | undefined;
308
+ })[];
309
+ toolCalls?: {
310
+ id: string;
311
+ name: string;
312
+ arguments: Record<string, unknown>;
313
+ }[] | undefined;
314
+ toolCallId?: string | undefined;
315
+ }>;
316
+ declare const chatInputSchema: z.ZodObject<{
317
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
318
+ override: z.ZodOptional<z.ZodObject<{
319
+ provider: z.ZodOptional<z.ZodString>;
320
+ model: z.ZodOptional<z.ZodString>;
321
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
322
+ }, "strip", z.ZodTypeAny, {
323
+ provider?: string | undefined;
324
+ model?: string | undefined;
325
+ transport?: "http" | "subprocess" | undefined;
326
+ }, {
327
+ provider?: string | undefined;
328
+ model?: string | undefined;
329
+ transport?: "http" | "subprocess" | undefined;
330
+ }>>;
331
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
332
+ provider: z.ZodString;
333
+ model: z.ZodString;
334
+ transport: z.ZodEnum<["http", "subprocess"]>;
335
+ }, "strip", z.ZodTypeAny, {
336
+ provider: string;
337
+ model: string;
338
+ transport: "http" | "subprocess";
339
+ }, {
340
+ provider: string;
341
+ model: string;
342
+ transport: "http" | "subprocess";
343
+ }>]>, "many">>;
344
+ purpose: z.ZodOptional<z.ZodString>;
345
+ prompt: z.ZodOptional<z.ZodString>;
346
+ messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
347
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
348
+ content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodObject<{
349
+ type: z.ZodLiteral<"text">;
350
+ text: z.ZodString;
351
+ }, "strip", z.ZodTypeAny, {
352
+ text: string;
353
+ type: "text";
354
+ }, {
355
+ text: string;
356
+ type: "text";
357
+ }>, z.ZodObject<{
358
+ type: z.ZodLiteral<"image">;
359
+ image: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
360
+ mimeType: z.ZodOptional<z.ZodString>;
361
+ }, "strip", z.ZodTypeAny, {
362
+ image: string | Uint8Array<ArrayBuffer>;
363
+ type: "image";
364
+ mimeType?: string | undefined;
365
+ }, {
366
+ image: string | Uint8Array<ArrayBuffer>;
367
+ type: "image";
368
+ mimeType?: string | undefined;
369
+ }>]>, "many">]>;
370
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
371
+ id: z.ZodString;
372
+ name: z.ZodString;
373
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
374
+ }, "strip", z.ZodTypeAny, {
375
+ id: string;
376
+ name: string;
377
+ arguments: Record<string, unknown>;
378
+ }, {
379
+ id: string;
380
+ name: string;
381
+ arguments: Record<string, unknown>;
382
+ }>, "many">>;
383
+ toolCallId: z.ZodOptional<z.ZodString>;
384
+ }, "strip", z.ZodTypeAny, {
385
+ role: "system" | "user" | "assistant" | "tool";
386
+ content: string | ({
387
+ text: string;
388
+ type: "text";
389
+ } | {
390
+ image: string | Uint8Array<ArrayBuffer>;
391
+ type: "image";
392
+ mimeType?: string | undefined;
393
+ })[];
394
+ toolCalls?: {
395
+ id: string;
396
+ name: string;
397
+ arguments: Record<string, unknown>;
398
+ }[] | undefined;
399
+ toolCallId?: string | undefined;
400
+ }, {
401
+ role: "system" | "user" | "assistant" | "tool";
402
+ content: string | ({
403
+ text: string;
404
+ type: "text";
405
+ } | {
406
+ image: string | Uint8Array<ArrayBuffer>;
407
+ type: "image";
408
+ mimeType?: string | undefined;
409
+ })[];
410
+ toolCalls?: {
411
+ id: string;
412
+ name: string;
413
+ arguments: Record<string, unknown>;
414
+ }[] | undefined;
415
+ toolCallId?: string | undefined;
416
+ }>, "many">>;
417
+ system: z.ZodOptional<z.ZodString>;
418
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
419
+ name: z.ZodString;
420
+ description: z.ZodString;
421
+ parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
422
+ }, "strip", z.ZodTypeAny, {
423
+ name: string;
424
+ description: string;
425
+ parameters: Record<string, unknown>;
426
+ }, {
427
+ name: string;
428
+ description: string;
429
+ parameters: Record<string, unknown>;
430
+ }>, "many">>;
431
+ maxTokens: z.ZodOptional<z.ZodNumber>;
432
+ temperature: z.ZodOptional<z.ZodNumber>;
433
+ }, "strip", z.ZodTypeAny, {
434
+ system?: string | undefined;
435
+ prompt?: string | undefined;
436
+ messages?: {
437
+ role: "system" | "user" | "assistant" | "tool";
438
+ content: string | ({
439
+ text: string;
440
+ type: "text";
441
+ } | {
442
+ image: string | Uint8Array<ArrayBuffer>;
443
+ type: "image";
444
+ mimeType?: string | undefined;
445
+ })[];
446
+ toolCalls?: {
447
+ id: string;
448
+ name: string;
449
+ arguments: Record<string, unknown>;
450
+ }[] | undefined;
451
+ toolCallId?: string | undefined;
452
+ }[] | undefined;
453
+ tools?: {
454
+ name: string;
455
+ description: string;
456
+ parameters: Record<string, unknown>;
457
+ }[] | undefined;
458
+ temperature?: number | undefined;
459
+ maxTokens?: number | undefined;
460
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
461
+ override?: {
462
+ provider?: string | undefined;
463
+ model?: string | undefined;
464
+ transport?: "http" | "subprocess" | undefined;
465
+ } | undefined;
466
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
467
+ provider: string;
468
+ model: string;
469
+ transport: "http" | "subprocess";
470
+ })[] | undefined;
471
+ purpose?: string | undefined;
472
+ }, {
473
+ system?: string | undefined;
474
+ prompt?: string | undefined;
475
+ messages?: {
476
+ role: "system" | "user" | "assistant" | "tool";
477
+ content: string | ({
478
+ text: string;
479
+ type: "text";
480
+ } | {
481
+ image: string | Uint8Array<ArrayBuffer>;
482
+ type: "image";
483
+ mimeType?: string | undefined;
484
+ })[];
485
+ toolCalls?: {
486
+ id: string;
487
+ name: string;
488
+ arguments: Record<string, unknown>;
489
+ }[] | undefined;
490
+ toolCallId?: string | undefined;
491
+ }[] | undefined;
492
+ tools?: {
493
+ name: string;
494
+ description: string;
495
+ parameters: Record<string, unknown>;
496
+ }[] | undefined;
497
+ temperature?: number | undefined;
498
+ maxTokens?: number | undefined;
499
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
500
+ override?: {
501
+ provider?: string | undefined;
502
+ model?: string | undefined;
503
+ transport?: "http" | "subprocess" | undefined;
504
+ } | undefined;
505
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
506
+ provider: string;
507
+ model: string;
508
+ transport: "http" | "subprocess";
509
+ })[] | undefined;
510
+ purpose?: string | undefined;
511
+ }>;
512
+ declare const visionInputSchema: z.ZodObject<{
513
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
514
+ override: z.ZodOptional<z.ZodObject<{
515
+ provider: z.ZodOptional<z.ZodString>;
516
+ model: z.ZodOptional<z.ZodString>;
517
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
518
+ }, "strip", z.ZodTypeAny, {
519
+ provider?: string | undefined;
520
+ model?: string | undefined;
521
+ transport?: "http" | "subprocess" | undefined;
522
+ }, {
523
+ provider?: string | undefined;
524
+ model?: string | undefined;
525
+ transport?: "http" | "subprocess" | undefined;
526
+ }>>;
527
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
528
+ provider: z.ZodString;
529
+ model: z.ZodString;
530
+ transport: z.ZodEnum<["http", "subprocess"]>;
531
+ }, "strip", z.ZodTypeAny, {
532
+ provider: string;
533
+ model: string;
534
+ transport: "http" | "subprocess";
535
+ }, {
536
+ provider: string;
537
+ model: string;
538
+ transport: "http" | "subprocess";
539
+ }>]>, "many">>;
540
+ purpose: z.ZodOptional<z.ZodString>;
541
+ image: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
542
+ prompt: z.ZodString;
543
+ mimeType: z.ZodOptional<z.ZodString>;
544
+ }, "strip", z.ZodTypeAny, {
545
+ image: string | Uint8Array<ArrayBuffer>;
546
+ prompt: string;
547
+ mimeType?: string | undefined;
548
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
549
+ override?: {
550
+ provider?: string | undefined;
551
+ model?: string | undefined;
552
+ transport?: "http" | "subprocess" | undefined;
553
+ } | undefined;
554
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
555
+ provider: string;
556
+ model: string;
557
+ transport: "http" | "subprocess";
558
+ })[] | undefined;
559
+ purpose?: string | undefined;
560
+ }, {
561
+ image: string | Uint8Array<ArrayBuffer>;
562
+ prompt: string;
563
+ mimeType?: string | undefined;
564
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
565
+ override?: {
566
+ provider?: string | undefined;
567
+ model?: string | undefined;
568
+ transport?: "http" | "subprocess" | undefined;
569
+ } | undefined;
570
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
571
+ provider: string;
572
+ model: string;
573
+ transport: "http" | "subprocess";
574
+ })[] | undefined;
575
+ purpose?: string | undefined;
576
+ }>;
577
+ declare const translateInputSchema: z.ZodObject<{
578
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
579
+ override: z.ZodOptional<z.ZodObject<{
580
+ provider: z.ZodOptional<z.ZodString>;
581
+ model: z.ZodOptional<z.ZodString>;
582
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
583
+ }, "strip", z.ZodTypeAny, {
584
+ provider?: string | undefined;
585
+ model?: string | undefined;
586
+ transport?: "http" | "subprocess" | undefined;
587
+ }, {
588
+ provider?: string | undefined;
589
+ model?: string | undefined;
590
+ transport?: "http" | "subprocess" | undefined;
591
+ }>>;
592
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
593
+ provider: z.ZodString;
594
+ model: z.ZodString;
595
+ transport: z.ZodEnum<["http", "subprocess"]>;
596
+ }, "strip", z.ZodTypeAny, {
597
+ provider: string;
598
+ model: string;
599
+ transport: "http" | "subprocess";
600
+ }, {
601
+ provider: string;
602
+ model: string;
603
+ transport: "http" | "subprocess";
604
+ }>]>, "many">>;
605
+ purpose: z.ZodOptional<z.ZodString>;
606
+ text: z.ZodString;
607
+ to: z.ZodString;
608
+ from: z.ZodOptional<z.ZodString>;
609
+ }, "strip", z.ZodTypeAny, {
610
+ text: string;
611
+ to: string;
612
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
613
+ override?: {
614
+ provider?: string | undefined;
615
+ model?: string | undefined;
616
+ transport?: "http" | "subprocess" | undefined;
617
+ } | undefined;
618
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
619
+ provider: string;
620
+ model: string;
621
+ transport: "http" | "subprocess";
622
+ })[] | undefined;
623
+ purpose?: string | undefined;
624
+ from?: string | undefined;
625
+ }, {
626
+ text: string;
627
+ to: string;
628
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
629
+ override?: {
630
+ provider?: string | undefined;
631
+ model?: string | undefined;
632
+ transport?: "http" | "subprocess" | undefined;
633
+ } | undefined;
634
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
635
+ provider: string;
636
+ model: string;
637
+ transport: "http" | "subprocess";
638
+ })[] | undefined;
639
+ purpose?: string | undefined;
640
+ from?: string | undefined;
641
+ }>;
642
+ declare const imageInputSchema: z.ZodObject<{
643
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
644
+ override: z.ZodOptional<z.ZodObject<{
645
+ provider: z.ZodOptional<z.ZodString>;
646
+ model: z.ZodOptional<z.ZodString>;
647
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
648
+ }, "strip", z.ZodTypeAny, {
649
+ provider?: string | undefined;
650
+ model?: string | undefined;
651
+ transport?: "http" | "subprocess" | undefined;
652
+ }, {
653
+ provider?: string | undefined;
654
+ model?: string | undefined;
655
+ transport?: "http" | "subprocess" | undefined;
656
+ }>>;
657
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
658
+ provider: z.ZodString;
659
+ model: z.ZodString;
660
+ transport: z.ZodEnum<["http", "subprocess"]>;
661
+ }, "strip", z.ZodTypeAny, {
662
+ provider: string;
663
+ model: string;
664
+ transport: "http" | "subprocess";
665
+ }, {
666
+ provider: string;
667
+ model: string;
668
+ transport: "http" | "subprocess";
669
+ }>]>, "many">>;
670
+ purpose: z.ZodOptional<z.ZodString>;
671
+ prompt: z.ZodString;
672
+ width: z.ZodOptional<z.ZodNumber>;
673
+ height: z.ZodOptional<z.ZodNumber>;
674
+ }, "strip", z.ZodTypeAny, {
675
+ prompt: string;
676
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
677
+ override?: {
678
+ provider?: string | undefined;
679
+ model?: string | undefined;
680
+ transport?: "http" | "subprocess" | undefined;
681
+ } | undefined;
682
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
683
+ provider: string;
684
+ model: string;
685
+ transport: "http" | "subprocess";
686
+ })[] | undefined;
687
+ purpose?: string | undefined;
688
+ width?: number | undefined;
689
+ height?: number | undefined;
690
+ }, {
691
+ prompt: string;
692
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
693
+ override?: {
694
+ provider?: string | undefined;
695
+ model?: string | undefined;
696
+ transport?: "http" | "subprocess" | undefined;
697
+ } | undefined;
698
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
699
+ provider: string;
700
+ model: string;
701
+ transport: "http" | "subprocess";
702
+ })[] | undefined;
703
+ purpose?: string | undefined;
704
+ width?: number | undefined;
705
+ height?: number | undefined;
706
+ }>;
707
+ declare const embeddingInputSchema: z.ZodObject<{
708
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
709
+ override: z.ZodOptional<z.ZodObject<{
710
+ provider: z.ZodOptional<z.ZodString>;
711
+ model: z.ZodOptional<z.ZodString>;
712
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
713
+ }, "strip", z.ZodTypeAny, {
714
+ provider?: string | undefined;
715
+ model?: string | undefined;
716
+ transport?: "http" | "subprocess" | undefined;
717
+ }, {
718
+ provider?: string | undefined;
719
+ model?: string | undefined;
720
+ transport?: "http" | "subprocess" | undefined;
721
+ }>>;
722
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
723
+ provider: z.ZodString;
724
+ model: z.ZodString;
725
+ transport: z.ZodEnum<["http", "subprocess"]>;
726
+ }, "strip", z.ZodTypeAny, {
727
+ provider: string;
728
+ model: string;
729
+ transport: "http" | "subprocess";
730
+ }, {
731
+ provider: string;
732
+ model: string;
733
+ transport: "http" | "subprocess";
734
+ }>]>, "many">>;
735
+ purpose: z.ZodOptional<z.ZodString>;
736
+ text: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
737
+ }, "strip", z.ZodTypeAny, {
738
+ text: string | string[];
739
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
740
+ override?: {
741
+ provider?: string | undefined;
742
+ model?: string | undefined;
743
+ transport?: "http" | "subprocess" | undefined;
744
+ } | undefined;
745
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
746
+ provider: string;
747
+ model: string;
748
+ transport: "http" | "subprocess";
749
+ })[] | undefined;
750
+ purpose?: string | undefined;
751
+ }, {
752
+ text: string | string[];
753
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
754
+ override?: {
755
+ provider?: string | undefined;
756
+ model?: string | undefined;
757
+ transport?: "http" | "subprocess" | undefined;
758
+ } | undefined;
759
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
760
+ provider: string;
761
+ model: string;
762
+ transport: "http" | "subprocess";
763
+ })[] | undefined;
764
+ purpose?: string | undefined;
765
+ }>;
766
+ declare const transcribeInputSchema: z.ZodObject<{
767
+ tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>>;
768
+ override: z.ZodOptional<z.ZodObject<{
769
+ provider: z.ZodOptional<z.ZodString>;
770
+ model: z.ZodOptional<z.ZodString>;
771
+ transport: z.ZodOptional<z.ZodEnum<["http", "subprocess"]>>;
772
+ }, "strip", z.ZodTypeAny, {
773
+ provider?: string | undefined;
774
+ model?: string | undefined;
775
+ transport?: "http" | "subprocess" | undefined;
776
+ }, {
777
+ provider?: string | undefined;
778
+ model?: string | undefined;
779
+ transport?: "http" | "subprocess" | undefined;
780
+ }>>;
781
+ fallback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
782
+ provider: z.ZodString;
783
+ model: z.ZodString;
784
+ transport: z.ZodEnum<["http", "subprocess"]>;
785
+ }, "strip", z.ZodTypeAny, {
786
+ provider: string;
787
+ model: string;
788
+ transport: "http" | "subprocess";
789
+ }, {
790
+ provider: string;
791
+ model: string;
792
+ transport: "http" | "subprocess";
793
+ }>]>, "many">>;
794
+ purpose: z.ZodOptional<z.ZodString>;
795
+ /** Audio URL or raw bytes. */
796
+ audio: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
797
+ language: z.ZodOptional<z.ZodString>;
798
+ }, "strip", z.ZodTypeAny, {
799
+ audio: string | Uint8Array<ArrayBuffer>;
800
+ language?: string | undefined;
801
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
802
+ override?: {
803
+ provider?: string | undefined;
804
+ model?: string | undefined;
805
+ transport?: "http" | "subprocess" | undefined;
806
+ } | undefined;
807
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
808
+ provider: string;
809
+ model: string;
810
+ transport: "http" | "subprocess";
811
+ })[] | undefined;
812
+ purpose?: string | undefined;
813
+ }, {
814
+ audio: string | Uint8Array<ArrayBuffer>;
815
+ language?: string | undefined;
816
+ tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | undefined;
817
+ override?: {
818
+ provider?: string | undefined;
819
+ model?: string | undefined;
820
+ transport?: "http" | "subprocess" | undefined;
821
+ } | undefined;
822
+ fallback?: ("fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding" | {
823
+ provider: string;
824
+ model: string;
825
+ transport: "http" | "subprocess";
826
+ })[] | undefined;
827
+ purpose?: string | undefined;
828
+ }>;
829
+ declare const aiConfigSchema: z.ZodObject<{
830
+ defaults: z.ZodOptional<z.ZodRecord<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "embedding"]>, z.ZodObject<{
831
+ provider: z.ZodString;
832
+ model: z.ZodString;
833
+ transport: z.ZodEnum<["http", "subprocess"]>;
834
+ }, "strip", z.ZodTypeAny, {
835
+ provider: string;
836
+ model: string;
837
+ transport: "http" | "subprocess";
838
+ }, {
839
+ provider: string;
840
+ model: string;
841
+ transport: "http" | "subprocess";
842
+ }>>>;
843
+ providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<ProviderAdapter, z.ZodTypeDef, ProviderAdapter>>>;
844
+ costSink: z.ZodOptional<z.ZodType<CostSink, z.ZodTypeDef, CostSink>>;
845
+ budget: z.ZodOptional<z.ZodObject<{
846
+ perCallUsd: z.ZodOptional<z.ZodNumber>;
847
+ rollingUsd: z.ZodOptional<z.ZodNumber>;
848
+ }, "strip", z.ZodTypeAny, {
849
+ perCallUsd?: number | undefined;
850
+ rollingUsd?: number | undefined;
851
+ }, {
852
+ perCallUsd?: number | undefined;
853
+ rollingUsd?: number | undefined;
854
+ }>>;
855
+ }, "strip", z.ZodTypeAny, {
856
+ defaults?: Partial<Record<"fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding", {
857
+ provider: string;
858
+ model: string;
859
+ transport: "http" | "subprocess";
860
+ }>> | undefined;
861
+ providers?: Record<string, ProviderAdapter> | undefined;
862
+ costSink?: CostSink | undefined;
863
+ budget?: {
864
+ perCallUsd?: number | undefined;
865
+ rollingUsd?: number | undefined;
866
+ } | undefined;
867
+ }, {
868
+ defaults?: Partial<Record<"fast" | "smart" | "powerful" | "cheap" | "vision" | "embedding", {
869
+ provider: string;
870
+ model: string;
871
+ transport: "http" | "subprocess";
872
+ }>> | undefined;
873
+ providers?: Record<string, ProviderAdapter> | undefined;
874
+ costSink?: CostSink | undefined;
875
+ budget?: {
876
+ perCallUsd?: number | undefined;
877
+ rollingUsd?: number | undefined;
878
+ } | undefined;
879
+ }>;
880
+ type ChatInput = z.infer<typeof chatInputSchema>;
881
+ type VisionInput = z.infer<typeof visionInputSchema>;
882
+ type TranslateInput = z.infer<typeof translateInputSchema>;
883
+ type ImageInput = z.infer<typeof imageInputSchema>;
884
+ type EmbeddingInput = z.infer<typeof embeddingInputSchema>;
885
+ type TranscribeInput = z.infer<typeof transcribeInputSchema>;
886
+ type AiConfig = z.infer<typeof aiConfigSchema>;
887
+ /** The public facade. Defined here because it depends on the derived inputs. */
888
+ interface AiClient {
889
+ chat(input: ChatInput): Promise<ChatResult>;
890
+ vision(input: VisionInput): Promise<ChatResult>;
891
+ translate(input: TranslateInput): Promise<TranslateResult>;
892
+ image(input: ImageInput): Promise<ImageResult>;
893
+ embedding(input: EmbeddingInput): Promise<EmbeddingResult>;
894
+ transcribe(input: TranscribeInput): Promise<TranscribeResult>;
895
+ /** Prompt-contract capabilities (F5.5) layered on chat/vision. */
896
+ contracts: Contracts;
897
+ }
898
+
899
+ declare function createAI(config?: AiConfig): AiClient;
900
+
901
+ /** Pull the first JSON value out of a model reply (tolerates ```json fences + prose). */
902
+ declare function parseJsonLoose(text: string): unknown;
903
+ type ChatVision = Pick<AiClient, "chat" | "vision">;
904
+ declare function makeContracts(client: ChatVision): Contracts;
905
+
906
+ /** Convert SDK tools to a provider's request format. */
907
+ declare function toProviderTools(tools: Tool[], provider: string): unknown;
908
+ /** Parse a single provider-shaped tool call back into the SDK ToolCall shape. */
909
+ declare function fromProviderToolCall(raw: unknown, provider: string): ToolCall;
910
+
911
+ declare function anthropicAdapter(config?: {
912
+ apiKey?: string;
913
+ baseUrl?: string;
914
+ anthropicVersion?: string;
915
+ }): ProviderAdapter;
916
+
917
+ declare function openaiAdapter(config?: {
918
+ apiKey?: string;
919
+ baseUrl?: string;
920
+ fetch?: typeof fetch;
921
+ }): ProviderAdapter;
922
+
923
+ declare function geminiAdapter(config?: {
924
+ apiKey?: string;
925
+ baseUrl?: string;
926
+ }): ProviderAdapter;
927
+
928
+ declare function deepinfraAdapter(config?: {
929
+ apiKey?: string;
930
+ baseUrl?: string;
931
+ }): ProviderAdapter;
932
+
933
+ declare function openrouterAdapter(config?: {
934
+ apiKey?: string;
935
+ baseUrl?: string;
936
+ referer?: string;
937
+ title?: string;
938
+ }): ProviderAdapter;
939
+
940
+ interface FalAdapterConfig {
941
+ apiKey?: string;
942
+ /** "sync" (default — fal.run, fast models) or "queue" (queue.fal.run, polled). */
943
+ mode?: "sync" | "queue";
944
+ syncBaseUrl?: string;
945
+ queueBaseUrl?: string;
946
+ pollIntervalMs?: number;
947
+ timeoutMs?: number;
948
+ fetch?: typeof fetch;
949
+ }
950
+ declare function falAdapter(config?: FalAdapterConfig): ProviderAdapter;
951
+
952
+ interface OpenAICompatibleConfig {
953
+ /** Provider name recorded on Usage (e.g. "openai", "deepinfra", "openrouter"). */
954
+ name: string;
955
+ /** Chat completions base, e.g. "https://api.openai.com/v1". */
956
+ baseUrl: string;
957
+ /** Resolved at call time if omitted (env var per provider). */
958
+ apiKey?: string;
959
+ /** Extra headers (e.g. OpenRouter's HTTP-Referer / X-Title). */
960
+ extraHeaders?: Record<string, string>;
961
+ }
962
+ declare function makeOpenAICompatibleAdapter(config: OpenAICompatibleConfig): ProviderAdapter;
963
+
964
+ declare const defaultProviders: Record<string, ProviderAdapter>;
965
+
966
+ /** Anthropic adapter stub (HTTP path). */
967
+ declare const anthropicApiAdapter: ProviderAdapter;
968
+ /** Anthropic adapter stub (subprocess / `claude -p` path). */
969
+ declare const anthropicSubprocessAdapter: ProviderAdapter;
970
+ /** OpenAI adapter stub — covers the embedding default tier + a chat fallback. */
971
+ declare const openaiStubAdapter: ProviderAdapter;
972
+ /** fal.ai adapter stub — image generation (real one in fal.ts, F5.3). */
973
+ declare const falStubAdapter: ProviderAdapter;
974
+ /** Stub provider registry — deterministic, no network. Used by tests via
975
+ * createAI({ providers: stubProviders }). The real default registry (registry.ts)
976
+ * wires the live adapters. */
977
+ declare const stubProviders: Record<string, ProviderAdapter>;
978
+
979
+ declare const VERSION: "0.1.0";
980
+ declare const SDK_TAG: "@broberg/ai-sdk@0.1.0";
981
+
982
+ /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
983
+ * per-call override. Model IDs are current at scaffold time; callers pin their
984
+ * own via config. `cheap` routes through the local `claude -p` subprocess
985
+ * (Max plan → costUsd 0); everything else is HTTP. */
986
+ declare const DEFAULT_TIER_MAP: Record<Tier, TierSpec>;
987
+ /**
988
+ * Resolve a Tier to a concrete TierSpec.
989
+ *
990
+ * Merge order (later wins): DEFAULT_TIER_MAP < configMap < override.
991
+ * - `configMap` is the client-level AiConfig.defaults (per-tier full specs).
992
+ * - `override` is a per-call Partial<TierSpec> — only the fields it sets win.
993
+ */
994
+ declare function resolveTier(tier: Tier, override?: Partial<TierSpec>, configMap?: Partial<Record<Tier, TierSpec>>): TierSpec;
995
+
996
+ /**
997
+ * Cost in USD for a call. cache-read/creation tokens are priced separately when
998
+ * the pricing entry defines rates for them; otherwise they fall back to the
999
+ * input rate (read) / are ignored (creation). Unknown model → 0.
1000
+ */
1001
+ declare function computeCost(provider: string, model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheCreationTokens?: number): number;
1002
+ /** Build a Usage with cost computed from the pricing table. Adapters call this
1003
+ * after a successful provider call; latencyMs/ts/capability are stamped by the
1004
+ * client (call-context owner), so they default to 0/""/the passed capability. */
1005
+ declare function freshUsage(args: {
1006
+ provider: string;
1007
+ model: string;
1008
+ transport: Transport;
1009
+ capability: Capability;
1010
+ inputTokens: number;
1011
+ outputTokens: number;
1012
+ cacheReadTokens?: number;
1013
+ cacheCreationTokens?: number;
1014
+ subprocess?: boolean;
1015
+ }): Usage;
1016
+
1017
+ declare class BudgetExceededError extends Error {
1018
+ readonly kind: "per-call" | "rolling";
1019
+ readonly limit: number;
1020
+ readonly spent: number;
1021
+ readonly requested: number;
1022
+ constructor(kind: "per-call" | "rolling", limit: number, spent: number, requested: number);
1023
+ }
1024
+ declare class BudgetGuard {
1025
+ private readonly config;
1026
+ private spentUsd;
1027
+ constructor(config: BudgetConfig);
1028
+ /** Throws BudgetExceededError if `requested` would breach the per-call ceiling
1029
+ * or push the rolling total past its ceiling. Call before firing the request. */
1030
+ check(requested: number): void;
1031
+ /** Add an actual cost to the running total (after a successful call). */
1032
+ record(actual: number): void;
1033
+ get totalSpent(): number;
1034
+ }
1035
+
1036
+ /** A sink that does nothing. The default when no costSink is configured. */
1037
+ declare const noopSink: CostSink;
1038
+
1039
+ /** Fan a Usage out to several sinks. Uses allSettled so one failing sink never
1040
+ * prevents the others from recording (and never propagates to the caller). */
1041
+ declare function multiSink(sinks: CostSink[]): CostSink;
1042
+
1043
+ interface UpmetricsSinkConfig {
1044
+ /** Ingest base URL, e.g. https://upmetrics.org */
1045
+ baseUrl: string;
1046
+ /** Per-project api_key → sent as the X-Upmetrics-Key header. */
1047
+ apiKey: string;
1048
+ /** Consumer name dashboards group by (e.g. "cms", "trail", "xrt81") — NOT the
1049
+ * capability. */
1050
+ agentName: string;
1051
+ /** Defaults to "chatbot" ("embedding" auto-selected for embedding calls). */
1052
+ agentKind?: string;
1053
+ /** When true, guarantees no prompt/response content is ever sent (the sink
1054
+ * sends none regardless — Usage carries no excerpts — so this is belt-and-
1055
+ * suspenders for GDPR-health projects). */
1056
+ complianceMode?: boolean;
1057
+ /** Injectable fetch for testing; defaults to global fetch. */
1058
+ fetch?: typeof fetch;
1059
+ /** Optional error hook (errors are otherwise swallowed silently). */
1060
+ onError?: (err: unknown) => void;
1061
+ }
1062
+ declare function upmetricsSink(config: UpmetricsSinkConfig): CostSink;
1063
+
1064
+ interface DiscordSinkConfig {
1065
+ webhookUrl: string;
1066
+ /** Skip posting paid calls below this USD threshold (anti-spam). Subprocess
1067
+ * (Max-plan free) calls always post so the "free" feed stays visible.
1068
+ * Default 0 → post everything. */
1069
+ minUsd?: number;
1070
+ fetch?: typeof fetch;
1071
+ onError?: (err: unknown) => void;
1072
+ }
1073
+ declare function discordSink(config: DiscordSinkConfig): CostSink;
1074
+
1075
+ interface SqliteSinkConfig {
1076
+ /** Path to the SQLite file, e.g. "./ai-cost.db" (or ":memory:"). */
1077
+ dbPath: string;
1078
+ }
1079
+ declare function sqliteSink(config: SqliteSinkConfig): CostSink;
1080
+ interface CostSummary {
1081
+ totalUsd: number;
1082
+ byProvider: Record<string, number>;
1083
+ byCapability: Record<string, number>;
1084
+ }
1085
+ /** Aggregate the recorded spend from a sqliteSink DB. */
1086
+ declare function getCostSummary(dbPath: string): CostSummary;
1087
+
1088
+ interface PricingEntry {
1089
+ /** USD per 1M input tokens. */
1090
+ inputPer1M: number;
1091
+ /** USD per 1M output tokens. */
1092
+ outputPer1M: number;
1093
+ /** USD per 1M cache-read tokens (falls back to input rate if unset). */
1094
+ cacheReadPer1M?: number;
1095
+ /** USD per 1M cache-write/creation tokens (falls back to input rate if unset). */
1096
+ cacheWritePer1M?: number;
1097
+ /** Pricing snapshot version (date or tag) so stale entries are detectable. */
1098
+ version: string;
1099
+ }
1100
+ declare function getPrice(provider: string, model: string): PricingEntry | undefined;
1101
+
1102
+ interface TransportRequest {
1103
+ /** Resolved routing for this call (transport field selects the path). */
1104
+ spec: TierSpec;
1105
+ /** HTTP details — required when spec.transport === "http". The adapter has
1106
+ * already built the provider-specific URL/headers/body. */
1107
+ http?: {
1108
+ url: string;
1109
+ method?: string;
1110
+ headers?: Record<string, string>;
1111
+ body?: unknown;
1112
+ };
1113
+ /** Subprocess details — required when spec.transport === "subprocess". */
1114
+ subprocess?: {
1115
+ prompt: string;
1116
+ systemPrompt?: string;
1117
+ };
1118
+ }
1119
+ /** HTTP transport result — raw, unparsed. The adapter reads text + token usage
1120
+ * out of `json` (shapes differ per provider). */
1121
+ interface HttpResponse {
1122
+ ok: boolean;
1123
+ status: number;
1124
+ json: unknown;
1125
+ }
1126
+ /** Subprocess transport result — already normalized from the `claude -p` JSON.
1127
+ * costUsd is always 0 (Max plan is not a metered charge); subprocess flags it. */
1128
+ interface SubprocessResponse {
1129
+ text: string;
1130
+ inputTokens: number;
1131
+ outputTokens: number;
1132
+ cacheReadTokens: number;
1133
+ cacheCreationTokens: number;
1134
+ costUsd: 0;
1135
+ subprocess: true;
1136
+ }
1137
+ type TransportResponse = HttpResponse | SubprocessResponse;
1138
+
1139
+ declare function httpTransport(req: TransportRequest): Promise<HttpResponse>;
1140
+
1141
+ /** Pure parser for the `claude -p --output-format json` stdout. Exported so it
1142
+ * can be unit-tested without spawning the binary. costUsd is pinned to 0. */
1143
+ declare function parseClaudeCliJson(raw: string): SubprocessResponse;
1144
+ declare function subprocessTransport(req: TransportRequest): Promise<SubprocessResponse>;
1145
+
1146
+ export { type AiClient, type AiConfig, type BudgetConfig, BudgetExceededError, BudgetGuard, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostSink, type CostSummary, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type Message, type MockupInput, type MockupResult, type OpenAICompatibleConfig, type PricingEntry, type ProviderAdapter, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteSinkConfig, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type UpmetricsSinkConfig, type Usage, VERSION, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, makeContracts, makeOpenAICompatibleAdapter, messageSchema, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, resolveTier, sqliteSink, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsSink, visionInputSchema };