mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
fix(ai): initialize and migrate default assistants
Load standalone CLI assistant configs through the shared manager so fresh data directories receive locale defaults. Back up custom assistants that occupy newly reserved default IDs before installing canonical templates.
This commit is contained in:
1 parent
713776a7c4
commit
79e2027b43
4 files changed
+110
-14
No files matched your search
@@ -1,22 +1,13 @@
|
||||
/**
|
||||
* 助手配置加载器
|
||||
*
|
||||
* 从 ~/.chatlab/ai/assistants/*.md 加载助手系统提示词。
|
||||
* 通过共享 AssistantManager 加载配置,确保 standalone CLI 在首次使用时
|
||||
* 也会创建默认助手,而不是绕过初始化直接读取磁盘。
|
||||
*/
|
||||
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { parseAssistantFile } from '@openchatlab/node-runtime'
|
||||
import type { AssistantConfig } from '@openchatlab/node-runtime'
|
||||
import { getAssistantManager } from './manager-factory'
|
||||
|
||||
export function loadAssistantConfig(aiDataDir: string, assistantId: string): AssistantConfig | null {
|
||||
const filePath = path.join(aiDataDir, 'assistants', `${assistantId}.md`)
|
||||
if (!fs.existsSync(filePath)) return null
|
||||
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf-8')
|
||||
return parseAssistantFile(content, filePath)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
return getAssistantManager(aiDataDir).getAssistantConfig(assistantId)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import * as os from 'node:os'
|
||||
import * as path from 'node:path'
|
||||
import { GENERAL_ASSISTANT_IDS } from '@openchatlab/shared-types'
|
||||
import { getAssistantManager } from './manager-factory'
|
||||
import { loadAssistantConfig } from './assistant-loader'
|
||||
|
||||
const tempDirs: string[] = []
|
||||
|
||||
@@ -22,6 +23,16 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('CLI assistant manager', () => {
|
||||
it('lazily initializes shared defaults when standalone chat loads an assistant', () => {
|
||||
const aiDataDir = createTempDir()
|
||||
|
||||
const assistant = loadAssistantConfig(aiDataDir, 'general_en')
|
||||
|
||||
assert.equal(assistant?.id, 'general_en')
|
||||
assert.ok(assistant?.systemPrompt)
|
||||
assert.equal(fs.existsSync(path.join(aiDataDir, 'assistants', 'general_en.md')), true)
|
||||
})
|
||||
|
||||
it('initializes all shared defaults and can reset a customized default', () => {
|
||||
const manager = getAssistantManager(createTempDir())
|
||||
|
||||
|
||||
Reference in new issue
Block a user