diff options
| author | Olcan <[email protected]> | 2025-05-27 15:40:18 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-27 15:40:18 -0700 |
| commit | bfeaac844186153698d3a7079b41214bbf1e4371 (patch) | |
| tree | b7b5208072de7f43eb45d9e7a2fe64b1febee42f /packages/server/src | |
| parent | 0d5f7686d7c4cd355cc2d327a2f04c8d7d31e09e (diff) | |
live output from shell tool (#573)
Diffstat (limited to 'packages/server/src')
| -rw-r--r-- | packages/server/src/tools/shell.ts | 7 | ||||
| -rw-r--r-- | packages/server/src/tools/tools.ts | 12 |
2 files changed, 17 insertions, 2 deletions
diff --git a/packages/server/src/tools/shell.ts b/packages/server/src/tools/shell.ts index 9e61717c..6ee36b8d 100644 --- a/packages/server/src/tools/shell.ts +++ b/packages/server/src/tools/shell.ts @@ -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; diff --git a/packages/server/src/tools/tools.ts b/packages/server/src/tools/tools.ts index 2f5a4095..c57bbd39 100644 --- a/packages/server/src/tools/tools.ts +++ b/packages/server/src/tools/tools.ts @@ -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 { |
