Lines 1-40javascript
2 * @fileoverview Provides a utility class for parsing XML strings.
3 * Wraps the `fast-xml-parser` peer dependency (lazy-loaded on first use) and strips
4 * optional `<think>...</think>` blocks that LLMs sometimes prepend to structured
5 * output before parsing. The underlying `XMLParser` instance is created once with
6 * `processEntities: false` and `htmlEntities: false` and reused for all calls.
8 * Peer dependency: `fast-xml-parser` — install with `bun add fast-xml-parser`.
9 * @module src/utils/parsing/xmlParser
11import { configurationError, validationError } from '../../types-global/errors.js';
12import { logger } from '../../utils/internal/logger.js';
13import { requestContextService } from '../../utils/internal/requestContext.js';
14import { thinkBlockRegex } from './thinkBlock.js';
16let _xmlParserInstance;
17const FXP_MODULE = 'fast-xml-parser';
18async function getFxp() {
21 _fxp = await import(FXP_MODULE).catch(() => {
22 throw configurationError('Install "fast-xml-parser" to use XML parsing: bun add fast-xml-parser');
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/utils/parsing/xmlParser.jsView on unpkg · L20 27 * Utility class for parsing XML strings.
29 * Lazily loads `fast-xml-parser` on first use (peer dependency — install with
30 * `bun add fast-xml-parser`). The `XMLParser` instance is constructed once at first
31 * call with `{ processEntities: false, htmlEntities: false }` and cached for subsequent
32 * calls. Handles optional `<think>...</think>` blocks that some LLMs prepend to
33 * structured output; the block's content is logged at debug level and stripped before
36export class XmlParser {
38 * Parses an XML string into a typed JavaScript object.
40 * This method is async because `fast-xml-parser` is loaded lazily on first call.