@ckeditor/ckeditor5-ai
Version:
AI Assistant feature for CKEditor 5.
23 lines • 10.1 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. |
* | |
* | |
* +---------------------------------------------------------------------------------+
*
*
*
*
*/
const _0x235c42=_0x1f16;(function(_0x5c376e,_0x44be73){const _0x16dbef=_0x1f16,_0x5bbba6=_0x5c376e();while(!![]){try{const _0x2d6a76=-parseInt(_0x16dbef(0xce))/0x1+parseInt(_0x16dbef(0xa4))/0x2*(parseInt(_0x16dbef(0x91))/0x3)+-parseInt(_0x16dbef(0x8b))/0x4+parseInt(_0x16dbef(0xca))/0x5+parseInt(_0x16dbef(0xcb))/0x6+-parseInt(_0x16dbef(0xc9))/0x7*(parseInt(_0x16dbef(0xbc))/0x8)+parseInt(_0x16dbef(0xb8))/0x9;if(_0x2d6a76===_0x44be73)break;else _0x5bbba6['push'](_0x5bbba6['shift']());}catch(_0xd06f37){_0x5bbba6['push'](_0x5bbba6['shift']());}}}(_0xa1f8,0x98ff4));function _0xa1f8(){const _0x5a2ae4=['bytes','anthropic.claude-v2','\x0a\x0aAssistant:','length','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','cohere.command','_readStreamableResponse','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.','_requestHeaders','4696532zCtOeQ','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.','AI_ERROR_UNSUPPORTED_MODEL','filter','split','chunk','9ayvZcW','_prepareRequestParameters','\x0a<</SYS>>\x0a[INST]\x0a','locale','preparePrompt','pluginName','data','anthropic.claude','define','ai.aws.bedrockClientConfig','get','_processProxyRequest','meta.llama','send','map','Instruction:\x0a','bedrock-2023-05-31','<<SYS>>\x0a','ai.aws.requestParameters','768002QvdQWU','completions','abortController','read','_bedrockClientConfig','editor','\x0a[/INST]','generation','_readAsyncIterableResponse','getModelFamily','config','body','_prepareRequestHeaders','AWSTextAdapter','_processAWSRequest','join','_apiUrl','test','generations','ai.aws.apiUrl','9668691zaMgiG','completion','utf-8','parse','331464dzyBiz','getReader','text','stringify','decode','sendRequest','POST','_readStaticResponse','_requestParameters','json','application/json','ai.aws.requestHeaders','_getGeneratedText','42XhQola','1333645FxdnBz','3667638ScXaKZ','resolve','signal','1054897ZhEEeg','ai21.j2','Human:\x0a'];_0xa1f8=function(){return _0x5a2ae4;};return _0xa1f8();}import{AITextAdapter as _0x29e37d}from'./aitextadapter.js';function _0x1f16(_0x251768,_0x12ec64){const _0xa1f80c=_0xa1f8();return _0x1f16=function(_0x1f1654,_0x40cc6b){_0x1f1654=_0x1f1654-0x89;let _0x58b29e=_0xa1f80c[_0x1f1654];return _0x58b29e;},_0x1f16(_0x251768,_0x12ec64);}import{AIRequestError as _0x26a680}from'./aiadapter.js';import{BedrockRuntimeClient as _0x34cb9c,InvokeModelCommand as _0x184a08,InvokeModelWithResponseStreamCommand as _0x3d906c}from'@aws-sdk/client-bedrock-runtime';import{getTranslation as _0x1e889c}from'../utils/common-translations.js';export class AWSTextAdapter extends _0x29e37d{[_0x235c42(0xb4)];[_0x235c42(0x8a)];[_0x235c42(0xa8)];[_0x235c42(0xc4)];static get[_0x235c42(0x96)](){const _0x18d24c=_0x235c42;return _0x18d24c(0xb1);}constructor(_0x3f7e79){const _0xf63340=_0x235c42;super(_0x3f7e79),_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x9b)](_0xf63340(0xa3))||_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x99)](_0xf63340(0xa3),{'model':_0xf63340(0xd2),'max_tokens_to_sample':0x7d0,'temperature':0x1,'top_p':0x1,'top_k':0xfa,'anthropic_version':_0xf63340(0xa1),'stream':!0x0}),this[_0xf63340(0xb4)]=_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x9b)](_0xf63340(0xb7)),this[_0xf63340(0xa8)]=_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x9b)](_0xf63340(0x9a)),this[_0xf63340(0x8a)]=_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x9b)](_0xf63340(0xc7)),this[_0xf63340(0xc4)]=_0x3f7e79[_0xf63340(0xae)][_0xf63340(0x9b)](_0xf63340(0xa3));}async[_0x235c42(0xc1)]({query:_0x134867,context:_0x5f5176,onData:_0x5de6d8,actionId:_0x2ae059}){const _0x5b3ce6=_0x235c42,{model:_0x20782a,stream:_0x28a476,..._0xbbf463}=await this[_0x5b3ce6(0x92)](this[_0x5b3ce6(0xc4)],_0x2ae059),_0x18fb06={'prompt':await this[_0x5b3ce6(0x95)](_0x134867,_0x5f5176,_0x20782a,_0x2ae059),..._0xbbf463};this[_0x5b3ce6(0xb4)]?await this[_0x5b3ce6(0x9c)](_0x18fb06,_0x20782a,_0x28a476,_0x5de6d8,_0x2ae059):await this[_0x5b3ce6(0xb2)](_0x18fb06,_0x20782a,_0x28a476,_0x5de6d8);}async[_0x235c42(0x95)](_0x2767d4,_0x2ce977,_0x17fdfa,_0x25b227){const _0x502108=_0x235c42;let _0x55d310,_0x64ff52;return _0x2ce977?(_0x55d310=_0x502108(0x8c),_0x64ff52=_0x502108(0xa0)+_0x2767d4+_0x502108(0xd5)+_0x2ce977):(_0x55d310=_0x502108(0x89),_0x64ff52=_0x2767d4),_0x502108(0x9d)==this[_0x502108(0xad)](_0x17fdfa)?_0x502108(0xa2)+_0x55d310+_0x502108(0x93)+_0x64ff52+_0x502108(0xaa):_0x502108(0xd0)+_0x55d310+'\x0a'+_0x64ff52+_0x502108(0xd3);}[_0x235c42(0xad)](_0x4f0dc1){const _0x3803ed=_0x235c42;if(/^anthropic\.claude/[_0x3803ed(0xb5)](_0x4f0dc1))return _0x3803ed(0x98);if(/^ai21\.j2/[_0x3803ed(0xb5)](_0x4f0dc1))return _0x3803ed(0xcf);if(/^cohere\.command/[_0x3803ed(0xb5)](_0x4f0dc1))return _0x3803ed(0xd6);if(/^meta\.llama/[_0x3803ed(0xb5)](_0x4f0dc1))return _0x3803ed(0x9d);throw new _0x26a680(_0x1e889c(this[_0x3803ed(0xa9)][_0x3803ed(0x94)],_0x3803ed(0x8d),_0x4f0dc1));}async[_0x235c42(0x9c)](_0x464767,_0x656087,_0x13b8df,_0x9ba227,_0x2e9bbf){const _0x2e7218=_0x235c42,_0x409104={'method':_0x2e7218(0xc2),'headers':await this[_0x2e7218(0xb0)](this[_0x2e7218(0x8a)],_0x2e9bbf),'body':JSON[_0x2e7218(0xbf)]({..._0x464767,'model':_0x656087,'stream':_0x13b8df}),'signal':this[_0x2e7218(0xa6)][_0x2e7218(0xcd)]},_0x29e6bf=await fetch(this[_0x2e7218(0xb4)],_0x409104);_0x13b8df?await this[_0x2e7218(0xd7)](_0x29e6bf,_0x656087,_0x9ba227):await this[_0x2e7218(0xc3)](_0x29e6bf,_0x656087,_0x9ba227);}async[_0x235c42(0xb2)](_0x5dca66,_0x4c0f37,_0x99e432,_0x509bb5){const _0x4d6245=_0x235c42,_0x26fb0c=new _0x34cb9c(this[_0x4d6245(0xa8)]),_0x5f2dd4={'body':JSON[_0x4d6245(0xbf)](_0x5dca66),'contentType':_0x4d6245(0xc6),'accept':_0x4d6245(0xc6),'modelId':_0x4c0f37};let _0x3dbf8d;if(_0x99e432){const _0x13048e=new _0x3d906c(_0x5f2dd4);_0x3dbf8d=await _0x26fb0c[_0x4d6245(0x9e)](_0x13048e,{'abortSignal':this[_0x4d6245(0xa6)][_0x4d6245(0xcd)]}),await this[_0x4d6245(0xac)](_0x3dbf8d,_0x4c0f37,_0x509bb5);}else{const _0x3e339f=new _0x184a08(_0x5f2dd4);_0x3dbf8d=await _0x26fb0c[_0x4d6245(0x9e)](_0x3e339f,{'abortSignal':this[_0x4d6245(0xa6)][_0x4d6245(0xcd)]}),await this[_0x4d6245(0xc3)](_0x3dbf8d,_0x4c0f37,_0x509bb5);}}async[_0x235c42(0xac)](_0x69bde3,_0x2813a6,_0x4cf786){const _0x4126f8=_0x235c42,_0x41a338=_0x69bde3[_0x4126f8(0xaf)],_0x2ac2e4=new TextDecoder(_0x4126f8(0xba));let _0xa6abe2='';for await(const _0x3aa80f of _0x41a338)if(_0x3aa80f[_0x4126f8(0x90)]){const _0x1a5a5b=_0x2ac2e4[_0x4126f8(0xc0)](_0x3aa80f[_0x4126f8(0x90)][_0x4126f8(0xd1)]),_0x82058a=JSON[_0x4126f8(0xbb)](_0x1a5a5b);_0xa6abe2+=this[_0x4126f8(0xc8)](_0x82058a,_0x2813a6),_0x4cf786(_0xa6abe2);}return Promise[_0x4126f8(0xcc)]();}async[_0x235c42(0xd7)](_0x17fc09,_0x5c4501,_0x3b88f9){const _0x12f5a0=_0x235c42,_0x4e4a9e=_0x17fc09[_0x12f5a0(0xaf)],_0x574e8e=new TextDecoder(_0x12f5a0(0xba)),_0x4db6cc=_0x4e4a9e[_0x12f5a0(0xbd)]();let _0x57e3ba='',_0x3d62c9='',_0x234b8f=!0x1;for(;!_0x234b8f;){const {done:_0x3fb428,value:_0x1fdf76}=await _0x4db6cc[_0x12f5a0(0xa7)]();if(_0x234b8f=_0x3fb428,_0x234b8f)break;const _0x20348=(_0x57e3ba+_0x574e8e[_0x12f5a0(0xc0)](_0x1fdf76))[_0x12f5a0(0x8f)]('\x0a')[_0x12f5a0(0x9f)](_0x5b274b=>{const _0x2b5f8b=_0x12f5a0;try{return _0x57e3ba='',JSON[_0x2b5f8b(0xbb)](_0x5b274b);}catch{return _0x57e3ba=_0x5b274b,null;}})[_0x12f5a0(0x8e)](_0x60a712=>null!==_0x60a712);_0x20348[_0x12f5a0(0xd4)]&&(_0x3d62c9+=_0x20348[_0x12f5a0(0x9f)](_0x296bc8=>this[_0x12f5a0(0xc8)](_0x296bc8,_0x5c4501))[_0x12f5a0(0xb3)](''),_0x3b88f9(_0x3d62c9));}return Promise[_0x12f5a0(0xcc)]();}async[_0x235c42(0xc3)](_0x1f393d,_0x3e1841,_0x189189){const _0x168524=_0x235c42;let _0x563ba9;return _0x563ba9=_0x1f393d instanceof Response?await _0x1f393d[_0x168524(0xc5)]():JSON[_0x168524(0xbb)](new TextDecoder(_0x168524(0xba))[_0x168524(0xc0)](_0x1f393d[_0x168524(0xaf)])),(_0x189189(this[_0x168524(0xc8)](_0x563ba9,_0x3e1841)),Promise[_0x168524(0xcc)]());}[_0x235c42(0xc8)](_0x2a5e2b,_0x1897fb){const _0x1eae54=_0x235c42;switch(this[_0x1eae54(0xad)](_0x1897fb)){case _0x1eae54(0x98):return _0x2a5e2b[_0x1eae54(0xb9)];case _0x1eae54(0xcf):return _0x2a5e2b[_0x1eae54(0xa5)][0x0][_0x1eae54(0x97)][_0x1eae54(0xbe)];case _0x1eae54(0xd6):return _0x2a5e2b[_0x1eae54(0xb6)][0x0][_0x1eae54(0xbe)];case _0x1eae54(0x9d):return _0x2a5e2b[_0x1eae54(0xab)];}}}