@ckeditor/ckeditor5-ai
Version:
AI Assistant feature for CKEditor 5.
23 lines • 8.29 kB
JavaScript
/*
* Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
*
*
*
*
* +---------------------------------------------------------------------------------+
* | |
* | Hello stranger! |
* | |
* | |
* | What you're currently looking at is the source code of a legally protected, |
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
* | are forbidden and will result in legal consequences. |
* | |
* | |
* +---------------------------------------------------------------------------------+
*
*
*
*
*/
function _0x59d4(){const _0x337e3e=['gpt-4o','_readStreamableResponse','replace','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','_requestParameters','1574zsjfRA','ai.openAI.apiUrl','abortController','164714gIsRvq','6WwpUam','1655631LSSKGg','_prepareRequestParameters','AI_ERROR_MODERATION','getReader','Moderation','context_length_exceeded','delta','body','86862SfldgC','length','_requestHeaders','384488nqXqWa','decode','get','ai.openAI.requestParameters','signal','194155IgIiag','message','170rcdrdY','text','join','_cleanUpData','resolve','system','locale','choices','Instruction:\x0a','split','AI_ERROR_CONTEXT_LENGTH','user','https://api.openai.com/v1/chat/completions','includes','100EKmNxR','Your\x20task\x20is\x20to\x20execute\x20the\x20instruction\x20using\x20the\x20provided\x20HTML\x20content.\x20Follow\x20the\x20instruction\x20closely.\x20Your\x20answer\x20must\x20be\x20a\x20properly\x20formatted\x20HTML\x20code.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.','POST','7wsRgVw','reject','_apiUrl','_isBufferIncomplete','prepareMessages','stream','content','OpenAITextAdapter','define','filter','pluginName','sendRequest','map','[DONE]','json','_readStaticResponse','111848eNGgyu','Your\x20task\x20is\x20to\x20generate\x20HTML\x20content\x20accordingly\x20to\x20the\x20given\x20instruction.\x20Never\x20include\x20<img>\x20tag\x20in\x20your\x20response\x20even\x20if\x20asked\x20for.\x20Your\x20answer\x20must\x20be\x20a\x20well-structured\x20and\x20properly\x20formatted\x20HTML\x20code.\x20Answer\x20only\x20with\x20the\x20generated\x20HTML\x20content.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.','stringify','config','data:\x20','editor','ai.openAI.requestHeaders','read','parse','_prepareRequestHeaders'];_0x59d4=function(){return _0x337e3e;};return _0x59d4();}const _0x4e2e3b=_0x28f7;(function(_0x3f6661,_0x373440){const _0x552319=_0x28f7,_0x2a4139=_0x3f6661();while(!![]){try{const _0x470f44=-parseInt(_0x552319(0x220))/0x1*(-parseInt(_0x552319(0x1fe))/0x2)+-parseInt(_0x552319(0x1dd))/0x3*(-parseInt(_0x552319(0x1e9))/0x4)+-parseInt(_0x552319(0x1ee))/0x5+-parseInt(_0x552319(0x1e6))/0x6*(parseInt(_0x552319(0x201))/0x7)+-parseInt(_0x552319(0x211))/0x8+parseInt(_0x552319(0x1de))/0x9+parseInt(_0x552319(0x1f0))/0xa*(-parseInt(_0x552319(0x1dc))/0xb);if(_0x470f44===_0x373440)break;else _0x2a4139['push'](_0x2a4139['shift']());}catch(_0x3dafca){_0x2a4139['push'](_0x2a4139['shift']());}}}(_0x59d4,0x207c0));import{AITextAdapter as _0x13da8d}from'./aitextadapter.js';function _0x28f7(_0x4e6e94,_0x54f821){const _0x59d474=_0x59d4();return _0x28f7=function(_0x28f799,_0x3b4241){_0x28f799=_0x28f799-0x1dc;let _0x35fbe9=_0x59d474[_0x28f799];return _0x35fbe9;},_0x28f7(_0x4e6e94,_0x54f821);}import{AIRequestError as _0x323ad3}from'./aiadapter.js';import{getTranslation as _0x1bc2eb}from'../utils/common-translations.js';export class OpenAITextAdapter extends _0x13da8d{[_0x4e2e3b(0x203)];[_0x4e2e3b(0x1e8)];[_0x4e2e3b(0x21f)];static get[_0x4e2e3b(0x20b)](){const _0x422040=_0x4e2e3b;return _0x422040(0x208);}constructor(_0x352a5b){const _0x217ad9=_0x4e2e3b;super(_0x352a5b),_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x209)](_0x217ad9(0x221),_0x217ad9(0x1fc)),_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x1eb)](_0x217ad9(0x1ec))||_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x209)](_0x217ad9(0x1ec),{'model':_0x217ad9(0x21b),'temperature':0x1,'top_p':0x1,'stream':!0x0}),this[_0x217ad9(0x203)]=_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x1eb)](_0x217ad9(0x221)),this[_0x217ad9(0x1e8)]=_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x1eb)](_0x217ad9(0x217))||{},this[_0x217ad9(0x21f)]=_0x352a5b[_0x217ad9(0x214)][_0x217ad9(0x1eb)](_0x217ad9(0x1ec));}async[_0x4e2e3b(0x20c)]({query:_0x227767,context:_0x16f24d,onData:_0x3e0f55,actionId:_0x385c6f}){const _0x55bf09=_0x4e2e3b,_0x528ab3=this[_0x55bf09(0x216)][_0x55bf09(0x1f6)],_0x241e42=await this[_0x55bf09(0x205)](_0x227767,_0x16f24d,_0x385c6f),_0x5941b0=await this[_0x55bf09(0x21a)](this[_0x55bf09(0x1e8)],_0x385c6f),_0x243033=await this[_0x55bf09(0x1df)](this[_0x55bf09(0x21f)],_0x385c6f),_0x17baa7={'messages':_0x241e42,..._0x243033},_0x40363e={'method':_0x55bf09(0x200),'headers':_0x5941b0,'body':JSON[_0x55bf09(0x213)](_0x17baa7),'signal':this[_0x55bf09(0x222)][_0x55bf09(0x1ed)]},_0x13d46b=await fetch(this[_0x55bf09(0x203)],_0x40363e);if(_0x13d46b['ok'])return _0x243033[_0x55bf09(0x206)]?await this[_0x55bf09(0x21c)](_0x13d46b,_0x3e0f55):await this[_0x55bf09(0x210)](_0x13d46b,_0x3e0f55),Promise[_0x55bf09(0x1f4)]();{const _0x3fcce6=await _0x13d46b[_0x55bf09(0x1f1)]();return _0x3fcce6[_0x55bf09(0x1fd)](_0x55bf09(0x1e3))?Promise[_0x55bf09(0x202)](new _0x323ad3(_0x1bc2eb(_0x528ab3,_0x55bf09(0x1fa)))):_0x3fcce6[_0x55bf09(0x1fd)](_0x55bf09(0x1e2))?Promise[_0x55bf09(0x202)](new _0x323ad3(_0x1bc2eb(_0x528ab3,_0x55bf09(0x1e0)))):Promise[_0x55bf09(0x202)](new Error(_0x3fcce6));}}async[_0x4e2e3b(0x205)](_0x15a6ba,_0x105100,_0x3bbd13){const _0xb58c15=_0x4e2e3b;let _0x9e3f7b,_0x801e2c;return _0x105100?(_0x9e3f7b=_0xb58c15(0x1ff),_0x801e2c=_0xb58c15(0x1f8)+_0x15a6ba+_0xb58c15(0x21e)+_0x105100):(_0x9e3f7b=_0xb58c15(0x212),_0x801e2c=_0x15a6ba),[{'role':_0xb58c15(0x1f5),'content':_0x9e3f7b},{'role':_0xb58c15(0x1fb),'content':_0x801e2c}];}async[_0x4e2e3b(0x21c)](_0x29ae1d,_0x264fb2){const _0x271f3e=_0x4e2e3b,_0x10b38e=_0x29ae1d[_0x271f3e(0x1e5)][_0x271f3e(0x1e1)](),_0x4ddd9e=new TextDecoder();let _0x189dc8='',_0x318d09='',_0x324dc3='',_0x50febe=!0x1;for(;!_0x50febe;){const {done:_0x5c0ea2,value:_0xd68719}=await _0x10b38e[_0x271f3e(0x218)](),_0x3b8e33=_0x189dc8+_0x4ddd9e[_0x271f3e(0x1ea)](_0xd68719);let _0xe90106='';_0x50febe=_0x5c0ea2;try{_0xe90106=this[_0x271f3e(0x1f3)](_0x3b8e33),_0x189dc8='';}catch{_0x189dc8=_0x3b8e33;continue;}_0x318d09+=_0xe90106,!_0x50febe&&this[_0x271f3e(0x204)](_0x318d09)||_0x318d09&&(_0x324dc3+=_0x318d09,_0x318d09='',_0x264fb2(_0x324dc3));}return Promise[_0x271f3e(0x1f4)]();}async[_0x4e2e3b(0x210)](_0x29afb3,_0x2ccacf){const _0x4127fc=_0x4e2e3b;return _0x2ccacf((await _0x29afb3[_0x4127fc(0x20f)]())[_0x4127fc(0x1f7)][0x0][_0x4127fc(0x1ef)][_0x4127fc(0x207)]),Promise[_0x4127fc(0x1f4)]();}[_0x4e2e3b(0x204)](_0x110cef){const _0x35704c=_0x4e2e3b,_0x2598d0=_0x110cef[_0x35704c(0x1f9)]('<')[_0x35704c(0x1e7)]!==_0x110cef[_0x35704c(0x1f9)]('>')[_0x35704c(0x1e7)],_0x5329cb=_0x110cef[_0x35704c(0x1e7)]<0x1e;return _0x2598d0&&_0x5329cb;}[_0x4e2e3b(0x1f3)](_0xf41a53){const _0x5f666c=_0x4e2e3b;return _0xf41a53[_0x5f666c(0x1f9)](/\n(?![^{]*\})/g)[_0x5f666c(0x20d)](_0x3de3df=>_0x3de3df[_0x5f666c(0x21d)](_0x5f666c(0x215),''))[_0x5f666c(0x20a)](_0x95442b=>_0x95442b&&_0x95442b[_0x5f666c(0x1e7)]>0x0&&_0x5f666c(0x20e)!==_0x95442b)[_0x5f666c(0x20d)](_0x4bd0b7=>{const _0x313afb=_0x5f666c,{choices:_0x193628}=JSON[_0x313afb(0x219)](_0x4bd0b7);if(_0x193628[0x0]?.[_0x313afb(0x1e4)]?.[_0x313afb(0x207)])return _0x193628[0x0][_0x313afb(0x1e4)][_0x313afb(0x207)];})[_0x5f666c(0x20a)](_0x280a84=>_0x280a84)[_0x5f666c(0x1f2)]('');}}