@yeaft/webchat-agent 1.0.84 → 1.0.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -91,6 +91,10 @@ let sessionLoadPromise = null;
91
91
 
92
92
  let threadClassifier = defaultClassifyThread;
93
93
 
94
+ function liveConfigRoot() {
95
+ return session?.config?.dir || ctx.CONFIG?.yeaftDir || session?.yeaftDir;
96
+ }
97
+
94
98
  function applyLiveLanguage(language) {
95
99
  if (!language || typeof language !== 'string') return;
96
100
  if (session?.config && typeof session.config === 'object') {
@@ -105,7 +109,7 @@ function applyLiveLanguage(language) {
105
109
  function refreshLiveSessionConfig() {
106
110
  if (!session) return;
107
111
  try {
108
- const freshConfig = loadConfig({ dir: session.yeaftDir || ctx.CONFIG?.yeaftDir });
112
+ const freshConfig = loadConfig({ dir: liveConfigRoot() });
109
113
  const freshModels = Array.isArray(freshConfig.availableModels) ? freshConfig.availableModels : [];
110
114
  session.config.availableModels = freshModels;
111
115
  if (freshConfig.language) {
@@ -317,6 +321,8 @@ const vpInboxes = new Map();
317
321
  const vpDrivers = new Map();
318
322
  /** @type {Map<string, import('./engine.js').Engine>} */
319
323
  const vpEngines = new Map();
324
+ /** @type {Map<string, string>} */
325
+ const vpEngineConfigKeys = new Map();
320
326
  /** @type {Map<string, AbortController>} */
321
327
  const vpAborts = new Map();
322
328
 
@@ -404,6 +410,17 @@ function threadKey(sessionId, vpId, threadId) {
404
410
  return `${sessionId}::${vpId}::${threadId || 'main'}`;
405
411
  }
406
412
 
413
+ function engineConfigKey(config) {
414
+ return JSON.stringify({
415
+ model: config?.model || '',
416
+ primaryModel: config?.primaryModel || '',
417
+ modelEffort: config?.modelEffort || '',
418
+ fastModel: config?.fastModel || '',
419
+ fastModelId: config?.fastModelId || '',
420
+ fallbackModel: config?.fallbackModel || '',
421
+ });
422
+ }
423
+
407
424
  function normalizeSessionWorkDir(workDir) {
408
425
  return typeof workDir === 'string' && workDir.trim() ? workDir.trim() : '';
409
426
  }
@@ -1192,7 +1209,7 @@ export function __testGroupHistory(sessionId) {
1192
1209
 
1193
1210
  export function __testResolveVpEffectiveConfig(sessionId) {
1194
1211
  if (!session) return null;
1195
- const sessionConfigRoot = ctx.CONFIG?.yeaftDir || session.yeaftDir;
1212
+ const sessionConfigRoot = liveConfigRoot();
1196
1213
  return resolveSessionConfig(session.config, loadSessionConfig(sessionConfigRoot, sessionId));
1197
1214
  }
1198
1215
 
@@ -1296,17 +1313,23 @@ function isPermissionErrorMsg(msg) {
1296
1313
  */
1297
1314
  function getOrCreateVpEngine(sessionId, vpId, threadId = 'main') {
1298
1315
  const key = threadKey(sessionId, vpId, threadId);
1299
- let eng = vpEngines.get(key);
1300
- if (eng) return eng;
1301
1316
  if (!session) throw new Error('getOrCreateVpEngine: session not loaded');
1302
1317
  // Per-session config overlay (v1: model only). Falls back to the
1303
1318
  // session's user-level config when no override is set. Prefer the agent-local
1304
1319
  // config root: sessionConfigPath() resolves registered workDir-backed
1305
1320
  // sessions from there, while still allowing a later agent-local session in
1306
1321
  // the same bridge runtime to read its own override after a workDir-first boot.
1307
- const sessionConfigRoot = ctx.CONFIG?.yeaftDir || session.yeaftDir;
1322
+ const sessionConfigRoot = liveConfigRoot();
1308
1323
  const groupCfg = loadSessionConfig(sessionConfigRoot, sessionId);
1309
1324
  const effectiveConfig = resolveSessionConfig(session.config, groupCfg);
1325
+ const configKey = engineConfigKey(effectiveConfig);
1326
+ let eng = vpEngines.get(key);
1327
+ if (eng && vpEngineConfigKeys.get(key) === configKey) return eng;
1328
+ if (eng) {
1329
+ try { eng.abort?.('config_changed'); } catch { /* best-effort */ }
1330
+ vpEngines.delete(key);
1331
+ vpEngineConfigKeys.delete(key);
1332
+ }
1310
1333
  eng = new Engine({
1311
1334
  adapter: session.adapter,
1312
1335
  trace: session.trace,
@@ -1342,6 +1365,7 @@ function getOrCreateVpEngine(sessionId, vpId, threadId = 'main') {
1342
1365
  }
1343
1366
  } catch { /* coordinator is best-effort plumbing, never block engine creation */ }
1344
1367
  vpEngines.set(key, eng);
1368
+ vpEngineConfigKeys.set(key, configKey);
1345
1369
  return eng;
1346
1370
  }
1347
1371
 
@@ -1845,6 +1869,7 @@ export async function __testResetVpState() {
1845
1869
  vpInboxes.clear();
1846
1870
  vpDrivers.clear();
1847
1871
  vpEngines.clear();
1872
+ vpEngineConfigKeys.clear();
1848
1873
  asyncTaskOwners.clear();
1849
1874
  vpAborts.clear();
1850
1875
  sessionContexts.clear();
@@ -2573,7 +2598,10 @@ export function handleYeaftUpdateSessionConfig(msg) {
2573
2598
  // Drop cached engines so the next VP turn rebuilds with the new model.
2574
2599
  const prefix = `${sessionId}::`;
2575
2600
  for (const k of Array.from(vpEngines.keys())) {
2576
- if (k.startsWith(prefix)) vpEngines.delete(k);
2601
+ if (k.startsWith(prefix)) {
2602
+ vpEngines.delete(k);
2603
+ vpEngineConfigKeys.delete(k);
2604
+ }
2577
2605
  }
2578
2606
  invalidateGroupContext(sessionId);
2579
2607
  sendSessionCrudResult({ op: 'update_config', requestId, ok: true, sessionId, config: savedConfig });
@@ -2630,7 +2658,10 @@ export function handleYeaftDeleteSession(msg) {
2630
2658
  invalidateGroupContext(sessionId);
2631
2659
  const prefix = `${sessionId}::`;
2632
2660
  for (const k of Array.from(vpEngines.keys())) {
2633
- if (k.startsWith(prefix)) vpEngines.delete(k);
2661
+ if (k.startsWith(prefix)) {
2662
+ vpEngines.delete(k);
2663
+ vpEngineConfigKeys.delete(k);
2664
+ }
2634
2665
  }
2635
2666
  sendSessionCrudResult({
2636
2667
  op: 'delete',
@@ -2675,7 +2706,10 @@ export function handleYeaftSessionRemoveMember(msg) {
2675
2706
  // added back they should start with fresh per-thread state.
2676
2707
  const removedPrefix = `${sessionId}::${vpId}::`;
2677
2708
  for (const key of Array.from(vpEngines.keys())) {
2678
- if (key.startsWith(removedPrefix)) vpEngines.delete(key);
2709
+ if (key.startsWith(removedPrefix)) {
2710
+ vpEngines.delete(key);
2711
+ vpEngineConfigKeys.delete(key);
2712
+ }
2679
2713
  }
2680
2714
  sendSessionCrudResult({ op: 'remove_member', requestId, ok: true, session: group });
2681
2715
  sendSessionRosterChanged(group);
@@ -5487,6 +5521,7 @@ export function handleYeaftModelSwitch(msg) {
5487
5521
  // Engines would otherwise keep the old effective config and drop newly
5488
5522
  // selected effort values until process restart.
5489
5523
  vpEngines.clear();
5524
+ vpEngineConfigKeys.clear();
5490
5525
  asyncTaskOwners.clear();
5491
5526
 
5492
5527
  sendSessionEvent({
@@ -5843,6 +5878,7 @@ export async function resetYeaftSession() {
5843
5878
  vpInboxes.clear();
5844
5879
  vpDrivers.clear();
5845
5880
  vpEngines.clear();
5881
+ vpEngineConfigKeys.clear();
5846
5882
  asyncTaskOwners.clear();
5847
5883
  sessionContexts.clear();
5848
5884
  vpCurrentTodos.clear();