@bizzywork/routing 0.4.3 → 0.4.4
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.
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
candidatesFor,
|
|
19
19
|
isTransient,
|
|
20
20
|
modelId,
|
|
21
|
+
fallbackFrom,
|
|
21
22
|
realModel,
|
|
22
23
|
routingWindow,
|
|
23
24
|
turnOf,
|
|
@@ -73,6 +74,13 @@ function loadConfig(): Config {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
const config = loadConfig();
|
|
77
|
+
// The last real @default, kept in the routing data dir so a reinstall doesn't lose it: `/model bizzy/auto` overwrites
|
|
78
|
+
// omp's own setting, and omp keeps no record of what it was.
|
|
79
|
+
const REMEMBERED = join(
|
|
80
|
+
config.server?.cwd ?? dirname(fileURLToPath(import.meta.url)),
|
|
81
|
+
"omp-default",
|
|
82
|
+
);
|
|
83
|
+
let remembered: string | undefined;
|
|
76
84
|
// One routing server per machine, however many sessions and subagents load this module.
|
|
77
85
|
let keepingServer = false;
|
|
78
86
|
|
|
@@ -192,8 +200,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
192
200
|
});
|
|
193
201
|
};
|
|
194
202
|
|
|
195
|
-
/** The model sent on when routing is off or refused
|
|
196
|
-
|
|
203
|
+
/** The model sent on when routing is off or refused: `@default`, or once `/model bizzy/auto` has made that this
|
|
204
|
+
* extension, the `@default` it last saw, or failing that the first real model. */
|
|
205
|
+
const fallbackOf = (c: ExtensionContext) => {
|
|
206
|
+
const set = realModel(c.models.resolve("@default"));
|
|
207
|
+
if (set) {
|
|
208
|
+
if (remembered !== modelId(set)) {
|
|
209
|
+
remembered = modelId(set);
|
|
210
|
+
try {
|
|
211
|
+
writeFileSync(REMEMBERED, remembered);
|
|
212
|
+
} catch {
|
|
213
|
+
// Unwritable: remembered for this process only.
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return set;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
remembered ??= readFileSync(REMEMBERED, "utf8").trim();
|
|
220
|
+
} catch {
|
|
221
|
+
// Never saved.
|
|
222
|
+
}
|
|
223
|
+
return fallbackFrom(remembered ? c.models.resolve(remembered) : undefined, c.models.list());
|
|
224
|
+
};
|
|
197
225
|
const candidates = (c: ExtensionContext) => candidatesFor(c.models.list(), fallbackOf(c));
|
|
198
226
|
|
|
199
227
|
// The server keeps the list in memory, so it is sent on every poll: a restarted server has it again within one.
|
|
@@ -117,6 +117,14 @@ export function turnOf(messages: readonly OmpMessage[]) {
|
|
|
117
117
|
export const realModel = <M extends { provider: string }>(model: M | undefined) =>
|
|
118
118
|
model && model.provider !== OWN_PROVIDER ? model : undefined;
|
|
119
119
|
|
|
120
|
+
/** The model to send on when routing is off: `preferred` if it is a real model, else the first real one in omp's list. */
|
|
121
|
+
export function fallbackFrom<M extends { provider: string }>(
|
|
122
|
+
preferred: M | undefined,
|
|
123
|
+
models: readonly M[],
|
|
124
|
+
): M | undefined {
|
|
125
|
+
return realModel(preferred) ?? models.find((model) => realModel(model));
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
/**
|
|
121
129
|
* The models routing may serve: every real one, except those with a known context window or output limit below
|
|
122
130
|
* `floor`'s (the `@default` model), so omp's budgets for `bizzy/auto` hold on whatever it serves.
|
package/package.json
CHANGED