Skip to content

Commit 9e81618

Browse files
committed
Initial sdk package + publish
1 parent 68fe70c commit 9e81618

File tree

7 files changed

+306
-17
lines changed

7 files changed

+306
-17
lines changed

sdk/.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Source files
2+
src/
3+
4+
# Development files
5+
tsconfig.json
6+
bun.lockb
7+
.DS_Store
8+
9+
# Test files
10+
**/*.test.ts
11+
**/*.spec.ts
12+
13+
# Build artifacts
14+
*.tsbuildinfo

sdk/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to the @codebuff/sdk package will be documented in this file.
4+
5+
## [0.0.1] - 2025-01-05
6+
7+
### Added
8+
- Initial release of the Codebuff SDK
9+
- `CodebuffClient` class for interacting with Codebuff agents
10+
- `runNewChat` method for starting new chat sessions
11+
- TypeScript support with full type definitions
12+
- Support for all Codebuff agent types
13+
- Event streaming for real-time responses

sdk/PUBLISHING.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Publishing the Codebuff SDK
2+
3+
## Quick Start
4+
5+
To publish the SDK to npm:
6+
7+
```bash
8+
# Dry run (recommended first)
9+
bun run publish-dry-run
10+
11+
# Publish to npm
12+
bun run publish-sdk
13+
```
14+
15+
## What the Publishing Script Does
16+
17+
1. **Cleans** previous build artifacts
18+
2. **Builds** TypeScript to JavaScript and .d.ts files
19+
3. **Prepares package.json** for publishing:
20+
- Updates file paths (removes `./dist/` prefix)
21+
- Converts workspace dependencies to peer dependencies
22+
- Sets public access
23+
4. **Copies** README.md and CHANGELOG.md to dist
24+
5. **Verifies** package contents with `npm pack --dry-run`
25+
6. **Publishes** to npm (if not dry run)
26+
27+
## Available Scripts
28+
29+
- `bun run build` - Build TypeScript only
30+
- `bun run clean` - Remove dist directory
31+
- `bun run publish-dry-run` - Full build + verification (no publish)
32+
- `bun run publish-sdk` - Full build + publish to npm
33+
- `bun run typecheck` - Type checking only
34+
35+
## Before Publishing
36+
37+
1. Update version in `package.json`
38+
2. Update `CHANGELOG.md` with new changes
39+
3. Run `bun run publish-dry-run` to verify
40+
4. Run `bun run publish-sdk` to publish
41+
42+
## Package Contents
43+
44+
The published package includes:
45+
- All compiled `.js` files
46+
- All TypeScript declaration `.d.ts` files
47+
- Source maps `.d.ts.map` files
48+
- README.md
49+
- CHANGELOG.md
50+
- Modified package.json with correct paths

sdk/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# @codebuff/sdk
2+
3+
Official SDK for Codebuff - AI coding agent and framework
4+
5+
## Installation
6+
7+
```bash
8+
npm install @codebuff/sdk
9+
```
10+
11+
## Prerequisites
12+
13+
1. Install the Codebuff CLI globally:
14+
```bash
15+
npm install -g codebuff
16+
```
17+
18+
2. Set your API key:
19+
```bash
20+
export CODEBUFF_API_KEY="your-api-key"
21+
```
22+
23+
## Usage
24+
25+
```typescript
26+
import { CodebuffClient } from '@codebuff/sdk'
27+
28+
const client = new CodebuffClient({
29+
cwd: process.cwd()
30+
})
31+
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+
}
39+
})
40+
```
41+
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+
66+
## License
67+
68+
MIT

sdk/package.json

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,54 @@
11
{
22
"name": "@codebuff/sdk",
3-
"version": "1.0.0",
4-
"private": true,
5-
"license": "UNLICENSED",
3+
"private": false,
4+
"access": "public",
5+
"version": "0.0.1",
6+
"description": "Official SDK for Codebuff — AI coding agent & framework",
7+
"license": "MIT",
68
"type": "module",
9+
"main": "./dist/index.js",
10+
"types": "./dist/index.d.ts",
711
"exports": {
812
".": {
9-
"bun": "./src/index.ts",
10-
"import": "./src/index.ts",
11-
"types": "./src/index.ts",
12-
"default": "./src/index.ts"
13-
},
14-
"./*": {
15-
"bun": "./src/*.ts",
16-
"import": "./src/*.ts",
17-
"types": "./src/*.ts",
18-
"default": "./src/*.ts"
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/index.js",
15+
"default": "./dist/index.js"
1916
}
2017
},
18+
"files": [
19+
"dist",
20+
"README.md"
21+
],
2122
"scripts": {
23+
"build": "tsc",
24+
"clean": "rm -rf dist",
25+
"prepare-dist": "node scripts/publish.js --dry-run",
26+
"publish-sdk": "node scripts/publish.js --public",
27+
"publish-dry-run": "node scripts/publish.js --dry-run",
28+
"prepublishOnly": "bun run clean && bun run build",
2229
"typecheck": "tsc --noEmit -p .",
2330
"test": "bun test"
2431
},
2532
"sideEffects": false,
2633
"engines": {
27-
"bun": ">=1.2.11"
34+
"node": ">=18.0.0"
35+
},
36+
"keywords": [
37+
"codebuff",
38+
"ai",
39+
"code-editing",
40+
"assistant",
41+
"sdk",
42+
"typescript"
43+
],
44+
"repository": {
45+
"type": "git",
46+
"url": "https://github.com/codebuff/codebuff.git",
47+
"directory": "sdk"
48+
},
49+
"homepage": "https://codebuff.com",
50+
"bugs": {
51+
"url": "https://github.com/codebuff/codebuff/issues"
2852
},
2953
"dependencies": {
3054
"@codebuff/common": "workspace:*"

sdk/scripts/publish.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'child_process'
4+
import fs from 'fs'
5+
import path from 'path'
6+
import { fileURLToPath } from 'url'
7+
8+
const __filename = fileURLToPath(import.meta.url)
9+
const __dirname = path.dirname(__filename)
10+
11+
function log(message) {
12+
console.log(`📦 ${message}`)
13+
}
14+
15+
function run(command, options = {}) {
16+
log(`Running: ${command}`)
17+
try {
18+
return execSync(command, { stdio: 'inherit', ...options })
19+
} catch (error) {
20+
console.error(`❌ Command failed: ${command}`)
21+
process.exit(1)
22+
}
23+
}
24+
25+
function main() {
26+
const args = process.argv.slice(2)
27+
const isDryRun = args.includes('--dry-run')
28+
29+
log('Starting SDK publishing process...')
30+
31+
// Clean and build
32+
log('Cleaning previous build...')
33+
run('bun run clean')
34+
35+
log('Building TypeScript...')
36+
run('bun run build')
37+
38+
// Prepare package.json for publishing
39+
log('Preparing package.json for publishing...')
40+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
41+
42+
// Remove workspace dependencies and replace with actual versions
43+
if (packageJson.dependencies && packageJson.dependencies['@codebuff/common']) {
44+
// For now, we'll make it a peer dependency since it's not published yet
45+
delete packageJson.dependencies['@codebuff/common']
46+
if (!packageJson.peerDependencies) {
47+
packageJson.peerDependencies = {}
48+
}
49+
packageJson.peerDependencies['@codebuff/common'] = '*'
50+
}
51+
52+
// Update paths for publishing from dist directory
53+
packageJson.main = './index.js'
54+
packageJson.types = './index.d.ts'
55+
packageJson.exports = {
56+
'.': {
57+
types: './index.d.ts',
58+
import: './index.js',
59+
default: './index.js'
60+
}
61+
}
62+
63+
// Update files field to include all built files
64+
packageJson.files = [
65+
'*.js',
66+
'*.d.ts',
67+
'*.d.ts.map',
68+
'README.md',
69+
'CHANGELOG.md'
70+
]
71+
72+
// Write the modified package.json to dist
73+
fs.writeFileSync('dist/package.json', JSON.stringify(packageJson, null, 2))
74+
75+
// Copy other files
76+
log('Copying additional files...')
77+
const filesToCopy = ['README.md', 'CHANGELOG.md']
78+
79+
for (const file of filesToCopy) {
80+
if (fs.existsSync(file)) {
81+
fs.copyFileSync(file, `dist/${file}`)
82+
log(`Copied ${file}`)
83+
}
84+
}
85+
86+
// Verify the package
87+
log('Verifying package contents...')
88+
run('npm pack --dry-run', { cwd: 'dist' })
89+
90+
if (isDryRun) {
91+
log('Dry run complete! Package is ready for publishing.')
92+
log('To publish for real, run: bun run publish-sdk')
93+
return
94+
}
95+
96+
// Publish
97+
log('Publishing to npm...')
98+
const publishCommand = 'npm publish'
99+
run(publishCommand, { cwd: 'dist' })
100+
log('✅ SDK published successfully!')
101+
log(`📦 Package: ${packageJson.name}@${packageJson.version}`)
102+
}
103+
104+
if (import.meta.url === `file://${process.argv[1]}`) {
105+
main()
106+
}
107+

sdk/tsconfig.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
2-
"extends": "../tsconfig.base.json",
32
"compilerOptions": {
4-
"types": ["bun", "node"]
3+
"target": "ES2021",
4+
"lib": ["ES2021", "DOM"],
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"declaration": true,
13+
"declarationMap": true,
14+
"outDir": "./dist",
15+
"rootDir": "./src",
16+
"allowImportingTsExtensions": false,
17+
"types": ["node"]
518
},
619
"include": ["src/**/*.ts"],
7-
"exclude": ["node_modules"]
20+
"exclude": ["node_modules", "dist"]
821
}

0 commit comments

Comments
 (0)