UNPKG

@ckeditor/ckeditor5-ai

Version:

AI Assistant feature for CKEditor 5.

23 lines • 8.25 kB
/* * 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. | * | | * | | * +---------------------------------------------------------------------------------+ * * * * */ const _0x2cd71a=_0x3e27;(function(_0x11222f,_0x38bb5d){const _0x5b5bb0=_0x3e27,_0x4cf156=_0x11222f();while(!![]){try{const _0x34a047=parseInt(_0x5b5bb0(0x1f5))/0x1+parseInt(_0x5b5bb0(0x20a))/0x2*(parseInt(_0x5b5bb0(0x21d))/0x3)+parseInt(_0x5b5bb0(0x21e))/0x4*(parseInt(_0x5b5bb0(0x203))/0x5)+-parseInt(_0x5b5bb0(0x22d))/0x6*(parseInt(_0x5b5bb0(0x1f2))/0x7)+-parseInt(_0x5b5bb0(0x1fa))/0x8+parseInt(_0x5b5bb0(0x1fc))/0x9+parseInt(_0x5b5bb0(0x218))/0xa;if(_0x34a047===_0x38bb5d)break;else _0x4cf156['push'](_0x4cf156['shift']());}catch(_0x27253a){_0x4cf156['push'](_0x4cf156['shift']());}}}(_0x1518,0x5f96f));function _0x3e27(_0x4bbf44,_0x5ae31f){const _0x151813=_0x1518();return _0x3e27=function(_0x3e274f,_0x512fb5){_0x3e274f=_0x3e274f-0x1e9;let _0x45bf9d=_0x151813[_0x3e274f];return _0x45bf9d;},_0x3e27(_0x4bbf44,_0x5ae31f);}import{default as _0x4a341e}from'./aitextadapter.js';import{AIRequestError as _0xa84ab1}from'./aiadapter.js';function _0x1518(){const _0x3e83af=['454732TQJQHL','getReader','split','_requestParameters','editor','_isBufferIncomplete','ai.openAI.requestParameters','choices','pluginName','reject','[DONE]','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.','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.','abortController','signal','273330srGQZQ','_prepareRequestParameters','locale','decode','_apiUrl','get','AI_ERROR_CONTEXT_LENGTH','body','prepareMessages','data:\x20','system','14VCZadp','length','gpt-3.5-turbo','196482XHZiyS','message','delta','https://api.openai.com/v1/chat/completions','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','1956360LolDkc','_prepareRequestHeaders','1891998dTqjRX','context_length_exceeded','filter','Instruction:\x0a','map','_requestHeaders','json','10WWcSci','AI_ERROR_MODERATION','includes','ai.openAI.apiUrl','OpenAITextAdapter','replace','text','161750KFohKL','join','_readStreamableResponse','sendRequest','resolve','Moderation','_readStaticResponse','read','user','config','_cleanUpData','ai.openAI.requestHeaders','parse','content','122450MIqOxs','stream','stringify','define','POST','3eFbtab'];_0x1518=function(){return _0x3e83af;};return _0x1518();}import{getTranslation as _0x370904}from'../utils/common-translations.js';export default class H extends _0x4a341e{static get[_0x2cd71a(0x226)](){const _0x1a6b20=_0x2cd71a;return _0x1a6b20(0x207);}constructor(_0x1f61f3){const _0x25b344=_0x2cd71a;super(_0x1f61f3),_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x21b)](_0x25b344(0x206),_0x25b344(0x1f8)),_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x1ec)](_0x25b344(0x224))||_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x21b)](_0x25b344(0x224),{'model':_0x25b344(0x1f4),'max_tokens':0x7d0,'temperature':0x1,'top_p':0x1,'stream':!0x0}),this[_0x25b344(0x1eb)]=_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x1ec)](_0x25b344(0x206)),this[_0x25b344(0x201)]=_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x1ec)](_0x25b344(0x215))||{},this[_0x25b344(0x221)]=_0x1f61f3[_0x25b344(0x213)][_0x25b344(0x1ec)](_0x25b344(0x224));}async[_0x2cd71a(0x20d)]({query:_0x1c9427,context:_0x2819b9,onData:_0x3239fb,actionId:_0x5d1bdb}){const _0x481b1b=_0x2cd71a,_0x545afb=this[_0x481b1b(0x222)][_0x481b1b(0x1e9)],_0x1e1cbd=await this[_0x481b1b(0x1ef)](_0x1c9427,_0x2819b9,_0x5d1bdb),_0x2c205b=await this[_0x481b1b(0x1fb)](this[_0x481b1b(0x201)],_0x5d1bdb),_0x22be73=await this[_0x481b1b(0x22e)](this[_0x481b1b(0x221)],_0x5d1bdb),_0x4f6142={'messages':_0x1e1cbd,..._0x22be73},_0x22e6bf={'method':_0x481b1b(0x21c),'headers':_0x2c205b,'body':JSON[_0x481b1b(0x21a)](_0x4f6142),'signal':this[_0x481b1b(0x22b)][_0x481b1b(0x22c)]},_0x3730e0=await fetch(this[_0x481b1b(0x1eb)],_0x22e6bf);if(_0x3730e0['ok'])return _0x22be73[_0x481b1b(0x219)]?await this[_0x481b1b(0x20c)](_0x3730e0,_0x3239fb):await this[_0x481b1b(0x210)](_0x3730e0,_0x3239fb),Promise[_0x481b1b(0x20e)]();{const _0x79f3d1=await _0x3730e0[_0x481b1b(0x209)]();return _0x79f3d1[_0x481b1b(0x205)](_0x481b1b(0x1fd))?Promise[_0x481b1b(0x227)](new _0xa84ab1(_0x370904(_0x545afb,_0x481b1b(0x1ed)))):_0x79f3d1[_0x481b1b(0x205)](_0x481b1b(0x20f))?Promise[_0x481b1b(0x227)](new _0xa84ab1(_0x370904(_0x545afb,_0x481b1b(0x204)))):Promise[_0x481b1b(0x227)](new Error(_0x79f3d1));}}async[_0x2cd71a(0x1ef)](_0x35856f,_0x50bace,_0x48faa7){const _0x2b56df=_0x2cd71a;let _0x4565a0,_0x3cf63;return _0x50bace?(_0x4565a0=_0x2b56df(0x22a),_0x3cf63=_0x2b56df(0x1ff)+_0x35856f+_0x2b56df(0x1f9)+_0x50bace):(_0x4565a0=_0x2b56df(0x229),_0x3cf63=_0x35856f),[{'role':_0x2b56df(0x1f1),'content':_0x4565a0},{'role':_0x2b56df(0x212),'content':_0x3cf63}];}async[_0x2cd71a(0x20c)](_0x16eab1,_0xd93eaf){const _0x405f30=_0x2cd71a,_0x318794=_0x16eab1[_0x405f30(0x1ee)][_0x405f30(0x21f)](),_0x41b2cb=new TextDecoder();let _0x52eca6='',_0x55f492='',_0x30b447='',_0x274b8d=!0x1;for(;!_0x274b8d;){const {done:_0x4df640,value:_0x252d5a}=await _0x318794[_0x405f30(0x211)](),_0x101333=_0x52eca6+_0x41b2cb[_0x405f30(0x1ea)](_0x252d5a);let _0x220b23='';_0x274b8d=_0x4df640;try{_0x220b23=this[_0x405f30(0x214)](_0x101333),_0x52eca6='';}catch(_0x1aaac8){_0x52eca6=_0x101333;continue;}_0x55f492+=_0x220b23,!_0x274b8d&&this[_0x405f30(0x223)](_0x55f492)||_0x55f492&&(_0x30b447+=_0x55f492,_0x55f492='',_0xd93eaf(_0x30b447));}return Promise[_0x405f30(0x20e)]();}async[_0x2cd71a(0x210)](_0x10ad5d,_0x5098f2){const _0x430e80=_0x2cd71a;return _0x5098f2((await _0x10ad5d[_0x430e80(0x202)]())[_0x430e80(0x225)][0x0][_0x430e80(0x1f6)][_0x430e80(0x217)]),Promise[_0x430e80(0x20e)]();}[_0x2cd71a(0x223)](_0x4c99fc){const _0x1c51d9=_0x2cd71a,_0x20a661=_0x4c99fc[_0x1c51d9(0x220)]('<')[_0x1c51d9(0x1f3)]!==_0x4c99fc[_0x1c51d9(0x220)]('>')[_0x1c51d9(0x1f3)],_0x497524=_0x4c99fc[_0x1c51d9(0x1f3)]<0x1e;return _0x20a661&&_0x497524;}[_0x2cd71a(0x214)](_0x5eab69){const _0x4bc75f=_0x2cd71a;return _0x5eab69[_0x4bc75f(0x220)](/\n(?![^{]*\})/g)[_0x4bc75f(0x200)](_0x1359b4=>_0x1359b4[_0x4bc75f(0x208)](_0x4bc75f(0x1f0),''))[_0x4bc75f(0x1fe)](_0x54a887=>_0x54a887&&_0x54a887[_0x4bc75f(0x1f3)]>0x0&&_0x4bc75f(0x228)!==_0x54a887)[_0x4bc75f(0x200)](_0x1bb83c=>{const _0x348cc0=_0x4bc75f,{choices:_0x1c61a0}=JSON[_0x348cc0(0x216)](_0x1bb83c);if(_0x1c61a0[0x0]&&_0x1c61a0[0x0][_0x348cc0(0x1f7)]&&_0x1c61a0[0x0][_0x348cc0(0x1f7)][_0x348cc0(0x217)])return _0x1c61a0[0x0][_0x348cc0(0x1f7)][_0x348cc0(0x217)];})[_0x4bc75f(0x1fe)](_0x1cccd5=>_0x1cccd5)[_0x4bc75f(0x20b)]('');}}