Skip to content

Commit 7e450cf

Browse files
committed
Remove verbose LLM stream logging and add authorization header sanitization to logger
- Update the `Logger` utility to automatically sanitize Axios errors by redacting the `Authorization` header to prevent API key leaks, and remove the `Logger.info` statements in `send-llm-message.ts` that log the full request body, streaming tokens, and complete responses. ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── code-at-cursor-command │ │ │ └── utils │ │ │ └── perform-code-at-cursor.ts │ │ └── generate-commit-message-commands │ │ └── utils │ │ └── generate-commit-message-with-api.ts │ ├── features │ │ └── search-files │ │ └── utils │ │ └── search-files-by-intelligent.ts │ ├── services │ │ ├── model-fetcher.ts │ │ └── prompt-view-api-calls-manager.ts │ ├── utils │ │ └── send-llm-message.ts │ └── views │ └── prompt │ └── backend │ └── message-handlers │ ├── handle-make-api-call.ts │ ├── handle-voice-input.ts │ └── utils │ └── patch-repair-utils.ts └── packages └── shared └── src └── utils └── logger.ts
1 parent 2c404fc commit 7e450cf

2 files changed

Lines changed: 68 additions & 36 deletions

File tree

‎apps/editor/src/utils/send-llm-message.ts‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ export const send_llm_message = async (params: {
148148
const request_url = params.base_url + '/chat/completions'
149149
const request_body: any = { ...params.body, stream: true }
150150

151-
Logger.info({
152-
function_name: 'send_llm_message',
153-
message: 'API Request Body',
154-
data: request_body
155-
})
156-
157151
let buffer = ''
158152
let full_response = ''
159153
let content_for_client = ''
@@ -162,9 +156,6 @@ export const send_llm_message = async (params: {
162156
let processed_think_content_length = 0
163157
let api_thoughts = ''
164158

165-
let last_log_time = Date.now()
166-
let logged_content_length = 0
167-
168159
const process_content = (new_content: string) => {
169160
if (!new_content) return
170161

@@ -335,17 +326,6 @@ export const send_llm_message = async (params: {
335326
}
336327

337328
process_content(new_content)
338-
339-
const current_time = Date.now()
340-
if (current_time - last_log_time >= 1000) {
341-
Logger.info({
342-
function_name: 'send_llm_message',
343-
message: 'Streaming tokens',
344-
data: `\n${full_response.substring(logged_content_length)}`
345-
})
346-
last_log_time = current_time
347-
logged_content_length = full_response.length
348-
}
349329
})
350330

351331
response.data.on('end', () => {
@@ -420,19 +400,6 @@ export const send_llm_message = async (params: {
420400
}
421401
}
422402

423-
Logger.info({
424-
function_name: 'send_llm_message',
425-
message: 'Combined code received (full response):',
426-
data: full_response
427-
})
428-
if (in_think_block || api_thoughts) {
429-
Logger.info({
430-
function_name: 'send_llm_message',
431-
message: 'Combined code received (for client):',
432-
data: content_for_client
433-
})
434-
}
435-
436403
resolve({ response: final_content, thoughts })
437404
})
438405

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
export namespace Logger {
22
const LOG_PREFIX = '[CWC]'
33

4+
const sanitize_data = (data: any) => {
5+
if (!data || typeof data !== 'object') return data
6+
7+
if (data.isAxiosError) {
8+
const sanitized = {
9+
name: data.name,
10+
message: data.message,
11+
stack: data.stack,
12+
...data
13+
}
14+
15+
if (sanitized.config?.headers) {
16+
sanitized.config = {
17+
...sanitized.config,
18+
headers: { ...sanitized.config.headers }
19+
}
20+
for (const key in sanitized.config.headers) {
21+
if (key.toLowerCase() === 'authorization') {
22+
sanitized.config.headers[key] = '[REDACTED]'
23+
}
24+
}
25+
}
26+
27+
if (sanitized.response?.config?.headers) {
28+
sanitized.response = {
29+
...sanitized.response,
30+
config: {
31+
...sanitized.response.config,
32+
headers: { ...sanitized.response.config.headers }
33+
}
34+
}
35+
for (const key in sanitized.response.config.headers) {
36+
if (key.toLowerCase() === 'authorization') {
37+
sanitized.response.config.headers[key] = '[REDACTED]'
38+
}
39+
}
40+
}
41+
42+
return sanitized
43+
}
44+
45+
return data
46+
}
47+
448
export function info(params: {
549
function_name?: string
650
message: string
@@ -9,7 +53,14 @@ export namespace Logger {
953
const function_name = params.function_name
1054
? `[${params.function_name}] `
1155
: ''
12-
console.log(`${LOG_PREFIX}${function_name}${params.message}`, params.data)
56+
if (params.data !== undefined) {
57+
console.log(
58+
`${LOG_PREFIX}${function_name}${params.message}`,
59+
sanitize_data(params.data)
60+
)
61+
} else {
62+
console.log(`${LOG_PREFIX}${function_name}${params.message}`)
63+
}
1364
}
1465

1566
export function warn(params: {
@@ -18,7 +69,14 @@ export namespace Logger {
1869
data?: any
1970
}) {
2071
const prefix = params.function_name ? `[${params.function_name}] ` : ''
21-
console.warn(`${LOG_PREFIX}${prefix}${params.message}`, params.data)
72+
if (params.data !== undefined) {
73+
console.warn(
74+
`${LOG_PREFIX}${prefix}${params.message}`,
75+
sanitize_data(params.data)
76+
)
77+
} else {
78+
console.warn(`${LOG_PREFIX}${prefix}${params.message}`)
79+
}
2280
}
2381

2482
export function error(params: {
@@ -27,6 +85,13 @@ export namespace Logger {
2785
data?: any
2886
}) {
2987
const prefix = params.function_name ? `[${params.function_name}] ` : ''
30-
console.error(`${LOG_PREFIX}${prefix}${params.message}`, params.data)
88+
if (params.data !== undefined) {
89+
console.error(
90+
`${LOG_PREFIX}${prefix}${params.message}`,
91+
sanitize_data(params.data)
92+
)
93+
} else {
94+
console.error(`${LOG_PREFIX}${prefix}${params.message}`)
95+
}
3196
}
3297
}

0 commit comments

Comments
 (0)