Sync upstream Gemini-CLI v0.8.2 (#838)

This commit is contained in:
tanzhenxin
2025-10-23 09:27:04 +08:00
committed by GitHub
parent 096fabb5d6
commit eb95c131be
644 changed files with 70389 additions and 23709 deletions

View File

@@ -41,7 +41,6 @@ import type {
ToolConfig,
} from './types.js';
import { SubagentTerminateMode } from './types.js';
import { GeminiClient } from '../core/client.js';
vi.mock('../core/geminiChat.js');
vi.mock('../core/contentGenerator.js');
@@ -162,7 +161,7 @@ describe('subagent.ts', () => {
let mockSendMessageStream: Mock;
const defaultModelConfig: ModelConfig = {
model: 'gemini-1.5-flash-latest',
model: 'qwen3-coder-plus',
temp: 0.5, // Specific temp to test override
top_p: 1,
};
@@ -188,7 +187,6 @@ describe('subagent.ts', () => {
});
mockSendMessageStream = vi.fn();
// We mock the implementation of the constructor.
vi.mocked(GeminiChat).mockImplementation(
() =>
({
@@ -196,28 +194,6 @@ describe('subagent.ts', () => {
}) as unknown as GeminiChat,
);
// Mock GeminiClient constructor to return a properly mocked client
const mockGeminiChat = {
setTools: vi.fn(),
getHistory: vi.fn().mockReturnValue([]),
setHistory: vi.fn(),
sendMessageStream: vi.fn(),
};
const mockGeminiClient = {
getChat: vi.fn().mockReturnValue(mockGeminiChat),
setTools: vi.fn().mockResolvedValue(undefined),
isInitialized: vi.fn().mockReturnValue(true),
getHistory: vi.fn().mockReturnValue([]),
initialize: vi.fn().mockResolvedValue(undefined),
setHistory: vi.fn(),
};
// Mock the GeminiClient constructor
vi.mocked(GeminiClient).mockImplementation(
() => mockGeminiClient as unknown as GeminiClient,
);
// Default mock for executeToolCall
vi.mocked(executeToolCall).mockResolvedValue({
callId: 'default-call',
@@ -237,7 +213,7 @@ describe('subagent.ts', () => {
callIndex = 0,
): GenerateContentConfig & { systemInstruction?: string | Content } => {
const callArgs = vi.mocked(GeminiChat).mock.calls[callIndex];
const generationConfig = callArgs?.[2];
const generationConfig = callArgs?.[1];
// Ensure it's defined before proceeding
expect(generationConfig).toBeDefined();
if (!generationConfig) throw new Error('generationConfig is undefined');
@@ -398,7 +374,7 @@ describe('subagent.ts', () => {
);
// Check History (should include environment context)
const history = callArgs[3];
const history = callArgs[2];
expect(history).toEqual([
{ role: 'user', parts: [{ text: 'Env Context' }] },
{
@@ -433,7 +409,7 @@ describe('subagent.ts', () => {
const callArgs = vi.mocked(GeminiChat).mock.calls[0];
const generationConfig = getGenerationConfigFromMock();
const history = callArgs[3];
const history = callArgs[2];
expect(generationConfig.systemInstruction).toBeUndefined();
expect(history).toEqual([
@@ -515,7 +491,7 @@ describe('subagent.ts', () => {
expect(scope.getTerminateMode()).toBe(SubagentTerminateMode.GOAL);
expect(mockSendMessageStream).toHaveBeenCalledTimes(1);
// Check the initial message
expect(mockSendMessageStream.mock.calls[0][0].message).toEqual([
expect(mockSendMessageStream.mock.calls[0][1].message).toEqual([
{ text: 'Get Started!' },
]);
});
@@ -609,7 +585,7 @@ describe('subagent.ts', () => {
await scope.runNonInteractive(new ContextState());
// Check the response sent back to the model (functionResponse part)
const secondCallArgs = mockSendMessageStream.mock.calls[1][0];
const secondCallArgs = mockSendMessageStream.mock.calls[1][1];
const parts = secondCallArgs.message as unknown[];
expect(Array.isArray(parts)).toBe(true);
const firstPart = parts[0] as Part;
@@ -667,7 +643,7 @@ describe('subagent.ts', () => {
expect(scope.getTerminateMode()).toBe(SubagentTerminateMode.MAX_TURNS);
});
it('should terminate with TIMEOUT if the time limit is reached during an LLM call', async () => {
it.skip('should terminate with TIMEOUT if the time limit is reached during an LLM call', async () => {
// Use fake timers to reliably test timeouts
vi.useFakeTimers();
@@ -713,7 +689,7 @@ describe('subagent.ts', () => {
vi.useRealTimers();
});
it('should terminate with ERROR if the model call throws', async () => {
it.skip('should terminate with ERROR if the model call throws', async () => {
const { config } = await createMockConfig();
mockSendMessageStream.mockRejectedValue(new Error('API Failure'));

View File

@@ -16,7 +16,6 @@ import type {
ToolConfirmationOutcome,
ToolCallConfirmationDetails,
} from '../tools/tools.js';
import { createContentGenerator } from '../core/contentGenerator.js';
import { getEnvironmentContext } from '../utils/environmentContext.js';
import type {
Content,
@@ -55,6 +54,7 @@ import type { SubagentHooks } from './subagent-hooks.js';
import { logSubagentExecution } from '../telemetry/loggers.js';
import { SubagentExecutionEvent } from '../telemetry/types.js';
import { TaskTool } from '../tools/task.js';
import { DEFAULT_QWEN_MODEL } from '../config/models.js';
/**
* @fileoverview Defines the configuration interfaces for a subagent.
@@ -329,7 +329,10 @@ export class SubAgentScope {
this.eventEmitter?.emit(SubAgentEventType.START, {
subagentId: this.subagentId,
name: this.name,
model: this.modelConfig.model,
model:
this.modelConfig.model ||
this.runtimeContext.getModel() ||
DEFAULT_QWEN_MODEL,
tools: (this.toolConfig?.tools || ['*']).map((t) =>
typeof t === 'string' ? t : t.name,
),
@@ -367,6 +370,9 @@ export class SubAgentScope {
};
const responseStream = await chat.sendMessageStream(
this.modelConfig.model ||
this.runtimeContext.getModel() ||
DEFAULT_QWEN_MODEL,
messageParams,
promptId,
);
@@ -828,26 +834,15 @@ export class SubAgentScope {
generationConfig.systemInstruction = systemInstruction;
}
const contentGenerator = await createContentGenerator(
this.runtimeContext.getContentGeneratorConfig(),
this.runtimeContext,
this.runtimeContext.getSessionId(),
);
if (this.modelConfig.model) {
await this.runtimeContext.setModel(this.modelConfig.model);
}
return new GeminiChat(
this.runtimeContext,
contentGenerator,
generationConfig,
start_history,
);
} catch (error) {
await reportError(
error,
'Error initializing Gemini chat session.',
'Error initializing chat session.',
start_history,
'startChat',
);

View File

@@ -227,7 +227,7 @@ export interface ToolConfig {
*/
export interface ModelConfig {
/**
* The name or identifier of the model to be used (e.g., 'gemini-2.5-pro').
* The name or identifier of the model to be used (e.g., 'qwen3-coder-plus').
*
* TODO: In the future, this needs to support 'auto' or some other string to support routing use cases.
*/