mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
fix(core): remove duplicate initialize call on agents refreshed (#25670)
This commit is contained in:
@@ -538,5 +538,52 @@ describe('a2aUtils', () => {
|
|||||||
expect(output).toContain('Artifact (Data):');
|
expect(output).toContain('Artifact (Data):');
|
||||||
expect(output).not.toContain('Answer from history');
|
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',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ export class A2AResultReassembler {
|
|||||||
|
|
||||||
private pushMessage(message: Message | undefined) {
|
private pushMessage(message: Message | undefined) {
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
|
if (message.role === 'user') return; // Skip user messages reflected by server
|
||||||
const text = extractPartsText(message.parts, '');
|
const text = extractPartsText(message.parts, '');
|
||||||
if (text && this.messageLog[this.messageLog.length - 1] !== text) {
|
if (text && this.messageLog[this.messageLog.length - 1] !== text) {
|
||||||
this.messageLog.push(text);
|
this.messageLog.push(text);
|
||||||
@@ -135,21 +136,36 @@ export class A2AResultReassembler {
|
|||||||
*/
|
*/
|
||||||
toActivityItems(): SubagentActivityItem[] {
|
toActivityItems(): SubagentActivityItem[] {
|
||||||
const isAuthRequired = this.messageLog.includes(AUTH_REQUIRED_MSG);
|
const isAuthRequired = this.messageLog.includes(AUTH_REQUIRED_MSG);
|
||||||
return [
|
const items: SubagentActivityItem[] = [];
|
||||||
isAuthRequired
|
|
||||||
? {
|
if (isAuthRequired) {
|
||||||
|
items.push({
|
||||||
id: 'auth-required',
|
id: 'auth-required',
|
||||||
type: 'thought',
|
type: 'thought',
|
||||||
content: AUTH_REQUIRED_MSG,
|
content: AUTH_REQUIRED_MSG,
|
||||||
status: 'running',
|
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',
|
id: 'pending',
|
||||||
type: 'thought',
|
type: 'thought',
|
||||||
content: 'Working...',
|
content: 'Working...',
|
||||||
status: 'running',
|
status: 'running',
|
||||||
},
|
});
|
||||||
];
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ Test System Prompt`;
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Trigger the refresh action that follows reloading
|
// 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
|
// 4. Verify the agent is UNREGISTERED
|
||||||
const finalAgents = agentRegistry.getAllDefinitions().map((d) => d.name);
|
const finalAgents = agentRegistry.getAllDefinitions().map((d) => d.name);
|
||||||
@@ -237,8 +237,8 @@ Test System Prompt`;
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Trigger the refresh action that follows reloading
|
// 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(
|
expect(agentRegistry.getAllDefinitions().map((d) => d.name)).toContain(
|
||||||
agentName,
|
agentName,
|
||||||
|
|||||||
@@ -3829,8 +3829,6 @@ export class Config implements McpContext, AgentLoopContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onAgentsRefreshed = async () => {
|
private onAgentsRefreshed = async () => {
|
||||||
await this.agentRegistry.initialize();
|
|
||||||
|
|
||||||
// Propagate updates to the active chat session
|
// Propagate updates to the active chat session
|
||||||
const client = this.geminiClient;
|
const client = this.geminiClient;
|
||||||
if (client?.isInitialized()) {
|
if (client?.isInitialized()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user