MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / buildAndPushResult

Method buildAndPushResult

src/core/tools/ReadFileTool.ts:572–621  ·  view source on GitHub ↗

* Build and push the final result to the tool output.

(task: Task, fileResults: FileResult[], pushToolResult: PushToolResult)

Source from the content-addressed store, hash-verified

570 * Build and push the final result to the tool output.
571 */
572 private buildAndPushResult(task: Task, fileResults: FileResult[], pushToolResult: PushToolResult): void {
573 const finalResult = fileResults
574 .filter((r) => r.nativeContent)
575 .map((r) => r.nativeContent)
576 .join("\n\n---\n\n")
577
578 const fileImageUrls = fileResults.filter((r) => r.imageDataUrl).map((r) => r.imageDataUrl as string)
579
580 let statusMessage = ""
581 let feedbackImages: string[] = []
582
583 const deniedWithFeedback = fileResults.find((r) => r.status === "denied" && r.feedbackText)
584
585 if (deniedWithFeedback?.feedbackText) {
586 statusMessage = formatResponse.toolDeniedWithFeedback(deniedWithFeedback.feedbackText)
587 feedbackImages = deniedWithFeedback.feedbackImages || []
588 } else if (task.didRejectTool) {
589 statusMessage = formatResponse.toolDenied()
590 } else {
591 const approvedWithFeedback = fileResults.find((r) => r.status === "approved" && r.feedbackText)
592 if (approvedWithFeedback?.feedbackText) {
593 statusMessage = formatResponse.toolApprovedWithFeedback(approvedWithFeedback.feedbackText)
594 feedbackImages = approvedWithFeedback.feedbackImages || []
595 }
596 }
597
598 const allImages = [...feedbackImages, ...fileImageUrls]
599 const finalModelSupportsImages = task.api.getModel().info.supportsImages ?? false
600 const imagesToInclude = finalModelSupportsImages ? allImages : []
601
602 if (statusMessage || imagesToInclude.length > 0) {
603 const result = formatResponse.toolResult(
604 statusMessage || finalResult,
605 imagesToInclude.length > 0 ? imagesToInclude : undefined,
606 )
607
608 if (typeof result === "string") {
609 pushToolResult(statusMessage ? `${result}\n${finalResult}` : result)
610 } else {
611 if (statusMessage) {
612 const textBlock = { type: "text" as const, text: finalResult }
613 pushToolResult([...result, textBlock] as any)
614 } else {
615 pushToolResult(result as any)
616 }
617 }
618 } else {
619 pushToolResult(finalResult)
620 }
621 }
622
623 getReadFileToolDescription(blockName: string, blockParams: { path?: string }): string
624 getReadFileToolDescription(blockName: string, nativeArgs: ReadFileParams): string

Callers 1

executeNewMethod · 0.95

Calls 2

pushToolResultFunction · 0.85
getModelMethod · 0.65

Tested by

no test coverage detected