wizards 0.2.42 → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/app.js +37 -3
- package/apps/runtime/dist/authoring/guide.js +5 -2
- package/apps/runtime/dist/browser/fast/action-space.js +162 -0
- package/apps/runtime/dist/browser/fast/classifier.js +91 -0
- package/apps/runtime/dist/browser/fast/decide.js +171 -0
- package/apps/runtime/dist/browser/fast/driver.js +141 -0
- package/apps/runtime/dist/browser/fast/instructions.js +33 -0
- package/apps/runtime/dist/browser/fast/run.js +249 -0
- package/apps/runtime/dist/browser/fast/span-picker.js +153 -0
- package/apps/runtime/dist/browser/fast/text-helper.js +178 -0
- package/apps/runtime/dist/browser/snapshot.js +335 -0
- package/apps/runtime/dist/db/migrations/tenant/0011_runners.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0011_snapshot.json +2956 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +4 -0
- package/apps/runtime/dist/engine/resources.js +109 -0
- package/apps/runtime/dist/engine/runner.js +7 -3
- package/apps/runtime/dist/engine/steps.js +89 -10
- package/apps/runtime/dist/env.js +9 -0
- package/apps/runtime/dist/harness/claude.js +9 -1
- package/apps/runtime/dist/link-preview.js +4 -3
- package/apps/runtime/dist/mcp/tools.js +1 -1
- package/apps/runtime/dist/media/conversation.js +177 -0
- package/apps/runtime/dist/models.js +17 -0
- package/apps/runtime/dist/plugins/loader.js +48 -2
- package/apps/runtime/dist/plugins/registry.js +1 -0
- package/apps/runtime/dist/plugins/runs.js +205 -0
- package/apps/runtime/dist/routes/runs.js +206 -22
- package/apps/runtime/dist/routes/studio.js +12 -1
- package/apps/runtime/dist/services/cloud.js +1 -0
- package/apps/runtime/dist/services/runners.js +138 -0
- package/apps/runtime/dist/services/runs.js +83 -45
- package/apps/runtime/dist/services/wizard-icon.js +12 -0
- package/apps/runtime/dist/services/wizards.js +5 -1
- package/apps/runtime/dist/tools/browser.js +426 -97
- package/apps/runtime/dist/tools/index.js +50 -3
- package/apps/web/dist/assets/ChangelogDialog-8qS5utcR.js +1 -0
- package/apps/web/dist/assets/ChatView-Bx1KVCEf.js +10 -0
- package/apps/web/dist/assets/{CreditsDialog-DPglouDr.js → CreditsDialog-BCuDsatt.js} +1 -1
- package/apps/web/dist/assets/EditorPage-_Sbj-mSD.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-CQN5acxA.js → FlowPreview-COgjib4H.js} +1 -1
- package/apps/web/dist/assets/{Harness-BFxUFB7B.js → Harness-BaxjV1Ng.js} +2 -2
- package/apps/web/dist/assets/HomePage-BlD0wZB0.js +1 -0
- package/apps/web/dist/assets/ImportWizard-BZDtNJg1.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-Ci_x__p9.js +2 -0
- package/apps/web/dist/assets/ProjectPage-NwFut2Z-.js +2 -0
- package/apps/web/dist/assets/PublicRunner-rHdvK18v.js +1 -0
- package/apps/web/dist/assets/RunDrawer-Dp-JowDX.js +4 -0
- package/apps/web/dist/assets/RunnerView-DSlReODC.js +2 -0
- package/apps/web/dist/assets/SettingsPage-2Bw-D3hC.js +1 -0
- package/apps/web/dist/assets/SetupPage-DHESCsTb.js +1 -0
- package/apps/web/dist/assets/SharePage-DdJ-qD-B.js +1 -0
- package/apps/web/dist/assets/ThemeSwitch-BkodFy16.js +1 -0
- package/apps/web/dist/assets/arrow-right-pf8p4FIz.js +1 -0
- package/apps/web/dist/assets/changelog-cmQb-lZW.js +1 -0
- package/apps/web/dist/assets/{circle-alert-B0rwkpC7.js → circle-alert-Gn4D6etf.js} +1 -1
- package/apps/web/dist/assets/{copy-DgbMaHoj.js → copy-C3D7PBYL.js} +1 -1
- package/apps/web/dist/assets/{definition-FVgbAXOo.js → definition-AlI4g-wR.js} +2 -2
- package/apps/web/dist/assets/{external-link-pP6YfR9-.js → external-link-M3mEgZA-.js} +1 -1
- package/apps/web/dist/assets/globe-BnaeE83w.js +1 -0
- package/apps/web/dist/assets/{image-D2X6TWdq.js → image-BuasG4Jr.js} +1 -1
- package/apps/web/dist/assets/index-BdrX1tJ4.js +78 -0
- package/apps/web/dist/assets/index-D6vcOCCh.css +1 -0
- package/apps/web/dist/assets/{lock-BG4mi_lJ.js → lock-CrB_z7n3.js} +1 -1
- package/apps/web/dist/assets/{meta-BD9yulXs.js → meta-CT4LmQ7g.js} +1 -1
- package/apps/web/dist/assets/mouse-pointer-click-BurvPVO8.js +1 -0
- package/apps/web/dist/assets/{pen-line-D54vxrGl.js → pen-line-BA6l84zC.js} +1 -1
- package/apps/web/dist/assets/{refresh-cw-DvTgdpdf.js → refresh-cw-DEKCEuIO.js} +1 -1
- package/apps/web/dist/assets/{session-CT1AZIlE.js → session-DCcgTTmG.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-DJATAPGg.js → settings-menu-C9fE9M0f.js} +1 -1
- package/apps/web/dist/assets/star-BwhVXiJM.js +1 -0
- package/apps/web/dist/assets/{trash-DAcf34LR.js → trash-WwlTeE_V.js} +1 -1
- package/apps/web/dist/assets/{type-BU0mWqf3.js → type-kpWj7Zf1.js} +1 -1
- package/apps/web/dist/assets/ui-Wxaw_APn.js +9 -0
- package/apps/web/dist/assets/{video-C6qoFAAs.js → video-U-idAC66.js} +1 -1
- package/apps/web/dist/assets/volume-2-BwidpioC.js +1 -0
- package/apps/web/dist/assets/{wand-sparkles-Bw4tu2An.js → wand-sparkles-DaINku4r.js} +1 -1
- package/apps/web/dist/embed.js +119 -4
- package/apps/web/dist/index.html +12 -11
- package/apps/web/dist/mcp/flow.html +45 -45
- package/modules/calls/dist/client.css +3 -0
- package/modules/calls/dist/client.js +1 -0
- package/modules/calls/engenty.plugin.json +8 -0
- package/modules/calls/migrations/0001_init.sql +26 -0
- package/modules/calls/package.json +25 -0
- package/modules/calls/src/openai.ts +155 -0
- package/modules/calls/src/plugin.ts +407 -0
- package/modules/calls/src/rules.ts +226 -0
- package/modules/calls/src/schema.ts +39 -0
- package/modules/calls/src/session.ts +353 -0
- package/modules/calls/src/store.ts +124 -0
- package/modules/calls/src/twilio.ts +90 -0
- package/modules/calls/tsconfig.json +10 -0
- package/modules/calls/ui/Settings.tsx +137 -0
- package/modules/calls/ui/app.ts +50 -0
- package/modules/calls/ui/messages.ts +81 -0
- package/modules/calls/ui/parts.tsx +36 -0
- package/modules/calls/ui/plugin.tsx +15 -0
- package/modules/sms/dist/client.css +3 -0
- package/modules/sms/dist/client.js +1 -0
- package/modules/sms/engenty.plugin.json +8 -0
- package/modules/sms/migrations/0001_init.sql +26 -0
- package/modules/sms/package.json +25 -0
- package/modules/sms/src/plugin.ts +324 -0
- package/modules/sms/src/schema.ts +26 -0
- package/modules/sms/src/store.ts +140 -0
- package/modules/sms/src/surface.ts +70 -0
- package/modules/sms/src/twilio.ts +130 -0
- package/modules/sms/tsconfig.json +10 -0
- package/modules/sms/ui/Settings.tsx +113 -0
- package/modules/sms/ui/Share.tsx +78 -0
- package/modules/sms/ui/app.ts +51 -0
- package/modules/sms/ui/messages.ts +72 -0
- package/modules/sms/ui/parts.tsx +36 -0
- package/modules/sms/ui/plugin.tsx +20 -0
- package/modules/whatsapp/dist/client.css +3 -0
- package/modules/whatsapp/dist/client.js +1 -0
- package/modules/whatsapp/engenty.plugin.json +8 -0
- package/modules/whatsapp/migrations/0001_init.sql +30 -0
- package/modules/whatsapp/package.json +25 -0
- package/modules/whatsapp/src/graph.ts +271 -0
- package/modules/whatsapp/src/inbound.ts +143 -0
- package/modules/whatsapp/src/plugin.ts +369 -0
- package/modules/whatsapp/src/schema.ts +32 -0
- package/modules/whatsapp/src/store.ts +156 -0
- package/modules/whatsapp/src/surface.ts +127 -0
- package/modules/whatsapp/tsconfig.json +10 -0
- package/modules/whatsapp/ui/Settings.tsx +141 -0
- package/modules/whatsapp/ui/Share.tsx +78 -0
- package/modules/whatsapp/ui/app.ts +54 -0
- package/modules/whatsapp/ui/messages.ts +82 -0
- package/modules/whatsapp/ui/parts.tsx +36 -0
- package/modules/whatsapp/ui/plugin.tsx +20 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +259 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +17 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.d.ts +174 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +816 -0
- package/node_modules/@engenty-wizards/plugin-sdk/package.json +2 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.js +21 -0
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +61 -3
- package/node_modules/@engenty-wizards/shared/dist/run.js +16 -0
- package/node_modules/@engenty-wizards/shared/dist/runners.d.ts +81 -0
- package/node_modules/@engenty-wizards/shared/dist/runners.js +146 -0
- package/package.json +1 -1
- package/apps/web/dist/assets/ChangelogDialog-BxRBTR8P.js +0 -1
- package/apps/web/dist/assets/EditorPage-BKAFzzWk.js +0 -3
- package/apps/web/dist/assets/HomePage-BZuwrr-b.js +0 -1
- package/apps/web/dist/assets/ImportWizard-JGMemER4.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-BwHAsJwj.js +0 -2
- package/apps/web/dist/assets/ProjectPage--ijr1jPE.js +0 -2
- package/apps/web/dist/assets/PublicRunner-D9Oe-_vs.js +0 -1
- package/apps/web/dist/assets/RunDrawer-BfociUm2.js +0 -4
- package/apps/web/dist/assets/RunnerView-D2b84UTY.js +0 -2
- package/apps/web/dist/assets/SettingsPage-9rk9IRdr.js +0 -1
- package/apps/web/dist/assets/SetupPage-BUJh_v9q.js +0 -1
- package/apps/web/dist/assets/SharePage-sNJ_s1RE.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-NDTEeh0R.js +0 -1
- package/apps/web/dist/assets/arrow-right-C1xLSnNa.js +0 -1
- package/apps/web/dist/assets/changelog-BSVi9hHS.js +0 -1
- package/apps/web/dist/assets/index-CBjgitjd.js +0 -78
- package/apps/web/dist/assets/index-gTcC8eX6.css +0 -1
- package/apps/web/dist/assets/star-CaOg5c-D.js +0 -1
- package/apps/web/dist/assets/ui-Bxf6zX5k.js +0 -9
- package/apps/web/dist/assets/volume-2-Dw4p9Ln4.js +0 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// The page as the wizard's browser sees it. Two views over one set of element ids that the page
|
|
2
|
+
// itself hands out (`window.__jevFast`), so an id names the same element in both and across
|
|
3
|
+
// readings:
|
|
4
|
+
//
|
|
5
|
+
// - `SNAPSHOT_SCRIPT`, the fast loop's observation: the visible controls in the viewport, their
|
|
6
|
+
// semantics and a freshness marker. Ported from engenty-pro's fast loop, which took it from
|
|
7
|
+
// browser-use/jev-ultrafast `snapshot.js` (MIT, Copyright (c) 2026 Browser Use) and kept it
|
|
8
|
+
// verbatim on purpose: the limits (250 actions, 6000 chars of text), the visible-only filter
|
|
9
|
+
// and the marker are what make a classifier's answer safe to execute. One change: a value the
|
|
10
|
+
// person typed into the page is not read out (`__wzPersonal`).
|
|
11
|
+
// - `PAGE_SCRIPT`, what an agent step reads: the whole page's visible controls, a dialog or
|
|
12
|
+
// cookie banner first, and its visible text.
|
|
13
|
+
//
|
|
14
|
+
// The scripts are strings on purpose: a function would be compiled first, and the dev build
|
|
15
|
+
// wraps named functions in a helper the page does not have.
|
|
16
|
+
/** What stands in for a value the person typed: the models learn a field is filled, not with what. */
|
|
17
|
+
export const PERSONAL = "(entered by the person)";
|
|
18
|
+
/** The whole observation, as one expression. */
|
|
19
|
+
export const SNAPSHOT_SCRIPT = String.raw `(() => {
|
|
20
|
+
if (!document.body) return null;
|
|
21
|
+
const cache = window.__jevFast ||= {ids:new WeakMap(), nodes:new Map(), next:1};
|
|
22
|
+
const identity = e => {
|
|
23
|
+
if (!cache.ids.has(e)) cache.ids.set(e,cache.next++);
|
|
24
|
+
const id=cache.ids.get(e); cache.nodes.set(id,e); return id;
|
|
25
|
+
};
|
|
26
|
+
for (const [id,e] of cache.nodes) if (!e.isConnected) cache.nodes.delete(id);
|
|
27
|
+
const safe = e => !['password','file','hidden'].includes(e.type);
|
|
28
|
+
const visible = e => !e.closest('[aria-hidden="true"],[inert]') &&
|
|
29
|
+
e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true});
|
|
30
|
+
const name = (e,seen=new Set()) => {
|
|
31
|
+
if (!e || seen.has(e)) return '';
|
|
32
|
+
seen.add(e);
|
|
33
|
+
const referenced=(e.getAttribute('aria-labelledby')||'').split(/\s+/)
|
|
34
|
+
.map(id=>name(document.getElementById(id),seen)).filter(Boolean).join(' ');
|
|
35
|
+
return referenced || e.getAttribute('aria-label') ||
|
|
36
|
+
[...(e.labels||[])].map(l=>name(l,seen)).filter(Boolean).join(' ') ||
|
|
37
|
+
(['button','submit','reset'].includes(e.type) ? e.value : '') || e.getAttribute('alt') ||
|
|
38
|
+
(e.tagName==='INPUT' ? '' : [...e.childNodes].map(n=>n.nodeType===3 ? n.textContent :
|
|
39
|
+
n.nodeType===1 && n.getAttribute('aria-hidden')!=='true' ? name(n,seen) : '').join(' ').trim()) ||
|
|
40
|
+
e.getAttribute('title') || e.getAttribute('placeholder') || '';
|
|
41
|
+
};
|
|
42
|
+
const roles=['button','link','checkbox','radio','switch','tab','menuitem','menuitemradio',
|
|
43
|
+
'option','gridcell','combobox','textbox','searchbox','spinbutton'];
|
|
44
|
+
const selector='a[href],button,input,textarea,select,summary,[contenteditable="true"],'+
|
|
45
|
+
roles.map(role=>'[role="'+role+'"]').join(',');
|
|
46
|
+
const role = e => {
|
|
47
|
+
const explicit=e.getAttribute('role');
|
|
48
|
+
if (roles.includes(explicit)) return explicit;
|
|
49
|
+
if (e.tagName==='BUTTON' || e.tagName==='SUMMARY') return 'button';
|
|
50
|
+
if (e.tagName==='A') return 'link';
|
|
51
|
+
if (e.tagName==='SELECT') return 'combobox';
|
|
52
|
+
if (e.tagName==='TEXTAREA' || e.isContentEditable) return 'textbox';
|
|
53
|
+
if (e.tagName==='INPUT') {
|
|
54
|
+
if (['checkbox','radio'].includes(e.type)) return e.type;
|
|
55
|
+
if (['button','submit','reset','image'].includes(e.type)) return 'button';
|
|
56
|
+
if (e.type==='search') return 'searchbox';
|
|
57
|
+
if (e.type==='number') return 'spinbutton';
|
|
58
|
+
if (['text','email','url','tel'].includes(e.type)) return 'textbox';
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
cache.pageKey=()=>[performance.timeOrigin,location.href,scrollX,scrollY,innerWidth,innerHeight,
|
|
63
|
+
[...document.querySelectorAll('input,textarea,select')].filter(safe)
|
|
64
|
+
.map(e=>[identity(e),e.value,e.checked,e.selectedIndex,e.disabled,e.readOnly])];
|
|
65
|
+
cache.guard=e=>{
|
|
66
|
+
if (!e?.isConnected || !visible(e)) return null;
|
|
67
|
+
const scope=e.closest('form,dialog,[role="dialog"],article,li,tr,[role="row"]') || e.parentElement;
|
|
68
|
+
return [identity(e),role(e),name(e),e.value??null,e.checked??null,e.selectedIndex??null,
|
|
69
|
+
e.readOnly??null,e.matches(':disabled'),e.getAttribute('aria-disabled'),
|
|
70
|
+
e.getAttribute('aria-expanded'),e.getAttribute('aria-checked'),e.getAttribute('aria-selected'),
|
|
71
|
+
e.getAttribute('href'),scope?.innerText?.slice(0,6000)||''];
|
|
72
|
+
};
|
|
73
|
+
const actions=[];
|
|
74
|
+
for (const e of document.querySelectorAll(selector)) {
|
|
75
|
+
if (!safe(e) || !visible(e) || e.matches(':disabled') || e.closest('[aria-disabled="true"]')) continue;
|
|
76
|
+
const r=e.getBoundingClientRect(), x=r.x+r.width/2, y=r.y+r.height/2, rname=role(e);
|
|
77
|
+
if (!rname || r.width<=0 || r.height<=0 || x<0 || y<0 || x>=innerWidth || y>=innerHeight) continue;
|
|
78
|
+
if (rname==='gridcell' && e.querySelector('button,[role="button"]')) continue;
|
|
79
|
+
const base={node:identity(e),role:rname,label:name(e)||rname,
|
|
80
|
+
rect:{x:r.x,y:r.y,w:r.width,h:r.height}};
|
|
81
|
+
for (const key of ['checked','selected','expanded']) {
|
|
82
|
+
const value=e.getAttribute('aria-'+key);
|
|
83
|
+
if (value!==null) base[key]=value;
|
|
84
|
+
}
|
|
85
|
+
if (['checkbox','radio'].includes(e.type)) base.checked=String(e.checked);
|
|
86
|
+
if (e.tagName==='SELECT') {
|
|
87
|
+
for (const o of e.options) if (!o.selected && !o.disabled && !o.closest('optgroup[disabled]'))
|
|
88
|
+
actions.push({...base,kind:'select',value:o.value,
|
|
89
|
+
current_value:[...e.selectedOptions].map(o=>o.label).join(', '),label:base.label+' → '+o.label});
|
|
90
|
+
} else {
|
|
91
|
+
const editable=!e.readOnly && e.getAttribute('aria-readonly')!=='true' &&
|
|
92
|
+
(['textbox','searchbox','spinbutton'].includes(rname) ||
|
|
93
|
+
(rname==='combobox' && ['INPUT','TEXTAREA'].includes(e.tagName)));
|
|
94
|
+
const value=window.__wzPersonal?.has(e) ? ${JSON.stringify(PERSONAL)} : 'value' in e ? String(e.value) :
|
|
95
|
+
e.isContentEditable || rname==='combobox' ? e.innerText.trim() : '';
|
|
96
|
+
actions.push({...base,kind:editable?'fill':'click',value});
|
|
97
|
+
if (editable) actions.push({...base,kind:'click',value,label:'Open '+base.label});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const words=[], walker=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT);
|
|
101
|
+
const range=document.createRange(); let node,length=0;
|
|
102
|
+
while ((node=walker.nextNode()) && length<6000) {
|
|
103
|
+
const value=node.textContent.trim(), parent=node.parentElement;
|
|
104
|
+
if (!value || !parent || parent.closest('script,style,noscript,template') || !visible(parent)) continue;
|
|
105
|
+
range.selectNodeContents(node); const r=range.getBoundingClientRect();
|
|
106
|
+
if (r.width>0 && r.height>0 && r.bottom>0 && r.top<innerHeight && r.right>0 && r.left<innerWidth) {
|
|
107
|
+
words.push(value); length+=value.length;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const text=words.join('\n').slice(0,6000), height=document.documentElement.scrollHeight;
|
|
111
|
+
const page_key=cache.pageKey(), guards={};
|
|
112
|
+
for (const a of actions) if (!(a.node in guards)) guards[a.node]=cache.guard(cache.nodes.get(a.node));
|
|
113
|
+
// Compare meaning and identity. Geometry is always resolved and hit-tested just before input.
|
|
114
|
+
const semantics=actions.map(({rect,...action})=>action);
|
|
115
|
+
const marker=[performance.timeOrigin,location.href,scrollX,scrollY,innerWidth,innerHeight,
|
|
116
|
+
document.title,text,semantics,page_key[6]];
|
|
117
|
+
const omitted_actions=Math.max(0,actions.length-250);
|
|
118
|
+
actions.splice(250);
|
|
119
|
+
actions.forEach((a,i)=>a.id='e'+(i+1));
|
|
120
|
+
if (scrollY+innerHeight<height-2) actions.push({id:'scroll_down',kind:'scroll',label:'Scroll down',delta:560});
|
|
121
|
+
if (scrollY>0) actions.push({id:'scroll_up',kind:'scroll',label:'Scroll up',delta:-560});
|
|
122
|
+
actions.push({id:'wait',kind:'wait',label:'Wait for the page to update'});
|
|
123
|
+
return {url:location.href,title:document.title,w:innerWidth,h:innerHeight,text,
|
|
124
|
+
scroll:{y:scrollY,height},actions,marker,page_key,guards,omitted_actions};
|
|
125
|
+
})()`;
|
|
126
|
+
/** Just the freshness marker — cheaper than a full observation. */
|
|
127
|
+
export const MARKER_SCRIPT = `(() => { const state=${SNAPSHOT_SCRIPT}; return state?.marker ?? null; })()`;
|
|
128
|
+
/** The page key plus one node's guard: is this exact element still what we saw. */
|
|
129
|
+
export function nodeGuardScript(node) {
|
|
130
|
+
return `(() => { const c=window.__jevFast; return c ? [c.pageKey(),c.guard(c.nodes.get(${node}))] : null; })()`;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resolve an observed node to a click point RIGHT before input: still
|
|
134
|
+
* attached, enabled, visible, inside the viewport, and the top-most element
|
|
135
|
+
* at its centre (occlusion). For `select`, also apply the value here — a
|
|
136
|
+
* native <select> takes no synthetic click. Returns null when any check
|
|
137
|
+
* fails, which the driver reports as a stale page.
|
|
138
|
+
*/
|
|
139
|
+
export function actTargetScript(action) {
|
|
140
|
+
return `(action => {
|
|
141
|
+
const e=window.__jevFast?.nodes.get(action.node);
|
|
142
|
+
if (!e?.isConnected || e.matches(':disabled') || e.closest('[aria-disabled="true"],[inert]') ||
|
|
143
|
+
!e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true})) return null;
|
|
144
|
+
if (action.kind==='fill' && (e.readOnly || e.getAttribute('aria-readonly')==='true')) return null;
|
|
145
|
+
const r=e.getBoundingClientRect(), x=r.x+r.width/2, y=r.y+r.height/2;
|
|
146
|
+
if (!r.width || !r.height || x<0 || y<0 || x>=innerWidth || y>=innerHeight) return null;
|
|
147
|
+
if (!e.contains(document.elementFromPoint(x,y))) return null;
|
|
148
|
+
if (action.kind==='select') {
|
|
149
|
+
if (e.tagName!=='SELECT' || ![...e.options].some(o=>o.value===action.value &&
|
|
150
|
+
!o.disabled && !o.closest('optgroup[disabled]'))) return null;
|
|
151
|
+
e.value=action.value;
|
|
152
|
+
e.dispatchEvent(new Event('input',{bubbles:true}));
|
|
153
|
+
e.dispatchEvent(new Event('change',{bubbles:true}));
|
|
154
|
+
}
|
|
155
|
+
return {x,y};
|
|
156
|
+
})(${JSON.stringify({ kind: action.kind, node: action.node, value: action.value ?? null })})`;
|
|
157
|
+
}
|
|
158
|
+
/** No DOM mutation for this long counts as the page having settled. */
|
|
159
|
+
export const SETTLE_QUIET_MS = 100;
|
|
160
|
+
/** Longest a settle waits; a page that never goes quiet is observed anyway. */
|
|
161
|
+
export const SETTLE_CAP_MS = 1500;
|
|
162
|
+
/**
|
|
163
|
+
* Wait for the page to come to rest before the next observation: at least
|
|
164
|
+
* two animation frames, then no DOM mutation for `SETTLE_QUIET_MS` and no
|
|
165
|
+
* finite CSS/Web animation still running (a re-rendering calendar, a dialog
|
|
166
|
+
* sliding in — a spinner's infinite animation is ignored). After typing into
|
|
167
|
+
* an autocomplete, also wait for its options to be visible. `action` is null
|
|
168
|
+
* when settling without a preceding input (a stale retry). Capped at
|
|
169
|
+
* `SETTLE_CAP_MS` so a busy page never stalls the loop.
|
|
170
|
+
*/
|
|
171
|
+
export function settleScript(action) {
|
|
172
|
+
return `(action => new Promise(resolve => {
|
|
173
|
+
const field=action.node===null ? null : window.__jevFast?.nodes.get(action.node);
|
|
174
|
+
const autocomplete=action.kind==='fill' && field?.getAttribute('role')==='combobox';
|
|
175
|
+
let frames=0, stopped=false, lastMutation=performance.now();
|
|
176
|
+
const observer=new MutationObserver(()=>{lastMutation=performance.now()});
|
|
177
|
+
observer.observe(document.documentElement,{subtree:true,childList:true,attributes:true,characterData:true});
|
|
178
|
+
const finish=()=>{if(stopped)return;stopped=true;observer.disconnect();resolve(true)};
|
|
179
|
+
setTimeout(finish,${SETTLE_CAP_MS});
|
|
180
|
+
const optionsVisible=()=>{
|
|
181
|
+
const ids=(field?.getAttribute('aria-controls')||field?.getAttribute('aria-owns')||'')
|
|
182
|
+
.split(/\\s+/).filter(Boolean);
|
|
183
|
+
const roots=ids.length ? ids.map(id=>document.getElementById(id)).filter(Boolean) : [document];
|
|
184
|
+
return roots.flatMap(root=>[...root.querySelectorAll('[role="option"]')]).some(e=>{
|
|
185
|
+
const r=e.getBoundingClientRect();
|
|
186
|
+
return r.width && r.height && r.bottom>0 && r.top<innerHeight &&
|
|
187
|
+
e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const animating=()=>document.getAnimations().some(a=>
|
|
191
|
+
a.playState==='running' && a.effect?.getTiming?.().iterations!==Infinity);
|
|
192
|
+
const ready=()=>{
|
|
193
|
+
if (stopped) return;
|
|
194
|
+
const quiet=performance.now()-lastMutation>=${SETTLE_QUIET_MS} && !animating();
|
|
195
|
+
if (++frames>=2 && quiet && (!autocomplete || optionsVisible())) finish();
|
|
196
|
+
else requestAnimationFrame(ready);
|
|
197
|
+
};
|
|
198
|
+
requestAnimationFrame(ready);
|
|
199
|
+
}))(${JSON.stringify({ kind: action?.kind ?? null, node: action?.node ?? null })})`;
|
|
200
|
+
}
|
|
201
|
+
/** How many controls an agent step reads at once; the rest come with scrolling or the next read. */
|
|
202
|
+
export const PAGE_ITEMS = 150;
|
|
203
|
+
/** Options of a dropdown listed by name. */
|
|
204
|
+
const PAGE_OPTIONS = 40;
|
|
205
|
+
/** Where a banner or dialog over the page lives. */
|
|
206
|
+
const OVERLAY = "[role=dialog],[role=alertdialog],[aria-modal=true],dialog[open],[id*=cookie i],[class*=cookie i],[id*=consent i],[class*=consent i],[id*=onetrust i],[id*=didomi i],[id*=usercentrics i]";
|
|
207
|
+
/**
|
|
208
|
+
* The whole page's visible controls — a dialog or banner first, then in page order — and its
|
|
209
|
+
* visible text. The same ids as the fast loop's observation. Password fields are listed (a
|
|
210
|
+
* sign-in request names them) but never with a value.
|
|
211
|
+
*/
|
|
212
|
+
export const PAGE_SCRIPT = String.raw `(() => {
|
|
213
|
+
if (!document.body) return null;
|
|
214
|
+
const cache = window.__jevFast ||= {ids:new WeakMap(), nodes:new Map(), next:1};
|
|
215
|
+
const identity = e => {
|
|
216
|
+
if (!cache.ids.has(e)) cache.ids.set(e,cache.next++);
|
|
217
|
+
const id=cache.ids.get(e); cache.nodes.set(id,e); return id;
|
|
218
|
+
};
|
|
219
|
+
for (const [id,e] of cache.nodes) if (!e.isConnected) cache.nodes.delete(id);
|
|
220
|
+
const visible = e => !e.closest('[aria-hidden="true"],[inert]') &&
|
|
221
|
+
e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true});
|
|
222
|
+
const name = (e,seen=new Set()) => {
|
|
223
|
+
if (!e || seen.has(e)) return '';
|
|
224
|
+
seen.add(e);
|
|
225
|
+
const referenced=(e.getAttribute('aria-labelledby')||'').split(/\s+/)
|
|
226
|
+
.map(id=>name(document.getElementById(id),seen)).filter(Boolean).join(' ');
|
|
227
|
+
return referenced || e.getAttribute('aria-label') ||
|
|
228
|
+
[...(e.labels||[])].map(l=>name(l,seen)).filter(Boolean).join(' ') ||
|
|
229
|
+
(['button','submit','reset'].includes(e.type) ? e.value : '') || e.getAttribute('alt') ||
|
|
230
|
+
(e.tagName==='INPUT' ? '' : [...e.childNodes].map(n=>n.nodeType===3 ? n.textContent :
|
|
231
|
+
n.nodeType===1 && n.getAttribute('aria-hidden')!=='true' ? name(n,seen) : '').join(' ').trim()) ||
|
|
232
|
+
e.getAttribute('title') || e.getAttribute('placeholder') || '';
|
|
233
|
+
};
|
|
234
|
+
const roles=['button','link','checkbox','radio','switch','tab','menuitem','menuitemradio',
|
|
235
|
+
'option','gridcell','combobox','textbox','searchbox','spinbutton','listbox'];
|
|
236
|
+
const selector='a[href],button,input,textarea,select,summary,[contenteditable="true"],'+
|
|
237
|
+
roles.map(role=>'[role="'+role+'"]').join(',');
|
|
238
|
+
const role = e => {
|
|
239
|
+
const explicit=e.getAttribute('role');
|
|
240
|
+
if (roles.includes(explicit)) return explicit;
|
|
241
|
+
if (e.tagName==='BUTTON' || e.tagName==='SUMMARY') return 'button';
|
|
242
|
+
if (e.tagName==='A') return 'link';
|
|
243
|
+
if (e.tagName==='SELECT') return 'combobox';
|
|
244
|
+
if (e.tagName==='TEXTAREA' || e.isContentEditable) return 'textbox';
|
|
245
|
+
if (e.tagName==='INPUT') {
|
|
246
|
+
if (e.type==='password') return 'password';
|
|
247
|
+
if (['checkbox','radio'].includes(e.type)) return e.type;
|
|
248
|
+
if (['button','submit','reset','image'].includes(e.type)) return 'button';
|
|
249
|
+
if (e.type==='search') return 'searchbox';
|
|
250
|
+
if (e.type==='number') return 'spinbutton';
|
|
251
|
+
return 'textbox';
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
};
|
|
255
|
+
const front=[], rest=[];
|
|
256
|
+
for (const e of document.querySelectorAll(selector)) {
|
|
257
|
+
if (['file','hidden'].includes(e.type) || !visible(e) || e.matches(':disabled') ||
|
|
258
|
+
e.closest('[aria-disabled="true"]')) continue;
|
|
259
|
+
const r=e.getBoundingClientRect(), rname=role(e);
|
|
260
|
+
if (!rname || r.width<=0 || r.height<=0) continue;
|
|
261
|
+
if (rname==='gridcell' && e.querySelector('button,[role="button"]')) continue;
|
|
262
|
+
const item={ref:identity(e),role:rname,label:(name(e)||'').replace(/\s+/g,' ').trim().slice(0,100)};
|
|
263
|
+
for (const key of ['checked','selected','expanded']) {
|
|
264
|
+
const value=e.getAttribute('aria-'+key);
|
|
265
|
+
if (value!==null) item[key]=value;
|
|
266
|
+
}
|
|
267
|
+
if (['checkbox','radio'].includes(e.type)) item.checked=String(e.checked);
|
|
268
|
+
if (rname==='password') {
|
|
269
|
+
item.kind='password';
|
|
270
|
+
if (e.value) item.value=${JSON.stringify(PERSONAL)};
|
|
271
|
+
} else if (e.tagName==='SELECT') {
|
|
272
|
+
const options=[...e.options].filter(o=>!o.disabled && !o.closest('optgroup[disabled]'));
|
|
273
|
+
item.kind='select';
|
|
274
|
+
item.value=[...e.selectedOptions].map(o=>o.label).join(', ');
|
|
275
|
+
item.options=options.slice(0,${PAGE_OPTIONS}).map(o=>o.label);
|
|
276
|
+
if (options.length>${PAGE_OPTIONS}) item.more_options=options.length-${PAGE_OPTIONS};
|
|
277
|
+
} else {
|
|
278
|
+
const editable=!e.readOnly && e.getAttribute('aria-readonly')!=='true' &&
|
|
279
|
+
(['textbox','searchbox','spinbutton'].includes(rname) ||
|
|
280
|
+
(rname==='combobox' && ['INPUT','TEXTAREA'].includes(e.tagName)));
|
|
281
|
+
item.kind=editable ? 'fill' : 'click';
|
|
282
|
+
if (editable) {
|
|
283
|
+
const value=window.__wzPersonal?.has(e) ? ${JSON.stringify(PERSONAL)} :
|
|
284
|
+
'value' in e ? String(e.value) : e.innerText.trim();
|
|
285
|
+
if (value) item.value=value.slice(0,200);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (e.closest(${JSON.stringify(OVERLAY)})) { item.dialog=true; front.push(item); }
|
|
289
|
+
else rest.push(item);
|
|
290
|
+
}
|
|
291
|
+
const items=[...front,...rest];
|
|
292
|
+
const words=[], walker=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT);
|
|
293
|
+
let node,length=0;
|
|
294
|
+
while ((node=walker.nextNode()) && length<6000) {
|
|
295
|
+
const value=node.textContent.trim(), parent=node.parentElement;
|
|
296
|
+
if (!value || !parent || parent.closest('script,style,noscript,template') || !visible(parent)) continue;
|
|
297
|
+
words.push(value); length+=value.length;
|
|
298
|
+
}
|
|
299
|
+
return {url:location.href,title:document.title,text:words.join('\n').slice(0,6000),
|
|
300
|
+
items:items.slice(0,${PAGE_ITEMS}),omitted:Math.max(0,items.length-${PAGE_ITEMS}),
|
|
301
|
+
scroll:{y:Math.round(scrollY),height:document.documentElement.scrollHeight,viewport:innerHeight}};
|
|
302
|
+
})()`;
|
|
303
|
+
/**
|
|
304
|
+
* Where to put the pointer for an element an agent step names: still there, enabled and
|
|
305
|
+
* visible, scrolled into view when it is off-screen, and the top-most element at its centre.
|
|
306
|
+
* What covers it is named, so the step can deal with that first (a cookie banner).
|
|
307
|
+
*/
|
|
308
|
+
export function targetScript(ref) {
|
|
309
|
+
return `(ref => {
|
|
310
|
+
const e=window.__jevFast?.nodes.get(ref);
|
|
311
|
+
if (!e?.isConnected) return {error:'gone'};
|
|
312
|
+
if (e.matches(':disabled') || e.closest('[aria-disabled="true"],[inert]')) return {error:'disabled'};
|
|
313
|
+
if (!e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true})) return {error:'hidden'};
|
|
314
|
+
let r=e.getBoundingClientRect();
|
|
315
|
+
if (r.top<0 || r.left<0 || r.bottom>innerHeight || r.right>innerWidth) {
|
|
316
|
+
e.scrollIntoView({block:'center',inline:'center',behavior:'instant'});
|
|
317
|
+
r=e.getBoundingClientRect();
|
|
318
|
+
}
|
|
319
|
+
const x=r.x+r.width/2, y=r.y+r.height/2;
|
|
320
|
+
if (!r.width || !r.height || x<0 || y<0 || x>=innerWidth || y>=innerHeight) return {error:'outside'};
|
|
321
|
+
const top=document.elementFromPoint(x,y);
|
|
322
|
+
if (top && !e.contains(top)) {
|
|
323
|
+
const layer=top.closest(${JSON.stringify(OVERLAY)}) || top;
|
|
324
|
+
const said=(layer.getAttribute('aria-label') || layer.innerText || layer.tagName).replace(/\\s+/g,' ').trim();
|
|
325
|
+
return {error:'covered', by:said.slice(0,80)};
|
|
326
|
+
}
|
|
327
|
+
return {x,y};
|
|
328
|
+
})(${ref})`;
|
|
329
|
+
}
|
|
330
|
+
/** Marks the field with focus as holding what the person typed. */
|
|
331
|
+
export const MARK_FOCUSED_PERSONAL = `(() => { const e=document.activeElement; if (e && e!==document.body) (window.__wzPersonal ||= new WeakSet()).add(e); })()`;
|
|
332
|
+
/** The element a ref names, as a handle, for what only Playwright does well (fill, select). */
|
|
333
|
+
export function nodeScript(ref) {
|
|
334
|
+
return `window.__jevFast?.nodes.get(${ref}) ?? null`;
|
|
335
|
+
}
|