mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Remove unnecessary promiuse usage. (#6585)
This commit is contained in:
committed by
GitHub
parent
1244ec6954
commit
0cc2a1e7ef
@@ -482,8 +482,8 @@ export class Config {
|
||||
return this.workspaceContext;
|
||||
}
|
||||
|
||||
getToolRegistry(): Promise<ToolRegistry> {
|
||||
return Promise.resolve(this.toolRegistry);
|
||||
getToolRegistry(): ToolRegistry {
|
||||
return this.toolRegistry;
|
||||
}
|
||||
|
||||
getPromptRegistry(): PromptRegistry {
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('Gemini Client (client.ts)', () => {
|
||||
getContentGeneratorConfig: vi
|
||||
.fn()
|
||||
.mockReturnValue(contentGeneratorConfig),
|
||||
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
|
||||
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
||||
getModel: vi.fn().mockReturnValue('test-model'),
|
||||
getEmbeddingModel: vi.fn().mockReturnValue('test-embedding-model'),
|
||||
getApiKey: vi.fn().mockReturnValue('test-key'),
|
||||
|
||||
@@ -201,7 +201,7 @@ export class GeminiClient {
|
||||
}
|
||||
|
||||
async setTools(): Promise<void> {
|
||||
const toolRegistry = await this.config.getToolRegistry();
|
||||
const toolRegistry = this.config.getToolRegistry();
|
||||
const toolDeclarations = toolRegistry.getFunctionDeclarations();
|
||||
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
|
||||
this.getChat().setTools(tools);
|
||||
@@ -225,7 +225,7 @@ export class GeminiClient {
|
||||
async startChat(extraHistory?: Content[]): Promise<GeminiChat> {
|
||||
this.forceFullIdeContext = true;
|
||||
const envParts = await getEnvironmentContext(this.config);
|
||||
const toolRegistry = await this.config.getToolRegistry();
|
||||
const toolRegistry = this.config.getToolRegistry();
|
||||
const toolDeclarations = toolRegistry.getFunctionDeclarations();
|
||||
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
|
||||
const history: Content[] = [
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('CoreToolScheduler', () => {
|
||||
const mockTool = new MockTool();
|
||||
mockTool.shouldConfirm = true;
|
||||
const declarativeTool = mockTool;
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getFunctionDeclarations: () => [],
|
||||
tools: new Map(),
|
||||
@@ -43,7 +43,7 @@ describe('CoreToolScheduler', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -61,7 +61,7 @@ describe('CoreToolScheduler', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
@@ -91,7 +91,7 @@ describe('CoreToolScheduler with payload', () => {
|
||||
it('should update args and diff and execute tool when payload is provided', async () => {
|
||||
const mockTool = new MockModifiableTool();
|
||||
const declarativeTool = mockTool;
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getFunctionDeclarations: () => [],
|
||||
tools: new Map(),
|
||||
@@ -103,7 +103,7 @@ describe('CoreToolScheduler with payload', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -121,7 +121,7 @@ describe('CoreToolScheduler with payload', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
@@ -391,7 +391,7 @@ describe('CoreToolScheduler edit cancellation', () => {
|
||||
it('should preserve diff when an edit is cancelled', async () => {
|
||||
const mockEditTool = new MockEditTool();
|
||||
const declarativeTool = mockEditTool;
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getFunctionDeclarations: () => [],
|
||||
tools: new Map(),
|
||||
@@ -403,7 +403,7 @@ describe('CoreToolScheduler edit cancellation', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -421,7 +421,7 @@ describe('CoreToolScheduler edit cancellation', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
@@ -481,7 +481,7 @@ describe('CoreToolScheduler YOLO mode', () => {
|
||||
mockTool.shouldConfirm = true;
|
||||
const declarativeTool = mockTool;
|
||||
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getToolByName: () => declarativeTool,
|
||||
// Other properties are not needed for this test but are included for type consistency.
|
||||
@@ -494,7 +494,7 @@ describe('CoreToolScheduler YOLO mode', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -513,7 +513,7 @@ describe('CoreToolScheduler YOLO mode', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
@@ -572,7 +572,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
mockTool.executeFn.mockImplementation(() => firstCallPromise);
|
||||
const declarativeTool = mockTool;
|
||||
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getToolByName: () => declarativeTool,
|
||||
getFunctionDeclarations: () => [],
|
||||
@@ -584,7 +584,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -602,7 +602,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
@@ -685,7 +685,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
it('should handle two synchronous calls to schedule', async () => {
|
||||
const mockTool = new MockTool();
|
||||
const declarativeTool = mockTool;
|
||||
const toolRegistry = {
|
||||
const mockToolRegistry = {
|
||||
getTool: () => declarativeTool,
|
||||
getToolByName: () => declarativeTool,
|
||||
getFunctionDeclarations: () => [],
|
||||
@@ -697,7 +697,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
discoverTools: async () => {},
|
||||
getAllTools: () => [],
|
||||
getToolsByServer: () => [],
|
||||
};
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
const onAllToolCallsComplete = vi.fn();
|
||||
const onToolCallsUpdate = vi.fn();
|
||||
@@ -715,7 +715,7 @@ describe('CoreToolScheduler request queueing', () => {
|
||||
|
||||
const scheduler = new CoreToolScheduler({
|
||||
config: mockConfig,
|
||||
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
|
||||
toolRegistry: mockToolRegistry,
|
||||
onAllToolCallsComplete,
|
||||
onToolCallsUpdate,
|
||||
getPreferredEditor: () => 'vscode',
|
||||
|
||||
@@ -226,7 +226,7 @@ const createErrorResponse = (
|
||||
});
|
||||
|
||||
interface CoreToolSchedulerOptions {
|
||||
toolRegistry: Promise<ToolRegistry>;
|
||||
toolRegistry: ToolRegistry;
|
||||
outputUpdateHandler?: OutputUpdateHandler;
|
||||
onAllToolCallsComplete?: AllToolCallsCompleteHandler;
|
||||
onToolCallsUpdate?: ToolCallsUpdateHandler;
|
||||
@@ -236,7 +236,7 @@ interface CoreToolSchedulerOptions {
|
||||
}
|
||||
|
||||
export class CoreToolScheduler {
|
||||
private toolRegistry: Promise<ToolRegistry>;
|
||||
private toolRegistry: ToolRegistry;
|
||||
private toolCalls: ToolCall[] = [];
|
||||
private outputUpdateHandler?: OutputUpdateHandler;
|
||||
private onAllToolCallsComplete?: AllToolCallsCompleteHandler;
|
||||
@@ -534,11 +534,10 @@ export class CoreToolScheduler {
|
||||
);
|
||||
}
|
||||
const requestsToProcess = Array.isArray(request) ? request : [request];
|
||||
const toolRegistry = await this.toolRegistry;
|
||||
|
||||
const newToolCalls: ToolCall[] = requestsToProcess.map(
|
||||
(reqInfo): ToolCall => {
|
||||
const toolInstance = toolRegistry.getTool(reqInfo.name);
|
||||
const toolInstance = this.toolRegistry.getTool(reqInfo.name);
|
||||
if (!toolInstance) {
|
||||
return {
|
||||
status: 'error',
|
||||
|
||||
@@ -428,7 +428,7 @@ export class GeminiChat {
|
||||
isSchemaDepthError(error.message) ||
|
||||
isInvalidArgumentError(error.message)
|
||||
) {
|
||||
const tools = (await this.config.getToolRegistry()).getAllTools();
|
||||
const tools = this.config.getToolRegistry().getAllTools();
|
||||
const cyclicSchemaTools: string[] = [];
|
||||
for (const tool of tools) {
|
||||
if (
|
||||
|
||||
@@ -59,7 +59,7 @@ async function createMockConfig(
|
||||
...toolRegistryMocks,
|
||||
} as unknown as ToolRegistry;
|
||||
|
||||
vi.spyOn(config, 'getToolRegistry').mockResolvedValue(mockToolRegistry);
|
||||
vi.spyOn(config, 'getToolRegistry').mockReturnValue(mockToolRegistry);
|
||||
return { config, toolRegistry: mockToolRegistry };
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ export class SubAgentScope {
|
||||
outputConfig?: OutputConfig,
|
||||
): Promise<SubAgentScope> {
|
||||
if (toolConfig) {
|
||||
const toolRegistry: ToolRegistry = await runtimeContext.getToolRegistry();
|
||||
const toolRegistry = runtimeContext.getToolRegistry();
|
||||
const toolsToLoad: string[] = [];
|
||||
for (const tool of toolConfig.tools) {
|
||||
if (typeof tool === 'string') {
|
||||
@@ -349,8 +349,7 @@ export class SubAgentScope {
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
const toolRegistry: ToolRegistry =
|
||||
await this.runtimeContext.getToolRegistry();
|
||||
const toolRegistry = this.runtimeContext.getToolRegistry();
|
||||
|
||||
// Prepare the list of tools available to the subagent.
|
||||
const toolsList: FunctionDeclaration[] = [];
|
||||
|
||||
@@ -89,7 +89,7 @@ describe('getEnvironmentContext', () => {
|
||||
}),
|
||||
getFileService: vi.fn(),
|
||||
getFullContext: vi.fn().mockReturnValue(false),
|
||||
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
|
||||
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
||||
};
|
||||
|
||||
vi.mocked(getFolderStructure).mockResolvedValue('Mock Folder Structure');
|
||||
|
||||
@@ -68,7 +68,7 @@ ${directoryContext}
|
||||
`.trim();
|
||||
|
||||
const initialParts: Part[] = [{ text: context }];
|
||||
const toolRegistry = await config.getToolRegistry();
|
||||
const toolRegistry = config.getToolRegistry();
|
||||
|
||||
// Add full file context if the flag is set
|
||||
if (config.getFullContext()) {
|
||||
|
||||
Reference in New Issue
Block a user