@peopl-health/nexus 3.5.8 → 3.5.9
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,7 +1,12 @@
|
|
|
1
|
+
const { Config_ID } = require('../config/airtableConfig.js');
|
|
2
|
+
const runtimeConfig = require('../config/runtimeConfig.js');
|
|
3
|
+
|
|
1
4
|
const { logger } = require('../utils/logger');
|
|
2
5
|
|
|
3
6
|
const { Thread } = require('../models/threadModel.js');
|
|
4
7
|
|
|
8
|
+
const { getRecordByFilter } = require('../services/airtableService.js');
|
|
9
|
+
|
|
5
10
|
const getThread = async (code, message = null) => {
|
|
6
11
|
try {
|
|
7
12
|
let thread = await Thread.findOne({ code });
|
|
@@ -33,9 +38,22 @@ const createPlaceholderThread = async (code) => {
|
|
|
33
38
|
const existing = await Thread.findOne({ code });
|
|
34
39
|
if (existing) return existing;
|
|
35
40
|
|
|
36
|
-
const
|
|
41
|
+
const nodeEnv = runtimeConfig.get('NODE_ENV');
|
|
42
|
+
const assistantStatus = nodeEnv === 'production' ? 'prod' : nodeEnv === 'development' ? 'dev' : nodeEnv;
|
|
43
|
+
const record = await getRecordByFilter(Config_ID, 'responses', `AND({code}="PIPO_ASST", {status}="${assistantStatus}")`, undefined, ['prompt_id']);
|
|
44
|
+
const prompt_id = record?.[0]?.['prompt_id'] || null;
|
|
45
|
+
|
|
46
|
+
const thread = new Thread({ code, assistant_id: null, prompt_id, conversation_id: null, stopped: true });
|
|
37
47
|
await thread.save();
|
|
38
|
-
logger.info('[createPlaceholderThread] Created', { code });
|
|
48
|
+
logger.info('[createPlaceholderThread] Created', { code, prompt_id });
|
|
49
|
+
|
|
50
|
+
if (prompt_id) {
|
|
51
|
+
// Imported here to avoid circular dependency
|
|
52
|
+
const { createAssistant } = require('../services/assistantService.js');
|
|
53
|
+
await createAssistant(code, prompt_id, [], true);
|
|
54
|
+
logger.info('[createPlaceholderThread] Assistant created', { code, prompt_id });
|
|
55
|
+
}
|
|
56
|
+
|
|
39
57
|
return thread;
|
|
40
58
|
} catch (error) {
|
|
41
59
|
logger.error('[createPlaceholderThread] Error', { code, error: error.message });
|