kynjal-cli 4.0.0 → 4.0.1
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/dist/src/appliance/gguf-engine.d.ts +91 -0
- package/dist/src/appliance/gguf-engine.d.ts.map +1 -0
- package/dist/src/appliance/gguf-engine.js +286 -525
- package/dist/src/appliance/gguf-engine.js.map +1 -1
- package/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
- package/dist/src/appliance/ruvllm-bridge.d.ts.map +1 -0
- package/dist/src/appliance/ruvllm-bridge.js +203 -403
- package/dist/src/appliance/ruvllm-bridge.js.map +1 -1
- package/dist/src/appliance/rvfa-builder.d.ts +44 -0
- package/dist/src/appliance/rvfa-builder.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-builder.js +154 -208
- package/dist/src/appliance/rvfa-builder.js.map +1 -1
- package/dist/src/appliance/rvfa-distribution.d.ts +97 -0
- package/dist/src/appliance/rvfa-distribution.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-distribution.js +260 -423
- package/dist/src/appliance/rvfa-distribution.js.map +1 -1
- package/dist/src/appliance/rvfa-format.d.ts +111 -0
- package/dist/src/appliance/rvfa-format.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-format.js +128 -200
- package/dist/src/appliance/rvfa-format.js.map +1 -1
- package/dist/src/appliance/rvfa-runner.d.ts +69 -0
- package/dist/src/appliance/rvfa-runner.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-runner.js +168 -304
- package/dist/src/appliance/rvfa-runner.js.map +1 -1
- package/dist/src/appliance/rvfa-signing.d.ts +123 -0
- package/dist/src/appliance/rvfa-signing.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-signing.js +173 -295
- package/dist/src/appliance/rvfa-signing.js.map +1 -1
- package/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/dist/src/benchmarks/pretrain/index.d.ts.map +1 -0
- package/dist/src/benchmarks/pretrain/index.js +331 -542
- package/dist/src/benchmarks/pretrain/index.js.map +1 -1
- package/dist/src/commands/agent.js +574 -697
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.js +1218 -1548
- package/dist/src/commands/analyze.js.map +1 -1
- package/dist/src/commands/appliance-advanced.js +158 -267
- package/dist/src/commands/appliance-advanced.js.map +1 -1
- package/dist/src/commands/appliance.js +318 -493
- package/dist/src/commands/appliance.js.map +1 -1
- package/dist/src/commands/benchmark.js +372 -523
- package/dist/src/commands/benchmark.js.map +1 -1
- package/dist/src/commands/claims.js +274 -364
- package/dist/src/commands/claims.js.map +1 -1
- package/dist/src/commands/cleanup.js +113 -157
- package/dist/src/commands/cleanup.js.map +1 -1
- package/dist/src/commands/completions.js +477 -118
- package/dist/src/commands/completions.js.map +1 -1
- package/dist/src/commands/config.js +237 -303
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.js +487 -596
- package/dist/src/commands/daemon.js.map +1 -1
- package/dist/src/commands/deployment.js +194 -275
- package/dist/src/commands/deployment.js.map +1 -1
- package/dist/src/commands/doctor.js +504 -686
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/embeddings.js +1293 -1543
- package/dist/src/commands/embeddings.js.map +1 -1
- package/dist/src/commands/guidance.js +449 -596
- package/dist/src/commands/guidance.js.map +1 -1
- package/dist/src/commands/hive-mind.js +854 -938
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.js +3112 -3519
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +115 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +126 -308
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/init.js +788 -940
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/issues.js +383 -558
- package/dist/src/commands/issues.js.map +1 -1
- package/dist/src/commands/mcp.js +493 -605
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.js +833 -1026
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +282 -347
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/neural.js +1289 -1563
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/commands/performance.js +497 -643
- package/dist/src/commands/performance.js.map +1 -1
- package/dist/src/commands/plugins.js +668 -841
- package/dist/src/commands/plugins.js.map +1 -1
- package/dist/src/commands/process.js +392 -447
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/progress.js +162 -256
- package/dist/src/commands/progress.js.map +1 -1
- package/dist/src/commands/providers.js +150 -220
- package/dist/src/commands/providers.js.map +1 -1
- package/dist/src/commands/route.js +520 -665
- package/dist/src/commands/route.js.map +1 -1
- package/dist/src/commands/ruvector/backup.js +505 -651
- package/dist/src/commands/ruvector/backup.js.map +1 -1
- package/dist/src/commands/ruvector/benchmark.js +349 -401
- package/dist/src/commands/ruvector/benchmark.js.map +1 -1
- package/dist/src/commands/ruvector/import.js +224 -266
- package/dist/src/commands/ruvector/import.js.map +1 -1
- package/dist/src/commands/ruvector/index.js +37 -75
- package/dist/src/commands/ruvector/index.js.map +1 -1
- package/dist/src/commands/ruvector/init.js +336 -359
- package/dist/src/commands/ruvector/init.js.map +1 -1
- package/dist/src/commands/ruvector/migrate.js +335 -322
- package/dist/src/commands/ruvector/migrate.js.map +1 -1
- package/dist/src/commands/ruvector/optimize.js +375 -431
- package/dist/src/commands/ruvector/optimize.js.map +1 -1
- package/dist/src/commands/ruvector/setup.js +703 -117
- package/dist/src/commands/ruvector/setup.js.map +1 -1
- package/dist/src/commands/ruvector/status.js +364 -419
- package/dist/src/commands/ruvector/status.js.map +1 -1
- package/dist/src/commands/security.js +485 -608
- package/dist/src/commands/security.js.map +1 -1
- package/dist/src/commands/session.js +504 -626
- package/dist/src/commands/session.js.map +1 -1
- package/dist/src/commands/start.js +267 -364
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.js +380 -486
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +408 -488
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/task.js +423 -538
- package/dist/src/commands/task.js.map +1 -1
- package/dist/src/commands/transfer-store.js +322 -412
- package/dist/src/commands/transfer-store.js.map +1 -1
- package/dist/src/commands/update.js +196 -291
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/workflow.js +386 -486
- package/dist/src/commands/workflow.js.map +1 -1
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +38 -39
- package/dist/src/config-adapter.js.map +1 -1
- package/dist/src/index.d.ts +77 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +309 -411
- package/dist/src/index.js.map +1 -1
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +246 -507
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts +25 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +368 -78
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts +41 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +1307 -996
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts +60 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +657 -12
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/index.d.ts +1 -1
- package/dist/src/init/index.d.ts.map +1 -1
- package/dist/src/init/index.js +1 -1
- package/dist/src/init/index.js.map +1 -1
- package/dist/src/init/mcp-generator.js +33 -37
- package/dist/src/init/mcp-generator.js.map +1 -1
- package/dist/src/init/settings-generator.js +76 -77
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/init/statusline-generator.js +801 -3
- package/dist/src/init/statusline-generator.js.map +1 -1
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/init/types.js +76 -59
- package/dist/src/init/types.js.map +1 -1
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +81 -125
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts +161 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +470 -757
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +391 -492
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/agentdb-tools.js +332 -533
- package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.js +172 -236
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
- package/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/dist/src/mcp-tools/auto-install.d.ts.map +1 -0
- package/dist/src/mcp-tools/auto-install.js +80 -142
- package/dist/src/mcp-tools/auto-install.js.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +252 -375
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/claims-tools.js +473 -565
- package/dist/src/mcp-tools/claims-tools.js.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +197 -272
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/coordination-tools.js +500 -572
- package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
- package/dist/src/mcp-tools/daa-tools.js +286 -364
- package/dist/src/mcp-tools/daa-tools.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +582 -693
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/mcp-tools/github-tools.js +260 -311
- package/dist/src/mcp-tools/github-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.js +573 -640
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +2215 -2648
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +350 -505
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/neural-tools.js +315 -412
- package/dist/src/mcp-tools/neural-tools.js.map +1 -1
- package/dist/src/mcp-tools/performance-tools.js +420 -480
- package/dist/src/mcp-tools/performance-tools.js.map +1 -1
- package/dist/src/mcp-tools/progress-tools.js +204 -278
- package/dist/src/mcp-tools/progress-tools.js.map +1 -1
- package/dist/src/mcp-tools/ruvllm-tools.js +163 -279
- package/dist/src/mcp-tools/ruvllm-tools.js.map +1 -1
- package/dist/src/mcp-tools/security-tools.js +297 -429
- package/dist/src/mcp-tools/security-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.js +185 -234
- package/dist/src/mcp-tools/session-tools.js.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +207 -260
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/system-tools.js +276 -325
- package/dist/src/mcp-tools/system-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.js +270 -336
- package/dist/src/mcp-tools/task-tools.js.map +1 -1
- package/dist/src/mcp-tools/terminal-tools.js +148 -196
- package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
- package/dist/src/mcp-tools/transfer-tools.js +186 -333
- package/dist/src/mcp-tools/transfer-tools.js.map +1 -1
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/wasm-agent-tools.js +133 -280
- package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/workflow-tools.js +405 -450
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
- package/dist/src/memory/ewc-consolidation.d.ts +295 -0
- package/dist/src/memory/ewc-consolidation.d.ts.map +1 -0
- package/dist/src/memory/ewc-consolidation.js +190 -303
- package/dist/src/memory/ewc-consolidation.js.map +1 -1
- package/dist/src/memory/intelligence.d.ts +338 -0
- package/dist/src/memory/intelligence.d.ts.map +1 -0
- package/dist/src/memory/intelligence.js +569 -794
- package/dist/src/memory/intelligence.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +407 -0
- package/dist/src/memory/memory-bridge.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge.js +1170 -1640
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-initializer.d.ts +412 -0
- package/dist/src/memory/memory-initializer.d.ts.map +1 -0
- package/dist/src/memory/memory-initializer.js +1836 -1851
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/dist/src/memory/sona-optimizer.d.ts.map +1 -0
- package/dist/src/memory/sona-optimizer.js +199 -329
- package/dist/src/memory/sona-optimizer.js.map +1 -1
- package/dist/src/output.d.ts +2 -2
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +242 -272
- package/dist/src/output.js.map +1 -1
- package/dist/src/parser.d.ts +51 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +140 -187
- package/dist/src/parser.js.map +1 -1
- package/dist/src/plugins/manager.d.ts +133 -0
- package/dist/src/plugins/manager.d.ts.map +1 -0
- package/dist/src/plugins/manager.js +285 -521
- package/dist/src/plugins/manager.js.map +1 -1
- package/dist/src/plugins/store/discovery.d.ts +88 -0
- package/dist/src/plugins/store/discovery.d.ts.map +1 -0
- package/dist/src/plugins/store/discovery.js +271 -358
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/plugins/store/index.d.ts +76 -0
- package/dist/src/plugins/store/index.d.ts.map +1 -0
- package/dist/src/plugins/store/index.js +48 -105
- package/dist/src/plugins/store/index.js.map +1 -1
- package/dist/src/plugins/store/search.d.ts +46 -0
- package/dist/src/plugins/store/search.d.ts.map +1 -0
- package/dist/src/plugins/store/search.js +69 -107
- package/dist/src/plugins/store/search.js.map +1 -1
- package/dist/src/plugins/store/types.d.ts +274 -0
- package/dist/src/plugins/store/types.d.ts.map +1 -0
- package/dist/src/plugins/tests/demo-plugin-store.js +113 -160
- package/dist/src/plugins/tests/demo-plugin-store.js.map +1 -1
- package/dist/src/plugins/tests/standalone-test.js +172 -223
- package/dist/src/plugins/tests/standalone-test.js.map +1 -1
- package/dist/src/plugins/tests/test-plugin-store.js +190 -228
- package/dist/src/plugins/tests/test-plugin-store.js.map +1 -1
- package/dist/src/production/circuit-breaker.d.ts +101 -0
- package/dist/src/production/circuit-breaker.d.ts.map +1 -0
- package/dist/src/production/circuit-breaker.js +62 -126
- package/dist/src/production/circuit-breaker.js.map +1 -1
- package/dist/src/production/error-handler.d.ts +92 -0
- package/dist/src/production/error-handler.d.ts.map +1 -0
- package/dist/src/production/error-handler.js +86 -156
- package/dist/src/production/error-handler.js.map +1 -1
- package/dist/src/production/monitoring.d.ts +161 -0
- package/dist/src/production/monitoring.d.ts.map +1 -0
- package/dist/src/production/monitoring.js +139 -220
- package/dist/src/production/monitoring.js.map +1 -1
- package/dist/src/production/rate-limiter.d.ts +80 -0
- package/dist/src/production/rate-limiter.d.ts.map +1 -0
- package/dist/src/production/rate-limiter.js +74 -93
- package/dist/src/production/rate-limiter.js.map +1 -1
- package/dist/src/production/retry.d.ts +48 -0
- package/dist/src/production/retry.d.ts.map +1 -0
- package/dist/src/production/retry.js +75 -167
- package/dist/src/production/retry.js.map +1 -1
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +436 -560
- package/dist/src/prompt.js.map +1 -1
- package/dist/src/runtime/headless.d.ts +60 -0
- package/dist/src/runtime/headless.d.ts.map +1 -0
- package/dist/src/runtime/headless.js +197 -286
- package/dist/src/runtime/headless.js.map +1 -1
- package/dist/src/ruvector/agent-wasm.d.ts +182 -0
- package/dist/src/ruvector/agent-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/agent-wasm.js +156 -351
- package/dist/src/ruvector/agent-wasm.js.map +1 -1
- package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/ast-analyzer.js +145 -232
- package/dist/src/ruvector/ast-analyzer.js.map +1 -1
- package/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-router.js +287 -419
- package/dist/src/ruvector/coverage-router.js.map +1 -1
- package/dist/src/ruvector/coverage-tools.js +56 -101
- package/dist/src/ruvector/coverage-tools.js.map +1 -1
- package/dist/src/ruvector/diff-classifier.d.ts +175 -0
- package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
- package/dist/src/ruvector/diff-classifier.js +324 -451
- package/dist/src/ruvector/diff-classifier.js.map +1 -1
- package/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/dist/src/ruvector/enhanced-model-router.d.ts.map +1 -0
- package/dist/src/ruvector/enhanced-model-router.js +260 -336
- package/dist/src/ruvector/enhanced-model-router.js.map +1 -1
- package/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/dist/src/ruvector/flash-attention.d.ts.map +1 -0
- package/dist/src/ruvector/flash-attention.js +223 -254
- package/dist/src/ruvector/flash-attention.js.map +1 -1
- package/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/graph-analyzer.js +486 -680
- package/dist/src/ruvector/graph-analyzer.js.map +1 -1
- package/dist/src/ruvector/index.d.ts +40 -0
- package/dist/src/ruvector/index.d.ts.map +1 -0
- package/dist/src/ruvector/index.js +36 -106
- package/dist/src/ruvector/index.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -0
- package/dist/src/ruvector/lora-adapter.js +155 -248
- package/dist/src/ruvector/lora-adapter.js.map +1 -1
- package/dist/src/ruvector/model-router.d.ts +220 -0
- package/dist/src/ruvector/model-router.d.ts.map +1 -0
- package/dist/src/ruvector/model-router.js +175 -248
- package/dist/src/ruvector/model-router.js.map +1 -1
- package/dist/src/ruvector/moe-router.d.ts +206 -0
- package/dist/src/ruvector/moe-router.d.ts.map +1 -0
- package/dist/src/ruvector/moe-router.js +228 -286
- package/dist/src/ruvector/moe-router.js.map +1 -1
- package/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
- package/dist/src/ruvector/q-learning-router.js +257 -338
- package/dist/src/ruvector/q-learning-router.js.map +1 -1
- package/dist/src/ruvector/ruvllm-wasm.d.ts +179 -0
- package/dist/src/ruvector/ruvllm-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/ruvllm-wasm.js +270 -434
- package/dist/src/ruvector/ruvllm-wasm.js.map +1 -1
- package/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/dist/src/ruvector/semantic-router.d.ts.map +1 -0
- package/dist/src/ruvector/semantic-router.js +60 -67
- package/dist/src/ruvector/semantic-router.js.map +1 -1
- package/dist/src/ruvector/vector-db.d.ts +69 -0
- package/dist/src/ruvector/vector-db.d.ts.map +1 -0
- package/dist/src/ruvector/vector-db.js +119 -205
- package/dist/src/ruvector/vector-db.js.map +1 -1
- package/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/dist/src/services/agentic-flow-bridge.d.ts.map +1 -0
- package/dist/src/services/agentic-flow-bridge.js +32 -105
- package/dist/src/services/agentic-flow-bridge.js.map +1 -1
- package/dist/src/services/claim-service.d.ts +204 -0
- package/dist/src/services/claim-service.d.ts.map +1 -0
- package/dist/src/services/claim-service.js +615 -940
- package/dist/src/services/claim-service.js.map +1 -1
- package/dist/src/services/container-worker-pool.d.ts +197 -0
- package/dist/src/services/container-worker-pool.d.ts.map +1 -0
- package/dist/src/services/container-worker-pool.js +398 -666
- package/dist/src/services/container-worker-pool.js.map +1 -1
- package/dist/src/services/headless-worker-executor.d.ts +304 -0
- package/dist/src/services/headless-worker-executor.d.ts.map +1 -0
- package/dist/src/services/headless-worker-executor.js +441 -467
- package/dist/src/services/headless-worker-executor.js.map +1 -1
- package/dist/src/services/index.d.ts +4 -4
- package/dist/src/services/index.d.ts.map +1 -1
- package/dist/src/services/index.js +4 -4
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/services/registry-api.d.ts +58 -0
- package/dist/src/services/registry-api.d.ts.map +1 -0
- package/dist/src/services/registry-api.js +92 -200
- package/dist/src/services/registry-api.js.map +1 -1
- package/dist/src/services/ruvector-training.d.ts +222 -0
- package/dist/src/services/ruvector-training.d.ts.map +1 -0
- package/dist/src/services/ruvector-training.js +257 -337
- package/dist/src/services/ruvector-training.js.map +1 -1
- package/dist/src/services/worker-daemon.d.ts +228 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +591 -849
- package/dist/src/services/worker-daemon.js.map +1 -1
- package/dist/src/services/worker-queue.d.ts +194 -0
- package/dist/src/services/worker-queue.d.ts.map +1 -0
- package/dist/src/services/worker-queue.js +331 -548
- package/dist/src/services/worker-queue.js.map +1 -1
- package/dist/src/suggest.d.ts +53 -0
- package/dist/src/suggest.d.ts.map +1 -0
- package/dist/src/suggest.js +45 -55
- package/dist/src/suggest.js.map +1 -1
- package/dist/src/transfer/anonymization/index.js +29 -37
- package/dist/src/transfer/anonymization/index.js.map +1 -1
- package/dist/src/transfer/deploy-seraphine.js +128 -155
- package/dist/src/transfer/deploy-seraphine.js.map +1 -1
- package/dist/src/transfer/export.d.ts +25 -0
- package/dist/src/transfer/export.d.ts.map +1 -0
- package/dist/src/transfer/export.js +84 -142
- package/dist/src/transfer/export.js.map +1 -1
- package/dist/src/transfer/index.d.ts +1 -1
- package/dist/src/transfer/index.d.ts.map +1 -1
- package/dist/src/transfer/index.js +0 -2
- package/dist/src/transfer/index.js.map +1 -1
- package/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/dist/src/transfer/ipfs/client.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/client.js +187 -337
- package/dist/src/transfer/ipfs/client.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/dist/src/transfer/ipfs/upload.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/upload.js +288 -434
- package/dist/src/transfer/ipfs/upload.js.map +1 -1
- package/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/dist/src/transfer/models/seraphine.d.ts.map +1 -0
- package/dist/src/transfer/models/seraphine.js +55 -55
- package/dist/src/transfer/models/seraphine.js.map +1 -1
- package/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/dist/src/transfer/serialization/cfp.d.ts.map +1 -0
- package/dist/src/transfer/serialization/cfp.js +30 -31
- package/dist/src/transfer/serialization/cfp.js.map +1 -1
- package/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/dist/src/transfer/storage/gcs.d.ts.map +1 -0
- package/dist/src/transfer/storage/gcs.js +165 -232
- package/dist/src/transfer/storage/gcs.js.map +1 -1
- package/dist/src/transfer/store/discovery.d.ts +84 -0
- package/dist/src/transfer/store/discovery.d.ts.map +1 -0
- package/dist/src/transfer/store/discovery.js +239 -349
- package/dist/src/transfer/store/discovery.js.map +1 -1
- package/dist/src/transfer/store/download.d.ts +70 -0
- package/dist/src/transfer/store/download.d.ts.map +1 -0
- package/dist/src/transfer/store/download.js +243 -365
- package/dist/src/transfer/store/download.js.map +1 -1
- package/dist/src/transfer/store/index.d.ts +84 -0
- package/dist/src/transfer/store/index.d.ts.map +1 -0
- package/dist/src/transfer/store/index.js +63 -130
- package/dist/src/transfer/store/index.js.map +1 -1
- package/dist/src/transfer/store/publish.d.ts +76 -0
- package/dist/src/transfer/store/publish.d.ts.map +1 -0
- package/dist/src/transfer/store/publish.js +184 -258
- package/dist/src/transfer/store/publish.js.map +1 -1
- package/dist/src/transfer/store/registry.js +50 -72
- package/dist/src/transfer/store/registry.js.map +1 -1
- package/dist/src/transfer/store/search.d.ts +54 -0
- package/dist/src/transfer/store/search.d.ts.map +1 -0
- package/dist/src/transfer/store/search.js +64 -96
- package/dist/src/transfer/store/search.js.map +1 -1
- package/dist/src/transfer/store/tests/standalone-test.js +174 -231
- package/dist/src/transfer/store/tests/standalone-test.js.map +1 -1
- package/dist/src/transfer/test-seraphine.js +95 -130
- package/dist/src/transfer/test-seraphine.js.map +1 -1
- package/dist/src/transfer/tests/test-store.js +194 -239
- package/dist/src/transfer/tests/test-store.js.map +1 -1
- package/dist/src/transfer/types.d.ts +245 -0
- package/dist/src/transfer/types.d.ts.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +26 -55
- package/dist/src/types.js.map +1 -1
- package/dist/src/update/checker.d.ts +34 -0
- package/dist/src/update/checker.d.ts.map +1 -0
- package/dist/src/update/checker.js +106 -183
- package/dist/src/update/checker.js.map +1 -1
- package/dist/src/update/executor.d.ts +32 -0
- package/dist/src/update/executor.d.ts.map +1 -0
- package/dist/src/update/executor.js +135 -198
- package/dist/src/update/executor.js.map +1 -1
- package/dist/src/update/index.d.ts +33 -0
- package/dist/src/update/index.d.ts.map +1 -0
- package/dist/src/update/index.js +38 -85
- package/dist/src/update/index.js.map +1 -1
- package/dist/src/update/rate-limiter.d.ts +20 -0
- package/dist/src/update/rate-limiter.d.ts.map +1 -0
- package/dist/src/update/rate-limiter.js +19 -31
- package/dist/src/update/rate-limiter.js.map +1 -1
- package/dist/src/update/validator.d.ts +17 -0
- package/dist/src/update/validator.d.ts.map +1 -0
- package/dist/src/update/validator.js +38 -64
- package/dist/src/update/validator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -15,68 +15,12 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module moe-router
|
|
17
17
|
*/
|
|
18
|
-
var __assign = (this && this.__assign) || function () {
|
|
19
|
-
__assign = Object.assign || function(t) {
|
|
20
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
-
s = arguments[i];
|
|
22
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
23
|
-
t[p] = s[p];
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
};
|
|
27
|
-
return __assign.apply(this, arguments);
|
|
28
|
-
};
|
|
29
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
30
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
39
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
40
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
41
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
42
|
-
function step(op) {
|
|
43
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
44
|
-
while (_) try {
|
|
45
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
46
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
47
|
-
switch (op[0]) {
|
|
48
|
-
case 0: case 1: t = op; break;
|
|
49
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
50
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
51
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
52
|
-
default:
|
|
53
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
54
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
55
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
56
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
57
|
-
if (t[2]) _.ops.pop();
|
|
58
|
-
_.trys.pop(); continue;
|
|
59
|
-
}
|
|
60
|
-
op = body.call(thisArg, _);
|
|
61
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
62
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
18
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
75
19
|
import { dirname } from 'path';
|
|
76
20
|
/**
|
|
77
21
|
* Expert names in order (index corresponds to expert slot)
|
|
78
22
|
*/
|
|
79
|
-
export
|
|
23
|
+
export const EXPERT_NAMES = [
|
|
80
24
|
'coder',
|
|
81
25
|
'tester',
|
|
82
26
|
'reviewer',
|
|
@@ -89,19 +33,19 @@ export var EXPERT_NAMES = [
|
|
|
89
33
|
/**
|
|
90
34
|
* Number of experts (fixed at 8)
|
|
91
35
|
*/
|
|
92
|
-
export
|
|
36
|
+
export const NUM_EXPERTS = 8;
|
|
93
37
|
/**
|
|
94
38
|
* Input dimension (384 from ONNX MiniLM-L6-v2)
|
|
95
39
|
*/
|
|
96
|
-
export
|
|
40
|
+
export const INPUT_DIM = 384;
|
|
97
41
|
/**
|
|
98
42
|
* Hidden layer dimension
|
|
99
43
|
*/
|
|
100
|
-
export
|
|
44
|
+
export const HIDDEN_DIM = 128;
|
|
101
45
|
/**
|
|
102
46
|
* Default configuration
|
|
103
47
|
*/
|
|
104
|
-
|
|
48
|
+
const DEFAULT_CONFIG = {
|
|
105
49
|
topK: 2,
|
|
106
50
|
learningRate: 0.01,
|
|
107
51
|
temperature: 1.0,
|
|
@@ -109,7 +53,7 @@ var DEFAULT_CONFIG = {
|
|
|
109
53
|
weightsPath: '.swarm/moe-weights.json',
|
|
110
54
|
autoSaveInterval: 50,
|
|
111
55
|
enableNoise: true,
|
|
112
|
-
noiseStd: 0.1
|
|
56
|
+
noiseStd: 0.1,
|
|
113
57
|
};
|
|
114
58
|
// ============================================================================
|
|
115
59
|
// Matrix Operations
|
|
@@ -118,13 +62,13 @@ var DEFAULT_CONFIG = {
|
|
|
118
62
|
* Initialize weights using Xavier/Glorot initialization
|
|
119
63
|
*/
|
|
120
64
|
function xavierInit(fanIn, fanOut) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
for (
|
|
65
|
+
const std = Math.sqrt(2.0 / (fanIn + fanOut));
|
|
66
|
+
const weights = new Float32Array(fanIn * fanOut);
|
|
67
|
+
for (let i = 0; i < weights.length; i++) {
|
|
124
68
|
// Box-Muller transform for normal distribution
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
69
|
+
const u1 = Math.random();
|
|
70
|
+
const u2 = Math.random();
|
|
71
|
+
const z = Math.sqrt(-2 * Math.log(u1 + 1e-8)) * Math.cos(2 * Math.PI * u2);
|
|
128
72
|
weights[i] = z * std;
|
|
129
73
|
}
|
|
130
74
|
return weights;
|
|
@@ -134,11 +78,11 @@ function xavierInit(fanIn, fanOut) {
|
|
|
134
78
|
* W is stored row-major: [rows * cols]
|
|
135
79
|
*/
|
|
136
80
|
function matmul(W, x, rows, cols, out) {
|
|
137
|
-
for (
|
|
138
|
-
|
|
139
|
-
|
|
81
|
+
for (let i = 0; i < rows; i++) {
|
|
82
|
+
let sum = 0;
|
|
83
|
+
const rowOffset = i * cols;
|
|
140
84
|
// 4x loop unrolling for SIMD-friendly access
|
|
141
|
-
|
|
85
|
+
let j = 0;
|
|
142
86
|
for (; j + 3 < cols; j += 4) {
|
|
143
87
|
sum +=
|
|
144
88
|
W[rowOffset + j] * x[j] +
|
|
@@ -157,7 +101,7 @@ function matmul(W, x, rows, cols, out) {
|
|
|
157
101
|
* Vector addition: y = x + b
|
|
158
102
|
*/
|
|
159
103
|
function addBias(x, b, out) {
|
|
160
|
-
for (
|
|
104
|
+
for (let i = 0; i < x.length; i++) {
|
|
161
105
|
out[i] = x[i] + b[i];
|
|
162
106
|
}
|
|
163
107
|
}
|
|
@@ -165,7 +109,7 @@ function addBias(x, b, out) {
|
|
|
165
109
|
* ReLU activation: y = max(0, x)
|
|
166
110
|
*/
|
|
167
111
|
function relu(x, out) {
|
|
168
|
-
for (
|
|
112
|
+
for (let i = 0; i < x.length; i++) {
|
|
169
113
|
out[i] = x[i] > 0 ? x[i] : 0;
|
|
170
114
|
}
|
|
171
115
|
}
|
|
@@ -174,20 +118,20 @@ function relu(x, out) {
|
|
|
174
118
|
*/
|
|
175
119
|
function softmax(x, temperature, out) {
|
|
176
120
|
// Find max for numerical stability
|
|
177
|
-
|
|
178
|
-
for (
|
|
121
|
+
let maxVal = x[0];
|
|
122
|
+
for (let i = 1; i < x.length; i++) {
|
|
179
123
|
if (x[i] > maxVal)
|
|
180
124
|
maxVal = x[i];
|
|
181
125
|
}
|
|
182
126
|
// Compute exp and sum
|
|
183
|
-
|
|
184
|
-
for (
|
|
127
|
+
let sum = 0;
|
|
128
|
+
for (let i = 0; i < x.length; i++) {
|
|
185
129
|
out[i] = Math.exp((x[i] - maxVal) / temperature);
|
|
186
130
|
sum += out[i];
|
|
187
131
|
}
|
|
188
132
|
// Normalize
|
|
189
|
-
|
|
190
|
-
for (
|
|
133
|
+
const invSum = 1.0 / (sum + 1e-8);
|
|
134
|
+
for (let i = 0; i < x.length; i++) {
|
|
191
135
|
out[i] *= invSum;
|
|
192
136
|
}
|
|
193
137
|
}
|
|
@@ -195,8 +139,8 @@ function softmax(x, temperature, out) {
|
|
|
195
139
|
* Compute entropy of distribution: H = -sum(p * log(p))
|
|
196
140
|
*/
|
|
197
141
|
function entropy(p) {
|
|
198
|
-
|
|
199
|
-
for (
|
|
142
|
+
let h = 0;
|
|
143
|
+
for (let i = 0; i < p.length; i++) {
|
|
200
144
|
if (p[i] > 1e-8) {
|
|
201
145
|
h -= p[i] * Math.log(p[i]);
|
|
202
146
|
}
|
|
@@ -207,10 +151,10 @@ function entropy(p) {
|
|
|
207
151
|
* Add Gaussian noise for exploration
|
|
208
152
|
*/
|
|
209
153
|
function addNoise(x, std, out) {
|
|
210
|
-
for (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
154
|
+
for (let i = 0; i < x.length; i++) {
|
|
155
|
+
const u1 = Math.random();
|
|
156
|
+
const u2 = Math.random();
|
|
157
|
+
const z = Math.sqrt(-2 * Math.log(u1 + 1e-8)) * Math.cos(2 * Math.PI * u2);
|
|
214
158
|
out[i] = x[i] + z * std;
|
|
215
159
|
}
|
|
216
160
|
}
|
|
@@ -226,18 +170,39 @@ function addNoise(x, std, out) {
|
|
|
226
170
|
*
|
|
227
171
|
* Uses top-k expert selection with load balancing.
|
|
228
172
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
173
|
+
export class MoERouter {
|
|
174
|
+
config;
|
|
175
|
+
// Network weights (pre-allocated Float32Arrays)
|
|
176
|
+
W1; // [HIDDEN_DIM x INPUT_DIM]
|
|
177
|
+
b1; // [HIDDEN_DIM]
|
|
178
|
+
W2; // [NUM_EXPERTS x HIDDEN_DIM]
|
|
179
|
+
b2; // [NUM_EXPERTS]
|
|
180
|
+
// Intermediate buffers (pre-allocated, no GC pressure)
|
|
181
|
+
hidden; // [HIDDEN_DIM]
|
|
182
|
+
hiddenWithBias; // [HIDDEN_DIM]
|
|
183
|
+
hiddenActivated; // [HIDDEN_DIM]
|
|
184
|
+
logits; // [NUM_EXPERTS]
|
|
185
|
+
logitsWithBias; // [NUM_EXPERTS]
|
|
186
|
+
noisyLogits; // [NUM_EXPERTS]
|
|
187
|
+
probs; // [NUM_EXPERTS]
|
|
188
|
+
// Gradient buffers for online learning
|
|
189
|
+
gradW2; // [NUM_EXPERTS x HIDDEN_DIM]
|
|
190
|
+
gradb2; // [NUM_EXPERTS]
|
|
191
|
+
gradW1; // [HIDDEN_DIM x INPUT_DIM]
|
|
192
|
+
gradb1; // [HIDDEN_DIM]
|
|
193
|
+
gradHidden; // [HIDDEN_DIM]
|
|
194
|
+
// Statistics
|
|
195
|
+
routingCounts; // [NUM_EXPERTS]
|
|
196
|
+
totalRoutings = 0;
|
|
197
|
+
updateCount = 0;
|
|
198
|
+
avgReward = 0;
|
|
199
|
+
// Cache for last input (for gradient computation)
|
|
200
|
+
lastInput = null;
|
|
201
|
+
lastHiddenActivated = null;
|
|
202
|
+
lastProbs = null;
|
|
203
|
+
lastSelectedExperts = [];
|
|
204
|
+
constructor(config = {}) {
|
|
205
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
241
206
|
// Initialize weights
|
|
242
207
|
this.W1 = xavierInit(INPUT_DIM, HIDDEN_DIM);
|
|
243
208
|
this.b1 = new Float32Array(HIDDEN_DIM);
|
|
@@ -263,33 +228,23 @@ var MoERouter = /** @class */ (function () {
|
|
|
263
228
|
/**
|
|
264
229
|
* Initialize router, loading persisted weights if available
|
|
265
230
|
*/
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
switch (_a.label) {
|
|
270
|
-
case 0: return [4 /*yield*/, this.loadWeights()];
|
|
271
|
-
case 1:
|
|
272
|
-
_a.sent();
|
|
273
|
-
return [2 /*return*/];
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
};
|
|
231
|
+
async initialize() {
|
|
232
|
+
await this.loadWeights();
|
|
233
|
+
}
|
|
278
234
|
/**
|
|
279
235
|
* Route task to top-k experts based on embedding
|
|
280
236
|
*
|
|
281
237
|
* @param taskEmbedding - 384-dim task embedding from ONNX
|
|
282
238
|
* @returns Routing result with selected experts and weights
|
|
283
239
|
*/
|
|
284
|
-
|
|
285
|
-
var _this = this;
|
|
240
|
+
route(taskEmbedding) {
|
|
286
241
|
// Convert to Float32Array if needed
|
|
287
|
-
|
|
242
|
+
const input = taskEmbedding instanceof Float32Array
|
|
288
243
|
? taskEmbedding
|
|
289
244
|
: new Float32Array(taskEmbedding);
|
|
290
245
|
// Validate input dimension
|
|
291
246
|
if (input.length !== INPUT_DIM) {
|
|
292
|
-
throw new Error(
|
|
247
|
+
throw new Error(`Expected embedding dimension ${INPUT_DIM}, got ${input.length}`);
|
|
293
248
|
}
|
|
294
249
|
// Forward pass through gating network
|
|
295
250
|
// Layer 1: Linear + ReLU
|
|
@@ -309,14 +264,13 @@ var MoERouter = /** @class */ (function () {
|
|
|
309
264
|
// Softmax to get probabilities
|
|
310
265
|
softmax(this.noisyLogits, this.config.temperature, this.probs);
|
|
311
266
|
// Select top-k experts
|
|
312
|
-
|
|
267
|
+
const expertIndices = this.selectTopK(this.probs, this.config.topK);
|
|
313
268
|
// Compute load balance loss
|
|
314
|
-
|
|
269
|
+
const loadBalanceLoss = this.computeLoadBalanceLoss();
|
|
315
270
|
// Compute entropy
|
|
316
|
-
|
|
271
|
+
const routingEntropy = entropy(this.probs);
|
|
317
272
|
// Update statistics
|
|
318
|
-
for (
|
|
319
|
-
var idx = expertIndices_1[_i];
|
|
273
|
+
for (const idx of expertIndices) {
|
|
320
274
|
this.routingCounts[idx]++;
|
|
321
275
|
}
|
|
322
276
|
this.totalRoutings++;
|
|
@@ -326,20 +280,20 @@ var MoERouter = /** @class */ (function () {
|
|
|
326
280
|
this.lastProbs = new Float32Array(this.probs);
|
|
327
281
|
this.lastSelectedExperts = expertIndices;
|
|
328
282
|
// Build result
|
|
329
|
-
|
|
330
|
-
|
|
283
|
+
const totalWeight = expertIndices.reduce((sum, idx) => sum + this.probs[idx], 0);
|
|
284
|
+
const experts = expertIndices.map((idx) => ({
|
|
331
285
|
name: EXPERT_NAMES[idx],
|
|
332
286
|
index: idx,
|
|
333
|
-
weight:
|
|
334
|
-
score:
|
|
335
|
-
})
|
|
287
|
+
weight: this.probs[idx] / (totalWeight + 1e-8), // Normalize weights
|
|
288
|
+
score: this.probs[idx],
|
|
289
|
+
}));
|
|
336
290
|
return {
|
|
337
|
-
experts
|
|
291
|
+
experts,
|
|
338
292
|
allScores: Array.from(this.probs),
|
|
339
|
-
loadBalanceLoss
|
|
340
|
-
entropy: routingEntropy
|
|
293
|
+
loadBalanceLoss,
|
|
294
|
+
entropy: routingEntropy,
|
|
341
295
|
};
|
|
342
|
-
}
|
|
296
|
+
}
|
|
343
297
|
/**
|
|
344
298
|
* Update expert weights based on reward signal
|
|
345
299
|
*
|
|
@@ -349,10 +303,10 @@ var MoERouter = /** @class */ (function () {
|
|
|
349
303
|
* @param expert - Expert that received the reward
|
|
350
304
|
* @param reward - Reward signal (-1 to 1, positive = good)
|
|
351
305
|
*/
|
|
352
|
-
|
|
353
|
-
|
|
306
|
+
updateExpertWeights(expert, reward) {
|
|
307
|
+
const expertIdx = typeof expert === 'number' ? expert : EXPERT_NAMES.indexOf(expert);
|
|
354
308
|
if (expertIdx < 0 || expertIdx >= NUM_EXPERTS) {
|
|
355
|
-
console.warn(
|
|
309
|
+
console.warn(`[MoE] Invalid expert: ${expert}`);
|
|
356
310
|
return;
|
|
357
311
|
}
|
|
358
312
|
if (!this.lastInput || !this.lastHiddenActivated || !this.lastProbs) {
|
|
@@ -360,7 +314,7 @@ var MoERouter = /** @class */ (function () {
|
|
|
360
314
|
return;
|
|
361
315
|
}
|
|
362
316
|
// Clamp reward to [-1, 1]
|
|
363
|
-
|
|
317
|
+
const clampedReward = Math.max(-1, Math.min(1, reward));
|
|
364
318
|
// Compute gradients using REINFORCE
|
|
365
319
|
// For softmax: d_log_p_i / d_logit_j = delta_ij - p_j
|
|
366
320
|
// gradient = reward * (1 - p_expert) for selected expert
|
|
@@ -372,7 +326,7 @@ var MoERouter = /** @class */ (function () {
|
|
|
372
326
|
this.gradb1.fill(0);
|
|
373
327
|
this.gradHidden.fill(0);
|
|
374
328
|
// Gradient w.r.t. logits (before softmax)
|
|
375
|
-
for (
|
|
329
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
376
330
|
if (i === expertIdx) {
|
|
377
331
|
this.gradb2[i] = clampedReward * (1 - this.lastProbs[i]);
|
|
378
332
|
}
|
|
@@ -381,22 +335,22 @@ var MoERouter = /** @class */ (function () {
|
|
|
381
335
|
}
|
|
382
336
|
}
|
|
383
337
|
// Gradient w.r.t. W2: outer product of gradb2 and hiddenActivated
|
|
384
|
-
for (
|
|
385
|
-
|
|
386
|
-
for (
|
|
338
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
339
|
+
const rowOffset = i * HIDDEN_DIM;
|
|
340
|
+
for (let j = 0; j < HIDDEN_DIM; j++) {
|
|
387
341
|
this.gradW2[rowOffset + j] = this.gradb2[i] * this.lastHiddenActivated[j];
|
|
388
342
|
}
|
|
389
343
|
}
|
|
390
344
|
// Backprop through W2 to get gradient w.r.t. hidden
|
|
391
|
-
for (
|
|
392
|
-
|
|
393
|
-
for (
|
|
345
|
+
for (let j = 0; j < HIDDEN_DIM; j++) {
|
|
346
|
+
let sum = 0;
|
|
347
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
394
348
|
sum += this.gradb2[i] * this.W2[i * HIDDEN_DIM + j];
|
|
395
349
|
}
|
|
396
350
|
this.gradHidden[j] = sum;
|
|
397
351
|
}
|
|
398
352
|
// Backprop through ReLU: gradient is 0 where activation was 0
|
|
399
|
-
for (
|
|
353
|
+
for (let j = 0; j < HIDDEN_DIM; j++) {
|
|
400
354
|
if (this.lastHiddenActivated[j] <= 0) {
|
|
401
355
|
this.gradHidden[j] = 0;
|
|
402
356
|
}
|
|
@@ -404,24 +358,24 @@ var MoERouter = /** @class */ (function () {
|
|
|
404
358
|
// Gradient w.r.t. b1
|
|
405
359
|
this.gradb1.set(this.gradHidden);
|
|
406
360
|
// Gradient w.r.t. W1: outer product of gradHidden and input
|
|
407
|
-
for (
|
|
408
|
-
|
|
409
|
-
for (
|
|
361
|
+
for (let i = 0; i < HIDDEN_DIM; i++) {
|
|
362
|
+
const rowOffset = i * INPUT_DIM;
|
|
363
|
+
for (let j = 0; j < INPUT_DIM; j++) {
|
|
410
364
|
this.gradW1[rowOffset + j] = this.gradHidden[i] * this.lastInput[j];
|
|
411
365
|
}
|
|
412
366
|
}
|
|
413
367
|
// Apply gradients with learning rate
|
|
414
|
-
|
|
415
|
-
for (
|
|
368
|
+
const lr = this.config.learningRate;
|
|
369
|
+
for (let i = 0; i < this.W2.length; i++) {
|
|
416
370
|
this.W2[i] += lr * this.gradW2[i];
|
|
417
371
|
}
|
|
418
|
-
for (
|
|
372
|
+
for (let i = 0; i < this.b2.length; i++) {
|
|
419
373
|
this.b2[i] += lr * this.gradb2[i];
|
|
420
374
|
}
|
|
421
|
-
for (
|
|
375
|
+
for (let i = 0; i < this.W1.length; i++) {
|
|
422
376
|
this.W1[i] += lr * this.gradW1[i];
|
|
423
377
|
}
|
|
424
|
-
for (
|
|
378
|
+
for (let i = 0; i < this.b1.length; i++) {
|
|
425
379
|
this.b1[i] += lr * this.gradb1[i];
|
|
426
380
|
}
|
|
427
381
|
// Update statistics
|
|
@@ -430,44 +384,44 @@ var MoERouter = /** @class */ (function () {
|
|
|
430
384
|
// Auto-save
|
|
431
385
|
if (this.config.autoSaveInterval > 0 &&
|
|
432
386
|
this.updateCount % this.config.autoSaveInterval === 0) {
|
|
433
|
-
this.saveWeights()
|
|
387
|
+
this.saveWeights().catch(() => { }); // Fire and forget
|
|
434
388
|
}
|
|
435
|
-
}
|
|
389
|
+
}
|
|
436
390
|
/**
|
|
437
391
|
* Get load balance statistics across all experts
|
|
438
392
|
*/
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
for (
|
|
445
|
-
|
|
393
|
+
getLoadBalance() {
|
|
394
|
+
const counts = {};
|
|
395
|
+
const utilization = {};
|
|
396
|
+
const total = this.totalRoutings || 1;
|
|
397
|
+
const idealUtilization = 1 / NUM_EXPERTS;
|
|
398
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
399
|
+
const name = EXPERT_NAMES[i];
|
|
446
400
|
counts[name] = this.routingCounts[i];
|
|
447
401
|
utilization[name] = this.routingCounts[i] / total;
|
|
448
402
|
}
|
|
449
403
|
// Compute Gini coefficient
|
|
450
|
-
|
|
404
|
+
const gini = this.computeGiniCoefficient();
|
|
451
405
|
// Compute coefficient of variation
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
for (
|
|
406
|
+
const mean = total / NUM_EXPERTS;
|
|
407
|
+
let variance = 0;
|
|
408
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
455
409
|
variance += Math.pow(this.routingCounts[i] - mean, 2);
|
|
456
410
|
}
|
|
457
411
|
variance /= NUM_EXPERTS;
|
|
458
|
-
|
|
412
|
+
const cv = Math.sqrt(variance) / (mean + 1e-8);
|
|
459
413
|
return {
|
|
460
|
-
utilization
|
|
414
|
+
utilization,
|
|
461
415
|
totalRoutings: this.totalRoutings,
|
|
462
416
|
routingCounts: counts,
|
|
463
417
|
giniCoefficient: gini,
|
|
464
|
-
coefficientOfVariation: cv
|
|
418
|
+
coefficientOfVariation: cv,
|
|
465
419
|
};
|
|
466
|
-
}
|
|
420
|
+
}
|
|
467
421
|
/**
|
|
468
422
|
* Get router statistics
|
|
469
423
|
*/
|
|
470
|
-
|
|
424
|
+
getStats() {
|
|
471
425
|
return {
|
|
472
426
|
totalRoutings: this.totalRoutings,
|
|
473
427
|
updateCount: this.updateCount,
|
|
@@ -475,139 +429,129 @@ var MoERouter = /** @class */ (function () {
|
|
|
475
429
|
topK: this.config.topK,
|
|
476
430
|
temperature: this.config.temperature,
|
|
477
431
|
learningRate: this.config.learningRate,
|
|
478
|
-
giniCoefficient: this.computeGiniCoefficient()
|
|
432
|
+
giniCoefficient: this.computeGiniCoefficient(),
|
|
479
433
|
};
|
|
480
|
-
}
|
|
434
|
+
}
|
|
481
435
|
/**
|
|
482
436
|
* Reset all statistics and routing counts
|
|
483
437
|
*/
|
|
484
|
-
|
|
438
|
+
resetStats() {
|
|
485
439
|
this.routingCounts.fill(0);
|
|
486
440
|
this.totalRoutings = 0;
|
|
487
441
|
this.updateCount = 0;
|
|
488
442
|
this.avgReward = 0;
|
|
489
|
-
}
|
|
443
|
+
}
|
|
490
444
|
/**
|
|
491
445
|
* Load weights from persistence file
|
|
492
446
|
*/
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return [2 /*return*/, false];
|
|
524
|
-
}
|
|
525
|
-
return [2 /*return*/];
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
};
|
|
447
|
+
async loadWeights(path) {
|
|
448
|
+
const weightsPath = path || this.config.weightsPath;
|
|
449
|
+
try {
|
|
450
|
+
if (!existsSync(weightsPath)) {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
const data = readFileSync(weightsPath, 'utf-8');
|
|
454
|
+
const model = JSON.parse(data);
|
|
455
|
+
// Validate version
|
|
456
|
+
if (!model.version || !model.version.startsWith('1.')) {
|
|
457
|
+
console.warn(`[MoE] Incompatible model version: ${model.version}`);
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
// Load weights
|
|
461
|
+
this.W1 = new Float32Array(model.weights.W1.flat());
|
|
462
|
+
this.b1 = new Float32Array(model.weights.b1);
|
|
463
|
+
this.W2 = new Float32Array(model.weights.W2.flat());
|
|
464
|
+
this.b2 = new Float32Array(model.weights.b2);
|
|
465
|
+
// Load stats
|
|
466
|
+
this.updateCount = model.stats.updateCount || 0;
|
|
467
|
+
this.avgReward = model.stats.avgReward || 0;
|
|
468
|
+
this.routingCounts = new Float32Array(model.stats.routingCounts || new Array(NUM_EXPERTS).fill(0));
|
|
469
|
+
this.totalRoutings = this.routingCounts.reduce((a, b) => a + b, 0);
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
catch (err) {
|
|
473
|
+
console.warn(`[MoE] Failed to load weights: ${err}`);
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
529
477
|
/**
|
|
530
478
|
* Save weights to persistence file
|
|
531
479
|
*/
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
return [2 /*return*/];
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
};
|
|
480
|
+
async saveWeights(path) {
|
|
481
|
+
const weightsPath = path || this.config.weightsPath;
|
|
482
|
+
try {
|
|
483
|
+
// Ensure directory exists
|
|
484
|
+
const dir = dirname(weightsPath);
|
|
485
|
+
if (!existsSync(dir)) {
|
|
486
|
+
mkdirSync(dir, { recursive: true });
|
|
487
|
+
}
|
|
488
|
+
// Convert Float32Arrays to nested arrays for JSON
|
|
489
|
+
const W1_2d = [];
|
|
490
|
+
for (let i = 0; i < HIDDEN_DIM; i++) {
|
|
491
|
+
W1_2d.push(Array.from(this.W1.slice(i * INPUT_DIM, (i + 1) * INPUT_DIM)));
|
|
492
|
+
}
|
|
493
|
+
const W2_2d = [];
|
|
494
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
495
|
+
W2_2d.push(Array.from(this.W2.slice(i * HIDDEN_DIM, (i + 1) * HIDDEN_DIM)));
|
|
496
|
+
}
|
|
497
|
+
const model = {
|
|
498
|
+
version: '1.0.0',
|
|
499
|
+
config: {
|
|
500
|
+
topK: this.config.topK,
|
|
501
|
+
temperature: this.config.temperature,
|
|
502
|
+
learningRate: this.config.learningRate,
|
|
503
|
+
loadBalanceCoef: this.config.loadBalanceCoef,
|
|
504
|
+
},
|
|
505
|
+
weights: {
|
|
506
|
+
W1: W1_2d,
|
|
507
|
+
b1: Array.from(this.b1),
|
|
508
|
+
W2: W2_2d,
|
|
509
|
+
b2: Array.from(this.b2),
|
|
510
|
+
},
|
|
511
|
+
stats: {
|
|
512
|
+
updateCount: this.updateCount,
|
|
513
|
+
routingCounts: Array.from(this.routingCounts),
|
|
514
|
+
avgReward: this.avgReward,
|
|
515
|
+
},
|
|
516
|
+
metadata: {
|
|
517
|
+
savedAt: new Date().toISOString(),
|
|
518
|
+
expertNames: [...EXPERT_NAMES],
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
writeFileSync(weightsPath, JSON.stringify(model, null, 2));
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
catch (err) {
|
|
525
|
+
console.warn(`[MoE] Failed to save weights: ${err}`);
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
585
529
|
/**
|
|
586
530
|
* Reset weights to random initialization
|
|
587
531
|
*/
|
|
588
|
-
|
|
532
|
+
resetWeights() {
|
|
589
533
|
this.W1 = xavierInit(INPUT_DIM, HIDDEN_DIM);
|
|
590
534
|
this.b1.fill(0);
|
|
591
535
|
this.W2 = xavierInit(HIDDEN_DIM, NUM_EXPERTS);
|
|
592
536
|
this.b2.fill(0);
|
|
593
537
|
this.resetStats();
|
|
594
|
-
}
|
|
538
|
+
}
|
|
595
539
|
// ============================================================================
|
|
596
540
|
// Private Methods
|
|
597
541
|
// ============================================================================
|
|
598
542
|
/**
|
|
599
543
|
* Select top-k indices from probabilities
|
|
600
544
|
*/
|
|
601
|
-
|
|
545
|
+
selectTopK(probs, k) {
|
|
602
546
|
// Create index-value pairs and sort by value descending
|
|
603
|
-
|
|
604
|
-
for (
|
|
547
|
+
const pairs = [];
|
|
548
|
+
for (let i = 0; i < probs.length; i++) {
|
|
605
549
|
pairs.push([i, probs[i]]);
|
|
606
550
|
}
|
|
607
|
-
pairs.sort(
|
|
551
|
+
pairs.sort((a, b) => b[1] - a[1]);
|
|
608
552
|
// Return top-k indices
|
|
609
|
-
return pairs.slice(0, k).map(
|
|
610
|
-
}
|
|
553
|
+
return pairs.slice(0, k).map((p) => p[0]);
|
|
554
|
+
}
|
|
611
555
|
/**
|
|
612
556
|
* Compute load balance loss for regularization
|
|
613
557
|
*
|
|
@@ -616,43 +560,41 @@ var MoERouter = /** @class */ (function () {
|
|
|
616
560
|
* where f_i = fraction of tokens routed to expert i
|
|
617
561
|
* P_i = average routing probability to expert i
|
|
618
562
|
*/
|
|
619
|
-
|
|
563
|
+
computeLoadBalanceLoss() {
|
|
620
564
|
if (this.totalRoutings === 0)
|
|
621
565
|
return 0;
|
|
622
|
-
|
|
623
|
-
for (
|
|
624
|
-
|
|
625
|
-
|
|
566
|
+
let loss = 0;
|
|
567
|
+
for (let i = 0; i < NUM_EXPERTS; i++) {
|
|
568
|
+
const fraction = this.routingCounts[i] / this.totalRoutings;
|
|
569
|
+
const avgProb = this.probs[i]; // Current routing prob
|
|
626
570
|
loss += fraction * avgProb;
|
|
627
571
|
}
|
|
628
572
|
return NUM_EXPERTS * loss * this.config.loadBalanceCoef;
|
|
629
|
-
}
|
|
573
|
+
}
|
|
630
574
|
/**
|
|
631
575
|
* Compute Gini coefficient for load distribution
|
|
632
576
|
*/
|
|
633
|
-
|
|
577
|
+
computeGiniCoefficient() {
|
|
634
578
|
if (this.totalRoutings === 0)
|
|
635
579
|
return 0;
|
|
636
580
|
// Sort counts
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
581
|
+
const sorted = Array.from(this.routingCounts).sort((a, b) => a - b);
|
|
582
|
+
const n = sorted.length;
|
|
583
|
+
const mean = this.totalRoutings / n;
|
|
640
584
|
// Compute Gini using the formula: G = (2 * sum(i * x_i) - (n+1) * sum(x_i)) / (n * sum(x_i))
|
|
641
|
-
|
|
642
|
-
for (
|
|
585
|
+
let weightedSum = 0;
|
|
586
|
+
for (let i = 0; i < n; i++) {
|
|
643
587
|
weightedSum += (i + 1) * sorted[i];
|
|
644
588
|
}
|
|
645
|
-
|
|
589
|
+
const gini = (2 * weightedSum - (n + 1) * this.totalRoutings) /
|
|
646
590
|
(n * this.totalRoutings + 1e-8);
|
|
647
591
|
return Math.max(0, gini);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
}());
|
|
651
|
-
export { MoERouter };
|
|
592
|
+
}
|
|
593
|
+
}
|
|
652
594
|
// ============================================================================
|
|
653
595
|
// Singleton Instance
|
|
654
596
|
// ============================================================================
|
|
655
|
-
|
|
597
|
+
let moeRouterInstance = null;
|
|
656
598
|
/**
|
|
657
599
|
* Get singleton MoE router instance
|
|
658
600
|
*
|
|
@@ -663,7 +605,7 @@ export function getMoERouter(config) {
|
|
|
663
605
|
if (!moeRouterInstance) {
|
|
664
606
|
moeRouterInstance = new MoERouter(config);
|
|
665
607
|
// Initialize in background (load weights)
|
|
666
|
-
moeRouterInstance.initialize()
|
|
608
|
+
moeRouterInstance.initialize().catch((err) => {
|
|
667
609
|
console.warn('[MoE] Failed to initialize router:', err);
|
|
668
610
|
});
|
|
669
611
|
}
|