notte-sdk 1.9.7 → 1.10.1

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.js CHANGED
@@ -31,11 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ActionExecutionError: () => ActionExecutionError,
34
- Agent: () => Agent,
35
34
  AuthenticationError: () => AuthenticationError,
36
35
  CAPTCHA_SOLVE_TIMEOUT_MS: () => CAPTCHA_SOLVE_TIMEOUT_MS,
37
36
  CLUSTER_OVERLOAD_RETRY_DELAY_MS: () => CLUSTER_OVERLOAD_RETRY_DELAY_MS,
38
37
  CREDENTIAL_FIELDS: () => CREDENTIAL_FIELDS,
38
+ DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES,
39
39
  DEFAULT_NOTTE_API_URL: () => DEFAULT_NOTTE_API_URL,
40
40
  DEFAULT_REQUEST_TIMEOUT_MS: () => DEFAULT_REQUEST_TIMEOUT_MS,
41
41
  Encryption: () => Encryption,
@@ -70,12 +70,17 @@ __export(index_exports, {
70
70
  Session: () => Session,
71
71
  SessionFiles: () => SessionFiles,
72
72
  TIMEOUT_HEADER: () => TIMEOUT_HEADER,
73
+ accountChanges: () => accountChanges,
74
+ accountRuns: () => accountRuns,
73
75
  actions: () => actions,
74
76
  agentStart: () => agentStart,
75
77
  agentStatus: () => agentStatus,
76
78
  agentStop: () => agentStop,
77
79
  anythingStart: () => anythingStart,
80
+ attempts: () => attempts,
81
+ brandRetrieve: () => brandRetrieve,
78
82
  buildFetchScript: () => buildFetchScript,
83
+ changes: () => changes,
79
84
  checkForLatestVersion: () => checkForLatestVersion,
80
85
  client: () => client,
81
86
  connectLinkContext: () => connectLinkContext,
@@ -85,15 +90,23 @@ __export(index_exports, {
85
90
  connectLinkStatus: () => connectLinkStatus,
86
91
  connectLinkSubmit: () => connectLinkSubmit,
87
92
  connectPaymentWallet: () => connectPaymentWallet,
93
+ create: () => create,
88
94
  createClient: () => createClient2,
89
95
  createOrAppendCookiesToFile: () => createOrAppendCookiesToFile,
90
96
  createPayment: () => createPayment,
97
+ creditUsage: () => creditUsage,
91
98
  default: () => NotteClient3,
92
99
  deleteSecret: () => deleteSecret,
93
100
  deleteSessionFile: () => deleteSessionFile,
101
+ delete_: () => delete_,
102
+ deliveries: () => deliveries,
103
+ detail: () => detail,
94
104
  disconnectPaymentWallet: () => disconnectPaymentWallet,
95
105
  downloadRunPayload: () => downloadRunPayload,
96
106
  downloadSessionFile: () => downloadSessionFile,
107
+ executeSessionFile: () => executeSessionFile,
108
+ extractProductEndpoint: () => extractProductEndpoint,
109
+ fetchSpecializedData: () => fetchSpecializedData,
97
110
  functionCreate: () => functionCreate,
98
111
  functionDelete: () => functionDelete,
99
112
  functionDownloadUrl: () => functionDownloadUrl,
@@ -109,6 +122,7 @@ __export(index_exports, {
109
122
  functionScheduleSet: () => functionScheduleSet,
110
123
  functionUpdate: () => functionUpdate,
111
124
  getPayment: () => getPayment,
125
+ getPolicy: () => getPolicy,
112
126
  getRootDomain: () => getRootDomain,
113
127
  getScript: () => getScript,
114
128
  getSecret: () => getSecret,
@@ -116,13 +130,18 @@ __export(index_exports, {
116
130
  getUsage: () => getUsage,
117
131
  getUsageLogs: () => getUsageLogs,
118
132
  healthCheck: () => healthCheck,
133
+ history_: () => history_,
119
134
  installServerOwnedDialogPolicy: () => installServerOwnedDialogPolicy,
135
+ invalidate: () => invalidate,
120
136
  isCaptchaSolveAction: () => isCaptchaSolveAction,
121
137
  isValidMfaSecret: () => isValidMfaSecret,
138
+ limits: () => limits,
122
139
  listAgents: () => listAgents,
123
140
  listAuditEvents: () => listAuditEvents,
141
+ listDataApis: () => listDataApis,
124
142
  listFunctionRunsByFunctionId: () => listFunctionRunsByFunctionId,
125
143
  listFunctions: () => listFunctions,
144
+ listMonitors: () => listMonitors,
126
145
  listPersonas: () => listPersonas,
127
146
  listSecrets: () => listSecrets,
128
147
  listSessionFiles: () => listSessionFiles,
@@ -135,19 +154,20 @@ __export(index_exports, {
135
154
  mailboxSync: () => mailboxSync,
136
155
  mailboxUpdate: () => mailboxUpdate,
137
156
  managedAuthConnectLinkCreate: () => managedAuthConnectLinkCreate,
157
+ mapsSearch: () => mapsSearch,
158
+ newsSearch: () => newsSearch,
138
159
  observeServerOwnedDialog: () => observeServerOwnedDialog,
139
160
  pageExecute: () => pageExecute,
140
161
  pageObserve: () => pageObserve,
141
162
  pageScrape: () => pageScrape,
142
163
  pageScreenshot: () => pageScreenshot,
143
- parseAgentStatusMessage: () => parseAgentStatusMessage,
164
+ peopleEnrich: () => peopleEnrich,
144
165
  personaCreate: () => personaCreate,
145
166
  personaDelete: () => personaDelete,
146
167
  personaEmailsList: () => personaEmailsList,
147
168
  personaGet: () => personaGet,
148
169
  personaSmsList: () => personaSmsList,
149
170
  personaUpdate: () => personaUpdate,
150
- prepareAgentRequest: () => prepareAgentRequest,
151
171
  prepareRunPayloadUpload: () => prepareRunPayloadUpload,
152
172
  processScrapeResponse: () => processScrapeResponse,
153
173
  profileCookiesGet: () => profileCookiesGet,
@@ -157,18 +177,29 @@ __export(index_exports, {
157
177
  profileDuplicate: () => profileDuplicate,
158
178
  profileGet: () => profileGet,
159
179
  profileList: () => profileList,
180
+ profileStateSet: () => profileStateSet,
160
181
  readCookiesFile: () => readCookiesFile,
161
182
  readyCheck: () => readyCheck,
162
183
  responseFromEvaluated: () => responseFromEvaluated,
163
- retry: () => retry,
184
+ retrieve: () => retrieve,
185
+ retrieveChange: () => retrieveChange,
186
+ retrieveDelivery: () => retrieveDelivery,
187
+ retrieveRun: () => retrieveRun,
188
+ retry: () => retry2,
189
+ retryWebhookDelivery: () => retry,
190
+ rotateSecret: () => rotateSecret,
191
+ runNow: () => runNow,
192
+ runs: () => runs,
164
193
  sanitizeFilename: () => sanitizeFilename,
165
194
  scrapeFromHtml: () => scrapeFromHtml,
195
+ scrapeSpecializedData: () => fetchSpecializedData,
166
196
  scrapeWebpage: () => scrapeWebpage,
167
197
  searchWeb: () => searchWeb,
168
198
  sessionAuthReadiness: () => sessionAuthReadiness,
169
199
  sessionCookiesGet: () => sessionCookiesGet,
170
200
  sessionCookiesSet: () => sessionCookiesSet,
171
201
  sessionDebugInfo: () => sessionDebugInfo,
202
+ sessionMouseReplay: () => sessionMouseReplay,
172
203
  sessionNetworkLogs: () => sessionNetworkLogs,
173
204
  sessionOffset: () => sessionOffset,
174
205
  sessionProfilePreview: () => sessionProfilePreview,
@@ -179,6 +210,9 @@ __export(index_exports, {
179
210
  sessionStop: () => sessionStop,
180
211
  startVersionCheck: () => startVersionCheck,
181
212
  storeSecret: () => storeSecret,
213
+ styleguideEndpoint: () => styleguideEndpoint,
214
+ summary: () => summary,
215
+ update: () => update,
182
216
  uploadSessionFile: () => uploadSessionFile,
183
217
  validateCredentials: () => validateCredentials,
184
218
  validateMfaSecret: () => validateMfaSecret,
@@ -192,12 +226,13 @@ __export(index_exports, {
192
226
  vaultCreditCardGet: () => vaultCreditCardGet,
193
227
  vaultCreditCardSet: () => vaultCreditCardSet,
194
228
  vaultDelete: () => vaultDelete,
195
- vaultUpdate: () => vaultUpdate
229
+ vaultUpdate: () => vaultUpdate,
230
+ youtubeEndpoint: () => youtubeEndpoint
196
231
  });
197
232
  module.exports = __toCommonJS(index_exports);
198
233
 
199
234
  // src/version.ts
200
- var SDK_VERSION = true ? "1.9.7" : "dev";
235
+ var SDK_VERSION = true ? "1.10.1" : "dev";
201
236
  var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
202
237
 
203
238
  // src/version-check.ts
@@ -1081,6 +1116,11 @@ var createClient = (config = {}) => {
1081
1116
  const { opts, url } = await beforeRequest(options);
1082
1117
  return createSseClient({
1083
1118
  ...opts,
1119
+ // Request interceptors can replace fetch when the stream starts.
1120
+ fetch: (input, init) => {
1121
+ const transport = opts.fetch;
1122
+ return transport(input, init);
1123
+ },
1084
1124
  body: opts.body,
1085
1125
  method,
1086
1126
  onRequest: async (url2, init) => {
@@ -1168,11 +1208,6 @@ var sessionProfileSave = (options) => (options.client ?? client).post({
1168
1208
  ...options.headers
1169
1209
  }
1170
1210
  });
1171
- var getSessionScript = (options) => (options.client ?? client).get({
1172
- security: [{ scheme: "bearer", type: "http" }],
1173
- url: "/sessions/{session_id}/workflow/code",
1174
- ...options
1175
- });
1176
1211
  var sessionStop = (options) => (options.client ?? client).delete({
1177
1212
  security: [{ scheme: "bearer", type: "http" }],
1178
1213
  url: "/sessions/{session_id}/stop",
@@ -1239,11 +1274,25 @@ var sessionNetworkLogs = (options) => (options.client ?? client).get({
1239
1274
  url: "/sessions/{session_id}/network/logs",
1240
1275
  ...options
1241
1276
  });
1277
+ var sessionMouseReplay = (options) => (options.client ?? client).get({
1278
+ security: [{ scheme: "bearer", type: "http" }],
1279
+ url: "/sessions/{session_id}/replay/mouse",
1280
+ ...options
1281
+ });
1242
1282
  var sessionReplay = (options) => (options.client ?? client).get({
1243
1283
  security: [{ scheme: "bearer", type: "http" }],
1244
1284
  url: "/sessions/{session_id}/replay",
1245
1285
  ...options
1246
1286
  });
1287
+ var executeSessionFile = (options) => (options.client ?? client).post({
1288
+ security: [{ scheme: "bearer", type: "http" }],
1289
+ url: "/sessions/{session_id}/page/execute/file",
1290
+ ...options,
1291
+ headers: {
1292
+ "Content-Type": "application/json",
1293
+ ...options.headers
1294
+ }
1295
+ });
1247
1296
  var listSessionFiles = (options) => (options.client ?? client).get({
1248
1297
  security: [{ scheme: "bearer", type: "http" }],
1249
1298
  url: "/sessions/{session_id}/files",
@@ -1269,35 +1318,6 @@ var downloadSessionFile = (options) => (options.client ?? client).get({
1269
1318
  url: "/sessions/{session_id}/files/{file_id}",
1270
1319
  ...options
1271
1320
  });
1272
- var agentStart = (options) => (options.client ?? client).post({
1273
- security: [{ scheme: "bearer", type: "http" }],
1274
- url: "/agents/start",
1275
- ...options,
1276
- headers: {
1277
- "Content-Type": "application/json",
1278
- ...options.headers
1279
- }
1280
- });
1281
- var agentStatus = (options) => (options.client ?? client).get({
1282
- security: [{ scheme: "bearer", type: "http" }],
1283
- url: "/agents/{agent_id}",
1284
- ...options
1285
- });
1286
- var getScript = (options) => (options.client ?? client).get({
1287
- security: [{ scheme: "bearer", type: "http" }],
1288
- url: "/agents/{agent_id}/workflow/code",
1289
- ...options
1290
- });
1291
- var agentStop = (options) => (options.client ?? client).delete({
1292
- security: [{ scheme: "bearer", type: "http" }],
1293
- url: "/agents/{agent_id}/stop",
1294
- ...options
1295
- });
1296
- var listAgents = (options) => (options?.client ?? client).get({
1297
- security: [{ scheme: "bearer", type: "http" }],
1298
- url: "/agents",
1299
- ...options
1300
- });
1301
1321
  var functionRuntimeHealth = (options) => (options?.client ?? client).get({
1302
1322
  security: [{ scheme: "bearer", type: "http" }],
1303
1323
  url: "/functions/health",
@@ -1567,6 +1587,15 @@ var profileCookiesSet = (options) => (options.client ?? client).post({
1567
1587
  ...options.headers
1568
1588
  }
1569
1589
  });
1590
+ var profileStateSet = (options) => (options.client ?? client).post({
1591
+ security: [{ scheme: "bearer", type: "http" }],
1592
+ url: "/profiles/{profile_id}/state",
1593
+ ...options,
1594
+ headers: {
1595
+ "Content-Type": "application/json",
1596
+ ...options.headers
1597
+ }
1598
+ });
1570
1599
  var profileList = (options) => (options?.client ?? client).get({
1571
1600
  security: [{ scheme: "bearer", type: "http" }],
1572
1601
  url: "/profiles",
@@ -1761,6 +1790,215 @@ var searchWeb = (options) => (options.client ?? client).post({
1761
1790
  ...options.headers
1762
1791
  }
1763
1792
  });
1793
+ var summary = (options) => (options?.client ?? client).get({
1794
+ security: [{ scheme: "bearer", type: "http" }],
1795
+ url: "/data/analytics",
1796
+ ...options
1797
+ });
1798
+ var history_ = (options) => (options?.client ?? client).get({
1799
+ security: [{ scheme: "bearer", type: "http" }],
1800
+ url: "/data/analytics/requests",
1801
+ ...options
1802
+ });
1803
+ var detail = (options) => (options.client ?? client).get({
1804
+ security: [{ scheme: "bearer", type: "http" }],
1805
+ url: "/data/analytics/requests/{request_id}",
1806
+ ...options
1807
+ });
1808
+ var invalidate = (options) => (options?.client ?? client).delete({
1809
+ security: [{ scheme: "bearer", type: "http" }],
1810
+ url: "/data/cache",
1811
+ ...options
1812
+ });
1813
+ var getPolicy = (options) => (options?.client ?? client).get({
1814
+ security: [{ scheme: "bearer", type: "http" }],
1815
+ url: "/data/cache",
1816
+ ...options
1817
+ });
1818
+ var brandRetrieve = (options) => (options.client ?? client).post({
1819
+ security: [{ scheme: "bearer", type: "http" }],
1820
+ url: "/data/brand/retrieve",
1821
+ ...options,
1822
+ headers: {
1823
+ "Content-Type": "application/json",
1824
+ ...options.headers
1825
+ }
1826
+ });
1827
+ var extractProductEndpoint = (options) => (options.client ?? client).post({
1828
+ security: [{ scheme: "bearer", type: "http" }],
1829
+ url: "/data/products/extract",
1830
+ ...options,
1831
+ headers: {
1832
+ "Content-Type": "application/json",
1833
+ ...options.headers
1834
+ }
1835
+ });
1836
+ var styleguideEndpoint = (options) => (options?.client ?? client).get({
1837
+ security: [{ scheme: "bearer", type: "http" }],
1838
+ url: "/data/web/styleguide",
1839
+ ...options
1840
+ });
1841
+ var mapsSearch = (options) => (options.client ?? client).post({
1842
+ security: [{ scheme: "bearer", type: "http" }],
1843
+ url: "/data/maps/search",
1844
+ ...options,
1845
+ headers: {
1846
+ "Content-Type": "application/json",
1847
+ ...options.headers
1848
+ }
1849
+ });
1850
+ var listMonitors = (options) => (options?.client ?? client).get({
1851
+ security: [{ scheme: "bearer", type: "http" }],
1852
+ url: "/data/monitors",
1853
+ ...options
1854
+ });
1855
+ var create = (options) => (options.client ?? client).post({
1856
+ security: [{ scheme: "bearer", type: "http" }],
1857
+ url: "/data/monitors",
1858
+ ...options,
1859
+ headers: {
1860
+ "Content-Type": "application/json",
1861
+ ...options.headers
1862
+ }
1863
+ });
1864
+ var limits = (options) => (options?.client ?? client).get({
1865
+ security: [{ scheme: "bearer", type: "http" }],
1866
+ url: "/data/monitors/limits",
1867
+ ...options
1868
+ });
1869
+ var creditUsage = (options) => (options?.client ?? client).get({
1870
+ security: [{ scheme: "bearer", type: "http" }],
1871
+ url: "/data/monitors/credit-usage",
1872
+ ...options
1873
+ });
1874
+ var accountRuns = (options) => (options?.client ?? client).get({
1875
+ security: [{ scheme: "bearer", type: "http" }],
1876
+ url: "/data/monitors/runs",
1877
+ ...options
1878
+ });
1879
+ var accountChanges = (options) => (options?.client ?? client).get({
1880
+ security: [{ scheme: "bearer", type: "http" }],
1881
+ url: "/data/monitors/changes",
1882
+ ...options
1883
+ });
1884
+ var delete_ = (options) => (options.client ?? client).delete({
1885
+ security: [{ scheme: "bearer", type: "http" }],
1886
+ url: "/data/monitors/{monitor_id}",
1887
+ ...options
1888
+ });
1889
+ var retrieve = (options) => (options.client ?? client).get({
1890
+ security: [{ scheme: "bearer", type: "http" }],
1891
+ url: "/data/monitors/{monitor_id}",
1892
+ ...options
1893
+ });
1894
+ var update = (options) => (options.client ?? client).patch({
1895
+ security: [{ scheme: "bearer", type: "http" }],
1896
+ url: "/data/monitors/{monitor_id}",
1897
+ ...options,
1898
+ headers: {
1899
+ "Content-Type": "application/json",
1900
+ ...options.headers
1901
+ }
1902
+ });
1903
+ var runNow = (options) => (options.client ?? client).post({
1904
+ security: [{ scheme: "bearer", type: "http" }],
1905
+ url: "/data/monitors/{monitor_id}/run",
1906
+ ...options
1907
+ });
1908
+ var runs = (options) => (options.client ?? client).get({
1909
+ security: [{ scheme: "bearer", type: "http" }],
1910
+ url: "/data/monitors/{monitor_id}/runs",
1911
+ ...options
1912
+ });
1913
+ var changes = (options) => (options.client ?? client).get({
1914
+ security: [{ scheme: "bearer", type: "http" }],
1915
+ url: "/data/monitors/{monitor_id}/changes",
1916
+ ...options
1917
+ });
1918
+ var retrieveRun = (options) => (options.client ?? client).get({
1919
+ security: [{ scheme: "bearer", type: "http" }],
1920
+ url: "/data/monitors/{monitor_id}/runs/{run_id}",
1921
+ ...options
1922
+ });
1923
+ var retrieveChange = (options) => (options.client ?? client).get({
1924
+ security: [{ scheme: "bearer", type: "http" }],
1925
+ url: "/data/monitors/{monitor_id}/changes/{change_id}",
1926
+ ...options
1927
+ });
1928
+ var rotateSecret = (options) => (options.client ?? client).post({
1929
+ security: [{ scheme: "bearer", type: "http" }],
1930
+ url: "/data/monitors/{monitor_id}/webhook/rotate-secret",
1931
+ ...options
1932
+ });
1933
+ var deliveries = (options) => (options.client ?? client).post({
1934
+ security: [{ scheme: "bearer", type: "http" }],
1935
+ url: "/data/webhooks/deliveries",
1936
+ ...options,
1937
+ headers: {
1938
+ "Content-Type": "application/json",
1939
+ ...options.headers
1940
+ }
1941
+ });
1942
+ var retrieveDelivery = (options) => (options.client ?? client).get({
1943
+ security: [{ scheme: "bearer", type: "http" }],
1944
+ url: "/data/webhooks/deliveries/{delivery_id}",
1945
+ ...options
1946
+ });
1947
+ var attempts = (options) => (options.client ?? client).get({
1948
+ security: [{ scheme: "bearer", type: "http" }],
1949
+ url: "/data/webhooks/deliveries/{delivery_id}/attempts",
1950
+ ...options
1951
+ });
1952
+ var retry = (options) => (options.client ?? client).post({
1953
+ security: [{ scheme: "bearer", type: "http" }],
1954
+ url: "/data/webhooks/deliveries/{delivery_id}/retry",
1955
+ ...options,
1956
+ headers: {
1957
+ "Content-Type": "application/json",
1958
+ ...options.headers
1959
+ }
1960
+ });
1961
+ var peopleEnrich = (options) => (options.client ?? client).post({
1962
+ security: [{ scheme: "bearer", type: "http" }],
1963
+ url: "/data/people/enrich",
1964
+ ...options,
1965
+ headers: {
1966
+ "Content-Type": "application/json",
1967
+ ...options.headers
1968
+ }
1969
+ });
1970
+ var newsSearch = (options) => (options.client ?? client).post({
1971
+ security: [{ scheme: "bearer", type: "http" }],
1972
+ url: "/data/news/search",
1973
+ ...options,
1974
+ headers: {
1975
+ "Content-Type": "application/json",
1976
+ ...options.headers
1977
+ }
1978
+ });
1979
+ var fetchSpecializedData = (options) => (options.client ?? client).post({
1980
+ security: [{ scheme: "bearer", type: "http" }],
1981
+ url: "/data/web/fetch",
1982
+ ...options,
1983
+ headers: {
1984
+ "Content-Type": "application/json",
1985
+ ...options.headers
1986
+ }
1987
+ });
1988
+ var youtubeEndpoint = (options) => (options.client ?? client).post({
1989
+ security: [{ scheme: "bearer", type: "http" }],
1990
+ url: "/data/youtube/extract",
1991
+ ...options,
1992
+ headers: {
1993
+ "Content-Type": "application/json",
1994
+ ...options.headers
1995
+ }
1996
+ });
1997
+ var listDataApis = (options) => (options?.client ?? client).get({
1998
+ security: [{ scheme: "bearer", type: "http" }],
1999
+ url: "/data",
2000
+ ...options
2001
+ });
1764
2002
  var scrapeFromHtml = (options) => (options.client ?? client).post({
1765
2003
  security: [{ scheme: "bearer", type: "http" }],
1766
2004
  url: "/scrape_from_html",
@@ -1770,6 +2008,40 @@ var scrapeFromHtml = (options) => (options.client ?? client).post({
1770
2008
  ...options.headers
1771
2009
  }
1772
2010
  });
2011
+ var agentStart = (options) => (options.client ?? client).post({
2012
+ security: [{ scheme: "bearer", type: "http" }],
2013
+ url: "/agents/start",
2014
+ ...options,
2015
+ headers: {
2016
+ "Content-Type": "application/json",
2017
+ ...options.headers
2018
+ }
2019
+ });
2020
+ var agentStop = (options) => (options.client ?? client).delete({
2021
+ security: [{ scheme: "bearer", type: "http" }],
2022
+ url: "/agents/{agent_id}/stop",
2023
+ ...options
2024
+ });
2025
+ var agentStatus = (options) => (options.client ?? client).get({
2026
+ security: [{ scheme: "bearer", type: "http" }],
2027
+ url: "/agents/{agent_id}",
2028
+ ...options
2029
+ });
2030
+ var getScript = (options) => (options.client ?? client).get({
2031
+ security: [{ scheme: "bearer", type: "http" }],
2032
+ url: "/agents/{agent_id}/workflow/code",
2033
+ ...options
2034
+ });
2035
+ var listAgents = (options) => (options?.client ?? client).get({
2036
+ security: [{ scheme: "bearer", type: "http" }],
2037
+ url: "/agents",
2038
+ ...options
2039
+ });
2040
+ var getSessionScript = (options) => (options.client ?? client).get({
2041
+ security: [{ scheme: "bearer", type: "http" }],
2042
+ url: "/sessions/{session_id}/workflow/code",
2043
+ ...options
2044
+ });
1773
2045
 
1774
2046
  // src/managed-auth.ts
1775
2047
  var import_promises = require("timers/promises");
@@ -1854,14 +2126,14 @@ var ActionExecutionError = class _ActionExecutionError extends NotteError {
1854
2126
  agentMessage;
1855
2127
  shouldRetryLater;
1856
2128
  shouldNotifyTeam;
1857
- constructor(detail) {
1858
- super(detail.dev_message || detail.user_message || detail.error_type);
1859
- this.errorType = detail.error_type;
1860
- this.devMessage = detail.dev_message;
1861
- this.userMessage = detail.user_message;
1862
- this.agentMessage = detail.agent_message;
1863
- this.shouldRetryLater = detail.should_retry_later ?? false;
1864
- this.shouldNotifyTeam = detail.should_notify_team ?? false;
2129
+ constructor(detail2) {
2130
+ super(detail2.dev_message || detail2.user_message || detail2.error_type);
2131
+ this.errorType = detail2.error_type;
2132
+ this.devMessage = detail2.dev_message;
2133
+ this.userMessage = detail2.user_message;
2134
+ this.agentMessage = detail2.agent_message;
2135
+ this.shouldRetryLater = detail2.should_retry_later ?? false;
2136
+ this.shouldNotifyTeam = detail2.should_notify_team ?? false;
1865
2137
  }
1866
2138
  static fromMessage(message, errorType = "NotteBaseError") {
1867
2139
  return new _ActionExecutionError({
@@ -1892,7 +2164,7 @@ function normalizeErrorBody(body) {
1892
2164
  return { message: typeof body === "string" ? body : String(body) };
1893
2165
  }
1894
2166
  var DEFAULT_RETRY_MESSAGE = "An error occurred while executing the function. Try again later...";
1895
- function retry(fn, options) {
2167
+ function retry2(fn, options) {
1896
2168
  const {
1897
2169
  maxTries,
1898
2170
  delayMs = 5e3,
@@ -1929,11 +2201,6 @@ function sleep(ms) {
1929
2201
  // src/managed-auth.ts
1930
2202
  var ManagedAuthError = class extends NotteError {
1931
2203
  };
1932
- function validateAuthRetry(value) {
1933
- if (!Number.isInteger(value) || value < 0 || value > 2) {
1934
- throw new InvalidRequestError("auth_retry must be an integer between 0 and 2");
1935
- }
1936
- }
1937
2204
  async function pollAuth(read, options) {
1938
2205
  const timeoutMs = options.timeoutMs ?? 615e3;
1939
2206
  const interval = options.pollIntervalMs ?? 1e3;
@@ -1974,6 +2241,7 @@ var NotteManagedAuth = class {
1974
2241
  constructor(client2) {
1975
2242
  this.client = client2;
1976
2243
  }
2244
+ client;
1977
2245
  /** Run only the verifier; this does not submit login credentials. */
1978
2246
  async checkConnection(connectionId) {
1979
2247
  const response = await this.client.getClient().post({
@@ -2014,12 +2282,10 @@ var NotteManagedAuth = class {
2014
2282
  return this.run(connectionId, "reauthenticate", options);
2015
2283
  }
2016
2284
  async run(connectionId, action, options) {
2017
- const authRetry = options.auth_retry ?? 0;
2018
- validateAuthRetry(authRetry);
2019
2285
  options.signal?.throwIfAborted();
2020
2286
  const response = await this.client.getClient().post({
2021
2287
  url: `/managed-auth/connections/${encodeURIComponent(connectionId)}/${action}`,
2022
- body: { auth_retry: authRetry },
2288
+ body: { auth_retry: options.auth_retry },
2023
2289
  headers: { "Content-Type": "application/json" },
2024
2290
  signal: options.signal,
2025
2291
  throwOnError: true
@@ -2054,7 +2320,7 @@ function createResources(client2, getApiKey) {
2054
2320
  },
2055
2321
  /** downloadSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2056
2322
  downloadSessionFile: async (sessionId, fileId, requestOptions = {}) => {
2057
- const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2323
+ const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, parseAs: "blob", headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2058
2324
  return response.data;
2059
2325
  },
2060
2326
  /** pageExecute: /sessions/{session_id}/page/execute. Returns the API response body. */
@@ -2062,6 +2328,11 @@ function createResources(client2, getApiKey) {
2062
2328
  const response = await pageExecute({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2063
2329
  return response.data;
2064
2330
  },
2331
+ /** executeSessionFile: /sessions/{session_id}/page/execute/file. Returns the API response body. */
2332
+ executeSessionFile: async (sessionId, body, query = void 0, requestOptions = {}) => {
2333
+ const response = await executeSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2334
+ return response.data;
2335
+ },
2065
2336
  /** sessionCookiesGet: /sessions/{session_id}/cookies. Returns the API response body. */
2066
2337
  getCookies: async (sessionId, query = void 0, requestOptions = {}) => {
2067
2338
  const response = await sessionCookiesGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
@@ -2082,6 +2353,11 @@ function createResources(client2, getApiKey) {
2082
2353
  const response = await listSessionFiles({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2083
2354
  return response.data;
2084
2355
  },
2356
+ /** sessionMouseReplay: /sessions/{session_id}/replay/mouse. Returns the API response body. */
2357
+ mouseReplay: async (sessionId, query = void 0, requestOptions = {}) => {
2358
+ const response = await sessionMouseReplay({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2359
+ return response.data;
2360
+ },
2085
2361
  /** sessionNetworkLogs: /sessions/{session_id}/network/logs. Returns the API response body. */
2086
2362
  networkLogs: async (sessionId, query = void 0, requestOptions = {}) => {
2087
2363
  const response = await sessionNetworkLogs({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
@@ -2107,16 +2383,16 @@ function createResources(client2, getApiKey) {
2107
2383
  const response = await sessionProfilePreview({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2108
2384
  return response.data;
2109
2385
  },
2110
- /** sessionProfileSave: /sessions/{session_id}/profile/save. Returns the API response body. */
2111
- profileSave: async (sessionId, body, requestOptions = {}) => {
2112
- const response = await sessionProfileSave({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body });
2113
- return response.data;
2114
- },
2115
2386
  /** sessionReplay: /sessions/{session_id}/replay. Returns the API response body. */
2116
2387
  replay: async (sessionId, requestOptions = {}) => {
2117
2388
  const response = await sessionReplay({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId } });
2118
2389
  return response.data;
2119
2390
  },
2391
+ /** sessionProfileSave: /sessions/{session_id}/profile/save. Returns the API response body. */
2392
+ saveProfile: async (sessionId, body, requestOptions = {}) => {
2393
+ const response = await sessionProfileSave({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body });
2394
+ return response.data;
2395
+ },
2120
2396
  /** pageScrape: /sessions/{session_id}/page/scrape. Returns the API response body. */
2121
2397
  scrape: async (sessionId, body, query = void 0, requestOptions = {}) => {
2122
2398
  const response = await pageScrape({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
@@ -2129,6 +2405,9 @@ function createResources(client2, getApiKey) {
2129
2405
  },
2130
2406
  /** sessionStart: /sessions/start. Returns the API response body. */
2131
2407
  start: async (body, requestOptions = {}) => {
2408
+ body = { ...body };
2409
+ if (body.record_session === true) delete body.record_session;
2410
+ if (body.log_session === true) delete body.log_session;
2132
2411
  const response = await sessionStart({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2133
2412
  return response.data;
2134
2413
  },
@@ -2148,30 +2427,30 @@ function createResources(client2, getApiKey) {
2148
2427
  return response.data;
2149
2428
  }
2150
2429
  },
2151
- agents: {
2152
- /** getScript: /agents/{agent_id}/workflow/code. Returns the API response body. */
2153
- getScript: async (agentId, query, requestOptions = {}) => {
2154
- const response = await getScript({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId }, query });
2430
+ files: {
2431
+ /** deleteSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2432
+ delete: async (sessionId, fileId, requestOptions = {}) => {
2433
+ const response = await deleteSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2155
2434
  return response.data;
2156
2435
  },
2157
- /** listAgents: /agents. Returns the API response body. */
2158
- list: async (query = void 0, requestOptions = {}) => {
2159
- const response = await listAgents({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2436
+ /** downloadSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2437
+ download: async (sessionId, fileId, requestOptions = {}) => {
2438
+ const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, parseAs: "blob", headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2160
2439
  return response.data;
2161
2440
  },
2162
- /** agentStart: /agents/start. Returns the API response body. */
2163
- start: async (body, requestOptions = {}) => {
2164
- const response = await agentStart({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2441
+ /** executeSessionFile: /sessions/{session_id}/page/execute/file. Returns the API response body. */
2442
+ execute: async (sessionId, body, query = void 0, requestOptions = {}) => {
2443
+ const response = await executeSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2165
2444
  return response.data;
2166
2445
  },
2167
- /** agentStatus: /agents/{agent_id}. Returns the API response body. */
2168
- status: async (agentId, requestOptions = {}) => {
2169
- const response = await agentStatus({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId } });
2446
+ /** listSessionFiles: /sessions/{session_id}/files. Returns the API response body. */
2447
+ list: async (sessionId, query = void 0, requestOptions = {}) => {
2448
+ const response = await listSessionFiles({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2170
2449
  return response.data;
2171
2450
  },
2172
- /** agentStop: /agents/{agent_id}/stop. Returns the API response body. */
2173
- stop: async (agentId, query, requestOptions = {}) => {
2174
- const response = await agentStop({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId }, query });
2451
+ /** uploadSessionFile: /sessions/{session_id}/files. Returns the API response body. */
2452
+ upload: async (sessionId, body, requestOptions = {}) => {
2453
+ const response = await uploadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body });
2175
2454
  return response.data;
2176
2455
  }
2177
2456
  },
@@ -2252,8 +2531,8 @@ function createResources(client2, getApiKey) {
2252
2531
  return response.data;
2253
2532
  },
2254
2533
  /** functionRuntimeHealth: /functions/health. Returns the API response body. */
2255
- runtimeHealth: async (requestOptions = {}) => {
2256
- const response = await functionRuntimeHealth({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers } });
2534
+ runtimeHealth: async (requestOptions = {}, query = void 0) => {
2535
+ const response = await functionRuntimeHealth({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2257
2536
  return response.data;
2258
2537
  },
2259
2538
  /** functionScheduleSet: /functions/{function_id}/schedule. Returns the API response body. */
@@ -2267,6 +2546,43 @@ function createResources(client2, getApiKey) {
2267
2546
  return response.data;
2268
2547
  }
2269
2548
  },
2549
+ personas: {
2550
+ /** personaCreate: /personas/create. Returns the API response body. */
2551
+ create: async (body, requestOptions = {}) => {
2552
+ const response = await personaCreate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2553
+ return response.data;
2554
+ },
2555
+ /** personaDelete: /personas/{persona_id}. Returns the API response body. */
2556
+ delete: async (personaId, requestOptions = {}) => {
2557
+ const response = await personaDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2558
+ return response.data;
2559
+ },
2560
+ /** personaEmailsList: /personas/{persona_id}/emails. Returns the API response body. */
2561
+ emailsList: async (personaId, query = void 0, requestOptions = {}) => {
2562
+ const response = await personaEmailsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2563
+ return response.data;
2564
+ },
2565
+ /** personaGet: /personas/{persona_id}. Returns the API response body. */
2566
+ get: async (personaId, requestOptions = {}) => {
2567
+ const response = await personaGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2568
+ return response.data;
2569
+ },
2570
+ /** listPersonas: /personas. Returns the API response body. */
2571
+ list: async (query = void 0, requestOptions = {}) => {
2572
+ const response = await listPersonas({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2573
+ return response.data;
2574
+ },
2575
+ /** personaSmsList: /personas/{persona_id}/sms. Returns the API response body. */
2576
+ smsList: async (personaId, query = void 0, requestOptions = {}) => {
2577
+ const response = await personaSmsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2578
+ return response.data;
2579
+ },
2580
+ /** personaUpdate: /personas/{persona_id}. Returns the API response body. */
2581
+ update: async (personaId, body, requestOptions = {}) => {
2582
+ const response = await personaUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, body });
2583
+ return response.data;
2584
+ }
2585
+ },
2270
2586
  vaults: {
2271
2587
  /** vaultCreate: /vaults/create. Returns the API response body. */
2272
2588
  create: async (body, requestOptions = {}) => {
@@ -2310,54 +2626,17 @@ function createResources(client2, getApiKey) {
2310
2626
  },
2311
2627
  /** vaultDelete: /vaults/{vault_id}. Returns the API response body. */
2312
2628
  delete: async (vaultId, requestOptions = {}) => {
2313
- const response = await vaultDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId } });
2314
- return response.data;
2315
- },
2316
- /** listVaults: /vaults. Returns the API response body. */
2317
- list: async (query = void 0, requestOptions = {}) => {
2318
- const response = await listVaults({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2319
- return response.data;
2320
- },
2321
- /** vaultUpdate: /vaults/{vault_id}. Returns the API response body. */
2322
- update: async (vaultId, body, requestOptions = {}) => {
2323
- const response = await vaultUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId }, body });
2324
- return response.data;
2325
- }
2326
- },
2327
- personas: {
2328
- /** personaCreate: /personas/create. Returns the API response body. */
2329
- create: async (body, requestOptions = {}) => {
2330
- const response = await personaCreate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2331
- return response.data;
2332
- },
2333
- /** personaDelete: /personas/{persona_id}. Returns the API response body. */
2334
- delete: async (personaId, requestOptions = {}) => {
2335
- const response = await personaDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2336
- return response.data;
2337
- },
2338
- /** personaEmailsList: /personas/{persona_id}/emails. Returns the API response body. */
2339
- emailsList: async (personaId, query = void 0, requestOptions = {}) => {
2340
- const response = await personaEmailsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2341
- return response.data;
2342
- },
2343
- /** personaGet: /personas/{persona_id}. Returns the API response body. */
2344
- get: async (personaId, requestOptions = {}) => {
2345
- const response = await personaGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2629
+ const response = await vaultDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId } });
2346
2630
  return response.data;
2347
2631
  },
2348
- /** listPersonas: /personas. Returns the API response body. */
2632
+ /** listVaults: /vaults. Returns the API response body. */
2349
2633
  list: async (query = void 0, requestOptions = {}) => {
2350
- const response = await listPersonas({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2351
- return response.data;
2352
- },
2353
- /** personaSmsList: /personas/{persona_id}/sms. Returns the API response body. */
2354
- smsList: async (personaId, query = void 0, requestOptions = {}) => {
2355
- const response = await personaSmsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2634
+ const response = await listVaults({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2356
2635
  return response.data;
2357
2636
  },
2358
- /** personaUpdate: /personas/{persona_id}. Returns the API response body. */
2359
- update: async (personaId, body, requestOptions = {}) => {
2360
- const response = await personaUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, body });
2637
+ /** vaultUpdate: /vaults/{vault_id}. Returns the API response body. */
2638
+ update: async (vaultId, body, requestOptions = {}) => {
2639
+ const response = await vaultUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId }, body });
2361
2640
  return response.data;
2362
2641
  }
2363
2642
  },
@@ -2396,6 +2675,11 @@ function createResources(client2, getApiKey) {
2396
2675
  list: async (query = void 0, requestOptions = {}) => {
2397
2676
  const response = await profileList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2398
2677
  return response.data;
2678
+ },
2679
+ /** profileStateSet: /profiles/{profile_id}/state. Returns the API response body. */
2680
+ stateSet: async (profileId, body, requestOptions = {}) => {
2681
+ const response = await profileStateSet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "profile_id": profileId }, body });
2682
+ return response.data;
2399
2683
  }
2400
2684
  }
2401
2685
  };
@@ -2760,10 +3044,16 @@ async function createOrAppendCookiesToFile(cookieFile, cookies) {
2760
3044
  throw error;
2761
3045
  }
2762
3046
  }
2763
- existing.push(...cookies);
2764
- await (0, import_promises2.writeFile)(cookieFile, JSON.stringify(existing), "utf-8");
3047
+ const merged = /* @__PURE__ */ new Map();
3048
+ for (const cookie of [...existing, ...cookies]) {
3049
+ merged.set(cookieIdentity(cookie), cookie);
3050
+ }
3051
+ await (0, import_promises2.writeFile)(cookieFile, JSON.stringify([...merged.values()]), "utf-8");
2765
3052
  });
2766
3053
  }
3054
+ function cookieIdentity(cookie) {
3055
+ return JSON.stringify([cookie.name, cookie.domain ?? null, cookie.path ?? null, cookie.partitionKey ?? null]);
3056
+ }
2767
3057
  var fileLocks = /* @__PURE__ */ new Map();
2768
3058
  async function withFileLock(path, fn) {
2769
3059
  const key = (0, import_node_path.resolve)(path);
@@ -2922,8 +3212,8 @@ async function buildScrapeBody(options) {
2922
3212
  if (json_schema) {
2923
3213
  body.response_format = json_schema;
2924
3214
  } else {
2925
- const { z: z2 } = await import("zod");
2926
- body.response_format = normalizeJsonSchema(z2.toJSONSchema(response_format));
3215
+ const { z } = await import("zod");
3216
+ body.response_format = normalizeJsonSchema(z.toJSONSchema(response_format));
2927
3217
  }
2928
3218
  } else if (response_format) {
2929
3219
  body.response_format = response_format;
@@ -2935,9 +3225,6 @@ function processScrapeResponse(scrapeResponse, options) {
2935
3225
  throw new ScrapeFailedError("empty response");
2936
3226
  }
2937
3227
  const raiseOnFailure = options.raiseOnFailure ?? true;
2938
- if (options.only_images) {
2939
- return scrapeResponse.images ?? [];
2940
- }
2941
3228
  if (requiresSchema(options)) {
2942
3229
  const structured = scrapeResponse.structured;
2943
3230
  if (!structured) {
@@ -2960,10 +3247,126 @@ function processScrapeResponse(scrapeResponse, options) {
2960
3247
  return scrapeResponse.markdown;
2961
3248
  }
2962
3249
 
3250
+ // src/retry.ts
3251
+ var DEFAULT_MAX_RETRIES = 3;
3252
+ var RETRY_BASE_DELAY_MS = 1e3;
3253
+ var RETRY_MAX_DELAY_MS = 1e4;
3254
+ var RETRY_AFTER_MAX_MS = 2e4;
3255
+ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]);
3256
+ var REFUSED_STATUSES = /* @__PURE__ */ new Set([503, 529]);
3257
+ var GATEWAY_STATUSES = /* @__PURE__ */ new Set([502, 504]);
3258
+ var NOT_SENT_ERROR_CODES = /* @__PURE__ */ new Set([
3259
+ "ECONNREFUSED",
3260
+ "EAI_AGAIN",
3261
+ "ENETUNREACH",
3262
+ "EHOSTUNREACH",
3263
+ "UND_ERR_CONNECT_TIMEOUT"
3264
+ ]);
3265
+ var BROKEN_CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
3266
+ "ECONNRESET",
3267
+ "EPIPE",
3268
+ "ETIMEDOUT",
3269
+ "UND_ERR_SOCKET",
3270
+ "UND_ERR_CLOSED"
3271
+ ]);
3272
+ function isIdempotentMethod(method) {
3273
+ return IDEMPOTENT_METHODS.has(method.toUpperCase());
3274
+ }
3275
+ function isRetryableStatus(status, method) {
3276
+ return REFUSED_STATUSES.has(status) || GATEWAY_STATUSES.has(status) && isIdempotentMethod(method);
3277
+ }
3278
+ function isRetryableNetworkError(error, method) {
3279
+ const code = networkErrorCode(error);
3280
+ if (code === void 0) return false;
3281
+ return NOT_SENT_ERROR_CODES.has(code) || BROKEN_CONNECTION_ERROR_CODES.has(code) && isIdempotentMethod(method);
3282
+ }
3283
+ function networkErrorCode(error, depth = 0) {
3284
+ if (typeof error !== "object" || error === null || depth > 4) return void 0;
3285
+ const { code, cause, errors } = error;
3286
+ if (typeof code === "string") return code;
3287
+ if (Array.isArray(errors) && errors.length > 0) return networkErrorCode(errors[0], depth + 1);
3288
+ return networkErrorCode(cause, depth + 1);
3289
+ }
3290
+ function parseRetryAfter(header, now = Date.now()) {
3291
+ if (!header) return void 0;
3292
+ const value = header.trim();
3293
+ if (/^\d+(\.\d+)?$/.test(value)) return Number(value) * 1e3;
3294
+ const date = Date.parse(value);
3295
+ return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
3296
+ }
3297
+ function backoffDelayMs(attempt, random = Math.random) {
3298
+ return random() * Math.min(RETRY_MAX_DELAY_MS, RETRY_BASE_DELAY_MS * 2 ** attempt);
3299
+ }
3300
+ function retryDelayMs(attempt, retryAfter, random) {
3301
+ const requested = parseRetryAfter(retryAfter);
3302
+ if (requested === void 0) return backoffDelayMs(attempt, random);
3303
+ return requested <= RETRY_AFTER_MAX_MS ? requested : void 0;
3304
+ }
3305
+ function createRetryingFetch(options) {
3306
+ const wait2 = options.sleep ?? abortableSleep;
3307
+ return async (input, init) => {
3308
+ const baseFetch = options.fetch ?? globalThis.fetch;
3309
+ const request = input instanceof Request ? input : void 0;
3310
+ const method = (request?.method ?? init?.method ?? "GET").toUpperCase();
3311
+ const signal = init?.signal ?? request?.signal;
3312
+ const maxRetries = Math.max(0, Math.floor(options.maxRetries(signal) || 0));
3313
+ const send = (last) => request && request.body !== null && !last ? baseFetch(request.clone(), init) : baseFetch(input, init);
3314
+ for (let attempt = 0; ; attempt++) {
3315
+ const last = attempt >= maxRetries;
3316
+ let response;
3317
+ try {
3318
+ response = await send(last);
3319
+ } catch (error) {
3320
+ if (last || !isRetryableNetworkError(error, method)) throw error;
3321
+ const delay4 = backoffDelayMs(attempt, options.random);
3322
+ if (!fitsDeadline(delay4)) throw error;
3323
+ warn(`${method} request failed (${networkErrorCode(error)})`, delay4, attempt, maxRetries);
3324
+ await wait2(delay4, signal);
3325
+ continue;
3326
+ }
3327
+ if (last || !isRetryableStatus(response.status, method)) return response;
3328
+ const delay3 = retryDelayMs(attempt, response.headers.get("retry-after"), options.random);
3329
+ if (delay3 === void 0 || !fitsDeadline(delay3)) return response;
3330
+ await response.body?.cancel().catch(() => void 0);
3331
+ warn(`${method} request returned ${response.status}`, delay3, attempt, maxRetries);
3332
+ await wait2(delay3, signal);
3333
+ }
3334
+ function fitsDeadline(delay3) {
3335
+ const deadline = options.deadline?.(signal);
3336
+ return deadline === void 0 || Date.now() + delay3 < deadline;
3337
+ }
3338
+ };
3339
+ }
3340
+ function warn(reason, delay3, attempt, maxRetries) {
3341
+ console.warn(`${reason}, retrying in ${(delay3 / 1e3).toFixed(1)}s (${attempt + 1}/${maxRetries})`);
3342
+ }
3343
+ function abortableSleep(ms, signal) {
3344
+ return new Promise((resolve3, reject) => {
3345
+ if (signal?.aborted) {
3346
+ reject(signal.reason);
3347
+ return;
3348
+ }
3349
+ const onAbort = () => {
3350
+ clearTimeout(timer);
3351
+ reject(signal?.reason);
3352
+ };
3353
+ const timer = setTimeout(() => {
3354
+ signal?.removeEventListener("abort", onAbort);
3355
+ resolve3();
3356
+ }, ms);
3357
+ signal?.addEventListener("abort", onAbort, { once: true });
3358
+ });
3359
+ }
3360
+
2963
3361
  // src/session.ts
2964
3362
  var SESSION_START_TRIES = 3;
2965
3363
  var CLUSTER_OVERLOAD_RETRY_DELAY_MS = 3e4;
2966
3364
  var CAPTCHA_SOLVE_TIMEOUT_MS = 1e5;
3365
+ var OBSERVE_MIGRATION_URL = "https://docs.notte.cc/features/sessions/observe-migration";
3366
+ var OBSERVE_DEPRECATIONS = {
3367
+ instructions: `\`observe({ instructions })\` is deprecated and will be removed on December 1, 2026; <<ALTERNATIVE FOR instructions: session.act() \u2014 pending>>. See ${OBSERVE_MIGRATION_URL}`,
3368
+ deep: `\`perception_type: 'deep'\` is deprecated and will be removed on December 1, 2026; use \`perception_type: 'fast'\` (the default). See ${OBSERVE_MIGRATION_URL}`
3369
+ };
2967
3370
  function observeServerOwnedDialog(_dialog) {
2968
3371
  }
2969
3372
  function installServerOwnedDialogPolicy(browser) {
@@ -2978,6 +3381,7 @@ var Session = class {
2978
3381
  legacyHeadless;
2979
3382
  defaultRaiseOnFailure;
2980
3383
  defaultPerceptionType;
3384
+ warnedObserveDeprecations = /* @__PURE__ */ new Set();
2981
3385
  cookieFile;
2982
3386
  cookiesLoaded = false;
2983
3387
  cookieLoadPromise;
@@ -3013,9 +3417,11 @@ var Session = class {
3013
3417
  /**
3014
3418
  * Start the session: creates a new session on the server.
3015
3419
  *
3016
- * Retries up to `SESSION_START_TRIES` times on 5xx errors, waiting
3017
- * `CLUSTER_OVERLOAD_RETRY_DELAY_MS` on HTTP 529 (cluster overload). 4xx
3018
- * errors are never retried.
3420
+ * 503, 529, and refused connections follow the client's retry policy
3421
+ * (`NotteClientConfig.maxRetries`, honoring `Retry-After`). Other 5xx
3422
+ * errors are retried up to `SESSION_START_TRIES` times. With client
3423
+ * retries disabled, 529 waits `CLUSTER_OVERLOAD_RETRY_DELAY_MS` instead.
3424
+ * 4xx errors are never retried.
3019
3425
  *
3020
3426
  * Managed-auth sessions wait for readiness by default. Pass
3021
3427
  * `{ wait_for_authentication: false }` for an explicit nonblocking start,
@@ -3028,11 +3434,6 @@ var Session = class {
3028
3434
  * await session.start();
3029
3435
  */
3030
3436
  async start(options = {}) {
3031
- if (this.legacyHeadless === false) {
3032
- throw new Error(
3033
- "Remote `headless: false` is no longer supported. `headless: true` sessions still include session replays and access to the live viewer."
3034
- );
3035
- }
3036
3437
  if (this.legacyHeadless === true) {
3037
3438
  console.warn("`headless: true` is deprecated and ignored; remote sessions always use the supported browser launch mode.");
3038
3439
  this.legacyHeadless = void 0;
@@ -3041,42 +3442,62 @@ var Session = class {
3041
3442
  throw new Error("Session is already active");
3042
3443
  }
3043
3444
  options.signal?.throwIfAborted();
3044
- validateAuthRetry(this.options.auth_retry ?? 0);
3045
3445
  const { auth_retry, wait_for_authentication, ...request } = this.options;
3046
3446
  const body = {
3047
3447
  ...request,
3048
- ...request.auth_ids?.length ? { auth_retry: auth_retry ?? 0, wait_for_authentication: false } : {}
3448
+ ...this.legacyHeadless !== void 0 ? { headless: this.legacyHeadless } : {},
3449
+ ...auth_retry !== void 0 ? { auth_retry } : {},
3450
+ ...request.auth_ids?.length ? { wait_for_authentication: false } : {}
3049
3451
  };
3452
+ if (body.record_session === true) delete body.record_session;
3453
+ if (body.log_session === true) delete body.log_session;
3050
3454
  const shouldWait = options.wait_for_authentication ?? wait_for_authentication ?? true;
3455
+ const maxRetries = this.client.getConfig().maxRetries ?? 0;
3456
+ const timeoutMs = this.client.getConfig().timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
3457
+ const deadline = timeoutMs > 0 ? Date.now() + timeoutMs : void 0;
3458
+ const fitsDeadline = (wait2) => deadline === void 0 || Date.now() + wait2 < deadline;
3459
+ let transientRetries = 0;
3051
3460
  let tries = SESSION_START_TRIES;
3052
3461
  const origTries = tries;
3053
3462
  let sessionData;
3054
3463
  while (tries > 0) {
3055
3464
  options.signal?.throwIfAborted();
3056
- tries -= 1;
3465
+ if (!fitsDeadline(0)) throw new NotteTimeoutError(`Session start timed out after ${timeoutMs}ms`);
3057
3466
  try {
3058
- const response = await sessionStart({ client: this.client.getClient(), body, throwOnError: true });
3467
+ const response = await sessionStart({
3468
+ client: this.client.getClient(),
3469
+ body,
3470
+ throwOnError: true,
3471
+ headers: {
3472
+ [MAX_RETRIES_HEADER]: "0",
3473
+ ...deadline === void 0 ? {} : { [TIMEOUT_HEADER]: String(Math.max(1, deadline - Date.now())) }
3474
+ }
3475
+ });
3059
3476
  sessionData = response.data;
3060
3477
  break;
3061
3478
  } catch (error) {
3479
+ const transient = error instanceof NotteAPIError ? isRetryableStatus(error.statusCode, "POST") : isRetryableNetworkError(error, "POST");
3480
+ if (maxRetries > 0 && transient) {
3481
+ const wait2 = transientRetries >= maxRetries ? void 0 : error instanceof NotteAPIError ? retryDelayMs(transientRetries, error.response?.headers.get("retry-after")) : backoffDelayMs(transientRetries);
3482
+ if (wait2 === void 0 || !fitsDeadline(wait2)) throw error;
3483
+ transientRetries += 1;
3484
+ console.warn(
3485
+ `Failed to start session (${error instanceof NotteAPIError ? error.statusCode : "connection error"}), retrying in ${(wait2 / 1e3).toFixed(1)}s (${transientRetries}/${maxRetries})`
3486
+ );
3487
+ await pauseStart(wait2, options.signal);
3488
+ continue;
3489
+ }
3490
+ tries -= 1;
3062
3491
  if (tries === 0 || !(error instanceof NotteAPIError) || error.statusCode < 500) {
3063
3492
  throw error;
3064
3493
  }
3065
3494
  const retryStr = `${origTries - tries}/${origTries - 1}`;
3495
+ if (!fitsDeadline(error.statusCode === 529 ? CLUSTER_OVERLOAD_RETRY_DELAY_MS : 0)) throw error;
3066
3496
  if (error.statusCode === 529) {
3067
3497
  console.warn(
3068
3498
  `Failed to start session due to cluster overload, retrying in ${CLUSTER_OVERLOAD_RETRY_DELAY_MS / 1e3} seconds (${retryStr})...`
3069
3499
  );
3070
- if (options.signal) {
3071
- try {
3072
- await (0, import_promises4.setTimeout)(CLUSTER_OVERLOAD_RETRY_DELAY_MS, void 0, { signal: options.signal });
3073
- } catch (error2) {
3074
- options.signal.throwIfAborted();
3075
- throw error2;
3076
- }
3077
- } else {
3078
- await sleep(CLUSTER_OVERLOAD_RETRY_DELAY_MS);
3079
- }
3500
+ await pauseStart(CLUSTER_OVERLOAD_RETRY_DELAY_MS, options.signal);
3080
3501
  } else {
3081
3502
  console.warn(`Failed to start session: retrying (${retryStr})`);
3082
3503
  }
@@ -3094,6 +3515,7 @@ var Session = class {
3094
3515
  this.fileStorage = this.fileStorage?.forSession(sessionData.session_id);
3095
3516
  try {
3096
3517
  options.signal?.throwIfAborted();
3518
+ if (!fitsDeadline(0)) throw new NotteTimeoutError(`Session start timed out after ${timeoutMs}ms`);
3097
3519
  if (shouldWait) await this.waitForAuth(options);
3098
3520
  if (this.openViewer) {
3099
3521
  this.openViewerInBrowser();
@@ -3330,7 +3752,11 @@ var Session = class {
3330
3752
  if (!(error instanceof NotteAPIError) || error.statusCode !== 404) {
3331
3753
  throw error;
3332
3754
  }
3333
- if (this.isActive && (error.apiMessage ?? "").includes("still active")) {
3755
+ const waitingForClose = error.error.replay_status === "waiting_for_session";
3756
+ if (error.error.replay_status === "disabled" || error.error.retryable === false && !waitingForClose) {
3757
+ throw error;
3758
+ }
3759
+ if (this.isActive && this.sessionId === sessionId && (waitingForClose || (error.apiMessage ?? "").includes("still active"))) {
3334
3760
  throw new Error(`Session ${sessionId} is still active \u2014 close the session first to generate the replay.`, {
3335
3761
  cause: error
3336
3762
  });
@@ -3418,9 +3844,7 @@ var Session = class {
3418
3844
  * start-time profile settings are not changed, so a session started with `persist: true`
3419
3845
  * still saves again when it stops.
3420
3846
  *
3421
- * @example
3422
- * const profile = await session.saveProfile({ name: 'github' });
3423
- * // later: client.Session({ profile: { id: profile.profile_id } })
3847
+ * See [Browser Profiles](/features/sessions/browser-profiles) for the tested Python and TypeScript example.
3424
3848
  */
3425
3849
  async saveProfile(options = {}) {
3426
3850
  const { profile_id, name } = options;
@@ -3653,19 +4077,30 @@ var Session = class {
3653
4077
  * The `perception_type` defaults to the session option (`fast`). A bare
3654
4078
  * string argument is accepted as the perception type.
3655
4079
  *
4080
+ * Deprecated: `perception_type: 'deep'` and `instructions` are removed on
4081
+ * December 1, 2026, and each warns once per session. Use `perception_type:
4082
+ * 'fast'` (the default) instead of `'deep'`. For `instructions`:
4083
+ * `<<ALTERNATIVE FOR instructions: session.act() — pending>>`. See https://docs.notte.cc/features/sessions/observe-migration
4084
+ *
3656
4085
  * @param options - Observation settings, including an optional URL, or a perception-mode string.
3657
4086
  * @returns Structured page analysis, available actions, and page metadata.
3658
4087
  * @throws NotteAPIError if observation fails.
3659
4088
  * @example
3660
4089
  * const obs = await session.observe();
3661
4090
  * console.log(obs.space.description);
3662
- * const deep = await session.observe({ perception_type: 'deep', max_nb_actions: 50 });
4091
+ * const firstActions = await session.observe({ max_nb_actions: 50 });
3663
4092
  */
3664
4093
  async observe(options = {}) {
3665
4094
  const body = typeof options === "string" ? { perception_type: options } : { ...options };
3666
4095
  if (body.perception_type == null) {
3667
4096
  body.perception_type = this.defaultPerceptionType;
3668
4097
  }
4098
+ if (body.instructions != null) {
4099
+ this.warnObserveDeprecation("instructions");
4100
+ }
4101
+ if (body.perception_type !== "fast") {
4102
+ this.warnObserveDeprecation("deep");
4103
+ }
3669
4104
  const response = await pageObserve({
3670
4105
  client: this.client.getClient(),
3671
4106
  path: { session_id: this.requireSessionId() },
@@ -3674,6 +4109,12 @@ var Session = class {
3674
4109
  });
3675
4110
  return response.data;
3676
4111
  }
4112
+ warnObserveDeprecation(option) {
4113
+ if (!this.warnedObserveDeprecations.has(option)) {
4114
+ this.warnedObserveDeprecations.add(option);
4115
+ console.warn(OBSERVE_DEPRECATIONS[option]);
4116
+ }
4117
+ }
3677
4118
  async scrape(options = {}) {
3678
4119
  const sessionId = this.requireSessionId();
3679
4120
  const body = await buildScrapeBody(options);
@@ -3741,424 +4182,18 @@ var Session = class {
3741
4182
  }
3742
4183
  }
3743
4184
  };
3744
-
3745
- // src/agent.ts
3746
- var import_ws = __toESM(require("ws"));
3747
- var import_zod = require("zod");
3748
- function prepareAgentRequest(data) {
3749
- const apiData = { ...data };
3750
- const rf = data.response_format;
3751
- if (rf && typeof rf.parse === "function" && typeof rf.safeParse === "function") {
3752
- apiData.response_format = normalizeJsonSchema(import_zod.z.toJSONSchema(rf));
3753
- return { apiData, zodSchema: rf };
3754
- }
3755
- return { apiData, zodSchema: null };
3756
- }
3757
- function parseAgentStatusMessage(parsed, agentId) {
3758
- if (parsed?.status === "agent_stop" && parsed.agent && parsed.agent.agent_id === agentId && parsed.agent.task !== void 0 && parsed.agent.status !== void 0) {
3759
- return parsed.agent;
3760
- }
3761
- if (parsed?.agent_id === agentId && parsed.task !== void 0 && parsed.status !== void 0) {
3762
- return parsed;
3763
- }
3764
- return null;
3765
- }
3766
- function validatePersonaOption(persona, persona_id) {
3767
- if (persona) {
3768
- try {
3769
- const personaId = persona.personaId;
3770
- if (!personaId || personaId.length === 0) {
3771
- throw new Error("Persona ID cannot be empty");
3772
- }
3773
- return personaId;
3774
- } catch (error) {
3775
- throw new Error(`Invalid persona object: ${error instanceof Error ? error.message : String(error)}`);
3776
- }
3777
- } else if (persona_id) {
3778
- if (persona_id.length === 0) {
3779
- throw new Error("Persona ID cannot be empty");
3780
- }
3781
- return persona_id;
3782
- }
3783
- return void 0;
3784
- }
3785
- function validateVaultOption(vault, vault_id) {
3786
- if (vault) {
3787
- try {
3788
- const vaultId = vault.vaultId;
3789
- if (!vaultId || vaultId.length === 0) {
3790
- throw new Error("Vault ID cannot be empty");
3791
- }
3792
- return vaultId;
3793
- } catch (error) {
3794
- throw new Error(`Invalid vault object: ${error instanceof Error ? error.message : String(error)}`);
3795
- }
3796
- } else if (vault_id) {
3797
- if (vault_id.length === 0) {
3798
- throw new Error("Vault ID cannot be empty");
3799
- }
3800
- return vault_id;
3801
- }
3802
- return void 0;
3803
- }
3804
- function validateSessionOption(session) {
3805
- const sessionId = session.getId();
3806
- if (!sessionId || sessionId.length === 0) {
3807
- throw new Error("Session ID cannot be empty");
4185
+ async function pauseStart(ms, signal) {
4186
+ if (!signal) {
4187
+ await sleep(ms);
4188
+ return;
3808
4189
  }
3809
- return sessionId;
3810
- }
3811
- function validateAgentIdOption(agent_id) {
3812
- if (agent_id.length === 0) {
3813
- throw new Error("Agent ID cannot be empty");
4190
+ try {
4191
+ await (0, import_promises4.setTimeout)(ms, void 0, { signal });
4192
+ } catch (error) {
4193
+ signal.throwIfAborted();
4194
+ throw error;
3814
4195
  }
3815
4196
  }
3816
- var defaultStepLogger = (stepData, stepCounter, agentId) => {
3817
- console.log(`\u2728 Step ${stepCounter} (agent: ${agentId})`);
3818
- if (stepData && typeof stepData === "object") {
3819
- if (stepData.state) {
3820
- const state = stepData.state;
3821
- if (state.page_summary) {
3822
- console.log(`\u{1F4DD} Current page: ${state.page_summary}`);
3823
- }
3824
- if (state.previous_goal_eval) {
3825
- const statusEmoji = state.previous_goal_status === "success" ? "\u2705" : state.previous_goal_status === "failure" ? "\u274C" : "\u2753";
3826
- console.log(`\u{1F52C} Previous goal: ${statusEmoji} ${state.previous_goal_eval}`);
3827
- }
3828
- if (state.memory) {
3829
- console.log(`\u{1F9E0} Memory: ${state.memory}`);
3830
- }
3831
- if (state.next_goal) {
3832
- console.log(`\u{1F3AF} Next goal: ${state.next_goal}`);
3833
- }
3834
- if (state.relevant_interactions && state.relevant_interactions.length > 0) {
3835
- console.log(`\u{1F194} Relevant ids:`);
3836
- state.relevant_interactions.forEach((interaction) => {
3837
- console.log(` \u25B6 ${interaction.id}: ${interaction.reason}`);
3838
- });
3839
- }
3840
- }
3841
- if (stepData.action) {
3842
- const action = stepData.action;
3843
- let actionStr = `\u26A1 Taking action:
3844
- \u25B6 ${action.name || action.type || "Unknown action"}`;
3845
- if (action.id) {
3846
- actionStr += ` with id ${action.id}`;
3847
- } else if (action.param && action.param.name && action[action.param.name]) {
3848
- actionStr += ` with ${action.param.name}=${action[action.param.name]}`;
3849
- }
3850
- console.log(actionStr);
3851
- }
3852
- } else {
3853
- console.log(stepData);
3854
- }
3855
- console.log("");
3856
- };
3857
- var Agent = class {
3858
- client;
3859
- request;
3860
- response = null;
3861
- websocket = null;
3862
- existingAgent;
3863
- constructor(client2, options) {
3864
- this.client = client2;
3865
- if ("agent_id" in options && options.agent_id) {
3866
- if (options.session) {
3867
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided, not both");
3868
- }
3869
- validateAgentIdOption(options.agent_id);
3870
- this.existingAgent = true;
3871
- this.response = { agent_id: options.agent_id };
3872
- } else if ("session" in options && options.session) {
3873
- if (options.agent_id) {
3874
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided, not both");
3875
- }
3876
- this.existingAgent = false;
3877
- const { session, vault, persona, ...requestData } = options;
3878
- const sessionId = validateSessionOption(session);
3879
- const vaultId = validateVaultOption(vault, options.vault_id);
3880
- const personaId = validatePersonaOption(persona, options.persona_id);
3881
- this.request = {
3882
- session_id: sessionId,
3883
- vault_id: vaultId,
3884
- persona_id: personaId,
3885
- ...requestData
3886
- };
3887
- } else {
3888
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided");
3889
- }
3890
- }
3891
- async start(data) {
3892
- if (this.existingAgent) {
3893
- throw new Error("You cannot call start() on an agent instantiated from agent id");
3894
- }
3895
- if (!this.request) {
3896
- throw new Error("Agent not properly initialized with session");
3897
- }
3898
- try {
3899
- const { apiData } = prepareAgentRequest(data);
3900
- const requestBody = {
3901
- ...this.request,
3902
- ...apiData
3903
- };
3904
- const response = await agentStart({
3905
- client: this.client.getClient(),
3906
- body: requestBody
3907
- });
3908
- if (response?.error) {
3909
- throw new Error(`Failed to start agent: ${formatError(response.error)}`);
3910
- }
3911
- this.response = response.data;
3912
- return this.response;
3913
- } catch (error) {
3914
- throw new Error(`Failed to start agent: ${error instanceof Error ? error.message : String(error)}`);
3915
- }
3916
- }
3917
- async run(data) {
3918
- if (this.existingAgent) {
3919
- throw new Error("You cannot call run() on an agent instantiated from agent id");
3920
- }
3921
- const { apiData, zodSchema } = prepareAgentRequest(data);
3922
- this.response = await this.start(apiData);
3923
- console.log(`[Agent] ${this.agentId} started`);
3924
- const result = await this.watchLogsAndWait(true, data.updateHandler || null);
3925
- if (zodSchema && result && result.answer !== void 0 && result.answer !== null) {
3926
- let candidate;
3927
- try {
3928
- candidate = typeof result.answer === "string" ? JSON.parse(result.answer) : result.answer;
3929
- } catch {
3930
- throw new Error(`Agent answer is not valid JSON and cannot be validated against the schema`);
3931
- }
3932
- try {
3933
- result.answer = zodSchema.parse(candidate);
3934
- } catch (error) {
3935
- throw new Error(`Agent answer schema validation failed: ${error instanceof Error ? error.message : String(error)}`);
3936
- }
3937
- }
3938
- return result;
3939
- }
3940
- /**
3941
- * Watch logs and wait for completion - mirrors Python watch_logs_and_wait
3942
- */
3943
- async watchLogsAndWait(log = true, updateHandler = null) {
3944
- if (this.existingAgent) {
3945
- throw new Error("You cannot call watchLogsAndWait() on an agent instantiated from agent id");
3946
- }
3947
- if (!this.response) {
3948
- throw new Error("Agent not started");
3949
- }
3950
- const deadline = Date.now() + 3e5;
3951
- try {
3952
- const result = await this.watchLogs(log, updateHandler, deadline);
3953
- if (result && result.status !== "active") {
3954
- return result;
3955
- }
3956
- } catch (error) {
3957
- console.warn(`[Agent] ${this.agentId} log stream unavailable; polling for completion.`);
3958
- }
3959
- while (Date.now() < deadline) {
3960
- const result = await this.status(AbortSignal.timeout(Math.max(1, deadline - Date.now())));
3961
- if (result.status !== "active") {
3962
- updateHandler?.({ type: "completion", data: result, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
3963
- return result;
3964
- }
3965
- await new Promise((resolve3) => setTimeout(resolve3, 1e3));
3966
- }
3967
- throw new Error(`Agent ${this.agentId} did not complete before the polling timeout; retrieve status() later.`);
3968
- }
3969
- /**
3970
- * Watch logs via WebSocket - mirrors Python watch_logs method
3971
- */
3972
- async watchLogs(log = true, updateHandler = null, deadline = Date.now() + 3e5) {
3973
- if (this.existingAgent) {
3974
- throw new Error("You cannot call watchLogs() on an agent instantiated from agent id");
3975
- }
3976
- if (!this.response) {
3977
- throw new Error("Agent not started");
3978
- }
3979
- const config = this.client.getConfig();
3980
- if (config.baseUrl?.startsWith("/")) return null;
3981
- const agentId = this.response.agent_id;
3982
- const sessionId = this.response.session_id;
3983
- const debug = await sessionDebugInfo({
3984
- client: this.client.getClient(),
3985
- path: { session_id: sessionId },
3986
- throwOnError: true,
3987
- signal: AbortSignal.timeout(Math.max(1, deadline - Date.now()))
3988
- });
3989
- const wsUrl = new URL(this.client.withDbPreview(debug.data.ws.logs));
3990
- const token = wsUrl.searchParams.get("token");
3991
- if (!token || token === config.apiKey || wsUrl.protocol !== "wss:") return null;
3992
- wsUrl.pathname = `/agents/${encodeURIComponent(agentId)}/debug/logs`;
3993
- wsUrl.searchParams.set("session_id", sessionId);
3994
- return new Promise((resolve3, reject) => {
3995
- this.websocket = new import_ws.default(wsUrl);
3996
- const socket = this.websocket;
3997
- const timeout = setTimeout(() => finish(null), Math.max(0, deadline - Date.now()));
3998
- let settled = false;
3999
- const finish = (result) => {
4000
- if (settled) return;
4001
- settled = true;
4002
- clearTimeout(timeout);
4003
- if (this.websocket === socket) this.websocket = null;
4004
- if (socket.readyState !== import_ws.default.CLOSED) socket.terminate();
4005
- resolve3(result);
4006
- };
4007
- let counter = 0;
4008
- this.websocket.on("open", () => {
4009
- });
4010
- this.websocket.on("error", (error) => {
4011
- console.error(`Connection error: ${agentId} ${error.message}`);
4012
- finish(null);
4013
- });
4014
- this.websocket.on("message", (data) => {
4015
- try {
4016
- const message = data.toString();
4017
- let parsed;
4018
- try {
4019
- parsed = JSON.parse(message);
4020
- } catch {
4021
- return;
4022
- }
4023
- const finalStatus = parseAgentStatusMessage(parsed, agentId);
4024
- if (finalStatus) {
4025
- if (updateHandler) {
4026
- updateHandler({
4027
- type: "completion",
4028
- data: finalStatus,
4029
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
4030
- });
4031
- } else if (!finalStatus.success) {
4032
- console.error(finalStatus.answer);
4033
- }
4034
- finish(finalStatus);
4035
- return;
4036
- }
4037
- if (log) {
4038
- counter++;
4039
- if (updateHandler) {
4040
- updateHandler({
4041
- type: "step",
4042
- data: parsed,
4043
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
4044
- });
4045
- } else {
4046
- defaultStepLogger(parsed, counter, agentId);
4047
- }
4048
- }
4049
- } catch (error) {
4050
- console.error(`Error processing WebSocket message: ${error}`);
4051
- }
4052
- });
4053
- this.websocket.on("close", () => {
4054
- finish(null);
4055
- });
4056
- });
4057
- }
4058
- /**
4059
- * Get agent status - mirrors Python status method
4060
- */
4061
- async status(signal) {
4062
- if (!this.response) {
4063
- throw new Error("Agent not started or not accessible");
4064
- }
4065
- const response = await agentStatus({
4066
- client: this.client.getClient(),
4067
- signal,
4068
- path: {
4069
- agent_id: this.response.agent_id
4070
- }
4071
- });
4072
- if (response?.error) {
4073
- throw new Error(`Failed to get agent status: ${formatError(response.error)}`);
4074
- }
4075
- return response.data;
4076
- }
4077
- /**
4078
- * Stop the agent - mirrors Python stop method
4079
- */
4080
- async stop() {
4081
- if (this.existingAgent) {
4082
- throw new Error("You cannot call stop() on an agent instantiated from agent id");
4083
- }
4084
- if (!this.response) {
4085
- throw new Error("Agent not started");
4086
- }
4087
- try {
4088
- console.log(`[Agent] ${this.response.agent_id} is stopping`);
4089
- const response = await agentStop({
4090
- client: this.client.getClient(),
4091
- path: {
4092
- agent_id: this.response.agent_id
4093
- },
4094
- query: { session_id: this.response.session_id }
4095
- });
4096
- if (response?.error) {
4097
- throw new Error(`Failed to stop agent: ${formatError(response.error)}`);
4098
- }
4099
- console.log(`[Agent] ${this.response.agent_id} stopped`);
4100
- return response.data;
4101
- } catch (error) {
4102
- console.warn(`Failed to stop agent: ${error instanceof Error ? error.message : String(error)}`);
4103
- throw error;
4104
- } finally {
4105
- this.disconnectWebSocket();
4106
- }
4107
- }
4108
- /**
4109
- * Disconnect WebSocket
4110
- */
4111
- disconnectWebSocket() {
4112
- if (this.websocket) {
4113
- this.websocket.close();
4114
- this.websocket = null;
4115
- }
4116
- }
4117
- /**
4118
- * Get agent ID - mirrors Python agent_id property
4119
- */
4120
- get agentId() {
4121
- if (!this.response) {
4122
- throw new Error("You need to run the agent first to get the agent id");
4123
- }
4124
- return this.response.agent_id;
4125
- }
4126
- /**
4127
- * Get session ID - mirrors Python session_id property
4128
- */
4129
- get sessionId() {
4130
- if (!this.response) {
4131
- throw new Error("You need to run the agent first to get the session id");
4132
- }
4133
- return this.response.session_id;
4134
- }
4135
- /**
4136
- * Whether `start()`/`run()` was called on this instance (or it was built from an agent id).
4137
- * This is a local check and does not contact the API.
4138
- */
4139
- hasStarted() {
4140
- return this.response !== null;
4141
- }
4142
- /**
4143
- * Whether the agent is still active on the server. Fetches the current status,
4144
- * like calling `agent.status()` in Python; an agent that was never started is not active.
4145
- */
4146
- async isActive() {
4147
- if (!this.response) {
4148
- return false;
4149
- }
4150
- const status = await this.status();
4151
- return status.status === "active";
4152
- }
4153
- /**
4154
- * @deprecated Only reports whether this instance was started; it does not
4155
- * contact the API. Use `hasStarted()` for that check or `isActive()` for the
4156
- * live server status.
4157
- */
4158
- isRunning() {
4159
- return this.hasStarted();
4160
- }
4161
- };
4162
4197
 
4163
4198
  // src/vaults.ts
4164
4199
  var import_tldts = require("tldts");
@@ -4318,9 +4353,9 @@ var NotteVault = class {
4318
4353
  await this.delete();
4319
4354
  }
4320
4355
  /**
4321
- * Add or update the credentials stored for a website. The URL is reduced to
4322
- * its root domain (`https://github.com/login` → `github.com`) before it is
4323
- * sent, like Python's `AddCredentialsRequest`.
4356
+ * Add or update the credentials stored for a website. Values are sent as
4357
+ * supplied; the API validates credentials and reduces the URL to its root
4358
+ * domain (`https://github.com/login` → `github.com`).
4324
4359
  *
4325
4360
  * ```ts
4326
4361
  * await vault.addCredentials('https://github.com/', {
@@ -4331,13 +4366,11 @@ var NotteVault = class {
4331
4366
  * ```
4332
4367
  */
4333
4368
  async addCredentials(url, credentials) {
4334
- const domain = validateUrl(url);
4335
- validateCredentials(credentials);
4336
4369
  const vaultId = await this.ensureInitialized();
4337
4370
  await vaultCredentialsAdd({
4338
4371
  client: this.client.getClient(),
4339
4372
  path: { vault_id: vaultId },
4340
- body: { url: domain, credentials },
4373
+ body: { url, credentials },
4341
4374
  throwOnError: true
4342
4375
  });
4343
4376
  }
@@ -4351,12 +4384,11 @@ var NotteVault = class {
4351
4384
  * ```
4352
4385
  */
4353
4386
  async getCredentials(url) {
4354
- const domain = validateUrl(url);
4355
4387
  const vaultId = await this.ensureInitialized();
4356
4388
  const response = await vaultCredentialsGet({
4357
4389
  client: this.client.getClient(),
4358
4390
  path: { vault_id: vaultId },
4359
- query: { url: domain },
4391
+ query: { url },
4360
4392
  throwOnError: true
4361
4393
  });
4362
4394
  return response.data.credentials;
@@ -4384,12 +4416,11 @@ var NotteVault = class {
4384
4416
  * ```
4385
4417
  */
4386
4418
  async deleteCredentials(url) {
4387
- const domain = validateUrl(url);
4388
4419
  const vaultId = await this.ensureInitialized();
4389
4420
  await vaultCredentialsDelete({
4390
4421
  client: this.client.getClient(),
4391
4422
  path: { vault_id: vaultId },
4392
- query: { url: domain },
4423
+ query: { url },
4393
4424
  throwOnError: true
4394
4425
  });
4395
4426
  }
@@ -4434,7 +4465,7 @@ var NotteVault = class {
4434
4465
  * ```
4435
4466
  */
4436
4467
  async addCredentialsFromEnv(url) {
4437
- const rootDomain = validateUrl(url);
4468
+ const rootDomain = getRootDomain(url);
4438
4469
  const prefix = rootDomain.replace(/\./g, "_").toUpperCase();
4439
4470
  const credentials = {};
4440
4471
  const variableNames = [];
@@ -4510,6 +4541,10 @@ var NotteVault = class {
4510
4541
  };
4511
4542
 
4512
4543
  // src/personas.ts
4544
+ function withPersonaDefaults(persona) {
4545
+ if (!persona || persona.email_provider) return persona;
4546
+ return { ...persona, email_provider: "notte" };
4547
+ }
4513
4548
  var NottePersona = class {
4514
4549
  client;
4515
4550
  _initRequest;
@@ -4569,7 +4604,7 @@ var NottePersona = class {
4569
4604
  if (response?.error) {
4570
4605
  throw new Error(`Failed to get persona: ${formatError(response.error)}`);
4571
4606
  }
4572
- this.response = response.data;
4607
+ this.response = withPersonaDefaults(response.data);
4573
4608
  return this.response;
4574
4609
  }
4575
4610
  async initNewPersona(createData) {
@@ -4580,7 +4615,7 @@ var NottePersona = class {
4580
4615
  if (response?.error) {
4581
4616
  throw new Error(`Failed to create persona: ${formatError(response.error)}`);
4582
4617
  }
4583
- this.response = response.data;
4618
+ this.response = withPersonaDefaults(response.data);
4584
4619
  console.warn(
4585
4620
  `[Persona] ${this.response.persona_id} created since no persona id was provided. Please store this to retrieve it later.`
4586
4621
  );
@@ -4809,11 +4844,10 @@ async function offloadRunPayloads(client2, path, fields) {
4809
4844
  if (payload.length > MAX_PAYLOAD_BYTES) throw new Error(`Function run ${field} exceeds the payload limit`);
4810
4845
  if (payload.length <= INLINE_FIELD_BYTES) continue;
4811
4846
  const checksum = (0, import_node_crypto2.createHash)("sha256").update(payload).digest("base64");
4812
- const prepared = await client2.post({
4813
- url: "/functions/{function_id}/runs/{run_id}/payloads/{field}/upload",
4847
+ const prepared = await prepareRunPayloadUpload({
4848
+ client: client2,
4814
4849
  path: { ...path, field },
4815
4850
  body: { size_bytes: payload.length, sha256: checksum },
4816
- headers: { "Content-Type": "application/json" },
4817
4851
  throwOnError: true
4818
4852
  });
4819
4853
  const upload = prepared.data;
@@ -4889,7 +4923,6 @@ var FUNCTION_RUN_ENDPOINTS = {
4889
4923
  start: "/functions/{function_id}/runs/{run_id}"
4890
4924
  };
4891
4925
  var RUN_API_KEY_HEADER = "x-notte-api-key";
4892
- var FUNCTION_RUNTIMES = ["standard", "extended"];
4893
4926
  var FUNCTION_RUN_STATUSES = ["closed", "active", "failed"];
4894
4927
  var NotteFunction = class {
4895
4928
  client;
@@ -4992,7 +5025,7 @@ var NotteFunction = class {
4992
5025
  throwOnError: true,
4993
5026
  path: { function_id: functionId },
4994
5027
  query: {
4995
- restricted: options.restricted ?? true,
5028
+ restricted: options.restricted,
4996
5029
  ...options.version !== void 0 ? { version: options.version } : {}
4997
5030
  },
4998
5031
  body: { file }
@@ -5089,7 +5122,7 @@ var NotteFunction = class {
5089
5122
  client: this.client.getClient(),
5090
5123
  throwOnError: true,
5091
5124
  path: { function_id: functionId },
5092
- query: { restricted: options.restricted ?? true },
5125
+ query: { restricted: options.restricted },
5093
5126
  body: { version: options.version }
5094
5127
  });
5095
5128
  return response.data;
@@ -5185,7 +5218,7 @@ var NotteFunction = class {
5185
5218
  client: this.client.getClient(),
5186
5219
  throwOnError: true,
5187
5220
  path: { function_id: functionId },
5188
- query: { ...options, only_active: options.only_active ?? false }
5221
+ query: options
5189
5222
  });
5190
5223
  return response.data;
5191
5224
  }
@@ -5218,9 +5251,6 @@ var NotteFunction = class {
5218
5251
  if (!(timeoutMs > 0)) {
5219
5252
  throw new InvalidRequestError("timeoutMs must be a positive number");
5220
5253
  }
5221
- if (options.runtime !== void 0 && !FUNCTION_RUNTIMES.includes(options.runtime)) {
5222
- throw new InvalidRequestError(`runtime must be one of ${FUNCTION_RUNTIMES.join(", ")}, got '${String(options.runtime)}'`);
5223
- }
5224
5254
  const functionId = await this.ensureInitialized();
5225
5255
  const functionRunId = options.functionRunId ?? (await this.createRun()).function_run_id;
5226
5256
  const body = {
@@ -5535,6 +5565,8 @@ var SessionFiles = class {
5535
5565
  this.client = client2;
5536
5566
  this.sessionId = sessionId;
5537
5567
  }
5568
+ client;
5569
+ sessionId;
5538
5570
  /**
5539
5571
  * Upload bytes as a session file. `filename` is what the browser sees when
5540
5572
  * the file is later attached to a page.
@@ -5563,7 +5595,7 @@ var SessionFiles = class {
5563
5595
  const response = await listSessionFiles({
5564
5596
  client: this.client,
5565
5597
  path: { session_id: this.sessionId },
5566
- query: { limit: options.limit ?? 100, offset: options.offset ?? 0, source: options.source },
5598
+ query: options,
5567
5599
  throwOnError: true
5568
5600
  });
5569
5601
  return response.data;
@@ -5639,6 +5671,7 @@ var RemoteFileStorage = class _RemoteFileStorage {
5639
5671
  this.client = client2;
5640
5672
  this._sessionId = sessionId ?? null;
5641
5673
  }
5674
+ client;
5642
5675
  _sessionId;
5643
5676
  /** Bind the storage to a session. Called by `Session.start()` when the storage was passed to the session. */
5644
5677
  setSessionId(sessionId) {
@@ -5972,6 +6005,7 @@ var DEFAULT_NOTTE_API_URL = "https://api.notte.cc";
5972
6005
  var DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
5973
6006
  var REQUEST_ORIGIN = "sdk-node";
5974
6007
  var TIMEOUT_HEADER = "x-notte-timeout-ms";
6008
+ var MAX_RETRIES_HEADER = "x-notte-max-retries";
5975
6009
  var DB_PREVIEW_ENV = "NOTTE_DB_PREVIEW_BRANCH";
5976
6010
  var DB_PREVIEW_HEADER = "x-db-preview";
5977
6011
  var EXECUTION_ERROR_CLASS = "NotteApiExecutionError";
@@ -5994,6 +6028,10 @@ var NotteClient3 = class {
5994
6028
  if (!(timeoutMs >= 0)) {
5995
6029
  throw new InvalidRequestError("timeoutMs must be a non-negative number");
5996
6030
  }
6031
+ const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
6032
+ if (!Number.isInteger(maxRetries) || maxRetries < 0) {
6033
+ throw new InvalidRequestError("maxRetries must be a non-negative integer");
6034
+ }
5997
6035
  const isProxyMode = isRelativeProxyUrl(baseUrl);
5998
6036
  if (!isProxyMode) {
5999
6037
  const url = new URL(baseUrl);
@@ -6009,7 +6047,15 @@ var NotteClient3 = class {
6009
6047
  "NOTTE_API_KEY needs to be provided. Pass config.apiKey or set the NOTTE_API_KEY environment variable."
6010
6048
  );
6011
6049
  }
6012
- this.config = { baseUrl, apiKey, timeoutMs, captchaTimeoutSeconds, dbPreview, verbose: config.verbose ?? false };
6050
+ this.config = {
6051
+ baseUrl,
6052
+ apiKey,
6053
+ timeoutMs,
6054
+ captchaTimeoutSeconds,
6055
+ dbPreview,
6056
+ maxRetries,
6057
+ verbose: config.verbose ?? false
6058
+ };
6013
6059
  if (baseUrl !== DEFAULT_NOTTE_API_URL && !isProxyMode) {
6014
6060
  console.warn(`NOTTE_API_URL is set to: ${baseUrl}`);
6015
6061
  }
@@ -6018,7 +6064,7 @@ var NotteClient3 = class {
6018
6064
  redirect: "manual",
6019
6065
  throwOnError: true
6020
6066
  });
6021
- this.client.interceptors.request.use((request) => {
6067
+ this.client.interceptors.request.use((request, opts) => {
6022
6068
  const headers = new Headers(request.headers);
6023
6069
  if (this.config.apiKey) headers.set("Authorization", `Bearer ${this.config.apiKey}`);
6024
6070
  headers.set("x-notte-request-origin", REQUEST_ORIGIN);
@@ -6026,16 +6072,25 @@ var NotteClient3 = class {
6026
6072
  if (this.config.dbPreview) headers.set(DB_PREVIEW_HEADER, this.config.dbPreview);
6027
6073
  const override = headers.get(TIMEOUT_HEADER);
6028
6074
  headers.delete(TIMEOUT_HEADER);
6075
+ const retriesOverride = headers.get(MAX_RETRIES_HEADER);
6076
+ headers.delete(MAX_RETRIES_HEADER);
6029
6077
  const timeoutMs2 = override !== null ? Number(override) : this.config.timeoutMs;
6030
6078
  if (this.config.verbose) {
6031
6079
  console.info(`Making \`${request.method}\` request to \`${request.url}\``);
6032
6080
  }
6033
- if (!(timeoutMs2 > 0)) {
6034
- return new Request(request, { headers });
6035
- }
6036
- const deadline = withTimeout(request.signal, timeoutMs2);
6037
- const timed = new Request(request, { headers, signal: deadline.signal });
6038
- pendingDeadlines.set(timed, deadline.release);
6081
+ const callerSignal = opts.signal ?? request.signal;
6082
+ const deadline = timeoutMs2 > 0 ? withTimeout(callerSignal, timeoutMs2) : void 0;
6083
+ const signal = deadline?.signal ?? callerSignal;
6084
+ const timed = new Request(request, { headers, signal });
6085
+ pendingRequests.set(timed, { signal, release: deadline?.release ?? (() => void 0), expiresAt: deadline?.expiresAt ?? Infinity });
6086
+ const transport = originalTransports.get(opts) ?? opts.fetch ?? globalThis.fetch;
6087
+ originalTransports.set(opts, transport);
6088
+ const retrying = createRetryingFetch({
6089
+ fetch: transport,
6090
+ maxRetries: () => retriesOverride !== null ? Number(retriesOverride) : this.config.maxRetries,
6091
+ deadline: () => deadline?.expiresAt
6092
+ });
6093
+ opts.fetch = (input, init) => retrying(input, { ...init, signal });
6039
6094
  return timed;
6040
6095
  });
6041
6096
  this.client.interceptors.response.use(async (response, request, opts) => {
@@ -6073,7 +6128,7 @@ var NotteClient3 = class {
6073
6128
  method: request.method,
6074
6129
  headers: headerRecord,
6075
6130
  body: opts.serializedBody ?? void 0,
6076
- signal: request.signal,
6131
+ signal: requestSignal(request),
6077
6132
  redirect: "manual"
6078
6133
  });
6079
6134
  currentUrl = location;
@@ -6121,14 +6176,15 @@ var NotteClient3 = class {
6121
6176
  if (error instanceof NotteAPIError) {
6122
6177
  return error;
6123
6178
  }
6124
- if (request?.signal.aborted) {
6125
- error = request.signal.reason ?? error;
6179
+ const signal = request && requestSignal(request);
6180
+ if (signal?.aborted) {
6181
+ error = signal.reason ?? error;
6126
6182
  }
6127
6183
  if (isTimeoutAbort(error)) {
6128
6184
  const target = request ? ` to \`${requestPath(request)}\`` : "";
6129
6185
  return new NotteTimeoutError(`Request${target} ${error.message}`, { cause: error });
6130
6186
  }
6131
- if (request?.signal.aborted) return error;
6187
+ if (signal?.aborted) return error;
6132
6188
  if (response) {
6133
6189
  const path = requestPath(request, response);
6134
6190
  const body = normalizeErrorBody(error);
@@ -6178,6 +6234,10 @@ var NotteClient3 = class {
6178
6234
  Session(options = {}) {
6179
6235
  return new Session(this, options);
6180
6236
  }
6237
+ /** Generated file operations; use Files(sessionId) for local file IO helpers. */
6238
+ get files() {
6239
+ return this.resources.files;
6240
+ }
6181
6241
  /** Access files owned by a specific session, including closed sessions. */
6182
6242
  Files(sessionId) {
6183
6243
  return new SessionFiles(this.getClient(), sessionId);
@@ -6196,12 +6256,6 @@ var NotteClient3 = class {
6196
6256
  FileStorage(sessionId) {
6197
6257
  return new RemoteFileStorage(this, sessionId);
6198
6258
  }
6199
- /**
6200
- * Create a new agent
6201
- */
6202
- Agent(options) {
6203
- return new Agent(this, options);
6204
- }
6205
6259
  /**
6206
6260
  * Create or access a vault
6207
6261
  */
@@ -6234,16 +6288,6 @@ var NotteClient3 = class {
6234
6288
  }
6235
6289
  };
6236
6290
  }
6237
- /** Client-bound agent API operations. `list()` retains its array return value. */
6238
- get agents() {
6239
- return {
6240
- ...this.resources.agents,
6241
- list: async (options = {}) => {
6242
- const response = await listAgents({ client: this.getClient(), query: options });
6243
- return response.data?.items ?? [];
6244
- }
6245
- };
6246
- }
6247
6291
  /** Client-bound vault API operations. `list()` retains its array return value. */
6248
6292
  get vaults() {
6249
6293
  return {
@@ -6292,14 +6336,18 @@ var NotteClient3 = class {
6292
6336
  * Personas client for listing and managing personas
6293
6337
  */
6294
6338
  get personas() {
6339
+ const personas = this.resources.personas;
6295
6340
  return {
6296
- ...this.resources.personas,
6341
+ ...personas,
6342
+ create: async (...args) => withPersonaDefaults(await personas.create(...args)),
6343
+ get: async (...args) => withPersonaDefaults(await personas.get(...args)),
6344
+ update: async (...args) => withPersonaDefaults(await personas.update(...args)),
6297
6345
  list: async (options) => {
6298
6346
  const response = await listPersonas({
6299
6347
  client: this.getClient(),
6300
6348
  query: options || {}
6301
6349
  });
6302
- return response.data?.items || [];
6350
+ return (response.data?.items || []).map(withPersonaDefaults);
6303
6351
  }
6304
6352
  };
6305
6353
  }
@@ -6345,18 +6393,18 @@ function isTimeoutAbort(error) {
6345
6393
  function timeoutReason(timeoutMs) {
6346
6394
  return new DOMException(`timed out after ${timeoutMs}ms`, "TimeoutError");
6347
6395
  }
6348
- var pendingDeadlines = /* @__PURE__ */ new WeakMap();
6396
+ var pendingRequests = /* @__PURE__ */ new WeakMap();
6397
+ var originalTransports = /* @__PURE__ */ new WeakMap();
6398
+ function requestSignal(request) {
6399
+ return pendingRequests.get(request)?.signal ?? request.signal;
6400
+ }
6349
6401
  function releaseDeadline(request) {
6350
- if (!request) return;
6351
- const release = pendingDeadlines.get(request);
6352
- if (release) {
6353
- pendingDeadlines.delete(request);
6354
- release();
6355
- }
6402
+ if (request) pendingRequests.get(request)?.release();
6356
6403
  }
6357
6404
  function withTimeout(signal, timeoutMs) {
6358
6405
  const controller = new AbortController();
6359
6406
  const timer = setTimeout(() => controller.abort(timeoutReason(timeoutMs)), timeoutMs);
6407
+ const expiresAt = Date.now() + timeoutMs;
6360
6408
  timer.unref?.();
6361
6409
  let detach = () => void 0;
6362
6410
  let composite;
@@ -6383,7 +6431,7 @@ function withTimeout(signal, timeoutMs) {
6383
6431
  detach();
6384
6432
  };
6385
6433
  composite.addEventListener("abort", release, { once: true });
6386
- return { signal: composite, release };
6434
+ return { signal: composite, release, expiresAt };
6387
6435
  }
6388
6436
 
6389
6437
  // src/actions.ts
@@ -6477,11 +6525,11 @@ var createClient2 = (config) => {
6477
6525
  // Annotate the CommonJS export names for ESM import in node:
6478
6526
  0 && (module.exports = {
6479
6527
  ActionExecutionError,
6480
- Agent,
6481
6528
  AuthenticationError,
6482
6529
  CAPTCHA_SOLVE_TIMEOUT_MS,
6483
6530
  CLUSTER_OVERLOAD_RETRY_DELAY_MS,
6484
6531
  CREDENTIAL_FIELDS,
6532
+ DEFAULT_MAX_RETRIES,
6485
6533
  DEFAULT_NOTTE_API_URL,
6486
6534
  DEFAULT_REQUEST_TIMEOUT_MS,
6487
6535
  Encryption,
@@ -6516,12 +6564,17 @@ var createClient2 = (config) => {
6516
6564
  Session,
6517
6565
  SessionFiles,
6518
6566
  TIMEOUT_HEADER,
6567
+ accountChanges,
6568
+ accountRuns,
6519
6569
  actions,
6520
6570
  agentStart,
6521
6571
  agentStatus,
6522
6572
  agentStop,
6523
6573
  anythingStart,
6574
+ attempts,
6575
+ brandRetrieve,
6524
6576
  buildFetchScript,
6577
+ changes,
6525
6578
  checkForLatestVersion,
6526
6579
  client,
6527
6580
  connectLinkContext,
@@ -6531,14 +6584,22 @@ var createClient2 = (config) => {
6531
6584
  connectLinkStatus,
6532
6585
  connectLinkSubmit,
6533
6586
  connectPaymentWallet,
6587
+ create,
6534
6588
  createClient,
6535
6589
  createOrAppendCookiesToFile,
6536
6590
  createPayment,
6591
+ creditUsage,
6537
6592
  deleteSecret,
6538
6593
  deleteSessionFile,
6594
+ delete_,
6595
+ deliveries,
6596
+ detail,
6539
6597
  disconnectPaymentWallet,
6540
6598
  downloadRunPayload,
6541
6599
  downloadSessionFile,
6600
+ executeSessionFile,
6601
+ extractProductEndpoint,
6602
+ fetchSpecializedData,
6542
6603
  functionCreate,
6543
6604
  functionDelete,
6544
6605
  functionDownloadUrl,
@@ -6554,6 +6615,7 @@ var createClient2 = (config) => {
6554
6615
  functionScheduleSet,
6555
6616
  functionUpdate,
6556
6617
  getPayment,
6618
+ getPolicy,
6557
6619
  getRootDomain,
6558
6620
  getScript,
6559
6621
  getSecret,
@@ -6561,13 +6623,18 @@ var createClient2 = (config) => {
6561
6623
  getUsage,
6562
6624
  getUsageLogs,
6563
6625
  healthCheck,
6626
+ history_,
6564
6627
  installServerOwnedDialogPolicy,
6628
+ invalidate,
6565
6629
  isCaptchaSolveAction,
6566
6630
  isValidMfaSecret,
6631
+ limits,
6567
6632
  listAgents,
6568
6633
  listAuditEvents,
6634
+ listDataApis,
6569
6635
  listFunctionRunsByFunctionId,
6570
6636
  listFunctions,
6637
+ listMonitors,
6571
6638
  listPersonas,
6572
6639
  listSecrets,
6573
6640
  listSessionFiles,
@@ -6580,19 +6647,20 @@ var createClient2 = (config) => {
6580
6647
  mailboxSync,
6581
6648
  mailboxUpdate,
6582
6649
  managedAuthConnectLinkCreate,
6650
+ mapsSearch,
6651
+ newsSearch,
6583
6652
  observeServerOwnedDialog,
6584
6653
  pageExecute,
6585
6654
  pageObserve,
6586
6655
  pageScrape,
6587
6656
  pageScreenshot,
6588
- parseAgentStatusMessage,
6657
+ peopleEnrich,
6589
6658
  personaCreate,
6590
6659
  personaDelete,
6591
6660
  personaEmailsList,
6592
6661
  personaGet,
6593
6662
  personaSmsList,
6594
6663
  personaUpdate,
6595
- prepareAgentRequest,
6596
6664
  prepareRunPayloadUpload,
6597
6665
  processScrapeResponse,
6598
6666
  profileCookiesGet,
@@ -6602,18 +6670,29 @@ var createClient2 = (config) => {
6602
6670
  profileDuplicate,
6603
6671
  profileGet,
6604
6672
  profileList,
6673
+ profileStateSet,
6605
6674
  readCookiesFile,
6606
6675
  readyCheck,
6607
6676
  responseFromEvaluated,
6677
+ retrieve,
6678
+ retrieveChange,
6679
+ retrieveDelivery,
6680
+ retrieveRun,
6608
6681
  retry,
6682
+ retryWebhookDelivery,
6683
+ rotateSecret,
6684
+ runNow,
6685
+ runs,
6609
6686
  sanitizeFilename,
6610
6687
  scrapeFromHtml,
6688
+ scrapeSpecializedData,
6611
6689
  scrapeWebpage,
6612
6690
  searchWeb,
6613
6691
  sessionAuthReadiness,
6614
6692
  sessionCookiesGet,
6615
6693
  sessionCookiesSet,
6616
6694
  sessionDebugInfo,
6695
+ sessionMouseReplay,
6617
6696
  sessionNetworkLogs,
6618
6697
  sessionOffset,
6619
6698
  sessionProfilePreview,
@@ -6624,6 +6703,9 @@ var createClient2 = (config) => {
6624
6703
  sessionStop,
6625
6704
  startVersionCheck,
6626
6705
  storeSecret,
6706
+ styleguideEndpoint,
6707
+ summary,
6708
+ update,
6627
6709
  uploadSessionFile,
6628
6710
  validateCredentials,
6629
6711
  validateMfaSecret,
@@ -6637,6 +6719,7 @@ var createClient2 = (config) => {
6637
6719
  vaultCreditCardGet,
6638
6720
  vaultCreditCardSet,
6639
6721
  vaultDelete,
6640
- vaultUpdate
6722
+ vaultUpdate,
6723
+ youtubeEndpoint
6641
6724
  });
6642
6725
  //# sourceMappingURL=index.js.map