const _0x4977ff=_0x1413;
function _0x1413(_0x4dc7c8, _0x5f3875) {
  _0x4dc7c8=_0x4dc7c8-0x1b4;
  const _0x4b721c=_0x4b72();
  let _0x1413d0=_0x4b721c[_0x4dc7c8];
  if(_0x1413['BPxKLt']===undefined) {
    var _0x3d0925=function(_0x4e4da8) {
      const _0x6eeb3b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';
      let _0x2ce721='', _0xda559a='';
      for(let _0x5e8928=0x0, _0x32c098, _0x34a6ae, _0x5461ee=0x0;
      _0x34a6ae=_0x4e4da8['charAt'](_0x5461ee++);
      ~_0x34a6ae&&(_0x32c098=_0x5e8928%0x4?_0x32c098*0x40+_0x34a6ae:_0x34a6ae, _0x5e8928++%0x4)?_0x2ce721+=String['fromCharCode'](0xff&_0x32c098>>(-0x2*_0x5e8928&0x6)):0x0) {
        _0x34a6ae=_0x6eeb3b['indexOf'](_0x34a6ae);
      }
      for(let _0x4561a6=0x0, _0xb5d9b3=_0x2ce721['length'];
      _0x4561a6<_0xb5d9b3;
      _0x4561a6++) {
        _0xda559a+='%'+('00'+_0x2ce721['charCodeAt'](_0x4561a6)['toString'](0x10))['slice'](-0x2);
      }
      return decodeURIComponent(_0xda559a);
    };
    _0x1413['YlMVSJ']=_0x3d0925, _0x1413['oOYfUP']= {
    }, _0x1413['BPxKLt']=!![];
  }
  const _0x5b7f69=_0x4b721c[0x0], _0x2feaef=_0x4dc7c8+_0x5b7f69, _0x36c442=_0x1413['oOYfUP'][_0x2feaef];
  return!_0x36c442?(_0x1413d0=_0x1413['YlMVSJ'](_0x1413d0), _0x1413['oOYfUP'][_0x2feaef]=_0x1413d0):_0x1413d0=_0x36c442, _0x1413d0;
}
function _0x4b72() {
  const _0x31729e=['y29UDgvUDenOCM9Tzq', 'ywjVCNq', 'AxnbCNjHEq', 'z2v0', 'C3LZDgvT', 'ioAxOoAZLEINO+AEKoMuMEIVR+wtJEw6LooaGG', 'quKGqvbjioIWG+EuQowKSEI0PEoaGUIVT+AJGoAFPsbbueKGs2v544cbqMfZzsbvuKWG5lIo572r57UC44cckoIVPUAdHtOG', 'mtq1mKfkv0fSBa', 'zxjYB3i', 'mti1mZC0ovfhEfjJta', 'quLFuKvtue9ou0vFru5e', 'DhLWzq', 'CM9Szq', 'w0rptKvD', 'rgv2ugfUzwW', 'DhjPBq', '5RAi5OgV5lI656M677Ym5PEG5Rov5y+r6ycb6k+35Rgc44cc', 'C3rHDhvZ', 'mMnowgfqCG', 'C3vIC3rYAw5N', 'ANnVBG', 'yxbWBgLJyxrPB24VANnVBG', 'mta4otGWotv1qLrzChy', 'DxnLCG', 'C3rHCNrZv2L0Aa', 'nZKWoduWmhH2t3DtAW', 'DgfI', 'zNjHBwvjza', 'Cg9ZDe1LC3nHz2u', 'ntqWBevmsvLb', 'zMLSDgvY', 'quLFuKvrvuvtva', 'ota4meHKvgXhtG', 'mZbJreTrqw8', 'rvjst1i', 'BgfZDevYCM9Y', 'u3rYzwfTihbHCNnLigvYCM9YoG', 'zgf0yq', 'CMvWBgfJzq', 'C2LNBMfS', 'y29UDgvUDa', 'mtfQBKXhD1i', 'mtK2mtu1ENb6C3zv', 'BMfTzq', 'zgvJB2rL', 'C3bSAxq', 'ue9tva', 'mJK3mdu5teHbwLHK', 'yM9KEq', 'zgv2ugfUzwXtDgf0zunOyw5Nzq', 'BgvUz3rO', 'qMvHCMvYia', 'CNvUDgLTzq', 'DgfIswq', 'BwvZC2fNzq', 'B25nzxnZywDL', 'ywrKtgLZDgvUzxi', 'nZuYndH4zvjtELC', 'zgvSzxrL', 'mtjss1PjBKG', 'Aw5KzxHpzG', 'zgf0ytOG', 'quLFuKvtue9ou0vFu1rbuLq', 'C2vUzgvY', 'l2nOyxqVy29TCgXLDgLVBNm', 'zgvSDge'];
  _0x4b72=function() {
    return _0x31729e;
  };
  return _0x4b72();
}
(function(_0x10b589, _0x2de170) {
  const _0x5799d1= {
    _0x2bee65:0x1ea, _0xa67a38:0x1c0, _0x3a82b3:0x1e6, _0x290827:0x1f2
  }, _0x26b0d9=_0x1413, _0xa3c5da=_0x10b589();
  while(!![]) {
    try {
      const _0xa41eba=parseInt("297059LHAZXd")/0x1*(-parseInt("2cNXaPr")/0x2)+parseInt("1452AJWAll")/0x3*(parseInt("9080HdTlGN")/0x4)+parseInt("196155zpzsvU")/0x5+parseInt("30cDKQAo")/0x6*(-parseInt("1253749QGxRcL")/0x7)+-parseInt("75248xeRSzW")/0x8*(-parseInt("540lELIYA")/0x9)+parseInt("7908500xvOwSk")/0xa*(-parseInt("11jnLGwR")/0xb)+-parseInt("12RKZInH")/0xc*(-parseInt("10898095uBTYpv")/0xd);
      if(_0xa41eba===_0x2de170)break;
      else _0xa3c5da['push'](_0xa3c5da['shift']());
    }
    catch(_0x3d981c) {
      _0xa3c5da['push'](_0xa3c5da['shift']());
    }
  }
}
(_0x4b72, 0x88056), importScripts('usage-stats.js'));
const devPanelPorts= {
}, contentChromePorts= {
};
function clearLastError() {
  const _0x1b4c81= {
    _0x5214df:0x1bb
  }, _0x994c8=_0x1413;
  chrome["runtime"]["lastError"]&&void chrome['runtime']['lastError']["message"];
}
function safePortPost(_0x2ce721, _0xda559a) {
  const _0x3feb6f=_0x1413;
  if(!_0x2ce721)return![];
  try {
    _0x2ce721["postMessage"](_0xda559a);
  }
  catch(_0x5e8928) {
    return clearLastError(), ![];
  }
  if(chrome["runtime"]["lastError"])return clearLastError(), ![];
  return!![];
}
chrome['runtime']['onConnect']["addListener"](function(_0x32c098) {
  const _0x32abbb= {
    _0x57b21b:0x1f4, _0x5c8069:0x1c3, _0x598189:0x1d7, _0x22a6f5:0x1f4, _0x25ca70:0x1f4, _0x1b36fc:0x1c9, _0x326a02:0x1c6, _0x543ed1:0x1e3, _0x3cbaf4:0x1be, _0x1c75fa:0x1bf
  }, _0x12dfcc= {
    _0x41acea:0x1cc
  }, _0x10f242= {
    _0x223000:0x1d4
  }, _0x2122f2=_0x4977ff;
  if(_0x32c098["name"]["indexOf"]("DevPanel")===0x0) {
    registerGameInspectPort(_0x32c098, devPanelPorts, contentChromePorts, parseInt(_0x32c098["name"]["replace"]("DevPanel", ''), 0xa));
    return;
  }
  if(_0x32c098["name"]["indexOf"]("contentChrome")===0x0) {
    const _0x34a6ae=_0x32c098["sender"]&&_0x32c098["sender"]["tab"]?_0x32c098["sender"]["tab"]['id']:0x0;
    registerGameInspectPort(_0x32c098, contentChromePorts, devPanelPorts, _0x34a6ae);
    return;
  }
  if(_0x32c098["name"]==='devtools-panel-port') {
    const _0x5461ee=new WeakMap();
    _0x32c098["onMessage"]["addListener"](function(_0x4561a6) {
      const _0x3e13f4=_0x2122f2;
      if(_0x4561a6["type"]==="AI_REQUEST")handleAiRequest(_0x4561a6['payload'], _0x32c098, _0x5461ee);
      else {
        if(_0x4561a6["type"]==='AI_CANCEL') {
          const _0xb5d9b3=_0x5461ee["get"](_0x32c098);
          if(_0xb5d9b3)_0xb5d9b3['abort']();
        }
      }
    }), _0x32c098['onDisconnect']["addListener"](function() {
      const _0x4d853f=_0x2122f2, _0x1818ae=_0x5461ee["get"](_0x32c098);
      if(_0x1818ae)_0x1818ae['abort']();
      clearLastError();
    });
  }
});
function registerGameInspectPort(_0x23465f, _0x8d87ea, _0x14090f, _0x2a4da0) {
  const _0x3785e4= {
    _0x41d86a:0x1bf, _0x3e256e:0x1bf
  }, _0x21c604= {
    _0x4d1550:0x1f4, _0x14086b:0x1ef, _0x4a8b9e:0x1c6, _0xe1087e:0x1f4, _0x5ac935:0x1e3, _0x10736f:0x1e4, _0x1782da:0x1c6, _0x368d41:0x1e4
  }, _0x1eeb0b=_0x4977ff;
  _0x8d87ea[_0x23465f["name"]]=_0x23465f, _0x23465f["onMessage"]["addListener"](function(_0x2f836a, _0x4ef43e) {
    const _0x3b3197=_0x1eeb0b;
    for(const _0x2f634f in _0x14090f) {
      const _0x47249b=_0x14090f[_0x2f634f];
      if(!_0x47249b)continue;
      let _0x59a96d=0x0;
      if(_0x47249b["name"]['indexOf']('DevPanel')===0x0) {
        _0x59a96d=parseInt(_0x47249b["name"]["replace"]("DevPanel", ''), 0xa);
        if(_0x4ef43e["sender"])_0x2f836a["frameId"]=_0x4ef43e['sender']["frameId"];
      }
      else {
        if(_0x47249b["name"]["indexOf"]('contentChrome')===0x0) {
          _0x59a96d=_0x47249b["sender"]&&_0x47249b["sender"]["tab"]?_0x47249b["sender"]['tab']['id']:0x0;
          if(_0x47249b["sender"])_0x2f836a["frameId"]=_0x47249b["sender"]["frameId"];
        }
      }
      _0x59a96d===_0x2a4da0&&safePortPost(_0x47249b, _0x2f836a);
    }
  }), _0x23465f['onDisconnect']["addListener"](function() {
    delete _0x8d87ea[_0x23465f['name']], clearLastError();
  });
}
chrome["runtime"]["onMessage"]['addListener'](function(_0x27aaec) {
  const _0x2c8483= {
    _0x4e959d:0x1b8, _0x8d0742:0x1c6, _0x1280a5:0x1c6
  }, _0x221c1d=_0x4977ff;
  if(_0x27aaec["type"]!=="devPanelStateChange")return;
  const _0x520e26=_0x27aaec["data"]&&_0x27aaec["data"]["tabId"];
  if(_0x520e26==null)return;
  for(const _0x52106d in devPanelPorts) {
    const _0x23906c=devPanelPorts[_0x52106d];
    _0x23906c["name"]==="DevPanel"+_0x520e26&&safePortPost(_0x23906c, _0x27aaec);
  }
  for(const _0x55c070 in contentChromePorts) {
    const _0x266f60=contentChromePorts[_0x55c070];
    _0x266f60["sender"]&&_0x266f60["sender"]["tab"]&&_0x266f60["sender"]["tab"]['id']===_0x520e26&&safePortPost(_0x266f60, _0x27aaec);
  }
});
async function handleAiRequest(_0x117494, _0x185e4c, _0x1e3694) {
  const _0x34e5cc= {
    _0x1f0edb:0x1ef, _0xd54f51:0x1c7, _0x447d17:0x1cb, _0x948bd7:0x1cd, _0x42a435:0x1eb, _0x46e69b:0x1b5, _0x553655:0x1de, _0x23f8df:0x1da, _0x212150:0x1dd, _0x4eac65:0x1d1, _0x3dd7b9:0x1bd, _0x4dd7f2:0x1d1, _0x1d1f5d:0x1b4, _0x32da3f:0x1e7, _0x130d77:0x1e1, _0x39f612:0x1c4, _0x35a84d:0x1f4, _0x156e48:0x1bd, _0x421935:0x1cc, _0x58144d:0x1c1
  }, _0x9de10a=_0x4977ff,  {
    systemPrompt:_0x52962a, userPrompt:_0x14d441, messages:_0x289539, model:_0x200183, apiKey:_0x509385, apiUrl:_0x41d613, apiBaseUrl:_0x19f7bb, analyzeOnly:_0x3049a2
  }
  =_0x117494, _0x9dcac3=_0x41d613||(_0x19f7bb?_0x19f7bb["replace"](/\/$/, '')+"/chat/completions":'');
  if(!_0x9dcac3) {
    safePortPost(_0x185e4c,  {
      'type':'ERROR', 'payload':'AI\x20API\x20地址未配置，请在「配置」中填写请求地址。'
    }), safePortPost(_0x185e4c,  {
      'type':'AI_RESPONSE_END', 'fullResponse':'', 'analyzeOnly':!!_0x3049a2
    });
    return;
  }
  const _0x448dff=Array["isArray"](_0x289539)&&_0x289539["length"]?_0x289539:[ {
    'role':"system", 'content':_0x52962a||''
  },  {
    'role':'user', 'content':_0x14d441||''
  }];
  if(!_0x448dff['some'](_0x25a996=>_0x25a996["role"]==="user")) {
    safePortPost(_0x185e4c,  {
      'type':"ERROR", 'payload':"消息为空，无法发送请求。"
    }), safePortPost(_0x185e4c,  {
      'type':"AI_RESPONSE_END", 'fullResponse':'', 'analyzeOnly':!!_0x3049a2
    });
    return;
  }
  const _0x37f884=_0x1e3694&&_0x1e3694["get"](_0x185e4c);
  if(_0x37f884)_0x37f884["abort"]();
  const _0x351cf7=new AbortController();
  if(_0x1e3694)_0x1e3694['set'](_0x185e4c, _0x351cf7);
  safePortPost(_0x185e4c,  {
    'type':"AI_RESPONSE_START"
  });
  let _0xea1c0c='', _0x5c0861=![];
  try {
    const _0x3245a6=await fetch(_0x9dcac3,  {
      'method':"POST", 'signal':_0x351cf7["signal"], 'headers': {
        'Content-Type':"application/json", 'Authorization':"Bearer "+_0x509385
      }, 'body':JSON['stringify']( {
        'model':_0x200183, 'messages':_0x448dff, 'temperature':0.2, 'stream':!![]
      })
    });
    if(!_0x3245a6['ok']) {
      let _0x393fe7='AI\x20API\x20请求失败\x20(状态码:\x20'+_0x3245a6["status"]+')。';
      try {
        const _0x596633=await _0x3245a6["json"]();
        if(_0x596633?.["error"]?.["message"])_0x393fe7+='\x20'+_0x596633["error"]["message"];
        else {
          if(_0x596633?.['message'])_0x393fe7+='\x20'+_0x596633['message'];
        }
      }
      catch(_0x3bfe07) {
        _0x393fe7+=" 无法解析错误响应。";
      }
      throw new Error(_0x393fe7);
    }
    const _0x45fb16=_0x3245a6["body"]['getReader'](), _0x5c4fdc=new TextDecoder('utf-8');
    while(!![]) {
      const  {
        value:_0x27f007, done:_0x3b852c
      }
      =await _0x45fb16['read']();
      if(_0x3b852c)break;
      const _0x28f11a=_0x5c4fdc["decode"](_0x27f007,  {
        'stream':!![]
      }), _0xa19ba2=_0x28f11a["split"]('\x0a')["filter"](_0x4ab455=>_0x4ab455["trim"]()!=='');
      for(const _0x889258 of _0xa19ba2) {
        if(!_0x889258["startsWith"]("data: "))continue;
        const _0xb52025=_0x889258["substring"](0x6);
        if(_0xb52025==="[DONE]")break;
        try {
          const _0x26c985=JSON['parse'](_0xb52025), _0x59ea95=_0x26c985['choices'][0x0]["delta"]["content"]||'';
          _0x59ea95&&(safePortPost(_0x185e4c,  {
            'type':'AI_RESPONSE_CHUNK', 'payload':_0x59ea95
          }), _0xea1c0c+=_0x59ea95);
        }
        catch(_0x341b09) {
          console["error"]("Stream parse error:", _0x341b09);
        }
      }
    }
  }
  catch(_0x2d2544) {
    _0x2d2544["name"]==='AbortError'?(_0x5c0861=!![], safePortPost(_0x185e4c,  {
      'type':'AI_RESPONSE_ABORTED', 'fullResponse':_0xea1c0c, 'analyzeOnly':!!_0x3049a2
    })):(safePortPost(_0x185e4c,  {
      'type':"ERROR", 'payload':"AI API 调用失败。请检查 API Key、Base URL 与网络。(详情: "+_0x2d2544["message"]+')'
    }), _0xea1c0c='');
  }
  finally {
    _0x1e3694&&_0x1e3694["get"](_0x185e4c)===_0x351cf7&&_0x1e3694["delete"](_0x185e4c), !_0x5c0861&&safePortPost(_0x185e4c,  {
      'type':"AI_RESPONSE_END", 'fullResponse':_0xea1c0c, 'analyzeOnly':!!_0x3049a2
    });
  }
}
