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

Function normalizeToolInputForAPI

source code/utils/api.ts:687–720  ·  view source on GitHub ↗
(
  tool: T,
  input: z.infer<T['inputSchema']>,
)

Source from the content-addressed store, hash-verified

685// Strips fields that were added by normalizeToolInput before sending to API
686// (e.g., plan field from ExitPlanModeV2 which has an empty input schema)
687export function normalizeToolInputForAPI<T extends Tool>(
688 tool: T,
689 input: z.infer<T['inputSchema']>,
690): z.infer<T['inputSchema']> {
691 switch (tool.name) {
692 case EXIT_PLAN_MODE_V2_TOOL_NAME: {
693 // Strip injected fields before sending to API (schema expects empty object)
694 if (
695 input &&
696 typeof input === 'object' &&
697 ('plan' in input || 'planFilePath' in input)
698 ) {
699 const { plan, planFilePath, ...rest } = input as Record<string, unknown>
700 return rest as z.infer<T['inputSchema']>
701 }
702 return input
703 }
704 case FileEditTool.name: {
705 // Strip synthetic old_string/new_string/replace_all from OLD sessions
706 // that were resumed from transcripts written before PR #20357, where
707 // normalizeToolInput used to synthesize these. Needed so old --resume'd
708 // transcripts don't send whole-file copies to the API. New sessions
709 // don't need this (synthesis moved to emission time).
710 if (input && typeof input === 'object' && 'edits' in input) {
711 const { old_string, new_string, replace_all, ...rest } =
712 input as Record<string, unknown>
713 return rest as z.infer<T['inputSchema']>
714 }
715 return input
716 }
717 default:
718 return input
719 }
720}

Callers 1

normalizeMessagesForAPIFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected