fix: show empty work preview without invoking the Agent
This commit is contained in:
@@ -176,11 +176,17 @@ export function AgentBrowserPanel({
|
||||
const work = useWorkPreview({
|
||||
projectId, conversationId, enabled: embedded && open, revision: workRevision,
|
||||
onResult: (result) => {
|
||||
if (result.status === 'empty') {
|
||||
setError(null);
|
||||
setPresentationFailed(false);
|
||||
presentationRetries.current = 0;
|
||||
}
|
||||
if (result.browser) applySnapshot(result.browser);
|
||||
if (result.conversation) onWorkConversation?.(result.conversation);
|
||||
onWorkResult?.(result);
|
||||
},
|
||||
});
|
||||
const workEmpty = embedded && work.result?.status === 'empty';
|
||||
const workPending = embedded && (work.result?.status !== 'ready' || presentationFailed);
|
||||
const recovery = codingRecovery(work.result?.errorCode, true);
|
||||
const transportFailure = ['NETWORK', 'TIMEOUT'].includes(work.result?.errorCode ?? '');
|
||||
@@ -220,6 +226,7 @@ export function AgentBrowserPanel({
|
||||
(next) => {
|
||||
if (next.projectId !== projectId) return;
|
||||
applySnapshot(next);
|
||||
if (workEmpty) restoreWork();
|
||||
onOpenChange(true);
|
||||
},
|
||||
);
|
||||
@@ -234,7 +241,7 @@ export function AgentBrowserPanel({
|
||||
unsubscribeShow();
|
||||
unsubscribeState();
|
||||
};
|
||||
}, [applySnapshot, onOpenChange, projectId]);
|
||||
}, [applySnapshot, onOpenChange, projectId, restoreWork, workEmpty]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !projectId) return undefined;
|
||||
@@ -520,7 +527,7 @@ export function AgentBrowserPanel({
|
||||
/>
|
||||
</form>
|
||||
|
||||
{error ? (
|
||||
{error && !workEmpty ? (
|
||||
<p role="alert" className="shrink-0 border-b border-destructive/15 bg-destructive/5 px-3 py-2 text-xs text-destructive">
|
||||
{error}
|
||||
</p>
|
||||
@@ -538,17 +545,17 @@ export function AgentBrowserPanel({
|
||||
<Globe2 className="h-5 w-5" aria-hidden="true" />
|
||||
</span>
|
||||
<p role="status" className="text-[13px] font-semibold text-foreground">{embedded
|
||||
? presentationFailed ? '作品画面暂时没能显示' : work.result?.status === 'failed' ? '作品还没有打开' : work.result?.status === 'waiting' ? '等当前步骤完成,就帮你打开作品' : '正在打开你的作品…'
|
||||
? workEmpty ? '还没有作品,快和老师聊聊吧' : presentationFailed ? '作品画面暂时没能显示' : work.result?.status === 'failed' ? '作品还没有打开' : work.result?.status === 'waiting' ? '等当前步骤完成,就帮你打开作品' : '正在打开你的作品…'
|
||||
: '开始浏览'}</p>
|
||||
<p className="text-xs leading-6">{embedded
|
||||
{!workEmpty && <p className="text-xs leading-6">{embedded
|
||||
? presentationFailed ? '点“重新打开作品”,接着看你的作品。' : work.result?.message ?? '准备好后,页面会自动出现在这里。'
|
||||
: '输入 URL,或等待智能体打开调试页面'}</p>
|
||||
: '输入 URL,或等待智能体打开调试页面'}</p>}
|
||||
{embedded && <div className="flex gap-2">
|
||||
{presentationFailed ? <Button variant="outline" size="sm" onClick={retryPresentation}>重新打开作品</Button> : work.result?.status === 'failed' && <Button variant="outline" size="sm" onClick={async () => {
|
||||
{!workEmpty && (presentationFailed ? <Button variant="outline" size="sm" onClick={retryPresentation}>重新打开作品</Button> : work.result?.status === 'failed' && <Button variant="outline" size="sm" onClick={async () => {
|
||||
if (transportFailure || recovery.action === 'check-work' || recovery.action === 'refresh') work.retry();
|
||||
else try { await onRecovery?.(recovery.action, true); }
|
||||
catch { setError('暂时没能继续,请稍后再点一次。'); }
|
||||
}}>{transportFailure ? '再试一次' : recovery.label}</Button>}
|
||||
}}>{transportFailure ? '再试一次' : recovery.label}</Button>)}
|
||||
<Button variant="ghost" size="sm" onClick={() => onOpenChange(false)}>回到操作对话</Button>
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user