mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: subagent - minor code refactor
This commit is contained in:
@@ -199,6 +199,7 @@ describe('<ToolMessage />', () => {
|
||||
type: 'task_execution' as const,
|
||||
subagentName: 'file-search',
|
||||
taskDescription: 'Search for files matching pattern',
|
||||
taskPrompt: 'Search for files matching pattern',
|
||||
status: 'running' as const,
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface IndividualToolCallDisplay {
|
||||
callId: string;
|
||||
name: string;
|
||||
description: string;
|
||||
resultDisplay: ToolResultDisplay | string | object | undefined;
|
||||
resultDisplay: ToolResultDisplay | string | undefined;
|
||||
status: ToolCallStatus;
|
||||
confirmationDetails: ToolCallConfirmationDetails | undefined;
|
||||
renderOutputAsMarkdown?: boolean;
|
||||
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
SubAgentEventType,
|
||||
SubAgentErrorEvent,
|
||||
} from '../subagents/subagent-events.js';
|
||||
import { ChatRecordingService } from '../services/chatRecordingService.js';
|
||||
|
||||
export interface TaskParams {
|
||||
description: string;
|
||||
@@ -413,43 +412,12 @@ class TaskToolInvocation extends BaseToolInvocation<TaskParams, ToolResult> {
|
||||
if (updateOutput) {
|
||||
updateOutput(this.currentDisplay);
|
||||
}
|
||||
const chatRecorder = new ChatRecordingService(this.config);
|
||||
try {
|
||||
chatRecorder.initialize();
|
||||
} catch {
|
||||
// Initialization failed, continue without recording
|
||||
}
|
||||
const subagentScope = await this.subagentManager.createSubagentScope(
|
||||
subagentConfig,
|
||||
this.config,
|
||||
{ eventEmitter: this.eventEmitter },
|
||||
);
|
||||
|
||||
// Set up basic event listeners for chat recording
|
||||
this.eventEmitter.on('start', () => {
|
||||
chatRecorder.recordMessage({
|
||||
type: 'user',
|
||||
content: `Subagent(${this.params.subagent_type}) Task: ${this.params.description}\n\n${this.params.prompt}`,
|
||||
});
|
||||
});
|
||||
|
||||
this.eventEmitter.on('finish', (e) => {
|
||||
const finishEvent = e as {
|
||||
inputTokens?: number;
|
||||
outputTokens?: number;
|
||||
};
|
||||
const text = subagentScope.getFinalText() || '';
|
||||
chatRecorder.recordMessage({ type: 'gemini', content: text });
|
||||
const input = finishEvent.inputTokens ?? 0;
|
||||
const output = finishEvent.outputTokens ?? 0;
|
||||
chatRecorder.recordMessageTokens({
|
||||
input,
|
||||
output,
|
||||
cached: 0,
|
||||
total: input + output,
|
||||
});
|
||||
});
|
||||
|
||||
// Create context state with the task prompt
|
||||
const contextState = new ContextState();
|
||||
contextState.set('task_prompt', this.params.prompt);
|
||||
|
||||
Reference in New Issue
Block a user