@liyuera/dsh-chrome-browser 0.2.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.
Files changed (96) hide show
  1. package/README.md +270 -20
  2. package/extension/manifest.json +4 -3
  3. package/extension/service-worker.js +721 -68
  4. package/lib/activity.d.ts +65 -0
  5. package/lib/activity.d.ts.map +1 -0
  6. package/lib/activity.js +111 -0
  7. package/lib/activity.js.map +1 -0
  8. package/lib/backend.d.ts +193 -11
  9. package/lib/backend.d.ts.map +1 -1
  10. package/lib/backend.js +344 -39
  11. package/lib/backend.js.map +1 -1
  12. package/lib/cdp.d.ts +7 -1
  13. package/lib/cdp.d.ts.map +1 -1
  14. package/lib/cdp.js +17 -1
  15. package/lib/cdp.js.map +1 -1
  16. package/lib/chrome.d.ts +8 -0
  17. package/lib/chrome.d.ts.map +1 -1
  18. package/lib/chrome.js +20 -0
  19. package/lib/chrome.js.map +1 -1
  20. package/lib/client/BrowserActivity.d.ts +22 -0
  21. package/lib/client/BrowserActivity.d.ts.map +1 -0
  22. package/lib/client/BrowserActivity.js +100 -0
  23. package/lib/client/BrowserActivity.js.map +1 -0
  24. package/lib/client/activity.d.ts +27 -0
  25. package/lib/client/activity.d.ts.map +1 -0
  26. package/lib/client/activity.js +57 -0
  27. package/lib/client/activity.js.map +1 -0
  28. package/lib/client/index.d.ts +4 -6
  29. package/lib/client/index.d.ts.map +1 -1
  30. package/lib/client/index.js +13 -19
  31. package/lib/client/index.js.map +1 -1
  32. package/lib/client/tab-catalog.d.ts +11 -1
  33. package/lib/client/tab-catalog.d.ts.map +1 -1
  34. package/lib/client/tab-catalog.js.map +1 -1
  35. package/lib/client/tab-source.d.ts +8 -2
  36. package/lib/client/tab-source.d.ts.map +1 -1
  37. package/lib/client/tab-source.js.map +1 -1
  38. package/lib/client.js +177 -13
  39. package/lib/client.js.map +1 -1
  40. package/lib/console-events.d.ts +32 -0
  41. package/lib/console-events.d.ts.map +1 -0
  42. package/lib/console-events.js +106 -0
  43. package/lib/console-events.js.map +1 -0
  44. package/lib/console-log.d.ts +107 -0
  45. package/lib/console-log.d.ts.map +1 -0
  46. package/lib/console-log.js +158 -0
  47. package/lib/console-log.js.map +1 -0
  48. package/lib/expressions.d.ts +71 -2
  49. package/lib/expressions.d.ts.map +1 -1
  50. package/lib/expressions.js +277 -14
  51. package/lib/expressions.js.map +1 -1
  52. package/lib/extension-package.d.ts +33 -0
  53. package/lib/extension-package.d.ts.map +1 -0
  54. package/lib/extension-package.js +133 -0
  55. package/lib/extension-package.js.map +1 -0
  56. package/lib/help.d.ts +89 -0
  57. package/lib/help.d.ts.map +1 -0
  58. package/lib/help.js +94 -0
  59. package/lib/help.js.map +1 -0
  60. package/lib/index.d.ts +4 -2
  61. package/lib/index.d.ts.map +1 -1
  62. package/lib/index.js +30 -9
  63. package/lib/index.js.map +1 -1
  64. package/lib/presentation.d.ts +130 -0
  65. package/lib/presentation.d.ts.map +1 -0
  66. package/lib/presentation.js +361 -0
  67. package/lib/presentation.js.map +1 -0
  68. package/lib/routes.d.ts +3 -8
  69. package/lib/routes.d.ts.map +1 -1
  70. package/lib/routes.js +38 -99
  71. package/lib/routes.js.map +1 -1
  72. package/lib/skill.d.ts +50 -0
  73. package/lib/skill.d.ts.map +1 -0
  74. package/lib/skill.js +163 -0
  75. package/lib/skill.js.map +1 -0
  76. package/lib/text.d.ts +21 -0
  77. package/lib/text.d.ts.map +1 -1
  78. package/lib/text.js +18 -0
  79. package/lib/text.js.map +1 -1
  80. package/lib/tools.d.ts +22 -4
  81. package/lib/tools.d.ts.map +1 -1
  82. package/lib/tools.js +467 -75
  83. package/lib/tools.js.map +1 -1
  84. package/lib/ws.d.ts +9 -2
  85. package/lib/ws.d.ts.map +1 -1
  86. package/lib/ws.js +49 -19
  87. package/lib/ws.js.map +1 -1
  88. package/package.json +4 -3
  89. package/lib/bindings.d.ts +0 -23
  90. package/lib/bindings.d.ts.map +0 -1
  91. package/lib/bindings.js +0 -49
  92. package/lib/bindings.js.map +0 -1
  93. package/lib/client/TabPicker.d.ts +0 -54
  94. package/lib/client/TabPicker.d.ts.map +0 -1
  95. package/lib/client/TabPicker.js +0 -329
  96. package/lib/client/TabPicker.js.map +0 -1
@@ -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
- * Click expression. Returns the number of elements matched and clicked:
31
- * `all` clicks every match, otherwise only the first.
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
- return all
36
- ? `(() => {
37
- const els = document.querySelectorAll(${sel});
38
- let n = 0;
39
- for (const el of els) { el.click(); n++ }
40
- return n
41
- })()`
42
- : `(() => {
43
- const el = document.querySelector(${sel});
44
- if (!el) return 0
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
- return 1
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
@@ -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;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,GAAY;IAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC7B,OAAO,GAAG;QACR,CAAC,CAAC;8CACwC,GAAG;;;;SAIxC;QACL,CAAC,CAAC;0CACoC,GAAG;;;;SAIpC,CAAA;AACT,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"}
1
+ {"version":3,"file":"expressions.js","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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,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"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The unpacked Chrome extension shipped inside this package.
3
+ *
4
+ * An npm install places the extension beside the built host half, where a user
5
+ * has no obvious way to find it, so the plugin serves the same files as a zip
6
+ * over its own web server. Every entry name carries one root folder, so
7
+ * unpacking the archive yields a directory Chrome accepts directly.
8
+ * @module @liyuera/dsh-chrome-browser/extension-package
9
+ */
10
+ /** Root folder every entry name inside the served zip starts with. */
11
+ export declare const EXTENSION_ZIP_ROOT = "dsh-chrome-browser-extension";
12
+ /**
13
+ * Standard CRC-32 of one buffer, as ZIP entries require.
14
+ * @param data - bytes to checksum.
15
+ * @returns the unsigned 32-bit checksum.
16
+ */
17
+ export declare function crc32(data: Buffer): number;
18
+ /**
19
+ * Absolute path of the extension folder beside one built module.
20
+ * @param moduleUrl - `import.meta.url` of the module resolving the folder.
21
+ * @returns the absolute extension directory path.
22
+ */
23
+ export declare function extensionDir(moduleUrl: string): string;
24
+ /**
25
+ * Build an uncompressed zip archive of one directory tree.
26
+ *
27
+ * Entries use the STORE method: the extension is a few kilobytes, and storing
28
+ * keeps the writer free of a compression dependency.
29
+ * @param directory - directory whose files become the archive contents.
30
+ * @returns the complete zip archive.
31
+ */
32
+ export declare function createExtensionZip(directory: string): Buffer;
33
+ //# sourceMappingURL=extension-package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-package.d.ts","sourceRoot":"","sources":["../src/extension-package.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,iCAAiC,CAAA;AA8BhE;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AAoBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CA0D5D"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The unpacked Chrome extension shipped inside this package.
3
+ *
4
+ * An npm install places the extension beside the built host half, where a user
5
+ * has no obvious way to find it, so the plugin serves the same files as a zip
6
+ * over its own web server. Every entry name carries one root folder, so
7
+ * unpacking the archive yields a directory Chrome accepts directly.
8
+ * @module @liyuera/dsh-chrome-browser/extension-package
9
+ */
10
+ import { readFileSync, readdirSync } from 'node:fs';
11
+ import { join, relative, sep } from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ /** Root folder every entry name inside the served zip starts with. */
14
+ export const EXTENSION_ZIP_ROOT = 'dsh-chrome-browser-extension';
15
+ /**
16
+ * Fixed DOS timestamp (2026-01-01T00:00:00Z) so identical files serve
17
+ * byte-identical archives and tests can compare whole buffers.
18
+ */
19
+ const DOS_TIME = 0;
20
+ const DOS_DATE = ((2026 - 1980) << 9) | (1 << 5) | 1;
21
+ /** CRC-32 lookup table, built once. */
22
+ const CRC_TABLE = (() => {
23
+ const table = new Uint32Array(256);
24
+ for (let index = 0; index < 256; index += 1) {
25
+ let value = index;
26
+ for (let bit = 0; bit < 8; bit += 1) {
27
+ value = (value & 1) === 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
28
+ }
29
+ table[index] = value >>> 0;
30
+ }
31
+ return table;
32
+ })();
33
+ /**
34
+ * Standard CRC-32 of one buffer, as ZIP entries require.
35
+ * @param data - bytes to checksum.
36
+ * @returns the unsigned 32-bit checksum.
37
+ */
38
+ export function crc32(data) {
39
+ let crc = 0xffffffff;
40
+ for (const byte of data) {
41
+ crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
42
+ }
43
+ return (crc ^ 0xffffffff) >>> 0;
44
+ }
45
+ /**
46
+ * Absolute path of the extension folder beside one built module.
47
+ * @param moduleUrl - `import.meta.url` of the module resolving the folder.
48
+ * @returns the absolute extension directory path.
49
+ */
50
+ export function extensionDir(moduleUrl) {
51
+ return fileURLToPath(new URL('../extension/', moduleUrl));
52
+ }
53
+ /** Collect every regular file under one directory, sorted for a stable archive. */
54
+ function collectFiles(root, current) {
55
+ const entries = [];
56
+ for (const item of readdirSync(current, { withFileTypes: true })) {
57
+ const absolute = join(current, item.name);
58
+ if (item.isDirectory()) {
59
+ entries.push(...collectFiles(root, absolute));
60
+ continue;
61
+ }
62
+ if (!item.isFile())
63
+ continue;
64
+ entries.push({
65
+ name: `${EXTENSION_ZIP_ROOT}/${relative(root, absolute).split(sep).join('/')}`,
66
+ data: readFileSync(absolute),
67
+ });
68
+ }
69
+ return entries.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
70
+ }
71
+ /**
72
+ * Build an uncompressed zip archive of one directory tree.
73
+ *
74
+ * Entries use the STORE method: the extension is a few kilobytes, and storing
75
+ * keeps the writer free of a compression dependency.
76
+ * @param directory - directory whose files become the archive contents.
77
+ * @returns the complete zip archive.
78
+ */
79
+ export function createExtensionZip(directory) {
80
+ const files = collectFiles(directory, directory);
81
+ const parts = [];
82
+ const central = [];
83
+ let offset = 0;
84
+ for (const file of files) {
85
+ const name = Buffer.from(file.name, 'utf8');
86
+ const checksum = crc32(file.data);
87
+ const local = Buffer.alloc(30);
88
+ local.writeUInt32LE(0x04034b50, 0);
89
+ local.writeUInt16LE(20, 4);
90
+ local.writeUInt16LE(0x0800, 6);
91
+ local.writeUInt16LE(0, 8);
92
+ local.writeUInt16LE(DOS_TIME, 10);
93
+ local.writeUInt16LE(DOS_DATE, 12);
94
+ local.writeUInt32LE(checksum, 14);
95
+ local.writeUInt32LE(file.data.length, 18);
96
+ local.writeUInt32LE(file.data.length, 22);
97
+ local.writeUInt16LE(name.length, 26);
98
+ local.writeUInt16LE(0, 28);
99
+ const entry = Buffer.alloc(46);
100
+ entry.writeUInt32LE(0x02014b50, 0);
101
+ entry.writeUInt16LE(20, 4);
102
+ entry.writeUInt16LE(20, 6);
103
+ entry.writeUInt16LE(0x0800, 8);
104
+ entry.writeUInt16LE(0, 10);
105
+ entry.writeUInt16LE(DOS_TIME, 12);
106
+ entry.writeUInt16LE(DOS_DATE, 14);
107
+ entry.writeUInt32LE(checksum, 16);
108
+ entry.writeUInt32LE(file.data.length, 20);
109
+ entry.writeUInt32LE(file.data.length, 24);
110
+ entry.writeUInt16LE(name.length, 28);
111
+ entry.writeUInt16LE(0, 30);
112
+ entry.writeUInt16LE(0, 32);
113
+ entry.writeUInt16LE(0, 34);
114
+ entry.writeUInt16LE(0, 36);
115
+ entry.writeUInt32LE(0, 38);
116
+ entry.writeUInt32LE(offset, 42);
117
+ parts.push(local, name, file.data);
118
+ central.push(entry, name);
119
+ offset += local.length + name.length + file.data.length;
120
+ }
121
+ const directoryBytes = Buffer.concat(central);
122
+ const end = Buffer.alloc(22);
123
+ end.writeUInt32LE(0x06054b50, 0);
124
+ end.writeUInt16LE(0, 4);
125
+ end.writeUInt16LE(0, 6);
126
+ end.writeUInt16LE(files.length, 8);
127
+ end.writeUInt16LE(files.length, 10);
128
+ end.writeUInt32LE(directoryBytes.length, 12);
129
+ end.writeUInt32LE(offset, 16);
130
+ end.writeUInt16LE(0, 20);
131
+ return Buffer.concat([...parts, directoryBytes, end]);
132
+ }
133
+ //# sourceMappingURL=extension-package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-package.js","sourceRoot":"","sources":["../src/extension-package.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,sEAAsE;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAA;AAEhE;;;GAGG;AACH,MAAM,QAAQ,GAAG,CAAC,CAAA;AAClB,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;AAUpD,uCAAuC;AACvC,MAAM,SAAS,GAAG,CAAC,GAAgB,EAAE;IACnC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAA;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC5C,IAAI,KAAK,GAAG,KAAK,CAAA;QACjB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;YACpC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAA;QACtE,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,KAAK,CAAC,CAAA;IAC5B,C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AG,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC,CAAA;AACvD,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,E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