@graview/tools 0.1.63 → 0.1.65
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/dist/ai.d.ts +19 -0
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js.map +1 -1
- package/dist/dev-ai.d.ts +4 -0
- package/dist/dev-ai.d.ts.map +1 -1
- package/dist/dev-ai.js +104 -8
- package/dist/dev-ai.js.map +1 -1
- package/dist/draft.d.ts +1 -0
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +2 -0
- package/dist/draft.js.map +1 -1
- package/dist/facts.d.ts +24 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +48 -0
- package/dist/facts.js.map +1 -0
- package/dist/graph-plan.d.ts +178 -0
- package/dist/graph-plan.d.ts.map +1 -0
- package/dist/graph-plan.js +570 -0
- package/dist/graph-plan.js.map +1 -0
- package/dist/inline-ai.d.ts +41 -2
- package/dist/inline-ai.d.ts.map +1 -1
- package/dist/inline-ai.js +423 -12
- package/dist/inline-ai.js.map +1 -1
- package/dist/reshape.d.ts +55 -2
- package/dist/reshape.d.ts.map +1 -1
- package/dist/reshape.js +2 -0
- package/dist/reshape.js.map +1 -1
- package/dist/say-change.d.ts +59 -0
- package/dist/say-change.d.ts.map +1 -0
- package/dist/say-change.js +156 -0
- package/dist/say-change.js.map +1 -0
- package/dist/section.d.ts +120 -0
- package/dist/section.d.ts.map +1 -0
- package/dist/section.js +351 -0
- package/dist/section.js.map +1 -0
- package/dist/sentences.d.ts +13 -0
- package/dist/sentences.d.ts.map +1 -0
- package/dist/sentences.js +30 -0
- package/dist/sentences.js.map +1 -0
- package/dist/suggest.js +2 -2
- package/dist/suggest.js.map +1 -1
- package/dist/workflows/run-agent.d.ts.map +1 -1
- package/dist/workflows/run-agent.js +8 -4
- package/dist/workflows/run-agent.js.map +1 -1
- package/dist/workflows/run-classify.d.ts.map +1 -1
- package/dist/workflows/run-classify.js +22 -9
- package/dist/workflows/run-classify.js.map +1 -1
- package/dist/workflows/run.d.ts +1 -1
- package/dist/workflows/run.d.ts.map +1 -1
- package/dist/workflows/run.js +40 -2
- package/dist/workflows/run.js.map +1 -1
- package/dist/workflows/types.d.ts +51 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/types.js +2 -1
- package/dist/workflows/types.js.map +1 -1
- package/dist/workflows.d.ts +2 -1
- package/dist/workflows.d.ts.map +1 -1
- package/dist/workflows.js +1 -0
- package/dist/workflows.js.map +1 -1
- package/package.json +7 -3
package/dist/inline-ai.js
CHANGED
|
@@ -33,9 +33,14 @@
|
|
|
33
33
|
* when the inline AI is first opened: a page whose reader never right-
|
|
34
34
|
* clicks carries none of it.
|
|
35
35
|
*/
|
|
36
|
-
import { labelOf, pluralOf, recordFriction } from "@graview/core";
|
|
36
|
+
import { argumentsTaken, labelOf, pluralOf, recordFriction } from "@graview/core";
|
|
37
37
|
import { aiContextOf, catalogOf, } from "@graview/core/catalog";
|
|
38
38
|
import { firstJsonObject } from "./intelligence.js";
|
|
39
|
+
import { COULD_NOT_WORK_OUT, forThePerson } from "./sentences.js";
|
|
40
|
+
import { factsOf, todayWords } from "./facts.js";
|
|
41
|
+
import { CANNOT_DO_IT, claimedAbsent, sayChange, sayNothingToChange, saysDone } from "./say-change.js";
|
|
42
|
+
export { COULD_NOT_WORK_OUT, forThePerson, plainly } from "./sentences.js";
|
|
43
|
+
import { askedParts, asking, barFor, decideOverTheGraph, heldBy, outsideVerb, outsideWords, peopleKinds, explicitReading, removing, unaccounted, UNDOING, effectOf } from "./graph-plan.js";
|
|
39
44
|
import { JEV_INPUT_USD_PER_MILLION, JEV_MODEL, jevDecide } from "./providers/jev.js";
|
|
40
45
|
// ── the slots ───────────────────────────────────────────────────────────────
|
|
41
46
|
/** The Fast slot as the host filled it, else its `decide` behind it. */
|
|
@@ -396,7 +401,9 @@ export async function panelHere(ai, ask) {
|
|
|
396
401
|
export function answerOf(ai) {
|
|
397
402
|
return ai.off ? undefined : ai.answer;
|
|
398
403
|
}
|
|
399
|
-
const ANSWER_SYSTEM = 'You answer a person
|
|
404
|
+
const ANSWER_SYSTEM = 'You answer a person who typed words about what they are looking at in an app, from the state given and nothing else: "facts" says the fields and links of each record ("covered by Ada Nowak", "holds it: This week"), as they see them — answer from them, and never say a record has no link the facts show. Before answering, look through "facts" for the link or field the words are about — what it waits for, who covers it, what holds it, when it is due — and name it: "what is blocking this" is answered by its "waits for" links, by name. A link the facts do not show is not there: say plainly that there is none, never borrow one from another record, and answer what was asked — a count by counting, a day by its day. Answer only JSON: {"answer": one to three short, whole sentences written to the person, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person. ' +
|
|
405
|
+
'Where "members" are given and the person asks for something done to them, answer "each": {"act": the name of one of "member_acts", "args": every value it asks for, by name, dates as YYYY-MM-DD counted from "today"; the facts already say each day against today, so trust those} — one act over every member, as one change. Judge an act by what it does ("does"), not only its title: "close", "complete", "check off", "tick" and "finish" are an act that marks something done; "delete" one that removes; "push", "move" and "postpone" one that changes a date or a place. Where "fast_leaned_to" names an act, it is likely the one: fill its values. When the person tells it to do something, answer "each" (with a short "answer" saying what it will do): nothing is done until they accept, so never say in words that it is done, and never ask them to confirm ("Move it to Friday?"): the card asks them, so answer "each". Where "people" maps a word like "her" or "me" to a name, that is who they mean. ' +
|
|
406
|
+
'Only where no act among "member_acts" or the candidates does what they ask, because the app has no field or link for it, answer "lacks": one whole sentence to the person saying what the app is missing (never an id, never a note to yourself), and "need": what it would need — {"link": {"on": the kind of the records, "called": what the link is called in their words, like "assigned to", "to": the kind it points to, or a noun for one the app lacks}} or {"field": {"on": the kind, "called": its name in their words, "type": "string", "number", "date" or "boolean"}} — with "who": the name of the record their words name (for a link) or "value": the value they give (for a field). When they ask for a change the app has no field or link for ("make these urgent", "give these a priority"), answer "lacks" and "need", never only "answer". A question is answered in "answer", never with "each" or "lacks"; so is "undo that", which the app\'s own Undo does.';
|
|
400
407
|
/**
|
|
401
408
|
* WORDS ASKED ABOUT WHAT THE PERSON IS ON (the quick ask): answered in a
|
|
402
409
|
* few sentences, with the catalog's candidates that act on the answer —
|
|
@@ -407,12 +414,103 @@ const ANSWER_SYSTEM = 'You answer a person\'s question about what they are looki
|
|
|
407
414
|
* follow-up carries the ask before it and its answer, and nothing older.
|
|
408
415
|
*/
|
|
409
416
|
export async function answerHere(ai, ask) {
|
|
410
|
-
const
|
|
417
|
+
const begun0 = begin(ai, ask);
|
|
411
418
|
const said = ask.said.trim();
|
|
412
|
-
const choices = asked.catalog.candidates.filter((candidate) => ready(candidate) || candidate.type === "panel" || candidate.type === "place" || candidate.type === "record").slice(0, 32);
|
|
413
419
|
const host = answerOf(ai);
|
|
414
|
-
const thinking = thinkingOf(ai);
|
|
415
420
|
const fast = fastOf(ai);
|
|
421
|
+
/* Each stage timed, as the entry keeps it: the Fast slot's pick, the light and the full model's words. */
|
|
422
|
+
const stages = [];
|
|
423
|
+
const timed = async (stage, model, work) => {
|
|
424
|
+
const from = Date.now();
|
|
425
|
+
try {
|
|
426
|
+
return await work();
|
|
427
|
+
}
|
|
428
|
+
finally {
|
|
429
|
+
stages.push({ stage, ms: Date.now() - from, model });
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const begun = { ...begun0, entry: begun0.entry };
|
|
433
|
+
/*
|
|
434
|
+
* THE GRAPH FIRST (Roadmap f-menu-type-anything): on what holds records —
|
|
435
|
+
* a record that holds others, a list, a place — the Fast slot decides in
|
|
436
|
+
* one typed call which records the words mean, which act, which person,
|
|
437
|
+
* and what the app would need; code composes the answer. Sure, no model
|
|
438
|
+
* writes a word. Unsure, the reading it made still narrows what the
|
|
439
|
+
* Thinking slot is told.
|
|
440
|
+
*/
|
|
441
|
+
let reading;
|
|
442
|
+
let leaned;
|
|
443
|
+
// Asks or tells, as Jev read it; the code's patterns only where Jev was not asked.
|
|
444
|
+
let asksJev;
|
|
445
|
+
let taken;
|
|
446
|
+
if (fast && said && !host && (ask.target.on === "record" || ask.target.on === "list" || ask.target.on === "lens" || ask.target.on === "selection")) {
|
|
447
|
+
try {
|
|
448
|
+
const deciding = (words) => decideOverTheGraph(fast, { store: ask.store, target: ask.target, said: words, ...(ask.principal.id ? { principal: { id: ask.principal.id } } : {}), ...(ask.members ? { members: ask.members } : {}), ...(ask.follows ? { follows: ask.follows } : {}), ...(ask.where ? { where: ask.where } : {}), ...(ask.examples ? { examples: ask.examples } : {}) });
|
|
449
|
+
/* TWO ASKS IN ONE SENTENCE ("archive the done ones, then close the rest"): one plan of two parts, each part read on its own — its own records, its own act — decided together. */
|
|
450
|
+
const parts = askedParts(said);
|
|
451
|
+
if (parts.length > 1) {
|
|
452
|
+
const several = await timed("fast", fast.model, () => Promise.all(parts.map(deciding)));
|
|
453
|
+
for (const one of several) {
|
|
454
|
+
const cost = costOf(fast.price, one.usage.inputTokens, one.usage.outputTokens);
|
|
455
|
+
begun.meter({ tier: "fast", model: fast.model, inputTokens: one.usage.inputTokens, outputTokens: one.usage.outputTokens, ...(cost !== undefined ? { costUsd: cost } : {}) });
|
|
456
|
+
}
|
|
457
|
+
if (several.every((one) => one.sure && one.each && !one.asks))
|
|
458
|
+
return graphResult(ask, begun, said, several, stages);
|
|
459
|
+
}
|
|
460
|
+
const graph = await timed("fast", fast.model, () => deciding(said));
|
|
461
|
+
const cost = costOf(fast.price, graph.usage.inputTokens, graph.usage.outputTokens);
|
|
462
|
+
begun.meter({ tier: "fast", model: fast.model, inputTokens: graph.usage.inputTokens, outputTokens: graph.usage.outputTokens, ...(cost !== undefined ? { costUsd: cost } : {}) });
|
|
463
|
+
reading = graph.reading;
|
|
464
|
+
leaned = graph.act;
|
|
465
|
+
asksJev = graph.asks;
|
|
466
|
+
taken = graph.taken;
|
|
467
|
+
if (graph.sure && (graph.each || graph.missing || graph.clarify || graph.outside))
|
|
468
|
+
return graphResult(ask, begun, said, graph, stages);
|
|
469
|
+
}
|
|
470
|
+
catch {
|
|
471
|
+
// The Fast slot failing leaves the Thinking slot to answer, as before there was a graph to read.
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const isQuestion = () => asksJev ?? asking(said);
|
|
475
|
+
/* THE LIGHT MODEL FIRST: the provider's quick one words an open answer; the full one only where it had none. */
|
|
476
|
+
const light = ai.off ? undefined : ai.light;
|
|
477
|
+
const full = thinkingOf(ai);
|
|
478
|
+
const thinking = light ?? full;
|
|
479
|
+
const all = begun.catalog.candidates.filter((candidate) => ready(candidate) || candidate.type === "panel" || candidate.type === "place" || candidate.type === "record").slice(0, 32);
|
|
480
|
+
/*
|
|
481
|
+
* TWO STEPS (Roadmap f-menu-type-anything): where a model will write the
|
|
482
|
+
* answer and a Fast slot is given, the Fast slot first picks the context
|
|
483
|
+
* that matters to the words — which of the catalog's candidates, which
|
|
484
|
+
* records around the target — and only that reaches the model that
|
|
485
|
+
* answers; with no Fast slot, the default the target is scoped to. Either
|
|
486
|
+
* way the entry says what was sent.
|
|
487
|
+
*/
|
|
488
|
+
let sent;
|
|
489
|
+
try {
|
|
490
|
+
sent = fast && (host || thinking) && said ? await contextPicked(fast, said, begun, all) : defaultContext(begun, all);
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
return failedResult(begun, said, "ask", error instanceof Error ? error.message : String(error));
|
|
494
|
+
}
|
|
495
|
+
const asked = { ...begun, state: sent.state, catalog: { ...begun.catalog, candidates: sent.choices }, entry: { ...begun.entry, context: sent.context } };
|
|
496
|
+
const choices = sent.choices;
|
|
497
|
+
/* The records the words are about — as the Fast slot read them, else the records the list shows — and the acts any of them takes. */
|
|
498
|
+
const members = (reading?.records ?? ask.members ?? []).flatMap((id) => {
|
|
499
|
+
const node = ask.store.graph.getNode(id);
|
|
500
|
+
return node ? [node] : [];
|
|
501
|
+
}).slice(0, 60);
|
|
502
|
+
const memberKinds = new Set(members.map((node) => node.kind));
|
|
503
|
+
const memberActs = ask.store.allMutations().flatMap((mutation) => {
|
|
504
|
+
const kinds = mutation.subject?.kinds;
|
|
505
|
+
if (!mutation.subject || !(kinds === "*" || kinds.some((kind) => memberKinds.has(kind))))
|
|
506
|
+
return [];
|
|
507
|
+
const kind = [...memberKinds].find((one) => kinds === "*" || kinds.includes(one));
|
|
508
|
+
return [{ name: mutation.name, title: mutation.title ?? mutation.name, does: `${mutation.description ?? ""} ${effectOf(mutation, ask.store.schema, kind)}`.trim(), subjectArg: mutation.subject.arg, asks: (argumentsTaken(mutation) ?? []).filter((arg) => arg !== mutation.subject.arg) }];
|
|
509
|
+
});
|
|
510
|
+
let each;
|
|
511
|
+
let missing;
|
|
512
|
+
// What the model was told, kept to ask it again.
|
|
513
|
+
let promptOf;
|
|
416
514
|
let text = "";
|
|
417
515
|
let picked = [];
|
|
418
516
|
const pickedOf = (ids) => ids.flatMap((id) => choices.filter((candidate) => candidate.id === id)).slice(0, 3).map((candidate) => ({ candidate }));
|
|
@@ -427,9 +525,84 @@ export async function answerHere(ai, ask) {
|
|
|
427
525
|
picked = pickedOf(reply.pick ?? []);
|
|
428
526
|
}
|
|
429
527
|
else if (thinking) {
|
|
430
|
-
const
|
|
528
|
+
const prompt = JSON.stringify({
|
|
529
|
+
ask: said,
|
|
530
|
+
about: asked.entry.targetLabel,
|
|
531
|
+
...(ask.follows ? { follows: ask.follows } : {}),
|
|
532
|
+
// Like tellings that worked (Roadmap f-menu-learns), said only when there are some: the instructions are otherwise unchanged.
|
|
533
|
+
...(ask.examples && ask.examples.length > 0 ? { worked_before: ask.examples, worked_before_is: "What people of this app asked before and what was done that they kept: where these words mean the same, do the same." } : {}),
|
|
534
|
+
state: asked.state,
|
|
535
|
+
candidates: choices.map((candidate) => ({ id: candidate.id, says: candidate.description })),
|
|
536
|
+
// What is true of the records the words are about, as this person sees them: an open answer is only as true as this.
|
|
537
|
+
// The record, the records the words were read as, and — whatever the reading — what the record holds: a question about a list is answered from its records.
|
|
538
|
+
facts: factsOf(ask.store, ask.principal, [...new Set([...(ask.target.on === "record" ? [ask.target.id, ...(heldBy(ask.store, ask.target.id)?.ids ?? [])] : []), ...members.map((node) => node.id), ...(ask.members ?? [])])], todayOf(ask.store)),
|
|
539
|
+
...(members.length > 0 ? { members: members.map((node) => ({ id: node.id, label: labelOf(ask.store.schema.tryDefinition(node.kind), node) })), member_acts: memberActs.map((act) => ({ name: act.name, title: act.title, does: act.does, asks: act.asks })) } : {}),
|
|
540
|
+
...(leaned ? { fast_leaned_to: leaned } : {}),
|
|
541
|
+
...(taken ? { people: { [taken.said]: taken.as } } : {}),
|
|
542
|
+
// Everyone in the app, by name — not who is linked to this record: an answer never says someone is not in the app while they are.
|
|
543
|
+
everyone_in_the_app: peopleKinds(ask.store).flatMap((kind) => ask.store.graph.allNodes().filter((node) => node.kind === kind)).slice(0, 40).map((node) => labelOf(ask.store.schema.tryDefinition(node.kind), node)),
|
|
544
|
+
...(todayOf(ask.store) ? { today: todayWords(todayOf(ask.store)) } : {}),
|
|
545
|
+
});
|
|
546
|
+
promptOf = prompt;
|
|
547
|
+
const usable = (one) => Boolean(one && ((typeof one.answer === "string" && one.answer.trim()) || (Array.isArray(one.pick) && one.pick.length > 0) || one.each || one.lacks));
|
|
548
|
+
let parsed = (await timed(light ? "light" : "thinking", thinking.model, () => thought(thinking, ANSWER_SYSTEM, prompt, asked, asked.meter)));
|
|
549
|
+
// The light model had nothing to say: the full one, once.
|
|
550
|
+
if (light && full && full !== light && !usable(parsed))
|
|
551
|
+
parsed = (await timed("thinking", full.model, () => thought(full, ANSWER_SYSTEM, prompt, asked, asked.meter)));
|
|
552
|
+
// Told to do something, it only talked: asked once more for the change, or for what the app lacks.
|
|
553
|
+
const told = !isQuestion() && !UNDOING.test(said) && members.length > 0;
|
|
554
|
+
const proposes = (ids) => Array.isArray(ids) && ids.some((id) => { const candidate = choices.find((one) => one.id === id); return candidate !== undefined && proposalOf(candidate) !== undefined; });
|
|
555
|
+
if (told && parsed && !parsed.each && !parsed.lacks && !proposes(parsed.pick)) {
|
|
556
|
+
const again = (await timed(light ? "light" : "thinking", thinking.model, () => thought(thinking, ANSWER_SYSTEM, JSON.stringify({ ...JSON.parse(prompt), told: "They told you to do this, not asked a question. Reply with exactly one of two shapes, never \"answer\" alone: \"each\" with an act from member_acts and its values, or \"lacks\" and \"need\" (and \"value\") where no act can — for example {\"lacks\": \"Tasks have no priority yet.\", \"need\": {\"field\": {\"on\": \"task\", \"called\": \"priority\", \"type\": \"string\"}}, \"value\": \"high\"}." }), asked, asked.meter)));
|
|
557
|
+
if (again && (again.each || again.lacks))
|
|
558
|
+
parsed = again;
|
|
559
|
+
// Still only words: the act Jev leaned to, where it needs no value it was not given — never words in place of the change.
|
|
560
|
+
else if (leaned) {
|
|
561
|
+
const lean = memberActs.find((one) => one.name === leaned);
|
|
562
|
+
const required = lean ? ask.store.allMutations().find((one) => one.name === lean.name)?.input?.shape ?? {} : {};
|
|
563
|
+
if (lean && lean.asks.every((arg) => required[arg]?.safeParse(undefined).success ?? true))
|
|
564
|
+
parsed = { ...parsed, answer: "", each: { act: lean.name, args: {} } };
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
// Told to do something and answered with one act over the records: the other changes it picked are not what was asked.
|
|
568
|
+
if (!isQuestion() && parsed?.each)
|
|
569
|
+
parsed = { ...parsed, pick: Array.isArray(parsed.pick) ? parsed.pick.filter((id) => { const candidate = choices.find((one) => one.id === id); return candidate !== undefined && proposalOf(candidate) === undefined; }) : parsed.pick };
|
|
570
|
+
// Asked a question: answered in words, never a change made over every record.
|
|
571
|
+
if (isQuestion() && parsed)
|
|
572
|
+
parsed = { ...parsed, each: undefined };
|
|
573
|
+
// An answer that is not whole sentences — a fragment, a list — is asked for once more, as sentences to the person.
|
|
574
|
+
if (parsed && typeof parsed.answer === "string" && parsed.answer.trim() && !forThePerson(parsed.answer) && !parsed.each && !parsed.lacks) {
|
|
575
|
+
const again = (await timed(light ? "light" : "thinking", thinking.model, () => thought(thinking, ANSWER_SYSTEM, JSON.stringify({ ...JSON.parse(prompt), rewrite: `Your answer was not whole sentences: “${String(parsed.answer).slice(0, 300)}”. Say it again in one to three whole sentences to the person, each begun with a capital and ended with a full stop.` }), asked, asked.meter)));
|
|
576
|
+
if (again && typeof again.answer === "string" && forThePerson(again.answer))
|
|
577
|
+
parsed = { ...parsed, answer: again.answer };
|
|
578
|
+
// A question answered by name ("Pay the deposit"): the names are the answer, said as one sentence.
|
|
579
|
+
else if (isQuestion() && /^[\p{L}\p{N}"“'(][^{}[\]]*$/u.test(String(parsed.answer).trim()) && String(parsed.answer).trim().split(/\s+/).length >= 2)
|
|
580
|
+
parsed = { ...parsed, answer: `${String(parsed.answer).trim().charAt(0).toUpperCase()}${String(parsed.answer).trim().slice(1).replace(/[\s,;:]+$/, "")}.` };
|
|
581
|
+
}
|
|
582
|
+
// A question answered with no words at all (a change picked, nothing said): asked once more, for the answer.
|
|
583
|
+
if (isQuestion() && parsed && !(typeof parsed.answer === "string" && parsed.answer.trim())) {
|
|
584
|
+
const again = (await timed(light ? "light" : "thinking", thinking.model, () => thought(thinking, ANSWER_SYSTEM, JSON.stringify({ ...JSON.parse(prompt), rewrite: "This is a question: answer it in \"answer\", in one to three whole sentences, from the facts." }), asked, asked.meter)));
|
|
585
|
+
if (again && typeof again.answer === "string" && forThePerson(again.answer))
|
|
586
|
+
parsed = { ...parsed, answer: again.answer };
|
|
587
|
+
}
|
|
431
588
|
text = typeof parsed?.answer === "string" ? parsed.answer.trim() : "";
|
|
432
589
|
picked = pickedOf(Array.isArray(parsed?.pick) ? parsed.pick : []);
|
|
590
|
+
each = eachOf(parsed?.each);
|
|
591
|
+
// Words that are not a sentence for the person — a fragment, a note — are said plainly instead.
|
|
592
|
+
if (text && !forThePerson(text))
|
|
593
|
+
text = each ? "" : COULD_NOT_WORK_OUT;
|
|
594
|
+
if (typeof parsed?.lacks === "string" && parsed.lacks.trim()) {
|
|
595
|
+
const need = needOf(parsed.need);
|
|
596
|
+
// The model's note to the pipeline is never shown as it came: a whole sentence for the person, or one code says from the need.
|
|
597
|
+
const lacks = parsed.lacks.trim();
|
|
598
|
+
const lacksSaid = forThePerson(lacks) ? lacks : need ? lacksOf(ask.store.schema, need) : COULD_NOT_WORK_OUT;
|
|
599
|
+
missing = {
|
|
600
|
+
said: lacksSaid,
|
|
601
|
+
...(need ? { need } : {}),
|
|
602
|
+
...(typeof parsed.who === "string" && parsed.who.trim() ? { who: parsed.who.trim() } : {}),
|
|
603
|
+
...(typeof parsed.value === "string" || typeof parsed.value === "number" ? { value: String(parsed.value) } : {}),
|
|
604
|
+
};
|
|
605
|
+
}
|
|
433
606
|
}
|
|
434
607
|
else if (fast && choices.length > 0) {
|
|
435
608
|
const { question, of } = choiceAmong(choices, `Which of these best answers, or acts on: ${said}`);
|
|
@@ -443,7 +616,36 @@ export async function answerHere(ai, ask) {
|
|
|
443
616
|
catch (error) {
|
|
444
617
|
return failedResult(asked, said, "ask", error instanceof Error ? error.message : String(error));
|
|
445
618
|
}
|
|
446
|
-
|
|
619
|
+
/*
|
|
620
|
+
* NEVER A CHANGE CLAIMED THAT WAS NOT MADE. Told to do something, with no
|
|
621
|
+
* change proposed, no plan and nothing picked, the model's words may not
|
|
622
|
+
* say it is done ("X is taken off the shift."): said plainly that it
|
|
623
|
+
* could not be done here instead.
|
|
624
|
+
*/
|
|
625
|
+
/* NEVER SOMETHING FALSE ABOUT THE APP: an answer that says someone or something here is absent is asked for again with who is here, and else said truly by code. */
|
|
626
|
+
for (const words of [text, missing?.said ?? ""]) {
|
|
627
|
+
const absent = words ? claimedAbsent(ask.store, words) : [];
|
|
628
|
+
if (absent.length === 0 || !thinking)
|
|
629
|
+
continue;
|
|
630
|
+
const here = absent.map((one) => `${one.name} (${pluralOf(ask.store.schema, one.kind).toLowerCase()})`).join(", ");
|
|
631
|
+
const again = (await timed(light ? "light" : "thinking", thinking.model, () => thought(thinking, ANSWER_SYSTEM, JSON.stringify({ ...JSON.parse(promptOf ?? "{}"), known: `These are in the app: ${here}. Never say they are not.` }), asked, asked.meter)));
|
|
632
|
+
const retold = typeof again?.answer === "string" ? again.answer.trim() : "";
|
|
633
|
+
const fixed = retold && forThePerson(retold) && claimedAbsent(ask.store, retold).length === 0 ? retold : `${absent[0].name} is here, one of its ${pluralOf(ask.store.schema, absent[0].kind).toLowerCase()}. Try saying it another way.`;
|
|
634
|
+
if (words !== text)
|
|
635
|
+
missing = undefined;
|
|
636
|
+
text = fixed;
|
|
637
|
+
}
|
|
638
|
+
// Outside the app ("email this", "text Sam"): said plainly, never a field to add.
|
|
639
|
+
if (!isQuestion() && outsideVerb(said) && !/\b(field|link|column)\b/i.test(said)) {
|
|
640
|
+
missing = undefined;
|
|
641
|
+
each = undefined;
|
|
642
|
+
picked = [];
|
|
643
|
+
text = outsideWords(ask.store, said, ask.target.on === "record" ? ask.target.id : undefined);
|
|
644
|
+
}
|
|
645
|
+
const changed = Boolean(each) || picked.some(({ candidate }) => proposalOf(candidate) !== undefined);
|
|
646
|
+
if (!isQuestion() && !changed && !missing && text && saysDone(text))
|
|
647
|
+
text = CANNOT_DO_IT;
|
|
648
|
+
if (!text && picked.length === 0 && !each && !missing) {
|
|
447
649
|
// The seat could not answer (Roadmap f-friction-log): the question, and the place it was asked on. A provider that failed is not this.
|
|
448
650
|
const place = ask.target.on === "place" || ask.target.on === "lens" ? ask.target.place : undefined;
|
|
449
651
|
const kind = ask.target.on === "list" ? ask.target.kind : ask.target.on === "lens" ? ask.target.kind : undefined;
|
|
@@ -451,21 +653,165 @@ export async function answerHere(ai, ask) {
|
|
|
451
653
|
return failedResult(asked, said, "ask", "The AI had no answer to that here.");
|
|
452
654
|
}
|
|
453
655
|
const model = asked.usage.at(-1)?.model;
|
|
656
|
+
/*
|
|
657
|
+
* A QUESTION NEVER COMES WITH A CHANGE. Answered in words, any act it
|
|
658
|
+
* picked is offered beside the answer as a suggestion the person chooses
|
|
659
|
+
* ("Mark it done?"), never proposed as the card's change.
|
|
660
|
+
*/
|
|
661
|
+
const question = isQuestion();
|
|
662
|
+
/* A destructive act over several, from words that did not say which: asked back, not proposed. */
|
|
663
|
+
const eachAct = each ? ask.store.allMutations().find((one) => one.name === each.act) : undefined;
|
|
664
|
+
if (eachAct && removing(eachAct) && members.length > 1 && (reading ? (reading.chance ?? 1) < barFor(eachAct, said) || unaccounted(said, reading) : !explicitReading(said))) {
|
|
665
|
+
const clarify = `Should I ${(eachAct.title ?? eachAct.name).trim().split(/\s+/)[0].toLowerCase()} all ${members.length} of them? Say “all” to go ahead, or say which.`;
|
|
666
|
+
return { interaction: { ...asked.entry, ask: { kind: "ask", said }, offered: [], outcome: "offered", answer: clarify, usage: [...asked.usage], stages }, offers: [], answer: clarify, ...(reading ? { reading } : {}) };
|
|
667
|
+
}
|
|
454
668
|
// A change picked is a proposal, previewed as the person: never made until it is accepted.
|
|
455
|
-
const proposals = picked.flatMap(({ candidate, confidence }) => {
|
|
669
|
+
const proposals = (question ? [] : picked).flatMap(({ candidate, confidence }) => {
|
|
456
670
|
const proposal = proposalOf(candidate);
|
|
457
671
|
return proposal ? [{ ...proposal, ...(confidence !== undefined ? { confidence } : {}) }] : [];
|
|
458
672
|
});
|
|
459
|
-
|
|
460
|
-
|
|
673
|
+
/*
|
|
674
|
+
* ONE ACT OVER EVERY RECORD THE LIST SHOWS, AS ONE CHANGE: a proposal for
|
|
675
|
+
* each, previewed as the person, accepted together and taken back with one
|
|
676
|
+
* undo; one the store would refuse them is left out, as any ghost's.
|
|
677
|
+
*/
|
|
678
|
+
const act = each ? memberActs.find((one) => one.name === each.act) : undefined;
|
|
679
|
+
if (act) {
|
|
680
|
+
for (const node of members) {
|
|
681
|
+
const mutation = ask.store.allMutations().find((one) => one.name === act.name);
|
|
682
|
+
const kinds = mutation?.subject?.kinds;
|
|
683
|
+
if (!mutation || !(kinds === "*" || kinds.includes(node.kind)))
|
|
684
|
+
continue;
|
|
685
|
+
proposals.push({ id: `each:${act.name}:${node.id}`, label: `${act.title}: ${labelOf(ask.store.schema.tryDefinition(node.kind), node)}`, said: act.title, call: { name: act.name, args: { ...each.args, [act.subjectArg]: node.id } }, record: node.id });
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
// One change to a record once: an act over every member and a candidate that is the same act on one of them are one proposal.
|
|
689
|
+
const once = proposals.filter((proposal, index) => proposals.findIndex((other) => other.call.name === proposal.call.name && JSON.stringify(other.call.args) === JSON.stringify(proposal.call.args)) === index);
|
|
690
|
+
const ghost = once.length > 0 ? ghostOf(ask.store, { interaction: asked.id, target: ask.target, basis: said, ...(model ? { model } : {}), proposals: once }, ask.principal) : undefined;
|
|
691
|
+
const offers = picked.map(({ candidate }) => candidate).filter((candidate) => question || proposalOf(candidate) === undefined);
|
|
692
|
+
// Changes the model picked one by one, for an instruction: each said as it will happen, in the app's words, never the model's.
|
|
693
|
+
if (!each && !question && ghost && ghost.proposals.length > 0) {
|
|
694
|
+
text = ghost.proposals
|
|
695
|
+
.slice(0, 3)
|
|
696
|
+
.flatMap((proposal) => {
|
|
697
|
+
const mutation = ask.store.allMutations().find((one) => one.name === proposal.call.name);
|
|
698
|
+
const record = mutation?.subject ? proposal.call.args[mutation.subject.arg] : undefined;
|
|
699
|
+
return mutation && typeof record === "string" ? [sayChange(ask.store, { act: mutation, args: proposal.call.args, records: [record], itself: true })] : [];
|
|
700
|
+
})
|
|
701
|
+
.join(" ");
|
|
702
|
+
}
|
|
703
|
+
// The change said as it will happen, its values and its records counted as the ghost keeps them: not the model's words for it.
|
|
704
|
+
if (each && eachAct && ghost) {
|
|
705
|
+
const acting = members.map((node) => node.id).filter((id) => ghost.proposals.some((proposal) => proposal.id === `each:${eachAct.name}:${id}`));
|
|
706
|
+
if (acting.length > 0)
|
|
707
|
+
text = changeWords(ask.store, eachAct, each.args, acting, reading ?? (members.length === 1 && ask.target.on === "record" && members[0].id === ask.target.id ? { which: "itself", records: acting, kind: members[0].kind, words: "", close: false } : undefined));
|
|
708
|
+
}
|
|
461
709
|
const offered = [...offers.map((candidate) => offeredOf(candidate, picked.find((one) => one.candidate === candidate)?.confidence)), ...(ghost?.proposals ?? []).map((proposal) => ({ id: proposal.id, type: (proposal.field !== undefined ? "fill" : "act"), label: proposal.label, ...(proposal.confidence !== undefined ? { confidence: proposal.confidence } : {}) }))];
|
|
462
710
|
return {
|
|
463
|
-
interaction: { ...asked.entry, ask: { kind: "ask", said }, offered, outcome: "offered", ...(text ? { answer: text } : {}), usage: [...asked.usage] },
|
|
711
|
+
interaction: { ...asked.entry, ask: { kind: "ask", said }, offered, outcome: "offered", ...(text ? { answer: text } : {}), usage: [...asked.usage], stages },
|
|
464
712
|
offers,
|
|
465
713
|
...(ghost && ghost.proposals.length > 0 ? { ghost } : {}),
|
|
714
|
+
...(text ? { answer: text } : missing ? { answer: missing.said } : {}),
|
|
715
|
+
...(missing ? { missing: missing.need && reading && "link" in missing.need ? { ...missing, need: { link: { ...missing.need.link, on: reading.kind } } } : missing } : {}),
|
|
716
|
+
...(reading ? { reading } : {}),
|
|
717
|
+
...(taken ? { taken } : {}),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
/** A change in words, from its act, its values and the records it will act on (`sayChange`), with what the reading narrowed them by. */
|
|
721
|
+
function changeWords(store, act, args, records, reading) {
|
|
722
|
+
const narrowed = reading?.part;
|
|
723
|
+
const where = reading ? / (in .+)$/.exec(reading.words)?.[1] : undefined;
|
|
724
|
+
return sayChange(store, { act, args, records, ...(narrowed ? { narrowed } : {}), ...(where ? { where } : {}), itself: reading?.which === "itself" });
|
|
725
|
+
}
|
|
726
|
+
/** The day the store reckons from, where it keeps one: "today" in what a model is told, so "tomorrow" is a date. */
|
|
727
|
+
function todayOf(store) {
|
|
728
|
+
try {
|
|
729
|
+
const day = (typeof store.today === "function" ? store.today() : undefined) ?? new Date().toISOString();
|
|
730
|
+
return /^\d{4}-\d{2}-\d{2}/.test(day) ? day.slice(0, 10) : undefined;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/** What the app lacks, said by code from the need: a whole sentence, whatever the model wrote. */
|
|
737
|
+
function lacksOf(schema, need) {
|
|
738
|
+
const plural = (kind) => pluralOf(schema, kind).toLowerCase();
|
|
739
|
+
const capitalized = (words) => words.charAt(0).toUpperCase() + words.slice(1);
|
|
740
|
+
const { on, called } = "link" in need ? need.link : need.field;
|
|
741
|
+
return `${capitalized(plural(on))} have no “${capitalized(called)}” yet.`;
|
|
742
|
+
}
|
|
743
|
+
/** What the Fast slot decided over the graph, as an answer: the act over every record as one ghost (two acts, where the words asked two), or what the app lacks — no model's words. */
|
|
744
|
+
function graphResult(ask, asked, said, decided, stages) {
|
|
745
|
+
const graphs = Array.isArray(decided) ? decided : [decided];
|
|
746
|
+
const proposals = [];
|
|
747
|
+
for (const graph of graphs) {
|
|
748
|
+
if (!graph.each || !graph.reading)
|
|
749
|
+
continue;
|
|
750
|
+
const mutation = ask.store.allMutations().find((one) => one.name === graph.each.act);
|
|
751
|
+
for (const id of graph.reading.records) {
|
|
752
|
+
const node = ask.store.graph.getNode(id);
|
|
753
|
+
if (!node || !mutation?.subject)
|
|
754
|
+
continue;
|
|
755
|
+
proposals.push({ id: `each:${mutation.name}:${id}`, label: `${mutation.title ?? mutation.name}: ${labelOf(ask.store.schema.tryDefinition(node.kind), node)}`, said: mutation.title ?? mutation.name, call: { name: mutation.name, args: { ...graph.each.args, [mutation.subject.arg]: id } }, record: id });
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const model = asked.usage.at(-1)?.model;
|
|
759
|
+
const ghost = proposals.length > 0 ? ghostOf(ask.store, { interaction: asked.id, target: ask.target, basis: said, ...(model ? { model } : {}), proposals }, ask.principal) : undefined;
|
|
760
|
+
const offered = (ghost?.proposals ?? []).map((proposal) => ({ id: proposal.id, type: "act", label: proposal.label }));
|
|
761
|
+
// Each part said: what it will do, or — every record already as the act would leave it — that it has nothing to change.
|
|
762
|
+
const kept = new Set((ghost?.proposals ?? []).map((proposal) => proposal.id));
|
|
763
|
+
const text = graphs
|
|
764
|
+
.map((graph) => {
|
|
765
|
+
if (graph.clarify)
|
|
766
|
+
return graph.clarify;
|
|
767
|
+
if (graph.outside)
|
|
768
|
+
return graph.outside;
|
|
769
|
+
if (graph.each && graph.reading) {
|
|
770
|
+
const mutation = ask.store.allMutations().find((one) => one.name === graph.each.act);
|
|
771
|
+
// Said as it will happen: the act, its values, and the records it will act on, counted as it will.
|
|
772
|
+
const acting = graph.reading.records.filter((id) => kept.has(`each:${graph.each.act}:${id}`));
|
|
773
|
+
return acting.length > 0 && mutation ? changeWords(ask.store, mutation, graph.each.args, acting, graph.reading) : mutation ? sayNothingToChange(ask.store, mutation, graph.reading.records) : `Nothing here would change.`;
|
|
774
|
+
}
|
|
775
|
+
return graph.text ?? graph.missing?.said ?? "";
|
|
776
|
+
})
|
|
777
|
+
.filter(Boolean)
|
|
778
|
+
.join(" ");
|
|
779
|
+
const first = graphs[0];
|
|
780
|
+
const missing = graphs.find((graph) => graph.missing)?.missing;
|
|
781
|
+
const taken = graphs.find((graph) => graph.taken)?.taken;
|
|
782
|
+
return {
|
|
783
|
+
interaction: { ...asked.entry, ask: { kind: "ask", said }, offered, outcome: "offered", ...(text ? { answer: text } : {}), usage: [...asked.usage], stages: [...stages] },
|
|
784
|
+
offers: [],
|
|
785
|
+
...(ghost && ghost.proposals.length > 0 ? { ghost } : {}),
|
|
466
786
|
...(text ? { answer: text } : {}),
|
|
787
|
+
...(missing ? { missing } : {}),
|
|
788
|
+
...(first.reading && graphs.length === 1 ? { reading: first.reading } : {}),
|
|
789
|
+
...(taken ? { taken } : {}),
|
|
467
790
|
};
|
|
468
791
|
}
|
|
792
|
+
/** The model's "need", read: a link or a field, each with the words it is called by, or nothing. */
|
|
793
|
+
function needOf(value) {
|
|
794
|
+
if (typeof value !== "object" || value === null)
|
|
795
|
+
return undefined;
|
|
796
|
+
const { link, field } = value;
|
|
797
|
+
const said = (one) => (typeof one === "string" && one.trim() ? one.trim() : undefined);
|
|
798
|
+
if (link && said(link["on"]) && said(link["called"]) && said(link["to"]))
|
|
799
|
+
return { link: { on: said(link["on"]), called: said(link["called"]), to: said(link["to"]) } };
|
|
800
|
+
if (field && said(field["on"]) && said(field["called"])) {
|
|
801
|
+
const type = ["string", "number", "date", "boolean"].includes(String(field["type"])) ? field["type"] : "string";
|
|
802
|
+
return { field: { on: said(field["on"]), called: said(field["called"]), type } };
|
|
803
|
+
}
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
/** The model's "each", read: an act's name and its values, or nothing. */
|
|
807
|
+
function eachOf(value) {
|
|
808
|
+
if (typeof value !== "object" || value === null)
|
|
809
|
+
return undefined;
|
|
810
|
+
const { act, args } = value;
|
|
811
|
+
if (typeof act !== "string")
|
|
812
|
+
return undefined;
|
|
813
|
+
return { act, args: typeof args === "object" && args !== null && !Array.isArray(args) ? args : {} };
|
|
814
|
+
}
|
|
469
815
|
// ── the ghost ───────────────────────────────────────────────────────────────
|
|
470
816
|
/**
|
|
471
817
|
* PROPOSALS, PREVIEWED AS THE PERSON: each call rehearsed as they would
|
|
@@ -530,6 +876,66 @@ export function acceptedEntry(entry, accepted, batch) {
|
|
|
530
876
|
}
|
|
531
877
|
/** The entry after its offer was put away. */
|
|
532
878
|
export const dismissedEntry = (entry) => ({ ...entry, outcome: "dismissed" });
|
|
879
|
+
// ── the context a quick ask sends ───────────────────────────────────────────
|
|
880
|
+
/** How many candidates and records the Fast slot may keep, and how likely one must be to be kept past the first. */
|
|
881
|
+
const CONTEXT_MOST = { candidates: 8, records: 6 };
|
|
882
|
+
const CONTEXT_FLOOR = 0.1;
|
|
883
|
+
/** How many records around the target the Fast slot is asked about, one Noul each. */
|
|
884
|
+
const CONTEXT_ASKED_RECORDS = 12;
|
|
885
|
+
/** The records around the target, as the state tells them: the selection, then its neighbors, each once. */
|
|
886
|
+
const recordsAround = (state) => {
|
|
887
|
+
const seen = new Set();
|
|
888
|
+
return [...state.selection, ...state.neighbors].filter((one) => !seen.has(one.id) && (seen.add(one.id), true));
|
|
889
|
+
};
|
|
890
|
+
/** The default: every candidate and every record the target is scoped to. */
|
|
891
|
+
function defaultContext(asked, choices) {
|
|
892
|
+
return { choices, state: asked.state, context: { by: "default", candidates: choices.map((one) => one.id), records: recordsAround(asked.state).map((one) => one.id) } };
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* THE FAST SLOT PICKS WHAT MATTERS, in Jev's own typed questions, one
|
|
896
|
+
* decision: a Choice of which candidate could answer or act on the words
|
|
897
|
+
* ("none of these" among them), each kept best first while it is likely
|
|
898
|
+
* enough, at least the best one unless none was chosen, at most a few; and
|
|
899
|
+
* a Noul for each record around the target — are the words about it? —
|
|
900
|
+
* kept where it is more likely so than not. The target itself is always
|
|
901
|
+
* sent; the state keeps the records picked and nothing else around it.
|
|
902
|
+
*/
|
|
903
|
+
async function contextPicked(fast, said, asked, choices) {
|
|
904
|
+
const around = recordsAround(asked.state);
|
|
905
|
+
const questions = {};
|
|
906
|
+
const candidates = choices.length > 0 ? choiceAmong(choices, `Which of these could answer, or act on: ${said}`) : undefined;
|
|
907
|
+
if (candidates)
|
|
908
|
+
questions["candidates"] = { ...candidates.question, criteria: { ...candidates.question.criteria, none: "None of these" } };
|
|
909
|
+
const keyed = new Map(around.slice(0, CONTEXT_ASKED_RECORDS).map((record, at) => [`record-${at + 1}`, record]));
|
|
910
|
+
for (const [key, record] of keyed)
|
|
911
|
+
questions[key] = { type: "noul", instructions: `Is “${said}” about ${record.label} (${record.kind})?` };
|
|
912
|
+
if (Object.keys(questions).length === 0)
|
|
913
|
+
return { ...defaultContext(asked, choices), context: { by: "fast", model: fast.model, candidates: [], records: [] } };
|
|
914
|
+
const answers = await decided(fast, { target: asked.state.target, asked: said }, questions, asked.meter);
|
|
915
|
+
const kept = (answer, of, most) => {
|
|
916
|
+
if (answer?.type !== "choice" || answer.choice === "none")
|
|
917
|
+
return [];
|
|
918
|
+
const order = Object.entries(answer.probabilities).filter(([key]) => key !== "none").sort((a, b) => b[1] - a[1]);
|
|
919
|
+
if (!order.some(([key]) => key === answer.choice))
|
|
920
|
+
order.unshift([answer.choice, answer.confidence]);
|
|
921
|
+
return order.filter(([, chance], at) => at === 0 || chance >= CONTEXT_FLOOR).flatMap(([key]) => {
|
|
922
|
+
const one = of(key);
|
|
923
|
+
return one === undefined ? [] : [one];
|
|
924
|
+
}).slice(0, most);
|
|
925
|
+
};
|
|
926
|
+
const picked = candidates ? kept(answers["candidates"], candidates.of, CONTEXT_MOST.candidates) : [];
|
|
927
|
+
const records = [...keyed]
|
|
928
|
+
.flatMap(([key, record]) => {
|
|
929
|
+
const answer = answers[key];
|
|
930
|
+
return answer?.type === "noul" && answer.noul > 0.5 ? [{ record, chance: answer.noul }] : [];
|
|
931
|
+
})
|
|
932
|
+
.sort((a, b) => b.chance - a.chance)
|
|
933
|
+
.slice(0, CONTEXT_MOST.records)
|
|
934
|
+
.map((one) => one.record);
|
|
935
|
+
const ids = new Set(records.map((record) => record.id));
|
|
936
|
+
const state = { ...asked.state, selection: asked.state.selection.filter((one) => ids.has(one.id)), neighbors: asked.state.neighbors.filter((one) => ids.has(one.id)) };
|
|
937
|
+
return { choices: picked, state, context: { by: "fast", model: fast.model, candidates: picked.map((one) => one.id), records: records.map((one) => one.id) } };
|
|
938
|
+
}
|
|
533
939
|
// ── stubs ───────────────────────────────────────────────────────────────────
|
|
534
940
|
/** A rough count of tokens, four characters each: what a stub reports, so metering has numbers to read. */
|
|
535
941
|
const tokensIn = (value) => Math.ceil(JSON.stringify(value).length / 4);
|
|
@@ -548,7 +954,12 @@ export function stubFast(options = {}) {
|
|
|
548
954
|
decide: async (state, questions) => {
|
|
549
955
|
const answers = {};
|
|
550
956
|
for (const [key, question] of Object.entries(questions)) {
|
|
551
|
-
if (question.type === "choice") {
|
|
957
|
+
if (question.type === "choice" && key === "mood") {
|
|
958
|
+
// Asks or tells, as the code's own patterns read it: a stub has no judgment of its own to give.
|
|
959
|
+
const choice = asking(String(state.said ?? "")) ? "asks" : "tells";
|
|
960
|
+
answers[key] = { type: "choice", choice, confidence: 0.9, probabilities: { [choice]: 0.9, [choice === "asks" ? "tells" : "asks"]: 0.1 } };
|
|
961
|
+
}
|
|
962
|
+
else if (question.type === "choice") {
|
|
552
963
|
const names = Object.keys(question.criteria);
|
|
553
964
|
const rank = (name) => {
|
|
554
965
|
const words = `${name} ${question.criteria[name] ?? ""}`;
|