@browserbasehq/stagehand 3.0.7-alpha-6a5496f17dbb716be1ee1aaa4e5ba9d8c723b30b → 3.0.7-alpha-e822f5a8898df9eb48ca32c321025f0c74b638f0

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/index.d.ts CHANGED
@@ -1533,63 +1533,32 @@ declare class Page {
1533
1533
  * on the top-level page target's session. Coordinates are relative to the
1534
1534
  * viewport origin (top-left). Does not scroll.
1535
1535
  */
1536
- click(x: number, y: number, options: {
1537
- button?: "left" | "right" | "middle";
1538
- clickCount?: number;
1539
- returnXpath: true;
1540
- }): Promise<string>;
1541
1536
  click(x: number, y: number, options?: {
1542
1537
  button?: "left" | "right" | "middle";
1543
1538
  clickCount?: number;
1544
- returnXpath?: false;
1545
- }): Promise<void>;
1546
- click(x: number, y: number, options: {
1547
- button?: "left" | "right" | "middle";
1548
- clickCount?: number;
1549
- returnXpath: boolean;
1550
- }): Promise<void | string>;
1539
+ returnXpath?: boolean;
1540
+ }): Promise<string>;
1551
1541
  /**
1552
1542
  * Hover at absolute page coordinates (CSS pixels).
1553
1543
  * Dispatches mouseMoved via CDP Input domain on the top-level page target's
1554
1544
  * session.
1555
1545
  */
1556
- hover(x: number, y: number, options: {
1557
- returnXpath: true;
1558
- }): Promise<string>;
1559
1546
  hover(x: number, y: number, options?: {
1560
- returnXpath?: false;
1561
- }): Promise<void>;
1562
- scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
1563
- returnXpath: true;
1547
+ returnXpath?: boolean;
1564
1548
  }): Promise<string>;
1565
1549
  scroll(x: number, y: number, deltaX: number, deltaY: number, options?: {
1566
- returnXpath?: false;
1567
- }): Promise<void>;
1568
- scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
1569
- returnXpath: boolean;
1570
- }): Promise<void | string>;
1550
+ returnXpath?: boolean;
1551
+ }): Promise<string>;
1571
1552
  /**
1572
1553
  * Drag from (fromX, fromY) to (toX, toY) using mouse events.
1573
1554
  * Sends mouseMoved → mousePressed → mouseMoved (steps) → mouseReleased.
1574
1555
  */
1575
- dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
1576
- button?: "left" | "right" | "middle";
1577
- steps?: number;
1578
- delay?: number;
1579
- returnXpath: true;
1580
- }): Promise<[string, string]>;
1581
1556
  dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options?: {
1582
1557
  button?: "left" | "right" | "middle";
1583
1558
  steps?: number;
1584
1559
  delay?: number;
1585
- returnXpath?: false;
1586
- }): Promise<void>;
1587
- dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
1588
- button?: "left" | "right" | "middle";
1589
- steps?: number;
1590
- delay?: number;
1591
- returnXpath: boolean;
1592
- }): Promise<void | [string, string]>;
1560
+ returnXpath?: boolean;
1561
+ }): Promise<[string, string]>;
1593
1562
  /**
1594
1563
  * Type a string by dispatching keyDown/keyUp events per character.
1595
1564
  * Focus must already be on the desired element. Uses CDP Input.dispatchKeyEvent
package/dist/index.js CHANGED
@@ -179,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
179
179
  var STAGEHAND_VERSION;
180
180
  var init_version = __esm({
181
181
  "lib/version.ts"() {
182
- STAGEHAND_VERSION = "3.0.7-alpha-6a5496f17dbb716be1ee1aaa4e5ba9d8c723b30b";
182
+ STAGEHAND_VERSION = "3.0.7-alpha-e822f5a8898df9eb48ca32c321025f0c74b638f0";
183
183
  }
184
184
  });
185
185
 
@@ -26247,7 +26247,7 @@ var init_page = __esm({
26247
26247
  clickCount: i2
26248
26248
  });
26249
26249
  }
26250
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26250
+ return xpathResult != null ? xpathResult : "";
26251
26251
  });
26252
26252
  }
26253
26253
  hover(x2, y, options) {
@@ -26292,7 +26292,7 @@ var init_page = __esm({
26292
26292
  y,
26293
26293
  button: "none"
26294
26294
  });
26295
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26295
+ return xpathResult != null ? xpathResult : "";
26296
26296
  });
26297
26297
  }
26298
26298
  scroll(x2, y, deltaX, deltaY, options) {
@@ -26320,7 +26320,7 @@ var init_page = __esm({
26320
26320
  deltaX,
26321
26321
  deltaY
26322
26322
  });
26323
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26323
+ return xpathResult != null ? xpathResult : "";
26324
26324
  });
26325
26325
  }
26326
26326
  dragAndDrop(fromX, fromY, toX, toY, options) {
@@ -26394,7 +26394,7 @@ var init_page = __esm({
26394
26394
  buttons: buttonMask(button),
26395
26395
  clickCount: 1
26396
26396
  });
26397
- if (options == null ? void 0 : options.returnXpath) return [fromXpath != null ? fromXpath : "", toXpath != null ? toXpath : ""];
26397
+ return [fromXpath != null ? fromXpath : "", toXpath != null ? toXpath : ""];
26398
26398
  });
26399
26399
  }
26400
26400
  type(text, options) {
@@ -27873,17 +27873,19 @@ var ActCache = class {
27873
27873
  return __async(this, null, function* () {
27874
27874
  if (!this.enabled) return null;
27875
27875
  const sanitizedInstruction = instruction.trim();
27876
- const sanitizedVariables = variables ? __spreadValues({}, variables) : {};
27876
+ const sanitizedVariables = variables ? __spreadValues({}, variables) : void 0;
27877
+ const variableKeys = sanitizedVariables ? Object.keys(sanitizedVariables).sort() : [];
27877
27878
  const pageUrl = yield safeGetPageUrl(page);
27878
27879
  const cacheKey = this.buildActCacheKey(
27879
27880
  sanitizedInstruction,
27880
27881
  pageUrl,
27881
- sanitizedVariables
27882
+ variableKeys
27882
27883
  );
27883
27884
  return {
27884
27885
  instruction: sanitizedInstruction,
27885
27886
  cacheKey,
27886
27887
  pageUrl,
27888
+ variableKeys,
27887
27889
  variables: sanitizedVariables
27888
27890
  };
27889
27891
  });
@@ -27913,6 +27915,22 @@ var ActCache = class {
27913
27915
  if (!Array.isArray(entry.actions) || entry.actions.length === 0) {
27914
27916
  return null;
27915
27917
  }
27918
+ const entryVariableKeys = Array.isArray(entry.variableKeys) ? [...entry.variableKeys].sort() : [];
27919
+ const contextVariableKeys = [...context.variableKeys];
27920
+ if (!this.doVariableKeysMatch(entryVariableKeys, contextVariableKeys)) {
27921
+ return null;
27922
+ }
27923
+ if (contextVariableKeys.length > 0 && (!context.variables || !this.hasAllVariableValues(contextVariableKeys, context.variables))) {
27924
+ this.logger({
27925
+ category: "cache",
27926
+ message: "act cache miss: missing variables for replay",
27927
+ level: 2,
27928
+ auxiliary: {
27929
+ instruction: { value: context.instruction, type: "string" }
27930
+ }
27931
+ });
27932
+ return null;
27933
+ }
27916
27934
  this.logger({
27917
27935
  category: "cache",
27918
27936
  message: "act cache hit",
@@ -27936,7 +27954,7 @@ var ActCache = class {
27936
27954
  version: 1,
27937
27955
  instruction: context.instruction,
27938
27956
  url: context.pageUrl,
27939
- variables: context.variables,
27957
+ variableKeys: context.variableKeys,
27940
27958
  actions: (_a4 = result.actions) != null ? _a4 : [],
27941
27959
  actionDescription: result.actionDescription,
27942
27960
  message: result.message
@@ -27967,11 +27985,11 @@ var ActCache = class {
27967
27985
  });
27968
27986
  });
27969
27987
  }
27970
- buildActCacheKey(instruction, url, variables) {
27988
+ buildActCacheKey(instruction, url, variableKeys) {
27971
27989
  const payload = JSON.stringify({
27972
27990
  instruction,
27973
27991
  url,
27974
- variables
27992
+ variableKeys
27975
27993
  });
27976
27994
  return (0, import_crypto.createHash)("sha256").update(payload).digest("hex");
27977
27995
  }
@@ -27989,7 +28007,9 @@ var ActCache = class {
27989
28007
  action,
27990
28008
  page,
27991
28009
  this.domSettleTimeoutMs,
27992
- this.getDefaultLlmClient()
28010
+ this.getDefaultLlmClient(),
28011
+ void 0,
28012
+ context.variables
27993
28013
  );
27994
28014
  actionResults.push(result);
27995
28015
  if (!result.success) {
@@ -28065,7 +28085,9 @@ var ActCache = class {
28065
28085
  return __async(this, null, function* () {
28066
28086
  const { error, path: path8 } = yield this.storage.writeJson(
28067
28087
  `${context.cacheKey}.json`,
28068
- entry
28088
+ __spreadProps(__spreadValues({}, entry), {
28089
+ variableKeys: context.variableKeys
28090
+ })
28069
28091
  );
28070
28092
  if (error && path8) {
28071
28093
  this.logger({
@@ -28089,6 +28111,25 @@ var ActCache = class {
28089
28111
  });
28090
28112
  });
28091
28113
  }
28114
+ doVariableKeysMatch(entryKeys, contextKeys) {
28115
+ if (entryKeys.length !== contextKeys.length) {
28116
+ return false;
28117
+ }
28118
+ for (let i2 = 0; i2 < entryKeys.length; i2 += 1) {
28119
+ if (entryKeys[i2] !== contextKeys[i2]) {
28120
+ return false;
28121
+ }
28122
+ }
28123
+ return true;
28124
+ }
28125
+ hasAllVariableValues(variableKeys, variables) {
28126
+ for (const key of variableKeys) {
28127
+ if (!(key in variables)) {
28128
+ return false;
28129
+ }
28130
+ }
28131
+ return true;
28132
+ }
28092
28133
  runWithTimeout(run, timeout) {
28093
28134
  return __async(this, null, function* () {
28094
28135
  if (!timeout) {
@@ -30074,7 +30115,6 @@ var ActHandler = class {
30074
30115
  domElements,
30075
30116
  xpathMap,
30076
30117
  llmClient,
30077
- variables,
30078
30118
  requireMethodAndArguments = true
30079
30119
  }) {
30080
30120
  const response = yield act({
@@ -30094,14 +30134,8 @@ var ActHandler = class {
30094
30134
  if (!normalized) {
30095
30135
  return { response };
30096
30136
  }
30097
- const action = __spreadProps(__spreadValues({}, normalized), {
30098
- arguments: substituteVariablesInArguments(
30099
- normalized.arguments,
30100
- variables
30101
- )
30102
- });
30103
30137
  return {
30104
- action,
30138
+ action: __spreadValues({}, normalized),
30105
30139
  response
30106
30140
  };
30107
30141
  });
@@ -30135,8 +30169,7 @@ var ActHandler = class {
30135
30169
  instruction: actInstruction,
30136
30170
  domElements: combinedTree,
30137
30171
  xpathMap: combinedXpathMap,
30138
- llmClient,
30139
- variables
30172
+ llmClient
30140
30173
  });
30141
30174
  if (!firstAction) {
30142
30175
  v3Logger({
@@ -30157,7 +30190,8 @@ var ActHandler = class {
30157
30190
  page,
30158
30191
  this.defaultDomSettleTimeoutMs,
30159
30192
  llmClient,
30160
- ensureTimeRemaining
30193
+ ensureTimeRemaining,
30194
+ variables
30161
30195
  );
30162
30196
  if ((actInferenceResponse == null ? void 0 : actInferenceResponse.twoStep) !== true) {
30163
30197
  return firstResult;
@@ -30184,8 +30218,7 @@ var ActHandler = class {
30184
30218
  instruction: stepTwoInstructions,
30185
30219
  domElements: diffedTree,
30186
30220
  xpathMap: combinedXpathMap2,
30187
- llmClient,
30188
- variables
30221
+ llmClient
30189
30222
  });
30190
30223
  if (!secondAction) {
30191
30224
  return firstResult;
@@ -30196,7 +30229,8 @@ var ActHandler = class {
30196
30229
  page,
30197
30230
  this.defaultDomSettleTimeoutMs,
30198
30231
  llmClient,
30199
- ensureTimeRemaining
30232
+ ensureTimeRemaining,
30233
+ variables
30200
30234
  );
30201
30235
  return {
30202
30236
  success: firstResult.success && secondResult.success,
@@ -30209,9 +30243,9 @@ var ActHandler = class {
30209
30243
  };
30210
30244
  });
30211
30245
  }
30212
- takeDeterministicAction(action, page, domSettleTimeoutMs, llmClientOverride, ensureTimeRemaining) {
30246
+ takeDeterministicAction(action, page, domSettleTimeoutMs, llmClientOverride, ensureTimeRemaining, variables) {
30213
30247
  return __async(this, null, function* () {
30214
- var _a4;
30248
+ var _a4, _b;
30215
30249
  ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
30216
30250
  const settleTimeout = domSettleTimeoutMs != null ? domSettleTimeoutMs : this.defaultDomSettleTimeoutMs;
30217
30251
  const effectiveClient = llmClientOverride != null ? llmClientOverride : this.llmClient;
@@ -30232,7 +30266,8 @@ var ActHandler = class {
30232
30266
  actions: []
30233
30267
  };
30234
30268
  }
30235
- const args = Array.isArray(action.arguments) ? action.arguments : [];
30269
+ const placeholderArgs = Array.isArray(action.arguments) ? [...action.arguments] : [];
30270
+ const resolvedArgs = (_b = substituteVariablesInArguments(action.arguments, variables)) != null ? _b : [];
30236
30271
  try {
30237
30272
  ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
30238
30273
  yield performUnderstudyMethod(
@@ -30240,7 +30275,7 @@ var ActHandler = class {
30240
30275
  page.mainFrame(),
30241
30276
  method,
30242
30277
  action.selector,
30243
- args,
30278
+ resolvedArgs,
30244
30279
  settleTimeout
30245
30280
  );
30246
30281
  return {
@@ -30252,7 +30287,7 @@ var ActHandler = class {
30252
30287
  selector: action.selector,
30253
30288
  description: action.description || `action (${method})`,
30254
30289
  method,
30255
- arguments: args
30290
+ arguments: placeholderArgs
30256
30291
  }
30257
30292
  ]
30258
30293
  };
@@ -30312,7 +30347,7 @@ var ActHandler = class {
30312
30347
  page.mainFrame(),
30313
30348
  method,
30314
30349
  newSelector,
30315
- args,
30350
+ resolvedArgs,
30316
30351
  settleTimeout
30317
30352
  );
30318
30353
  return {
@@ -30324,7 +30359,7 @@ var ActHandler = class {
30324
30359
  selector: newSelector,
30325
30360
  description: action.description || `action (${method})`,
30326
30361
  method,
30327
- arguments: args
30362
+ arguments: placeholderArgs
30328
30363
  }
30329
30364
  ]
30330
30365
  };
@@ -65182,7 +65217,8 @@ var _V3 = class _V3 {
65182
65217
  v3Page,
65183
65218
  this.domSettleTimeoutMs,
65184
65219
  this.resolveLlmClient(options == null ? void 0 : options.model),
65185
- ensureTimeRemaining
65220
+ ensureTimeRemaining,
65221
+ options == null ? void 0 : options.variables
65186
65222
  );
65187
65223
  }
65188
65224
  this.addToHistory(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "3.0.7-alpha-6a5496f17dbb716be1ee1aaa4e5ba9d8c723b30b",
3
+ "version": "3.0.7-alpha-e822f5a8898df9eb48ca32c321025f0c74b638f0",
4
4
  "description": "An AI web browsing framework focused on simplicity and extensibility.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",