@pinecall/dot 0.11.24 → 0.11.26
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/README.md +135 -59
- package/dist/agent/index.d.ts +3 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/tutor.d.ts +8 -10
- package/dist/agent/tutor.d.ts.map +1 -1
- package/dist/agent/tutor.js +71 -74
- package/dist/agent/tutor.js.map +1 -1
- package/dist/agent/walks.d.ts +19 -0
- package/dist/agent/walks.d.ts.map +1 -0
- package/dist/agent/walks.js +89 -0
- package/dist/agent/walks.js.map +1 -0
- package/dist/page/page.d.ts +2 -2
- package/dist/page/page.d.ts.map +1 -1
- package/dist/page/page.js +5 -5
- package/dist/page/page.js.map +1 -1
- package/dist/page/roles.d.ts +2 -0
- package/dist/page/roles.d.ts.map +1 -1
- package/dist/page/roles.js +21 -2
- package/dist/page/roles.js.map +1 -1
- package/dist/pointer/asking.d.ts +25 -0
- package/dist/pointer/asking.d.ts.map +1 -0
- package/dist/pointer/asking.js +82 -0
- package/dist/pointer/asking.js.map +1 -0
- package/dist/pointer/flight.d.ts +28 -0
- package/dist/pointer/flight.d.ts.map +1 -1
- package/dist/pointer/flight.js +93 -7
- package/dist/pointer/flight.js.map +1 -1
- package/dist/pointer/frames.d.ts +28 -0
- package/dist/pointer/frames.d.ts.map +1 -0
- package/dist/pointer/frames.js +66 -0
- package/dist/pointer/frames.js.map +1 -0
- package/dist/pointer/icons.d.ts +8 -0
- package/dist/pointer/icons.d.ts.map +1 -0
- package/dist/pointer/icons.js +15 -0
- package/dist/pointer/icons.js.map +1 -0
- package/dist/pointer/menu.d.ts +3 -0
- package/dist/pointer/menu.d.ts.map +1 -1
- package/dist/pointer/menu.js +26 -6
- package/dist/pointer/menu.js.map +1 -1
- package/dist/pointer/person.d.ts +13 -2
- package/dist/pointer/person.d.ts.map +1 -1
- package/dist/pointer/person.js +47 -41
- package/dist/pointer/person.js.map +1 -1
- package/dist/pointer/pressing.d.ts +6 -0
- package/dist/pointer/pressing.d.ts.map +1 -0
- package/dist/pointer/pressing.js +32 -0
- package/dist/pointer/pressing.js.map +1 -0
- package/dist/pointer/typing.d.ts +5 -3
- package/dist/pointer/typing.d.ts.map +1 -1
- package/dist/pointer/typing.js +46 -15
- package/dist/pointer/typing.js.map +1 -1
- package/dist/server/index.d.ts +34 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +108 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/questions.d.ts +30 -0
- package/dist/server/questions.d.ts.map +1 -0
- package/dist/server/questions.js +136 -0
- package/dist/server/questions.js.map +1 -0
- package/dist/server/saying.d.ts +31 -0
- package/dist/server/saying.d.ts.map +1 -0
- package/dist/server/saying.js +124 -0
- package/dist/server/saying.js.map +1 -0
- package/dist/tutor/acting.d.ts +42 -0
- package/dist/tutor/acting.d.ts.map +1 -0
- package/dist/tutor/acting.js +180 -0
- package/dist/tutor/acting.js.map +1 -0
- package/dist/tutor/aloud.d.ts +50 -0
- package/dist/tutor/aloud.d.ts.map +1 -0
- package/dist/tutor/aloud.js +288 -0
- package/dist/tutor/aloud.js.map +1 -0
- package/dist/tutor/ask.d.ts +49 -0
- package/dist/tutor/ask.d.ts.map +1 -0
- package/dist/tutor/ask.js +47 -0
- package/dist/tutor/ask.js.map +1 -0
- package/dist/tutor/listening.d.ts +17 -0
- package/dist/tutor/listening.d.ts.map +1 -0
- package/dist/tutor/listening.js +66 -0
- package/dist/tutor/listening.js.map +1 -0
- package/dist/tutor/options.d.ts +37 -1
- package/dist/tutor/options.d.ts.map +1 -1
- package/dist/tutor/options.js +1 -1
- package/dist/tutor/options.js.map +1 -1
- package/dist/tutor/reading.d.ts +58 -0
- package/dist/tutor/reading.d.ts.map +1 -0
- package/dist/tutor/reading.js +193 -0
- package/dist/tutor/reading.js.map +1 -0
- package/dist/tutor/text.d.ts +16 -0
- package/dist/tutor/text.d.ts.map +1 -0
- package/dist/tutor/text.js +119 -0
- package/dist/tutor/text.js.map +1 -0
- package/dist/tutor/tutor.d.ts +2 -9
- package/dist/tutor/tutor.d.ts.map +1 -1
- package/dist/tutor/tutor.js +109 -87
- package/dist/tutor/tutor.js.map +1 -1
- package/dist/tutor/walking.d.ts +20 -6
- package/dist/tutor/walking.d.ts.map +1 -1
- package/dist/tutor/walking.js +125 -25
- package/dist/tutor/walking.js.map +1 -1
- package/dist/tutor/walks.d.ts +33 -0
- package/dist/tutor/walks.d.ts.map +1 -1
- package/dist/tutor/walks.js +116 -10
- package/dist/tutor/walks.js.map +1 -1
- package/dist/wire/acts.d.ts +60 -0
- package/dist/wire/acts.d.ts.map +1 -0
- package/dist/wire/acts.js +120 -0
- package/dist/wire/acts.js.map +1 -0
- package/dist/wire/ask.d.ts +132 -0
- package/dist/wire/ask.d.ts.map +1 -0
- package/dist/wire/ask.js +102 -0
- package/dist/wire/ask.js.map +1 -0
- package/dist/wire/index.d.ts +26 -8
- package/dist/wire/index.d.ts.map +1 -1
- package/dist/wire/index.js +62 -11
- package/dist/wire/index.js.map +1 -1
- package/docs/macros.md +53 -3
- package/docs/write-a-tutor.md +26 -2
- package/package.json +8 -4
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** A macro as a function: the params it takes, the steps that act on the page (fill, press, wait, read), and the `{slots}` its words are filled from. */
|
|
2
|
+
//
|
|
3
|
+
// A walk that takes params is called with them: in a call the agent's model passes them, with no call
|
|
4
|
+
// the site's server picks them out of what the visitor typed (`@pinecall/dot/server`). A param is the
|
|
5
|
+
// visitor's own words (a name, a phone, what to search for) or one option of a list. Its value fills
|
|
6
|
+
// the `{name}` slots of the walk's sentences and of what a step types, and `read` adds the cells of a
|
|
7
|
+
// row of a table the page shows (`{hit.Time}`). A step with a slot nothing filled is left out, so a
|
|
8
|
+
// walk said without a param says the rest; `if` and `unless` keep a step for a value there, or not.
|
|
9
|
+
/** The longest a wait may be, in ms. */
|
|
10
|
+
export const LONGEST_WAIT = 20_000;
|
|
11
|
+
/** The longest a value may be: a name, a phone, a cell. */
|
|
12
|
+
export const LONGEST_VALUE = 80;
|
|
13
|
+
const SLOT = /\{([A-Za-z_][\w]*(?:\.[^{}\n]+)?)\}/g;
|
|
14
|
+
/** The slots a text names, in order: `{name}`, `{hit.Time}`. */
|
|
15
|
+
export function slotsOf(text) {
|
|
16
|
+
return [...text.matchAll(SLOT)].map((found) => found[1] ?? "");
|
|
17
|
+
}
|
|
18
|
+
/** `text` with its slots filled; null when one has no value. */
|
|
19
|
+
export function filled(text, values) {
|
|
20
|
+
let missing = false;
|
|
21
|
+
const out = text.replace(SLOT, (_, slot) => {
|
|
22
|
+
const value = values[slot];
|
|
23
|
+
if (value === undefined || value === "")
|
|
24
|
+
missing = true;
|
|
25
|
+
return value ?? "";
|
|
26
|
+
});
|
|
27
|
+
return missing ? null : out;
|
|
28
|
+
}
|
|
29
|
+
/** Whether a step is taken, with these values. */
|
|
30
|
+
export function taken(step, values) {
|
|
31
|
+
const has = (slot) => (values[slot] ?? "") !== "";
|
|
32
|
+
return (step.if === undefined || has(step.if)) && (step.unless === undefined || !has(step.unless));
|
|
33
|
+
}
|
|
34
|
+
/** A value as it may fill a slot: one line, cut. */
|
|
35
|
+
export function valueOf(text) {
|
|
36
|
+
return text.replace(/\s+/g, " ").trim().slice(0, LONGEST_VALUE);
|
|
37
|
+
}
|
|
38
|
+
/** Whether a step is an act rather than a sentence. */
|
|
39
|
+
export function isAct(step) {
|
|
40
|
+
return "fill" in step || "press" in step || "wait" in step || "read" in step;
|
|
41
|
+
}
|
|
42
|
+
const text = (value) => typeof value === "string" && value.trim() !== "";
|
|
43
|
+
/** An act as a file or a document says it, checked; null for one that is not. */
|
|
44
|
+
export function actOf(fields) {
|
|
45
|
+
if ("fill" in fields)
|
|
46
|
+
return text(fields["fill"]) && text(fields["with"]) ? { fill: fields["fill"], with: fields["with"] } : null;
|
|
47
|
+
if ("press" in fields)
|
|
48
|
+
return text(fields["press"]) && slotsOf(fields["press"]).length === 0 ? { press: fields["press"] } : null;
|
|
49
|
+
if ("wait" in fields) {
|
|
50
|
+
const ms = fields["ms"];
|
|
51
|
+
if (!text(fields["wait"]) || (ms !== undefined && (typeof ms !== "number" || ms <= 0 || ms > LONGEST_WAIT)))
|
|
52
|
+
return null;
|
|
53
|
+
return { wait: fields["wait"], ...(ms === undefined ? {} : { ms }) };
|
|
54
|
+
}
|
|
55
|
+
if ("read" in fields) {
|
|
56
|
+
const row = fields["row"];
|
|
57
|
+
if (!text(fields["read"]) || !text(fields["as"]) || !/^[A-Za-z_]\w*$/.test(fields["as"]))
|
|
58
|
+
return null;
|
|
59
|
+
if (row !== undefined && row !== "first" && row !== "best")
|
|
60
|
+
return null;
|
|
61
|
+
return { read: fields["read"], as: fields["as"], ...(row === undefined ? {} : { row }) };
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** A step's guards, checked; null when one is not a slot's name. */
|
|
66
|
+
export function guardsOf(fields) {
|
|
67
|
+
const guards = {};
|
|
68
|
+
for (const key of ["if", "unless"]) {
|
|
69
|
+
const slot = fields[key];
|
|
70
|
+
if (slot === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
if (typeof slot !== "string" || slot === "")
|
|
73
|
+
return null;
|
|
74
|
+
guards[key] = slot;
|
|
75
|
+
}
|
|
76
|
+
return guards;
|
|
77
|
+
}
|
|
78
|
+
/** A walk's params, as its file or document says them (`one_of` for the options), checked; null for any that is not one. */
|
|
79
|
+
export function paramsOf(value) {
|
|
80
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
81
|
+
return null;
|
|
82
|
+
const params = {};
|
|
83
|
+
for (const [name, declared] of Object.entries(value)) {
|
|
84
|
+
if (!/^[A-Za-z_]\w*$/.test(name) || typeof declared !== "object" || declared === null)
|
|
85
|
+
return null;
|
|
86
|
+
const fields = { ...declared };
|
|
87
|
+
const about = fields["about"];
|
|
88
|
+
const options = fields["one_of"] ?? fields["oneOf"];
|
|
89
|
+
if (!text(about))
|
|
90
|
+
return null;
|
|
91
|
+
if (options === undefined) {
|
|
92
|
+
params[name] = { about };
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (typeof options !== "object" || options === null || Array.isArray(options))
|
|
96
|
+
return null;
|
|
97
|
+
const entries = Object.entries(options);
|
|
98
|
+
if (entries.length === 0 || !entries.every(([, said]) => typeof said === "string"))
|
|
99
|
+
return null;
|
|
100
|
+
params[name] = { about, oneOf: Object.fromEntries(entries) };
|
|
101
|
+
}
|
|
102
|
+
return params;
|
|
103
|
+
}
|
|
104
|
+
/** The values a walk is called with, checked against its params: a list's value one of its options, the rest the visitor's words, cut. */
|
|
105
|
+
export function valuesFor(params, given) {
|
|
106
|
+
const values = {};
|
|
107
|
+
const wrong = [];
|
|
108
|
+
for (const [name, value] of Object.entries(given)) {
|
|
109
|
+
const param = params[name];
|
|
110
|
+
if (param === undefined || typeof value !== "string" || value.trim() === "")
|
|
111
|
+
continue;
|
|
112
|
+
if (param.oneOf !== undefined && !(value in param.oneOf)) {
|
|
113
|
+
wrong.push(`${name} is one of ${Object.keys(param.oneOf).join(", ")}`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
values[name] = valueOf(value);
|
|
117
|
+
}
|
|
118
|
+
return { values, wrong };
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=acts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acts.js","sourceRoot":"","sources":["../../src/wire/acts.ts"],"names":[],"mappings":"AAAA,yJAAyJ;AACzJ,EAAE;AACF,sGAAsG;AACtG,sGAAsG;AACtG,qGAAqG;AACrG,sGAAsG;AACtG,oGAAoG;AACpG,oGAAoG;AA2CpG,wCAAwC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AACnC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;A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,IAAI,CAAC,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC;QAChG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAA2B,EAAE,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0IAA0I;AAC1I,MAAM,UAAU,SAAS,CAAC,MAA6B,EAAE,KAA8B;IACrF,MAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,SAAS;QACtF,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,cAAc,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvE,SAAS;QACX,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** What the dot asks when the visitor types to it, and the one thing it may be told to do: a walk, a thing shown, the agent, or nothing. */
|
|
2
|
+
import { type Values } from "./acts.js";
|
|
3
|
+
/** What the visitor typed, and the page it was typed on, as the dot sends it to be decided. */
|
|
4
|
+
export interface AskRequest {
|
|
5
|
+
message: string;
|
|
6
|
+
/** The path of the page: `/pricing`. */
|
|
7
|
+
path: string;
|
|
8
|
+
/** The page as the agent reads it: each thing with its role, its name and its ref. */
|
|
9
|
+
page: string;
|
|
10
|
+
/** The walks of this page, and what each takes. */
|
|
11
|
+
walks: {
|
|
12
|
+
name: string;
|
|
13
|
+
title: string;
|
|
14
|
+
when?: string | undefined;
|
|
15
|
+
params?: Record<string, {
|
|
16
|
+
about: string;
|
|
17
|
+
oneOf?: Record<string, string> | undefined;
|
|
18
|
+
}> | undefined;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
/** Which row of a table a walk read best answers what the visitor typed: each row as its cells, joined. */
|
|
22
|
+
export interface RowRequest {
|
|
23
|
+
message: string;
|
|
24
|
+
rows: string[];
|
|
25
|
+
}
|
|
26
|
+
/** A sentence of a walk with slots, to record now its values are known: the page it is on, the walk, the step, the values. */
|
|
27
|
+
export interface SayRequest {
|
|
28
|
+
path: string;
|
|
29
|
+
walk: string;
|
|
30
|
+
step: number;
|
|
31
|
+
values: Values;
|
|
32
|
+
}
|
|
33
|
+
/** A text of the page itself to record in the agent's voice: a part of a page read aloud. */
|
|
34
|
+
export interface ReadRequest {
|
|
35
|
+
text: string;
|
|
36
|
+
}
|
|
37
|
+
/** A command's output a page shows, for the agent's model to explain: notes, each on a line of it. */
|
|
38
|
+
export interface ExplainRequest {
|
|
39
|
+
output: string;
|
|
40
|
+
command?: string | undefined;
|
|
41
|
+
language?: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** One turn of a chat the dot talks to, as it was heard: whose, and what was said. */
|
|
44
|
+
export interface Heard {
|
|
45
|
+
who: "agent" | "caller";
|
|
46
|
+
said: string;
|
|
47
|
+
}
|
|
48
|
+
/** The dot's next line on a chat it talks to for a goal: the goal, what was said so far, the language. */
|
|
49
|
+
export interface NextRequest {
|
|
50
|
+
goal: string;
|
|
51
|
+
heard: Heard[];
|
|
52
|
+
language?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The dot's next line, and whether it says goodbye with it. */
|
|
55
|
+
export interface NextLine {
|
|
56
|
+
say: string;
|
|
57
|
+
hangup: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The most turns a talk sends as heard: the gateway's own ceiling. */
|
|
60
|
+
export declare const MOST_HEARD = 80;
|
|
61
|
+
/** A note of an output: a fragment of one of its lines, and what is said of it. */
|
|
62
|
+
export interface Note {
|
|
63
|
+
find: string;
|
|
64
|
+
say: string;
|
|
65
|
+
}
|
|
66
|
+
/** What the page asks the site's door: one of the five. */
|
|
67
|
+
export type DoorRequest = {
|
|
68
|
+
decide: AskRequest;
|
|
69
|
+
} | {
|
|
70
|
+
row: RowRequest;
|
|
71
|
+
} | {
|
|
72
|
+
say: SayRequest;
|
|
73
|
+
} | {
|
|
74
|
+
read: ReadRequest;
|
|
75
|
+
} | {
|
|
76
|
+
explain: ExplainRequest;
|
|
77
|
+
} | {
|
|
78
|
+
next: NextRequest;
|
|
79
|
+
};
|
|
80
|
+
/** The site's door's answer to a `row`: the row's index, or null when none answers it. */
|
|
81
|
+
export interface RowAnswer {
|
|
82
|
+
row: number | null;
|
|
83
|
+
}
|
|
84
|
+
/** The door's answer to a `say`: the sentence as recorded. */
|
|
85
|
+
export interface SaidAnswer {
|
|
86
|
+
say: string;
|
|
87
|
+
audio: string;
|
|
88
|
+
durationMs: number;
|
|
89
|
+
words: {
|
|
90
|
+
text: string;
|
|
91
|
+
startMs: number;
|
|
92
|
+
endMs: number;
|
|
93
|
+
}[];
|
|
94
|
+
}
|
|
95
|
+
/** The one thing to do, and how sure the decision is, 0 to 1. */
|
|
96
|
+
export type Decision = {
|
|
97
|
+
do: "walk";
|
|
98
|
+
walk: string;
|
|
99
|
+
params?: Values | undefined;
|
|
100
|
+
confidence: number;
|
|
101
|
+
} | {
|
|
102
|
+
do: "show";
|
|
103
|
+
target: string;
|
|
104
|
+
confidence: number;
|
|
105
|
+
} | {
|
|
106
|
+
do: "talk";
|
|
107
|
+
confidence: number;
|
|
108
|
+
} | {
|
|
109
|
+
do: "none";
|
|
110
|
+
confidence: number;
|
|
111
|
+
};
|
|
112
|
+
/** A thing of the page with a name: its ref, its role and its name. */
|
|
113
|
+
export interface Named {
|
|
114
|
+
ref: string;
|
|
115
|
+
role: string;
|
|
116
|
+
name: string;
|
|
117
|
+
}
|
|
118
|
+
/** The things of a page with a name and a ref, in the page's order. */
|
|
119
|
+
export declare function namedIn(page: string): Named[];
|
|
120
|
+
/** A decision as a server answered it, checked; null for anything else. */
|
|
121
|
+
export declare function decisionOf(value: unknown): Decision | null;
|
|
122
|
+
/** The most notes an output is explained with. */
|
|
123
|
+
export declare const MOST_NOTES = 6;
|
|
124
|
+
/** An explanation's notes, checked, the first six; none for anything else. */
|
|
125
|
+
/** The door's answer to `{ next }` read as the dot's next line; null when it gave none. */
|
|
126
|
+
export declare function nextOf(value: unknown): NextLine | null;
|
|
127
|
+
export declare function notesOf(value: unknown): Note[];
|
|
128
|
+
/** A row answer, checked; null for anything else. */
|
|
129
|
+
export declare function rowOf(value: unknown): number | null;
|
|
130
|
+
/** A recorded sentence, checked; null for anything else. */
|
|
131
|
+
export declare function saidOf(value: unknown): SaidAnswer | null;
|
|
132
|
+
//# sourceMappingURL=ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/wire/ask.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAS5I,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAEvD,+FAA+F;AAC/F,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAA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AK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CAK7C;AAID,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAuB1D;AAED,kDAAkD;AAClD,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,8EAA8E;AAC9E,2FAA2F;AAC3F,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAItD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,CAY9C;AAED,qDAAqD;AACrD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAInD;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAWxD"}
|
package/dist/wire/ask.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** What the dot asks when the visitor types to it, and the one thing it may be told to do: a walk, a thing shown, the agent, or nothing. */
|
|
2
|
+
//
|
|
3
|
+
// The visitor types "where do I see what each plan includes?" and the dot does something on the page,
|
|
4
|
+
// never a conversation: it plays one of the page's walks, shows one thing of the page, offers the agent
|
|
5
|
+
// for a question a person answers, or says it cannot find it. What decides is a server's (`@pinecall/dot/server`);
|
|
6
|
+
// this is what the two say to each other. A walk that takes params is told them, picked out of what was typed.
|
|
7
|
+
// The same door picks the row of a table a walk read that best answers the visitor, and records a sentence
|
|
8
|
+
// of a walk once its slots are filled: one door, three asks, told apart by their one key.
|
|
9
|
+
import { LONGEST_VALUE } from "./acts.js";
|
|
10
|
+
/** The most turns a talk sends as heard: the gateway's own ceiling. */
|
|
11
|
+
export const MOST_HEARD = 80;
|
|
12
|
+
// A line of the page as Page writes it: ` - heading "Pricing" [level=2] [ref=e10]`. A name's own quotes are
|
|
13
|
+
// written as apostrophes, so the first closing quote ends it.
|
|
14
|
+
const A_THING = /^\s*- ([a-z]+) "([^"]*)".*?\[ref=(e\d+)\]/;
|
|
15
|
+
/** The things of a page with a name and a ref, in the page's order. */
|
|
16
|
+
export function namedIn(page) {
|
|
17
|
+
return page.split("\n").flatMap((line) => {
|
|
18
|
+
const found = A_THING.exec(line);
|
|
19
|
+
return found === null || found[2] === undefined || found[2].trim() === "" ? [] : [{ role: found[1] ?? "", name: found[2], ref: found[3] ?? "" }];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
23
|
+
/** A decision as a server answered it, checked; null for anything else. */
|
|
24
|
+
export function decisionOf(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null)
|
|
26
|
+
return null;
|
|
27
|
+
const fields = { ...value };
|
|
28
|
+
const confidence = fields["confidence"];
|
|
29
|
+
if (!isNumber(confidence))
|
|
30
|
+
return null;
|
|
31
|
+
switch (fields["do"]) {
|
|
32
|
+
case "walk": {
|
|
33
|
+
if (typeof fields["walk"] !== "string")
|
|
34
|
+
return null;
|
|
35
|
+
const given = fields["params"];
|
|
36
|
+
if (given === undefined)
|
|
37
|
+
return { do: "walk", walk: fields["walk"], confidence };
|
|
38
|
+
if (typeof given !== "object" || given === null)
|
|
39
|
+
return null;
|
|
40
|
+
const params = Object.fromEntries(Object.entries(given).filter((entry) => typeof entry[1] === "string" && entry[1].length <= LONGEST_VALUE));
|
|
41
|
+
return { do: "walk", walk: fields["walk"], params, confidence };
|
|
42
|
+
}
|
|
43
|
+
case "show":
|
|
44
|
+
return typeof fields["target"] === "string" && /^e\d+$/.test(fields["target"]) ? { do: "show", target: fields["target"], confidence } : null;
|
|
45
|
+
case "talk":
|
|
46
|
+
return { do: "talk", confidence };
|
|
47
|
+
case "none":
|
|
48
|
+
return { do: "none", confidence };
|
|
49
|
+
default:
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The most notes an output is explained with. */
|
|
54
|
+
export const MOST_NOTES = 6;
|
|
55
|
+
/** An explanation's notes, checked, the first six; none for anything else. */
|
|
56
|
+
/** The door's answer to `{ next }` read as the dot's next line; null when it gave none. */
|
|
57
|
+
export function nextOf(value) {
|
|
58
|
+
if (typeof value !== "object" || value === null)
|
|
59
|
+
return null;
|
|
60
|
+
const { say, hangup } = value;
|
|
61
|
+
return typeof say === "string" && say.trim() !== "" ? { say: say.trim(), hangup: hangup === true } : null;
|
|
62
|
+
}
|
|
63
|
+
export function notesOf(value) {
|
|
64
|
+
if (typeof value !== "object" || value === null)
|
|
65
|
+
return [];
|
|
66
|
+
const notes = value["notes"];
|
|
67
|
+
if (!Array.isArray(notes))
|
|
68
|
+
return [];
|
|
69
|
+
return notes
|
|
70
|
+
.flatMap((note) => {
|
|
71
|
+
if (typeof note !== "object" || note === null)
|
|
72
|
+
return [];
|
|
73
|
+
const fields = { ...note };
|
|
74
|
+
const { find, say } = fields;
|
|
75
|
+
return typeof find === "string" && find.trim() !== "" && typeof say === "string" && say.trim() !== "" ? [{ find, say }] : [];
|
|
76
|
+
})
|
|
77
|
+
.slice(0, MOST_NOTES);
|
|
78
|
+
}
|
|
79
|
+
/** A row answer, checked; null for anything else. */
|
|
80
|
+
export function rowOf(value) {
|
|
81
|
+
if (typeof value !== "object" || value === null)
|
|
82
|
+
return null;
|
|
83
|
+
const row = value["row"];
|
|
84
|
+
return typeof row === "number" && Number.isInteger(row) && row >= 0 ? row : null;
|
|
85
|
+
}
|
|
86
|
+
/** A recorded sentence, checked; null for anything else. */
|
|
87
|
+
export function saidOf(value) {
|
|
88
|
+
if (typeof value !== "object" || value === null)
|
|
89
|
+
return null;
|
|
90
|
+
const said = { ...value };
|
|
91
|
+
const { say, audio, durationMs, words } = said;
|
|
92
|
+
if (typeof say !== "string" || typeof audio !== "string" || !/^https?:\/\//.test(audio) || typeof durationMs !== "number" || !Array.isArray(words))
|
|
93
|
+
return null;
|
|
94
|
+
const timed = words.filter((word) => {
|
|
95
|
+
if (typeof word !== "object" || word === null)
|
|
96
|
+
return false;
|
|
97
|
+
const one = { ...word };
|
|
98
|
+
return typeof one["text"] === "string" && typeof one["startMs"] === "number" && typeof one["endMs"] === "number";
|
|
99
|
+
});
|
|
100
|
+
return timed.length === words.length ? { say, audio, durationMs, words: timed } : null;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=ask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.js","sourceRoot":"","sources":["../../src/wire/ask.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAC5I,EAAE;AACF,sGAAsG;AACtG,wGAAwG;AACxG,mHAAmH;AACnH,+GAA+G;AAC/G,2GAA2G;AAC3G,0FAA0F;AAE1F,OAAO,EAAE,aAAa,EAAe,MAAM,WAAW,CAAC;AA0DvD,uEAAuE;AACvE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAsC7B,6GAA6G;AAC7G,8DAA8D;AAC9D,MAAM,OAAO,GAAG,2CAA2C,CAAC;AAE5D,uEAAuE;AACvE,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACvC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,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MAAM,IAAI,GAA4B,EAAE,GAAG,KAAK,EAAE,CAAC;IACnD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC/C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAChK,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAuC,EAAE;QACvE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QAC5D,MAAM,GAAG,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAC;QACjD,OAAO,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;IACnH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzF,CAAC"}
|
package/dist/wire/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** What a tutored page and its agent say to each other: the page's events, and the cursor and macro messages it takes. */
|
|
2
|
+
import { type Act, type Guarded, type Param } from "./acts.js";
|
|
3
|
+
export * from "./acts.js";
|
|
2
4
|
/** The topic the agent sends on, and the page's `onUi` hears. */
|
|
3
5
|
export declare const UI = "pinecall.ui";
|
|
4
6
|
/**
|
|
@@ -20,10 +22,11 @@ export declare const WALKED = "page.walked";
|
|
|
20
22
|
/** The name the agent publishes its recorded walks under, which the page reads with no key. */
|
|
21
23
|
export declare const WALKS = "walks";
|
|
22
24
|
/**
|
|
23
|
-
* What the pointer can do. `type` fills a field with what the visitor said
|
|
24
|
-
*
|
|
25
|
+
* What the pointer can do. `type` fills a field with what the visitor said, and never touches a password
|
|
26
|
+
* or a card. `press` presses a button a walk names, one outside any form or in a search form: never a
|
|
27
|
+
* form that sends the visitor's details, and never a page left. `wait` waits for the page to change.
|
|
25
28
|
*/
|
|
26
|
-
export declare const ACTIONS: readonly ["point", "highlight", "unhighlight", "scroll_to", "here", "home", "type"];
|
|
29
|
+
export declare const ACTIONS: readonly ["point", "highlight", "unhighlight", "scroll_to", "here", "home", "type", "press", "wait"];
|
|
27
30
|
export type Action = (typeof ACTIONS)[number];
|
|
28
31
|
/** What the site wrote for the agent to say about one element, and the move it is said with. */
|
|
29
32
|
export interface Line {
|
|
@@ -39,6 +42,8 @@ export interface Cursor {
|
|
|
39
42
|
target?: string | undefined;
|
|
40
43
|
/** What `type` writes in the field: its text, or the option of a list to choose. */
|
|
41
44
|
text?: string | undefined;
|
|
45
|
+
/** How long `wait` waits at most, in ms. */
|
|
46
|
+
ms?: number | undefined;
|
|
42
47
|
}
|
|
43
48
|
/** A target that is a ref of the snapshot rather than a name. */
|
|
44
49
|
export declare const A_REF: RegExp;
|
|
@@ -60,11 +65,13 @@ export interface Shown {
|
|
|
60
65
|
code?: CodeView | null | undefined;
|
|
61
66
|
lines?: [from: number, to: number] | undefined;
|
|
62
67
|
}
|
|
63
|
-
/** One sentence of a macro and the moves hung on its words. */
|
|
64
|
-
export interface MacroStep extends Shown {
|
|
68
|
+
/** One sentence of a macro and the moves hung on its words; its `{slots}` filled when it is said. */
|
|
69
|
+
export interface MacroStep extends Shown, Guarded {
|
|
65
70
|
say: string;
|
|
66
71
|
beats: Beat[];
|
|
67
72
|
}
|
|
73
|
+
/** A step of a macro that acts on the page instead of saying a sentence. */
|
|
74
|
+
export type ActStep = Act & Guarded;
|
|
68
75
|
/** A guided walk an agent was given: `macros/<name>.json` in its folder. */
|
|
69
76
|
export interface Macro {
|
|
70
77
|
name: string;
|
|
@@ -74,7 +81,9 @@ export interface Macro {
|
|
|
74
81
|
when?: string | undefined;
|
|
75
82
|
/** The paths of the pages it is for: `["/security"]`. Left out, it is for every page. */
|
|
76
83
|
pages?: string[] | undefined;
|
|
77
|
-
|
|
84
|
+
/** What it is called with, by name. */
|
|
85
|
+
params?: Record<string, Param> | undefined;
|
|
86
|
+
steps: (MacroStep | ActStep)[];
|
|
78
87
|
}
|
|
79
88
|
/**
|
|
80
89
|
* The name of the document the walks of a page are published under: `walks` for the home, `walks-security`
|
|
@@ -91,13 +100,20 @@ export interface TimedWord {
|
|
|
91
100
|
endMs: number;
|
|
92
101
|
}
|
|
93
102
|
/** One sentence of a recorded walk, as the page plays it: its audio, when each word is said, its beats. */
|
|
94
|
-
export interface RecordedStep extends Shown {
|
|
103
|
+
export interface RecordedStep extends Shown, Guarded {
|
|
95
104
|
say: string;
|
|
96
105
|
audio: string;
|
|
97
106
|
durationMs: number;
|
|
98
107
|
words: TimedWord[];
|
|
99
108
|
beats: Beat[];
|
|
100
109
|
}
|
|
110
|
+
/** A sentence with slots: recorded when it is reached, once its values are known (`live`). */
|
|
111
|
+
export interface LiveStep extends Shown, Guarded {
|
|
112
|
+
say: string;
|
|
113
|
+
beats: Beat[];
|
|
114
|
+
live: true;
|
|
115
|
+
}
|
|
116
|
+
export type WalkStep = RecordedStep | LiveStep | ActStep;
|
|
101
117
|
/** A walk recorded in the agent's voice, published for the page to play with no call. */
|
|
102
118
|
export interface RecordedWalk {
|
|
103
119
|
name: string;
|
|
@@ -107,7 +123,9 @@ export interface RecordedWalk {
|
|
|
107
123
|
voice?: string | undefined;
|
|
108
124
|
/** The paths of the pages it is for; none, every page. */
|
|
109
125
|
pages?: string[] | undefined;
|
|
110
|
-
|
|
126
|
+
/** What it is called with: a walk with params is asked for, not picked from the menu. */
|
|
127
|
+
params?: Record<string, Param> | undefined;
|
|
128
|
+
steps: WalkStep[];
|
|
111
129
|
}
|
|
112
130
|
/** The agent asking for the page as it is now: sent when its call opens, answered with `page.seen`. */
|
|
113
131
|
export interface Look {
|
package/dist/wire/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAM1H,iEAAiE;AACjE,eAAO,MAAM,EAAE,gBAAgB,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,IAAI,cAAc,CAAC;AAChC,wEAAwE;AACxE,eAAO,MAAM,KAAK,UAAU,CAAC;AAC7B,uDAAuD;AACvD,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,8FAA8F;AAC9F,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,4FAA4F;AAC5F,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,yHAAyH;AACzH,eAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,+FAA+F;AAC/F,eAAO,MAAM,KAAK,UAAU,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAM1H,OAAO,EAA6C,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AAE1G,cAAc,WAAW,CAAC;AAE1B,iEAAiE;AACjE,eAAO,MAAM,EAAE,gBAAgB,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,IAAI,cAAc,CAAC;AAChC,wEAAwE;AACxE,eAAO,MAAM,KAAK,UAAU,CAAC;AAC7B,uDAAuD;AACvD,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,8FAA8F;AAC9F,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,4FAA4F;AAC5F,eAAO,MAAM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wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,GAAG,IAAI,CAiBrE;AAgBD,+GAA+G;AAC/G,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CA2B1E;AAED,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,CAW9C;AA0BD,4GAA4G;AAC5G,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,EAAE,CAiBtD;AAED,sGAAsG;AACtG,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAoD3D;AAED,iDAAiD;AACjD,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGxC;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9C"}
|
package/dist/wire/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// Both ride what a call already has. The page's facts go up as events (`call.event(name, data)`,
|
|
4
4
|
// the agent's `onEvent`); the agent's moves come down on `pinecall.ui`, beside its cards and
|
|
5
5
|
// choices, told apart by `type`.
|
|
6
|
+
import { actOf, guardsOf, isAct, paramsOf, slotsOf } from "./acts.js";
|
|
7
|
+
export * from "./acts.js";
|
|
6
8
|
/** The topic the agent sends on, and the page's `onUi` hears. */
|
|
7
9
|
export const UI = "pinecall.ui";
|
|
8
10
|
/**
|
|
@@ -24,10 +26,13 @@ export const WALKED = "page.walked";
|
|
|
24
26
|
/** The name the agent publishes its recorded walks under, which the page reads with no key. */
|
|
25
27
|
export const WALKS = "walks";
|
|
26
28
|
/**
|
|
27
|
-
* What the pointer can do. `type` fills a field with what the visitor said
|
|
28
|
-
*
|
|
29
|
+
* What the pointer can do. `type` fills a field with what the visitor said, and never touches a password
|
|
30
|
+
* or a card. `press` presses a button a walk names, one outside any form or in a search form: never a
|
|
31
|
+
* form that sends the visitor's details, and never a page left. `wait` waits for the page to change.
|
|
29
32
|
*/
|
|
30
|
-
export const ACTIONS = ["point", "highlight", "unhighlight", "scroll_to", "here", "home", "type"];
|
|
33
|
+
export const ACTIONS = ["point", "highlight", "unhighlight", "scroll_to", "here", "home", "type", "press", "wait"];
|
|
34
|
+
/** The moves a macro's beat cannot make: what types, presses or waits is a step of its own. */
|
|
35
|
+
const NOT_A_BEAT = ["type", "press", "wait"];
|
|
31
36
|
/** A target that is a ref of the snapshot rather than a name. */
|
|
32
37
|
export const A_REF = /^e\d+$/;
|
|
33
38
|
/** A path as a page names it: no trailing slash but the root's. */
|
|
@@ -82,7 +87,7 @@ function isBeat(value) {
|
|
|
82
87
|
const nth = beat["nth"];
|
|
83
88
|
// A beat has no words to type: a macro shows, and the agent fills a field only with what the visitor said.
|
|
84
89
|
const move = beat["do"];
|
|
85
|
-
return typeof beat["word"] === "string" && isAction(move) && move
|
|
90
|
+
return typeof beat["word"] === "string" && isAction(move) && !NOT_A_BEAT.includes(move) && found && (nth === undefined || (typeof nth === "number" && nth >= 1));
|
|
86
91
|
}
|
|
87
92
|
/** A message on `pinecall.ui` the tutor carries out, or null for one that is not its own (a card, choices). */
|
|
88
93
|
export function tutoring(data) {
|
|
@@ -94,10 +99,15 @@ export function tutoring(data) {
|
|
|
94
99
|
if (message["type"] === "macro.done" && typeof message["macro"] === "string")
|
|
95
100
|
return { type: "macro.done", macro: message["macro"] };
|
|
96
101
|
const action = message["action"];
|
|
102
|
+
const ms = message["ms"];
|
|
97
103
|
if (message["type"] === "cursor" && isAction(action) && optionalText(message["target"]) && optionalText(message["text"])) {
|
|
98
104
|
if (action === "type" && (message["target"] === undefined || message["text"] === undefined))
|
|
99
105
|
return null;
|
|
100
|
-
|
|
106
|
+
if ((action === "press" || action === "wait") && message["target"] === undefined)
|
|
107
|
+
return null;
|
|
108
|
+
if (ms !== undefined && (typeof ms !== "number" || ms <= 0))
|
|
109
|
+
return null;
|
|
110
|
+
return { type: "cursor", action, target: message["target"], text: message["text"], ...(ms === undefined ? {} : { ms }) };
|
|
101
111
|
}
|
|
102
112
|
const beats = message["beats"];
|
|
103
113
|
if (message["type"] === "macro.step" &&
|
|
@@ -140,13 +150,24 @@ function stepOf(value) {
|
|
|
140
150
|
if (typeof value !== "object" || value === null)
|
|
141
151
|
return null;
|
|
142
152
|
const step = { ...value };
|
|
153
|
+
const guards = guardsOf(step);
|
|
154
|
+
if (guards === null)
|
|
155
|
+
return null;
|
|
156
|
+
if (isAct(step)) {
|
|
157
|
+
const act = actOf(step);
|
|
158
|
+
return act === null ? null : { ...act, ...guards };
|
|
159
|
+
}
|
|
143
160
|
const { say, audio, durationMs, words, beats } = step;
|
|
144
|
-
|
|
161
|
+
const shown = shownOf(step);
|
|
162
|
+
if (typeof say !== "string" || !Array.isArray(beats) || !beats.every(isBeat) || shown === null)
|
|
145
163
|
return null;
|
|
146
|
-
if (
|
|
164
|
+
if (step["live"] === true)
|
|
165
|
+
return { say, beats, live: true, ...shown, ...guards };
|
|
166
|
+
if (typeof audio !== "string" || !/^https?:\/\//.test(audio) || typeof durationMs !== "number")
|
|
147
167
|
return null;
|
|
148
|
-
|
|
149
|
-
|
|
168
|
+
if (!Array.isArray(words) || !words.every(isWord))
|
|
169
|
+
return null;
|
|
170
|
+
return { say, audio, durationMs, words, beats, ...shown, ...guards };
|
|
150
171
|
}
|
|
151
172
|
/** The walks a published document holds, each checked: a walk with any step that is not one is left out. */
|
|
152
173
|
export function walksOf(value) {
|
|
@@ -166,8 +187,11 @@ export function walksOf(value) {
|
|
|
166
187
|
const checked = steps.map(stepOf);
|
|
167
188
|
if (checked.some((step) => step === null))
|
|
168
189
|
return [];
|
|
190
|
+
const params = walk["params"] === undefined ? undefined : paramsOf(walk["params"]);
|
|
191
|
+
if (params === null)
|
|
192
|
+
return [];
|
|
169
193
|
const paths = Array.isArray(pages) && pages.every((page) => typeof page === "string") ? pages : undefined;
|
|
170
|
-
return [{ name, title, when: typeof when === "string" ? when : undefined, pages: paths, steps: checked.filter((step) => step !== null) }];
|
|
194
|
+
return [{ name, title, when: typeof when === "string" ? when : undefined, pages: paths, ...(params === undefined ? {} : { params }), steps: checked.filter((step) => step !== null) }];
|
|
171
195
|
});
|
|
172
196
|
}
|
|
173
197
|
/** A macro as its JSON file says it, checked; it throws naming what is wrong, at the class's load. */
|
|
@@ -178,10 +202,33 @@ export function macroOf(name, value) {
|
|
|
178
202
|
const steps = macro["steps"];
|
|
179
203
|
if (!Array.isArray(steps) || steps.length === 0)
|
|
180
204
|
throw new Error(`macro ${name}: no steps`);
|
|
205
|
+
const params = macro["params"] === undefined ? {} : paramsOf(macro["params"]);
|
|
206
|
+
if (params === null)
|
|
207
|
+
throw new Error(`macro ${name}: params are {"<name>": {"about": "...", "one_of"?: {"<option>": "..."}}}`);
|
|
208
|
+
// A slot is a param, or a row an earlier step read: `{name}`, `{hit.Time}`.
|
|
209
|
+
const known = new Set(Object.keys(params));
|
|
210
|
+
const slotted = (at, text) => {
|
|
211
|
+
const unknown = slotsOf(text).find((slot) => !known.has(slot.split(".")[0] ?? ""));
|
|
212
|
+
if (unknown !== undefined)
|
|
213
|
+
throw new Error(`macro ${name}: step ${at + 1} fills {${unknown}}, which is no param and no row read before it`);
|
|
214
|
+
};
|
|
181
215
|
const checked = steps.map((step, at) => {
|
|
182
216
|
if (typeof step !== "object" || step === null)
|
|
183
217
|
throw new Error(`macro ${name}: step ${at + 1} is not an object`);
|
|
184
218
|
const fields = { ...step };
|
|
219
|
+
const guards = guardsOf(fields);
|
|
220
|
+
if (guards === null)
|
|
221
|
+
throw new Error(`macro ${name}: step ${at + 1} has an if or unless that is not a slot's name`);
|
|
222
|
+
if (isAct(fields)) {
|
|
223
|
+
const act = actOf(fields);
|
|
224
|
+
if (act === null)
|
|
225
|
+
throw new Error(`macro ${name}: step ${at + 1} is not {fill, with}, {press}, {wait, ms?} or {read, as, row?}`);
|
|
226
|
+
if ("fill" in act)
|
|
227
|
+
slotted(at, act.with);
|
|
228
|
+
if ("read" in act)
|
|
229
|
+
known.add(act.as);
|
|
230
|
+
return { ...act, ...guards };
|
|
231
|
+
}
|
|
185
232
|
const say = fields["say"];
|
|
186
233
|
const beats = fields["beats"] ?? [];
|
|
187
234
|
if (typeof say !== "string" || say.trim() === "")
|
|
@@ -191,11 +238,14 @@ export function macroOf(name, value) {
|
|
|
191
238
|
for (const beat of beats) {
|
|
192
239
|
if (!wordsOf(say).some((word) => word === normal(beat.word)))
|
|
193
240
|
throw new Error(`macro ${name}: step ${at + 1} never says "${beat.word}"`);
|
|
241
|
+
if (beat.find !== undefined)
|
|
242
|
+
slotted(at, beat.find[1]);
|
|
194
243
|
}
|
|
244
|
+
slotted(at, say);
|
|
195
245
|
const shown = shownOf(fields);
|
|
196
246
|
if (shown === null)
|
|
197
247
|
throw new Error(`macro ${name}: step ${at + 1} shows code that is not {code: {title, text} or null, lines: [from, to]}`);
|
|
198
|
-
return { say, beats, ...shown };
|
|
248
|
+
return { say, beats, ...shown, ...guards };
|
|
199
249
|
});
|
|
200
250
|
const when = macro["when"];
|
|
201
251
|
const title = macro["title"];
|
|
@@ -208,6 +258,7 @@ export function macroOf(name, value) {
|
|
|
208
258
|
title: typeof title === "string" ? title : undefined,
|
|
209
259
|
when: typeof when === "string" ? when : undefined,
|
|
210
260
|
pages: pages === undefined ? undefined : pages,
|
|
261
|
+
...(Object.keys(params).length === 0 ? {} : { params }),
|
|
211
262
|
steps: checked,
|
|
212
263
|
};
|
|
213
264
|
}
|