@dnotifier-realtime/dnotifier 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dnotifier.js +1 -1
- package/dist/cjs/providers/openai.js +1 -1
- package/dist/cjs/transport/httpTransport.js +1 -1
- package/dist/cjs/transport/websocketTransport.js +1 -1
- package/dist/cjs/utils/buffer.js +1 -1
- package/dist/cjs/utils/frame.js +1 -1
- package/dist/cjs/utils/id.js +1 -1
- package/dist/cjs/utils/payload.js +1 -1
- package/dist/dnotifier.cjs +102 -98
- package/dist/dnotifier.d.ts +19 -10
- package/dist/dnotifier.d.ts.map +1 -1
- package/dist/dnotifier.js +1 -1
- package/dist/providers/openai.js +1 -1
- package/dist/transport/httpTransport.js +1 -1
- package/dist/transport/websocketTransport.js +1 -1
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/frame.js +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/payload.js +1 -1
- package/package.json +1 -1
package/dist/cjs/dnotifier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['DNotifier']=void 0x0;const httpTransport_js_1=require('./transport/httpTransport.js'),websocketTransport_js_1=require('./transport/websocketTransport.js'),id_js_1=require('./utils/id.js'),frame_js_1=require('./utils/frame.js'),payload_js_1=require('./utils/payload.js'),buffer_js_1=require('./utils/buffer.js'),openai_js_1=require('./providers/openai.js');class DNotifier{constructor({appId:
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['DNotifier']=void 0x0;const httpTransport_js_1=require('./transport/httpTransport.js'),websocketTransport_js_1=require('./transport/websocketTransport.js'),id_js_1=require('./utils/id.js'),frame_js_1=require('./utils/frame.js'),payload_js_1=require('./utils/payload.js'),buffer_js_1=require('./utils/buffer.js'),openai_js_1=require('./providers/openai.js');class DNotifier{constructor({appId:_0x31a71c,secret:_0x58b7fa,transport:_0x5cca27,userId:_0x1db143,onConnected:_0x6b0185,onMessage:_0x401e16,onDisconnected:_0x5c7086,WebSocketImpl:_0x14d66d}){if(!(_0x31a71c&&_0x58b7fa&&_0x5cca27&&_0x1db143))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0x31a71c,this['secret']=_0x58b7fa,this['userId']=_0x1db143,this['url']='wss://link.dchatter.com/ws',this['onConnectedCallback']=_0x6b0185||(()=>{}),this['onMessageCallback']=_0x401e16||(()=>{}),this['onDisconnectedCallback']=_0x5c7086||(()=>{}),this['isConnected']=!0x1,this['transport']='ws'===_0x5cca27?new websocketTransport_js_1['WebsocketTransport'](_0x14d66d):new httpTransport_js_1['HttpTransport']();}async['connect'](){const _0x2c1389=new httpTransport_js_1['HttpTransport']({'url':'https://link.dchatter.com/api/v1/sdk/auth'}),_0x16339c=await _0x2c1389['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0x16339c['_responseCode'])throw new Error('Authentication\x20Failed.');this['authToken']=_0x16339c['_responseData'],await this['transport']['connect'](this['url']);const _0x56fb49={'type':'text','code':0x65,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0xa12e16=(0x0,buffer_js_1['toUint8'])(JSON['stringify']({'token':this['authToken']})),_0x2cdfbd=(0x0,frame_js_1['framePacket'])(_0x56fb49,_0xa12e16);this['transport']['sendBinary'](_0x2cdfbd);let _0x3683c7=!0x1;this['transport']['on']('message',_0x7a07dc=>{try{const {metadata:_0x339cf8,data:_0x53807b}=_0x7a07dc;if(!_0x3683c7&&'102'===_0x339cf8['packet']['code']&&_0x339cf8['packet']['sender']['includes']((0x0,id_js_1['prefixId'])(this['appId'],this['userId'])))return _0x3683c7=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x3683c7&&this['onMessageCallback']({'metadata':{'sender':_0x339cf8['packet']['sender'],'timestamp':_0x339cf8['packet']['timestamp']},'payload':new payload_js_1['Payload'](_0x53807b)});}catch(_0x4a8fc7){console['error']('Packet\x20error:',_0x4a8fc7);}}),this['transport']['on']('close',({code:_0xc37a10,reason:_0x3920e3})=>{this['isConnected']&&(this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':_0xc37a10,'reason':_0x3920e3||'Disconnected'}));}),this['transport']['on']('error',_0x1c0f43=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x1c0f43?void 0x0:_0x1c0f43['message'])||'Transport\x20error'});});}['send']({senderId:_0x2df571,receiverId:_0x1049a7,receiverIds:_0x54600b,data:_0x280426}){if(!_0x2df571)throw new Error('senderId\x20required');if(!_0x1049a7&&!_0x54600b)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x45329e=null!=_0x54600b?_0x54600b:[_0x1049a7],_0x2499ca={'type':'text','code':0xc8,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x2df571),'receivers':_0x45329e['map'](_0x4c9611=>(0x0,id_js_1['prefixId'])(this['appId'],_0x4c9611)),'timestamp':Date['now'](),'token':this['authToken']},_0x21e7f0=(0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x280426)),_0x397064=(0x0,frame_js_1['framePacket'])(_0x2499ca,_0x21e7f0);this['transport']['sendBinary'](_0x397064);}['sendBinary']({senderId:_0x3f74ae,receiverIds:_0x4a754f,buffer:_0x2e80c3,type:_0x3e4529='binary'}){if(!_0x3f74ae)throw new Error('senderId\x20required');if(!_0x2e80c3)throw new Error('buffer\x20is\x20required');const _0x3cfc91={'type':_0x3e4529,'code':0xca,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x3f74ae),'receivers':_0x4a754f['map'](_0x38f245=>(0x0,id_js_1['prefixId'])(this['appId'],_0x38f245)),'timestamp':Date['now'](),'token':this['authToken']},_0xb880ba=(0x0,frame_js_1['framePacket'])(_0x3cfc91,_0x2e80c3);this['transport']['sendBinary'](_0xb880ba);}async['sendWithOpenAI']({senderId:_0x4848cd,message:_0x182795,openaiApiKey:_0x470eaa,model:_0x46b3e9,baseUrl:_0x48f719}){if(!_0x4848cd)throw new Error('senderId\x20is\x20required');if(!_0x182795)throw new Error('message\x20is\x20required');if(!_0x470eaa)throw new Error('openaiApiKey\x20is\x20required');const {content:_0x129ac1}=await(0x0,openai_js_1['chatStream'])({'apiKey':_0x470eaa,'model':_0x46b3e9,'messages':_0x182795,'baseUrl':_0x48f719}),_0x231d8f={'type':'openai','content':_0x129ac1,'ts':Date['now']()};return this['onMessageCallback']({'metadata':{'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x4848cd),'timestamp':Date['now']()},'payload':new payload_js_1['Payload']((0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x231d8f)))}),{'content':_0x129ac1};}}exports['DNotifier']=DNotifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['chat']=chat,exports['chatStream']=chatStream;const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['chat']=chat,exports['chatStream']=chatStream;const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(_0x344d1c){if('string'==typeof _0x344d1c)return[{'role':'user','content':_0x344d1c}];if(Array['isArray'](_0x344d1c)&&_0x344d1c['length']>0x0)return _0x344d1c['map'](_0x3ef4bc=>({'role':_0x3ef4bc['role']||'user','content':'string'==typeof _0x3ef4bc['content']?_0x3ef4bc['content']:String(_0x3ef4bc['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}async function chat(_0x2dfd42){var _0x21dc28,_0x48663b,_0x5bbf86,_0x5da3c8,_0x496d23,_0x3ac763;const {apiKey:_0x48b491,model:_0x2fc991=DEFAULT_MODEL,messages:_0x2ccc22,baseUrl:_0x41ce1b=DEFAULT_BASE_URL}=_0x2dfd42;if(!_0x48b491||!_0x2ccc22)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x22105d=_0x41ce1b['replace'](/\/$/,'')+'/v1/chat/completions',_0x486c0a={'model':_0x2fc991,'messages':normalizeMessages(_0x2ccc22),'stream':!0x1},_0x105818=await fetch(_0x22105d,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x48b491},'body':JSON['stringify'](_0x486c0a)}),_0x5cfb9e=await _0x105818['json']();if(!_0x105818['ok']){const _0x3d74ec=new Error((null===(_0x21dc28=null==_0x5cfb9e?void 0x0:_0x5cfb9e['error'])||void 0x0===_0x21dc28?void 0x0:_0x21dc28['message'])||'OpenAI\x20API\x20error:\x20'+_0x105818['status']);throw _0x3d74ec['status']=_0x105818['status'],_0x3d74ec['code']=null===(_0x48663b=null==_0x5cfb9e?void 0x0:_0x5cfb9e['error'])||void 0x0===_0x48663b?void 0x0:_0x48663b['code'],_0x3d74ec;}return{'content':null!==(_0x3ac763=null===(_0x496d23=null===(_0x5da3c8=null===(_0x5bbf86=null==_0x5cfb9e?void 0x0:_0x5cfb9e['choices'])||void 0x0===_0x5bbf86?void 0x0:_0x5bbf86[0x0])||void 0x0===_0x5da3c8?void 0x0:_0x5da3c8['message'])||void 0x0===_0x496d23?void 0x0:_0x496d23['content'])&&void 0x0!==_0x3ac763?_0x3ac763:'','usage':null==_0x5cfb9e?void 0x0:_0x5cfb9e['usage'],'raw':_0x5cfb9e};}async function chatStream(_0x673ec4){var _0x343a9e,_0xc624ef,_0x18ab4b,_0xdafd45,_0x412b93;const {apiKey:_0x56bc97,model:_0x4582f5=DEFAULT_MODEL,messages:_0x5bdb68,baseUrl:_0x4a3437=DEFAULT_BASE_URL,onChunk:_0x5d361b}=_0x673ec4;if(!_0x56bc97||!_0x5bdb68)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x4a0845=_0x4a3437['replace'](/\/$/,'')+'/v1/chat/completions',_0x13e79d={'model':_0x4582f5,'messages':normalizeMessages(_0x5bdb68),'stream':!0x0},_0x5ca7ab=await fetch(_0x4a0845,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x56bc97},'body':JSON['stringify'](_0x13e79d)});if(!_0x5ca7ab['ok']){const _0x1d0f29=await _0x5ca7ab['json']()['catch'](()=>({})),_0x1d79c3=new Error((null===(_0x343a9e=null==_0x1d0f29?void 0x0:_0x1d0f29['error'])||void 0x0===_0x343a9e?void 0x0:_0x343a9e['message'])||'OpenAI\x20API\x20error:\x20'+_0x5ca7ab['status']);throw _0x1d79c3['status']=_0x5ca7ab['status'],_0x1d79c3['code']=null===(_0xc624ef=null==_0x1d0f29?void 0x0:_0x1d0f29['error'])||void 0x0===_0xc624ef?void 0x0:_0xc624ef['code'],_0x1d79c3;}const _0x3a73b4=_0x5ca7ab['body']['getReader'](),_0xdbe88e=new TextDecoder();let _0x28c07b='',_0x16a31a='';for(;;){const {done:_0x2d2808,value:_0x4b8370}=await _0x3a73b4['read']();if(_0x2d2808)break;_0x16a31a+=_0xdbe88e['decode'](_0x4b8370,{'stream':!0x0});const _0x5f4292=_0x16a31a['split']('\x0a');_0x16a31a=_0x5f4292['pop']()||'';for(const _0x4833c0 of _0x5f4292){const _0x3aab6f=_0x4833c0['trim']();if(''!==_0x3aab6f&&'data:\x20[DONE]'!==_0x3aab6f&&_0x3aab6f['startsWith']('data:\x20'))try{const _0x3a860b=JSON['parse'](_0x3aab6f['slice'](0x6)),_0x27ad9a=null===(_0x412b93=null===(_0xdafd45=null===(_0x18ab4b=null==_0x3a860b?void 0x0:_0x3a860b['choices'])||void 0x0===_0x18ab4b?void 0x0:_0x18ab4b[0x0])||void 0x0===_0xdafd45?void 0x0:_0xdafd45['delta'])||void 0x0===_0x412b93?void 0x0:_0x412b93['content'];'string'==typeof _0x27ad9a&&(_0x28c07b+=_0x27ad9a,_0x5d361b&&_0x5d361b(_0x27ad9a));}catch(_0x18d541){}}}return{'content':_0x28c07b};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['HttpTransport']=void 0x0;class HttpTransport{constructor({url:
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['HttpTransport']=void 0x0;class HttpTransport{constructor({url:_0x55557e}){this['url']=_0x55557e;}async['send'](_0x2f8002){const _0x3974ee=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0x2f8002)});if(!_0x3974ee['ok']){const _0x45a883=await _0x3974ee['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0x45a883);}return await _0x3974ee['json']();}['sendBinary'](){throw new Error('Binary\x20is\x20not\x20supported\x20over\x20HTTP\x20yet');}}exports['HttpTransport']=HttpTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['WebsocketTransport']=void 0x0;const events_1=require('events'),frame_js_1=require('../utils/frame.js');class WebsocketTransport extends events_1['default']{constructor(
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['WebsocketTransport']=void 0x0;const events_1=require('events'),frame_js_1=require('../utils/frame.js');class WebsocketTransport extends events_1['default']{constructor(_0x5ce0d9=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x5ce0d9||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x3e5b32){return new Promise((_0x14700d,_0x5cf4a2)=>{this['socket']=new this['WebSocketImpl'](_0x3e5b32),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x14700d(!0x0)),this['_on']('error',_0x558fcc=>{console['error']('WS\x20error',_0x558fcc),_0x5cf4a2(_0x558fcc);}),this['_on']('close',_0x9be1d8=>{const _0x516fcc=null==_0x9be1d8?void 0x0:_0x9be1d8['code'],_0x691e0e=null==_0x9be1d8?void 0x0:_0x9be1d8['reason'];this['emit']('close',{'code':_0x516fcc,'reason':_0x691e0e});}),this['_on']('message',async(_0x18cb96,_0x1c9f6e)=>{var _0x58fc47,_0x4ee806=null!==(_0x58fc47=null==_0x18cb96?void 0x0:_0x18cb96['data'])&&void 0x0!==_0x58fc47?_0x58fc47:_0x18cb96;'undefined'!=typeof Blob&&_0x4ee806 instanceof Blob&&(_0x4ee806=await _0x4ee806['arrayBuffer']());const _0x298b82=(0x0,frame_js_1['decodePacket'])(_0x4ee806);_0x298b82&&this['emit']('message',_0x298b82,_0x1c9f6e);});});}['_on'](_0x2f6884,_0x2d1873){this['socket']['on']?this['socket']['on'](_0x2f6884,_0x2d1873):this['socket']['on'+_0x2f6884]=_0x2d1873;}['send'](_0x4c9e93){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x4c9e93);}['sendBinary'](_0x204dd6){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x204dd6);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x1f7f5d;null===(_0x1f7f5d=this['socket'])||void 0x0===_0x1f7f5d||_0x1f7f5d['close']();}}exports['WebsocketTransport']=WebsocketTransport;
|
package/dist/cjs/utils/buffer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function toUint8(
|
|
1
|
+
'use strict';function toUint8(_0x313469){return'undefined'!=typeof Buffer?Buffer['from'](_0x313469,'utf8'):new TextEncoder()['encode'](_0x313469);}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['toUint8']=toUint8;
|
package/dist/cjs/utils/frame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function framePacket(
|
|
1
|
+
'use strict';function framePacket(_0x16c1d9,_0xe41a11){const _0x4fb571=Buffer['from'](JSON['stringify'](_0x16c1d9)),_0x4bed78=Buffer['isBuffer'](_0xe41a11)?_0xe41a11:Buffer['from'](_0xe41a11),_0x55432d=Buffer['alloc'](0x4+_0x4fb571['length']+0x4+_0x4bed78['length']);let _0x232269=0x0;return _0x55432d['writeUInt32BE'](_0x4fb571['length'],_0x232269),_0x232269+=0x4,_0x4fb571['copy'](_0x55432d,_0x232269),_0x232269+=_0x4fb571['length'],_0x55432d['writeUInt32BE'](_0x4bed78['length'],_0x232269),_0x232269+=0x4,_0x4bed78['copy'](_0x55432d,_0x232269),_0x55432d;}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['framePacket']=framePacket,exports['decodePacket']=decodePacket;let internalBuffer=Buffer['alloc'](0x0);function decodePacket(_0x1bf590){try{Buffer['isBuffer'](_0x1bf590)||(_0x1bf590=Buffer['from'](_0x1bf590)),internalBuffer=Buffer['concat']([internalBuffer,_0x1bf590]);let _0x1c0afa=0x0;if(internalBuffer['length']<0x4)return null;const _0x1a74e7=internalBuffer['readUInt32BE'](_0x1c0afa);if(_0x1c0afa+=0x4,internalBuffer['length']<_0x1c0afa+_0x1a74e7)return null;const _0x3d3aa8=internalBuffer['slice'](_0x1c0afa,_0x1c0afa+_0x1a74e7),_0x31103b=JSON['parse'](_0x3d3aa8['toString']());if(_0x1c0afa+=_0x1a74e7,internalBuffer['length']<_0x1c0afa+0x4)return null;const _0x4ebcd2=internalBuffer['readUInt32BE'](_0x1c0afa);if(_0x1c0afa+=0x4,internalBuffer['length']<_0x1c0afa+_0x4ebcd2)return null;const _0xbc947a=internalBuffer['slice'](_0x1c0afa,_0x1c0afa+_0x4ebcd2);_0x1c0afa+=_0x4ebcd2,internalBuffer=internalBuffer['slice'](_0x1c0afa);let _0x5c25df=_0xbc947a;if('text'===_0x31103b['type'])try{_0x5c25df=JSON['parse'](_0xbc947a['toString']('utf8'));}catch{_0x5c25df=_0xbc947a;}return{'metadata':_0x31103b,'data':_0x5c25df};}catch(_0xb3e795){return console['error']('decodePacket\x20error:',_0xb3e795),null;}}
|
package/dist/cjs/utils/id.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['prefixId']=void 0x0;const prefixId=(
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['prefixId']=void 0x0;const prefixId=(_0x3b613d,_0x3a0ba5)=>_0x3a0ba5['includes'](':')?_0x3a0ba5:_0x3b613d+':'+_0x3a0ba5;exports['prefixId']=prefixId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['Payload']=void 0x0;class Payload{constructor(
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['Payload']=void 0x0;class Payload{constructor(_0x5ad9ff){this['buffer']=_0x5ad9ff;}['raw'](){return this['buffer'];}['toString'](_0x462156='utf8'){return this['buffer']['toString'](_0x462156);}['toJSON'](_0x2d3892='utf8'){try{return JSON['parse'](this['buffer']['toString'](_0x2d3892));}catch(_0xf9c4a7){return null;}}['toBase64'](){return this['buffer']['toString']('base64');}}exports['Payload']=Payload;
|
package/dist/dnotifier.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(dnotifier_exports, {
|
|
|
33
33
|
DNotifier: () => DNotifier
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(dnotifier_exports);
|
|
36
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
36
37
|
|
|
37
38
|
// src/transport/httpTransport.js
|
|
38
39
|
var HttpTransport = class {
|
|
@@ -235,83 +236,9 @@ function toUint8(data) {
|
|
|
235
236
|
return new TextEncoder().encode(data);
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
// src/providers/openai.js
|
|
239
|
-
var DEFAULT_BASE_URL = "https://api.openai.com";
|
|
240
|
-
var DEFAULT_MODEL = "gpt-4o-mini";
|
|
241
|
-
function normalizeMessages(message) {
|
|
242
|
-
if (typeof message === "string") {
|
|
243
|
-
return [{ role: "user", content: message }];
|
|
244
|
-
}
|
|
245
|
-
if (Array.isArray(message) && message.length > 0) {
|
|
246
|
-
return message.map((m) => ({
|
|
247
|
-
role: m.role || "user",
|
|
248
|
-
content: typeof m.content === "string" ? m.content : String(m.content)
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
251
|
-
throw new Error("message must be a non-empty string or array of { role, content }");
|
|
252
|
-
}
|
|
253
|
-
async function chatStream(options) {
|
|
254
|
-
const {
|
|
255
|
-
apiKey,
|
|
256
|
-
model = DEFAULT_MODEL,
|
|
257
|
-
messages,
|
|
258
|
-
baseUrl = DEFAULT_BASE_URL,
|
|
259
|
-
onChunk
|
|
260
|
-
} = options;
|
|
261
|
-
if (!apiKey || !messages) {
|
|
262
|
-
throw new Error("openai.chatStream: apiKey and messages are required");
|
|
263
|
-
}
|
|
264
|
-
const url = `${baseUrl.replace(/\/$/, "")}/v1/chat/completions`;
|
|
265
|
-
const body = {
|
|
266
|
-
model,
|
|
267
|
-
messages: normalizeMessages(messages),
|
|
268
|
-
stream: true
|
|
269
|
-
};
|
|
270
|
-
const res = await fetch(url, {
|
|
271
|
-
method: "POST",
|
|
272
|
-
headers: {
|
|
273
|
-
"Content-Type": "application/json",
|
|
274
|
-
Authorization: `Bearer ${apiKey}`
|
|
275
|
-
},
|
|
276
|
-
body: JSON.stringify(body)
|
|
277
|
-
});
|
|
278
|
-
if (!res.ok) {
|
|
279
|
-
const raw = await res.json().catch(() => ({}));
|
|
280
|
-
const err = new Error(raw?.error?.message || `OpenAI API error: ${res.status}`);
|
|
281
|
-
err.status = res.status;
|
|
282
|
-
err.code = raw?.error?.code;
|
|
283
|
-
throw err;
|
|
284
|
-
}
|
|
285
|
-
const reader = res.body.getReader();
|
|
286
|
-
const decoder = new TextDecoder();
|
|
287
|
-
let content = "";
|
|
288
|
-
let buffer = "";
|
|
289
|
-
while (true) {
|
|
290
|
-
const { done, value } = await reader.read();
|
|
291
|
-
if (done) break;
|
|
292
|
-
buffer += decoder.decode(value, { stream: true });
|
|
293
|
-
const lines = buffer.split("\n");
|
|
294
|
-
buffer = lines.pop() || "";
|
|
295
|
-
for (const line of lines) {
|
|
296
|
-
const trimmed = line.trim();
|
|
297
|
-
if (trimmed === "" || trimmed === "data: [DONE]") continue;
|
|
298
|
-
if (!trimmed.startsWith("data: ")) continue;
|
|
299
|
-
try {
|
|
300
|
-
const json = JSON.parse(trimmed.slice(6));
|
|
301
|
-
const delta = json?.choices?.[0]?.delta?.content;
|
|
302
|
-
if (typeof delta === "string") {
|
|
303
|
-
content += delta;
|
|
304
|
-
if (onChunk) onChunk(delta);
|
|
305
|
-
}
|
|
306
|
-
} catch (_) {
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return { content };
|
|
311
|
-
}
|
|
312
|
-
|
|
313
239
|
// src/dnotifier.js
|
|
314
|
-
var _defaultWsUrl = "wss://api.dnotifier.com/ecs/ws";
|
|
240
|
+
var _defaultWsUrl = "wss://dev.api.dnotifier.com/ecs/ws";
|
|
241
|
+
var _defaultAuthUrl = "https://dev.api.dnotifier.com/ecs/api/v1/sdk/auth";
|
|
315
242
|
var DNotifier = class {
|
|
316
243
|
constructor({
|
|
317
244
|
appId,
|
|
@@ -344,7 +271,7 @@ var DNotifier = class {
|
|
|
344
271
|
}
|
|
345
272
|
async connect() {
|
|
346
273
|
const authServer = new HttpTransport({
|
|
347
|
-
url:
|
|
274
|
+
url: _defaultAuthUrl
|
|
348
275
|
});
|
|
349
276
|
const res = await authServer.send({
|
|
350
277
|
appId: this.appId,
|
|
@@ -357,8 +284,9 @@ var DNotifier = class {
|
|
|
357
284
|
}
|
|
358
285
|
throw new Error("Authentication Failed.");
|
|
359
286
|
}
|
|
287
|
+
this._authResponse = res._responseData;
|
|
360
288
|
this.authToken = res._responseData.token;
|
|
361
|
-
this.aiEnabled = res._responseData.limits
|
|
289
|
+
this.aiEnabled = res._responseData.limits?.aiEnabled ?? false;
|
|
362
290
|
await this.transport.connect(this.url);
|
|
363
291
|
const metadata = {
|
|
364
292
|
type: "text",
|
|
@@ -416,6 +344,26 @@ var DNotifier = class {
|
|
|
416
344
|
});
|
|
417
345
|
});
|
|
418
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns the plan limits from the last successful authentication.
|
|
349
|
+
* @returns {{ messagesHardLimit: number, maxRequestsPerMonth: number, maxAIWordsPerMonth: number, knowledgeBaseMaxWords: number, aiEnabled: boolean, maxUsers: number, maxRowsPerUser: number } | null}
|
|
350
|
+
* @throws {Error} If not connected.
|
|
351
|
+
*/
|
|
352
|
+
getPlanLimits() {
|
|
353
|
+
if (!this.isConnected) throw new Error("Not connected");
|
|
354
|
+
const limits = this._authResponse?.limits;
|
|
355
|
+
if (!limits) return null;
|
|
356
|
+
const aiEnabled = limits.aiEnabled ?? false;
|
|
357
|
+
return {
|
|
358
|
+
messagesHardLimit: limits.messagesHardLimit,
|
|
359
|
+
maxAIRequestsPerMonth: aiEnabled ? limits.ai_limits?.maxRequestsPerMonth ?? 0 : 0,
|
|
360
|
+
maxAIWordsPerMonth: aiEnabled ? limits.ai_limits?.maxAIWordsPerMonth ?? 0 : 0,
|
|
361
|
+
knowledgeBaseMaxWords: aiEnabled ? limits.knowledge_base_limits?.maxWords ?? 0 : 0,
|
|
362
|
+
aiEnabled,
|
|
363
|
+
maxUsers: limits.db_storage_limits?.maxUsers ?? 0,
|
|
364
|
+
maxRowsPerUser: limits.db_storage_limits?.maxRowsPerUser ?? 0
|
|
365
|
+
};
|
|
366
|
+
}
|
|
419
367
|
send({ senderId, receiverId, receiverIds, data }) {
|
|
420
368
|
if (!this.isConnected) throw new Error("Not connected");
|
|
421
369
|
if (!senderId) throw new Error("senderId required");
|
|
@@ -423,6 +371,7 @@ var DNotifier = class {
|
|
|
423
371
|
throw new Error("receiverId or receiverIds required");
|
|
424
372
|
const receivers = receiverIds ?? [receiverId];
|
|
425
373
|
const metadata = {
|
|
374
|
+
id: import_crypto.default.randomUUID(),
|
|
426
375
|
type: "text",
|
|
427
376
|
code: 200,
|
|
428
377
|
appId: this.appId,
|
|
@@ -437,6 +386,45 @@ var DNotifier = class {
|
|
|
437
386
|
const frame = framePacket(metadata, payloadBuffer);
|
|
438
387
|
this.transport.sendBinary(frame);
|
|
439
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Send a message to the AI pipeline.
|
|
391
|
+
* @param {Object} options
|
|
392
|
+
* @param {string} options.senderId - Sender user id.
|
|
393
|
+
* @param {string | object} options.message - Message or payload to send to AI.
|
|
394
|
+
*/
|
|
395
|
+
sendAI({ senderId, message }) {
|
|
396
|
+
if (!this.isConnected) throw new Error("Not connected");
|
|
397
|
+
if (!senderId) throw new Error("senderId required");
|
|
398
|
+
const metadata = {
|
|
399
|
+
id: import_crypto.default.randomUUID(),
|
|
400
|
+
type: "ai",
|
|
401
|
+
code: 300,
|
|
402
|
+
appId: this.appId,
|
|
403
|
+
sender: prefixId(this.appId, senderId),
|
|
404
|
+
receiverId: prefixId(this.appId, senderId),
|
|
405
|
+
timestamp: Date.now(),
|
|
406
|
+
token: this.authToken
|
|
407
|
+
};
|
|
408
|
+
const payloadBuffer = toUint8(JSON.stringify(message));
|
|
409
|
+
const frame = framePacket(metadata, payloadBuffer);
|
|
410
|
+
this.transport.sendBinary(frame);
|
|
411
|
+
}
|
|
412
|
+
fetchAIHistory({ senderId }) {
|
|
413
|
+
if (!this.isConnected) throw new Error("Not connected");
|
|
414
|
+
if (!senderId) throw new Error("senderId required");
|
|
415
|
+
const metadata = {
|
|
416
|
+
id: import_crypto.default.randomUUID(),
|
|
417
|
+
type: "ai",
|
|
418
|
+
code: 301,
|
|
419
|
+
appId: this.appId,
|
|
420
|
+
sender: prefixId(this.appId, senderId),
|
|
421
|
+
timestamp: Date.now(),
|
|
422
|
+
token: this.authToken
|
|
423
|
+
};
|
|
424
|
+
const payloadBuffer = toUint8(JSON.stringify({}));
|
|
425
|
+
const frame = framePacket(metadata, payloadBuffer);
|
|
426
|
+
this.transport.sendBinary(frame);
|
|
427
|
+
}
|
|
440
428
|
sendBinary({ senderId, receiverIds, buffer, type = "binary" }) {
|
|
441
429
|
if (!this.isConnected) throw new Error("Not connected");
|
|
442
430
|
if (!senderId) throw new Error("senderId required");
|
|
@@ -467,31 +455,47 @@ var DNotifier = class {
|
|
|
467
455
|
* @param {string} [options.baseUrl] - OpenAI-compatible API base URL (e.g. Azure/custom).
|
|
468
456
|
* @returns {Promise<{ content: string }>} Resolves with the full assistant content when done.
|
|
469
457
|
*/
|
|
458
|
+
// async sendWithOpenAI({ senderId, message, openaiApiKey, model, baseUrl }) {
|
|
459
|
+
// if (!this.aiEnabled) throw new Error("AI is not enabled for this subscription.");
|
|
460
|
+
// if (!this.isConnected) throw new Error("Not connected");
|
|
461
|
+
// if (!senderId) throw new Error("senderId is required");
|
|
462
|
+
// if (!message) throw new Error("message is required");
|
|
463
|
+
// if (!openaiApiKey) throw new Error("openaiApiKey is required");
|
|
464
|
+
// const { content } = await openaiChatStream({
|
|
465
|
+
// apiKey: openaiApiKey,
|
|
466
|
+
// model,
|
|
467
|
+
// messages: message,
|
|
468
|
+
// baseUrl,
|
|
469
|
+
// });
|
|
470
|
+
// const data = {
|
|
471
|
+
// type: "openai",
|
|
472
|
+
// content,
|
|
473
|
+
// ts: Date.now(),
|
|
474
|
+
// };
|
|
475
|
+
// this.onMessageCallback({
|
|
476
|
+
// metadata: {
|
|
477
|
+
// sender: prefixId(this.appId, senderId),
|
|
478
|
+
// timestamp: Date.now(),
|
|
479
|
+
// },
|
|
480
|
+
// payload: new Payload(toUint8(JSON.stringify(data))),
|
|
481
|
+
// });
|
|
482
|
+
// return { content };
|
|
483
|
+
// }
|
|
484
|
+
/**
|
|
485
|
+
* Send a message to the AI pipeline. This method still works but is deprecated.
|
|
486
|
+
* Use {@link sendAI} instead. This function will be removed in a future release.
|
|
487
|
+
*
|
|
488
|
+
* @deprecated Use sendAI({ senderId, message }) instead. Will be removed in a future release.
|
|
489
|
+
* @param {Object} options
|
|
490
|
+
* @param {string} options.senderId - Sender user id.
|
|
491
|
+
* @param {string | object} options.message - Message or payload to send to AI.
|
|
492
|
+
*/
|
|
470
493
|
async sendWithOpenAI({ senderId, message, openaiApiKey, model, baseUrl }) {
|
|
471
494
|
if (!this.aiEnabled) throw new Error("AI is not enabled for this subscription.");
|
|
472
495
|
if (!this.isConnected) throw new Error("Not connected");
|
|
473
496
|
if (!senderId) throw new Error("senderId is required");
|
|
474
497
|
if (!message) throw new Error("message is required");
|
|
475
|
-
|
|
476
|
-
const { content } = await chatStream({
|
|
477
|
-
apiKey: openaiApiKey,
|
|
478
|
-
model,
|
|
479
|
-
messages: message,
|
|
480
|
-
baseUrl
|
|
481
|
-
});
|
|
482
|
-
const data = {
|
|
483
|
-
type: "openai",
|
|
484
|
-
content,
|
|
485
|
-
ts: Date.now()
|
|
486
|
-
};
|
|
487
|
-
this.onMessageCallback({
|
|
488
|
-
metadata: {
|
|
489
|
-
sender: prefixId(this.appId, senderId),
|
|
490
|
-
timestamp: Date.now()
|
|
491
|
-
},
|
|
492
|
-
payload: new Payload(toUint8(JSON.stringify(data)))
|
|
493
|
-
});
|
|
494
|
-
return { content };
|
|
498
|
+
this.sendAI({ senderId, message });
|
|
495
499
|
}
|
|
496
500
|
};
|
|
497
501
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/dnotifier.d.ts
CHANGED
|
@@ -21,13 +21,30 @@ export class DNotifier {
|
|
|
21
21
|
aiEnabled: boolean;
|
|
22
22
|
transport: HttpTransport | WebsocketTransport;
|
|
23
23
|
connect(): Promise<void>;
|
|
24
|
+
_authResponse: any;
|
|
24
25
|
authToken: any;
|
|
26
|
+
getPlanLimits(): {
|
|
27
|
+
messagesHardLimit: number;
|
|
28
|
+
maxRequestsPerMonth: number;
|
|
29
|
+
maxAIWordsPerMonth: number;
|
|
30
|
+
knowledgeBaseMaxWords: number;
|
|
31
|
+
aiEnabled: boolean;
|
|
32
|
+
maxUsers: number;
|
|
33
|
+
maxRowsPerUser: number;
|
|
34
|
+
} | null;
|
|
25
35
|
send({ senderId, receiverId, receiverIds, data }: {
|
|
26
36
|
senderId: any;
|
|
27
37
|
receiverId: any;
|
|
28
38
|
receiverIds: any;
|
|
29
39
|
data: any;
|
|
30
40
|
}): void;
|
|
41
|
+
sendAI({ senderId, message }: {
|
|
42
|
+
senderId: string;
|
|
43
|
+
message: string | object;
|
|
44
|
+
}): void;
|
|
45
|
+
fetchAIHistory({ senderId }: {
|
|
46
|
+
senderId: any;
|
|
47
|
+
}): void;
|
|
31
48
|
sendBinary({ senderId, receiverIds, buffer, type }: {
|
|
32
49
|
senderId: any;
|
|
33
50
|
receiverIds: any;
|
|
@@ -36,16 +53,8 @@ export class DNotifier {
|
|
|
36
53
|
}): void;
|
|
37
54
|
sendWithOpenAI({ senderId, message, openaiApiKey, model, baseUrl }: {
|
|
38
55
|
senderId: string;
|
|
39
|
-
message: string |
|
|
40
|
-
|
|
41
|
-
content: string;
|
|
42
|
-
}>;
|
|
43
|
-
openaiApiKey: string;
|
|
44
|
-
model?: string | undefined;
|
|
45
|
-
baseUrl?: string | undefined;
|
|
46
|
-
}): Promise<{
|
|
47
|
-
content: string;
|
|
48
|
-
}>;
|
|
56
|
+
message: string | object;
|
|
57
|
+
}): Promise<void>;
|
|
49
58
|
}
|
|
50
59
|
import { HttpTransport } from "./transport/httpTransport.js";
|
|
51
60
|
import { WebsocketTransport } from "./transport/websocketTransport.js";
|
package/dist/dnotifier.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dnotifier.d.ts","sourceRoot":"","sources":["../src/dnotifier.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dnotifier.d.ts","sourceRoot":"","sources":["../src/dnotifier.js"],"names":[],"mappings":"AAaA;IACE;;;;;;;;;;OA+BC;IAhBC,WAAkB;IAClB,YAAoB;IACpB,YAAoB;IACpB,SAA+B;IAE/B,yBAAoD;IACpD,uBAAgD;IAChD,4BAA0D;IAE1D,qBAAwB;IACxB,mBAAsB;IAEtB,8CAGyB;IAG3B,yBA+FC;IA5EC,mBAAsC;IACtC,eAAwC;IAkF1C,iBAHa;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAC;QAAC,qBAAqB,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAiBtM;IAED;;;;;aAyBC;IAQD,8BAHG;QAAwB,QAAQ,EAAxB,MAAM;QACmB,OAAO,EAAhC,MAAM,GAAG,MAAM;KACzB,QAoBA;IAED;;aAkBC;IAED;;;;;aAmBC;IAqDD,oEAHG;QAAwB,QAAQ,EAAxB,MAAM;QACmB,OAAO,EAAhC,MAAM,GAAG,MAAM;KACzB,iBAQA;CACF;8BA9T6B,8BAA8B;mCACzB,mCAAmC"}
|
package/dist/dnotifier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HttpTransport}from'./transport/httpTransport.js';import{WebsocketTransport}from'./transport/websocketTransport.js';import{prefixId}from'./utils/id.js';import{framePacket}from'./utils/frame.js';import{Payload}from'./utils/payload.js';import{toUint8}from'./utils/buffer.js';import{chatStream as
|
|
1
|
+
import _0x3cc31a from'crypto';import{HttpTransport}from'./transport/httpTransport.js';import{WebsocketTransport}from'./transport/websocketTransport.js';import{prefixId}from'./utils/id.js';import{framePacket}from'./utils/frame.js';import{Payload}from'./utils/payload.js';import{toUint8}from'./utils/buffer.js';import{chatStream as _0x5bca0b}from'./providers/openai.js';const _defaultWsUrl='wss://dev.api.dnotifier.com/ecs/ws',_defaultAuthUrl='https://dev.api.dnotifier.com/ecs/api/v1/sdk/auth';export class DNotifier{constructor({appId:_0xdd2c63,secret:_0x8e8ee5,transport:_0x336d75,userId:_0x10f639,url:_0x329e6f,onConnected:_0x7a4b82,onMessage:_0x4b4472,onDisconnected:_0x1057b9,WebSocketImpl:_0x18a939}){if(!(_0xdd2c63&&_0x8e8ee5&&_0x336d75&&_0x10f639))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0xdd2c63,this['secret']=_0x8e8ee5,this['userId']=_0x10f639,this['url']=null!=_0x329e6f?_0x329e6f:_defaultWsUrl,this['onConnectedCallback']=_0x7a4b82||(()=>{}),this['onMessageCallback']=_0x4b4472||(()=>{}),this['onDisconnectedCallback']=_0x1057b9||(()=>{}),this['isConnected']=!0x1,this['aiEnabled']=!0x1,this['transport']='ws'===_0x336d75?new WebsocketTransport(_0x18a939):new HttpTransport();}async['connect'](){var _0x13d73c,_0x2f39f7;const _0x62bae2=new HttpTransport({'url':_defaultAuthUrl}),_0xd3fc81=await _0x62bae2['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0xd3fc81['_responseCode']){if(0x190===_0xd3fc81['_responseCode'])throw new Error(_0xd3fc81['_responseData']);throw new Error('Authentication\x20Failed.');}this['_authResponse']=_0xd3fc81['_responseData'],this['authToken']=_0xd3fc81['_responseData']['token'],this['aiEnabled']=null!==(_0x2f39f7=null===(_0x13d73c=_0xd3fc81['_responseData']['limits'])||void 0x0===_0x13d73c?void 0x0:_0x13d73c['aiEnabled'])&&void 0x0!==_0x2f39f7&&_0x2f39f7,await this['transport']['connect'](this['url']);const _0x31813a={'type':'text','code':0x65,'appId':this['appId'],'sender':prefixId(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0x2eae87=toUint8(JSON['stringify']({'token':this['authToken']})),_0x3b10dd=framePacket(_0x31813a,_0x2eae87);this['transport']['sendBinary'](_0x3b10dd);let _0x258591=!0x1;this['transport']['on']('message',_0x3cf988=>{try{const {metadata:_0x572c96,data:_0x3f59ab}=_0x3cf988;if(!_0x258591&&'102'===_0x572c96['packet']['code']&&_0x572c96['packet']['sender']['includes'](prefixId(this['appId'],this['userId'])))return _0x258591=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x258591&&this['onMessageCallback']({'metadata':{'sender':_0x572c96['packet']['sender'],'timestamp':_0x572c96['packet']['timestamp']},'payload':new Payload(_0x3f59ab)});}catch(_0x260632){console['error']('Packet\x20error:',_0x260632);}}),this['transport']['on']('close',({code:_0x3a3063,reason:_0x962eb2})=>{const _0x361174=this['isConnected'];this['isConnected']=!0x1,_0x361174&&this['onDisconnectedCallback']&&this['onDisconnectedCallback']({'code':_0x3a3063,'reason':_0x962eb2||'Disconnected'});}),this['transport']['on']('error',_0x5392dc=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x5392dc?void 0x0:_0x5392dc['message'])||'Transport\x20error'});});}['getPlanLimits'](){var _0x5453e8,_0x3e59a3,_0x3390b8,_0x210a15,_0x59c17d,_0x39e811,_0xa9cb5,_0x423879,_0x3b8c6f,_0x31eb88,_0x49cae5,_0x2993e8;if(!this['isConnected'])throw new Error('Not\x20connected');const _0x1cd083=null===(_0x5453e8=this['_authResponse'])||void 0x0===_0x5453e8?void 0x0:_0x5453e8['limits'];if(!_0x1cd083)return null;const _0x4a7fbd=null!==(_0x3e59a3=_0x1cd083['aiEnabled'])&&void 0x0!==_0x3e59a3&&_0x3e59a3;return{'messagesHardLimit':_0x1cd083['messagesHardLimit'],'maxAIRequestsPerMonth':_0x4a7fbd&&null!==(_0x210a15=null===(_0x3390b8=_0x1cd083['ai_limits'])||void 0x0===_0x3390b8?void 0x0:_0x3390b8['maxRequestsPerMonth'])&&void 0x0!==_0x210a15?_0x210a15:0x0,'maxAIWordsPerMonth':_0x4a7fbd&&null!==(_0x39e811=null===(_0x59c17d=_0x1cd083['ai_limits'])||void 0x0===_0x59c17d?void 0x0:_0x59c17d['maxAIWordsPerMonth'])&&void 0x0!==_0x39e811?_0x39e811:0x0,'knowledgeBaseMaxWords':_0x4a7fbd&&null!==(_0x423879=null===(_0xa9cb5=_0x1cd083['knowledge_base_limits'])||void 0x0===_0xa9cb5?void 0x0:_0xa9cb5['maxWords'])&&void 0x0!==_0x423879?_0x423879:0x0,'aiEnabled':_0x4a7fbd,'maxUsers':null!==(_0x31eb88=null===(_0x3b8c6f=_0x1cd083['db_storage_limits'])||void 0x0===_0x3b8c6f?void 0x0:_0x3b8c6f['maxUsers'])&&void 0x0!==_0x31eb88?_0x31eb88:0x0,'maxRowsPerUser':null!==(_0x2993e8=null===(_0x49cae5=_0x1cd083['db_storage_limits'])||void 0x0===_0x49cae5?void 0x0:_0x49cae5['maxRowsPerUser'])&&void 0x0!==_0x2993e8?_0x2993e8:0x0};}['send']({senderId:_0x11cf9b,receiverId:_0x467975,receiverIds:_0x751204,data:_0x54b3fc}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x11cf9b)throw new Error('senderId\x20required');if(!_0x467975&&!_0x751204)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x4b115f=null!=_0x751204?_0x751204:[_0x467975],_0x5aea40={'id':_0x3cc31a['randomUUID'](),'type':'text','code':0xc8,'appId':this['appId'],'sender':prefixId(this['appId'],_0x11cf9b),'receivers':_0x4b115f['map'](_0x48cc2a=>prefixId(this['appId'],_0x48cc2a)),'timestamp':Date['now'](),'token':this['authToken']},_0x445a74=toUint8(JSON['stringify'](_0x54b3fc)),_0x116408=framePacket(_0x5aea40,_0x445a74);this['transport']['sendBinary'](_0x116408);}['sendAI']({senderId:_0x481531,message:_0x3f231e}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x481531)throw new Error('senderId\x20required');const _0x1c9fbe={'id':_0x3cc31a['randomUUID'](),'type':'ai','code':0x12c,'appId':this['appId'],'sender':prefixId(this['appId'],_0x481531),'receiverId':prefixId(this['appId'],_0x481531),'timestamp':Date['now'](),'token':this['authToken']},_0x49ee2a=toUint8(JSON['stringify'](_0x3f231e)),_0x37daa1=framePacket(_0x1c9fbe,_0x49ee2a);this['transport']['sendBinary'](_0x37daa1);}['fetchAIHistory']({senderId:_0x5b4214}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x5b4214)throw new Error('senderId\x20required');const _0x496e3b={'id':_0x3cc31a['randomUUID'](),'type':'ai','code':0x12d,'appId':this['appId'],'sender':prefixId(this['appId'],_0x5b4214),'timestamp':Date['now'](),'token':this['authToken']},_0x3dc2ab=toUint8(JSON['stringify']({})),_0x12c8bd=framePacket(_0x496e3b,_0x3dc2ab);this['transport']['sendBinary'](_0x12c8bd);}['sendBinary']({senderId:_0x3f56d4,receiverIds:_0x3be7ca,buffer:_0x467685,type:_0x342ae2='binary'}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x3f56d4)throw new Error('senderId\x20required');if(!_0x467685)throw new Error('buffer\x20is\x20required');const _0x20cff8={'type':_0x342ae2,'code':0xca,'appId':this['appId'],'sender':prefixId(this['appId'],_0x3f56d4),'receivers':_0x3be7ca['map'](_0x4986d1=>prefixId(this['appId'],_0x4986d1)),'timestamp':Date['now'](),'token':this['authToken']},_0x5006ea=framePacket(_0x20cff8,_0x467685);this['transport']['sendBinary'](_0x5006ea);}async['sendWithOpenAI']({senderId:_0x10f7ea,message:_0x1c37ad,openaiApiKey:_0x3fe51f,model:_0x58b217,baseUrl:_0x352a25}){if(!this['aiEnabled'])throw new Error('AI\x20is\x20not\x20enabled\x20for\x20this\x20subscription.');if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x10f7ea)throw new Error('senderId\x20is\x20required');if(!_0x1c37ad)throw new Error('message\x20is\x20required');this['sendAI']({'senderId':_0x10f7ea,'message':_0x1c37ad});}}
|
package/dist/providers/openai.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(
|
|
1
|
+
const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(_0x5c99e3){if('string'==typeof _0x5c99e3)return[{'role':'user','content':_0x5c99e3}];if(Array['isArray'](_0x5c99e3)&&_0x5c99e3['length']>0x0)return _0x5c99e3['map'](_0x2554c2=>({'role':_0x2554c2['role']||'user','content':'string'==typeof _0x2554c2['content']?_0x2554c2['content']:String(_0x2554c2['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}export async function chat(_0x3add80){var _0x73b71b,_0x3606a2,_0x66260b,_0x5753f2,_0x1f0284,_0x41007e;const {apiKey:_0xe516bf,model:_0x57fca7=DEFAULT_MODEL,messages:_0xe0a812,baseUrl:_0x189ff4=DEFAULT_BASE_URL}=_0x3add80;if(!_0xe516bf||!_0xe0a812)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x5c81da=_0x189ff4['replace'](/\/$/,'')+'/v1/chat/completions',_0x15d311={'model':_0x57fca7,'messages':normalizeMessages(_0xe0a812),'stream':!0x1},_0xae82d4=await fetch(_0x5c81da,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0xe516bf},'body':JSON['stringify'](_0x15d311)}),_0x495039=await _0xae82d4['json']();if(!_0xae82d4['ok']){const _0x5ae7b6=new Error((null===(_0x73b71b=null==_0x495039?void 0x0:_0x495039['error'])||void 0x0===_0x73b71b?void 0x0:_0x73b71b['message'])||'OpenAI\x20API\x20error:\x20'+_0xae82d4['status']);throw _0x5ae7b6['status']=_0xae82d4['status'],_0x5ae7b6['code']=null===(_0x3606a2=null==_0x495039?void 0x0:_0x495039['error'])||void 0x0===_0x3606a2?void 0x0:_0x3606a2['code'],_0x5ae7b6;}return{'content':null!==(_0x41007e=null===(_0x1f0284=null===(_0x5753f2=null===(_0x66260b=null==_0x495039?void 0x0:_0x495039['choices'])||void 0x0===_0x66260b?void 0x0:_0x66260b[0x0])||void 0x0===_0x5753f2?void 0x0:_0x5753f2['message'])||void 0x0===_0x1f0284?void 0x0:_0x1f0284['content'])&&void 0x0!==_0x41007e?_0x41007e:'','usage':null==_0x495039?void 0x0:_0x495039['usage'],'raw':_0x495039};}export async function chatStream(_0x1420de){var _0x3a2075,_0xfc8a01,_0x266966,_0x5bd32b,_0x353842;const {apiKey:_0x25926f,model:_0x21ef75=DEFAULT_MODEL,messages:_0xf5e9a6,baseUrl:_0x8a814c=DEFAULT_BASE_URL,onChunk:_0x367e60}=_0x1420de;if(!_0x25926f||!_0xf5e9a6)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x1f0a49=_0x8a814c['replace'](/\/$/,'')+'/v1/chat/completions',_0x49d849={'model':_0x21ef75,'messages':normalizeMessages(_0xf5e9a6),'stream':!0x0},_0x5cce9a=await fetch(_0x1f0a49,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x25926f},'body':JSON['stringify'](_0x49d849)});if(!_0x5cce9a['ok']){const _0x25a913=await _0x5cce9a['json']()['catch'](()=>({})),_0xa02335=new Error((null===(_0x3a2075=null==_0x25a913?void 0x0:_0x25a913['error'])||void 0x0===_0x3a2075?void 0x0:_0x3a2075['message'])||'OpenAI\x20API\x20error:\x20'+_0x5cce9a['status']);throw _0xa02335['status']=_0x5cce9a['status'],_0xa02335['code']=null===(_0xfc8a01=null==_0x25a913?void 0x0:_0x25a913['error'])||void 0x0===_0xfc8a01?void 0x0:_0xfc8a01['code'],_0xa02335;}const _0x3bd25e=_0x5cce9a['body']['getReader'](),_0x4e8a60=new TextDecoder();let _0x54d63c='',_0xf9fbac='';for(;;){const {done:_0x2a5816,value:_0x3afe36}=await _0x3bd25e['read']();if(_0x2a5816)break;_0xf9fbac+=_0x4e8a60['decode'](_0x3afe36,{'stream':!0x0});const _0x394860=_0xf9fbac['split']('\x0a');_0xf9fbac=_0x394860['pop']()||'';for(const _0x52fcdc of _0x394860){const _0x494adc=_0x52fcdc['trim']();if(''!==_0x494adc&&'data:\x20[DONE]'!==_0x494adc&&_0x494adc['startsWith']('data:\x20'))try{const _0x4fd30c=JSON['parse'](_0x494adc['slice'](0x6)),_0x4a7495=null===(_0x353842=null===(_0x5bd32b=null===(_0x266966=null==_0x4fd30c?void 0x0:_0x4fd30c['choices'])||void 0x0===_0x266966?void 0x0:_0x266966[0x0])||void 0x0===_0x5bd32b?void 0x0:_0x5bd32b['delta'])||void 0x0===_0x353842?void 0x0:_0x353842['content'];'string'==typeof _0x4a7495&&(_0x54d63c+=_0x4a7495,_0x367e60&&_0x367e60(_0x4a7495));}catch(_0x1070c3){}}}return{'content':_0x54d63c};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export class HttpTransport{constructor({url:
|
|
1
|
+
export class HttpTransport{constructor({url:_0x1a572c}){this['url']=_0x1a572c;}async['send'](_0x386abf){const _0xa4efdc=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0x386abf)});if(!_0xa4efdc['ok']){const _0x7e002f=await _0xa4efdc['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0x7e002f);}return await _0xa4efdc['json']();}['sendBinary'](){throw new Error('Binary\x20is\x20not\x20supported\x20over\x20HTTP\x20yet');}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _0xc26122 from'events';import{decodePacket}from'../utils/frame.js';export class WebsocketTransport extends _0xc26122{constructor(_0x558f28=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x558f28||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x3ea07c){return new Promise((_0x2854e1,_0x2574df)=>{this['socket']=new this['WebSocketImpl'](_0x3ea07c),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x2854e1(!0x0)),this['_on']('error',_0x1d71cf=>{console['error']('WS\x20error',_0x1d71cf),_0x2574df(_0x1d71cf);}),this['_on']('close',_0x797e14=>{const _0x562e26=null==_0x797e14?void 0x0:_0x797e14['code'],_0x1bb07c=null==_0x797e14?void 0x0:_0x797e14['reason'];this['emit']('close',{'code':_0x562e26,'reason':_0x1bb07c});}),this['_on']('message',async(_0x343d5c,_0x486ba0)=>{var _0x2b9780,_0x14511e=null!==(_0x2b9780=null==_0x343d5c?void 0x0:_0x343d5c['data'])&&void 0x0!==_0x2b9780?_0x2b9780:_0x343d5c;'undefined'!=typeof Blob&&_0x14511e instanceof Blob&&(_0x14511e=await _0x14511e['arrayBuffer']());const _0x445b7e=decodePacket(_0x14511e);_0x445b7e&&this['emit']('message',_0x445b7e,_0x486ba0);});});}['_on'](_0x422281,_0x53cd6f){this['socket']['on']?this['socket']['on'](_0x422281,_0x53cd6f):this['socket']['on'+_0x422281]=_0x53cd6f;}['send'](_0x3d3c0f){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x3d3c0f);}['sendBinary'](_0x4768fb){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x4768fb);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x2cf320;null===(_0x2cf320=this['socket'])||void 0x0===_0x2cf320||_0x2cf320['close']();}}
|
package/dist/utils/buffer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function toUint8(
|
|
1
|
+
export function toUint8(_0x1bb3c2){return'undefined'!=typeof Buffer?Buffer['from'](_0x1bb3c2,'utf8'):new TextEncoder()['encode'](_0x1bb3c2);}
|
package/dist/utils/frame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function framePacket(
|
|
1
|
+
export function framePacket(_0x25aaa9,_0x3d2487){const _0x56adb9=Buffer['from'](JSON['stringify'](_0x25aaa9)),_0x2bddc4=Buffer['isBuffer'](_0x3d2487)?_0x3d2487:Buffer['from'](_0x3d2487),_0xe56822=Buffer['alloc'](0x4+_0x56adb9['length']+0x4+_0x2bddc4['length']);let _0x1323d3=0x0;return _0xe56822['writeUInt32BE'](_0x56adb9['length'],_0x1323d3),_0x1323d3+=0x4,_0x56adb9['copy'](_0xe56822,_0x1323d3),_0x1323d3+=_0x56adb9['length'],_0xe56822['writeUInt32BE'](_0x2bddc4['length'],_0x1323d3),_0x1323d3+=0x4,_0x2bddc4['copy'](_0xe56822,_0x1323d3),_0xe56822;}let internalBuffer=Buffer['alloc'](0x0);export function decodePacket(_0x105aba){try{Buffer['isBuffer'](_0x105aba)||(_0x105aba=Buffer['from'](_0x105aba)),internalBuffer=Buffer['concat']([internalBuffer,_0x105aba]);let _0x1c4ad3=0x0;if(internalBuffer['length']<0x4)return null;const _0xa745af=internalBuffer['readUInt32BE'](_0x1c4ad3);if(_0x1c4ad3+=0x4,internalBuffer['length']<_0x1c4ad3+_0xa745af)return null;const _0x108a4a=internalBuffer['slice'](_0x1c4ad3,_0x1c4ad3+_0xa745af),_0x1e81b1=JSON['parse'](_0x108a4a['toString']());if(_0x1c4ad3+=_0xa745af,internalBuffer['length']<_0x1c4ad3+0x4)return null;const _0x75cc56=internalBuffer['readUInt32BE'](_0x1c4ad3);if(_0x1c4ad3+=0x4,internalBuffer['length']<_0x1c4ad3+_0x75cc56)return null;const _0x4a755e=internalBuffer['slice'](_0x1c4ad3,_0x1c4ad3+_0x75cc56);_0x1c4ad3+=_0x75cc56,internalBuffer=internalBuffer['slice'](_0x1c4ad3);let _0x119efa=_0x4a755e;if('text'===_0x1e81b1['type'])try{_0x119efa=JSON['parse'](_0x4a755e['toString']('utf8'));}catch{_0x119efa=_0x4a755e;}return{'metadata':_0x1e81b1,'data':_0x119efa};}catch(_0x414901){return console['error']('decodePacket\x20error:',_0x414901),null;}}
|
package/dist/utils/id.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const prefixId=(
|
|
1
|
+
export const prefixId=(_0x1b03a6,_0x593a1f)=>_0x593a1f['includes'](':')?_0x593a1f:_0x1b03a6+':'+_0x593a1f;
|
package/dist/utils/payload.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class Payload{constructor(
|
|
1
|
+
export class Payload{constructor(_0xed108b){this['buffer']=_0xed108b;}['raw'](){return this['buffer'];}['toString'](_0x4e5b25='utf8'){return this['buffer']['toString'](_0x4e5b25);}['toJSON'](_0x74c245='utf8'){try{return JSON['parse'](this['buffer']['toString'](_0x74c245));}catch(_0x3b1cfd){return null;}}['toBase64'](){return this['buffer']['toString']('base64');}}
|