Skip to content

Commit 29d512f

Browse files
committed
update readme for sdk
1 parent 3960e5f commit 29d512f

File tree

1 file changed

+91
-37
lines changed

1 file changed

+91
-37
lines changed

sdk/README.md

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,112 @@ npm install @codebuff/sdk
1111
## Prerequisites
1212

1313
1. Install the Codebuff CLI globally:
14+
1415
```bash
1516
npm install -g codebuff
1617
```
1718

18-
2. Set your API key:
19+
2. Login to `codebuff` to store the API key in your local config:
1920
```bash
20-
export CODEBUFF_API_KEY="your-api-key"
21+
codebuff login
2122
```
2223

2324
## Usage
2425

2526
```typescript
26-
import { CodebuffClient } from '@codebuff/sdk'
27-
28-
const client = new CodebuffClient({
29-
cwd: process.cwd()
27+
import * as fs from 'fs'
28+
import * as os from 'os'
29+
30+
import { WebSocketHandler, getInitialSessionState } from '@codebuff/sdk'
31+
32+
const client = new WebSocketHandler({
33+
onWebsocketError: (error) => {
34+
console.log({ error }, 'onWebsocketError')
35+
},
36+
onWebsocketReconnect: () => {
37+
console.log('onWebsocketReconnect')
38+
},
39+
onRequestReconnect: async () => {
40+
console.log('onRequestReconnect')
41+
},
42+
readFiles: async (input) => {
43+
console.log({ input }, 'readFiles')
44+
return {}
45+
},
46+
handleToolCall: async ({
47+
type,
48+
toolName,
49+
requestId,
50+
userInputId,
51+
args,
52+
timeout,
53+
}) => {
54+
console.log(
55+
{ type, toolName, requestId, userInputId, args, timeout },
56+
'handleToolCall',
57+
)
58+
return { success: true, toolCallResult: 'asdf' }
59+
},
60+
onCostResponse: async (action) => {
61+
console.log({ action }, 'onCostResponse')
62+
},
63+
onUsageResponse: async (action) => {
64+
console.log({ action }, 'onUsageResponse')
65+
},
66+
onResponseChunk: async (action) => {
67+
console.log({ action }, 'onResponseChunk')
68+
},
69+
onSubagentResponseChunk: async (action) => {
70+
console.log({ action }, 'onSubagentResponseChunk')
71+
},
72+
onPromptResponse: async (response) => {
73+
console.log({ response }, 'onPromptResponse')
74+
},
75+
// Available after running `codebuff login`
76+
apiKey: JSON.parse(
77+
fs
78+
.readFileSync(os.homedir() + '/.config/manicode/credentials.json')
79+
.toString(),
80+
).default.authToken,
3081
})
3182

32-
// Start a new chat with an agent
33-
await client.runNewChat({
34-
agent: 'base',
35-
prompt: 'Add a new function to calculate fibonacci numbers',
36-
handleEvent: (event) => {
37-
console.log(event)
38-
}
83+
console.log('connecting')
84+
await client.connect()
85+
console.log('connected')
86+
client.sendInput({
87+
prompt: 'can you run echo "hi" for me?',
88+
promptId: 'some-prompt-id-12345',
89+
costMode: 'normal',
90+
sessionState: getInitialSessionState({
91+
projectRoot: os.homedir() + '/github/codebuff',
92+
cwd: os.homedir() + '/github/codebuff',
93+
fileTree: [],
94+
fileTokenScores: {},
95+
tokenCallers: {},
96+
knowledgeFiles: {},
97+
userKnowledgeFiles: {},
98+
agentTemplates: {},
99+
gitChanges: {
100+
status: '',
101+
diff: '',
102+
diffCached: '',
103+
lastCommitMessages: '',
104+
},
105+
changesSinceLastChat: {},
106+
shellConfigFiles: {},
107+
systemInfo: {
108+
platform: process.platform,
109+
shell: 'bash',
110+
nodeVersion: process.version,
111+
arch: process.arch,
112+
homedir: os.homedir() + '/github/codebuff',
113+
cpus: 16,
114+
},
115+
}),
116+
toolResults: [],
39117
})
40118
```
41119

42-
## API Reference
43-
44-
### CodebuffClient
45-
46-
#### Constructor
47-
48-
```typescript
49-
new CodebuffClient({ cwd: string })
50-
```
51-
52-
#### Methods
53-
54-
##### runNewChat(options)
55-
56-
Starts a new chat session with a Codebuff agent.
57-
58-
**Parameters:**
59-
- `agent`: The agent type to use (e.g., 'base', 'base-lite', 'base-max')
60-
- `prompt`: The instruction to send to the agent
61-
- `params`: Optional parameters for the agent
62-
- `handleEvent`: Callback function to handle streaming events
63-
64-
**Returns:** Promise<ChatContext>
65-
66120
## License
67121

68122
MIT

0 commit comments

Comments
 (0)