@webex/internal-plugin-llm 2.23.0
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/README.md +55 -0
- package/dist/constants.js +13 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.js +156 -0
- package/dist/llm.js.map +1 -0
- package/dist/llm.types.js +8 -0
- package/dist/llm.types.js.map +1 -0
- package/package.json +24 -0
- package/src/constants.ts +2 -0
- package/src/index.js +8 -0
- package/src/llm.ts +125 -0
- package/src/llm.types.ts +10 -0
- package/test/unit/spec/llm.js +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @webex/internal-plugin-llm
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
+
|
|
5
|
+
> Plugin for the LLM service
|
|
6
|
+
|
|
7
|
+
This is an internal Cisco Webex plugin. As such, it does not strictly adhere to semantic versioning. Use at your own risk. If you're not working on one of our first party clients, please look at our [developer api](https://developer.webex.com/) and stick to our public plugins.
|
|
8
|
+
|
|
9
|
+
- [@webex/internal-plugin-llm](#webexinternal-plugin-llm)
|
|
10
|
+
- [Install](#install)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Maintainers](#maintainers)
|
|
13
|
+
- [Contribute](#contribute)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install --save @webex/internal-plugin-llm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
|
|
26
|
+
import '@webex/internal-plugin-llm';
|
|
27
|
+
|
|
28
|
+
import WebexCore from '@webex/webex-core';
|
|
29
|
+
|
|
30
|
+
const webex = new WebexCore();
|
|
31
|
+
// locusUrl is got from meeting.locusInfo.url;
|
|
32
|
+
// datachannelUrl is got from meeting.locusInfo.info.datachannelUrl;
|
|
33
|
+
webex.internal.llm.registerAndConnect(locusUrl, datachannelUrl);
|
|
34
|
+
|
|
35
|
+
// Checks if LLM is connected
|
|
36
|
+
webex.internal.llm.isConnected();
|
|
37
|
+
|
|
38
|
+
// Disconnect LLM connection
|
|
39
|
+
webex.internal.llm.disconnectLLM();
|
|
40
|
+
|
|
41
|
+
// Get Locus URL
|
|
42
|
+
webex.internal.llm.getLocusUrl();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Maintainers
|
|
46
|
+
|
|
47
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
48
|
+
|
|
49
|
+
## Contribute
|
|
50
|
+
|
|
51
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
© 2016-2022 Cisco and/or its affiliates. All Rights Reserved.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
exports.LLM = void 0;
|
|
10
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
11
|
+
var LLM = 'llm';
|
|
12
|
+
exports.LLM = LLM;
|
|
13
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LLM"],"sources":["constants.ts"],"sourcesContent":["// eslint-disable-next-line import/prefer-default-export\nexport const LLM = 'llm';\n"],"mappings":";;;;;;;;;AAAA;AACO,IAAMA,GAAG,GAAG,KAAZ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime-corejs2/helpers/typeof");
|
|
4
|
+
|
|
5
|
+
var _WeakMap = require("@babel/runtime-corejs2/core-js/weak-map");
|
|
6
|
+
|
|
7
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
8
|
+
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
10
|
+
|
|
11
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
12
|
+
|
|
13
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
_Object$defineProperty(exports, "default", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function get() {
|
|
20
|
+
return _llm2.default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
var WebexCore = _interopRequireWildcard(require("@webex/webex-core"));
|
|
25
|
+
|
|
26
|
+
var _llm = _interopRequireWildcard(require("@webex/internal-plugin-llm/src/llm"));
|
|
27
|
+
|
|
28
|
+
var _llm2 = _interopRequireDefault(require("./llm"));
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
WebexCore.registerInternalPlugin('llm', _llm.default, {
|
|
35
|
+
config: _llm.config
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WebexCore","registerInternalPlugin","LLMChannel","config"],"sources":["index.js"],"sourcesContent":["import * as WebexCore from '@webex/webex-core';\nimport LLMChannel, {config} from '@webex/internal-plugin-llm/src/llm';\n\nWebexCore.registerInternalPlugin('llm', LLMChannel, {\n config,\n});\n\nexport {default} from './llm';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAMA;;;;;;AAJAA,SAAS,CAACC,sBAAV,CAAiC,KAAjC,EAAwCC,YAAxC,EAAoD;EAClDC,MAAM,EAANA;AADkD,CAApD"}
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
+
|
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
6
|
+
|
|
7
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
8
|
+
|
|
9
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
exports.default = exports.config = void 0;
|
|
14
|
+
|
|
15
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
16
|
+
|
|
17
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
18
|
+
|
|
19
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
|
|
20
|
+
|
|
21
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
22
|
+
|
|
23
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
24
|
+
|
|
25
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
26
|
+
|
|
27
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
28
|
+
|
|
29
|
+
var _internalPluginMercury = _interopRequireDefault(require("@webex/internal-plugin-mercury"));
|
|
30
|
+
|
|
31
|
+
var _constants = require("./constants");
|
|
32
|
+
|
|
33
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
34
|
+
|
|
35
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
36
|
+
|
|
37
|
+
var config = {
|
|
38
|
+
llm: {
|
|
39
|
+
/**
|
|
40
|
+
* Milliseconds between pings sent up the socket
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
pingInterval: process.env.MERCURY_PING_INTERVAL || 15000,
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Milliseconds to wait for a pong before declaring the connection dead
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
pongTimeout: process.env.MERCURY_PONG_TIMEOUT || 14000,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Maximum milliseconds between connection attempts
|
|
53
|
+
* @type {Number}
|
|
54
|
+
*/
|
|
55
|
+
backoffTimeMax: process.env.MERCURY_BACKOFF_TIME_MAX || 32000,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Initial milliseconds between connection attempts
|
|
59
|
+
* @type {Number}
|
|
60
|
+
*/
|
|
61
|
+
backoffTimeReset: process.env.MERCURY_BACKOFF_TIME_RESET || 1000,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Milliseconds to wait for a close frame before declaring the socket dead and
|
|
65
|
+
* discarding it
|
|
66
|
+
* @type {[type]}
|
|
67
|
+
*/
|
|
68
|
+
forceCloseDelay: process.env.MERCURY_FORCE_CLOSE_DELAY || 2000
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* LLMChannel to provide socket connections
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
exports.config = config;
|
|
76
|
+
|
|
77
|
+
var LLMChannel = /*#__PURE__*/function (_ref) {
|
|
78
|
+
(0, _inherits2.default)(LLMChannel, _ref);
|
|
79
|
+
|
|
80
|
+
var _super = _createSuper(LLMChannel);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* If the LLM plugin has been registered and listening
|
|
84
|
+
* @instance
|
|
85
|
+
* @type {Boolean}
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Initializes the LLM Plugin
|
|
91
|
+
* @constructor
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
function LLMChannel() {
|
|
95
|
+
var _this;
|
|
96
|
+
|
|
97
|
+
(0, _classCallCheck2.default)(this, LLMChannel);
|
|
98
|
+
|
|
99
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
100
|
+
args[_key] = arguments[_key];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// eslint-disable-next-line constructor-super
|
|
104
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
105
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "namespace", _constants.LLM);
|
|
106
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "registered", false);
|
|
107
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "webex", void 0);
|
|
108
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "webSocketUrl", void 0);
|
|
109
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "binding", void 0);
|
|
110
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "locusUrl", void 0);
|
|
111
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "register", function (llmSocketUrl) {
|
|
112
|
+
return _this.request({
|
|
113
|
+
method: 'POST',
|
|
114
|
+
url: llmSocketUrl
|
|
115
|
+
}).then(function (res) {
|
|
116
|
+
_this.webSocketUrl = res.body.webSocketUrl;
|
|
117
|
+
_this.binding = res.body.binding;
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "registerAndConnect", function (locusUrl, datachannelUrl) {
|
|
121
|
+
return _this.register(datachannelUrl).then(function () {
|
|
122
|
+
if (!locusUrl || !datachannelUrl) return undefined;
|
|
123
|
+
_this.locusUrl = locusUrl;
|
|
124
|
+
|
|
125
|
+
_this.connect(_this.webSocketUrl).then(function () {
|
|
126
|
+
_this.registered = true;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isConnected", function () {
|
|
131
|
+
return _this.registered;
|
|
132
|
+
});
|
|
133
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getBinding", function () {
|
|
134
|
+
return _this.binding;
|
|
135
|
+
});
|
|
136
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getLocusUrl", function () {
|
|
137
|
+
return _this.locusUrl;
|
|
138
|
+
});
|
|
139
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "disconnectLLM", function () {
|
|
140
|
+
return _this.disconnect();
|
|
141
|
+
});
|
|
142
|
+
_this.registered = false;
|
|
143
|
+
return _this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Register to the websocket
|
|
147
|
+
* @param {string} llmSocketUrl
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
return (0, _createClass2.default)(LLMChannel);
|
|
153
|
+
}(_internalPluginMercury.default);
|
|
154
|
+
|
|
155
|
+
exports.default = LLMChannel;
|
|
156
|
+
//# sourceMappingURL=llm.js.map
|
package/dist/llm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["config","llm","pingInterval","process","env","MERCURY_PING_INTERVAL","pongTimeout","MERCURY_PONG_TIMEOUT","backoffTimeMax","MERCURY_BACKOFF_TIME_MAX","backoffTimeReset","MERCURY_BACKOFF_TIME_RESET","forceCloseDelay","MERCURY_FORCE_CLOSE_DELAY","LLMChannel","args","LLM","llmSocketUrl","request","method","url","then","res","webSocketUrl","body","binding","locusUrl","datachannelUrl","register","undefined","connect","registered","disconnect","Mercury"],"sources":["llm.ts"],"sourcesContent":["import Mercury from '@webex/internal-plugin-mercury';\n\n\nimport {LLM} from './constants';\n// eslint-disable-next-line no-unused-vars\nimport {ILLMChannel} from './llm.types';\n\nexport const config = {\n llm: {\n /**\n * Milliseconds between pings sent up the socket\n * @type {number}\n */\n pingInterval: process.env.MERCURY_PING_INTERVAL || 15000,\n /**\n * Milliseconds to wait for a pong before declaring the connection dead\n * @type {number}\n */\n pongTimeout: process.env.MERCURY_PONG_TIMEOUT || 14000,\n /**\n * Maximum milliseconds between connection attempts\n * @type {Number}\n */\n backoffTimeMax: process.env.MERCURY_BACKOFF_TIME_MAX || 32000,\n /**\n * Initial milliseconds between connection attempts\n * @type {Number}\n */\n backoffTimeReset: process.env.MERCURY_BACKOFF_TIME_RESET || 1000,\n /**\n * Milliseconds to wait for a close frame before declaring the socket dead and\n * discarding it\n * @type {[type]}\n */\n forceCloseDelay: process.env.MERCURY_FORCE_CLOSE_DELAY || 2000,\n },\n};\n\n/**\n * LLMChannel to provide socket connections\n */\nexport default class LLMChannel extends (Mercury as any) implements ILLMChannel {\n namespace = LLM;\n\n /**\n * If the LLM plugin has been registered and listening\n * @instance\n * @type {Boolean}\n * @public\n */\n private registered:boolean = false;\n\n public webex: any;\n\n private webSocketUrl: string;\n\n private binding: string;\n\n private locusUrl: string;\n\n\n /**\n * Initializes the LLM Plugin\n * @constructor\n * @public\n */\n constructor(...args) {\n // eslint-disable-next-line constructor-super\n super(...args);\n\n\n this.registered = false;\n }\n\n /**\n * Register to the websocket\n * @param {string} llmSocketUrl\n * @returns {Promise<void>}\n */\n private register = (llmSocketUrl:string):Promise<void> => this.request({\n method: 'POST',\n url: llmSocketUrl,\n }).then((res: { body: { webSocketUrl: string; binding: string; }; }) => {\n this.webSocketUrl = res.body.webSocketUrl;\n this.binding = res.body.binding;\n });\n\n /**\n * Register and connect to the websocket\n * @param {string} locusUrl\n * @param {string} datachannelUrl\n * @returns {Promise<void>}\n */\n public registerAndConnect = (locusUrl:string, datachannelUrl:string):Promise<void> => this.register(datachannelUrl).then(() => {\n if(!locusUrl || !datachannelUrl) return undefined;\n this.locusUrl = locusUrl;\n this.connect(this.webSocketUrl).then(() => {\n this.registered = true;\n });\n });\n\n /**\n * Tells if LLM socket is connected\n * @returns {boolean} isRegistered\n */\n public isConnected = ():boolean => this.registered;\n\n /**\n * Tells if LLM socket is connected\n * @returns {bool} isRegistered\n */\n public getBinding = ():string => this.binding;\n\n /**\n * Get Locus URL for the connection\n * @returns {string} locus Url\n */\n public getLocusUrl = ():string => this.locusUrl;\n /**\n * Disconnects websocket connection\n * @returns Promise<void>\n */\n public disconnectLLM = () => this.disconnect()\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAGA;;;;;;AAIO,IAAMA,MAAM,GAAG;EACpBC,GAAG,EAAE;IACH;AACJ;AACA;AACA;IACIC,YAAY,EAAEC,OAAO,CAACC,GAAR,CAAYC,qBAAZ,IAAqC,KALhD;;IAMH;AACJ;AACA;AACA;IACIC,WAAW,EAAEH,OAAO,CAACC,GAAR,CAAYG,oBAAZ,IAAoC,KAV9C;;IAWH;AACJ;AACA;AACA;IACIC,cAAc,EAAEL,OAAO,CAACC,GAAR,CAAYK,wBAAZ,IAAwC,KAfrD;;IAgBH;AACJ;AACA;AACA;IACIC,gBAAgB,EAAEP,OAAO,CAACC,GAAR,CAAYO,0BAAZ,IAA0C,IApBzD;;IAqBH;AACJ;AACA;AACA;AACA;IACIC,eAAe,EAAET,OAAO,CAACC,GAAR,CAAYS,yBAAZ,IAAyC;EA1BvD;AADe,CAAf;AA+BP;AACA;AACA;;;;IACqBC,U;;;;;EAGnB;AACF;AACA;AACA;AACA;AACA;;EAYE;AACF;AACA;AACA;AACA;EACE,sBAAqB;IAAA;;IAAA;;IAAA,kCAANC,IAAM;MAANA,IAAM;IAAA;;IACnB;IACA,gDAASA,IAAT;IAFmB,wFAxBTC,cAwBS;IAAA,yFAhBQ,KAgBR;IAAA;IAAA;IAAA;IAAA;IAAA,uFAaF,UAACC,YAAD;MAAA,OAAuC,MAAKC,OAAL,CAAa;QACrEC,MAAM,EAAE,MAD6D;QAErEC,GAAG,EAAEH;MAFgE,CAAb,EAGvDI,IAHuD,CAGlD,UAACC,GAAD,EAAgE;QACtE,MAAKC,YAAL,GAAoBD,GAAG,CAACE,IAAJ,CAASD,YAA7B;QACA,MAAKE,OAAL,GAAeH,GAAG,CAACE,IAAJ,CAASC,OAAxB;MACD,CANyD,CAAvC;IAAA,CAbE;IAAA,iGA2BO,UAACC,QAAD,EAAkBC,cAAlB;MAAA,OAA0D,MAAKC,QAAL,CAAcD,cAAd,EAA8BN,IAA9B,CAAmC,YAAM;QAC7H,IAAG,CAACK,QAAD,IAAa,CAACC,cAAjB,EAAiC,OAAOE,SAAP;QACjC,MAAKH,QAAL,GAAgBA,QAAhB;;QACA,MAAKI,OAAL,CAAa,MAAKP,YAAlB,EAAgCF,IAAhC,CAAqC,YAAM;UACzC,MAAKU,UAAL,GAAkB,IAAlB;QACD,CAFD;MAGD,CANqF,CAA1D;IAAA,CA3BP;IAAA,0FAuCA;MAAA,OAAc,MAAKA,UAAnB;IAAA,CAvCA;IAAA,yFA6CD;MAAA,OAAa,MAAKN,OAAlB;IAAA,CA7CC;IAAA,0FAmDA;MAAA,OAAa,MAAKC,QAAlB;IAAA,CAnDA;IAAA,4FAwDE;MAAA,OAAM,MAAKM,UAAL,EAAN;IAAA,CAxDF;IAKnB,MAAKD,UAAL,GAAkB,KAAlB;IALmB;EAMpB;EAED;AACF;AACA;AACA;AACA;;;;EArCyCE,8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["llm.types.ts"],"sourcesContent":["\ninterface ILLMChannel{\n registerAndConnect: (locusUrl:string, datachannelUrl:string) => Promise<void>;\n isConnected: () => boolean;\n getBinding: () => string;\n getLocusUrl: () => string;\n disconnectLLM: () => Promise<void>;\n}\n// eslint-disable-next-line import/prefer-default-export\nexport {ILLMChannel};\n"],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webex/internal-plugin-llm",
|
|
3
|
+
"version": "2.23.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"devMain": "src/index.js",
|
|
8
|
+
"repository": "https://github.com/webex/webex-js-sdk/tree/master/packages/node_modules/@webex/internal-plugin-llm",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=8"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@babel/runtime-corejs2": "^7.14.8",
|
|
14
|
+
"@webex/webex-core": "2.23.0",
|
|
15
|
+
"@webex/internal-plugin-llm": "2.23.0",
|
|
16
|
+
"@webex/internal-plugin-mercury": "2.23.0",
|
|
17
|
+
"envify": "^4.1.0"
|
|
18
|
+
},
|
|
19
|
+
"browserify": {
|
|
20
|
+
"transform": [
|
|
21
|
+
"envify"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/constants.ts
ADDED
package/src/index.js
ADDED
package/src/llm.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Mercury from '@webex/internal-plugin-mercury';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import {LLM} from './constants';
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
import {ILLMChannel} from './llm.types';
|
|
7
|
+
|
|
8
|
+
export const config = {
|
|
9
|
+
llm: {
|
|
10
|
+
/**
|
|
11
|
+
* Milliseconds between pings sent up the socket
|
|
12
|
+
* @type {number}
|
|
13
|
+
*/
|
|
14
|
+
pingInterval: process.env.MERCURY_PING_INTERVAL || 15000,
|
|
15
|
+
/**
|
|
16
|
+
* Milliseconds to wait for a pong before declaring the connection dead
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
pongTimeout: process.env.MERCURY_PONG_TIMEOUT || 14000,
|
|
20
|
+
/**
|
|
21
|
+
* Maximum milliseconds between connection attempts
|
|
22
|
+
* @type {Number}
|
|
23
|
+
*/
|
|
24
|
+
backoffTimeMax: process.env.MERCURY_BACKOFF_TIME_MAX || 32000,
|
|
25
|
+
/**
|
|
26
|
+
* Initial milliseconds between connection attempts
|
|
27
|
+
* @type {Number}
|
|
28
|
+
*/
|
|
29
|
+
backoffTimeReset: process.env.MERCURY_BACKOFF_TIME_RESET || 1000,
|
|
30
|
+
/**
|
|
31
|
+
* Milliseconds to wait for a close frame before declaring the socket dead and
|
|
32
|
+
* discarding it
|
|
33
|
+
* @type {[type]}
|
|
34
|
+
*/
|
|
35
|
+
forceCloseDelay: process.env.MERCURY_FORCE_CLOSE_DELAY || 2000,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* LLMChannel to provide socket connections
|
|
41
|
+
*/
|
|
42
|
+
export default class LLMChannel extends (Mercury as any) implements ILLMChannel {
|
|
43
|
+
namespace = LLM;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* If the LLM plugin has been registered and listening
|
|
47
|
+
* @instance
|
|
48
|
+
* @type {Boolean}
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
private registered:boolean = false;
|
|
52
|
+
|
|
53
|
+
public webex: any;
|
|
54
|
+
|
|
55
|
+
private webSocketUrl: string;
|
|
56
|
+
|
|
57
|
+
private binding: string;
|
|
58
|
+
|
|
59
|
+
private locusUrl: string;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Initializes the LLM Plugin
|
|
64
|
+
* @constructor
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
constructor(...args) {
|
|
68
|
+
// eslint-disable-next-line constructor-super
|
|
69
|
+
super(...args);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
this.registered = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Register to the websocket
|
|
77
|
+
* @param {string} llmSocketUrl
|
|
78
|
+
* @returns {Promise<void>}
|
|
79
|
+
*/
|
|
80
|
+
private register = (llmSocketUrl:string):Promise<void> => this.request({
|
|
81
|
+
method: 'POST',
|
|
82
|
+
url: llmSocketUrl,
|
|
83
|
+
}).then((res: { body: { webSocketUrl: string; binding: string; }; }) => {
|
|
84
|
+
this.webSocketUrl = res.body.webSocketUrl;
|
|
85
|
+
this.binding = res.body.binding;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Register and connect to the websocket
|
|
90
|
+
* @param {string} locusUrl
|
|
91
|
+
* @param {string} datachannelUrl
|
|
92
|
+
* @returns {Promise<void>}
|
|
93
|
+
*/
|
|
94
|
+
public registerAndConnect = (locusUrl:string, datachannelUrl:string):Promise<void> => this.register(datachannelUrl).then(() => {
|
|
95
|
+
if(!locusUrl || !datachannelUrl) return undefined;
|
|
96
|
+
this.locusUrl = locusUrl;
|
|
97
|
+
this.connect(this.webSocketUrl).then(() => {
|
|
98
|
+
this.registered = true;
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tells if LLM socket is connected
|
|
104
|
+
* @returns {boolean} isRegistered
|
|
105
|
+
*/
|
|
106
|
+
public isConnected = ():boolean => this.registered;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Tells if LLM socket is connected
|
|
110
|
+
* @returns {bool} isRegistered
|
|
111
|
+
*/
|
|
112
|
+
public getBinding = ():string => this.binding;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get Locus URL for the connection
|
|
116
|
+
* @returns {string} locus Url
|
|
117
|
+
*/
|
|
118
|
+
public getLocusUrl = ():string => this.locusUrl;
|
|
119
|
+
/**
|
|
120
|
+
* Disconnects websocket connection
|
|
121
|
+
* @returns Promise<void>
|
|
122
|
+
*/
|
|
123
|
+
public disconnectLLM = () => this.disconnect()
|
|
124
|
+
}
|
|
125
|
+
|
package/src/llm.types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
interface ILLMChannel{
|
|
3
|
+
registerAndConnect: (locusUrl:string, datachannelUrl:string) => Promise<void>;
|
|
4
|
+
isConnected: () => boolean;
|
|
5
|
+
getBinding: () => string;
|
|
6
|
+
getLocusUrl: () => string;
|
|
7
|
+
disconnectLLM: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
10
|
+
export {ILLMChannel};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
2
|
+
import {assert} from '@webex/test-helper-chai';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import Mercury from '@webex/internal-plugin-mercury';
|
|
5
|
+
|
|
6
|
+
import LLMService from '@webex/internal-plugin-llm';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('plugin-llm', () => {
|
|
10
|
+
const locusUrl = 'locusUrl';
|
|
11
|
+
const datachannelUrl = 'datachannelUrl';
|
|
12
|
+
|
|
13
|
+
describe('llm', () => {
|
|
14
|
+
let webex, llmService;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
webex = new MockWebex({
|
|
18
|
+
children: {
|
|
19
|
+
mercury: Mercury,
|
|
20
|
+
llm: LLMService,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
llmService = webex.internal.llm;
|
|
25
|
+
llmService.connect = sinon.stub().resolves(true);
|
|
26
|
+
llmService.disconnect = sinon.stub().resolves(true);
|
|
27
|
+
llmService.request = sinon.stub().resolves({
|
|
28
|
+
headers: {},
|
|
29
|
+
body: {
|
|
30
|
+
binding: 'binding',
|
|
31
|
+
webSocketUrl: 'url'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
describe('#registerAndConnect', () => {
|
|
38
|
+
it('registers connection', async () => {
|
|
39
|
+
llmService.register = sinon.stub().resolves({
|
|
40
|
+
body: {
|
|
41
|
+
binding: 'binding',
|
|
42
|
+
webSocketUrl: 'url'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
assert.equal(llmService.isConnected(), false);
|
|
46
|
+
await llmService.registerAndConnect(locusUrl, datachannelUrl);
|
|
47
|
+
assert.equal(llmService.isConnected(), true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('doesn\'t registers connection for invalid input', async () => {
|
|
51
|
+
llmService.register = sinon.stub().resolves({
|
|
52
|
+
body: {
|
|
53
|
+
binding: 'binding',
|
|
54
|
+
webSocketUrl: 'url'
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
await llmService.registerAndConnect();
|
|
58
|
+
assert.equal(llmService.isConnected(), false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('#register', () => {
|
|
63
|
+
it('registers connection', async () => {
|
|
64
|
+
await llmService.register(datachannelUrl);
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
sinon.assert.calledOnceWithExactly(llmService.request, sinon.match({
|
|
68
|
+
method: 'POST',
|
|
69
|
+
url: `${datachannelUrl}`,
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
assert.equal(llmService.getBinding(), 'binding');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('#getLocusUrl', () => {
|
|
77
|
+
it('gets LocusUrl', async () => {
|
|
78
|
+
llmService.register = sinon.stub().resolves({
|
|
79
|
+
body: {
|
|
80
|
+
binding: 'binding',
|
|
81
|
+
webSocketUrl: 'url'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
await llmService.registerAndConnect(locusUrl, datachannelUrl);
|
|
85
|
+
assert.equal(llmService.getLocusUrl(), locusUrl);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('#disconnect', () => {
|
|
90
|
+
it('disconnects mercury', async () => {
|
|
91
|
+
await llmService.disconnect();
|
|
92
|
+
sinon.assert.calledOnce(llmService.disconnect);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|