Fix : Fix error 400
This commit is contained in:
@@ -219,37 +219,40 @@ function convertMessages(messages, tools, model) {
|
|||||||
flushPending();
|
flushPending();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If last message in history is userInputMessage, use it as currentMessage
|
// Pop last userInputMessage as currentMessage (search from end, skip trailing assistant messages)
|
||||||
if (history.length > 0 && history[history.length - 1].userInputMessage) {
|
for (let i = history.length - 1; i >= 0; i--) {
|
||||||
currentMessage = history.pop();
|
if (history[i].userInputMessage) {
|
||||||
|
currentMessage = history.splice(i, 1)[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstHistoryItem = history[0];
|
// Grab tools from first history item BEFORE cleanup removes them
|
||||||
if (firstHistoryItem?.userInputMessage?.userInputMessageContext?.tools &&
|
const firstHistoryTools = history[0]?.userInputMessage?.userInputMessageContext?.tools;
|
||||||
!currentMessage?.userInputMessage?.userInputMessageContext?.tools) {
|
|
||||||
if (!currentMessage.userInputMessage.userInputMessageContext) {
|
|
||||||
currentMessage.userInputMessage.userInputMessageContext = {};
|
|
||||||
}
|
|
||||||
currentMessage.userInputMessage.userInputMessageContext.tools =
|
|
||||||
firstHistoryItem.userInputMessage.userInputMessageContext.tools;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up history for Kiro API compatibility
|
// Clean up history for Kiro API compatibility
|
||||||
history.forEach(item => {
|
history.forEach(item => {
|
||||||
if (item.userInputMessage?.userInputMessageContext?.tools) {
|
if (item.userInputMessage?.userInputMessageContext?.tools) {
|
||||||
delete item.userInputMessage.userInputMessageContext.tools;
|
delete item.userInputMessage.userInputMessageContext.tools;
|
||||||
}
|
}
|
||||||
|
if (item.userInputMessage?.userInputMessageContext &&
|
||||||
if (item.userInputMessage?.userInputMessageContext &&
|
|
||||||
Object.keys(item.userInputMessage.userInputMessageContext).length === 0) {
|
Object.keys(item.userInputMessage.userInputMessageContext).length === 0) {
|
||||||
delete item.userInputMessage.userInputMessageContext;
|
delete item.userInputMessage.userInputMessageContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.userInputMessage && !item.userInputMessage.modelId) {
|
if (item.userInputMessage && !item.userInputMessage.modelId) {
|
||||||
item.userInputMessage.modelId = model;
|
item.userInputMessage.modelId = model;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Inject tools into currentMessage AFTER cleanup
|
||||||
|
if (firstHistoryTools && currentMessage?.userInputMessage &&
|
||||||
|
!currentMessage.userInputMessage.userInputMessageContext?.tools) {
|
||||||
|
if (!currentMessage.userInputMessage.userInputMessageContext) {
|
||||||
|
currentMessage.userInputMessage.userInputMessageContext = {};
|
||||||
|
}
|
||||||
|
currentMessage.userInputMessage.userInputMessageContext.tools = firstHistoryTools;
|
||||||
|
}
|
||||||
|
|
||||||
return { history, currentMessage };
|
return { history, currentMessage };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Submodule src/mitm/dev updated: ebfb215130...b3b7473d6d
Reference in New Issue
Block a user