saros-proxy 0.7.4 → 0.9.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 +74 -44
- package/dist/cli/daemon.js +4 -0
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/dsh-config.d.ts +32 -0
- package/dist/cli/dsh-config.js +122 -0
- package/dist/cli/dsh-config.js.map +1 -0
- package/dist/cli/harness-models.d.ts +26 -2
- package/dist/cli/harness-models.js +192 -2
- package/dist/cli/harness-models.js.map +1 -1
- package/dist/cli/harness-sync.d.ts +3 -6
- package/dist/cli/harness-sync.js +14 -7
- package/dist/cli/harness-sync.js.map +1 -1
- package/dist/cli/help.js +2 -2
- package/dist/cli/omp-config.js +11 -1
- package/dist/cli/omp-config.js.map +1 -1
- package/dist/cli/overview.js +2 -1
- package/dist/cli/overview.js.map +1 -1
- package/dist/cli/pi-config.js +11 -1
- package/dist/cli/pi-config.js.map +1 -1
- package/dist/cli/setup.d.ts +6 -10
- package/dist/cli/setup.js +100 -232
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/ui.d.ts +0 -1
- package/dist/cli/ui.js +0 -16
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/usage.d.ts +12 -0
- package/dist/cli/usage.js +116 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/config.d.ts +13 -17
- package/dist/config.js +29 -78
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +6 -5
- package/dist/constants.js +10 -5
- package/dist/constants.js.map +1 -1
- package/dist/index.js +7 -25
- package/dist/index.js.map +1 -1
- package/dist/model-stats.d.ts +20 -0
- package/dist/model-stats.js +135 -0
- package/dist/model-stats.js.map +1 -0
- package/dist/providers/commandcode.d.ts +17 -0
- package/dist/providers/commandcode.js +232 -0
- package/dist/providers/commandcode.js.map +1 -0
- package/dist/providers/index.d.ts +43 -0
- package/dist/providers/index.js +75 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/infer.d.ts +23 -0
- package/dist/providers/infer.js +13 -0
- package/dist/providers/infer.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +4 -0
- package/dist/providers/opencode-go.js +179 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/types.d.ts +118 -0
- package/dist/providers/types.js +10 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/proxy-logic.d.ts +46 -22
- package/dist/proxy-logic.js +146 -106
- package/dist/proxy-logic.js.map +1 -1
- package/dist/proxy.d.ts +20 -2
- package/dist/proxy.js +231 -57
- package/dist/proxy.js.map +1 -1
- package/dist/usage-client.d.ts +41 -0
- package/dist/usage-client.js +124 -0
- package/dist/usage-client.js.map +1 -0
- package/dist/validation.d.ts +5 -5
- package/dist/validation.js +7 -9
- package/dist/validation.js.map +1 -1
- package/package.json +6 -2
package/dist/proxy-logic.js
CHANGED
|
@@ -18,10 +18,13 @@ export function createProxyState(keys, options) {
|
|
|
18
18
|
keys: keys.map((k) => ({
|
|
19
19
|
label: k.label,
|
|
20
20
|
key: k.key,
|
|
21
|
+
provider: k.provider ?? 'opencode-go',
|
|
21
22
|
enabled: true,
|
|
22
23
|
consecutiveFailures: 0,
|
|
23
24
|
lastUsed: null,
|
|
24
25
|
disabledAt: null,
|
|
26
|
+
usagePercent: null,
|
|
27
|
+
currentWeight: 0,
|
|
25
28
|
})),
|
|
26
29
|
currentIndex: 0,
|
|
27
30
|
circuitBreakerThreshold: options?.circuitBreakerThreshold ?? 3,
|
|
@@ -37,7 +40,7 @@ export function createProxyState(keys, options) {
|
|
|
37
40
|
* (Keeps mutation paths through markKeyFailed / markKeySucceeded.)
|
|
38
41
|
*/
|
|
39
42
|
function toSnapshot(key) {
|
|
40
|
-
return { label: key.label, key: key.key };
|
|
43
|
+
return { label: key.label, key: key.key, provider: key.provider };
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Internal: check whether a key is available (enabled & under threshold).
|
|
@@ -60,86 +63,6 @@ function isKeyAvailable(state, key) {
|
|
|
60
63
|
}
|
|
61
64
|
return false;
|
|
62
65
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Check if a key is available based on usage data.
|
|
65
|
-
* A key is unavailable if ANY of its usage windows >= threshold.
|
|
66
|
-
*
|
|
67
|
-
* @param usage - The usage data for this key's account (null = no data = available)
|
|
68
|
-
* @param threshold - The usage threshold (1-100)
|
|
69
|
-
* @returns true if the key is available (usage below threshold or no data)
|
|
70
|
-
*/
|
|
71
|
-
function isKeyAvailableByUsage(usage, threshold) {
|
|
72
|
-
if (usage === null)
|
|
73
|
-
return true; // no data = don't block
|
|
74
|
-
return ((usage.rolling === null || usage.rolling < threshold) &&
|
|
75
|
-
(usage.weekly === null || usage.weekly < threshold) &&
|
|
76
|
-
(usage.monthly === null || usage.monthly < threshold));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Internal: when all circuit-breaker-available keys are over the usage
|
|
80
|
-
* threshold, fall back to the key with the lowest maximum usage across
|
|
81
|
-
* all windows. If a key has no usage data, it is preferred immediately.
|
|
82
|
-
*/
|
|
83
|
-
function findFallbackKey(state, usageMap) {
|
|
84
|
-
let best = null;
|
|
85
|
-
let bestMaxUsage = Infinity;
|
|
86
|
-
for (const key of state.keys) {
|
|
87
|
-
if (!isKeyAvailable(state, key))
|
|
88
|
-
continue;
|
|
89
|
-
const usage = usageMap.get(key.label);
|
|
90
|
-
if (!usage) {
|
|
91
|
-
// No usage data = best possible – take it immediately
|
|
92
|
-
key.lastUsed = Date.now();
|
|
93
|
-
return toSnapshot(key);
|
|
94
|
-
}
|
|
95
|
-
const maxUsage = Math.max(usage.rolling ?? 0, usage.weekly ?? 0, usage.monthly ?? 0);
|
|
96
|
-
if (maxUsage < bestMaxUsage) {
|
|
97
|
-
bestMaxUsage = maxUsage;
|
|
98
|
-
best = key;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (best) {
|
|
102
|
-
best.lastUsed = Date.now();
|
|
103
|
-
return toSnapshot(best);
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Internal: apply usage-gating to an exclusion set, then attempt to find
|
|
109
|
-
* the next available key. Falls back to findFallbackKey if all
|
|
110
|
-
* circuit-breaker-available keys are over the usage threshold.
|
|
111
|
-
*
|
|
112
|
-
* Shared by selectKeyForRequest and failoverRequest — extracts the ~90%
|
|
113
|
-
* identical usage-gating logic that was previously copy-pasted (PR-5).
|
|
114
|
-
*
|
|
115
|
-
* @param excludeLabels Mutable set; usage-over-threshold labels are added.
|
|
116
|
-
* @returns A key snapshot, or null if no key is available.
|
|
117
|
-
*/
|
|
118
|
-
function selectKeyWithUsageFallback(state, excludeLabels, options) {
|
|
119
|
-
// Exclude keys whose account usage exceeds the threshold
|
|
120
|
-
if (options?.usageMap && options?.usageThreshold !== undefined) {
|
|
121
|
-
const threshold = options.usageThreshold;
|
|
122
|
-
for (const key of state.keys) {
|
|
123
|
-
const usage = options.usageMap.get(key.label) ?? null;
|
|
124
|
-
if (!isKeyAvailableByUsage(usage, threshold)) {
|
|
125
|
-
excludeLabels.add(key.label);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
let snapshot = findNextKey(state, excludeLabels);
|
|
130
|
-
// Fallback: all circuit-breaker-available keys are over threshold
|
|
131
|
-
if (!snapshot && options?.usageMap) {
|
|
132
|
-
const fallback = findFallbackKey(state, options.usageMap);
|
|
133
|
-
if (fallback) {
|
|
134
|
-
const idx = state.keys.findIndex((k) => k.label === fallback.label);
|
|
135
|
-
if (idx !== -1) {
|
|
136
|
-
state.currentIndex = (idx + 1) % state.keys.length;
|
|
137
|
-
}
|
|
138
|
-
snapshot = fallback;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return snapshot;
|
|
142
|
-
}
|
|
143
66
|
/**
|
|
144
67
|
* Internal: return the set of key labels that are currently *in use* by
|
|
145
68
|
* active requests (C4 double-booking avoidance).
|
|
@@ -163,36 +86,128 @@ function buildBookedLabels(state) {
|
|
|
163
86
|
* Internal: find the next available key, skipping:
|
|
164
87
|
* - disabled / under-cooldown keys
|
|
165
88
|
* - labels in `excludeLabels`
|
|
166
|
-
*
|
|
89
|
+
*
|
|
90
|
+
* Selection strategy (smooth weighted round-robin, nginx-style):
|
|
91
|
+
* - When usage data is known for the candidates, keys with more remaining
|
|
92
|
+
* quota are proportionally preferred. E.g. key X at 30% used and key Y at
|
|
93
|
+
* 70% used receive ~70%/30% of requests — exact proportions over a cycle,
|
|
94
|
+
* not random sampling.
|
|
95
|
+
* - Without usage data (or when every candidate is exhausted), falls back to
|
|
96
|
+
* plain round-robin ordering.
|
|
167
97
|
*/
|
|
168
|
-
function findNextKey(state, excludeLabels) {
|
|
98
|
+
function findNextKey(state, excludeLabels, providerFilter) {
|
|
169
99
|
const n = state.keys.length;
|
|
170
100
|
if (n === 0)
|
|
171
101
|
return null;
|
|
102
|
+
const candidates = [];
|
|
172
103
|
for (let i = 0; i < n; i++) {
|
|
173
|
-
const
|
|
174
|
-
const key = state.keys[idx];
|
|
104
|
+
const key = state.keys[(state.currentIndex + i) % n];
|
|
175
105
|
if (excludeLabels.has(key.label))
|
|
176
106
|
continue;
|
|
107
|
+
if (providerFilter && !providerFilter(key.provider))
|
|
108
|
+
continue;
|
|
177
109
|
if (!isKeyAvailable(state, key))
|
|
178
110
|
continue;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return
|
|
111
|
+
candidates.push(key);
|
|
112
|
+
}
|
|
113
|
+
if (candidates.length === 0)
|
|
114
|
+
return null;
|
|
115
|
+
const picked = pickWeighted(state, candidates);
|
|
116
|
+
state.currentIndex = (state.keys.indexOf(picked) + 1) % n;
|
|
117
|
+
picked.lastUsed = Date.now();
|
|
118
|
+
return toSnapshot(picked);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Internal: smooth weighted round-robin over the candidates.
|
|
122
|
+
* Falls back to the first candidate (round-robin order) when usage data is
|
|
123
|
+
* missing for any candidate or when no candidate has remaining capacity.
|
|
124
|
+
*/
|
|
125
|
+
function pickWeighted(state, candidates) {
|
|
126
|
+
const known = candidates.filter((k) => k.usagePercent !== null);
|
|
127
|
+
if (known.length === 0)
|
|
128
|
+
return candidates[0];
|
|
129
|
+
let weights = candidates.map((k) => Math.max(0, 100 - (k.usagePercent ?? 0)));
|
|
130
|
+
// Keys missing usage data get the median of the known weights — neutral,
|
|
131
|
+
// so one flaky key no longer disables weighting for the whole pool.
|
|
132
|
+
const sorted = known.map((k) => 100 - (k.usagePercent ?? 0)).sort((a, b) => a - b);
|
|
133
|
+
const median = sorted[Math.floor(sorted.length / 2)] ?? 0;
|
|
134
|
+
weights = weights.map((w, i) => (candidates[i].usagePercent === null ? median : w));
|
|
135
|
+
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
136
|
+
if (totalWeight === 0)
|
|
137
|
+
return candidates[0];
|
|
138
|
+
let best = candidates[0];
|
|
139
|
+
let bestWeight = -Infinity;
|
|
140
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
141
|
+
candidates[i].currentWeight += weights[i];
|
|
142
|
+
if (candidates[i].currentWeight > bestWeight) {
|
|
143
|
+
bestWeight = candidates[i].currentWeight;
|
|
144
|
+
best = candidates[i];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
best.currentWeight -= totalWeight;
|
|
148
|
+
return best;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Update per-key usage data (worst-window used percent, 0-100).
|
|
152
|
+
* Keys absent from the map keep their previous value.
|
|
153
|
+
*/
|
|
154
|
+
export function updateKeyUsage(state, usage) {
|
|
155
|
+
for (const key of state.keys) {
|
|
156
|
+
const percent = usage.get(key.label);
|
|
157
|
+
if (typeof percent === 'number')
|
|
158
|
+
key.usagePercent = percent;
|
|
183
159
|
}
|
|
184
|
-
return null;
|
|
185
160
|
}
|
|
186
161
|
// ---------------------------------------------------------------------------
|
|
187
162
|
// Request-Scoped Key Tracking (C4)
|
|
188
163
|
// ---------------------------------------------------------------------------
|
|
164
|
+
/** Parse a trailing '@provider' suffix from a model id ('x@cc' → 'cc'). */
|
|
165
|
+
function parseModelSuffix(modelId) {
|
|
166
|
+
if (!modelId)
|
|
167
|
+
return null;
|
|
168
|
+
const at = modelId.lastIndexOf('@');
|
|
169
|
+
if (at <= 0 || at === modelId.length - 1)
|
|
170
|
+
return null;
|
|
171
|
+
return modelId.slice(at + 1);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Resolve the provider-preference predicate for a request.
|
|
175
|
+
*
|
|
176
|
+
* Rule: exclude providers whose verdict is definitively 'no' for the model
|
|
177
|
+
* (e.g. claude-* on opencode-go). Everything else — 'yes' AND 'maybe' —
|
|
178
|
+
* serves the request, so genuinely shared models rotate across ALL their
|
|
179
|
+
* keys regardless of which catalog loaded first. When no provider says 'no'
|
|
180
|
+
* the filter is undefined (legacy any-key behavior).
|
|
181
|
+
*/
|
|
182
|
+
function makeProviderFilter(state, modelId) {
|
|
183
|
+
if (!modelId)
|
|
184
|
+
return undefined;
|
|
185
|
+
const resolver = state.affinityResolver;
|
|
186
|
+
if (!resolver)
|
|
187
|
+
return undefined;
|
|
188
|
+
const excluded = new Set();
|
|
189
|
+
for (const key of state.keys) {
|
|
190
|
+
if (excluded.has(key.provider))
|
|
191
|
+
continue;
|
|
192
|
+
if (resolver(key.provider, modelId) === 'no') {
|
|
193
|
+
excluded.add(key.provider);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (excluded.size === 0)
|
|
197
|
+
return undefined;
|
|
198
|
+
return (provider) => !excluded.has(provider);
|
|
199
|
+
}
|
|
189
200
|
/**
|
|
190
201
|
* Obtain a key for a new (or in-flight) request.
|
|
191
202
|
* Creates a RequestContext if one does not already exist for this requestId.
|
|
192
203
|
* Skips keys that have already been tried for this request AND keys booked
|
|
193
204
|
* by any other active request.
|
|
205
|
+
*
|
|
206
|
+
* When a modelId is supplied and some providers claim it (modelAffinity
|
|
207
|
+
* 'yes'), keys of other providers are only used after the preferred pool is
|
|
208
|
+
* exhausted (including its booked-share tier).
|
|
194
209
|
*/
|
|
195
|
-
export function selectKeyForRequest(state, requestId,
|
|
210
|
+
export function selectKeyForRequest(state, requestId, modelId) {
|
|
196
211
|
// If context already exists, return the already-assigned current key
|
|
197
212
|
const existing = state.activeRequests.get(requestId);
|
|
198
213
|
if (existing) {
|
|
@@ -201,18 +216,27 @@ export function selectKeyForRequest(state, requestId, options) {
|
|
|
201
216
|
// Create new context and pick a fresh key
|
|
202
217
|
const ctx = { requestId, triedKeys: [], currentKey: null };
|
|
203
218
|
state.activeRequests.set(requestId, ctx);
|
|
219
|
+
const providerFilter = makeProviderFilter(state, modelId);
|
|
220
|
+
ctx.providerFilter = providerFilter;
|
|
221
|
+
ctx.pinned = Boolean(parseModelSuffix(modelId));
|
|
204
222
|
// Tier 1: prefer a key not booked by another active request (spread load)
|
|
205
223
|
const excludeLabels = new Set(ctx.triedKeys);
|
|
206
224
|
const booked = buildBookedLabels(state);
|
|
207
225
|
for (const label of booked) {
|
|
208
226
|
excludeLabels.add(label);
|
|
209
227
|
}
|
|
210
|
-
let snapshot =
|
|
211
|
-
// Tier 2: all healthy keys are booked — share one via
|
|
212
|
-
// Better to share a key than return 503 when concurrent
|
|
213
|
-
// outnumber the key pool.
|
|
228
|
+
let snapshot = findNextKey(state, excludeLabels, providerFilter);
|
|
229
|
+
// Tier 2: all healthy preferred keys are booked — share one via
|
|
230
|
+
// round-robin. Better to share a key than return 503 when concurrent
|
|
231
|
+
// requests outnumber the key pool.
|
|
214
232
|
if (!snapshot) {
|
|
215
|
-
snapshot =
|
|
233
|
+
snapshot = findNextKey(state, new Set(ctx.triedKeys), providerFilter);
|
|
234
|
+
}
|
|
235
|
+
// Tier 3: preferred providers exhausted → fall back to any provider
|
|
236
|
+
// (pinned requests exempt: a @provider suffix or messages-only model
|
|
237
|
+
// cannot be served by other providers at all).
|
|
238
|
+
if (!snapshot && providerFilter && !ctx.pinned) {
|
|
239
|
+
snapshot = findNextKey(state, new Set(ctx.triedKeys));
|
|
216
240
|
}
|
|
217
241
|
ctx.currentKey = snapshot;
|
|
218
242
|
return snapshot;
|
|
@@ -223,7 +247,7 @@ export function selectKeyForRequest(state, requestId, options) {
|
|
|
223
247
|
* appropriate ErrorType; this function only manages the request-context
|
|
224
248
|
* tracking (adds the current key to triedKeys).
|
|
225
249
|
*/
|
|
226
|
-
export function failoverRequest(state, requestId
|
|
250
|
+
export function failoverRequest(state, requestId) {
|
|
227
251
|
const ctx = state.activeRequests.get(requestId);
|
|
228
252
|
if (!ctx)
|
|
229
253
|
return null;
|
|
@@ -231,18 +255,25 @@ export function failoverRequest(state, requestId, options) {
|
|
|
231
255
|
if (ctx.currentKey) {
|
|
232
256
|
ctx.triedKeys.push(ctx.currentKey.label);
|
|
233
257
|
}
|
|
234
|
-
//
|
|
258
|
+
// The provider preference was fixed when the request context was created;
|
|
259
|
+
// failover re-applies it so cross-provider failover can't pick a key that
|
|
260
|
+
// cannot serve the (possibly rewritten) model id.
|
|
261
|
+
const filter = ctx.providerFilter;
|
|
235
262
|
const excludeLabels = new Set(ctx.triedKeys);
|
|
236
263
|
const booked = buildBookedLabels(state);
|
|
237
264
|
for (const label of booked) {
|
|
238
265
|
excludeLabels.add(label);
|
|
239
266
|
}
|
|
240
|
-
let snapshot =
|
|
241
|
-
// Tier 2: all remaining healthy keys are booked — share one.
|
|
267
|
+
let snapshot = findNextKey(state, excludeLabels, filter);
|
|
268
|
+
// Tier 2: all remaining healthy preferred keys are booked — share one.
|
|
242
269
|
// Still respects per-request triedKeys (don't re-use a key this
|
|
243
270
|
// request already failed on).
|
|
244
271
|
if (!snapshot) {
|
|
245
|
-
snapshot =
|
|
272
|
+
snapshot = findNextKey(state, new Set(ctx.triedKeys), filter);
|
|
273
|
+
}
|
|
274
|
+
// Tier 3: exhausted → any provider, unless the model is provider-pinned.
|
|
275
|
+
if (!snapshot && !ctx.pinned) {
|
|
276
|
+
snapshot = findNextKey(state, new Set(ctx.triedKeys));
|
|
246
277
|
}
|
|
247
278
|
ctx.currentKey = snapshot;
|
|
248
279
|
return snapshot;
|
|
@@ -266,10 +297,11 @@ export function completeRequest(state, requestId, success) {
|
|
|
266
297
|
/**
|
|
267
298
|
* Mark a key as failed according to the error type (C2).
|
|
268
299
|
* - KeyFault / ServerFault: penalise the key (KeyFault disables immediately)
|
|
269
|
-
* - RequestFault: no penalisation (bad request,
|
|
300
|
+
* - RequestFault / NetworkFault: no penalisation (bad request, or network
|
|
301
|
+
* trouble that is not the key's fault)
|
|
270
302
|
*/
|
|
271
303
|
export function markKeyFailed(state, keyLabel, errorType) {
|
|
272
|
-
if (errorType === 'RequestFault')
|
|
304
|
+
if (errorType === 'RequestFault' || errorType === 'NetworkFault')
|
|
273
305
|
return;
|
|
274
306
|
const key = state.keys.find((k) => k.label === keyLabel);
|
|
275
307
|
if (!key)
|
|
@@ -313,15 +345,23 @@ export function markKeySucceeded(state, keyLabel) {
|
|
|
313
345
|
* 401 → KeyFault (invalid/revoked key — immediate disable)
|
|
314
346
|
* 429 → ServerFault (transient rate-limit — incremental circuit breaker)
|
|
315
347
|
* 500 / 502 / 503 → KeyFault if body mentions quota/balance, else ServerFault
|
|
316
|
-
* 400 / 404 / 422
|
|
348
|
+
* 400 / 403 / 404 / 422 → RequestFault (bad request or permission denial —
|
|
349
|
+
* don't penalise the key; 403 MODEL_NOT_IN_PLAN is a plan
|
|
350
|
+
* restriction, found live on commandcode)
|
|
317
351
|
* everything else → ServerFault
|
|
318
352
|
*/
|
|
319
353
|
export function classifyHttpError(status, _body) {
|
|
320
|
-
if (status === 401)
|
|
354
|
+
if (status === 401) {
|
|
355
|
+
// opencode-go returns 401 ModelError for UNKNOWN MODELS (verified live:
|
|
356
|
+
// a Model gpt-5.5 is not supported, with a valid key). That is a request
|
|
357
|
+
// fault — penalising it would disable every key as the pool rotates.
|
|
358
|
+
if (_body && /ModelError|not supported/i.test(_body))
|
|
359
|
+
return 'RequestFault';
|
|
321
360
|
return 'KeyFault';
|
|
361
|
+
}
|
|
322
362
|
if (status === 429)
|
|
323
363
|
return 'ServerFault';
|
|
324
|
-
if (status === 400 || status === 404 || status === 422)
|
|
364
|
+
if (status === 400 || status === 403 || status === 404 || status === 422)
|
|
325
365
|
return 'RequestFault';
|
|
326
366
|
if (status === 500 || status === 502 || status === 503) {
|
|
327
367
|
// Server errors: if the body hints at a quota/balance issue treat as KeyFault
|
package/dist/proxy-logic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-logic.js","sourceRoot":"","sources":["../src/proxy-logic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy-logic.js","sourceRoot":"","sources":["../src/proxy-logic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AAuErE,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,MAAM,UAAU,gBAAgB,CAC9B,IAA8D,EAC9D,OAGC;IAED,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACrB,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,aAAa;YACrC,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,CAAC;YACtB,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,aAAa,EAAE,CAAC;SACjB,CAAC,CAAC;QACH,YAAY,EAAE,CAAC;QACf,uBAAuB,EAAE,OAAO,EAAE,uBAAuB,IAAI,CAAC;QAC9D,wBAAwB,EAAE,OAAO,EAAE,w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AAK,KAAK,QAAQ,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,GAAG,CAAC,mBAAmB,GAAG,CAAC,CAAC;IAC5B,kEAAkE;IAClE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;AACxB,CAAC;AAED,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,8EAA8E;AAC9E,4BAA4B;AAC5B,8EAA8E;AAE9E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,KAAc;IAC9D,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,wEAAwE;QACxE,yEAAyE;QACzE,qEAAqE;QACrE,IAAI,KAAK,IAAI,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,cAAc,CAAC;QAC5E,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,aAAa,CAAC;IACzC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,cAAc,CAAC;IAChG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACvD,8EAA8E;QAC9E,IAAI,KAAK,IAAI,mCAAmC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7D,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/dist/proxy.d.ts
CHANGED
|
@@ -6,6 +6,21 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Hono } from 'hono';
|
|
8
8
|
import type { ProxyConfig } from './config.js';
|
|
9
|
+
import type { KeyProvider } from './providers/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the upstream URL for one attempt: per-provider base URL + path
|
|
12
|
+
* remapping. Clients always speak canonical saros routes (/zen/go/v1/<rest>,
|
|
13
|
+
* the opencode-go shape); requests routed to a provider with a different
|
|
14
|
+
* chat surface get the prefix remapped (e.g. /provider/v1 for commandcode).
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveUpstreamUrl(config: ProxyConfig, provider: KeyProvider, path: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Extract a provider-suffix routing hint from a model id
|
|
19
|
+
* (e.g. 'claude-…@commandcode' → 'commandcode'). Returns null when absent.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseProviderSuffix(modelId: string | undefined): string | null;
|
|
22
|
+
/** Strip the @provider routing suffix from a model id for upstream forwarding. */
|
|
23
|
+
export declare function stripProviderSuffix(modelId: string): string;
|
|
9
24
|
declare module 'hono' {
|
|
10
25
|
interface ContextVariableMap {
|
|
11
26
|
remote: {
|
|
@@ -18,8 +33,11 @@ declare module 'hono' {
|
|
|
18
33
|
*/
|
|
19
34
|
export declare function buildUpstreamUrl(base: string, path: string): string;
|
|
20
35
|
/**
|
|
21
|
-
* Clean headers for upstream forwarding: remove hop-by-hop headers
|
|
22
|
-
*
|
|
36
|
+
* Clean headers for upstream forwarding: remove hop-by-hop headers,
|
|
37
|
+
* pre-existing Authorization, and content-length (the forwarded body may be
|
|
38
|
+
* rewritten — model-id aliasing / suffix strip — so a stale content-length
|
|
39
|
+
* makes the upstream wait for bytes that never arrive; undici recomputes it
|
|
40
|
+
* from the real body).
|
|
23
41
|
*/
|
|
24
42
|
export declare function buildUpstreamHeaders(incoming: Headers, bearerToken: string): Headers;
|
|
25
43
|
/**
|