MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / main

Function main

sdk/e2e/examples/sdk-refactor.example.ts:26–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24`.trim()
25
26async function main() {
27 const apiKey = process.env.CODEBUFF_API_KEY
28 if (!apiKey) {
29 console.error('CODEBUFF_API_KEY environment variable is required')
30 process.exit(1)
31 }
32
33 const client = new CodebuffClient({ apiKey })
34
35 console.log('🔧 Refactoring code...\n')
36 console.log('Original code:')
37 console.log('```')
38 console.log(CODE_TO_REFACTOR)
39 console.log('```\n')
40 console.log('Refactored version:\n')
41
42 const result = await client.run({
43 agent: 'codebuff/base2@latest',
44 prompt: `Refactor this code to be more readable and use modern JavaScript features:\n\n${CODE_TO_REFACTOR}`,
45 handleStreamChunk: (chunk) => {
46 if (typeof chunk === 'string') {
47 process.stdout.write(chunk)
48 }
49 },
50 })
51
52 console.log('\n')
53
54 if (result.output.type === 'error') {
55 console.error('Error:', result.output.message)
56 process.exit(1)
57 }
58
59 console.log('✅ Refactoring complete!')
60}
61
62main().catch(console.error)

Callers 1

Calls 1

runMethod · 0.95

Tested by

no test coverage detected