|
|
@@ -8,7 +8,8 @@ import { researchElapsed } from "./progress"
|
|
|
import { externalToolPhase, researchToolLabel } from "./tool-label"
|
|
|
import { useDialog } from "@opencode-ai/ui/context/dialog"
|
|
|
import { ResearchIssue } from "./issue"
|
|
|
-import { resolveAgentProfile } from "./agent-profiles"
|
|
|
+import { directAgents, resolveAgentProfile } from "./agent-profiles"
|
|
|
+import { routeAgent } from "./agent-routing"
|
|
|
import { ReportReader } from "./report-reader"
|
|
|
import { Icon } from "@opencode-ai/ui/icon"
|
|
|
import { usePlatform } from "@/context/platform"
|
|
|
@@ -84,6 +85,7 @@ export function PaasChat(props: {
|
|
|
expandedGroups: {} as Record<string, boolean>,
|
|
|
renaming: false,
|
|
|
title: "",
|
|
|
+ agentOverride: "",
|
|
|
exporting: "",
|
|
|
saved: "",
|
|
|
savedPath: "",
|
|
|
@@ -103,6 +105,7 @@ export function PaasChat(props: {
|
|
|
return props.legacyScope
|
|
|
},
|
|
|
projectID: () => props.projectID,
|
|
|
+ agents: () => props.agents,
|
|
|
windowID: platform.windowID,
|
|
|
onNotice: (notice) => {
|
|
|
setUI("notices", (rows) => [
|
|
|
@@ -120,6 +123,25 @@ export function PaasChat(props: {
|
|
|
})
|
|
|
const { state, setState, current } = model
|
|
|
const currentAgent = createMemo(() => props.agents.find((agent) => agent.id === current()?.agentID))
|
|
|
+ const blank = () => !!current() && !current()!.messages.length && !current()!.threadID
|
|
|
+ const routed = createMemo(() =>
|
|
|
+ routeAgent({
|
|
|
+ goal: current()?.draft || "",
|
|
|
+ files: current()?.files,
|
|
|
+ workspace: props.workspace,
|
|
|
+ agents: directAgents(props.agents),
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ const routedAgent = createMemo(() => props.agents.find((agent) => paasText(agent.id) === routed().agentID))
|
|
|
+ const overrideAgent = createMemo(() => props.agents.find((agent) => paasText(agent.id) === ui.agentOverride))
|
|
|
+ const activeAgent = createMemo(() => (blank() ? overrideAgent() || routedAgent() : currentAgent()))
|
|
|
+ const routeLabel = createMemo(() => paasText(activeAgent()?.name) || "自动选择")
|
|
|
+ createEffect(
|
|
|
+ on(
|
|
|
+ () => current()?.id,
|
|
|
+ () => setUI("agentOverride", ""),
|
|
|
+ ),
|
|
|
+ )
|
|
|
const currentTitle = createMemo(() => current()?.title || paasText(currentAgent()?.name) || "科研工作台")
|
|
|
createEffect(
|
|
|
on(
|
|
|
@@ -352,12 +374,15 @@ export function PaasChat(props: {
|
|
|
if (id) setState("chats", (c) => c.id === id, "draft", value)
|
|
|
}
|
|
|
const send = () => {
|
|
|
- const profile = currentAgent() ? resolveAgentProfile(currentAgent()!) : undefined
|
|
|
+ const target = blank() ? activeAgent() : currentAgent()
|
|
|
+ const profile = target ? resolveAgentProfile(target) : undefined
|
|
|
if (profile?.requiresWorkspace && !props.workspace) {
|
|
|
setState("error", "工作区助手需要先为当前项目绑定工作文件夹。")
|
|
|
return
|
|
|
}
|
|
|
if (current() && !materials.busy(current()!.id)) {
|
|
|
+ const agentID = target ? paasText(target.id) : ""
|
|
|
+ if (blank() && agentID) model.route(agentID)
|
|
|
bottom()
|
|
|
void model.send(profile?.requiresWorkspace ? props.workspace : undefined)
|
|
|
}
|
|
|
@@ -1104,22 +1129,34 @@ export function PaasChat(props: {
|
|
|
}}
|
|
|
/>
|
|
|
<footer>
|
|
|
- <label class="paas-agent-picker">
|
|
|
- 智能体
|
|
|
- <select
|
|
|
- aria-label="选择智能体"
|
|
|
- title={currentAgent()?.name ? paasText(currentAgent()?.name) : undefined}
|
|
|
- value={current()?.agentID || ""}
|
|
|
- onChange={(event) => {
|
|
|
- const agent = props.agents.find((a) => a.id === event.currentTarget.value)
|
|
|
- if (agent) model.choose(agent)
|
|
|
- }}
|
|
|
- >
|
|
|
- <For each={props.agents}>
|
|
|
- {(agent) => <option value={paasText(agent.id)}>{paasText(agent.name)}</option>}
|
|
|
- </For>
|
|
|
- </select>
|
|
|
- </label>
|
|
|
+ <details class="paas-agent-route">
|
|
|
+ <summary title={routeLabel()}>
|
|
|
+ {blank() ? (overrideAgent() ? "指定" : "自动") : "当前"} · {routeLabel()}
|
|
|
+ </summary>
|
|
|
+ <div class="paas-agent-route-panel">
|
|
|
+ <p class="paas-muted">
|
|
|
+ {blank() ? routed().reason : "已有会话沿用当前智能体;新会话会按目标自动选择。"}
|
|
|
+ </p>
|
|
|
+ <select
|
|
|
+ aria-label="选择执行角色"
|
|
|
+ disabled={!blank()}
|
|
|
+ value={activeAgent() ? paasText(activeAgent()!.id) : routed().agentID}
|
|
|
+ onInput={(event) => {
|
|
|
+ const value = event.currentTarget.value
|
|
|
+ if (!model.route(value)) {
|
|
|
+ setState("error", "已有会话不能切换智能体,请新建会话后再选择。")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ setUI("agentOverride", value)
|
|
|
+ event.currentTarget.closest("details")?.removeAttribute("open")
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <For each={directAgents(props.agents)}>
|
|
|
+ {(agent) => <option value={paasText(agent.id)}>{paasText(agent.name)}</option>}
|
|
|
+ </For>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ </details>
|
|
|
<Show when={ui.efforts.length}>
|
|
|
<label>
|
|
|
推理强度
|
|
|
@@ -1145,7 +1182,7 @@ export function PaasChat(props: {
|
|
|
aria-label="发送消息"
|
|
|
disabled={
|
|
|
!props.connected ||
|
|
|
- !currentAgent() ||
|
|
|
+ !activeAgent() ||
|
|
|
(!current()?.draft.trim() && !current()?.reference?.text) ||
|
|
|
!!model.job() ||
|
|
|
(!!current() && materials.busy(current()!.id))
|