| 1 | import { CodebuffClient } from '@codebuff/sdk' |
| 2 | |
| 3 | async function main() { |
| 4 | const client = new CodebuffClient({ |
| 5 | // You need to pass in your own API key here. |
| 6 | // Get one here: https://www.codebuff.com/api-keys |
| 7 | apiKey: process.env.CODEBUFF_API_KEY, |
| 8 | cwd: process.cwd(), |
| 9 | }) |
| 10 | |
| 11 | // First run |
| 12 | const runState1 = await client.run({ |
| 13 | // The agent id. Any agent on the store (https://codebuff.com/store) |
| 14 | agent: 'codebuff/base@0.0.16', |
| 15 | prompt: 'Create a simple calculator class', |
| 16 | handleEvent: (event) => { |
| 17 | // All events that happen during the run: agent start/finish, tool calls/results, text responses, errors. |
| 18 | console.log('Codebuff Event', JSON.stringify(event)) |
| 19 | }, |
| 20 | }) |
| 21 | |
| 22 | // Continue the same session with a follow-up |
| 23 | const _runOrError2 = await client.run({ |
| 24 | agent: 'codebuff/base@0.0.16', |
| 25 | prompt: 'Add unit tests for the calculator', |
| 26 | previousRun: runState1, // <-- this is where your next run differs from the previous run |
| 27 | handleEvent: (event) => { |
| 28 | console.log('Codebuff Event', JSON.stringify(event)) |
| 29 | }, |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | main() |