Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 76d48f9ccb | |||
| 115cd80432 | |||
| 531101742e | |||
| c3c577dff4 |
@@ -11,7 +11,6 @@
|
|||||||
"dist/**",
|
"dist/**",
|
||||||
"out/**",
|
"out/**",
|
||||||
"local/**",
|
"local/**",
|
||||||
"tests/**",
|
|
||||||
".yarn/**",
|
".yarn/**",
|
||||||
".gitignore",
|
".gitignore",
|
||||||
"scripts/cloudflare-worker.js",
|
"scripts/cloudflare-worker.js",
|
||||||
|
|||||||
@@ -12,15 +12,7 @@ This file provides guidance to AI coding assistants when working with code in th
|
|||||||
- **Always propose before executing**: Before making any changes, clearly explain your planned approach and wait for explicit user approval to ensure alignment and prevent unwanted modifications.
|
- **Always propose before executing**: Before making any changes, clearly explain your planned approach and wait for explicit user approval to ensure alignment and prevent unwanted modifications.
|
||||||
- **Lint, test, and format before completion**: Coding tasks are only complete after running `yarn lint`, `yarn test`, and `yarn format` successfully.
|
- **Lint, test, and format before completion**: Coding tasks are only complete after running `yarn lint`, `yarn test`, and `yarn format` successfully.
|
||||||
- **Write conventional commits**: Commit small, focused changes using Conventional Commit messages (e.g., `feat:`, `fix:`, `refactor:`, `docs:`).
|
- **Write conventional commits**: Commit small, focused changes using Conventional Commit messages (e.g., `feat:`, `fix:`, `refactor:`, `docs:`).
|
||||||
|
- **Follow PR template**: When submitting pull requests, follow the template in `.github/pull_request_template.md` to ensure complete context and documentation.
|
||||||
## Pull Request Workflow (CRITICAL)
|
|
||||||
|
|
||||||
When creating a Pull Request, you MUST:
|
|
||||||
|
|
||||||
1. **Read the PR template first**: Always read `.github/pull_request_template.md` before creating the PR
|
|
||||||
2. **Follow ALL template sections**: Structure the `--body` parameter to include every section from the template
|
|
||||||
3. **Never skip sections**: Include all sections even if marking them as N/A or "None"
|
|
||||||
4. **Use proper formatting**: Match the template's markdown structure exactly (headings, checkboxes, code blocks)
|
|
||||||
|
|
||||||
## Development Commands
|
## Development Commands
|
||||||
|
|
||||||
|
|||||||
+44
-96
@@ -134,108 +134,56 @@ artifactBuildCompleted: scripts/artifact-build-completed.js
|
|||||||
releaseInfo:
|
releaseInfo:
|
||||||
releaseNotes: |
|
releaseNotes: |
|
||||||
<!--LANG:en-->
|
<!--LANG:en-->
|
||||||
A New Era of Intelligence with Cherry Studio 1.7.1
|
What's New in v1.7.0-rc.3
|
||||||
|
|
||||||
Today we're releasing Cherry Studio 1.7.1 — our most ambitious update yet, introducing Agent: autonomous AI that thinks, plans, and acts.
|
✨ New Features:
|
||||||
|
- Provider: Added Silicon provider support for Anthropic API compatibility
|
||||||
|
- Provider: AIHubMix support for nano banana
|
||||||
|
|
||||||
For years, AI assistants have been reactive — waiting for your commands, responding to your questions. With Agent, we're changing that. Now, AI can truly work alongside you: understanding complex goals, breaking them into steps, and executing them independently.
|
🐛 Bug Fixes:
|
||||||
|
- i18n: Clean up translation tags and untranslated strings
|
||||||
|
- Provider: Fixed Silicon provider code list
|
||||||
|
- Provider: Fixed Poe API reasoning parameters for GPT-5 and reasoning models
|
||||||
|
- Provider: Fixed duplicate /v1 in Anthropic API endpoints
|
||||||
|
- Provider: Fixed Azure provider handling in AI SDK integration
|
||||||
|
- Models: Added Claude Opus 4.5 pattern to THINKING_TOKEN_MAP
|
||||||
|
- Models: Improved Gemini reasoning and message handling
|
||||||
|
- Models: Fixed custom parameters for Gemini models
|
||||||
|
- Models: Fixed qwen-mt-flash text delta support
|
||||||
|
- Models: Fixed Groq verbosity setting
|
||||||
|
- UI: Fixed quota display and quota tips
|
||||||
|
- UI: Fixed web search button condition
|
||||||
|
- Settings: Fixed updateAssistantPreset reducer to properly update preset
|
||||||
|
- Settings: Respect enableMaxTokens setting when maxTokens is not configured
|
||||||
|
- SDK: Fixed header merging logic in AI SDK
|
||||||
|
|
||||||
This is what we've been building toward. And it's just the beginning.
|
⚡ Improvements:
|
||||||
|
- SDK: Upgraded @anthropic-ai/claude-agent-sdk to 0.1.53
|
||||||
🤖 Meet Agent
|
|
||||||
Imagine having a brilliant colleague who never sleeps. Give Agent a goal — write a report, analyze data, refactor code — and watch it work. It reasons through problems, breaks them into steps, calls the right tools, and adapts when things change.
|
|
||||||
|
|
||||||
- **Think → Plan → Act**: From goal to execution, fully autonomous
|
|
||||||
- **Deep Reasoning**: Multi-turn thinking that solves real problems
|
|
||||||
- **Tool Mastery**: File operations, web search, code execution, and more
|
|
||||||
- **Skill Plugins**: Extend with custom commands and capabilities
|
|
||||||
- **You Stay in Control**: Real-time approval for sensitive actions
|
|
||||||
- **Full Visibility**: Every thought, every decision, fully transparent
|
|
||||||
|
|
||||||
🌐 Expanding Ecosystem
|
|
||||||
- **New Providers**: HuggingFace, Mistral, CherryIN, AI Gateway, Intel OVMS, Didi MCP
|
|
||||||
- **New Models**: Claude 4.5 Haiku, DeepSeek v3.2, GLM-4.6, Doubao, Ling series
|
|
||||||
- **MCP Integration**: Alibaba Cloud, ModelScope, Higress, MCP.so, TokenFlux and more
|
|
||||||
|
|
||||||
📚 Smarter Knowledge Base
|
|
||||||
- **OpenMinerU**: Self-hosted document processing
|
|
||||||
- **Full-Text Search**: Find anything instantly across your notes
|
|
||||||
- **Enhanced Tool Selection**: Smarter configuration for better AI assistance
|
|
||||||
|
|
||||||
📝 Notes, Reimagined
|
|
||||||
- Full-text search with highlighted results
|
|
||||||
- AI-powered smart rename
|
|
||||||
- Export as image
|
|
||||||
- Auto-wrap for tables
|
|
||||||
|
|
||||||
🖼️ Image & OCR
|
|
||||||
- Intel OVMS painting capabilities
|
|
||||||
- Intel OpenVINO NPU-accelerated OCR
|
|
||||||
|
|
||||||
🌍 Now in 10+ Languages
|
|
||||||
- Added German support
|
|
||||||
- Enhanced internationalization
|
|
||||||
|
|
||||||
⚡ Faster & More Polished
|
|
||||||
- Electron 38 upgrade
|
|
||||||
- New MCP management interface
|
|
||||||
- Dozens of UI refinements
|
|
||||||
|
|
||||||
❤️ Fully Open Source
|
|
||||||
Commercial restrictions removed. Cherry Studio now follows standard AGPL v3 — free for teams of any size.
|
|
||||||
|
|
||||||
The Agent Era is here. We can't wait to see what you'll create.
|
|
||||||
|
|
||||||
<!--LANG:zh-CN-->
|
<!--LANG:zh-CN-->
|
||||||
Cherry Studio 1.7.1:开启智能新纪元
|
v1.7.0-rc.3 更新内容
|
||||||
|
|
||||||
今天,我们正式发布 Cherry Studio 1.7.1 —— 迄今最具雄心的版本,带来全新的 Agent:能够自主思考、规划和行动的 AI。
|
✨ 新功能:
|
||||||
|
- 提供商:新增 Silicon 提供商对 Anthropic API 的兼容性支持
|
||||||
|
- 提供商:AIHubMix 支持 nano banana
|
||||||
|
|
||||||
多年来,AI 助手一直是被动的——等待你的指令,回应你的问题。Agent 改变了这一切。现在,AI 能够真正与你并肩工作:理解复杂目标,将其拆解为步骤,并独立执行。
|
🐛 问题修复:
|
||||||
|
- 国际化:清理翻译标签和未翻译字符串
|
||||||
|
- 提供商:修复 Silicon 提供商代码列表
|
||||||
|
- 提供商:修复 Poe API 对 GPT-5 和推理模型的推理参数
|
||||||
|
- 提供商:修复 Anthropic API 端点重复 /v1 问题
|
||||||
|
- 提供商:修复 Azure 提供商在 AI SDK 集成中的处理
|
||||||
|
- 模型:Claude Opus 4.5 添加到 THINKING_TOKEN_MAP
|
||||||
|
- 模型:改进 Gemini 推理和消息处理
|
||||||
|
- 模型:修复 Gemini 模型自定义参数
|
||||||
|
- 模型:修复 qwen-mt-flash text delta 支持
|
||||||
|
- 模型:修复 Groq verbosity 设置
|
||||||
|
- 界面:修复配额显示和配额提示
|
||||||
|
- 界面:修复 Web 搜索按钮条件
|
||||||
|
- 设置:修复 updateAssistantPreset reducer 正确更新 preset
|
||||||
|
- 设置:尊重 enableMaxTokens 设置
|
||||||
|
- SDK:修复 AI SDK 中 header 合并逻辑
|
||||||
|
|
||||||
这是我们一直在构建的未来。而这,仅仅是开始。
|
⚡ 改进:
|
||||||
|
- SDK:升级 @anthropic-ai/claude-agent-sdk 到 0.1.53
|
||||||
🤖 认识 Agent
|
|
||||||
想象一位永不疲倦的得力伙伴。给 Agent 一个目标——撰写报告、分析数据、重构代码——然后看它工作。它会推理问题、拆解步骤、调用工具,并在情况变化时灵活应对。
|
|
||||||
|
|
||||||
- **思考 → 规划 → 行动**:从目标到执行,全程自主
|
|
||||||
- **深度推理**:多轮思考,解决真实问题
|
|
||||||
- **工具大师**:文件操作、网络搜索、代码执行,样样精通
|
|
||||||
- **技能插件**:自定义命令,无限扩展
|
|
||||||
- **你掌控全局**:敏感操作,实时审批
|
|
||||||
- **完全透明**:每一步思考,每一个决策,清晰可见
|
|
||||||
|
|
||||||
🌐 生态持续壮大
|
|
||||||
- **新增服务商**:Hugging Face、Mistral、Perplexity、SophNet、AI Gateway、Cerebras AI
|
|
||||||
- **新增模型**:Gemini 3、Gemini 3 Pro(支持图像预览)、GPT-5.1、Claude Opus 4.5
|
|
||||||
- **MCP 集成**:百炼、魔搭、Higress、MCP.so、TokenFlux 等平台
|
|
||||||
|
|
||||||
📚 更智能的知识库
|
|
||||||
- **OpenMinerU**:本地自部署文档处理
|
|
||||||
- **全文搜索**:笔记内容一搜即达
|
|
||||||
- **增强工具选择**:更智能的配置,更好的 AI 协助
|
|
||||||
|
|
||||||
📝 笔记,焕然一新
|
|
||||||
- 全文搜索,结果高亮
|
|
||||||
- AI 智能重命名
|
|
||||||
- 导出为图片
|
|
||||||
- 表格自动换行
|
|
||||||
|
|
||||||
🖼️ 图像与 OCR
|
|
||||||
- Intel OVMS 绘图能力
|
|
||||||
- Intel OpenVINO NPU 加速 OCR
|
|
||||||
|
|
||||||
🌍 支持 10+ 种语言
|
|
||||||
- 新增德语支持
|
|
||||||
- 全面增强国际化
|
|
||||||
|
|
||||||
⚡ 更快、更精致
|
|
||||||
- 升级 Electron 38
|
|
||||||
- 新的 MCP 管理界面
|
|
||||||
- 数十处 UI 细节打磨
|
|
||||||
|
|
||||||
❤️ 完全开源
|
|
||||||
商用限制已移除。Cherry Studio 现遵循标准 AGPL v3 协议——任意规模团队均可自由使用。
|
|
||||||
|
|
||||||
Agent 纪元已至。期待你的创造。
|
|
||||||
<!--LANG:END-->
|
<!--LANG:END-->
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ export default defineConfig([
|
|||||||
'dist/**',
|
'dist/**',
|
||||||
'out/**',
|
'out/**',
|
||||||
'local/**',
|
'local/**',
|
||||||
'tests/**',
|
|
||||||
'.yarn/**',
|
'.yarn/**',
|
||||||
'.gitignore',
|
'.gitignore',
|
||||||
'scripts/cloudflare-worker.js',
|
'scripts/cloudflare-worker.js',
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "CherryStudio",
|
"name": "CherryStudio",
|
||||||
"version": "1.7.1",
|
"version": "1.7.0-rc.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A powerful AI assistant for producer.",
|
"description": "A powerful AI assistant for producer.",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
@@ -62,7 +62,6 @@
|
|||||||
"test": "vitest run --silent",
|
"test": "vitest run --silent",
|
||||||
"test:main": "vitest run --project main",
|
"test:main": "vitest run --project main",
|
||||||
"test:renderer": "vitest run --project renderer",
|
"test:renderer": "vitest run --project renderer",
|
||||||
"test:aicore": "vitest run --project aiCore",
|
|
||||||
"test:update": "yarn test:renderer --update",
|
"test:update": "yarn test:renderer --update",
|
||||||
"test:coverage": "vitest run --coverage --silent",
|
"test:coverage": "vitest run --coverage --silent",
|
||||||
"test:ui": "vitest --ui",
|
"test:ui": "vitest --ui",
|
||||||
@@ -165,7 +164,7 @@
|
|||||||
"@modelcontextprotocol/sdk": "^1.17.5",
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
||||||
"@mozilla/readability": "^0.6.0",
|
"@mozilla/readability": "^0.6.0",
|
||||||
"@notionhq/client": "^2.2.15",
|
"@notionhq/client": "^2.2.15",
|
||||||
"@openrouter/ai-sdk-provider": "^1.2.8",
|
"@openrouter/ai-sdk-provider": "^1.2.5",
|
||||||
"@opentelemetry/api": "^1.9.0",
|
"@opentelemetry/api": "^1.9.0",
|
||||||
"@opentelemetry/core": "2.0.0",
|
"@opentelemetry/core": "2.0.0",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.200.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.200.0",
|
||||||
@@ -173,7 +172,7 @@
|
|||||||
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
||||||
"@opentelemetry/sdk-trace-web": "^2.0.0",
|
"@opentelemetry/sdk-trace-web": "^2.0.0",
|
||||||
"@opeoginni/github-copilot-openai-compatible": "^0.1.21",
|
"@opeoginni/github-copilot-openai-compatible": "^0.1.21",
|
||||||
"@playwright/test": "^1.55.1",
|
"@playwright/test": "^1.52.0",
|
||||||
"@radix-ui/react-context-menu": "^2.2.16",
|
"@radix-ui/react-context-menu": "^2.2.16",
|
||||||
"@reduxjs/toolkit": "^2.2.5",
|
"@reduxjs/toolkit": "^2.2.5",
|
||||||
"@shikijs/markdown-it": "^3.12.0",
|
"@shikijs/markdown-it": "^3.12.0",
|
||||||
@@ -322,6 +321,7 @@
|
|||||||
"p-queue": "^8.1.0",
|
"p-queue": "^8.1.0",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdf-parse": "^1.1.1",
|
"pdf-parse": "^1.1.1",
|
||||||
|
"playwright": "^1.55.1",
|
||||||
"proxy-agent": "^6.5.0",
|
"proxy-agent": "^6.5.0",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.0",
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ export interface CherryInProviderSettings {
|
|||||||
headers?: HeadersInput
|
headers?: HeadersInput
|
||||||
/**
|
/**
|
||||||
* Optional endpoint type to distinguish different endpoint behaviors.
|
* Optional endpoint type to distinguish different endpoint behaviors.
|
||||||
* "image-generation" is also openai endpoint, but specifically for image generation.
|
|
||||||
*/
|
*/
|
||||||
endpointType?: 'openai' | 'openai-response' | 'anthropic' | 'gemini' | 'image-generation' | 'jina-rerank'
|
endpointType?: 'openai' | 'openai-response' | 'anthropic' | 'gemini' | 'image-generation' | 'jina-rerank'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
* Provides realistic mock responses for all provider types
|
* Provides realistic mock responses for all provider types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ModelMessage, Tool } from 'ai'
|
import { jsonSchema, type ModelMessage, type Tool } from 'ai'
|
||||||
import { jsonSchema } from 'ai'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard test messages for all scenarios
|
* Standard test messages for all scenarios
|
||||||
*/
|
*/
|
||||||
export const testMessages: Record<string, ModelMessage[]> = {
|
export const testMessages = {
|
||||||
simple: [{ role: 'user' as const, content: 'Hello, how are you?' }],
|
simple: [{ role: 'user' as const, content: 'Hello, how are you?' }],
|
||||||
|
|
||||||
conversation: [
|
conversation: [
|
||||||
@@ -46,7 +45,7 @@ export const testMessages: Record<string, ModelMessage[]> = {
|
|||||||
{ role: 'assistant' as const, content: '15 * 23 = 345' },
|
{ role: 'assistant' as const, content: '15 * 23 = 345' },
|
||||||
{ role: 'user' as const, content: 'Now divide that by 5' }
|
{ role: 'user' as const, content: 'Now divide that by 5' }
|
||||||
]
|
]
|
||||||
}
|
} satisfies Record<string, ModelMessage[]>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard test tools for tool calling scenarios
|
* Standard test tools for tool calling scenarios
|
||||||
@@ -139,17 +138,68 @@ export const testTools: Record<string, Tool> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock streaming chunks for different providers
|
||||||
|
*/
|
||||||
|
export const mockStreamingChunks = {
|
||||||
|
text: [
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'Hello' },
|
||||||
|
{ type: 'text-delta' as const, textDelta: ', ' },
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'this ' },
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'is ' },
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'a ' },
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'test.' }
|
||||||
|
],
|
||||||
|
|
||||||
|
withToolCall: [
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'Let me check the weather for you.' },
|
||||||
|
{
|
||||||
|
type: 'tool-call-delta' as const,
|
||||||
|
toolCallType: 'function' as const,
|
||||||
|
toolCallId: 'call_123',
|
||||||
|
toolName: 'getWeather',
|
||||||
|
argsTextDelta: '{"location":'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'tool-call-delta' as const,
|
||||||
|
toolCallType: 'function' as const,
|
||||||
|
toolCallId: 'call_123',
|
||||||
|
toolName: 'getWeather',
|
||||||
|
argsTextDelta: ' "San Francisco, CA"}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'tool-call' as const,
|
||||||
|
toolCallType: 'function' as const,
|
||||||
|
toolCallId: 'call_123',
|
||||||
|
toolName: 'getWeather',
|
||||||
|
args: { location: 'San Francisco, CA' }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
withFinish: [
|
||||||
|
{ type: 'text-delta' as const, textDelta: 'Complete response.' },
|
||||||
|
{
|
||||||
|
type: 'finish' as const,
|
||||||
|
finishReason: 'stop' as const,
|
||||||
|
usage: {
|
||||||
|
promptTokens: 10,
|
||||||
|
completionTokens: 5,
|
||||||
|
totalTokens: 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock complete responses for non-streaming scenarios
|
* Mock complete responses for non-streaming scenarios
|
||||||
* Note: AI SDK v5 uses inputTokens/outputTokens instead of promptTokens/completionTokens
|
|
||||||
*/
|
*/
|
||||||
export const mockCompleteResponses = {
|
export const mockCompleteResponses = {
|
||||||
simple: {
|
simple: {
|
||||||
text: 'This is a simple response.',
|
text: 'This is a simple response.',
|
||||||
finishReason: 'stop' as const,
|
finishReason: 'stop' as const,
|
||||||
usage: {
|
usage: {
|
||||||
inputTokens: 15,
|
promptTokens: 15,
|
||||||
outputTokens: 8,
|
completionTokens: 8,
|
||||||
totalTokens: 23
|
totalTokens: 23
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -165,8 +215,8 @@ export const mockCompleteResponses = {
|
|||||||
],
|
],
|
||||||
finishReason: 'tool-calls' as const,
|
finishReason: 'tool-calls' as const,
|
||||||
usage: {
|
usage: {
|
||||||
inputTokens: 25,
|
promptTokens: 25,
|
||||||
outputTokens: 12,
|
completionTokens: 12,
|
||||||
totalTokens: 37
|
totalTokens: 37
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -175,15 +225,14 @@ export const mockCompleteResponses = {
|
|||||||
text: 'Response with warnings.',
|
text: 'Response with warnings.',
|
||||||
finishReason: 'stop' as const,
|
finishReason: 'stop' as const,
|
||||||
usage: {
|
usage: {
|
||||||
inputTokens: 10,
|
promptTokens: 10,
|
||||||
outputTokens: 5,
|
completionTokens: 5,
|
||||||
totalTokens: 15
|
totalTokens: 15
|
||||||
},
|
},
|
||||||
warnings: [
|
warnings: [
|
||||||
{
|
{
|
||||||
type: 'unsupported-setting' as const,
|
type: 'unsupported-setting' as const,
|
||||||
setting: 'temperature',
|
message: 'Temperature parameter not supported for this model'
|
||||||
details: 'Temperature parameter not supported for this model'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -236,3 +285,47 @@ export const mockImageResponses = {
|
|||||||
warnings: []
|
warnings: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock error responses
|
||||||
|
*/
|
||||||
|
export const mockErrors = {
|
||||||
|
invalidApiKey: {
|
||||||
|
name: 'APIError',
|
||||||
|
message: 'Invalid API key provided',
|
||||||
|
statusCode: 401
|
||||||
|
},
|
||||||
|
|
||||||
|
rateLimitExceeded: {
|
||||||
|
name: 'RateLimitError',
|
||||||
|
message: 'Rate limit exceeded. Please try again later.',
|
||||||
|
statusCode: 429,
|
||||||
|
headers: {
|
||||||
|
'retry-after': '60'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
modelNotFound: {
|
||||||
|
name: 'ModelNotFoundError',
|
||||||
|
message: 'The requested model was not found',
|
||||||
|
statusCode: 404
|
||||||
|
},
|
||||||
|
|
||||||
|
contextLengthExceeded: {
|
||||||
|
name: 'ContextLengthError',
|
||||||
|
message: "This model's maximum context length is 4096 tokens",
|
||||||
|
statusCode: 400
|
||||||
|
},
|
||||||
|
|
||||||
|
timeout: {
|
||||||
|
name: 'TimeoutError',
|
||||||
|
message: 'Request timed out after 30000ms',
|
||||||
|
code: 'ETIMEDOUT'
|
||||||
|
},
|
||||||
|
|
||||||
|
networkError: {
|
||||||
|
name: 'NetworkError',
|
||||||
|
message: 'Network connection failed',
|
||||||
|
code: 'ECONNREFUSED'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
* Mock for @cherrystudio/ai-sdk-provider
|
|
||||||
* This mock is used in tests to avoid importing the actual package
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type CherryInProviderSettings = {
|
|
||||||
apiKey?: string
|
|
||||||
baseURL?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// oxlint-disable-next-line no-unused-vars
|
|
||||||
export const createCherryIn = (_options?: CherryInProviderSettings) => ({
|
|
||||||
// oxlint-disable-next-line no-unused-vars
|
|
||||||
languageModel: (_modelId: string) => ({
|
|
||||||
specificationVersion: 'v1',
|
|
||||||
provider: 'cherryin',
|
|
||||||
modelId: 'mock-model',
|
|
||||||
doGenerate: async () => ({ text: 'mock response' }),
|
|
||||||
doStream: async () => ({ stream: (async function* () {})() })
|
|
||||||
}),
|
|
||||||
// oxlint-disable-next-line no-unused-vars
|
|
||||||
chat: (_modelId: string) => ({
|
|
||||||
specificationVersion: 'v1',
|
|
||||||
provider: 'cherryin-chat',
|
|
||||||
modelId: 'mock-model',
|
|
||||||
doGenerate: async () => ({ text: 'mock response' }),
|
|
||||||
doStream: async () => ({ stream: (async function* () {})() })
|
|
||||||
}),
|
|
||||||
// oxlint-disable-next-line no-unused-vars
|
|
||||||
textEmbeddingModel: (_modelId: string) => ({
|
|
||||||
specificationVersion: 'v1',
|
|
||||||
provider: 'cherryin',
|
|
||||||
modelId: 'mock-embedding-model'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* Vitest Setup File
|
|
||||||
* Global test configuration and mocks for @cherrystudio/ai-core package
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Mock Vite SSR helper to avoid Node environment errors
|
|
||||||
;(globalThis as any).__vite_ssr_exportName__ = (_name: string, value: any) => value
|
|
||||||
|
|
||||||
// Note: @cherrystudio/ai-sdk-provider is mocked via alias in vitest.config.ts
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
|
|
||||||
import { createOpenAIOptions, createOpenRouterOptions, mergeProviderOptions } from '../factory'
|
|
||||||
|
|
||||||
describe('mergeProviderOptions', () => {
|
|
||||||
it('deep merges provider options for the same provider', () => {
|
|
||||||
const reasoningOptions = createOpenRouterOptions({
|
|
||||||
reasoning: {
|
|
||||||
enabled: true,
|
|
||||||
effort: 'medium'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const webSearchOptions = createOpenRouterOptions({
|
|
||||||
plugins: [{ id: 'web', max_results: 5 }]
|
|
||||||
})
|
|
||||||
|
|
||||||
const merged = mergeProviderOptions(reasoningOptions, webSearchOptions)
|
|
||||||
|
|
||||||
expect(merged.openrouter).toEqual({
|
|
||||||
reasoning: {
|
|
||||||
enabled: true,
|
|
||||||
effort: 'medium'
|
|
||||||
},
|
|
||||||
plugins: [{ id: 'web', max_results: 5 }]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('preserves options from other providers while merging', () => {
|
|
||||||
const openRouter = createOpenRouterOptions({
|
|
||||||
reasoning: { enabled: true }
|
|
||||||
})
|
|
||||||
const openAI = createOpenAIOptions({
|
|
||||||
reasoningEffort: 'low'
|
|
||||||
})
|
|
||||||
const merged = mergeProviderOptions(openRouter, openAI)
|
|
||||||
|
|
||||||
expect(merged.openrouter).toEqual({ reasoning: { enabled: true } })
|
|
||||||
expect(merged.openai).toEqual({ reasoningEffort: 'low' })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('overwrites primitive values with later values', () => {
|
|
||||||
const first = createOpenAIOptions({
|
|
||||||
reasoningEffort: 'low',
|
|
||||||
user: 'user-123'
|
|
||||||
})
|
|
||||||
const second = createOpenAIOptions({
|
|
||||||
reasoningEffort: 'high',
|
|
||||||
maxToolCalls: 5
|
|
||||||
})
|
|
||||||
|
|
||||||
const merged = mergeProviderOptions(first, second)
|
|
||||||
|
|
||||||
expect(merged.openai).toEqual({
|
|
||||||
reasoningEffort: 'high', // overwritten by second
|
|
||||||
user: 'user-123', // preserved from first
|
|
||||||
maxToolCalls: 5 // added from second
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('overwrites arrays with later values instead of merging', () => {
|
|
||||||
const first = createOpenRouterOptions({
|
|
||||||
models: ['gpt-4', 'gpt-3.5-turbo']
|
|
||||||
})
|
|
||||||
const second = createOpenRouterOptions({
|
|
||||||
models: ['claude-3-opus', 'claude-3-sonnet']
|
|
||||||
})
|
|
||||||
|
|
||||||
const merged = mergeProviderOptions(first, second)
|
|
||||||
|
|
||||||
// Array is completely replaced, not merged
|
|
||||||
expect(merged.openrouter?.models).toEqual(['claude-3-opus', 'claude-3-sonnet'])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('deeply merges nested objects while overwriting primitives', () => {
|
|
||||||
const first = createOpenRouterOptions({
|
|
||||||
reasoning: {
|
|
||||||
enabled: true,
|
|
||||||
effort: 'low'
|
|
||||||
},
|
|
||||||
user: 'user-123'
|
|
||||||
})
|
|
||||||
const second = createOpenRouterOptions({
|
|
||||||
reasoning: {
|
|
||||||
effort: 'high',
|
|
||||||
max_tokens: 500
|
|
||||||
},
|
|
||||||
user: 'user-456'
|
|
||||||
})
|
|
||||||
|
|
||||||
const merged = mergeProviderOptions(first, second)
|
|
||||||
|
|
||||||
expect(merged.openrouter).toEqual({
|
|
||||||
reasoning: {
|
|
||||||
enabled: true, // preserved from first
|
|
||||||
effort: 'high', // overwritten by second
|
|
||||||
max_tokens: 500 // added from second
|
|
||||||
},
|
|
||||||
user: 'user-456' // overwritten by second
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('replaces arrays instead of merging them', () => {
|
|
||||||
const first = createOpenRouterOptions({ plugins: [{ id: 'old' }] })
|
|
||||||
const second = createOpenRouterOptions({ plugins: [{ id: 'new' }] })
|
|
||||||
const merged = mergeProviderOptions(first, second)
|
|
||||||
// @ts-expect-error type-check for openrouter options is skipped. see function signature of createOpenRouterOptions
|
|
||||||
expect(merged.openrouter?.plugins).toEqual([{ id: 'new' }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -26,65 +26,13 @@ export function createGenericProviderOptions<T extends string>(
|
|||||||
return { [provider]: options } as Record<T, Record<string, any>>
|
return { [provider]: options } as Record<T, Record<string, any>>
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlainObject = Record<string, any>
|
|
||||||
|
|
||||||
const isPlainObject = (value: unknown): value is PlainObject => {
|
|
||||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function deepMergeObjects<T extends PlainObject>(target: T, source: PlainObject): T {
|
|
||||||
const result: PlainObject = { ...target }
|
|
||||||
Object.entries(source).forEach(([key, value]) => {
|
|
||||||
if (isPlainObject(value) && isPlainObject(result[key])) {
|
|
||||||
result[key] = deepMergeObjects(result[key], value)
|
|
||||||
} else {
|
|
||||||
result[key] = value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return result as T
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deep-merge multiple provider-specific options.
|
* 合并多个供应商的options
|
||||||
* Nested objects are recursively merged; primitive values are overwritten.
|
* @param optionsMap 包含多个供应商选项的对象
|
||||||
*
|
* @returns 合并后的TypedProviderOptions
|
||||||
* When the same key appears in multiple options:
|
|
||||||
* - If both values are plain objects: they are deeply merged (recursive merge)
|
|
||||||
* - If values are primitives/arrays: the later value overwrites the earlier one
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* mergeProviderOptions(
|
|
||||||
* { openrouter: { reasoning: { enabled: true, effort: 'low' }, user: 'user-123' } },
|
|
||||||
* { openrouter: { reasoning: { effort: 'high', max_tokens: 500 }, models: ['gpt-4'] } }
|
|
||||||
* )
|
|
||||||
* // Result: {
|
|
||||||
* // openrouter: {
|
|
||||||
* // reasoning: { enabled: true, effort: 'high', max_tokens: 500 },
|
|
||||||
* // user: 'user-123',
|
|
||||||
* // models: ['gpt-4']
|
|
||||||
* // }
|
|
||||||
* // }
|
|
||||||
*
|
|
||||||
* @param optionsMap Objects containing options for multiple providers
|
|
||||||
* @returns Fully merged TypedProviderOptions
|
|
||||||
*/
|
*/
|
||||||
export function mergeProviderOptions(...optionsMap: Partial<TypedProviderOptions>[]): TypedProviderOptions {
|
export function mergeProviderOptions(...optionsMap: Partial<TypedProviderOptions>[]): TypedProviderOptions {
|
||||||
return optionsMap.reduce<TypedProviderOptions>((acc, options) => {
|
return Object.assign({}, ...optionsMap)
|
||||||
if (!options) {
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
Object.entries(options).forEach(([providerId, providerOptions]) => {
|
|
||||||
if (!providerOptions) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (acc[providerId]) {
|
|
||||||
acc[providerId] = deepMergeObjects(acc[providerId] as PlainObject, providerOptions as PlainObject)
|
|
||||||
} else {
|
|
||||||
acc[providerId] = providerOptions as any
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return acc
|
|
||||||
}, {} as TypedProviderOptions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,20 +19,15 @@ describe('Provider Schemas', () => {
|
|||||||
expect(Array.isArray(baseProviders)).toBe(true)
|
expect(Array.isArray(baseProviders)).toBe(true)
|
||||||
expect(baseProviders.length).toBeGreaterThan(0)
|
expect(baseProviders.length).toBeGreaterThan(0)
|
||||||
|
|
||||||
// These are the actual base providers defined in schemas.ts
|
|
||||||
const expectedIds = [
|
const expectedIds = [
|
||||||
'openai',
|
'openai',
|
||||||
'openai-chat',
|
'openai-responses',
|
||||||
'openai-compatible',
|
'openai-compatible',
|
||||||
'anthropic',
|
'anthropic',
|
||||||
'google',
|
'google',
|
||||||
'xai',
|
'xai',
|
||||||
'azure',
|
'azure',
|
||||||
'azure-responses',
|
'deepseek'
|
||||||
'deepseek',
|
|
||||||
'openrouter',
|
|
||||||
'cherryin',
|
|
||||||
'cherryin-chat'
|
|
||||||
]
|
]
|
||||||
const actualIds = baseProviders.map((p) => p.id)
|
const actualIds = baseProviders.map((p) => p.id)
|
||||||
expectedIds.forEach((id) => {
|
expectedIds.forEach((id) => {
|
||||||
|
|||||||
@@ -232,13 +232,11 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
|
|
||||||
expect(pluginCallOrder).toEqual(['onRequestStart', 'transformParams', 'transformResult', 'onRequestEnd'])
|
expect(pluginCallOrder).toEqual(['onRequestStart', 'transformParams', 'transformResult', 'onRequestEnd'])
|
||||||
|
|
||||||
// transformParams receives params without model (model is handled separately)
|
|
||||||
// and context with core fields + dynamic fields (requestId, startTime, etc.)
|
|
||||||
expect(testPlugin.transformParams).toHaveBeenCalledWith(
|
expect(testPlugin.transformParams).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ prompt: 'A test image' }),
|
{ prompt: 'A test image' },
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
providerId: 'openai',
|
providerId: 'openai',
|
||||||
model: 'dall-e-3'
|
modelId: 'dall-e-3'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -275,12 +273,11 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
|
|
||||||
await executorWithPlugin.generateImage({ model: 'dall-e-3', prompt: 'A test image' })
|
await executorWithPlugin.generateImage({ model: 'dall-e-3', prompt: 'A test image' })
|
||||||
|
|
||||||
// resolveModel receives model id and context with core fields
|
|
||||||
expect(modelResolutionPlugin.resolveModel).toHaveBeenCalledWith(
|
expect(modelResolutionPlugin.resolveModel).toHaveBeenCalledWith(
|
||||||
'dall-e-3',
|
'dall-e-3',
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
providerId: 'openai',
|
providerId: 'openai',
|
||||||
model: 'dall-e-3'
|
modelId: 'dall-e-3'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -342,11 +339,12 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
.generateImage({ model: 'invalid-model', prompt: 'A test image' })
|
.generateImage({ model: 'invalid-model', prompt: 'A test image' })
|
||||||
.catch((error) => error)
|
.catch((error) => error)
|
||||||
|
|
||||||
// Error is thrown from pluginEngine directly as ImageModelResolutionError
|
expect(thrownError).toBeInstanceOf(ImageGenerationError)
|
||||||
expect(thrownError).toBeInstanceOf(ImageModelResolutionError)
|
expect(thrownError.message).toContain('Failed to generate image:')
|
||||||
expect(thrownError.message).toContain('Failed to resolve image model: invalid-model')
|
|
||||||
expect(thrownError.providerId).toBe('openai')
|
expect(thrownError.providerId).toBe('openai')
|
||||||
expect(thrownError.modelId).toBe('invalid-model')
|
expect(thrownError.modelId).toBe('invalid-model')
|
||||||
|
expect(thrownError.cause).toBeInstanceOf(ImageModelResolutionError)
|
||||||
|
expect(thrownError.cause.message).toContain('Failed to resolve image model: invalid-model')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle ImageModelResolutionError without provider', async () => {
|
it('should handle ImageModelResolutionError without provider', async () => {
|
||||||
@@ -364,9 +362,8 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
const apiError = new Error('API request failed')
|
const apiError = new Error('API request failed')
|
||||||
vi.mocked(aiGenerateImage).mockRejectedValue(apiError)
|
vi.mocked(aiGenerateImage).mockRejectedValue(apiError)
|
||||||
|
|
||||||
// Error propagates directly from pluginEngine without wrapping
|
|
||||||
await expect(executor.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
await expect(executor.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
||||||
'API request failed'
|
'Failed to generate image:'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -379,9 +376,8 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
vi.mocked(aiGenerateImage).mockRejectedValue(noImageError)
|
vi.mocked(aiGenerateImage).mockRejectedValue(noImageError)
|
||||||
vi.mocked(NoImageGeneratedError.isInstance).mockReturnValue(true)
|
vi.mocked(NoImageGeneratedError.isInstance).mockReturnValue(true)
|
||||||
|
|
||||||
// Error propagates directly from pluginEngine
|
|
||||||
await expect(executor.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
await expect(executor.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
||||||
'No image generated'
|
'Failed to generate image:'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -402,17 +398,15 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
[errorPlugin]
|
[errorPlugin]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error propagates directly from pluginEngine
|
|
||||||
await expect(executorWithPlugin.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
await expect(executorWithPlugin.generateImage({ model: 'dall-e-3', prompt: 'A test image' })).rejects.toThrow(
|
||||||
'Generation failed'
|
'Failed to generate image:'
|
||||||
)
|
)
|
||||||
|
|
||||||
// onError receives the original error and context with core fields
|
|
||||||
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
||||||
error,
|
error,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
providerId: 'openai',
|
providerId: 'openai',
|
||||||
model: 'dall-e-3'
|
modelId: 'dall-e-3'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -425,10 +419,9 @@ describe('RuntimeExecutor.generateImage', () => {
|
|||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
setTimeout(() => abortController.abort(), 10)
|
setTimeout(() => abortController.abort(), 10)
|
||||||
|
|
||||||
// Error propagates directly from pluginEngine
|
|
||||||
await expect(
|
await expect(
|
||||||
executor.generateImage({ model: 'dall-e-3', prompt: 'A test image', abortSignal: abortController.signal })
|
executor.generateImage({ model: 'dall-e-3', prompt: 'A test image', abortSignal: abortController.signal })
|
||||||
).rejects.toThrow('Operation was aborted')
|
).rejects.toThrow('Failed to generate image:')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,10 @@ import type { AiPlugin } from '../../plugins'
|
|||||||
import { globalRegistryManagement } from '../../providers/RegistryManagement'
|
import { globalRegistryManagement } from '../../providers/RegistryManagement'
|
||||||
import { RuntimeExecutor } from '../executor'
|
import { RuntimeExecutor } from '../executor'
|
||||||
|
|
||||||
// Mock AI SDK - use importOriginal to keep jsonSchema and other non-mocked exports
|
// Mock AI SDK
|
||||||
vi.mock('ai', async (importOriginal) => {
|
vi.mock('ai', () => ({
|
||||||
const actual = (await importOriginal()) as Record<string, unknown>
|
generateText: vi.fn()
|
||||||
return {
|
}))
|
||||||
...actual,
|
|
||||||
generateText: vi.fn()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
vi.mock('../../providers/RegistryManagement', () => ({
|
vi.mock('../../providers/RegistryManagement', () => ({
|
||||||
globalRegistryManagement: {
|
globalRegistryManagement: {
|
||||||
@@ -413,12 +409,11 @@ describe('RuntimeExecutor.generateText', () => {
|
|||||||
})
|
})
|
||||||
).rejects.toThrow('Generation failed')
|
).rejects.toThrow('Generation failed')
|
||||||
|
|
||||||
// onError receives the original error and context with core fields
|
|
||||||
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
||||||
error,
|
error,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
providerId: 'openai',
|
providerId: 'openai',
|
||||||
model: 'gpt-4'
|
modelId: 'gpt-4'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,14 +11,10 @@ import type { AiPlugin } from '../../plugins'
|
|||||||
import { globalRegistryManagement } from '../../providers/RegistryManagement'
|
import { globalRegistryManagement } from '../../providers/RegistryManagement'
|
||||||
import { RuntimeExecutor } from '../executor'
|
import { RuntimeExecutor } from '../executor'
|
||||||
|
|
||||||
// Mock AI SDK - use importOriginal to keep jsonSchema and other non-mocked exports
|
// Mock AI SDK
|
||||||
vi.mock('ai', async (importOriginal) => {
|
vi.mock('ai', () => ({
|
||||||
const actual = (await importOriginal()) as Record<string, unknown>
|
streamText: vi.fn()
|
||||||
return {
|
}))
|
||||||
...actual,
|
|
||||||
streamText: vi.fn()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
vi.mock('../../providers/RegistryManagement', () => ({
|
vi.mock('../../providers/RegistryManagement', () => ({
|
||||||
globalRegistryManagement: {
|
globalRegistryManagement: {
|
||||||
@@ -157,7 +153,7 @@ describe('RuntimeExecutor.streamText', () => {
|
|||||||
describe('Max Tokens Parameter', () => {
|
describe('Max Tokens Parameter', () => {
|
||||||
const maxTokensValues = [10, 50, 100, 500, 1000, 2000, 4000]
|
const maxTokensValues = [10, 50, 100, 500, 1000, 2000, 4000]
|
||||||
|
|
||||||
it.each(maxTokensValues)('should support maxOutputTokens=%s', async (maxOutputTokens) => {
|
it.each(maxTokensValues)('should support maxTokens=%s', async (maxTokens) => {
|
||||||
const mockStream = {
|
const mockStream = {
|
||||||
textStream: (async function* () {
|
textStream: (async function* () {
|
||||||
yield 'Response'
|
yield 'Response'
|
||||||
@@ -172,13 +168,12 @@ describe('RuntimeExecutor.streamText', () => {
|
|||||||
await executor.streamText({
|
await executor.streamText({
|
||||||
model: 'gpt-4',
|
model: 'gpt-4',
|
||||||
messages: testMessages.simple,
|
messages: testMessages.simple,
|
||||||
maxOutputTokens
|
maxOutputTokens: maxTokens
|
||||||
})
|
})
|
||||||
|
|
||||||
// Parameters are passed through without transformation
|
|
||||||
expect(streamText).toHaveBeenCalledWith(
|
expect(streamText).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
maxOutputTokens
|
maxTokens
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -518,12 +513,11 @@ describe('RuntimeExecutor.streamText', () => {
|
|||||||
})
|
})
|
||||||
).rejects.toThrow('Stream error')
|
).rejects.toThrow('Stream error')
|
||||||
|
|
||||||
// onError receives the original error and context with core fields
|
|
||||||
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
expect(errorPlugin.onError).toHaveBeenCalledWith(
|
||||||
error,
|
error,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
providerId: 'openai',
|
providerId: 'openai',
|
||||||
model: 'gpt-4'
|
modelId: 'gpt-4'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
import path from 'node:path'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
import { defineConfig } from 'vitest/config'
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true
|
||||||
setupFiles: [path.resolve(__dirname, './src/__tests__/setup.ts')]
|
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'@': './src'
|
||||||
// Mock external packages that may not be available in test environment
|
|
||||||
'@cherrystudio/ai-sdk-provider': path.resolve(__dirname, './src/__tests__/mocks/ai-sdk-provider.ts')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
esbuild: {
|
esbuild: {
|
||||||
|
|||||||
@@ -374,5 +374,13 @@ export enum IpcChannel {
|
|||||||
WebSocket_Stop = 'webSocket:stop',
|
WebSocket_Stop = 'webSocket:stop',
|
||||||
WebSocket_Status = 'webSocket:status',
|
WebSocket_Status = 'webSocket:status',
|
||||||
WebSocket_SendFile = 'webSocket:send-file',
|
WebSocket_SendFile = 'webSocket:send-file',
|
||||||
WebSocket_GetAllCandidates = 'webSocket:get-all-candidates'
|
WebSocket_GetAllCandidates = 'webSocket:get-all-candidates',
|
||||||
|
|
||||||
|
// Volcengine
|
||||||
|
Volcengine_SaveCredentials = 'volcengine:save-credentials',
|
||||||
|
Volcengine_HasCredentials = 'volcengine:has-credentials',
|
||||||
|
Volcengine_ClearCredentials = 'volcengine:clear-credentials',
|
||||||
|
Volcengine_ListModels = 'volcengine:list-models',
|
||||||
|
Volcengine_GetAuthHeaders = 'volcengine:get-auth-headers',
|
||||||
|
Volcengine_MakeRequest = 'volcengine:make-request'
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-49
@@ -1,64 +1,42 @@
|
|||||||
import { defineConfig } from '@playwright/test'
|
import { defineConfig, devices } from '@playwright/test'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Playwright configuration for Electron e2e testing.
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
* See https://playwright.dev/docs/test-configuration
|
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// Look for test files in the specs directory
|
// Look for test files, relative to this configuration file.
|
||||||
testDir: './tests/e2e/specs',
|
testDir: './tests/e2e',
|
||||||
|
/* Run tests in files in parallel */
|
||||||
// Global timeout for each test
|
fullyParallel: true,
|
||||||
timeout: 60000,
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
|
|
||||||
// Assertion timeout
|
|
||||||
expect: {
|
|
||||||
timeout: 10000
|
|
||||||
},
|
|
||||||
|
|
||||||
// Electron apps should run tests sequentially to avoid conflicts
|
|
||||||
fullyParallel: false,
|
|
||||||
workers: 1,
|
|
||||||
|
|
||||||
// Fail the build on CI if you accidentally left test.only in the source code
|
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
|
/* Retry on CI only */
|
||||||
// Retry on CI only
|
|
||||||
retries: process.env.CI ? 2 : 0,
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
/* Opt out of parallel tests on CI. */
|
||||||
// Reporter configuration
|
workers: process.env.CI ? 1 : undefined,
|
||||||
reporter: [['html', { outputFolder: 'playwright-report' }], ['list']],
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
|
reporter: 'html',
|
||||||
// Global setup and teardown
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
globalSetup: './tests/e2e/global-setup.ts',
|
|
||||||
globalTeardown: './tests/e2e/global-teardown.ts',
|
|
||||||
|
|
||||||
// Output directory for test artifacts
|
|
||||||
outputDir: './test-results',
|
|
||||||
|
|
||||||
// Shared settings for all tests
|
|
||||||
use: {
|
use: {
|
||||||
// Collect trace when retrying the failed test
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
trace: 'retain-on-failure',
|
// baseURL: 'http://localhost:3000',
|
||||||
|
|
||||||
// Take screenshot only on failure
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
screenshot: 'only-on-failure',
|
trace: 'on-first-retry'
|
||||||
|
|
||||||
// Record video only on failure
|
|
||||||
video: 'retain-on-failure',
|
|
||||||
|
|
||||||
// Action timeout
|
|
||||||
actionTimeout: 15000,
|
|
||||||
|
|
||||||
// Navigation timeout
|
|
||||||
navigationTimeout: 30000
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Single project for Electron testing
|
/* Configure projects for major browsers */
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
name: 'electron',
|
name: 'chromium',
|
||||||
testMatch: '**/*.spec.ts'
|
use: { ...devices['Desktop Chrome'] }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/* Run your local dev server before starting the tests */
|
||||||
|
// webServer: {
|
||||||
|
// command: 'npm run start',
|
||||||
|
// url: 'http://localhost:3000',
|
||||||
|
// reuseExistingServer: !process.env.CI,
|
||||||
|
// },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ import {
|
|||||||
import storeSyncService from './services/StoreSyncService'
|
import storeSyncService from './services/StoreSyncService'
|
||||||
import { themeService } from './services/ThemeService'
|
import { themeService } from './services/ThemeService'
|
||||||
import VertexAIService from './services/VertexAIService'
|
import VertexAIService from './services/VertexAIService'
|
||||||
|
import VolcengineService from './services/VolcengineService'
|
||||||
import WebSocketService from './services/WebSocketService'
|
import WebSocketService from './services/WebSocketService'
|
||||||
import { setOpenLinkExternal } from './services/WebviewService'
|
import { setOpenLinkExternal } from './services/WebviewService'
|
||||||
import { windowService } from './services/WindowService'
|
import { windowService } from './services/WindowService'
|
||||||
@@ -1077,6 +1078,14 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
ipcMain.handle(IpcChannel.WebSocket_SendFile, WebSocketService.sendFile)
|
ipcMain.handle(IpcChannel.WebSocket_SendFile, WebSocketService.sendFile)
|
||||||
ipcMain.handle(IpcChannel.WebSocket_GetAllCandidates, WebSocketService.getAllCandidates)
|
ipcMain.handle(IpcChannel.WebSocket_GetAllCandidates, WebSocketService.getAllCandidates)
|
||||||
|
|
||||||
|
// Volcengine
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_SaveCredentials, VolcengineService.saveCredentials)
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_HasCredentials, VolcengineService.hasCredentials)
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_ClearCredentials, VolcengineService.clearCredentials)
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_ListModels, VolcengineService.listModels)
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_GetAuthHeaders, VolcengineService.getAuthHeaders)
|
||||||
|
ipcMain.handle(IpcChannel.Volcengine_MakeRequest, VolcengineService.makeRequest)
|
||||||
|
|
||||||
ipcMain.handle(IpcChannel.APP_CrashRenderProcess, () => {
|
ipcMain.handle(IpcChannel.APP_CrashRenderProcess, () => {
|
||||||
mainWindow.webContents.forcefullyCrashRenderer()
|
mainWindow.webContents.forcefullyCrashRenderer()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -548,17 +548,6 @@ class CodeToolsService {
|
|||||||
logger.debug(`Environment variables:`, Object.keys(env))
|
logger.debug(`Environment variables:`, Object.keys(env))
|
||||||
logger.debug(`Options:`, options)
|
logger.debug(`Options:`, options)
|
||||||
|
|
||||||
// Validate directory exists before proceeding
|
|
||||||
if (!directory || !fs.existsSync(directory)) {
|
|
||||||
const errorMessage = `Directory does not exist: ${directory}`
|
|
||||||
logger.error(errorMessage)
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: errorMessage,
|
|
||||||
command: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const packageName = await this.getPackageName(cliTool)
|
const packageName = await this.getPackageName(cliTool)
|
||||||
const bunPath = await this.getBunPath()
|
const bunPath = await this.getBunPath()
|
||||||
const executableName = await this.getCliExecutableName(cliTool)
|
const executableName = await this.getCliExecutableName(cliTool)
|
||||||
@@ -720,7 +709,6 @@ class CodeToolsService {
|
|||||||
// Build bat file content, including debug information
|
// Build bat file content, including debug information
|
||||||
const batContent = [
|
const batContent = [
|
||||||
'@echo off',
|
'@echo off',
|
||||||
'chcp 65001 >nul 2>&1', // Switch to UTF-8 code page for international path support
|
|
||||||
`title ${cliTool} - Cherry Studio`, // Set window title in bat file
|
`title ${cliTool} - Cherry Studio`, // Set window title in bat file
|
||||||
'echo ================================================',
|
'echo ================================================',
|
||||||
'echo Cherry Studio CLI Tool Launcher',
|
'echo Cherry Studio CLI Tool Launcher',
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ class McpService {
|
|||||||
tools.map((tool: SDKTool) => {
|
tools.map((tool: SDKTool) => {
|
||||||
const serverTool: MCPTool = {
|
const serverTool: MCPTool = {
|
||||||
...tool,
|
...tool,
|
||||||
id: buildFunctionCallToolName(server.name, tool.name, server.id),
|
id: buildFunctionCallToolName(server.name, tool.name),
|
||||||
serverId: server.id,
|
serverId: server.id,
|
||||||
serverName: server.name,
|
serverName: server.name,
|
||||||
type: 'mcp'
|
type: 'mcp'
|
||||||
|
|||||||
@@ -0,0 +1,732 @@
|
|||||||
|
import { loggerService } from '@logger'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
import { app, net, safeStorage } from 'electron'
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import * as z from 'zod'
|
||||||
|
|
||||||
|
import { getConfigDir } from '../utils/file'
|
||||||
|
|
||||||
|
const logger = loggerService.withContext('VolcengineService')
|
||||||
|
|
||||||
|
// Configuration constants
|
||||||
|
const CONFIG = {
|
||||||
|
ALGORITHM: 'HMAC-SHA256',
|
||||||
|
REQUEST_TYPE: 'request',
|
||||||
|
DEFAULT_REGION: 'cn-beijing',
|
||||||
|
SERVICE_NAME: 'ark',
|
||||||
|
DEFAULT_HEADERS: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
accept: 'application/json'
|
||||||
|
},
|
||||||
|
API_URLS: {
|
||||||
|
ARK_HOST: 'open.volcengineapi.com'
|
||||||
|
},
|
||||||
|
CREDENTIALS_FILE_NAME: '.volcengine_credentials',
|
||||||
|
API_VERSION: '2024-01-01',
|
||||||
|
DEFAULT_PAGE_SIZE: 100
|
||||||
|
} as const
|
||||||
|
|
||||||
|
// Request schemas
|
||||||
|
const ListFoundationModelsRequestSchema = z.object({
|
||||||
|
PageNumber: z.optional(z.number()),
|
||||||
|
PageSize: z.optional(z.number())
|
||||||
|
})
|
||||||
|
|
||||||
|
const ListEndpointsRequestSchema = z.object({
|
||||||
|
ProjectName: z.optional(z.string()),
|
||||||
|
PageNumber: z.optional(z.number()),
|
||||||
|
PageSize: z.optional(z.number())
|
||||||
|
})
|
||||||
|
|
||||||
|
// Response schemas - only keep fields needed for model list
|
||||||
|
const FoundationModelItemSchema = z.object({
|
||||||
|
Name: z.string(),
|
||||||
|
DisplayName: z.optional(z.string()),
|
||||||
|
Description: z.optional(z.string())
|
||||||
|
})
|
||||||
|
|
||||||
|
const EndpointItemSchema = z.object({
|
||||||
|
Id: z.string(),
|
||||||
|
Name: z.optional(z.string()),
|
||||||
|
Description: z.optional(z.string()),
|
||||||
|
ModelReference: z.optional(
|
||||||
|
z.object({
|
||||||
|
FoundationModel: z.optional(
|
||||||
|
z.object({
|
||||||
|
Name: z.optional(z.string()),
|
||||||
|
ModelVersion: z.optional(z.string())
|
||||||
|
})
|
||||||
|
),
|
||||||
|
CustomModelId: z.optional(z.string())
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const ListFoundationModelsResponseSchema = z.object({
|
||||||
|
Result: z.object({
|
||||||
|
TotalCount: z.number(),
|
||||||
|
Items: z.array(FoundationModelItemSchema)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const ListEndpointsResponseSchema = z.object({
|
||||||
|
Result: z.object({
|
||||||
|
TotalCount: z.number(),
|
||||||
|
Items: z.array(EndpointItemSchema)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Infer types from schemas
|
||||||
|
type ListFoundationModelsRequest = z.infer<typeof ListFoundationModelsRequestSchema>
|
||||||
|
type ListEndpointsRequest = z.infer<typeof ListEndpointsRequestSchema>
|
||||||
|
type ListFoundationModelsResponse = z.infer<typeof ListFoundationModelsResponseSchema>
|
||||||
|
type ListEndpointsResponse = z.infer<typeof ListEndpointsResponseSchema>
|
||||||
|
|
||||||
|
// ============= Internal Type Definitions =============
|
||||||
|
|
||||||
|
interface VolcengineCredentials {
|
||||||
|
accessKeyId: string
|
||||||
|
secretAccessKey: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SignedRequestParams {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
host: string
|
||||||
|
path: string
|
||||||
|
query: Record<string, string>
|
||||||
|
headers: Record<string, string>
|
||||||
|
body?: string
|
||||||
|
service: string
|
||||||
|
region: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SignedHeaders {
|
||||||
|
Authorization: string
|
||||||
|
'X-Date': string
|
||||||
|
'X-Content-Sha256': string
|
||||||
|
Host: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ModelInfo {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
description?: string
|
||||||
|
created?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ListModelsResult {
|
||||||
|
models: ModelInfo[]
|
||||||
|
total?: number
|
||||||
|
warnings?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom error class
|
||||||
|
class VolcengineServiceError extends Error {
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
public readonly cause?: unknown
|
||||||
|
) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'VolcengineServiceError'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volcengine API Signing Service
|
||||||
|
*
|
||||||
|
* Implements HMAC-SHA256 signing algorithm for Volcengine API authentication.
|
||||||
|
* Securely stores credentials using Electron's safeStorage.
|
||||||
|
*/
|
||||||
|
class VolcengineService {
|
||||||
|
private readonly credentialsFilePath: string
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.credentialsFilePath = this.getCredentialsFilePath()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path for storing encrypted credentials
|
||||||
|
*/
|
||||||
|
private getCredentialsFilePath(): string {
|
||||||
|
const oldPath = path.join(app.getPath('userData'), CONFIG.CREDENTIALS_FILE_NAME)
|
||||||
|
if (fs.existsSync(oldPath)) {
|
||||||
|
return oldPath
|
||||||
|
}
|
||||||
|
return path.join(getConfigDir(), CONFIG.CREDENTIALS_FILE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Cryptographic Helper Methods =============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate SHA256 hash of data and return hex encoded string
|
||||||
|
*/
|
||||||
|
private sha256Hash(data: string | Buffer): string {
|
||||||
|
return crypto.createHash('sha256').update(data).digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate HMAC-SHA256 and return buffer
|
||||||
|
*/
|
||||||
|
private hmacSha256(key: Buffer | string, data: string): Buffer {
|
||||||
|
return crypto.createHmac('sha256', key).update(data, 'utf8').digest()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate HMAC-SHA256 and return hex encoded string
|
||||||
|
*/
|
||||||
|
private hmacSha256Hex(key: Buffer | string, data: string): string {
|
||||||
|
return crypto.createHmac('sha256', key).update(data, 'utf8').digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL encode according to RFC3986
|
||||||
|
*/
|
||||||
|
private uriEncode(str: string, encodeSlash: boolean = true): string {
|
||||||
|
if (!str) return ''
|
||||||
|
|
||||||
|
return str
|
||||||
|
.split('')
|
||||||
|
.map((char) => {
|
||||||
|
if (
|
||||||
|
(char >= 'A' && char <= 'Z') ||
|
||||||
|
(char >= 'a' && char <= 'z') ||
|
||||||
|
(char >= '0' && char <= '9') ||
|
||||||
|
char === '_' ||
|
||||||
|
char === '-' ||
|
||||||
|
char === '~' ||
|
||||||
|
char === '.'
|
||||||
|
) {
|
||||||
|
return char
|
||||||
|
}
|
||||||
|
if (char === '/' && !encodeSlash) {
|
||||||
|
return char
|
||||||
|
}
|
||||||
|
return encodeURIComponent(char)
|
||||||
|
})
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Signing Implementation =============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current UTC time in ISO8601 format (YYYYMMDD'T'HHMMSS'Z')
|
||||||
|
*/
|
||||||
|
private getIso8601DateTime(): string {
|
||||||
|
const now = new Date()
|
||||||
|
return now
|
||||||
|
.toISOString()
|
||||||
|
.replace(/[-:]/g, '')
|
||||||
|
.replace(/\.\d{3}/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get date portion from datetime (YYYYMMDD)
|
||||||
|
*/
|
||||||
|
private getDateFromDateTime(dateTime: string): string {
|
||||||
|
return dateTime.substring(0, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build canonical query string from query parameters
|
||||||
|
*/
|
||||||
|
private buildCanonicalQueryString(query: Record<string, string>): string {
|
||||||
|
if (!query || Object.keys(query).length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.keys(query)
|
||||||
|
.sort()
|
||||||
|
.map((key) => `${this.uriEncode(key)}=${this.uriEncode(query[key])}`)
|
||||||
|
.join('&')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build canonical headers string
|
||||||
|
*/
|
||||||
|
private buildCanonicalHeaders(headers: Record<string, string>): {
|
||||||
|
canonicalHeaders: string
|
||||||
|
signedHeaders: string
|
||||||
|
} {
|
||||||
|
const sortedKeys = Object.keys(headers)
|
||||||
|
.map((k) => k.toLowerCase())
|
||||||
|
.sort()
|
||||||
|
|
||||||
|
const canonicalHeaders = sortedKeys.map((key) => `${key}:${headers[key]?.trim() || ''}`).join('\n') + '\n'
|
||||||
|
|
||||||
|
const signedHeaders = sortedKeys.join(';')
|
||||||
|
|
||||||
|
return { canonicalHeaders, signedHeaders }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the signing key through a series of HMAC operations
|
||||||
|
*
|
||||||
|
* kSecret = SecretAccessKey
|
||||||
|
* kDate = HMAC(kSecret, Date)
|
||||||
|
* kRegion = HMAC(kDate, Region)
|
||||||
|
* kService = HMAC(kRegion, Service)
|
||||||
|
* kSigning = HMAC(kService, "request")
|
||||||
|
*/
|
||||||
|
private deriveSigningKey(secretKey: string, date: string, region: string, service: string): Buffer {
|
||||||
|
const kDate = this.hmacSha256(secretKey, date)
|
||||||
|
const kRegion = this.hmacSha256(kDate, region)
|
||||||
|
const kService = this.hmacSha256(kRegion, service)
|
||||||
|
const kSigning = this.hmacSha256(kService, CONFIG.REQUEST_TYPE)
|
||||||
|
return kSigning
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create canonical request string
|
||||||
|
*
|
||||||
|
* CanonicalRequest =
|
||||||
|
* HTTPRequestMethod + '\n' +
|
||||||
|
* CanonicalURI + '\n' +
|
||||||
|
* CanonicalQueryString + '\n' +
|
||||||
|
* CanonicalHeaders + '\n' +
|
||||||
|
* SignedHeaders + '\n' +
|
||||||
|
* HexEncode(Hash(RequestPayload))
|
||||||
|
*/
|
||||||
|
private createCanonicalRequest(
|
||||||
|
method: string,
|
||||||
|
canonicalUri: string,
|
||||||
|
canonicalQueryString: string,
|
||||||
|
canonicalHeaders: string,
|
||||||
|
signedHeaders: string,
|
||||||
|
payloadHash: string
|
||||||
|
): string {
|
||||||
|
return [method, canonicalUri, canonicalQueryString, canonicalHeaders, signedHeaders, payloadHash].join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create string to sign
|
||||||
|
*
|
||||||
|
* StringToSign =
|
||||||
|
* Algorithm + '\n' +
|
||||||
|
* RequestDateTime + '\n' +
|
||||||
|
* CredentialScope + '\n' +
|
||||||
|
* HexEncode(Hash(CanonicalRequest))
|
||||||
|
*/
|
||||||
|
private createStringToSign(dateTime: string, credentialScope: string, canonicalRequest: string): string {
|
||||||
|
const hashedCanonicalRequest = this.sha256Hash(canonicalRequest)
|
||||||
|
return [CONFIG.ALGORITHM, dateTime, credentialScope, hashedCanonicalRequest].join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate signature for the request
|
||||||
|
*/
|
||||||
|
private generateSignature(params: SignedRequestParams, credentials: VolcengineCredentials): SignedHeaders {
|
||||||
|
const { method, host, path: requestPath, query, body, service, region } = params
|
||||||
|
|
||||||
|
// Step 1: Prepare datetime
|
||||||
|
const dateTime = this.getIso8601DateTime()
|
||||||
|
const date = this.getDateFromDateTime(dateTime)
|
||||||
|
|
||||||
|
// Step 2: Calculate payload hash
|
||||||
|
const payloadHash = this.sha256Hash(body || '')
|
||||||
|
|
||||||
|
// Step 3: Prepare headers for signing
|
||||||
|
const headersToSign: Record<string, string> = {
|
||||||
|
host: host,
|
||||||
|
'x-date': dateTime,
|
||||||
|
'x-content-sha256': payloadHash,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Build canonical components
|
||||||
|
const canonicalUri = this.uriEncode(requestPath, false) || '/'
|
||||||
|
const canonicalQueryString = this.buildCanonicalQueryString(query)
|
||||||
|
const { canonicalHeaders, signedHeaders } = this.buildCanonicalHeaders(headersToSign)
|
||||||
|
|
||||||
|
// Step 5: Create canonical request
|
||||||
|
const canonicalRequest = this.createCanonicalRequest(
|
||||||
|
method.toUpperCase(),
|
||||||
|
canonicalUri,
|
||||||
|
canonicalQueryString,
|
||||||
|
canonicalHeaders,
|
||||||
|
signedHeaders,
|
||||||
|
payloadHash
|
||||||
|
)
|
||||||
|
|
||||||
|
// Step 6: Create credential scope and string to sign
|
||||||
|
const credentialScope = `${date}/${region}/${service}/${CONFIG.REQUEST_TYPE}`
|
||||||
|
const stringToSign = this.createStringToSign(dateTime, credentialScope, canonicalRequest)
|
||||||
|
|
||||||
|
// Step 7: Calculate signature
|
||||||
|
const signingKey = this.deriveSigningKey(credentials.secretAccessKey, date, region, service)
|
||||||
|
const signature = this.hmacSha256Hex(signingKey, stringToSign)
|
||||||
|
|
||||||
|
// Step 8: Build authorization header
|
||||||
|
const authorization = `${CONFIG.ALGORITHM} Credential=${credentials.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`
|
||||||
|
|
||||||
|
return {
|
||||||
|
Authorization: authorization,
|
||||||
|
'X-Date': dateTime,
|
||||||
|
'X-Content-Sha256': payloadHash,
|
||||||
|
Host: host
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Credential Management =============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save credentials securely using Electron's safeStorage
|
||||||
|
*/
|
||||||
|
public saveCredentials = async (
|
||||||
|
_: Electron.IpcMainInvokeEvent,
|
||||||
|
accessKeyId: string,
|
||||||
|
secretAccessKey: string
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
if (!accessKeyId || !secretAccessKey) {
|
||||||
|
throw new VolcengineServiceError('Access Key ID and Secret Access Key are required')
|
||||||
|
}
|
||||||
|
|
||||||
|
const credentials: VolcengineCredentials = { accessKeyId, secretAccessKey }
|
||||||
|
const credentialsJson = JSON.stringify(credentials)
|
||||||
|
const encryptedData = safeStorage.encryptString(credentialsJson)
|
||||||
|
|
||||||
|
// Ensure directory exists
|
||||||
|
const dir = path.dirname(this.credentialsFilePath)
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
await fs.promises.mkdir(dir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.promises.writeFile(this.credentialsFilePath, encryptedData)
|
||||||
|
logger.info('Volcengine credentials saved successfully')
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to save Volcengine credentials:', error as Error)
|
||||||
|
throw new VolcengineServiceError('Failed to save credentials', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load credentials from encrypted storage
|
||||||
|
* @throws VolcengineServiceError if credentials file exists but is corrupted
|
||||||
|
*/
|
||||||
|
private async loadCredentials(): Promise<VolcengineCredentials | null> {
|
||||||
|
if (!fs.existsSync(this.credentialsFilePath)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const encryptedData = await fs.promises.readFile(this.credentialsFilePath)
|
||||||
|
const decryptedJson = safeStorage.decryptString(Buffer.from(encryptedData))
|
||||||
|
return JSON.parse(decryptedJson) as VolcengineCredentials
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to load Volcengine credentials:', error as Error)
|
||||||
|
throw new VolcengineServiceError(
|
||||||
|
'Credentials file exists but could not be loaded. Please re-enter your credentials.',
|
||||||
|
error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if credentials exist
|
||||||
|
*/
|
||||||
|
public hasCredentials = async (): Promise<boolean> => {
|
||||||
|
return fs.existsSync(this.credentialsFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear stored credentials
|
||||||
|
*/
|
||||||
|
public clearCredentials = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(this.credentialsFilePath)) {
|
||||||
|
await fs.promises.unlink(this.credentialsFilePath)
|
||||||
|
logger.info('Volcengine credentials cleared')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to clear Volcengine credentials:', error as Error)
|
||||||
|
throw new VolcengineServiceError('Failed to clear credentials', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= API Methods =============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a signed request to Volcengine API
|
||||||
|
*/
|
||||||
|
private async makeSignedRequest<T>(
|
||||||
|
method: 'GET' | 'POST',
|
||||||
|
host: string,
|
||||||
|
path: string,
|
||||||
|
action: string,
|
||||||
|
version: string,
|
||||||
|
query?: Record<string, string>,
|
||||||
|
body?: Record<string, unknown>,
|
||||||
|
service: string = CONFIG.SERVICE_NAME,
|
||||||
|
region: string = CONFIG.DEFAULT_REGION
|
||||||
|
): Promise<T> {
|
||||||
|
const credentials = await this.loadCredentials()
|
||||||
|
if (!credentials) {
|
||||||
|
throw new VolcengineServiceError('No credentials found. Please save credentials first.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullQuery: Record<string, string> = {
|
||||||
|
Action: action,
|
||||||
|
Version: version,
|
||||||
|
...query
|
||||||
|
}
|
||||||
|
|
||||||
|
const bodyString = body ? JSON.stringify(body) : ''
|
||||||
|
|
||||||
|
const signedHeaders = this.generateSignature(
|
||||||
|
{
|
||||||
|
method,
|
||||||
|
host,
|
||||||
|
path,
|
||||||
|
query: fullQuery,
|
||||||
|
headers: {},
|
||||||
|
body: bodyString,
|
||||||
|
service,
|
||||||
|
region
|
||||||
|
},
|
||||||
|
credentials
|
||||||
|
)
|
||||||
|
|
||||||
|
// Build URL with query string (use simple encoding for URL, canonical encoding is only for signature)
|
||||||
|
const urlParams = new URLSearchParams(fullQuery)
|
||||||
|
const url = `https://${host}${path}?${urlParams.toString()}`
|
||||||
|
|
||||||
|
const requestHeaders: Record<string, string> = {
|
||||||
|
...CONFIG.DEFAULT_HEADERS,
|
||||||
|
Authorization: signedHeaders.Authorization,
|
||||||
|
'X-Date': signedHeaders['X-Date'],
|
||||||
|
'X-Content-Sha256': signedHeaders['X-Content-Sha256']
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug('Making Volcengine API request', { url, method, action })
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await net.fetch(url, {
|
||||||
|
method,
|
||||||
|
headers: requestHeaders,
|
||||||
|
body: method === 'POST' && bodyString ? bodyString : undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text()
|
||||||
|
logger.error(`Volcengine API error: ${response.status}`, { errorText })
|
||||||
|
throw new VolcengineServiceError(`API request failed: ${response.status} - ${errorText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (await response.json()) as T
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof VolcengineServiceError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
logger.error('Volcengine API request failed:', error as Error)
|
||||||
|
throw new VolcengineServiceError('API request failed', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List foundation models from Volcengine ARK
|
||||||
|
*/
|
||||||
|
private async listFoundationModels(region: string = CONFIG.DEFAULT_REGION): Promise<ListFoundationModelsResponse> {
|
||||||
|
const requestBody: ListFoundationModelsRequest = {
|
||||||
|
PageNumber: 1,
|
||||||
|
PageSize: CONFIG.DEFAULT_PAGE_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.makeSignedRequest<unknown>(
|
||||||
|
'POST',
|
||||||
|
CONFIG.API_URLS.ARK_HOST,
|
||||||
|
'/',
|
||||||
|
'ListFoundationModels',
|
||||||
|
CONFIG.API_VERSION,
|
||||||
|
{},
|
||||||
|
requestBody,
|
||||||
|
CONFIG.SERVICE_NAME,
|
||||||
|
region
|
||||||
|
)
|
||||||
|
|
||||||
|
return ListFoundationModelsResponseSchema.parse(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List user-created endpoints from Volcengine ARK
|
||||||
|
*/
|
||||||
|
private async listEndpoints(
|
||||||
|
projectName?: string,
|
||||||
|
region: string = CONFIG.DEFAULT_REGION
|
||||||
|
): Promise<ListEndpointsResponse> {
|
||||||
|
const requestBody: ListEndpointsRequest = {
|
||||||
|
ProjectName: projectName || 'default',
|
||||||
|
PageNumber: 1,
|
||||||
|
PageSize: CONFIG.DEFAULT_PAGE_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.makeSignedRequest<unknown>(
|
||||||
|
'POST',
|
||||||
|
CONFIG.API_URLS.ARK_HOST,
|
||||||
|
'/',
|
||||||
|
'ListEndpoints',
|
||||||
|
CONFIG.API_VERSION,
|
||||||
|
{},
|
||||||
|
requestBody,
|
||||||
|
CONFIG.SERVICE_NAME,
|
||||||
|
region
|
||||||
|
)
|
||||||
|
|
||||||
|
return ListEndpointsResponseSchema.parse(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all available models from Volcengine ARK
|
||||||
|
* Combines foundation models and user-created endpoints
|
||||||
|
*/
|
||||||
|
public listModels = async (
|
||||||
|
_?: Electron.IpcMainInvokeEvent,
|
||||||
|
projectName?: string,
|
||||||
|
region?: string
|
||||||
|
): Promise<ListModelsResult> => {
|
||||||
|
try {
|
||||||
|
const effectiveRegion = region || CONFIG.DEFAULT_REGION
|
||||||
|
const [foundationModelsResult, endpointsResult] = await Promise.allSettled([
|
||||||
|
this.listFoundationModels(effectiveRegion),
|
||||||
|
this.listEndpoints(projectName, effectiveRegion)
|
||||||
|
])
|
||||||
|
|
||||||
|
const models: ModelInfo[] = []
|
||||||
|
const warnings: string[] = []
|
||||||
|
|
||||||
|
if (foundationModelsResult.status === 'fulfilled') {
|
||||||
|
const foundationModels = foundationModelsResult.value
|
||||||
|
for (const item of foundationModels.Result.Items) {
|
||||||
|
models.push({
|
||||||
|
id: item.Name,
|
||||||
|
name: item.DisplayName || item.Name,
|
||||||
|
description: item.Description
|
||||||
|
})
|
||||||
|
}
|
||||||
|
logger.info(`Found ${foundationModels.Result.Items.length} foundation models`)
|
||||||
|
} else {
|
||||||
|
const errorMsg = `Failed to fetch foundation models: ${foundationModelsResult.reason}`
|
||||||
|
logger.warn(errorMsg)
|
||||||
|
warnings.push(errorMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process endpoints
|
||||||
|
if (endpointsResult.status === 'fulfilled') {
|
||||||
|
const endpoints = endpointsResult.value
|
||||||
|
for (const item of endpoints.Result.Items) {
|
||||||
|
const modelRef = item.ModelReference
|
||||||
|
const foundationModelName = modelRef?.FoundationModel?.Name
|
||||||
|
const modelVersion = modelRef?.FoundationModel?.ModelVersion
|
||||||
|
const customModelId = modelRef?.CustomModelId
|
||||||
|
|
||||||
|
let displayName = item.Name || item.Id
|
||||||
|
if (foundationModelName) {
|
||||||
|
displayName = modelVersion ? `${foundationModelName} (${modelVersion})` : foundationModelName
|
||||||
|
} else if (customModelId) {
|
||||||
|
displayName = customModelId
|
||||||
|
}
|
||||||
|
|
||||||
|
models.push({
|
||||||
|
id: item.Id,
|
||||||
|
name: displayName,
|
||||||
|
description: item.Description
|
||||||
|
})
|
||||||
|
}
|
||||||
|
logger.info(`Found ${endpoints.Result.Items.length} endpoints`)
|
||||||
|
} else {
|
||||||
|
const errorMsg = `Failed to fetch endpoints: ${endpointsResult.reason}`
|
||||||
|
logger.warn(errorMsg)
|
||||||
|
warnings.push(errorMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If both failed, throw error
|
||||||
|
if (foundationModelsResult.status === 'rejected' && endpointsResult.status === 'rejected') {
|
||||||
|
throw new VolcengineServiceError('Failed to fetch both foundation models and endpoints')
|
||||||
|
}
|
||||||
|
|
||||||
|
const total =
|
||||||
|
(foundationModelsResult.status === 'fulfilled' ? foundationModelsResult.value.Result.TotalCount : 0) +
|
||||||
|
(endpointsResult.status === 'fulfilled' ? endpointsResult.value.Result.TotalCount : 0)
|
||||||
|
|
||||||
|
logger.info(`Total models found: ${models.length}`)
|
||||||
|
|
||||||
|
return {
|
||||||
|
models,
|
||||||
|
total,
|
||||||
|
warnings: warnings.length > 0 ? warnings : undefined
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to list Volcengine models:', error as Error)
|
||||||
|
throw new VolcengineServiceError('Failed to list models', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get authorization headers for external use
|
||||||
|
* This allows the renderer process to make direct API calls with proper authentication
|
||||||
|
*/
|
||||||
|
public getAuthHeaders = async (
|
||||||
|
_: Electron.IpcMainInvokeEvent,
|
||||||
|
params: {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
host: string
|
||||||
|
path: string
|
||||||
|
query?: Record<string, string>
|
||||||
|
body?: string
|
||||||
|
service?: string
|
||||||
|
region?: string
|
||||||
|
}
|
||||||
|
): Promise<SignedHeaders> => {
|
||||||
|
const credentials = await this.loadCredentials()
|
||||||
|
if (!credentials) {
|
||||||
|
throw new VolcengineServiceError('No credentials found. Please save credentials first.')
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.generateSignature(
|
||||||
|
{
|
||||||
|
method: params.method,
|
||||||
|
host: params.host,
|
||||||
|
path: params.path,
|
||||||
|
query: params.query || {},
|
||||||
|
headers: {},
|
||||||
|
body: params.body,
|
||||||
|
service: params.service || CONFIG.SERVICE_NAME,
|
||||||
|
region: params.region || CONFIG.DEFAULT_REGION
|
||||||
|
},
|
||||||
|
credentials
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a generic signed API request
|
||||||
|
* This is a more flexible method that allows custom API calls
|
||||||
|
*/
|
||||||
|
public makeRequest = async (
|
||||||
|
_: Electron.IpcMainInvokeEvent,
|
||||||
|
params: {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
host: string
|
||||||
|
path: string
|
||||||
|
action: string
|
||||||
|
version: string
|
||||||
|
query?: Record<string, string>
|
||||||
|
body?: Record<string, unknown>
|
||||||
|
service?: string
|
||||||
|
region?: string
|
||||||
|
}
|
||||||
|
): Promise<unknown> => {
|
||||||
|
return this.makeSignedRequest(
|
||||||
|
params.method,
|
||||||
|
params.host,
|
||||||
|
params.path,
|
||||||
|
params.action,
|
||||||
|
params.version,
|
||||||
|
params.query,
|
||||||
|
params.body,
|
||||||
|
params.service || CONFIG.SERVICE_NAME,
|
||||||
|
params.region || CONFIG.DEFAULT_REGION
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new VolcengineService()
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
// src/main/services/agents/services/claudecode/index.ts
|
// src/main/services/agents/services/claudecode/index.ts
|
||||||
import { EventEmitter } from 'node:events'
|
import { EventEmitter } from 'node:events'
|
||||||
import { createRequire } from 'node:module'
|
import { createRequire } from 'node:module'
|
||||||
import path from 'node:path'
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
CanUseTool,
|
CanUseTool,
|
||||||
@@ -122,11 +121,7 @@ class ClaudeCodeService implements AgentServiceInterface {
|
|||||||
// TODO: support set small model in UI
|
// TODO: support set small model in UI
|
||||||
ANTHROPIC_DEFAULT_HAIKU_MODEL: modelInfo.modelId,
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: modelInfo.modelId,
|
||||||
ELECTRON_RUN_AS_NODE: '1',
|
ELECTRON_RUN_AS_NODE: '1',
|
||||||
ELECTRON_NO_ATTACH_CONSOLE: '1',
|
ELECTRON_NO_ATTACH_CONSOLE: '1'
|
||||||
// Set CLAUDE_CONFIG_DIR to app's userData directory to avoid path encoding issues
|
|
||||||
// on Windows when the username contains non-ASCII characters (e.g., Chinese characters)
|
|
||||||
// This prevents the SDK from using the user's home directory which may have encoding problems
|
|
||||||
CLAUDE_CONFIG_DIR: path.join(app.getPath('userData'), '.claude')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorChunks: string[] = []
|
const errorChunks: string[] = []
|
||||||
|
|||||||
@@ -1,196 +0,0 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
|
|
||||||
import { buildFunctionCallToolName } from '../mcp'
|
|
||||||
|
|
||||||
describe('buildFunctionCallToolName', () => {
|
|
||||||
describe('basic functionality', () => {
|
|
||||||
it('should combine server name and tool name', () => {
|
|
||||||
const result = buildFunctionCallToolName('github', 'search_issues')
|
|
||||||
expect(result).toContain('github')
|
|
||||||
expect(result).toContain('search')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should sanitize names by replacing dashes with underscores', () => {
|
|
||||||
const result = buildFunctionCallToolName('my-server', 'my-tool')
|
|
||||||
// Input dashes are replaced, but the separator between server and tool is a dash
|
|
||||||
expect(result).toBe('my_serv-my_tool')
|
|
||||||
expect(result).toContain('_')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle empty server names gracefully', () => {
|
|
||||||
const result = buildFunctionCallToolName('', 'tool')
|
|
||||||
expect(result).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('uniqueness with serverId', () => {
|
|
||||||
it('should generate different IDs for same server name but different serverIds', () => {
|
|
||||||
const serverId1 = 'server-id-123456'
|
|
||||||
const serverId2 = 'server-id-789012'
|
|
||||||
const serverName = 'github'
|
|
||||||
const toolName = 'search_repos'
|
|
||||||
|
|
||||||
const result1 = buildFunctionCallToolName(serverName, toolName, serverId1)
|
|
||||||
const result2 = buildFunctionCallToolName(serverName, toolName, serverId2)
|
|
||||||
|
|
||||||
expect(result1).not.toBe(result2)
|
|
||||||
expect(result1).toContain('123456')
|
|
||||||
expect(result2).toContain('789012')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should generate same ID when serverId is not provided', () => {
|
|
||||||
const serverName = 'github'
|
|
||||||
const toolName = 'search_repos'
|
|
||||||
|
|
||||||
const result1 = buildFunctionCallToolName(serverName, toolName)
|
|
||||||
const result2 = buildFunctionCallToolName(serverName, toolName)
|
|
||||||
|
|
||||||
expect(result1).toBe(result2)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should include serverId suffix when provided', () => {
|
|
||||||
const serverId = 'abc123def456'
|
|
||||||
const result = buildFunctionCallToolName('server', 'tool', serverId)
|
|
||||||
|
|
||||||
// Should include last 6 chars of serverId
|
|
||||||
expect(result).toContain('ef456')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('character sanitization', () => {
|
|
||||||
it('should replace invalid characters with underscores', () => {
|
|
||||||
const result = buildFunctionCallToolName('test@server', 'tool#name')
|
|
||||||
expect(result).not.toMatch(/[@#]/)
|
|
||||||
expect(result).toMatch(/^[a-zA-Z0-9_-]+$/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should ensure name starts with a letter', () => {
|
|
||||||
const result = buildFunctionCallToolName('123server', '456tool')
|
|
||||||
expect(result).toMatch(/^[a-zA-Z]/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle consecutive underscores/dashes', () => {
|
|
||||||
const result = buildFunctionCallToolName('my--server', 'my__tool')
|
|
||||||
expect(result).not.toMatch(/[_-]{2,}/)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('length constraints', () => {
|
|
||||||
it('should truncate names longer than 63 characters', () => {
|
|
||||||
const longServerName = 'a'.repeat(50)
|
|
||||||
const longToolName = 'b'.repeat(50)
|
|
||||||
const result = buildFunctionCallToolName(longServerName, longToolName, 'id123456')
|
|
||||||
|
|
||||||
expect(result.length).toBeLessThanOrEqual(63)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not end with underscore or dash after truncation', () => {
|
|
||||||
const longServerName = 'a'.repeat(50)
|
|
||||||
const longToolName = 'b'.repeat(50)
|
|
||||||
const result = buildFunctionCallToolName(longServerName, longToolName, 'id123456')
|
|
||||||
|
|
||||||
expect(result).not.toMatch(/[_-]$/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should preserve serverId suffix even with long server/tool names', () => {
|
|
||||||
const longServerName = 'a'.repeat(50)
|
|
||||||
const longToolName = 'b'.repeat(50)
|
|
||||||
const serverId = 'server-id-xyz789'
|
|
||||||
|
|
||||||
const result = buildFunctionCallToolName(longServerName, longToolName, serverId)
|
|
||||||
|
|
||||||
// The suffix should be preserved and not truncated
|
|
||||||
expect(result).toContain('xyz789')
|
|
||||||
expect(result.length).toBeLessThanOrEqual(63)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should ensure two long-named servers with different IDs produce different results', () => {
|
|
||||||
const longServerName = 'a'.repeat(50)
|
|
||||||
const longToolName = 'b'.repeat(50)
|
|
||||||
const serverId1 = 'server-id-abc123'
|
|
||||||
const serverId2 = 'server-id-def456'
|
|
||||||
|
|
||||||
const result1 = buildFunctionCallToolName(longServerName, longToolName, serverId1)
|
|
||||||
const result2 = buildFunctionCallToolName(longServerName, longToolName, serverId2)
|
|
||||||
|
|
||||||
// Both should be within limit
|
|
||||||
expect(result1.length).toBeLessThanOrEqual(63)
|
|
||||||
expect(result2.length).toBeLessThanOrEqual(63)
|
|
||||||
|
|
||||||
// They should be different due to preserved suffix
|
|
||||||
expect(result1).not.toBe(result2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('edge cases with serverId', () => {
|
|
||||||
it('should handle serverId with only non-alphanumeric characters', () => {
|
|
||||||
const serverId = '------' // All dashes
|
|
||||||
const result = buildFunctionCallToolName('server', 'tool', serverId)
|
|
||||||
|
|
||||||
// Should still produce a valid unique suffix via fallback hash
|
|
||||||
expect(result).toBeTruthy()
|
|
||||||
expect(result.length).toBeLessThanOrEqual(63)
|
|
||||||
expect(result).toMatch(/^[a-zA-Z][a-zA-Z0-9_-]*$/)
|
|
||||||
// Should have a suffix (underscore followed by something)
|
|
||||||
expect(result).toMatch(/_[a-z0-9]+$/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should produce different results for different non-alphanumeric serverIds', () => {
|
|
||||||
const serverId1 = '------'
|
|
||||||
const serverId2 = '!!!!!!'
|
|
||||||
|
|
||||||
const result1 = buildFunctionCallToolName('server', 'tool', serverId1)
|
|
||||||
const result2 = buildFunctionCallToolName('server', 'tool', serverId2)
|
|
||||||
|
|
||||||
// Should be different because the hash fallback produces different values
|
|
||||||
expect(result1).not.toBe(result2)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle empty string serverId differently from undefined', () => {
|
|
||||||
const resultWithEmpty = buildFunctionCallToolName('server', 'tool', '')
|
|
||||||
const resultWithUndefined = buildFunctionCallToolName('server', 'tool', undefined)
|
|
||||||
|
|
||||||
// Empty string is falsy, so both should behave the same (no suffix)
|
|
||||||
expect(resultWithEmpty).toBe(resultWithUndefined)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle serverId with mixed alphanumeric and special chars', () => {
|
|
||||||
const serverId = 'ab@#cd' // Mixed chars, last 6 chars contain some alphanumeric
|
|
||||||
const result = buildFunctionCallToolName('server', 'tool', serverId)
|
|
||||||
|
|
||||||
// Should extract alphanumeric chars: 'abcd' from 'ab@#cd'
|
|
||||||
expect(result).toContain('abcd')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('real-world scenarios', () => {
|
|
||||||
it('should handle GitHub MCP server instances correctly', () => {
|
|
||||||
const serverName = 'github'
|
|
||||||
const toolName = 'search_repositories'
|
|
||||||
|
|
||||||
const githubComId = 'server-github-com-abc123'
|
|
||||||
const gheId = 'server-ghe-internal-xyz789'
|
|
||||||
|
|
||||||
const tool1 = buildFunctionCallToolName(serverName, toolName, githubComId)
|
|
||||||
const tool2 = buildFunctionCallToolName(serverName, toolName, gheId)
|
|
||||||
|
|
||||||
// Should be different
|
|
||||||
expect(tool1).not.toBe(tool2)
|
|
||||||
|
|
||||||
// Both should be valid identifiers
|
|
||||||
expect(tool1).toMatch(/^[a-zA-Z][a-zA-Z0-9_-]*$/)
|
|
||||||
expect(tool2).toMatch(/^[a-zA-Z][a-zA-Z0-9_-]*$/)
|
|
||||||
|
|
||||||
// Both should be <= 63 chars
|
|
||||||
expect(tool1.length).toBeLessThanOrEqual(63)
|
|
||||||
expect(tool2.length).toBeLessThanOrEqual(63)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle tool names that already include server name prefix', () => {
|
|
||||||
const result = buildFunctionCallToolName('github', 'github_search_repos')
|
|
||||||
expect(result).toBeTruthy()
|
|
||||||
// Should not double the server name
|
|
||||||
expect(result.split('github').length - 1).toBeLessThanOrEqual(2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
+4
-27
@@ -1,25 +1,7 @@
|
|||||||
export function buildFunctionCallToolName(serverName: string, toolName: string, serverId?: string) {
|
export function buildFunctionCallToolName(serverName: string, toolName: string) {
|
||||||
const sanitizedServer = serverName.trim().replace(/-/g, '_')
|
const sanitizedServer = serverName.trim().replace(/-/g, '_')
|
||||||
const sanitizedTool = toolName.trim().replace(/-/g, '_')
|
const sanitizedTool = toolName.trim().replace(/-/g, '_')
|
||||||
|
|
||||||
// Calculate suffix first to reserve space for it
|
|
||||||
// Suffix format: "_" + 6 alphanumeric chars = 7 chars total
|
|
||||||
let serverIdSuffix = ''
|
|
||||||
if (serverId) {
|
|
||||||
// Take the last 6 characters of the serverId for brevity
|
|
||||||
serverIdSuffix = serverId.slice(-6).replace(/[^a-zA-Z0-9]/g, '')
|
|
||||||
|
|
||||||
// Fallback: if suffix becomes empty (all non-alphanumeric chars), use a simple hash
|
|
||||||
if (!serverIdSuffix) {
|
|
||||||
const hash = serverId.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0)
|
|
||||||
serverIdSuffix = hash.toString(36).slice(-6) || 'x'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reserve space for suffix when calculating max base name length
|
|
||||||
const SUFFIX_LENGTH = serverIdSuffix ? serverIdSuffix.length + 1 : 0 // +1 for underscore
|
|
||||||
const MAX_BASE_LENGTH = 63 - SUFFIX_LENGTH
|
|
||||||
|
|
||||||
// Combine server name and tool name
|
// Combine server name and tool name
|
||||||
let name = sanitizedTool
|
let name = sanitizedTool
|
||||||
if (!sanitizedTool.includes(sanitizedServer.slice(0, 7))) {
|
if (!sanitizedTool.includes(sanitizedServer.slice(0, 7))) {
|
||||||
@@ -38,9 +20,9 @@ export function buildFunctionCallToolName(serverName: string, toolName: string,
|
|||||||
// Remove consecutive underscores/dashes (optional improvement)
|
// Remove consecutive underscores/dashes (optional improvement)
|
||||||
name = name.replace(/[_-]{2,}/g, '_')
|
name = name.replace(/[_-]{2,}/g, '_')
|
||||||
|
|
||||||
// Truncate base name BEFORE adding suffix to ensure suffix is never cut off
|
// Truncate to 63 characters maximum
|
||||||
if (name.length > MAX_BASE_LENGTH) {
|
if (name.length > 63) {
|
||||||
name = name.slice(0, MAX_BASE_LENGTH)
|
name = name.slice(0, 63)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle edge case: ensure we still have a valid name if truncation left invalid chars at edges
|
// Handle edge case: ensure we still have a valid name if truncation left invalid chars at edges
|
||||||
@@ -48,10 +30,5 @@ export function buildFunctionCallToolName(serverName: string, toolName: string,
|
|||||||
name = name.slice(0, -1)
|
name = name.slice(0, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now append the suffix - it will always fit within 63 chars
|
|
||||||
if (serverIdSuffix) {
|
|
||||||
name = `${name}_${serverIdSuffix}`
|
|
||||||
}
|
|
||||||
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -572,6 +572,41 @@ const api = {
|
|||||||
status: () => ipcRenderer.invoke(IpcChannel.WebSocket_Status),
|
status: () => ipcRenderer.invoke(IpcChannel.WebSocket_Status),
|
||||||
sendFile: (filePath: string) => ipcRenderer.invoke(IpcChannel.WebSocket_SendFile, filePath),
|
sendFile: (filePath: string) => ipcRenderer.invoke(IpcChannel.WebSocket_SendFile, filePath),
|
||||||
getAllCandidates: () => ipcRenderer.invoke(IpcChannel.WebSocket_GetAllCandidates)
|
getAllCandidates: () => ipcRenderer.invoke(IpcChannel.WebSocket_GetAllCandidates)
|
||||||
|
},
|
||||||
|
volcengine: {
|
||||||
|
saveCredentials: (accessKeyId: string, secretAccessKey: string): Promise<void> =>
|
||||||
|
ipcRenderer.invoke(IpcChannel.Volcengine_SaveCredentials, accessKeyId, secretAccessKey),
|
||||||
|
hasCredentials: (): Promise<boolean> => ipcRenderer.invoke(IpcChannel.Volcengine_HasCredentials),
|
||||||
|
clearCredentials: (): Promise<void> => ipcRenderer.invoke(IpcChannel.Volcengine_ClearCredentials),
|
||||||
|
listModels: (
|
||||||
|
projectName?: string,
|
||||||
|
region?: string
|
||||||
|
): Promise<{
|
||||||
|
models: Array<{ id: string; name: string; description?: string; created?: number }>
|
||||||
|
total?: number
|
||||||
|
warnings?: string[]
|
||||||
|
}> => ipcRenderer.invoke(IpcChannel.Volcengine_ListModels, projectName, region),
|
||||||
|
getAuthHeaders: (params: {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
host: string
|
||||||
|
path: string
|
||||||
|
query?: Record<string, string>
|
||||||
|
body?: string
|
||||||
|
service?: string
|
||||||
|
region?: string
|
||||||
|
}): Promise<{ Authorization: string; 'X-Date': string; 'X-Content-Sha256': string; Host: string }> =>
|
||||||
|
ipcRenderer.invoke(IpcChannel.Volcengine_GetAuthHeaders, params),
|
||||||
|
makeRequest: (params: {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
host: string
|
||||||
|
path: string
|
||||||
|
action: string
|
||||||
|
version: string
|
||||||
|
query?: Record<string, string>
|
||||||
|
body?: Record<string, unknown>
|
||||||
|
service?: string
|
||||||
|
region?: string
|
||||||
|
}): Promise<unknown> => ipcRenderer.invoke(IpcChannel.Volcengine_MakeRequest, params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,9 +212,8 @@ export class ToolCallChunkHandler {
|
|||||||
description: toolName,
|
description: toolName,
|
||||||
type: 'builtin'
|
type: 'builtin'
|
||||||
} as BaseTool
|
} as BaseTool
|
||||||
} else if ((mcpTool = this.mcpTools.find((t) => t.id === toolName) as MCPTool)) {
|
} else if ((mcpTool = this.mcpTools.find((t) => t.name === toolName) as MCPTool)) {
|
||||||
// 如果是客户端执行的 MCP 工具,沿用现有逻辑
|
// 如果是客户端执行的 MCP 工具,沿用现有逻辑
|
||||||
// toolName is mcpTool.id (registered with id as key in convertMcpToolsToAiSdkTools)
|
|
||||||
logger.info(`[ToolCallChunkHandler] Handling client-side MCP tool: ${toolName}`)
|
logger.info(`[ToolCallChunkHandler] Handling client-side MCP tool: ${toolName}`)
|
||||||
// mcpTool = this.mcpTools.find((t) => t.name === toolName) as MCPTool
|
// mcpTool = this.mcpTools.find((t) => t.name === toolName) as MCPTool
|
||||||
// if (!mcpTool) {
|
// if (!mcpTool) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import { buildAiSdkMiddlewares } from './middleware/AiSdkMiddlewareBuilder'
|
|||||||
import { buildPlugins } from './plugins/PluginBuilder'
|
import { buildPlugins } from './plugins/PluginBuilder'
|
||||||
import { createAiSdkProvider } from './provider/factory'
|
import { createAiSdkProvider } from './provider/factory'
|
||||||
import {
|
import {
|
||||||
adaptProvider,
|
|
||||||
getActualProvider,
|
getActualProvider,
|
||||||
isModernSdkSupported,
|
isModernSdkSupported,
|
||||||
prepareSpecialProviderConfig,
|
prepareSpecialProviderConfig,
|
||||||
@@ -65,11 +64,12 @@ export default class ModernAiProvider {
|
|||||||
* - URL will be automatically formatted via `formatProviderApiHost`, adding version suffixes like `/v1`
|
* - URL will be automatically formatted via `formatProviderApiHost`, adding version suffixes like `/v1`
|
||||||
*
|
*
|
||||||
* 2. When called with `(model, provider)`:
|
* 2. When called with `(model, provider)`:
|
||||||
* - The provided provider will be adapted via `adaptProvider`
|
* - **Directly uses the provided provider WITHOUT going through `getActualProvider`**
|
||||||
* - URL formatting behavior depends on the adapted result
|
* - **URL will NOT be automatically formatted, `/v1` suffix will NOT be added**
|
||||||
|
* - This is legacy behavior kept for backward compatibility
|
||||||
*
|
*
|
||||||
* 3. When called with `(provider)`:
|
* 3. When called with `(provider)`:
|
||||||
* - The provider will be adapted via `adaptProvider`
|
* - Directly uses the provider without requiring a model
|
||||||
* - Used for operations that don't need a model (e.g., fetchModels)
|
* - Used for operations that don't need a model (e.g., fetchModels)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -77,7 +77,7 @@ export default class ModernAiProvider {
|
|||||||
* // Recommended: Auto-format URL
|
* // Recommended: Auto-format URL
|
||||||
* const ai = new ModernAiProvider(model)
|
* const ai = new ModernAiProvider(model)
|
||||||
*
|
*
|
||||||
* // Provider will be adapted
|
* // Not recommended: Skip URL formatting (only for special cases)
|
||||||
* const ai = new ModernAiProvider(model, customProvider)
|
* const ai = new ModernAiProvider(model, customProvider)
|
||||||
*
|
*
|
||||||
* // For operations that don't need a model
|
* // For operations that don't need a model
|
||||||
@@ -91,12 +91,12 @@ export default class ModernAiProvider {
|
|||||||
if (this.isModel(modelOrProvider)) {
|
if (this.isModel(modelOrProvider)) {
|
||||||
// 传入的是 Model
|
// 传入的是 Model
|
||||||
this.model = modelOrProvider
|
this.model = modelOrProvider
|
||||||
this.actualProvider = provider ? adaptProvider({ provider }) : getActualProvider(modelOrProvider)
|
this.actualProvider = provider || getActualProvider(modelOrProvider)
|
||||||
// 只保存配置,不预先创建executor
|
// 只保存配置,不预先创建executor
|
||||||
this.config = providerToAiSdkConfig(this.actualProvider, modelOrProvider)
|
this.config = providerToAiSdkConfig(this.actualProvider, modelOrProvider)
|
||||||
} else {
|
} else {
|
||||||
// 传入的是 Provider
|
// 传入的是 Provider
|
||||||
this.actualProvider = adaptProvider({ provider: modelOrProvider })
|
this.actualProvider = modelOrProvider
|
||||||
// model为可选,某些操作(如fetchModels)不需要model
|
// model为可选,某些操作(如fetchModels)不需要model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { OpenAIAPIClient } from './openai/OpenAIApiClient'
|
|||||||
import { OpenAIResponseAPIClient } from './openai/OpenAIResponseAPIClient'
|
import { OpenAIResponseAPIClient } from './openai/OpenAIResponseAPIClient'
|
||||||
import { OVMSClient } from './ovms/OVMSClient'
|
import { OVMSClient } from './ovms/OVMSClient'
|
||||||
import { PPIOAPIClient } from './ppio/PPIOAPIClient'
|
import { PPIOAPIClient } from './ppio/PPIOAPIClient'
|
||||||
|
import { VolcengineAPIClient } from './volcengine/VolcengineAPIClient'
|
||||||
import { ZhipuAPIClient } from './zhipu/ZhipuAPIClient'
|
import { ZhipuAPIClient } from './zhipu/ZhipuAPIClient'
|
||||||
|
|
||||||
const logger = loggerService.withContext('ApiClientFactory')
|
const logger = loggerService.withContext('ApiClientFactory')
|
||||||
@@ -64,6 +65,12 @@ export class ApiClientFactory {
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (provider.id === 'doubao') {
|
||||||
|
logger.debug(`Creating VolcengineAPIClient for provider: ${provider.id}`)
|
||||||
|
instance = new VolcengineAPIClient(provider) as BaseApiClient
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
if (provider.id === 'ovms') {
|
if (provider.id === 'ovms') {
|
||||||
logger.debug(`Creating OVMSClient for provider: ${provider.id}`)
|
logger.debug(`Creating OVMSClient for provider: ${provider.id}`)
|
||||||
instance = new OVMSClient(provider) as BaseApiClient
|
instance = new OVMSClient(provider) as BaseApiClient
|
||||||
|
|||||||
@@ -405,9 +405,6 @@ export abstract class BaseApiClient<
|
|||||||
if (!param.name?.trim()) {
|
if (!param.name?.trim()) {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
// Parse JSON type parameters (Legacy API clients)
|
|
||||||
// Related: src/renderer/src/pages/settings/AssistantSettings/AssistantModelSettings.tsx:133-148
|
|
||||||
// The UI stores JSON type params as strings, this function parses them before sending to API
|
|
||||||
if (param.type === 'json') {
|
if (param.type === 'json') {
|
||||||
const value = param.value as string
|
const value = param.value as string
|
||||||
if (value === 'undefined') {
|
if (value === 'undefined') {
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import type {
|
|||||||
GeminiSdkRawOutput,
|
GeminiSdkRawOutput,
|
||||||
GeminiSdkToolCall
|
GeminiSdkToolCall
|
||||||
} from '@renderer/types/sdk'
|
} from '@renderer/types/sdk'
|
||||||
import { getTrailingApiVersion, withoutTrailingApiVersion } from '@renderer/utils'
|
|
||||||
import { isToolUseModeFunction } from '@renderer/utils/assistant'
|
import { isToolUseModeFunction } from '@renderer/utils/assistant'
|
||||||
import {
|
import {
|
||||||
geminiFunctionCallToMcpTool,
|
geminiFunctionCallToMcpTool,
|
||||||
@@ -164,10 +163,6 @@ export class GeminiAPIClient extends BaseApiClient<
|
|||||||
return models
|
return models
|
||||||
}
|
}
|
||||||
|
|
||||||
override getBaseURL(): string {
|
|
||||||
return withoutTrailingApiVersion(super.getBaseURL())
|
|
||||||
}
|
|
||||||
|
|
||||||
override async getSdkInstance() {
|
override async getSdkInstance() {
|
||||||
if (this.sdkInstance) {
|
if (this.sdkInstance) {
|
||||||
return this.sdkInstance
|
return this.sdkInstance
|
||||||
@@ -193,13 +188,6 @@ export class GeminiAPIClient extends BaseApiClient<
|
|||||||
if (this.provider.isVertex) {
|
if (this.provider.isVertex) {
|
||||||
return 'v1'
|
return 'v1'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract trailing API version from the URL
|
|
||||||
const trailingVersion = getTrailingApiVersion(this.provider.apiHost || '')
|
|
||||||
if (trailingVersion) {
|
|
||||||
return trailingVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'v1beta'
|
return 'v1beta'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import type OpenAI from '@cherrystudio/openai'
|
||||||
|
import { loggerService } from '@logger'
|
||||||
|
import { getVolcengineProjectName, getVolcengineRegion } from '@renderer/hooks/useVolcengine'
|
||||||
|
import type { Provider } from '@renderer/types'
|
||||||
|
|
||||||
|
import { OpenAIAPIClient } from '../openai/OpenAIApiClient'
|
||||||
|
|
||||||
|
const logger = loggerService.withContext('VolcengineAPIClient')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volcengine (Doubao) API Client
|
||||||
|
*
|
||||||
|
* Extends OpenAIAPIClient for standard chat completions (OpenAI-compatible),
|
||||||
|
* but overrides listModels to use Volcengine's signed API via IPC.
|
||||||
|
*/
|
||||||
|
export class VolcengineAPIClient extends OpenAIAPIClient {
|
||||||
|
constructor(provider: Provider) {
|
||||||
|
super(provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List models using Volcengine's signed API
|
||||||
|
* This calls the main process VolcengineService which handles HMAC-SHA256 signing
|
||||||
|
*/
|
||||||
|
override async listModels(): Promise<OpenAI.Models.Model[]> {
|
||||||
|
try {
|
||||||
|
const hasCredentials = await window.api.volcengine.hasCredentials()
|
||||||
|
|
||||||
|
if (!hasCredentials) {
|
||||||
|
logger.info('Volcengine credentials not configured, falling back to OpenAI-compatible list')
|
||||||
|
// Fall back to standard OpenAI-compatible API if no Volcengine credentials
|
||||||
|
return super.listModels()
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info('Fetching models from Volcengine API using signed request')
|
||||||
|
|
||||||
|
const projectName = getVolcengineProjectName()
|
||||||
|
const region = getVolcengineRegion()
|
||||||
|
const response = await window.api.volcengine.listModels(projectName, region)
|
||||||
|
|
||||||
|
if (!response || !response.models) {
|
||||||
|
logger.warn('Empty response from Volcengine listModels')
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify user of any partial failures
|
||||||
|
if (response.warnings && response.warnings.length > 0) {
|
||||||
|
for (const warning of response.warnings) {
|
||||||
|
logger.warn(warning)
|
||||||
|
}
|
||||||
|
window.toast?.warning('Some Volcengine models could not be fetched. Check logs for details.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const models: OpenAI.Models.Model[] = response.models.map((model) => ({
|
||||||
|
id: model.id,
|
||||||
|
object: 'model' as const,
|
||||||
|
created: model.created || Math.floor(Date.now() / 1000),
|
||||||
|
owned_by: 'volcengine',
|
||||||
|
// @ts-ignore - description is used by UI to display model name
|
||||||
|
name: model.name || model.id
|
||||||
|
}))
|
||||||
|
|
||||||
|
logger.info(`Found ${models.length} models from Volcengine API`)
|
||||||
|
return models
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to list Volcengine models:', error as Error)
|
||||||
|
// Notify user before falling back
|
||||||
|
window.toast?.warning('Failed to fetch Volcengine models. Check credentials if this persists.')
|
||||||
|
// Fall back to standard OpenAI-compatible API on error
|
||||||
|
logger.info('Falling back to OpenAI-compatible model list')
|
||||||
|
return super.listModels()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import { isAwsBedrockProvider, isVertexProvider } from '@renderer/utils/provider
|
|||||||
// https://docs.claude.com/en/docs/build-with-claude/extended-thinking#interleaved-thinking
|
// https://docs.claude.com/en/docs/build-with-claude/extended-thinking#interleaved-thinking
|
||||||
const INTERLEAVED_THINKING_HEADER = 'interleaved-thinking-2025-05-14'
|
const INTERLEAVED_THINKING_HEADER = 'interleaved-thinking-2025-05-14'
|
||||||
// https://docs.claude.com/en/docs/build-with-claude/context-windows#1m-token-context-window
|
// https://docs.claude.com/en/docs/build-with-claude/context-windows#1m-token-context-window
|
||||||
// const CONTEXT_100M_HEADER = 'context-1m-2025-08-07'
|
const CONTEXT_100M_HEADER = 'context-1m-2025-08-07'
|
||||||
// https://docs.cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude/web-search
|
// https://docs.cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude/web-search
|
||||||
const WEBSEARCH_HEADER = 'web-search-2025-03-05'
|
const WEBSEARCH_HEADER = 'web-search-2025-03-05'
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export function addAnthropicHeaders(assistant: Assistant, model: Model): string[
|
|||||||
if (
|
if (
|
||||||
isClaude45ReasoningModel(model) &&
|
isClaude45ReasoningModel(model) &&
|
||||||
isToolUseModeFunction(assistant) &&
|
isToolUseModeFunction(assistant) &&
|
||||||
!(isVertexProvider(provider) || isAwsBedrockProvider(provider))
|
!(isVertexProvider(provider) && isAwsBedrockProvider(provider))
|
||||||
) {
|
) {
|
||||||
anthropicHeaders.push(INTERLEAVED_THINKING_HEADER)
|
anthropicHeaders.push(INTERLEAVED_THINKING_HEADER)
|
||||||
}
|
}
|
||||||
@@ -25,9 +25,7 @@ export function addAnthropicHeaders(assistant: Assistant, model: Model): string[
|
|||||||
if (isVertexProvider(provider) && assistant.enableWebSearch) {
|
if (isVertexProvider(provider) && assistant.enableWebSearch) {
|
||||||
anthropicHeaders.push(WEBSEARCH_HEADER)
|
anthropicHeaders.push(WEBSEARCH_HEADER)
|
||||||
}
|
}
|
||||||
// We may add it by user preference in assistant.settings instead of always adding it.
|
anthropicHeaders.push(CONTEXT_100M_HEADER)
|
||||||
// See #11540, #11397
|
|
||||||
// anthropicHeaders.push(CONTEXT_100M_HEADER)
|
|
||||||
}
|
}
|
||||||
return anthropicHeaders
|
return anthropicHeaders
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import { type Assistant, type MCPTool, type Provider } from '@renderer/types'
|
|||||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||||
import { mapRegexToPatterns } from '@renderer/utils/blacklistMatchPattern'
|
import { mapRegexToPatterns } from '@renderer/utils/blacklistMatchPattern'
|
||||||
import { replacePromptVariables } from '@renderer/utils/prompt'
|
import { replacePromptVariables } from '@renderer/utils/prompt'
|
||||||
import { isAwsBedrockProvider } from '@renderer/utils/provider'
|
|
||||||
import type { ModelMessage, Tool } from 'ai'
|
import type { ModelMessage, Tool } from 'ai'
|
||||||
import { stepCountIs } from 'ai'
|
import { stepCountIs } from 'ai'
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ export async function buildStreamTextParams(
|
|||||||
|
|
||||||
let headers: Record<string, string | undefined> = options.requestOptions?.headers ?? {}
|
let headers: Record<string, string | undefined> = options.requestOptions?.headers ?? {}
|
||||||
|
|
||||||
if (isAnthropicModel(model) && !isAwsBedrockProvider(provider)) {
|
if (isAnthropicModel(model)) {
|
||||||
const newBetaHeaders = { 'anthropic-beta': addAnthropicHeaders(assistant, model).join(',') }
|
const newBetaHeaders = { 'anthropic-beta': addAnthropicHeaders(assistant, model).join(',') }
|
||||||
headers = combineHeaders(headers, newBetaHeaders)
|
headers = combineHeaders(headers, newBetaHeaders)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Model, Provider } from '@renderer/types'
|
import type { Provider } from '@renderer/types'
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import { getAiSdkProviderId } from '../factory'
|
import { getAiSdkProviderId } from '../factory'
|
||||||
@@ -68,18 +68,6 @@ function createTestProvider(id: string, type: string): Provider {
|
|||||||
} as Provider
|
} as Provider
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAzureProvider(id: string, apiVersion?: string, model?: string): Provider {
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
type: 'azure-openai',
|
|
||||||
name: `Azure Test ${id}`,
|
|
||||||
apiKey: 'azure-test-key',
|
|
||||||
apiHost: 'azure-test-host',
|
|
||||||
apiVersion,
|
|
||||||
models: [{ id: model || 'gpt-4' } as Model]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Integrated Provider Registry', () => {
|
describe('Integrated Provider Registry', () => {
|
||||||
describe('Provider ID Resolution', () => {
|
describe('Provider ID Resolution', () => {
|
||||||
it('should resolve openrouter provider correctly', () => {
|
it('should resolve openrouter provider correctly', () => {
|
||||||
@@ -123,24 +111,6 @@ describe('Integrated Provider Registry', () => {
|
|||||||
const result = getAiSdkProviderId(unknownProvider)
|
const result = getAiSdkProviderId(unknownProvider)
|
||||||
expect(result).toBe('unknown-provider')
|
expect(result).toBe('unknown-provider')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle Azure OpenAI providers correctly', () => {
|
|
||||||
const azureProvider = createAzureProvider('azure-test', '2024-02-15', 'gpt-4o')
|
|
||||||
const result = getAiSdkProviderId(azureProvider)
|
|
||||||
expect(result).toBe('azure')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle Azure OpenAI providers response endpoint correctly', () => {
|
|
||||||
const azureProvider = createAzureProvider('azure-test', 'v1', 'gpt-4o')
|
|
||||||
const result = getAiSdkProviderId(azureProvider)
|
|
||||||
expect(result).toBe('azure-responses')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handle Azure provider Claude Models', () => {
|
|
||||||
const provider = createTestProvider('azure-anthropic', 'anthropic')
|
|
||||||
const result = getAiSdkProviderId(provider)
|
|
||||||
expect(result).toBe('azure-anthropic')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Backward Compatibility', () => {
|
describe('Backward Compatibility', () => {
|
||||||
|
|||||||
@@ -78,13 +78,11 @@ function handleSpecialProviders(model: Model, provider: Provider): Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format and normalize the API host URL for a provider.
|
* 主要用来对齐AISdk的BaseURL格式
|
||||||
* Handles provider-specific URL formatting rules (e.g., appending version paths, Azure formatting).
|
* @param provider
|
||||||
*
|
* @returns
|
||||||
* @param provider - The provider whose API host is to be formatted.
|
|
||||||
* @returns A new provider instance with the formatted API host.
|
|
||||||
*/
|
*/
|
||||||
export function formatProviderApiHost(provider: Provider): Provider {
|
function formatProviderApiHost(provider: Provider): Provider {
|
||||||
const formatted = { ...provider }
|
const formatted = { ...provider }
|
||||||
if (formatted.anthropicApiHost) {
|
if (formatted.anthropicApiHost) {
|
||||||
formatted.anthropicApiHost = formatApiHost(formatted.anthropicApiHost)
|
formatted.anthropicApiHost = formatApiHost(formatted.anthropicApiHost)
|
||||||
@@ -116,38 +114,18 @@ export function formatProviderApiHost(provider: Provider): Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the effective Provider configuration for the given model.
|
* 获取实际的Provider配置
|
||||||
* Applies all necessary transformations (special-provider handling, URL formatting, etc.).
|
* 简化版:将逻辑分解为小函数
|
||||||
*
|
|
||||||
* @param model - The model whose provider is to be resolved.
|
|
||||||
* @returns A new Provider instance with all adaptations applied.
|
|
||||||
*/
|
*/
|
||||||
export function getActualProvider(model: Model): Provider {
|
export function getActualProvider(model: Model): Provider {
|
||||||
const baseProvider = getProviderByModel(model)
|
const baseProvider = getProviderByModel(model)
|
||||||
|
|
||||||
return adaptProvider({ provider: baseProvider, model })
|
// 按顺序处理各种转换
|
||||||
}
|
let actualProvider = cloneDeep(baseProvider)
|
||||||
|
actualProvider = handleSpecialProviders(model, actualProvider)
|
||||||
|
actualProvider = formatProviderApiHost(actualProvider)
|
||||||
|
|
||||||
/**
|
return actualProvider
|
||||||
* Transforms a provider configuration by applying model-specific adaptations and normalizing its API host.
|
|
||||||
* The transformations are applied in the following order:
|
|
||||||
* 1. Model-specific provider handling (e.g., New-API, system providers, Azure OpenAI)
|
|
||||||
* 2. API host formatting (provider-specific URL normalization)
|
|
||||||
*
|
|
||||||
* @param provider - The base provider configuration to transform.
|
|
||||||
* @param model - The model associated with the provider; optional but required for special-provider handling.
|
|
||||||
* @returns A new Provider instance with all transformations applied.
|
|
||||||
*/
|
|
||||||
export function adaptProvider({ provider, model }: { provider: Provider; model?: Model }): Provider {
|
|
||||||
let adaptedProvider = cloneDeep(provider)
|
|
||||||
|
|
||||||
// Apply transformations in order
|
|
||||||
if (model) {
|
|
||||||
adaptedProvider = handleSpecialProviders(model, adaptedProvider)
|
|
||||||
}
|
|
||||||
adaptedProvider = formatProviderApiHost(adaptedProvider)
|
|
||||||
|
|
||||||
return adaptedProvider
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ export class AiSdkSpanAdapter {
|
|||||||
'gen_ai.usage.output_tokens'
|
'gen_ai.usage.output_tokens'
|
||||||
]
|
]
|
||||||
|
|
||||||
const promptTokens = attributes[inputsTokenKeys.find((key) => attributes[key]) || '']
|
const completionTokens = attributes[inputsTokenKeys.find((key) => attributes[key]) || '']
|
||||||
const completionTokens = attributes[outputTokenKeys.find((key) => attributes[key]) || '']
|
const promptTokens = attributes[outputTokenKeys.find((key) => attributes[key]) || '']
|
||||||
|
|
||||||
if (completionTokens !== undefined || promptTokens !== undefined) {
|
if (completionTokens !== undefined || promptTokens !== undefined) {
|
||||||
const usage: TokenUsage = {
|
const usage: TokenUsage = {
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import type { Span } from '@opentelemetry/api'
|
|
||||||
import { SpanKind, SpanStatusCode } from '@opentelemetry/api'
|
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
|
||||||
|
|
||||||
import { AiSdkSpanAdapter } from '../AiSdkSpanAdapter'
|
|
||||||
|
|
||||||
vi.mock('@logger', () => ({
|
|
||||||
loggerService: {
|
|
||||||
withContext: () => ({
|
|
||||||
debug: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
info: vi.fn(),
|
|
||||||
warn: vi.fn()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe('AiSdkSpanAdapter', () => {
|
|
||||||
const createMockSpan = (attributes: Record<string, unknown>): Span => {
|
|
||||||
const span = {
|
|
||||||
spanContext: () => ({
|
|
||||||
traceId: 'trace-id',
|
|
||||||
spanId: 'span-id'
|
|
||||||
}),
|
|
||||||
_attributes: attributes,
|
|
||||||
_events: [],
|
|
||||||
name: 'test span',
|
|
||||||
status: { code: SpanStatusCode.OK },
|
|
||||||
kind: SpanKind.CLIENT,
|
|
||||||
startTime: [0, 0] as [number, number],
|
|
||||||
endTime: [0, 1] as [number, number],
|
|
||||||
ended: true,
|
|
||||||
parentSpanId: '',
|
|
||||||
links: []
|
|
||||||
}
|
|
||||||
return span as unknown as Span
|
|
||||||
}
|
|
||||||
|
|
||||||
it('maps prompt and completion usage tokens to the correct fields', () => {
|
|
||||||
const attributes = {
|
|
||||||
'ai.usage.promptTokens': 321,
|
|
||||||
'ai.usage.completionTokens': 654
|
|
||||||
}
|
|
||||||
|
|
||||||
const span = createMockSpan(attributes)
|
|
||||||
const result = AiSdkSpanAdapter.convertToSpanEntity({ span })
|
|
||||||
|
|
||||||
expect(result.usage).toBeDefined()
|
|
||||||
expect(result.usage?.prompt_tokens).toBe(321)
|
|
||||||
expect(result.usage?.completion_tokens).toBe(654)
|
|
||||||
expect(result.usage?.total_tokens).toBe(975)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -71,11 +71,10 @@ describe('mcp utils', () => {
|
|||||||
const result = setupToolsConfig(mcpTools)
|
const result = setupToolsConfig(mcpTools)
|
||||||
|
|
||||||
expect(result).not.toBeUndefined()
|
expect(result).not.toBeUndefined()
|
||||||
// Tools are now keyed by id (which includes serverId suffix) for uniqueness
|
expect(Object.keys(result!)).toEqual(['test-tool'])
|
||||||
expect(Object.keys(result!)).toEqual(['test-tool-1'])
|
expect(result!['test-tool']).toHaveProperty('description')
|
||||||
expect(result!['test-tool-1']).toHaveProperty('description')
|
expect(result!['test-tool']).toHaveProperty('inputSchema')
|
||||||
expect(result!['test-tool-1']).toHaveProperty('inputSchema')
|
expect(result!['test-tool']).toHaveProperty('execute')
|
||||||
expect(result!['test-tool-1']).toHaveProperty('execute')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle multiple MCP tools', () => {
|
it('should handle multiple MCP tools', () => {
|
||||||
@@ -110,8 +109,7 @@ describe('mcp utils', () => {
|
|||||||
|
|
||||||
expect(result).not.toBeUndefined()
|
expect(result).not.toBeUndefined()
|
||||||
expect(Object.keys(result!)).toHaveLength(2)
|
expect(Object.keys(result!)).toHaveLength(2)
|
||||||
// Tools are keyed by id for uniqueness
|
expect(Object.keys(result!)).toEqual(['tool1', 'tool2'])
|
||||||
expect(Object.keys(result!)).toEqual(['tool1-id', 'tool2-id'])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -137,10 +135,9 @@ describe('mcp utils', () => {
|
|||||||
|
|
||||||
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
|
|
||||||
// Tools are keyed by id for uniqueness when multiple server instances exist
|
expect(Object.keys(result)).toEqual(['get-weather'])
|
||||||
expect(Object.keys(result)).toEqual(['get-weather-id'])
|
|
||||||
|
|
||||||
const tool = result['get-weather-id'] as Tool
|
const tool = result['get-weather'] as Tool
|
||||||
expect(tool.description).toBe('Get weather information')
|
expect(tool.description).toBe('Get weather information')
|
||||||
expect(tool.inputSchema).toBeDefined()
|
expect(tool.inputSchema).toBeDefined()
|
||||||
expect(typeof tool.execute).toBe('function')
|
expect(typeof tool.execute).toBe('function')
|
||||||
@@ -163,8 +160,8 @@ describe('mcp utils', () => {
|
|||||||
|
|
||||||
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
|
|
||||||
expect(Object.keys(result)).toEqual(['no-desc-tool-id'])
|
expect(Object.keys(result)).toEqual(['no-desc-tool'])
|
||||||
const tool = result['no-desc-tool-id'] as Tool
|
const tool = result['no-desc-tool'] as Tool
|
||||||
expect(tool.description).toBe('Tool from test-server')
|
expect(tool.description).toBe('Tool from test-server')
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -205,13 +202,13 @@ describe('mcp utils', () => {
|
|||||||
|
|
||||||
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
|
|
||||||
expect(Object.keys(result)).toEqual(['complex-tool-id'])
|
expect(Object.keys(result)).toEqual(['complex-tool'])
|
||||||
const tool = result['complex-tool-id'] as Tool
|
const tool = result['complex-tool'] as Tool
|
||||||
expect(tool.inputSchema).toBeDefined()
|
expect(tool.inputSchema).toBeDefined()
|
||||||
expect(typeof tool.execute).toBe('function')
|
expect(typeof tool.execute).toBe('function')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should preserve tool id with special characters', () => {
|
it('should preserve tool names with special characters', () => {
|
||||||
const mcpTools: MCPTool[] = [
|
const mcpTools: MCPTool[] = [
|
||||||
{
|
{
|
||||||
id: 'special-tool-id',
|
id: 'special-tool-id',
|
||||||
@@ -228,8 +225,7 @@ describe('mcp utils', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
// Tools are keyed by id for uniqueness
|
expect(Object.keys(result)).toEqual(['tool_with-special.chars'])
|
||||||
expect(Object.keys(result)).toEqual(['special-tool-id'])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle multiple tools with different schemas', () => {
|
it('should handle multiple tools with different schemas', () => {
|
||||||
@@ -280,11 +276,10 @@ describe('mcp utils', () => {
|
|||||||
|
|
||||||
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
const result = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
|
|
||||||
// Tools are keyed by id for uniqueness
|
expect(Object.keys(result).sort()).toEqual(['boolean-tool', 'number-tool', 'string-tool'])
|
||||||
expect(Object.keys(result).sort()).toEqual(['boolean-tool-id', 'number-tool-id', 'string-tool-id'])
|
expect(result['string-tool']).toBeDefined()
|
||||||
expect(result['string-tool-id']).toBeDefined()
|
expect(result['number-tool']).toBeDefined()
|
||||||
expect(result['number-tool-id']).toBeDefined()
|
expect(result['boolean-tool']).toBeDefined()
|
||||||
expect(result['boolean-tool-id']).toBeDefined()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -315,7 +310,7 @@ describe('mcp utils', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
const tool = tools['test-exec-tool-id'] as Tool
|
const tool = tools['test-exec-tool'] as Tool
|
||||||
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'test-call-123' })
|
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'test-call-123' })
|
||||||
|
|
||||||
expect(requestToolConfirmation).toHaveBeenCalled()
|
expect(requestToolConfirmation).toHaveBeenCalled()
|
||||||
@@ -348,7 +343,7 @@ describe('mcp utils', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
const tool = tools['cancelled-tool-id'] as Tool
|
const tool = tools['cancelled-tool'] as Tool
|
||||||
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'cancel-call-123' })
|
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'cancel-call-123' })
|
||||||
|
|
||||||
expect(requestToolConfirmation).toHaveBeenCalled()
|
expect(requestToolConfirmation).toHaveBeenCalled()
|
||||||
@@ -390,7 +385,7 @@ describe('mcp utils', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
const tool = tools['error-tool-id'] as Tool
|
const tool = tools['error-tool'] as Tool
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'error-call-123' })
|
tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'error-call-123' })
|
||||||
@@ -426,7 +421,7 @@ describe('mcp utils', () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
const tools = convertMcpToolsToAiSdkTools(mcpTools)
|
||||||
const tool = tools['auto-approve-tool-id'] as Tool
|
const tool = tools['auto-approve-tool'] as Tool
|
||||||
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'auto-call-123' })
|
const result = await tool.execute!({}, { messages: [], abortSignal: undefined, toolCallId: 'auto-call-123' })
|
||||||
|
|
||||||
expect(requestToolConfirmation).not.toHaveBeenCalled()
|
expect(requestToolConfirmation).not.toHaveBeenCalled()
|
||||||
|
|||||||
@@ -154,10 +154,6 @@ vi.mock('../websearch', () => ({
|
|||||||
getWebSearchParams: vi.fn(() => ({ enable_search: true }))
|
getWebSearchParams: vi.fn(() => ({ enable_search: true }))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('../../prepareParams/header', () => ({
|
|
||||||
addAnthropicHeaders: vi.fn(() => ['context-1m-2025-08-07'])
|
|
||||||
}))
|
|
||||||
|
|
||||||
const ensureWindowApi = () => {
|
const ensureWindowApi = () => {
|
||||||
const globalWindow = window as any
|
const globalWindow = window as any
|
||||||
globalWindow.api = globalWindow.api || {}
|
globalWindow.api = globalWindow.api || {}
|
||||||
@@ -637,64 +633,5 @@ describe('options utils', () => {
|
|||||||
expect(result.providerOptions).toHaveProperty('anthropic')
|
expect(result.providerOptions).toHaveProperty('anthropic')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('AWS Bedrock provider', () => {
|
|
||||||
const bedrockProvider = {
|
|
||||||
id: 'bedrock',
|
|
||||||
name: 'AWS Bedrock',
|
|
||||||
type: 'aws-bedrock',
|
|
||||||
apiKey: 'test-key',
|
|
||||||
apiHost: 'https://bedrock.us-east-1.amazonaws.com',
|
|
||||||
models: [] as Model[]
|
|
||||||
} as Provider
|
|
||||||
|
|
||||||
const bedrockModel: Model = {
|
|
||||||
id: 'anthropic.claude-sonnet-4-20250514-v1:0',
|
|
||||||
name: 'Claude Sonnet 4',
|
|
||||||
provider: 'bedrock'
|
|
||||||
} as Model
|
|
||||||
|
|
||||||
it('should build basic Bedrock options', () => {
|
|
||||||
const result = buildProviderOptions(mockAssistant, bedrockModel, bedrockProvider, {
|
|
||||||
enableReasoning: false,
|
|
||||||
enableWebSearch: false,
|
|
||||||
enableGenerateImage: false
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.providerOptions).toHaveProperty('bedrock')
|
|
||||||
expect(result.providerOptions.bedrock).toBeDefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should include anthropicBeta when Anthropic headers are needed', async () => {
|
|
||||||
const { addAnthropicHeaders } = await import('../../prepareParams/header')
|
|
||||||
vi.mocked(addAnthropicHeaders).mockReturnValue(['interleaved-thinking-2025-05-14', 'context-1m-2025-08-07'])
|
|
||||||
|
|
||||||
const result = buildProviderOptions(mockAssistant, bedrockModel, bedrockProvider, {
|
|
||||||
enableReasoning: false,
|
|
||||||
enableWebSearch: false,
|
|
||||||
enableGenerateImage: false
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.providerOptions.bedrock).toHaveProperty('anthropicBeta')
|
|
||||||
expect(result.providerOptions.bedrock.anthropicBeta).toEqual([
|
|
||||||
'interleaved-thinking-2025-05-14',
|
|
||||||
'context-1m-2025-08-07'
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should include reasoning parameters when enabled', () => {
|
|
||||||
const result = buildProviderOptions(mockAssistant, bedrockModel, bedrockProvider, {
|
|
||||||
enableReasoning: true,
|
|
||||||
enableWebSearch: false,
|
|
||||||
enableGenerateImage: false
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.providerOptions.bedrock).toHaveProperty('reasoningConfig')
|
|
||||||
expect(result.providerOptions.bedrock.reasoningConfig).toEqual({
|
|
||||||
type: 'enabled',
|
|
||||||
budgetTokens: 5000
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ describe('reasoning utils', () => {
|
|||||||
expect(result).toEqual({})
|
expect(result).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not override reasoning for OpenRouter when reasoning effort undefined', async () => {
|
it('should disable reasoning for OpenRouter when no reasoning effort set', async () => {
|
||||||
const { isReasoningModel } = await import('@renderer/config/models')
|
const { isReasoningModel } = await import('@renderer/config/models')
|
||||||
|
|
||||||
vi.mocked(isReasoningModel).mockReturnValue(true)
|
vi.mocked(isReasoningModel).mockReturnValue(true)
|
||||||
@@ -161,29 +161,6 @@ describe('reasoning utils', () => {
|
|||||||
settings: {}
|
settings: {}
|
||||||
} as Assistant
|
} as Assistant
|
||||||
|
|
||||||
const result = getReasoningEffort(assistant, model)
|
|
||||||
expect(result).toEqual({})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should disable reasoning for OpenRouter when reasoning effort explicitly none', async () => {
|
|
||||||
const { isReasoningModel } = await import('@renderer/config/models')
|
|
||||||
|
|
||||||
vi.mocked(isReasoningModel).mockReturnValue(true)
|
|
||||||
|
|
||||||
const model: Model = {
|
|
||||||
id: 'anthropic/claude-sonnet-4',
|
|
||||||
name: 'Claude Sonnet 4',
|
|
||||||
provider: SystemProviderIds.openrouter
|
|
||||||
} as Model
|
|
||||||
|
|
||||||
const assistant: Assistant = {
|
|
||||||
id: 'test',
|
|
||||||
name: 'Test',
|
|
||||||
settings: {
|
|
||||||
reasoning_effort: 'none'
|
|
||||||
}
|
|
||||||
} as Assistant
|
|
||||||
|
|
||||||
const result = getReasoningEffort(assistant, model)
|
const result = getReasoningEffort(assistant, model)
|
||||||
expect(result).toEqual({ reasoning: { enabled: false, exclude: true } })
|
expect(result).toEqual({ reasoning: { enabled: false, exclude: true } })
|
||||||
})
|
})
|
||||||
@@ -292,9 +269,7 @@ describe('reasoning utils', () => {
|
|||||||
const assistant: Assistant = {
|
const assistant: Assistant = {
|
||||||
id: 'test',
|
id: 'test',
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
settings: {
|
settings: {}
|
||||||
reasoning_effort: 'none'
|
|
||||||
}
|
|
||||||
} as Assistant
|
} as Assistant
|
||||||
|
|
||||||
const result = getReasoningEffort(assistant, model)
|
const result = getReasoningEffort(assistant, model)
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ export function convertMcpToolsToAiSdkTools(mcpTools: MCPTool[]): ToolSet {
|
|||||||
const tools: ToolSet = {}
|
const tools: ToolSet = {}
|
||||||
|
|
||||||
for (const mcpTool of mcpTools) {
|
for (const mcpTool of mcpTools) {
|
||||||
// Use mcpTool.id (which includes serverId suffix) to ensure uniqueness
|
tools[mcpTool.name] = tool({
|
||||||
// when multiple instances of the same MCP server type are configured
|
|
||||||
tools[mcpTool.id] = tool({
|
|
||||||
description: mcpTool.description || `Tool from ${mcpTool.serverName}`,
|
description: mcpTool.description || `Tool from ${mcpTool.serverName}`,
|
||||||
inputSchema: jsonSchema(mcpTool.inputSchema as JSONSchema7),
|
inputSchema: jsonSchema(mcpTool.inputSchema as JSONSchema7),
|
||||||
execute: async (params, { toolCallId }) => {
|
execute: async (params, { toolCallId }) => {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import { isSupportServiceTierProvider, isSupportVerbosityProvider } from '@rende
|
|||||||
import type { JSONValue } from 'ai'
|
import type { JSONValue } from 'ai'
|
||||||
import { t } from 'i18next'
|
import { t } from 'i18next'
|
||||||
|
|
||||||
import { addAnthropicHeaders } from '../prepareParams/header'
|
|
||||||
import { getAiSdkProviderId } from '../provider/factory'
|
import { getAiSdkProviderId } from '../provider/factory'
|
||||||
import { buildGeminiGenerateImageParams } from './image'
|
import { buildGeminiGenerateImageParams } from './image'
|
||||||
import {
|
import {
|
||||||
@@ -470,11 +469,6 @@ function buildBedrockProviderOptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const betaHeaders = addAnthropicHeaders(assistant, model)
|
|
||||||
if (betaHeaders.length > 0) {
|
|
||||||
providerOptions.anthropicBeta = betaHeaders
|
|
||||||
}
|
|
||||||
|
|
||||||
return providerOptions
|
return providerOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import {
|
|||||||
isGPT5SeriesModel,
|
isGPT5SeriesModel,
|
||||||
isGPT51SeriesModel,
|
isGPT51SeriesModel,
|
||||||
isGrok4FastReasoningModel,
|
isGrok4FastReasoningModel,
|
||||||
|
isGrokReasoningModel,
|
||||||
isOpenAIDeepResearchModel,
|
isOpenAIDeepResearchModel,
|
||||||
isOpenAIModel,
|
isOpenAIModel,
|
||||||
|
isOpenAIReasoningModel,
|
||||||
isQwenAlwaysThinkModel,
|
isQwenAlwaysThinkModel,
|
||||||
isQwenReasoningModel,
|
isQwenReasoningModel,
|
||||||
isReasoningModel,
|
isReasoningModel,
|
||||||
@@ -62,22 +64,30 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
|||||||
}
|
}
|
||||||
const reasoningEffort = assistant?.settings?.reasoning_effort
|
const reasoningEffort = assistant?.settings?.reasoning_effort
|
||||||
|
|
||||||
// reasoningEffort is not set, no extra reasoning setting
|
// Handle undefined and 'none' reasoningEffort.
|
||||||
// Generally, for every model which supports reasoning control, the reasoning effort won't be undefined.
|
// TODO: They should be separated.
|
||||||
// It's for some reasoning models that don't support reasoning control, such as deepseek reasoner.
|
if (!reasoningEffort || reasoningEffort === 'none') {
|
||||||
if (!reasoningEffort) {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle 'none' reasoningEffort. It's explicitly off.
|
|
||||||
if (reasoningEffort === 'none') {
|
|
||||||
// openrouter: use reasoning
|
// openrouter: use reasoning
|
||||||
if (model.provider === SystemProviderIds.openrouter) {
|
if (model.provider === SystemProviderIds.openrouter) {
|
||||||
|
// Don't disable reasoning for Gemini models that support thinking tokens
|
||||||
|
if (isSupportedThinkingTokenGeminiModel(model) && !GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
// 'none' is not an available value for effort for now.
|
// 'none' is not an available value for effort for now.
|
||||||
// I think they should resolve this issue soon, so I'll just go ahead and use this value.
|
// I think they should resolve this issue soon, so I'll just go ahead and use this value.
|
||||||
if (isGPT51SeriesModel(model) && reasoningEffort === 'none') {
|
if (isGPT51SeriesModel(model) && reasoningEffort === 'none') {
|
||||||
return { reasoning: { effort: 'none' } }
|
return { reasoning: { effort: 'none' } }
|
||||||
}
|
}
|
||||||
|
// Don't disable reasoning for models that require it
|
||||||
|
if (
|
||||||
|
isGrokReasoningModel(model) ||
|
||||||
|
isOpenAIReasoningModel(model) ||
|
||||||
|
isQwenAlwaysThinkModel(model) ||
|
||||||
|
model.id.includes('seed-oss') ||
|
||||||
|
model.id.includes('minimax-m2')
|
||||||
|
) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
return { reasoning: { enabled: false, exclude: true } }
|
return { reasoning: { enabled: false, exclude: true } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +101,11 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
|||||||
return { enable_thinking: false }
|
return { enable_thinking: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// claude
|
||||||
|
if (isSupportedThinkingTokenClaudeModel(model)) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
// gemini
|
// gemini
|
||||||
if (isSupportedThinkingTokenGeminiModel(model)) {
|
if (isSupportedThinkingTokenGeminiModel(model)) {
|
||||||
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||||
@@ -103,10 +118,8 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.warn(`Model ${model.id} cannot disable reasoning. Fallback to empty reasoning param.`)
|
|
||||||
return {}
|
|
||||||
}
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use thinking, doubao, zhipu, etc.
|
// use thinking, doubao, zhipu, etc.
|
||||||
@@ -126,7 +139,6 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.warn(`Model ${model.id} doesn't match any disable reasoning behavior. Fallback to empty reasoning param.`)
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +293,6 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OpenRouter models, use reasoning
|
// OpenRouter models, use reasoning
|
||||||
// FIXME: duplicated openrouter handling. remove one
|
|
||||||
if (model.provider === SystemProviderIds.openrouter) {
|
if (model.provider === SystemProviderIds.openrouter) {
|
||||||
if (isSupportedReasoningEffortModel(model) || isSupportedThinkingTokenModel(model)) {
|
if (isSupportedReasoningEffortModel(model) || isSupportedThinkingTokenModel(model)) {
|
||||||
return {
|
return {
|
||||||
@@ -673,10 +684,6 @@ export function getCustomParameters(assistant: Assistant): Record<string, any> {
|
|||||||
if (!param.name?.trim()) {
|
if (!param.name?.trim()) {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
// Parse JSON type parameters
|
|
||||||
// Related: src/renderer/src/pages/settings/AssistantSettings/AssistantModelSettings.tsx:133-148
|
|
||||||
// The UI stores JSON type params as strings (e.g., '{"key":"value"}')
|
|
||||||
// This function parses them into objects before sending to the API
|
|
||||||
if (param.type === 'json') {
|
if (param.type === 'json') {
|
||||||
const value = param.value as string
|
const value = param.value as string
|
||||||
if (value === 'undefined') {
|
if (value === 'undefined') {
|
||||||
|
|||||||
@@ -215,10 +215,6 @@
|
|||||||
border-top: none !important;
|
border-top: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-collapse-header-text {
|
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ant-slider .ant-slider-handle::after {
|
.ant-slider .ant-slider-handle::after {
|
||||||
box-shadow: 0 1px 4px 0px rgb(128 128 128 / 50%) !important;
|
box-shadow: 0 1px 4px 0px rgb(128 128 128 / 50%) !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
import { loggerService } from '@logger'
|
import { loggerService } from '@logger'
|
||||||
import { download } from '@renderer/utils/download'
|
import { download } from '@renderer/utils/download'
|
||||||
import { convertImageToPng } from '@renderer/utils/image'
|
|
||||||
import type { ImageProps as AntImageProps } from 'antd'
|
import type { ImageProps as AntImageProps } from 'antd'
|
||||||
import { Dropdown, Image as AntImage, Space } from 'antd'
|
import { Dropdown, Image as AntImage, Space } from 'antd'
|
||||||
import { Base64 } from 'js-base64'
|
import { Base64 } from 'js-base64'
|
||||||
@@ -34,38 +33,39 @@ const ImageViewer: React.FC<ImageViewerProps> = ({ src, style, ...props }) => {
|
|||||||
// 复制图片到剪贴板
|
// 复制图片到剪贴板
|
||||||
const handleCopyImage = async (src: string) => {
|
const handleCopyImage = async (src: string) => {
|
||||||
try {
|
try {
|
||||||
let blob: Blob
|
|
||||||
|
|
||||||
if (src.startsWith('data:')) {
|
if (src.startsWith('data:')) {
|
||||||
// 处理 base64 格式的图片
|
// 处理 base64 格式的图片
|
||||||
const match = src.match(/^data:(image\/\w+);base64,(.+)$/)
|
const match = src.match(/^data:(image\/\w+);base64,(.+)$/)
|
||||||
if (!match) throw new Error('Invalid base64 image format')
|
if (!match) throw new Error('Invalid base64 image format')
|
||||||
const mimeType = match[1]
|
const mimeType = match[1]
|
||||||
const byteArray = Base64.toUint8Array(match[2])
|
const byteArray = Base64.toUint8Array(match[2])
|
||||||
blob = new Blob([byteArray], { type: mimeType })
|
const blob = new Blob([byteArray], { type: mimeType })
|
||||||
|
await navigator.clipboard.write([new ClipboardItem({ [mimeType]: blob })])
|
||||||
} else if (src.startsWith('file://')) {
|
} else if (src.startsWith('file://')) {
|
||||||
// 处理本地文件路径
|
// 处理本地文件路径
|
||||||
const bytes = await window.api.fs.read(src)
|
const bytes = await window.api.fs.read(src)
|
||||||
const mimeType = mime.getType(src) || 'application/octet-stream'
|
const mimeType = mime.getType(src) || 'application/octet-stream'
|
||||||
blob = new Blob([bytes], { type: mimeType })
|
const blob = new Blob([bytes], { type: mimeType })
|
||||||
|
await navigator.clipboard.write([
|
||||||
|
new ClipboardItem({
|
||||||
|
[mimeType]: blob
|
||||||
|
})
|
||||||
|
])
|
||||||
} else {
|
} else {
|
||||||
// 处理 URL 格式的图片
|
// 处理 URL 格式的图片
|
||||||
const response = await fetch(src)
|
const response = await fetch(src)
|
||||||
blob = await response.blob()
|
const blob = await response.blob()
|
||||||
|
|
||||||
|
await navigator.clipboard.write([
|
||||||
|
new ClipboardItem({
|
||||||
|
[blob.type]: blob
|
||||||
|
})
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一转换为 PNG 以确保兼容性(剪贴板 API 不支持 JPEG)
|
|
||||||
const pngBlob = await convertImageToPng(blob)
|
|
||||||
|
|
||||||
const item = new ClipboardItem({
|
|
||||||
'image/png': pngBlob
|
|
||||||
})
|
|
||||||
await navigator.clipboard.write([item])
|
|
||||||
|
|
||||||
window.toast.success(t('message.copy.success'))
|
window.toast.success(t('message.copy.success'))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = error as Error
|
logger.error('Failed to copy image:', error as Error)
|
||||||
logger.error(`Failed to copy image: ${err.message}`, { stack: err.stack })
|
|
||||||
window.toast.error(t('message.copy.failed'))
|
window.toast.error(t('message.copy.failed'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const PopupContainer: React.FC<Props> = ({ model, apiFilter, modelFilter, showTa
|
|||||||
const [_searchText, setSearchText] = useState('')
|
const [_searchText, setSearchText] = useState('')
|
||||||
const searchText = useDeferredValue(_searchText)
|
const searchText = useDeferredValue(_searchText)
|
||||||
const { models, isLoading } = useApiModels(apiFilter)
|
const { models, isLoading } = useApiModels(apiFilter)
|
||||||
const adaptedModels = useMemo(() => models.map((model) => apiModelAdapter(model)), [models])
|
const adaptedModels = models.map((model) => apiModelAdapter(model))
|
||||||
|
|
||||||
// 当前选中的模型ID
|
// 当前选中的模型ID
|
||||||
const currentModelId = model ? model.id : ''
|
const currentModelId = model ? model.id : ''
|
||||||
|
|||||||
@@ -309,14 +309,11 @@ describe('Ling Models', () => {
|
|||||||
describe('Claude & regional providers', () => {
|
describe('Claude & regional providers', () => {
|
||||||
it('identifies claude 4.5 variants', () => {
|
it('identifies claude 4.5 variants', () => {
|
||||||
expect(isClaude45ReasoningModel(createModel({ id: 'claude-sonnet-4.5-preview' }))).toBe(true)
|
expect(isClaude45ReasoningModel(createModel({ id: 'claude-sonnet-4.5-preview' }))).toBe(true)
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'claude-sonnet-4-5@20250929' }))).toBe(true)
|
|
||||||
expect(isClaude45ReasoningModel(createModel({ id: 'claude-3-sonnet' }))).toBe(false)
|
expect(isClaude45ReasoningModel(createModel({ id: 'claude-3-sonnet' }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('identifies claude 4 variants', () => {
|
it('identifies claude 4 variants', () => {
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'claude-opus-4' }))).toBe(true)
|
expect(isClaude4SeriesModel(createModel({ id: 'claude-opus-4' }))).toBe(true)
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'claude-sonnet-4@20250514' }))).toBe(true)
|
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'anthropic.claude-sonnet-4-20250514-v1:0' }))).toBe(true)
|
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'claude-4.2-sonnet-variant' }))).toBe(false)
|
expect(isClaude4SeriesModel(createModel({ id: 'claude-4.2-sonnet-variant' }))).toBe(false)
|
||||||
expect(isClaude4SeriesModel(createModel({ id: 'claude-3-haiku' }))).toBe(false)
|
expect(isClaude4SeriesModel(createModel({ id: 'claude-3-haiku' }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -125,371 +125,195 @@ describe('model utils', () => {
|
|||||||
openAIWebSearchOnlyMock.mockReturnValue(false)
|
openAIWebSearchOnlyMock.mockReturnValue(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('OpenAI model detection', () => {
|
it('detects OpenAI LLM models through reasoning and GPT prefix', () => {
|
||||||
describe('isOpenAILLMModel', () => {
|
expect(isOpenAILLMModel(undefined as unknown as Model)).toBe(false)
|
||||||
it('returns false for undefined model', () => {
|
expect(isOpenAILLMModel(createModel({ id: 'gpt-4o-image' }))).toBe(false)
|
||||||
expect(isOpenAILLMModel(undefined as unknown as Model)).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for image generation models', () => {
|
reasoningMock.mockReturnValueOnce(true)
|
||||||
expect(isOpenAILLMModel(createModel({ id: 'gpt-4o-image' }))).toBe(false)
|
expect(isOpenAILLMModel(createModel({ id: 'o1-preview' }))).toBe(true)
|
||||||
})
|
|
||||||
|
|
||||||
it('returns true for reasoning models', () => {
|
expect(isOpenAILLMModel(createModel({ id: 'GPT-5-turbo' }))).toBe(true)
|
||||||
reasoningMock.mockReturnValueOnce(true)
|
})
|
||||||
expect(isOpenAILLMModel(createModel({ id: 'o1-preview' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns true for GPT-prefixed models', () => {
|
it('detects OpenAI models via GPT prefix or reasoning support', () => {
|
||||||
expect(isOpenAILLMModel(createModel({ id: 'GPT-5-turbo' }))).toBe(true)
|
expect(isOpenAIModel(createModel({ id: 'gpt-4.1' }))).toBe(true)
|
||||||
})
|
reasoningMock.mockReturnValueOnce(true)
|
||||||
|
expect(isOpenAIModel(createModel({ id: 'o3' }))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('evaluates support for flex service tier and alias helper', () => {
|
||||||
|
expect(isSupportFlexServiceTierModel(createModel({ id: 'o3' }))).toBe(true)
|
||||||
|
expect(isSupportFlexServiceTierModel(createModel({ id: 'o3-mini' }))).toBe(false)
|
||||||
|
expect(isSupportFlexServiceTierModel(createModel({ id: 'o4-mini' }))).toBe(true)
|
||||||
|
expect(isSupportFlexServiceTierModel(createModel({ id: 'gpt-5-preview' }))).toBe(true)
|
||||||
|
expect(isSupportedFlexServiceTier(createModel({ id: 'gpt-4o' }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('detects verbosity support for GPT-5+ families', () => {
|
||||||
|
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5' }))).toBe(true)
|
||||||
|
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5-chat' }))).toBe(false)
|
||||||
|
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5.1-preview' }))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('limits verbosity controls for GPT-5 Pro models', () => {
|
||||||
|
const proModel = createModel({ id: 'gpt-5-pro' })
|
||||||
|
const previewModel = createModel({ id: 'gpt-5-preview' })
|
||||||
|
expect(getModelSupportedVerbosity(proModel)).toEqual([undefined, 'high'])
|
||||||
|
expect(getModelSupportedVerbosity(previewModel)).toEqual([undefined, 'low', 'medium', 'high'])
|
||||||
|
expect(isGPT5ProModel(proModel)).toBe(true)
|
||||||
|
expect(isGPT5ProModel(previewModel)).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('identifies OpenAI chat-completion-only models', () => {
|
||||||
|
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'gpt-4o-search-preview' }))).toBe(true)
|
||||||
|
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'o1-mini' }))).toBe(true)
|
||||||
|
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('filters unsupported OpenAI catalog entries', () => {
|
||||||
|
expect(isSupportedModel({ id: 'gpt-4', object: 'model' } as any)).toBe(true)
|
||||||
|
expect(isSupportedModel({ id: 'tts-1', object: 'model' } as any)).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calculates temperature/top-p support correctly', () => {
|
||||||
|
const model = createModel({ id: 'o1' })
|
||||||
|
reasoningMock.mockReturnValue(true)
|
||||||
|
expect(isNotSupportTemperatureAndTopP(model)).toBe(true)
|
||||||
|
|
||||||
|
const openWeight = createModel({ id: 'gpt-oss-debug' })
|
||||||
|
expect(isNotSupportTemperatureAndTopP(openWeight)).toBe(false)
|
||||||
|
|
||||||
|
const chatOnly = createModel({ id: 'o1-preview' })
|
||||||
|
reasoningMock.mockReturnValue(false)
|
||||||
|
expect(isNotSupportTemperatureAndTopP(chatOnly)).toBe(true)
|
||||||
|
|
||||||
|
const qwenMt = createModel({ id: 'qwen-mt-large', provider: 'aliyun' })
|
||||||
|
expect(isNotSupportTemperatureAndTopP(qwenMt)).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles gemma and gemini detections plus zhipu tagging', () => {
|
||||||
|
expect(isGemmaModel(createModel({ id: 'Gemma-3-27B' }))).toBe(true)
|
||||||
|
expect(isGemmaModel(createModel({ group: 'Gemma' }))).toBe(true)
|
||||||
|
expect(isGemmaModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
||||||
|
|
||||||
|
expect(isGeminiModel(createModel({ id: 'Gemini-2.0' }))).toBe(true)
|
||||||
|
|
||||||
|
expect(isZhipuModel(createModel({ provider: 'zhipu' }))).toBe(true)
|
||||||
|
expect(isZhipuModel(createModel({ provider: 'openai' }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('groups qwen models by prefix', () => {
|
||||||
|
const qwen = createModel({ id: 'Qwen-7B', provider: 'qwen', name: 'Qwen-7B' })
|
||||||
|
const qwenOmni = createModel({ id: 'qwen2.5-omni', name: 'qwen2.5-omni' })
|
||||||
|
const other = createModel({ id: 'deepseek-v3', group: 'DeepSeek' })
|
||||||
|
|
||||||
|
const grouped = groupQwenModels([qwen, qwenOmni, other])
|
||||||
|
expect(Object.keys(grouped)).toContain('qwen-7b')
|
||||||
|
expect(Object.keys(grouped)).toContain('qwen2.5')
|
||||||
|
expect(grouped.DeepSeek).toContain(other)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('aggregates boolean helpers based on regex rules', () => {
|
||||||
|
expect(isAnthropicModel(createModel({ id: 'claude-3.5' }))).toBe(true)
|
||||||
|
expect(isQwenMTModel(createModel({ id: 'qwen-mt-plus' }))).toBe(true)
|
||||||
|
expect(isNotSupportSystemMessageModel(createModel({ id: 'gemma-moe' }))).toBe(true)
|
||||||
|
expect(isOpenAIOpenWeightModel(createModel({ id: 'gpt-oss-free' }))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isNotSupportedTextDelta', () => {
|
||||||
|
it('returns true for qwen-mt-turbo and qwen-mt-plus models', () => {
|
||||||
|
// qwen-mt series that don't support text delta
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-turbo' }))).toBe(true)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-plus' }))).toBe(true)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'Qwen-MT-Turbo' }))).toBe(true)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'QWEN-MT-PLUS' }))).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('isOpenAIModel', () => {
|
it('returns false for qwen-mt-flash and other models', () => {
|
||||||
it('detects models via GPT prefix', () => {
|
// qwen-mt-flash supports text delta
|
||||||
expect(isOpenAIModel(createModel({ id: 'gpt-4.1' }))).toBe(true)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-flash' }))).toBe(false)
|
||||||
})
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'Qwen-MT-Flash' }))).toBe(false)
|
||||||
|
|
||||||
it('detects models via reasoning support', () => {
|
// Legacy qwen models without mt prefix (support text delta)
|
||||||
reasoningMock.mockReturnValueOnce(true)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-turbo' }))).toBe(false)
|
||||||
expect(isOpenAIModel(createModel({ id: 'o3' }))).toBe(true)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-plus' }))).toBe(false)
|
||||||
})
|
|
||||||
|
// Other qwen models
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-max' }))).toBe(false)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen2.5-72b' }))).toBe(false)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-vl-plus' }))).toBe(false)
|
||||||
|
|
||||||
|
// Non-qwen models
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'claude-3.5' }))).toBe(false)
|
||||||
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'glm-4-plus' }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('isOpenAIChatCompletionOnlyModel', () => {
|
it('handles models with version suffixes', () => {
|
||||||
it('identifies chat-completion-only models', () => {
|
// qwen-mt models with version suffixes
|
||||||
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'gpt-4o-search-preview' }))).toBe(true)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-turbo-1201' }))).toBe(true)
|
||||||
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'o1-mini' }))).toBe(true)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-plus-0828' }))).toBe(true)
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for general models', () => {
|
// Legacy qwen models with version suffixes (support text delta)
|
||||||
expect(isOpenAIChatCompletionOnlyModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-turbo-0828' }))).toBe(false)
|
||||||
})
|
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-plus-latest' }))).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('GPT-5 family detection', () => {
|
it('evaluates GPT-5 family helpers', () => {
|
||||||
describe('isGPT5SeriesModel', () => {
|
expect(isGPT5SeriesModel(createModel({ id: 'gpt-5-preview' }))).toBe(true)
|
||||||
it('returns true for GPT-5 models', () => {
|
expect(isGPT5SeriesModel(createModel({ id: 'gpt-5.1-preview' }))).toBe(false)
|
||||||
expect(isGPT5SeriesModel(createModel({ id: 'gpt-5-preview' }))).toBe(true)
|
expect(isGPT51SeriesModel(createModel({ id: 'gpt-5.1-mini' }))).toBe(true)
|
||||||
})
|
expect(isGPT5SeriesReasoningModel(createModel({ id: 'gpt-5-prompt' }))).toBe(true)
|
||||||
|
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5-chat' }))).toBe(false)
|
||||||
it('returns false for GPT-5.1 models', () => {
|
|
||||||
expect(isGPT5SeriesModel(createModel({ id: 'gpt-5.1-preview' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isGPT51SeriesModel', () => {
|
|
||||||
it('returns true for GPT-5.1 models', () => {
|
|
||||||
expect(isGPT51SeriesModel(createModel({ id: 'gpt-5.1-mini' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isGPT5SeriesReasoningModel', () => {
|
|
||||||
it('returns true for GPT-5 reasoning models', () => {
|
|
||||||
expect(isGPT5SeriesReasoningModel(createModel({ id: 'gpt-5' }))).toBe(true)
|
|
||||||
})
|
|
||||||
it('returns false for gpt-5-chat', () => {
|
|
||||||
expect(isGPT5SeriesReasoningModel(createModel({ id: 'gpt-5-chat' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isGPT5ProModel', () => {
|
|
||||||
it('returns true for GPT-5 Pro models', () => {
|
|
||||||
expect(isGPT5ProModel(createModel({ id: 'gpt-5-pro' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for non-Pro GPT-5 models', () => {
|
|
||||||
expect(isGPT5ProModel(createModel({ id: 'gpt-5-preview' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Verbosity support', () => {
|
it('wraps generate/vision helpers that operate on arrays', () => {
|
||||||
describe('isSupportVerbosityModel', () => {
|
const models = [createModel({ id: 'gpt-4o' }), createModel({ id: 'gpt-4o-mini' })]
|
||||||
it('returns true for GPT-5 models', () => {
|
expect(isVisionModels(models)).toBe(true)
|
||||||
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5' }))).toBe(true)
|
visionMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
|
||||||
})
|
expect(isVisionModels(models)).toBe(false)
|
||||||
|
|
||||||
it('returns false for GPT-5 chat models', () => {
|
expect(isGenerateImageModels(models)).toBe(true)
|
||||||
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5-chat' }))).toBe(false)
|
generateImageMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
|
||||||
})
|
expect(isGenerateImageModels(models)).toBe(false)
|
||||||
|
|
||||||
it('returns true for GPT-5.1 models', () => {
|
|
||||||
expect(isSupportVerbosityModel(createModel({ id: 'gpt-5.1-preview' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getModelSupportedVerbosity', () => {
|
|
||||||
it('returns only "high" for GPT-5 Pro models', () => {
|
|
||||||
expect(getModelSupportedVerbosity(createModel({ id: 'gpt-5-pro' }))).toEqual([undefined, 'high'])
|
|
||||||
expect(getModelSupportedVerbosity(createModel({ id: 'gpt-5-pro-2025-10-06' }))).toEqual([undefined, 'high'])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns all levels for non-Pro GPT-5 models', () => {
|
|
||||||
const previewModel = createModel({ id: 'gpt-5-preview' })
|
|
||||||
expect(getModelSupportedVerbosity(previewModel)).toEqual([undefined, 'low', 'medium', 'high'])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns all levels for GPT-5.1 models', () => {
|
|
||||||
const gpt51Model = createModel({ id: 'gpt-5.1-preview' })
|
|
||||||
expect(getModelSupportedVerbosity(gpt51Model)).toEqual([undefined, 'low', 'medium', 'high'])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns only undefined for non-GPT-5 models', () => {
|
|
||||||
expect(getModelSupportedVerbosity(createModel({ id: 'gpt-4o' }))).toEqual([undefined])
|
|
||||||
expect(getModelSupportedVerbosity(createModel({ id: 'claude-3.5' }))).toEqual([undefined])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns only undefined for undefiend/null input', () => {
|
|
||||||
expect(getModelSupportedVerbosity(undefined)).toEqual([undefined])
|
|
||||||
expect(getModelSupportedVerbosity(null)).toEqual([undefined])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Flex service tier support', () => {
|
it('filters models for agent usage', () => {
|
||||||
describe('isSupportFlexServiceTierModel', () => {
|
expect(agentModelFilter(createModel())).toBe(true)
|
||||||
it('returns true for supported models', () => {
|
|
||||||
expect(isSupportFlexServiceTierModel(createModel({ id: 'o3' }))).toBe(true)
|
|
||||||
expect(isSupportFlexServiceTierModel(createModel({ id: 'o4-mini' }))).toBe(true)
|
|
||||||
expect(isSupportFlexServiceTierModel(createModel({ id: 'gpt-5-preview' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for unsupported models', () => {
|
embeddingMock.mockReturnValueOnce(true)
|
||||||
expect(isSupportFlexServiceTierModel(createModel({ id: 'o3-mini' }))).toBe(false)
|
expect(agentModelFilter(createModel({ id: 'text-embedding' }))).toBe(false)
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isSupportedFlexServiceTier', () => {
|
embeddingMock.mockReturnValue(false)
|
||||||
it('returns false for non-flex models', () => {
|
rerankMock.mockReturnValueOnce(true)
|
||||||
expect(isSupportedFlexServiceTier(createModel({ id: 'gpt-4o' }))).toBe(false)
|
expect(agentModelFilter(createModel({ id: 'rerank' }))).toBe(false)
|
||||||
})
|
|
||||||
})
|
rerankMock.mockReturnValue(false)
|
||||||
|
textToImageMock.mockReturnValueOnce(true)
|
||||||
|
expect(agentModelFilter(createModel({ id: 'gpt-image-1' }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Temperature and top-p support', () => {
|
it('identifies models with maximum temperature of 1.0', () => {
|
||||||
describe('isNotSupportTemperatureAndTopP', () => {
|
// Zhipu models should have max temperature of 1.0
|
||||||
it('returns true for reasoning models', () => {
|
expect(isMaxTemperatureOneModel(createModel({ id: 'glm-4' }))).toBe(true)
|
||||||
const model = createModel({ id: 'o1' })
|
expect(isMaxTemperatureOneModel(createModel({ id: 'GLM-4-Plus' }))).toBe(true)
|
||||||
reasoningMock.mockReturnValue(true)
|
expect(isMaxTemperatureOneModel(createModel({ id: 'glm-3-turbo' }))).toBe(true)
|
||||||
expect(isNotSupportTemperatureAndTopP(model)).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for open weight models', () => {
|
// Anthropic models should have max temperature of 1.0
|
||||||
const openWeight = createModel({ id: 'gpt-oss-debug' })
|
expect(isMaxTemperatureOneModel(createModel({ id: 'claude-3.5-sonnet' }))).toBe(true)
|
||||||
expect(isNotSupportTemperatureAndTopP(openWeight)).toBe(false)
|
expect(isMaxTemperatureOneModel(createModel({ id: 'Claude-3-opus' }))).toBe(true)
|
||||||
})
|
expect(isMaxTemperatureOneModel(createModel({ id: 'claude-2.1' }))).toBe(true)
|
||||||
|
|
||||||
it('returns true for chat-only models without reasoning', () => {
|
// Moonshot models should have max temperature of 1.0
|
||||||
const chatOnly = createModel({ id: 'o1-preview' })
|
expect(isMaxTemperatureOneModel(createModel({ id: 'moonshot-1.0' }))).toBe(true)
|
||||||
reasoningMock.mockReturnValue(false)
|
expect(isMaxTemperatureOneModel(createModel({ id: 'kimi-k2-thinking' }))).toBe(true)
|
||||||
expect(isNotSupportTemperatureAndTopP(chatOnly)).toBe(true)
|
expect(isMaxTemperatureOneModel(createModel({ id: 'Moonshot-Pro' }))).toBe(true)
|
||||||
})
|
|
||||||
|
|
||||||
it('returns true for Qwen MT models', () => {
|
// Other models should return false
|
||||||
const qwenMt = createModel({ id: 'qwen-mt-large', provider: 'aliyun' })
|
expect(isMaxTemperatureOneModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
||||||
expect(isNotSupportTemperatureAndTopP(qwenMt)).toBe(true)
|
expect(isMaxTemperatureOneModel(createModel({ id: 'gpt-4-turbo' }))).toBe(false)
|
||||||
})
|
expect(isMaxTemperatureOneModel(createModel({ id: 'qwen-max' }))).toBe(false)
|
||||||
})
|
expect(isMaxTemperatureOneModel(createModel({ id: 'gemini-pro' }))).toBe(false)
|
||||||
})
|
|
||||||
|
|
||||||
describe('Text delta support', () => {
|
|
||||||
describe('isNotSupportTextDeltaModel', () => {
|
|
||||||
it('returns true for qwen-mt-turbo and qwen-mt-plus models', () => {
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-turbo' }))).toBe(true)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-plus' }))).toBe(true)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'Qwen-MT-Turbo' }))).toBe(true)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'QWEN-MT-PLUS' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for qwen-mt-flash and other models', () => {
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-flash' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'Qwen-MT-Flash' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-turbo' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-plus' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-max' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen2.5-72b' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-vl-plus' }))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for non-qwen models', () => {
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'claude-3.5' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'glm-4-plus' }))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('handles models with version suffixes', () => {
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-turbo-1201' }))).toBe(true)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-mt-plus-0828' }))).toBe(true)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-turbo-0828' }))).toBe(false)
|
|
||||||
expect(isNotSupportTextDeltaModel(createModel({ id: 'qwen-plus-latest' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Model provider detection', () => {
|
|
||||||
describe('isGemmaModel', () => {
|
|
||||||
it('detects Gemma models by ID', () => {
|
|
||||||
expect(isGemmaModel(createModel({ id: 'Gemma-3-27B' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('detects Gemma models by group', () => {
|
|
||||||
expect(isGemmaModel(createModel({ group: 'Gemma' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for non-Gemma models', () => {
|
|
||||||
expect(isGemmaModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isGeminiModel', () => {
|
|
||||||
it('detects Gemini models', () => {
|
|
||||||
expect(isGeminiModel(createModel({ id: 'Gemini-2.0' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isZhipuModel', () => {
|
|
||||||
it('detects Zhipu models by provider', () => {
|
|
||||||
expect(isZhipuModel(createModel({ provider: 'zhipu' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for non-Zhipu models', () => {
|
|
||||||
expect(isZhipuModel(createModel({ provider: 'openai' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isAnthropicModel', () => {
|
|
||||||
it('detects Anthropic models', () => {
|
|
||||||
expect(isAnthropicModel(createModel({ id: 'claude-3.5' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isQwenMTModel', () => {
|
|
||||||
it('detects Qwen MT models', () => {
|
|
||||||
expect(isQwenMTModel(createModel({ id: 'qwen-mt-plus' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isOpenAIOpenWeightModel', () => {
|
|
||||||
it('detects OpenAI open weight models', () => {
|
|
||||||
expect(isOpenAIOpenWeightModel(createModel({ id: 'gpt-oss-free' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('System message support', () => {
|
|
||||||
describe('isNotSupportSystemMessageModel', () => {
|
|
||||||
it('returns true for models that do not support system messages', () => {
|
|
||||||
expect(isNotSupportSystemMessageModel(createModel({ id: 'gemma-moe' }))).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Model grouping', () => {
|
|
||||||
describe('groupQwenModels', () => {
|
|
||||||
it('groups qwen models by prefix', () => {
|
|
||||||
const qwen = createModel({ id: 'Qwen-7B', provider: 'qwen', name: 'Qwen-7B' })
|
|
||||||
const qwenOmni = createModel({ id: 'qwen2.5-omni', name: 'qwen2.5-omni' })
|
|
||||||
const other = createModel({ id: 'deepseek-v3', group: 'DeepSeek' })
|
|
||||||
|
|
||||||
const grouped = groupQwenModels([qwen, qwenOmni, other])
|
|
||||||
expect(Object.keys(grouped)).toContain('qwen-7b')
|
|
||||||
expect(Object.keys(grouped)).toContain('qwen2.5')
|
|
||||||
expect(grouped.DeepSeek).toContain(other)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Vision and image generation', () => {
|
|
||||||
describe('isVisionModels', () => {
|
|
||||||
it('returns true when all models support vision', () => {
|
|
||||||
const models = [createModel({ id: 'gpt-4o' }), createModel({ id: 'gpt-4o-mini' })]
|
|
||||||
expect(isVisionModels(models)).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false when some models do not support vision', () => {
|
|
||||||
const models = [createModel({ id: 'gpt-4o' }), createModel({ id: 'gpt-4o-mini' })]
|
|
||||||
visionMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
|
|
||||||
expect(isVisionModels(models)).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('isGenerateImageModels', () => {
|
|
||||||
it('returns true when all models support image generation', () => {
|
|
||||||
const models = [createModel({ id: 'gpt-4o' }), createModel({ id: 'gpt-4o-mini' })]
|
|
||||||
expect(isGenerateImageModels(models)).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false when some models do not support image generation', () => {
|
|
||||||
const models = [createModel({ id: 'gpt-4o' }), createModel({ id: 'gpt-4o-mini' })]
|
|
||||||
generateImageMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
|
|
||||||
expect(isGenerateImageModels(models)).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Model filtering', () => {
|
|
||||||
describe('isSupportedModel', () => {
|
|
||||||
it('filters supported OpenAI catalog entries', () => {
|
|
||||||
expect(isSupportedModel({ id: 'gpt-4', object: 'model' } as any)).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('filters unsupported OpenAI catalog entries', () => {
|
|
||||||
expect(isSupportedModel({ id: 'tts-1', object: 'model' } as any)).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('agentModelFilter', () => {
|
|
||||||
it('returns true for regular models', () => {
|
|
||||||
expect(agentModelFilter(createModel())).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('filters out embedding models', () => {
|
|
||||||
embeddingMock.mockReturnValueOnce(true)
|
|
||||||
expect(agentModelFilter(createModel({ id: 'text-embedding' }))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('filters out rerank models', () => {
|
|
||||||
embeddingMock.mockReturnValue(false)
|
|
||||||
rerankMock.mockReturnValueOnce(true)
|
|
||||||
expect(agentModelFilter(createModel({ id: 'rerank' }))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('filters out text-to-image models', () => {
|
|
||||||
rerankMock.mockReturnValue(false)
|
|
||||||
textToImageMock.mockReturnValueOnce(true)
|
|
||||||
expect(agentModelFilter(createModel({ id: 'gpt-image-1' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Temperature limits', () => {
|
|
||||||
describe('isMaxTemperatureOneModel', () => {
|
|
||||||
it('returns true for Zhipu models', () => {
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'glm-4' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'GLM-4-Plus' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'glm-3-turbo' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns true for Anthropic models', () => {
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'claude-3.5-sonnet' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'Claude-3-opus' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'claude-2.1' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns true for Moonshot models', () => {
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'moonshot-1.0' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'kimi-k2-thinking' }))).toBe(true)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'Moonshot-Pro' }))).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false for other models', () => {
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'gpt-4o' }))).toBe(false)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'gpt-4-turbo' }))).toBe(false)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'qwen-max' }))).toBe(false)
|
|
||||||
expect(isMaxTemperatureOneModel(createModel({ id: 'gemini-pro' }))).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -396,11 +396,7 @@ export function isClaude45ReasoningModel(model: Model): boolean {
|
|||||||
|
|
||||||
export function isClaude4SeriesModel(model: Model): boolean {
|
export function isClaude4SeriesModel(model: Model): boolean {
|
||||||
const modelId = getLowerBaseModelName(model.id, '/')
|
const modelId = getLowerBaseModelName(model.id, '/')
|
||||||
// Supports various formats including:
|
const regex = /claude-(sonnet|opus|haiku)-4(?:[.-]\d+)?(?:-[\w-]+)?$/i
|
||||||
// - Direct API: claude-sonnet-4, claude-opus-4-20250514
|
|
||||||
// - GCP Vertex AI: claude-sonnet-4@20250514
|
|
||||||
// - AWS Bedrock: anthropic.claude-sonnet-4-20250514-v1:0
|
|
||||||
const regex = /claude-(sonnet|opus|haiku)-4(?:[.-]\d+)?(?:[@\-:][\w\-:]+)?$/i
|
|
||||||
return regex.test(modelId)
|
return regex.test(modelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,19 +456,16 @@ export const isSupportedThinkingTokenZhipuModel = (model: Model): boolean => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const isDeepSeekHybridInferenceModel = (model: Model) => {
|
export const isDeepSeekHybridInferenceModel = (model: Model) => {
|
||||||
const { idResult, nameResult } = withModelIdAndNameAsId(model, (model) => {
|
const modelId = getLowerBaseModelName(model.id)
|
||||||
const modelId = getLowerBaseModelName(model.id)
|
// deepseek官方使用chat和reasoner做推理控制,其他provider需要单独判断,id可能会有所差别
|
||||||
// deepseek官方使用chat和reasoner做推理控制,其他provider需要单独判断,id可能会有所差别
|
// openrouter: deepseek/deepseek-chat-v3.1 不知道会不会有其他provider仿照ds官方分出一个同id的作为非思考模式的模型,这里有风险
|
||||||
// openrouter: deepseek/deepseek-chat-v3.1 不知道会不会有其他provider仿照ds官方分出一个同id的作为非思考模式的模型,这里有风险
|
// Matches: "deepseek-v3" followed by ".digit" or "-digit".
|
||||||
// Matches: "deepseek-v3" followed by ".digit" or "-digit".
|
// Optionally, this can be followed by ".alphanumeric_sequence" or "-alphanumeric_sequence"
|
||||||
// Optionally, this can be followed by ".alphanumeric_sequence" or "-alphanumeric_sequence"
|
// until the end of the string.
|
||||||
// until the end of the string.
|
// Examples: deepseek-v3.1, deepseek-v3-1, deepseek-v3.1.2, deepseek-v3.1-alpha
|
||||||
// Examples: deepseek-v3.1, deepseek-v3-1, deepseek-v3.1.2, deepseek-v3.1-alpha
|
// Does NOT match: deepseek-v3.123 (missing separator after '1'), deepseek-v3.x (x isn't a digit)
|
||||||
// Does NOT match: deepseek-v3.123 (missing separator after '1'), deepseek-v3.x (x isn't a digit)
|
// TODO: move to utils and add test cases
|
||||||
// TODO: move to utils and add test cases
|
return /deepseek-v3(?:\.\d|-\d)(?:(\.|-)\w+)?$/.test(modelId) || modelId.includes('deepseek-chat-v3.1')
|
||||||
return /deepseek-v3(?:\.\d|-\d)(?:(\.|-)\w+)?$/.test(modelId) || modelId.includes('deepseek-chat-v3.1')
|
|
||||||
})
|
|
||||||
return idResult || nameResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isLingReasoningModel = (model?: Model): boolean => {
|
export const isLingReasoningModel = (model?: Model): boolean => {
|
||||||
@@ -526,6 +519,7 @@ export function isReasoningModel(model?: Model): boolean {
|
|||||||
REASONING_REGEX.test(model.name) ||
|
REASONING_REGEX.test(model.name) ||
|
||||||
isSupportedThinkingTokenDoubaoModel(model) ||
|
isSupportedThinkingTokenDoubaoModel(model) ||
|
||||||
isDeepSeekHybridInferenceModel(model) ||
|
isDeepSeekHybridInferenceModel(model) ||
|
||||||
|
isDeepSeekHybridInferenceModel({ ...model, id: model.name }) ||
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,7 @@ import { type Model, SystemProviderIds } from '@renderer/types'
|
|||||||
import type { OpenAIVerbosity, ValidOpenAIVerbosity } from '@renderer/types/aiCoreTypes'
|
import type { OpenAIVerbosity, ValidOpenAIVerbosity } from '@renderer/types/aiCoreTypes'
|
||||||
import { getLowerBaseModelName } from '@renderer/utils'
|
import { getLowerBaseModelName } from '@renderer/utils'
|
||||||
|
|
||||||
import {
|
import { isOpenAIChatCompletionOnlyModel, isOpenAIOpenWeightModel, isOpenAIReasoningModel } from './openai'
|
||||||
isGPT5ProModel,
|
|
||||||
isGPT5SeriesModel,
|
|
||||||
isGPT51SeriesModel,
|
|
||||||
isOpenAIChatCompletionOnlyModel,
|
|
||||||
isOpenAIOpenWeightModel,
|
|
||||||
isOpenAIReasoningModel
|
|
||||||
} from './openai'
|
|
||||||
import { isQwenMTModel } from './qwen'
|
import { isQwenMTModel } from './qwen'
|
||||||
import { isGenerateImageModel, isTextToImageModel, isVisionModel } from './vision'
|
import { isGenerateImageModel, isTextToImageModel, isVisionModel } from './vision'
|
||||||
export const NOT_SUPPORTED_REGEX = /(?:^tts|whisper|speech)/i
|
export const NOT_SUPPORTED_REGEX = /(?:^tts|whisper|speech)/i
|
||||||
@@ -130,46 +123,21 @@ export const isNotSupportSystemMessageModel = (model: Model): boolean => {
|
|||||||
return isQwenMTModel(model) || isGemmaModel(model)
|
return isQwenMTModel(model) || isGemmaModel(model)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verbosity settings is only supported by GPT-5 and newer models
|
// GPT-5 verbosity configuration
|
||||||
// Specifically, GPT-5 and GPT-5.1 for now
|
|
||||||
// gpt-5-pro only supports 'high', other GPT-5 models support all levels
|
// gpt-5-pro only supports 'high', other GPT-5 models support all levels
|
||||||
const MODEL_SUPPORTED_VERBOSITY: readonly {
|
export const MODEL_SUPPORTED_VERBOSITY: Record<string, ValidOpenAIVerbosity[]> = {
|
||||||
readonly validator: (model: Model) => boolean
|
'gpt-5-pro': ['high'],
|
||||||
readonly values: readonly ValidOpenAIVerbosity[]
|
default: ['low', 'medium', 'high']
|
||||||
}[] = [
|
} as const
|
||||||
// gpt-5-pro
|
|
||||||
{ validator: isGPT5ProModel, values: ['high'] },
|
|
||||||
// gpt-5 except gpt-5-pro
|
|
||||||
{
|
|
||||||
validator: (model: Model) => isGPT5SeriesModel(model) && !isGPT5ProModel(model),
|
|
||||||
values: ['low', 'medium', 'high']
|
|
||||||
},
|
|
||||||
// gpt-5.1
|
|
||||||
{ validator: isGPT51SeriesModel, values: ['low', 'medium', 'high'] }
|
|
||||||
]
|
|
||||||
|
|
||||||
/**
|
export const getModelSupportedVerbosity = (model: Model): OpenAIVerbosity[] => {
|
||||||
* Returns the list of supported verbosity levels for the given model.
|
const modelId = getLowerBaseModelName(model.id)
|
||||||
* If the model is not recognized as a GPT-5 series model, only `undefined` is returned.
|
let supportedValues: ValidOpenAIVerbosity[]
|
||||||
* For GPT-5-pro, only 'high' is supported; for other GPT-5 models, 'low', 'medium', and 'high' are supported.
|
if (modelId.includes('gpt-5-pro')) {
|
||||||
* For GPT-5.1 series models, 'low', 'medium', and 'high' are supported.
|
supportedValues = MODEL_SUPPORTED_VERBOSITY['gpt-5-pro']
|
||||||
* @param model - The model to check
|
} else {
|
||||||
* @returns An array of supported verbosity levels, always including `undefined` as the first element
|
supportedValues = MODEL_SUPPORTED_VERBOSITY.default
|
||||||
*/
|
|
||||||
export const getModelSupportedVerbosity = (model: Model | undefined | null): OpenAIVerbosity[] => {
|
|
||||||
if (!model) {
|
|
||||||
return [undefined]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let supportedValues: ValidOpenAIVerbosity[] = []
|
|
||||||
|
|
||||||
for (const { validator, values } of MODEL_SUPPORTED_VERBOSITY) {
|
|
||||||
if (validator(model)) {
|
|
||||||
supportedValues = [...values]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [undefined, ...supportedValues]
|
return [undefined, ...supportedValues]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { throttle } from 'lodash'
|
import { throttle } from 'lodash'
|
||||||
import { useEffect, useMemo, useRef } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
import { useTimer } from './useTimer'
|
import { useTimer } from './useTimer'
|
||||||
|
|
||||||
@@ -12,18 +12,13 @@ import { useTimer } from './useTimer'
|
|||||||
*/
|
*/
|
||||||
export default function useScrollPosition(key: string, throttleWait?: number) {
|
export default function useScrollPosition(key: string, throttleWait?: number) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const scrollKey = useMemo(() => `scroll:${key}`, [key])
|
const scrollKey = `scroll:${key}`
|
||||||
const scrollKeyRef = useRef(scrollKey)
|
|
||||||
const { setTimeoutTimer } = useTimer()
|
const { setTimeoutTimer } = useTimer()
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
scrollKeyRef.current = scrollKey
|
|
||||||
}, [scrollKey])
|
|
||||||
|
|
||||||
const handleScroll = throttle(() => {
|
const handleScroll = throttle(() => {
|
||||||
const position = containerRef.current?.scrollTop ?? 0
|
const position = containerRef.current?.scrollTop ?? 0
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
window.keyv.set(scrollKeyRef.current, position)
|
window.keyv.set(scrollKey, position)
|
||||||
})
|
})
|
||||||
}, throttleWait ?? 100)
|
}, throttleWait ?? 100)
|
||||||
|
|
||||||
@@ -33,9 +28,5 @@ export default function useScrollPosition(key: string, throttleWait?: number) {
|
|||||||
setTimeoutTimer('scrollEffect', scroll, 50)
|
setTimeoutTimer('scrollEffect', scroll, 50)
|
||||||
}, [scrollKey, setTimeoutTimer])
|
}, [scrollKey, setTimeoutTimer])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => handleScroll.cancel()
|
|
||||||
}, [handleScroll])
|
|
||||||
|
|
||||||
return { containerRef, handleScroll }
|
return { containerRef, handleScroll }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useRef } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时器管理 Hook,用于管理 setTimeout 和 setInterval 定时器,支持通过 key 来标识不同的定时器
|
* 定时器管理 Hook,用于管理 setTimeout 和 setInterval 定时器,支持通过 key 来标识不同的定时器
|
||||||
@@ -43,38 +43,10 @@ export const useTimer = () => {
|
|||||||
const timeoutMapRef = useRef(new Map<string, NodeJS.Timeout>())
|
const timeoutMapRef = useRef(new Map<string, NodeJS.Timeout>())
|
||||||
const intervalMapRef = useRef(new Map<string, NodeJS.Timeout>())
|
const intervalMapRef = useRef(new Map<string, NodeJS.Timeout>())
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除指定 key 的 setTimeout 定时器
|
|
||||||
* @param key - 定时器标识符
|
|
||||||
*/
|
|
||||||
const clearTimeoutTimer = useCallback((key: string) => {
|
|
||||||
clearTimeout(timeoutMapRef.current.get(key))
|
|
||||||
timeoutMapRef.current.delete(key)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除指定 key 的 setInterval 定时器
|
|
||||||
* @param key - 定时器标识符
|
|
||||||
*/
|
|
||||||
const clearIntervalTimer = useCallback((key: string) => {
|
|
||||||
clearInterval(intervalMapRef.current.get(key))
|
|
||||||
intervalMapRef.current.delete(key)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除所有定时器,包括 setTimeout 和 setInterval
|
|
||||||
*/
|
|
||||||
const clearAllTimers = useCallback(() => {
|
|
||||||
timeoutMapRef.current.forEach((timer) => clearTimeout(timer))
|
|
||||||
intervalMapRef.current.forEach((timer) => clearInterval(timer))
|
|
||||||
timeoutMapRef.current.clear()
|
|
||||||
intervalMapRef.current.clear()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
// 组件卸载时自动清理所有定时器
|
// 组件卸载时自动清理所有定时器
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => clearAllTimers()
|
return () => clearAllTimers()
|
||||||
}, [clearAllTimers])
|
}, [])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置一个 setTimeout 定时器
|
* 设置一个 setTimeout 定时器
|
||||||
@@ -93,15 +65,12 @@ export const useTimer = () => {
|
|||||||
* cleanup();
|
* cleanup();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
const setTimeoutTimer = useCallback(
|
const setTimeoutTimer = (key: string, ...args: Parameters<typeof setTimeout>) => {
|
||||||
(key: string, ...args: Parameters<typeof setTimeout>) => {
|
clearTimeout(timeoutMapRef.current.get(key))
|
||||||
clearTimeout(timeoutMapRef.current.get(key))
|
const timer = setTimeout(...args)
|
||||||
const timer = setTimeout(...args)
|
timeoutMapRef.current.set(key, timer)
|
||||||
timeoutMapRef.current.set(key, timer)
|
return () => clearTimeoutTimer(key)
|
||||||
return () => clearTimeoutTimer(key)
|
}
|
||||||
},
|
|
||||||
[clearTimeoutTimer]
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置一个 setInterval 定时器
|
* 设置一个 setInterval 定时器
|
||||||
@@ -120,31 +89,56 @@ export const useTimer = () => {
|
|||||||
* cleanup();
|
* cleanup();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
const setIntervalTimer = useCallback(
|
const setIntervalTimer = (key: string, ...args: Parameters<typeof setInterval>) => {
|
||||||
(key: string, ...args: Parameters<typeof setInterval>) => {
|
clearInterval(intervalMapRef.current.get(key))
|
||||||
clearInterval(intervalMapRef.current.get(key))
|
const timer = setInterval(...args)
|
||||||
const timer = setInterval(...args)
|
intervalMapRef.current.set(key, timer)
|
||||||
intervalMapRef.current.set(key, timer)
|
return () => clearIntervalTimer(key)
|
||||||
return () => clearIntervalTimer(key)
|
}
|
||||||
},
|
|
||||||
[clearIntervalTimer]
|
/**
|
||||||
)
|
* 清除指定 key 的 setTimeout 定时器
|
||||||
|
* @param key - 定时器标识符
|
||||||
|
*/
|
||||||
|
const clearTimeoutTimer = (key: string) => {
|
||||||
|
clearTimeout(timeoutMapRef.current.get(key))
|
||||||
|
timeoutMapRef.current.delete(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除指定 key 的 setInterval 定时器
|
||||||
|
* @param key - 定时器标识符
|
||||||
|
*/
|
||||||
|
const clearIntervalTimer = (key: string) => {
|
||||||
|
clearInterval(intervalMapRef.current.get(key))
|
||||||
|
intervalMapRef.current.delete(key)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除所有 setTimeout 定时器
|
* 清除所有 setTimeout 定时器
|
||||||
*/
|
*/
|
||||||
const clearAllTimeoutTimers = useCallback(() => {
|
const clearAllTimeoutTimers = () => {
|
||||||
timeoutMapRef.current.forEach((timer) => clearTimeout(timer))
|
timeoutMapRef.current.forEach((timer) => clearTimeout(timer))
|
||||||
timeoutMapRef.current.clear()
|
timeoutMapRef.current.clear()
|
||||||
}, [])
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除所有 setInterval 定时器
|
* 清除所有 setInterval 定时器
|
||||||
*/
|
*/
|
||||||
const clearAllIntervalTimers = useCallback(() => {
|
const clearAllIntervalTimers = () => {
|
||||||
intervalMapRef.current.forEach((timer) => clearInterval(timer))
|
intervalMapRef.current.forEach((timer) => clearInterval(timer))
|
||||||
intervalMapRef.current.clear()
|
intervalMapRef.current.clear()
|
||||||
}, [])
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有定时器,包括 setTimeout 和 setInterval
|
||||||
|
*/
|
||||||
|
const clearAllTimers = () => {
|
||||||
|
timeoutMapRef.current.forEach((timer) => clearTimeout(timer))
|
||||||
|
intervalMapRef.current.forEach((timer) => clearInterval(timer))
|
||||||
|
timeoutMapRef.current.clear()
|
||||||
|
intervalMapRef.current.clear()
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setTimeoutTimer,
|
setTimeoutTimer,
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import store, { useAppSelector } from '@renderer/store'
|
||||||
|
import { setVolcengineProjectName, setVolcengineRegion } from '@renderer/store/llm'
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
|
|
||||||
|
export function useVolcengineSettings() {
|
||||||
|
const settings = useAppSelector((state) => state.llm.settings.volcengine)
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
|
return {
|
||||||
|
...settings,
|
||||||
|
setRegion: (region: string) => dispatch(setVolcengineRegion(region)),
|
||||||
|
setProjectName: (projectName: string) => dispatch(setVolcengineProjectName(projectName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVolcengineSettings() {
|
||||||
|
return store.getState().llm.settings.volcengine
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVolcengineRegion() {
|
||||||
|
return store.getState().llm.settings.volcengine.region
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVolcengineProjectName() {
|
||||||
|
return store.getState().llm.settings.volcengine.projectName
|
||||||
|
}
|
||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "Tool request was denied.",
|
"denied": "Tool request was denied.",
|
||||||
"timeout": "Tool request timed out before receiving approval."
|
"timeout": "Tool request timed out before receiving approval."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Tool",
|
|
||||||
"waiting": "Waiting for tool permission decision..."
|
"waiting": "Waiting for tool permission decision..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Image Generation (OpenAI)",
|
"image-generation": "Image Generation",
|
||||||
"jina-rerank": "Jina Rerank",
|
"jina-rerank": "Jina Rerank",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Preview: {{url}}",
|
"preview": "Preview: {{url}}",
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
"tip": "Add # at the end to disable the automatically appended API version."
|
"tip": "ending with # forces use of input address"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "API Host",
|
"api_host": "API Host",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Enter Service Account private key",
|
"private_key_placeholder": "Enter Service Account private key",
|
||||||
"title": "Service Account Configuration"
|
"title": "Service Account Configuration"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "Access Key ID",
|
||||||
|
"access_key_id_help": "Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "Clear Credentials",
|
||||||
|
"credentials_cleared": "Credentials cleared",
|
||||||
|
"credentials_required": "Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "Credentials saved",
|
||||||
|
"description": "Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Please use IAM user's Access Key for authentication, do not use the root user credentials.",
|
||||||
|
"project_name": "Project Name",
|
||||||
|
"project_name_help": "Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "Region",
|
||||||
|
"region_help": "Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "Save Credentials",
|
||||||
|
"secret_access_key": "Secret Access Key",
|
||||||
|
"secret_access_key_help": "Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "工具请求已被拒绝。",
|
"denied": "工具请求已被拒绝。",
|
||||||
"timeout": "工具请求在收到批准前超时。"
|
"timeout": "工具请求在收到批准前超时。"
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "工具",
|
|
||||||
"waiting": "等待工具权限决定..."
|
"waiting": "等待工具权限决定..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "图像生成 (OpenAI)",
|
"image-generation": "图片生成",
|
||||||
"jina-rerank": "Jina 重排序",
|
"jina-rerank": "Jina 重排序",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "预览: {{url}}",
|
"preview": "预览: {{url}}",
|
||||||
"reset": "重置",
|
"reset": "重置",
|
||||||
"tip": "在末尾添加 # 以禁用自动附加的API版本。"
|
"tip": "# 结尾强制使用输入地址"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "API 地址",
|
"api_host": "API 地址",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "请输入 Service Account 私钥",
|
"private_key_placeholder": "请输入 Service Account 私钥",
|
||||||
"title": "Service Account 配置"
|
"title": "Service Account 配置"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "Access Key ID",
|
||||||
|
"access_key_id_help": "您的火山引擎 Access Key ID",
|
||||||
|
"clear_credentials": "清除凭证",
|
||||||
|
"credentials_cleared": "凭证已清除",
|
||||||
|
"credentials_required": "请填写 Access Key ID 和 Secret Access Key",
|
||||||
|
"credentials_saved": "凭证已保存",
|
||||||
|
"description": "火山引擎是字节跳动旗下的云服务平台,提供豆包等大语言模型服务。请使用 IAM 子用户的 Access Key 进行身份验证,不要使用主账号的根用户密钥。",
|
||||||
|
"project_name": "项目名称",
|
||||||
|
"project_name_help": "用于筛选推理接入点的项目名称,默认为 'default'",
|
||||||
|
"region": "地域",
|
||||||
|
"region_help": "服务地域,例如 cn-beijing",
|
||||||
|
"save_credentials": "保存凭证",
|
||||||
|
"secret_access_key": "Secret Access Key",
|
||||||
|
"secret_access_key_help": "您的火山引擎 Secret Access Key,请妥善保管",
|
||||||
|
"title": "火山引擎配置"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "工具請求已被拒絕。",
|
"denied": "工具請求已被拒絕。",
|
||||||
"timeout": "工具請求在收到核准前逾時。"
|
"timeout": "工具請求在收到核准前逾時。"
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "工具",
|
|
||||||
"waiting": "等待工具權限決定..."
|
"waiting": "等待工具權限決定..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "圖像生成 (OpenAI)",
|
"image-generation": "圖片生成",
|
||||||
"jina-rerank": "Jina Rerank",
|
"jina-rerank": "Jina Rerank",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "預覽:{{url}}",
|
"preview": "預覽:{{url}}",
|
||||||
"reset": "重設",
|
"reset": "重設",
|
||||||
"tip": "在末尾添加 # 以停用自動附加的 API 版本。"
|
"tip": "# 結尾強制使用輸入位址"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "API 主機地址",
|
"api_host": "API 主機地址",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "輸入服務帳戶私密金鑰",
|
"private_key_placeholder": "輸入服務帳戶私密金鑰",
|
||||||
"title": "服務帳戶設定"
|
"title": "服務帳戶設定"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "Access Key ID",
|
||||||
|
"access_key_id_help": "您的火山引擎 Access Key ID",
|
||||||
|
"clear_credentials": "清除憑證",
|
||||||
|
"credentials_cleared": "憑證已清除",
|
||||||
|
"credentials_required": "請填寫 Access Key ID 和 Secret Access Key",
|
||||||
|
"credentials_saved": "憑證已儲存",
|
||||||
|
"description": "火山引擎是字節跳動旗下的雲端服務平台,提供豆包等大型語言模型服務。請使用 IAM 子用戶的 Access Key 進行身份驗證,不要使用主帳號的根用戶密鑰。",
|
||||||
|
"project_name": "專案名稱",
|
||||||
|
"project_name_help": "用於篩選推論接入點的專案名稱,預設為 'default'",
|
||||||
|
"region": "地區",
|
||||||
|
"region_help": "服務地區,例如 cn-beijing",
|
||||||
|
"save_credentials": "儲存憑證",
|
||||||
|
"secret_access_key": "Secret Access Key",
|
||||||
|
"secret_access_key_help": "您的火山引擎 Secret Access Key,請妥善保管",
|
||||||
|
"title": "火山引擎設定"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "Tool-Anfrage wurde abgelehnt.",
|
"denied": "Tool-Anfrage wurde abgelehnt.",
|
||||||
"timeout": "Tool-Anfrage ist abgelaufen, bevor eine Genehmigung eingegangen ist."
|
"timeout": "Tool-Anfrage ist abgelaufen, bevor eine Genehmigung eingegangen ist."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Werkzeug",
|
|
||||||
"waiting": "Warten auf Entscheidung über Tool-Berechtigung..."
|
"waiting": "Warten auf Entscheidung über Tool-Berechtigung..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Bilderzeugung (OpenAI)",
|
"image-generation": "Bildgenerierung",
|
||||||
"jina-rerank": "Jina Reranking",
|
"jina-rerank": "Jina Reranking",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Vorschau: {{url}}",
|
"preview": "Vorschau: {{url}}",
|
||||||
"reset": "Zurücksetzen",
|
"reset": "Zurücksetzen",
|
||||||
"tip": "Fügen Sie am Ende ein # hinzu, um die automatisch angehängte API-Version zu deaktivieren."
|
"tip": "# am Ende erzwingt die Verwendung der Eingabe-Adresse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "API-Adresse",
|
"api_host": "API-Adresse",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Service Account-Privat-Schlüssel eingeben",
|
"private_key_placeholder": "Service Account-Privat-Schlüssel eingeben",
|
||||||
"title": "Service Account-Konfiguration"
|
"title": "Service Account-Konfiguration"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "Το αίτημα για εργαλείο απορρίφθηκε.",
|
"denied": "Το αίτημα για εργαλείο απορρίφθηκε.",
|
||||||
"timeout": "Το αίτημα για το εργαλείο έληξε πριν λάβει έγκριση."
|
"timeout": "Το αίτημα για το εργαλείο έληξε πριν λάβει έγκριση."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Εργαλείο",
|
|
||||||
"waiting": "Αναμονή για απόφαση άδειας εργαλείου..."
|
"waiting": "Αναμονή για απόφαση άδειας εργαλείου..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Δημιουργία Εικόνων (OpenAI)",
|
"image-generation": "Δημιουργία Εικόνας",
|
||||||
"jina-rerank": "Επαναταξινόμηση Jina",
|
"jina-rerank": "Επαναταξινόμηση Jina",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "Απάντηση OpenAI"
|
"openai-response": "Απάντηση OpenAI"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Προεπισκόπηση: {{url}}",
|
"preview": "Προεπισκόπηση: {{url}}",
|
||||||
"reset": "Επαναφορά",
|
"reset": "Επαναφορά",
|
||||||
"tip": "Προσθέστε το σύμβολο # στο τέλος για να απενεργοποιήσετε την αυτόματα προστιθέμενη έκδοση API."
|
"tip": "#τέλος ενδεχόμενη χρήση της εισαγωγής διευθύνσεως"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "Διεύθυνση API",
|
"api_host": "Διεύθυνση API",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Παρακαλώ εισάγετε το ιδιωτικό κλειδί του λογαριασμού υπηρεσίας",
|
"private_key_placeholder": "Παρακαλώ εισάγετε το ιδιωτικό κλειδί του λογαριασμού υπηρεσίας",
|
||||||
"title": "Διαμόρφωση λογαριασμού υπηρεσίας"
|
"title": "Διαμόρφωση λογαριασμού υπηρεσίας"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "La solicitud de herramienta fue denegada.",
|
"denied": "La solicitud de herramienta fue denegada.",
|
||||||
"timeout": "La solicitud de herramienta expiró antes de recibir la aprobación."
|
"timeout": "La solicitud de herramienta expiró antes de recibir la aprobación."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Herramienta",
|
|
||||||
"waiting": "Esperando la decisión de permiso de la herramienta..."
|
"waiting": "Esperando la decisión de permiso de la herramienta..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Generación de Imágenes (OpenAI)",
|
"image-generation": "Generación de imágenes",
|
||||||
"jina-rerank": "Reordenamiento Jina",
|
"jina-rerank": "Reordenamiento Jina",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "Respuesta de OpenAI"
|
"openai-response": "Respuesta de OpenAI"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Vista previa: {{url}}",
|
"preview": "Vista previa: {{url}}",
|
||||||
"reset": "Restablecer",
|
"reset": "Restablecer",
|
||||||
"tip": "Añada # al final para deshabilitar la versión de la API que se añade automáticamente."
|
"tip": "forzar uso de dirección de entrada con # al final"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "Dirección API",
|
"api_host": "Dirección API",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Ingrese la clave privada de Service Account",
|
"private_key_placeholder": "Ingrese la clave privada de Service Account",
|
||||||
"title": "Configuración de Service Account"
|
"title": "Configuración de Service Account"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "La demande d'outil a été refusée.",
|
"denied": "La demande d'outil a été refusée.",
|
||||||
"timeout": "La demande d'outil a expiré avant d'obtenir l'approbation."
|
"timeout": "La demande d'outil a expiré avant d'obtenir l'approbation."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Outil",
|
|
||||||
"waiting": "En attente de la décision d'autorisation de l'outil..."
|
"waiting": "En attente de la décision d'autorisation de l'outil..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Génération d'images (OpenAI)",
|
"image-generation": "Génération d'images",
|
||||||
"jina-rerank": "Reclassement Jina",
|
"jina-rerank": "Reclassement Jina",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "Réponse OpenAI"
|
"openai-response": "Réponse OpenAI"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Aperçu : {{url}}",
|
"preview": "Aperçu : {{url}}",
|
||||||
"reset": "Réinitialiser",
|
"reset": "Réinitialiser",
|
||||||
"tip": "Ajoutez # à la fin pour désactiver la version d'API ajoutée automatiquement."
|
"tip": "forcer l'utilisation de l'adresse d'entrée si terminé par #"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "Adresse API",
|
"api_host": "Adresse API",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Veuillez saisir la clé privée du compte de service",
|
"private_key_placeholder": "Veuillez saisir la clé privée du compte de service",
|
||||||
"title": "Configuration du compte de service"
|
"title": "Configuration du compte de service"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "ツールリクエストは拒否されました。",
|
"denied": "ツールリクエストは拒否されました。",
|
||||||
"timeout": "ツールリクエストは承認を受ける前にタイムアウトしました。"
|
"timeout": "ツールリクエストは承認を受ける前にタイムアウトしました。"
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "ツール",
|
|
||||||
"waiting": "ツールの許可決定を待っています..."
|
"waiting": "ツールの許可決定を待っています..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "画像生成 (OpenAI)",
|
"image-generation": "画像生成",
|
||||||
"jina-rerank": "Jina Rerank",
|
"jina-rerank": "Jina Rerank",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "プレビュー: {{url}}",
|
"preview": "プレビュー: {{url}}",
|
||||||
"reset": "リセット",
|
"reset": "リセット",
|
||||||
"tip": "自動的に付加されるAPIバージョンを無効にするには、末尾に#を追加します。"
|
"tip": "#で終わる場合、入力されたアドレスを強制的に使用します"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "APIホスト",
|
"api_host": "APIホスト",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "サービスアカウントの秘密鍵を入力してください",
|
"private_key_placeholder": "サービスアカウントの秘密鍵を入力してください",
|
||||||
"title": "サービスアカウント設定"
|
"title": "サービスアカウント設定"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"error": {
|
"error": {
|
||||||
"failed": "Falha ao excluir o agente"
|
"failed": "Falha ao excluir o agente"
|
||||||
},
|
},
|
||||||
"title": "Excluir Agente"
|
"title": "删除代理"
|
||||||
},
|
},
|
||||||
"edit": {
|
"edit": {
|
||||||
"title": "Agent Editor"
|
"title": "Agent Editor"
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
"label": "Modo de permissão",
|
"label": "Modo de permissão",
|
||||||
"options": {
|
"options": {
|
||||||
"acceptEdits": "Aceitar edições automaticamente",
|
"acceptEdits": "Aceitar edições automaticamente",
|
||||||
"bypassPermissions": "Ignorar verificações de permissão",
|
"bypassPermissions": "忽略检查 de permissão",
|
||||||
"default": "Padrão (perguntar antes de continuar)",
|
"default": "Padrão (perguntar antes de continuar)",
|
||||||
"plan": "Modo de planejamento (plano sujeito a aprovação)"
|
"plan": "Modo de planejamento (plano sujeito a aprovação)"
|
||||||
},
|
},
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
},
|
},
|
||||||
"success": {
|
"success": {
|
||||||
"install": "Plugin instalado com sucesso",
|
"install": "Plugin instalado com sucesso",
|
||||||
"uninstall": "Plugin desinstalado com sucesso"
|
"uninstall": "插件 desinstalado com sucesso"
|
||||||
},
|
},
|
||||||
"tab": "plug-in",
|
"tab": "plug-in",
|
||||||
"type": {
|
"type": {
|
||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "Solicitação de ferramenta foi negada.",
|
"denied": "Solicitação de ferramenta foi negada.",
|
||||||
"timeout": "A solicitação da ferramenta expirou antes de receber aprovação."
|
"timeout": "A solicitação da ferramenta expirou antes de receber aprovação."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Ferramenta",
|
|
||||||
"waiting": "Aguardando decisão de permissão da ferramenta..."
|
"waiting": "Aguardando decisão de permissão da ferramenta..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1135,7 +1134,7 @@
|
|||||||
"duplicate": "Duplicar",
|
"duplicate": "Duplicar",
|
||||||
"edit": "Editar",
|
"edit": "Editar",
|
||||||
"enabled": "Ativado",
|
"enabled": "Ativado",
|
||||||
"error": "Erro",
|
"error": "错误",
|
||||||
"errors": {
|
"errors": {
|
||||||
"create_message": "Falha ao criar mensagem",
|
"create_message": "Falha ao criar mensagem",
|
||||||
"validation": "Falha na verificação"
|
"validation": "Falha na verificação"
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Geração de Imagens (OpenAI)",
|
"image-generation": "Geração de Imagem",
|
||||||
"jina-rerank": "Jina Reordenar",
|
"jina-rerank": "Jina Reordenar",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "Resposta OpenAI"
|
"openai-response": "Resposta OpenAI"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Pré-visualização: {{url}}",
|
"preview": "Pré-visualização: {{url}}",
|
||||||
"reset": "Redefinir",
|
"reset": "Redefinir",
|
||||||
"tip": "Adicione # no final para desativar a versão da API adicionada automaticamente."
|
"tip": "e forçar o uso do endereço original quando terminar com '#'"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "Endereço API",
|
"api_host": "Endereço API",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Por favor, insira a chave privada da Conta de Serviço",
|
"private_key_placeholder": "Por favor, insira a chave privada da Conta de Serviço",
|
||||||
"title": "Configuração da Conta de Serviço"
|
"title": "Configuração da Conta de Serviço"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
"denied": "Запрос на инструмент был отклонён.",
|
"denied": "Запрос на инструмент был отклонён.",
|
||||||
"timeout": "Запрос на инструмент превысил время ожидания до получения подтверждения."
|
"timeout": "Запрос на инструмент превысил время ожидания до получения подтверждения."
|
||||||
},
|
},
|
||||||
"toolPendingFallback": "Инструмент",
|
|
||||||
"waiting": "Ожидание решения о разрешении на использование инструмента..."
|
"waiting": "Ожидание решения о разрешении на использование инструмента..."
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
@@ -1209,7 +1208,7 @@
|
|||||||
"endpoint_type": {
|
"endpoint_type": {
|
||||||
"anthropic": "Anthropic",
|
"anthropic": "Anthropic",
|
||||||
"gemini": "Gemini",
|
"gemini": "Gemini",
|
||||||
"image-generation": "Генерация изображений (OpenAI)",
|
"image-generation": "Изображение",
|
||||||
"jina-rerank": "Jina Rerank",
|
"jina-rerank": "Jina Rerank",
|
||||||
"openai": "OpenAI",
|
"openai": "OpenAI",
|
||||||
"openai-response": "OpenAI-Response"
|
"openai-response": "OpenAI-Response"
|
||||||
@@ -4372,7 +4371,7 @@
|
|||||||
"url": {
|
"url": {
|
||||||
"preview": "Предпросмотр: {{url}}",
|
"preview": "Предпросмотр: {{url}}",
|
||||||
"reset": "Сброс",
|
"reset": "Сброс",
|
||||||
"tip": "Добавьте # в конце, чтобы отключить автоматически добавляемую версию API."
|
"tip": "заканчивая на # принудительно использует введенный адрес"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api_host": "Хост API",
|
"api_host": "Хост API",
|
||||||
@@ -4511,6 +4510,23 @@
|
|||||||
"private_key_placeholder": "Введите приватный ключ Service Account",
|
"private_key_placeholder": "Введите приватный ключ Service Account",
|
||||||
"title": "Конфигурация Service Account"
|
"title": "Конфигурация Service Account"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"volcengine": {
|
||||||
|
"access_key_id": "[to be translated]:Access Key ID",
|
||||||
|
"access_key_id_help": "[to be translated]:Your Volcengine Access Key ID",
|
||||||
|
"clear_credentials": "[to be translated]:Clear Credentials",
|
||||||
|
"credentials_cleared": "[to be translated]:Credentials cleared",
|
||||||
|
"credentials_required": "[to be translated]:Please fill in Access Key ID and Secret Access Key",
|
||||||
|
"credentials_saved": "[to be translated]:Credentials saved",
|
||||||
|
"description": "[to be translated]:Volcengine is ByteDance's cloud service platform, providing Doubao and other large language model services. Use Access Key for authentication to fetch model list.",
|
||||||
|
"project_name": "[to be translated]:Project Name",
|
||||||
|
"project_name_help": "[to be translated]:Project name for endpoint filtering, default is 'default'",
|
||||||
|
"region": "[to be translated]:Region",
|
||||||
|
"region_help": "[to be translated]:Service region, e.g., cn-beijing",
|
||||||
|
"save_credentials": "[to be translated]:Save Credentials",
|
||||||
|
"secret_access_key": "[to be translated]:Secret Access Key",
|
||||||
|
"secret_access_key_help": "[to be translated]:Your Volcengine Secret Access Key, please keep it secure",
|
||||||
|
"title": "[to be translated]:Volcengine Configuration"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": {
|
"proxy": {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { getModel } from '@renderer/hooks/useModel'
|
|||||||
import { useSettings } from '@renderer/hooks/useSettings'
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import { useTextareaResize } from '@renderer/hooks/useTextareaResize'
|
import { useTextareaResize } from '@renderer/hooks/useTextareaResize'
|
||||||
import { useTimer } from '@renderer/hooks/useTimer'
|
import { useTimer } from '@renderer/hooks/useTimer'
|
||||||
import { CacheService } from '@renderer/services/CacheService'
|
|
||||||
import { pauseTrace } from '@renderer/services/SpanManagerService'
|
import { pauseTrace } from '@renderer/services/SpanManagerService'
|
||||||
import { estimateUserPromptUsage } from '@renderer/services/TokenService'
|
import { estimateUserPromptUsage } from '@renderer/services/TokenService'
|
||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
@@ -42,10 +41,19 @@ import { getInputbarConfig } from './registry'
|
|||||||
import { TopicType } from './types'
|
import { TopicType } from './types'
|
||||||
|
|
||||||
const logger = loggerService.withContext('AgentSessionInputbar')
|
const logger = loggerService.withContext('AgentSessionInputbar')
|
||||||
|
const agentSessionDraftCache = new Map<string, string>()
|
||||||
|
|
||||||
const DRAFT_CACHE_TTL = 24 * 60 * 60 * 1000 // 24 hours
|
const readDraftFromCache = (key: string): string => {
|
||||||
|
return agentSessionDraftCache.get(key) ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
const getAgentDraftCacheKey = (agentId: string) => `agent-session-draft-${agentId}`
|
const writeDraftToCache = (key: string, value: string) => {
|
||||||
|
if (!value) {
|
||||||
|
agentSessionDraftCache.delete(key)
|
||||||
|
} else {
|
||||||
|
agentSessionDraftCache.set(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
agentId: string
|
agentId: string
|
||||||
@@ -162,15 +170,16 @@ const AgentSessionInputbarInner: FC<InnerProps> = ({ assistant, agentId, session
|
|||||||
const scope = TopicType.Session
|
const scope = TopicType.Session
|
||||||
const config = getInputbarConfig(scope)
|
const config = getInputbarConfig(scope)
|
||||||
|
|
||||||
// Use shared hooks for text and textarea management with draft persistence
|
// Use shared hooks for text and textarea management
|
||||||
const draftCacheKey = getAgentDraftCacheKey(agentId)
|
const initialDraft = useMemo(() => readDraftFromCache(agentId), [agentId])
|
||||||
|
const persistDraft = useCallback((next: string) => writeDraftToCache(agentId, next), [agentId])
|
||||||
const {
|
const {
|
||||||
text,
|
text,
|
||||||
setText,
|
setText,
|
||||||
isEmpty: inputEmpty
|
isEmpty: inputEmpty
|
||||||
} = useInputText({
|
} = useInputText({
|
||||||
initialValue: CacheService.get<string>(draftCacheKey) ?? '',
|
initialValue: initialDraft,
|
||||||
onChange: (value) => CacheService.set(draftCacheKey, value, DRAFT_CACHE_TTL)
|
onChange: persistDraft
|
||||||
})
|
})
|
||||||
const {
|
const {
|
||||||
textareaRef,
|
textareaRef,
|
||||||
@@ -422,7 +431,6 @@ const AgentSessionInputbarInner: FC<InnerProps> = ({ assistant, agentId, session
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clear text after successful send (draft is cleared automatically via onChange)
|
|
||||||
setText('')
|
setText('')
|
||||||
setTimeoutTimer('agentSession_sendMessage', () => setText(''), 500)
|
setTimeoutTimer('agentSession_sendMessage', () => setText(''), 500)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { useInputText } from '@renderer/hooks/useInputText'
|
|||||||
import { useMessageOperations, useTopicLoading } from '@renderer/hooks/useMessageOperations'
|
import { useMessageOperations, useTopicLoading } from '@renderer/hooks/useMessageOperations'
|
||||||
import { useSettings } from '@renderer/hooks/useSettings'
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import { useShortcut } from '@renderer/hooks/useShortcuts'
|
import { useShortcut } from '@renderer/hooks/useShortcuts'
|
||||||
|
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
||||||
import { useTextareaResize } from '@renderer/hooks/useTextareaResize'
|
import { useTextareaResize } from '@renderer/hooks/useTextareaResize'
|
||||||
import { useTimer } from '@renderer/hooks/useTimer'
|
import { useTimer } from '@renderer/hooks/useTimer'
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +24,6 @@ import {
|
|||||||
useInputbarToolsState
|
useInputbarToolsState
|
||||||
} from '@renderer/pages/home/Inputbar/context/InputbarToolsProvider'
|
} from '@renderer/pages/home/Inputbar/context/InputbarToolsProvider'
|
||||||
import { getDefaultTopic } from '@renderer/services/AssistantService'
|
import { getDefaultTopic } from '@renderer/services/AssistantService'
|
||||||
import { CacheService } from '@renderer/services/CacheService'
|
|
||||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||||
import FileManager from '@renderer/services/FileManager'
|
import FileManager from '@renderer/services/FileManager'
|
||||||
import { checkRateLimit, getUserMessage } from '@renderer/services/MessagesService'
|
import { checkRateLimit, getUserMessage } from '@renderer/services/MessagesService'
|
||||||
@@ -39,7 +39,7 @@ import { getSendMessageShortcutLabel } from '@renderer/utils/input'
|
|||||||
import { documentExts, imageExts, textExts } from '@shared/config/constant'
|
import { documentExts, imageExts, textExts } from '@shared/config/constant'
|
||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { InputbarCore } from './components/InputbarCore'
|
import { InputbarCore } from './components/InputbarCore'
|
||||||
@@ -51,17 +51,6 @@ import TokenCount from './TokenCount'
|
|||||||
|
|
||||||
const logger = loggerService.withContext('Inputbar')
|
const logger = loggerService.withContext('Inputbar')
|
||||||
|
|
||||||
const INPUTBAR_DRAFT_CACHE_KEY = 'inputbar-draft'
|
|
||||||
const DRAFT_CACHE_TTL = 24 * 60 * 60 * 1000 // 24 hours
|
|
||||||
|
|
||||||
const getMentionedModelsCacheKey = (assistantId: string) => `inputbar-mentioned-models-${assistantId}`
|
|
||||||
|
|
||||||
const getValidatedCachedModels = (assistantId: string): Model[] => {
|
|
||||||
const cached = CacheService.get<Model[]>(getMentionedModelsCacheKey(assistantId))
|
|
||||||
if (!Array.isArray(cached)) return []
|
|
||||||
return cached.filter((model) => model?.id && model?.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
assistant: Assistant
|
assistant: Assistant
|
||||||
setActiveTopic: (topic: Topic) => void
|
setActiveTopic: (topic: Topic) => void
|
||||||
@@ -91,18 +80,16 @@ const Inputbar: FC<Props> = ({ assistant: initialAssistant, setActiveTopic, topi
|
|||||||
toggleExpanded: () => {}
|
toggleExpanded: () => {}
|
||||||
})
|
})
|
||||||
|
|
||||||
const [initialMentionedModels] = useState(() => getValidatedCachedModels(initialAssistant.id))
|
|
||||||
|
|
||||||
const initialState = useMemo(
|
const initialState = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
files: [] as FileType[],
|
files: [] as FileType[],
|
||||||
mentionedModels: initialMentionedModels,
|
mentionedModels: [] as Model[],
|
||||||
selectedKnowledgeBases: initialAssistant.knowledge_bases ?? [],
|
selectedKnowledgeBases: initialAssistant.knowledge_bases ?? [],
|
||||||
isExpanded: false,
|
isExpanded: false,
|
||||||
couldAddImageFile: false,
|
couldAddImageFile: false,
|
||||||
extensions: [] as string[]
|
extensions: [] as string[]
|
||||||
}),
|
}),
|
||||||
[initialMentionedModels, initialAssistant.knowledge_bases]
|
[initialAssistant.knowledge_bases]
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -134,10 +121,7 @@ const InputbarInner: FC<InputbarInnerProps> = ({ assistant: initialAssistant, se
|
|||||||
const { setFiles, setMentionedModels, setSelectedKnowledgeBases } = useInputbarToolsDispatch()
|
const { setFiles, setMentionedModels, setSelectedKnowledgeBases } = useInputbarToolsDispatch()
|
||||||
const { setCouldAddImageFile } = useInputbarToolsInternalDispatch()
|
const { setCouldAddImageFile } = useInputbarToolsInternalDispatch()
|
||||||
|
|
||||||
const { text, setText } = useInputText({
|
const { text, setText } = useInputText()
|
||||||
initialValue: CacheService.get<string>(INPUTBAR_DRAFT_CACHE_KEY) ?? '',
|
|
||||||
onChange: (value) => CacheService.set(INPUTBAR_DRAFT_CACHE_KEY, value, DRAFT_CACHE_TTL)
|
|
||||||
})
|
|
||||||
const {
|
const {
|
||||||
textareaRef,
|
textareaRef,
|
||||||
resize: resizeTextArea,
|
resize: resizeTextArea,
|
||||||
@@ -149,6 +133,7 @@ const InputbarInner: FC<InputbarInnerProps> = ({ assistant: initialAssistant, se
|
|||||||
minHeight: 30
|
minHeight: 30
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const showKnowledgeIcon = useSidebarIconShow('knowledge')
|
||||||
const { assistant, addTopic, model, setModel, updateAssistant } = useAssistant(initialAssistant.id)
|
const { assistant, addTopic, model, setModel, updateAssistant } = useAssistant(initialAssistant.id)
|
||||||
const { sendMessageShortcut, showInputEstimatedTokens, enableQuickPanelTriggers } = useSettings()
|
const { sendMessageShortcut, showInputEstimatedTokens, enableQuickPanelTriggers } = useSettings()
|
||||||
const [estimateTokenCount, setEstimateTokenCount] = useState(0)
|
const [estimateTokenCount, setEstimateTokenCount] = useState(0)
|
||||||
@@ -205,15 +190,6 @@ const InputbarInner: FC<InputbarInnerProps> = ({ assistant: initialAssistant, se
|
|||||||
setCouldAddImageFile(canAddImageFile)
|
setCouldAddImageFile(canAddImageFile)
|
||||||
}, [canAddImageFile, setCouldAddImageFile])
|
}, [canAddImageFile, setCouldAddImageFile])
|
||||||
|
|
||||||
const onUnmount = useEffectEvent((id: string) => {
|
|
||||||
CacheService.set(getMentionedModelsCacheKey(id), mentionedModels, DRAFT_CACHE_TTL)
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => onUnmount(assistant.id)
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [assistant.id])
|
|
||||||
|
|
||||||
const placeholderText = enableQuickPanelTriggers
|
const placeholderText = enableQuickPanelTriggers
|
||||||
? t('chat.input.placeholder', { key: getSendMessageShortcutLabel(sendMessageShortcut) })
|
? t('chat.input.placeholder', { key: getSendMessageShortcutLabel(sendMessageShortcut) })
|
||||||
: t('chat.input.placeholder_without_triggers', {
|
: t('chat.input.placeholder_without_triggers', {
|
||||||
@@ -405,10 +381,9 @@ const InputbarInner: FC<InputbarInnerProps> = ({ assistant: initialAssistant, se
|
|||||||
focusTextarea
|
focusTextarea
|
||||||
])
|
])
|
||||||
|
|
||||||
// TODO: Just use assistant.knowledge_bases as selectedKnowledgeBases. context state is overdesigned.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedKnowledgeBases(assistant.knowledge_bases ?? [])
|
setSelectedKnowledgeBases(showKnowledgeIcon ? (assistant.knowledge_bases ?? []) : [])
|
||||||
}, [assistant.knowledge_bases, setSelectedKnowledgeBases])
|
}, [assistant.knowledge_bases, setSelectedKnowledgeBases, showKnowledgeIcon])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Disable web search if model doesn't support it
|
// Disable web search if model doesn't support it
|
||||||
|
|||||||
@@ -156,8 +156,11 @@ export const InputbarCore: FC<InputbarCoreProps> = ({
|
|||||||
|
|
||||||
const setText = useCallback<React.Dispatch<React.SetStateAction<string>>>(
|
const setText = useCallback<React.Dispatch<React.SetStateAction<string>>>(
|
||||||
(value) => {
|
(value) => {
|
||||||
const newText = typeof value === 'function' ? value(textRef.current) : value
|
if (typeof value === 'function') {
|
||||||
onTextChange(newText)
|
onTextChange(value(textRef.current))
|
||||||
|
} else {
|
||||||
|
onTextChange(value)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[onTextChange]
|
[onTextChange]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||||
|
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
||||||
import { defineTool, registerTool, TopicType } from '@renderer/pages/home/Inputbar/types'
|
import { defineTool, registerTool, TopicType } from '@renderer/pages/home/Inputbar/types'
|
||||||
import type { KnowledgeBase } from '@renderer/types'
|
import type { KnowledgeBase } from '@renderer/types'
|
||||||
import { isPromptToolUse, isSupportedToolUse } from '@renderer/utils/mcp-tools'
|
import { isPromptToolUse, isSupportedToolUse } from '@renderer/utils/mcp-tools'
|
||||||
@@ -29,6 +30,7 @@ const knowledgeBaseTool = defineTool({
|
|||||||
render: function KnowledgeBaseToolRender(context) {
|
render: function KnowledgeBaseToolRender(context) {
|
||||||
const { assistant, state, actions, quickPanel } = context
|
const { assistant, state, actions, quickPanel } = context
|
||||||
|
|
||||||
|
const knowledgeSidebarEnabled = useSidebarIconShow('knowledge')
|
||||||
const { updateAssistant } = useAssistant(assistant.id)
|
const { updateAssistant } = useAssistant(assistant.id)
|
||||||
|
|
||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
@@ -39,6 +41,10 @@ const knowledgeBaseTool = defineTool({
|
|||||||
[updateAssistant, actions]
|
[updateAssistant, actions]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!knowledgeSidebarEnabled) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KnowledgeBaseButton
|
<KnowledgeBaseButton
|
||||||
quickPanel={quickPanel}
|
quickPanel={quickPanel}
|
||||||
|
|||||||
@@ -102,12 +102,10 @@ const ThinkingBlock: React.FC<Props> = ({ block }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizeThinkingTime = (value?: number) => (typeof value === 'number' && Number.isFinite(value) ? value : 0)
|
|
||||||
|
|
||||||
const ThinkingTimeSeconds = memo(
|
const ThinkingTimeSeconds = memo(
|
||||||
({ blockThinkingTime, isThinking }: { blockThinkingTime: number; isThinking: boolean }) => {
|
({ blockThinkingTime, isThinking }: { blockThinkingTime: number; isThinking: boolean }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [displayTime, setDisplayTime] = useState(normalizeThinkingTime(blockThinkingTime))
|
const [displayTime, setDisplayTime] = useState(blockThinkingTime)
|
||||||
|
|
||||||
const timer = useRef<NodeJS.Timeout | null>(null)
|
const timer = useRef<NodeJS.Timeout | null>(null)
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ const ThinkingTimeSeconds = memo(
|
|||||||
clearInterval(timer.current)
|
clearInterval(timer.current)
|
||||||
timer.current = null
|
timer.current = null
|
||||||
}
|
}
|
||||||
setDisplayTime(normalizeThinkingTime(blockThinkingTime))
|
setDisplayTime(blockThinkingTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@@ -134,10 +132,10 @@ const ThinkingTimeSeconds = memo(
|
|||||||
}
|
}
|
||||||
}, [isThinking, blockThinkingTime])
|
}, [isThinking, blockThinkingTime])
|
||||||
|
|
||||||
const thinkingTimeSeconds = useMemo(() => {
|
const thinkingTimeSeconds = useMemo(
|
||||||
const safeTime = normalizeThinkingTime(displayTime)
|
() => ((displayTime < 1000 ? 100 : displayTime) / 1000).toFixed(1),
|
||||||
return ((safeTime < 1000 ? 100 : safeTime) / 1000).toFixed(1)
|
[displayTime]
|
||||||
}, [displayTime])
|
)
|
||||||
|
|
||||||
return isThinking
|
return isThinking
|
||||||
? t('chat.thinking', {
|
? t('chat.thinking', {
|
||||||
|
|||||||
@@ -255,20 +255,6 @@ describe('ThinkingBlock', () => {
|
|||||||
unmount()
|
unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should clamp invalid thinking times to a safe default', () => {
|
|
||||||
const testCases = [undefined, Number.NaN, Number.POSITIVE_INFINITY]
|
|
||||||
|
|
||||||
testCases.forEach((thinking_millsec) => {
|
|
||||||
const block = createThinkingBlock({
|
|
||||||
thinking_millsec: thinking_millsec as any,
|
|
||||||
status: MessageBlockStatus.SUCCESS
|
|
||||||
})
|
|
||||||
const { unmount } = renderThinkingBlock(block)
|
|
||||||
expect(getThinkingTimeText()).toHaveTextContent('0.1s')
|
|
||||||
unmount()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('collapse behavior', () => {
|
describe('collapse behavior', () => {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { useSettings } from '@renderer/hooks/useSettings'
|
|||||||
import { useTimer } from '@renderer/hooks/useTimer'
|
import { useTimer } from '@renderer/hooks/useTimer'
|
||||||
import type { RootState } from '@renderer/store'
|
import type { RootState } from '@renderer/store'
|
||||||
// import { selectCurrentTopicId } from '@renderer/store/newMessage'
|
// import { selectCurrentTopicId } from '@renderer/store/newMessage'
|
||||||
import { scrollIntoView } from '@renderer/utils/dom'
|
|
||||||
import { Button, Drawer, Tooltip } from 'antd'
|
import { Button, Drawer, Tooltip } from 'antd'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
@@ -119,8 +118,7 @@ const ChatNavigation: FC<ChatNavigationProps> = ({ containerId }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scrollToMessage = (element: HTMLElement) => {
|
const scrollToMessage = (element: HTMLElement) => {
|
||||||
// Use container: 'nearest' to keep scroll within the chat pane (Chromium-only, see #11565, #11567)
|
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
scrollIntoView(element, { behavior: 'smooth', block: 'start', container: 'nearest' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrollToTop = () => {
|
const scrollToTop = () => {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { estimateMessageUsage } from '@renderer/services/TokenService'
|
|||||||
import type { Assistant, Topic } from '@renderer/types'
|
import type { Assistant, Topic } from '@renderer/types'
|
||||||
import type { Message, MessageBlock } from '@renderer/types/newMessage'
|
import type { Message, MessageBlock } from '@renderer/types/newMessage'
|
||||||
import { classNames, cn } from '@renderer/utils'
|
import { classNames, cn } from '@renderer/utils'
|
||||||
import { scrollIntoView } from '@renderer/utils/dom'
|
|
||||||
import { isMessageProcessing } from '@renderer/utils/messageUtils/is'
|
import { isMessageProcessing } from '@renderer/utils/messageUtils/is'
|
||||||
import { Divider } from 'antd'
|
import { Divider } from 'antd'
|
||||||
import type { Dispatch, FC, SetStateAction } from 'react'
|
import type { Dispatch, FC, SetStateAction } from 'react'
|
||||||
@@ -80,10 +79,9 @@ const MessageItem: FC<Props> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEditing && messageContainerRef.current) {
|
if (isEditing && messageContainerRef.current) {
|
||||||
scrollIntoView(messageContainerRef.current, {
|
messageContainerRef.current.scrollIntoView({
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
block: 'center',
|
block: 'center'
|
||||||
container: 'nearest'
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [isEditing])
|
}, [isEditing])
|
||||||
@@ -126,7 +124,7 @@ const MessageItem: FC<Props> = ({
|
|||||||
const messageHighlightHandler = useCallback(
|
const messageHighlightHandler = useCallback(
|
||||||
(highlight: boolean = true) => {
|
(highlight: boolean = true) => {
|
||||||
if (messageContainerRef.current) {
|
if (messageContainerRef.current) {
|
||||||
scrollIntoView(messageContainerRef.current, { behavior: 'smooth', block: 'center', container: 'nearest' })
|
messageContainerRef.current.scrollIntoView({ behavior: 'smooth' })
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
setTimeoutTimer(
|
setTimeoutTimer(
|
||||||
'messageHighlightHandler',
|
'messageHighlightHandler',
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { newMessagesActions } from '@renderer/store/newMessage'
|
|||||||
// import { updateMessageThunk } from '@renderer/store/thunk/messageThunk'
|
// import { updateMessageThunk } from '@renderer/store/thunk/messageThunk'
|
||||||
import type { Message } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
import { isEmoji, removeLeadingEmoji } from '@renderer/utils'
|
import { isEmoji, removeLeadingEmoji } from '@renderer/utils'
|
||||||
import { scrollIntoView } from '@renderer/utils/dom'
|
|
||||||
import { getMainTextContent } from '@renderer/utils/messageUtils/find'
|
import { getMainTextContent } from '@renderer/utils/messageUtils/find'
|
||||||
import { Avatar } from 'antd'
|
import { Avatar } from 'antd'
|
||||||
import { CircleChevronDown } from 'lucide-react'
|
import { CircleChevronDown } from 'lucide-react'
|
||||||
@@ -120,7 +119,7 @@ const MessageAnchorLine: FC<MessageLineProps> = ({ messages }) => {
|
|||||||
() => {
|
() => {
|
||||||
const messageElement = document.getElementById(`message-${message.id}`)
|
const messageElement = document.getElementById(`message-${message.id}`)
|
||||||
if (messageElement) {
|
if (messageElement) {
|
||||||
scrollIntoView(messageElement, { behavior: 'auto', block: 'start', container: 'nearest' })
|
messageElement.scrollIntoView({ behavior: 'auto', block: 'start' })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
100
|
100
|
||||||
@@ -142,7 +141,7 @@ const MessageAnchorLine: FC<MessageLineProps> = ({ messages }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollIntoView(messageElement, { behavior: 'smooth', block: 'start', container: 'nearest' })
|
messageElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
},
|
},
|
||||||
[setSelectedMessage]
|
[setSelectedMessage]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type { MultiModelMessageStyle } from '@renderer/store/settings'
|
|||||||
import type { Topic } from '@renderer/types'
|
import type { Topic } from '@renderer/types'
|
||||||
import type { Message } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
import { classNames } from '@renderer/utils'
|
import { classNames } from '@renderer/utils'
|
||||||
import { scrollIntoView } from '@renderer/utils/dom'
|
|
||||||
import { Popover } from 'antd'
|
import { Popover } from 'antd'
|
||||||
import type { ComponentProps } from 'react'
|
import type { ComponentProps } from 'react'
|
||||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
@@ -74,7 +73,7 @@ const MessageGroup = ({ messages, topic, registerMessageElement }: Props) => {
|
|||||||
() => {
|
() => {
|
||||||
const messageElement = document.getElementById(`message-${message.id}`)
|
const messageElement = document.getElementById(`message-${message.id}`)
|
||||||
if (messageElement) {
|
if (messageElement) {
|
||||||
scrollIntoView(messageElement, { behavior: 'smooth', block: 'start', container: 'nearest' })
|
messageElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
200
|
200
|
||||||
@@ -133,7 +132,7 @@ const MessageGroup = ({ messages, topic, registerMessageElement }: Props) => {
|
|||||||
setSelectedMessage(message)
|
setSelectedMessage(message)
|
||||||
} else {
|
} else {
|
||||||
// 直接滚动
|
// 直接滚动
|
||||||
scrollIntoView(element, { behavior: 'smooth', block: 'start', container: 'nearest' })
|
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type { RootState } from '@renderer/store'
|
|||||||
import { messageBlocksSelectors } from '@renderer/store/messageBlock'
|
import { messageBlocksSelectors } from '@renderer/store/messageBlock'
|
||||||
import type { Message } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
import { MessageBlockType } from '@renderer/types/newMessage'
|
import { MessageBlockType } from '@renderer/types/newMessage'
|
||||||
import { scrollIntoView } from '@renderer/utils/dom'
|
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useMemo, useRef } from 'react'
|
import React, { useMemo, useRef } from 'react'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
@@ -73,10 +72,10 @@ const MessageOutline: FC<MessageOutlineProps> = ({ message }) => {
|
|||||||
const parent = messageOutlineContainerRef.current?.parentElement
|
const parent = messageOutlineContainerRef.current?.parentElement
|
||||||
const messageContentContainer = parent?.querySelector('.message-content-container')
|
const messageContentContainer = parent?.querySelector('.message-content-container')
|
||||||
if (messageContentContainer) {
|
if (messageContentContainer) {
|
||||||
const headingElement = messageContentContainer.querySelector<HTMLElement>(`#${id}`)
|
const headingElement = messageContentContainer.querySelector(`#${id}`)
|
||||||
if (headingElement) {
|
if (headingElement) {
|
||||||
const scrollBlock = ['horizontal', 'grid'].includes(message.multiModelMessageStyle ?? '') ? 'nearest' : 'start'
|
const scrollBlock = ['horizontal', 'grid'].includes(message.multiModelMessageStyle ?? '') ? 'nearest' : 'start'
|
||||||
scrollIntoView(headingElement, { behavior: 'smooth', block: scrollBlock, container: 'nearest' })
|
headingElement.scrollIntoView({ behavior: 'smooth', block: scrollBlock })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export function BashOutputTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: BashOutputToolInput
|
input: BashOutputToolInput
|
||||||
output?: BashOutputToolOutput
|
output?: BashOutputToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
const parsedOutput = parseBashOutput(output)
|
const parsedOutput = parseBashOutput(output)
|
||||||
@@ -144,7 +144,7 @@ export function BashOutputTool({
|
|||||||
label="Bash Output"
|
label="Bash Output"
|
||||||
params={
|
params={
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Tag className="py-0 font-mono text-xs">{input?.bash_id}</Tag>
|
<Tag className="py-0 font-mono text-xs">{input.bash_id}</Tag>
|
||||||
{statusConfig && (
|
{statusConfig && (
|
||||||
<Tag
|
<Tag
|
||||||
color={statusConfig.color}
|
color={statusConfig.color}
|
||||||
|
|||||||
@@ -5,20 +5,24 @@ import { Terminal } from 'lucide-react'
|
|||||||
import { ToolTitle } from './GenericTools'
|
import { ToolTitle } from './GenericTools'
|
||||||
import type { BashToolInput as BashToolInputType, BashToolOutput as BashToolOutputType } from './types'
|
import type { BashToolInput as BashToolInputType, BashToolOutput as BashToolOutputType } from './types'
|
||||||
|
|
||||||
|
const MAX_TAG_LENGTH = 100
|
||||||
|
|
||||||
export function BashTool({
|
export function BashTool({
|
||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: BashToolInputType
|
input: BashToolInputType
|
||||||
output?: BashToolOutputType
|
output?: BashToolOutputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
// 如果有输出,计算输出行数
|
// 如果有输出,计算输出行数
|
||||||
const outputLines = output ? output.split('\n').length : 0
|
const outputLines = output ? output.split('\n').length : 0
|
||||||
|
|
||||||
// 处理命令字符串,添加空值检查
|
// 处理命令字符串的截断
|
||||||
const command = input?.command ?? ''
|
const command = input.command
|
||||||
|
const needsTruncate = command.length > MAX_TAG_LENGTH
|
||||||
|
const displayCommand = needsTruncate ? `${command.slice(0, MAX_TAG_LENGTH)}...` : command
|
||||||
|
|
||||||
const tagContent = <Tag className="!m-0 max-w-full truncate font-mono">{command}</Tag>
|
const tagContent = <Tag className="whitespace-pre-wrap break-all font-mono">{displayCommand}</Tag>
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: 'tool',
|
key: 'tool',
|
||||||
@@ -27,15 +31,19 @@ export function BashTool({
|
|||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<Terminal className="h-4 w-4" />}
|
icon={<Terminal className="h-4 w-4" />}
|
||||||
label="Bash"
|
label="Bash"
|
||||||
params={input?.description}
|
params={input.description}
|
||||||
stats={output ? `${outputLines} ${outputLines === 1 ? 'line' : 'lines'}` : undefined}
|
stats={output ? `${outputLines} ${outputLines === 1 ? 'line' : 'lines'}` : undefined}
|
||||||
/>
|
/>
|
||||||
<div className="mt-1 max-w-full">
|
<div className="mt-1">
|
||||||
<Popover
|
{needsTruncate ? (
|
||||||
content={<div className="max-w-xl whitespace-pre-wrap break-all font-mono text-xs">{command}</div>}
|
<Popover
|
||||||
trigger="hover">
|
content={<div className="max-w-xl whitespace-pre-wrap break-all font-mono">{command}</div>}
|
||||||
{tagContent}
|
trigger="hover">
|
||||||
</Popover>
|
{tagContent}
|
||||||
|
</Popover>
|
||||||
|
) : (
|
||||||
|
tagContent
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -32,19 +32,19 @@ export function EditTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: EditToolInput
|
input: EditToolInput
|
||||||
output?: EditToolOutput
|
output?: EditToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
key: AgentToolsType.Edit,
|
key: AgentToolsType.Edit,
|
||||||
label: <ToolTitle icon={<FileEdit className="h-4 w-4" />} label="Edit" params={input?.file_path} />,
|
label: <ToolTitle icon={<FileEdit className="h-4 w-4" />} label="Edit" params={input.file_path} />,
|
||||||
children: (
|
children: (
|
||||||
<>
|
<>
|
||||||
{/* Diff View */}
|
{/* Diff View */}
|
||||||
{/* Old Content */}
|
{/* Old Content */}
|
||||||
{renderCodeBlock(input?.old_string ?? '', 'old')}
|
{renderCodeBlock(input.old_string, 'old')}
|
||||||
{/* New Content */}
|
{/* New Content */}
|
||||||
{renderCodeBlock(input?.new_string ?? '', 'new')}
|
{renderCodeBlock(input.new_string, 'new')}
|
||||||
{/* Output */}
|
{/* Output */}
|
||||||
{output}
|
{output}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -10,19 +10,18 @@ export function ExitPlanModeTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: ExitPlanModeToolInput
|
input: ExitPlanModeToolInput
|
||||||
output?: ExitPlanModeToolOutput
|
output?: ExitPlanModeToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
const plan = input?.plan ?? ''
|
|
||||||
return {
|
return {
|
||||||
key: AgentToolsType.ExitPlanMode,
|
key: AgentToolsType.ExitPlanMode,
|
||||||
label: (
|
label: (
|
||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<DoorOpen className="h-4 w-4" />}
|
icon={<DoorOpen className="h-4 w-4" />}
|
||||||
label="ExitPlanMode"
|
label="ExitPlanMode"
|
||||||
stats={`${plan.split('\n\n').length} plans`}
|
stats={`${input.plan.split('\n\n').length} plans`}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
children: <ReactMarkdown>{plan + '\n\n' + (output ?? '')}</ReactMarkdown>
|
children: <ReactMarkdown>{input.plan + '\n\n' + (output ?? '')}</ReactMarkdown>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ export function ToolTitle({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={`flex items-center gap-1 ${className}`}>
|
<div className={`flex items-center gap-1 ${className}`}>
|
||||||
{icon && <span className="flex flex-shrink-0">{icon}</span>}
|
{icon}
|
||||||
{label && <span className="flex-shrink-0 font-medium text-sm">{label}</span>}
|
{label && <span className="font-medium text-sm">{label}</span>}
|
||||||
{params && <span className="min-w-0 truncate text-muted-foreground text-xs">{params}</span>}
|
{params && <span className="flex-shrink-0 text-muted-foreground text-xs">{params}</span>}
|
||||||
{stats && <span className="flex-shrink-0 text-muted-foreground text-xs">{stats}</span>}
|
{stats && <span className="flex-shrink-0 text-muted-foreground text-xs">{stats}</span>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function GlobTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: GlobToolInputType
|
input: GlobToolInputType
|
||||||
output?: GlobToolOutputType
|
output?: GlobToolOutputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
// 如果有输出,计算文件数量
|
// 如果有输出,计算文件数量
|
||||||
@@ -20,7 +20,7 @@ export function GlobTool({
|
|||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<FolderSearch className="h-4 w-4" />}
|
icon={<FolderSearch className="h-4 w-4" />}
|
||||||
label="Glob"
|
label="Glob"
|
||||||
params={input?.pattern}
|
params={input.pattern}
|
||||||
stats={output ? `${lineCount} ${lineCount === 1 ? 'file' : 'files'}` : undefined}
|
stats={output ? `${lineCount} ${lineCount === 1 ? 'file' : 'files'}` : undefined}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function GrepTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: GrepToolInput
|
input: GrepToolInput
|
||||||
output?: GrepToolOutput
|
output?: GrepToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
// 如果有输出,计算结果行数
|
// 如果有输出,计算结果行数
|
||||||
@@ -22,8 +22,8 @@ export function GrepTool({
|
|||||||
label="Grep"
|
label="Grep"
|
||||||
params={
|
params={
|
||||||
<>
|
<>
|
||||||
{input?.pattern}
|
{input.pattern}
|
||||||
{input?.output_mode && <span className="ml-1">({input.output_mode})</span>}
|
{input.output_mode && <span className="ml-1">({input.output_mode})</span>}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
stats={output ? `${resultLines} ${resultLines === 1 ? 'line' : 'lines'}` : undefined}
|
stats={output ? `${resultLines} ${resultLines === 1 ? 'line' : 'lines'}` : undefined}
|
||||||
|
|||||||
@@ -9,19 +9,18 @@ import { AgentToolsType } from './types'
|
|||||||
export function MultiEditTool({
|
export function MultiEditTool({
|
||||||
input
|
input
|
||||||
}: {
|
}: {
|
||||||
input?: MultiEditToolInput
|
input: MultiEditToolInput
|
||||||
output?: MultiEditToolOutput
|
output?: MultiEditToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
const edits = Array.isArray(input?.edits) ? input.edits : []
|
|
||||||
return {
|
return {
|
||||||
key: AgentToolsType.MultiEdit,
|
key: AgentToolsType.MultiEdit,
|
||||||
label: <ToolTitle icon={<FileText className="h-4 w-4" />} label="MultiEdit" params={input?.file_path} />,
|
label: <ToolTitle icon={<FileText className="h-4 w-4" />} label="MultiEdit" params={input.file_path} />,
|
||||||
children: (
|
children: (
|
||||||
<div>
|
<div>
|
||||||
{edits.map((edit, index) => (
|
{input.edits.map((edit, index) => (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
{renderCodeBlock(edit.old_string ?? '', 'old')}
|
{renderCodeBlock(edit.old_string, 'old')}
|
||||||
{renderCodeBlock(edit.new_string ?? '', 'new')}
|
{renderCodeBlock(edit.new_string, 'new')}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export function NotebookEditTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: NotebookEditToolInput
|
input: NotebookEditToolInput
|
||||||
output?: NotebookEditToolOutput
|
output?: NotebookEditToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
@@ -20,10 +20,10 @@ export function NotebookEditTool({
|
|||||||
<>
|
<>
|
||||||
<ToolTitle icon={<FileText className="h-4 w-4" />} label="NotebookEdit" />
|
<ToolTitle icon={<FileText className="h-4 w-4" />} label="NotebookEdit" />
|
||||||
<Tag className="mt-1" color="blue">
|
<Tag className="mt-1" color="blue">
|
||||||
{input?.notebook_path}{' '}
|
{input.notebook_path}{' '}
|
||||||
</Tag>
|
</Tag>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
children: <ReactMarkdown>{output ?? ''}</ReactMarkdown>
|
children: <ReactMarkdown>{output}</ReactMarkdown>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function ReadTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: ReadToolInputType
|
input: ReadToolInputType
|
||||||
output?: ReadToolOutputType
|
output?: ReadToolOutputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
const outputString = normalizeOutputString(output)
|
const outputString = normalizeOutputString(output)
|
||||||
@@ -58,7 +58,7 @@ export function ReadTool({
|
|||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<FileText className="h-4 w-4" />}
|
icon={<FileText className="h-4 w-4" />}
|
||||||
label="Read File"
|
label="Read File"
|
||||||
params={input?.file_path?.split('/').pop()}
|
params={input.file_path.split('/').pop()}
|
||||||
stats={stats ? `${stats.lineCount} lines, ${stats.formatSize(stats.fileSize)}` : undefined}
|
stats={stats ? `${stats.lineCount} lines, ${stats.formatSize(stats.fileSize)}` : undefined}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function SearchTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: SearchToolInputType
|
input: SearchToolInputType
|
||||||
output?: SearchToolOutputType
|
output?: SearchToolOutputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
// 如果有输出,计算结果数量
|
// 如果有输出,计算结果数量
|
||||||
@@ -20,13 +20,13 @@ export function SearchTool({
|
|||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<Search className="h-4 w-4" />}
|
icon={<Search className="h-4 w-4" />}
|
||||||
label="Search"
|
label="Search"
|
||||||
params={input ? `"${input}"` : undefined}
|
params={`"${input}"`}
|
||||||
stats={output ? `${resultCount} ${resultCount === 1 ? 'result' : 'results'}` : undefined}
|
stats={output ? `${resultCount} ${resultCount === 1 ? 'result' : 'results'}` : undefined}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
children: (
|
children: (
|
||||||
<div>
|
<div>
|
||||||
{input && <StringInputTool input={input} label="Search Query" />}
|
<StringInputTool input={input} label="Search Query" />
|
||||||
{output && (
|
{output && (
|
||||||
<div>
|
<div>
|
||||||
<StringOutputTool output={output} label="Search Results" textColor="text-yellow-600 dark:text-yellow-400" />
|
<StringOutputTool output={output} label="Search Results" textColor="text-yellow-600 dark:text-yellow-400" />
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ export function SkillTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: SkillToolInput
|
input: SkillToolInput
|
||||||
output?: SkillToolOutput
|
output?: SkillToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
key: 'tool',
|
key: 'tool',
|
||||||
label: <ToolTitle icon={<PencilRuler className="h-4 w-4" />} label="Skill" params={input?.command} />,
|
label: <ToolTitle icon={<PencilRuler className="h-4 w-4" />} label="Skill" params={input.command} />,
|
||||||
children: <div>{output}</div>
|
children: <div>{output}</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,19 @@ export function TaskTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: TaskToolInputType
|
input: TaskToolInputType
|
||||||
output?: TaskToolOutputType
|
output?: TaskToolOutputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
key: 'tool',
|
key: 'tool',
|
||||||
label: <ToolTitle icon={<Bot className="h-4 w-4" />} label="Task" params={input?.description} />,
|
label: <ToolTitle icon={<Bot className="h-4 w-4" />} label="Task" params={input.description} />,
|
||||||
children: (
|
children: (
|
||||||
<div>
|
<div>
|
||||||
{Array.isArray(output) &&
|
{output?.map((item) => (
|
||||||
output.map((item) => (
|
<div key={item.type}>
|
||||||
<div key={item.type}>
|
<div>{item.type === 'text' ? <Markdown>{item.text}</Markdown> : item.text}</div>
|
||||||
<div>{item.type === 'text' ? <Markdown>{item.text}</Markdown> : item.text}</div>
|
</div>
|
||||||
</div>
|
))}
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ const getStatusConfig = (status: TodoItem['status']) => {
|
|||||||
export function TodoWriteTool({
|
export function TodoWriteTool({
|
||||||
input
|
input
|
||||||
}: {
|
}: {
|
||||||
input?: TodoWriteToolInputType
|
input: TodoWriteToolInputType
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
const todos = Array.isArray(input?.todos) ? input.todos : []
|
const doneCount = input.todos.filter((todo) => todo.status === 'completed').length
|
||||||
const doneCount = todos.filter((todo) => todo.status === 'completed').length
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: AgentToolsType.TodoWrite,
|
key: AgentToolsType.TodoWrite,
|
||||||
@@ -50,12 +49,12 @@ export function TodoWriteTool({
|
|||||||
icon={<ListTodo className="h-4 w-4" />}
|
icon={<ListTodo className="h-4 w-4" />}
|
||||||
label="Todo Write"
|
label="Todo Write"
|
||||||
params={`${doneCount} Done`}
|
params={`${doneCount} Done`}
|
||||||
stats={`${todos.length} ${todos.length === 1 ? 'item' : 'items'}`}
|
stats={`${input.todos.length} ${input.todos.length === 1 ? 'item' : 'items'}`}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
children: (
|
children: (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{todos.map((todo, index) => {
|
{input.todos.map((todo, index) => {
|
||||||
const statusConfig = getStatusConfig(todo.status)
|
const statusConfig = getStatusConfig(todo.status)
|
||||||
return (
|
return (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ export function WebFetchTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: WebFetchToolInput
|
input: WebFetchToolInput
|
||||||
output?: WebFetchToolOutput
|
output?: WebFetchToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
key: 'tool',
|
key: 'tool',
|
||||||
label: <ToolTitle icon={<Globe className="h-4 w-4" />} label="Web Fetch" params={input?.url} />,
|
label: <ToolTitle icon={<Globe className="h-4 w-4" />} label="Web Fetch" params={input.url} />,
|
||||||
children: <div>{output}</div>
|
children: <div>{output}</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function WebSearchTool({
|
|||||||
input,
|
input,
|
||||||
output
|
output
|
||||||
}: {
|
}: {
|
||||||
input?: WebSearchToolInput
|
input: WebSearchToolInput
|
||||||
output?: WebSearchToolOutput
|
output?: WebSearchToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
// 如果有输出,计算结果数量
|
// 如果有输出,计算结果数量
|
||||||
@@ -20,7 +20,7 @@ export function WebSearchTool({
|
|||||||
<ToolTitle
|
<ToolTitle
|
||||||
icon={<Globe className="h-4 w-4" />}
|
icon={<Globe className="h-4 w-4" />}
|
||||||
label="Web Search"
|
label="Web Search"
|
||||||
params={input?.query}
|
params={input.query}
|
||||||
stats={output ? `${resultCount} ${resultCount === 1 ? 'result' : 'results'}` : undefined}
|
stats={output ? `${resultCount} ${resultCount === 1 ? 'result' : 'results'}` : undefined}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import type { WriteToolInput, WriteToolOutput } from './types'
|
|||||||
export function WriteTool({
|
export function WriteTool({
|
||||||
input
|
input
|
||||||
}: {
|
}: {
|
||||||
input?: WriteToolInput
|
input: WriteToolInput
|
||||||
output?: WriteToolOutput
|
output?: WriteToolOutput
|
||||||
}): NonNullable<CollapseProps['items']>[number] {
|
}): NonNullable<CollapseProps['items']>[number] {
|
||||||
return {
|
return {
|
||||||
key: 'tool',
|
key: 'tool',
|
||||||
label: <ToolTitle icon={<FileText className="h-4 w-4" />} label="Write" params={input?.file_path} />,
|
label: <ToolTitle icon={<FileText className="h-4 w-4" />} label="Write" params={input.file_path} />,
|
||||||
children: <div>{input?.content}</div>
|
children: <div>{input.content}</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { loggerService } from '@logger'
|
import { loggerService } from '@logger'
|
||||||
import { useAppSelector } from '@renderer/store'
|
|
||||||
import { selectPendingPermission } from '@renderer/store/toolPermissions'
|
|
||||||
import type { NormalToolResponse } from '@renderer/types'
|
import type { NormalToolResponse } from '@renderer/types'
|
||||||
import type { CollapseProps } from 'antd'
|
import type { CollapseProps } from 'antd'
|
||||||
import { Collapse, Spin } from 'antd'
|
import { Collapse } from 'antd'
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
|
|
||||||
// 导出所有类型
|
// 导出所有类型
|
||||||
export * from './types'
|
export * from './types'
|
||||||
@@ -86,41 +83,17 @@ function ToolContent({ toolName, input, output }: { toolName: AgentToolsType; in
|
|||||||
// 统一的组件渲染入口
|
// 统一的组件渲染入口
|
||||||
export function MessageAgentTools({ toolResponse }: { toolResponse: NormalToolResponse }) {
|
export function MessageAgentTools({ toolResponse }: { toolResponse: NormalToolResponse }) {
|
||||||
const { arguments: args, response, tool, status } = toolResponse
|
const { arguments: args, response, tool, status } = toolResponse
|
||||||
logger.debug('Rendering agent tool response', {
|
logger.info('Rendering agent tool response', {
|
||||||
tool: tool,
|
tool: tool,
|
||||||
arguments: args,
|
arguments: args,
|
||||||
status,
|
|
||||||
response
|
response
|
||||||
})
|
})
|
||||||
|
|
||||||
const pendingPermission = useAppSelector((state) =>
|
|
||||||
selectPendingPermission(state.toolPermissions, toolResponse.toolCallId)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (status === 'pending') {
|
if (status === 'pending') {
|
||||||
if (pendingPermission) {
|
return <ToolPermissionRequestCard toolResponse={toolResponse} />
|
||||||
return <ToolPermissionRequestCard toolResponse={toolResponse} />
|
|
||||||
}
|
|
||||||
return <ToolPendingIndicator toolName={tool?.name} description={tool?.description} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolContent toolName={tool.name as AgentToolsType} input={args as ToolInput} output={response as ToolOutput} />
|
<ToolContent toolName={tool.name as AgentToolsType} input={args as ToolInput} output={response as ToolOutput} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ToolPendingIndicator({ toolName, description }: { toolName?: string; description?: string }) {
|
|
||||||
const { t } = useTranslation()
|
|
||||||
const label = toolName || t('agent.toolPermission.toolPendingFallback', 'Tool')
|
|
||||||
const detail = description?.trim() || t('agent.toolPermission.executing')
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex w-full max-w-xl items-center gap-3 rounded-xl border border-default-200 bg-default-100 px-4 py-3 shadow-sm">
|
|
||||||
<Spin size="small" />
|
|
||||||
<div className="flex flex-col gap-1">
|
|
||||||
<span className="font-semibold text-default-700 text-sm">{label}</span>
|
|
||||||
<span className="text-default-500 text-xs">{detail}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
DEFAULT_TEMPERATURE,
|
DEFAULT_TEMPERATURE,
|
||||||
MAX_CONTEXT_COUNT
|
MAX_CONTEXT_COUNT
|
||||||
} from '@renderer/config/constant'
|
} from '@renderer/config/constant'
|
||||||
import { isOpenAIModel, isSupportVerbosityModel } from '@renderer/config/models'
|
import { isOpenAIModel } from '@renderer/config/models'
|
||||||
import { UNKNOWN } from '@renderer/config/translate'
|
import { UNKNOWN } from '@renderer/config/translate'
|
||||||
import { useCodeStyle } from '@renderer/context/CodeStyleProvider'
|
import { useCodeStyle } from '@renderer/context/CodeStyleProvider'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
@@ -56,7 +56,7 @@ import type { Assistant, AssistantSettings, CodeStyleVarious, MathEngine } from
|
|||||||
import { isGroqSystemProvider, ThemeMode } from '@renderer/types'
|
import { isGroqSystemProvider, ThemeMode } from '@renderer/types'
|
||||||
import { modalConfirm } from '@renderer/utils'
|
import { modalConfirm } from '@renderer/utils'
|
||||||
import { getSendMessageShortcutLabel } from '@renderer/utils/input'
|
import { getSendMessageShortcutLabel } from '@renderer/utils/input'
|
||||||
import { isSupportServiceTierProvider, isSupportVerbosityProvider } from '@renderer/utils/provider'
|
import { isSupportServiceTierProvider } from '@renderer/utils/provider'
|
||||||
import { Button, Col, InputNumber, Row, Slider, Switch } from 'antd'
|
import { Button, Col, InputNumber, Row, Slider, Switch } from 'antd'
|
||||||
import { Settings2 } from 'lucide-react'
|
import { Settings2 } from 'lucide-react'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
@@ -183,10 +183,7 @@ const SettingsTab: FC<Props> = (props) => {
|
|||||||
|
|
||||||
const model = assistant.model || getDefaultModel()
|
const model = assistant.model || getDefaultModel()
|
||||||
|
|
||||||
const showOpenAiSettings =
|
const showOpenAiSettings = isOpenAIModel(model) || isSupportServiceTierProvider(provider)
|
||||||
isOpenAIModel(model) ||
|
|
||||||
isSupportServiceTierProvider(provider) ||
|
|
||||||
(isSupportVerbosityModel(model) && isSupportVerbosityProvider(provider))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container className="settings-tab">
|
<Container className="settings-tab">
|
||||||
|
|||||||
@@ -404,11 +404,11 @@ const UpdateNotesWrapper = styled.div`
|
|||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
background-color: var(--color-bg-2);
|
background-color: var(--color-bg-2);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--color-text-2);
|
|
||||||
font-size: 14px;
|
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
color: var(--color-text-2);
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -135,18 +135,12 @@ const AssistantModelSettings: FC<Props> = ({ assistant, updateAssistant, updateA
|
|||||||
<Input
|
<Input
|
||||||
value={typeof param.value === 'string' ? param.value : JSON.stringify(param.value, null, 2)}
|
value={typeof param.value === 'string' ? param.value : JSON.stringify(param.value, null, 2)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
// For JSON type parameters, always store the value as a STRING
|
try {
|
||||||
//
|
const jsonValue = JSON.parse(e.target.value)
|
||||||
// Data Flow:
|
onUpdateCustomParameter(index, 'value', jsonValue)
|
||||||
// 1. UI stores: { name: "config", value: '{"key":"value"}', type: "json" } ← STRING format
|
} catch {
|
||||||
// 2. API parses: getCustomParameters() in src/renderer/src/aiCore/utils/reasoning.ts:687-696
|
onUpdateCustomParameter(index, 'value', e.target.value)
|
||||||
// calls JSON.parse() to convert string to object
|
}
|
||||||
// 3. Request sends: The parsed object is sent to the AI provider
|
|
||||||
//
|
|
||||||
// Previously this code was parsing JSON here and storing
|
|
||||||
// the object directly, which caused getCustomParameters() to fail when trying
|
|
||||||
// to JSON.parse() an already-parsed object.
|
|
||||||
onUpdateCustomParameter(index, 'value', e.target.value)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { adaptProvider } from '@renderer/aiCore/provider/providerConfig'
|
|
||||||
import OpenAIAlert from '@renderer/components/Alert/OpenAIAlert'
|
import OpenAIAlert from '@renderer/components/Alert/OpenAIAlert'
|
||||||
import { LoadingIcon } from '@renderer/components/Icons'
|
import { LoadingIcon } from '@renderer/components/Icons'
|
||||||
import { HStack } from '@renderer/components/Layout'
|
import { HStack } from '@renderer/components/Layout'
|
||||||
import { ApiKeyListPopup } from '@renderer/components/Popups/ApiKeyListPopup'
|
import { ApiKeyListPopup } from '@renderer/components/Popups/ApiKeyListPopup'
|
||||||
import Selector from '@renderer/components/Selector'
|
import Selector from '@renderer/components/Selector'
|
||||||
import { HelpTooltip } from '@renderer/components/TooltipIcons'
|
|
||||||
import { isEmbeddingModel, isRerankModel } from '@renderer/config/models'
|
import { isEmbeddingModel, isRerankModel } from '@renderer/config/models'
|
||||||
import { PROVIDER_URLS } from '@renderer/config/providers'
|
import { PROVIDER_URLS } from '@renderer/config/providers'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
@@ -21,7 +19,14 @@ import type { SystemProviderId } from '@renderer/types'
|
|||||||
import { isSystemProvider, isSystemProviderId, SystemProviderIds } from '@renderer/types'
|
import { isSystemProvider, isSystemProviderId, SystemProviderIds } from '@renderer/types'
|
||||||
import type { ApiKeyConnectivity } from '@renderer/types/healthCheck'
|
import type { ApiKeyConnectivity } from '@renderer/types/healthCheck'
|
||||||
import { HealthStatus } from '@renderer/types/healthCheck'
|
import { HealthStatus } from '@renderer/types/healthCheck'
|
||||||
import { formatApiHost, formatApiKeys, getFancyProviderName, validateApiHost } from '@renderer/utils'
|
import {
|
||||||
|
formatApiHost,
|
||||||
|
formatApiKeys,
|
||||||
|
formatAzureOpenAIApiHost,
|
||||||
|
formatVertexApiHost,
|
||||||
|
getFancyProviderName,
|
||||||
|
validateApiHost
|
||||||
|
} from '@renderer/utils'
|
||||||
import { formatErrorMessage } from '@renderer/utils/error'
|
import { formatErrorMessage } from '@renderer/utils/error'
|
||||||
import {
|
import {
|
||||||
isAIGatewayProvider,
|
isAIGatewayProvider,
|
||||||
@@ -31,6 +36,7 @@ import {
|
|||||||
isNewApiProvider,
|
isNewApiProvider,
|
||||||
isOpenAICompatibleProvider,
|
isOpenAICompatibleProvider,
|
||||||
isOpenAIProvider,
|
isOpenAIProvider,
|
||||||
|
isSupportAPIVersionProvider,
|
||||||
isVertexProvider
|
isVertexProvider
|
||||||
} from '@renderer/utils/provider'
|
} from '@renderer/utils/provider'
|
||||||
import { Button, Divider, Flex, Input, Select, Space, Switch, Tooltip } from 'antd'
|
import { Button, Divider, Flex, Input, Select, Space, Switch, Tooltip } from 'antd'
|
||||||
@@ -61,6 +67,7 @@ import OVMSSettings from './OVMSSettings'
|
|||||||
import ProviderOAuth from './ProviderOAuth'
|
import ProviderOAuth from './ProviderOAuth'
|
||||||
import SelectProviderModelPopup from './SelectProviderModelPopup'
|
import SelectProviderModelPopup from './SelectProviderModelPopup'
|
||||||
import VertexAISettings from './VertexAISettings'
|
import VertexAISettings from './VertexAISettings'
|
||||||
|
import VolcengineSettings from './VolcengineSettings'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
providerId: string
|
providerId: string
|
||||||
@@ -275,10 +282,12 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
|||||||
}, [configuredApiHost, apiHost])
|
}, [configuredApiHost, apiHost])
|
||||||
|
|
||||||
const hostPreview = () => {
|
const hostPreview = () => {
|
||||||
const formattedApiHost = adaptProvider({ provider: { ...provider, apiHost } }).apiHost
|
if (apiHost.endsWith('#')) {
|
||||||
|
return apiHost.replace('#', '')
|
||||||
|
}
|
||||||
|
|
||||||
if (isOpenAICompatibleProvider(provider)) {
|
if (isOpenAICompatibleProvider(provider)) {
|
||||||
return formattedApiHost + '/chat/completions'
|
return formatApiHost(apiHost, isSupportAPIVersionProvider(provider)) + '/chat/completions'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAzureOpenAIProvider(provider)) {
|
if (isAzureOpenAIProvider(provider)) {
|
||||||
@@ -286,26 +295,29 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
|||||||
const path = !['preview', 'v1'].includes(apiVersion)
|
const path = !['preview', 'v1'].includes(apiVersion)
|
||||||
? `/v1/chat/completion?apiVersion=v1`
|
? `/v1/chat/completion?apiVersion=v1`
|
||||||
: `/v1/responses?apiVersion=v1`
|
: `/v1/responses?apiVersion=v1`
|
||||||
return formattedApiHost + path
|
return formatAzureOpenAIApiHost(apiHost) + path
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAnthropicProvider(provider)) {
|
if (isAnthropicProvider(provider)) {
|
||||||
return formattedApiHost + '/messages'
|
// AI SDK uses the baseURL with /v1, then appends /messages
|
||||||
|
// formatApiHost adds /v1 automatically if not present
|
||||||
|
const normalizedHost = formatApiHost(apiHost)
|
||||||
|
return normalizedHost + '/messages'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGeminiProvider(provider)) {
|
if (isGeminiProvider(provider)) {
|
||||||
return formattedApiHost + '/models'
|
return formatApiHost(apiHost, true, 'v1beta') + '/models'
|
||||||
}
|
}
|
||||||
if (isOpenAIProvider(provider)) {
|
if (isOpenAIProvider(provider)) {
|
||||||
return formattedApiHost + '/responses'
|
return formatApiHost(apiHost) + '/responses'
|
||||||
}
|
}
|
||||||
if (isVertexProvider(provider)) {
|
if (isVertexProvider(provider)) {
|
||||||
return formattedApiHost + '/publishers/google'
|
return formatVertexApiHost(provider) + '/publishers/google'
|
||||||
}
|
}
|
||||||
if (isAIGatewayProvider(provider)) {
|
if (isAIGatewayProvider(provider)) {
|
||||||
return formattedApiHost + '/language-model'
|
return formatApiHost(apiHost) + '/language-model'
|
||||||
}
|
}
|
||||||
return formattedApiHost
|
return formatApiHost(apiHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
// API key 连通性检查状态指示器,目前仅在失败时显示
|
// API key 连通性检查状态指示器,目前仅在失败时显示
|
||||||
@@ -483,21 +495,16 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
|||||||
{!isDmxapi && (
|
{!isDmxapi && (
|
||||||
<>
|
<>
|
||||||
<SettingSubtitle style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
<SettingSubtitle style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||||
<div className="flex items-center gap-1">
|
<Tooltip title={hostSelectorTooltip} mouseEnterDelay={0.3}>
|
||||||
<Tooltip title={hostSelectorTooltip} mouseEnterDelay={0.3}>
|
<Selector
|
||||||
<div>
|
size={14}
|
||||||
<Selector
|
value={activeHostField}
|
||||||
size={14}
|
onChange={(value) => setActiveHostField(value as HostField)}
|
||||||
value={activeHostField}
|
options={hostSelectorOptions}
|
||||||
onChange={(value) => setActiveHostField(value as HostField)}
|
style={{ paddingLeft: 1, fontWeight: 'bold' }}
|
||||||
options={hostSelectorOptions}
|
placement="bottomLeft"
|
||||||
style={{ paddingLeft: 1, fontWeight: 'bold' }}
|
/>
|
||||||
placement="bottomLeft"
|
</Tooltip>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Tooltip>
|
|
||||||
<HelpTooltip title={t('settings.provider.api.url.tip')}></HelpTooltip>
|
|
||||||
</div>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
@@ -587,6 +594,7 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
|||||||
{provider.id === 'copilot' && <GithubCopilotSettings providerId={provider.id} />}
|
{provider.id === 'copilot' && <GithubCopilotSettings providerId={provider.id} />}
|
||||||
{provider.id === 'aws-bedrock' && <AwsBedrockSettings />}
|
{provider.id === 'aws-bedrock' && <AwsBedrockSettings />}
|
||||||
{provider.id === 'vertexai' && <VertexAISettings />}
|
{provider.id === 'vertexai' && <VertexAISettings />}
|
||||||
|
{provider.id === 'doubao' && <VolcengineSettings />}
|
||||||
<ModelList providerId={provider.id} />
|
<ModelList providerId={provider.id} />
|
||||||
</SettingContainer>
|
</SettingContainer>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import { HStack } from '@renderer/components/Layout'
|
||||||
|
import { PROVIDER_URLS } from '@renderer/config/providers'
|
||||||
|
import { useVolcengineSettings } from '@renderer/hooks/useVolcengine'
|
||||||
|
import { Alert, Button, Input, Space } from 'antd'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
|
import { SettingHelpLink, SettingHelpText, SettingHelpTextRow, SettingSubtitle } from '..'
|
||||||
|
|
||||||
|
const VolcengineSettings: FC = () => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { region, projectName, setRegion, setProjectName } = useVolcengineSettings()
|
||||||
|
|
||||||
|
const providerConfig = PROVIDER_URLS['doubao']
|
||||||
|
const apiKeyWebsite = providerConfig?.websites?.apiKey
|
||||||
|
|
||||||
|
const [localAccessKeyId, setLocalAccessKeyId] = useState('')
|
||||||
|
const [localSecretAccessKey, setLocalSecretAccessKey] = useState('')
|
||||||
|
const [localRegion, setLocalRegion] = useState(region)
|
||||||
|
const [localProjectName, setLocalProjectName] = useState(projectName)
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [hasCredentials, setHasCredentials] = useState(false)
|
||||||
|
|
||||||
|
// Check if credentials exist on mount
|
||||||
|
useEffect(() => {
|
||||||
|
window.api.volcengine.hasCredentials().then(setHasCredentials)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Sync local state with store (only for region and projectName)
|
||||||
|
useEffect(() => {
|
||||||
|
setLocalRegion(region)
|
||||||
|
setLocalProjectName(projectName)
|
||||||
|
}, [region, projectName])
|
||||||
|
|
||||||
|
const handleSaveCredentials = useCallback(async () => {
|
||||||
|
if (!localAccessKeyId || !localSecretAccessKey) {
|
||||||
|
window.toast.error(t('settings.provider.volcengine.credentials_required'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
// Save credentials to secure storage via IPC first
|
||||||
|
await window.api.volcengine.saveCredentials(localAccessKeyId, localSecretAccessKey)
|
||||||
|
|
||||||
|
// Only update Redux after IPC success (for region and projectName only)
|
||||||
|
setRegion(localRegion)
|
||||||
|
setProjectName(localProjectName)
|
||||||
|
|
||||||
|
setHasCredentials(true)
|
||||||
|
// Clear local credential state after successful save (they're now in secure storage)
|
||||||
|
setLocalAccessKeyId('')
|
||||||
|
setLocalSecretAccessKey('')
|
||||||
|
window.toast.success(t('settings.provider.volcengine.credentials_saved'))
|
||||||
|
} catch (error) {
|
||||||
|
window.toast.error(String(error))
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}, [localAccessKeyId, localSecretAccessKey, localRegion, localProjectName, setRegion, setProjectName, t])
|
||||||
|
|
||||||
|
const handleClearCredentials = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await window.api.volcengine.clearCredentials()
|
||||||
|
setLocalAccessKeyId('')
|
||||||
|
setLocalSecretAccessKey('')
|
||||||
|
setHasCredentials(false)
|
||||||
|
window.toast.success(t('settings.provider.volcengine.credentials_cleared'))
|
||||||
|
} catch (error) {
|
||||||
|
window.toast.error(String(error))
|
||||||
|
}
|
||||||
|
}, [t])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SettingSubtitle style={{ marginTop: 5 }}>{t('settings.provider.volcengine.title')}</SettingSubtitle>
|
||||||
|
<Alert type="info" style={{ marginTop: 5 }} message={t('settings.provider.volcengine.description')} showIcon />
|
||||||
|
|
||||||
|
<SettingSubtitle style={{ marginTop: 15 }}>{t('settings.provider.volcengine.access_key_id')}</SettingSubtitle>
|
||||||
|
<Input
|
||||||
|
value={localAccessKeyId}
|
||||||
|
placeholder="Access Key ID"
|
||||||
|
onChange={(e) => setLocalAccessKeyId(e.target.value)}
|
||||||
|
style={{ marginTop: 5 }}
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
<SettingHelpTextRow>
|
||||||
|
<SettingHelpText>{t('settings.provider.volcengine.access_key_id_help')}</SettingHelpText>
|
||||||
|
</SettingHelpTextRow>
|
||||||
|
|
||||||
|
<SettingSubtitle style={{ marginTop: 15 }}>{t('settings.provider.volcengine.secret_access_key')}</SettingSubtitle>
|
||||||
|
<Input.Password
|
||||||
|
value={localSecretAccessKey}
|
||||||
|
placeholder="Secret Access Key"
|
||||||
|
onChange={(e) => setLocalSecretAccessKey(e.target.value)}
|
||||||
|
style={{ marginTop: 5 }}
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
|
||||||
|
<HStack>
|
||||||
|
{apiKeyWebsite && (
|
||||||
|
<SettingHelpLink target="_blank" href={apiKeyWebsite}>
|
||||||
|
{t('settings.provider.get_api_key')}
|
||||||
|
</SettingHelpLink>
|
||||||
|
)}
|
||||||
|
</HStack>
|
||||||
|
<SettingHelpText>{t('settings.provider.volcengine.secret_access_key_help')}</SettingHelpText>
|
||||||
|
</SettingHelpTextRow>
|
||||||
|
|
||||||
|
<SettingSubtitle style={{ marginTop: 15 }}>{t('settings.provider.volcengine.region')}</SettingSubtitle>
|
||||||
|
<Input
|
||||||
|
value={localRegion}
|
||||||
|
placeholder="cn-beijing"
|
||||||
|
onChange={(e) => setLocalRegion(e.target.value)}
|
||||||
|
onBlur={() => setRegion(localRegion)}
|
||||||
|
style={{ marginTop: 5 }}
|
||||||
|
/>
|
||||||
|
<SettingHelpTextRow>
|
||||||
|
<SettingHelpText>{t('settings.provider.volcengine.region_help')}</SettingHelpText>
|
||||||
|
</SettingHelpTextRow>
|
||||||
|
|
||||||
|
<SettingSubtitle style={{ marginTop: 15 }}>{t('settings.provider.volcengine.project_name')}</SettingSubtitle>
|
||||||
|
<Input
|
||||||
|
value={localProjectName}
|
||||||
|
placeholder="default"
|
||||||
|
onChange={(e) => setLocalProjectName(e.target.value)}
|
||||||
|
onBlur={() => setProjectName(localProjectName)}
|
||||||
|
style={{ marginTop: 5 }}
|
||||||
|
/>
|
||||||
|
<SettingHelpTextRow>
|
||||||
|
<SettingHelpText>{t('settings.provider.volcengine.project_name_help')}</SettingHelpText>
|
||||||
|
</SettingHelpTextRow>
|
||||||
|
|
||||||
|
<Space style={{ marginTop: 15 }}>
|
||||||
|
<Button type="primary" onClick={handleSaveCredentials} loading={saving}>
|
||||||
|
{t('settings.provider.volcengine.save_credentials')}
|
||||||
|
</Button>
|
||||||
|
{hasCredentials && (
|
||||||
|
<Button danger onClick={handleClearCredentials}>
|
||||||
|
{t('settings.provider.volcengine.clear_credentials')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default VolcengineSettings
|
||||||
@@ -12,7 +12,7 @@ import type { FetchChatCompletionParams } from '@renderer/types'
|
|||||||
import type { Assistant, MCPServer, MCPTool, Model, Provider } from '@renderer/types'
|
import type { Assistant, MCPServer, MCPTool, Model, Provider } from '@renderer/types'
|
||||||
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
import type { StreamTextParams } from '@renderer/types/aiCoreTypes'
|
||||||
import { type Chunk, ChunkType } from '@renderer/types/chunk'
|
import { type Chunk, ChunkType } from '@renderer/types/chunk'
|
||||||
import type { Message, ResponseError } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
import type { SdkModel } from '@renderer/types/sdk'
|
import type { SdkModel } from '@renderer/types/sdk'
|
||||||
import { removeSpecialCharactersForTopicName, uuid } from '@renderer/utils'
|
import { removeSpecialCharactersForTopicName, uuid } from '@renderer/utils'
|
||||||
import { abortCompletion, readyToAbort } from '@renderer/utils/abortController'
|
import { abortCompletion, readyToAbort } from '@renderer/utils/abortController'
|
||||||
@@ -476,7 +476,7 @@ export async function checkApi(provider: Provider, model: Model, timeout = 15000
|
|||||||
} else {
|
} else {
|
||||||
const abortId = uuid()
|
const abortId = uuid()
|
||||||
const signal = readyToAbort(abortId)
|
const signal = readyToAbort(abortId)
|
||||||
let streamError: ResponseError | undefined
|
let chunkError
|
||||||
const params: StreamTextParams = {
|
const params: StreamTextParams = {
|
||||||
system: assistant.prompt,
|
system: assistant.prompt,
|
||||||
prompt: 'hi',
|
prompt: 'hi',
|
||||||
@@ -495,18 +495,19 @@ export async function checkApi(provider: Provider, model: Model, timeout = 15000
|
|||||||
callType: 'check',
|
callType: 'check',
|
||||||
onChunk: (chunk: Chunk) => {
|
onChunk: (chunk: Chunk) => {
|
||||||
if (chunk.type === ChunkType.ERROR) {
|
if (chunk.type === ChunkType.ERROR) {
|
||||||
streamError = chunk.error
|
chunkError = chunk.error
|
||||||
} else {
|
} else {
|
||||||
abortCompletion(abortId)
|
abortCompletion(abortId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try streaming check
|
||||||
try {
|
try {
|
||||||
await ai.completions(model.id, params, config)
|
await ai.completions(model.id, params, config)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!isAbortError(e) && !isAbortError(streamError)) {
|
if (!isAbortError(e) && !isAbortError(chunkError)) {
|
||||||
throw streamError ?? e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,6 +242,10 @@ vi.mock('@renderer/store/llm.ts', () => {
|
|||||||
secretAccessKey: '',
|
secretAccessKey: '',
|
||||||
apiKey: '',
|
apiKey: '',
|
||||||
region: ''
|
region: ''
|
||||||
|
},
|
||||||
|
volcengine: {
|
||||||
|
region: 'cn-beijing',
|
||||||
|
projectName: 'default'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} satisfies LlmState
|
} satisfies LlmState
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user