@renjfk/opencode-model-fallback 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/lib/router.js +16 -8
  2. package/package.json +1 -1
package/lib/router.js CHANGED
@@ -16,6 +16,7 @@ export function createMappedFallbackRouter(ctx, rawOptions) {
16
16
  const timers = new Map();
17
17
  const selfAbortAt = new Map();
18
18
  const activeOriginals = new Map();
19
+ const activeTargets = new Map();
19
20
  let agentConfigs;
20
21
 
21
22
  function hasMapping(model) {
@@ -123,6 +124,19 @@ export function createMappedFallbackRouter(ctx, rawOptions) {
123
124
  .catch(() => {});
124
125
  }
125
126
 
127
+ async function toastRouteChange(sessionID, requested, target, original) {
128
+ const previous = activeTargets.get(sessionID);
129
+ activeTargets.set(sessionID, target);
130
+ if (previous === target) return;
131
+ if (!previous && requested === target) return;
132
+ const isFallback = target !== original;
133
+ await toast(
134
+ isFallback ? "Model Fallback" : "Model Recovered",
135
+ previous ? `${previous} -> ${target}` : `Using ${target} instead of ${requested}`,
136
+ isFallback ? "warning" : "info",
137
+ );
138
+ }
139
+
126
140
  async function handleError(sessionID, error, model, agent, source) {
127
141
  if (!sessionID || retrying.has(sessionID)) return;
128
142
  const name = extractErrorName(error);
@@ -197,14 +211,7 @@ export function createMappedFallbackRouter(ctx, rawOptions) {
197
211
  if (original) activeOriginals.set(sessionID, original);
198
212
  const model = modelObject(target);
199
213
  if (model && output.message) output.message.model = model;
200
- if (requested !== target) {
201
- const isFallback = hasMapping(requested);
202
- await toast(
203
- isFallback ? "Model Fallback" : "Model Recovered",
204
- `Using ${target} instead of ${requested}`,
205
- isFallback ? "warning" : "info",
206
- );
207
- }
214
+ await toastRouteChange(sessionID, requested, target, original);
208
215
  if (hasMapping(target)) scheduleTimeout(sessionID, target, input.agent);
209
216
  else clearTimer(sessionID);
210
217
  },
@@ -216,6 +223,7 @@ export function createMappedFallbackRouter(ctx, rawOptions) {
216
223
  if (id) {
217
224
  retrying.delete(id);
218
225
  activeOriginals.delete(id);
226
+ activeTargets.delete(id);
219
227
  clearTimer(id);
220
228
  }
221
229
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renjfk/opencode-model-fallback",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Mapped model fallback router for OpenCode. Routes retryable model failures to configured fallback models and recovers after cooldown.",
5
5
  "keywords": [
6
6
  "fallback",