@myassis/gateway 1.0.28 → 1.0.29
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,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getGlobalModelSelector = exports.parseAruments = exports.LLMClient = void 0;
|
|
7
4
|
const index_js_1 = require("../../stores/index.js");
|
|
8
5
|
const shared_1 = require("@myassis/shared");
|
|
9
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
6
|
const logger = (0, shared_1.getLogger)('LLMClient');
|
|
11
7
|
/**
|
|
12
8
|
* LLM 调用器类
|
|
@@ -18,7 +14,7 @@ class LLMClient {
|
|
|
18
14
|
tools;
|
|
19
15
|
preferredModelId;
|
|
20
16
|
signal;
|
|
21
|
-
timeoutMs =
|
|
17
|
+
timeoutMs = 120000;
|
|
22
18
|
constructor(models, messages, signal, tools) {
|
|
23
19
|
this.models = models;
|
|
24
20
|
this.messages = messages;
|
|
@@ -80,7 +76,12 @@ class LLMClient {
|
|
|
80
76
|
}
|
|
81
77
|
selector.markTried(model.id);
|
|
82
78
|
clearTimeout(timer);
|
|
83
|
-
|
|
79
|
+
if (controller.signal.aborted) {
|
|
80
|
+
lastError = new Error('Request timed out');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
lastError = error;
|
|
84
|
+
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
throw lastError || new Error('All models are unavailable or has been aborted');
|
|
@@ -401,8 +402,6 @@ class LLMClient {
|
|
|
401
402
|
const tokens = JSON.stringify(body).length;
|
|
402
403
|
logger.debug('tokens', tokens);
|
|
403
404
|
if (tokens > 200000 && !existAttachments) {
|
|
404
|
-
logger.warn('message is too large and has writen to the file debug.json');
|
|
405
|
-
await promises_1.default.writeFile('debug.json', JSON.stringify(body.messages), 'utf-8');
|
|
406
405
|
throw Error('exceed max message tokens');
|
|
407
406
|
}
|
|
408
407
|
return {
|
|
@@ -41,16 +41,13 @@ class MemoryManager {
|
|
|
41
41
|
let messages = this.session.getMessages();
|
|
42
42
|
if (this.childAgent) {
|
|
43
43
|
messages.splice(-1);
|
|
44
|
-
logger.debug('history', messages);
|
|
45
44
|
}
|
|
46
45
|
// 2. 消息少于摘要配置的阈值数,直接返回
|
|
47
|
-
logger.debug('message length:', messages.length);
|
|
48
46
|
if (messages.length < this.config.summaryThreshold) {
|
|
49
47
|
return messages;
|
|
50
48
|
}
|
|
51
49
|
// 3. 检查是否有摘要
|
|
52
50
|
const hasSummary = this.session.lastMessageSummary;
|
|
53
|
-
logger.debug('hasSummary', hasSummary);
|
|
54
51
|
if (!hasSummary) {
|
|
55
52
|
// 4A. 首次摘要生成
|
|
56
53
|
const summary = await this.generateSummaryAsync(messages.slice(0, -index_js_2.appConfig.messageKeep), null);
|
|
@@ -65,7 +62,6 @@ class MemoryManager {
|
|
|
65
62
|
else {
|
|
66
63
|
// 4B. 增量摘要更新
|
|
67
64
|
const newMessages = messages.filter((m) => m.createdAt > this.session.lastMessageSummaryAt);
|
|
68
|
-
logger.debug('new messages length:', newMessages.length);
|
|
69
65
|
if (newMessages.length < this.config.summaryThreshold) {
|
|
70
66
|
// 新消息少于阈值条:返回摘要 + 从摘要时刻起的所有消息
|
|
71
67
|
const fromSummary = messages.filter((m) => m.createdAt >= this.session.lastMessageSummaryAt);
|
|
@@ -120,7 +120,7 @@ exports.execTool = {
|
|
|
120
120
|
}
|
|
121
121
|
catch (e) {
|
|
122
122
|
const error = e;
|
|
123
|
-
resolve({ success: false, errorMessage: error
|
|
123
|
+
resolve({ success: false, errorMessage: (error?.stdout?.toLocaleString()?.substring(0, 100) ?? '') + (error?.stderr?.toLocaleString() ?? '') + (error?.message ?? '') });
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
});
|