@qqbrowser/qbot-claw-launcher 0.9.92 → 0.9.93
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/dist/build.js +1 -1
- package/dist/openai-proxy.js +11 -11
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.93",exports.IS_DEBUG_BUILD=!1;
|
package/dist/openai-proxy.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var H=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.proxyApiKey=void 0,exports.handleOpenAIProxy=fe;const K=H(require("crypto")),ae=H(require("http")),se=H(require("https")),z=require("url"),o=require("./reportLog"),V=require("./api/llm-access-proxy"),ie=require("./api/auth-client"),S=require("./api/content-review");exports.proxyApiKey=K.default.randomBytes(32).toString("base64url");const le={enabled:!0,targetBaseUrl:"https://qbqaproxy.imtt.qq.com/openapi",allowedApiKeys:[exports.proxyApiKey],timeout:12e4};function ce(r){const e=r.headers.authorization;if(!e||typeof e!="string")return null;const l=e.match(/^Bearer\s+(.+)$/i);return l?l[1]:null}function _(r,e,l,c,t){const m=JSON.stringify({error:{message:l,type:c,code:t}});r.writeHead(e,{"Content-Type":"application/json","Content-Length":Buffer.byteLength(m)}),r.end(m)}function O(r,e,l="QBotClawRouter"){const c=Math.floor(Date.now()/1e3),t=`chatcmpl-${K.default.randomBytes(12).toString("hex")}`,m=JSON.stringify({id:t,object:"chat.completion",created:c,model:l,choices:[{index:0,message:{role:"assistant",content:e},finish_reason:"stop"}],usage:{prompt_tokens:0,completion_tokens:0,total_tokens:0}});r.writeHead(200,{"Content-Type":"application/json","Content-Length":Buffer.byteLength(m)}),r.end(m)}function B(r,e,l="QBotClawRouter"){if(!r.writable)return;const c=Math.floor(Date.now()/1e3),t=`chatcmpl-${K.default.randomBytes(12).toString("hex")}`,m=JSON.stringify({id:t,object:"chat.completion.chunk",created:c,model:l,choices:[{index:0,delta:{role:"assistant",content:e},finish_reason:null}]});r.write(`data: ${m}
|
|
2
2
|
|
|
3
|
-
`);const k=JSON.stringify({id:t,object:"chat.completion.chunk",created:c,model:
|
|
3
|
+
`);const k=JSON.stringify({id:t,object:"chat.completion.chunk",created:c,model:l,choices:[{index:0,delta:{},finish_reason:"stop"}]});r.write(`data: ${k}
|
|
4
4
|
|
|
5
5
|
`),r.write(`data: [DONE]
|
|
6
6
|
|
|
7
|
-
`),r.end()}function pe(){return Math.random().toString(36).substring(2,10)}function X(r){const e=r?.choices?.[0]?.delta;if(!e)return(0,o.log)(`[extractDeltaContent] delta \u4E3A\u7A7A, choices=${JSON.stringify(r?.choices)}`),{content:"",hasToolCalls:!1};const
|
|
7
|
+
`),r.end()}function pe(){return Math.random().toString(36).substring(2,10)}function X(r){const e=r?.choices?.[0]?.delta;if(!e)return(0,o.log)(`[extractDeltaContent] delta \u4E3A\u7A7A, choices=${JSON.stringify(r?.choices)}`),{content:"",hasToolCalls:!1};const l=e.content,c=Array.isArray(e.tool_calls)&&e.tool_calls.length>0||e.function_call!=null;return{content:typeof l=="string"&&l.length>0?l:"",hasToolCalls:c}}function ue(r){try{const e=JSON.parse(r);return X(e)}catch(e){return(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${e}`),{content:"",hasToolCalls:!1}}}function ge(r,e){const l=JSON.stringify({error:{message:e,type:"content_filter_error",code:"content_review_failed"}});r.writable&&(r.write(`data: ${l}
|
|
8
8
|
|
|
9
9
|
`),r.write(`data: [DONE]
|
|
10
10
|
|
|
11
|
-
`),r.end())}function de(r){return new Promise((e,
|
|
12
|
-
${
|
|
13
|
-
${
|
|
11
|
+
`),r.end())}function de(r){return new Promise((e,l)=>{const c=[];r.on("data",t=>c.push(t)),r.on("end",()=>e(Buffer.concat(c))),r.on("error",l)})}async function fe(r,e,l){const c=r.url||"";if(!c.startsWith("/v1/"))return!1;const t=pe(),m=r.method||"GET",k=Date.now();(0,o.log)(`[openai-proxy][${t}] \u6536\u5230\u8BF7\u6C42: ${m} ${c}`);const q=le;if(!q.enabled)return(0,o.log)(`[openai-proxy][${t}] \u4EE3\u7406\u672A\u542F\u7528\uFF0C\u8FD4\u56DE 404`),_(e,404,"Not Found","invalid_request_error","not_found"),!0;const Q=ce(r);if(!Q)return(0,o.log)(`[openai-proxy][${t}] \u7F3A\u5C11 API Key`),_(e,401,"You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth.","invalid_request_error","missing_api_key"),!0;if(!q.allowedApiKeys.includes(Q))return(0,o.log)(`[openai-proxy][${t}] API Key \u6821\u9A8C\u5931\u8D25`),_(e,401,"Incorrect API key provided. You can check your API key in the proxy configuration.","invalid_request_error","invalid_api_key"),!0;let A;try{A=await de(r)}catch(n){return(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u8BF7\u6C42\u4F53\u5931\u8D25: ${n.message}`),_(e,400,"Failed to read request body","invalid_request_error","bad_request"),!0}let v=!1,d=null;if(c.includes("/chat/completions")&&A.length>0)try{d=JSON.parse(A.toString("utf-8")),v=d.stream===!0,(0,o.log)(`[openai-proxy][${t}] stream=${d.stream}`)}catch{}let L=!1;if(Array.isArray(d?.messages)){const n=d.messages;let a=-1;for(let i=n.length-1;i>=0;i--)if(n[i].role==="user"){a=i;break}a>=0&&(L=n.slice(a+1).some(i=>i.role==="tool"))}if(L&&(0,o.log)(`[openai-proxy][${t}] \u6700\u540E\u4E00\u6761\u7528\u6237\u6D88\u606F\u4E4B\u540E\u5B58\u5728 tool \u6D88\u606F\uFF0C\u8DF3\u8FC7\u8F93\u5165\u5185\u5BB9\u5BA1\u6838\uFF08\u5DE5\u5177\u8C03\u7528\u540E\u7EED\u8BF7\u6C42\uFF09`),d&&c.includes("/chat/completions")&&Array.isArray(d.messages)&&!L){const n=[];for(const a of d.messages)if(a.role==="user"){if(typeof a.content=="string"&&a.content.length>0)n.push(a.content);else if(Array.isArray(a.content))for(const i of a.content)i.type==="text"&&typeof i.text=="string"&&i.text.length>0&&n.push(i.text)}if(n.length>0){const a=n[n.length-1];try{(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${a.length}\uFF0C\u9001\u5BA1\u5185\u5BB9:
|
|
12
|
+
${a}`),await(0,S.reviewText)(a,S.AuditContentType.INPUT,l),(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}catch(i){if(i instanceof S.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${i.fallbackMsg}`);const C=d?.model||"QBotClawRouter",I=i.fallbackMsg||"\u8F93\u5165\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002";return v?(e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),B(e,I,C)):O(e,I,C),!0}(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${i.message||JSON.stringify(i)}`)}}}const j=new z.URL(q.targetBaseUrl),Z=j.pathname.replace(/\/+$/,""),ee=c.replace(/^\/v1/,""),T=new z.URL(Z+ee,j.origin),F=T.protocol==="https:",te=F?se.default:ae.default,oe=F?443:80,N={};for(const[n,a]of Object.entries(r.headers)){if(!a)continue;const i=n.toLowerCase();["host","connection","keep-alive","transfer-encoding","upgrade"].includes(i)||(N[n]=a)}N.host=T.host;let R;try{R=await(0,V.fetchLlmToken)(l),(0,o.log)(`[openai-proxy][${t}] \u6210\u529F\u83B7\u53D6 LLM Token ${R}`)}catch(n){if(n instanceof V.TokenExhaustedError){(0,o.log)(`[openai-proxy][${t}] Token \u5DF2\u8017\u5C3D: ${n.message}`);const i=d?.model||"QBotClawRouter",C=n.message||"\u5F53\u65E5Token\u5DF2\u8017\u5C3D\uFF0C\u8BF7\u5207\u6362\u6A21\u578B\u6216\u660E\u65E5\u518D\u8BD5";return v?(e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),B(e,C,i)):O(e,C,i),!0}if(n instanceof ie.AuthExpiredError)return(0,o.log)(`[openai-proxy][${t}] \u7968\u636E\u8FC7\u671F: ${n.message}`),_(e,401,`Auth token expired: ${n.message}`,"authentication_error","auth_expired"),!0;const a=n instanceof Error?n.message:JSON.stringify(n);return(0,o.log)(`[openai-proxy][${t}] \u83B7\u53D6 LLM Token \u5931\u8D25: ${a}`),_(e,500,`Failed to obtain auth token: ${a}`,"server_error","token_fetch_error"),!0}N.authorization=`Bearer ${R}`;const ne={hostname:T.hostname,port:T.port||oe,path:T.pathname+T.search,method:m,headers:N,timeout:q.timeout||12e4};(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u5230: ${m} ${T.href}`);try{const n=A.toString("utf-8");(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u8BF7\u6C42\u4F53: ${n.length>500?n.substring(0,500)+`...(truncated, total ${n.length} chars)`:n}`)}catch{}const D=te.request(ne,n=>{const a=n.statusCode||502,i=n.headers["content-type"]||"",C=i.includes("text/event-stream")||v,I=Date.now()-k;(0,o.log)(`[openai-proxy][${t}] \u76EE\u6807\u54CD\u5E94: ${a} ${i} (${I}ms)${C?" [SSE\u6D41\u5F0F]":""} (isStreamRequest=${v})`);const U={};for(const[y,g]of Object.entries(n.headers)){if(!g)continue;const p=y.toLowerCase();["connection","keep-alive","upgrade"].includes(p)||(U[y]=g)}const G=v&&!i.includes("text/event-stream")&&a>=400;if(G&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u975ESSE\u9519\u8BEF\u54CD\u5E94 (status=${a}, content-type=${i})\uFF0C\u964D\u7EA7\u4E3A\u975E\u6D41\u5F0F\u5904\u7406`),C&&!G){e.writeHead(a,U);let y="",g="",p="",x=!1,u=!1,M=!1;const f=100,w=async(s,$)=>{if(!s||x)return;const E=S.AuditContentType.OUTPUT;try{(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838${$?"(\u6700\u7EC8)":""}\uFF0C\u6587\u672C\u957F\u5EA6: ${s.length}\uFF0C\u9001\u5BA1\u5185\u5BB9:
|
|
13
|
+
${s}`),await(0,S.reviewText)(s,E,l),(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}catch(h){if(h instanceof S.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${h.fallbackMsg}`),x=!0;const W=h.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002";B(e,`
|
|
14
14
|
|
|
15
|
-
[${W}]`,d?.model||"QBotClawRouter"),n.destroy();return}(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${h.message||JSON.stringify(h)}`)}};n.on("data",
|
|
15
|
+
[${W}]`,d?.model||"QBotClawRouter"),n.destroy();return}(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${h.message||JSON.stringify(h)}`)}};n.on("data",s=>{if(x){(0,o.log)(`[openai-proxy][${t}] [SSE] \u5BA1\u6838\u5DF2\u4E2D\u65AD\uFF0C\u8DF3\u8FC7chunk (${s.length}\u5B57\u8282)`);return}if(!e.writable){(0,o.log)(`[openai-proxy][${t}] [SSE] \u5BA2\u6237\u7AEF\u8FDE\u63A5\u5DF2\u5173\u95ED(res.writable=false)\uFF0C\u8DF3\u8FC7chunk (${s.length}\u5B57\u8282)`);return}const $=s.toString("utf-8");p+=$,p=p.replace(/\r\n/g,`
|
|
16
16
|
`).replace(/\r/g,`
|
|
17
|
-
`);const
|
|
18
|
-
`);p=
|
|
19
|
-
${g}`),y.length>0&&!x&&await w(y,!0),!x){if(g.length===0&&!u){(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4E14\u65E0tool_calls\uFF0C\u8FD4\u56DE\u7EDF\u4E00\u63D0\u793A`),B(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",d?.model||"QBotClawRouter");return}g.length===0&&u&&(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4F46\u5305\u542Btool_calls\uFF08\u51FD\u6570\u8C03\u7528\u4E2D\u95F4\u8F6E\uFF09\uFF0C\u6B63\u5E38\u7ED3\u675F`);const
|
|
20
|
-
`);(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${
|
|
17
|
+
`);const E=p.split(`
|
|
18
|
+
`);p=E.pop()||"";for(let h=0;h<E.length;h++){const P=E[h].trim();if(P){if(P==="data: [DONE]")M=!0;else if(P.startsWith("data: ")){const Y=P.slice(6);try{const b=JSON.parse(Y);if(b?.type==="upstream_error"||b?.error?.type==="upstream_error"){const re=b.reqid||b.error?.reqid;(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${re})\uFF0C\u539F\u59CB\u56DE\u5305: ${Y}\uFF0C\u8FD4\u56DE\u53CB\u597D\u63D0\u793A`),x=!0,B(e,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",d?.model||"QBotClawRouter"),n.destroy();return}const J=X(b);J.content&&(y+=J.content,g+=J.content),J.hasToolCalls&&(u=!0)}catch(b){(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${b}`)}}}}if(M&&g.length===0&&!u?(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230 [DONE] \u4E14\u8F93\u51FA\u4E3A\u7A7A\uFF0C\u6682\u4E0D\u8F6C\u53D1\uFF0C\u7B49\u5F85 end \u4E8B\u4EF6\u5904\u7406`):e.write(s),y.length>=f){const h=y;y="",(0,o.log)(`[openai-proxy][${t}] [SSE] \u89E6\u53D1\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${h.length} ${h}`),w(h,!1)}}),n.on("end",async()=>{if(p.trim()){const s=p.trim();if(s.startsWith("data: ")&&s!=="data: [DONE]"){const $=ue(s.slice(6));$.content&&(y+=$.content,g+=$.content),$.hasToolCalls&&(u=!0)}}if(g.length===0?(0,o.log)(`[openai-proxy][${t}] [SSE] \u26A0\uFE0F \u6A21\u578B\u8F93\u51FA\u5185\u5BB9\u4E3A\u7A7A\uFF01\u8BF7\u68C0\u67E5\u4E0A\u65B9\u65E5\u5FD7\u4E2D\u7684\u539F\u59CBchunk\u6570\u636E`):(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u5185\u5BB9 (${g.length}\u5B57\u7B26):
|
|
19
|
+
${g}`),y.length>0&&!x&&await w(y,!0),!x){if(g.length===0&&!u){(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4E14\u65E0tool_calls\uFF0C\u8FD4\u56DE\u7EDF\u4E00\u63D0\u793A`),B(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",d?.model||"QBotClawRouter");return}g.length===0&&u&&(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4F46\u5305\u542Btool_calls\uFF08\u51FD\u6570\u8C03\u7528\u4E2D\u95F4\u8F6E\uFF09\uFF0C\u6B63\u5E38\u7ED3\u675F`);const s=Date.now()-k;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${s}ms`),e.end()}}),n.on("error",s=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${s.message}`),e.headersSent?x||e.end():_(e,502,`Bad Gateway: ${s.message}`,"server_error","proxy_error")})}else{const y=c.includes("/chat/completions"),g=[];n.on("data",p=>{g.push(p)}),n.on("end",async()=>{const p=Buffer.concat(g),x=p.toString("utf-8");a>=400&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u9519\u8BEF (status=${a}): ${x.substring(0,1e3)}`);let u=null;if(y)try{u=JSON.parse(x)}catch{}if(u?.type==="upstream_error"||u?.error?.type==="upstream_error"){const f=u.reqid||u.error?.reqid;if((0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${f})\uFF0C\u539F\u59CB\u56DE\u5305: ${x.substring(0,2e3)}\uFF0C\u8FD4\u56DE\u53CB\u597D\u63D0\u793A`),e.headersSent)e.end();else{const w=d?.model||"QBotClawRouter";O(e,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",w)}return}if(y&&a>=200&&a<300&&u)try{const f=[];if(Array.isArray(u.choices))for(const s of u.choices){const $=s.message?.content;typeof $=="string"&&$.length>0&&f.push($)}const w=Array.isArray(u.choices)&&u.choices.some(s=>Array.isArray(s.message?.tool_calls)&&s.message.tool_calls.length>0||s.message?.function_call!=null);if(f.length===0&&!w){if((0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u26A0\uFE0F \u6A21\u578B\u8F93\u51FA\u5185\u5BB9\u4E3A\u7A7A\u4E14\u65E0tool_calls\uFF0C\u8FD4\u56DE\u7EDF\u4E00\u63D0\u793A`),e.headersSent)e.end();else{const s=d?.model||u?.model||"QBotClawRouter";O(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",s)}return}if(f.length===0&&w&&(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4F46\u5305\u542Btool_calls\uFF08\u51FD\u6570\u8C03\u7528\u4E2D\u95F4\u8F6E\uFF09\uFF0C\u6B63\u5E38\u900F\u4F20`),f.length>0){const s=f.join(`
|
|
20
|
+
`);(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${s.length}`),await(0,S.reviewText)(s,S.AuditContentType.OUTPUT,l),(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}}catch(f){if(f instanceof S.ContentReviewFailedError){if((0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${f.fallbackMsg}`),e.headersSent)e.end();else{const w=d?.model||"QBotClawRouter";O(e,f.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002",w)}return}(0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${f.message||f}`)}e.headersSent||e.writeHead(a,U),e.end(p);const M=Date.now()-k;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${M}ms`)}),n.on("error",p=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${p.message}`),e.headersSent?e.end():_(e,502,`Bad Gateway: ${p.message}`,"server_error","proxy_error")})}});return D.on("error",n=>{const a=Date.now()-k;(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u8BF7\u6C42\u5931\u8D25 (${a}ms): ${n.message}`),e.headersSent?e.end():_(e,502,`Bad Gateway: ${n.message}`,"server_error","proxy_error")}),D.on("timeout",()=>{const n=Date.now()-k;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u8D85\u65F6 (${n}ms)`),D.destroy(),e.headersSent?e.end():_(e,504,"Gateway Timeout","server_error","gateway_timeout")}),D.end(A),!0}
|