@nuanu-ai/agentbrowse 0.2.18 → 0.2.20
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/dist/commands/act.d.ts.map +1 -1
- package/dist/commands/act.js +48 -21
- package/dist/commands/action-executor-helpers.d.ts.map +1 -1
- package/dist/commands/action-executor-helpers.js +8 -3
- package/dist/commands/extract-scoped-dialog-text.d.ts +3 -0
- package/dist/commands/extract-scoped-dialog-text.d.ts.map +1 -0
- package/dist/commands/extract-scoped-dialog-text.js +213 -0
- package/dist/commands/extract.d.ts.map +1 -1
- package/dist/commands/extract.js +20 -0
- package/dist/commands/observe-inventory.d.ts +12 -0
- package/dist/commands/observe-inventory.d.ts.map +1 -1
- package/dist/commands/observe-inventory.js +299 -57
- package/dist/commands/observe-page-state.d.ts +11 -0
- package/dist/commands/observe-page-state.d.ts.map +1 -0
- package/dist/commands/observe-page-state.js +89 -0
- package/dist/commands/observe.d.ts +1 -0
- package/dist/commands/observe.d.ts.map +1 -1
- package/dist/commands/observe.js +9 -2
- package/dist/commands/observe.test-harness.d.ts +1 -0
- package/dist/commands/observe.test-harness.d.ts.map +1 -1
- package/dist/control-semantics.d.ts.map +1 -1
- package/dist/control-semantics.js +10 -0
- package/dist/runtime-state.d.ts.map +1 -1
- package/dist/runtime-state.js +11 -4
- package/dist/secrets/form-matcher.d.ts.map +1 -1
- package/dist/secrets/form-matcher.js +133 -11
- package/dist/secrets/protected-bindings.d.ts +4 -0
- package/dist/secrets/protected-bindings.d.ts.map +1 -1
- package/dist/secrets/protected-bindings.js +7 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/commands/act.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAoCnD,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqHxF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,CAAC;AAoV7B,wBAAsB,GAAG,CACvB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/commands/act.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAoCnD,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqHxF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,CAAC;AAoV7B,wBAAsB,GAAG,CACvB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAmqBf"}
|
package/dist/commands/act.js
CHANGED
|
@@ -531,6 +531,38 @@ export async function act(session, targetRef, action, value) {
|
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
let acceptanceProbe = null;
|
|
534
|
+
const tryRecoverActionErrorAcceptance = async () => {
|
|
535
|
+
if (!acceptanceProbe) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
const acceptance = await waitForAcceptanceProbe(acceptanceProbe).catch(() => null);
|
|
539
|
+
if (acceptance?.polls && acceptance.polls > 1) {
|
|
540
|
+
attempts.push(`acceptance.polled:${acceptance.polls}`);
|
|
541
|
+
}
|
|
542
|
+
if (!acceptance?.accepted) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
if (acceptanceProbe.policy === 'submit') {
|
|
546
|
+
const submitResolution = await resolveSubmitResult(acceptanceProbe, acceptance.afterPageObservation);
|
|
547
|
+
if (!submitResolution.acceptAsProgress) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
attempts.push(`submit-resolution:${submitResolution.finalVerdict}`);
|
|
551
|
+
if (submitResolution.claims.some((claim) => claim.kind === 'soft_result_candidate')) {
|
|
552
|
+
attempts.push('submit-resolution:soft-result-candidate');
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
attempts.push(`acceptance.recovered:${acceptanceProbe.policy}`);
|
|
556
|
+
incrementMetric(session, 'fallbackActions');
|
|
557
|
+
resolvedBy = 'playwright-locator';
|
|
558
|
+
locatorStrategy = strategy;
|
|
559
|
+
progressProbe = null;
|
|
560
|
+
lastError = null;
|
|
561
|
+
recoveredAfterError = true;
|
|
562
|
+
recoveredAcceptancePolicy = acceptanceProbe.policy;
|
|
563
|
+
setTargetAvailability(session, targetRef, 'available');
|
|
564
|
+
return true;
|
|
565
|
+
};
|
|
534
566
|
try {
|
|
535
567
|
const valueProjection = await projectActionValue({
|
|
536
568
|
target,
|
|
@@ -573,31 +605,26 @@ export async function act(session, targetRef, action, value) {
|
|
|
573
605
|
(acceptanceProbe.policy === 'value-change' ||
|
|
574
606
|
acceptanceProbe.policy === 'selection' ||
|
|
575
607
|
acceptanceProbe.policy === 'date-selection' ||
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const acceptance = await waitForAcceptanceProbe(acceptanceProbe).catch(() => null);
|
|
581
|
-
if (acceptance?.polls && acceptance.polls > 1) {
|
|
582
|
-
attempts.push(`acceptance.polled:${acceptance.polls}`);
|
|
583
|
-
}
|
|
584
|
-
if (acceptance?.accepted) {
|
|
585
|
-
attempts.push(`acceptance.recovered:${acceptanceProbe.policy}`);
|
|
586
|
-
incrementMetric(session, 'fallbackActions');
|
|
587
|
-
resolvedBy = 'playwright-locator';
|
|
588
|
-
locatorStrategy = strategy;
|
|
589
|
-
progressProbe = null;
|
|
590
|
-
lastError = null;
|
|
591
|
-
recoveredAfterError = true;
|
|
592
|
-
recoveredAcceptancePolicy = acceptanceProbe.policy;
|
|
593
|
-
setTargetAvailability(session, targetRef, 'available');
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
608
|
+
acceptanceProbe.policy === 'navigation' ||
|
|
609
|
+
acceptanceProbe.policy === 'submit');
|
|
610
|
+
if (shouldAttemptAcceptanceRecovery && (await tryRecoverActionErrorAcceptance())) {
|
|
611
|
+
return true;
|
|
596
612
|
}
|
|
597
613
|
if (staleReason) {
|
|
598
614
|
throw lastError;
|
|
599
615
|
}
|
|
600
|
-
|
|
616
|
+
try {
|
|
617
|
+
await assertResolvedTargetStillValid(resolvedLocator, `after-error:${strategy}`);
|
|
618
|
+
}
|
|
619
|
+
catch (validationError) {
|
|
620
|
+
if ((acceptanceProbe?.policy === 'navigation' || acceptanceProbe?.policy === 'submit') &&
|
|
621
|
+
validationError instanceof Error &&
|
|
622
|
+
validationError.message === 'stale_target_page_signature_changed' &&
|
|
623
|
+
(await tryRecoverActionErrorAcceptance())) {
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
throw validationError;
|
|
627
|
+
}
|
|
601
628
|
return false;
|
|
602
629
|
}
|
|
603
630
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-executor-helpers.d.ts","sourceRoot":"","sources":["../../src/commands/action-executor-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAerD,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAC9C,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAkB7C,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWpE;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC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AC,CAgBD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,EACjC,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,CAkBR;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAarF"}
|
|
@@ -33,9 +33,14 @@ export async function dismissBlockingOverlay(page, attempts) {
|
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
35
|
attempts.push(`overlay.dismiss:${selector}`);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
try {
|
|
37
|
+
await candidate.click({ timeout: LOCATOR_CLICK_TIMEOUT_MS });
|
|
38
|
+
attempts.push('overlay.dismissed');
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
return false;
|
|
41
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-scoped-dialog-text.d.ts","sourceRoot":"","sources":["../../src/commands/extract-scoped-dialog-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAuM5C,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyB/F"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
const BLOCK_MARKER = '[block]';
|
|
2
|
+
const ANCHOR_SELECTOR = [
|
|
3
|
+
'button',
|
|
4
|
+
'a[href]',
|
|
5
|
+
'[role="button"]',
|
|
6
|
+
'[role="link"]',
|
|
7
|
+
'input[type="button"]',
|
|
8
|
+
'input[type="submit"]',
|
|
9
|
+
'input[type="reset"]',
|
|
10
|
+
].join(', ');
|
|
11
|
+
// Build the browser callback from plain JS source so Playwright serializes
|
|
12
|
+
// stable code instead of tsx-transformed output.
|
|
13
|
+
const readScopedDialogTextInBrowser = Function(`return (${String.raw `(root, payload) => {
|
|
14
|
+
const marker = payload.marker;
|
|
15
|
+
const anchorSelector = payload.anchorSelector;
|
|
16
|
+
const minBlockTextLength = payload.minBlockTextLength;
|
|
17
|
+
const maxAnchorCountPerBlock = payload.maxAnchorCountPerBlock;
|
|
18
|
+
|
|
19
|
+
function normalizeOutputText(text) {
|
|
20
|
+
return text
|
|
21
|
+
.replace(/\r/g, '')
|
|
22
|
+
.split('\n')
|
|
23
|
+
.map((line) => line.trim())
|
|
24
|
+
.join('\n')
|
|
25
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
26
|
+
.trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeBlockText(text) {
|
|
30
|
+
return normalizeOutputText(text).replace(/\n{2,}/g, '\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isVisibleElement(element) {
|
|
34
|
+
if (!(element instanceof HTMLElement)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (element.hidden || element.getAttribute('aria-hidden') === 'true') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const style = window.getComputedStyle(element);
|
|
43
|
+
return style.display !== 'none' && style.visibility !== 'hidden';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function visibleChildren(element) {
|
|
47
|
+
return Array.from(element.children).filter((child) => isVisibleElement(child));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function collectVisibleAnchors(rootElement) {
|
|
51
|
+
return Array.from(rootElement.querySelectorAll(anchorSelector)).filter((anchor) =>
|
|
52
|
+
isVisibleElement(anchor)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function countAnchorsWithin(element, anchors) {
|
|
57
|
+
let count = 0;
|
|
58
|
+
for (const anchor of anchors) {
|
|
59
|
+
if (element.contains(anchor)) {
|
|
60
|
+
count += 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return count;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function pathFromRoot(rootElement, node) {
|
|
67
|
+
const path = [];
|
|
68
|
+
let current = node;
|
|
69
|
+
|
|
70
|
+
while (current && current !== rootElement) {
|
|
71
|
+
const parent = current.parentElement;
|
|
72
|
+
if (!(parent instanceof HTMLElement)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const index = Array.from(parent.children).indexOf(current);
|
|
77
|
+
if (index < 0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
path.unshift(index);
|
|
82
|
+
current = parent;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return current === rootElement ? path : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function max(values) {
|
|
89
|
+
return values.reduce((current, value) => Math.max(current, value), 0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sum(values) {
|
|
93
|
+
return values.reduce((current, value) => current + value, 0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!(root instanceof HTMLElement)) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const rawText = normalizeOutputText(root.innerText);
|
|
101
|
+
if (!rawText) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const anchors = collectVisibleAnchors(root);
|
|
106
|
+
if (anchors.length < 2) {
|
|
107
|
+
return rawText;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const candidates = [root, ...Array.from(root.querySelectorAll('*')).filter((element) => isVisibleElement(element))]
|
|
111
|
+
.map((element) => {
|
|
112
|
+
const children = visibleChildren(element);
|
|
113
|
+
if (children.length < 2) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const tagName = children[0] && children[0].tagName;
|
|
118
|
+
if (!tagName || children.some((child) => child.tagName !== tagName)) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const childSummaries = children.map((child) => {
|
|
123
|
+
const text = normalizeBlockText(child.innerText);
|
|
124
|
+
const anchorCount = countAnchorsWithin(child, anchors);
|
|
125
|
+
return {
|
|
126
|
+
text,
|
|
127
|
+
textLength: text.length,
|
|
128
|
+
anchorCount,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
childSummaries.some(
|
|
134
|
+
(summary) => summary.anchorCount < 1 || summary.anchorCount > maxAnchorCountPerBlock
|
|
135
|
+
)
|
|
136
|
+
) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const anchorCounts = childSummaries.map((summary) => summary.anchorCount);
|
|
141
|
+
if (max(anchorCounts) - Math.min(...anchorCounts) > 1) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const textLengths = childSummaries.map((summary) => summary.textLength);
|
|
146
|
+
if (textLengths.some((length) => length < minBlockTextLength)) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const parentPath = pathFromRoot(root, element);
|
|
151
|
+
if (!parentPath) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
parentPath,
|
|
157
|
+
blockTexts: childSummaries.map((summary) => summary.text).filter(Boolean),
|
|
158
|
+
childCount: childSummaries.length,
|
|
159
|
+
totalTextLength: sum(textLengths),
|
|
160
|
+
depth: parentPath.length,
|
|
161
|
+
maxAnchorCount: max(anchorCounts),
|
|
162
|
+
};
|
|
163
|
+
})
|
|
164
|
+
.filter(Boolean);
|
|
165
|
+
|
|
166
|
+
const bestCandidate = candidates.sort((left, right) => {
|
|
167
|
+
if (right.childCount !== left.childCount) {
|
|
168
|
+
return right.childCount - left.childCount;
|
|
169
|
+
}
|
|
170
|
+
if (right.totalTextLength !== left.totalTextLength) {
|
|
171
|
+
return right.totalTextLength - left.totalTextLength;
|
|
172
|
+
}
|
|
173
|
+
if (right.maxAnchorCount !== left.maxAnchorCount) {
|
|
174
|
+
return right.maxAnchorCount - left.maxAnchorCount;
|
|
175
|
+
}
|
|
176
|
+
return right.depth - left.depth;
|
|
177
|
+
})[0];
|
|
178
|
+
|
|
179
|
+
if (!bestCandidate || bestCandidate.blockTexts.length < 2) {
|
|
180
|
+
return rawText;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return normalizeOutputText(
|
|
184
|
+
bestCandidate.blockTexts.map((text) => marker + '\n' + text).join('\n\n')
|
|
185
|
+
);
|
|
186
|
+
}`});`)();
|
|
187
|
+
export async function readScopedDialogText(page, selector) {
|
|
188
|
+
let rawText = null;
|
|
189
|
+
try {
|
|
190
|
+
rawText = (await page.locator(selector).first().innerText()).replace(/\r/g, '');
|
|
191
|
+
if (!rawText.trim()) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const result = await page
|
|
200
|
+
.locator(selector)
|
|
201
|
+
.first()
|
|
202
|
+
.evaluate(readScopedDialogTextInBrowser, {
|
|
203
|
+
marker: BLOCK_MARKER,
|
|
204
|
+
anchorSelector: ANCHOR_SELECTOR,
|
|
205
|
+
minBlockTextLength: 20,
|
|
206
|
+
maxAnchorCountPerBlock: 4,
|
|
207
|
+
});
|
|
208
|
+
return typeof result === 'string' && result.trim().length > 0 ? result : rawText;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return rawText;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA8KnD,wBAAsB,OAAO,CAC3B,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAkMf"}
|
package/dist/commands/extract.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getSurface, getTarget, markSurfaceLifecycle, markTargetLifecycle, setCu
|
|
|
8
8
|
import { outputContractFailure, outputJSON } from '../output.js';
|
|
9
9
|
import { connectPlaywright, disconnectPlaywright, resolvePageByRef as resolvePlaywrightPageByRef, syncSessionPage, } from '../playwright-runtime.js';
|
|
10
10
|
import { normalizePageSignature } from './descriptor-validation.js';
|
|
11
|
+
import { readScopedDialogText } from './extract-scoped-dialog-text.js';
|
|
11
12
|
import { resolveScopedExtractContext } from './extract-scope-resolution.js';
|
|
12
13
|
import { executeStagehandExtract } from './extract-stagehand-executor.js';
|
|
13
14
|
function buildSchemaValue(descriptor) {
|
|
@@ -133,6 +134,9 @@ function buildTruncationReason(error) {
|
|
|
133
134
|
? `Structured output was truncated by the LLM provider (${details.join(', ')}).`
|
|
134
135
|
: 'Structured output was truncated by the LLM provider.';
|
|
135
136
|
}
|
|
137
|
+
function schemaRequestsScopedDialogText(schemaDescriptor) {
|
|
138
|
+
return schemaDescriptor.dialog_text === 'string';
|
|
139
|
+
}
|
|
136
140
|
export async function extract(session, schemaJson, scopeRef) {
|
|
137
141
|
let schemaDescriptor;
|
|
138
142
|
try {
|
|
@@ -239,10 +243,26 @@ export async function extract(session, schemaJson, scopeRef) {
|
|
|
239
243
|
? scopedResolution.degradationReason
|
|
240
244
|
: undefined,
|
|
241
245
|
});
|
|
246
|
+
let data = execution.data;
|
|
247
|
+
if (scopeTarget &&
|
|
248
|
+
effectiveSelector &&
|
|
249
|
+
schemaRequestsScopedDialogText(schemaDescriptor) &&
|
|
250
|
+
data &&
|
|
251
|
+
typeof data === 'object' &&
|
|
252
|
+
!Array.isArray(data)) {
|
|
253
|
+
const dialogText = await readScopedDialogText(page, effectiveSelector);
|
|
254
|
+
if (typeof dialogText === 'string' && dialogText.trim().length > 0) {
|
|
255
|
+
data = {
|
|
256
|
+
...data,
|
|
257
|
+
dialog_text: dialogText,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
242
261
|
saveSession(session);
|
|
243
262
|
outputJSON({
|
|
244
263
|
success: true,
|
|
245
264
|
...execution,
|
|
265
|
+
data,
|
|
246
266
|
pageRef,
|
|
247
267
|
scopeRef,
|
|
248
268
|
metrics: session.runtime?.metrics,
|
|
@@ -70,6 +70,17 @@ export type DomTargetCollectionOptions = {
|
|
|
70
70
|
type DomTargetCollectionContext = {
|
|
71
71
|
evaluate<T>(pageFunction: string): Promise<T>;
|
|
72
72
|
};
|
|
73
|
+
type StructuredCellVariantEvidence = {
|
|
74
|
+
role?: string;
|
|
75
|
+
surfaceKind?: string;
|
|
76
|
+
normalizedLabel?: string;
|
|
77
|
+
className?: string;
|
|
78
|
+
hasSeatAttribute?: boolean;
|
|
79
|
+
hasSeatRowAttribute?: boolean;
|
|
80
|
+
hasSeatColumnAttribute?: boolean;
|
|
81
|
+
hasDateMetadata?: boolean;
|
|
82
|
+
};
|
|
83
|
+
export declare function inferStructuredCellVariantFromEvidence(evidence: StructuredCellVariantEvidence): 'date-cell' | 'seat-cell' | 'grid-cell' | undefined;
|
|
73
84
|
export declare function readStagehandLocatorSnapshot(locator: Locator): Promise<StagehandLocatorSnapshot>;
|
|
74
85
|
declare function readStagehandDomFactsInBrowser(element: Element): StagehandDomFacts | null;
|
|
75
86
|
declare function readStagehandDomFacts(locator: Locator): Promise<StagehandDomFacts | null>;
|
|
@@ -97,6 +108,7 @@ export declare function collectPageSignals(page: {
|
|
|
97
108
|
export declare const __testDomTargetCollection: {
|
|
98
109
|
collectDomTargetsFromDocument: typeof collectDomTargetsFromDocument;
|
|
99
110
|
collectPageSignalsFromDocument: typeof collectPageSignalsFromDocument;
|
|
111
|
+
inferStructuredCellVariantFromEvidence: typeof inferStructuredCellVariantFromEvidence;
|
|
100
112
|
locatorDomSignatureScript: string;
|
|
101
113
|
};
|
|
102
114
|
export declare const __testStagehandDescriptor: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-inventory.d.ts","sourceRoot":"","sources":["../../src/commands/observe-inventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAc7B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;I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