notte-sdk 1.9.6 → 1.10.0

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,
119
- improvePrompt: () => improvePrompt,
133
+ history_: () => history_,
120
134
  installServerOwnedDialogPolicy: () => installServerOwnedDialogPolicy,
135
+ invalidate: () => invalidate,
121
136
  isCaptchaSolveAction: () => isCaptchaSolveAction,
122
137
  isValidMfaSecret: () => isValidMfaSecret,
138
+ limits: () => limits,
123
139
  listAgents: () => listAgents,
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,20 +154,20 @@ __export(index_exports, {
135
154
  mailboxSync: () => mailboxSync,
136
155
  mailboxUpdate: () => mailboxUpdate,
137
156
  managedAuthConnectLinkCreate: () => managedAuthConnectLinkCreate,
138
- nudgePrompt: () => nudgePrompt,
157
+ mapsSearch: () => mapsSearch,
158
+ newsSearch: () => newsSearch,
139
159
  observeServerOwnedDialog: () => observeServerOwnedDialog,
140
160
  pageExecute: () => pageExecute,
141
161
  pageObserve: () => pageObserve,
142
162
  pageScrape: () => pageScrape,
143
163
  pageScreenshot: () => pageScreenshot,
144
- parseAgentStatusMessage: () => parseAgentStatusMessage,
164
+ peopleEnrich: () => peopleEnrich,
145
165
  personaCreate: () => personaCreate,
146
166
  personaDelete: () => personaDelete,
147
167
  personaEmailsList: () => personaEmailsList,
148
168
  personaGet: () => personaGet,
149
169
  personaSmsList: () => personaSmsList,
150
170
  personaUpdate: () => personaUpdate,
151
- prepareAgentRequest: () => prepareAgentRequest,
152
171
  prepareRunPayloadUpload: () => prepareRunPayloadUpload,
153
172
  processScrapeResponse: () => processScrapeResponse,
154
173
  profileCookiesGet: () => profileCookiesGet,
@@ -158,27 +177,42 @@ __export(index_exports, {
158
177
  profileDuplicate: () => profileDuplicate,
159
178
  profileGet: () => profileGet,
160
179
  profileList: () => profileList,
180
+ profileStateSet: () => profileStateSet,
161
181
  readCookiesFile: () => readCookiesFile,
162
182
  readyCheck: () => readyCheck,
163
183
  responseFromEvaluated: () => responseFromEvaluated,
164
- 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,
165
193
  sanitizeFilename: () => sanitizeFilename,
166
194
  scrapeFromHtml: () => scrapeFromHtml,
195
+ scrapeSpecializedData: () => fetchSpecializedData,
167
196
  scrapeWebpage: () => scrapeWebpage,
168
197
  searchWeb: () => searchWeb,
169
198
  sessionAuthReadiness: () => sessionAuthReadiness,
170
199
  sessionCookiesGet: () => sessionCookiesGet,
171
200
  sessionCookiesSet: () => sessionCookiesSet,
172
201
  sessionDebugInfo: () => sessionDebugInfo,
202
+ sessionMouseReplay: () => sessionMouseReplay,
173
203
  sessionNetworkLogs: () => sessionNetworkLogs,
174
204
  sessionOffset: () => sessionOffset,
175
205
  sessionProfilePreview: () => sessionProfilePreview,
206
+ sessionProfileSave: () => sessionProfileSave,
176
207
  sessionReplay: () => sessionReplay,
177
208
  sessionStart: () => sessionStart,
178
209
  sessionStatus: () => sessionStatus,
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.6" : "dev";
235
+ var SDK_VERSION = true ? "1.10.0" : "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) => {
@@ -1159,10 +1199,14 @@ var sessionProfilePreview = (options) => (options.client ?? client).get({
1159
1199
  url: "/sessions/{session_id}/profile-preview",
1160
1200
  ...options
1161
1201
  });
1162
- var getSessionScript = (options) => (options.client ?? client).get({
1202
+ var sessionProfileSave = (options) => (options.client ?? client).post({
1163
1203
  security: [{ scheme: "bearer", type: "http" }],
1164
- url: "/sessions/{session_id}/workflow/code",
1165
- ...options
1204
+ url: "/sessions/{session_id}/profile/save",
1205
+ ...options,
1206
+ headers: {
1207
+ "Content-Type": "application/json",
1208
+ ...options.headers
1209
+ }
1166
1210
  });
1167
1211
  var sessionStop = (options) => (options.client ?? client).delete({
1168
1212
  security: [{ scheme: "bearer", type: "http" }],
@@ -1230,11 +1274,25 @@ var sessionNetworkLogs = (options) => (options.client ?? client).get({
1230
1274
  url: "/sessions/{session_id}/network/logs",
1231
1275
  ...options
1232
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
+ });
1233
1282
  var sessionReplay = (options) => (options.client ?? client).get({
1234
1283
  security: [{ scheme: "bearer", type: "http" }],
1235
1284
  url: "/sessions/{session_id}/replay",
1236
1285
  ...options
1237
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
+ });
1238
1296
  var listSessionFiles = (options) => (options.client ?? client).get({
1239
1297
  security: [{ scheme: "bearer", type: "http" }],
1240
1298
  url: "/sessions/{session_id}/files",
@@ -1260,35 +1318,6 @@ var downloadSessionFile = (options) => (options.client ?? client).get({
1260
1318
  url: "/sessions/{session_id}/files/{file_id}",
1261
1319
  ...options
1262
1320
  });
1263
- var agentStart = (options) => (options.client ?? client).post({
1264
- security: [{ scheme: "bearer", type: "http" }],
1265
- url: "/agents/start",
1266
- ...options,
1267
- headers: {
1268
- "Content-Type": "application/json",
1269
- ...options.headers
1270
- }
1271
- });
1272
- var agentStatus = (options) => (options.client ?? client).get({
1273
- security: [{ scheme: "bearer", type: "http" }],
1274
- url: "/agents/{agent_id}",
1275
- ...options
1276
- });
1277
- var getScript = (options) => (options.client ?? client).get({
1278
- security: [{ scheme: "bearer", type: "http" }],
1279
- url: "/agents/{agent_id}/workflow/code",
1280
- ...options
1281
- });
1282
- var agentStop = (options) => (options.client ?? client).delete({
1283
- security: [{ scheme: "bearer", type: "http" }],
1284
- url: "/agents/{agent_id}/stop",
1285
- ...options
1286
- });
1287
- var listAgents = (options) => (options?.client ?? client).get({
1288
- security: [{ scheme: "bearer", type: "http" }],
1289
- url: "/agents",
1290
- ...options
1291
- });
1292
1321
  var functionRuntimeHealth = (options) => (options?.client ?? client).get({
1293
1322
  security: [{ scheme: "bearer", type: "http" }],
1294
1323
  url: "/functions/health",
@@ -1558,6 +1587,15 @@ var profileCookiesSet = (options) => (options.client ?? client).post({
1558
1587
  ...options.headers
1559
1588
  }
1560
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
+ });
1561
1599
  var profileList = (options) => (options?.client ?? client).get({
1562
1600
  security: [{ scheme: "bearer", type: "http" }],
1563
1601
  url: "/profiles",
@@ -1684,24 +1722,6 @@ var connectLinkSubmit = (options) => (options.client ?? client).post({
1684
1722
  }
1685
1723
  });
1686
1724
  var connectLinkStatus = (options) => (options.client ?? client).get({ url: "/managed-auth/connect-links/status", ...options });
1687
- var improvePrompt = (options) => (options.client ?? client).post({
1688
- security: [{ scheme: "bearer", type: "http" }],
1689
- url: "/prompts/improve",
1690
- ...options,
1691
- headers: {
1692
- "Content-Type": "application/json",
1693
- ...options.headers
1694
- }
1695
- });
1696
- var nudgePrompt = (options) => (options.client ?? client).post({
1697
- security: [{ scheme: "bearer", type: "http" }],
1698
- url: "/prompts/nudge",
1699
- ...options,
1700
- headers: {
1701
- "Content-Type": "application/json",
1702
- ...options.headers
1703
- }
1704
- });
1705
1725
  var getUsage = (options) => (options?.client ?? client).get({
1706
1726
  security: [{ scheme: "bearer", type: "http" }],
1707
1727
  url: "/usage",
@@ -1745,6 +1765,11 @@ var deleteSecret = (options) => (options.client ?? client).delete({
1745
1765
  url: "/secrets/{secret_id}",
1746
1766
  ...options
1747
1767
  });
1768
+ var listAuditEvents = (options) => (options?.client ?? client).get({
1769
+ security: [{ scheme: "bearer", type: "http" }],
1770
+ url: "/audit-events",
1771
+ ...options
1772
+ });
1748
1773
  var healthCheck = (options) => (options?.client ?? client).get({ url: "/health", ...options });
1749
1774
  var readyCheck = (options) => (options?.client ?? client).get({ url: "/ready", ...options });
1750
1775
  var scrapeWebpage = (options) => (options.client ?? client).post({
@@ -1765,6 +1790,215 @@ var searchWeb = (options) => (options.client ?? client).post({
1765
1790
  ...options.headers
1766
1791
  }
1767
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
+ });
1768
2002
  var scrapeFromHtml = (options) => (options.client ?? client).post({
1769
2003
  security: [{ scheme: "bearer", type: "http" }],
1770
2004
  url: "/scrape_from_html",
@@ -1774,6 +2008,40 @@ var scrapeFromHtml = (options) => (options.client ?? client).post({
1774
2008
  ...options.headers
1775
2009
  }
1776
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
+ });
1777
2045
 
1778
2046
  // src/managed-auth.ts
1779
2047
  var import_promises = require("timers/promises");
@@ -1858,14 +2126,14 @@ var ActionExecutionError = class _ActionExecutionError extends NotteError {
1858
2126
  agentMessage;
1859
2127
  shouldRetryLater;
1860
2128
  shouldNotifyTeam;
1861
- constructor(detail) {
1862
- super(detail.dev_message || detail.user_message || detail.error_type);
1863
- this.errorType = detail.error_type;
1864
- this.devMessage = detail.dev_message;
1865
- this.userMessage = detail.user_message;
1866
- this.agentMessage = detail.agent_message;
1867
- this.shouldRetryLater = detail.should_retry_later ?? false;
1868
- 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;
1869
2137
  }
1870
2138
  static fromMessage(message, errorType = "NotteBaseError") {
1871
2139
  return new _ActionExecutionError({
@@ -1896,7 +2164,7 @@ function normalizeErrorBody(body) {
1896
2164
  return { message: typeof body === "string" ? body : String(body) };
1897
2165
  }
1898
2166
  var DEFAULT_RETRY_MESSAGE = "An error occurred while executing the function. Try again later...";
1899
- function retry(fn, options) {
2167
+ function retry2(fn, options) {
1900
2168
  const {
1901
2169
  maxTries,
1902
2170
  delayMs = 5e3,
@@ -1933,11 +2201,6 @@ function sleep(ms) {
1933
2201
  // src/managed-auth.ts
1934
2202
  var ManagedAuthError = class extends NotteError {
1935
2203
  };
1936
- function validateAuthRetry(value) {
1937
- if (!Number.isInteger(value) || value < 0 || value > 2) {
1938
- throw new InvalidRequestError("auth_retry must be an integer between 0 and 2");
1939
- }
1940
- }
1941
2204
  async function pollAuth(read, options) {
1942
2205
  const timeoutMs = options.timeoutMs ?? 615e3;
1943
2206
  const interval = options.pollIntervalMs ?? 1e3;
@@ -2018,12 +2281,10 @@ var NotteManagedAuth = class {
2018
2281
  return this.run(connectionId, "reauthenticate", options);
2019
2282
  }
2020
2283
  async run(connectionId, action, options) {
2021
- const authRetry = options.auth_retry ?? 0;
2022
- validateAuthRetry(authRetry);
2023
2284
  options.signal?.throwIfAborted();
2024
2285
  const response = await this.client.getClient().post({
2025
2286
  url: `/managed-auth/connections/${encodeURIComponent(connectionId)}/${action}`,
2026
- body: { auth_retry: authRetry },
2287
+ body: { auth_retry: options.auth_retry },
2027
2288
  headers: { "Content-Type": "application/json" },
2028
2289
  signal: options.signal,
2029
2290
  throwOnError: true
@@ -2058,7 +2319,7 @@ function createResources(client2, getApiKey) {
2058
2319
  },
2059
2320
  /** downloadSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2060
2321
  downloadSessionFile: async (sessionId, fileId, requestOptions = {}) => {
2061
- const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2322
+ const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, parseAs: "blob", headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2062
2323
  return response.data;
2063
2324
  },
2064
2325
  /** pageExecute: /sessions/{session_id}/page/execute. Returns the API response body. */
@@ -2066,6 +2327,11 @@ function createResources(client2, getApiKey) {
2066
2327
  const response = await pageExecute({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2067
2328
  return response.data;
2068
2329
  },
2330
+ /** executeSessionFile: /sessions/{session_id}/page/execute/file. Returns the API response body. */
2331
+ executeSessionFile: async (sessionId, body, query = void 0, requestOptions = {}) => {
2332
+ const response = await executeSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2333
+ return response.data;
2334
+ },
2069
2335
  /** sessionCookiesGet: /sessions/{session_id}/cookies. Returns the API response body. */
2070
2336
  getCookies: async (sessionId, query = void 0, requestOptions = {}) => {
2071
2337
  const response = await sessionCookiesGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
@@ -2086,6 +2352,11 @@ function createResources(client2, getApiKey) {
2086
2352
  const response = await listSessionFiles({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2087
2353
  return response.data;
2088
2354
  },
2355
+ /** sessionMouseReplay: /sessions/{session_id}/replay/mouse. Returns the API response body. */
2356
+ mouseReplay: async (sessionId, query = void 0, requestOptions = {}) => {
2357
+ const response = await sessionMouseReplay({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2358
+ return response.data;
2359
+ },
2089
2360
  /** sessionNetworkLogs: /sessions/{session_id}/network/logs. Returns the API response body. */
2090
2361
  networkLogs: async (sessionId, query = void 0, requestOptions = {}) => {
2091
2362
  const response = await sessionNetworkLogs({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
@@ -2116,6 +2387,11 @@ function createResources(client2, getApiKey) {
2116
2387
  const response = await sessionReplay({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId } });
2117
2388
  return response.data;
2118
2389
  },
2390
+ /** sessionProfileSave: /sessions/{session_id}/profile/save. Returns the API response body. */
2391
+ saveProfile: async (sessionId, body, requestOptions = {}) => {
2392
+ const response = await sessionProfileSave({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body });
2393
+ return response.data;
2394
+ },
2119
2395
  /** pageScrape: /sessions/{session_id}/page/scrape. Returns the API response body. */
2120
2396
  scrape: async (sessionId, body, query = void 0, requestOptions = {}) => {
2121
2397
  const response = await pageScrape({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
@@ -2147,30 +2423,30 @@ function createResources(client2, getApiKey) {
2147
2423
  return response.data;
2148
2424
  }
2149
2425
  },
2150
- agents: {
2151
- /** getScript: /agents/{agent_id}/workflow/code. Returns the API response body. */
2152
- getScript: async (agentId, query, requestOptions = {}) => {
2153
- const response = await getScript({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId }, query });
2426
+ files: {
2427
+ /** deleteSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2428
+ delete: async (sessionId, fileId, requestOptions = {}) => {
2429
+ const response = await deleteSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2154
2430
  return response.data;
2155
2431
  },
2156
- /** listAgents: /agents. Returns the API response body. */
2157
- list: async (query = void 0, requestOptions = {}) => {
2158
- const response = await listAgents({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2432
+ /** downloadSessionFile: /sessions/{session_id}/files/{file_id}. Returns the API response body. */
2433
+ download: async (sessionId, fileId, requestOptions = {}) => {
2434
+ const response = await downloadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, parseAs: "blob", headers: { ...requestOptions.headers }, path: { "session_id": sessionId, "file_id": fileId } });
2159
2435
  return response.data;
2160
2436
  },
2161
- /** agentStart: /agents/start. Returns the API response body. */
2162
- start: async (body, requestOptions = {}) => {
2163
- const response = await agentStart({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2437
+ /** executeSessionFile: /sessions/{session_id}/page/execute/file. Returns the API response body. */
2438
+ execute: async (sessionId, body, query = void 0, requestOptions = {}) => {
2439
+ const response = await executeSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body, query });
2164
2440
  return response.data;
2165
2441
  },
2166
- /** agentStatus: /agents/{agent_id}. Returns the API response body. */
2167
- status: async (agentId, requestOptions = {}) => {
2168
- const response = await agentStatus({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId } });
2442
+ /** listSessionFiles: /sessions/{session_id}/files. Returns the API response body. */
2443
+ list: async (sessionId, query = void 0, requestOptions = {}) => {
2444
+ const response = await listSessionFiles({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, query });
2169
2445
  return response.data;
2170
2446
  },
2171
- /** agentStop: /agents/{agent_id}/stop. Returns the API response body. */
2172
- stop: async (agentId, query, requestOptions = {}) => {
2173
- const response = await agentStop({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "agent_id": agentId }, query });
2447
+ /** uploadSessionFile: /sessions/{session_id}/files. Returns the API response body. */
2448
+ upload: async (sessionId, body, requestOptions = {}) => {
2449
+ const response = await uploadSessionFile({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "session_id": sessionId }, body });
2174
2450
  return response.data;
2175
2451
  }
2176
2452
  },
@@ -2251,8 +2527,8 @@ function createResources(client2, getApiKey) {
2251
2527
  return response.data;
2252
2528
  },
2253
2529
  /** functionRuntimeHealth: /functions/health. Returns the API response body. */
2254
- runtimeHealth: async (requestOptions = {}) => {
2255
- const response = await functionRuntimeHealth({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers } });
2530
+ runtimeHealth: async (requestOptions = {}, query = void 0) => {
2531
+ const response = await functionRuntimeHealth({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2256
2532
  return response.data;
2257
2533
  },
2258
2534
  /** functionScheduleSet: /functions/{function_id}/schedule. Returns the API response body. */
@@ -2266,6 +2542,43 @@ function createResources(client2, getApiKey) {
2266
2542
  return response.data;
2267
2543
  }
2268
2544
  },
2545
+ personas: {
2546
+ /** personaCreate: /personas/create. Returns the API response body. */
2547
+ create: async (body, requestOptions = {}) => {
2548
+ const response = await personaCreate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2549
+ return response.data;
2550
+ },
2551
+ /** personaDelete: /personas/{persona_id}. Returns the API response body. */
2552
+ delete: async (personaId, requestOptions = {}) => {
2553
+ const response = await personaDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2554
+ return response.data;
2555
+ },
2556
+ /** personaEmailsList: /personas/{persona_id}/emails. Returns the API response body. */
2557
+ emailsList: async (personaId, query = void 0, requestOptions = {}) => {
2558
+ const response = await personaEmailsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2559
+ return response.data;
2560
+ },
2561
+ /** personaGet: /personas/{persona_id}. Returns the API response body. */
2562
+ get: async (personaId, requestOptions = {}) => {
2563
+ const response = await personaGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2564
+ return response.data;
2565
+ },
2566
+ /** listPersonas: /personas. Returns the API response body. */
2567
+ list: async (query = void 0, requestOptions = {}) => {
2568
+ const response = await listPersonas({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2569
+ return response.data;
2570
+ },
2571
+ /** personaSmsList: /personas/{persona_id}/sms. Returns the API response body. */
2572
+ smsList: async (personaId, query = void 0, requestOptions = {}) => {
2573
+ const response = await personaSmsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2574
+ return response.data;
2575
+ },
2576
+ /** personaUpdate: /personas/{persona_id}. Returns the API response body. */
2577
+ update: async (personaId, body, requestOptions = {}) => {
2578
+ const response = await personaUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, body });
2579
+ return response.data;
2580
+ }
2581
+ },
2269
2582
  vaults: {
2270
2583
  /** vaultCreate: /vaults/create. Returns the API response body. */
2271
2584
  create: async (body, requestOptions = {}) => {
@@ -2316,47 +2629,10 @@ function createResources(client2, getApiKey) {
2316
2629
  list: async (query = void 0, requestOptions = {}) => {
2317
2630
  const response = await listVaults({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2318
2631
  return response.data;
2319
- },
2320
- /** vaultUpdate: /vaults/{vault_id}. Returns the API response body. */
2321
- update: async (vaultId, body, requestOptions = {}) => {
2322
- const response = await vaultUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId }, body });
2323
- return response.data;
2324
- }
2325
- },
2326
- personas: {
2327
- /** personaCreate: /personas/create. Returns the API response body. */
2328
- create: async (body, requestOptions = {}) => {
2329
- const response = await personaCreate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, body });
2330
- return response.data;
2331
- },
2332
- /** personaDelete: /personas/{persona_id}. Returns the API response body. */
2333
- delete: async (personaId, requestOptions = {}) => {
2334
- const response = await personaDelete({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2335
- return response.data;
2336
- },
2337
- /** personaEmailsList: /personas/{persona_id}/emails. Returns the API response body. */
2338
- emailsList: async (personaId, query = void 0, requestOptions = {}) => {
2339
- const response = await personaEmailsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2340
- return response.data;
2341
- },
2342
- /** personaGet: /personas/{persona_id}. Returns the API response body. */
2343
- get: async (personaId, requestOptions = {}) => {
2344
- const response = await personaGet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId } });
2345
- return response.data;
2346
- },
2347
- /** listPersonas: /personas. Returns the API response body. */
2348
- list: async (query = void 0, requestOptions = {}) => {
2349
- const response = await listPersonas({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2350
- return response.data;
2351
- },
2352
- /** personaSmsList: /personas/{persona_id}/sms. Returns the API response body. */
2353
- smsList: async (personaId, query = void 0, requestOptions = {}) => {
2354
- const response = await personaSmsList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, query });
2355
- return response.data;
2356
- },
2357
- /** personaUpdate: /personas/{persona_id}. Returns the API response body. */
2358
- update: async (personaId, body, requestOptions = {}) => {
2359
- const response = await personaUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "persona_id": personaId }, body });
2632
+ },
2633
+ /** vaultUpdate: /vaults/{vault_id}. Returns the API response body. */
2634
+ update: async (vaultId, body, requestOptions = {}) => {
2635
+ const response = await vaultUpdate({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "vault_id": vaultId }, body });
2360
2636
  return response.data;
2361
2637
  }
2362
2638
  },
@@ -2395,6 +2671,11 @@ function createResources(client2, getApiKey) {
2395
2671
  list: async (query = void 0, requestOptions = {}) => {
2396
2672
  const response = await profileList({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, query });
2397
2673
  return response.data;
2674
+ },
2675
+ /** profileStateSet: /profiles/{profile_id}/state. Returns the API response body. */
2676
+ stateSet: async (profileId, body, requestOptions = {}) => {
2677
+ const response = await profileStateSet({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers }, path: { "profile_id": profileId }, body });
2678
+ return response.data;
2398
2679
  }
2399
2680
  }
2400
2681
  };
@@ -2759,10 +3040,16 @@ async function createOrAppendCookiesToFile(cookieFile, cookies) {
2759
3040
  throw error;
2760
3041
  }
2761
3042
  }
2762
- existing.push(...cookies);
2763
- await (0, import_promises2.writeFile)(cookieFile, JSON.stringify(existing), "utf-8");
3043
+ const merged = /* @__PURE__ */ new Map();
3044
+ for (const cookie of [...existing, ...cookies]) {
3045
+ merged.set(cookieIdentity(cookie), cookie);
3046
+ }
3047
+ await (0, import_promises2.writeFile)(cookieFile, JSON.stringify([...merged.values()]), "utf-8");
2764
3048
  });
2765
3049
  }
3050
+ function cookieIdentity(cookie) {
3051
+ return JSON.stringify([cookie.name, cookie.domain ?? null, cookie.path ?? null, cookie.partitionKey ?? null]);
3052
+ }
2766
3053
  var fileLocks = /* @__PURE__ */ new Map();
2767
3054
  async function withFileLock(path, fn) {
2768
3055
  const key = (0, import_node_path.resolve)(path);
@@ -2921,8 +3208,8 @@ async function buildScrapeBody(options) {
2921
3208
  if (json_schema) {
2922
3209
  body.response_format = json_schema;
2923
3210
  } else {
2924
- const { z: z2 } = await import("zod");
2925
- body.response_format = normalizeJsonSchema(z2.toJSONSchema(response_format));
3211
+ const { z } = await import("zod");
3212
+ body.response_format = normalizeJsonSchema(z.toJSONSchema(response_format));
2926
3213
  }
2927
3214
  } else if (response_format) {
2928
3215
  body.response_format = response_format;
@@ -2934,9 +3221,6 @@ function processScrapeResponse(scrapeResponse, options) {
2934
3221
  throw new ScrapeFailedError("empty response");
2935
3222
  }
2936
3223
  const raiseOnFailure = options.raiseOnFailure ?? true;
2937
- if (options.only_images) {
2938
- return scrapeResponse.images ?? [];
2939
- }
2940
3224
  if (requiresSchema(options)) {
2941
3225
  const structured = scrapeResponse.structured;
2942
3226
  if (!structured) {
@@ -2959,10 +3243,126 @@ function processScrapeResponse(scrapeResponse, options) {
2959
3243
  return scrapeResponse.markdown;
2960
3244
  }
2961
3245
 
3246
+ // src/retry.ts
3247
+ var DEFAULT_MAX_RETRIES = 3;
3248
+ var RETRY_BASE_DELAY_MS = 1e3;
3249
+ var RETRY_MAX_DELAY_MS = 1e4;
3250
+ var RETRY_AFTER_MAX_MS = 2e4;
3251
+ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]);
3252
+ var REFUSED_STATUSES = /* @__PURE__ */ new Set([503, 529]);
3253
+ var GATEWAY_STATUSES = /* @__PURE__ */ new Set([502, 504]);
3254
+ var NOT_SENT_ERROR_CODES = /* @__PURE__ */ new Set([
3255
+ "ECONNREFUSED",
3256
+ "EAI_AGAIN",
3257
+ "ENETUNREACH",
3258
+ "EHOSTUNREACH",
3259
+ "UND_ERR_CONNECT_TIMEOUT"
3260
+ ]);
3261
+ var BROKEN_CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
3262
+ "ECONNRESET",
3263
+ "EPIPE",
3264
+ "ETIMEDOUT",
3265
+ "UND_ERR_SOCKET",
3266
+ "UND_ERR_CLOSED"
3267
+ ]);
3268
+ function isIdempotentMethod(method) {
3269
+ return IDEMPOTENT_METHODS.has(method.toUpperCase());
3270
+ }
3271
+ function isRetryableStatus(status, method) {
3272
+ return REFUSED_STATUSES.has(status) || GATEWAY_STATUSES.has(status) && isIdempotentMethod(method);
3273
+ }
3274
+ function isRetryableNetworkError(error, method) {
3275
+ const code = networkErrorCode(error);
3276
+ if (code === void 0) return false;
3277
+ return NOT_SENT_ERROR_CODES.has(code) || BROKEN_CONNECTION_ERROR_CODES.has(code) && isIdempotentMethod(method);
3278
+ }
3279
+ function networkErrorCode(error, depth = 0) {
3280
+ if (typeof error !== "object" || error === null || depth > 4) return void 0;
3281
+ const { code, cause, errors } = error;
3282
+ if (typeof code === "string") return code;
3283
+ if (Array.isArray(errors) && errors.length > 0) return networkErrorCode(errors[0], depth + 1);
3284
+ return networkErrorCode(cause, depth + 1);
3285
+ }
3286
+ function parseRetryAfter(header, now = Date.now()) {
3287
+ if (!header) return void 0;
3288
+ const value = header.trim();
3289
+ if (/^\d+(\.\d+)?$/.test(value)) return Number(value) * 1e3;
3290
+ const date = Date.parse(value);
3291
+ return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
3292
+ }
3293
+ function backoffDelayMs(attempt, random = Math.random) {
3294
+ return random() * Math.min(RETRY_MAX_DELAY_MS, RETRY_BASE_DELAY_MS * 2 ** attempt);
3295
+ }
3296
+ function retryDelayMs(attempt, retryAfter, random) {
3297
+ const requested = parseRetryAfter(retryAfter);
3298
+ if (requested === void 0) return backoffDelayMs(attempt, random);
3299
+ return requested <= RETRY_AFTER_MAX_MS ? requested : void 0;
3300
+ }
3301
+ function createRetryingFetch(options) {
3302
+ const wait2 = options.sleep ?? abortableSleep;
3303
+ return async (input, init) => {
3304
+ const baseFetch = options.fetch ?? globalThis.fetch;
3305
+ const request = input instanceof Request ? input : void 0;
3306
+ const method = (request?.method ?? init?.method ?? "GET").toUpperCase();
3307
+ const signal = init?.signal ?? request?.signal;
3308
+ const maxRetries = Math.max(0, Math.floor(options.maxRetries(signal) || 0));
3309
+ const send = (last) => request && request.body !== null && !last ? baseFetch(request.clone(), init) : baseFetch(input, init);
3310
+ for (let attempt = 0; ; attempt++) {
3311
+ const last = attempt >= maxRetries;
3312
+ let response;
3313
+ try {
3314
+ response = await send(last);
3315
+ } catch (error) {
3316
+ if (last || !isRetryableNetworkError(error, method)) throw error;
3317
+ const delay4 = backoffDelayMs(attempt, options.random);
3318
+ if (!fitsDeadline(delay4)) throw error;
3319
+ warn(`${method} request failed (${networkErrorCode(error)})`, delay4, attempt, maxRetries);
3320
+ await wait2(delay4, signal);
3321
+ continue;
3322
+ }
3323
+ if (last || !isRetryableStatus(response.status, method)) return response;
3324
+ const delay3 = retryDelayMs(attempt, response.headers.get("retry-after"), options.random);
3325
+ if (delay3 === void 0 || !fitsDeadline(delay3)) return response;
3326
+ await response.body?.cancel().catch(() => void 0);
3327
+ warn(`${method} request returned ${response.status}`, delay3, attempt, maxRetries);
3328
+ await wait2(delay3, signal);
3329
+ }
3330
+ function fitsDeadline(delay3) {
3331
+ const deadline = options.deadline?.(signal);
3332
+ return deadline === void 0 || Date.now() + delay3 < deadline;
3333
+ }
3334
+ };
3335
+ }
3336
+ function warn(reason, delay3, attempt, maxRetries) {
3337
+ console.warn(`${reason}, retrying in ${(delay3 / 1e3).toFixed(1)}s (${attempt + 1}/${maxRetries})`);
3338
+ }
3339
+ function abortableSleep(ms, signal) {
3340
+ return new Promise((resolve3, reject) => {
3341
+ if (signal?.aborted) {
3342
+ reject(signal.reason);
3343
+ return;
3344
+ }
3345
+ const onAbort = () => {
3346
+ clearTimeout(timer);
3347
+ reject(signal?.reason);
3348
+ };
3349
+ const timer = setTimeout(() => {
3350
+ signal?.removeEventListener("abort", onAbort);
3351
+ resolve3();
3352
+ }, ms);
3353
+ signal?.addEventListener("abort", onAbort, { once: true });
3354
+ });
3355
+ }
3356
+
2962
3357
  // src/session.ts
2963
3358
  var SESSION_START_TRIES = 3;
2964
3359
  var CLUSTER_OVERLOAD_RETRY_DELAY_MS = 3e4;
2965
3360
  var CAPTCHA_SOLVE_TIMEOUT_MS = 1e5;
3361
+ var OBSERVE_MIGRATION_URL = "https://docs.notte.cc/features/sessions/observe-migration";
3362
+ var OBSERVE_DEPRECATIONS = {
3363
+ instructions: `\`observe({ instructions })\` is deprecated and will be removed on December 1, 2026; <<ALTERNATIVE FOR instructions: session.act() \u2014 pending>>. See ${OBSERVE_MIGRATION_URL}`,
3364
+ deep: `\`perception_type: 'deep'\` is deprecated and will be removed on December 1, 2026; use \`perception_type: 'fast'\` (the default). See ${OBSERVE_MIGRATION_URL}`
3365
+ };
2966
3366
  function observeServerOwnedDialog(_dialog) {
2967
3367
  }
2968
3368
  function installServerOwnedDialogPolicy(browser) {
@@ -2977,6 +3377,7 @@ var Session = class {
2977
3377
  legacyHeadless;
2978
3378
  defaultRaiseOnFailure;
2979
3379
  defaultPerceptionType;
3380
+ warnedObserveDeprecations = /* @__PURE__ */ new Set();
2980
3381
  cookieFile;
2981
3382
  cookiesLoaded = false;
2982
3383
  cookieLoadPromise;
@@ -3012,9 +3413,11 @@ var Session = class {
3012
3413
  /**
3013
3414
  * Start the session: creates a new session on the server.
3014
3415
  *
3015
- * Retries up to `SESSION_START_TRIES` times on 5xx errors, waiting
3016
- * `CLUSTER_OVERLOAD_RETRY_DELAY_MS` on HTTP 529 (cluster overload). 4xx
3017
- * errors are never retried.
3416
+ * 503, 529, and refused connections follow the client's retry policy
3417
+ * (`NotteClientConfig.maxRetries`, honoring `Retry-After`). Other 5xx
3418
+ * errors are retried up to `SESSION_START_TRIES` times. With client
3419
+ * retries disabled, 529 waits `CLUSTER_OVERLOAD_RETRY_DELAY_MS` instead.
3420
+ * 4xx errors are never retried.
3018
3421
  *
3019
3422
  * Managed-auth sessions wait for readiness by default. Pass
3020
3423
  * `{ wait_for_authentication: false }` for an explicit nonblocking start,
@@ -3027,11 +3430,6 @@ var Session = class {
3027
3430
  * await session.start();
3028
3431
  */
3029
3432
  async start(options = {}) {
3030
- if (this.legacyHeadless === false) {
3031
- throw new Error(
3032
- "Remote `headless: false` is no longer supported. `headless: true` sessions still include session replays and access to the live viewer."
3033
- );
3034
- }
3035
3433
  if (this.legacyHeadless === true) {
3036
3434
  console.warn("`headless: true` is deprecated and ignored; remote sessions always use the supported browser launch mode.");
3037
3435
  this.legacyHeadless = void 0;
@@ -3040,42 +3438,60 @@ var Session = class {
3040
3438
  throw new Error("Session is already active");
3041
3439
  }
3042
3440
  options.signal?.throwIfAborted();
3043
- validateAuthRetry(this.options.auth_retry ?? 0);
3044
3441
  const { auth_retry, wait_for_authentication, ...request } = this.options;
3045
3442
  const body = {
3046
3443
  ...request,
3047
- ...request.auth_ids?.length ? { auth_retry: auth_retry ?? 0, wait_for_authentication: false } : {}
3444
+ ...this.legacyHeadless !== void 0 ? { headless: this.legacyHeadless } : {},
3445
+ ...auth_retry !== void 0 ? { auth_retry } : {},
3446
+ ...request.auth_ids?.length ? { wait_for_authentication: false } : {}
3048
3447
  };
3049
3448
  const shouldWait = options.wait_for_authentication ?? wait_for_authentication ?? true;
3449
+ const maxRetries = this.client.getConfig().maxRetries ?? 0;
3450
+ const timeoutMs = this.client.getConfig().timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
3451
+ const deadline = timeoutMs > 0 ? Date.now() + timeoutMs : void 0;
3452
+ const fitsDeadline = (wait2) => deadline === void 0 || Date.now() + wait2 < deadline;
3453
+ let transientRetries = 0;
3050
3454
  let tries = SESSION_START_TRIES;
3051
3455
  const origTries = tries;
3052
3456
  let sessionData;
3053
3457
  while (tries > 0) {
3054
3458
  options.signal?.throwIfAborted();
3055
- tries -= 1;
3459
+ if (!fitsDeadline(0)) throw new NotteTimeoutError(`Session start timed out after ${timeoutMs}ms`);
3056
3460
  try {
3057
- const response = await sessionStart({ client: this.client.getClient(), body, throwOnError: true });
3461
+ const response = await sessionStart({
3462
+ client: this.client.getClient(),
3463
+ body,
3464
+ throwOnError: true,
3465
+ headers: {
3466
+ [MAX_RETRIES_HEADER]: "0",
3467
+ ...deadline === void 0 ? {} : { [TIMEOUT_HEADER]: String(Math.max(1, deadline - Date.now())) }
3468
+ }
3469
+ });
3058
3470
  sessionData = response.data;
3059
3471
  break;
3060
3472
  } catch (error) {
3473
+ const transient = error instanceof NotteAPIError ? isRetryableStatus(error.statusCode, "POST") : isRetryableNetworkError(error, "POST");
3474
+ if (maxRetries > 0 && transient) {
3475
+ const wait2 = transientRetries >= maxRetries ? void 0 : error instanceof NotteAPIError ? retryDelayMs(transientRetries, error.response?.headers.get("retry-after")) : backoffDelayMs(transientRetries);
3476
+ if (wait2 === void 0 || !fitsDeadline(wait2)) throw error;
3477
+ transientRetries += 1;
3478
+ console.warn(
3479
+ `Failed to start session (${error instanceof NotteAPIError ? error.statusCode : "connection error"}), retrying in ${(wait2 / 1e3).toFixed(1)}s (${transientRetries}/${maxRetries})`
3480
+ );
3481
+ await pauseStart(wait2, options.signal);
3482
+ continue;
3483
+ }
3484
+ tries -= 1;
3061
3485
  if (tries === 0 || !(error instanceof NotteAPIError) || error.statusCode < 500) {
3062
3486
  throw error;
3063
3487
  }
3064
3488
  const retryStr = `${origTries - tries}/${origTries - 1}`;
3489
+ if (!fitsDeadline(error.statusCode === 529 ? CLUSTER_OVERLOAD_RETRY_DELAY_MS : 0)) throw error;
3065
3490
  if (error.statusCode === 529) {
3066
3491
  console.warn(
3067
3492
  `Failed to start session due to cluster overload, retrying in ${CLUSTER_OVERLOAD_RETRY_DELAY_MS / 1e3} seconds (${retryStr})...`
3068
3493
  );
3069
- if (options.signal) {
3070
- try {
3071
- await (0, import_promises4.setTimeout)(CLUSTER_OVERLOAD_RETRY_DELAY_MS, void 0, { signal: options.signal });
3072
- } catch (error2) {
3073
- options.signal.throwIfAborted();
3074
- throw error2;
3075
- }
3076
- } else {
3077
- await sleep(CLUSTER_OVERLOAD_RETRY_DELAY_MS);
3078
- }
3494
+ await pauseStart(CLUSTER_OVERLOAD_RETRY_DELAY_MS, options.signal);
3079
3495
  } else {
3080
3496
  console.warn(`Failed to start session: retrying (${retryStr})`);
3081
3497
  }
@@ -3093,6 +3509,7 @@ var Session = class {
3093
3509
  this.fileStorage = this.fileStorage?.forSession(sessionData.session_id);
3094
3510
  try {
3095
3511
  options.signal?.throwIfAborted();
3512
+ if (!fitsDeadline(0)) throw new NotteTimeoutError(`Session start timed out after ${timeoutMs}ms`);
3096
3513
  if (shouldWait) await this.waitForAuth(options);
3097
3514
  if (this.openViewer) {
3098
3515
  this.openViewerInBrowser();
@@ -3406,6 +3823,42 @@ var Session = class {
3406
3823
  return response.data.cookies;
3407
3824
  }
3408
3825
  // #######################################################################
3826
+ // ############################# Profiles ################################
3827
+ // #######################################################################
3828
+ /**
3829
+ * Save the session's current browser state (cookies, localStorage, sessionStorage) into a
3830
+ * profile, without stopping the session.
3831
+ *
3832
+ * Pass `profile_id` to overwrite an existing profile or `name` to create a new one. With
3833
+ * neither, the state is saved into the profile the session was started with. The session's
3834
+ * start-time profile settings are not changed, so a session started with `persist: true`
3835
+ * still saves again when it stops.
3836
+ *
3837
+ * See [Browser Profiles](/features/sessions/browser-profiles) for the tested Python and TypeScript example.
3838
+ */
3839
+ async saveProfile(options = {}) {
3840
+ const { profile_id, name } = options;
3841
+ if (profile_id !== void 0 && name !== void 0) {
3842
+ throw new Error("profile_id and name are mutually exclusive");
3843
+ }
3844
+ if (profile_id !== void 0 && profile_id.trim() === "") {
3845
+ throw new Error("profile_id must not be empty");
3846
+ }
3847
+ if (name !== void 0 && name.trim() === "") {
3848
+ throw new Error("name must not be empty");
3849
+ }
3850
+ const body = {};
3851
+ if (profile_id !== void 0) body.profile_id = profile_id;
3852
+ if (name !== void 0) body.name = name;
3853
+ const response = await sessionProfileSave({
3854
+ client: this.client.getClient(),
3855
+ path: { session_id: this.requireSessionId() },
3856
+ body,
3857
+ throwOnError: true
3858
+ });
3859
+ return response.data;
3860
+ }
3861
+ // #######################################################################
3409
3862
  // ############################# Debug / CDP #############################
3410
3863
  // #######################################################################
3411
3864
  /** Detailed debug information for the session (debug URL, websocket URLs, tabs). */
@@ -3482,7 +3935,9 @@ var Session = class {
3482
3935
  try {
3483
3936
  if (!this.playwrightBrowser) {
3484
3937
  const cdpUrl = await this.cdpUrl();
3485
- this.playwrightBrowser = await playwright.chromium.connectOverCDP(cdpUrl);
3938
+ this.playwrightBrowser = this.options.cdp_url ? await playwright.chromium.connectOverCDP(cdpUrl) : await playwright.chromium.connectOverCDP(cdpUrl, {
3939
+ headers: { "x-notte-request-origin": REQUEST_ORIGIN, "x-notte-sdk-version": SDK_VERSION }
3940
+ });
3486
3941
  installServerOwnedDialogPolicy(this.playwrightBrowser);
3487
3942
  }
3488
3943
  const page = this.playwrightBrowser.contexts()[0]?.pages()[0];
@@ -3612,19 +4067,30 @@ var Session = class {
3612
4067
  * The `perception_type` defaults to the session option (`fast`). A bare
3613
4068
  * string argument is accepted as the perception type.
3614
4069
  *
4070
+ * Deprecated: `perception_type: 'deep'` and `instructions` are removed on
4071
+ * December 1, 2026, and each warns once per session. Use `perception_type:
4072
+ * 'fast'` (the default) instead of `'deep'`. For `instructions`:
4073
+ * `<<ALTERNATIVE FOR instructions: session.act() — pending>>`. See https://docs.notte.cc/features/sessions/observe-migration
4074
+ *
3615
4075
  * @param options - Observation settings, including an optional URL, or a perception-mode string.
3616
4076
  * @returns Structured page analysis, available actions, and page metadata.
3617
4077
  * @throws NotteAPIError if observation fails.
3618
4078
  * @example
3619
4079
  * const obs = await session.observe();
3620
4080
  * console.log(obs.space.description);
3621
- * const deep = await session.observe({ perception_type: 'deep', max_nb_actions: 50 });
4081
+ * const firstActions = await session.observe({ max_nb_actions: 50 });
3622
4082
  */
3623
4083
  async observe(options = {}) {
3624
4084
  const body = typeof options === "string" ? { perception_type: options } : { ...options };
3625
4085
  if (body.perception_type == null) {
3626
4086
  body.perception_type = this.defaultPerceptionType;
3627
4087
  }
4088
+ if (body.instructions != null) {
4089
+ this.warnObserveDeprecation("instructions");
4090
+ }
4091
+ if (body.perception_type !== "fast") {
4092
+ this.warnObserveDeprecation("deep");
4093
+ }
3628
4094
  const response = await pageObserve({
3629
4095
  client: this.client.getClient(),
3630
4096
  path: { session_id: this.requireSessionId() },
@@ -3633,6 +4099,12 @@ var Session = class {
3633
4099
  });
3634
4100
  return response.data;
3635
4101
  }
4102
+ warnObserveDeprecation(option) {
4103
+ if (!this.warnedObserveDeprecations.has(option)) {
4104
+ this.warnedObserveDeprecations.add(option);
4105
+ console.warn(OBSERVE_DEPRECATIONS[option]);
4106
+ }
4107
+ }
3636
4108
  async scrape(options = {}) {
3637
4109
  const sessionId = this.requireSessionId();
3638
4110
  const body = await buildScrapeBody(options);
@@ -3700,424 +4172,18 @@ var Session = class {
3700
4172
  }
3701
4173
  }
3702
4174
  };
3703
-
3704
- // src/agent.ts
3705
- var import_ws = __toESM(require("ws"));
3706
- var import_zod = require("zod");
3707
- function prepareAgentRequest(data) {
3708
- const apiData = { ...data };
3709
- const rf = data.response_format;
3710
- if (rf && typeof rf.parse === "function" && typeof rf.safeParse === "function") {
3711
- apiData.response_format = normalizeJsonSchema(import_zod.z.toJSONSchema(rf));
3712
- return { apiData, zodSchema: rf };
3713
- }
3714
- return { apiData, zodSchema: null };
3715
- }
3716
- function parseAgentStatusMessage(parsed, agentId) {
3717
- if (parsed?.status === "agent_stop" && parsed.agent && parsed.agent.agent_id === agentId && parsed.agent.task !== void 0 && parsed.agent.status !== void 0) {
3718
- return parsed.agent;
3719
- }
3720
- if (parsed?.agent_id === agentId && parsed.task !== void 0 && parsed.status !== void 0) {
3721
- return parsed;
3722
- }
3723
- return null;
3724
- }
3725
- function validatePersonaOption(persona, persona_id) {
3726
- if (persona) {
3727
- try {
3728
- const personaId = persona.personaId;
3729
- if (!personaId || personaId.length === 0) {
3730
- throw new Error("Persona ID cannot be empty");
3731
- }
3732
- return personaId;
3733
- } catch (error) {
3734
- throw new Error(`Invalid persona object: ${error instanceof Error ? error.message : String(error)}`);
3735
- }
3736
- } else if (persona_id) {
3737
- if (persona_id.length === 0) {
3738
- throw new Error("Persona ID cannot be empty");
3739
- }
3740
- return persona_id;
3741
- }
3742
- return void 0;
3743
- }
3744
- function validateVaultOption(vault, vault_id) {
3745
- if (vault) {
3746
- try {
3747
- const vaultId = vault.vaultId;
3748
- if (!vaultId || vaultId.length === 0) {
3749
- throw new Error("Vault ID cannot be empty");
3750
- }
3751
- return vaultId;
3752
- } catch (error) {
3753
- throw new Error(`Invalid vault object: ${error instanceof Error ? error.message : String(error)}`);
3754
- }
3755
- } else if (vault_id) {
3756
- if (vault_id.length === 0) {
3757
- throw new Error("Vault ID cannot be empty");
3758
- }
3759
- return vault_id;
3760
- }
3761
- return void 0;
3762
- }
3763
- function validateSessionOption(session) {
3764
- const sessionId = session.getId();
3765
- if (!sessionId || sessionId.length === 0) {
3766
- throw new Error("Session ID cannot be empty");
4175
+ async function pauseStart(ms, signal) {
4176
+ if (!signal) {
4177
+ await sleep(ms);
4178
+ return;
3767
4179
  }
3768
- return sessionId;
3769
- }
3770
- function validateAgentIdOption(agent_id) {
3771
- if (agent_id.length === 0) {
3772
- throw new Error("Agent ID cannot be empty");
4180
+ try {
4181
+ await (0, import_promises4.setTimeout)(ms, void 0, { signal });
4182
+ } catch (error) {
4183
+ signal.throwIfAborted();
4184
+ throw error;
3773
4185
  }
3774
4186
  }
3775
- var defaultStepLogger = (stepData, stepCounter, agentId) => {
3776
- console.log(`\u2728 Step ${stepCounter} (agent: ${agentId})`);
3777
- if (stepData && typeof stepData === "object") {
3778
- if (stepData.state) {
3779
- const state = stepData.state;
3780
- if (state.page_summary) {
3781
- console.log(`\u{1F4DD} Current page: ${state.page_summary}`);
3782
- }
3783
- if (state.previous_goal_eval) {
3784
- const statusEmoji = state.previous_goal_status === "success" ? "\u2705" : state.previous_goal_status === "failure" ? "\u274C" : "\u2753";
3785
- console.log(`\u{1F52C} Previous goal: ${statusEmoji} ${state.previous_goal_eval}`);
3786
- }
3787
- if (state.memory) {
3788
- console.log(`\u{1F9E0} Memory: ${state.memory}`);
3789
- }
3790
- if (state.next_goal) {
3791
- console.log(`\u{1F3AF} Next goal: ${state.next_goal}`);
3792
- }
3793
- if (state.relevant_interactions && state.relevant_interactions.length > 0) {
3794
- console.log(`\u{1F194} Relevant ids:`);
3795
- state.relevant_interactions.forEach((interaction) => {
3796
- console.log(` \u25B6 ${interaction.id}: ${interaction.reason}`);
3797
- });
3798
- }
3799
- }
3800
- if (stepData.action) {
3801
- const action = stepData.action;
3802
- let actionStr = `\u26A1 Taking action:
3803
- \u25B6 ${action.name || action.type || "Unknown action"}`;
3804
- if (action.id) {
3805
- actionStr += ` with id ${action.id}`;
3806
- } else if (action.param && action.param.name && action[action.param.name]) {
3807
- actionStr += ` with ${action.param.name}=${action[action.param.name]}`;
3808
- }
3809
- console.log(actionStr);
3810
- }
3811
- } else {
3812
- console.log(stepData);
3813
- }
3814
- console.log("");
3815
- };
3816
- var Agent = class {
3817
- client;
3818
- request;
3819
- response = null;
3820
- websocket = null;
3821
- existingAgent;
3822
- constructor(client2, options) {
3823
- this.client = client2;
3824
- if ("agent_id" in options && options.agent_id) {
3825
- if (options.session) {
3826
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided, not both");
3827
- }
3828
- validateAgentIdOption(options.agent_id);
3829
- this.existingAgent = true;
3830
- this.response = { agent_id: options.agent_id };
3831
- } else if ("session" in options && options.session) {
3832
- if (options.agent_id) {
3833
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided, not both");
3834
- }
3835
- this.existingAgent = false;
3836
- const { session, vault, persona, ...requestData } = options;
3837
- const sessionId = validateSessionOption(session);
3838
- const vaultId = validateVaultOption(vault, options.vault_id);
3839
- const personaId = validatePersonaOption(persona, options.persona_id);
3840
- this.request = {
3841
- session_id: sessionId,
3842
- vault_id: vaultId,
3843
- persona_id: personaId,
3844
- ...requestData
3845
- };
3846
- } else {
3847
- throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided");
3848
- }
3849
- }
3850
- async start(data) {
3851
- if (this.existingAgent) {
3852
- throw new Error("You cannot call start() on an agent instantiated from agent id");
3853
- }
3854
- if (!this.request) {
3855
- throw new Error("Agent not properly initialized with session");
3856
- }
3857
- try {
3858
- const { apiData } = prepareAgentRequest(data);
3859
- const requestBody = {
3860
- ...this.request,
3861
- ...apiData
3862
- };
3863
- const response = await agentStart({
3864
- client: this.client.getClient(),
3865
- body: requestBody
3866
- });
3867
- if (response?.error) {
3868
- throw new Error(`Failed to start agent: ${formatError(response.error)}`);
3869
- }
3870
- this.response = response.data;
3871
- return this.response;
3872
- } catch (error) {
3873
- throw new Error(`Failed to start agent: ${error instanceof Error ? error.message : String(error)}`);
3874
- }
3875
- }
3876
- async run(data) {
3877
- if (this.existingAgent) {
3878
- throw new Error("You cannot call run() on an agent instantiated from agent id");
3879
- }
3880
- const { apiData, zodSchema } = prepareAgentRequest(data);
3881
- this.response = await this.start(apiData);
3882
- console.log(`[Agent] ${this.agentId} started`);
3883
- const result = await this.watchLogsAndWait(true, data.updateHandler || null);
3884
- if (zodSchema && result && result.answer !== void 0 && result.answer !== null) {
3885
- let candidate;
3886
- try {
3887
- candidate = typeof result.answer === "string" ? JSON.parse(result.answer) : result.answer;
3888
- } catch {
3889
- throw new Error(`Agent answer is not valid JSON and cannot be validated against the schema`);
3890
- }
3891
- try {
3892
- result.answer = zodSchema.parse(candidate);
3893
- } catch (error) {
3894
- throw new Error(`Agent answer schema validation failed: ${error instanceof Error ? error.message : String(error)}`);
3895
- }
3896
- }
3897
- return result;
3898
- }
3899
- /**
3900
- * Watch logs and wait for completion - mirrors Python watch_logs_and_wait
3901
- */
3902
- async watchLogsAndWait(log = true, updateHandler = null) {
3903
- if (this.existingAgent) {
3904
- throw new Error("You cannot call watchLogsAndWait() on an agent instantiated from agent id");
3905
- }
3906
- if (!this.response) {
3907
- throw new Error("Agent not started");
3908
- }
3909
- const deadline = Date.now() + 3e5;
3910
- try {
3911
- const result = await this.watchLogs(log, updateHandler, deadline);
3912
- if (result && result.status !== "active") {
3913
- return result;
3914
- }
3915
- } catch (error) {
3916
- console.warn(`[Agent] ${this.agentId} log stream unavailable; polling for completion.`);
3917
- }
3918
- while (Date.now() < deadline) {
3919
- const result = await this.status(AbortSignal.timeout(Math.max(1, deadline - Date.now())));
3920
- if (result.status !== "active") {
3921
- updateHandler?.({ type: "completion", data: result, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
3922
- return result;
3923
- }
3924
- await new Promise((resolve3) => setTimeout(resolve3, 1e3));
3925
- }
3926
- throw new Error(`Agent ${this.agentId} did not complete before the polling timeout; retrieve status() later.`);
3927
- }
3928
- /**
3929
- * Watch logs via WebSocket - mirrors Python watch_logs method
3930
- */
3931
- async watchLogs(log = true, updateHandler = null, deadline = Date.now() + 3e5) {
3932
- if (this.existingAgent) {
3933
- throw new Error("You cannot call watchLogs() on an agent instantiated from agent id");
3934
- }
3935
- if (!this.response) {
3936
- throw new Error("Agent not started");
3937
- }
3938
- const config = this.client.getConfig();
3939
- if (config.baseUrl?.startsWith("/")) return null;
3940
- const agentId = this.response.agent_id;
3941
- const sessionId = this.response.session_id;
3942
- const debug = await sessionDebugInfo({
3943
- client: this.client.getClient(),
3944
- path: { session_id: sessionId },
3945
- throwOnError: true,
3946
- signal: AbortSignal.timeout(Math.max(1, deadline - Date.now()))
3947
- });
3948
- const wsUrl = new URL(this.client.withDbPreview(debug.data.ws.logs));
3949
- const token = wsUrl.searchParams.get("token");
3950
- if (!token || token === config.apiKey || wsUrl.protocol !== "wss:") return null;
3951
- wsUrl.pathname = `/agents/${encodeURIComponent(agentId)}/debug/logs`;
3952
- wsUrl.searchParams.set("session_id", sessionId);
3953
- return new Promise((resolve3, reject) => {
3954
- this.websocket = new import_ws.default(wsUrl);
3955
- const socket = this.websocket;
3956
- const timeout = setTimeout(() => finish(null), Math.max(0, deadline - Date.now()));
3957
- let settled = false;
3958
- const finish = (result) => {
3959
- if (settled) return;
3960
- settled = true;
3961
- clearTimeout(timeout);
3962
- if (this.websocket === socket) this.websocket = null;
3963
- if (socket.readyState !== import_ws.default.CLOSED) socket.terminate();
3964
- resolve3(result);
3965
- };
3966
- let counter = 0;
3967
- this.websocket.on("open", () => {
3968
- });
3969
- this.websocket.on("error", (error) => {
3970
- console.error(`Connection error: ${agentId} ${error.message}`);
3971
- finish(null);
3972
- });
3973
- this.websocket.on("message", (data) => {
3974
- try {
3975
- const message = data.toString();
3976
- let parsed;
3977
- try {
3978
- parsed = JSON.parse(message);
3979
- } catch {
3980
- return;
3981
- }
3982
- const finalStatus = parseAgentStatusMessage(parsed, agentId);
3983
- if (finalStatus) {
3984
- if (updateHandler) {
3985
- updateHandler({
3986
- type: "completion",
3987
- data: finalStatus,
3988
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
3989
- });
3990
- } else if (!finalStatus.success) {
3991
- console.error(finalStatus.answer);
3992
- }
3993
- finish(finalStatus);
3994
- return;
3995
- }
3996
- if (log) {
3997
- counter++;
3998
- if (updateHandler) {
3999
- updateHandler({
4000
- type: "step",
4001
- data: parsed,
4002
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
4003
- });
4004
- } else {
4005
- defaultStepLogger(parsed, counter, agentId);
4006
- }
4007
- }
4008
- } catch (error) {
4009
- console.error(`Error processing WebSocket message: ${error}`);
4010
- }
4011
- });
4012
- this.websocket.on("close", () => {
4013
- finish(null);
4014
- });
4015
- });
4016
- }
4017
- /**
4018
- * Get agent status - mirrors Python status method
4019
- */
4020
- async status(signal) {
4021
- if (!this.response) {
4022
- throw new Error("Agent not started or not accessible");
4023
- }
4024
- const response = await agentStatus({
4025
- client: this.client.getClient(),
4026
- signal,
4027
- path: {
4028
- agent_id: this.response.agent_id
4029
- }
4030
- });
4031
- if (response?.error) {
4032
- throw new Error(`Failed to get agent status: ${formatError(response.error)}`);
4033
- }
4034
- return response.data;
4035
- }
4036
- /**
4037
- * Stop the agent - mirrors Python stop method
4038
- */
4039
- async stop() {
4040
- if (this.existingAgent) {
4041
- throw new Error("You cannot call stop() on an agent instantiated from agent id");
4042
- }
4043
- if (!this.response) {
4044
- throw new Error("Agent not started");
4045
- }
4046
- try {
4047
- console.log(`[Agent] ${this.response.agent_id} is stopping`);
4048
- const response = await agentStop({
4049
- client: this.client.getClient(),
4050
- path: {
4051
- agent_id: this.response.agent_id
4052
- },
4053
- query: { session_id: this.response.session_id }
4054
- });
4055
- if (response?.error) {
4056
- throw new Error(`Failed to stop agent: ${formatError(response.error)}`);
4057
- }
4058
- console.log(`[Agent] ${this.response.agent_id} stopped`);
4059
- return response.data;
4060
- } catch (error) {
4061
- console.warn(`Failed to stop agent: ${error instanceof Error ? error.message : String(error)}`);
4062
- throw error;
4063
- } finally {
4064
- this.disconnectWebSocket();
4065
- }
4066
- }
4067
- /**
4068
- * Disconnect WebSocket
4069
- */
4070
- disconnectWebSocket() {
4071
- if (this.websocket) {
4072
- this.websocket.close();
4073
- this.websocket = null;
4074
- }
4075
- }
4076
- /**
4077
- * Get agent ID - mirrors Python agent_id property
4078
- */
4079
- get agentId() {
4080
- if (!this.response) {
4081
- throw new Error("You need to run the agent first to get the agent id");
4082
- }
4083
- return this.response.agent_id;
4084
- }
4085
- /**
4086
- * Get session ID - mirrors Python session_id property
4087
- */
4088
- get sessionId() {
4089
- if (!this.response) {
4090
- throw new Error("You need to run the agent first to get the session id");
4091
- }
4092
- return this.response.session_id;
4093
- }
4094
- /**
4095
- * Whether `start()`/`run()` was called on this instance (or it was built from an agent id).
4096
- * This is a local check and does not contact the API.
4097
- */
4098
- hasStarted() {
4099
- return this.response !== null;
4100
- }
4101
- /**
4102
- * Whether the agent is still active on the server. Fetches the current status,
4103
- * like calling `agent.status()` in Python; an agent that was never started is not active.
4104
- */
4105
- async isActive() {
4106
- if (!this.response) {
4107
- return false;
4108
- }
4109
- const status = await this.status();
4110
- return status.status === "active";
4111
- }
4112
- /**
4113
- * @deprecated Only reports whether this instance was started; it does not
4114
- * contact the API. Use `hasStarted()` for that check or `isActive()` for the
4115
- * live server status.
4116
- */
4117
- isRunning() {
4118
- return this.hasStarted();
4119
- }
4120
- };
4121
4187
 
4122
4188
  // src/vaults.ts
4123
4189
  var import_tldts = require("tldts");
@@ -4277,9 +4343,9 @@ var NotteVault = class {
4277
4343
  await this.delete();
4278
4344
  }
4279
4345
  /**
4280
- * Add or update the credentials stored for a website. The URL is reduced to
4281
- * its root domain (`https://github.com/login` → `github.com`) before it is
4282
- * sent, like Python's `AddCredentialsRequest`.
4346
+ * Add or update the credentials stored for a website. Values are sent as
4347
+ * supplied; the API validates credentials and reduces the URL to its root
4348
+ * domain (`https://github.com/login` → `github.com`).
4283
4349
  *
4284
4350
  * ```ts
4285
4351
  * await vault.addCredentials('https://github.com/', {
@@ -4290,13 +4356,11 @@ var NotteVault = class {
4290
4356
  * ```
4291
4357
  */
4292
4358
  async addCredentials(url, credentials) {
4293
- const domain = validateUrl(url);
4294
- validateCredentials(credentials);
4295
4359
  const vaultId = await this.ensureInitialized();
4296
4360
  await vaultCredentialsAdd({
4297
4361
  client: this.client.getClient(),
4298
4362
  path: { vault_id: vaultId },
4299
- body: { url: domain, credentials },
4363
+ body: { url, credentials },
4300
4364
  throwOnError: true
4301
4365
  });
4302
4366
  }
@@ -4310,12 +4374,11 @@ var NotteVault = class {
4310
4374
  * ```
4311
4375
  */
4312
4376
  async getCredentials(url) {
4313
- const domain = validateUrl(url);
4314
4377
  const vaultId = await this.ensureInitialized();
4315
4378
  const response = await vaultCredentialsGet({
4316
4379
  client: this.client.getClient(),
4317
4380
  path: { vault_id: vaultId },
4318
- query: { url: domain },
4381
+ query: { url },
4319
4382
  throwOnError: true
4320
4383
  });
4321
4384
  return response.data.credentials;
@@ -4343,12 +4406,11 @@ var NotteVault = class {
4343
4406
  * ```
4344
4407
  */
4345
4408
  async deleteCredentials(url) {
4346
- const domain = validateUrl(url);
4347
4409
  const vaultId = await this.ensureInitialized();
4348
4410
  await vaultCredentialsDelete({
4349
4411
  client: this.client.getClient(),
4350
4412
  path: { vault_id: vaultId },
4351
- query: { url: domain },
4413
+ query: { url },
4352
4414
  throwOnError: true
4353
4415
  });
4354
4416
  }
@@ -4393,7 +4455,7 @@ var NotteVault = class {
4393
4455
  * ```
4394
4456
  */
4395
4457
  async addCredentialsFromEnv(url) {
4396
- const rootDomain = validateUrl(url);
4458
+ const rootDomain = getRootDomain(url);
4397
4459
  const prefix = rootDomain.replace(/\./g, "_").toUpperCase();
4398
4460
  const credentials = {};
4399
4461
  const variableNames = [];
@@ -4469,6 +4531,10 @@ var NotteVault = class {
4469
4531
  };
4470
4532
 
4471
4533
  // src/personas.ts
4534
+ function withPersonaDefaults(persona) {
4535
+ if (!persona || persona.email_provider) return persona;
4536
+ return { ...persona, email_provider: "notte" };
4537
+ }
4472
4538
  var NottePersona = class {
4473
4539
  client;
4474
4540
  _initRequest;
@@ -4528,7 +4594,7 @@ var NottePersona = class {
4528
4594
  if (response?.error) {
4529
4595
  throw new Error(`Failed to get persona: ${formatError(response.error)}`);
4530
4596
  }
4531
- this.response = response.data;
4597
+ this.response = withPersonaDefaults(response.data);
4532
4598
  return this.response;
4533
4599
  }
4534
4600
  async initNewPersona(createData) {
@@ -4539,7 +4605,7 @@ var NottePersona = class {
4539
4605
  if (response?.error) {
4540
4606
  throw new Error(`Failed to create persona: ${formatError(response.error)}`);
4541
4607
  }
4542
- this.response = response.data;
4608
+ this.response = withPersonaDefaults(response.data);
4543
4609
  console.warn(
4544
4610
  `[Persona] ${this.response.persona_id} created since no persona id was provided. Please store this to retrieve it later.`
4545
4611
  );
@@ -4768,11 +4834,10 @@ async function offloadRunPayloads(client2, path, fields) {
4768
4834
  if (payload.length > MAX_PAYLOAD_BYTES) throw new Error(`Function run ${field} exceeds the payload limit`);
4769
4835
  if (payload.length <= INLINE_FIELD_BYTES) continue;
4770
4836
  const checksum = (0, import_node_crypto2.createHash)("sha256").update(payload).digest("base64");
4771
- const prepared = await client2.post({
4772
- url: "/functions/{function_id}/runs/{run_id}/payloads/{field}/upload",
4837
+ const prepared = await prepareRunPayloadUpload({
4838
+ client: client2,
4773
4839
  path: { ...path, field },
4774
4840
  body: { size_bytes: payload.length, sha256: checksum },
4775
- headers: { "Content-Type": "application/json" },
4776
4841
  throwOnError: true
4777
4842
  });
4778
4843
  const upload = prepared.data;
@@ -4848,7 +4913,6 @@ var FUNCTION_RUN_ENDPOINTS = {
4848
4913
  start: "/functions/{function_id}/runs/{run_id}"
4849
4914
  };
4850
4915
  var RUN_API_KEY_HEADER = "x-notte-api-key";
4851
- var FUNCTION_RUNTIMES = ["standard", "extended"];
4852
4916
  var FUNCTION_RUN_STATUSES = ["closed", "active", "failed"];
4853
4917
  var NotteFunction = class {
4854
4918
  client;
@@ -4951,7 +5015,7 @@ var NotteFunction = class {
4951
5015
  throwOnError: true,
4952
5016
  path: { function_id: functionId },
4953
5017
  query: {
4954
- restricted: options.restricted ?? true,
5018
+ restricted: options.restricted,
4955
5019
  ...options.version !== void 0 ? { version: options.version } : {}
4956
5020
  },
4957
5021
  body: { file }
@@ -5048,7 +5112,7 @@ var NotteFunction = class {
5048
5112
  client: this.client.getClient(),
5049
5113
  throwOnError: true,
5050
5114
  path: { function_id: functionId },
5051
- query: { restricted: options.restricted ?? true },
5115
+ query: { restricted: options.restricted },
5052
5116
  body: { version: options.version }
5053
5117
  });
5054
5118
  return response.data;
@@ -5144,7 +5208,7 @@ var NotteFunction = class {
5144
5208
  client: this.client.getClient(),
5145
5209
  throwOnError: true,
5146
5210
  path: { function_id: functionId },
5147
- query: { ...options, only_active: options.only_active ?? false }
5211
+ query: options
5148
5212
  });
5149
5213
  return response.data;
5150
5214
  }
@@ -5177,9 +5241,6 @@ var NotteFunction = class {
5177
5241
  if (!(timeoutMs > 0)) {
5178
5242
  throw new InvalidRequestError("timeoutMs must be a positive number");
5179
5243
  }
5180
- if (options.runtime !== void 0 && !FUNCTION_RUNTIMES.includes(options.runtime)) {
5181
- throw new InvalidRequestError(`runtime must be one of ${FUNCTION_RUNTIMES.join(", ")}, got '${String(options.runtime)}'`);
5182
- }
5183
5244
  const functionId = await this.ensureInitialized();
5184
5245
  const functionRunId = options.functionRunId ?? (await this.createRun()).function_run_id;
5185
5246
  const body = {
@@ -5522,7 +5583,7 @@ var SessionFiles = class {
5522
5583
  const response = await listSessionFiles({
5523
5584
  client: this.client,
5524
5585
  path: { session_id: this.sessionId },
5525
- query: { limit: options.limit ?? 100, offset: options.offset ?? 0, source: options.source },
5586
+ query: options,
5526
5587
  throwOnError: true
5527
5588
  });
5528
5589
  return response.data;
@@ -5931,6 +5992,7 @@ var DEFAULT_NOTTE_API_URL = "https://api.notte.cc";
5931
5992
  var DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
5932
5993
  var REQUEST_ORIGIN = "sdk-node";
5933
5994
  var TIMEOUT_HEADER = "x-notte-timeout-ms";
5995
+ var MAX_RETRIES_HEADER = "x-notte-max-retries";
5934
5996
  var DB_PREVIEW_ENV = "NOTTE_DB_PREVIEW_BRANCH";
5935
5997
  var DB_PREVIEW_HEADER = "x-db-preview";
5936
5998
  var EXECUTION_ERROR_CLASS = "NotteApiExecutionError";
@@ -5953,6 +6015,10 @@ var NotteClient3 = class {
5953
6015
  if (!(timeoutMs >= 0)) {
5954
6016
  throw new InvalidRequestError("timeoutMs must be a non-negative number");
5955
6017
  }
6018
+ const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
6019
+ if (!Number.isInteger(maxRetries) || maxRetries < 0) {
6020
+ throw new InvalidRequestError("maxRetries must be a non-negative integer");
6021
+ }
5956
6022
  const isProxyMode = isRelativeProxyUrl(baseUrl);
5957
6023
  if (!isProxyMode) {
5958
6024
  const url = new URL(baseUrl);
@@ -5968,7 +6034,15 @@ var NotteClient3 = class {
5968
6034
  "NOTTE_API_KEY needs to be provided. Pass config.apiKey or set the NOTTE_API_KEY environment variable."
5969
6035
  );
5970
6036
  }
5971
- this.config = { baseUrl, apiKey, timeoutMs, captchaTimeoutSeconds, dbPreview, verbose: config.verbose ?? false };
6037
+ this.config = {
6038
+ baseUrl,
6039
+ apiKey,
6040
+ timeoutMs,
6041
+ captchaTimeoutSeconds,
6042
+ dbPreview,
6043
+ maxRetries,
6044
+ verbose: config.verbose ?? false
6045
+ };
5972
6046
  if (baseUrl !== DEFAULT_NOTTE_API_URL && !isProxyMode) {
5973
6047
  console.warn(`NOTTE_API_URL is set to: ${baseUrl}`);
5974
6048
  }
@@ -5977,7 +6051,7 @@ var NotteClient3 = class {
5977
6051
  redirect: "manual",
5978
6052
  throwOnError: true
5979
6053
  });
5980
- this.client.interceptors.request.use((request) => {
6054
+ this.client.interceptors.request.use((request, opts) => {
5981
6055
  const headers = new Headers(request.headers);
5982
6056
  if (this.config.apiKey) headers.set("Authorization", `Bearer ${this.config.apiKey}`);
5983
6057
  headers.set("x-notte-request-origin", REQUEST_ORIGIN);
@@ -5985,16 +6059,25 @@ var NotteClient3 = class {
5985
6059
  if (this.config.dbPreview) headers.set(DB_PREVIEW_HEADER, this.config.dbPreview);
5986
6060
  const override = headers.get(TIMEOUT_HEADER);
5987
6061
  headers.delete(TIMEOUT_HEADER);
6062
+ const retriesOverride = headers.get(MAX_RETRIES_HEADER);
6063
+ headers.delete(MAX_RETRIES_HEADER);
5988
6064
  const timeoutMs2 = override !== null ? Number(override) : this.config.timeoutMs;
5989
6065
  if (this.config.verbose) {
5990
6066
  console.info(`Making \`${request.method}\` request to \`${request.url}\``);
5991
6067
  }
5992
- if (!(timeoutMs2 > 0)) {
5993
- return new Request(request, { headers });
5994
- }
5995
- const deadline = withTimeout(request.signal, timeoutMs2);
5996
- const timed = new Request(request, { headers, signal: deadline.signal });
5997
- pendingDeadlines.set(timed, deadline.release);
6068
+ const callerSignal = opts.signal ?? request.signal;
6069
+ const deadline = timeoutMs2 > 0 ? withTimeout(callerSignal, timeoutMs2) : void 0;
6070
+ const signal = deadline?.signal ?? callerSignal;
6071
+ const timed = new Request(request, { headers, signal });
6072
+ pendingRequests.set(timed, { signal, release: deadline?.release ?? (() => void 0), expiresAt: deadline?.expiresAt ?? Infinity });
6073
+ const transport = originalTransports.get(opts) ?? opts.fetch ?? globalThis.fetch;
6074
+ originalTransports.set(opts, transport);
6075
+ const retrying = createRetryingFetch({
6076
+ fetch: transport,
6077
+ maxRetries: () => retriesOverride !== null ? Number(retriesOverride) : this.config.maxRetries,
6078
+ deadline: () => deadline?.expiresAt
6079
+ });
6080
+ opts.fetch = (input, init) => retrying(input, { ...init, signal });
5998
6081
  return timed;
5999
6082
  });
6000
6083
  this.client.interceptors.response.use(async (response, request, opts) => {
@@ -6032,7 +6115,7 @@ var NotteClient3 = class {
6032
6115
  method: request.method,
6033
6116
  headers: headerRecord,
6034
6117
  body: opts.serializedBody ?? void 0,
6035
- signal: request.signal,
6118
+ signal: requestSignal(request),
6036
6119
  redirect: "manual"
6037
6120
  });
6038
6121
  currentUrl = location;
@@ -6080,14 +6163,15 @@ var NotteClient3 = class {
6080
6163
  if (error instanceof NotteAPIError) {
6081
6164
  return error;
6082
6165
  }
6083
- if (request?.signal.aborted) {
6084
- error = request.signal.reason ?? error;
6166
+ const signal = request && requestSignal(request);
6167
+ if (signal?.aborted) {
6168
+ error = signal.reason ?? error;
6085
6169
  }
6086
6170
  if (isTimeoutAbort(error)) {
6087
6171
  const target = request ? ` to \`${requestPath(request)}\`` : "";
6088
6172
  return new NotteTimeoutError(`Request${target} ${error.message}`, { cause: error });
6089
6173
  }
6090
- if (request?.signal.aborted) return error;
6174
+ if (signal?.aborted) return error;
6091
6175
  if (response) {
6092
6176
  const path = requestPath(request, response);
6093
6177
  const body = normalizeErrorBody(error);
@@ -6137,6 +6221,10 @@ var NotteClient3 = class {
6137
6221
  Session(options = {}) {
6138
6222
  return new Session(this, options);
6139
6223
  }
6224
+ /** Generated file operations; use Files(sessionId) for local file IO helpers. */
6225
+ get files() {
6226
+ return this.resources.files;
6227
+ }
6140
6228
  /** Access files owned by a specific session, including closed sessions. */
6141
6229
  Files(sessionId) {
6142
6230
  return new SessionFiles(this.getClient(), sessionId);
@@ -6155,12 +6243,6 @@ var NotteClient3 = class {
6155
6243
  FileStorage(sessionId) {
6156
6244
  return new RemoteFileStorage(this, sessionId);
6157
6245
  }
6158
- /**
6159
- * Create a new agent
6160
- */
6161
- Agent(options) {
6162
- return new Agent(this, options);
6163
- }
6164
6246
  /**
6165
6247
  * Create or access a vault
6166
6248
  */
@@ -6193,16 +6275,6 @@ var NotteClient3 = class {
6193
6275
  }
6194
6276
  };
6195
6277
  }
6196
- /** Client-bound agent API operations. `list()` retains its array return value. */
6197
- get agents() {
6198
- return {
6199
- ...this.resources.agents,
6200
- list: async (options = {}) => {
6201
- const response = await listAgents({ client: this.getClient(), query: options });
6202
- return response.data?.items ?? [];
6203
- }
6204
- };
6205
- }
6206
6278
  /** Client-bound vault API operations. `list()` retains its array return value. */
6207
6279
  get vaults() {
6208
6280
  return {
@@ -6251,14 +6323,18 @@ var NotteClient3 = class {
6251
6323
  * Personas client for listing and managing personas
6252
6324
  */
6253
6325
  get personas() {
6326
+ const personas = this.resources.personas;
6254
6327
  return {
6255
- ...this.resources.personas,
6328
+ ...personas,
6329
+ create: async (...args) => withPersonaDefaults(await personas.create(...args)),
6330
+ get: async (...args) => withPersonaDefaults(await personas.get(...args)),
6331
+ update: async (...args) => withPersonaDefaults(await personas.update(...args)),
6256
6332
  list: async (options) => {
6257
6333
  const response = await listPersonas({
6258
6334
  client: this.getClient(),
6259
6335
  query: options || {}
6260
6336
  });
6261
- return response.data?.items || [];
6337
+ return (response.data?.items || []).map(withPersonaDefaults);
6262
6338
  }
6263
6339
  };
6264
6340
  }
@@ -6304,18 +6380,18 @@ function isTimeoutAbort(error) {
6304
6380
  function timeoutReason(timeoutMs) {
6305
6381
  return new DOMException(`timed out after ${timeoutMs}ms`, "TimeoutError");
6306
6382
  }
6307
- var pendingDeadlines = /* @__PURE__ */ new WeakMap();
6383
+ var pendingRequests = /* @__PURE__ */ new WeakMap();
6384
+ var originalTransports = /* @__PURE__ */ new WeakMap();
6385
+ function requestSignal(request) {
6386
+ return pendingRequests.get(request)?.signal ?? request.signal;
6387
+ }
6308
6388
  function releaseDeadline(request) {
6309
- if (!request) return;
6310
- const release = pendingDeadlines.get(request);
6311
- if (release) {
6312
- pendingDeadlines.delete(request);
6313
- release();
6314
- }
6389
+ if (request) pendingRequests.get(request)?.release();
6315
6390
  }
6316
6391
  function withTimeout(signal, timeoutMs) {
6317
6392
  const controller = new AbortController();
6318
6393
  const timer = setTimeout(() => controller.abort(timeoutReason(timeoutMs)), timeoutMs);
6394
+ const expiresAt = Date.now() + timeoutMs;
6319
6395
  timer.unref?.();
6320
6396
  let detach = () => void 0;
6321
6397
  let composite;
@@ -6342,7 +6418,7 @@ function withTimeout(signal, timeoutMs) {
6342
6418
  detach();
6343
6419
  };
6344
6420
  composite.addEventListener("abort", release, { once: true });
6345
- return { signal: composite, release };
6421
+ return { signal: composite, release, expiresAt };
6346
6422
  }
6347
6423
 
6348
6424
  // src/actions.ts
@@ -6436,11 +6512,11 @@ var createClient2 = (config) => {
6436
6512
  // Annotate the CommonJS export names for ESM import in node:
6437
6513
  0 && (module.exports = {
6438
6514
  ActionExecutionError,
6439
- Agent,
6440
6515
  AuthenticationError,
6441
6516
  CAPTCHA_SOLVE_TIMEOUT_MS,
6442
6517
  CLUSTER_OVERLOAD_RETRY_DELAY_MS,
6443
6518
  CREDENTIAL_FIELDS,
6519
+ DEFAULT_MAX_RETRIES,
6444
6520
  DEFAULT_NOTTE_API_URL,
6445
6521
  DEFAULT_REQUEST_TIMEOUT_MS,
6446
6522
  Encryption,
@@ -6475,12 +6551,17 @@ var createClient2 = (config) => {
6475
6551
  Session,
6476
6552
  SessionFiles,
6477
6553
  TIMEOUT_HEADER,
6554
+ accountChanges,
6555
+ accountRuns,
6478
6556
  actions,
6479
6557
  agentStart,
6480
6558
  agentStatus,
6481
6559
  agentStop,
6482
6560
  anythingStart,
6561
+ attempts,
6562
+ brandRetrieve,
6483
6563
  buildFetchScript,
6564
+ changes,
6484
6565
  checkForLatestVersion,
6485
6566
  client,
6486
6567
  connectLinkContext,
@@ -6490,14 +6571,22 @@ var createClient2 = (config) => {
6490
6571
  connectLinkStatus,
6491
6572
  connectLinkSubmit,
6492
6573
  connectPaymentWallet,
6574
+ create,
6493
6575
  createClient,
6494
6576
  createOrAppendCookiesToFile,
6495
6577
  createPayment,
6578
+ creditUsage,
6496
6579
  deleteSecret,
6497
6580
  deleteSessionFile,
6581
+ delete_,
6582
+ deliveries,
6583
+ detail,
6498
6584
  disconnectPaymentWallet,
6499
6585
  downloadRunPayload,
6500
6586
  downloadSessionFile,
6587
+ executeSessionFile,
6588
+ extractProductEndpoint,
6589
+ fetchSpecializedData,
6501
6590
  functionCreate,
6502
6591
  functionDelete,
6503
6592
  functionDownloadUrl,
@@ -6513,6 +6602,7 @@ var createClient2 = (config) => {
6513
6602
  functionScheduleSet,
6514
6603
  functionUpdate,
6515
6604
  getPayment,
6605
+ getPolicy,
6516
6606
  getRootDomain,
6517
6607
  getScript,
6518
6608
  getSecret,
@@ -6520,13 +6610,18 @@ var createClient2 = (config) => {
6520
6610
  getUsage,
6521
6611
  getUsageLogs,
6522
6612
  healthCheck,
6523
- improvePrompt,
6613
+ history_,
6524
6614
  installServerOwnedDialogPolicy,
6615
+ invalidate,
6525
6616
  isCaptchaSolveAction,
6526
6617
  isValidMfaSecret,
6618
+ limits,
6527
6619
  listAgents,
6620
+ listAuditEvents,
6621
+ listDataApis,
6528
6622
  listFunctionRunsByFunctionId,
6529
6623
  listFunctions,
6624
+ listMonitors,
6530
6625
  listPersonas,
6531
6626
  listSecrets,
6532
6627
  listSessionFiles,
@@ -6539,20 +6634,20 @@ var createClient2 = (config) => {
6539
6634
  mailboxSync,
6540
6635
  mailboxUpdate,
6541
6636
  managedAuthConnectLinkCreate,
6542
- nudgePrompt,
6637
+ mapsSearch,
6638
+ newsSearch,
6543
6639
  observeServerOwnedDialog,
6544
6640
  pageExecute,
6545
6641
  pageObserve,
6546
6642
  pageScrape,
6547
6643
  pageScreenshot,
6548
- parseAgentStatusMessage,
6644
+ peopleEnrich,
6549
6645
  personaCreate,
6550
6646
  personaDelete,
6551
6647
  personaEmailsList,
6552
6648
  personaGet,
6553
6649
  personaSmsList,
6554
6650
  personaUpdate,
6555
- prepareAgentRequest,
6556
6651
  prepareRunPayloadUpload,
6557
6652
  processScrapeResponse,
6558
6653
  profileCookiesGet,
@@ -6562,27 +6657,42 @@ var createClient2 = (config) => {
6562
6657
  profileDuplicate,
6563
6658
  profileGet,
6564
6659
  profileList,
6660
+ profileStateSet,
6565
6661
  readCookiesFile,
6566
6662
  readyCheck,
6567
6663
  responseFromEvaluated,
6664
+ retrieve,
6665
+ retrieveChange,
6666
+ retrieveDelivery,
6667
+ retrieveRun,
6568
6668
  retry,
6669
+ retryWebhookDelivery,
6670
+ rotateSecret,
6671
+ runNow,
6672
+ runs,
6569
6673
  sanitizeFilename,
6570
6674
  scrapeFromHtml,
6675
+ scrapeSpecializedData,
6571
6676
  scrapeWebpage,
6572
6677
  searchWeb,
6573
6678
  sessionAuthReadiness,
6574
6679
  sessionCookiesGet,
6575
6680
  sessionCookiesSet,
6576
6681
  sessionDebugInfo,
6682
+ sessionMouseReplay,
6577
6683
  sessionNetworkLogs,
6578
6684
  sessionOffset,
6579
6685
  sessionProfilePreview,
6686
+ sessionProfileSave,
6580
6687
  sessionReplay,
6581
6688
  sessionStart,
6582
6689
  sessionStatus,
6583
6690
  sessionStop,
6584
6691
  startVersionCheck,
6585
6692
  storeSecret,
6693
+ styleguideEndpoint,
6694
+ summary,
6695
+ update,
6586
6696
  uploadSessionFile,
6587
6697
  validateCredentials,
6588
6698
  validateMfaSecret,
@@ -6596,6 +6706,7 @@ var createClient2 = (config) => {
6596
6706
  vaultCreditCardGet,
6597
6707
  vaultCreditCardSet,
6598
6708
  vaultDelete,
6599
- vaultUpdate
6709
+ vaultUpdate,
6710
+ youtubeEndpoint
6600
6711
  });
6601
6712
  //# sourceMappingURL=index.js.map