@peopl-health/nexus 3.8.30 → 3.8.32
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.
|
@@ -62,12 +62,12 @@ class DefaultMemoryManager extends MemoryManager {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async handlePendingFunctionCalls(assistant, conversationMessages
|
|
65
|
+
async handlePendingFunctionCalls(assistant, conversationMessages) {
|
|
66
66
|
if (!assistant || !conversationMessages?.length) {
|
|
67
67
|
return { outputs: [], toolsExecuted: [] };
|
|
68
68
|
}
|
|
69
69
|
try {
|
|
70
|
-
return await handlePendingFunctionCallsUtil(assistant, conversationMessages
|
|
70
|
+
return await handlePendingFunctionCallsUtil(assistant, conversationMessages);
|
|
71
71
|
} catch (error) {
|
|
72
72
|
logger.error('[DefaultMemoryManager] Function call handling failed', { error: error.message });
|
|
73
73
|
return { outputs: [], toolsExecuted: [] };
|
|
@@ -212,7 +212,6 @@ class OpenAIResponsesProvider {
|
|
|
212
212
|
...config,
|
|
213
213
|
threadId: conversationId,
|
|
214
214
|
assistantId,
|
|
215
|
-
toolMetadata: { numero: thread.code, assistant_id: assistantId }
|
|
216
215
|
}
|
|
217
216
|
});
|
|
218
217
|
|
|
@@ -301,7 +300,7 @@ class OpenAIResponsesProvider {
|
|
|
301
300
|
const {
|
|
302
301
|
threadId, assistantId, presetId = null, additionalMessages = [], context = null,
|
|
303
302
|
instructions = null, additionalInstructions = null, metadata = {},
|
|
304
|
-
assistant,
|
|
303
|
+
assistant, promptVersion = null, promptVariables = null,
|
|
305
304
|
toolChoice = 'auto'
|
|
306
305
|
} = config;
|
|
307
306
|
|
|
@@ -395,11 +394,7 @@ class OpenAIResponsesProvider {
|
|
|
395
394
|
const functionCalls = finalResponse.output.filter(item => item.type === 'function_call');
|
|
396
395
|
if (!functionCalls.length) break;
|
|
397
396
|
|
|
398
|
-
const { outputs, toolsExecuted } = await handleFunctionCalls(
|
|
399
|
-
functionCalls,
|
|
400
|
-
assistant,
|
|
401
|
-
toolMetadata || { thread_id: threadId, assistant_id: assistantId }
|
|
402
|
-
);
|
|
397
|
+
const { outputs, toolsExecuted } = await handleFunctionCalls(functionCalls, assistant);
|
|
403
398
|
|
|
404
399
|
currentInput.push(...finalResponse.output, ...outputs);
|
|
405
400
|
allToolsExecuted.push(...toolsExecuted);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { logger } = require('../utils/logger');
|
|
2
2
|
const { hasTool, executeTool: registryExecuteTool } = require('../services/toolRegistryService');
|
|
3
3
|
|
|
4
|
-
async function executeFunctionCall(assistant, call
|
|
4
|
+
async function executeFunctionCall(assistant, call) {
|
|
5
5
|
const startTime = Date.now();
|
|
6
6
|
const name = call.name;
|
|
7
7
|
const args = call.arguments ? JSON.parse(call.arguments) : {};
|
|
@@ -10,9 +10,14 @@ async function executeFunctionCall(assistant, call, context = {}) {
|
|
|
10
10
|
|
|
11
11
|
let result, success = true;
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (hasTool(name)) {
|
|
14
|
+
const context = {
|
|
15
|
+
code: assistant?.thread?.code || ''
|
|
16
|
+
};
|
|
17
|
+
result = await registryExecuteTool(name, args, context);
|
|
18
|
+
} else {
|
|
19
|
+
result = await assistant.executeTool(name, args);
|
|
20
|
+
}
|
|
16
21
|
logger.info('[executeFunctionCall] Completed', { name, call_id: call.call_id, source: hasTool(name) ? 'registry' : 'assistant', duration_ms: Date.now() - startTime });
|
|
17
22
|
} catch (error) {
|
|
18
23
|
result = { error: error?.message || 'Tool execution failed' };
|
|
@@ -38,14 +43,14 @@ async function executeFunctionCall(assistant, call, context = {}) {
|
|
|
38
43
|
};
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
async function handleFunctionCalls(functionCalls, assistant
|
|
46
|
+
async function handleFunctionCalls(functionCalls, assistant) {
|
|
42
47
|
if (!functionCalls?.length) return { outputs: [], toolsExecuted: [] };
|
|
43
48
|
|
|
44
49
|
const outputs = [];
|
|
45
50
|
const toolsExecuted = [];
|
|
46
51
|
|
|
47
52
|
for (const call of functionCalls) {
|
|
48
|
-
const { functionOutput, toolData } = await executeFunctionCall(assistant, call
|
|
53
|
+
const { functionOutput, toolData } = await executeFunctionCall(assistant, call);
|
|
49
54
|
outputs.push(functionOutput);
|
|
50
55
|
toolsExecuted.push(toolData);
|
|
51
56
|
}
|
|
@@ -53,7 +58,7 @@ async function handleFunctionCalls(functionCalls, assistant, context = {}) {
|
|
|
53
58
|
return { outputs, toolsExecuted };
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
async function handlePendingFunctionCalls(assistant, conversationItems
|
|
61
|
+
async function handlePendingFunctionCalls(assistant, conversationItems) {
|
|
57
62
|
const outputCallIds = new Set(
|
|
58
63
|
conversationItems.filter(item => item.type === 'function_call_output').map(o => o.call_id)
|
|
59
64
|
);
|
|
@@ -66,7 +71,7 @@ async function handlePendingFunctionCalls(assistant, conversationItems, metadata
|
|
|
66
71
|
logger.info('[handlePendingFunctionCalls] Found pending calls', { count: orphanedCalls.length });
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
return handleFunctionCalls(orphanedCalls, assistant
|
|
74
|
+
return handleFunctionCalls(orphanedCalls, assistant);
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
function transformToolsForResponsesAPI(variant, tools) {
|
|
@@ -171,7 +171,8 @@ async function resolveTools({ promptId, assistant, presetToolIds = null, status
|
|
|
171
171
|
const mappedTools = await fetchToolsByRecordIds(presetToolIds);
|
|
172
172
|
if (!mappedTools.length) return { toolIds: [], filtered: false, descriptions: {} };
|
|
173
173
|
|
|
174
|
-
const
|
|
174
|
+
const isProd = status === 'prod';
|
|
175
|
+
const activeTools = mappedTools.filter(t => !t.status || t.status === 'prod' || (!isProd && t.status === 'dev'));
|
|
175
176
|
|
|
176
177
|
const validToolIds = [];
|
|
177
178
|
const descriptions = {};
|