@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
37 lines • 1.55 kB
TypeScript
/**
* Parse tool arguments from various formats
* Handles both string-encoded JSON and already-parsed objects
*
* This utility eliminates the repeated pattern of JSON parsing that appears
* throughout the codebase when handling tool call arguments.
*
* ## Error Handling Modes
*
* **Lenient mode (strict=false, default)**: Used for display/UI purposes where
* graceful degradation is acceptable. If JSON parsing fails, returns the
* unparsed string, allowing the application to continue.
*
* **Strict mode (strict=true)**: Used for tool execution where malformed
* arguments must be caught early. Throws an error if JSON parsing fails,
* preventing execution with invalid data.
*
* @param args - Arguments in any format (string, object, etc.)
* @param options - Parsing options
* @param options.strict - If true, throw error on parse failure. If false, return unparsed value. Default: false
* @returns Parsed arguments as the specified type
* @throws Error if strict=true and JSON parsing fails
*
* @example
* // Lenient parsing for display
* const parsedArgs = parseToolArguments(toolCall.function.arguments);
*
* // Strict parsing for tool execution
* const parsedArgs = parseToolArguments(toolCall.function.arguments, {strict: true});
*
* // With type parameter
* const typedArgs = parseToolArguments<{path: string}>(args, {strict: true});
*/
export declare function parseToolArguments<T = Record<string, unknown>>(args: unknown, options?: {
strict?: boolean;
}): T;
//# sourceMappingURL=tool-args-parser.d.ts.map