effect-browserbase 0.2.0-beta.8 → 0.3.0-beta.10

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 (155) hide show
  1. package/README.md +277 -315
  2. package/dist/Browserbase-CaPKwEY9.mjs +544 -0
  3. package/dist/Browserbase-CaPKwEY9.mjs.map +1 -0
  4. package/dist/Browserbase.d.mts +110 -0
  5. package/dist/Browserbase.mjs +3 -0
  6. package/dist/BrowserbaseClient-CtAQ2rg4.d.mts +195 -0
  7. package/dist/BrowserbaseClient.d.mts +2 -0
  8. package/dist/BrowserbaseClient.mjs +190 -0
  9. package/dist/BrowserbaseClient.mjs.map +1 -0
  10. package/dist/BrowserbaseError-D1EOrLNc.d.mts +79 -0
  11. package/dist/BrowserbaseError.d.mts +2 -0
  12. package/dist/BrowserbaseError.mjs +101 -0
  13. package/dist/BrowserbaseError.mjs.map +1 -0
  14. package/dist/ContextLease.d.mts +42 -0
  15. package/dist/ContextLease.mjs +80 -0
  16. package/dist/ContextLease.mjs.map +1 -0
  17. package/dist/index.d.mts +5 -27
  18. package/dist/index.mjs +5 -26
  19. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  20. package/dist/testing/index.d.mts +136 -0
  21. package/dist/testing/index.mjs +440 -0
  22. package/dist/testing/index.mjs.map +1 -0
  23. package/package.json +51 -121
  24. package/src/Browserbase.ts +729 -0
  25. package/src/BrowserbaseClient.ts +559 -0
  26. package/src/BrowserbaseError.ts +108 -0
  27. package/src/ContextLease.ts +118 -0
  28. package/src/index.ts +7 -0
  29. package/src/internal/captureConnection.ts +214 -0
  30. package/src/testing/BrowserbaseContract.ts +170 -0
  31. package/src/testing/TestBrowserbase.ts +509 -0
  32. package/src/testing/index.ts +7 -0
  33. package/dist/Account.d.mts +0 -32
  34. package/dist/Account.mjs +0 -36
  35. package/dist/Account.mjs.map +0 -1
  36. package/dist/Acquisition-BOABu_qJ.mjs +0 -244
  37. package/dist/Acquisition-BOABu_qJ.mjs.map +0 -1
  38. package/dist/Agents-CPaTOH_g.d.mts +0 -156
  39. package/dist/Agents.d.mts +0 -3
  40. package/dist/Agents.mjs +0 -292
  41. package/dist/Agents.mjs.map +0 -1
  42. package/dist/Allocation.d.mts +0 -97
  43. package/dist/Allocation.mjs +0 -27
  44. package/dist/Allocation.mjs.map +0 -1
  45. package/dist/Authorization-Ll5f_XNM.mjs +0 -12
  46. package/dist/Authorization-Ll5f_XNM.mjs.map +0 -1
  47. package/dist/Browser-ByrWJ0ss.mjs +0 -274
  48. package/dist/Browser-ByrWJ0ss.mjs.map +0 -1
  49. package/dist/Browser.d.mts +0 -83
  50. package/dist/Browser.mjs +0 -3
  51. package/dist/BrowserBinding.d.mts +0 -13
  52. package/dist/BrowserBinding.mjs +0 -31
  53. package/dist/BrowserBinding.mjs.map +0 -1
  54. package/dist/Certificates-D4NQmyeA.d.mts +0 -34
  55. package/dist/Certificates.d.mts +0 -3
  56. package/dist/Certificates.mjs +0 -85
  57. package/dist/Certificates.mjs.map +0 -1
  58. package/dist/Cleanup-DMTDBir8.d.mts +0 -23
  59. package/dist/Cleanup.d.mts +0 -3
  60. package/dist/Cleanup.mjs +0 -43
  61. package/dist/Cleanup.mjs.map +0 -1
  62. package/dist/Client-BEC4Q8ZS.mjs +0 -564
  63. package/dist/Client-BEC4Q8ZS.mjs.map +0 -1
  64. package/dist/Client-B_f6bBLT.d.mts +0 -52
  65. package/dist/Client.d.mts +0 -3
  66. package/dist/Client.mjs +0 -2
  67. package/dist/Connection-sxyxtwlk.mjs +0 -56
  68. package/dist/Connection-sxyxtwlk.mjs.map +0 -1
  69. package/dist/ContextCoordination.d.mts +0 -29
  70. package/dist/ContextCoordination.mjs +0 -94
  71. package/dist/ContextCoordination.mjs.map +0 -1
  72. package/dist/ContextWriter-CiEma24z.mjs +0 -204
  73. package/dist/ContextWriter-CiEma24z.mjs.map +0 -1
  74. package/dist/Contexts-DqdL7cyX.d.mts +0 -31
  75. package/dist/Contexts.d.mts +0 -3
  76. package/dist/Contexts.mjs +0 -97
  77. package/dist/Contexts.mjs.map +0 -1
  78. package/dist/Deadline-CrViaogr.mjs +0 -13
  79. package/dist/Deadline-CrViaogr.mjs.map +0 -1
  80. package/dist/Downloads-CX52GOFJ.d.mts +0 -43
  81. package/dist/Downloads.d.mts +0 -3
  82. package/dist/Downloads.mjs +0 -137
  83. package/dist/Downloads.mjs.map +0 -1
  84. package/dist/Errors.d.mts +0 -100
  85. package/dist/Errors.mjs +0 -194
  86. package/dist/Errors.mjs.map +0 -1
  87. package/dist/Extensions-BTUn9zhK.mjs +0 -231
  88. package/dist/Extensions-BTUn9zhK.mjs.map +0 -1
  89. package/dist/Extensions-DBXuVM1f.d.mts +0 -43
  90. package/dist/Extensions.d.mts +0 -3
  91. package/dist/Extensions.mjs +0 -2
  92. package/dist/Functions-CsKMMUuZ.d.mts +0 -226
  93. package/dist/Functions.d.mts +0 -3
  94. package/dist/Functions.mjs +0 -318
  95. package/dist/Functions.mjs.map +0 -1
  96. package/dist/Issued-DejqoMYL.mjs +0 -15
  97. package/dist/Issued-DejqoMYL.mjs.map +0 -1
  98. package/dist/Launch-cAdE2rrZ.mjs +0 -115
  99. package/dist/Launch-cAdE2rrZ.mjs.map +0 -1
  100. package/dist/Launch.d.mts +0 -127
  101. package/dist/Launch.mjs +0 -97
  102. package/dist/Launch.mjs.map +0 -1
  103. package/dist/PageFetch-CjAM_0DS.d.mts +0 -40
  104. package/dist/PageFetch.d.mts +0 -3
  105. package/dist/PageFetch.mjs +0 -59
  106. package/dist/PageFetch.mjs.map +0 -1
  107. package/dist/Projects-tm5bTDH0.d.mts +0 -38
  108. package/dist/Projects.d.mts +0 -3
  109. package/dist/Projects.mjs +0 -65
  110. package/dist/Projects.mjs.map +0 -1
  111. package/dist/Recordings-B9k5aODB.d.mts +0 -27
  112. package/dist/Recordings.d.mts +0 -3
  113. package/dist/Recordings.mjs +0 -144
  114. package/dist/Recordings.mjs.map +0 -1
  115. package/dist/References-DOH3Wu44.d.mts +0 -34
  116. package/dist/References.d.mts +0 -3
  117. package/dist/References.mjs +0 -33
  118. package/dist/References.mjs.map +0 -1
  119. package/dist/Replays-mV93WGtx.d.mts +0 -27
  120. package/dist/Replays.d.mts +0 -3
  121. package/dist/Replays.mjs +0 -107
  122. package/dist/Replays.mjs.map +0 -1
  123. package/dist/Resource-J7Kkk5mu.mjs +0 -54
  124. package/dist/Resource-J7Kkk5mu.mjs.map +0 -1
  125. package/dist/Search-B64e7g-h.d.mts +0 -37
  126. package/dist/Search.d.mts +0 -3
  127. package/dist/Search.mjs +0 -46
  128. package/dist/Search.mjs.map +0 -1
  129. package/dist/SessionData-5xYZDshJ.d.mts +0 -38
  130. package/dist/SessionData.d.mts +0 -3
  131. package/dist/SessionData.mjs +0 -48
  132. package/dist/SessionData.mjs.map +0 -1
  133. package/dist/Sessions-D2H5m6rF.mjs +0 -260
  134. package/dist/Sessions-D2H5m6rF.mjs.map +0 -1
  135. package/dist/Sessions-oJEUmZth.d.mts +0 -69
  136. package/dist/Sessions.d.mts +0 -4
  137. package/dist/Sessions.mjs +0 -3
  138. package/dist/Testing.d.mts +0 -119
  139. package/dist/Testing.mjs +0 -206
  140. package/dist/Testing.mjs.map +0 -1
  141. package/dist/TransferPolicy-DQ06i7SZ.mjs +0 -25
  142. package/dist/TransferPolicy-DQ06i7SZ.mjs.map +0 -1
  143. package/dist/Transfers-GVqzrDWl.d.mts +0 -89
  144. package/dist/Transfers.d.mts +0 -3
  145. package/dist/Transfers.mjs +0 -85
  146. package/dist/Transfers.mjs.map +0 -1
  147. package/dist/Uploads-C2_bACgv.d.mts +0 -28
  148. package/dist/Uploads.d.mts +0 -3
  149. package/dist/Uploads.mjs +0 -105
  150. package/dist/Uploads.mjs.map +0 -1
  151. package/dist/Webhooks-BoeRAxzG.d.mts +0 -59
  152. package/dist/Webhooks.d.mts +0 -3
  153. package/dist/Webhooks.mjs +0 -134
  154. package/dist/Webhooks.mjs.map +0 -1
  155. package/dist/WriterFacts-BBJRDZYY.d.mts +0 -54
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserbaseClient.mjs","names":[],"sources":["../src/BrowserbaseClient.ts"],"sourcesContent":["/**\n * A small client for the Browserbase REST API: sessions, stored contexts, extensions, web search\n * and page fetch.\n *\n * It runs on the `HttpClient` the application provides, such as `FetchHttpClient.layer`. The API\n * key travels only in the `X-BB-API-Key` header and is redacted from logs and traces. Redirects\n * are refused rather than followed, because following one would send the key wherever it points.\n *\n * Every request has a deadline, so a provider that never answers cannot hold a caller's scope open.\n * Reads are retried twice on transient failures. Writes are not: a session create that fails in\n * transit or misses its deadline may still have created the session, which then ends at its timeout.\n *\n * @since 0.3.0\n */\nimport {\n Config,\n Context,\n Duration,\n Effect,\n Exit,\n flow,\n identity,\n Layer,\n Option,\n Redacted,\n Schedule,\n Schema,\n} from \"effect\";\nimport {\n FetchHttpClient,\n Headers,\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from \"effect/http\";\n\nimport {\n BrowserbaseError,\n Decode,\n InvalidRequest,\n isTransient,\n NotFound,\n RateLimited,\n type Reason,\n Status,\n Transport,\n Unauthorized,\n} from \"./BrowserbaseError.ts\";\n\nexport const defaultBaseUrl = \"https://api.browserbase.com\";\n\nexport class Session extends Schema.Class<Session>(\"effect-browserbase/Session\")({\n id: Schema.String,\n /** `PENDING`, `RUNNING`, `ERROR`, `TIMED_OUT` or `COMPLETED`, kept open for new values. */\n status: Schema.String,\n region: Schema.String,\n keepAlive: Schema.Boolean,\n createdAt: Schema.String,\n expiresAt: Schema.String,\n endedAt: Schema.optional(Schema.String),\n contextId: Schema.optional(Schema.String),\n proxyBytes: Schema.optional(Schema.Finite),\n userMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n /** The CDP WebSocket address, a credential. Only create and get return it. */\n connectUrl: Schema.optional(Schema.RedactedFromValue(Schema.String)),\n}) {}\n\n/** Links that let a person watch and control a running session. They are credentials. */\nexport class LiveView extends Schema.Class<LiveView>(\"effect-browserbase/LiveView\")({\n /** The active tab, without browser chrome: suited to an iframe. */\n debuggerFullscreenUrl: Schema.RedactedFromValue(Schema.String),\n debuggerUrl: Schema.RedactedFromValue(Schema.String),\n pages: Schema.Array(\n Schema.Struct({\n id: Schema.String,\n url: Schema.String,\n title: Schema.String,\n debuggerFullscreenUrl: Schema.RedactedFromValue(Schema.String),\n }),\n ),\n}) {}\n\n/** Browser state (cookies, storage, cache) kept by Browserbase for sessions to load and save. */\nexport class StoredContext extends Schema.Class<StoredContext>(\"effect-browserbase/StoredContext\")({\n id: Schema.String,\n name: Schema.optional(Schema.String),\n /** `getContext` returns the timestamps; `createContext` does not. */\n createdAt: Schema.optional(Schema.String),\n updatedAt: Schema.optional(Schema.String),\n}) {}\n\n/** A Chrome extension uploaded to the project, which sessions load when created with its id. */\nexport class Extension extends Schema.Class<Extension>(\"effect-browserbase/Extension\")({\n id: Schema.String,\n fileName: Schema.String,\n createdAt: Schema.String,\n updatedAt: Schema.String,\n}) {}\n\nexport class SearchResult extends Schema.Class<SearchResult>(\"effect-browserbase/SearchResult\")({\n url: Schema.String,\n title: Schema.String,\n author: Schema.optional(Schema.String),\n publishedDate: Schema.optional(Schema.String),\n}) {}\n\n/** A page fetched without a browser. */\nexport class FetchedPage extends Schema.Class<FetchedPage>(\"effect-browserbase/FetchedPage\")({\n statusCode: Schema.Finite,\n contentType: Schema.String,\n headers: Schema.Record(Schema.String, Schema.String),\n /** Text for the `raw` and `markdown` formats; the extracted object for `json`. */\n content: Schema.Union([Schema.String, Schema.Record(Schema.String, Schema.Unknown)]),\n}) {}\n\n/** A session create request, as Browserbase's API reference describes it. */\nexport interface SessionOptions {\n /** Defaults to the API key's project. */\n readonly projectId?: string | undefined;\n /** An uploaded extension for the browser to load. It makes the session slower to start. */\n readonly extensionId?: string | undefined;\n /** Seconds until Browserbase ends the session, from 60 to 21,600. Defaults to the project's. */\n readonly timeout?: number | undefined;\n /** Keep the session running after every client disconnects, until released or timed out. */\n readonly keepAlive?: boolean | undefined;\n readonly region?: \"us-west-2\" | \"us-east-1\" | \"eu-central-1\" | \"ap-southeast-1\" | undefined;\n /** `true` for Browserbase's proxies, or rules per domain. */\n readonly proxies?: boolean | ReadonlyArray<ProxyRule> | undefined;\n /** Labels that `listSessions` can query. */\n readonly userMetadata?: Readonly<Record<string, unknown>> | undefined;\n readonly browserSettings?: BrowserSettings | undefined;\n}\n\n/** Browser settings. Left unset, each takes Browserbase's default. */\nexport interface BrowserSettings {\n /**\n * Load a stored context. With `persist`, Browserbase saves the session's changes back to it once\n * the session ends; `Browserbase.open` lets one such session at a time write to each context.\n */\n readonly context?: { readonly id: string; readonly persist?: boolean | undefined } | undefined;\n readonly viewport?: { readonly width: number; readonly height: number } | undefined;\n readonly blockAds?: boolean | undefined;\n /** Browserbase solves captchas unless this is false. */\n readonly solveCaptchas?: boolean | undefined;\n /** Browserbase records the session for replay unless this is false. */\n readonly recordSession?: boolean | undefined;\n /** Browserbase keeps the session's logs unless this is false. */\n readonly logSession?: boolean | undefined;\n /** Verified browser mode, on plans that include it. */\n readonly verified?: boolean | undefined;\n readonly os?: \"windows\" | \"mac\" | \"linux\" | \"mobile\" | \"tablet\" | undefined;\n /** Restrict top-level navigation to these domains and their subdomains. */\n readonly allowedDomains?: ReadonlyArray<string> | undefined;\n readonly ignoreCertificateErrors?: boolean | undefined;\n}\n\nexport type ProxyRule =\n | {\n readonly type: \"browserbase\";\n readonly geolocation?:\n | {\n readonly country: string;\n readonly state?: string | undefined;\n readonly city?: string | undefined;\n }\n | undefined;\n readonly domainPattern?: string | undefined;\n }\n | {\n readonly type: \"external\";\n readonly server: string;\n readonly username?: string | undefined;\n readonly password?: string | undefined;\n readonly domainPattern?: string | undefined;\n }\n | { readonly type: \"none\"; readonly domainPattern?: string | undefined };\n\nexport interface FetchOptions {\n /** `raw` (the default) returns the body as is; `json` needs `schema`. */\n readonly format?: \"raw\" | \"markdown\" | \"json\" | undefined;\n /** JSON Schema of the object to extract with the `json` format. */\n readonly schema?: Readonly<Record<string, unknown>> | undefined;\n readonly allowRedirects?: boolean | undefined;\n readonly allowInsecureSsl?: boolean | undefined;\n readonly proxies?: boolean | undefined;\n}\n\nexport interface Service {\n readonly createSession: (options?: SessionOptions) => Effect.Effect<Session, BrowserbaseError>;\n readonly getSession: (id: string) => Effect.Effect<Session, BrowserbaseError>;\n /** Sessions with the given status, or all. `query` filters on user metadata, in Browserbase's syntax. */\n readonly listSessions: (options?: {\n readonly status?: string | undefined;\n readonly query?: string | undefined;\n }) => Effect.Effect<ReadonlyArray<Session>, BrowserbaseError>;\n /** End the session now, which stops its billing. Ending an ended session succeeds. */\n readonly releaseSession: (id: string) => Effect.Effect<void, BrowserbaseError>;\n /** Live view links. They last `expiresInSeconds`, or as long as the session. */\n readonly liveView: (\n id: string,\n options?: { readonly expiresInSeconds?: number | undefined },\n ) => Effect.Effect<LiveView, BrowserbaseError>;\n readonly createContext: (options?: {\n readonly name?: string | undefined;\n }) => Effect.Effect<StoredContext, BrowserbaseError>;\n readonly getContext: (id: string) => Effect.Effect<StoredContext, BrowserbaseError>;\n /** Delete a stored context for good. Sessions can no longer load it. */\n readonly deleteContext: (id: string) => Effect.Effect<void, BrowserbaseError>;\n /**\n * Upload a Chrome extension: a zip of at most 100 MB with `manifest.json` at its root. Create a\n * session with the returned id as `extensionId` to load it.\n */\n readonly uploadExtension: (\n archive: Uint8Array,\n options?: { readonly fileName?: string | undefined },\n ) => Effect.Effect<Extension, BrowserbaseError>;\n readonly getExtension: (id: string) => Effect.Effect<Extension, BrowserbaseError>;\n readonly deleteExtension: (id: string) => Effect.Effect<void, BrowserbaseError>;\n /** Search the web for up to `results` hits, from 1 to 25. Defaults to 10. */\n readonly search: (\n query: string,\n options?: { readonly results?: number | undefined },\n ) => Effect.Effect<ReadonlyArray<SearchResult>, BrowserbaseError>;\n readonly fetch: (\n url: string,\n options?: FetchOptions,\n ) => Effect.Effect<FetchedPage, BrowserbaseError>;\n}\n\nexport class BrowserbaseClient extends Context.Service<BrowserbaseClient, Service>()(\n \"effect-browserbase/BrowserbaseClient\",\n) {}\n\nexport interface Options {\n readonly apiKey: Redacted.Redacted<string>;\n /** Defaults to `https://api.browserbase.com`. */\n readonly baseUrl?: string | undefined;\n /** Bound on each request attempt, including reading its answer. Defaults to 60 seconds. */\n readonly requestTimeout?: Duration.Input | undefined;\n}\n\nconst ids = /^[A-Za-z0-9_-]{1,128}$/;\nconst maxExtensionBytes = 100 * 1024 * 1024;\nconst ErrorBody = Schema.fromJsonString(Schema.Struct({ message: Schema.String }));\nconst SearchResponse = Schema.Struct({ results: Schema.Array(SearchResult) });\nconst CreatedId = Schema.Struct({ id: Schema.String.check(Schema.isPattern(ids)) });\n\nconst statusReason = (status: number, detail: string): Reason => {\n if (status < 200 || (status >= 300 && status < 400)) {\n return new Status({\n status,\n detail: \"redirected; redirects are refused so the API key stays with Browserbase\",\n });\n }\n if (status === 400) return new InvalidRequest({ detail });\n if (status === 401 || status === 403) return new Unauthorized({ detail });\n if (status === 404) return new NotFound({ detail });\n if (status === 429) return new RateLimited({ detail });\n\n return new Status({ status, detail });\n};\n\n/** A create's answer that did not decode though it named session `id`, released or not since. */\nconst undecoded = (detail: string, id: string, released: boolean) =>\n new Decode({\n detail: `${detail}; session ${id} ${released ? \"was released\" : \"could not be released and ends at its timeout\"}`,\n released,\n });\n\n/** Run the request with fetch's redirect mode set to manual, keeping any other fetch options. */\nconst refuseRedirects = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n Effect.contextWith((context: Context.Context<never>) =>\n Effect.provideService(effect, FetchHttpClient.RequestInit, {\n ...Context.getOrUndefined(context, FetchHttpClient.RequestInit),\n redirect: \"manual\",\n }),\n );\n\nexport const make = Effect.fnUntraced(function* (options: Options) {\n const http = (yield* HttpClient.HttpClient).pipe(\n HttpClient.mapRequest(\n flow(\n HttpClientRequest.prependUrl(options.baseUrl ?? defaultBaseUrl),\n HttpClientRequest.setHeader(\"x-bb-api-key\", Redacted.value(options.apiKey)),\n HttpClientRequest.acceptJson,\n ),\n ),\n HttpClient.transformResponse(\n flow(\n refuseRedirects,\n Effect.updateService(Headers.CurrentRedactedNames, (names) => [...names, \"x-bb-api-key\"]),\n ),\n ),\n );\n\n const failure = (operation: string, reason: Reason) =>\n new BrowserbaseError({ operation, reason });\n\n const requestTimeout = Duration.fromInputUnsafe(options.requestTimeout ?? Duration.seconds(60));\n\n /** Send one request; on a success status, read the answer with `read`. */\n const send = <A>(\n operation: string,\n request: HttpClientRequest.HttpClientRequest,\n read: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, BrowserbaseError>,\n ): Effect.Effect<A, BrowserbaseError> =>\n http.execute(request).pipe(\n Effect.mapError((error) => failure(operation, new Transport({ detail: error.message }))),\n Effect.flatMap((response) =>\n response.status >= 200 && response.status < 300\n ? read(response)\n : response.text.pipe(\n Effect.map((text) =>\n Option.getOrElse(\n Option.map(Schema.decodeOption(ErrorBody)(text), (body) => body.message),\n () => text.slice(0, 300),\n ),\n ),\n Effect.orElseSucceed(() => \"\"),\n Effect.flatMap((detail) =>\n Effect.fail(failure(operation, statusReason(response.status, detail))),\n ),\n ),\n ),\n // The deadline also applies inside a caller's uninterruptible acquisition, such as the\n // session create in Browserbase.open, so that acquisition always settles.\n Effect.timeoutOrElse({\n duration: requestTimeout,\n orElse: () =>\n Effect.fail(\n failure(\n operation,\n new Transport({\n detail: `no answer within ${Duration.format(requestTimeout)}`,\n }),\n ),\n ),\n }),\n request.method === \"GET\"\n ? Effect.retry({\n while: isTransient,\n times: 2,\n schedule: Schedule.exponential(\"250 millis\").pipe(Schedule.jittered),\n })\n : identity,\n Effect.withSpan(`Browserbase.${operation}`),\n );\n\n const json =\n <A>(operation: string, schema: Schema.Decoder<A>) =>\n (response: HttpClientResponse.HttpClientResponse) =>\n HttpClientResponse.schemaBodyJson(schema)(response).pipe(\n Effect.mapError((error) =>\n failure(operation, new Decode({ detail: error.message.split(\"\\n\")[0] ?? \"\" })),\n ),\n );\n\n const ignoreBody = () => Effect.void;\n\n const withBody = (\n operation: string,\n request: HttpClientRequest.HttpClientRequest,\n body: unknown,\n ) =>\n HttpClientRequest.bodyJson(request, body).pipe(\n Effect.mapError((error) => failure(operation, new InvalidRequest({ detail: error.message }))),\n );\n\n const checkId = (operation: string, id: string): Effect.Effect<string, BrowserbaseError> =>\n ids.test(id)\n ? Effect.succeed(id)\n : Effect.fail(\n failure(\n operation,\n new InvalidRequest({ detail: `${JSON.stringify(id)} is not a Browserbase id` }),\n ),\n );\n\n const releaseSession = (id: string) =>\n checkId(\"releaseSession\", id).pipe(\n Effect.flatMap(() =>\n withBody(\"releaseSession\", HttpClientRequest.post(`/v1/sessions/${id}`), {\n status: \"REQUEST_RELEASE\",\n }),\n ),\n Effect.flatMap((request) => send(\"releaseSession\", request, ignoreBody)),\n );\n\n // A success answer means the session exists even if the rest of it does not decode. Only an id\n // lets anyone end it early, so release it here before reporting the unexpected answer.\n const createSession = (body: SessionOptions) =>\n withBody(\"createSession\", HttpClientRequest.post(\"/v1/sessions\"), body).pipe(\n Effect.flatMap((request) =>\n send(\"createSession\", request, json(\"createSession\", Schema.Unknown)),\n ),\n Effect.flatMap((answer) =>\n Schema.decodeUnknownEffect(Session)(answer).pipe(\n Effect.catch((error) => {\n const detail = error.message.split(\"\\n\")[0] ?? \"\";\n\n return Option.match(Schema.decodeUnknownOption(CreatedId)(answer), {\n onNone: () => Effect.fail(failure(\"createSession\", new Decode({ detail }))),\n onSome: ({ id }) =>\n releaseSession(id).pipe(\n Effect.exit,\n Effect.flatMap((release) =>\n Effect.fail(\n failure(\"createSession\", undecoded(detail, id, Exit.isSuccess(release))),\n ),\n ),\n ),\n });\n }),\n ),\n ),\n );\n\n return BrowserbaseClient.of({\n createSession: (body = {}) => createSession(body),\n getSession: (id) =>\n checkId(\"getSession\", id).pipe(\n Effect.flatMap(() =>\n send(\n \"getSession\",\n HttpClientRequest.get(`/v1/sessions/${id}`),\n json(\"getSession\", Session),\n ),\n ),\n ),\n listSessions: (filter = {}) =>\n send(\n \"listSessions\",\n HttpClientRequest.get(\"/v1/sessions\", {\n urlParams: {\n ...(filter.status === undefined ? {} : { status: filter.status }),\n ...(filter.query === undefined ? {} : { q: filter.query }),\n },\n }),\n json(\"listSessions\", Schema.Array(Session)),\n ),\n releaseSession,\n liveView: (id, options = {}) =>\n checkId(\"liveView\", id).pipe(\n Effect.flatMap(() =>\n send(\n \"liveView\",\n HttpClientRequest.get(`/v1/sessions/${id}/debug`, {\n urlParams:\n options.expiresInSeconds === undefined\n ? {}\n : { expiresIn: options.expiresInSeconds },\n }),\n json(\"liveView\", LiveView),\n ),\n ),\n ),\n createContext: (body = {}) =>\n withBody(\"createContext\", HttpClientRequest.post(\"/v1/contexts\"), body).pipe(\n Effect.flatMap((request) =>\n send(\"createContext\", request, json(\"createContext\", StoredContext)),\n ),\n ),\n getContext: (id) =>\n checkId(\"getContext\", id).pipe(\n Effect.flatMap(() =>\n send(\n \"getContext\",\n HttpClientRequest.get(`/v1/contexts/${id}`),\n json(\"getContext\", StoredContext),\n ),\n ),\n ),\n deleteContext: (id) =>\n checkId(\"deleteContext\", id).pipe(\n Effect.flatMap(() =>\n send(\"deleteContext\", HttpClientRequest.delete(`/v1/contexts/${id}`), ignoreBody),\n ),\n ),\n uploadExtension: (archive, options = {}) =>\n archive.byteLength === 0 || archive.byteLength > maxExtensionBytes\n ? Effect.fail(\n failure(\n \"uploadExtension\",\n new InvalidRequest({\n detail: `the archive has ${archive.byteLength} bytes; Browserbase takes 1 byte to 100 MB`,\n }),\n ),\n )\n : Effect.suspend(() => {\n const form = new FormData();\n\n form.append(\n \"file\",\n new Blob([new Uint8Array(archive)], { type: \"application/zip\" }),\n options.fileName ?? \"extension.zip\",\n );\n\n return send(\n \"uploadExtension\",\n HttpClientRequest.post(\"/v1/extensions\").pipe(HttpClientRequest.bodyFormData(form)),\n json(\"uploadExtension\", Extension),\n );\n }),\n getExtension: (id) =>\n checkId(\"getExtension\", id).pipe(\n Effect.flatMap(() =>\n send(\n \"getExtension\",\n HttpClientRequest.get(`/v1/extensions/${id}`),\n json(\"getExtension\", Extension),\n ),\n ),\n ),\n deleteExtension: (id) =>\n checkId(\"deleteExtension\", id).pipe(\n Effect.flatMap(() =>\n send(\"deleteExtension\", HttpClientRequest.delete(`/v1/extensions/${id}`), ignoreBody),\n ),\n ),\n search: (query, options = {}) =>\n withBody(\"search\", HttpClientRequest.post(\"/v1/search\"), {\n query,\n ...(options.results === undefined ? {} : { numResults: options.results }),\n }).pipe(\n Effect.flatMap((request) => send(\"search\", request, json(\"search\", SearchResponse))),\n Effect.map((response) => response.results),\n ),\n fetch: (url, options = {}) =>\n withBody(\"fetch\", HttpClientRequest.post(\"/v1/fetch\"), { url, ...options }).pipe(\n Effect.flatMap((request) => send(\"fetch\", request, json(\"fetch\", FetchedPage))),\n ),\n });\n});\n\nexport const layer = (\n options: Options,\n): Layer.Layer<BrowserbaseClient, never, HttpClient.HttpClient> =>\n Layer.effect(BrowserbaseClient, make(options));\n\n/** The client configured from `BROWSERBASE_API_KEY` and, optionally, `BROWSERBASE_BASE_URL`. */\nexport const layerConfig = (\n options: {\n readonly apiKey?: Config.Config<Redacted.Redacted<string>> | undefined;\n readonly baseUrl?: Config.Config<string> | undefined;\n } = {},\n): Layer.Layer<BrowserbaseClient, Config.ConfigError, HttpClient.HttpClient> =>\n Layer.effect(\n BrowserbaseClient,\n Effect.gen(function* () {\n const apiKey = yield* options.apiKey ?? Config.Redacted(\"BROWSERBASE_API_KEY\");\n\n const baseUrl = yield* (\n options.baseUrl ??\n Config.String(\"BROWSERBASE_BASE_URL\").pipe(Config.withDefault(defaultBaseUrl))\n );\n\n return yield* make({ apiKey, baseUrl });\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,iBAAiB;AAE9B,IAAa,UAAb,cAA6B,OAAO,MAAe,4BAA4B,CAAC,CAAC;CAC/E,IAAI,OAAO;;CA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kBAAkB,OAAO,kBAAkB,IAAI,GAAG,UAAU,CACtF,CACF;EACF,SAAS,OAAO,UAAU,CAAC,MACzB,SAAS,UAAU,kBAAkB,KAAK,YAAY,GAAG;GACvD;GACA,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,QAAQ;EACzE,CAAC,CAAC,CAAC,KACD,OAAO,SAAS,YAAY,KAAK,UAAU,SAAS,KAAK,UAAU,cAAc,CAAC,CAAC,GACnF,OAAO,KAAK,aAAa,SAAS,OAAO,CAC3C;EACF,QAAQ,KAAK,UAAU,CAAC,MACtB,SAAS,SAAS,kBAAkB,KAAK,WAAW,GAAG;GAAE;GAAK,GAAG;EAAQ,CAAC,CAAC,CAAC,KAC1E,OAAO,SAAS,YAAY,KAAK,SAAS,SAAS,KAAK,SAAS,WAAW,CAAC,CAAC,CAChF;CACJ,CAAC;AACH,CAAC;AAED,MAAa,SACX,YAEA,MAAM,OAAO,mBAAmB,KAAK,OAAO,CAAC;;AAG/C,MAAa,eACX,UAGI,CAAC,MAEL,MAAM,OACJ,mBACA,OAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAO,QAAQ,UAAU,OAAO,SAAS,qBAAqB;CAE7E,MAAM,UAAU,OACd,QAAQ,WACN,OAAO,OAAO,sBAAsB,CAAC,CAAC,KAAK,OAAO,YAAA,6BAA0B,CAAC;CAGjF,OAAO,OAAO,KAAK;EAAE;EAAQ;CAAQ,CAAC;AACxC,CAAC,CACH"}
@@ -0,0 +1,79 @@
1
+ import { Schema } from "effect";
2
+ declare namespace BrowserbaseError_d_exports {
3
+ export { BrowserbaseError, Decode, InvalidRequest, NotFound, RateLimited, Reason, Status, Transport, Unauthorized, isTransient };
4
+ }
5
+ declare const Unauthorized_base: Schema.Class<Unauthorized, Schema.TaggedStruct<"Unauthorized", {
6
+ readonly detail: Schema.String;
7
+ }>, import("effect/Cause").YieldableError>;
8
+ /** The API key is missing, wrong or not allowed to do this (401 or 403). */
9
+ declare class Unauthorized extends Unauthorized_base {
10
+ get message(): string;
11
+ }
12
+ declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"NotFound", {
13
+ readonly detail: Schema.String;
14
+ }>, import("effect/Cause").YieldableError>;
15
+ /** No session, context or other resource has that id (404). */
16
+ declare class NotFound extends NotFound_base {
17
+ get message(): string;
18
+ }
19
+ declare const RateLimited_base: Schema.Class<RateLimited, Schema.TaggedStruct<"RateLimited", {
20
+ readonly detail: Schema.String;
21
+ }>, import("effect/Cause").YieldableError>;
22
+ /** Too many concurrent sessions or requests for the plan (429). Wait, then try again. */
23
+ declare class RateLimited extends RateLimited_base {
24
+ get message(): string;
25
+ }
26
+ declare const Status_base: Schema.Class<Status, Schema.TaggedStruct<"Status", {
27
+ readonly status: Schema.Finite;
28
+ readonly detail: Schema.String;
29
+ }>, import("effect/Cause").YieldableError>;
30
+ /** Any other answer that is not a success, including a redirect, which is never followed. */
31
+ declare class Status extends Status_base {
32
+ get message(): string;
33
+ }
34
+ declare const Transport_base: Schema.Class<Transport, Schema.TaggedStruct<"Transport", {
35
+ readonly detail: Schema.String;
36
+ }>, import("effect/Cause").YieldableError>;
37
+ /**
38
+ * No answer arrived: the request could not be sent, or the connection failed. A request that
39
+ * creates something may still have created it.
40
+ */
41
+ declare class Transport extends Transport_base {
42
+ get message(): string;
43
+ }
44
+ declare const Decode_base: Schema.Class<Decode, Schema.TaggedStruct<"Decode", {
45
+ readonly detail: Schema.String;
46
+ readonly released: Schema.optional<Schema.Boolean>;
47
+ }>, import("effect/Cause").YieldableError>;
48
+ /**
49
+ * The answer did not have the expected shape. For a create whose answer named its session,
50
+ * `released` says whether the client then released that session; without it, a session may be
51
+ * left running.
52
+ */
53
+ declare class Decode extends Decode_base {
54
+ get message(): string;
55
+ }
56
+ declare const InvalidRequest_base: Schema.Class<InvalidRequest, Schema.TaggedStruct<"InvalidRequest", {
57
+ readonly detail: Schema.String;
58
+ }>, import("effect/Cause").YieldableError>;
59
+ /**
60
+ * Not a request Browserbase takes, such as an id that is not one: Browserbase refused it (400), or
61
+ * it was refused before sending.
62
+ */
63
+ declare class InvalidRequest extends InvalidRequest_base {
64
+ get message(): string;
65
+ }
66
+ declare const Reason: Schema.Union<readonly [typeof Unauthorized, typeof NotFound, typeof RateLimited, typeof Status, typeof Transport, typeof Decode, typeof InvalidRequest]>;
67
+ type Reason = typeof Reason.Type;
68
+ declare const BrowserbaseError_base: Schema.Class<BrowserbaseError, Schema.TaggedStruct<"BrowserbaseError", {
69
+ readonly operation: Schema.String;
70
+ readonly reason: Schema.Union<readonly [typeof Unauthorized, typeof NotFound, typeof RateLimited, typeof Status, typeof Transport, typeof Decode, typeof InvalidRequest]>;
71
+ }>, import("effect/Cause").YieldableError>;
72
+ declare class BrowserbaseError extends BrowserbaseError_base {
73
+ get message(): string;
74
+ }
75
+ /** True for failures worth retrying after a pause: no answer, a rate limit or a server error. */
76
+ declare const isTransient: (error: BrowserbaseError) => boolean;
77
+ //#endregion
78
+ export { NotFound as a, Status as c, isTransient as d, InvalidRequest as i, Transport as l, BrowserbaseError_d_exports as n, RateLimited as o, Decode as r, Reason as s, BrowserbaseError as t, Unauthorized as u };
79
+ //# sourceMappingURL=BrowserbaseError-D1EOrLNc.d.mts.map
@@ -0,0 +1,2 @@
1
+ import { a as NotFound, c as Status, d as isTransient, i as InvalidRequest, l as Transport, o as RateLimited, r as Decode, s as Reason, t as BrowserbaseError, u as Unauthorized } from "./BrowserbaseError-D1EOrLNc.mjs";
2
+ export { BrowserbaseError, Decode, InvalidRequest, NotFound, RateLimited, Reason, Status, Transport, Unauthorized, isTransient };
@@ -0,0 +1,101 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Schema } from "effect";
3
+ //#region src/BrowserbaseError.ts
4
+ /**
5
+ * The one error every Browserbase API call fails with. `reason` says what went wrong.
6
+ *
7
+ * @since 0.3.0
8
+ */
9
+ var BrowserbaseError_exports = /* @__PURE__ */ __exportAll({
10
+ BrowserbaseError: () => BrowserbaseError,
11
+ Decode: () => Decode,
12
+ InvalidRequest: () => InvalidRequest,
13
+ NotFound: () => NotFound,
14
+ RateLimited: () => RateLimited,
15
+ Reason: () => Reason,
16
+ Status: () => Status,
17
+ Transport: () => Transport,
18
+ Unauthorized: () => Unauthorized,
19
+ isTransient: () => isTransient
20
+ });
21
+ /** The API key is missing, wrong or not allowed to do this (401 or 403). */
22
+ var Unauthorized = class extends Schema.TaggedError()("Unauthorized", { detail: Schema.String }) {
23
+ get message() {
24
+ return `unauthorized: ${this.detail}`;
25
+ }
26
+ };
27
+ /** No session, context or other resource has that id (404). */
28
+ var NotFound = class extends Schema.TaggedError()("NotFound", { detail: Schema.String }) {
29
+ get message() {
30
+ return `not found: ${this.detail}`;
31
+ }
32
+ };
33
+ /** Too many concurrent sessions or requests for the plan (429). Wait, then try again. */
34
+ var RateLimited = class extends Schema.TaggedError()("RateLimited", { detail: Schema.String }) {
35
+ get message() {
36
+ return `rate limited: ${this.detail}`;
37
+ }
38
+ };
39
+ /** Any other answer that is not a success, including a redirect, which is never followed. */
40
+ var Status = class extends Schema.TaggedError()("Status", {
41
+ status: Schema.Finite,
42
+ detail: Schema.String
43
+ }) {
44
+ get message() {
45
+ return `status ${this.status}: ${this.detail}`;
46
+ }
47
+ };
48
+ /**
49
+ * No answer arrived: the request could not be sent, or the connection failed. A request that
50
+ * creates something may still have created it.
51
+ */
52
+ var Transport = class extends Schema.TaggedError()("Transport", { detail: Schema.String }) {
53
+ get message() {
54
+ return this.detail;
55
+ }
56
+ };
57
+ /**
58
+ * The answer did not have the expected shape. For a create whose answer named its session,
59
+ * `released` says whether the client then released that session; without it, a session may be
60
+ * left running.
61
+ */
62
+ var Decode = class extends Schema.TaggedError()("Decode", {
63
+ detail: Schema.String,
64
+ released: Schema.optional(Schema.Boolean)
65
+ }) {
66
+ get message() {
67
+ return `unexpected response: ${this.detail}`;
68
+ }
69
+ };
70
+ /**
71
+ * Not a request Browserbase takes, such as an id that is not one: Browserbase refused it (400), or
72
+ * it was refused before sending.
73
+ */
74
+ var InvalidRequest = class extends Schema.TaggedError()("InvalidRequest", { detail: Schema.String }) {
75
+ get message() {
76
+ return this.detail;
77
+ }
78
+ };
79
+ const Reason = Schema.Union([
80
+ Unauthorized,
81
+ NotFound,
82
+ RateLimited,
83
+ Status,
84
+ Transport,
85
+ Decode,
86
+ InvalidRequest
87
+ ]);
88
+ var BrowserbaseError = class extends Schema.TaggedError()("BrowserbaseError", {
89
+ operation: Schema.String,
90
+ reason: Reason
91
+ }) {
92
+ get message() {
93
+ return `Browserbase ${this.operation} failed: ${this.reason.message}`;
94
+ }
95
+ };
96
+ /** True for failures worth retrying after a pause: no answer, a rate limit or a server error. */
97
+ const isTransient = (error) => error.reason._tag === "Transport" || error.reason._tag === "RateLimited" || error.reason._tag === "Status" && (error.reason.status >= 500 || error.reason.status === 408);
98
+ //#endregion
99
+ export { BrowserbaseError, Decode, InvalidRequest, NotFound, RateLimited, Reason, Status, Transport, Unauthorized, isTransient, BrowserbaseError_exports as t };
100
+
101
+ //# sourceMappingURL=BrowserbaseError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserbaseError.mjs","names":[],"sources":["../src/BrowserbaseError.ts"],"sourcesContent":["/**\n * The one error every Browserbase API call fails with. `reason` says what went wrong.\n *\n * @since 0.3.0\n */\nimport { Schema } from \"effect\";\n\n/** The API key is missing, wrong or not allowed to do this (401 or 403). */\nexport class Unauthorized extends Schema.TaggedError<Unauthorized>()(\"Unauthorized\", {\n detail: Schema.String,\n}) {\n override get message() {\n return `unauthorized: ${this.detail}`;\n }\n}\n\n/** No session, context or other resource has that id (404). */\nexport class NotFound extends Schema.TaggedError<NotFound>()(\"NotFound\", {\n detail: Schema.String,\n}) {\n override get message() {\n return `not found: ${this.detail}`;\n }\n}\n\n/** Too many concurrent sessions or requests for the plan (429). Wait, then try again. */\nexport class RateLimited extends Schema.TaggedError<RateLimited>()(\"RateLimited\", {\n detail: Schema.String,\n}) {\n override get message() {\n return `rate limited: ${this.detail}`;\n }\n}\n\n/** Any other answer that is not a success, including a redirect, which is never followed. */\nexport class Status extends Schema.TaggedError<Status>()(\"Status\", {\n status: Schema.Finite,\n detail: Schema.String,\n}) {\n override get message() {\n return `status ${this.status}: ${this.detail}`;\n }\n}\n\n/**\n * No answer arrived: the request could not be sent, or the connection failed. A request that\n * creates something may still have created it.\n */\nexport class Transport extends Schema.TaggedError<Transport>()(\"Transport\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/**\n * The answer did not have the expected shape. For a create whose answer named its session,\n * `released` says whether the client then released that session; without it, a session may be\n * left running.\n */\nexport class Decode extends Schema.TaggedError<Decode>()(\"Decode\", {\n detail: Schema.String,\n released: Schema.optional(Schema.Boolean),\n}) {\n override get message() {\n return `unexpected response: ${this.detail}`;\n }\n}\n\n/**\n * Not a request Browserbase takes, such as an id that is not one: Browserbase refused it (400), or\n * it was refused before sending.\n */\nexport class InvalidRequest extends Schema.TaggedError<InvalidRequest>()(\"InvalidRequest\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\nexport const Reason = Schema.Union([\n Unauthorized,\n NotFound,\n RateLimited,\n Status,\n Transport,\n Decode,\n InvalidRequest,\n]);\n\nexport type Reason = typeof Reason.Type;\n\nexport class BrowserbaseError extends Schema.TaggedError<BrowserbaseError>()(\"BrowserbaseError\", {\n operation: Schema.String,\n reason: Reason,\n}) {\n override get message() {\n return `Browserbase ${this.operation} failed: ${this.reason.message}`;\n }\n}\n\n/** True for failures worth retrying after a pause: no answer, a rate limit or a server error. */\nexport const isTransient = (error: BrowserbaseError): boolean =>\n error.reason._tag === \"Transport\" ||\n error.reason._tag === \"RateLimited\" ||\n (error.reason._tag === \"Status\" && (error.reason.status >= 500 || error.reason.status === 408));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAAC,gBAAgB,E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AC/F,WAAW,OAAO;CAClB,QAAQ;AACV,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,eAAe,KAAK,UAAU,WAAW,KAAK,OAAO;CAC9D;AACF;;AAGA,MAAa,eAAe,UAC1B,MAAM,OAAO,SAAS,eACtB,MAAM,OAAO,SAAS,iBACrB,MAAM,OAAO,SAAS,aAAa,MAAM,OAAO,UAAU,OAAO,MAAM,OAAO,WAAW"}
@@ -0,0 +1,42 @@
1
+ import { Context, Effect, Layer, Schema, Scope } from "effect";
2
+ declare namespace ContextLease_d_exports {
3
+ export { ContextHeld, ContextLease, Hold, Service, layer };
4
+ }
5
+ declare const ContextHeld_base: Schema.Class<ContextHeld, Schema.TaggedStruct<"ContextHeld", {
6
+ readonly context: Schema.String;
7
+ readonly detail: Schema.String;
8
+ }>, import("effect/Cause").YieldableError>;
9
+ /**
10
+ * The stored context could not be held for writing: a session that saves to it may still run, as
11
+ * its sessions could not be confirmed ended, or the lease itself could not be taken. The next try
12
+ * clears it again.
13
+ */
14
+ export declare class ContextHeld extends ContextHeld_base {
15
+ get message(): string;
16
+ }
17
+ /** A writer's hold on a stored context, for the scope `hold` was given. */
18
+ export interface Hold {
19
+ /** Whether a session that saves to the context may still run, as the writer before left it. */
20
+ readonly unsettled: boolean;
21
+ /** Say how this writer leaves the context, once, before the hold goes: the next writer reads it. */
22
+ readonly leave: (unsettled: boolean) => Effect.Effect<void>;
23
+ }
24
+ export interface Service {
25
+ /**
26
+ * Hold the context as its only writer until the scope closes, waiting while another holds it.
27
+ * It fails with `ContextHeld` when the lease cannot be taken, as when its own store is down.
28
+ */
29
+ readonly hold: (context: string) => Effect.Effect<Hold, ContextHeld, Scope.Scope>;
30
+ }
31
+ declare const ContextLease_base: Context.ServiceClass<ContextLease, "effect-browserbase/ContextLease", Service>;
32
+ export declare class ContextLease extends ContextLease_base {}
33
+ /**
34
+ * The lease within this process: one writer at a time for each stored context. A context it has
35
+ * not held is presumed settled, so writers in other processes are the application's to exclude,
36
+ * with a lease of its own. It forgets a context once nobody holds it, or waits for it, and it was
37
+ * left settled.
38
+ */
39
+ export declare const layer: Layer.Layer<ContextLease>;
40
+ //#endregion
41
+ export { ContextLease_d_exports as t };
42
+ //# sourceMappingURL=ContextLease.d.mts.map
@@ -0,0 +1,80 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Context, Effect, Layer, Schema, Semaphore } from "effect";
3
+ //#region src/ContextLease.ts
4
+ /**
5
+ * Who may write a stored context. A session that persists to a context saves to it when the
6
+ * session ends, so two at once can lose one's changes. `Browserbase.open` holds a context through
7
+ * its `ContextLease` from before it creates a persisting session until that session has ended and
8
+ * its save has settled, and the next writer waits. `verifyContext` and `reconcile` hold it too.
9
+ *
10
+ * The lease is a port. `layer` holds contexts within the process that builds it. An application
11
+ * whose writers run in several processes provides its own, such as an advisory lock in its
12
+ * database, and so excludes them all.
13
+ *
14
+ * A hold also passes on how the writer before left the context: `unsettled` while a session that
15
+ * saves to it may still run, as when that writer's release was left unconfirmed, its create's answer
16
+ * was lost, or it kept its session past its scope. The next writer then ends the context's sessions
17
+ * before it writes. A writer says how it leaves the context once, as it lets the hold go; a hold
18
+ * that never says, as when its process ends first, must read as `unsettled` to the next.
19
+ *
20
+ * @since 0.3.0
21
+ */
22
+ var ContextLease_exports = /* @__PURE__ */ __exportAll({
23
+ ContextHeld: () => ContextHeld,
24
+ ContextLease: () => ContextLease,
25
+ layer: () => layer
26
+ });
27
+ /**
28
+ * The stored context could not be held for writing: a session that saves to it may still run, as
29
+ * its sessions could not be confirmed ended, or the lease itself could not be taken. The next try
30
+ * clears it again.
31
+ */
32
+ var ContextHeld = class extends Schema.TaggedError()("ContextHeld", {
33
+ context: Schema.String,
34
+ detail: Schema.String
35
+ }) {
36
+ get message() {
37
+ return `context ${this.context} is held: ${this.detail}`;
38
+ }
39
+ };
40
+ var ContextLease = class extends Context.Service()("effect-browserbase/ContextLease") {};
41
+ /**
42
+ * The lease within this process: one writer at a time for each stored context. A context it has
43
+ * not held is presumed settled, so writers in other processes are the application's to exclude,
44
+ * with a lease of its own. It forgets a context once nobody holds it, or waits for it, and it was
45
+ * left settled.
46
+ */
47
+ const layer = Layer.sync(ContextLease, () => {
48
+ const contexts = /* @__PURE__ */ new Map();
49
+ const enter = (context) => {
50
+ const entry = contexts.get(context) ?? {
51
+ lock: Semaphore.makeUnsafe(1),
52
+ unsettled: false,
53
+ users: 0
54
+ };
55
+ entry.users += 1;
56
+ contexts.set(context, entry);
57
+ return entry;
58
+ };
59
+ const exit = (context, entry) => {
60
+ entry.users -= 1;
61
+ if (entry.users === 0 && !entry.unsettled) contexts.delete(context);
62
+ };
63
+ return ContextLease.of({ hold: (context) => Effect.gen(function* () {
64
+ const entry = yield* Effect.acquireRelease(Effect.sync(() => enter(context)), (entered) => Effect.sync(() => exit(context, entered)));
65
+ let leaving = true;
66
+ yield* Effect.acquireRelease(entry.lock.take(1), () => Effect.sync(() => {
67
+ entry.unsettled = leaving;
68
+ }).pipe(Effect.andThen(entry.lock.release(1))), { interruptible: true });
69
+ return {
70
+ unsettled: entry.unsettled,
71
+ leave: (unsettled) => Effect.sync(() => {
72
+ leaving = unsettled;
73
+ })
74
+ };
75
+ }) });
76
+ });
77
+ //#endregion
78
+ export { ContextHeld, ContextLease, layer, ContextLease_exports as t };
79
+
80
+ //# sourceMappingURL=ContextLease.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextLease.mjs","names":[],"sources":["../src/ContextLease.ts"],"sourcesContent":["/**\n * Who may write a stored context. A session that persists to a context saves to it when the\n * session ends, so two at once can lose one's changes. `Browserbase.open` holds a context through\n * its `ContextLease` from before it creates a persisting session until that session has ended and\n * its save has settled, and the next writer waits. `verifyContext` and `reconcile` hold it too.\n *\n * The lease is a port. `layer` holds contexts within the process that builds it. An application\n * whose writers run in several processes provides its own, such as an advisory lock in its\n * database, and so excludes them all.\n *\n * A hold also passes on how the writer before left the context: `unsettled` while a session that\n * saves to it may still run, as when that writer's release was left unconfirmed, its create's answer\n * was lost, or it kept its session past its scope. The next writer then ends the context's sessions\n * before it writes. A writer says how it leaves the context once, as it lets the hold go; a hold\n * that never says, as when its process ends first, must read as `unsettled` to the next.\n *\n * @since 0.3.0\n */\nimport { Context, Effect, Layer, Schema, type Scope, Semaphore } from \"effect\";\n\n/**\n * The stored context could not be held for writing: a session that saves to it may still run, as\n * its sessions could not be confirmed ended, or the lease itself could not be taken. The next try\n * clears it again.\n */\nexport class ContextHeld extends Schema.TaggedError<ContextHeld>()(\"ContextHeld\", {\n context: Schema.String,\n detail: Schema.String,\n}) {\n override get message() {\n return `context ${this.context} is held: ${this.detail}`;\n }\n}\n\n/** A writer's hold on a stored context, for the scope `hold` was given. */\nexport interface Hold {\n /** Whether a session that saves to the context may still run, as the writer before left it. */\n readonly unsettled: boolean;\n /** Say how this writer leaves the context, once, before the hold goes: the next writer reads it. */\n readonly leave: (unsettled: boolean) => Effect.Effect<void>;\n}\n\nexport interface Service {\n /**\n * Hold the context as its only writer until the scope closes, waiting while another holds it.\n * It fails with `ContextHeld` when the lease cannot be taken, as when its own store is down.\n */\n readonly hold: (context: string) => Effect.Effect<Hold, ContextHeld, Scope.Scope>;\n}\n\nexport class ContextLease extends Context.Service<ContextLease, Service>()(\n \"effect-browserbase/ContextLease\",\n) {}\n\ninterface Entry {\n readonly lock: Semaphore.Semaphore;\n unsettled: boolean;\n /** Its holder and the writers waiting for it. */\n users: number;\n}\n\n/**\n * The lease within this process: one writer at a time for each stored context. A context it has\n * not held is presumed settled, so writers in other processes are the application's to exclude,\n * with a lease of its own. It forgets a context once nobody holds it, or waits for it, and it was\n * left settled.\n */\nexport const layer: Layer.Layer<ContextLease> = Layer.sync(ContextLease, () => {\n const contexts = new Map<string, Entry>();\n\n const enter = (context: string) => {\n const entry = contexts.get(context) ?? {\n lock: Semaphore.makeUnsafe(1),\n unsettled: false,\n users: 0,\n };\n\n entry.users += 1;\n contexts.set(context, entry);\n\n return entry;\n };\n\n const exit = (context: string, entry: Entry) => {\n entry.users -= 1;\n if (entry.users === 0 && !entry.unsettled) contexts.delete(context);\n };\n\n return ContextLease.of({\n hold: (context) =>\n Effect.gen(function* () {\n const entry = yield* Effect.acquireRelease(\n Effect.sync(() => enter(context)),\n (entered) => Effect.sync(() => exit(context, entered)),\n );\n\n // Unless the holder says otherwise, it leaves a session that saves to the context running.\n let leaving = true;\n\n yield* Effect.acquireRelease(\n entry.lock.take(1),\n () =>\n Effect.sync(() => {\n entry.unsettled = leaving;\n }).pipe(Effect.andThen(entry.lock.release(1))),\n { interruptible: true },\n );\n\n return {\n unsettled: entry.unsettled,\n leave: (unsettled) =>\n Effect.sync(() => {\n leaving = unsettled;\n }),\n } satisfies Hold;\n }),\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CAAC,eAAe;CAChF,SAAS,OAAO;CAChB,QAAQ,OAAO;AACjB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,WAAW,KAAK,QAAQ,YAAY,KAAK;CAClD;AACF;AAkBA,IAAa,eAAb,cAAkC,QAAQ,QAA+B,CAAC,CACxE,iCACF,CAAC,CAAC,CAAC;;;;;;;AAeH,MAAa,QAAmC,MAAM,KAAK,oBAAoB;CAC7E,MAAM,2BAAW,IAAI,IAAmB;CAExC,MAAM,SAAS,YAAoB;EACjC,MAAM,QAAQ,SAAS,IAAI,OAAO,KAAK;GACrC,MAAM,UAAU,WAAW,CAAC;GAC5B,WAAW;GACX,OAAO;EACT;EAEA,MAAM,SAAS;EACf,SAAS,IAAI,SAAS,KAAK;EAE3B,OAAO;CACT;CAEA,MAAM,QAAQ,SAAiB,UAAiB;EAC9C,MAAM,SAAS;EACf,IAAI,MAAM,UAAU,KAAK,CAAC,MAAM,WAAW,SAAS,OAAO,OAAO;CACpE;CAEA,OAAO,aAAa,GAAG,EACrB,OAAO,YACL,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,OAAO,eAC1B,OAAO,WAAW,MAAM,OAAO,CAAC,IAC/B,YAAY,OAAO,WAAW,KAAK,SAAS,OAAO,CAAC,CACvD;EAGA,IAAI,UAAU;EAEd,OAAO,OAAO,eACZ,MAAM,KAAK,KAAK,CAAC,SAEf,OAAO,WAAW;GAChB,MAAM,YAAY;EACpB,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAC/C,EAAE,eAAe,KAAK,CACxB;EAEA,OAAO;GACL,WAAW,MAAM;GACjB,QAAQ,cACN,OAAO,WAAW;IAChB,UAAU;GACZ,CAAC;EACL;CACF,CAAC,EACL,CAAC;AACH,CAAC"}
package/dist/index.d.mts CHANGED
@@ -1,27 +1,5 @@
1
- import * as Account from "./Account.mjs";
2
- import * as Agents from "./Agents.mjs";
3
- import * as Allocation from "./Allocation.mjs";
4
- import * as Browser from "./Browser.mjs";
5
- import * as Certificates from "./Certificates.mjs";
6
- import * as Cleanup from "./Cleanup.mjs";
7
- import * as Client from "./Client.mjs";
8
- import * as ContextCoordination from "./ContextCoordination.mjs";
9
- import * as Contexts from "./Contexts.mjs";
10
- import * as Downloads from "./Downloads.mjs";
11
- import * as Errors from "./Errors.mjs";
12
- import * as Extensions from "./Extensions.mjs";
13
- import * as Functions from "./Functions.mjs";
14
- import * as Launch from "./Launch.mjs";
15
- import * as PageFetch from "./PageFetch.mjs";
16
- import * as Projects from "./Projects.mjs";
17
- import * as Recordings from "./Recordings.mjs";
18
- import * as References from "./References.mjs";
19
- import * as Replays from "./Replays.mjs";
20
- import * as Search from "./Search.mjs";
21
- import * as SessionData from "./SessionData.mjs";
22
- import * as Sessions from "./Sessions.mjs";
23
- import * as Transfers from "./Transfers.mjs";
24
- import * as Uploads from "./Uploads.mjs";
25
- import * as Webhooks from "./Webhooks.mjs";
26
- export { Account, Agents, Allocation, Browser, Certificates, Cleanup, Client, ContextCoordination, Contexts, Downloads, Errors, Extensions, Functions, Launch, PageFetch, Projects, Recordings, References, Replays, Search, SessionData, Sessions, Transfers, Uploads, Webhooks };
27
- export {};
1
+ import { n as BrowserbaseError_d_exports } from "./BrowserbaseError-D1EOrLNc.mjs";
2
+ import { r as BrowserbaseClient_d_exports } from "./BrowserbaseClient-CtAQ2rg4.mjs";
3
+ import { t as ContextLease_d_exports } from "./ContextLease.mjs";
4
+ import { t as Browserbase_d_exports } from "./Browserbase.mjs";
5
+ export { Browserbase_d_exports as Browserbase, BrowserbaseClient_d_exports as BrowserbaseClient, BrowserbaseError_d_exports as BrowserbaseError, ContextLease_d_exports as ContextLease };
package/dist/index.mjs CHANGED
@@ -1,26 +1,5 @@
1
- import * as Account from "./Account.mjs";
2
- import * as Agents from "./Agents.mjs";
3
- import * as Allocation from "./Allocation.mjs";
4
- import * as Browser from "./Browser.mjs";
5
- import * as Certificates from "./Certificates.mjs";
6
- import * as Cleanup from "./Cleanup.mjs";
7
- import * as Client from "./Client.mjs";
8
- import * as ContextCoordination from "./ContextCoordination.mjs";
9
- import * as Contexts from "./Contexts.mjs";
10
- import * as Downloads from "./Downloads.mjs";
11
- import * as Errors from "./Errors.mjs";
12
- import * as Extensions from "./Extensions.mjs";
13
- import * as Functions from "./Functions.mjs";
14
- import * as Launch from "./Launch.mjs";
15
- import * as PageFetch from "./PageFetch.mjs";
16
- import * as Projects from "./Projects.mjs";
17
- import * as Recordings from "./Recordings.mjs";
18
- import * as References from "./References.mjs";
19
- import * as Replays from "./Replays.mjs";
20
- import * as Search from "./Search.mjs";
21
- import * as SessionData from "./SessionData.mjs";
22
- import * as Sessions from "./Sessions.mjs";
23
- import * as Transfers from "./Transfers.mjs";
24
- import * as Uploads from "./Uploads.mjs";
25
- import * as Webhooks from "./Webhooks.mjs";
26
- export { Account, Agents, Allocation, Browser, Certificates, Cleanup, Client, ContextCoordination, Contexts, Downloads, Errors, Extensions, Functions, Launch, PageFetch, Projects, Recordings, References, Replays, Search, SessionData, Sessions, Transfers, Uploads, Webhooks };
1
+ import { t as BrowserbaseError_exports } from "./BrowserbaseError.mjs";
2
+ import { t as BrowserbaseClient_exports } from "./BrowserbaseClient.mjs";
3
+ import { t as ContextLease_exports } from "./ContextLease.mjs";
4
+ import { t as Browserbase_exports } from "./Browserbase-CaPKwEY9.mjs";
5
+ export { Browserbase_exports as Browserbase, BrowserbaseClient_exports as BrowserbaseClient, BrowserbaseError_exports as BrowserbaseError, ContextLease_exports as ContextLease };
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
@@ -0,0 +1,136 @@
1
+ import { t as BrowserbaseError } from "../BrowserbaseError-D1EOrLNc.mjs";
2
+ import { n as BrowserbaseClient, p as SessionOptions } from "../BrowserbaseClient-CtAQ2rg4.mjs";
3
+ import { Context, Effect, Layer, Schema } from "effect";
4
+ import { HttpClient } from "effect/http";
5
+ declare namespace BrowserbaseContract_d_exports {
6
+ export { Broken, Check, checks };
7
+ }
8
+ declare const Broken_base: Schema.Class<Broken, Schema.TaggedStruct<"Broken", {
9
+ readonly check: Schema.String;
10
+ readonly detail: Schema.String;
11
+ }>, import("effect/Cause").YieldableError>;
12
+ /** A check found the API behaving otherwise. */
13
+ declare class Broken extends Broken_base {
14
+ get message(): string;
15
+ }
16
+ interface Check {
17
+ readonly name: string;
18
+ /** It moves the test clock, so only the fake can run it. */
19
+ readonly clock: boolean;
20
+ readonly run: Effect.Effect<void, Broken | BrowserbaseError, BrowserbaseClient>;
21
+ }
22
+ declare const checks: ReadonlyArray<Check>;
23
+ declare namespace TestBrowserbase_d_exports {
24
+ export { Create, Handle, Kept, Read, Release, Script, TestBrowserbase, apiKey, layer, make };
25
+ }
26
+ /** How a session create answers. */
27
+ declare const Create: Schema.Union<readonly [Schema.TaggedStruct<"Accept", {}>, Schema.TaggedStruct<"Reject", {
28
+ readonly status: Schema.Int;
29
+ readonly retryAfterSeconds: Schema.optional<Schema.Int>;
30
+ }>, Schema.TaggedStruct<"Malformed", {}>, Schema.TaggedStruct<"Lost", {
31
+ readonly listedAfter: Schema.optional<Schema.Finite>;
32
+ }>]>;
33
+ /** How a release answers. */
34
+ declare const Release: Schema.Union<readonly [Schema.TaggedStruct<"Ends", {}>, Schema.TaggedStruct<"Pending", {
35
+ readonly millis: Schema.optional<Schema.Finite>;
36
+ }>, Schema.TaggedStruct<"Refused", {
37
+ readonly status: Schema.Int;
38
+ }>, Schema.TaggedStruct<"Lost", {}>]>;
39
+ /** How a session read answers. */
40
+ declare const Read: Schema.Union<readonly [Schema.TaggedStruct<"Answer", {}>, Schema.TaggedStruct<"Refused", {
41
+ readonly status: Schema.Int;
42
+ }>, Schema.TaggedStruct<"Lost", {}>]>;
43
+ declare const Script: Schema.Struct<{
44
+ /** How creates answer, in turn; once these run out, each is accepted. */
45
+ readonly creates: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"Accept", {}>, Schema.TaggedStruct<"Reject", {
46
+ readonly status: Schema.Int;
47
+ readonly retryAfterSeconds: Schema.optional<Schema.Int>;
48
+ }>, Schema.TaggedStruct<"Malformed", {}>, Schema.TaggedStruct<"Lost", {
49
+ readonly listedAfter: Schema.optional<Schema.Finite>;
50
+ }>]>>>;
51
+ /** How releases answer, in turn; once these run out, each ends its session. */
52
+ readonly releases: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"Ends", {}>, Schema.TaggedStruct<"Pending", {
53
+ readonly millis: Schema.optional<Schema.Finite>;
54
+ }>, Schema.TaggedStruct<"Refused", {
55
+ readonly status: Schema.Int;
56
+ }>, Schema.TaggedStruct<"Lost", {}>]>>>;
57
+ /** How session reads answer, in turn; once these run out, each answers. */
58
+ readonly reads: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"Answer", {}>, Schema.TaggedStruct<"Refused", {
59
+ readonly status: Schema.Int;
60
+ }>, Schema.TaggedStruct<"Lost", {}>]>>>;
61
+ /** The DevTools address each session hands out. Without it, sessions have none. */
62
+ readonly connectUrl: Schema.optional<Schema.String>;
63
+ }>;
64
+ type Script = typeof Script.Type;
65
+ /** A session as the fake keeps it, with how many releases it was asked. */
66
+ interface Kept {
67
+ readonly id: string;
68
+ readonly status: string;
69
+ /** The create options as sent, without provider defaults. Only the test handle exposes them. */
70
+ readonly options: SessionOptions;
71
+ readonly userMetadata: Readonly<Record<string, unknown>> | undefined;
72
+ readonly releases: number;
73
+ /** Whether it was created to outlive its connections, until released or timed out. */
74
+ readonly keepAlive: boolean;
75
+ /** The stored context it loaded, and whether it saves to it as it ends. */
76
+ readonly context: {
77
+ readonly id: string;
78
+ readonly persist: boolean;
79
+ } | undefined;
80
+ }
81
+ interface Handle {
82
+ /** Every request, oldest first, as `METHOD /path?query`. */
83
+ readonly requests: Effect.Effect<ReadonlyArray<string>>;
84
+ /** Each session as Browserbase would describe it now, oldest first. */
85
+ readonly sessions: Effect.Effect<ReadonlyArray<Kept>>;
86
+ /** End a session as Browserbase does on its own, as when its browser fails. */
87
+ readonly end: (id: string) => Effect.Effect<void>;
88
+ }
89
+ declare const TestBrowserbase_base: Context.ServiceClass<TestBrowserbase, "effect-browserbase/testing/TestBrowserbase", Handle>;
90
+ /** The fake's handle, beside the `BrowserbaseClient` that `layer` runs on it. */
91
+ declare class TestBrowserbase extends TestBrowserbase_base {}
92
+ /** The API key the fake takes; any other is unauthorized. */
93
+ declare const apiKey = "test-browserbase-key";
94
+ /** The fake as an `HttpClient`, with its handle. */
95
+ declare const make: (script?: {
96
+ readonly creates?: readonly ({
97
+ readonly _tag: "Accept";
98
+ } | {
99
+ readonly _tag: "Reject";
100
+ readonly status: number;
101
+ readonly retryAfterSeconds?: number | undefined;
102
+ } | {
103
+ readonly _tag: "Malformed";
104
+ } | {
105
+ readonly _tag: "Lost";
106
+ readonly listedAfter?: number | undefined;
107
+ })[] | undefined;
108
+ readonly releases?: readonly ({
109
+ readonly _tag: "Lost";
110
+ } | {
111
+ readonly _tag: "Ends";
112
+ } | {
113
+ readonly _tag: "Pending";
114
+ readonly millis?: number | undefined;
115
+ } | {
116
+ readonly _tag: "Refused";
117
+ readonly status: number;
118
+ })[] | undefined;
119
+ readonly reads?: readonly ({
120
+ readonly _tag: "Answer";
121
+ } | {
122
+ readonly _tag: "Refused";
123
+ readonly status: number;
124
+ } | {
125
+ readonly _tag: "Lost";
126
+ })[] | undefined;
127
+ readonly connectUrl?: string | undefined;
128
+ } | undefined) => Effect.Effect<{
129
+ http: HttpClient.HttpClient;
130
+ handle: Handle;
131
+ }, never, never>;
132
+ /** The real `BrowserbaseClient` over the fake, and the fake's handle. */
133
+ declare const layer: (script?: Script) => Layer.Layer<BrowserbaseClient | TestBrowserbase>;
134
+ //#endregion
135
+ export { BrowserbaseContract_d_exports as BrowserbaseContract, TestBrowserbase_d_exports as TestBrowserbase };
136
+ //# sourceMappingURL=index.d.mts.map