Tool Message Tagging Utils (tools/utils.ts)

collection-claude-code-source-code · original-source-code/src/tools/utils.ts · typescript · Apache-2.0
ai, chat, lang:typescript, tag:tool-use, tag:utilities

Tags user messages with a tool-use ID to keep tool status messages transient, and extracts tool-use IDs from parent assistant messages. Reuse for AI tool-call message handling.

// Source: https://github.com/chauncygu/collection-claude-code-source-code | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import type {
  AssistantMessage,
  AttachmentMessage,
  SystemMessage,
  UserMessage,
} from 'src/types/message.js'

/**
 * Tags user messages with a sourceToolUseID so they stay transient until the tool resolves.
 * This prevents the "is running" message from being duplicated in the UI.
 */
export function tagMessagesWithToolUseID(
  messages: (UserMessage | AttachmentMessage | SystemMessage)[],
  toolUseID: string | undefined,
): (UserMessage | AttachmentMessage | SystemMessage)[] {
  if (!toolUseID) {
    return messages
  }
  return messages.map(m => {
  

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key