Skip to content

Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.

6.1 KB
Raw Blame
import { Disclosure, UiIcon } from '../../ui';
import type { Draft, Plan } from '../../plan-editor';
import type { DecisionService } from './types';
import { decisionFailureHelp, decisionReferences, providerLabel, type DecisionTest } from './presentation';
import { DecisionIcon } from './DecisionIcon';

export function DecisionConnectionDetail({ service, language, mutable, busy, result, savedBeforeTest, plans, drafts, onEdit, onTest, onDelete, onProtocol, onOpenRoute, onUse }: {
  service: DecisionService; language: 'zh' | 'en'; mutable: boolean; busy: boolean; result?: DecisionTest; savedBeforeTest: boolean;
  plans: Plan[]; drafts: Draft[]; onEdit(): void; onTest(): void; onDelete(): void; onProtocol(): void;
  onOpenRoute?(plan?: Plan, draft?: Draft): void; onUse?(): void;
}) {
  const t = (zh: string, en: string) => language === 'zh' ? zh : en;
  const connection = service.connection;
  const references = decisionReferences(service.id, plans, drafts);
  return <>
    <header className="editor-section decision-heading"><DecisionIcon provider={connection.kind === 'system_one' ? connection.provider : undefined} language={language} /><div><h2>{service.name}</h2><p>{providerLabel(connection, language)}</p></div><button className="btn" disabled={!mutable || busy} onClick={onEdit}>{t('编辑', 'Edit')}</button></header>
    <section className="editor-section"><dl className="decision-facts"><div><dt>{t('类型', 'Type')}</dt><dd>{connection.kind === 'system_one' ? t('决策模型 · HiRoute 内置逻辑', 'Decision model · HiRoute logic') : t('自定义扩展 · 自行实现决策', 'Custom extension · your decision logic')}</dd></div>{connection.kind === 'system_one' && <div><dt>{t('模型', 'Model')}</dt><dd>{connection.model}</dd></div>}<div><dt>{t('接入点', 'Endpoint')}</dt><dd className="decision-endpoint">{connection.endpoint}</dd></div><div><dt>{t('认证', 'Authentication')}</dt><dd>{connection.auth_header ? t('已配置', 'Configured') : t('无需认证', 'No authentication')}</dd></div></dl>
      {connection.kind === 'custom' && <div className="decision-protocol-intro"><p>{t('扩展直接选择类别和模型组,可选评分仅用于观察;HiRoute 校验结果并执行候选选择、可用性接力与回退。', 'The extension selects the category and model group; optional scores are observation only. HiRoute validates the result and handles candidate selection, availability relay and fallback.')}</p><button className="btn" onClick={onProtocol}>{t('查看接入协议', 'View protocol')}</button></div>}
    </section>
    <section className="editor-section"><div className={'decision-test-result' + (result ? result.passed ? ' passed' : ' failed' : '')} role="status"><UiIcon name={busy ? 'clock' : result ? result.passed ? 'check' : 'warning' : 'plug'} /><div><strong>{busy ? t('正在处理连接…', 'Processing connection…') : result ? result.passed ? t('连接测试通过', 'Connection test passed') : savedBeforeTest ? t('配置已保存,测试失败', 'Configuration saved; test failed') : t('连接测试失败', 'Connection test failed') : t('本次打开尚未测试', 'Not tested during this visit')}</strong>{result && <p>{result.passed ? t(`配置版本 ${service.revision} · ${result.duration ?? '—'} ms · ${new Date(result.at).toLocaleTimeString()}`, `Configuration ${service.revision} · ${result.duration ?? '—'} ms · ${new Date(result.at).toLocaleTimeString()}`) : decisionFailureHelp(result.code ?? '', language)}</p>}{result?.code && <Disclosure label={t('诊断详情', 'Diagnostic details')} language={language}><code>{result.code}</code></Disclosure>}</div></div><div className="decision-test-actions"><button className="btn" disabled={!mutable || busy} onClick={onTest}><UiIcon name="refresh" />{t('测试连接', 'Test connection')}</button>{result && !result.passed && <button className="btn" disabled={!mutable || busy} onClick={onEdit}>{t('修改连接', 'Edit connection')}</button>}{onUse && <button className="btn btn-primary" disabled={busy} onClick={onUse}>{t('用于当前路由', 'Use in current route')}</button>}</div><p className="field-help">{t('发送固定示例验证连接,可能消耗供应商配额;不读取真实会话。测试结果仅对应此配置版本,不代表持续可用或实际路由质量。', 'Sends a fixed example to check the connection and may consume provider quota; no real conversation is read. Results apply to this version and do not establish ongoing availability or routing quality.')}</p></section>
    <section className="editor-section"><h3>{t('用于这些路由', 'Used by these routes')}</h3>{references.length ? <div className="decision-references">{references.map(reference => <button className="decision-reference" key={reference.key} onClick={() => onOpenRoute?.(reference.plan, reference.draft)} disabled={!onOpenRoute || busy}><UiIcon name="route" /><span>{reference.name || t('未命名草稿', 'Untitled draft')}<small>{reference.draft ? t('草稿', 'Draft') : t('已发布', 'Published')} · {t(`配置版本 ${reference.revision}`, `Configuration ${reference.revision}`)}</small></span><UiIcon name="chevronRight" /></button>)}</div> : <p className="field-help">{t('当前路由和草稿尚未使用此连接。', 'No current route or draft uses this connection.')}</p>}<p className="field-help">{t('更改连接后,需在路由中选用新版本并发布。此处不包含保留的历史版本引用。', 'After editing a connection, select the new version in a route and publish it. Retained historical references are not listed here.')}</p></section>
    <section className="editor-section"><Disclosure label={t('连接详情与更多操作', 'Connection details and more actions')} language={language}><dl className="decision-facts"><div><dt>{t('配置版本', 'Configuration version')}</dt><dd>{service.revision}</dd></div><div><dt>{t('决策超时', 'Decision timeout')}</dt><dd>{connection.timeout_ms / 1000} {t('秒', 'seconds')}</dd></div></dl><button className="btn btn-danger" disabled={!mutable || busy} onClick={onDelete}><UiIcon name="trash" />{t('删除连接', 'Delete connection')}</button></Disclosure></section>
  </>;
}