aicodeswitch 3.0.4 → 3.0.6

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.
@@ -748,7 +748,7 @@ class FileSystemDatabaseManager {
748
748
  const serviceIds = (vendor.services || []).map(s => s.id);
749
749
  const rulesUsingServices = this.rules.filter(r => serviceIds.includes(r.targetServiceId));
750
750
  if (rulesUsingServices.length > 0) {
751
- throw new Error(`无法删除供应商:有 ${rulesUsingServices.length} 个规则正在使用该供应商的服务`);
751
+ throw new Error(`无法删除供应商:有 ${rulesUsingServices.length} 个路由规则正在使用该供应商的服务`);
752
752
  }
753
753
  this.vendors.splice(index, 1);
754
754
  yield this.saveVendors();
@@ -857,7 +857,7 @@ class FileSystemDatabaseManager {
857
857
  // 检查是否有规则正在使用此服务
858
858
  const rulesUsingService = this.rules.filter(r => r.targetServiceId === id);
859
859
  if (rulesUsingService.length > 0) {
860
- throw new Error(`无法删除服务:有 ${rulesUsingService.length} 个规则正在使用此服务`);
860
+ throw new Error(`无法删除服务:有 ${rulesUsingService.length} 个路由规则正在使用此服务`);
861
861
  }
862
862
  vendor.services.splice(index, 1);
863
863
  // 更新供应商的 updatedAt 时间
@@ -76,7 +76,10 @@ app.use((0, cors_1.default)());
76
76
  app.use(express_1.default.json({ limit: 'Infinity' }));
77
77
  app.use(express_1.default.urlencoded({ extended: true, limit: 'Infinity' }));
78
78
  const asyncHandler = (handler) => (req, res, next) => {
79
- Promise.resolve(handler(req, res, next)).catch(next);
79
+ Promise.resolve(handler(req, res, next)).catch((err) => {
80
+ console.error('[asyncHandler] Caught error:', err);
81
+ next(err);
82
+ });
80
83
  };
81
84
  const writeClaudeConfig = (dbManager) => __awaiter(void 0, void 0, void 0, function* () {
82
85
  try {
@@ -728,25 +731,48 @@ const registerRoutes = (dbManager, proxyServer) => {
728
731
  }
729
732
  });
730
733
  app.get('/api/vendors', (_req, res) => res.json(dbManager.getVendors()));
731
- app.post('/api/vendors', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createVendor(req.body)); }));
732
- app.put('/api/vendors/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateVendor(req.params.id, req.body)); }));
733
- app.delete('/api/vendors/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteVendor(req.params.id)); }));
734
+ app.post('/api/vendors', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createVendor(req.body)); })));
735
+ app.put('/api/vendors/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateVendor(req.params.id, req.body)); })));
736
+ app.delete('/api/vendors/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
737
+ try {
738
+ const result = yield dbManager.deleteVendor(req.params.id);
739
+ res.json(result);
740
+ }
741
+ catch (error) {
742
+ console.error('[删除供应商] 错误:', error);
743
+ res.setHeader('Content-Type', 'application/json');
744
+ res.status(500).json({ error: error instanceof Error ? error.message : '删除失败' });
745
+ }
746
+ }));
734
747
  app.get('/api/services', (req, res) => {
735
748
  const vendorId = typeof req.query.vendorId === 'string' ? req.query.vendorId : undefined;
736
749
  res.json(dbManager.getAPIServices(vendorId));
737
750
  });
738
- app.post('/api/services', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
751
+ app.post('/api/services', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () {
739
752
  console.log('[创建服务] 请求数据:', JSON.stringify(req.body, null, 2));
740
753
  const result = yield dbManager.createAPIService(req.body);
741
754
  console.log('[创建服务] 创建结果:', JSON.stringify(result, null, 2));
742
755
  res.json(result);
756
+ })));
757
+ app.put('/api/services/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateAPIService(req.params.id, req.body)); })));
758
+ app.delete('/api/services/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
759
+ console.log('[删除服务] 请求 ID:', req.params.id);
760
+ try {
761
+ const result = yield dbManager.deleteAPIService(req.params.id);
762
+ console.log('[删除服务] 结果:', result);
763
+ res.json(result);
764
+ }
765
+ catch (error) {
766
+ console.error('[删除服务] 错误:', error);
767
+ // 显式设置 Content-Type 并返回 JSON 错误
768
+ res.setHeader('Content-Type', 'application/json');
769
+ res.status(500).json({ error: error instanceof Error ? error.message : '删除失败' });
770
+ }
743
771
  }));
744
- app.put('/api/services/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateAPIService(req.params.id, req.body)); }));
745
- app.delete('/api/services/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteAPIService(req.params.id)); }));
746
772
  app.get('/api/routes', (_req, res) => res.json(dbManager.getRoutes()));
747
- app.post('/api/routes', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createRoute(req.body)); }));
748
- app.put('/api/routes/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateRoute(req.params.id, req.body)); }));
749
- app.delete('/api/routes/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteRoute(req.params.id)); }));
773
+ app.post('/api/routes', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createRoute(req.body)); })));
774
+ app.put('/api/routes/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateRoute(req.params.id, req.body)); })));
775
+ app.delete('/api/routes/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteRoute(req.params.id)); })));
750
776
  app.post('/api/routes/:id/activate', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () {
751
777
  const result = yield dbManager.activateRoute(req.params.id);
752
778
  if (result) {
@@ -803,12 +829,12 @@ const registerRoutes = (dbManager, proxyServer) => {
803
829
  const routeId = typeof req.query.routeId === 'string' ? req.query.routeId : undefined;
804
830
  res.json(dbManager.getRules(routeId));
805
831
  });
806
- app.post('/api/rules', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createRule(req.body)); }));
807
- app.put('/api/rules/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateRule(req.params.id, req.body)); }));
808
- app.delete('/api/rules/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteRule(req.params.id)); }));
809
- app.put('/api/rules/:id/reset-tokens', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.resetRuleTokenUsage(req.params.id)); }));
810
- app.put('/api/rules/:id/reset-requests', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.resetRuleRequestCount(req.params.id)); }));
811
- app.put('/api/rules/:id/toggle-disable', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.toggleRuleDisabled(req.params.id)); }));
832
+ app.post('/api/rules', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.createRule(req.body)); })));
833
+ app.put('/api/rules/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.updateRule(req.params.id, req.body)); })));
834
+ app.delete('/api/rules/:id', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.deleteRule(req.params.id)); })));
835
+ app.put('/api/rules/:id/reset-tokens', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.resetRuleTokenUsage(req.params.id)); })));
836
+ app.put('/api/rules/:id/reset-requests', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.resetRuleRequestCount(req.params.id)); })));
837
+ app.put('/api/rules/:id/toggle-disable', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () { return res.json(yield dbManager.toggleRuleDisabled(req.params.id)); })));
812
838
  // 解除规则的黑名单状态
813
839
  app.put('/api/rules/:id/clear-blacklist', asyncHandler((req, res) => __awaiter(void 0, void 0, void 0, function* () {
814
840
  const { id } = req.params;
@@ -1434,6 +1460,17 @@ const start = () => __awaiter(void 0, void 0, void 0, function* () {
1434
1460
  registerRoutes(dbManager, proxyServer);
1435
1461
  yield proxyServer.registerProxyRoutes();
1436
1462
  app.use(express_1.default.static(path_1.default.resolve(__dirname, '../ui')));
1463
+ // 404 处理程序 - 确保返回 JSON 而不是 HTML(放在所有路由和静态文件之后)
1464
+ app.use((_req, res) => {
1465
+ res.status(404).json({ error: 'Not found' });
1466
+ });
1467
+ // Error handling middleware - must be the last middleware
1468
+ app.use((err, _req, res, _next) => {
1469
+ console.error('[Error Handler]', err);
1470
+ // Ensure JSON response
1471
+ res.setHeader('Content-Type', 'application/json');
1472
+ res.status(500).json({ error: err.message || 'Internal server error' });
1473
+ });
1437
1474
  const isPortUsable = yield (0, utils_1.checkPortUsable)(port);
1438
1475
  if (!isPortUsable) {
1439
1476
  console.error(`端口 ${port} 已被占用,无法启动服务。请执行 aicos stop 后重启。`);
@@ -1475,10 +1512,6 @@ const start = () => __awaiter(void 0, void 0, void 0, function* () {
1475
1512
  process.on('SIGINT', shutdown);
1476
1513
  process.on('SIGTERM', shutdown);
1477
1514
  });
1478
- app.use((err, _req, res, _next) => {
1479
- console.error(err);
1480
- res.status(500).json({ error: err.message || 'Internal server error' });
1481
- });
1482
1515
  // 全局未捕获异常处理 - 防止服务崩溃
1483
1516
  process.on('uncaughtException', (error) => {
1484
1517
  console.error('[Uncaught Exception] 服务遇到未捕获的异常:', error);
@@ -77,14 +77,14 @@ Error generating stack: `+a.message+`
77
77
  `});++r<e.length;)r&&n.push({type:"text",value:`
78
78
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
79
79
  `}),n}function D1(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function L1(e,t){const n=$4(e,t),r=n.one(e,void 0),i=E4(n),a=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&a.children.push({type:"text",value:`
80
- `},i),a}function H4(e,t){return e&&"run"in e?async function(n,r){const i=L1(n,{file:r,...t});await e.run(i,r)}:function(n,r){return L1(n,{file:r,...e||t})}}function R1(e){if(e)throw e}var Oc=Object.prototype.hasOwnProperty,tE=Object.prototype.toString,z1=Object.defineProperty,$1=Object.getOwnPropertyDescriptor,B1=function(t){return typeof Array.isArray=="function"?Array.isArray(t):tE.call(t)==="[object Array]"},F1=function(t){if(!t||tE.call(t)!=="[object Object]")return!1;var n=Oc.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&Oc.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!n&&!r)return!1;var i;for(i in t);return typeof i>"u"||Oc.call(t,i)},U1=function(t,n){z1&&n.name==="__proto__"?z1(t,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):t[n.name]=n.newValue},W1=function(t,n){if(n==="__proto__")if(Oc.call(t,n)){if($1)return $1(t,n).value}else return;return t[n]},K4=function e(){var t,n,r,i,a,o,l=arguments[0],s=1,u=arguments.length,d=!1;for(typeof l=="boolean"&&(d=l,l=arguments[1]||{},s=2),(l==null||typeof l!="object"&&typeof l!="function")&&(l={});s<u;++s)if(t=arguments[s],t!=null)for(n in t)r=W1(l,n),i=W1(t,n),l!==i&&(d&&i&&(F1(i)||(a=B1(i)))?(a?(a=!1,o=r&&B1(r)?r:[]):o=r&&F1(r)?r:{},U1(l,{name:n,newValue:e(d,o,i)})):typeof i<"u"&&U1(l,{name:n,newValue:i}));return l};const Ph=Un(K4);function fg(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function V4(){const e=[],t={run:n,use:r};return t;function n(...i){let a=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(s,...u){const d=e[++a];let f=-1;if(s){o(s);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,d?q4(d,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function q4(e,t){let n;return r;function r(...o){const l=e.length>o.length;let s;l&&o.push(i);try{s=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return i(d)}l||(s&&s.then&&typeof s.then=="function"?s.then(a,i):s instanceof Error?i(s):a(s))}function i(o,...l){n||(n=!0,t(o,...l))}function a(o){i(null,o)}}const Nr={basename:Y4,dirname:G4,extname:X4,join:Q4,sep:"/"};function Y4(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');nu(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function G4(e){if(nu(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function X4(e){nu(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function Q4(...e){let t=-1,n;for(;++t<e.length;)nu(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Z4(n)}function Z4(e){nu(e);const t=e.codePointAt(0)===47;let n=J4(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function J4(e,t){let n="",r=0,i=-1,a=0,o=-1,l,s;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(s=n.lastIndexOf("/"),s!==n.length-1){s<0?(n="",r=0):(n=n.slice(0,s),r=n.length-1-n.lastIndexOf("/")),i=o,a=0;continue}}else if(n.length>0){n="",r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function nu(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const e3={cwd:t3};function t3(){return"/"}function pg(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function n3(e){if(typeof e=="string")e=new URL(e);else if(!pg(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return r3(e)}function r3(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const Ch=["history","path","basename","stem","extname","dirname"];class nE{constructor(t){let n;t?pg(t)?n={path:t}:typeof t=="string"||i3(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":e3.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Ch.length;){const a=Ch[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let i;for(i in n)Ch.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Nr.basename(this.path):void 0}set basename(t){Eh(t,"basename"),Oh(t,"basename"),this.path=Nr.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Nr.dirname(this.path):void 0}set dirname(t){H1(this.basename,"dirname"),this.path=Nr.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Nr.extname(this.path):void 0}set extname(t){if(Oh(t,"extname"),H1(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Nr.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){pg(t)&&(t=n3(t)),Eh(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Nr.basename(this.path,this.extname):void 0}set stem(t){Eh(t,"stem"),Oh(t,"stem"),this.path=Nr.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new sn(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Oh(e,t){if(e&&e.includes(Nr.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Nr.sep+"`")}function Eh(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function H1(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function i3(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const a3=function(e){const r=this.constructor.prototype,i=r[e],a=function(){return i.apply(a,arguments)};return Object.setPrototypeOf(a,r),a},o3={}.hasOwnProperty;class Cy extends a3{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=V4()}copy(){const t=new Cy;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Ph(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Ih("data",this.frozen),this.namespace[t]=n,this):o3.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Ih("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=qu(t),r=this.parser||this.Parser;return Ah("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Ah("process",this.parser||this.Parser),Th("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(a,o){const l=qu(t),s=r.parse(l);r.run(s,l,function(d,f,p){if(d||!f||!p)return u(d);const h=f,g=r.stringify(h,p);u3(g)?p.value=g:p.result=g,u(d,p)});function u(d,f){d||!f?o(d):a?a(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),Ah("processSync",this.parser||this.Parser),Th("processSync",this.compiler||this.Compiler),this.process(t,i),V1("processSync","process",n),r;function i(a,o){n=!0,R1(a),r=o}}run(t,n,r){K1(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const s=qu(n);i.run(t,s,u);function u(d,f,p){const h=f||t;d?l(d):o?o(h):r(void 0,h,p)}}}runSync(t,n){let r=!1,i;return this.run(t,n,a),V1("runSync","run",r),i;function a(o,l){R1(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=qu(n),i=this.compiler||this.Compiler;return Th("stringify",i),K1(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Ih("use",this.frozen),t!=null)if(typeof t=="function")s(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")s(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...f]=u;s(d,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=Ph(!0,i.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const f=u[d];a(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function s(u,d){let f=-1,p=-1;for(;++f<r.length;)if(r[f][0]===u){p=f;break}if(p===-1)r.push([u,...d]);else if(d.length>0){let[h,...g]=d;const y=r[p][1];fg(y)&&fg(h)&&(h=Ph(!0,y,h)),r[p]=[u,h,...g]}}}}const l3=new Cy().freeze();function Ah(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Th(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Ih(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function K1(e){if(!fg(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function V1(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function qu(e){return s3(e)?e:new nE(e)}function s3(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function u3(e){return typeof e=="string"||c3(e)}function c3(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const d3="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",q1=[],Y1={allowDangerousHtml:!0},f3=/^(https?|ircs?|mailto|xmpp)$/i,p3=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function cs(e){const t=h3(e),n=m3(e);return g3(t.runSync(t.parse(n),n),e)}function h3(e){const t=e.rehypePlugins||q1,n=e.remarkPlugins||q1,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Y1}:Y1;return l3().use(G$).use(n).use(H4,r).use(t)}function m3(e){const t=e.children||"",n=new nE;return typeof t=="string"&&(n.value=t),n}function g3(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,s=t.urlTransform||v3;for(const d of p3)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+d3+d.id,void 0);return eE(e,u),ER(e,{Fragment:c.Fragment,components:i,ignoreInvalidStyle:!0,jsx:c.jsx,jsxs:c.jsxs,passKeys:!0,passNode:!0});function u(d,f,p){if(d.type==="raw"&&p&&typeof f=="number")return o?p.children.splice(f,1):p.children[f]={type:"text",value:d.value},f;if(d.type==="element"){let h;for(h in Sh)if(Object.hasOwn(Sh,h)&&Object.hasOwn(d.properties,h)){const g=d.properties[h],y=Sh[h];(y===null||y.includes(d.tagName))&&(d.properties[h]=s(String(g||""),h,d))}}if(d.type==="element"){let h=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!h&&r&&typeof f=="number"&&(h=!r(d,f,p)),h&&p&&typeof f=="number")return l&&d.children?p.children.splice(f,1,...d.children):p.children.splice(f,1),f}}}function v3(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||f3.test(e.slice(0,t))?e:""}const ue=(e,t)=>{if(!t)return e;const n=new URLSearchParams;Object.entries(t).forEach(([i,a])=>{a!=null&&a!==""&&n.set(i,String(a))});const r=n.toString();return r?`${e}?${r}`:e},ce=async(e,t={})=>{const n=localStorage.getItem("auth_token"),r=await fetch(e,{...t,headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},...t.headers||{}}});if(!r.ok){if(r.status===401){localStorage.removeItem("auth_token");const o=await r.text(),l=new Error(o||r.statusText);throw l.status=401,l}const a=await r.text();throw new Error(a||r.statusText)}return r.status===204?void 0:(r.headers.get("content-type")||"").includes("application/json")?r.json():r.text()},ne={getAuthStatus:()=>ce(ue("/api/auth/status")),login:e=>ce(ue("/api/auth/login"),{method:"POST",body:JSON.stringify({authCode:e})}),checkVersion:()=>ce(ue("/api/version/check")),getVendors:()=>ce(ue("/api/vendors")),createVendor:e=>ce(ue("/api/vendors"),{method:"POST",body:JSON.stringify(e)}),updateVendor:(e,t)=>ce(ue(`/api/vendors/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteVendor:e=>ce(ue(`/api/vendors/${e}`),{method:"DELETE"}),getAPIServices:e=>ce(ue("/api/services",e?{vendorId:e}:void 0)),createAPIService:e=>ce(ue("/api/services"),{method:"POST",body:JSON.stringify(e)}),updateAPIService:(e,t)=>ce(ue(`/api/services/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteAPIService:e=>ce(ue(`/api/services/${e}`),{method:"DELETE"}),getRoutes:()=>ce(ue("/api/routes")),createRoute:e=>ce(ue("/api/routes"),{method:"POST",body:JSON.stringify(e)}),updateRoute:(e,t)=>ce(ue(`/api/routes/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteRoute:e=>ce(ue(`/api/routes/${e}`),{method:"DELETE"}),activateRoute:e=>ce(ue(`/api/routes/${e}/activate`),{method:"POST"}),deactivateRoute:e=>ce(ue(`/api/routes/${e}/deactivate`),{method:"POST"}),getRules:e=>ce(ue("/api/rules",e?{routeId:e}:void 0)),createRule:e=>ce(ue("/api/rules"),{method:"POST",body:JSON.stringify(e)}),updateRule:(e,t)=>ce(ue(`/api/rules/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteRule:e=>ce(ue(`/api/rules/${e}`),{method:"DELETE"}),resetRuleTokens:e=>ce(ue(`/api/rules/${e}/reset-tokens`),{method:"PUT"}),resetRuleRequests:e=>ce(ue(`/api/rules/${e}/reset-requests`),{method:"PUT"}),clearRuleBlacklist:e=>ce(ue(`/api/rules/${e}/clear-blacklist`),{method:"PUT"}),toggleRuleDisable:e=>ce(ue(`/api/rules/${e}/toggle-disable`),{method:"PUT"}),getRulesBlacklistStatus:e=>ce(ue(`/api/rules/${e}/blacklist-status`)),getLogs:(e,t)=>ce(ue("/api/logs",{limit:e,offset:t})),clearLogs:()=>ce(ue("/api/logs"),{method:"DELETE"}),getErrorLogs:(e,t)=>ce(ue("/api/error-logs",{limit:e,offset:t})),clearErrorLogs:()=>ce(ue("/api/error-logs"),{method:"DELETE"}),getLogsCount:()=>ce(ue("/api/logs/count")),getErrorLogsCount:()=>ce(ue("/api/error-logs/count")),getStatistics:(e=30)=>ce(ue("/api/statistics",{days:e})),resetStatistics:()=>ce(ue("/api/statistics"),{method:"DELETE"}),getConfig:()=>ce(ue("/api/config")),updateConfig:e=>ce(ue("/api/config"),{method:"PUT",body:JSON.stringify(e)}),exportData:async e=>(await ce(ue("/api/export"),{method:"POST",body:JSON.stringify({password:e})})).data,previewImportData:(e,t)=>ce(ue("/api/import/preview"),{method:"POST",body:JSON.stringify({encryptedData:e,password:t})}),importData:(e,t)=>ce(ue("/api/import"),{method:"POST",body:JSON.stringify({encryptedData:e,password:t})}),writeClaudeConfig:()=>ce(ue("/api/write-config/claude"),{method:"POST"}),writeCodexConfig:()=>ce(ue("/api/write-config/codex"),{method:"POST"}),restoreClaudeConfig:()=>ce(ue("/api/restore-config/claude"),{method:"POST"}),restoreCodexConfig:()=>ce(ue("/api/restore-config/codex"),{method:"POST"}),checkClaudeBackup:()=>ce(ue("/api/check-backup/claude")),checkCodexBackup:()=>ce(ue("/api/check-backup/codex")),getClaudeConfigStatus:()=>ce(ue("/api/config-status/claude")),getCodexConfigStatus:()=>ce(ue("/api/config-status/codex")),getSessions:(e,t)=>ce(ue("/api/sessions",{limit:e,offset:t})),getSessionsCount:()=>ce(ue("/api/sessions/count")),getSession:e=>ce(ue(`/api/sessions/${e}`)),getSessionLogs:(e,t)=>ce(ue(`/api/sessions/${e}/logs`,{limit:t})),deleteSession:e=>ce(ue(`/api/sessions/${e}`),{method:"DELETE"}),clearSessions:()=>ce(ue("/api/sessions"),{method:"DELETE"}),getRecommendVendorsMarkdown:()=>ce(ue("/api/docs/recommend-vendors")),getReadmeMarkdown:()=>ce(ue("/api/docs/readme")),getInstalledSkills:()=>ce(ue("/api/skills/installed")),searchSkills:e=>ce(ue("/api/skills/search"),{method:"POST",body:JSON.stringify({query:e})}),getSkillDetails:e=>ce(ue(`/api/skills/${e}/details`)),installSkill:(e,t)=>ce(ue("/api/skills/install"),{method:"POST",body:JSON.stringify({skillId:e.id,name:e.name,description:e.description,tags:e.tags,...t?{targetType:t}:{},githubUrl:e.url})}),enableSkill:(e,t)=>ce(ue(`/api/skills/${e}/enable`),{method:"POST",body:JSON.stringify({targetType:t})}),disableSkill:(e,t)=>ce(ue(`/api/skills/${e}/disable`),{method:"POST",body:JSON.stringify({targetType:t})}),deleteSkill:e=>ce(ue(`/api/skills/${e}`),{method:"DELETE"}),createLocalSkill:e=>ce(ue("/api/skills/create-local"),{method:"POST",body:JSON.stringify(e)}),getUpgradeMarkdown:()=>ce(ue("/api/docs/upgrade")),getUpgrade:()=>ce(ue("/api/upgrade")),acknowledgeUpgrade:()=>ce(ue("/api/upgrade/ack"),{method:"POST"}),getToolsStatus:()=>ce(ue("/api/tools/status")),installTool:(e,t)=>{var u;console.log("[API Client] 开始安装工具:",e);const n=window.location.protocol==="https:"?"wss:":"ws:",r=window.location.host,i=`${n}//${r}/api/tools/install`;console.log("[API Client] 连接 WebSocket:",i);let a=null;try{a=new WebSocket(i)}catch(d){return console.error("[API Client] 创建 WebSocket 失败:",d),(u=t.onError)==null||u.call(t,"创建 WebSocket 连接失败"),()=>{}}a.onopen=()=>{console.log("[API Client] WebSocket 连接已建立"),a==null||a.send(JSON.stringify({type:"install",tool:e}))},a.onmessage=d=>{var f,p,h,g,y,x,v,b,w;try{const S=JSON.parse(d.data);switch(console.log("[API Client] 收到消息:",S.type),S.type){case"start":console.log("[API Client] 安装开始:",S.data),(f=t.onStdout)==null||f.call(t,`
80
+ `},i),a}function H4(e,t){return e&&"run"in e?async function(n,r){const i=L1(n,{file:r,...t});await e.run(i,r)}:function(n,r){return L1(n,{file:r,...e||t})}}function R1(e){if(e)throw e}var Oc=Object.prototype.hasOwnProperty,tE=Object.prototype.toString,z1=Object.defineProperty,$1=Object.getOwnPropertyDescriptor,B1=function(t){return typeof Array.isArray=="function"?Array.isArray(t):tE.call(t)==="[object Array]"},F1=function(t){if(!t||tE.call(t)!=="[object Object]")return!1;var n=Oc.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&Oc.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!n&&!r)return!1;var i;for(i in t);return typeof i>"u"||Oc.call(t,i)},U1=function(t,n){z1&&n.name==="__proto__"?z1(t,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):t[n.name]=n.newValue},W1=function(t,n){if(n==="__proto__")if(Oc.call(t,n)){if($1)return $1(t,n).value}else return;return t[n]},K4=function e(){var t,n,r,i,a,o,l=arguments[0],s=1,u=arguments.length,d=!1;for(typeof l=="boolean"&&(d=l,l=arguments[1]||{},s=2),(l==null||typeof l!="object"&&typeof l!="function")&&(l={});s<u;++s)if(t=arguments[s],t!=null)for(n in t)r=W1(l,n),i=W1(t,n),l!==i&&(d&&i&&(F1(i)||(a=B1(i)))?(a?(a=!1,o=r&&B1(r)?r:[]):o=r&&F1(r)?r:{},U1(l,{name:n,newValue:e(d,o,i)})):typeof i<"u"&&U1(l,{name:n,newValue:i}));return l};const Ph=Un(K4);function fg(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function V4(){const e=[],t={run:n,use:r};return t;function n(...i){let a=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(s,...u){const d=e[++a];let f=-1;if(s){o(s);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,d?q4(d,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function q4(e,t){let n;return r;function r(...o){const l=e.length>o.length;let s;l&&o.push(i);try{s=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return i(d)}l||(s&&s.then&&typeof s.then=="function"?s.then(a,i):s instanceof Error?i(s):a(s))}function i(o,...l){n||(n=!0,t(o,...l))}function a(o){i(null,o)}}const Nr={basename:Y4,dirname:G4,extname:X4,join:Q4,sep:"/"};function Y4(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');nu(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function G4(e){if(nu(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function X4(e){nu(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function Q4(...e){let t=-1,n;for(;++t<e.length;)nu(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Z4(n)}function Z4(e){nu(e);const t=e.codePointAt(0)===47;let n=J4(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function J4(e,t){let n="",r=0,i=-1,a=0,o=-1,l,s;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(s=n.lastIndexOf("/"),s!==n.length-1){s<0?(n="",r=0):(n=n.slice(0,s),r=n.length-1-n.lastIndexOf("/")),i=o,a=0;continue}}else if(n.length>0){n="",r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function nu(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const e3={cwd:t3};function t3(){return"/"}function pg(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function n3(e){if(typeof e=="string")e=new URL(e);else if(!pg(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return r3(e)}function r3(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const Ch=["history","path","basename","stem","extname","dirname"];class nE{constructor(t){let n;t?pg(t)?n={path:t}:typeof t=="string"||i3(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":e3.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Ch.length;){const a=Ch[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let i;for(i in n)Ch.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Nr.basename(this.path):void 0}set basename(t){Eh(t,"basename"),Oh(t,"basename"),this.path=Nr.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Nr.dirname(this.path):void 0}set dirname(t){H1(this.basename,"dirname"),this.path=Nr.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Nr.extname(this.path):void 0}set extname(t){if(Oh(t,"extname"),H1(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Nr.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){pg(t)&&(t=n3(t)),Eh(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Nr.basename(this.path,this.extname):void 0}set stem(t){Eh(t,"stem"),Oh(t,"stem"),this.path=Nr.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new sn(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Oh(e,t){if(e&&e.includes(Nr.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Nr.sep+"`")}function Eh(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function H1(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function i3(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const a3=function(e){const r=this.constructor.prototype,i=r[e],a=function(){return i.apply(a,arguments)};return Object.setPrototypeOf(a,r),a},o3={}.hasOwnProperty;class Cy extends a3{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=V4()}copy(){const t=new Cy;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Ph(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Ih("data",this.frozen),this.namespace[t]=n,this):o3.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Ih("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=qu(t),r=this.parser||this.Parser;return Ah("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Ah("process",this.parser||this.Parser),Th("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(a,o){const l=qu(t),s=r.parse(l);r.run(s,l,function(d,f,p){if(d||!f||!p)return u(d);const h=f,g=r.stringify(h,p);u3(g)?p.value=g:p.result=g,u(d,p)});function u(d,f){d||!f?o(d):a?a(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),Ah("processSync",this.parser||this.Parser),Th("processSync",this.compiler||this.Compiler),this.process(t,i),V1("processSync","process",n),r;function i(a,o){n=!0,R1(a),r=o}}run(t,n,r){K1(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const s=qu(n);i.run(t,s,u);function u(d,f,p){const h=f||t;d?l(d):o?o(h):r(void 0,h,p)}}}runSync(t,n){let r=!1,i;return this.run(t,n,a),V1("runSync","run",r),i;function a(o,l){R1(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=qu(n),i=this.compiler||this.Compiler;return Th("stringify",i),K1(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Ih("use",this.frozen),t!=null)if(typeof t=="function")s(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")s(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...f]=u;s(d,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=Ph(!0,i.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const f=u[d];a(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function s(u,d){let f=-1,p=-1;for(;++f<r.length;)if(r[f][0]===u){p=f;break}if(p===-1)r.push([u,...d]);else if(d.length>0){let[h,...g]=d;const y=r[p][1];fg(y)&&fg(h)&&(h=Ph(!0,y,h)),r[p]=[u,h,...g]}}}}const l3=new Cy().freeze();function Ah(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Th(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Ih(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function K1(e){if(!fg(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function V1(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function qu(e){return s3(e)?e:new nE(e)}function s3(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function u3(e){return typeof e=="string"||c3(e)}function c3(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const d3="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",q1=[],Y1={allowDangerousHtml:!0},f3=/^(https?|ircs?|mailto|xmpp)$/i,p3=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function cs(e){const t=h3(e),n=m3(e);return g3(t.runSync(t.parse(n),n),e)}function h3(e){const t=e.rehypePlugins||q1,n=e.remarkPlugins||q1,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Y1}:Y1;return l3().use(G$).use(n).use(H4,r).use(t)}function m3(e){const t=e.children||"",n=new nE;return typeof t=="string"&&(n.value=t),n}function g3(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,s=t.urlTransform||v3;for(const d of p3)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+d3+d.id,void 0);return eE(e,u),ER(e,{Fragment:c.Fragment,components:i,ignoreInvalidStyle:!0,jsx:c.jsx,jsxs:c.jsxs,passKeys:!0,passNode:!0});function u(d,f,p){if(d.type==="raw"&&p&&typeof f=="number")return o?p.children.splice(f,1):p.children[f]={type:"text",value:d.value},f;if(d.type==="element"){let h;for(h in Sh)if(Object.hasOwn(Sh,h)&&Object.hasOwn(d.properties,h)){const g=d.properties[h],y=Sh[h];(y===null||y.includes(d.tagName))&&(d.properties[h]=s(String(g||""),h,d))}}if(d.type==="element"){let h=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!h&&r&&typeof f=="number"&&(h=!r(d,f,p)),h&&p&&typeof f=="number")return l&&d.children?p.children.splice(f,1,...d.children):p.children.splice(f,1),f}}}function v3(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||f3.test(e.slice(0,t))?e:""}const ue=(e,t)=>{if(!t)return e;const n=new URLSearchParams;Object.entries(t).forEach(([i,a])=>{a!=null&&a!==""&&n.set(i,String(a))});const r=n.toString();return r?`${e}?${r}`:e},ce=async(e,t={})=>{const n=localStorage.getItem("auth_token"),r=await fetch(e,{...t,headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},...t.headers||{}}});if(!r.ok){if(r.status===401){localStorage.removeItem("auth_token");const l=await r.text(),s=new Error(l||r.statusText);throw s.status=401,s}const a=await r.text();let o=null;try{const l=JSON.parse(a);l.error&&(o=l.error)}catch{}throw new Error(o||a||r.statusText)}return r.status===204?void 0:(r.headers.get("content-type")||"").includes("application/json")?r.json():r.text()},ne={getAuthStatus:()=>ce(ue("/api/auth/status")),login:e=>ce(ue("/api/auth/login"),{method:"POST",body:JSON.stringify({authCode:e})}),checkVersion:()=>ce(ue("/api/version/check")),getVendors:()=>ce(ue("/api/vendors")),createVendor:e=>ce(ue("/api/vendors"),{method:"POST",body:JSON.stringify(e)}),updateVendor:(e,t)=>ce(ue(`/api/vendors/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteVendor:e=>ce(ue(`/api/vendors/${e}`),{method:"DELETE"}),getAPIServices:e=>ce(ue("/api/services",e?{vendorId:e}:void 0)),createAPIService:e=>ce(ue("/api/services"),{method:"POST",body:JSON.stringify(e)}),updateAPIService:(e,t)=>ce(ue(`/api/services/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteAPIService:e=>ce(ue(`/api/services/${e}`),{method:"DELETE"}),getRoutes:()=>ce(ue("/api/routes")),createRoute:e=>ce(ue("/api/routes"),{method:"POST",body:JSON.stringify(e)}),updateRoute:(e,t)=>ce(ue(`/api/routes/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteRoute:e=>ce(ue(`/api/routes/${e}`),{method:"DELETE"}),activateRoute:e=>ce(ue(`/api/routes/${e}/activate`),{method:"POST"}),deactivateRoute:e=>ce(ue(`/api/routes/${e}/deactivate`),{method:"POST"}),getRules:e=>ce(ue("/api/rules",e?{routeId:e}:void 0)),createRule:e=>ce(ue("/api/rules"),{method:"POST",body:JSON.stringify(e)}),updateRule:(e,t)=>ce(ue(`/api/rules/${e}`),{method:"PUT",body:JSON.stringify(t)}),deleteRule:e=>ce(ue(`/api/rules/${e}`),{method:"DELETE"}),resetRuleTokens:e=>ce(ue(`/api/rules/${e}/reset-tokens`),{method:"PUT"}),resetRuleRequests:e=>ce(ue(`/api/rules/${e}/reset-requests`),{method:"PUT"}),clearRuleBlacklist:e=>ce(ue(`/api/rules/${e}/clear-blacklist`),{method:"PUT"}),toggleRuleDisable:e=>ce(ue(`/api/rules/${e}/toggle-disable`),{method:"PUT"}),getRulesBlacklistStatus:e=>ce(ue(`/api/rules/${e}/blacklist-status`)),getLogs:(e,t)=>ce(ue("/api/logs",{limit:e,offset:t})),clearLogs:()=>ce(ue("/api/logs"),{method:"DELETE"}),getErrorLogs:(e,t)=>ce(ue("/api/error-logs",{limit:e,offset:t})),clearErrorLogs:()=>ce(ue("/api/error-logs"),{method:"DELETE"}),getLogsCount:()=>ce(ue("/api/logs/count")),getErrorLogsCount:()=>ce(ue("/api/error-logs/count")),getStatistics:(e=30)=>ce(ue("/api/statistics",{days:e})),resetStatistics:()=>ce(ue("/api/statistics"),{method:"DELETE"}),getConfig:()=>ce(ue("/api/config")),updateConfig:e=>ce(ue("/api/config"),{method:"PUT",body:JSON.stringify(e)}),exportData:async e=>(await ce(ue("/api/export"),{method:"POST",body:JSON.stringify({password:e})})).data,previewImportData:(e,t)=>ce(ue("/api/import/preview"),{method:"POST",body:JSON.stringify({encryptedData:e,password:t})}),importData:(e,t)=>ce(ue("/api/import"),{method:"POST",body:JSON.stringify({encryptedData:e,password:t})}),writeClaudeConfig:()=>ce(ue("/api/write-config/claude"),{method:"POST"}),writeCodexConfig:()=>ce(ue("/api/write-config/codex"),{method:"POST"}),restoreClaudeConfig:()=>ce(ue("/api/restore-config/claude"),{method:"POST"}),restoreCodexConfig:()=>ce(ue("/api/restore-config/codex"),{method:"POST"}),checkClaudeBackup:()=>ce(ue("/api/check-backup/claude")),checkCodexBackup:()=>ce(ue("/api/check-backup/codex")),getClaudeConfigStatus:()=>ce(ue("/api/config-status/claude")),getCodexConfigStatus:()=>ce(ue("/api/config-status/codex")),getSessions:(e,t)=>ce(ue("/api/sessions",{limit:e,offset:t})),getSessionsCount:()=>ce(ue("/api/sessions/count")),getSession:e=>ce(ue(`/api/sessions/${e}`)),getSessionLogs:(e,t)=>ce(ue(`/api/sessions/${e}/logs`,{limit:t})),deleteSession:e=>ce(ue(`/api/sessions/${e}`),{method:"DELETE"}),clearSessions:()=>ce(ue("/api/sessions"),{method:"DELETE"}),getRecommendVendorsMarkdown:()=>ce(ue("/api/docs/recommend-vendors")),getReadmeMarkdown:()=>ce(ue("/api/docs/readme")),getInstalledSkills:()=>ce(ue("/api/skills/installed")),searchSkills:e=>ce(ue("/api/skills/search"),{method:"POST",body:JSON.stringify({query:e})}),getSkillDetails:e=>ce(ue(`/api/skills/${e}/details`)),installSkill:(e,t)=>ce(ue("/api/skills/install"),{method:"POST",body:JSON.stringify({skillId:e.id,name:e.name,description:e.description,tags:e.tags,...t?{targetType:t}:{},githubUrl:e.url})}),enableSkill:(e,t)=>ce(ue(`/api/skills/${e}/enable`),{method:"POST",body:JSON.stringify({targetType:t})}),disableSkill:(e,t)=>ce(ue(`/api/skills/${e}/disable`),{method:"POST",body:JSON.stringify({targetType:t})}),deleteSkill:e=>ce(ue(`/api/skills/${e}`),{method:"DELETE"}),createLocalSkill:e=>ce(ue("/api/skills/create-local"),{method:"POST",body:JSON.stringify(e)}),getUpgradeMarkdown:()=>ce(ue("/api/docs/upgrade")),getUpgrade:()=>ce(ue("/api/upgrade")),acknowledgeUpgrade:()=>ce(ue("/api/upgrade/ack"),{method:"POST"}),getToolsStatus:()=>ce(ue("/api/tools/status")),installTool:(e,t)=>{var u;console.log("[API Client] 开始安装工具:",e);const n=window.location.protocol==="https:"?"wss:":"ws:",r=window.location.host,i=`${n}//${r}/api/tools/install`;console.log("[API Client] 连接 WebSocket:",i);let a=null;try{a=new WebSocket(i)}catch(d){return console.error("[API Client] 创建 WebSocket 失败:",d),(u=t.onError)==null||u.call(t,"创建 WebSocket 连接失败"),()=>{}}a.onopen=()=>{console.log("[API Client] WebSocket 连接已建立"),a==null||a.send(JSON.stringify({type:"install",tool:e}))},a.onmessage=d=>{var f,p,h,g,y,x,v,b,w;try{const S=JSON.parse(d.data);switch(console.log("[API Client] 收到消息:",S.type),S.type){case"start":console.log("[API Client] 安装开始:",S.data),(f=t.onStdout)==null||f.call(t,`
81
81
  ========== 开始安装 ${S.data.tool} ==========
82
82
  `),(p=t.onStdout)==null||p.call(t,`操作系统: ${S.data.os}
83
83
  `),(h=t.onStdout)==null||h.call(t,`执行命令: ${S.data.command}
84
84
  `),(g=t.onStdout)==null||g.call(t,`子进程已创建 (PID: ${S.data.pid})
85
85
  `),(y=t.onStdout)==null||y.call(t,`等待 npm 输出...
86
86
 
87
- `);break;case"stdout":(x=t.onStdout)==null||x.call(t,S.data);break;case"stderr":(v=t.onStderr)==null||v.call(t,S.data);break;case"close":console.log("[API Client] 安装完成:",S.data),(b=t.onClose)==null||b.call(t,S.data.code,S.data.success),setTimeout(()=>{a==null||a.close()},1e3);break;case"error":console.error("[API Client] 安装错误:",S.data),(w=t.onError)==null||w.call(t,S.data);break}}catch(S){console.error("[API Client] 解析消息失败:",S,d.data)}},a.onclose=d=>{var f;console.log("[API Client] WebSocket 连接关闭:",d.code,d.reason),d.wasClean||(f=t.onError)==null||f.call(t,"连接意外关闭")},a.onerror=d=>{var f;console.error("[API Client] WebSocket 错误:",d),(f=t.onError)==null||f.call(t,"WebSocket 连接错误")};const o=()=>{console.log("[API Client] 清理 WebSocket 连接"),a&&(a.close(),a=null)},l=d=>{a&&a.readyState===WebSocket.OPEN?(a.send(JSON.stringify({type:"input",data:d})),console.log("[API Client] 发送输入:",d.slice(0,10))):console.warn("[API Client] WebSocket 未连接,无法发送输入")},s=o;return s.sendInput=l,s}};var Sn=(e=>(e.AUTH_TOKEN="authorization",e.API_KEY="x-api-key",e.G_API_KEY="x-goog-api-key",e.AUTO="auto",e))(Sn||{});const In={minimax:{name:"Minimax",description:"国内优秀的大模型 https://platform.minimaxi.com/subscribe/coding-plan?code=G6xKj7L4YN&source=link",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://api.minimaxi.com/anthropic",models:"MiniMax-M2.1"},{name:"Coding Plan Codex",sourceType:"openai-chat",apiUrl:"https://api.minimaxi.com/v1",models:"codex-MiniMax-M2.1"}]},glm:{name:"GLM",description:"国内优秀的大模型 https://www.bigmodel.cn/glm-coding?ic=5AH7ATEZSC",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://open.bigmodel.cn/api/anthropic",models:"glm-4.7, glm-4.5-air",modelLimits:{"glm-4.7":131072,"glm-4.5-air":98304}}]},kimi:{name:"Kimi",description:"国内优秀大模型 https://www.kimi.ai/",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://api.kimi.com/coding"}]},doubao:{name:"火山方舟(豆包)",description:"字节旗下大模型平台。Coding Plan一次性支持GLM、Kimi-K2、Deepseek多个国产模型 https://volcengine.com/L/RcHlm6yxj0w/ 邀请码:Y58X463P",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://ark.cn-beijing.volces.com/api/coding",models:"ark-code-latest"},{name:"Coding Plan Codex",sourceType:"openai-responses",apiUrl:"https://ark.cn-beijing.volces.com/api/coding/v3",models:"ark-code-latest"},{name:"付费API兼容Claude Code",sourceType:"claude-code",apiUrl:"https://ark.cn-beijing.volces.com/api/compatible",models:"doubao-seed-code-preview-251028"},{name:"付费API兼容Codex",sourceType:"openai-responses",apiUrl:"https://ark.cn-beijing.volces.com/api/v3",models:"doubao-seed-code-preview-251028"}]},qwen:{name:"阿里云百炼(千问)",description:"国内优秀大模型 https://help.aliyun.com/zh/model-studio/coding-plan",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://coding.dashscope.aliyuncs.com/apps/anthropic",models:"qwen3-max-2026-01-23, qwen3-coder-plus"},{name:"Coding Plan Codex",sourceType:"openai-chat",apiUrl:"https://coding.dashscope.aliyuncs.com/v1",models:"qwen3-max-2026-01-23, qwen3-coder-plus"},{name:"付费API兼容Codex",sourceType:"openai-responses",apiUrl:"https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",models:"qwen3-max-2026-01-23, qwen3-coder-plus, kimi-k2.5, glm-4.7, MiniMax-M2.1"}]},aicodewith:{name:"AICodeWith",description:"稳定的第三方中转 https://aicodewith.com/login?tab=register&invitation=QCA74W",services:[{name:"claudecode",sourceType:"claude-code",apiUrl:"https://api.aicodewith.com"},{name:"codex",sourceType:"openai-responses",apiUrl:"https://api.aicodewith.com/chatgpt"}]},openai:{name:"OpenAI",description:"OpenAI 官方 API https://platform.openai.com",services:[{name:"GPT",sourceType:"openai-responses",apiUrl:"https://api.openai.com"}],is_oversea:!0},anthropic:{name:"Anthropic",description:"Anthropic 官方 API https://www.anthropic.com",services:[{name:"Claude",sourceType:"claude-code",apiUrl:"https://api.anthropic.com"}],is_oversea:!0},google:{name:"Google AI",description:"Google AI 官方 API",services:[{name:"Gemini",sourceType:"gemini",apiUrl:"https://generativelanguage.googleapis.com"}],is_oversea:!0},openrouter:{name:"OpenRouter",description:"一站式 AI 模型路由平台 https://openrouter.ai",services:[{name:"Claude Code专属接口",sourceType:"claude-code",apiUrl:"https://openrouter.ai/api",models:"anthropic/claude-opus-4.6, anthropic/claude-opus-4.5, anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5",authType:Sn.AUTH_TOKEN},{name:"通用接口",sourceType:"openai-chat",apiUrl:"https://openrouter.ai/api/v1/chat/completions",models:"anthropic/claude-opus-4.5, anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5, openai/gpt-5.2-codex, openai/gpt-5.2-chat, openai/gpt-5.2-pro, openai/gpt-5.2, openai/gpt-5.1-codex-max, google/gemini-3-flash-preview, google/gemini-3-pro-preview"}],is_oversea:!0}},Yu={"claude-code":"Claude Code",codex:"Codex"},Gu={"claude-code":"Claude Code","claude-chat":"Claude Chat","openai-responses":"OpenAI Responses","openai-chat":"OpenAI Chat","deepseek-reasoning-chat":"DeepSeek Reasoning Chat",gemini:"Gemini"},y3={"openai-chat":"填写完整的接口地址,如:https://api.openai.com/v1/chat/completions","openai-responses":"只填写 base 地址(含/v1),如:https://api.openai.com/v1","claude-chat":"填写完整的接口地址,如:https://api.anthropic.com/v1/messages","claude-code":"只填写 base 地址,如:https://api.anthropic.com","deepseek-reasoning-chat":"推理类模型,填写完整的接口地址,如:https://api.deepseek.com/v1/chat/completions",gemini:"只填写 base 地址,如:https://generativelanguage.googleapis.com"},G1={[Sn.AUTO]:"自动",[Sn.AUTH_TOKEN]:"AUTH_TOKEN",[Sn.API_KEY]:"API_KEY",[Sn.G_API_KEY]:"GOOGLE_API_KEY"},x3={[Sn.AUTO]:"根据数据源类型自动判断:Claude 相关类型使用 x-api-key header,OpenAI 相关类型使用 Authorization: Bearer header,Gemini 使用 x-goog-api-key header",[Sn.AUTH_TOKEN]:"使用 Authorization: Bearer <token> 进行认证(对应 Claude Code 的 ANTHROPIC_AUTH_TOKEN,以及OpenAI的所有请求)",[Sn.API_KEY]:"使用 x-api-key: <token> 进行认证(对应 Claude Code 的 ANTHROPIC_API_KEY)",[Sn.G_API_KEY]:"使用 x-goog-api-key: <token> 进行认证(对应 Google Gemini API)"},b3=`#### 🚀 智谱 GLM Coding Plan
87
+ `);break;case"stdout":(x=t.onStdout)==null||x.call(t,S.data);break;case"stderr":(v=t.onStderr)==null||v.call(t,S.data);break;case"close":console.log("[API Client] 安装完成:",S.data),(b=t.onClose)==null||b.call(t,S.data.code,S.data.success),setTimeout(()=>{a==null||a.close()},1e3);break;case"error":console.error("[API Client] 安装错误:",S.data),(w=t.onError)==null||w.call(t,S.data);break}}catch(S){console.error("[API Client] 解析消息失败:",S,d.data)}},a.onclose=d=>{var f;console.log("[API Client] WebSocket 连接关闭:",d.code,d.reason),d.wasClean||(f=t.onError)==null||f.call(t,"连接意外关闭")},a.onerror=d=>{var f;console.error("[API Client] WebSocket 错误:",d),(f=t.onError)==null||f.call(t,"WebSocket 连接错误")};const o=()=>{console.log("[API Client] 清理 WebSocket 连接"),a&&(a.close(),a=null)},l=d=>{a&&a.readyState===WebSocket.OPEN?(a.send(JSON.stringify({type:"input",data:d})),console.log("[API Client] 发送输入:",d.slice(0,10))):console.warn("[API Client] WebSocket 未连接,无法发送输入")},s=o;return s.sendInput=l,s}};var Sn=(e=>(e.AUTH_TOKEN="authorization",e.API_KEY="x-api-key",e.G_API_KEY="x-goog-api-key",e.AUTO="auto",e))(Sn||{});const In={minimax:{name:"Minimax",description:"国内优秀的大模型 https://platform.minimaxi.com/subscribe/coding-plan?code=G6xKj7L4YN&source=link",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://api.minimaxi.com/anthropic",models:"MiniMax-M2.5"},{name:"Coding Plan Codex",sourceType:"openai-chat",apiUrl:"https://api.minimaxi.com/v1",models:"codex-MiniMax-M2.1, codex-MiniMax-M2.5"}]},glm:{name:"GLM",description:"国内优秀的大模型 https://www.bigmodel.cn/glm-coding?ic=5AH7ATEZSC",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://open.bigmodel.cn/api/anthropic",models:"glm-4.7, glm-4.5-air",modelLimits:{"glm-4.7":131072,"glm-4.5-air":98304}}]},kimi:{name:"Kimi",description:"国内优秀大模型 https://www.kimi.ai/",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://api.kimi.com/coding"}]},doubao:{name:"火山方舟(豆包)",description:"字节旗下大模型平台。Coding Plan一次性支持GLM、Kimi-K2、Deepseek多个国产模型 https://volcengine.com/L/RcHlm6yxj0w/ 邀请码:Y58X463P",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://ark.cn-beijing.volces.com/api/coding",models:"ark-code-latest"},{name:"Coding Plan Codex",sourceType:"openai-responses",apiUrl:"https://ark.cn-beijing.volces.com/api/coding/v3",models:"ark-code-latest"},{name:"付费API兼容Claude Code",sourceType:"claude-code",apiUrl:"https://ark.cn-beijing.volces.com/api/compatible",models:"doubao-seed-code-preview-251028"},{name:"付费API兼容Codex",sourceType:"openai-responses",apiUrl:"https://ark.cn-beijing.volces.com/api/v3",models:"doubao-seed-code-preview-251028"}]},qwen:{name:"阿里云百炼(千问)",description:"国内优秀大模型 https://help.aliyun.com/zh/model-studio/coding-plan",services:[{name:"Coding Plan Claude Code",sourceType:"claude-code",apiUrl:"https://coding.dashscope.aliyuncs.com/apps/anthropic",models:"qwen3-max-2026-01-23, qwen3-coder-plus"},{name:"Coding Plan Codex",sourceType:"openai-chat",apiUrl:"https://coding.dashscope.aliyuncs.com/v1",models:"qwen3-max-2026-01-23, qwen3-coder-plus"},{name:"付费API兼容Codex",sourceType:"openai-responses",apiUrl:"https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",models:"qwen3-max-2026-01-23, qwen3-coder-plus, kimi-k2.5, glm-4.7, MiniMax-M2.1"}]},aicodewith:{name:"AICodeWith",description:"稳定的第三方中转 https://aicodewith.com/login?tab=register&invitation=QCA74W",services:[{name:"claudecode",sourceType:"claude-code",apiUrl:"https://api.aicodewith.com"},{name:"codex",sourceType:"openai-responses",apiUrl:"https://api.aicodewith.com/chatgpt"}]},openai:{name:"OpenAI",description:"OpenAI 官方 API https://platform.openai.com",services:[{name:"GPT",sourceType:"openai-responses",apiUrl:"https://api.openai.com"}],is_oversea:!0},anthropic:{name:"Anthropic",description:"Anthropic 官方 API https://www.anthropic.com",services:[{name:"Claude",sourceType:"claude-code",apiUrl:"https://api.anthropic.com"}],is_oversea:!0},google:{name:"Google AI",description:"Google AI 官方 API",services:[{name:"Gemini",sourceType:"gemini",apiUrl:"https://generativelanguage.googleapis.com"}],is_oversea:!0},openrouter:{name:"OpenRouter",description:"一站式 AI 模型路由平台 https://openrouter.ai",services:[{name:"Claude Code专属接口",sourceType:"claude-code",apiUrl:"https://openrouter.ai/api",models:"anthropic/claude-opus-4.6, anthropic/claude-opus-4.5, anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5",authType:Sn.AUTH_TOKEN},{name:"通用接口",sourceType:"openai-chat",apiUrl:"https://openrouter.ai/api/v1/chat/completions",models:"anthropic/claude-opus-4.5, anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5, openai/gpt-5.2-codex, openai/gpt-5.2-chat, openai/gpt-5.2-pro, openai/gpt-5.2, openai/gpt-5.1-codex-max, google/gemini-3-flash-preview, google/gemini-3-pro-preview"}],is_oversea:!0}},Yu={"claude-code":"Claude Code",codex:"Codex"},Gu={"claude-code":"Claude Code","claude-chat":"Claude Chat","openai-responses":"OpenAI Responses","openai-chat":"OpenAI Chat","deepseek-reasoning-chat":"DeepSeek Reasoning Chat",gemini:"Gemini"},y3={"openai-chat":"填写完整的接口地址,如:https://api.openai.com/v1/chat/completions","openai-responses":"只填写 base 地址(含/v1),如:https://api.openai.com/v1","claude-chat":"填写完整的接口地址,如:https://api.anthropic.com/v1/messages","claude-code":"只填写 base 地址,如:https://api.anthropic.com","deepseek-reasoning-chat":"推理类模型,填写完整的接口地址,如:https://api.deepseek.com/v1/chat/completions",gemini:"只填写 base 地址,如:https://generativelanguage.googleapis.com"},G1={[Sn.AUTO]:"自动",[Sn.AUTH_TOKEN]:"AUTH_TOKEN",[Sn.API_KEY]:"API_KEY",[Sn.G_API_KEY]:"GOOGLE_API_KEY"},x3={[Sn.AUTO]:"根据数据源类型自动判断:Claude 相关类型使用 x-api-key header,OpenAI 相关类型使用 Authorization: Bearer header,Gemini 使用 x-goog-api-key header",[Sn.AUTH_TOKEN]:"使用 Authorization: Bearer <token> 进行认证(对应 Claude Code 的 ANTHROPIC_AUTH_TOKEN,以及OpenAI的所有请求)",[Sn.API_KEY]:"使用 x-api-key: <token> 进行认证(对应 Claude Code 的 ANTHROPIC_API_KEY)",[Sn.G_API_KEY]:"使用 x-goog-api-key: <token> 进行认证(对应 Google Gemini API)"},b3=`#### 🚀 智谱 GLM Coding Plan
88
88
 
89
89
  > 价格便宜,国内速度快,支持多工具(Claude Code等 20+ 大编程工具),而且其中的GLM-4.7是目前国内最强编程模型。适合对模型有一定要求,同时又无法获取国外模型的朋友入手。
90
90
  >
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>AI Code Switch</title>
7
- <script type="module" crossorigin src="./assets/index-DyW-TIXE.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-itoCE7yt.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="./assets/index-BFZeqM0H.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicodeswitch",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "A tool to help you manage AI programming tools to access large language models locally. It allows your Claude Code, Codex and other tools to no longer be limited to official models.",
5
5
  "author": "tangshuang",
6
6
  "license": "GPL-3.0",