@@ -24,29 +24,19 @@ async function main() {
2424 // You need to pass in your own API key here.
2525 // Get one here: https://www.codebuff.com/api-keys
2626 apiKey: process .env .CODEBUFF_API_KEY ,
27- cwd: process .cwd (),
2827 })
2928
3029 // First run
31- console .log (' ------- First run started -------' )
3230 const run1 = await client .run ({
3331 agent: ' base' ,
3432 prompt: ' Create a simple calculator class' ,
3533 handleEvent : (event ) => {
36- // This will fire for all events that happen during the run, like when each agent starts/stops and when they respond .
37- console .dir ( event , { depth: null }) // Log all events
34+ // All events that happen during the run: agent start/finish, tool calls/results, text responses, errors .
35+ console .log ( ' Event ' , event )
3836 },
3937 })
40- console .log (' ------- First run ended -------' )
41-
42- if (run1 .output .type === ' error' ) {
43- // The previous run failed, handleEvent should have been called with an error
44- console .error (` First run failed:\n ${run1 .output .message } ` )
45- process .exit (1 )
46- }
4738
4839 // Continue the same session with a follow-up
49- console .log (' ------- Second run started -------' )
5040 const run2 = await client .run ({
5141 agent: ' base' ,
5242 prompt: ' Add unit tests for the calculator' ,
@@ -55,7 +45,6 @@ async function main() {
5545 console .dir (event , { depth: null })
5646 },
5747 })
58- console .log (' ------- Second run ended -------' )
5948}
6049
6150main ()
@@ -77,6 +66,7 @@ async function main() {
7766 // Note: You need to pass in your own API key.
7867 // Get it here: https://www.codebuff.com/profile?tab=api-keys
7968 apiKey: process .env .CODEBUFF_API_KEY ,
69+ // Optional directory agent runs from (if applicable).
8070 cwd: process .cwd (),
8171 })
8272
@@ -121,11 +111,16 @@ async function main() {
121111 agentDefinitions: [myCustomAgent ],
122112 customToolDefinitions: [myCustomTool ],
123113 handleEvent : (event ) => {
124- console .log (event )
114+ // All events that happen during the run: agent start/finish, tool calls/results, text responses, errors.
115+ console .log (' Event' , event )
125116 },
126117 })
127118
128- console .log (' Final output:' , output )
119+ if (output .type === ' error' ) {
120+ console .error (` The run failed:\n ${output .message } ` )
121+ } else {
122+ console .log (' The run succeeded with output:' , output )
123+ }
129124}
130125
131126main ()
0 commit comments