@nhtio/adk 0.1.0-master-f0aa531d
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/LICENSE.md +9 -0
- package/README.md +3 -0
- package/batteries/index.d.ts +28 -0
- package/batteries/llm/index.d.ts +11 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
- package/batteries/llm/openai_chat_completions/types.cjs +1 -0
- package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
- package/batteries/llm/openai_chat_completions/types.mjs +0 -0
- package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
- package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
- package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
- package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions.cjs +51 -0
- package/batteries/llm/openai_chat_completions.mjs +5 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
- package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
- package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
- package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
- package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions.cjs +50 -0
- package/batteries/llm/webllm_chat_completions.mjs +6 -0
- package/batteries/llm.cjs +63 -0
- package/batteries/llm.mjs +10 -0
- package/batteries/storage/flydrive/index.d.ts +167 -0
- package/batteries/storage/flydrive.cjs +249 -0
- package/batteries/storage/flydrive.cjs.map +1 -0
- package/batteries/storage/flydrive.mjs +249 -0
- package/batteries/storage/flydrive.mjs.map +1 -0
- package/batteries/storage/in_memory/index.d.ts +106 -0
- package/batteries/storage/in_memory.cjs +121 -0
- package/batteries/storage/in_memory.cjs.map +1 -0
- package/batteries/storage/in_memory.mjs +119 -0
- package/batteries/storage/in_memory.mjs.map +1 -0
- package/batteries/storage/index.d.ts +18 -0
- package/batteries/storage/opfs/index.d.ts +299 -0
- package/batteries/storage/opfs.cjs +368 -0
- package/batteries/storage/opfs.cjs.map +1 -0
- package/batteries/storage/opfs.mjs +366 -0
- package/batteries/storage/opfs.mjs.map +1 -0
- package/batteries/storage.cjs +4 -0
- package/batteries/storage.mjs +2 -0
- package/batteries/tools/color/index.d.ts +37 -0
- package/batteries/tools/color.cjs +659 -0
- package/batteries/tools/color.cjs.map +1 -0
- package/batteries/tools/color.mjs +655 -0
- package/batteries/tools/color.mjs.map +1 -0
- package/batteries/tools/comparison/index.d.ts +29 -0
- package/batteries/tools/comparison.cjs +171 -0
- package/batteries/tools/comparison.cjs.map +1 -0
- package/batteries/tools/comparison.mjs +168 -0
- package/batteries/tools/comparison.mjs.map +1 -0
- package/batteries/tools/data_structure/index.d.ts +30 -0
- package/batteries/tools/data_structure.cjs +270 -0
- package/batteries/tools/data_structure.cjs.map +1 -0
- package/batteries/tools/data_structure.mjs +267 -0
- package/batteries/tools/data_structure.mjs.map +1 -0
- package/batteries/tools/datetime_extended/index.d.ts +51 -0
- package/batteries/tools/datetime_extended.cjs +309 -0
- package/batteries/tools/datetime_extended.cjs.map +1 -0
- package/batteries/tools/datetime_extended.mjs +302 -0
- package/batteries/tools/datetime_extended.mjs.map +1 -0
- package/batteries/tools/datetime_math/index.d.ts +36 -0
- package/batteries/tools/datetime_math.cjs +175 -0
- package/batteries/tools/datetime_math.cjs.map +1 -0
- package/batteries/tools/datetime_math.mjs +171 -0
- package/batteries/tools/datetime_math.mjs.map +1 -0
- package/batteries/tools/encoding/index.d.ts +36 -0
- package/batteries/tools/encoding.cjs +156 -0
- package/batteries/tools/encoding.cjs.map +1 -0
- package/batteries/tools/encoding.mjs +152 -0
- package/batteries/tools/encoding.mjs.map +1 -0
- package/batteries/tools/formatting/index.d.ts +28 -0
- package/batteries/tools/formatting.cjs +120 -0
- package/batteries/tools/formatting.cjs.map +1 -0
- package/batteries/tools/formatting.mjs +117 -0
- package/batteries/tools/formatting.mjs.map +1 -0
- package/batteries/tools/geo_basics/index.d.ts +33 -0
- package/batteries/tools/geo_basics.cjs +136 -0
- package/batteries/tools/geo_basics.cjs.map +1 -0
- package/batteries/tools/geo_basics.mjs +132 -0
- package/batteries/tools/geo_basics.mjs.map +1 -0
- package/batteries/tools/index.d.ts +32 -0
- package/batteries/tools/math/index.d.ts +37 -0
- package/batteries/tools/math.cjs +136 -0
- package/batteries/tools/math.cjs.map +1 -0
- package/batteries/tools/math.mjs +133 -0
- package/batteries/tools/math.mjs.map +1 -0
- package/batteries/tools/memory/index.d.ts +73 -0
- package/batteries/tools/memory.cjs +193 -0
- package/batteries/tools/memory.cjs.map +1 -0
- package/batteries/tools/memory.mjs +187 -0
- package/batteries/tools/memory.mjs.map +1 -0
- package/batteries/tools/parsing/index.d.ts +47 -0
- package/batteries/tools/parsing.cjs +191 -0
- package/batteries/tools/parsing.cjs.map +1 -0
- package/batteries/tools/parsing.mjs +185 -0
- package/batteries/tools/parsing.mjs.map +1 -0
- package/batteries/tools/retrievables/index.d.ts +81 -0
- package/batteries/tools/retrievables.cjs +215 -0
- package/batteries/tools/retrievables.cjs.map +1 -0
- package/batteries/tools/retrievables.mjs +209 -0
- package/batteries/tools/retrievables.mjs.map +1 -0
- package/batteries/tools/standing_instructions/index.d.ts +64 -0
- package/batteries/tools/standing_instructions.cjs +126 -0
- package/batteries/tools/standing_instructions.cjs.map +1 -0
- package/batteries/tools/standing_instructions.mjs +121 -0
- package/batteries/tools/standing_instructions.mjs.map +1 -0
- package/batteries/tools/statistics/index.d.ts +46 -0
- package/batteries/tools/statistics.cjs +253 -0
- package/batteries/tools/statistics.cjs.map +1 -0
- package/batteries/tools/statistics.mjs +248 -0
- package/batteries/tools/statistics.mjs.map +1 -0
- package/batteries/tools/string_processing/index.d.ts +29 -0
- package/batteries/tools/string_processing.cjs +154 -0
- package/batteries/tools/string_processing.cjs.map +1 -0
- package/batteries/tools/string_processing.mjs +151 -0
- package/batteries/tools/string_processing.mjs.map +1 -0
- package/batteries/tools/structured_data/index.d.ts +34 -0
- package/batteries/tools/structured_data.cjs +189 -0
- package/batteries/tools/structured_data.cjs.map +1 -0
- package/batteries/tools/structured_data.mjs +185 -0
- package/batteries/tools/structured_data.mjs.map +1 -0
- package/batteries/tools/text_analysis/index.d.ts +31 -0
- package/batteries/tools/text_analysis.cjs +120 -0
- package/batteries/tools/text_analysis.cjs.map +1 -0
- package/batteries/tools/text_analysis.mjs +117 -0
- package/batteries/tools/text_analysis.mjs.map +1 -0
- package/batteries/tools/text_comparison/index.d.ts +28 -0
- package/batteries/tools/text_comparison.cjs +96 -0
- package/batteries/tools/text_comparison.cjs.map +1 -0
- package/batteries/tools/text_comparison.mjs +93 -0
- package/batteries/tools/text_comparison.mjs.map +1 -0
- package/batteries/tools/time/index.d.ts +27 -0
- package/batteries/tools/time.cjs +63 -0
- package/batteries/tools/time.cjs.map +1 -0
- package/batteries/tools/time.mjs +60 -0
- package/batteries/tools/time.mjs.map +1 -0
- package/batteries/tools/unit_conversion/index.d.ts +19 -0
- package/batteries/tools/unit_conversion.cjs +452 -0
- package/batteries/tools/unit_conversion.cjs.map +1 -0
- package/batteries/tools/unit_conversion.mjs +450 -0
- package/batteries/tools/unit_conversion.mjs.map +1 -0
- package/batteries/tools.cjs +80 -0
- package/batteries/tools.mjs +21 -0
- package/batteries.cjs +142 -0
- package/batteries.mjs +30 -0
- package/chunk-KmRHZBOW.js +35 -0
- package/common-DeZaonK1.mjs +208 -0
- package/common-DeZaonK1.mjs.map +1 -0
- package/common-Od8edUXU.js +232 -0
- package/common-Od8edUXU.js.map +1 -0
- package/common.cjs +31 -0
- package/common.d.ts +108 -0
- package/common.mjs +8 -0
- package/dispatch_runner-9j6bXHL3.mjs +1609 -0
- package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
- package/dispatch_runner-CsoH0nld.js +1627 -0
- package/dispatch_runner-CsoH0nld.js.map +1 -0
- package/dispatch_runner.cjs +3 -0
- package/dispatch_runner.d.ts +17 -0
- package/dispatch_runner.mjs +2 -0
- package/exceptions-D5YrO9Vm.js +280 -0
- package/exceptions-D5YrO9Vm.js.map +1 -0
- package/exceptions-NrzIHw_R.mjs +244 -0
- package/exceptions-NrzIHw_R.mjs.map +1 -0
- package/exceptions.cjs +33 -0
- package/exceptions.d.ts +52 -0
- package/exceptions.mjs +3 -0
- package/factories.cjs +4 -0
- package/factories.d.ts +39 -0
- package/factories.mjs +2 -0
- package/forge.cjs +9 -0
- package/forge.d.ts +49 -0
- package/forge.mjs +5 -0
- package/guards.cjs +96 -0
- package/guards.cjs.map +1 -0
- package/guards.d.ts +83 -0
- package/guards.mjs +72 -0
- package/guards.mjs.map +1 -0
- package/index.cjs +107 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +18 -0
- package/index.mjs +31 -0
- package/index.mjs.map +1 -0
- package/lib/classes/artifact_tool.d.ts +129 -0
- package/lib/classes/base_exception.d.ts +83 -0
- package/lib/classes/identity.d.ts +71 -0
- package/lib/classes/media.d.ts +326 -0
- package/lib/classes/memory.d.ts +72 -0
- package/lib/classes/message.d.ts +137 -0
- package/lib/classes/registry.d.ts +79 -0
- package/lib/classes/retrievable.d.ts +100 -0
- package/lib/classes/spooled_artifact.d.ts +296 -0
- package/lib/classes/spooled_json_artifact.d.ts +158 -0
- package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
- package/lib/classes/thought.d.ts +142 -0
- package/lib/classes/tokenizable.d.ts +124 -0
- package/lib/classes/tool.d.ts +228 -0
- package/lib/classes/tool_call.d.ts +190 -0
- package/lib/classes/tool_registry.d.ts +159 -0
- package/lib/classes/turn_gate.d.ts +109 -0
- package/lib/contracts/dispatch_context.d.ts +345 -0
- package/lib/contracts/media_reader.d.ts +60 -0
- package/lib/contracts/spool_reader.d.ts +80 -0
- package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
- package/lib/contracts/turn_runner_config.d.ts +101 -0
- package/lib/contracts/turn_runner_context.d.ts +267 -0
- package/lib/dispatch_runner.d.ts +98 -0
- package/lib/exceptions/runtime.d.ts +370 -0
- package/lib/helpers/media_readers.d.ts +39 -0
- package/lib/turn_runner.d.ts +144 -0
- package/lib/types/dispatch_context.d.ts +233 -0
- package/lib/types/dispatch_runner.d.ts +387 -0
- package/lib/types/turn_runner.d.ts +322 -0
- package/lib/utils/canonical_json.d.ts +18 -0
- package/lib/utils/exceptions.d.ts +78 -0
- package/lib/utils/guards.d.ts +32 -0
- package/lib/utils/validation.d.ts +77 -0
- package/package.json +334 -0
- package/runtime-BJVkrGQe.js +519 -0
- package/runtime-BJVkrGQe.js.map +1 -0
- package/runtime-CrEPIFgr.mjs +346 -0
- package/runtime-CrEPIFgr.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +109 -0
- package/skills/adk-assembly/references/assembly-contract.md +66 -0
- package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
- package/skills/adk-assembly/references/first-integration.md +93 -0
- package/skills/adk-assembly/references/storage-and-context.md +102 -0
- package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
- package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
- package/spooled_artifact-Cm9Te22K.js +568 -0
- package/spooled_artifact-Cm9Te22K.js.map +1 -0
- package/spooled_artifact.cjs +7 -0
- package/spooled_artifact.d.ts +40 -0
- package/spooled_artifact.mjs +3 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
- package/spooled_markdown_artifact-RRB113sy.js +786 -0
- package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
- package/thought-CDb457b4.mjs +470 -0
- package/thought-CDb457b4.mjs.map +1 -0
- package/thought-DuN2PgdO.js +494 -0
- package/thought-DuN2PgdO.js.map +1 -0
- package/tool-COSeH8I6.js +302 -0
- package/tool-COSeH8I6.js.map +1 -0
- package/tool-D2WB1EA1.mjs +296 -0
- package/tool-D2WB1EA1.mjs.map +1 -0
- package/tool_call-BKyyxGaZ.mjs +578 -0
- package/tool_call-BKyyxGaZ.mjs.map +1 -0
- package/tool_call-DFgzcVcU.js +608 -0
- package/tool_call-DFgzcVcU.js.map +1 -0
- package/tool_registry-Dkfprsck.js +641 -0
- package/tool_registry-Dkfprsck.js.map +1 -0
- package/tool_registry-DqLOyGyG.mjs +592 -0
- package/tool_registry-DqLOyGyG.mjs.map +1 -0
- package/turn_runner-CMm2BHdX.js +615 -0
- package/turn_runner-CMm2BHdX.js.map +1 -0
- package/turn_runner-y7eyEcJH.mjs +603 -0
- package/turn_runner-y7eyEcJH.mjs.map +1 -0
- package/turn_runner.cjs +3 -0
- package/turn_runner.d.ts +21 -0
- package/turn_runner.mjs +2 -0
- package/types.cjs +1 -0
- package/types.d.ts +56 -0
- package/types.mjs +0 -0
- package/vite-env.d.ts +23 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text_comparison.cjs","names":[],"sources":["../../../src/batteries/tools/text_comparison/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for text diffs, similarity checks, and edit-distance comparisons.\n *\n * @module @nhtio/adk/batteries/tools/text_comparison\n *\n * @remarks\n * Pre-constructed bundled tools for the `text_comparison` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { diffLines, diffWords } from 'diff'\nimport { validator } from '@nhtio/validation'\nimport { distance } from 'fastest-levenshtein'\n\n/**\n * Compare two texts and emit a unified-style diff plus an additions/removals summary.\n *\n * @remarks\n * `mode: 'lines'` (default) compares line-by-line; `mode: 'words'` compares word-by-word. The\n * output is clipped at 60 diff lines — the suffix `… (N more lines truncated)` is appended if\n * the diff is larger. Identical inputs short-circuit with `Texts are identical`.\n */\nexport const textDiffTool = new Tool({\n name: 'text_diff',\n description:\n 'Compare two texts and show what changed. Returns a summary of additions, deletions, and a unified-style diff.',\n inputSchema: validator.object({\n text_a: validator.string().required().allow('').description('Original text (before)'),\n text_b: validator.string().required().allow('').description('New text (after)'),\n mode: validator\n .string()\n .valid('lines', 'words')\n .default('lines')\n .description('Compare line-by-line or word-by-word (default: lines)'),\n }),\n handler: async (args) => {\n const {\n text_a: a,\n text_b: b,\n mode,\n } = args as {\n text_a: string\n text_b: string\n mode: 'lines' | 'words'\n }\n\n if (a === b) return 'Texts are identical — no differences found.'\n\n const changes = mode === 'words' ? diffWords(a, b) : diffLines(a, b)\n\n let added = 0\n let removed = 0\n let unchanged = 0\n const diffOutput: string[] = []\n\n for (const part of changes) {\n const unit = mode === 'words' ? (part.value.match(/\\S+/g) ?? []).length : (part.count ?? 1)\n if (part.added) {\n added += unit\n for (const line of part.value.split('\\n').filter((l) => l !== '' || mode === 'words')) {\n if (line !== '') diffOutput.push(`+ ${line}`)\n }\n } else if (part.removed) {\n removed += unit\n for (const line of part.value.split('\\n').filter((l) => l !== '' || mode === 'words')) {\n if (line !== '') diffOutput.push(`- ${line}`)\n }\n } else {\n unchanged += unit\n }\n }\n\n const unit = mode === 'lines' ? 'line' : 'word'\n const summary = `+${added} ${unit}${added !== 1 ? 's' : ''} added, -${removed} ${unit}${removed !== 1 ? 's' : ''} removed, ${unchanged} unchanged`\n\n const MAX_DIFF_LINES = 60\n const truncated =\n diffOutput.length > MAX_DIFF_LINES\n ? `\\n… (${diffOutput.length - MAX_DIFF_LINES} more lines truncated)`\n : ''\n return [summary, '', ...diffOutput.slice(0, MAX_DIFF_LINES)].join('\\n') + truncated\n },\n})\n\n/**\n * Report the Levenshtein edit distance and a similarity percentage between two strings.\n *\n * @remarks\n * Useful for fuzzy matching. The percentage is `(1 - distance / max(len_a, len_b)) * 100`, with\n * a human-readable label appended (`identical` / `very similar` / `similar` / `somewhat\n * similar` / `different` / `very different`).\n */\nexport const stringSimilarityTool = new Tool({\n name: 'string_similarity',\n description:\n 'Calculate edit distance and similarity percentage between two strings using Levenshtein distance. Useful for fuzzy matching.',\n inputSchema: validator.object({\n a: validator.string().required().allow('').description('First string'),\n b: validator.string().required().allow('').description('Second string'),\n case_insensitive: validator\n .boolean()\n .default(false)\n .description('Ignore case when comparing (default: false)'),\n }),\n handler: async (args) => {\n let { a, b } = args as { a: string; b: string }\n const { case_insensitive: ci } = args as { case_insensitive: boolean }\n\n if (ci) {\n a = a.toLowerCase()\n b = b.toLowerCase()\n }\n\n const dist = distance(a, b)\n const maxLen = Math.max(a.length, b.length)\n const pct = maxLen === 0 ? 100 : Number.parseFloat(((1 - dist / maxLen) * 100).toFixed(1))\n\n const label =\n pct === 100\n ? 'identical'\n : pct >= 90\n ? 'very similar'\n : pct >= 70\n ? 'similar'\n : pct >= 50\n ? 'somewhat similar'\n : pct >= 30\n ? 'different'\n : 'very different'\n\n return `Edit distance: ${dist}\\nSimilarity: ${pct}% (${label})`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,eAAe,IAAI,aAAA,KAAK;CACnC,MAAM;CACN,aACE;CACF,aAAa,kBAAA,UAAU,OAAO;EAC5B,QAAQ,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,wBAAwB;EACpF,QAAQ,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,kBAAkB;EAC9E,MAAM,kBAAA,UACH,OAAO,EACP,MAAM,SAAS,OAAO,EACtB,QAAQ,OAAO,EACf,YAAY,uDAAuD;CACxE,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EACJ,QAAQ,GACR,QAAQ,GACR,SACE;EAMJ,IAAI,MAAM,GAAG,OAAO;EAEpB,MAAM,UAAU,SAAS,WAAA,GAAA,KAAA,WAAoB,GAAG,CAAC,KAAA,GAAA,KAAA,WAAc,GAAG,CAAC;EAEnE,IAAI,QAAQ;EACZ,IAAI,UAAU;EACd,IAAI,YAAY;EAChB,MAAM,aAAuB,CAAC;EAE9B,KAAK,MAAM,QAAQ,SAAS;GAC1B,MAAM,OAAO,SAAS,WAAW,KAAK,MAAM,MAAM,MAAM,KAAK,CAAC,GAAG,SAAU,KAAK,SAAS;GACzF,IAAI,KAAK,OAAO;IACd,SAAS;IACT,KAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,EAAE,QAAQ,MAAM,MAAM,MAAM,SAAS,OAAO,GAClF,IAAI,SAAS,IAAI,WAAW,KAAK,KAAK,MAAM;GAEhD,OAAO,IAAI,KAAK,SAAS;IACvB,WAAW;IACX,KAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,EAAE,QAAQ,MAAM,MAAM,MAAM,SAAS,OAAO,GAClF,IAAI,SAAS,IAAI,WAAW,KAAK,KAAK,MAAM;GAEhD,OACE,aAAa;EAEjB;EAEA,MAAM,OAAO,SAAS,UAAU,SAAS;EACzC,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,UAAU,IAAI,MAAM,GAAG,WAAW,QAAQ,GAAG,OAAO,YAAY,IAAI,MAAM,GAAG,YAAY,UAAU;EAEvI,MAAM,iBAAiB;EACvB,MAAM,YACJ,WAAW,SAAS,iBAChB,QAAQ,WAAW,SAAS,eAAe,0BAC3C;EACN,OAAO;GAAC;GAAS;GAAI,GAAG,WAAW,MAAM,GAAG,cAAc;EAAC,EAAE,KAAK,IAAI,IAAI;CAC5E;AACF,CAAC;;;;;;;;;AAUD,IAAa,uBAAuB,IAAI,aAAA,KAAK;CAC3C,MAAM;CACN,aACE;CACF,aAAa,kBAAA,UAAU,OAAO;EAC5B,GAAG,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,cAAc;EACrE,GAAG,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,eAAe;EACtE,kBAAkB,kBAAA,UACf,QAAQ,EACR,QAAQ,KAAK,EACb,YAAY,6CAA6C;CAC9D,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,IAAI,EAAE,GAAG,MAAM;EACf,MAAM,EAAE,kBAAkB,OAAO;EAEjC,IAAI,IAAI;GACN,IAAI,EAAE,YAAY;GAClB,IAAI,EAAE,YAAY;EACpB;EAEA,MAAM,QAAA,GAAA,oBAAA,UAAgB,GAAG,CAAC;EAC1B,MAAM,SAAS,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM;EAC1C,MAAM,MAAM,WAAW,IAAI,MAAM,OAAO,aAAa,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;EAezF,OAAO,kBAAkB,KAAK,gBAAgB,IAAI,KAZhD,QAAQ,MACJ,cACA,OAAO,KACL,iBACA,OAAO,KACL,YACA,OAAO,KACL,qBACA,OAAO,KACL,cACA,iBAE+C;CAC/D;AACF,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import "../../common-DeZaonK1.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-D2WB1EA1.mjs";
|
|
3
|
+
import { validator } from "@nhtio/validation";
|
|
4
|
+
import { diffLines, diffWords } from "diff";
|
|
5
|
+
import { distance } from "fastest-levenshtein";
|
|
6
|
+
//#region src/batteries/tools/text_comparison/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Pre-constructed tools for text diffs, similarity checks, and edit-distance comparisons.
|
|
9
|
+
*
|
|
10
|
+
* @module @nhtio/adk/batteries/tools/text_comparison
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Pre-constructed bundled tools for the `text_comparison` category. Import individually, the whole
|
|
14
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Compare two texts and emit a unified-style diff plus an additions/removals summary.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* `mode: 'lines'` (default) compares line-by-line; `mode: 'words'` compares word-by-word. The
|
|
21
|
+
* output is clipped at 60 diff lines — the suffix `… (N more lines truncated)` is appended if
|
|
22
|
+
* the diff is larger. Identical inputs short-circuit with `Texts are identical`.
|
|
23
|
+
*/
|
|
24
|
+
var textDiffTool = new Tool({
|
|
25
|
+
name: "text_diff",
|
|
26
|
+
description: "Compare two texts and show what changed. Returns a summary of additions, deletions, and a unified-style diff.",
|
|
27
|
+
inputSchema: validator.object({
|
|
28
|
+
text_a: validator.string().required().allow("").description("Original text (before)"),
|
|
29
|
+
text_b: validator.string().required().allow("").description("New text (after)"),
|
|
30
|
+
mode: validator.string().valid("lines", "words").default("lines").description("Compare line-by-line or word-by-word (default: lines)")
|
|
31
|
+
}),
|
|
32
|
+
handler: async (args) => {
|
|
33
|
+
const { text_a: a, text_b: b, mode } = args;
|
|
34
|
+
if (a === b) return "Texts are identical — no differences found.";
|
|
35
|
+
const changes = mode === "words" ? diffWords(a, b) : diffLines(a, b);
|
|
36
|
+
let added = 0;
|
|
37
|
+
let removed = 0;
|
|
38
|
+
let unchanged = 0;
|
|
39
|
+
const diffOutput = [];
|
|
40
|
+
for (const part of changes) {
|
|
41
|
+
const unit = mode === "words" ? (part.value.match(/\S+/g) ?? []).length : part.count ?? 1;
|
|
42
|
+
if (part.added) {
|
|
43
|
+
added += unit;
|
|
44
|
+
for (const line of part.value.split("\n").filter((l) => l !== "" || mode === "words")) if (line !== "") diffOutput.push(`+ ${line}`);
|
|
45
|
+
} else if (part.removed) {
|
|
46
|
+
removed += unit;
|
|
47
|
+
for (const line of part.value.split("\n").filter((l) => l !== "" || mode === "words")) if (line !== "") diffOutput.push(`- ${line}`);
|
|
48
|
+
} else unchanged += unit;
|
|
49
|
+
}
|
|
50
|
+
const unit = mode === "lines" ? "line" : "word";
|
|
51
|
+
const summary = `+${added} ${unit}${added !== 1 ? "s" : ""} added, -${removed} ${unit}${removed !== 1 ? "s" : ""} removed, ${unchanged} unchanged`;
|
|
52
|
+
const MAX_DIFF_LINES = 60;
|
|
53
|
+
const truncated = diffOutput.length > MAX_DIFF_LINES ? `\n… (${diffOutput.length - MAX_DIFF_LINES} more lines truncated)` : "";
|
|
54
|
+
return [
|
|
55
|
+
summary,
|
|
56
|
+
"",
|
|
57
|
+
...diffOutput.slice(0, MAX_DIFF_LINES)
|
|
58
|
+
].join("\n") + truncated;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Report the Levenshtein edit distance and a similarity percentage between two strings.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Useful for fuzzy matching. The percentage is `(1 - distance / max(len_a, len_b)) * 100`, with
|
|
66
|
+
* a human-readable label appended (`identical` / `very similar` / `similar` / `somewhat
|
|
67
|
+
* similar` / `different` / `very different`).
|
|
68
|
+
*/
|
|
69
|
+
var stringSimilarityTool = new Tool({
|
|
70
|
+
name: "string_similarity",
|
|
71
|
+
description: "Calculate edit distance and similarity percentage between two strings using Levenshtein distance. Useful for fuzzy matching.",
|
|
72
|
+
inputSchema: validator.object({
|
|
73
|
+
a: validator.string().required().allow("").description("First string"),
|
|
74
|
+
b: validator.string().required().allow("").description("Second string"),
|
|
75
|
+
case_insensitive: validator.boolean().default(false).description("Ignore case when comparing (default: false)")
|
|
76
|
+
}),
|
|
77
|
+
handler: async (args) => {
|
|
78
|
+
let { a, b } = args;
|
|
79
|
+
const { case_insensitive: ci } = args;
|
|
80
|
+
if (ci) {
|
|
81
|
+
a = a.toLowerCase();
|
|
82
|
+
b = b.toLowerCase();
|
|
83
|
+
}
|
|
84
|
+
const dist = distance(a, b);
|
|
85
|
+
const maxLen = Math.max(a.length, b.length);
|
|
86
|
+
const pct = maxLen === 0 ? 100 : Number.parseFloat(((1 - dist / maxLen) * 100).toFixed(1));
|
|
87
|
+
return `Edit distance: ${dist}\nSimilarity: ${pct}% (${pct === 100 ? "identical" : pct >= 90 ? "very similar" : pct >= 70 ? "similar" : pct >= 50 ? "somewhat similar" : pct >= 30 ? "different" : "very different"})`;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
//#endregion
|
|
91
|
+
export { stringSimilarityTool, textDiffTool };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=text_comparison.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text_comparison.mjs","names":[],"sources":["../../../src/batteries/tools/text_comparison/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for text diffs, similarity checks, and edit-distance comparisons.\n *\n * @module @nhtio/adk/batteries/tools/text_comparison\n *\n * @remarks\n * Pre-constructed bundled tools for the `text_comparison` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { diffLines, diffWords } from 'diff'\nimport { validator } from '@nhtio/validation'\nimport { distance } from 'fastest-levenshtein'\n\n/**\n * Compare two texts and emit a unified-style diff plus an additions/removals summary.\n *\n * @remarks\n * `mode: 'lines'` (default) compares line-by-line; `mode: 'words'` compares word-by-word. The\n * output is clipped at 60 diff lines — the suffix `… (N more lines truncated)` is appended if\n * the diff is larger. Identical inputs short-circuit with `Texts are identical`.\n */\nexport const textDiffTool = new Tool({\n name: 'text_diff',\n description:\n 'Compare two texts and show what changed. Returns a summary of additions, deletions, and a unified-style diff.',\n inputSchema: validator.object({\n text_a: validator.string().required().allow('').description('Original text (before)'),\n text_b: validator.string().required().allow('').description('New text (after)'),\n mode: validator\n .string()\n .valid('lines', 'words')\n .default('lines')\n .description('Compare line-by-line or word-by-word (default: lines)'),\n }),\n handler: async (args) => {\n const {\n text_a: a,\n text_b: b,\n mode,\n } = args as {\n text_a: string\n text_b: string\n mode: 'lines' | 'words'\n }\n\n if (a === b) return 'Texts are identical — no differences found.'\n\n const changes = mode === 'words' ? diffWords(a, b) : diffLines(a, b)\n\n let added = 0\n let removed = 0\n let unchanged = 0\n const diffOutput: string[] = []\n\n for (const part of changes) {\n const unit = mode === 'words' ? (part.value.match(/\\S+/g) ?? []).length : (part.count ?? 1)\n if (part.added) {\n added += unit\n for (const line of part.value.split('\\n').filter((l) => l !== '' || mode === 'words')) {\n if (line !== '') diffOutput.push(`+ ${line}`)\n }\n } else if (part.removed) {\n removed += unit\n for (const line of part.value.split('\\n').filter((l) => l !== '' || mode === 'words')) {\n if (line !== '') diffOutput.push(`- ${line}`)\n }\n } else {\n unchanged += unit\n }\n }\n\n const unit = mode === 'lines' ? 'line' : 'word'\n const summary = `+${added} ${unit}${added !== 1 ? 's' : ''} added, -${removed} ${unit}${removed !== 1 ? 's' : ''} removed, ${unchanged} unchanged`\n\n const MAX_DIFF_LINES = 60\n const truncated =\n diffOutput.length > MAX_DIFF_LINES\n ? `\\n… (${diffOutput.length - MAX_DIFF_LINES} more lines truncated)`\n : ''\n return [summary, '', ...diffOutput.slice(0, MAX_DIFF_LINES)].join('\\n') + truncated\n },\n})\n\n/**\n * Report the Levenshtein edit distance and a similarity percentage between two strings.\n *\n * @remarks\n * Useful for fuzzy matching. The percentage is `(1 - distance / max(len_a, len_b)) * 100`, with\n * a human-readable label appended (`identical` / `very similar` / `similar` / `somewhat\n * similar` / `different` / `very different`).\n */\nexport const stringSimilarityTool = new Tool({\n name: 'string_similarity',\n description:\n 'Calculate edit distance and similarity percentage between two strings using Levenshtein distance. Useful for fuzzy matching.',\n inputSchema: validator.object({\n a: validator.string().required().allow('').description('First string'),\n b: validator.string().required().allow('').description('Second string'),\n case_insensitive: validator\n .boolean()\n .default(false)\n .description('Ignore case when comparing (default: false)'),\n }),\n handler: async (args) => {\n let { a, b } = args as { a: string; b: string }\n const { case_insensitive: ci } = args as { case_insensitive: boolean }\n\n if (ci) {\n a = a.toLowerCase()\n b = b.toLowerCase()\n }\n\n const dist = distance(a, b)\n const maxLen = Math.max(a.length, b.length)\n const pct = maxLen === 0 ? 100 : Number.parseFloat(((1 - dist / maxLen) * 100).toFixed(1))\n\n const label =\n pct === 100\n ? 'identical'\n : pct >= 90\n ? 'very similar'\n : pct >= 70\n ? 'similar'\n : pct >= 50\n ? 'somewhat similar'\n : pct >= 30\n ? 'different'\n : 'very different'\n\n return `Edit distance: ${dist}\\nSimilarity: ${pct}% (${label})`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,eAAe,IAAI,KAAK;CACnC,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,QAAQ,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,wBAAwB;EACpF,QAAQ,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,kBAAkB;EAC9E,MAAM,UACH,OAAO,EACP,MAAM,SAAS,OAAO,EACtB,QAAQ,OAAO,EACf,YAAY,uDAAuD;CACxE,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EACJ,QAAQ,GACR,QAAQ,GACR,SACE;EAMJ,IAAI,MAAM,GAAG,OAAO;EAEpB,MAAM,UAAU,SAAS,UAAU,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC;EAEnE,IAAI,QAAQ;EACZ,IAAI,UAAU;EACd,IAAI,YAAY;EAChB,MAAM,aAAuB,CAAC;EAE9B,KAAK,MAAM,QAAQ,SAAS;GAC1B,MAAM,OAAO,SAAS,WAAW,KAAK,MAAM,MAAM,MAAM,KAAK,CAAC,GAAG,SAAU,KAAK,SAAS;GACzF,IAAI,KAAK,OAAO;IACd,SAAS;IACT,KAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,EAAE,QAAQ,MAAM,MAAM,MAAM,SAAS,OAAO,GAClF,IAAI,SAAS,IAAI,WAAW,KAAK,KAAK,MAAM;GAEhD,OAAO,IAAI,KAAK,SAAS;IACvB,WAAW;IACX,KAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,EAAE,QAAQ,MAAM,MAAM,MAAM,SAAS,OAAO,GAClF,IAAI,SAAS,IAAI,WAAW,KAAK,KAAK,MAAM;GAEhD,OACE,aAAa;EAEjB;EAEA,MAAM,OAAO,SAAS,UAAU,SAAS;EACzC,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,UAAU,IAAI,MAAM,GAAG,WAAW,QAAQ,GAAG,OAAO,YAAY,IAAI,MAAM,GAAG,YAAY,UAAU;EAEvI,MAAM,iBAAiB;EACvB,MAAM,YACJ,WAAW,SAAS,iBAChB,QAAQ,WAAW,SAAS,eAAe,0BAC3C;EACN,OAAO;GAAC;GAAS;GAAI,GAAG,WAAW,MAAM,GAAG,cAAc;EAAC,EAAE,KAAK,IAAI,IAAI;CAC5E;AACF,CAAC;;;;;;;;;AAUD,IAAa,uBAAuB,IAAI,KAAK;CAC3C,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,GAAG,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,cAAc;EACrE,GAAG,UAAU,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,eAAe;EACtE,kBAAkB,UACf,QAAQ,EACR,QAAQ,KAAK,EACb,YAAY,6CAA6C;CAC9D,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,IAAI,EAAE,GAAG,MAAM;EACf,MAAM,EAAE,kBAAkB,OAAO;EAEjC,IAAI,IAAI;GACN,IAAI,EAAE,YAAY;GAClB,IAAI,EAAE,YAAY;EACpB;EAEA,MAAM,OAAO,SAAS,GAAG,CAAC;EAC1B,MAAM,SAAS,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM;EAC1C,MAAM,MAAM,WAAW,IAAI,MAAM,OAAO,aAAa,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;EAezF,OAAO,kBAAkB,KAAK,gBAAgB,IAAI,KAZhD,QAAQ,MACJ,cACA,OAAO,KACL,iBACA,OAAO,KACL,YACA,OAAO,KACL,qBACA,OAAO,KACL,cACA,iBAE+C;CAC/D;AACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-constructed tools for current time lookup and timezone-aware time formatting.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/tools/time
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pre-constructed bundled tools for the `time` category. Import individually, the whole
|
|
8
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
9
|
+
*/
|
|
10
|
+
import { Tool } from "../../../common";
|
|
11
|
+
/**
|
|
12
|
+
* Return the current time formatted in a given timezone.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* `timezone` defaults to `UTC` when omitted. The ADK has no notion of a "user local"
|
|
16
|
+
* timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for
|
|
17
|
+
* non-UTC formatting.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getCurrentTimeTool: Tool<import("../../../common").SpooledArtifact>;
|
|
20
|
+
/**
|
|
21
|
+
* Convert a wall-clock time between two IANA timezones.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion
|
|
25
|
+
* uses today's date in the source zone to pick the correct DST offset.
|
|
26
|
+
*/
|
|
27
|
+
export declare const convertTimeTool: Tool<import("../../../common").SpooledArtifact>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../chunk-KmRHZBOW.js");
|
|
3
|
+
require("../../common-Od8edUXU.js");
|
|
4
|
+
const require_tool = require("../../tool-COSeH8I6.js");
|
|
5
|
+
let _nhtio_validation = require("@nhtio/validation");
|
|
6
|
+
let luxon = require("luxon");
|
|
7
|
+
//#region src/batteries/tools/time/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Pre-constructed tools for current time lookup and timezone-aware time formatting.
|
|
10
|
+
*
|
|
11
|
+
* @module @nhtio/adk/batteries/tools/time
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Pre-constructed bundled tools for the `time` category. Import individually, the whole
|
|
15
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Return the current time formatted in a given timezone.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* `timezone` defaults to `UTC` when omitted. The ADK has no notion of a "user local"
|
|
22
|
+
* timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for
|
|
23
|
+
* non-UTC formatting.
|
|
24
|
+
*/
|
|
25
|
+
var getCurrentTimeTool = new require_tool.Tool({
|
|
26
|
+
name: "get_current_time",
|
|
27
|
+
description: "Get current time in an IANA timezone (defaults to UTC).",
|
|
28
|
+
inputSchema: _nhtio_validation.validator.object({ timezone: _nhtio_validation.validator.string().default("UTC").description("IANA timezone (optional, defaults UTC)") }),
|
|
29
|
+
handler: async (args) => {
|
|
30
|
+
const { timezone } = args;
|
|
31
|
+
if (!luxon.IANAZone.isValidZone(timezone)) return `Error: Invalid timezone "${timezone}".`;
|
|
32
|
+
return `${timezone}: ${luxon.DateTime.now().setZone(timezone).toFormat("cccc, LLLL d, yyyy h:mm:ss a ZZZZ")}`;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Convert a wall-clock time between two IANA timezones.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion
|
|
40
|
+
* uses today's date in the source zone to pick the correct DST offset.
|
|
41
|
+
*/
|
|
42
|
+
var convertTimeTool = new require_tool.Tool({
|
|
43
|
+
name: "convert_time",
|
|
44
|
+
description: "Convert time between timezones.",
|
|
45
|
+
inputSchema: _nhtio_validation.validator.object({
|
|
46
|
+
source_timezone: _nhtio_validation.validator.string().required().description("Source IANA timezone"),
|
|
47
|
+
time: _nhtio_validation.validator.string().required().description("HH:MM (24h)"),
|
|
48
|
+
target_timezone: _nhtio_validation.validator.string().default("UTC").description("Target IANA timezone (optional, defaults UTC)")
|
|
49
|
+
}),
|
|
50
|
+
handler: async (args) => {
|
|
51
|
+
const { source_timezone: sourceTimezone, time, target_timezone: targetTimezone } = args;
|
|
52
|
+
if (!luxon.IANAZone.isValidZone(sourceTimezone)) return `Error: Invalid source timezone "${sourceTimezone}".`;
|
|
53
|
+
if (!luxon.IANAZone.isValidZone(targetTimezone)) return `Error: Invalid target timezone "${targetTimezone}".`;
|
|
54
|
+
const parsed = luxon.DateTime.fromFormat(time, "HH:mm", { zone: sourceTimezone });
|
|
55
|
+
if (!parsed.isValid) return `Error: Invalid time "${time}". Use HH:MM.`;
|
|
56
|
+
return `${time} ${sourceTimezone} = ${parsed.setZone(targetTimezone).toFormat("HH:mm")} ${targetTimezone}`;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.convertTimeTool = convertTimeTool;
|
|
61
|
+
exports.getCurrentTimeTool = getCurrentTimeTool;
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=time.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.cjs","names":[],"sources":["../../../src/batteries/tools/time/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for current time lookup and timezone-aware time formatting.\n *\n * @module @nhtio/adk/batteries/tools/time\n *\n * @remarks\n * Pre-constructed bundled tools for the `time` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { DateTime, IANAZone } from 'luxon'\nimport { validator } from '@nhtio/validation'\n\n/**\n * Return the current time formatted in a given timezone.\n *\n * @remarks\n * `timezone` defaults to `UTC` when omitted. The ADK has no notion of a \"user local\"\n * timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for\n * non-UTC formatting.\n */\nexport const getCurrentTimeTool = new Tool({\n name: 'get_current_time',\n description: 'Get current time in an IANA timezone (defaults to UTC).',\n inputSchema: validator.object({\n timezone: validator\n .string()\n .default('UTC')\n .description('IANA timezone (optional, defaults UTC)'),\n }),\n handler: async (args) => {\n const { timezone } = args as { timezone: string }\n if (!IANAZone.isValidZone(timezone)) {\n return `Error: Invalid timezone \"${timezone}\".`\n }\n const now = DateTime.now().setZone(timezone)\n return `${timezone}: ${now.toFormat('cccc, LLLL d, yyyy h:mm:ss a ZZZZ')}`\n },\n})\n\n/**\n * Convert a wall-clock time between two IANA timezones.\n *\n * @remarks\n * `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion\n * uses today's date in the source zone to pick the correct DST offset.\n */\nexport const convertTimeTool = new Tool({\n name: 'convert_time',\n description: 'Convert time between timezones.',\n inputSchema: validator.object({\n source_timezone: validator.string().required().description('Source IANA timezone'),\n time: validator.string().required().description('HH:MM (24h)'),\n target_timezone: validator\n .string()\n .default('UTC')\n .description('Target IANA timezone (optional, defaults UTC)'),\n }),\n handler: async (args) => {\n const {\n source_timezone: sourceTimezone,\n time,\n target_timezone: targetTimezone,\n } = args as {\n source_timezone: string\n time: string\n target_timezone: string\n }\n\n if (!IANAZone.isValidZone(sourceTimezone)) {\n return `Error: Invalid source timezone \"${sourceTimezone}\".`\n }\n if (!IANAZone.isValidZone(targetTimezone)) {\n return `Error: Invalid target timezone \"${targetTimezone}\".`\n }\n\n const parsed = DateTime.fromFormat(time, 'HH:mm', { zone: sourceTimezone })\n if (!parsed.isValid) {\n return `Error: Invalid time \"${time}\". Use HH:MM.`\n }\n\n const converted = parsed.setZone(targetTimezone)\n return `${time} ${sourceTimezone} = ${converted.toFormat('HH:mm')} ${targetTimezone}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,qBAAqB,IAAI,aAAA,KAAK;CACzC,MAAM;CACN,aAAa;CACb,aAAa,kBAAA,UAAU,OAAO,EAC5B,UAAU,kBAAA,UACP,OAAO,EACP,QAAQ,KAAK,EACb,YAAY,wCAAwC,EACzD,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,aAAa;EACrB,IAAI,CAAC,MAAA,SAAS,YAAY,QAAQ,GAChC,OAAO,4BAA4B,SAAS;EAG9C,OAAO,GAAG,SAAS,IADP,MAAA,SAAS,IAAI,EAAE,QAAQ,QACZ,EAAI,SAAS,mCAAmC;CACzE;AACF,CAAC;;;;;;;;AASD,IAAa,kBAAkB,IAAI,aAAA,KAAK;CACtC,MAAM;CACN,aAAa;CACb,aAAa,kBAAA,UAAU,OAAO;EAC5B,iBAAiB,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,sBAAsB;EACjF,MAAM,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,aAAa;EAC7D,iBAAiB,kBAAA,UACd,OAAO,EACP,QAAQ,KAAK,EACb,YAAY,+CAA+C;CAChE,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EACJ,iBAAiB,gBACjB,MACA,iBAAiB,mBACf;EAMJ,IAAI,CAAC,MAAA,SAAS,YAAY,cAAc,GACtC,OAAO,mCAAmC,eAAe;EAE3D,IAAI,CAAC,MAAA,SAAS,YAAY,cAAc,GACtC,OAAO,mCAAmC,eAAe;EAG3D,MAAM,SAAS,MAAA,SAAS,WAAW,MAAM,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1E,IAAI,CAAC,OAAO,SACV,OAAO,wBAAwB,KAAK;EAItC,OAAO,GAAG,KAAK,GAAG,eAAe,KADf,OAAO,QAAQ,cACK,EAAU,SAAS,OAAO,EAAE,GAAG;CACvE;AACF,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "../../common-DeZaonK1.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-D2WB1EA1.mjs";
|
|
3
|
+
import { validator } from "@nhtio/validation";
|
|
4
|
+
import { DateTime, IANAZone } from "luxon";
|
|
5
|
+
//#region src/batteries/tools/time/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Pre-constructed tools for current time lookup and timezone-aware time formatting.
|
|
8
|
+
*
|
|
9
|
+
* @module @nhtio/adk/batteries/tools/time
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Pre-constructed bundled tools for the `time` category. Import individually, the whole
|
|
13
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Return the current time formatted in a given timezone.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* `timezone` defaults to `UTC` when omitted. The ADK has no notion of a "user local"
|
|
20
|
+
* timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for
|
|
21
|
+
* non-UTC formatting.
|
|
22
|
+
*/
|
|
23
|
+
var getCurrentTimeTool = new Tool({
|
|
24
|
+
name: "get_current_time",
|
|
25
|
+
description: "Get current time in an IANA timezone (defaults to UTC).",
|
|
26
|
+
inputSchema: validator.object({ timezone: validator.string().default("UTC").description("IANA timezone (optional, defaults UTC)") }),
|
|
27
|
+
handler: async (args) => {
|
|
28
|
+
const { timezone } = args;
|
|
29
|
+
if (!IANAZone.isValidZone(timezone)) return `Error: Invalid timezone "${timezone}".`;
|
|
30
|
+
return `${timezone}: ${DateTime.now().setZone(timezone).toFormat("cccc, LLLL d, yyyy h:mm:ss a ZZZZ")}`;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Convert a wall-clock time between two IANA timezones.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion
|
|
38
|
+
* uses today's date in the source zone to pick the correct DST offset.
|
|
39
|
+
*/
|
|
40
|
+
var convertTimeTool = new Tool({
|
|
41
|
+
name: "convert_time",
|
|
42
|
+
description: "Convert time between timezones.",
|
|
43
|
+
inputSchema: validator.object({
|
|
44
|
+
source_timezone: validator.string().required().description("Source IANA timezone"),
|
|
45
|
+
time: validator.string().required().description("HH:MM (24h)"),
|
|
46
|
+
target_timezone: validator.string().default("UTC").description("Target IANA timezone (optional, defaults UTC)")
|
|
47
|
+
}),
|
|
48
|
+
handler: async (args) => {
|
|
49
|
+
const { source_timezone: sourceTimezone, time, target_timezone: targetTimezone } = args;
|
|
50
|
+
if (!IANAZone.isValidZone(sourceTimezone)) return `Error: Invalid source timezone "${sourceTimezone}".`;
|
|
51
|
+
if (!IANAZone.isValidZone(targetTimezone)) return `Error: Invalid target timezone "${targetTimezone}".`;
|
|
52
|
+
const parsed = DateTime.fromFormat(time, "HH:mm", { zone: sourceTimezone });
|
|
53
|
+
if (!parsed.isValid) return `Error: Invalid time "${time}". Use HH:MM.`;
|
|
54
|
+
return `${time} ${sourceTimezone} = ${parsed.setZone(targetTimezone).toFormat("HH:mm")} ${targetTimezone}`;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
//#endregion
|
|
58
|
+
export { convertTimeTool, getCurrentTimeTool };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=time.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.mjs","names":[],"sources":["../../../src/batteries/tools/time/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for current time lookup and timezone-aware time formatting.\n *\n * @module @nhtio/adk/batteries/tools/time\n *\n * @remarks\n * Pre-constructed bundled tools for the `time` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { DateTime, IANAZone } from 'luxon'\nimport { validator } from '@nhtio/validation'\n\n/**\n * Return the current time formatted in a given timezone.\n *\n * @remarks\n * `timezone` defaults to `UTC` when omitted. The ADK has no notion of a \"user local\"\n * timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for\n * non-UTC formatting.\n */\nexport const getCurrentTimeTool = new Tool({\n name: 'get_current_time',\n description: 'Get current time in an IANA timezone (defaults to UTC).',\n inputSchema: validator.object({\n timezone: validator\n .string()\n .default('UTC')\n .description('IANA timezone (optional, defaults UTC)'),\n }),\n handler: async (args) => {\n const { timezone } = args as { timezone: string }\n if (!IANAZone.isValidZone(timezone)) {\n return `Error: Invalid timezone \"${timezone}\".`\n }\n const now = DateTime.now().setZone(timezone)\n return `${timezone}: ${now.toFormat('cccc, LLLL d, yyyy h:mm:ss a ZZZZ')}`\n },\n})\n\n/**\n * Convert a wall-clock time between two IANA timezones.\n *\n * @remarks\n * `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion\n * uses today's date in the source zone to pick the correct DST offset.\n */\nexport const convertTimeTool = new Tool({\n name: 'convert_time',\n description: 'Convert time between timezones.',\n inputSchema: validator.object({\n source_timezone: validator.string().required().description('Source IANA timezone'),\n time: validator.string().required().description('HH:MM (24h)'),\n target_timezone: validator\n .string()\n .default('UTC')\n .description('Target IANA timezone (optional, defaults UTC)'),\n }),\n handler: async (args) => {\n const {\n source_timezone: sourceTimezone,\n time,\n target_timezone: targetTimezone,\n } = args as {\n source_timezone: string\n time: string\n target_timezone: string\n }\n\n if (!IANAZone.isValidZone(sourceTimezone)) {\n return `Error: Invalid source timezone \"${sourceTimezone}\".`\n }\n if (!IANAZone.isValidZone(targetTimezone)) {\n return `Error: Invalid target timezone \"${targetTimezone}\".`\n }\n\n const parsed = DateTime.fromFormat(time, 'HH:mm', { zone: sourceTimezone })\n if (!parsed.isValid) {\n return `Error: Invalid time \"${time}\". Use HH:MM.`\n }\n\n const converted = parsed.setZone(targetTimezone)\n return `${time} ${sourceTimezone} = ${converted.toFormat('HH:mm')} ${targetTimezone}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,qBAAqB,IAAI,KAAK;CACzC,MAAM;CACN,aAAa;CACb,aAAa,UAAU,OAAO,EAC5B,UAAU,UACP,OAAO,EACP,QAAQ,KAAK,EACb,YAAY,wCAAwC,EACzD,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,aAAa;EACrB,IAAI,CAAC,SAAS,YAAY,QAAQ,GAChC,OAAO,4BAA4B,SAAS;EAG9C,OAAO,GAAG,SAAS,IADP,SAAS,IAAI,EAAE,QAAQ,QACZ,EAAI,SAAS,mCAAmC;CACzE;AACF,CAAC;;;;;;;;AASD,IAAa,kBAAkB,IAAI,KAAK;CACtC,MAAM;CACN,aAAa;CACb,aAAa,UAAU,OAAO;EAC5B,iBAAiB,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,sBAAsB;EACjF,MAAM,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,aAAa;EAC7D,iBAAiB,UACd,OAAO,EACP,QAAQ,KAAK,EACb,YAAY,+CAA+C;CAChE,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EACJ,iBAAiB,gBACjB,MACA,iBAAiB,mBACf;EAMJ,IAAI,CAAC,SAAS,YAAY,cAAc,GACtC,OAAO,mCAAmC,eAAe;EAE3D,IAAI,CAAC,SAAS,YAAY,cAAc,GACtC,OAAO,mCAAmC,eAAe;EAG3D,MAAM,SAAS,SAAS,WAAW,MAAM,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1E,IAAI,CAAC,OAAO,SACV,OAAO,wBAAwB,KAAK;EAItC,OAAO,GAAG,KAAK,GAAG,eAAe,KADf,OAAO,QAAQ,cACK,EAAU,SAAS,OAAO,EAAE,GAAG;CACvE;AACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-constructed tools for converting values across common measurement units.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/tools/unit_conversion
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pre-constructed bundled tools for the `unit_conversion` category. Import individually, the whole
|
|
8
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
9
|
+
*/
|
|
10
|
+
import { Tool } from "../../../common";
|
|
11
|
+
/**
|
|
12
|
+
* Convert a numeric value between units of the same physical category.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Supported categories: length, mass, volume, temperature, speed, area, data, time, energy,
|
|
16
|
+
* pressure, angle. Uses static conversion tables — no external data required. Temperature is
|
|
17
|
+
* handled specially via a Kelvin intermediate to preserve precision across `C`/`F`/`K`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const convertUnitTool: Tool<import("../../../common").SpooledArtifact>;
|