@capagents/forgeqe 2.9.5 → 2.9.7

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 (97) hide show
  1. package/HOW_TO_USE.md +130 -1
  2. package/README.md +3 -0
  3. package/dist/docs-site/docs/architecture/index.html +1 -1
  4. package/dist/docs-site/docs/containers/index.html +2 -2
  5. package/dist/docs-site/docs/cost-architecture/index.html +1 -1
  6. package/dist/docs-site/docs/custom-agents-first-run/index.html +216 -0
  7. package/dist/docs-site/docs/desktop/index.html +1 -1
  8. package/dist/docs-site/docs/desktop-ci/index.html +1 -1
  9. package/dist/docs-site/docs/evidence/index.html +992 -0
  10. package/dist/docs-site/docs/feature-test-prompts/index.html +1 -1
  11. package/dist/docs-site/docs/graphify/index.html +380 -0
  12. package/dist/docs-site/docs/guardrails/index.html +2 -2
  13. package/dist/docs-site/docs/index.html +141 -6
  14. package/dist/docs-site/docs/mobile/index.html +1 -1
  15. package/dist/docs-site/docs/model-routing/index.html +1 -1
  16. package/dist/docs-site/docs/product-graph/index.html +356 -0
  17. package/dist/docs-site/docs/product-knowledge/index.html +3 -3
  18. package/dist/docs-site/docs/product-views/index.html +431 -0
  19. package/dist/docs-site/docs/search.js +1 -1
  20. package/dist/docs-site/docs/web-app/index.html +2 -2
  21. package/dist/forgeqe.js +1866 -1664
  22. package/dist/web/assets/{Agent-BU8FKiQt.js → Agent-I5mRol1P.js} +1 -1
  23. package/dist/web/assets/{ApiTests-Bsv3NhD5.js → ApiTests--JGFKbOa.js} +1 -1
  24. package/dist/web/assets/{Browse-D-ho9bS_.js → Browse-CIcl1j4N.js} +2 -2
  25. package/dist/web/assets/Chat-Baph1nlV.js +3 -0
  26. package/dist/web/assets/{CommandPalette-CrLuxoE5.js → CommandPalette-Dd0seTKQ.js} +1 -1
  27. package/dist/web/assets/{Compare-DfHMTNGi.js → Compare-B7barE31.js} +1 -1
  28. package/dist/web/assets/{Cost-BYb3T8-c.js → Cost-CGXZTXSz.js} +1 -1
  29. package/dist/web/assets/{Data-EF_k6c_T.js → Data-DGKi3KHS.js} +1 -1
  30. package/dist/web/assets/{Desktop-DY5Q1Sd3.js → Desktop-wfNhaxat.js} +1 -1
  31. package/dist/web/assets/{DesktopReview-DFKpYor2.js → DesktopReview-Cxn3mgKO.js} +1 -1
  32. package/dist/web/assets/{Evidence-Db9H4-Nu.js → Evidence-BZ-WKU9t.js} +1 -1
  33. package/dist/web/assets/{Explore-B0EkFCFe.js → Explore-pa8l7kiC.js} +1 -1
  34. package/dist/web/assets/{Features-8jsv2A1d.js → Features-JDMSSUpb.js} +1 -1
  35. package/dist/web/assets/{Flags-DtzmOA5o.js → Flags-DcWTBteQ.js} +1 -1
  36. package/dist/web/assets/{Flaky-BCzOx7Mq.js → Flaky-DnHWlzlk.js} +1 -1
  37. package/dist/web/assets/{ForceGraph-i1zlas5l.js → ForceGraph-BLYMwmyj.js} +1 -1
  38. package/dist/web/assets/{Impact-Da9L1tDd.js → Impact-Dn5PPQ5Z.js} +1 -1
  39. package/dist/web/assets/{Jobs-CHw00lcx.js → Jobs-CNhlUenm.js} +1 -1
  40. package/dist/web/assets/{KindPage-DiOmtzVZ.js → KindPage-BPwFdxHe.js} +1 -1
  41. package/dist/web/assets/{Migration-Cu4JgOj1.js → Migration-DsGwJd40.js} +1 -1
  42. package/dist/web/assets/{Product-DmvUI7pH.js → Product-DsolJU4Y.js} +1 -1
  43. package/dist/web/assets/{Production-CLoOV4jl.js → Production-Cnh3wWiK.js} +1 -1
  44. package/dist/web/assets/{Quality-ylTg9e0c.js → Quality-W_rQ6nRf.js} +1 -1
  45. package/dist/web/assets/{Readiness-BMD5Uj8D.js → Readiness-IWAIRZwC.js} +1 -1
  46. package/dist/web/assets/Record-DOImb7O7.js +2 -0
  47. package/dist/web/assets/{Regression-D_Hy9bMt.js → Regression-DQuiIAFx.js} +1 -1
  48. package/dist/web/assets/{Reports-DXphAHAy.js → Reports-C16UVZtQ.js} +1 -1
  49. package/dist/web/assets/{Response-PDQ8zEZU.js → Response-Vh2lEWnS.js} +1 -1
  50. package/dist/web/assets/{RunDiff-C3MIKipo.js → RunDiff-CVnhT7JE.js} +1 -1
  51. package/dist/web/assets/{Runs-DSQZwCpE.js → Runs-CI8NJB1v.js} +1 -1
  52. package/dist/web/assets/{Steps-CY6WROAr.js → Steps-Bwe4WAjy.js} +1 -1
  53. package/dist/web/assets/{TestCases-BjgWdtPi.js → TestCases-D5oOzYL4.js} +1 -1
  54. package/dist/web/assets/{TestData-CDziNp2d.js → TestData-27tyi6OD.js} +1 -1
  55. package/dist/web/assets/{TestDebt-D59zFYSu.js → TestDebt-D9k3uAiS.js} +1 -1
  56. package/dist/web/assets/{Tosca-umw1O224.js → Tosca-CMmixiPy.js} +1 -1
  57. package/dist/web/assets/{WhatsNew-DqNMAytd.js → WhatsNew-CuCua9dD.js} +1 -1
  58. package/dist/web/assets/{dataParts-DGVc48Ed.js → dataParts-D06wI4i1.js} +1 -1
  59. package/dist/web/assets/{families-DlfXDoO8.js → families-B0QIuAe3.js} +1 -1
  60. package/dist/web/assets/filters-mFECJpMB.js +1 -0
  61. package/dist/web/assets/{fold-BKAl2p_2.js → fold-CeQ84ypG.js} +1 -1
  62. package/dist/web/assets/frame-BcGZt823.js +4 -0
  63. package/dist/web/assets/{index-BLUj4Sgh.js → index-CotEpFLY.js} +19 -17
  64. package/dist/web/assets/index-VgSzQGK8.css +2 -0
  65. package/dist/web/assets/{logos-J0WPxDqj.js → logos-DN9jLn4q.js} +1 -1
  66. package/dist/web/assets/{palette-DViz4KwG.js → palette-BdMPhc9j.js} +1 -1
  67. package/dist/web/assets/{parts-W2J4TR3o.js → parts-z_AE9U-M.js} +1 -1
  68. package/dist/web/assets/{productParts-_8gKGn4o.js → productParts-C4vc_bLJ.js} +1 -1
  69. package/dist/web/assets/{qualityParts-DnbSeK-G.js → qualityParts-Cfirt7dZ.js} +1 -1
  70. package/dist/web/assets/{recordTest-etYNiLQy.js → recordTest-GvGQjhR4.js} +1 -1
  71. package/dist/web/assets/{rows-CbXelp5_.js → rows-CiR4hGkv.js} +1 -1
  72. package/dist/web/assets/{segmented-B7n6eLrO.js → segmented-DANusepM.js} +1 -1
  73. package/dist/web/assets/thread-CyTIuLgk.js +5 -0
  74. package/dist/web/assets/{usePageChat-DMOtRwzT.js → usePageChat-DOTAHsIS.js} +1 -1
  75. package/dist/web/index.html +4 -4
  76. package/docs/user-guide.html +137 -2
  77. package/env.example.yaml +1 -0
  78. package/forgeqe.example.yaml +14 -0
  79. package/package.json +1 -1
  80. package/prompts/brain.md +6 -3
  81. package/prompts/doc-reader.md +49 -0
  82. package/prompts/knowledge-agent.md +64 -0
  83. package/py/forgeqe_engine/brand.py +10 -1
  84. package/py/forgeqe_engine/capture.py +28 -12
  85. package/py/forgeqe_engine/logins.py +27 -0
  86. package/py/forgeqe_engine/loops.py +9 -0
  87. package/py/forgeqe_engine/memory.py +59 -0
  88. package/py/forgeqe_engine/recordsession.py +315 -40
  89. package/py/forgeqe_engine/service.py +11 -3
  90. package/py/forgeqe_engine/webrecord.py +153 -12
  91. package/py/forgeqe_engine/webrecord_page.py +211 -45
  92. package/dist/web/assets/Chat-czaM5kUi.js +0 -3
  93. package/dist/web/assets/Record-CoCnmfqW.js +0 -2
  94. package/dist/web/assets/filters-NVjc0d8i.js +0 -1
  95. package/dist/web/assets/frame-B0nzdTfN.js +0 -4
  96. package/dist/web/assets/index-RzPHjTCW.css +0 -2
  97. package/dist/web/assets/thread-BIUxcjeu.js +0 -5
@@ -27,11 +27,39 @@ COMMAND_KEYS = (
27
27
  )
28
28
 
29
29
  RECORDER_JS = r"""(() => {
30
- if (window.top !== window) return;
31
30
  if (globalThis.__fqeRec) return;
32
31
  const CFG = __CONFIG__;
33
- const send = (ev) => { try { globalThis[CFG.binding](JSON.stringify(ev)); } catch (e) {} };
32
+ // In a frame (an <iframe>, nested or not, of this site or another): the steps done in it are recorded the same way,
33
+ // marked as a frame's, and ForgeQE finds the frame's place in the page through the DevTools protocol. The Recorder
34
+ // panel and badge are the top page's only; a frame shows only the pick highlight while one is picked in it.
35
+ const inFrame = window.top !== window;
36
+ const send = (ev) => { try { globalThis[CFG.binding](JSON.stringify(inFrame ? { ...ev, frame: true } : ev)); } catch (e) {} };
34
37
  const norm = (s) => String(s || '').replace(/\s+/g, ' ').trim();
38
+
39
+ // ---- web components: open shadow roots -----------------------------------------------------------------------
40
+ // A listener on window sees an event from inside a web component retargeted to the component's outermost host (a
41
+ // click on a menu's button inside <cy-page-header> reads as a click on <cy-page-header>). The element really acted
42
+ // on is the first of the event's composed path; a closed shadow root keeps it hidden, and then its host stands in.
43
+ const deep = (ev) => { const p = ev.composedPath ? ev.composedPath() : []; const t = p.length ? p[0] : ev.target; return t && t.nodeType === 3 ? t.parentElement : t; };
44
+ // The parent across a shadow boundary: a shadow root's top elements have its host.
45
+ const up = (e) => e.parentElement || (e.parentNode && e.parentNode.nodeType === 11 && e.parentNode.host) || null;
46
+ const inShadow = (e) => !!e && e.getRootNode() !== document;
47
+ const deepContains = (a, b) => { for (let x = b; x; x = up(x)) if (x === a) return true; return false; };
48
+ const deepClosest = (e, sel) => { for (let x = e; x; x = up(x)) if (x.nodeType === 1 && x.matches(sel)) return x; return null; };
49
+ // The document and every open shadow root in it (the Recorder's own is closed): what Playwright's CSS, text and role
50
+ // locators search, so a count here is what a test's locator finds.
51
+ const roots = () => { const out = [document]; for (let i = 0; i < out.length && out.length < 500; i++) for (const x of out[i].querySelectorAll('*')) if (x.shadowRoot) out.push(x.shadowRoot); return out; };
52
+ const deepAll = (sel, rs) => (rs || roots()).flatMap((r) => [...r.querySelectorAll(r === document && sel === '*' ? 'body *' : sel)]);
53
+ // Text as it shows: through a component's shadow root and the light DOM it puts in its slots (innerText sees neither).
54
+ const flatText = (n, d = 0) => {
55
+ if (d > 40 || !n) return '';
56
+ if (n.nodeType === 3) return n.data;
57
+ if (n.nodeType !== 1 && n.nodeType !== 11) return '';
58
+ if (n.nodeType === 1 && ['SCRIPT', 'STYLE', 'TEMPLATE'].includes(n.tagName)) return '';
59
+ if (n.tagName === 'SLOT') { const a = n.assignedNodes({ flatten: true }); return (a.length ? a : [...n.childNodes]).map((x) => flatText(x, d + 1)).join(' '); }
60
+ return [...(n.nodeType === 1 && n.shadowRoot ? n.shadowRoot.childNodes : n.childNodes)].map((x) => flatText(x, d + 1)).join(' ');
61
+ };
62
+ const textOf = (e) => (inShadow(e) || e.shadowRoot || e.querySelector('slot') ? norm(flatText(e)) : norm(e.innerText || e.textContent));
35
63
  // Elements reported to ForgeQE, by number, so it can find each on the page through the DevTools protocol.
36
64
  const els = [];
37
65
  let dropped = 0;
@@ -49,7 +77,7 @@ RECORDER_JS = r"""(() => {
49
77
  const editableRoot = (e) => { let r = e; while (r.parentElement && r.parentElement.isContentEditable) r = r.parentElement; return r; };
50
78
  const control = (node) => {
51
79
  let e = node && node.nodeType === 1 ? node : node && node.parentElement;
52
- for (let i = 0, c = e; c && i <= 5; i++, c = c.parentElement) if (actionable(c)) return c;
80
+ for (let i = 0, c = e; c && i <= 5; i++, c = up(c)) if (actionable(c)) return c;
53
81
  return e;
54
82
  };
55
83
  const TEXT_TYPES = new Set(['', 'text', 'search', 'email', 'tel', 'url', 'number', 'password', 'date', 'time', 'datetime-local', 'month', 'week']);
@@ -77,7 +105,11 @@ RECORDER_JS = r"""(() => {
77
105
  };
78
106
  const labelText = (e) => {
79
107
  const by = e.getAttribute('aria-labelledby');
80
- if (by) { const t = by.split(/\s+/).map((id) => { const x = document.getElementById(id); return x ? x.textContent : ''; }).join(' '); if (norm(t)) return norm(t); }
108
+ if (by) {
109
+ const scope = e.getRootNode();
110
+ const t = by.split(/\s+/).map((id) => { const x = scope.getElementById ? scope.getElementById(id) : document.getElementById(id); return x ? flatText(x) : ''; }).join(' ');
111
+ if (norm(t)) return norm(t);
112
+ }
81
113
  if (e.getAttribute('aria-label')) return norm(e.getAttribute('aria-label'));
82
114
  if (e.labels && e.labels.length) return norm([...e.labels].map((l) => l.textContent).join(' '));
83
115
  return '';
@@ -95,38 +127,41 @@ RECORDER_JS = r"""(() => {
95
127
  if (t === 'TEXTAREA' || t === 'SELECT') return norm(e.getAttribute('title'));
96
128
  if (t === 'IMG') return norm(e.getAttribute('alt'));
97
129
  const role = e.getAttribute('role') || implicitRole(e);
98
- if (['button', 'link', 'heading', 'tab', 'menuitem', 'option', 'checkbox', 'radio', 'switch', 'treeitem'].includes(role)) return norm(e.innerText || e.textContent).slice(0, 120) || norm(e.getAttribute('title'));
130
+ if (['button', 'link', 'heading', 'tab', 'menuitem', 'option', 'checkbox', 'radio', 'switch', 'treeitem'].includes(role)) return textOf(e).slice(0, 120) || norm(e.getAttribute('title'));
99
131
  return norm(e.getAttribute('title'));
100
132
  };
101
- const xpath = (e) => { const parts = []; for (; e && e.nodeType === 1; e = e.parentElement) { let i = 1; for (let s = e.previousElementSibling; s; s = s.previousElementSibling) if (s.tagName === e.tagName) i++; parts.unshift(e.tagName.toLowerCase() + '[' + i + ']'); } return parts.join('/'); };
133
+ // No XPath for an element inside a shadow root: an XPath cannot reach into one, so it would find nothing on replay.
134
+ const xpath = (e) => inShadow(e) ? '' : xpathOf(e);
135
+ const xpathOf = (e) => { const parts = []; for (; e && e.nodeType === 1; e = e.parentElement) { let i = 1; for (let s = e.previousElementSibling; s; s = s.previousElementSibling) if (s.tagName === e.tagName) i++; parts.unshift(e.tagName.toLowerCase() + '[' + i + ']'); } return parts.join('/'); };
102
136
  const facts = (e) => {
103
137
  const attrs = {};
104
138
  for (const k of CFG.kept) { const v = e.getAttribute(k); if (v) attrs[k] = v; }
105
139
  const name = accName(e);
106
140
  const classes = [...e.classList].filter((c) => /^[A-Za-z_-][\w-]*$/.test(c)).slice(0, 4);
107
- return { tag: e.tagName.toLowerCase(), attributes: attrs, classes, xpath: xpath(e), role: e.getAttribute('role') || implicitRole(e), name: name.slice(0, 120), text: name ? '' : norm(e.innerText || e.textContent).slice(0, 120) };
141
+ return { tag: e.tagName.toLowerCase(), attributes: attrs, classes, xpath: xpath(e), role: e.getAttribute('role') || implicitRole(e), name: name.slice(0, 120), text: name ? '' : textOf(e).slice(0, 120) };
108
142
  };
109
143
  // How many elements each kind of locator for `e` matches right now, counted at the event: ForgeQE checks locators
110
144
  // through the DevTools protocol, but a click that opens another page can take the element away before it looks.
111
145
  const q = (v) => '"' + String(v).replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
112
146
  const visible = (x) => x.getClientRects().length > 0;
113
- const count = (sel) => { try { const all = [...document.querySelectorAll(sel)]; const v = all.filter(visible); return (v.length ? v : all).length; } catch (err) { return -1; } };
147
+ const count = (sel, rs) => { try { const all = deepAll(sel, rs); const v = all.filter(visible); return (v.length ? v : all).length; } catch (err) { return -1; } };
114
148
  const ROLE_SEL = 'a, button, input, select, textarea, summary, option, img, h1, h2, h3, h4, h5, h6, [role]';
115
149
  const matches = (e, f) => {
116
150
  const out = { attr: {} };
117
- for (const [k, v] of Object.entries(f.attributes)) out.attr[k] = count('[' + k + '=' + q(v) + ']');
118
- if (f.attributes.name) out.name = count(f.tag + '[name=' + q(f.attributes.name) + ']');
119
- if (f.attributes.href) out.href = count('a[href=' + q(f.attributes.href) + ']');
120
- if (f.classes.length) out.css = count(f.tag + f.classes.slice(0, 2).map((c) => '.' + c).join(''));
151
+ const rs = roots();
152
+ for (const [k, v] of Object.entries(f.attributes)) out.attr[k] = count('[' + k + '=' + q(v) + ']', rs);
153
+ if (f.attributes.name) out.name = count(f.tag + '[name=' + q(f.attributes.name) + ']', rs);
154
+ if (f.attributes.href) out.href = count('a[href=' + q(f.attributes.href) + ']', rs);
155
+ if (f.classes.length) out.css = count(f.tag + f.classes.slice(0, 2).map((c) => '.' + c).join(''), rs);
121
156
  const t = f.text || f.name;
122
- if (t) out.text = [...document.querySelectorAll('body *')].filter((x) => visible(x) && norm(x.textContent) === t && ![...x.children].some((c) => norm(c.textContent) === t)).length;
157
+ if (t) out.text = deepAll('*', rs).filter((x) => visible(x) && norm(x.textContent) === t && ![...x.children].some((c) => norm(c.textContent) === t)).length;
123
158
  if (f.role && f.name) {
124
- const same = [...document.querySelectorAll(ROLE_SEL)].filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === f.role);
159
+ const same = deepAll(ROLE_SEL, rs).filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === f.role);
125
160
  out.role = same.filter((x) => accName(x) === f.name).length;
126
161
  // The names of the others with this role, for a locator by part of the name, counted after the page is gone.
127
162
  if (/\d/.test(f.name)) out.role_names = same.slice(0, 400).map((x) => accName(x).slice(0, 160));
128
163
  }
129
- if (f.name) out.label = [...document.querySelectorAll('input, select, textarea, [aria-label]')].filter((x) => labelText(x) === f.name).length;
164
+ if (f.name) out.label = deepAll('input, select, textarea, [aria-label]', rs).filter((x) => labelText(x) === f.name).length;
130
165
  return out;
131
166
  };
132
167
  const shown = (e) => {
@@ -135,7 +170,80 @@ RECORDER_JS = r"""(() => {
135
170
  if (e.tagName === 'SELECT') return norm([...e.selectedOptions].map((o) => o.text).join(', '));
136
171
  return norm(String(e.innerText || e.textContent || '').split('\n').map(norm).filter(Boolean)[0] || '');
137
172
  };
138
- const describeEl = (e) => { const f = facts(e); return { id: ref(e), el: f, matches: matches(e, f), url: location.href }; };
173
+ // ---- a locator anchored on a container, for an element none of whose own locators is unique ---------------------
174
+ // Nine cards with the same "Book online now" button: the card that holds it, by a text only that card has ("FABIA
175
+ // Auto"), then the button inside it, as Playwright writes it: getByRole('listitem').filter({ hasText }).getByRole(…).
176
+ // A field with no label of its own is found the same way, by the text beside it in the group that holds it.
177
+ const CONTAINER_ROLES = new Set(['listitem', 'row', 'article', 'dialog', 'group', 'tabpanel', 'gridcell', 'cell']);
178
+ const containerRole = (x) => {
179
+ const r = x.getAttribute('role');
180
+ if (r) return CONTAINER_ROLES.has(r) ? r : '';
181
+ if (x.tagName === 'LI' && x.parentElement && /^(UL|OL|MENU)$/.test(x.parentElement.tagName)) return 'listitem';
182
+ if (x.tagName === 'TR') return 'row';
183
+ if (x.tagName === 'ARTICLE') return 'article';
184
+ if (x.tagName === 'DIALOG') return 'dialog';
185
+ if (x.tagName === 'FIELDSET') return 'group';
186
+ return '';
187
+ };
188
+ const stableClass = (c) => /^[A-Za-z][\w-]{2,40}$/.test(c) && !/\d{3,}|__|^(?:css|sc|jsx|svelte|emotion)-/i.test(c);
189
+ const containerCss = (x) => { const c = [...x.classList].find(stableClass); return c ? x.tagName.toLowerCase() + '.' + c : ''; };
190
+ const lowText = (x) => norm(x.textContent).toLowerCase();
191
+ // The texts that could tell this container from the others: its headings, then its labels, then short texts of its own.
192
+ const anchorTexts = (box, own) => {
193
+ const out = [];
194
+ const add = (t) => { t = norm(t); if (t && t.length <= 80 && t !== own && !out.includes(t)) out.push(t); };
195
+ for (const h of box.querySelectorAll('h1, h2, h3, h4, h5, h6, [role=heading]')) add(h.textContent);
196
+ for (const l of box.querySelectorAll('label, legend, dt, th')) add(l.textContent);
197
+ const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT);
198
+ for (let n = walker.nextNode(), k = 0; n && k < 40; n = walker.nextNode(), k++) add(n.data);
199
+ return out.slice(0, 12);
200
+ };
201
+ const innerOf = (e, f, box) => {
202
+ const inBox = (sel) => [...box.querySelectorAll(sel)].filter(visible);
203
+ if (f.role && f.name) {
204
+ const same = inBox(ROLE_SEL).filter((x) => (x.getAttribute('role') || implicitRole(x)) === f.role && accName(x) === f.name);
205
+ if (same.length === 1 && same[0] === e) return { type: 'role', value: f.role + '|' + f.name };
206
+ }
207
+ if (f.role && !f.name) {
208
+ const same = inBox(ROLE_SEL).filter((x) => (x.getAttribute('role') || implicitRole(x)) === f.role);
209
+ if (same.length === 1 && same[0] === e) return { type: 'role', value: f.role };
210
+ }
211
+ const t = f.text || f.name;
212
+ if (t && t.length <= 80) {
213
+ const same = inBox('*').filter((x) => norm(x.textContent) === t && ![...x.children].some((c) => norm(c.textContent) === t));
214
+ if (same.length === 1 && (same[0] === e || e.contains(same[0]))) return { type: 'text', value: t };
215
+ }
216
+ const css = containerCss(e);
217
+ if (css && inBox(css).length === 1) return { type: 'css', value: css };
218
+ return null;
219
+ };
220
+ const anchorFor = (e, f) => {
221
+ const own = f.text || f.name;
222
+ for (let box = up(e), i = 0; box && i < 8 && box !== document.body && box !== document.documentElement; box = up(box), i++) {
223
+ if (box.nodeType !== 1) continue;
224
+ const role = containerRole(box);
225
+ const css = role ? '' : containerCss(box);
226
+ if (!role && !css) continue;
227
+ const inner = innerOf(e, f, box);
228
+ if (!inner) continue;
229
+ const peers = role ? deepAll(ROLE_SEL + ', li, tr, article, dialog, fieldset').filter((x) => containerRole(x) === role) : deepAll(css);
230
+ for (const t of anchorTexts(box, own)) {
231
+ const low = t.toLowerCase();
232
+ const hits = peers.filter((x) => visible(x) && lowText(x).includes(low));
233
+ if (hits.length === 1 && hits[0] === box) return { c: role ? { role } : { css }, t, i: inner };
234
+ }
235
+ }
236
+ return null;
237
+ };
238
+ // Unique by a locator of its own: no anchor needed.
239
+ const uniqueAlone = (m) => [m.role, m.text, m.label, m.name, m.href, m.attr && m.attr.id, m.attr && m.attr['data-testid']].some((n) => n === 1);
240
+ const describeEl = (e) => {
241
+ const f = facts(e);
242
+ const m = matches(e, f);
243
+ let anchor = null;
244
+ if (!uniqueAlone(m)) { try { anchor = anchorFor(e, f); } catch (err) { anchor = null; } }
245
+ return { id: ref(e), el: f, matches: m, url: location.href, ...(anchor ? { anchor } : {}) };
246
+ };
139
247
 
140
248
  // ---- the Recorder panel, docked in the page, with the pick highlight and the key bar --------------------------------
141
249
  // In the top layer (a popover), above the page's own dialogs, as brand.py's overlay is; a closed shadow root, so the
@@ -228,14 +336,14 @@ RECORDER_JS = r"""(() => {
228
336
  // A dialog the page opens later goes into the top layer above the Recorder: put the Recorder back on top.
229
337
  new MutationObserver(() => { if (document.querySelector('dialog[open], [popover]:popover-open:not(forgeqe-recorder)')) raise(); }).observe(document, { subtree: true, attributes: true, attributeFilter: ['open'] });
230
338
  let tipTimer = 0;
231
- const say = (parts, ms = 2600) => { mount(); tip.textContent = ''; for (const [b, t] of parts) { const s = document.createElement(b ? 'b' : 'span'); s.textContent = t; tip.appendChild(s); } tip.style.display = 'block'; clearTimeout(tipTimer); if (ms) tipTimer = setTimeout(() => { tip.style.display = 'none'; }, ms); };
339
+ const say = (parts, ms = 2600) => { if (inFrame && !picking) return; mount(); tip.textContent = ''; for (const [b, t] of parts) { const s = document.createElement(b ? 'b' : 'span'); s.textContent = t; tip.appendChild(s); } tip.style.display = 'block'; clearTimeout(tipTimer); if (ms) tipTimer = setTimeout(() => { tip.style.display = 'none'; }, ms); };
232
340
  const ours = (ev) => ev.composedPath().includes(host);
233
341
  const el = (tag, cls, t) => { const e = document.createElement(tag); if (cls) e.className = cls; if (t !== undefined) e.textContent = t; return e; };
234
342
 
235
343
  let paused = false;
236
344
  let ui = { collapsed: false, x: null, y: null };
237
345
  const place = () => {
238
- panel.hidden = CFG.badge || ui.collapsed; pill.hidden = !CFG.badge && !ui.collapsed;
346
+ panel.hidden = inFrame || CFG.badge || ui.collapsed; pill.hidden = inFrame || (!CFG.badge && !ui.collapsed);
239
347
  for (const p of [panel, pill]) {
240
348
  if (ui.x === null || ui.x === undefined) { p.style.left = p.style.top = p.style.right = p.style.bottom = ''; continue; }
241
349
  const w = p.offsetWidth || 340, h = p.offsetHeight || 32;
@@ -356,12 +464,19 @@ RECORDER_JS = r"""(() => {
356
464
 
357
465
  // ---- picking an element for a check, a variable, or a wait ---------------------------------------------------
358
466
  let picking = null;
359
- const pickTarget = (ev) => { host.style.setProperty('display', 'none', 'important'); const e = document.elementFromPoint(ev.clientX, ev.clientY); host.style.removeProperty('display'); return e; };
467
+ const pickTarget = (ev) => {
468
+ host.style.setProperty('display', 'none', 'important');
469
+ let e = document.elementFromPoint(ev.clientX, ev.clientY);
470
+ // Into a web component's open shadow root: the element under the pointer there, not its host.
471
+ for (let i = 0; e && e.shadowRoot && i < 20; i++) { const inner = e.shadowRoot.elementFromPoint(ev.clientX, ev.clientY); if (!inner || inner === e) break; e = inner; }
472
+ host.style.removeProperty('display');
473
+ return e;
474
+ };
360
475
  const highlight = (e) => { if (!e) { box.style.display = 'none'; return; } const r = e.getBoundingClientRect(); Object.assign(box.style, { display: 'block', left: r.left - 2 + 'px', top: r.top - 2 + 'px', width: r.width + 4 + 'px', height: r.height + 4 + 'px' }); };
361
476
  // A control, or else the smallest element under the pointer (the text a check is about).
362
477
  const pickable = (node) => { const c = control(node); return actionable(c) ? c : node && node.nodeType === 1 ? node : c; };
363
478
  const startPick = (purpose) => { picking = { purpose }; mount(); say([[1, 'Pick an element'], [0, purpose === 'assert' ? ' to check' : purpose === 'variable' ? ' whose text to keep' : ' to wait for'], [0, ' · Esc cancels']], 0); };
364
- const endPick = () => { picking = null; highlight(null); tip.style.display = 'none'; };
479
+ const endPick = () => { picking = null; highlight(null); tip.style.display = 'none'; if (inFrame && host.isConnected) host.remove(); };
365
480
  // Check, Variable, and Wait for start picking here at once: the next click is the pick, however soon it comes.
366
481
  const picks = (cmd) => { if (['assert', 'variable', 'wait'].includes(cmd)) startPick(cmd); };
367
482
  const swallow = (ev) => { if (!picking || !ev.isTrusted || ours(ev)) return false; ev.preventDefault(); ev.stopImmediatePropagation(); return true; };
@@ -373,29 +488,44 @@ RECORDER_JS = r"""(() => {
373
488
  const MENU = '[role=menu], [role=menubar] [role=menu], [role=listbox], ul ul, .dropdown-menu, .submenu, .sub-menu, [class*="dropdown"], [class*="submenu"], [class*="flyout"], [class*="mega"]';
374
489
  const revealed = [];
375
490
  let hovered = null;
376
- window.addEventListener('mouseover', (ev) => {
377
- if (!ev.isTrusted || picking || ours(ev)) return;
378
- const t = ev.target.closest && ev.target.closest(TRIGGER);
379
- if (t && (!hovered || t !== hovered.el)) hovered = { el: t, at: Date.now() };
380
- }, true);
381
- new MutationObserver((list) => {
491
+ const onReveal = (list) => {
382
492
  if (!hovered || Date.now() - hovered.at > 1500) return;
383
493
  for (const m of list) {
384
494
  const n = m.type === 'childList' ? [...m.addedNodes].find((x) => x.nodeType === 1) : m.target;
385
- if (n && n.nodeType === 1 && !n.contains(hovered.el) && n !== host) revealed.push({ by: hovered.el, root: n, at: Date.now() });
495
+ if (n && n.nodeType === 1 && !deepContains(n, hovered.el) && n !== host) revealed.push({ by: hovered.el, root: n, at: Date.now() });
386
496
  }
387
497
  if (revealed.length > 50) revealed.splice(0, revealed.length - 50);
388
- }).observe(document, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class', 'hidden', 'aria-hidden', 'aria-expanded', 'open'] });
498
+ };
499
+ const REVEAL = { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class', 'hidden', 'aria-hidden', 'aria-expanded', 'open'] };
500
+ new MutationObserver(onReveal).observe(document, REVEAL);
501
+ // A document's MutationObserver and its change events do not reach into shadow roots: each open one the tester
502
+ // reaches (the pointer goes over it, or the focus goes in) is watched too, once.
503
+ const watched = new WeakSet();
504
+ const watchRoots = (ev) => {
505
+ if (!ev.composedPath) return;
506
+ for (const n of ev.composedPath()) {
507
+ if (!n || n.nodeType !== 11 || !n.host || n.host === host || watched.has(n)) continue;
508
+ watched.add(n);
509
+ new MutationObserver(onReveal).observe(n, REVEAL);
510
+ n.addEventListener('change', (e) => { if (deep(e).getRootNode() === n) onChange(e); }, true);
511
+ }
512
+ };
513
+ for (const type of ['mouseover', 'focusin', 'pointerdown']) window.addEventListener(type, (ev) => { if (ev.isTrusted && !ours(ev)) watchRoots(ev); }, true);
514
+ window.addEventListener('mouseover', (ev) => {
515
+ if (!ev.isTrusted || picking || ours(ev)) return;
516
+ const t = deepClosest(deep(ev), TRIGGER);
517
+ if (t && (!hovered || t !== hovered.el)) hovered = { el: t, at: Date.now() };
518
+ }, true);
389
519
  const hoverFor = (c) => {
390
520
  for (let i = revealed.length - 1; i >= 0; i--) {
391
521
  const r = revealed[i];
392
- if (r.root.contains(c) && r.by !== c && !r.by.contains(c) && r.by.isConnected && Date.now() - r.at < 60000) return r.by;
522
+ if (deepContains(r.root, c) && r.by !== c && !deepContains(r.by, c) && r.by.isConnected && Date.now() - r.at < 60000) return r.by;
393
523
  }
394
- for (let e = c.parentElement, i = 0; e && e !== document.body && i < 8; e = e.parentElement, i++) {
524
+ for (let e = up(c), i = 0; e && e !== document.body && i < 8; e = up(e), i++) {
395
525
  if (!e.matches(MENU)) continue;
396
- const owner = e.parentElement;
526
+ const owner = up(e);
397
527
  if (!owner || !owner.matches(':hover')) continue;
398
- const trig = [...owner.children].find((x) => x !== e && !x.contains(c) && (x.matches(TRIGGER) || (x.querySelector && x.querySelector('a, button'))));
528
+ const trig = [...owner.children].find((x) => x !== e && !deepContains(x, c) && (x.matches(TRIGGER) || (x.querySelector && x.querySelector('a, button'))));
399
529
  if (trig) return trig.matches(TRIGGER) ? trig : trig.querySelector('a, button');
400
530
  }
401
531
  return null;
@@ -412,24 +542,44 @@ RECORDER_JS = r"""(() => {
412
542
  };
413
543
  window.addEventListener('input', (ev) => {
414
544
  if (!ev.isTrusted || picking || ours(ev) || paused) return;
415
- const e = ev.target.isContentEditable ? editableRoot(ev.target) : ev.target;
545
+ const t = deep(ev);
546
+ const e = t && t.isContentEditable ? editableRoot(t) : t;
416
547
  if (!isField(e)) return;
417
548
  if (dirty && dirty !== e) flush();
418
549
  dirty = e;
419
550
  }, true);
420
- window.addEventListener('focusout', (ev) => { if (dirty && ev.target === dirty) flush(); }, true);
551
+ window.addEventListener('focusout', (ev) => { if (dirty && (deep(ev) === dirty || ev.target === dirty)) flush(); }, true);
421
552
  window.addEventListener('pagehide', flush, true);
422
553
  window.addEventListener('submit', (ev) => { if (ev.isTrusted !== false) flush(); }, true);
423
554
 
424
- window.addEventListener('change', (ev) => {
555
+ // A change does not leave a shadow root (it is not composed): watchRoots adds this to each open one as well.
556
+ function onChange(ev) {
425
557
  if (!ev.isTrusted || picking || ours(ev) || paused) return;
426
- const e = ev.target;
558
+ const e = deep(ev);
427
559
  if (e.tagName === 'SELECT') { flush(); send({ kind: 'select', ...describeEl(e), text: shown(e) }); return; }
428
560
  // The files' paths are read by ForgeQE through the DevTools protocol: the page itself only sees their names.
429
561
  if (e.tagName === 'INPUT' && (e.getAttribute('type') || '').toLowerCase() === 'file') { send({ kind: 'upload', ...describeEl(e), count: e.files ? e.files.length : 0 }); return; }
430
562
  if (dirty === e) flush();
431
- }, true);
563
+ }
564
+ window.addEventListener('change', onChange, true);
432
565
 
566
+ // A click on a CAPTCHA's own layer in the page (the dimmed layer behind reCAPTCHA's pictures): not a control, and a
567
+ // CAPTCHA's frame is right beside it. Its name only (webrecord.py CAPTCHA_FRAMES says the same).
568
+ const CAPTCHA_SRC = [['reCAPTCHA', /^https:\/\/(?:www\.)?(?:google\.com|recaptcha\.net)\/recaptcha\//i], ['hCaptcha', /^https:\/\/(?:[\w-]+\.)*hcaptcha\.com\//i], ['Turnstile', /^https:\/\/challenges\.cloudflare\.com\//i], ['Arkose', /^https:\/\/(?:[\w-]+\.)*(?:arkoselabs\.com|funcaptcha\.com)\//i], ['GeeTest', /^https:\/\/(?:[\w-]+\.)*geetest\.com\//i]];
569
+ const captchaNear = (c) => {
570
+ if (!c || actionable(c)) return '';
571
+ for (let e = c, i = 0; e && i < 3; e = e.parentElement, i++) {
572
+ for (const f of e.querySelectorAll ? e.querySelectorAll('iframe[src]') : []) { const hit = CAPTCHA_SRC.find(([, rx]) => rx.test(f.src)); if (hit) return hit[0]; }
573
+ }
574
+ return '';
575
+ };
576
+ // A canvas has no elements in it: where in it the click landed is the step, as Playwright's recorder keeps it
577
+ // (locator.click({ position })), in the canvas's own pixels from its top left corner.
578
+ const where = (c, ev) => {
579
+ if (!c || c.tagName !== 'CANVAS') return {};
580
+ const r = c.getBoundingClientRect();
581
+ return { position: { x: Math.round(ev.clientX - r.left), y: Math.round(ev.clientY - r.top) } };
582
+ };
433
583
  let lastLabel = null;
434
584
  window.addEventListener('click', (ev) => {
435
585
  if (!ev.isTrusted || ours(ev)) return;
@@ -443,21 +593,35 @@ RECORDER_JS = r"""(() => {
443
593
  return;
444
594
  }
445
595
  if (paused) return;
446
- const c = control(ev.target);
596
+ const c = control(deep(ev));
447
597
  if (!c || c.tagName === 'OPTION' || c.tagName === 'SELECT') return;
448
598
  // A click on a label also clicks its control: one step.
449
599
  if (lastLabel && lastLabel.control === c && Date.now() - lastLabel.at < 100) return;
450
600
  if (c.tagName === 'LABEL') lastLabel = { control: c.control, at: Date.now() };
451
601
  if (dirty && dirty !== c) flush();
602
+ const cap = captchaNear(c);
603
+ if (cap) { send({ kind: 'captcha', provider: cap }); return; }
452
604
  const h = hoverFor(c);
453
- send({ kind: 'click', ...describeEl(c), field: isField(c), ...(h ? { hover: describeEl(h) } : {}) });
605
+ send({ kind: 'click', ...describeEl(c), field: isField(c), ...(h ? { hover: describeEl(h) } : {}), ...where(c, ev) });
454
606
  }, true);
455
607
  window.addEventListener('dblclick', (ev) => {
456
608
  if (!ev.isTrusted || picking || ours(ev) || paused) return;
457
- const c = control(ev.target);
458
- if (c && !isField(c)) send({ kind: 'dblclick', ...describeEl(c) });
609
+ const c = control(deep(ev));
610
+ if (c && !isField(c)) send({ kind: 'dblclick', ...describeEl(c), ...where(c, ev) });
459
611
  }, true);
460
612
  window.addEventListener('dragstart', (ev) => { if (ev.isTrusted && !paused && !picking && !ours(ev)) send({ kind: 'unsupported', action: 'drag', reason: 'drag and drop is not recorded yet; add it in the test' }); }, true);
613
+ // Files dropped on the page from this computer (a drop zone): an upload. The files are kept here, by number, for
614
+ // ForgeQE to read their paths through the DevTools protocol (the page itself only sees their names).
615
+ const drops = [];
616
+ window.addEventListener('drop', (ev) => {
617
+ if (!ev.isTrusted || picking || paused || ours(ev)) return;
618
+ const fs = ev.dataTransfer && ev.dataTransfer.files;
619
+ if (!fs || !fs.length) return;
620
+ if (drops.length > 50) drops.splice(0, drops.length - 50);
621
+ drops.push([...fs]);
622
+ const at = deep(ev);
623
+ send({ kind: 'upload', drop: true, drop_id: drops.length - 1, count: fs.length, ...describeEl(control(at) || at) });
624
+ }, true);
461
625
 
462
626
  // ---- keys: the leader key and its letter, then Enter, Escape, and chords ----------------------------------------
463
627
  let leader = 0;
@@ -491,7 +655,8 @@ RECORDER_JS = r"""(() => {
491
655
  return;
492
656
  }
493
657
  if (paused || ['Shift', 'Control', 'Alt', 'Meta'].includes(ev.key)) return;
494
- const e = ev.target && ev.target.nodeType === 1 ? (ev.target.isContentEditable ? editableRoot(ev.target) : ev.target) : null;
658
+ const t = deep(ev);
659
+ const e = t && t.nodeType === 1 ? (t.isContentEditable ? editableRoot(t) : t) : null;
495
660
  const inField = isField(e);
496
661
  const mods = [ev.ctrlKey && 'Control', ev.altKey && 'Alt', ev.metaKey && 'Meta', ev.shiftKey && ev.key.length > 1 && 'Shift'].filter(Boolean);
497
662
  const key = ev.key === ' ' ? 'Space' : ev.key.length === 1 ? ev.key.toLowerCase() : ev.key;
@@ -508,6 +673,7 @@ RECORDER_JS = r"""(() => {
508
673
 
509
674
  globalThis.__fqeRec = {
510
675
  el: elAt,
676
+ dropped: (i) => drops[i] || [],
511
677
  pick: (purpose) => startPick(purpose),
512
678
  cancelPick: () => endPick(),
513
679
  flush,
@@ -521,13 +687,13 @@ RECORDER_JS = r"""(() => {
521
687
  countPattern: (role, source) => {
522
688
  let rx;
523
689
  try { rx = new RegExp(source); } catch (e) { return -1; }
524
- if (role) return [...document.querySelectorAll(ROLE_SEL)].filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === role && rx.test(accName(x))).length;
525
- return [...document.querySelectorAll('body *')].filter((x) => visible(x) && !host.contains(x) && rx.test(norm(x.textContent)) && ![...x.children].some((c) => rx.test(norm(c.textContent)))).length;
690
+ if (role) return deepAll(ROLE_SEL).filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === role && rx.test(accName(x))).length;
691
+ return deepAll('*').filter((x) => visible(x) && !host.contains(x) && rx.test(norm(x.textContent)) && ![...x.children].some((c) => rx.test(norm(c.textContent)))).length;
526
692
  },
527
693
  // Where a control of the panel is on screen (tests click it as a person would).
528
694
  box: (sel) => { const e = root.querySelector(sel); if (!e) return null; const r = e.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; },
529
695
  };
530
- if (document.documentElement) mount(); else document.addEventListener('DOMContentLoaded', mount, { once: true });
696
+ if (!inFrame) { if (document.documentElement) mount(); else document.addEventListener('DOMContentLoaded', mount, { once: true }); }
531
697
  send({ kind: 'ready', url: location.href });
532
698
  })()"""
533
699
 
@@ -1,3 +0,0 @@
1
- import{An as e,C as t,Gn as n,Ir as r,Nr as i,T as a,Xn as o,a as s,i as c,ln as l}from"./line-icons-CQ-3V8ax.js";import{B as u,R as d,Z as f,f as p,h as m,i as h,l as g,qt as _,rt as v,z as y}from"./filters-NVjc0d8i.js";import{Et as b,a as x,gt as S,n as C,r as w,t as T}from"./frame-B0nzdTfN.js";import{B as E,F as ee,I as te,L as ne,R as re,T as ie,V as ae,i as D,w as O,z as k}from"./index-BLUj4Sgh.js";import{n as A}from"./Response-PDQ8zEZU.js";import{n as oe}from"./thread-BIUxcjeu.js";import{i as j,n as M,r as N,t as P}from"./rows-CbXelp5_.js";import{n as F}from"./recordTest-etYNiLQy.js";var I=r(i(),1),L=_();function R({id:e}){let[r,i]=(0,I.useState)([]),[a,h]=(0,I.useState)(null),[g,_]=(0,I.useState)(!1),[b,S]=(0,I.useState)(``),[w,T]=(0,I.useState)(``),[D,j]=(0,I.useState)(!1),M=ae(w,T,`reply`,{chat:e}),N=(0,I.useRef)(null),P=(0,I.useRef)(null),R=(0,I.useRef)(!0),[z,B]=(0,I.useState)(!0);(0,I.useEffect)(()=>{let t=!1,n=0;return i([]),h(null),S(``),T(``),M.reset(),(async()=>{for(;!t;)try{let r=await v.events(e,n,n>0);if(t)return;S(``),h({title:r.title,state:r.state,profile:r.profile,settingsChanged:r.settingsChanged===!0,...r.recording?{recording:r.recording}:{}}),r.events.length&&(n=r.events[r.events.length-1].n,i(e=>[...e,...r.events]))}catch(e){if(t||(S(e.message),e.status===404))return;await new Promise(e=>setTimeout(e,2e3))}})(),()=>{t=!0}},[e]);let V=(0,I.useMemo)(()=>oe(r),[r]),H=(0,I.useMemo)(()=>{let e=new Map;for(let t of V.turns.flatMap(e=>e.changes)){let n=e.get(t.path);e.set(t.path,n?{...n,added:n.added+t.added,removed:n.removed+t.removed}:{path:t.path,added:t.added,removed:t.removed})}return[...e.values()]},[V]),U=(0,I.useMemo)(()=>{let e=[];for(let t of V.turns){for(let n of t.tests)n.testFile&&e.push({label:n.ok?`Test`:`Test (failed)`,path:n.testFile,kind:`test`});for(let n of t.reports)e.push({label:/\.html?$/i.test(n.path)?`Report`:`Run report`,path:n.path,kind:`report`})}return e.filter((t,n)=>e.findIndex(e=>e.path===t.path)===n)},[V]),W=(0,I.useRef)(()=>{});x(V.context||V.usage||H.length||U.length||V.uses?{context:V.context,usage:V.usage,agents:V.agents,model:V.model?.name,changes:H,outputs:U,uses:V.uses,busy:a?.state===`busy`||a?.state===`starting`,...H.length?{onCreatePr:()=>W.current()}:{}}:null);let G=a?.state,K=G===`busy`||G===`starting`,q=G===`closed`||G===`failed`,J=V.turns.at(-1),Y=!!J&&!J.outcome&&(J.asks.some(e=>e.answer===void 0)||J.waits.some(e=>e.answer===void 0));(0,I.useEffect)(()=>{let e=document.documentElement,t=()=>window.innerHeight+window.scrollY>=e.scrollHeight-48,n=e=>{R.current=e,B(e)},r=window.scrollY,i=()=>{t()?n(!0):window.scrollY<r-2&&n(!1),r=window.scrollY},a=new ResizeObserver(()=>{R.current&&!t()&&window.scrollTo({top:e.scrollHeight,behavior:`instant`})});return N.current&&a.observe(N.current),P.current&&a.observe(P.current),window.addEventListener(`scroll`,i,{passive:!0}),()=>{a.disconnect(),window.removeEventListener(`scroll`,i)}},[]);let se=()=>{R.current=!0,B(!0),window.scrollTo({top:document.documentElement.scrollHeight,behavior:`smooth`})},[X,ce]=(0,I.useState)(null);(0,I.useEffect)(()=>void f.settings().then(ce,()=>{}),[]);let Z=(0,I.useCallback)(async e=>{try{await e()}catch(e){S(e.message)}},[]),Q=re(`chat-${e}`.replace(/[^\w-]/g,``).slice(0,80),e=>{T(e),ne(`reply`)}),$=async t=>{if(!(D||!t.trim()&&!M.hasFiles)){j(!0),R.current=!0,B(!0);try{let n=await M.wrap(t);if(!n.trim())return;await v.send(e,n),T(``),M.reset({keep:!0}),S(``),Q.close()}catch(e){S(e.message)}finally{j(!1)}}};return W.current=()=>{if(a?.state===`busy`||a?.state===`starting`||D)return;let e=H.map(e=>`- ${e.path}`).join(`
2
- `);$(`Open a pull request with the changes you made in this chat:\n${e}\n\nUse a new branch, a clear title and description, and tell me its link.`)},(0,L.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,L.jsxs)(`header`,{className:`sticky top-0 z-20 flex items-center gap-1 border-b border-line-soft bg-bg py-3 pr-16 pl-5 md:pr-5`,children:[(0,L.jsx)(C,{}),(0,L.jsx)(`h1`,{className:`m-0 ml-2 min-w-0 flex-1 truncate text-base font-semibold`,children:a?.title||`Chat`}),a?.recording&&(0,L.jsxs)(`a`,{className:y({size:`sm`}),href:F(a.recording.run),"data-tip":`Back to the recording ${a.recording.name}`,children:[(0,L.jsx)(s,{"aria-hidden":`true`}),`Back to the recording`]}),V.model&&(0,L.jsxs)(`span`,{className:`hidden min-h-9 items-center gap-1.5 rounded-lg px-2 text-sm text-ink-2 sm:inline-flex`,"data-tip":`The model this chat uses`,children:[(0,L.jsx)(m,{icon:o,size:14,className:`text-accent-fg`}),V.model.name]})]}),(0,L.jsxs)(`main`,{ref:N,className:`mx-auto box-border flex w-full max-w-[960px] flex-auto flex-col gap-8 px-6 pt-8 pb-6`,children:[!a&&!b&&(0,L.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Opening the chat…`}),a?.recording&&(0,L.jsxs)(`p`,{className:`m-0 rounded-[12px] bg-accent-soft px-3 py-2.5 text-sm text-ink [overflow-wrap:anywhere]`,children:[`This chat writes the test from the recording `,(0,L.jsx)(`a`,{href:F(a.recording.run),children:a.recording.name}),`. The recording shows how it goes, and it goes on if you leave.`]}),V.turns.map((t,n)=>(0,L.jsxs)(`section`,{"aria-label":`Message ${n+1}`,className:`flex flex-col gap-5`,children:[(0,L.jsx)(E,{text:t.user,scope:{chat:e}}),(0,L.jsx)(A,{turn:t,live:n===V.turns.length-1&&!q,onAnswer:(t,n)=>Z(()=>v.answer(e,t,n)),onProceed:(t,n)=>Z(()=>v.proceed(e,t,n))})]},t.id)),J?.outcome===`done`&&J.next.length>0&&!K&&!q&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-2 pl-12`,children:J.next.map(e=>(0,L.jsx)(`button`,{type:`button`,"data-tip":e.request===e.label?void 0:e.request,onClick:()=>void $(e.request),className:`inline-flex min-h-10 cursor-pointer items-center rounded-[8px] border-0 bg-surface-strong px-4 text-sm font-medium text-ink-2 hover:bg-line hover:text-ink`,children:e.label},e.label))}),(V.fatal||q&&V.ended)&&(0,L.jsxs)(`div`,{role:`alert`,className:u(`flex flex-col gap-2 rounded-[14px] px-4 py-3 text-sm leading-relaxed`,V.fatal||G===`failed`?`bg-fail-soft text-fail`:`bg-surface-muted text-ink-2`),children:[(0,L.jsx)(`span`,{className:`[overflow-wrap:anywhere]`,children:V.fatal||V.ended?.message||(G===`failed`?`ForgeQE stopped unexpectedly.`:`This chat has ended.`)}),q&&(0,L.jsx)(`span`,{className:`text-ink-2`,children:`Write below to carry on: ForgeQE starts again with this conversation.`}),V.ended?.stderr&&(0,L.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto rounded-lg bg-bg/60 px-3 py-2 font-mono text-[12px] whitespace-pre-wrap text-ink-2 [overflow-wrap:anywhere]`,children:V.ended.stderr.join(`
3
- `)}),(0,L.jsxs)(`span`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsxs)(`a`,{className:y({size:`sm`}),href:p(),"data-tip":`Start a new chat`,children:[(0,L.jsx)(l,{"aria-hidden":`true`}),`Chat`]}),V.fatal&&/model|key|sign/i.test(V.fatal)&&(0,L.jsxs)(`a`,{className:y({size:`sm`}),href:p(`settings`,`models`),"data-tip":`Set up the models`,children:[(0,L.jsx)(n,{"aria-hidden":`true`}),`Models`]}),V.fatal&&/runtime|engine|setup/i.test(V.fatal)&&(0,L.jsxs)(`a`,{className:y({size:`sm`}),href:p(`settings`,`setup`),children:[(0,L.jsx)(n,{"aria-hidden":`true`}),`Set up`]})]})]}),V.notes.map((e,t)=>(0,L.jsx)(`p`,{className:`m-0 text-sm text-muted [overflow-wrap:anywhere]`,children:e},t))]}),(0,L.jsx)(`div`,{ref:P,className:`sticky bottom-0 z-10 bg-gradient-to-t from-bg from-70% to-transparent px-6 pt-4 pb-5`,children:(0,L.jsxs)(`div`,{className:`relative mx-auto flex w-full max-w-[880px] flex-col gap-2`,children:[!z&&K&&(0,L.jsxs)(`button`,{type:`button`,onClick:se,"data-tip":`Go to the latest activity`,className:`absolute -top-11 left-1/2 inline-flex min-h-8 -translate-x-1/2 cursor-pointer items-center gap-1.5 rounded-[8px] border-0 bg-surface-strong px-3 text-[13px] font-medium text-ink-2 shadow-sm hover:bg-line hover:text-ink`,children:[(0,L.jsx)(c,{size:14,"aria-hidden":`true`}),`Latest`]}),(0,L.jsxs)(`div`,{"aria-live":`polite`,children:[a?.settingsChanged&&!K&&!q&&!Y&&(0,L.jsxs)(`div`,{role:`status`,className:`mb-2 flex flex-wrap items-center gap-2 rounded-[12px] border border-accent-line bg-accent-soft px-3 py-2 text-sm`,children:[(0,L.jsx)(`span`,{className:`min-w-0 flex-1`,children:`The settings changed since this chat started. Carry on with them? The conversation is kept.`}),(0,L.jsxs)(d,{size:`sm`,variant:`primary`,disabled:g,onClick:()=>{_(!0),v.refresh(e).then(()=>{_(!1),h(e=>e&&{...e,settingsChanged:!1,state:`starting`})},e=>{_(!1),S(e.message)})},"data-tip":`Carry on with the new settings`,children:[(0,L.jsx)(t,{"aria-hidden":`true`}),`Apply`]})]}),(b||M.error)&&(0,L.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:b||M.error})]}),(0,L.jsx)(k,{id:`reply`,label:`Reply to ForgeQE`,rows:1,value:w,onChange:T,onSend:()=>void $(w),onStop:()=>Z(()=>v.stop(e)),busy:K&&!Y,disabled:D||Y||Q.running,canSend:!!w.trim()||M.hasFiles,onEdit:M.onEdit,onKey:M.onKeyDown,onFiles:M.onFiles,dropping:M.dropping,drop:M.drop,mentions:M.mentions,combo:M.combo,top:(0,L.jsxs)(L.Fragment,{children:[M.chips,Q.state&&(0,L.jsx)(te,{state:Q.state,onStop:()=>void Q.stop(),onUndo:Q.undo,onClose:Q.close})]}),left:(0,L.jsxs)(L.Fragment,{children:[M.paperclip,(0,L.jsx)(ie,{chat:e,thread:V,ended:q,snap:X,onError:S}),(0,L.jsx)(ee,{running:Q.running,disabled:!w.trim()||D||Y,onClick:()=>void Q.start(w)})]}),placeholder:q?`Write to carry on this chat…`:Y?`Answer above to go on`:K?`ForgeQE is working…`:`Reply to ForgeQE…`,right:(0,L.jsx)(O,{chat:e,thread:V,ended:q,busy:K||D,snap:X,onError:S})})]})})]})}var z=[{id:`all`,label:`All`},{id:`working`,label:`Working`},{id:`waiting`,label:`Needs you`},{id:`done`,label:`Your turn`},{id:`ended`,label:`Ended`}],B=50;function V(){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(``),[o,s]=(0,I.useState)(`all`),[c,f]=(0,I.useState)(``),[m,_]=(0,I.useState)(B);(0,I.useEffect)(()=>_(B),[o,c]),(0,I.useEffect)(()=>{let e=!1,t=()=>v.list().then(t=>!e&&n(t.chats),t=>!e&&i(t.message));t();let r=setInterval(t,5e3);return()=>{e=!0,clearInterval(r)}},[]);let x=(0,I.useMemo)(()=>{let e={all:0,working:0,waiting:0,done:0,ended:0};for(let n of t||[])e.all++,e[N(n)]++;return e},[t]),C=(0,I.useMemo)(()=>j((t||[]).filter(e=>(o===`all`||N(e)===o)&&M(e,c))),[t,o,c]),E=(0,I.useMemo)(()=>{let e=[];for(let t of C.slice(0,m)){let n=D(t.lastAt||t.started),r=e.find(e=>e.day===n);r?r.chats.push(t):e.push({day:n,chats:[t]})}return e},[C,m]);return(0,L.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,L.jsx)(w,{}),(0,L.jsxs)(`main`,{className:u(T,`gap-5`),children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsx)(b,{pixel:S.chats,size:`lg`}),(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,L.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:`Chats`}),(0,L.jsx)(`span`,{className:`text-[13px] text-muted`,children:`Each one is its own ForgeQE agent in your project folder. Past chats stay here after forgeqe web restarts, to read or carry on.`})]}),(0,L.jsxs)(`a`,{className:u(y({variant:`primary`}),`gap-2`),href:p(),children:[(0,L.jsx)(e,{"aria-hidden":`true`}),`New chat`]})]}),t&&t.length>0&&(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(`div`,{role:`radiogroup`,"aria-label":`Show`,className:`flex flex-wrap gap-1 rounded-[10px] bg-surface-strong p-1`,children:z.map(e=>(0,L.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":o===e.id,onClick:()=>s(e.id),className:u(`inline-flex min-h-8 cursor-pointer items-center gap-1.5 rounded-[7px] border-0 px-3 text-sm font-medium`,o===e.id?`bg-bg text-ink shadow-sm`:`bg-transparent text-muted hover:text-ink`),children:[e.label,(0,L.jsx)(`span`,{className:u(`tabular-nums text-[12px]`,e.id===`waiting`&&x.waiting?`text-warn`:`text-muted`),children:x[e.id]})]},e.id))}),(0,L.jsx)(h,{id:`find-a-chat`,label:`Find a chat`,value:c,onChange:f})]}),r&&(0,L.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail`,children:r}),!t&&!r&&(0,L.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Loading…`}),t&&t.length===0&&(0,L.jsx)(g,{icon:l,title:`No chats yet`,action:(0,L.jsxs)(`a`,{className:y({size:`sm`}),href:p(),"data-tip":`Start a chat`,children:[(0,L.jsx)(l,{"aria-hidden":`true`}),`Chat`]}),children:`Ask ForgeQE to run test cases, explore a journey, write a test or review requirements. Each chat shows up here, and stays after forgeqe web restarts so you can carry it on.`}),t&&t.length>0&&C.length===0&&(0,L.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`No chat matches.`}),C.length>0&&(0,L.jsxs)(`div`,{className:`@container rounded-[14px] card border`,children:[(0,L.jsxs)(`div`,{"aria-hidden":`true`,className:`hidden grid-cols-[minmax(0,1fr)_120px_90px_150px_96px] gap-x-4 border-b border-line-soft px-6 py-2 text-[12px] font-medium text-muted @3xl:grid`,children:[(0,L.jsx)(`span`,{children:`Chat`}),(0,L.jsx)(`span`,{children:`Status`}),(0,L.jsx)(`span`,{children:`Messages`}),(0,L.jsx)(`span`,{children:`Model`}),(0,L.jsx)(`span`,{className:`text-right`,children:`Last activity`})]}),E.map(e=>(0,L.jsxs)(`section`,{"aria-labelledby":`day-${e.day}`,children:[(0,L.jsxs)(`h2`,{id:`day-${e.day}`,className:`sticky top-0 z-[1] m-0 border-b border-line-soft bg-surface-muted/95 px-6 py-1.5 text-[12px] font-semibold tracking-wide text-muted uppercase backdrop-blur`,children:[e.day,` `,(0,L.jsxs)(`span`,{className:`font-normal tabular-nums`,children:[`· `,e.chats.length]})]}),(0,L.jsx)(`ul`,{className:`m-0 flex list-none flex-col p-1.5`,children:e.chats.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsx)(P,{c:e})},e.id))})]},e.day)),C.length>m&&(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-line-soft px-6 py-3 text-[13px] text-muted`,children:[(0,L.jsxs)(`span`,{children:[`Showing `,m,` of `,C.length]}),(0,L.jsxs)(d,{size:`sm`,onClick:()=>_(m+B),children:[(0,L.jsx)(a,{"aria-hidden":`true`}),`More (`,Math.min(B,C.length-m),`)`]})]})]})]})]})}export{R as Chat,V as Chats};