Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/model/src/intent-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const PAY_PAGE = { test: (t: string) => !QUESTION.test(t) && ((PAY_PAGE_VERB.tes
* answer sent, written, posted or drafted to someone is asked for: "send a reply to Ana", "post the answer to Ana". Only
* with "to": "did Ana send a reply?" stays a question.
*/
export const REPLY_COMMAND_WORDS = String.raw`dile a|dile que|d[ií]gale a|dec[ií]le|resp[oó]ndele|respondele|contesta(le)?|cont[eé]stale|contestale|av[ií]sale a|escr[ií]bele a|m[aá]ndale (un mensaje )?a \w+ (que|diciendo)|tell (?!me\b|us\b)\w+|text (?!me\b|us\b|messages?\b|back\b)\w+ \S+|let (?!me\b|us\b)\S+( \S+)? know|(?<!(?:a|an|any|the)\s)answer (?!me\b|us\b)\S+|send (?!me\b|us\b)\S+( \S+)? an? (message|text|msg)|(?<!(?:last|any|the)\s)msg \S+|m[aá]ndale (un )?(wasap|whatsapp|mensaje|msj) a \S+|(?<!(?:a|an|any|the)\s)reply to|(?:send|write|post|draft) (?:a|an|the) (?:reply|answer) to|write back|text (?!me\b|us\b)\w+ (back|that)|text my \w+ back|message (?!me\b|us\b)(the |my )?\S+( \S+){0,2} (that|saying)`;
export const REPLY_COMMAND_WORDS = String.raw`dile a|dile que|d[ií]gale a|dec[ií]le|resp[oó]ndele|respondele|contesta(le)?|cont[eé]stale|contestale|av[ií]sale a|escr[ií]bele a|m[aá]ndale (un mensaje )?a \w+ (que|diciendo)|tell (?!me\b|us\b)\w+|text (?!me\b|us\b|messages?\b|back\b)\w+ \S+|let (?!me\b|us\b)\S+( \S+)? know|(?<!(?:a|an|any|the)\s)answer (?!me\b|us\b)\S+|send (?!me\b|us\b)\S+( \S+)? an? (message|text|msg)|(?<!(?:last|any|the)\s)msg \S+|m[aá]ndale (un )?(wasap|whatsapp|mensaje|msj) a \S+|(?<!(?:a|an|any|the)\s)reply to|(?:send|write|post|draft|compose|type) (?:a|an|the) (?:reply|answer) to|write back|text (?!me\b|us\b)\w+ (back|that)|text my \w+ back|message (?!me\b|us\b)(the |my )?\S+( \S+){0,2} (that|saying)`;

const HINTS: readonly Hint[] = [
{ pattern: MAKE_BOT, skills: ["create_bot"], force: true, needs: "create_bot" },
Expand Down
24 changes: 23 additions & 1 deletion packages/model/test/intent-hints.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import { describe, expect, test, vi } from "vitest";
import { connectSkill, createBotDef, firstWinSkills, intentSkills, mailSkillDefs, payDef, payMerchantDef, webSkills } from "@hermit/skills";
import { EXAMPLE_BANK } from "../src/example-bank.ts";
import { narrowMenu, planIntents, routeIntent } from "../src/intent-hints.ts";
import { narrowMenu, planIntents, REPLY_COMMAND_WORDS, routeIntent } from "../src/intent-hints.ts";

const ids = (text: string) => narrowMenu(text, firstWinSkills).map((s) => s.id);

/** The same boundary rule the port uses to decide that the user asked for a reply (#110). */
const replyCommand = new RegExp(`(?<![\\p{L}\\p{N}])(?:${REPLY_COMMAND_WORDS})(?![\\p{L}\\p{N}])`, "iu");

describe("reply command verbs (#110)", () => {
test.each([
"compose a reply to Ana Prueba saying I'm late",
"type a reply to Carlos Demo: on my way",
"send a reply to Ana Prueba saying I'm late",
"write an answer to Carlos Demo: on my way",
])("a reply command: %s", (text) => {
expect(replyCommand.test(text)).toBe(true);
});

test.each([
"did Ana Prueba type a reply?",
"Carlos Demo is composing a reply",
"compose a reply for Ana Prueba",
])("not a reply command: %s", (text) => {
expect(replyCommand.test(text)).toBe(false);
});
});

describe("intent hints narrow the menu, never widen it", () => {
test.each([
["recuérdame comprar pan mañana a las 7", ["remind"]],
Expand Down
Loading