UNPKG

@ckeditor/ckeditor5-ai

Version:

AI Assistant feature for CKEditor 5.

23 lines 10.1 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 _0x3ebbfd=_0x250f;(function(_0x54dda5,_0x428da7){const _0x308e57=_0x250f,_0x302e8f=_0x54dda5();while(!![]){try{const _0x2d379e=-parseInt(_0x308e57(0xe2))/0x1+-parseInt(_0x308e57(0x10c))/0x2+parseInt(_0x308e57(0x103))/0x3*(-parseInt(_0x308e57(0xe1))/0x4)+parseInt(_0x308e57(0xc9))/0x5+parseInt(_0x308e57(0x10e))/0x6+-parseInt(_0x308e57(0xfb))/0x7*(parseInt(_0x308e57(0x109))/0x8)+parseInt(_0x308e57(0xc1))/0x9;if(_0x2d379e===_0x428da7)break;else _0x302e8f['push'](_0x302e8f['shift']());}catch(_0x576f75){_0x302e8f['push'](_0x302e8f['shift']());}}}(_0x62d9,0x39629));import{default as _0x1ae379}from'./aitextadapter.js';function _0x62d9(){const _0x22bda5=['948918zmuOJU','utf-8','resolve','parse','_bedrockClientConfig','7385598pXUUma','\x0a[/INST]','_prepareRequestParameters','_readStreamableResponse','read','length','config','anthropic.claude','1652260qsrTPw','\x0a<</SYS>>\x0a[INST]\x0a','send','ai.aws.bedrockClientConfig','application/json','ai21.j2','toString','define','locale','abortController','get','editor','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.','test','pluginName','_getGeneratedText','_readAsyncIterableResponse','completions','ai.aws.apiUrl','from','data','_processProxyRequest','generation','_requestHeaders','4804vFEiZC','396940GzYBip','generations','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','AWSTextAdapter','join','_readStaticResponse','utf8','getReader','chunk','Instruction:\x0a','split','stringify','_apiUrl','bedrock-2023-05-31','_requestParameters','<<SYS>>\x0a','AI_ERROR_UNSUPPORTED_MODEL','sendRequest','anthropic.claude-v2','filter','map','completion','text','ai.aws.requestParameters','\x0a\x0aAssistant:','91BzFgNW','meta.llama','bytes','_processAWSRequest','body','getModelFamily','Human:\x0a','ai.aws.requestHeaders','732NemJDh','_prepareRequestHeaders','cohere.command','decode','signal','POST','42552mLFDHB','preparePrompt','json','630094LhwKXC','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.'];_0x62d9=function(){return _0x22bda5;};return _0x62d9();}import{AIRequestError as _0x25e855}from'./aiadapter.js';function _0x250f(_0x5baaf9,_0x37d048){const _0x62d966=_0x62d9();return _0x250f=function(_0x250fb2,_0x4d4aae){_0x250fb2=_0x250fb2-0xc1;let _0x3829fc=_0x62d966[_0x250fb2];return _0x3829fc;},_0x250f(_0x5baaf9,_0x37d048);}import{BedrockRuntimeClient as _0x250c2a,InvokeModelCommand as _0x3323bb,InvokeModelWithResponseStreamCommand as _0x4790bc}from'@aws-sdk/client-bedrock-runtime';import{getTranslation as _0x1512ec}from'../utils/common-translations.js';export default class D extends _0x1ae379{[_0x3ebbfd(0xee)];[_0x3ebbfd(0xe0)];[_0x3ebbfd(0x112)];[_0x3ebbfd(0xf0)];static get[_0x3ebbfd(0xd7)](){const _0x3f8768=_0x3ebbfd;return _0x3f8768(0xe5);}constructor(_0x503f17){const _0x5bc7de=_0x3ebbfd;super(_0x503f17),_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd3)](_0x5bc7de(0xf9))||_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd0)](_0x5bc7de(0xf9),{'model':_0x5bc7de(0xf4),'max_tokens_to_sample':0x7d0,'temperature':0x1,'top_p':0x1,'top_k':0xfa,'anthropic_version':_0x5bc7de(0xef),'stream':!0x0}),this[_0x5bc7de(0xee)]=_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd3)](_0x5bc7de(0xdb)),this[_0x5bc7de(0x112)]=_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd3)](_0x5bc7de(0xcc)),this[_0x5bc7de(0xe0)]=_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd3)](_0x5bc7de(0x102)),this[_0x5bc7de(0xf0)]=_0x503f17[_0x5bc7de(0xc7)][_0x5bc7de(0xd3)](_0x5bc7de(0xf9));}async[_0x3ebbfd(0xf3)]({query:_0x5be987,context:_0x2e18a1,onData:_0x550a45,actionId:_0x35c841}){const _0x3d52f9=_0x3ebbfd,{model:_0x5642e7,stream:_0x1455b0,..._0x156e2b}=await this[_0x3d52f9(0xc3)](this[_0x3d52f9(0xf0)],_0x35c841),_0x5c6ff4={'prompt':await this[_0x3d52f9(0x10a)](_0x5be987,_0x2e18a1,_0x5642e7,_0x35c841),..._0x156e2b};this[_0x3d52f9(0xee)]?await this[_0x3d52f9(0xde)](_0x5c6ff4,_0x5642e7,_0x1455b0,_0x550a45,_0x35c841):await this[_0x3d52f9(0xfe)](_0x5c6ff4,_0x5642e7,_0x1455b0,_0x550a45);}async[_0x3ebbfd(0x10a)](_0x4cb5fd,_0x54f56f,_0xb359fd,_0x558695){const _0x2fe9cc=_0x3ebbfd;let _0x245735,_0x38487c;return _0x54f56f?(_0x245735=_0x2fe9cc(0xd5),_0x38487c=_0x2fe9cc(0xeb)+_0x4cb5fd+_0x2fe9cc(0xe4)+_0x54f56f):(_0x245735=_0x2fe9cc(0x10d),_0x38487c=_0x4cb5fd),_0x2fe9cc(0xfc)==this[_0x2fe9cc(0x100)](_0xb359fd)?_0x2fe9cc(0xf1)+_0x245735+_0x2fe9cc(0xca)+_0x38487c+_0x2fe9cc(0xc2):_0x2fe9cc(0x101)+_0x245735+'\x0a'+_0x38487c+_0x2fe9cc(0xfa);}[_0x3ebbfd(0x100)](_0x5aed4f){const _0x5b65f2=_0x3ebbfd;if(/^anthropic\.claude/[_0x5b65f2(0xd6)](_0x5aed4f))return _0x5b65f2(0xc8);if(/^ai21\.j2/[_0x5b65f2(0xd6)](_0x5aed4f))return _0x5b65f2(0xce);if(/^cohere\.command/[_0x5b65f2(0xd6)](_0x5aed4f))return _0x5b65f2(0x105);if(/^meta\.llama/[_0x5b65f2(0xd6)](_0x5aed4f))return _0x5b65f2(0xfc);throw new _0x25e855(_0x1512ec(this[_0x5b65f2(0xd4)][_0x5b65f2(0xd1)],_0x5b65f2(0xf2),_0x5aed4f));}async[_0x3ebbfd(0xde)](_0x1cb8ed,_0x53d871,_0x4ef16e,_0x2a2c41,_0x5c4537){const _0x104d14=_0x3ebbfd,_0x5452f6={'method':_0x104d14(0x108),'headers':await this[_0x104d14(0x104)](this[_0x104d14(0xe0)],_0x5c4537),'body':JSON[_0x104d14(0xed)]({..._0x1cb8ed,'model':_0x53d871,'stream':_0x4ef16e}),'signal':this[_0x104d14(0xd2)][_0x104d14(0x107)]},_0x18194a=await fetch(this[_0x104d14(0xee)],_0x5452f6);_0x4ef16e?await this[_0x104d14(0xc4)](_0x18194a,_0x53d871,_0x2a2c41):await this[_0x104d14(0xe7)](_0x18194a,_0x53d871,_0x2a2c41);}async[_0x3ebbfd(0xfe)](_0x29d7f1,_0x333e57,_0x57fae5,_0x489252){const _0x461abd=_0x3ebbfd,_0x23a001=new _0x250c2a(this[_0x461abd(0x112)]),_0x5e37ea={'body':JSON[_0x461abd(0xed)](_0x29d7f1),'contentType':_0x461abd(0xcd),'accept':_0x461abd(0xcd),'modelId':_0x333e57};let _0xb4548;if(_0x57fae5){const _0x944940=new _0x4790bc(_0x5e37ea);_0xb4548=await _0x23a001[_0x461abd(0xcb)](_0x944940,{'abortSignal':this[_0x461abd(0xd2)][_0x461abd(0x107)]}),await this[_0x461abd(0xd9)](_0xb4548,_0x333e57,_0x489252);}else{const _0x458fae=new _0x3323bb(_0x5e37ea);_0xb4548=await _0x23a001[_0x461abd(0xcb)](_0x458fae,{'abortSignal':this[_0x461abd(0xd2)][_0x461abd(0x107)]}),await this[_0x461abd(0xe7)](_0xb4548,_0x333e57,_0x489252);}}async[_0x3ebbfd(0xd9)](_0x487797,_0xe7b65d,_0x4b3895){const _0x33aa5d=_0x3ebbfd,_0x2595ef=_0x487797[_0x33aa5d(0xff)],_0x5e22bf=new TextDecoder(_0x33aa5d(0x10f));let _0x14c8d9='';for await(const _0xf8c71a of _0x2595ef)if(_0xf8c71a[_0x33aa5d(0xea)]){const _0x1b319e=_0x5e22bf[_0x33aa5d(0x106)](_0xf8c71a[_0x33aa5d(0xea)][_0x33aa5d(0xfd)]),_0x232e56=JSON[_0x33aa5d(0x111)](_0x1b319e);_0x14c8d9+=this[_0x33aa5d(0xd8)](_0x232e56,_0xe7b65d),_0x4b3895(_0x14c8d9);}return Promise[_0x33aa5d(0x110)]();}async[_0x3ebbfd(0xc4)](_0x323c89,_0x1ceaa7,_0x130fab){const _0x8f4c5e=_0x3ebbfd,_0x187c79=_0x323c89[_0x8f4c5e(0xff)],_0xc4eeb0=new TextDecoder(_0x8f4c5e(0x10f)),_0x1c3aed=_0x187c79[_0x8f4c5e(0xe9)]();let _0x4b20ba='',_0x4076b0='',_0x55e050=!0x1;for(;!_0x55e050;){const {done:_0x978adf,value:_0x226b92}=await _0x1c3aed[_0x8f4c5e(0xc5)]();if(_0x55e050=_0x978adf,_0x55e050)break;const _0x2e7d59=(_0x4b20ba+_0xc4eeb0[_0x8f4c5e(0x106)](_0x226b92))[_0x8f4c5e(0xec)]('\x0a')[_0x8f4c5e(0xf6)](_0x31eb32=>{const _0x513953=_0x8f4c5e;try{return _0x4b20ba='',JSON[_0x513953(0x111)](_0x31eb32);}catch{return _0x4b20ba=_0x31eb32,null;}})[_0x8f4c5e(0xf5)](_0x41ae59=>null!==_0x41ae59);_0x2e7d59[_0x8f4c5e(0xc6)]&&(_0x4076b0+=_0x2e7d59[_0x8f4c5e(0xf6)](_0x1594cf=>this[_0x8f4c5e(0xd8)](_0x1594cf,_0x1ceaa7))[_0x8f4c5e(0xe6)](''),_0x130fab(_0x4076b0));}return Promise[_0x8f4c5e(0x110)]();}async[_0x3ebbfd(0xe7)](_0x27cd37,_0x33a42e,_0x50a83f){const _0x50a89d=_0x3ebbfd;let _0x2f39da;return _0x2f39da=_0x27cd37 instanceof Response?await _0x27cd37[_0x50a89d(0x10b)]():JSON[_0x50a89d(0x111)](Buffer[_0x50a89d(0xdc)](_0x27cd37[_0x50a89d(0xff)])[_0x50a89d(0xcf)](_0x50a89d(0xe8))),(_0x50a83f(this[_0x50a89d(0xd8)](_0x2f39da,_0x33a42e)),Promise[_0x50a89d(0x110)]());}[_0x3ebbfd(0xd8)](_0x3b624a,_0x44f9d2){const _0x5402db=_0x3ebbfd;switch(this[_0x5402db(0x100)](_0x44f9d2)){case _0x5402db(0xc8):return _0x3b624a[_0x5402db(0xf7)];case _0x5402db(0xce):return _0x3b624a[_0x5402db(0xda)][0x0][_0x5402db(0xdd)][_0x5402db(0xf8)];case _0x5402db(0x105):return _0x3b624a[_0x5402db(0xe3)][0x0][_0x5402db(0xf8)];case _0x5402db(0xfc):return _0x3b624a[_0x5402db(0xdf)];}}}