-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
397 lines (242 loc) · 11.9 KB
/
Copy pathconfig.js
File metadata and controls
397 lines (242 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
const profileBudgets = {
speed: 400,
balanced: 800,
deep: 1200,
};
function record(value ) {
return value !== null && typeof value === "object" && !Array.isArray(value)
? value
: {};
}
function stringValue(value , fallback ) {
return typeof value === "string" && value.length > 0 ? value : fallback;
}
function numberValue(value , fallback ) {
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : fallback;
}
function booleanValue(value , fallback ) {
return typeof value === "boolean" ? value : fallback;
}
function profileValue(value ) {
return value === "speed" || value === "deep" || value === "balanced" ? value : "balanced";
}
function triggerModeValue(value ) {
return value === "always" || value === "explicit" || value === "on-demand" ? value : "on-demand";
}
function structuredOutputModeValue(value ) {
return value === "json_schema" ? "json_schema" : "json_object";
}
function thinkingModeValue(value ) {
return value === "enabled" || value === "disabled" || value === "omit" || value === "low" || value === "high" || value === "max" ? value : "auto";
}
function graphProviderValue(value ) {
return value === "graphiti" || value === "falkordb" || value === "neo4j" ? value : "local-sqlite";
}
function graphRouteModeValue(value ) {
return value === "vector" || value === "graph" || value === "hybrid" ? value : "auto";
}
function graphWriterModeValue(value , fallback ) {
return value === "off" || value === "dry-run" || value === "shadow" || value === "write"
? value
: fallback;
}
function retrievalModeValue(value ) {
return value === "adapter" ? "adapter" : "standalone";
}
function otherProjectPolicyValue(value ) {
return value === "low-weight" ? "low-weight" : "exclude";
}
function stringArray(value , fallback ) {
if (!Array.isArray(value)) return [...fallback];
const output = value
.filter((item) => typeof item === "string")
.map((item) => item.trim())
.filter(Boolean);
return output.length === value.length ? output : [...fallback];
}
function stringMap(value ) {
const output = {};
for (const [key, item] of Object.entries(record(value))) {
if (typeof item === "string") output[key] = item;
}
return output;
}
function numberMap(value , defaults ) {
const output = { ...defaults };
for (const [key, item] of Object.entries(record(value))) {
if (typeof item === "number" && Number.isFinite(item) && item >= 0) output[key] = item;
}
return output;
}
export function readConfig(pluginConfig ) {
const raw = record(pluginConfig);
const profile = profileValue(raw.profile);
const trigger = record(raw.trigger);
const expansion = record(raw.expansion);
const associations = record(expansion.associations);
const strongSignal = record(raw.strongSignal);
const strongSources = record(strongSignal.sources);
const qualityGate = record(raw.qualityGate);
const semanticGate = record(raw.semanticGate);
const projectScope = record(raw.projectScope);
const graphMemory = record(raw.graphMemory);
const graphWriter = record(graphMemory.writer);
const graphWriterCircuitBreaker = record(graphWriter.circuitBreaker);
const rrf = record(raw.rrf);
const trace = record(raw.trace);
return {
enabled: booleanValue(raw.enabled, true),
retrievalMode: retrievalModeValue(raw.retrievalMode),
agents: Array.isArray(raw.agents) && raw.agents.every((item) => typeof item === "string")
? raw.agents
: ["main"],
skipSystemEvents: booleanValue(raw.skipSystemEvents, true),
trigger: {
mode: triggerModeValue(trigger.mode),
explicitPrefixes: stringArray(trigger.explicitPrefixes, ["/recall", "/memory", "回忆:", "记忆:"]),
suppressPrefixes: stringArray(trigger.suppressPrefixes, ["/no-recall", "/no-memory", "不查记忆:"]),
additionalKeywords: stringArray(trigger.additionalKeywords, []),
},
profile,
injectTokenBudget: numberValue(raw.injectTokenBudget, profileBudgets[profile]),
maxTotalMs: numberValue(raw.maxTotalMs, 5000),
searchTimeoutMs: numberValue(raw.searchTimeoutMs, 2200),
expansion: {
endpoint: stringValue(expansion.endpoint, "https://api.deepseek.com/v1").replace(/\/$/, ""),
apiKeyEnv: stringValue(expansion.apiKeyEnv, "DEEPSEEK_API_KEY"),
model: stringValue(expansion.model, "deepseek-v4-flash"),
headers: stringMap(expansion.headers),
timeoutMs: Math.min(2500, numberValue(expansion.timeoutMs, 2500)),
minRemainingBudgetMs: numberValue(expansion.minRemainingBudgetMs, 2750),
maxOutputTokens: numberValue(expansion.maxOutputTokens, 800),
responseFormat: structuredOutputModeValue(expansion.responseFormat),
thinkingMode: thinkingModeValue(expansion.thinkingMode),
associations: {
maxBalanced: numberValue(associations.maxBalanced, 1),
maxDeep: numberValue(associations.maxDeep, 3),
},
},
semanticGate: {
enabled: booleanValue(semanticGate.enabled, false),
model: stringValue(semanticGate.model, stringValue(expansion.model, "deepseek-v4-flash")),
timeoutMs: numberValue(semanticGate.timeoutMs, 1800),
maxOutputTokens: numberValue(semanticGate.maxOutputTokens, 160),
},
projectScope: {
enabled: booleanValue(projectScope.enabled, true),
sameProjectBoost: numberValue(projectScope.sameProjectBoost, 1.5),
includeGlobal: booleanValue(projectScope.includeGlobal, true),
otherProjectPolicy: otherProjectPolicyValue(projectScope.otherProjectPolicy),
otherProjectWeight: numberValue(projectScope.otherProjectWeight, 0.25),
candidateMultiplier: Math.max(1, Math.min(5, numberValue(projectScope.candidateMultiplier, 3))),
gitTimeoutMs: Math.max(25, Math.min(2000, Math.round(numberValue(projectScope.gitTimeoutMs, 250)))),
},
graphMemory: {
enabled: booleanValue(graphMemory.enabled, false),
provider: graphProviderValue(graphMemory.provider),
file: stringValue(graphMemory.file, "memory/graph-memory/graph-memory-v1.sqlite"),
profileFile: stringValue(graphMemory.profileFile, "memory/profile-memory.json"),
vectorDir: stringValue(graphMemory.vectorDir, "memory/graph-memory/episodes"),
readTimeoutMs: numberValue(graphMemory.readTimeoutMs, 120),
writeTimeoutMs: numberValue(graphMemory.writeTimeoutMs, 12000),
routeMode: graphRouteModeValue(graphMemory.routeMode),
maxGraphResults: Math.max(1, Math.round(numberValue(graphMemory.maxGraphResults, 4))),
maxHops: Math.max(1, Math.min(4, Math.round(numberValue(graphMemory.maxHops, 2)))),
profileBudget: numberValue(graphMemory.profileBudget, 160),
vectorBudget: numberValue(graphMemory.vectorBudget, 600),
graphBudget: numberValue(graphMemory.graphBudget, 300),
writer: {
enabled: booleanValue(graphWriter.enabled, true),
mode: graphWriterModeValue(
graphWriter.mode,
booleanValue(graphWriter.enabled, true) && booleanValue(graphMemory.enabled, false) ? "write" : "off",
),
model: stringValue(graphWriter.model, stringValue(expansion.model, "deepseek-v4-flash")),
timeoutMs: numberValue(graphWriter.timeoutMs, 8000),
maxOutputTokens: numberValue(graphWriter.maxOutputTokens, 1200),
maxInputChars: numberValue(graphWriter.maxInputChars, 12000),
traceFile: stringValue(graphWriter.traceFile, "memory/graph-memory/write-traces.jsonl"),
sessionAllowlist: stringArray(graphWriter.sessionAllowlist, []),
isolateVerificationSessions: graphWriter.isolateVerificationSessions !== false,
excludeSessionPatterns: stringArray(graphWriter.excludeSessionPatterns, []),
maxEntitiesPerTurn: Math.max(1, Math.round(numberValue(graphWriter.maxEntitiesPerTurn, 12))),
maxEdgesPerTurn: Math.max(0, Math.round(numberValue(graphWriter.maxEdgesPerTurn, 16))),
maxEpisodesPerTurn: Math.max(0, Math.min(1, Math.round(numberValue(graphWriter.maxEpisodesPerTurn, 1)))),
circuitBreaker: {
failureThreshold: Math.max(1, Math.round(numberValue(graphWriterCircuitBreaker.failureThreshold, 3))),
resetAfterMs: Math.max(1000, Math.round(numberValue(graphWriterCircuitBreaker.resetAfterMs, 300000))),
},
},
},
strongSignal: (() => {
const minScore = numberValue(strongSignal.minScore, 0.85);
const gap = numberValue(strongSignal.gap, 0.15);
const calibration = (name , defaultMin , defaultGap ) => {
const source = record(strongSources[name]);
return {
minScore: numberValue(source.minScore, Math.min(1, defaultMin)),
gap: numberValue(source.gap, Math.min(1, defaultGap)),
};
};
return {
minScore,
gap,
enabled: booleanValue(strongSignal.enabled, true),
sources: {
memory: calibration("memory", minScore, gap),
documents: calibration("documents", minScore + 0.02, gap),
wiki: calibration("wiki", minScore + 0.02, gap),
sessions: calibration("sessions", Math.round((minScore + 0.07) * 100) / 100, Math.round((gap + 0.05) * 100) / 100),
default: calibration("default", minScore + 0.02, gap),
},
};
})(),
qualityGate: (() => {
const legacyHigh = numberValue(qualityGate.minBestRawScore, 0.65);
const highRawScore = numberValue(qualityGate.highRawScore, legacyHigh);
return {
minBestRawScore: highRawScore,
highRawScore,
mediumRawScore: numberValue(qualityGate.mediumRawScore, numberValue(raw.minScore, 0.55)),
minRouteHits: Math.max(1, Math.round(numberValue(qualityGate.minRouteHits, 2))),
metric: qualityGate.metric === "vector" ? "vector" : "blended" ,
};
})(),
rrf: {
k: numberValue(rrf.k, 20),
originalWeight: numberValue(rrf.originalWeight, 2),
rawScoreBlend: numberValue(rrf.rawScoreBlend, 0.5),
},
topK: numberValue(raw.topK, 3),
snippetChars: numberValue(raw.snippetChars, 200),
minScore: numberValue(raw.minScore, 0.55),
candidateMinScore: numberValue(raw.candidateMinScore, 0.1),
preferSources: numberMap(raw.preferSources, { memory: 1, wiki: 1, sessions: 1 }),
trace: {
enabled: booleanValue(trace.enabled, true),
file: stringValue(trace.file, "memory/recall-traces.jsonl"),
},
disableActiveMemoryHint: booleanValue(raw.disableActiveMemoryHint, true),
};
}
export function maxAssociations(config ) {
return maxAssociationsForDepth(config, depthForProfile(config.profile));
}
export function depthForProfile(profile ) {
if (profile === "speed") return "literal";
return profile;
}
export function maxAssociationsForDepth(config , depth ) {
if (depth === "deep") return config.expansion.associations.maxDeep;
if (depth === "balanced") return config.expansion.associations.maxBalanced;
return 0;
}
export function maxResultsForProfile(profile ) {
return maxResultsForDepth(depthForProfile(profile));
}
export function maxResultsForDepth(depth ) {
if (depth === "deep") return 8;
if (depth === "literal") return 3;
return 5;
}
//# sourceURL=C:\Users\lenovo\.openclaw\workspace\plugins\active_recall\config.ts