mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-03 19:20:07 +02:00
feat(agent): inspector picker for thinking_level (MUL-2339)
PR1 (#2865) shipped the backend — column, daemon-side discovery, Claude/Codex injection, API validation — but the agent detail inspector had no UI to set the value. Users could only configure thinking_level via custom_env / API. This wires up the picker so it lives next to Runtime and Model where everything else editable already lives. Picker is per-(runtime, model): it reuses the same `runtimeModelsOptions` query the Model picker already runs (60s cache, no extra round-trip) and reads the active model's `thinking.supported_levels`. When the list is empty — every provider except Claude/Codex today, or a Claude model that doesn't expose `--effort` — the entire PropRow is hidden, not just rendered inert. The picker never gets to invent value/label pairs itself; they come verbatim from each CLI's own catalog (`Low`, `Extra high`, …) so the user sees exactly what `claude --effort` / `/effort` and Codex's TUI show. The `default_level` from the catalog is badged inside the popover so the user knows which value `""` (the persisted "use model default" sentinel) maps to. The clear footer sends `""` explicitly, which the backend already understands as the tri-state "explicit clear" branch of UpdateAgent. Invalid combinations (e.g. picking a value not in the target provider's enum after a runtime swap in the same PATCH) hit the existing 400 path on the server and surface as a toast via the inspector's standard `onUpdate` error handler — no extra client-side guard needed. Exports `RuntimeModelThinking` and `RuntimeModelThinkingLevel` from `@multica/core/types` so views consumers can refer to them by name. i18n keys added in EN and zh-Hans (parity test green). Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -36,6 +36,8 @@ export type {
|
||||
RuntimeUpdate,
|
||||
RuntimeUpdateStatus,
|
||||
RuntimeModel,
|
||||
RuntimeModelThinking,
|
||||
RuntimeModelThinkingLevel,
|
||||
RuntimeModelListRequest,
|
||||
RuntimeModelListStatus,
|
||||
RuntimeModelsResult,
|
||||
|
||||
@@ -8,10 +8,12 @@ import {
|
||||
} from "react";
|
||||
import { Camera, Loader2, Pencil } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type {
|
||||
Agent,
|
||||
AgentRuntime,
|
||||
MemberWithUser,
|
||||
RuntimeModel,
|
||||
} from "@multica/core/types";
|
||||
import {
|
||||
AGENT_DESCRIPTION_MAX_LENGTH,
|
||||
@@ -19,6 +21,7 @@ import {
|
||||
} from "@multica/core/agents";
|
||||
import { api } from "@multica/core/api";
|
||||
import { useFileUpload } from "@multica/core/hooks/use-file-upload";
|
||||
import { runtimeModelsOptions } from "@multica/core/runtimes";
|
||||
import { isImeComposing, timeAgo } from "@multica/core/utils";
|
||||
import { Button } from "@multica/ui/components/ui/button";
|
||||
import { ActorAvatar } from "../../common/actor-avatar";
|
||||
@@ -43,6 +46,7 @@ import { ConcurrencyPicker } from "./inspector/concurrency-picker";
|
||||
import { ModelPicker } from "./inspector/model-picker";
|
||||
import { RuntimePicker } from "./inspector/runtime-picker";
|
||||
import { SkillAttach } from "./inspector/skill-attach";
|
||||
import { ThinkingPicker } from "./inspector/thinking-picker";
|
||||
import { VisibilityPicker } from "./inspector/visibility-picker";
|
||||
|
||||
interface InspectorProps {
|
||||
@@ -130,6 +134,14 @@ export function AgentDetailInspector({
|
||||
onChange={(m) => update({ model: m })}
|
||||
/>
|
||||
</PropRow>
|
||||
<ThinkingPropRow
|
||||
runtimeId={agent.runtime_id}
|
||||
runtimeOnline={!!isOnline}
|
||||
model={agent.model ?? ""}
|
||||
value={agent.thinking_level ?? ""}
|
||||
canEdit={canEdit}
|
||||
onChange={(v) => update({ thinking_level: v })}
|
||||
/>
|
||||
<PropRow label={t(($) => $.inspector.prop_visibility)} interactive={false}>
|
||||
<VisibilityPicker
|
||||
value={agent.visibility}
|
||||
@@ -221,6 +233,59 @@ function Section({
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Thinking row — hidden entirely when the active model has no
|
||||
// `supported_levels` advertised. Reuses the shared runtime-models query so
|
||||
// it hits the same 60s cache as the model picker; no extra round-trip on
|
||||
// the inspector's hot path.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function ThinkingPropRow({
|
||||
runtimeId,
|
||||
runtimeOnline,
|
||||
model,
|
||||
value,
|
||||
canEdit,
|
||||
onChange,
|
||||
}: {
|
||||
runtimeId: string | null;
|
||||
runtimeOnline: boolean;
|
||||
model: string;
|
||||
value: string;
|
||||
canEdit: boolean;
|
||||
onChange: (next: string) => Promise<void> | void;
|
||||
}) {
|
||||
const { t } = useT("agents");
|
||||
const modelsQuery = useQuery(
|
||||
runtimeModelsOptions(runtimeOnline ? runtimeId : null),
|
||||
);
|
||||
|
||||
const models = modelsQuery.data?.models ?? [];
|
||||
const entry = pickModelEntry(models, model);
|
||||
const levels = entry?.thinking?.supported_levels ?? [];
|
||||
if (levels.length === 0) return null;
|
||||
|
||||
return (
|
||||
<PropRow label={t(($) => $.inspector.prop_thinking)} interactive={false}>
|
||||
<ThinkingPicker
|
||||
value={value}
|
||||
levels={levels}
|
||||
defaultLevel={entry?.thinking?.default_level}
|
||||
canEdit={canEdit}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</PropRow>
|
||||
);
|
||||
}
|
||||
|
||||
function pickModelEntry(
|
||||
models: RuntimeModel[],
|
||||
model: string,
|
||||
): RuntimeModel | undefined {
|
||||
if (model) return models.find((m) => m.id === model);
|
||||
return models.find((m) => m.default) ?? models[0];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Identity — avatar / name / description editors
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
127
packages/views/agents/components/inspector/thinking-picker.tsx
Normal file
127
packages/views/agents/components/inspector/thinking-picker.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import type { RuntimeModelThinkingLevel } from "@multica/core/types";
|
||||
import {
|
||||
PickerItem,
|
||||
PropertyPicker,
|
||||
} from "../../../issues/components/pickers";
|
||||
import { CHIP_CLASS } from "./chip";
|
||||
import { useT } from "../../../i18n";
|
||||
|
||||
/**
|
||||
* Per-agent reasoning/effort picker (MUL-2339). Renders only when the
|
||||
* current model exposes a non-empty `supported_levels` set — Claude and
|
||||
* Codex today; every other provider gets nothing. The catalog is daemon-
|
||||
* discovered, so the value/label pairs match each CLI's own UI (`Low`,
|
||||
* `Extra high`, …) verbatim; never normalised across providers.
|
||||
*
|
||||
* The empty string is the "use model default" sentinel and renders as
|
||||
* "Default" in the chip, with the discovered `default_level` (when
|
||||
* present) badged inside the popover so the user can see what they'll
|
||||
* get if they clear.
|
||||
*/
|
||||
export function ThinkingPicker({
|
||||
value,
|
||||
levels,
|
||||
defaultLevel,
|
||||
canEdit = true,
|
||||
onChange,
|
||||
}: {
|
||||
/** Persisted thinking_level — "" means "use model default". */
|
||||
value: string;
|
||||
/** Supported levels for the current (runtime, model) pair. Caller has
|
||||
* already verified the list is non-empty before mounting this picker. */
|
||||
levels: RuntimeModelThinkingLevel[];
|
||||
/** Level the runtime uses when no override is sent. Surfaced as a badge
|
||||
* in the popover. */
|
||||
defaultLevel?: string;
|
||||
/** When false, render a static read-only display and skip the popover. */
|
||||
canEdit?: boolean;
|
||||
onChange: (next: string) => Promise<void> | void;
|
||||
}) {
|
||||
const { t } = useT("agents");
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const selected = value ? levels.find((l) => l.value === value) : undefined;
|
||||
const triggerLabel = selected
|
||||
? selected.label
|
||||
: t(($) => $.pickers.thinking_default);
|
||||
const triggerTitle = t(($) => $.pickers.thinking_tooltip, {
|
||||
value: triggerLabel,
|
||||
});
|
||||
|
||||
const select = async (next: string) => {
|
||||
setOpen(false);
|
||||
if (next !== value) await onChange(next);
|
||||
};
|
||||
|
||||
if (!canEdit) {
|
||||
return (
|
||||
<span
|
||||
className="min-w-0 truncate px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground"
|
||||
title={triggerTitle}
|
||||
>
|
||||
{triggerLabel}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PropertyPicker
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
width="w-auto min-w-[14rem] max-w-md"
|
||||
align="start"
|
||||
tooltip={triggerTitle}
|
||||
triggerRender={
|
||||
<button
|
||||
type="button"
|
||||
className={CHIP_CLASS}
|
||||
aria-label={triggerTitle}
|
||||
/>
|
||||
}
|
||||
trigger={
|
||||
<span className="min-w-0 truncate font-mono text-[11px]">
|
||||
{triggerLabel}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
{levels.map((l) => (
|
||||
<PickerItem
|
||||
key={l.value}
|
||||
selected={l.value === value}
|
||||
onClick={() => void select(l.value)}
|
||||
tooltip={l.description || (l.label !== l.value ? `${l.label} · ${l.value}` : l.value)}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate font-medium">{l.label}</span>
|
||||
{l.value === defaultLevel && (
|
||||
<span className="shrink-0 rounded bg-primary/10 px-1 text-[10px] font-medium text-primary">
|
||||
{t(($) => $.pickers.thinking_default_badge)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{l.description && (
|
||||
<div className="truncate text-[10px] text-muted-foreground">
|
||||
{l.description}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PickerItem>
|
||||
))}
|
||||
|
||||
{value && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void select("")}
|
||||
className="mt-1 flex w-full items-center border-t px-3 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-accent/50"
|
||||
title={t(($) => $.pickers.thinking_clear_title)}
|
||||
>
|
||||
{t(($) => $.pickers.thinking_clear)}
|
||||
</button>
|
||||
)}
|
||||
</PropertyPicker>
|
||||
);
|
||||
}
|
||||
@@ -130,6 +130,7 @@
|
||||
"section_skills": "Skills",
|
||||
"prop_runtime": "Runtime",
|
||||
"prop_model": "Model",
|
||||
"prop_thinking": "Thinking",
|
||||
"prop_visibility": "Visibility",
|
||||
"prop_concurrency": "Concurrency",
|
||||
"prop_owner": "Owner",
|
||||
@@ -172,7 +173,12 @@
|
||||
"model_custom_tooltip": "Use \"{{value}}\" as a custom model id",
|
||||
"model_custom_use": "Use \"{{value}}\"",
|
||||
"model_clear": "Clear (use provider default)",
|
||||
"model_clear_title": "Clear and fall back to the runtime's provider default"
|
||||
"model_clear_title": "Clear and fall back to the runtime's provider default",
|
||||
"thinking_default": "Default",
|
||||
"thinking_tooltip": "Thinking · {{value}}",
|
||||
"thinking_default_badge": "default",
|
||||
"thinking_clear": "Use model default",
|
||||
"thinking_clear_title": "Clear and fall back to this model's default reasoning level"
|
||||
},
|
||||
"model_dropdown": {
|
||||
"label": "Model",
|
||||
|
||||
@@ -126,6 +126,7 @@
|
||||
"section_skills": "skill",
|
||||
"prop_runtime": "运行时",
|
||||
"prop_model": "模型",
|
||||
"prop_thinking": "思考",
|
||||
"prop_visibility": "可见性",
|
||||
"prop_concurrency": "并发",
|
||||
"prop_owner": "所有者",
|
||||
@@ -168,7 +169,12 @@
|
||||
"model_custom_tooltip": "使用\"{{value}}\"作为自定义模型 ID",
|
||||
"model_custom_use": "使用\"{{value}}\"",
|
||||
"model_clear": "清除(使用提供方默认)",
|
||||
"model_clear_title": "清除并回退到运行时的提供方默认"
|
||||
"model_clear_title": "清除并回退到运行时的提供方默认",
|
||||
"thinking_default": "默认",
|
||||
"thinking_tooltip": "思考 · {{value}}",
|
||||
"thinking_default_badge": "默认",
|
||||
"thinking_clear": "使用模型默认",
|
||||
"thinking_clear_title": "清除并回退到该模型的默认推理级别"
|
||||
},
|
||||
"model_dropdown": {
|
||||
"label": "模型",
|
||||
|
||||
Reference in New Issue
Block a user