@peopl-health/nexus 3.2.2 → 3.2.4
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.
|
@@ -59,15 +59,15 @@ async function getLastMessages(code) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
async function getLastNMessages(code, n, before=null) {
|
|
62
|
+
async function getLastNMessages(code, n, before = null, options = {}) {
|
|
64
63
|
try {
|
|
65
|
-
const query = { numero: code };
|
|
64
|
+
const query = { numero: code, ...options.query };
|
|
66
65
|
|
|
67
66
|
if (before) query.createdAt = { $lte: before };
|
|
68
67
|
|
|
69
68
|
const lastMessages = await Message.find(query)
|
|
70
|
-
.
|
|
69
|
+
.select(options.select || null)
|
|
70
|
+
.sort(options.sort || { createdAt: -1 })
|
|
71
71
|
.limit(n)
|
|
72
72
|
.lean();
|
|
73
73
|
|
|
@@ -16,21 +16,25 @@ class DefaultMemoryManager extends MemoryManager {
|
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
18
|
const beforeCheckpoint = message ? message.createdAt : null;
|
|
19
|
-
const allMessages = await getLastNMessages(thread.code, this.maxHistoricalMessages, beforeCheckpoint
|
|
20
|
-
|
|
19
|
+
const allMessages = await getLastNMessages(thread.code, this.maxHistoricalMessages, beforeCheckpoint, {
|
|
20
|
+
query: { origin: { $ne: 'instruction' } }
|
|
21
|
+
});
|
|
22
|
+
const additionalMessages = config.additionalMessages || [];
|
|
23
|
+
|
|
21
24
|
if (!allMessages?.length) {
|
|
22
|
-
return
|
|
25
|
+
return additionalMessages;
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
const roleMap = { system: 'system', patient: 'user' };
|
|
25
29
|
const messageContext = allMessages.reverse().flatMap(msg => {
|
|
26
30
|
const formattedContents = formatMessage(msg);
|
|
27
31
|
return formattedContents.map(content => ({
|
|
28
|
-
role: msg.origin
|
|
32
|
+
role: roleMap[msg.origin] || 'assistant',
|
|
29
33
|
content: content || msg.body || msg.content || ''
|
|
30
34
|
}));
|
|
31
35
|
}).filter(msg => msg.content);
|
|
32
36
|
|
|
33
|
-
return messageContext;
|
|
37
|
+
return [...messageContext, ...additionalMessages];
|
|
34
38
|
} catch (error) {
|
|
35
39
|
logger.error('[DefaultMemoryManager] Context building failed', {
|
|
36
40
|
threadCode: thread.code,
|
|
@@ -231,10 +231,7 @@ class OpenAIResponsesProvider {
|
|
|
231
231
|
await this.conversationManager.processResponse(result, thread, config);
|
|
232
232
|
|
|
233
233
|
const completed = result.status === 'completed';
|
|
234
|
-
const output =
|
|
235
|
-
runId: result.id,
|
|
236
|
-
fallback: ''
|
|
237
|
-
});
|
|
234
|
+
const output = result.output_text || result.output?.find(o => o.type === 'message')?.content?.[0]?.text || '';
|
|
238
235
|
|
|
239
236
|
if (filter) {
|
|
240
237
|
await Thread.updateOne(filter, { $set: { run_id: null } });
|
|
@@ -243,6 +240,9 @@ class OpenAIResponsesProvider {
|
|
|
243
240
|
logger.info('[OpenAIResponsesProvider] Run complete', {
|
|
244
241
|
runId: result.id,
|
|
245
242
|
completed,
|
|
243
|
+
outputLength: output?.length || 0,
|
|
244
|
+
hasOutputText: !!result.output_text,
|
|
245
|
+
outputTypes: result.output?.map(o => o.type) || [],
|
|
246
246
|
toolsExecuted: result.tools_executed?.length || 0
|
|
247
247
|
});
|
|
248
248
|
|
|
@@ -300,6 +300,7 @@ class OpenAIResponsesProvider {
|
|
|
300
300
|
this.client.responses.create({
|
|
301
301
|
prompt: promptConfig,
|
|
302
302
|
input: inputData,
|
|
303
|
+
instructions: instructions || additionalInstructions,
|
|
303
304
|
truncation: truncationStrategy,
|
|
304
305
|
}), { providerName: PROVIDER_NAME });
|
|
305
306
|
|
|
@@ -338,21 +339,6 @@ class OpenAIResponsesProvider {
|
|
|
338
339
|
}
|
|
339
340
|
}
|
|
340
341
|
|
|
341
|
-
async getRun({ threadId, runId }) {
|
|
342
|
-
const id = this._ensureResponseId(runId);
|
|
343
|
-
return await this.client.responses.retrieve(id);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
async getRunText({ runId, messageIndex = 0, contentIndex = 0, fallback = '' } = {}) {
|
|
347
|
-
const response = await this.client.responses.retrieve(this._ensureResponseId(runId));
|
|
348
|
-
if (!response) return fallback;
|
|
349
|
-
|
|
350
|
-
if (response.output_text) return response.output_text;
|
|
351
|
-
|
|
352
|
-
const text = response.output?.[messageIndex]?.content?.[contentIndex]?.text;
|
|
353
|
-
return text || fallback;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
342
|
/**
|
|
357
343
|
* Generic helpers
|
|
358
344
|
*/
|