@mupt-ai/dari-router 0.2.1 → 0.2.2
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 +1 -1
- package/dist/anonymous_actions.d.ts +31 -2
- package/dist/anonymous_actions.js +225 -16
- package/dist/anonymous_actions.js.map +1 -1
- package/dist/cache_behavior.d.ts +1 -1
- package/dist/cache_behavior.js +23 -14
- package/dist/cache_behavior.js.map +1 -1
- package/dist/cache_scope.js +14 -7
- package/dist/cache_scope.js.map +1 -1
- package/dist/candidate_resolution.d.ts +2 -1
- package/dist/candidate_resolution.js +5 -2
- package/dist/candidate_resolution.js.map +1 -1
- package/dist/compatibility.d.ts +1 -0
- package/dist/compatibility.js +6 -0
- package/dist/compatibility.js.map +1 -1
- package/dist/continuation_state.d.ts +12 -0
- package/dist/continuation_state.js +48 -7
- package/dist/continuation_state.js.map +1 -1
- package/dist/cost.d.ts +8 -0
- package/dist/cost.js +47 -30
- package/dist/cost.js.map +1 -1
- package/dist/dari_policy.d.ts +1 -1
- package/dist/dari_policy.js +4 -2
- package/dist/dari_policy.js.map +1 -1
- package/dist/eval_score_imputation.d.ts +1 -0
- package/dist/eval_score_imputation.js +27 -2
- package/dist/eval_score_imputation.js.map +1 -1
- package/dist/fingerprint.js +45 -12
- package/dist/fingerprint.js.map +1 -1
- package/dist/fixed_turn_cost_config.d.ts +2 -0
- package/dist/fixed_turn_cost_config.js +7 -0
- package/dist/fixed_turn_cost_config.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jev_router.d.ts +5 -0
- package/dist/jev_router.js +22 -0
- package/dist/jev_router.js.map +1 -0
- package/dist/jev_selector.d.ts +77 -0
- package/dist/jev_selector.js +418 -0
- package/dist/jev_selector.js.map +1 -0
- package/dist/model_ids.d.ts +1 -0
- package/dist/model_ids.js +26 -0
- package/dist/model_ids.js.map +1 -1
- package/dist/pi_context.js +37 -6
- package/dist/pi_context.js.map +1 -1
- package/dist/pi_options.js +6 -3
- package/dist/pi_options.js.map +1 -1
- package/dist/policy-engine.d.ts +1 -0
- package/dist/policy-engine.js +1 -0
- package/dist/policy-engine.js.map +1 -1
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.js +21 -4
- package/dist/prompts.js.map +1 -1
- package/dist/route.d.ts +3 -0
- package/dist/route.js +64 -5
- package/dist/route.js.map +1 -1
- package/dist/routing_history.d.ts +1 -0
- package/dist/routing_history.js +2 -0
- package/dist/routing_history.js.map +1 -1
- package/dist/selector_input.d.ts +26 -1
- package/dist/selector_input.js +17 -1
- package/dist/selector_input.js.map +1 -1
- package/dist/selector_request.d.ts +3 -1
- package/dist/selector_request.js +52 -12
- package/dist/selector_request.js.map +1 -1
- package/dist/selector_truncation.d.ts +2 -0
- package/dist/selector_truncation.js +42 -0
- package/dist/selector_truncation.js.map +1 -1
- package/dist/types.d.ts +9 -2
- package/examples/basic_route.ts +1 -1
- package/examples/jev_router.ts +50 -0
- package/examples/managed/README.md +2 -2
- package/examples/managed/byok-router/router.yml +1 -1
- package/examples/managed/custom-rules-router/router.yml +5 -5
- package/examples/managed/{slm-router → dari}/README.md +1 -1
- package/examples/managed/{slm-router → dari}/router.yml +2 -2
- package/examples/managed/eval-router/router.yml +1 -1
- package/package.json +4 -3
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
// conversation; the eventual provider call still receives the full request.
|
|
3
3
|
import { isRecord } from "./types.js";
|
|
4
4
|
const SELECTOR_TRUNCATION_MARKER = "<earlier messages truncated for routing>";
|
|
5
|
+
const TASK_TRUNCATION_MARKER = "\n...[original task truncated for routing]...\n";
|
|
6
|
+
const TASK_OMITTED_PLACEHOLDER = "<original task omitted for routing>";
|
|
5
7
|
const MARKER_MESSAGE = { role: "user", content: SELECTOR_TRUNCATION_MARKER };
|
|
8
|
+
// Maximum removable history while keeping the latest message intact. Sizing
|
|
9
|
+
// uses this before compacting a separately retained task or the latest turn.
|
|
10
|
+
export function olderMessageChars(messages) {
|
|
11
|
+
if (messages.length <= 1)
|
|
12
|
+
return 0;
|
|
13
|
+
return Math.max(0, JSON.stringify(messages).length - JSON.stringify([MARKER_MESSAGE, messages.at(-1)]).length);
|
|
14
|
+
}
|
|
6
15
|
// Drop oldest messages first — in multi-turn conversations the latest
|
|
7
16
|
// messages carry the routing signal.
|
|
8
17
|
export function trimMessagesFromFront(messages, dropChars) {
|
|
@@ -31,6 +40,39 @@ export function trimMessagesFromFront(messages, dropChars) {
|
|
|
31
40
|
}
|
|
32
41
|
return [MARKER_MESSAGE];
|
|
33
42
|
}
|
|
43
|
+
// The original task normally stays intact even when conversation history is
|
|
44
|
+
// compacted. If that retained task alone exceeds the selector window, preserve
|
|
45
|
+
// both ends so the request and its trailing constraints remain visible.
|
|
46
|
+
export function trimTaskMessage(task, dropChars) {
|
|
47
|
+
const targetLength = Math.max(0, JSON.stringify(task).length - Math.max(0, dropChars));
|
|
48
|
+
if (JSON.stringify(task).length <= targetLength)
|
|
49
|
+
return task;
|
|
50
|
+
const source = trimSourceContent(task);
|
|
51
|
+
if (source === null)
|
|
52
|
+
return { role: task.role, content: TASK_OMITTED_PLACEHOLDER };
|
|
53
|
+
let contentChars = source.length;
|
|
54
|
+
while (contentChars > 0) {
|
|
55
|
+
const candidate = {
|
|
56
|
+
role: task.role,
|
|
57
|
+
content: elideTaskMiddle(source, contentChars),
|
|
58
|
+
};
|
|
59
|
+
const excess = JSON.stringify(candidate).length - targetLength;
|
|
60
|
+
if (excess <= 0)
|
|
61
|
+
return candidate;
|
|
62
|
+
contentChars = Math.max(0, contentChars - excess);
|
|
63
|
+
}
|
|
64
|
+
return { role: task.role, content: TASK_OMITTED_PLACEHOLDER };
|
|
65
|
+
}
|
|
66
|
+
function elideTaskMiddle(value, maxChars) {
|
|
67
|
+
if (value.length <= maxChars)
|
|
68
|
+
return value;
|
|
69
|
+
if (maxChars <= TASK_TRUNCATION_MARKER.length) {
|
|
70
|
+
return TASK_TRUNCATION_MARKER.slice(0, maxChars);
|
|
71
|
+
}
|
|
72
|
+
const retainedChars = maxChars - TASK_TRUNCATION_MARKER.length;
|
|
73
|
+
const prefixChars = Math.ceil(retainedChars / 2);
|
|
74
|
+
return `${value.slice(0, prefixChars)}${TASK_TRUNCATION_MARKER}${value.slice(-(retainedChars - prefixChars))}`;
|
|
75
|
+
}
|
|
34
76
|
function trimSourceContent(message) {
|
|
35
77
|
if (typeof message.content === "string")
|
|
36
78
|
return message.content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector_truncation.js","sourceRoot":"","sources":["../src/selector_truncation.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAE5E,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAExD,MAAM,0BAA0B,GAAG,0CAA0C,CAAC;AAC9E,MAAM,cAAc,GAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAE1F,sEAAsE;AACtE,qCAAqC;AACrC,MAAM,UAAU,qBAAqB,CAAC,QAAuB,EAAE,SAAiB;IAC9E,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC3F,MAAM,IAAI,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,YAAY,EAAE,CAAC;QAC1F,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,IAAI,IAAI,CAAC,SAAS,CAAC,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I,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export type RouterPrefixHit = {
|
|
|
99
99
|
reason: string | null;
|
|
100
100
|
updated_at: string;
|
|
101
101
|
};
|
|
102
|
-
export type RoutingStrategy = "
|
|
102
|
+
export type RoutingStrategy = "dari" | "custom";
|
|
103
103
|
export type CustomRouterRule = {
|
|
104
104
|
when: string;
|
|
105
105
|
use: string;
|
|
@@ -115,6 +115,13 @@ export type RouterModelPrice = {
|
|
|
115
115
|
output: number;
|
|
116
116
|
cached_input?: number | null;
|
|
117
117
|
cache_write?: number | null;
|
|
118
|
+
tiers?: Array<{
|
|
119
|
+
input_tokens_above: number;
|
|
120
|
+
input: number;
|
|
121
|
+
output: number;
|
|
122
|
+
cached_input?: number | null;
|
|
123
|
+
cache_write?: number | null;
|
|
124
|
+
}>;
|
|
118
125
|
};
|
|
119
126
|
export type PrefixHit = {
|
|
120
127
|
entry: RouterPrefixHit;
|
|
@@ -149,4 +156,4 @@ export type PreviousDecision = {
|
|
|
149
156
|
reasoningEffort: ReasoningEffort;
|
|
150
157
|
reason: string;
|
|
151
158
|
};
|
|
152
|
-
export type HardCapability = "image_input" | "structured_output" | "openai_hosted_web_search";
|
|
159
|
+
export type HardCapability = "image_input" | "structured_output" | "openai_hosted_web_search" | "reasoning_configuration_update";
|
package/examples/basic_route.ts
CHANGED
|
@@ -58,7 +58,7 @@ const input: RouteInput = {
|
|
|
58
58
|
return entry;
|
|
59
59
|
},
|
|
60
60
|
requiredCapabilities: [],
|
|
61
|
-
strategy: "
|
|
61
|
+
strategy: "dari",
|
|
62
62
|
pricing: (model) => pricing[model] ?? null,
|
|
63
63
|
// Keep the candidate list broad but the pairs manageable: pin each model to
|
|
64
64
|
// a subset of its supported levels, as a router configuration would.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Jev Router — route with TypeSafe's Jev System One model instead of Dari's
|
|
2
|
+
// trained routing policy. Jev answers two typed questions per request (which candidate,
|
|
3
|
+
// how long a lease) and returns calibrated probabilities; the decision is
|
|
4
|
+
// built from those answers in this package.
|
|
5
|
+
//
|
|
6
|
+
// Requires TYPESAFE_API_KEY, OPENAI_API_KEY, and ANTHROPIC_API_KEY.
|
|
7
|
+
|
|
8
|
+
import { createJevRouter, createPiRuntime, createRouter } from "../src/index.js";
|
|
9
|
+
|
|
10
|
+
const pi = await createPiRuntime({
|
|
11
|
+
apiKey: ({ provider }) => {
|
|
12
|
+
const key = process.env[`${provider.toUpperCase()}_API_KEY`];
|
|
13
|
+
if (!key) throw new Error(`Missing ${provider.toUpperCase()}_API_KEY`);
|
|
14
|
+
return key;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const SOL = "openai/gpt-5.6-sol";
|
|
19
|
+
const SONNET = "anthropic/claude-sonnet-5";
|
|
20
|
+
|
|
21
|
+
const router = createRouter({
|
|
22
|
+
models: [pi.model(SOL), pi.model(SONNET)],
|
|
23
|
+
policy: createJevRouter({
|
|
24
|
+
apiKey: process.env.TYPESAFE_API_KEY!,
|
|
25
|
+
// Jev routes on cost evidence you supply; these are per-million-token USD
|
|
26
|
+
// prices and observed output-token averages for each enabled pair.
|
|
27
|
+
pricing: (model) => model === SOL
|
|
28
|
+
? { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 }
|
|
29
|
+
: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
30
|
+
averageOutputTokensByModel: {
|
|
31
|
+
[SOL]: { medium: 800 },
|
|
32
|
+
[SONNET]: { medium: 800 },
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
executor: pi,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const response = await router.fetch(
|
|
39
|
+
new Request("https://example.test/v1/chat/completions", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
model: "dari/routing",
|
|
44
|
+
messages: [{ role: "user", content: "Explain speculative decoding in one paragraph." }],
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (!response.ok) throw new Error(await response.text());
|
|
50
|
+
console.log(response.headers.get("X-Router-Selected-Model"), await response.json());
|
|
@@ -16,7 +16,7 @@ Your organization needs access to the providers and models used by an example. F
|
|
|
16
16
|
|
|
17
17
|
## Examples
|
|
18
18
|
|
|
19
|
-
- [`
|
|
19
|
+
- [`dari/`](dari) — automatic selection with managed provider credentials.
|
|
20
20
|
- [`byok-router/`](byok-router) — automatic selection with a provider key from your environment.
|
|
21
21
|
- [`custom-rules-router/`](custom-rules-router) — natural-language rules with explicit model and reasoning-level constraints.
|
|
22
22
|
- [`eval-router/`](eval-router) — automatic selection informed by an organization eval scorecard.
|
|
@@ -26,7 +26,7 @@ Your organization needs access to the providers and models used by an example. F
|
|
|
26
26
|
From an example directory:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
cd examples/managed/
|
|
29
|
+
cd examples/managed/dari
|
|
30
30
|
dari router create ./router.yml
|
|
31
31
|
dari router get <router_id>
|
|
32
32
|
```
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
name: Example Custom Rules Router
|
|
2
2
|
enabled_models:
|
|
3
3
|
- openai/gpt-5.6-sol
|
|
4
|
-
- deepseek-ai/DeepSeek-V4-Flash
|
|
4
|
+
- deepseek-ai/DeepSeek-V4.1-Flash
|
|
5
5
|
model_providers:
|
|
6
6
|
openai/gpt-5.6-sol: openai
|
|
7
|
-
deepseek-ai/DeepSeek-V4-Flash
|
|
7
|
+
deepseek-ai/DeepSeek-V4.1-Flash: fireworks
|
|
8
8
|
model_thinking_levels:
|
|
9
9
|
openai/gpt-5.6-sol: [low, medium, high]
|
|
10
|
-
deepseek-ai/DeepSeek-V4-Flash
|
|
10
|
+
deepseek-ai/DeepSeek-V4.1-Flash: [off]
|
|
11
11
|
provider_key_sources:
|
|
12
12
|
openai: managed
|
|
13
13
|
fireworks: managed
|
|
@@ -18,7 +18,7 @@ custom_config:
|
|
|
18
18
|
use: openai/gpt-5.6-sol
|
|
19
19
|
thinking_level: high
|
|
20
20
|
- when: short questions and straightforward implementation
|
|
21
|
-
use: deepseek-ai/DeepSeek-V4-Flash
|
|
21
|
+
use: deepseek-ai/DeepSeek-V4.1-Flash
|
|
22
22
|
thinking_level: off
|
|
23
|
-
default: deepseek-ai/DeepSeek-V4-Flash
|
|
23
|
+
default: deepseek-ai/DeepSeek-V4.1-Flash
|
|
24
24
|
default_thinking_level: off
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mupt-ai/dari-router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "End-to-end TypeScript framework for routing across LLMs with built-in Pi AI execution and pluggable policies and executors.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -63,11 +63,12 @@
|
|
|
63
63
|
"example": "bun run examples/create_router.ts",
|
|
64
64
|
"example:pi": "bun run examples/pi_runtime.ts",
|
|
65
65
|
"example:dari-policy": "bun run examples/dari_policy.ts",
|
|
66
|
+
"example:jev": "bun run examples/jev_router.ts",
|
|
66
67
|
"example:decision-pipeline": "bun run examples/basic_route.ts",
|
|
67
68
|
"example:lease-stores": "bun run examples/lease_stores.ts"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@mupt-ai/pi-ai": ">=0.80.6-mupt.
|
|
71
|
+
"@mupt-ai/pi-ai": ">=0.80.6-mupt.6 <0.81.0"
|
|
71
72
|
},
|
|
72
73
|
"peerDependenciesMeta": {
|
|
73
74
|
"@mupt-ai/pi-ai": {
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
}
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
|
-
"@mupt-ai/pi-ai": "0.80.6-mupt.
|
|
79
|
+
"@mupt-ai/pi-ai": "0.80.6-mupt.6",
|
|
79
80
|
"@types/bun": "^1.3.4",
|
|
80
81
|
"@types/node": "^24.10.2",
|
|
81
82
|
"typescript": "^5.6.3"
|