{"_id":"@langchain/typesafe","name":"@langchain/typesafe","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@langchain/typesafe","version":"0.0.1","description":"TypeSafe System One integration for LangChain.js (Jev classifier).","author":{"name":"LangChain"},"license":"MIT","type":"module","engines":{"node":">=20"},"repository":{"type":"git","url":"git+ssh://git@github.com/langchain-ai/langchainjs.git"},"homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","dependencies":{"zod":"^4"},"peerDependencies":{"@langchain/core":"^1.0.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.3","dotenv":"^17.4.2","typescript":"~7.0.2","vitest":"^4.1.11","@langchain/core":"^1.2.11","@langchain/tsconfig":"0.0.1"},"publishConfig":{"access":"public"},"main":"./dist/index.cjs","types":"./dist/index.d.cts","exports":{".":{"input":"./src/index.ts","require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"},"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"module":"./dist/index.js","scripts":{"build":"turbo build:compile --filter @langchain/typesafe --output-logs new-only","build:compile":"tsdown","clean":"rm -rf .turbo dist/","test":"vitest run","test:watch":"vitest","test:int":"vitest run --mode int"},"_id":"@langchain/typesafe@0.0.1","bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"_integrity":"sha512-ldhcpKfVZ6F65ps3vi073cbmTchJhYwxcHJyNhXx4ZwIJpeA8HJ9/kOGZHsN1A0Al48Qbxgvy97ZsHlbJ8P+vA==","_resolved":"/private/var/folders/j4/cz00grtx5nxdjcxw3cysv7zm0000gn/T/1768e212ffcc7aa1acbd3403e32a5fb4/langchain-typesafe-0.0.1.tgz","_from":"file:langchain-typesafe-0.0.1.tgz","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-ldhcpKfVZ6F65ps3vi073cbmTchJhYwxcHJyNhXx4ZwIJpeA8HJ9/kOGZHsN1A0Al48Qbxgvy97ZsHlbJ8P+vA==","shasum":"a205f14cc32237f2ca075a4a4cba865ddde9653a","tarball":"https://registry.npmjs.org/@langchain/typesafe/-/typesafe-0.0.1.tgz","fileCount":49,"unpackedSize":228667,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBpHVAAlLhCnJTw/QlpE0PeifyR5WTt48ISWp3KQnfMkAiEAz6xC7OljYFNbRwqsHfyoQ1SD6noAJe/f3y6ZvGN9FNw="}]},"_npmUser":{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},"directories":{},"maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/typesafe_0.0.1_1789697346664_0.38049325266997536"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-18T02:09:06.436Z","0.0.1":"2026-09-18T02:09:06.793Z","modified":"2026-09-18T02:09:07.034Z"},"maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"description":"TypeSafe System One integration for LangChain.js (Jev classifier).","homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","repository":{"type":"git","url":"git+ssh://git@github.com/langchain-ai/langchainjs.git"},"author":{"name":"LangChain"},"bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"license":"MIT","readme":"# @langchain/typesafe\n\nThis package contains the LangChain.js integration for [TypeSafe](https://typesafe.ai) System One models.\n\nTypeSafe's `jev` model answers typed questions about unstructured input — no string generation, no parsing, no schema wrangling. It returns calibrated probabilities in 70–500ms, and every question in a single request is evaluated in parallel, so asking ten questions costs barely more than asking one.\n\n## Installation\n\n```bash npm2yarn\nnpm install @langchain/typesafe @langchain/core\n```\n\nThis package passes `@langchain/core` as a peer dependency. Make sure your project resolves a single instance of it:\n\n```json\n{\n  \"overrides\": { \"@langchain/core\": \"^1.0.0\" },\n  \"resolutions\": { \"@langchain/core\": \"^1.0.0\" },\n  \"pnpm\": { \"overrides\": { \"@langchain/core\": \"^1.0.0\" } }\n}\n```\n\n## Usage\n\nSet `TYPESAFE_API_KEY` in your environment, then:\n\n```ts\nimport { TypeSafeClassifier } from \"@langchain/typesafe\";\n\nconst classifier = new TypeSafeClassifier({\n  questions: {\n    department: {\n      type: \"choice\",\n      criteria: {\n        billing: \"Payment and payout issues\",\n        technical: \"Bugs and outages\",\n        sales: null,\n      },\n      instructions: \"Which team should handle this?\",\n    },\n    urgent: { type: \"noul\", instructions: \"Does this convey urgency?\" },\n    frustration: {\n      type: \"score\",\n      criteria: [\"calm\", \"frustrated\", \"angry\"],\n      instructions: \"How frustrated is the writer?\",\n    },\n  },\n});\n\nconst result = await classifier.invoke({\n  message: \"Help! My payouts have been failing for 3 days.\",\n  account_tier: \"enterprise\",\n});\n\nresult.answers.department; // { type: \"choice\", choice: \"billing\", confidence: 0.99, probabilities: {...} }\nresult.answers.urgent; // { type: \"noul\", noul: 0.97 }\nresult.answers.frustration; // { type: \"score\", score: 1.3, legend: { 0: \"calm\", ... }, ... }\n```\n\n`result.model` is the versioned model that actually answered (e.g. `jev-1.13.0`), not the alias you sent — `jev-latest` in, `jev-1.13.0` out.\n\nThree read-only, non-enumerable helpers partition `answers` by variant, keyed by question id — handy when you only care about one kind of question:\n\n```ts\nresult.choices.department; // same object as result.answers.department\nresult.nouls.urgent;\nresult.scores.frustration;\n```\n\nBecause they're non-enumerable, they never duplicate `answers` in `JSON.stringify(result)` or a LangSmith trace.\n\n### Question types\n\n| Type     | Ask                                         | Get back                                                                                     |\n| -------- | ------------------------------------------- | -------------------------------------------------------------------------------------------- |\n| `choice` | pick one of N labels you define             | the winning label, the full distribution, and a confidence                                   |\n| `score`  | position on an ordered rubric (low to high) | a probability-weighted number that may land _between_ levels, plus a legend and distribution |\n| `noul`   | a single yes/no proposition                 | a bare probability from 0 to 1                                                               |\n\nA Noul answer carries **no `confidence` and no `probabilities`**. For a binary question the probability is the confidence: 0.97 means \"almost certainly yes\", and 0.5 means genuine uncertainty. Threshold it when your code needs a hard decision.\n\n`score` and `choice` may omit `instructions` if `criteria` alone is clear. A `noul` needs at least one of the two.\n\n### Messages as input\n\nLangChain messages are the common unit of context, so they are accepted anywhere in the input and converted automatically:\n\n```ts\nawait classifier.invoke([new HumanMessage(\"...\"), new AIMessage(\"...\")]);\nawait classifier.invoke({ conversation: messages, account: { tier: \"pro\" } });\n```\n\n### Tracing\n\n`TypeSafeClassifier` is a `Runnable`, so calls appear in LangSmith traces with their inputs, outputs and configuration, nested inside whatever agent or chain invoked them. The API key is redacted before it reaches the tracer. Note that LangSmith does not attribute token cost to non-LLM runs, so `usage` appears in the traced output rather than as a costed metric.\n\n### Errors\n\n```ts\nimport { TypeSafeRateLimitError } from \"@langchain/typesafe\";\n\ntry {\n  await classifier.invoke(input);\n} catch (error) {\n  if (TypeSafeRateLimitError.isInstance(error)) {\n    console.log(error.retryAfterMs, error.requestId);\n  }\n}\n```\n\nUse `.isInstance()` rather than `instanceof` — it stays correct when more than one copy of the library ends up in a dependency tree.\n\nErrors carry `status`, `requestId`, `body` and `headers` as properties, but never render the response body into their message, because TypeSafe error bodies echo the request — including the content you asked it to classify.\n\nRetries are handled by LangChain's `AsyncCaller`; configure them with `maxRetries` and `maxConcurrency` on the constructor.\n\n## Development\n\n```bash\npnpm install\npnpm build --filter @langchain/typesafe\npnpm test\n```\n\nIntegration tests hit the live API and are excluded from `pnpm test`. To run them, put your key in `libs/providers/langchain-typesafe/.env` (this path, not the repo root — `dotenv` resolves relative to the package directory):\n\n```\nTYPESAFE_API_KEY=your-key\n```\n\nthen:\n\n```bash\npnpm test:int\n```\n\nThey skip rather than fail when no key is present.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-950c316fe03f93dc539aca3030c27612"}