openclawProviderConfig.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * OpenClaw 模型供应商(AI Providers)环境变量配置
  3. * 用于:1)生成「填写并创建新密钥」表单 2)选择已有密钥时展示「将配置的 AI 供应商」
  4. */
  5. /** @typedef {{ sectionKey: string, sectionLabelKey: string, required: boolean, vars: Array<{ envKey: string, providerLabelKey: string, descriptionKey: string, overrideUrlKey?: string, component?: 'a-select', resource?: string, placeholderKey?: string, required?: boolean }> }} OpenclawSection */
  6. export const OPENCLAW_PROVIDER_SECTIONS = [
  7. {
  8. sectionKey: 'ai_providers',
  9. sectionLabelKey: 'aice.openclaw.section.ai_providers_env',
  10. required: true,
  11. vars: [
  12. { envKey: 'ANTHROPIC_API_KEY', providerLabelKey: 'aice.openclaw.provider.anthropic', descriptionKey: 'aice.openclaw.env.ANTHROPIC_API_KEY', overrideUrlKey: 'ANTHROPIC_BASE_URL' },
  13. // { envKey: 'OPENAI_API_KEY', providerLabelKey: 'aice.openclaw.provider.openai', descriptionKey: 'aice.openclaw.env.OPENAI_API_KEY' },
  14. // { envKey: 'OPENROUTER_API_KEY', providerLabelKey: 'aice.openclaw.provider.openrouter', descriptionKey: 'aice.openclaw.env.OPENROUTER_API_KEY' },
  15. // { envKey: 'GEMINI_API_KEY', providerLabelKey: 'aice.openclaw.provider.gemini', descriptionKey: 'aice.openclaw.env.GEMINI_API_KEY' },
  16. // { envKey: 'XAI_API_KEY', providerLabelKey: 'aice.openclaw.provider.xai', descriptionKey: 'aice.openclaw.env.XAI_API_KEY' },
  17. // { envKey: 'GROQ_API_KEY', providerLabelKey: 'aice.openclaw.provider.groq', descriptionKey: 'aice.openclaw.env.GROQ_API_KEY' },
  18. // { envKey: 'MISTRAL_API_KEY', providerLabelKey: 'aice.openclaw.provider.mistral', descriptionKey: 'aice.openclaw.env.MISTRAL_API_KEY' },
  19. // { envKey: 'CEREBRAS_API_KEY', providerLabelKey: 'aice.openclaw.provider.cerebras', descriptionKey: 'aice.openclaw.env.CEREBRAS_API_KEY' },
  20. // { envKey: 'VENICE_API_KEY', providerLabelKey: 'aice.openclaw.provider.venice', descriptionKey: 'aice.openclaw.env.VENICE_API_KEY' },
  21. { envKey: 'MOONSHOT_API_KEY', providerLabelKey: 'aice.openclaw.provider.moonshot', descriptionKey: 'aice.openclaw.env.MOONSHOT_API_KEY', overrideUrlKey: 'MOONSHOT_BASE_URL' },
  22. // { envKey: 'KIMI_API_KEY', providerLabelKey: 'aice.openclaw.provider.kimi', descriptionKey: 'aice.openclaw.env.KIMI_API_KEY', overrideUrlKey: 'KIMI_BASE_URL' },
  23. { envKey: 'MINIMAX_API_KEY', providerLabelKey: 'aice.openclaw.provider.minimax', descriptionKey: 'aice.openclaw.env.MINIMAX_API_KEY' },
  24. { envKey: 'ZAI_API_KEY', providerLabelKey: 'aice.openclaw.provider.zai', descriptionKey: 'aice.openclaw.env.ZAI_API_KEY' },
  25. // { envKey: 'AI_GATEWAY_API_KEY', providerLabelKey: 'aice.openclaw.provider.ai_gateway', descriptionKey: 'aice.openclaw.env.AI_GATEWAY_API_KEY', overrideUrlKey: 'AI_GATEWAY_BASE_URL' },
  26. // { envKey: 'OPENCODE_API_KEY', providerLabelKey: 'aice.openclaw.provider.opencode', descriptionKey: 'aice.openclaw.env.OPENCODE_API_KEY' },
  27. // { envKey: 'SYNTHETIC_API_KEY', providerLabelKey: 'aice.openclaw.provider.synthetic', descriptionKey: 'aice.openclaw.env.SYNTHETIC_API_KEY' },
  28. // { envKey: 'COPILOT_GITHUB_TOKEN', providerLabelKey: 'aice.openclaw.provider.copilot', descriptionKey: 'aice.openclaw.env.COPILOT_GITHUB_TOKEN' },
  29. // { envKey: 'XIAOMI_API_KEY', providerLabelKey: 'aice.openclaw.provider.xiaomi', descriptionKey: 'aice.openclaw.env.XIAOMI_API_KEY' },
  30. ],
  31. },
  32. // {
  33. // sectionKey: 'deepgram',
  34. // sectionLabelKey: 'aice.openclaw.section.deepgram',
  35. // required: false,
  36. // vars: [
  37. // { envKey: 'DEEPGRAM_API_KEY', providerLabelKey: 'aice.openclaw.provider.deepgram', descriptionKey: 'aice.openclaw.env.DEEPGRAM_API_KEY' },
  38. // ],
  39. // },
  40. // {
  41. // sectionKey: 'bedrock',
  42. // sectionLabelKey: 'aice.openclaw.section.bedrock',
  43. // required: false,
  44. // vars: [
  45. // { envKey: 'AWS_ACCESS_KEY_ID', providerLabelKey: 'aice.openclaw.provider.bedrock', descriptionKey: 'aice.openclaw.env.AWS_ACCESS_KEY_ID' },
  46. // { envKey: 'AWS_SECRET_ACCESS_KEY', providerLabelKey: 'aice.openclaw.provider.bedrock', descriptionKey: 'aice.openclaw.env.AWS_SECRET_ACCESS_KEY' },
  47. // { envKey: 'AWS_REGION', providerLabelKey: 'aice.openclaw.provider.bedrock', descriptionKey: 'aice.openclaw.env.AWS_REGION' },
  48. // { envKey: 'AWS_SESSION_TOKEN', providerLabelKey: 'aice.openclaw.provider.bedrock', descriptionKey: 'aice.openclaw.env.AWS_SESSION_TOKEN' },
  49. // { envKey: 'BEDROCK_PROVIDER_FILTER', providerLabelKey: 'aice.openclaw.provider.bedrock', descriptionKey: 'aice.openclaw.env.BEDROCK_PROVIDER_FILTER' },
  50. // ],
  51. // },
  52. {
  53. sectionKey: 'ollama',
  54. sectionLabelKey: 'aice.openclaw.section.ollama',
  55. required: false,
  56. vars: [
  57. { envKey: 'OLLAMA_BASE_URL', providerLabelKey: 'aice.openclaw.provider.ollama', descriptionKey: 'aice.openclaw.env.OLLAMA_BASE_URL' },
  58. {
  59. envKey: 'OPENCLAW_PRIMARY_MODEL',
  60. providerLabelKey: 'aice.openclaw.provider.ollama',
  61. descriptionKey: 'aice.openclaw.env.OPENCLAW_PRIMARY_MODEL',
  62. component: 'a-select',
  63. resource: 'llms/provider-models',
  64. placeholderKey: 'aice.model',
  65. required: true,
  66. },
  67. ],
  68. },
  69. ]
  70. /** 去重后的供应商列表(用于下拉多选),按在 OPENCLAW_PROVIDER_SECTIONS 中首次出现顺序 */
  71. const _providerKeySet = new Set()
  72. export const OPENCLAW_PROVIDER_OPTIONS = []
  73. OPENCLAW_PROVIDER_SECTIONS.forEach(section => {
  74. section.vars.forEach(({ providerLabelKey }) => {
  75. if (!_providerKeySet.has(providerLabelKey)) {
  76. _providerKeySet.add(providerLabelKey)
  77. OPENCLAW_PROVIDER_OPTIONS.push(providerLabelKey)
  78. }
  79. })
  80. })
  81. /**
  82. * KEY -> provider 显示名 i18n key(用于选择已有密钥时展示「将配置的 AI 供应商」)
  83. * @type {Record<string, string>}
  84. */
  85. export const OPENCLAW_ENV_KEY_TO_PROVIDER_LABEL = {}
  86. OPENCLAW_PROVIDER_SECTIONS.forEach(section => {
  87. section.vars.forEach(({ envKey, providerLabelKey }) => {
  88. OPENCLAW_ENV_KEY_TO_PROVIDER_LABEL[envKey] = providerLabelKey
  89. })
  90. })
  91. /**
  92. * 根据已选 export keys 得到对应的 provider 显示名 i18n keys(去重)
  93. * @param {string[]} exportKeys
  94. * @returns {string[]}
  95. */
  96. export function getProviderLabelKeysFromExportKeys (exportKeys) {
  97. if (!Array.isArray(exportKeys) || exportKeys.length === 0) return []
  98. const set = new Set()
  99. exportKeys.forEach(key => {
  100. const labelKey = OPENCLAW_ENV_KEY_TO_PROVIDER_LABEL[key]
  101. if (labelKey) set.add(labelKey)
  102. })
  103. return Array.from(set)
  104. }