dsh-memu-memory 1.4.2 → 1.4.4
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/AGENTS.md +108 -110
- package/CHANGELOG.md +173 -868
- package/LICENSE +21 -21
- package/README.md +368 -374
- package/README.zh.md +354 -360
- package/assets/icon.svg +7 -7
- package/cordis.patch.yml +8 -8
- package/docs/active-memory-ab.md +279 -385
- package/docs/binding-lifecycle.md +99 -99
- package/docs/client-conventions.md +75 -75
- package/docs/contributing.md +217 -217
- package/docs/emotion-model-spec.md +247 -281
- package/docs/env-and-commands.md +149 -152
- package/docs/host-adaptation.md +339 -360
- package/docs/host-api.md +131 -137
- package/docs/host-versions.md +117 -120
- package/docs/mcp-porting.md +146 -146
- package/docs/memory-semantics.md +271 -259
- package/docs/pending-work.md +44 -51
- package/docs/troubleshooting.md +909 -854
- package/lib/active-memory.js +160 -165
- package/lib/activity-log.js +207 -207
- package/lib/auto-link/apply.js +248 -249
- package/lib/auto-link/candidates.js +163 -163
- package/lib/auto-link/decide.js +300 -300
- package/lib/auto-link/normalize.js +99 -99
- package/lib/auto-link/policy.js +42 -42
- package/lib/auto-link/suppression.js +101 -101
- package/lib/auto-link/terminology.js +311 -311
- package/lib/backup.js +1254 -1254
- package/lib/binding-diagnostics.js +634 -634
- package/lib/budget.js +118 -118
- package/lib/client.js +9820 -9751
- package/lib/commitment.js +178 -138
- package/lib/consolidation-ledger.js +434 -438
- package/lib/consolidation-receipt.js +386 -387
- package/lib/consolidation-snapshot.js +420 -405
- package/lib/consolidation-worker.js +240 -241
- package/lib/context.js +33 -33
- package/lib/curator-evidence.js +131 -131
- package/lib/curator-policy.js +198 -202
- package/lib/curator.js +1813 -1811
- package/lib/cycle.js +524 -513
- package/lib/diagnostics.js +524 -524
- package/lib/embedding-catalog.js +1051 -1055
- package/lib/embedding-download.js +637 -607
- package/lib/embedding-runtime.js +946 -946
- package/lib/engine.js +1103 -1103
- package/lib/entity-repair.js +285 -285
- package/lib/environment-check.js +394 -394
- package/lib/fork-model.js +312 -312
- package/lib/freshness.js +128 -121
- package/lib/global-graph.js +389 -389
- package/lib/graph.js +1193 -1193
- package/lib/host-surface.js +30 -30
- package/lib/inbound.js +284 -281
- package/lib/index.js +506 -511
- package/lib/inject.js +2639 -2619
- package/lib/lexicon-scope.js +143 -143
- package/lib/lexicon.js +1183 -1192
- package/lib/lifecycle-audit.js +37 -0
- package/lib/local-embedding-entry.js +145 -145
- package/lib/local-embedding-manager.js +306 -306
- package/lib/local-embedding-protocol.js +210 -210
- package/lib/local-embedding-worker.js +682 -682
- package/lib/local-vector-service.js +506 -453
- package/lib/maintenance-ledger.js +138 -0
- package/lib/maintenance-review.js +103 -0
- package/lib/maintenance-runner.js +267 -0
- package/lib/managed-runtime.js +118 -118
- package/lib/media.js +607 -513
- package/lib/memory.js +5035 -4941
- package/lib/memu-config.js +213 -213
- package/lib/memu.js +565 -565
- package/lib/migrate.js +200 -200
- package/lib/mood.js +300 -300
- package/lib/paths.js +453 -457
- package/lib/port-surface.js +82 -82
- package/lib/preset-mount.js +85 -0
- package/lib/preset-scope.js +126 -126
- package/lib/private-links.js +567 -567
- package/lib/private.js +2198 -2209
- package/lib/prompts/global-curator.md +135 -135
- package/lib/prompts/image-caption.md +1 -1
- package/lib/prompts/private-consolidation.coding.md +39 -39
- package/lib/prompts/private-consolidation.md +32 -32
- package/lib/prompts/private-consolidation.mixed.md +37 -37
- package/lib/prompts/private-consolidation.rp.md +47 -47
- package/lib/prompts/private-policy.coding.md +35 -35
- package/lib/prompts/private-policy.md +36 -36
- package/lib/prompts/private-policy.mixed.md +29 -29
- package/lib/prompts/private-policy.rp.md +43 -43
- package/lib/prompts/system-guide.coding.md +20 -20
- package/lib/prompts/system-guide.md +25 -25
- package/lib/prompts/system-guide.mixed.md +22 -22
- package/lib/prompts/system-guide.rp.md +23 -23
- package/lib/prompts.js +331 -331
- package/lib/recall-cache.js +212 -212
- package/lib/remote-summary.js +123 -123
- package/lib/rpc.js +2531 -2532
- package/lib/salient-wake.js +438 -438
- package/lib/snippet.js +125 -125
- package/lib/state.js +1948 -1928
- package/lib/stats.js +236 -236
- package/lib/temporal.js +345 -348
- package/lib/text-retrieval.js +992 -1001
- package/lib/text-similarity.js +305 -305
- package/lib/tokenizer-v2.js +271 -271
- package/lib/tools.js +1098 -1091
- package/lib/turn-log.js +545 -545
- package/lib/vector-migration.js +928 -930
- package/lib/vector-profile.js +1353 -1359
- package/lib/visibility.js +59 -59
- package/lib/webui/graph-LICENSE.txt +1 -1
- package/lib/webui/graph-view.bundle.js +2 -2
- package/lib/webui/graph-view.js +1171 -1175
- package/lib/webui/mark.svg +7 -7
- package/lib/webui/standalone.css +1178 -1178
- package/lib/webui/standalone.js +238 -238
- package/lib/webui.js +136 -136
- package/lib/worker-pool.js +1020 -979
- package/package.json +153 -153
- package/requirements.lock +34 -34
- package/scripts/acceptance-local.mjs +946 -946
- package/scripts/active-memory-ab-live.mjs +653 -655
- package/scripts/active-memory-ab.mjs +1302 -1302
- package/scripts/audit-memory-lifecycle.mjs +55 -0
- package/scripts/bench-recall.mjs +142 -142
- package/scripts/build-graph.mjs +44 -45
- package/scripts/chain-matrix.mjs +541 -541
- package/scripts/check-all.mjs +68 -74
- package/scripts/check-doc-drift.mjs +547 -547
- package/scripts/check-graph-browser.mjs +261 -261
- package/scripts/check-i18n.mjs +81 -83
- package/scripts/check-idle-compositing.mjs +61 -61
- package/scripts/check-seed-compat.mjs +115 -118
- package/scripts/check-text-format.mjs +55 -0
- package/scripts/curator-pair-calibrate.mjs +259 -259
- package/scripts/diagnose-bindings.mjs +176 -176
- package/scripts/drive-session.mjs +863 -864
- package/scripts/engine-smoke.mjs +69 -69
- package/scripts/entity-dedupe.mjs +110 -110
- package/scripts/lexicon-calibrate.mjs +230 -230
- package/scripts/lexicon-dedupe.mjs +318 -318
- package/scripts/local-runtime-install.mjs +142 -142
- package/scripts/local-runtime-verify.mjs +56 -56
- package/scripts/local-vector-verify.mjs +93 -93
- package/scripts/make-readme-shots.mjs +59 -59
- package/scripts/migrate-visibility.mjs +94 -94
- package/scripts/mock-llm.mjs +938 -903
- package/scripts/preview.mjs +58 -58
- package/scripts/prune-sessions.mjs +31 -34
- package/scripts/prune-turnlogs.mjs +29 -30
- package/scripts/prune-vectors.mjs +24 -24
- package/scripts/rebuild-auto-links.mjs +252 -252
- package/scripts/recall-bench.mjs +820 -820
- package/scripts/repetition-ab-scenarios.mjs +93 -93
- package/scripts/repetition-detector-snapshot.mjs +314 -314
- package/scripts/repetition-eval-live.mjs +360 -360
- package/scripts/repetition-eval.mjs +702 -702
- package/scripts/replay.mjs +705 -575
- package/scripts/setup.mjs +46 -46
- package/scripts/simulate-injection.mjs +299 -301
- package/tests/absorb-review.test.mjs +354 -354
- package/tests/activation.test.mjs +89 -89
- package/tests/active-memory-ab.test.mjs +745 -745
- package/tests/active-memory.test.mjs +129 -129
- package/tests/activity-log.test.mjs +126 -126
- package/tests/activity-wiring.test.mjs +155 -155
- package/tests/appendix-b.test.mjs +217 -217
- package/tests/appendix-b2.test.mjs +166 -166
- package/tests/audit-batch3.test.mjs +247 -247
- package/tests/audit-regression.test.mjs +275 -275
- package/tests/audit-safety.test.mjs +227 -227
- package/tests/auto-link-candidates.test.mjs +245 -245
- package/tests/auto-link-decide.test.mjs +512 -512
- package/tests/auto-link-migration.test.mjs +133 -133
- package/tests/backend-compensation.test.mjs +272 -272
- package/tests/backup.test.mjs +793 -793
- package/tests/binding-diagnostics.test.mjs +720 -720
- package/tests/browser.test.mjs +476 -476
- package/tests/client-export.test.mjs +521 -521
- package/tests/client-render.test.mjs +2008 -1728
- package/tests/coalesce.test.mjs +113 -113
- package/tests/commitment.test.mjs +243 -144
- package/tests/config.test.mjs +159 -159
- package/tests/consolidation-credential.test.mjs +330 -330
- package/tests/consolidation-feed.test.mjs +122 -122
- package/tests/consolidation-fork.test.mjs +1587 -1539
- package/tests/consolidation-ledger.test.mjs +389 -389
- package/tests/consolidation-snapshot.test.mjs +567 -505
- package/tests/consolidation-value.test.mjs +89 -89
- package/tests/context-scope.test.mjs +40 -40
- package/tests/cross-library-recall.test.mjs +269 -269
- package/tests/cue.test.mjs +58 -58
- package/tests/curator-absorb.test.mjs +444 -444
- package/tests/curator-calibrate.test.mjs +173 -173
- package/tests/curator-clusters.test.mjs +306 -306
- package/tests/curator-commit.test.mjs +325 -325
- package/tests/curator-contract.test.mjs +191 -191
- package/tests/curator-evidence.test.mjs +102 -102
- package/tests/curator-link.test.mjs +317 -317
- package/tests/curator-pairing.test.mjs +339 -339
- package/tests/curator-probe.test.mjs +490 -490
- package/tests/curator-review-mode.test.mjs +315 -315
- package/tests/curator.test.mjs +152 -152
- package/tests/cycle.test.mjs +567 -568
- package/tests/diagnostics.test.mjs +278 -278
- package/tests/disclosure.test.mjs +249 -249
- package/tests/doc-drift.test.mjs +342 -342
- package/tests/drive-session.test.mjs +152 -152
- package/tests/dynamic-rrf.test.mjs +182 -182
- package/tests/dynamic-threshold.test.mjs +52 -52
- package/tests/embedding-catalog.test.mjs +374 -374
- package/tests/embedding-download.test.mjs +529 -486
- package/tests/embedding-runtime.test.mjs +449 -449
- package/tests/emotion-chain.test.mjs +84 -84
- package/tests/emotion-contract.test.mjs +445 -445
- package/tests/engine.test.mjs +108 -108
- package/tests/entity-merge.test.mjs +278 -278
- package/tests/environment-check.test.mjs +187 -187
- package/tests/fact-version.test.mjs +146 -146
- package/tests/fixtures/active-memory-ab/README.md +56 -56
- package/tests/fixtures/active-memory-ab/cases/01-clean-dense-turn.json +351 -351
- package/tests/fixtures/active-memory-ab/cases/02-clean-thin-turn.json +122 -122
- package/tests/fixtures/active-memory-ab/cases/03-clean-starved-small.json +125 -125
- package/tests/fixtures/active-memory-ab/cases/04-clean-large-thin.json +137 -137
- package/tests/fixtures/active-memory-ab/cases/05-clean-half-step.json +166 -166
- package/tests/fixtures/active-memory-ab/cases/06-clean-duplicate-reread.json +197 -197
- package/tests/fixtures/active-memory-ab/cases/07-clean-recent-recall.json +125 -125
- package/tests/fixtures/active-memory-ab/cases/08-global-relevant.json +111 -111
- package/tests/fixtures/active-memory-ab/cases/09-global-irrelevant-conflict.json +158 -158
- package/tests/fixtures/active-memory-ab/cases/10-no-human-turn.json +97 -97
- package/tests/fixtures/active-memory-ab/cases/11-clean-scale-100.json +137 -137
- package/tests/fixtures/active-memory-ab/cases/12-clean-scale-1000.json +137 -137
- package/tests/fixtures/active-memory-ab/cases/13-clean-scale-5000.json +137 -137
- package/tests/fixtures/active-memory-ab/cases/14-clean-scale-20000.json +137 -137
- package/tests/fixtures/active-memory-ab/lead-ai-reviewed-reference.json +191 -191
- package/tests/fixtures/active-memory-ab/manifest.json +199 -199
- package/tests/fixtures/curator-pairs/labeled.v1.jsonl +90 -90
- package/tests/fixtures/lexicon-stub-hooks.mjs +15 -15
- package/tests/fixtures/lexicon-stub.mjs +284 -284
- package/tests/fixtures/mock-llm/reply.txt +1 -1
- package/tests/fixtures/recall-bench/01-paraphrase.json +183 -183
- package/tests/fixtures/recall-bench/02-exact.json +152 -152
- package/tests/fixtures/recall-bench/03-negation.json +172 -172
- package/tests/fixtures/recall-bench/04-no-answer.json +161 -161
- package/tests/fixtures/recall-bench/05-conflict.json +193 -193
- package/tests/fixtures/recall-bench/06-boundary.json +272 -272
- package/tests/fixtures/recall-bench/07-secret.json +190 -190
- package/tests/fixtures/recall-bench/08-coding.json +163 -163
- package/tests/fixtures/recall-bench-gold-candidates/01-paraphrase.json +193 -193
- package/tests/fixtures/recall-bench-gold-candidates/02-exact.json +197 -197
- package/tests/fixtures/recall-bench-gold-candidates/03-negation.json +244 -244
- package/tests/fixtures/recall-bench-gold-candidates/04-no-answer.json +189 -189
- package/tests/fixtures/recall-bench-gold-candidates/05-conflict.json +245 -245
- package/tests/fixtures/recall-bench-gold-candidates/06-boundary.json +279 -279
- package/tests/fixtures/recall-bench-gold-candidates/07-secret.json +224 -224
- package/tests/fixtures/recall-bench-gold-candidates/08-coding.json +218 -218
- package/tests/fixtures/repetition-eval/01-zh-rp.json +92 -92
- package/tests/fixtures/repetition-eval/02-en.json +96 -96
- package/tests/fixtures/repetition-eval/03-code.json +90 -90
- package/tests/fixtures/repetition-eval/04-names.json +115 -115
- package/tests/fixtures/repetition-eval/05-user-quote.json +95 -95
- package/tests/fixtures/repetition-eval/06-agreement.json +85 -85
- package/tests/fixtures/tokenizer-cases.mjs +27 -27
- package/tests/fork-model.test.mjs +345 -345
- package/tests/freshness.test.mjs +140 -140
- package/tests/global-graph.test.mjs +106 -106
- package/tests/global-lifecycle.test.mjs +149 -149
- package/tests/graph-cascade.test.mjs +363 -363
- package/tests/graph-view.test.mjs +414 -414
- package/tests/graph.test.mjs +371 -371
- package/tests/help-page.test.mjs +416 -416
- package/tests/hook-order.test.mjs +72 -72
- package/tests/humanlike.test.mjs +232 -232
- package/tests/hybrid-recall.test.mjs +610 -610
- package/tests/inbound.test.mjs +441 -441
- package/tests/inject-conflict.test.mjs +173 -173
- package/tests/inject-guide.test.mjs +513 -513
- package/tests/inject.test.mjs +384 -384
- package/tests/injection-budget-settings.test.mjs +35 -35
- package/tests/injection-budget.test.mjs +165 -165
- package/tests/injection-chain.test.mjs +442 -442
- package/tests/injection-intent-budget.test.mjs +92 -92
- package/tests/injection-rollback.test.mjs +428 -428
- package/tests/issue2-chain.test.mjs +169 -169
- package/tests/lexical-bm25.test.mjs +171 -171
- package/tests/lexicon-calibrate.test.mjs +48 -48
- package/tests/lexicon-dedupe.test.mjs +171 -171
- package/tests/lexicon-frequency.test.mjs +195 -195
- package/tests/lexicon-inject.test.mjs +459 -459
- package/tests/lexicon-perf.test.mjs +464 -464
- package/tests/lexicon-scope.test.mjs +256 -256
- package/tests/lexicon-ui.test.mjs +667 -667
- package/tests/lexicon.test.mjs +922 -922
- package/tests/lifecycle-audit.test.mjs +56 -0
- package/tests/loader-register.mjs +3 -3
- package/tests/loader.mjs +17 -17
- package/tests/local-embedding-entry.test.mjs +95 -95
- package/tests/local-embedding-env.test.mjs +51 -51
- package/tests/local-embedding-manager.test.mjs +494 -494
- package/tests/local-embedding-protocol.test.mjs +121 -121
- package/tests/local-embedding-worker.test.mjs +440 -440
- package/tests/local-vector-service.test.mjs +41 -0
- package/tests/maintenance-status.test.mjs +77 -0
- package/tests/maintenance.test.mjs +438 -0
- package/tests/managed-memory.test.mjs +1234 -1234
- package/tests/managed-runtime.test.mjs +72 -72
- package/tests/media-injection.test.mjs +225 -0
- package/tests/media.test.mjs +135 -135
- package/tests/memory-chain.test.mjs +169 -169
- package/tests/memory-fields.test.mjs +134 -134
- package/tests/memu-resident-route.test.mjs +130 -130
- package/tests/memu-resident.test.mjs +33 -33
- package/tests/migration-payload.test.mjs +40 -42
- package/tests/mock-llm.test.mjs +263 -225
- package/tests/mood.test.mjs +109 -109
- package/tests/multiprocess.test.mjs +29 -29
- package/tests/negation-polarity.test.mjs +135 -135
- package/tests/new-session-gate.test.mjs +617 -617
- package/tests/open-loop-date.test.mjs +416 -416
- package/tests/ops-hardening.test.mjs +209 -209
- package/tests/package-shipping.test.mjs +88 -88
- package/tests/pending-injection.test.mjs +107 -107
- package/tests/port-surface.test.mjs +138 -138
- package/tests/preset-mount.test.mjs +132 -0
- package/tests/preset-scope.test.mjs +212 -212
- package/tests/private-links.test.mjs +493 -493
- package/tests/prompt-semantics.test.mjs +51 -51
- package/tests/prompts.test.mjs +315 -315
- package/tests/query-decompose.test.mjs +62 -62
- package/tests/react-snapshot.test.mjs +24 -24
- package/tests/recall-bench.test.mjs +317 -317
- package/tests/recall-cache.test.mjs +292 -292
- package/tests/recall-corpus-eligibility.test.mjs +51 -51
- package/tests/recall-dedup.test.mjs +446 -446
- package/tests/recall-intent.test.mjs +172 -172
- package/tests/regression-sweep.test.mjs +311 -311
- package/tests/reminder-fairness.test.mjs +55 -0
- package/tests/remote.test.mjs +140 -140
- package/tests/rename.test.mjs +30 -30
- package/tests/repetition-detector-snapshot.test.mjs +231 -231
- package/tests/repetition-eval-live.test.mjs +177 -177
- package/tests/repetition-eval.test.mjs +373 -373
- package/tests/salience-domain.test.mjs +173 -173
- package/tests/salient-date.test.mjs +142 -142
- package/tests/salient-wake.test.mjs +389 -389
- package/tests/settings-beat.test.mjs +222 -222
- package/tests/settings-coverage.test.mjs +97 -97
- package/tests/settings-plumbing.test.mjs +79 -79
- package/tests/short-term.test.mjs +182 -166
- package/tests/sidebar-beat.test.mjs +213 -213
- package/tests/sidebar-refresh.test.mjs +123 -123
- package/tests/sidebar.test.mjs +102 -74
- package/tests/simulate-injection.test.mjs +76 -76
- package/tests/slot-similarity.test.mjs +153 -153
- package/tests/snippet.test.mjs +79 -79
- package/tests/source-kind.test.mjs +52 -52
- package/tests/speaker-provenance.test.mjs +120 -120
- package/tests/stale-maintenance.test.mjs +206 -131
- package/tests/state-gc.test.mjs +34 -34
- package/tests/state.test.mjs +155 -155
- package/tests/stats.test.mjs +112 -112
- package/tests/storage.test.mjs +125 -125
- package/tests/stubs/child-process-spy.mjs +14 -14
- package/tests/stubs/dsh-llm-pi-ai.js +13 -13
- package/tests/stubs/dsh-llm.js +5 -5
- package/tests/stubs/dsh-schedule.js +140 -140
- package/tests/stubs/dsh-session-query.js +26 -26
- package/tests/stubs/dsh-session.js +7 -7
- package/tests/stubs/dsh-tools.js +101 -101
- package/tests/temporal-repair.test.mjs +78 -0
- package/tests/temporal.test.mjs +124 -124
- package/tests/text-format.test.mjs +24 -0
- package/tests/tokenizer-v2.test.mjs +142 -142
- package/tests/tool-schema.test.mjs +126 -126
- package/tests/tools.test.mjs +810 -810
- package/tests/turn-log.test.mjs +487 -487
- package/tests/ui-defaults.test.mjs +57 -57
- package/tests/update-fields.test.mjs +138 -138
- package/tests/vector-gc.test.mjs +37 -37
- package/tests/vector-migration.test.mjs +810 -810
- package/tests/vector-profile.test.mjs +449 -449
- package/tests/visibility-migration.test.mjs +152 -152
- package/tests/webui-auth.test.mjs +963 -963
- package/tests/webui.test.mjs +421 -421
- package/tests/windows-env.test.mjs +89 -89
- package/tests/worker-lifecycle.test.mjs +1522 -1429
package/lib/visibility.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
// Visibility used to have three levels: `shared`, `session` (a lease on the one
|
|
2
|
-
// conversation that wrote it) and `secret`. The session level is gone.
|
|
3
|
-
//
|
|
4
|
-
// It could never answer the question people actually ask — "can the same character in
|
|
5
|
-
// another conversation read this?" — because a lease that dies with its conversation
|
|
6
|
-
// is wrong in both of its states: while that conversation is alive it hides the memory
|
|
7
|
-
// from every other conversation of the same character (breaking continuity), and once
|
|
8
|
-
// the conversation is deleted it falls back to the whole folder (protecting nothing).
|
|
9
|
-
// Anything that has to stay out of another conversation is expressed with `context`
|
|
10
|
-
// (channelId / characterId / worldId / branchId) instead: that survives conversation
|
|
11
|
-
// deletion, and it is the only dimension the reader checks.
|
|
12
|
-
//
|
|
13
|
-
// Stored data from an older version is still read here, so a library that has not been
|
|
14
|
-
// rewritten yet behaves exactly like a migrated one: `session` is read as `shared`, and
|
|
15
|
-
// the entry keeps a marker saying where it came from.
|
|
16
|
-
export const STORED_VISIBILITIES = ['shared', 'secret']
|
|
17
|
-
export const LEGACY_SESSION = 'session'
|
|
18
|
-
|
|
19
|
-
export function isLegacySession(entry) {
|
|
20
|
-
return entry?.visibility === LEGACY_SESSION
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Rewrites one entry in place. The timestamp is recorded so a reader can tell a memory
|
|
24
|
-
// that was always shared from one that inherited its folder during the upgrade.
|
|
25
|
-
export function migrateEntryVisibility(entry, now) {
|
|
26
|
-
if (!entry || typeof entry !== 'object') return false
|
|
27
|
-
let changed = false
|
|
28
|
-
if (isLegacySession(entry)) {
|
|
29
|
-
entry.visibility = 'shared'
|
|
30
|
-
entry.migratedFromVisibility = LEGACY_SESSION
|
|
31
|
-
entry.visibilityMigratedAt = now
|
|
32
|
-
changed = true
|
|
33
|
-
}
|
|
34
|
-
// `sessionId` meant nothing outside the lease it belonged to; older writes also left
|
|
35
|
-
// `sessionId: null` on ordinary entries. Either way it is a dead pointer, and a later
|
|
36
|
-
// reader must not mistake it for a live scope.
|
|
37
|
-
if ('sessionId' in entry) {
|
|
38
|
-
delete entry.sessionId
|
|
39
|
-
changed = true
|
|
40
|
-
}
|
|
41
|
-
return changed
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function migrateIndexVisibility(index, now = new Date().toISOString()) {
|
|
45
|
-
const entries = index?.entries
|
|
46
|
-
if (!entries || typeof entries !== 'object') return 0
|
|
47
|
-
let migrated = 0
|
|
48
|
-
for (const entry of Object.values(entries)) if (migrateEntryVisibility(entry, now)) migrated += 1
|
|
49
|
-
return migrated
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Counted against the raw file, before load-time normalization, so a pass can tell a
|
|
53
|
-
// library that still needs rewriting from one that is already migrated. A leftover
|
|
54
|
-
// `sessionId` counts: it is the same old shape, just without the level that used it.
|
|
55
|
-
export function countLegacyInRaw(raw) {
|
|
56
|
-
const entries = raw?.entries
|
|
57
|
-
if (!entries || typeof entries !== 'object') return 0
|
|
58
|
-
return Object.values(entries).filter((entry) => isLegacySession(entry) || (entry && 'sessionId' in entry)).length
|
|
59
|
-
}
|
|
1
|
+
// Visibility used to have three levels: `shared`, `session` (a lease on the one
|
|
2
|
+
// conversation that wrote it) and `secret`. The session level is gone.
|
|
3
|
+
//
|
|
4
|
+
// It could never answer the question people actually ask — "can the same character in
|
|
5
|
+
// another conversation read this?" — because a lease that dies with its conversation
|
|
6
|
+
// is wrong in both of its states: while that conversation is alive it hides the memory
|
|
7
|
+
// from every other conversation of the same character (breaking continuity), and once
|
|
8
|
+
// the conversation is deleted it falls back to the whole folder (protecting nothing).
|
|
9
|
+
// Anything that has to stay out of another conversation is expressed with `context`
|
|
10
|
+
// (channelId / characterId / worldId / branchId) instead: that survives conversation
|
|
11
|
+
// deletion, and it is the only dimension the reader checks.
|
|
12
|
+
//
|
|
13
|
+
// Stored data from an older version is still read here, so a library that has not been
|
|
14
|
+
// rewritten yet behaves exactly like a migrated one: `session` is read as `shared`, and
|
|
15
|
+
// the entry keeps a marker saying where it came from.
|
|
16
|
+
export const STORED_VISIBILITIES = ['shared', 'secret']
|
|
17
|
+
export const LEGACY_SESSION = 'session'
|
|
18
|
+
|
|
19
|
+
export function isLegacySession(entry) {
|
|
20
|
+
return entry?.visibility === LEGACY_SESSION
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Rewrites one entry in place. The timestamp is recorded so a reader can tell a memory
|
|
24
|
+
// that was always shared from one that inherited its folder during the upgrade.
|
|
25
|
+
export function migrateEntryVisibility(entry, now) {
|
|
26
|
+
if (!entry || typeof entry !== 'object') return false
|
|
27
|
+
let changed = false
|
|
28
|
+
if (isLegacySession(entry)) {
|
|
29
|
+
entry.visibility = 'shared'
|
|
30
|
+
entry.migratedFromVisibility = LEGACY_SESSION
|
|
31
|
+
entry.visibilityMigratedAt = now
|
|
32
|
+
changed = true
|
|
33
|
+
}
|
|
34
|
+
// `sessionId` meant nothing outside the lease it belonged to; older writes also left
|
|
35
|
+
// `sessionId: null` on ordinary entries. Either way it is a dead pointer, and a later
|
|
36
|
+
// reader must not mistake it for a live scope.
|
|
37
|
+
if ('sessionId' in entry) {
|
|
38
|
+
delete entry.sessionId
|
|
39
|
+
changed = true
|
|
40
|
+
}
|
|
41
|
+
return changed
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function migrateIndexVisibility(index, now = new Date().toISOString()) {
|
|
45
|
+
const entries = index?.entries
|
|
46
|
+
if (!entries || typeof entries !== 'object') return 0
|
|
47
|
+
let migrated = 0
|
|
48
|
+
for (const entry of Object.values(entries)) if (migrateEntryVisibility(entry, now)) migrated += 1
|
|
49
|
+
return migrated
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Counted against the raw file, before load-time normalization, so a pass can tell a
|
|
53
|
+
// library that still needs rewriting from one that is already migrated. A leftover
|
|
54
|
+
// `sessionId` counts: it is the same old shape, just without the level that used it.
|
|
55
|
+
export function countLegacyInRaw(raw) {
|
|
56
|
+
const entries = raw?.entries
|
|
57
|
+
if (!entries || typeof entries !== 'object') return 0
|
|
58
|
+
return Object.values(entries).filter((entry) => isLegacySession(entry) || (entry && 'sessionId' in entry)).length
|
|
59
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
graph-view.bundle.js:
|
|
1
|
+
graph-view.bundle.js: no third-party runtime dependencies.
|
|
@@ -1,2 +1,2 @@
|
|
|
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 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);})();
|
|
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 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);})();
|