56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { getTaskRunSquad, type SquadMemberDTO } from '../../api/taskRuns';
|
|
import { subagentsHash } from '../../engine/anchorNavigator';
|
|
import { useRunProcessStream } from '../../hooks/useRunProcessStream';
|
|
import { itemsForLayout, SubagentsLayout } from './SubagentsLayout';
|
|
|
|
export function SubagentsView(props: {
|
|
runId: string;
|
|
sessionId: string;
|
|
roleId?: string;
|
|
onExit: () => void;
|
|
}) {
|
|
const stream = useRunProcessStream(props.runId);
|
|
const [members, setMembers] = useState<SquadMemberDTO[]>([]);
|
|
const [title, setTitle] = useState('');
|
|
const [notice, setNotice] = useState<string | undefined>();
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
void getTaskRunSquad(props.runId)
|
|
.then((squad) => {
|
|
if (cancelled) return;
|
|
setMembers(squad.members || []);
|
|
setTitle(squad.title || squad.task_key || '');
|
|
setNotice(undefined);
|
|
})
|
|
.catch(() => {
|
|
if (!cancelled) setNotice('暂时读不到小队编制,过程事件仍会显示。');
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [props.runId]);
|
|
|
|
const selectRole = (role: string) => {
|
|
const next = subagentsHash({ sessionId: props.sessionId, runId: props.runId, roleId: role });
|
|
if (window.location.hash !== next) window.location.hash = next;
|
|
};
|
|
|
|
const streamNotice = stream.status === 'error' ? '过程流中断,可返回对话后重新进入。' : notice;
|
|
|
|
return (
|
|
<SubagentsLayout
|
|
title={title}
|
|
runId={props.runId}
|
|
members={members}
|
|
items={itemsForLayout(stream.items)}
|
|
phases={stream.phases}
|
|
selectedRole={props.roleId}
|
|
onSelectRole={selectRole}
|
|
onExit={props.onExit}
|
|
notice={streamNotice}
|
|
/>
|
|
);
|
|
}
|