notte-sdk 1.10.18 → 1.10.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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = true ? "1.10.18" : "dev";
2
+ var SDK_VERSION = true ? "1.10.20" : "dev";
3
3
  var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
4
4
 
5
5
  // src/version-check.ts
@@ -119,33 +119,33 @@ function getEnv() {
119
119
  }
120
120
 
121
121
  // src/lib/client/core/bodySerializer.gen.ts
122
- var serializeFormDataPair = (data, key, value) => {
123
- if (typeof value === "string" || value instanceof Blob) {
124
- data.append(key, value);
125
- } else if (value instanceof Date) {
126
- data.append(key, value.toISOString());
122
+ var serializeFormDataPair = (data, key, value2) => {
123
+ if (typeof value2 === "string" || value2 instanceof Blob) {
124
+ data.append(key, value2);
125
+ } else if (value2 instanceof Date) {
126
+ data.append(key, value2.toISOString());
127
127
  } else {
128
- data.append(key, JSON.stringify(value));
128
+ data.append(key, JSON.stringify(value2));
129
129
  }
130
130
  };
131
131
  var formDataBodySerializer = {
132
132
  bodySerializer: (body) => {
133
133
  const data = new FormData();
134
- Object.entries(body).forEach(([key, value]) => {
135
- if (value === void 0 || value === null) {
134
+ Object.entries(body).forEach(([key, value2]) => {
135
+ if (value2 === void 0 || value2 === null) {
136
136
  return;
137
137
  }
138
- if (Array.isArray(value)) {
139
- value.forEach((v) => serializeFormDataPair(data, key, v));
138
+ if (Array.isArray(value2)) {
139
+ value2.forEach((v) => serializeFormDataPair(data, key, v));
140
140
  } else {
141
- serializeFormDataPair(data, key, value);
141
+ serializeFormDataPair(data, key, value2);
142
142
  }
143
143
  });
144
144
  return data;
145
145
  }
146
146
  };
147
147
  var jsonBodySerializer = {
148
- bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
148
+ bodySerializer: (body) => JSON.stringify(body, (_key, value2) => typeof value2 === "bigint" ? value2.toString() : value2)
149
149
  };
150
150
 
151
151
  // src/lib/client/core/params.gen.ts
@@ -211,9 +211,9 @@ function createSseClient({
211
211
  signal.addEventListener("abort", abortHandler);
212
212
  try {
213
213
  while (true) {
214
- const { done, value } = await reader.read();
214
+ const { done, value: value2 } = await reader.read();
215
215
  if (done) break;
216
- buffer += value;
216
+ buffer += value2;
217
217
  buffer = buffer.replace(/\r\n?/g, "\n");
218
218
  const chunks = buffer.split("\n\n");
219
219
  buffer = chunks.pop() ?? "";
@@ -326,10 +326,10 @@ var serializeArrayParam = ({
326
326
  explode,
327
327
  name,
328
328
  style,
329
- value
329
+ value: value2
330
330
  }) => {
331
331
  if (!explode) {
332
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
332
+ const joinedValues2 = (allowReserved ? value2 : value2.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
333
333
  switch (style) {
334
334
  case "label":
335
335
  return `.${joinedValues2}`;
@@ -342,7 +342,7 @@ var serializeArrayParam = ({
342
342
  }
343
343
  }
344
344
  const separator = separatorArrayExplode(style);
345
- const joinedValues = value.map((v) => {
345
+ const joinedValues = value2.map((v) => {
346
346
  if (style === "label" || style === "simple") {
347
347
  return allowReserved ? v : encodeURIComponent(v);
348
348
  }
@@ -357,32 +357,32 @@ var serializeArrayParam = ({
357
357
  var serializePrimitiveParam = ({
358
358
  allowReserved,
359
359
  name,
360
- value
360
+ value: value2
361
361
  }) => {
362
- if (value === void 0 || value === null) {
362
+ if (value2 === void 0 || value2 === null) {
363
363
  return "";
364
364
  }
365
- if (typeof value === "object") {
365
+ if (typeof value2 === "object") {
366
366
  throw new Error(
367
367
  "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
368
368
  );
369
369
  }
370
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
370
+ return `${name}=${allowReserved ? value2 : encodeURIComponent(value2)}`;
371
371
  };
372
372
  var serializeObjectParam = ({
373
373
  allowReserved,
374
374
  explode,
375
375
  name,
376
376
  style,
377
- value,
377
+ value: value2,
378
378
  valueOnly
379
379
  }) => {
380
- if (value instanceof Date) {
381
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
380
+ if (value2 instanceof Date) {
381
+ return valueOnly ? value2.toISOString() : `${name}=${value2.toISOString()}`;
382
382
  }
383
383
  if (style !== "deepObject" && !explode) {
384
384
  let values = [];
385
- Object.entries(value).forEach(([key, v]) => {
385
+ Object.entries(value2).forEach(([key, v]) => {
386
386
  values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
387
387
  });
388
388
  const joinedValues2 = values.join(",");
@@ -398,7 +398,7 @@ var serializeObjectParam = ({
398
398
  }
399
399
  }
400
400
  const separator = separatorObjectExplode(style);
401
- const joinedValues = Object.entries(value).map(
401
+ const joinedValues = Object.entries(value2).map(
402
402
  ([key, v]) => serializePrimitiveParam({
403
403
  allowReserved,
404
404
  name: style === "deepObject" ? `${name}[${key}]` : key,
@@ -429,22 +429,22 @@ var defaultPathSerializer = ({ path, url: _url }) => {
429
429
  name = name.substring(1);
430
430
  style = "matrix";
431
431
  }
432
- const value = path[name];
433
- if (value === void 0 || value === null) {
432
+ const value2 = path[name];
433
+ if (value2 === void 0 || value2 === null) {
434
434
  continue;
435
435
  }
436
- if (Array.isArray(value)) {
437
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
436
+ if (Array.isArray(value2)) {
437
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value: value2 }));
438
438
  continue;
439
439
  }
440
- if (typeof value === "object") {
440
+ if (typeof value2 === "object") {
441
441
  url = url.replace(
442
442
  match,
443
443
  serializeObjectParam({
444
444
  explode,
445
445
  name,
446
446
  style,
447
- value,
447
+ value: value2,
448
448
  valueOnly: true
449
449
  })
450
450
  );
@@ -455,13 +455,13 @@ var defaultPathSerializer = ({ path, url: _url }) => {
455
455
  match,
456
456
  `;${serializePrimitiveParam({
457
457
  name,
458
- value
458
+ value: value2
459
459
  })}`
460
460
  );
461
461
  continue;
462
462
  }
463
463
  const replaceValue = encodeURIComponent(
464
- style === "label" ? `.${value}` : value
464
+ style === "label" ? `.${value2}` : value2
465
465
  );
466
466
  url = url.replace(match, replaceValue);
467
467
  }
@@ -529,28 +529,28 @@ var createQuerySerializer = ({
529
529
  const search = [];
530
530
  if (queryParams && typeof queryParams === "object") {
531
531
  for (const name in queryParams) {
532
- const value = queryParams[name];
533
- if (value === void 0 || value === null) {
532
+ const value2 = queryParams[name];
533
+ if (value2 === void 0 || value2 === null) {
534
534
  continue;
535
535
  }
536
536
  const options = parameters[name] || args;
537
- if (Array.isArray(value)) {
537
+ if (Array.isArray(value2)) {
538
538
  const serializedArray = serializeArrayParam({
539
539
  allowReserved: options.allowReserved,
540
540
  explode: true,
541
541
  name,
542
542
  style: "form",
543
- value,
543
+ value: value2,
544
544
  ...options.array
545
545
  });
546
546
  if (serializedArray) search.push(serializedArray);
547
- } else if (typeof value === "object") {
547
+ } else if (typeof value2 === "object") {
548
548
  const serializedObject = serializeObjectParam({
549
549
  allowReserved: options.allowReserved,
550
550
  explode: true,
551
551
  name,
552
552
  style: "deepObject",
553
- value,
553
+ value: value2,
554
554
  ...options.object
555
555
  });
556
556
  if (serializedObject) search.push(serializedObject);
@@ -558,7 +558,7 @@ var createQuerySerializer = ({
558
558
  const serializedPrimitive = serializePrimitiveParam({
559
559
  allowReserved: options.allowReserved,
560
560
  name,
561
- value
561
+ value: value2
562
562
  });
563
563
  if (serializedPrimitive) search.push(serializedPrimitive);
564
564
  }
@@ -643,8 +643,8 @@ var mergeConfigs = (a, b) => {
643
643
  };
644
644
  var headersEntries = (headers) => {
645
645
  const entries = [];
646
- headers.forEach((value, key) => {
647
- entries.push([key, value]);
646
+ headers.forEach((value2, key) => {
647
+ entries.push([key, value2]);
648
648
  });
649
649
  return entries;
650
650
  };
@@ -655,17 +655,17 @@ var mergeHeaders = (...headers) => {
655
655
  continue;
656
656
  }
657
657
  const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
658
- for (const [key, value] of iterator) {
659
- if (value === null) {
658
+ for (const [key, value2] of iterator) {
659
+ if (value2 === null) {
660
660
  mergedHeaders.delete(key);
661
- } else if (Array.isArray(value)) {
662
- for (const v of value) {
661
+ } else if (Array.isArray(value2)) {
662
+ for (const v of value2) {
663
663
  mergedHeaders.append(key, v);
664
664
  }
665
- } else if (value !== void 0) {
665
+ } else if (value2 !== void 0) {
666
666
  mergedHeaders.set(
667
667
  key,
668
- typeof value === "object" ? JSON.stringify(value) : value
668
+ typeof value2 === "object" ? JSON.stringify(value2) : value2
669
669
  );
670
670
  }
671
671
  }
@@ -2152,9 +2152,9 @@ async function pollAuth(read, options) {
2152
2152
  while (true) {
2153
2153
  signal.throwIfAborted();
2154
2154
  try {
2155
- const value = await read(signal);
2155
+ const value2 = await read(signal);
2156
2156
  signal.throwIfAborted();
2157
- if (value !== void 0) return value;
2157
+ if (value2 !== void 0) return value2;
2158
2158
  errors = 0;
2159
2159
  } catch (error) {
2160
2160
  signal.throwIfAborted();
@@ -2197,10 +2197,10 @@ var NotteManagedAuth = class {
2197
2197
  }
2198
2198
  /** Wait for an accepted operation. Aborting this wait does not cancel the server operation. */
2199
2199
  async waitForAuth(operation, options = {}) {
2200
- const completed = (value) => {
2201
- if (value.status === "succeeded") return value;
2202
- if (value.status === "pending" || value.status === "running") return void 0;
2203
- throw new ManagedAuthError(value.error || "Connection authentication failed");
2200
+ const completed = (value2) => {
2201
+ if (value2.status === "succeeded") return value2;
2202
+ if (value2.status === "pending" || value2.status === "running") return void 0;
2203
+ throw new ManagedAuthError(value2.error || "Connection authentication failed");
2204
2204
  };
2205
2205
  options.signal?.throwIfAborted();
2206
2206
  const result = completed(operation);
@@ -2666,6 +2666,32 @@ import { writeFile as writeFile2 } from "fs/promises";
2666
2666
  import { resolve as resolve2 } from "path";
2667
2667
  import { setTimeout as delay2 } from "timers/promises";
2668
2668
 
2669
+ // src/client-info.ts
2670
+ var UNSAFE = /[^A-Za-z0-9._/-]/g;
2671
+ var MAX_VALUE_LENGTH = 100;
2672
+ function value(env, name) {
2673
+ const raw = env[name];
2674
+ return raw ? raw.replace(UNSAFE, "_").slice(0, MAX_VALUE_LENGTH) : void 0;
2675
+ }
2676
+ function githubActionsContext(env) {
2677
+ if (env.GITHUB_ACTIONS !== "true") return void 0;
2678
+ const run = value(env, "GITHUB_RUN_ID");
2679
+ const attempt = value(env, "GITHUB_RUN_ATTEMPT");
2680
+ const fields = [
2681
+ ["repo", value(env, "GITHUB_REPOSITORY")],
2682
+ ["run", run && attempt ? `${run}/${attempt}` : run],
2683
+ ["job", value(env, "GITHUB_JOB")]
2684
+ ];
2685
+ const parts = fields.filter(([, v]) => v).map(([k, v]) => `${k}=${v}`);
2686
+ return `github-actions (${parts.join("; ")})`;
2687
+ }
2688
+ function clientUserAgent() {
2689
+ if (typeof process === "undefined" || !process.versions?.node) return void 0;
2690
+ const agent = `notte-sdk-node/${SDK_VERSION} (node ${process.versions.node}; ${process.platform})`;
2691
+ const ci = githubActionsContext(process.env);
2692
+ return ci === void 0 ? agent : `${agent} ${ci}`;
2693
+ }
2694
+
2669
2695
  // src/captcha.ts
2670
2696
  async function executeWithCaptcha(action, budgetSeconds, request) {
2671
2697
  const explicit = action.type === "captcha_solve";
@@ -2756,11 +2782,11 @@ function hasHeader(headers, name) {
2756
2782
  }
2757
2783
  function urlencode(mapping) {
2758
2784
  const search = new URLSearchParams();
2759
- for (const [key, value] of Object.entries(mapping)) {
2760
- if (Array.isArray(value)) {
2761
- for (const item of value) search.append(key, String(item));
2785
+ for (const [key, value2] of Object.entries(mapping)) {
2786
+ if (Array.isArray(value2)) {
2787
+ for (const item of value2) search.append(key, String(item));
2762
2788
  } else {
2763
- search.append(key, String(value));
2789
+ search.append(key, String(value2));
2764
2790
  }
2765
2791
  }
2766
2792
  return search.toString();
@@ -2900,9 +2926,9 @@ function encodingFor(headers, content) {
2900
2926
  const contentType = Object.entries(headers).find(([key]) => key.toLowerCase() === CONTENT_TYPE)?.[1] ?? "";
2901
2927
  for (const param of contentType.split(";").slice(1)) {
2902
2928
  const [name, ...rest] = param.split("=");
2903
- const value = rest.join("=");
2904
- if (name?.trim().toLowerCase() === "charset" && value) {
2905
- return value.trim().replace(/^["']|["']$/g, "");
2929
+ const value2 = rest.join("=");
2930
+ if (name?.trim().toLowerCase() === "charset" && value2) {
2931
+ return value2.trim().replace(/^["']|["']$/g, "");
2906
2932
  }
2907
2933
  }
2908
2934
  try {
@@ -2960,11 +2986,11 @@ var PageFetchResponse = class {
2960
2986
  }
2961
2987
  };
2962
2988
  var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
2963
- function decodeBase64(value) {
2964
- if (!BASE64_PATTERN.test(value) || value.length % 4 !== 0) {
2989
+ function decodeBase64(value2) {
2990
+ if (!BASE64_PATTERN.test(value2) || value2.length % 4 !== 0) {
2965
2991
  throw new Error("body_b64 is not valid base64");
2966
2992
  }
2967
- return new Uint8Array(Buffer.from(value, "base64"));
2993
+ return new Uint8Array(Buffer.from(value2, "base64"));
2968
2994
  }
2969
2995
  function responseFromEvaluated(raw) {
2970
2996
  let payload;
@@ -2990,8 +3016,8 @@ function responseFromEvaluated(raw) {
2990
3016
  throw new Error("headers is not an object");
2991
3017
  }
2992
3018
  const headers = {};
2993
- for (const [key, value] of Object.entries(rawHeaders)) {
2994
- headers[String(key)] = String(value);
3019
+ for (const [key, value2] of Object.entries(rawHeaders)) {
3020
+ headers[String(key)] = String(value2);
2995
3021
  }
2996
3022
  const content = decodeBase64(String(envelope.body_b64 ?? ""));
2997
3023
  const url = String(envelope.url ?? "");
@@ -3128,17 +3154,17 @@ var SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set(["properties", "patternPropert
3128
3154
  function normalizeJsonSchema(schema) {
3129
3155
  if (schema === null || typeof schema !== "object" || Array.isArray(schema)) return schema;
3130
3156
  const out = {};
3131
- for (const [key, value] of Object.entries(schema)) {
3132
- if (SCHEMA_KEYWORDS.has(key) || key === "items" && Array.isArray(value)) {
3133
- out[key] = Array.isArray(value) ? value.map(normalizeJsonSchema) : normalizeJsonSchema(value);
3134
- } else if (SCHEMA_ARRAY_KEYWORDS.has(key) && Array.isArray(value)) {
3135
- out[key] = value.map(normalizeJsonSchema);
3136
- } else if (SCHEMA_MAP_KEYWORDS.has(key) && value !== null && typeof value === "object" && !Array.isArray(value)) {
3157
+ for (const [key, value2] of Object.entries(schema)) {
3158
+ if (SCHEMA_KEYWORDS.has(key) || key === "items" && Array.isArray(value2)) {
3159
+ out[key] = Array.isArray(value2) ? value2.map(normalizeJsonSchema) : normalizeJsonSchema(value2);
3160
+ } else if (SCHEMA_ARRAY_KEYWORDS.has(key) && Array.isArray(value2)) {
3161
+ out[key] = value2.map(normalizeJsonSchema);
3162
+ } else if (SCHEMA_MAP_KEYWORDS.has(key) && value2 !== null && typeof value2 === "object" && !Array.isArray(value2)) {
3137
3163
  out[key] = Object.fromEntries(
3138
- Object.entries(value).map(([name, sub]) => [name, normalizeJsonSchema(sub)])
3164
+ Object.entries(value2).map(([name, sub]) => [name, normalizeJsonSchema(sub)])
3139
3165
  );
3140
3166
  } else {
3141
- out[key] = value;
3167
+ out[key] = value2;
3142
3168
  }
3143
3169
  }
3144
3170
  if (Array.isArray(out.type)) {
@@ -3146,8 +3172,8 @@ function normalizeJsonSchema(schema) {
3146
3172
  const types = type;
3147
3173
  const parent = {};
3148
3174
  const scoped = {};
3149
- for (const [key, value] of Object.entries(rest)) {
3150
- (TYPE_SCOPED_KEYWORDS.has(key) ? scoped : parent)[key] = value;
3175
+ for (const [key, value2] of Object.entries(rest)) {
3176
+ (TYPE_SCOPED_KEYWORDS.has(key) ? scoped : parent)[key] = value2;
3151
3177
  }
3152
3178
  const typed = (t) => t === "null" ? { type: t } : { type: t, ...scoped };
3153
3179
  let branches;
@@ -3177,8 +3203,8 @@ function normalizeJsonSchema(schema) {
3177
3203
  }
3178
3204
 
3179
3205
  // src/scrape.ts
3180
- function isZodSchema(value) {
3181
- return typeof value === "object" && value !== null && typeof value.parse === "function";
3206
+ function isZodSchema(value2) {
3207
+ return typeof value2 === "object" && value2 !== null && typeof value2.parse === "function";
3182
3208
  }
3183
3209
  function requiresSchema(options) {
3184
3210
  return Boolean(options.response_format || options.instructions);
@@ -3267,9 +3293,9 @@ function networkErrorCode(error, depth = 0) {
3267
3293
  }
3268
3294
  function parseRetryAfter(header, now = Date.now()) {
3269
3295
  if (!header) return void 0;
3270
- const value = header.trim();
3271
- if (/^\d+(\.\d+)?$/.test(value)) return Number(value) * 1e3;
3272
- const date = Date.parse(value);
3296
+ const value2 = header.trim();
3297
+ if (/^\d+(\.\d+)?$/.test(value2)) return Number(value2) * 1e3;
3298
+ const date = Date.parse(value2);
3273
3299
  return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
3274
3300
  }
3275
3301
  function backoffDelayMs(attempt, random = Math.random) {
@@ -3376,6 +3402,30 @@ function cdpTransportFailure(error) {
3376
3402
  if (reason.startsWith("ws://") || reason.startsWith("wss://")) return void 0;
3377
3403
  return CDP_TRANSPORT_FAILURES.some((failure) => reason.includes(failure)) ? reason : void 0;
3378
3404
  }
3405
+ function onApiOrigin(cdpUrl, apiUrl) {
3406
+ if (!apiUrl) return false;
3407
+ let target;
3408
+ let api;
3409
+ try {
3410
+ target = new URL(cdpUrl);
3411
+ api = new URL(apiUrl);
3412
+ } catch {
3413
+ return false;
3414
+ }
3415
+ const secure = target.protocol === "wss:" && api.protocol === "https:";
3416
+ const plain = target.protocol === "ws:" && api.protocol === "http:";
3417
+ if (!secure && !plain) return false;
3418
+ const defaultPort = secure ? "443" : "80";
3419
+ return target.hostname === api.hostname && (target.port || defaultPort) === (api.port || defaultPort);
3420
+ }
3421
+ function cdpHeaders(cdpUrl, apiUrl) {
3422
+ const userAgent = onApiOrigin(cdpUrl, apiUrl) ? clientUserAgent() : void 0;
3423
+ return {
3424
+ ...userAgent ? { "user-agent": userAgent } : {},
3425
+ "x-notte-request-origin": REQUEST_ORIGIN,
3426
+ "x-notte-sdk-version": SDK_VERSION
3427
+ };
3428
+ }
3379
3429
  async function connectOverCdpWithRetry(connect) {
3380
3430
  try {
3381
3431
  return await connect();
@@ -4016,7 +4066,7 @@ var Session = class {
4016
4066
  const cdpUrl = await this.cdpUrl();
4017
4067
  this.playwrightBrowser = await connectOverCdpWithRetry(
4018
4068
  () => this.options.cdp_url ? playwright.chromium.connectOverCDP(cdpUrl) : playwright.chromium.connectOverCDP(cdpUrl, {
4019
- headers: { "x-notte-request-origin": REQUEST_ORIGIN, "x-notte-sdk-version": SDK_VERSION }
4069
+ headers: cdpHeaders(cdpUrl, this.client.getConfig().baseUrl)
4020
4070
  })
4021
4071
  );
4022
4072
  installServerOwnedDialogPolicy(this.playwrightBrowser);
@@ -4042,7 +4092,7 @@ var Session = class {
4042
4092
  }
4043
4093
  }
4044
4094
  /**
4045
- * Get the workflow code generated from the session steps
4095
+ * Get the function code generated from the session steps
4046
4096
  * (`GET /sessions/{id}/workflow/code`).
4047
4097
  *
4048
4098
  * @example
@@ -4564,9 +4614,9 @@ var NotteVault = class {
4564
4614
  for (const field of CREDENTIAL_FIELDS) {
4565
4615
  const variable = `${prefix}_${field.toUpperCase()}`;
4566
4616
  variableNames.push(variable);
4567
- const value = process.env[variable];
4568
- if (value !== void 0) {
4569
- credentials[field] = value;
4617
+ const value2 = process.env[variable];
4618
+ if (value2 !== void 0) {
4619
+ credentials[field] = value2;
4570
4620
  }
4571
4621
  }
4572
4622
  if (Object.keys(credentials).length === 0) {
@@ -4601,9 +4651,9 @@ var NotteVault = class {
4601
4651
  const limit = Math.floor(4294967296 / size) * size;
4602
4652
  const buffer = new Uint32Array(1);
4603
4653
  for (; ; ) {
4604
- const [value] = globalThis.crypto.getRandomValues(buffer);
4605
- if (value < limit) {
4606
- return value % size;
4654
+ const [value2] = globalThis.crypto.getRandomValues(buffer);
4655
+ if (value2 < limit) {
4656
+ return value2 % size;
4607
4657
  }
4608
4658
  }
4609
4659
  };
@@ -4980,12 +5030,12 @@ async function resolveRunPayloads(input) {
4980
5030
  let size = 0;
4981
5031
  try {
4982
5032
  while (true) {
4983
- const { done, value: value2 } = await reader.read();
5033
+ const { done, value: value3 } = await reader.read();
4984
5034
  if (done) break;
4985
- size += value2.length;
5035
+ size += value3.length;
4986
5036
  if (size > reference.size_bytes) throw new Error("Run payload exceeds its declared size");
4987
- hash.update(value2);
4988
- chunks.push(value2);
5037
+ hash.update(value3);
5038
+ chunks.push(value3);
4989
5039
  }
4990
5040
  } finally {
4991
5041
  await reader.cancel();
@@ -4994,11 +5044,11 @@ async function resolveRunPayloads(input) {
4994
5044
  if (size !== reference.size_bytes || hash.digest("base64") !== reference.sha256) {
4995
5045
  throw new Error("Run payload failed size/checksum verification");
4996
5046
  }
4997
- const value = JSON.parse(Buffer.concat(chunks, size).toString("utf8"));
4998
- if (field === "result" && value !== null && typeof value !== "string") throw new Error("Invalid stored result");
4999
- if (field === "logs" && (!Array.isArray(value) || !value.every((line) => typeof line === "string"))) throw new Error("Invalid stored logs");
5000
- if (field === "variables" && value !== null && (typeof value !== "object" || Array.isArray(value))) throw new Error("Invalid stored variables");
5001
- Object.assign(run, { [field]: value });
5047
+ const value2 = JSON.parse(Buffer.concat(chunks, size).toString("utf8"));
5048
+ if (field === "result" && value2 !== null && typeof value2 !== "string") throw new Error("Invalid stored result");
5049
+ if (field === "logs" && (!Array.isArray(value2) || !value2.every((line) => typeof line === "string"))) throw new Error("Invalid stored logs");
5050
+ if (field === "variables" && value2 !== null && (typeof value2 !== "object" || Array.isArray(value2))) throw new Error("Invalid stored variables");
5051
+ Object.assign(run, { [field]: value2 });
5002
5052
  }
5003
5053
  delete run.payloads;
5004
5054
  delete run.payload_urls;
@@ -5505,8 +5555,8 @@ var NotteFunction = class {
5505
5555
  return response.data;
5506
5556
  }
5507
5557
  };
5508
- function isHttpUrl(value) {
5509
- return value.startsWith("https://") || value.startsWith("http://");
5558
+ function isHttpUrl(value2) {
5559
+ return value2.startsWith("https://") || value2.startsWith("http://");
5510
5560
  }
5511
5561
  function assertPythonPath(path) {
5512
5562
  if (!path.endsWith(".py")) {
@@ -5540,11 +5590,11 @@ function unwrapRuntimeEnvelope(candidate, path) {
5540
5590
  }
5541
5591
  throw NotteAPIError.fromBody(path, statusCode, parsed);
5542
5592
  }
5543
- function parseFunctionRunResult(value, path) {
5544
- if (typeof value !== "object" || value === null) {
5593
+ function parseFunctionRunResult(value2, path) {
5594
+ if (typeof value2 !== "object" || value2 === null) {
5545
5595
  throw new NotteError("Invalid function result: expected an object");
5546
5596
  }
5547
- const candidate = value;
5597
+ const candidate = value2;
5548
5598
  unwrapRuntimeEnvelope(candidate, path);
5549
5599
  const status = candidate.status;
5550
5600
  if (typeof candidate.function_run_id !== "string" || typeof candidate.function_id !== "string" || typeof status !== "string" || !FUNCTION_RUN_STATUSES.includes(status) || !("result" in candidate)) {
@@ -5590,21 +5640,21 @@ async function readFunctionStream(body, onLog, path, signal) {
5590
5640
  if (event.type === "log") onLog(String(event.message ?? ""));
5591
5641
  if (event.type === "error") throw new NotteError(`Function stream error: ${String(event.message ?? "")}`);
5592
5642
  if (event.type === "result") {
5593
- const value = typeof event.message === "string" ? JSON.parse(event.message) : event.message;
5594
- result = parseFunctionRunResult(value, path);
5643
+ const value2 = typeof event.message === "string" ? JSON.parse(event.message) : event.message;
5644
+ result = parseFunctionRunResult(value2, path);
5595
5645
  }
5596
5646
  };
5597
- const line = (value) => {
5598
- if (value === "") dispatch();
5599
- else if (value.startsWith("data:")) {
5647
+ const line = (value2) => {
5648
+ if (value2 === "") dispatch();
5649
+ else if (value2.startsWith("data:")) {
5600
5650
  sawFrame = true;
5601
- data.push(value.slice(5).replace(/^ /, ""));
5651
+ data.push(value2.slice(5).replace(/^ /, ""));
5602
5652
  }
5603
5653
  };
5604
5654
  try {
5605
5655
  while (true) {
5606
- const { value, done } = await reader.read();
5607
- const text = decoder.decode(value, { stream: !done });
5656
+ const { value: value2, done } = await reader.read();
5657
+ const text = decoder.decode(value2, { stream: !done });
5608
5658
  buffer += text;
5609
5659
  if (!sawFrame) raw += text;
5610
5660
  let end;
@@ -5961,8 +6011,8 @@ async function* readAnythingStream(body) {
5961
6011
  let buffer = "";
5962
6012
  try {
5963
6013
  while (true) {
5964
- const { value, done } = await reader.read();
5965
- buffer += decoder.decode(value, { stream: !done });
6014
+ const { value: value2, done } = await reader.read();
6015
+ buffer += decoder.decode(value2, { stream: !done });
5966
6016
  let end;
5967
6017
  while ((end = buffer.indexOf("\n")) !== -1) {
5968
6018
  const line = buffer.slice(0, end).replace(/\r$/, "");
@@ -6195,6 +6245,8 @@ var NotteClient3 = class {
6195
6245
  if (this.config.apiKey) headers.set("Authorization", `Bearer ${this.config.apiKey}`);
6196
6246
  headers.set("x-notte-request-origin", REQUEST_ORIGIN);
6197
6247
  headers.set("x-notte-sdk-version", SDK_VERSION);
6248
+ const userAgent = clientUserAgent();
6249
+ if (userAgent) headers.set("user-agent", userAgent);
6198
6250
  if (this.config.dbPreview) headers.set(DB_PREVIEW_HEADER, this.config.dbPreview);
6199
6251
  if (!headers.has(ACCEPT_RUN_STATUSES_HEADER) && isFunctionsRequest(request.url, this.config.baseUrl)) {
6200
6252
  headers.set(ACCEPT_RUN_STATUSES_HEADER, "rejected");