@peopl-health/nexus 2.2.2 → 2.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.
package/lib/config/llmConfig.js
CHANGED
|
@@ -4,7 +4,7 @@ const { createProvider } = require('../providers/createProvider');
|
|
|
4
4
|
let anthropicClient = null;
|
|
5
5
|
let openaiClient = null;
|
|
6
6
|
let providerInstance = null;
|
|
7
|
-
let providerVariant = 'assistants';
|
|
7
|
+
let providerVariant = process.env.VARIANT || 'assistants';
|
|
8
8
|
|
|
9
9
|
const setOpenAIClient = (client) => {
|
|
10
10
|
openaiClient = client || null;
|
|
@@ -12,7 +12,6 @@ const setOpenAIClient = (client) => {
|
|
|
12
12
|
if (!client) {
|
|
13
13
|
providerInstance = null;
|
|
14
14
|
module.exports.providerInstance = null;
|
|
15
|
-
providerVariant = 'assistants';
|
|
16
15
|
module.exports.providerVariant = providerVariant;
|
|
17
16
|
}
|
|
18
17
|
};
|
|
@@ -20,8 +19,7 @@ const setOpenAIClient = (client) => {
|
|
|
20
19
|
const setOpenAIProvider = (provider) => {
|
|
21
20
|
providerInstance = provider || null;
|
|
22
21
|
module.exports.providerInstance = providerInstance;
|
|
23
|
-
providerVariant = provider?.variant || providerVariant
|
|
24
|
-
module.exports.providerVariant = providerVariant;
|
|
22
|
+
module.exports.providerVariant = provider?.variant || providerVariant;
|
|
25
23
|
|
|
26
24
|
if (!provider) {
|
|
27
25
|
setOpenAIClient(null);
|
|
@@ -37,11 +35,11 @@ const setOpenAIProvider = (provider) => {
|
|
|
37
35
|
}
|
|
38
36
|
};
|
|
39
37
|
|
|
40
|
-
const getOpenAIProvider = ({ instantiate = true } = {}) => {
|
|
38
|
+
const getOpenAIProvider = ({ instantiate = true, variant = providerVariant } = {}) => {
|
|
41
39
|
if (providerInstance) return providerInstance;
|
|
42
40
|
if (!instantiate) return null;
|
|
43
41
|
if (!openaiClient) return null;
|
|
44
|
-
const provider = createProvider({ client: openaiClient, variant
|
|
42
|
+
const provider = createProvider({ client: openaiClient, variant });
|
|
45
43
|
setOpenAIProvider(provider);
|
|
46
44
|
return provider;
|
|
47
45
|
};
|
|
@@ -615,7 +615,7 @@ const getOpenAIThreadMessagesController = async (req, res) => {
|
|
|
615
615
|
const conversationId = thread.getConversationId();
|
|
616
616
|
console.log('Thread found - Conversation ID:', conversationId);
|
|
617
617
|
|
|
618
|
-
const provider = llmConfig.getOpenAIProvider({ instantiate: true });
|
|
618
|
+
const provider = llmConfig.getOpenAIProvider({ instantiate: true, variant });
|
|
619
619
|
if (!provider) {
|
|
620
620
|
throw new Error('OpenAI provider not initialized');
|
|
621
621
|
}
|
|
@@ -18,6 +18,55 @@ const checkTemplateSupport = () => {
|
|
|
18
18
|
};
|
|
19
19
|
const { handleApiError } = require('../utils/errorHandler');
|
|
20
20
|
|
|
21
|
+
// Checks if a label is valid (non-null, non-undefined, non-empty string)
|
|
22
|
+
const isValidLabel = (label) => {
|
|
23
|
+
return label !== null &&
|
|
24
|
+
label !== undefined &&
|
|
25
|
+
typeof label === 'string' &&
|
|
26
|
+
label.trim() !== '';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Generates a label for a layout item based on available fields
|
|
30
|
+
const generateLabel = (item, index) => {
|
|
31
|
+
if (item.name && typeof item.name === 'string' && item.name.trim() !== '') {
|
|
32
|
+
return item.name.trim();
|
|
33
|
+
}
|
|
34
|
+
if (item.type && typeof item.type === 'string') {
|
|
35
|
+
return `${item.type}_${index + 1}`;
|
|
36
|
+
}
|
|
37
|
+
return `element_${index + 1}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Ensures all layout elements have a valid label
|
|
41
|
+
const ensureLabels = (pages) => {
|
|
42
|
+
if (!Array.isArray(pages)) {
|
|
43
|
+
return pages;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return pages.map((page) => {
|
|
47
|
+
if (!page || typeof page !== 'object' || !page.layout || !Array.isArray(page.layout)) {
|
|
48
|
+
return page;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const processedLayout = page.layout.map((item, index) => {
|
|
52
|
+
if (!item || typeof item !== 'object') {
|
|
53
|
+
return item;
|
|
54
|
+
}
|
|
55
|
+
if (isValidLabel(item.label)) {
|
|
56
|
+
return { ...item, label: item.label.trim() };
|
|
57
|
+
}
|
|
58
|
+
const newLabel = generateLabel(item, index);
|
|
59
|
+
|
|
60
|
+
if (!isValidLabel(newLabel)) {
|
|
61
|
+
return { ...item, label: `element_${index + 1}` };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { ...item, label: newLabel };
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return { ...page, layout: processedLayout };
|
|
68
|
+
});
|
|
69
|
+
};
|
|
21
70
|
|
|
22
71
|
const createFlow = async (req, res) => {
|
|
23
72
|
try {
|
|
@@ -35,6 +84,9 @@ const createFlow = async (req, res) => {
|
|
|
35
84
|
});
|
|
36
85
|
}
|
|
37
86
|
|
|
87
|
+
// Ensure all layout elements have labels (Twilio requirement)
|
|
88
|
+
const processedPages = ensureLabels(pages);
|
|
89
|
+
|
|
38
90
|
// Generate unique identifiers for anti-rejection
|
|
39
91
|
const timestamp = Date.now().toString();
|
|
40
92
|
const uniqueId = require('uuid').v4().substring(0, 6);
|
|
@@ -51,7 +103,7 @@ const createFlow = async (req, res) => {
|
|
|
51
103
|
body: body,
|
|
52
104
|
button_text: buttonText,
|
|
53
105
|
subtitle: subtitle || null,
|
|
54
|
-
pages:
|
|
106
|
+
pages: processedPages,
|
|
55
107
|
type: flowType
|
|
56
108
|
}
|
|
57
109
|
}
|
|
@@ -10,6 +10,7 @@ const PROVIDER_VARIANTS = {
|
|
|
10
10
|
* Returns the appropriate OpenAI provider implementation for the requested variant.
|
|
11
11
|
*/
|
|
12
12
|
function createProvider(config = {}) {
|
|
13
|
+
console.log('Creating OpenAI provider with config:', config);
|
|
13
14
|
const variant = (config.variant || config.providerVariant || config.llmVariant || 'assistants')
|
|
14
15
|
.toString()
|
|
15
16
|
.toLowerCase();
|