@browserbasehq/stagehand 3.0.7-alpha-b48c9c68e97f6370e2c01ba0232b951915142abd → 3.0.7-alpha-fea1700552af3319052f463685752501c8e71de3

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
@@ -947,6 +947,7 @@ declare class StagehandAPIClient {
947
947
  private projectId;
948
948
  private sessionId?;
949
949
  private modelApiKey;
950
+ private modelProvider?;
950
951
  private logger;
951
952
  private fetchWithCookies;
952
953
  constructor({ apiKey, projectId, logger }: StagehandAPIConstructorParams);
@@ -960,6 +961,14 @@ declare class StagehandAPIClient {
960
961
  agentExecute(agentConfig: AgentConfig, executeOptions: AgentExecuteOptions | string, frameId?: string): Promise<AgentResult>;
961
962
  end(): Promise<Response>;
962
963
  getReplayMetrics(): Promise<StagehandMetrics>;
964
+ /**
965
+ * Prepares a model configuration for the API payload by ensuring
966
+ * the apiKey is included. If the model is passed as a string,
967
+ * it converts it to an object with modelName and apiKey.
968
+ * The apiKey is loaded from environment variables only if the provider
969
+ * differs from the one used during init.
970
+ */
971
+ private prepareModelConfig;
963
972
  private execute;
964
973
  private request;
965
974
  }
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-b48c9c68e97f6370e2c01ba0232b951915142abd";
182
+ STAGEHAND_VERSION = "3.0.7-alpha-fea1700552af3319052f463685752501c8e71de3";
183
183
  }
184
184
  });
185
185
 
@@ -65014,6 +65014,7 @@ var StagehandAPIClient = class {
65014
65014
  throw new StagehandAPIError("modelApiKey is required");
65015
65015
  }
65016
65016
  this.modelApiKey = modelApiKey;
65017
+ this.modelProvider = (modelName == null ? void 0 : modelName.includes("/")) ? modelName.split("/")[0] : void 0;
65017
65018
  const region = browserbaseSessionCreateParams == null ? void 0 : browserbaseSessionCreateParams.region;
65018
65019
  if (region && region !== "us-west-2") {
65019
65020
  return { sessionId: browserbaseSessionID != null ? browserbaseSessionID : null, available: false };
@@ -65068,6 +65069,9 @@ var StagehandAPIClient = class {
65068
65069
  if (options) {
65069
65070
  const _a4 = options, { page: _ } = _a4, restOptions = __objRest(_a4, ["page"]);
65070
65071
  if (Object.keys(restOptions).length > 0) {
65072
+ if (restOptions.model) {
65073
+ restOptions.model = this.prepareModelConfig(restOptions.model);
65074
+ }
65071
65075
  args.options = restOptions;
65072
65076
  }
65073
65077
  }
@@ -65093,6 +65097,9 @@ var StagehandAPIClient = class {
65093
65097
  if (options) {
65094
65098
  const _a4 = options, { page: _ } = _a4, restOptions = __objRest(_a4, ["page"]);
65095
65099
  if (Object.keys(restOptions).length > 0) {
65100
+ if (restOptions.model) {
65101
+ restOptions.model = this.prepareModelConfig(restOptions.model);
65102
+ }
65096
65103
  args.options = restOptions;
65097
65104
  }
65098
65105
  }
@@ -65115,6 +65122,9 @@ var StagehandAPIClient = class {
65115
65122
  if (options) {
65116
65123
  const _a4 = options, { page: _ } = _a4, restOptions = __objRest(_a4, ["page"]);
65117
65124
  if (Object.keys(restOptions).length > 0) {
65125
+ if (restOptions.model) {
65126
+ restOptions.model = this.prepareModelConfig(restOptions.model);
65127
+ }
65118
65128
  args.options = restOptions;
65119
65129
  }
65120
65130
  }
@@ -65259,6 +65269,32 @@ var StagehandAPIClient = class {
65259
65269
  return metrics;
65260
65270
  });
65261
65271
  }
65272
+ /**
65273
+ * Prepares a model configuration for the API payload by ensuring
65274
+ * the apiKey is included. If the model is passed as a string,
65275
+ * it converts it to an object with modelName and apiKey.
65276
+ * The apiKey is loaded from environment variables only if the provider
65277
+ * differs from the one used during init.
65278
+ */
65279
+ prepareModelConfig(model) {
65280
+ var _a4, _b, _c;
65281
+ if (typeof model === "string") {
65282
+ const provider = model.includes("/") ? model.split("/")[0] : void 0;
65283
+ const apiKey = provider && provider !== this.modelProvider ? (_a4 = loadApiKeyFromEnv(provider, this.logger)) != null ? _a4 : this.modelApiKey : this.modelApiKey;
65284
+ return {
65285
+ modelName: model,
65286
+ apiKey
65287
+ };
65288
+ }
65289
+ if (!model.apiKey) {
65290
+ const provider = ((_b = model.modelName) == null ? void 0 : _b.includes("/")) ? model.modelName.split("/")[0] : void 0;
65291
+ const apiKey = provider && provider !== this.modelProvider ? (_c = loadApiKeyFromEnv(provider, this.logger)) != null ? _c : this.modelApiKey : this.modelApiKey;
65292
+ return __spreadProps(__spreadValues({}, model), {
65293
+ apiKey
65294
+ });
65295
+ }
65296
+ return model;
65297
+ }
65262
65298
  execute(_0) {
65263
65299
  return __async(this, arguments, function* ({
65264
65300
  method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "3.0.7-alpha-b48c9c68e97f6370e2c01ba0232b951915142abd",
3
+ "version": "3.0.7-alpha-fea1700552af3319052f463685752501c8e71de3",
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",