(
result: ClientToolResult,
clientTool: AnyClientTool | undefined,
context?: ChatClientRunEventContext,
)
| 1195 | } |
| 1196 | |
| 1197 | private async addToolResultForClientTool( |
| 1198 | result: ClientToolResult, |
| 1199 | clientTool: AnyClientTool | undefined, |
| 1200 | context?: ChatClientRunEventContext, |
| 1201 | ): Promise<void> { |
| 1202 | if (clientTool && result.state !== 'output-error') { |
| 1203 | try { |
| 1204 | result = { |
| 1205 | ...result, |
| 1206 | output: this.validateClientToolOutput(clientTool, result.output), |
| 1207 | } |
| 1208 | } catch (error: any) { |
| 1209 | result = { |
| 1210 | ...result, |
| 1211 | output: null, |
| 1212 | state: 'output-error', |
| 1213 | errorText: error.message, |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | this.events.toolResultAdded( |
| 1219 | result.toolCallId, |
| 1220 | result.tool, |
| 1221 | result.output, |
| 1222 | result.state || 'output-available', |
| 1223 | context, |
| 1224 | ) |
| 1225 | |
| 1226 | // Forward an error message only for output-error results (with a fallback so |
| 1227 | // a message-less `throw new Error()` still reaches the terminal 'error' |
| 1228 | // state); a stray errorText on a successful result must not signal an error. |
| 1229 | this.processor.addToolResult( |
| 1230 | result.toolCallId, |
| 1231 | result.output, |
| 1232 | result.state === 'output-error' |
| 1233 | ? result.errorText || 'Tool execution failed' |
| 1234 | : undefined, |
| 1235 | ) |
| 1236 | |
| 1237 | // If stream is in progress, queue continuation check for after it ends |
| 1238 | if (this.isLoading) { |
| 1239 | this.queuePostStreamAction(() => this.checkForContinuation()) |
| 1240 | return |
| 1241 | } |
| 1242 | |
| 1243 | await this.checkForContinuation() |
| 1244 | } |
| 1245 | |
| 1246 | private validateClientToolOutput( |
| 1247 | clientTool: AnyClientTool, |
no test coverage detected