MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseRawToolCall

Function parseRawToolCall

packages/agent-runtime/src/tools/tool-executor.ts:192–246  ·  view source on GitHub ↗
(params: {
  rawToolCall: {
    toolName: T
    toolCallId: string
    input: unknown
  }
})

Source from the content-addressed store, hash-verified

190}
191
192export function parseRawToolCall<T extends ToolName = ToolName>(params: {
193 rawToolCall: {
194 toolName: T
195 toolCallId: string
196 input: unknown
197 }
198}): CodebuffToolCall<T> | ToolCallError {
199 const { rawToolCall } = params
200 const toolName = rawToolCall.toolName
201
202 const processedParameters = parseStringifiedToolInput(
203 rawToolCall.input,
204 toolName,
205 )
206 const paramsSchema = toolParams[toolName].inputSchema
207
208 if (typeof processedParameters.input === 'string') {
209 return stringInputError(
210 toolName,
211 rawToolCall.toolCallId,
212 processedParameters.parseError,
213 )
214 }
215
216 const result = paramsSchema.safeParse(processedParameters.input)
217
218 if (!result.success) {
219 const hint = getToolValidationHint(toolName)
220 const summary = summarizeMissingReplacementFields(
221 toolName,
222 result.error.issues,
223 )
224 const validationDetails = JSON.stringify(result.error.issues, null, 2)
225 return {
226 toolName,
227 toolCallId: rawToolCall.toolCallId,
228 input: rawToolCall.input,
229 error: `Invalid parameters for ${toolName}: ${
230 summary
231 ? `${summary}\n\nRaw validation issues:\n${validationDetails}`
232 : validationDetails
233 }${hint ? `\n\n${hint}` : ''}`,
234 }
235 }
236
237 if (endsAgentStepParam in result.data) {
238 delete result.data[endsAgentStepParam]
239 }
240
241 return {
242 toolName,
243 input: result.data,
244 toolCallId: rawToolCall.toolCallId,
245 } as CodebuffToolCall<T>
246}
247
248export type ExecuteToolCallParams<T extends string = ToolName> = {
249 toolName: T

Callers 2

executeToolCallFunction · 0.85

Calls 4

stringInputErrorFunction · 0.85
getToolValidationHintFunction · 0.85

Tested by

no test coverage detected