@peopl-health/nexus 3.8.29 → 3.8.31
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.
|
@@ -11,7 +11,15 @@ function get(key, fallback = undefined) {
|
|
|
11
11
|
return process.env[k] !== undefined ? process.env[k] : fallback;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const PROD_ENVIRONMENTS = new Set(['production', 'prod']);
|
|
15
|
+
|
|
16
|
+
function getServerMode() {
|
|
17
|
+
const explicit = get('SERVER_MODE');
|
|
18
|
+
if (explicit) return explicit;
|
|
19
|
+
return PROD_ENVIRONMENTS.has(process.env.NODE_ENV) ? 'prod' : 'dev';
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
function _resetOverrides() { overrides.clear(); }
|
|
15
23
|
|
|
16
|
-
module.exports = { set, get, _resetOverrides };
|
|
24
|
+
module.exports = { set, get, getServerMode, _resetOverrides };
|
|
17
25
|
|
|
@@ -321,7 +321,7 @@ class OpenAIResponsesProvider {
|
|
|
321
321
|
variables: promptVariables,
|
|
322
322
|
});
|
|
323
323
|
|
|
324
|
-
const { toolIds, filtered } = await resolveTools({
|
|
324
|
+
const { toolIds, filtered, descriptions: toolDescriptions } = await resolveTools({
|
|
325
325
|
promptId: resolvedPromptId || assistantId,
|
|
326
326
|
assistant,
|
|
327
327
|
presetToolIds,
|
|
@@ -334,10 +334,20 @@ class OpenAIResponsesProvider {
|
|
|
334
334
|
for (const s of registrySchemas) schemasByName.set(s.function?.name, s);
|
|
335
335
|
const allSchemas = Array.from(schemasByName.values());
|
|
336
336
|
|
|
337
|
-
|
|
337
|
+
let activeToolSchemas = filtered
|
|
338
338
|
? allSchemas.filter(s => toolIds.includes(s.function?.name))
|
|
339
339
|
: allSchemas;
|
|
340
340
|
|
|
341
|
+
if (toolDescriptions && Object.keys(toolDescriptions).length > 0) {
|
|
342
|
+
activeToolSchemas = activeToolSchemas.map(s => {
|
|
343
|
+
const name = s.function?.name;
|
|
344
|
+
if (name && toolDescriptions[name]) {
|
|
345
|
+
return { ...s, function: { ...s.function, description: toolDescriptions[name] } };
|
|
346
|
+
}
|
|
347
|
+
return s;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
341
351
|
let devContent = resolvedPrompt;
|
|
342
352
|
if (activeToolSchemas.length > 0) {
|
|
343
353
|
const toolNames = activeToolSchemas.map(s => s.function?.name).join(', ');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Config_ID } = require('../config/airtableConfig');
|
|
2
|
+
const runtimeConfig = require('../config/runtimeConfig');
|
|
2
3
|
|
|
3
4
|
const { logger } = require('../utils/logger');
|
|
4
5
|
const MapCache = require('../utils/MapCache');
|
|
@@ -159,27 +160,28 @@ async function fetchToolsByRecordIds(recordIds) {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
async function resolveTools({ promptId, assistant, presetToolIds = null, status =
|
|
163
|
+
async function resolveTools({ promptId, assistant, presetToolIds = null, status = runtimeConfig.getServerMode() }) {
|
|
163
164
|
const hasRegistryTools = getRegisteredToolNames().length > 0;
|
|
164
165
|
const hasAssistantTools = assistant?.tools?.size > 0;
|
|
165
166
|
|
|
166
|
-
if (!hasRegistryTools && !hasAssistantTools) return { toolIds: [], filtered: false };
|
|
167
|
+
if (!hasRegistryTools && !hasAssistantTools) return { toolIds: [], filtered: false, descriptions: {} };
|
|
167
168
|
|
|
168
|
-
if (!presetToolIds) return { toolIds: [], filtered: false };
|
|
169
|
+
if (!presetToolIds) return { toolIds: [], filtered: false, descriptions: {} };
|
|
169
170
|
|
|
170
171
|
const mappedTools = await fetchToolsByRecordIds(presetToolIds);
|
|
171
|
-
if (!mappedTools.length) return { toolIds: [], filtered: false };
|
|
172
|
+
if (!mappedTools.length) return { toolIds: [], filtered: false, descriptions: {} };
|
|
172
173
|
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
: mappedTools;
|
|
174
|
+
const isProd = status === 'prod';
|
|
175
|
+
const activeTools = mappedTools.filter(t => !t.status || t.status === 'prod' || (!isProd && t.status === 'dev'));
|
|
176
176
|
|
|
177
177
|
const validToolIds = [];
|
|
178
|
+
const descriptions = {};
|
|
178
179
|
|
|
179
180
|
for (const tool of activeTools) {
|
|
180
181
|
const id = tool.tool_id;
|
|
181
182
|
if (hasTool(id) || assistant?.tools?.has(id)) {
|
|
182
183
|
validToolIds.push(id);
|
|
184
|
+
if (tool.description) descriptions[id] = tool.description;
|
|
183
185
|
} else {
|
|
184
186
|
logger.warn('[promptComposer] Tool mapped in Airtable but not registered in code', {
|
|
185
187
|
toolId: id, promptId,
|
|
@@ -194,7 +196,7 @@ async function resolveTools({ promptId, assistant, presetToolIds = null, status
|
|
|
194
196
|
filtered: true,
|
|
195
197
|
});
|
|
196
198
|
|
|
197
|
-
return { toolIds: validToolIds, filtered: true };
|
|
199
|
+
return { toolIds: validToolIds, filtered: true, descriptions };
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
function clearCache() {
|