Skip to content

Commit 8e662a3

Browse files
committed
fix sdk types
1 parent 6a62466 commit 8e662a3

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:esm": "cd test/esm-compatibility && npm install --silent && npm run test:all",
3232
"test:ripgrep": "cd test/ripgrep-bundling && npm install --silent && npm run test:all",
3333
"test:tree-sitter-queries": "cd test/tree-sitter-queries && npm install --silent && npm run test:all",
34+
"test:types": "bun run scripts/test-types.ts",
3435
"test:e2e": "bun test e2e/streaming/ e2e/workflows/ e2e/custom-agents/ e2e/features/",
3536
"test:integration": "bun test e2e/integration/",
3637
"test:unit:e2e": "bun test e2e/utils/__tests__/",

sdk/scripts/test-types.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bun
2+
/**
3+
* Script to test SDK types by running setup in each test subproject.
4+
* Removes the previous node_modules/@codebuff/sdk installation before running setup.
5+
*/
6+
7+
import { execSync } from 'child_process'
8+
import { existsSync, rmSync } from 'fs'
9+
import { join } from 'path'
10+
11+
const TEST_SUBPROJECTS = [
12+
'cjs-compatibility',
13+
'esm-compatibility',
14+
'ripgrep-bundling',
15+
]
16+
17+
const sdkRoot = join(import.meta.dirname, '..')
18+
const testDir = join(sdkRoot, 'test')
19+
20+
function log(message: string) {
21+
console.log(`\n📦 ${message}`)
22+
}
23+
24+
function removeOldSdk(projectPath: string) {
25+
const sdkPath = join(projectPath, 'node_modules', '@codebuff', 'sdk')
26+
if (existsSync(sdkPath)) {
27+
console.log(` 🗑️ Removing old SDK at ${sdkPath}`)
28+
rmSync(sdkPath, { recursive: true, force: true })
29+
}
30+
}
31+
32+
function runSetup(projectName: string) {
33+
const projectPath = join(testDir, projectName)
34+
35+
if (!existsSync(projectPath)) {
36+
console.error(` ❌ Project not found: ${projectPath}`)
37+
process.exit(1)
38+
}
39+
40+
log(`Setting up ${projectName}...`)
41+
42+
// Remove old SDK installation
43+
removeOldSdk(projectPath)
44+
45+
// Run npm install to ensure dependencies are present
46+
console.log(` 📥 Installing dependencies...`)
47+
execSync('npm install --silent', { cwd: projectPath, stdio: 'inherit' })
48+
49+
// Run the setup script
50+
console.log(` 🔧 Running setup script...`)
51+
execSync('npm run setup', { cwd: projectPath, stdio: 'inherit' })
52+
53+
// Run type tests
54+
console.log(` 🔍 Running type tests...`)
55+
execSync('npm run test:types', { cwd: projectPath, stdio: 'inherit' })
56+
57+
console.log(` ✅ ${projectName} types passed!`)
58+
}
59+
60+
async function main() {
61+
console.log('🧪 SDK Type Testing Script')
62+
console.log('==========================')
63+
64+
// Ensure the SDK is built first
65+
log('Checking SDK dist...')
66+
const distPath = join(sdkRoot, 'dist')
67+
if (!existsSync(distPath)) {
68+
console.log(' ⚠️ SDK dist not found, building...')
69+
execSync('bun run build', { cwd: sdkRoot, stdio: 'inherit' })
70+
}
71+
72+
// Run setup and type tests for each subproject
73+
for (const project of TEST_SUBPROJECTS) {
74+
runSetup(project)
75+
}
76+
77+
console.log('\n🎉 All type tests passed!')
78+
}
79+
80+
main().catch((error) => {
81+
console.error('\n❌ Type testing failed:', error.message)
82+
process.exit(1)
83+
})

sdk/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ export type * from '../../common/src/types/json'
22
export type * from '../../common/src/types/messages/codebuff-message'
33
export type * from '../../common/src/types/messages/data-content'
44
export type * from '../../common/src/types/print-mode'
5-
export type { TextPart, ImagePart } from '../../common/src/types/messages/content-part'
5+
export type {
6+
TextPart,
7+
ImagePart,
8+
} from '../../common/src/types/messages/content-part'
69
export { run, getRetryableErrorCode } from './run'
7-
export type { RunOptions, RetryOptions, MessageContent, TextContent, ImageContent } from './run'
8-
export { buildUserMessageContent } from '@codebuff/agent-runtime/util/messages'
10+
export type {
11+
RunOptions,
12+
RetryOptions,
13+
MessageContent,
14+
TextContent,
15+
ImageContent,
16+
} from './run'
17+
export { buildUserMessageContent } from '../../packages/agent-runtime/src/util/messages'
918
// Agent type exports
1019
export type { AgentDefinition } from '../../common/src/templates/initial-agents-dir/types/agent-definition'
1120
export type { ToolName } from '../../common/src/tools/constants'

0 commit comments

Comments
 (0)