(
projectId: string,
content: string,
metadata: Record<string, unknown>,
requestId?: string,
options: { persist?: boolean; isStreaming?: boolean; messageType?: 'tool_use' | 'tool_result' } = {},
)
| 182 | } |
| 183 | |
| 184 | async 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 | |
| 229 | function createStreamAccumulator(requestId?: string): StreamAccumulator { |
| 230 | return { |
no test coverage detected