@tokenbuddy/tokenbuddy 1.0.40 → 1.0.41
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/dist/src/buyer-store.d.ts +22 -0
- package/dist/src/buyer-store.js +46 -7
- package/dist/src/daemon.d.ts +16 -0
- package/dist/src/daemon.js +421 -17
- package/dist/src/provider-install.d.ts +3 -5
- package/dist/src/provider-install.js +33 -425
- package/dist/src/route-failover.js +10 -0
- package/dist/src/seller-pool.d.ts +5 -5
- package/dist/src/seller-pool.js +5 -7
- package/dist/src/seller-route-recommendations.d.ts +110 -0
- package/dist/src/seller-route-recommendations.js +334 -0
- package/package.json +2 -2
- package/static/ui/assets/index-Ca_IcEY6.js +271 -0
- package/static/ui/assets/index-DAq0t0SA.css +1 -0
- package/static/ui/index.html +2 -2
- package/static/ui/assets/index-BAwWDK4H.js +0 -271
- package/static/ui/assets/index-DM9SnAfj.css +0 -1
|
@@ -99,17 +99,28 @@ export interface InferenceLedgerInput {
|
|
|
99
99
|
promptTokens: number;
|
|
100
100
|
completionTokens: number;
|
|
101
101
|
cacheReadTokens?: number;
|
|
102
|
+
cacheWriteTokens?: number;
|
|
103
|
+
reasoningTokens?: number;
|
|
104
|
+
audioInputTokens?: number;
|
|
105
|
+
webSearchCalls?: number;
|
|
102
106
|
billedMicros: number;
|
|
103
107
|
estimatedMicros?: number;
|
|
104
108
|
settledMicros?: number;
|
|
105
109
|
settledUsdMicros?: number;
|
|
110
|
+
pricingCurrency?: string;
|
|
111
|
+
settlementUnit?: string;
|
|
112
|
+
usdToMicrosRate?: number;
|
|
113
|
+
billingSource?: string;
|
|
114
|
+
reportedCostUsdMicros?: number;
|
|
106
115
|
priceVersion?: string;
|
|
107
116
|
inputPriceMicrosPer1m?: number;
|
|
108
117
|
outputPriceMicrosPer1m?: number;
|
|
109
118
|
cacheReadPriceMicrosPer1m?: number;
|
|
119
|
+
cacheWritePriceMicrosPer1m?: number;
|
|
110
120
|
inputCostMicros?: number;
|
|
111
121
|
outputCostMicros?: number;
|
|
112
122
|
cacheReadCostMicros?: number;
|
|
123
|
+
cacheWriteCostMicros?: number;
|
|
113
124
|
originalUsdMicros?: number;
|
|
114
125
|
billingMultiplier?: number;
|
|
115
126
|
serviceTier?: string;
|
|
@@ -147,17 +158,28 @@ export interface SafeInferenceLedgerEntry {
|
|
|
147
158
|
promptTokens: number;
|
|
148
159
|
completionTokens: number;
|
|
149
160
|
cacheReadTokens: number;
|
|
161
|
+
cacheWriteTokens: number;
|
|
162
|
+
reasoningTokens: number;
|
|
163
|
+
audioInputTokens: number;
|
|
164
|
+
webSearchCalls: number;
|
|
150
165
|
billedMicros: number;
|
|
151
166
|
estimatedMicros?: number;
|
|
152
167
|
settledMicros?: number;
|
|
153
168
|
settledUsdMicros?: number;
|
|
169
|
+
pricingCurrency?: string;
|
|
170
|
+
settlementUnit?: string;
|
|
171
|
+
usdToMicrosRate?: number;
|
|
172
|
+
billingSource?: string;
|
|
173
|
+
reportedCostUsdMicros?: number;
|
|
154
174
|
priceVersion?: string;
|
|
155
175
|
inputPriceMicrosPer1m?: number;
|
|
156
176
|
outputPriceMicrosPer1m?: number;
|
|
157
177
|
cacheReadPriceMicrosPer1m?: number;
|
|
178
|
+
cacheWritePriceMicrosPer1m?: number;
|
|
158
179
|
inputCostMicros?: number;
|
|
159
180
|
outputCostMicros?: number;
|
|
160
181
|
cacheReadCostMicros?: number;
|
|
182
|
+
cacheWriteCostMicros?: number;
|
|
161
183
|
originalUsdMicros?: number;
|
|
162
184
|
billingMultiplier?: number;
|
|
163
185
|
serviceTier?: string;
|
package/dist/src/buyer-store.js
CHANGED
|
@@ -283,10 +283,13 @@ export class BuyerStore {
|
|
|
283
283
|
recordInferenceLedger(input) {
|
|
284
284
|
this.db.prepare(`INSERT INTO inference_ledger (
|
|
285
285
|
request_id, seller_key, model_id, endpoint, status, prompt_tokens,
|
|
286
|
-
completion_tokens, cache_read_tokens,
|
|
287
|
-
|
|
286
|
+
completion_tokens, cache_read_tokens, cache_write_tokens, reasoning_tokens,
|
|
287
|
+
audio_input_tokens, web_search_calls, billed_micros, estimated_micros, settled_micros,
|
|
288
|
+
settled_usd_micros, pricing_currency, settlement_unit, usd_to_micros_rate,
|
|
289
|
+
billing_source, reported_cost_usd_micros, price_version,
|
|
288
290
|
input_price_micros_per_1m, output_price_micros_per_1m, cache_read_price_micros_per_1m,
|
|
289
|
-
|
|
291
|
+
cache_write_price_micros_per_1m,
|
|
292
|
+
input_cost_micros, output_cost_micros, cache_read_cost_micros, cache_write_cost_micros,
|
|
290
293
|
original_usd_micros, billing_multiplier, service_tier,
|
|
291
294
|
billing_unit, image_count, image_size, image_quality, image_output_format,
|
|
292
295
|
image_output_tokens, image_output_cost_micros, image_cost_micros_per_image,
|
|
@@ -294,14 +297,17 @@ export class BuyerStore {
|
|
|
294
297
|
prompt_hash, response_hash, created_at,
|
|
295
298
|
ttft_ms, fallback_count, route_reason, fallover_chain_json, upstream_status,
|
|
296
299
|
duration_ms, avg_output_tokens_per_second, payment_method
|
|
297
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.requestId, input.sellerKey, input.modelId, input.endpoint, input.status, input.promptTokens, input.completionTokens, input.cacheReadTokens ?? 0, input.billedMicros, input.estimatedMicros ?? input.billedMicros, input.settledMicros ?? null, input.settledUsdMicros ?? null, input.priceVersion || null, input.inputPriceMicrosPer1m ?? null, input.outputPriceMicrosPer1m ?? null, input.cacheReadPriceMicrosPer1m ?? null, input.inputCostMicros ?? null, input.outputCostMicros ?? null, input.cacheReadCostMicros ?? null, input.originalUsdMicros ?? null, input.billingMultiplier ?? null, input.serviceTier ?? null, input.billingUnit ?? (input.endpoint === "/v1/images/generations" ? "images" : "tokens"), input.imageCount ?? null, input.imageSize ?? null, input.imageQuality ?? null, input.imageOutputFormat ?? null, input.imageOutputTokens ?? null, input.imageOutputCostMicros ?? null, input.imageCostMicrosPerImage ?? null, input.balanceSnapshotMicros ?? null, input.balanceSource || "unknown", safeHash(input.prompt) || null, safeHash(input.response) || null, nowIso(), input.ttftMs ?? null, input.fallbackCount ?? null, input.routeReason ?? null, input.falloverChain ? JSON.stringify(input.falloverChain) : null, input.upstreamStatus ?? null, input.durationMs ?? null, input.avgOutputTokensPerSecond ?? null, input.paymentMethod ?? null);
|
|
300
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.requestId, input.sellerKey, input.modelId, input.endpoint, input.status, input.promptTokens, input.completionTokens, input.cacheReadTokens ?? 0, input.cacheWriteTokens ?? 0, input.reasoningTokens ?? 0, input.audioInputTokens ?? 0, input.webSearchCalls ?? 0, input.billedMicros, input.estimatedMicros ?? input.billedMicros, input.settledMicros ?? null, input.settledUsdMicros ?? null, input.pricingCurrency || null, input.settlementUnit || null, input.usdToMicrosRate ?? null, input.billingSource || null, input.reportedCostUsdMicros ?? null, input.priceVersion || null, input.inputPriceMicrosPer1m ?? null, input.outputPriceMicrosPer1m ?? null, input.cacheReadPriceMicrosPer1m ?? null, input.cacheWritePriceMicrosPer1m ?? null, input.inputCostMicros ?? null, input.outputCostMicros ?? null, input.cacheReadCostMicros ?? null, input.cacheWriteCostMicros ?? null, input.originalUsdMicros ?? null, input.billingMultiplier ?? null, input.serviceTier ?? null, input.billingUnit ?? (input.endpoint === "/v1/images/generations" ? "images" : "tokens"), input.imageCount ?? null, input.imageSize ?? null, input.imageQuality ?? null, input.imageOutputFormat ?? null, input.imageOutputTokens ?? null, input.imageOutputCostMicros ?? null, input.imageCostMicrosPerImage ?? null, input.balanceSnapshotMicros ?? null, input.balanceSource || "unknown", safeHash(input.prompt) || null, safeHash(input.response) || null, nowIso(), input.ttftMs ?? null, input.fallbackCount ?? null, input.routeReason ?? null, input.falloverChain ? JSON.stringify(input.falloverChain) : null, input.upstreamStatus ?? null, input.durationMs ?? null, input.avgOutputTokensPerSecond ?? null, input.paymentMethod ?? null);
|
|
298
301
|
}
|
|
299
302
|
listInferenceLedger() {
|
|
300
303
|
const rows = this.db.prepare(`SELECT request_id, seller_key, model_id, endpoint, status, prompt_tokens,
|
|
301
|
-
completion_tokens, cache_read_tokens,
|
|
302
|
-
|
|
304
|
+
completion_tokens, cache_read_tokens, cache_write_tokens, reasoning_tokens,
|
|
305
|
+
audio_input_tokens, web_search_calls, billed_micros, estimated_micros, settled_micros,
|
|
306
|
+
settled_usd_micros, pricing_currency, settlement_unit, usd_to_micros_rate,
|
|
307
|
+
billing_source, reported_cost_usd_micros, price_version,
|
|
303
308
|
input_price_micros_per_1m, output_price_micros_per_1m, cache_read_price_micros_per_1m,
|
|
304
|
-
|
|
309
|
+
cache_write_price_micros_per_1m,
|
|
310
|
+
input_cost_micros, output_cost_micros, cache_read_cost_micros, cache_write_cost_micros,
|
|
305
311
|
original_usd_micros, billing_multiplier, service_tier,
|
|
306
312
|
billing_unit, image_count, image_size, image_quality, image_output_format,
|
|
307
313
|
image_output_tokens, image_output_cost_micros, image_cost_micros_per_image,
|
|
@@ -320,17 +326,28 @@ export class BuyerStore {
|
|
|
320
326
|
promptTokens: row.prompt_tokens,
|
|
321
327
|
completionTokens: row.completion_tokens,
|
|
322
328
|
cacheReadTokens: row.cache_read_tokens,
|
|
329
|
+
cacheWriteTokens: row.cache_write_tokens,
|
|
330
|
+
reasoningTokens: row.reasoning_tokens,
|
|
331
|
+
audioInputTokens: row.audio_input_tokens,
|
|
332
|
+
webSearchCalls: row.web_search_calls,
|
|
323
333
|
billedMicros: row.billed_micros,
|
|
324
334
|
estimatedMicros: row.estimated_micros ?? undefined,
|
|
325
335
|
settledMicros: row.settled_micros ?? undefined,
|
|
326
336
|
settledUsdMicros: row.settled_usd_micros ?? undefined,
|
|
337
|
+
pricingCurrency: row.pricing_currency || undefined,
|
|
338
|
+
settlementUnit: row.settlement_unit || undefined,
|
|
339
|
+
usdToMicrosRate: row.usd_to_micros_rate ?? undefined,
|
|
340
|
+
billingSource: row.billing_source || undefined,
|
|
341
|
+
reportedCostUsdMicros: row.reported_cost_usd_micros ?? undefined,
|
|
327
342
|
priceVersion: row.price_version || undefined,
|
|
328
343
|
inputPriceMicrosPer1m: row.input_price_micros_per_1m ?? undefined,
|
|
329
344
|
outputPriceMicrosPer1m: row.output_price_micros_per_1m ?? undefined,
|
|
330
345
|
cacheReadPriceMicrosPer1m: row.cache_read_price_micros_per_1m ?? undefined,
|
|
346
|
+
cacheWritePriceMicrosPer1m: row.cache_write_price_micros_per_1m ?? undefined,
|
|
331
347
|
inputCostMicros: row.input_cost_micros ?? undefined,
|
|
332
348
|
outputCostMicros: row.output_cost_micros ?? undefined,
|
|
333
349
|
cacheReadCostMicros: row.cache_read_cost_micros ?? undefined,
|
|
350
|
+
cacheWriteCostMicros: row.cache_write_cost_micros ?? undefined,
|
|
334
351
|
originalUsdMicros: row.original_usd_micros ?? undefined,
|
|
335
352
|
billingMultiplier: row.billing_multiplier ?? undefined,
|
|
336
353
|
serviceTier: row.service_tier || undefined,
|
|
@@ -423,17 +440,28 @@ export class BuyerStore {
|
|
|
423
440
|
prompt_tokens INTEGER NOT NULL,
|
|
424
441
|
completion_tokens INTEGER NOT NULL,
|
|
425
442
|
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
|
|
443
|
+
cache_write_tokens INTEGER NOT NULL DEFAULT 0,
|
|
444
|
+
reasoning_tokens INTEGER NOT NULL DEFAULT 0,
|
|
445
|
+
audio_input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
446
|
+
web_search_calls INTEGER NOT NULL DEFAULT 0,
|
|
426
447
|
billed_micros INTEGER NOT NULL,
|
|
427
448
|
estimated_micros INTEGER,
|
|
428
449
|
settled_micros INTEGER,
|
|
429
450
|
settled_usd_micros INTEGER,
|
|
451
|
+
pricing_currency TEXT,
|
|
452
|
+
settlement_unit TEXT,
|
|
453
|
+
usd_to_micros_rate INTEGER,
|
|
454
|
+
billing_source TEXT,
|
|
455
|
+
reported_cost_usd_micros INTEGER,
|
|
430
456
|
price_version TEXT,
|
|
431
457
|
input_price_micros_per_1m INTEGER,
|
|
432
458
|
output_price_micros_per_1m INTEGER,
|
|
433
459
|
cache_read_price_micros_per_1m INTEGER,
|
|
460
|
+
cache_write_price_micros_per_1m INTEGER,
|
|
434
461
|
input_cost_micros INTEGER,
|
|
435
462
|
output_cost_micros INTEGER,
|
|
436
463
|
cache_read_cost_micros INTEGER,
|
|
464
|
+
cache_write_cost_micros INTEGER,
|
|
437
465
|
original_usd_micros INTEGER,
|
|
438
466
|
billing_multiplier REAL,
|
|
439
467
|
service_tier TEXT,
|
|
@@ -498,15 +526,26 @@ export class BuyerStore {
|
|
|
498
526
|
for (const [column, definition] of [
|
|
499
527
|
["estimated_micros", "INTEGER"],
|
|
500
528
|
["cache_read_tokens", "INTEGER NOT NULL DEFAULT 0"],
|
|
529
|
+
["cache_write_tokens", "INTEGER NOT NULL DEFAULT 0"],
|
|
530
|
+
["reasoning_tokens", "INTEGER NOT NULL DEFAULT 0"],
|
|
531
|
+
["audio_input_tokens", "INTEGER NOT NULL DEFAULT 0"],
|
|
532
|
+
["web_search_calls", "INTEGER NOT NULL DEFAULT 0"],
|
|
501
533
|
["settled_micros", "INTEGER"],
|
|
502
534
|
["settled_usd_micros", "INTEGER"],
|
|
535
|
+
["pricing_currency", "TEXT"],
|
|
536
|
+
["settlement_unit", "TEXT"],
|
|
537
|
+
["usd_to_micros_rate", "INTEGER"],
|
|
538
|
+
["billing_source", "TEXT"],
|
|
539
|
+
["reported_cost_usd_micros", "INTEGER"],
|
|
503
540
|
["price_version", "TEXT"],
|
|
504
541
|
["input_price_micros_per_1m", "INTEGER"],
|
|
505
542
|
["output_price_micros_per_1m", "INTEGER"],
|
|
506
543
|
["cache_read_price_micros_per_1m", "INTEGER"],
|
|
544
|
+
["cache_write_price_micros_per_1m", "INTEGER"],
|
|
507
545
|
["input_cost_micros", "INTEGER"],
|
|
508
546
|
["output_cost_micros", "INTEGER"],
|
|
509
547
|
["cache_read_cost_micros", "INTEGER"],
|
|
548
|
+
["cache_write_cost_micros", "INTEGER"],
|
|
510
549
|
["original_usd_micros", "INTEGER"],
|
|
511
550
|
["billing_multiplier", "REAL"],
|
|
512
551
|
["service_tier", "TEXT"],
|
package/dist/src/daemon.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ClawtipBootstrapPayment, type ParsedClawtipOutput, type WaitForCla
|
|
|
3
3
|
import { type SellerRegistryDocument } from "./seller-catalog.js";
|
|
4
4
|
import { type SellerConcurrencyLimiterOptions } from "./seller-concurrency-limiter.js";
|
|
5
5
|
import type { SellerRoutePlan } from "./seller-route-planner.js";
|
|
6
|
+
import { type RecommendationScope, type SellerRouteRecommendations } from "./seller-route-recommendations.js";
|
|
6
7
|
import { type BuyerSellerRoutingConfig } from "./seller-routing-config.js";
|
|
7
8
|
/**
|
|
8
9
|
* buyer 端守护进程(`tb-proxyd`)的配置。
|
|
@@ -173,6 +174,8 @@ export declare class TokenbuddyDaemon {
|
|
|
173
174
|
* re-purchase.
|
|
174
175
|
*/
|
|
175
176
|
private classifyFailureStatus;
|
|
177
|
+
private classifyRouteException;
|
|
178
|
+
private isBuyerDeadlineError;
|
|
176
179
|
/**
|
|
177
180
|
* Emit the structured failover log line. The decision itself is
|
|
178
181
|
* produced by `RouteFailover.decide`; this helper exists only to keep
|
|
@@ -271,6 +274,19 @@ export declare class TokenbuddyDaemon {
|
|
|
271
274
|
error: string;
|
|
272
275
|
};
|
|
273
276
|
}>;
|
|
277
|
+
buildRoutingRecommendations(input: {
|
|
278
|
+
modelIds?: string[];
|
|
279
|
+
protocol?: string;
|
|
280
|
+
paymentMethod?: string;
|
|
281
|
+
scorer?: BuyerSellerRoutingConfig["scorer"];
|
|
282
|
+
scope?: RecommendationScope;
|
|
283
|
+
topK?: number;
|
|
284
|
+
}): Promise<SellerRouteRecommendations | {
|
|
285
|
+
error: string;
|
|
286
|
+
}>;
|
|
287
|
+
private resolveRecommendationProtocols;
|
|
288
|
+
private resolveRecommendationProtocol;
|
|
289
|
+
private resolveRecommendationFocusSet;
|
|
274
290
|
private runStartupPrewarmSweep;
|
|
275
291
|
private resolvePrewarmProtocol;
|
|
276
292
|
stop(): void;
|