@pinecall/dot 0.11.23 → 0.11.25

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.
Files changed (124) hide show
  1. package/README.md +145 -63
  2. package/dist/agent/index.d.ts +3 -2
  3. package/dist/agent/index.d.ts.map +1 -1
  4. package/dist/agent/index.js +2 -1
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/tutor.d.ts +12 -10
  7. package/dist/agent/tutor.d.ts.map +1 -1
  8. package/dist/agent/tutor.js +81 -68
  9. package/dist/agent/tutor.js.map +1 -1
  10. package/dist/agent/walks.d.ts +19 -0
  11. package/dist/agent/walks.d.ts.map +1 -0
  12. package/dist/agent/walks.js +89 -0
  13. package/dist/agent/walks.js.map +1 -0
  14. package/dist/page/page.d.ts +2 -2
  15. package/dist/page/page.d.ts.map +1 -1
  16. package/dist/page/page.js +5 -5
  17. package/dist/page/page.js.map +1 -1
  18. package/dist/page/roles.d.ts +2 -0
  19. package/dist/page/roles.d.ts.map +1 -1
  20. package/dist/page/roles.js +21 -2
  21. package/dist/page/roles.js.map +1 -1
  22. package/dist/pointer/asking.d.ts +25 -0
  23. package/dist/pointer/asking.d.ts.map +1 -0
  24. package/dist/pointer/asking.js +82 -0
  25. package/dist/pointer/asking.js.map +1 -0
  26. package/dist/pointer/flight.d.ts +40 -4
  27. package/dist/pointer/flight.d.ts.map +1 -1
  28. package/dist/pointer/flight.js +139 -17
  29. package/dist/pointer/flight.js.map +1 -1
  30. package/dist/pointer/frames.d.ts +28 -0
  31. package/dist/pointer/frames.d.ts.map +1 -0
  32. package/dist/pointer/frames.js +66 -0
  33. package/dist/pointer/frames.js.map +1 -0
  34. package/dist/pointer/icons.d.ts +8 -0
  35. package/dist/pointer/icons.d.ts.map +1 -0
  36. package/dist/pointer/icons.js +15 -0
  37. package/dist/pointer/icons.js.map +1 -0
  38. package/dist/pointer/menu.d.ts +5 -4
  39. package/dist/pointer/menu.d.ts.map +1 -1
  40. package/dist/pointer/menu.js +56 -47
  41. package/dist/pointer/menu.js.map +1 -1
  42. package/dist/pointer/person.d.ts +13 -2
  43. package/dist/pointer/person.d.ts.map +1 -1
  44. package/dist/pointer/person.js +47 -41
  45. package/dist/pointer/person.js.map +1 -1
  46. package/dist/pointer/pressing.d.ts +6 -0
  47. package/dist/pointer/pressing.d.ts.map +1 -0
  48. package/dist/pointer/pressing.js +32 -0
  49. package/dist/pointer/pressing.js.map +1 -0
  50. package/dist/pointer/sections.d.ts +4 -7
  51. package/dist/pointer/sections.d.ts.map +1 -1
  52. package/dist/pointer/sections.js +11 -17
  53. package/dist/pointer/sections.js.map +1 -1
  54. package/dist/pointer/typing.d.ts +5 -3
  55. package/dist/pointer/typing.d.ts.map +1 -1
  56. package/dist/pointer/typing.js +46 -15
  57. package/dist/pointer/typing.js.map +1 -1
  58. package/dist/server/index.d.ts +34 -0
  59. package/dist/server/index.d.ts.map +1 -0
  60. package/dist/server/index.js +108 -0
  61. package/dist/server/index.js.map +1 -0
  62. package/dist/server/questions.d.ts +30 -0
  63. package/dist/server/questions.d.ts.map +1 -0
  64. package/dist/server/questions.js +136 -0
  65. package/dist/server/questions.js.map +1 -0
  66. package/dist/server/saying.d.ts +31 -0
  67. package/dist/server/saying.d.ts.map +1 -0
  68. package/dist/server/saying.js +124 -0
  69. package/dist/server/saying.js.map +1 -0
  70. package/dist/tutor/acting.d.ts +42 -0
  71. package/dist/tutor/acting.d.ts.map +1 -0
  72. package/dist/tutor/acting.js +180 -0
  73. package/dist/tutor/acting.js.map +1 -0
  74. package/dist/tutor/aloud.d.ts +50 -0
  75. package/dist/tutor/aloud.d.ts.map +1 -0
  76. package/dist/tutor/aloud.js +288 -0
  77. package/dist/tutor/aloud.js.map +1 -0
  78. package/dist/tutor/ask.d.ts +49 -0
  79. package/dist/tutor/ask.d.ts.map +1 -0
  80. package/dist/tutor/ask.js +47 -0
  81. package/dist/tutor/ask.js.map +1 -0
  82. package/dist/tutor/listening.d.ts +17 -0
  83. package/dist/tutor/listening.d.ts.map +1 -0
  84. package/dist/tutor/listening.js +66 -0
  85. package/dist/tutor/listening.js.map +1 -0
  86. package/dist/tutor/options.d.ts +37 -1
  87. package/dist/tutor/options.d.ts.map +1 -1
  88. package/dist/tutor/options.js +1 -1
  89. package/dist/tutor/options.js.map +1 -1
  90. package/dist/tutor/reading.d.ts +58 -0
  91. package/dist/tutor/reading.d.ts.map +1 -0
  92. package/dist/tutor/reading.js +193 -0
  93. package/dist/tutor/reading.js.map +1 -0
  94. package/dist/tutor/text.d.ts +16 -0
  95. package/dist/tutor/text.d.ts.map +1 -0
  96. package/dist/tutor/text.js +119 -0
  97. package/dist/tutor/text.js.map +1 -0
  98. package/dist/tutor/tutor.d.ts +2 -9
  99. package/dist/tutor/tutor.d.ts.map +1 -1
  100. package/dist/tutor/tutor.js +110 -87
  101. package/dist/tutor/tutor.js.map +1 -1
  102. package/dist/tutor/walking.d.ts +26 -8
  103. package/dist/tutor/walking.d.ts.map +1 -1
  104. package/dist/tutor/walking.js +145 -30
  105. package/dist/tutor/walking.js.map +1 -1
  106. package/dist/tutor/walks.d.ts +33 -0
  107. package/dist/tutor/walks.d.ts.map +1 -1
  108. package/dist/tutor/walks.js +121 -13
  109. package/dist/tutor/walks.js.map +1 -1
  110. package/dist/wire/acts.d.ts +60 -0
  111. package/dist/wire/acts.d.ts.map +1 -0
  112. package/dist/wire/acts.js +120 -0
  113. package/dist/wire/acts.js.map +1 -0
  114. package/dist/wire/ask.d.ts +132 -0
  115. package/dist/wire/ask.d.ts.map +1 -0
  116. package/dist/wire/ask.js +102 -0
  117. package/dist/wire/ask.js.map +1 -0
  118. package/dist/wire/index.d.ts +38 -8
  119. package/dist/wire/index.d.ts.map +1 -1
  120. package/dist/wire/index.js +86 -12
  121. package/dist/wire/index.js.map +1 -1
  122. package/docs/macros.md +216 -0
  123. package/docs/write-a-tutor.md +247 -0
  124. package/package.json +11 -6
@@ -0,0 +1,136 @@
1
+ /** What Jev is asked about what the visitor typed, and what its answers come to: the questions, the parts of the message a param is picked from, the decision. */
2
+ //
3
+ // Three questions on the same state, answered at once: what kind of thing they want (a walk, a thing
4
+ // shown, a person's answer, nothing), which walk, which thing of the page. And one more for each param of
5
+ // each walk: Jev cannot write, so a param in the visitor's words is a choice among the parts of what they
6
+ // typed (`spans`), one to five words in a row, or none; a param of a list, a choice among its options.
7
+ // So what fills a field is what the visitor wrote, never a word of the model's.
8
+ import { namedIn } from "../wire/ask.js";
9
+ import { valueOf } from "../wire/acts.js";
10
+ export const MODEL = "~typesafe/jev-latest";
11
+ export const THRESHOLD = 0.5;
12
+ /** The most options a Choice takes. */
13
+ export const MOST = 255;
14
+ /** The most words a part of the message picked as a param holds. */
15
+ const SPAN_WORDS = 5;
16
+ /** The roles a visitor asks to be shown first, when a page has more things than a Choice takes. */
17
+ const FIRST = ["region", "heading", "article", "group", "tab", "button", "link", "img", "form", "textbox", "combobox", "checkbox", "radio"];
18
+ // A question is often a walk's to answer ("do you have a time on Thursday?" is a walk that searches the
19
+ // times): what a walk does or finds wins over a person's words.
20
+ const INTENTS = {
21
+ walk: "one of this page's walks does or finds what they ask, even asked as a question: a tour, a topic it covers, a search it runs, a form it fills",
22
+ show: "they want to see where one thing is on this page",
23
+ talk: "no walk of the page does it, and only a person can answer: advice on their own case, a problem, a complaint",
24
+ none: "it is not about this site, or nothing on this page answers it",
25
+ };
26
+ /** The things of the page the choice is among: every one with a name, the sections and headings first when there are too many. */
27
+ export function thingsOf(page) {
28
+ const named = namedIn(page);
29
+ if (named.length <= MOST)
30
+ return named;
31
+ const rank = (role) => (FIRST.includes(role) ? FIRST.indexOf(role) : FIRST.length);
32
+ const kept = new Set([...named].sort((a, b) => rank(a.role) - rank(b.role)).slice(0, MOST));
33
+ return named.filter((thing) => kept.has(thing));
34
+ }
35
+ /**
36
+ * The parts of what the visitor typed a param can be: one to five words in a row, as written, without the
37
+ * commas and quotes around them. An email or a phone stays whole, being one word or two. The shorter first.
38
+ */
39
+ export function spansOf(message) {
40
+ const words = [...message.matchAll(/\S+/g)].map((found) => ({ at: found.index, text: found[0] }));
41
+ const trimmed = (text) => text.replace(/^["'¿¡«“]+/, "").replace(/[,.;:!?"'»”]+$/, "");
42
+ const spans = [];
43
+ for (let size = 1; size <= SPAN_WORDS; size += 1) {
44
+ for (let from = 0; from + size <= words.length; from += 1) {
45
+ const first = words[from];
46
+ const last = words[from + size - 1];
47
+ if (first === undefined || last === undefined)
48
+ continue;
49
+ const span = trimmed(message.slice(first.at, last.at + last.text.length));
50
+ if (span !== "" && !spans.includes(span))
51
+ spans.push(span);
52
+ }
53
+ }
54
+ return spans.slice(0, MOST - 1);
55
+ }
56
+ /** The key a param's question is asked under: `param.<walk>.<name>`. */
57
+ const keyOf = (walk, param) => `param.${walk}.${param}`;
58
+ /** The request Jev is asked: the state, and the questions on it. */
59
+ export function questionsOf(request, things, model = MODEL, spans = spansOf(request.message)) {
60
+ const walks = request.walks;
61
+ const intents = walks.length > 0 ? INTENTS : { show: INTENTS.show, talk: INTENTS.talk, none: INTENTS.none };
62
+ const state = [
63
+ `A visitor is on the page ${request.path} of a website and typed to its guide: "${request.message}"`,
64
+ "",
65
+ "The things on the page (role and name):",
66
+ ...things.map((thing) => `- ${thing.role} "${thing.name}"`),
67
+ ...(walks.length > 0 ? ["", "The page's guided walks:", ...walks.map((walk) => `- ${walk.title}${walk.when ? `: ${walk.when}` : ""}`)] : []),
68
+ ].join("\n");
69
+ const questions = {
70
+ intent: {
71
+ type: "choice",
72
+ instructions: walks.length > 0 ? "What does the visitor want the guide to do? Read the page's walks first: one that does or finds it is the answer." : "What does the visitor want the guide to do?",
73
+ criteria: intents,
74
+ },
75
+ target: {
76
+ type: "choice",
77
+ instructions: "Which one thing on the page is what they want to see, or best answers what they typed?",
78
+ criteria: Object.fromEntries(things.map((thing) => [thing.ref, `${thing.role} "${thing.name}"`])),
79
+ },
80
+ };
81
+ if (walks.length > 0) {
82
+ questions["walk"] = {
83
+ type: "choice",
84
+ instructions: "Which of the page's guided walks is about what they typed?",
85
+ criteria: Object.fromEntries(walks.map((walk) => [walk.name, `${walk.title}${walk.when ? `: ${walk.when}` : ""}`])),
86
+ };
87
+ }
88
+ for (const walk of walks) {
89
+ for (const [name, param] of Object.entries(walk.params ?? {})) {
90
+ const options = param.oneOf ?? Object.fromEntries(spans.map((span, at) => [`s${at}`, `"${span}"`]));
91
+ questions[keyOf(walk.name, name)] = {
92
+ type: "choice",
93
+ instructions: param.oneOf === undefined
94
+ ? `If they want "${walk.title}": which part of what they typed is ${param.about}? "none" when they did not write it.`
95
+ : `If they want "${walk.title}": which one is ${param.about}? "none" when they did not say.`,
96
+ criteria: { none: "they did not say", ...options },
97
+ };
98
+ }
99
+ }
100
+ return { model, state: [state], questions };
101
+ }
102
+ /**
103
+ * The one thing to do, from Jev's answers. To act (a walk or a thing shown) wins when the two together are
104
+ * more likely than not, and of the two the surer one; under `threshold` it does nothing rather than guess.
105
+ */
106
+ export function decisionFrom(answers, threshold = THRESHOLD) {
107
+ const p = answers["intent"]?.probabilities ?? {};
108
+ const intent = answers["intent"]?.confidence ?? 0;
109
+ const walk = answers["walk"];
110
+ const target = answers["target"];
111
+ if ((p["walk"] ?? 0) + (p["show"] ?? 0) >= 0.5) {
112
+ const walking = (p["walk"] ?? 0) * (walk?.confidence ?? 0);
113
+ const showing = (p["show"] ?? 0) * (target?.confidence ?? 0);
114
+ if (walking >= showing && walk?.choice !== undefined && (walk.confidence ?? 0) >= threshold)
115
+ return { do: "walk", walk: walk.choice, confidence: walk.confidence ?? 0 };
116
+ if (target?.choice !== undefined && (target.confidence ?? 0) >= threshold)
117
+ return { do: "show", target: target.choice, confidence: target.confidence ?? 0 };
118
+ return { do: "none", confidence: intent };
119
+ }
120
+ return (p["talk"] ?? 0) >= (p["none"] ?? 0) ? { do: "talk", confidence: intent } : { do: "none", confidence: intent };
121
+ }
122
+ /** The params of the walk decided, each one Jev was sure of: the part of the message, or the option. */
123
+ export function paramsFrom(answers, walk, spans, threshold = THRESHOLD) {
124
+ const values = {};
125
+ for (const [name, param] of Object.entries(walk.params ?? {})) {
126
+ const answer = answers[keyOf(walk.name, name)];
127
+ const choice = answer?.choice;
128
+ if (choice === undefined || choice === "none" || (answer?.confidence ?? 0) < threshold)
129
+ continue;
130
+ const value = param.oneOf === undefined ? spans[Number(choice.slice(1))] : choice in param.oneOf ? choice : undefined;
131
+ if (value !== undefined)
132
+ values[name] = valueOf(value);
133
+ }
134
+ return values;
135
+ }
136
+ //# sourceMappingURL=questions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.js","sourceRoot":"","sources":["../../src/server/questions.ts"],"names":[],"mappings":"AAAA,kKAAkK;AAClK,EAAE;AACF,qGAAqG;AACrG,0GAA0G;AAC1G,0GAA0G;AAC1G,uGAAuG;AACvG,gFAAgF;AAEhF,OAAO,EAAE,OAAO,EAA8C,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAe,MAAM,iBAAiB,CAAC;AAEvD,MAAM,CAAC,MAAM,KAAK,GAAG,sBAAsB,CAAC;AAC5C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,uCAAuC;AACvC,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC;AACxB,oEAAoE;AACpE,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,mGAAmG;AACnG,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAE5I,wGAAwG;AACxG,gEAAgE;AAChE,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,8IAA8I;IACpJ,IAAI,EAAE,kDAAkD;IACxD,IAAI,EAAE,6GAA6G;IACnH,IAAI,EAAE,+DAA+D;CACtE,CAAC;AASF,kIAAkI;AAClI,MAAM,UA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S;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /** A sentence of a walk recorded when it is reached, once its slots are filled: the agent's voice, in real time, on the site's server. */
2
+ import { type ExplainRequest, type NextLine, type NextRequest, type Note, type SaidAnswer, type SayRequest } from "../wire/ask.js";
3
+ /** The agent whose voice records it, and the key the site's server holds for it. */
4
+ export interface Voicing {
5
+ key: string;
6
+ agent: string;
7
+ /** Default `https://cloud.pinecall.io`. */
8
+ gateway?: string | undefined;
9
+ /** Which world the agent's walks and voice are read in: `sandbox` while it is held there. Default production. */
10
+ env?: "sandbox" | "production" | undefined;
11
+ /**
12
+ * Whether a page may have its own text read aloud (`{ read }`, a page read with `reading`): any text of 480
13
+ * characters said in the agent's voice. For a site whose door answers its own pages alone. Default no.
14
+ */
15
+ read?: boolean | undefined;
16
+ /** Whether a page may have an output explained by the agent's model (`{ explain }`): a model asked per output. Default no. */
17
+ explain?: boolean | undefined;
18
+ /** Whether a page may have the dot talk to a chat for a goal (`{ next }`): Pinecall's caller asked per turn. Default no. */
19
+ next?: boolean | undefined;
20
+ }
21
+ /** Record a walk's sentence with its slots filled, in the agent's voice. Throws when the sentence is not the walk's or a slot is empty. */
22
+ export declare function recordSay(request: SayRequest, voicing: Voicing, ask?: typeof fetch): Promise<SaidAnswer>;
23
+ /** A text of the page itself recorded in the agent's voice: a part of a page read aloud. Throws unless the voicing lets a page read. */
24
+ export declare function recordRead(text: string, voicing: Voicing, ask?: typeof fetch): Promise<SaidAnswer>;
25
+ /** An output explained by the agent's model, through the gateway: notes, each on one line of it. Throws unless the voicing lets a page explain. */
26
+ export declare function explainOutput(request: ExplainRequest, voicing: Voicing, ask?: typeof fetch): Promise<{
27
+ notes: Note[];
28
+ }>;
29
+ /** The dot's next line on a chat it talks to for a goal: Pinecall's caller, through the gateway, playing it. Throws unless the voicing lets a page talk. */
30
+ export declare function nextLine(request: NextRequest, voicing: Voicing, ask?: typeof fetch): Promise<NextLine>;
31
+ //# sourceMappingURL=saying.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saying.d.ts","sourceRoot":"","sources":["../../src/server/saying.ts"],"names":[],"mappings":"AAAA,0IAA0I;AAS1I,OAAO,EAA+B,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGhK,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,iHAAiH;IACjH,GAAG,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;IAC3C;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,8HAA8H;IAC9H,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,4HAA4H;IAC5H,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B;AAuCD,2IAA2I;AAC3I,wBAAsB,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAE,OAAO,KAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAUrH;AAED,wIAAwI;AACxI,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAE,OAAO,KAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAK/G;AAED,mJAAmJ;AACnJ,wBAAsB,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAE,OAAO,KAAa,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,IAAI,EAAE,CAAA;CAAE,CAAC,CAWpI;AAED,4JAA4J;AAC5J,wBAAsB,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,GAAE,OAAO,KAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBnH"}
@@ -0,0 +1,124 @@
1
+ /** A sentence of a walk recorded when it is reached, once its slots are filled: the agent's voice, in real time, on the site's server. */
2
+ //
3
+ // A walk's sentence with `{slots}` cannot be recorded before the visitor says what fills them. The page
4
+ // asks for it by the walk, the step and the values; the sentence itself is read from the walks the agent
5
+ // published, never from the page, so a page asks the voice for the site's own sentences and nothing else:
6
+ // what a visitor brings is the values, one line of 80 characters each. The gateway records each text once
7
+ // and keeps it, so the same sentence with the same values costs nothing the second time.
8
+ import { filled, slotsOf, valueOf } from "../wire/acts.js";
9
+ import { MOST_HEARD, nextOf, notesOf } from "../wire/ask.js";
10
+ import { walksDocument, walksOf } from "../wire/index.js";
11
+ /** The most turns of its own a talk takes: the gateway's own ceiling on a caller's. */
12
+ const MOST_TURNS = 40;
13
+ const STYLE = "a person writing in a chat{language}: short turns, one or two lines, no narration";
14
+ /** The longest output a page may have explained. */
15
+ const LONGEST_EXPLAINED = 8000;
16
+ /** The longest text a page may have read in one request. */
17
+ const LONGEST_READ = 480;
18
+ const GATEWAY = "https://cloud.pinecall.io";
19
+ /** How long the walks a page reads are kept, in ms: as long as the gateway lets a page keep them. */
20
+ const KEPT_MS = 60_000;
21
+ const kept = new Map();
22
+ async function walksAt(url, ask) {
23
+ const hit = kept.get(url);
24
+ if (hit !== undefined && Date.now() - hit.at < KEPT_MS)
25
+ return hit.walks;
26
+ const answer = await ask(url);
27
+ const walks = answer.ok ? walksOf(await answer.json()) : [];
28
+ kept.set(url, { at: Date.now(), walks });
29
+ return walks;
30
+ }
31
+ /** The live step a request names, in the walks published for its page or, failing them, the home's. */
32
+ async function stepOf(request, voicing, ask) {
33
+ const base = `${(voicing.gateway ?? GATEWAY).replace(/\/+$/, "")}/v1/agents/${encodeURIComponent(voicing.agent)}/public/`;
34
+ const query = voicing.env === "sandbox" ? "?env=sandbox" : "";
35
+ for (const document of new Set([walksDocument(request.path), "walks"])) {
36
+ const walk = (await walksAt(`${base}${document}${query}`, ask)).find((one) => one.name === request.walk);
37
+ const step = walk?.steps[request.step];
38
+ if (step !== undefined && "live" in step)
39
+ return step;
40
+ if (walk !== undefined)
41
+ break;
42
+ }
43
+ throw new Error(`the walk ${request.walk} has no sentence to record at step ${request.step}`);
44
+ }
45
+ /** Record a walk's sentence with its slots filled, in the agent's voice. Throws when the sentence is not the walk's or a slot is empty. */
46
+ export async function recordSay(request, voicing, ask = fetch) {
47
+ const step = await stepOf(request, voicing, ask);
48
+ const values = {};
49
+ for (const slot of slotsOf(step.say)) {
50
+ const value = request.values[slot];
51
+ if (typeof value === "string")
52
+ values[slot] = valueOf(value);
53
+ }
54
+ const text = filled(step.say, values);
55
+ if (text === null)
56
+ throw new Error(`the walk ${request.walk}'s step ${request.step} needs ${slotsOf(step.say).join(", ")}`);
57
+ return recorded(text, voicing, ask);
58
+ }
59
+ /** A text of the page itself recorded in the agent's voice: a part of a page read aloud. Throws unless the voicing lets a page read. */
60
+ export async function recordRead(text, voicing, ask = fetch) {
61
+ if (voicing.read !== true)
62
+ throw new Error("this door reads no page aloud: give its voicing read: true");
63
+ const line = text.replace(/\s+/g, " ").trim();
64
+ if (line === "" || line.length > LONGEST_READ)
65
+ throw new Error(`a text read is 1 to ${LONGEST_READ} characters`);
66
+ return recorded(line, voicing, ask);
67
+ }
68
+ /** An output explained by the agent's model, through the gateway: notes, each on one line of it. Throws unless the voicing lets a page explain. */
69
+ export async function explainOutput(request, voicing, ask = fetch) {
70
+ if (voicing.explain !== true)
71
+ throw new Error("this door explains no output: give its voicing explain: true");
72
+ const output = request.output.trim();
73
+ if (output === "" || output.length > LONGEST_EXPLAINED)
74
+ throw new Error(`an output explained is 1 to ${LONGEST_EXPLAINED} characters`);
75
+ const answer = await ask(`${(voicing.gateway ?? GATEWAY).replace(/\/+$/, "")}/v1/agents/${encodeURIComponent(voicing.agent)}/explain`, {
76
+ method: "POST",
77
+ headers: { authorization: `Bearer ${voicing.key}`, "content-type": "application/json", ...(voicing.env === undefined ? {} : { "pinecall-env": voicing.env }) },
78
+ body: JSON.stringify({ output, ...(request.command === undefined ? {} : { command: request.command.slice(0, 300) }), ...(request.language === undefined ? {} : { language: request.language }) }),
79
+ });
80
+ if (!answer.ok)
81
+ throw new Error(`the gateway explained nothing: ${answer.status}`);
82
+ return { notes: notesOf(await answer.json()) };
83
+ }
84
+ /** The dot's next line on a chat it talks to for a goal: Pinecall's caller, through the gateway, playing it. Throws unless the voicing lets a page talk. */
85
+ export async function nextLine(request, voicing, ask = fetch) {
86
+ if (voicing.next !== true)
87
+ throw new Error("this door talks to no chat: give its voicing next: true");
88
+ const goal = request.goal.trim();
89
+ if (goal === "" || goal.length > 4000)
90
+ throw new Error("a goal talked for is 1 to 4000 characters");
91
+ const heard = request.heard.slice(-MOST_HEARD).map((turn) => ({ who: turn.who === "agent" ? "agent" : "caller", said: turn.said.slice(0, 4000) }));
92
+ const mine = heard.filter((turn) => turn.who === "caller").length;
93
+ const answer = await ask(`${(voicing.gateway ?? GATEWAY).replace(/\/+$/, "")}/v1/evals/caller`, {
94
+ method: "POST",
95
+ headers: { authorization: `Bearer ${voicing.key}`, "content-type": "application/json", ...(voicing.env === undefined ? {} : { "pinecall-env": voicing.env }) },
96
+ body: JSON.stringify({
97
+ persona: { goal, style: STYLE.replace("{language}", request.language === undefined ? "" : `, in the language "${request.language}"`) },
98
+ heard,
99
+ turns_left: Math.max(1, MOST_TURNS - mine),
100
+ }),
101
+ });
102
+ if (!answer.ok)
103
+ throw new Error(`the gateway said nothing: ${answer.status}`);
104
+ const line = nextOf(await answer.json());
105
+ if (line === null)
106
+ throw new Error("the gateway gave no line");
107
+ return line;
108
+ }
109
+ /** One text recorded by the gateway in the agent's voice, kept: the same text again costs nothing. */
110
+ async function recorded(text, voicing, ask) {
111
+ const answer = await ask(`${(voicing.gateway ?? GATEWAY).replace(/\/+$/, "")}/v1/agents/${encodeURIComponent(voicing.agent)}/lines`, {
112
+ method: "POST",
113
+ headers: { authorization: `Bearer ${voicing.key}`, "content-type": "application/json", ...(voicing.env === undefined ? {} : { "pinecall-env": voicing.env }) },
114
+ body: JSON.stringify({ texts: [text] }),
115
+ });
116
+ if (!answer.ok)
117
+ throw new Error(`the gateway recorded nothing: ${answer.status}`);
118
+ const body = (await answer.json());
119
+ const line = body.lines?.[0];
120
+ if (line === undefined)
121
+ throw new Error("the gateway recorded nothing");
122
+ return { say: text, audio: line.url, durationMs: line.duration_ms, words: line.words.map((word) => ({ text: word.text, startMs: word.start_ms, endMs: word.end_ms })) };
123
+ }
124
+ //# sourceMappingURL=saying.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saying.js","sourceRoot":"","sources":["../../src/server/saying.ts"],"names":[],"mappings":"AAAA,0IAA0I;AAC1I,EAAE;AACF,wGAAwG;AACxG,yGAAyG;AACzG,0GAA0G;AAC1G,0GAA0G;AAC1G,yFAAyF;AAEzF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAe,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAqG,MAAM,gBAAgB,CAAC;AAChK,OAAO,EAAE,aAAa,EAAE,OAAO,EAAoC,MAAM,kBAAkB,CAAC;AAqB5F,uFAAuF;AACvF,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,KAAK,GAAG,mFAAmF,CAAC;AAElG,oDAAoD;AACpD,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,4DAA4D;AAC5D,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,qGAAqG;AACrG,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,IAAI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E,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AAC1K,CAAC"}
@@ -0,0 +1,42 @@
1
+ /** What a walk's acts do on the page with no call: a field filled, a button pressed, the page waited on, a table read; and a sentence with slots recorded. */
2
+ import type { Page } from "../page/page.js";
3
+ import { type DoorRequest, type ExplainRequest, type NextLine, type NextRequest, type Note } from "../wire/ask.js";
4
+ import { type ActStep, type RecordedStep, type RecordedWalk, type Values } from "../wire/index.js";
5
+ export interface ActingOptions {
6
+ document: Document;
7
+ page: Page;
8
+ /** Run `work` after the moves already queued. */
9
+ queued: <T>(work: () => Promise<T>) => Promise<T>;
10
+ /** The pointer onto an element; called inside the queue. */
11
+ point: (element: Element) => Promise<void>;
12
+ /** The ring at the pointer's tip. */
13
+ ring: () => void;
14
+ /** The visitor's words typed into a field, the pointer on it; called inside the queue. Paced to `ms` when given. Why it could not, or null. */
15
+ type: (element: Element, text: string, ms?: number) => Promise<string | null>;
16
+ /** The site's door; none, a sentence with slots is left out and the first row read. */
17
+ door?: ((request: DoorRequest) => Promise<unknown>) | undefined;
18
+ }
19
+ /** How long a wait waits when its step does not say, in ms. */
20
+ export declare const WAIT_MS = 8000;
21
+ export declare class Acting {
22
+ #private;
23
+ constructor(options: ActingOptions);
24
+ /** One act of a walk, after the moves queued before it: the values a read adds. */
25
+ act(step: ActStep, values: Values, message: string): Promise<Values>;
26
+ /** Press a button, the pointer on it first and a ring as it presses; the page is watched from now. Why it could not, or null. `forms`, a page read aloud's example, pressed in any form. */
27
+ press(element: Element, forms?: boolean): Promise<string | null>;
28
+ /** Words typed into a field, the pointer on it: a page read aloud's example. Why it could not, or null. */
29
+ type(element: Element, text: string, ms?: number): Promise<string | null>;
30
+ /** Wait for `target` to change, settle and not be busy, `ms` at most: true when it did. */
31
+ wait(target: () => Element | null, ms: number): Promise<boolean>;
32
+ /** A sentence with slots, recorded now by the site's door; null when it cannot be. */
33
+ voice(path: string, walk: RecordedWalk, at: number, values: Values): Promise<RecordedStep | null>;
34
+ /** An output explained by the site's door, the agent's model: its notes; none when the door gives none. */
35
+ explain(request: ExplainRequest): Promise<Note[]>;
36
+ /** The dot's next line on a chat it talks to for a goal, by the site's door; null when it gives none. */
37
+ next(request: NextRequest): Promise<NextLine | null>;
38
+ /** A text of the page, recorded now by the site's door in the agent's voice; null when it cannot be. */
39
+ read(text: string): Promise<RecordedStep | null>;
40
+ close(): void;
41
+ }
42
+ //# sourceMappingURL=acting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acting.d.ts","sourceRoot":"","sources":["../../src/tutor/acting.ts"],"names":[],"mappings":"AAAA,8JAA8J;AAS9J,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAkC,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACnJ,OAAO,EAA4B,KAAK,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAgB,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1J,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,iDAAiD;IACjD,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAClD,4DAA4D;IAC5D,KAAK,EAAE,CAAC,OAAO,EAAE,OA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OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAItD;IAED,yGAAyG;IACnG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAIzD;IAED,wGAAwG;IAClG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAKrD;IAED,KAAK,IAAI,IAAI,CAEZ;CAoDF"}
@@ -0,0 +1,180 @@
1
+ /** What a walk's acts do on the page with no call: a field filled, a button pressed, the page waited on, a table read; and a sentence with slots recorded. */
2
+ //
3
+ // Each act runs after the pointer's moves queued before it, as a person does one thing after another.
4
+ // A press is watched: a wait after it ends when the thing it waits on has changed and then stayed still a
5
+ // moment, and says it is not busy (`aria-busy`): a search answered and drawn. Or at its time. A read takes the rows of a table as a person reads them, by
6
+ // its header's words, and the row that best answers what the visitor typed, which the site's door picks;
7
+ // with nothing typed, or no answer, the first. A sentence with slots is recorded by the site's door when
8
+ // it is reached: the door reads the sentence from the agent's walks, and the page sends only the values.
9
+ import { nameOf } from "../page/roles.js";
10
+ import { framesIn, isElement } from "../pointer/frames.js";
11
+ import { press } from "../pointer/pressing.js";
12
+ import { nextOf, notesOf, rowOf, saidOf } from "../wire/ask.js";
13
+ import { filled, slotsOf, valueOf } from "../wire/index.js";
14
+ /** How long a wait waits when its step does not say, in ms. */
15
+ export const WAIT_MS = 8000;
16
+ /** How long the page must stay still after it changed for a wait to end, in ms. */
17
+ const QUIET_MS = 300;
18
+ const LOOK_MS = 100;
19
+ /** The most changes kept between a press and its wait. */
20
+ const KEPT = 500;
21
+ export class Acting {
22
+ #options;
23
+ #observer = null;
24
+ /** What changed since the press, and when. */
25
+ #changes = [];
26
+ constructor(options) {
27
+ this.#options = options;
28
+ }
29
+ /** One act of a walk, after the moves queued before it: the values a read adds. */
30
+ act(step, values, message) {
31
+ return this.#options.queued(async () => {
32
+ if ("fill" in step) {
33
+ const text = filled(step.with, values);
34
+ const field = this.#named(step.fill, ["textbox", "combobox"]);
35
+ if (text !== null && field !== null)
36
+ await this.#options.type(field, text);
37
+ return {};
38
+ }
39
+ if ("press" in step) {
40
+ const button = this.#named(step.press, ["button"]);
41
+ if (button !== null)
42
+ await this.press(button);
43
+ return {};
44
+ }
45
+ if ("wait" in step) {
46
+ await this.wait(() => this.#named(step.wait), step.ms ?? WAIT_MS);
47
+ return {};
48
+ }
49
+ return this.#read(step, message);
50
+ });
51
+ }
52
+ /** Press a button, the pointer on it first and a ring as it presses; the page is watched from now. Why it could not, or null. `forms`, a page read aloud's example, pressed in any form. */
53
+ async press(element, forms = false) {
54
+ await this.#options.point(element);
55
+ this.#options.ring();
56
+ this.#watch();
57
+ return press(element, forms);
58
+ }
59
+ /** Words typed into a field, the pointer on it: a page read aloud's example. Why it could not, or null. */
60
+ type(element, text, ms) {
61
+ return this.#options.type(element, text, ms);
62
+ }
63
+ /** Wait for `target` to change, settle and not be busy, `ms` at most: true when it did. */
64
+ wait(target, ms) {
65
+ const started = performance.now();
66
+ // A wait with no press before it watches from now.
67
+ if (this.#observer === null)
68
+ this.#watch();
69
+ const waited = new Promise((done) => {
70
+ const look = () => {
71
+ const now = performance.now();
72
+ const element = target();
73
+ const changed = element === null ? [] : this.#changes.filter((change) => element.contains(change.node));
74
+ const last = changed.at(-1)?.at ?? 0;
75
+ const busy = element?.closest("[aria-busy=true]") != null || element?.querySelector("[aria-busy=true]") != null;
76
+ if (changed.length > 0 && now - last >= QUIET_MS && !busy)
77
+ return done(true);
78
+ if (now - started >= ms)
79
+ return done(false);
80
+ setTimeout(look, LOOK_MS);
81
+ };
82
+ look();
83
+ });
84
+ return waited.finally(() => this.#stop());
85
+ }
86
+ /** A sentence with slots, recorded now by the site's door; null when it cannot be. */
87
+ async voice(path, walk, at, values) {
88
+ const step = walk.steps[at];
89
+ const door = this.#options.door;
90
+ if (door === undefined || step === undefined || !("live" in step))
91
+ return null;
92
+ const live = step;
93
+ const asked = Object.fromEntries(slotsOf(live.say).flatMap((slot) => (values[slot] === undefined ? [] : [[slot, values[slot]]])));
94
+ const said = saidOf(await door({ say: { path, walk: walk.name, step: at, values: asked } }).catch(() => null));
95
+ if (said === null)
96
+ return null;
97
+ const { live: _live, ...shown } = live;
98
+ return { ...shown, say: said.say, audio: said.audio, durationMs: said.durationMs, words: said.words };
99
+ }
100
+ /** An output explained by the site's door, the agent's model: its notes; none when the door gives none. */
101
+ async explain(request) {
102
+ const door = this.#options.door;
103
+ if (door === undefined)
104
+ return [];
105
+ return notesOf(await door({ explain: request }).catch(() => null));
106
+ }
107
+ /** The dot's next line on a chat it talks to for a goal, by the site's door; null when it gives none. */
108
+ async next(request) {
109
+ const door = this.#options.door;
110
+ if (door === undefined)
111
+ return null;
112
+ return nextOf(await door({ next: request }).catch(() => null));
113
+ }
114
+ /** A text of the page, recorded now by the site's door in the agent's voice; null when it cannot be. */
115
+ async read(text) {
116
+ const door = this.#options.door;
117
+ if (door === undefined)
118
+ return null;
119
+ const said = saidOf(await door({ read: { text } }).catch(() => null));
120
+ return said === null ? null : { say: said.say, audio: said.audio, durationMs: said.durationMs, words: said.words, beats: [] };
121
+ }
122
+ close() {
123
+ this.#stop();
124
+ }
125
+ /** The first thing of one of `roles` the page names so, on the screen or not. */
126
+ #named(name, roles) {
127
+ const ref = this.#options.page.named(name, roles);
128
+ return ref === null ? null : this.#options.page.element(ref);
129
+ }
130
+ /** The table the step names, its rows by their header's words, and one row's cells as the step's values. */
131
+ async #read(step, message) {
132
+ const named = this.#named(step.read);
133
+ const table = named === null ? null : named.matches("table") ? named : named.querySelector("table");
134
+ if (table === null)
135
+ return {};
136
+ const all = [...table.querySelectorAll("tr")];
137
+ const headers = [...(all.find((row) => row.querySelector("td") === null)?.children ?? [])].map((cell) => valueOf(cell.textContent ?? ""));
138
+ const rows = all.filter((row) => row.querySelector("td") !== null);
139
+ if (rows.length === 0)
140
+ return {};
141
+ const names = rows.map((row) => nameOf(row, "row"));
142
+ let at = 0;
143
+ if (step.row === "best" && message !== "" && this.#options.door !== undefined) {
144
+ at = rowOf(await this.#options.door({ row: { message, rows: names } }).catch(() => null)) ?? 0;
145
+ }
146
+ const row = rows[at] ?? rows[0];
147
+ if (row === undefined)
148
+ return {};
149
+ const values = { [step.as]: names[at] ?? "" };
150
+ [...row.children].forEach((cell, column) => {
151
+ const header = headers[column];
152
+ if (header !== undefined && header !== "")
153
+ values[`${step.as}.${header}`] = valueOf(cell.textContent ?? "");
154
+ });
155
+ return values;
156
+ }
157
+ /** Count what changes on the page from now, the tutor's own layer left out. */
158
+ #watch() {
159
+ this.#changes = [];
160
+ if (this.#observer !== null)
161
+ return;
162
+ const ours = (node) => (isElement(node) ? node : node.parentElement)?.closest("[data-pinecall-skip]") != null;
163
+ this.#observer = new MutationObserver((records) => {
164
+ const at = performance.now();
165
+ for (const record of records)
166
+ if (!ours(record.target))
167
+ this.#changes.push({ node: record.target, at });
168
+ this.#changes.splice(0, Math.max(0, this.#changes.length - KEPT));
169
+ });
170
+ // The page, and the pages of the site's own frames in it: a chat in a frame answers there.
171
+ for (const page of [this.#options.document, ...framesIn(this.#options.document)]) {
172
+ this.#observer.observe(page.body, { subtree: true, childList: true, characterData: true, attributes: true });
173
+ }
174
+ }
175
+ #stop() {
176
+ this.#observer?.disconnect();
177
+ this.#observer = null;
178
+ }
179
+ }
180
+ //# sourceMappingURL=acting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acting.js","sourceRoot":"","sources":["../../src/tutor/acting.ts"],"names":[],"mappings":"AAAA,8JAA8J;AAC9J,EAAE;AACF,sGAAsG;AACtG,0GAA0G;AAC1G,0JAA0J;AAC1J,yGAAyG;AACzG,yGAAyG;AACzG,yGAAyG;AAGzG,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB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ded as it is reached, the examples pressed, typed and talked to, the outputs explained; and what a reading takes from the tutor. */
2
+ import { type ExplainRequest, type NextLine, type NextRequest, type Note } from "../wire/ask.js";
3
+ import type { RecordedStep } from "../wire/index.js";
4
+ import type { Acting } from "./acting.js";
5
+ import { type Reading } from "./reading.js";
6
+ /** What reading a page takes from the tutor. */
7
+ export interface ReadingOptions {
8
+ /** A text recorded in the agent's voice, by the site's door; null when it was not. */
9
+ record: (text: string) => Promise<RecordedStep | null>;
10
+ /** The part being read lit and pointed at, the rest dimmed; null puts the light out. */
11
+ light: (element: Element | null) => void;
12
+ /** An example pressed, and what it controls waited on until it answered. */
13
+ press: (element: Element) => Promise<void>;
14
+ /** The page's own example typed into a field, the pointer on it; paced to `ms`, the recording said meanwhile. */
15
+ type?: ((element: Element, text: string, ms?: number) => Promise<void>) | undefined;
16
+ /** An output explained by the site's door: notes on its lines; none when the door gives none. */
17
+ explain?: ((request: ExplainRequest) => Promise<Note[]>) | undefined;
18
+ /** The dot's next line on a chat it talks to for a goal, by the site's door; null when it gives none. */
19
+ next?: ((request: NextRequest) => Promise<NextLine | null>) | undefined;
20
+ /** A chat talked to opened before its first line: its field focused, and its output waited on while it says it is busy (a greeting coming). */
21
+ open?: ((field: Element, output: Element) => Promise<void>) | undefined;
22
+ /** A spoken call's output waited on while it says it is busy: the agent answering what the dot said into it. */
23
+ settle?: ((output: Element) => Promise<void>) | undefined;
24
+ }
25
+ /** One reading under way: each part recorded when it is reached, the next one asked for while one plays. */
26
+ export declare class ReadAloud {
27
+ #private;
28
+ readonly reading: Reading;
29
+ constructor(reading: Reading, options: ReadingOptions);
30
+ /** The `at`th step recorded, and the next sentence asked for, so it is there when this one ends; a note whose line is not in the output, none. */
31
+ voice(at: number): Promise<RecordedStep | null>;
32
+ /** The `at`th step, an example: typed into a field; a turn of a talk; or pressed, waited on, and its output explained by the door when the page notes nothing on it. */
33
+ act(at: number): Promise<void>;
34
+ /** The `at`th step starts: its part lit and pointed at, an output's line by its note; -1, the reading is over. */
35
+ shows(at: number): void;
36
+ }
37
+ /** How long a part that could not be recorded waits before it is asked again, each time, in ms: a door that just came up (a machine booting) answers within these. */
38
+ export declare const RECORD_AGAIN_MS: number[];
39
+ /**
40
+ * What a reading takes, from the tutor's acts and moves: each part recorded by the site's door, the part read
41
+ * lit and pointed at (`light`), and an example pressed, then what it controls (its output) waited on until it
42
+ * answered and is not busy.
43
+ */
44
+ export declare function readingWith(title: string, acting: Acting, moves: {
45
+ light: (element: Element | null) => void;
46
+ queued: <T>(work: () => Promise<T>) => Promise<T>;
47
+ }): {
48
+ title: string;
49
+ } & ReadingOptions;
50
+ //# sourceMappingURL=aloud.d.ts.map