@peopl-health/nexus 6.0.14 → 6.0.16
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.
|
@@ -67,9 +67,9 @@ const createAssistantCore = async (code, assistant_id, _messages = [], force = f
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const curRow = await getCurRow(Historial_Clinico_ID, code);
|
|
70
|
-
logger.info('[createAssistant] curRow', { curRow: curRow[0] });
|
|
71
70
|
const nombre = curRow?.[0]?.['name'] || null;
|
|
72
71
|
const patientId = curRow?.[0]?.['record_id'] || null;
|
|
72
|
+
logger.info('[createAssistant] curRow', { patientId });
|
|
73
73
|
|
|
74
74
|
try {
|
|
75
75
|
const assistant = getAssistantById(assistant_id, null);
|
|
@@ -83,7 +83,7 @@ const createAssistantCore = async (code, assistant_id, _messages = [], force = f
|
|
|
83
83
|
};
|
|
84
84
|
Thread.setConversationId(thread, initialThread.id);
|
|
85
85
|
|
|
86
|
-
const condition = {
|
|
86
|
+
const condition = { code };
|
|
87
87
|
const options = { new: true, upsert: true };
|
|
88
88
|
const updatedThread = await Thread.findOneAndUpdate(condition, { ...thread }, options);
|
|
89
89
|
await setThreadPromptId(code, assistant_id);
|
|
@@ -30,7 +30,7 @@ const threadSchema = new mongoose.Schema({
|
|
|
30
30
|
lastMessageMedia: { type: Object, default: null }
|
|
31
31
|
}, { timestamps: true });
|
|
32
32
|
|
|
33
|
-
threadSchema.index({ code: 1 });
|
|
33
|
+
threadSchema.index({ code: 1 }, { unique: true });
|
|
34
34
|
threadSchema.index({ thread_id: 1 });
|
|
35
35
|
threadSchema.index({ conversation_id: 1 });
|
|
36
36
|
threadSchema.index({ lastMessageAt: -1 }, { name: 'last_message_at_idx', sparse: true });
|
|
@@ -173,15 +173,20 @@ const rewriteOps = (docs, setFor) => docs.map((doc) => ({
|
|
|
173
173
|
updateOne: { filter: { _id: doc._id }, update: { $set: setFor(doc) } },
|
|
174
174
|
}));
|
|
175
175
|
|
|
176
|
+
// The new number may write mid-migration and get its own thread; the source thread is then archived like a merge.
|
|
177
|
+
const renameThread = (thread, target) => Thread.updateOne({ _id: thread._id }, { $set: { code: target } }).then(() => true, (error) => {
|
|
178
|
+
if (error.code !== 11000) throw error;
|
|
179
|
+
return false;
|
|
180
|
+
});
|
|
181
|
+
|
|
176
182
|
async function moveThreads(source, target, state, migrationId) {
|
|
177
|
-
const archived = `archived:${source}`;
|
|
178
183
|
const [newest, ...rest] = [...state.sourceThreads].sort((a, b) => new Date(b.createdAt || 0) - new Date(a.createdAt || 0));
|
|
179
|
-
const
|
|
180
|
-
|
|
184
|
+
const renamed = !state.targetThread && !!newest && await renameThread(newest, target);
|
|
185
|
+
const toArchive = renamed ? rest : state.sourceThreads;
|
|
181
186
|
if (toArchive.length) {
|
|
182
|
-
await Thread.
|
|
187
|
+
await Thread.bulkWrite(rewriteOps(toArchive, (doc) => ({ code: `archived:${source}:${doc._id}`, stopped: true })));
|
|
183
188
|
}
|
|
184
|
-
logger.debug('[migratePatientCode] Threads moved', { migrationId, renamed
|
|
189
|
+
logger.debug('[migratePatientCode] Threads moved', { migrationId, renamed, archived: toArchive.length });
|
|
185
190
|
}
|
|
186
191
|
|
|
187
192
|
async function migratePatientCode({ from, to, asCaregiver = false, apply = false, operator = null } = {}) {
|