UNPKG

@ckeditor/ckeditor5-ai

Version:

AI features for CKEditor 5.

23 lines • 8.32 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 _0x4ee92e=_0x2835;(function(_0x326fee,_0x4f15d8){const _0xaf97a6=_0x2835,_0x34bff5=_0x326fee();while(!![]){try{const _0x4805df=-parseInt(_0xaf97a6(0xbc))/0x1*(parseInt(_0xaf97a6(0xe1))/0x2)+-parseInt(_0xaf97a6(0xe6))/0x3*(-parseInt(_0xaf97a6(0xc6))/0x4)+parseInt(_0xaf97a6(0xc8))/0x5*(parseInt(_0xaf97a6(0xb0))/0x6)+parseInt(_0xaf97a6(0xb8))/0x7*(parseInt(_0xaf97a6(0xf2))/0x8)+-parseInt(_0xaf97a6(0xbe))/0x9*(-parseInt(_0xaf97a6(0xc3))/0xa)+-parseInt(_0xaf97a6(0xbb))/0xb*(parseInt(_0xaf97a6(0xd5))/0xc)+parseInt(_0xaf97a6(0xe2))/0xd;if(_0x4805df===_0x4f15d8)break;else _0x34bff5['push'](_0x34bff5['shift']());}catch(_0x2cfb5b){_0x34bff5['push'](_0x34bff5['shift']());}}}(_0x2b2d,0xe9d6e));import{AITextAdapter as _0x1aeee1}from'./aitextadapter.js';function _0x2835(_0x2dff34,_0x4d71e7){const _0x2b2d7f=_0x2b2d();return _0x2835=function(_0x283541,_0x4eca0b){_0x283541=_0x283541-0xb0;let _0x17613c=_0x2b2d7f[_0x283541];return _0x17613c;},_0x2835(_0x2dff34,_0x4d71e7);}import{AIRequestError as _0x43adc0}from'./aiadapter.js';function _0x2b2d(){const _0x37cb73=['join','choices','gpt-4o','6vrAcUs','_readStaticResponse','https://api.openai.com/v1/chat/completions','abortController','split','parse','pluginName','_prepareRequestHeaders','1978151GFhGpI','data:\x20','stringify','1235179uyVqGx','1864orEevA','define','171duRVHm','body','Moderation','resolve','AI_ERROR_CONTEXT_LENGTH','760570WOYTws','content','reject','3184kzdvFD','_readStreamableResponse','6224505SFBCuN','read','signal','OpenAITextAdapter','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.','get','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','getReader','decode','[DONE]','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.','_apiUrl','editor','204JcsHpP','context_length_exceeded','_cleanUpData','json','_prepareRequestParameters','stream','includes','_requestParameters','user','config','locale','ai.assistant.adapter.openAI.apiUrl','1052SShuCW','959790EbGhYB','POST','delta','system','3018vbkJcM','length','ai.assistant.adapter.openAI.requestHeaders','AI_ERROR_MODERATION','_requestHeaders','Instruction:\x0a','message','filter','ai.assistant.adapter.openAI.requestParameters','text','prepareMessages','replace','8gfwjma','map','_isBufferIncomplete','sendRequest'];_0x2b2d=function(){return _0x37cb73;};return _0x2b2d();}import{getTranslation as _0x28dba0}from'../utils/common-translations.js';export class OpenAITextAdapter extends _0x1aeee1{[_0x4ee92e(0xd3)];[_0x4ee92e(0xea)];[_0x4ee92e(0xdc)];static get[_0x4ee92e(0xb6)](){const _0x20a709=_0x4ee92e;return _0x20a709(0xcb);}constructor(_0x223afd){const _0x27d768=_0x4ee92e;super(_0x223afd),_0x223afd[_0x27d768(0xde)][_0x27d768(0xbd)](_0x27d768(0xe0),_0x27d768(0xb2)),_0x223afd[_0x27d768(0xde)][_0x27d768(0xcd)](_0x27d768(0xee))||_0x223afd[_0x27d768(0xde)][_0x27d768(0xbd)](_0x27d768(0xee),{'model':_0x27d768(0xf8),'temperature':0x1,'top_p':0x1,'stream':!0x0}),this[_0x27d768(0xd3)]=_0x223afd[_0x27d768(0xde)][_0x27d768(0xcd)](_0x27d768(0xe0)),this[_0x27d768(0xea)]=_0x223afd[_0x27d768(0xde)][_0x27d768(0xcd)](_0x27d768(0xe8))||{},this[_0x27d768(0xdc)]=_0x223afd[_0x27d768(0xde)][_0x27d768(0xcd)](_0x27d768(0xee));}async[_0x4ee92e(0xf5)]({query:_0x42a337,context:_0x25ea8b,onData:_0x19ab93,actionId:_0x39278c}){const _0x2e819e=_0x4ee92e,_0x6d2a5c=this[_0x2e819e(0xd4)][_0x2e819e(0xdf)],_0x365397=await this[_0x2e819e(0xf0)](_0x42a337,_0x25ea8b,_0x39278c),_0x14b724=await this[_0x2e819e(0xb7)](this[_0x2e819e(0xea)],_0x39278c),_0x4c7def=await this[_0x2e819e(0xd9)](this[_0x2e819e(0xdc)],_0x39278c),_0x5f4b03={'messages':_0x365397,..._0x4c7def},_0xc846={'method':_0x2e819e(0xe3),'headers':_0x14b724,'body':JSON[_0x2e819e(0xba)](_0x5f4b03),'signal':this[_0x2e819e(0xb3)][_0x2e819e(0xca)]},_0x5eeaab=await fetch(this[_0x2e819e(0xd3)],_0xc846);if(_0x5eeaab['ok'])return _0x4c7def[_0x2e819e(0xda)]?await this[_0x2e819e(0xc7)](_0x5eeaab,_0x19ab93):await this[_0x2e819e(0xb1)](_0x5eeaab,_0x19ab93),Promise[_0x2e819e(0xc1)]();{const _0x4cbd91=await _0x5eeaab[_0x2e819e(0xef)]();return _0x4cbd91[_0x2e819e(0xdb)](_0x2e819e(0xd6))?Promise[_0x2e819e(0xc5)](new _0x43adc0(_0x28dba0(_0x6d2a5c,_0x2e819e(0xc2)))):_0x4cbd91[_0x2e819e(0xdb)](_0x2e819e(0xc0))?Promise[_0x2e819e(0xc5)](new _0x43adc0(_0x28dba0(_0x6d2a5c,_0x2e819e(0xe9)))):Promise[_0x2e819e(0xc5)](new Error(_0x4cbd91));}}async[_0x4ee92e(0xf0)](_0x11c0d5,_0x21070b,_0xc5ae7b){const _0x4c895c=_0x4ee92e;let _0x3b77a4,_0x24cc42;return _0x21070b?(_0x3b77a4=_0x4c895c(0xd2),_0x24cc42=_0x4c895c(0xeb)+_0x11c0d5+_0x4c895c(0xce)+_0x21070b):(_0x3b77a4=_0x4c895c(0xcc),_0x24cc42=_0x11c0d5),[{'role':_0x4c895c(0xe5),'content':_0x3b77a4},{'role':_0x4c895c(0xdd),'content':_0x24cc42}];}async[_0x4ee92e(0xc7)](_0x3a8511,_0x3d48d5){const _0x53dc92=_0x4ee92e,_0x4152e2=_0x3a8511[_0x53dc92(0xbf)][_0x53dc92(0xcf)](),_0x386838=new TextDecoder();let _0x624328='',_0xb3bb77='',_0x578abb='',_0x1a86e5=!0x1;for(;!_0x1a86e5;){const {done:_0x686f19,value:_0x24a6d6}=await _0x4152e2[_0x53dc92(0xc9)](),_0x261d2a=_0x624328+_0x386838[_0x53dc92(0xd0)](_0x24a6d6);let _0x1d589a='';_0x1a86e5=_0x686f19;try{_0x1d589a=this[_0x53dc92(0xd7)](_0x261d2a),_0x624328='';}catch{_0x624328=_0x261d2a;continue;}_0xb3bb77+=_0x1d589a,!_0x1a86e5&&this[_0x53dc92(0xf4)](_0xb3bb77)||_0xb3bb77&&(_0x578abb+=_0xb3bb77,_0xb3bb77='',_0x3d48d5(_0x578abb));}return Promise[_0x53dc92(0xc1)]();}async[_0x4ee92e(0xb1)](_0x3042d9,_0x26c179){const _0x2f82f0=_0x4ee92e;return _0x26c179((await _0x3042d9[_0x2f82f0(0xd8)]())[_0x2f82f0(0xf7)][0x0][_0x2f82f0(0xec)][_0x2f82f0(0xc4)]),Promise[_0x2f82f0(0xc1)]();}[_0x4ee92e(0xf4)](_0x393454){const _0x5ccbd6=_0x4ee92e,_0x4b22e6=_0x393454[_0x5ccbd6(0xb4)]('<')[_0x5ccbd6(0xe7)]!==_0x393454[_0x5ccbd6(0xb4)]('>')[_0x5ccbd6(0xe7)],_0x1b3f52=_0x393454[_0x5ccbd6(0xe7)]<0x1e;return _0x4b22e6&&_0x1b3f52;}[_0x4ee92e(0xd7)](_0x1d7408){const _0x4fe7f2=_0x4ee92e;return _0x1d7408[_0x4fe7f2(0xb4)](/\n(?![^{]*\})/g)[_0x4fe7f2(0xf3)](_0x25faf5=>_0x25faf5[_0x4fe7f2(0xf1)](_0x4fe7f2(0xb9),''))[_0x4fe7f2(0xed)](_0x921ccf=>_0x921ccf&&_0x921ccf[_0x4fe7f2(0xe7)]>0x0&&_0x4fe7f2(0xd1)!==_0x921ccf)[_0x4fe7f2(0xf3)](_0x351606=>{const _0x2878fc=_0x4fe7f2,{choices:_0x49d2d0}=JSON[_0x2878fc(0xb5)](_0x351606);if(_0x49d2d0[0x0]?.[_0x2878fc(0xe4)]?.[_0x2878fc(0xc4)])return _0x49d2d0[0x0][_0x2878fc(0xe4)][_0x2878fc(0xc4)];})[_0x4fe7f2(0xed)](_0x4f1862=>_0x4f1862)[_0x4fe7f2(0xf6)]('');}}