fix(pipeline): BREAK-04 接入 pipeline-complete 事件监听
PipelinesPanel 新增 useEffect 订阅 PipelineClient.onComplete(), 处理用户导航离开后的后台 Pipeline 完成通知。 - 后台完成时 toast 提示成功/失败 - 跳过当前选中 pipeline 的重复通知(轮询路径已处理) - 组件卸载时自动清理监听器
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
* Pipelines orchestrate Skills and Hands to accomplish complex tasks.
|
* Pipelines orchestrate Skills and Hands to accomplish complex tasks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Play,
|
Play,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
@@ -437,6 +437,22 @@ export function PipelinesPanel() {
|
|||||||
const [runResult, setRunResult] = useState<{ result: PipelineRunResponse; pipeline: PipelineInfo } | null>(null);
|
const [runResult, setRunResult] = useState<{ result: PipelineRunResponse; pipeline: PipelineInfo } | null>(null);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
// Subscribe to pipeline-complete push events (for background completion)
|
||||||
|
useEffect(() => {
|
||||||
|
let unlisten: (() => void) | undefined;
|
||||||
|
PipelineClient.onComplete((event) => {
|
||||||
|
// Only show notification if we're not already tracking this run
|
||||||
|
// (the polling path handles in-flight runs via handleRunComplete)
|
||||||
|
if (selectedPipeline?.id === event.pipelineId) return;
|
||||||
|
if (event.status === 'completed') {
|
||||||
|
toast(`Pipeline "${event.pipelineId}" 后台执行完成`, 'success');
|
||||||
|
} else if (event.status === 'failed') {
|
||||||
|
toast(`Pipeline "${event.pipelineId}" 后台执行失败: ${event.error ?? ''}`, 'error');
|
||||||
|
}
|
||||||
|
}).then((fn) => { unlisten = fn; });
|
||||||
|
return () => { unlisten?.(); };
|
||||||
|
}, [selectedPipeline, toast]);
|
||||||
|
|
||||||
// Fetch all pipelines without filtering
|
// Fetch all pipelines without filtering
|
||||||
const { pipelines, loading, error, refresh } = usePipelines({});
|
const { pipelines, loading, error, refresh } = usePipelines({});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user