mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): add Native Swarm mode compatibility and distinct worker telemetry
- Guard conversation_parents against forked Swarm Workers (subagentSpec or trajectoryType != 22) and selectively decode CORTEX_STEP_TYPE_SYSTEM_MESSAGE (step_type = 101) for child trajectories only
- Parse swarm, post_message, read_board, and swarm_wait tool calls, split zero-human-turn worker trajectories on initial brief / @mention / cron wakeup boundaries, and downgrade swarm_wait parked workers from RUNNING to IDLE ('waiting') while surfacing killed workers ('killed')
- Scan brain/<id>/.system_generated/swarm/members.json with mtime+size memoization, sort workers chronologically, assign independent swarm_worker ordinals (蜂k / Wk) separate from standard subagents (子k / Sk) and side questions (问k / Qk), and preserve 100% of worker token/USD billing
- Render Swarm counts, titles, scrollable sorted live worker lists, and one-shot auto-focus when navigating host routes to /c/<worker-uuid>, backed by E2E and binary SQLite tests
This commit is contained in:
@@ -80,18 +80,24 @@ function projectDisplayStep(st) {
|
||||
modelUpstream, responseModel, modelSource, tokPerSec, ttftSec, totalDurationSec,
|
||||
streamDurationSec, selectedSpeedReason, contextTokens, inputTokens, cacheReadTokens,
|
||||
outputTokens, thinkingTokens, responseTokens, cacheHitPct, costUsd, inCostUsd,
|
||||
cacheCostUsd, outCostUsd, agentId, agentCascadeId, agentLabel, agentBadge,
|
||||
agentRole, agentIndex, isSubagent, turnIndex, isTurnStart, isLatestTurn,
|
||||
turnPrompt, rootTurnIndex, isRootTurnStart, isRootLatestTurn, rootTurnPrompt,
|
||||
cacheCostUsd, outCostUsd, agentId, agentCascadeId, agentKind, agentOrdinal,
|
||||
agentCustomRole, agentLabel, agentBadge, agentRole, agentIndex, isSubagent,
|
||||
isSideQuestion, sideIndex, turnIndex, isTurnStart, isLatestTurn, turnPrompt,
|
||||
turnPromptClean, turnHasMedia, turnMediaOnly, rootTurnIndex, isRootTurnStart,
|
||||
isRootLatestTurn, rootTurnPrompt, rootTurnPromptClean, rootTurnHasMedia,
|
||||
rootTurnMediaOnly,
|
||||
} = st;
|
||||
return {
|
||||
stepIndex, createdAtMs, isCompactionStep, modelKey, modelShort, modelLabel,
|
||||
modelUpstream, responseModel, modelSource, tokPerSec, ttftSec, totalDurationSec,
|
||||
streamDurationSec, selectedSpeedReason, contextTokens, inputTokens, cacheReadTokens,
|
||||
outputTokens, thinkingTokens, responseTokens, cacheHitPct, costUsd, inCostUsd,
|
||||
cacheCostUsd, outCostUsd, agentId, agentCascadeId, agentLabel, agentBadge,
|
||||
agentRole, agentIndex, isSubagent, turnIndex, isTurnStart, isLatestTurn,
|
||||
turnPrompt, rootTurnIndex, isRootTurnStart, isRootLatestTurn, rootTurnPrompt,
|
||||
cacheCostUsd, outCostUsd, agentId, agentCascadeId, agentKind, agentOrdinal,
|
||||
agentCustomRole, agentLabel, agentBadge, agentRole, agentIndex, isSubagent,
|
||||
isSideQuestion, sideIndex, turnIndex, isTurnStart, isLatestTurn, turnPrompt,
|
||||
turnPromptClean, turnHasMedia, turnMediaOnly, rootTurnIndex, isRootTurnStart,
|
||||
isRootLatestTurn, rootTurnPrompt, rootTurnPromptClean, rootTurnHasMedia,
|
||||
rootTurnMediaOnly,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -678,6 +678,16 @@ export function readLocalSummarySnapshot(productRoots = PRODUCT_DATA_ROOTS, { fo
|
||||
const sqLower = String(pRow?.conversation_id || '').trim().toLowerCase();
|
||||
const parentLower = String(pRow?.parent_id || '').trim().toLowerCase();
|
||||
if (!sqLower || !parentLower) continue;
|
||||
const childSummary = nextSummariesObj[sqLower];
|
||||
if (
|
||||
childSummary &&
|
||||
!childSummary.isSideQuestion &&
|
||||
(childSummary.trajectoryMetadata?.subagentSpec ||
|
||||
(Number(childSummary.trajectoryType) > 0 && Number(childSummary.trajectoryType) !== 22))
|
||||
) {
|
||||
// 排除通过 fork 创建的蜂群工蜂或常规子代理,避免误归入旁路提问
|
||||
continue;
|
||||
}
|
||||
const parentSummary = nextSummariesObj[parentLower];
|
||||
const titleFromParent = String(
|
||||
parentSummary?.annotations?.sideQuestionTitles?.[sqLower] ||
|
||||
@@ -1451,7 +1461,26 @@ function decodeProtoGenericStepInvokeSubagentSlice(buf, state, end) {
|
||||
return invokeSubagent;
|
||||
}
|
||||
|
||||
function decodeProtoSelectiveStepPayload(rawBlob, { stepTypeNum, isInvokeSubagent, keepFullText }) {
|
||||
function decodeProtoSystemMessageSlice(buf, state, end) {
|
||||
let message = '';
|
||||
while (state.off < end) {
|
||||
const tag = Number(BigInt.asUintN(32, readProtoVarint(buf, state, end)));
|
||||
const fn = tag >>> 3;
|
||||
const wt = tag & 7;
|
||||
if (fn === 1 && wt === 2) {
|
||||
message = readProtoString(buf, state, end);
|
||||
} else {
|
||||
skipProtoField(buf, state, wt, end);
|
||||
}
|
||||
}
|
||||
state.off = end;
|
||||
return message;
|
||||
}
|
||||
|
||||
function decodeProtoSelectiveStepPayload(
|
||||
rawBlob,
|
||||
{ stepTypeNum, isInvokeSubagent, includeSystemMessage = false, keepFullText }
|
||||
) {
|
||||
const buf = toUint8Array(rawBlob);
|
||||
if (!buf || buf.length === 0) return {};
|
||||
const state = { off: 0 };
|
||||
@@ -1472,6 +1501,9 @@ function decodeProtoSelectiveStepPayload(rawBlob, { stepTypeNum, isInvokeSubagen
|
||||
readSubEnd(buf, state, end),
|
||||
keepFullText
|
||||
);
|
||||
} else if (fn === 114 && wt === 2 && stepTypeNum === 101 && includeSystemMessage) {
|
||||
const sysMsg = decodeProtoSystemMessageSlice(buf, state, readSubEnd(buf, state, end));
|
||||
if (sysMsg) out.systemMessage = { message: sysMsg };
|
||||
} else if (fn === 140 && wt === 2 && isInvokeSubagent) {
|
||||
const inv = decodeProtoGenericStepInvokeSubagentSlice(buf, state, readSubEnd(buf, state, end));
|
||||
if (inv) out.invokeSubagent = inv;
|
||||
@@ -1728,6 +1760,17 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
|
||||
ownStepRecords.push({ idx, stepTypeNum, statusNum, metadata });
|
||||
}
|
||||
|
||||
const isChildTrajectory =
|
||||
!isSideQuestion &&
|
||||
Boolean(
|
||||
trajectoryMetadata.parentConversationId ||
|
||||
parentConversationId ||
|
||||
(trajectoryMetadata.rootConversationId &&
|
||||
trajectoryMetadata.rootConversationId !== normCid) ||
|
||||
(rootConversationId && rootConversationId !== normCid) ||
|
||||
trajectoryMetadata.subagentSpec
|
||||
);
|
||||
|
||||
const runningTailStart = isRunning
|
||||
? Math.max(0, ownStepRecords.length - 16)
|
||||
: ownStepRecords.length;
|
||||
@@ -1743,6 +1786,7 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
|
||||
if (
|
||||
rec.stepTypeNum === 14 ||
|
||||
rec.stepTypeNum === 15 ||
|
||||
(isChildTrajectory && rec.stepTypeNum === 101) ||
|
||||
isInvSub ||
|
||||
(inRunningTail && (rec.stepTypeNum !== 132 || !rec.metadata?.toolCall?.argumentsJson))
|
||||
) {
|
||||
@@ -1805,6 +1849,7 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
|
||||
const decodedPayload = decodeProtoSelectiveStepPayload(rawPayload, {
|
||||
stepTypeNum: rec.stepTypeNum,
|
||||
isInvokeSubagent: isInvSub,
|
||||
includeSystemMessage: isChildTrajectory && rec.stepTypeNum === 101,
|
||||
keepFullText: inRunningTail,
|
||||
});
|
||||
if (decodedPayload.userInput) {
|
||||
@@ -1816,6 +1861,10 @@ export function readLocalSqliteTrajectory(dbFilePath, options = {}) {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (decodedPayload.systemMessage) {
|
||||
stepObj.systemMessage = decodedPayload.systemMessage;
|
||||
stepObj.content = decodedPayload.systemMessage.message;
|
||||
}
|
||||
if (decodedPayload.plannerResponse) {
|
||||
stepObj.plannerResponse = decodedPayload.plannerResponse;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import {
|
||||
extractLiveActivity,
|
||||
extractModelSteps,
|
||||
getMaxMeaningfulStepIndex,
|
||||
isParkedOnSwarmWait,
|
||||
parseIsoMs,
|
||||
parseSwarmWorkerRole,
|
||||
} from '../trajectory-metrics.mjs';
|
||||
import {
|
||||
ANNOTATION_DIRS,
|
||||
@@ -353,11 +355,133 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
||||
const failedFetchCooldownMap = new Map();
|
||||
const liveActivityMemo = new Map();
|
||||
const transcriptTailMemo = new Map();
|
||||
const swarmManifestMemo = new Map();
|
||||
|
||||
export function clearScannerRuntimeMemos() {
|
||||
failedFetchCooldownMap.clear();
|
||||
liveActivityMemo.clear();
|
||||
transcriptTailMemo.clear();
|
||||
swarmManifestMemo.clear();
|
||||
}
|
||||
|
||||
function findSwarmMembersPath(cascadeId) {
|
||||
if (!cascadeId) return '';
|
||||
const normId = String(cascadeId).trim().toLowerCase();
|
||||
if (!UUID_RE.test(normId)) return '';
|
||||
const dirs = Array.isArray(BRAIN_DIRS) && BRAIN_DIRS.length > 0 ? BRAIN_DIRS : [BRAIN_DIR];
|
||||
let bestPath = '';
|
||||
let bestMtime = -1;
|
||||
for (const dir of dirs) {
|
||||
if (!dir) continue;
|
||||
const candidate = join(dir, normId, '.system_generated', 'swarm', 'members.json');
|
||||
if (!existsSync(candidate)) continue;
|
||||
if (dirs.length === 1) return candidate;
|
||||
try {
|
||||
const mtime = Number(statSync(candidate)?.mtimeMs || 0);
|
||||
if (mtime > bestMtime) {
|
||||
bestMtime = mtime;
|
||||
bestPath = candidate;
|
||||
}
|
||||
} catch {
|
||||
if (!bestPath) bestPath = candidate;
|
||||
}
|
||||
}
|
||||
return bestPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按会话 ID 精确读取本地 `brain/<cascadeId>/.system_generated/swarm/members.json` 蜂群花名册(O(1) 定点读取 + `mtimeMs + size` 缓存)。
|
||||
*
|
||||
* @param {string} cascadeId
|
||||
* @returns {{
|
||||
* title: string,
|
||||
* coordinator: object|null,
|
||||
* membersByCid: Map<string, object>,
|
||||
* membersByName: Map<string, object>,
|
||||
* workerRefs: Array<object>
|
||||
* } | null}
|
||||
*/
|
||||
export function readSwarmManifestForCascade(cascadeId) {
|
||||
if (!cascadeId) return null;
|
||||
const normId = String(cascadeId).trim().toLowerCase();
|
||||
if (!UUID_RE.test(normId)) return null;
|
||||
const membersPath = findSwarmMembersPath(normId);
|
||||
if (!membersPath) {
|
||||
swarmManifestMemo.delete(normId);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const st = statSync(membersPath);
|
||||
const mtimeMs = Number(st?.mtimeMs || 0);
|
||||
const size = Number(st?.size || 0);
|
||||
const cached = swarmManifestMemo.get(normId);
|
||||
if (
|
||||
cached &&
|
||||
cached.path === membersPath &&
|
||||
cached.mtimeMs === mtimeMs &&
|
||||
cached.size === size &&
|
||||
size > 0
|
||||
) {
|
||||
return cached.manifest;
|
||||
}
|
||||
const raw = readFileSync(membersPath, 'utf8');
|
||||
const parsed = raw ? JSON.parse(raw) : null;
|
||||
if (!parsed || typeof parsed !== 'object') return null;
|
||||
|
||||
const title = String(parsed.title || '').trim();
|
||||
const rawMembers = parsed.members && typeof parsed.members === 'object' ? parsed.members : {};
|
||||
const membersByCid = new Map();
|
||||
const membersByName = new Map();
|
||||
const workerRefs = [];
|
||||
let coordinator = null;
|
||||
|
||||
for (const [rawKey, m] of Object.entries(rawMembers)) {
|
||||
if (!m || typeof m !== 'object') continue;
|
||||
const memberName = String(m.name || rawKey || '').replace(/^@+/, '').trim();
|
||||
const cid = String(m.conversation_id || m.conversationId || '').trim().toLowerCase();
|
||||
if (!cid || !UUID_RE.test(cid)) continue;
|
||||
const role = String(m.role || '').trim().toLowerCase();
|
||||
const wakeMode = String(m.wake_mode || m.wakeMode || '').trim().toLowerCase();
|
||||
const killed = Boolean(m.killed);
|
||||
const workspaceMode = String(m.workspace_mode || m.workspaceMode || 'inherit').trim();
|
||||
const model = String(m.applied_model || m.model || m.desired_model || '').trim();
|
||||
const entry = {
|
||||
memberName,
|
||||
conversationId: cid,
|
||||
role,
|
||||
wakeMode,
|
||||
killed,
|
||||
workspaceMode,
|
||||
model,
|
||||
};
|
||||
membersByCid.set(cid, entry);
|
||||
if (memberName) {
|
||||
membersByName.set(memberName.toLowerCase(), entry);
|
||||
}
|
||||
if (role === 'coordinator' || cid === normId) {
|
||||
coordinator = entry;
|
||||
} else {
|
||||
workerRefs.push({
|
||||
cascadeId: cid,
|
||||
role: memberName ? `Swarm Worker (${memberName})` : 'Swarm Worker',
|
||||
typeName: 'worker',
|
||||
memberName,
|
||||
createdTimeMs: 0,
|
||||
spawnOrder: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const manifest = { title, coordinator, membersByCid, membersByName, workerRefs };
|
||||
if (swarmManifestMemo.size >= MAX_TRANSCRIPT_MEMO_ENTRIES && !swarmManifestMemo.has(normId)) {
|
||||
const oldestKey = swarmManifestMemo.keys().next().value;
|
||||
if (oldestKey !== undefined) swarmManifestMemo.delete(oldestKey);
|
||||
}
|
||||
swarmManifestMemo.set(normId, { path: membersPath, mtimeMs, size, manifest });
|
||||
return manifest;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function findTranscriptPath(cascadeId) {
|
||||
@@ -461,6 +585,7 @@ function enrichSqliteStepsFromTranscriptIfNeeded(cidLower, sqliteSteps) {
|
||||
const needsTranscriptBackfill = sqliteSteps.some(
|
||||
(s) =>
|
||||
(s?.type === 'CORTEX_STEP_TYPE_USER_INPUT' && !s.userInput) ||
|
||||
(s?.type === 'CORTEX_STEP_TYPE_SYSTEM_MESSAGE' && !s.content && !s.systemMessage) ||
|
||||
(s?.metadata?.modelUsage && !s.metadata.modelUsage.model)
|
||||
);
|
||||
if (!needsTranscriptBackfill) {
|
||||
@@ -522,6 +647,12 @@ function enrichSqliteStepsFromTranscriptIfNeeded(cidLower, sqliteSteps) {
|
||||
if (typeof tLine.content === 'string') sq.content = tLine.content;
|
||||
if (tLine.userInput) sq.userInput = tLine.userInput;
|
||||
if (Array.isArray(tLine.media)) sq.media = tLine.media;
|
||||
} else if (
|
||||
sq.type === 'CORTEX_STEP_TYPE_SYSTEM_MESSAGE' &&
|
||||
!sq.content &&
|
||||
typeof tLine.content === 'string'
|
||||
) {
|
||||
sq.content = tLine.content;
|
||||
} else if (sq.metadata?.modelUsage && !sq.metadata.modelUsage.model) {
|
||||
const fallbackModel = String(tLine.model || tLine.generator_model || '').trim();
|
||||
if (fallbackModel) sq.metadata.modelUsage.model = fallbackModel;
|
||||
@@ -635,6 +766,23 @@ function loadOfflineTranscriptConversation(conv, diskFiles, externalByLower, loc
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (sq.type === 'CORTEX_STEP_TYPE_SYSTEM_MESSAGE') {
|
||||
const sysText =
|
||||
typeof sq.content === 'string' && sq.content
|
||||
? sq.content
|
||||
: typeof tLine?.content === 'string'
|
||||
? tLine.content
|
||||
: '';
|
||||
if (sysText) {
|
||||
sqliteRawSteps.push({
|
||||
type: sq.type,
|
||||
status: sq.status,
|
||||
content: sysText,
|
||||
metadata: sq.metadata,
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sq.metadata?.modelUsage) {
|
||||
const deepStep = extMatch?.steps?.[modelOrdinal] || null;
|
||||
@@ -672,7 +820,9 @@ function loadOfflineTranscriptConversation(conv, diskFiles, externalByLower, loc
|
||||
if (
|
||||
upperType === 'USER_INPUT' ||
|
||||
upperType === 'CORTEX_STEP_TYPE_USER_INPUT' ||
|
||||
(line.userInput && typeof line.userInput === 'object')
|
||||
(line.userInput && typeof line.userInput === 'object') ||
|
||||
upperType === 'SYSTEM_MESSAGE' ||
|
||||
upperType === 'CORTEX_STEP_TYPE_SYSTEM_MESSAGE'
|
||||
) {
|
||||
sqliteRawSteps.push(line);
|
||||
} else if (
|
||||
@@ -721,7 +871,9 @@ function loadOfflineTranscriptConversation(conv, diskFiles, externalByLower, loc
|
||||
if (
|
||||
upperType === 'USER_INPUT' ||
|
||||
upperType === 'CORTEX_STEP_TYPE_USER_INPUT' ||
|
||||
(line.userInput && typeof line.userInput === 'object')
|
||||
(line.userInput && typeof line.userInput === 'object') ||
|
||||
upperType === 'SYSTEM_MESSAGE' ||
|
||||
upperType === 'CORTEX_STEP_TYPE_SYSTEM_MESSAGE'
|
||||
) {
|
||||
syntheticSteps.push(line);
|
||||
continue;
|
||||
@@ -1390,8 +1542,10 @@ export async function enumerateAndSyncConversations({
|
||||
Boolean(cached?.isSubagent) ||
|
||||
Boolean(parentConversationId) ||
|
||||
Boolean(rootConversationId && rootConversationId !== cidLower);
|
||||
const isKilled = Boolean(item?.killed || localSum?.killed);
|
||||
const latestLocalTouchMs = Math.max(diskMtimeMs || 0, localSum?.lastModifiedMs || 0);
|
||||
const localStatus =
|
||||
!isKilled &&
|
||||
localSum?.status === 'CASCADE_RUN_STATUS_RUNNING' &&
|
||||
latestLocalTouchMs > 0 &&
|
||||
nowSweepMs - latestLocalTouchMs <= STALE_LOCAL_RUNNING_MAX_AGE_MS
|
||||
@@ -1417,7 +1571,8 @@ export async function enumerateAndSyncConversations({
|
||||
(isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
stepCount: modelStepCount,
|
||||
rawStepCount: rawSummaryStepCount,
|
||||
status: item?.status || '',
|
||||
status: isKilled ? 'IDLE' : item?.status || '',
|
||||
killed: isKilled,
|
||||
lastModifiedTime,
|
||||
lastModifiedMs,
|
||||
diskMtimeMs,
|
||||
@@ -1448,6 +1603,7 @@ export async function enumerateAndSyncConversations({
|
||||
stepCount: cachedStepCount,
|
||||
rawStepCount: localSum?.stepCount || cached.rawStepCount || cachedStepCount,
|
||||
status: localStatus,
|
||||
killed: isKilled,
|
||||
lastModifiedTime: localSum?.lastModifiedTime || '',
|
||||
lastModifiedMs: Math.max(
|
||||
cached.lastModifiedMs || 0,
|
||||
@@ -1480,6 +1636,7 @@ export async function enumerateAndSyncConversations({
|
||||
stepCount: 0,
|
||||
rawStepCount: localSum?.stepCount || 0,
|
||||
status: localStatus,
|
||||
killed: isKilled,
|
||||
lastModifiedTime: localSum?.lastModifiedTime || '',
|
||||
lastModifiedMs: Math.max(diskMtimeMs || 0, localSum?.lastModifiedMs || 0),
|
||||
diskMtimeMs,
|
||||
@@ -1710,6 +1867,19 @@ export async function enumerateAndSyncConversations({
|
||||
}
|
||||
|
||||
const subagentRefs = extractSubagentRefsFromSteps(rawSteps);
|
||||
const ownSwarmManifest = !conv.isSubagent ? readSwarmManifestForCascade(cidLower) : null;
|
||||
if (ownSwarmManifest?.workerRefs?.length) {
|
||||
const seenRefCids = new Set(subagentRefs.map((r) => r.cascadeId));
|
||||
for (const wRef of ownSwarmManifest.workerRefs) {
|
||||
if (!seenRefCids.has(wRef.cascadeId)) {
|
||||
seenRefCids.add(wRef.cascadeId);
|
||||
subagentRefs.push(wRef);
|
||||
}
|
||||
}
|
||||
if (!nonShortTitle(conv.title) && ownSwarmManifest.title) {
|
||||
conv.title = ownSwarmManifest.title;
|
||||
}
|
||||
}
|
||||
conv.subagentRefs = subagentRefs;
|
||||
|
||||
const lastStepMs = nextLast?.createdAtMs || 0;
|
||||
@@ -1718,16 +1888,24 @@ export async function enumerateAndSyncConversations({
|
||||
conv.stepCount = steps.length;
|
||||
const finalSig = buildConvSig(conv);
|
||||
|
||||
const effectiveIsRunning = isRunning && !isParkedOnSwarmWait(rawSteps);
|
||||
if (!effectiveIsRunning && conv.status === 'CASCADE_RUN_STATUS_RUNNING') {
|
||||
conv.status = 'IDLE';
|
||||
}
|
||||
|
||||
const liveAct = resolveBestLiveActivity(
|
||||
conv.cascadeId,
|
||||
rawSteps,
|
||||
isRunning,
|
||||
effectiveIsRunning,
|
||||
resolvedLastModMs || conv.createdTimeMs || 0
|
||||
);
|
||||
if (liveAct) {
|
||||
if (liveAct && liveAct.actionKey !== 'swarm_wait') {
|
||||
conv.liveActivity = liveAct;
|
||||
liveActivityMemo.set(cidLower, liveAct);
|
||||
} else {
|
||||
if (liveAct?.actionKey === 'swarm_wait') {
|
||||
conv.status = 'IDLE';
|
||||
}
|
||||
conv.liveActivity = null;
|
||||
liveActivityMemo.delete(cidLower);
|
||||
}
|
||||
@@ -1747,10 +1925,11 @@ export async function enumerateAndSyncConversations({
|
||||
diskMtimeMs:
|
||||
conv.diskMtimeMs ?? readConversationMtime(diskConvMap.get(cidLower)),
|
||||
rawStepCount: conv.rawStepCount ?? stepsWithOwners.length,
|
||||
wasRunning: isRunning,
|
||||
wasRunning: conv.status === 'CASCADE_RUN_STATUS_RUNNING',
|
||||
contextLimitTelemetry: true,
|
||||
speedClearedTelemetry: true,
|
||||
turnRailTelemetry: true,
|
||||
wakeupTurnTelemetry: true,
|
||||
contextGroupsTelemetry: 2,
|
||||
steps: stepsWithOwners,
|
||||
subagentRefs,
|
||||
@@ -1963,6 +2142,12 @@ export async function enumerateAndSyncConversations({
|
||||
return false;
|
||||
}
|
||||
|
||||
function needsWakeupTurnRefresh(conv, cached) {
|
||||
if (!conv?.isSubagent || conv.isSideQuestion || cached?.wakeupTurnTelemetry) return false;
|
||||
const steps = cached?.steps || [];
|
||||
return steps.length > 0 && steps.every((s) => !s?.turnIndex);
|
||||
}
|
||||
|
||||
let remainingTimingRefreshes = LEGACY_MIGRATION_BATCH_SIZE;
|
||||
const toFetch = rawConversations.filter((conv) => {
|
||||
const sig = buildConvSig(conv);
|
||||
@@ -1979,6 +2164,7 @@ export async function enumerateAndSyncConversations({
|
||||
if (
|
||||
(!cached.turnRailTelemetry ||
|
||||
hasMissingTurnRailFields(cached) ||
|
||||
needsWakeupTurnRefresh(conv, cached) ||
|
||||
hasDroppedContextGroups(cached)) &&
|
||||
isSelectedFamily
|
||||
) {
|
||||
@@ -2056,7 +2242,22 @@ export async function enumerateAndSyncConversations({
|
||||
|
||||
for (const parentConv of [...rawConversations]) {
|
||||
const parentCached = getCachedTrajectory(parentConv.cascadeId);
|
||||
const refs = parentConv.subagentRefs || parentCached?.subagentRefs || [];
|
||||
const baseRefs = parentConv.subagentRefs || parentCached?.subagentRefs || [];
|
||||
const swarmManifest = !parentConv.isSubagent
|
||||
? readSwarmManifestForCascade(parentConv.cascadeId)
|
||||
: null;
|
||||
let refs = baseRefs;
|
||||
if (swarmManifest?.workerRefs?.length) {
|
||||
const merged = Array.isArray(baseRefs) ? baseRefs.slice() : [];
|
||||
const seenRefCids = new Set(merged.map((r) => String(r?.cascadeId || '').toLowerCase()));
|
||||
for (const wRef of swarmManifest.workerRefs) {
|
||||
if (!seenRefCids.has(wRef.cascadeId)) {
|
||||
seenRefCids.add(wRef.cascadeId);
|
||||
merged.push(wRef);
|
||||
}
|
||||
}
|
||||
refs = merged;
|
||||
}
|
||||
if (!Array.isArray(refs) || refs.length === 0) continue;
|
||||
|
||||
const parentId = parentConv.cascadeId.toLowerCase();
|
||||
@@ -2145,6 +2346,7 @@ export async function enumerateAndSyncConversations({
|
||||
(!isSelectedSubFamily ||
|
||||
(Boolean(existingSubCache.turnRailTelemetry) &&
|
||||
!hasMissingTurnRailFields(existingSubCache) &&
|
||||
!needsWakeupTurnRefresh(subConv, existingSubCache) &&
|
||||
!hasDroppedContextGroups(existingSubCache)));
|
||||
|
||||
if (hasValidSubCache) {
|
||||
@@ -2253,16 +2455,33 @@ export async function enumerateAndSyncConversations({
|
||||
persistTrajectoryCacheIfNeeded({ hasRunningSessions });
|
||||
}
|
||||
|
||||
// 确保所有处于 RUNNING 状态的会话(含本轮未触发 RPC 拉取的会话)都同步了最新的实时动作摘要
|
||||
// 确保所有处于 RUNNING 状态的会话(含本轮未触发 RPC 拉取的会话)都同步了最新的实时动作摘要,并剔除已进入 swarm_wait 待命的假运行态
|
||||
for (const conv of rawConversations) {
|
||||
if (conv.status === 'CASCADE_RUN_STATUS_RUNNING') {
|
||||
if (!conv.liveActivity) {
|
||||
const tailSteps = readTranscriptTailSteps(conv.cascadeId);
|
||||
if (isParkedOnSwarmWait(tailSteps)) {
|
||||
conv.status = 'IDLE';
|
||||
conv.liveActivity = null;
|
||||
liveActivityMemo.delete(conv.cascadeId.toLowerCase());
|
||||
continue;
|
||||
}
|
||||
const fallbackMs = conv.lastModifiedMs || conv.createdTimeMs || 0;
|
||||
const resolved = resolveBestLiveActivity(conv.cascadeId, [], true, fallbackMs);
|
||||
if (resolved?.actionKey === 'swarm_wait') {
|
||||
conv.status = 'IDLE';
|
||||
conv.liveActivity = null;
|
||||
liveActivityMemo.delete(conv.cascadeId.toLowerCase());
|
||||
continue;
|
||||
}
|
||||
conv.liveActivity = resolved;
|
||||
if (resolved) {
|
||||
liveActivityMemo.set(conv.cascadeId.toLowerCase(), resolved);
|
||||
}
|
||||
} else if (conv.liveActivity.actionKey === 'swarm_wait') {
|
||||
conv.status = 'IDLE';
|
||||
conv.liveActivity = null;
|
||||
liveActivityMemo.delete(conv.cascadeId.toLowerCase());
|
||||
}
|
||||
} else {
|
||||
conv.liveActivity = null;
|
||||
@@ -2308,7 +2527,64 @@ export async function enumerateAndSyncConversations({
|
||||
|
||||
for (const rootConv of conversations) {
|
||||
const cid = rootConv.cascadeId.toLowerCase();
|
||||
const swarmManifest = readSwarmManifestForCascade(cid);
|
||||
const swarmTitle = String(swarmManifest?.title || '').trim();
|
||||
if (swarmTitle) {
|
||||
rootConv.swarmTitle = swarmTitle;
|
||||
const curTitle = String(rootConv.title || '').trim();
|
||||
if (!curTitle || curTitle.toLowerCase() === cid.slice(0, 8)) {
|
||||
rootConv.title = swarmTitle;
|
||||
}
|
||||
}
|
||||
if (swarmManifest?.coordinator?.killed || rootConv.killed) {
|
||||
rootConv.status = 'IDLE';
|
||||
rootConv.liveActivity = null;
|
||||
}
|
||||
|
||||
const subs = subagentsByRoot.get(cid) || [];
|
||||
let swarmCount = 0;
|
||||
for (const s of subs) {
|
||||
const subLower = s.cascadeId.toLowerCase();
|
||||
const mEntry = swarmManifest?.membersByCid.get(subLower) || null;
|
||||
const subCached = getCachedTrajectory(s.cascadeId);
|
||||
const parsedSwarm = !s.isSideQuestion
|
||||
? parseSwarmWorkerRole({
|
||||
role: s.subagentSpec?.role || subCached?.subagentSpec?.role || '',
|
||||
typeName: s.subagentSpec?.typeName || subCached?.subagentSpec?.typeName || '',
|
||||
agentScriptName: s.agentScriptName || subCached?.agentScriptName || '',
|
||||
memberName: mEntry?.memberName || '',
|
||||
})
|
||||
: { isSwarmWorker: false };
|
||||
if (parsedSwarm.isSwarmWorker) {
|
||||
swarmCount += 1;
|
||||
s.isSwarmWorker = true;
|
||||
s.swarmMemberName = parsedSwarm.memberName;
|
||||
s.isSwarmAuxiliary = Boolean(parsedSwarm.isAuxiliary);
|
||||
s.killed = Boolean(s.killed || mEntry?.killed);
|
||||
if (s.killed) {
|
||||
s.status = 'IDLE';
|
||||
s.liveActivity = null;
|
||||
liveActivityMemo.delete(subLower);
|
||||
s.swarmState = 'killed';
|
||||
} else if (s.status === 'CASCADE_RUN_STATUS_RUNNING') {
|
||||
const parkedInManifest =
|
||||
Boolean(mEntry) &&
|
||||
(mEntry.wakeMode === 'mentions' || mEntry.wakeMode === 'anything') &&
|
||||
(!s.liveActivity || s.liveActivity.signature === 'init:0');
|
||||
if (s.liveActivity?.actionKey === 'swarm_wait' || parkedInManifest) {
|
||||
s.status = 'IDLE';
|
||||
s.liveActivity = null;
|
||||
liveActivityMemo.delete(subLower);
|
||||
s.swarmState = 'waiting';
|
||||
} else {
|
||||
s.swarmState = 'working';
|
||||
}
|
||||
} else {
|
||||
s.swarmState = 'waiting';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subs.sort((a, b) => {
|
||||
const aSide = Boolean(a.isSideQuestion);
|
||||
const bSide = Boolean(b.isSideQuestion);
|
||||
@@ -2338,6 +2614,7 @@ export async function enumerateAndSyncConversations({
|
||||
});
|
||||
rootConv.subagents = subs;
|
||||
rootConv.subagentCount = subs.length;
|
||||
rootConv.swarmCount = swarmCount;
|
||||
rootConv.totalStepCount =
|
||||
Number(rootConv.stepCount || 0) +
|
||||
subs.reduce((sum, s) => sum + Number(s.stepCount || 0), 0);
|
||||
|
||||
@@ -14,6 +14,7 @@ import { scaleBucketsExact } from '../shared/telemetry-display-rules.mjs';
|
||||
import {
|
||||
extractLiveActivity,
|
||||
parseIsoMs,
|
||||
parseSwarmWorkerRole,
|
||||
speedMetric,
|
||||
summarizeSpeed,
|
||||
summarizeTtft,
|
||||
@@ -573,6 +574,8 @@ export function buildAgentUnitTelemetry({
|
||||
agentKind = isMain ? 'main' : isSideQuestion ? 'side_question' : 'subagent',
|
||||
agentOrdinal = isMain ? 0 : isSideQuestion ? sideIndex : 0,
|
||||
customRole = '',
|
||||
swarmState = '',
|
||||
isSwarmAuxiliary = false,
|
||||
index,
|
||||
shortLabel,
|
||||
badgeText,
|
||||
@@ -628,6 +631,8 @@ export function buildAgentUnitTelemetry({
|
||||
agentKind,
|
||||
agentOrdinal,
|
||||
customRole,
|
||||
...(swarmState ? { swarmState } : {}),
|
||||
...(isSwarmAuxiliary ? { isSwarmAuxiliary: true } : {}),
|
||||
...(isSideQuestion ? { isSideQuestion: true, sideIndex } : {}),
|
||||
index,
|
||||
shortLabel,
|
||||
@@ -829,6 +834,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
let totalFamilyOutputTokens = sessionOutputTokens;
|
||||
|
||||
let normalSubCount = 0;
|
||||
let swarmWorkerCount = 0;
|
||||
let sideQuestionCount = 0;
|
||||
for (let idx = 0; idx < subagentSummaries.length; idx++) {
|
||||
const subSum = subagentSummaries[idx];
|
||||
@@ -844,11 +850,22 @@ export async function buildTelemetryPayloadInternal(
|
||||
);
|
||||
const rawRole =
|
||||
subSpec?.role || subSum.agentScriptName || subEntry?.agentScriptName || subSpec?.typeName || '';
|
||||
const parsedSwarm = !isSideQ
|
||||
? parseSwarmWorkerRole({
|
||||
role: subSpec?.role || '',
|
||||
typeName: subSpec?.typeName || '',
|
||||
agentScriptName: subSum.agentScriptName || subEntry?.agentScriptName || '',
|
||||
memberName: subSum.swarmMemberName || '',
|
||||
})
|
||||
: { isSwarmWorker: false };
|
||||
const isSwarmW = Boolean(!isSideQ && (subSum.isSwarmWorker || parsedSwarm.isSwarmWorker));
|
||||
const subIndex = idx + 1;
|
||||
let sideIndex = 0;
|
||||
let agentKind = 'subagent';
|
||||
let agentOrdinal = 0;
|
||||
let customRole = '';
|
||||
let swarmState = '';
|
||||
let isSwarmAuxiliary = false;
|
||||
let shortLabel = '';
|
||||
let badgeText = '';
|
||||
let roleLabel = '';
|
||||
@@ -871,6 +888,23 @@ export async function buildTelemetryPayloadInternal(
|
||||
roleLabel = cleanSideRole || '旁路提问';
|
||||
typeName = 'side_question';
|
||||
agentLabel = cleanSideRole ? `${shortLabel} · ${cleanSideRole}` : shortLabel;
|
||||
} else if (isSwarmW) {
|
||||
const swOrd = ++swarmWorkerCount;
|
||||
agentKind = 'swarm_worker';
|
||||
agentOrdinal = swOrd;
|
||||
const memberTag = parsedSwarm.memberName ? `@${parsedSwarm.memberName}` : '';
|
||||
customRole = memberTag;
|
||||
shortLabel = `蜂群 #${swOrd}`;
|
||||
badgeText = `蜂${swOrd}`;
|
||||
roleLabel = memberTag || '蜂群';
|
||||
typeName = 'worker';
|
||||
agentLabel = memberTag ? `${shortLabel} · ${memberTag}` : shortLabel;
|
||||
swarmState = subSum.killed
|
||||
? 'killed'
|
||||
: subSum.status === 'CASCADE_RUN_STATUS_RUNNING'
|
||||
? 'working'
|
||||
: subSum.swarmState || 'waiting';
|
||||
isSwarmAuxiliary = Boolean(subSum.isSwarmAuxiliary || parsedSwarm.isAuxiliary);
|
||||
} else {
|
||||
const subOrd = ++normalSubCount;
|
||||
agentKind = 'subagent';
|
||||
@@ -892,6 +926,8 @@ export async function buildTelemetryPayloadInternal(
|
||||
agentKind,
|
||||
agentOrdinal,
|
||||
customRole,
|
||||
swarmState,
|
||||
isSwarmAuxiliary,
|
||||
index: subIndex,
|
||||
shortLabel,
|
||||
badgeText,
|
||||
@@ -1026,12 +1062,18 @@ export async function buildTelemetryPayloadInternal(
|
||||
.sort((a, b) => (b.lastModifiedMs || 0) - (a.lastModifiedMs || 0))[0] ||
|
||||
mainAgentTelemetry;
|
||||
|
||||
const roleSummaryParts = [];
|
||||
if (swarmWorkerCount > 0) roleSummaryParts.push(`${swarmWorkerCount} 蜂群`);
|
||||
if (normalSubCount > 0) roleSummaryParts.push(`${normalSubCount} 子代理`);
|
||||
if (sideQuestionCount > 0) {
|
||||
roleSummaryParts.push(
|
||||
roleSummaryParts.length > 0 ? `${sideQuestionCount} 旁问` : `${sideQuestionCount} 旁路提问`
|
||||
);
|
||||
}
|
||||
const aggregatedRoleLabel =
|
||||
normalSubCount > 0 && sideQuestionCount > 0
|
||||
? `主代理 + ${normalSubCount} 子代理 + ${sideQuestionCount} 旁问`
|
||||
: sideQuestionCount > 0
|
||||
? `主代理 + ${sideQuestionCount} 旁路提问`
|
||||
: `主代理 + ${subAgentTelemetries.length} 子代理`;
|
||||
roleSummaryParts.length > 0
|
||||
? `主代理 + ${roleSummaryParts.join(' + ')}`
|
||||
: `主代理 + ${subAgentTelemetries.length} 子代理`;
|
||||
|
||||
const totalCostUsd = roundSessionCost(totalRawSessionCostUsd);
|
||||
const totalUnpricedCalls = allAgents.reduce(
|
||||
@@ -1412,6 +1454,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
rootConv.lastModifiedMs || rootEntry?.lastModifiedMs || rootConv.createdTimeMs || 0;
|
||||
|
||||
let runNormalSubIdx = 0;
|
||||
let runSwarmIdx = 0;
|
||||
let runSideIdx = 0;
|
||||
const subItems = rawSubs.map((subSum, idx) => {
|
||||
const subCid = subSum.cascadeId;
|
||||
@@ -1426,11 +1469,22 @@ export async function buildTelemetryPayloadInternal(
|
||||
subEntry?.agentScriptName ||
|
||||
subSpec?.typeName ||
|
||||
'';
|
||||
const parsedSwarm = !isSideQ
|
||||
? parseSwarmWorkerRole({
|
||||
role: subSpec?.role || '',
|
||||
typeName: subSpec?.typeName || '',
|
||||
agentScriptName: subSum.agentScriptName || subEntry?.agentScriptName || '',
|
||||
memberName: subSum.swarmMemberName || '',
|
||||
})
|
||||
: { isSwarmWorker: false };
|
||||
const isSwarmW = Boolean(!isSideQ && (subSum.isSwarmWorker || parsedSwarm.isSwarmWorker));
|
||||
const subIndex = idx + 1;
|
||||
let sideIndex = 0;
|
||||
let agentKind = 'subagent';
|
||||
let agentOrdinal = 0;
|
||||
let customRole = '';
|
||||
let swarmState = '';
|
||||
let isSwarmAuxiliary = false;
|
||||
let badgeText = '';
|
||||
let shortLabel = '';
|
||||
let role = '';
|
||||
@@ -1449,6 +1503,16 @@ export async function buildTelemetryPayloadInternal(
|
||||
: '';
|
||||
customRole = cleanSide;
|
||||
role = cleanSide || shortLabel;
|
||||
} else if (isSwarmW) {
|
||||
const swOrd = ++runSwarmIdx;
|
||||
agentKind = 'swarm_worker';
|
||||
agentOrdinal = swOrd;
|
||||
const memberTag = parsedSwarm.memberName ? `@${parsedSwarm.memberName}` : '';
|
||||
customRole = memberTag;
|
||||
badgeText = `蜂${swOrd}`;
|
||||
shortLabel = `蜂群 #${swOrd}`;
|
||||
role = memberTag || shortLabel;
|
||||
isSwarmAuxiliary = Boolean(subSum.isSwarmAuxiliary || parsedSwarm.isAuxiliary);
|
||||
} else {
|
||||
const nOrd = ++runNormalSubIdx;
|
||||
agentKind = 'subagent';
|
||||
@@ -1459,32 +1523,62 @@ export async function buildTelemetryPayloadInternal(
|
||||
role = rawRole || shortLabel;
|
||||
}
|
||||
const isSubRunning = subSum.status === 'CASCADE_RUN_STATUS_RUNNING';
|
||||
const isKilled = Boolean(subSum.killed || subSum.swarmState === 'killed');
|
||||
if (isSwarmW) {
|
||||
swarmState = isKilled ? 'killed' : isSubRunning ? 'working' : subSum.swarmState || 'waiting';
|
||||
}
|
||||
const stepCount = Number(subSum.stepCount ?? subEntry?.steps?.length ?? 0);
|
||||
const subModMs = subSum.lastModifiedMs || subEntry?.lastModifiedMs || 0;
|
||||
const liveActivity = isSubRunning
|
||||
? subSum.liveActivity || extractLiveActivity([], true, subModMs)
|
||||
: {
|
||||
phase: 'done',
|
||||
actionKey: 'done',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '已完成',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: subModMs,
|
||||
signature: `done:${stepCount}`,
|
||||
};
|
||||
: isSwarmW
|
||||
? isKilled
|
||||
? {
|
||||
phase: 'done',
|
||||
actionKey: 'swarm_killed',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '已终止',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: subModMs,
|
||||
signature: `killed:${stepCount}`,
|
||||
}
|
||||
: {
|
||||
phase: 'waiting',
|
||||
actionKey: 'swarm_waiting',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '待命中',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: subModMs,
|
||||
signature: `waiting:${stepCount}`,
|
||||
}
|
||||
: {
|
||||
phase: 'done',
|
||||
actionKey: 'done',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '已完成',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: subModMs,
|
||||
signature: `done:${stepCount}`,
|
||||
};
|
||||
return {
|
||||
cascadeId: subCid,
|
||||
index: subIndex,
|
||||
agentKind,
|
||||
agentOrdinal,
|
||||
customRole,
|
||||
...(swarmState ? { swarmState } : {}),
|
||||
...(isSwarmAuxiliary ? { isSwarmAuxiliary: true } : {}),
|
||||
...(isSideQ ? { isSideQuestion: true, sideIndex } : {}),
|
||||
badgeText,
|
||||
shortLabel,
|
||||
role,
|
||||
typeName: isSideQ ? 'side_question' : subSpec?.typeName || '',
|
||||
typeName: isSideQ ? 'side_question' : isSwarmW ? 'worker' : subSpec?.typeName || '',
|
||||
isRunning: isSubRunning,
|
||||
status: subSum.status || 'IDLE',
|
||||
stepCount,
|
||||
@@ -1498,52 +1592,86 @@ export async function buildTelemetryPayloadInternal(
|
||||
: null;
|
||||
|
||||
const runningSubCount = subItems.filter((s) => s.isRunning).length;
|
||||
if (
|
||||
isMainRunning &&
|
||||
(mainLiveAct?.toolName === 'invoke_subagent' || mainLiveAct?.actionKey === 'invoke_subagent') &&
|
||||
runningSubCount === 0
|
||||
) {
|
||||
const isPendingSubSpawn =
|
||||
mainLiveAct?.toolName === 'invoke_subagent' || mainLiveAct?.actionKey === 'invoke_subagent';
|
||||
const isPendingSwarmSpawn = mainLiveAct?.actionKey === 'swarm_add';
|
||||
if (isMainRunning && (isPendingSubSpawn || isPendingSwarmSpawn) && runningSubCount === 0) {
|
||||
const pendingIndex = subItems.length + 1;
|
||||
const pendingCustomRole = mainLiveAct.detail || '';
|
||||
const pendingRole = pendingCustomRole || '子代理';
|
||||
subItems.push({
|
||||
cascadeId: `${rootConv.cascadeId}:pending-sub-${pendingIndex}`,
|
||||
index: pendingIndex,
|
||||
agentKind: 'subagent',
|
||||
agentOrdinal: pendingIndex,
|
||||
customRole: pendingCustomRole,
|
||||
badgeText: `子${pendingIndex}`,
|
||||
shortLabel: `子代理 #${pendingIndex}`,
|
||||
role: pendingRole,
|
||||
typeName: '',
|
||||
isRunning: true,
|
||||
status: 'CASCADE_RUN_STATUS_RUNNING',
|
||||
stepCount: 0,
|
||||
lastModifiedMs: rootFallbackMs,
|
||||
liveActivity: {
|
||||
phase: 'thinking',
|
||||
actionKey: 'starting',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '启动中',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: mainLiveAct.startedAtMs || 0,
|
||||
signature: `spawning-sub:${pendingIndex}:${pendingRole}`,
|
||||
},
|
||||
});
|
||||
if (isPendingSwarmSpawn) {
|
||||
const pendingSwarmOrd = ++runSwarmIdx;
|
||||
const pendingRole = pendingCustomRole || `蜂群 #${pendingSwarmOrd}`;
|
||||
subItems.push({
|
||||
cascadeId: `${rootConv.cascadeId}:pending-swarm-${pendingIndex}`,
|
||||
index: pendingIndex,
|
||||
agentKind: 'swarm_worker',
|
||||
agentOrdinal: pendingSwarmOrd,
|
||||
customRole: pendingCustomRole,
|
||||
swarmState: 'working',
|
||||
badgeText: `蜂${pendingSwarmOrd}`,
|
||||
shortLabel: `蜂群 #${pendingSwarmOrd}`,
|
||||
role: pendingRole,
|
||||
typeName: 'worker',
|
||||
isRunning: true,
|
||||
status: 'CASCADE_RUN_STATUS_RUNNING',
|
||||
stepCount: 0,
|
||||
lastModifiedMs: rootFallbackMs,
|
||||
liveActivity: {
|
||||
phase: 'thinking',
|
||||
actionKey: 'starting',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '启动中',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: mainLiveAct.startedAtMs || 0,
|
||||
signature: `spawning-swarm:${pendingSwarmOrd}:${pendingRole}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const pendingNormOrd = ++runNormalSubIdx;
|
||||
const pendingRole = pendingCustomRole || '子代理';
|
||||
subItems.push({
|
||||
cascadeId: `${rootConv.cascadeId}:pending-sub-${pendingIndex}`,
|
||||
index: pendingIndex,
|
||||
agentKind: 'subagent',
|
||||
agentOrdinal: pendingNormOrd,
|
||||
customRole: pendingCustomRole,
|
||||
badgeText: `子${pendingNormOrd}`,
|
||||
shortLabel: `子代理 #${pendingNormOrd}`,
|
||||
role: pendingRole,
|
||||
typeName: '',
|
||||
isRunning: true,
|
||||
status: 'CASCADE_RUN_STATUS_RUNNING',
|
||||
stepCount: 0,
|
||||
lastModifiedMs: rootFallbackMs,
|
||||
liveActivity: {
|
||||
phase: 'thinking',
|
||||
actionKey: 'starting',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '启动中',
|
||||
detail: '',
|
||||
stepProgress: '',
|
||||
startedAtMs: mainLiveAct.startedAtMs || 0,
|
||||
signature: `spawning-sub:${pendingIndex}:${pendingRole}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const runningSubList = subItems.filter((s) => s.isRunning);
|
||||
const allRunningAreSwarm =
|
||||
runningSubList.length > 0 && runningSubList.every((s) => s.agentKind === 'swarm_worker');
|
||||
const resolvedMainActivity =
|
||||
mainLiveAct ||
|
||||
(runningSubList.length > 0
|
||||
? {
|
||||
phase: 'waiting',
|
||||
actionKey: 'waiting_subagent',
|
||||
actionKey: allRunningAreSwarm ? 'waiting_swarm' : 'waiting_subagent',
|
||||
waitingApproval: false,
|
||||
detailKey: '',
|
||||
label: '等待子代理',
|
||||
label: allRunningAreSwarm ? '等待工蜂' : '等待子代理',
|
||||
detail: runningSubList.map((s) => s.customRole || s.role).join(', '),
|
||||
stepProgress: '',
|
||||
startedAtMs: runningSubList[0]?.liveActivity?.startedAtMs || rootFallbackMs,
|
||||
@@ -1555,6 +1683,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
runningConversations.push({
|
||||
cascadeId: rootConv.cascadeId,
|
||||
title: rootConv.title || rootConv.cascadeId.slice(0, 8),
|
||||
...(rootConv.swarmTitle ? { swarmTitle: rootConv.swarmTitle } : {}),
|
||||
isCurrentSelected:
|
||||
Boolean(activeCascadeId) &&
|
||||
rootConv.cascadeId.toLowerCase() === String(activeCascadeId).toLowerCase(),
|
||||
@@ -1566,7 +1695,11 @@ export async function buildTelemetryPayloadInternal(
|
||||
lastModifiedMs: rootConv.groupLastModifiedMs || rootConv.lastModifiedMs || 0,
|
||||
mainActivity: resolvedMainActivity,
|
||||
subagentCount: subItems.length,
|
||||
swarmCount: runSwarmIdx,
|
||||
normalSubagentCount: runNormalSubIdx,
|
||||
sideQuestionCount: runSideIdx,
|
||||
runningSubagentCount: runningSubList.length,
|
||||
runningSwarmCount: runningSubList.filter((s) => s.agentKind === 'swarm_worker').length,
|
||||
subagents: subItems,
|
||||
modelShort: qStats.modelShort,
|
||||
modelUpstream: qStats.modelUpstream,
|
||||
@@ -1606,13 +1739,21 @@ export async function buildTelemetryPayloadInternal(
|
||||
const qStats = getConversationQuickStats(c);
|
||||
const rawSubs = Array.isArray(c.subagents) ? c.subagents : [];
|
||||
const runningSubCount = rawSubs.filter((s) => s.status === 'CASCADE_RUN_STATUS_RUNNING').length;
|
||||
const cSwarmCount = Number(c.swarmCount ?? rawSubs.filter((s) => s.isSwarmWorker).length);
|
||||
const cSideCount = rawSubs.filter((s) => s.isSideQuestion).length;
|
||||
const cNormalSubCount = Math.max(0, rawSubs.length - cSwarmCount - cSideCount);
|
||||
return {
|
||||
cascadeId: c.cascadeId,
|
||||
title: c.title,
|
||||
...(c.swarmTitle ? { swarmTitle: c.swarmTitle } : {}),
|
||||
stepCount: c.stepCount,
|
||||
subagentCount: c.subagentCount || 0,
|
||||
swarmCount: cSwarmCount,
|
||||
normalSubagentCount: cNormalSubCount,
|
||||
sideQuestionCount: cSideCount,
|
||||
runningSubagentCount: runningSubCount,
|
||||
totalStepCount: c.totalStepCount || c.stepCount || 0,
|
||||
...(rawSubs.length > 0 ? { memberCascadeIds: rawSubs.map((s) => s.cascadeId) } : {}),
|
||||
isRunning: c.status === 'CASCADE_RUN_STATUS_RUNNING' || runningSubCount > 0,
|
||||
status: c.status,
|
||||
lastModifiedTime: c.lastModifiedTime,
|
||||
@@ -1628,12 +1769,16 @@ export async function buildTelemetryPayloadInternal(
|
||||
activeConversation: {
|
||||
cascadeId: activeCascadeId,
|
||||
title: activeConvSummary?.title || '当前会话',
|
||||
...(activeConvSummary?.swarmTitle ? { swarmTitle: activeConvSummary.swarmTitle } : {}),
|
||||
isRunning: activeConvSummary?.status === 'CASCADE_RUN_STATUS_RUNNING',
|
||||
status: activeConvSummary?.status || 'IDLE',
|
||||
liveActivity: mainAgentTelemetry.liveActivity || null,
|
||||
stepCount: enrichedActiveSteps.length,
|
||||
hasSubagents: subAgentTelemetries.length > 0,
|
||||
subagentCount: subAgentTelemetries.length,
|
||||
swarmCount: swarmWorkerCount,
|
||||
normalSubagentCount: normalSubCount,
|
||||
sideQuestionCount,
|
||||
totalStepsAllAgents: subAgentTelemetries.length
|
||||
? allCombinedEnrichedSteps.length
|
||||
: enrichedActiveSteps.length,
|
||||
|
||||
Reference in New Issue
Block a user