MCPcopy
hub / github.com/opactorai/Claudable / persistToolMessage

Function persistToolMessage

lib/services/cli/glm.ts:184–227  ·  view source on GitHub ↗
(
  projectId: string,
  content: string,
  metadata: Record<string, unknown>,
  requestId?: string,
  options: { persist?: boolean; isStreaming?: boolean; messageType?: 'tool_use' | 'tool_result' } = {},
)

Source from the content-addressed store, hash-verified

182}
183
184async function persistToolMessage(
185 projectId: string,
186 content: string,
187 metadata: Record<string, unknown>,
188 requestId?: string,
189 options: { persist?: boolean; isStreaming?: boolean; messageType?: 'tool_use' | 'tool_result' } = {},
190) {
191 const trimmed = content.trim();
192 if (!trimmed) return;
193
194 const { persist = true, isStreaming = false, messageType = 'tool_use' } = options;
195 const enrichedMetadata: Record<string, unknown> = {
196 cli_type: 'glm',
197 ...metadata,
198 };
199
200 if (!persist) {
201 const realtime = createRealtimeMessage({
202 projectId,
203 role: 'tool',
204 messageType,
205 content: trimmed,
206 metadata: enrichedMetadata,
207 cliSource: 'glm',
208 requestId,
209 isStreaming,
210 isFinal: !isStreaming,
211 });
212 streamManager.publish(projectId, { type: 'message', data: realtime });
213 return;
214 }
215
216 await persistAssistantMessage(
217 projectId,
218 {
219 role: 'tool',
220 messageType,
221 content: trimmed,
222 metadata: enrichedMetadata,
223 },
224 requestId,
225 { isStreaming, isFinal: !isStreaming },
226 );
227}
228
229function createStreamAccumulator(requestId?: string): StreamAccumulator {
230 return {

Callers 1

emitToolMessageFunction · 0.85

Calls 3

createRealtimeMessageFunction · 0.90
publishMethod · 0.80
persistAssistantMessageFunction · 0.70

Tested by

no test coverage detected