Skip to content

Commit c348b51

Browse files
committed
only allow api key through env
1 parent df20249 commit c348b51

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

sdk/src/client.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ import type {
1313
} from './types'
1414

1515
export class CodebuffClient {
16-
private authToken: string
17-
1816
public cwd: string
1917

20-
constructor({ apiKey, cwd }: CodebuffClientOptions) {
18+
constructor({ cwd }: CodebuffClientOptions) {
2119
// TODO: download binary automatically
2220
if (execFileSync('which', [CODEBUFF_BINARY]).toString().trim() === '') {
2321
throw new Error(
2422
'Codebuff binary not found. Please run "npm i -g codebuff"',
2523
)
2624
}
25+
if (!process.env[API_KEY_ENV_VAR]) {
26+
throw new Error(
27+
`Codebuff API key not found. Please set the ${API_KEY_ENV_VAR} environment variable.`,
28+
)
29+
}
2730

28-
this.authToken =
29-
apiKey.type === 'string'
30-
? apiKey.value
31-
: process.env[API_KEY_ENV_VAR] ?? ''
3231
this.cwd = cwd
3332
}
3433

@@ -51,7 +50,6 @@ export class CodebuffClient {
5150

5251
await processStream({
5352
codebuffArgs: args,
54-
authToken: this.authToken,
5553
handleEvent,
5654
})
5755

@@ -82,7 +80,6 @@ export class CodebuffClient {
8280

8381
await processStream({
8482
codebuffArgs: args,
85-
authToken: this.authToken,
8683
handleEvent,
8784
})
8885

sdk/src/process-stream.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
66

77
export function processStream({
88
codebuffArgs,
9-
authToken,
109
handleEvent,
1110
}: {
1211
codebuffArgs: string[]
13-
authToken?: string
1412
handleEvent: (event: PrintModeEvent) => void
1513
}): Promise<void> {
1614
let buffer = ''
@@ -29,9 +27,6 @@ export function processStream({
2927
}
3028

3129
const env = { ...process.env }
32-
if (authToken) {
33-
env.CODEBUFF_API_KEY = authToken
34-
}
3530
const child = spawn(CODEBUFF_BINARY, codebuffArgs, {
3631
stdio: 'pipe',
3732
env,

sdk/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
22
import type { AgentTemplateType } from '@codebuff/common/types/session-state'
33

44
export type CodebuffClientOptions = {
5-
apiKey: { type: 'string'; value: string } | { type: 'env' }
65
cwd: string
76
}
87

0 commit comments

Comments
 (0)