{"_id":"@agentsmith-app/sdk","_rev":"7-19e9c087f05ac83ed619104ec538f61b","name":"@agentsmith-app/sdk","dist-tags":{"latest":"0.0.8"},"versions":{"0.0.2":{"name":"@agentsmith-app/sdk","version":"0.0.2","_id":"@agentsmith-app/sdk@0.0.2","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"dist":{"shasum":"d9e57f896a3e030cdc24d7806a591da5b29b6c88","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.2.tgz","fileCount":9,"integrity":"sha512-eyUhCxm8sk36TKOYZp0IKu+6muYzO0RXsS6g8oeRV+RA5P+r04JGTIoF0s80IhGfqS7jW2l/amhvRseNTFO3+w==","signatures":[{"sig":"MEYCIQDU559IfRFB+8UGt2TDQ1HXWXi0pAhxbEhAdM7xF4iNkQIhAJZgRDo/QpJFNI6qV0NCOjqpnzX3A0eQAAvR0QcoQ81N","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2393414},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"c0b8951140c22d3028b11e842fcc7d3fc35f6a8f","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","actor":{"name":"chad_syntax","type":"user","email":"chad@chadsyntax.com"},"email":"chad@chadsyntax.com"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.2_1751400669651_0.6119450528165282","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@agentsmith-app/sdk","version":"0.0.3","_id":"@agentsmith-app/sdk@0.0.3","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"homepage":"https://github.com/chad-syntax/agentsmith#readme","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"dist":{"shasum":"4945649e5b6fecebdb3b6487ce439d2c2e90ca23","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.3.tgz","fileCount":9,"integrity":"sha512-qUqTamRPycJKzqUmTvlWXSynGgKM0qrvQePGZiWkCeDuIezLo5GXXzY/tyS4KJ0He4T5W0zwSwnRaGAWzkc1bg==","signatures":[{"sig":"MEYCIQCbXJXovKq2flrz8LuaUsbciCW6L0C1k+XF1cwmiA+ClAIhAN4wQzp3uDmKYo5bqqGbFA22RLtTOAE6s5KDOgQtoay/","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2394472},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"28342fbfc35cff67c1502fdc1fc8b19cd9790e30","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","actor":{"name":"chad_syntax","type":"user","email":"chad@chadsyntax.com"},"email":"chad@chadsyntax.com"},"repository":{"url":"git+https://github.com/chad-syntax/agentsmith.git","type":"git"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.3_1751486809854_0.9684687407463641","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@agentsmith-app/sdk","version":"0.0.4","_id":"@agentsmith-app/sdk@0.0.4","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"homepage":"https://github.com/chad-syntax/agentsmith#readme","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"dist":{"shasum":"ca3937f19a72907abf66d4c5a93ae8178579d217","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.4.tgz","fileCount":9,"integrity":"sha512-xqJ14n+VtWVvlVhA1nF8366/sdYJWP2ooWPmg2szkKqt9OztTWkCiybT5uq6vG5vVNbCz8fDGjE/Ue8pwSutYA==","signatures":[{"sig":"MEUCIQC92gM6PZ6HpnbJ+2OeEiWZnVYXXFTWX+YeddDlyToipQIga8vDm4hk6n0M7vG4lHarI2w22LKl6ohdtanSMM/I5+s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2395347},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"baa9e229c3056188c2f87e3d99f02550dd6bab4b","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","email":"chad@chadsyntax.com"},"repository":{"url":"git+https://github.com/chad-syntax/agentsmith.git","type":"git"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.4_1752517413354_0.3071473201824384","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@agentsmith-app/sdk","version":"0.0.5","_id":"@agentsmith-app/sdk@0.0.5","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"homepage":"https://github.com/chad-syntax/agentsmith#readme","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"dist":{"shasum":"e50ee7aae2b0f2c7111001bdbb6f282dc450195f","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.5.tgz","fileCount":9,"integrity":"sha512-cnpEE2S8eixHTXFAOHlrMQNqEvvCE7cFAijiHZLscEqqUhd+pVk97qJ/AMIAbJG6KotvoZoCq2swf4Tzs/1VoA==","signatures":[{"sig":"MEUCIQDewYFVZm3rEspuOpZa7wgbSQ29jBfnW+/YepRTW+dVoQIgBoMVlKHAoXmM8a21kmRcg0iMctvf0gw3GoPzEXfcPfY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2472446},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"298c7d84adab032e191a8fb3c6295e011c5b9106","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","email":"chad@chadsyntax.com"},"repository":{"url":"git+https://github.com/chad-syntax/agentsmith.git","type":"git"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.5_1753390577055_0.23052981164097264","host":"s3://npm-registry-packages-npm-production"}},"0.0.6":{"name":"@agentsmith-app/sdk","version":"0.0.6","_id":"@agentsmith-app/sdk@0.0.6","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"homepage":"https://github.com/chad-syntax/agentsmith#readme","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"dist":{"shasum":"2a8ca76f29ab80931e1c5756daec88cea6e9e4dd","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.6.tgz","fileCount":9,"integrity":"sha512-tNRZRfUQ6aAHF0i1ohb6sVaNQ7R96DnJuaErzeEGFVUrslR82kEFlp0C7L4vcmUx4vpi8ARu1fQRMhbe5FmloA==","signatures":[{"sig":"MEUCIQCW3nGGewI9C/z7oqm5TGRblDRZJeK/t2KSKeS7cQlctwIgUDYSUWC0W+WTm5CV6mmsfNGygasTNFPHteQdDlMSXOM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2480140},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"e0b690ec90199ba7706ca4b01a90cd2339313d3e","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","email":"chad@chadsyntax.com"},"repository":{"url":"git+https://github.com/chad-syntax/agentsmith.git","type":"git"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.6_1753476430805_0.5778167235973966","host":"s3://npm-registry-packages-npm-production"}},"0.0.7":{"name":"@agentsmith-app/sdk","version":"0.0.7","_id":"@agentsmith-app/sdk@0.0.7","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"homepage":"https://github.com/chad-syntax/agentsmith#readme","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"dist":{"shasum":"9bbb9a8b45add65d101cc199a3f9ef6c94cc2f06","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.7.tgz","fileCount":9,"integrity":"sha512-NkIs9NDAE9FnB8X2Um0mSieIZgm2Ne+MOUkg0CjDFjqDERTXVzcKizTZ7LDHIy1eH4xoAqQjOry2XGFFfQYG7w==","signatures":[{"sig":"MEUCIQDceOX4u68GO2gUKXCE1KodDRa9Ys2Mag9xo0oeyR0NEwIgd4FOZ43n+YvgMTs0GIHzmy0A0M//qXURCtfxB5FASjA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2481116},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"1bf1ae1c61c17f59d3d457c50b30b82feba5113f","scripts":{"build":"tsup"},"_npmUser":{"name":"chad_syntax","email":"chad@chadsyntax.com"},"repository":{"url":"git+https://github.com/chad-syntax/agentsmith.git","type":"git"},"_npmVersion":"10.9.2","description":"Agentsmith TypeScript SDK","directories":{},"_nodeVersion":"22.14.0","dependencies":{"dotenv":"^16.4.7","p-queue":"^8.1.0","nunjucks":"^3.2.4","lodash.merge":"^4.6.2","@supabase/supabase-js":"latest"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","typescript":"^5.7.2","@types/lodash.merge":"^4.6.9"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.0.7_1753485978966_0.9054599900379343","host":"s3://npm-registry-packages-npm-production"}},"0.0.8":{"name":"@agentsmith-app/sdk","version":"0.0.8","description":"Agentsmith TypeScript SDK","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"tsup"},"repository":{"type":"git","url":"git+https://github.com/chad-syntax/agentsmith.git"},"devDependencies":{"@types/lodash.merge":"^4.6.9","tsup":"^8.5.0","typescript":"^5.7.2"},"dependencies":{"@supabase/supabase-js":"latest","dotenv":"^16.4.7","lodash.merge":"^4.6.2","nunjucks":"^3.2.4","p-queue":"^8.1.0"},"_id":"@agentsmith-app/sdk@0.0.8","gitHead":"22d05e61a483a04ad472943d3a40d9a979ca1045","bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"homepage":"https://github.com/chad-syntax/agentsmith#readme","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-rejpYvKo2kWq1eoH+k22//1WmkpQkXITIqU3WGCiRmndzMprmRHMzprruh3c0DtzeqykzINgTGExtHiT325erQ==","shasum":"320d356e75d676cd160cd029efa202126d31764d","tarball":"https://registry.npmjs.org/@agentsmith-app/sdk/-/sdk-0.0.8.tgz","fileCount":9,"unpackedSize":2492168,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICPDs2UBbXt68nRnx6rZRP3LVti+gGhrtjxo/nLAF8QTAiEAvXaDJbQUKsDOSxrP3fmio/ZFRnj/r7DI5VSEdaX1fiM="}]},"_npmUser":{"name":"chad_syntax","email":"chad@chadsyntax.com"},"directories":{},"maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.0.8_1754489131764_0.9223755714155135"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-01T20:11:09.484Z","modified":"2025-08-06T14:05:32.255Z","0.0.2":"2025-07-01T20:11:09.862Z","0.0.3":"2025-07-02T20:06:50.103Z","0.0.4":"2025-07-14T18:23:33.582Z","0.0.5":"2025-07-24T20:56:17.403Z","0.0.6":"2025-07-25T20:47:11.087Z","0.0.7":"2025-07-25T23:26:19.235Z","0.0.8":"2025-08-06T14:05:32.055Z"},"bugs":{"url":"https://github.com/chad-syntax/agentsmith/issues"},"homepage":"https://github.com/chad-syntax/agentsmith#readme","repository":{"type":"git","url":"git+https://github.com/chad-syntax/agentsmith.git"},"description":"Agentsmith TypeScript SDK","maintainers":[{"name":"chad_syntax","email":"chad@chadsyntax.com"}],"readme":"> [!WARNING]\n> Agentsmith is currently in alpha. Changes are pushed frequently and may include breaking changes. If you encounter any issues, please reach out to support@agentsmith.dev for assistance.\n\n# @agentsmith-app/sdk\n\nThe Agentsmith SDK provides a type-safe way to interact with your AI agents and prompts. It enables you to:\n\n- Fetch and compile prompts with full TypeScript type safety\n- Execute prompts against various AI models through OpenRouter\n- Integrate AI capabilities into your applications with confidence\n\nThe SDK is designed to work seamlessly with the Agentsmith platform, ensuring that your prompts are always in sync and properly typed.\n\n## Getting Started\n\n### 1. Install the SDK\n\n```sh\nnpm install @agentsmith-app/sdk\n```\n\n### 2. Initialize the SDK in your code\n\n```ts\n// import the generated types (default location is in the agentsmith folder after sync)\nimport { Agency } from '../agentsmith/agentsmith.types';\n\nconst sdkApiKey = 'sdk_********************************'; // copy from your project page/organization settings page\nconst projectId = '123456-abcde-7890-fghij-klmnopqrstuv'; // copy from your project page\n\nconst client = new AgentsmithClient<Agency>(sdkApiKey, projectId);\n```\n\n### 3. Fetch your prompts\n\n```ts\n// pass in the slug, or a string in `slug@version` format\nconst helloWorldLatest = await client.getPrompt('hello-world');\nconst helloWorldLatestAlt = await client.getPrompt('hello-world@latest');\nconst helloWorld0dot0dot1 = await client.getPrompt('hello-world@0.0.1');\n```\n\n### 4. Compile or Execute your prompts\n\n```ts\nconst helloWorldPrompt = await client.getPrompt('hello-world');\n\n// variable typing enforced\nconst { compiledPrompt, finalVariables } = helloWorldPrompt.compile({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\nconsole.log('Compiled prompt:', compiledPrompt);\nconsole.log('Final Variables prompt compiled with:' finalVariables);\n\n// variable typing enforces\nconst { completion } = await helloWorldPrompt.execute({\n  firstName: 'John',\n  lastName: 'Doe,\n});\n\nconsole.log('Completion', completion); // LLM response\n```\n\n### 5. Customize compilation or execution\n\n```ts\nconst helloWorldPrompt = await client.getPrompt('hello-world');\n\n// Override global context variables during compilation\nconst { compiledPrompt } = await helloWorldPrompt.compile(\n  { firstName: 'John', lastName: 'Doe' },\n  {\n    globals: {\n      companyName: 'Acme Corp', // Override global context variable\n      environment: 'production',\n    },\n  },\n);\n\n// Override both global context and model config during execution\nconst { completion } = await helloWorldPrompt.execute(\n  { firstName: 'John', lastName: 'Doe' },\n  {\n    globals: {\n      companyName: 'Acme Corp',\n      environment: 'production',\n    },\n    config: {\n      temperature: 0.7,\n      model: 'x-ai/grok-3-mini-beta',\n    },\n  },\n);\n```\n\nThe config object you pass extends the prompt config object defined in the studio.\nYou can pass whatever values are supported by [OpenRouter's API](https://openrouter.ai/docs/api-reference/overview):\n\n### 6. Shutdown the client when finished\n\n**Important:** Always call `shutdown()` when your application is done using the SDK to prevent scripts from hanging:\n\n```ts\nconst client = new AgentsmithClient<Agency>(sdkApiKey, projectId);\n\n// Your application logic...\nconst helloWorldPrompt = await client.getPrompt('hello-world');\nconst { content } = await helloWorldPrompt.execute({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\nconsole.log('Response:', content);\n\n// Shutdown the client before exiting\nawait client.shutdown();\n```\n\nWithout calling `shutdown()`, your Node.js process may hang indefinitely due to:\n\n- Background HTTP connections staying open\n- Internal processing queues waiting for more work\n- JWT refresh timers continuing to run\n\nThis is especially important in:\n\n- CLI tools and scripts\n- Serverless functions\n- Applications that process requests and exit\n\n## Advanced Usage\n\n### Client configuration\n\nThe `AgentsmithClient` constructor accepts an optional third parameter with advanced configuration options:\n\n```ts\nimport { Agency } from '../agentsmith/agentsmith.types';\n\nconst client = new AgentsmithClient<Agency>(\n  'sdk_********************************', // API key\n  '123456-abcde-7890-fghij-klmnopqrstuv', // Project ID\n  {\n    // Configuration options\n    fetchStrategy: 'remote-fallback',\n    logLevel: 'warn',\n    agentsmithDirectory: './custom-agentsmith-folder',\n    logger: customLogger,\n    queueOptions: { concurrency: 5 },\n  },\n);\n```\n\n#### Available configuration options\n\n**`fetchStrategy`** - Controls how prompts and globals are fetched:\n\n- `'remote-fallback'` (default) - Try filesystem first, fallback to remote API\n- `'fs-fallback'` - Try remote API first, fallback to filesystem\n- `'remote-only'` - Always fetch from remote API, fail if unavailable\n- `'fs-only'` - Always fetch from filesystem, fail if files don't exist\n\n**`logLevel`** - Controls SDK logging verbosity:\n\n- `'debug'` - Show all logs including debug information\n- `'info'` - Show info, warnings, and errors\n- `'warn'` (default) - Show warnings and errors only\n- `'error'` - Show errors only\n- `'silent'` - No logging output\n\n**`logger`** - Custom logger implementation (optional):\n\n```ts\nconst customLogger = {\n  debug: (message: string, ...args: any[]) => myLogger.debug(message, args),\n  info: (message: string, ...args: any[]) => myLogger.info(message, args),\n  warn: (message: string, ...args: any[]) => myLogger.warn(message, args),\n  error: (message: string, ...args: any[]) => myLogger.error(message, args),\n};\n```\n\n**`agentsmithDirectory`** - Path to your agentsmith folder (default: `'./agentsmith'`)\n\n**`queueOptions`** - Options for the internal processing queue (uses [p-queue](https://github.com/sindresorhus/p-queue)):\n\n```ts\nqueueOptions: {\n  concurrency: 3,     // Number of concurrent operations\n  interval: 1000,     // Minimum time between operations\n  intervalCap: 10,    // Max operations per interval\n}\n```\n\n**`agentsmithApiRoot`**, **`supabaseUrl`**, **`supabaseAnonKey`** - Override default API endpoints (typically only needed for self-hosted instances)\n\n#### Graceful shutdown\n\nWhen your application is shutting down, call the `shutdown()` method to ensure all background operations complete gracefully:\n\n```ts\nconst client = new AgentsmithClient<Agency>(apiKey, projectId);\n\n// Your application code...\nawait client.getPrompt('hello-world').execute({ name: 'John' });\n\n// Before exiting your application\nawait client.shutdown();\n```\n\nThe `shutdown()` method will:\n\n- Cancel any ongoing HTTP requests\n- Wait for all queued operations (like log saving) to complete\n- Clean up timers and connections\n- Allow your application to exit cleanly\n\nThis is especially important in serverless environments or when processing multiple requests concurrently.\n\n### Execute method return values\n\nThe SDK's `execute` method returns different fields depending on whether you're using streaming or non-streaming execution. You can destructure these fields to access specific parts of the response:\n\n### Non-streaming execution\n\n```ts\nconst helloWorldPrompt = await client.getPrompt('hello-world');\n\n// Access the content directly without diving into completion.choices[0].message.content\nconst { content } = await helloWorldPrompt.execute({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\nconsole.log('AI Response:', content);\n\n// Access the full OpenRouter response object for additional metadata\nconst { completion, response } = await helloWorldPrompt.execute({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\nconsole.log('Full completion:', completion);\nconsole.log('HTTP response status:', response.status);\nconsole.log('Usage info:', completion.usage);\n\n// Access the compiled prompt and variables that were used in execution\nconst { compiledPrompt, finalVariables } = await helloWorldPrompt.execute({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\nconsole.log('Compiled prompt sent to LLM:', compiledPrompt);\nconsole.log('Final variables used:', finalVariables);\n```\n\n### Streaming execution\n\n```ts\nconst helloWorldPrompt = await client.getPrompt('hello-world');\n\n// Stream tokens as they arrive\nconst { tokens } = await helloWorldPrompt.execute(\n  { firstName: 'John', lastName: 'Doe' },\n  { config: { stream: true } },\n);\n\n// Simple token streaming\nfor await (const token of tokens) {\n  if (token) {\n    process.stdout.write(token);\n  }\n}\n\n// Access the raw SSE stream for more control\nconst { stream } = await helloWorldPrompt.execute(\n  { firstName: 'John', lastName: 'Doe' },\n  { config: { stream: true } },\n);\n\n// Process parsed SSE events\nfor await (const event of stream) {\n  // Each event contains parsed data from the SSE stream\n  if (event.data?.choices?.[0]?.delta?.content) {\n    process.stdout.write(event.data.choices[0].delta.content);\n  }\n\n  // Handle usage information when streaming completes\n  if (event.data?.usage) {\n    console.log('\\nUsage:', event.data.usage);\n  }\n}\n\n// Access other fields like the HTTP response and compiled prompt\nconst { response, compiledPrompt, finalVariables } = await helloWorldPrompt.execute(\n  { firstName: 'John', lastName: 'Doe' },\n  { config: { stream: true } },\n);\n\nconsole.log('HTTP response headers:', response.headers);\nconsole.log('Compiled prompt:', compiledPrompt);\nconsole.log('Variables used:', finalVariables);\n```\n\n### Custom message arrays\n\nBy default, `execute` compiles your prompt and sends it as a single user message. For advanced use cases, you can compile the prompt separately and create your own message array:\n\n```ts\nconst helloWorldPrompt = await client.getPrompt('hello-world');\n\n// First, compile the prompt to get the final content\nconst { compiledPrompt } = await helloWorldPrompt.compile({\n  firstName: 'John',\n  lastName: 'Doe',\n});\n\n// Create a custom messages array for multi-turn conversations\nconst customMessages = [\n  { role: 'system', content: 'You are a helpful assistant.' },\n  { role: 'user', content: 'Hello, I need help with something.' },\n  { role: 'assistant', content: 'Of course! How can I assist you today?' },\n  { role: 'user', content: compiledPrompt }, // Use your compiled prompt\n];\n\n// Execute with custom messages array\nconst { completion } = await helloWorldPrompt.execute(\n  { firstName: 'John', lastName: 'Doe' },\n  {\n    config: {\n      messages: customMessages, // Override the default single-message behavior\n      temperature: 0.7,\n    },\n  },\n);\n\nconsole.log('Multi-turn response:', completion.choices[0].message.content);\n```\n\nThis is particularly useful for:\n\n- Building multi-turn conversations\n- Adding system prompts or context\n- Creating few-shot examples with assistant responses\n- Implementing conversation flows where your compiled prompt is just one part of a larger exchange\n\n### Available return fields\n\n**Non-streaming execution** returns:\n\n- `content` - The AI response content (shortcut for `completion.choices[0].message.content`)\n- `reasoning` - The AI response reasoning content (shortcut for `completion.choices[0].message.reasoning`)\n- `toolCalls` - The AI response tool calls\n- `completion` - Full OpenRouter completion object with choices, usage, etc.\n- `response` - Raw HTTP Response object\n- `compiledPrompt` - The final prompt sent to the LLM\n- `finalVariables` - Variables used in compilation (includes defaults and globals)\n- `logUuid` - UUID of the log entry created for this execution\n\n**Streaming execution** returns:\n\n- `tokens` - AsyncGenerator that yields content tokens as strings\n- `reasoningTokens` - AsyncGenerator that yields reasoning tokens as strings\n- `toolCalls` - AsyncGenerator that yields tool calls\n- `completion` - A Promise of the final completion data in NonStreamingResponse format\n- `stream` - Raw SSE stream as an AsyncIterable of parsed events\n- `response` - Raw HTTP Response object\n- `compiledPrompt` - The final prompt sent to the LLM\n- `finalVariables` - Variables used in compilation (includes defaults and globals)\n- `logUuid` - UUID of the log entry created for this execution\n\n## Development\n\n1.  **Install dependencies**\n\n    Navigate to the `sdk` directory and install the necessary dependencies:\n\n    ```sh\n    cd sdk\n    npm install\n    ```\n\n2.  **Build the SDK**\n\n    Run the build command which will build esm, cjs, and dts files into the `sdk/dist` directory\n\n    ```sh\n    npm run build\n    ```\n\n3.  **Link the SDK**\n\n    To test local changes in a consuming project without publishing to npm, use `npm link`:\n\n    - **In the `sdk` directory:**\n      Create a global symbolic link.\n\n      ```sh\n      npm link\n      ```\n\n      Remember to rebuild the SDK (step 2) after making changes.\n\n    - **In your consuming project:**\n      Link the globally created symbolic link to your project's `node_modules` directory.\n      ```sh\n      npm link @agentsmith-app/sdk\n      ```\n\n    Now, your consuming project will use your local version of `@agentsmith-app/sdk`. Changes in the SDK (followed by a rebuild) will be reflected immediately.\n\n### Unlinking the SDK\n\nOnce you're done with local development and testing, you might want to unlink the SDK to revert to using the version from npm.\n\n1.  **In your consuming project:**\n\n    ```sh\n    npm unlink @agentsmith-app/sdk\n    # Optionally, reinstall the package from npm if you were using a published version before linking\n    # npm install @agentsmith-app/sdk\n    ```\n\n2.  **In the `agentsmith/sdk` directory (optional but good practice):**\n    This removes the global link.\n    ```sh\n    npm unlink\n    ```\n\nThis will remove the symbolic links and restore the normal package resolution.\n\n## Roadmap\n\n- [ ] Add background check for latest prompts in db and hold in memory\n- [ ] Add memoization for prompts to reduce calls to fs/db\n","readmeFilename":"README.md"}