I’ve created an middleware like this, which seems to be the same as the middleware in document. And it complains: Error: Invalid response from “wrapModelCall” in middleware “HandleModelErrors”: expected AIMessage, got object
const maxRetries = 3;
const handleModelErrors = createMiddleware({
name: "HandleModelErrors",
wrapModelCall: (request, handler) => {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return handler(request);
} catch (e) {
if (attempt === maxRetries - 1) {
throw e;
}
console.log(`Retry ${attempt + 1}/${maxRetries} after error: ${e}`);
}
}
throw new Error("Unreachable");
},
})