mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
refactor(aiCore): consolidate StreamTextParams type imports and enhance type definitions
- Moved StreamTextParams type definition to a new file for better organization. - Updated imports across multiple files to reference the new location. - Adjusted related type definitions in ApiService and ConversationService for consistency.
This commit is contained in:
parent
6b92e676dc
commit
837e929731
@ -15,6 +15,7 @@ import { getEnableDeveloperMode } from '@renderer/hooks/useSettings'
|
||||
import { addSpan, endSpan } from '@renderer/services/SpanManagerService'
|
||||
import { StartSpanParams } from '@renderer/trace/types/ModelSpanEntity'
|
||||
import type { Assistant, GenerateImageParams, Model, Provider } from '@renderer/types'
|
||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||
import { ChunkType } from '@renderer/types/chunk'
|
||||
|
||||
import AiSdkToChunkAdapter from './chunk/AiSdkToChunkAdapter'
|
||||
@ -28,7 +29,6 @@ import {
|
||||
prepareSpecialProviderConfig,
|
||||
providerToAiSdkConfig
|
||||
} from './provider/providerConfig'
|
||||
import type { StreamTextParams } from './types'
|
||||
|
||||
const logger = loggerService.withContext('ModernAiProvider')
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ import {
|
||||
import { getAssistantSettings, getDefaultModel, getProviderByModel } from '@renderer/services/AssistantService'
|
||||
import type { Assistant, MCPTool, Message, Model, Provider } from '@renderer/types'
|
||||
import { FileTypes } from '@renderer/types'
|
||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||
import { FileMessageBlock, ImageMessageBlock, ThinkingMessageBlock } from '@renderer/types/newMessage'
|
||||
// import { getWebSearchTools } from './utils/websearch'
|
||||
import {
|
||||
@ -33,7 +34,6 @@ import type { AssistantModelMessage, FilePart, ImagePart, ModelMessage, TextPart
|
||||
import { stepCountIs } from 'ai'
|
||||
|
||||
import { getAiSdkProviderId } from './provider/factory'
|
||||
import type { StreamTextParams } from './types'
|
||||
// import { webSearchTool } from './tools/WebSearchTool'
|
||||
// import { jsonSchemaToZod } from 'json-schema-to-zod'
|
||||
import { setupToolsConfig } from './utils/mcp'
|
||||
|
||||
@ -250,7 +250,7 @@ export const SYSTEM_PROVIDERS_CONFIG: Record<SystemProviderId, SystemProvider> =
|
||||
name: 'Anthropic',
|
||||
type: 'anthropic',
|
||||
apiKey: '',
|
||||
apiHost: 'https://api.anthropic.com/',
|
||||
apiHost: 'https://api.anthropic.com',
|
||||
models: SYSTEM_MODELS.anthropic,
|
||||
isSystem: true,
|
||||
enabled: false
|
||||
|
||||
@ -6,12 +6,13 @@ import AiProvider from '@renderer/aiCore'
|
||||
import { CompletionsParams } from '@renderer/aiCore/legacy/middleware/schemas'
|
||||
import { AiSdkMiddlewareConfig } from '@renderer/aiCore/middleware/AiSdkMiddlewareBuilder'
|
||||
import { buildStreamTextParams } from '@renderer/aiCore/transformParameters'
|
||||
import type { StreamTextParams } from '@renderer/aiCore/types'
|
||||
import { isDedicatedImageGenerationModel, isEmbeddingModel } from '@renderer/config/models'
|
||||
import { getStoreSetting } from '@renderer/hooks/useSettings'
|
||||
import i18n from '@renderer/i18n'
|
||||
import store from '@renderer/store'
|
||||
import type { FetchChatCompletionParams } from '@renderer/types'
|
||||
import { Assistant, MCPServer, MCPTool, Model, Provider } from '@renderer/types'
|
||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||
import { type Chunk, ChunkType } from '@renderer/types/chunk'
|
||||
import { Message } from '@renderer/types/newMessage'
|
||||
import { SdkModel } from '@renderer/types/sdk'
|
||||
@ -54,7 +55,7 @@ export async function fetchMcpTools(assistant: Assistant) {
|
||||
|
||||
if (enabledMCPs && enabledMCPs.length > 0) {
|
||||
try {
|
||||
const toolPromises = enabledMCPs.map<Promise<MCPTool[]>>(async (mcpServer: MCPServer) => {
|
||||
const toolPromises = enabledMCPs.map(async (mcpServer: MCPServer) => {
|
||||
try {
|
||||
const tools = await window.api.mcp.listTools(mcpServer)
|
||||
return tools.filter((tool: any) => !mcpServer.disabledTools?.includes(tool.name))
|
||||
@ -75,33 +76,6 @@ export async function fetchMcpTools(assistant: Assistant) {
|
||||
return mcpTools
|
||||
}
|
||||
|
||||
export type FetchChatCompletionOptions = {
|
||||
signal?: AbortSignal
|
||||
timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}
|
||||
|
||||
type BaseParams = {
|
||||
assistant: Assistant
|
||||
options?: FetchChatCompletionOptions
|
||||
onChunkReceived: (chunk: Chunk) => void
|
||||
topicId?: string // 添加 topicId 参数
|
||||
}
|
||||
|
||||
type MessagesParams = BaseParams & {
|
||||
messages: StreamTextParams['messages']
|
||||
prompt?: never
|
||||
}
|
||||
|
||||
type PromptParams = BaseParams & {
|
||||
messages?: never
|
||||
// prompt: StreamTextParams['prompt']
|
||||
// see https://github.com/vercel/ai/issues/8363
|
||||
prompt: string
|
||||
}
|
||||
|
||||
export type FetchChatCompletionParams = MessagesParams | PromptParams
|
||||
|
||||
export async function fetchChatCompletion({
|
||||
messages,
|
||||
prompt,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { convertMessagesToSdkMessages } from '@renderer/aiCore/transformParameters'
|
||||
import type { StreamTextParams } from '@renderer/aiCore/types'
|
||||
import { Assistant, Message } from '@renderer/types'
|
||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||
import { filterAdjacentUserMessaegs, filterLastAssistantMessage } from '@renderer/utils/messageUtils/filters'
|
||||
import { isEmpty, takeRight } from 'lodash'
|
||||
|
||||
|
||||
@ -6,6 +6,8 @@ import * as z from 'zod/v4'
|
||||
|
||||
export * from './file'
|
||||
|
||||
import type { StreamTextParams } from './aiCoreTypes'
|
||||
import type { Chunk } from './chunk'
|
||||
import type { FileMetadata } from './file'
|
||||
import type { Message } from './newMessage'
|
||||
import type { BaseTool, MCPTool } from './tool'
|
||||
@ -1254,3 +1256,30 @@ export type HexColor = string
|
||||
export const isHexColor = (value: string): value is HexColor => {
|
||||
return /^#([0-9A-F]{3}){1,2}$/i.test(value)
|
||||
}
|
||||
|
||||
export type FetchChatCompletionOptions = {
|
||||
signal?: AbortSignal
|
||||
timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}
|
||||
|
||||
type BaseParams = {
|
||||
assistant: Assistant
|
||||
options?: FetchChatCompletionOptions
|
||||
onChunkReceived: (chunk: Chunk) => void
|
||||
topicId?: string // 添加 topicId 参数
|
||||
}
|
||||
|
||||
type MessagesParams = BaseParams & {
|
||||
messages: StreamTextParams['messages']
|
||||
prompt?: never
|
||||
}
|
||||
|
||||
type PromptParams = BaseParams & {
|
||||
messages?: never
|
||||
// prompt: StreamTextParams['prompt']
|
||||
// see https://github.com/vercel/ai/issues/8363
|
||||
prompt: string
|
||||
}
|
||||
|
||||
export type FetchChatCompletionParams = MessagesParams | PromptParams
|
||||
|
||||
Loading…
Reference in New Issue
Block a user