@qqbrowser/qbot-claw-launcher 0.10.17 → 0.10.18

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 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.10.17",exports.IS_DEBUG_BUILD=!1;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.10.18",exports.IS_DEBUG_BUILD=!1;
@@ -1,18 +1,18 @@
1
- "use strict";var J=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.proxyApiKey=void 0,exports.handleOpenAIProxy=Se;const G=J(require("crypto")),fe=J(require("http")),de=J(require("https")),te=require("url"),o=require("./reportLog"),oe=require("./api/llm-access-proxy"),ge=require("./api/auth-client"),w=require("./api/content-review");exports.proxyApiKey=G.default.randomBytes(32).toString("base64url");const he={enabled:!0,targetBaseUrl:"https://qbqaproxy.imtt.qq.com/openapi",allowedApiKeys:[exports.proxyApiKey],timeout:12e4},p={INVALID_REQUEST:"invalid_request_error",AUTH:"authentication_error",SERVER:"server_error",CONTENT_FILTER:"content_filter",INSUFFICIENT_QUOTA:"insufficient_quota",UPSTREAM:"upstream_error"},u={NOT_FOUND:"not_found",MISSING_API_KEY:"missing_api_key",INVALID_API_KEY:"invalid_api_key",BAD_REQUEST:"bad_request",AUTH_EXPIRED:"auth_expired",TOKEN_FETCH_ERROR:"token_fetch_error",PROXY_ERROR:"proxy_error",GATEWAY_TIMEOUT:"gateway_timeout",CONTENT_REVIEW_FAILED_INPUT:"content_review_failed_input",CONTENT_REVIEW_FAILED_OUTPUT:"content_review_failed_output",CONTENT_REVIEW_FAILED_OUTPUT_PARTIAL:"content_review_failed_output_partial",TOKEN_EXHAUSTED:"token_exhausted",UPSTREAM_UNAVAILABLE:"upstream_unavailable"};function ye(r){const e=r.headers.authorization;if(!e||typeof e!="string")return null;const i=e.match(/^Bearer\s+(.+)$/i);return i?i[1]:null}function _(r,e,i,l,t,h){const y=JSON.stringify({error:{message:i,type:l,code:t,...h||{}}});r.writeHead(e,{"Content-Type":"application/json","Content-Length":Buffer.byteLength(y)}),r.end(y)}function Ee(r,e,i="QBotClawRouter"){const l=Math.floor(Date.now()/1e3),t=`chatcmpl-${G.default.randomBytes(12).toString("hex")}`,h=JSON.stringify({id:t,object:"chat.completion",created:l,model:i,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(h)}),r.end(h)}function _e(r,e,i="QBotClawRouter"){if(!r.writable)return;const l=Math.floor(Date.now()/1e3),t=`chatcmpl-${G.default.randomBytes(12).toString("hex")}`;r.write(`data: ${JSON.stringify({id:t,object:"chat.completion.chunk",created:l,model:i,choices:[{index:0,delta:{role:"assistant",content:e},finish_reason:null}]})}
1
+ "use strict";var J=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.proxyApiKey=void 0,exports.handleOpenAIProxy=Ae;const G=J(require("crypto")),de=J(require("http")),ge=J(require("https")),ne=require("url"),o=require("./reportLog"),W=require("./api/llm-access-proxy"),he=require("./api/auth-client"),w=require("./api/content-review");exports.proxyApiKey=G.default.randomBytes(32).toString("base64url");const ye={enabled:!0,targetBaseUrl:"https://qbqaproxy.imtt.qq.com/openapi",allowedApiKeys:[exports.proxyApiKey],timeout:12e4},p={INVALID_REQUEST:"invalid_request_error",AUTH:"authentication_error",SERVER:"server_error",CONTENT_FILTER:"content_filter",INSUFFICIENT_QUOTA:"insufficient_quota",UPSTREAM:"upstream_error"},u={NOT_FOUND:"not_found",MISSING_API_KEY:"missing_api_key",INVALID_API_KEY:"invalid_api_key",BAD_REQUEST:"bad_request",AUTH_EXPIRED:"auth_expired",TOKEN_FETCH_ERROR:"token_fetch_error",PROXY_ERROR:"proxy_error",GATEWAY_TIMEOUT:"gateway_timeout",CONTENT_REVIEW_FAILED_INPUT:"content_review_failed_input",CONTENT_REVIEW_FAILED_OUTPUT:"content_review_failed_output",CONTENT_REVIEW_FAILED_OUTPUT_PARTIAL:"content_review_failed_output_partial",TOKEN_EXHAUSTED:"token_exhausted",UPSTREAM_UNAVAILABLE:"upstream_unavailable"};function Ee(r){const e=r.headers.authorization;if(!e||typeof e!="string")return null;const i=e.match(/^Bearer\s+(.+)$/i);return i?i[1]:null}function _(r,e,i,l,t,h){const y=JSON.stringify({error:{message:i,type:l,code:t,...h||{}}});r.writeHead(e,{"Content-Type":"application/json","Content-Length":Buffer.byteLength(y)}),r.end(y)}function _e(r,e,i="QBotClawRouter"){const l=Math.floor(Date.now()/1e3),t=`chatcmpl-${G.default.randomBytes(12).toString("hex")}`,h=JSON.stringify({id:t,object:"chat.completion",created:l,model:i,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(h)}),r.end(h)}function Te(r,e,i="QBotClawRouter"){if(!r.writable)return;const l=Math.floor(Date.now()/1e3),t=`chatcmpl-${G.default.randomBytes(12).toString("hex")}`;r.write(`data: ${JSON.stringify({id:t,object:"chat.completion.chunk",created:l,model:i,choices:[{index:0,delta:{role:"assistant",content:e},finish_reason:null}]})}
2
2
 
3
3
  `),r.write(`data: ${JSON.stringify({id:t,object:"chat.completion.chunk",created:l,model:i,choices:[{index:0,delta:{},finish_reason:"stop"}]})}
4
4
 
5
5
  `),r.write(`data: [DONE]
6
6
 
7
- `),r.end()}function Te(){return Math.random().toString(36).substring(2,10)}function ne(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 i=e.content,l=Array.isArray(e.tool_calls)&&e.tool_calls.length>0||e.function_call!=null;return{content:typeof i=="string"&&i.length>0?i:"",hasToolCalls:l}}function $e(r){try{const e=JSON.parse(r);return ne(e)}catch(e){return(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${e}`),{content:"",hasToolCalls:!1}}}function k(r,e,i,l,t){if(!r.writable)return;const h={message:e,type:i,code:l,...t||{}},y=JSON.stringify({error:h});r.write(`data: ${y}
7
+ `),r.end()}function $e(){return Math.random().toString(36).substring(2,10)}function re(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 i=e.content,l=Array.isArray(e.tool_calls)&&e.tool_calls.length>0||e.function_call!=null;return{content:typeof i=="string"&&i.length>0?i:"",hasToolCalls:l}}function me(r){try{const e=JSON.parse(r);return re(e)}catch(e){return(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${e}`),{content:"",hasToolCalls:!1}}}function b(r,e,i,l,t){if(!r.writable)return;const h={message:e,type:i,code:l,...t||{}},y=JSON.stringify({error:h});r.write(`data: ${y}
8
8
 
9
9
  `),r.write(`data: [DONE]
10
10
 
11
- `),r.end()}function re(r,e){const{isStream:i,httpStatus:l,message:t,type:h,code:y,extra:O}=e;if(!i){_(r,l,t,h,y,O);return}if(!r.headersSent){_(r,l,t,h,y,O);return}k(r,t,h,y,O)}function me(r){return new Promise((e,i)=>{const l=[];r.on("data",t=>l.push(t)),r.on("end",()=>e(Buffer.concat(l))),r.on("error",i)})}async function Se(r,e,i){const l=r.url||"";if(!l.startsWith("/v1/"))return!1;const t=Te(),h=r.method||"GET",y=Date.now();(0,o.log)(`[openai-proxy][${t}] \u6536\u5230\u8BF7\u6C42: ${h} ${l}`);const O=he;if(!O.enabled)return(0,o.log)(`[openai-proxy][${t}] \u4EE3\u7406\u672A\u542F\u7528\uFF0C\u8FD4\u56DE 404`),_(e,404,"Not Found",p.INVALID_REQUEST,u.NOT_FOUND),!0;const W=ye(r);if(!W)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.",p.INVALID_REQUEST,u.MISSING_API_KEY),!0;if(!O.allowedApiKeys.includes(W))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.",p.INVALID_REQUEST,u.INVALID_API_KEY),!0;let D;try{D=await me(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",p.INVALID_REQUEST,u.BAD_REQUEST),!0}let x=!1,A=null;if(l.includes("/chat/completions")&&D.length>0)try{A=JSON.parse(D.toString("utf-8")),x=A.stream===!0,(0,o.log)(`[openai-proxy][${t}] stream=${A.stream}`)}catch{}let q=!1;if(Array.isArray(A?.messages)){const n=A.messages;let a=-1;for(let s=n.length-1;s>=0;s--)if(n[s].role==="user"){a=s;break}a>=0&&(q=n.slice(a+1).some(s=>s.role==="tool"))}if(q&&(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`),A&&l.includes("/chat/completions")&&Array.isArray(A.messages)&&!q){const n=[];for(const a of A.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 s of a.content)s.type==="text"&&typeof s.text=="string"&&s.text.length>0&&n.push(s.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,w.reviewText)(a,w.AuditContentType.INPUT,i),(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}catch(s){if(s instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${s.fallbackMsg}`);const B=s.fallbackMsg||"\u8F93\u5165\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002";return re(e,{isStream:x,httpStatus:400,message:B,type:p.CONTENT_FILTER,code:u.CONTENT_REVIEW_FAILED_INPUT,extra:{phase_action:s.phase_action,is_show:s.is_show}}),!0}(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${s.message||JSON.stringify(s)}`)}}}const Q=new te.URL(O.targetBaseUrl),ae=Q.pathname.replace(/\/+$/,""),se=l.replace(/^\/v1/,""),C=new te.URL(ae+se,Q.origin),X=C.protocol==="https:",ie=X?de.default:fe.default,le=X?443:80,L={};for(const[n,a]of Object.entries(r.headers)){if(!a)continue;const s=n.toLowerCase();["host","connection","keep-alive","transfer-encoding","upgrade"].includes(s)||(L[n]=a)}L.host=C.host;let H;try{H=await(0,oe.fetchLlmToken)(i),(0,o.log)(`[openai-proxy][${t}] \u6210\u529F\u83B7\u53D6 LLM Token ${H}`)}catch(n){if(n instanceof oe.TokenExhaustedError){(0,o.log)(`[openai-proxy][${t}] Token \u5DF2\u8017\u5C3D: ${n.message}`);const s=n.message||"\u5F53\u65E5Token\u5DF2\u8017\u5C3D\uFF0C\u8BF7\u5207\u6362\u6A21\u578B\u6216\u660E\u65E5\u518D\u8BD5";return re(e,{isStream:x,httpStatus:429,message:s,type:p.INSUFFICIENT_QUOTA,code:u.TOKEN_EXHAUSTED}),!0}if(n instanceof ge.AuthExpiredError)return(0,o.log)(`[openai-proxy][${t}] \u7968\u636E\u8FC7\u671F: ${n.message}`),_(e,401,`Auth token expired: ${n.message}`,p.AUTH,u.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}`,p.SERVER,u.TOKEN_FETCH_ERROR),!0}L.authorization=`Bearer ${H}`;const ce={hostname:C.hostname,port:C.port||le,path:C.pathname+C.search,method:h,headers:L,timeout:O.timeout||12e4};(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u5230: ${h} ${C.href}`);try{const n=D.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 v=ie.request(ce,n=>{const a=n.statusCode||502,s=n.headers["content-type"]||"",B=s.includes("text/event-stream")||x,pe=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u76EE\u6807\u54CD\u5E94: ${a} ${s} (${pe}ms)${B?" [SSE\u6D41\u5F0F]":""} (isStreamRequest=${x})`);const K={};for(const[T,E]of Object.entries(n.headers)){if(!E)continue;const f=T.toLowerCase();["connection","keep-alive","upgrade"].includes(f)||(K[T]=E)}const j=x&&!s.includes("text/event-stream")&&a>=400;if(j&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u975ESSE\u9519\u8BEF\u54CD\u5E94 (status=${a}, content-type=${s})\uFF0C\u964D\u7EA7\u4E3A\u975E\u6D41\u5F0F\u5904\u7406`),B&&!j){e.writeHead(a,K);let T="",E="",f="",$=!1,d=!1,M=!1;const g=100;let R=[],m=!1,N=!1,z=Promise.resolve();const Y=()=>{if(!(!e.writable||$)){for(const c of R)e.write(c);R.length>0&&(m=!0),R=[]}},Z=async(c,U)=>{if(!c||$)return;const b=w.AuditContentType.OUTPUT;try{(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838${U?"(\u6700\u7EC8)":""}\uFF0C\u6587\u672C\u957F\u5EA6: ${c.length}\uFF0C\u9001\u5BA1\u5185\u5BB9:
13
- ${c}`),await(0,w.reviewText)(c,b,i),(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7\uFF0Cflush ${R.length} \u4E2A\u7F13\u5B58chunk`),Y()}catch(S){if(S instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${S.fallbackMsg}`),$=!0,R=[];const I=`400 ${S.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002"}`;m?((0,o.log)(`[openai-proxy][${t}] [SSE] \u5DF2\u6709\u5185\u5BB9\u88ABflush\uFF0C\u8FFD\u52A0\u6807\u51C6 error`),k(e,I,p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT_PARTIAL,{phase_action:S.phase_action,is_show:S.is_show})):((0,o.log)(`[openai-proxy][${t}] [SSE] \u5C1A\u672Aflush\u4EFB\u4F55\u5185\u5BB9\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),k(e,I,p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT,{phase_action:S.phase_action,is_show:S.is_show})),n.destroy();return}(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF0C\u76F4\u63A5flush\uFF09: ${S.message||JSON.stringify(S)}`),Y()}};n.on("data",c=>{if($){(0,o.log)(`[openai-proxy][${t}] [SSE] \u5BA1\u6838\u5DF2\u4E2D\u65AD\uFF0C\u8DF3\u8FC7chunk (${c.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 (${c.length}\u5B57\u8282)`);return}const U=c.toString("utf-8");f+=U,f=f.replace(/\r\n/g,`
11
+ `),r.end()}function ae(r,e){const{isStream:i,httpStatus:l,message:t,type:h,code:y,extra:O}=e;if(!i){_(r,l,t,h,y,O);return}if(!r.headersSent){_(r,l,t,h,y,O);return}b(r,t,h,y,O)}function Se(r){return new Promise((e,i)=>{const l=[];r.on("data",t=>l.push(t)),r.on("end",()=>e(Buffer.concat(l))),r.on("error",i)})}async function Ae(r,e,i){const l=r.url||"";if(!l.startsWith("/v1/"))return!1;const t=$e(),h=r.method||"GET",y=Date.now();(0,o.log)(`[openai-proxy][${t}] \u6536\u5230\u8BF7\u6C42: ${h} ${l}`);const O=ye;if(!O.enabled)return(0,o.log)(`[openai-proxy][${t}] \u4EE3\u7406\u672A\u542F\u7528\uFF0C\u8FD4\u56DE 404`),_(e,404,"Not Found",p.INVALID_REQUEST,u.NOT_FOUND),!0;const Q=Ee(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.",p.INVALID_REQUEST,u.MISSING_API_KEY),!0;if(!O.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.",p.INVALID_REQUEST,u.INVALID_API_KEY),!0;let D;try{D=await Se(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",p.INVALID_REQUEST,u.BAD_REQUEST),!0}let x=!1,A=null;if(l.includes("/chat/completions")&&D.length>0)try{A=JSON.parse(D.toString("utf-8")),x=A.stream===!0,(0,o.log)(`[openai-proxy][${t}] stream=${A.stream}`)}catch{}let V=!1;if(Array.isArray(A?.messages)){const n=A.messages;let a=-1;for(let s=n.length-1;s>=0;s--)if(n[s].role==="user"){a=s;break}a>=0&&(V=n.slice(a+1).some(s=>s.role==="tool"))}if(V&&(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`),A&&l.includes("/chat/completions")&&Array.isArray(A.messages)&&!V){const n=[];for(const a of A.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 s of a.content)s.type==="text"&&typeof s.text=="string"&&s.text.length>0&&n.push(s.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,w.reviewText)(a,w.AuditContentType.INPUT,i),(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}catch(s){if(s instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${s.fallbackMsg}`);const B=s.fallbackMsg||"\u8F93\u5165\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002";return ae(e,{isStream:x,httpStatus:400,message:B,type:p.CONTENT_FILTER,code:u.CONTENT_REVIEW_FAILED_INPUT,extra:{phase_action:s.phase_action,is_show:s.is_show}}),!0}(0,o.log)(`[openai-proxy][${t}] \u8F93\u5165\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${s.message||JSON.stringify(s)}`)}}}const X=new ne.URL(O.targetBaseUrl),se=X.pathname.replace(/\/+$/,""),ie=l.replace(/^\/v1/,""),P=new ne.URL(se+ie,X.origin),j=P.protocol==="https:",le=j?ge.default:de.default,ce=j?443:80,k={};for(const[n,a]of Object.entries(r.headers)){if(!a)continue;const s=n.toLowerCase();["host","connection","keep-alive","transfer-encoding","upgrade"].includes(s)||(k[n]=a)}k.host=P.host;let H;try{H=await(0,W.fetchLlmToken)(i),(0,o.log)(`[openai-proxy][${t}] \u6210\u529F\u83B7\u53D6 LLM Token ${H}`)}catch(n){if(n instanceof W.TokenExhaustedError){(0,o.log)(`[openai-proxy][${t}] Token \u5DF2\u8017\u5C3D: ${n.message}`);const s=n.message||"\u5F53\u65E5Token\u5DF2\u8017\u5C3D\uFF0C\u8BF7\u5207\u6362\u6A21\u578B\u6216\u660E\u65E5\u518D\u8BD5";return ae(e,{isStream:x,httpStatus:429,message:s,type:p.INSUFFICIENT_QUOTA,code:u.TOKEN_EXHAUSTED}),!0}if(n instanceof he.AuthExpiredError)return(0,o.log)(`[openai-proxy][${t}] \u7968\u636E\u8FC7\u671F: ${n.message}`),_(e,401,`Auth token expired: ${n.message}`,p.AUTH,u.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}`,p.SERVER,u.TOKEN_FETCH_ERROR),!0}const z=await(0,W.getUserBase)(i);k.qimei36=z.qimei36,k.qua2=z.qua2,k.authorization=`Bearer ${H}`;const pe={hostname:P.hostname,port:P.port||ce,path:P.pathname+P.search,method:h,headers:k,timeout:O.timeout||12e4};(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u5230: ${h} ${P.href}`);try{const n=D.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 v=le.request(pe,n=>{const a=n.statusCode||502,s=n.headers["content-type"]||"",B=s.includes("text/event-stream")||x,ue=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u76EE\u6807\u54CD\u5E94: ${a} ${s} (${ue}ms)${B?" [SSE\u6D41\u5F0F]":""} (isStreamRequest=${x})`);const K={};for(const[T,E]of Object.entries(n.headers)){if(!E)continue;const f=T.toLowerCase();["connection","keep-alive","upgrade"].includes(f)||(K[T]=E)}const Z=x&&!s.includes("text/event-stream")&&a>=400;if(Z&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u975ESSE\u9519\u8BEF\u54CD\u5E94 (status=${a}, content-type=${s})\uFF0C\u964D\u7EA7\u4E3A\u975E\u6D41\u5F0F\u5904\u7406`),B&&!Z){e.writeHead(a,K);let T="",E="",f="",$=!1,d=!1,q=!1;const g=100;let R=[],m=!1,N=!1,ee=Promise.resolve();const Y=()=>{if(!(!e.writable||$)){for(const c of R)e.write(c);R.length>0&&(m=!0),R=[]}},te=async(c,U)=>{if(!c||$)return;const L=w.AuditContentType.OUTPUT;try{(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838${U?"(\u6700\u7EC8)":""}\uFF0C\u6587\u672C\u957F\u5EA6: ${c.length}\uFF0C\u9001\u5BA1\u5185\u5BB9:
13
+ ${c}`),await(0,w.reviewText)(c,L,i),(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7\uFF0Cflush ${R.length} \u4E2A\u7F13\u5B58chunk`),Y()}catch(S){if(S instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${S.fallbackMsg}`),$=!0,R=[];const I=`400 ${S.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002"}`;m?((0,o.log)(`[openai-proxy][${t}] [SSE] \u5DF2\u6709\u5185\u5BB9\u88ABflush\uFF0C\u8FFD\u52A0\u6807\u51C6 error`),b(e,I,p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT_PARTIAL,{phase_action:S.phase_action,is_show:S.is_show})):((0,o.log)(`[openai-proxy][${t}] [SSE] \u5C1A\u672Aflush\u4EFB\u4F55\u5185\u5BB9\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),b(e,I,p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT,{phase_action:S.phase_action,is_show:S.is_show})),n.destroy();return}(0,o.log)(`[openai-proxy][${t}] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF0C\u76F4\u63A5flush\uFF09: ${S.message||JSON.stringify(S)}`),Y()}};n.on("data",c=>{if($){(0,o.log)(`[openai-proxy][${t}] [SSE] \u5BA1\u6838\u5DF2\u4E2D\u65AD\uFF0C\u8DF3\u8FC7chunk (${c.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 (${c.length}\u5B57\u8282)`);return}const U=c.toString("utf-8");f+=U,f=f.replace(/\r\n/g,`
14
14
  `).replace(/\r/g,`
15
- `);const b=f.split(`
16
- `);f=b.pop()||"";let S=!1;for(let I=0;I<b.length;I++){const F=b[I].trim();if(F){if(F==="data: [DONE]")M=!0;else if(F.startsWith("data: ")){const ee=F.slice(6);try{const P=JSON.parse(ee);if(P?.type==="upstream_error"||P?.error?.type==="upstream_error"){const ue=P.reqid||P.error?.reqid;(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${ue})\uFF0C\u539F\u59CB\u56DE\u5305: ${ee}\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),$=!0,R=[],k(e,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",p.UPSTREAM,u.UPSTREAM_UNAVAILABLE),n.destroy(),S=!0;break}const V=ne(P);V.content&&(T+=V.content,E+=V.content),V.hasToolCalls&&(d=!0)}catch(P){(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${P}`)}}}}if(!S&&(M&&E.length===0&&!d?(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230 [DONE] \u4E14\u8F93\u51FA\u4E3A\u7A7A\uFF0C\u6682\u4E0D\u7F13\u5B58\uFF0C\u7B49\u5F85 end \u4E8B\u4EF6\u5904\u7406`):R.push(c),T.length>=g&&!N)){const I=T;T="",(0,o.log)(`[openai-proxy][${t}] [SSE] \u89E6\u53D1\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${I.length} ${I}`),N=!0,n.pause(),z=Z(I,!1).finally(()=>{N=!1,$||n.resume()})}}),n.on("end",async()=>{if(N&&((0,o.log)(`[openai-proxy][${t}] [SSE] end\u4E8B\u4EF6\u89E6\u53D1\uFF0C\u7B49\u5F85\u8FDB\u884C\u4E2D\u7684\u5BA1\u6838\u5B8C\u6210...`),await z),f.trim()){const c=f.trim();if(c.startsWith("data: ")&&c!=="data: [DONE]"){const U=$e(c.slice(6));U.content&&(T+=U.content,E+=U.content),U.hasToolCalls&&(d=!0)}}if(E.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 (${E.length}\u5B57\u7B26):
17
- ${E}`),T.length>0&&!$&&await Z(T,!0),!$){if(Y(),E.length===0&&!d){(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4E14\u65E0tool_calls\uFF0C\u8FD4\u56DE\u7EDF\u4E00\u63D0\u793A`),_e(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",A?.model||"QBotClawRouter");return}E.length===0&&d&&(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 c=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${c}ms`),e.end()}}),n.on("error",c=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${c.message}`),e.headersSent?$||k(e,`Bad Gateway: ${c.message}`,p.SERVER,u.PROXY_ERROR):_(e,502,`Bad Gateway: ${c.message}`,p.SERVER,u.PROXY_ERROR)})}else{const T=l.includes("/chat/completions"),E=[];n.on("data",f=>{E.push(f)}),n.on("end",async()=>{const f=Buffer.concat(E),$=f.toString("utf-8");a>=400&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u9519\u8BEF (status=${a}): ${$.substring(0,1e3)}`);let d=null;if(T)try{d=JSON.parse($)}catch{}if(d?.type==="upstream_error"||d?.error?.type==="upstream_error"){const g=d.reqid||d.error?.reqid;(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${g})\uFF0C\u539F\u59CB\u56DE\u5305: ${$.substring(0,2e3)}\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),e.headersSent?e.end():_(e,503,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",p.UPSTREAM,u.UPSTREAM_UNAVAILABLE);return}if(T&&a>=200&&a<300&&d)try{const g=[];if(Array.isArray(d.choices))for(const m of d.choices){const N=m.message?.content;typeof N=="string"&&N.length>0&&g.push(N)}const R=Array.isArray(d.choices)&&d.choices.some(m=>Array.isArray(m.message?.tool_calls)&&m.message.tool_calls.length>0||m.message?.function_call!=null);if(g.length===0&&!R){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 m=A?.model||d?.model||"QBotClawRouter";Ee(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",m)}return}if(g.length===0&&R&&(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`),g.length>0){const m=g.join(`
18
- `);(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${m.length}`),await(0,w.reviewText)(m,w.AuditContentType.OUTPUT,i),(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}}catch(g){if(g instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${g.fallbackMsg}`),e.headersSent?e.end():_(e,400,g.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002",p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT,{phase_action:g.phase_action,is_show:g.is_show});return}(0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${g.message||g}`)}e.headersSent||e.writeHead(a,K),e.end(f);const M=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${M}ms`)}),n.on("error",f=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${f.message}`),e.headersSent?e.end():_(e,502,`Bad Gateway: ${f.message}`,p.SERVER,u.PROXY_ERROR)})}});return v.on("error",n=>{const a=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u8BF7\u6C42\u5931\u8D25 (${a}ms): ${n.message}`),e.headersSent?x?k(e,`Bad Gateway: ${n.message}`,p.SERVER,u.PROXY_ERROR):e.end():_(e,502,`Bad Gateway: ${n.message}`,p.SERVER,u.PROXY_ERROR)}),v.on("timeout",()=>{const n=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u8D85\u65F6 (${n}ms)`),v.destroy(),e.headersSent?x?k(e,"Gateway Timeout",p.SERVER,u.GATEWAY_TIMEOUT):e.end():_(e,504,"Gateway Timeout",p.SERVER,u.GATEWAY_TIMEOUT)}),v.end(D),!0}
15
+ `);const L=f.split(`
16
+ `);f=L.pop()||"";let S=!1;for(let I=0;I<L.length;I++){const M=L[I].trim();if(M){if(M==="data: [DONE]")q=!0;else if(M.startsWith("data: ")){const oe=M.slice(6);try{const C=JSON.parse(oe);if(C?.type==="upstream_error"||C?.error?.type==="upstream_error"){const fe=C.reqid||C.error?.reqid;(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${fe})\uFF0C\u539F\u59CB\u56DE\u5305: ${oe}\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),$=!0,R=[],b(e,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",p.UPSTREAM,u.UPSTREAM_UNAVAILABLE),n.destroy(),S=!0;break}const F=re(C);F.content&&(T+=F.content,E+=F.content),F.hasToolCalls&&(d=!0)}catch(C){(0,o.log)(`[extractDeltaContent] JSON\u89E3\u6790\u5931\u8D25: ${C}`)}}}}if(!S&&(q&&E.length===0&&!d?(0,o.log)(`[openai-proxy][${t}] [SSE] \u68C0\u6D4B\u5230 [DONE] \u4E14\u8F93\u51FA\u4E3A\u7A7A\uFF0C\u6682\u4E0D\u7F13\u5B58\uFF0C\u7B49\u5F85 end \u4E8B\u4EF6\u5904\u7406`):R.push(c),T.length>=g&&!N)){const I=T;T="",(0,o.log)(`[openai-proxy][${t}] [SSE] \u89E6\u53D1\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${I.length} ${I}`),N=!0,n.pause(),ee=te(I,!1).finally(()=>{N=!1,$||n.resume()})}}),n.on("end",async()=>{if(N&&((0,o.log)(`[openai-proxy][${t}] [SSE] end\u4E8B\u4EF6\u89E6\u53D1\uFF0C\u7B49\u5F85\u8FDB\u884C\u4E2D\u7684\u5BA1\u6838\u5B8C\u6210...`),await ee),f.trim()){const c=f.trim();if(c.startsWith("data: ")&&c!=="data: [DONE]"){const U=me(c.slice(6));U.content&&(T+=U.content,E+=U.content),U.hasToolCalls&&(d=!0)}}if(E.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 (${E.length}\u5B57\u7B26):
17
+ ${E}`),T.length>0&&!$&&await te(T,!0),!$){if(Y(),E.length===0&&!d){(0,o.log)(`[openai-proxy][${t}] [SSE] \u6A21\u578B\u8F93\u51FA\u4E3A\u7A7A\u4E14\u65E0tool_calls\uFF0C\u8FD4\u56DE\u7EDF\u4E00\u63D0\u793A`),Te(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",A?.model||"QBotClawRouter");return}E.length===0&&d&&(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 c=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${c}ms`),e.end()}}),n.on("error",c=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${c.message}`),e.headersSent?$||b(e,`Bad Gateway: ${c.message}`,p.SERVER,u.PROXY_ERROR):_(e,502,`Bad Gateway: ${c.message}`,p.SERVER,u.PROXY_ERROR)})}else{const T=l.includes("/chat/completions"),E=[];n.on("data",f=>{E.push(f)}),n.on("end",async()=>{const f=Buffer.concat(E),$=f.toString("utf-8");a>=400&&(0,o.log)(`[openai-proxy][${t}] \u26A0\uFE0F \u4E0A\u6E38\u8FD4\u56DE\u9519\u8BEF (status=${a}): ${$.substring(0,1e3)}`);let d=null;if(T)try{d=JSON.parse($)}catch{}if(d?.type==="upstream_error"||d?.error?.type==="upstream_error"){const g=d.reqid||d.error?.reqid;(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u68C0\u6D4B\u5230\u4E0A\u6E38 upstream_error (reqid=${g})\uFF0C\u539F\u59CB\u56DE\u5305: ${$.substring(0,2e3)}\uFF0C\u8FD4\u56DE\u6807\u51C6 error`),e.headersSent?e.end():_(e,503,"\u5F53\u524D\u4F7F\u7528\u4EBA\u6570\u8F83\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",p.UPSTREAM,u.UPSTREAM_UNAVAILABLE);return}if(T&&a>=200&&a<300&&d)try{const g=[];if(Array.isArray(d.choices))for(const m of d.choices){const N=m.message?.content;typeof N=="string"&&N.length>0&&g.push(N)}const R=Array.isArray(d.choices)&&d.choices.some(m=>Array.isArray(m.message?.tool_calls)&&m.message.tool_calls.length>0||m.message?.function_call!=null);if(g.length===0&&!R){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 m=A?.model||d?.model||"QBotClawRouter";_e(e,"\u62B1\u6B49\uFF0C\u6682\u65F6\u65E0\u6CD5\u56DE\u7B54\u8BE5\u95EE\u9898",m)}return}if(g.length===0&&R&&(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`),g.length>0){const m=g.join(`
18
+ `);(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\uFF0C\u6587\u672C\u957F\u5EA6: ${m.length}`),await(0,w.reviewText)(m,w.AuditContentType.OUTPUT,i),(0,o.log)(`[openai-proxy][${t}] [\u975E\u6D41\u5F0F] \u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u901A\u8FC7`)}}catch(g){if(g instanceof w.ContentReviewFailedError){(0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u672A\u901A\u8FC7: ${g.fallbackMsg}`),e.headersSent?e.end():_(e,400,g.fallbackMsg||"\u8F93\u51FA\u5185\u5BB9\u5305\u542B\u8FDD\u89C4\u4FE1\u606F\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5\u3002",p.CONTENT_FILTER,u.CONTENT_REVIEW_FAILED_OUTPUT,{phase_action:g.phase_action,is_show:g.is_show});return}(0,o.log)(`[openai-proxy][${t}] \u975E\u6D41\u5F0F\u8F93\u51FA\u5185\u5BB9\u5BA1\u6838\u5F02\u5E38\uFF08\u4E0D\u963B\u585E\uFF09: ${g.message||g}`)}e.headersSent||e.writeHead(a,K),e.end(f);const q=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u5B8C\u6210\uFF0C\u603B\u8017\u65F6: ${q}ms`)}),n.on("error",f=>{(0,o.log)(`[openai-proxy][${t}] \u8BFB\u53D6\u76EE\u6807\u54CD\u5E94\u5931\u8D25: ${f.message}`),e.headersSent?e.end():_(e,502,`Bad Gateway: ${f.message}`,p.SERVER,u.PROXY_ERROR)})}});return v.on("error",n=>{const a=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8F6C\u53D1\u8BF7\u6C42\u5931\u8D25 (${a}ms): ${n.message}`),e.headersSent?x?b(e,`Bad Gateway: ${n.message}`,p.SERVER,u.PROXY_ERROR):e.end():_(e,502,`Bad Gateway: ${n.message}`,p.SERVER,u.PROXY_ERROR)}),v.on("timeout",()=>{const n=Date.now()-y;(0,o.log)(`[openai-proxy][${t}] \u8BF7\u6C42\u8D85\u65F6 (${n}ms)`),v.destroy(),e.headersSent?x?b(e,"Gateway Timeout",p.SERVER,u.GATEWAY_TIMEOUT):e.end():_(e,504,"Gateway Timeout",p.SERVER,u.GATEWAY_TIMEOUT)}),v.end(D),!0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqbrowser/qbot-claw-launcher",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {