mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-14 10:29:15 +08:00
feat: 移除旧版提示词系统
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
type Usage as PiUsage,
|
||||
} from '@mariozechner/pi-ai'
|
||||
|
||||
import type { AgentConfig, AgentStreamChunk, AgentResult, PromptConfig, TokenUsage, SkillContext } from './types'
|
||||
import type { AgentConfig, AgentStreamChunk, AgentResult, TokenUsage, SkillContext } from './types'
|
||||
import type { AssistantConfig } from '../assistant/types'
|
||||
import { buildSystemPrompt } from './prompt-builder'
|
||||
import { extractThinkingContent, stripToolCallTags } from './content-parser'
|
||||
@@ -26,7 +26,7 @@ import { AgentEventHandler } from './event-handler'
|
||||
type SimpleHistoryMessage = { role: 'user' | 'assistant'; content: string }
|
||||
|
||||
// Re-export types for external consumers
|
||||
export type { AgentConfig, AgentStreamChunk, AgentResult, PromptConfig, TokenUsage, AgentRuntimeStatus } from './types'
|
||||
export type { AgentConfig, AgentStreamChunk, AgentResult, TokenUsage, AgentRuntimeStatus } from './types'
|
||||
|
||||
/**
|
||||
* Agent 执行器类
|
||||
@@ -39,7 +39,6 @@ export class Agent {
|
||||
private apiKey: string
|
||||
private abortSignal?: AbortSignal
|
||||
private chatType: 'group' | 'private' = 'group'
|
||||
private promptConfig?: PromptConfig
|
||||
private assistantConfig?: AssistantConfig
|
||||
private skillCtx?: SkillContext
|
||||
private locale: string = 'zh-CN'
|
||||
@@ -50,7 +49,6 @@ export class Agent {
|
||||
apiKey: string,
|
||||
config: AgentConfig = {},
|
||||
chatType: 'group' | 'private' = 'group',
|
||||
promptConfig?: PromptConfig,
|
||||
locale: string = 'zh-CN',
|
||||
assistantConfig?: AssistantConfig,
|
||||
skillCtx?: SkillContext
|
||||
@@ -60,7 +58,6 @@ export class Agent {
|
||||
this.apiKey = apiKey
|
||||
this.abortSignal = config.abortSignal
|
||||
this.chatType = chatType
|
||||
this.promptConfig = promptConfig
|
||||
this.assistantConfig = assistantConfig
|
||||
this.skillCtx = skillCtx
|
||||
this.locale = locale
|
||||
@@ -83,13 +80,9 @@ export class Agent {
|
||||
|
||||
const maxToolRounds = Math.max(0, this.config.maxToolRounds ?? 0)
|
||||
|
||||
const effectivePromptConfig: PromptConfig | undefined = this.assistantConfig
|
||||
? { systemPrompt: this.assistantConfig.systemPrompt }
|
||||
: this.promptConfig
|
||||
|
||||
const systemPrompt = buildSystemPrompt(
|
||||
this.chatType,
|
||||
effectivePromptConfig,
|
||||
this.assistantConfig?.systemPrompt,
|
||||
this.context.ownerInfo,
|
||||
this.locale,
|
||||
this.skillCtx,
|
||||
@@ -312,7 +305,6 @@ export async function runAgent(
|
||||
context: ToolContext,
|
||||
config?: AgentConfig,
|
||||
chatType?: 'group' | 'private',
|
||||
promptConfig?: PromptConfig,
|
||||
locale?: string,
|
||||
assistantConfig?: AssistantConfig,
|
||||
skillCtx?: SkillContext
|
||||
@@ -320,17 +312,7 @@ export async function runAgent(
|
||||
const activeConfig = getActiveConfig()
|
||||
if (!activeConfig) throw new Error('LLM service not configured')
|
||||
const piModel = buildPiModel(activeConfig)
|
||||
const agent = new Agent(
|
||||
context,
|
||||
piModel,
|
||||
activeConfig.apiKey,
|
||||
config,
|
||||
chatType,
|
||||
promptConfig,
|
||||
locale,
|
||||
assistantConfig,
|
||||
skillCtx
|
||||
)
|
||||
const agent = new Agent(context, piModel, activeConfig.apiKey, config, chatType, locale, assistantConfig, skillCtx)
|
||||
return agent.execute(userMessage)
|
||||
}
|
||||
|
||||
@@ -343,7 +325,6 @@ export async function runAgentStream(
|
||||
onChunk: (chunk: AgentStreamChunk) => void,
|
||||
config?: AgentConfig,
|
||||
chatType?: 'group' | 'private',
|
||||
promptConfig?: PromptConfig,
|
||||
locale?: string,
|
||||
assistantConfig?: AssistantConfig,
|
||||
skillCtx?: SkillContext
|
||||
@@ -351,16 +332,6 @@ export async function runAgentStream(
|
||||
const activeConfig = getActiveConfig()
|
||||
if (!activeConfig) throw new Error('LLM service not configured')
|
||||
const piModel = buildPiModel(activeConfig)
|
||||
const agent = new Agent(
|
||||
context,
|
||||
piModel,
|
||||
activeConfig.apiKey,
|
||||
config,
|
||||
chatType,
|
||||
promptConfig,
|
||||
locale,
|
||||
assistantConfig,
|
||||
skillCtx
|
||||
)
|
||||
const agent = new Agent(context, piModel, activeConfig.apiKey, config, chatType, locale, assistantConfig, skillCtx)
|
||||
return agent.executeStream(userMessage, onChunk)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { t as i18nT } from '../../i18n'
|
||||
import type { OwnerInfo } from '../tools/types'
|
||||
import type { PromptConfig, SkillContext } from './types'
|
||||
import type { SkillContext } from './types'
|
||||
import type { ToolContext } from '../tools/types'
|
||||
|
||||
function agentT(key: string, locale: string, options?: Record<string, unknown>): string {
|
||||
@@ -80,20 +80,19 @@ function getFallbackRoleDefinition(chatType: 'group' | 'private', locale: string
|
||||
/**
|
||||
* 构建完整的系统提示词
|
||||
*
|
||||
* 提示词配置主要来自前端 src/config/prompts.ts,通过 promptConfig 参数传递。
|
||||
* Fallback 仅在前端未传递配置时使用。
|
||||
* 系统提示词优先使用当前助手配置;若助手不存在,再退回内置默认角色定义。
|
||||
*
|
||||
* 最终格式:{用户系统提示词}\n\n{系统锁定段(日期/owner/时间参数/通用指引)}
|
||||
* 最终格式:{助手系统提示词}\n\n{系统锁定段(日期/owner/时间参数/通用指引)}
|
||||
*/
|
||||
export function buildSystemPrompt(
|
||||
chatType: 'group' | 'private' = 'group',
|
||||
promptConfig?: PromptConfig,
|
||||
assistantSystemPrompt?: string,
|
||||
ownerInfo?: OwnerInfo,
|
||||
locale: string = 'zh-CN',
|
||||
skillCtx?: SkillContext,
|
||||
mentionedMembers?: ToolContext['mentionedMembers']
|
||||
): string {
|
||||
const systemPrompt = promptConfig?.systemPrompt || getFallbackRoleDefinition(chatType, locale)
|
||||
const systemPrompt = assistantSystemPrompt || getFallbackRoleDefinition(chatType, locale)
|
||||
const lockedSection = getLockedPromptSection(chatType, ownerInfo, locale, mentionedMembers)
|
||||
|
||||
let skillSection = ''
|
||||
|
||||
@@ -60,14 +60,6 @@ export interface AgentResult {
|
||||
totalUsage?: TokenUsage
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自定义提示词配置
|
||||
*/
|
||||
export interface PromptConfig {
|
||||
/** 系统提示词(角色定义 + 回答要求,统一为单一字段) */
|
||||
systemPrompt: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 技能上下文(传递给 prompt-builder)
|
||||
* 手动选择和 AI 自选两种模式互斥
|
||||
|
||||
@@ -15,6 +15,5 @@ export {
|
||||
getBuiltinCatalog,
|
||||
importAssistant,
|
||||
reimportAssistant,
|
||||
backupOldPromptPresets,
|
||||
} from './manager'
|
||||
export { getBuiltinSqlToolCatalog, getBuiltinTsToolNames } from './builtinSqlTools'
|
||||
|
||||
@@ -341,39 +341,6 @@ export function resetAssistant(id: string): AssistantSaveResult {
|
||||
return saveAssistantToDisk(resetConfig)
|
||||
}
|
||||
|
||||
// ==================== 提示词预设迁移 ====================
|
||||
|
||||
/**
|
||||
* 备份旧的提示词预设数据到 data/backup 目录
|
||||
*/
|
||||
export function backupOldPromptPresets(data: {
|
||||
customPresets?: unknown[]
|
||||
builtinOverrides?: Record<string, unknown>
|
||||
remotePresetIds?: string[]
|
||||
}): { success: boolean; filePath?: string; error?: string } {
|
||||
try {
|
||||
const backupDir = path.join(getAiDataDir(), '..', 'backup')
|
||||
ensureDir(backupDir)
|
||||
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)
|
||||
const filePath = path.join(backupDir, `prompt-presets-${timestamp}.json`)
|
||||
|
||||
const backupContent = {
|
||||
backupTime: new Date().toISOString(),
|
||||
description: 'ChatLab 旧提示词预设系统备份(已被多助手系统替代)',
|
||||
...data,
|
||||
}
|
||||
|
||||
writeJsonFile(filePath, backupContent)
|
||||
aiLogger.info('AssistantManager', 'Old prompt presets backed up', { filePath })
|
||||
|
||||
return { success: true, filePath }
|
||||
} catch (error) {
|
||||
aiLogger.error('AssistantManager', 'Failed to backup prompt presets', { error: String(error) })
|
||||
return { success: false, error: String(error) }
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 内部工具函数 ====================
|
||||
|
||||
function ensureInitialized(): void {
|
||||
|
||||
Reference in New Issue
Block a user