@myassis/gateway 1.0.99 → 1.0.101
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 +10 -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,12 +1018,9 @@ class Session {
|
|
|
1015
1018
|
const callModel = async () => {
|
|
1016
1019
|
let transientRetries = 0;
|
|
1017
1020
|
while (true) {
|
|
1018
|
-
//
|
|
1019
|
-
//
|
|
1020
|
-
|
|
1021
|
-
await compactInTurn();
|
|
1022
|
-
}
|
|
1023
|
-
const built = (0, ContextBuilder_js_1.buildContext)(messages, messagesLength, index_js_2.appConfig.contextMaxChars, trimLevel);
|
|
1021
|
+
// 分级裁剪只截断旧工具负载(保留最近 turnCompactKeepPairs 轮完整内容),
|
|
1022
|
+
// 不主动做摘要压缩;只有模型返回上下文超限错误时才在 catch 中触发轮内压缩。
|
|
1023
|
+
const built = (0, ContextBuilder_js_1.buildContext)(messages, messagesLength, effectiveContextMaxChars, trimLevel);
|
|
1024
1024
|
if (built.trimmed) {
|
|
1025
1025
|
logger.debug(`上下文裁剪: level=${built.level} chars=${built.chars}`);
|
|
1026
1026
|
}
|