mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
feat: subagent - minor code refactor
This commit is contained in:
@@ -199,6 +199,7 @@ describe('<ToolMessage />', () => {
|
|||||||
type: 'task_execution' as const,
|
type: 'task_execution' as const,
|
||||||
subagentName: 'file-search',
|
subagentName: 'file-search',
|
||||||
taskDescription: 'Search for files matching pattern',
|
taskDescription: 'Search for files matching pattern',
|
||||||
|
taskPrompt: 'Search for files matching pattern',
|
||||||
status: 'running' as const,
|
status: 'running' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export interface IndividualToolCallDisplay {
|
|||||||
callId: string;
|
callId: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
resultDisplay: ToolResultDisplay | string | object | undefined;
|
resultDisplay: ToolResultDisplay | string | undefined;
|
||||||
status: ToolCallStatus;
|
status: ToolCallStatus;
|
||||||
confirmationDetails: ToolCallConfirmationDetails | undefined;
|
confirmationDetails: ToolCallConfirmationDetails | undefined;
|
||||||
renderOutputAsMarkdown?: boolean;
|
renderOutputAsMarkdown?: boolean;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
SubAgentEventType,
|
SubAgentEventType,
|
||||||
SubAgentErrorEvent,
|
SubAgentErrorEvent,
|
||||||
} from '../subagents/subagent-events.js';
|
} from '../subagents/subagent-events.js';
|
||||||
import { ChatRecordingService } from '../services/chatRecordingService.js';
|
|
||||||
|
|
||||||
export interface TaskParams {
|
export interface TaskParams {
|
||||||
description: string;
|
description: string;
|
||||||
@@ -413,43 +412,12 @@ class TaskToolInvocation extends BaseToolInvocation<TaskParams, ToolResult> {
|
|||||||
if (updateOutput) {
|
if (updateOutput) {
|
||||||
updateOutput(this.currentDisplay);
|
updateOutput(this.currentDisplay);
|
||||||
}
|
}
|
||||||
const chatRecorder = new ChatRecordingService(this.config);
|
|
||||||
try {
|
|
||||||
chatRecorder.initialize();
|
|
||||||
} catch {
|
|
||||||
// Initialization failed, continue without recording
|
|
||||||
}
|
|
||||||
const subagentScope = await this.subagentManager.createSubagentScope(
|
const subagentScope = await this.subagentManager.createSubagentScope(
|
||||||
subagentConfig,
|
subagentConfig,
|
||||||
this.config,
|
this.config,
|
||||||
{ eventEmitter: this.eventEmitter },
|
{ 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
|
// Create context state with the task prompt
|
||||||
const contextState = new ContextState();
|
const contextState = new ContextState();
|
||||||
contextState.set('task_prompt', this.params.prompt);
|
contextState.set('task_prompt', this.params.prompt);
|
||||||
|
|||||||
Reference in New Issue
Block a user