feat(subagent): 实验功能设置新增子代理模型配置
- 子代理设置页支持选择次主力模型,仅保存模型引用(不再写补丁字段), 子代理直接继承所选模型的上下文长度与思考模式 - 界面只读展示继承的上下文长度与思考模式,移除补丁编辑项 - 仪表盘统计识别子代理请求(__secondary__):归为「子代理模型(估算)」 并缓存次主力模型定价;自定义网关模型价格按官方同名模型跨 provider 匹配 - bump v0.7.1
This commit is contained in:
1 parent
8b0daabd95
commit
8aed04898c
22 files changed
+16648
-8882
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslation } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n/zh";
|
||||
import { getAgentSettings, setAgentSettings } from "../lib/agent-settings";
|
||||
import type { AgentSettings, Hook, PermissionRule } from "../types";
|
||||
import { Card, Checkbox, NumberField, Segmented } from "./ui/controls";
|
||||
|
||||
interface AgentSettingsPanelProps {
|
||||
rawOther: unknown;
|
||||
@@ -275,102 +275,3 @@ export function AgentSettingsPanel({ rawOther, onChange }: AgentSettingsPanelPro
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-xl p-4 space-y-3">
|
||||
<h4 className="text-content-muted text-sm font-medium">{title}</h4>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Checkbox({
|
||||
label,
|
||||
checked,
|
||||
disabled,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
disabled?: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
}) {
|
||||
return (
|
||||
<label
|
||||
className={`flex items-center gap-2 text-sm ${
|
||||
disabled ? "text-content-muted" : "text-content-primary"
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
className="rounded border-border bg-input text-blue-600 focus:ring-blue-500"
|
||||
/>
|
||||
{label}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function NumberField({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value?: number;
|
||||
onChange: (value: number | undefined) => void;
|
||||
}) {
|
||||
return (
|
||||
<label className="flex items-center gap-3 text-sm text-content-primary">
|
||||
<span className="text-content-muted">{label}</span>
|
||||
<input
|
||||
type="number"
|
||||
value={value ?? ""}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
onChange(raw === "" ? undefined : Number(raw));
|
||||
}}
|
||||
className="w-32 bg-input border border-border rounded px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function Segmented({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
options: { key: string; label: string }[];
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center rounded overflow-hidden border border-border ${
|
||||
disabled ? "opacity-50" : ""
|
||||
}`}
|
||||
>
|
||||
{options.map((opt) => (
|
||||
<button
|
||||
key={opt.key}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(opt.key)}
|
||||
className={`px-3 py-1 text-sm ${
|
||||
value === opt.key
|
||||
? "bg-blue-600 text-white"
|
||||
: "bg-input text-content-muted hover:bg-hover-2"
|
||||
}`}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useTranslation } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n/zh";
|
||||
import type { ExperimentalEnvStatus, Model } from "../types";
|
||||
import {
|
||||
EXPERIMENTAL_FLAGS,
|
||||
clearSecondaryModel,
|
||||
forcedEnvValue,
|
||||
getExperimentalFlags,
|
||||
getSecondaryModel,
|
||||
isFlagLockedByEnv,
|
||||
isMasterEnvOn,
|
||||
setExperimentalFlag,
|
||||
setSecondaryModelOnly,
|
||||
type ExperimentalFlagDef,
|
||||
} from "../lib/subagent-settings";
|
||||
import { Card, Checkbox } from "./ui/controls";
|
||||
|
||||
interface SubagentSettingsPageProps {
|
||||
/** config.raw_other — hosts the `[experimental]` and `[secondary_model]` sections. */
|
||||
rawOther: unknown;
|
||||
/** All configured models (alias → entry) for the secondary-model picker. */
|
||||
models: Record<string, Model>;
|
||||
onChange: (nextRawOther: unknown) => void;
|
||||
onBack: () => void;
|
||||
}
|
||||
|
||||
const EFFORTS = ["low", "medium", "high", "max"] as const;
|
||||
const EFFORT_LABELS: Record<(typeof EFFORTS)[number], TranslationKey> = {
|
||||
low: "thinkingLow",
|
||||
medium: "thinkingMedium",
|
||||
high: "thinkingHigh",
|
||||
max: "thinkingMax",
|
||||
};
|
||||
|
||||
const FLAG_LABELS: Record<string, { name: TranslationKey; desc: TranslationKey }> = {
|
||||
"secondary-model": { name: "flagSecondaryModel", desc: "flagSecondaryModelDesc" },
|
||||
"tool-select": { name: "flagToolSelect", desc: "flagToolSelectDesc" },
|
||||
"acp-v2": { name: "flagAcpV2", desc: "flagAcpV2Desc" },
|
||||
persistence_minidb_readmodel: {
|
||||
name: "flagMinidbReadmodel",
|
||||
desc: "flagMinidbReadmodelDesc",
|
||||
},
|
||||
};
|
||||
|
||||
export function SubagentSettingsPage({
|
||||
rawOther,
|
||||
models,
|
||||
onChange,
|
||||
onBack,
|
||||
}: SubagentSettingsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [env, setEnv] = useState<ExperimentalEnvStatus | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
invoke<ExperimentalEnvStatus>("get_experimental_env_status")
|
||||
.then(setEnv)
|
||||
.catch(() => setEnv({}));
|
||||
}, []);
|
||||
|
||||
const flags = getExperimentalFlags(rawOther);
|
||||
const secondary = getSecondaryModel(rawOther);
|
||||
const masterOn = isMasterEnvOn(env);
|
||||
const secondaryFlag = EXPERIMENTAL_FLAGS[0]; // "secondary-model"
|
||||
const otherFlags = EXPERIMENTAL_FLAGS.slice(1);
|
||||
|
||||
/** Effective state of the secondary-model flag (env overrides config). */
|
||||
const secondaryEnabled = masterOn
|
||||
? true
|
||||
: isFlagLockedByEnv(env, secondaryFlag)
|
||||
? forcedEnvValue(env, secondaryFlag)
|
||||
: flags["secondary-model"] === true;
|
||||
|
||||
const aliasList = Object.keys(models).sort();
|
||||
|
||||
// Inherited settings shown for the picked model: subagents bind the pointed
|
||||
// entry directly (no patch fields), so context size and effort come from the
|
||||
// model entry / global [thinking], not from a `[secondary_model]` patch.
|
||||
const selectedEntry = secondary.model ? models[secondary.model] : undefined;
|
||||
const inheritedContext = selectedEntry?.max_context_size;
|
||||
const modelEffort =
|
||||
selectedEntry &&
|
||||
typeof (selectedEntry.raw_other as Record<string, unknown> | undefined)
|
||||
?.default_effort === "string"
|
||||
? ((selectedEntry.raw_other as Record<string, unknown>).default_effort as string)
|
||||
: undefined;
|
||||
const thinkingEffort = (() => {
|
||||
const ro = rawOther as Record<string, unknown> | undefined;
|
||||
const thinking = ro?.thinking as Record<string, unknown> | undefined;
|
||||
return thinking && typeof thinking.effort === "string" && thinking.effort
|
||||
? thinking.effort
|
||||
: undefined;
|
||||
})();
|
||||
const inheritedEffort = modelEffort ?? thinkingEffort;
|
||||
|
||||
const fmtContext = (n: number): string =>
|
||||
n >= 1_000_000
|
||||
? `${(n / 1_000_000).toFixed(1)}M`
|
||||
: n >= 1000
|
||||
? `${Math.round(n / 1000)}K`
|
||||
: String(n);
|
||||
const effortLabel = (e: string): string => {
|
||||
const key = EFFORT_LABELS[e as (typeof EFFORTS)[number]];
|
||||
return key ? t(key) : e;
|
||||
};
|
||||
|
||||
const renderFlagRow = (flag: ExperimentalFlagDef) => {
|
||||
const labels = FLAG_LABELS[flag.id];
|
||||
const locked = masterOn || isFlagLockedByEnv(env, flag);
|
||||
const on = masterOn
|
||||
? true
|
||||
: isFlagLockedByEnv(env, flag)
|
||||
? forcedEnvValue(env, flag)
|
||||
: flags[flag.id] === true;
|
||||
return (
|
||||
<div key={flag.id} className="flex items-center gap-3">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm text-content-primary">{t(labels.name)}</div>
|
||||
<div className="text-xs text-content-muted">
|
||||
{t(labels.desc)}
|
||||
<code className="ml-2">{flag.envVar}</code>
|
||||
</div>
|
||||
</div>
|
||||
{locked && (
|
||||
<span className="text-xs text-content-muted shrink-0">
|
||||
🔒 {t("lockedByEnv")}
|
||||
</span>
|
||||
)}
|
||||
<Checkbox
|
||||
label=""
|
||||
checked={on}
|
||||
disabled={locked}
|
||||
onChange={(checked) =>
|
||||
onChange(setExperimentalFlag(rawOther, flag.id, checked))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col bg-app">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-3 px-4 py-3 border-b border-border bg-panel">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onBack}
|
||||
className="p-2 rounded-lg hover:bg-hover-2 focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
>
|
||||
← {t("back")}
|
||||
</button>
|
||||
<h2 className="font-semibold text-lg">{t("subagentSettings")}</h2>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-auto p-6 space-y-4">
|
||||
{masterOn && (
|
||||
<div className="bg-green-100 dark:bg-green-900/20 border border-green-300 dark:border-green-500/30 rounded-lg px-4 py-2 text-sm text-green-700 dark:text-green-400">
|
||||
{t("masterEnvOnHint")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Subagent: experimental flag + secondary model in one card */}
|
||||
<Card title={t("secondaryModelSection")}>
|
||||
{renderFlagRow(secondaryFlag)}
|
||||
<div className="border-t border-border" />
|
||||
|
||||
{!secondaryEnabled && (
|
||||
<div className="bg-amber-100 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-500/30 rounded-lg px-3 py-2 text-sm text-amber-800 dark:text-amber-400">
|
||||
{t("secondaryModelDisabledHint")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<label className="flex items-center gap-3 text-sm text-content-primary">
|
||||
<span className="text-content-muted">{t("secondaryModelLabel")}</span>
|
||||
<select
|
||||
className="flex-1 max-w-md bg-input border border-border rounded px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
value={secondary.model ?? ""}
|
||||
onChange={(e) => {
|
||||
const alias = e.target.value;
|
||||
if (alias === "") {
|
||||
onChange(clearSecondaryModel(rawOther));
|
||||
} else {
|
||||
// Only the model reference is persisted — no patch fields.
|
||||
// Subagents bind the pointed entry directly and inherit its
|
||||
// settings; usage records stay keyed on the real alias
|
||||
// instead of Kimi Code's synthesized `__secondary__` entry.
|
||||
onChange(setSecondaryModelOnly(rawOther, alias));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option value="">{t("secondaryModelUnset")}</option>
|
||||
{aliasList.map((alias) => (
|
||||
<option key={alias} value={alias}>
|
||||
{models[alias]?.display_name
|
||||
? `${alias}(${models[alias].display_name})`
|
||||
: alias}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{secondary.model !== undefined && (
|
||||
<div className="rounded-lg border border-border bg-input/40 px-3 py-2 space-y-1.5">
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<span className="text-content-muted w-24 shrink-0">
|
||||
{t("secondaryModelInheritedContext")}
|
||||
</span>
|
||||
<span className="text-content-primary">
|
||||
{inheritedContext ? fmtContext(inheritedContext) : "—"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<span className="text-content-muted w-24 shrink-0">
|
||||
{t("secondaryModelInheritedEffort")}
|
||||
</span>
|
||||
<span className="text-content-primary">
|
||||
{inheritedEffort ? effortLabel(inheritedEffort) : "—"}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-content-muted">
|
||||
{t("secondaryModelInheritedHint")}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<p className="text-xs text-content-muted">{t("secondaryModelHint")}</p>
|
||||
<p className="text-xs text-content-muted">{t("secondaryModelPriorityHint")}</p>
|
||||
</Card>
|
||||
|
||||
{/* Other experimental features (not subagent-related) */}
|
||||
<Card title={t("otherExperimentalFlags")}>
|
||||
{otherFlags.map(renderFlagRow)}
|
||||
<p className="text-xs text-content-muted">{t("experimentalFlagsHint")}</p>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -59,6 +59,10 @@ export function DailyBars({ daily, dimension, names, unknownProviderLabel }: Dai
|
||||
if (dimension === "provider") {
|
||||
return key === "unknown" ? unknownProviderLabel : key;
|
||||
}
|
||||
// Subagent records (Kimi Code `__secondary__` marker) show their own label.
|
||||
if (key === "__secondary__") {
|
||||
return t("subagentModel");
|
||||
}
|
||||
return shortModel(key);
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ export function DailyDetailModal({ day, dimension, colorMap, unknownProviderLabe
|
||||
const { t } = useTranslation();
|
||||
const { money } = useCurrency();
|
||||
|
||||
/** Subagent records (Kimi Code `__secondary__` marker) show their own label. */
|
||||
const modelName = (model: string) =>
|
||||
model === "__secondary__" ? t("subagentModel") : shortModel(model);
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") onClose();
|
||||
@@ -143,7 +147,7 @@ export function DailyDetailModal({ day, dimension, colorMap, unknownProviderLabe
|
||||
<div className="mt-1 ml-5 space-y-0.5">
|
||||
{p.models.map((m) => (
|
||||
<div key={m.model} className="flex items-baseline justify-between gap-2 text-xs">
|
||||
<span className="truncate text-content-muted" title={m.model}>{shortModel(m.model)}</span>
|
||||
<span className="truncate text-content-muted" title={m.model}>{modelName(m.model)}</span>
|
||||
<span className="shrink-0 text-content-muted tabular-nums">{fmtTokens(m.tokens)}</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -167,7 +171,7 @@ export function DailyDetailModal({ day, dimension, colorMap, unknownProviderLabe
|
||||
<span className="inline-block h-2.5 w-2.5 rounded-sm shrink-0" style={{ backgroundColor: modelColor(i) }} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<span className="truncate text-content-primary" title={s.model}>{shortModel(s.model)}</span>
|
||||
<span className="truncate text-content-primary" title={s.model}>{modelName(s.model)}</span>
|
||||
<span className="shrink-0 text-xs text-content-muted tabular-nums">
|
||||
{fmtTokens(s.tokens)} <span className="text-content-muted">· {s.pct.toFixed(1)}%</span>
|
||||
</span>
|
||||
|
||||
@@ -310,7 +310,9 @@ export function DashboardPage() {
|
||||
}}
|
||||
/>
|
||||
<div className="flex items-center gap-1.5 min-w-0">
|
||||
<span className="text-content-primary whitespace-nowrap truncate">{m.modelDisplay || m.model}</span>
|
||||
<span className="text-content-primary whitespace-nowrap truncate">
|
||||
{m.isSecondary ? t("subagentModel") : m.modelDisplay || m.model}
|
||||
</span>
|
||||
{m.costEstimated && (
|
||||
<span className="text-[10px] text-yellow-600 shrink-0">({t("estimate")})</span>
|
||||
)}
|
||||
@@ -371,7 +373,13 @@ export function DashboardPage() {
|
||||
<td className="py-1.5 pr-4 text-content-muted whitespace-nowrap">
|
||||
{fmtTime(r.time)}
|
||||
</td>
|
||||
<td className="py-1.5 pr-4 text-content-primary">{r.modelDisplay || r.model}</td>
|
||||
<td className="py-1.5 pr-4 text-content-primary">
|
||||
<span className="flex items-center gap-1.5 min-w-0">
|
||||
<span className="truncate">
|
||||
{r.isSecondary ? t("subagentModel") : r.modelDisplay || r.model}
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-1.5 pr-4 text-right text-content-muted">{fmtTokens(r.inputOther)}</td>
|
||||
<td className="py-1.5 pr-4 text-right text-content-muted">{fmtTokens(r.output)}</td>
|
||||
<td className="py-1.5 pr-4 text-right text-content-muted">{fmtTokens(r.inputCacheRead)}</td>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
/** Shared small form controls used by settings panels (Agent settings,
|
||||
* Subagent settings, ...). Extracted from AgentSettingsPanel.tsx so new
|
||||
* panels can reuse the same look without duplicating code. */
|
||||
|
||||
export function Card({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-xl p-4 space-y-3">
|
||||
<h4 className="text-content-muted text-sm font-medium">{title}</h4>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Checkbox({
|
||||
label,
|
||||
checked,
|
||||
disabled,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
disabled?: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
}) {
|
||||
return (
|
||||
<label
|
||||
className={`flex items-center gap-2 text-sm ${
|
||||
disabled ? "text-content-muted" : "text-content-primary"
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
className="rounded border-border bg-input text-blue-600 focus:ring-blue-500"
|
||||
/>
|
||||
{label}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
export function NumberField({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value?: number;
|
||||
onChange: (value: number | undefined) => void;
|
||||
}) {
|
||||
return (
|
||||
<label className="flex items-center gap-3 text-sm text-content-primary">
|
||||
<span className="text-content-muted">{label}</span>
|
||||
<input
|
||||
type="number"
|
||||
value={value ?? ""}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
onChange(raw === "" ? undefined : Number(raw));
|
||||
}}
|
||||
className="w-32 bg-input border border-border rounded px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
export function Segmented({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
options: { key: string; label: string }[];
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center rounded overflow-hidden border border-border ${
|
||||
disabled ? "opacity-50" : ""
|
||||
}`}
|
||||
>
|
||||
{options.map((opt) => (
|
||||
<button
|
||||
key={opt.key}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(opt.key)}
|
||||
className={`px-3 py-1 text-sm ${
|
||||
value === opt.key
|
||||
? "bg-blue-600 text-white"
|
||||
: "bg-input text-content-muted hover:bg-hover-2"
|
||||
}`}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user