@van1s1mys/ai-router 1.0.0 → 1.1.0

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/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @van1s1mys/ai-router
2
+
3
+ Semantic search routing for SPAs — find the best route by meaning, not keywords.
4
+
5
+ Runs a HuggingFace embedding model inside a **Web Worker** and uses [Orama](https://orama.com) hybrid (text + vector) search to match user queries by semantic similarity.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @van1s1mys/ai-router
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { SmartRouter } from '@van1s1mys/ai-router';
17
+
18
+ const router = new SmartRouter({
19
+ routes: [
20
+ { path: '/pricing', title: 'Pricing', description: 'cost, plans, subscription' },
21
+ { path: '/contact', title: 'Contact', description: 'support, phone, address' },
22
+ { path: '/docs', title: 'Docs', description: 'documentation, API, guides' },
23
+ ],
24
+ threshold: 0.5,
25
+ });
26
+
27
+ await router.ready; // model loads (~22 MB, cached after first run)
28
+
29
+ const result = await router.search('how to reach support?');
30
+ // { path: '/contact', score: 0.91 }
31
+
32
+ router.destroy(); // cleanup when done
33
+ ```
34
+
35
+ ## Multilingual support
36
+
37
+ The default model (`Xenova/all-MiniLM-L6-v2`) works best for English. For other languages, use the multilingual model:
38
+
39
+ ```ts
40
+ const router = new SmartRouter({
41
+ routes,
42
+ model: 'Xenova/multilingual-e5-small',
43
+ });
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `new SmartRouter(options)`
49
+
50
+ | Option | Type | Default | Description |
51
+ |---|---|---|---|
52
+ | `routes` | `RouteConfig[]` | required | Routes to index |
53
+ | `model` | `string` | `"Xenova/all-MiniLM-L6-v2"` | HuggingFace model ID (384-dim) |
54
+ | `threshold` | `number` | `0.5` | Minimum similarity score (0-1) |
55
+
56
+ ### `router.ready: Promise<void>`
57
+
58
+ Resolves when the model is loaded and routes are indexed. Resolves immediately during SSR.
59
+
60
+ ### `router.search(query): Promise<SearchResult | null>`
61
+
62
+ Returns `{ path, score }` or `null` if no route meets the threshold. Returns `null` during SSR.
63
+
64
+ ### `router.destroy()`
65
+
66
+ Terminates the worker and cleans up resources. Safe to call multiple times.
67
+
68
+ ## SSR
69
+
70
+ SSR-safe out of the box. On the server `ready` resolves immediately and `search()` returns `null`. The worker is only spawned in the browser.
71
+
72
+ ## Framework plugins
73
+
74
+ Auto-scan your pages directory instead of listing routes manually:
75
+
76
+ - [`@van1s1mys/ai-router-plugin-vite`](https://www.npmjs.com/package/@van1s1mys/ai-router-plugin-vite)
77
+ - [`@van1s1mys/ai-router-plugin-next`](https://www.npmjs.com/package/@van1s1mys/ai-router-plugin-next)
78
+ - [`@van1s1mys/ai-router-plugin-webpack`](https://www.npmjs.com/package/@van1s1mys/ai-router-plugin-webpack)
79
+
80
+ ## License
81
+
82
+ [MIT](../../LICENSE) &copy; [IvanMalkS](https://github.com/IvanMalkS)