@sermas/sermas-toolkit-node-sdk 1.0.0-alpha.7 → 1.0.0-alpha.9
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/config/defaults.js +18 -0
- package/dist/cjs/config/logger.js +10 -0
- package/dist/cjs/config/util.js +70 -0
- package/dist/cjs/dto/session.js +2 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/modules/auth.js +238 -0
- package/dist/cjs/modules/openai.js +63 -0
- package/dist/cjs/modules/sermas.js +233 -0
- package/dist/cjs/modules/store.js +177 -0
- package/dist/cjs/modules/tools.js +44 -0
- package/dist/cjs/modules/ui.js +124 -0
- package/dist/{modules → esm/modules}/openai.js +2 -1
- package/dist/{modules → esm/modules}/sermas.js +3 -1
- package/dist/{modules → esm/modules}/store.js +3 -2
- package/dist/{modules → esm/modules}/tools.js +2 -1
- package/dist/{modules → esm/modules}/ui.js +3 -1
- package/dist/{index.d.ts → types/index.d.ts} +3 -1
- package/dist/{modules → types/modules}/openai.d.ts +2 -2
- package/dist/{modules → types/modules}/sermas.d.ts +2 -1
- package/dist/{modules → types/modules}/store.d.ts +2 -1
- package/dist/{modules → types/modules}/tools.d.ts +2 -2
- package/dist/{modules → types/modules}/ui.d.ts +2 -1
- package/package.json +12 -5
- /package/dist/{config → esm/config}/defaults.js +0 -0
- /package/dist/{config → esm/config}/logger.js +0 -0
- /package/dist/{config → esm/config}/util.js +0 -0
- /package/dist/{dto → esm/dto}/session.js +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{modules → esm/modules}/auth.js +0 -0
- /package/dist/{config → types/config}/defaults.d.ts +0 -0
- /package/dist/{config → types/config}/logger.d.ts +0 -0
- /package/dist/{config → types/config}/util.d.ts +0 -0
- /package/dist/{dto → types/dto}/session.d.ts +0 -0
- /package/dist/{modules → types/modules}/auth.d.ts +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaults = void 0;
|
|
4
|
+
exports.defaults = {
|
|
5
|
+
auth: {
|
|
6
|
+
PUBLIC_AUTH_URL: "http://172.17.0.1:8080/keycloak",
|
|
7
|
+
PUBLIC_AUTH_REALM: "sermas-local",
|
|
8
|
+
PRIVATE_AUTH_CLIENT_ID: "platform",
|
|
9
|
+
PRIVATE_AUTH_CLIENT_SECRET: "platform",
|
|
10
|
+
PRIVATE_API_BASE_URL: "http://api:3000/api",
|
|
11
|
+
},
|
|
12
|
+
sermas: {
|
|
13
|
+
SERMAS_BASE_URL: "http://localhost:8080",
|
|
14
|
+
SERMAS_CLIENT_ID: "sermas-client",
|
|
15
|
+
SERMAS_CLIENT_SECRET: "s3cr3t",
|
|
16
|
+
SERMAS_APPID: "sermas",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLogger = void 0;
|
|
4
|
+
const winston_1 = require("winston");
|
|
5
|
+
const createLogger = (name) => (0, winston_1.createLogger)({
|
|
6
|
+
defaultMeta: { name },
|
|
7
|
+
format: winston_1.format.json(),
|
|
8
|
+
transports: new winston_1.transports.Console(),
|
|
9
|
+
});
|
|
10
|
+
exports.createLogger = createLogger;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.saveFile = exports.loadFile = exports.loadJSON = exports.saveJSON = exports.uuidv4 = void 0;
|
|
36
|
+
const fs = __importStar(require("fs/promises"));
|
|
37
|
+
const logger_js_1 = require("./logger.js");
|
|
38
|
+
var uuid_1 = require("uuid");
|
|
39
|
+
Object.defineProperty(exports, "uuidv4", { enumerable: true, get: function () { return uuid_1.v4; } });
|
|
40
|
+
const logger = (0, logger_js_1.createLogger)("util");
|
|
41
|
+
const saveJSON = (filename, dataset) => fs.writeFile(filename, JSON.stringify(dataset, null, 2));
|
|
42
|
+
exports.saveJSON = saveJSON;
|
|
43
|
+
const loadJSON = (filename) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const raw = yield (0, exports.loadFile)(filename);
|
|
46
|
+
if (raw === null)
|
|
47
|
+
return null;
|
|
48
|
+
return JSON.parse(raw);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (e instanceof Error)
|
|
52
|
+
logger.error(`Failed to load dataset: ${e.stack}`);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
exports.loadJSON = loadJSON;
|
|
57
|
+
const loadFile = (filename) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
const raw = yield fs.readFile(filename);
|
|
60
|
+
return raw.toString();
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
if (e instanceof Error)
|
|
64
|
+
logger.error(`Failed to load dataset: ${e.stack}`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
exports.loadFile = loadFile;
|
|
69
|
+
const saveFile = (filename, dataset) => fs.writeFile(filename, dataset);
|
|
70
|
+
exports.saveFile = saveFile;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SermasApp = exports.Tools = exports.UI = exports.Store = exports.OpenAIClient = exports.getAvatarTokenWithClientSecret = exports.getAvatarToken = void 0;
|
|
4
|
+
var auth_js_1 = require("./modules/auth.js");
|
|
5
|
+
Object.defineProperty(exports, "getAvatarToken", { enumerable: true, get: function () { return auth_js_1.getAvatarToken; } });
|
|
6
|
+
Object.defineProperty(exports, "getAvatarTokenWithClientSecret", { enumerable: true, get: function () { return auth_js_1.getAvatarTokenWithClientSecret; } });
|
|
7
|
+
var openai_js_1 = require("./modules/openai.js");
|
|
8
|
+
Object.defineProperty(exports, "OpenAIClient", { enumerable: true, get: function () { return openai_js_1.OpenAIClient; } });
|
|
9
|
+
var store_js_1 = require("./modules/store.js");
|
|
10
|
+
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return store_js_1.Store; } });
|
|
11
|
+
var ui_js_1 = require("./modules/ui.js");
|
|
12
|
+
Object.defineProperty(exports, "UI", { enumerable: true, get: function () { return ui_js_1.UI; } });
|
|
13
|
+
var tools_js_1 = require("./modules/tools.js");
|
|
14
|
+
Object.defineProperty(exports, "Tools", { enumerable: true, get: function () { return tools_js_1.Tools; } });
|
|
15
|
+
var sermas_js_1 = require("./modules/sermas.js");
|
|
16
|
+
Object.defineProperty(exports, "SermasApp", { enumerable: true, get: function () { return sermas_js_1.SermasApp; } });
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.getAvatarTokenWithClientSecret = exports.getAvatarToken = void 0;
|
|
36
|
+
const axios_1 = __importStar(require("axios"));
|
|
37
|
+
const https = __importStar(require("https"));
|
|
38
|
+
const defaults_js_1 = require("../config/defaults.js");
|
|
39
|
+
const logger_js_1 = require("../config/logger.js");
|
|
40
|
+
const httpsAgent = new https.Agent({
|
|
41
|
+
rejectUnauthorized: process.env.NODE_ENV !== "development",
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Returns access and refresh tokens for the given appId
|
|
45
|
+
* @param {string} appId null by default
|
|
46
|
+
* @param {AuthConfig} authConfig
|
|
47
|
+
*/
|
|
48
|
+
const getAvatarToken = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (appId = null, authConfig = defaults_js_1.defaults.auth) {
|
|
49
|
+
const logger = (0, logger_js_1.createLogger)("getAvatarToken");
|
|
50
|
+
const tokens = {};
|
|
51
|
+
let kioskToken = null;
|
|
52
|
+
const PUBLIC_AUTH_URL = authConfig.PUBLIC_AUTH_URL || defaults_js_1.defaults.auth.PUBLIC_AUTH_URL;
|
|
53
|
+
const PUBLIC_AUTH_REALM = authConfig.PUBLIC_AUTH_REALM || defaults_js_1.defaults.auth.PUBLIC_AUTH_REALM;
|
|
54
|
+
const PRIVATE_AUTH_CLIENT_ID = authConfig.PRIVATE_AUTH_CLIENT_ID || defaults_js_1.defaults.auth.PRIVATE_AUTH_CLIENT_ID;
|
|
55
|
+
const PRIVATE_AUTH_CLIENT_SECRET = authConfig.PRIVATE_AUTH_CLIENT_SECRET ||
|
|
56
|
+
defaults_js_1.defaults.auth.PRIVATE_AUTH_CLIENT_SECRET;
|
|
57
|
+
const PRIVATE_API_BASE_URL = authConfig.PRIVATE_API_BASE_URL || defaults_js_1.defaults.auth.PRIVATE_API_BASE_URL;
|
|
58
|
+
const getAvatarToken = (...args_2) => __awaiter(void 0, [...args_2], void 0, function* (appId = null) {
|
|
59
|
+
yield getSystemAccessToken();
|
|
60
|
+
let appToken = null;
|
|
61
|
+
if (appId) {
|
|
62
|
+
appToken = yield getAppAccessToken(appId);
|
|
63
|
+
}
|
|
64
|
+
return Object.assign(Object.assign({}, (appToken || {})), { appId });
|
|
65
|
+
});
|
|
66
|
+
const getAppAccessToken = (appId_1, ...args_3) => __awaiter(void 0, [appId_1, ...args_3], void 0, function* (appId, clientId = "avatar") {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
logger.info(`Fetch app token for appId=${appId} clientId=${clientId}`);
|
|
69
|
+
const cacheKey = `${appId}-${clientId}`;
|
|
70
|
+
tokens[cacheKey] = tokens[cacheKey] || null;
|
|
71
|
+
if (tokens[cacheKey]) {
|
|
72
|
+
const expiresIn = (_a = tokens[cacheKey]) === null || _a === void 0 ? void 0 : _a.expiresIn;
|
|
73
|
+
if (!expiresIn || new Date(expiresIn).getTime() - 30000 < Date.now()) {
|
|
74
|
+
tokens[cacheKey] = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (tokens[cacheKey]) {
|
|
78
|
+
logger.info(`Using cached token for ${cacheKey}`);
|
|
79
|
+
return tokens[cacheKey];
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const url = `${PRIVATE_API_BASE_URL}/platform/token`;
|
|
83
|
+
const data = {
|
|
84
|
+
appId,
|
|
85
|
+
clientId,
|
|
86
|
+
};
|
|
87
|
+
logger.debug(`Requesting to ${url}`);
|
|
88
|
+
const res = yield axios_1.default.post(url, data, {
|
|
89
|
+
httpsAgent,
|
|
90
|
+
headers: {
|
|
91
|
+
Authorization: `Bearer ${kioskToken === null || kioskToken === void 0 ? void 0 : kioskToken.accessToken}`,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
// expires 1min before
|
|
95
|
+
const expiresIn = res.data.expires_in * 1000;
|
|
96
|
+
logger.info(`Token for ${appId} expires in ${Math.round(expiresIn / 60 / 60 / 1000)}min`);
|
|
97
|
+
const { access_token, refresh_token } = res.data;
|
|
98
|
+
const token = {
|
|
99
|
+
accessToken: access_token,
|
|
100
|
+
refreshToken: refresh_token,
|
|
101
|
+
expiresIn: new Date(Date.now() + expiresIn),
|
|
102
|
+
};
|
|
103
|
+
tokens[cacheKey] = token;
|
|
104
|
+
return token;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
if (e instanceof Error)
|
|
108
|
+
logger.error(`Request failed ${e === null || e === void 0 ? void 0 : e.message}`);
|
|
109
|
+
if ((0, axios_1.isAxiosError)(e)) {
|
|
110
|
+
logger.error((_b = e.response) === null || _b === void 0 ? void 0 : _b.data);
|
|
111
|
+
delete tokens[cacheKey];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
});
|
|
116
|
+
const getSystemAccessToken = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
var _c, _d;
|
|
118
|
+
const cacheKey = "___kiosk___";
|
|
119
|
+
if (tokens[cacheKey]) {
|
|
120
|
+
const expiresIn = (_c = tokens[cacheKey]) === null || _c === void 0 ? void 0 : _c.expiresIn;
|
|
121
|
+
if (!expiresIn || new Date(expiresIn).getTime() - 30000 < Date.now()) {
|
|
122
|
+
tokens[cacheKey] = null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (tokens[cacheKey])
|
|
126
|
+
return tokens[cacheKey];
|
|
127
|
+
logger.debug(`Load kiosk access token`);
|
|
128
|
+
const url = `${PUBLIC_AUTH_URL}/realms/${PUBLIC_AUTH_REALM}/protocol/openid-connect/token`;
|
|
129
|
+
const data = {
|
|
130
|
+
client_id: PRIVATE_AUTH_CLIENT_ID,
|
|
131
|
+
client_secret: PRIVATE_AUTH_CLIENT_SECRET,
|
|
132
|
+
grant_type: "client_credentials",
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
logger.debug(`Requesting to ${url}`);
|
|
136
|
+
const res = yield axios_1.default.post(url, data, {
|
|
137
|
+
headers: {
|
|
138
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
139
|
+
Authorization: `Bearer ${btoa(PRIVATE_AUTH_CLIENT_ID + ":" + PRIVATE_AUTH_CLIENT_SECRET)}`,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
// expires 1min before
|
|
143
|
+
const expiresIn = res.data.expires_in * 1000;
|
|
144
|
+
logger.debug(`kioskToken expires in ${Math.round(expiresIn / 60 / 60 / 1000)}min`);
|
|
145
|
+
// const access_token = await getAuthorizationToken(res.data.access_token)
|
|
146
|
+
const { access_token, refresh_token } = res.data;
|
|
147
|
+
kioskToken = {
|
|
148
|
+
accessToken: access_token,
|
|
149
|
+
refreshToken: refresh_token,
|
|
150
|
+
expiresIn: new Date(Date.now() + expiresIn),
|
|
151
|
+
};
|
|
152
|
+
tokens["__kiosk"] = kioskToken;
|
|
153
|
+
return kioskToken;
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
kioskToken = null;
|
|
157
|
+
if (e instanceof Error)
|
|
158
|
+
logger.error(`Request failed ${e.message}`);
|
|
159
|
+
if ((0, axios_1.isAxiosError)(e)) {
|
|
160
|
+
logger.error((_d = e.response) === null || _d === void 0 ? void 0 : _d.data);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
});
|
|
165
|
+
return yield getAvatarToken(appId);
|
|
166
|
+
});
|
|
167
|
+
exports.getAvatarToken = getAvatarToken;
|
|
168
|
+
/**
|
|
169
|
+
* Returns access and refresh tokens for the given appId
|
|
170
|
+
* @param {string} appId null by default
|
|
171
|
+
* @param {AuthConfig} authConfig only PRIVATE_API_BASE_URL and PRIVATE_AUTH_CLIENT_ID are used
|
|
172
|
+
* @param {string} clientSecret needed for server2server authentication
|
|
173
|
+
*/
|
|
174
|
+
const getAvatarTokenWithClientSecret = (...args_4) => __awaiter(void 0, [...args_4], void 0, function* (appId = null, authConfig = defaults_js_1.defaults.auth, clientSecret = "") {
|
|
175
|
+
const logger = (0, logger_js_1.createLogger)("getAvatarTokenWithClientSecret");
|
|
176
|
+
const tokens = {};
|
|
177
|
+
const PRIVATE_API_BASE_URL = authConfig.PRIVATE_API_BASE_URL || defaults_js_1.defaults.auth.PRIVATE_API_BASE_URL;
|
|
178
|
+
const PRIVATE_AUTH_CLIENT_ID = authConfig.PRIVATE_AUTH_CLIENT_ID || defaults_js_1.defaults.auth.PRIVATE_AUTH_CLIENT_ID;
|
|
179
|
+
const getAppAccessTokenWithClientSecret = (appId_2, ...args_5) => __awaiter(void 0, [appId_2, ...args_5], void 0, function* (appId, clientId = "avatar", clientSecret = "") {
|
|
180
|
+
var _e, _f;
|
|
181
|
+
logger.info(`Fetch app token for appId=${appId} clientId=${clientId} clientSecret=${clientSecret}`);
|
|
182
|
+
const cacheKey = `${appId}-${clientId}`;
|
|
183
|
+
tokens[cacheKey] = tokens[cacheKey] || null;
|
|
184
|
+
if (tokens[cacheKey]) {
|
|
185
|
+
const expiresIn = (_e = tokens[cacheKey]) === null || _e === void 0 ? void 0 : _e.expiresIn;
|
|
186
|
+
if (!expiresIn ||
|
|
187
|
+
new Date(expiresIn).getTime() - 60 * 1000 < Date.now()) {
|
|
188
|
+
tokens[cacheKey] = null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (tokens[cacheKey]) {
|
|
192
|
+
logger.info(`Using cached token for ${cacheKey}`);
|
|
193
|
+
return tokens[cacheKey];
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const url = `${PRIVATE_API_BASE_URL}/platform/token/access_token`;
|
|
197
|
+
logger.debug(`Requesting to ${url}`);
|
|
198
|
+
const data = {
|
|
199
|
+
appId,
|
|
200
|
+
clientId,
|
|
201
|
+
clientSecret,
|
|
202
|
+
};
|
|
203
|
+
logger.debug(`get token from ${url}`);
|
|
204
|
+
const res = yield axios_1.default.post(url, data, {
|
|
205
|
+
httpsAgent,
|
|
206
|
+
});
|
|
207
|
+
// expires 1min before
|
|
208
|
+
const expiresIn = res.data.expires_in * 1000;
|
|
209
|
+
logger.info(`Token for ${appId} expires in ${Math.round(expiresIn / 60 / 60 / 1000)}min`);
|
|
210
|
+
const { access_token, refresh_token } = res.data;
|
|
211
|
+
const token = {
|
|
212
|
+
accessToken: access_token,
|
|
213
|
+
refreshToken: refresh_token,
|
|
214
|
+
expiresIn: new Date(Date.now() + expiresIn),
|
|
215
|
+
};
|
|
216
|
+
tokens[cacheKey] = token;
|
|
217
|
+
return token;
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
if (e instanceof Error)
|
|
221
|
+
logger.error(`Request failed ${e.message}`);
|
|
222
|
+
if ((0, axios_1.isAxiosError)(e)) {
|
|
223
|
+
logger.error((_f = e.response) === null || _f === void 0 ? void 0 : _f.data);
|
|
224
|
+
delete tokens[cacheKey];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
});
|
|
229
|
+
const getAvatarTokenWithClientSecret = (...args_6) => __awaiter(void 0, [...args_6], void 0, function* (appId = null, clientId = "", clientSecret = "") {
|
|
230
|
+
let appToken = null;
|
|
231
|
+
if (appId) {
|
|
232
|
+
appToken = yield getAppAccessTokenWithClientSecret(appId, clientId, clientSecret);
|
|
233
|
+
}
|
|
234
|
+
return Object.assign(Object.assign({}, (appToken || {})), { appId });
|
|
235
|
+
});
|
|
236
|
+
return yield getAvatarTokenWithClientSecret(appId, PRIVATE_AUTH_CLIENT_ID, clientSecret);
|
|
237
|
+
});
|
|
238
|
+
exports.getAvatarTokenWithClientSecret = getAvatarTokenWithClientSecret;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OpenAIClient = void 0;
|
|
16
|
+
const logger_js_1 = require("../config/logger.js");
|
|
17
|
+
const openai_1 = __importDefault(require("openai"));
|
|
18
|
+
/**
|
|
19
|
+
* Wrapper for OpenAI client to implement sermas functionalities
|
|
20
|
+
*/
|
|
21
|
+
class OpenAIClient {
|
|
22
|
+
constructor(openAIConfig) {
|
|
23
|
+
this.logger = (0, logger_js_1.createLogger)(OpenAIClient.name);
|
|
24
|
+
if (!openAIConfig.apiKey)
|
|
25
|
+
this.logger.warn("No API key provided for OpenAIClient");
|
|
26
|
+
this.openAI = new openai_1.default(openAIConfig);
|
|
27
|
+
}
|
|
28
|
+
chat(body, options) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
const result = yield this.openAI.chat.completions.create(Object.assign({ model: "gpt-3.5-turbo" }, (typeof body === "string"
|
|
32
|
+
? { messages: [{ role: "user", content: body }] }
|
|
33
|
+
: body)), options);
|
|
34
|
+
return result.choices[0].message.content;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
if (e instanceof Error)
|
|
38
|
+
this.logger.error(`OpenAI request failed: ${e.stack}`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
json(body, options) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
let text = yield this.chat(body, options);
|
|
46
|
+
if (text === null)
|
|
47
|
+
return;
|
|
48
|
+
try {
|
|
49
|
+
if (text.startsWith("```json")) {
|
|
50
|
+
text = text.replace("```json", "").replace("```", "");
|
|
51
|
+
}
|
|
52
|
+
return JSON.parse(text);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (e instanceof Error)
|
|
56
|
+
this.logger.error(`Failed to parse content: ${e.stack}`);
|
|
57
|
+
this.logger.debug(`Content: ${text}`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.OpenAIClient = OpenAIClient;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SermasApp = void 0;
|
|
13
|
+
const logger_js_1 = require("../config/logger.js");
|
|
14
|
+
const eventemitter2_1 = require("eventemitter2");
|
|
15
|
+
const api_client_1 = require("@sermas/api-client");
|
|
16
|
+
const defaults_js_1 = require("../config/defaults.js");
|
|
17
|
+
class SermasApp {
|
|
18
|
+
constructor(sermasConfig) {
|
|
19
|
+
this.logger = (0, logger_js_1.createLogger)(SermasApp.name);
|
|
20
|
+
this.app = null;
|
|
21
|
+
this.subs = [];
|
|
22
|
+
this.baseUrl =
|
|
23
|
+
sermasConfig.SERMAS_BASE_URL || defaults_js_1.defaults.sermas.SERMAS_BASE_URL;
|
|
24
|
+
this.appId = sermasConfig.SERMAS_APPID || defaults_js_1.defaults.sermas.SERMAS_CLIENT_ID;
|
|
25
|
+
this.clientId =
|
|
26
|
+
sermasConfig.SERMAS_CLIENT_ID || defaults_js_1.defaults.sermas.SERMAS_CLIENT_SECRET;
|
|
27
|
+
this.clientSecret =
|
|
28
|
+
sermasConfig.SERMAS_CLIENT_SECRET || defaults_js_1.defaults.sermas.SERMAS_APPID;
|
|
29
|
+
console.log("object");
|
|
30
|
+
this.emitter = new eventemitter2_1.EventEmitter2();
|
|
31
|
+
this.initialize();
|
|
32
|
+
this.client = new api_client_1.SermasApiClient({
|
|
33
|
+
baseURL: this.getBaseUrl(),
|
|
34
|
+
appId: this.appId,
|
|
35
|
+
logger: (0, logger_js_1.createLogger)("sermas-api-client"),
|
|
36
|
+
});
|
|
37
|
+
this.getApp();
|
|
38
|
+
}
|
|
39
|
+
getBaseUrl() {
|
|
40
|
+
return this.baseUrl;
|
|
41
|
+
}
|
|
42
|
+
initialize() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
// return await this.getClientCredentials();
|
|
45
|
+
yield this.setupSermasClient();
|
|
46
|
+
this.addSub(() => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return yield this.client.events.auth.onUserLogin((ev) => {
|
|
48
|
+
this.logger.debug(`User login: ${ev}`);
|
|
49
|
+
});
|
|
50
|
+
}));
|
|
51
|
+
this.addSub(() => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return yield this.client.events.session.onSessionChanged((ev) => {
|
|
53
|
+
this.logger.debug(`session changed ${ev.operation.toUpperCase()} sessionId=${ev.record.sessionId}`);
|
|
54
|
+
this.emitter.emit(`session`, ev);
|
|
55
|
+
});
|
|
56
|
+
}));
|
|
57
|
+
this.addSub(() => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return yield this.client.events.dialogue.onToolTriggered((event) => {
|
|
59
|
+
this.logger.debug("Tool triggered: " + event.name);
|
|
60
|
+
this.emitter.emit(`tool`, event);
|
|
61
|
+
});
|
|
62
|
+
}));
|
|
63
|
+
this.addSub(() => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return yield this.client.events.ui.onInteraction((event) => {
|
|
65
|
+
// this.logger.debug('UI interaction: ' + event.interaction);
|
|
66
|
+
this.emitter.emit(`ui.interaction`, event);
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
this.addSub(() => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
return yield this.client.events.session.onAgentChanged((event) => {
|
|
71
|
+
this.logger.debug("Agent changed: " + event.operation);
|
|
72
|
+
this.emitter.emit(`agent.changed`, event);
|
|
73
|
+
});
|
|
74
|
+
}));
|
|
75
|
+
this.logger.info("Sermas initialization completed");
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
setupSermasClient() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
this.logger.debug("Initializing sermas client.");
|
|
81
|
+
try {
|
|
82
|
+
this.logger.debug(`Loading token`);
|
|
83
|
+
yield this.client.loadToken(this.clientId, this.clientSecret);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
this.logger.error(`Failed to load token, retrying`);
|
|
87
|
+
if (e instanceof Error)
|
|
88
|
+
this.logger.debug(e.stack);
|
|
89
|
+
setTimeout(() => this.setupSermasClient(), 1000);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.logger.debug(`sermas client ready`);
|
|
93
|
+
this.emitter.emit("sermas.ready");
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
addSub(sub) {
|
|
97
|
+
sub()
|
|
98
|
+
.then((fn) => {
|
|
99
|
+
this.subs.push(fn);
|
|
100
|
+
})
|
|
101
|
+
.catch((e) => {
|
|
102
|
+
this.logger.error(`Subscribe failed: ${e.stack}`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
sendChatMessage(ev) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
yield this.client.api.dialogue.chatMessage({
|
|
108
|
+
appId: ev.appId,
|
|
109
|
+
sessionId: ev.sessionId,
|
|
110
|
+
requestBody: ev,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
sendUiContent(ev) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
yield this.client.events.ui.content(ev);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
getApp() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
if (this.app)
|
|
122
|
+
return this.app;
|
|
123
|
+
this.logger.debug(`Load app ${this.appId}`);
|
|
124
|
+
try {
|
|
125
|
+
this.app = yield this.client.api.platform.readApp({ appId: this.appId });
|
|
126
|
+
return this.app;
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
if (e instanceof Error)
|
|
130
|
+
this.logger.error(`Failed to load app ${this.appId}: ${e.stack}`);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
updateAppTools(tools) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
yield this.client.api.platform.updateAppTools({
|
|
138
|
+
appId: this.appId,
|
|
139
|
+
requestBody: tools,
|
|
140
|
+
});
|
|
141
|
+
this.logger.debug("Updated tools");
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
setTools(repositoryId, tools) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
yield this.client.api.dialogue.setTools({
|
|
147
|
+
repositoryId,
|
|
148
|
+
requestBody: {
|
|
149
|
+
repositoryId,
|
|
150
|
+
appId: this.appId,
|
|
151
|
+
tools,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
this.logger.debug("Updated tools");
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
addTools(repositoryId, tools, options) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
yield this.client.api.dialogue.addTools({
|
|
160
|
+
repositoryId,
|
|
161
|
+
requestBody: { repositoryId, appId: this.appId, tools, options },
|
|
162
|
+
});
|
|
163
|
+
this.logger.debug("Updated tools");
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
readSession(sessionId) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
try {
|
|
169
|
+
return yield this.client.api.session.readSession({ sessionId });
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
if (e instanceof Error)
|
|
173
|
+
this.logger.error(`Failed to readSession: ${e.stack}`);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
getRecord(storageId) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
try {
|
|
181
|
+
return yield this.client.api.session.getRecord({ storageId });
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
if (e instanceof Error && e.message.indexOf("Not Found") === -1)
|
|
185
|
+
this.logger.error(`Failed to getRecord: ${e.stack}`);
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
findRecords(query) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
try {
|
|
193
|
+
return yield this.client.api.session.findRecords({
|
|
194
|
+
requestBody: query,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
if (e instanceof Error)
|
|
199
|
+
this.logger.error(`Failed to findRecords: ${e.stack}`);
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
setRecord(storage) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
try {
|
|
207
|
+
return yield this.client.api.session.setRecord({
|
|
208
|
+
requestBody: storage,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
if (e instanceof Error)
|
|
213
|
+
this.logger.error(`Failed to setRecord: ${e.stack}`);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
generateQRCode(data) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
try {
|
|
221
|
+
return yield this.client.api.ui.generateQrCode({
|
|
222
|
+
requestBody: { version: 5, data },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
if (e instanceof Error)
|
|
227
|
+
this.logger.error(`Failed to generate QR code: ${e.stack}`);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.SermasApp = SermasApp;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Store = void 0;
|
|
13
|
+
const logger_js_1 = require("../config/logger.js");
|
|
14
|
+
const util_js_1 = require("../config/util.js");
|
|
15
|
+
class Store {
|
|
16
|
+
constructor(sermas) {
|
|
17
|
+
this.logger = (0, logger_js_1.createLogger)(Store.name);
|
|
18
|
+
this.sessions = {};
|
|
19
|
+
this.locks = {};
|
|
20
|
+
this.sermas = sermas;
|
|
21
|
+
this.sermas.emitter.on("session", this.onSessionChange.bind(this));
|
|
22
|
+
}
|
|
23
|
+
// @OnEvent("session")
|
|
24
|
+
onSessionChange(ev) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!ev.record.sessionId)
|
|
27
|
+
return;
|
|
28
|
+
const session = yield this.saveSessionWrapper(ev);
|
|
29
|
+
switch (ev.operation) {
|
|
30
|
+
case "created":
|
|
31
|
+
if (!session) {
|
|
32
|
+
this.logger.warn(`Failed to get session for sessionId=${ev.record.sessionId}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.sermas.emitter.emit("session.started", session);
|
|
36
|
+
break;
|
|
37
|
+
case "updated":
|
|
38
|
+
yield this.saveSessionWrapper(ev);
|
|
39
|
+
break;
|
|
40
|
+
case "removed":
|
|
41
|
+
if (!this.sessions[ev.record.sessionId])
|
|
42
|
+
return;
|
|
43
|
+
delete this.sessions[ev.record.sessionId];
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
lock(sessionId, fn) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
51
|
+
this.locks[sessionId] = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
resolve(yield fn());
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
try {
|
|
60
|
+
const res = yield this.locks[sessionId];
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (e instanceof Error)
|
|
65
|
+
this.logger.error(`lock failure: ${e.stack}`);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
delete this.locks[sessionId];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
loadSessionWrapper(context) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const opId = `[${performance.now()}] `;
|
|
76
|
+
if (yield this.locks[context.sessionId]) {
|
|
77
|
+
this.logger.debug(`${opId} Wait lock for sessionId=${context.sessionId}`);
|
|
78
|
+
yield this.locks[context.sessionId];
|
|
79
|
+
this.logger.debug(`${opId} Lock released for sessionId=${context.sessionId}`);
|
|
80
|
+
}
|
|
81
|
+
return yield this.lock(context.sessionId, () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
this.logger.debug(`${opId} Loading wrapper for sessionId=${context.sessionId}`);
|
|
83
|
+
const records = yield this.sermas.findRecords({
|
|
84
|
+
appId: "",
|
|
85
|
+
sessionId: [context.sessionId],
|
|
86
|
+
userId: undefined,
|
|
87
|
+
});
|
|
88
|
+
if (records && records.length) {
|
|
89
|
+
this.logger.debug(`${opId} Wrapper exists for sessionId=${context.sessionId}`);
|
|
90
|
+
return records[0].data;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.logger.debug(`${opId} Wrapper not found for sessionId=${context.sessionId}`);
|
|
94
|
+
}
|
|
95
|
+
this.logger.debug(`${opId} Creating new session wrapper store sessionId=${context.sessionId} appId=${context.appId} userId=${context.userId}`);
|
|
96
|
+
const storageId = (0, util_js_1.uuidv4)();
|
|
97
|
+
const sessionWrapper = Object.assign(Object.assign({}, context), { appId: context.appId, sessionId: context.sessionId, userId: context.userId, storageId });
|
|
98
|
+
if (!sessionWrapper.appId || !sessionWrapper.userId) {
|
|
99
|
+
this.logger.debug(`${opId} Load session record sessionId=${sessionWrapper.sessionId}`);
|
|
100
|
+
const session = yield this.sermas.readSession(sessionWrapper.sessionId);
|
|
101
|
+
if (session) {
|
|
102
|
+
if (!sessionWrapper.appId)
|
|
103
|
+
sessionWrapper.appId = session.appId;
|
|
104
|
+
if (!sessionWrapper.userId)
|
|
105
|
+
sessionWrapper.userId = session.userId;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.logger.warn(`${opId} Failed to load sessionId=${sessionWrapper.sessionId}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const record = {
|
|
112
|
+
appId: sessionWrapper.appId,
|
|
113
|
+
sessionId: sessionWrapper.sessionId,
|
|
114
|
+
data: sessionWrapper,
|
|
115
|
+
userId: sessionWrapper.userId || undefined,
|
|
116
|
+
storageId,
|
|
117
|
+
};
|
|
118
|
+
yield this.sermas.setRecord(record);
|
|
119
|
+
this.logger.debug(`${opId} Saved store storageId=${record.storageId} for sessionId=${record.sessionId} appId=${record.appId} userId=${record.userId}`);
|
|
120
|
+
return sessionWrapper;
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
saveSession(session) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
let record = yield this.sermas.getRecord(session.storageId);
|
|
127
|
+
if (!record) {
|
|
128
|
+
this.logger.warn(`sessionId=${session.sessionId} storageId=${session.storageId} not found, creating new record`);
|
|
129
|
+
const newSession = yield this.loadSessionWrapper(Object.assign({}, session));
|
|
130
|
+
record = yield this.sermas.getRecord(newSession.storageId);
|
|
131
|
+
}
|
|
132
|
+
if (!record) {
|
|
133
|
+
this.logger.error(`Cannot save sessionId=${session.sessionId}, storage not found`);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
record.data = Object.assign(Object.assign({}, session), { storageId: record.storageId });
|
|
137
|
+
const res = yield this.sermas.setRecord(record);
|
|
138
|
+
this.logger.debug(`Saved record for sessionId=${record.sessionId} storageId=${record.storageId}`);
|
|
139
|
+
return res === null || res === void 0 ? void 0 : res.data;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
getSessionWrapper(sessionId) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
if (!sessionId) {
|
|
145
|
+
this.logger.debug(`sessionId is empty`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (!this.sessions[sessionId]) {
|
|
149
|
+
const session = yield this.loadSessionWrapper({
|
|
150
|
+
sessionId,
|
|
151
|
+
});
|
|
152
|
+
this.logger.debug(`loaded sessionId=${sessionId}`);
|
|
153
|
+
this.sessions[sessionId] = session;
|
|
154
|
+
}
|
|
155
|
+
return this.sessions[sessionId];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
saveSessionWrapper(ev) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (!ev.appId)
|
|
161
|
+
return;
|
|
162
|
+
if (!ev.record.sessionId)
|
|
163
|
+
return;
|
|
164
|
+
if (this.sessions[ev.record.sessionId])
|
|
165
|
+
return;
|
|
166
|
+
const wrapper = yield this.loadSessionWrapper({
|
|
167
|
+
userId: ev.userId,
|
|
168
|
+
appId: ev.appId,
|
|
169
|
+
sessionId: ev.record.sessionId,
|
|
170
|
+
});
|
|
171
|
+
this.sessions[wrapper.sessionId] = wrapper;
|
|
172
|
+
this.logger.info(`Added session ${wrapper.sessionId}`);
|
|
173
|
+
return this.sessions[wrapper.sessionId];
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.Store = Store;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Tools = void 0;
|
|
13
|
+
class Tools {
|
|
14
|
+
constructor(sermasApp) {
|
|
15
|
+
this.sermas = sermasApp;
|
|
16
|
+
}
|
|
17
|
+
reset(session) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield this.sermas.setTools(session.sessionId, []);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
set(session, tools) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
yield this.sermas.setTools(session.sessionId, tools);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
add(session, tools, options) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
yield this.sermas.addTools(session.sessionId, tools, options);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getSchemaValues(tool) {
|
|
33
|
+
const values = {};
|
|
34
|
+
if (!tool.schema)
|
|
35
|
+
return values;
|
|
36
|
+
tool.schema.forEach((schema) => (values[schema.parameter] = schema.value));
|
|
37
|
+
return values;
|
|
38
|
+
}
|
|
39
|
+
getSchemaValue(tool, parameterName) {
|
|
40
|
+
const values = this.getSchemaValues(tool);
|
|
41
|
+
return values[parameterName];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Tools = Tools;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UI = void 0;
|
|
13
|
+
const core_1 = require("openai/core");
|
|
14
|
+
const ulidx_1 = require("ulidx");
|
|
15
|
+
const logger_js_1 = require("../config/logger.js");
|
|
16
|
+
class UI {
|
|
17
|
+
constructor(sermas, store) {
|
|
18
|
+
this.logger = (0, logger_js_1.createLogger)(UI.name);
|
|
19
|
+
this.backMenuOptions = [];
|
|
20
|
+
this.sermas = sermas;
|
|
21
|
+
this.store = store;
|
|
22
|
+
this.sermas.emitter.on("session", this.onSessionChange.bind(this));
|
|
23
|
+
}
|
|
24
|
+
// @OnEvent("session")
|
|
25
|
+
onSessionChange(ev) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
if (!ev.record.sessionId)
|
|
28
|
+
return;
|
|
29
|
+
const session = yield this.store.getSessionWrapper(ev.record.sessionId);
|
|
30
|
+
switch (ev.operation) {
|
|
31
|
+
case "removed":
|
|
32
|
+
if (!session)
|
|
33
|
+
return;
|
|
34
|
+
yield this.sendClearScreen(session);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
createBackButton(value) {
|
|
40
|
+
this.backMenuOptions = Array.from(new Set([...this.backMenuOptions, value]));
|
|
41
|
+
const button = {
|
|
42
|
+
value,
|
|
43
|
+
classes: ["is-light"],
|
|
44
|
+
};
|
|
45
|
+
return button;
|
|
46
|
+
}
|
|
47
|
+
sendBackMenu(session, labels) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
labels = typeof labels === "string" ? [labels] : labels;
|
|
50
|
+
yield this.sendButtons(session, "", labels.map((value) => this.createBackButton(value)), undefined, {
|
|
51
|
+
ttsEnabled: false,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
sendMenuButtons(session, buttons) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield this.sendButtons(session, "", buttons, undefined, {
|
|
58
|
+
ttsEnabled: false,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
sendAgentMessage(session, message, messageLanguage) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const app = yield this.sermas.getApp();
|
|
66
|
+
if (!app) {
|
|
67
|
+
this.logger.warn(`app is not available`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const filtered = (_b = (_a = app.repository) === null || _a === void 0 ? void 0 : _a.avatars) === null || _b === void 0 ? void 0 : _b.filter((a) => a.name === app.settings.avatar);
|
|
71
|
+
const gender = filtered.length ? filtered[0].gender : undefined;
|
|
72
|
+
yield this.sermas.sendChatMessage(Object.assign(Object.assign({}, session), { text: message, appId: app.appId, actor: "agent", gender, language: messageLanguage, chunkId: this.getChunkId() }));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
sendButtons(session_1, label_1, list_1) {
|
|
76
|
+
return __awaiter(this, arguments, void 0, function* (session, label, list, metadata = {}, options = {
|
|
77
|
+
clearScreen: false,
|
|
78
|
+
ttsEnabled: true,
|
|
79
|
+
stopSpeech: false,
|
|
80
|
+
}) {
|
|
81
|
+
if (!session) {
|
|
82
|
+
this.logger.warn(`[sendButtons] Session is empty`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const ev = Object.assign(Object.assign({}, session), { metadata,
|
|
86
|
+
options, content: {
|
|
87
|
+
label,
|
|
88
|
+
list: list.map((button) => {
|
|
89
|
+
if (typeof button === "string")
|
|
90
|
+
return { value: button };
|
|
91
|
+
return button;
|
|
92
|
+
}),
|
|
93
|
+
}, contentType: "buttons", chunkId: this.getChunkId() });
|
|
94
|
+
yield this.sermas.sendUiContent(ev);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
sendClearScreen(session) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const ev = Object.assign(Object.assign({}, session), { metadata: {}, options: {
|
|
100
|
+
clearScreen: true,
|
|
101
|
+
stopSpeech: true,
|
|
102
|
+
}, content: {}, contentType: "clear-screen" });
|
|
103
|
+
yield this.sermas.sendUiContent(ev);
|
|
104
|
+
yield (0, core_1.sleep)(500);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
sendImage(session, data, width, height) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
this.logger.info(`Send image sessionId=${session.sessionId} appId=${session.appId}`);
|
|
110
|
+
const ev = Object.assign(Object.assign({}, session), { metadata: {}, options: {
|
|
111
|
+
clearScreen: false,
|
|
112
|
+
stopSpeech: false,
|
|
113
|
+
}, content: { src: data, alt: "no image", width, height }, contentType: "image" });
|
|
114
|
+
yield this.sermas.sendUiContent(ev);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getChunkId(ts) {
|
|
118
|
+
return (0, ulidx_1.ulid)(ts ? new Date(ts).getTime() : undefined);
|
|
119
|
+
}
|
|
120
|
+
matchBackMenu(selection) {
|
|
121
|
+
return selection && this.backMenuOptions.indexOf(selection) > -1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.UI = UI;
|
|
@@ -12,7 +12,7 @@ import OpenAI from "openai";
|
|
|
12
12
|
/**
|
|
13
13
|
* Wrapper for OpenAI client to implement sermas functionalities
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
class OpenAIClient {
|
|
16
16
|
constructor(openAIConfig) {
|
|
17
17
|
this.logger = createLogger(OpenAIClient.name);
|
|
18
18
|
if (!openAIConfig.apiKey)
|
|
@@ -54,3 +54,4 @@ export class OpenAIClient {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
export { OpenAIClient };
|
|
@@ -11,7 +11,7 @@ import { createLogger } from "../config/logger.js";
|
|
|
11
11
|
import { EventEmitter2 } from "eventemitter2";
|
|
12
12
|
import { SermasApiClient, } from "@sermas/api-client";
|
|
13
13
|
import { defaults } from "../config/defaults.js";
|
|
14
|
-
|
|
14
|
+
class SermasApp {
|
|
15
15
|
constructor(sermasConfig) {
|
|
16
16
|
this.logger = createLogger(SermasApp.name);
|
|
17
17
|
this.app = null;
|
|
@@ -23,6 +23,7 @@ export class SermasApp {
|
|
|
23
23
|
sermasConfig.SERMAS_CLIENT_ID || defaults.sermas.SERMAS_CLIENT_SECRET;
|
|
24
24
|
this.clientSecret =
|
|
25
25
|
sermasConfig.SERMAS_CLIENT_SECRET || defaults.sermas.SERMAS_APPID;
|
|
26
|
+
console.log("object");
|
|
26
27
|
this.emitter = new EventEmitter2();
|
|
27
28
|
this.initialize();
|
|
28
29
|
this.client = new SermasApiClient({
|
|
@@ -226,3 +227,4 @@ export class SermasApp {
|
|
|
226
227
|
});
|
|
227
228
|
}
|
|
228
229
|
}
|
|
230
|
+
export { SermasApp };
|
|
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { createLogger } from "../config/logger.js";
|
|
11
11
|
import { uuidv4 } from "../config/util.js";
|
|
12
|
-
|
|
13
|
-
export class Store {
|
|
12
|
+
class Store {
|
|
14
13
|
constructor(sermas) {
|
|
15
14
|
this.logger = createLogger(Store.name);
|
|
16
15
|
this.sessions = {};
|
|
17
16
|
this.locks = {};
|
|
18
17
|
this.sermas = sermas;
|
|
18
|
+
this.sermas.emitter.on("session", this.onSessionChange.bind(this));
|
|
19
19
|
}
|
|
20
20
|
// @OnEvent("session")
|
|
21
21
|
onSessionChange(ev) {
|
|
@@ -171,3 +171,4 @@ export class Store {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
export { Store };
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
class Tools {
|
|
11
11
|
constructor(sermasApp) {
|
|
12
12
|
this.sermas = sermasApp;
|
|
13
13
|
}
|
|
@@ -38,3 +38,4 @@ export class Tools {
|
|
|
38
38
|
return values[parameterName];
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
export { Tools };
|
|
@@ -10,12 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { sleep } from "openai/core";
|
|
11
11
|
import { ulid } from "ulidx";
|
|
12
12
|
import { createLogger } from "../config/logger.js";
|
|
13
|
-
|
|
13
|
+
class UI {
|
|
14
14
|
constructor(sermas, store) {
|
|
15
15
|
this.logger = createLogger(UI.name);
|
|
16
16
|
this.backMenuOptions = [];
|
|
17
17
|
this.sermas = sermas;
|
|
18
18
|
this.store = store;
|
|
19
|
+
this.sermas.emitter.on("session", this.onSessionChange.bind(this));
|
|
19
20
|
}
|
|
20
21
|
// @OnEvent("session")
|
|
21
22
|
onSessionChange(ev) {
|
|
@@ -117,3 +118,4 @@ export class UI {
|
|
|
117
118
|
return selection && this.backMenuOptions.indexOf(selection) > -1;
|
|
118
119
|
}
|
|
119
120
|
}
|
|
121
|
+
export { UI };
|
|
@@ -3,4 +3,6 @@ export { OpenAIClient } from "./modules/openai.js";
|
|
|
3
3
|
export { Store } from "./modules/store.js";
|
|
4
4
|
export { UI } from "./modules/ui.js";
|
|
5
5
|
export { Tools } from "./modules/tools.js";
|
|
6
|
-
export { SermasApp
|
|
6
|
+
export { SermasApp } from "./modules/sermas.js";
|
|
7
|
+
export type { OpenAIConfig } from "./modules/openai.js";
|
|
8
|
+
export type { SermasConfig } from "./modules/sermas.js";
|
|
@@ -8,11 +8,11 @@ type ChatCompletionMessage = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Wrapper for OpenAI client to implement sermas functionalities
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
declare class OpenAIClient {
|
|
12
12
|
private logger;
|
|
13
13
|
private openAI;
|
|
14
14
|
constructor(openAIConfig: OpenAIConfig);
|
|
15
15
|
chat(body: string | ChatCompletionMessage, options?: OpenAI.RequestOptions<unknown>): Promise<string | null>;
|
|
16
16
|
json<T = Record<string, unknown>>(body: string | OpenAI.Chat.ChatCompletionCreateParams, options?: OpenAI.RequestOptions<unknown>): Promise<T | null | undefined>;
|
|
17
17
|
}
|
|
18
|
-
export {};
|
|
18
|
+
export { OpenAIClient };
|
|
@@ -6,7 +6,7 @@ export type SermasConfig = {
|
|
|
6
6
|
SERMAS_CLIENT_SECRET: string;
|
|
7
7
|
SERMAS_APPID: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
declare class SermasApp {
|
|
10
10
|
private logger;
|
|
11
11
|
private baseUrl;
|
|
12
12
|
private app;
|
|
@@ -33,3 +33,4 @@ export declare class SermasApp {
|
|
|
33
33
|
setRecord(storage: SessionStorageRecordDto): Promise<SessionStorageRecordDto | null>;
|
|
34
34
|
generateQRCode(data: string): Promise<any>;
|
|
35
35
|
}
|
|
36
|
+
export { SermasApp };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SessionChangedDto } from "@sermas/api-client";
|
|
2
2
|
import { SermasApp } from "./sermas.js";
|
|
3
3
|
import { BaseSessionWrapper } from "../dto/session.js";
|
|
4
|
-
|
|
4
|
+
declare class Store {
|
|
5
5
|
private readonly logger;
|
|
6
6
|
private sermas;
|
|
7
7
|
private sessions;
|
|
@@ -18,3 +18,4 @@ export declare class Store {
|
|
|
18
18
|
getSessionWrapper(sessionId: string): Promise<BaseSessionWrapper | undefined>;
|
|
19
19
|
saveSessionWrapper(ev: SessionChangedDto): Promise<unknown>;
|
|
20
20
|
}
|
|
21
|
+
export { Store };
|
|
@@ -3,7 +3,7 @@ import { BaseSessionWrapper } from "../dto/session.js";
|
|
|
3
3
|
import { SermasApp } from "./sermas.js";
|
|
4
4
|
type ToolsSchemaValues = string | number | boolean | undefined;
|
|
5
5
|
type ToolsSchemaParameters = Record<string, ToolsSchemaValues>;
|
|
6
|
-
|
|
6
|
+
declare class Tools {
|
|
7
7
|
private sermas;
|
|
8
8
|
constructor(sermasApp: SermasApp);
|
|
9
9
|
reset(session: BaseSessionWrapper): Promise<void>;
|
|
@@ -12,4 +12,4 @@ export declare class Tools {
|
|
|
12
12
|
getSchemaValues<T extends ToolsSchemaParameters = ToolsSchemaParameters>(tool: AppToolsDTO): T;
|
|
13
13
|
getSchemaValue(tool: AppToolsDTO, parameterName: string): ToolsSchemaValues;
|
|
14
14
|
}
|
|
15
|
-
export {};
|
|
15
|
+
export { Tools };
|
|
@@ -2,7 +2,7 @@ import { ButtonDto, SessionChangedDto, UIContentOptionsDto } from "@sermas/api-c
|
|
|
2
2
|
import { BaseSessionWrapper } from "../dto/session.js";
|
|
3
3
|
import { SermasApp } from "./sermas.js";
|
|
4
4
|
import { Store } from "./store.js";
|
|
5
|
-
|
|
5
|
+
declare class UI {
|
|
6
6
|
private sermas;
|
|
7
7
|
private store;
|
|
8
8
|
private readonly logger;
|
|
@@ -21,3 +21,4 @@ export declare class UI {
|
|
|
21
21
|
getChunkId(ts?: Date): string;
|
|
22
22
|
matchBackMenu(selection: string): boolean | "";
|
|
23
23
|
}
|
|
24
|
+
export { UI };
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sermas/sermas-toolkit-node-sdk",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "Sermas toolkit node SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
-
"exports":
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"default": "./dist/esm/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
12
17
|
"repository": {
|
|
13
18
|
"type": "git",
|
|
14
19
|
"url": "https://github.com/sermas-eu/sermas-toolkit-node-sdk.git"
|
|
15
20
|
},
|
|
16
21
|
"scripts": {
|
|
17
22
|
"clean": "rm -rf ./dist",
|
|
18
|
-
"build": "npm run clean && tsc",
|
|
23
|
+
"build": "npm run clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && tsc -p tsconfig.types.json",
|
|
24
|
+
"build:watch": "concurrently \"npx tsc -p tsconfig.cjs.json --watch\" \"npx tsc -p tsconfig.types.json --watch\"",
|
|
19
25
|
"start": "node dist/index.js",
|
|
20
26
|
"dev": "tsx watch src/index.ts"
|
|
21
27
|
},
|
|
@@ -33,6 +39,7 @@
|
|
|
33
39
|
"@types/uuid": "^9.0.8",
|
|
34
40
|
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
35
41
|
"@typescript-eslint/parser": "^7.9.0",
|
|
42
|
+
"concurrently": "^8.2.2",
|
|
36
43
|
"eslint": "^8.57.0",
|
|
37
44
|
"eslint-config-prettier": "^9.1.0",
|
|
38
45
|
"eslint-plugin-prettier": "^5.1.3",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|