ruvector 0.1.62 → 0.1.64

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.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Router Wrapper - Semantic router for AI agent intent matching
3
+ *
4
+ * Wraps @ruvector/router for vector-based intent classification.
5
+ * Perfect for hooks to route tasks to the right agent.
6
+ */
7
+ export declare function isRouterAvailable(): boolean;
8
+ export interface Route {
9
+ name: string;
10
+ utterances: string[];
11
+ metadata?: Record<string, any>;
12
+ }
13
+ export interface RouteMatch {
14
+ route: string;
15
+ score: number;
16
+ metadata?: Record<string, any>;
17
+ }
18
+ /**
19
+ * Semantic Router for agent task routing
20
+ */
21
+ export declare class SemanticRouter {
22
+ private inner;
23
+ private routes;
24
+ constructor(options?: {
25
+ dimensions?: number;
26
+ threshold?: number;
27
+ });
28
+ /**
29
+ * Add a route with example utterances
30
+ */
31
+ addRoute(name: string, utterances: string[], metadata?: Record<string, any>): void;
32
+ /**
33
+ * Add multiple routes at once
34
+ */
35
+ addRoutes(routes: Route[]): void;
36
+ /**
37
+ * Match input to best route
38
+ */
39
+ match(input: string): RouteMatch | null;
40
+ /**
41
+ * Get top-k route matches
42
+ */
43
+ matchTopK(input: string, k?: number): RouteMatch[];
44
+ /**
45
+ * Get all registered routes
46
+ */
47
+ getRoutes(): Route[];
48
+ /**
49
+ * Remove a route
50
+ */
51
+ removeRoute(name: string): boolean;
52
+ /**
53
+ * Clear all routes
54
+ */
55
+ clear(): void;
56
+ }
57
+ /**
58
+ * Create a pre-configured agent router for hooks
59
+ */
60
+ export declare function createAgentRouter(): SemanticRouter;
61
+ export default SemanticRouter;
62
+ //# sourceMappingURL=router-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/router-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,wBAAgB,iBAAiB,IAAI,OAAO,CAO3C;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,MAAM,CAAiC;gBAEnC,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO;IAQrE;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKlF;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI;IAMhC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAWvC;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,GAAE,MAAU,GAAG,UAAU,EAAE;IASrD;;OAEG;IACH,SAAS,IAAI,KAAK,EAAE;IAIpB;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMlC;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CA8FlD;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ /**
3
+ * Router Wrapper - Semantic router for AI agent intent matching
4
+ *
5
+ * Wraps @ruvector/router for vector-based intent classification.
6
+ * Perfect for hooks to route tasks to the right agent.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SemanticRouter = void 0;
10
+ exports.isRouterAvailable = isRouterAvailable;
11
+ exports.createAgentRouter = createAgentRouter;
12
+ let routerModule = null;
13
+ let loadError = null;
14
+ function getRouterModule() {
15
+ if (routerModule)
16
+ return routerModule;
17
+ if (loadError)
18
+ throw loadError;
19
+ try {
20
+ routerModule = require('@ruvector/router');
21
+ return routerModule;
22
+ }
23
+ catch (e) {
24
+ loadError = new Error(`@ruvector/router not installed: ${e.message}\n` +
25
+ `Install with: npm install @ruvector/router`);
26
+ throw loadError;
27
+ }
28
+ }
29
+ function isRouterAvailable() {
30
+ try {
31
+ getRouterModule();
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ /**
39
+ * Semantic Router for agent task routing
40
+ */
41
+ class SemanticRouter {
42
+ constructor(options = {}) {
43
+ this.routes = new Map();
44
+ const router = getRouterModule();
45
+ this.inner = new router.SemanticRouter({
46
+ dimensions: options.dimensions ?? 384,
47
+ threshold: options.threshold ?? 0.7,
48
+ });
49
+ }
50
+ /**
51
+ * Add a route with example utterances
52
+ */
53
+ addRoute(name, utterances, metadata) {
54
+ this.routes.set(name, { name, utterances, metadata });
55
+ this.inner.addRoute(name, utterances, metadata ? JSON.stringify(metadata) : undefined);
56
+ }
57
+ /**
58
+ * Add multiple routes at once
59
+ */
60
+ addRoutes(routes) {
61
+ for (const route of routes) {
62
+ this.addRoute(route.name, route.utterances, route.metadata);
63
+ }
64
+ }
65
+ /**
66
+ * Match input to best route
67
+ */
68
+ match(input) {
69
+ const result = this.inner.match(input);
70
+ if (!result)
71
+ return null;
72
+ return {
73
+ route: result.route,
74
+ score: result.score,
75
+ metadata: result.metadata ? JSON.parse(result.metadata) : undefined,
76
+ };
77
+ }
78
+ /**
79
+ * Get top-k route matches
80
+ */
81
+ matchTopK(input, k = 3) {
82
+ const results = this.inner.matchTopK(input, k);
83
+ return results.map((r) => ({
84
+ route: r.route,
85
+ score: r.score,
86
+ metadata: r.metadata ? JSON.parse(r.metadata) : undefined,
87
+ }));
88
+ }
89
+ /**
90
+ * Get all registered routes
91
+ */
92
+ getRoutes() {
93
+ return Array.from(this.routes.values());
94
+ }
95
+ /**
96
+ * Remove a route
97
+ */
98
+ removeRoute(name) {
99
+ if (!this.routes.has(name))
100
+ return false;
101
+ this.routes.delete(name);
102
+ return this.inner.removeRoute(name);
103
+ }
104
+ /**
105
+ * Clear all routes
106
+ */
107
+ clear() {
108
+ this.routes.clear();
109
+ this.inner.clear();
110
+ }
111
+ }
112
+ exports.SemanticRouter = SemanticRouter;
113
+ /**
114
+ * Create a pre-configured agent router for hooks
115
+ */
116
+ function createAgentRouter() {
117
+ const router = new SemanticRouter({ threshold: 0.6 });
118
+ // Add common agent routes
119
+ router.addRoutes([
120
+ {
121
+ name: 'coder',
122
+ utterances: [
123
+ 'implement feature',
124
+ 'write code',
125
+ 'create function',
126
+ 'add method',
127
+ 'build component',
128
+ 'fix bug',
129
+ 'update implementation',
130
+ ],
131
+ metadata: { type: 'development' },
132
+ },
133
+ {
134
+ name: 'reviewer',
135
+ utterances: [
136
+ 'review code',
137
+ 'check quality',
138
+ 'find issues',
139
+ 'suggest improvements',
140
+ 'analyze code',
141
+ 'code review',
142
+ ],
143
+ metadata: { type: 'review' },
144
+ },
145
+ {
146
+ name: 'tester',
147
+ utterances: [
148
+ 'write tests',
149
+ 'add test cases',
150
+ 'create unit tests',
151
+ 'test coverage',
152
+ 'integration tests',
153
+ 'verify functionality',
154
+ ],
155
+ metadata: { type: 'testing' },
156
+ },
157
+ {
158
+ name: 'researcher',
159
+ utterances: [
160
+ 'research topic',
161
+ 'find information',
162
+ 'explore options',
163
+ 'investigate',
164
+ 'analyze requirements',
165
+ 'understand codebase',
166
+ ],
167
+ metadata: { type: 'research' },
168
+ },
169
+ {
170
+ name: 'architect',
171
+ utterances: [
172
+ 'design system',
173
+ 'architecture',
174
+ 'structure project',
175
+ 'plan implementation',
176
+ 'design patterns',
177
+ 'system design',
178
+ ],
179
+ metadata: { type: 'architecture' },
180
+ },
181
+ {
182
+ name: 'devops',
183
+ utterances: [
184
+ 'deploy',
185
+ 'ci/cd',
186
+ 'docker',
187
+ 'kubernetes',
188
+ 'infrastructure',
189
+ 'build pipeline',
190
+ 'github actions',
191
+ ],
192
+ metadata: { type: 'devops' },
193
+ },
194
+ {
195
+ name: 'security',
196
+ utterances: [
197
+ 'security audit',
198
+ 'vulnerability',
199
+ 'authentication',
200
+ 'authorization',
201
+ 'secure code',
202
+ 'penetration test',
203
+ ],
204
+ metadata: { type: 'security' },
205
+ },
206
+ ]);
207
+ return router;
208
+ }
209
+ exports.default = SemanticRouter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruvector",
3
- "version": "0.1.62",
3
+ "version": "0.1.64",
4
4
  "description": "High-performance vector database for Node.js with automatic native/WASM fallback",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/ruvector.db CHANGED
Binary file