@@ -39,9 +39,9 @@ async function main() {
3939 })
4040 console .log (' ------- First run ended -------' )
4141
42- if (! run1 ) {
42+ if (run1 . output . type === ' error ' ) {
4343 // The previous run failed, handleEvent should have been called with an error
44- console .error (' First run failed. ' )
44+ console .error (` First run failed: \n ${ run1 . output . message } ` )
4545 process .exit (1 )
4646 }
4747
@@ -66,20 +66,18 @@ main()
6666Here, we create a full agent and custom tools that can be reused between runs.
6767
6868``` typescript
69- import { z } from ' zod'
70- import {
71- CodebuffClient ,
72- AgentDefinition ,
73- getCustomToolDefinition ,
74- } from ' @codebuff/sdk'
69+ import { z } from ' zod/v4'
70+
71+ import { CodebuffClient , getCustomToolDefinition } from ' @codebuff/sdk'
72+
73+ import type { AgentDefinition } from ' @codebuff/sdk'
7574
7675async function main() {
7776 const client = new CodebuffClient ({
7877 // Note: You need to pass in your own API key.
7978 // Get it here: https://www.codebuff.com/profile?tab=api-keys
8079 apiKey: process .env .CODEBUFF_API_KEY ,
8180 cwd: process .cwd (),
82- onError : (e ) => console .error (' Codebuff error:' , e .message ),
8381 })
8482
8583 // This is a custom agent that can be used instead of the `base` agent or other agents on the Codebuff store (https://codebuff.com/store).
@@ -102,16 +100,8 @@ async function main() {
102100 method: z .enum ([' GET' , ' POST' ]).default (' GET' ),
103101 headers: z .record (z .string (), z .string ()).optional (),
104102 }),
105- outputSchema: z .array (
106- z .object ({
107- type: z .literal (' json' ),
108- value: z .object ({
109- message: z .string (),
110- }),
111- }),
112- ),
113103 exampleInputs: [{ url: ' https://api.example.com/data' , method: ' GET' }],
114- handler : async ({ url , method , headers }) => {
104+ execute : async ({ url , method , headers }) => {
115105 const response = await fetch (url , { method , headers })
116106 const data = await response .text ()
117107 return [
@@ -136,8 +126,6 @@ async function main() {
136126 })
137127
138128 console .log (' Final output:' , output )
139-
140- client .closeConnection ()
141129}
142130
143131main ()
0 commit comments