Skip to content

Commit ecc9923

Browse files
Merge remote-tracking branch 'origin/main' into v2
2 parents e469016 + 6afaf62 commit ecc9923

File tree

39 files changed

+422
-184
lines changed

39 files changed

+422
-184
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"@aws-sdk/client-bedrock-runtime": "^3.840.0",
111111
"@aws-sdk/client-s3": "^3.840.0",
112112
"@biomejs/biome": "2.2.4",
113-
"@cherrystudio/ai-core": "workspace:^1.0.0-alpha.16",
113+
"@cherrystudio/ai-core": "workspace:^1.0.0-alpha.17",
114114
"@cherrystudio/embedjs": "^0.1.31",
115115
"@cherrystudio/embedjs-libsql": "^0.1.31",
116116
"@cherrystudio/embedjs-loader-csv": "^0.1.31",
@@ -338,7 +338,7 @@
338338
"tsx": "^4.20.3",
339339
"turndown-plugin-gfm": "^1.0.2",
340340
"tw-animate-css": "^1.3.8",
341-
"typescript": "^5.8.2",
341+
"typescript": "~5.8.2",
342342
"undici": "6.21.2",
343343
"unified": "^11.0.5",
344344
"uuid": "^10.0.0",

packages/aiCore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cherrystudio/ai-core",
3-
"version": "1.0.0-alpha.16",
3+
"version": "1.0.0-alpha.17",
44
"description": "Cherry Studio AI Core - Unified AI Provider Interface Based on Vercel AI SDK",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

packages/aiCore/src/core/options/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function createGoogleOptions(options: ExtractProviderOptions<'google'>) {
5959
/**
6060
* 创建OpenRouter供应商选项的便捷函数
6161
*/
62-
export function createOpenRouterOptions(options: ExtractProviderOptions<'openrouter'>) {
62+
export function createOpenRouterOptions(options: ExtractProviderOptions<'openrouter'> | Record<string, any>) {
6363
return createProviderOptions('openrouter', options)
6464
}
6565

packages/aiCore/src/core/options/openrouter.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/aiCore/src/core/options/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { type AnthropicProviderOptions } from '@ai-sdk/anthropic'
22
import { type GoogleGenerativeAIProviderOptions } from '@ai-sdk/google'
33
import { type OpenAIResponsesProviderOptions } from '@ai-sdk/openai'
44
import { type SharedV2ProviderMetadata } from '@ai-sdk/provider'
5-
6-
import { type OpenRouterProviderOptions } from './openrouter'
7-
import { type XaiProviderOptions } from './xai'
5+
import { type XaiProviderOptions } from '@ai-sdk/xai'
6+
import { type OpenRouterProviderOptions } from '@openrouter/ai-sdk-provider'
87

98
export type ProviderOptions<T extends keyof SharedV2ProviderMetadata> = SharedV2ProviderMetadata[T]
109

packages/aiCore/src/core/options/xai.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

packages/aiCore/src/core/plugins/built-in/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ export const BUILT_IN_PLUGIN_PREFIX = 'built-in:'
77
export { googleToolsPlugin } from './googleToolsPlugin'
88
export { createLoggingPlugin } from './logging'
99
export { createPromptToolUsePlugin } from './toolUsePlugin/promptToolUsePlugin'
10-
export type { PromptToolUseConfig, ToolUseRequestContext, ToolUseResult } from './toolUsePlugin/type'
11-
export { webSearchPlugin } from './webSearchPlugin'
10+
export type {
11+
PromptToolUseConfig,
12+
ToolUseRequestContext,
13+
ToolUseResult
14+
} from './toolUsePlugin/type'
15+
export { webSearchPlugin, type WebSearchPluginConfig } from './webSearchPlugin'

packages/aiCore/src/core/plugins/built-in/webSearchPlugin/helper.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import type { google } from '@ai-sdk/google'
33
import type { openai } from '@ai-sdk/openai'
44

55
import type { ProviderOptionsMap } from '../../../options/types'
6+
import type { OpenRouterSearchConfig } from './openrouter'
67

78
/**
89
* 从 AI SDK 的工具函数中提取参数类型,以确保类型安全。
910
*/
10-
type OpenAISearchConfig = Parameters<typeof openai.tools.webSearchPreview>[0]
11-
type AnthropicSearchConfig = Parameters<typeof anthropic.tools.webSearch_20250305>[0]
12-
type GoogleSearchConfig = Parameters<typeof google.tools.googleSearch>[0]
11+
export type OpenAISearchConfig = NonNullable<Parameters<typeof openai.tools.webSearch>[0]>
12+
export type OpenAISearchPreviewConfig = NonNullable<Parameters<typeof openai.tools.webSearchPreview>[0]>
13+
export type AnthropicSearchConfig = NonNullable<Parameters<typeof anthropic.tools.webSearch_20250305>[0]>
14+
export type GoogleSearchConfig = NonNullable<Parameters<typeof google.tools.googleSearch>[0]>
15+
export type XAISearchConfig = NonNullable<ProviderOptionsMap['xai']['searchParameters']>
1316

1417
/**
1518
* 插件初始化时接收的完整配置对象
@@ -18,10 +21,12 @@ type GoogleSearchConfig = Parameters<typeof google.tools.googleSearch>[0]
1821
*/
1922
export interface WebSearchPluginConfig {
2023
openai?: OpenAISearchConfig
24+
'openai-chat'?: OpenAISearchPreviewConfig
2125
anthropic?: AnthropicSearchConfig
2226
xai?: ProviderOptionsMap['xai']['searchParameters']
2327
google?: GoogleSearchConfig
2428
'google-vertex'?: GoogleSearchConfig
29+
openrouter?: OpenRouterSearchConfig
2530
}
2631

2732
/**
@@ -31,6 +36,7 @@ export const DEFAULT_WEB_SEARCH_CONFIG: WebSearchPluginConfig = {
3136
google: {},
3237
'google-vertex': {},
3338
openai: {},
39+
'openai-chat': {},
3440
xai: {
3541
mode: 'on',
3642
returnCitations: true,
@@ -39,6 +45,14 @@ export const DEFAULT_WEB_SEARCH_CONFIG: WebSearchPluginConfig = {
3945
},
4046
anthropic: {
4147
maxUses: 5
48+
},
49+
openrouter: {
50+
plugins: [
51+
{
52+
id: 'web',
53+
max_results: 5
54+
}
55+
]
4256
}
4357
}
4458

packages/aiCore/src/core/plugins/built-in/webSearchPlugin/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { anthropic } from '@ai-sdk/anthropic'
66
import { google } from '@ai-sdk/google'
77
import { openai } from '@ai-sdk/openai'
88

9-
import { createXaiOptions, mergeProviderOptions } from '../../../options'
9+
import { createOpenRouterOptions, createXaiOptions, mergeProviderOptions } from '../../../options'
1010
import { definePlugin } from '../../'
1111
import type { AiRequestContext } from '../../types'
1212
import type { WebSearchPluginConfig } from './helper'
@@ -32,6 +32,13 @@ export const webSearchPlugin = (config: WebSearchPluginConfig = DEFAULT_WEB_SEAR
3232
}
3333
break
3434
}
35+
case 'openai-chat': {
36+
if (config['openai-chat']) {
37+
if (!params.tools) params.tools = {}
38+
params.tools.web_search_preview = openai.tools.webSearchPreview(config['openai-chat'])
39+
}
40+
break
41+
}
3542

3643
case 'anthropic': {
3744
if (config.anthropic) {
@@ -57,6 +64,14 @@ export const webSearchPlugin = (config: WebSearchPluginConfig = DEFAULT_WEB_SEAR
5764
}
5865
break
5966
}
67+
68+
case 'openrouter': {
69+
if (config.openrouter) {
70+
const searchOptions = createOpenRouterOptions(config.openrouter)
71+
params.providerOptions = mergeProviderOptions(params.providerOptions, searchOptions)
72+
}
73+
break
74+
}
6075
}
6176

6277
return params
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export type OpenRouterSearchConfig = {
2+
plugins?: Array<{
3+
id: 'web'
4+
/**
5+
* Maximum number of search results to include (default: 5)
6+
*/
7+
max_results?: number
8+
/**
9+
* Custom search prompt to guide the search query
10+
*/
11+
search_prompt?: string
12+
}>
13+
/**
14+
* Built-in web search options for models that support native web search
15+
*/
16+
web_search_options?: {
17+
/**
18+
* Maximum number of search results to include
19+
*/
20+
max_results?: number
21+
/**
22+
* Custom search prompt to guide the search query
23+
*/
24+
search_prompt?: string
25+
}
26+
}

0 commit comments

Comments
 (0)