|
|
@@ -1,5 +1,6 @@
|
|
|
import { For, Show, createEffect, on, onCleanup } from "solid-js"
|
|
|
import { createStore, reconcile } from "solid-js/store"
|
|
|
+import { PaasActivity, paasActivityItems } from "./activity"
|
|
|
import { PaasMarkdown } from "./markdown"
|
|
|
import {
|
|
|
paasRecord,
|
|
|
@@ -31,8 +32,11 @@ export function PaasRunPanel(props: {
|
|
|
api: PaasPlatform
|
|
|
agentID: string
|
|
|
runID: string
|
|
|
+ initial?: Record<string, unknown>
|
|
|
+ showGoal?: boolean
|
|
|
showResult?: boolean
|
|
|
onUpdate?: (run: Record<string, unknown>) => void
|
|
|
+ onClose?: () => void
|
|
|
}) {
|
|
|
const [state, setState] = createStore({
|
|
|
run: {} as Record<string, unknown>,
|
|
|
@@ -51,6 +55,7 @@ export function PaasRunPanel(props: {
|
|
|
if (value?.status && !["pending", "waiting"].includes(paasText(value.status))) return undefined
|
|
|
return value
|
|
|
}
|
|
|
+ const rawEvents = () => (Array.isArray(state.run.events) ? state.run.events : state.run.activity)
|
|
|
const lifecycle = { active: true, epoch: 0, request: 0, pending: 0 }
|
|
|
onCleanup(() => {
|
|
|
lifecycle.active = false
|
|
|
@@ -81,7 +86,7 @@ export function PaasRunPanel(props: {
|
|
|
on([() => props.api, () => props.agentID, () => props.runID], () => {
|
|
|
lifecycle.epoch++
|
|
|
setState({ files: [], filesLoaded: false, busy: "", error: "", syncError: "", note: "", message: "" })
|
|
|
- setState("run", reconcile({}))
|
|
|
+ setState("run", reconcile(props.initial ?? {}))
|
|
|
void refresh(true)
|
|
|
const timer = window.setInterval(() => {
|
|
|
if (!document.hidden && !state.busy && (active.has(status()) || state.syncError)) void refresh()
|
|
|
@@ -144,7 +149,11 @@ export function PaasRunPanel(props: {
|
|
|
: []
|
|
|
|
|
|
return (
|
|
|
- <section class="paas-panel" aria-label="任务进度与成果">
|
|
|
+ <section
|
|
|
+ class="paas-panel"
|
|
|
+ classList={{ "paas-detail": !!props.showGoal }}
|
|
|
+ aria-label={props.showGoal ? "任务详情" : "任务进度与成果"}
|
|
|
+ >
|
|
|
<div class="paas-actions">
|
|
|
<strong>{paasStatuses[status()] || "正在同步任务"}</strong>
|
|
|
<button type="button" disabled={!!state.busy} onClick={() => void refresh()}>
|
|
|
@@ -176,6 +185,11 @@ export function PaasRunPanel(props: {
|
|
|
继续执行
|
|
|
</button>
|
|
|
</Show>
|
|
|
+ <Show when={props.onClose}>
|
|
|
+ <button type="button" onClick={props.onClose}>
|
|
|
+ 收起
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
</div>
|
|
|
<Show when={state.busy}>
|
|
|
<p role="status">{state.busy}…</p>
|
|
|
@@ -190,6 +204,11 @@ export function PaasRunPanel(props: {
|
|
|
{state.syncError}
|
|
|
</p>
|
|
|
</Show>
|
|
|
+ <Show when={state.run.client_detail_source === "history"}>
|
|
|
+ <p class="paas-notice">
|
|
|
+ 当前平台未提供单条任务详情,此处展示刚刚读取的最近任务记录。成果与审批信息可能不包含在列表中。
|
|
|
+ </p>
|
|
|
+ </Show>
|
|
|
<Show when={status() === "failed" && paasText(state.run.error_message)}>
|
|
|
<p role="alert" class="paas-notice">
|
|
|
{paasText(state.run.error_message)}
|
|
|
@@ -230,17 +249,72 @@ export function PaasRunPanel(props: {
|
|
|
</div>
|
|
|
)}
|
|
|
</Show>
|
|
|
- <Show when={props.showResult && paasText(state.run.output)}>
|
|
|
+ <Show when={props.showGoal}>
|
|
|
+ <section class="paas-run-section" aria-label="概览">
|
|
|
+ <h3>概览</h3>
|
|
|
+ <Show when={paasText(state.run.input)}>
|
|
|
+ <p class="paas-run-goal">{paasText(state.run.input)}</p>
|
|
|
+ </Show>
|
|
|
+ <Show when={paasText(state.run.output)} fallback={<p class="paas-muted">平台暂未返回文本结果。</p>}>
|
|
|
+ <PaasMarkdown text={paasText(state.run.output)} />
|
|
|
+ </Show>
|
|
|
+ </section>
|
|
|
+ <section class="paas-run-section" aria-label="活动">
|
|
|
+ <h3>活动</h3>
|
|
|
+ <PaasActivity
|
|
|
+ items={paasActivityItems(rawEvents())}
|
|
|
+ empty="当前任务快照未包含工具事件;执行期间的实时活动显示在会话中。"
|
|
|
+ />
|
|
|
+ </section>
|
|
|
+ </Show>
|
|
|
+ <Show when={!props.showGoal && props.showResult && paasText(state.run.output)}>
|
|
|
<details class="paas-run-output">
|
|
|
<summary>查看最新结果</summary>
|
|
|
<PaasMarkdown text={paasText(state.run.output)} />
|
|
|
</details>
|
|
|
</Show>
|
|
|
- <For each={artifacts()}>
|
|
|
- {(file) => (
|
|
|
- <div class="paas-actions">
|
|
|
- <span>{paasText(file.name)}</span>
|
|
|
- <Show when={paasText(file.artifact_id)}>
|
|
|
+ <section class="paas-run-results" aria-label="成果">
|
|
|
+ <Show when={props.showGoal}>
|
|
|
+ <h3>成果{artifacts().length ? ` · ${artifacts().length}` : ""}</h3>
|
|
|
+ </Show>
|
|
|
+ <For each={artifacts()}>
|
|
|
+ {(file) => (
|
|
|
+ <div class="paas-actions">
|
|
|
+ <span>{paasText(file.name)}</span>
|
|
|
+ <Show when={paasText(file.artifact_id)}>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ disabled={!!state.busy}
|
|
|
+ onClick={() =>
|
|
|
+ void perform("下载", {
|
|
|
+ action: "download",
|
|
|
+ agentID: props.agentID,
|
|
|
+ runID: props.runID,
|
|
|
+ artifactID: paasText(file.artifact_id),
|
|
|
+ name: paasText(file.name),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 保存成果
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ disabled={!!state.busy}
|
|
|
+ onClick={() => void perform("读取文件", { action: "run-files", agentID: props.agentID, runID: props.runID })}
|
|
|
+ >
|
|
|
+ 查看工作文件
|
|
|
+ </button>
|
|
|
+ <Show when={state.filesLoaded && !state.files.length}>
|
|
|
+ <p>目前还没有工作文件。</p>
|
|
|
+ </Show>
|
|
|
+ <For each={state.files}>
|
|
|
+ {(file) => (
|
|
|
+ <div class="paas-actions">
|
|
|
+ <span>{paasText(file.name) || paasText(file.path)}</span>
|
|
|
<button
|
|
|
type="button"
|
|
|
disabled={!!state.busy}
|
|
|
@@ -249,49 +323,35 @@ export function PaasRunPanel(props: {
|
|
|
action: "download",
|
|
|
agentID: props.agentID,
|
|
|
runID: props.runID,
|
|
|
- artifactID: paasText(file.artifact_id),
|
|
|
- name: paasText(file.name),
|
|
|
+ path: paasText(file.path),
|
|
|
+ name: paasText(file.name) || paasText(file.path),
|
|
|
})
|
|
|
}
|
|
|
>
|
|
|
- 保存成果
|
|
|
+ 保存文件
|
|
|
</button>
|
|
|
- </Show>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- </For>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- disabled={!!state.busy}
|
|
|
- onClick={() => void perform("读取文件", { action: "run-files", agentID: props.agentID, runID: props.runID })}
|
|
|
- >
|
|
|
- 查看工作文件
|
|
|
- </button>
|
|
|
- <Show when={state.filesLoaded && !state.files.length}>
|
|
|
- <p>目前还没有工作文件。</p>
|
|
|
- </Show>
|
|
|
- <For each={state.files}>
|
|
|
- {(file) => (
|
|
|
- <div class="paas-actions">
|
|
|
- <span>{paasText(file.name) || paasText(file.path)}</span>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- disabled={!!state.busy}
|
|
|
- onClick={() =>
|
|
|
- void perform("下载", {
|
|
|
- action: "download",
|
|
|
- agentID: props.agentID,
|
|
|
- runID: props.runID,
|
|
|
- path: paasText(file.path),
|
|
|
- name: paasText(file.name) || paasText(file.path),
|
|
|
- })
|
|
|
- }
|
|
|
- >
|
|
|
- 保存文件
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- </For>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </section>
|
|
|
+ <details class="paas-run-technical">
|
|
|
+ <summary>技术信息</summary>
|
|
|
+ <dl>
|
|
|
+ <dt>任务编号</dt>
|
|
|
+ <dd>
|
|
|
+ <code>{props.runID}</code>
|
|
|
+ </dd>
|
|
|
+ <dt>智能体</dt>
|
|
|
+ <dd>
|
|
|
+ <code>{props.agentID}</code>
|
|
|
+ </dd>
|
|
|
+ <Show when={paasText(state.run.client_detail_source)}>
|
|
|
+ <dt>快照来源</dt>
|
|
|
+ <dd>{state.run.client_detail_source === "history" ? "最近任务列表" : "单条任务详情"}</dd>
|
|
|
+ </Show>
|
|
|
+ </dl>
|
|
|
+ <pre>{JSON.stringify(state.run, null, 2)}</pre>
|
|
|
+ </details>
|
|
|
</section>
|
|
|
)
|
|
|
}
|