refactor(core): update remaining files to use SubagentState enum

This commit is contained in:
Adam Weidman
2026-05-12 13:45:17 -04:00
parent 086337784a
commit 435c483b3a
2 changed files with 31 additions and 23 deletions
+4 -4
View File
@@ -16,7 +16,7 @@ import type {
AgentInterface,
} from '@a2a-js/sdk';
import type { SendMessageResult } from './a2a-client-manager.js';
import type { SubagentActivityItem } from './types.js';
import { type SubagentActivityItem, SubagentState } from './types.js';
export const AUTH_REQUIRED_MSG = `[Authorization Required] The agent has indicated it requires authorization to proceed. Please follow the agent's instructions.`;
@@ -143,7 +143,7 @@ export class A2AResultReassembler {
id: 'auth-required',
type: 'thought',
content: AUTH_REQUIRED_MSG,
status: 'running',
status: SubagentState.RUNNING,
});
}
@@ -152,7 +152,7 @@ export class A2AResultReassembler {
id: `msg-${index}`,
type: 'thought',
content: msg.trim(),
status: 'completed',
status: SubagentState.COMPLETED,
});
});
@@ -161,7 +161,7 @@ export class A2AResultReassembler {
id: 'pending',
type: 'thought',
content: 'Working...',
status: 'running',
status: SubagentState.RUNNING,
});
}
@@ -32,6 +32,7 @@ import {
type SubagentActivityItem,
AgentTerminateMode,
isToolActivityError,
SubagentState,
} from '../types.js';
import type { MessageBus } from '../../confirmation-bus/message-bus.js';
import { createBrowserAgentDefinition } from './browserAgentFactory.js';
@@ -123,7 +124,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
isSubagentProgress: true,
agentName: this.agentName,
recentActivity: [],
state: 'running',
state: SubagentState.RUNNING,
};
updateOutput(initialProgress);
}
@@ -137,7 +138,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
id: randomUUID(),
type: 'thought',
content: sanitizedMsg,
status: 'completed',
status: SubagentState.COMPLETED,
});
if (recentActivity.length > MAX_RECENT_ACTIVITY) {
recentActivity = recentActivity.slice(-MAX_RECENT_ACTIVITY);
@@ -146,7 +147,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
isSubagentProgress: true,
agentName: this.agentName,
recentActivity: [...recentActivity],
state: 'running',
state: SubagentState.RUNNING,
} as SubagentProgress);
}
: undefined;
@@ -175,7 +176,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
if (
lastItem &&
lastItem.type === 'thought' &&
lastItem.status === 'running'
lastItem.status === SubagentState.RUNNING
) {
lastItem.content = sanitizeThoughtContent(text);
} else {
@@ -183,7 +184,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
id: randomUUID(),
type: 'thought',
content: sanitizeThoughtContent(text),
status: 'running',
status: SubagentState.RUNNING,
});
}
updated = true;
@@ -210,7 +211,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
displayName,
description,
args,
status: 'running',
status: SubagentState.RUNNING,
});
updated = true;
break;
@@ -227,9 +228,11 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
recentActivity[i].type === 'tool_call' &&
callId != null &&
recentActivity[i].id === callId &&
recentActivity[i].status === 'running'
recentActivity[i].status === SubagentState.RUNNING
) {
recentActivity[i].status = isError ? 'error' : 'completed';
recentActivity[i].status = isError
? SubagentState.ERROR
: SubagentState.COMPLETED;
updated = true;
break;
}
@@ -242,7 +245,9 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
const callId = activity.data['callId']
? String(activity.data['callId'])
: undefined;
const newStatus = isCancellation ? 'cancelled' : 'error';
const newStatus = isCancellation
? SubagentState.CANCELLED
: SubagentState.ERROR;
if (callId) {
// Mark the specific tool as error/cancelled
@@ -250,7 +255,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
if (
recentActivity[i].type === 'tool_call' &&
recentActivity[i].id === callId &&
recentActivity[i].status === 'running'
recentActivity[i].status === SubagentState.RUNNING
) {
recentActivity[i].status = newStatus;
updated = true;
@@ -260,7 +265,10 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
} else {
// No specific tool — mark ALL running tool_call items
for (const item of recentActivity) {
if (item.type === 'tool_call' && item.status === 'running') {
if (
item.type === 'tool_call' &&
item.status === SubagentState.RUNNING
) {
item.status = newStatus;
updated = true;
}
@@ -293,7 +301,7 @@ export class BrowserAgentInvocation extends BaseToolInvocation<
isSubagentProgress: true,
agentName: this.agentName,
recentActivity: [...recentActivity],
state: 'running',
state: SubagentState.RUNNING,
};
updateOutput(progress);
}
@@ -330,13 +338,13 @@ ${output.result}`;
// GOAL = agent completed its task normally.
// ABORTED = user cancelled.
// Others (ERROR, MAX_TURNS, ERROR_NO_COMPLETE_TASK_CALL) = error.
let progressState: SubagentProgress['state'];
let progressState: SubagentState;
if (output.terminate_reason === AgentTerminateMode.ABORTED) {
progressState = 'cancelled';
progressState = SubagentState.CANCELLED;
} else if (output.terminate_reason === AgentTerminateMode.GOAL) {
progressState = 'completed';
progressState = SubagentState.COMPLETED;
} else {
progressState = 'error';
progressState = SubagentState.ERROR;
}
const progress: SubagentProgress = {
@@ -366,8 +374,8 @@ ${output.result}`;
// Mark any running items as error/cancelled
for (const item of recentActivity) {
if (item.status === 'running') {
item.status = isAbort ? 'cancelled' : 'error';
if (item.status === SubagentState.RUNNING) {
item.status = isAbort ? SubagentState.CANCELLED : SubagentState.ERROR;
}
}
@@ -375,7 +383,7 @@ ${output.result}`;
isSubagentProgress: true,
agentName: this.agentName,
recentActivity: [...recentActivity],
state: isAbort ? 'cancelled' : 'error',
state: isAbort ? SubagentState.CANCELLED : SubagentState.ERROR,
};
if (updateOutput) {