@yeaft/webchat-agent 0.1.559 → 0.1.561
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 +1 -1
- package/unify/vp/vp-bridge.js +25 -10
package/package.json
CHANGED
package/unify/vp/vp-bridge.js
CHANGED
|
@@ -210,16 +210,31 @@ export function buildVpSnapshot(registry = defaultRegistry) {
|
|
|
210
210
|
*/
|
|
211
211
|
export function handleVpSubscribe(sendUnifyEvent, registry = defaultRegistry) {
|
|
212
212
|
const { loader, fresh } = ensureLoader(registry);
|
|
213
|
-
// task-338-F2: replay semantics.
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
|
|
213
|
+
// task-338-F2 + task-339-followup: replay semantics.
|
|
214
|
+
//
|
|
215
|
+
// The loader's own start() already scans on first creation, so on a
|
|
216
|
+
// `fresh` loader an additional `rescanNow()` is normally redundant.
|
|
217
|
+
// HOWEVER — in production (registry === defaultRegistry) the first
|
|
218
|
+
// subscribe can arrive far enough after module import that the on-disk
|
|
219
|
+
// library has diverged from what the initial scan captured (e.g. a
|
|
220
|
+
// platform where `fs.watch` is unreliable, or a containerized
|
|
221
|
+
// bind-mount, or seedDefaultVps writing role.md files after the scan
|
|
222
|
+
// but before the first subscribe). We rescan defensively on the
|
|
223
|
+
// production path so the first snapshot always reflects current disk.
|
|
224
|
+
//
|
|
225
|
+
// For NON-default registries (unit tests that seed VPs manually), we
|
|
226
|
+
// MUST skip the rescan: rescan against DEFAULT_VP_LIB_DIR would call
|
|
227
|
+
// registry.removeVp() for seeded ids that don't exist on disk, wiping
|
|
228
|
+
// the test fixture. See vp-bridge-live-diff.test.js and
|
|
229
|
+
// vp-bridge-first-subscribe-replay.test.js (test-seed preservation).
|
|
230
|
+
//
|
|
231
|
+
// On subsequent subscribes (page reload, reconnect, second web client)
|
|
232
|
+
// rescanNow() refreshes the registry so every client gets a snapshot
|
|
233
|
+
// that reflects current disk — catching the case where the FS watcher
|
|
234
|
+
// missed an event or VPs were added between the initial scan and this
|
|
235
|
+
// subscribe.
|
|
236
|
+
const shouldRescan = (fresh && registry === defaultRegistry) || !fresh;
|
|
237
|
+
if (shouldRescan && loader && typeof loader.rescanNow === 'function') {
|
|
223
238
|
try { loader.rescanNow(); } catch { /* never crash subscribe on rescan */ }
|
|
224
239
|
}
|
|
225
240
|
_subscribers.add(sendUnifyEvent);
|