@dalek-ai/router 0.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/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +66 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dalek (@dalekkskaro)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @dalek-ai/router
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for [agent-tool-router](https://github.com/dalek-ai/agent-tool-router) — picks the right tools for an agent task from a catalog of 18 000.
|
|
4
|
+
|
|
5
|
+
The default endpoint is a hosted API at `dalek-ai-router-api.hf.space`. No API key, no signup.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @dalek-ai/router
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node 18+ (uses the built-in `fetch`).
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { route } from "@dalek-ai/router";
|
|
19
|
+
|
|
20
|
+
const result = await route({
|
|
21
|
+
task: "annule ma commande et rembourse-moi",
|
|
22
|
+
k: 3,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
console.log(result.tools);
|
|
26
|
+
// [
|
|
27
|
+
// { name: "get_order_details", score: 0.26 },
|
|
28
|
+
// { name: "get_user_details", score: 0.25 },
|
|
29
|
+
// { name: "return_delivered_order_items", score: 0.24 }
|
|
30
|
+
// ]
|
|
31
|
+
console.log(result.model); // "baseline-v1-desc-hybrid-multilingual-next-v1"
|
|
32
|
+
console.log(result.latency_ms); // ~200
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### History-aware routing
|
|
36
|
+
|
|
37
|
+
Pass the previous tools called to bias the next-tool prediction (uses a Markov-2 history bigram with stupid-backoff under the hood):
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const result = await route({
|
|
41
|
+
task: "rembourse-moi maintenant",
|
|
42
|
+
history: ["get_order_details", "verify_refund_eligibility"],
|
|
43
|
+
k: 3,
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Reusable client
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { Router } from "@dalek-ai/router";
|
|
51
|
+
|
|
52
|
+
const r = new Router(); // defaults to https://dalek-ai-router-api.hf.space
|
|
53
|
+
const top3 = await r.route("send slack to my team");
|
|
54
|
+
|
|
55
|
+
// or point at a self-hosted instance
|
|
56
|
+
const self = new Router("https://router.mycompany.internal");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Errors
|
|
60
|
+
|
|
61
|
+
Failed requests throw `RouterError` with `.status` and `.body`:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { RouterError } from "@dalek-ai/router";
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
await route({ task: "..." });
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (e instanceof RouterError) console.error(e.status, e.body);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Hosted API specs
|
|
74
|
+
|
|
75
|
+
- URL: `https://dalek-ai-router-api.hf.space`
|
|
76
|
+
- Median latency: ~200 ms (shared free CPU on Hugging Face Spaces)
|
|
77
|
+
- Default model: `baseline-v1-desc-hybrid-multilingual-next-v1` (FR + EN, Pareto-dominates 3 LOSO benchmarks)
|
|
78
|
+
- Rate limits: HF Spaces public quotas (generous, not for production scale)
|
|
79
|
+
- Higher limits / private deployments: drop your handle on the [Waitlist discussion](https://github.com/dalek-ai/agent-tool-router/discussions/1)
|
|
80
|
+
|
|
81
|
+
## Numbers
|
|
82
|
+
|
|
83
|
+
- 18 671 tools indexed (Hermes function-calling, ToolACE, tau-bench)
|
|
84
|
+
- 14 000 agent traces in the training corpus
|
|
85
|
+
- 77.4% top-3 next-tool accuracy (Markov-2 backoff on the multilingual encoder)
|
|
86
|
+
- 100% top-3 on tau-bench position 2 (228 test calls, zero errors at this horizon)
|
|
87
|
+
- 9 ms p50 latency in-process (local MacBook MPS) with the Python SDK
|
|
88
|
+
|
|
89
|
+
Full benchmark numbers, eval scripts, and the dataset rebuild script:
|
|
90
|
+
[github.com/dalek-ai/agent-tool-router](https://github.com/dalek-ai/agent-tool-router)
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dalek-ai/router — TypeScript SDK for the agent-tool-router hosted API.
|
|
3
|
+
* https://github.com/dalek-ai/agent-tool-router
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_API_URL = "https://dalek-ai-router-api.hf.space";
|
|
6
|
+
export interface RouteOptions {
|
|
7
|
+
task: string;
|
|
8
|
+
k?: number;
|
|
9
|
+
history?: string[];
|
|
10
|
+
model?: string;
|
|
11
|
+
apiUrl?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface RouteResultTool {
|
|
15
|
+
name: string;
|
|
16
|
+
score: number;
|
|
17
|
+
}
|
|
18
|
+
export interface RouteResult {
|
|
19
|
+
tools: RouteResultTool[];
|
|
20
|
+
model: string;
|
|
21
|
+
latency_ms: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class RouterError extends Error {
|
|
24
|
+
status?: number;
|
|
25
|
+
body?: string;
|
|
26
|
+
constructor(message: string, status?: number, body?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare function route(opts: RouteOptions): Promise<RouteResult>;
|
|
29
|
+
export declare class Router {
|
|
30
|
+
private readonly apiUrl;
|
|
31
|
+
private readonly defaultModel?;
|
|
32
|
+
constructor(apiUrl?: string, defaultModel?: string);
|
|
33
|
+
route(task: string, opts?: {
|
|
34
|
+
k?: number;
|
|
35
|
+
history?: string[];
|
|
36
|
+
model?: string;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}): Promise<RouteResult>;
|
|
39
|
+
health(signal?: AbortSignal): Promise<{
|
|
40
|
+
status: string;
|
|
41
|
+
models_loaded: number;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dalek-ai/router — TypeScript SDK for the agent-tool-router hosted API.
|
|
4
|
+
* https://github.com/dalek-ai/agent-tool-router
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Router = exports.RouterError = exports.DEFAULT_API_URL = void 0;
|
|
8
|
+
exports.route = route;
|
|
9
|
+
exports.DEFAULT_API_URL = "https://dalek-ai-router-api.hf.space";
|
|
10
|
+
class RouterError extends Error {
|
|
11
|
+
constructor(message, status, body) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "RouterError";
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.body = body;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.RouterError = RouterError;
|
|
19
|
+
async function route(opts) {
|
|
20
|
+
if (!opts.task || typeof opts.task !== "string") {
|
|
21
|
+
throw new RouterError("`task` must be a non-empty string");
|
|
22
|
+
}
|
|
23
|
+
const url = (opts.apiUrl ?? exports.DEFAULT_API_URL).replace(/\/$/, "") + "/route";
|
|
24
|
+
const payload = {
|
|
25
|
+
task: opts.task,
|
|
26
|
+
k: opts.k ?? 3,
|
|
27
|
+
};
|
|
28
|
+
if (opts.history && opts.history.length > 0)
|
|
29
|
+
payload.history = opts.history;
|
|
30
|
+
if (opts.model)
|
|
31
|
+
payload.model = opts.model;
|
|
32
|
+
const res = await fetch(url, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: { "Content-Type": "application/json" },
|
|
35
|
+
body: JSON.stringify(payload),
|
|
36
|
+
signal: opts.signal,
|
|
37
|
+
});
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
const body = await res.text().catch(() => "");
|
|
40
|
+
throw new RouterError(`Router API ${res.status} ${res.statusText}`, res.status, body);
|
|
41
|
+
}
|
|
42
|
+
return (await res.json());
|
|
43
|
+
}
|
|
44
|
+
class Router {
|
|
45
|
+
constructor(apiUrl = exports.DEFAULT_API_URL, defaultModel) {
|
|
46
|
+
this.apiUrl = apiUrl;
|
|
47
|
+
this.defaultModel = defaultModel;
|
|
48
|
+
}
|
|
49
|
+
async route(task, opts) {
|
|
50
|
+
return route({
|
|
51
|
+
task,
|
|
52
|
+
k: opts?.k,
|
|
53
|
+
history: opts?.history,
|
|
54
|
+
model: opts?.model ?? this.defaultModel,
|
|
55
|
+
apiUrl: this.apiUrl,
|
|
56
|
+
signal: opts?.signal,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async health(signal) {
|
|
60
|
+
const res = await fetch(this.apiUrl.replace(/\/$/, "") + "/health", { signal });
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw new RouterError(`health ${res.status}`, res.status);
|
|
63
|
+
return (await res.json());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.Router = Router;
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dalek-ai/router",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the agent-tool-router hosted API. Picks the right tools for an agent task from a catalog of 18 000.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"agent",
|
|
18
|
+
"agents",
|
|
19
|
+
"tool-routing",
|
|
20
|
+
"tool-calling",
|
|
21
|
+
"function-calling",
|
|
22
|
+
"llm",
|
|
23
|
+
"mcp",
|
|
24
|
+
"router"
|
|
25
|
+
],
|
|
26
|
+
"author": "Dalek",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/dalek-ai/agent-tool-router.git",
|
|
31
|
+
"directory": "router/sdk/typescript"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/dalek-ai/agent-tool-router",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/dalek-ai/agent-tool-router/issues"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.6.0"
|
|
45
|
+
}
|
|
46
|
+
}
|