{"id":26474,"library":"thingtalk","title":"ThingTalk","description":"ThingTalk is a declarative, rule-based distributed programming language for virtual assistants, developed by Stanford Open Virtual Assistant Lab. This package (v2.1.1, not semver: minor bumps can break library APIs) provides the grammar, just-in-time compiler, interface for SMT-based program analysis, natural language translation, and runtime libraries. It connects web services and IoT devices via 'when-get-do' statements, leveraging Thingpedia API primitives. Differentiators: unique focus on virtual assistants, crowdsourced API repository, and non-semver versioning where minor versions may introduce breaking API changes. Release cadence: irregular, with major version bumps for language incompatibility, minor for library changes, patch for bug fixes.","status":"active","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/stanford-oval/thingtalk","tags":["javascript","typescript"],"install":[{"cmd":"npm install thingtalk","lang":"bash","label":"npm"},{"cmd":"yarn add thingtalk","lang":"bash","label":"yarn"},{"cmd":"pnpm add thingtalk","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required to run ThingTalk programs in a full virtual assistant runtime","package":"genie-toolkit","optional":true}],"imports":[{"note":"ESM only since v2; no default export","wrong":"const compile = require('thingtalk').compile;","symbol":"compile","correct":"import { compile } from 'thingtalk'"},{"note":"Grammar is a named export, not default","wrong":"import Grammar from 'thingtalk';","symbol":"Grammar","correct":"import { Grammar } from 'thingtalk'"},{"note":"Ast is a type; use 'import type' in TypeScript to avoid runtime import","wrong":"import { Ast } from 'thingtalk';","symbol":"Ast","correct":"import type { Ast } from 'thingtalk'"}],"quickstart":{"code":"import { compile } from 'thingtalk';\n\nconst code = `\nmonitor(@com.washingtonpost.get_article(section=enum world))\n=> @com.yandex.translate.translate(target_language=\"zh\", text=title)\n=> @com.facebook.post(status=$result);\n`;\n\ntry {\n  const compiled = compile(code, { locale: 'en-US', timezone: 'America/Los_Angeles' });\n  console.log('Compiled program:', JSON.stringify(compiled, null, 2));\n} catch (err) {\n  console.error('Compilation failed:', err);\n}","lang":"typescript","description":"Compiles a ThingTalk program that monitors Washington Post articles, translates to Chinese, and posts to Facebook."},"warnings":[{"fix":"Specify dependency as \"thingtalk\": \"~2.1.0\" in package.json to allow only patch updates.","message":"Minor version bumps can break library APIs. Use tilde version ranges.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Use named imports like `import { compile } from 'thingtalk'` instead of `import compile from 'thingtalk'`.","message":"No default export; all exports are named.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Use `compileWithTranslation` instead.","message":"The `translate` function has been deprecated in favor of `compileWithTranslation`.","severity":"deprecated","affected_versions":">=2.0.0 <2.2"},{"fix":"Pass `{ libraryVersion: '2.1.0' }` in options when compiling for older clients.","message":"ThingTalk syntax generated by a newer version may not parse with an older client. Specify library version for compatibility.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure each statement ends with a semicolon and uses correct triple arrow syntax: `=> @service.function(params)`. Refer to ThingTalk language specification.","cause":"Invalid ThingTalk syntax, possibly due to missing semicolons or wrong invocation syntax.","error":"SyntaxError: Unexpected token"},{"fix":"Run `npm install thingtalk` and use `import { compile } from 'thingtalk'` (ESM) or ensure your bundler supports ESM. For CommonJS, use dynamic import: `const { compile } = await import('thingtalk')`.","cause":"Missing dependency or incorrect import path in CommonJS project.","error":"Error: Cannot find module 'thingtalk'"},{"fix":"Replace `import compile from 'thingtalk'` with `import { compile } from 'thingtalk'`.","cause":"Importing default export instead of named export.","error":"TypeError: compile is not a function"},{"fix":"Pass `{ libraryVersion: '2.1.0' }` in the compile options to output syntax compatible with the older client.","cause":"Generating syntax with a newer library version that is incompatible with the client version specified.","error":"ThingTalk version mismatch: expected 2.1.x, got 2.2.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}