mslxdff 0.1.72 → 0.1.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mslxdff",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -124,28 +124,9 @@ export function createChatGateway({ upstream, auto, logs, peers, maxHops, groups
124
124
  if (Number.isInteger(v) && v > 0) return Math.min(v, nonCoolingOrder.length);
125
125
  return Math.min(nonCoolingOrder.length, 5);
126
126
  })();
127
- const raceModels = nonCoolingOrder.slice(0, concLimit);
128
- evt("auto-concurrent-race", { reqId, models: raceModels, skippedFaulty: order.length - nonCoolingOrder.length, limit: concLimit });
129
- const raceStart = performance.now();
130
- const attempts = raceModels.map(async (m) => {
131
- const fwd = { ...injectReasoningContent(m, body), model: m };
132
- let r = null;
133
- try {
134
- const chatOpts = {};
135
- if (Object.keys(shareKeys).length) chatOpts.shareKeys = shareKeys;
136
- if (workbuddyUid) chatOpts.workbuddyUid = workbuddyUid;
137
- r = await upstream.chat(fwd, Object.keys(chatOpts).length ? chatOpts : undefined);
138
- } catch (err) {
139
- return { model: m, ok: false, error: errMsg(err), status: 502, timing: err?._t ?? null };
140
- }
141
- if (r && r.status >= 400) {
142
- const isAllow = r.status === 403 && r.headers?.get?.("x-mslxdff-allowlist") === "1";
143
- if (isAllow) return { model: m, ok: false, error: "allowlist", status: 403, allowlist: true };
144
- return { model: m, ok: false, error: `upstream ${r.status}`, status: r.status, res: r, timing: r._t ?? null };
145
- }
146
- if (r instanceof Error) return { model: m, ok: false, error: errMsg(r), status: 502 };
147
- return { model: m, ok: true, res: r, status: r.status, timing: r._t ?? null };
148
- });
127
+ let raceModels=nonCoolingOrder.slice(0,concLimit);
128
+ if(plugins?.length){const k=[];for(const m of raceModels){const b=await runHook(plugins,"model:beforeTry",{reqId,requested,model:m,hops});if(b.value===false||b.value?.skip)continue;k.push(m);}raceModels=k;}
129
+ if(!raceModels.length){order=order.filter(m=>!new Set(nonCoolingOrder.slice(0,concLimit)).has(m));if(!order.length){await handleExhaustedAll({res,body,lastErr:{model:requested,status:502,message:"all concurrent candidates skipped by plugin"},order:nonCoolingOrder.slice(0,concLimit),requested,handlerCtx:{...handlerCtx,reqId,startedAt},evt,logCall,mark,perf0,stages});return;}}else{evt("auto-concurrent-race",{reqId,models:raceModels,skippedFaulty:order.length-nonCoolingOrder.length,limit:concLimit});const raceStart=performance.now();const attempts=raceModels.map(async m=>{let f={...injectReasoningContent(m,body),model:m};if(plugins?.length){const u=await runHook(plugins,"upstream:request",{reqId,requested,model:m,payload:f,stream:Boolean(body.stream)});if(u.changed&&u.value?.payload) f=u.value.payload;}let r=null;try{const o={};if(Object.keys(shareKeys).length)o.shareKeys=shareKeys;if(workbuddyUid)o.workbuddyUid=workbuddyUid;r=await upstream.chat(f,Object.keys(o).length?o:undefined);}catch(e){if(plugins?.length)runHook(plugins,"upstream:response",{reqId,requested,model:m,status:null,ok:false,error:errMsg(e),timing:e?._t??null}).catch(()=>{});return{model:m,ok:false,error:errMsg(e),status:502,timing:e?._t??null};}if(plugins?.length)runHook(plugins,"upstream:response",{reqId,requested,model:m,status:r instanceof Error?null:r?.status??null,ok:!(r instanceof Error)&&r?r.status<400:false,error:r instanceof Error?errMsg(r):null,timing:r?._t??null}).catch(()=>{});if(r&&r.status>=400){const a=r.status===403&&r.headers?.get?.("x-mslxdff-allowlist")==="1";if(a)return{model:m,ok:false,error:"allowlist",status:403,allowlist:true};return{model:m,ok:false,error:`upstream ${r.status}`,status:r.status,res:r,timing:r._t??null};}if(r instanceof Error)return{model:m,ok:false,error:errMsg(r),status:502};return{model:m,ok:true,res:r,status:r.status,timing:r._t??null};});
149
130
  const results = await Promise.allSettled(attempts);
150
131
  const okList = results.map((r, i) => ({ r, i, model: raceModels[i] }))
151
132
  .filter(({ r }) => r.status === "fulfilled" && r.value?.ok)
@@ -185,10 +166,13 @@ export function createChatGateway({ upstream, auto, logs, peers, maxHops, groups
185
166
  const triedSet = new Set(raceModels);
186
167
  order = order.filter((m) => !triedSet.has(m));
187
168
  if (!order.length) {
188
- const last = { model: raceModels[0] || requested, status: 502, message: "all concurrent candidates failed" };
169
+ const failedStatuses = results.map((r) => (r.status === "fulfilled" ? r.value?.status : null)).filter((s) => Number.isInteger(s));
170
+ const lastStatus = failedStatuses[failedStatuses.length - 1] || failedStatuses[0] || 502;
171
+ const last = { model: raceModels[0] || requested, status: lastStatus, message: "all concurrent candidates failed" };
189
172
  await handleExhaustedAll({ res, body, lastErr: last, order: raceModels, requested, handlerCtx: { ...handlerCtx, reqId, startedAt }, evt, logCall, mark, perf0, stages });
190
173
  return;
191
174
  }
175
+ } // close else (raceModels not empty)
192
176
  }
193
177
  }
194
178