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

Function mergeInPlace

packages/kosong/src/message.ts:141–172  ·  view source on GitHub ↗
(target: StreamedMessagePart, source: StreamedMessagePart)

Source from the content-addressed store, hash-verified

139 * Returns `true` if the merge was performed, `false` otherwise.
140 */
141export function mergeInPlace(target: StreamedMessagePart, source: StreamedMessagePart): boolean {
142 // TextPart + TextPart
143 if (target.type === 'text' && source.type === 'text') {
144 target.text += source.text;
145 return true;
146 }
147
148 // ThinkPart + ThinkPart
149 if (target.type === 'think' && source.type === 'think') {
150 if (target.encrypted !== undefined) {
151 return false;
152 }
153 target.think += source.think;
154 if (source.encrypted !== undefined) {
155 target.encrypted = source.encrypted;
156 }
157 return true;
158 }
159
160 // ToolCall + ToolCallPart
161 if (target.type === 'function' && source.type === 'tool_call_part') {
162 if (source.argumentsPart !== null) {
163 target.arguments =
164 target.arguments === null
165 ? source.argumentsPart
166 : target.arguments + source.argumentsPart;
167 }
168 return true;
169 }
170
171 return false;
172}
173
174/**
175 * Extract the concatenated text from a message's content parts.

Callers 3

message.test.tsFile · 0.90
stress.test.tsFile · 0.90
generateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected