@resolveio/server-lib 22.1.29 → 22.1.30
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/methods/ai-terminal.js +145 -4
- package/methods/ai-terminal.js.map +1 -1
- package/methods.ts +3 -0
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -1184,6 +1184,24 @@ function loadAiTerminalMethods(methodManager) {
|
|
|
1184
1184
|
});
|
|
1185
1185
|
});
|
|
1186
1186
|
} }),
|
|
1187
|
+
aiCoderTerminalRunStatus: {
|
|
1188
|
+
check: new simpl_schema_1.default({
|
|
1189
|
+
payload: {
|
|
1190
|
+
type: Object,
|
|
1191
|
+
blackbox: true
|
|
1192
|
+
}
|
|
1193
|
+
}),
|
|
1194
|
+
function: function (payload) {
|
|
1195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1196
|
+
return __generator(this, function (_a) {
|
|
1197
|
+
switch (_a.label) {
|
|
1198
|
+
case 0: return [4 /*yield*/, executeAiAssistantCodexRunStatus(payload, this)];
|
|
1199
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
},
|
|
1187
1205
|
aiCoderTerminalReportIssue: {
|
|
1188
1206
|
check: new simpl_schema_1.default({
|
|
1189
1207
|
payload: {
|
|
@@ -2678,6 +2696,98 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2678
2696
|
});
|
|
2679
2697
|
});
|
|
2680
2698
|
}
|
|
2699
|
+
function executeAiAssistantCodexRunStatus(payload, context) {
|
|
2700
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2701
|
+
var input, idUser, requestedConversationId, requestedMessageId, requestedRequestId, conversation, conversationId, ownerId, assistantMessage, messageConversationId, ownerId, pending, messageRequestId;
|
|
2702
|
+
var _a, _b;
|
|
2703
|
+
return __generator(this, function (_c) {
|
|
2704
|
+
switch (_c.label) {
|
|
2705
|
+
case 0:
|
|
2706
|
+
input = payload || {};
|
|
2707
|
+
idUser = normalizeOptionalString(context === null || context === void 0 ? void 0 : context.id_user);
|
|
2708
|
+
if (!idUser) {
|
|
2709
|
+
throw new Error('Unauthorized.');
|
|
2710
|
+
}
|
|
2711
|
+
requestedConversationId = normalizeOptionalString(input.id_conversation);
|
|
2712
|
+
requestedMessageId = normalizeOptionalString(input.id_message);
|
|
2713
|
+
requestedRequestId = normalizeOptionalString(input.request_id);
|
|
2714
|
+
if (!requestedConversationId && !requestedMessageId && !requestedRequestId) {
|
|
2715
|
+
throw new Error('Conversation id, message id, or request id is required.');
|
|
2716
|
+
}
|
|
2717
|
+
conversation = null;
|
|
2718
|
+
conversationId = requestedConversationId;
|
|
2719
|
+
if (!conversationId) return [3 /*break*/, 2];
|
|
2720
|
+
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.findById(conversationId)];
|
|
2721
|
+
case 1:
|
|
2722
|
+
conversation = _c.sent();
|
|
2723
|
+
if (!conversation) {
|
|
2724
|
+
throw new Error('Conversation not found.');
|
|
2725
|
+
}
|
|
2726
|
+
ownerId = normalizeOptionalString(conversation.id_user);
|
|
2727
|
+
if (ownerId && ownerId !== idUser) {
|
|
2728
|
+
throw new Error('Conversation access denied.');
|
|
2729
|
+
}
|
|
2730
|
+
_c.label = 2;
|
|
2731
|
+
case 2:
|
|
2732
|
+
assistantMessage = null;
|
|
2733
|
+
if (!requestedMessageId) return [3 /*break*/, 4];
|
|
2734
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({ _id: requestedMessageId })];
|
|
2735
|
+
case 3:
|
|
2736
|
+
assistantMessage = (_c.sent());
|
|
2737
|
+
if (assistantMessage) {
|
|
2738
|
+
messageConversationId = normalizeOptionalString(assistantMessage.id_conversation);
|
|
2739
|
+
if (!conversationId) {
|
|
2740
|
+
conversationId = messageConversationId;
|
|
2741
|
+
}
|
|
2742
|
+
if (conversationId && messageConversationId && messageConversationId !== conversationId) {
|
|
2743
|
+
throw new Error('Message does not belong to the selected conversation.');
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
_c.label = 4;
|
|
2747
|
+
case 4:
|
|
2748
|
+
if (!(!conversation && conversationId)) return [3 /*break*/, 6];
|
|
2749
|
+
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.findById(conversationId)];
|
|
2750
|
+
case 5:
|
|
2751
|
+
conversation = _c.sent();
|
|
2752
|
+
if (!conversation) {
|
|
2753
|
+
throw new Error('Conversation not found.');
|
|
2754
|
+
}
|
|
2755
|
+
ownerId = normalizeOptionalString(conversation.id_user);
|
|
2756
|
+
if (ownerId && ownerId !== idUser) {
|
|
2757
|
+
throw new Error('Conversation access denied.');
|
|
2758
|
+
}
|
|
2759
|
+
_c.label = 6;
|
|
2760
|
+
case 6:
|
|
2761
|
+
if (!(!assistantMessage && conversationId && requestedRequestId)) return [3 /*break*/, 8];
|
|
2762
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({
|
|
2763
|
+
id_conversation: conversationId,
|
|
2764
|
+
role: 'assistant',
|
|
2765
|
+
'metadata.request_id': requestedRequestId
|
|
2766
|
+
}, { sort: { createdAt: -1 } })];
|
|
2767
|
+
case 7:
|
|
2768
|
+
assistantMessage = (_c.sent());
|
|
2769
|
+
_c.label = 8;
|
|
2770
|
+
case 8:
|
|
2771
|
+
if (!(!assistantMessage && conversationId && !requestedRequestId)) return [3 /*break*/, 10];
|
|
2772
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({ id_conversation: conversationId, role: 'assistant' }, { sort: { createdAt: -1 } })];
|
|
2773
|
+
case 9:
|
|
2774
|
+
assistantMessage = (_c.sent());
|
|
2775
|
+
_c.label = 10;
|
|
2776
|
+
case 10:
|
|
2777
|
+
pending = ((_a = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.metadata) === null || _a === void 0 ? void 0 : _a.pending) === true;
|
|
2778
|
+
messageRequestId = normalizeOptionalString((_b = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.metadata) === null || _b === void 0 ? void 0 : _b.request_id);
|
|
2779
|
+
return [2 /*return*/, {
|
|
2780
|
+
id_conversation: conversationId || normalizeOptionalString(assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.id_conversation),
|
|
2781
|
+
id_message: normalizeOptionalString(assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage._id),
|
|
2782
|
+
request_id: requestedRequestId || messageRequestId,
|
|
2783
|
+
pending: pending,
|
|
2784
|
+
done: !!assistantMessage && !pending,
|
|
2785
|
+
message: assistantMessage || null
|
|
2786
|
+
}];
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2681
2791
|
function executeAiAssistantReportBuilderRead(payload, context) {
|
|
2682
2792
|
return __awaiter(this, void 0, void 0, function () {
|
|
2683
2793
|
return __generator(this, function (_a) {
|
|
@@ -20517,6 +20627,12 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20517
20627
|
result = _h.sent();
|
|
20518
20628
|
_h.label = 4;
|
|
20519
20629
|
case 4:
|
|
20630
|
+
if (!result || result.matchedCount === 0) {
|
|
20631
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20632
|
+
messageId: fallbackId || messageId,
|
|
20633
|
+
via: 'collection_manager'
|
|
20634
|
+
});
|
|
20635
|
+
}
|
|
20520
20636
|
if (debugEnabled) {
|
|
20521
20637
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update', {
|
|
20522
20638
|
messageId: fallbackId || messageId,
|
|
@@ -20554,7 +20670,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20554
20670
|
case 8:
|
|
20555
20671
|
result = _h.sent();
|
|
20556
20672
|
_h.label = 9;
|
|
20557
|
-
case 9:
|
|
20673
|
+
case 9:
|
|
20674
|
+
if (!result || result.matchedCount === 0) {
|
|
20675
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20676
|
+
messageId: fallbackId || messageId,
|
|
20677
|
+
via: 'direct_mongo_fallback'
|
|
20678
|
+
});
|
|
20679
|
+
}
|
|
20680
|
+
return [4 /*yield*/, notifyAiTerminalCollectionUpdate('ai-terminal-messages', fallbackId || messageId)];
|
|
20558
20681
|
case 10:
|
|
20559
20682
|
_h.sent();
|
|
20560
20683
|
if (debugEnabled) {
|
|
@@ -20581,6 +20704,12 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20581
20704
|
retryResult = _h.sent();
|
|
20582
20705
|
_h.label = 16;
|
|
20583
20706
|
case 16:
|
|
20707
|
+
if (!retryResult || retryResult.matchedCount === 0) {
|
|
20708
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20709
|
+
messageId: fallbackId || messageId,
|
|
20710
|
+
via: 'collection_manager_retry'
|
|
20711
|
+
});
|
|
20712
|
+
}
|
|
20584
20713
|
if (debugEnabled) {
|
|
20585
20714
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update', {
|
|
20586
20715
|
messageId: fallbackId || messageId,
|
|
@@ -20597,7 +20726,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20597
20726
|
}
|
|
20598
20727
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
20599
20728
|
return __awaiter(this, void 0, void 0, function () {
|
|
20600
|
-
var update, error_13, dbName, conversationsCollection;
|
|
20729
|
+
var update, result, error_13, dbName, conversationsCollection, fallbackResult;
|
|
20601
20730
|
return __generator(this, function (_a) {
|
|
20602
20731
|
switch (_a.label) {
|
|
20603
20732
|
case 0:
|
|
@@ -20613,7 +20742,13 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
20613
20742
|
_a.trys.push([1, 3, , 6]);
|
|
20614
20743
|
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: idConversation }, { $set: update }, undefined, false, false, true)];
|
|
20615
20744
|
case 2:
|
|
20616
|
-
_a.sent();
|
|
20745
|
+
result = _a.sent();
|
|
20746
|
+
if (!result || result.matchedCount === 0) {
|
|
20747
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] conversation touch no-match', {
|
|
20748
|
+
idConversation: idConversation,
|
|
20749
|
+
via: 'collection_manager'
|
|
20750
|
+
});
|
|
20751
|
+
}
|
|
20617
20752
|
return [2 /*return*/];
|
|
20618
20753
|
case 3:
|
|
20619
20754
|
error_13 = _a.sent();
|
|
@@ -20626,7 +20761,13 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
20626
20761
|
.collection('ai-terminal-conversations');
|
|
20627
20762
|
return [4 /*yield*/, conversationsCollection.updateOne({ _id: idConversation }, { $set: update })];
|
|
20628
20763
|
case 4:
|
|
20629
|
-
_a.sent();
|
|
20764
|
+
fallbackResult = _a.sent();
|
|
20765
|
+
if (!fallbackResult || fallbackResult.matchedCount === 0) {
|
|
20766
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] conversation touch no-match', {
|
|
20767
|
+
idConversation: idConversation,
|
|
20768
|
+
via: 'direct_mongo_fallback'
|
|
20769
|
+
});
|
|
20770
|
+
}
|
|
20630
20771
|
return [4 /*yield*/, notifyAiTerminalCollectionUpdate('ai-terminal-conversations', idConversation)];
|
|
20631
20772
|
case 5:
|
|
20632
20773
|
_a.sent();
|