orquesta-cli 0.2.79 → 0.2.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/llm/llm-client.js +25 -1
- package/package.json +1 -1
|
@@ -138,14 +138,38 @@ export class LLMClient {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
preprocessMessages(messages, modelId) {
|
|
141
|
-
|
|
141
|
+
let lastUserIdx = -1;
|
|
142
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
143
|
+
if (messages[i]?.role === 'user') {
|
|
144
|
+
lastUserIdx = i;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const stripImagesToText = (parts) => {
|
|
149
|
+
const text = parts.filter((p) => p?.type === 'text').map((p) => p.text ?? '').join('\n');
|
|
150
|
+
const hadImages = parts.some((p) => p?.type === 'image_url');
|
|
151
|
+
return text + (hadImages ? '\n[image attachment removed from history]' : '');
|
|
152
|
+
};
|
|
153
|
+
return messages.map((msg, idx) => {
|
|
142
154
|
let processedMsg = { ...msg };
|
|
143
155
|
const multimodal = processedMsg.multimodal;
|
|
144
156
|
if (multimodal && Array.isArray(multimodal)) {
|
|
157
|
+
if (idx !== lastUserIdx) {
|
|
158
|
+
processedMsg.content = stripImagesToText(multimodal);
|
|
159
|
+
delete processedMsg.multimodal;
|
|
160
|
+
return processedMsg;
|
|
161
|
+
}
|
|
145
162
|
processedMsg.content = multimodal;
|
|
146
163
|
delete processedMsg.multimodal;
|
|
147
164
|
return processedMsg;
|
|
148
165
|
}
|
|
166
|
+
if (idx !== lastUserIdx && Array.isArray(processedMsg.content)) {
|
|
167
|
+
const parts = processedMsg.content;
|
|
168
|
+
if (parts.some((p) => p?.type === 'image_url')) {
|
|
169
|
+
processedMsg.content = stripImagesToText(parts);
|
|
170
|
+
return processedMsg;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
149
173
|
if (msg.role !== 'assistant') {
|
|
150
174
|
return processedMsg;
|
|
151
175
|
}
|