refactor(agent): replace OMP with Claude Code kernel
This commit is contained in:
1 parent
0fb2226f8c
commit
9a1f182397
232 files changed
+2561
-25564
No files matched your search
+6
-6
@@ -78,7 +78,7 @@ async function readRegistry(persistMigration: boolean): Promise<StoredRegistry>
|
||||
const legacy = await getGatewayConfig()
|
||||
const migrated: StoredModel = {
|
||||
id: 'legacy-default', name: legacy.model, providerId: 'custom',
|
||||
model: legacy.model, baseUrl: legacy.baseUrl, authMode: 'api-key',
|
||||
model: legacy.model, baseUrl: legacy.baseUrl, authMode: 'api-key', protocol: 'anthropic',
|
||||
supportsToolCall: true, supportsImages: false, supportsReasoning: false,
|
||||
temperature: legacy.temperature, maxToolRounds: legacy.maxToolRounds
|
||||
}
|
||||
@@ -146,15 +146,15 @@ function normalize(input: CustomModelInput, existing?: StoredModel, testing = fa
|
||||
const key = authMode === 'none' || input.clearApiKey ? '' : suppliedKey || (existing ? readKey(existing).key : '')
|
||||
if (authMode !== 'none' && !key && (testing || !input.clearApiKey)) throw new Error('请输入 API Key')
|
||||
const next: StoredModel = { id, name, providerId, model, baseUrl, authMode }
|
||||
if (input.protocol !== undefined && !['auto', 'openai', 'anthropic', 'gemini'].includes(input.protocol)) throw new Error('模型协议无效')
|
||||
next.protocol = input.protocol ?? existing?.protocol
|
||||
if (input.protocol !== undefined && input.protocol !== 'anthropic') throw new Error('首版仅支持 Anthropic 协议')
|
||||
next.protocol = 'anthropic'
|
||||
if (input.tokenBudgetVersion !== undefined && input.tokenBudgetVersion !== 2) throw new Error('模型上下文配置版本无效')
|
||||
if (input.tokenBudgetVersion === 2) next.tokenBudgetVersion = 2
|
||||
const configuredEndpoint = input.endpoint ?? (baseUrl === existing?.baseUrl && next.protocol === existing?.protocol && !suppliedKey ? existing.endpoint : undefined)
|
||||
if (configuredEndpoint) {
|
||||
if (!['openai-completions', 'openai-responses', 'anthropic-messages', 'google-generative-ai'].includes(configuredEndpoint.api)) throw new Error('协商协议无效')
|
||||
const root = normalizeModelAddress(configuredEndpoint.baseUrl)
|
||||
if (new URL(root).origin !== endpoint.origin || next.protocol && next.protocol !== 'auto' && apiProtocol(configuredEndpoint.api) !== next.protocol) throw new Error('协商地址与填写的域名或协议不一致')
|
||||
if (new URL(root).origin !== endpoint.origin || apiProtocol(configuredEndpoint.api) !== 'anthropic') throw new Error('协商地址与填写的域名或协议不一致')
|
||||
next.endpoint = { api: configuredEndpoint.api, baseUrl: root, checkedAt: configuredEndpoint.checkedAt,
|
||||
...(['models', 'generation'].includes(configuredEndpoint.verifiedBy ?? '') ? { verifiedBy: configuredEndpoint.verifiedBy } : {}) }
|
||||
}
|
||||
@@ -281,12 +281,12 @@ export async function resolveModel(id?: string | null): Promise<ResolvedModel |
|
||||
}
|
||||
|
||||
export async function fetchModels(input: ModelDiscoveryInput): Promise<ModelDiscoveryResult> {
|
||||
if (!input || typeof input.baseUrl !== 'string' || !['auto', 'openai', 'anthropic', 'gemini'].includes(input.protocol ?? 'auto')) throw new Error('模型查询参数无效')
|
||||
if (!input || typeof input.baseUrl !== 'string' || (input.protocol !== undefined && input.protocol !== 'anthropic')) throw new Error('首版仅支持 Anthropic 协议')
|
||||
await writes
|
||||
const registry = cache ?? await readRegistry(false), existing = registry.models.find(model => model.id === input.previousId)
|
||||
const key = input.authMode === 'none' ? '' : typeof input.apiKey === 'string' && input.apiKey.trim() ? input.apiKey.replace(/\s/gu, '') : existing ? readKey(existing).key : ''
|
||||
if (!key && input.authMode !== 'none') throw new Error('请输入 API Key')
|
||||
return discoverModelConnection(input.baseUrl, input.protocol ?? 'auto', key, true)
|
||||
return discoverModelConnection(input.baseUrl, 'anthropic', key, true)
|
||||
}
|
||||
|
||||
/** Test only the user-specified origin, negotiating paths/protocols before reporting success. */
|
||||
|
||||
Reference in new issue
Block a user