發佈 0.1.12:會話模式新增「每則獨立」,ctx 達 80% 自動開新會話

根本原因:
會話越用越慢——每張生成圖都會塞回上下文,實測同一會話從 36 秒
一路漲到 135 秒,也更容易在串流時被切斷。

修法:
1. 會話模式 sharedSession 布林改為 sessionMode(per-chat / shared / stateless),
   stateless = 每則訊息獨立、不保留記憶,適合單張生圖這類不需上下文的 bot;
   舊設定檔的 sharedSession 自動相容轉換。
2. 新增 autoResetCtxPercent(預設 80):任一會話上下文用量達門檻即自動
   開新會話並在回覆末尾提示,避免無限累積。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-17 16:18:33 +08:00
co-authored by Claude Fable 5
parent cfa61aa01a
commit 24c66130d0
5 changed files with 54 additions and 25 deletions
+4 -4
View File
@@ -78,7 +78,7 @@ async function listBots() {
sandbox: cfg?.sandbox || null,
model: cfg?.model || '',
reasoningEffort: cfg?.reasoningEffort || '',
sharedSession: !!cfg?.sharedSession,
sessionMode: cfg?.sessionMode || 'per-chat',
networkAccess: !!cfg?.networkAccess,
serviceTier: cfg?.serviceTier || '',
timeoutMinutes: cfg?.timeoutMinutes || null,
@@ -114,7 +114,7 @@ function validateBotInput({ name, token, workDir, sandbox }, { isCreate }) {
}
}
async function createBot({ name, token, workDir, sandbox, model, reasoningEffort, sharedSession, networkAccess, timeoutMinutes }) {
async function createBot({ name, token, workDir, sandbox, model, reasoningEffort, sessionMode, networkAccess, timeoutMinutes }) {
validateBotInput({ name, token, workDir, sandbox }, { isCreate: true });
const reg = loadRegistry();
if (reg.bots[name]) throw new Error(`已有同名 bot${name}`);
@@ -130,7 +130,7 @@ async function createBot({ name, token, workDir, sandbox, model, reasoningEffort
sandbox: sandbox || 'workspace-write',
model: model || '',
reasoningEffort: reasoningEffort || '',
sharedSession: !!sharedSession,
sessionMode: ['per-chat','shared','stateless'].includes(sessionMode) ? sessionMode : 'per-chat',
networkAccess: !!networkAccess,
serviceTier: 'priority', // 速度固定 Fast 1.5x
timeoutMinutes: Number(timeoutMinutes) || 30,
@@ -162,7 +162,7 @@ async function updateBot(name, patch) {
}
if (patch.model !== undefined) raw.model = patch.model;
if (patch.reasoningEffort !== undefined) raw.reasoningEffort = patch.reasoningEffort;
if (patch.sharedSession !== undefined) raw.sharedSession = !!patch.sharedSession;
if (['per-chat','shared','stateless'].includes(patch.sessionMode)) { raw.sessionMode = patch.sessionMode; delete raw.sharedSession; }
if (patch.networkAccess !== undefined) raw.networkAccess = !!patch.networkAccess;
if (patch.timeoutMinutes !== undefined && Number(patch.timeoutMinutes) > 0) {
raw.timeoutMinutes = Number(patch.timeoutMinutes);