MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createToolResultMessage

Function createToolResultMessage

source code/utils/messages.ts:4290–4325  ·  view source on GitHub ↗
(
  tool: Tool<AnyObject, Output>,
  toolUseResult: Output,
)

Source from the content-addressed store, hash-verified

4288}
4289
4290function createToolResultMessage<Output>(
4291 tool: Tool<AnyObject, Output>,
4292 toolUseResult: Output,
4293): UserMessage {
4294 try {
4295 const result = tool.mapToolResultToToolResultBlockParam(toolUseResult, '1')
4296
4297 // If the result contains image content blocks, preserve them as is
4298 if (
4299 Array.isArray(result.content) &&
4300 result.content.some(block => block.type === 'image')
4301 ) {
4302 return createUserMessage({
4303 content: result.content as ContentBlockParam[],
4304 isMeta: true,
4305 })
4306 }
4307
4308 // For string content, use raw string — jsonStringify would escape \n→\\n,
4309 // wasting ~1 token per newline (a 2000-line @-file = ~1000 wasted tokens).
4310 // Keep jsonStringify for array/object content where structure matters.
4311 const contentStr =
4312 typeof result.content === 'string'
4313 ? result.content
4314 : jsonStringify(result.content)
4315 return createUserMessage({
4316 content: `Result of calling the ${tool.name} tool:\n${contentStr}`,
4317 isMeta: true,
4318 })
4319 } catch {
4320 return createUserMessage({
4321 content: `Result of calling the ${tool.name} tool: Error`,
4322 isMeta: true,
4323 })
4324 }
4325}
4326
4327function createToolUseMessage(
4328 toolName: string,

Callers 1

Calls 2

createUserMessageFunction · 0.85
jsonStringifyFunction · 0.85

Tested by

no test coverage detected