@browserbasehq/sdk 1.1.9 → 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 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
- experimental_generateText,
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 experimental_generateText({
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?: string;
59
+ type?: number;
60
60
  time?: string;
61
- data?: object;
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?: object;
75
+ params?: any;
76
76
  rawBody?: string;
77
77
  };
78
78
  response?: {
79
79
  timestamp?: string;
80
- result?: object;
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({ projectId: this.projectId, ...options }),
45
+ body: JSON.stringify(mergedOptions),
42
46
  });
43
47
  return await response.json();
44
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/sdk",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "description": "Browserbase JS SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -72,9 +72,9 @@ export type Session = {
72
72
  }
73
73
 
74
74
  export type SessionRecording = {
75
- type?: string
75
+ type?: number
76
76
  time?: string
77
- data?: object
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?: object
93
+ params?: any
94
94
  rawBody?: string
95
95
  }
96
96
  response?: {
97
97
  timestamp?: string
98
- result?: object
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({ projectId: this.projectId, ...options }),
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