Add files via upload

This commit is contained in:
2026-01-01 20:03:54 +08:00
committed by GitHub
parent 5df9c5ebd3
commit f44395120b
8 changed files with 680 additions and 265 deletions

View File

@@ -4,6 +4,8 @@ export class ContextManager {
this.tokenLimit = 100000;
this.rules = [];
this.worldInfo = [];
this.activeWorldInfoCache = new Map();
this.cacheDuration = 3;
}
addRule(rule) {
@@ -40,12 +42,27 @@ export class ContextManager {
return contextText.includes(rule.keyword);
});
const relevantWorldInfo = this.worldInfo.filter(entry => {
const currentMatches = this.worldInfo.filter(entry => {
if (!entry.enabled) return false;
if (!entry.keys || entry.keys.length === 0) return false;
return entry.keys.some(key => contextText.includes(key));
});
for (const [uid, data] of this.activeWorldInfoCache) {
data.turnsLeft--;
if (data.turnsLeft <= 0) {
this.activeWorldInfoCache.delete(uid);
}
}
currentMatches.forEach(entry => {
this.activeWorldInfoCache.set(entry.id, { turnsLeft: this.cacheDuration });
});
const allRelevantUIDs = new Set([...currentMatches.map(e => e.id), ...this.activeWorldInfoCache.keys()]);
const relevantWorldInfo = this.worldInfo.filter(entry => allRelevantUIDs.has(entry.id));
return {
rules: relevantRules,
worldInfo: relevantWorldInfo