Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@salutejs/scenario

Package Overview
Dependencies
Maintainers
3
Versions
246
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salutejs/scenario - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

4

dist/lib/createIntents.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createIntents = void 0;
var createIntents = function (intents) {
return intents;
};
var createIntents = function (intents) { return intents; };
exports.createIntents = createIntents;

@@ -7,2 +7,3 @@ "use strict";

var inference;
var variant;
var variables = {};

@@ -19,5 +20,8 @@ return {

},
get intent() {
get systemIntent() {
return request.payload.intent;
},
get variant() {
return variant;
},
get inference() {

@@ -30,3 +34,4 @@ return inference;

get state() {
return request.payload.meta.current_app.state;
var _a, _b;
return (_b = (_a = request.payload.meta) === null || _a === void 0 ? void 0 : _a.current_app) === null || _b === void 0 ? void 0 : _b.state;
},

@@ -53,4 +58,7 @@ get serverAction() {

},
setVariant: function (v) {
variant = v;
},
};
};
exports.createSaluteRequest = createSaluteRequest;

@@ -73,3 +73,2 @@ "use strict";

},
// TODO: fix types
appendItem: function (item) {

@@ -76,0 +75,0 @@ if (message.messageName !== 'ANSWER_TO_USER') {

@@ -46,12 +46,15 @@ "use strict";

return __awaiter(void 0, void 0, void 0, function () {
var dispatch, saluteHandlerOpts, variant, currentIntent, connected, missingVars, question, scenarioState, missingVars;
var _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
var dispatch, saluteHandlerOpts, scenarioState, missingVars;
var _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
dispatch = function (path) { return __awaiter(void 0, void 0, void 0, function () {
var state;
return __generator(this, function (_a) {
switch (_a.label) {
var state, currentIntent, connected, currentIntentPath, missingVars, question;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!userScenario)
return [2 /*return*/];
state = userScenario.getByPath(path);

@@ -64,6 +67,32 @@ if (!state) return [3 /*break*/, 2];

};
if (req.variant && intents) {
req.variant.slots.forEach(function (slot) {
req.setVariable(slot.name, slot.value);
});
currentIntent = req.variant;
if (session.path.length && session.slotFilling) {
connected = (((_a = req.inference) === null || _a === void 0 ? void 0 : _a.variants) || []).find(function (v) { return v.confidence >= slotFillingConfidence && v.intent.path === session.currentIntent; });
currentIntent = connected || req.variant;
}
currentIntentPath = currentIntent.intent.path;
session.currentIntent = currentIntentPath;
missingVars = missingVariables_1.lookupMissingVariables(currentIntentPath, intents, req.variables);
if (missingVars.length) {
// сохраняем состояние в сессии
Object.keys(req.variables).forEach(function (name) {
session.variables[name] = req.variables[name];
});
question = missingVars[0].question;
res.appendBubble(question);
res.setPronounceText(question);
// устанавливаем флаг слотфиллинга, на него будем смотреть при следующем запросе пользователя
session.slotFilling = true;
return [2 /*return*/];
}
// SLOTFILING LOGIC END
}
return [4 /*yield*/, state.handle({ req: req, res: res, session: session.state, history: {} }, dispatch)];
case 1:
_a.sent();
_a.label = 2;
_b.sent();
_b.label = 2;
case 2: return [2 /*return*/];

@@ -74,3 +103,3 @@ }

saluteHandlerOpts = { req: req, res: res, session: session.state, history: {} };
if (req.intent === 'run_app') {
if (req.systemIntent === 'run_app') {
if (((_b = req.serverAction) === null || _b === void 0 ? void 0 : _b.action_id) === 'PAY_DIALOG_FINISHED') {

@@ -90,3 +119,3 @@ if (typeof systemScenario.PAY_DIALOG_FINISHED === 'undefined') {

}
if (req.intent === 'close_app') {
if (req.systemIntent === 'close_app') {
systemScenario.CLOSE_APP(saluteHandlerOpts, dispatch);

@@ -99,44 +128,15 @@ return [2 /*return*/];

});
if (!(typeof intents !== undefined && typeof userScenario !== undefined)) return [3 /*break*/, 4];
if (!(typeof intents !== undefined && userScenario)) return [3 /*break*/, 4];
// restore request from server_action payload
if (req.serverAction) {
Object.keys(req.serverAction.payload || {}).forEach(function (key) {
req.setVariable(key, req.serverAction.payload[key]);
Object.keys((req.serverAction.payload || {})).forEach(function (key) {
var _a;
req.setVariable(key, ((_a = req.serverAction) === null || _a === void 0 ? void 0 : _a.payload)[key]);
});
}
if (!(req.voiceAction && typeof recognizer !== 'undefined' && typeof intents !== 'undefined')) return [3 /*break*/, 2];
// INFERENCE LOGIC START
if (!(req.voiceAction && typeof recognizer !== 'undefined')) return [3 /*break*/, 2];
return [4 /*yield*/, recognizer.inference({ req: req, res: res, session: session })];
case 1:
// INFERENCE LOGIC START
_e.sent();
variant = ((_c = req.inference) === null || _c === void 0 ? void 0 : _c.variants.length) > 0 ? req.inference.variants[0] : null;
if (variant) {
variant.slots.forEach(function (slot) {
req.setVariable(slot.name, slot.value);
});
currentIntent = variant;
if (session.path.length && session.slotFilling) {
connected = (((_d = req.inference) === null || _d === void 0 ? void 0 : _d.variants) || []).find(function (v) { return v.confidence >= slotFillingConfidence && v.intent.path === session.currentIntent; });
currentIntent = connected || variant;
}
missingVars = missingVariables_1.lookupMissingVariables(currentIntent.intent.path, intents, req.variables);
if (missingVars.length) {
// сохраняем состояние в сессии
Object.keys(req.variables).forEach(function (name) {
session.variables[name] = req.variables[name];
});
question = missingVars[0].question;
res.appendBubble(question);
res.setPronounceText(question);
// устанавливаем флаг слотфиллинга, на него будем смотреть при следующем запросе пользователя
session.slotFilling = true;
session.currentIntent = currentIntent.intent.path;
return [2 /*return*/];
}
// SLOTFILING LOGIC END
session.currentIntent = currentIntent.intent.path;
// INFERENCE LOGIC END
}
_e.label = 2;
_c.sent();
_c.label = 2;
case 2:

@@ -168,3 +168,3 @@ scenarioState = userScenario.resolve(session.path, req);

case 3:
_e.sent();
_c.sent();
if (!req.currentState.state.children) {

@@ -171,0 +171,0 @@ session.path = [];

@@ -8,3 +8,3 @@ import { SaluteHandler } from '@salutejs/types';

};
export declare const createSystemScenario: (systemScenarioSchema?: Partial<SystemScenario>) => SystemScenario;
export declare const createSystemScenario: (systemScenarioSchema?: Partial<SystemScenario> | undefined) => SystemScenario;
//# sourceMappingURL=createSystemScenario.d.ts.map

@@ -8,3 +8,3 @@ import { SaluteRequest, ScenarioSchema } from '@salutejs/types';

}>) => boolean;
schema?: string;
schema?: string | undefined;
handle: import("@salutejs/types").SaluteHandler<SaluteRequest<Record<string, unknown>, import("@salutejs/types").AppState, {

@@ -14,9 +14,9 @@ payload: unknown;

}>, Record<string, unknown>, import("@salutejs/types").SaluteResponse, Record<string, unknown>>;
children?: Record<string, any>;
};
children?: Record<string, any> | undefined;
} | undefined;
resolve: (path: string[], req: R) => {
path: string[];
state: ScenarioSchema['string'];
};
} | null;
};
//# sourceMappingURL=createUserScenario.d.ts.map

@@ -30,3 +30,4 @@ "use strict";

};
/** Возвращает обработчик запроса для указанного пути в дереве диалогов
/**
* Возвращает обработчик запроса для указанного пути в дереве диалогов
* @param path путь в дереве диалога, поиск будет выполнен среди вложенных обработчиков

@@ -37,11 +38,13 @@ * @param req объект запроса

var resolve = function (path, req) {
var matchedState;
var matchedState = null;
if (path.length > 0) {
var children = getByPath(path).children;
for (var _i = 0, _a = Object.keys(children); _i < _a.length; _i++) {
var el = _a[_i];
var nextState = children[el];
if (nextState.match(req)) {
matchedState = { state: nextState, path: __spreadArrays(path, [el]) };
break;
var state = getByPath(path);
if (state === null || state === void 0 ? void 0 : state.children) {
for (var _i = 0, _a = Object.keys(state === null || state === void 0 ? void 0 : state.children); _i < _a.length; _i++) {
var el = _a[_i];
var nextState = state === null || state === void 0 ? void 0 : state.children[el];
if (nextState.match(req)) {
matchedState = { state: nextState, path: __spreadArrays(path, [el]) };
break;
}
}

@@ -48,0 +51,0 @@ }

@@ -48,3 +48,6 @@ "use strict";

}
res.push(template.substring(pos, p1), options[template.substring(p1 + 1, p2)]);
res.push(template.substring(pos, p1));
var opts = options[template.substring(p1 + 1, p2)];
if (opts)
res.push(opts);
pos = p2 + 1;

@@ -51,0 +54,0 @@ }

@@ -1,29 +0,31 @@

import { IntentsDict, SaluteRequest } from '@salutejs/types';
import { AppState, IntentsDict, SaluteRequest } from '@salutejs/types';
export declare const compare: (expected: any, actual: any) => any;
export declare function createMatchers<R extends SaluteRequest = SaluteRequest, I extends IntentsDict = IntentsDict>(): {
match: (...matchers: ((req: R) => boolean)[]) => (req: R) => boolean;
intent: (expected: keyof I) => (req: R) => boolean;
intent: (expected: keyof I, { confidence }?: {
confidence: number;
}) => (req: R) => boolean;
text: (expected: string | RegExp) => (req: R) => boolean;
state: (expected: Partial<R['state']>) => (req: R) => any;
selectItem: (expected: Partial<R['state']['item_selector']['items'][number]>) => (req: R) => {
selectItem: (expected: AppState) => (req: R) => {
[k: string]: unknown;
number?: number;
id?: string;
title?: string;
aliases?: string[];
number?: number | undefined;
id?: string | undefined;
title?: string | undefined;
aliases?: string[] | undefined;
server_action?: unknown;
action?: unknown;
};
selectItems: (expected: Partial<R['state']['item_selector']['items'][number]>) => (req: R) => {
} | undefined;
selectItems: (expected: AppState) => (req: R) => {
[k: string]: unknown;
number?: number;
id?: string;
title?: string;
aliases?: string[];
number?: number | undefined;
id?: string | undefined;
title?: string | undefined;
aliases?: string[] | undefined;
server_action?: unknown;
action?: unknown;
}[];
action: (expected: R['serverAction']['type']) => (req: R) => boolean;
}[] | undefined;
action: (expected: string) => (req: R) => boolean;
regexp: (re: RegExp) => (req: R) => boolean;
};
//# sourceMappingURL=matchers.d.ts.map

@@ -27,8 +27,16 @@ "use strict";

function createMatchers() {
var intent = function (expected) { return function (req) {
var _a, _b;
if (!((_a = req.inference) === null || _a === void 0 ? void 0 : _a.variants.length))
var intent = function (expected, _a) {
var _b = _a === void 0 ? { confidence: 0.7 } : _a, confidence = _b.confidence;
return function (req) {
var _a, _b;
if (!((_a = req.inference) === null || _a === void 0 ? void 0 : _a.variants.length))
return false;
var variant = (_b = req.inference) === null || _b === void 0 ? void 0 : _b.variants.find(function (v) { return v.intent.path === expected && v.confidence >= confidence; });
if (variant) {
req.setVariant(variant);
return true;
}
return false;
return ((_b = req.inference) === null || _b === void 0 ? void 0 : _b.variants[0].intent.path) === expected;
}; };
};
};
var text = function (expected) { return function (req) {

@@ -44,5 +52,7 @@ var actual = req.message.original_text;

var action = function (expected) { return function (req) { var _a; return ((_a = req.serverAction) === null || _a === void 0 ? void 0 : _a.type) === expected; }; };
var selectItems = function (expected) { return function (req) { var _a, _b; return (_b = (_a = req.state.item_selector) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.filter(function (i) { return exports.compare(expected, i); }); }; };
var selectItems = function (expected) { return function (req) { var _a, _b, _c; return (_c = (_b = (_a = req.state) === null || _a === void 0 ? void 0 : _a.item_selector) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.filter(function (i) { return exports.compare(expected, i); }); }; };
var selectItem = function (expected) { return function (req) {
return selectItems(expected)(req)[0];
var items = selectItems(expected)(req);
if (items)
return items[0];
}; };

@@ -49,0 +59,0 @@ var regexp = function (re) { return function (req) {

@@ -9,6 +9,6 @@ "use strict";

Object.keys(vars).forEach(function (v) {
var _a;
if (vars[v].required && variables[v] === undefined && ((_a = vars[v].questions) === null || _a === void 0 ? void 0 : _a.length)) {
var questionNo = Math.floor(Math.random() * vars[v].questions.length);
missing.push({ name: v, question: vars[v].questions[questionNo] });
var _a = vars[v], questions = _a.questions, required = _a.required;
if (questions && (questions === null || questions === void 0 ? void 0 : questions.length) && required && variables[v] === undefined) {
var questionNo = Math.floor(Math.random() * questions.length);
missing.push({ name: v, question: questions[questionNo] });
}

@@ -15,0 +15,0 @@ });

@@ -42,3 +42,3 @@ "use strict";

return callApi(API_URL + "/invoices/" + encodeURIComponent(invoiceId) + (params && (params.invStatus || typeof params.wait !== 'undefined')
? "?" + ((_a = params.invStatus) !== null && _a !== void 0 ? _a : "inv_status=" + encodeURIComponent(params.invStatus)) + ((_b = params.wait) !== null && _b !== void 0 ? _b : ((_c = params.invStatus) !== null && _c !== void 0 ? _c : '&') + "wait=" + encodeURIComponent(params.wait))
? "?" + ((_a = params.invStatus) !== null && _a !== void 0 ? _a : "inv_status=" + encodeURIComponent(!params.invStatus)) + ((_b = params.wait) !== null && _b !== void 0 ? _b : ((_c = params.invStatus) !== null && _c !== void 0 ? _c : '&') + "wait=" + encodeURIComponent(params.wait))
: ''));

@@ -57,3 +57,3 @@ };

if (params === void 0) { params = {}; }
return callApi(API_URL + "/invoices/0?service_id=" + encodeURIComponent(serviceId) + "&order_id=" + encodeURIComponent(orderId) + ((_a = params.invStatus) !== null && _a !== void 0 ? _a : "&inv_status=" + encodeURIComponent(params.invStatus) + ((_b = params.wait) !== null && _b !== void 0 ? _b : "&wait=" + encodeURIComponent(params.wait))));
return callApi(API_URL + "/invoices/0?service_id=" + encodeURIComponent(serviceId) + "&order_id=" + encodeURIComponent(orderId) + ((_a = params.invStatus) !== null && _a !== void 0 ? _a : "&inv_status=" + encodeURIComponent(!params.invStatus) + ((_b = params.wait) !== null && _b !== void 0 ? _b : "&wait=" + encodeURIComponent(!params.wait))));
};

@@ -60,0 +60,0 @@ exports.findInvoiceByServiceIdOrderId = findInvoiceByServiceIdOrderId;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PayDialogStatuses = exports.PaymentInvoiceStatuses = exports.PaymentReponseStatuses = exports.NdsTypes = exports.TaxSystemTypes = exports.PaymentTypes = void 0;
/* eslint-disable no-shadow */
/** Тип оплаты счета */

@@ -5,0 +6,0 @@ var PaymentTypes;

{
"name": "@salutejs/scenario",
"version": "0.5.0",
"version": "0.6.0",
"description": "Tiny helpers to make scenario for Salute family",

@@ -35,6 +35,6 @@ "author": "SberDevices Frontend Team <sberdevices.frontend@gmail.com>",

"dependencies": {
"@salutejs/types": "0.5.0",
"@salutejs/types": "0.6.0",
"node-fetch": "2.6.1"
},
"gitHead": "40cd4fcb637366dc43fad1b9a1447b331e458fac"
"gitHead": "6967e37ba23ba2afdc6333afa3bf0b27e8383b59"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc