MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / flushPart

Function flushPart

packages/kosong/src/generate.ts:294–319  ·  view source on GitHub ↗

* Append a fully-merged part to the message. * * - ContentPart -> message.content * - ToolCall -> message.toolCalls (the `_streamIndex` routing key is * registered in the map and stripped before storage). * - ToolCallPart -> ignored (orphaned delta without a matching pending

(
  message: Message,
  part: StreamedMessagePart,
  toolCallIndexMap: Map<number | string, number>,
)

Source from the content-addressed store, hash-verified

292 * - ToolCallPart -> ignored (orphaned delta without a matching pending call)
293 */
294function flushPart(
295 message: Message,
296 part: StreamedMessagePart,
297 toolCallIndexMap: Map<number | string, number>,
298): void {
299 if (isContentPart(part)) {
300 message.content.push(part);
301 return;
302 }
303 if (isToolCall(part)) {
304 const streamIndex = part._streamIndex;
305 const stored: StoredToolCall = {
306 type: 'function',
307 id: part.id,
308 name: part.name,
309 arguments: part.arguments,
310 extras: part.extras,
311 };
312 const ordinal = message.toolCalls.length;
313 message.toolCalls.push(stored as ToolCall);
314 if (streamIndex !== undefined) {
315 toolCallIndexMap.set(streamIndex, ordinal);
316 }
317 }
318 // ToolCallPart: orphaned delta — silently ignore.
319}
320
321function formatFinishReasonHint(stream: StreamedMessage): string {
322 if (stream.finishReason === null && stream.rawFinishReason === null) return '';

Callers 1

generateFunction · 0.85

Calls 4

isContentPartFunction · 0.90
isToolCallFunction · 0.90
setMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected