{"_id":"@ai-path/lattica-ai","_rev":"2-dd0bce2f9223bcf97bb847f2594c681a","name":"@ai-path/lattica-ai","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@ai-path/lattica-ai","version":"0.1.0","license":"MIT","_id":"@ai-path/lattica-ai@0.1.0","maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"dist":{"shasum":"745285f9cd43796d69a07a99ddfe637d8f66f866","tarball":"https://registry.npmjs.org/@ai-path/lattica-ai/-/lattica-ai-0.1.0.tgz","fileCount":9,"integrity":"sha512-cqhafZd8n13N0sFFQ1ygo3BCYLeRVZOvZdmAjygRs+FCLT7ZteXvljBR5ARGR6+lAjMDcE/44D2qhisKyPQMKQ==","signatures":[{"sig":"MEQCIHm+2/zuQfegp12JiaUSL8nPsD/NLa4ybInJVDz1NqtGAiB+ATd6zXw2PxPnv6QlUmwTiy2fMvjSLych45YHm/LrXw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":310932},"main":"./dist/index.cjs","type":"module","_from":"file:ai-path-lattica-ai-0.1.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/f9044690827f24c011ef58835ad1929a/ai-path-lattica-ai-0.1.0.tgz","_integrity":"sha512-cqhafZd8n13N0sFFQ1ygo3BCYLeRVZOvZdmAjygRs+FCLT7ZteXvljBR5ARGR6+lAjMDcE/44D2qhisKyPQMKQ==","_npmVersion":"10.9.3","description":"AI-native spreadsheet primitives for Lattica: 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/lattica-core":"0.1.1","@ai-path/lattica-data":"0.1.2","@ai-path/lattica-formula":"0.1.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lattica-ai_0.1.0_1783177110201_0.722866726225657","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Renamed to @ai-path/tb-ai (product: Taible). Install @ai-path/tb-ai instead."}},"time":{"created":"2026-07-04T14:58:30.055Z","modified":"2026-07-04T16:08:49.978Z","0.1.0":"2026-07-04T14:58:30.382Z"},"license":"MIT","description":"AI-native spreadsheet primitives for Lattica: 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/lattica-ai\n\nAI-native spreadsheet primitives for Lattica. 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/lattica-ai\n```\n\n## API overview\n\n### Provider & client\n\n```ts\nimport { MockProvider, AIClient } from '@ai-path/lattica-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/lattica-formula`, so `valid`/`error` reflect real syntax checks).\n\n```ts\nimport { nlToFormula, explainFormula, fixFormula } from '@ai-path/lattica-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/lattica-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/lattica-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/lattica-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"}