{"_id":"@agi_inc/agi-js","_rev":"6-884fec8a3057f944d99335dbd59d0ba1","name":"@agi_inc/agi-js","dist-tags":{"latest":"0.5.1"},"versions":{"0.0.1":{"name":"@agi_inc/agi-js","version":"0.0.1","keywords":["agi","automation","browser","ai","agent","api","sdk","typescript","web-automation"],"author":{"name":"AGI Inc","email":"sdk@agi.tech"},"license":"MIT","_id":"@agi_inc/agi-js@0.0.1","maintainers":[{"name":"kaushikb11","email":"kaushikbokka@gmail.com"}],"homepage":"https://docs.agi.tech","bugs":{"url":"https://github.com/agi-inc/agi-node/issues"},"dist":{"shasum":"4b33a61761b6c9f4864c4ca5b03b944a32210c66","tarball":"https://registry.npmjs.org/@agi_inc/agi-js/-/agi-js-0.0.1.tgz","fileCount":9,"integrity":"sha512-M6ykh8439ZA8wihvReWF5046f9Cw/js4XbqGLxW0fK0PH02TLcSAN1/a0qcgohQJ4UHS+x0Va2UVZEiGHaw+QA==","signatures":[{"sig":"MEYCIQD88lSjhb7Ti2N1+KRrg4dGIor8T+ZhBSRWdy7pME1WIQIhAMVMsJOS+2jy6OnE2Stp6xL8srBul3891ThZx1IJyxpm","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agi_inc%2fagi-js@0.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":237953},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=20.4.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"cfeeb63934fccc121439543ff01414b6d716c33e","scripts":{"dev":"tsup --watch","lint":"eslint src --ext .ts","test":"vitest run tests/unit","build":"tsup","format":"prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"","typecheck":"tsc --noEmit","test:smoke":"AGI_API_KEY=f94a74fa-bcdf-429f-97b0-37b7a1df6ab2 vitest run tests/smoke-simple.test.ts --reporter=verbose","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"kaushikb11","email":"kaushikbokka@gmail.com"},"repository":{"url":"git+https://github.com/agi-inc/agi-node.git","type":"git"},"_npmVersion":"10.8.2","description":"Official TypeScript/JavaScript SDK for AGI.tech API","directories":{},"_nodeVersion":"20.19.6","dependencies":{"eventsource-parser":"^1.1.2"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.1","eslint":"^8.55.0","vitest":"^1.0.4","prettier":"^3.1.0","typescript":"^5.3.3","@types/node":"^20.10.0","@vitest/coverage-v8":"^1.6.1","eslint-config-prettier":"^9.1.0","@typescript-eslint/parser":"^6.13.0","@typescript-eslint/eslint-plugin":"^6.13.0"},"_npmOperationalInternal":{"tmp":"tmp/agi-js_0.0.1_1768116959148_0.6846408499852406","host":"s3://npm-registry-packages-npm-production"}},"0.4.2":{"name":"@agi_inc/agi-js","version":"0.4.2","keywords":["agi","automation","browser","ai","agent","api","sdk","typescript","web-automation"],"author":{"name":"AGI Inc","email":"sdk@agi.tech"},"license":"MIT","_id":"@agi_inc/agi-js@0.4.2","maintainers":[{"name":"namangarg","email":"gargnaman20@gmail.com"},{"name":"jacob-agi","email":"jacob@theagi.company"}],"homepage":"https://docs.agi.tech","bugs":{"url":"https://github.com/agi-inc/agi-node/issues"},"dist":{"shasum":"8b972200152180b1e2fdc3e8fcb1156adae93621","tarball":"https://registry.npmjs.org/@agi_inc/agi-js/-/agi-js-0.4.2.tgz","fileCount":9,"integrity":"sha512-I2F1jEJ/vFJ6OXdt1qQeoNJXbeDbUA1Wt6hbgbmT50heJj7QzfkDpUuuhHlOBrr+Fq2MMsRkxnIhvEVM7kMwqA==","signatures":[{"sig":"MEQCIBn7LIN91v7J/4Riw7QhoXgkKHvEyDvypT0PmtDN2zjFAiAWh76uVnKUgp896S6v7iYiQfbQphpL72qqIAHXuTWV4g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":437344},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=20.4.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"460aed5b41bd19f7effae7a4a7873f0fc27d3705","scripts":{"dev":"tsup --watch","lint":"eslint src --ext .ts","test":"vitest run tests/unit","build":"tsup","format":"prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"","typecheck":"tsc --noEmit","test:smoke":"AGI_API_KEY=f94a74fa-bcdf-429f-97b0-37b7a1df6ab2 vitest run tests/smoke-simple.test.ts --reporter=verbose","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build","test:integration":"vitest run tests/integration --reporter=verbose"},"_npmUser":{"name":"namangarg","email":"gargnaman20@gmail.com"},"repository":{"url":"git+https://github.com/agi-inc/agi-node.git","type":"git"},"_npmVersion":"11.7.0","description":"Official TypeScript/JavaScript SDK for AGI.tech API","directories":{},"_nodeVersion":"24.11.1","dependencies":{"eventsource-parser":"^1.1.2"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.1","eslint":"^8.55.0","vitest":"^1.0.4","prettier":"^3.1.0","typescript":"^5.3.3","@types/node":"^20.10.0","@vitest/coverage-v8":"^1.6.1","eslint-config-prettier":"^9.1.0","@typescript-eslint/parser":"^6.13.0","@typescript-eslint/eslint-plugin":"^6.13.0"},"optionalDependencies":{"@agi/agi-linux-x64":"0.4.0","@agi/agi-win32-x64":"0.4.0","@agi/agi-darwin-x64":"0.4.0","@agi/agi-darwin-arm64":"0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/agi-js_0.4.2_1770681427464_0.9263404711250398","host":"s3://npm-registry-packages-npm-production"}},"0.5.0":{"name":"@agi_inc/agi-js","version":"0.5.0","keywords":["agi","automation","browser","ai","agent","api","sdk","typescript","web-automation"],"author":{"name":"AGI Inc","email":"sdk@agi.tech"},"license":"MIT","_id":"@agi_inc/agi-js@0.5.0","maintainers":[{"name":"namangarg","email":"gargnaman20@gmail.com"},{"name":"jacob-agi","email":"jacob@theagi.company"}],"homepage":"https://docs.agi.tech","bugs":{"url":"https://github.com/agi-inc/agi-node/issues"},"dist":{"shasum":"93871aceab82ab12fc99785c87e0ec52ef657ecd","tarball":"https://registry.npmjs.org/@agi_inc/agi-js/-/agi-js-0.5.0.tgz","fileCount":9,"integrity":"sha512-RLoMw5xjnrfK0Zwrn02c4o+Fm6UmkIU2S6QTDCyqpO7jOf2KeVE6Ayf0ZxjYHACH30NwRCBmIHahb9jp057+gQ==","signatures":[{"sig":"MEUCIGCGtVdCfp8YK1GaWPk5XYJ1k8bLmN5Ru4SAebU9ZlOHAiEA8fg3ICGCdvMh6m065OxfsX6ISd0flOqHZa3eSfg1rHc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agi_inc%2fagi-js@0.5.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":460485},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=20.4.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"0b1134116bee8ec1770be78beb126d7f09cd286d","scripts":{"dev":"tsup --watch","lint":"eslint src --ext .ts","test":"vitest run tests/unit","build":"tsup","format":"prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"","typecheck":"tsc --noEmit","test:smoke":"AGI_API_KEY=f94a74fa-bcdf-429f-97b0-37b7a1df6ab2 vitest run tests/smoke-simple.test.ts --reporter=verbose","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build","test:integration":"vitest run tests/integration --reporter=verbose"},"_npmUser":{"name":"namangarg","email":"gargnaman20@gmail.com"},"repository":{"url":"git+https://github.com/agi-inc/agi-node.git","type":"git"},"_npmVersion":"10.8.2","description":"Official TypeScript/JavaScript SDK for AGI.tech API","directories":{},"_nodeVersion":"20.20.0","dependencies":{"eventsource-parser":"^1.1.2"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.1","eslint":"^8.55.0","vitest":"^1.0.4","prettier":"^3.1.0","typescript":"^5.3.3","@types/node":"^20.10.0","@vitest/coverage-v8":"^1.6.1","eslint-config-prettier":"^9.1.0","@typescript-eslint/parser":"^6.13.0","@typescript-eslint/eslint-plugin":"^6.13.0"},"optionalDependencies":{"@agi/agi-linux-x64":"0.4.0","@agi/agi-win32-x64":"0.4.0","@agi/agi-darwin-x64":"0.4.0","@agi/agi-darwin-arm64":"0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/agi-js_0.5.0_1770761009358_0.7204614514350776","host":"s3://npm-registry-packages-npm-production"}},"0.5.1":{"name":"@agi_inc/agi-js","version":"0.5.1","description":"Official TypeScript/JavaScript SDK for AGI.tech API","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run tests/unit","test:watch":"vitest","test:smoke":"AGI_API_KEY=f94a74fa-bcdf-429f-97b0-37b7a1df6ab2 vitest run tests/smoke-simple.test.ts --reporter=verbose","test:integration":"vitest run tests/integration --reporter=verbose","test:coverage":"vitest run --coverage","lint":"eslint src --ext .ts","format":"prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["agi","automation","browser","ai","agent","api","sdk","typescript","web-automation"],"author":{"name":"AGI Inc","email":"sdk@agi.tech"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/agi-inc/agi-node.git"},"bugs":{"url":"https://github.com/agi-inc/agi-node/issues"},"homepage":"https://docs.agi.tech","engines":{"node":">=20.4.0"},"dependencies":{"eventsource-parser":"^1.1.2"},"optionalDependencies":{"@agi/agi-darwin-arm64":"0.3.1","@agi/agi-darwin-x64":"0.3.1","@agi/agi-linux-x64":"0.3.1","@agi/agi-win32-x64":"0.3.1"},"devDependencies":{"@types/node":"^20.10.0","@typescript-eslint/eslint-plugin":"^6.13.0","@typescript-eslint/parser":"^6.13.0","@vitest/coverage-v8":"^1.6.1","eslint":"^8.55.0","eslint-config-prettier":"^9.1.0","prettier":"^3.1.0","tsup":"^8.0.1","typescript":"^5.3.3","vitest":"^1.0.4"},"_id":"@agi_inc/agi-js@0.5.1","gitHead":"b5a290fc0f6da92c6fca4383028dacddfb878cf6","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-eoU6XPBq+KQ+5bxsoI0WRZ879RoSdm5jv6+MUGTqH2pkzhV4zNhDxge+e1npFA5vwI438ybwf4cPLRnPz76gnQ==","shasum":"16426a87335987828ce241d38bc9c06e30938aae","tarball":"https://registry.npmjs.org/@agi_inc/agi-js/-/agi-js-0.5.1.tgz","fileCount":9,"unpackedSize":460485,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agi_inc%2fagi-js@0.5.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDluH92Mv5rTREC+iwNrE2+P+sqj9bkOyNNeZY0VDcZrQIhAL3SedZ+WKNki2nUK81J4NgcfysLD+bbPHInFTwW8q9L"}]},"_npmUser":{"name":"namangarg","email":"gargnaman20@gmail.com"},"directories":{},"maintainers":[{"name":"namangarg","email":"gargnaman20@gmail.com"},{"name":"jacob-agi","email":"jacob@theagi.company"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/agi-js_0.5.1_1770770320528_0.6530153955000255"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-11T07:35:59.019Z","modified":"2026-02-11T00:38:40.964Z","0.0.1":"2026-01-11T07:35:59.302Z","0.4.2":"2026-02-09T23:57:07.615Z","0.5.0":"2026-02-10T22:03:29.558Z","0.5.1":"2026-02-11T00:38:40.677Z"},"bugs":{"url":"https://github.com/agi-inc/agi-node/issues"},"author":{"name":"AGI Inc","email":"sdk@agi.tech"},"license":"MIT","homepage":"https://docs.agi.tech","keywords":["agi","automation","browser","ai","agent","api","sdk","typescript","web-automation"],"repository":{"type":"git","url":"git+https://github.com/agi-inc/agi-node.git"},"description":"Official TypeScript/JavaScript SDK for AGI.tech API","maintainers":[{"name":"namangarg","email":"gargnaman20@gmail.com"},{"name":"jacob-agi","email":"jacob@theagi.company"}],"readme":"<div align=\"center\">\n\n<img src=\"https://cdn.prod.website-files.com/67be56277f6d514dcad939e2/67e48dd1cdab04c17a311669_logo-agi-white.png\" alt=\"AGI\" width=\"120\"/>\n\n<h1>AGI Node.js SDK</h1>\n\n<p>\n  <a href=\"https://www.npmjs.com/package/agi\"><img src=\"https://img.shields.io/npm/v/agi?style=flat-square\" alt=\"npm version\"></a>\n  <a href=\"https://github.com/agi-inc/agi-node/actions/workflows/ci.yml\"><img src=\"https://img.shields.io/github/actions/workflow/status/agi-inc/agi-node/ci.yml?branch=main&style=flat-square\" alt=\"Build Status\"></a>\n  <a href=\"https://codecov.io/gh/agi-inc/agi-node\"><img src=\"https://img.shields.io/codecov/c/github/agi-inc/agi-node?style=flat-square\" alt=\"Coverage\"></a>\n  <a href=\"https://github.com/agi-inc/agi-node/blob/main/LICENSE\"><img src=\"https://img.shields.io/npm/l/agi?style=flat-square\" alt=\"License\"></a>\n  <a href=\"https://www.npmjs.com/package/agi\"><img src=\"https://img.shields.io/npm/dm/agi?style=flat-square\" alt=\"Downloads\"></a>\n</p>\n\n<p>\n  <a href=\"https://www.theagi.company/\">Website</a> •\n  <a href=\"https://docs.agi.tech\">Documentation</a> •\n  <a href=\"https://platform.agi.tech\">Platform</a> •\n  <a href=\"https://theagi.company/blog\">Blog</a>\n</p>\n\n---\n\n**Universal Computer-Use AI**\n\n<br />\n\n</div>\n\n```typescript\nimport { AGIClient } from 'agi';\n\nconst client = new AGIClient({ apiKey: process.env.AGI_API_KEY });\n\n// Context manager with automatic cleanup\nawait using session = client.session('agi-0');\n\nconst result = await session.runTask(\n  'Find three nonstop flights from SFO to JFK next month under $450. ' +\n    'Return flight times, airlines, and booking links.'\n);\n\nconsole.log(result.data);\nconsole.log(`Duration: ${result.metadata.duration}s, Steps: ${result.metadata.steps}`);\n// Session automatically deleted\n```\n\n<br />\n\n> Powered by [AGI.tech](https://agi.tech) - the world's most capable computer agent. Trusted by [Visa](https://www.theagi.company/blog/agi-inc-visa) for agentic commerce. Evaluated with [REAL Bench](https://www.theagi.company/blog/introducing-real-bench).\n\n<br />\n\n## Installation\n\n```bash\nnpm install agi\n```\n\nGet your API key at [platform.agi.tech](https://platform.agi.tech/api-keys)\n\n```bash\nexport AGI_API_KEY=\"your-api-key\"\n```\n\n## Quick Start\n\n### Simple Task (Recommended)\n\n```typescript\nimport { AGIClient } from 'agi';\n\nconst client = new AGIClient({ apiKey: process.env.AGI_API_KEY });\n\n// Context manager with automatic cleanup\nawait using session = client.session('agi-0');\n\nconst result = await session.runTask('Find the cheapest iPhone 15 on Amazon');\n\nconsole.log(result.data); // Task output\nconsole.log(result.metadata.duration); // Execution time in seconds\nconsole.log(result.metadata.steps); // Number of steps taken\n// Session automatically deleted when scope exits\n```\n\n### Real-Time Event Streaming\n\n```typescript\nawait using session = client.session('agi-0');\n\nawait session.sendMessage('Research the top 5 AI companies in 2025');\n\nfor await (const event of session.streamEvents()) {\n  if (event.event === 'thought') {\n    console.log('💭 Agent:', event.data);\n  }\n  if (event.event === 'done') {\n    console.log('✅ Result:', event.data);\n    break;\n  }\n}\n// Session automatically deleted\n```\n\n### Polling Configuration\n\nConfigure timeouts and polling intervals for different task types:\n\n```typescript\nawait using session = client.session('agi-0');\n\n// Quick task (1 min timeout, 2s polling)\nconst result1 = await session.runTask('What is 2+2?', {\n  timeout: 60000,\n  pollInterval: 2000,\n});\n\n// Complex task (15 min timeout, 5s polling)\nconst result2 = await session.runTask('Research AI companies...', {\n  timeout: 900000,\n  pollInterval: 5000,\n});\n```\n\n### Manual Session Management\n\nFor advanced use cases requiring fine-grained control:\n\n```typescript\n// Create session manually\nconst response = await client.sessions.create('agi-0', {\n  webhookUrl: 'https://yourapp.com/webhook',\n  maxSteps: 200,\n});\n\n// Send message\nawait client.sessions.sendMessage(response.sessionId, 'Find flights from SFO to JFK under $450');\n\n// Check status\nconst status = await client.sessions.getStatus(response.sessionId);\n\n// Delete when done\nawait client.sessions.delete(response.sessionId);\n```\n\n### Session Control\n\n```typescript\nawait using session = client.session('agi-0');\n\nawait session.sendMessage('Long research task...');\n\n// Control execution\nawait session.pause(); // Pause the agent\nawait session.resume(); // Resume later\nawait session.cancel(); // Or cancel\n```\n\n---\n\n## Core Concepts\n\n_Understanding the building blocks of agi_\n\n### Sessions: The Container for Tasks\n\nEvery task runs inside a **session** - an isolated browser environment:\n\n```typescript\n// Recommended: Context manager (automatic cleanup)\nawait using session = client.session('agi-0');\nawait session.runTask('Find flights...');\n// Session automatically deleted\n\n// Alternative: Manual management\nconst response = await client.sessions.create('agi-0');\nawait client.sessions.delete(response.sessionId);\n```\n\n▸ Use context managers (`await using`) for automatic cleanup. Sessions consume resources and should be deleted when done.\n\n### Available Agents\n\n- **agi-0** - General purpose agent (recommended)\n- **agi-0-fast** - Faster agent for simple tasks\n- **agi-1** - Advanced agent with enhanced capabilities\n\nSee [docs.agi.tech](https://docs.agi.tech) for the full list.\n\n---\n\n## Features\n\n- **Natural Language** - Describe tasks in plain English, no selectors or scraping code\n- **Real-Time Streaming** - Watch agent execution live with Server-Sent Events\n- **Session Control** - Pause, resume, or cancel long-running tasks\n- **Browser Control** - Navigate and screenshot for visual debugging\n- **Type-Safe** - Full TypeScript support with comprehensive type definitions\n- **Production-Ready** - Built-in retries, automatic cleanup, comprehensive error handling\n\n---\n\n## Common Use Cases\n\n### Price Monitoring\n\nMonitor product prices and availability across retailers.\n\n```typescript\nconst session = await client.createSession('agi-0');\n\ntry {\n  const result = await session.runTask(\n    'Go to amazon.com and search for \"Sony WH-1000XM5\". ' +\n      \"Get the current price, check if it's in stock, and return the product rating. \" +\n      'Return as JSON with fields: price, in_stock, rating, url.'\n  );\n  console.log(result);\n} finally {\n  await session.delete();\n}\n```\n\n### Lead Generation\n\nExtract structured data from public sources.\n\n```typescript\nconst session = await client.createSession('agi-0');\n\ntry {\n  const result = await session.runTask(\n    'Go to ycombinator.com/companies, find companies in the \"AI\" category ' +\n      'from the latest batch. For the first 10 companies, get their name, ' +\n      'description, and website. Return as a JSON array.'\n  );\n  console.log(result);\n} finally {\n  await session.delete();\n}\n```\n\n### Flight Booking Research\n\n```typescript\nconst session = await client.createSession('agi-0');\n\ntry {\n  const result = await session.runTask(\n    'Find three nonstop SFO→JFK flights next month under $450. ' +\n      'Compare prices on Google Flights, Kayak, and Expedia. ' +\n      'Return flight details and booking links.'\n  );\n  console.log(result);\n} finally {\n  await session.delete();\n}\n```\n\n<details>\n<summary><b>Browser Control</b> – Navigate and take screenshots for visual debugging</summary>\n\n<br />\n\n```typescript\nconst session = await client.createSession('agi-0');\n\ntry {\n  // Navigate to specific URL\n  await session.navigate('https://amazon.com');\n\n  // Get screenshot for debugging\n  const screenshot = await session.screenshot();\n  console.log(screenshot.url); // Current page URL\n  console.log(screenshot.title); // Page title\n  // screenshot.screenshot contains base64 JPEG data\n} finally {\n  await session.delete();\n}\n```\n\n</details>\n\n<details>\n<summary><b>Session Snapshots</b> – Preserve authentication and browser state</summary>\n\n<br />\n\n```typescript\n// Create session and save environment\nconst session1 = await client.createSession('agi-0');\n// ... do some authentication work ...\nawait session1.delete('filesystem');\n\n// Later, restore from saved environment\nconst session2 = await client.createSession('agi-0', {\n  restoreFromEnvironmentId: session1.environmentId,\n});\n// Authentication state and cookies preserved!\n\nawait session2.delete();\n```\n\n</details>\n\n<details>\n<summary><b>Advanced Session Management</b> – Full control over session lifecycle</summary>\n\n<br />\n\n```typescript\n// Create session with options\nconst session = await client.createSession('agi-0-fast', {\n  webhookUrl: 'https://yourapp.com/webhook',\n  maxSteps: 200,\n});\n\n// Send message\nawait session.sendMessage('Find flights from SFO to JFK under $450');\n\n// Check status\nconst status = await session.getStatus();\nconsole.log(status.status); // \"running\", \"finished\", etc.\n\n// List all sessions\nconst sessions = await client.listSessions();\n\n// Delete when done\nawait session.delete();\n```\n\n</details>\n\n<details>\n<summary><b>Webhooks</b> – Get notified when tasks complete</summary>\n\n<br />\n\n```typescript\nconst session = await client.createSession('agi-0', {\n  webhookUrl: 'https://yourapp.com/webhook',\n});\n\n// Your webhook will receive events:\n// POST https://yourapp.com/webhook\n// {\n//   \"event\": \"done\",\n//   \"session_id\": \"sess_...\",\n//   \"data\": {...}\n// }\n```\n\n</details>\n\n<details>\n<summary><b>Client-Driven Sessions</b> – Run agents on desktop, mobile, or custom environments</summary>\n\n<br />\n\n> **Note:** Desktop mode is currently feature-gated. For enterprise access, contact [`partner@theagi.company`](mailto:partner@theagi.company).\n\nFor scenarios where you control the execution environment (desktop automation, mobile apps, custom browsers), use client-driven sessions with `AgentLoop`:\n\n```typescript\nimport { AGIClient, AgentLoop } from 'agi';\n\nconst client = new AGIClient({ apiKey: process.env.AGI_API_KEY });\n\n// Create a client-driven session\nconst session = await client.sessions.create('agi-2-claude', {\n  agentSessionType: 'desktop',\n  goal: 'Open calculator and compute 2+2',\n});\n\n// Create and run the loop\nconst loop = new AgentLoop({\n  client,\n  agentUrl: session.agentUrl!,\n  captureScreenshot: async () => {\n    // Return base64-encoded screenshot from your environment\n    return '...';\n  },\n  executeActions: async (actions) => {\n    for (const action of actions) {\n      console.log(`Executing: ${action.type}`);\n      // Execute action in your environment\n    }\n  },\n  onThinking: (t) => console.log(`💭 ${t}`),\n});\n\nconst result = await loop.start();\nconsole.log(`Finished: ${result.finished}`);\n```\n\n**Loop Control:**\n\n```typescript\n// Start without awaiting\nconst promise = loop.start();\n\n// Pause/resume/stop\nloop.pause(); // Pause after current step\nloop.resume(); // Continue execution\nloop.stop(); // Stop the loop\n\n// Check state\nloop.state; // 'running', 'paused', 'stopped', 'finished'\nloop.currentStep; // Current step number\nloop.lastResult; // Last StepDesktopResponse\n```\n\n**Manual Step Control:**\n\n```typescript\n// Or manage the loop yourself\nlet finished = false;\nwhile (!finished) {\n  const screenshot = await captureScreenshot();\n  const result = await client.sessions.step(session.agentUrl!, screenshot);\n  await executeActions(result.actions);\n  finished = result.finished;\n}\n```\n\n</details>\n\n---\n\n## Error Handling\n\n<details>\n<summary><b>Robust error handling with detailed debugging</b></summary>\n\n<br />\n\n```typescript\nimport {\n  AGIClient,\n  AuthenticationError,\n  NotFoundError,\n  RateLimitError,\n  AgentExecutionError,\n  AGIError,\n} from 'agi';\n\nconst client = new AGIClient({ apiKey: process.env.AGI_API_KEY });\n\ntry {\n  const session = await client.createSession('agi-0');\n  try {\n    const result = await session.runTask('Find flights...');\n    console.log(result);\n  } finally {\n    await session.delete();\n  }\n} catch (error) {\n  if (error instanceof AuthenticationError) {\n    console.error('Invalid API key');\n  } else if (error instanceof NotFoundError) {\n    console.error('Session not found');\n  } else if (error instanceof RateLimitError) {\n    console.error('Rate limit exceeded - please retry');\n  } else if (error instanceof AgentExecutionError) {\n    console.error('Task failed:', error.message);\n    // Debug at VNC URL if available\n  } else if (error instanceof AGIError) {\n    console.error('API error:', error.message);\n  }\n}\n```\n\n</details>\n\n---\n\n## Examples\n\n**Real-world, production-ready examples** → See [examples/](./examples)\n\n### Quick Start\n\n```bash\n# 5-line hello world\nnpx tsx examples/hello-world.ts\n\n# Price tracking\nnpx tsx examples/ecommerce/price-tracker.ts \\\n  --product \"Sony WH-1000XM5\" --max-price 350\n\n# Flight search\nnpx tsx examples/travel/flight-finder.ts \\\n  --from SFO --to JFK --date \"2026-02-15\" --max-price 450\n\n# B2B lead generation\nnpx tsx examples/sales-marketing/linkedin-scraper.ts \\\n  --industry \"SaaS\" --location \"San Francisco\" --count 10\n\n# Competitor analysis\nnpx tsx examples/research/competitor-analysis.ts \\\n  --competitors \"stripe.com,square.com,paypal.com\"\n```\n\n### Example Categories\n\n- **[Basic](./examples#-basic-examples-basic)** (⭐ Beginner) - Quickstart, error handling, streaming\n- **[E-Commerce](./examples#-e-commerce-ecommerce)** (⭐⭐ Intermediate) - Price tracking, product comparison\n- **[Travel](./examples#️-travel-travel)** (⭐⭐ Intermediate) - Flight search, booking research\n- **[Sales & Marketing](./examples#-sales--marketing-sales-marketing)** (⭐⭐ Intermediate) - Lead generation, LinkedIn scraping\n- **[Research](./examples#-research-research)** (⭐⭐ Intermediate) - Competitive analysis, market research\n- **[Production](./examples#-production-patterns-production)** (⭐⭐⭐ Advanced) - Batch processing, webhook servers\n\n**Learning Path**: [hello-world.ts](./examples/hello-world.ts) → [basic/quickstart.ts](./examples/basic/quickstart.ts) → [Choose your domain](./examples#-examples-by-category) → [Production patterns](./examples#-production-patterns-production)\n\n---\n\n## Documentation & Resources\n\n**Learn More**\n\n- [API Reference](https://docs.agi.tech) – Complete API documentation\n- [Code Examples](./examples) – 15+ production-ready examples\n- [GitHub Issues](https://github.com/agi-inc/agi-node/issues) – Report bugs or request features\n\n**Get Help**\n\n- [Platform](https://platform.agi.tech) – Manage API keys and monitor usage\n- [Documentation](https://docs.agi.tech) – Guides and tutorials\n\n---\n\n## TypeScript Support\n\nThis SDK is written in TypeScript and provides full type definitions:\n\n```typescript\nimport type { Session, SessionStatus, SSEEvent, NavigateResponse } from 'agi';\n\nconst session: Session = await client.createSession('agi-0');\nconst status: SessionStatus = (await session.getStatus()).status;\n```\n\n---\n\n## Requirements\n\n- Node.js 20.4 or higher (required for `await using` syntax)\n- TypeScript 5.0+ (for TypeScript users)\n\n---\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n","readmeFilename":"README.md"}