Interactive TypeScript examples for aitutorial.dev. These are embedded via StackBlitz in the tutorial site.
src/prompting/— Context engineering & prompt design examplessrc/rag/— Retrieval-Augmented Generation examplessrc/agents/— AI agent & MCP server examplessrc/types/— Shared type definitionssrc/utils/— Shared utilitiesscripts/run.ts— Interactive runner scriptenv/.env— API keys (not in git)
Module-specific dependencies are installed automatically when running an example from that module.
- Every file must have a
mainfunction as the first function after imports/setup - Functions must declare return types
- Functions must have a single return point
- Local variables should not have explicit type annotations (use TypeScript inference)
- Use template literals for
console.logwith variables:console.log(`Result: ${value}`) - Don't start
console.logwith\n— use separateconsole.log('')for blank lines - Multi-line template literals must align with surrounding indentation
- Each file is a self-contained, executable script
mainfunction JSDoc must include: brief description, introduction ("This example shows..."), concluding note- Use numbered step comments in
main:// Step 1: ...,// Step 2: ... - If
mainonly calls one function, inline it directly intomain - Input/output logs go inside called functions, not in
main
Every file must include these three fields in its header comment:
- Costs & Safety: API cost/safety notes (e.g., "Real API calls; keep inputs small.")
- Module reference: Link to the tutorial section:
[Section Name](https://aitutorial.dev/{module-slug}#{anchor-slug}) - Why: Brief explanation of why this technique is useful
- Supports Gemini (
GOOGLE_GENERATIVE_AI_API_KEY) and OpenAI (OPENAI_API_KEY) - Set
AI_PROVIDER=geminiorAI_PROVIDER=openaiinenv/.env - Uses Vercel AI SDK (
aipackage) with@ai-sdk/openaiand@ai-sdk/googleproviders - OpenAI SDK uses
max_completion_tokens(not the deprecatedmax_tokens)
npm start # interactive runner
npx tsx src/prompting/hello_world.ts # direct execution