feat(数据库): 添加秘塔AI工具配置和搜索图片支持
- 在 userSettings 表添加 metasoApiKey 和 metasoApiKeyConfigured 字段 - 更新默认工具列表,添加 mita_search 和 mita_reader - 在 messages 表添加 usedTools 和 searchImages 字段 - 新增 SearchImageData 接口定义图片搜索结果类型 - 添加秘塔搜索和秘塔阅读器工具的种子数据 - 更新数据库名称配置从 lioncode_ui 到 cchcode_ui
This commit is contained in:
parent
5ad191684a
commit
baf27ceca6
@ -9,7 +9,7 @@ export default defineConfig({
|
|||||||
port: parseInt(process.env.DB_PORT || '35433'),
|
port: parseInt(process.env.DB_PORT || '35433'),
|
||||||
user: process.env.DB_USER || 'postgres',
|
user: process.env.DB_USER || 'postgres',
|
||||||
password: process.env.DB_PASSWORD || 'postgres',
|
password: process.env.DB_PASSWORD || 'postgres',
|
||||||
database: process.env.DB_NAME || 'lioncode_ui',
|
database: process.env.DB_NAME || 'cchcode_ui',
|
||||||
ssl: false,
|
ssl: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
3
src/drizzle/migrations/0010_pretty_khan.sql
Normal file
3
src/drizzle/migrations/0010_pretty_khan.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE "user_settings" ALTER COLUMN "default_tools" SET DEFAULT '["web_search","web_fetch","mita_search","mita_reader"]'::jsonb;--> statement-breakpoint
|
||||||
|
ALTER TABLE "user_settings" ADD COLUMN "metaso_api_key" varchar(512);--> statement-breakpoint
|
||||||
|
ALTER TABLE "user_settings" ADD COLUMN "metaso_api_key_configured" boolean DEFAULT false;
|
||||||
1
src/drizzle/migrations/0011_spooky_toad_men.sql
Normal file
1
src/drizzle/migrations/0011_spooky_toad_men.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "messages" ADD COLUMN "used_tools" jsonb DEFAULT '[]'::jsonb;
|
||||||
1
src/drizzle/migrations/0012_flippant_marvel_apes.sql
Normal file
1
src/drizzle/migrations/0012_flippant_marvel_apes.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "messages" ADD COLUMN "search_images" jsonb;
|
||||||
1191
src/drizzle/migrations/meta/0010_snapshot.json
Normal file
1191
src/drizzle/migrations/meta/0010_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1198
src/drizzle/migrations/meta/0011_snapshot.json
Normal file
1198
src/drizzle/migrations/meta/0011_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1204
src/drizzle/migrations/meta/0012_snapshot.json
Normal file
1204
src/drizzle/migrations/meta/0012_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -71,6 +71,27 @@
|
|||||||
"when": 1766323563111,
|
"when": 1766323563111,
|
||||||
"tag": "0009_omniscient_vision",
|
"tag": "0009_omniscient_vision",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 10,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1766335500962,
|
||||||
|
"tag": "0010_pretty_khan",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 11,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1766337225624,
|
||||||
|
"tag": "0011_spooky_toad_men",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 12,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1766339459689,
|
||||||
|
"tag": "0012_flippant_marvel_apes",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -63,11 +63,14 @@ export const userSettings = pgTable('user_settings', {
|
|||||||
cchUrl: varchar('cch_url', { length: 512 }).notNull().default('http://localhost:13500'),
|
cchUrl: varchar('cch_url', { length: 512 }).notNull().default('http://localhost:13500'),
|
||||||
cchApiKey: varchar('cch_api_key', { length: 512 }),
|
cchApiKey: varchar('cch_api_key', { length: 512 }),
|
||||||
cchApiKeyConfigured: boolean('cch_api_key_configured').default(false),
|
cchApiKeyConfigured: boolean('cch_api_key_configured').default(false),
|
||||||
|
// 秘塔AI配置
|
||||||
|
metasoApiKey: varchar('metaso_api_key', { length: 512 }),
|
||||||
|
metasoApiKeyConfigured: boolean('metaso_api_key_configured').default(false),
|
||||||
// API 格式类型:claude(原生)| openai(兼容)
|
// API 格式类型:claude(原生)| openai(兼容)
|
||||||
apiFormat: varchar('api_format', { length: 20 }).default('claude'),
|
apiFormat: varchar('api_format', { length: 20 }).default('claude'),
|
||||||
// 默认设置
|
// 默认设置
|
||||||
defaultModel: varchar('default_model', { length: 64 }).default('claude-sonnet-4-5-20250929'),
|
defaultModel: varchar('default_model', { length: 64 }).default('claude-sonnet-4-5-20250929'),
|
||||||
defaultTools: jsonb('default_tools').$type<string[]>().default(['web_search', 'web_fetch']),
|
defaultTools: jsonb('default_tools').$type<string[]>().default(['web_search', 'web_fetch', 'mita_search', 'mita_reader']),
|
||||||
// AI 行为设置
|
// AI 行为设置
|
||||||
systemPrompt: text('system_prompt'), // 系统提示词
|
systemPrompt: text('system_prompt'), // 系统提示词
|
||||||
temperature: varchar('temperature', { length: 10 }).default('0.7'), // 温度参数 (0-1)
|
temperature: varchar('temperature', { length: 10 }).default('0.7'), // 温度参数 (0-1)
|
||||||
@ -200,6 +203,10 @@ export const messages = pgTable('messages', {
|
|||||||
uploadedImages: jsonb('uploaded_images').$type<string[]>(),
|
uploadedImages: jsonb('uploaded_images').$type<string[]>(),
|
||||||
// 用户上传的文档
|
// 用户上传的文档
|
||||||
uploadedDocuments: jsonb('uploaded_documents').$type<UploadedDocumentData[]>(),
|
uploadedDocuments: jsonb('uploaded_documents').$type<UploadedDocumentData[]>(),
|
||||||
|
// 使用的工具名称列表(用于简洁显示)
|
||||||
|
usedTools: jsonb('used_tools').$type<string[]>().default([]),
|
||||||
|
// 搜索到的图片(图片搜索工具返回)
|
||||||
|
searchImages: jsonb('search_images').$type<SearchImageData[]>(),
|
||||||
// Token 统计
|
// Token 统计
|
||||||
inputTokens: integer('input_tokens').default(0),
|
inputTokens: integer('input_tokens').default(0),
|
||||||
outputTokens: integer('output_tokens').default(0),
|
outputTokens: integer('output_tokens').default(0),
|
||||||
@ -415,6 +422,17 @@ export interface UploadedDocumentData {
|
|||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 搜索到的图片数据(用于图片搜索结果持久化)
|
||||||
|
export interface SearchImageData {
|
||||||
|
title: string;
|
||||||
|
imageUrl: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
score: string;
|
||||||
|
position: number;
|
||||||
|
sourceUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
// 导出类型
|
// 导出类型
|
||||||
export type User = typeof users.$inferSelect;
|
export type User = typeof users.$inferSelect;
|
||||||
export type NewUser = typeof users.$inferInsert;
|
export type NewUser = typeof users.$inferInsert;
|
||||||
|
|||||||
@ -13,8 +13,9 @@ async function seedUserSettings() {
|
|||||||
id: 1,
|
id: 1,
|
||||||
cchUrl: 'http://localhost:13500',
|
cchUrl: 'http://localhost:13500',
|
||||||
cchApiKeyConfigured: false,
|
cchApiKeyConfigured: false,
|
||||||
|
metasoApiKeyConfigured: false,
|
||||||
defaultModel: 'claude-sonnet-4-5-20250929',
|
defaultModel: 'claude-sonnet-4-5-20250929',
|
||||||
defaultTools: ['web_search', 'web_fetch'],
|
defaultTools: ['web_search', 'web_fetch', 'mita_search', 'mita_reader'],
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
language: 'zh-CN',
|
language: 'zh-CN',
|
||||||
enableThinking: false,
|
enableThinking: false,
|
||||||
@ -63,6 +64,41 @@ async function seedTools() {
|
|||||||
isDefault: true,
|
isDefault: true,
|
||||||
sortOrder: 2,
|
sortOrder: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
toolId: 'mita_search',
|
||||||
|
name: 'mita_search',
|
||||||
|
displayName: 'Metaso Search',
|
||||||
|
description: '秘塔AI智能搜索,需要配置API Key',
|
||||||
|
icon: 'Search',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
query: { type: 'string', description: '搜索查询关键词' },
|
||||||
|
size: { type: 'number', description: '返回结果数量,默认10' },
|
||||||
|
},
|
||||||
|
required: ['query'],
|
||||||
|
},
|
||||||
|
isEnabled: true,
|
||||||
|
isDefault: true,
|
||||||
|
sortOrder: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
toolId: 'mita_reader',
|
||||||
|
name: 'mita_reader',
|
||||||
|
displayName: 'Metaso Reader',
|
||||||
|
description: '秘塔AI网页读取,返回Markdown格式',
|
||||||
|
icon: 'FileText',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
url: { type: 'string', description: '要读取的网页URL' },
|
||||||
|
},
|
||||||
|
required: ['url'],
|
||||||
|
},
|
||||||
|
isEnabled: true,
|
||||||
|
isDefault: true,
|
||||||
|
sortOrder: 4,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const tool of toolsData) {
|
for (const tool of toolsData) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user