@qqbrowser/qbot-claw-launcher 0.10.10 → 0.10.11

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.
@@ -34,10 +34,12 @@ class ContentReviewApi extends trpc_1.TrpcApi {
34
34
  }
35
35
  exports.contentReviewApi = new ContentReviewApi();
36
36
  class ContentReviewFailedError extends Error {
37
- constructor(fallbackMsg) {
37
+ constructor(fallbackMsg, is_show, phase_action) {
38
38
  super('内容审核未通过');
39
39
  this.name = 'ContentReviewFailedError';
40
40
  this.fallbackMsg = fallbackMsg;
41
+ this.is_show = is_show;
42
+ this.phase_action = phase_action;
41
43
  }
42
44
  }
43
45
  exports.ContentReviewFailedError = ContentReviewFailedError;
@@ -64,8 +66,9 @@ const reviewText = async (text, auditContentType, authOrLoginInfo) => {
64
66
  else {
65
67
  rsp = await exports.contentReviewApi.getReviewResult(body, authOrLoginInfo);
66
68
  }
69
+ (0, reportLog_1.log)(`[content-review] rsp: ${JSON.stringify(rsp)}`);
67
70
  if (!rsp.pass) {
68
- throw new ContentReviewFailedError(rsp.fallback_msg);
71
+ throw new ContentReviewFailedError(rsp.fallback_msg, rsp.is_show, rsp.phase_action);
69
72
  }
70
73
  return rsp.session_id;
71
74
  };
@@ -1 +1 @@
1
- {"version":3,"file":"content-review.js","sourceRoot":"","sources":["../../src/api/content-review.ts"],"names":[],"mappings":";;;AACA,iCAAwC;AAExC,4CAAmC;AAenC,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,qEAAe,CAAA;IAEf,yDAAS,CAAA;IAET,2DAAU,CAAA;IAEV,+DAAY,CAAA;AACd,CAAC,EARW,gBAAgB,gCAAhB,gBAAgB,QAQ3B;AAgCM,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAyB,EAAE;IACtF,MAAM,UAAU,GAAG,UAAU,EAAE,mBAAmB,EAAE,CAAC;IACrD,MAAM,SAAS,GAAG,UAAU,EAAE,YAAY,EAAE,CAAC;IA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mB,EAAE,CAAC,EAAE,CAAC,CAAC;IAChK,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,EAAC,UAAU,CAAC,CAAC;IACvD,IAAA,eAAG,EAAC,kCAAkC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAEtE,MAAM,IAAI,GAAuB;QAC/B,cAAc,EAAE,YAAY;QAC5B,UAAU,EAAE,SAAS;QACrB,IAAI;QACJ,kBAAkB,EAAE,gBAAgB;KACrC,CAAC;IAEF,IAAI,GAAuB,CAAC;IAE5B,IAAI,UAAU,EAAE,CAAC;QAEf,GAAG,GAAG,MAAM,UAAU,CAAC,YAAY,CACjC,CAAC,SAAS,EAAE,YAAY,EAAE,EAAE,CAAC,wBAAgB,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,YAAY,CAAC,CAC7F,CAAC;IACJ,CAAC;SAAM,CAAC;QAEN,GAAG,GAAG,MAAM,wBAAgB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAwC,CAAC,CAAC;IAC/F,CAAC;IAED,IAAA,eAAG,EAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,wBAAwB,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,GAAG,CAAC,UAAU,CAAC;AACxB,CAAC,CAAC;AA3CW,QAAA,UAAU,cA2CrB"}
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.10",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.11",exports.IS_DEBUG_BUILD=!1;
@@ -1,33 +1,35 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isFilePickerBusy=P,exports.showFilePicker=O;const w=require("child_process"),d=3e5;let h=!1;function P(){return h}async function O(s={}){if(h)throw new Error("\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A");h=!0;try{const n=process.platform;switch(n){case"darwin":return await k(s);case"win32":return await S(s);case"linux":return await E(s);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0: ${n}`)}}finally{h=!1}}function k(s){const{extensions:n=[],multiple:a=!1,title:p="\u9009\u62E9\u6587\u4EF6",allowDirectory:f=!1}=s;let e;if(f)e=`choose folder with prompt "${$(p)}"`,a&&(e+=" with multiple selections allowed");else if(e=`choose file with prompt "${$(p)}"`,a&&(e+=" with multiple selections allowed"),n.length>0){const l=n.map(t=>`"${t.replace(/^\./,"")}"`).join(", ");e+=` of type {${l}}`}const i=a?`set selectedItems to (${e})
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isFilePickerBusy=P,exports.showFilePicker=O;const d=require("child_process"),w=3e5;let h=!1;function P(){return h}async function O(l={}){if(h)throw new Error("\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A");h=!0;try{const o=process.platform;switch(o){case"darwin":return await S(l);case"win32":return await k(l);case"linux":return await E(l);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0: ${o}`)}}finally{h=!1}}function S(l){const{extensions:o=[],multiple:a=!1,title:u="\u9009\u62E9\u6587\u4EF6",allowDirectory:m=!1}=l;let e;if(m)e=`choose folder with prompt "${y(u)}"`,a&&(e+=" with multiple selections allowed");else if(e=`choose file with prompt "${y(u)}"`,a&&(e+=" with multiple selections allowed"),o.length>0){const i=o.map(t=>`"${t.replace(/^\./,"")}"`).join(", ");e+=` of type {${i}}`}const n=a?`set selectedItems to (${e})
2
2
  set posixPaths to ""
3
3
  repeat with anItem in selectedItems
4
4
  set posixPaths to posixPaths & POSIX path of anItem & linefeed
5
5
  end repeat
6
6
  return posixPaths`:`set selectedItem to (${e})
7
- return POSIX path of selectedItem`;return new Promise((l,t)=>{const o=(0,w.execFile)("osascript",["-e",i],{timeout:d},(u,c,r)=>{if(u){if(u.killed){t(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(r&&r.includes("User canceled")){l(null);return}if(u.code===1){l(null);return}t(new Error(`macOS \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${r||u.message}`));return}const m=c.trim().split(`
8
- `).map(F=>F.trim()).filter(Boolean);l(m.length>0?m:null)})})}function $(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function S(s){const{extensions:n=[],multiple:a=!1,title:p="\u9009\u62E9\u6587\u4EF6",allowDirectory:f=!1}=s;let e;if(f)e=`
7
+ return POSIX path of selectedItem`;return new Promise((i,t)=>{const c=(0,d.execFile)("osascript",["-e",n],{timeout:w},(s,p,r)=>{if(s){if(s.killed){t(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(r&&r.includes("User canceled")){i(null);return}if(s.code===1){i(null);return}t(new Error(`macOS \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${r||s.message}`));return}const f=p.trim().split(`
8
+ `).map(g=>g.trim()).filter(Boolean);i(f.length>0?f:null)})})}function y(l){return l.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function k(l){const{extensions:o=[],multiple:a=!1,title:u="\u9009\u62E9\u6587\u4EF6",allowDirectory:m=!1}=l;let e;const n="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;";if(m)e=`
9
+ ${n}
9
10
  Add-Type -AssemblyName System.Windows.Forms
10
11
  $dialog = New-Object System.Windows.Forms.FolderBrowserDialog
11
- $dialog.Description = '${g(p)}'
12
+ $dialog.Description = '${$(u)}'
12
13
  $dialog.ShowNewFolderButton = $true
13
14
  $result = $dialog.ShowDialog()
14
15
  if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
15
16
  Write-Output $dialog.SelectedPath
16
17
  } else {
17
18
  Write-Output ''
18
- }`;else{let i="\u6240\u6709\u6587\u4EF6 (*.*)|*.*";if(n.length>0){const l=n.map(o=>`*${o.startsWith(".")?o:"."+o}`).join(";");i=`\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B (${n.map(o=>o.startsWith(".")?o:"."+o).join(", ")})|${l}|\u6240\u6709\u6587\u4EF6 (*.*)|*.*`}e=`
19
+ }`;else{let i="\u6240\u6709\u6587\u4EF6 (*.*)|*.*";if(o.length>0){const t=o.map(s=>`*${s.startsWith(".")?s:"."+s}`).join(";");i=`\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B (${o.map(s=>s.startsWith(".")?s:"."+s).join(", ")})|${t}|\u6240\u6709\u6587\u4EF6 (*.*)|*.*`}e=`
20
+ ${n}
19
21
  Add-Type -AssemblyName System.Windows.Forms
20
22
  $dialog = New-Object System.Windows.Forms.OpenFileDialog
21
- $dialog.Title = '${g(p)}'
22
- $dialog.Filter = '${g(i)}'
23
+ $dialog.Title = '${$(u)}'
24
+ $dialog.Filter = '${$(i)}'
23
25
  $dialog.Multiselect = $${a?"true":"false"}
24
26
  $result = $dialog.ShowDialog()
25
27
  if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
26
28
  $dialog.FileNames | ForEach-Object { Write-Output $_ }
27
29
  } else {
28
30
  Write-Output ''
29
- }`}return new Promise((i,l)=>{(0,w.execFile)("powershell.exe",["-NoProfile","-NonInteractive","-Command",e],{timeout:d,windowsHide:!0},(t,o,u)=>{if(t){if(t.killed){l(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}l(new Error(`Windows \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${u||t.message}`));return}const c=o.trim();if(!c){i(null);return}const r=c.split(`
30
- `).map(m=>m.trim()).filter(Boolean);i(r.length>0?r:null)})})}function g(s){return s.replace(/'/g,"''")}async function E(s){if(await y("zenity"))return W(s);if(await y("kdialog"))return D(s);throw new Error("Linux \u7CFB\u7EDF\u672A\u5B89\u88C5 zenity \u6216 kdialog\uFF0C\u65E0\u6CD5\u5F39\u51FA\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u3002\u8BF7\u5B89\u88C5\u5176\u4E2D\u4E4B\u4E00\uFF1Asudo apt install zenity \u6216 sudo apt install kdialog")}function y(s){return new Promise(n=>{(0,w.execFile)("which",[s],a=>{n(!a)})})}function W(s){const{extensions:n=[],multiple:a=!1,title:p="\u9009\u62E9\u6587\u4EF6",allowDirectory:f=!1}=s,e=["--file-selection",`--title=${p}`];if(f&&e.push("--directory"),a&&e.push("--multiple",`--separator=
31
- `),!f&&n.length>0){const i=n.map(l=>`*${l.startsWith(".")?l:"."+l}`).join(" ");e.push(`--file-filter=\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B | ${i}`),e.push("--file-filter=\u6240\u6709\u6587\u4EF6 | *")}return new Promise((i,l)=>{(0,w.execFile)("zenity",e,{timeout:d},(t,o,u)=>{if(t){if(t.killed){l(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(t.code===1){i(null);return}l(new Error(`zenity \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${u||t.message}`));return}const c=o.trim();if(!c){i(null);return}const r=c.split(`
32
- `).map(m=>m.trim()).filter(Boolean);i(r.length>0?r:null)})})}function D(s){const{extensions:n=[],multiple:a=!1,title:p="\u9009\u62E9\u6587\u4EF6",allowDirectory:f=!1}=s;let e;if(f)e=["--getexistingdirectory",process.env.HOME||"/"];else{let i="";n.length>0&&(i=`${n.map(t=>`*${t.startsWith(".")?t:"."+t}`).join(" ")} | \u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B`),a?e=["--getopenfilename",process.env.HOME||"/",i,"--multiple","--separate-output"]:e=["--getopenfilename",process.env.HOME||"/",i]}return e.push("--title",p),new Promise((i,l)=>{(0,w.execFile)("kdialog",e,{timeout:d},(t,o,u)=>{if(t){if(t.killed){l(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(t.code===1){i(null);return}l(new Error(`kdialog \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${u||t.message}`));return}const c=o.trim();if(!c){i(null);return}const r=c.split(`
33
- `).map(m=>m.trim()).filter(Boolean);i(r.length>0?r:null)})})}
31
+ }`}return new Promise((i,t)=>{(0,d.execFile)("powershell.exe",["-NoProfile","-NonInteractive","-Command",e],{timeout:w,windowsHide:!0,encoding:"utf8"},(c,s,p)=>{if(c){if(c.killed){t(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}t(new Error(`Windows \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${p||c.message}`));return}const r=s.trim();if(!r){i(null);return}const f=r.split(`
32
+ `).map(g=>g.trim()).filter(Boolean);i(f.length>0?f:null)})})}function $(l){return l.replace(/'/g,"''")}async function E(l){if(await F("zenity"))return W(l);if(await F("kdialog"))return D(l);throw new Error("Linux \u7CFB\u7EDF\u672A\u5B89\u88C5 zenity \u6216 kdialog\uFF0C\u65E0\u6CD5\u5F39\u51FA\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u3002\u8BF7\u5B89\u88C5\u5176\u4E2D\u4E4B\u4E00\uFF1Asudo apt install zenity \u6216 sudo apt install kdialog")}function F(l){return new Promise(o=>{(0,d.execFile)("which",[l],a=>{o(!a)})})}function W(l){const{extensions:o=[],multiple:a=!1,title:u="\u9009\u62E9\u6587\u4EF6",allowDirectory:m=!1}=l,e=["--file-selection",`--title=${u}`];if(m&&e.push("--directory"),a&&e.push("--multiple",`--separator=
33
+ `),!m&&o.length>0){const n=o.map(i=>`*${i.startsWith(".")?i:"."+i}`).join(" ");e.push(`--file-filter=\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B | ${n}`),e.push("--file-filter=\u6240\u6709\u6587\u4EF6 | *")}return new Promise((n,i)=>{(0,d.execFile)("zenity",e,{timeout:w},(t,c,s)=>{if(t){if(t.killed){i(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(t.code===1){n(null);return}i(new Error(`zenity \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${s||t.message}`));return}const p=c.trim();if(!p){n(null);return}const r=p.split(`
34
+ `).map(f=>f.trim()).filter(Boolean);n(r.length>0?r:null)})})}function D(l){const{extensions:o=[],multiple:a=!1,title:u="\u9009\u62E9\u6587\u4EF6",allowDirectory:m=!1}=l;let e;if(m)e=["--getexistingdirectory",process.env.HOME||"/"];else{let n="";o.length>0&&(n=`${o.map(t=>`*${t.startsWith(".")?t:"."+t}`).join(" ")} | \u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B`),a?e=["--getopenfilename",process.env.HOME||"/",n,"--multiple","--separate-output"]:e=["--getopenfilename",process.env.HOME||"/",n]}return e.push("--title",u),new Promise((n,i)=>{(0,d.execFile)("kdialog",e,{timeout:w},(t,c,s)=>{if(t){if(t.killed){i(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(t.code===1){n(null);return}i(new Error(`kdialog \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${s||t.message}`));return}const p=c.trim();if(!p){n(null);return}const r=p.split(`
35
+ `).map(f=>f.trim()).filter(Boolean);n(r.length>0?r:null)})})}
@@ -1,20 +1,18 @@
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}
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}]})}
2
2
 
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}
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 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}
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}
8
8
 
9
9
  `),r.write(`data: [DONE]
10
10
 
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
-
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,`
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=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,`
16
14
  `).replace(/\r/g,`
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}
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqbrowser/qbot-claw-launcher",
3
- "version": "0.10.10",
3
+ "version": "0.10.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {