@nhtio/adk 1.20260609.0 → 1.20260610.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -9
- package/batteries/llm/ollama/helpers.cjs +9 -0
- package/batteries/llm/ollama/helpers.cjs.map +1 -1
- package/batteries/llm/ollama/helpers.mjs +9 -0
- package/batteries/llm/ollama/helpers.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.cjs +19 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.mjs +19 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
- package/batteries/media/builder.d.ts +245 -0
- package/batteries/media/contracts.cjs +119 -0
- package/batteries/media/contracts.cjs.map +1 -0
- package/batteries/media/contracts.d.ts +321 -0
- package/batteries/media/contracts.mjs +110 -0
- package/batteries/media/contracts.mjs.map +1 -0
- package/batteries/media/engines/audio_decode.cjs +92 -0
- package/batteries/media/engines/audio_decode.cjs.map +1 -0
- package/batteries/media/engines/audio_decode.d.ts +46 -0
- package/batteries/media/engines/audio_decode.mjs +90 -0
- package/batteries/media/engines/audio_decode.mjs.map +1 -0
- package/batteries/media/engines/execa_executor.cjs +64 -0
- package/batteries/media/engines/execa_executor.cjs.map +1 -0
- package/batteries/media/engines/execa_executor.d.ts +54 -0
- package/batteries/media/engines/execa_executor.mjs +62 -0
- package/batteries/media/engines/execa_executor.mjs.map +1 -0
- package/batteries/media/engines/fs_workspace.cjs +84 -0
- package/batteries/media/engines/fs_workspace.cjs.map +1 -0
- package/batteries/media/engines/fs_workspace.d.ts +51 -0
- package/batteries/media/engines/fs_workspace.mjs +82 -0
- package/batteries/media/engines/fs_workspace.mjs.map +1 -0
- package/batteries/media/engines/jimp.cjs +116 -0
- package/batteries/media/engines/jimp.cjs.map +1 -0
- package/batteries/media/engines/jimp.d.ts +32 -0
- package/batteries/media/engines/jimp.mjs +114 -0
- package/batteries/media/engines/jimp.mjs.map +1 -0
- package/batteries/media/engines/sharp.cjs +120 -0
- package/batteries/media/engines/sharp.cjs.map +1 -0
- package/batteries/media/engines/sharp.d.ts +42 -0
- package/batteries/media/engines/sharp.mjs +117 -0
- package/batteries/media/engines/sharp.mjs.map +1 -0
- package/batteries/media/engines/soffice.cjs +246 -0
- package/batteries/media/engines/soffice.cjs.map +1 -0
- package/batteries/media/engines/soffice.d.ts +39 -0
- package/batteries/media/engines/soffice.mjs +244 -0
- package/batteries/media/engines/soffice.mjs.map +1 -0
- package/batteries/media/engines/tesseract_js.cjs +87 -0
- package/batteries/media/engines/tesseract_js.cjs.map +1 -0
- package/batteries/media/engines/tesseract_js.d.ts +41 -0
- package/batteries/media/engines/tesseract_js.mjs +85 -0
- package/batteries/media/engines/tesseract_js.mjs.map +1 -0
- package/batteries/media/engines/transformers_asr.cjs +111 -0
- package/batteries/media/engines/transformers_asr.cjs.map +1 -0
- package/batteries/media/engines/transformers_asr.d.ts +41 -0
- package/batteries/media/engines/transformers_asr.mjs +109 -0
- package/batteries/media/engines/transformers_asr.mjs.map +1 -0
- package/batteries/media/exceptions.d.ts +103 -0
- package/batteries/media/forge.cjs +403 -0
- package/batteries/media/forge.cjs.map +1 -0
- package/batteries/media/forge.d.ts +90 -0
- package/batteries/media/forge.mjs +399 -0
- package/batteries/media/forge.mjs.map +1 -0
- package/batteries/media/formats.d.ts +72 -0
- package/batteries/media/index.d.ts +136 -0
- package/batteries/media/lint.cjs +339 -0
- package/batteries/media/lint.cjs.map +1 -0
- package/batteries/media/lint.d.ts +117 -0
- package/batteries/media/lint.mjs +331 -0
- package/batteries/media/lint.mjs.map +1 -0
- package/batteries/media/pipe.d.ts +66 -0
- package/batteries/media/plan.d.ts +133 -0
- package/batteries/media/registry.d.ts +92 -0
- package/batteries/media/runtime.d.ts +105 -0
- package/batteries/media/steps/doc.d.ts +33 -0
- package/batteries/media/steps/image_audio.d.ts +24 -0
- package/batteries/media/steps/ingest.d.ts +25 -0
- package/batteries/media/steps/pages.d.ts +18 -0
- package/batteries/media/steps/sheet.d.ts +36 -0
- package/batteries/media/steps/slides.d.ts +35 -0
- package/batteries/media/steps/text.d.ts +43 -0
- package/batteries/media/validate.d.ts +49 -0
- package/batteries/media/verbs.d.ts +126 -0
- package/batteries/media.cjs +3049 -0
- package/batteries/media.cjs.map +1 -0
- package/batteries/media.mjs +3009 -0
- package/batteries/media.mjs.map +1 -0
- package/batteries/tools/_shared/index.d.ts +142 -0
- package/batteries/tools/_shared.cjs +173 -0
- package/batteries/tools/_shared.cjs.map +1 -0
- package/batteries/tools/_shared.mjs +164 -0
- package/batteries/tools/_shared.mjs.map +1 -0
- package/batteries/tools/index.d.ts +2 -0
- package/batteries/tools/scrapper/exceptions.d.ts +21 -0
- package/batteries/tools/scrapper/index.d.ts +172 -0
- package/batteries/tools/scrapper/shared.d.ts +146 -0
- package/batteries/tools/scrapper.cjs +8 -0
- package/batteries/tools/scrapper.mjs +2 -0
- package/batteries/tools/searxng/index.d.ts +54 -20
- package/batteries/tools/searxng.cjs +2 -1
- package/batteries/tools/searxng.mjs +2 -2
- package/batteries/tools/web_retrieval/index.d.ts +186 -0
- package/batteries/tools/web_retrieval.cjs +206 -0
- package/batteries/tools/web_retrieval.cjs.map +1 -0
- package/batteries/tools/web_retrieval.mjs +201 -0
- package/batteries/tools/web_retrieval.mjs.map +1 -0
- package/batteries/tools.cjs +13 -1
- package/batteries/tools.mjs +4 -2
- package/batteries.cjs +13 -1
- package/batteries.mjs +4 -2
- package/common.d.ts +1 -1
- package/eslint.cjs +1 -1
- package/eslint.mjs +1 -1
- package/exceptions-C7FSHEnV.mjs +87 -0
- package/exceptions-C7FSHEnV.mjs.map +1 -0
- package/exceptions-CQi_lNs1.js +152 -0
- package/exceptions-CQi_lNs1.js.map +1 -0
- package/index.cjs +2 -2
- package/index.mjs +2 -2
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +301 -178
- package/scrapper-BOLWYGbD.js +463 -0
- package/scrapper-BOLWYGbD.js.map +1 -0
- package/scrapper-hDKlNuCT.mjs +433 -0
- package/scrapper-hDKlNuCT.mjs.map +1 -0
- package/{searxng-Bkrwhwhw.js → searxng-CJtEpa8p.js} +82 -85
- package/searxng-CJtEpa8p.js.map +1 -0
- package/{searxng-CyA-nEu5.mjs → searxng-riarj_0u.mjs} +76 -85
- package/searxng-riarj_0u.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +2 -2
- package/validate-BFaUYHDN.js +1298 -0
- package/validate-BFaUYHDN.js.map +1 -0
- package/validate-DSZ3wicB.mjs +1215 -0
- package/validate-DSZ3wicB.mjs.map +1 -0
- package/searxng-Bkrwhwhw.js.map +0 -1
- package/searxng-CyA-nEu5.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-DSZ3wicB.mjs","names":[],"sources":["../src/batteries/media/plan.ts","../src/batteries/media/verbs.ts","../src/batteries/media/validate.ts"],"sourcesContent":["/**\n * The neutral `MediaPlan` intermediate representation and its canonical serializers.\n *\n * @remarks\n * Internal sibling of the `@nhtio/adk/batteries/media` entry. All three front-ends — the\n * chainable builder, the pipe-string parser, and the JSON ops array — compile to this one IR,\n * and the step runtime consumes only this IR. Invariants (frozen design, section 0.7):\n *\n * - **Serializable.** No live `RegExp`, `Media`, or function values — regexes are\n * `{ source, flags }`, media refs are typed handles. A plan can be logged, content-hashed,\n * and embedded in a tool result.\n * - **Round-trip is fixed-point.** `parsePipe(toPipe(plan))` produces an equal plan and\n * `toPipe` is idempotent. `toPipe(parsePipe(s)) === s` is NOT promised (e.g. `2,3,4,5`\n * renders as `2-5`).\n * - **Engine-agnostic.** Steps name verbs, never engines.\n */\n\nimport { isObject } from '@nhtio/adk/guards'\nimport { E_MEDIA_NOT_PIPE_EXPRESSIBLE } from './exceptions'\n\n/**\n * A serializable regex reference. Never a live `RegExp` in the IR.\n */\nexport interface RegExpRef {\n /** The regex source, exactly as `RegExp.prototype.source` would report it. */\n source: string\n /** Sorted flag characters (canonicalized — `gi`, never `ig`). */\n flags: string\n}\n\n/**\n * A reference to another media participating in a multi-input verb (`merge`, `diff`,\n * `apply_patch`, `slides.update_image`).\n *\n * @remarks\n * The `id` variant is the canonical model-facing form — the pipe syntax is an inline\n * `@id` token (`merge with=@018f…`) and the ops form carries the same id. The `builder`\n * variant is implementor-only (a nested chain: `mp(a).diff(mp(b).convert('txt'))`) and is\n * not expressible in a flat pipe string.\n */\nexport type MediaRef = { kind: 'id'; id: string } | { kind: 'builder'; plan: MediaPlan }\n\n/** Scalar arg values the flat pipe grammar can express directly. */\nexport type MediaArgScalar = string | number | boolean | RegExpRef | MediaRef\n\n/**\n * A structured (JSON-shaped) arg value. In the pipe surface these are written as quoted JSON\n * (`updates='[{\"address\":\"B2\",\"value\":3}]'`); in ops they are plain JSON. `null` is legal only\n * inside structured values (cell values), never as a top-level scalar.\n */\nexport type MediaArgJson =\n | string\n | number\n | boolean\n | null\n | MediaArgJson[]\n | { [key: string]: MediaArgJson }\n\n/**\n * The value space of a single verb arg in the IR.\n *\n * @remarks\n * Flat lists (`types=image,font` → `['image','font']`) are `MediaArgScalar[]`. Whether a\n * value parsed from quoted JSON or a flat token is decided by the verb's arg schema — the IR\n * stores the final shape only.\n */\nexport type MediaArgValue = MediaArgScalar | MediaArgScalar[] | MediaArgJson\n\n/** Source span carried by steps parsed from a pipe string, for error mapping. */\nexport interface SourceSpan {\n /** Zero-based character offset into the source string. */\n offset: number\n /** One-based line number. */\n line: number\n /** One-based column number. */\n col: number\n /** Length of the spanned text in characters. */\n length: number\n}\n\n/** One transform step: a canonical verb id plus its validated content args. */\nexport interface MediaStep {\n /**\n * Canonical verb id — dot-namespaced snake_case (`convert`, `select`, `extract.text`,\n * `sheet.update_cells`, `image.resize`).\n */\n verb: string\n /** Validated content args for this verb. */\n args: Record<string, MediaArgValue>\n /** Present when the step came from a pipe string; absent for builder/ops origins. */\n span?: SourceSpan\n}\n\n/** The neutral plan: an ordered, linear list of steps. No branching. */\nexport interface MediaPlan {\n /** The ordered transform steps. */\n steps: MediaStep[]\n}\n\n/** The JSON ops front-end's step shape — identical to {@link MediaStep} minus the span. */\nexport interface MediaOp {\n /** The canonical (or foldable) verb id. */\n verb: string\n /** The verb's named args. */\n args: Record<string, MediaArgValue>\n}\n\n// ── guards ───────────────────────────────────────────────────────────────────\n\n/** `true` when `value` is a {@link RegExpRef}. */\nexport const isRegExpRef = (value: unknown): value is RegExpRef => {\n if (!isObject(value)) return false\n const v = value as Record<string, unknown>\n return typeof v.source === 'string' && typeof v.flags === 'string' && Object.keys(v).length === 2\n}\n\n/** `true` when `value` is a {@link MediaRef}. */\nexport const isMediaRef = (value: unknown): value is MediaRef => {\n if (!isObject(value)) return false\n const v = value as MediaRef\n if (v.kind === 'id') return typeof (v as { id?: unknown }).id === 'string'\n if (v.kind === 'builder') return isObject((v as { plan?: unknown }).plan)\n return false\n}\n\n// ── canonical rendering helpers ──────────────────────────────────────────────\n\n/** Characters legal in an unquoted bareword value. */\nconst BAREWORD = /^[A-Za-z0-9_]+$/\n/** Strings that would lex as a non-ident token and therefore must be quoted. */\nconst LEXES_AS_OTHER = /^(?:\\d+(?:-\\d+)?|\\d+\\.\\d+|true|false|@.*)$/\n\n/**\n * The frozen quoting predicate: quote any string that is empty, would lex as a number, range,\n * boolean, or `@id` token, starts with `/`, or contains a character outside `[A-Za-z0-9_]`.\n */\nconst renderString = (s: string): string => {\n if (s.length === 0 || !BAREWORD.test(s) || LEXES_AS_OTHER.test(s) || s.startsWith('/')) {\n return `\"${s.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n')}\"`\n }\n return s\n}\n\n/** Canonicalize regex flags: validate against JS flags and sort. */\nexport const canonicalFlags = (flags: string): string => Array.from(flags).sort().join('')\n\n/** Render a {@link RegExpRef} back to a pipe regex literal, re-escaping bare slashes. */\nconst renderRegExp = (ref: RegExpRef): string => {\n const source = ref.source.length === 0 ? '(?:)' : ref.source\n // Escape bare `/` that are not already escaped and not inside a character class.\n let out = ''\n let inClass = false\n for (let i = 0; i < source.length; i++) {\n const ch = source[i]\n if (ch === '\\\\') {\n out += ch + (source[i + 1] ?? '')\n i++\n continue\n }\n if (ch === '[') inClass = true\n else if (ch === ']') inClass = false\n if (ch === '/' && !inClass) {\n out += '\\\\/'\n continue\n }\n out += ch\n }\n return `/${out}/${canonicalFlags(ref.flags)}`\n}\n\n/**\n * Compress maximal ascending consecutive runs in a number list to `a-b` range tokens.\n * Order-preserving and lossless on the array; never sorts or dedupes.\n */\nconst renderNumberList = (nums: number[]): string => {\n const parts: string[] = []\n let i = 0\n while (i < nums.length) {\n let j = i\n while (\n j + 1 < nums.length &&\n Number.isInteger(nums[j]) &&\n nums[j + 1] === (nums[j] as number) + 1\n ) {\n j++\n }\n if (j - i >= 1 && Number.isInteger(nums[i])) {\n parts.push(`${nums[i]}-${nums[j]}`)\n } else {\n parts.push(String(nums[i]))\n j = i\n }\n i = j + 1\n }\n return parts.join(',')\n}\n\nconst renderScalar = (value: MediaArgScalar): string => {\n if (typeof value === 'number') return String(value)\n if (typeof value === 'boolean') return String(value)\n if (typeof value === 'string') return renderString(value)\n if (isRegExpRef(value)) return renderRegExp(value)\n // MediaRef\n if (value.kind === 'id') return `@${value.id}`\n throw new E_MEDIA_NOT_PIPE_EXPRESSIBLE(['nested builder refs have no pipe form; use toOps()'])\n}\n\nconst isScalar = (value: MediaArgValue): value is MediaArgScalar =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n isRegExpRef(value) ||\n isMediaRef(value)\n\nconst renderValue = (value: MediaArgValue): string => {\n if (value === null) {\n // null is only legal inside structured JSON values\n throw new E_MEDIA_NOT_PIPE_EXPRESSIBLE(['null is not a flat pipe value; use toOps()'])\n }\n if (Array.isArray(value)) {\n const arr = value as MediaArgScalar[]\n if (arr.length > 0 && arr.every((v) => typeof v === 'number')) {\n return renderNumberList(arr as number[])\n }\n if (arr.every(isScalar)) {\n return arr.map(renderScalar).join(',')\n }\n // structured (nested) array -> quoted JSON\n return `'${JSON.stringify(value)}'`\n }\n if (isScalar(value)) return renderScalar(value)\n // structured object -> quoted JSON\n return `'${JSON.stringify(value)}'`\n}\n\n/**\n * Render a {@link MediaPlan} to its canonical pipe string.\n *\n * @remarks\n * Total for every plan except those containing builder-variant media refs, which throw\n * {@link E_MEDIA_NOT_PIPE_EXPRESSIBLE}. Structured args render as quoted JSON. The output is\n * canonical: dot-namespaced verbs render as space-separated words, number runs compress to\n * ranges, strings quote per the frozen predicate.\n *\n * @param plan - The plan to render.\n * @returns The canonical pipe expression.\n */\nexport const toPipe = (plan: MediaPlan): string =>\n plan.steps\n .map((step) => {\n const verb = step.verb.replace(/\\./g, ' ')\n const args = Object.entries(step.args)\n .map(([k, v]) => `${k}=${renderValue(v)}`)\n .join(' ')\n return args.length > 0 ? `${verb} ${args}` : verb\n })\n .join(' | ')\n\n/**\n * Render a {@link MediaPlan} to its JSON ops array. Total — every plan has an ops form.\n *\n * @param plan - The plan to render.\n * @returns The ops array (spans stripped).\n */\nexport const toOps = (plan: MediaPlan): MediaOp[] =>\n plan.steps.map((step) => ({ verb: step.verb, args: step.args }))\n\n/**\n * Build a {@link MediaPlan} from a JSON ops array. The inverse of {@link toOps}.\n *\n * @remarks\n * Performs structural normalization only (verb-id folding via the caller's verb table happens\n * in validation, not here). Steps carry no spans.\n *\n * @param ops - The ops array.\n * @returns The equivalent plan.\n */\nexport const fromOps = (ops: MediaOp[]): MediaPlan => ({\n steps: ops.map((op) => ({ verb: op.verb, args: op.args })),\n})\n","/**\n * The canonical verb table: every verb the media DSL knows, with arg schemas, engine\n * requirements, format-family applicability, and output kinds.\n *\n * @remarks\n * Internal sibling of the `@nhtio/adk/batteries/media` entry. This table is the single source\n * of truth consumed by:\n *\n * - the pipe parser's semantic validator (unknown-verb/arg detection, did-you-mean),\n * - the plan compiler (arg coercion + constraint checks),\n * - the engine-narrowing pass (which verbs a deployment advertises),\n * - the forge (generating the `media_query` tool description and few-shot examples),\n * - the builder (typed front-end methods map 1:1 onto entries here).\n *\n * Frozen design decisions (design doc section 0): canonical verb ids are dot-namespaced\n * snake_case; verb matching is separator-insensitive (space/`_`/`.` fold); args are named-only;\n * indices are 1-based everywhere; arg names follow one-meaning-one-name (`to`, `with`, `match`,\n * `replace`, `order`, `pages`, `at`).\n */\n\nimport { PCM_MIME } from './contracts'\n\n/** The value type of a single declared arg. */\nexport type VerbArgType =\n | 'string'\n | 'number'\n | 'boolean'\n | 'enum'\n | 'number-list'\n | 'string-list'\n | 'regex-or-string-list'\n | 'name-or-index'\n | 'media-ref'\n | 'media-ref-list'\n | 'json'\n\n/** Declaration of one named arg on a verb. */\nexport interface VerbArgSpec {\n /** The arg's value type. */\n type: VerbArgType\n /** Whether the statement must supply this arg. */\n required?: boolean\n /** Legal values when `type === 'enum'` (or per-element for list types). */\n values?: readonly string[]\n /** Inclusive minimum for numbers / per-element for number lists. */\n min?: number\n /** Inclusive maximum for numbers / per-element for number lists. */\n max?: number\n /** Model-facing description used in generated tool grammar text. */\n description: string\n}\n\n/**\n * A verb's capability requirement against the deployment's engine registry. Verbs with no\n * requirement are always advertised; input-conditional engine needs (e.g. `extract.text`\n * needing OCR only for images) stay runtime checks inside the step implementation.\n */\nexport type VerbRequirement =\n | { capability: 'convert'; from?: string; to?: string }\n | { capability: 'mutate' }\n\n/** Broad input families used for verb-applicability checks. */\nexport type FormatFamily =\n | 'document' // pdf/docx/odt/rtf/txt/md/html...\n | 'spreadsheet' // xlsx/ods/xls/csv\n | 'presentation' // pptx/odp/ppt\n | 'image'\n | 'audio'\n | 'any'\n\n/** What awaiting a chain ending in this verb resolves to. */\nexport type VerbOutput = 'media' | 'media-list' | 'text' | 'json'\n\n/** One verb table entry. */\nexport interface VerbSpec {\n /** Canonical id: dot-namespaced snake_case (`extract.text`, `sheet.update_cells`). */\n id: string\n /** Model-facing one-line description. */\n description: string\n /** Named args (named-only grammar; no positionals). */\n args: Record<string, VerbArgSpec>\n /**\n * Capability the verb always requires, if any — gates whether the verb is advertised and\n * accepted under a given engine configuration. Input-conditional needs are handled (and\n * error-messaged) by the step implementation at runtime.\n */\n requires?: VerbRequirement\n /** Input families the verb applies to. */\n appliesTo: readonly FormatFamily[]\n /** Output kind. May be refined by an `out`-style arg (documented per verb). */\n output: VerbOutput\n}\n\n/** Conversion targets supported by `convert` (matches the server's enum exactly). */\nexport const CONVERT_TARGETS = [\n 'pdf',\n 'html',\n 'txt',\n 'md',\n 'csv',\n 'json',\n 'docx',\n 'doc',\n 'rtf',\n 'odt',\n 'xlsx',\n 'xls',\n 'ods',\n 'pptx',\n 'ppt',\n 'odp',\n] as const\n\n/** Image output formats supported by `image.format`. */\nexport const IMAGE_FORMATS = ['png', 'jpg', 'jpeg', 'webp', 'tiff', 'avif'] as const\n\n/** The canonical verb table. Order is presentation order in generated grammar text. */\nexport const VERBS: readonly VerbSpec[] = [\n // ── root: document transforms ──────────────────────────────────────────────\n {\n id: 'convert',\n description: 'Convert the media to another format.',\n args: {\n to: {\n type: 'enum',\n required: true,\n values: CONVERT_TARGETS,\n description: 'Target format.',\n },\n },\n requires: { capability: 'convert' },\n appliesTo: ['document', 'spreadsheet', 'presentation'],\n output: 'media',\n },\n {\n id: 'select',\n description: 'Keep only the listed pages/slides/sections (1-based), producing one file.',\n args: {\n pages: {\n type: 'number-list',\n required: true,\n min: 1,\n description: 'Pages (or slides/sections) to keep, 1-based. Ranges allowed: 2-5,8.',\n },\n },\n appliesTo: ['document', 'presentation'],\n output: 'media',\n },\n {\n id: 'split',\n description: 'Split the media into multiple files by page or section.',\n args: {\n by: {\n type: 'enum',\n values: ['page', 'section'],\n description: 'Split unit. Default: page.',\n },\n ranges: {\n type: 'json',\n description:\n \"Explicit grouping as a JSON array of [start,end] pairs (1-based), e.g. '[[1,3],[5,7]]'.\",\n },\n },\n appliesTo: ['document', 'presentation'],\n output: 'media-list',\n },\n {\n id: 'merge',\n description: 'Merge other media into this one, in order.',\n args: {\n with: {\n type: 'media-ref-list',\n required: true,\n description: 'Other media to append, as @id refs: with=@<media id>,@<media id>.',\n },\n },\n appliesTo: ['document', 'presentation'],\n output: 'media',\n },\n {\n id: 'reorder',\n description: 'Reorder pages/slides/sections by the given 1-based index order.',\n args: {\n order: {\n type: 'number-list',\n required: true,\n min: 1,\n description: 'New order of existing 1-based indices.',\n },\n },\n appliesTo: ['document', 'presentation'],\n output: 'media',\n },\n {\n id: 'redact',\n description: 'Redact matching text. Prefer literal strings; /regex/ is supported.',\n args: {\n match: {\n type: 'regex-or-string-list',\n required: true,\n description: 'Literal string(s) or a /regex/ to redact.',\n },\n replace: {\n type: 'string',\n description: 'Replacement text. Default: blackout/removal.',\n },\n },\n appliesTo: ['document', 'spreadsheet', 'presentation'],\n output: 'media',\n },\n {\n id: 'sanitize',\n description: 'Remove potentially unsafe embedded content from the media.',\n args: {},\n appliesTo: ['document', 'spreadsheet', 'presentation'],\n output: 'media',\n },\n {\n id: 'normalize',\n description: 'Normalize the media structure/encoding for downstream consistency.',\n args: {},\n appliesTo: ['document', 'spreadsheet', 'presentation'],\n output: 'media',\n },\n {\n id: 'update_text',\n description: 'Replace the first occurrence of an anchor text.',\n args: {\n anchor: {\n type: 'string',\n required: true,\n description: 'Existing text to find.',\n },\n replace: {\n type: 'string',\n required: true,\n description: 'Replacement text (empty string deletes).',\n },\n },\n appliesTo: ['document', 'presentation'],\n output: 'media',\n },\n {\n id: 'diff',\n description: 'Compare this media against another; returns a structured diff.',\n args: {\n with: {\n type: 'media-ref',\n required: true,\n description: 'The media to compare against, as an @id ref.',\n },\n },\n appliesTo: ['document', 'spreadsheet', 'presentation'],\n output: 'json',\n },\n {\n id: 'apply_patch',\n description: 'Apply a unified-diff patch to the media text.',\n args: {\n patch: {\n type: 'string',\n required: true,\n description: 'The unified diff content.',\n },\n with: {\n type: 'media-ref-list',\n description: 'Optional additional context media, as @id refs.',\n },\n },\n appliesTo: ['document'],\n output: 'media',\n },\n // ── root: extraction ────────────────────────────────────────────────────────\n {\n id: 'extract.text',\n description:\n 'Extract text from any supported media (document, spreadsheet, image). To limit pages: select pages=… | extract text.',\n args: {\n ocr: {\n type: 'enum',\n values: ['off', 'auto', 'force'],\n description: 'OCR behavior. Default auto (OCR only when there is no text layer).',\n },\n ocr_out: {\n type: 'enum',\n values: ['txt', 'hocr', 'json'],\n description: 'OCR output structure when OCR runs. Default txt.',\n },\n lang: {\n type: 'string-list',\n description: 'OCR language hint(s), e.g. lang=eng,deu. Quote tags with dashes.',\n },\n },\n appliesTo: ['document', 'spreadsheet', 'presentation', 'image'],\n output: 'text',\n },\n {\n id: 'extract.metadata',\n description: 'Extract document metadata (author, dates, page count) as JSON.',\n args: {},\n appliesTo: ['document', 'spreadsheet', 'presentation', 'image', 'audio'],\n output: 'json',\n },\n {\n id: 'extract.assets',\n description: 'Extract embedded assets (images, fonts, attachments) as separate media.',\n args: {\n types: {\n type: 'string-list',\n values: ['image', 'font', 'attachment', 'all'],\n description: 'Asset kinds to extract. Default all.',\n },\n format: {\n type: 'enum',\n values: IMAGE_FORMATS,\n description:\n 'Re-encode extracted images to this format. Default: native encoding as stored.',\n },\n },\n appliesTo: ['document', 'presentation', 'spreadsheet'],\n output: 'media-list',\n },\n {\n id: 'chunk',\n description: 'Split extracted text into chunks for retrieval/indexing.',\n args: {\n by: {\n type: 'enum',\n values: ['sentence', 'paragraph', 'fixed'],\n description: 'Chunking strategy. Default paragraph.',\n },\n size: {\n type: 'number',\n min: 1,\n description: 'Chunk size for fixed strategy / max size otherwise.',\n },\n overlap: {\n type: 'number',\n min: 0,\n description: 'Overlap between consecutive chunks.',\n },\n },\n appliesTo: ['document', 'any'],\n output: 'json',\n },\n // ── sheet namespace ─────────────────────────────────────────────────────────\n {\n id: 'sheet.add_rows',\n description: 'Insert rows into a worksheet.',\n args: {\n sheet: {\n type: 'name-or-index',\n description: 'Target worksheet: bare number = 1-based index, quoted string = name.',\n },\n rows: {\n type: 'json',\n required: true,\n description: 'Rows as a JSON array of arrays of cell values, e.g. \\'[[\"a\",1],[\"b\",2]]\\'.',\n },\n before: { type: 'number', min: 1, description: 'Insert before this 1-based row.' },\n after: { type: 'number', min: 1, description: 'Insert after this 1-based row.' },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.add_columns',\n description: 'Insert columns into a worksheet.',\n args: {\n sheet: { type: 'name-or-index', description: 'Target worksheet (index or quoted name).' },\n headers: {\n type: 'string-list',\n description: 'Header names for the new columns (values empty).',\n },\n columns: {\n type: 'json',\n description: 'Full column descriptors as JSON: \\'[{\"header\":\"X\",\"values\":[1,2]}]\\'.',\n },\n before: { type: 'number', min: 1, description: 'Insert before this 1-based column.' },\n after: { type: 'number', min: 1, description: 'Insert after this 1-based column.' },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.update_cells',\n description: 'Update specific cells.',\n args: {\n sheet: { type: 'name-or-index', description: 'Target worksheet (index or quoted name).' },\n updates: {\n type: 'json',\n required: true,\n description:\n 'JSON array of updates: \\'[{\"address\":\"B2\",\"value\":42}]\\' or \\'[{\"row\":2,\"col\":3,\"value\":\"x\"}]\\'.',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.delete_rows',\n description: 'Delete rows by 1-based index.',\n args: {\n sheet: { type: 'name-or-index', description: 'Target worksheet (index or quoted name).' },\n rows: {\n type: 'number-list',\n required: true,\n min: 1,\n description: '1-based row indices to delete.',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.delete_columns',\n description: 'Delete columns by 1-based index.',\n args: {\n sheet: { type: 'name-or-index', description: 'Target worksheet (index or quoted name).' },\n columns: {\n type: 'number-list',\n required: true,\n min: 1,\n description: '1-based column indices to delete.',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.rename_sheet',\n description: 'Rename a worksheet. The target must be a sheet NAME (quote it).',\n args: {\n sheet: {\n type: 'string',\n required: true,\n description: 'Current sheet name (names only for rename; quote it).',\n },\n to: { type: 'string', required: true, description: 'New sheet name.' },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.add_sheet',\n description: 'Add a new worksheet.',\n args: {\n name: { type: 'string', required: true, description: 'Name for the new worksheet.' },\n at: { type: 'number', min: 1, description: 'Insert at this 1-based position.' },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.remove_sheet',\n description: 'Remove a worksheet. The target must be a sheet NAME (quote it).',\n args: {\n sheet: {\n type: 'string',\n required: true,\n description: 'Sheet name to remove (names only; quote it).',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.reorder_sheets',\n description: 'Reorder worksheets.',\n args: {\n order: {\n type: 'json',\n required: true,\n description:\n 'JSON array of sheet names and/or 1-based indices in the new order: \\'[\"Summary\",2,3]\\'.',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n {\n id: 'sheet.transform_table',\n description: 'Rename/select/drop table columns by header name.',\n args: {\n sheet: { type: 'name-or-index', description: 'Target worksheet (index or quoted name).' },\n header_row: { type: 'number', min: 1, description: '1-based header row. Default 1.' },\n select: { type: 'string-list', description: 'Column headers to keep.' },\n drop: { type: 'string-list', description: 'Column headers to drop.' },\n rename: {\n type: 'json',\n description: 'JSON array of renames: \\'[{\"from\":\"Old\",\"to\":\"New\"}]\\'.',\n },\n },\n appliesTo: ['spreadsheet'],\n output: 'media',\n },\n // ── slides namespace ────────────────────────────────────────────────────────\n {\n id: 'slides.add',\n description: 'Add a new slide.',\n args: {\n at: { type: 'number', min: 1, description: 'Insert at this 1-based position.' },\n title: { type: 'string', description: 'Title text for the new slide.' },\n layout: { type: 'string', description: 'Layout name (template-dependent).' },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.update_text',\n description: 'Update text on a slide.',\n args: {\n slide: {\n type: 'name-or-index',\n description: 'Target slide: bare number = 1-based index, quoted string = title.',\n },\n placeholder: { type: 'string', description: 'Placeholder/shape to target.' },\n text: { type: 'string', required: true, description: 'Replacement text.' },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.update_table',\n description: 'Update table cells on a slide.',\n args: {\n slide: { type: 'name-or-index', description: 'Target slide (index or quoted title).' },\n updates: {\n type: 'json',\n required: true,\n description: 'JSON array: \\'[{\"row\":1,\"col\":2,\"value\":\"x\"}]\\' (1-based).',\n },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.update_image',\n description: 'Replace an image on a slide with another media.',\n args: {\n slide: { type: 'name-or-index', description: 'Target slide (index or quoted title).' },\n placeholder: { type: 'string', description: 'Placeholder/shape to target.' },\n with: {\n type: 'media-ref',\n required: true,\n description: 'The replacement image, as an @id ref.',\n },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.update_chart',\n description: 'Update chart data on a slide.',\n args: {\n slide: { type: 'name-or-index', description: 'Target slide (index or quoted title).' },\n data: {\n type: 'json',\n description: 'JSON array-of-arrays of chart data: \\'[[\"Q1\",10],[\"Q2\",20]]\\'.',\n },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.delete',\n description: 'Delete slides by 1-based index.',\n args: {\n slides: {\n type: 'number-list',\n required: true,\n min: 1,\n description: '1-based slide indices to delete.',\n },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.reorder',\n description: 'Reorder slides.',\n args: {\n order: {\n type: 'number-list',\n required: true,\n min: 1,\n description: 'New order of existing 1-based slide indices.',\n },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n {\n id: 'slides.duplicate',\n description: 'Duplicate a slide.',\n args: {\n slide: { type: 'number', required: true, min: 1, description: '1-based slide to copy.' },\n at: { type: 'number', min: 1, description: 'Insert the copy at this position.' },\n },\n appliesTo: ['presentation'],\n output: 'media',\n },\n // ── image namespace (split verbs; runtime fuses adjacent image.* steps) ─────\n {\n id: 'image.resize',\n description: 'Resize the image.',\n args: {\n width: { type: 'number', min: 1, max: 16384, description: 'Target width in px.' },\n height: { type: 'number', min: 1, max: 16384, description: 'Target height in px.' },\n fit: {\n type: 'enum',\n values: ['cover', 'contain', 'fill', 'inside', 'outside'],\n description: 'Resize fit mode. Default cover.',\n },\n },\n requires: { capability: 'mutate' },\n appliesTo: ['image'],\n output: 'media',\n },\n {\n id: 'image.format',\n description: 'Re-encode the image to another format.',\n args: {\n to: {\n type: 'enum',\n required: true,\n values: IMAGE_FORMATS,\n description: 'Target image format.',\n },\n quality: { type: 'number', min: 1, max: 100, description: 'Quality for lossy formats.' },\n strip_metadata: {\n type: 'boolean',\n description: 'Remove EXIF/ICC metadata from the output.',\n },\n },\n requires: { capability: 'mutate' },\n appliesTo: ['image'],\n output: 'media',\n },\n {\n id: 'image.rotate',\n description: 'Rotate the image.',\n args: {\n deg: {\n type: 'enum',\n required: true,\n values: ['90', '180', '270'],\n description: 'Rotation in degrees (clockwise).',\n },\n },\n requires: { capability: 'mutate' },\n appliesTo: ['image'],\n output: 'media',\n },\n {\n id: 'image.flip',\n description: 'Flip the image.',\n args: {\n axis: {\n type: 'enum',\n required: true,\n values: ['horizontal', 'vertical', 'both'],\n description: 'Flip axis.',\n },\n },\n requires: { capability: 'mutate' },\n appliesTo: ['image'],\n output: 'media',\n },\n {\n id: 'image.strip_metadata',\n description: 'Remove EXIF/ICC metadata from the image without other changes.',\n args: {},\n requires: { capability: 'mutate' },\n appliesTo: ['image'],\n output: 'media',\n },\n // ── audio namespace ─────────────────────────────────────────────────────────\n {\n id: 'audio.transcribe',\n description: 'Transcribe speech to text.',\n args: {\n lang: {\n type: 'string',\n description: 'Language hint, e.g. lang=en. Quote tags with dashes: lang=\"en-US\".',\n },\n out: {\n type: 'enum',\n values: ['txt', 'srt', 'vtt', 'json'],\n description: 'Output format. Default txt. srt/vtt produce subtitles.',\n },\n translate: {\n type: 'boolean',\n description: 'Translate the transcription to English.',\n },\n },\n requires: { capability: 'convert', from: PCM_MIME },\n appliesTo: ['audio'],\n output: 'text',\n },\n] as const\n\n/** Map of canonical verb id → spec, for direct lookup. */\nexport const VERB_INDEX: ReadonlyMap<string, VerbSpec> = new Map(VERBS.map((v) => [v.id, v]))\n\n/**\n * Fold a verb token sequence to canonical form: lowercase, separators (space/`_`/`.`)\n * normalized so `extract_text` ≡ `extract text` ≡ `extract.text` all match `extract.text`.\n *\n * @param words - The verb word tokens as written (1 or 2 words, possibly containing `_`/`.`).\n * @returns The canonical verb id when a fold-match exists, otherwise `undefined`.\n */\nexport const foldVerb = (words: string[]): string | undefined => {\n const flat = words\n .join(' ')\n .toLowerCase()\n .replace(/[._\\s]+/g, ' ')\n .trim()\n return FOLDED_INDEX.get(flat)\n}\n\n/** Internal: folded \"word word\" form → canonical id. */\nconst FOLDED_INDEX: ReadonlyMap<string, string> = (() => {\n const map = new Map<string, string>()\n for (const v of VERBS) {\n const folded = v.id.replace(/[._]+/g, ' ')\n if (map.has(folded)) {\n throw new Error(`verb table invariant violated: \"${folded}\" folds to multiple verbs`)\n }\n map.set(folded, v.id)\n }\n return map\n})()\n\n/**\n * All folded verb word-sequences, for the parser's longest-match verb recognition and for\n * generated grammar text.\n */\nexport const FOLDED_VERBS: readonly string[] = Array.from(FOLDED_INDEX.keys())\n\n/**\n * Suggest the nearest verbs to an unknown input, for did-you-mean errors. Matches whole folded\n * forms AND suffix words (`resize` suggests `image resize`), per the frozen error model.\n *\n * @param input - The unknown verb text as written.\n * @param candidates - The folded verb forms to search (pass the narrowed set to avoid\n * suggesting unconfigured verbs).\n * @returns Up to three suggestions, best first.\n */\nexport const suggestVerbs = (input: string, candidates: readonly string[]): string[] => {\n const folded = input\n .toLowerCase()\n .replace(/[._\\s]+/g, ' ')\n .trim()\n const scored: Array<{ name: string; score: number }> = []\n for (const cand of candidates) {\n const direct = levenshtein(folded, cand)\n const words = cand.split(' ')\n const suffix = words.length > 1 ? levenshtein(folded, words[words.length - 1]) : Infinity\n const score = Math.min(direct, suffix)\n if (score <= Math.max(2, Math.floor(folded.length / 3))) {\n scored.push({ name: cand, score })\n }\n }\n scored.sort((a, b) => a.score - b.score)\n return scored.slice(0, 3).map((s) => s.name)\n}\n\n/** Classic two-row Levenshtein distance. */\nconst levenshtein = (a: string, b: string): number => {\n if (a === b) return 0\n if (a.length === 0) return b.length\n if (b.length === 0) return a.length\n let prev = Array.from({ length: b.length + 1 }, (_, i) => i)\n let curr = new Array<number>(b.length + 1)\n for (let i = 1; i <= a.length; i++) {\n curr[0] = i\n for (let j = 1; j <= b.length; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1\n curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost)\n }\n ;[prev, curr] = [curr, prev]\n }\n return prev[b.length]\n}\n","/**\n * The semantic validator: checks raw parsed segments (or ops) against the verb table and the\n * deployment's configured engines, producing the validated {@link MediaPlan} or a\n * model-actionable error.\n *\n * @remarks\n * Internal sibling of the `@nhtio/adk/batteries/media` entry. This is the layer no parser\n * toolkit could supply — every error names what was wrong, suggests the nearest valid form,\n * and shows a corrective exemplar (frozen design 0.14). Engine narrowing happens HERE, never\n * at parse time (frozen 0.3): the same string parses identically in every deployment; only\n * validation differs.\n */\n\nimport { isMediaRef, isRegExpRef } from './plan'\nimport { isError, isObject } from '@nhtio/adk/guards'\nimport { VERB_INDEX, suggestVerbs, foldVerb } from './verbs'\nimport {\n E_MEDIA_UNKNOWN_VERB,\n E_MEDIA_UNKNOWN_ARG,\n E_MEDIA_BAD_ARG,\n E_MEDIA_MISSING_ARG,\n E_MEDIA_ENGINE_REQUIRED,\n} from './exceptions'\nimport type { RawSegment, RawArgValue } from './pipe'\nimport type { VerbSpec, VerbArgSpec, VerbRequirement } from './verbs'\nimport type { MediaPlan, MediaStep, MediaArgValue, MediaArgScalar, MediaOp } from './plan'\n\n/**\n * The minimal synchronous capability probe the validator narrows against. The pipeline's\n * engine registry implements it; tests stub it.\n */\nexport interface CapabilityProbe {\n /** `true` when some engine declares a matching convert edge (omit either side for \"any\"). */\n hasConvert(from?: string, to?: string): boolean\n /** `true` when some engine declares a mutate capability. */\n hasMutate(): boolean\n}\n\n/** Options for {@link validateSegments} / {@link validateOps}. */\nexport interface ValidateOptions {\n /** The deployment's capabilities. Narrows advertised verbs + error suggestions. */\n capabilities: CapabilityProbe\n}\n\n/** `true` when the deployment satisfies a verb's capability requirement. */\nconst satisfies = (capabilities: CapabilityProbe, requires: VerbRequirement): boolean =>\n requires.capability === 'mutate'\n ? capabilities.hasMutate()\n : capabilities.hasConvert(requires.from, requires.to)\n\n/** A human phrase for an unmet requirement, for the do-not-retry error. */\nconst requirementText = (requires: VerbRequirement): string => {\n if (requires.capability === 'mutate') return 'an engine that can mutate this media'\n const from = requires.from ? ` from ${requires.from}` : ''\n const to = requires.to ? ` to ${requires.to}` : ''\n return `an engine that can convert${from}${to}`\n}\n\n/** The folded verb forms available under a given capability configuration. */\nexport const availableVerbs = (capabilities: CapabilityProbe): string[] => {\n const out: string[] = []\n for (const [id, spec] of VERB_INDEX) {\n if (spec.requires && !satisfies(capabilities, spec.requires)) continue\n out.push(id.replace(/[._]+/g, ' '))\n }\n return out\n}\n\nconst levSuggest = (verbText: string, capabilities: CapabilityProbe): string => {\n const suggestions = suggestVerbs(verbText, availableVerbs(capabilities))\n return suggestions.length > 0 ? ` did you mean \"${suggestions[0]}\"?` : ''\n}\n\nconst verbList = (capabilities: CapabilityProbe): string => availableVerbs(capabilities).join(', ')\n\nconst resolveVerb = (\n verbText: string,\n capabilities: CapabilityProbe,\n position: number\n): VerbSpec => {\n const canonical = foldVerb(verbText.split(' ')) ?? verbText\n const spec = VERB_INDEX.get(canonical)\n if (!spec) {\n throw new E_MEDIA_UNKNOWN_VERB([\n `unknown verb \"${verbText}\" at segment ${position}.${levSuggest(verbText, capabilities)} Available verbs: ${verbList(capabilities)}`,\n ])\n }\n if (spec.requires && !satisfies(capabilities, spec.requires)) {\n throw new E_MEDIA_ENGINE_REQUIRED([\n `verb \"${verbText}\" requires ${requirementText(spec.requires)}, and none is configured in this deployment. Do not retry this verb here. Available verbs: ${verbList(capabilities)}`,\n ])\n }\n return spec\n}\n\nconst suggestArg = (name: string, spec: VerbSpec): string => {\n const candidates = Object.keys(spec.args)\n const ranked = suggestVerbs(name, candidates)\n return ranked.length > 0 ? ` did you mean \"${ranked[0]}\"?` : ''\n}\n\nconst argList = (spec: VerbSpec): string => {\n const names = Object.keys(spec.args)\n return names.length > 0 ? names.join(', ') : '(none)'\n}\n\nconst exemplar = (spec: VerbSpec): string => {\n const verb = spec.id.replace(/\\./g, ' ')\n const parts: string[] = [verb]\n for (const [name, arg] of Object.entries(spec.args)) {\n if (!arg.required) continue\n parts.push(`${name}=${exampleValue(arg)}`)\n }\n return parts.join(' ')\n}\n\nconst exampleValue = (arg: VerbArgSpec): string => {\n switch (arg.type) {\n case 'enum':\n return arg.values?.[0] ?? 'value'\n case 'number':\n return String(arg.min ?? 1)\n case 'number-list':\n return '1-3,5'\n case 'string-list':\n return 'a,b'\n case 'boolean':\n return 'true'\n case 'regex-or-string-list':\n return '\"literal text\"'\n case 'media-ref':\n return '@<media id>'\n case 'media-ref-list':\n return '@<media id>'\n case 'json':\n return `'[…]'`\n default:\n return '\"value\"'\n }\n}\n\n/** Coerce + check one arg value against its spec. Returns the IR-final value. */\nconst checkArg = (\n verb: VerbSpec,\n name: string,\n raw: { value: MediaArgValue; quoted: boolean }\n): MediaArgValue => {\n const spec = verb.args[name]\n const verbText = verb.id.replace(/\\./g, ' ')\n const where = `arg \"${name}\" on \"${verbText}\"`\n const bad = (msg: string): never => {\n throw new E_MEDIA_BAD_ARG([`${where}: ${msg}. Write it like: ${exemplar(verb)}`])\n }\n const v = raw.value\n switch (spec.type) {\n case 'name-or-index': {\n if (typeof v === 'number') {\n if (!Number.isInteger(v) || v < 1) bad('indices are 1-based integers')\n return v\n }\n if (typeof v !== 'string') bad('expected a 1-based index or a quoted name')\n return v\n }\n case 'string': {\n if (typeof v === 'number' && !raw.quoted) return String(v)\n if (typeof v !== 'string')\n bad(`expected text${typeof v === 'object' ? ', got a structured value' : ''}`)\n return v\n }\n case 'number': {\n if (typeof v !== 'number') bad('expected a number')\n const n = v as number\n if (spec.min !== undefined && n < spec.min) bad(`must be ≥ ${spec.min} (indices are 1-based)`)\n if (spec.max !== undefined && n > spec.max) bad(`must be ≤ ${spec.max}`)\n return n\n }\n case 'boolean': {\n if (typeof v !== 'boolean') bad('expected true or false')\n return v\n }\n case 'enum': {\n const s = typeof v === 'number' ? String(v) : v\n if (typeof s !== 'string' || !spec.values?.includes(s)) {\n bad(`\"${String(v)}\" is not valid; valid values: ${spec.values?.join(', ')}`)\n }\n return s as string\n }\n case 'number-list': {\n const arr = Array.isArray(v) ? v : [v]\n if (!arr.every((x): x is number => typeof x === 'number'))\n bad('expected numbers (e.g. 1-3,5)')\n const nums = arr as number[]\n if (spec.min !== undefined && nums.some((n) => n < (spec.min as number))) {\n bad(`values must be ≥ ${spec.min} (indices are 1-based)`)\n }\n return nums\n }\n case 'string-list': {\n const arr = Array.isArray(v) ? v : [v]\n if (!arr.every((x): x is string => typeof x === 'string'))\n bad('expected names (quote values with special characters)')\n const strs = arr as string[]\n if (spec.values && !strs.every((s) => spec.values?.includes(s))) {\n bad(`valid values: ${spec.values.join(', ')}`)\n }\n return strs\n }\n case 'regex-or-string-list': {\n if (isRegExpRef(v)) return v\n const arr = Array.isArray(v) ? v : [v]\n if (arr.every((x) => typeof x === 'string' || isRegExpRef(x))) return arr as MediaArgScalar[]\n bad('expected literal text, a list of literals, or a /regex/')\n break\n }\n case 'media-ref': {\n if (isMediaRef(v)) return v\n bad('expected a media reference: with=@<media id> (get ids from list_media)')\n break\n }\n case 'media-ref-list': {\n const arr = Array.isArray(v) ? v : [v]\n if (arr.every(isMediaRef)) return arr as MediaArgScalar[]\n bad('expected media references: with=@<id>,@<id> (get ids from list_media)')\n break\n }\n case 'json': {\n // From pipe: a quoted string containing JSON. From ops: already-structured JSON.\n if (typeof v === 'string') {\n if (!raw.quoted) bad(`expected a quoted JSON value, e.g. ${name}='[…]'`)\n try {\n return JSON.parse(v) as MediaArgValue\n } catch (err) {\n const detail = isError(err) ? err.message : String(err)\n bad(`the quoted value is not valid JSON (${detail})`)\n }\n }\n if (isObject(v) || Array.isArray(v)) return v\n bad(`expected a JSON value, e.g. ${name}='[…]'`)\n break\n }\n }\n /* unreachable */\n throw new E_MEDIA_BAD_ARG([`${where}: invalid value`])\n}\n\nconst checkStep = (\n spec: VerbSpec,\n args: ReadonlyMap<string, { value: MediaArgValue; quoted: boolean }>\n): MediaStep => {\n const verbText = spec.id.replace(/\\./g, ' ')\n const finalArgs: Record<string, MediaArgValue> = {}\n for (const [name, raw] of args) {\n if (!(name in spec.args)) {\n throw new E_MEDIA_UNKNOWN_ARG([\n `verb \"${verbText}\" has no arg \"${name}\".${suggestArg(name, spec)} Args: ${argList(spec)}. Write it like: ${exemplar(spec)}`,\n ])\n }\n finalArgs[name] = checkArg(spec, name, raw)\n }\n for (const [name, argSpec] of Object.entries(spec.args)) {\n if (argSpec.required && !(name in finalArgs)) {\n throw new E_MEDIA_MISSING_ARG([\n `verb \"${verbText}\" requires arg \"${name}\" (${argSpec.description}). Write it like: ${exemplar(spec)}`,\n ])\n }\n }\n return { verb: spec.id, args: finalArgs }\n}\n\n/**\n * Validate raw pipe segments into a {@link MediaPlan}.\n *\n * @param segments - Output of `parsePipeRaw`.\n * @param options - The deployment's capability probe.\n * @returns The validated plan, spans preserved.\n */\nexport const validateSegments = (\n segments: readonly RawSegment[],\n options: ValidateOptions\n): MediaPlan => {\n const steps: MediaStep[] = []\n segments.forEach((seg, i) => {\n const spec = resolveVerb(seg.verb.replace(/\\./g, ' '), options.capabilities, i + 1)\n const step = checkStep(spec, seg.args)\n step.span = seg.span\n steps.push(step)\n })\n return { steps }\n}\n\n/**\n * Validate a JSON ops array into a {@link MediaPlan}. The same checks as the pipe path —\n * verbs fold the same way, args validate against the same specs — so the two front-ends\n * produce identical plans for equivalent statements.\n *\n * @param ops - The ops array.\n * @param options - The deployment's capability probe.\n * @returns The validated plan (no spans).\n */\nexport const validateOps = (ops: readonly MediaOp[], options: ValidateOptions): MediaPlan => {\n const steps: MediaStep[] = []\n ops.forEach((op, i) => {\n const spec = resolveVerb(op.verb.replace(/[._]+/g, ' '), options.capabilities, i + 1)\n const args = new Map<string, RawArgValue>(\n Object.entries(op.args).map(([k, v]) => [\n k,\n {\n value: v,\n quoted: typeof v === 'string',\n span: { offset: 0, line: 1, col: 1, length: 0 },\n },\n ])\n )\n steps.push(checkStep(spec, args))\n })\n return { steps }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8GA,IAAa,eAAe,UAAuC;CACjE,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO;CAC7B,MAAM,IAAI;CACV,OAAO,OAAO,EAAE,WAAW,YAAY,OAAO,EAAE,UAAU,YAAY,OAAO,KAAK,CAAC,EAAE,WAAW;AAClG;;AAGA,IAAa,cAAc,UAAsC;CAC/D,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO;CAC7B,MAAM,IAAI;CACV,IAAI,EAAE,SAAS,MAAM,OAAO,OAAQ,EAAuB,OAAO;CAClE,IAAI,EAAE,SAAS,WAAW,OAAO,SAAU,EAAyB,IAAI;CACxE,OAAO;AACT;;AAKA,IAAM,WAAW;;AAEjB,IAAM,iBAAiB;;;;;AAMvB,IAAM,gBAAgB,MAAsB;CAC1C,IAAI,EAAE,WAAW,KAAK,CAAC,SAAS,KAAK,CAAC,KAAK,eAAe,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GACnF,OAAO,IAAI,EAAE,QAAQ,OAAO,MAAM,EAAE,QAAQ,MAAM,MAAK,EAAE,QAAQ,OAAO,KAAK,EAAE;CAEjF,OAAO;AACT;;AAGA,IAAa,kBAAkB,UAA0B,MAAM,KAAK,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;;AAGzF,IAAM,g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ools/searxng/index.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the SearXNG search tool.\n *\n * @remarks\n * Battery-scoped exception classes owned by the SearXNG tool battery (not the ADK core). Minted\n * via `createException` from `@nhtio/adk/factories` and re-exported from the battery's barrel\n * (`@nhtio/adk/batteries/tools/searxng`). This file intentionally carries **no** `@module` tag:\n * it is an internal sibling relative-imported by `index.ts`, so it does not mint its own\n * `…/searxng/exceptions` entrypoint (whose `exceptions` leaf basename would collide with sibling\n * batteries under the `vite-plugin-dts` rolled-up `.d.ts` rule).\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when {@link createSearxngSearchTool} receives invalid configuration.\n *\n * @remarks\n * Fatal: config bugs (missing or unparseable `instanceUrl`) fail loud at factory-call time\n * rather than at the first search.\n */\nexport const E_INVALID_SEARXNG_CONFIG = createException<[string]>(\n 'E_INVALID_SEARXNG_CONFIG',\n 'Invalid SearXNG tool config: %s',\n 'E_INVALID_SEARXNG_CONFIG',\n 529,\n true\n)\n","/**\n * Factory for a configured SearXNG metasearch tool.\n *\n * @module @nhtio/adk/batteries/tools/searxng\n *\n * @remarks\n * Unlike the other bundled tool categories — every one of which exports a ready-made,\n * stateless `Tool` constant — the SearXNG battery exports a **factory**,\n * {@link createSearxngSearchTool}. A search tool has to talk to a *specific* SearXNG instance,\n * usually behind custom authentication, so it needs per-deployment configuration (a base URL\n * and headers) that cannot be baked in at module load.\n *\n * Because this module exports a factory rather than a `Tool` instance, it MUST NOT be\n * bulk-registered via `Object.values(batteries)`. Call the factory first, then register the\n * returned tool: `new ToolRegistry([createSearxngSearchTool({ instanceUrl })])`.\n *\n * @see https://docs.searxng.org/dev/search_api.html\n */\n\nimport { validator } from '@nhtio/validation'\nimport { Middleware } from '@nhtio/middleware'\nimport { isError, isObject } from '@nhtio/adk/guards'\nimport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\nimport { Tool, SpooledJsonArtifact, type ArtifactConstructorResolver } from '@nhtio/adk/common'\nimport type { Schema } from '@nhtio/validation'\nimport type { NextFn } from '@nhtio/middleware'\n\nexport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\n\n/** A static set of request headers (used for custom authentication). */\nexport type SearxngHeaders = Record<string, string>\n\n/**\n * A resolver returning request headers, sync or async. Use this form when the auth token is\n * refreshable — the resolver runs on every search, so a fresh token can be minted per call.\n */\nexport type SearxngHeadersResolver = () => SearxngHeaders | Promise<SearxngHeaders>\n\n/** The output shape the tool serialises. `either` lets the model pick per call. */\nexport type SearxngResultFormat = 'normalized' | 'raw' | 'either'\n\n/**\n * A single normalised SearXNG result. SearXNG result items are deliberately untyped upstream,\n * so every field except a best-effort `title`/`url` is optional.\n */\nexport interface SearxngResult {\n /** Result title, when the source engine provided one. */\n title?: string\n /** Result URL, when the source engine provided one. */\n url?: string\n /** Snippet / summary text for the result. */\n content?: string\n /** The SearXNG engine that produced this result (e.g. `google`, `duckduckgo`). */\n engine?: string\n /** Relevance score as reported by SearXNG (higher is more relevant). */\n score?: number\n /** Publication date, when the source engine exposed one (ISO-ish string, engine-dependent). */\n publishedDate?: string\n}\n\n/**\n * Mutable context handed to each input-pipeline stage **before** the HTTP request is sent.\n *\n * @remarks\n * Stages mutate this in place (onion `(ctx, next)` style) to adjust the outgoing request —\n * inject or rotate auth headers, force a language, rewrite the query — or call\n * {@link SearxngRequestContext.shortCircuit} to skip the fetch entirely (e.g. a cache hit).\n */\nexport interface SearxngRequestContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The search query. Mutable. */\n query: string\n /** Extra SearXNG query parameters (`categories`, `engines`, `language`, …). Mutable. */\n params: Record<string, string>\n /** Resolved request headers. Mutable — inject, redact, or rotate auth here. */\n headers: SearxngHeaders\n /** The target instance base URL (read-only). */\n readonly instanceUrl: string\n /** Cross-stage scratch space; also carried onto the response context. */\n readonly stash: Map<string, unknown>\n /** Skip the fetch and return `result` verbatim as the tool's output. */\n shortCircuit(result: string): void\n}\n\n/**\n * Mutable context handed to each output-pipeline stage **after** the response JSON is parsed.\n *\n * @remarks\n * Stages reshape, redact, enrich, or re-rank {@link SearxngResponseContext.results}, mutate the\n * raw body, or set {@link SearxngResponseContext.output} to override the serialised string\n * verbatim (e.g. to render markdown that matches a markdown `artifactConstructor`).\n */\nexport interface SearxngResponseContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The request context as it was sent (post-input-pipeline). */\n readonly request: SearxngRequestContext\n /** The parsed SearXNG JSON body. Mutable (used when `format` is `raw`). */\n raw: unknown\n /** The normalised result list. Mutable — filter, redact, or re-rank. */\n results: SearxngResult[]\n /** The effective payload shape for this call. */\n format: 'normalized' | 'raw'\n /** When set, used verbatim as the tool's output (overrides serialisation). */\n output?: string\n /** Cross-stage scratch space; carried over from the request context. */\n readonly stash: Map<string, unknown>\n}\n\n/** An input-pipeline stage. Onion middleware over {@link SearxngRequestContext}. */\nexport type SearxngInputMiddlewareFn = (\n ctx: SearxngRequestContext,\n next: NextFn\n) => void | Promise<void>\n\n/** An output-pipeline stage. Onion middleware over {@link SearxngResponseContext}. */\nexport type SearxngOutputMiddlewareFn = (\n ctx: SearxngResponseContext,\n next: NextFn\n) => void | Promise<void>\n\n/** Configuration for {@link createSearxngSearchTool}. */\nexport interface SearxngToolConfig {\n /** Base URL of the SearXNG instance, e.g. `https://searx.example.org`. Required. */\n instanceUrl: string\n /** Custom request headers — a static object or a (sync/async) resolver for refreshable auth. */\n headers?: SearxngHeaders | SearxngHeadersResolver\n /** Request timeout in milliseconds. Default `10_000`. */\n timeout?: number\n /**\n * Output shape. `normalized`/`raw` pin the shape (the model cannot change it); `either`\n * (default) exposes a `format` argument so the model chooses per call.\n */\n resultFormat?: SearxngResultFormat\n /** Tool name. Default `searxng_search`. */\n name?: string\n /** Tool description override. */\n description?: string\n /**\n * Spool artifact constructor for the tool's output. Default `() => SpooledJsonArtifact`.\n * Pass `() => SpooledMarkdownArtifact` (paired with an output stage that renders markdown into\n * `ctx.output`) or `() => SpooledArtifact` for plain text.\n */\n artifactConstructor?: ArtifactConstructorResolver\n /** Stages run before the HTTP request. See {@link SearxngRequestContext}. */\n inputPipeline?: SearxngInputMiddlewareFn[]\n /** Stages run after the response is parsed. See {@link SearxngResponseContext}. */\n outputPipeline?: SearxngOutputMiddlewareFn[]\n}\n\nconst DEFAULT_NAME = 'searxng_search'\nconst DEFAULT_TIMEOUT = 10_000\nconst DEFAULT_DESCRIPTION =\n 'Search the web via a SearXNG metasearch instance. Returns aggregated results (title, url, ' +\n 'snippet, source engine) plus any answers, infoboxes, and suggestions.'\n\n/** Internal sentinel a short-circuiting input stage throws to unwind the pipeline immediately. */\nconst SHORT_CIRCUIT = Symbol('searxng.shortCircuit')\n\ninterface ShortCircuitSignal {\n [SHORT_CIRCUIT]: true\n result: string\n}\n\nconst isShortCircuit = (value: unknown): value is ShortCircuitSignal =>\n isObject(value) && (value as Record<symbol, unknown>)[SHORT_CIRCUIT] === true\n\n/** Normalise a loose SearXNG result item into a {@link SearxngResult}. */\nconst normaliseResult = (raw: unknown): SearxngResult => {\n const r = (raw ?? {}) as Record<string, unknown>\n const out: SearxngResult = {}\n if (typeof r.title === 'string') out.title = r.title\n if (typeof r.url === 'string') out.url = r.url\n if (typeof r.content === 'string') out.content = r.content\n if (typeof r.engine === 'string') out.engine = r.engine\n if (typeof r.score === 'number') out.score = r.score\n if (typeof r.publishedDate === 'string') out.publishedDate = r.publishedDate\n return out\n}\n\n/** Resolve the configured headers (static object or resolver) for a single request. */\nconst resolveHeaders = async (headers: SearxngToolConfig['headers']): Promise<SearxngHeaders> => {\n if (typeof headers === 'function') return { ...(await headers()) }\n return { ...(headers ?? {}) }\n}\n\n/**\n * Create a configured SearXNG search {@link Tool}.\n *\n * @remarks\n * The handler always requests `format=json`. Note that SearXNG ships with JSON output\n * **disabled** by default (it is abused by bots); an instance that has not enabled\n * `search.formats: [json]` in its `settings.yml` answers with HTTP 403, which the tool returns\n * as a graceful `Error:` string naming the setting.\n *\n * @warning\n * Do not trust the `number_of_results` field for a result count — SearXNG frequently reports `0`\n * in JSON output even when `results` is non-empty. This is a long-standing upstream quirk, not a\n * tool defect (see {@link https://github.com/searxng/searxng/issues/2987 | searxng#2987} and\n * {@link https://github.com/searxng/searxng/issues/2457 | searxng#2457}). The tool passes the\n * field through verbatim; use `results.length` as the authoritative count.\n *\n * @param config - The instance URL, optional custom headers, output-format policy, artifact\n * type, and input/output middleware pipelines. See {@link SearxngToolConfig}.\n * @returns A `Tool` ready to register in a `ToolRegistry`.\n * @throws {@link E_INVALID_SEARXNG_CONFIG} when `instanceUrl` is missing or unparseable.\n */\nexport const createSearxngSearchTool = (config: SearxngToolConfig): Tool => {\n if (typeof config?.instanceUrl !== 'string' || config.instanceUrl.trim() === '') {\n throw new E_INVALID_SEARXNG_CONFIG(['instanceUrl is required'])\n }\n try {\n // Parse-validate only; the normalised string below is what we actually use.\n new URL(config.instanceUrl)\n } catch {\n throw new E_INVALID_SEARXNG_CONFIG([`instanceUrl is not a valid URL: ${config.instanceUrl}`])\n }\n // Normalise away a trailing slash so `new URL('/search', base)` resolves cleanly.\n const instanceUrl = config.instanceUrl.replace(/\\/+$/, '')\n\n const timeout = config.timeout ?? DEFAULT_TIMEOUT\n const resultFormat: SearxngResultFormat = config.resultFormat ?? 'either'\n const toolName = config.name ?? DEFAULT_NAME\n const artifactConstructor: ArtifactConstructorResolver =\n config.artifactConstructor ?? (() => SpooledJsonArtifact)\n\n // Stages are fixed at factory time; build the Middleware shells once. A fresh `.runner()` is\n // minted per invocation inside the handler (runners are single-use).\n const inputMw = new Middleware<SearxngInputMiddlewareFn>()\n for (const fn of config.inputPipeline ?? []) inputMw.add(fn)\n const outputMw = new Middleware<SearxngOutputMiddlewareFn>()\n for (const fn of config.outputPipeline ?? []) outputMw.add(fn)\n const hasInput = (config.inputPipeline ?? []).length > 0\n const hasOutput = (config.outputPipeline ?? []).length > 0\n\n // Build the input schema, conditionally exposing `format` only when the factory is neutral.\n const schemaShape: Record<string, Schema> = {\n query: validator.string().required().description('The search query.'),\n categories: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG categories (e.g. \"general,news\").'),\n engines: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG engines (e.g. \"google,duckduckgo\").'),\n language: validator.string().optional().description('Language code (e.g. \"en\", \"de\").'),\n pageno: validator.number().min(1).default(1).description('Result page number (1-based).'),\n time_range: validator\n .string()\n .valid('day', 'month', 'year')\n .optional()\n .description('Restrict results to a time range.'),\n safesearch: validator\n .number()\n .valid(0, 1, 2)\n .optional()\n .description('Safe-search level: 0 (off), 1 (moderate), 2 (strict).'),\n }\n if (resultFormat === 'either') {\n schemaShape.format = validator\n .string()\n .valid('normalized', 'raw')\n .default('normalized')\n .description('Output shape: \"normalized\" (trimmed) or \"raw\" (full SearXNG JSON).')\n }\n const inputSchema = validator.object(schemaShape)\n\n return new Tool({\n name: toolName,\n description: config.description ?? DEFAULT_DESCRIPTION,\n inputSchema,\n artifactConstructor,\n handler: async (args) => {\n const a = args as {\n query: string\n categories?: string\n engines?: string\n language?: string\n pageno?: number\n time_range?: string\n safesearch?: number\n format?: 'normalized' | 'raw'\n }\n\n try {\n // 1. Effective output format: a pinned factory format wins; else the model's choice.\n const format: 'normalized' | 'raw' =\n resultFormat === 'either' ? (a.format ?? 'normalized') : resultFormat\n\n // 2. Resolve headers, merged over portable defaults (caller headers win).\n const headers: SearxngHeaders = {\n 'Accept': 'application/json',\n 'User-Agent': 'adk-searxng-tool',\n ...(await resolveHeaders(config.headers)),\n }\n\n // 3. Assemble the SearXNG query params from validated args.\n const params: Record<string, string> = {}\n if (a.categories) params.categories = a.categories\n if (a.engines) params.engines = a.engines\n if (a.language) params.language = a.language\n if (a.pageno && a.pageno !== 1) params.pageno = String(a.pageno)\n if (a.time_range) params.time_range = a.time_range\n if (typeof a.safesearch === 'number') params.safesearch = String(a.safesearch)\n\n const stash = new Map<string, unknown>()\n\n // 4. Run the input pipeline (fresh runner) over a mutable request context.\n const requestCtx: SearxngRequestContext = {\n toolName,\n query: a.query,\n params,\n headers,\n instanceUrl,\n stash,\n shortCircuit: (result: string) => {\n const signal: ShortCircuitSignal = { [SHORT_CIRCUIT]: true, result }\n throw signal\n },\n }\n\n if (hasInput) {\n const short = await runInputPipeline(inputMw, requestCtx)\n if (short !== undefined) return short\n }\n\n // 5. Build the request URL from the (possibly mutated) query + params.\n const url = new URL('/search', instanceUrl + '/')\n url.searchParams.set('q', requestCtx.query)\n for (const [k, v] of Object.entries(requestCtx.params)) url.searchParams.set(k, v)\n url.searchParams.set('format', 'json')\n\n // 6. Fetch with an AbortController timeout.\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeout)\n let response: Response\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: requestCtx.headers,\n signal: controller.signal,\n })\n } finally {\n clearTimeout(timer)\n }\n\n if (!response.ok) {\n if (response.status === 403) {\n return (\n `Error: SearXNG returned 403 Forbidden. The instance likely has the JSON output ` +\n `format disabled — enable it under \"search.formats: [json]\" in its settings.yml.`\n )\n }\n return `Error: SearXNG returned HTTP ${response.status} ${response.statusText}.`\n }\n\n const body = (await response.json()) as Record<string, unknown>\n\n // 7. Run the output pipeline (fresh runner) over a mutable response context.\n const responseCtx: SearxngResponseContext = {\n toolName,\n request: requestCtx,\n raw: body,\n results: Array.isArray(body.results) ? body.results.map(normaliseResult) : [],\n format,\n stash,\n }\n\n if (hasOutput) await runOutputPipeline(outputMw, responseCtx)\n\n // 8. Serialise and return.\n if (typeof responseCtx.output === 'string') return responseCtx.output\n if (responseCtx.format === 'raw') return JSON.stringify(responseCtx.raw, null, 2)\n return JSON.stringify(buildNormalisedPayload(responseCtx), null, 2)\n } catch (err) {\n if (isShortCircuit(err)) return err.result\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n })\n}\n\n/** Assemble the trimmed normalised payload, dropping empty aggregate arrays. */\nconst buildNormalisedPayload = (ctx: SearxngResponseContext): Record<string, unknown> => {\n const raw = (ctx.raw ?? {}) as Record<string, unknown>\n const payload: Record<string, unknown> = {\n query: typeof raw.query === 'string' ? raw.query : ctx.request.query,\n results: ctx.results,\n }\n // NOTE: SearXNG's `number_of_results` is frequently `0` in JSON output even when `results`\n // is non-empty — a long-standing upstream quirk, not a tool bug (see\n // https://github.com/searxng/searxng/issues/2987 and\n // https://github.com/searxng/searxng/issues/2457). We pass through whatever the instance\n // reports; treat `results.length` as the authoritative count, not this field.\n if (typeof raw.number_of_results === 'number') payload.number_of_results = raw.number_of_results\n for (const key of ['answers', 'infoboxes', 'suggestions', 'corrections'] as const) {\n const value = raw[key]\n if (Array.isArray(value) && value.length > 0) payload[key] = value\n }\n return payload\n}\n\n/**\n * Run the input pipeline. Returns the short-circuit string when a stage short-circuited, or\n * `undefined` when the pipeline reached its terminal handler. A non-terminal pipeline (a stage\n * that neither called `next()` nor short-circuited) is surfaced as a thrown Error so the handler\n * converts it to an `Error:` string.\n */\nconst runInputPipeline = async (\n mw: Middleware<SearxngInputMiddlewareFn>,\n ctx: SearxngRequestContext\n): Promise<string | undefined> => {\n let reached = false\n let shortResult: string | undefined\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) {\n if (isShortCircuit(caught)) {\n shortResult = caught.result\n } else {\n throw caught\n }\n } else if (!reached) {\n throw new Error('SearXNG input pipeline did not call next() and did not short-circuit.')\n }\n return shortResult\n}\n\n/** Run the output pipeline; rethrow any stage error to the handler's try/catch. */\nconst runOutputPipeline = async (\n mw: Middleware<SearxngOutputMiddlewareFn>,\n ctx: SearxngResponseContext\n): Promise<void> => {\n let reached = false\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) throw caught\n if (!reached) {\n throw new Error('SearXNG output pipeline did not call next().')\n }\n}\n"],"mappings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P,aAAa,OAAO,UAAmB;EACtC,SAAS;CACX,CAAC,EACA,aAAa,YAAY;EACxB,UAAU;CACZ,CAAC,EACA,KAAK,IAAI,SAAS,QAAQ,QAAQ,GAAG,KAAK,IAAI,CAAC,CAAC;CAEnD,IAAI,WAAW,KAAA,GACb,IAAI,eAAe,MAAM,GACvB,cAAc,OAAO;MAErB,MAAM;MAEH,IAAI,CAAC,SACV,MAAM,IAAI,MAAM,uEAAuE;CAEzF,OAAO;AACT;;AAGA,IAAM,oBAAoB,OACxB,IACA,QACkB;CAClB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,GACH,OAAO,EACP,aAAa,OAAO,UAAmB;EACtC,SAAS;CACX,CAAC,EACA,aAAa,YAAY;EACxB,UAAU;CACZ,CAAC,EACA,KAAK,IAAI,SAAS,QAAQ,QAAQ,GAAG,KAAK,IAAI,CAAC,CAAC;CAEnD,IAAI,WAAW,KAAA,GAAW,MAAM;CAChC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8CAA8C;AAElE"}
|
package/searxng-CyA-nEu5.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"searxng-CyA-nEu5.mjs","names":[],"sources":["../src/batteries/tools/searxng/exceptions.ts","../src/batteries/tools/searxng/index.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the SearXNG search tool.\n *\n * @remarks\n * Battery-scoped exception classes owned by the SearXNG tool battery (not the ADK core). Minted\n * via `createException` from `@nhtio/adk/factories` and re-exported from the battery's barrel\n * (`@nhtio/adk/batteries/tools/searxng`). This file intentionally carries **no** `@module` tag:\n * it is an internal sibling relative-imported by `index.ts`, so it does not mint its own\n * `…/searxng/exceptions` entrypoint (whose `exceptions` leaf basename would collide with sibling\n * batteries under the `vite-plugin-dts` rolled-up `.d.ts` rule).\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when {@link createSearxngSearchTool} receives invalid configuration.\n *\n * @remarks\n * Fatal: config bugs (missing or unparseable `instanceUrl`) fail loud at factory-call time\n * rather than at the first search.\n */\nexport const E_INVALID_SEARXNG_CONFIG = createException<[string]>(\n 'E_INVALID_SEARXNG_CONFIG',\n 'Invalid SearXNG tool config: %s',\n 'E_INVALID_SEARXNG_CONFIG',\n 529,\n true\n)\n","/**\n * Factory for a configured SearXNG metasearch tool.\n *\n * @module @nhtio/adk/batteries/tools/searxng\n *\n * @remarks\n * Unlike the other bundled tool categories — every one of which exports a ready-made,\n * stateless `Tool` constant — the SearXNG battery exports a **factory**,\n * {@link createSearxngSearchTool}. A search tool has to talk to a *specific* SearXNG instance,\n * usually behind custom authentication, so it needs per-deployment configuration (a base URL\n * and headers) that cannot be baked in at module load.\n *\n * Because this module exports a factory rather than a `Tool` instance, it MUST NOT be\n * bulk-registered via `Object.values(batteries)`. Call the factory first, then register the\n * returned tool: `new ToolRegistry([createSearxngSearchTool({ instanceUrl })])`.\n *\n * @see https://docs.searxng.org/dev/search_api.html\n */\n\nimport { validator } from '@nhtio/validation'\nimport { Middleware } from '@nhtio/middleware'\nimport { isError, isObject } from '@nhtio/adk/guards'\nimport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\nimport { Tool, SpooledJsonArtifact, type ArtifactConstructorResolver } from '@nhtio/adk/common'\nimport type { Schema } from '@nhtio/validation'\nimport type { NextFn } from '@nhtio/middleware'\n\nexport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\n\n/** A static set of request headers (used for custom authentication). */\nexport type SearxngHeaders = Record<string, string>\n\n/**\n * A resolver returning request headers, sync or async. Use this form when the auth token is\n * refreshable — the resolver runs on every search, so a fresh token can be minted per call.\n */\nexport type SearxngHeadersResolver = () => SearxngHeaders | Promise<SearxngHeaders>\n\n/** The output shape the tool serialises. `either` lets the model pick per call. */\nexport type SearxngResultFormat = 'normalized' | 'raw' | 'either'\n\n/**\n * A single normalised SearXNG result. SearXNG result items are deliberately untyped upstream,\n * so every field except a best-effort `title`/`url` is optional.\n */\nexport interface SearxngResult {\n /** Result title, when the source engine provided one. */\n title?: string\n /** Result URL, when the source engine provided one. */\n url?: string\n /** Snippet / summary text for the result. */\n content?: string\n /** The SearXNG engine that produced this result (e.g. `google`, `duckduckgo`). */\n engine?: string\n /** Relevance score as reported by SearXNG (higher is more relevant). */\n score?: number\n /** Publication date, when the source engine exposed one (ISO-ish string, engine-dependent). */\n publishedDate?: string\n}\n\n/**\n * Mutable context handed to each input-pipeline stage **before** the HTTP request is sent.\n *\n * @remarks\n * Stages mutate this in place (onion `(ctx, next)` style) to adjust the outgoing request —\n * inject or rotate auth headers, force a language, rewrite the query — or call\n * {@link SearxngRequestContext.shortCircuit} to skip the fetch entirely (e.g. a cache hit).\n */\nexport interface SearxngRequestContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The search query. Mutable. */\n query: string\n /** Extra SearXNG query parameters (`categories`, `engines`, `language`, …). Mutable. */\n params: Record<string, string>\n /** Resolved request headers. Mutable — inject, redact, or rotate auth here. */\n headers: SearxngHeaders\n /** The target instance base URL (read-only). */\n readonly instanceUrl: string\n /** Cross-stage scratch space; also carried onto the response context. */\n readonly stash: Map<string, unknown>\n /** Skip the fetch and return `result` verbatim as the tool's output. */\n shortCircuit(result: string): void\n}\n\n/**\n * Mutable context handed to each output-pipeline stage **after** the response JSON is parsed.\n *\n * @remarks\n * Stages reshape, redact, enrich, or re-rank {@link SearxngResponseContext.results}, mutate the\n * raw body, or set {@link SearxngResponseContext.output} to override the serialised string\n * verbatim (e.g. to render markdown that matches a markdown `artifactConstructor`).\n */\nexport interface SearxngResponseContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The request context as it was sent (post-input-pipeline). */\n readonly request: SearxngRequestContext\n /** The parsed SearXNG JSON body. Mutable (used when `format` is `raw`). */\n raw: unknown\n /** The normalised result list. Mutable — filter, redact, or re-rank. */\n results: SearxngResult[]\n /** The effective payload shape for this call. */\n format: 'normalized' | 'raw'\n /** When set, used verbatim as the tool's output (overrides serialisation). */\n output?: string\n /** Cross-stage scratch space; carried over from the request context. */\n readonly stash: Map<string, unknown>\n}\n\n/** An input-pipeline stage. Onion middleware over {@link SearxngRequestContext}. */\nexport type SearxngInputMiddlewareFn = (\n ctx: SearxngRequestContext,\n next: NextFn\n) => void | Promise<void>\n\n/** An output-pipeline stage. Onion middleware over {@link SearxngResponseContext}. */\nexport type SearxngOutputMiddlewareFn = (\n ctx: SearxngResponseContext,\n next: NextFn\n) => void | Promise<void>\n\n/** Configuration for {@link createSearxngSearchTool}. */\nexport interface SearxngToolConfig {\n /** Base URL of the SearXNG instance, e.g. `https://searx.example.org`. Required. */\n instanceUrl: string\n /** Custom request headers — a static object or a (sync/async) resolver for refreshable auth. */\n headers?: SearxngHeaders | SearxngHeadersResolver\n /** Request timeout in milliseconds. Default `10_000`. */\n timeout?: number\n /**\n * Output shape. `normalized`/`raw` pin the shape (the model cannot change it); `either`\n * (default) exposes a `format` argument so the model chooses per call.\n */\n resultFormat?: SearxngResultFormat\n /** Tool name. Default `searxng_search`. */\n name?: string\n /** Tool description override. */\n description?: string\n /**\n * Spool artifact constructor for the tool's output. Default `() => SpooledJsonArtifact`.\n * Pass `() => SpooledMarkdownArtifact` (paired with an output stage that renders markdown into\n * `ctx.output`) or `() => SpooledArtifact` for plain text.\n */\n artifactConstructor?: ArtifactConstructorResolver\n /** Stages run before the HTTP request. See {@link SearxngRequestContext}. */\n inputPipeline?: SearxngInputMiddlewareFn[]\n /** Stages run after the response is parsed. See {@link SearxngResponseContext}. */\n outputPipeline?: SearxngOutputMiddlewareFn[]\n}\n\nconst DEFAULT_NAME = 'searxng_search'\nconst DEFAULT_TIMEOUT = 10_000\nconst DEFAULT_DESCRIPTION =\n 'Search the web via a SearXNG metasearch instance. Returns aggregated results (title, url, ' +\n 'snippet, source engine) plus any answers, infoboxes, and suggestions.'\n\n/** Internal sentinel a short-circuiting input stage throws to unwind the pipeline immediately. */\nconst SHORT_CIRCUIT = Symbol('searxng.shortCircuit')\n\ninterface ShortCircuitSignal {\n [SHORT_CIRCUIT]: true\n result: string\n}\n\nconst isShortCircuit = (value: unknown): value is ShortCircuitSignal =>\n isObject(value) && (value as Record<symbol, unknown>)[SHORT_CIRCUIT] === true\n\n/** Normalise a loose SearXNG result item into a {@link SearxngResult}. */\nconst normaliseResult = (raw: unknown): SearxngResult => {\n const r = (raw ?? {}) as Record<string, unknown>\n const out: SearxngResult = {}\n if (typeof r.title === 'string') out.title = r.title\n if (typeof r.url === 'string') out.url = r.url\n if (typeof r.content === 'string') out.content = r.content\n if (typeof r.engine === 'string') out.engine = r.engine\n if (typeof r.score === 'number') out.score = r.score\n if (typeof r.publishedDate === 'string') out.publishedDate = r.publishedDate\n return out\n}\n\n/** Resolve the configured headers (static object or resolver) for a single request. */\nconst resolveHeaders = async (headers: SearxngToolConfig['headers']): Promise<SearxngHeaders> => {\n if (typeof headers === 'function') return { ...(await headers()) }\n return { ...(headers ?? {}) }\n}\n\n/**\n * Create a configured SearXNG search {@link Tool}.\n *\n * @remarks\n * The handler always requests `format=json`. Note that SearXNG ships with JSON output\n * **disabled** by default (it is abused by bots); an instance that has not enabled\n * `search.formats: [json]` in its `settings.yml` answers with HTTP 403, which the tool returns\n * as a graceful `Error:` string naming the setting.\n *\n * @warning\n * Do not trust the `number_of_results` field for a result count — SearXNG frequently reports `0`\n * in JSON output even when `results` is non-empty. This is a long-standing upstream quirk, not a\n * tool defect (see {@link https://github.com/searxng/searxng/issues/2987 | searxng#2987} and\n * {@link https://github.com/searxng/searxng/issues/2457 | searxng#2457}). The tool passes the\n * field through verbatim; use `results.length` as the authoritative count.\n *\n * @param config - The instance URL, optional custom headers, output-format policy, artifact\n * type, and input/output middleware pipelines. See {@link SearxngToolConfig}.\n * @returns A `Tool` ready to register in a `ToolRegistry`.\n * @throws {@link E_INVALID_SEARXNG_CONFIG} when `instanceUrl` is missing or unparseable.\n */\nexport const createSearxngSearchTool = (config: SearxngToolConfig): Tool => {\n if (typeof config?.instanceUrl !== 'string' || config.instanceUrl.trim() === '') {\n throw new E_INVALID_SEARXNG_CONFIG(['instanceUrl is required'])\n }\n try {\n // Parse-validate only; the normalised string below is what we actually use.\n new URL(config.instanceUrl)\n } catch {\n throw new E_INVALID_SEARXNG_CONFIG([`instanceUrl is not a valid URL: ${config.instanceUrl}`])\n }\n // Normalise away a trailing slash so `new URL('/search', base)` resolves cleanly.\n const instanceUrl = config.instanceUrl.replace(/\\/+$/, '')\n\n const timeout = config.timeout ?? DEFAULT_TIMEOUT\n const resultFormat: SearxngResultFormat = config.resultFormat ?? 'either'\n const toolName = config.name ?? DEFAULT_NAME\n const artifactConstructor: ArtifactConstructorResolver =\n config.artifactConstructor ?? (() => SpooledJsonArtifact)\n\n // Stages are fixed at factory time; build the Middleware shells once. A fresh `.runner()` is\n // minted per invocation inside the handler (runners are single-use).\n const inputMw = new Middleware<SearxngInputMiddlewareFn>()\n for (const fn of config.inputPipeline ?? []) inputMw.add(fn)\n const outputMw = new Middleware<SearxngOutputMiddlewareFn>()\n for (const fn of config.outputPipeline ?? []) outputMw.add(fn)\n const hasInput = (config.inputPipeline ?? []).length > 0\n const hasOutput = (config.outputPipeline ?? []).length > 0\n\n // Build the input schema, conditionally exposing `format` only when the factory is neutral.\n const schemaShape: Record<string, Schema> = {\n query: validator.string().required().description('The search query.'),\n categories: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG categories (e.g. \"general,news\").'),\n engines: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG engines (e.g. \"google,duckduckgo\").'),\n language: validator.string().optional().description('Language code (e.g. \"en\", \"de\").'),\n pageno: validator.number().min(1).default(1).description('Result page number (1-based).'),\n time_range: validator\n .string()\n .valid('day', 'month', 'year')\n .optional()\n .description('Restrict results to a time range.'),\n safesearch: validator\n .number()\n .valid(0, 1, 2)\n .optional()\n .description('Safe-search level: 0 (off), 1 (moderate), 2 (strict).'),\n }\n if (resultFormat === 'either') {\n schemaShape.format = validator\n .string()\n .valid('normalized', 'raw')\n .default('normalized')\n .description('Output shape: \"normalized\" (trimmed) or \"raw\" (full SearXNG JSON).')\n }\n const inputSchema = validator.object(schemaShape)\n\n return new Tool({\n name: toolName,\n description: config.description ?? DEFAULT_DESCRIPTION,\n inputSchema,\n artifactConstructor,\n handler: async (args) => {\n const a = args as {\n query: string\n categories?: string\n engines?: string\n language?: string\n pageno?: number\n time_range?: string\n safesearch?: number\n format?: 'normalized' | 'raw'\n }\n\n try {\n // 1. Effective output format: a pinned factory format wins; else the model's choice.\n const format: 'normalized' | 'raw' =\n resultFormat === 'either' ? (a.format ?? 'normalized') : resultFormat\n\n // 2. Resolve headers, merged over portable defaults (caller headers win).\n const headers: SearxngHeaders = {\n 'Accept': 'application/json',\n 'User-Agent': 'adk-searxng-tool',\n ...(await resolveHeaders(config.headers)),\n }\n\n // 3. Assemble the SearXNG query params from validated args.\n const params: Record<string, string> = {}\n if (a.categories) params.categories = a.categories\n if (a.engines) params.engines = a.engines\n if (a.language) params.language = a.language\n if (a.pageno && a.pageno !== 1) params.pageno = String(a.pageno)\n if (a.time_range) params.time_range = a.time_range\n if (typeof a.safesearch === 'number') params.safesearch = String(a.safesearch)\n\n const stash = new Map<string, unknown>()\n\n // 4. Run the input pipeline (fresh runner) over a mutable request context.\n const requestCtx: SearxngRequestContext = {\n toolName,\n query: a.query,\n params,\n headers,\n instanceUrl,\n stash,\n shortCircuit: (result: string) => {\n const signal: ShortCircuitSignal = { [SHORT_CIRCUIT]: true, result }\n throw signal\n },\n }\n\n if (hasInput) {\n const short = await runInputPipeline(inputMw, requestCtx)\n if (short !== undefined) return short\n }\n\n // 5. Build the request URL from the (possibly mutated) query + params.\n const url = new URL('/search', instanceUrl + '/')\n url.searchParams.set('q', requestCtx.query)\n for (const [k, v] of Object.entries(requestCtx.params)) url.searchParams.set(k, v)\n url.searchParams.set('format', 'json')\n\n // 6. Fetch with an AbortController timeout.\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeout)\n let response: Response\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: requestCtx.headers,\n signal: controller.signal,\n })\n } finally {\n clearTimeout(timer)\n }\n\n if (!response.ok) {\n if (response.status === 403) {\n return (\n `Error: SearXNG returned 403 Forbidden. The instance likely has the JSON output ` +\n `format disabled — enable it under \"search.formats: [json]\" in its settings.yml.`\n )\n }\n return `Error: SearXNG returned HTTP ${response.status} ${response.statusText}.`\n }\n\n const body = (await response.json()) as Record<string, unknown>\n\n // 7. Run the output pipeline (fresh runner) over a mutable response context.\n const responseCtx: SearxngResponseContext = {\n toolName,\n request: requestCtx,\n raw: body,\n results: Array.isArray(body.results) ? body.results.map(normaliseResult) : [],\n format,\n stash,\n }\n\n if (hasOutput) await runOutputPipeline(outputMw, responseCtx)\n\n // 8. Serialise and return.\n if (typeof responseCtx.output === 'string') return responseCtx.output\n if (responseCtx.format === 'raw') return JSON.stringify(responseCtx.raw, null, 2)\n return JSON.stringify(buildNormalisedPayload(responseCtx), null, 2)\n } catch (err) {\n if (isShortCircuit(err)) return err.result\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n })\n}\n\n/** Assemble the trimmed normalised payload, dropping empty aggregate arrays. */\nconst buildNormalisedPayload = (ctx: SearxngResponseContext): Record<string, unknown> => {\n const raw = (ctx.raw ?? {}) as Record<string, unknown>\n const payload: Record<string, unknown> = {\n query: typeof raw.query === 'string' ? raw.query : ctx.request.query,\n results: ctx.results,\n }\n // NOTE: SearXNG's `number_of_results` is frequently `0` in JSON output even when `results`\n // is non-empty — a long-standing upstream quirk, not a tool bug (see\n // https://github.com/searxng/searxng/issues/2987 and\n // https://github.com/searxng/searxng/issues/2457). We pass through whatever the instance\n // reports; treat `results.length` as the authoritative count, not this field.\n if (typeof raw.number_of_results === 'number') payload.number_of_results = raw.number_of_results\n for (const key of ['answers', 'infoboxes', 'suggestions', 'corrections'] as const) {\n const value = raw[key]\n if (Array.isArray(value) && value.length > 0) payload[key] = value\n }\n return payload\n}\n\n/**\n * Run the input pipeline. Returns the short-circuit string when a stage short-circuited, or\n * `undefined` when the pipeline reached its terminal handler. A non-terminal pipeline (a stage\n * that neither called `next()` nor short-circuited) is surfaced as a thrown Error so the handler\n * converts it to an `Error:` string.\n */\nconst runInputPipeline = async (\n mw: Middleware<SearxngInputMiddlewareFn>,\n ctx: SearxngRequestContext\n): Promise<string | undefined> => {\n let reached = false\n let shortResult: string | undefined\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) {\n if (isShortCircuit(caught)) {\n shortResult = caught.result\n } else {\n throw caught\n }\n } else if (!reached) {\n throw new Error('SearXNG input pipeline did not call next() and did not short-circuit.')\n }\n return shortResult\n}\n\n/** Run the output pipeline; rethrow any stage error to the handler's try/catch. */\nconst runOutputPipeline = async (\n mw: Middleware<SearxngOutputMiddlewareFn>,\n ctx: SearxngResponseContext\n): Promise<void> => {\n let reached = false\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) throw caught\n if (!reached) {\n throw new Error('SearXNG output pipeline did not call next().')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,2BAA2B,gBACtC,4BACA,mCACA,4BACA,KACA,IACF;;;;;;;;;;;;;;;;;;;;;AC4HA,IAAM,eAAe;AACrB,IAAM,kBAAkB;AACxB,IAAM,sBACJ;;AAIF,IAAM,gBAAgB,OAAO,sBAAsB;AAOnD,IAAM,kBAAkB,UACtB,SAAS,KAAK,KAAM,MAAkC,mBAAmB;;AAG3E,IAAM,mBAAmB,QAAgC;CACvD,MAAM,IAAK,OAAO,CAAC;CACnB,MAAM,MAAqB,CAAC;CAC5B,IAAI,OAAO,EAAE,UAAU,UAAU,IAAI,QAAQ,EAAE;CAC/C,IAAI,OAAO,EAAE,QAAQ,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