MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / runServerAgent

Function runServerAgent

apps/cli/src/ai/agent.ts:64–285  ·  view source on GitHub ↗
(options: RunAgentOptions)

Source from the content-addressed store, hash-verified

62}
63
64export async function runServerAgent(options: RunAgentOptions): Promise<void> {
65 const {
66 userMessage,
67 aiChatId,
68 historyLeafMessageId,
69 chatType = 'group',
70 locale = 'zh-CN',
71 assistantSystemPrompt,
72 skillMenu,
73 skillDef,
74 compressionConfig,
75 tools = [],
76 aiDataDir,
77 aiChatManager,
78 onEvent,
79 abortSignal,
80 ownerInfo,
81 mentionedMembers,
82 dataSnapshot,
83 thinkingLevel,
84 chartAutoMode = 'suggest',
85 } = options
86
87 const aiLogger = getServerAiLogger()
88
89 // 确保 tokenizer rank 表已加载(compression + agent 路径均依赖)
90 await initTokenizer()
91
92 const llmConfig = getDefaultAssistantConfig(aiDataDir)
93 if (!llmConfig) {
94 onEvent({ type: 'error', error: { name: 'ConfigError', message: 'LLM service not configured' } })
95 onEvent({ type: 'done', isFinished: true })
96 return
97 }
98
99 const piModel = buildPiModel(llmConfig)
100 const t = createAiTranslate(locale)
101
102 let skillCtx: { skillDef?: { name: string; prompt: string }; skillMenu?: string } | undefined
103 if (skillDef) {
104 skillCtx = { skillDef }
105 } else if (skillMenu) {
106 skillCtx = { skillMenu }
107 }
108
109 const systemPrompt = buildSystemPrompt({
110 t,
111 chatType,
112 assistantSystemPrompt,
113 ownerInfo,
114 locale,
115 skillCtx,
116 mentionedMembers,
117 dataSnapshot,
118 })
119
120 const handler = new AgentEventHandler({
121 onChunk: onEvent,

Callers 1

createCliRunAgentStreamFunction · 0.90

Calls 15

emitStatusMethod · 0.95
cloneUsageMethod · 0.95
handleCoreEventMethod · 0.95
getServerAiLoggerFunction · 0.90
initTokenizerFunction · 0.90
buildPiModelFunction · 0.90
createAiTranslateFunction · 0.90
buildSystemPromptFunction · 0.90
checkAndCompressFunction · 0.90

Tested by

no test coverage detected