同步上游主仓库最新代码,整合以下新功能: - feat: 工具层及 mcp 大重构 (#252) - feat: 远程群控 (#243) - feat: 添加对 langfuse 监控的支持 (#242) - feat: 完成第一个 mcp-chrome 接入版本 - feat: 添加模型 1M 上下文切换 - feat: langfuse 工具调用显示为嵌套结构 - feat: 加上 userId 的传递 - feat: Add Ultraplan Feature for Advanced Multi-Agent Planning (#232) - feat: Add brave as alternative WebSearchTool - fix: 修复 Bun.hash 不存在问题 - fix: 修复缓存 - fix: 修复 interrupt 日志不上传 - fix: 修复 chrome 链接版本 - fix: 使用简化版本的 chrome 桥接器 - fix: 修复 node 环境没有 bun 的问题 - fix: 修复穷鬼模式的写入问题 - fix: 修复对穷鬼模式的 auto dream 和 session memory 越过 - fix: 修复初次登陆的校验问题 - fix(openai): fix stop_reason null, zero usage fields and max_tokens forwarding - chore: 1.3.3 版本 - docs: 添加浏览器说明支持 冲突解决策略: - 保留 CoStrict 品牌、4.0.x 版本号、csc bin 命令 - 保留 CoStrict 企业认证体系和 Agent 编排 - 采用上游的 1M context、langfuse、chrome mcp、远程群控等新功能 - 采用上游的 getDialogConfig/promptIdentifier 模式 - 采用上游的 FORCE_INTERACTIVE TTY 修复 - 合并两者:保留 CoStrict 品牌名 + 上游新代码模式
86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import type { AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS } from '../../services/analytics/index.js'
|
|
import { getInitialSettings } from '../settings/settings.js'
|
|
import { isEnvTruthy } from '../envUtils.js'
|
|
|
|
export type APIProvider =
|
|
| 'firstParty'
|
|
| 'bedrock'
|
|
| 'vertex'
|
|
| 'foundry'
|
|
| 'openai'
|
|
| 'gemini'
|
|
| 'grok'
|
|
| 'costrict'
|
|
|
|
export function getAPIProvider(): APIProvider {
|
|
const modelType = getInitialSettings().modelType
|
|
if (modelType === 'openai') return 'openai'
|
|
if (modelType === 'gemini') return 'gemini'
|
|
if (modelType === 'grok') return 'grok'
|
|
if (modelType === 'costrict') return 'costrict'
|
|
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)) return 'bedrock'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_VERTEX)) return 'vertex'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_FOUNDRY)) return 'foundry'
|
|
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI)) return 'openai'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_GEMINI)) return 'gemini'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_GROK)) return 'grok'
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_USE_COSTRICT)) return 'costrict'
|
|
|
|
return 'firstParty'
|
|
}
|
|
|
|
export function getAPIProviderForStatsig(): AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS {
|
|
return getAPIProvider() as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
|
}
|
|
|
|
/**
|
|
* Get a human-readable display name for the current API provider
|
|
*/
|
|
export function getProviderDisplayName(provider: APIProvider): string {
|
|
switch (provider) {
|
|
case 'firstParty':
|
|
return 'Anthropic'
|
|
case 'bedrock':
|
|
return 'AWS Bedrock'
|
|
case 'vertex':
|
|
return 'Google Vertex'
|
|
case 'foundry':
|
|
return 'Foundry'
|
|
case 'openai':
|
|
return 'OpenAI'
|
|
case 'gemini':
|
|
return 'Google Gemini'
|
|
case 'grok':
|
|
return 'xAI Grok'
|
|
case 'costrict':
|
|
return 'CoStrict'
|
|
default:
|
|
return provider
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if ANTHROPIC_BASE_URL is a first-party Anthropic API URL.
|
|
* Returns true if not set (default API) or points to api.anthropic.com
|
|
* (or api-staging.anthropic.com for ant users).
|
|
*/
|
|
export function isFirstPartyAnthropicBaseUrl(): boolean {
|
|
const baseUrl = process.env.ANTHROPIC_BASE_URL
|
|
// TODO: 这里会有问题, 只配置了 openai 协议的用户, 按理说会为 true 导致问题
|
|
if (!baseUrl) {
|
|
return true
|
|
}
|
|
try {
|
|
const host = new URL(baseUrl).host
|
|
const allowedHosts = ['api.anthropic.com']
|
|
if (process.env.USER_TYPE === 'ant') {
|
|
allowedHosts.push('api-staging.anthropic.com')
|
|
}
|
|
return allowedHosts.includes(host)
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|