@dnotifier-realtime/dnotifier 1.0.18 → 1.0.20
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 +101 -97
- 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:_0x35a22a,secret:_0x2134d4,transport:_0x57b844,userId:_0x2be4e6,onConnected:_0x240d06,onMessage:_0x4b14f3,onDisconnected:_0x3b26db,WebSocketImpl:_0x13c690}){if(!(_0x35a22a&&_0x2134d4&&_0x57b844&&_0x2be4e6))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0x35a22a,this['secret']=_0x2134d4,this['userId']=_0x2be4e6,this['url']='wss://link.dchatter.com/ws',this['onConnectedCallback']=_0x240d06||(()=>{}),this['onMessageCallback']=_0x4b14f3||(()=>{}),this['onDisconnectedCallback']=_0x3b26db||(()=>{}),this['isConnected']=!0x1,this['transport']='ws'===_0x57b844?new websocketTransport_js_1['WebsocketTransport'](_0x13c690):new httpTransport_js_1['HttpTransport']();}async['connect'](){const _0x1a0eae=new httpTransport_js_1['HttpTransport']({'url':'https://link.dchatter.com/api/v1/sdk/auth'}),_0xa64117=await _0x1a0eae['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0xa64117['_responseCode'])throw new Error('Authentication\x20Failed.');this['authToken']=_0xa64117['_responseData'],await this['transport']['connect'](this['url']);const _0x26176d={'type':'text','code':0x65,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0x55bfa4=(0x0,buffer_js_1['toUint8'])(JSON['stringify']({'token':this['authToken']})),_0x37943f=(0x0,frame_js_1['framePacket'])(_0x26176d,_0x55bfa4);this['transport']['sendBinary'](_0x37943f);let _0x136177=!0x1;this['transport']['on']('message',_0x2f48be=>{try{const {metadata:_0x13a76e,data:_0x1b025e}=_0x2f48be;if(!_0x136177&&'102'===_0x13a76e['packet']['code']&&_0x13a76e['packet']['sender']['includes']((0x0,id_js_1['prefixId'])(this['appId'],this['userId'])))return _0x136177=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x136177&&this['onMessageCallback']({'metadata':{'sender':_0x13a76e['packet']['sender'],'timestamp':_0x13a76e['packet']['timestamp']},'payload':new payload_js_1['Payload'](_0x1b025e)});}catch(_0x1a457a){console['error']('Packet\x20error:',_0x1a457a);}}),this['transport']['on']('close',({code:_0x263371,reason:_0xfa1f95})=>{this['isConnected']&&(this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':_0x263371,'reason':_0xfa1f95||'Disconnected'}));}),this['transport']['on']('error',_0x20f7f8=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x20f7f8?void 0x0:_0x20f7f8['message'])||'Transport\x20error'});});}['send']({senderId:_0x1e29e9,receiverId:_0x563096,receiverIds:_0x5129e2,data:_0x9bc71a}){if(!_0x1e29e9)throw new Error('senderId\x20required');if(!_0x563096&&!_0x5129e2)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x4fc782=null!=_0x5129e2?_0x5129e2:[_0x563096],_0x11eb05={'type':'text','code':0xc8,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x1e29e9),'receivers':_0x4fc782['map'](_0x4195de=>(0x0,id_js_1['prefixId'])(this['appId'],_0x4195de)),'timestamp':Date['now'](),'token':this['authToken']},_0x1392c2=(0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x9bc71a)),_0x4cbf40=(0x0,frame_js_1['framePacket'])(_0x11eb05,_0x1392c2);this['transport']['sendBinary'](_0x4cbf40);}['sendBinary']({senderId:_0x4a37d9,receiverIds:_0x434368,buffer:_0xe9e67c,type:_0x11cd7d='binary'}){if(!_0x4a37d9)throw new Error('senderId\x20required');if(!_0xe9e67c)throw new Error('buffer\x20is\x20required');const _0x3470f0={'type':_0x11cd7d,'code':0xca,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x4a37d9),'receivers':_0x434368['map'](_0x57ed5a=>(0x0,id_js_1['prefixId'])(this['appId'],_0x57ed5a)),'timestamp':Date['now'](),'token':this['authToken']},_0x27875f=(0x0,frame_js_1['framePacket'])(_0x3470f0,_0xe9e67c);this['transport']['sendBinary'](_0x27875f);}async['sendWithOpenAI']({senderId:_0x700549,message:_0x4a67ac,openaiApiKey:_0x1e0b82,model:_0x233a81,baseUrl:_0x460ae6}){if(!_0x700549)throw new Error('senderId\x20is\x20required');if(!_0x4a67ac)throw new Error('message\x20is\x20required');if(!_0x1e0b82)throw new Error('openaiApiKey\x20is\x20required');const {content:_0x214aea}=await(0x0,openai_js_1['chatStream'])({'apiKey':_0x1e0b82,'model':_0x233a81,'messages':_0x4a67ac,'baseUrl':_0x460ae6}),_0x2f61ec={'type':'openai','content':_0x214aea,'ts':Date['now']()};return this['onMessageCallback']({'metadata':{'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x700549),'timestamp':Date['now']()},'payload':new payload_js_1['Payload']((0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x2f61ec)))}),{'content':_0x214aea};}}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(_0x37b2e0){if('string'==typeof _0x37b2e0)return[{'role':'user','content':_0x37b2e0}];if(Array['isArray'](_0x37b2e0)&&_0x37b2e0['length']>0x0)return _0x37b2e0['map'](_0x34ac64=>({'role':_0x34ac64['role']||'user','content':'string'==typeof _0x34ac64['content']?_0x34ac64['content']:String(_0x34ac64['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}async function chat(_0x3e97db){var _0x2b1e56,_0x47d7dd,_0x4f6aa4,_0x481238,_0x2bfe0a,_0x59b573;const {apiKey:_0x329c4e,model:_0x44d78b=DEFAULT_MODEL,messages:_0x254567,baseUrl:_0x1ad47c=DEFAULT_BASE_URL}=_0x3e97db;if(!_0x329c4e||!_0x254567)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x40a8bb=_0x1ad47c['replace'](/\/$/,'')+'/v1/chat/completions',_0xe4f074={'model':_0x44d78b,'messages':normalizeMessages(_0x254567),'stream':!0x1},_0x1c0dd5=await fetch(_0x40a8bb,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x329c4e},'body':JSON['stringify'](_0xe4f074)}),_0x5e9a42=await _0x1c0dd5['json']();if(!_0x1c0dd5['ok']){const _0x412383=new Error((null===(_0x2b1e56=null==_0x5e9a42?void 0x0:_0x5e9a42['error'])||void 0x0===_0x2b1e56?void 0x0:_0x2b1e56['message'])||'OpenAI\x20API\x20error:\x20'+_0x1c0dd5['status']);throw _0x412383['status']=_0x1c0dd5['status'],_0x412383['code']=null===(_0x47d7dd=null==_0x5e9a42?void 0x0:_0x5e9a42['error'])||void 0x0===_0x47d7dd?void 0x0:_0x47d7dd['code'],_0x412383;}return{'content':null!==(_0x59b573=null===(_0x2bfe0a=null===(_0x481238=null===(_0x4f6aa4=null==_0x5e9a42?void 0x0:_0x5e9a42['choices'])||void 0x0===_0x4f6aa4?void 0x0:_0x4f6aa4[0x0])||void 0x0===_0x481238?void 0x0:_0x481238['message'])||void 0x0===_0x2bfe0a?void 0x0:_0x2bfe0a['content'])&&void 0x0!==_0x59b573?_0x59b573:'','usage':null==_0x5e9a42?void 0x0:_0x5e9a42['usage'],'raw':_0x5e9a42};}async function chatStream(_0x429e8b){var _0x1727aa,_0x190c48,_0x594c51,_0x3209ae,_0x477f49;const {apiKey:_0x35ebd6,model:_0x33d398=DEFAULT_MODEL,messages:_0x37210d,baseUrl:_0x181391=DEFAULT_BASE_URL,onChunk:_0x2da7eb}=_0x429e8b;if(!_0x35ebd6||!_0x37210d)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x10e687=_0x181391['replace'](/\/$/,'')+'/v1/chat/completions',_0x19c2df={'model':_0x33d398,'messages':normalizeMessages(_0x37210d),'stream':!0x0},_0x516de6=await fetch(_0x10e687,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x35ebd6},'body':JSON['stringify'](_0x19c2df)});if(!_0x516de6['ok']){const _0x2ccd65=await _0x516de6['json']()['catch'](()=>({})),_0x3d4d08=new Error((null===(_0x1727aa=null==_0x2ccd65?void 0x0:_0x2ccd65['error'])||void 0x0===_0x1727aa?void 0x0:_0x1727aa['message'])||'OpenAI\x20API\x20error:\x20'+_0x516de6['status']);throw _0x3d4d08['status']=_0x516de6['status'],_0x3d4d08['code']=null===(_0x190c48=null==_0x2ccd65?void 0x0:_0x2ccd65['error'])||void 0x0===_0x190c48?void 0x0:_0x190c48['code'],_0x3d4d08;}const _0x3b2d99=_0x516de6['body']['getReader'](),_0x853ff=new TextDecoder();let _0x27572e='',_0x19acd1='';for(;;){const {done:_0x1bedf2,value:_0x1bfe88}=await _0x3b2d99['read']();if(_0x1bedf2)break;_0x19acd1+=_0x853ff['decode'](_0x1bfe88,{'stream':!0x0});const _0x30438a=_0x19acd1['split']('\x0a');_0x19acd1=_0x30438a['pop']()||'';for(const _0x433aee of _0x30438a){const _0x292f57=_0x433aee['trim']();if(''!==_0x292f57&&'data:\x20[DONE]'!==_0x292f57&&_0x292f57['startsWith']('data:\x20'))try{const _0x3943b7=JSON['parse'](_0x292f57['slice'](0x6)),_0x12c1d7=null===(_0x477f49=null===(_0x3209ae=null===(_0x594c51=null==_0x3943b7?void 0x0:_0x3943b7['choices'])||void 0x0===_0x594c51?void 0x0:_0x594c51[0x0])||void 0x0===_0x3209ae?void 0x0:_0x3209ae['delta'])||void 0x0===_0x477f49?void 0x0:_0x477f49['content'];'string'==typeof _0x12c1d7&&(_0x27572e+=_0x12c1d7,_0x2da7eb&&_0x2da7eb(_0x12c1d7));}catch(_0x18f635){}}}return{'content':_0x27572e};}
|
|
@@ -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:_0x481071}){this['url']=_0x481071;}async['send'](_0x476e98){const _0x54ca24=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0x476e98)});if(!_0x54ca24['ok']){const _0x100527=await _0x54ca24['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0x100527);}return await _0x54ca24['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(_0x1a30c3=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x1a30c3||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x8a4d4){return new Promise((_0x2b618c,_0x46deda)=>{this['socket']=new this['WebSocketImpl'](_0x8a4d4),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x2b618c(!0x0)),this['_on']('error',_0x536b69=>{console['error']('WS\x20error',_0x536b69),_0x46deda(_0x536b69);}),this['_on']('close',_0x4098fc=>{const _0x2b892d=null==_0x4098fc?void 0x0:_0x4098fc['code'],_0x419a31=null==_0x4098fc?void 0x0:_0x4098fc['reason'];this['emit']('close',{'code':_0x2b892d,'reason':_0x419a31});}),this['_on']('message',async(_0x194773,_0x4f6852)=>{var _0x41fd56,_0x117ebe=null!==(_0x41fd56=null==_0x194773?void 0x0:_0x194773['data'])&&void 0x0!==_0x41fd56?_0x41fd56:_0x194773;'undefined'!=typeof Blob&&_0x117ebe instanceof Blob&&(_0x117ebe=await _0x117ebe['arrayBuffer']());const _0x4f3197=(0x0,frame_js_1['decodePacket'])(_0x117ebe);_0x4f3197&&this['emit']('message',_0x4f3197,_0x4f6852);});});}['_on'](_0x39a410,_0x38109e){this['socket']['on']?this['socket']['on'](_0x39a410,_0x38109e):this['socket']['on'+_0x39a410]=_0x38109e;}['send'](_0x986199){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x986199);}['sendBinary'](_0x4f2957){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x4f2957);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x201725;null===(_0x201725=this['socket'])||void 0x0===_0x201725||_0x201725['close']();}}exports['WebsocketTransport']=WebsocketTransport;
|
package/dist/cjs/utils/buffer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function toUint8(
|
|
1
|
+
'use strict';function toUint8(_0x1dfe92){return'undefined'!=typeof Buffer?Buffer['from'](_0x1dfe92,'utf8'):new TextEncoder()['encode'](_0x1dfe92);}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(_0x5c121e,_0x1751a7){const _0x15bc6e=Buffer['from'](JSON['stringify'](_0x5c121e)),_0x5b1ed5=Buffer['isBuffer'](_0x1751a7)?_0x1751a7:Buffer['from'](_0x1751a7),_0xb6e358=Buffer['alloc'](0x4+_0x15bc6e['length']+0x4+_0x5b1ed5['length']);let _0x271585=0x0;return _0xb6e358['writeUInt32BE'](_0x15bc6e['length'],_0x271585),_0x271585+=0x4,_0x15bc6e['copy'](_0xb6e358,_0x271585),_0x271585+=_0x15bc6e['length'],_0xb6e358['writeUInt32BE'](_0x5b1ed5['length'],_0x271585),_0x271585+=0x4,_0x5b1ed5['copy'](_0xb6e358,_0x271585),_0xb6e358;}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['framePacket']=framePacket,exports['decodePacket']=decodePacket;let internalBuffer=Buffer['alloc'](0x0);function decodePacket(_0x775088){try{Buffer['isBuffer'](_0x775088)||(_0x775088=Buffer['from'](_0x775088)),internalBuffer=Buffer['concat']([internalBuffer,_0x775088]);let _0x5e6ba2=0x0;if(internalBuffer['length']<0x4)return null;const _0x545b2a=internalBuffer['readUInt32BE'](_0x5e6ba2);if(_0x5e6ba2+=0x4,internalBuffer['length']<_0x5e6ba2+_0x545b2a)return null;const _0x300b09=internalBuffer['slice'](_0x5e6ba2,_0x5e6ba2+_0x545b2a),_0x4e5bcb=JSON['parse'](_0x300b09['toString']());if(_0x5e6ba2+=_0x545b2a,internalBuffer['length']<_0x5e6ba2+0x4)return null;const _0x35c1f8=internalBuffer['readUInt32BE'](_0x5e6ba2);if(_0x5e6ba2+=0x4,internalBuffer['length']<_0x5e6ba2+_0x35c1f8)return null;const _0x3a5523=internalBuffer['slice'](_0x5e6ba2,_0x5e6ba2+_0x35c1f8);_0x5e6ba2+=_0x35c1f8,internalBuffer=internalBuffer['slice'](_0x5e6ba2);let _0x223e6a=_0x3a5523;if('text'===_0x4e5bcb['type'])try{_0x223e6a=JSON['parse'](_0x3a5523['toString']('utf8'));}catch{_0x223e6a=_0x3a5523;}return{'metadata':_0x4e5bcb,'data':_0x223e6a};}catch(_0x28318a){return console['error']('decodePacket\x20error:',_0x28318a),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=(_0x23dd5d,_0x57f943)=>_0x57f943['includes'](':')?_0x57f943:_0x23dd5d+':'+_0x57f943;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(_0x5e7ac3){this['buffer']=_0x5e7ac3;}['raw'](){return this['buffer'];}['toString'](_0x445e97='utf8'){return this['buffer']['toString'](_0x445e97);}['toJSON'](_0x541f3c='utf8'){try{return JSON['parse'](this['buffer']['toString'](_0x541f3c));}catch(_0x22ff8c){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
240
|
var _defaultWsUrl = "wss://api.dnotifier.com/ecs/ws";
|
|
241
|
+
var _defaultAuthUrl = "https://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 _0x31f4e1 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 _0x3ae2da}from'./providers/openai.js';const _defaultWsUrl='wss://api.dnotifier.com/ecs/ws',_defaultAuthUrl='https://api.dnotifier.com/ecs/api/v1/sdk/auth';export class DNotifier{constructor({appId:_0x109ce3,secret:_0x380fe0,transport:_0x85713a,userId:_0x5e1876,url:_0x2e666c,onConnected:_0x17fb61,onMessage:_0x39095f,onDisconnected:_0x176849,WebSocketImpl:_0x24048a}){if(!(_0x109ce3&&_0x380fe0&&_0x85713a&&_0x5e1876))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0x109ce3,this['secret']=_0x380fe0,this['userId']=_0x5e1876,this['url']=null!=_0x2e666c?_0x2e666c:_defaultWsUrl,this['onConnectedCallback']=_0x17fb61||(()=>{}),this['onMessageCallback']=_0x39095f||(()=>{}),this['onDisconnectedCallback']=_0x176849||(()=>{}),this['isConnected']=!0x1,this['aiEnabled']=!0x1,this['transport']='ws'===_0x85713a?new WebsocketTransport(_0x24048a):new HttpTransport();}async['connect'](){var _0x34b910,_0xfa55d4;const _0x5e6211=new HttpTransport({'url':_defaultAuthUrl}),_0x39dbf5=await _0x5e6211['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0x39dbf5['_responseCode']){if(0x190===_0x39dbf5['_responseCode'])throw new Error(_0x39dbf5['_responseData']);throw new Error('Authentication\x20Failed.');}this['_authResponse']=_0x39dbf5['_responseData'],this['authToken']=_0x39dbf5['_responseData']['token'],this['aiEnabled']=null!==(_0xfa55d4=null===(_0x34b910=_0x39dbf5['_responseData']['limits'])||void 0x0===_0x34b910?void 0x0:_0x34b910['aiEnabled'])&&void 0x0!==_0xfa55d4&&_0xfa55d4,await this['transport']['connect'](this['url']);const _0x3d7cf5={'type':'text','code':0x65,'appId':this['appId'],'sender':prefixId(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0x450c17=toUint8(JSON['stringify']({'token':this['authToken']})),_0x2181cb=framePacket(_0x3d7cf5,_0x450c17);this['transport']['sendBinary'](_0x2181cb);let _0x40c1cf=!0x1;this['transport']['on']('message',_0x4e2cad=>{try{const {metadata:_0x4bcff3,data:_0x4d3d04}=_0x4e2cad;if(!_0x40c1cf&&'102'===_0x4bcff3['packet']['code']&&_0x4bcff3['packet']['sender']['includes'](prefixId(this['appId'],this['userId'])))return _0x40c1cf=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x40c1cf&&this['onMessageCallback']({'metadata':{'sender':_0x4bcff3['packet']['sender'],'timestamp':_0x4bcff3['packet']['timestamp']},'payload':new Payload(_0x4d3d04)});}catch(_0x446923){console['error']('Packet\x20error:',_0x446923);}}),this['transport']['on']('close',({code:_0x561577,reason:_0x151919})=>{const _0x478ac8=this['isConnected'];this['isConnected']=!0x1,_0x478ac8&&this['onDisconnectedCallback']&&this['onDisconnectedCallback']({'code':_0x561577,'reason':_0x151919||'Disconnected'});}),this['transport']['on']('error',_0x7d2d5d=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x7d2d5d?void 0x0:_0x7d2d5d['message'])||'Transport\x20error'});});}['getPlanLimits'](){var _0x10663f,_0x398735,_0x582ff1,_0x3ffc95,_0x1ea032,_0x4d4fbc,_0x57d0b6,_0x399c1e,_0x34ef6d,_0x41026b,_0x120a3b,_0x1540e2;if(!this['isConnected'])throw new Error('Not\x20connected');const _0x2a2511=null===(_0x10663f=this['_authResponse'])||void 0x0===_0x10663f?void 0x0:_0x10663f['limits'];if(!_0x2a2511)return null;const _0x490feb=null!==(_0x398735=_0x2a2511['aiEnabled'])&&void 0x0!==_0x398735&&_0x398735;return{'messagesHardLimit':_0x2a2511['messagesHardLimit'],'maxAIRequestsPerMonth':_0x490feb&&null!==(_0x3ffc95=null===(_0x582ff1=_0x2a2511['ai_limits'])||void 0x0===_0x582ff1?void 0x0:_0x582ff1['maxRequestsPerMonth'])&&void 0x0!==_0x3ffc95?_0x3ffc95:0x0,'maxAIWordsPerMonth':_0x490feb&&null!==(_0x4d4fbc=null===(_0x1ea032=_0x2a2511['ai_limits'])||void 0x0===_0x1ea032?void 0x0:_0x1ea032['maxAIWordsPerMonth'])&&void 0x0!==_0x4d4fbc?_0x4d4fbc:0x0,'knowledgeBaseMaxWords':_0x490feb&&null!==(_0x399c1e=null===(_0x57d0b6=_0x2a2511['knowledge_base_limits'])||void 0x0===_0x57d0b6?void 0x0:_0x57d0b6['maxWords'])&&void 0x0!==_0x399c1e?_0x399c1e:0x0,'aiEnabled':_0x490feb,'maxUsers':null!==(_0x41026b=null===(_0x34ef6d=_0x2a2511['db_storage_limits'])||void 0x0===_0x34ef6d?void 0x0:_0x34ef6d['maxUsers'])&&void 0x0!==_0x41026b?_0x41026b:0x0,'maxRowsPerUser':null!==(_0x1540e2=null===(_0x120a3b=_0x2a2511['db_storage_limits'])||void 0x0===_0x120a3b?void 0x0:_0x120a3b['maxRowsPerUser'])&&void 0x0!==_0x1540e2?_0x1540e2:0x0};}['send']({senderId:_0xc44f25,receiverId:_0x33ad69,receiverIds:_0x514142,data:_0x1c96fd}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0xc44f25)throw new Error('senderId\x20required');if(!_0x33ad69&&!_0x514142)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x5e33c5=null!=_0x514142?_0x514142:[_0x33ad69],_0x2546ad={'id':_0x31f4e1['randomUUID'](),'type':'text','code':0xc8,'appId':this['appId'],'sender':prefixId(this['appId'],_0xc44f25),'receivers':_0x5e33c5['map'](_0x396c8b=>prefixId(this['appId'],_0x396c8b)),'timestamp':Date['now'](),'token':this['authToken']},_0x45ba34=toUint8(JSON['stringify'](_0x1c96fd)),_0x2cc662=framePacket(_0x2546ad,_0x45ba34);this['transport']['sendBinary'](_0x2cc662);}['sendAI']({senderId:_0x1e8d18,message:_0x33ff1d}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x1e8d18)throw new Error('senderId\x20required');const _0x1fa398={'id':_0x31f4e1['randomUUID'](),'type':'ai','code':0x12c,'appId':this['appId'],'sender':prefixId(this['appId'],_0x1e8d18),'receiverId':prefixId(this['appId'],_0x1e8d18),'timestamp':Date['now'](),'token':this['authToken']},_0xba4ae=toUint8(JSON['stringify'](_0x33ff1d)),_0x55d010=framePacket(_0x1fa398,_0xba4ae);this['transport']['sendBinary'](_0x55d010);}['fetchAIHistory']({senderId:_0x5a6e1a}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x5a6e1a)throw new Error('senderId\x20required');const _0xaed7fd={'id':_0x31f4e1['randomUUID'](),'type':'ai','code':0x12d,'appId':this['appId'],'sender':prefixId(this['appId'],_0x5a6e1a),'timestamp':Date['now'](),'token':this['authToken']},_0x5ebb80=toUint8(JSON['stringify']({})),_0xb25183=framePacket(_0xaed7fd,_0x5ebb80);this['transport']['sendBinary'](_0xb25183);}['sendBinary']({senderId:_0x2decc0,receiverIds:_0x53cdab,buffer:_0x4da3cf,type:_0x44bb34='binary'}){if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x2decc0)throw new Error('senderId\x20required');if(!_0x4da3cf)throw new Error('buffer\x20is\x20required');const _0x2d3cb8={'type':_0x44bb34,'code':0xca,'appId':this['appId'],'sender':prefixId(this['appId'],_0x2decc0),'receivers':_0x53cdab['map'](_0x219b93=>prefixId(this['appId'],_0x219b93)),'timestamp':Date['now'](),'token':this['authToken']},_0x3e7345=framePacket(_0x2d3cb8,_0x4da3cf);this['transport']['sendBinary'](_0x3e7345);}async['sendWithOpenAI']({senderId:_0x532290,message:_0x599762,openaiApiKey:_0x33cd68,model:_0x20afa9,baseUrl:_0xe50e9f}){if(!this['aiEnabled'])throw new Error('AI\x20is\x20not\x20enabled\x20for\x20this\x20subscription.');if(!this['isConnected'])throw new Error('Not\x20connected');if(!_0x532290)throw new Error('senderId\x20is\x20required');if(!_0x599762)throw new Error('message\x20is\x20required');this['sendAI']({'senderId':_0x532290,'message':_0x599762});}}
|
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(_0x11c81d){if('string'==typeof _0x11c81d)return[{'role':'user','content':_0x11c81d}];if(Array['isArray'](_0x11c81d)&&_0x11c81d['length']>0x0)return _0x11c81d['map'](_0x4bcf3d=>({'role':_0x4bcf3d['role']||'user','content':'string'==typeof _0x4bcf3d['content']?_0x4bcf3d['content']:String(_0x4bcf3d['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}export async function chat(_0x1622b0){var _0xdd8dbb,_0x1a234e,_0x32762f,_0x14b5ae,_0x419e9f,_0x418cb8;const {apiKey:_0x1e43f3,model:_0x91b0a9=DEFAULT_MODEL,messages:_0x160ab4,baseUrl:_0x26efc8=DEFAULT_BASE_URL}=_0x1622b0;if(!_0x1e43f3||!_0x160ab4)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x12b184=_0x26efc8['replace'](/\/$/,'')+'/v1/chat/completions',_0x6f4c52={'model':_0x91b0a9,'messages':normalizeMessages(_0x160ab4),'stream':!0x1},_0x224c38=await fetch(_0x12b184,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x1e43f3},'body':JSON['stringify'](_0x6f4c52)}),_0x1d89e4=await _0x224c38['json']();if(!_0x224c38['ok']){const _0x4cf6ff=new Error((null===(_0xdd8dbb=null==_0x1d89e4?void 0x0:_0x1d89e4['error'])||void 0x0===_0xdd8dbb?void 0x0:_0xdd8dbb['message'])||'OpenAI\x20API\x20error:\x20'+_0x224c38['status']);throw _0x4cf6ff['status']=_0x224c38['status'],_0x4cf6ff['code']=null===(_0x1a234e=null==_0x1d89e4?void 0x0:_0x1d89e4['error'])||void 0x0===_0x1a234e?void 0x0:_0x1a234e['code'],_0x4cf6ff;}return{'content':null!==(_0x418cb8=null===(_0x419e9f=null===(_0x14b5ae=null===(_0x32762f=null==_0x1d89e4?void 0x0:_0x1d89e4['choices'])||void 0x0===_0x32762f?void 0x0:_0x32762f[0x0])||void 0x0===_0x14b5ae?void 0x0:_0x14b5ae['message'])||void 0x0===_0x419e9f?void 0x0:_0x419e9f['content'])&&void 0x0!==_0x418cb8?_0x418cb8:'','usage':null==_0x1d89e4?void 0x0:_0x1d89e4['usage'],'raw':_0x1d89e4};}export async function chatStream(_0xdf6b84){var _0x24d47c,_0x82689e,_0x324b28,_0x55a775,_0x24d228;const {apiKey:_0x38056f,model:_0x12fa5f=DEFAULT_MODEL,messages:_0x497862,baseUrl:_0x23e38f=DEFAULT_BASE_URL,onChunk:_0x339fad}=_0xdf6b84;if(!_0x38056f||!_0x497862)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0xa3def9=_0x23e38f['replace'](/\/$/,'')+'/v1/chat/completions',_0x3af0bc={'model':_0x12fa5f,'messages':normalizeMessages(_0x497862),'stream':!0x0},_0x190eff=await fetch(_0xa3def9,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x38056f},'body':JSON['stringify'](_0x3af0bc)});if(!_0x190eff['ok']){const _0x16435e=await _0x190eff['json']()['catch'](()=>({})),_0x426d62=new Error((null===(_0x24d47c=null==_0x16435e?void 0x0:_0x16435e['error'])||void 0x0===_0x24d47c?void 0x0:_0x24d47c['message'])||'OpenAI\x20API\x20error:\x20'+_0x190eff['status']);throw _0x426d62['status']=_0x190eff['status'],_0x426d62['code']=null===(_0x82689e=null==_0x16435e?void 0x0:_0x16435e['error'])||void 0x0===_0x82689e?void 0x0:_0x82689e['code'],_0x426d62;}const _0x5dc678=_0x190eff['body']['getReader'](),_0x3ccbde=new TextDecoder();let _0x1cd4a4='',_0x2c56f4='';for(;;){const {done:_0x22445a,value:_0x35428b}=await _0x5dc678['read']();if(_0x22445a)break;_0x2c56f4+=_0x3ccbde['decode'](_0x35428b,{'stream':!0x0});const _0x342cd5=_0x2c56f4['split']('\x0a');_0x2c56f4=_0x342cd5['pop']()||'';for(const _0x3d06bc of _0x342cd5){const _0x117027=_0x3d06bc['trim']();if(''!==_0x117027&&'data:\x20[DONE]'!==_0x117027&&_0x117027['startsWith']('data:\x20'))try{const _0x4f5cac=JSON['parse'](_0x117027['slice'](0x6)),_0x3172c2=null===(_0x24d228=null===(_0x55a775=null===(_0x324b28=null==_0x4f5cac?void 0x0:_0x4f5cac['choices'])||void 0x0===_0x324b28?void 0x0:_0x324b28[0x0])||void 0x0===_0x55a775?void 0x0:_0x55a775['delta'])||void 0x0===_0x24d228?void 0x0:_0x24d228['content'];'string'==typeof _0x3172c2&&(_0x1cd4a4+=_0x3172c2,_0x339fad&&_0x339fad(_0x3172c2));}catch(_0x49f8b0){}}}return{'content':_0x1cd4a4};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export class HttpTransport{constructor({url:
|
|
1
|
+
export class HttpTransport{constructor({url:_0x172890}){this['url']=_0x172890;}async['send'](_0x2f6ab7){const _0x5a94fc=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0x2f6ab7)});if(!_0x5a94fc['ok']){const _0x5f584d=await _0x5a94fc['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0x5f584d);}return await _0x5a94fc['json']();}['sendBinary'](){throw new Error('Binary\x20is\x20not\x20supported\x20over\x20HTTP\x20yet');}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _0x47fa2a from'events';import{decodePacket}from'../utils/frame.js';export class WebsocketTransport extends _0x47fa2a{constructor(_0x8e02e9=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x8e02e9||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x45aae1){return new Promise((_0x34d540,_0x4b42d0)=>{this['socket']=new this['WebSocketImpl'](_0x45aae1),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x34d540(!0x0)),this['_on']('error',_0x21a39f=>{console['error']('WS\x20error',_0x21a39f),_0x4b42d0(_0x21a39f);}),this['_on']('close',_0x2d40c2=>{const _0xd45a93=null==_0x2d40c2?void 0x0:_0x2d40c2['code'],_0x3e35ac=null==_0x2d40c2?void 0x0:_0x2d40c2['reason'];this['emit']('close',{'code':_0xd45a93,'reason':_0x3e35ac});}),this['_on']('message',async(_0x260056,_0x21e1e0)=>{var _0x26fa5d,_0x271d24=null!==(_0x26fa5d=null==_0x260056?void 0x0:_0x260056['data'])&&void 0x0!==_0x26fa5d?_0x26fa5d:_0x260056;'undefined'!=typeof Blob&&_0x271d24 instanceof Blob&&(_0x271d24=await _0x271d24['arrayBuffer']());const _0x1198e8=decodePacket(_0x271d24);_0x1198e8&&this['emit']('message',_0x1198e8,_0x21e1e0);});});}['_on'](_0x21ce3b,_0x38ef54){this['socket']['on']?this['socket']['on'](_0x21ce3b,_0x38ef54):this['socket']['on'+_0x21ce3b]=_0x38ef54;}['send'](_0x37b6e7){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x37b6e7);}['sendBinary'](_0x297888){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x297888);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x3fde14;null===(_0x3fde14=this['socket'])||void 0x0===_0x3fde14||_0x3fde14['close']();}}
|
package/dist/utils/buffer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function toUint8(
|
|
1
|
+
export function toUint8(_0x38b3a0){return'undefined'!=typeof Buffer?Buffer['from'](_0x38b3a0,'utf8'):new TextEncoder()['encode'](_0x38b3a0);}
|
package/dist/utils/frame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function framePacket(
|
|
1
|
+
export function framePacket(_0x12666f,_0xd8806a){const _0x398f5c=Buffer['from'](JSON['stringify'](_0x12666f)),_0x1e1f16=Buffer['isBuffer'](_0xd8806a)?_0xd8806a:Buffer['from'](_0xd8806a),_0x4ab99f=Buffer['alloc'](0x4+_0x398f5c['length']+0x4+_0x1e1f16['length']);let _0x1f03fe=0x0;return _0x4ab99f['writeUInt32BE'](_0x398f5c['length'],_0x1f03fe),_0x1f03fe+=0x4,_0x398f5c['copy'](_0x4ab99f,_0x1f03fe),_0x1f03fe+=_0x398f5c['length'],_0x4ab99f['writeUInt32BE'](_0x1e1f16['length'],_0x1f03fe),_0x1f03fe+=0x4,_0x1e1f16['copy'](_0x4ab99f,_0x1f03fe),_0x4ab99f;}let internalBuffer=Buffer['alloc'](0x0);export function decodePacket(_0x5a4f31){try{Buffer['isBuffer'](_0x5a4f31)||(_0x5a4f31=Buffer['from'](_0x5a4f31)),internalBuffer=Buffer['concat']([internalBuffer,_0x5a4f31]);let _0x258b4b=0x0;if(internalBuffer['length']<0x4)return null;const _0x5874fa=internalBuffer['readUInt32BE'](_0x258b4b);if(_0x258b4b+=0x4,internalBuffer['length']<_0x258b4b+_0x5874fa)return null;const _0x52ebc0=internalBuffer['slice'](_0x258b4b,_0x258b4b+_0x5874fa),_0x287d05=JSON['parse'](_0x52ebc0['toString']());if(_0x258b4b+=_0x5874fa,internalBuffer['length']<_0x258b4b+0x4)return null;const _0x4b0340=internalBuffer['readUInt32BE'](_0x258b4b);if(_0x258b4b+=0x4,internalBuffer['length']<_0x258b4b+_0x4b0340)return null;const _0x29b577=internalBuffer['slice'](_0x258b4b,_0x258b4b+_0x4b0340);_0x258b4b+=_0x4b0340,internalBuffer=internalBuffer['slice'](_0x258b4b);let _0x2de255=_0x29b577;if('text'===_0x287d05['type'])try{_0x2de255=JSON['parse'](_0x29b577['toString']('utf8'));}catch{_0x2de255=_0x29b577;}return{'metadata':_0x287d05,'data':_0x2de255};}catch(_0x254413){return console['error']('decodePacket\x20error:',_0x254413),null;}}
|
package/dist/utils/id.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const prefixId=(
|
|
1
|
+
export const prefixId=(_0xdbecd4,_0x18937f)=>_0x18937f['includes'](':')?_0x18937f:_0xdbecd4+':'+_0x18937f;
|
package/dist/utils/payload.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class Payload{constructor(
|
|
1
|
+
export class Payload{constructor(_0x21d1ef){this['buffer']=_0x21d1ef;}['raw'](){return this['buffer'];}['toString'](_0x382c98='utf8'){return this['buffer']['toString'](_0x382c98);}['toJSON'](_0x2a8c01='utf8'){try{return JSON['parse'](this['buffer']['toString'](_0x2a8c01));}catch(_0x23337c){return null;}}['toBase64'](){return this['buffer']['toString']('base64');}}
|