@jeffusion/bungee-core 6.12.0 → 6.13.1

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.
Files changed (29) hide show
  1. package/dist/config-storage-worker.js +142 -7
  2. package/dist/gateway/plugin.js +3 -1
  3. package/dist/main.js +3531 -3089
  4. package/dist/observability-worker.js +948 -175
  5. package/dist/plugins/anthropic-request-sanitizer/index.js.map +2 -2
  6. package/dist/plugins/anthropic-tool-name-transformer/index.js.map +2 -2
  7. package/dist/plugins/chatgpt-oauth/index.js.map +2 -2
  8. package/dist/plugins/codex-router/index.js.map +2 -2
  9. package/dist/plugins/deepseek-reasoning-fix/index.js.map +2 -2
  10. package/dist/plugins/key-access/index.js.map +2 -2
  11. package/dist/plugins/key-rate-limit/index.js.map +2 -2
  12. package/dist/plugins/llm-protocol-adapter/index.js +4 -2
  13. package/dist/plugins/llm-protocol-adapter/index.js.map +4 -4
  14. package/dist/plugins/llm-tps/index.js.map +2 -2
  15. package/dist/plugins/model-mapping/index.js.map +2 -2
  16. package/dist/plugins/models-dev/index.js.map +2 -2
  17. package/dist/plugins/request-logs/index.js +1392 -0
  18. package/dist/plugins/request-logs/index.js.map +33 -0
  19. package/dist/plugins/request-logs/ingress.js +28 -0
  20. package/dist/plugins/request-logs/ingress.js.map +10 -0
  21. package/dist/plugins/request-logs/manifest.json +68 -0
  22. package/dist/plugins/request-logs/ui/RequestLogsPage.svelte +1130 -0
  23. package/dist/plugins/request-logs/ui/RequestLogsSettings.svelte +111 -0
  24. package/dist/plugins/signature-repair/index.js.map +2 -2
  25. package/dist/plugins/token-budget/index.js.map +2 -2
  26. package/dist/plugins/token-metering/index.js.map +2 -2
  27. package/dist/plugins/token-stats/index.js.map +2 -2
  28. package/dist/plugins/user-auth/index.js.map +2 -2
  29. package/package.json +2 -2
@@ -481,7 +481,9 @@ function hashConfigurationRequest(identity) {
481
481
 
482
482
  // ../types/src/daemon-control.ts
483
483
  var DAEMON_METADATA_MAX_BYTES = 4 * 1024;
484
+
484
485
  // ../types/src/types.ts
486
+ var DEFAULT_BODY_LOG_MAX_BYTES = 64 * 1024;
485
487
  var DEFAULT_WEBSOCKET_MAX_MESSAGE_BYTES = 16 * 1024 * 1024;
486
488
  var MAX_WEBSOCKET_MAX_MESSAGE_BYTES = 2147483647;
487
489
  // ../types/src/rate-limit.ts
@@ -8409,7 +8411,9 @@ function readAllWorkers(db) {
8409
8411
 
8410
8412
  // src/config-storage/worker-launch-store.ts
8411
8413
  var INTENT_SELECT = `SELECT worker_instance_id,master_generation,worker_slot,
8412
- allocation_mutation_id,allocation_worker_slot,allocation_attempt_no,guard_json,registered_at
8414
+ allocation_mutation_id,allocation_worker_slot,allocation_attempt_no,guard_json,registered_at,
8415
+ EXISTS (SELECT 1 FROM configuration_worker_launch_capacity_reclaims reclaim
8416
+ WHERE reclaim.worker_instance_id=configuration_worker_launch_intents.worker_instance_id) AS capacity_reclaimed
8413
8417
  FROM configuration_worker_launch_intents`;
8414
8418
  function invalid3(message) {
8415
8419
  throw new ConfigRepositoryError("invalid_command", message);
@@ -8509,6 +8513,10 @@ function launchFromRow(db, row) {
8509
8513
  throw new ConfigRepositoryError("schema_corrupt", "worker launch guard identity is invalid");
8510
8514
  }
8511
8515
  const facts = readFacts(db, row.worker_instance_id, allocation);
8516
+ const capacityReclaimed = row.capacity_reclaimed === 1;
8517
+ if (capacityReclaimed && (!facts.admitted || !facts.exited || facts.not_started)) {
8518
+ throw new ConfigRepositoryError("schema_corrupt", "worker launch capacity reclaim has no admitted exit");
8519
+ }
8512
8520
  return Object.freeze({
8513
8521
  identity: Object.freeze({
8514
8522
  master_generation: row.master_generation,
@@ -8521,7 +8529,8 @@ function launchFromRow(db, row) {
8521
8529
  admitted: facts.admitted,
8522
8530
  not_started: facts.not_started,
8523
8531
  exited: facts.exited,
8524
- cleanup_released: facts.cleanup_released
8532
+ cleanup_released: facts.cleanup_released,
8533
+ capacity_reclaimed: capacityReclaimed
8525
8534
  });
8526
8535
  }
8527
8536
  function requireIntentRow(db, workerInstanceId) {
@@ -8715,6 +8724,19 @@ function readWorkerLaunch(db, workerInstanceId) {
8715
8724
  const row = sqliteGet(db, `${INTENT_SELECT} WHERE worker_instance_id=?`, workerInstanceId);
8716
8725
  return row === null ? null : launchFromRow(db, row);
8717
8726
  }
8727
+ function recordWorkerLaunchCapacityReclaimed(db, workerInstanceId, guard, updatedAt) {
8728
+ const row = requireIntentRow(db, workerInstanceId);
8729
+ const launch = launchFromRow(db, row);
8730
+ if (canonicalJson(parseInputGuard(guard, launch.identity)) !== canonicalJson(launch.guard))
8731
+ invalidOperation("worker launch capacity guard does not match");
8732
+ if (launch.capacity_reclaimed)
8733
+ return;
8734
+ if (!launch.admitted || !launch.exited || launch.not_started || launch.cleanup_released) {
8735
+ invalidOperation("worker launch capacity reclaim requires admitted exit without successful cleanup");
8736
+ }
8737
+ requireTimestamp(updatedAt, Math.max(launch.registered_at, readFacts(db, workerInstanceId, launch.allocation).last_recorded_at));
8738
+ db.run("INSERT INTO configuration_worker_launch_capacity_reclaims (worker_instance_id,recorded_at) VALUES (?,?)", [workerInstanceId, updatedAt]);
8739
+ }
8718
8740
  function readWorkerLaunchAllocationFacts(db, allocation) {
8719
8741
  validateAllocationInput(allocation);
8720
8742
  const intent = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
@@ -11153,8 +11175,40 @@ var PUBLICATION_TARGET_MIGRATION = {
11153
11175
  }
11154
11176
  };
11155
11177
 
11178
+ // src/config-storage/migrations/request-logs-default.ts
11179
+ var REQUEST_LOGS_DEFAULT_MIGRATION = {
11180
+ version: 9,
11181
+ name: "request_logs_default",
11182
+ up(db) {
11183
+ db.run(`CREATE TABLE configuration_request_logs_default (
11184
+ id INTEGER PRIMARY KEY CHECK(id=1),
11185
+ settled_revision INTEGER NOT NULL REFERENCES configuration_revisions(revision)
11186
+ ) STRICT, WITHOUT ROWID`);
11187
+ }
11188
+ };
11189
+
11190
+ // src/config-storage/migrations/worker-launch-capacity.ts
11191
+ var WORKER_LAUNCH_CAPACITY_MIGRATION = {
11192
+ version: 10,
11193
+ name: "worker_launch_capacity",
11194
+ up(db) {
11195
+ db.run(`CREATE TABLE configuration_worker_launch_capacity_reclaims (
11196
+ worker_instance_id TEXT PRIMARY KEY REFERENCES configuration_worker_launch_intents(worker_instance_id),
11197
+ recorded_at INTEGER NOT NULL CHECK(recorded_at >= 0 AND recorded_at <= 9007199254740991)
11198
+ ) STRICT, WITHOUT ROWID`);
11199
+ db.run(`CREATE TRIGGER configuration_worker_launch_capacity_reclaims_guard BEFORE INSERT ON configuration_worker_launch_capacity_reclaims
11200
+ WHEN EXISTS (SELECT 1 FROM configuration_worker_launch_capacity_reclaims WHERE worker_instance_id=NEW.worker_instance_id)
11201
+ OR NOT EXISTS (SELECT 1 FROM configuration_worker_launch_facts WHERE worker_instance_id=NEW.worker_instance_id AND kind='admitted' AND recorded_at<=NEW.recorded_at)
11202
+ OR NOT EXISTS (SELECT 1 FROM configuration_worker_launch_facts WHERE worker_instance_id=NEW.worker_instance_id AND kind='exited' AND recorded_at<=NEW.recorded_at)
11203
+ OR EXISTS (SELECT 1 FROM configuration_worker_launch_facts WHERE worker_instance_id=NEW.worker_instance_id AND kind IN ('not_started','cleanup'))
11204
+ BEGIN SELECT RAISE(ABORT,'worker launch capacity reclaim requires a new admitted exit without successful cleanup'); END`);
11205
+ db.run("CREATE TRIGGER configuration_worker_launch_capacity_reclaims_no_delete BEFORE DELETE ON configuration_worker_launch_capacity_reclaims BEGIN SELECT RAISE(ABORT,'worker launch capacity reclaim is immutable'); END");
11206
+ db.run("CREATE TRIGGER configuration_worker_launch_capacity_reclaims_no_update BEFORE UPDATE ON configuration_worker_launch_capacity_reclaims BEGIN SELECT RAISE(ABORT,'worker launch capacity reclaim is immutable'); END");
11207
+ }
11208
+ };
11209
+
11156
11210
  // src/config-storage/migrations/plan.ts
11157
- var CONFIG_MIGRATIONS = [CONFIG_BASELINE, PUBLICATION_RETIREMENT_MIGRATION, UI_MENUS_MIGRATION, MANAGEMENT_PROTECTION_MIGRATION, SERVICE_REFERENCES_MIGRATION, WEBSOCKET_CONNECTIONS_MIGRATION, WEBSOCKET_MESSAGE_SIZE_MIGRATION, PUBLICATION_TARGET_MIGRATION];
11211
+ var CONFIG_MIGRATIONS = [CONFIG_BASELINE, PUBLICATION_RETIREMENT_MIGRATION, UI_MENUS_MIGRATION, MANAGEMENT_PROTECTION_MIGRATION, SERVICE_REFERENCES_MIGRATION, WEBSOCKET_CONNECTIONS_MIGRATION, WEBSOCKET_MESSAGE_SIZE_MIGRATION, PUBLICATION_TARGET_MIGRATION, REQUEST_LOGS_DEFAULT_MIGRATION, WORKER_LAUNCH_CAPACITY_MIGRATION];
11158
11212
  var CONFIG_SCHEMA_VERSION = CONFIG_MIGRATIONS.at(-1).version;
11159
11213
 
11160
11214
  // src/config-storage/schema-fingerprint.ts
@@ -11320,6 +11374,74 @@ function convertServiceReferenceRevision(db, options) {
11320
11374
  readRepositorySnapshot(db);
11321
11375
  }
11322
11376
 
11377
+ // src/config-storage/request-logs-default.ts
11378
+ import { randomUUID as randomUUID3 } from "crypto";
11379
+ var PLUGIN = "request-logs";
11380
+ function settleRequestLogsDefault(db, options, revision) {
11381
+ if (!options.compileOptions?.availablePlugins?.has(PLUGIN))
11382
+ return;
11383
+ db.run(`INSERT INTO configuration_request_logs_default (id,settled_revision) VALUES(1,?)
11384
+ ON CONFLICT(id) DO NOTHING`, [revision]);
11385
+ }
11386
+ function applyRequestLogsDefault(db, options, targetWorkerSlots) {
11387
+ if (!options.compileOptions?.availablePlugins?.has(PLUGIN))
11388
+ return false;
11389
+ const state = sqliteGet(db, `SELECT updated_at FROM configuration_state WHERE id=1
11390
+ AND NOT EXISTS (SELECT 1 FROM configuration_request_logs_default WHERE id=1)`);
11391
+ if (state === null)
11392
+ return false;
11393
+ verifyRepositoryIntegrity(db);
11394
+ const snapshot = readRepositorySnapshot(db);
11395
+ let settledRevision = snapshot.revision;
11396
+ if (!snapshot.aggregate.plugin_activations.some((activation) => activation.plugin_name === PLUGIN)) {
11397
+ const unfinished = sqliteGet(db, `SELECT 1 AS unfinished FROM configuration_operations
11398
+ WHERE state IN ('committed','publishing','draining') OR (state='pending' AND committed_revision=(
11399
+ SELECT active_revision FROM configuration_state WHERE id=1))
11400
+ UNION ALL SELECT 1 FROM configuration_retirements WHERE state<>'released'
11401
+ UNION ALL SELECT 1 FROM configuration_recoveries WHERE state='stopped' AND recovery_sequence=(
11402
+ SELECT max(recovery_sequence) FROM configuration_recoveries WHERE target_revision=(
11403
+ SELECT active_revision FROM configuration_state WHERE id=1))
11404
+ LIMIT 1`);
11405
+ if (unfinished !== null || readPublicationRecoveryBarrier(db) !== null || readUnsettledWorkerLaunches(db).length > 0)
11406
+ return false;
11407
+ const aggregate = {
11408
+ ...snapshot.aggregate,
11409
+ plugin_activations: [...snapshot.aggregate.plugin_activations, { plugin_name: PLUGIN }]
11410
+ };
11411
+ const operationId = randomUUID3();
11412
+ const now = Math.max(Date.now(), state.updated_at);
11413
+ const prepared = prepareCommitCommand({
11414
+ mutation_id: operationId,
11415
+ expected_revision: snapshot.revision,
11416
+ aggregate,
11417
+ kind: "config",
11418
+ created_at: now,
11419
+ target_worker_slots: targetWorkerSlots ?? []
11420
+ });
11421
+ const provider = readManagementProtection(db).selectedProvider;
11422
+ const command = {
11423
+ ...prepared,
11424
+ managementProvider: provider,
11425
+ requestHash: hashConfigurationRequest({
11426
+ kind: prepared.kind,
11427
+ expected_revision: prepared.expectedRevision,
11428
+ aggregate: prepared.aggregate,
11429
+ target_worker_slots: prepared.targetSlots,
11430
+ management_provider: provider
11431
+ })
11432
+ };
11433
+ const result = commitTransaction(db, command, options, snapshot);
11434
+ if (result.kind !== "committed") {
11435
+ throw new ConfigRepositoryError("migration_failed", `request logs activation revision commit failed (${result.kind})`);
11436
+ }
11437
+ if (targetWorkerSlots === undefined)
11438
+ finalizeOfflineOperation(db, operationId, now);
11439
+ settledRevision = readRepositorySnapshot(db).revision;
11440
+ }
11441
+ settleRequestLogsDefault(db, options, settledRevision);
11442
+ return settledRevision !== snapshot.revision;
11443
+ }
11444
+
11323
11445
  // src/config-storage/migrations/index.ts
11324
11446
  function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}) {
11325
11447
  if (db.inTransaction)
@@ -11348,6 +11470,8 @@ function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}
11348
11470
  if (plan === CONFIG_MIGRATIONS && applied.length > 0 && applied.at(-1).version < 5) {
11349
11471
  convertServiceReferenceRevision(db, options);
11350
11472
  }
11473
+ if (plan === CONFIG_MIGRATIONS)
11474
+ applyRequestLogsDefault(db, options);
11351
11475
  if (plan.length > applied.length && db.query("PRAGMA foreign_key_check").all().length > 0) {
11352
11476
  throw new ConfigRepositoryError("schema_corrupt", "configuration migration left invalid references");
11353
11477
  }
@@ -11364,7 +11488,7 @@ function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}
11364
11488
  }
11365
11489
 
11366
11490
  // src/config-storage/config-repository.ts
11367
- import { randomUUID as randomUUID3 } from "crypto";
11491
+ import { randomUUID as randomUUID4 } from "crypto";
11368
11492
 
11369
11493
  // src/config-storage/sqlite-version.ts
11370
11494
  class SqliteVersionError extends Error {
@@ -11651,7 +11775,7 @@ class ConfigRepository {
11651
11775
  return;
11652
11776
  const protection = readManagementProtection(this.db);
11653
11777
  const provider = protection.selectedProvider !== null && available.has(protection.selectedProvider) ? protection.selectedProvider : null;
11654
- const now = Date.now(), operationId = randomUUID3();
11778
+ const now = Date.now(), operationId = randomUUID4();
11655
11779
  const prepared = prepareCommitCommand({
11656
11780
  mutation_id: operationId,
11657
11781
  expected_revision: snapshot.revision,
@@ -11777,10 +11901,16 @@ class ConfigRepository {
11777
11901
  commit(command) {
11778
11902
  return this.commitPrepared(prepareCommitCommand(command, this.options.compileOptions));
11779
11903
  }
11904
+ applyPendingRequestLogsDefault(targetWorkerSlots) {
11905
+ const applied = this.mutationTransaction(() => applyRequestLogsDefault(this.db, this.options, targetWorkerSlots));
11906
+ return applied ? this.getControlProjection() : null;
11907
+ }
11780
11908
  commitPrepared(prepared) {
11781
11909
  try {
11782
11910
  const decision = this.mutationTransaction(() => {
11783
11911
  const result = commitTransaction(this.db, prepared, this.options, this.snapshot);
11912
+ if (result.kind === "committed")
11913
+ settleRequestLogsDefault(this.db, this.options, result.operation.committed_revision);
11784
11914
  readManagementProtection(this.db);
11785
11915
  return result;
11786
11916
  });
@@ -11917,6 +12047,9 @@ class ConfigRepository {
11917
12047
  recordWorkerLaunchExit(workerInstanceId, evidence, updatedAt) {
11918
12048
  return runRepositoryAction(() => this.mutationTransaction(() => recordWorkerLaunchExit(this.db, workerInstanceId, evidence, updatedAt)));
11919
12049
  }
12050
+ recordWorkerLaunchCapacityReclaimed(workerInstanceId, guard, updatedAt) {
12051
+ return runRepositoryAction(() => this.mutationTransaction(() => recordWorkerLaunchCapacityReclaimed(this.db, workerInstanceId, guard, updatedAt)));
12052
+ }
11920
12053
  getWorkerLaunch(workerInstanceId) {
11921
12054
  return runRepositoryAction(() => withConsistentRead(this.db, () => readWorkerLaunch(this.db, workerInstanceId)));
11922
12055
  }
@@ -11949,14 +12082,14 @@ class ConfigRepository {
11949
12082
  if (before.state !== "converged" && before.state !== "degraded" && before.state !== "superseded" && outcome.outcome === "degraded" && (outcome.error_code === "replacement_convergence_failed" || outcome.error_code === "control_readiness_failed")) {
11950
12083
  switch (outcome.recovery_disposition) {
11951
12084
  case "retryable":
11952
- createAutomaticRecovery(this.db, randomUUID3(), mutationId, operation.committed_revision, updatedAt);
12085
+ createAutomaticRecovery(this.db, randomUUID4(), mutationId, operation.committed_revision, updatedAt);
11953
12086
  this.options.faultInjection?.("after_automatic_recovery");
11954
12087
  break;
11955
12088
  case "deterministic_worker_rejection":
11956
12089
  case "deterministic_protocol_failure":
11957
12090
  case "deterministic_control_failure":
11958
12091
  case "fatal":
11959
- createStoppedRecovery(this.db, randomUUID3(), mutationId, operation.committed_revision, outcome.recovery_disposition === "fatal" ? "fatal_source_failure" : outcome.recovery_disposition, outcome.error_detail, updatedAt);
12092
+ createStoppedRecovery(this.db, randomUUID4(), mutationId, operation.committed_revision, outcome.recovery_disposition === "fatal" ? "fatal_source_failure" : outcome.recovery_disposition, outcome.error_detail, updatedAt);
11960
12093
  break;
11961
12094
  default: {
11962
12095
  const unhandled = outcome.recovery_disposition;
@@ -12085,6 +12218,7 @@ var STORAGE_METHODS = [
12085
12218
  "getControlProjection",
12086
12219
  "setManagementProviderOffline",
12087
12220
  "commitPrepared",
12221
+ "applyPendingRequestLogsDefault",
12088
12222
  "appendServingSnapshot",
12089
12223
  "getServingSnapshot",
12090
12224
  "claimController",
@@ -12099,6 +12233,7 @@ var STORAGE_METHODS = [
12099
12233
  "fenceWorkerLaunchNotStarted",
12100
12234
  "recordWorkerLaunchAdmitted",
12101
12235
  "recordWorkerLaunchExit",
12236
+ "recordWorkerLaunchCapacityReclaimed",
12102
12237
  "getWorkerLaunch",
12103
12238
  "getWorkerLaunchAllocationFacts",
12104
12239
  "getUnsettledWorkerLaunches",
@@ -284,6 +284,9 @@ function createPluginHooks() {
284
284
  onWebSocketSessionMode: new AsyncSeriesBailHook("onWebSocketSessionMode"),
285
285
  onWebSocketHandshake: new AsyncSeriesWaterfallHook("onWebSocketHandshake"),
286
286
  onWebSocketObservation: new WebSocketObservationHook("onWebSocketObservation"),
287
+ onRequestLog: new SyncBailHook("onRequestLog"),
288
+ onRequestLogBody: new SyncBailHook("onRequestLogBody"),
289
+ onRequestLogApplication: new SyncBailHook("onRequestLogApplication"),
287
290
  onGatewayBody: new SyncBailHook("onGatewayBody"),
288
291
  onGatewayRequest: new AsyncSeriesBailHook("onGatewayRequest"),
289
292
  onGatewayRoute: new AsyncSeriesBailHook("onGatewayRoute"),
@@ -301,7 +304,6 @@ function createPluginHooks() {
301
304
  onGatewayBodyRules: new AsyncSeriesBailHook("onGatewayBodyRules"),
302
305
  onGatewayQueryRules: new AsyncSeriesBailHook("onGatewayQueryRules"),
303
306
  onGatewayResponseRules: new AsyncSeriesBailHook("onGatewayResponseRules"),
304
- onGatewayLog: new AsyncSeriesBailHook("onGatewayLog"),
305
307
  onRequestInit: new AsyncParallelHook("onRequestInit"),
306
308
  onBeforeRequest: new AsyncSeriesWaterfallHook("onBeforeRequest"),
307
309
  onValidateOutbound: new AsyncSeriesWaterfallHook("onValidateOutbound"),