{"_id":"@langchain/typesafe","_rev":"3-0e91d761a0c21d102618db628f8fa3e5","name":"@langchain/typesafe","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.1":{"name":"@langchain/typesafe","version":"0.0.1","author":{"name":"LangChain"},"license":"MIT","_id":"@langchain/typesafe@0.0.1","maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"dist":{"shasum":"a205f14cc32237f2ca075a4a4cba865ddde9653a","tarball":"https://registry.npmjs.org/@langchain/typesafe/-/typesafe-0.0.1.tgz","fileCount":49,"integrity":"sha512-ldhcpKfVZ6F65ps3vi073cbmTchJhYwxcHJyNhXx4ZwIJpeA8HJ9/kOGZHsN1A0Al48Qbxgvy97ZsHlbJ8P+vA==","signatures":[{"sig":"MEUCIBpHVAAlLhCnJTw/QlpE0PeifyR5WTt48ISWp3KQnfMkAiEAz6xC7OljYFNbRwqsHfyoQ1SD6noAJe/f3y6ZvGN9FNw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":228667},"main":"./dist/index.cjs","type":"module","_from":"file:langchain-typesafe-0.0.1.tgz","types":"./dist/index.d.cts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"input":"./src/index.ts","import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./package.json":"./package.json"},"scripts":{"test":"vitest run","build":"turbo build:compile --filter @langchain/typesafe --output-logs new-only","clean":"rm -rf .turbo dist/","test:int":"vitest run --mode int","test:watch":"vitest","build:compile":"tsdown"},"_npmUser":{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},"_resolved":"/private/var/folders/j4/cz00grtx5nxdjcxw3cysv7zm0000gn/T/1768e212ffcc7aa1acbd3403e32a5fb4/langchain-typesafe-0.0.1.tgz","_integrity":"sha512-ldhcpKfVZ6F65ps3vi073cbmTchJhYwxcHJyNhXx4ZwIJpeA8HJ9/kOGZHsN1A0Al48Qbxgvy97ZsHlbJ8P+vA==","repository":{"url":"git+ssh://git@github.com/langchain-ai/langchainjs.git","type":"git"},"_npmVersion":"11.5.1","description":"TypeSafe System One integration for LangChain.js (Jev classifier).","directories":{},"_nodeVersion":"24.6.0","dependencies":{"zod":"^4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"dotenv":"^17.4.2","vitest":"^4.1.11","typescript":"~7.0.2","@langchain/core":"^1.2.11","@langchain/tsconfig":"0.0.1","@tsconfig/recommended":"^1.0.3"},"peerDependencies":{"@langchain/core":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/typesafe_0.0.1_1789697346664_0.38049325266997536","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@langchain/typesafe","version":"0.0.2","author":{"name":"LangChain"},"license":"MIT","_id":"@langchain/typesafe@0.0.2","maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"dist":{"shasum":"c4bef22fd8509d9650ef91d255df8f9925678f30","tarball":"https://registry.npmjs.org/@langchain/typesafe/-/typesafe-0.0.2.tgz","fileCount":69,"integrity":"sha512-FwNQ5ZzKRvguO4zGhwRsOxumH7zNQjfGdlfdla7KUUGCGfXbGpqXtFmxw+4DRdTCVxgsJQ3NIpke9WICukWlnQ==","signatures":[{"sig":"MEQCIAUjkAywNGeU5JqZ+VlKcVMORaWe6yDI81XG/nPSaPGwAiAiEnEN5x1qXHcBtvEyh9r/6oGMFJAU5Z+KB1mpTkSkmw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIB6G47niHLe6g3vw07jWd/h4IChzfhYDMM/b/lkXKUmNAiEAnWbmPlxcQ6nKTrCZ73OKrTCx3SAMwuQiWvCfHkYB3m4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@langchain%2ftypesafe@0.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":311250},"main":"./dist/index.cjs","type":"module","_from":"file:langchain-typesafe-0.0.2.tgz","types":"./dist/index.d.cts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"input":"./src/index.ts","import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./middleware":{"input":"./src/middleware/index.ts","import":{"types":"./dist/middleware/index.d.ts","default":"./dist/middleware/index.js"},"require":{"types":"./dist/middleware/index.d.cts","default":"./dist/middleware/index.cjs"}},"./package.json":"./package.json"},"scripts":{"test":"vitest run","build":"turbo build:compile --filter @langchain/typesafe --output-logs new-only","clean":"rm -rf .turbo dist/","test:int":"vitest run --mode int","test:watch":"vitest","build:compile":"tsdown"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"2a463801-b2b1-453b-95f5-fbe2394e4ca9"}},"_resolved":"/tmp/407677d1f0a43bb2e04dac98ae6b70ee/langchain-typesafe-0.0.2.tgz","_integrity":"sha512-FwNQ5ZzKRvguO4zGhwRsOxumH7zNQjfGdlfdla7KUUGCGfXbGpqXtFmxw+4DRdTCVxgsJQ3NIpke9WICukWlnQ==","repository":{"url":"git+ssh://git@github.com/langchain-ai/langchainjs.git","type":"git"},"_npmVersion":"11.5.1","description":"TypeSafe System One integration for LangChain.js (Jev classifier).","directories":{},"_nodeVersion":"24.6.0","dependencies":{"zod":"^4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"dotenv":"^17.4.2","vitest":"^4.1.11","langchain":"^1.5.15","typescript":"~7.0.2","@langchain/core":"^1.2.14","@langchain/openai":"^1.5.13","@langchain/tsconfig":"0.0.1","@tsconfig/recommended":"^1.0.3"},"peerDependencies":{"langchain":"^1.0.0","@langchain/core":"^1.0.0"},"peerDependenciesMeta":{"langchain":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typesafe_0.0.2_1790817809702_0.07425289029866855","host":"s3://npm-registry-packages-npm-production"}},"0.1.0":{"_id":"@langchain/typesafe@0.1.0","bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"dist":{"shasum":"5d5b2f924b309b13b880ddce11e08d37de02c8d8","tarball":"https://registry.npmjs.org/@langchain/typesafe/-/typesafe-0.1.0.tgz","fileCount":75,"integrity":"sha512-lCu8YEPtdutj3vLXRAhN6kuUNk1E266ZsBIGfDWm8Pv2t2LLp7Ak+BiGA0wOx1F+JmjvDVbaM0a1C+Tdc58H8g==","signatures":[{"sig":"MEUCIQCqSTnR6fNjXLgwViyLwhmwU014+ZglNEzAjdQDkJmzYAIgX3yMp3O/X4pgtL610CUgtkD/6uD9iio12r/uXn9ewpk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDIpDywsdkKPQOwIDiHDARBhuOi8z2ETYzP90uFeLAamwIhAIJHnaK7lcpshgGZqCHf8+tyTavggWDUMHHlcIONiXDu"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@langchain%2ftypesafe@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":295215},"main":"./dist/index.cjs","name":"@langchain/typesafe","type":"module","_from":"file:langchain-typesafe-0.1.0.tgz","types":"./dist/index.d.cts","author":{"name":"LangChain"},"module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"input":"./src/index.ts","import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./middleware":{"input":"./src/middleware/index.ts","import":{"types":"./dist/middleware/index.d.ts","default":"./dist/middleware/index.js"},"require":{"types":"./dist/middleware/index.d.cts","default":"./dist/middleware/index.cjs"}},"./package.json":"./package.json"},"license":"MIT","scripts":{"test":"vitest run","build":"turbo build:compile --filter @langchain/typesafe --output-logs new-only","clean":"rm -rf .turbo dist/","test:int":"vitest run --mode int","test:watch":"vitest","build:compile":"tsdown"},"version":"0.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"2a463801-b2b1-453b-95f5-fbe2394e4ca9"}},"homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","_resolved":"/tmp/70de4fc2a963ee4f875b09178899c8c0/langchain-typesafe-0.1.0.tgz","_integrity":"sha512-lCu8YEPtdutj3vLXRAhN6kuUNk1E266ZsBIGfDWm8Pv2t2LLp7Ak+BiGA0wOx1F+JmjvDVbaM0a1C+Tdc58H8g==","repository":{"url":"git+ssh://git@github.com/langchain-ai/langchainjs.git","type":"git"},"_npmVersion":"11.19.1","description":"TypeSafe System One integration for LangChain.js (Jev classifier).","directories":{},"maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"_nodeVersion":"24.22.1","dependencies":{"zod":"^4.6.6"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"dotenv":"^18.0.9","vitest":"^5.0.5","langchain":"^1.6.5","typescript":"~7.0.2","@langchain/core":"^1.4.0","@langchain/openai":"1.8.4","@langchain/tsconfig":"0.0.1","@tsconfig/recommended":"^1.0.3"},"peerDependencies":{"langchain":"^1.0.0","@langchain/core":"^1.4.0"},"peerDependenciesMeta":{"langchain":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/typesafe_0.1.0_1794434686951_0.8002621289621537"}}},"time":{"created":"2026-09-18T02:09:06.436Z","modified":"2026-11-11T22:04:47.452Z","0.0.1":"2026-09-18T02:09:06.793Z","0.0.2":"2026-10-01T01:23:29.801Z","0.1.0":"2026-11-11T22:04:47.040Z"},"bugs":{"url":"https://github.com/langchain-ai/langchainjs/issues"},"author":{"name":"LangChain"},"license":"MIT","homepage":"https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-typesafe/","repository":{"url":"git+ssh://git@github.com/langchain-ai/langchainjs.git","type":"git"},"description":"TypeSafe System One integration for LangChain.js (Jev classifier).","maintainers":[{"name":"lc-oss-admin","email":"oss-admin@langchain.dev"},{"name":"langchain-security","email":"infra@langchain.dev"}],"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.4.0\" },\n  \"resolutions\": { \"@langchain/core\": \"^1.4.0\" },\n  \"pnpm\": { \"overrides\": { \"@langchain/core\": \"^1.4.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\nconst result = await classifier.invoke({\n  state: {\n    message: \"Help! My payouts have been failing for 3 days.\",\n    account_tier: \"enterprise\",\n  },\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\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`TypeSafeClassifier` is a LangChain decision model (`BaseDecisionModel` from `@langchain/core/decisions`), so questions are sent with each request and the question and answer types are the shared ones from core.\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\nFour 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;\nresult.boxes.dog;\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| `box`    | where something is in an image              | the box's edges as fractions of the image height and width                                   |\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\nEvery question requires `instructions`.\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({\n  state: [new HumanMessage(\"...\"), new AIMessage(\"...\")],\n  questions,\n});\nawait classifier.invoke({\n  state: { conversation: messages, account: { tier: \"pro\" } },\n  questions,\n});\n```\n\n### Images\n\nImage content blocks with inline base64 data or a base64 `data:` URL can appear anywhere in `state` or in question `instructions` and `criteria`, including inside messages. They are sent to TypeSafe as request assets. PNG and JPEG images are supported; images are not downloaded from remote URLs.\n\n```ts\nconst result = await classifier.invoke({\n  state: { type: \"image\", data: imageData, mimeType: \"image/png\" },\n  questions: { dog: { type: \"box\", instructions: \"Where is the dog?\" } },\n});\nresult.boxes.dog.box; // { top, bottom, left, right }\n```\n\n### Tracing\n\nCalls appear in LangSmith as LLM runs with `ls_provider: \"typesafe\"` and the model name, nested inside whatever agent or chain invoked them. Token usage is reported as `usage_metadata` in the run output. The API key is redacted before it reaches the tracer.\n\n### Errors\n\n```ts\nimport { TypeSafeRateLimitError } from \"@langchain/typesafe\";\n\ntry {\n  await classifier.invoke(request);\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## Agent middleware\n\nLangChain's `modelRouterMiddleware` and `autoModeMiddleware` accept any decision model as their `classifier`. Pass a `TypeSafeClassifier` to use TypeSafe.\n\n> **Deprecated:** `@langchain/typesafe/middleware` is deprecated since 0.1.0 and will be removed in 0.2.0. Import the middleware from `langchain` and pass `classifier: new TypeSafeClassifier()` instead.\n\n### `modelRouterMiddleware`\n\nClassifies the latest human message once per agent run with a `Choice` question, then routes every model call in that run to the selected model:\n\n```ts\nimport { createAgent, modelRouterMiddleware } from \"langchain\";\nimport { TypeSafeClassifier } from \"@langchain/typesafe\";\n\nconst agent = createAgent({\n  model: \"openai:gpt-5-mini\",\n  middleware: [\n    modelRouterMiddleware({\n      choices: {\n        fast: {\n          model: \"openai:gpt-5-mini\",\n          criteria: \"Simple, well-scoped tasks.\",\n        },\n        powerful: {\n          model: \"openai:gpt-5\",\n          criteria: \"Complex tasks requiring deeper reasoning.\",\n        },\n      },\n      instructions: \"Choose the least costly model suited to the task.\",\n      classifier: new TypeSafeClassifier(),\n    }),\n  ],\n});\n```\n\n### `autoModeMiddleware`\n\nClassifies calls to explicitly configured tools and blocks risky calls before they run. It blocks rather than asking, and composes with `humanInTheLoopMiddleware` rather than replacing it:\n\n```ts\nimport { autoModeMiddleware, createAgent } from \"langchain\";\nimport { TypeSafeClassifier } from \"@langchain/typesafe\";\n\nconst agent = createAgent({\n  model: \"openai:gpt-5\",\n  tools: [runSqlTool, sendEmailTool],\n  middleware: [\n    autoModeMiddleware({\n      tools: [runSqlTool, sendEmailTool],\n      criteria: {\n        true: \"The call writes, deletes, publishes, or changes access.\",\n        false: \"The call only reads public or user-provided data.\",\n      },\n      classifier: new TypeSafeClassifier(),\n    }),\n  ],\n});\n```\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"}