* Type guard that checks whether a value is a ToolResultObject. * A valid object must have a string `textResultForLlm` and a recognized `resultType`.
(value: unknown)
| 1393 | * A valid object must have a string `textResultForLlm` and a recognized `resultType`. |
| 1394 | */ |
| 1395 | function isToolResultObject(value: unknown): value is ToolResultObject { |
| 1396 | if (typeof value !== "object" || value === null) { |
| 1397 | return false; |
| 1398 | } |
| 1399 | |
| 1400 | if ( |
| 1401 | !("textResultForLlm" in value) || |
| 1402 | typeof (value as ToolResultObject).textResultForLlm !== "string" |
| 1403 | ) { |
| 1404 | return false; |
| 1405 | } |
| 1406 | |
| 1407 | if (!("resultType" in value) || typeof (value as ToolResultObject).resultType !== "string") { |
| 1408 | return false; |
| 1409 | } |
| 1410 | |
| 1411 | const allowedResultTypes: Array<ToolResultObject["resultType"]> = [ |
| 1412 | "success", |
| 1413 | "failure", |
| 1414 | "rejected", |
| 1415 | "denied", |
| 1416 | "timeout", |
| 1417 | ]; |
| 1418 | |
| 1419 | return allowedResultTypes.includes((value as ToolResultObject).resultType); |
| 1420 | } |
| 1421 | |
| 1422 | /** Convert a canvas handler error into a ResponseError with a structured data envelope. */ |
| 1423 | function toCanvasRpcError(error: unknown): ResponseError<unknown> { |
no outgoing calls
no test coverage detected
searching dependent graphs…