UNPKG

@ckeditor/ckeditor5-ai

Version:

AI Assistant feature for CKEditor 5.

23 lines 10.2 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 _0x2a3ade=_0x4d7e;(function(_0x3bb815,_0x2bc8d2){const _0x28e69e=_0x4d7e,_0x4457b0=_0x3bb815();while(!![]){try{const _0x29fc9d=-parseInt(_0x28e69e(0x1f2))/0x1+-parseInt(_0x28e69e(0x1da))/0x2+-parseInt(_0x28e69e(0x1e3))/0x3*(parseInt(_0x28e69e(0x1eb))/0x4)+-parseInt(_0x28e69e(0x1d7))/0x5*(-parseInt(_0x28e69e(0x1a7))/0x6)+parseInt(_0x28e69e(0x1c2))/0x7+-parseInt(_0x28e69e(0x1cd))/0x8+parseInt(_0x28e69e(0x1ae))/0x9;if(_0x29fc9d===_0x2bc8d2)break;else _0x4457b0['push'](_0x4457b0['shift']());}catch(_0x221a96){_0x4457b0['push'](_0x4457b0['shift']());}}}(_0x1fd5,0x2e976));import{default as _0x21c15f}from'./aitextadapter.js';function _0x1fd5(){const _0x577ad0=['resolve','pluginName','_readStreamableResponse','_processAWSRequest','meta.llama','utf-8','test','map','getModelFamily','text','bedrock-2023-05-31','_processProxyRequest','AI_ERROR_UNSUPPORTED_MODEL','anthropic.claude','_requestParameters','bytes','parse','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.','1822534baBoBJ','_readAsyncIterableResponse','data','read','POST','application/json','_requestHeaders','AWSTextAdapter','ai.aws.requestParameters','length','utf8','1234920qTyfzh','ai21.j2','_getGeneratedText','json','completions','_prepareRequestHeaders','\x0a<</SYS>>\x0a[INST]\x0a','_apiUrl','generation','config','1137110oqCGTW','abortController','<<SYS>>\x0a','93086QDptwv','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.','chunk','_prepareRequestParameters','stringify','getReader','body','Instruction:\x0a','filter','12TfyeEm','join','send','\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a','split','cohere.command','decode','toString','289576VkbqCD','ai.aws.apiUrl','editor','sendRequest','completion','\x0a\x0aAssistant:','define','340223frCGnq','locale','anthropic.claude-v2','ai.aws.bedrockClientConfig','\x0a[/INST]','get','ai.aws.requestHeaders','6jQNaWs','from','preparePrompt','_readStaticResponse','Human:\x0a','generations','signal','4803849GGlKlu','_bedrockClientConfig'];_0x1fd5=function(){return _0x577ad0;};return _0x1fd5();}import{AIRequestError as _0x1480d6}from'./aiadapter.js';function _0x4d7e(_0x176cc0,_0xd497a8){const _0x1fd573=_0x1fd5();return _0x4d7e=function(_0x4d7ee3,_0x44ae7e){_0x4d7ee3=_0x4d7ee3-0x1a7;let _0x29ce9c=_0x1fd573[_0x4d7ee3];return _0x29ce9c;},_0x4d7e(_0x176cc0,_0xd497a8);}import{BedrockRuntimeClient as _0x35daeb,InvokeModelCommand as _0x121ddc,InvokeModelWithResponseStreamCommand as _0x3ce519}from'@aws-sdk/client-bedrock-runtime';import{getTranslation as _0x8e2609}from'../utils/common-translations.js';export default class O extends _0x21c15f{static get[_0x2a3ade(0x1b1)](){const _0x9e6d5e=_0x2a3ade;return _0x9e6d5e(0x1c9);}constructor(_0x3b36ef){const _0x272ef1=_0x2a3ade;super(_0x3b36ef),_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f7)](_0x272ef1(0x1ca))||_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f1)](_0x272ef1(0x1ca),{'model':_0x272ef1(0x1f4),'max_tokens_to_sample':0x7d0,'temperature':0x1,'top_p':0x1,'top_k':0xfa,'anthropic_version':_0x272ef1(0x1ba),'stream':!0x0}),this[_0x272ef1(0x1d4)]=_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f7)](_0x272ef1(0x1ec)),this[_0x272ef1(0x1af)]=_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f7)](_0x272ef1(0x1f5)),this[_0x272ef1(0x1c8)]=_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f7)](_0x272ef1(0x1f8)),this[_0x272ef1(0x1be)]=_0x3b36ef[_0x272ef1(0x1d6)][_0x272ef1(0x1f7)](_0x272ef1(0x1ca));}async[_0x2a3ade(0x1ee)]({query:_0x807eea,context:_0xc56e21,onData:_0x52e185,actionId:_0x34a011}){const _0x148eeb=_0x2a3ade,{model:_0x4863de,stream:_0x2a251b,..._0x2fb168}=await this[_0x148eeb(0x1dd)](this[_0x148eeb(0x1be)],_0x34a011),_0x50514e={'prompt':await this[_0x148eeb(0x1a9)](_0x807eea,_0xc56e21,_0x4863de,_0x34a011),..._0x2fb168};this[_0x148eeb(0x1d4)]?await this[_0x148eeb(0x1bb)](_0x50514e,_0x4863de,_0x2a251b,_0x52e185,_0x34a011):await this[_0x148eeb(0x1b3)](_0x50514e,_0x4863de,_0x2a251b,_0x52e185);}async[_0x2a3ade(0x1a9)](_0x1819dd,_0x43687f,_0x3bf1a0,_0x261023){const _0x63302e=_0x2a3ade;let _0x482194,_0x235f29;return _0x43687f?(_0x482194=_0x63302e(0x1c1),_0x235f29=_0x63302e(0x1e1)+_0x1819dd+_0x63302e(0x1e6)+_0x43687f):(_0x482194=_0x63302e(0x1db),_0x235f29=_0x1819dd),_0x63302e(0x1b4)==this[_0x63302e(0x1b8)](_0x3bf1a0)?_0x63302e(0x1d9)+_0x482194+_0x63302e(0x1d3)+_0x235f29+_0x63302e(0x1f6):_0x63302e(0x1ab)+_0x482194+'\x0a'+_0x235f29+_0x63302e(0x1f0);}[_0x2a3ade(0x1b8)](_0x5bf964){const _0x1abe93=_0x2a3ade;if(/^anthropic\.claude/[_0x1abe93(0x1b6)](_0x5bf964))return _0x1abe93(0x1bd);if(/^ai21\.j2/[_0x1abe93(0x1b6)](_0x5bf964))return _0x1abe93(0x1ce);if(/^cohere\.command/[_0x1abe93(0x1b6)](_0x5bf964))return _0x1abe93(0x1e8);if(/^meta\.llama/[_0x1abe93(0x1b6)](_0x5bf964))return _0x1abe93(0x1b4);throw new _0x1480d6(_0x8e2609(this[_0x1abe93(0x1ed)][_0x1abe93(0x1f3)],_0x1abe93(0x1bc),_0x5bf964));}async[_0x2a3ade(0x1bb)](_0x513469,_0x5ce7dc,_0x3230db,_0x1c8741,_0x373af9){const _0x54301d=_0x2a3ade,_0xe689a9={'method':_0x54301d(0x1c6),'headers':await this[_0x54301d(0x1d2)](this[_0x54301d(0x1c8)],_0x373af9),'body':JSON[_0x54301d(0x1de)]({..._0x513469,'model':_0x5ce7dc,'stream':_0x3230db}),'signal':this[_0x54301d(0x1d8)][_0x54301d(0x1ad)]},_0x12b679=await fetch(this[_0x54301d(0x1d4)],_0xe689a9);_0x3230db?await this[_0x54301d(0x1b2)](_0x12b679,_0x5ce7dc,_0x1c8741):await this[_0x54301d(0x1aa)](_0x12b679,_0x5ce7dc,_0x1c8741);}async[_0x2a3ade(0x1b3)](_0x1a53b4,_0x10f6b6,_0x3ddba8,_0x6548ad){const _0x1f66e4=_0x2a3ade,_0x2f290a=new _0x35daeb(this[_0x1f66e4(0x1af)]),_0x53420a={'body':JSON[_0x1f66e4(0x1de)](_0x1a53b4),'contentType':_0x1f66e4(0x1c7),'accept':_0x1f66e4(0x1c7),'modelId':_0x10f6b6};let _0x3245fe;if(_0x3ddba8){const _0x53aeff=new _0x3ce519(_0x53420a);_0x3245fe=await _0x2f290a[_0x1f66e4(0x1e5)](_0x53aeff,{'abortSignal':this[_0x1f66e4(0x1d8)][_0x1f66e4(0x1ad)]}),await this[_0x1f66e4(0x1c3)](_0x3245fe,_0x10f6b6,_0x6548ad);}else{const _0x446f3c=new _0x121ddc(_0x53420a);_0x3245fe=await _0x2f290a[_0x1f66e4(0x1e5)](_0x446f3c,{'abortSignal':this[_0x1f66e4(0x1d8)][_0x1f66e4(0x1ad)]}),await this[_0x1f66e4(0x1aa)](_0x3245fe,_0x10f6b6,_0x6548ad);}}async[_0x2a3ade(0x1c3)](_0x2da61f,_0x2edb96,_0x13662b){const _0x2e36a7=_0x2a3ade,_0x3b2ff1=_0x2da61f[_0x2e36a7(0x1e0)],_0x4049ed=new TextDecoder(_0x2e36a7(0x1b5));let _0x5ac4f0='';for await(const _0x21cd3d of _0x3b2ff1)if(_0x21cd3d[_0x2e36a7(0x1dc)]){const _0x4e76fd=_0x4049ed[_0x2e36a7(0x1e9)](_0x21cd3d[_0x2e36a7(0x1dc)][_0x2e36a7(0x1bf)]),_0x4e29a=JSON[_0x2e36a7(0x1c0)](_0x4e76fd);_0x5ac4f0+=this[_0x2e36a7(0x1cf)](_0x4e29a,_0x2edb96),_0x13662b(_0x5ac4f0);}return Promise[_0x2e36a7(0x1b0)]();}async[_0x2a3ade(0x1b2)](_0x213e94,_0x158c65,_0x12f761){const _0xd691af=_0x2a3ade,_0x161865=_0x213e94[_0xd691af(0x1e0)],_0x5aacc7=new TextDecoder(_0xd691af(0x1b5)),_0x13e534=_0x161865[_0xd691af(0x1df)]();let _0x235ef4='',_0x1e1aff='',_0x58ba58=!0x1;for(;!_0x58ba58;){const {done:_0xf60e6d,value:_0x43bb2a}=await _0x13e534[_0xd691af(0x1c5)]();if(_0x58ba58=_0xf60e6d,_0x58ba58)break;const _0xe477ed=(_0x235ef4+_0x5aacc7[_0xd691af(0x1e9)](_0x43bb2a))[_0xd691af(0x1e7)]('\x0a')[_0xd691af(0x1b7)](_0x5e0321=>{const _0x473a83=_0xd691af;try{return _0x235ef4='',JSON[_0x473a83(0x1c0)](_0x5e0321);}catch(_0x573086){return _0x235ef4=_0x5e0321,null;}})[_0xd691af(0x1e2)](_0x47295e=>null!==_0x47295e);_0xe477ed[_0xd691af(0x1cb)]&&(_0x1e1aff+=_0xe477ed[_0xd691af(0x1b7)](_0x377257=>this[_0xd691af(0x1cf)](_0x377257,_0x158c65))[_0xd691af(0x1e4)](''),_0x12f761(_0x1e1aff));}return Promise[_0xd691af(0x1b0)]();}async[_0x2a3ade(0x1aa)](_0x2b492f,_0x2b1d3c,_0x4df218){const _0x1ae1de=_0x2a3ade;let _0x2dc3b7;return _0x2dc3b7=_0x2b492f instanceof Response?await _0x2b492f[_0x1ae1de(0x1d0)]():JSON[_0x1ae1de(0x1c0)](Buffer[_0x1ae1de(0x1a8)](_0x2b492f[_0x1ae1de(0x1e0)])[_0x1ae1de(0x1ea)](_0x1ae1de(0x1cc))),(_0x4df218(this[_0x1ae1de(0x1cf)](_0x2dc3b7,_0x2b1d3c)),Promise[_0x1ae1de(0x1b0)]());}[_0x2a3ade(0x1cf)](_0x594ba8,_0x3b80a9){const _0x306efc=_0x2a3ade;switch(this[_0x306efc(0x1b8)](_0x3b80a9)){case _0x306efc(0x1bd):return _0x594ba8[_0x306efc(0x1ef)];case _0x306efc(0x1ce):return _0x594ba8[_0x306efc(0x1d1)][0x0][_0x306efc(0x1c4)][_0x306efc(0x1b9)];case _0x306efc(0x1e8):return _0x594ba8[_0x306efc(0x1ac)][0x0][_0x306efc(0x1b9)];case _0x306efc(0x1b4):return _0x594ba8[_0x306efc(0x1d5)];}}}