@jeffusion/bungee-core 6.14.1 → 6.15.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 (49) hide show
  1. package/dist/config-storage-worker.js +413 -216
  2. package/dist/main.js +16093 -13501
  3. package/dist/plugins/anthropic-request-sanitizer/index.js.map +1 -1
  4. package/dist/plugins/anthropic-tool-name-transformer/index.js.map +1 -1
  5. package/dist/plugins/chatgpt-oauth/control.js +13 -5
  6. package/dist/plugins/chatgpt-oauth/control.js.map +4 -4
  7. package/dist/plugins/chatgpt-oauth/index.js.map +1 -1
  8. package/dist/plugins/codex-router/control.js +2 -2
  9. package/dist/plugins/codex-router/control.js.map +4 -4
  10. package/dist/plugins/codex-router/index.js +99 -3
  11. package/dist/plugins/codex-router/index.js.map +8 -7
  12. package/dist/plugins/codex-router/manifest.json +6 -0
  13. package/dist/plugins/deepseek-reasoning-fix/index.js.map +1 -1
  14. package/dist/plugins/key-access/control.js +2 -2
  15. package/dist/plugins/key-access/control.js.map +4 -4
  16. package/dist/plugins/key-access/index.js.map +1 -1
  17. package/dist/plugins/key-access/ingress.js.map +1 -1
  18. package/dist/plugins/key-rate-limit/control.js +2 -2
  19. package/dist/plugins/key-rate-limit/control.js.map +4 -4
  20. package/dist/plugins/key-rate-limit/index.js +19 -7
  21. package/dist/plugins/key-rate-limit/index.js.map +4 -4
  22. package/dist/plugins/key-rate-limit/ingress.js +19 -7
  23. package/dist/plugins/key-rate-limit/ingress.js.map +3 -3
  24. package/dist/plugins/llm-protocol-adapter/control.js +113 -20
  25. package/dist/plugins/llm-protocol-adapter/control.js.map +9 -9
  26. package/dist/plugins/llm-protocol-adapter/index.js +100 -16
  27. package/dist/plugins/llm-protocol-adapter/index.js.map +8 -8
  28. package/dist/plugins/llm-tps/control.js +2 -2
  29. package/dist/plugins/llm-tps/control.js.map +3 -3
  30. package/dist/plugins/llm-tps/index.js.map +1 -1
  31. package/dist/plugins/model-mapping/control.js +2 -2
  32. package/dist/plugins/model-mapping/control.js.map +3 -3
  33. package/dist/plugins/model-mapping/index.js.map +1 -1
  34. package/dist/plugins/models-dev/control.js +13 -7
  35. package/dist/plugins/models-dev/control.js.map +3 -3
  36. package/dist/plugins/models-dev/index.js.map +1 -1
  37. package/dist/plugins/request-logs/index.js.map +1 -1
  38. package/dist/plugins/signature-repair/index.js.map +1 -1
  39. package/dist/plugins/token-budget/control.js +58 -47
  40. package/dist/plugins/token-budget/control.js.map +5 -5
  41. package/dist/plugins/token-budget/index.js.map +1 -1
  42. package/dist/plugins/token-metering/index.js.map +1 -1
  43. package/dist/plugins/token-stats/control.js +2 -2
  44. package/dist/plugins/token-stats/control.js.map +4 -4
  45. package/dist/plugins/token-stats/index.js.map +1 -1
  46. package/dist/plugins/user-auth/control.js +16 -15
  47. package/dist/plugins/user-auth/control.js.map +4 -4
  48. package/dist/plugins/user-auth/index.js.map +1 -1
  49. package/package.json +2 -2
@@ -962,6 +962,9 @@ var manifest_default = {
962
962
  "editor.context": "\u4E0A\u4E0B\u6587\u957F\u5EA6\u4E0A\u9650",
963
963
  "editor.contextHint": "\u7559\u7A7A\u4F7F\u7528\u76EE\u6807\u6A21\u578B\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u3002",
964
964
  "editor.toolsOff": "\u7981\u7528\u5DE5\u5177\u8C03\u7528",
965
+ "editor.allowedTools": "\u5141\u8BB8\u7684\u5DE5\u5177",
966
+ "editor.allowedToolsHint": "\u7559\u7A7A\u5141\u8BB8\u5168\u90E8\u5DE5\u5177\u3002\u7528\u82F1\u6587\u9017\u53F7\u5206\u9694\uFF0C\u652F\u6301 * \u901A\u914D\u7B26\u3002\u5206\u7EC4\u5185\u7684\u5DE5\u5177\u5199\u4E3A \u547D\u540D\u7A7A\u95F4.\u5DE5\u5177\u540D\u3002",
967
+ "editor.allowedToolsInvalid": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u5DE5\u5177\u540D\u79F0\u6216\u901A\u914D\u7B26\uFF0C\u5E76\u7528\u82F1\u6587\u9017\u53F7\u5206\u9694\u3002",
965
968
  "editor.imagesOff": "\u7981\u7528\u56FE\u7247\u8F93\u5165",
966
969
  "editor.reasoningOff": "\u7981\u7528\u63A8\u7406\u80FD\u529B",
967
970
  "editor.increase": "\u589E\u52A0\u4E0A\u4E0B\u6587\u4E0A\u9650",
@@ -1023,6 +1026,9 @@ var manifest_default = {
1023
1026
  "editor.context": "Context length limit",
1024
1027
  "editor.contextHint": "Leave empty to use the target model context length.",
1025
1028
  "editor.toolsOff": "Disable tool calls",
1029
+ "editor.allowedTools": "Allowed tools",
1030
+ "editor.allowedToolsHint": "Leave blank to allow all tools. Separate entries with commas. Use * as a wildcard and namespace.tool for grouped tools.",
1031
+ "editor.allowedToolsInvalid": "Enter valid tool names or wildcard patterns separated by commas.",
1026
1032
  "editor.imagesOff": "Disable image input",
1027
1033
  "editor.reasoningOff": "Disable reasoning",
1028
1034
  "editor.increase": "Increase context limit",
@@ -1064,6 +1070,7 @@ function parseCollaborationRelay(value) {
1064
1070
  throw new Error("codex_router_invalid_collaboration_relay");
1065
1071
  return Object.freeze(structuredClone(relay));
1066
1072
  }
1073
+ var MAX_ALLOWED_TOOLS_LENGTH = 4096;
1067
1074
  function bindingSource(binding) {
1068
1075
  return binding.source ?? binding.alias ?? binding.model;
1069
1076
  }
@@ -1098,6 +1105,11 @@ function parseBindings(value) {
1098
1105
  if (!overrides || typeof overrides !== "object" || Array.isArray(overrides))
1099
1106
  throw new Error("codex_router_invalid_capabilities");
1100
1107
  for (const [key, val] of Object.entries(overrides)) {
1108
+ if (key === "allowedTools") {
1109
+ if (typeof val !== "string" || val.length > MAX_ALLOWED_TOOLS_LENGTH || /[\x00-\x1f\x7f]/.test(val) || val.trim() && !val.split(",").some((pattern) => pattern.trim()))
1110
+ throw new Error("codex_router_invalid_allowed_tools");
1111
+ continue;
1112
+ }
1101
1113
  if (["contextWindow"].includes(key) ? typeof val !== "number" || !Number.isSafeInteger(val) || val < 1 : !["tools", "reasoning", "images"].includes(key) || typeof val !== "boolean")
1102
1114
  throw new Error("codex_router_invalid_capabilities");
1103
1115
  }
@@ -1309,6 +1321,87 @@ function catalogKeys({ context, principal, servingRevision }, bindings) {
1309
1321
  return { validator: key(version.replace(/^(\d+\.\d+\.\d+)[-+].*$/, "$1")), snapshot: key(version) };
1310
1322
  }
1311
1323
 
1324
+ // plugins/codex-router/server/tool-allowlist.ts
1325
+ function matches(name, parts) {
1326
+ const first = parts[0];
1327
+ if (parts.length === 1)
1328
+ return name === first;
1329
+ const last = parts.at(-1);
1330
+ if (!name.startsWith(first) || !name.endsWith(last))
1331
+ return false;
1332
+ let offset = first.length;
1333
+ for (let i = 1;i < parts.length - 1; i++) {
1334
+ const part = parts[i];
1335
+ const index = name.indexOf(part, offset);
1336
+ if (index < 0)
1337
+ return false;
1338
+ offset = index + part.length;
1339
+ }
1340
+ return offset <= name.length - last.length;
1341
+ }
1342
+ var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
1343
+ function applyToolAllowlist(body, input, allowlist) {
1344
+ const entries = allowlist.split(",").map((pattern) => pattern.trim()).filter(Boolean);
1345
+ if (entries.some((pattern) => /^\*+$/.test(pattern)))
1346
+ return input;
1347
+ const patterns = entries.map((pattern) => pattern.split("*"));
1348
+ const allows = (name, namespace) => {
1349
+ if (typeof name !== "string" || namespace !== undefined && typeof namespace !== "string")
1350
+ return true;
1351
+ const qualified = namespace === undefined ? name : `${namespace}.${name}`;
1352
+ return patterns.some((pattern) => matches(qualified, pattern));
1353
+ };
1354
+ const allowsTool = (tool, namespace) => tool.type === "function" || tool.type === "custom" ? allows(tool.name, namespace) : allows(tool.type, namespace);
1355
+ const filter = (tools) => tools.flatMap((tool) => {
1356
+ if (!isObject(tool) || typeof tool.type !== "string")
1357
+ return [tool];
1358
+ if (tool.type !== "namespace")
1359
+ return allowsTool(tool) ? [tool] : [];
1360
+ if (typeof tool.name !== "string" || !Array.isArray(tool.tools))
1361
+ return [tool];
1362
+ const children = tool.tools.filter((child) => !isObject(child) || allowsTool(child, tool.name));
1363
+ return children.length ? [{ ...tool, tools: children }] : [];
1364
+ });
1365
+ const choice = body.tool_choice;
1366
+ const selected = isObject(choice) && choice.type === "allowed_tools" && Array.isArray(choice.tools) ? choice.tools : [choice];
1367
+ if (selected.some((tool) => isObject(tool) && typeof tool.type === "string" && !allowsTool(tool, tool.namespace)))
1368
+ throw new DataAdmissionError(422, "codex_router_tool_choice_excluded", undefined, { param: "tool_choice", message: "The selected tool is excluded by the model binding" });
1369
+ if (Array.isArray(body.tools)) {
1370
+ const tools = filter(body.tools);
1371
+ if (tools.length)
1372
+ body.tools = tools;
1373
+ else
1374
+ delete body.tools;
1375
+ }
1376
+ let hasTools = body.tools !== undefined;
1377
+ const filteredInput = input.flatMap((item, index) => {
1378
+ if (!isObject(item))
1379
+ return [item];
1380
+ const { type } = item;
1381
+ const historicalToolAllowed = type === "function_call" || type === "custom_tool_call" ? allows(item.name, item.namespace) : type === "web_search_call" ? ["web_search", "web_search_preview", "web_search_preview_2025_03_11"].some((name) => allows(name)) : type === "computer_call" ? ["computer", "computer_use_preview"].some((name) => allows(name)) : typeof type === "string" && type.endsWith("_call") ? allows(type.slice(0, -5)) : true;
1382
+ if (!historicalToolAllowed || type === "item_reference")
1383
+ throw new DataAdmissionError(422, "codex_router_tool_history_excluded", undefined, { param: `input[${index}]`, message: "Tool history is excluded by the model binding. Start a new conversation or allow the tool." });
1384
+ if (item.type !== "additional_tools" && item.type !== "tool_search_output" || !Array.isArray(item.tools))
1385
+ return [item];
1386
+ const declarations = filter(item.tools);
1387
+ if (!declarations.length && item.type === "additional_tools" && item.content === undefined)
1388
+ return [];
1389
+ hasTools ||= declarations.length > 0;
1390
+ return [{ ...item, tools: declarations }];
1391
+ });
1392
+ if (!hasTools) {
1393
+ if (choice === "required")
1394
+ throw new DataAdmissionError(422, "codex_router_tool_choice_excluded", undefined, { param: "tool_choice", message: "The model binding leaves no tools to call" });
1395
+ if (choice === "auto" || choice === "none")
1396
+ delete body.tool_choice;
1397
+ if (typeof body.parallel_tool_calls === "boolean")
1398
+ delete body.parallel_tool_calls;
1399
+ }
1400
+ if (Array.isArray(body.input))
1401
+ body.input = filteredInput;
1402
+ return filteredInput;
1403
+ }
1404
+
1312
1405
  // plugins/codex-router/server/index.ts
1313
1406
  var CodexRouterPlugin = definePlugin(class {
1314
1407
  static name = "codex-router";
@@ -1395,9 +1488,12 @@ var CodexRouterPlugin = definePlugin(class {
1395
1488
  throw new DataAdmissionError(422, "codex_router_invalid_history");
1396
1489
  if (protocol !== "responses" && protocol !== "gemini_generate_content" && !opaqueRestored && logicalInput.some((item) => item?.encrypted_content || item?.type === "compaction"))
1397
1490
  throw new DataAdmissionError(422, "codex_router_unrestorable_history_start_new_conversation");
1398
- const hasTools = input.tools?.length || logicalInput.some((item) => item?.type === "additional_tools" && item.tools?.length);
1491
+ const hasTools = input.tools?.length || logicalInput.some((item) => (item?.type === "additional_tools" || item?.type === "tool_search_output") && item.tools?.length);
1399
1492
  if (hasTools && (!capabilities.toolCall || binding.capabilityOverrides?.tools === false))
1400
1493
  throw new DataAdmissionError(422, "codex_router_tools_unsupported");
1494
+ const allowedTools = binding.capabilityOverrides?.tools === false ? undefined : binding.capabilityOverrides?.allowedTools?.trim();
1495
+ if (allowedTools)
1496
+ logicalInput = applyToolAllowlist(input, logicalInput, allowedTools);
1401
1497
  let relayDiagnostics = [];
1402
1498
  if (protocol !== "responses") {
1403
1499
  try {
@@ -1464,7 +1560,7 @@ var CodexRouterPlugin = definePlugin(class {
1464
1560
  return result;
1465
1561
  });
1466
1562
  } };
1467
- return { requiredUpstreamId, adapter, ...protocol !== "responses" ? { canonicalInput: logicalInput, diagnostics } : {} };
1563
+ return { requiredUpstreamId, adapter, ...protocol !== "responses" || allowedTools ? { canonicalInput: logicalInput } : {}, ...protocol !== "responses" ? { diagnostics } : {} };
1468
1564
  } };
1469
1565
  });
1470
1566
  hooks.onBeforeRequest.tap("codex-router.catalog-validator", (context) => {
@@ -1563,4 +1659,4 @@ export {
1563
1659
  server_default as default
1564
1660
  };
1565
1661
 
1566
- //# debugId=4CB821EDFC34396864756E2164756E21
1662
+ //# debugId=3F779FDBE47C3F4B64756E2164756E21