MCPcopy Create free account
hub / github.com/continuedev/continue / appendItemsToLLMLog

Function appendItemsToLLMLog

gui/src/hooks/useLLMLog.ts:118–180  ·  view source on GitHub ↗
(
  oldLog: LLMLog,
  items: LLMInteractionItem[],
)

Source from the content-addressed store, hash-verified

116}
117
118function appendItemsToLLMLog(
119 oldLog: LLMLog,
120 items: LLMInteractionItem[],
121): LLMLog {
122 const oldInteractions = oldLog.interactions;
123 const newInteractions: Map<string, LLMInteraction> = new Map();
124 let order = oldLog.order;
125 let interactionsAdded = false;
126
127 // Add the new items to the log, making mutable copies of old
128 // LLMInteraction as necessary
129 for (const item of items) {
130 let interaction = newInteractions.get(item.interactionId);
131 if (interaction === undefined) {
132 const oldInteraction = oldInteractions.get(item.interactionId);
133 if (oldInteraction) {
134 interaction = copyInteractionForMutation(oldInteraction);
135 } else {
136 interaction = {
137 results: [],
138 };
139
140 if (interactionsAdded) {
141 order.push(item.interactionId);
142 } else {
143 order = [...order, item.interactionId];
144 interactionsAdded = true;
145 }
146 }
147 newInteractions.set(item.interactionId, interaction);
148 }
149
150 switch (item.kind) {
151 case "startChat":
152 case "startComplete":
153 case "startFim":
154 interaction.start = item;
155 break;
156 case "chunk":
157 case "message":
158 appendItemToInteractionResult(interaction, item);
159 break;
160 case "success":
161 case "error":
162 case "cancel":
163 interaction.end = item;
164 break;
165 }
166 }
167
168 // Copy over unchanged interactions
169 for (const interactionId of oldInteractions.keys()) {
170 if (!newInteractions.has(interactionId)) {
171 newInteractions.set(interactionId, oldInteractions.get(interactionId)!);
172 }
173 }
174
175 return {

Callers 1

useLLMLogFunction · 0.85

Calls 5

getMethod · 0.65
pushMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected