@liyuera/dsh-chrome-browser 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -10
- package/extension/manifest.json +4 -3
- package/extension/service-worker.js +721 -68
- package/lib/activity.d.ts +65 -0
- package/lib/activity.d.ts.map +1 -0
- package/lib/activity.js +111 -0
- package/lib/activity.js.map +1 -0
- package/lib/backend.d.ts +193 -11
- package/lib/backend.d.ts.map +1 -1
- package/lib/backend.js +344 -39
- package/lib/backend.js.map +1 -1
- package/lib/cdp.d.ts +7 -1
- package/lib/cdp.d.ts.map +1 -1
- package/lib/cdp.js +17 -1
- package/lib/cdp.js.map +1 -1
- package/lib/chrome.d.ts +8 -0
- package/lib/chrome.d.ts.map +1 -1
- package/lib/chrome.js +20 -0
- package/lib/chrome.js.map +1 -1
- package/lib/client/BrowserActivity.d.ts +22 -0
- package/lib/client/BrowserActivity.d.ts.map +1 -0
- package/lib/client/BrowserActivity.js +100 -0
- package/lib/client/BrowserActivity.js.map +1 -0
- package/lib/client/activity.d.ts +27 -0
- package/lib/client/activity.d.ts.map +1 -0
- package/lib/client/activity.js +57 -0
- package/lib/client/activity.js.map +1 -0
- package/lib/client/index.d.ts +4 -6
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +13 -19
- package/lib/client/index.js.map +1 -1
- package/lib/client/tab-catalog.d.ts +11 -1
- package/lib/client/tab-catalog.d.ts.map +1 -1
- package/lib/client/tab-catalog.js.map +1 -1
- package/lib/client/tab-source.d.ts +8 -2
- package/lib/client/tab-source.d.ts.map +1 -1
- package/lib/client/tab-source.js.map +1 -1
- package/lib/client.js +177 -13
- package/lib/client.js.map +1 -1
- package/lib/console-events.d.ts +32 -0
- package/lib/console-events.d.ts.map +1 -0
- package/lib/console-events.js +106 -0
- package/lib/console-events.js.map +1 -0
- package/lib/console-log.d.ts +107 -0
- package/lib/console-log.d.ts.map +1 -0
- package/lib/console-log.js +158 -0
- package/lib/console-log.js.map +1 -0
- package/lib/expressions.d.ts +71 -2
- package/lib/expressions.d.ts.map +1 -1
- package/lib/expressions.js +277 -14
- package/lib/expressions.js.map +1 -1
- package/lib/help.d.ts +89 -0
- package/lib/help.d.ts.map +1 -0
- package/lib/help.js +94 -0
- package/lib/help.js.map +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +30 -9
- package/lib/index.js.map +1 -1
- package/lib/presentation.d.ts +130 -0
- package/lib/presentation.d.ts.map +1 -0
- package/lib/presentation.js +361 -0
- package/lib/presentation.js.map +1 -0
- package/lib/routes.d.ts +3 -8
- package/lib/routes.d.ts.map +1 -1
- package/lib/routes.js +20 -109
- package/lib/routes.js.map +1 -1
- package/lib/skill.d.ts +50 -0
- package/lib/skill.d.ts.map +1 -0
- package/lib/skill.js +163 -0
- package/lib/skill.js.map +1 -0
- package/lib/text.d.ts +21 -0
- package/lib/text.d.ts.map +1 -1
- package/lib/text.js +18 -0
- package/lib/text.js.map +1 -1
- package/lib/tools.d.ts +22 -4
- package/lib/tools.d.ts.map +1 -1
- package/lib/tools.js +467 -75
- package/lib/tools.js.map +1 -1
- package/lib/ws.d.ts +9 -2
- package/lib/ws.d.ts.map +1 -1
- package/lib/ws.js +49 -19
- package/lib/ws.js.map +1 -1
- package/package.json +4 -3
- package/lib/bindings.d.ts +0 -23
- package/lib/bindings.d.ts.map +0 -1
- package/lib/bindings.js +0 -49
- package/lib/bindings.js.map +0 -1
- package/lib/client/TabPicker.d.ts +0 -54
- package/lib/client/TabPicker.d.ts.map +0 -1
- package/lib/client/TabPicker.js +0 -329
- package/lib/client/TabPicker.js.map +0 -1
package/lib/expressions.js
CHANGED
|
@@ -8,6 +8,161 @@
|
|
|
8
8
|
function literal(value) {
|
|
9
9
|
return JSON.stringify(value);
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Legacy `keyCode` values the common keys need: libraries still read them, and
|
|
13
|
+
* a synthesized `KeyboardEvent` carries none by default.
|
|
14
|
+
*/
|
|
15
|
+
const KEY_CODES = {
|
|
16
|
+
Enter: 13,
|
|
17
|
+
Escape: 27,
|
|
18
|
+
Tab: 9,
|
|
19
|
+
Backspace: 8,
|
|
20
|
+
Delete: 46,
|
|
21
|
+
ArrowUp: 38,
|
|
22
|
+
ArrowDown: 40,
|
|
23
|
+
ArrowLeft: 37,
|
|
24
|
+
ArrowRight: 39,
|
|
25
|
+
Home: 36,
|
|
26
|
+
End: 35,
|
|
27
|
+
PageUp: 33,
|
|
28
|
+
PageDown: 34,
|
|
29
|
+
' ': 32,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Press expression: dispatch one key on a matched element, or on whatever
|
|
33
|
+
* currently has focus.
|
|
34
|
+
*
|
|
35
|
+
* Synthetic key events do not trigger the browser's own default actions, so
|
|
36
|
+
* `Enter` in a form would type nothing and submit nothing. The expression
|
|
37
|
+
* therefore submits the owning form explicitly and reports that it did, rather
|
|
38
|
+
* than leaving the caller to guess why nothing happened.
|
|
39
|
+
* @param key - the `KeyboardEvent.key` value, e.g. `Enter` or `ArrowDown`.
|
|
40
|
+
* @param selector - element to focus first; omit to press on the focused element.
|
|
41
|
+
* @returns a self-contained expression evaluating to `{ found, pressed, submitted }`.
|
|
42
|
+
*/
|
|
43
|
+
export function pressExpression(key, selector) {
|
|
44
|
+
const target = selector === undefined
|
|
45
|
+
? 'document.activeElement'
|
|
46
|
+
: `document.querySelector(${literal(selector)})`;
|
|
47
|
+
return `(() => {
|
|
48
|
+
const el = ${target}
|
|
49
|
+
if (el === null) return { found: false, pressed: false, submitted: false }
|
|
50
|
+
const node = el ?? document.body
|
|
51
|
+
if (typeof node.focus === 'function') node.focus()
|
|
52
|
+
const init = { key: ${literal(key)}, bubbles: true, cancelable: true, keyCode: ${KEY_CODES[key] ?? 0} }
|
|
53
|
+
node.dispatchEvent(new KeyboardEvent('keydown', init))
|
|
54
|
+
node.dispatchEvent(new KeyboardEvent('keypress', init))
|
|
55
|
+
node.dispatchEvent(new KeyboardEvent('keyup', init))
|
|
56
|
+
let submitted = false
|
|
57
|
+
if (init.key === 'Enter') {
|
|
58
|
+
const form = node.form ?? (typeof node.closest === 'function' ? node.closest('form') : null)
|
|
59
|
+
if (form !== null && form !== undefined && typeof form.requestSubmit === 'function') {
|
|
60
|
+
form.requestSubmit()
|
|
61
|
+
submitted = true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { found: true, pressed: true, submitted }
|
|
65
|
+
})()`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Select expression: set a `<select>`'s value and fire the events a controlled
|
|
69
|
+
* component listens for, through the prototype setter so frameworks that patch
|
|
70
|
+
* the instance still see the change.
|
|
71
|
+
*
|
|
72
|
+
* A value with no matching option leaves the select unchanged; the result says
|
|
73
|
+
* so and lists what was available instead of reporting a success the page never
|
|
74
|
+
* saw.
|
|
75
|
+
* @param selector - CSS selector for the `<select>`.
|
|
76
|
+
* @param value - the option value to select.
|
|
77
|
+
* @returns a self-contained expression evaluating to the selection outcome.
|
|
78
|
+
*/
|
|
79
|
+
export function selectExpression(selector, value) {
|
|
80
|
+
return `(() => {
|
|
81
|
+
const el = document.querySelector(${literal(selector)})
|
|
82
|
+
if (el === null) return { matched: 0, changed: false, value: '', options: [] }
|
|
83
|
+
if (!(el instanceof HTMLSelectElement)) {
|
|
84
|
+
return { matched: 1, changed: false, value: '', options: [], reason: 'not a <select>' }
|
|
85
|
+
}
|
|
86
|
+
const all = Array.from(el.options).map((option) => option.value)
|
|
87
|
+
const options = all.slice(0, 30)
|
|
88
|
+
// Checked BEFORE assigning: assigning a value no option carries sets
|
|
89
|
+
// selectedIndex to -1 and clears the control, so a call that is about to be
|
|
90
|
+
// rejected would still wipe the selection the user had.
|
|
91
|
+
if (all.indexOf(${literal(value)}) === -1) {
|
|
92
|
+
return { matched: 1, changed: false, value: el.value, options }
|
|
93
|
+
}
|
|
94
|
+
const setter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value').set
|
|
95
|
+
setter.call(el, ${literal(value)})
|
|
96
|
+
const changed = el.value === ${literal(value)}
|
|
97
|
+
if (changed) {
|
|
98
|
+
el.dispatchEvent(new Event('input', { bubbles: true }))
|
|
99
|
+
el.dispatchEvent(new Event('change', { bubbles: true }))
|
|
100
|
+
}
|
|
101
|
+
return { matched: 1, changed, value: el.value, options }
|
|
102
|
+
})()`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Poll expression for one wait condition: does the selector currently satisfy
|
|
106
|
+
* `state`? Resolved fresh on every poll, because the page changes between them.
|
|
107
|
+
* @param selector - CSS selector to test.
|
|
108
|
+
* @param state - the condition to test for.
|
|
109
|
+
* @returns a self-contained expression evaluating to a boolean.
|
|
110
|
+
*/
|
|
111
|
+
export function waitExpression(selector, state) {
|
|
112
|
+
const condition = {
|
|
113
|
+
attached: 'attached',
|
|
114
|
+
detached: '!attached',
|
|
115
|
+
visible: 'attached && shown',
|
|
116
|
+
hidden: '!attached || !shown',
|
|
117
|
+
}[state];
|
|
118
|
+
return `(() => {
|
|
119
|
+
const el = document.querySelector(${literal(selector)})
|
|
120
|
+
const attached = el !== null
|
|
121
|
+
let shown = false
|
|
122
|
+
if (attached) {
|
|
123
|
+
const rect = el.getBoundingClientRect()
|
|
124
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
125
|
+
const style = getComputedStyle(el)
|
|
126
|
+
shown = style.visibility !== 'hidden' && style.display !== 'none'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return ${condition}
|
|
130
|
+
})()`;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Hover expression: dispatch the pointer events a hover-driven menu listens for
|
|
134
|
+
* on the first match.
|
|
135
|
+
*
|
|
136
|
+
* These are synthetic: they reach listeners the page attached, but they do not
|
|
137
|
+
* set the browser's own hover state, so a control revealed purely by a CSS
|
|
138
|
+
* `:hover` rule will not appear. The alternative — real pointer input — is not
|
|
139
|
+
* available on the extension bridge, so both backends behave the same.
|
|
140
|
+
* @param selector - CSS selector to hover.
|
|
141
|
+
* @returns a self-contained expression evaluating to `{ matched, hovered }`.
|
|
142
|
+
*/
|
|
143
|
+
export function hoverExpression(selector) {
|
|
144
|
+
return `(() => {
|
|
145
|
+
const el = document.querySelector(${literal(selector)})
|
|
146
|
+
if (el === null) return { matched: 0, hovered: false }
|
|
147
|
+
const rect = el.getBoundingClientRect()
|
|
148
|
+
const init = {
|
|
149
|
+
bubbles: true,
|
|
150
|
+
cancelable: true,
|
|
151
|
+
view: window,
|
|
152
|
+
clientX: rect.left + rect.width / 2,
|
|
153
|
+
clientY: rect.top + rect.height / 2,
|
|
154
|
+
}
|
|
155
|
+
const Pointer = typeof PointerEvent === 'function' ? PointerEvent : MouseEvent
|
|
156
|
+
for (const type of ['pointerover', 'mouseover', 'pointermove', 'mousemove']) {
|
|
157
|
+
el.dispatchEvent(new Pointer(type, init))
|
|
158
|
+
}
|
|
159
|
+
// Enter does not bubble; it is delivered on the target only.
|
|
160
|
+
for (const type of ['pointerenter', 'mouseenter']) {
|
|
161
|
+
el.dispatchEvent(new Pointer(type, { ...init, bubbles: false }))
|
|
162
|
+
}
|
|
163
|
+
return { matched: 1, hovered: true }
|
|
164
|
+
})()`;
|
|
165
|
+
}
|
|
11
166
|
/** Live page-facts expression: title, url, visible text, optional HTML. */
|
|
12
167
|
export function readPageExpression(includeHtml) {
|
|
13
168
|
const htmlPart = includeHtml
|
|
@@ -27,24 +182,132 @@ export function readyStateExpression() {
|
|
|
27
182
|
return 'document.readyState';
|
|
28
183
|
}
|
|
29
184
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
185
|
+
* Page-side clickability probe, shared with the extension bridge: the same
|
|
186
|
+
* function body exists in `extension/service-worker.js` (`describeTarget`), and
|
|
187
|
+
* the two must stay in step — the bridge cannot import this module.
|
|
188
|
+
*
|
|
189
|
+
* `disabled` is the only state that suppresses the click event outright, so it
|
|
190
|
+
* is the only one the caller refuses to click. The others are reported because
|
|
191
|
+
* a click can be dispatched while a real pointer could never have reached the
|
|
192
|
+
* element, which is exactly the case a caller must not mistake for success.
|
|
193
|
+
*/
|
|
194
|
+
const CLICK_PROBE = `const probe = (el) => {
|
|
195
|
+
if (el.disabled === true) return 'disabled'
|
|
196
|
+
const rect = el.getBoundingClientRect()
|
|
197
|
+
if (rect.width === 0 || rect.height === 0) return 'invisible'
|
|
198
|
+
const style = getComputedStyle(el)
|
|
199
|
+
if (style.visibility === 'hidden' || style.display === 'none') return 'invisible'
|
|
200
|
+
const x = rect.left + rect.width / 2
|
|
201
|
+
const y = rect.top + rect.height / 2
|
|
202
|
+
if (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight) return 'offscreen'
|
|
203
|
+
const root = el.getRootNode()
|
|
204
|
+
const from = root && typeof root.elementFromPoint === 'function' ? root : document
|
|
205
|
+
const hit = from.elementFromPoint(x, y)
|
|
206
|
+
if (hit === null) return 'offscreen'
|
|
207
|
+
return hit === el || el.contains(hit) ? 'ok' : 'covered'
|
|
208
|
+
}`;
|
|
209
|
+
/**
|
|
210
|
+
* Click expression. Returns one outcome per call: how many elements the
|
|
211
|
+
* selector matched, how many received a dispatched click, and why the rest did
|
|
212
|
+
* not or may not have taken effect. `all` clicks every match, otherwise only
|
|
213
|
+
* the first.
|
|
214
|
+
* @param selector - CSS selector to resolve.
|
|
215
|
+
* @param all - whether to click every match instead of the first.
|
|
216
|
+
* @returns a self-contained expression evaluating to the click outcome.
|
|
32
217
|
*/
|
|
33
218
|
export function clickExpression(selector, all) {
|
|
34
219
|
const sel = literal(selector);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
220
|
+
const targets = all ? 'Array.from(matched)' : 'matched.length > 0 ? [matched[0]] : []';
|
|
221
|
+
return `(() => {
|
|
222
|
+
${CLICK_PROBE}
|
|
223
|
+
const matched = document.querySelectorAll(${sel})
|
|
224
|
+
const targets = ${targets}
|
|
225
|
+
const outcome = { matched: matched.length, clicked: 0, disabled: 0, invisible: 0, offscreen: 0, covered: 0, ariaDisabled: 0 }
|
|
226
|
+
for (const el of targets) {
|
|
227
|
+
const state = probe(el)
|
|
228
|
+
if (state === 'disabled') { outcome.disabled++; continue }
|
|
229
|
+
if (state !== 'ok') outcome[state]++
|
|
230
|
+
if (el.getAttribute('aria-disabled') === 'true') outcome.ariaDisabled++
|
|
45
231
|
el.click()
|
|
46
|
-
|
|
47
|
-
}
|
|
232
|
+
outcome.clicked++
|
|
233
|
+
}
|
|
234
|
+
return outcome
|
|
235
|
+
})()`;
|
|
236
|
+
}
|
|
237
|
+
/** Elements the interactive inventory considers actionable. */
|
|
238
|
+
export const INTERACTIVE_SELECTOR = 'a[href],button,input,select,textarea,[role=button],[role=link],'
|
|
239
|
+
+ '[role=checkbox],[role=radio],[role=tab],[role=menuitem],[role=switch],[contenteditable=""],[contenteditable=true]';
|
|
240
|
+
/** Elements one inventory returns; a longer page is reported as capped. */
|
|
241
|
+
export const INVENTORY_LIMIT = 150;
|
|
242
|
+
/** Characters one inventory entry's name keeps. */
|
|
243
|
+
const MAX_NAME_CHARS = 80;
|
|
244
|
+
/**
|
|
245
|
+
* Interactive-element inventory expression: what a reader can act on, with the
|
|
246
|
+
* selector to act on it, instead of the page's prose. Shares the click probe
|
|
247
|
+
* with {@link clickExpression}, so `covered` here means the same thing it means
|
|
248
|
+
* in a click result.
|
|
249
|
+
*
|
|
250
|
+
* The extension bridge runs the same inventory in
|
|
251
|
+
* `extension/service-worker.js` (`interactiveInventory`), because it cannot
|
|
252
|
+
* import host modules; tests/inventory.spec.ts requires the two to agree.
|
|
253
|
+
* @returns a self-contained expression evaluating to `{ matched, items }`.
|
|
254
|
+
*/
|
|
255
|
+
export function inventoryExpression() {
|
|
256
|
+
return `(() => {
|
|
257
|
+
${CLICK_PROBE}
|
|
258
|
+
const SELECTOR = ${JSON.stringify(INTERACTIVE_SELECTOR)}
|
|
259
|
+
const LIMIT = ${INVENTORY_LIMIT}
|
|
260
|
+
const MAX_NAME = ${MAX_NAME_CHARS}
|
|
261
|
+
const escape = (value) => (typeof CSS !== 'undefined' && CSS.escape
|
|
262
|
+
? CSS.escape(value)
|
|
263
|
+
: String(value).replace(/[^a-zA-Z0-9_-]/g, (ch) => '\\\\' + ch))
|
|
264
|
+
const stableSelector = (el) => {
|
|
265
|
+
if (el.id) {
|
|
266
|
+
const byId = '#' + escape(el.id)
|
|
267
|
+
try { if (document.querySelectorAll(byId).length === 1) return byId } catch (error) { /* unusable id */ }
|
|
268
|
+
}
|
|
269
|
+
const parts = []
|
|
270
|
+
let node = el
|
|
271
|
+
for (let depth = 0; node && node.nodeType === 1 && depth < 4; depth++) {
|
|
272
|
+
const tag = node.tagName.toLowerCase()
|
|
273
|
+
const parent = node.parentElement
|
|
274
|
+
if (parent === null) { parts.unshift(tag); break }
|
|
275
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === node.tagName)
|
|
276
|
+
parts.unshift(siblings.length > 1 ? tag + ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')' : tag)
|
|
277
|
+
node = parent
|
|
278
|
+
}
|
|
279
|
+
return parts.join(' > ')
|
|
280
|
+
}
|
|
281
|
+
const nameOf = (el) => {
|
|
282
|
+
const raw = el.getAttribute('aria-label')
|
|
283
|
+
|| (el.innerText && el.innerText.trim())
|
|
284
|
+
|| el.value
|
|
285
|
+
|| el.getAttribute('placeholder')
|
|
286
|
+
|| el.getAttribute('title')
|
|
287
|
+
|| el.getAttribute('name')
|
|
288
|
+
|| ''
|
|
289
|
+
return String(raw).replace(/\\s+/g, ' ').trim().slice(0, MAX_NAME)
|
|
290
|
+
}
|
|
291
|
+
const matched = document.querySelectorAll(SELECTOR)
|
|
292
|
+
const items = []
|
|
293
|
+
for (const el of matched) {
|
|
294
|
+
if (items.length >= LIMIT) break
|
|
295
|
+
const rect = el.getBoundingClientRect()
|
|
296
|
+
if (rect.width === 0 || rect.height === 0) continue
|
|
297
|
+
const style = getComputedStyle(el)
|
|
298
|
+
if (style.visibility === 'hidden' || style.display === 'none') continue
|
|
299
|
+
const state = probe(el)
|
|
300
|
+
items.push({
|
|
301
|
+
selector: stableSelector(el),
|
|
302
|
+
role: el.getAttribute('role') || el.tagName.toLowerCase(),
|
|
303
|
+
name: nameOf(el),
|
|
304
|
+
inView: state !== 'offscreen',
|
|
305
|
+
disabled: el.disabled === true || el.getAttribute('aria-disabled') === 'true',
|
|
306
|
+
covered: state === 'covered',
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
return { title: document.title, url: location.href, matched: matched.length, items }
|
|
310
|
+
})()`;
|
|
48
311
|
}
|
|
49
312
|
/**
|
|
50
313
|
* Focus-only expression for typing without replacing existing content: focuses
|
package/lib/expressions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,WAAoB;IACrD,MAAM,QAAQ,GAAG,WAAW;QAC1B,CAAC,CAAC,oEAAoE;QACtE,CAAC,CAAC,IAAI,CAAA;IACR,OAAO;;sEAE6D,QAAQ;OACvE,CAAA;AACP,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,kBAAkB;IAChC,OAAO,4DAA4D,CAAA;AACrE,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,oBAAoB;IAClC,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG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M,cAAc,GAAG,EAAE,CAAA;AAEzB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO;MACH,WAAW;uBACM,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC;oBACvC,eAAe;uBACZ,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkD9B,CAAA;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC7B,OAAO;wCAC+B,GAAG;;;;OAIpC,CAAA;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACvD,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC7B,OAAO;wCAC+B,GAAG;;;;;;;;;;;OAWpC,CAAA;AACP,CAAC"}
|
package/lib/help.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The human-help channel behind `chrome_request_help`: the model asks the user
|
|
3
|
+
* to do a step only they can do — sign in, solve a CAPTCHA, approve a prompt —
|
|
4
|
+
* and waits for the answer instead of guessing at a login wall.
|
|
5
|
+
*
|
|
6
|
+
* The question service is reached structurally and through `ctx.inject`, so a
|
|
7
|
+
* composition without one keeps every other tool working and answers this one
|
|
8
|
+
* with a clear error rather than hanging or silently doing nothing.
|
|
9
|
+
* @module @liyuera/dsh-chrome-browser/help
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
/** Label the human picks to say the step is done; the answer is compared against it. */
|
|
13
|
+
export declare const HELP_DONE_LABEL = "\u5DF2\u5B8C\u6210,\u7EE7\u7EED";
|
|
14
|
+
/** Label the human picks to stop this line of work. */
|
|
15
|
+
export declare const HELP_SKIP_LABEL = "\u8DF3\u8FC7,\u505C\u6B62\u8FD9\u6761\u8DEF\u5F84";
|
|
16
|
+
/** One question as the question service takes it. */
|
|
17
|
+
export interface HelpQuestion {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly header?: string;
|
|
20
|
+
readonly question: string;
|
|
21
|
+
readonly detail?: string;
|
|
22
|
+
readonly options?: readonly {
|
|
23
|
+
readonly label: string;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
27
|
+
/** Structural view of the question service (`ctx.userQuestions`). */
|
|
28
|
+
export interface UserQuestionsLike {
|
|
29
|
+
/** Ask the scoped answerer waterfall and wait for the human's answer. */
|
|
30
|
+
ask(request: {
|
|
31
|
+
questions: readonly HelpQuestion[];
|
|
32
|
+
agent?: unknown;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
answers: readonly {
|
|
36
|
+
id: string;
|
|
37
|
+
selected: readonly string[];
|
|
38
|
+
custom?: string;
|
|
39
|
+
}[];
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
/** What one help request produced. */
|
|
43
|
+
export interface HelpOutcome {
|
|
44
|
+
/** Whether the human reported the step done. */
|
|
45
|
+
completed: boolean;
|
|
46
|
+
/** Free text the human added, when they added any. */
|
|
47
|
+
note?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Ask the human one thing and resolve with what they answered. */
|
|
50
|
+
export type HelpAsker = (reason: string, agent: unknown) => Promise<HelpOutcome>;
|
|
51
|
+
/**
|
|
52
|
+
* Build the asker over a live question service.
|
|
53
|
+
*
|
|
54
|
+
* The question offers exactly two answers, so the model cannot read an
|
|
55
|
+
* ambiguous reply as permission: anything that is not the done label — a skip,
|
|
56
|
+
* or a dismissal that comes back empty — means the step did not happen.
|
|
57
|
+
* @param questions - the resolved `ctx.userQuestions`.
|
|
58
|
+
* @returns the asker {@link HelpChannel.wire} takes.
|
|
59
|
+
*/
|
|
60
|
+
export declare function questionAsker(questions: UserQuestionsLike): HelpAsker;
|
|
61
|
+
/**
|
|
62
|
+
* The channel `chrome_request_help` speaks to. It starts unwired, because the
|
|
63
|
+
* question service may be absent or may resolve after this plugin applies;
|
|
64
|
+
* {@link registerHelpChannel} installs the asker once it exists.
|
|
65
|
+
*/
|
|
66
|
+
export declare class HelpChannel {
|
|
67
|
+
private asker;
|
|
68
|
+
/** Install the asker; the last wiring wins. */
|
|
69
|
+
wire(asker: HelpAsker): void;
|
|
70
|
+
/** Whether this composition can reach a human at all. */
|
|
71
|
+
get wired(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Ask the human to do a step and wait for their answer.
|
|
74
|
+
* @param reason - what the human must do, in their own language.
|
|
75
|
+
* @param agent - the asking agent, when the caller has one.
|
|
76
|
+
* @returns what the human answered.
|
|
77
|
+
* @throws when this composition exposes no question service.
|
|
78
|
+
*/
|
|
79
|
+
request(reason: string, agent: unknown): Promise<HelpOutcome>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Wire the channel once a question service exists in this composition. A
|
|
83
|
+
* composition without one never runs the callback, which is the intended
|
|
84
|
+
* degradation: the tool stays registered and explains itself.
|
|
85
|
+
* @param ctx - the plugin's Cordis context.
|
|
86
|
+
* @param channel - the channel `chrome_request_help` reads.
|
|
87
|
+
*/
|
|
88
|
+
export declare function registerHelpChannel(ctx: Context, channel: HelpChannel): void;
|
|
89
|
+
//# sourceMappingURL=help.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,wFAAwF;AACxF,eAAO,MAAM,eAAe,oCAAW,CAAA;AAEvC,uDAAuD;AACvD,eAAO,MAAM,eAAe,sDAAc,CAAA;AAE1C,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,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OAMG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;CAUpE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAM5E"}
|
package/lib/help.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The human-help channel behind `chrome_request_help`: the model asks the user
|
|
3
|
+
* to do a step only they can do — sign in, solve a CAPTCHA, approve a prompt —
|
|
4
|
+
* and waits for the answer instead of guessing at a login wall.
|
|
5
|
+
*
|
|
6
|
+
* The question service is reached structurally and through `ctx.inject`, so a
|
|
7
|
+
* composition without one keeps every other tool working and answers this one
|
|
8
|
+
* with a clear error rather than hanging or silently doing nothing.
|
|
9
|
+
* @module @liyuera/dsh-chrome-browser/help
|
|
10
|
+
*/
|
|
11
|
+
/** Label the human picks to say the step is done; the answer is compared against it. */
|
|
12
|
+
export const HELP_DONE_LABEL = '已完成,继续';
|
|
13
|
+
/** Label the human picks to stop this line of work. */
|
|
14
|
+
export const HELP_SKIP_LABEL = '跳过,停止这条路径';
|
|
15
|
+
/**
|
|
16
|
+
* Build the asker over a live question service.
|
|
17
|
+
*
|
|
18
|
+
* The question offers exactly two answers, so the model cannot read an
|
|
19
|
+
* ambiguous reply as permission: anything that is not the done label — a skip,
|
|
20
|
+
* or a dismissal that comes back empty — means the step did not happen.
|
|
21
|
+
* @param questions - the resolved `ctx.userQuestions`.
|
|
22
|
+
* @returns the asker {@link HelpChannel.wire} takes.
|
|
23
|
+
*/
|
|
24
|
+
export function questionAsker(questions) {
|
|
25
|
+
return async (reason, agent) => {
|
|
26
|
+
const answer = await questions.ask({
|
|
27
|
+
questions: [{
|
|
28
|
+
id: 'chrome-request-help',
|
|
29
|
+
header: '需要你在浏览器里操作一下',
|
|
30
|
+
question: reason,
|
|
31
|
+
detail: '做完后选「' + HELP_DONE_LABEL + '」,模型会接着往下走;'
|
|
32
|
+
+ '选「' + HELP_SKIP_LABEL + '」它会停下这条路径,不会反复重试。',
|
|
33
|
+
options: [
|
|
34
|
+
{ label: HELP_DONE_LABEL, description: '我已经做完了,继续' },
|
|
35
|
+
{ label: HELP_SKIP_LABEL, description: '不做了,让模型停止' },
|
|
36
|
+
],
|
|
37
|
+
}],
|
|
38
|
+
...(agent === undefined ? {} : { agent }),
|
|
39
|
+
});
|
|
40
|
+
const first = answer.answers[0];
|
|
41
|
+
const note = first?.custom;
|
|
42
|
+
return {
|
|
43
|
+
completed: first?.selected?.[0] === HELP_DONE_LABEL,
|
|
44
|
+
...(note === undefined || note === '' ? {} : { note }),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The channel `chrome_request_help` speaks to. It starts unwired, because the
|
|
50
|
+
* question service may be absent or may resolve after this plugin applies;
|
|
51
|
+
* {@link registerHelpChannel} installs the asker once it exists.
|
|
52
|
+
*/
|
|
53
|
+
export class HelpChannel {
|
|
54
|
+
asker;
|
|
55
|
+
/** Install the asker; the last wiring wins. */
|
|
56
|
+
wire(asker) {
|
|
57
|
+
this.asker = asker;
|
|
58
|
+
}
|
|
59
|
+
/** Whether this composition can reach a human at all. */
|
|
60
|
+
get wired() {
|
|
61
|
+
return this.asker !== undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Ask the human to do a step and wait for their answer.
|
|
65
|
+
* @param reason - what the human must do, in their own language.
|
|
66
|
+
* @param agent - the asking agent, when the caller has one.
|
|
67
|
+
* @returns what the human answered.
|
|
68
|
+
* @throws when this composition exposes no question service.
|
|
69
|
+
*/
|
|
70
|
+
async request(reason, agent) {
|
|
71
|
+
const asker = this.asker;
|
|
72
|
+
if (asker === undefined) {
|
|
73
|
+
throw new Error('chrome_request_help: this dsh composition exposes no user-question service, so the plugin cannot reach'
|
|
74
|
+
+ ' you. Continue without the step — and say in your reply what you needed the user to do.');
|
|
75
|
+
}
|
|
76
|
+
return await asker(reason, agent);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Wire the channel once a question service exists in this composition. A
|
|
81
|
+
* composition without one never runs the callback, which is the intended
|
|
82
|
+
* degradation: the tool stays registered and explains itself.
|
|
83
|
+
* @param ctx - the plugin's Cordis context.
|
|
84
|
+
* @param channel - the channel `chrome_request_help` reads.
|
|
85
|
+
*/
|
|
86
|
+
export function registerHelpChannel(ctx, channel) {
|
|
87
|
+
ctx.inject(['userQuestions'], (scoped) => {
|
|
88
|
+
const questions = scoped.get('userQuestions');
|
|
89
|
+
if (questions === undefined)
|
|
90
|
+
return;
|
|
91
|
+
channel.wire(questionAsker(questions));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=help.js.map
|
package/lib/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA;AAEvC,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA;AAgC1C;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,SAA4B;IACxD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC;YACjC,SAAS,EAAE,CAAC;oBACV,EAAE,EAAE,qBAAqB;oBACzB,MAAM,EAAE,cAAc;oBACtB,QAAQ,EAAE,MAAM;oBAChB,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,aAAa;0BAC7C,IAAI,GAAG,eAAe,GAAG,mBAAmB;oBAChD,OAAO,EAAE;wBACP,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE;w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AAE,CAAC,MAAM,EAAE,EAAE;QACvC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAkC,CAAA;QAC9E,IAAI,SAAS,KAAK,SAAS;YAAE,OAAM;QACnC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Protocol (cdp fallback): list tabs, read page content, navigate, open
|
|
5
5
|
* tabs, capture screenshots, click, type, and evaluate JS — plus the
|
|
6
6
|
* same-origin routes the browser half uses to list tabs, bind them per
|
|
7
|
-
* session, and serve the extension bridge WebSocket,
|
|
8
|
-
*
|
|
7
|
+
* session, and serve the extension bridge WebSocket, the pre-step hook that
|
|
8
|
+
* expands a tab citation into a context message, the `chrome-browser` agent
|
|
9
|
+
* skill (when this composition exposes a skill registry), and the human-help
|
|
10
|
+
* channel behind `chrome_request_help` (when it exposes a question service).
|
|
9
11
|
* @module @liyuera/dsh-chrome-browser
|
|
10
12
|
*/
|
|
11
13
|
import type { Context } from '@deepseek-ai/cordis';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAIxC,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,aAAa,CAAA;AAQnE,uBAAuB;AACvB,eAAO,MAAM,IAAI,mBAAmB,CAAA;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,UAAyB,CAAA;AAE5C,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,wGAAwG;IACxG,OAAO,CAAC,EAAE,WAAW,GAAG,KAAK,CAAA;IAC7B,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,iFAAiF;IACjF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,8FAA8F;IAC9F,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,mDAAmD;AACnD,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,kBAAkB,CAYvC,CAAA;AAEF;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,kBAAuB,GAAG,IAAI,CA0CzE"}
|
package/lib/index.js
CHANGED
|
@@ -4,16 +4,21 @@
|
|
|
4
4
|
* Protocol (cdp fallback): list tabs, read page content, navigate, open
|
|
5
5
|
* tabs, capture screenshots, click, type, and evaluate JS — plus the
|
|
6
6
|
* same-origin routes the browser half uses to list tabs, bind them per
|
|
7
|
-
* session, and serve the extension bridge WebSocket,
|
|
8
|
-
*
|
|
7
|
+
* session, and serve the extension bridge WebSocket, the pre-step hook that
|
|
8
|
+
* expands a tab citation into a context message, the `chrome-browser` agent
|
|
9
|
+
* skill (when this composition exposes a skill registry), and the human-help
|
|
10
|
+
* channel behind `chrome_request_help` (when it exposes a question service).
|
|
9
11
|
* @module @liyuera/dsh-chrome-browser
|
|
10
12
|
*/
|
|
11
13
|
import z from '@deepseek-ai/schemastery';
|
|
14
|
+
import { ActivityTracker, withActivity } from "./activity.js";
|
|
12
15
|
import { buildBackend } from "./backend.js";
|
|
13
|
-
import { SessionBindings } from "./bindings.js";
|
|
14
16
|
import { resolveChromeConfig } from "./chrome.js";
|
|
17
|
+
import { ConsoleLog } from "./console-log.js";
|
|
18
|
+
import { HelpChannel, registerHelpChannel } from "./help.js";
|
|
15
19
|
import { expandTabMentions } from "./mentions.js";
|
|
16
20
|
import { registerChromeRoutes } from "./routes.js";
|
|
21
|
+
import { registerChromeSkill } from "./skill.js";
|
|
17
22
|
import { chromeToolDefinitions } from "./tools.js";
|
|
18
23
|
/** Plugin identity. */
|
|
19
24
|
export const name = 'chrome-browser';
|
|
@@ -49,14 +54,26 @@ export const Config = z.object({
|
|
|
49
54
|
*/
|
|
50
55
|
export function apply(ctx, config = {}) {
|
|
51
56
|
const resolved = resolveChromeConfig(config);
|
|
52
|
-
|
|
57
|
+
// The console buffer lives here, in the long-lived host: the extension's
|
|
58
|
+
// service worker is suspended by Chrome and would lose it silently.
|
|
59
|
+
const consoleLog = new ConsoleLog();
|
|
60
|
+
const { backend, chrome } = buildBackend(resolved, (tabId, message) => {
|
|
61
|
+
consoleLog.append(tabId, message);
|
|
62
|
+
});
|
|
53
63
|
if (chrome !== undefined)
|
|
54
64
|
chrome.reclaimOwnedLeftover();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
// The help channel reaches the user through the harness's question service;
|
|
66
|
+
// it stays unwired (and says so) when this composition has none.
|
|
67
|
+
const help = new HelpChannel();
|
|
68
|
+
// Every tool execution is recorded here so the browser half can show what the
|
|
69
|
+
// agent is doing without reading the session stream itself.
|
|
70
|
+
const activity = new ActivityTracker();
|
|
71
|
+
for (const definition of chromeToolDefinitions(backend, resolved, consoleLog, help)) {
|
|
72
|
+
ctx.tools.register(withActivity(definition, activity));
|
|
58
73
|
}
|
|
59
|
-
|
|
74
|
+
registerHelpChannel(ctx, help);
|
|
75
|
+
registerChromeRoutes(ctx, backend, config.screenshotDir ?? resolveChromeConfig(config).screenshotDir, activity);
|
|
76
|
+
registerChromeSkill(ctx);
|
|
60
77
|
// A message citing tabs gains one context message carrying their URLs and
|
|
61
78
|
// ids. Only the messages this step admits are scanned, and the context
|
|
62
79
|
// message's own source keeps it out of the next scan.
|
|
@@ -67,6 +84,10 @@ export function apply(ctx, config = {}) {
|
|
|
67
84
|
const messages = await expandTabMentions(decision.messages, () => backend.listTabs());
|
|
68
85
|
return messages === undefined ? decision : { ...decision, messages };
|
|
69
86
|
}, { prepend: true });
|
|
70
|
-
ctx.effect(() => () =>
|
|
87
|
+
ctx.effect(() => () => {
|
|
88
|
+
consoleLog.releaseAll();
|
|
89
|
+
activity.clear();
|
|
90
|
+
backend.dispose();
|
|
91
|
+
}, 'chrome-browser: backend lifecycle');
|
|
71
92
|
}
|
|
72
93
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,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