@fatagnus/codebuff 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @codebuff/sdk
1
+ # @fatagnus/codebuff
2
2
 
3
3
  Official SDK for Codebuff - AI coding agent and framework
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @codebuff/sdk
8
+ npm install @fatagnus/codebuff
9
9
  ```
10
10
 
11
11
  ## Prerequisites
@@ -17,7 +17,7 @@ npm install @codebuff/sdk
17
17
  ### Basic Example
18
18
 
19
19
  ```typescript
20
- import { CodebuffClient } from '@codebuff/sdk'
20
+ import { CodebuffClient } from '@fatagnus/codebuff'
21
21
 
22
22
  async function main() {
23
23
  const client = new CodebuffClient({
@@ -59,9 +59,9 @@ Here, we create a full agent and custom tools that can be reused between runs.
59
59
  ```typescript
60
60
  import { z } from 'zod/v4'
61
61
 
62
- import { CodebuffClient, getCustomToolDefinition } from '@codebuff/sdk'
62
+ import { CodebuffClient, getCustomToolDefinition } from '@fatagnus/codebuff'
63
63
 
64
- import type { AgentDefinition } from '@codebuff/sdk'
64
+ import type { AgentDefinition } from '@fatagnus/codebuff'
65
65
 
66
66
  async function main() {
67
67
  const client = new CodebuffClient({
@@ -160,7 +160,7 @@ const client = new CodebuffClient({
160
160
  Loads agent definitions from `.agents` directories on disk.
161
161
 
162
162
  ```typescript
163
- import { loadLocalAgents, CodebuffClient } from '@codebuff/sdk'
163
+ import { loadLocalAgents, CodebuffClient } from '@fatagnus/codebuff'
164
164
 
165
165
  // Load from default locations (.agents in cwd, parent, or home)
166
166
  const agents = await loadLocalAgents({ verbose: true })
@@ -243,6 +243,157 @@ The `RunState` object contains:
243
243
  - `sessionState`: Internal state to be passed to the next run
244
244
  - `output`: The agent's output (text, error, or other types)
245
245
 
246
+ ## Convex Compatibility
247
+
248
+ This SDK includes a special entry point for running agents in [Convex](https://convex.dev) backend actions. Convex actions run in a sandboxed Node.js environment without access to the file system or `child_process`, so we provide a `ConvexCodebuffClient` that works within these constraints.
249
+
250
+ ### Installation for Convex
251
+
252
+ ```bash
253
+ npm install @fatagnus/codebuff
254
+ ```
255
+
256
+ ### Basic Convex Example
257
+
258
+ ```typescript
259
+ import { ConvexCodebuffClient } from '@fatagnus/codebuff/convex'
260
+
261
+ // In a Convex action
262
+ export async function analyzeCode(apiKey: string, codeToAnalyze: string) {
263
+ const client = new ConvexCodebuffClient({
264
+ apiKey,
265
+ // In Convex, provide project files as a plain object since there's no file system
266
+ projectFiles: {
267
+ 'code-to-analyze.ts': codeToAnalyze,
268
+ },
269
+ })
270
+
271
+ const result = await client.run({
272
+ agent: 'codebuff/base-lite@1.0.0',
273
+ prompt: 'Please analyze the code in code-to-analyze.ts and explain what it does.',
274
+ })
275
+
276
+ if (result.output.type === 'error') {
277
+ throw new Error(`Agent error: ${result.output.message}`)
278
+ }
279
+
280
+ return result.output
281
+ }
282
+ ```
283
+
284
+ ### Full Convex Action Example
285
+
286
+ ```typescript
287
+ import { action } from "./_generated/server"
288
+ import { v } from "convex/values"
289
+ import { ConvexCodebuffClient } from "@fatagnus/codebuff/convex"
290
+
291
+ export const analyzeCode = action({
292
+ args: {
293
+ code: v.string(),
294
+ },
295
+ handler: async (ctx, args) => {
296
+ const apiKey = process.env.CODEBUFF_API_KEY
297
+ if (!apiKey) throw new Error("CODEBUFF_API_KEY not configured")
298
+
299
+ const client = new ConvexCodebuffClient({
300
+ apiKey,
301
+ projectFiles: { "input.ts": args.code },
302
+ maxAgentSteps: 10, // Limit steps to stay within Convex's timeout
303
+ })
304
+
305
+ const result = await client.run({
306
+ agent: "codebuff/base-lite@1.0.0",
307
+ prompt: "Analyze this code and suggest improvements.",
308
+ })
309
+
310
+ if (result.output.type === "error") {
311
+ throw new Error(result.output.message)
312
+ }
313
+
314
+ return result.output
315
+ },
316
+ })
317
+ ```
318
+
319
+ ### Multi-turn Conversations in Convex
320
+
321
+ ```typescript
322
+ import { ConvexCodebuffClient } from '@fatagnus/codebuff/convex'
323
+
324
+ export async function multiTurnConversation(
325
+ apiKey: string,
326
+ projectFiles: Record<string, string>,
327
+ ) {
328
+ const client = new ConvexCodebuffClient({
329
+ apiKey,
330
+ projectFiles,
331
+ })
332
+
333
+ // First turn
334
+ const run1 = await client.run({
335
+ agent: 'codebuff/base-lite@1.0.0',
336
+ prompt: 'What files are in this project?',
337
+ })
338
+
339
+ // Second turn - continues the conversation
340
+ const run2 = await client.run({
341
+ agent: 'codebuff/base-lite@1.0.0',
342
+ prompt: 'Now explain the main entry point.',
343
+ previousRun: run1, // Pass the previous run state to continue the conversation
344
+ })
345
+
346
+ return run2
347
+ }
348
+ ```
349
+
350
+ ### Convex Limitations
351
+
352
+ When running in Convex, the following tools are **not available** (they will throw `ConvexUnsupportedToolError`):
353
+
354
+ - `run_terminal_command` - No `child_process` access
355
+ - `code_search` - Requires ripgrep and file system
356
+ - `write_file` / `str_replace` - No file system write access
357
+ - `list_directory` / `glob` - No file system access
358
+
359
+ You can provide custom implementations via `overrideTools` if needed:
360
+
361
+ ```typescript
362
+ const client = new ConvexCodebuffClient({
363
+ apiKey,
364
+ projectFiles: myFiles,
365
+ overrideTools: {
366
+ read_files: async ({ filePaths }) => {
367
+ // Custom implementation to fetch files from your database
368
+ const result: Record<string, string | null> = {}
369
+ for (const path of filePaths) {
370
+ result[path] = await fetchFileFromDatabase(path)
371
+ }
372
+ return result
373
+ },
374
+ },
375
+ })
376
+ ```
377
+
378
+ ### ConvexCodebuffClient API
379
+
380
+ #### Constructor Options
381
+
382
+ - **`apiKey`** (string, required): Your Codebuff API key
383
+ - **`projectFiles`** (object, optional): Files as `{ path: content }` - required since there's no file system
384
+ - **`knowledgeFiles`** (object, optional): Knowledge files to inject into context
385
+ - **`agentDefinitions`** (array, optional): Custom agent definitions
386
+ - **`maxAgentSteps`** (number, optional): Max steps before stopping (recommended: 10-20 for Convex timeout limits)
387
+ - **`handleEvent`** (function, optional): Event callback for streaming
388
+ - **`handleStreamChunk`** (function, optional): Chunk callback for real-time updates
389
+ - **`overrideTools`** (object, optional): Custom tool implementations
390
+ - **`customToolDefinitions`** (array, optional): Custom tool definitions
391
+
392
+ #### Methods
393
+
394
+ - **`run(options)`**: Run an agent (same options as standard `CodebuffClient.run()`)
395
+ - **`checkConnection()`**: Check if the Codebuff backend is reachable
396
+
246
397
  ## License
247
398
 
248
399
  MIT