@oisin-ee/pi-tiers 0.9.0 → 0.9.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/LICENSE +21 -0
- package/package.json +4 -4
- package/src/policy.ts +3 -1
- package/src/recovery.ts +3 -1
- package/src/router.ts +31 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Momokaya
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oisin-ee/pi-tiers",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Sticky virtual model tiers with quota-aware recovery for pi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-extension",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@earendil-works/pi-ai": "
|
|
24
|
-
"@earendil-works/pi-coding-agent": "
|
|
23
|
+
"@earendil-works/pi-ai": "1.3.0",
|
|
24
|
+
"@earendil-works/pi-coding-agent": "1.3.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@earendil-works/pi-ai": "*",
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
"./src/index.ts"
|
|
33
33
|
]
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|
package/src/policy.ts
CHANGED
|
@@ -77,7 +77,9 @@ const ZERO = 0,
|
|
|
77
77
|
["minimax-", "minimax"],
|
|
78
78
|
],
|
|
79
79
|
pool =
|
|
80
|
-
pools.find(([prefix]: readonly string[]) => id.startsWith(prefix ?? ""))?.[
|
|
80
|
+
pools.find(([prefix]: readonly string[]) => id.toLowerCase().startsWith(prefix ?? ""))?.[
|
|
81
|
+
ONE
|
|
82
|
+
] ?? provider;
|
|
81
83
|
return { id, pool, provider };
|
|
82
84
|
};
|
|
83
85
|
|
package/src/recovery.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { Context } from "./ports.ts";
|
|
|
9
9
|
import type { Router } from "./router.ts";
|
|
10
10
|
import type { Tiers } from "./config.ts";
|
|
11
11
|
import { classify } from "./policy.ts";
|
|
12
|
+
import { listed } from "./router.ts";
|
|
12
13
|
|
|
13
14
|
const ZERO = 0,
|
|
14
15
|
ONE = 1;
|
|
@@ -76,7 +77,8 @@ class Recovery {
|
|
|
76
77
|
}
|
|
77
78
|
const tier = ctx.model.id,
|
|
78
79
|
state = branchState(ctx.sessionManager.getBranch(), tier),
|
|
79
|
-
|
|
80
|
+
tierTargets = this.#tiers.get(tier),
|
|
81
|
+
targets = tierTargets === undefined ? undefined : listed(tierTargets, ctx),
|
|
80
82
|
message = event.context.contextMessages.findLast((item) => item.role === "assistant"),
|
|
81
83
|
entry = event.context.contextEntries.findLast(
|
|
82
84
|
(item: Readonly<{ sourceEntry: SessionEntry; messages: readonly unknown[] }>) =>
|
package/src/router.ts
CHANGED
|
@@ -10,7 +10,29 @@ import type { Window } from "./quota.ts";
|
|
|
10
10
|
|
|
11
11
|
const ZERO = 0,
|
|
12
12
|
ONE = 1,
|
|
13
|
-
CACHE_MS = 60_000
|
|
13
|
+
CACHE_MS = 60_000,
|
|
14
|
+
/**
|
|
15
|
+
* Resolves tier targets to the references the model registry lists. Provider model
|
|
16
|
+
* ids differ in case from the tier file (`MiniMax-M3.1-Flash`), so matching ignores
|
|
17
|
+
* case and returns the registry's exact reference. A target that is not listed yet
|
|
18
|
+
* behaves like an unavailable target instead of a terminal error.
|
|
19
|
+
* @param {readonly string[]} targets Ordered tier.
|
|
20
|
+
* @param {Context} ctx Pi authority.
|
|
21
|
+
* @returns {readonly string[]} Listed registry references, in tier order.
|
|
22
|
+
*/
|
|
23
|
+
listed = (targets: readonly string[], ctx: Context): readonly string[] => {
|
|
24
|
+
const available = new Map(
|
|
25
|
+
ctx.modelRegistry.getAvailable().map((candidate) => {
|
|
26
|
+
const reference = `${candidate.provider}/${candidate.id}`;
|
|
27
|
+
return [reference.toLowerCase(), reference];
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
return targets.flatMap((reference) => {
|
|
31
|
+
const parsed = target(reference),
|
|
32
|
+
found = available.get(`${parsed.provider}/${parsed.id}`.toLowerCase());
|
|
33
|
+
return found === undefined ? [] : [found];
|
|
34
|
+
});
|
|
35
|
+
};
|
|
14
36
|
|
|
15
37
|
/** Sticky routing with host-wide quota and gateway health. */
|
|
16
38
|
class Router {
|
|
@@ -139,19 +161,20 @@ class Router {
|
|
|
139
161
|
|
|
140
162
|
/**
|
|
141
163
|
* Routes a tier without fabricating conversation messages.
|
|
142
|
-
* @param {readonly string[]}
|
|
164
|
+
* @param {readonly string[]} tier Ordered physical models, listed or not.
|
|
143
165
|
* @param {Request} request Pi request.
|
|
144
166
|
* @param {Context} ctx Pi authority.
|
|
145
167
|
* @returns {Promise<ModelRoute<State>>} Physical dispatch.
|
|
146
168
|
*/
|
|
147
169
|
public async route(
|
|
148
|
-
|
|
170
|
+
tier: readonly string[],
|
|
149
171
|
request: Request,
|
|
150
172
|
ctx: Context,
|
|
151
173
|
): Promise<ModelRoute<State>> {
|
|
152
174
|
request.signal?.throwIfAborted();
|
|
153
175
|
await this.#refresh();
|
|
154
|
-
const
|
|
176
|
+
const targets = listed(tier, ctx),
|
|
177
|
+
previous =
|
|
155
178
|
request.reason === "direct"
|
|
156
179
|
? undefined
|
|
157
180
|
: (branchState(ctx.sessionManager.getBranch(), request.model.id) ?? request.state),
|
|
@@ -163,7 +186,9 @@ class Router {
|
|
|
163
186
|
state = await this.#retry(request, current),
|
|
164
187
|
health = await this.#effects.read(),
|
|
165
188
|
chosen =
|
|
166
|
-
|
|
189
|
+
targets.includes(state.chosen) &&
|
|
190
|
+
!state.attempted.includes(state.chosen) &&
|
|
191
|
+
this.#available(state.chosen, health)
|
|
167
192
|
? state.chosen
|
|
168
193
|
: await this.next(targets, state);
|
|
169
194
|
if (chosen === undefined) {
|
|
@@ -173,4 +198,4 @@ class Router {
|
|
|
173
198
|
}
|
|
174
199
|
}
|
|
175
200
|
|
|
176
|
-
export { Router };
|
|
201
|
+
export { Router, listed };
|