monomind 1.10.57 → 1.11.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/.claude/agents/core/coordinator.md +71 -0
- package/.claude/agents/generated/case-analyst.md +50 -0
- package/.claude/agents/generated/copy-editor.md +45 -0
- package/.claude/agents/generated/court-reporter.md +50 -0
- package/.claude/agents/generated/defender.md +51 -0
- package/.claude/agents/generated/editor-in-chief.md +45 -0
- package/.claude/agents/generated/fact-checker.md +45 -0
- package/.claude/agents/generated/judge.md +51 -0
- package/.claude/agents/generated/prosecutor.md +51 -0
- package/.claude/agents/generated/reporter.md +45 -0
- package/.claude/commands/hooks/README.md +1 -1
- package/.claude/commands/hooks/overview.md +1 -1
- package/.claude/commands/mastermind/_repeat.md +1 -1
- package/.claude/commands/mastermind/do.md +3 -1
- package/.claude/commands/mastermind/help.md +2 -2
- package/.claude/commands/mastermind/master.md +39 -6
- package/.claude/commands/mastermind/memory.md +1 -1
- package/.claude/commands/memory/memory-search.md +2 -2
- package/.claude/commands/monitoring/status.md +1 -1
- package/.claude/commands/{browse.md → monobrowse.md} +2 -2
- package/.claude/commands/sparc.md +1 -1
- package/.claude/helpers/handlers/graph-status-handler.cjs +1 -1
- package/.claude/helpers/loop-tracker.cjs +1 -1
- package/.claude/scheduled_tasks.lock +1 -1
- package/.claude/skills/agent-browser-testing/SKILL.md +1 -1
- package/.claude/skills/hooks-automation/SKILL.md +0 -3
- package/.claude/skills/mastermind/build.md +1 -1
- package/.claude/skills/mastermind/code-quality-reviewer-prompt.md +60 -0
- package/.claude/skills/mastermind/content.md +1 -1
- package/.claude/skills/mastermind/createorg.md +79 -2
- package/.claude/skills/mastermind/design.md +3 -1
- package/.claude/skills/mastermind/finance.md +1 -1
- package/.claude/skills/mastermind/implementer-prompt.md +109 -0
- package/.claude/skills/mastermind/marketing.md +1 -1
- package/.claude/skills/mastermind/ops.md +1 -1
- package/.claude/skills/mastermind/plan.md +20 -2
- package/.claude/skills/mastermind/release.md +1 -1
- package/.claude/skills/mastermind/research.md +1 -1
- package/.claude/skills/mastermind/review.md +1 -1
- package/.claude/skills/mastermind/sales.md +1 -1
- package/.claude/skills/mastermind/spec-reviewer-prompt.md +63 -0
- package/.claude/skills/sparc-methodology/SKILL.md +3 -3
- package/.claude/skills/swarm-advanced/SKILL.md +1 -4
- package/.claude-plugin/README.md +1 -2
- package/.claude-plugin/docs/PLUGIN_SUMMARY.md +0 -1
- package/README.md +18 -32
- package/package.json +2 -2
- package/packages/@monomind/cli/README.md +18 -32
- package/packages/@monomind/cli/dist/src/agents/registry-builder.d.ts +1 -7
- package/packages/@monomind/cli/dist/src/agents/registry-builder.js +10 -6
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +59 -12
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +67 -13
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -13
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +5 -5
- package/packages/@monomind/cli/dist/src/commands/agent.js +1 -6
- package/packages/@monomind/cli/dist/src/commands/analyze.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/analyze.js +8 -18
- package/packages/@monomind/cli/dist/src/commands/doctor.js +53 -3
- package/packages/@monomind/cli/dist/src/commands/embeddings.js +9 -33
- package/packages/@monomind/cli/dist/src/commands/hooks.js +31 -74
- package/packages/@monomind/cli/dist/src/commands/index.d.ts +4 -6
- package/packages/@monomind/cli/dist/src/commands/index.js +8 -15
- package/packages/@monomind/cli/dist/src/commands/init.js +2 -2
- package/packages/@monomind/cli/dist/src/commands/issues.js +16 -11
- package/packages/@monomind/cli/dist/src/commands/memory.js +6 -6
- package/packages/@monomind/cli/dist/src/commands/migrate.js +1 -2
- package/packages/@monomind/cli/dist/src/commands/monograph.js +18 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/backup.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/backup.js +25 -25
- package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/benchmark.js +14 -14
- package/packages/@monomind/cli/dist/src/commands/monovector/import.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/import.js +21 -21
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.d.ts +6 -6
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.js +22 -22
- package/packages/@monomind/cli/dist/src/commands/monovector/init.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/init.js +36 -36
- package/packages/@monomind/cli/dist/src/commands/monovector/migrate.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/migrate.js +16 -16
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.js +10 -10
- package/packages/@monomind/cli/dist/src/commands/monovector/setup.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/setup.js +77 -77
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.js +34 -34
- package/packages/@monomind/cli/dist/src/commands/neural.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/neural.js +31 -608
- package/packages/@monomind/cli/dist/src/commands/performance.js +7 -10
- package/packages/@monomind/cli/dist/src/commands/plugins.js +3 -4
- package/packages/@monomind/cli/dist/src/commands/process.js +5 -12
- package/packages/@monomind/cli/dist/src/commands/progress.js +16 -16
- package/packages/@monomind/cli/dist/src/commands/route.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/route.js +23 -23
- package/packages/@monomind/cli/dist/src/commands/status.js +0 -3
- package/packages/@monomind/cli/dist/src/commands/swarm.js +2 -3
- package/packages/@monomind/cli/dist/src/config-adapter.js +27 -0
- package/packages/@monomind/cli/dist/src/consensus/audit-writer.d.ts +44 -17
- package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/index.js +5 -5
- package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +57 -37
- package/packages/@monomind/cli/dist/src/init/executor.js +17 -27
- package/packages/@monomind/cli/dist/src/init/helpers-generator.js +2 -2
- package/packages/@monomind/cli/dist/src/init/types.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-client.js +1 -7
- package/packages/@monomind/cli/dist/src/mcp-server.js +9 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +1 -52
- package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +5 -5
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +6 -5
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +51 -54
- package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +10 -10
- package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +0 -24
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +189 -480
- package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +0 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/index.js +0 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.d.ts +334 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.js +1126 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +76 -34
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.js +3 -3
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +29 -19
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +2 -2
- package/packages/@monomind/cli/dist/src/memory/intelligence.js +14 -8
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +17 -2
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +76 -23
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +37 -39
- package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +34 -0
- package/packages/@monomind/cli/dist/src/monovector/capabilities.js +37 -0
- package/packages/@monomind/cli/dist/src/monovector/command-outcomes.d.ts +37 -0
- package/packages/@monomind/cli/dist/src/monovector/command-outcomes.js +87 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-router.d.ts +103 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-router.js +337 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-tools.js +112 -0
- package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/monovector/index.d.ts +61 -0
- package/packages/@monomind/cli/dist/src/monovector/index.js +67 -0
- package/packages/@monomind/cli/dist/src/monovector/init-state.d.ts +35 -0
- package/packages/@monomind/cli/dist/src/monovector/init-state.js +36 -0
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.d.ts +55 -0
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.js +137 -0
- package/packages/@monomind/cli/dist/src/parser.js +3 -3
- package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +0 -31
- package/packages/@monomind/cli/dist/src/production/circuit-breaker.d.ts +26 -6
- package/packages/@monomind/cli/dist/src/production/error-handler.d.ts +55 -30
- package/packages/@monomind/cli/dist/src/production/index.d.ts +3 -20
- package/packages/@monomind/cli/dist/src/production/index.js +3 -15
- package/packages/@monomind/cli/dist/src/production/monitoring.d.ts +54 -34
- package/packages/@monomind/cli/dist/src/production/monitoring.js +12 -14
- package/packages/@monomind/cli/dist/src/production/rate-limiter.d.ts +64 -19
- package/packages/@monomind/cli/dist/src/production/rate-limiter.js +5 -5
- package/packages/@monomind/cli/dist/src/production/retry.js +4 -2
- package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +50 -59
- package/packages/@monomind/cli/dist/src/services/claim-service.js +83 -50
- package/packages/@monomind/cli/dist/src/services/config-file-manager.js +8 -1
- package/packages/@monomind/cli/dist/src/services/worker-daemon.js +4 -0
- package/packages/@monomind/cli/dist/src/types.d.ts +13 -0
- package/packages/@monomind/cli/package.json +14 -14
- package/packages/@monomind/guidance/dist/index.d.ts +1 -1
- package/packages/@monomind/guidance/dist/index.js +1 -1
- package/packages/@monomind/guidance/package.json +1 -2
- package/scripts/build-monovector.sh +10 -0
- package/scripts/publish-monovector.sh +20 -0
- package/.claude/commands/monomind/adr.md +0 -11
- package/.claude/commands/monomind/budget.md +0 -7
- package/.claude/commands/monomind/createtask.md +0 -277
- package/.claude/commands/monomind/do.md +0 -498
- package/.claude/commands/monomind/graph-status.md +0 -7
- package/.claude/commands/monomind/help.md +0 -118
- package/.claude/commands/monomind/idea.md +0 -273
- package/.claude/commands/monomind/improve.md +0 -352
- package/.claude/commands/monomind/loops.md +0 -7
- package/.claude/commands/monomind/memory.md +0 -230
- package/.claude/commands/monomind/repeat.md +0 -257
- package/.claude/commands/monomind/review.md +0 -317
- package/.claude/commands/monomind/specialagents.md +0 -125
- package/.claude/commands/monomind/swarm.md +0 -161
- package/.claude/commands/monomind/understand.md +0 -139
- package/.claude/commands/training/README.md +0 -39
- package/.claude/commands/training/neural-patterns.md +0 -73
- package/.claude/commands/training/neural-train.md +0 -79
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.d.ts +0 -9
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.js +0 -238
- package/packages/@monomind/cli/dist/src/commands/appliance.d.ts +0 -8
- package/packages/@monomind/cli/dist/src/commands/appliance.js +0 -406
- package/packages/@monomind/cli/dist/src/commands/ruvector/backup.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/benchmark.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/import.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/commands/ruvector/init.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/migrate.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/setup.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.d.ts +0 -182
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.js +0 -316
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.d.ts +0 -67
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.js +0 -277
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.d.ts +0 -160
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.js +0 -539
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.d.ts +0 -33
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.js +0 -157
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.d.ts +0 -146
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.js +0 -551
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.d.ts +0 -195
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.js +0 -643
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.d.ts +0 -187
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.js +0 -929
- package/packages/@monomind/cli/dist/src/ruvector/index.d.ts +0 -67
- package/packages/@monomind/cli/dist/src/ruvector/index.js +0 -88
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.d.ts +0 -218
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.js +0 -455
- package/packages/@monomind/cli/dist/src/ruvector/model-router.d.ts +0 -222
- package/packages/@monomind/cli/dist/src/ruvector/model-router.js +0 -512
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.d.ts +0 -213
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.js +0 -649
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.d.ts +0 -217
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.js +0 -712
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.d.ts +0 -179
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.js +0 -363
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.d.ts +0 -77
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.js +0 -178
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.d.ts +0 -69
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.js +0 -243
- package/packages/@monomind/cli/dist/src/services/ruvector-training.d.ts +0 -222
- package/packages/@monomind/cli/dist/src/services/ruvector-training.js +0 -696
- /package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.js +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuVector LLM WASM Integration
|
|
3
|
-
*
|
|
4
|
-
* Wraps @ruvector/ruvllm-wasm for browser-native LLM inference utilities.
|
|
5
|
-
* Provides HNSW routing, SONA instant adaptation, MicroLoRA fine-tuning,
|
|
6
|
-
* chat template formatting, KV cache management, and inference arena.
|
|
7
|
-
*
|
|
8
|
-
* Published API (v2.0.2): RuvLLMWasm, ChatTemplateWasm, ChatMessageWasm,
|
|
9
|
-
* GenerateConfig, HnswRouterWasm, SonaInstantWasm, MicroLoraWasm,
|
|
10
|
-
* KvCacheWasm, BufferPoolWasm, InferenceArenaWasm.
|
|
11
|
-
*
|
|
12
|
-
* v2.0.2 fixes:
|
|
13
|
-
* - HNSW supports 1000+ patterns (fixed connect_node ordering)
|
|
14
|
-
* - MicroLoRA adapt() now takes (input: Float32Array, feedback: AdaptFeedbackWasm)
|
|
15
|
-
*
|
|
16
|
-
* Remaining quirks:
|
|
17
|
-
* - Stats objects return WASM pointers — use .toJson() or named accessors
|
|
18
|
-
* - GenerateConfig float precision loss (f32 roundtrip)
|
|
19
|
-
* - MicroLoRA apply() hardcoded to 768 dims regardless of config
|
|
20
|
-
*
|
|
21
|
-
* @module @monomind/cli/ruvector/ruvllm-wasm
|
|
22
|
-
*/
|
|
23
|
-
export interface HnswRouterConfig {
|
|
24
|
-
dimensions: number;
|
|
25
|
-
maxPatterns: number;
|
|
26
|
-
efSearch?: number;
|
|
27
|
-
}
|
|
28
|
-
export interface HnswPattern {
|
|
29
|
-
name: string;
|
|
30
|
-
embedding: Float32Array;
|
|
31
|
-
metadata?: Record<string, unknown>;
|
|
32
|
-
}
|
|
33
|
-
export interface HnswRouteResult {
|
|
34
|
-
name: string;
|
|
35
|
-
score: number;
|
|
36
|
-
metadata?: Record<string, unknown>;
|
|
37
|
-
}
|
|
38
|
-
export interface SonaConfig {
|
|
39
|
-
hiddenDim?: number;
|
|
40
|
-
learningRate?: number;
|
|
41
|
-
emaDecay?: number;
|
|
42
|
-
ewcLambda?: number;
|
|
43
|
-
microLoraRank?: number;
|
|
44
|
-
patternCapacity?: number;
|
|
45
|
-
}
|
|
46
|
-
export interface MicroLoraConfig {
|
|
47
|
-
inputDim: number;
|
|
48
|
-
outputDim: number;
|
|
49
|
-
rank?: number;
|
|
50
|
-
alpha?: number;
|
|
51
|
-
}
|
|
52
|
-
export interface ChatMessage {
|
|
53
|
-
role: 'system' | 'user' | 'assistant';
|
|
54
|
-
content: string;
|
|
55
|
-
}
|
|
56
|
-
export interface GenerateOptions {
|
|
57
|
-
maxTokens?: number;
|
|
58
|
-
temperature?: number;
|
|
59
|
-
topP?: number;
|
|
60
|
-
topK?: number;
|
|
61
|
-
repetitionPenalty?: number;
|
|
62
|
-
stopSequences?: string[];
|
|
63
|
-
}
|
|
64
|
-
export interface RuvllmStatus {
|
|
65
|
-
available: boolean;
|
|
66
|
-
initialized: boolean;
|
|
67
|
-
version: string | null;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if @ruvector/ruvllm-wasm is installed and loadable.
|
|
71
|
-
*/
|
|
72
|
-
export declare function isRuvllmWasmAvailable(): Promise<boolean>;
|
|
73
|
-
/**
|
|
74
|
-
* Initialize the WASM module for Node.js. Safe to call multiple times.
|
|
75
|
-
* Uses initSync with object form: { module: bytes } (raw bytes deprecated).
|
|
76
|
-
*/
|
|
77
|
-
export declare function initRuvllmWasm(): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Get ruvllm-wasm status.
|
|
80
|
-
*/
|
|
81
|
-
export declare function getRuvllmStatus(): Promise<RuvllmStatus>;
|
|
82
|
-
/**
|
|
83
|
-
* Maximum safe pattern count for HNSW router.
|
|
84
|
-
* v2.0.2 supports 1000+ patterns (fixed connect_node ordering).
|
|
85
|
-
*/
|
|
86
|
-
export declare const HNSW_MAX_SAFE_PATTERNS = 1024;
|
|
87
|
-
/**
|
|
88
|
-
* Create a WASM HNSW router for semantic routing.
|
|
89
|
-
* Returns an object with add/route/clear methods.
|
|
90
|
-
*
|
|
91
|
-
* Enforces HNSW_MAX_SAFE_PATTERNS limit (1024 in v2.0.2).
|
|
92
|
-
*/
|
|
93
|
-
export declare function createHnswRouter(config: HnswRouterConfig): Promise<{
|
|
94
|
-
addPattern: (pattern: HnswPattern) => boolean;
|
|
95
|
-
route: (query: Float32Array, k?: number) => HnswRouteResult[];
|
|
96
|
-
clear: () => void;
|
|
97
|
-
patternCount: () => number;
|
|
98
|
-
toJson: () => string;
|
|
99
|
-
}>;
|
|
100
|
-
/**
|
|
101
|
-
* Create a SONA instant adaptation loop (<1ms adaptation).
|
|
102
|
-
* v2.0.1: requires SonaConfigWasm object, not raw number.
|
|
103
|
-
*/
|
|
104
|
-
export declare function createSonaInstant(config?: SonaConfig): Promise<{
|
|
105
|
-
adapt: (quality: number) => void;
|
|
106
|
-
recordPattern: (embedding: number[], success: boolean) => void;
|
|
107
|
-
suggestAction: (context: string) => string | undefined;
|
|
108
|
-
stats: () => string;
|
|
109
|
-
reset: () => void;
|
|
110
|
-
toJson: () => string;
|
|
111
|
-
}>;
|
|
112
|
-
/**
|
|
113
|
-
* Create a MicroLoRA adapter (ultra-lightweight LoRA, ranks 1-4).
|
|
114
|
-
* v2.0.2: .adapt(input, feedback) takes Float32Array + AdaptFeedbackWasm.
|
|
115
|
-
*/
|
|
116
|
-
export declare function createMicroLora(config: MicroLoraConfig): Promise<{
|
|
117
|
-
apply: (input: Float32Array) => Float32Array;
|
|
118
|
-
adapt: (quality: number, learningRate?: number, success?: boolean) => void;
|
|
119
|
-
applyUpdates: (gradients: Float32Array) => void;
|
|
120
|
-
stats: () => string;
|
|
121
|
-
reset: () => void;
|
|
122
|
-
toJson: () => string;
|
|
123
|
-
pendingUpdates: () => number;
|
|
124
|
-
}>;
|
|
125
|
-
type TemplatePreset = 'llama3' | 'mistral' | 'chatml' | 'phi' | 'gemma';
|
|
126
|
-
/**
|
|
127
|
-
* Format chat messages using a chat template.
|
|
128
|
-
* Supports presets (llama3, mistral, chatml, phi, gemma) and auto-detection.
|
|
129
|
-
*/
|
|
130
|
-
export declare function formatChat(messages: ChatMessage[], template: TemplatePreset | {
|
|
131
|
-
custom: string;
|
|
132
|
-
} | {
|
|
133
|
-
modelId: string;
|
|
134
|
-
}): Promise<string>;
|
|
135
|
-
/**
|
|
136
|
-
* Create a KV cache for token management.
|
|
137
|
-
*/
|
|
138
|
-
export declare function createKvCache(opts?: {
|
|
139
|
-
tailLength?: number;
|
|
140
|
-
maxTokens?: number;
|
|
141
|
-
numKvHeads?: number;
|
|
142
|
-
headDim?: number;
|
|
143
|
-
}): Promise<{
|
|
144
|
-
append: (keys: Float32Array, values: Float32Array) => void;
|
|
145
|
-
stats: () => string;
|
|
146
|
-
clear: () => void;
|
|
147
|
-
tokenCount: () => number;
|
|
148
|
-
}>;
|
|
149
|
-
/**
|
|
150
|
-
* Create a generation config object.
|
|
151
|
-
* Note: f32 precision loss is expected (0.7 → 0.699999...).
|
|
152
|
-
*/
|
|
153
|
-
export declare function createGenerateConfig(opts?: GenerateOptions): Promise<string>;
|
|
154
|
-
/**
|
|
155
|
-
* Create a buffer pool for inference memory management.
|
|
156
|
-
*/
|
|
157
|
-
export declare function createBufferPool(capacity: number): Promise<{
|
|
158
|
-
prewarm: (count: number) => void;
|
|
159
|
-
stats: () => string;
|
|
160
|
-
hitRate: () => number;
|
|
161
|
-
clear: () => void;
|
|
162
|
-
}>;
|
|
163
|
-
/**
|
|
164
|
-
* Create an inference arena for model memory allocation.
|
|
165
|
-
*/
|
|
166
|
-
export declare function createInferenceArena(opts: {
|
|
167
|
-
capacity: number;
|
|
168
|
-
} | {
|
|
169
|
-
hiddenDim: number;
|
|
170
|
-
vocabSize: number;
|
|
171
|
-
batchSize: number;
|
|
172
|
-
}): Promise<{
|
|
173
|
-
reset: () => void;
|
|
174
|
-
used: () => number;
|
|
175
|
-
capacity: () => number;
|
|
176
|
-
remaining: () => number;
|
|
177
|
-
}>;
|
|
178
|
-
export {};
|
|
179
|
-
//# sourceMappingURL=ruvllm-wasm.d.ts.map
|
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuVector LLM WASM Integration
|
|
3
|
-
*
|
|
4
|
-
* Wraps @ruvector/ruvllm-wasm for browser-native LLM inference utilities.
|
|
5
|
-
* Provides HNSW routing, SONA instant adaptation, MicroLoRA fine-tuning,
|
|
6
|
-
* chat template formatting, KV cache management, and inference arena.
|
|
7
|
-
*
|
|
8
|
-
* Published API (v2.0.2): RuvLLMWasm, ChatTemplateWasm, ChatMessageWasm,
|
|
9
|
-
* GenerateConfig, HnswRouterWasm, SonaInstantWasm, MicroLoraWasm,
|
|
10
|
-
* KvCacheWasm, BufferPoolWasm, InferenceArenaWasm.
|
|
11
|
-
*
|
|
12
|
-
* v2.0.2 fixes:
|
|
13
|
-
* - HNSW supports 1000+ patterns (fixed connect_node ordering)
|
|
14
|
-
* - MicroLoRA adapt() now takes (input: Float32Array, feedback: AdaptFeedbackWasm)
|
|
15
|
-
*
|
|
16
|
-
* Remaining quirks:
|
|
17
|
-
* - Stats objects return WASM pointers — use .toJson() or named accessors
|
|
18
|
-
* - GenerateConfig float precision loss (f32 roundtrip)
|
|
19
|
-
* - MicroLoRA apply() hardcoded to 768 dims regardless of config
|
|
20
|
-
*
|
|
21
|
-
* @module @monomind/cli/ruvector/ruvllm-wasm
|
|
22
|
-
*/
|
|
23
|
-
import { readFileSync } from 'node:fs';
|
|
24
|
-
import { createRequire } from 'node:module';
|
|
25
|
-
// ── WASM Module Detection & Init ─────────────────────────────
|
|
26
|
-
let _wasmReady = false;
|
|
27
|
-
/**
|
|
28
|
-
* Check if @ruvector/ruvllm-wasm is installed and loadable.
|
|
29
|
-
*/
|
|
30
|
-
export async function isRuvllmWasmAvailable() {
|
|
31
|
-
try {
|
|
32
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
33
|
-
return typeof mod.RuvLLMWasm === 'function';
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Initialize the WASM module for Node.js. Safe to call multiple times.
|
|
41
|
-
* Uses initSync with object form: { module: bytes } (raw bytes deprecated).
|
|
42
|
-
*/
|
|
43
|
-
export async function initRuvllmWasm() {
|
|
44
|
-
if (_wasmReady)
|
|
45
|
-
return;
|
|
46
|
-
try {
|
|
47
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
48
|
-
const require_ = createRequire(import.meta.url);
|
|
49
|
-
const wasmPath = require_.resolve('@ruvector/ruvllm-wasm/ruvllm_wasm_bg.wasm');
|
|
50
|
-
const wasmBytes = readFileSync(wasmPath);
|
|
51
|
-
// MUST use object form — initSync(bytes) is deprecated
|
|
52
|
-
mod.initSync({ module: wasmBytes });
|
|
53
|
-
_wasmReady = true;
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
throw new Error(`Failed to initialize @ruvector/ruvllm-wasm: ${err}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get ruvllm-wasm status.
|
|
61
|
-
*/
|
|
62
|
-
export async function getRuvllmStatus() {
|
|
63
|
-
const available = await isRuvllmWasmAvailable();
|
|
64
|
-
if (!available) {
|
|
65
|
-
return { available: false, initialized: false, version: null };
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
69
|
-
// version is a standalone function, not on RuvLLMWasm class
|
|
70
|
-
const version = typeof mod.getVersion === 'function' ? mod.getVersion() : null;
|
|
71
|
-
return { available: true, initialized: _wasmReady, version };
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return { available: true, initialized: _wasmReady, version: null };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ── HNSW Router ──────────────────────────────────────────────
|
|
78
|
-
/**
|
|
79
|
-
* Maximum safe pattern count for HNSW router.
|
|
80
|
-
* v2.0.2 supports 1000+ patterns (fixed connect_node ordering).
|
|
81
|
-
*/
|
|
82
|
-
export const HNSW_MAX_SAFE_PATTERNS = 1024;
|
|
83
|
-
/**
|
|
84
|
-
* Create a WASM HNSW router for semantic routing.
|
|
85
|
-
* Returns an object with add/route/clear methods.
|
|
86
|
-
*
|
|
87
|
-
* Enforces HNSW_MAX_SAFE_PATTERNS limit (1024 in v2.0.2).
|
|
88
|
-
*/
|
|
89
|
-
export async function createHnswRouter(config) {
|
|
90
|
-
await initRuvllmWasm();
|
|
91
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
92
|
-
const router = new mod.HnswRouterWasm(config.dimensions, config.maxPatterns);
|
|
93
|
-
if (config.efSearch) {
|
|
94
|
-
router.setEfSearch(config.efSearch);
|
|
95
|
-
}
|
|
96
|
-
let count = 0;
|
|
97
|
-
return {
|
|
98
|
-
addPattern(pattern) {
|
|
99
|
-
if (count >= HNSW_MAX_SAFE_PATTERNS) {
|
|
100
|
-
throw new Error(`HNSW pattern limit reached (${HNSW_MAX_SAFE_PATTERNS}).`);
|
|
101
|
-
}
|
|
102
|
-
const metadataJson = JSON.stringify(pattern.metadata ?? {});
|
|
103
|
-
// addPattern requires 3 args: (embedding, name, metadata_json)
|
|
104
|
-
const ok = router.addPattern(pattern.embedding, pattern.name, metadataJson);
|
|
105
|
-
if (ok)
|
|
106
|
-
count++;
|
|
107
|
-
return ok;
|
|
108
|
-
},
|
|
109
|
-
route(query, k = 3) {
|
|
110
|
-
return router.route(query, k);
|
|
111
|
-
},
|
|
112
|
-
clear() {
|
|
113
|
-
router.clear();
|
|
114
|
-
count = 0;
|
|
115
|
-
},
|
|
116
|
-
patternCount() {
|
|
117
|
-
return count;
|
|
118
|
-
},
|
|
119
|
-
toJson() {
|
|
120
|
-
return router.toJson();
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
// ── SONA Instant Adaptation ──────────────────────────────────
|
|
125
|
-
/**
|
|
126
|
-
* Create a SONA instant adaptation loop (<1ms adaptation).
|
|
127
|
-
* v2.0.1: requires SonaConfigWasm object, not raw number.
|
|
128
|
-
*/
|
|
129
|
-
export async function createSonaInstant(config = {}) {
|
|
130
|
-
await initRuvllmWasm();
|
|
131
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
132
|
-
const sonaConfig = new mod.SonaConfigWasm();
|
|
133
|
-
if (config.hiddenDim !== undefined)
|
|
134
|
-
sonaConfig.hiddenDim = config.hiddenDim;
|
|
135
|
-
if (config.learningRate !== undefined)
|
|
136
|
-
sonaConfig.learningRate = config.learningRate;
|
|
137
|
-
if (config.emaDecay !== undefined)
|
|
138
|
-
sonaConfig.emaDecay = config.emaDecay;
|
|
139
|
-
if (config.ewcLambda !== undefined)
|
|
140
|
-
sonaConfig.ewcLambda = config.ewcLambda;
|
|
141
|
-
if (config.microLoraRank !== undefined)
|
|
142
|
-
sonaConfig.microLoraRank = config.microLoraRank;
|
|
143
|
-
if (config.patternCapacity !== undefined)
|
|
144
|
-
sonaConfig.patternCapacity = config.patternCapacity;
|
|
145
|
-
const sona = new mod.SonaInstantWasm(sonaConfig);
|
|
146
|
-
return {
|
|
147
|
-
adapt(quality) {
|
|
148
|
-
sona.instantAdapt(quality);
|
|
149
|
-
},
|
|
150
|
-
recordPattern(embedding, success) {
|
|
151
|
-
sona.recordPattern(new Float32Array(embedding), success);
|
|
152
|
-
},
|
|
153
|
-
suggestAction(context) {
|
|
154
|
-
return sona.suggestAction(context);
|
|
155
|
-
},
|
|
156
|
-
stats() {
|
|
157
|
-
return sona.toJson();
|
|
158
|
-
},
|
|
159
|
-
reset() {
|
|
160
|
-
sona.reset();
|
|
161
|
-
},
|
|
162
|
-
toJson() {
|
|
163
|
-
return sona.toJson();
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
// ── MicroLoRA ────────────────────────────────────────────────
|
|
168
|
-
/**
|
|
169
|
-
* Create a MicroLoRA adapter (ultra-lightweight LoRA, ranks 1-4).
|
|
170
|
-
* v2.0.2: .adapt(input, feedback) takes Float32Array + AdaptFeedbackWasm.
|
|
171
|
-
*/
|
|
172
|
-
export async function createMicroLora(config) {
|
|
173
|
-
await initRuvllmWasm();
|
|
174
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
175
|
-
const loraConfig = new mod.MicroLoraConfigWasm();
|
|
176
|
-
loraConfig.inputDim = config.inputDim;
|
|
177
|
-
loraConfig.outputDim = config.outputDim;
|
|
178
|
-
loraConfig.rank = config.rank ?? 2;
|
|
179
|
-
loraConfig.alpha = config.alpha ?? 1.0;
|
|
180
|
-
const lora = new mod.MicroLoraWasm(loraConfig);
|
|
181
|
-
return {
|
|
182
|
-
apply(input) {
|
|
183
|
-
return lora.apply(input);
|
|
184
|
-
},
|
|
185
|
-
adapt(quality, learningRate = 0.01, success = true) {
|
|
186
|
-
// v2.0.2: adapt(input, feedback) — two args
|
|
187
|
-
const feedback = new mod.AdaptFeedbackWasm();
|
|
188
|
-
feedback.quality = quality;
|
|
189
|
-
feedback.learningRate = learningRate;
|
|
190
|
-
// Note: feedback.success not on prototype in v2.0.2, set via property
|
|
191
|
-
try {
|
|
192
|
-
feedback.success = success;
|
|
193
|
-
}
|
|
194
|
-
catch { /* v2.0.2 quirk */ }
|
|
195
|
-
// Create a dummy input vector matching the configured inputDim
|
|
196
|
-
const input = new Float32Array(config.inputDim);
|
|
197
|
-
lora.adapt(input, feedback);
|
|
198
|
-
},
|
|
199
|
-
applyUpdates(gradients) {
|
|
200
|
-
lora.applyUpdates(gradients);
|
|
201
|
-
},
|
|
202
|
-
stats() {
|
|
203
|
-
return lora.toJson();
|
|
204
|
-
},
|
|
205
|
-
reset() {
|
|
206
|
-
lora.reset();
|
|
207
|
-
},
|
|
208
|
-
toJson() {
|
|
209
|
-
return lora.toJson();
|
|
210
|
-
},
|
|
211
|
-
pendingUpdates() {
|
|
212
|
-
return lora.pendingUpdates();
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Format chat messages using a chat template.
|
|
218
|
-
* Supports presets (llama3, mistral, chatml, phi, gemma) and auto-detection.
|
|
219
|
-
*/
|
|
220
|
-
export async function formatChat(messages, template) {
|
|
221
|
-
await initRuvllmWasm();
|
|
222
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
223
|
-
// Build template
|
|
224
|
-
let tmpl;
|
|
225
|
-
if (typeof template === 'string') {
|
|
226
|
-
const presets = {
|
|
227
|
-
llama3: () => mod.ChatTemplateWasm.llama3(),
|
|
228
|
-
mistral: () => mod.ChatTemplateWasm.mistral(),
|
|
229
|
-
chatml: () => mod.ChatTemplateWasm.chatml(),
|
|
230
|
-
phi: () => mod.ChatTemplateWasm.phi(),
|
|
231
|
-
gemma: () => mod.ChatTemplateWasm.gemma(),
|
|
232
|
-
};
|
|
233
|
-
const factory = presets[template];
|
|
234
|
-
if (!factory)
|
|
235
|
-
throw new Error(`Unknown template preset: ${template}. Use: ${Object.keys(presets).join(', ')}`);
|
|
236
|
-
tmpl = factory();
|
|
237
|
-
}
|
|
238
|
-
else if ('custom' in template) {
|
|
239
|
-
tmpl = mod.ChatTemplateWasm.custom(template.custom);
|
|
240
|
-
}
|
|
241
|
-
else if ('modelId' in template) {
|
|
242
|
-
tmpl = mod.ChatTemplateWasm.detectFromModelId(template.modelId);
|
|
243
|
-
}
|
|
244
|
-
// Build messages
|
|
245
|
-
const wasmMessages = messages.map(m => {
|
|
246
|
-
switch (m.role) {
|
|
247
|
-
case 'system': return mod.ChatMessageWasm.system(m.content);
|
|
248
|
-
case 'user': return mod.ChatMessageWasm.user(m.content);
|
|
249
|
-
case 'assistant': return mod.ChatMessageWasm.assistant(m.content);
|
|
250
|
-
default: throw new Error(`Unknown role: ${m.role}`);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
return tmpl.format(wasmMessages);
|
|
254
|
-
}
|
|
255
|
-
// ── KV Cache ─────────────────────────────────────────────────
|
|
256
|
-
/**
|
|
257
|
-
* Create a KV cache for token management.
|
|
258
|
-
*/
|
|
259
|
-
export async function createKvCache(opts) {
|
|
260
|
-
await initRuvllmWasm();
|
|
261
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
262
|
-
let cache;
|
|
263
|
-
if (opts) {
|
|
264
|
-
const config = new mod.KvCacheConfigWasm();
|
|
265
|
-
if (opts.tailLength !== undefined)
|
|
266
|
-
config.tailLength = opts.tailLength;
|
|
267
|
-
if (opts.maxTokens !== undefined)
|
|
268
|
-
config.maxTokens = opts.maxTokens;
|
|
269
|
-
if (opts.numKvHeads !== undefined)
|
|
270
|
-
config.numKvHeads = opts.numKvHeads;
|
|
271
|
-
if (opts.headDim !== undefined)
|
|
272
|
-
config.headDim = opts.headDim;
|
|
273
|
-
cache = new mod.KvCacheWasm(config);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
cache = mod.KvCacheWasm.withDefaults();
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
append(keys, values) {
|
|
280
|
-
cache.append(keys, values);
|
|
281
|
-
},
|
|
282
|
-
stats() {
|
|
283
|
-
// Use toJson if available, otherwise stringify
|
|
284
|
-
try {
|
|
285
|
-
return JSON.stringify(cache.stats());
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
return '{}';
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
clear() {
|
|
292
|
-
cache.clear();
|
|
293
|
-
},
|
|
294
|
-
tokenCount() {
|
|
295
|
-
return cache.tokenCount;
|
|
296
|
-
},
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
// ── Generate Config ──────────────────────────────────────────
|
|
300
|
-
/**
|
|
301
|
-
* Create a generation config object.
|
|
302
|
-
* Note: f32 precision loss is expected (0.7 → 0.699999...).
|
|
303
|
-
*/
|
|
304
|
-
export async function createGenerateConfig(opts = {}) {
|
|
305
|
-
await initRuvllmWasm();
|
|
306
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
307
|
-
const config = new mod.GenerateConfig();
|
|
308
|
-
if (opts.maxTokens !== undefined)
|
|
309
|
-
config.maxTokens = opts.maxTokens;
|
|
310
|
-
if (opts.temperature !== undefined)
|
|
311
|
-
config.temperature = opts.temperature;
|
|
312
|
-
if (opts.topP !== undefined)
|
|
313
|
-
config.topP = opts.topP;
|
|
314
|
-
if (opts.topK !== undefined)
|
|
315
|
-
config.topK = opts.topK;
|
|
316
|
-
if (opts.repetitionPenalty !== undefined)
|
|
317
|
-
config.repetitionPenalty = opts.repetitionPenalty;
|
|
318
|
-
for (const seq of opts.stopSequences ?? []) {
|
|
319
|
-
config.addStopSequence(seq);
|
|
320
|
-
}
|
|
321
|
-
return config.toJson();
|
|
322
|
-
}
|
|
323
|
-
// ── Buffer Pool ──────────────────────────────────────────────
|
|
324
|
-
/**
|
|
325
|
-
* Create a buffer pool for inference memory management.
|
|
326
|
-
*/
|
|
327
|
-
export async function createBufferPool(capacity) {
|
|
328
|
-
await initRuvllmWasm();
|
|
329
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
330
|
-
const pool = mod.BufferPoolWasm.withCapacity(capacity);
|
|
331
|
-
return {
|
|
332
|
-
prewarm(count) {
|
|
333
|
-
pool.prewarmAll(count);
|
|
334
|
-
},
|
|
335
|
-
stats() {
|
|
336
|
-
return pool.statsJson();
|
|
337
|
-
},
|
|
338
|
-
hitRate() {
|
|
339
|
-
return pool.hitRate;
|
|
340
|
-
},
|
|
341
|
-
clear() {
|
|
342
|
-
pool.clear();
|
|
343
|
-
},
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
// ── Inference Arena ──────────────────────────────────────────
|
|
347
|
-
/**
|
|
348
|
-
* Create an inference arena for model memory allocation.
|
|
349
|
-
*/
|
|
350
|
-
export async function createInferenceArena(opts) {
|
|
351
|
-
await initRuvllmWasm();
|
|
352
|
-
const mod = await import('@ruvector/ruvllm-wasm');
|
|
353
|
-
const arena = 'capacity' in opts
|
|
354
|
-
? new mod.InferenceArenaWasm(opts.capacity)
|
|
355
|
-
: mod.InferenceArenaWasm.forModel(opts.hiddenDim, opts.vocabSize, opts.batchSize);
|
|
356
|
-
return {
|
|
357
|
-
reset() { arena.reset(); },
|
|
358
|
-
used() { return arena.used; },
|
|
359
|
-
capacity() { return arena.capacity; },
|
|
360
|
-
remaining() { return arena.remaining; },
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
//# sourceMappingURL=ruvllm-wasm.js.map
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure JavaScript SemanticRouter implementation
|
|
3
|
-
*
|
|
4
|
-
* Provides intent routing using cosine similarity.
|
|
5
|
-
* This is a fallback implementation since @ruvector/router's native VectorDb has bugs.
|
|
6
|
-
*
|
|
7
|
-
* Performance: ~50,000 routes/sec with 100 intents (sufficient for agent routing)
|
|
8
|
-
*/
|
|
9
|
-
export interface Intent {
|
|
10
|
-
name: string;
|
|
11
|
-
utterances: string[];
|
|
12
|
-
metadata?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
export interface RouteResult {
|
|
15
|
-
intent: string;
|
|
16
|
-
score: number;
|
|
17
|
-
metadata: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
export interface RouterConfig {
|
|
20
|
-
dimension: number;
|
|
21
|
-
metric?: 'cosine' | 'euclidean' | 'dotProduct';
|
|
22
|
-
}
|
|
23
|
-
export declare class SemanticRouter {
|
|
24
|
-
private dimension;
|
|
25
|
-
private metric;
|
|
26
|
-
private intents;
|
|
27
|
-
private totalVectors;
|
|
28
|
-
constructor(config: RouterConfig);
|
|
29
|
-
/**
|
|
30
|
-
* Add an intent with pre-computed embeddings
|
|
31
|
-
*/
|
|
32
|
-
addIntentWithEmbeddings(name: string, embeddings: Float32Array[], metadata?: Record<string, unknown>): void;
|
|
33
|
-
/**
|
|
34
|
-
* Route a query using a pre-computed embedding
|
|
35
|
-
*/
|
|
36
|
-
routeWithEmbedding(embedding: Float32Array, k?: number): RouteResult[];
|
|
37
|
-
/**
|
|
38
|
-
* Remove an intent
|
|
39
|
-
*/
|
|
40
|
-
removeIntent(name: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Get all intent names
|
|
43
|
-
*/
|
|
44
|
-
getIntents(): string[];
|
|
45
|
-
/**
|
|
46
|
-
* Get intent details
|
|
47
|
-
*/
|
|
48
|
-
getIntent(name: string): Intent | null;
|
|
49
|
-
/**
|
|
50
|
-
* Clear all intents
|
|
51
|
-
*/
|
|
52
|
-
clear(): void;
|
|
53
|
-
/**
|
|
54
|
-
* Get total vector count
|
|
55
|
-
*/
|
|
56
|
-
count(): number;
|
|
57
|
-
/**
|
|
58
|
-
* Get number of intents
|
|
59
|
-
*/
|
|
60
|
-
intentCount(): number;
|
|
61
|
-
/**
|
|
62
|
-
* Normalize a vector for cosine similarity
|
|
63
|
-
*/
|
|
64
|
-
private normalize;
|
|
65
|
-
/**
|
|
66
|
-
* Calculate similarity between two normalized vectors
|
|
67
|
-
*/
|
|
68
|
-
private similarity;
|
|
69
|
-
private dotProduct;
|
|
70
|
-
private euclideanDistance;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Create a SemanticRouter with the given configuration
|
|
74
|
-
*/
|
|
75
|
-
export declare function createSemanticRouter(config: RouterConfig): SemanticRouter;
|
|
76
|
-
export default SemanticRouter;
|
|
77
|
-
//# sourceMappingURL=semantic-router.d.ts.map
|