{"_id":"typechat","_rev":"7-e71dc77ce7c927e2f51f1bd50fd10af6","name":"typechat","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.10":{"name":"typechat","version":"0.0.10","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.0.10","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"cb3c302cc218f078999c34eaf22aa6300dfb767b","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.0.10.tgz","fileCount":18,"integrity":"sha512-iF/wLLaZWt4Q9WO8stpq3NKilAa4b8hnCD16EirdhaxzAYk80MCb1wnW1il7GhkMNJuhJUD38dxs8q4A/EdxJw==","signatures":[{"sig":"MEUCIQCE/ZQkYpGoXDneEc7H9UPA2KsDfTvXUfFLMOowyyXhZwIgHRBFyzT3O1EfQ8ZeCpLZTjFGudq4mMWo0SgQ/0yIIqE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":48559},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=18"},"gitHead":"716abab2ff3dfe4107bd14340f5f7ef95545d742","scripts":{"build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"9.6.7","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"20.3.0","dependencies":{"axios":"^1.4.0","typescript":"^5.1.3"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.3.3"},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.0.10_1689869255335_0.03453805960426748","host":"s3://npm-registry-packages"}},"0.1.0":{"name":"typechat","version":"0.1.0","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.1.0","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"fcd157b8dd59596b4ab79b56f82c2eb0f9a83a99","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.1.0.tgz","fileCount":25,"integrity":"sha512-1QeypvhyoXz/1DssDq8NbIzRHX3V20b+TWfrO7t4wd3o8OygcQO3Zo9MRNSBwK0Pyw+Fw6MmE/hOFi372gpvzA==","signatures":[{"sig":"MEUCIQDIuLBMMZ4X5wZ0gGbiIGMncksue0xYwwivUtdkctxo0gIgc7pB+xtjB9p/Qx5ybGR03hrWUrS6ybco7b12CkbqsnQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":61350},"engines":{"node":">=18"},"exports":{".":"./dist/index.js","./ts":"./dist/ts/index.js","./zod":"./dist/zod/index.js","./interactive":"./dist/interactive/index.js"},"gitHead":"11dd31668a833eb67806756bb78f2f521002b2c3","scripts":{"build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"10.2.4","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"20.11.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.10.4"},"peerDependencies":{"zod":"^3.22.4","typescript":"^5.3.3"},"peerDependenciesMeta":{"zod":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.1.0_1711387211537_0.40974327784992304","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"typechat","version":"0.1.1","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.1.1","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"faa5bb0d1b64785f456ce9c3ec7302c577d92509","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.1.1.tgz","fileCount":25,"integrity":"sha512-Sw96vmkYqbAahqam7vCp8P/MjIGsR26Odz17UHpVGniYN5ir2B37nRRkoDuRpA5djwNQB+W5TB7w2xoF6kwbHQ==","signatures":[{"sig":"MEYCIQCvBhl26uTCUybwwXs8CzufbiaWSWYjJ3+LyMtxUOFXcwIhAM4ErvFuXT9SE0TjMj4psGM3gjr97DanW0PH/yKzQCWG","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":62315},"engines":{"node":">=18"},"exports":{".":"./dist/index.js","./ts":"./dist/ts/index.js","./zod":"./dist/zod/index.js","./interactive":"./dist/interactive/index.js"},"gitHead":"fb4bdeb8eefc5ed33718c5ed83417f38f83f1480","scripts":{"build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"10.2.4","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"20.11.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.10.4"},"peerDependencies":{"zod":"^3.22.4","typescript":"^5.3.3"},"peerDependenciesMeta":{"zod":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.1.1_1725472427940_0.8296266826345016","host":"s3://npm-registry-packages"}},"0.1.2":{"name":"typechat","version":"0.1.2","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.1.2","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"e55c03d0cf98c281ea6eff5e2aa9bd467926b158","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.1.2.tgz","fileCount":26,"integrity":"sha512-yZQ9IcHeMYZPZZa7+JZh5b5zlXvGo8Oj9eafMfZbmQ/frqipmjNCwF7F3NjcZHTT32ri+AdECnpH5Ds6A4K4aQ==","signatures":[{"sig":"MEUCIQCp9fEL/UtNgJlZrWmkdUPSjO9af8igunNjTJs0kN/aXAIgH6wjwv5d3G3AVGl/CJOzZS4gT4wkAbuIcp9+uFz6LXQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":65117},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":{".":"./dist/index.js","./ts":"./dist/ts/index.js","./zod":"./dist/zod/index.js","./interactive":"./dist/interactive/index.js"},"gitHead":"b198d2e0b61ee4166d4b57fc785d7bcec7442d87","scripts":{"build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces","postpublish":"node -e \"require('fs').unlinkSync('SECURITY.md')\"","prepublishOnly":"node -e \"require('fs').copyFileSync('../SECURITY.md','SECURITY.md')\"","publish-package":"npm publish","publish-package:dry-run":"npm publish --dry-run"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"10.9.3","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"22.18.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.10.4"},"peerDependencies":{"zod":"^3.22.4","typescript":"^5.3.3"},"peerDependenciesMeta":{"zod":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.1.2_1772056307426_0.8169446446660318","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"typechat","version":"0.1.3","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.1.3","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"1980868b4cb86dd1da8965a171f05f540d92001b","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.1.3.tgz","fileCount":26,"integrity":"sha512-Reydbu+bs9ITrvxPsIl6Q+SD/ZYOYDQcgacFY+8BqqQZ8If1xicxQBGJJwj8pKgK2t7SVTHxbGdrubfe4g0pEA==","signatures":[{"sig":"MEYCIQCQ6yU7aLbMTAxenNNo1dorgksjZo6cL7bVG6ZbL1vcswIhAKZpxzhDxiqJOGVH6WlfVNPkc1l/oIDX/500feJkhjZK","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":84263},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":{".":"./dist/index.js","./ts":"./dist/ts/index.js","./zod":"./dist/zod/index.js","./interactive":"./dist/interactive/index.js"},"gitHead":"ef7d87e8eef96e284b333536946f145ba6718af8","scripts":{"test":"npm run build && tsc -p test && node --test out/validate.test.js out/zod.test.js out/program.test.js tests/model.test.mjs","build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces","postpublish":"node -e \"require('fs').unlinkSync('SECURITY.md')\"","prepublishOnly":"node -e \"require('fs').copyFileSync('../SECURITY.md','SECURITY.md')\"","publish-package":"npm publish","publish-package:dry-run":"npm publish --dry-run"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"10.9.3","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"devDependencies":{"undici":"^6.27.0","@types/node":"^20.10.4"},"peerDependencies":{"zod":"^4.4.3","undici":"^6.0.0","typescript":"^5.3.3"},"peerDependenciesMeta":{"zod":{"optional":true},"undici":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.1.3_1785198651248_0.8136400789660947","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"typechat","version":"0.1.4","keywords":["schema","LLM","prompt","TypeScript","validation"],"author":{"name":"Microsoft"},"license":"MIT","_id":"typechat@0.1.4","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"homepage":"https://github.com/microsoft/TypeChat#readme","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"9e397c50336c9dd6dc0aa615bc91b25ca6610b54","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.1.4.tgz","fileCount":26,"integrity":"sha512-ICbPaUL1XSunAHCvfNhzHEL3kKU76xnJ9Z+qVggaaCxIo2vSuOyniwp895sfpXy47arQdP7lDoC8zt1JkU7iuA==","signatures":[{"sig":"MEYCIQDtRDlz158qmFMqdDq9vTTjQk0rcwTxsfqtPOz+lh6FcQIhALB+XTMgkfaiO7w83sk+s6GTknqXtdDXo260s0k2P4BM","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":85733},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=22.19.0"},"exports":{".":"./dist/index.js","./ts":"./dist/ts/index.js","./zod":"./dist/zod/index.js","./interactive":"./dist/interactive/index.js"},"gitHead":"cdc7206e0e68f8e27a6656230e4890f03f144b03","scripts":{"test":"npm run build && tsc -p test && node --test out/validate.test.js out/zod.test.js out/program.test.js tests/model.test.mjs","build":"tsc -p src","prepare":"npm run build-all","build-all":"npm run build --workspaces","postpublish":"node -e \"require('fs').unlinkSync('SECURITY.md')\"","prepublishOnly":"node -e \"require('fs').copyFileSync('../SECURITY.md','SECURITY.md')\"","publish-package":"npm publish","publish-package:dry-run":"npm publish --dry-run"},"_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"10.9.3","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"devDependencies":{"undici":"^8.10.0","@types/node":"^26.2.0"},"peerDependencies":{"zod":"^4.4.3","undici":"^8.10.0","typescript":"^7.0.2"},"peerDependenciesMeta":{"zod":{"optional":true},"undici":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/typechat_0.1.4_1787342608960_0.34626345381381785","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"_id":"typechat@0.2.0","bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"dist":{"shasum":"ed0ce7bfa023cb839f420a952906ca8ea9b229d9","tarball":"https://registry.npmjs.org/typechat/-/typechat-0.2.0.tgz","fileCount":62,"integrity":"sha512-u7pB5xmlKc4NAW38EMNJE3aSIWcPCP4RshiQsZOnYjLD16vsyhZlB7C6C2JqJjDnAw7n3TUMGNVbHpjZK+Tq0Q==","signatures":[{"sig":"MEQCIEyE9e7BmOl/XWx93n4F6AqRzTPdCr3YKOsIxsTyfVjdAiBtVQAEIrJkOtVQeKqHPEGPPInnaFoLI91hr8q85GDVgg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBuRGf+/H5+4zWfm/Z2qs80BlWBo2dyAPYOpj7fFRG3jAiAQbkQPXuCGVICewXdPN22Y2NAqCLDNhZW2sNGNgmSelw=="}],"unpackedSize":219300},"main":"./dist/index.js","name":"typechat","type":"commonjs","types":"./dist/index.d.ts","author":{"name":"Microsoft"},"module":"./dist/esm/index.mjs","engines":{"node":">=24.22.1"},"exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"default":"./dist/index.js","require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./ts":{"import":{"types":"./dist/esm/ts/index.d.mts","default":"./dist/esm/ts/index.mjs"},"default":"./dist/ts/index.js","require":{"types":"./dist/ts/index.d.ts","default":"./dist/ts/index.js"}},"./zod":{"import":{"types":"./dist/esm/zod/index.d.mts","default":"./dist/esm/zod/index.mjs"},"default":"./dist/zod/index.js","require":{"types":"./dist/zod/index.d.ts","default":"./dist/zod/index.js"}},"./interactive":{"import":{"types":"./dist/esm/interactive/index.d.mts","default":"./dist/esm/interactive/index.mjs"},"default":"./dist/interactive/index.js","require":{"types":"./dist/interactive/index.d.ts","default":"./dist/interactive/index.js"}}},"gitHead":"c2215ed196d6cf2907360b515ce439b02ec346b6","license":"MIT","scripts":{"test":"npm run build && tsc -p test && node --test \"out/**/*.test.js\" \"tests/**/*.test.mjs\"","build":"npm run build:cjs && npm run build:esm","prepare":"npm run build-all","build-all":"npm run build && npm run build --workspaces","build:cjs":"tsc -p src","build:esm":"tsc -p src/tsconfig.esm.json && node -e \"const fs = require('fs'); fs.writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' })); fs.copyFileSync('dist/esm/schemaValidation.d.ts', 'dist/schemaValidation.d.ts'); fs.writeFileSync('dist/esm/schemaValidation.d.ts', 'export { typeChatSchemaValidation } from \\'../schemaValidation.js\\';\\n')\"","postpublish":"node -e \"require('fs').unlinkSync('SECURITY.md')\"","prepublishOnly":"node -e \"require('fs').copyFileSync('../SECURITY.md','SECURITY.md')\"","publish-package":"npm publish","publish-package:dry-run":"npm publish --dry-run"},"version":"0.2.0","_npmUser":{"name":"typechat","email":"typechat@microsoft.com"},"homepage":"https://github.com/microsoft/TypeChat#readme","keywords":["schema","LLM","prompt","TypeScript","validation"],"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"workspaces":["./","./examples/*"],"_npmVersion":"11.20.0","description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","directories":{},"maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"_nodeVersion":"26.13.0","_hasShrinkwrap":false,"devDependencies":{"undici":"^8.10.0","typescript":"^7.0.2","@types/node":"^26.2.0"},"peerDependencies":{"zod":"^4.4.3","undici":"^8.10.0","typescript":"^7.0.2"},"peerDependenciesMeta":{"zod":{"optional":true},"undici":{"optional":true},"typescript":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/typechat_0.2.0_1794003064524_0.12864044845564448"}}},"time":{"created":"2023-07-20T16:07:35.335Z","modified":"2026-11-06T22:11:04.800Z","0.0.10":"2023-07-20T16:07:35.574Z","0.1.0":"2024-03-25T17:20:11.713Z","0.1.1":"2024-09-04T17:53:48.113Z","0.1.2":"2026-02-25T21:51:47.566Z","0.1.3":"2026-07-28T00:30:51.416Z","0.1.4":"2026-08-21T20:03:29.216Z","0.2.0":"2026-11-06T22:11:04.619Z"},"bugs":{"url":"https://github.com/microsoft/TypeChat/issues"},"author":{"name":"Microsoft"},"license":"MIT","homepage":"https://github.com/microsoft/TypeChat#readme","keywords":["schema","LLM","prompt","TypeScript","validation"],"repository":{"url":"git+https://github.com/microsoft/TypeChat.git","type":"git"},"description":"TypeChat is an experimental library that makes it easy to build natural language interfaces using types.","maintainers":[{"name":"typechat","email":"typechat@microsoft.com"}],"readme":"# TypeChat\r\n\r\nTypeChat is a library that makes it easy to build natural language interfaces using types.\r\n\r\nBuilding natural language interfaces has traditionally been difficult. These apps often relied on complex decision trees to determine intent and collect the required inputs to take action. Large language models (LLMs) have made this easier by enabling us to take natural language input from a user and match to intent. This has introduced its own challenges including the need to constrain the model's reply for safety, structure responses from the model for further processing, and ensuring that the reply from the model is valid. Prompt engineering aims to solve these problems, but comes with a steep learning curve and increased fragility as the prompt increases in size.\r\n\r\nTypeChat replaces _prompt engineering_ with _schema engineering_.\r\n\r\nSimply define types that represent the intents supported in your natural language application. That could be as simple as an interface for categorizing sentiment or more complex examples like types for a shopping cart or music application. For example, to add additional intents to a schema, a developer can add additional types into a discriminated union. To make schemas hierarchical, a developer can use a \"meta-schema\" to choose one or more sub-schemas based on user input.\r\n\r\nAfter defining your types, TypeChat takes care of the rest by:\r\n\r\n1. Constructing a prompt to the LLM using types.\r\n2. Validating the LLM response conforms to the schema. If the validation fails, repair the non-conforming output through further language model interaction.\r\n3. Summarizing succinctly (without use of a LLM) the instance and confirm that it aligns with user intent.\r\n\r\nTypes are all you need!\r\n\r\n# Getting Started\r\n\r\nRequires [Node.js 24.22.1 or newer](https://nodejs.org/en/download).\r\nThe development version is pinned in [.nvmrc](../.nvmrc).\r\n\r\nInstall TypeChat:\r\n\r\n```sh\r\nnpm install typechat\r\n```\r\n\r\nTypeChat supports both native ECMAScript modules (ESM) and CommonJS. Use `import`\r\nin an ESM application:\r\n\r\n```js\r\nimport { createJsonTranslator } from \"typechat\";\r\nimport { createTypeScriptJsonValidator } from \"typechat/ts\";\r\n```\r\n\r\nOr use `require` in a CommonJS application:\r\n\r\n```js\r\nconst { createJsonTranslator } = require(\"typechat\");\r\nconst { createTypeScriptJsonValidator } = require(\"typechat/ts\");\r\n```\r\n\r\nThe `typechat`, `typechat/ts`, `typechat/zod`, and `typechat/interactive` entry points\r\nselect the matching JavaScript build and TypeScript declarations automatically.\r\nBoth builds target ES2021 and require Node.js 24.22.1 or newer.\r\n\r\nFor compatibility with earlier CommonJS-only releases, native ESM default imports\r\n(`import typechat from \"typechat\"`) and dynamic imports' `.default` properties remain\r\nsupported for all four entry points. Default imports also preserve the exported\r\nTypeScript types, such as `typechat.Result<T>`.\r\n\r\nYou can also build TypeChat from source:\r\n\r\n```sh\r\ngit clone https://github.com/microsoft/TypeChat\r\ncd TypeChat/typescript\r\nnpm install\r\nnpm run build\r\n```\r\n\r\nThe build emits CommonJS JavaScript and declarations in `dist`, and native ESM\r\nJavaScript and declarations in `dist/esm`.\r\n\r\nRun the test suite with `npm test`. Package tests verify named and default imports,\r\nboth module formats, and their declaration resolution using only the files included\r\nin the npm package.\r\nThe test command recursively discovers compiled `*.test.js` suites under `out/`\r\nand runtime `*.test.mjs` suites under `tests/`. Add TypeScript tests under\r\n[test/](https://github.com/microsoft/TypeChat/tree/main/typescript/test) or runtime\r\ntests under [tests/](https://github.com/microsoft/TypeChat/tree/main/typescript/tests);\r\nno manual suite-list update is needed.\r\nQuoted patterns let Node handle discovery consistently across platforms, including\r\nnested directories, without executing helper files or uncompiled TypeScript.\r\n\r\nThe Zod schema tests also compile their generated TypeScript schema text to check\r\nfor syntax errors and unresolved type references.\r\nNode.js CI runs this suite across its Node.js matrix after a clean dependency\r\ninstallation and workspace build.\r\n\r\nThe TypeScript-backed JSON validator checks its schema and target export before a\r\ntranslator makes its first model request. Schema configuration errors are returned\r\nwithout asking the model to repair them. This preflight uses the same minimal\r\nTypeScript library as response validation and is cached for the validator's lifetime.\r\nOnce a schema passes preflight, invalid model responses continue through the normal\r\nvalidation and repair flow. Zod and custom validators without schema-only checks keep\r\ntheir existing instance-validation behavior. The `TypeChatJsonValidator` contract is\r\nunchanged; custom validators can opt in through the exported `typeChatSchemaValidation`\r\nsymbol, so existing string-named `validateSchema` methods are not invoked as preflight.\r\nThe symbol's runtime value and canonical declaration are shared across the ESM and\r\nCommonJS builds, so validators remain type-compatible and schema preflight also runs\r\nwhen a validator and translator come from different module formats.\r\n\r\nTo see TypeChat in action, we recommend exploring the [TypeChat example projects](https://github.com/microsoft/TypeChat/tree/main/typescript/examples). You can try them on your local machine or in a GitHub Codespace.\r\n\r\nTo learn more about TypeChat, visit the [documentation](https://microsoft.github.io/TypeChat) which includes more information on TypeChat and how to get started.\r\n\r\n## Reusing model authentication\r\n\r\nThe HTTP model factories accept a synchronous or asynchronous `tokenProvider` option\r\nwith `undefined` for the API key. Existing string-key and environment-based calls are\r\nunchanged. For an already configured OpenAI/AzureOpenAI or compatible client, use\r\n`createOpenAILanguageModelFromClient`, optionally with `{ useResponsesApi: true }`.\r\n\r\nThese paths add no SDK dependency to TypeChat. See the\r\n[token-provider example](../site/src/docs/typescript/basic-usage.md#using-a-bearer-token-provider)\r\nand [configured-client example](../site/src/docs/typescript/basic-usage.md#reusing-a-configured-client)\r\nfor multimodal prompts, network-control ownership, and error behavior.\r\n\r\n## Accessing failed output\r\n\r\nFailed results include a `message` and may also include `data: unknown` and `responseText: string`.\r\nValidators return the rejected input in `data`. Translators also retain the original model text,\r\nincluding when that text is not valid JSON:\r\n\r\n```ts\r\nconst result = await translator.translate(request);\r\nif (!result.success) {\r\n    const rejected: unknown = result.data;\r\n    const originalResponse = result.responseText;\r\n    // Validate or repair the rejected value before treating it as the target type.\r\n}\r\n```\r\n\r\nOn final failure, automatic repair retains the latest rejected candidate and available response text,\r\nnot a full attempt history. If a repair response cannot be parsed, `data` can come from an earlier\r\nattempt than `responseText`. An initial network failure has no candidate data. Successful results,\r\nerror messages, and repair limits are unchanged; `getData` still throws on failure.\r\n\r\nUse `success` to distinguish successful and failed results, not the presence of `data`.\r\nCustom validators can supply their own failure payloads, which the translator preserves.\r\nTo create such a failure, use `error(message, { data, responseText })`; `error(message)` still returns\r\nthe original message-only shape. A present `data` property can contain any value, including `null`\r\nor `undefined`, so check property presence when that distinction matters.\r\n\r\nRejected values and response text may contain sensitive output. Do not log them automatically.\r\n\r\n## Accessing response metadata\r\n\r\nModel and translation results can include optional `metadata` on success and failure,\r\nseparate from application data. See the [response metadata guide](https://github.com/microsoft/TypeChat/blob/main/typescript/metadata.md)\r\nfor reported token usage, initial and repair response records, and available filtering details.\r\nThe guide is also included as `metadata.md` in the npm package.\r\n\r\n## Contributing\r\n\r\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\r\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\r\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\r\n\r\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\r\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\r\nprovided by the bot. You will only need to do this once across all repos using our CLA.\r\n\r\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\r\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\r\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\r\n\r\n## Trademarks\r\n\r\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft \r\ntrademarks or logos is subject to and must follow \r\n[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\r\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\r\nAny use of third-party trademarks or logos are subject to those third-party's policies.\r\n","readmeFilename":"README.md"}