@kdejaeger/pi-model-router 0.3.1 → 0.4.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 +0 -6
- package/extensions/provider.ts +7 -7
- package/extensions/routing.ts +2 -1
- package/package.json +5 -5
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -460,9 +460,3 @@ The classifier gating notifications show why the classifier ran or was skipped (
|
|
|
460
460
|
## Architecture
|
|
461
461
|
|
|
462
462
|
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for a detailed architectural deep dive, including the decision flow, module responsibilities, state persistence, and fallback chain design.
|
|
463
|
-
|
|
464
|
-
---
|
|
465
|
-
|
|
466
|
-
## License
|
|
467
|
-
|
|
468
|
-
MIT (c) Ye Liu
|
package/extensions/provider.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
createAssistantMessageEventStream,
|
|
7
7
|
type Model,
|
|
8
8
|
type SimpleStreamOptions,
|
|
9
|
-
streamSimple
|
|
10
9
|
} from '@earendil-works/pi-ai';
|
|
10
|
+
import { streamSimple } from '@earendil-works/pi-ai/compat';
|
|
11
11
|
import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
12
12
|
import type { RouterConfig, RouterPinByProfile, RouterTier, RoutingDecision } from './types';
|
|
13
13
|
import { createOpenRouterOnPayload, OPENROUTER_ATTR_HEADERS, parseCanonicalModelRef, profileNames, resolveModelFromRef, ROUTER_TIERS } from './config';
|
|
@@ -95,7 +95,7 @@ export const registerRouterProvider = (
|
|
|
95
95
|
const models = profileNames(currentConfig).map((name) => {
|
|
96
96
|
const profile = currentConfig.profiles[name];
|
|
97
97
|
let maxContextWindow = 0;
|
|
98
|
-
let
|
|
98
|
+
let maxTokens = 0;
|
|
99
99
|
|
|
100
100
|
if (state.currentModelRegistry) {
|
|
101
101
|
for (const tier of ROUTER_TIERS) {
|
|
@@ -108,7 +108,7 @@ export const registerRouterProvider = (
|
|
|
108
108
|
const currentContextWindow = model.contextWindow ?? 0;
|
|
109
109
|
if (currentContextWindow > maxContextWindow) {
|
|
110
110
|
maxContextWindow = currentContextWindow;
|
|
111
|
-
|
|
111
|
+
maxTokens = model.maxTokens ?? 120_000;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -116,7 +116,7 @@ export const registerRouterProvider = (
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
if (maxContextWindow === 0) maxContextWindow = 1_000_000;
|
|
119
|
-
if (
|
|
119
|
+
if (maxTokens === 0) maxTokens = 120_000;
|
|
120
120
|
|
|
121
121
|
const profileSupportsReasoning = state.currentModelRegistry
|
|
122
122
|
? ROUTER_TIERS.some((tier) => {
|
|
@@ -138,7 +138,7 @@ export const registerRouterProvider = (
|
|
|
138
138
|
input: ['text', 'image'] as ('text' | 'image')[],
|
|
139
139
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
140
140
|
contextWindow: maxContextWindow,
|
|
141
|
-
maxTokens
|
|
141
|
+
maxTokens,
|
|
142
142
|
};
|
|
143
143
|
});
|
|
144
144
|
|
|
@@ -417,8 +417,8 @@ export const registerRouterProvider = (
|
|
|
417
417
|
|
|
418
418
|
if (!success) {
|
|
419
419
|
const errorMsg = `Failed to delegate to any model in the chain.${failureReasons.length > 0 ? ' Reasons: ' + failureReasons.filter(Boolean).join('; ') + '.' : ''}`;
|
|
420
|
-
const
|
|
421
|
-
throw
|
|
420
|
+
const combinedError = lastError ? new Error(`${(lastError as Error).message} — ${errorMsg}`) : new Error(errorMsg);
|
|
421
|
+
throw combinedError;
|
|
422
422
|
}
|
|
423
423
|
|
|
424
424
|
stream.end();
|
package/extensions/routing.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { streamSimple } from '@earendil-works/pi-ai/compat';
|
|
2
|
+
import type { Context, Message } from '@earendil-works/pi-ai';
|
|
2
3
|
import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
3
4
|
import type { RouterConfig, RouterProfile, RouterTier, RoutingDecision } from './types';
|
|
4
5
|
import { createOpenRouterOnPayload, OPENROUTER_ATTR_HEADERS, parseCanonicalModelRef, resolveModelFromRef } from './config';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kdejaeger/pi-model-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Intelligent per-turn model router extension for the pi coding agent",
|
|
6
6
|
"keywords": [
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"prepublishOnly": "npm run tsc"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@earendil-works/pi-agent-core": "
|
|
45
|
-
"@earendil-works/pi-ai": "
|
|
46
|
-
"@earendil-works/pi-coding-agent": "
|
|
47
|
-
"@earendil-works/pi-tui": "
|
|
44
|
+
"@earendil-works/pi-agent-core": "^0.80.1",
|
|
45
|
+
"@earendil-works/pi-ai": "^0.80.1",
|
|
46
|
+
"@earendil-works/pi-coding-agent": "^0.80.1",
|
|
47
|
+
"@earendil-works/pi-tui": "^0.80.1",
|
|
48
48
|
"@sinclair/typebox": "*"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ye Liu
|
|
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.
|