@browserbasehq/sdk 1.0.0 → 1.0.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 +69 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integrations/ai-sdk.d.ts +1 -0
- package/dist/integrations/ai-sdk.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/integrations/ai-sdk.ts +2 -0
- package/test/lib.test.ts +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Browserbase JS SDK
|
|
2
|
+
|
|
3
|
+
[Browserbase](https://browserbase.com) is a serverless platform for running headless browsers, it offers advanced debugging, session recordings, stealth mode, integrated proxies and captcha solving.
|
|
4
|
+
|
|
5
|
+
## Installation and setup
|
|
6
|
+
|
|
7
|
+
- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_API_KEY`).
|
|
8
|
+
- Install the required dependencies:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @browserbasehq/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { Browserbase, BrowserbaseAISDK } from '@browserbasehq/sdk'
|
|
18
|
+
|
|
19
|
+
// Init the SDK
|
|
20
|
+
const browserbase = new Browserbase()
|
|
21
|
+
|
|
22
|
+
// Load a webpage
|
|
23
|
+
const result = await browserbase.load("https://example.com")
|
|
24
|
+
|
|
25
|
+
// Load multiple webpages (returns iterator)
|
|
26
|
+
const result = await browserbase.load(["https://example.com"])
|
|
27
|
+
|
|
28
|
+
// Text-only mode
|
|
29
|
+
const result = await browserbase.load("https://example.com", { textContent: true })
|
|
30
|
+
|
|
31
|
+
// Screenshot (returns bytes)
|
|
32
|
+
const result = await browserbase.screenshot("https://example.com", { textContent: true })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Vercel AI SDK Integration
|
|
36
|
+
|
|
37
|
+
Install the additional dependencies:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
npm i ai openai zod
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import OpenAI from 'openai';
|
|
45
|
+
import { Browserbase } from '@browserbasehq/sdk'
|
|
46
|
+
import { BrowserbaseAISDK } from '@browserbasehq/sdk/dist/integrations/ai-sdk'
|
|
47
|
+
import { OpenAIStream, StreamingTextResponse, experimental_generateText } from 'ai';
|
|
48
|
+
|
|
49
|
+
// Create new OpenAI client
|
|
50
|
+
const openai = new OpenAI({
|
|
51
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Init the Browserbase SDK
|
|
55
|
+
const browserbase = new Browserbase();
|
|
56
|
+
|
|
57
|
+
// Init the tool
|
|
58
|
+
const browserTool = BrowserbaseAISDK(browserbase, { textContent: true });
|
|
59
|
+
|
|
60
|
+
// Load completions
|
|
61
|
+
const result = await experimental_generateText({
|
|
62
|
+
model: openai.chat('gpt-3.5-turbo'),
|
|
63
|
+
tools: {
|
|
64
|
+
browserTool
|
|
65
|
+
},
|
|
66
|
+
prompt:
|
|
67
|
+
'What is the weather in San Francisco?',
|
|
68
|
+
});
|
|
69
|
+
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/test/lib.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 } from '../src'
|
|
4
|
+
import { BrowserbaseAISDK } from '../src/integrations/ai-sdk'
|
|
5
5
|
|
|
6
6
|
describe('Browserbase', () => {
|
|
7
7
|
let browserbase: Browserbase
|