mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-28 23:11:19 -07:00
feat(core): improve A2A content extraction (#20487)
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
This commit is contained in:
@@ -74,6 +74,26 @@ export class A2AResultReassembler {
|
||||
]);
|
||||
}
|
||||
}
|
||||
// History Fallback: Some agent implementations do not populate the
|
||||
// status.message in their final terminal response, instead archiving
|
||||
// the final answer in the task's history array. To ensure we don't
|
||||
// present an empty result, we fallback to the most recent agent message
|
||||
// in the history only when the task is terminal and no other content
|
||||
// (message log or artifacts) has been reassembled.
|
||||
if (
|
||||
isTerminalState(chunk.status?.state) &&
|
||||
this.messageLog.length === 0 &&
|
||||
this.artifacts.size === 0 &&
|
||||
chunk.history &&
|
||||
chunk.history.length > 0
|
||||
) {
|
||||
const lastAgentMsg = [...chunk.history]
|
||||
.reverse()
|
||||
.find((m) => m.role?.toLowerCase().includes('agent'));
|
||||
if (lastAgentMsg) {
|
||||
this.pushMessage(lastAgentMsg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'message': {
|
||||
@@ -126,7 +146,7 @@ export class A2AResultReassembler {
|
||||
* Handles Text, Data (JSON), and File parts.
|
||||
*/
|
||||
export function extractMessageText(message: Message | undefined): string {
|
||||
if (!message) {
|
||||
if (!message || !message.parts || !Array.isArray(message.parts)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -158,7 +178,6 @@ function extractPartText(part: Part): string {
|
||||
}
|
||||
|
||||
if (isDataPart(part)) {
|
||||
// Attempt to format known data types if metadata exists, otherwise JSON stringify
|
||||
return `Data: ${JSON.stringify(part.data)}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user