@broberg/lens-daemon 0.1.70 → 0.1.73

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 +2 -2
  2. package/src/flow.ts +18 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@broberg/lens-daemon",
3
- "version": "0.1.70",
3
+ "version": "0.1.73",
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-measure": "0.1.4",
18
19
  "@broberg/lens-engine": "0.14.1",
19
- "@broberg/lens-measure": "0.1.3",
20
20
  "@broberg/lens-svg": "0.1.1"
21
21
  },
22
22
  "devDependencies": {
package/src/flow.ts CHANGED
@@ -169,7 +169,8 @@ export type FlowStep =
169
169
  | { type: 'autocomplete'; testid: string; value: string; option: string; pickText?: string; pickIndex?: number; label?: string; timeout?: number }
170
170
  | { type: 'capture'; testid: string; as: string; from?: 'text' | 'value'; label?: string; timeout?: number }
171
171
  /** F010.15 — the value goes straight into cardmem's vault; the run only ever holds its receipt. */
172
- | { type: 'capture'; testid: string; to: 'vault'; vault: VaultTarget; label?: string; timeout?: number }
172
+ // F010.19 — a `target` (e.g. {css}) instead of a testid: a third-party console has no testids.
173
+ | { type: 'capture'; testid?: string; target?: Target; to: 'vault'; vault: VaultTarget; label?: string; timeout?: number }
173
174
  // F010.9 — `selector` (css) instead of `testid`, for a third-party page with no testids
174
175
  // (a login page whose next screen depends on the account).
175
176
  | { type: 'conditional'; testid?: string; selector?: string; present: boolean; steps: FlowStep[]; label?: string; timeout?: number }
@@ -816,7 +817,7 @@ export const STEP_FIELDS: Record<string, string[]> = {
816
817
  uploadFile: ['testid', 'path'],
817
818
  uploadSelector: ['selector', 'path', 'frame'],
818
819
  autocomplete: ['testid', 'value', 'option', 'pickText', 'pickIndex'],
819
- capture: ['testid', 'as', 'from', 'to', 'vault'],
820
+ capture: ['testid', 'target', 'as', 'from', 'to', 'vault'],
820
821
  conditional: ['testid', 'selector', 'present', 'steps'],
821
822
  loop: ['data', 'steps', 'parallel'],
822
823
  openPopup: ['path'],
@@ -940,7 +941,8 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
940
941
  }
941
942
  if (s.type === 'capture' && (s as { to?: unknown }).to !== undefined) {
942
943
  // F010.15 — to vault: a target, and never a variable that would hold the value.
943
- const c = s as { to?: unknown; vault?: unknown; as?: unknown; from?: unknown };
944
+ const c = s as { to?: unknown; vault?: unknown; as?: unknown; from?: unknown; testid?: unknown; target?: unknown };
945
+ if ((c.testid === undefined) === (c.target === undefined)) throw new Error('capture to vault needs exactly one of "testid" or "target"');
944
946
  const v = c.vault as Partial<VaultTarget> | undefined;
945
947
  if (c.to !== 'vault') throw new Error('capture step: "to" must be "vault"');
946
948
  if (c.as !== undefined || c.from !== undefined) throw new Error('capture to vault takes no "as"/"from" — the value must never become a flow variable');
@@ -949,6 +951,8 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
949
951
  || (v.env_var_name !== undefined && (typeof v.env_var_name !== 'string' || !/^[A-Z_][A-Z0-9_]*$/.test(v.env_var_name)))) {
950
952
  throw new Error('capture to vault needs vault: {project, name, env_var_name?} (env_var_name in UPPER_SNAKE_CASE)');
951
953
  }
954
+ } else if (s.type === 'capture' && (s as { target?: unknown }).target !== undefined) {
955
+ throw new Error('capture by "target" is only for capture to vault — a flow variable is read by testid');
952
956
  } else if (s.type === 'capture' && typeof (s as { as?: unknown }).as !== 'string') {
953
957
  throw new Error('capture step requires a string "as" name');
954
958
  }
@@ -1013,7 +1017,10 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
1013
1017
  throw new Error('conditional step requires exactly one of a string testid or a css selector');
1014
1018
  }
1015
1019
  }
1016
- if (testidOnly.includes(s.type) && typeof (s as { testid?: unknown }).testid !== 'string') {
1020
+ // F010.19 — capture to vault may name a `target` instead (a third-party console).
1021
+ const vaultTarget = s.type === 'capture' && (s as { to?: unknown }).to === 'vault' && (s as { target?: unknown }).target !== undefined;
1022
+ if (vaultTarget && !isValidTarget((s as { target?: unknown }).target)) throw new Error('capture to vault: "target" is not a valid target (e.g. {"css": "input.key"})');
1023
+ if (testidOnly.includes(s.type) && !vaultTarget && typeof (s as { testid?: unknown }).testid !== 'string') {
1017
1024
  throw new Error(`${s.type} step requires a string testid`);
1018
1025
  }
1019
1026
  if (targetable.includes(s.type)) {
@@ -1774,7 +1781,7 @@ function describe(step: FlowStep): string {
1774
1781
  case 'uploadFile': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.testid}`;
1775
1782
  case 'press': return `press ${step.key}${step.testid ? ` @${step.testid}` : ''}`;
1776
1783
  case 'autocomplete': return `autocomplete ${step.testid} → ${step.pickText !== undefined ? `"${step.pickText}"` : `#${step.pickIndex}`}`;
1777
- case 'capture': return 'to' in step ? `capture ${step.testid} → vault ${step.vault.project}/${step.vault.name}` : `capture ${step.testid} → {{${step.as}}}`;
1784
+ case 'capture': return 'to' in step ? `capture ${step.testid ?? targetSummary(step.target!)} → vault ${step.vault.project}/${step.vault.name}` : `capture ${step.testid} → {{${step.as}}}`;
1778
1785
  case 'conditional': return `${step.present ? 'if' : 'unless'} ${step.selector ?? `[${step.testid}]`}`;
1779
1786
  case 'loop': return 'loop';
1780
1787
  case 'openPopup': return `openPopup ${step.path ?? '(manifest popup)'}`;
@@ -2788,26 +2795,27 @@ async function execStep(page: Page, step: FlowStep, base: string, vars: Record<s
2788
2795
  // F213.3 — capture an element's text (or an input's value) into a named var,
2789
2796
  // reused by a later step via {{name}}. Mutates the shared `vars` in place.
2790
2797
  case 'capture': {
2791
- const loc = page.locator(sel(step.testid)).first();
2798
+ const loc = 'to' in step ? (await locate(page, step)).loc : page.locator(sel(step.testid)).first();
2792
2799
  await loc.waitFor({ state: 'attached', timeout: stepTimeout(step) });
2793
2800
  if ('to' in step) {
2801
+ const what = step.testid ?? targetSummary(step.target!);
2794
2802
  // F010.15 — read in the daemon, stored in the vault, never returned. Every
2795
2803
  // message below names the target and never the value.
2796
2804
  const writer = getVaultWriter();
2797
- if (!writer) throw new Error(`capture [${step.testid}] to vault: this daemon is not signed in to cardmem — nothing stored`);
2805
+ if (!writer) throw new Error(`capture [${what}] to vault: this daemon is not signed in to cardmem — nothing stored`);
2798
2806
  const value = (await loc.evaluate((el) => {
2799
2807
  const v = (el as HTMLInputElement).value;
2800
2808
  return typeof v === 'string' && v ? v : (el.textContent ?? '');
2801
2809
  }, undefined, { timeout: stepTimeout(step) })).trim();
2802
- if (!value) throw new Error(`capture [${step.testid}] to vault: the element holds no value — nothing stored`);
2810
+ if (!value) throw new Error(`capture [${what}] to vault: the element holds no value — nothing stored`);
2803
2811
  // Known to the run from here on, so F010.14 redacts it from every later report.
2804
- pwSink?.push({ anchor: step.testid, value });
2812
+ pwSink?.push({ anchor: what, value });
2805
2813
  let receipt: VaultReceipt;
2806
2814
  try {
2807
2815
  receipt = await writer(step.vault, value);
2808
2816
  } catch (err) {
2809
2817
  const why = (err instanceof Error ? err.message : String(err)).split(value).join('[redacted]');
2810
- throw new Error(`capture [${step.testid}] to vault ${step.vault.project}/${step.vault.name}: storing failed (${why}) — nothing confirmed stored`);
2818
+ throw new Error(`capture [${what}] to vault ${step.vault.project}/${step.vault.name}: storing failed (${why}) — nothing confirmed stored`);
2811
2819
  }
2812
2820
  return { __vault: receipt };
2813
2821
  }