@jeffusion/bungee-core 6.16.2 → 6.18.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/dist/main.js +5691 -2189
- package/dist/observability-worker.js +3257 -1491
- package/dist/plugins/anthropic-request-sanitizer/index.js.map +2 -2
- package/dist/plugins/anthropic-tool-name-transformer/index.js.map +2 -2
- package/dist/plugins/chatgpt-oauth/index.js +37 -15
- package/dist/plugins/chatgpt-oauth/index.js.map +5 -5
- package/dist/plugins/codex-router/index.js +21 -3
- package/dist/plugins/codex-router/index.js.map +5 -5
- package/dist/plugins/deepseek-reasoning-fix/index.js.map +2 -2
- package/dist/plugins/key-access/index.js +1 -1
- package/dist/plugins/key-access/index.js.map +4 -4
- package/dist/plugins/key-access/ingress.js +1 -1
- package/dist/plugins/key-access/ingress.js.map +3 -3
- package/dist/plugins/key-rate-limit/index.js.map +2 -2
- package/dist/plugins/llm-protocol-adapter/control.js +1 -1
- package/dist/plugins/llm-protocol-adapter/control.js.map +3 -3
- package/dist/plugins/llm-protocol-adapter/index.js +1 -1
- package/dist/plugins/llm-protocol-adapter/index.js.map +5 -5
- package/dist/plugins/llm-tps/index.js.map +2 -2
- package/dist/plugins/model-mapping/index.js +1 -1
- package/dist/plugins/model-mapping/index.js.map +4 -4
- package/dist/plugins/models-dev/index.js.map +2 -2
- package/dist/plugins/request-body-redaction/control.js +58 -0
- package/dist/plugins/request-body-redaction/control.js.map +10 -0
- package/dist/plugins/request-body-redaction/index.js +7049 -0
- package/dist/plugins/request-body-redaction/index.js.map +28 -0
- package/dist/plugins/request-body-redaction/manifest.json +83 -0
- package/dist/plugins/request-body-redaction/ui/RedactionRulesEditor.svelte +475 -0
- package/dist/plugins/request-body-redaction/ui/RequestBodyRedactionPage.svelte +674 -0
- package/dist/plugins/request-body-redaction/ui/RequestBodyRedactionStats.svelte +218 -0
- package/dist/plugins/request-body-redaction/ui/route-bindings.ts +69 -0
- package/dist/plugins/request-logs/index.js +505 -118
- package/dist/plugins/request-logs/index.js.map +11 -10
- package/dist/plugins/request-logs/ingress.js +3 -23
- package/dist/plugins/request-logs/ingress.js.map +3 -3
- package/dist/plugins/request-logs/ui/RequestLogsPage.svelte +215 -130
- package/dist/plugins/signature-repair/index.js.map +2 -2
- package/dist/plugins/token-budget/index.js.map +2 -2
- package/dist/plugins/token-metering/index.js.map +2 -2
- package/dist/plugins/token-stats/control.js +111 -40
- package/dist/plugins/token-stats/control.js.map +6 -6
- package/dist/plugins/token-stats/index.js +92 -39
- package/dist/plugins/token-stats/index.js.map +5 -5
- package/dist/plugins/user-auth/index.js.map +2 -2
- package/package.json +3 -2
|
@@ -294,26 +294,66 @@ class SQLiteTokenStatsMetering {
|
|
|
294
294
|
constructor(observation) {
|
|
295
295
|
this.observation = observation;
|
|
296
296
|
}
|
|
297
|
-
async recordAttempt(row) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
297
|
+
async recordAttempt(row, deadlineAt) {
|
|
298
|
+
row = { ...row };
|
|
299
|
+
let remainingMs;
|
|
300
|
+
if (deadlineAt === undefined) {
|
|
301
|
+
const directDeadline = performance.now() + 50;
|
|
302
|
+
remainingMs = () => directDeadline - performance.now();
|
|
303
|
+
} else {
|
|
304
|
+
if (!Number.isSafeInteger(deadlineAt))
|
|
305
|
+
throw new Error("invalid token-stats write deadline");
|
|
306
|
+
const budget = this.observation.writeBudgetMs?.(deadlineAt);
|
|
307
|
+
if (!budget)
|
|
308
|
+
throw new Error("token-stats write deadline clock unavailable");
|
|
309
|
+
remainingMs = budget;
|
|
310
|
+
}
|
|
311
|
+
const requireWriteBudget = () => {
|
|
312
|
+
if (remainingMs() < TOKEN_STATS_BUSY_TIMEOUT_MS)
|
|
313
|
+
throw new Error("token-stats write deadline expired");
|
|
314
|
+
};
|
|
315
|
+
requireWriteBudget();
|
|
316
|
+
const maxAttempts = deadlineAt === undefined ? 8 : Infinity;
|
|
317
|
+
for (let attempt = 1;; attempt++) {
|
|
318
|
+
const busy = await this.observation.withDatabase((db) => {
|
|
319
|
+
validateTokenStatsAttempt(row);
|
|
320
|
+
const transaction = db.transaction(() => {
|
|
321
|
+
if (deadlineAt !== undefined)
|
|
322
|
+
requireWriteBudget();
|
|
323
|
+
db.query(`
|
|
324
|
+
INSERT OR IGNORE INTO token_stats_attempts (
|
|
325
|
+
attempt_id, request_id, finished_at_ms, route_id, upstream_id, provider, outcome, model, key_id,
|
|
326
|
+
input_tokens, output_tokens, input_source, output_source,
|
|
327
|
+
cache_read_tokens, cache_write_tokens, cost_usd, observation_incomplete
|
|
328
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
329
|
+
`).run(row.attempt_id, row.request_id, row.finished_at_ms, row.route_id, row.upstream_id, row.provider, row.outcome, row.model, row.key_id ?? null, row.input_tokens, row.output_tokens, row.input_source, row.output_source, row.cache_read_tokens, row.cache_write_tokens, row.cost_usd, row.observation_incomplete ? 1 : 0);
|
|
330
|
+
db.query(`
|
|
331
|
+
DELETE FROM token_stats_attempts WHERE attempt_id IN (
|
|
332
|
+
SELECT attempt_id FROM token_stats_attempts INDEXED BY idx_token_stats_attempts_finished
|
|
333
|
+
WHERE finished_at_ms < ? ORDER BY finished_at_ms LIMIT 500
|
|
334
|
+
)
|
|
335
|
+
`).run(Date.now() - TOKEN_STATS_RETENTION_MS);
|
|
336
|
+
if (deadlineAt !== undefined)
|
|
337
|
+
requireWriteBudget();
|
|
338
|
+
});
|
|
339
|
+
return withReportingWriteTimeout(db, () => {
|
|
340
|
+
try {
|
|
341
|
+
transaction.immediate();
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (error instanceof Error && error.name === "SQLiteError" && "code" in error && error.code === "SQLITE_BUSY" && db.inTransaction === false)
|
|
344
|
+
return error;
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
314
348
|
});
|
|
315
|
-
|
|
316
|
-
|
|
349
|
+
if (!busy)
|
|
350
|
+
return;
|
|
351
|
+
if (attempt === maxAttempts || remainingMs() < TOKEN_STATS_BUSY_TIMEOUT_MS)
|
|
352
|
+
throw busy;
|
|
353
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
354
|
+
if (remainingMs() < TOKEN_STATS_BUSY_TIMEOUT_MS)
|
|
355
|
+
throw busy;
|
|
356
|
+
}
|
|
317
357
|
}
|
|
318
358
|
async queryPricingModels(input) {
|
|
319
359
|
const window = queryBounds(input);
|
|
@@ -593,13 +633,29 @@ var pendingCount = 0;
|
|
|
593
633
|
var drainTimer;
|
|
594
634
|
var draining = false;
|
|
595
635
|
var lastDropLogAt = 0;
|
|
596
|
-
var lastFailureLogAt =
|
|
597
|
-
function
|
|
636
|
+
var lastFailureLogAt = new Map;
|
|
637
|
+
function failureCode(error) {
|
|
638
|
+
if (error instanceof DOMException && error.name === "TimeoutError")
|
|
639
|
+
return "rpc_timeout";
|
|
640
|
+
if (error instanceof Error && error.name === "DataAdmissionError" && "code" in error) {
|
|
641
|
+
switch (error.code) {
|
|
642
|
+
case "invalid_worker_rpc":
|
|
643
|
+
case "worker_not_admitted":
|
|
644
|
+
case "rpc_busy":
|
|
645
|
+
case "rpc_capacity":
|
|
646
|
+
return error.code;
|
|
647
|
+
default:
|
|
648
|
+
return "rpc_rejected";
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return "unclassified";
|
|
652
|
+
}
|
|
653
|
+
function logRateLimited(logger, stage, error) {
|
|
598
654
|
try {
|
|
599
655
|
logger.onFailure?.();
|
|
600
656
|
} catch {}
|
|
601
657
|
const now = Date.now();
|
|
602
|
-
if (
|
|
658
|
+
if (stage === "drop") {
|
|
603
659
|
if (now - lastDropLogAt < LOG_INTERVAL_MS)
|
|
604
660
|
return;
|
|
605
661
|
lastDropLogAt = now;
|
|
@@ -608,13 +664,12 @@ function logRateLimited(logger, kind, error) {
|
|
|
608
664
|
} catch {}
|
|
609
665
|
return;
|
|
610
666
|
}
|
|
611
|
-
if (now - lastFailureLogAt < LOG_INTERVAL_MS)
|
|
612
|
-
return;
|
|
613
|
-
lastFailureLogAt = now;
|
|
614
667
|
try {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
668
|
+
const failure = `${stage}/${failureCode(error)}`;
|
|
669
|
+
if (now - (lastFailureLogAt.get(failure) ?? 0) < LOG_INTERVAL_MS)
|
|
670
|
+
return;
|
|
671
|
+
lastFailureLogAt.set(failure, now);
|
|
672
|
+
logger.error(`Token stats attempt processing failed; dropping metering row [${failure}]`);
|
|
618
673
|
} catch {}
|
|
619
674
|
}
|
|
620
675
|
function scheduleDrain() {
|
|
@@ -632,17 +687,15 @@ async function drainOneAttempt() {
|
|
|
632
687
|
if (!item)
|
|
633
688
|
return;
|
|
634
689
|
draining = true;
|
|
690
|
+
let stage = "prepare";
|
|
635
691
|
try {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
} catch (error) {
|
|
644
|
-
logRateLimited(item.logger, "failure", error);
|
|
645
|
-
}
|
|
692
|
+
const row = await item.task();
|
|
693
|
+
if (row === undefined)
|
|
694
|
+
return logRateLimited(item.logger, "missing_row");
|
|
695
|
+
stage = "write";
|
|
696
|
+
await item.metering.recordAttempt(row);
|
|
697
|
+
} catch (error) {
|
|
698
|
+
logRateLimited(item.logger, stage, error);
|
|
646
699
|
} finally {
|
|
647
700
|
pendingCount--;
|
|
648
701
|
draining = false;
|
|
@@ -1003,4 +1056,4 @@ export {
|
|
|
1003
1056
|
server_default as default
|
|
1004
1057
|
};
|
|
1005
1058
|
|
|
1006
|
-
//# debugId=
|
|
1059
|
+
//# debugId=E5DE987FFE6B7D0064756E2164756E21
|