MCPcopy Create free account
hub / github.com/echoVic/blade-code / addMessage

Method addMessage

src/context/ContextManager.ts:193–220  ·  view source on GitHub ↗

* 添加消息到当前会话

(
    role: ContextMessage['role'],
    content: string,
    metadata?: Record<string, any>
  )

Source from the content-addressed store, hash-verified

191 * 添加消息到当前会话
192 */
193 async addMessage(
194 role: ContextMessage['role'],
195 content: string,
196 metadata?: Record<string, any>
197 ): Promise<void> {
198 if (!this.currentSessionId) {
199 throw new Error('没有活动会话');
200 }
201
202 const message: ContextMessage = {
203 id: this.generateMessageId(),
204 role,
205 content,
206 timestamp: Date.now(),
207 metadata,
208 };
209
210 this.memory.addMessage(message);
211
212 // 如果需要压缩,执行压缩
213 const contextData = this.memory.getContext();
214 if (contextData && this.shouldCompress(contextData)) {
215 await this.compressCurrentContext();
216 }
217
218 // 异步保存到持久化存储
219 this.saveCurrentSessionAsync();
220 }
221
222 /**
223 * 添加工具调用记录

Callers 4

exampleFunction · 0.45
addUserMessageMethod · 0.45
addAssistantMessageMethod · 0.45
addSystemMessageMethod · 0.45

Calls 5

generateMessageIdMethod · 0.95
shouldCompressMethod · 0.95
getContextMethod · 0.80

Tested by

no test coverage detected