Skip to content

Commit 7a2dfca

Browse files
author
29486
committed
fix: 根据代码审查意见修复两处问题
- qwen-ai.ts: 将 auto_search 恢复为 false(默认禁用联网搜索), 避免所有普通对话请求无条件触发网络搜索,导致响应变慢 和结果非预期包含联网内容。如需启用,请在模型名加 -search 后缀或通过 web_search 参数显式指定。 - manager.ts: 登录成功后的日志改为只打印凭据字段名 (Object.keys),不再将 Cookie 等敏感凭据明文输出到日志, 防止可复用的会话 Cookie 泄露到日志文件。
1 parent 3edcad2 commit 7a2dfca

2 files changed

Lines changed: 41 additions & 41 deletions

File tree

src/main/oauth/manager.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ export class OAuthManager extends EventEmitter {
5252
*/
5353
private getAdapter(providerId: string, providerType: ProviderType): BaseOAuthAdapter {
5454
const key = `${providerId}_${providerType}`
55-
55+
5656
if (!this.adapters.has(key)) {
5757
const adapter = createAdapter(providerType, {
5858
providerId,
5959
providerType,
6060
authMethods: [],
6161
callbackPort: DEFAULT_CALLBACK_PORT,
6262
})
63-
63+
6464
if (this.mainWindow) {
6565
adapter.setMainWindow(this.mainWindow)
6666
}
67-
67+
6868
adapter.setProgressCallback((event) => {
6969
this.emit('progress', event)
7070
this.sendProgressToRenderer(event)
7171
})
72-
72+
7373
this.adapters.set(key, adapter)
7474
}
75-
75+
7676
return this.adapters.get(key)!
7777
}
7878

@@ -100,7 +100,7 @@ export class OAuthManager extends EventEmitter {
100100

101101
return new Promise((resolve, reject) => {
102102
const adapter = this.getAdapter(options.providerId, options.providerType)
103-
103+
104104
const timeout = setTimeout(() => {
105105
this.cancelLogin()
106106
const result: OAuthResult = {
@@ -146,11 +146,11 @@ export class OAuthManager extends EventEmitter {
146146
mimoPhToken?: string
147147
): Promise<OAuthResult> {
148148
const adapter = this.getAdapter(providerId, providerType)
149-
149+
150150
if ('loginWithToken' in adapter && typeof (adapter as any).loginWithToken === 'function') {
151151
return await (adapter as any).loginWithToken(providerId, token, realUserID, mimoUserId, mimoPhToken)
152152
}
153-
153+
154154
// For Mimo, validate with all three tokens
155155
if (providerType === 'mimo') {
156156
if (!mimoUserId || !mimoPhToken) {
@@ -166,7 +166,7 @@ export class OAuthManager extends EventEmitter {
166166
user_id: mimoUserId,
167167
ph_token: mimoPhToken,
168168
})
169-
169+
170170
if (!validation.valid) {
171171
return {
172172
success: false,
@@ -175,7 +175,7 @@ export class OAuthManager extends EventEmitter {
175175
error: validation.error || 'Token validation failed',
176176
}
177177
}
178-
178+
179179
return {
180180
success: true,
181181
providerId,
@@ -188,9 +188,9 @@ export class OAuthManager extends EventEmitter {
188188
accountInfo: validation.accountInfo,
189189
}
190190
}
191-
191+
192192
const validation = await adapter.validateToken({ token })
193-
193+
194194
if (!validation.valid) {
195195
return {
196196
success: false,
@@ -199,7 +199,7 @@ export class OAuthManager extends EventEmitter {
199199
error: validation.error || 'Token validation failed',
200200
}
201201
}
202-
202+
203203
return {
204204
success: true,
205205
providerId,
@@ -345,13 +345,13 @@ export class OAuthManager extends EventEmitter {
345345

346346
// Store the token
347347
collectedTokens[event.key] = event.value
348-
348+
349349
// Store all cookies if provided (needed for Cloudflare-protected requests)
350350
if (event.allCookies) {
351351
collectedTokens['cookies'] = event.allCookies as any
352352
console.log('[OAuthManager] Stored all cookies:', Object.keys(event.allCookies).length, 'cookies')
353353
}
354-
354+
355355
console.log('[OAuthManager] Collected tokens:', Object.keys(collectedTokens))
356356

357357
// For MiniMax, we need both token and realUserID before validating
@@ -401,7 +401,7 @@ export class OAuthManager extends EventEmitter {
401401
hasUserId: !!hasUserId,
402402
hasPhToken: !!hasPhToken,
403403
})
404-
404+
405405
// Clear any existing timeout
406406
if (validationTimeout) {
407407
clearTimeout(validationTimeout)
@@ -555,7 +555,7 @@ export class OAuthManager extends EventEmitter {
555555
console.log('[OAuthManager] Validation result:', validation)
556556

557557
if (validation.valid) {
558-
console.log('[OAuthManager] Token is valid, completing login with credentials:', JSON.stringify(finalCredentials, null, 2))
558+
console.log('[OAuthManager] Token is valid, completing login with credentials keys:', Object.keys(finalCredentials).join(', '))
559559
inAppLoginManager.completeWithSuccess(finalCredentials)
560560
} else {
561561
console.log('[OAuthManager] Token validation failed:', validation.error)

src/main/proxy/adapters/qwen-ai.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,31 @@ export class QwenAiAdapter {
148148
mapModel(openaiModel: string): string {
149149
let model = openaiModel
150150
let forceThinking: boolean | undefined
151-
151+
152152
if (model.endsWith('-thinking')) {
153153
forceThinking = true
154154
model = model.slice(0, -9)
155155
} else if (model.endsWith('-fast')) {
156156
forceThinking = false
157157
model = model.slice(0, -5)
158158
}
159-
160-
;(this as any)._forceThinking = forceThinking
161-
159+
160+
; (this as any)._forceThinking = forceThinking
161+
162162
const lowerModel = model.toLowerCase()
163-
163+
164164
if (MODEL_ALIASES[lowerModel]) {
165165
return MODEL_ALIASES[lowerModel]
166166
}
167-
167+
168168
if (this.provider.modelMappings) {
169169
for (const [key, value] of Object.entries(this.provider.modelMappings)) {
170170
if (key.toLowerCase() === lowerModel) {
171171
return value
172172
}
173173
}
174174
}
175-
175+
176176
return model
177177
}
178178

@@ -236,7 +236,7 @@ export class QwenAiAdapter {
236236

237237
try {
238238
console.log('[QwenAI] Deleting all chats for account')
239-
239+
240240
const response = await this.axiosInstance.delete(url, {
241241
headers: this.getHeaders(),
242242
})
@@ -265,7 +265,7 @@ export class QwenAiAdapter {
265265
}
266266

267267
const modelId = this.mapModel(request.model)
268-
268+
269269
// Get forced thinking mode setting from originalModel (preserves user's intent before mapping)
270270
// If originalModel exists, use it for thinking detection; otherwise fall back to request.model
271271
const modelForThinking = request.originalModel || request.model
@@ -289,11 +289,11 @@ export class QwenAiAdapter {
289289
console.log('[QwenAI] Created new chat:', chatId)
290290

291291
const messages = request.messages
292-
292+
293293
// Extract system message and user message
294294
let systemContent = ''
295295
let userContent = ''
296-
296+
297297
// Single-turn mode: extract all messages
298298
for (const msg of messages) {
299299
if (msg.role === 'system') {
@@ -302,7 +302,7 @@ export class QwenAiAdapter {
302302
userContent = msg.content
303303
}
304304
}
305-
305+
306306
// If system prompt exists, prepend it to user content
307307
if (systemContent) {
308308
userContent = `${systemContent}\n\nUser: ${userContent}`
@@ -317,17 +317,17 @@ export class QwenAiAdapter {
317317
// 1. Model name suffix: -thinking (force thinking), -fast (force fast mode)
318318
// 2. enable_thinking parameter for explicit control
319319
// 3. If neither is specified, thinking mode is disabled by default (fast mode)
320-
const shouldEnableThinking = forceThinking !== undefined
321-
? forceThinking
320+
const shouldEnableThinking = forceThinking !== undefined
321+
? forceThinking
322322
: request.enable_thinking === true
323-
323+
324324
const featureConfig: Record<string, any> = {
325325
thinking_enabled: shouldEnableThinking,
326326
output_schema: 'phase',
327327
research_mode: 'normal',
328328
auto_thinking: false,
329329
thinking_mode: shouldEnableThinking ? 'Thinking' : 'Fast',
330-
auto_search: true,
330+
auto_search: false, // Default to disable auto search
331331
}
332332

333333
if (shouldEnableThinking) {
@@ -419,11 +419,11 @@ export class QwenAiStreamHandler {
419419

420420
private sendToolCalls(transStream: PassThrough): void {
421421
if (this.toolCallsSent) return
422-
422+
423423
const toolCalls = parseToolUse(this.content)
424424
if (toolCalls && toolCalls.length > 0) {
425425
this.toolCallsSent = true
426-
426+
427427
// Send tool_calls delta
428428
for (let i = 0; i < toolCalls.length; i++) {
429429
const tc = toolCalls[i]
@@ -451,7 +451,7 @@ export class QwenAiStreamHandler {
451451
})}\n\n`
452452
)
453453
}
454-
454+
455455
// Send finish with tool_calls
456456
transStream.write(
457457
`data: ${JSON.stringify({
@@ -499,7 +499,7 @@ export class QwenAiStreamHandler {
499499
onEvent: (event: any) => {
500500
try {
501501
console.log('[QwenAI] Parsed event:', event.event, 'data:', event.data?.substring(0, 200))
502-
502+
503503
if (event.data === '[DONE]') {
504504
console.log('[QwenAI] Received [DONE] signal')
505505
return
@@ -592,10 +592,10 @@ export class QwenAiStreamHandler {
592592
sendInitialChunk()
593593
}
594594
console.log('[QwenAI] Entering answer branch, content:', content)
595-
595+
596596
// Accumulate content for tool call detection
597597
this.content += content
598-
598+
599599
if (content) {
600600
console.log('[QwenAI] Sending content chunk:', content)
601601
const chunk = {
@@ -614,7 +614,7 @@ export class QwenAiStreamHandler {
614614
}
615615
// Accumulate content for tool call detection
616616
this.content += content
617-
617+
618618
const chunk = {
619619
id: this.responseId || this.chatId,
620620
model: this.model,
@@ -632,7 +632,7 @@ export class QwenAiStreamHandler {
632632
this.sendToolCalls(transStream)
633633
return
634634
}
635-
635+
636636
const finishReason = delta.finish_reason || 'stop'
637637
const finalChunk = {
638638
id: this.responseId || this.chatId,

0 commit comments

Comments
 (0)