@nuanu-ai/agentbrowse 0.2.41 → 0.2.42
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.
|
@@ -4,6 +4,7 @@ export declare function isPrimaryFormControlTarget(target: DomObservedTarget): b
|
|
|
4
4
|
export declare function formGroupingKeyOf(target: DomObservedTarget): string | undefined;
|
|
5
5
|
export declare function observedTargetKey(target: DomObservedTarget): string;
|
|
6
6
|
export declare function expandRerankedFormTargets(targets: ReadonlyArray<DomObservedTarget>, selectedTargets: ReadonlyArray<DomObservedTarget>): DomObservedTarget[];
|
|
7
|
+
export declare function expandCompanionSubmitTargets(targets: ReadonlyArray<DomObservedTarget>, selectedTargets: ReadonlyArray<DomObservedTarget>): DomObservedTarget[];
|
|
7
8
|
export declare function prioritizeGoalActionTargets(instruction: string, selectedTargets: ReadonlyArray<DomObservedTarget>): DomObservedTarget[];
|
|
8
9
|
export declare function compressSemanticallyDuplicateTargets(targets: ReadonlyArray<DomObservedTarget>): DomObservedTarget[];
|
|
9
10
|
export declare function annotateDomTargets(targets: ReadonlyArray<DomObservedTarget>): DomObservedTarget[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-semantics.d.ts","sourceRoot":"","sources":["../../src/commands/observe-semantics.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAYjF;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CA6B7E;AAgBD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAQ/E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAMnE;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,aAAa,CAAC,iBAAiB,C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2B,CACzC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,GAChD,iBAAiB,EAAE,CA+BrB;AAqBD,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GACxC,iBAAiB,EAAE,CAuBrB;AAkGD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,CAoFjG;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GACxC,iBAAiB,EAAE,CAsFrB"}
|
|
@@ -94,6 +94,116 @@ export function expandRerankedFormTargets(targets, selectedTargets) {
|
|
|
94
94
|
return (left.label ?? '').localeCompare(right.label ?? '');
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
function isSubmitLikeTarget(target) {
|
|
98
|
+
const acceptancePolicy = (target.acceptancePolicy ?? '').trim().toLowerCase();
|
|
99
|
+
const inputType = (target.inputType ?? '').trim().toLowerCase();
|
|
100
|
+
return acceptancePolicy === 'submit' || inputType === 'submit';
|
|
101
|
+
}
|
|
102
|
+
function selectedFormClusterKeyOf(target) {
|
|
103
|
+
const formKey = formGroupingKeyOf(target);
|
|
104
|
+
if (formKey) {
|
|
105
|
+
return `form:${formKey}`;
|
|
106
|
+
}
|
|
107
|
+
const surfaceRef = target.surfaceRef?.trim();
|
|
108
|
+
return surfaceRef ? `surface:${surfaceRef}` : undefined;
|
|
109
|
+
}
|
|
110
|
+
function matchesSelectedFormCluster(target, clusterKey) {
|
|
111
|
+
if (!clusterKey) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (clusterKey.startsWith('form:')) {
|
|
115
|
+
return `form:${formGroupingKeyOf(target)}` === clusterKey;
|
|
116
|
+
}
|
|
117
|
+
if (!clusterKey.startsWith('surface:')) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return `surface:${target.surfaceRef?.trim() ?? ''}` === clusterKey;
|
|
121
|
+
}
|
|
122
|
+
function isStandaloneBottomSubmitInputTarget(target) {
|
|
123
|
+
const inputType = (target.inputType ?? '').trim().toLowerCase();
|
|
124
|
+
if (inputType !== 'submit') {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (target.framePath?.length) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (target.surfaceRef?.trim() || formGroupingKeyOf(target)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return target.context?.layout?.band === 'bottom';
|
|
134
|
+
}
|
|
135
|
+
export function expandCompanionSubmitTargets(targets, selectedTargets) {
|
|
136
|
+
if (selectedTargets.some(isSubmitLikeTarget)) {
|
|
137
|
+
return [...selectedTargets];
|
|
138
|
+
}
|
|
139
|
+
const primarySelectedTargets = selectedTargets.filter(isPrimaryFormControlTarget);
|
|
140
|
+
if (primarySelectedTargets.length < 2) {
|
|
141
|
+
return [...selectedTargets];
|
|
142
|
+
}
|
|
143
|
+
const clusterEntries = new Map();
|
|
144
|
+
for (const target of primarySelectedTargets) {
|
|
145
|
+
const clusterKey = selectedFormClusterKeyOf(target);
|
|
146
|
+
if (!clusterKey) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const existing = clusterEntries.get(clusterKey) ?? {
|
|
150
|
+
count: 0,
|
|
151
|
+
priority: clusterKey.startsWith('form:') ? 2 : 1,
|
|
152
|
+
inFrame: false,
|
|
153
|
+
};
|
|
154
|
+
existing.count += 1;
|
|
155
|
+
existing.inFrame ||= Boolean(target.framePath?.length);
|
|
156
|
+
clusterEntries.set(clusterKey, existing);
|
|
157
|
+
}
|
|
158
|
+
const dominantCluster = [...clusterEntries.entries()]
|
|
159
|
+
.filter(([, entry]) => entry.count >= 2)
|
|
160
|
+
.sort((left, right) => {
|
|
161
|
+
const [, leftEntry] = left;
|
|
162
|
+
const [, rightEntry] = right;
|
|
163
|
+
if (leftEntry.count !== rightEntry.count) {
|
|
164
|
+
return rightEntry.count - leftEntry.count;
|
|
165
|
+
}
|
|
166
|
+
if (leftEntry.priority !== rightEntry.priority) {
|
|
167
|
+
return rightEntry.priority - leftEntry.priority;
|
|
168
|
+
}
|
|
169
|
+
return left[0].localeCompare(right[0]);
|
|
170
|
+
})[0];
|
|
171
|
+
if (!dominantCluster) {
|
|
172
|
+
return [...selectedTargets];
|
|
173
|
+
}
|
|
174
|
+
const [dominantClusterKey, dominantClusterMeta] = dominantCluster;
|
|
175
|
+
const expanded = new Map();
|
|
176
|
+
for (const target of selectedTargets) {
|
|
177
|
+
expanded.set(observedTargetKey(target), target);
|
|
178
|
+
}
|
|
179
|
+
const explicitCompanions = targets.filter((target) => {
|
|
180
|
+
const key = observedTargetKey(target);
|
|
181
|
+
if (expanded.has(key) || !isSubmitLikeTarget(target)) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return matchesSelectedFormCluster(target, dominantClusterKey);
|
|
185
|
+
});
|
|
186
|
+
for (const target of explicitCompanions) {
|
|
187
|
+
expanded.set(observedTargetKey(target), target);
|
|
188
|
+
}
|
|
189
|
+
if (explicitCompanions.length === 0 && dominantClusterMeta.inFrame) {
|
|
190
|
+
const fallbackCandidates = targets.filter((target) => {
|
|
191
|
+
const key = observedTargetKey(target);
|
|
192
|
+
return !expanded.has(key) && isStandaloneBottomSubmitInputTarget(target);
|
|
193
|
+
});
|
|
194
|
+
if (fallbackCandidates.length === 1) {
|
|
195
|
+
expanded.set(observedTargetKey(fallbackCandidates[0]), fallbackCandidates[0]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return [...expanded.values()].sort((left, right) => {
|
|
199
|
+
const leftOrdinal = left.ordinal ?? Number.MAX_SAFE_INTEGER;
|
|
200
|
+
const rightOrdinal = right.ordinal ?? Number.MAX_SAFE_INTEGER;
|
|
201
|
+
if (leftOrdinal !== rightOrdinal) {
|
|
202
|
+
return leftOrdinal - rightOrdinal;
|
|
203
|
+
}
|
|
204
|
+
return (left.label ?? '').localeCompare(right.label ?? '');
|
|
205
|
+
});
|
|
206
|
+
}
|
|
97
207
|
function parseNumericAmount(value) {
|
|
98
208
|
const normalized = value.replace(/,/g, '.').trim();
|
|
99
209
|
if (!/^\d+(?:\.\d+)?$/.test(normalized)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/commands/observe.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/commands/observe.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA4DnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAU/D,eAAO,MAAM,yBAAyB;;;;iBA4Uk6G,CAAC;gBAAwB,CAAC;;;;;CA5U75G,CAAC;AACtE,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGrC,CAAC;AAEF,wBAAsB,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqUzF"}
|
package/dist/commands/observe.js
CHANGED
|
@@ -14,7 +14,7 @@ import { collectPageSignals } from './observe-signals.js';
|
|
|
14
14
|
import { attachObservedTargetOwners, linkObservedSurfaceGraph, reconcileObservedTargetsForPage, persistObservedSurfacesForPage, toDomDescriptor, } from './observe-persistence.js';
|
|
15
15
|
import { clearProtectedFillableFormsForPage, persistProtectedFillableFormsForPage, } from './observe-protected.js';
|
|
16
16
|
import { classifyObservePageState, shouldSuppressFillableFormsForObserve, } from './observe-page-state.js';
|
|
17
|
-
import { annotateDomTargets, compressSemanticallyDuplicateTargets, expandRerankedFormTargets, orderBySurfaceCompetition, prioritizeGoalActionTargets, } from './observe-semantics.js';
|
|
17
|
+
import { annotateDomTargets, compressSemanticallyDuplicateTargets, expandCompanionSubmitTargets, expandRerankedFormTargets, orderBySurfaceCompetition, prioritizeGoalActionTargets, } from './observe-semantics.js';
|
|
18
18
|
import { buildGroupedObserveScopes, buildExplicitScopeRefs, buildGoalObserveInventoryCandidates, compactFillableForms, compactSignals, projectPersistedTargetsForGoal, selectTargetsForGoalMatches, } from './observe-projection.js';
|
|
19
19
|
import { collectSurfaceDescriptors, selectScopesForOutput } from './observe-surfaces.js';
|
|
20
20
|
import { toStagehandDescriptor } from './observe-stagehand.js';
|
|
@@ -126,7 +126,7 @@ export async function observe(session, instruction) {
|
|
|
126
126
|
if (domTargets.length > 0) {
|
|
127
127
|
const rerankedCandidates = await rerankDomTargetsForGoal(instruction, buildGoalObserveInventoryCandidates(domTargets, surfaceInputs), { session });
|
|
128
128
|
const { targets: goalMatchedTargets, selectedSurfaceIds } = selectTargetsForGoalMatches(domTargets, rerankedCandidates);
|
|
129
|
-
const selectedTargets = prioritizeGoalActionTargets(instruction, expandRerankedFormTargets(domTargets, goalMatchedTargets));
|
|
129
|
+
const selectedTargets = prioritizeGoalActionTargets(instruction, expandCompanionSubmitTargets(domTargets, expandRerankedFormTargets(domTargets, goalMatchedTargets)));
|
|
130
130
|
const persisted = persistObservedSurfacesForPage(session, pageRef, domTargets, {
|
|
131
131
|
allSurfaceInputs: surfaceInputs,
|
|
132
132
|
explicitSurfaceIds: selectedSurfaceIds,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuanu-ai/agentbrowse",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Browser automation CLI for AI agents: control a CDP browser, observe UI surfaces, act on refs, extract data, capture screenshots, complete protected fills, and solve captchas",
|
|
6
6
|
"keywords": [
|