Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/core/src/agents/a2aUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,52 @@ describe('a2aUtils', () => {
expect(output).toContain('Artifact (Data):');
expect(output).not.toContain('Answer from history');
});

it('should return message log as activity items', () => {
const reassembler = new A2AResultReassembler();

reassembler.update({
kind: 'status-update',
taskId: 't1',
contextId: 'ctx1',
status: {
state: 'working',
message: {
kind: 'message',
role: 'agent',
parts: [{ kind: 'text', text: 'Message 1' }],
} as Message,
},
} as unknown as SendMessageResult);

reassembler.update({
kind: 'status-update',
taskId: 't1',
contextId: 'ctx1',
status: {
state: 'working',
message: {
kind: 'message',
role: 'agent',
parts: [{ kind: 'text', text: 'Message 2' }],
} as Message,
},
} as unknown as SendMessageResult);

const items = reassembler.toActivityItems();
expect(items).toHaveLength(2);
expect(items[0]).toEqual({
id: 'msg-0',
type: 'thought',
content: 'Message 1',
status: 'completed',
});
expect(items[1]).toEqual({
id: 'msg-1',
type: 'thought',
content: 'Message 2',
status: 'completed',
});
});
});
});
46 changes: 31 additions & 15 deletions packages/core/src/agents/a2aUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class A2AResultReassembler {

private pushMessage(message: Message | undefined) {
if (!message) return;
if (message.role === 'user') return; // Skip user messages reflected by server
const text = extractPartsText(message.parts, '');
if (text && this.messageLog[this.messageLog.length - 1] !== text) {
this.messageLog.push(text);
Expand All @@ -135,21 +136,36 @@ export class A2AResultReassembler {
*/
toActivityItems(): SubagentActivityItem[] {
const isAuthRequired = this.messageLog.includes(AUTH_REQUIRED_MSG);
return [
isAuthRequired
? {
id: 'auth-required',
type: 'thought',
content: AUTH_REQUIRED_MSG,
status: 'running',
}
: {
id: 'pending',
type: 'thought',
content: 'Working...',
status: 'running',
},
];
const items: SubagentActivityItem[] = [];

if (isAuthRequired) {
items.push({
id: 'auth-required',
type: 'thought',
content: AUTH_REQUIRED_MSG,
status: 'running',
});
}

this.messageLog.forEach((msg, index) => {
items.push({
id: `msg-${index}`,
type: 'thought',
content: msg.trim(),
status: 'completed',
});
});

if (items.length === 0 && !isAuthRequired) {
items.push({
id: 'pending',
type: 'thought',
content: 'Working...',
status: 'running',
});
}

return items;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/config/config-agents-reload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ Test System Prompt`;
});

// Trigger the refresh action that follows reloading
// @ts-expect-error accessing private method for testing
await config.onAgentsRefreshed();

await config.getAgentRegistry().reload();

// 4. Verify the agent is UNREGISTERED
const finalAgents = agentRegistry.getAllDefinitions().map((d) => d.name);
Expand Down Expand Up @@ -237,8 +237,8 @@ Test System Prompt`;
});

// Trigger the refresh action that follows reloading
// @ts-expect-error accessing private method for testing
await config.onAgentsRefreshed();

await config.getAgentRegistry().reload();

expect(agentRegistry.getAllDefinitions().map((d) => d.name)).toContain(
agentName,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3804,8 +3804,6 @@ export class Config implements McpContext, AgentLoopContext {
}

private onAgentsRefreshed = async () => {
await this.agentRegistry.initialize();

// Propagate updates to the active chat session
const client = this.geminiClient;
if (client?.isInitialized()) {
Expand Down
Loading