mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
live output from shell tool (#573)
This commit is contained in:
@@ -123,6 +123,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||
async execute(
|
||||
params: ShellToolParams,
|
||||
abortSignal: AbortSignal,
|
||||
onOutputChunk?: (chunk: string) => void,
|
||||
): Promise<ToolResult> {
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
@@ -157,6 +158,9 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||
const str = data.toString();
|
||||
stdout += str;
|
||||
output += str;
|
||||
if (onOutputChunk) {
|
||||
onOutputChunk(str);
|
||||
}
|
||||
});
|
||||
|
||||
let stderr = '';
|
||||
@@ -174,6 +178,9 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||
}
|
||||
stderr += str;
|
||||
output += str;
|
||||
if (onOutputChunk) {
|
||||
onOutputChunk(str);
|
||||
}
|
||||
});
|
||||
|
||||
let error: Error | null = null;
|
||||
|
||||
@@ -64,7 +64,11 @@ export interface Tool<
|
||||
* @param params Parameters for the tool execution
|
||||
* @returns Result of the tool execution
|
||||
*/
|
||||
execute(params: TParams, signal: AbortSignal): Promise<TResult>;
|
||||
execute(
|
||||
params: TParams,
|
||||
signal: AbortSignal,
|
||||
onOutputChunk?: (chunk: string) => void,
|
||||
): Promise<TResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +148,11 @@ export abstract class BaseTool<
|
||||
* @param signal AbortSignal for tool cancellation
|
||||
* @returns Result of the tool execution
|
||||
*/
|
||||
abstract execute(params: TParams, signal: AbortSignal): Promise<TResult>;
|
||||
abstract execute(
|
||||
params: TParams,
|
||||
signal: AbortSignal,
|
||||
onOutputChunk?: (chunk: string) => void,
|
||||
): Promise<TResult>;
|
||||
}
|
||||
|
||||
export interface ToolResult {
|
||||
|
||||
Reference in New Issue
Block a user