@shobyde/boaz 0.0.0-stage → 0.8.2
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/LICENSE +21 -0
- package/README.md +422 -2
- package/dist/build/codes.d.ts +16 -0
- package/dist/build/codes.d.ts.map +1 -0
- package/dist/build/codes.js +72 -0
- package/dist/build/codes.js.map +1 -0
- package/dist/build/extract.d.ts +45 -0
- package/dist/build/extract.d.ts.map +1 -0
- package/dist/build/extract.js +484 -0
- package/dist/build/extract.js.map +1 -0
- package/dist/build/glob.d.ts +11 -0
- package/dist/build/glob.d.ts.map +1 -0
- package/dist/build/glob.js +88 -0
- package/dist/build/glob.js.map +1 -0
- package/dist/build/index.d.ts +7 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +4 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/probes.d.ts +41 -0
- package/dist/build/probes.d.ts.map +1 -0
- package/dist/build/probes.js +134 -0
- package/dist/build/probes.js.map +1 -0
- package/dist/build/report.d.ts +11 -0
- package/dist/build/report.d.ts.map +1 -0
- package/dist/build/report.js +39 -0
- package/dist/build/report.js.map +1 -0
- package/dist/cli/audit.d.ts +15 -0
- package/dist/cli/audit.d.ts.map +1 -0
- package/dist/cli/audit.js +68 -0
- package/dist/cli/audit.js.map +1 -0
- package/dist/cli/bench.d.ts +7 -0
- package/dist/cli/bench.d.ts.map +1 -0
- package/dist/cli/bench.js +147 -0
- package/dist/cli/bench.js.map +1 -0
- package/dist/cli/harness.d.ts +45 -0
- package/dist/cli/harness.d.ts.map +1 -0
- package/dist/cli/harness.js +90 -0
- package/dist/cli/harness.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +404 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/probes.d.ts +20 -0
- package/dist/cli/probes.d.ts.map +1 -0
- package/dist/cli/probes.js +27 -0
- package/dist/cli/probes.js.map +1 -0
- package/dist/cli/skill-template.d.ts +2 -0
- package/dist/cli/skill-template.d.ts.map +1 -0
- package/dist/cli/skill-template.js +254 -0
- package/dist/cli/skill-template.js.map +1 -0
- package/dist/core/actions.d.ts +67 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +357 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/define.d.ts +25 -0
- package/dist/core/define.d.ts.map +1 -0
- package/dist/core/define.js +76 -0
- package/dist/core/define.js.map +1 -0
- package/dist/core/execute.d.ts +75 -0
- package/dist/core/execute.d.ts.map +1 -0
- package/dist/core/execute.js +145 -0
- package/dist/core/execute.js.map +1 -0
- package/dist/core/index.d.ts +35 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lemmas.d.ts +32 -0
- package/dist/core/lemmas.d.ts.map +1 -0
- package/dist/core/lemmas.js +80 -0
- package/dist/core/lemmas.js.map +1 -0
- package/dist/core/lexical-engine.d.ts +18 -0
- package/dist/core/lexical-engine.d.ts.map +1 -0
- package/dist/core/lexical-engine.js +296 -0
- package/dist/core/lexical-engine.js.map +1 -0
- package/dist/core/loop.d.ts +51 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +432 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/mcp.d.ts +119 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +253 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/memory.d.ts +106 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +185 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/plan.d.ts +83 -0
- package/dist/core/plan.d.ts.map +1 -0
- package/dist/core/plan.js +258 -0
- package/dist/core/plan.js.map +1 -0
- package/dist/core/preferences.d.ts +54 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +83 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/prompt.d.ts +23 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +76 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/question.d.ts +96 -0
- package/dist/core/question.d.ts.map +1 -0
- package/dist/core/question.js +501 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/registry.d.ts +33 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +72 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/retriever.d.ts +48 -0
- package/dist/core/retriever.d.ts.map +1 -0
- package/dist/core/retriever.js +123 -0
- package/dist/core/retriever.js.map +1 -0
- package/dist/core/schema.d.ts +27 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +231 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/skill.d.ts +105 -0
- package/dist/core/skill.d.ts.map +1 -0
- package/dist/core/skill.js +205 -0
- package/dist/core/skill.js.map +1 -0
- package/dist/core/summarise.d.ts +52 -0
- package/dist/core/summarise.d.ts.map +1 -0
- package/dist/core/summarise.js +146 -0
- package/dist/core/summarise.js.map +1 -0
- package/dist/core/tools.d.ts +21 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +120 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/types.d.ts +199 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dom/index.d.ts +22 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +94 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/extract/index.d.ts +36 -0
- package/dist/extract/index.d.ts.map +1 -0
- package/dist/extract/index.js +86 -0
- package/dist/extract/index.js.map +1 -0
- package/dist/react/index.d.ts +52 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +131 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rules/engine.d.ts +152 -0
- package/dist/rules/engine.d.ts.map +1 -0
- package/dist/rules/engine.js +364 -0
- package/dist/rules/engine.js.map +1 -0
- package/dist/rules/facts.d.ts +63 -0
- package/dist/rules/facts.d.ts.map +1 -0
- package/dist/rules/facts.js +115 -0
- package/dist/rules/facts.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/knowledge.d.ts +78 -0
- package/dist/rules/knowledge.d.ts.map +1 -0
- package/dist/rules/knowledge.js +254 -0
- package/dist/rules/knowledge.js.map +1 -0
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +112 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +108 -4
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/* ============================================================
|
|
2
|
+
Actions on an accessibility tree without a model.
|
|
3
|
+
|
|
4
|
+
Everything else in this package answers a question. This is the
|
|
5
|
+
other half of an agent loop: doing something. The surface a
|
|
6
|
+
browser hands you is the accessibility tree, which is already a
|
|
7
|
+
typed, named, ordered list of controls — a schema, not a picture.
|
|
8
|
+
|
|
9
|
+
So "click the send button" does not need a vision model, and does
|
|
10
|
+
not need a model at all: it needs the role the visitor named, the
|
|
11
|
+
name the control already carries, and a tie-break rule for the two
|
|
12
|
+
buttons that share a name.
|
|
13
|
+
|
|
14
|
+
The resolver refuses rather than guesses. Two controls scoring the
|
|
15
|
+
same is reported as `ambiguous` with both candidates, because a
|
|
16
|
+
clicked button cannot be unclicked; a hidden control is reported as
|
|
17
|
+
`hidden` rather than dismissed as absent, since the difference
|
|
18
|
+
between "not on this page" and "on this page but not rendered" is
|
|
19
|
+
the whole diagnosis.
|
|
20
|
+
============================================================ */
|
|
21
|
+
const VERBS = [
|
|
22
|
+
[/^(?:please\s+|can you\s+|could you\s+|then\s+|and\s+)?(?:click|press|tap|push|hit|activate)\b/, 'click'],
|
|
23
|
+
[/^(?:please\s+|can you\s+|could you\s+|then\s+|and\s+)?(?:fill|type|enter|write|put)\b/, 'fill'],
|
|
24
|
+
[/^(?:please\s+|can you\s+|could you\s+|then\s+|and\s+)?(?:scroll|jump|go)\b/, 'scroll'],
|
|
25
|
+
[/^(?:please\s+|can you\s+|could you\s+|then\s+|and\s+)?(?:focus|highlight|select)\b/, 'focus'],
|
|
26
|
+
];
|
|
27
|
+
/** The noun a visitor uses for a role. Both directions are closed lists. */
|
|
28
|
+
const ROLE_NOUNS = [
|
|
29
|
+
[/\b(?:search\s+box|search\s+field)\b/, 'searchbox'],
|
|
30
|
+
[/\b(?:text\s*box|text\s*field|input|field|form\s+field|box)\b/, 'textbox'],
|
|
31
|
+
[/\b(?:button|btn)\b/, 'button'],
|
|
32
|
+
[/\b(?:link|hyperlink)\b/, 'link'],
|
|
33
|
+
[/\b(?:checkbox|tick\s*box)\b/, 'checkbox'],
|
|
34
|
+
[/\b(?:radio\s+button|radio)\b/, 'radio'],
|
|
35
|
+
[/\b(?:tab)\b/, 'tab'],
|
|
36
|
+
[/\b(?:menu\s+item|menuitem)\b/, 'menuitem'],
|
|
37
|
+
[/\b(?:heading|header\s+text|section\s+title)\b/, 'heading'],
|
|
38
|
+
[/\b(?:switch|toggle)\b/, 'switch'],
|
|
39
|
+
[/\b(?:image|picture|thumbnail)\b/, 'img'],
|
|
40
|
+
];
|
|
41
|
+
const VERB_ROLES = {
|
|
42
|
+
click: ['button', 'link', 'menuitem', 'tab', 'checkbox', 'radio', 'switch', 'option'],
|
|
43
|
+
fill: ['textbox', 'searchbox', 'combobox', 'spinbutton'],
|
|
44
|
+
scroll: [],
|
|
45
|
+
focus: [],
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Roles a visitor's noun may legitimately mean, nearest first. Order matters:
|
|
49
|
+
* `searchbox` is a textbox in ARIA and an input[type=search] is a searchbox in
|
|
50
|
+
* Chromium, so "the search box" has to accept both, with the nearer role winning
|
|
51
|
+
* a narrow contest. Two controls of the same role still tie and refuse.
|
|
52
|
+
*/
|
|
53
|
+
const ROLE_FAMILY = {
|
|
54
|
+
textbox: ['textbox', 'searchbox', 'combobox'],
|
|
55
|
+
searchbox: ['searchbox', 'textbox'],
|
|
56
|
+
combobox: ['combobox', 'textbox'],
|
|
57
|
+
button: ['button'],
|
|
58
|
+
link: ['link'],
|
|
59
|
+
};
|
|
60
|
+
const ORDINALS = {
|
|
61
|
+
first: 1,
|
|
62
|
+
second: 2,
|
|
63
|
+
third: 3,
|
|
64
|
+
fourth: 4,
|
|
65
|
+
fifth: 5,
|
|
66
|
+
last: -1,
|
|
67
|
+
};
|
|
68
|
+
const ARTICLES = /^(?:the|a|an|that|this|its|his|her|their)\s+/;
|
|
69
|
+
/** Case, punctuation, articles and spacing: the only free variation in a name. */
|
|
70
|
+
export function normaliseName(input) {
|
|
71
|
+
return String(input)
|
|
72
|
+
.replace(/&/g, ' and ')
|
|
73
|
+
.replace(/[‘’“”"']/g, '')
|
|
74
|
+
.replace(/[^A-Za-z0-9#+/. ]+/g, ' ')
|
|
75
|
+
.replace(/\s+/g, ' ')
|
|
76
|
+
.trim()
|
|
77
|
+
.toLowerCase()
|
|
78
|
+
.replace(ARTICLES, '');
|
|
79
|
+
}
|
|
80
|
+
function tokensOf(input) {
|
|
81
|
+
return normaliseName(input)
|
|
82
|
+
.split(' ')
|
|
83
|
+
.filter((t) => t.length > 0 && !['the', 'a', 'an', 'of', 'to', 'in', 'on'].includes(t));
|
|
84
|
+
}
|
|
85
|
+
/** Words that describe the control rather than name it. */
|
|
86
|
+
const ROLE_WORDS = new Set([
|
|
87
|
+
'button', 'btn', 'link', 'field', 'input', 'textbox', 'text', 'box', 'checkbox',
|
|
88
|
+
'radio', 'tab', 'menuitem', 'menu', 'item', 'heading', 'switch', 'toggle', 'image',
|
|
89
|
+
'picture', 'thumbnail', 'search', 'form',
|
|
90
|
+
]);
|
|
91
|
+
function stripRoleWords(phrase) {
|
|
92
|
+
const kept = phrase.split(' ').filter((w) => !ROLE_WORDS.has(w));
|
|
93
|
+
return kept.join(' ').trim();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Read one sentence into an action request, or `null` when the sentence is not
|
|
97
|
+
* an action. Roles, ordinals and scopes come from closed tables; the name is
|
|
98
|
+
* whatever is left after those are removed, so a control whose name is new to
|
|
99
|
+
* the package still resolves.
|
|
100
|
+
*/
|
|
101
|
+
export function parseAction(query) {
|
|
102
|
+
const text = String(query).replace(/\s+/g, ' ').trim();
|
|
103
|
+
if (!text)
|
|
104
|
+
return null;
|
|
105
|
+
let verb;
|
|
106
|
+
let rest = '';
|
|
107
|
+
for (const [pattern, kind] of VERBS) {
|
|
108
|
+
const hit = pattern.exec(text.toLowerCase());
|
|
109
|
+
if (hit) {
|
|
110
|
+
verb = kind;
|
|
111
|
+
rest = text.slice(hit[0].length).trim();
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!verb || !rest)
|
|
116
|
+
return null;
|
|
117
|
+
let scope;
|
|
118
|
+
const scopeHit = /\b(?:in|inside|within|on)\s+(?:the\s+)?([a-z0-9 ]+?)\s+(?:panel|menu|nav|navigation|header|footer|card|dialog|sidebar|section|bar)\b/i.exec(rest);
|
|
119
|
+
if (scopeHit) {
|
|
120
|
+
scope = scopeHit[1].trim();
|
|
121
|
+
rest = `${rest.slice(0, scopeHit.index)} ${rest.slice(scopeHit.index + scopeHit[0].length)}`.trim();
|
|
122
|
+
}
|
|
123
|
+
let fillText;
|
|
124
|
+
if (verb === 'fill') {
|
|
125
|
+
const withHit = /\bwith\b/i.exec(rest);
|
|
126
|
+
const intoHit = /\b(?:into|in|to)\b/i.exec(rest);
|
|
127
|
+
if (withHit) {
|
|
128
|
+
// "fill the email field with sho@example.com": target, then value.
|
|
129
|
+
fillText = unquote(rest.slice(withHit.index + withHit[0].length).trim());
|
|
130
|
+
rest = rest.slice(0, withHit.index).trim();
|
|
131
|
+
}
|
|
132
|
+
else if (intoHit) {
|
|
133
|
+
// "type sho@example.com into the email field": value, then target.
|
|
134
|
+
fillText = unquote(rest.slice(0, intoHit.index).trim());
|
|
135
|
+
rest = rest.slice(intoHit.index + intoHit[0].length).trim();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!rest)
|
|
139
|
+
return null;
|
|
140
|
+
let role;
|
|
141
|
+
const lower = rest.toLowerCase();
|
|
142
|
+
for (const [pattern, canonical] of ROLE_NOUNS) {
|
|
143
|
+
if (pattern.test(lower)) {
|
|
144
|
+
role = canonical;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let ordinal;
|
|
149
|
+
const ordinalHit = /\b(first|second|third|fourth|fifth|last)\b/.exec(lower);
|
|
150
|
+
if (ordinalHit)
|
|
151
|
+
ordinal = ORDINALS[ordinalHit[1]];
|
|
152
|
+
let namePart = lower
|
|
153
|
+
.replace(/\b(?:first|second|third|fourth|fifth|last)\b/, ' ')
|
|
154
|
+
.replace(/\b(?:button|btn|link|hyperlink|field|input|text\s*box|textbox|checkbox|tick\s*box|radio|tab|menu\s+item|heading|switch|toggle|image|picture|thumbnail|search\s+box)\b/g, ' ')
|
|
155
|
+
.replace(/\b(?:on the page|in the page|on this page)\b/g, ' ')
|
|
156
|
+
.replace(/\s+/g, ' ')
|
|
157
|
+
.trim();
|
|
158
|
+
namePart = stripRoleWords(namePart);
|
|
159
|
+
const name = unquote(namePart.replace(/^(?:the|a|an)\b\s*/, '').trim());
|
|
160
|
+
// A target named only by its role ("fill the search box") is still a target.
|
|
161
|
+
if (!name && !role)
|
|
162
|
+
return null;
|
|
163
|
+
const request = { verb };
|
|
164
|
+
const hint = rest.replace(/^(?:the|a|an)\s+/i, '').trim();
|
|
165
|
+
if (name)
|
|
166
|
+
request.name = name;
|
|
167
|
+
else if (hint)
|
|
168
|
+
request.hint = hint;
|
|
169
|
+
if (role)
|
|
170
|
+
request.role = role;
|
|
171
|
+
if (ordinal !== undefined)
|
|
172
|
+
request.ordinal = ordinal;
|
|
173
|
+
if (scope)
|
|
174
|
+
request.scope = scope;
|
|
175
|
+
if (fillText !== undefined)
|
|
176
|
+
request.text = fillText;
|
|
177
|
+
return request;
|
|
178
|
+
}
|
|
179
|
+
function unquote(input) {
|
|
180
|
+
return input.replace(/^["'“”‘’]+|["'“”‘’]+$/g, '').trim();
|
|
181
|
+
}
|
|
182
|
+
/** Walk a nested tree into the flat, document-ordered list the resolver wants. */
|
|
183
|
+
export function flattenTree(nodes, scopes = [], hidden = false) {
|
|
184
|
+
const out = [];
|
|
185
|
+
for (const node of nodes) {
|
|
186
|
+
const ownScope = node.scopes ?? [];
|
|
187
|
+
const nodeHidden = hidden || node.hidden === true;
|
|
188
|
+
out.push({ ...node, scopes: [...scopes, ...ownScope], hidden: nodeHidden, children: undefined });
|
|
189
|
+
if (node.children?.length) {
|
|
190
|
+
out.push(...flattenTree(node.children, [...scopes, ...ownScope, ...(node.name ? [node.name] : [])], nodeHidden));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Resolve a request (or a sentence) against the tree. Refusals carry the reason
|
|
197
|
+
* and the candidates, so a host can say "two buttons are called Send" instead of
|
|
198
|
+
* clicking one and hoping.
|
|
199
|
+
*/
|
|
200
|
+
export function resolveAction(input, nodes) {
|
|
201
|
+
const request = typeof input === 'string' ? parseAction(input) : input;
|
|
202
|
+
if (!request) {
|
|
203
|
+
return { ok: false, score: 0, reason: 'no-verb', considered: [] };
|
|
204
|
+
}
|
|
205
|
+
const wanted = normaliseName(request.name ?? '');
|
|
206
|
+
const wantedTokens = new Set(tokensOf(request.name ?? ''));
|
|
207
|
+
const roleAllowed = request.role ? ROLE_FAMILY[request.role] ?? [request.role] : VERB_ROLES[request.verb];
|
|
208
|
+
const seen = [];
|
|
209
|
+
let roleSeen = 0;
|
|
210
|
+
let hiddenMatches = 0;
|
|
211
|
+
let disabledMatch;
|
|
212
|
+
let offRoleMatch;
|
|
213
|
+
nodes.forEach((node, index) => {
|
|
214
|
+
if (node.hidden) {
|
|
215
|
+
if (wanted && normaliseName(node.name ?? '') === wanted)
|
|
216
|
+
hiddenMatches += 1;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// The right name on the wrong role is worth reporting, not clicking.
|
|
220
|
+
if (!offRoleMatch && wanted && normaliseName(node.name ?? '') === wanted && !roleAllowed.includes(node.role)) {
|
|
221
|
+
offRoleMatch = node;
|
|
222
|
+
}
|
|
223
|
+
if (roleAllowed.length > 0 && !roleAllowed.includes(node.role))
|
|
224
|
+
return;
|
|
225
|
+
roleSeen += 1;
|
|
226
|
+
// A role the noun names directly beats a role from the same family.
|
|
227
|
+
const roleRank = Math.max(0, roleAllowed.indexOf(node.role));
|
|
228
|
+
const nodeName = normaliseName(node.name ?? '');
|
|
229
|
+
if (!wanted) {
|
|
230
|
+
// Role-only request ("fill the search box"): every control of that role is a candidate,
|
|
231
|
+
// and the phrase's own words are weak evidence for which one.
|
|
232
|
+
let score = 0.45 - 0.05 * roleRank;
|
|
233
|
+
if (request.hint) {
|
|
234
|
+
const hintTokens = tokensOf(request.hint);
|
|
235
|
+
const nodeTokens = tokensOf(node.name ?? '');
|
|
236
|
+
const covered = hintTokens.filter((t) => nodeTokens.includes(t)).length;
|
|
237
|
+
if (hintTokens.length > 0 && covered > 0)
|
|
238
|
+
score += 0.15 * (covered / hintTokens.length);
|
|
239
|
+
}
|
|
240
|
+
if (request.scope) {
|
|
241
|
+
const scope = normaliseName(request.scope);
|
|
242
|
+
const inScope = (node.scopes ?? []).some((s) => normaliseName(s).includes(scope));
|
|
243
|
+
score += inScope ? 0.2 : -0.1;
|
|
244
|
+
}
|
|
245
|
+
if (!node.disabled)
|
|
246
|
+
seen.push({ node, index, score: Math.round(score * 1000) / 1000, exactName: false });
|
|
247
|
+
else
|
|
248
|
+
disabledMatch = { node, index, score, exactName: false };
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
let nameScore = 0;
|
|
252
|
+
let exactName = false;
|
|
253
|
+
if (nodeName === wanted) {
|
|
254
|
+
nameScore = 0.6;
|
|
255
|
+
exactName = true;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const nodeTokens = tokensOf(node.name ?? '');
|
|
259
|
+
const covered = [...wantedTokens].filter((t) => nodeTokens.includes(t)).length;
|
|
260
|
+
if (wantedTokens.size > 0 && covered === wantedTokens.size) {
|
|
261
|
+
// Same words, different order or extra words the visitor did not say.
|
|
262
|
+
nameScore = nodeTokens.length === wantedTokens.size ? 0.55 : 0.45;
|
|
263
|
+
}
|
|
264
|
+
else if (covered > 0) {
|
|
265
|
+
nameScore = 0.3 * (covered / wantedTokens.size);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (nameScore === 0)
|
|
269
|
+
return;
|
|
270
|
+
let score = nameScore;
|
|
271
|
+
if (request.role)
|
|
272
|
+
score += 0.25;
|
|
273
|
+
if (request.scope) {
|
|
274
|
+
const scope = normaliseName(request.scope);
|
|
275
|
+
const inScope = (node.scopes ?? []).some((s) => normaliseName(s).includes(scope));
|
|
276
|
+
if (inScope)
|
|
277
|
+
score += 0.2;
|
|
278
|
+
else
|
|
279
|
+
score -= 0.1;
|
|
280
|
+
}
|
|
281
|
+
const scored = { node, index, score: Math.round(score * 1000) / 1000, exactName };
|
|
282
|
+
// A control that cannot be used is not a tie: it cannot be clicked either.
|
|
283
|
+
if (node.disabled)
|
|
284
|
+
disabledMatch = scored;
|
|
285
|
+
else
|
|
286
|
+
seen.push(scored);
|
|
287
|
+
});
|
|
288
|
+
seen.sort((a, b) => b.score - a.score || a.index - b.index);
|
|
289
|
+
const considered = seen.slice(0, 5).map(({ node, index, score }) => ({ node, index, score }));
|
|
290
|
+
if (seen.length === 0) {
|
|
291
|
+
if (hiddenMatches > 0)
|
|
292
|
+
return { ok: false, request, score: 0, reason: 'hidden', considered: [] };
|
|
293
|
+
if (disabledMatch) {
|
|
294
|
+
return { ok: false, request, node: disabledMatch.node, index: disabledMatch.index, score: disabledMatch.score, reason: 'disabled', considered: [] };
|
|
295
|
+
}
|
|
296
|
+
if (roleSeen === 0 && request.role) {
|
|
297
|
+
return { ok: false, request, score: 0, reason: 'role-mismatch', considered: [], ...(offRoleMatch ? { nearMiss: offRoleMatch } : {}) };
|
|
298
|
+
}
|
|
299
|
+
return { ok: false, request, score: 0, reason: 'name-mismatch', considered: [], ...(offRoleMatch ? { nearMiss: offRoleMatch } : {}) };
|
|
300
|
+
}
|
|
301
|
+
const best = seen[0];
|
|
302
|
+
const ties = seen.filter((s) => Math.abs(s.score - best.score) < 0.001);
|
|
303
|
+
if (ties.length > 1 && request.ordinal === undefined) {
|
|
304
|
+
return { ok: false, request, score: best.score, reason: 'ambiguous', considered };
|
|
305
|
+
}
|
|
306
|
+
let chosen = best;
|
|
307
|
+
if (request.ordinal !== undefined) {
|
|
308
|
+
const pick = request.ordinal < 0 ? ties[ties.length - 1] : ties[request.ordinal - 1];
|
|
309
|
+
if (!pick) {
|
|
310
|
+
return { ok: false, request, score: best.score, reason: 'ambiguous', considered };
|
|
311
|
+
}
|
|
312
|
+
chosen = pick;
|
|
313
|
+
}
|
|
314
|
+
if (chosen.node.disabled) {
|
|
315
|
+
return { ok: false, request, node: chosen.node, index: chosen.index, score: chosen.score, reason: 'disabled', considered };
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
ok: true,
|
|
319
|
+
request,
|
|
320
|
+
node: chosen.node,
|
|
321
|
+
index: chosen.index,
|
|
322
|
+
score: chosen.score,
|
|
323
|
+
reason: 'resolved',
|
|
324
|
+
considered,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/** The sentence a host prints before it acts. One line, no jargon. */
|
|
328
|
+
export function describeResolution(resolution) {
|
|
329
|
+
const { request } = resolution;
|
|
330
|
+
const target = [request?.role, request?.name && `"${request.name}"`].filter(Boolean).join(' ');
|
|
331
|
+
switch (resolution.reason) {
|
|
332
|
+
case 'resolved':
|
|
333
|
+
return `Found ${target || 'the control'}${request?.scope ? ` in the ${request.scope}` : ''}, ${resolution.node?.role} at position ${(resolution.index ?? 0) + 1}.`;
|
|
334
|
+
case 'ambiguous':
|
|
335
|
+
return `${resolution.considered.length} controls match ${target}: ${resolution.considered
|
|
336
|
+
.map((c) => `"${c.node.name ?? c.node.role}"`)
|
|
337
|
+
.slice(0, 3)
|
|
338
|
+
.join(', ')}. Nothing was clicked.`;
|
|
339
|
+
case 'hidden':
|
|
340
|
+
return `${target} exists but is not rendered, so nothing was clicked.`;
|
|
341
|
+
case 'disabled':
|
|
342
|
+
return `${target} is disabled, so nothing was clicked.`;
|
|
343
|
+
case 'role-mismatch':
|
|
344
|
+
return [
|
|
345
|
+
`This page has no ${request?.role ?? 'control'} to ${request?.verb ?? 'use'}.`,
|
|
346
|
+
resolution.nearMiss ? `The ${resolution.nearMiss.name} ${resolution.nearMiss.role} has that name.` : '',
|
|
347
|
+
].filter(Boolean).join(' ');
|
|
348
|
+
case 'name-mismatch':
|
|
349
|
+
return [
|
|
350
|
+
`No ${request?.role ?? 'control'} is named "${request?.name ?? ''}".`,
|
|
351
|
+
resolution.nearMiss ? `The ${resolution.nearMiss.name} ${resolution.nearMiss.role} has that name.` : '',
|
|
352
|
+
].filter(Boolean).join(' ');
|
|
353
|
+
default:
|
|
354
|
+
return 'That sentence is not an action.';
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/core/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;kEAmBkE;AA+DlE,MAAM,KAAK,GAAgC;IACzC,CAAC,+FAA+F,EAAE,OAAO,CAAC;IAC1G,CAAC,uFAAuF,EAAE,MAAM,CAAC;IACjG,CAAC,4EAA4E,EAAE,QAAQ,CAAC;IACxF,CAAC,oFAAoF,EAAE,OAAO,CAAC;C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MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,KAAK,eAAe;YAClB,OAAO;gBACL,MAAM,OAAO,EAAE,IAAI,IAAI,SAAS,cAAc,OAAO,EAAE,IAAI,IAAI,EAAE,IAAI;gBACrE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,EAAE;aACxG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B;YACE,OAAO,iCAAiC,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CapabilityDeclaration, JSONSchemaObject } from './types.js';
|
|
2
|
+
export declare class CapabilityDefinitionError extends Error {
|
|
3
|
+
readonly capabilityId?: string | undefined;
|
|
4
|
+
constructor(message: string, capabilityId?: string | undefined);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Declares a navigable destination or an executable client action.
|
|
8
|
+
*
|
|
9
|
+
* Fails fast on the mistakes the build-time verifier would otherwise report
|
|
10
|
+
* later: a missing id, a description written for developers, a route
|
|
11
|
+
* capability with no route, or an action that cannot run because no handler
|
|
12
|
+
* was attached.
|
|
13
|
+
*/
|
|
14
|
+
export declare function defineCapability<TParams = Record<string, unknown>, TResult = unknown>(declaration: CapabilityDeclaration<TParams, TResult>): CapabilityDeclaration<TParams, TResult>;
|
|
15
|
+
/** Strips the handler so the same declaration can be serialised into a manifest. */
|
|
16
|
+
export declare function toManifestCapability(declaration: CapabilityDeclaration): Omit<CapabilityDeclaration, 'handler'>;
|
|
17
|
+
export declare function normalizeSchema(schema: JSONSchemaObject | undefined): JSONSchemaObject | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Convenience wrapper for declaring knowledge the assistant can quote verbatim.
|
|
20
|
+
* The text is indexed for retrieval and returned as prose when matched.
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineKnowledge(declaration: Omit<CapabilityDeclaration, 'kind'> & {
|
|
23
|
+
knowledge: string;
|
|
24
|
+
}): CapabilityDeclaration;
|
|
25
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/core/define.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAkB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG1F,qBAAa,yBAA0B,SAAQ,KAAK;IAGhD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;gBAD9B,OAAO,EAAE,MAAM,EACN,YAAY,CAAC,EAAE,MAAM,YAAA;CAKjC;AAKD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EACnF,WAAW,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,GACnD,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAqDzC;AAED,oFAAoF;AACpF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAC5E,qBAAqB,EACrB,SAAS,CACV,CAGA;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAElG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CAE/H"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { unsupportedKeywords } from './schema.js';
|
|
2
|
+
export class CapabilityDefinitionError extends Error {
|
|
3
|
+
capabilityId;
|
|
4
|
+
constructor(message, capabilityId) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.capabilityId = capabilityId;
|
|
7
|
+
this.name = 'CapabilityDefinitionError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
11
|
+
const KINDS = ['route', 'action', 'query', 'knowledge'];
|
|
12
|
+
/**
|
|
13
|
+
* Declares a navigable destination or an executable client action.
|
|
14
|
+
*
|
|
15
|
+
* Fails fast on the mistakes the build-time verifier would otherwise report
|
|
16
|
+
* later: a missing id, a description written for developers, a route
|
|
17
|
+
* capability with no route, or an action that cannot run because no handler
|
|
18
|
+
* was attached.
|
|
19
|
+
*/
|
|
20
|
+
export function defineCapability(declaration) {
|
|
21
|
+
const problems = [];
|
|
22
|
+
const id = declaration.id;
|
|
23
|
+
if (!id || !ID_PATTERN.test(id)) {
|
|
24
|
+
problems.push(`id "${id}" must be lowercase and match ${ID_PATTERN}`);
|
|
25
|
+
}
|
|
26
|
+
if (!KINDS.includes(declaration.kind)) {
|
|
27
|
+
problems.push(`kind must be one of ${KINDS.join(', ')}`);
|
|
28
|
+
}
|
|
29
|
+
if (!declaration.title || declaration.title.trim().length < 3) {
|
|
30
|
+
problems.push('title must be a short human-readable label');
|
|
31
|
+
}
|
|
32
|
+
if (!declaration.description || declaration.description.trim().length < 12) {
|
|
33
|
+
problems.push('description must be at least 12 characters and written from the user perspective');
|
|
34
|
+
}
|
|
35
|
+
if (declaration.kind === 'route' && !declaration.route) {
|
|
36
|
+
problems.push('kind "route" requires a route path');
|
|
37
|
+
}
|
|
38
|
+
if (declaration.kind !== 'route' && declaration.kind !== 'knowledge' && typeof declaration.handler !== 'function') {
|
|
39
|
+
problems.push(`kind "${declaration.kind}" requires a handler function`);
|
|
40
|
+
}
|
|
41
|
+
if (declaration.kind === 'knowledge' && (!declaration.knowledge || declaration.knowledge.trim().length < 8)) {
|
|
42
|
+
problems.push('kind "knowledge" requires a knowledge string of at least 8 characters');
|
|
43
|
+
}
|
|
44
|
+
if (declaration.kind === 'route' &&
|
|
45
|
+
declaration.route &&
|
|
46
|
+
!/^[/#]/.test(declaration.route)) {
|
|
47
|
+
problems.push(`route "${declaration.route}" must start with "/" or "#"`);
|
|
48
|
+
}
|
|
49
|
+
if (problems.length > 0) {
|
|
50
|
+
throw new CapabilityDefinitionError(`Invalid capability${id ? ` "${id}"` : ''}:\n - ${problems.join('\n - ')}`, id);
|
|
51
|
+
}
|
|
52
|
+
const unsupported = unsupportedKeywords(declaration.paramsSchema);
|
|
53
|
+
if (unsupported.length > 0) {
|
|
54
|
+
// Not fatal: the schema is still usable, but the runtime cannot enforce
|
|
55
|
+
// these keywords, so say so loudly instead of silently weakening the gate.
|
|
56
|
+
console.warn(`[boaz] capability "${id}" uses schema keywords the runtime does not enforce: ${unsupported.join(', ')}. ` +
|
|
57
|
+
`Arguments matching them will not be rejected.`);
|
|
58
|
+
}
|
|
59
|
+
return declaration;
|
|
60
|
+
}
|
|
61
|
+
/** Strips the handler so the same declaration can be serialised into a manifest. */
|
|
62
|
+
export function toManifestCapability(declaration) {
|
|
63
|
+
const { handler: _handler, ...rest } = declaration;
|
|
64
|
+
return rest;
|
|
65
|
+
}
|
|
66
|
+
export function normalizeSchema(schema) {
|
|
67
|
+
return schema;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Convenience wrapper for declaring knowledge the assistant can quote verbatim.
|
|
71
|
+
* The text is indexed for retrieval and returned as prose when matched.
|
|
72
|
+
*/
|
|
73
|
+
export function defineKnowledge(declaration) {
|
|
74
|
+
return defineCapability({ ...declaration, kind: 'knowledge' });
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/core/define.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,OAAO,yBAA0B,SA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AAI,CAAC,IAAI;YACxG,+CAA+C,CAClD,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CAAC,WAAkC;IAIrE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAoC;IAClE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,WAAwE;IACtG,OAAO,gBAAgB,CAAC,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PlannedStep, RequestPlan } from './plan.js';
|
|
2
|
+
/**
|
|
3
|
+
* A plan is only worth making if something runs it. `planRequest` decides what a
|
|
4
|
+
* two-request sentence means; this walks the steps in order, refuses the ones the
|
|
5
|
+
* sentence never paid for, and reports each step so a host can show what
|
|
6
|
+
* happened instead of inferring it from prose.
|
|
7
|
+
*
|
|
8
|
+
* The executor owns ordering, preconditions and recovery. It does not own
|
|
9
|
+
* effects: the host passes `run`, which is the same path a single request
|
|
10
|
+
* already takes. That keeps confirmation, validation and navigation in one
|
|
11
|
+
* place, so a planned step cannot reach a control that a one-step request could
|
|
12
|
+
* not.
|
|
13
|
+
*
|
|
14
|
+
* Recovery is the one thing a planner can do that a single call cannot: when a
|
|
15
|
+
* capability throws or returns nothing, the runner-up for the same clause is a
|
|
16
|
+
* fact the planner already ranked. It is not a guess about intent, and it is not
|
|
17
|
+
* a retry of the same call.
|
|
18
|
+
*/
|
|
19
|
+
export type StepStatus = 'ran' | 'skipped' | 'failed';
|
|
20
|
+
export type SkipReason = 'missing-argument' | 'not-on-route' | 'previous-failed' | 'step-limit';
|
|
21
|
+
/** Why one candidate did not serve the step. */
|
|
22
|
+
export type AttemptOutcome = 'threw' | 'empty';
|
|
23
|
+
export interface StepAttempt {
|
|
24
|
+
capabilityId: string;
|
|
25
|
+
outcome: AttemptOutcome;
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ExecutedStep {
|
|
29
|
+
capabilityId: string;
|
|
30
|
+
title: string;
|
|
31
|
+
/** The clause the visitor wrote, kept so a trace can quote it. */
|
|
32
|
+
text: string;
|
|
33
|
+
status: StepStatus;
|
|
34
|
+
reason?: SkipReason;
|
|
35
|
+
result?: unknown;
|
|
36
|
+
error?: string;
|
|
37
|
+
/** Candidates that did not work, in the order they were tried. */
|
|
38
|
+
attempts?: StepAttempt[];
|
|
39
|
+
}
|
|
40
|
+
export interface PlanExecution {
|
|
41
|
+
steps: ExecutedStep[];
|
|
42
|
+
/** One sentence covering what ran, what was tried and what was refused. */
|
|
43
|
+
summary: string;
|
|
44
|
+
/** True when every step ran. */
|
|
45
|
+
ok: boolean;
|
|
46
|
+
/** The step that stopped the plan, when one failed. */
|
|
47
|
+
failedAt?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface ExecuteOptions {
|
|
50
|
+
/** Runs one step. Pass the host's ordinary capability path, not a second one. */
|
|
51
|
+
run: (step: PlannedStep) => Promise<unknown> | unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Runs a capability by id, for the recovery candidates. A host that routes on
|
|
54
|
+
* text cannot reach a runner-up, because the text would route the same way
|
|
55
|
+
* again; this is the hook that makes recovery real instead of decorative.
|
|
56
|
+
*/
|
|
57
|
+
runAlternate?: (step: PlannedStep) => Promise<unknown> | unknown;
|
|
58
|
+
/** The route the visitor is on now. Required to honour `needs: 'route'`. */
|
|
59
|
+
currentRoute?: () => string;
|
|
60
|
+
/** Refuse work past this many executed steps. Default 4. */
|
|
61
|
+
maxSteps?: number;
|
|
62
|
+
/** Try runner-ups after a failure. Default true. */
|
|
63
|
+
recover?: boolean;
|
|
64
|
+
/** Cap on runner-ups tried per step. Default 2. */
|
|
65
|
+
maxAlternates?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What counts as "the capability came back with nothing". Only a handler that
|
|
69
|
+
* produced no value at all: `undefined`, `null` or an empty string. An empty
|
|
70
|
+
* array is an answer ("no project lists Cobol"), and recovering from it would
|
|
71
|
+
* overwrite a correct result with an unrelated one.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isEmptyResult(value: unknown): boolean;
|
|
74
|
+
export declare function executePlan(plan: RequestPlan, options: ExecuteOptions): Promise<PlanExecution>;
|
|
75
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/core/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE5E;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEtD,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,cAAc,GACd,iBAAiB,GACjB,YAAY,CAAC;AAEjB,gDAAgD;AAChD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,QAAQ,CAAC,EAAE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