|
|
@@ -9,6 +9,7 @@ import { ResearchIcon } from "./research-icon"
|
|
|
import { PaasActivity, paasActivityItems } from "./activity"
|
|
|
import { researchElapsed } from "./progress"
|
|
|
import { externalToolPhase, researchToolLabel } from "./tool-label"
|
|
|
+import { Dialog } from "@opencode-ai/ui/dialog"
|
|
|
import { useDialog } from "@opencode-ai/ui/context/dialog"
|
|
|
import { ResearchIssue } from "./issue"
|
|
|
import { directAgents, resolveAgentProfile } from "./agent-profiles"
|
|
|
@@ -42,6 +43,7 @@ import { PaasGeneratedFiles } from "./generated-files"
|
|
|
import type { PaasPreviewFile } from "./preview"
|
|
|
import { buildInbox, type InboxItem, type InboxProject } from "./inbox"
|
|
|
import { inboxSeenKey, markInboxSeen, readInboxSeen } from "./inbox-seen"
|
|
|
+import { DelegatedConversation } from "./delegated-conversation"
|
|
|
import { TaskScope } from "./task-scope"
|
|
|
import { projectFolders } from "./projects"
|
|
|
import { InboxPanel } from "./inbox-panel"
|
|
|
@@ -242,29 +244,13 @@ export function PaasChat(props: {
|
|
|
const life = { active: true, epoch: 0 }
|
|
|
const elements: { messages?: HTMLDivElement; content?: HTMLDivElement; input?: HTMLTextAreaElement } = {}
|
|
|
let moreActions: HTMLDetailsElement | undefined
|
|
|
- let routeMenu: HTMLDetailsElement | undefined
|
|
|
- createEffect(
|
|
|
- on(
|
|
|
- () => current()?.id,
|
|
|
- () => {
|
|
|
- if (routeMenu) routeMenu.open = false
|
|
|
- },
|
|
|
- ),
|
|
|
- )
|
|
|
const closeMoreOutside = (event: PointerEvent) => {
|
|
|
- if (routeMenu?.open && event.target instanceof Node && !routeMenu.contains(event.target)) routeMenu.open = false
|
|
|
if (!moreActions?.open) return
|
|
|
if (event.target instanceof Node && moreActions.contains(event.target)) return
|
|
|
moreActions.open = false
|
|
|
}
|
|
|
const closeMoreOnEscape = (event: KeyboardEvent) => {
|
|
|
if (event.defaultPrevented) return
|
|
|
- if (event.key === "Escape" && routeMenu?.open) {
|
|
|
- routeMenu.open = false
|
|
|
- routeMenu.querySelector("summary")?.focus()
|
|
|
- event.preventDefault()
|
|
|
- return
|
|
|
- }
|
|
|
if (event.key !== "Escape" || !moreActions?.open) return
|
|
|
moreActions.open = false
|
|
|
moreActions.querySelector("summary")?.focus()
|
|
|
@@ -401,6 +387,16 @@ export function PaasChat(props: {
|
|
|
const rows = paasRows(await props.api.request({ action: "threads", agentID }), "threads")
|
|
|
if (life.active && epoch === life.epoch) {
|
|
|
setUI("threads", agentID, rows)
|
|
|
+ for (const row of rows) {
|
|
|
+ if (typeof row.delegated === "boolean")
|
|
|
+ setState(
|
|
|
+ "chats",
|
|
|
+ (chat) => chat.agentID === agentID && chat.threadID === row.id,
|
|
|
+ "delegated",
|
|
|
+ row.delegated,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ model.save()
|
|
|
setUI("historyError", agentID, "")
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -503,7 +499,8 @@ export function PaasChat(props: {
|
|
|
const elapsed = (message: ResearchMessage) => researchElapsed(message, ui.now)
|
|
|
const phase = (message: ResearchMessage) => {
|
|
|
if (message.status === "submitting") return "正在提交任务"
|
|
|
- if (message.status === "unknown") return "正在核对执行状态"
|
|
|
+ if (message.status === "unknown")
|
|
|
+ return message.receiptClosedAt || message.receiptCheck?.paused ? "提交状态未知" : "正在核对提交回执"
|
|
|
if (message.status?.startsWith("waiting")) return "需要你确认后继续"
|
|
|
if (message.status === "running") {
|
|
|
const event = message.activity?.at(-1)
|
|
|
@@ -554,6 +551,8 @@ export function PaasChat(props: {
|
|
|
const chats = state.chats.filter(
|
|
|
(chat) =>
|
|
|
chat.agentID === agent.id &&
|
|
|
+ !chat.delegated &&
|
|
|
+ !(ui.threads[id] || []).some((thread) => thread.id === chat.threadID && thread.delegated === true) &&
|
|
|
chat.projectID === props.projectID &&
|
|
|
!!chat.archived === ui.archived &&
|
|
|
hasConversationHistory(chat) &&
|
|
|
@@ -562,6 +561,7 @@ export function PaasChat(props: {
|
|
|
const threads = (props.projectID === "project-default" ? ui.threads[id] || [] : []).filter(
|
|
|
(thread) =>
|
|
|
!ui.archived &&
|
|
|
+ thread.delegated !== true &&
|
|
|
matches(paasText(thread.title) || "历史会话") &&
|
|
|
!state.chats.some((chat) => chat.agentID === agent.id && chat.threadID === thread.id),
|
|
|
)
|
|
|
@@ -995,7 +995,7 @@ export function PaasChat(props: {
|
|
|
<Show when={elapsed(message)}>
|
|
|
<span>已用时 {elapsed(message)}</span>
|
|
|
</Show>
|
|
|
- <Show when={working(message) && message.updated}>
|
|
|
+ <Show when={working(message) && message.status !== "unknown" && message.updated}>
|
|
|
<span>最近更新 {Math.max(0, Math.floor((ui.now - message.updated!) / 1000))} 秒前</span>
|
|
|
</Show>
|
|
|
<Show when={message.activity?.length}>
|
|
|
@@ -1049,7 +1049,7 @@ export function PaasChat(props: {
|
|
|
</Show>
|
|
|
</section>
|
|
|
</Show>
|
|
|
- <Show when={message.error}>
|
|
|
+ <Show when={message.error && !message.receiptClosedAt}>
|
|
|
<ResearchIssue
|
|
|
message={message.error!}
|
|
|
onSettings={() => props.onEditAgent?.(agentID)}
|
|
|
@@ -1122,12 +1122,36 @@ export function PaasChat(props: {
|
|
|
</div>
|
|
|
</Show>
|
|
|
<Show when={message.submitted && ["failed", "unknown"].includes(message.status || "")}>
|
|
|
- <div class="paas-actions">
|
|
|
- <button onClick={() => model.recover(message)}>恢复原输入与材料</button>
|
|
|
- <button onClick={props.onOpenTasks}>核对平台任务</button>
|
|
|
- <Show when={message.status === "unknown" && !message.runID}>
|
|
|
+ <section class="paas-recovery-actions" aria-label="本次提交的恢复操作">
|
|
|
+ <Show when={message.error && message.receiptClosedAt}>
|
|
|
<details>
|
|
|
- <summary>保留原任务并另建草稿</summary>
|
|
|
+ <summary>查看提交时的错误</summary>
|
|
|
+ <p class="paas-muted">{redactDiagnostic(message.error!)}</p>
|
|
|
+ </details>
|
|
|
+ </Show>
|
|
|
+ <div class="paas-actions">
|
|
|
+ <button onClick={() => model.recover(message)}>恢复原输入与材料</button>
|
|
|
+ <button onClick={props.onOpenTasks}>核对平台任务</button>
|
|
|
+ <Show when={message.status === "unknown"}>
|
|
|
+ <button
|
|
|
+ onClick={() => model.endReceipt(chatID, message.id)}
|
|
|
+ disabled={!!message.receiptClosedAt}
|
|
|
+ >
|
|
|
+ {message.receiptClosedAt ? "已结束等待回执" : "结束本次提交等待"}
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ onClick={() => {
|
|
|
+ model.endReceipt(chatID, message.id)
|
|
|
+ model.archive()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 归档此会话
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ </div>
|
|
|
+ <Show when={message.status === "unknown" && !message.runID}>
|
|
|
+ <details class="paas-recovery-alternative">
|
|
|
+ <summary>保留原记录,另建草稿</summary>
|
|
|
<p>
|
|
|
原任务仍可能在平台执行。新草稿不会自动发送,重新发送前请核对任务中心,避免重复执行。
|
|
|
</p>
|
|
|
@@ -1145,7 +1169,7 @@ export function PaasChat(props: {
|
|
|
</button>
|
|
|
</details>
|
|
|
</Show>
|
|
|
- </div>
|
|
|
+ </section>
|
|
|
</Show>
|
|
|
<Show when={message.activity?.length}>
|
|
|
<PaasActivity items={paasActivityItems(message.activity)} raw={message.activity} />
|
|
|
@@ -1227,14 +1251,142 @@ export function PaasChat(props: {
|
|
|
/>
|
|
|
)}
|
|
|
</For>
|
|
|
- <TaskScope
|
|
|
- projectID={current()?.projectID || props.projectID}
|
|
|
- api={props.api}
|
|
|
- connected={props.connected}
|
|
|
- agent={activeAgent()}
|
|
|
- folders={folders()}
|
|
|
- scope={props.scope}
|
|
|
- />
|
|
|
+ <Show
|
|
|
+ when={Object.values(ui.threads)
|
|
|
+ .flat()
|
|
|
+ .some(
|
|
|
+ (thread) =>
|
|
|
+ paasRecord(thread.origin)?.kind === "paas" &&
|
|
|
+ paasRecord(thread.origin)?.session_id === current()?.threadID,
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ <section class="paas-child-conversations" aria-label="本会话的子任务">
|
|
|
+ <strong>子任务</strong>
|
|
|
+ <For
|
|
|
+ each={Object.entries(ui.threads).flatMap(([agentID, threads]) =>
|
|
|
+ threads
|
|
|
+ .filter(
|
|
|
+ (thread) =>
|
|
|
+ paasRecord(thread.origin)?.kind === "paas" &&
|
|
|
+ paasRecord(thread.origin)?.session_id === current()?.threadID,
|
|
|
+ )
|
|
|
+ .map((thread) => ({ agentID, thread })),
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ {(child) => (
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={(event) => {
|
|
|
+ const returnFocus = event.currentTarget
|
|
|
+ dialog.show(() => (
|
|
|
+ <DelegatedConversation
|
|
|
+ returnFocus={returnFocus}
|
|
|
+ api={props.api!}
|
|
|
+ agentID={child.agentID}
|
|
|
+ threadID={paasText(child.thread.id)}
|
|
|
+ title={paasText(child.thread.title)}
|
|
|
+ />
|
|
|
+ ))
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {paasText(child.thread.title) || "查看子任务"}
|
|
|
+ <Icon name="arrow-right" size="small" />
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </section>
|
|
|
+ </Show>
|
|
|
+ <div class="paas-composer-toolbar">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="paas-agent-picker-trigger"
|
|
|
+ aria-label="选择执行角色"
|
|
|
+ onClick={(event) => {
|
|
|
+ const trigger = event.currentTarget
|
|
|
+ dialog.show(() => (
|
|
|
+ <Dialog
|
|
|
+ title="选择执行角色"
|
|
|
+ onCloseAutoFocus={(event) => {
|
|
|
+ event.preventDefault()
|
|
|
+ trigger.focus()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div class="paas-agent-picker">
|
|
|
+ <p class="paas-muted">
|
|
|
+ {blank()
|
|
|
+ ? "自动按目标匹配,也可指定本次任务的智能体。"
|
|
|
+ : "当前会话沿用原智能体。选择其他角色会新建会话,原记录与草稿保留。"}
|
|
|
+ </p>
|
|
|
+ <div
|
|
|
+ role="listbox"
|
|
|
+ aria-label="执行角色"
|
|
|
+ onKeyDown={(event) => {
|
|
|
+ if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return
|
|
|
+ event.preventDefault()
|
|
|
+ const options = [...event.currentTarget.querySelectorAll<HTMLButtonElement>("[role=option]")]
|
|
|
+ const index = options.indexOf(document.activeElement as HTMLButtonElement)
|
|
|
+ options[
|
|
|
+ event.key === "Home"
|
|
|
+ ? 0
|
|
|
+ : event.key === "End"
|
|
|
+ ? options.length - 1
|
|
|
+ : (index + (event.key === "ArrowDown" ? 1 : -1) + options.length) % options.length
|
|
|
+ ]?.focus()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Show when={blank()}>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ role="option"
|
|
|
+ aria-selected={!ui.agentOverride}
|
|
|
+ onClick={() => {
|
|
|
+ setUI("agentOverride", "")
|
|
|
+ dialog.close()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <strong>自动匹配</strong>
|
|
|
+ <small>{routed().reason}</small>
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ <For each={directAgents(props.agents)}>
|
|
|
+ {(agent) => (
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ role="option"
|
|
|
+ aria-selected={blank() ? ui.agentOverride === agent.id : current()?.agentID === agent.id}
|
|
|
+ onClick={() => {
|
|
|
+ if (!blank()) model.choose(agent, true)
|
|
|
+ model.route(paasText(agent.id))
|
|
|
+ setUI("agentOverride", paasText(agent.id))
|
|
|
+ dialog.close()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <strong>{paasText(agent.name)}</strong>
|
|
|
+ <small>{resolveAgentProfile(agent).summary}</small>
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </Dialog>
|
|
|
+ ))
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <ResearchIcon kind="agent" />
|
|
|
+ <span>
|
|
|
+ {blank() ? (overrideAgent() ? "指定" : "自动") : "当前"} · {routeLabel()}
|
|
|
+ </span>
|
|
|
+ <Icon name="chevron-down" size="small" />
|
|
|
+ </button>
|
|
|
+ <TaskScope
|
|
|
+ projectID={current()?.projectID || props.projectID}
|
|
|
+ api={props.api}
|
|
|
+ connected={props.connected}
|
|
|
+ agent={activeAgent()}
|
|
|
+ folders={folders()}
|
|
|
+ scope={props.scope}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
<form
|
|
|
noValidate
|
|
|
class="paas-composer"
|
|
|
@@ -1379,51 +1531,6 @@ export function PaasChat(props: {
|
|
|
<Icon name="plus-small" size="small" />
|
|
|
添加文件
|
|
|
</button>
|
|
|
- <details ref={routeMenu} class="paas-agent-route">
|
|
|
- <summary title={routeLabel()}>
|
|
|
- <span>
|
|
|
- {blank() ? (overrideAgent() ? "指定" : "自动") : "当前"} · {routeLabel()}
|
|
|
- </span>
|
|
|
- <Icon name="chevron-down" size="small" />
|
|
|
- </summary>
|
|
|
- <div class="paas-agent-route-panel">
|
|
|
- <p class="paas-muted">
|
|
|
- {blank()
|
|
|
- ? overrideAgent()
|
|
|
- ? "已按你的选择指定角色,也可切回自动匹配。"
|
|
|
- : routed().reason
|
|
|
- : "已有会话沿用当前智能体;新会话会按目标自动选择。"}
|
|
|
- </p>
|
|
|
- <select
|
|
|
- aria-label="选择执行角色"
|
|
|
- disabled={!blank()}
|
|
|
- value={blank() ? ui.agentOverride : paasText(currentAgent()?.id)}
|
|
|
- onInput={(event) => {
|
|
|
- const value = event.currentTarget.value
|
|
|
- if (!value && blank()) {
|
|
|
- setUI("agentOverride", "")
|
|
|
- if (routeMenu) routeMenu.open = false
|
|
|
- routeMenu?.querySelector("summary")?.focus()
|
|
|
- return
|
|
|
- }
|
|
|
- if (!model.route(value)) {
|
|
|
- setState("error", "已有会话不能切换智能体,请新建会话后再选择。")
|
|
|
- return
|
|
|
- }
|
|
|
- setUI("agentOverride", value)
|
|
|
- event.currentTarget.closest("details")?.removeAttribute("open")
|
|
|
- routeMenu?.querySelector("summary")?.focus()
|
|
|
- }}
|
|
|
- >
|
|
|
- <Show when={blank()}>
|
|
|
- <option value="">自动匹配任务</option>
|
|
|
- </Show>
|
|
|
- <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>
|
|
|
推理强度
|