@browserbasehq/sdk 1.1.9 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +13 -13
- package/package.json +1 -1
- package/src/index.ts +23 -19
- package/test/lib.test.ts +1 -2
package/README.md
CHANGED
|
@@ -76,12 +76,11 @@ npm i ai openai zod
|
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
import OpenAI from 'openai'
|
|
79
|
-
import { Browserbase } from '@browserbasehq/sdk'
|
|
80
|
-
import { BrowserbaseAISDK } from '@browserbasehq/sdk/dist/integrations/ai-sdk'
|
|
79
|
+
import { Browserbase, BrowserbaseAISDK } from '@browserbasehq/sdk'
|
|
81
80
|
import {
|
|
82
81
|
OpenAIStream,
|
|
83
82
|
StreamingTextResponse,
|
|
84
|
-
|
|
83
|
+
generateText,
|
|
85
84
|
} from 'ai'
|
|
86
85
|
|
|
87
86
|
// Create new OpenAI client
|
|
@@ -96,7 +95,7 @@ const browserbase = new Browserbase()
|
|
|
96
95
|
const browserTool = BrowserbaseAISDK(browserbase, { textContent: true })
|
|
97
96
|
|
|
98
97
|
// Load completions
|
|
99
|
-
const result = await
|
|
98
|
+
const result = await generateText({
|
|
100
99
|
model: openai.chat('gpt-3.5-turbo'),
|
|
101
100
|
tools: {
|
|
102
101
|
browserTool,
|
package/dist/index.d.ts
CHANGED
|
@@ -56,9 +56,9 @@ export type Session = {
|
|
|
56
56
|
logs?: string;
|
|
57
57
|
};
|
|
58
58
|
export type SessionRecording = {
|
|
59
|
-
type?:
|
|
59
|
+
type?: number;
|
|
60
60
|
time?: string;
|
|
61
|
-
data?:
|
|
61
|
+
data?: any;
|
|
62
62
|
};
|
|
63
63
|
export type DebugConnectionURLs = {
|
|
64
64
|
debuggerFullscreenUrl?: string;
|
|
@@ -72,12 +72,12 @@ export type SessionLog = {
|
|
|
72
72
|
method?: string;
|
|
73
73
|
request?: {
|
|
74
74
|
timestamp?: string;
|
|
75
|
-
params?:
|
|
75
|
+
params?: any;
|
|
76
76
|
rawBody?: string;
|
|
77
77
|
};
|
|
78
78
|
response?: {
|
|
79
79
|
timestamp?: string;
|
|
80
|
-
result?:
|
|
80
|
+
result?: any;
|
|
81
81
|
rawBody?: string;
|
|
82
82
|
};
|
|
83
83
|
pageId?: string;
|
package/dist/index.js
CHANGED
|
@@ -32,13 +32,17 @@ class Browserbase {
|
|
|
32
32
|
return await response.json();
|
|
33
33
|
}
|
|
34
34
|
async createSession(options) {
|
|
35
|
+
const mergedOptions = { projectId: this.projectId, ...options };
|
|
36
|
+
if (!mergedOptions.projectId) {
|
|
37
|
+
throw new Error('a projectId is missing: use the options.projectId or BROWSERBASE_PROJECT_ID environment variable to set one.');
|
|
38
|
+
}
|
|
35
39
|
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
36
40
|
method: 'POST',
|
|
37
41
|
headers: {
|
|
38
42
|
'x-bb-api-key': this.apiKey,
|
|
39
43
|
'Content-Type': 'application/json',
|
|
40
44
|
},
|
|
41
|
-
body: JSON.stringify(
|
|
45
|
+
body: JSON.stringify(mergedOptions),
|
|
42
46
|
});
|
|
43
47
|
return await response.json();
|
|
44
48
|
}
|
|
@@ -130,12 +134,10 @@ class Browserbase {
|
|
|
130
134
|
await page.goto(url);
|
|
131
135
|
let html = await page.content();
|
|
132
136
|
if (options.textContent) {
|
|
133
|
-
const readable = await page.evaluate(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return new readability.Readability(document).parse();
|
|
138
|
-
});
|
|
137
|
+
const readable = await page.evaluate(`
|
|
138
|
+
import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
|
|
139
|
+
return new readability.Readability(document).parse()
|
|
140
|
+
})`);
|
|
139
141
|
html = `${readable.title}\n${readable.textContent}`;
|
|
140
142
|
}
|
|
141
143
|
await browser.close();
|
|
@@ -157,12 +159,10 @@ class Browserbase {
|
|
|
157
159
|
await page.goto(url);
|
|
158
160
|
let html = await page.content();
|
|
159
161
|
if (options.textContent) {
|
|
160
|
-
const readable = await page.evaluate(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return new readability.Readability(document).parse();
|
|
165
|
-
});
|
|
162
|
+
const readable = await page.evaluate(`
|
|
163
|
+
import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
|
|
164
|
+
return new readability.Readability(document).parse()
|
|
165
|
+
})`);
|
|
166
166
|
html = `${readable.title}\n${readable.textContent}`;
|
|
167
167
|
}
|
|
168
168
|
yield html;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -72,9 +72,9 @@ export type Session = {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export type SessionRecording = {
|
|
75
|
-
type?:
|
|
75
|
+
type?: number
|
|
76
76
|
time?: string
|
|
77
|
-
data?:
|
|
77
|
+
data?: any
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export type DebugConnectionURLs = {
|
|
@@ -90,12 +90,12 @@ export type SessionLog = {
|
|
|
90
90
|
method?: string
|
|
91
91
|
request?: {
|
|
92
92
|
timestamp?: string
|
|
93
|
-
params?:
|
|
93
|
+
params?: any
|
|
94
94
|
rawBody?: string
|
|
95
95
|
}
|
|
96
96
|
response?: {
|
|
97
97
|
timestamp?: string
|
|
98
|
-
result?:
|
|
98
|
+
result?: any
|
|
99
99
|
rawBody?: string
|
|
100
100
|
}
|
|
101
101
|
pageId?: string
|
|
@@ -133,13 +133,21 @@ export default class Browserbase {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
async createSession(options?: CreateSessionOptions): Promise<Session> {
|
|
136
|
+
const mergedOptions = { projectId: this.projectId, ...options }
|
|
137
|
+
|
|
138
|
+
if (!mergedOptions.projectId) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
'a projectId is missing: use the options.projectId or BROWSERBASE_PROJECT_ID environment variable to set one.'
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
136
144
|
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
137
145
|
method: 'POST',
|
|
138
146
|
headers: {
|
|
139
147
|
'x-bb-api-key': this.apiKey,
|
|
140
148
|
'Content-Type': 'application/json',
|
|
141
149
|
},
|
|
142
|
-
body: JSON.stringify(
|
|
150
|
+
body: JSON.stringify(mergedOptions),
|
|
143
151
|
})
|
|
144
152
|
|
|
145
153
|
return await response.json()
|
|
@@ -267,13 +275,11 @@ export default class Browserbase {
|
|
|
267
275
|
let html = await page.content()
|
|
268
276
|
|
|
269
277
|
if (options.textContent) {
|
|
270
|
-
const readable
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
275
|
-
return new readability.Readability(document).parse()
|
|
276
|
-
})
|
|
278
|
+
const readable: { title?: string; textContent?: string } =
|
|
279
|
+
await page.evaluate(`
|
|
280
|
+
import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
|
|
281
|
+
return new readability.Readability(document).parse()
|
|
282
|
+
})`)
|
|
277
283
|
html = `${readable.title}\n${readable.textContent}`
|
|
278
284
|
}
|
|
279
285
|
|
|
@@ -304,13 +310,11 @@ export default class Browserbase {
|
|
|
304
310
|
let html = await page.content()
|
|
305
311
|
|
|
306
312
|
if (options.textContent) {
|
|
307
|
-
const readable
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
)
|
|
312
|
-
return new readability.Readability(document).parse()
|
|
313
|
-
})
|
|
313
|
+
const readable: { title?: string; textContent?: string } =
|
|
314
|
+
await page.evaluate(`
|
|
315
|
+
import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
|
|
316
|
+
return new readability.Readability(document).parse()
|
|
317
|
+
})`)
|
|
314
318
|
html = `${readable.title}\n${readable.textContent}`
|
|
315
319
|
}
|
|
316
320
|
|
package/test/lib.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, it, beforeEach } from 'node:test'
|
|
2
2
|
import { expect } from 'chai'
|
|
3
|
-
import { Browserbase } from '../src'
|
|
4
|
-
import { BrowserbaseAISDK } from '../src/integrations/ai-sdk'
|
|
3
|
+
import { Browserbase, BrowserbaseAISDK } from '../src'
|
|
5
4
|
|
|
6
5
|
describe('Browserbase', () => {
|
|
7
6
|
let browserbase: Browserbase
|