fix: clean up code (#5851)

This commit is contained in:
自由的世界人 2025-05-11 00:37:01 +08:00 committed by GitHub
parent 2193a665c6
commit 6ee181ed38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 22 additions and 47 deletions

View File

@ -7,7 +7,6 @@ exports.default = async function notarizing(context) {
} }
if (!process.env.APPLE_ID || !process.env.APPLE_APP_SPECIFIC_PASSWORD || !process.env.APPLE_TEAM_ID) { if (!process.env.APPLE_ID || !process.env.APPLE_APP_SPECIFIC_PASSWORD || !process.env.APPLE_TEAM_ID) {
console.log('Skipping notarization')
return return
} }

View File

@ -56,7 +56,6 @@ class DifyKnowledgeServer {
private config: DifyKnowledgeServerConfig private config: DifyKnowledgeServerConfig
constructor(difyKey: string, args: string[]) { constructor(difyKey: string, args: string[]) {
console.log('DifyKnowledgeServer args', args)
if (args.length === 0) { if (args.length === 0) {
throw new Error('DifyKnowledgeServer requires at least one argument') throw new Error('DifyKnowledgeServer requires at least one argument')
} }
@ -113,8 +112,6 @@ class DifyKnowledgeServer {
const errorDetails = JSON.stringify(parsed.error.format(), null, 2) const errorDetails = JSON.stringify(parsed.error.format(), null, 2)
throw new Error(`无效的参数:\n${errorDetails}`) throw new Error(`无效的参数:\n${errorDetails}`)
} }
console.log('DifyKnowledgeServer search_knowledge parsed', parsed.data)
return await this.performSearchKnowledge( return await this.performSearchKnowledge(
parsed.data.id, parsed.data.id,
parsed.data.query, parsed.data.query,

View File

@ -25,7 +25,6 @@ export function handleProtocolUrl(url: string) {
if (!url) return if (!url) return
// Process the URL that was used to open the app // Process the URL that was used to open the app
// The url will be in the format: cherrystudio://data?param1=value1&param2=value2 // The url will be in the format: cherrystudio://data?param1=value1&param2=value2
console.log('Received URL:', url)
// Parse the URL and extract parameters // Parse the URL and extract parameters
const urlObj = new URL(url) const urlObj = new URL(url)

View File

@ -88,7 +88,6 @@ export function useMessageOperations(topic: Topic) {
console.error('[editMessage] Topic prop is not valid.') console.error('[editMessage] Topic prop is not valid.')
return return
} }
console.log(`[useMessageOperations] Editing message ${messageId} with updates:`, updates)
const messageUpdates: Partial<Message> & Pick<Message, 'id'> = { const messageUpdates: Partial<Message> & Pick<Message, 'id'> = {
id: messageId, id: messageId,
@ -274,12 +273,10 @@ export function useMessageOperations(topic: Topic) {
} }
dispatch(updateOneBlock({ id: blockId, changes })) dispatch(updateOneBlock({ id: blockId, changes }))
await dispatch(updateTranslationBlockThunk(blockId, '', false)) await dispatch(updateTranslationBlockThunk(blockId, '', false))
console.log('[getTranslationUpdater] update existing translation block:', blockId)
} else { } else {
blockId = await dispatch( blockId = await dispatch(
initiateTranslationThunk(messageId, topic.id, targetLanguage, sourceBlockId, sourceLanguage) initiateTranslationThunk(messageId, topic.id, targetLanguage, sourceBlockId, sourceLanguage)
) )
console.log('[getTranslationUpdater] create new translation block:', blockId)
} }
if (!blockId) { if (!blockId) {

View File

@ -88,7 +88,6 @@ const MessageMenubar: FC<Props> = (props) => {
const onCopy = useCallback( const onCopy = useCallback(
(e: React.MouseEvent) => { (e: React.MouseEvent) => {
e.stopPropagation() e.stopPropagation()
console.log('mainTextContent', mainTextContent)
navigator.clipboard.writeText(removeTrailingDoubleSpaces(mainTextContent.trimStart())) navigator.clipboard.writeText(removeTrailingDoubleSpaces(mainTextContent.trimStart()))
window.message.success({ content: t('message.copied'), key: 'copy-message' }) window.message.success({ content: t('message.copied'), key: 'copy-message' })

View File

@ -495,7 +495,7 @@ export default class AnthropicProvider extends BaseProvider {
/** /**
* Translate a message * Translate a message
* @param message - The message * @param content
* @param assistant - The assistant * @param assistant - The assistant
* @param onResponse - The onResponse callback * @param onResponse - The onResponse callback
* @returns The translated message * @returns The translated message
@ -622,8 +622,7 @@ export default class AnthropicProvider extends BaseProvider {
) )
.finally(cleanup) .finally(cleanup)
const responseContent = response.content[0].type === 'text' ? response.content[0].text : '' return response.content[0].type === 'text' ? response.content[0].text : ''
return responseContent
} }
/** /**

View File

@ -620,7 +620,7 @@ export default class GeminiProvider extends BaseProvider {
/** /**
* Translate a message * Translate a message
* @param message - The message * @param content
* @param assistant - The assistant * @param assistant - The assistant
* @param onResponse - The onResponse callback * @param onResponse - The onResponse callback
* @returns The translated message * @returns The translated message
@ -827,7 +827,7 @@ export default class GeminiProvider extends BaseProvider {
/** /**
* Gemini图像响应 * Gemini图像响应
* @param response - Gemini响应 * @param chunk
* @param onChunk - * @param onChunk -
*/ */
private processGeminiImageResponse( private processGeminiImageResponse(
@ -961,7 +961,7 @@ export default class GeminiProvider extends BaseProvider {
if ('toolUseId' in mcpToolResponse && mcpToolResponse.toolUseId) { if ('toolUseId' in mcpToolResponse && mcpToolResponse.toolUseId) {
return mcpToolCallResponseToGeminiMessage(mcpToolResponse, resp, isVisionModel(model)) return mcpToolCallResponseToGeminiMessage(mcpToolResponse, resp, isVisionModel(model))
} else if ('toolCallId' in mcpToolResponse) { } else if ('toolCallId' in mcpToolResponse) {
const toolCallOut = { return {
role: 'user', role: 'user',
parts: [ parts: [
{ {
@ -976,7 +976,6 @@ export default class GeminiProvider extends BaseProvider {
} }
] ]
} satisfies Content } satisfies Content
return toolCallOut
} }
return return
} }

View File

@ -1239,12 +1239,11 @@ export default class OpenAIProvider extends BaseOpenAiProvider {
if ('toolUseId' in mcpToolResponse && mcpToolResponse.toolUseId) { if ('toolUseId' in mcpToolResponse && mcpToolResponse.toolUseId) {
return mcpToolCallResponseToOpenAIMessage(mcpToolResponse, resp, isVisionModel(model)) return mcpToolCallResponseToOpenAIMessage(mcpToolResponse, resp, isVisionModel(model))
} else if ('toolCallId' in mcpToolResponse && mcpToolResponse.toolCallId) { } else if ('toolCallId' in mcpToolResponse && mcpToolResponse.toolCallId) {
const toolCallOut: OpenAI.Responses.ResponseInputItem = { return {
type: 'function_call_output', type: 'function_call_output',
call_id: mcpToolResponse.toolCallId, call_id: mcpToolResponse.toolCallId,
output: JSON.stringify(resp.content) output: JSON.stringify(resp.content)
} }
return toolCallOut
} }
return return
} }

View File

@ -17,8 +17,6 @@ export default class WebSearchEngineProvider {
httpOptions?: RequestInit httpOptions?: RequestInit
): Promise<WebSearchProviderResponse> { ): Promise<WebSearchProviderResponse> {
const result = await this.sdk.search(query, websearch, httpOptions) const result = await this.sdk.search(query, websearch, httpOptions)
const filteredResult = await filterResultWithBlacklist(result, websearch) return await filterResultWithBlacklist(result, websearch)
return filteredResult
} }
} }

View File

@ -4,11 +4,7 @@ export function formatApiHost(host: string) {
return true return true
} }
if (host.endsWith('volces.com/api/v3')) { return host.endsWith('volces.com/api/v3')
return true
}
return false
} }
return forceUseOriginalHost() ? host : `${host}/v1/` return forceUseOriginalHost() ? host : `${host}/v1/`

View File

@ -190,12 +190,10 @@ export async function parseSubscribeContent(url: string): Promise<string[]> {
const lines = content.split('\n') const lines = content.split('\n')
// 过滤出有效的匹配模式 // 过滤出有效的匹配模式
const patterns = lines return lines
.filter((line) => line.trim() !== '' && !line.startsWith('#')) .filter((line) => line.trim() !== '' && !line.startsWith('#'))
.map((line) => line.trim()) .map((line) => line.trim())
.filter((pattern) => parseMatchPattern(pattern) !== null) .filter((pattern) => parseMatchPattern(pattern) !== null)
return patterns
} catch (error) { } catch (error) {
console.error('Error parsing subscribe content:', error) console.error('Error parsing subscribe content:', error)
throw error throw error
@ -264,11 +262,7 @@ export async function filterResultWithBlacklist(
// 检查URL是否匹配任何匹配模式规则 // 检查URL是否匹配任何匹配模式规则
const matchesPattern = patternMap.get(result.url).length > 0 const matchesPattern = patternMap.get(result.url).length > 0
if (matchesPattern) { return !matchesPattern
return false
}
return true
} catch (error) { } catch (error) {
console.error('Error processing URL:', result.url, error) console.error('Error processing URL:', result.url, error)
return true // 如果URL解析失败保留该结果 return true // 如果URL解析失败保留该结果

View File

@ -13,8 +13,12 @@ import type {
ToolMessageBlock, ToolMessageBlock,
TranslationMessageBlock TranslationMessageBlock
} from '@renderer/types/newMessage' } from '@renderer/types/newMessage'
import { AssistantMessageStatus, UserMessageStatus } from '@renderer/types/newMessage' import {
import { MessageBlockStatus, MessageBlockType } from '@renderer/types/newMessage' AssistantMessageStatus,
MessageBlockStatus,
MessageBlockType,
UserMessageStatus
} from '@renderer/types/newMessage'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>> type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
@ -184,7 +188,7 @@ export function createFileBlock(
/** /**
* Creates an Error Message Block. * Creates an Error Message Block.
* @param messageId - The ID of the parent message. * @param messageId - The ID of the parent message.
* @param error - The error object/details. * @param errorData
* @param overrides - Optional properties to override the defaults. * @param overrides - Optional properties to override the defaults.
* @returns An ErrorMessageBlock object. * @returns An ErrorMessageBlock object.
*/ */
@ -273,7 +277,6 @@ export function createCitationBlock(
* @param role - The role of the message sender ('user' or 'assistant'). * @param role - The role of the message sender ('user' or 'assistant').
* @param topicId - The ID of the topic this message belongs to. * @param topicId - The ID of the topic this message belongs to.
* @param assistantId - The ID of the assistant (relevant for assistant messages). * @param assistantId - The ID of the assistant (relevant for assistant messages).
* @param type - The type of the message ('text', '@', 'clear').
* @param overrides - Optional properties to override the defaults. Initial blocks can be passed here. * @param overrides - Optional properties to override the defaults. Initial blocks can be passed here.
* @returns A Message object. * @returns A Message object.
*/ */
@ -311,8 +314,8 @@ export function createMessage(
/** /**
* Creates a new Assistant Message object (stub) based on the LATEST definition. * Creates a new Assistant Message object (stub) based on the LATEST definition.
* Contains only metadata, no content or block data initially. * Contains only metadata, no content or block data initially.
* @param assistant - The assistant configuration. * @param assistantId
* @param topic - The topic this message belongs to. * @param topicId
* @param overrides - Optional properties to override the defaults (e.g., model, askId). * @param overrides - Optional properties to override the defaults (e.g., model, askId).
* @returns An Assistant Message stub object. * @returns An Assistant Message stub object.
*/ */
@ -395,7 +398,7 @@ export const resetAssistantMessage = (
} }
// Create the base reset message // Create the base reset message
const resetMsg: Message = { return {
// --- Retain Core Identifiers --- // --- Retain Core Identifiers ---
id: originalMessage.id, // Keep the same message ID id: originalMessage.id, // Keep the same message ID
topicId: originalMessage.topicId, topicId: originalMessage.topicId,
@ -420,8 +423,6 @@ export const resetAssistantMessage = (
// --- Apply Overrides --- // --- Apply Overrides ---
...updates // Apply any specific updates passed in (e.g., a different status) ...updates // Apply any specific updates passed in (e.g., a different status)
} }
return resetMsg
} }
// 需要一个重置助手消息 // 需要一个重置助手消息

View File

@ -135,10 +135,7 @@ export function filterUsefulMessages(messages: Message[]): Message[] {
// Filter adjacent user messages, keeping only the last one // Filter adjacent user messages, keeping only the last one
_messages = _messages.filter((message, index, origin) => { _messages = _messages.filter((message, index, origin) => {
if (message.role === 'user' && index + 1 < origin.length && origin[index + 1].role === 'user') { return !(message.role === 'user' && index + 1 < origin.length && origin[index + 1].role === 'user')
return false
}
return true
}) })
return _messages return _messages

View File

@ -6,6 +6,7 @@ const requestQueues: { [topicId: string]: PQueue } = {}
/** /**
* Get or create a queue for a specific topic * Get or create a queue for a specific topic
* @param topicId The ID of the topic * @param topicId The ID of the topic
* @param options
* @returns A PQueue instance for the topic * @returns A PQueue instance for the topic
*/ */
export const getTopicQueue = (topicId: string, options = {}): PQueue => { export const getTopicQueue = (topicId: string, options = {}): PQueue => {