dsh-memu-memory 1.3.11 → 1.3.13
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/CHANGELOG.md +28 -0
- package/README.md +3 -3
- package/README.zh.md +1 -1
- package/docs/contributing.md +14 -2
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +52 -1
- package/lib/auto-link/candidates.js +10 -5
- package/lib/auto-link/terminology.js +34 -18
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +431 -69
- package/lib/diagnostics.js +514 -0
- package/lib/environment-check.js +325 -0
- package/lib/graph.js +94 -21
- package/lib/index.js +70 -2
- package/lib/local-embedding-manager.js +39 -5
- package/lib/memory.js +81 -0
- package/lib/paths.js +153 -10
- package/lib/private.js +14 -2
- package/lib/rpc.js +66 -2
- package/lib/tools.js +4 -20
- package/lib/vector-profile.js +302 -8
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +1 -2
- package/lib/webui/standalone.js +2 -2
- package/package.json +1 -1
- package/tests/auto-link-candidates.test.mjs +71 -0
- package/tests/client-render.test.mjs +226 -3
- package/tests/diagnostics.test.mjs +257 -0
- package/tests/environment-check.test.mjs +159 -0
- package/tests/global-lifecycle.test.mjs +130 -0
- package/tests/graph-view.test.mjs +31 -3
- package/tests/graph.test.mjs +110 -0
- package/tests/tools.test.mjs +95 -0
- package/tests/webui-auth.test.mjs +73 -0
- package/tests/webui.test.mjs +2 -1
package/lib/vector-profile.js
CHANGED
|
@@ -2,8 +2,8 @@ import fs from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import crypto from 'node:crypto'
|
|
4
4
|
import {
|
|
5
|
-
dataDir, librariesDir, indexDir, ensureDir,
|
|
6
|
-
readJsonStrict, writeJson, withFileLock, stamp, isSafeId,
|
|
5
|
+
dataDir, librariesDir, indexDir, ensureDir, downloadsDir,
|
|
6
|
+
readJsonStrict, writeJson, withFileLock, stamp, isSafeId, warn,
|
|
7
7
|
} from './paths.js'
|
|
8
8
|
import {
|
|
9
9
|
PROVIDER_ORDER, getEmbeddingModel, profileFingerprint, validateEmbeddingManifest,
|
|
@@ -103,11 +103,95 @@ export function sha256Hex(value) {
|
|
|
103
103
|
const DIGEST_FIELDS = ['id', 'dimension', 'maxTokens', 'pooling', 'normalization', 'prefixes', 'quantization',
|
|
104
104
|
'runtime', 'sources', 'files', 'graph', 'protocol', 'preprocessing', 'windowing', 'aggregation', 'tokenizer']
|
|
105
105
|
|
|
106
|
+
// 制品清单里只有这些子字段属于"身份":镜像源、镜像标签、下载地址都回答"从哪拿",
|
|
107
|
+
// 不回答"拿到什么"。
|
|
108
|
+
//
|
|
109
|
+
// 2026-11-21 现场:catalog 给三个 runtime 制品(onnxruntime-node / onnxruntime-common /
|
|
110
|
+
// @huggingface/tokenizers)加了 npmmirror 镜像条目,name/version/bytes/sha256/integrity
|
|
111
|
+
// 一个都没变,已激活 profile 却被判"manifest 已变",语义召回连坏 9 天(661 次失败)。
|
|
112
|
+
// 同一类 bug 2026-10-30 已在 displayName/summary 上出现过一次,当时只修了顶层文案:
|
|
113
|
+
// 原则一致——**文案与来源不是制品身份**,这次把 runtime/sources 里的镜像层也收窄掉。
|
|
114
|
+
const RUNTIME_IDENTITY_FIELDS = ['engine', 'abi', 'version', 'os', 'arch']
|
|
115
|
+
// 这些键只描述"从哪个镜像下载",不参与身份。
|
|
116
|
+
const MIRROR_KEYS = new Set(['sources', 'mirrors', 'mirror', 'label', 'displayName', 'summary', 'note', 'url', 'gated'])
|
|
117
|
+
|
|
118
|
+
function identityArtifact(item) {
|
|
119
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) return item
|
|
120
|
+
const out = {}
|
|
121
|
+
for (const key of Object.keys(item)) {
|
|
122
|
+
if (MIRROR_KEYS.has(key)) continue
|
|
123
|
+
out[key] = item[key]
|
|
124
|
+
}
|
|
125
|
+
return out
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// runtime 里还可能是"平台 → 制品"的字典(artifacts: { 'win32-x64': {...} })或制品数组
|
|
129
|
+
// (artifacts: [{...}])。两种都要剥镜像层,否则字典形态会把 sources 原样算进身份。
|
|
130
|
+
function identityNested(value) {
|
|
131
|
+
if (Array.isArray(value)) return value.map(item => identityNested(item))
|
|
132
|
+
if (!value || typeof value !== 'object') return value
|
|
133
|
+
const out = {}
|
|
134
|
+
for (const key of Object.keys(value)) {
|
|
135
|
+
if (MIRROR_KEYS.has(key)) continue
|
|
136
|
+
const inner = value[key]
|
|
137
|
+
out[key] = inner && typeof inner === 'object' ? identityNested(inner) : inner
|
|
138
|
+
}
|
|
139
|
+
return out
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function identityRuntime(runtime) {
|
|
143
|
+
if (runtime === undefined) return undefined
|
|
144
|
+
if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime)) return runtime
|
|
145
|
+
const out = {}
|
|
146
|
+
for (const key of RUNTIME_IDENTITY_FIELDS) if (runtime[key] !== undefined) out[key] = runtime[key]
|
|
147
|
+
for (const key of Object.keys(runtime)) {
|
|
148
|
+
if (RUNTIME_IDENTITY_FIELDS.includes(key)) continue
|
|
149
|
+
const value = runtime[key]
|
|
150
|
+
if (MIRROR_KEYS.has(key)) continue
|
|
151
|
+
if (Array.isArray(value)) out[key] = value.map(identityArtifact)
|
|
152
|
+
else if (value && typeof value === 'object') out[key] = identityNested(value)
|
|
153
|
+
else out[key] = value
|
|
154
|
+
}
|
|
155
|
+
return out
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function identitySources(sources) {
|
|
159
|
+
if (sources === undefined) return undefined
|
|
160
|
+
if (!sources || typeof sources !== 'object' || Array.isArray(sources)) return sources
|
|
161
|
+
const out = {}
|
|
162
|
+
for (const provider of Object.keys(sources)) {
|
|
163
|
+
const value = sources[provider]
|
|
164
|
+
out[provider] = value && typeof value === 'object' && !Array.isArray(value) ? identityArtifact(value) : value
|
|
165
|
+
}
|
|
166
|
+
return out
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 单个摘要字段的"身份视图":runtime/sources 去掉镜像层,其余字段原样。 */
|
|
170
|
+
function identityOf(field, value) {
|
|
171
|
+
if (field === 'runtime') return identityRuntime(value)
|
|
172
|
+
if (field === 'sources') return identitySources(value)
|
|
173
|
+
return value
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function digestSubset(manifest, normalize) {
|
|
177
|
+
const subset = {}
|
|
178
|
+
for (const key of DIGEST_FIELDS) {
|
|
179
|
+
if (manifest[key] === undefined) continue
|
|
180
|
+
subset[key] = normalize ? identityOf(key, manifest[key]) : manifest[key]
|
|
181
|
+
}
|
|
182
|
+
return subset
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 当前算法:摘要只覆盖身份视图里的制品字段。 */
|
|
106
186
|
export function manifestDigest(manifest) {
|
|
107
187
|
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return null
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
188
|
+
return sha256Hex(stableStringify(digestSubset(manifest, true)))
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 1.3.x 算法(DIGEST_FIELDS 原样):只用于兼容已经落盘的 profile。 */
|
|
192
|
+
export function rawManifestDigest(manifest) {
|
|
193
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return null
|
|
194
|
+
return sha256Hex(stableStringify(digestSubset(manifest, false)))
|
|
111
195
|
}
|
|
112
196
|
|
|
113
197
|
/** 旧算法(全字段,除了它自己)。只用于兼容已经落盘的 profile。 */
|
|
@@ -121,12 +205,41 @@ export function legacyManifestDigest(manifest) {
|
|
|
121
205
|
return sha256Hex(stableStringify(copy))
|
|
122
206
|
}
|
|
123
207
|
|
|
124
|
-
/**
|
|
208
|
+
/** 已落盘摘要三种都认:当前算法 + 1.3.x 算法 + 更早的全字段算法。 */
|
|
125
209
|
export function manifestDigestAccepted(stored, manifest) {
|
|
126
210
|
if (typeof stored !== 'string' || !stored) return true
|
|
127
|
-
return stored === manifestDigest(manifest)
|
|
211
|
+
return stored === manifestDigest(manifest)
|
|
212
|
+
|| stored === rawManifestDigest(manifest)
|
|
213
|
+
|| stored === legacyManifestDigest(manifest)
|
|
128
214
|
}
|
|
129
215
|
|
|
216
|
+
/**
|
|
217
|
+
* 已落盘的 profile manifest 与 catalog 现在的条目差在哪。
|
|
218
|
+
*
|
|
219
|
+
* 返回值把这个差异分成两类,这是"能不能自动修"的判据:
|
|
220
|
+
* - `fields`:摘要字段里有哪几个字面不同;
|
|
221
|
+
* - `metadataOnly`:字面不同但**身份视图相同**的字段(镜像源/标签/地址);
|
|
222
|
+
* - `identityChanged`:身份真的变了的字段(向量空间或制品内容),只能重建,不能重签。
|
|
223
|
+
*/
|
|
224
|
+
export function manifestDrift(profileManifest, entry) {
|
|
225
|
+
const fields = []
|
|
226
|
+
const metadataOnly = []
|
|
227
|
+
const identityChanged = []
|
|
228
|
+
if (!profileManifest || typeof profileManifest !== 'object') {
|
|
229
|
+
return { fields: ['manifest'], metadataOnly: [], identityChanged: ['manifest'] }
|
|
230
|
+
}
|
|
231
|
+
for (const field of DIGEST_FIELDS) {
|
|
232
|
+
if (stableStringify(profileManifest[field]) === stableStringify(entry?.[field])) continue
|
|
233
|
+
fields.push(field)
|
|
234
|
+
if (stableStringify(identityOf(field, profileManifest[field])) === stableStringify(identityOf(field, entry?.[field]))) metadataOnly.push(field)
|
|
235
|
+
else identityChanged.push(field)
|
|
236
|
+
}
|
|
237
|
+
return { fields, metadataOnly, identityChanged }
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// 元数据漂移只 warn 一次:每回合都记一遍就变成新的日志洪水。
|
|
241
|
+
let lastMetadataDriftKey = null
|
|
242
|
+
|
|
130
243
|
/** 直接复用 embedding-catalog 的指纹协议(任何改变向量空间的字段都进指纹,§14.8)。 */
|
|
131
244
|
export { profileFingerprint }
|
|
132
245
|
|
|
@@ -262,7 +375,28 @@ export function assertProfileVerified(profile) {
|
|
|
262
375
|
}
|
|
263
376
|
const digest = manifestDigest(entry)
|
|
264
377
|
if (!manifestDigestAccepted(profile.manifestDigest, entry)) {
|
|
265
|
-
|
|
378
|
+
// 摘要对不上时先分类,别急着判废:镜像元数据变化不代表向量空间变了。
|
|
379
|
+
// 只有"身份视图也变了"才是真的换了制品(files/graph/dimension/runtime 版本…),
|
|
380
|
+
// 那种情况必须重建;否则重签即可,已算好的 25 条向量一条都不用重算。
|
|
381
|
+
const drift = manifestDrift(profile.manifest, entry)
|
|
382
|
+
if (drift.identityChanged.length) {
|
|
383
|
+
throw vectorError(VECTOR_ERROR_CODES.PROFILE_MANIFEST_CHANGED, 'the manifest for ' + entry.id + ' changed after this profile was recorded', {
|
|
384
|
+
expected: digest, actual: profile.manifestDigest, changedFields: drift.identityChanged, recoverable: false, catalogId: entry.id,
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
// 逐字段比下来一处都没变,摘要却对不上:这说明存下来的摘要本身不可信(被改过、
|
|
388
|
+
// 或用的是一个我们已经不认识的算法),不是"元数据漂移"。这种情况不能放过——
|
|
389
|
+
// 放过等于承认任意摘要都行。
|
|
390
|
+
if (!drift.fields.length) {
|
|
391
|
+
throw vectorError(VECTOR_ERROR_CODES.PROFILE_MANIFEST_CHANGED, 'the manifest for ' + entry.id + ' changed after this profile was recorded', {
|
|
392
|
+
expected: digest, actual: profile.manifestDigest, changedFields: [], recoverable: false, catalogId: entry.id,
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
const driftKey = [profile.catalogId, drift.fields.join(',')].join('|')
|
|
396
|
+
if (driftKey !== lastMetadataDriftKey) {
|
|
397
|
+
lastMetadataDriftKey = driftKey
|
|
398
|
+
warn(`vector profile ${profile.catalogId}: manifest metadata moved (${drift.fields.join(', ') || 'unknown'}); accepting the recorded profile because the artifacts themselves are unchanged`)
|
|
399
|
+
}
|
|
266
400
|
}
|
|
267
401
|
// The persisted manifest and derived processing fields are execution inputs,
|
|
268
402
|
// not harmless annotations. Reject tampering even if cached hashes survived.
|
|
@@ -515,6 +649,166 @@ export function activeGeneration() {
|
|
|
515
649
|
return state?.active?.generation ?? null
|
|
516
650
|
}
|
|
517
651
|
|
|
652
|
+
// ---------------------------------------------------------------- 兼容修复:重签与重指
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* 把落盘 profile 重写成 catalog 现在的规范形态(重签 manifest 摘要)。
|
|
656
|
+
*
|
|
657
|
+
* 只在"制品身份没变"时允许:身份变了就是真换了制品,重签会把不同向量空间混进同一个
|
|
658
|
+
* 代际(比报错更坏),那种情况必须走重建。重签保留 modelDir / runtimeDir——那是"本地装
|
|
659
|
+
* 在哪",不是制品身份。写盘走 updateVectorStateSync(文件锁 + 原子写),并先留一份
|
|
660
|
+
* .bak-resign-<时间> 备份。
|
|
661
|
+
*/
|
|
662
|
+
export function resignVectorProfile({ dryRun = false } = {}) {
|
|
663
|
+
const state = vectorState()
|
|
664
|
+
const slots = ['requested', 'active'].filter(slot => state?.[slot]?.profile?.catalogId)
|
|
665
|
+
if (!slots.length) return { changed: false, reason: 'no-profile', slots: [] }
|
|
666
|
+
const plan = []
|
|
667
|
+
for (const slot of slots) {
|
|
668
|
+
const profile = state[slot].profile
|
|
669
|
+
const entry = resolveCatalogEntry(profile.catalogId)
|
|
670
|
+
if (!entry) throw vectorError(VECTOR_ERROR_CODES.PROFILE_UNKNOWN, 'the catalog no longer defines ' + profile.catalogId, { catalogId: profile.catalogId })
|
|
671
|
+
const expected = profileFingerprint(entry)
|
|
672
|
+
if (profile.fingerprint !== expected) {
|
|
673
|
+
throw vectorError(VECTOR_ERROR_CODES.PROFILE_FINGERPRINT_MISMATCH, 'profile fingerprint does not match the catalog for ' + entry.id, { expected, actual: profile.fingerprint, catalogId: entry.id })
|
|
674
|
+
}
|
|
675
|
+
plan.push({ slot, profile, entry, drift: manifestDrift(profile.manifest, entry) })
|
|
676
|
+
}
|
|
677
|
+
const blocked = plan.find(item => item.drift.identityChanged.length)
|
|
678
|
+
if (blocked) {
|
|
679
|
+
throw vectorError(VECTOR_ERROR_CODES.PROFILE_MANIFEST_CHANGED, 'the artifact identity changed; re-signing cannot fix that', {
|
|
680
|
+
changedFields: blocked.drift.identityChanged, catalogId: blocked.profile.catalogId, recoverable: false,
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
const stale = plan.filter(item => item.drift.fields.length)
|
|
684
|
+
const report = {
|
|
685
|
+
changed: stale.length > 0,
|
|
686
|
+
reason: stale.length ? 'metadata-drift' : 'already-current',
|
|
687
|
+
file: vectorActiveFile(),
|
|
688
|
+
backup: null,
|
|
689
|
+
slots: stale.map(item => ({
|
|
690
|
+
slot: item.slot,
|
|
691
|
+
catalogId: item.profile.catalogId,
|
|
692
|
+
changedFields: item.drift.fields,
|
|
693
|
+
metadataOnly: item.drift.metadataOnly,
|
|
694
|
+
previousDigest: item.profile.manifestDigest,
|
|
695
|
+
nextDigest: manifestDigest(item.entry),
|
|
696
|
+
})),
|
|
697
|
+
}
|
|
698
|
+
if (!report.changed || dryRun) return report
|
|
699
|
+
try {
|
|
700
|
+
report.backup = `${report.file}.bak-resign-${stamp().replace(/[:.]/g, '-')}`
|
|
701
|
+
fs.copyFileSync(report.file, report.backup)
|
|
702
|
+
} catch { report.backup = null }
|
|
703
|
+
updateVectorStateSync(current => {
|
|
704
|
+
const next = { ...current }
|
|
705
|
+
for (const slot of ['requested', 'active']) {
|
|
706
|
+
const wrapper = next[slot]
|
|
707
|
+
const catalogId = wrapper?.profile?.catalogId
|
|
708
|
+
if (!catalogId) continue
|
|
709
|
+
const entry = resolveCatalogEntry(catalogId)
|
|
710
|
+
if (!entry) continue
|
|
711
|
+
const rebuilt = buildProfile(entry, { modelDir: wrapper.profile.modelDir, runtimeDir: wrapper.profile.runtimeDir })
|
|
712
|
+
next[slot] = {
|
|
713
|
+
...wrapper,
|
|
714
|
+
status: wrapper.status || (slot === 'active' ? 'active' : 'requested'),
|
|
715
|
+
catalogId: rebuilt.catalogId,
|
|
716
|
+
fingerprint: rebuilt.fingerprint,
|
|
717
|
+
manifestDigest: rebuilt.manifestDigest,
|
|
718
|
+
profile: rebuilt,
|
|
719
|
+
resignedAt: stamp(),
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return next
|
|
723
|
+
})
|
|
724
|
+
return report
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function runtimeDirHasArtifacts(dir) {
|
|
728
|
+
if (typeof dir !== 'string' || !dir.trim()) return false
|
|
729
|
+
try { return fs.existsSync(path.join(dir, 'node_modules', 'onnxruntime-node', 'package.json')) } catch { return false }
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* 候选 runtime 目录。
|
|
734
|
+
*
|
|
735
|
+
* 受管运行时住在 downloads/embeddings/runtime/<key>(与模型同级,见 local-vector-service.js
|
|
736
|
+
* 的 runtimeRoot);早期版本写过 downloads/runtime,所以两处都扫,新的优先。
|
|
737
|
+
*/
|
|
738
|
+
export function runtimeDirCandidates() {
|
|
739
|
+
const roots = [path.join(downloadsDir(), 'embeddings', 'runtime'), path.join(downloadsDir(), 'runtime')]
|
|
740
|
+
const out = []
|
|
741
|
+
for (const root of roots) {
|
|
742
|
+
try {
|
|
743
|
+
const active = JSON.parse(fs.readFileSync(path.join(root, 'active.json'), 'utf8'))
|
|
744
|
+
const hinted = active?.dir || active?.runtimeDir || active?.path || active?.active?.dir || null
|
|
745
|
+
if (typeof hinted === 'string' && hinted.trim()) {
|
|
746
|
+
const abs = path.isAbsolute(hinted) ? hinted : path.join(root, hinted)
|
|
747
|
+
if (runtimeDirHasArtifacts(abs)) out.push({ dir: abs, source: 'active.json', mtimeMs: 0 })
|
|
748
|
+
}
|
|
749
|
+
} catch {}
|
|
750
|
+
}
|
|
751
|
+
const found = []
|
|
752
|
+
for (const root of roots) {
|
|
753
|
+
let entries = []
|
|
754
|
+
try { entries = fs.readdirSync(root, { withFileTypes: true }) } catch { entries = [] }
|
|
755
|
+
for (const entry of entries) {
|
|
756
|
+
if (!entry.isDirectory()) continue
|
|
757
|
+
const abs = path.join(root, entry.name)
|
|
758
|
+
if (!runtimeDirHasArtifacts(abs)) continue
|
|
759
|
+
let mtimeMs = 0
|
|
760
|
+
try { mtimeMs = fs.statSync(path.join(abs, 'node_modules', 'onnxruntime-node', 'package.json')).mtimeMs } catch {}
|
|
761
|
+
found.push({ dir: abs, source: 'scan', mtimeMs })
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
found.sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
765
|
+
for (const item of found) if (!out.some(existing => existing.dir === item.dir)) out.push(item)
|
|
766
|
+
return out
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* 把 profile 的 runtimeDir 重指到一个真正装着 onnxruntime-node 的目录。
|
|
771
|
+
*
|
|
772
|
+
* 2026-11-21 现场:profile 记的 runtimeDir 指向一个已被删掉的 UUID 目录,worker 用
|
|
773
|
+
* MODULE_NOT_FOUND 退出,而父进程把 stderr 丢了,只留一句"worker exited before it
|
|
774
|
+
* became ready"——查了两小时。重指只改"本地安装位置",不碰身份与代际。
|
|
775
|
+
*/
|
|
776
|
+
export function repointVectorRuntimeDir({ dryRun = false, dir = null } = {}) {
|
|
777
|
+
const state = vectorState()
|
|
778
|
+
const slots = ['requested', 'active'].filter(slot => state?.[slot]?.profile?.catalogId)
|
|
779
|
+
if (!slots.length) return { changed: false, reason: 'no-profile', slots: [], candidates: runtimeDirCandidates().map(item => item.dir) }
|
|
780
|
+
const current = state.active?.profile?.runtimeDir || state.requested?.profile?.runtimeDir || null
|
|
781
|
+
if (!dir) {
|
|
782
|
+
const candidates = runtimeDirCandidates()
|
|
783
|
+
if (!candidates.length) return { changed: false, reason: 'no-runtime-installed', slots: [], current, candidates: [] }
|
|
784
|
+
dir = candidates[0].dir
|
|
785
|
+
}
|
|
786
|
+
if (runtimeDirHasArtifacts(current) && path.resolve(current) === path.resolve(dir)) {
|
|
787
|
+
return { changed: false, reason: 'already-pointed', slots: [], current, next: dir, candidates: [] }
|
|
788
|
+
}
|
|
789
|
+
const report = { changed: true, reason: 'repointed', file: vectorActiveFile(), backup: null, current, next: dir, slots: [], candidates: [] }
|
|
790
|
+
if (dryRun) return report
|
|
791
|
+
try {
|
|
792
|
+
report.backup = `${report.file}.bak-runtimedir-${stamp().replace(/[:.]/g, '-')}`
|
|
793
|
+
fs.copyFileSync(report.file, report.backup)
|
|
794
|
+
} catch { report.backup = null }
|
|
795
|
+
updateVectorStateSync(current2 => {
|
|
796
|
+
const next = { ...current2 }
|
|
797
|
+
for (const slot of ['requested', 'active']) {
|
|
798
|
+
const wrapper = next[slot]
|
|
799
|
+
if (!wrapper?.profile?.catalogId) continue
|
|
800
|
+
next[slot] = {
|
|
801
|
+
...wrapper,
|
|
802
|
+
profile: { ...wrapper.profile, runtimeDir: dir },
|
|
803
|
+
repointedAt: stamp(),
|
|
804
|
+
}
|
|
805
|
+
report.slots.push(slot)
|
|
806
|
+
}
|
|
807
|
+
return next
|
|
808
|
+
})
|
|
809
|
+
return report
|
|
810
|
+
}
|
|
811
|
+
|
|
518
812
|
/**
|
|
519
813
|
* 条目级"已入向量库"戳(entry.vector)。迁移写库故意不碰索引,所以迁移写入的条目没有
|
|
520
814
|
* 戳、只有账本知道;而迁移之后的每一次向量写入(remember/import/review/update/curator)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */
|
|
2
|
-
var DshMemuGraph=(()=>{var Tt=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var _t=(d,y)=>{for(var N in y)Tt(d,N,{get:y[N],enumerable:!0})},Gt=(d,y,N,L)=>{if(y&&typeof y=="object"||typeof y=="function")for(let R of jt(y))!qt.call(d,R)&&R!==N&&Tt(d,R,{get:()=>y[R],enumerable:!(L=$t(y,R))||L.enumerable});return d};var Wt=d=>Gt(Tt({},"__esModule",{value:!0}),d);var Zt={};_t(Zt,{DEFAULT_OPTIONS:()=>Ct,createForceLayout:()=>Rt,createGraphView:()=>Qt,fitCamera:()=>Et,placeLabels:()=>Xt,zoomCamera:()=>Nt});var Pt=Math.PI*2,Ht=2.399963229728653,Jt=200,Ut=800,Vt=new Set(["x","y","vx","vy","fx","fy"]),Y=(d,y,N)=>Math.max(y,Math.min(N,d)),Ct=Object.freeze({repulsion:120,distance:100,center:0,labels:!0,motion:!0,grid:!0,clusterScope:!0}),W=Object.freeze({cell:120,range:150,repel:900,link:.9,centerForce:.012,vDecay:.6,alphaDecay:.025,alphaTarget:.02}),dt=Object.freeze({memory:"#618fcd",must:"#d97768",short:"#8a93a6",entity:"#36a582",provisional:"#b9963f",global:"#8b7bd8",missing:"#92959c"}),zt=Object.freeze({"entity-mention":"#4f6bdb",conflict:"#d9705f",supersede:"#c08a49","fact-key":"#7a8fbc","worker-quote":"#8a7cc0"}),Yt=(d,y,N)=>d.rule&&zt[d.rule]?zt[d.rule]:d.manual?N:y,wt=d=>d.missing?dt.missing:d.kind==="global"?dt.global:d.kind!=="memory"?d.status==="provisional"?dt.provisional:dt.entity:d.layer==="must_remember"?dt.must:d.layer==="short_term"?dt.short:dt.memory,Dt=d=>{let y=2166136261,N=String(d);for(let L=0;L<N.length;L++)y^=N.charCodeAt(L),y=Math.imul(y,16777619);return y>>>0},Ft=(d,y)=>`${Math.floor(d/W.cell)},${Math.floor(y/W.cell)}`;function Rt(d={}){let y=new Map,N=new Map,L=[],R=[],H=new Map,U=null,e="",f=1,T={...Ct,...d},O=null,V=!1,v=!1,z=!1,ht=()=>({repel:Y(T.repulsion,1,1e3)/120,linkDist:Y(T.distance,1,1e3)/100,center:Y(T.center,0,20)}),K=(r,l)=>Y(Math.hypot(r.x-l.x,r.y-l.y)||56,48,160),b=()=>{let r=new Map;for(let l of R)r.has(l.from)||r.set(l.from,new Set),r.has(l.to)||r.set(l.to,new Set),r.get(l.from).add(l.to),r.get(l.to).add(l.from);return r},St=()=>{let r=new Map;for(let l of L){if(r.has(l.id))continue;let x=new Set([l.id]),k=[l.id],F=[];for(let w=0;w<k.length;w++){let o=k[w],I=y.get(o);I&&F.push(I);for(let m of H.get(o)||[])x.has(m)||(x.add(m),k.push(m))}let s={ids:x,members:F};for(let w of x)r.set(w,s)}return r},Q=r=>{f=Math.max(f,r)},rt=r=>T.clusterScope&&U?U.get(r):null,it=18,yt=r=>Y(Math.sqrt(900/Math.max(900,r)),.56,1),J=()=>{let r=[],l=new Set;for(let x of L){if(l.has(x.id))continue;let k=U?.get(x.id),F=k?[...k.ids]:[x.id];for(let a of F)l.add(a);let s=new Map(F.map(a=>[a,[]]));for(let a of R)!s.has(a.from)||!s.has(a.to)||(s.get(a.from).push(a.to),s.get(a.to).push(a.from));let w=F[0],o=-1;for(let a of F){let c=y.get(a),P=(s.get(a)?.length||0)*10+(c?.kind==="memory"?0:3);(P>o||P===o&&a<w)&&(w=a,o=P)}let I=new Map([[w,null]]),m=new Map([[w,[]]]),i=new Map([[w,0]]),p=[w];for(let a=0;a<p.length;a++){let c=p[a];for(let P of s.get(c)||[])I.has(P)||(I.set(P,c),m.set(P,[]),i.set(P,i.get(c)+1),m.get(c).push(P),p.push(P))}let u=new Map;for(let a=p.length-1;a>=0;a--){let c=p[a],P=0;for(let j of m.get(c)||[])P+=u.get(j);u.set(c,P||1)}r.push({ids:F,root:w,kids:m,weight:u})}return r.sort((x,k)=>k.ids.length-x.ids.length),r},It=(r,l,x,k)=>{let F=y.get(r.root);if(!F)return;F.x=0,F.y=0;let s=[{id:r.root,x:0,y:0,dir:-Math.PI/2,span:Math.PI*2}];for(;s.length;){let w=s.pop(),o=r.kids.get(w.id);if(!o||!o.length)continue;let I=o.length>1?o.slice().sort((c,P)=>r.weight.get(P)-r.weight.get(c)):o,m=0;for(let c of I)m+=r.weight.get(c);let i=1/0;for(let c of I)i=Math.min(i,w.span*r.weight.get(c)/m);let p=l;I.length>1&&i>1e-6&&(p=Math.max(l,x/(2*Math.sin(Math.min(Math.PI,i)/2)))),p>k&&(p=k);let u=I.length===1?.62:0,a=w.dir-w.span/2;for(let c of I){let P=w.span*r.weight.get(c)/m,j=a+P/2+u,t=y.get(c);t&&(t.x=w.x+Math.cos(j)*p,t.y=w.y+Math.sin(j)*p),s.push({id:c,x:t?t.x:w.x,y:t?t.y:w.y,dir:j,span:P}),a+=P}}},et=r=>{let x=new Float64Array(36),k=r[0],F=m=>Math.min(35,Math.floor((m+Math.PI)/(Math.PI*2)*36));for(let m of k.ids){let i=y.get(m);if(!i)continue;let p=Math.hypot(i.x-(k.cx||0),i.y-(k.cy||0)),u=F(Math.atan2(i.y-(k.cy||0),i.x-(k.cx||0)));p>x[u]&&(x[u]=p)}let s=0,w=1/0;for(let m=0;m<36;m++){let i=m/36*Math.PI*2,p=Float64Array.from(x);for(let c=1;c<r.length;c++){let P=r[c],j=Math.hypot(P.ax,P.ay),t=Math.atan2(P.ay,P.ax)+i,n=P.radius;for(let h=0;h<36;h++){let S=-Math.PI+(h+.5)/36*Math.PI*2-t;for(;S>Math.PI;)S-=Math.PI*2;for(;S<-Math.PI;)S+=Math.PI*2;let E=j*Math.sin(S);if(Math.abs(E)>=n||Math.abs(S)>=Math.PI/2)continue;let ot=j*Math.cos(S)+Math.sqrt(n*n-E*E);ot>p[h]&&(p[h]=ot)}}let u=0;for(let c=0;c<36;c++)u+=p[c];u/=36;let a=0;for(let c=0;c<36;c++)a+=(p[c]-u)*(p[c]-u);a<w&&(w=a,s=i)}if(!s)return;let o=Math.cos(s),I=Math.sin(s);for(let m=1;m<r.length;m++){let i=r[m],p=i.ax,u=i.ay;i.ax=p*o-u*I,i.ay=p*I+u*o}},Mt=r=>{let l=r.slice().sort((s,w)=>w.radius-s.radius);if(!l.length)return;l[0].ax=0,l[0].ay=0;let x=l[0].radius+it,k=1,F=1;for(;k<l.length;){let s=[],w=0,o=k;for(;o<l.length;){let u=l[o],a=x+u.radius,c=(2*u.radius+it)/Math.max(1,a);if(s.length&&w+c>Math.PI*2)break;s.push({c:u,d:a,need:c}),w+=c,o++}let I=0,m=x;for(let u of s)I+=u.need,m=Math.max(m,u.d+u.c.radius);let i=-Math.PI/2+F*.9,p=0;for(let u of s){let a=(2*u.c.radius+it)/Math.max(1,u.d),c=i+(p+a/2)/Math.max(1e-6,I)*Math.PI*2;u.c.ax=Math.cos(c)*u.d,u.c.ay=Math.sin(c)*u.d,p+=a}x=m+it,k=o,F++}l.length<=12&&et(l)},ut=(r,l)=>{let x=r.filter(s=>Math.hypot(s.ax,s.ay)>1);if(!x.length)return;let k=0;for(let s of x)k=Math.max(k,Math.hypot(s.ax,s.ay)+s.radius*.5);let F=Math.PI*2/x.length;x.sort((s,w)=>Math.atan2(s.ay,s.ax)-Math.atan2(w.ay,w.ax));for(let s=0;s<x.length;s++){let w=x[s],o=w.ids.map(a=>y.get(a)).filter(Boolean);if(!o.length)continue;let I=1/0,m=-1/0;for(let a of o){let c=a.x-w.ax;c<I&&(I=c),c>m&&(m=c)}let i=Math.max(1,m-I),p=-Math.PI/2+(s+.5)*F,u=Math.min(F*.94,Math.max(1,o.length)*(l/Math.max(k,l)));for(let a of o){let c=a.x-w.ax,P=a.y-w.ay,j=(c-I)/i-.5,t=p+j*u,n=k+Y(P,-l,l)*.28;a.x=Math.cos(t)*n,a.y=Math.sin(t)*n}}},lt=()=>{if(!L.length)return;let r=yt(L.length),l=56*r,x=Math.max(22,44*r),k=l*2.8,F=J();for(let s of F){It(s,l,x,k);let w=1/0,o=-1/0,I=1/0,m=-1/0;for(let u of s.ids){let a=y.get(u);a&&(a.x<w&&(w=a.x),a.x>o&&(o=a.x),a.y<I&&(I=a.y),a.y>m&&(m=a.y))}s.cx=(w+o)/2,s.cy=(I+m)/2;let i=[];for(let u of s.ids){let a=y.get(u);a&&i.push(Math.hypot(a.x-s.cx,a.y-s.cy))}i.sort((u,a)=>u-a);let p=i.length?i[Math.min(i.length-1,Math.floor(i.length*.88))]:0;if(s.radius=p+26,s.cx||s.cy){for(let u of s.ids){let a=y.get(u);a&&(a.x-=s.cx,a.y-=s.cy)}s.cx=0,s.cy=0}}Mt(F);for(let s of F)for(let w of s.ids){let o=y.get(w);o&&(o.x+=s.ax,o.y+=s.ay)}F.length<=12&&ut(F,l);for(let s of y.values())s.vx=0,s.vy=0,s.fx=null,s.fy=null,s.locked=!1;for(let s of R){let w=s.source,o=s.target;s.baseLen=w&&o?Math.max(1,Math.hypot(w.x-o.x,w.y-o.y)):56,N.set(JSON.stringify([s.from,s.to,s.kind||""]),s.baseLen)}},xt=r=>{let l=[...new Map((r?.nodes||[]).slice(0,Jt).map(i=>[i.id,i])).values()].sort((i,p)=>String(i.id).localeCompare(String(p.id))),x=new Set(l.map(i=>i.id)),k=(r?.edges||[]).filter(i=>x.has(i.from)&&x.has(i.to)&&i.from!==i.to),F=JSON.stringify([l.map(i=>i.id),k.map(i=>[i.from,i.to]).sort()]),s=e!==F,w=L.length,o=new Map;for(let i of k)o.set(i.from,(o.get(i.from)||0)+1),o.set(i.to,(o.get(i.to)||0)+1);let I=l.filter(i=>!y.has(i.id));for(let i=0;i<I.length;i++){let p=I[i],u=k.filter(t=>t.from===p.id||t.to===p.id).map(t=>y.get(t.from===p.id?t.to:t.from)).filter(Boolean),a=i*Ht,c=u.length?32:24*Math.sqrt(i+.5),P=u.length?u.reduce((t,n)=>t+n.x,0)/u.length:0,j=u.length?u.reduce((t,n)=>t+n.y,0)/u.length:0;y.set(p.id,{id:p.id,x:P+Math.cos(a)*c,y:j+Math.sin(a)*c,vx:0,vy:0,fx:null,fy:null,locked:!1})}L=l.map(i=>{let p=y.get(i.id);for(let[u,a]of Object.entries(i))Vt.has(u)||(p[u]=a);return p.degree=o.get(i.id)||0,p.radius=4+Math.min(3,Math.log2(1+p.degree))+Y(Number(i.strength)||0,0,1)*2,p}),R=k.map(i=>{let p=y.get(i.from),u=y.get(i.to),a=JSON.stringify([i.from,i.to,i.kind||""]),c=N.get(a);return c===void 0&&(c=K(p,u),N.set(a,c)),{...i,source:p,target:u,manual:i.source!=="auto",baseLen:c}}),H=b(),s&&(U=St());let m=L.length>0&&I.length>=Math.ceil(L.length*.6)&&w<=Math.max(8,L.length*.2);s&&L.length&&(!z||m)&&(lt(),z=!0),s&&Q(e?.25:1),e=F;for(let i of y.keys())y.size>Ut&&!x.has(i)&&y.delete(i);return N.size>4e3&&N.clear(),s},Z=()=>{if(!L.length)return;f+=(W.alphaTarget-f)*W.alphaDecay,f<W.alphaTarget&&(f=W.alphaTarget);let r=ht();O&&!V&&!v&&f<.05&&(O=null);let l=O?O.members:L,x=O?O.ids:null,k=new Map;for(let o of L){let I=Ft(o.x,o.y),m=k.get(I);m||k.set(I,m=[]),m.push(o)}let F=W.range*W.range,s=W.repel*r.repel*f;for(let o of l){let I=Math.floor(o.x/W.cell),m=Math.floor(o.y/W.cell);for(let i=-1;i<=1;i++)for(let p=-1;p<=1;p++){let u=k.get(`${I+i},${m+p}`);if(u)for(let a of u){if(a===o)continue;let c=o.x-a.x,P=o.y-a.y,j=c*c+P*P;if(j>F)continue;if(j<1){let h=Dt(o.id)^Dt(a.id);c=(h&1023)/1023-.5||.25,P=(h>>>10&1023)/1023-.5||.25,j=c*c+P*P+1}let t=Math.sqrt(j),n=s/(j+60);o.vx+=c/t*n,o.vy+=P/t*n}}}let w=W.link*f;for(let o of R){if(x&&(!x.has(o.from)||!x.has(o.to)))continue;let I=o.source,m=o.target;if(!I||!m)continue;let i=m.x-I.x,p=m.y-I.y,u=Math.hypot(i,p)||.01,a=(u-o.baseLen*r.linkDist)/u*w,c=i*a,P=p*a;I.vx+=c,I.vy+=P,m.vx-=c,m.vy-=P}if(r.center>0&&l.length){let o=0,I=0;for(let i of l)o+=i.x,I+=i.y;o/=l.length,I/=l.length;let m=W.centerForce*r.center*f;for(let i of l)i.vx+=(o-i.x)*m,i.vy+=(I-i.y)*m}for(let o of l)if(o.vx=Y(o.vx,-24,24),o.vy=Y(o.vy,-24,24),o.fx!=null?(o.x=o.fx,o.vx=0):(o.vx*=W.vDecay,o.x+=o.vx),o.fy!=null?(o.y=o.fy,o.vy=0):(o.vy*=W.vDecay,o.y+=o.vy),(!Number.isFinite(o.x)||!Number.isFinite(o.y))&&(o.x=0,o.y=0,o.vx=0,o.vy=0),o.fx==null||!V&&!o.locked){let I=(Number(o.radius)||4)+(V?2:8),m=Math.floor(o.x/W.cell),i=Math.floor(o.y/W.cell);for(let p=-1;p<=1;p++)for(let u=-1;u<=1;u++){let a=k.get(`${m+p},${i+u}`);if(a)for(let c of a){if(c===o)continue;let P=o.x-c.x,j=o.y-c.y,t=P*P+j*j,n=I+(Number(c.radius)||4),h=n*n;if(t>=h)continue;let C=Math.sqrt(t);if(C<.01){let E=Dt(o.id)^Dt(c.id);P=(E&1023)/1023-.5||.25,j=(E>>>10&1023)/1023-.5||.25,C=Math.hypot(P,j)||1}let S=n-C;o.x+=P/C*S,o.y+=j/C*S}}o.vx*=.3,o.vy*=.3,o.fx!=null&&(o.fx=o.x,o.fy=o.y)}};return{get nodes(){return L},get edges(){return R},get alpha(){return f},get active(){return f>W.alphaTarget+1e-4||V},update:xt,tick:Z,settle(r=200){v=!0;try{for(let l=0;l<r;l++)Z()}finally{v=!1}f=W.alphaTarget},configure(r){let l=r?.distance!==void 0&&r.distance!==T.distance;if(T={...T,...r},l){N.clear();for(let x of R)x.baseLen=K(x.source,x.target),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen)}Q(.25)},reheat:Q,pin(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,k.locked=!0,Q(.3))},hold(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,Q(.55))},release(r){let l=y.get(r);if(l){l.fx=null,l.fy=null,l.vx=0,l.vy=0;for(let x of R)x.from!==r&&x.to!==r||(x.baseLen=Math.max(24,Math.hypot(x.source.x-x.target.x,x.source.y-x.target.y)),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen));Q(.2)}},unpin(r){let l=y.get(r);l&&(l.fx=null,l.fy=null,l.vx=0,l.vy=0,l.locked=!1,Q(.3))},unpinAll(){for(let r of y.values())r.fx=null,r.fy=null,r.vx=0,r.vy=0,r.locked=!1;Q(.35)},relayout(){lt(),N.clear();for(let r of R)r.baseLen=K(r.source,r.target),N.set(JSON.stringify([r.from,r.to,r.kind||""]),r.baseLen);O=null,V=!1,f=1},componentOf:rt,startDragScope(r){V=!0;let l=rt(r);return O=l?{ids:l.ids,members:l.members}:null,Q(.35),O},setDragging(r){V=r},clearDragScope(){O=null,V=!1},nodeById:r=>y.get(r),dispose(){y.clear(),N.clear(),L=[],R=[],U=null,H=new Map}}}function Et(d,y,N){if(!d.length)return{x:y/2,y:N/2,k:1};let L=1/0,R=-1/0,H=1/0,U=-1/0;for(let f of d){let T=Number(f.radius)||4;L=Math.min(L,f.x-T),R=Math.max(R,f.x+T),H=Math.min(H,f.y-T),U=Math.max(U,f.y+T)}let e=Y(Math.min(Math.max(32,y-100)/Math.max(120,R-L),Math.max(32,N-96)/Math.max(120,U-H)),.06,1.6);return{x:y/2-(L+R)*e/2,y:N/2-(H+U)*e/2,k:e}}function Nt(d,y,N){let L=Y(d.k*y,.06,5);return{k:L,x:N.x-(N.x-d.x)*L/d.k,y:N.y-(N.y-d.y)*L/d.k}}var Kt=(d,y)=>d.x<y.x+y.width&&d.x+d.width>y.x&&d.y<y.y+y.height&&d.y+d.height>y.y;function Xt(d,y,N,L){let R=[...y],H=[];for(let U of d){let{x:e,y:f,radius:T,textWidth:O}=U,V=[{x:e-O/2,y:f+T+5},{x:e-O/2,y:f-T-21},{x:e+T+6,y:f-8},{x:e-T-O-6,y:f-8}];if(U.priority)for(let z of[28,48,72])V.push({x:e-O/2,y:f+T+z},{x:e-O/2,y:f-T-16-z},{x:e+T+z,y:f-8},{x:e-T-O-z,y:f-8});let v=V.map(z=>({...z,width:O,height:16})).find(z=>z.x>=5&&z.y>=5&&z.x+z.width<=N-5&&z.y+z.height<=L-5&&!R.some(ht=>Kt(z,ht)));v&&(R.push({x:v.x-3,y:v.y-2,width:v.width+6,height:v.height+4}),H.push({...U,box:v}))}return H}function Qt(d,{onFocus:y=()=>{},onZoom:N=()=>{},onPaint:L=()=>{},tooltip:R,reducedMotion:H=!1,emptyLabel:U=""}={}){let e=d.getContext("2d");if(!e)throw new Error("Canvas 2D is unavailable");let f=Rt(),T=1,O=1,V=1,v={x:0,y:0,k:1},z={...Ct},ht="",K=null,b=null,St=!1,Q=!1,rt=null,it=0,yt=0,J=new Map,It=[],et=d.ownerDocument.defaultView,Mt=t=>({x:(t.x-v.x)/v.k,y:(t.y-v.y)/v.k}),ut=t=>Y((Number(t.radius)||4)*Math.sqrt(v.k),2.5,22),lt=t=>{let n=d.getBoundingClientRect();return{x:(t.clientX-n.left)*T/n.width,y:(t.clientY-n.top)*O/n.height}},xt=(t,n)=>{let h=f.nodes;if(!h.length)return null;let C=Mt(t),S=Y(Math.ceil(40/Math.max(v.k,.06)/W.cell),1,8),E=Math.floor(C.x/W.cell),ot=Math.floor(C.y/W.cell),$=new Map;for(let tt of h){let g=Ft(tt.x,tt.y),D=$.get(g);D||$.set(g,D=[]),D.push(tt)}let X=tt=>Math.max(6,ut(tt)+4),nt=null,at=1/0,st=1/0;for(let tt=-S;tt<=S;tt++)for(let g=-S;g<=S;g++){let D=$.get(`${E+tt},${ot+g}`);if(D)for(let M of D){let A=M.x*v.k+v.x,_=M.y*v.k+v.y,B=Math.hypot(A-t.x,_-t.y);M===n&&(st=B),B<=X(M)&&B<at&&(nt=M,at=B)}}return n&&st<=X(n)&&(!nt||at>st-2)?n:nt},Z=()=>{R&&(R.hidden=!0)},r=(t,n)=>{K!==t&&(K=t,s()),d.style.cursor=b?"grabbing":t?"pointer":"grab",R&&(R.hidden=!t||!!b,!(!t||b)&&(R.textContent=String(t.title||t.id),R.style.left=`${Y(n.x+14,6,Math.max(6,T-Math.min(260,T-12)))}px`,R.style.top=`${(d.offsetTop||0)+Y(n.y+16,6,O-60)}px`))},l=t=>{if(t?.snapshot){for(let n of t.snapshot){let h=f.nodeById(n.id);h&&(h.fx=n.fx,h.fy=n.fy,h.locked=n.locked===!0,h.x=n.x,h.y=n.y,h.vx=0,h.vy=0)}f.clearDragScope()}},x=t=>{let n=34*v.k;if(n<12)return;let h=(v.x%n+n)%n,C=(v.y%n+n)%n;e.fillStyle=e.strokeStyle,e.globalAlpha=t,e.beginPath();for(let S=h;S<T;S+=n)for(let E=C;E<O;E+=n)e.rect(S,E,1.2,1.2);e.fill()},k=()=>{e.setTransform(V,0,0,V,0,0),e.clearRect(0,0,T,O);let t=et.getComputedStyle(d),n=t.color||"#202020",h=t.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",C=t.getPropertyValue("--dsw-alias-brand-primary").trim()||"#3b5bdb",S=K?.id||ht,E=new Set(S?[S]:[]);for(let g of f.edges)g.from===S&&E.add(g.to),g.to===S&&E.add(g.from);e.strokeStyle=n;let ot=z.motion&&!H&&f.active?.06+.025*Math.sin(Date.now()/900):.07;z.grid!==!1&&x(ot);let $=v.k,X=v.x,nt=v.y,at=new Map;for(let g of f.edges){let D={x:g.source.x*$+X,y:g.source.y*$+nt},M={x:g.target.x*$+X,y:g.target.y*$+nt};if(D.x<-40&&M.x<-40||D.x>T+40&&M.x>T+40||D.y<-40&&M.y<-40||D.y>O+40&&M.y>O+40)continue;let A=Yt(g,n,C),_=g.source.kind!=="memory"&&g.target.kind!=="memory",B=`${A}|${g.manual?"d":"s"}|${_?"k":"n"}`,q=at.get(B);q||at.set(B,q={color:A,manual:g.manual,skeleton:_,list:[]}),q.list.push({edge:g,a:D,b:M})}e.lineWidth=.8;for(let g of at.values()){e.strokeStyle=g.color,e.globalAlpha=S?.055:g.skeleton?.1:g.manual?.24:.16,e.setLineDash(g.manual?[5,4]:[]),e.beginPath();for(let D of g.list)e.moveTo(D.a.x,D.a.y),e.lineTo(D.b.x,D.b.y);if(e.stroke(),e.setLineDash([]),g.manual&&v.k>=.3){e.fillStyle=g.color,e.globalAlpha=S?.22:.4;for(let D of g.list){if(D.edge.rule==="entity-mention"||D.edge.rule==="conflict")continue;let M=D.b.x-D.a.x,A=D.b.y-D.a.y,_=Math.hypot(M,A);if(_<=22)continue;let B=M/_,q=A/_,gt=ut(D.edge.target)+3,pt=D.b.x-B*gt,mt=D.b.y-q*gt;e.beginPath(),e.moveTo(pt,mt),e.lineTo(pt-B*7-q*3.4,mt-q*7+B*3.4),e.lineTo(pt-B*7+q*3.4,mt-q*7-B*3.4),e.closePath(),e.fill()}}}if(S){e.globalAlpha=.6,e.lineWidth=1.5,e.strokeStyle=C,e.beginPath();for(let g of f.edges)g.from!==S&&g.to!==S||(e.moveTo(g.source.x*$+X,g.source.y*$+nt),e.lineTo(g.target.x*$+X,g.target.y*$+nt));e.stroke()}e.globalAlpha=1,e.strokeStyle=n;let st=[];for(let g of f.nodes){let D=g.x*$+X,M=g.y*$+nt;D>=-120&&D<=T+120&&M>=-120&&M<=O+120&&st.push({node:g,x:D,y:M,r:ut(g)})}let tt=f.nodes.length>2400&&v.k<.3;if(tt){let g=new Map;for(let D of f.nodes){let M=D.x*$+X,A=D.y*$+nt;if(M<0||M>T||A<0||A>O)continue;let _=wt(D),B=g.get(_);B||g.set(_,B=[]),B.push(M,A)}e.globalAlpha=1;for(let[D,M]of g){e.fillStyle=D,e.beginPath();for(let A=0;A<M.length;A+=2)e.rect(M[A]-1,M[A+1]-1,2,2);e.fill()}}else{let g=new Map;for(let M of st){let A=!!S&&!E.has(M.node.id),_=wt(M.node)+(A?"|d":"|n"),B=g.get(_);B||g.set(_,B=[]),B.push(M)}for(let[M,A]of g){let[_,B]=M.split("|");e.globalAlpha=B==="d"?.22:1,e.fillStyle=_,e.beginPath();for(let q of A)e.moveTo(q.x+q.r,q.y),e.arc(q.x,q.y,q.r,0,Pt);e.fill()}e.globalAlpha=1;let D=String(z.query||"").trim().toLowerCase();for(let M of st){if(M.node.kind==="memory"||M.node.missing)continue;let A=M.r*1.75,_=Math.min(5,A/3),B=M.x-A/2,q=M.y-A/2;e.fillStyle=wt(M.node),e.beginPath(),e.moveTo(B+_,q),e.arcTo(B+A,q,B+A,q+A,_),e.arcTo(B+A,q+A,B,q+A,_),e.arcTo(B,q+A,B,q,_),e.arcTo(B,q,B+A,q,_),e.closePath(),e.fill()}for(let M of st){let A=M.node;A.status==="provisional"&&(e.strokeStyle=wt(A),e.lineWidth=1.2,e.setLineDash([3,3]),e.beginPath(),e.ellipse(M.x,M.y,M.r+5,M.r+5,0,0,Pt),e.stroke(),e.setLineDash([])),A.locked&&(e.fillStyle=h,e.globalAlpha=.95,e.fillRect(M.x-1.5,M.y-1.5,3,3),e.globalAlpha=1),(A.id===S||A.id===K?.id)&&(e.strokeStyle=A.id===S?C:wt(A),e.lineWidth=1.5,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke()),D&&String(A.title||A.id).toLowerCase().includes(D)&&(e.strokeStyle=C,e.lineWidth=2,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke())}}if(e.globalAlpha=1,e.strokeStyle=n,z.labels&&!tt){e.font='11.5px -apple-system,"PingFang SC","Microsoft YaHei",sans-serif';let g=st.filter(G=>G.x>-60&&G.x<T+60&&G.y>-60&&G.y<O+60),D=(v.k>=.55||st.length<34)&&g.length<=260,M=g.length>260?9999:3,A=Y((v.k-.3)/.35,0,1),_=b?.type==="pan"&&b.moved,gt=(b?.type==="node"&&b.moved||_)&&f.nodes.length>400?g.filter(G=>G.node.id===S):D?g:g.filter(G=>G.node.id===S||G.node.degree>=M),pt=gt.length>260?gt.slice(0,260):gt;pt.sort((G,bt)=>+(bt.node.id===S)-+(G.node.id===S)||bt.node.degree-G.node.degree);let mt=[];e.textAlign="center",e.textBaseline="top";for(let G of pt){if(S&&!E.has(G.node.id))continue;let bt=G.node.id===S;if(!bt&&(!D&&G.node.degree<M||A<.02))continue;let At=String(G.node.title||G.node.id),Lt=e.measureText(At).width,Ot=ft=>({l:G.x-Lt/2-3,t:ft-1,r:G.x+Lt/2+3,b:ft+14}),Bt=ft=>mt.some(vt=>ft.l<vt.r&&ft.r>vt.l&&ft.t<vt.b&&ft.b>vt.t),kt=G.y+G.r+4,ct=Ot(kt);Bt(ct)&&(kt+=16,ct=Ot(kt),Bt(ct))||ct.l<2||ct.r>T-2||ct.b>O-2||(mt.push(ct),e.globalAlpha=bt?1:.78*Math.max(.35,A),e.lineWidth=3.5,e.strokeStyle=h,e.lineJoin="round",e.strokeText(At,G.x,kt),e.fillStyle=n,e.fillText(At,G.x,kt))}e.globalAlpha=1}else if(z.labels&&tt&&S){let g=f.nodes.find(D=>D.id===S);g&&(e.font="12px system-ui, sans-serif",e.textAlign="center",e.textBaseline="top",e.fillStyle=n,e.fillText(String(g.title||g.id),g.x*$+X,g.y*$+nt+10))}!f.nodes.length&&U&&(e.font="13px system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n,e.globalAlpha=.55,e.fillText(U,T/2,O/2),e.globalAlpha=1),L()},F=t=>{if(rt=null,Q)return;let n=z.motion&&!H&&f.active;if(n){yt+=it?Math.min(64,t-it):17;let h=0;for(;yt>=1e3/60&&h<4;yt-=1e3/60,h++)f.tick();it=t}else it=0,yt=0;k(),n&&s()};function s(){!Q&&rt===null&&(rt=et.requestAnimationFrame(F))}let w=()=>{N(v.k),s()},o=()=>{v=Et(f.nodes,T,O),Z(),w()},I=(t,n={x:T/2,y:O/2})=>{v=Nt(v,t,n),Z(),w()},m=()=>{let t=d.getBoundingClientRect();if(!t.width||!t.height)return;let n=t.width,h=t.height;v.x+=(n-T)/2,v.y+=(h-O)/2,T=n,O=h,V=Math.min(2,et.devicePixelRatio||1),d.width=Math.round(T*V),d.height=Math.round(O*V),s()},i=()=>{l(b);let[t,n]=[...J.values()];b={type:"pinch",distance:Math.max(1,Math.hypot(n.x-t.x,n.y-t.y)),camera:{...v},center:{x:(t.x+n.x)/2,y:(t.y+n.y)/2},moved:!0}},p=t=>{if(t.button!==0&&t.pointerType!=="touch")return;t.preventDefault(),d.focus({preventScroll:!0});let n=lt(t);if(J.set(t.pointerId,n),d.setPointerCapture?.(t.pointerId),J.size>=2){i(),Z();return}let h=xt(n),C=Mt(n),S=h?f.componentOf(h.id):null,E=h&&t.shiftKey&&S?"rigid":"node",ot=E==="rigid"?S.members:h?[h]:[];if(b={type:h?"node":"pan",node:h,mode:E,members:ot,start:n,camera:{...v},moved:!1,offset:h?{x:h.x-C.x,y:h.y-C.y}:null,snapshot:ot.map($=>({id:$.id,x:$.x,y:$.y,fx:$.fx,fy:$.fy,locked:$.locked}))},h){for(let $ of ot)f.hold($.id,$.x,$.y);f.startDragScope(h.id),f.setDragging(!0)}Z(),d.style.cursor="grabbing"},u=t=>{let n=lt(t);if(!J.has(t.pointerId)||!b){r(xt(n,K),n);return}if(J.set(t.pointerId,n),b.type==="pinch"){if(J.size<2)return;let[h,C]=[...J.values()],S={x:(h.x+C.x)/2,y:(h.y+C.y)/2};v=Nt(b.camera,Math.hypot(C.x-h.x,C.y-h.y)/b.distance,b.center),v.x+=S.x-b.center.x,v.y+=S.y-b.center.y,w()}else{if(b.moved||(b.moved=Math.hypot(n.x-b.start.x,n.y-b.start.y)>5),!b.moved)return;if(b.node){let h=Mt(n),C=b.node;if(b.mode==="rigid"){let S=h.x+b.offset.x,E=h.y+b.offset.y,ot=S-C.fx,$=E-C.fy;for(let X of b.members)f.hold(X.id,X.fx+ot,X.fy+$)}else f.hold(C.id,h.x+b.offset.x,h.y+b.offset.y);f.settle(2)}else v.x=b.camera.x+n.x-b.start.x,v.y=b.camera.y+n.y-b.start.y;s()}},a=t=>{if(!J.has(t.pointerId))return;let n=t.type!=="pointerup",h=b?.node,C=!n&&!b?.moved&&b?.type!=="pinch"&&(t.detail??1)<2;if(C||n)l(b);else if(h){for(let S of b.snapshot){let E=f.nodeById(S.id);E&&(S.locked||S.fx!=null?(E.fx=E.x,E.fy=E.y,E.locked=!0,E.vx=0,E.vy=0):f.release(S.id))}f.setDragging(!1),H||!z.motion?(f.settle(120),f.clearDragScope()):f.reheat(.3)}J.delete(t.pointerId),b=null,J.size&&(b={type:"pan",start:[...J.values()][0],camera:{...v},moved:!0}),d.hasPointerCapture?.(t.pointerId)&&d.releasePointerCapture(t.pointerId),C&&y(h?.id||""),K=null,d.style.cursor="grab",Z(),s()},c=(t,n,h,C)=>{t.addEventListener(n,h,C),It.push(()=>t.removeEventListener(n,h,C))};c(d,"pointerdown",p),c(d,"pointermove",u);for(let t of["pointerup","pointercancel","lostpointercapture"])c(d,t,a);c(d,"pointerleave",()=>{b||(K=null,Z(),s())}),c(d,"contextmenu",t=>{t.preventDefault();let n=xt(lt(t));if(!n)return;let h=f.nodeById(n.id);h&&(h.fx!=null?f.unpin(n.id):f.pin(n.id,h.x,h.y),f.setDragging(!1),(H||!z.motion)&&f.settle(20),s())}),c(d,"dblclick",t=>{y(xt(lt(t))?.id||"")}),c(d,"wheel",t=>{t.preventDefault(),I(Math.exp(-Y(t.deltaY,-160,160)*.0025),lt(t))},{passive:!1}),c(d,"keydown",t=>{if(t.key==="+"||t.key==="=")I(1.25);else if(t.key==="-")I(.8);else if(t.key==="0"||t.key==="Home")o();else if(t.key==="Escape")l(b),b=null,J.clear(),y(""),Z(),s();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)){let n=t.shiftKey?90:30;v.x+=t.key==="ArrowLeft"?n:t.key==="ArrowRight"?-n:0,v.y+=t.key==="ArrowUp"?n:t.key==="ArrowDown"?-n:0,s()}else return;t.preventDefault()}),c(et,"blur",()=>{l(b),b=null,J.clear(),K=null,Z(),s()});let P=et.ResizeObserver?new et.ResizeObserver(m):null;P?.observe(d),c(et,"resize",m);let j=et.MutationObserver?new et.MutationObserver(s):null;return j?.observe(d.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),d.ownerDocument.body&&j?.observe(d.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),m(),{update(t,n=""){b?.node&&!t.nodes.some(C=>C.id===b.node.id)&&(l(b),b=null,J.clear());let h=f.update(t);ht=n,K&&!f.nodes.includes(K)&&(K=null,Z()),!St&&f.nodes.length?(f.settle(220),St=!0,o()):h&&(H||!z.motion)&&f.settle(180),s()},configure(t){let n=["repulsion","distance","center"].some(h=>t[h]!==void 0&&t[h]!==z[h]);z={...z,...t},n&&(f.configure(t),(H||!z.motion)&&f.settle(160)),s()},fit:o,zoom:I,isPinned(t){return f.nodeById(t)?.locked===!0},pinnedCount(){return f.nodes.reduce((t,n)=>t+(n.locked?1:0),0)},snapshot(){return f.nodes.map(t=>({id:t.id,x:t.x*v.k+v.x,y:t.y*v.k+v.y,r:ut(t),pinned:t.locked===!0,degree:t.degree||0}))},unpinAll(){f.unpinAll(),f.clearDragScope(),(H||!z.motion)&&f.settle(120),s()},relayout(){l(b),b=null,J.clear(),f.relayout(),(H||!z.motion)&&f.settle(220),s()},dispose(){Q=!0,l(b),b=null,J.clear(),rt!==null&&et.cancelAnimationFrame(rt);for(let t of It)t();P?.disconnect(),j?.disconnect(),f.dispose(),Z()}}}return Wt(Zt);})();
|
|
2
|
+
var DshMemuGraph=(()=>{var Tt=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var Gt=(d,y)=>{for(var N in y)Tt(d,N,{get:y[N],enumerable:!0})},_t=(d,y,N,L)=>{if(y&&typeof y=="object"||typeof y=="function")for(let R of jt(y))!qt.call(d,R)&&R!==N&&Tt(d,R,{get:()=>y[R],enumerable:!(L=$t(y,R))||L.enumerable});return d};var Wt=d=>_t(Tt({},"__esModule",{value:!0}),d);var Qt={};Gt(Qt,{DEFAULT_OPTIONS:()=>Ct,createForceLayout:()=>Rt,createGraphView:()=>Xt,fitCamera:()=>Et,placeLabels:()=>Kt,zoomCamera:()=>Nt});var Pt=Math.PI*2,Ht=2.399963229728653,Jt=800,Ut=new Set(["x","y","vx","vy","fx","fy"]),Y=(d,y,N)=>Math.max(y,Math.min(N,d)),Ct=Object.freeze({repulsion:120,distance:100,center:0,labels:!0,motion:!0,grid:!0,clusterScope:!0}),W=Object.freeze({cell:120,range:150,repel:900,link:.9,centerForce:.012,vDecay:.6,alphaDecay:.025,alphaTarget:.02}),dt=Object.freeze({memory:"#618fcd",must:"#d97768",short:"#8a93a6",entity:"#36a582",provisional:"#b9963f",global:"#8b7bd8",missing:"#92959c"}),zt=Object.freeze({"entity-mention":"#4f6bdb",conflict:"#d9705f",supersede:"#c08a49","fact-key":"#7a8fbc","worker-quote":"#8a7cc0"}),Vt=(d,y,N)=>d.rule&&zt[d.rule]?zt[d.rule]:d.manual?N:y,wt=d=>d.missing?dt.missing:d.kind==="global"?dt.global:d.kind!=="memory"?d.status==="provisional"?dt.provisional:dt.entity:d.layer==="must_remember"?dt.must:d.layer==="short_term"?dt.short:dt.memory,Dt=d=>{let y=2166136261,N=String(d);for(let L=0;L<N.length;L++)y^=N.charCodeAt(L),y=Math.imul(y,16777619);return y>>>0},Ft=(d,y)=>`${Math.floor(d/W.cell)},${Math.floor(y/W.cell)}`;function Rt(d={}){let y=new Map,N=new Map,L=[],R=[],H=new Map,U=null,e="",f=1,T={...Ct,...d},O=null,V=!1,v=!1,z=!1,ht=()=>({repel:Y(T.repulsion,1,1e3)/120,linkDist:Y(T.distance,1,1e3)/100,center:Y(T.center,0,20)}),K=(r,l)=>Y(Math.hypot(r.x-l.x,r.y-l.y)||56,48,160),b=()=>{let r=new Map;for(let l of R)r.has(l.from)||r.set(l.from,new Set),r.has(l.to)||r.set(l.to,new Set),r.get(l.from).add(l.to),r.get(l.to).add(l.from);return r},St=()=>{let r=new Map;for(let l of L){if(r.has(l.id))continue;let x=new Set([l.id]),k=[l.id],F=[];for(let w=0;w<k.length;w++){let o=k[w],I=y.get(o);I&&F.push(I);for(let m of H.get(o)||[])x.has(m)||(x.add(m),k.push(m))}let s={ids:x,members:F};for(let w of x)r.set(w,s)}return r},Q=r=>{f=Math.max(f,r)},rt=r=>T.clusterScope&&U?U.get(r):null,it=18,yt=r=>Y(Math.sqrt(900/Math.max(900,r)),.56,1),J=()=>{let r=[],l=new Set;for(let x of L){if(l.has(x.id))continue;let k=U?.get(x.id),F=k?[...k.ids]:[x.id];for(let a of F)l.add(a);let s=new Map(F.map(a=>[a,[]]));for(let a of R)!s.has(a.from)||!s.has(a.to)||(s.get(a.from).push(a.to),s.get(a.to).push(a.from));let w=F[0],o=-1;for(let a of F){let c=y.get(a),P=(s.get(a)?.length||0)*10+(c?.kind==="memory"?0:3);(P>o||P===o&&a<w)&&(w=a,o=P)}let I=new Map([[w,null]]),m=new Map([[w,[]]]),i=new Map([[w,0]]),p=[w];for(let a=0;a<p.length;a++){let c=p[a];for(let P of s.get(c)||[])I.has(P)||(I.set(P,c),m.set(P,[]),i.set(P,i.get(c)+1),m.get(c).push(P),p.push(P))}let u=new Map;for(let a=p.length-1;a>=0;a--){let c=p[a],P=0;for(let j of m.get(c)||[])P+=u.get(j);u.set(c,P||1)}r.push({ids:F,root:w,kids:m,weight:u})}return r.sort((x,k)=>k.ids.length-x.ids.length),r},It=(r,l,x,k)=>{let F=y.get(r.root);if(!F)return;F.x=0,F.y=0;let s=[{id:r.root,x:0,y:0,dir:-Math.PI/2,span:Math.PI*2}];for(;s.length;){let w=s.pop(),o=r.kids.get(w.id);if(!o||!o.length)continue;let I=o.length>1?o.slice().sort((c,P)=>r.weight.get(P)-r.weight.get(c)):o,m=0;for(let c of I)m+=r.weight.get(c);let i=1/0;for(let c of I)i=Math.min(i,w.span*r.weight.get(c)/m);let p=l;I.length>1&&i>1e-6&&(p=Math.max(l,x/(2*Math.sin(Math.min(Math.PI,i)/2)))),p>k&&(p=k);let u=I.length===1?.62:0,a=w.dir-w.span/2;for(let c of I){let P=w.span*r.weight.get(c)/m,j=a+P/2+u,t=y.get(c);t&&(t.x=w.x+Math.cos(j)*p,t.y=w.y+Math.sin(j)*p),s.push({id:c,x:t?t.x:w.x,y:t?t.y:w.y,dir:j,span:P}),a+=P}}},et=r=>{let x=new Float64Array(36),k=r[0],F=m=>Math.min(35,Math.floor((m+Math.PI)/(Math.PI*2)*36));for(let m of k.ids){let i=y.get(m);if(!i)continue;let p=Math.hypot(i.x-(k.cx||0),i.y-(k.cy||0)),u=F(Math.atan2(i.y-(k.cy||0),i.x-(k.cx||0)));p>x[u]&&(x[u]=p)}let s=0,w=1/0;for(let m=0;m<36;m++){let i=m/36*Math.PI*2,p=Float64Array.from(x);for(let c=1;c<r.length;c++){let P=r[c],j=Math.hypot(P.ax,P.ay),t=Math.atan2(P.ay,P.ax)+i,n=P.radius;for(let h=0;h<36;h++){let S=-Math.PI+(h+.5)/36*Math.PI*2-t;for(;S>Math.PI;)S-=Math.PI*2;for(;S<-Math.PI;)S+=Math.PI*2;let E=j*Math.sin(S);if(Math.abs(E)>=n||Math.abs(S)>=Math.PI/2)continue;let ot=j*Math.cos(S)+Math.sqrt(n*n-E*E);ot>p[h]&&(p[h]=ot)}}let u=0;for(let c=0;c<36;c++)u+=p[c];u/=36;let a=0;for(let c=0;c<36;c++)a+=(p[c]-u)*(p[c]-u);a<w&&(w=a,s=i)}if(!s)return;let o=Math.cos(s),I=Math.sin(s);for(let m=1;m<r.length;m++){let i=r[m],p=i.ax,u=i.ay;i.ax=p*o-u*I,i.ay=p*I+u*o}},Mt=r=>{let l=r.slice().sort((s,w)=>w.radius-s.radius);if(!l.length)return;l[0].ax=0,l[0].ay=0;let x=l[0].radius+it,k=1,F=1;for(;k<l.length;){let s=[],w=0,o=k;for(;o<l.length;){let u=l[o],a=x+u.radius,c=(2*u.radius+it)/Math.max(1,a);if(s.length&&w+c>Math.PI*2)break;s.push({c:u,d:a,need:c}),w+=c,o++}let I=0,m=x;for(let u of s)I+=u.need,m=Math.max(m,u.d+u.c.radius);let i=-Math.PI/2+F*.9,p=0;for(let u of s){let a=(2*u.c.radius+it)/Math.max(1,u.d),c=i+(p+a/2)/Math.max(1e-6,I)*Math.PI*2;u.c.ax=Math.cos(c)*u.d,u.c.ay=Math.sin(c)*u.d,p+=a}x=m+it,k=o,F++}l.length<=12&&et(l)},ut=(r,l)=>{let x=r.filter(s=>Math.hypot(s.ax,s.ay)>1);if(!x.length)return;let k=0;for(let s of x)k=Math.max(k,Math.hypot(s.ax,s.ay)+s.radius*.5);let F=Math.PI*2/x.length;x.sort((s,w)=>Math.atan2(s.ay,s.ax)-Math.atan2(w.ay,w.ax));for(let s=0;s<x.length;s++){let w=x[s],o=w.ids.map(a=>y.get(a)).filter(Boolean);if(!o.length)continue;let I=1/0,m=-1/0;for(let a of o){let c=a.x-w.ax;c<I&&(I=c),c>m&&(m=c)}let i=Math.max(1,m-I),p=-Math.PI/2+(s+.5)*F,u=Math.min(F*.94,Math.max(1,o.length)*(l/Math.max(k,l)));for(let a of o){let c=a.x-w.ax,P=a.y-w.ay,j=(c-I)/i-.5,t=p+j*u,n=k+Y(P,-l,l)*.28;a.x=Math.cos(t)*n,a.y=Math.sin(t)*n}}},lt=()=>{if(!L.length)return;let r=yt(L.length),l=56*r,x=Math.max(22,44*r),k=l*2.8,F=J();for(let s of F){It(s,l,x,k);let w=1/0,o=-1/0,I=1/0,m=-1/0;for(let u of s.ids){let a=y.get(u);a&&(a.x<w&&(w=a.x),a.x>o&&(o=a.x),a.y<I&&(I=a.y),a.y>m&&(m=a.y))}s.cx=(w+o)/2,s.cy=(I+m)/2;let i=[];for(let u of s.ids){let a=y.get(u);a&&i.push(Math.hypot(a.x-s.cx,a.y-s.cy))}i.sort((u,a)=>u-a);let p=i.length?i[Math.min(i.length-1,Math.floor(i.length*.88))]:0;if(s.radius=p+26,s.cx||s.cy){for(let u of s.ids){let a=y.get(u);a&&(a.x-=s.cx,a.y-=s.cy)}s.cx=0,s.cy=0}}Mt(F);for(let s of F)for(let w of s.ids){let o=y.get(w);o&&(o.x+=s.ax,o.y+=s.ay)}F.length<=12&&ut(F,l);for(let s of y.values())s.vx=0,s.vy=0,s.fx=null,s.fy=null,s.locked=!1;for(let s of R){let w=s.source,o=s.target;s.baseLen=w&&o?Math.max(1,Math.hypot(w.x-o.x,w.y-o.y)):56,N.set(JSON.stringify([s.from,s.to,s.kind||""]),s.baseLen)}},xt=r=>{let l=[...new Map((r?.nodes||[]).map(i=>[i.id,i])).values()].sort((i,p)=>String(i.id).localeCompare(String(p.id))),x=new Set(l.map(i=>i.id)),k=(r?.edges||[]).filter(i=>x.has(i.from)&&x.has(i.to)&&i.from!==i.to),F=JSON.stringify([l.map(i=>i.id),k.map(i=>[i.from,i.to]).sort()]),s=e!==F,w=L.length,o=new Map;for(let i of k)o.set(i.from,(o.get(i.from)||0)+1),o.set(i.to,(o.get(i.to)||0)+1);let I=l.filter(i=>!y.has(i.id));for(let i=0;i<I.length;i++){let p=I[i],u=k.filter(t=>t.from===p.id||t.to===p.id).map(t=>y.get(t.from===p.id?t.to:t.from)).filter(Boolean),a=i*Ht,c=u.length?32:24*Math.sqrt(i+.5),P=u.length?u.reduce((t,n)=>t+n.x,0)/u.length:0,j=u.length?u.reduce((t,n)=>t+n.y,0)/u.length:0;y.set(p.id,{id:p.id,x:P+Math.cos(a)*c,y:j+Math.sin(a)*c,vx:0,vy:0,fx:null,fy:null,locked:!1})}L=l.map(i=>{let p=y.get(i.id);for(let[u,a]of Object.entries(i))Ut.has(u)||(p[u]=a);return p.degree=o.get(i.id)||0,p.radius=4+Math.min(3,Math.log2(1+p.degree))+Y(Number(i.strength)||0,0,1)*2,p}),R=k.map(i=>{let p=y.get(i.from),u=y.get(i.to),a=JSON.stringify([i.from,i.to,i.kind||""]),c=N.get(a);return c===void 0&&(c=K(p,u),N.set(a,c)),{...i,source:p,target:u,manual:i.source!=="auto",baseLen:c}}),H=b(),s&&(U=St());let m=L.length>0&&I.length>=Math.ceil(L.length*.6)&&w<=Math.max(8,L.length*.2);s&&L.length&&(!z||m)&&(lt(),z=!0),s&&Q(e?.25:1),e=F;for(let i of y.keys())y.size>Jt&&!x.has(i)&&y.delete(i);return N.size>4e3&&N.clear(),s},Z=()=>{if(!L.length)return;f+=(W.alphaTarget-f)*W.alphaDecay,f<W.alphaTarget&&(f=W.alphaTarget);let r=ht();O&&!V&&!v&&f<.05&&(O=null);let l=O?O.members:L,x=O?O.ids:null,k=new Map;for(let o of L){let I=Ft(o.x,o.y),m=k.get(I);m||k.set(I,m=[]),m.push(o)}let F=W.range*W.range,s=W.repel*r.repel*f;for(let o of l){let I=Math.floor(o.x/W.cell),m=Math.floor(o.y/W.cell);for(let i=-1;i<=1;i++)for(let p=-1;p<=1;p++){let u=k.get(`${I+i},${m+p}`);if(u)for(let a of u){if(a===o)continue;let c=o.x-a.x,P=o.y-a.y,j=c*c+P*P;if(j>F)continue;if(j<1){let h=Dt(o.id)^Dt(a.id);c=(h&1023)/1023-.5||.25,P=(h>>>10&1023)/1023-.5||.25,j=c*c+P*P+1}let t=Math.sqrt(j),n=s/(j+60);o.vx+=c/t*n,o.vy+=P/t*n}}}let w=W.link*f;for(let o of R){if(x&&(!x.has(o.from)||!x.has(o.to)))continue;let I=o.source,m=o.target;if(!I||!m)continue;let i=m.x-I.x,p=m.y-I.y,u=Math.hypot(i,p)||.01,a=(u-o.baseLen*r.linkDist)/u*w,c=i*a,P=p*a;I.vx+=c,I.vy+=P,m.vx-=c,m.vy-=P}if(r.center>0&&l.length){let o=0,I=0;for(let i of l)o+=i.x,I+=i.y;o/=l.length,I/=l.length;let m=W.centerForce*r.center*f;for(let i of l)i.vx+=(o-i.x)*m,i.vy+=(I-i.y)*m}for(let o of l)if(o.vx=Y(o.vx,-24,24),o.vy=Y(o.vy,-24,24),o.fx!=null?(o.x=o.fx,o.vx=0):(o.vx*=W.vDecay,o.x+=o.vx),o.fy!=null?(o.y=o.fy,o.vy=0):(o.vy*=W.vDecay,o.y+=o.vy),(!Number.isFinite(o.x)||!Number.isFinite(o.y))&&(o.x=0,o.y=0,o.vx=0,o.vy=0),o.fx==null||!V&&!o.locked){let I=(Number(o.radius)||4)+(V?2:8),m=Math.floor(o.x/W.cell),i=Math.floor(o.y/W.cell);for(let p=-1;p<=1;p++)for(let u=-1;u<=1;u++){let a=k.get(`${m+p},${i+u}`);if(a)for(let c of a){if(c===o)continue;let P=o.x-c.x,j=o.y-c.y,t=P*P+j*j,n=I+(Number(c.radius)||4),h=n*n;if(t>=h)continue;let C=Math.sqrt(t);if(C<.01){let E=Dt(o.id)^Dt(c.id);P=(E&1023)/1023-.5||.25,j=(E>>>10&1023)/1023-.5||.25,C=Math.hypot(P,j)||1}let S=n-C;o.x+=P/C*S,o.y+=j/C*S}}o.vx*=.3,o.vy*=.3,o.fx!=null&&(o.fx=o.x,o.fy=o.y)}};return{get nodes(){return L},get edges(){return R},get alpha(){return f},get active(){return f>W.alphaTarget+1e-4||V},update:xt,tick:Z,settle(r=200){v=!0;try{for(let l=0;l<r;l++)Z()}finally{v=!1}f=W.alphaTarget},configure(r){let l=r?.distance!==void 0&&r.distance!==T.distance;if(T={...T,...r},l){N.clear();for(let x of R)x.baseLen=K(x.source,x.target),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen)}Q(.25)},reheat:Q,pin(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,k.locked=!0,Q(.3))},hold(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,Q(.55))},release(r){let l=y.get(r);if(l){l.fx=null,l.fy=null,l.vx=0,l.vy=0;for(let x of R)x.from!==r&&x.to!==r||(x.baseLen=Math.max(24,Math.hypot(x.source.x-x.target.x,x.source.y-x.target.y)),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen));Q(.2)}},unpin(r){let l=y.get(r);l&&(l.fx=null,l.fy=null,l.vx=0,l.vy=0,l.locked=!1,Q(.3))},unpinAll(){for(let r of y.values())r.fx=null,r.fy=null,r.vx=0,r.vy=0,r.locked=!1;Q(.35)},relayout(){lt(),N.clear();for(let r of R)r.baseLen=K(r.source,r.target),N.set(JSON.stringify([r.from,r.to,r.kind||""]),r.baseLen);O=null,V=!1,f=1},componentOf:rt,startDragScope(r){V=!0;let l=rt(r);return O=l?{ids:l.ids,members:l.members}:null,Q(.35),O},setDragging(r){V=r},clearDragScope(){O=null,V=!1},nodeById:r=>y.get(r),dispose(){y.clear(),N.clear(),L=[],R=[],U=null,H=new Map}}}function Et(d,y,N){if(!d.length)return{x:y/2,y:N/2,k:1};let L=1/0,R=-1/0,H=1/0,U=-1/0;for(let f of d){let T=Number(f.radius)||4;L=Math.min(L,f.x-T),R=Math.max(R,f.x+T),H=Math.min(H,f.y-T),U=Math.max(U,f.y+T)}let e=Y(Math.min(Math.max(32,y-100)/Math.max(120,R-L),Math.max(32,N-96)/Math.max(120,U-H)),.06,1.6);return{x:y/2-(L+R)*e/2,y:N/2-(H+U)*e/2,k:e}}function Nt(d,y,N){let L=Y(d.k*y,.06,5);return{k:L,x:N.x-(N.x-d.x)*L/d.k,y:N.y-(N.y-d.y)*L/d.k}}var Yt=(d,y)=>d.x<y.x+y.width&&d.x+d.width>y.x&&d.y<y.y+y.height&&d.y+d.height>y.y;function Kt(d,y,N,L){let R=[...y],H=[];for(let U of d){let{x:e,y:f,radius:T,textWidth:O}=U,V=[{x:e-O/2,y:f+T+5},{x:e-O/2,y:f-T-21},{x:e+T+6,y:f-8},{x:e-T-O-6,y:f-8}];if(U.priority)for(let z of[28,48,72])V.push({x:e-O/2,y:f+T+z},{x:e-O/2,y:f-T-16-z},{x:e+T+z,y:f-8},{x:e-T-O-z,y:f-8});let v=V.map(z=>({...z,width:O,height:16})).find(z=>z.x>=5&&z.y>=5&&z.x+z.width<=N-5&&z.y+z.height<=L-5&&!R.some(ht=>Yt(z,ht)));v&&(R.push({x:v.x-3,y:v.y-2,width:v.width+6,height:v.height+4}),H.push({...U,box:v}))}return H}function Xt(d,{onFocus:y=()=>{},onZoom:N=()=>{},onPaint:L=()=>{},tooltip:R,reducedMotion:H=!1,emptyLabel:U=""}={}){let e=d.getContext("2d");if(!e)throw new Error("Canvas 2D is unavailable");let f=Rt(),T=1,O=1,V=1,v={x:0,y:0,k:1},z={...Ct},ht="",K=null,b=null,St=!1,Q=!1,rt=null,it=0,yt=0,J=new Map,It=[],et=d.ownerDocument.defaultView,Mt=t=>({x:(t.x-v.x)/v.k,y:(t.y-v.y)/v.k}),ut=t=>Y((Number(t.radius)||4)*Math.sqrt(v.k),2.5,22),lt=t=>{let n=d.getBoundingClientRect();return{x:(t.clientX-n.left)*T/n.width,y:(t.clientY-n.top)*O/n.height}},xt=(t,n)=>{let h=f.nodes;if(!h.length)return null;let C=Mt(t),S=Y(Math.ceil(40/Math.max(v.k,.06)/W.cell),1,8),E=Math.floor(C.x/W.cell),ot=Math.floor(C.y/W.cell),$=new Map;for(let tt of h){let g=Ft(tt.x,tt.y),D=$.get(g);D||$.set(g,D=[]),D.push(tt)}let X=tt=>Math.max(6,ut(tt)+4),nt=null,at=1/0,st=1/0;for(let tt=-S;tt<=S;tt++)for(let g=-S;g<=S;g++){let D=$.get(`${E+tt},${ot+g}`);if(D)for(let M of D){let A=M.x*v.k+v.x,G=M.y*v.k+v.y,B=Math.hypot(A-t.x,G-t.y);M===n&&(st=B),B<=X(M)&&B<at&&(nt=M,at=B)}}return n&&st<=X(n)&&(!nt||at>st-2)?n:nt},Z=()=>{R&&(R.hidden=!0)},r=(t,n)=>{K!==t&&(K=t,s()),d.style.cursor=b?"grabbing":t?"pointer":"grab",R&&(R.hidden=!t||!!b,!(!t||b)&&(R.textContent=String(t.title||t.id),R.style.left=`${Y(n.x+14,6,Math.max(6,T-Math.min(260,T-12)))}px`,R.style.top=`${(d.offsetTop||0)+Y(n.y+16,6,O-60)}px`))},l=t=>{if(t?.snapshot){for(let n of t.snapshot){let h=f.nodeById(n.id);h&&(h.fx=n.fx,h.fy=n.fy,h.locked=n.locked===!0,h.x=n.x,h.y=n.y,h.vx=0,h.vy=0)}f.clearDragScope()}},x=t=>{let n=34*v.k;if(n<12)return;let h=(v.x%n+n)%n,C=(v.y%n+n)%n;e.fillStyle=e.strokeStyle,e.globalAlpha=t,e.beginPath();for(let S=h;S<T;S+=n)for(let E=C;E<O;E+=n)e.rect(S,E,1.2,1.2);e.fill()},k=()=>{e.setTransform(V,0,0,V,0,0),e.clearRect(0,0,T,O);let t=et.getComputedStyle(d),n=t.color||"#202020",h=t.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",C=t.getPropertyValue("--dsw-alias-brand-primary").trim()||"#3b5bdb",S=K?.id||ht,E=new Set(S?[S]:[]);for(let g of f.edges)g.from===S&&E.add(g.to),g.to===S&&E.add(g.from);e.strokeStyle=n;let ot=z.motion&&!H&&f.active?.06+.025*Math.sin(Date.now()/900):.07;z.grid!==!1&&x(ot);let $=v.k,X=v.x,nt=v.y,at=new Map;for(let g of f.edges){let D={x:g.source.x*$+X,y:g.source.y*$+nt},M={x:g.target.x*$+X,y:g.target.y*$+nt};if(D.x<-40&&M.x<-40||D.x>T+40&&M.x>T+40||D.y<-40&&M.y<-40||D.y>O+40&&M.y>O+40)continue;let A=Vt(g,n,C),G=g.source.kind!=="memory"&&g.target.kind!=="memory",B=`${A}|${g.manual?"d":"s"}|${G?"k":"n"}`,q=at.get(B);q||at.set(B,q={color:A,manual:g.manual,skeleton:G,list:[]}),q.list.push({edge:g,a:D,b:M})}e.lineWidth=.8;for(let g of at.values()){e.strokeStyle=g.color,e.globalAlpha=S?.055:g.skeleton?.1:g.manual?.24:.16,e.setLineDash(g.manual?[5,4]:[]),e.beginPath();for(let D of g.list)e.moveTo(D.a.x,D.a.y),e.lineTo(D.b.x,D.b.y);if(e.stroke(),e.setLineDash([]),g.manual&&v.k>=.3){e.fillStyle=g.color,e.globalAlpha=S?.22:.4;for(let D of g.list){if(D.edge.rule==="entity-mention"||D.edge.rule==="conflict")continue;let M=D.b.x-D.a.x,A=D.b.y-D.a.y,G=Math.hypot(M,A);if(G<=22)continue;let B=M/G,q=A/G,gt=ut(D.edge.target)+3,pt=D.b.x-B*gt,mt=D.b.y-q*gt;e.beginPath(),e.moveTo(pt,mt),e.lineTo(pt-B*7-q*3.4,mt-q*7+B*3.4),e.lineTo(pt-B*7+q*3.4,mt-q*7-B*3.4),e.closePath(),e.fill()}}}if(S){e.globalAlpha=.6,e.lineWidth=1.5,e.strokeStyle=C,e.beginPath();for(let g of f.edges)g.from!==S&&g.to!==S||(e.moveTo(g.source.x*$+X,g.source.y*$+nt),e.lineTo(g.target.x*$+X,g.target.y*$+nt));e.stroke()}e.globalAlpha=1,e.strokeStyle=n;let st=[];for(let g of f.nodes){let D=g.x*$+X,M=g.y*$+nt;D>=-120&&D<=T+120&&M>=-120&&M<=O+120&&st.push({node:g,x:D,y:M,r:ut(g)})}let tt=f.nodes.length>2400&&v.k<.3;if(tt){let g=new Map;for(let D of f.nodes){let M=D.x*$+X,A=D.y*$+nt;if(M<0||M>T||A<0||A>O)continue;let G=wt(D),B=g.get(G);B||g.set(G,B=[]),B.push(M,A)}e.globalAlpha=1;for(let[D,M]of g){e.fillStyle=D,e.beginPath();for(let A=0;A<M.length;A+=2)e.rect(M[A]-1,M[A+1]-1,2,2);e.fill()}}else{let g=new Map;for(let M of st){let A=!!S&&!E.has(M.node.id),G=wt(M.node)+(A?"|d":"|n"),B=g.get(G);B||g.set(G,B=[]),B.push(M)}for(let[M,A]of g){let[G,B]=M.split("|");e.globalAlpha=B==="d"?.22:1,e.fillStyle=G,e.beginPath();for(let q of A)e.moveTo(q.x+q.r,q.y),e.arc(q.x,q.y,q.r,0,Pt);e.fill()}e.globalAlpha=1;let D=String(z.query||"").trim().toLowerCase();for(let M of st){if(M.node.kind==="memory"||M.node.missing)continue;let A=M.r*1.75,G=Math.min(5,A/3),B=M.x-A/2,q=M.y-A/2;e.fillStyle=wt(M.node),e.beginPath(),e.moveTo(B+G,q),e.arcTo(B+A,q,B+A,q+A,G),e.arcTo(B+A,q+A,B,q+A,G),e.arcTo(B,q+A,B,q,G),e.arcTo(B,q,B+A,q,G),e.closePath(),e.fill()}for(let M of st){let A=M.node;A.status==="provisional"&&(e.strokeStyle=wt(A),e.lineWidth=1.2,e.setLineDash([3,3]),e.beginPath(),e.ellipse(M.x,M.y,M.r+5,M.r+5,0,0,Pt),e.stroke(),e.setLineDash([])),A.locked&&(e.fillStyle=h,e.globalAlpha=.95,e.fillRect(M.x-1.5,M.y-1.5,3,3),e.globalAlpha=1),(A.id===S||A.id===K?.id)&&(e.strokeStyle=A.id===S?C:wt(A),e.lineWidth=1.5,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke()),D&&String(A.title||A.id).toLowerCase().includes(D)&&(e.strokeStyle=C,e.lineWidth=2,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke())}}if(e.globalAlpha=1,e.strokeStyle=n,z.labels&&!tt){e.font='11.5px -apple-system,"PingFang SC","Microsoft YaHei",sans-serif';let g=st.filter(_=>_.x>-60&&_.x<T+60&&_.y>-60&&_.y<O+60),D=(v.k>=.55||st.length<34)&&g.length<=260,M=g.length>260?9999:3,A=Y((v.k-.3)/.35,0,1),G=b?.type==="pan"&&b.moved,gt=(b?.type==="node"&&b.moved||G)&&f.nodes.length>400?g.filter(_=>_.node.id===S):D?g:g.filter(_=>_.node.id===S||_.node.degree>=M),pt=gt.length>260?gt.slice(0,260):gt;pt.sort((_,bt)=>+(bt.node.id===S)-+(_.node.id===S)||bt.node.degree-_.node.degree);let mt=[];e.textAlign="center",e.textBaseline="top";for(let _ of pt){if(S&&!E.has(_.node.id))continue;let bt=_.node.id===S;if(!bt&&(!D&&_.node.degree<M||A<.02))continue;let At=String(_.node.title||_.node.id),Lt=e.measureText(At).width,Ot=ft=>({l:_.x-Lt/2-3,t:ft-1,r:_.x+Lt/2+3,b:ft+14}),Bt=ft=>mt.some(vt=>ft.l<vt.r&&ft.r>vt.l&&ft.t<vt.b&&ft.b>vt.t),kt=_.y+_.r+4,ct=Ot(kt);Bt(ct)&&(kt+=16,ct=Ot(kt),Bt(ct))||ct.l<2||ct.r>T-2||ct.b>O-2||(mt.push(ct),e.globalAlpha=bt?1:.78*Math.max(.35,A),e.lineWidth=3.5,e.strokeStyle=h,e.lineJoin="round",e.strokeText(At,_.x,kt),e.fillStyle=n,e.fillText(At,_.x,kt))}e.globalAlpha=1}else if(z.labels&&tt&&S){let g=f.nodes.find(D=>D.id===S);g&&(e.font="12px system-ui, sans-serif",e.textAlign="center",e.textBaseline="top",e.fillStyle=n,e.fillText(String(g.title||g.id),g.x*$+X,g.y*$+nt+10))}!f.nodes.length&&U&&(e.font="13px system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n,e.globalAlpha=.55,e.fillText(U,T/2,O/2),e.globalAlpha=1),L()},F=t=>{if(rt=null,Q)return;let n=z.motion&&!H&&f.active;if(n){yt+=it?Math.min(64,t-it):17;let h=0;for(;yt>=1e3/60&&h<4;yt-=1e3/60,h++)f.tick();it=t}else it=0,yt=0;k(),n&&s()};function s(){!Q&&rt===null&&(rt=et.requestAnimationFrame(F))}let w=()=>{N(v.k),s()},o=()=>{v=Et(f.nodes,T,O),Z(),w()},I=(t,n={x:T/2,y:O/2})=>{v=Nt(v,t,n),Z(),w()},m=()=>{let t=d.getBoundingClientRect();if(!t.width||!t.height)return;let n=t.width,h=t.height;v.x+=(n-T)/2,v.y+=(h-O)/2,T=n,O=h,V=Math.min(2,et.devicePixelRatio||1),d.width=Math.round(T*V),d.height=Math.round(O*V),s()},i=()=>{l(b);let[t,n]=[...J.values()];b={type:"pinch",distance:Math.max(1,Math.hypot(n.x-t.x,n.y-t.y)),camera:{...v},center:{x:(t.x+n.x)/2,y:(t.y+n.y)/2},moved:!0}},p=t=>{if(t.button!==0&&t.pointerType!=="touch")return;t.preventDefault(),d.focus({preventScroll:!0});let n=lt(t);if(J.set(t.pointerId,n),d.setPointerCapture?.(t.pointerId),J.size>=2){i(),Z();return}let h=xt(n),C=Mt(n),S=h?f.componentOf(h.id):null,E=h&&t.shiftKey&&S?"rigid":"node",ot=E==="rigid"?S.members:h?[h]:[];if(b={type:h?"node":"pan",node:h,mode:E,members:ot,start:n,camera:{...v},moved:!1,offset:h?{x:h.x-C.x,y:h.y-C.y}:null,snapshot:ot.map($=>({id:$.id,x:$.x,y:$.y,fx:$.fx,fy:$.fy,locked:$.locked}))},h){for(let $ of ot)f.hold($.id,$.x,$.y);f.startDragScope(h.id),f.setDragging(!0)}Z(),d.style.cursor="grabbing"},u=t=>{let n=lt(t);if(!J.has(t.pointerId)||!b){r(xt(n,K),n);return}if(J.set(t.pointerId,n),b.type==="pinch"){if(J.size<2)return;let[h,C]=[...J.values()],S={x:(h.x+C.x)/2,y:(h.y+C.y)/2};v=Nt(b.camera,Math.hypot(C.x-h.x,C.y-h.y)/b.distance,b.center),v.x+=S.x-b.center.x,v.y+=S.y-b.center.y,w()}else{if(b.moved||(b.moved=Math.hypot(n.x-b.start.x,n.y-b.start.y)>5),!b.moved)return;if(b.node){let h=Mt(n),C=b.node;if(b.mode==="rigid"){let S=h.x+b.offset.x,E=h.y+b.offset.y,ot=S-C.fx,$=E-C.fy;for(let X of b.members)f.hold(X.id,X.fx+ot,X.fy+$)}else f.hold(C.id,h.x+b.offset.x,h.y+b.offset.y);f.settle(2)}else v.x=b.camera.x+n.x-b.start.x,v.y=b.camera.y+n.y-b.start.y;s()}},a=t=>{if(!J.has(t.pointerId))return;let n=t.type!=="pointerup",h=b?.node,C=!n&&!b?.moved&&b?.type!=="pinch"&&(t.detail??1)<2;if(C||n)l(b);else if(h){for(let S of b.snapshot){let E=f.nodeById(S.id);E&&(S.locked||S.fx!=null?(E.fx=E.x,E.fy=E.y,E.locked=!0,E.vx=0,E.vy=0):f.release(S.id))}f.setDragging(!1),H||!z.motion?(f.settle(120),f.clearDragScope()):f.reheat(.3)}J.delete(t.pointerId),b=null,J.size&&(b={type:"pan",start:[...J.values()][0],camera:{...v},moved:!0}),d.hasPointerCapture?.(t.pointerId)&&d.releasePointerCapture(t.pointerId),C&&y(h?.id||""),K=null,d.style.cursor="grab",Z(),s()},c=(t,n,h,C)=>{t.addEventListener(n,h,C),It.push(()=>t.removeEventListener(n,h,C))};c(d,"pointerdown",p),c(d,"pointermove",u);for(let t of["pointerup","pointercancel","lostpointercapture"])c(d,t,a);c(d,"pointerleave",()=>{b||(K=null,Z(),s())}),c(d,"contextmenu",t=>{t.preventDefault();let n=xt(lt(t));if(!n)return;let h=f.nodeById(n.id);h&&(h.fx!=null?f.unpin(n.id):f.pin(n.id,h.x,h.y),f.setDragging(!1),(H||!z.motion)&&f.settle(20),s())}),c(d,"dblclick",t=>{y(xt(lt(t))?.id||"")}),c(d,"wheel",t=>{t.preventDefault(),I(Math.exp(-Y(t.deltaY,-160,160)*.0025),lt(t))},{passive:!1}),c(d,"keydown",t=>{if(t.key==="+"||t.key==="=")I(1.25);else if(t.key==="-")I(.8);else if(t.key==="0"||t.key==="Home")o();else if(t.key==="Escape")l(b),b=null,J.clear(),y(""),Z(),s();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)){let n=t.shiftKey?90:30;v.x+=t.key==="ArrowLeft"?n:t.key==="ArrowRight"?-n:0,v.y+=t.key==="ArrowUp"?n:t.key==="ArrowDown"?-n:0,s()}else return;t.preventDefault()}),c(et,"blur",()=>{l(b),b=null,J.clear(),K=null,Z(),s()});let P=et.ResizeObserver?new et.ResizeObserver(m):null;P?.observe(d),c(et,"resize",m);let j=et.MutationObserver?new et.MutationObserver(s):null;return j?.observe(d.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),d.ownerDocument.body&&j?.observe(d.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),m(),{update(t,n=""){b?.node&&!t.nodes.some(C=>C.id===b.node.id)&&(l(b),b=null,J.clear());let h=f.update(t);ht=n,K&&!f.nodes.includes(K)&&(K=null,Z()),!St&&f.nodes.length?(f.settle(220),St=!0,o()):h&&(H||!z.motion)&&f.settle(180),s()},configure(t){let n=["repulsion","distance","center"].some(h=>t[h]!==void 0&&t[h]!==z[h]);z={...z,...t},n&&(f.configure(t),(H||!z.motion)&&f.settle(160)),s()},fit:o,zoom:I,isPinned(t){return f.nodeById(t)?.locked===!0},pinnedCount(){return f.nodes.reduce((t,n)=>t+(n.locked?1:0),0)},snapshot(){return f.nodes.map(t=>({id:t.id,x:t.x*v.k+v.x,y:t.y*v.k+v.y,r:ut(t),pinned:t.locked===!0,degree:t.degree||0}))},unpinAll(){f.unpinAll(),f.clearDragScope(),(H||!z.motion)&&f.settle(120),s()},relayout(){l(b),b=null,J.clear(),f.relayout(),(H||!z.motion)&&f.settle(220),s()},dispose(){Q=!0,l(b),b=null,J.clear(),rt!==null&&et.cancelAnimationFrame(rt);for(let t of It)t();P?.disconnect(),j?.disconnect(),f.dispose(),Z()}}}return Wt(Qt);})();
|
package/lib/webui/graph-view.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
const TAU = Math.PI * 2
|
|
7
7
|
const GOLDEN_ANGLE = 2.399963229728653
|
|
8
|
-
const INPUT_LIMIT = 200 // 与 getGraph 的 limit 对齐
|
|
9
8
|
const CACHE_LIMIT = 800
|
|
10
9
|
const PHYSICS_KEYS = new Set(['x', 'y', 'vx', 'vy', 'fx', 'fy'])
|
|
11
10
|
const clamp = (value, min, max) => Math.max(min, Math.min(max, value))
|
|
@@ -354,7 +353,7 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
354
353
|
}
|
|
355
354
|
|
|
356
355
|
const update = graph => {
|
|
357
|
-
const input = [...new Map((graph?.nodes || []).
|
|
356
|
+
const input = [...new Map((graph?.nodes || []).map(node => [node.id, node])).values()]
|
|
358
357
|
.sort((a, b) => String(a.id).localeCompare(String(b.id)))
|
|
359
358
|
const ids = new Set(input.map(node => node.id))
|
|
360
359
|
const links = (graph?.edges || []).filter(edge => ids.has(edge.from) && ids.has(edge.to) && edge.from !== edge.to)
|
package/lib/webui/standalone.js
CHANGED
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
zh: {
|
|
29
29
|
engine: '引擎与连接', connection: '连接与向量', settings: '记忆设置', folders: '文件夹', libraries: '记忆库',
|
|
30
30
|
browser: '记忆浏览', global: '全局记忆', prompts: '提示词', stats: '统计', memories: '记忆总览',
|
|
31
|
-
graph: '关系图谱', logs: '日志', lexicon: '词典', help: '帮助',
|
|
31
|
+
graph: '关系图谱', logs: '日志', lexicon: '词典', help: '帮助', diagnostics: '诊断',
|
|
32
32
|
},
|
|
33
33
|
en: {
|
|
34
34
|
engine: 'Engine & connection', connection: 'Connection & vectors', settings: 'Memory settings', folders: 'Folders', libraries: 'Libraries',
|
|
35
35
|
browser: 'Memory browser', global: 'Global memory', prompts: 'Prompts', stats: 'Stats', memories: 'Memories',
|
|
36
|
-
graph: 'Relationship graph', logs: 'Logs', lexicon: 'Lexicon', help: 'Help',
|
|
36
|
+
graph: 'Relationship graph', logs: 'Logs', lexicon: 'Lexicon', help: 'Help', diagnostics: 'Diagnostics',
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
39
|
var copy = COPY[locale]
|
package/package.json
CHANGED
|
@@ -159,3 +159,74 @@ test('legacy grading keeps asserted rows and downgrades everything else to provi
|
|
|
159
159
|
assert.equal(graded[c.id].status, 'confirmed', 'a non-auto inbound link protects the row')
|
|
160
160
|
assert.equal(graded[b.id].status, 'provisional', 'garbage without evidence stays provisional')
|
|
161
161
|
})
|
|
162
|
+
|
|
163
|
+
test('quoted and introduced surfaces do not nominate fragments, including spans beyond the n-gram cap', () => {
|
|
164
|
+
const entries = [
|
|
165
|
+
'她叫主人一说。提到「记忆组件」和「极光记忆组件」。我叫「小一」。',
|
|
166
|
+
'她自称「主人一说」。使用「记忆组件」和「极光记忆组件」。也叫“小一”。',
|
|
167
|
+
...Array.from({ length: 8 }, (_, i) => '额外记录 ' + i),
|
|
168
|
+
].map(text => ({ text, title: '' }))
|
|
169
|
+
const stats = terminology.buildTermStats(entries)
|
|
170
|
+
const ranked = terminology.rankCandidates(entries, stats)
|
|
171
|
+
const queue = [...ranked.tier1, ...ranked.tier2]
|
|
172
|
+
for (const fragment of ['忆组件', '主人一', '人一', '主人一说', '极光记忆']) {
|
|
173
|
+
assert.equal(stats.get(fragment)?.df, 2, fragment + ' is present in the raw statistics')
|
|
174
|
+
assert.ok(!queue.some(row => row.term === fragment), fragment + ' must stay out of the review queue')
|
|
175
|
+
}
|
|
176
|
+
assert.equal(ranked.tier1.find(row => row.term === '记忆组件')?.quoted, true)
|
|
177
|
+
const name = ranked.tier1.find(row => row.term === '小一')
|
|
178
|
+
assert.equal(name?.quoted, true)
|
|
179
|
+
assert.equal(name?.intro, true)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test('a candidate can qualify independently of a longer name intro and quoted span', () => {
|
|
183
|
+
const entries = [
|
|
184
|
+
'她叫主人一说得对。后来新成员报名,名字是「主人一」。',
|
|
185
|
+
'大家用“主人一”称呼新成员。另有「主人一说」。',
|
|
186
|
+
...Array.from({ length: 8 }, (_, i) => '额外记录 ' + i),
|
|
187
|
+
].map(text => ({ text, title: '' }))
|
|
188
|
+
const ranked = terminology.rankCandidates(entries, terminology.buildTermStats(entries))
|
|
189
|
+
const owner = ranked.tier1.find(row => row.term === '主人一')
|
|
190
|
+
assert.equal(owner?.quoted, true)
|
|
191
|
+
assert.equal(owner?.intro, true)
|
|
192
|
+
assert.ok(![...ranked.tier1, ...ranked.tier2].some(row => row.term === '人一'))
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('older candidate snapshots are rebuilt despite an unchanged source signature', () => {
|
|
196
|
+
const lib = library('old-snapshot')
|
|
197
|
+
state.savePrivateIndex(lib, { version: 1, entries: fixture() })
|
|
198
|
+
const fresh = candidates.generateAnchorCandidates({ libraryId: lib, now: 1 })
|
|
199
|
+
const file = candidates.candidatesFile(lib)
|
|
200
|
+
const legacy = { ...fresh, version: 1, tiers: { tier1: [{ term: '遗留碎片' }], tier2: [] } }
|
|
201
|
+
delete legacy.candidateVersion
|
|
202
|
+
fs.writeFileSync(file, JSON.stringify(legacy), 'utf8')
|
|
203
|
+
candidates.resetAnchorCandidatesCache()
|
|
204
|
+
const rebuilt = candidates.generateAnchorCandidates({ libraryId: lib, now: 2 })
|
|
205
|
+
assert.equal(rebuilt.revision, fresh.revision)
|
|
206
|
+
assert.equal(rebuilt.generatedAt, new Date(2).toISOString())
|
|
207
|
+
assert.deepEqual(rebuilt.tiers, fresh.tiers)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('custom candidate policy invalidates both cache layers for that library', async () => {
|
|
211
|
+
const { AUTOLINK_POLICY_V3 } = await import('../lib/auto-link/policy.js')
|
|
212
|
+
const lib = library('policy-cache')
|
|
213
|
+
state.savePrivateIndex(lib, { version: 1, entries: fixture() })
|
|
214
|
+
const normal = candidates.generateAnchorCandidates({ libraryId: lib, now: 1 })
|
|
215
|
+
assert.equal(normal.tiers.tier1.find(row => row.term === '小柚')?.df, 2)
|
|
216
|
+
const strictPolicy = { ...AUTOLINK_POLICY_V3, minDf: 3 }
|
|
217
|
+
const strict = candidates.generateAnchorCandidates({ libraryId: lib, now: 2, policy: strictPolicy })
|
|
218
|
+
assert.equal(strict.tiers.tier1.some(row => row.term === '小柚'), false)
|
|
219
|
+
candidates.resetAnchorCandidatesCache()
|
|
220
|
+
assert.deepEqual(candidates.generateAnchorCandidates({ libraryId: lib, now: 3, policy: { ...strictPolicy } }), strict)
|
|
221
|
+
candidates.resetAnchorCandidatesCache()
|
|
222
|
+
const normalAgain = candidates.generateAnchorCandidates({ libraryId: lib, now: 4 })
|
|
223
|
+
assert.deepEqual(normalAgain.tiers, normal.tiers)
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
test('name-intro does not treat a prefix of a mixed-script surface as a whole name', () => {
|
|
227
|
+
const entries = ['她叫阿兰2。', '名字是「阿兰2」。', '额外记录'].map(text => ({ text, title: '' }))
|
|
228
|
+
const stats = terminology.buildTermStats(entries)
|
|
229
|
+
assert.equal(stats.get('阿兰')?.df, 2)
|
|
230
|
+
const { tier1, tier2 } = terminology.rankCandidates(entries, stats)
|
|
231
|
+
assert.ok(![...tier1, ...tier2].some(row => row.term === '阿兰'))
|
|
232
|
+
})
|