@browserbasehq/sdk 1.1.8 → 1.2.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/README.md +3 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +20 -8
- package/dist/integrations/ai-sdk.js +9 -5
- package/package.json +1 -2
- package/src/index.ts +13 -5
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
import BrowserbaseAISDK from './integrations/ai-sdk.js';
|
|
3
3
|
export type ClientOptions = {
|
|
4
4
|
apiKey?: string;
|
|
@@ -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
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.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
|
+
class Browserbase {
|
|
4
11
|
apiKey;
|
|
5
12
|
projectId;
|
|
6
13
|
baseAPIURL;
|
|
@@ -25,13 +32,17 @@ export default class Browserbase {
|
|
|
25
32
|
return await response.json();
|
|
26
33
|
}
|
|
27
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
|
+
}
|
|
28
39
|
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
29
40
|
method: 'POST',
|
|
30
41
|
headers: {
|
|
31
42
|
'x-bb-api-key': this.apiKey,
|
|
32
43
|
'Content-Type': 'application/json',
|
|
33
44
|
},
|
|
34
|
-
body: JSON.stringify(
|
|
45
|
+
body: JSON.stringify(mergedOptions),
|
|
35
46
|
});
|
|
36
47
|
return await response.json();
|
|
37
48
|
}
|
|
@@ -112,7 +123,7 @@ export default class Browserbase {
|
|
|
112
123
|
if (!url) {
|
|
113
124
|
throw new Error('Page URL was not provided');
|
|
114
125
|
}
|
|
115
|
-
const browser = await
|
|
126
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
116
127
|
browserWSEndpoint: this.getConnectURL({
|
|
117
128
|
sessionId: options.sessionId,
|
|
118
129
|
proxy: options.proxy,
|
|
@@ -138,7 +149,7 @@ export default class Browserbase {
|
|
|
138
149
|
if (!urls.length) {
|
|
139
150
|
throw new Error('Page URLs were not provided');
|
|
140
151
|
}
|
|
141
|
-
const browser = await
|
|
152
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
142
153
|
browserWSEndpoint: this.getConnectURL({
|
|
143
154
|
sessionId: options.sessionId,
|
|
144
155
|
proxy: options.proxy,
|
|
@@ -166,7 +177,7 @@ export default class Browserbase {
|
|
|
166
177
|
if (!url) {
|
|
167
178
|
throw new Error('Page URL was not provided');
|
|
168
179
|
}
|
|
169
|
-
const browser = await
|
|
180
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
170
181
|
browserWSEndpoint: this.getConnectURL({
|
|
171
182
|
sessionId: options.sessionId,
|
|
172
183
|
proxy: options.proxy,
|
|
@@ -180,4 +191,5 @@ export default class Browserbase {
|
|
|
180
191
|
return screenshot;
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
|
-
|
|
194
|
+
exports.default = Browserbase;
|
|
195
|
+
exports.Browserbase = Browserbase;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserbaseAISDK = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
function BrowserbaseAISDK(b, options = {}) {
|
|
3
6
|
return {
|
|
4
7
|
description: 'Load a webpage in a browser hosted by Browserbase and return its contents',
|
|
5
|
-
parameters: z.object({
|
|
6
|
-
url: z.string().describe('Page URL to be loaded'),
|
|
8
|
+
parameters: zod_1.z.object({
|
|
9
|
+
url: zod_1.z.string().describe('Page URL to be loaded'),
|
|
7
10
|
}),
|
|
8
11
|
execute: async ({ url }) => {
|
|
9
12
|
const page = await b.loadURL(url, options);
|
|
@@ -11,4 +14,5 @@ export default function BrowserbaseAISDK(b, options = {}) {
|
|
|
11
14
|
},
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
exports.default = BrowserbaseAISDK;
|
|
18
|
+
exports.BrowserbaseAISDK = BrowserbaseAISDK;
|
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()
|
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
|