mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 13:22:35 -07:00
refactor(core): agent session protocol changes (#26661)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
geminiPartsToContentParts,
|
||||
contentPartsToGeminiParts,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from './content-utils.js';
|
||||
import type { Part } from '@google/genai';
|
||||
import type { ContentPart } from './types.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
describe('geminiPartsToContentParts', () => {
|
||||
it('converts text parts', () => {
|
||||
@@ -191,11 +192,17 @@ describe('contentPartsToGeminiParts', () => {
|
||||
const content = [
|
||||
{ type: 'custom_widget', payload: 123 },
|
||||
] as unknown as ContentPart[];
|
||||
|
||||
const warnSpy = vi.spyOn(debugLogger, 'warn');
|
||||
const result = contentPartsToGeminiParts(content);
|
||||
|
||||
expect(warnSpy).toHaveBeenCalled();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toEqual({
|
||||
text: JSON.stringify({ type: 'custom_widget', payload: 123 }),
|
||||
});
|
||||
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import type { Part } from '@google/genai';
|
||||
import type { ContentPart } from './types.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
/**
|
||||
* Converts Gemini API Part objects to framework-agnostic ContentPart objects.
|
||||
@@ -93,6 +94,9 @@ export function contentPartsToGeminiParts(content: ContentPart[]): Part[] {
|
||||
result.push({ text: part.text });
|
||||
break;
|
||||
default:
|
||||
debugLogger.warn(
|
||||
`Unhandled ContentPart type: ${JSON.stringify(part)} fallback to serialization`,
|
||||
);
|
||||
// Serialize unknown ContentPart variants instead of dropping them
|
||||
result.push({ text: JSON.stringify(part) });
|
||||
break;
|
||||
|
||||
@@ -1330,6 +1330,7 @@ describe('LegacyAgentSession', () => {
|
||||
);
|
||||
expect(err?.message).toBe('Connection refused');
|
||||
expect(err?.fatal).toBe(true);
|
||||
expect(err?._meta?.['stack']).toBeDefined();
|
||||
|
||||
const streamEnd = events.find(
|
||||
(e): e is AgentEvent<'agent_end'> => e.type === 'agent_end',
|
||||
|
||||
@@ -166,6 +166,7 @@ export class LegacyAgentProtocol implements AgentProtocol {
|
||||
} else {
|
||||
this._emitErrorAndAgentEnd(err);
|
||||
}
|
||||
} finally {
|
||||
this._clearActiveStream();
|
||||
}
|
||||
}
|
||||
@@ -390,6 +391,7 @@ export class LegacyAgentProtocol implements AgentProtocol {
|
||||
const meta: Record<string, unknown> = {};
|
||||
if (err instanceof Error) {
|
||||
meta['errorName'] = err.constructor.name;
|
||||
meta['stack'] = err.stack;
|
||||
if ('exitCode' in err && typeof err.exitCode === 'number') {
|
||||
meta['exitCode'] = err.exitCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user