channel-affinity-template.constants.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. const buildPassHeadersTemplate = (headers) => ({
  16. operations: [
  17. {
  18. mode: 'pass_headers',
  19. value: [...headers],
  20. keep_origin: true,
  21. },
  22. ],
  23. });
  24. export const CODEX_CLI_HEADER_PASSTHROUGH_HEADERS = [
  25. 'Originator',
  26. 'Session_id',
  27. 'User-Agent',
  28. 'X-Codex-Beta-Features',
  29. 'X-Codex-Turn-Metadata',
  30. ];
  31. export const CLAUDE_CLI_HEADER_PASSTHROUGH_HEADERS = [
  32. 'X-Stainless-Arch',
  33. 'X-Stainless-Lang',
  34. 'X-Stainless-Os',
  35. 'X-Stainless-Package-Version',
  36. 'X-Stainless-Retry-Count',
  37. 'X-Stainless-Runtime',
  38. 'X-Stainless-Runtime-Version',
  39. 'X-Stainless-Timeout',
  40. 'User-Agent',
  41. 'X-App',
  42. 'Anthropic-Beta',
  43. 'Anthropic-Dangerous-Direct-Browser-Access',
  44. 'Anthropic-Version',
  45. ];
  46. export const CODEX_CLI_HEADER_PASSTHROUGH_TEMPLATE = buildPassHeadersTemplate(
  47. CODEX_CLI_HEADER_PASSTHROUGH_HEADERS,
  48. );
  49. export const CLAUDE_CLI_HEADER_PASSTHROUGH_TEMPLATE = buildPassHeadersTemplate(
  50. CLAUDE_CLI_HEADER_PASSTHROUGH_HEADERS,
  51. );
  52. export const CHANNEL_AFFINITY_RULE_TEMPLATES = {
  53. codexCli: {
  54. name: 'codex cli trace',
  55. model_regex: ['^gpt-.*$'],
  56. path_regex: ['/v1/responses'],
  57. key_sources: [{ type: 'gjson', path: 'prompt_cache_key' }],
  58. param_override_template: CODEX_CLI_HEADER_PASSTHROUGH_TEMPLATE,
  59. value_regex: '',
  60. ttl_seconds: 0,
  61. skip_retry_on_failure: false,
  62. include_using_group: true,
  63. include_rule_name: true,
  64. },
  65. claudeCli: {
  66. name: 'claude cli trace',
  67. model_regex: ['^claude-.*$'],
  68. path_regex: ['/v1/messages'],
  69. key_sources: [{ type: 'gjson', path: 'metadata.user_id' }],
  70. param_override_template: CLAUDE_CLI_HEADER_PASSTHROUGH_TEMPLATE,
  71. value_regex: '',
  72. ttl_seconds: 0,
  73. skip_retry_on_failure: false,
  74. include_using_group: true,
  75. include_rule_name: true,
  76. },
  77. };
  78. export const cloneChannelAffinityTemplate = (template) =>
  79. JSON.parse(JSON.stringify(template || {}));