@resolveio/server-lib 22.1.29 → 22.1.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.
- package/methods/ai-terminal.js +177 -26
- 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) {
|
|
@@ -2700,7 +2810,7 @@ function executeAiAssistantReportBuilderAggregate(payload, context) {
|
|
|
2700
2810
|
}
|
|
2701
2811
|
function executeAiAssistantReportIssue(payload, context) {
|
|
2702
2812
|
return __awaiter(this, void 0, void 0, function () {
|
|
2703
|
-
var input, reason, expected, requestedConversationId, requestedMessageId, conversationId, assistantMessage, messageConversationId, conversation, userPrompt, createdAt, userQuery, userMessage, assistantContent, toolResult, reportMetadata, category, severity, requestId, idClient, _a, idApp, now, doc, insertResult;
|
|
2813
|
+
var input, reason, expected, requestedConversationId, requestedMessageId, requestedRequestId, conversationId, assistantMessage, messageConversationId, conversation, userPrompt, createdAt, userQuery, userMessage, assistantContent, toolResult, reportMetadata, category, severity, requestId, idClient, _a, idApp, now, doc, insertResult;
|
|
2704
2814
|
var _b, _c, _d, _e, _f, _g;
|
|
2705
2815
|
return __generator(this, function (_h) {
|
|
2706
2816
|
switch (_h.label) {
|
|
@@ -2713,21 +2823,21 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2713
2823
|
}
|
|
2714
2824
|
requestedConversationId = normalizeOptionalString(input.id_conversation);
|
|
2715
2825
|
requestedMessageId = normalizeOptionalString(input.id_message);
|
|
2826
|
+
requestedRequestId = normalizeOptionalString(input.request_id);
|
|
2716
2827
|
conversationId = requestedConversationId;
|
|
2717
2828
|
assistantMessage = null;
|
|
2718
2829
|
if (!requestedMessageId) return [3 /*break*/, 2];
|
|
2719
2830
|
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({ _id: requestedMessageId })];
|
|
2720
2831
|
case 1:
|
|
2721
2832
|
assistantMessage = (_h.sent());
|
|
2722
|
-
if (
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
throw new Error('Message does not belong to the selected conversation.');
|
|
2833
|
+
if (assistantMessage) {
|
|
2834
|
+
messageConversationId = normalizeOptionalString(assistantMessage.id_conversation);
|
|
2835
|
+
if (!conversationId) {
|
|
2836
|
+
conversationId = messageConversationId;
|
|
2837
|
+
}
|
|
2838
|
+
else if (messageConversationId && messageConversationId !== conversationId) {
|
|
2839
|
+
throw new Error('Message does not belong to the selected conversation.');
|
|
2840
|
+
}
|
|
2731
2841
|
}
|
|
2732
2842
|
_h.label = 2;
|
|
2733
2843
|
case 2:
|
|
@@ -2740,14 +2850,24 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2740
2850
|
if (!conversation) {
|
|
2741
2851
|
throw new Error('Conversation not found.');
|
|
2742
2852
|
}
|
|
2743
|
-
if (
|
|
2744
|
-
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({
|
|
2853
|
+
if (!(!assistantMessage && requestedRequestId)) return [3 /*break*/, 5];
|
|
2854
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({
|
|
2855
|
+
id_conversation: conversationId,
|
|
2856
|
+
role: 'assistant',
|
|
2857
|
+
'metadata.request_id': requestedRequestId
|
|
2858
|
+
}, { sort: { createdAt: -1 } })];
|
|
2745
2859
|
case 4:
|
|
2746
2860
|
assistantMessage = (_h.sent());
|
|
2747
2861
|
_h.label = 5;
|
|
2748
2862
|
case 5:
|
|
2863
|
+
if (!!assistantMessage) return [3 /*break*/, 7];
|
|
2864
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne({ id_conversation: conversationId, role: 'assistant' }, { sort: { createdAt: -1 } })];
|
|
2865
|
+
case 6:
|
|
2866
|
+
assistantMessage = (_h.sent());
|
|
2867
|
+
_h.label = 7;
|
|
2868
|
+
case 7:
|
|
2749
2869
|
userPrompt = '';
|
|
2750
|
-
if (!assistantMessage) return [3 /*break*/,
|
|
2870
|
+
if (!assistantMessage) return [3 /*break*/, 9];
|
|
2751
2871
|
createdAt = (assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.createdAt) ? new Date(assistantMessage.createdAt) : null;
|
|
2752
2872
|
userQuery = {
|
|
2753
2873
|
id_conversation: conversationId,
|
|
@@ -2757,13 +2877,13 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2757
2877
|
userQuery.createdAt = { $lte: createdAt };
|
|
2758
2878
|
}
|
|
2759
2879
|
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.findOne(userQuery, { sort: { createdAt: -1 } })];
|
|
2760
|
-
case
|
|
2880
|
+
case 8:
|
|
2761
2881
|
userMessage = _h.sent();
|
|
2762
2882
|
if (userMessage === null || userMessage === void 0 ? void 0 : userMessage.content) {
|
|
2763
2883
|
userPrompt = normalizeOptionalString(userMessage.content);
|
|
2764
2884
|
}
|
|
2765
|
-
_h.label =
|
|
2766
|
-
case
|
|
2885
|
+
_h.label = 9;
|
|
2886
|
+
case 9:
|
|
2767
2887
|
assistantContent = normalizeOptionalString(assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.content);
|
|
2768
2888
|
toolResult = (_b = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.metadata) === null || _b === void 0 ? void 0 : _b.tool_result;
|
|
2769
2889
|
reportMetadata = (input === null || input === void 0 ? void 0 : input.metadata) && typeof input.metadata === 'object' && !Array.isArray(input.metadata)
|
|
@@ -2780,21 +2900,21 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2780
2900
|
|| normalizeOptionalString((_c = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.metadata) === null || _c === void 0 ? void 0 : _c.request_id);
|
|
2781
2901
|
_a = normalizeOptionalString(input.id_client)
|
|
2782
2902
|
|| normalizeOptionalString(conversation === null || conversation === void 0 ? void 0 : conversation.id_client);
|
|
2783
|
-
if (_a) return [3 /*break*/,
|
|
2903
|
+
if (_a) return [3 /*break*/, 11];
|
|
2784
2904
|
return [4 /*yield*/, resolveClientIdFromConfig(undefined, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
2785
|
-
case
|
|
2905
|
+
case 10:
|
|
2786
2906
|
_a = (_h.sent());
|
|
2787
|
-
_h.label =
|
|
2788
|
-
case
|
|
2907
|
+
_h.label = 11;
|
|
2908
|
+
case 11:
|
|
2789
2909
|
idClient = _a;
|
|
2790
2910
|
idApp = normalizeOptionalString(input.id_app)
|
|
2791
2911
|
|| normalizeOptionalString(conversation === null || conversation === void 0 ? void 0 : conversation.id_app);
|
|
2792
2912
|
now = new Date();
|
|
2793
2913
|
doc = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ id_conversation: conversationId, status: 'open', source: 'user_report', reason: reason }, (expected ? { expected_outcome: expected } : {})), (userPrompt ? { user_prompt: userPrompt } : {})), (assistantContent ? { assistant_content: assistantContent } : {})), (requestId ? { request_id: requestId } : {})), ((toolResult === null || toolResult === void 0 ? void 0 : toolResult.type) ? { tool_type: normalizeOptionalString(toolResult.type) } : {})), (((_d = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _d === void 0 ? void 0 : _d.collection) || ((_e = toolResult === null || toolResult === void 0 ? void 0 : toolResult.input) === null || _e === void 0 ? void 0 : _e.collection)
|
|
2794
2914
|
? { tool_collection: normalizeOptionalString(((_f = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _f === void 0 ? void 0 : _f.collection) || ((_g = toolResult === null || toolResult === void 0 ? void 0 : toolResult.input) === null || _g === void 0 ? void 0 : _g.collection)) }
|
|
2795
|
-
: {})), (
|
|
2915
|
+
: {})), ((assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage._id) || requestedMessageId ? { id_message: normalizeOptionalString((assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage._id) || requestedMessageId) } : {})), (idClient ? { id_client: idClient } : {})), (idApp ? { id_app: idApp } : {})), (normalizeOptionalString(context === null || context === void 0 ? void 0 : context.id_user) ? { id_user: normalizeOptionalString(context.id_user) } : {})), (Object.keys(reportMetadata).length ? { metadata: reportMetadata } : {})), { createdAt: now, updatedAt: now });
|
|
2796
2916
|
return [4 /*yield*/, ai_terminal_issue_report_collection_1.AiTerminalIssueReports.insertOne(doc)];
|
|
2797
|
-
case
|
|
2917
|
+
case 12:
|
|
2798
2918
|
insertResult = _h.sent();
|
|
2799
2919
|
return [2 /*return*/, {
|
|
2800
2920
|
id_issue_report: insertResult._id,
|
|
@@ -20517,6 +20637,12 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20517
20637
|
result = _h.sent();
|
|
20518
20638
|
_h.label = 4;
|
|
20519
20639
|
case 4:
|
|
20640
|
+
if (!result || result.matchedCount === 0) {
|
|
20641
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20642
|
+
messageId: fallbackId || messageId,
|
|
20643
|
+
via: 'collection_manager'
|
|
20644
|
+
});
|
|
20645
|
+
}
|
|
20520
20646
|
if (debugEnabled) {
|
|
20521
20647
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update', {
|
|
20522
20648
|
messageId: fallbackId || messageId,
|
|
@@ -20554,7 +20680,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20554
20680
|
case 8:
|
|
20555
20681
|
result = _h.sent();
|
|
20556
20682
|
_h.label = 9;
|
|
20557
|
-
case 9:
|
|
20683
|
+
case 9:
|
|
20684
|
+
if (!result || result.matchedCount === 0) {
|
|
20685
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20686
|
+
messageId: fallbackId || messageId,
|
|
20687
|
+
via: 'direct_mongo_fallback'
|
|
20688
|
+
});
|
|
20689
|
+
}
|
|
20690
|
+
return [4 /*yield*/, notifyAiTerminalCollectionUpdate('ai-terminal-messages', fallbackId || messageId)];
|
|
20558
20691
|
case 10:
|
|
20559
20692
|
_h.sent();
|
|
20560
20693
|
if (debugEnabled) {
|
|
@@ -20581,6 +20714,12 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20581
20714
|
retryResult = _h.sent();
|
|
20582
20715
|
_h.label = 16;
|
|
20583
20716
|
case 16:
|
|
20717
|
+
if (!retryResult || retryResult.matchedCount === 0) {
|
|
20718
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update no-match', {
|
|
20719
|
+
messageId: fallbackId || messageId,
|
|
20720
|
+
via: 'collection_manager_retry'
|
|
20721
|
+
});
|
|
20722
|
+
}
|
|
20584
20723
|
if (debugEnabled) {
|
|
20585
20724
|
console.log(new Date(), '[AI-Dashboard][AI-Assistant] message finalize update', {
|
|
20586
20725
|
messageId: fallbackId || messageId,
|
|
@@ -20597,7 +20736,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
20597
20736
|
}
|
|
20598
20737
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
20599
20738
|
return __awaiter(this, void 0, void 0, function () {
|
|
20600
|
-
var update, error_13, dbName, conversationsCollection;
|
|
20739
|
+
var update, result, error_13, dbName, conversationsCollection, fallbackResult;
|
|
20601
20740
|
return __generator(this, function (_a) {
|
|
20602
20741
|
switch (_a.label) {
|
|
20603
20742
|
case 0:
|
|
@@ -20613,7 +20752,13 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
20613
20752
|
_a.trys.push([1, 3, , 6]);
|
|
20614
20753
|
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: idConversation }, { $set: update }, undefined, false, false, true)];
|
|
20615
20754
|
case 2:
|
|
20616
|
-
_a.sent();
|
|
20755
|
+
result = _a.sent();
|
|
20756
|
+
if (!result || result.matchedCount === 0) {
|
|
20757
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] conversation touch no-match', {
|
|
20758
|
+
idConversation: idConversation,
|
|
20759
|
+
via: 'collection_manager'
|
|
20760
|
+
});
|
|
20761
|
+
}
|
|
20617
20762
|
return [2 /*return*/];
|
|
20618
20763
|
case 3:
|
|
20619
20764
|
error_13 = _a.sent();
|
|
@@ -20626,7 +20771,13 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
20626
20771
|
.collection('ai-terminal-conversations');
|
|
20627
20772
|
return [4 /*yield*/, conversationsCollection.updateOne({ _id: idConversation }, { $set: update })];
|
|
20628
20773
|
case 4:
|
|
20629
|
-
_a.sent();
|
|
20774
|
+
fallbackResult = _a.sent();
|
|
20775
|
+
if (!fallbackResult || fallbackResult.matchedCount === 0) {
|
|
20776
|
+
console.warn(new Date(), '[AI-Dashboard][AI-Assistant] conversation touch no-match', {
|
|
20777
|
+
idConversation: idConversation,
|
|
20778
|
+
via: 'direct_mongo_fallback'
|
|
20779
|
+
});
|
|
20780
|
+
}
|
|
20630
20781
|
return [4 /*yield*/, notifyAiTerminalCollectionUpdate('ai-terminal-conversations', idConversation)];
|
|
20631
20782
|
case 5:
|
|
20632
20783
|
_a.sent();
|