@myassis/gateway 1.0.99 → 1.0.100
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/dist/config/index.js +1 -1
- package/dist/services/session/Session.js +15 -10
- package/package.json +1 -1
package/dist/config/index.js
CHANGED
|
@@ -118,7 +118,7 @@ exports.appConfig = {
|
|
|
118
118
|
*/
|
|
119
119
|
/** 模型 maxTokens 缺失时的轮内压缩兜底阈值(字符) */
|
|
120
120
|
turnCompactTriggerChars: parseInt(process.env.TURN_COMPACT_TRIGGER_CHARS || '1000000', 10),
|
|
121
|
-
/**
|
|
121
|
+
/** 模型上下文窗口的可用百分比(折算为字符预算,对齐 Codex 的 90%) */
|
|
122
122
|
turnCompactTriggerPercent: parseInt(process.env.TURN_COMPACT_TRIGGER_PERCENT || '90', 10),
|
|
123
123
|
/** 轮内压缩时保留原文的最近工具调用轮数 */
|
|
124
124
|
turnCompactKeepPairs: parseInt(process.env.TURN_COMPACT_KEEP_PAIRS || '2', 10),
|
|
@@ -925,13 +925,16 @@ class Session {
|
|
|
925
925
|
const models = this.useSystemMode
|
|
926
926
|
? (await dataService_js_1.modelsService.listSystem()).data.map(x => (0, models_js_1.toSystemModel)(x))
|
|
927
927
|
: (await dataService_js_1.modelsService.list(token)).data.map(x => (0, models_js_1.toModel)(x));
|
|
928
|
-
//
|
|
928
|
+
// 计算当前模型上下文窗口对应的字符预算(对齐 Codex 的 90%),
|
|
929
929
|
// 模型未声明 maxTokens 时回退到固定字符阈值。
|
|
930
930
|
const activeModel = models.find(m => m.modelId === this.selectModelId || m.id === this.selectModelId) || models[0];
|
|
931
931
|
const modelMaxTokens = activeModel?.maxTokens || 0;
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
932
|
+
// 发给模型的字符预算:取配置上限与模型窗口(按百分比折算)的较小值,
|
|
933
|
+
// 避免对小窗口模型发出超限请求;大窗口模型则沿用 contextMaxChars。
|
|
934
|
+
const modelWindowChars = modelMaxTokens > 0
|
|
935
|
+
? Math.floor(modelMaxTokens * index_js_2.appConfig.turnCompactTriggerPercent / 100 * ContextBuilder_js_1.CHARS_PER_TOKEN)
|
|
936
|
+
: index_js_2.appConfig.turnCompactTriggerChars;
|
|
937
|
+
const effectiveContextMaxChars = Math.min(index_js_2.appConfig.contextMaxChars, modelWindowChars);
|
|
935
938
|
// 工具调用轮次计数,防止无限循环
|
|
936
939
|
let toolRound = 0;
|
|
937
940
|
// 达到工具轮上限后置位:强制模型停止调用工具、直接产出最终回复
|
|
@@ -1015,15 +1018,17 @@ class Session {
|
|
|
1015
1018
|
const callModel = async () => {
|
|
1016
1019
|
let transientRetries = 0;
|
|
1017
1020
|
while (true) {
|
|
1018
|
-
//
|
|
1019
|
-
//
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
const built = (0, ContextBuilder_js_1.buildContext)(messages, messagesLength, index_js_2.appConfig.contextMaxChars, trimLevel);
|
|
1021
|
+
// 先做分级裁剪(只截断旧工具负载,保留最近 turnCompactKeepPairs 轮完整内容)。
|
|
1022
|
+
// 只有裁剪到当前级别后仍超出预算时,才做轮内摘要压缩;平时靠截断即可,
|
|
1023
|
+
// 避免工具调用一达到轮数就触发摘要。
|
|
1024
|
+
const built = (0, ContextBuilder_js_1.buildContext)(messages, messagesLength, effectiveContextMaxChars, trimLevel);
|
|
1024
1025
|
if (built.trimmed) {
|
|
1025
1026
|
logger.debug(`上下文裁剪: level=${built.level} chars=${built.chars}`);
|
|
1026
1027
|
}
|
|
1028
|
+
if (built.chars > effectiveContextMaxChars) {
|
|
1029
|
+
if (await compactInTurn())
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1027
1032
|
// 收尾阶段不再下发工具定义:只要工具还在,模型大概率继续调用而不收尾
|
|
1028
1033
|
const llmClient = new LLMClient_js_1.LLMClient(models, built.messages, this.abortController.signal, forceFinalize ? [] : tools);
|
|
1029
1034
|
llmClient.setPreferredModel(this.selectModelId);
|