|
|
@@ -27,6 +27,35 @@ export class ClaudeProvider implements AgentProvider {
|
|
|
/** 对话中引擎报告的额度(rate_limit_event),查询额度失败时作为后备 */
|
|
|
private lastRateLimits = new Map<string, QuotaWindowDto>()
|
|
|
private quotaCache: { at: number; value: ProviderQuotaDto } | null = null
|
|
|
+ private labelsCache: { at: number; value: Record<string, string> } | null = null
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模型别名对应的实际版本(如 sonnet → Sonnet 5.5 · claude-sonnet-5-5):用 SDK 的 supportedModels 查询,
|
|
|
+ * 不发送消息、不调用模型;缓存 10 分钟,失败时不显示
|
|
|
+ */
|
|
|
+ private async modelLabels(settings: AppSettings): Promise<Record<string, string>> {
|
|
|
+ if (this.labelsCache && Date.now() - this.labelsCache.at < 600_000) return this.labelsCache.value
|
|
|
+ const ac = new AbortController()
|
|
|
+ const timer = setTimeout(() => ac.abort(), 30_000)
|
|
|
+ try {
|
|
|
+ const q = query({
|
|
|
+ prompt: idleInput(ac.signal),
|
|
|
+ options: { abortController: ac, settingSources: [], cwd: settings.paths.workspaceRoot, pathToClaudeCodeExecutable: settings.providers.claude.cliPath },
|
|
|
+ })
|
|
|
+ const value: Record<string, string> = {}
|
|
|
+ for (const m of await q.supportedModels()) {
|
|
|
+ if (m.value === 'default') continue
|
|
|
+ value[m.value] = m.resolvedModel && m.resolvedModel !== m.value ? `${m.displayName} · ${m.resolvedModel}` : m.displayName
|
|
|
+ }
|
|
|
+ this.labelsCache = { at: Date.now(), value }
|
|
|
+ return value
|
|
|
+ } catch {
|
|
|
+ return {}
|
|
|
+ } finally {
|
|
|
+ clearTimeout(timer)
|
|
|
+ ac.abort()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
async run(ctx: RunContext): Promise<RunResult> {
|
|
|
try {
|
|
|
@@ -227,6 +256,7 @@ export class ClaudeProvider implements AgentProvider {
|
|
|
const info = JSON.parse(auth.stdout) as { loggedIn?: boolean; subscriptionType?: string; email?: string }
|
|
|
return {
|
|
|
...base,
|
|
|
+ modelLabels: info.loggedIn ? await this.modelLabels(settings) : undefined,
|
|
|
version: ver.stdout.trim().split(' ')[0] || null,
|
|
|
loggedIn: !!info.loggedIn,
|
|
|
available: s.enabled && !!info.loggedIn,
|