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

Function convertToolBlocksToText

src/core/condense/index.ts:71–93  ·  view source on GitHub ↗
(
	content: string | Anthropic.Messages.ContentBlockParam[],
)

Source from the content-addressed store, hash-verified

69 * @returns The transformed content with tool blocks converted to text blocks
70 */
71export function convertToolBlocksToText(
72 content: string | Anthropic.Messages.ContentBlockParam[],
73): string | Anthropic.Messages.ContentBlockParam[] {
74 if (typeof content === "string") {
75 return content
76 }
77
78 return content.map((block) => {
79 if (block.type === "tool_use") {
80 return {
81 type: "text" as const,
82 text: toolUseToText(block),
83 }
84 }
85 if (block.type === "tool_result") {
86 return {
87 type: "text" as const,
88 text: toolResultToText(block),
89 }
90 }
91 return block
92 })
93}
94
95/**
96 * Transforms all messages by converting tool_use and tool_result blocks to text representations.

Callers 2

index.spec.tsFile · 0.90

Calls 2

toolUseToTextFunction · 0.85
toolResultToTextFunction · 0.85

Tested by

no test coverage detected