@nhtio/adk 0.1.0-master-463eb577 → 0.1.0-master-44ebe1d2
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 +22 -0
- package/batteries/embeddings/openai/adapter.cjs +1 -1
- package/batteries/embeddings/openai/adapter.mjs +1 -1
- package/batteries/embeddings/webllm/adapter.cjs +1 -1
- package/batteries/embeddings/webllm/adapter.mjs +1 -1
- package/batteries/llm/openai_chat_completions/adapter.cjs +5 -5
- package/batteries/llm/openai_chat_completions/adapter.mjs +5 -5
- package/batteries/llm/openai_chat_completions/helpers.cjs +2 -2
- package/batteries/llm/openai_chat_completions/helpers.mjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.cjs +1 -1
- package/batteries/llm/openai_chat_completions/validation.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.cjs +5 -5
- package/batteries/llm/webllm_chat_completions/adapter.mjs +5 -5
- package/batteries/llm/webllm_chat_completions/validation.cjs +1 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs +1 -1
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +1 -1
- package/batteries/storage/in_memory.cjs +1 -1
- package/batteries/storage/in_memory.mjs +1 -1
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/tools/color.cjs +2 -2
- package/batteries/tools/color.mjs +2 -2
- package/batteries/tools/comparison.cjs +3 -3
- package/batteries/tools/comparison.mjs +3 -3
- package/batteries/tools/data_structure.cjs +3 -3
- package/batteries/tools/data_structure.mjs +3 -3
- package/batteries/tools/datetime_extended.cjs +2 -2
- package/batteries/tools/datetime_extended.mjs +2 -2
- package/batteries/tools/datetime_math.cjs +2 -2
- package/batteries/tools/datetime_math.mjs +2 -2
- package/batteries/tools/encoding.cjs +3 -3
- package/batteries/tools/encoding.mjs +3 -3
- package/batteries/tools/formatting.cjs +3 -3
- package/batteries/tools/formatting.mjs +3 -3
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/math/index.d.ts +14 -3
- package/batteries/tools/math.cjs +241 -9
- package/batteries/tools/math.cjs.map +1 -1
- package/batteries/tools/math.mjs +241 -9
- package/batteries/tools/math.mjs.map +1 -1
- package/batteries/tools/memory.cjs +5 -5
- package/batteries/tools/memory.mjs +5 -5
- package/batteries/tools/parsing.cjs +4 -4
- package/batteries/tools/parsing.mjs +4 -4
- package/batteries/tools/retrievables.cjs +4 -4
- package/batteries/tools/retrievables.mjs +4 -4
- package/batteries/tools/standing_instructions.cjs +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +4 -4
- package/batteries/tools/statistics.mjs +4 -4
- package/batteries/tools/string_processing.cjs +3 -3
- package/batteries/tools/string_processing.mjs +3 -3
- package/batteries/tools/structured_data.cjs +3 -3
- package/batteries/tools/structured_data.mjs +3 -3
- package/batteries/tools/text_analysis.cjs +3 -3
- package/batteries/tools/text_analysis.mjs +3 -3
- package/batteries/tools/text_comparison.cjs +2 -2
- package/batteries/tools/text_comparison.mjs +2 -2
- package/batteries/tools/time.cjs +2 -2
- package/batteries/tools/time.mjs +2 -2
- package/batteries/tools/unit_conversion.cjs +2 -2
- package/batteries/tools/unit_conversion.mjs +2 -2
- package/{common-GPkVZ_S_.js → common-D_e5zYsG.js} +8 -8
- package/{common-GPkVZ_S_.js.map → common-D_e5zYsG.js.map} +1 -1
- package/{common-DaOXYsz4.mjs → common-lMrnzoyn.mjs} +8 -8
- package/{common-DaOXYsz4.mjs.map → common-lMrnzoyn.mjs.map} +1 -1
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-BSJnHGll.mjs → dispatch_runner-CDF3X0nv.mjs} +3 -3
- package/{dispatch_runner-BSJnHGll.mjs.map → dispatch_runner-CDF3X0nv.mjs.map} +1 -1
- package/{dispatch_runner-CwBEskd7.js → dispatch_runner-CpuyATj1.js} +3 -3
- package/{dispatch_runner-CwBEskd7.js.map → dispatch_runner-CpuyATj1.js.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.mjs +1 -1
- package/exceptions.cjs +1 -1
- package/exceptions.mjs +1 -1
- package/forge.cjs +4 -4
- package/forge.mjs +4 -4
- package/guards.cjs +8 -8
- package/guards.mjs +8 -8
- package/index.cjs +12 -12
- package/index.mjs +12 -12
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +100 -100
- package/{runtime-DQ9CcNdt.js → runtime-MFFcJrRv.js} +1 -1
- package/{runtime-DQ9CcNdt.js.map → runtime-MFFcJrRv.js.map} +1 -1
- package/{runtime-DZ892Rht.mjs → runtime-j92CNi5z.mjs} +1 -1
- package/{runtime-DZ892Rht.mjs.map → runtime-j92CNi5z.mjs.map} +1 -1
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-7A9-TJeb.js → spooled_artifact-B8gIIn9h.js} +4 -4
- package/{spooled_artifact-7A9-TJeb.js.map → spooled_artifact-B8gIIn9h.js.map} +1 -1
- package/{spooled_artifact-D_K8dkI5.mjs → spooled_artifact-CWoKUDEm.mjs} +4 -4
- package/{spooled_artifact-D_K8dkI5.mjs.map → spooled_artifact-CWoKUDEm.mjs.map} +1 -1
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-CSMXhajY.mjs → spooled_markdown_artifact-CNle4jXN.mjs} +3 -3
- package/{spooled_markdown_artifact-CSMXhajY.mjs.map → spooled_markdown_artifact-CNle4jXN.mjs.map} +1 -1
- package/{spooled_markdown_artifact-yno0AFt2.js → spooled_markdown_artifact-DQX0RCdI.js} +3 -3
- package/{spooled_markdown_artifact-yno0AFt2.js.map → spooled_markdown_artifact-DQX0RCdI.js.map} +1 -1
- package/{thought-D4Urt3-j.js → thought-BD6AkkOr.js} +4 -4
- package/{thought-D4Urt3-j.js.map → thought-BD6AkkOr.js.map} +1 -1
- package/{thought-C5M4KlGw.mjs → thought-B_P8LiB6.mjs} +4 -4
- package/{thought-C5M4KlGw.mjs.map → thought-B_P8LiB6.mjs.map} +1 -1
- package/{tool-DDqsPmsX.mjs → tool-CRZSUcdP.mjs} +3 -3
- package/{tool-DDqsPmsX.mjs.map → tool-CRZSUcdP.mjs.map} +1 -1
- package/{tool-BwV8Zwpx.js → tool-CX9vNHAw.js} +3 -3
- package/{tool-BwV8Zwpx.js.map → tool-CX9vNHAw.js.map} +1 -1
- package/{tool_call-_5_kLSni.js → tool_call--7ti-frB.js} +4 -4
- package/{tool_call-_5_kLSni.js.map → tool_call--7ti-frB.js.map} +1 -1
- package/{tool_call-DdqI6Lv7.mjs → tool_call-BUeMuCc6.mjs} +4 -4
- package/{tool_call-DdqI6Lv7.mjs.map → tool_call-BUeMuCc6.mjs.map} +1 -1
- package/{tool_registry-CiNgQfJR.mjs → tool_registry-BGHg6KTq.mjs} +3 -3
- package/{tool_registry-CiNgQfJR.mjs.map → tool_registry-BGHg6KTq.mjs.map} +1 -1
- package/{tool_registry-BQVQtiJ5.js → tool_registry-CtCQ4Xoz.js} +3 -3
- package/{tool_registry-BQVQtiJ5.js.map → tool_registry-CtCQ4Xoz.js.map} +1 -1
- package/{turn_runner-B7IQ1s_1.js → turn_runner-BJTtAORU.js} +5 -5
- package/{turn_runner-B7IQ1s_1.js.map → turn_runner-BJTtAORU.js.map} +1 -1
- package/{turn_runner-DbG1qKPG.mjs → turn_runner-C02LZHjt.mjs} +5 -5
- package/{turn_runner-DbG1qKPG.mjs.map → turn_runner-C02LZHjt.mjs.map} +1 -1
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.mjs","names":[],"sources":["../../../src/batteries/tools/math/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for safe arithmetic, expression evaluation, and numeric operations.\n *\n * @module @nhtio/adk/batteries/tools/math\n *\n * @remarks\n * Pre-constructed bundled tools for the `math` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { create, all } from 'mathjs'\nimport { Tool } from '@nhtio/adk/common'\nimport { isError } from '@nhtio/adk/guards'\nimport { validator } from '@nhtio/validation'\n\nconst math = create(all)\n\nconst BLOCKED_FUNCTIONS = [\n 'import',\n 'createUnit',\n 'simplify',\n 'derivative',\n 'compile',\n 'chain',\n 'reviver',\n 'replacer',\n]\n\nfor (const fn of BLOCKED_FUNCTIONS) {\n if (fn in math) {\n ;(math as any)[fn] = undefined\n }\n}\n\nconst MAX_EXPRESSION_LENGTH = 1000\n\nfunction validateExpression(expr: string): string | undefined {\n if (expr.length > MAX_EXPRESSION_LENGTH) {\n return `Expression too long (max ${MAX_EXPRESSION_LENGTH} characters).`\n }\n return undefined\n}\n\n/**\n * Convert common LaTeX/KaTeX notation to a mathjs-evaluable expression.\n */\nfunction latexToMathjs(latex: string): string {\n let expr = latex.trim()\n\n expr = expr.replace(/^\\$\\$?|\\$\\$?$/g, '')\n expr = expr.replace(/^\\\\[[(]|\\\\[\\])]$/g, '')\n\n for (let i = 0; i < 10; i++) {\n const before = expr\n expr = expr.replace(/\\\\frac\\s*\\{([^{}]*)\\}\\s*\\{([^{}]*)\\}/g, '(($1)/($2))')\n if (expr === before) break\n }\n\n expr = expr.replace(/\\\\sqrt\\[([^\\]]+)\\]\\s*\\{([^{}]*)\\}/g, 'nthRoot($2, $1)')\n expr = expr.replace(/\\\\sqrt\\s*\\{([^{}]*)\\}/g, 'sqrt($1)')\n\n expr = expr.replace(\n /\\\\(sin|cos|tan|cot|sec|csc|arcsin|arccos|arctan|sinh|cosh|tanh|ln|log|exp|abs|det)/g,\n '$1'\n )\n\n expr = expr.replace(/log_\\{?(\\w+)\\}?\\s*\\(([^)]+)\\)/g, 'log($2, $1)')\n expr = expr.replace(/\\^{([^{}]*)}/g, '^($1)')\n expr = expr.replace(/_\\{[^{}]*\\}/g, '')\n expr = expr.replace(/_\\w/g, '')\n\n expr = expr.replace(/\\\\pi/g, 'pi')\n expr = expr.replace(\n /\\\\(alpha|beta|gamma|delta|epsilon|theta|lambda|mu|sigma|tau|phi|omega)/g,\n '$1'\n )\n\n expr = expr.replace(/\\\\cdot/g, '*')\n expr = expr.replace(/\\\\times/g, '*')\n expr = expr.replace(/\\\\div/g, '/')\n expr = expr.replace(/\\\\infty/g, 'Infinity')\n expr = expr.replace(/\\\\left\\s*([([{|])/g, '$1')\n expr = expr.replace(/\\\\right\\s*([)\\]}|])/g, '$1')\n expr = expr.replace(/\\\\sum/g, 'sum')\n expr = expr.replace(/\\\\prod/g, 'prod')\n expr = expr.replace(/\\\\,/g, ' ')\n expr = expr.replace(/\\\\;/g, ' ')\n expr = expr.replace(/\\\\quad/g, ' ')\n expr = expr.replace(/\\\\qquad/g, ' ')\n expr = expr.replace(/\\\\text\\{([^{}]*)\\}/g, '')\n expr = expr.replace(/(\\d)([a-zA-Z(])/g, '$1*$2')\n expr = expr.replace(/\\)\\s*\\(/g, ')*(')\n expr = expr.replace(/\\s+/g, ' ').trim()\n\n return expr\n}\n\n/**\n * Evaluates a mathjs-syntax expression and returns the numeric result alongside the KaTeX\n * representation of the parsed expression.\n *\n * @remarks\n * Supports arithmetic, trigonometric, logarithmic, exponential, factorial, matrix, and unit\n * operations via `mathjs`. The mathjs instance is hardened: dangerous functions (`import`,\n * `createUnit`, `simplify`, `derivative`, `compile`, `chain`, `reviver`, `replacer`) are\n * disabled to prevent interpreter-surface exposure.\n *\n * Expressions over 1000 characters are rejected with an error string (not thrown). Parse and\n * evaluation errors are also returned as error strings — the tool surfaces math errors as\n * content rather than exceptions, so the model can react to them in-line.\n */\nexport const calculateTool = new Tool({\n name: 'calculate',\n description:\n 'Evaluate a math expression. Supports arithmetic, trig, log, sqrt, factorial, matrices.',\n inputSchema: validator.object({\n expression: validator.string().required().description('Math expression, e.g. \"sin(pi/4) + 5!\"'),\n }),\n handler: async (args) => {\n const { expression } = args as { expression: string }\n\n const lengthError = validateExpression(expression)\n if (lengthError) return lengthError\n\n try {\n const result = math.evaluate!(expression)\n const node = math.parse!(expression)\n const katex = node.toTex()\n return `Result: ${result}\\nKaTeX: $${katex} = ${result}$`\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Translates a LaTeX/KaTeX expression into mathjs syntax, evaluates it, and returns the result.\n *\n * @remarks\n * Translates common LaTeX constructs (`\\frac{a}{b}`, `\\sqrt{...}`, `\\cdot`, `\\times`, Greek\n * macros like `\\pi`, `\\left`/`\\right` delimiters, `\\text{...}`, subscripts, etc.) into their\n * mathjs equivalents before evaluation. Both the source and the translated mathjs expression\n * are subject to the 1000-character length cap.\n *\n * Parse and evaluation errors are returned as error strings rather than thrown.\n */\nexport const evaluateKatexTool = new Tool({\n name: 'evaluate_katex',\n description: 'Evaluate a KaTeX/LaTeX math expression and return the numeric result.',\n inputSchema: validator.object({\n katex: validator\n .string()\n .required()\n .description('LaTeX expression, e.g. \"\\\\frac{1}{2} + \\\\sqrt{9}\"'),\n }),\n handler: async (args) => {\n const { katex } = args as { katex: string }\n\n const lengthError = validateExpression(katex)\n if (lengthError) return lengthError\n\n try {\n const mathjsExpr = latexToMathjs(katex)\n\n const translatedLengthError = validateExpression(mathjsExpr)\n if (translatedLengthError) return translatedLengthError\n\n const result = math.evaluate!(mathjsExpr)\n return `Converted: ${mathjsExpr}\\nResult: ${result}`\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAM,OAAO,OAAO,GAAG;AAavB,KAAK,MAAM,MAAM;CAVf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAGe,GACf,IAAI,MAAM,MACP,KAAc,MAAM,KAAA;AAIzB,IAAM,wBAAwB;AAE9B,SAAS,mBAAmB,MAAkC;CAC5D,IAAI,KAAK,SAAS,uBAChB,OAAO,4BAA4B,sBAAsB;AAG7D;;;;AAKA,SAAS,cAAc,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AK;CAEtC,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,IAAa,gBAAgB,IAAI,KAAK;CACpC,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,EAC5B,YAAY,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,0CAAwC,EAChG,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,eAAe;EAEvB,MAAM,cAAc,mBAAmB,UAAU;EACjD,IAAI,aAAa,OAAO;EAExB,IAAI;GACF,MAAM,SAAS,KAAK,SAAU,UAAU;GAGxC,OAAO,WAAW,OAAO,YAFZ,KAAK,MAAO,UACX,EAAK,MACkB,EAAM,KAAK,OAAO;EACzD,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;;;;AAaD,IAAa,oBAAoB,IAAI,KAAK;CACxC,MAAM;CACN,aAAa;CACb,aAAa,UAAU,OAAO,EAC5B,OAAO,UACJ,OAAO,EACP,SAAS,EACT,YAAY,qDAAmD,EACpE,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,UAAU;EAElB,MAAM,cAAc,mBAAmB,KAAK;EAC5C,IAAI,aAAa,OAAO;EAExB,IAAI;GACF,MAAM,aAAa,cAAc,KAAK;GAEtC,MAAM,wBAAwB,mBAAmB,UAAU;GAC3D,IAAI,uBAAuB,OAAO;GAGlC,OAAO,cAAc,WAAW,YADjB,KAAK,SAAU,UACc;EAC9C,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"math.mjs","names":[],"sources":["../../../src/batteries/tools/math/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for safe arithmetic, expression evaluation, and numeric operations.\n *\n * @module @nhtio/adk/batteries/tools/math\n *\n * @remarks\n * Pre-constructed bundled tools for the `math` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { create, all } from 'mathjs'\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\nimport { isError, isInstanceOf } from '@nhtio/adk/guards'\n\nconst math = create(all)\n\nconst BLOCKED_FUNCTIONS = [\n 'import',\n 'createUnit',\n 'simplify',\n 'derivative',\n 'compile',\n 'chain',\n 'reviver',\n 'replacer',\n]\n\nfor (const fn of BLOCKED_FUNCTIONS) {\n if (fn in math) {\n ;(math as any)[fn] = undefined\n }\n}\n\nconst MAX_EXPRESSION_LENGTH = 1000\n\nfunction validateExpression(expr: string): string | undefined {\n if (expr.length > MAX_EXPRESSION_LENGTH) {\n return `Expression too long (max ${MAX_EXPRESSION_LENGTH} characters).`\n }\n return undefined\n}\n\n/**\n * Convert common LaTeX/KaTeX notation to a mathjs-evaluable expression.\n */\nfunction latexToMathjs(latex: string): string {\n let expr = latex.trim()\n\n expr = expr.replace(/^\\$\\$?|\\$\\$?$/g, '')\n expr = expr.replace(/^\\\\[[(]|\\\\[\\])]$/g, '')\n\n for (let i = 0; i < 10; i++) {\n const before = expr\n expr = expr.replace(/\\\\frac\\s*\\{([^{}]*)\\}\\s*\\{([^{}]*)\\}/g, '(($1)/($2))')\n if (expr === before) break\n }\n\n expr = expr.replace(/\\\\sqrt\\[([^\\]]+)\\]\\s*\\{([^{}]*)\\}/g, 'nthRoot($2, $1)')\n expr = expr.replace(/\\\\sqrt\\s*\\{([^{}]*)\\}/g, 'sqrt($1)')\n\n // Inverse trig: mathjs spells these asin/acos/atan, not arcsin/arccos/arctan.\n expr = expr.replace(/\\\\arcsin/g, 'asin')\n expr = expr.replace(/\\\\arccos/g, 'acos')\n expr = expr.replace(/\\\\arctan/g, 'atan')\n\n expr = expr.replace(/\\\\(sin|cos|tan|cot|sec|csc|sinh|cosh|tanh|ln|log|exp|abs|det)/g, '$1')\n\n expr = expr.replace(/log_\\{?(\\w+)\\}?\\s*\\(([^)]+)\\)/g, 'log($2, $1)')\n expr = expr.replace(/\\^{([^{}]*)}/g, '^($1)')\n expr = expr.replace(/_\\{[^{}]*\\}/g, '')\n expr = expr.replace(/_\\w/g, '')\n\n expr = expr.replace(/\\\\pi/g, 'pi')\n expr = expr.replace(\n /\\\\(alpha|beta|gamma|delta|epsilon|theta|lambda|mu|sigma|tau|phi|omega)/g,\n '$1'\n )\n\n expr = expr.replace(/\\\\cdot/g, '*')\n expr = expr.replace(/\\\\times/g, '*')\n expr = expr.replace(/\\\\div/g, '/')\n expr = expr.replace(/\\\\infty/g, 'Infinity')\n expr = expr.replace(/\\\\left\\s*([([{|])/g, '$1')\n expr = expr.replace(/\\\\right\\s*([)\\]}|])/g, '$1')\n expr = expr.replace(/\\\\sum/g, 'sum')\n expr = expr.replace(/\\\\prod/g, 'prod')\n expr = expr.replace(/\\\\,/g, ' ')\n expr = expr.replace(/\\\\;/g, ' ')\n expr = expr.replace(/\\\\quad/g, ' ')\n expr = expr.replace(/\\\\qquad/g, ' ')\n expr = expr.replace(/\\\\text\\{([^{}]*)\\}/g, '')\n expr = expr.replace(/(\\d)([a-zA-Z(])/g, '$1*$2')\n expr = expr.replace(/\\)\\s*\\(/g, ')*(')\n expr = expr.replace(/\\s+/g, ' ').trim()\n\n return expr\n}\n\n// ─── Numeric calculus ─────────────────────────────────────────────────────────\n//\n// `evaluate_katex` is a numeric evaluator. mathjs has no symbolic integration, and its symbolic\n// `derivative` is intentionally blocklisted above, so calculus is computed NUMERICALLY: definite\n// integrals via composite Simpson quadrature, derivatives via central finite differences, and limits\n// via a two-sided approach. These are approximations (correct to ~1e-9 for the smooth expressions a\n// model emits), surfaced under a `Result (numeric):` label so the distinction is explicit.\n//\n// Detection runs on the RAW LaTeX, before `latexToMathjs` flattens it — its subscript stripping\n// would otherwise destroy integral bounds (`\\int_{0}^{1}` → `\\int^(1)`) and limit targets. The\n// extracted sub-expressions (integrand, bounds, body, point) are then translated by the existing\n// `latexToMathjs` and evaluated per-point with a scope, which works under the security blocklist.\n\n/** A tagged error whose message is surfaced to the model verbatim (caught by {@link tryCalculus}). */\nclass CalculusError extends Error {}\n\n/** Evaluate a mathjs expression at a single point, guarding against non-finite results. */\nfunction evalAt(expr: string, varName: string, x: number): number {\n const y = math.evaluate!(expr, { [varName]: x })\n if (typeof y !== 'number' || !Number.isFinite(y)) {\n throw new CalculusError('NON_FINITE')\n }\n return y\n}\n\n/** Composite Simpson's rule over a finite interval. Throws {@link CalculusError} on a singularity. */\nfunction simpson(fn: (x: number) => number, a: number, b: number, n = 1000): number {\n if (n % 2 === 1) n++\n const h = (b - a) / n\n let sum = fn(a) + fn(b)\n for (let i = 1; i < n; i++) {\n sum += (i % 2 === 1 ? 4 : 2) * fn(a + i * h)\n }\n const result = (h / 3) * sum\n if (!Number.isFinite(result)) throw new CalculusError('NON_FINITE')\n return result\n}\n\n/** Round numeric output to 12 significant digits, collapsing floating-point noise. */\nfunction formatNumeric(n: number): string {\n // Snap values that are zero-to-within-tolerance to exactly 0 (e.g. lim_{x->inf} 1/x ≈ 1e-8).\n if (Math.abs(n) < 1e-9) return '0'\n return math.format!(n, { precision: 12 })\n}\n\n/**\n * Reads a single `_`/`^` script starting at `i`, supporting braced (`_{0}`, `^{\\pi}`), command\n * (`^\\pi`), and bare-token (`_0`, `^1`) forms. Returns the mark, its raw-LaTeX value, and the next\n * index, or `null` when there is no script at `i`.\n */\nfunction readScript(s: string, i: number): { mark: '_' | '^'; val: string; next: number } | null {\n while (s[i] === ' ') i++\n const mark = s[i]\n if (mark !== '_' && mark !== '^') return null\n i++\n while (s[i] === ' ') i++\n if (s[i] === '{') {\n let depth = 0\n const start = ++i\n for (; i < s.length; i++) {\n if (s[i] === '{') depth++\n else if (s[i] === '}') {\n if (depth === 0) break\n depth--\n }\n }\n return { mark, val: s.slice(start, i), next: i + 1 }\n }\n if (s[i] === '\\\\') {\n const m = /^\\\\[a-zA-Z]+/.exec(s.slice(i))\n if (!m) return null\n return { mark, val: m[0], next: i + m[0].length }\n }\n const m = /^[A-Za-z0-9.]+/.exec(s.slice(i))\n if (!m) return null\n return { mark, val: m[0], next: i + m[0].length }\n}\n\n/** Translate a raw-LaTeX bound/target fragment and evaluate it to a finite number. */\nfunction evalBound(latex: string): number {\n const trimmed = latex.trim()\n if (/\\\\infty/.test(trimmed)) throw new CalculusError('INFINITE_BOUND')\n const mathjsExpr = latexToMathjs(trimmed)\n const value = math.evaluate!(mathjsExpr)\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new CalculusError('BAD_BOUND')\n }\n return value\n}\n\n/** Evaluate a definite integral `\\int_{a}^{b} f \\,dx` by Simpson quadrature. */\nfunction evalIntegral(s: string): string {\n // Strip the operator (\\int, optionally with \\limits).\n const m = /\\\\int(?:\\\\limits)?/.exec(s)\n if (!m) throw new CalculusError('NOT_INTEGRAL')\n let i = m.index + m[0].length\n\n // Read up to two scripts (bounds), in either order.\n const scripts: Record<'_' | '^', string | undefined> = { '_': undefined, '^': undefined }\n for (let k = 0; k < 2; k++) {\n const sc = readScript(s, i)\n if (!sc) break\n scripts[sc.mark] = sc.val\n i = sc.next\n }\n if (scripts._ === undefined || scripts['^'] === undefined) {\n throw new CalculusError('INDEFINITE')\n }\n\n // The remainder is `integrand … d<var>`. Pull the trailing differential off the end.\n const rest = s.slice(i)\n const diff = /\\\\?,?\\s*\\bd\\s*([a-zA-Z])\\s*$/.exec(rest)\n if (!diff) throw new CalculusError('NO_DIFFERENTIAL')\n const variable = diff[1]\n const integrandLatex = rest.slice(0, diff.index)\n if (integrandLatex.trim().length === 0) throw new CalculusError('NO_INTEGRAND')\n\n const a = evalBound(scripts._)\n const b = evalBound(scripts['^'])\n const integrand = latexToMathjs(integrandLatex)\n const fn = (x: number) => evalAt(integrand, variable, x)\n\n let result: number\n if (a === b) result = 0\n else if (a < b) result = simpson(fn, a, b)\n else result = -simpson(fn, b, a)\n\n return `Converted: ∫(${integrand}) d${variable} from ${formatNumeric(a)} to ${formatNumeric(b)}\\nResult (numeric): ${formatNumeric(result)}`\n}\n\n/** Evaluate a derivative `\\frac{d}{dx} f \\big|_{x=a}` at a point via central finite difference. */\nfunction evalDerivative(s: string): string {\n // Operator + variable: \\frac{d}{dx} … or bare d/dx ….\n let variable: string | undefined\n let body = s\n const fracOp = /\\\\frac\\s*\\{\\s*d\\s*\\}\\s*\\{\\s*d\\s*([a-zA-Z])\\s*\\}/.exec(s)\n if (fracOp) {\n variable = fracOp[1]\n body = s.slice(fracOp.index + fracOp[0].length)\n } else {\n const bareOp = /(?:^|[^a-zA-Z])d\\s*\\/\\s*d([a-zA-Z])/.exec(s)\n if (bareOp) {\n variable = bareOp[1]\n body = s.slice(bareOp.index + bareOp[0].length)\n }\n }\n if (!variable) throw new CalculusError('NOT_DERIVATIVE')\n\n // Remove pure \\left. / \\right. delimiters.\n body = body.replace(/\\\\left\\.?/g, '').replace(/\\\\right\\.?/g, '')\n\n // Evaluation bar + point at the end: …|_{x=3} (optionally \\Big| etc.).\n const bar = /\\\\?(?:Big|big|bigg|Bigg)?\\s*\\|\\s*_\\s*\\{?\\s*([a-zA-Z])\\s*=\\s*([^}]+?)\\s*\\}?\\s*$/.exec(\n body\n )\n if (!bar) throw new CalculusError('NO_POINT')\n const point = evalBound(bar[2])\n let fnLatex = body.slice(0, bar.index).trim()\n\n // Strip one layer of wrapping parentheses/brackets around the function body.\n fnLatex = fnLatex\n .replace(/^\\\\?\\(([\\s\\S]*)\\\\?\\)$/, '$1')\n .replace(/^\\[([\\s\\S]*)\\]$/, '$1')\n .trim()\n if (fnLatex.length === 0) throw new CalculusError('NO_FUNCTION')\n\n const expr = latexToMathjs(fnLatex)\n const h = 1e-6\n const fn = (x: number) => evalAt(expr, variable, x)\n const result = (fn(point + h) - fn(point - h)) / (2 * h)\n if (!Number.isFinite(result)) throw new CalculusError('NON_FINITE')\n\n return `Converted: d/d${variable}(${expr}) at ${variable}=${formatNumeric(point)}\\nResult (numeric): ${formatNumeric(result)}`\n}\n\n/** Evaluate a limit `\\lim_{x \\to a} f(x)` by a two-sided numeric approach. */\nfunction evalLimit(s: string): string {\n const head = /\\\\lim\\s*_\\s*\\{\\s*([a-zA-Z])\\s*\\\\to\\s*([\\s\\S]+?)\\s*\\}/.exec(s)\n if (!head) throw new CalculusError('NOT_LIMIT')\n const variable = head[1]\n let targetLatex = head[2].trim()\n const bodyLatex = s.slice(head.index + head[0].length).trim()\n if (bodyLatex.length === 0) throw new CalculusError('NO_FUNCTION')\n\n // One-sided markers (0^+, 0^-, 0^{+}) — record the side, strip the marker.\n let side: 'both' | 'plus' | 'minus' = 'both'\n const oneSided = /\\^\\s*\\{?\\s*([+-])\\s*\\}?\\s*$/.exec(targetLatex)\n if (oneSided) {\n side = oneSided[1] === '+' ? 'plus' : 'minus'\n targetLatex = targetLatex.slice(0, oneSided.index).trim()\n }\n\n const expr = latexToMathjs(bodyLatex)\n const fn = (x: number) => evalAt(expr, variable, x)\n const eps = 1e-6\n\n // Infinite targets via large-magnitude substitution.\n let result: number\n let targetLabel: string\n if (/^-\\s*\\\\infty$/.test(targetLatex)) {\n result = fn(-1e8)\n targetLabel = '-∞'\n } else if (/^\\\\infty$/.test(targetLatex)) {\n result = fn(1e8)\n targetLabel = '∞'\n } else {\n const target = evalBound(targetLatex)\n targetLabel = formatNumeric(target)\n if (side === 'plus') {\n result = fn(target + eps)\n } else if (side === 'minus') {\n result = fn(target - eps)\n } else {\n const lo = fn(target - eps)\n const hi = fn(target + eps)\n const avg = (lo + hi) / 2\n if (Math.abs(hi - lo) > 1e-3 * Math.max(1, Math.abs(avg))) {\n throw new CalculusError('LIMIT_MISMATCH')\n }\n result = avg\n }\n }\n if (!Number.isFinite(result)) throw new CalculusError('LIMIT_UNBOUNDED')\n\n // Infinite-target substitution (±1e8) and the eps offset leave more residue than Simpson or the\n // derivative difference, so snap a limit result to a nearby round value before formatting:\n // 0.99999998 → 1, 1e-8 → 0. The tolerance is loose enough to absorb the substitution error yet\n // far tighter than the divergence check that already rejected genuinely non-convergent limits.\n const nearest = Math.round(result)\n if (Math.abs(result - nearest) < 1e-6) result = nearest\n\n return `Converted: lim ${variable}→${targetLabel} of (${expr})\\nResult (numeric): ${formatNumeric(result)}`\n}\n\n/** Human-readable, model-actionable message for each {@link CalculusError} tag. */\nfunction calculusErrorMessage(tag: string): string {\n switch (tag) {\n case 'INDEFINITE':\n return 'Cannot evaluate an indefinite integral numerically. Provide bounds, e.g. \\\\int_{0}^{1} x dx.'\n case 'NO_DIFFERENTIAL':\n return \"Could not find the integration variable. Expected a trailing differential like 'dx'.\"\n case 'NO_INTEGRAND':\n return 'The integral has no integrand to evaluate.'\n case 'INFINITE_BOUND':\n return 'Infinite integration bounds are not supported. Provide finite numeric bounds, e.g. \\\\int_{0}^{1} f dx.'\n case 'BAD_BOUND':\n return 'Could not evaluate the integration bounds to numbers.'\n case 'NO_POINT':\n return 'Cannot evaluate a derivative numerically without a point. Specify where, e.g. \\\\frac{d}{dx}(x^2)\\\\Big|_{x=3}.'\n case 'NO_FUNCTION':\n return 'Could not find the function to evaluate.'\n case 'LIMIT_MISMATCH':\n return 'The limit may not exist (left and right values disagree).'\n case 'LIMIT_UNBOUNDED':\n return 'The limit appears to diverge (function is unbounded near the target).'\n case 'NON_FINITE':\n return 'The expression is not finite over the requested range (possible singularity); cannot evaluate numerically.'\n default:\n return 'Could not evaluate the calculus expression.'\n }\n}\n\n/**\n * Detects a calculus construct in raw LaTeX and routes it to the matching numeric handler. Returns\n * the result/error string, or `null` when the input is not a calculus expression (so the caller\n * falls through to the scalar evaluation path unchanged).\n */\nfunction tryCalculus(latex: string): string | null {\n let s = latex.trim()\n s = s.replace(/^\\$\\$?|\\$\\$?$/g, '')\n s = s.replace(/^\\\\[[(]|\\\\[\\])]$/g, '').trim()\n\n let handler: ((expr: string) => string) | undefined\n if (/\\\\int/.test(s)) handler = evalIntegral\n else if (/\\\\lim/.test(s)) handler = evalLimit\n else if (\n /\\\\frac\\s*\\{\\s*d\\s*\\}\\s*\\{\\s*d\\s*[a-zA-Z]\\s*\\}/.test(s) ||\n /(?:^|[^a-zA-Z])d\\s*\\/\\s*d[a-zA-Z]/.test(s)\n )\n handler = evalDerivative\n if (!handler) return null\n\n try {\n return handler(s)\n } catch (err) {\n if (isInstanceOf(err, 'CalculusError', CalculusError)) {\n return `Error: ${calculusErrorMessage(err.message)}`\n }\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n}\n\n/**\n * Evaluates a mathjs-syntax expression and returns the numeric result alongside the KaTeX\n * representation of the parsed expression.\n *\n * @remarks\n * Supports arithmetic, trigonometric, logarithmic, exponential, factorial, matrix, and unit\n * operations via `mathjs`. The mathjs instance is hardened: dangerous functions (`import`,\n * `createUnit`, `simplify`, `derivative`, `compile`, `chain`, `reviver`, `replacer`) are\n * disabled to prevent interpreter-surface exposure.\n *\n * Expressions over 1000 characters are rejected with an error string (not thrown). Parse and\n * evaluation errors are also returned as error strings — the tool surfaces math errors as\n * content rather than exceptions, so the model can react to them in-line.\n */\nexport const calculateTool = new Tool({\n name: 'calculate',\n description:\n 'Evaluate a math expression. Supports arithmetic, trig, log, sqrt, factorial, matrices.',\n inputSchema: validator.object({\n expression: validator.string().required().description('Math expression, e.g. \"sin(pi/4) + 5!\"'),\n }),\n handler: async (args) => {\n const { expression } = args as { expression: string }\n\n const lengthError = validateExpression(expression)\n if (lengthError) return lengthError\n\n try {\n const result = math.evaluate!(expression)\n const node = math.parse!(expression)\n const katex = node.toTex()\n return `Result: ${result}\\nKaTeX: $${katex} = ${result}$`\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Translates a LaTeX/KaTeX expression into mathjs syntax, evaluates it, and returns the result.\n *\n * @remarks\n * Translates common LaTeX constructs (`\\frac{a}{b}`, `\\sqrt{...}`, `\\cdot`, `\\times`, Greek\n * macros like `\\pi`, inverse trig `\\arcsin`/`\\arccos`/`\\arctan`, `\\left`/`\\right` delimiters,\n * `\\text{...}`, subscripts, etc.) into their mathjs equivalents before evaluation. Both the source\n * and the translated mathjs expression are subject to the 1000-character length cap.\n *\n * Also evaluates three calculus constructs **numerically** (mathjs has no symbolic integration, and\n * its symbolic `derivative` is blocklisted here for safety):\n * - Definite integrals — `\\int_{a}^{b} f \\,dx` via composite Simpson quadrature.\n * - Derivatives at a point — `\\frac{d}{dx} f \\big|_{x=a}` via central finite difference.\n * - Limits — `\\lim_{x \\to a} f` (including `a = \\pm\\infty`) via a two-sided numeric approach.\n *\n * Numeric results are rounded with `math.format(..., { precision: 12 })` and labelled\n * `Result (numeric):` to flag that they are approximations. Constructs that cannot be evaluated\n * numerically (indefinite integrals, derivatives without a point, infinite integration bounds,\n * singular integrands, divergent limits) return a specific, guiding error string.\n *\n * Parse and evaluation errors are returned as error strings rather than thrown.\n */\nexport const evaluateKatexTool = new Tool({\n name: 'evaluate_katex',\n description:\n 'Evaluate a KaTeX/LaTeX math expression and return the numeric result. Supports arithmetic, trig, logs, roots, and numeric calculus: definite integrals (\\\\int_{a}^{b} f dx), derivatives at a point (\\\\frac{d}{dx} f|_{x=a}), and limits (\\\\lim_{x \\\\to a} f).',\n inputSchema: validator.object({\n katex: validator\n .string()\n .required()\n .description('LaTeX expression, e.g. \"\\\\frac{1}{2} + \\\\sqrt{9}\" or \"\\\\int_{0}^{1} x^2 dx\"'),\n }),\n handler: async (args) => {\n const { katex } = args as { katex: string }\n\n const lengthError = validateExpression(katex)\n if (lengthError) return lengthError\n\n try {\n // Calculus (\\int, \\lim, d/dx) is detected on the raw LaTeX and evaluated numerically before\n // the scalar flattening path, which would otherwise mangle bounds/targets. Returns null for\n // non-calculus input, falling through to the scalar evaluator below unchanged.\n const calculus = tryCalculus(katex)\n if (calculus !== null) return calculus\n\n const mathjsExpr = latexToMathjs(katex)\n\n const translatedLengthError = validateExpression(mathjsExpr)\n if (translatedLengthError) return translatedLengthError\n\n const result = math.evaluate!(mathjsExpr)\n return `Converted: ${mathjsExpr}\\nResult: ${result}`\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err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AAa,oBAAoB,IAAI,KAAK;CACxC,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,EAC5B,OAAO,UACJ,OAAO,EACP,SAAS,EACT,YAAY,iFAA6E,EAC9F,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,UAAU;EAElB,MAAM,cAAc,mBAAmB,KAAK;EAC5C,IAAI,aAAa,OAAO;EAExB,IAAI;GAIF,MAAM,WAAW,YAAY,KAAK;GAClC,IAAI,aAAa,MAAM,OAAO;GAE9B,MAAM,aAAa,cAAc,KAAK;GAEtC,MAAM,wBAAwB,mBAAmB,UAAU;GAC3D,IAAI,uBAAuB,OAAO;GAGlC,OAAO,cAAc,WAAW,YADjB,KAAK,SAAU,UACc;EAC9C,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_thought = require("../../thought-
|
|
5
|
-
const require_tool = require("../../tool-
|
|
6
|
-
require("../../common-
|
|
7
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_thought = require("../../thought-BD6AkkOr.js");
|
|
5
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
6
|
+
require("../../common-D_e5zYsG.js");
|
|
7
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
8
8
|
require("../../guards.cjs");
|
|
9
9
|
let _nhtio_validation = require("@nhtio/validation");
|
|
10
10
|
let luxon = require("luxon");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { r as Memory } from "../../thought-
|
|
3
|
-
import { t as Tool } from "../../tool-
|
|
4
|
-
import "../../common-
|
|
5
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { r as Memory } from "../../thought-B_P8LiB6.mjs";
|
|
3
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
4
|
+
import "../../common-lMrnzoyn.mjs";
|
|
5
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
6
6
|
import "../../guards.mjs";
|
|
7
7
|
import { validator } from "@nhtio/validation";
|
|
8
8
|
import { DateTime } from "luxon";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
6
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
require("../../common-D_e5zYsG.js");
|
|
6
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
7
7
|
require("../../guards.cjs");
|
|
8
8
|
let _nhtio_validation = require("@nhtio/validation");
|
|
9
9
|
let js_yaml = require("js-yaml");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
4
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import "../../common-lMrnzoyn.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
5
5
|
import "../../guards.mjs";
|
|
6
6
|
import { validator } from "@nhtio/validation";
|
|
7
7
|
import { load } from "js-yaml";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
const require_common = require("../../common-
|
|
6
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
const require_common = require("../../common-D_e5zYsG.js");
|
|
6
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
7
7
|
require("../../guards.cjs");
|
|
8
8
|
let _nhtio_validation = require("@nhtio/validation");
|
|
9
9
|
let luxon = require("luxon");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import { o as Retrievable } from "../../common-
|
|
4
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import { o as Retrievable } from "../../common-lMrnzoyn.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
5
5
|
import "../../guards.mjs";
|
|
6
6
|
import { validator } from "@nhtio/validation";
|
|
7
7
|
import { DateTime } from "luxon";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
6
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
require("../../common-D_e5zYsG.js");
|
|
6
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
7
7
|
require("../../guards.cjs");
|
|
8
8
|
let _nhtio_validation = require("@nhtio/validation");
|
|
9
9
|
//#region src/batteries/tools/standing_instructions/index.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
4
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import "../../common-lMrnzoyn.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
5
5
|
import "../../guards.mjs";
|
|
6
6
|
import { validator } from "@nhtio/validation";
|
|
7
7
|
//#region src/batteries/tools/standing_instructions/index.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
6
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
require("../../common-D_e5zYsG.js");
|
|
6
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
7
7
|
require("../../guards.cjs");
|
|
8
8
|
let _nhtio_validation = require("@nhtio/validation");
|
|
9
9
|
let simple_statistics = require("simple-statistics");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
4
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import "../../common-lMrnzoyn.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
5
5
|
import "../../guards.mjs";
|
|
6
6
|
import { validator } from "@nhtio/validation";
|
|
7
7
|
import { equalIntervalBreaks, interquartileRange, max, mean, median, min, mode, quantile, sampleCorrelation, standardDeviation, sum, variance, zScore } from "simple-statistics";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
require("../../common-D_e5zYsG.js");
|
|
6
6
|
require("../../guards.cjs");
|
|
7
7
|
let _nhtio_validation = require("@nhtio/validation");
|
|
8
8
|
let case_anything = require("case-anything");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import "../../common-lMrnzoyn.mjs";
|
|
4
4
|
import "../../guards.mjs";
|
|
5
5
|
import { validator } from "@nhtio/validation";
|
|
6
6
|
import { camelCase, capitalCase, kebabCase, pascalCase, snakeCase, trainCase } from "case-anything";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
5
|
+
require("../../common-D_e5zYsG.js");
|
|
6
6
|
require("../../guards.cjs");
|
|
7
7
|
let _nhtio_validation = require("@nhtio/validation");
|
|
8
8
|
//#region src/batteries/tools/structured_data/index.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
1
|
+
import { o as isError } from "../../tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
3
|
+
import "../../common-lMrnzoyn.mjs";
|
|
4
4
|
import "../../guards.mjs";
|
|
5
5
|
import { validator } from "@nhtio/validation";
|
|
6
6
|
//#region src/batteries/tools/structured_data/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
5
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
4
|
+
require("../../common-D_e5zYsG.js");
|
|
5
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DQX0RCdI.js");
|
|
6
6
|
let _nhtio_validation = require("@nhtio/validation");
|
|
7
7
|
//#region src/batteries/tools/text_analysis/index.ts
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
3
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
2
|
+
import "../../common-lMrnzoyn.mjs";
|
|
3
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-CNle4jXN.mjs";
|
|
4
4
|
import { validator } from "@nhtio/validation";
|
|
5
5
|
//#region src/batteries/tools/text_analysis/index.ts
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
4
|
+
require("../../common-D_e5zYsG.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
let diff = require("diff");
|
|
7
7
|
let fastest_levenshtein = require("fastest-levenshtein");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
2
|
+
import "../../common-lMrnzoyn.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { diffLines, diffWords } from "diff";
|
|
5
5
|
import { distance } from "fastest-levenshtein";
|
package/batteries/tools/time.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
4
|
+
require("../../common-D_e5zYsG.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
let luxon = require("luxon");
|
|
7
7
|
//#region src/batteries/tools/time/index.ts
|
package/batteries/tools/time.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
2
|
+
import "../../common-lMrnzoyn.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { DateTime, IANAZone } from "luxon";
|
|
5
5
|
//#region src/batteries/tools/time/index.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-CX9vNHAw.js");
|
|
4
|
+
require("../../common-D_e5zYsG.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
//#region src/batteries/tools/unit_conversion/index.ts
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CRZSUcdP.mjs";
|
|
2
|
+
import "../../common-lMrnzoyn.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
//#region src/batteries/tools/unit_conversion/index.ts
|
|
5
5
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require("./chunk-Ble4zEEl.js");
|
|
2
2
|
const require_exceptions = require("./exceptions-CitH5wZI.js");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
require("./thought-
|
|
6
|
-
require("./tool-
|
|
7
|
-
const require_spooled_artifact = require("./spooled_artifact-
|
|
8
|
-
require("./tool_call-
|
|
9
|
-
require("./spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("./tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_runtime = require("./runtime-MFFcJrRv.js");
|
|
5
|
+
require("./thought-BD6AkkOr.js");
|
|
6
|
+
require("./tool-CX9vNHAw.js");
|
|
7
|
+
const require_spooled_artifact = require("./spooled_artifact-B8gIIn9h.js");
|
|
8
|
+
require("./tool_call--7ti-frB.js");
|
|
9
|
+
require("./spooled_markdown_artifact-DQX0RCdI.js");
|
|
10
10
|
let _nhtio_validation = require("@nhtio/validation");
|
|
11
11
|
//#region src/lib/classes/retrievable.ts
|
|
12
12
|
/**
|
|
@@ -307,4 +307,4 @@ Object.defineProperty(exports, "inMemoryMediaReader", {
|
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
-
//# sourceMappingURL=common-
|
|
310
|
+
//# sourceMappingURL=common-D_e5zYsG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-GPkVZ_S_.js","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,kBAAA,UAAU,aAC9B,kBAAA,UAAU,OAAO,GACjB,kBAAA,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,sBAAA,YAAY,cAAc,KAAK,KAAK,yBAAA,gBAAgB,kBAAkB,KAAK,GAC7E,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC,CACH;AAEA,IAAM,uBAAuB,kBAAA,UAAU,OAAuB;CAC5D,IAAI,kBAAA,UAAU,OAAO,EAAE,SAAS;CAChC,SAAS,cAAc,SAAS;CAChC,WAAW,kBAAA,UACR,OAAO,EACP,MAAM,eAAe,sBAAsB,qBAAqB,EAChE,SAAS;CACZ,QAAQ,kBAAA,UAAU,OAAO,EAAE,SAAS;CACpC,MAAM,kBAAA,UAAU,OAAO,EAAE,SAAS;CAClC,OAAO,kBAAA,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACjD,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AA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"common-D_e5zYsG.js","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,kBAAA,UAAU,aAC9B,kBAAA,UAAU,OAAO,GACjB,kBAAA,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,sBAAA,YAAY,cAAc,KAAK,KAAK,yBAAA,gBAAgB,kBAAkB,KAAK,GAC7E,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC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,OAAO,MAAM;EACf;CACF;AACF;;;;;;;;;;;;;;;;AAiBA,IAAa,aAAa,KAAmB,SAAoC;CAC/E,OAAO;EACL,MAAM,SAA8C;GAClD,MAAM,WAAW,MAAM,MAAM,KAAK,IAAI;GACtC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,uCAAuC,SAAS,QAAQ;GAE1E,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,iCAAiC;GAEnD,OAAO,SAAS;EAClB;EACA,aAAwB,CAExB;CACF;AACF;;;;;;;;;;;AAYA,IAAa,eAAe,SAA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { a as validateOrThrow, i as passesSchema } from "./exceptions-BeWH2FwP.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import "./thought-
|
|
5
|
-
import "./tool-
|
|
6
|
-
import { t as SpooledArtifact } from "./spooled_artifact-
|
|
7
|
-
import "./tool_call-
|
|
8
|
-
import "./spooled_markdown_artifact-
|
|
2
|
+
import { a as Tokenizable, o as isError, s as isInstanceOf } from "./tool_registry-BGHg6KTq.mjs";
|
|
3
|
+
import { c as E_INVALID_INITIAL_RETRIEVABLE_VALUE } from "./runtime-j92CNi5z.mjs";
|
|
4
|
+
import "./thought-B_P8LiB6.mjs";
|
|
5
|
+
import "./tool-CRZSUcdP.mjs";
|
|
6
|
+
import { t as SpooledArtifact } from "./spooled_artifact-CWoKUDEm.mjs";
|
|
7
|
+
import "./tool_call-BUeMuCc6.mjs";
|
|
8
|
+
import "./spooled_markdown_artifact-CNle4jXN.mjs";
|
|
9
9
|
import { validator } from "@nhtio/validation";
|
|
10
10
|
//#region src/lib/classes/retrievable.ts
|
|
11
11
|
/**
|
|
@@ -271,4 +271,4 @@ var fromWebFile = (file) => {
|
|
|
271
271
|
//#endregion
|
|
272
272
|
export { implementsByteStore as a, byteStoreSchema as i, fromWebFile as n, Retrievable as o, inMemoryMediaReader as r, fromFetch as t };
|
|
273
273
|
|
|
274
|
-
//# sourceMappingURL=common-
|
|
274
|
+
//# sourceMappingURL=common-lMrnzoyn.mjs.map
|