Add reliable execution reporting and coordinated dashboard views
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { FormEvent } from 'react'
|
||||
import { Send, RefreshCw } from 'lucide-react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Send } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { PageHeading } from '@/components/shared'
|
||||
import { useWorkbench } from '@/lib/context'
|
||||
import { request, errorText, messageKey } from '@/lib/api'
|
||||
import type { Message } from '@/lib/types'
|
||||
@@ -40,6 +40,11 @@ export default function Communication() {
|
||||
const timer = setInterval(() => void poll(), 3000)
|
||||
return () => { controller.abort(); clearInterval(timer) }
|
||||
}, [selected, token, known, refreshVersion])
|
||||
useEffect(() => {
|
||||
const reload = () => { setRefreshVersion(n => n + 1); void refresh().catch(e => setError(errorText(e))) }
|
||||
window.addEventListener('workbench-refresh-conversation', reload)
|
||||
return () => window.removeEventListener('workbench-refresh-conversation', reload)
|
||||
}, [refresh])
|
||||
const items = messages.session === selected ? messages.items : []
|
||||
const lastId = items.at(-1)?.id
|
||||
useEffect(() => {
|
||||
@@ -48,6 +53,7 @@ export default function Communication() {
|
||||
if (loaded.current !== selected || box.scrollHeight - box.scrollTop - box.clientHeight < 300) box.scrollTop = box.scrollHeight
|
||||
loaded.current = selected
|
||||
}, [lastId, selected, messages.session])
|
||||
const decisions = (state as { decisions?: { id: string; status: string }[] }).decisions?.filter(d => d.status === 'open') || []
|
||||
const text = drafts[selected] || ''
|
||||
async function send(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
@@ -64,22 +70,24 @@ export default function Communication() {
|
||||
} catch (e) { setError(errorText(e)) }
|
||||
finally { setSending(false) }
|
||||
}
|
||||
return <div className="mx-auto flex w-full max-w-4xl flex-col gap-5">
|
||||
<PageHeading title="项目沟通" description="询问进度、讨论方案,或告诉我你的新想法。" action={<Button variant="ghost" size="sm" onClick={() => { setRefreshVersion(n => n + 1); void refresh() }}><RefreshCw />刷新</Button>} />
|
||||
return <div className="flex min-h-0 w-full flex-1 flex-col">
|
||||
|
||||
{decisions.length > 0 && <p className="shrink-0 border-b px-4 py-3 text-sm"><Link className="text-primary underline underline-offset-4" to={`/decisions?decision=${encodeURIComponent(decisions[0].id)}`}>有 {decisions.length} 项需要你决定,查看决策</Link></p>}
|
||||
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
||||
<section className="overflow-hidden rounded-xl border bg-card">
|
||||
<div ref={scroll} role="log" aria-label="对话" aria-live="polite" className="h-[min(60vh,660px)] min-h-72 space-y-6 overflow-y-auto p-5 sm:p-7">
|
||||
<section className="flex min-h-0 flex-1 flex-col bg-card">
|
||||
<div ref={scroll} role="log" aria-label="对话" aria-live="polite" className="min-h-0 flex-1 space-y-6 overflow-y-auto px-4 py-5 sm:px-8">
|
||||
{items.length ? items.map(m => <article key={m.id} className={`flex ${m.source === 'human' ? 'justify-end' : 'justify-start'}`}>
|
||||
<div className={`max-w-[92%] rounded-2xl px-4 py-3 sm:max-w-[85%] ${m.source === 'human' ? 'bg-primary text-primary-foreground' : 'bg-muted/60'}`}>
|
||||
<p className="mb-1 text-xs opacity-65">{m.source === 'human' ? '你' : '项目助手'}</p>
|
||||
<p className="whitespace-pre-wrap wrap-anywhere text-sm leading-7">{m.text}</p>
|
||||
{m.log_id && <Link className="mt-2 inline-block text-sm text-primary underline underline-offset-4" to={`/logs?incident=${encodeURIComponent(m.log_id)}`}>查看日志</Link>}
|
||||
{m.source === 'human' && ['queued', 'claimed'].includes(m.status) && <p className="mt-2 text-xs opacity-70">正在等待回复…</p>}
|
||||
{m.source === 'human' && ['failed', 'uncertain'].includes(m.status) && <p className="mt-2 text-xs opacity-70">暂未确认回复,请稍后查看;无需重复发送。</p>}
|
||||
</div>
|
||||
</article>) : <div className="flex h-full items-center justify-center text-sm text-muted-foreground">{known ? '有什么想了解的?从这里开始交流。' : '会话准备好后,即可在这里交流。'}</div>}
|
||||
</div>
|
||||
<form onSubmit={send} className="border-t p-4">
|
||||
<Textarea id="message" aria-label="输入消息" value={text} onChange={e => setDrafts(old => ({ ...old, [selected]: e.target.value }))} placeholder="输入你的问题或想法…" maxLength={32000} rows={3} required className="resize-none border-0 shadow-none focus-visible:ring-0" />
|
||||
<form onSubmit={send} className="shrink-0 border-t p-3 sm:px-8">
|
||||
<Textarea id="message" aria-label="输入消息" value={text} onChange={e => setDrafts(old => ({ ...old, [selected]: e.target.value }))} placeholder="输入你的问题或想法…" maxLength={32000} rows={2} required className="resize-none border-0 shadow-none focus-visible:ring-0" />
|
||||
<div className="mt-2 flex items-center justify-between gap-3"><p className="text-xs text-muted-foreground">{!known ? '正在准备会话' : session?.connection === 'connected' ? '' : '暂时离线,消息会保存并等待回复。'}</p><Button type="submit" disabled={!known || sending || !text.trim()}><Send />{sending ? '发送中…' : '发送'}</Button></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user