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

Function main

sdk/e2e/examples/code-explainer.example.ts:25–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23`.trim()
24
25async function main() {
26 const apiKey = process.env.CODEBUFF_API_KEY
27 if (!apiKey) {
28 console.error('CODEBUFF_API_KEY environment variable is required')
29 process.exit(1)
30 }
31
32 const client = new CodebuffClient({ apiKey })
33
34 console.log('📖 Explaining code...\n')
35 console.log('Code to explain:')
36 console.log('```')
37 console.log(SAMPLE_CODE)
38 console.log('```\n')
39 console.log('Explanation:\n')
40
41 const result = await client.run({
42 agent: 'codebuff/base2@latest',
43 prompt: `Explain what this code does in simple terms:\n\n${SAMPLE_CODE}`,
44 handleStreamChunk: (chunk) => {
45 if (typeof chunk === 'string') {
46 process.stdout.write(chunk)
47 }
48 },
49 })
50
51 console.log('\n')
52
53 if (result.output.type === 'error') {
54 console.error('Error:', result.output.message)
55 process.exit(1)
56 }
57
58 console.log('✅ Done!')
59}
60
61main().catch(console.error)

Callers 1

Calls 1

runMethod · 0.95

Tested by

no test coverage detected