{"_id":"@ai-path/tb-ai","_rev":"2-5d3f1b9ff2b9e30c07be1b1b7f98479d","name":"@ai-path/tb-ai","dist-tags":{"latest":"0.3.0"},"versions":{"0.2.0":{"name":"@ai-path/tb-ai","version":"0.2.0","license":"MIT","_id":"@ai-path/tb-ai@0.2.0","maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"homepage":"https://github.com/aipathjp/lattica#readme","bugs":{"url":"https://github.com/aipathjp/lattica/issues"},"dist":{"shasum":"3b6b0396e01b720f725f20005b476546f63aac7d","tarball":"https://registry.npmjs.org/@ai-path/tb-ai/-/tb-ai-0.2.0.tgz","fileCount":9,"integrity":"sha512-+oD4G7KleRAdANzntkIyoBvYTWA3iJm0sgiypB824RZ0LgUJ8sIwG+1hAC7bM2brAVvPzwSROawmsq7rxvhZpA==","signatures":[{"sig":"MEUCICriIkqr8yZC+BI/tMbEQrz3uVlsDXKvuq6NjuMJGumTAiEA1QS1uZebTeIJ62gAOQf5IZzvzXlWnT6XuRoOEC2JU8g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":311072},"main":"./dist/index.cjs","type":"module","_from":"file:ai-path-tb-ai-0.2.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"fsakurai","email":"f-sakurai@ai-path.jp"},"_resolved":"/private/var/folders/tf/0c43660d4k1dg4ssxq0n63ww0000gn/T/a525f162ed8580296ffc412c7a112f58/ai-path-tb-ai-0.2.0.tgz","_integrity":"sha512-+oD4G7KleRAdANzntkIyoBvYTWA3iJm0sgiypB824RZ0LgUJ8sIwG+1hAC7bM2brAVvPzwSROawmsq7rxvhZpA==","repository":{"url":"git+https://github.com/aipathjp/lattica.git","type":"git","directory":"packages/ai"},"_npmVersion":"10.9.3","description":"AI-native spreadsheet primitives for Taible: provider-agnostic AI client, undoable AICommand with provenance, NL<->formula, AI columns, smart fill, schema inference, semantic search.","directories":{},"sideEffects":false,"_nodeVersion":"22.18.0","dependencies":{"@ai-path/tb-core":"0.2.0","@ai-path/tb-data":"0.2.0","@ai-path/tb-formula":"0.2.0"},"publishConfig":{"access":"public","provenance":false},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/tb-ai_0.2.0_1783181305145_0.3366210975076873","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@ai-path/tb-ai","version":"0.3.0","description":"AI-native spreadsheet primitives for Taible: provider-agnostic AI client, undoable AICommand with provenance, NL<->formula, AI columns, smart fill, schema inference, semantic search.","license":"MIT","type":"module","sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"repository":{"type":"git","url":"git+https://github.com/aipathjp/lattica.git","directory":"packages/ai"},"homepage":"https://github.com/aipathjp/lattica#readme","bugs":{"url":"https://github.com/aipathjp/lattica/issues"},"dependencies":{"@ai-path/tb-core":"0.3.0","@ai-path/tb-formula":"0.3.0","@ai-path/tb-data":"0.3.0"},"publishConfig":{"access":"public","provenance":false},"scripts":{"build":"tsup","typecheck":"tsc --noEmit"},"_id":"@ai-path/tb-ai@0.3.0","_integrity":"sha512-RPzy71W8NM6Pwpl/Y8RMc2toOuCqXMUFRaMJz+HNWOr8m+y962tmP8A9kDkFi/NzSJp9E2dep21mF3g/2tX4Cg==","_resolved":"/private/var/folders/tf/0c43660d4k1dg4ssxq0n63ww0000gn/T/2339a27dcd979e7de5e39a4dfade8949/ai-path-tb-ai-0.3.0.tgz","_from":"file:ai-path-tb-ai-0.3.0.tgz","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-RPzy71W8NM6Pwpl/Y8RMc2toOuCqXMUFRaMJz+HNWOr8m+y962tmP8A9kDkFi/NzSJp9E2dep21mF3g/2tX4Cg==","shasum":"f3550e4c8c7e64f08bfa370a93903b6c8a45071e","tarball":"https://registry.npmjs.org/@ai-path/tb-ai/-/tb-ai-0.3.0.tgz","fileCount":9,"unpackedSize":311072,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCZMIdSiwxy7iXPR90d+kzGUR4nhg1+lY1SHlyx2FV8JwIgXufGwUm+6Hf3MMWxYXB01TGKVl85s3JAjxhPD2Owsso="}]},"_npmUser":{"name":"fsakurai","email":"f-sakurai@ai-path.jp"},"directories":{},"maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tb-ai_0.3.0_1783188082989_0.9111417396527222"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-04T16:08:25.032Z","modified":"2026-07-04T18:01:23.263Z","0.2.0":"2026-07-04T16:08:25.277Z","0.3.0":"2026-07-04T18:01:23.136Z"},"bugs":{"url":"https://github.com/aipathjp/lattica/issues"},"license":"MIT","homepage":"https://github.com/aipathjp/lattica#readme","repository":{"type":"git","url":"git+https://github.com/aipathjp/lattica.git","directory":"packages/ai"},"description":"AI-native spreadsheet primitives for Taible: provider-agnostic AI client, undoable AICommand with provenance, NL<->formula, AI columns, smart fill, schema inference, semantic search.","maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"readme":"# @ai-path/tb-ai\n\nAI-native spreadsheet primitives for Taible. Every feature is built on a\nprovider-agnostic `AIProvider` interface and a governance layer (`AIClient`)\nthat enforces a call budget and accumulates token usage, so the package never\ndepends on a specific model vendor. It ships a deterministic `MockProvider` for\ntests and offline development, and a suite of grid-aware capabilities:\nnatural-language → formula/operation, AI-generated columns, smart fill (with a\ndeterministic rule fast-path), semantic search, schema inference, anomaly\ndetection, text operations, and a HITL workflow planner/runner.\n\n## Install\n\n```sh\npnpm add @ai-path/tb-ai\n```\n\n## API overview\n\n### Provider & client\n\n```ts\nimport { MockProvider, AIClient } from '@ai-path/tb-ai';\n\nconst provider = new MockProvider({ texts: ['=A1+B1'], objects: [{ formula: 'A1+B1' }] });\nconst client = new AIClient(provider, { maxCalls: 50, maxOutputTokens: 512 });\n\nawait client.generateText({ prompt: 'hi' });\nclient.getUsage();     // { inputTokens, outputTokens }\nclient.getCallCount();\n```\n\n### Natural language → formula\n\n`nlToFormula` returns a validated `NlFormulaResult` (the formula is parsed by\n`@ai-path/tb-formula`, so `valid`/`error` reflect real syntax checks).\n\n```ts\nimport { nlToFormula, explainFormula, fixFormula } from '@ai-path/tb-ai';\n\nconst result = await nlToFormula(client, 'sum of column A', { context: 'A1:A20 is sales' });\nresult.formula; // e.g. '=SUM(A1:A20)'\nresult.valid;   // true when it parses\n\nawait explainFormula(client, '=VLOOKUP(A1,B:C,2,0)');\nawait fixFormula(client, '=SUM(A1:A', 'unexpected end of input');\n```\n\n### Generate a column & smart fill\n\n```ts\nimport { generateColumn, smartFill } from '@ai-path/tb-ai';\n\nconst cells = await generateColumn(\n  client,\n  [['Acme', 'NY'], ['Globex', 'CA']],\n  { template: 'Write a one-line tagline for {0} based in {1}.' },\n);\ncells[0]?.value;       // generated text\ncells[0]?.provenance;  // { model, prompt, usage }\n\n// smartFill prefers a deterministic rule; falls back to the client only if needed.\nconst filled = await smartFill(\n  [{ input: 'john@x.com', output: 'john' }],\n  ['jane@x.com', 'bob@x.com'],\n  client,\n); // ['jane', 'bob']\n```\n\n### Semantic search\n\n```ts\nimport { SemanticIndex, cosineSimilarity, type Embedder } from '@ai-path/tb-ai';\n\nconst embedder: Embedder = (text) => /* your embedding model */ embed(text);\nconst index = new SemanticIndex(embedder);\nawait index.add('row-1', 'quarterly revenue report');\nawait index.add('row-2', 'office supplies invoice');\nconst hits = await index.search('earnings', 5); // [{ id, score }, …] by descending similarity\n```\n\n### NL → grid operation & workflow\n\n`nlToOperation` returns a safe, validated `GridOperation` (sort/filter/summarize/none).\n`planWorkflow` plans a list of `WorkflowStep`s restricted to allowed tool names,\nand `WorkflowRunner` executes approved steps with a HITL approval callback and an\naudit trail.\n\n```ts\nimport { nlToOperation, planWorkflow, WorkflowRunner } from '@ai-path/tb-ai';\n\nconst op = await nlToOperation(client, 'sort by revenue descending', ['name', 'revenue']);\n// e.g. { op: 'sort', col: 1, direction: 'desc' }\n\nconst steps = await planWorkflow(client, 'clean and sort the data', ['sort', 'filter']);\nconst runner = new WorkflowRunner((step) => apply(step));\nconst audit = runner.run(steps, (step) => step.tool !== 'filter'); // reject filters\n```\n\n### Other exports\n\n- `inferCellType` / `inferColumnType` / `normalizeValue` / `detectDuplicateRows` — schema inference.\n- `zScoreOutliers` / `iqrOutliers` / `detectColumnOutliers` (+ `mean`, `stddev`) — anomaly detection.\n- `summarizeValues` / `translateValues` / `classifyValues` — bulk text operations.\n- `inferRule` / `applyRule` (`FillRule`) — the deterministic fill primitives behind `smartFill`.\n- `suggestRule` / `matchesSpec` / `fitRate` (`RuleSpec`) — rule generation.\n- `withProvenance` (`Provenance`, `AICommand`) — attach model/usage provenance to AI-produced edits.\n","readmeFilename":"README.md"}