|
|
@@ -1,12 +1,41 @@
|
|
|
-import { For, Show, createEffect, createMemo, onCleanup } from "solid-js"
|
|
|
+import { For, Show, createEffect, createMemo, onCleanup, onMount, untrack } from "solid-js"
|
|
|
import { createStore } from "solid-js/store"
|
|
|
+import { DropdownMenu } from "@opencode-ai/ui/dropdown-menu"
|
|
|
import { Icon } from "@opencode-ai/ui/icon"
|
|
|
-import { paasRecord, paasText, paasStatuses, type PaasPlatform } from "@/paas"
|
|
|
+import {
|
|
|
+ paasEfforts,
|
|
|
+ paasRecord,
|
|
|
+ paasRows,
|
|
|
+ paasText,
|
|
|
+ paasStatus,
|
|
|
+ paasStatuses,
|
|
|
+ type PaasEffort,
|
|
|
+ type PaasPlatform,
|
|
|
+ type PaasProgress,
|
|
|
+} from "@/paas"
|
|
|
|
|
|
-type Message = { role: "user" | "assistant"; text: string; status?: string; runID?: string }
|
|
|
-type Chat = { id: string; agentID: string; name: string; title: string; threadID: string; messages: Message[] }
|
|
|
+type Message = { role: "user" | "assistant"; text: string; status?: string; runID?: string; activity?: PaasProgress[] }
|
|
|
+type Chat = {
|
|
|
+ id: string
|
|
|
+ agentID: string
|
|
|
+ name: string
|
|
|
+ title: string
|
|
|
+ threadID: string
|
|
|
+ effort?: PaasEffort
|
|
|
+ messages: Message[]
|
|
|
+}
|
|
|
|
|
|
-export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents: Record<string, unknown>[] }) {
|
|
|
+export function PaasChat(props: {
|
|
|
+ api?: PaasPlatform
|
|
|
+ connected: boolean
|
|
|
+ visible: boolean
|
|
|
+ agents: Record<string, unknown>[]
|
|
|
+ openAgentID: string
|
|
|
+ onAgentOpened: () => void
|
|
|
+ onOpenAgentPacks: () => void
|
|
|
+ onOpenWorkspace?: (agentID: string) => Promise<void>
|
|
|
+ workspaceDisabled: boolean
|
|
|
+}) {
|
|
|
const [state, setState] = createStore({
|
|
|
chats: [] as Chat[],
|
|
|
active: "",
|
|
|
@@ -16,19 +45,69 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
end: 0,
|
|
|
option: 0,
|
|
|
pending: "",
|
|
|
+ progress: [] as PaasProgress[],
|
|
|
+ threads: {} as Record<string, Record<string, unknown>[]>,
|
|
|
+ historyErrors: {} as Record<string, string>,
|
|
|
+ loadingHistory: {} as Record<string, boolean>,
|
|
|
+ loadingThread: false,
|
|
|
+ efforts: [] as PaasEffort[],
|
|
|
error: "",
|
|
|
collapsed: {} as Record<string, boolean>,
|
|
|
})
|
|
|
- const lifecycle = { active: true, epoch: 0 }
|
|
|
+ const lifecycle = { active: true, epoch: 0, executionID: "" }
|
|
|
onCleanup(() => {
|
|
|
lifecycle.active = false
|
|
|
})
|
|
|
+ onMount(() => {
|
|
|
+ const unsubscribe = props.api?.onProgress?.((event) => {
|
|
|
+ if (!state.pending || event.executionID !== lifecycle.executionID) return
|
|
|
+ setState("progress", (previous) => [...previous.slice(-79), event])
|
|
|
+ })
|
|
|
+ if (unsubscribe) onCleanup(unsubscribe)
|
|
|
+ })
|
|
|
createEffect(() => {
|
|
|
if (props.connected) return
|
|
|
lifecycle.epoch++
|
|
|
- setState({ chats: [], active: "", draft: "", pending: "", error: "", query: undefined })
|
|
|
+ setState({
|
|
|
+ chats: [],
|
|
|
+ active: "",
|
|
|
+ draft: "",
|
|
|
+ pending: "",
|
|
|
+ error: "",
|
|
|
+ query: undefined,
|
|
|
+ progress: [],
|
|
|
+ threads: {},
|
|
|
+ historyErrors: {},
|
|
|
+ loadingHistory: {},
|
|
|
+ loadingThread: false,
|
|
|
+ })
|
|
|
})
|
|
|
const current = createMemo(() => state.chats.find((chat) => chat.id === state.active))
|
|
|
+ const currentAgent = createMemo(() => props.agents.find((agent) => agent.id === current()?.agentID))
|
|
|
+ const currentName = () => paasText(currentAgent()?.name) || current()?.name
|
|
|
+ const effortAgent = createMemo(() => paasText(currentAgent()?.id))
|
|
|
+ const effortVersion = createMemo(() => currentAgent()?.current_version)
|
|
|
+ createEffect(() => {
|
|
|
+ const agentID = effortAgent()
|
|
|
+ effortVersion()
|
|
|
+ setState("efforts", [])
|
|
|
+ if (!agentID || !props.api || !props.connected) return
|
|
|
+ const request = { active: true }
|
|
|
+ onCleanup(() => (request.active = false))
|
|
|
+ void props.api
|
|
|
+ .request({ action: "run-options", agentID })
|
|
|
+ .then((value) => {
|
|
|
+ const options = paasRecord(value)?.efforts
|
|
|
+ if (request.active && Array.isArray(options))
|
|
|
+ setState(
|
|
|
+ "efforts",
|
|
|
+ options.filter(
|
|
|
+ (option): option is PaasEffort => option === "low" || option === "medium" || option === "high",
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ })
|
|
|
+ .catch(() => undefined)
|
|
|
+ })
|
|
|
const matches = createMemo(() =>
|
|
|
props.agents.filter((agent) =>
|
|
|
`${paasText(agent.name)} ${paasText(agent.id)}`.toLowerCase().includes((state.query || "").toLowerCase()),
|
|
|
@@ -38,11 +117,72 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
createEffect(() => {
|
|
|
current()?.messages.length
|
|
|
state.pending
|
|
|
+ state.progress.length
|
|
|
if (elements.messages) elements.messages.scrollTo({ top: elements.messages.scrollHeight, behavior: "smooth" })
|
|
|
})
|
|
|
|
|
|
+ async function loadHistory(agentID: string) {
|
|
|
+ if (!props.api || !props.connected || state.loadingHistory[agentID]) return
|
|
|
+ const epoch = lifecycle.epoch
|
|
|
+ setState("loadingHistory", agentID, true)
|
|
|
+ setState("historyErrors", agentID, "")
|
|
|
+ await props.api
|
|
|
+ .request({ action: "threads", agentID })
|
|
|
+ .then((value) => {
|
|
|
+ const threads = paasRows(value, "threads").filter((thread) => paasText(thread.id))
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch) setState("threads", agentID, threads)
|
|
|
+ })
|
|
|
+ .catch((error: unknown) => {
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch)
|
|
|
+ setState("historyErrors", agentID, error instanceof Error ? error.message : "会话列表读取失败。")
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch) setState("loadingHistory", agentID, false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async function restore(agent: Record<string, unknown>, thread: Record<string, unknown>) {
|
|
|
+ if (!props.api || !props.connected || state.loadingThread || state.pending) return
|
|
|
+ const epoch = lifecycle.epoch
|
|
|
+ const agentID = paasText(agent.id)
|
|
|
+ const threadID = paasText(thread.id)
|
|
|
+ setState({ loadingThread: true, error: "" })
|
|
|
+ await props.api
|
|
|
+ .request({ action: "thread-runs", agentID, threadID })
|
|
|
+ .then((value) => {
|
|
|
+ if (!lifecycle.active || epoch !== lifecycle.epoch) return
|
|
|
+ if (paasRecord(value)?.thread_id !== threadID) throw new Error("平台返回的会话编号不匹配。")
|
|
|
+ const messages = paasRows(value, "runs").flatMap((run): Message[] => [
|
|
|
+ { role: "user", text: paasText(run.input) },
|
|
|
+ {
|
|
|
+ role: "assistant",
|
|
|
+ text: paasText(run.output),
|
|
|
+ status: paasStatus(run),
|
|
|
+ runID: paasText(run.run_id) || paasText(run.id),
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ const chat = {
|
|
|
+ id: crypto.randomUUID(),
|
|
|
+ threadID,
|
|
|
+ agentID,
|
|
|
+ name: paasText(agent.name),
|
|
|
+ title: paasText(thread.title) || "历史会话",
|
|
|
+ messages,
|
|
|
+ }
|
|
|
+ setState("chats", (chats) => [...chats, chat])
|
|
|
+ setState({ active: chat.id, draft: "", query: undefined })
|
|
|
+ })
|
|
|
+ .catch((error: unknown) => {
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch)
|
|
|
+ setState("error", error instanceof Error ? error.message : "会话读取失败。")
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch) setState("loadingThread", false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
function choose(agent: Record<string, unknown>, fresh = false) {
|
|
|
- if (state.pending) return
|
|
|
+ if (state.pending || state.loadingThread) return
|
|
|
const id = paasText(agent.id)
|
|
|
if (fresh || current()?.agentID !== id) {
|
|
|
const chat = {
|
|
|
@@ -61,11 +201,24 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
elements.input?.focus()
|
|
|
}
|
|
|
|
|
|
+ createEffect(() => {
|
|
|
+ const id = props.openAgentID
|
|
|
+ if (!id || !props.visible || !props.connected || state.pending || state.loadingThread) return
|
|
|
+ untrack(() => {
|
|
|
+ const agent = props.agents.find((item) => item.id === id)
|
|
|
+ props.onAgentOpened()
|
|
|
+ if (agent) choose(agent)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
async function send() {
|
|
|
const chat = current()
|
|
|
const input = state.draft.trim()
|
|
|
- if (!chat || !input || !props.connected || !props.api || state.pending) return
|
|
|
+ if (!chat || !currentAgent() || !input || !props.connected || !props.api || state.pending || state.loadingThread)
|
|
|
+ return
|
|
|
const epoch = lifecycle.epoch
|
|
|
+ const executionID = crypto.randomUUID()
|
|
|
+ lifecycle.executionID = executionID
|
|
|
setState(
|
|
|
"chats",
|
|
|
(item) => item.id === chat.id,
|
|
|
@@ -73,9 +226,16 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
(messages) => [...messages, { role: "user" as const, text: input }],
|
|
|
)
|
|
|
if (chat.messages.length === 1) setState("chats", (item) => item.id === chat.id, "title", input.slice(0, 32))
|
|
|
- setState({ draft: "", pending: chat.id, error: "", query: undefined })
|
|
|
+ setState({ draft: "", pending: chat.id, progress: [], error: "", query: undefined })
|
|
|
await props.api
|
|
|
- .request({ action: "execute", agentID: chat.agentID, input, threadID: chat.threadID || undefined })
|
|
|
+ .request({
|
|
|
+ action: "execute",
|
|
|
+ agentID: chat.agentID,
|
|
|
+ input,
|
|
|
+ threadID: chat.threadID || undefined,
|
|
|
+ executionID,
|
|
|
+ effort: chat.effort && state.efforts.includes(chat.effort) ? chat.effort : undefined,
|
|
|
+ })
|
|
|
.then((value) => {
|
|
|
if (!lifecycle.active || epoch !== lifecycle.epoch) return
|
|
|
const result = paasRecord(value)
|
|
|
@@ -96,6 +256,7 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
"平台未返回文本回复,请查看任务记录。",
|
|
|
status,
|
|
|
runID: paasText(result.run_id) || paasText(result.id),
|
|
|
+ activity: state.progress.filter((event) => event.type === "tool_call" || event.type === "tool_result"),
|
|
|
},
|
|
|
],
|
|
|
)
|
|
|
@@ -119,12 +280,13 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
role: "assistant" as const,
|
|
|
text: `${message}\n请到平台任务核对执行状态,避免重复发送。`,
|
|
|
status: "unknown",
|
|
|
+ activity: state.progress.filter((event) => event.type === "tool_call" || event.type === "tool_result"),
|
|
|
},
|
|
|
],
|
|
|
)
|
|
|
})
|
|
|
.finally(() => {
|
|
|
- if (lifecycle.active && epoch === lifecycle.epoch) setState("pending", "")
|
|
|
+ if (lifecycle.active && epoch === lifecycle.epoch) setState({ pending: "", progress: [] })
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -133,13 +295,28 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
<aside class="paas-session-sidebar" aria-label="智能体会话导航">
|
|
|
<div class="paas-session-heading">
|
|
|
<strong>智能体</strong>
|
|
|
- <span>当前窗口</span>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="paas-sidebar-add-agent"
|
|
|
+ aria-label="从 AgentPack 创建智能体"
|
|
|
+ aria-haspopup="dialog"
|
|
|
+ title={props.connected ? "导入智能体包或从平台包创建" : "请先连接 AgentPaaS"}
|
|
|
+ disabled={!props.connected || !props.api}
|
|
|
+ onClick={props.onOpenAgentPacks}
|
|
|
+ >
|
|
|
+ <Icon name="plus-small" size="small" />
|
|
|
+ </button>
|
|
|
</div>
|
|
|
<nav aria-label="按智能体分组的会话">
|
|
|
<For each={props.agents}>
|
|
|
{(agent) => {
|
|
|
const id = paasText(agent.id)
|
|
|
const chats = () => state.chats.filter((chat) => chat.agentID === id)
|
|
|
+ createEffect(() => {
|
|
|
+ if (props.visible && props.connected) void untrack(() => loadHistory(id))
|
|
|
+ })
|
|
|
+ const threads = () =>
|
|
|
+ state.threads[id]?.filter((thread) => !chats().some((chat) => chat.threadID === thread.id))
|
|
|
return (
|
|
|
<section class="paas-session-group">
|
|
|
<div class="paas-session-agent">
|
|
|
@@ -153,7 +330,7 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
<button
|
|
|
aria-label={`为 ${paasText(agent.name)} 新建会话`}
|
|
|
title="新建会话"
|
|
|
- disabled={!!state.pending}
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
onClick={() => {
|
|
|
setState("collapsed", id, false)
|
|
|
choose(agent, true)
|
|
|
@@ -164,12 +341,30 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
</div>
|
|
|
<Show when={!state.collapsed[id]}>
|
|
|
<div class="paas-session-items">
|
|
|
+ <button disabled={state.loadingHistory[id]} onClick={() => void loadHistory(id)}>
|
|
|
+ {state.loadingHistory[id] ? "正在读取历史…" : "刷新历史会话"}
|
|
|
+ </button>
|
|
|
+ <Show when={state.historyErrors[id]}>
|
|
|
+ <small role="status" class="paas-muted">
|
|
|
+ {state.historyErrors[id]}
|
|
|
+ </small>
|
|
|
+ </Show>
|
|
|
+ <For each={threads()}>
|
|
|
+ {(thread) => (
|
|
|
+ <button
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
+ onClick={() => void restore(agent, thread)}
|
|
|
+ >
|
|
|
+ {paasText(thread.title) || "历史会话"}
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
<For each={chats()}>
|
|
|
{(chat) => (
|
|
|
<button
|
|
|
title={chat.title}
|
|
|
aria-current={chat.id === state.active ? "page" : undefined}
|
|
|
- disabled={!!state.pending}
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
onClick={() => setState({ active: chat.id, draft: "", query: undefined, error: "" })}
|
|
|
>
|
|
|
{chat.title}
|
|
|
@@ -190,16 +385,30 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
<div class="paas-conversation">
|
|
|
<header class="paas-chat-header">
|
|
|
<div>
|
|
|
- <h1>{current()?.name || "会话"}</h1>
|
|
|
+ <h1>{currentName() || "会话"}</h1>
|
|
|
<span class="paas-muted">{current()?.threadID ? "上下文已关联平台会话" : "与专业智能体一起工作"}</span>
|
|
|
</div>
|
|
|
- <button
|
|
|
- disabled={!!state.pending}
|
|
|
- onClick={() => setState({ active: "", draft: "", error: "", query: "", start: 0, end: 0 })}
|
|
|
- >
|
|
|
- <Icon name="plus-small" size="small" />
|
|
|
- 新会话
|
|
|
- </button>
|
|
|
+ <div class="paas-chat-header-actions">
|
|
|
+ <Show when={props.onOpenWorkspace && currentAgent()} keyed>
|
|
|
+ {(agent) => (
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ disabled={props.workspaceDisabled || !!state.pending || state.loadingThread}
|
|
|
+ onClick={() => void props.onOpenWorkspace?.(paasText(agent.id))}
|
|
|
+ >
|
|
|
+ <Icon name="folder" size="small" />
|
|
|
+ 打开工作区
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </Show>
|
|
|
+ <button
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
+ onClick={() => setState({ active: "", draft: "", error: "", query: "", start: 0, end: 0 })}
|
|
|
+ >
|
|
|
+ <Icon name="plus-small" size="small" />
|
|
|
+ 新会话
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
</header>
|
|
|
<div
|
|
|
ref={(element) => {
|
|
|
@@ -226,8 +435,14 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
<For each={current()?.messages}>
|
|
|
{(message) => (
|
|
|
<article class="paas-chat-message" data-role={message.role}>
|
|
|
- <strong>{message.role === "user" ? "你" : current()?.name}</strong>
|
|
|
+ <strong>{message.role === "user" ? "你" : currentName()}</strong>
|
|
|
<div class="paas-output">{message.text}</div>
|
|
|
+ <Show when={message.activity?.length}>
|
|
|
+ <details>
|
|
|
+ <summary>工具活动</summary>
|
|
|
+ <PaasActivity events={message.activity!} />
|
|
|
+ </details>
|
|
|
+ </Show>
|
|
|
<Show when={message.status}>
|
|
|
<small class="paas-muted">
|
|
|
{paasStatuses[message.status!] || "执行状态待核对"}
|
|
|
@@ -239,9 +454,10 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
</For>
|
|
|
</Show>
|
|
|
<Show when={state.pending}>
|
|
|
- <p role="status" class="paas-chat-progress">
|
|
|
- 智能体正在执行任务… 完成后显示回复。
|
|
|
- </p>
|
|
|
+ <div class="paas-chat-progress">
|
|
|
+ <p role="status">{progressLabel(state.progress.at(-1))}</p>
|
|
|
+ <PaasActivity events={state.progress} />
|
|
|
+ </div>
|
|
|
</Show>
|
|
|
</div>
|
|
|
<Show when={state.error}>
|
|
|
@@ -265,7 +481,7 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
type="button"
|
|
|
role="option"
|
|
|
aria-selected={state.option === index()}
|
|
|
- disabled={!!state.pending}
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
onClick={() => choose(agent)}
|
|
|
>
|
|
|
<Icon name="brain" size="small" />
|
|
|
@@ -290,7 +506,7 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
}
|
|
|
placeholder="输入 @ 选择智能体,描述你想完成的任务…"
|
|
|
value={state.draft}
|
|
|
- disabled={!props.connected || !!state.pending}
|
|
|
+ disabled={!props.connected || !!state.pending || state.loadingThread}
|
|
|
maxLength={100000}
|
|
|
rows={3}
|
|
|
onInput={(event) => {
|
|
|
@@ -332,26 +548,105 @@ export function PaasChat(props: { api?: PaasPlatform; connected: boolean; agents
|
|
|
<button
|
|
|
type="button"
|
|
|
class="paas-mention-trigger"
|
|
|
- disabled={!props.connected || !!state.pending}
|
|
|
+ disabled={!props.connected || !!state.pending || state.loadingThread}
|
|
|
onClick={() => {
|
|
|
setState({ query: "", start: state.draft.length, end: state.draft.length, option: 0 })
|
|
|
elements.input?.focus()
|
|
|
}}
|
|
|
>
|
|
|
- @ {current()?.name || "选择智能体"}
|
|
|
+ @ {currentName() || "选择智能体"}
|
|
|
</button>
|
|
|
+ <Show when={state.efforts.length > 0 ? current() : undefined}>
|
|
|
+ {(chat) => {
|
|
|
+ const selected = () => {
|
|
|
+ const effort = chat().effort
|
|
|
+ return effort && state.efforts.includes(effort) ? effort : "default"
|
|
|
+ }
|
|
|
+ const label = (effort: PaasEffort | "default") => (effort === "default" ? "默认" : paasEfforts[effort])
|
|
|
+ return (
|
|
|
+ <DropdownMenu modal={false} placement="top-end" gutter={8}>
|
|
|
+ <DropdownMenu.Trigger
|
|
|
+ class="paas-effort-trigger"
|
|
|
+ disabled={!!state.pending || state.loadingThread}
|
|
|
+ aria-label={`模型推理强度:${label(selected())}`}
|
|
|
+ >
|
|
|
+ <span>推理强度</span>
|
|
|
+ <strong>{label(selected())}</strong>
|
|
|
+ <Icon name="chevron-down" size="small" />
|
|
|
+ </DropdownMenu.Trigger>
|
|
|
+ <DropdownMenu.Portal>
|
|
|
+ <DropdownMenu.Content>
|
|
|
+ <DropdownMenu.Group>
|
|
|
+ <DropdownMenu.GroupLabel>推理强度</DropdownMenu.GroupLabel>
|
|
|
+ <DropdownMenu.RadioGroup
|
|
|
+ value={selected()}
|
|
|
+ onChange={(value) => {
|
|
|
+ const effort = state.efforts.find((option) => option === value)
|
|
|
+ setState("chats", (item) => item.id === chat().id, "effort", effort)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <For each={["default" as const, ...state.efforts]}>
|
|
|
+ {(effort) => (
|
|
|
+ <DropdownMenu.RadioItem value={effort}>
|
|
|
+ <DropdownMenu.ItemLabel>{label(effort)}</DropdownMenu.ItemLabel>
|
|
|
+ <DropdownMenu.ItemIndicator>
|
|
|
+ <Icon name="check-small" size="small" />
|
|
|
+ </DropdownMenu.ItemIndicator>
|
|
|
+ </DropdownMenu.RadioItem>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </DropdownMenu.RadioGroup>
|
|
|
+ </DropdownMenu.Group>
|
|
|
+ </DropdownMenu.Content>
|
|
|
+ </DropdownMenu.Portal>
|
|
|
+ </DropdownMenu>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </Show>
|
|
|
<button
|
|
|
class="paas-primary"
|
|
|
type="submit"
|
|
|
aria-label="发送消息"
|
|
|
- disabled={!props.connected || !current() || !state.draft.trim() || !!state.pending}
|
|
|
+ disabled={
|
|
|
+ !props.connected || !currentAgent() || !state.draft.trim() || !!state.pending || state.loadingThread
|
|
|
+ }
|
|
|
>
|
|
|
<Icon name="arrow-up" size="normal" />
|
|
|
</button>
|
|
|
</footer>
|
|
|
</form>
|
|
|
- <p class="paas-chat-caption">Enter 发送 · Shift + Enter 换行 · 会话列表仅保留在当前窗口,执行记录保存在平台</p>
|
|
|
+ <p class="paas-chat-caption">Enter 发送 · Shift + Enter 换行</p>
|
|
|
</div>
|
|
|
</section>
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+function progressLabel(event?: PaasProgress) {
|
|
|
+ if (event?.type === "tool_call") return `正在调用 ${event.tool || "工具"}`
|
|
|
+ if (event?.type === "tool_result") return "已收到工具结果,等待智能体继续"
|
|
|
+ if (event?.type === "paused") return "任务已暂停"
|
|
|
+ if (event?.type === "cancelled") return "任务已取消"
|
|
|
+ if (event?.type === "done") return paasStatuses[event.status || ""] || "正在整理结果"
|
|
|
+ return event ? "智能体正在执行" : "正在提交任务"
|
|
|
+}
|
|
|
+
|
|
|
+function PaasActivity(props: { events: PaasProgress[] }) {
|
|
|
+ const events = createMemo(() =>
|
|
|
+ props.events.filter((event) => event.type === "tool_call" || event.type === "tool_result"),
|
|
|
+ )
|
|
|
+ return (
|
|
|
+ <For each={events()}>
|
|
|
+ {(event) => (
|
|
|
+ <details>
|
|
|
+ <summary>
|
|
|
+ {event.type === "tool_call" ? "调用工具" : "工具结果"}
|
|
|
+ {event.tool ? ` · ${event.tool}` : ""}
|
|
|
+ </summary>
|
|
|
+ <Show when={event.content}>
|
|
|
+ <pre class="paas-output">{event.content}</pre>
|
|
|
+ </Show>
|
|
|
+ </details>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ )
|
|
|
+}
|