@botonic/core 0.55.1 → 0.57.0-rslib-esm.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/lib/esm/constants.js +7 -7
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/core-bot.d.ts +3 -3
- package/lib/esm/core-bot.js +87 -50
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/debug/index.d.ts +1 -1
- package/lib/esm/debug/index.js +5 -4
- package/lib/esm/debug/index.js.map +1 -1
- package/lib/esm/debug/inspector.d.ts +1 -1
- package/lib/esm/debug/inspector.js +27 -21
- package/lib/esm/debug/inspector.js.map +1 -1
- package/lib/esm/handoff.d.ts +1 -1
- package/lib/esm/handoff.js +82 -53
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/hubtype-service.d.ts +3 -3
- package/lib/esm/hubtype-service.js +100 -64
- package/lib/esm/hubtype-service.js.map +1 -1
- package/lib/esm/index.d.ts +9 -9
- package/lib/esm/index.js +21 -12
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/models/ai-agents.js +15 -15
- package/lib/esm/models/ai-agents.js.map +1 -1
- package/lib/esm/models/bot-config.js +6 -6
- package/lib/esm/models/bot-config.js.map +1 -1
- package/lib/esm/models/hubtype-analytics.d.ts +1 -1
- package/lib/esm/models/hubtype-analytics.js +10 -10
- package/lib/esm/models/hubtype-analytics.js.map +1 -1
- package/lib/esm/models/index.d.ts +4 -4
- package/lib/esm/models/index.js +11 -7
- package/lib/esm/models/index.js.map +1 -1
- package/lib/esm/models/legacy-types.d.ts +3 -1
- package/lib/esm/models/legacy-types.js +25 -24
- package/lib/esm/models/legacy-types.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/plugins.d.ts +1 -1
- package/lib/esm/plugins.js +7 -8
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/pusher-utils.js +15 -10
- package/lib/esm/pusher-utils.js.map +1 -1
- package/lib/esm/routing/index.d.ts +2 -2
- package/lib/esm/routing/index.js +7 -5
- package/lib/esm/routing/index.js.map +1 -1
- package/lib/esm/routing/router-utils.d.ts +1 -1
- package/lib/esm/routing/router-utils.js +37 -30
- package/lib/esm/routing/router-utils.js.map +1 -1
- package/lib/esm/routing/router.d.ts +2 -2
- package/lib/esm/routing/router.js +152 -149
- package/lib/esm/routing/router.js.map +1 -1
- package/lib/esm/testing/index.d.ts +1 -1
- package/lib/esm/testing/index.js +60 -94
- package/lib/esm/testing/index.js.map +1 -1
- package/lib/esm/utils/bot-config.d.ts +1 -1
- package/lib/esm/utils/bot-config.js +57 -28
- package/lib/esm/utils/bot-config.js.map +1 -1
- package/lib/esm/utils/check-providers.d.ts +1 -1
- package/lib/esm/utils/check-providers.js +14 -17
- package/lib/esm/utils/check-providers.js.map +1 -1
- package/lib/esm/utils/functional.js +19 -38
- package/lib/esm/utils/functional.js.map +1 -1
- package/lib/esm/utils/index.d.ts +3 -3
- package/lib/esm/utils/index.js +9 -6
- package/lib/esm/utils/index.js.map +1 -1
- package/package.json +12 -11
- package/src/hubtype-service.ts +4 -2
- package/src/models/legacy-types.ts +3 -0
- package/lib/cjs/constants.d.ts +0 -4
- package/lib/cjs/constants.js +0 -8
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/core-bot.d.ts +0 -43
- package/lib/cjs/core-bot.js +0 -205
- package/lib/cjs/core-bot.js.map +0 -1
- package/lib/cjs/debug/index.d.ts +0 -1
- package/lib/cjs/debug/index.js +0 -5
- package/lib/cjs/debug/index.js.map +0 -1
- package/lib/cjs/debug/inspector.d.ts +0 -24
- package/lib/cjs/debug/inspector.js +0 -70
- package/lib/cjs/debug/inspector.js.map +0 -1
- package/lib/cjs/handoff.d.ts +0 -110
- package/lib/cjs/handoff.js +0 -238
- package/lib/cjs/handoff.js.map +0 -1
- package/lib/cjs/hubtype-service.d.ts +0 -58
- package/lib/cjs/hubtype-service.js +0 -205
- package/lib/cjs/hubtype-service.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -9
- package/lib/cjs/index.js +0 -13
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/models/ai-agents.d.ts +0 -140
- package/lib/cjs/models/ai-agents.js +0 -30
- package/lib/cjs/models/ai-agents.js.map +0 -1
- package/lib/cjs/models/bot-config.d.ts +0 -24
- package/lib/cjs/models/bot-config.js +0 -10
- package/lib/cjs/models/bot-config.js.map +0 -1
- package/lib/cjs/models/hubtype-analytics.d.ts +0 -210
- package/lib/cjs/models/hubtype-analytics.js +0 -38
- package/lib/cjs/models/hubtype-analytics.js.map +0 -1
- package/lib/cjs/models/index.d.ts +0 -4
- package/lib/cjs/models/index.js +0 -8
- package/lib/cjs/models/index.js.map +0 -1
- package/lib/cjs/models/legacy-types.d.ts +0 -330
- package/lib/cjs/models/legacy-types.js +0 -83
- package/lib/cjs/models/legacy-types.js.map +0 -1
- package/lib/cjs/plugins.d.ts +0 -9
- package/lib/cjs/plugins.js +0 -24
- package/lib/cjs/plugins.js.map +0 -1
- package/lib/cjs/pusher-utils.d.ts +0 -7
- package/lib/cjs/pusher-utils.js +0 -18
- package/lib/cjs/pusher-utils.js.map +0 -1
- package/lib/cjs/routing/index.d.ts +0 -2
- package/lib/cjs/routing/index.js +0 -6
- package/lib/cjs/routing/index.js.map +0 -1
- package/lib/cjs/routing/router-utils.d.ts +0 -11
- package/lib/cjs/routing/router-utils.js +0 -96
- package/lib/cjs/routing/router-utils.js.map +0 -1
- package/lib/cjs/routing/router.d.ts +0 -54
- package/lib/cjs/routing/router.js +0 -330
- package/lib/cjs/routing/router.js.map +0 -1
- package/lib/cjs/testing/index.d.ts +0 -91
- package/lib/cjs/testing/index.js +0 -196
- package/lib/cjs/testing/index.js.map +0 -1
- package/lib/cjs/utils/bot-config.d.ts +0 -4
- package/lib/cjs/utils/bot-config.js +0 -94
- package/lib/cjs/utils/bot-config.js.map +0 -1
- package/lib/cjs/utils/check-providers.d.ts +0 -8
- package/lib/cjs/utils/check-providers.js +0 -34
- package/lib/cjs/utils/check-providers.js.map +0 -1
- package/lib/cjs/utils/functional.d.ts +0 -10
- package/lib/cjs/utils/functional.js +0 -88
- package/lib/cjs/utils/functional.js.map +0 -1
- package/lib/cjs/utils/index.d.ts +0 -3
- package/lib/cjs/utils/index.js +0 -7
- package/lib/cjs/utils/index.js.map +0 -1
package/lib/esm/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
const NOT_FOUND_PATH = '404';
|
|
2
|
+
const EMPTY_ACTION_PATH = '';
|
|
3
|
+
const PATH_PAYLOAD_IDENTIFIER = '__PATH_PAYLOAD__';
|
|
4
|
+
const PATH_PAYLOAD_REGEXP = new RegExp(`\\b^${PATH_PAYLOAD_IDENTIFIER}(.*)\\b`);
|
|
5
|
+
|
|
6
|
+
export { EMPTY_ACTION_PATH, NOT_FOUND_PATH, PATH_PAYLOAD_IDENTIFIER, PATH_PAYLOAD_REGEXP };
|
|
7
|
+
|
|
8
8
|
//# sourceMappingURL=constants.js.map
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const NOT_FOUND_PATH = '404'\nexport const EMPTY_ACTION_PATH = ''\nexport const PATH_PAYLOAD_IDENTIFIER = '__PATH_PAYLOAD__'\nexport const PATH_PAYLOAD_REGEXP = new RegExp(\n `\\\\b^${PATH_PAYLOAD_IDENTIFIER}(.*)\\\\b`\n)\n"],"names":["NOT_FOUND_PATH","EMPTY_ACTION_PATH","PATH_PAYLOAD_IDENTIFIER","PATH_PAYLOAD_REGEXP","RegExp"],"mappings":"AAAO,MAAMA,cAAcA,GAAG,MAAK;AAC5B,MAAMC,iBAAiBA,GAAG,GAAE;AAC5B,MAAMC,uBAAuBA,GAAG,mBAAkB;AAClD,MAAMC,mBAAmBA,GAAG,IAAIC,OACrC,CAAC,IAAI,EAAEF,uBAAuBA,CAAC,OAAO,CAAC,EACxC"}
|
package/lib/esm/core-bot.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Inspector } from './debug';
|
|
2
|
-
import { type BotRequest, type BotResponse, type ResolvedPlugins, type Route, type Routes, type Session } from './models';
|
|
3
|
-
import { Router } from './routing';
|
|
1
|
+
import { Inspector } from './debug/index.js';
|
|
2
|
+
import { type BotRequest, type BotResponse, type ResolvedPlugins, type Route, type Routes, type Session } from './models/index.js';
|
|
3
|
+
import { Router } from './routing/index.js';
|
|
4
4
|
export interface CoreBotConfig {
|
|
5
5
|
appId?: string;
|
|
6
6
|
defaultDelay?: number;
|
package/lib/esm/core-bot.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Inspector } from "./debug/index.js";
|
|
2
|
+
import { BotonicAction, INPUT } from "./models/index.js";
|
|
3
|
+
import { runPlugins } from "./plugins.js";
|
|
4
|
+
import { Router, getComputedRoutes } from "./routing/index.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function _define_property(obj, key, value) {
|
|
11
|
+
if (key in obj) {
|
|
12
|
+
Object.defineProperty(obj, key, {
|
|
13
|
+
value: value,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true
|
|
17
|
+
});
|
|
18
|
+
} else obj[key] = value;
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
8
25
|
class CoreBot {
|
|
9
|
-
constructor({ renderer, routes, theme, plugins, appId, defaultTyping = 0.6, defaultDelay = 0.4, defaultRoutes, inspector, }) {
|
|
10
|
-
this.renderer = renderer;
|
|
11
|
-
this.plugins = plugins || {};
|
|
12
|
-
this.theme = theme || {};
|
|
13
|
-
this.defaultTyping = defaultTyping;
|
|
14
|
-
this.defaultDelay = defaultDelay;
|
|
15
|
-
this.appId = appId || undefined;
|
|
16
|
-
this.rootElement = null;
|
|
17
|
-
this.inspector = inspector || new debug_1.Inspector();
|
|
18
|
-
this.routes = routes;
|
|
19
|
-
this.defaultRoutes = defaultRoutes || [];
|
|
20
|
-
this.router =
|
|
21
|
-
this.routes instanceof Function
|
|
22
|
-
? null
|
|
23
|
-
: new routing_1.Router([...this.routes, ...this.defaultRoutes], this.inspector.routeInspector);
|
|
24
|
-
}
|
|
25
26
|
setSystemLocale(locale, session) {
|
|
26
27
|
session.user.system_locale = locale;
|
|
27
28
|
}
|
|
@@ -34,7 +35,7 @@ class CoreBot {
|
|
|
34
35
|
async input(request) {
|
|
35
36
|
const botContext = this.getBotContext(request);
|
|
36
37
|
const output = await this.runInput(botContext);
|
|
37
|
-
if (botContext.session._botonic_action?.startsWith(
|
|
38
|
+
if (botContext.session._botonic_action?.startsWith(BotonicAction.Redirect)) {
|
|
38
39
|
return await this.runRedirectAction(output, botContext);
|
|
39
40
|
}
|
|
40
41
|
return output;
|
|
@@ -51,14 +52,14 @@ class CoreBot {
|
|
|
51
52
|
plugins: this.plugins,
|
|
52
53
|
defaultTyping: this.defaultTyping,
|
|
53
54
|
defaultDelay: this.defaultDelay,
|
|
54
|
-
getUserCountry: ()
|
|
55
|
-
getUserLocale: ()
|
|
56
|
-
getSystemLocale: ()
|
|
57
|
-
setUserCountry: (country)
|
|
58
|
-
setUserLocale: (locale)
|
|
59
|
-
setSystemLocale: (locale)
|
|
55
|
+
getUserCountry: ()=>session.user.country,
|
|
56
|
+
getUserLocale: ()=>session.user.locale,
|
|
57
|
+
getSystemLocale: ()=>session.user.system_locale,
|
|
58
|
+
setUserCountry: (country)=>this.setUserCountry(country, session),
|
|
59
|
+
setUserLocale: (locale)=>this.setUserLocale(locale, session),
|
|
60
|
+
setSystemLocale: (locale)=>this.setSystemLocale(locale, session),
|
|
60
61
|
settings,
|
|
61
|
-
secrets
|
|
62
|
+
secrets
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
getSettings(request) {
|
|
@@ -72,7 +73,7 @@ class CoreBot {
|
|
|
72
73
|
AZURE_OPENAI_API_VERSION: '',
|
|
73
74
|
CUSTOM_SHORT_URL_HOST: '',
|
|
74
75
|
LANGUAGE_DETECTION_ENABLED: false,
|
|
75
|
-
custom: {}
|
|
76
|
+
custom: {}
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
return request.settings;
|
|
@@ -84,7 +85,7 @@ class CoreBot {
|
|
|
84
85
|
HUBTYPE_ACCESS_TOKEN: '',
|
|
85
86
|
LITELLM_API_KEY: '',
|
|
86
87
|
AZURE_OPENAI_API_KEY: '',
|
|
87
|
-
custom: {}
|
|
88
|
+
custom: {}
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
return request.secrets;
|
|
@@ -92,14 +93,14 @@ class CoreBot {
|
|
|
92
93
|
async runInput(botContext) {
|
|
93
94
|
// After first updateSession, user country locale and system_locale are always defined
|
|
94
95
|
this.updateSession(botContext.session);
|
|
95
|
-
if (botContext.input.type ===
|
|
96
|
+
if (botContext.input.type === INPUT.CHAT_EVENT) {
|
|
96
97
|
return {
|
|
97
98
|
input: botContext.input,
|
|
98
99
|
session: botContext.session,
|
|
99
100
|
lastRoutePath: botContext.lastRoutePath,
|
|
100
101
|
settings: botContext.settings,
|
|
101
102
|
secrets: botContext.secrets,
|
|
102
|
-
response: []
|
|
103
|
+
response: []
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
106
|
await this.runPrePlugins(botContext);
|
|
@@ -107,7 +108,11 @@ class CoreBot {
|
|
|
107
108
|
botContext = this.updateRequestFromOutput(botContext, output);
|
|
108
109
|
const response = await this.renderer({
|
|
109
110
|
request: botContext,
|
|
110
|
-
actions: [
|
|
111
|
+
actions: [
|
|
112
|
+
output.fallbackAction,
|
|
113
|
+
output.action,
|
|
114
|
+
output.emptyAction
|
|
115
|
+
]
|
|
111
116
|
});
|
|
112
117
|
await this.runPostPlugins(botContext, response);
|
|
113
118
|
botContext.session.is_first_interaction = false;
|
|
@@ -117,7 +122,7 @@ class CoreBot {
|
|
|
117
122
|
lastRoutePath: botContext.lastRoutePath,
|
|
118
123
|
settings: botContext.settings,
|
|
119
124
|
secrets: botContext.secrets,
|
|
120
|
-
response
|
|
125
|
+
response
|
|
121
126
|
};
|
|
122
127
|
}
|
|
123
128
|
updateSession(session) {
|
|
@@ -139,7 +144,10 @@ class CoreBot {
|
|
|
139
144
|
}
|
|
140
145
|
async runPrePlugins(botContext) {
|
|
141
146
|
if (this.plugins) {
|
|
142
|
-
await
|
|
147
|
+
await runPlugins({
|
|
148
|
+
botContext,
|
|
149
|
+
mode: 'pre'
|
|
150
|
+
});
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
153
|
async getOutput(botContext) {
|
|
@@ -149,9 +157,9 @@ class CoreBot {
|
|
|
149
157
|
}
|
|
150
158
|
async setRouter(botContext) {
|
|
151
159
|
if (this.routes instanceof Function) {
|
|
152
|
-
this.router = new
|
|
153
|
-
...
|
|
154
|
-
...this.defaultRoutes
|
|
160
|
+
this.router = new Router([
|
|
161
|
+
...await getComputedRoutes(this.routes, botContext),
|
|
162
|
+
...this.defaultRoutes
|
|
155
163
|
], this.inspector.routeInspector);
|
|
156
164
|
}
|
|
157
165
|
}
|
|
@@ -159,15 +167,15 @@ class CoreBot {
|
|
|
159
167
|
return {
|
|
160
168
|
...botContext,
|
|
161
169
|
params: output.params || {},
|
|
162
|
-
lastRoutePath: output.lastRoutePath
|
|
170
|
+
lastRoutePath: output.lastRoutePath
|
|
163
171
|
};
|
|
164
172
|
}
|
|
165
173
|
async runPostPlugins(botContext, response) {
|
|
166
174
|
if (this.plugins) {
|
|
167
|
-
await
|
|
175
|
+
await runPlugins({
|
|
168
176
|
botContext,
|
|
169
177
|
mode: 'post',
|
|
170
|
-
response
|
|
178
|
+
response
|
|
171
179
|
});
|
|
172
180
|
}
|
|
173
181
|
}
|
|
@@ -175,13 +183,13 @@ class CoreBot {
|
|
|
175
183
|
if (numOfRedirects > 10) {
|
|
176
184
|
throw new Error('Maximum BotAction recursive calls reached (10)');
|
|
177
185
|
}
|
|
178
|
-
const nextPayload = botContext.session._botonic_action?.split(`${
|
|
186
|
+
const nextPayload = botContext.session._botonic_action?.split(`${BotonicAction.Redirect}:`)[1];
|
|
179
187
|
const inputWithBotActionPayload = {
|
|
180
188
|
...botContext.input,
|
|
181
189
|
payload: nextPayload,
|
|
182
|
-
type:
|
|
190
|
+
type: INPUT.POSTBACK,
|
|
183
191
|
data: undefined,
|
|
184
|
-
text: undefined
|
|
192
|
+
text: undefined
|
|
185
193
|
};
|
|
186
194
|
botContext.session._botonic_action = undefined;
|
|
187
195
|
botContext.input = inputWithBotActionPayload;
|
|
@@ -192,14 +200,43 @@ class CoreBot {
|
|
|
192
200
|
session: botContext.session,
|
|
193
201
|
lastRoutePath: followUp.lastRoutePath,
|
|
194
202
|
settings: followUp.settings,
|
|
195
|
-
secrets: followUp.secrets
|
|
203
|
+
secrets: followUp.secrets
|
|
196
204
|
};
|
|
197
205
|
// Recursive call to handle multiple bot actions in a row
|
|
198
|
-
if (response.session._botonic_action?.startsWith(
|
|
206
|
+
if (response.session._botonic_action?.startsWith(BotonicAction.Redirect)) {
|
|
199
207
|
return await this.runRedirectAction(response, botContext, numOfRedirects + 1);
|
|
200
208
|
}
|
|
201
209
|
return response;
|
|
202
210
|
}
|
|
211
|
+
constructor({ renderer, routes, theme, plugins, appId, defaultTyping = 0.6, defaultDelay = 0.4, defaultRoutes, inspector }){
|
|
212
|
+
_define_property(this, "appId", void 0);
|
|
213
|
+
_define_property(this, "defaultDelay", void 0);
|
|
214
|
+
_define_property(this, "defaultRoutes", void 0);
|
|
215
|
+
_define_property(this, "defaultTyping", void 0);
|
|
216
|
+
_define_property(this, "inspector", void 0);
|
|
217
|
+
_define_property(this, "plugins", void 0);
|
|
218
|
+
_define_property(this, "renderer", void 0); // TODO use a type like ({ request, actions }: RendererArgs) => Promise<any[]>
|
|
219
|
+
_define_property(this, "rootElement", void 0);
|
|
220
|
+
_define_property(this, "router", void 0);
|
|
221
|
+
_define_property(this, "routes", void 0);
|
|
222
|
+
_define_property(this, "theme", void 0);
|
|
223
|
+
this.renderer = renderer;
|
|
224
|
+
this.plugins = plugins || {};
|
|
225
|
+
this.theme = theme || {};
|
|
226
|
+
this.defaultTyping = defaultTyping;
|
|
227
|
+
this.defaultDelay = defaultDelay;
|
|
228
|
+
this.appId = appId || undefined;
|
|
229
|
+
this.rootElement = null;
|
|
230
|
+
this.inspector = inspector || new Inspector();
|
|
231
|
+
this.routes = routes;
|
|
232
|
+
this.defaultRoutes = defaultRoutes || [];
|
|
233
|
+
this.router = this.routes instanceof Function ? null : new Router([
|
|
234
|
+
...this.routes,
|
|
235
|
+
...this.defaultRoutes
|
|
236
|
+
], this.inspector.routeInspector);
|
|
237
|
+
}
|
|
203
238
|
}
|
|
204
|
-
|
|
239
|
+
|
|
240
|
+
export { CoreBot };
|
|
241
|
+
|
|
205
242
|
//# sourceMappingURL=core-bot.js.map
|
package/lib/esm/core-bot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qCAciB;AACjB,uCAAsC;AACtC,uCAAqD;AAcrD,MAAa,OAAO;IAalB,YAAY,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,OAAO,EACP,KAAK,EACL,aAAa,GAAG,GAAG,EACnB,YAAY,GAAG,GAAG,EAClB,aAAa,EACb,SAAS,GACK;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAA;QAC5B,IAAI,CAAC,KAAK,GA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Request,\n type BotResponse,\n type BotSecrets,\n type BotSettings,\n INPUT,\n type Input,\n type ProcessInputResult,\n type ResolvedPlugins,\n type Route,\n type Routes,\n type Session,\n} from './models'\nimport { runPlugins } from './plugins'\nimport { getComputedRoutes, Router } from './routing'\n\nexport interface CoreBotConfig {\n appId?: string\n defaultDelay?: number\n defaultRoutes?: Route[]\n defaultTyping?: number\n inspector?: Inspector\n plugins?: ResolvedPlugins\n renderer: any\n routes: Routes\n theme?: any\n}\n\nexport class CoreBot {\n appId?: string\n defaultDelay: number\n defaultRoutes: Route[]\n defaultTyping: number\n inspector: Inspector\n plugins: ResolvedPlugins\n renderer: any // TODO use a type like ({ request, actions }: RendererArgs) => Promise<any[]>\n rootElement: any\n router: Router | null\n routes: Routes\n theme?: any\n\n constructor({\n renderer,\n routes,\n theme,\n plugins,\n appId,\n defaultTyping = 0.6,\n defaultDelay = 0.4,\n defaultRoutes,\n inspector,\n }: CoreBotConfig) {\n this.renderer = renderer\n this.plugins = plugins || {}\n this.theme = theme || {}\n this.defaultTyping = defaultTyping\n this.defaultDelay = defaultDelay\n this.appId = appId || undefined\n this.rootElement = null\n this.inspector = inspector || new Inspector()\n this.routes = routes\n this.defaultRoutes = defaultRoutes || []\n this.router =\n this.routes instanceof Function\n ? null\n : new Router(\n [...this.routes, ...this.defaultRoutes],\n this.inspector.routeInspector\n )\n }\n\n setSystemLocale(locale: string, session: Session): void {\n session.user.system_locale = locale\n }\n\n setUserLocale(locale: string, session: Session): void {\n session.user.locale = locale\n }\n\n setUserCountry(country: string, session: Session): void {\n session.user.country = country\n }\n\n async input(request: BotRequest): Promise<BotResponse> {\n const botContext = this.getBotContext(request)\n\n const output = await this.runInput(botContext)\n\n if (\n botContext.session._botonic_action?.startsWith(BotonicAction.Redirect)\n ) {\n return await this.runRedirectAction(output, botContext)\n }\n\n return output\n }\n\n private getBotContext(request: BotRequest): BotContext {\n const { input, session, lastRoutePath } = request\n const settings = this.getSettings(request)\n const secrets = this.getSecrets(request)\n\n return {\n input,\n session,\n lastRoutePath,\n params: {},\n plugins: this.plugins,\n defaultTyping: this.defaultTyping,\n defaultDelay: this.defaultDelay,\n getUserCountry: () => session.user.country,\n getUserLocale: () => session.user.locale,\n getSystemLocale: () => session.user.system_locale,\n setUserCountry: (country: string) =>\n this.setUserCountry(country, session),\n setUserLocale: (locale: string) => this.setUserLocale(locale, session),\n setSystemLocale: (locale: string) =>\n this.setSystemLocale(locale, session),\n settings,\n secrets,\n }\n }\n\n private getSettings(request: BotRequest): BotSettings {\n if (!request.settings) {\n // This only happens in local development\n return {\n HUBTYPE_API_URL: '',\n STATIC_URL: '',\n LITELLM_API_URL: '',\n AZURE_OPENAI_API_BASE: '',\n AZURE_OPENAI_API_VERSION: '',\n CUSTOM_SHORT_URL_HOST: '',\n LANGUAGE_DETECTION_ENABLED: false,\n custom: {},\n }\n }\n\n return request.settings\n }\n\n private getSecrets(request: BotRequest): BotSecrets {\n if (!request.secrets) {\n // This only happens in local development\n return {\n HUBTYPE_ACCESS_TOKEN: '',\n LITELLM_API_KEY: '',\n AZURE_OPENAI_API_KEY: '',\n custom: {},\n }\n }\n\n return request.secrets\n }\n\n private async runInput(botContext: BotContext): Promise<BotResponse> {\n // After first updateSession, user country locale and system_locale are always defined\n this.updateSession(botContext.session)\n\n if (botContext.input.type === INPUT.CHAT_EVENT) {\n return {\n input: botContext.input,\n session: botContext.session,\n lastRoutePath: botContext.lastRoutePath,\n settings: botContext.settings,\n secrets: botContext.secrets,\n response: [],\n }\n }\n\n await this.runPrePlugins(botContext)\n\n const output = await this.getOutput(botContext)\n botContext = this.updateRequestFromOutput(botContext, output)\n const response = await this.renderer({\n request: botContext,\n actions: [output.fallbackAction, output.action, output.emptyAction],\n })\n\n await this.runPostPlugins(botContext, response)\n\n botContext.session.is_first_interaction = false\n\n return {\n input: botContext.input,\n session: botContext.session,\n lastRoutePath: botContext.lastRoutePath,\n settings: botContext.settings,\n secrets: botContext.secrets,\n response,\n }\n }\n\n private updateSession(session: Session) {\n // set new user fields (country, locale, system_locale) from old fields in extra_data\n if (!session.user.country) {\n const country = session.user.extra_data?.country\n this.setUserCountry(country, session)\n }\n\n if (!session.user.locale) {\n const language = session.user.extra_data?.language\n this.setUserLocale(language, session)\n }\n\n if (!session.user.system_locale) {\n const locale = session.user.locale\n if (locale) {\n this.setSystemLocale(locale, session)\n }\n }\n }\n\n private async runPrePlugins(botContext: BotContext) {\n if (this.plugins) {\n await runPlugins({ botContext, mode: 'pre' })\n }\n }\n\n private async getOutput(botContext: BotContext): Promise<ProcessInputResult> {\n await this.setRouter(botContext)\n\n const output = (this.router as Router).processInput(\n botContext.input,\n botContext.session,\n botContext.lastRoutePath\n )\n return output\n }\n\n private async setRouter(botContext: BotContext) {\n if (this.routes instanceof Function) {\n this.router = new Router(\n [\n ...(await getComputedRoutes(this.routes, botContext)),\n ...this.defaultRoutes,\n ],\n this.inspector.routeInspector\n )\n }\n }\n\n private updateRequestFromOutput(\n botContext: BotContext,\n output: ProcessInputResult\n ): BotContext {\n return {\n ...botContext,\n params: output.params || {},\n lastRoutePath: output.lastRoutePath,\n }\n }\n\n private async runPostPlugins(botContext: BotContext, response: any) {\n if (this.plugins) {\n await runPlugins({\n botContext,\n mode: 'post',\n response,\n })\n }\n }\n\n private async runRedirectAction(\n previousResponse: BotResponse,\n botContext: BotContext,\n numOfRedirects: number = 0\n ) {\n if (numOfRedirects > 10) {\n throw new Error('Maximum BotAction recursive calls reached (10)')\n }\n\n const nextPayload = botContext.session._botonic_action?.split(\n `${BotonicAction.Redirect}:`\n )[1]\n\n const inputWithBotActionPayload: Input = {\n ...botContext.input,\n payload: nextPayload,\n type: INPUT.POSTBACK,\n data: undefined,\n text: undefined,\n }\n\n botContext.session._botonic_action = undefined\n botContext.input = inputWithBotActionPayload\n\n const followUp = await this.runInput(botContext)\n\n const response: BotResponse = {\n input: followUp.input,\n response: previousResponse.response.concat(followUp.response),\n session: botContext.session,\n lastRoutePath: followUp.lastRoutePath,\n settings: followUp.settings,\n secrets: followUp.secrets,\n }\n\n // Recursive call to handle multiple bot actions in a row\n if (response.session._botonic_action?.startsWith(BotonicAction.Redirect)) {\n return await this.runRedirectAction(\n response,\n botContext,\n numOfRedirects + 1\n )\n }\n\n return response\n }\n}\n"],"names":["Inspector","BotonicAction","INPUT","runPlugins","getComputedRoutes","Router","CoreBot","locale","session","country","request","botContext","output","input","lastRoutePath","settings","secrets","response","language","Function","previousResponse","numOfRedirects","Error","nextPayload","inputWithBotActionPayload","undefined","followUp","renderer","routes","theme","plugins","appId","defaultTyping","defaultDelay","defaultRoutes","inspector"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAmC;AAelB;AACqB;AACe;AAc9C,MAAMM,OAAOA;IA2ClB,gBAAgBC,MAAc,EAAEC,OAAgB,EAAQ;QACtDA,QAAQ,IAAI,CAAC,aAAa,GAAGD;IAC/B;IAEA,cAAcA,MAAc,EAAEC,OAAgB,EAAQ;QACpDA,QAAQ,IAAI,CAAC,MAAM,GAAGD;IACxB;IAEA,eAAeE,OAAe,EAAED,OAAgB,EAAQ;QACtDA,QAAQ,IAAI,CAAC,OAAO,GAAGC;IACzB;IAEA,MAAM,MAAMC,OAAmB,EAAwB;QACrD,MAAMC,aAAa,IAAI,CAAC,aAAa,CAACD;QAEtC,MAAME,SAAS,MAAM,IAAI,CAAC,QAAQ,CAACD;QAEnC,IACEA,WAAW,OAAO,CAAC,eAAe,EAAE,WAAWV,sBAAsB,GACrE;YACA,OAAO,MAAM,IAAI,CAAC,iBAAiB,CAACW,QAAQD;QAC9C;QAEA,OAAOC;IACT;IAEQ,cAAcF,OAAmB,EAAc;QACrD,MAAM,EAAEG,KAAK,EAAEL,OAAO,EAAEM,aAAa,EAAE,GAAGJ;QAC1C,MAAMK,WAAW,IAAI,CAAC,WAAW,CAACL;QAClC,MAAMM,UAAU,IAAI,CAAC,UAAU,CAACN;QAEhC,OAAO;YACLG;YACAL;YACAM;YACA,QAAQ,CAAC;YACT,SAAS,IAAI,CAAC,OA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AO;YAC3B,eAAee,SAAS,aAAa;YACrC,UAAUA,SAAS,QAAQ;YAC3B,SAASA,SAAS,OAAO;QAC3B;QAEA,yDAAyD;QACzD,IAAIT,SAAS,OAAO,CAAC,eAAe,EAAE,WAAWhB,sBAAsB,GAAG;YACxE,OAAO,MAAM,IAAI,CAAC,iBAAiB,CACjCgB,UACAN,YACAU,iBAAiB;QAErB;QAEA,OAAOJ;IACT;IA3QA,YAAY,EACVU,QAAQ,EACRC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,gBAAgB,GAAG,EACnBC,eAAe,GAAG,EAClBC,aAAa,EACbC,SAAS,EACK,CAAE;QAtBlB;QACA;QACA;QACA;QACA;QACA;QACA,4CAAc,8EAA8E;QAC5F;QACA;QACA;QACA;QAaE,IAAI,CAAC,QAAQ,GAAGR;QAChB,IAAI,CAAC,OAAO,GAAGG,WAAW,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAGD,SAAS,CAAC;QACvB,IAAI,CAAC,aAAa,GAAGG;QACrB,IAAI,CAAC,YAAY,GAAGC;QACpB,IAAI,CAAC,KAAK,GAAGF,SAASN;QACtB,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,SAAS,GAAGU,aAAa,IAAInC,SAASA;QAC3C,IAAI,CAAC,MAAM,GAAG4B;QACd,IAAI,CAAC,aAAa,GAAGM,iBAAiB,EAAE;QACxC,IAAI,CAAC,MAAM,GACT,IAAI,CAAC,MAAM,YAAYf,WACnB,OACA,IAAId,MAAMA,CACR;eAAI,IAAI,CAAC,MAAM;eAAK,IAAI,CAAC,aAAa;SAAC,EACvC,IAAI,CAAC,SAAS,CAAC,cAAc;IAEvC;AAgPF"}
|
package/lib/esm/debug/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './inspector';
|
|
1
|
+
export * from './inspector.js';
|
package/lib/esm/debug/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"debug/index.js","sources":["../../../src/debug/index.ts"],"sourcesContent":["export * from './inspector'\n"],"names":[],"mappings":";AAA2B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Route, RouteMatcher } from '../models';
|
|
1
|
+
import type { Route, RouteMatcher } from '../models/index.js';
|
|
2
2
|
export declare class RouteInspector {
|
|
3
3
|
routeMatched(_route: Route, _routeKey: string, _routeValue: RouteMatcher, _input: any): void;
|
|
4
4
|
routeNotMatched(_route: Route, _routeKey: string, _routeValue: RouteMatcher, _input: any): void;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
4
12
|
class RouteInspector {
|
|
5
|
-
routeMatched(_route, _routeKey, _routeValue, _input) {
|
|
6
|
-
routeNotMatched(_route, _routeKey, _routeValue, _input) {
|
|
13
|
+
routeMatched(_route, _routeKey, _routeValue, _input) {}
|
|
14
|
+
routeNotMatched(_route, _routeKey, _routeValue, _input) {}
|
|
7
15
|
}
|
|
8
|
-
exports.RouteInspector = RouteInspector;
|
|
9
16
|
class FocusRouteInspector extends RouteInspector {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this.focusRoutePaths = null;
|
|
13
|
-
this.focusOnMatches = false;
|
|
14
|
-
}
|
|
15
17
|
focusOnlyOnRoutes(focusRoutePaths) {
|
|
16
18
|
this.focusRoutePaths = focusRoutePaths;
|
|
17
19
|
return this;
|
|
@@ -26,22 +28,24 @@ class FocusRouteInspector extends RouteInspector {
|
|
|
26
28
|
}
|
|
27
29
|
return this.focusRoutePaths.includes(route.path);
|
|
28
30
|
}
|
|
31
|
+
constructor(){
|
|
32
|
+
super(), _define_property(this, "focusRoutePaths", void 0), _define_property(this, "focusOnMatches", void 0);
|
|
33
|
+
this.focusRoutePaths = null;
|
|
34
|
+
this.focusOnMatches = false;
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
|
-
exports.FocusRouteInspector = FocusRouteInspector;
|
|
31
37
|
class LogRouteInspector extends FocusRouteInspector {
|
|
32
38
|
routeMatched(route, routeKey, routeValue, inputValue) {
|
|
33
39
|
if (!this._isOnFocus(route)) {
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
36
|
-
this._log(`Route ${this._routeName(route)} selected ` +
|
|
37
|
-
`because Input.${routeKey} (${inputValue}) matched '${routeValue}'`);
|
|
42
|
+
this._log(`Route ${this._routeName(route)} selected ` + `because Input.${routeKey} (${inputValue}) matched '${routeValue}'`);
|
|
38
43
|
}
|
|
39
44
|
routeNotMatched(route, routeKey, routeValue, inputValue) {
|
|
40
45
|
if (!this._isOnFocus(route) || this.focusOnMatches) {
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
|
-
this._log(`Route ${this._routeName(route)} not selected ` +
|
|
44
|
-
`because Input.${routeKey} (${inputValue}) did not match '${routeValue}'`);
|
|
48
|
+
this._log(`Route ${this._routeName(route)} not selected ` + `because Input.${routeKey} (${inputValue}) did not match '${routeValue}'`);
|
|
45
49
|
}
|
|
46
50
|
_routeName(obj) {
|
|
47
51
|
let name = obj.path || '<<no path defined>>';
|
|
@@ -57,14 +61,16 @@ class LogRouteInspector extends FocusRouteInspector {
|
|
|
57
61
|
console.log(message, ...optionalParams);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
|
-
exports.LogRouteInspector = LogRouteInspector;
|
|
61
64
|
class Inspector {
|
|
62
|
-
constructor(routeInspector = undefined) {
|
|
63
|
-
this.routeInspector = routeInspector || new RouteInspector();
|
|
64
|
-
}
|
|
65
65
|
getRouteInspector() {
|
|
66
66
|
return this.routeInspector;
|
|
67
67
|
}
|
|
68
|
+
constructor(routeInspector = undefined){
|
|
69
|
+
_define_property(this, "routeInspector", void 0);
|
|
70
|
+
this.routeInspector = routeInspector || new RouteInspector();
|
|
71
|
+
}
|
|
68
72
|
}
|
|
69
|
-
|
|
73
|
+
|
|
74
|
+
export { FocusRouteInspector, Inspector, LogRouteInspector, RouteInspector };
|
|
75
|
+
|
|
70
76
|
//# sourceMappingURL=inspector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector.js","
|
|
1
|
+
{"version":3,"file":"debug/inspector.js","sources":["../../../src/debug/inspector.ts"],"sourcesContent":["import type { Route, RouteMatcher } from '../models'\nexport class RouteInspector {\n routeMatched(\n _route: Route,\n _routeKey: string,\n _routeValue: RouteMatcher,\n _input: any\n ): void {}\n routeNotMatched(\n _route: Route,\n _routeKey: string,\n _routeValue: RouteMatcher,\n _input: any\n ): void {}\n}\n\nexport class FocusRouteInspector extends RouteInspector {\n focusRoutePaths: string[] | null\n focusOnMatches: boolean\n constructor() {\n super()\n this.focusRoutePaths = null\n this.focusOnMatches = false\n }\n\n focusOnlyOnRoutes(focusRoutePaths: string[]): this {\n this.focusRoutePaths = focusRoutePaths\n return this\n }\n\n focusOnlyOnMatches(): this {\n this.focusOnMatches = true\n return this\n }\n\n _isOnFocus(route: Route): boolean {\n if (this.focusRoutePaths === null) {\n return true\n }\n return this.focusRoutePaths.includes(route.path as string)\n }\n}\n\nexport class LogRouteInspector extends FocusRouteInspector {\n override routeMatched(\n route: Route,\n routeKey: string,\n routeValue: RouteMatcher,\n inputValue: string\n ): void {\n if (!this._isOnFocus(route)) {\n return\n }\n this._log(\n `Route ${this._routeName(route)} selected ` +\n `because Input.${routeKey} (${inputValue}) matched '${routeValue}'`\n )\n }\n\n override routeNotMatched(\n route: Route,\n routeKey: string,\n routeValue: RouteMatcher,\n inputValue: string\n ): void {\n if (!this._isOnFocus(route) || this.focusOnMatches) {\n return\n }\n this._log(\n `Route ${this._routeName(route)} not selected ` +\n `because Input.${routeKey} (${inputValue}) did not match '${routeValue}'`\n )\n }\n\n _routeName(obj: Route): string {\n let name = obj.path || '<<no path defined>>'\n if (obj.action) {\n name = `'${name}' (to action '${obj.action.name}')`\n }\n if (obj.redirect) {\n name = `'${name}' (with redirect to '${obj.redirect}')`\n }\n return name as string\n }\n\n _log(message: string, ...optionalParams: string[]): void {\n console.log(message, ...optionalParams)\n }\n}\n\nexport class Inspector {\n routeInspector: RouteInspector\n constructor(routeInspector: RouteInspector | undefined = undefined) {\n this.routeInspector = routeInspector || new RouteInspector()\n }\n\n getRouteInspector(): RouteInspector {\n return this.routeInspector\n }\n}\n"],"names":["RouteInspector","_route","_routeKey","_routeValue","_input","FocusRouteInspector","focusRoutePaths","route","LogRouteInspector","routeKey","routeValue","inputValue","obj","name","message","optionalParams","console","Inspector","routeInspector","undefined"],"mappings":";;;;;;;;;;;AACO,MAAMA,cAAcA;IACzB,aACEC,MAAa,EACbC,SAAiB,EACjBC,WAAyB,EACzBC,MAAW,EACL,CAAC;IACT,gBACEH,MAAa,EACbC,SAAiB,EACjBC,WAAyB,EACzBC,MAAW,EACL,CAAC;AACX;AAEO,MAAMC,mBAAmBA,SAASL,cAAcA;IASrD,kBAAkBM,eAAyB,EAAQ;QACjD,IAAI,CAAC,eAAe,GAAGA;QACvB,OAAO,IAAI;IACb;IAEA,qBAA2B;QACzB,IAAI,CAAC,cAAc,GAAG;QACtB,OAAO,IAAI;IACb;IAEA,WAAWC,KAAY,EAAW;QAChC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM;YACjC,OAAO;QACT;QACA,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAACA,MAAM,IAAI;IACjD;IArBA,aAAc;QACZ,KAAK,IAHP,mDACA;QAGE,IAAI,CAAC,eAAe,GAAG;QACvB,IAAI,CAAC,cAAc,GAAG;IACxB;AAkBF;AAEO,MAAMC,iBAAiBA,SAASH,mBAAmBA;IAC/C,aACPE,KAAY,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