@broberg/lens-daemon 0.1.51 → 0.1.52

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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/owner-fill.ts +33 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@broberg/lens-daemon",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "The Lens module of the cardmem daemon (flows, critic, coverage, capture sessions, the /lens/* routes and the cardmem-lens MCP) as a package. The daemon mounts createLensRouter(deps) + createLensMcpRouter(deps). Bun runtime.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "sharp": "^0.35.5",
16
16
  "turndown": "^7.2.4",
17
17
  "zod": "^3.23.8",
18
- "@broberg/lens-svg": "0.1.1",
19
- "@broberg/lens-engine": "0.14.1"
18
+ "@broberg/lens-engine": "0.14.1",
19
+ "@broberg/lens-svg": "0.1.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@happy-dom/global-registrator": "^20.10.6",
package/src/owner-fill.ts CHANGED
@@ -87,9 +87,42 @@ export async function fillFromOwner(loc: Locator, of: OwnerFrom, fillTimeout: nu
87
87
  if (res.status === 'expired') throw new Error(`fill from owner: expired — no answer to «${of.question}» in time`);
88
88
  if (res.status === 'error') throw new Error(`fill from owner: ARS failed — ${res.reason}`);
89
89
  if (!res.answer) throw new Error('fill from owner: ARS answered with an empty value');
90
+ // F010.11 — a code field split into one box per character (Microsoft's «Enter your
91
+ // code»): type it key by key from the first box and let the page advance.
92
+ const oneCharBox = await loc.evaluate((el) => (el as HTMLInputElement).maxLength === 1).catch(() => false);
93
+ if (oneCharBox && res.answer.length > 1) {
94
+ await typeIntoBoxes(loc, res.answer, kind, fillTimeout);
95
+ return;
96
+ }
90
97
  try {
91
98
  await fillAndVerify(loc, res.answer, fillTimeout);
92
99
  } catch {
93
100
  throw new Error(`fill from owner did not land: expected a ${res.answer.length}-character ${kind} in the field (value withheld)`);
94
101
  }
95
102
  }
103
+
104
+ /** F010.11 — the joined value of the one-character boxes around `el`. */
105
+ function joinedBoxes(el: Element): string {
106
+ let group: Element | null = el.parentElement;
107
+ while (group && group.querySelectorAll('input').length < 2 && group.parentElement) group = group.parentElement;
108
+ return [...(group?.querySelectorAll('input') ?? [])]
109
+ .filter((i) => (i as HTMLInputElement).maxLength === 1)
110
+ .map((i) => (i as HTMLInputElement).value)
111
+ .join('');
112
+ }
113
+
114
+ async function typeIntoBoxes(loc: Locator, answer: string, kind: string, timeout: number): Promise<void> {
115
+ await loc.focus({ timeout });
116
+ await loc.pressSequentially(answer, { timeout });
117
+ let got: string;
118
+ try {
119
+ got = await loc.evaluate(joinedBoxes);
120
+ } catch (err) {
121
+ // The last digit often submits the form; the page leaving is the code landing.
122
+ if (/Execution context was destroyed|Cannot find context|has been closed|detached/i.test(err instanceof Error ? err.message : String(err))) return;
123
+ throw err;
124
+ }
125
+ if (got !== answer) {
126
+ throw new Error(`fill from owner did not land: expected a ${answer.length}-character ${kind} across the boxes, found ${got.length} (value withheld)`);
127
+ }
128
+ }