MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / getCodebuffClient

Function getCodebuffClient

cli/src/utils/codebuff-client.ts:47–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45}
46
47export async function getCodebuffClient(): Promise<CodebuffClient | null> {
48 if (!clientInstance) {
49 const { token: apiKey } = getAuthTokenDetails()
50
51 if (!apiKey) {
52 logger.warn(
53 {},
54 `No authentication token found. Please run the login flow or set ${API_KEY_ENV_VAR}.`,
55 )
56 return null
57 }
58
59 const projectRoot = getProjectRoot()
60
61 // Set up ripgrep path for SDK to use
62 const env = getCliEnv()
63 if (env.CODEBUFF_IS_BINARY) {
64 try {
65 const rgPath = await getRgPath()
66 // Note: We still set process.env here because SDK reads from it
67 getSystemProcessEnv().CODEBUFF_RG_PATH = rgPath
68 } catch (error) {
69 logger.error(error, 'Failed to set up ripgrep binary for SDK')
70 }
71 }
72
73 try {
74 const agentDefinitions = loadAgentDefinitions()
75 clientInstance = new CodebuffClient({
76 apiKey,
77 cwd: projectRoot,
78 agentDefinitions,
79 logger,
80 overrideTools: {
81 ask_user: async (input: ClientToolCall<'ask_user'>['input']) => {
82 const askUserResponse = await AskUserBridge.request(
83 'cli-override',
84 input.questions,
85 )
86 const response = askUserResponse as {
87 answers?: Array<{ questionIndex: number; selectedOption: string }>
88 skipped?: boolean
89 }
90 return [
91 {
92 type: 'json',
93 value: removeUndefinedValues(response),
94 },
95 ]
96 },
97 },
98 })
99 } catch (error) {
100 logger.error(error, 'Failed to initialize CodebuffClient')
101 return null
102 }
103 }
104

Callers 2

checkConnectionFunction · 0.90
useSendMessageFunction · 0.90

Calls 8

getAuthTokenDetailsFunction · 0.90
getProjectRootFunction · 0.90
getCliEnvFunction · 0.90
getRgPathFunction · 0.90
getSystemProcessEnvFunction · 0.90
loadAgentDefinitionsFunction · 0.90
removeUndefinedValuesFunction · 0.85
requestMethod · 0.80

Tested by

no test coverage detected