|
|
@@ -1,5 +1,6 @@
|
|
|
import { For, Show, createEffect, createMemo, on, onCleanup, onMount, untrack } from "solid-js"
|
|
|
import { createStore } from "solid-js/store"
|
|
|
+import { Portal } from "solid-js/web"
|
|
|
import { ResearchReport } from "./report"
|
|
|
import { PaasActivity, paasActivityItems } from "./activity"
|
|
|
import { useDialog } from "@opencode-ai/ui/context/dialog"
|
|
|
@@ -39,6 +40,7 @@ export function PaasChat(props: {
|
|
|
workspaceDisabled: boolean
|
|
|
openTask?: Record<string, unknown>
|
|
|
onTaskOpened?: () => void
|
|
|
+ historyMount?: HTMLElement
|
|
|
}) {
|
|
|
const platform = usePlatform()
|
|
|
const dialog = useDialog()
|
|
|
@@ -56,7 +58,6 @@ export function PaasChat(props: {
|
|
|
copyError: "",
|
|
|
search: "",
|
|
|
archived: false,
|
|
|
- historyOpen: false,
|
|
|
renaming: false,
|
|
|
title: "",
|
|
|
exporting: "",
|
|
|
@@ -119,32 +120,11 @@ export function PaasChat(props: {
|
|
|
on(
|
|
|
() => state.active,
|
|
|
() => {
|
|
|
- setUI({ follow: true, unread: false, historyOpen: false, renaming: false })
|
|
|
+ setUI({ follow: true, unread: false, renaming: false })
|
|
|
queueMicrotask(bottom)
|
|
|
},
|
|
|
),
|
|
|
)
|
|
|
- createEffect(
|
|
|
- on(
|
|
|
- () => ui.historyOpen,
|
|
|
- (open) => {
|
|
|
- if (!open) return
|
|
|
- const close = (event: KeyboardEvent) => {
|
|
|
- if (event.key === "Escape") setUI("historyOpen", false)
|
|
|
- }
|
|
|
- document.addEventListener("keydown", close)
|
|
|
- onCleanup(() => document.removeEventListener("keydown", close))
|
|
|
- },
|
|
|
- ),
|
|
|
- )
|
|
|
- createEffect(
|
|
|
- on(
|
|
|
- () => props.visible,
|
|
|
- (visible) => {
|
|
|
- if (!visible) setUI("historyOpen", false)
|
|
|
- },
|
|
|
- ),
|
|
|
- )
|
|
|
createEffect(() => {
|
|
|
current()
|
|
|
?.messages.map((m) => `${m.updated}:${m.text.length}:${m.activity?.length}`)
|
|
|
@@ -338,101 +318,112 @@ export function PaasChat(props: {
|
|
|
const matches = (title: string) => title.toLocaleLowerCase().includes(ui.search.trim().toLocaleLowerCase())
|
|
|
return (
|
|
|
<section class="paas-chat" aria-label="智能体会话">
|
|
|
- <aside
|
|
|
- class="paas-session-sidebar"
|
|
|
- classList={{ "paas-session-drawer-open": ui.historyOpen }}
|
|
|
- aria-label="智能体会话导航"
|
|
|
- >
|
|
|
- <div class="paas-session-heading">
|
|
|
- <strong>研究会话</strong>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- aria-label="从 AgentPack 创建智能体"
|
|
|
- disabled={!props.connected}
|
|
|
- onClick={props.onOpenAgentPacks}
|
|
|
- >
|
|
|
- <Icon name="plus-small" />
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- <input
|
|
|
- class="paas-chat-search"
|
|
|
- aria-label="搜索会话标题"
|
|
|
- placeholder="搜索会话标题"
|
|
|
- value={ui.search}
|
|
|
- onInput={(e) => setUI("search", e.currentTarget.value)}
|
|
|
- />
|
|
|
- <button class="paas-archive-toggle" aria-pressed={ui.archived} onClick={() => setUI("archived", !ui.archived)}>
|
|
|
- {ui.archived ? "返回未归档会话" : "查看本机归档"}
|
|
|
- </button>
|
|
|
- <For each={props.agents}>
|
|
|
- {(agent) => (
|
|
|
- <section class="paas-session-group">
|
|
|
- <div class="paas-session-agent">
|
|
|
- <strong>{paasText(agent.name)}</strong>
|
|
|
- <button aria-label={`为 ${paasText(agent.name)} 新建会话`} onClick={() => model.choose(agent, true)}>
|
|
|
+ <Show when={props.historyMount}>
|
|
|
+ {(mount) => (
|
|
|
+ <Portal mount={mount()}>
|
|
|
+ <section class="paas-nav-history-panel" aria-label="智能体会话导航">
|
|
|
+ <div class="paas-session-heading">
|
|
|
+ <strong>研究会话</strong>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ aria-label="从 AgentPack 创建智能体"
|
|
|
+ disabled={!props.connected}
|
|
|
+ onClick={props.onOpenAgentPacks}
|
|
|
+ >
|
|
|
<Icon name="plus-small" />
|
|
|
</button>
|
|
|
</div>
|
|
|
- <div class="paas-session-items">
|
|
|
- <For
|
|
|
- each={state.chats.filter(
|
|
|
- (c) => c.agentID === agent.id && !!c.archived === ui.archived && matches(c.title),
|
|
|
- )}
|
|
|
- >
|
|
|
- {(chat) => (
|
|
|
- <button
|
|
|
- aria-current={state.active === chat.id ? "page" : undefined}
|
|
|
- onClick={() => model.activate(chat.id)}
|
|
|
- >
|
|
|
- {chat.title}
|
|
|
- <Show when={model.job(chat)}>
|
|
|
- <span class="paas-running-dot" title="任务在后台执行">
|
|
|
- {" "}
|
|
|
- · 进行中
|
|
|
- </span>
|
|
|
- </Show>
|
|
|
- <Show when={chat.draft}>
|
|
|
- <small>有草稿</small>
|
|
|
+ <input
|
|
|
+ class="paas-chat-search"
|
|
|
+ aria-label="搜索会话标题"
|
|
|
+ placeholder="搜索会话标题"
|
|
|
+ value={ui.search}
|
|
|
+ onInput={(e) => setUI("search", e.currentTarget.value)}
|
|
|
+ />
|
|
|
+ <button
|
|
|
+ class="paas-archive-toggle"
|
|
|
+ aria-pressed={ui.archived}
|
|
|
+ onClick={() => setUI("archived", !ui.archived)}
|
|
|
+ >
|
|
|
+ {ui.archived ? "返回未归档会话" : "查看本机归档"}
|
|
|
+ </button>
|
|
|
+ <For each={props.agents}>
|
|
|
+ {(agent) => (
|
|
|
+ <section class="paas-session-group">
|
|
|
+ <div class="paas-session-agent">
|
|
|
+ <strong>{paasText(agent.name)}</strong>
|
|
|
+ <button
|
|
|
+ aria-label={`为 ${paasText(agent.name)} 新建会话`}
|
|
|
+ onClick={() => {
|
|
|
+ model.choose(agent, true)
|
|
|
+ props.onShowChat?.()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Icon name="plus-small" />
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ <div class="paas-session-items">
|
|
|
+ <For
|
|
|
+ each={state.chats.filter(
|
|
|
+ (c) => c.agentID === agent.id && !!c.archived === ui.archived && matches(c.title),
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ {(chat) => (
|
|
|
+ <button
|
|
|
+ aria-current={state.active === chat.id ? "page" : undefined}
|
|
|
+ onClick={() => {
|
|
|
+ model.activate(chat.id)
|
|
|
+ props.onShowChat?.()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {chat.title}
|
|
|
+ <Show when={model.job(chat)}>
|
|
|
+ <span class="paas-running-dot" title="任务在后台执行">
|
|
|
+ {" "}
|
|
|
+ · 进行中
|
|
|
+ </span>
|
|
|
+ </Show>
|
|
|
+ <Show when={chat.draft}>
|
|
|
+ <small>有草稿</small>
|
|
|
+ </Show>
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <For
|
|
|
+ each={(ui.threads[paasText(agent.id)] || []).filter(
|
|
|
+ (t) =>
|
|
|
+ !ui.archived &&
|
|
|
+ matches(paasText(t.title) || "历史会话") &&
|
|
|
+ !state.chats.some((c) => c.agentID === agent.id && c.threadID === t.id),
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ {(thread) => (
|
|
|
+ <button
|
|
|
+ onClick={() => {
|
|
|
+ props.onShowChat?.()
|
|
|
+ void model.restore(agent, paasText(thread.id), paasText(thread.title) || "历史会话")
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {paasText(thread.title) || "历史会话"}
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <button
|
|
|
+ disabled={ui.loading[paasText(agent.id)]}
|
|
|
+ onClick={() => void history(paasText(agent.id))}
|
|
|
+ >
|
|
|
+ {ui.loading[paasText(agent.id)] ? "正在读取历史…" : "刷新历史会话"}
|
|
|
+ </button>
|
|
|
+ <Show when={ui.historyError[paasText(agent.id)]}>
|
|
|
+ <small role="status">{ui.historyError[paasText(agent.id)]}</small>
|
|
|
</Show>
|
|
|
- </button>
|
|
|
- )}
|
|
|
- </For>
|
|
|
- <For
|
|
|
- each={(ui.threads[paasText(agent.id)] || []).filter(
|
|
|
- (t) =>
|
|
|
- !ui.archived &&
|
|
|
- matches(paasText(t.title) || "历史会话") &&
|
|
|
- !state.chats.some((c) => c.agentID === agent.id && c.threadID === t.id),
|
|
|
- )}
|
|
|
- >
|
|
|
- {(thread) => (
|
|
|
- <button
|
|
|
- onClick={() =>
|
|
|
- void model.restore(agent, paasText(thread.id), paasText(thread.title) || "历史会话")
|
|
|
- }
|
|
|
- >
|
|
|
- {paasText(thread.title) || "历史会话"}
|
|
|
- </button>
|
|
|
- )}
|
|
|
- </For>
|
|
|
- <button disabled={ui.loading[paasText(agent.id)]} onClick={() => void history(paasText(agent.id))}>
|
|
|
- {ui.loading[paasText(agent.id)] ? "正在读取历史…" : "刷新历史会话"}
|
|
|
- </button>
|
|
|
- <Show when={ui.historyError[paasText(agent.id)]}>
|
|
|
- <small role="status">{ui.historyError[paasText(agent.id)]}</small>
|
|
|
- </Show>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
</section>
|
|
|
- )}
|
|
|
- </For>
|
|
|
- </aside>
|
|
|
- <Show when={ui.historyOpen}>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- class="paas-session-backdrop"
|
|
|
- aria-label="关闭历史会话"
|
|
|
- onClick={() => setUI("historyOpen", false)}
|
|
|
- />
|
|
|
+ </Portal>
|
|
|
+ )}
|
|
|
</Show>
|
|
|
<div class="paas-conversation">
|
|
|
<header class="paas-chat-header">
|
|
|
@@ -443,14 +434,6 @@ export function PaasChat(props: {
|
|
|
</span>
|
|
|
</div>
|
|
|
<div class="paas-chat-header-actions">
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- class="paas-history-toggle"
|
|
|
- aria-expanded={ui.historyOpen}
|
|
|
- onClick={() => setUI("historyOpen", !ui.historyOpen)}
|
|
|
- >
|
|
|
- 历史会话
|
|
|
- </button>
|
|
|
<Show when={currentAgent() && props.onEditAgent}>
|
|
|
<button disabled={!props.connected} onClick={() => props.onEditAgent?.(current()!.agentID)}>
|
|
|
研究设置
|
|
|
@@ -843,9 +826,7 @@ export function PaasChat(props: {
|
|
|
)}
|
|
|
</Show>
|
|
|
<Show when={model.job()}>
|
|
|
- <p class="paas-draft-hint">
|
|
|
- 研究正在进行;这里可填写下一轮要求,本轮反馈请在确认卡片提交。
|
|
|
- </p>
|
|
|
+ <p class="paas-draft-hint">研究正在进行;这里可填写下一轮要求,本轮反馈请在确认卡片提交。</p>
|
|
|
</Show>
|
|
|
<textarea
|
|
|
ref={(el) => {
|