UNPKG

@autobe/agent

Version:

AI backend server code generator

34 lines (33 loc) 1.22 kB
/** * Parses text-based function calls from LLM response content. * * Some models (e.g., Qwen3) attempt function calling but return the call as * plain text/JSON in `message.content` instead of the proper `tool_calls` * field. This utility extracts those text-based function calls and normalizes * them into a structured format. * * @author Juntak */ export interface IParsedFunctionCall { /** Function name (must match one of the available tools) */ name: string; /** Arguments as a JSON string */ arguments: string; } /** * Extracts function calls from text content. * * Parsing strategy (in priority order): * * 1. XML `<tool_call>` / `<function_call>` tags (Qwen-style patterns) * 2. Markdown code blocks * 3. Raw JSON objects in content * 4. JavaScript-style invocations (e.g. `process({...})`) * * Only returns calls whose function name matches `availableToolNames`. * * @param content The text content to parse * @param availableToolNames List of valid function names from the request tools * @returns Array of parsed function calls (empty if none found) */ export declare const parseTextFunctionCall: (content: string, availableToolNames: string[]) => IParsedFunctionCall[];