|
|
@@ -1,6 +1,9 @@
|
|
|
import { For, Show, createEffect, createMemo, on, onCleanup, onMount, untrack } from "solid-js"
|
|
|
import { createStore } from "solid-js/store"
|
|
|
import { ResearchReport } from "./report"
|
|
|
+import { useDialog } from "@opencode-ai/ui/context/dialog"
|
|
|
+import { ResearchIssue } from "./issue"
|
|
|
+import { ReportReader } from "./report-reader"
|
|
|
import { Icon } from "@opencode-ai/ui/icon"
|
|
|
import { usePlatform } from "@/context/platform"
|
|
|
import {
|
|
|
@@ -29,6 +32,7 @@ export function PaasChat(props: {
|
|
|
onOpenAgentPacks: () => void
|
|
|
onOpenTasks?: () => void
|
|
|
onShowChat?: () => void
|
|
|
+ onConnection?: () => void
|
|
|
onOpenWorkspace?: (agentID: string) => Promise<void>
|
|
|
onEditAgent?: (agentID: string) => void
|
|
|
workspaceDisabled: boolean
|
|
|
@@ -36,6 +40,7 @@ export function PaasChat(props: {
|
|
|
onTaskOpened?: () => void
|
|
|
}) {
|
|
|
const platform = usePlatform()
|
|
|
+ const dialog = useDialog()
|
|
|
const [ui, setUI] = createStore({
|
|
|
threads: {} as Record<string, Record<string, unknown>[]>,
|
|
|
historyError: {} as Record<string, string>,
|
|
|
@@ -283,19 +288,26 @@ export function PaasChat(props: {
|
|
|
setUI("copyError", "复制未成功,可选中报告文字后复制。")
|
|
|
}
|
|
|
}
|
|
|
- async function exportReport(message: ResearchMessage) {
|
|
|
+ async function exportReport(message: ResearchMessage, format: "md" | "docx" | "pdf" = "md") {
|
|
|
if (!props.api || ui.exporting) return
|
|
|
const epoch = life.epoch
|
|
|
setUI({ exporting: message.id, exportError: "", saved: "", savedPath: "" })
|
|
|
try {
|
|
|
const result = paasRecord(
|
|
|
- await props.api.request({ action: "export-report", name: current()?.title || "研究报告", text: message.text }),
|
|
|
+ await props.api.request({
|
|
|
+ action: "export-report",
|
|
|
+ name: current()?.title || "研究报告",
|
|
|
+ text: message.text,
|
|
|
+ format,
|
|
|
+ }),
|
|
|
)
|
|
|
if (life.active && epoch === life.epoch && result?.saved)
|
|
|
setUI({ saved: paasText(result.name) || "研究报告", savedPath: paasText(result.path) })
|
|
|
+ return { saved: !!result?.saved, name: paasText(result?.name) }
|
|
|
} catch (error) {
|
|
|
if (life.active && epoch === life.epoch)
|
|
|
setUI("exportError", error instanceof Error ? error.message : "报告导出失败,可重试或复制报告。")
|
|
|
+ return { saved: false, error: error instanceof Error ? error.message : "报告导出失败,可重试。" }
|
|
|
} finally {
|
|
|
if (life.active && epoch === life.epoch) setUI("exporting", "")
|
|
|
}
|
|
|
@@ -401,20 +413,23 @@ export function PaasChat(props: {
|
|
|
研究设置
|
|
|
</button>
|
|
|
</Show>
|
|
|
- <Show when={current()}>
|
|
|
- <button onClick={() => setUI({ renaming: true, title: current()!.title })}>重命名会话</button>
|
|
|
- <button title="仅整理本机列表,不会停止后台任务" onClick={() => model.archive()}>
|
|
|
- {current()?.archived ? "取消归档" : "在本机归档"}
|
|
|
- </button>
|
|
|
- </Show>
|
|
|
- <Show when={currentAgent() && props.onOpenWorkspace}>
|
|
|
- <button
|
|
|
- disabled={props.workspaceDisabled}
|
|
|
- onClick={() => void props.onOpenWorkspace?.(current()!.agentID)}
|
|
|
- >
|
|
|
- 打开工作区
|
|
|
- </button>
|
|
|
- </Show>
|
|
|
+ <details class="paas-more-actions">
|
|
|
+ <summary>更多操作</summary>
|
|
|
+ <Show when={current()}>
|
|
|
+ <button onClick={() => setUI({ renaming: true, title: current()!.title })}>重命名会话</button>
|
|
|
+ <button title="仅整理本机列表,不会停止后台任务" onClick={() => model.archive()}>
|
|
|
+ {current()?.archived ? "取消归档" : "在本机归档"}
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ <Show when={currentAgent() && props.onOpenWorkspace}>
|
|
|
+ <button
|
|
|
+ disabled={props.workspaceDisabled}
|
|
|
+ onClick={() => void props.onOpenWorkspace?.(current()!.agentID)}
|
|
|
+ >
|
|
|
+ 打开工作区
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ </details>
|
|
|
<button disabled={!props.connected || !currentAgent()} onClick={() => model.choose(currentAgent()!, true)}>
|
|
|
新会话
|
|
|
</button>
|
|
|
@@ -561,17 +576,38 @@ export function PaasChat(props: {
|
|
|
</p>
|
|
|
</Show>
|
|
|
<Show when={message.error}>
|
|
|
- <p role="alert" class="paas-notice">
|
|
|
- {message.error}
|
|
|
- </p>
|
|
|
+ <ResearchIssue
|
|
|
+ message={message.error!}
|
|
|
+ onSettings={() => props.onEditAgent?.(agentID)}
|
|
|
+ onConnection={props.onConnection}
|
|
|
+ onTasks={props.onOpenTasks}
|
|
|
+ />
|
|
|
</Show>
|
|
|
<Show when={message.status === "partial"}>
|
|
|
<p class="paas-notice">
|
|
|
- 当前成果已保留,可先导出,或调整研究设置后基于已有成果继续。续研会填入草稿,由你确认发送,不会自动重跑。
|
|
|
+ 当前成果已保留,可先导出,或调整研究设置后基于已有成果继续。续研将引用已有报告,由你确认发送,不会自动重跑。
|
|
|
</p>
|
|
|
</Show>
|
|
|
<Show when={message.text}>
|
|
|
<div class="paas-actions">
|
|
|
+ <button
|
|
|
+ onClick={() =>
|
|
|
+ dialog.show(() => (
|
|
|
+ <ReportReader
|
|
|
+ message={message}
|
|
|
+ earlier={current()!
|
|
|
+ .messages.slice(
|
|
|
+ 0,
|
|
|
+ current()!.messages.findIndex((m) => m.id === message.id),
|
|
|
+ )
|
|
|
+ .filter((m) => m.role === "assistant" && !!m.text)}
|
|
|
+ onExport={(format) => exportReport(message, format)}
|
|
|
+ />
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 阅读与对比
|
|
|
+ </button>
|
|
|
<button onClick={() => void copy(message)}>
|
|
|
{ui.copied === message.id ? "已复制" : "复制报告"}
|
|
|
</button>
|
|
|
@@ -677,9 +713,12 @@ export function PaasChat(props: {
|
|
|
each={[state.error, state.storageError, materials.state.error, ui.copyError, ui.exportError].filter(Boolean)}
|
|
|
>
|
|
|
{(error) => (
|
|
|
- <p class="paas-notice" role="alert">
|
|
|
- {error}
|
|
|
- </p>
|
|
|
+ <ResearchIssue
|
|
|
+ message={error}
|
|
|
+ onSettings={current() ? () => props.onEditAgent?.(current()!.agentID) : undefined}
|
|
|
+ onConnection={props.onConnection}
|
|
|
+ onTasks={props.onOpenTasks}
|
|
|
+ />
|
|
|
)}
|
|
|
</For>
|
|
|
<form
|
|
|
@@ -758,9 +797,25 @@ export function PaasChat(props: {
|
|
|
</span>
|
|
|
)}
|
|
|
</For>
|
|
|
+ <Show when={current()?.reference}>
|
|
|
+ {(reference) => (
|
|
|
+ <div class="paas-reference" aria-label="已引用研究报告">
|
|
|
+ <details>
|
|
|
+ <summary>已引用研究报告 · 填写本轮新增要求即可</summary>
|
|
|
+ <pre>{reference().text}</pre>
|
|
|
+ </details>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setState("chats", (c) => c.id === current()?.id, "reference", undefined)}
|
|
|
+ >
|
|
|
+ 移除引用
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </Show>
|
|
|
<Show when={model.job()}>
|
|
|
<p class="paas-draft-hint">
|
|
|
- 当前任务继续在后台运行。这里编辑的是下一轮草稿,不会改变本轮执行;本轮反馈请在确认卡片提交。
|
|
|
+ 研究正在进行;这里可填写下一轮要求,本轮反馈请在确认卡片提交。
|
|
|
</p>
|
|
|
</Show>
|
|
|
<textarea
|
|
|
@@ -768,10 +823,12 @@ export function PaasChat(props: {
|
|
|
elements.input = el
|
|
|
}}
|
|
|
aria-label="消息"
|
|
|
- placeholder="描述研究目标、约束或希望交付的成果…"
|
|
|
+ placeholder={
|
|
|
+ current()?.reference ? "填写新增要求,或直接发送继续完善…" : "描述研究目标、约束或希望交付的成果…"
|
|
|
+ }
|
|
|
value={current()?.draft || ""}
|
|
|
disabled={!current()}
|
|
|
- rows={3}
|
|
|
+ rows={2}
|
|
|
onInput={(event) => draft(event.currentTarget.value)}
|
|
|
onKeyDown={(event) => {
|
|
|
if (event.key === "Enter" && !event.shiftKey && !event.isComposing) {
|
|
|
@@ -822,7 +879,7 @@ export function PaasChat(props: {
|
|
|
disabled={
|
|
|
!props.connected ||
|
|
|
!currentAgent() ||
|
|
|
- !current()?.draft.trim() ||
|
|
|
+ (!current()?.draft.trim() && !current()?.reference?.text) ||
|
|
|
!!model.job() ||
|
|
|
(!!current() && materials.busy(current()!.id))
|
|
|
}
|
|
|
@@ -830,7 +887,7 @@ export function PaasChat(props: {
|
|
|
<Icon name="arrow-up" />
|
|
|
</button>
|
|
|
</footer>
|
|
|
- <Show when={current()?.draft}>
|
|
|
+ <Show when={current()?.draft || current()?.reference}>
|
|
|
<small class="paas-muted">草稿已保留{model.job() ? ",任务结束后可发送" : ""}</small>
|
|
|
</Show>
|
|
|
</form>
|