@browserbasehq/sdk 1.5.0 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +198 -4
  3. package/README.md +266 -76
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +13 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +88 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +77 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +240 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +903 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +871 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +132 -0
  87. package/index.d.ts +132 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +115 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +87 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +93 -31
  94. package/resource.d.ts +6 -0
  95. package/resource.d.ts.map +1 -0
  96. package/resource.js +11 -0
  97. package/resource.js.map +1 -0
  98. package/resource.mjs +7 -0
  99. package/resource.mjs.map +1 -0
  100. package/resources/contexts.d.ts +82 -0
  101. package/resources/contexts.d.ts.map +1 -0
  102. package/resources/contexts.js +29 -0
  103. package/resources/contexts.js.map +1 -0
  104. package/resources/contexts.mjs +25 -0
  105. package/resources/contexts.mjs.map +1 -0
  106. package/resources/extensions.d.ts +35 -0
  107. package/resources/extensions.d.ts.map +1 -0
  108. package/resources/extensions.js +56 -0
  109. package/resources/extensions.js.map +1 -0
  110. package/resources/extensions.mjs +29 -0
  111. package/resources/extensions.mjs.map +1 -0
  112. package/resources/index.d.ts +5 -0
  113. package/resources/index.d.ts.map +1 -0
  114. package/resources/index.js +13 -0
  115. package/resources/index.js.map +1 -0
  116. package/resources/index.mjs +6 -0
  117. package/resources/index.mjs.map +1 -0
  118. package/resources/projects.d.ts +36 -0
  119. package/resources/projects.d.ts.map +1 -0
  120. package/resources/projects.js +29 -0
  121. package/resources/projects.js.map +1 -0
  122. package/resources/projects.mjs +25 -0
  123. package/resources/projects.mjs.map +1 -0
  124. package/resources/sessions/downloads.d.ts +10 -0
  125. package/resources/sessions/downloads.d.ts.map +1 -0
  126. package/resources/sessions/downloads.js +15 -0
  127. package/resources/sessions/downloads.js.map +1 -0
  128. package/resources/sessions/downloads.mjs +11 -0
  129. package/resources/sessions/downloads.mjs.map +1 -0
  130. package/resources/sessions/index.d.ts +6 -0
  131. package/resources/sessions/index.d.ts.map +1 -0
  132. package/resources/sessions/index.js +15 -0
  133. package/resources/sessions/index.js.map +1 -0
  134. package/resources/sessions/index.mjs +7 -0
  135. package/resources/sessions/index.mjs.map +1 -0
  136. package/resources/sessions/logs.d.ts +47 -0
  137. package/resources/sessions/logs.d.ts.map +1 -0
  138. package/resources/sessions/logs.js +17 -0
  139. package/resources/sessions/logs.js.map +1 -0
  140. package/resources/sessions/logs.mjs +13 -0
  141. package/resources/sessions/logs.mjs.map +1 -0
  142. package/resources/sessions/recording.d.ts +29 -0
  143. package/resources/sessions/recording.d.ts.map +1 -0
  144. package/resources/sessions/recording.js +17 -0
  145. package/resources/sessions/recording.js.map +1 -0
  146. package/resources/sessions/recording.mjs +13 -0
  147. package/resources/sessions/recording.mjs.map +1 -0
  148. package/resources/sessions/sessions.d.ts +338 -0
  149. package/resources/sessions/sessions.d.ts.map +1 -0
  150. package/resources/sessions/sessions.js +80 -0
  151. package/resources/sessions/sessions.js.map +1 -0
  152. package/resources/sessions/sessions.mjs +53 -0
  153. package/resources/sessions/sessions.mjs.map +1 -0
  154. package/resources/sessions/uploads.d.ts +20 -0
  155. package/resources/sessions/uploads.d.ts.map +1 -0
  156. package/resources/sessions/uploads.js +41 -0
  157. package/resources/sessions/uploads.js.map +1 -0
  158. package/resources/sessions/uploads.mjs +14 -0
  159. package/resources/sessions/uploads.mjs.map +1 -0
  160. package/shims/node.d.ts +26 -0
  161. package/shims/node.d.ts.map +1 -0
  162. package/shims/node.js +6 -0
  163. package/shims/node.js.map +1 -0
  164. package/shims/node.mjs +4 -0
  165. package/shims/node.mjs.map +1 -0
  166. package/shims/web.d.ts +26 -0
  167. package/shims/web.d.ts.map +1 -0
  168. package/shims/web.js +6 -0
  169. package/shims/web.js.map +1 -0
  170. package/shims/web.mjs +4 -0
  171. package/shims/web.mjs.map +1 -0
  172. package/src/_shims/MultipartBody.ts +9 -0
  173. package/src/_shims/README.md +46 -0
  174. package/src/_shims/auto/runtime-bun.ts +4 -0
  175. package/src/_shims/auto/runtime-node.ts +4 -0
  176. package/src/_shims/auto/runtime.ts +4 -0
  177. package/src/_shims/auto/types-node.ts +4 -0
  178. package/src/_shims/auto/types.d.ts +101 -0
  179. package/src/_shims/auto/types.js +3 -0
  180. package/src/_shims/auto/types.mjs +3 -0
  181. package/src/_shims/bun-runtime.ts +14 -0
  182. package/src/_shims/index.d.ts +81 -0
  183. package/src/_shims/index.js +13 -0
  184. package/src/_shims/index.mjs +7 -0
  185. package/src/_shims/manual-types.d.ts +12 -0
  186. package/src/_shims/manual-types.js +3 -0
  187. package/src/_shims/manual-types.mjs +3 -0
  188. package/src/_shims/node-runtime.ts +81 -0
  189. package/src/_shims/node-types.d.ts +42 -0
  190. package/src/_shims/node-types.js +3 -0
  191. package/src/_shims/node-types.mjs +3 -0
  192. package/src/_shims/registry.ts +67 -0
  193. package/src/_shims/web-runtime.ts +103 -0
  194. package/src/_shims/web-types.d.ts +83 -0
  195. package/src/_shims/web-types.js +3 -0
  196. package/src/_shims/web-types.mjs +3 -0
  197. package/src/core.ts +1197 -0
  198. package/src/error.ts +146 -0
  199. package/src/index.ts +210 -0
  200. package/src/lib/.keep +4 -0
  201. package/src/resource.ts +11 -0
  202. package/src/resources/contexts.ts +108 -0
  203. package/src/resources/extensions.ts +55 -0
  204. package/src/resources/index.ts +21 -0
  205. package/src/resources/projects.ts +56 -0
  206. package/src/resources/sessions/downloads.ts +14 -0
  207. package/src/resources/sessions/index.ts +16 -0
  208. package/src/resources/sessions/logs.ts +68 -0
  209. package/src/resources/sessions/recording.ts +40 -0
  210. package/src/resources/sessions/sessions.ts +451 -0
  211. package/src/resources/sessions/uploads.ts +34 -0
  212. package/src/shims/node.ts +50 -0
  213. package/src/shims/web.ts +50 -0
  214. package/src/tsconfig.json +11 -0
  215. package/src/uploads.ts +256 -0
  216. package/src/version.ts +1 -0
  217. package/uploads.d.ts +75 -0
  218. package/uploads.d.ts.map +1 -0
  219. package/uploads.js +170 -0
  220. package/uploads.js.map +1 -0
  221. package/uploads.mjs +157 -0
  222. package/uploads.mjs.map +1 -0
  223. package/version.d.ts +2 -0
  224. package/version.d.ts.map +1 -0
  225. package/version.js +5 -0
  226. package/version.js.map +1 -0
  227. package/version.mjs +2 -0
  228. package/version.mjs.map +1 -0
  229. package/dist/index.d.ts +0 -138
  230. package/dist/index.js +0 -228
  231. package/dist/integrations/ai-sdk.d.ts +0 -18
  232. package/dist/integrations/ai-sdk.js +0 -19
  233. package/dist/recorder/call-metadata.d.ts +0 -66
  234. package/dist/recorder/call-metadata.js +0 -2
  235. package/dist/recorder/crypto.d.ts +0 -1
  236. package/dist/recorder/crypto.js +0 -10
  237. package/dist/recorder/css-utils.d.ts +0 -2
  238. package/dist/recorder/css-utils.js +0 -34
  239. package/dist/recorder/generator.d.ts +0 -31
  240. package/dist/recorder/generator.js +0 -154
  241. package/dist/recorder/javascript-generator.d.ts +0 -29
  242. package/dist/recorder/javascript-generator.js +0 -256
  243. package/dist/recorder/language.d.ts +0 -127
  244. package/dist/recorder/language.js +0 -21
  245. package/dist/recorder/recorder-types.d.ts +0 -108
  246. package/dist/recorder/recorder-types.js +0 -2
  247. package/dist/recorder/recorder.d.ts +0 -35
  248. package/dist/recorder/recorder.js +0 -333
  249. package/dist/recorder/time.d.ts +0 -1
  250. package/dist/recorder/time.js +0 -42
  251. package/dist/recorder/timeout-runner.d.ts +0 -6
  252. package/dist/recorder/timeout-runner.js +0 -19
  253. package/dist/recorder/utils/isomorphic/css-parser.d.ts +0 -41
  254. package/dist/recorder/utils/isomorphic/css-parser.js +0 -291
  255. package/dist/recorder/utils/isomorphic/css-tokenizer.d.ts +0 -171
  256. package/dist/recorder/utils/isomorphic/css-tokenizer.js +0 -986
  257. package/dist/recorder/utils/isomorphic/locator-generators.d.ts +0 -79
  258. package/dist/recorder/utils/isomorphic/locator-generators.js +0 -666
  259. package/dist/recorder/utils/isomorphic/locator-parser.d.ts +0 -17
  260. package/dist/recorder/utils/isomorphic/locator-parser.js +0 -244
  261. package/dist/recorder/utils/isomorphic/locator-utils.d.ts +0 -43
  262. package/dist/recorder/utils/isomorphic/locator-utils.js +0 -69
  263. package/dist/recorder/utils/isomorphic/selector-parser.d.ts +0 -48
  264. package/dist/recorder/utils/isomorphic/selector-parser.js +0 -483
  265. package/dist/recorder/utils/isomorphic/string-utils.d.ts +0 -28
  266. package/dist/recorder/utils/isomorphic/string-utils.js +0 -123
  267. package/dist/recorder/utils.d.ts +0 -20
  268. package/dist/recorder/utils.js +0 -32
package/uploads.mjs ADDED
@@ -0,0 +1,157 @@
1
+ import { FormData, File, getMultipartRequestOptions, isFsReadStream, } from "./_shims/index.mjs";
2
+ export { fileFromPath } from "./_shims/index.mjs";
3
+ export const isResponseLike = (value) => value != null &&
4
+ typeof value === 'object' &&
5
+ typeof value.url === 'string' &&
6
+ typeof value.blob === 'function';
7
+ export const isFileLike = (value) => value != null &&
8
+ typeof value === 'object' &&
9
+ typeof value.name === 'string' &&
10
+ typeof value.lastModified === 'number' &&
11
+ isBlobLike(value);
12
+ /**
13
+ * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
14
+ * adds the arrayBuffer() method type because it is available and used at runtime
15
+ */
16
+ export const isBlobLike = (value) => value != null &&
17
+ typeof value === 'object' &&
18
+ typeof value.size === 'number' &&
19
+ typeof value.type === 'string' &&
20
+ typeof value.text === 'function' &&
21
+ typeof value.slice === 'function' &&
22
+ typeof value.arrayBuffer === 'function';
23
+ export const isUploadable = (value) => {
24
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
25
+ };
26
+ /**
27
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
28
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
29
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
30
+ * @param {Object=} options additional properties
31
+ * @param {string=} options.type the MIME type of the content
32
+ * @param {number=} options.lastModified the last modified timestamp
33
+ * @returns a {@link File} with the given properties
34
+ */
35
+ export async function toFile(value, name, options) {
36
+ // If it's a promise, resolve it.
37
+ value = await value;
38
+ // If we've been given a `File` we don't need to do anything
39
+ if (isFileLike(value)) {
40
+ return value;
41
+ }
42
+ if (isResponseLike(value)) {
43
+ const blob = await value.blob();
44
+ name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
45
+ // we need to convert the `Blob` into an array buffer because the `Blob` class
46
+ // that `node-fetch` defines is incompatible with the web standard which results
47
+ // in `new File` interpreting it as a string instead of binary data.
48
+ const data = isBlobLike(blob) ? [(await blob.arrayBuffer())] : [blob];
49
+ return new File(data, name, options);
50
+ }
51
+ const bits = await getBytes(value);
52
+ name || (name = getName(value) ?? 'unknown_file');
53
+ if (!options?.type) {
54
+ const type = bits[0]?.type;
55
+ if (typeof type === 'string') {
56
+ options = { ...options, type };
57
+ }
58
+ }
59
+ return new File(bits, name, options);
60
+ }
61
+ async function getBytes(value) {
62
+ let parts = [];
63
+ if (typeof value === 'string' ||
64
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
65
+ value instanceof ArrayBuffer) {
66
+ parts.push(value);
67
+ }
68
+ else if (isBlobLike(value)) {
69
+ parts.push(await value.arrayBuffer());
70
+ }
71
+ else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
72
+ ) {
73
+ for await (const chunk of value) {
74
+ parts.push(chunk); // TODO, consider validating?
75
+ }
76
+ }
77
+ else {
78
+ throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
79
+ }
80
+ return parts;
81
+ }
82
+ function propsForError(value) {
83
+ const props = Object.getOwnPropertyNames(value);
84
+ return `[${props.map((p) => `"${p}"`).join(', ')}]`;
85
+ }
86
+ function getName(value) {
87
+ return (getStringFromMaybeBuffer(value.name) ||
88
+ getStringFromMaybeBuffer(value.filename) ||
89
+ // For fs.ReadStream
90
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop());
91
+ }
92
+ const getStringFromMaybeBuffer = (x) => {
93
+ if (typeof x === 'string')
94
+ return x;
95
+ if (typeof Buffer !== 'undefined' && x instanceof Buffer)
96
+ return String(x);
97
+ return undefined;
98
+ };
99
+ const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
100
+ export const isMultipartBody = (body) => body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
101
+ /**
102
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
103
+ * Otherwise returns the request as is.
104
+ */
105
+ export const maybeMultipartFormRequestOptions = async (opts) => {
106
+ if (!hasUploadableValue(opts.body))
107
+ return opts;
108
+ const form = await createForm(opts.body);
109
+ return getMultipartRequestOptions(form, opts);
110
+ };
111
+ export const multipartFormRequestOptions = async (opts) => {
112
+ const form = await createForm(opts.body);
113
+ return getMultipartRequestOptions(form, opts);
114
+ };
115
+ export const createForm = async (body) => {
116
+ const form = new FormData();
117
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
118
+ return form;
119
+ };
120
+ const hasUploadableValue = (value) => {
121
+ if (isUploadable(value))
122
+ return true;
123
+ if (Array.isArray(value))
124
+ return value.some(hasUploadableValue);
125
+ if (value && typeof value === 'object') {
126
+ for (const k in value) {
127
+ if (hasUploadableValue(value[k]))
128
+ return true;
129
+ }
130
+ }
131
+ return false;
132
+ };
133
+ const addFormValue = async (form, key, value) => {
134
+ if (value === undefined)
135
+ return;
136
+ if (value == null) {
137
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
138
+ }
139
+ // TODO: make nested formats configurable
140
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
141
+ form.append(key, String(value));
142
+ }
143
+ else if (isUploadable(value)) {
144
+ const file = await toFile(value);
145
+ form.append(key, file);
146
+ }
147
+ else if (Array.isArray(value)) {
148
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
149
+ }
150
+ else if (typeof value === 'object') {
151
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
152
+ }
153
+ else {
154
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
155
+ }
156
+ };
157
+ //# sourceMappingURL=uploads.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":"OACO,EACL,QAAQ,EACR,IAAI,EAGJ,0BAA0B,EAE1B,cAAc,GACf;OAEM,EAAE,YAAY,EAAE;AAiDvB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAU,EAAyB,EAAE,CAClE,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;IAC7B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAEnC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAU,EAAqB,EAAE,CAC1D,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ;IACtC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEpB;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CACpG,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;IAChC,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;IACjC,OAAO,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC;AAE1C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAU,EAAuB,EAAE;IAC9D,OAAO,UAAU,CAAC,KAA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CAAyC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QACzF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,CAAC;SAAM,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAY,CAAC,CAAC;IACjC,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACjF,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
package/version.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "2.0.0-alpha.1";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,kBAAkB,CAAC"}
package/version.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = '2.0.0-alpha.1'; // x-release-please-version
5
+ //# sourceMappingURL=version.js.map
package/version.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,eAAe,CAAC,CAAC,2BAA2B"}
package/version.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export const VERSION = '2.0.0-alpha.1'; // x-release-please-version
2
+ //# sourceMappingURL=version.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,2BAA2B"}
package/dist/index.d.ts DELETED
@@ -1,138 +0,0 @@
1
- import BrowserbaseAISDK from './integrations/ai-sdk.js';
2
- import { BrowserbaseCodeGenerator, type GeneratorOptions, type ActionsEvent } from './recorder/recorder';
3
- export type ClientOptions = {
4
- apiKey?: string;
5
- projectId?: string;
6
- baseURL?: string;
7
- baseConnectURL?: string;
8
- };
9
- export type ConnectOptions = {
10
- sessionId?: string;
11
- proxy?: boolean;
12
- };
13
- export type LoadOptions = {
14
- textContent?: boolean;
15
- } & ConnectOptions;
16
- export type ScreenshotOptions = {
17
- fullPage?: boolean;
18
- } & ConnectOptions;
19
- export type CreateSessionOptions = {
20
- projectId?: string;
21
- extensionId?: string;
22
- browserSettings?: {
23
- fingerprint?: {
24
- browserListQuery?: string;
25
- httpVersion?: 1 | 2;
26
- browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>;
27
- devices?: Array<'desktop' | 'mobile'>;
28
- locales?: string[];
29
- operatingSystems?: Array<'windows' | 'macos' | 'linux' | 'ios' | 'android'>;
30
- screen?: {
31
- maxHeight?: number;
32
- maxWidth?: number;
33
- minHeight?: number;
34
- minWidth?: number;
35
- };
36
- };
37
- viewport?: {
38
- width?: number;
39
- height?: number;
40
- };
41
- context?: {
42
- id: string;
43
- persist: boolean;
44
- };
45
- blockAds?: boolean;
46
- solveCaptchas?: boolean;
47
- recordSession?: boolean;
48
- logSession?: boolean;
49
- };
50
- keepAlive?: boolean;
51
- timeout?: number;
52
- proxies?: boolean | Array<{
53
- type: 'browserbase';
54
- geolocation?: {
55
- country: string;
56
- state?: string;
57
- city?: string;
58
- };
59
- domainPattern?: string;
60
- } | {
61
- type: 'external';
62
- server: string;
63
- domainPattern?: string;
64
- username?: string;
65
- password?: string;
66
- }>;
67
- };
68
- export type Session = {
69
- id: string;
70
- createdAt: string;
71
- startedAt: string;
72
- endedAt?: string;
73
- expiresAt: string;
74
- projectId: string;
75
- status: 'RUNNING' | 'COMPLETED' | 'ERROR' | 'TIMED_OUT';
76
- proxyBytes?: number;
77
- keepAlive: boolean;
78
- contextId?: string;
79
- };
80
- export type SessionRecording = {
81
- type?: number;
82
- time?: string;
83
- data?: any;
84
- };
85
- export type DebugConnectionURLs = {
86
- debuggerFullscreenUrl?: string;
87
- debuggerUrl?: string;
88
- wsUrl?: string;
89
- pages?: DebugConnectionPage;
90
- };
91
- export type DebugConnectionPage = {
92
- id: string;
93
- url: string;
94
- title: string;
95
- debuggerUrl: string;
96
- debuggerFullscreenUrl: string;
97
- };
98
- export type SessionLog = {
99
- sessionId?: string;
100
- id: string;
101
- timestamp?: string;
102
- method?: string;
103
- request?: {
104
- timestamp?: string;
105
- params?: any;
106
- rawBody?: string;
107
- };
108
- response?: {
109
- timestamp?: string;
110
- result?: any;
111
- rawBody?: string;
112
- };
113
- pageId?: string;
114
- };
115
- export default class Browserbase {
116
- private apiKey;
117
- private projectId;
118
- private baseAPIURL;
119
- private baseConnectURL;
120
- constructor(options?: ClientOptions);
121
- getConnectURL({ sessionId, proxy }?: ConnectOptions): string;
122
- listSessions(): Promise<Session[]>;
123
- createSession(options?: CreateSessionOptions): Promise<Session>;
124
- completeSession(sessionId: string): Promise<Session>;
125
- getSession(sessionId: string): Promise<Session>;
126
- getSessionRecording(sessionId: string): Promise<SessionRecording[]>;
127
- getSessionDownloads(sessionId: string, retryInterval?: number, retryCount?: number): Promise<Buffer>;
128
- getDebugConnectionURLs(sessionId: string): Promise<DebugConnectionURLs>;
129
- getSessionLogs(sessionId: string): Promise<SessionLog[]>;
130
- load(url: string | string[], options?: LoadOptions): Promise<string> | AsyncGenerator<string, any, unknown>;
131
- loadURL(url: string, options?: LoadOptions): Promise<string>;
132
- loadURLs(urls: string[], options?: LoadOptions): AsyncGenerator<string>;
133
- screenshot(url: string, options?: ScreenshotOptions): Promise<Buffer>;
134
- createContext(): Promise<{
135
- id: string;
136
- }>;
137
- }
138
- export { Browserbase, BrowserbaseAISDK, BrowserbaseCodeGenerator, type GeneratorOptions, type ActionsEvent, };
package/dist/index.js DELETED
@@ -1,228 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BrowserbaseCodeGenerator = exports.BrowserbaseAISDK = exports.Browserbase = void 0;
7
- const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
8
- const ai_sdk_js_1 = __importDefault(require("./integrations/ai-sdk.js"));
9
- exports.BrowserbaseAISDK = ai_sdk_js_1.default;
10
- const recorder_1 = require("./recorder/recorder");
11
- Object.defineProperty(exports, "BrowserbaseCodeGenerator", { enumerable: true, get: function () { return recorder_1.BrowserbaseCodeGenerator; } });
12
- class Browserbase {
13
- apiKey;
14
- projectId;
15
- baseAPIURL;
16
- baseConnectURL;
17
- constructor(options = {}) {
18
- this.apiKey = options.apiKey || process.env.BROWSERBASE_API_KEY;
19
- this.projectId = options.projectId || process.env.BROWSERBASE_PROJECT_ID;
20
- this.baseAPIURL = options.baseURL || 'https://api.browserbase.com';
21
- this.baseConnectURL =
22
- options.baseConnectURL || 'wss://connect.browserbase.com';
23
- }
24
- getConnectURL({ sessionId, proxy = false } = {}) {
25
- return `${this.baseConnectURL}?apiKey=${this.apiKey}${sessionId ? `&sessionId=${sessionId}` : ''}${proxy ? `&enableProxy=true` : ''}`;
26
- }
27
- async listSessions() {
28
- const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
29
- headers: {
30
- 'x-bb-api-key': this.apiKey,
31
- 'Content-Type': 'application/json',
32
- },
33
- });
34
- return await response.json();
35
- }
36
- async createSession(options) {
37
- const mergedOptions = { projectId: this.projectId, ...options };
38
- if (!mergedOptions.projectId) {
39
- throw new Error('a projectId is missing: use the options.projectId or BROWSERBASE_PROJECT_ID environment variable to set one.');
40
- }
41
- const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
42
- method: 'POST',
43
- headers: {
44
- 'x-bb-api-key': this.apiKey,
45
- 'Content-Type': 'application/json',
46
- },
47
- body: JSON.stringify(mergedOptions),
48
- });
49
- return await response.json();
50
- }
51
- async completeSession(sessionId) {
52
- if (!sessionId || sessionId === '') {
53
- throw new Error('sessionId is required');
54
- }
55
- if (!this.projectId) {
56
- throw new Error('a projectId is missing: use the options.projectId or BROWSERBASE_PROJECT_ID environment variable to set one.');
57
- }
58
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}`, {
59
- method: 'POST',
60
- headers: {
61
- 'x-bb-api-key': this.apiKey,
62
- 'Content-Type': 'application/json',
63
- },
64
- body: JSON.stringify({
65
- projectId: this.projectId,
66
- status: 'REQUEST_RELEASE',
67
- }),
68
- });
69
- return await response.json();
70
- }
71
- async getSession(sessionId) {
72
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}`, {
73
- headers: {
74
- 'x-bb-api-key': this.apiKey,
75
- 'Content-Type': 'application/json',
76
- },
77
- });
78
- return await response.json();
79
- }
80
- async getSessionRecording(sessionId) {
81
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/recording`, {
82
- headers: {
83
- 'x-bb-api-key': this.apiKey,
84
- 'Content-Type': 'application/json',
85
- },
86
- });
87
- return await response.json();
88
- }
89
- async getSessionDownloads(sessionId, retryInterval = 2000, retryCount = 2) {
90
- return new Promise((resolve, reject) => {
91
- const fetchDownload = async () => {
92
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`, {
93
- method: 'GET',
94
- headers: {
95
- 'x-bb-api-key': this.apiKey,
96
- },
97
- });
98
- const arrayBuffer = await response.arrayBuffer();
99
- if (arrayBuffer.byteLength > 0) {
100
- resolve(Buffer.from(arrayBuffer));
101
- }
102
- else {
103
- retryCount--;
104
- if (retryCount <= 0) {
105
- reject();
106
- }
107
- setTimeout(fetchDownload, retryInterval);
108
- }
109
- };
110
- fetchDownload();
111
- });
112
- }
113
- async getDebugConnectionURLs(sessionId) {
114
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/debug`, {
115
- method: 'GET',
116
- headers: {
117
- 'x-bb-api-key': this.apiKey,
118
- 'Content-Type': 'application/json',
119
- },
120
- });
121
- const json = await response.json();
122
- return json;
123
- }
124
- async getSessionLogs(sessionId) {
125
- const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`, {
126
- headers: {
127
- 'x-bb-api-key': this.apiKey,
128
- 'Content-Type': 'application/json',
129
- },
130
- });
131
- return await response.json();
132
- }
133
- load(url, options = {}) {
134
- if (typeof url === 'string') {
135
- return this.loadURL(url, options);
136
- }
137
- else if (Array.isArray(url)) {
138
- return this.loadURLs(url, options);
139
- }
140
- else {
141
- throw new TypeError('Input must be a URL string or array of URLs');
142
- }
143
- }
144
- async loadURL(url, options = {}) {
145
- if (!url) {
146
- throw new Error('Page URL was not provided');
147
- }
148
- const browser = await puppeteer_core_1.default.connect({
149
- browserWSEndpoint: this.getConnectURL({
150
- sessionId: options.sessionId,
151
- proxy: options.proxy,
152
- }),
153
- });
154
- const pages = await browser.pages();
155
- const page = pages[0];
156
- await page.goto(url);
157
- let html = await page.content();
158
- if (options.textContent) {
159
- const readable = await page.evaluate(`
160
- import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
161
- return new readability.Readability(document).parse()
162
- })`);
163
- html = `${readable.title}\n${readable.textContent}`;
164
- }
165
- await browser.close();
166
- return html;
167
- }
168
- async *loadURLs(urls, options = {}) {
169
- if (!urls.length) {
170
- throw new Error('Page URLs were not provided');
171
- }
172
- const browser = await puppeteer_core_1.default.connect({
173
- browserWSEndpoint: this.getConnectURL({
174
- sessionId: options.sessionId,
175
- proxy: options.proxy,
176
- }),
177
- });
178
- const pages = await browser.pages();
179
- const page = pages[0];
180
- for (const url of urls) {
181
- await page.goto(url);
182
- let html = await page.content();
183
- if (options.textContent) {
184
- const readable = await page.evaluate(`
185
- import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
186
- return new readability.Readability(document).parse()
187
- })`);
188
- html = `${readable.title}\n${readable.textContent}`;
189
- }
190
- yield html;
191
- }
192
- await browser.close();
193
- }
194
- async screenshot(url, options = { fullPage: false }) {
195
- if (!url) {
196
- throw new Error('Page URL was not provided');
197
- }
198
- const browser = await puppeteer_core_1.default.connect({
199
- browserWSEndpoint: this.getConnectURL({
200
- sessionId: options.sessionId,
201
- proxy: options.proxy,
202
- }),
203
- });
204
- const pages = await browser.pages();
205
- const page = pages[0];
206
- await page.goto(url);
207
- const screenshot = await page.screenshot({ fullPage: options.fullPage });
208
- await browser.close();
209
- return screenshot;
210
- }
211
- async createContext() {
212
- const response = await fetch(`${this.baseAPIURL}/v1/contexts`, {
213
- method: 'POST',
214
- headers: {
215
- 'x-bb-api-key': this.apiKey,
216
- 'Content-Type': 'application/json',
217
- },
218
- body: JSON.stringify({ projectId: this.projectId }),
219
- });
220
- if (!response.ok) {
221
- throw new Error('Failed to create context');
222
- }
223
- const data = await response.json();
224
- return data;
225
- }
226
- }
227
- exports.default = Browserbase;
228
- exports.Browserbase = Browserbase;
@@ -1,18 +0,0 @@
1
- import { z } from 'zod';
2
- import Browserbase, { LoadOptions } from '../index.js';
3
- export default function BrowserbaseAISDK(b: Browserbase, options?: LoadOptions): {
4
- description: string;
5
- parameters: z.ZodObject<{
6
- url: z.ZodString;
7
- }, "strip", z.ZodTypeAny, {
8
- url?: string;
9
- }, {
10
- url?: string;
11
- }>;
12
- execute: ({ url }: {
13
- url: string;
14
- }) => Promise<{
15
- page: string;
16
- }>;
17
- };
18
- export { BrowserbaseAISDK };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = BrowserbaseAISDK;
4
- exports.BrowserbaseAISDK = BrowserbaseAISDK;
5
- exports.default = BrowserbaseAISDK;
6
- exports.BrowserbaseAISDK = BrowserbaseAISDK;
7
- const zod_1 = require("zod");
8
- function BrowserbaseAISDK(b, options = {}) {
9
- return {
10
- description: 'Load a webpage in a browser hosted by Browserbase and return its contents',
11
- parameters: zod_1.z.object({
12
- url: zod_1.z.string().describe('Page URL to be loaded'),
13
- }),
14
- execute: async ({ url }) => {
15
- const page = await b.loadURL(url, options);
16
- return { page };
17
- },
18
- };
19
- }
@@ -1,66 +0,0 @@
1
- import type { Point } from './recorder-types';
2
- export type SerializedValue = {
3
- n?: number;
4
- b?: boolean;
5
- s?: string;
6
- v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0';
7
- d?: string;
8
- u?: string;
9
- bi?: string;
10
- r?: {
11
- p: string;
12
- f: string;
13
- };
14
- a?: SerializedValue[];
15
- o?: {
16
- k: string;
17
- v: SerializedValue;
18
- }[];
19
- h?: number;
20
- id?: number;
21
- ref?: number;
22
- };
23
- export type SerializedError = {
24
- error?: {
25
- message: string;
26
- name: string;
27
- stack?: string;
28
- };
29
- value?: SerializedValue;
30
- };
31
- export type CallMetadata = {
32
- id: string;
33
- startTime: number;
34
- endTime: number;
35
- pauseStartTime?: number;
36
- pauseEndTime?: number;
37
- type: string;
38
- method: string;
39
- params: any;
40
- apiName?: string;
41
- internal?: boolean;
42
- isServerSide?: boolean;
43
- stepId?: string;
44
- location?: {
45
- file: string;
46
- line?: number;
47
- column?: number;
48
- };
49
- log: string[];
50
- error?: SerializedError;
51
- result?: any;
52
- point?: Point;
53
- objectId?: string;
54
- pageId?: string;
55
- frameId?: string;
56
- potentiallyClosesScope?: boolean;
57
- };
58
- export type ActionMetadata = {
59
- apiName?: string;
60
- objectId?: string;
61
- pageId?: string;
62
- frameId?: string;
63
- params: any;
64
- method: string;
65
- type: string;
66
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare function createGuid(): string;