@wabot-dev/framework 0.9.10 → 0.9.12
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.
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { Logger } from '../../../core/logger/Logger.js';
|
|
4
|
+
import '../../../feature/chat-bot/ChatAdapterRegistry.js';
|
|
5
|
+
import '../../../feature/chat-bot/ChatBot.js';
|
|
6
|
+
import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
|
|
7
|
+
import '../../../feature/chat-bot/ChatOperator.js';
|
|
8
|
+
import '../../../feature/chat-bot/UnionChatAdapter.js';
|
|
9
|
+
import '../../../core/injection/index.js';
|
|
10
|
+
import '../../../feature/chat-bot/metadata/ChatAdapterMetadataStore.js';
|
|
11
|
+
import 'uuid';
|
|
12
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
13
|
+
import '../../../core/error/setupErrorHandlers.js';
|
|
4
14
|
|
|
5
15
|
const PERSIST_LIMIT = 32;
|
|
6
16
|
const PERSIST_DIR = '.wabot/in-memory';
|
|
@@ -45,7 +55,7 @@ class InMemoryChatMemory {
|
|
|
45
55
|
const raw = fs.readFileSync(this.filePath, 'utf-8');
|
|
46
56
|
const parsed = JSON.parse(raw);
|
|
47
57
|
if (Array.isArray(parsed)) {
|
|
48
|
-
this.memory = parsed.slice(-PERSIST_LIMIT);
|
|
58
|
+
this.memory = parsed.slice(-PERSIST_LIMIT).map((entry) => new ChatItem(entry.data));
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
61
|
catch (err) {
|
|
@@ -143,7 +143,12 @@ let OpenRouterChatAdapter = class OpenRouterChatAdapter {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
mapResponse(response) {
|
|
146
|
-
const
|
|
146
|
+
const choice = response.choices?.[0];
|
|
147
|
+
const message = choice?.message;
|
|
148
|
+
const finishReason = choice?.finishReason ?? null;
|
|
149
|
+
const responseText = typeof message?.content === 'string' ? message.content : undefined;
|
|
150
|
+
const responseToolCalls = message?.toolCalls;
|
|
151
|
+
const refusal = message?.refusal;
|
|
147
152
|
const nextItems = [];
|
|
148
153
|
if (responseText) {
|
|
149
154
|
nextItems.push({ type: 'botMessage', botMessage: { text: responseText } });
|
|
@@ -163,7 +168,18 @@ let OpenRouterChatAdapter = class OpenRouterChatAdapter {
|
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
if (nextItems.length === 0) {
|
|
166
|
-
|
|
171
|
+
const diagnostics = {
|
|
172
|
+
model: response.model,
|
|
173
|
+
finishReason,
|
|
174
|
+
hasChoices: (response.choices?.length ?? 0) > 0,
|
|
175
|
+
hasMessage: !!message,
|
|
176
|
+
contentType: message?.content === undefined ? 'undefined' : typeof message.content,
|
|
177
|
+
hasReasoning: !!message?.reasoning,
|
|
178
|
+
refusal: refusal ?? null,
|
|
179
|
+
toolCallsCount: responseToolCalls?.length ?? 0,
|
|
180
|
+
};
|
|
181
|
+
this.logger.warn(`Empty OpenRouter response: ${JSON.stringify(diagnostics)}`);
|
|
182
|
+
throw new Error(`Empty OpenRouter response (model: ${response.model}, finishReason: ${finishReason ?? 'null'}${refusal ? ', refused' : ''})`);
|
|
167
183
|
}
|
|
168
184
|
let usage;
|
|
169
185
|
if (response.usage) {
|