New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prague

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prague - npm Package Compare versions

Comparing version 0.6.5 to 0.7.0

dist/core/Dialogs.d.ts

4

core/ChatState.ts

@@ -1,4 +0,4 @@

export interface ChatState<BOT = undefined, USER = undefined, CHANNEL = undefined, CONVERSATION = undefined, USERINCONVERSATION = undefined> {
export interface ChatState<BOT = undefined, USERINCHANNEL = undefined, CHANNEL = undefined, CONVERSATION = undefined, USERINCONVERSATION = undefined> {
bot?: BOT
user?: USER,
userInChannel?: USERINCHANNEL,
channel?: CHANNEL,

@@ -5,0 +5,0 @@ conversation?: CONVERSATION,

@@ -1,39 +0,276 @@

import { IRule, SimpleRule, Observizeable, RuleResult, BaseRule, Matcher, Handler, Match, observize, combineMatchers } from './Rules';
import { Match, IRule, BaseRule, RuleResult, Observableable, toObservable, toFilteredObservable } from './Rules';
import { Observable } from 'rxjs';
import { ITextMatch } from './Text';
import { konsole } from './Konsole';
export interface DialogRules<M> {
[promptKey: string]: IRule<M>;
const pragueRoot = 'pragueRoot';
export interface DialogInstance {
name: string;
instance: string;
}
export class Dialogs<M extends Match = any> extends BaseRule<M> {
export interface DialogRegistry<M extends Match = any> {
[name: string]: IDialog<M>;
}
export interface IDialogRootMatch {
beginChildDialog<DIALOGARGS extends object = any>(name: string, args?: DIALOGARGS): Observableable<void>;
clearChildDialog(): Observableable<void>;
}
export type IDialogData<DIALOGDATA extends object> = { childDialogInstance?: DialogInstance } & DIALOGDATA;
export interface IDialogMatch<DIALOGRESPONSE extends object = any, DIALOGDATA extends object = any> extends IDialogRootMatch {
dialogData: IDialogData<DIALOGDATA>;
dialogStack: DialogInstance[];
replaceThisDialog<DIALOGARGS = any>(name: string, args?: DIALOGARGS, response?: DIALOGRESPONSE): Observableable<void>;
endThisDialog(response?: DIALOGRESPONSE): Observableable<void>;
}
export interface IDialogArgsMatch<DIALOGARGS extends object> {
dialogArgs: DIALOGARGS;
}
export interface IDialog<M extends Match = any, DIALOGARGS extends object = any, DIALOGRESPONSE extends object = any> {
invoke(name: string, match: M & IDialogMatch<DIALOGRESPONSE> & IDialogArgsMatch<DIALOGARGS>): Observable<string>;
tryMatch(dialogInstance: DialogInstance, match: M & IDialogMatch<DIALOGRESPONSE>): Observable<RuleResult>;
}
export interface RootDialogInstance<M extends Match = any> {
get: (match: M) => Observableable<DialogInstance>;
set: (match: M, rootDialogInstance?: DialogInstance) => Observableable<void>;
}
export interface IDialogResponderMatch<DIALOGRESPONSE extends object = object> {
dialogResponse: DIALOGRESPONSE;
}
export interface DialogResponder<M extends Match = any, DIALOGRESPONSE extends object = any> {
(match: M & IDialogMatch<DIALOGRESPONSE> & IDialogResponderMatch<DIALOGRESPONSE>): Observableable<void>;
}
export interface DialogResponders<M extends Match = any> {
[name: string]: DialogResponder<M>;
}
export interface LocalDialogInstances {
newInstance: <DIALOGDATA extends object = any>(name: string, dialogData: IDialogData<DIALOGDATA>) => Observableable<string>,
getDialogData: <DIALOGDATA extends object = any>(dialogInstance: DialogInstance) => Observableable<IDialogData<DIALOGDATA>>,
setDialogData: <DIALOGDATA extends object = any>(dialogInstance: DialogInstance, dialogData?: IDialogData<DIALOGDATA>) => Observableable<void>
}
// export interface RemoteDialogProxy {
// private matchRemoteDialog: (match: M & IDialogMatch) => any,
// private executeTasks: (response: tasks) => Observizeable<void>
// }
export class Dialogs<M extends Match = any> {
private dialogs: DialogRegistry<M> = {}
constructor(
private rules: DialogRules<M>,
private getDialogStack: (match: M) => string,
private setDialogStack: (match: M, promptKey?: string) => void
private rootDialogInstance: RootDialogInstance,
private localDialogInstances: LocalDialogInstances,
) {
super();
}
tryMatch(match: M): Observable<RuleResult> {
return Observable.of(this.getDialogStack(match))
.do(promptKey => konsole.log("promptKey", promptKey))
.filter(promptKey => promptKey !== undefined)
.map(promptKey => this.rules[promptKey])
.filter(rule => rule !== undefined)
.flatMap(rule =>
rule.tryMatch(match)
.map(ruleResult => ({
... ruleResult,
action: () => {
this.setDialogStack(match, undefined);
return ruleResult.action();
private invokeDialog<M extends Match = any, DIALOGARGS extends object = any>(match: M, name: string, args: DIALOGARGS) : Observable<DialogInstance> {
const dialog = this.dialogs[name];
if (!dialog)
throw new Error(`You attempted to begin a dialog named "${name}" but no dialog with that name exists.`);
return dialog.invoke(name, {
... match as any,
dialogArgs: args
})
.map(instance => ({ name, instance }));
}
runChildIfActive<ANYMATCH extends Match = M, DIALOGRESPONSE extends object = any>(name: string, responder?: DialogResponder<ANYMATCH, DIALOGRESPONSE>): IRule<ANYMATCH>;
runChildIfActive<ANYMATCH extends Match = M>(responders?: DialogResponders<ANYMATCH>): IRule<ANYMATCH>;
runChildIfActive<ANYMATCH extends Match = M>(... args: any[]): IRule<ANYMATCH> {
const dialogs = this.dialogs,
rootDialogInstance: RootDialogInstance<ANYMATCH> = this.rootDialogInstance;
return new class extends BaseRule<ANYMATCH & IDialogMatch> {
dialogResponders: DialogResponders<ANYMATCH>;
constructor(... args: any[]) {
super();
if (args.length === 1)
this.dialogResponders = typeof args[0] === "object"
? args[0]
: { [args[0]]: () => {} }
else if (args.length === 2)
this.dialogResponders = { [args[0]]: args[1] };
}
tryMatch(match: ANYMATCH & IDialogMatch): Observable<RuleResult> {
console.log("runIfActive.tryMatch", match);
let odi: Observable<DialogInstance>;
if (match.dialogStack) {
odi = Observable.of(match.dialogData.childDialogInstance);
} else {
// This is being run from a non-dialog rule
match = {
... match as any,
dialogStack: [],
}
}))
);
odi = toObservable(rootDialogInstance.get(match));
}
return odi
.filter(dialogInstance => !!dialogInstance)
.flatMap(dialogInstance => {
let dialogResponder: DialogResponder<ANYMATCH> = () => {};
if (this.dialogResponders) {
dialogResponder = this.dialogResponders[dialogInstance.name];
if (!dialogResponder)
return Observable.empty<RuleResult>();
}
const dialog = dialogs[dialogInstance.name];
if (!dialog) {
console.warn(`The stack references a dialog named "${dialogInstance.name}", which doesn't exist.`);
return Observable.empty<RuleResult>();
}
return dialog.tryMatch(dialogInstance, {
... match as any,
replaceThisDialog: <DIALOGARGS extends object = any, DIALOGRESPONSE extends object = any>(name: string, args?: DIALOGARGS, dialogResponse?: DIALOGRESPONSE) =>
toObservable(dialogResponder({
... match as any,
dialogResponse
}))
.flatMap(_ => toObservable(match.beginChildDialog(name, args))),
endThisDialog: <DIALOGRESPONSE extends object = any>(dialogResponse?: DIALOGRESPONSE) =>
toObservable(dialogResponder({
... match as any,
dialogResponse
}))
.flatMap(_ => toObservable(match.clearChildDialog()))
});
});
}
}(... args) as IRule<ANYMATCH>;
}
setPrompt(match, promptKey: string) {
this.setDialogStack(match, promptKey);
matchRootDialog(match: M): M & IDialogRootMatch {
return {
... match as any,
beginChildDialog: <DIALOGARGS extends object = any>(name: string, args?: DIALOGARGS) =>
this.invokeDialog(match, name, args)
.flatMap(dialogInstance => toObservable(this.rootDialogInstance.set(match, dialogInstance))),
clearChildDialog: () => this.rootDialogInstance.set(match)
}
}
addLocal<
DIALOGARGS extends object = any,
DIALOGRESPONSE extends object = any,
DIALOGDATA extends object = any
>(
name: string,
rule: IRule<M & IDialogMatch<DIALOGRESPONSE, DIALOGDATA>>,
init: (match: M & IDialogMatch<DIALOGRESPONSE> & IDialogArgsMatch<DIALOGARGS>) => Observableable<DIALOGDATA> = () => ({} as DIALOGDATA)
): IDialog<M, DIALOGARGS, DIALOGRESPONSE> {
if (this.dialogs[name]) {
console.warn(`You attempted to add a dialog named "${name}" but a dialog with that name already exists.`);
return;
}
this.dialogs[name] = {
invoke: (name: string, match: M & IDialogMatch<DIALOGRESPONSE> & IDialogArgsMatch<DIALOGARGS>) =>
toObservable(init(match))
.flatMap(dialogData => toObservable(this.localDialogInstances.newInstance(name, dialogData))),
tryMatch: (dialogInstance: DialogInstance, match: M & IDialogMatch<DIALOGRESPONSE>) =>
toObservable(this.localDialogInstances.getDialogData<DIALOGDATA>(dialogInstance))
.flatMap(dialogData =>
rule.tryMatch({
... match as any,
dialogData,
dialogStack: [... match.dialogStack, dialogInstance],
beginChildDialog: <DIALOGARGS extends object = any>(name: string, args?: DIALOGARGS) =>
this.invokeDialog(match, name, args)
.flatMap(dialogInstance => {
dialogData.childDialogInstance = dialogInstance;
return Observable.of({});
}),
clearChildDialog: () => dialogData.childDialogInstance = undefined,
})
.map(ruleResult => ({
... ruleResult,
action: () =>
toObservable(ruleResult.action())
.flatMap(_ => toObservable(this.localDialogInstances.setDialogData(dialogInstance, dialogData)))
}))
)
}
}
// addRemote<DIALOGARGS>(
// name: string,
// remoteUrl: string,
// remoteName: string
// ): IDialog<M, DIALOGARGS> {
// return {
// invoke: (name: string, match: M & IDialogMatch & IDialogArgsMatch<DIALOGARGS>) =>
// Observable.fromPromise(
// fetch(
// remoteUrl + "/invoke", {
// method: 'POST',
// body: {
// name,
// match // this needs to be transformed too!
// }
// }
// )
// .then(response => response.json())
// )
// .flatMap(json => {
// switch (json.status) {
// case 'success':
// return Observable.of(json.instance);
// case 'error':
// return Observable.throw(`RemoteDialog.invoke() returned error "${json.error}".`);
// default:
// return Observable.throw(`RemoteDialog.invoke() returned unexpected status "${json.status}".`);
// }
// }),
// tryMatch: (dialogInstance: DialogInstance, match: M & IDialogMatch) =>
// Observable.fromPromise(
// fetch(
// remoteUrl + "/tryMatch", {
// method: 'POST',
// body: {
// name,
// instance,
// match: this.matchRemoteDialog(match)
// }
// }
// )
// .then(response => response.json())
// )
// .flatMap(json => {
// switch (json.status) {
// case 'end':
// // end dialog, then fall through
// case 'result':
// return observize(this.handleSuccessfulResponse(json.ruleResult));
// case 'matchless':
// return Observable.empty<void>();
// case 'error':
// return Observable.throw(`RemoteDialog.tryMatch() returned error "${json.error}".`);
// default:
// return Observable.throw(`RemoteDialog.tryMatch() returned unexpected status "${json.status}".`);
// }
// })
// }
// }
}
import { Observable } from 'rxjs';
import { ITextMatch } from './Text';
import { konsole } from './Konsole';
import { IRule, RuleResult, BaseRule, SimpleRule, Matcher, Handler, Match, Observizeable, observize, ruleize } from './Rules';
import { IRule, RuleResult, BaseRule, SimpleRule, Matcher, Handler, Match, Observableable, toFilteredObservable, ruleize } from './Rules';
import 'isomorphic-fetch';

@@ -190,3 +190,3 @@

best<M extends ITextMatch = any>(luisRules: LuisRules<M>): IRule<M> {
best<M extends Match & ITextMatch = any>(luisRules: LuisRules<M>): IRule<M> {
return new BestMatchingLuisRule<M>(match => this.match(match), luisRules);

@@ -207,3 +207,3 @@ }

class BestMatchingLuisRule<M extends ITextMatch> extends BaseRule<M> {
class BestMatchingLuisRule<M extends Match & ITextMatch> extends BaseRule<M> {
constructor(

@@ -217,3 +217,3 @@ private matchModel: Matcher<M, M & { luisResponse: LuisResponse }>,

tryMatch(match: M): Observable<RuleResult> {
return observize(this.matchModel(match))
return toFilteredObservable(this.matchModel(match))
.flatMap(m =>

@@ -220,0 +220,0 @@ Observable.from(m.luisResponse.intents)

import { konsole } from './Konsole';
import { IRule, SimpleRule, Observizeable, RuleResult, BaseRule, Matcher, Handler, Match, observize, combineMatchers } from './Rules';
import { IRule, SimpleRule, Observableable, RuleResult, BaseRule, Matcher, Handler, Match, combineMatchers } from './Rules';
import { Observable } from 'rxjs';

@@ -50,3 +50,3 @@ import { ITextMatch } from './Text';

export class TextPrompts<M extends ITextMatch> extends Prompts<M> {
export class TextPrompts<M extends Match & ITextMatch> extends Prompts<M> {
matchChoice(choices: string[]): Matcher<M, M & IChatPromptChoiceMatch> {

@@ -53,0 +53,0 @@ return match =>

import { Observable } from 'rxjs';
import { konsole } from './Konsole';
import { ITextMatch } from './Text';
import { IRule, SimpleRule, Matcher, Handler, arrayize } from './Rules';
import { Match, IRule, SimpleRule, Matcher, Handler, arrayize } from './Rules';

@@ -10,3 +10,3 @@ export interface IRegExpMatch {

export const matchRegExp = <M extends ITextMatch = any>(intents: RegExp | RegExp[]): Matcher<M, M & IRegExpMatch> =>
export const matchRegExp = <M extends Match & ITextMatch = any>(intents: RegExp | RegExp[]): Matcher<M, M & IRegExpMatch> =>
(match) =>

@@ -26,3 +26,3 @@ Observable.from(arrayize(intents))

// Either call as re(intent, action) or re([intent, intent, ...], action)
export const re = <M extends ITextMatch = any>(intents: RegExp | RegExp[], handler: Handler<M & IRegExpMatch>) => {
export const re = <M extends Match & ITextMatch = any>(intents: RegExp | RegExp[], handler: Handler<M & IRegExpMatch>) => {
return new SimpleRule(

@@ -29,0 +29,0 @@ matchRegExp(intents),

import { konsole } from './Konsole';
import { Observable } from 'rxjs';
export type Observizeable<T> = T | Observable<T> | Promise<T>
export type Observableable<T> = T | Observable<T> | Promise<T>
export interface RuleResult {
score?: number,
action: () => Observizeable<any>
action: () => Observableable<any>
}

@@ -25,9 +25,9 @@

export type Matcher<A extends Match = any, Z extends Match = any> = (match: A) => Observizeable<Z>;
export type Matcher<A extends Match = any, Z extends Match = any> = (match: A) => Observableable<Z>;
export type Handler<Z extends Match = any> = (match: Z) => Observizeable<any>;
export type Handler<Z extends Match = any> = (match: Z) => Observableable<any>;
export const arrayize = <T>(stuff: T | T[]) => Array.isArray(stuff) ? stuff : [stuff];
export const observize = <T>(t: Observizeable<T>) => {
export const toFilteredObservable = <T>(t: Observableable<T>) => {
if (!t)

@@ -42,2 +42,10 @@ return Observable.empty<T>();

export const toObservable = <T>(t: Observableable<T>) => {
if (t instanceof Observable)
return t;
if (t instanceof Promise)
return Observable.fromPromise<T>(t);
return Observable.of(t);
}
export function isRule<M>(r: IRule<M> | Handler<M>): r is IRule<M> {

@@ -55,3 +63,3 @@ return ((r as any).tryMatch !== undefined);

// so we just need to catch the case where it is precisely true
return observize(matcher(match))
return toFilteredObservable(matcher(match))
.map(m => typeof(m) === 'boolean' ? match : m);

@@ -66,3 +74,3 @@ }

.do(result => konsole.log("handle: matched a rule", result))
.flatMap(result => observize(result.action()))
.flatMap(result => toObservable(result.action()))
.do(_ => konsole.log("handle: called action"));

@@ -189,3 +197,3 @@ }

tryMatch(match: M): Observable<RuleResult> {
return observize(this.handler(match))
return toFilteredObservable(this.handler(match))
.map(_ => null);

@@ -232,6 +240,6 @@ }

export interface Predicate<M extends Match = any> {
(match: M): Observizeable<boolean>;
(match: M): Observableable<boolean>;
}
export function rule<M extends Match = any>(handler: Handler<M> | IRule<M>)
export function rule<M extends Match = any>(handler: Handler<M> | IRule<M>): IRule<M>

@@ -268,4 +276,6 @@ export function rule<M extends Match = any>(p1: Predicate<M>, handler: Handler<M> | IRule<M>): IRule<M>

export const first = <M extends Match = any>(... rules: (IRule<M> | Handler<M>)[]) => new FirstMatchingRule(... rules) as IRule<M>;
export function first<M extends Match = any>(... rules: (IRule<M> | Handler<M>)[]): IRule<M> {
return new FirstMatchingRule(... rules);
}
export const run = <M extends Match = any>(handler: Handler<M>) => new RunRule<M>(handler) as IRule<M>;

@@ -1,4 +0,4 @@

export interface ChatState<BOT = undefined, USER = undefined, CHANNEL = undefined, CONVERSATION = undefined, USERINCONVERSATION = undefined> {
export interface ChatState<BOT = undefined, USERINCHANNEL = undefined, CHANNEL = undefined, CONVERSATION = undefined, USERINCONVERSATION = undefined> {
bot?: BOT;
user?: USER;
userInChannel?: USERINCHANNEL;
channel?: CHANNEL;

@@ -5,0 +5,0 @@ conversation?: CONVERSATION;

import { Observable } from 'rxjs';
import { ITextMatch } from './Text';
import { IRule, Handler } from './Rules';
import { IRule, Handler, Match } from './Rules';
import 'isomorphic-fetch';

@@ -40,5 +40,5 @@ export interface LuisIntent {

}>;
best<M extends ITextMatch = any>(luisRules: LuisRules<M>): IRule<M>;
best<M extends Match & ITextMatch = any>(luisRules: LuisRules<M>): IRule<M>;
static findEntity(entities: LuisEntity[], type: string): LuisEntity[];
static entityValues(entities: LuisEntity[], type: string): string[];
}

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

var _this = this;
return Rules_1.observize(this.matchModel(match))
return Rules_1.toFilteredObservable(this.matchModel(match))
.flatMap(function (m) {

@@ -185,0 +185,0 @@ return rxjs_1.Observable.from(m.luisResponse.intents)

@@ -21,3 +21,3 @@ import { IRule, RuleResult, BaseRule, Matcher, Handler, Match } from './Rules';

}
export declare class TextPrompts<M extends ITextMatch> extends Prompts<M> {
export declare class TextPrompts<M extends Match & ITextMatch> extends Prompts<M> {
matchChoice(choices: string[]): Matcher<M, M & IChatPromptChoiceMatch>;

@@ -24,0 +24,0 @@ matchConfirm(): Matcher<M & IChatPromptChoiceMatch, M & IChatPromptConfirmMatch>;

import { ITextMatch } from './Text';
import { IRule, Matcher, Handler } from './Rules';
import { Match, IRule, Matcher, Handler } from './Rules';
export interface IRegExpMatch {
groups: RegExpExecArray;
}
export declare const matchRegExp: <M extends ITextMatch = any>(intents: RegExp | RegExp[]) => Matcher<M, M & IRegExpMatch>;
export declare const re: <M extends ITextMatch = any>(intents: RegExp | RegExp[], handler: Handler<M & IRegExpMatch>) => IRule<M>;
export declare const matchRegExp: <M extends Match & ITextMatch = any>(intents: RegExp | RegExp[]) => Matcher<M, M & IRegExpMatch>;
export declare const re: <M extends Match & ITextMatch = any>(intents: RegExp | RegExp[], handler: Handler<M & IRegExpMatch>) => IRule<M>;
import { Observable } from 'rxjs';
export declare type Observizeable<T> = T | Observable<T> | Promise<T>;
export declare type Observableable<T> = T | Observable<T> | Promise<T>;
export interface RuleResult {
score?: number;
action: () => Observizeable<any>;
action: () => Observableable<any>;
}

@@ -15,6 +15,7 @@ export interface Match {

}
export declare type Matcher<A extends Match = any, Z extends Match = any> = (match: A) => Observizeable<Z>;
export declare type Handler<Z extends Match = any> = (match: Z) => Observizeable<any>;
export declare type Matcher<A extends Match = any, Z extends Match = any> = (match: A) => Observableable<Z>;
export declare type Handler<Z extends Match = any> = (match: Z) => Observableable<any>;
export declare const arrayize: <T>(stuff: T | T[]) => T[];
export declare const observize: <T>(t: Observizeable<T>) => Observable<T>;
export declare const toFilteredObservable: <T>(t: Observableable<T>) => Observable<T>;
export declare const toObservable: <T>(t: Observableable<T>) => Observable<T>;
export declare function isRule<M>(r: IRule<M> | Handler<M>): r is IRule<M>;

@@ -57,5 +58,5 @@ export declare const ruleize: <M extends Match = any>(r: IRule<M> | Handler<M>) => IRule<M>;

export interface Predicate<M extends Match = any> {
(match: M): Observizeable<boolean>;
(match: M): Observableable<boolean>;
}
export declare function rule<M extends Match = any>(handler: Handler<M> | IRule<M>): any;
export declare function rule<M extends Match = any>(handler: Handler<M> | IRule<M>): IRule<M>;
export declare function rule<M extends Match = any>(p1: Predicate<M>, handler: Handler<M> | IRule<M>): IRule<M>;

@@ -73,3 +74,3 @@ export declare function rule<M extends Match = any, Z extends Match = any>(m1: Matcher<M, Z>, handler: Handler<Z> | IRule<Z>): IRule<M>;

export declare function rule<M extends Match = any, N extends Match = any, O extends Match = any, Z extends Match = any>(m1: Matcher<M, N>, m2: Matcher<N, O>, m3: Matcher<O, Z>, handler: Handler<Z> | IRule<Z>): IRule<M>;
export declare const first: <M extends Match = any>(...rules: (IRule<M> | Handler<M>)[]) => IRule<M>;
export declare function first<M extends Match = any>(...rules: (IRule<M> | Handler<M>)[]): IRule<M>;
export declare const run: <M extends Match = any>(handler: Handler<M>) => IRule<M>;

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

exports.arrayize = function (stuff) { return Array.isArray(stuff) ? stuff : [stuff]; };
exports.observize = function (t) {
exports.toFilteredObservable = function (t) {
if (!t)

@@ -29,2 +29,9 @@ return rxjs_1.Observable.empty();

};
exports.toObservable = function (t) {
if (t instanceof rxjs_1.Observable)
return t;
if (t instanceof Promise)
return rxjs_1.Observable.fromPromise(t);
return rxjs_1.Observable.of(t);
};
function isRule(r) {

@@ -41,3 +48,3 @@ return (r.tryMatch !== undefined);

// so we just need to catch the case where it is precisely true
return exports.observize(matcher(match))
return exports.toFilteredObservable(matcher(match))
.map(function (m) { return typeof (m) === 'boolean' ? match : m; });

@@ -51,3 +58,3 @@ };

.do(function (result) { return Konsole_1.konsole.log("handle: matched a rule", result); })
.flatMap(function (result) { return exports.observize(result.action()); })
.flatMap(function (result) { return exports.toObservable(result.action()); })
.do(function (_) { return Konsole_1.konsole.log("handle: called action"); });

@@ -175,3 +182,3 @@ };

RunRule.prototype.tryMatch = function (match) {
return exports.observize(this.handler(match))
return exports.toFilteredObservable(this.handler(match))
.map(function (_) { return null; });

@@ -201,3 +208,3 @@ };

exports.rule = rule;
exports.first = function () {
function first() {
var rules = [];

@@ -208,4 +215,5 @@ for (var _i = 0; _i < arguments.length; _i++) {

return new (FirstMatchingRule.bind.apply(FirstMatchingRule, [void 0].concat(rules)))();
};
}
exports.first = first;
exports.run = function (handler) { return new RunRule(handler); };
//# sourceMappingURL=Rules.js.map

@@ -9,1 +9,2 @@ export * from './core/Rules';

export * from './core/Konsole';
export * from './core/Dialogs';

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

__export(require("./core/Konsole"));
__export(require("./core/Dialogs"));
//# sourceMappingURL=prague.js.map

@@ -7,3 +7,3 @@ {

},
"version": "0.6.5",
"version": "0.7.0",
"description": "rules-based app engine",

@@ -20,3 +20,4 @@ "main": "dist/prague.js",

"devDependencies": {
"typescript": "^2.3.2"
"@types/node": "^7.0.31",
"typescript": "^2.4.0-dev.20170610"
},

@@ -23,0 +24,0 @@ "dependencies": {

@@ -9,1 +9,2 @@ export * from './core/Rules';

export * from './core/Konsole';
export * from './core/Dialogs';

@@ -28,3 +28,4 @@ # Prague

* [prague-botframework-browserbot](https://www.npmjs.com/package/prague-botframework-browserbot) - Build
* [prague-botframework-browserbot](https://www.npmjs.com/package/prague-botframework-browserbot) - Build in-browser bots using the Bot Framework WebChat
* [prague-nodeconsole](https://www.npmjs.com/package/prague-nodeconsole) - Build Node console bots

@@ -34,6 +35,7 @@ ## Prague samples

* [BrowserBot](https://github.com/billba/BrowserBot)
* [NodeConsoleBot](https://github.com/billba/NodeConsoleBot)
# Prague 101
Let's write a simple bot:
Let's write a simple bot that replies the same way to all inputs:

@@ -44,5 +46,3 @@ ```typescript

```typescript
const rule = rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
```
Let's be a little more discriminating about when we say Hello, so we introduce a condition that must be satisfied before the action is taken:

@@ -53,2 +53,4 @@ ```typescript

We need a default reply for when the first rule is not satisfied. That means we have two rules, so we need a way to decide how to evaluate them. `first` tries a given input on each rule, in order, until one succeeds:
```typescript

@@ -61,5 +63,7 @@ const rule = first(

Now let's add a new rule that responds to a different pattern:
```typescript
const rule = first(
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
rule(matchRegExp(/I am (.*)/), reply("Nice to meet you!")),

@@ -70,2 +74,4 @@ reply("I don't understand you.")

`matchRegExp` isn't just a predicate. It also extracts out matching groups, which we can use to customize the reply:
```typescript

@@ -79,6 +85,8 @@ const rule = first(

Now let's add another rule which looks for specific names. We do this by adding another condition that must be satisfied before the action is taken:
```typescript
const rule = first(
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
rule(matchRegExp(/I am (.*)/), match => match.groups[1] === 'Bill', match => match.reply(`HELLO MY CREATOR`)),
rule(matchRegExp(/I am (.*)/), match => match.groups[1] === 'Bill', reply(`HELLO MY CREATOR`)),
rule(matchRegExp(/I am (.*)/), match => match.reply(`Nice to meet you, ${match.groups[1]}!`)),

@@ -89,2 +97,4 @@ reply("I don't understand you.")

This works, but if the name isn't "Bill" we'll end up calling `matchRegExp` twice. let's optimize this:
```typescript

@@ -94,4 +104,4 @@ const rule = first(

rule(matchRegExp(/I am (.*)/), first(
rule(match => match.groups[1] === 'Bill', match => match.reply(`HELLO MY CREATOR`)),
rule(match => match.reply(`Nice to meet you, ${match.groups[1]}!`))
rule(match => match.groups[1] === 'Bill', reply(`HELLO MY CREATOR`)),
match => match.reply(`Nice to meet you, ${match.groups[1]}!`)
)),

@@ -102,2 +112,4 @@ reply("I don't understand you.")

This is a simple example to give you a sense of how rules are created and composed in Prague.
## Asynchronous functions

@@ -107,8 +119,4 @@

## Applications and State
## Lots More Tutorial Needed
Now that you've been introduced to Rules, Matchers, and Handlers, the key helpers, and the type system, we can look into what it takes to build more complex apps using state.
## Prompts
Here I'll talk about Prompts.
I know, I know.

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