@wabot-dev/framework 0.9.12 → 0.9.13
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.
|
@@ -8,6 +8,7 @@ import '../../../feature/chat-bot/ChatOperator.js';
|
|
|
8
8
|
import '../../../feature/chat-bot/UnionChatAdapter.js';
|
|
9
9
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
10
10
|
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
11
|
+
import { isRetryableError } from '../../../feature/chat-bot/isRetryableError.js';
|
|
11
12
|
import { chatAdapter } from '../../../feature/chat-bot/metadata/@chatAdapter.js';
|
|
12
13
|
import 'uuid';
|
|
13
14
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
@@ -39,15 +40,29 @@ let OpenRouterChatAdapter = class OpenRouterChatAdapter {
|
|
|
39
40
|
const modelNames = req.models.map((m) => m.model);
|
|
40
41
|
const [primary, ...fallbacks] = modelNames;
|
|
41
42
|
this.logger.debug(`Call OpenRouter with model: ${primary}, fallbacks: ${fallbacks.length}, messages: ${messages.length}, tools: ${tools.length}`);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const maxAttempts = 3;
|
|
44
|
+
const backoffMs = [500, 1000, 2000];
|
|
45
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
46
|
+
try {
|
|
47
|
+
const response = await this.openRouter.chat.send({
|
|
48
|
+
chatRequest: {
|
|
49
|
+
model: primary,
|
|
50
|
+
models: fallbacks.length > 0 ? fallbacks : undefined,
|
|
51
|
+
messages,
|
|
52
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return this.mapResponse(response);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (attempt === maxAttempts || !isRetryableError(err))
|
|
59
|
+
throw err;
|
|
60
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
61
|
+
this.logger.warn(`OpenRouter call failed (attempt ${attempt}/${maxAttempts}), retrying in ${backoffMs[attempt - 1]}ms: ${message}`);
|
|
62
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs[attempt - 1]));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error('OpenRouter retry loop exited without result');
|
|
51
66
|
}
|
|
52
67
|
mapChatItems(chatItems) {
|
|
53
68
|
const messages = [];
|