effect-browserbase 0.1.0-beta.104 → 0.2.0-beta.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.
Files changed (158) hide show
  1. package/README.md +106 -307
  2. package/dist/Account.d.mts +17 -19
  3. package/dist/Account.mjs +4 -9
  4. package/dist/Account.mjs.map +1 -1
  5. package/dist/{Acquisition-WBafHwXH.mjs → Acquisition-CAsTTXp4.mjs} +25 -70
  6. package/dist/Acquisition-CAsTTXp4.mjs.map +1 -0
  7. package/dist/Agents-5HpTp9YE.d.mts +155 -0
  8. package/dist/Agents.d.mts +3 -156
  9. package/dist/Agents.mjs +4 -20
  10. package/dist/Agents.mjs.map +1 -1
  11. package/dist/Allocation.d.mts +9 -11
  12. package/dist/Allocation.mjs +2 -4
  13. package/dist/Allocation.mjs.map +1 -1
  14. package/dist/Browser-DpSajNai.mjs +270 -0
  15. package/dist/Browser-DpSajNai.mjs.map +1 -0
  16. package/dist/Browser.d.mts +26 -143
  17. package/dist/Browser.mjs +3 -223
  18. package/dist/BrowserBinding.d.mts +7 -34
  19. package/dist/BrowserBinding.mjs +30 -1
  20. package/dist/BrowserBinding.mjs.map +1 -0
  21. package/dist/Certificates-D4NQmyeA.d.mts +34 -0
  22. package/dist/Certificates.d.mts +3 -35
  23. package/dist/Certificates.mjs +2 -7
  24. package/dist/Certificates.mjs.map +1 -1
  25. package/dist/{Cleanup-G2YpTCuU.d.mts → Cleanup-DMTDBir8.d.mts} +5 -6
  26. package/dist/Cleanup.d.mts +3 -2
  27. package/dist/Cleanup.mjs +1 -6
  28. package/dist/Cleanup.mjs.map +1 -1
  29. package/dist/{Client-D1_xYM9o.mjs → Client-4RMKIpL2.mjs} +12 -12
  30. package/dist/Client-4RMKIpL2.mjs.map +1 -0
  31. package/dist/{Client-Ca0zSg1n.d.mts → Client-B_f6bBLT.d.mts} +4 -5
  32. package/dist/Client.d.mts +3 -2
  33. package/dist/Client.mjs +1 -1
  34. package/dist/Connection-sxyxtwlk.mjs +56 -0
  35. package/dist/Connection-sxyxtwlk.mjs.map +1 -0
  36. package/dist/ContextCoordination.d.mts +5 -6
  37. package/dist/ContextCoordination.mjs +2 -9
  38. package/dist/ContextCoordination.mjs.map +1 -1
  39. package/dist/{ContextWriter-BrQmoXRg.mjs → ContextWriter-oKWFLHuP.mjs} +8 -12
  40. package/dist/ContextWriter-oKWFLHuP.mjs.map +1 -0
  41. package/dist/Contexts-DqdL7cyX.d.mts +31 -0
  42. package/dist/Contexts.d.mts +3 -32
  43. package/dist/Contexts.mjs +3 -9
  44. package/dist/Contexts.mjs.map +1 -1
  45. package/dist/Downloads-CdhiCO5X.d.mts +43 -0
  46. package/dist/Downloads.d.mts +3 -44
  47. package/dist/Downloads.mjs +3 -8
  48. package/dist/Downloads.mjs.map +1 -1
  49. package/dist/Errors.d.mts +3 -26
  50. package/dist/Errors.mjs +1 -137
  51. package/dist/Errors.mjs.map +1 -1
  52. package/dist/Extensions-DBXuVM1f.d.mts +43 -0
  53. package/dist/{Extensions-ClZbYb1H.mjs → Extensions-Dg3jHOf0.mjs} +3 -9
  54. package/dist/Extensions-Dg3jHOf0.mjs.map +1 -0
  55. package/dist/Extensions.d.mts +3 -44
  56. package/dist/Extensions.mjs +1 -1
  57. package/dist/Functions-CsKMMUuZ.d.mts +226 -0
  58. package/dist/Functions.d.mts +3 -227
  59. package/dist/Functions.mjs +4 -18
  60. package/dist/Functions.mjs.map +1 -1
  61. package/dist/{Launch-BHcAEq05.mjs → Launch-cAdE2rrZ.mjs} +16 -12
  62. package/dist/Launch-cAdE2rrZ.mjs.map +1 -0
  63. package/dist/Launch.d.mts +127 -2
  64. package/dist/Launch.mjs +5 -13
  65. package/dist/Launch.mjs.map +1 -1
  66. package/dist/PageFetch-CAMqb5m8.d.mts +39 -0
  67. package/dist/PageFetch.d.mts +3 -40
  68. package/dist/PageFetch.mjs +2 -8
  69. package/dist/PageFetch.mjs.map +1 -1
  70. package/dist/Projects-tm5bTDH0.d.mts +38 -0
  71. package/dist/Projects.d.mts +3 -39
  72. package/dist/Projects.mjs +2 -8
  73. package/dist/Projects.mjs.map +1 -1
  74. package/dist/Recordings-bVI33sTq.d.mts +27 -0
  75. package/dist/Recordings.d.mts +3 -28
  76. package/dist/Recordings.mjs +3 -5
  77. package/dist/Recordings.mjs.map +1 -1
  78. package/dist/{References-URDAtapt.d.mts → References-DOH3Wu44.d.mts} +5 -6
  79. package/dist/References.d.mts +3 -2
  80. package/dist/References.mjs +10 -18
  81. package/dist/References.mjs.map +1 -1
  82. package/dist/Replays-Bo-9xeLz.d.mts +27 -0
  83. package/dist/Replays.d.mts +3 -28
  84. package/dist/Replays.mjs +3 -5
  85. package/dist/Replays.mjs.map +1 -1
  86. package/dist/Search-1g6TUem7.d.mts +37 -0
  87. package/dist/Search.d.mts +3 -38
  88. package/dist/Search.mjs +2 -9
  89. package/dist/Search.mjs.map +1 -1
  90. package/dist/{SessionData-DRKcKCqw.d.mts → SessionData-5xYZDshJ.d.mts} +5 -6
  91. package/dist/SessionData.d.mts +3 -2
  92. package/dist/SessionData.mjs +1 -8
  93. package/dist/SessionData.mjs.map +1 -1
  94. package/dist/{Sessions-B8E4kMxo.d.mts → Sessions-BpZgjteE.d.mts} +8 -8
  95. package/dist/{Sessions-CtbseWEh.mjs → Sessions-suOLSym9.mjs} +34 -18
  96. package/dist/Sessions-suOLSym9.mjs.map +1 -0
  97. package/dist/Sessions.d.mts +4 -3
  98. package/dist/Sessions.mjs +1 -1
  99. package/dist/Testing.d.mts +119 -0
  100. package/dist/Testing.mjs +206 -0
  101. package/dist/Testing.mjs.map +1 -0
  102. package/dist/{Transfers-Czv5IZzJ.d.mts → Transfers-GVqzrDWl.d.mts} +22 -9
  103. package/dist/Transfers.d.mts +3 -2
  104. package/dist/Transfers.mjs +12 -28
  105. package/dist/Transfers.mjs.map +1 -1
  106. package/dist/Uploads-C2neBEpj.d.mts +28 -0
  107. package/dist/Uploads.d.mts +3 -29
  108. package/dist/Uploads.mjs +3 -5
  109. package/dist/Uploads.mjs.map +1 -1
  110. package/dist/Webhooks-BoeRAxzG.d.mts +59 -0
  111. package/dist/Webhooks.d.mts +3 -60
  112. package/dist/Webhooks.mjs +2 -11
  113. package/dist/Webhooks.mjs.map +1 -1
  114. package/dist/{WriterFacts-osvYAsIx.d.mts → WriterFacts-BBJRDZYY.d.mts} +8 -15
  115. package/dist/index.d.mts +27 -31
  116. package/dist/index.mjs +26 -31
  117. package/package.json +7 -28
  118. package/dist/Acquisition-WBafHwXH.mjs.map +0 -1
  119. package/dist/Association-CEps4hYP.mjs +0 -10
  120. package/dist/Association-CEps4hYP.mjs.map +0 -1
  121. package/dist/Bootstrap-BXuzZojd.mjs +0 -194
  122. package/dist/Bootstrap-BXuzZojd.mjs.map +0 -1
  123. package/dist/Bootstrap-m7lHgj0D.d.mts +0 -177
  124. package/dist/Bootstrap.d.mts +0 -2
  125. package/dist/Bootstrap.mjs +0 -2
  126. package/dist/Browser.mjs.map +0 -1
  127. package/dist/BrowserBinding-DlJTGYZL.mjs +0 -2508
  128. package/dist/BrowserBinding-DlJTGYZL.mjs.map +0 -1
  129. package/dist/BrowserData-LpcAuAub.d.mts +0 -369
  130. package/dist/BrowserData.d.mts +0 -2
  131. package/dist/BrowserData.mjs +0 -442
  132. package/dist/BrowserData.mjs.map +0 -1
  133. package/dist/Capture-Bc0z9IAi.mjs +0 -571
  134. package/dist/Capture-Bc0z9IAi.mjs.map +0 -1
  135. package/dist/Capture-BvWI-l1A.d.mts +0 -168
  136. package/dist/Capture.d.mts +0 -2
  137. package/dist/Capture.mjs +0 -2
  138. package/dist/Client-D1_xYM9o.mjs.map +0 -1
  139. package/dist/ContextWriter-BrQmoXRg.mjs.map +0 -1
  140. package/dist/Extensions-ClZbYb1H.mjs.map +0 -1
  141. package/dist/Images-DgscEfSf.mjs +0 -127
  142. package/dist/Images-DgscEfSf.mjs.map +0 -1
  143. package/dist/Launch-BHcAEq05.mjs.map +0 -1
  144. package/dist/Launch-C8CfaYxb.d.mts +0 -132
  145. package/dist/LocalBrowser-BLancJ3R.d.mts +0 -79
  146. package/dist/LocalBrowser-DsQLWNL1.mjs +0 -439
  147. package/dist/LocalBrowser-DsQLWNL1.mjs.map +0 -1
  148. package/dist/LocalBrowser.d.mts +0 -2
  149. package/dist/LocalBrowser.mjs +0 -2
  150. package/dist/PageControl.d.mts +0 -16
  151. package/dist/PageControl.mjs +0 -36
  152. package/dist/PageControl.mjs.map +0 -1
  153. package/dist/PageControlAssociation-DabEg5AR.mjs +0 -10
  154. package/dist/PageControlAssociation-DabEg5AR.mjs.map +0 -1
  155. package/dist/Session-D4nT9hOO.mjs +0 -1379
  156. package/dist/Session-D4nT9hOO.mjs.map +0 -1
  157. package/dist/Sessions-CtbseWEh.mjs.map +0 -1
  158. package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
package/dist/Agents.mjs CHANGED
@@ -1,28 +1,12 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
1
  import { ContextReference, Identifier } from "./References.mjs";
3
2
  import { PlatformError } from "./Errors.mjs";
4
- import { t as BrowserbaseClient } from "./Client-D1_xYM9o.mjs";
3
+ import { t as BrowserbaseClient } from "./Client-4RMKIpL2.mjs";
5
4
  import { t as resource } from "./Resource-DBksC4zB.mjs";
6
5
  import { ProxyRule } from "./Launch.mjs";
7
- import { n as proxy } from "./Launch-BHcAEq05.mjs";
8
- import { n as isContextWriterBusy } from "./ContextWriter-BrQmoXRg.mjs";
6
+ import { n as proxy } from "./Launch-cAdE2rrZ.mjs";
7
+ import { n as isContextWriterBusy } from "./ContextWriter-oKWFLHuP.mjs";
9
8
  import { Clock, Context, Effect, Layer, Schema } from "effect";
10
9
  //#region src/Agents.ts
11
- var Agents_exports = /* @__PURE__ */ __exportAll({
12
- AgentDefinition: () => AgentDefinition,
13
- AgentListQuery: () => AgentListQuery,
14
- AgentMessageQuery: () => AgentMessageQuery,
15
- AgentMetadata: () => AgentMetadata,
16
- AgentRun: () => AgentRun,
17
- AgentRunListQuery: () => AgentRunListQuery,
18
- AgentRunMessage: () => AgentRunMessage,
19
- AgentRunRequest: () => AgentRunRequest,
20
- AgentRunStatus: () => AgentRunStatus,
21
- AgentRunWaitOptions: () => AgentRunWaitOptions,
22
- AgentUpdate: () => AgentUpdate,
23
- BrowserbaseAgents: () => BrowserbaseAgents,
24
- isTerminalAgentRunStatus: () => isTerminalAgentRunStatus
25
- });
26
10
  const Timestamp = Schema.String.check(Schema.isMaxLength(64));
27
11
  const Cursor = Schema.NonEmptyString.check(Schema.isMaxLength(4096));
28
12
  const JsonObject = Schema.Record(Schema.String, Schema.Json);
@@ -302,6 +286,6 @@ var BrowserbaseAgents = class BrowserbaseAgents extends Context.Service()("effec
302
286
  }));
303
287
  };
304
288
  //#endregion
305
- export { AgentDefinition, AgentListQuery, AgentMessageQuery, AgentMetadata, AgentRun, AgentRunListQuery, AgentRunMessage, AgentRunRequest, AgentRunStatus, AgentRunWaitOptions, AgentUpdate, BrowserbaseAgents, isTerminalAgentRunStatus, Agents_exports as t };
289
+ export { AgentDefinition, AgentListQuery, AgentMessageQuery, AgentMetadata, AgentRun, AgentRunListQuery, AgentRunMessage, AgentRunRequest, AgentRunStatus, AgentRunWaitOptions, AgentUpdate, BrowserbaseAgents, isTerminalAgentRunStatus };
306
290
 
307
291
  //# sourceMappingURL=Agents.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Agents.mjs","names":[],"sources":["../src/Agents.ts"],"sourcesContent":["import { Clock, Context, Effect, Layer, Schema } from \"effect\";\n\nimport { BrowserbaseClient } from \"./Client.ts\";\nimport { PlatformError } from \"./Errors.ts\";\nimport { resource } from \"./internal/http/Resource.ts\";\nimport { proxy } from \"./internal/provider/Launch.ts\";\nimport { isContextWriterBusy } from \"./internal/session/ContextWriter.ts\";\nimport { ProxyRule } from \"./Launch.ts\";\nimport { ContextReference, Identifier } from \"./References.ts\";\n\nconst Timestamp = Schema.String.check(Schema.isMaxLength(64));\nconst Cursor = Schema.NonEmptyString.check(Schema.isMaxLength(4096));\nconst JsonObject = Schema.Record(Schema.String, Schema.Json);\nconst Prompt = Schema.String.check(Schema.isMaxLength(100_000));\n\nexport const AgentRunStatus = Schema.Literals([\n \"PENDING\",\n \"RUNNING\",\n \"COMPLETED\",\n \"FAILED\",\n \"STOPPED\",\n \"TIMED_OUT\",\n]);\n\nexport type AgentRunStatus = typeof AgentRunStatus.Type;\n\nexport const isTerminalAgentRunStatus = (status: AgentRunStatus): boolean =>\n status !== \"PENDING\" && status !== \"RUNNING\";\n\nexport class AgentMetadata extends Schema.Class<AgentMetadata>(\"BrowserbaseAgentMetadata\")({\n agentId: Identifier,\n name: Schema.String.check(Schema.isMaxLength(255)),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n}) {}\n\nexport class AgentRun extends Schema.Class<AgentRun>(\"BrowserbaseAgentRun\")({\n runId: Identifier,\n agentId: Schema.optionalKey(Identifier),\n task: Prompt,\n status: AgentRunStatus,\n sessionId: Schema.optionalKey(Identifier),\n sandboxId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n resultSchema: Schema.optionalKey(JsonObject),\n result: Schema.optionalKey(JsonObject),\n cause: Schema.optionalKey(\n Schema.Struct({\n code: Schema.String.check(Schema.isMaxLength(64)),\n message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(500))),\n }),\n ),\n startedAt: Schema.optionalKey(Timestamp),\n endedAt: Schema.optionalKey(Timestamp),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n}) {}\n\nexport class AgentRunMessage extends Schema.Class<AgentRunMessage>(\"BrowserbaseAgentRunMessage\")({\n id: Schema.String.check(Schema.isMaxLength(256)),\n createdAt: Timestamp,\n role: Schema.Literals([\"assistant\", \"tool\"]),\n content: Schema.Json,\n}) {}\n\nexport const AgentDefinition = Schema.Struct({\n name: Schema.NonEmptyString.check(Schema.isMaxLength(255)),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n});\n\nexport type AgentDefinition = typeof AgentDefinition.Type;\n\nexport const AgentUpdate = Schema.Struct({\n name: Schema.optionalKey(AgentDefinition.fields.name),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n});\n\nexport type AgentUpdate = typeof AgentUpdate.Type;\n\nexport const AgentRunRequest = Schema.Struct({\n task: Schema.NonEmptyString.check(Schema.isMaxLength(100_000)),\n agentId: Schema.optionalKey(Identifier),\n resultSchema: Schema.optionalKey(JsonObject),\n variables: Schema.optionalKey(\n Schema.Record(\n Schema.String.check(Schema.isMaxLength(128)),\n Schema.Struct({\n value: Schema.String.check(Schema.isMaxLength(100_000)),\n description: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(1024))),\n }),\n ),\n ),\n browserSettings: Schema.optionalKey(\n Schema.Struct({\n /**\n * A persisting run writes the Context from Browserbase's side, outside\n * `ContextCoordination.withWriter`. It is refused while a local writer holds the\n * Context, but nothing stops a later local writer from racing the hosted run.\n */\n context: Schema.optionalKey(\n Schema.Struct({ reference: ContextReference, persist: Schema.Boolean }),\n ),\n proxies: Schema.optionalKey(\n Schema.Union([Schema.Boolean, Schema.Array(ProxyRule).check(Schema.isMaxLength(64))]),\n ),\n verified: Schema.optionalKey(Schema.Boolean),\n }),\n ),\n});\n\nexport type AgentRunRequest = typeof AgentRunRequest.Type;\n\nconst Window = {\n startAt: Schema.optionalKey(Timestamp),\n endAt: Schema.optionalKey(Timestamp),\n cursor: Schema.optionalKey(Cursor),\n};\n\nexport const AgentListQuery = Schema.Struct({\n ...Window,\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 }))),\n});\n\nexport type AgentListQuery = typeof AgentListQuery.Type;\n\nexport const AgentRunListQuery = Schema.Struct({\n ...Window,\n status: Schema.optionalKey(AgentRunStatus),\n agentId: Schema.optionalKey(Identifier),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 }))),\n});\n\nexport type AgentRunListQuery = typeof AgentRunListQuery.Type;\n\nexport const AgentMessageQuery = Schema.Struct({\n since: Schema.optionalKey(Cursor),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),\n all: Schema.optionalKey(Schema.Boolean),\n});\n\nexport type AgentMessageQuery = typeof AgentMessageQuery.Type;\n\nexport const AgentRunWaitOptions = Schema.Struct({\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 21_600_000 })),\n pollIntervalMillis: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 250, maximum: 60_000 })),\n ),\n});\n\nexport type AgentRunWaitOptions = typeof AgentRunWaitOptions.Type;\n\nexport interface Page<A> {\n readonly items: ReadonlyArray<A>;\n readonly nextCursor: string | undefined;\n}\n\nexport interface AgentMessages {\n readonly messages: ReadonlyArray<AgentRunMessage>;\n readonly nextSince: string | undefined;\n}\n\nconst ProviderAgent = Schema.Struct({\n agentId: Identifier,\n name: AgentMetadata.fields.name,\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n});\n\nconst ProviderPage = <S extends Schema.Top>(item: S) =>\n Schema.Struct({\n data: Schema.Array(item).check(Schema.isMaxLength(1000)),\n nextCursor: Schema.optionalKey(Schema.NullOr(Schema.String.check(Schema.isMaxLength(4096)))),\n });\n\nconst ProviderMessages = Schema.Struct({\n data: Schema.Array(\n Schema.Struct({\n id: AgentRunMessage.fields.id,\n createdAt: Timestamp,\n message: Schema.Struct({ role: AgentRunMessage.fields.role, content: Schema.Json }),\n }),\n ).check(Schema.isMaxLength(100)),\n nextSince: Schema.optionalKey(Schema.NullOr(Schema.String.check(Schema.isMaxLength(4096)))),\n});\n\nconst now = Clock.monotonicTimeNanos.pipe(Effect.map((value) => Number(value) / 1_000_000));\n\n/**\n * Browserbase Agents: hosted autonomous runs that allocate their own browser sessions and\n * bill inference. Creating or stopping a run is never retried; a lost reply is `unknown`.\n */\nexport class BrowserbaseAgents extends Context.Service<\n BrowserbaseAgents,\n {\n readonly create: (definition: AgentDefinition) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly list: (query?: AgentListQuery) => Effect.Effect<Page<AgentMetadata>, PlatformError>;\n readonly retrieve: (agentId: string) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly update: (\n agentId: string,\n update: AgentUpdate,\n ) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly delete: (agentId: string) => Effect.Effect<void, PlatformError>;\n readonly run: (request: AgentRunRequest) => Effect.Effect<AgentRun, PlatformError>;\n readonly retrieveRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;\n readonly listRuns: (query?: AgentRunListQuery) => Effect.Effect<Page<AgentRun>, PlatformError>;\n readonly stopRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;\n readonly messages: (\n runId: string,\n query?: AgentMessageQuery,\n ) => Effect.Effect<AgentMessages, PlatformError>;\n /** Polls until the run is terminal. Interrupting the wait does not stop the run. */\n readonly waitForRun: (\n runId: string,\n options: AgentRunWaitOptions,\n ) => Effect.Effect<AgentRun, PlatformError>;\n }\n>()(\"effect-browserbase/Agents\") {\n static readonly layer: Layer.Layer<BrowserbaseAgents, never, BrowserbaseClient> = Layer.effect(\n BrowserbaseAgents,\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n\n const api = resource<PlatformError>(client, (failure) =>\n PlatformError.make({ ...failure, service: \"agents\" }),\n );\n\n const agentPath = (id: string) => `/v1/agents/${api.segment(id)}`;\n const runPath = (id: string) => `/v1/agents/runs/${api.segment(id)}`;\n\n const agent = (operation: PlatformError[\"operation\"], mutation: boolean, expected?: string) =>\n Effect.fnUntraced(function* (value: typeof ProviderAgent.Type) {\n if (expected !== undefined && value.agentId !== expected)\n return yield* api.malformed(operation, mutation);\n\n return AgentMetadata.make(value);\n });\n\n const run = (operation: PlatformError[\"operation\"], mutation: boolean, expected?: string) =>\n Effect.fnUntraced(function* (value: AgentRun) {\n if (expected !== undefined && value.runId !== expected)\n return yield* api.malformed(operation, mutation);\n\n return value;\n });\n\n const create = Effect.fn(\"BrowserbaseAgents.create\")(function* (definition: AgentDefinition) {\n const value = yield* api.input(AgentDefinition, definition, \"agent-create\");\n\n return yield* api\n .request(\"POST\", \"/v1/agents\", ProviderAgent, \"agent-create\", value)\n .pipe(Effect.flatMap(agent(\"agent-create\", true)));\n });\n\n const list = Effect.fn(\"BrowserbaseAgents.list\")(function* (query: AgentListQuery = {}) {\n const value = yield* api.input(AgentListQuery, query, \"agent-list\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/agents${api.query(value)}`,\n ProviderPage(ProviderAgent),\n \"agent-list\",\n );\n\n return {\n items: page.data.map((row) => AgentMetadata.make(row)),\n nextCursor: page.nextCursor ?? undefined,\n };\n });\n\n const retrieve = Effect.fn(\"BrowserbaseAgents.retrieve\")(function* (agentId: string) {\n const id = yield* api.input(Identifier, agentId, \"agent-retrieve\");\n\n return yield* api\n .request(\"GET\", agentPath(id), ProviderAgent, \"agent-retrieve\")\n .pipe(Effect.flatMap(agent(\"agent-retrieve\", false, id)));\n });\n\n const update = Effect.fn(\"BrowserbaseAgents.update\")(function* (\n agentId: string,\n changes: AgentUpdate,\n ) {\n const id = yield* api.input(Identifier, agentId, \"agent-update\");\n const value = yield* api.input(AgentUpdate, changes, \"agent-update\");\n\n if (Object.keys(value).length === 0) return yield* api.configuration(\"agent-update\");\n\n return yield* api\n .request(\"PATCH\", agentPath(id), ProviderAgent, \"agent-update\", value)\n .pipe(Effect.flatMap(agent(\"agent-update\", true, id)));\n });\n\n const remove = Effect.fn(\"BrowserbaseAgents.delete\")(function* (agentId: string) {\n const id = yield* api.input(Identifier, agentId, \"agent-delete\");\n\n yield* api.remove(agentPath(id), \"agent-delete\");\n });\n\n const start = Effect.fn(\"BrowserbaseAgents.run\")(function* (request: AgentRunRequest) {\n const value = yield* api.input(AgentRunRequest, request, \"agent-run\");\n const settings = value.browserSettings;\n const context = settings?.context;\n\n if (context !== undefined) {\n if (context.reference.projectId !== client.projectId)\n return yield* api.make({\n operation: \"agent-run\",\n reason: \"authorization\",\n outcome: \"undispatched\",\n });\n if (context.persist && isContextWriterBusy(context.reference))\n return yield* api.make({\n operation: \"agent-run\",\n reason: \"active\",\n outcome: \"undispatched\",\n });\n }\n\n const body: Schema.Json = {\n task: value.task,\n ...(value.agentId === undefined ? {} : { agentId: value.agentId }),\n ...(value.resultSchema === undefined ? {} : { resultSchema: value.resultSchema }),\n ...(value.variables === undefined ? {} : { variables: value.variables }),\n ...(settings === undefined\n ? {}\n : {\n browserSettings: {\n ...(context === undefined\n ? {}\n : {\n context: { id: context.reference.contextId, persist: context.persist },\n }),\n ...(settings.proxies === undefined\n ? {}\n : {\n proxies:\n typeof settings.proxies === \"boolean\"\n ? settings.proxies\n : settings.proxies.map(proxy),\n }),\n ...(settings.verified === undefined ? {} : { verified: settings.verified }),\n },\n }),\n };\n\n return yield* api.request(\"POST\", \"/v1/agents/runs\", AgentRun, \"agent-run\", body);\n });\n\n const retrieveRun = Effect.fn(\"BrowserbaseAgents.retrieveRun\")(function* (runId: string) {\n const id = yield* api.input(Identifier, runId, \"agent-run-retrieve\");\n\n return yield* api\n .request(\"GET\", runPath(id), AgentRun, \"agent-run-retrieve\")\n .pipe(Effect.flatMap(run(\"agent-run-retrieve\", false, id)));\n });\n\n const listRuns = Effect.fn(\"BrowserbaseAgents.listRuns\")(function* (\n query: AgentRunListQuery = {},\n ) {\n const value = yield* api.input(AgentRunListQuery, query, \"agent-run-list\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/agents/runs${api.query(value)}`,\n ProviderPage(AgentRun),\n \"agent-run-list\",\n );\n\n return { items: page.data, nextCursor: page.nextCursor ?? undefined };\n });\n\n const stopRun = Effect.fn(\"BrowserbaseAgents.stopRun\")(function* (runId: string) {\n const id = yield* api.input(Identifier, runId, \"agent-run-stop\");\n\n return yield* api\n .request(\"POST\", `${runPath(id)}/stop`, AgentRun, \"agent-run-stop\")\n .pipe(Effect.flatMap(run(\"agent-run-stop\", true, id)));\n });\n\n const messages = Effect.fn(\"BrowserbaseAgents.messages\")(function* (\n runId: string,\n query: AgentMessageQuery = {},\n ) {\n const id = yield* api.input(Identifier, runId, \"agent-run-messages\");\n const value = yield* api.input(AgentMessageQuery, query, \"agent-run-messages\");\n\n const page = yield* api.request(\n \"GET\",\n `${runPath(id)}/messages${api.query(value)}`,\n ProviderMessages,\n \"agent-run-messages\",\n );\n\n return {\n messages: page.data.map((row) =>\n AgentRunMessage.make({\n id: row.id,\n createdAt: row.createdAt,\n role: row.message.role,\n content: row.message.content,\n }),\n ),\n nextSince: page.nextSince ?? undefined,\n };\n });\n\n const waitForRun = Effect.fn(\"BrowserbaseAgents.waitForRun\")(function* (\n runId: string,\n options: AgentRunWaitOptions,\n ) {\n const bounds = yield* api.input(AgentRunWaitOptions, options, \"agent-run-wait\");\n const deadline = (yield* now) + bounds.timeoutMillis;\n\n for (;;) {\n const current = yield* retrieveRun(runId);\n\n if (isTerminalAgentRunStatus(current.status)) return current;\n const remaining = deadline - (yield* now);\n\n if (remaining <= 0)\n return yield* api.make({ operation: \"agent-run-wait\", reason: \"timeout\" });\n yield* Effect.sleep(Math.min(bounds.pollIntervalMillis ?? 2_000, remaining));\n }\n });\n\n return BrowserbaseAgents.of({\n create,\n list,\n retrieve,\n update,\n delete: remove,\n run: start,\n retrieveRun,\n listRuns,\n stopRun,\n messages,\n waitForRun,\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,EAAE,CAAC;AAC5D,MAAM,SAAS,OAAO,eAAe,MAAM,OAAO,YAAY,IAAI,CAAC;AACnE,MAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI;AAC3D,MAAM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R,WAAW,IAAI;KACf,MAAM,IAAI,QAAQ;KAClB,SAAS,IAAI,QAAQ;IACvB,CAAC,CACH;IACA,WAAW,KAAK,aAAa,KAAA;GAC/B;EACF,CAAC;EAED,MAAM,aAAa,OAAO,GAAG,8BAA8B,CAAC,CAAC,WAC3D,OACA,SACA;GACA,MAAM,SAAS,OAAO,IAAI,MAAM,qBAAqB,SAAS,gBAAgB;GAC9E,MAAM,YAAY,OAAO,OAAO,OAAO;GAEvC,SAAS;IACP,MAAM,UAAU,OAAO,YAAY,KAAK;IAExC,IAAI,yBAAyB,QAAQ,MAAM,GAAG,OAAO;IACrD,MAAM,YAAY,YAAY,OAAO;IAErC,IAAI,aAAa,GACf,OAAO,OAAO,IAAI,KAAK;KAAE,WAAW;KAAkB,QAAQ;IAAU,CAAC;IAC3E,OAAO,OAAO,MAAM,KAAK,IAAI,OAAO,sBAAsB,KAAO,SAAS,CAAC;GAC7E;EACF,CAAC;EAED,OAAO,kBAAkB,GAAG;GAC1B;GACA;GACA;GACA;GACA,QAAQ;GACR,KAAK;GACL;GACA;GACA;GACA;GACA;EACF,CAAC;CACH,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"Agents.mjs","names":[],"sources":["../src/Agents.ts"],"sourcesContent":["import { Clock, Context, Effect, Layer, Schema } from \"effect\";\n\nimport { BrowserbaseClient } from \"./Client.ts\";\nimport { PlatformError } from \"./Errors.ts\";\nimport { resource } from \"./internal/http/Resource.ts\";\nimport { proxy } from \"./internal/provider/Launch.ts\";\nimport { isContextWriterBusy } from \"./internal/session/ContextWriter.ts\";\nimport { ProxyRule } from \"./Launch.ts\";\nimport { ContextReference, Identifier } from \"./References.ts\";\n\nconst Timestamp = Schema.String.check(Schema.isMaxLength(64));\nconst Cursor = Schema.NonEmptyString.check(Schema.isMaxLength(4096));\nconst JsonObject = Schema.Record(Schema.String, Schema.Json);\nconst Prompt = Schema.String.check(Schema.isMaxLength(100_000));\n\nexport const AgentRunStatus = Schema.Literals([\n \"PENDING\",\n \"RUNNING\",\n \"COMPLETED\",\n \"FAILED\",\n \"STOPPED\",\n \"TIMED_OUT\",\n]);\n\nexport type AgentRunStatus = typeof AgentRunStatus.Type;\n\nexport const isTerminalAgentRunStatus = (status: AgentRunStatus): boolean =>\n status !== \"PENDING\" && status !== \"RUNNING\";\n\nexport class AgentMetadata extends Schema.Class<AgentMetadata>(\"BrowserbaseAgentMetadata\")({\n agentId: Identifier,\n name: Schema.String.check(Schema.isMaxLength(255)),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n}) {}\n\nexport class AgentRun extends Schema.Class<AgentRun>(\"BrowserbaseAgentRun\")({\n runId: Identifier,\n agentId: Schema.optionalKey(Identifier),\n task: Prompt,\n status: AgentRunStatus,\n sessionId: Schema.optionalKey(Identifier),\n sandboxId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n resultSchema: Schema.optionalKey(JsonObject),\n result: Schema.optionalKey(JsonObject),\n cause: Schema.optionalKey(\n Schema.Struct({\n code: Schema.String.check(Schema.isMaxLength(64)),\n message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(500))),\n }),\n ),\n startedAt: Schema.optionalKey(Timestamp),\n endedAt: Schema.optionalKey(Timestamp),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n}) {}\n\nexport class AgentRunMessage extends Schema.Class<AgentRunMessage>(\"BrowserbaseAgentRunMessage\")({\n id: Schema.String.check(Schema.isMaxLength(256)),\n createdAt: Timestamp,\n role: Schema.Literals([\"assistant\", \"tool\"]),\n content: Schema.Json,\n}) {}\n\nexport const AgentDefinition = Schema.Struct({\n name: Schema.NonEmptyString.check(Schema.isMaxLength(255)),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n});\n\nexport type AgentDefinition = typeof AgentDefinition.Type;\n\nexport const AgentUpdate = Schema.Struct({\n name: Schema.optionalKey(AgentDefinition.fields.name),\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n});\n\nexport type AgentUpdate = typeof AgentUpdate.Type;\n\nexport const AgentRunRequest = Schema.Struct({\n task: Schema.NonEmptyString.check(Schema.isMaxLength(100_000)),\n agentId: Schema.optionalKey(Identifier),\n resultSchema: Schema.optionalKey(JsonObject),\n variables: Schema.optionalKey(\n Schema.Record(\n Schema.String.check(Schema.isMaxLength(128)),\n Schema.Struct({\n value: Schema.String.check(Schema.isMaxLength(100_000)),\n description: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(1024))),\n }),\n ),\n ),\n browserSettings: Schema.optionalKey(\n Schema.Struct({\n /**\n * A persisting run writes the Context from Browserbase's side, outside\n * `ContextCoordination.withWriter`. It is refused while a local writer holds the\n * Context, but nothing stops a later local writer from racing the hosted run.\n */\n context: Schema.optionalKey(\n Schema.Struct({ reference: ContextReference, persist: Schema.Boolean }),\n ),\n proxies: Schema.optionalKey(\n Schema.Union([Schema.Boolean, Schema.Array(ProxyRule).check(Schema.isMaxLength(64))]),\n ),\n verified: Schema.optionalKey(Schema.Boolean),\n }),\n ),\n});\n\nexport type AgentRunRequest = typeof AgentRunRequest.Type;\n\nconst Window = {\n startAt: Schema.optionalKey(Timestamp),\n endAt: Schema.optionalKey(Timestamp),\n cursor: Schema.optionalKey(Cursor),\n};\n\nexport const AgentListQuery = Schema.Struct({\n ...Window,\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 }))),\n});\n\nexport type AgentListQuery = typeof AgentListQuery.Type;\n\nexport const AgentRunListQuery = Schema.Struct({\n ...Window,\n status: Schema.optionalKey(AgentRunStatus),\n agentId: Schema.optionalKey(Identifier),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 }))),\n});\n\nexport type AgentRunListQuery = typeof AgentRunListQuery.Type;\n\nexport const AgentMessageQuery = Schema.Struct({\n since: Schema.optionalKey(Cursor),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),\n all: Schema.optionalKey(Schema.Boolean),\n});\n\nexport type AgentMessageQuery = typeof AgentMessageQuery.Type;\n\nexport const AgentRunWaitOptions = Schema.Struct({\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 21_600_000 })),\n pollIntervalMillis: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 250, maximum: 60_000 })),\n ),\n});\n\nexport type AgentRunWaitOptions = typeof AgentRunWaitOptions.Type;\n\nexport interface Page<A> {\n readonly items: ReadonlyArray<A>;\n readonly nextCursor: string | undefined;\n}\n\nexport interface AgentMessages {\n readonly messages: ReadonlyArray<AgentRunMessage>;\n readonly nextSince: string | undefined;\n}\n\nconst ProviderAgent = Schema.Struct({\n agentId: Identifier,\n name: AgentMetadata.fields.name,\n systemPrompt: Schema.optionalKey(Prompt),\n resultSchema: Schema.optionalKey(JsonObject),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n});\n\nconst ProviderPage = <S extends Schema.Top>(item: S) =>\n Schema.Struct({\n data: Schema.Array(item).check(Schema.isMaxLength(1000)),\n nextCursor: Schema.optionalKey(Schema.NullOr(Schema.String.check(Schema.isMaxLength(4096)))),\n });\n\nconst ProviderMessages = Schema.Struct({\n data: Schema.Array(\n Schema.Struct({\n id: AgentRunMessage.fields.id,\n createdAt: Timestamp,\n message: Schema.Struct({ role: AgentRunMessage.fields.role, content: Schema.Json }),\n }),\n ).check(Schema.isMaxLength(100)),\n nextSince: Schema.optionalKey(Schema.NullOr(Schema.String.check(Schema.isMaxLength(4096)))),\n});\n\nconst now = Clock.monotonicTimeNanos.pipe(Effect.map((value) => Number(value) / 1_000_000));\n\n/**\n * Browserbase Agents: hosted autonomous runs that allocate their own browser sessions and\n * bill inference. Creating or stopping a run is never retried; a lost reply is `unknown`.\n */\nexport class BrowserbaseAgents extends Context.Service<\n BrowserbaseAgents,\n {\n readonly create: (definition: AgentDefinition) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly list: (query?: AgentListQuery) => Effect.Effect<Page<AgentMetadata>, PlatformError>;\n readonly retrieve: (agentId: string) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly update: (\n agentId: string,\n update: AgentUpdate,\n ) => Effect.Effect<AgentMetadata, PlatformError>;\n readonly delete: (agentId: string) => Effect.Effect<void, PlatformError>;\n readonly run: (request: AgentRunRequest) => Effect.Effect<AgentRun, PlatformError>;\n readonly retrieveRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;\n readonly listRuns: (query?: AgentRunListQuery) => Effect.Effect<Page<AgentRun>, PlatformError>;\n readonly stopRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;\n readonly messages: (\n runId: string,\n query?: AgentMessageQuery,\n ) => Effect.Effect<AgentMessages, PlatformError>;\n /** Polls until the run is terminal. Interrupting the wait does not stop the run. */\n readonly waitForRun: (\n runId: string,\n options: AgentRunWaitOptions,\n ) => Effect.Effect<AgentRun, PlatformError>;\n }\n>()(\"effect-browserbase/Agents\") {\n static readonly layer: Layer.Layer<BrowserbaseAgents, never, BrowserbaseClient> = Layer.effect(\n BrowserbaseAgents,\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n\n const api = resource<PlatformError>(client, (failure) =>\n PlatformError.make({ ...failure, service: \"agents\" }),\n );\n\n const agentPath = (id: string) => `/v1/agents/${api.segment(id)}`;\n const runPath = (id: string) => `/v1/agents/runs/${api.segment(id)}`;\n\n const agent = (operation: PlatformError[\"operation\"], mutation: boolean, expected?: string) =>\n Effect.fnUntraced(function* (value: typeof ProviderAgent.Type) {\n if (expected !== undefined && value.agentId !== expected)\n return yield* api.malformed(operation, mutation);\n\n return AgentMetadata.make(value);\n });\n\n const run = (operation: PlatformError[\"operation\"], mutation: boolean, expected?: string) =>\n Effect.fnUntraced(function* (value: AgentRun) {\n if (expected !== undefined && value.runId !== expected)\n return yield* api.malformed(operation, mutation);\n\n return value;\n });\n\n const create = Effect.fn(\"BrowserbaseAgents.create\")(function* (definition: AgentDefinition) {\n const value = yield* api.input(AgentDefinition, definition, \"agent-create\");\n\n return yield* api\n .request(\"POST\", \"/v1/agents\", ProviderAgent, \"agent-create\", value)\n .pipe(Effect.flatMap(agent(\"agent-create\", true)));\n });\n\n const list = Effect.fn(\"BrowserbaseAgents.list\")(function* (query: AgentListQuery = {}) {\n const value = yield* api.input(AgentListQuery, query, \"agent-list\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/agents${api.query(value)}`,\n ProviderPage(ProviderAgent),\n \"agent-list\",\n );\n\n return {\n items: page.data.map((row) => AgentMetadata.make(row)),\n nextCursor: page.nextCursor ?? undefined,\n };\n });\n\n const retrieve = Effect.fn(\"BrowserbaseAgents.retrieve\")(function* (agentId: string) {\n const id = yield* api.input(Identifier, agentId, \"agent-retrieve\");\n\n return yield* api\n .request(\"GET\", agentPath(id), ProviderAgent, \"agent-retrieve\")\n .pipe(Effect.flatMap(agent(\"agent-retrieve\", false, id)));\n });\n\n const update = Effect.fn(\"BrowserbaseAgents.update\")(function* (\n agentId: string,\n changes: AgentUpdate,\n ) {\n const id = yield* api.input(Identifier, agentId, \"agent-update\");\n const value = yield* api.input(AgentUpdate, changes, \"agent-update\");\n\n if (Object.keys(value).length === 0) return yield* api.configuration(\"agent-update\");\n\n return yield* api\n .request(\"PATCH\", agentPath(id), ProviderAgent, \"agent-update\", value)\n .pipe(Effect.flatMap(agent(\"agent-update\", true, id)));\n });\n\n const remove = Effect.fn(\"BrowserbaseAgents.delete\")(function* (agentId: string) {\n const id = yield* api.input(Identifier, agentId, \"agent-delete\");\n\n yield* api.remove(agentPath(id), \"agent-delete\");\n });\n\n const start = Effect.fn(\"BrowserbaseAgents.run\")(function* (request: AgentRunRequest) {\n const value = yield* api.input(AgentRunRequest, request, \"agent-run\");\n const settings = value.browserSettings;\n const context = settings?.context;\n\n if (context !== undefined) {\n if (context.reference.projectId !== client.projectId)\n return yield* api.make({\n operation: \"agent-run\",\n reason: \"authorization\",\n outcome: \"undispatched\",\n });\n if (context.persist && isContextWriterBusy(context.reference))\n return yield* api.make({\n operation: \"agent-run\",\n reason: \"active\",\n outcome: \"undispatched\",\n });\n }\n\n const body: Schema.Json = {\n task: value.task,\n ...(value.agentId === undefined ? {} : { agentId: value.agentId }),\n ...(value.resultSchema === undefined ? {} : { resultSchema: value.resultSchema }),\n ...(value.variables === undefined ? {} : { variables: value.variables }),\n ...(settings === undefined\n ? {}\n : {\n browserSettings: {\n ...(context === undefined\n ? {}\n : {\n context: { id: context.reference.contextId, persist: context.persist },\n }),\n ...(settings.proxies === undefined\n ? {}\n : {\n proxies:\n typeof settings.proxies === \"boolean\"\n ? settings.proxies\n : settings.proxies.map(proxy),\n }),\n ...(settings.verified === undefined ? {} : { verified: settings.verified }),\n },\n }),\n };\n\n return yield* api.request(\"POST\", \"/v1/agents/runs\", AgentRun, \"agent-run\", body);\n });\n\n const retrieveRun = Effect.fn(\"BrowserbaseAgents.retrieveRun\")(function* (runId: string) {\n const id = yield* api.input(Identifier, runId, \"agent-run-retrieve\");\n\n return yield* api\n .request(\"GET\", runPath(id), AgentRun, \"agent-run-retrieve\")\n .pipe(Effect.flatMap(run(\"agent-run-retrieve\", false, id)));\n });\n\n const listRuns = Effect.fn(\"BrowserbaseAgents.listRuns\")(function* (\n query: AgentRunListQuery = {},\n ) {\n const value = yield* api.input(AgentRunListQuery, query, \"agent-run-list\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/agents/runs${api.query(value)}`,\n ProviderPage(AgentRun),\n \"agent-run-list\",\n );\n\n return { items: page.data, nextCursor: page.nextCursor ?? undefined };\n });\n\n const stopRun = Effect.fn(\"BrowserbaseAgents.stopRun\")(function* (runId: string) {\n const id = yield* api.input(Identifier, runId, \"agent-run-stop\");\n\n return yield* api\n .request(\"POST\", `${runPath(id)}/stop`, AgentRun, \"agent-run-stop\")\n .pipe(Effect.flatMap(run(\"agent-run-stop\", true, id)));\n });\n\n const messages = Effect.fn(\"BrowserbaseAgents.messages\")(function* (\n runId: string,\n query: AgentMessageQuery = {},\n ) {\n const id = yield* api.input(Identifier, runId, \"agent-run-messages\");\n const value = yield* api.input(AgentMessageQuery, query, \"agent-run-messages\");\n\n const page = yield* api.request(\n \"GET\",\n `${runPath(id)}/messages${api.query(value)}`,\n ProviderMessages,\n \"agent-run-messages\",\n );\n\n return {\n messages: page.data.map((row) =>\n AgentRunMessage.make({\n id: row.id,\n createdAt: row.createdAt,\n role: row.message.role,\n content: row.message.content,\n }),\n ),\n nextSince: page.nextSince ?? undefined,\n };\n });\n\n const waitForRun = Effect.fn(\"BrowserbaseAgents.waitForRun\")(function* (\n runId: string,\n options: AgentRunWaitOptions,\n ) {\n const bounds = yield* api.input(AgentRunWaitOptions, options, \"agent-run-wait\");\n const deadline = (yield* now) + bounds.timeoutMillis;\n\n for (;;) {\n const current = yield* retrieveRun(runId);\n\n if (isTerminalAgentRunStatus(current.status)) return current;\n const remaining = deadline - (yield* now);\n\n if (remaining <= 0)\n return yield* api.make({ operation: \"agent-run-wait\", reason: \"timeout\" });\n yield* Effect.sleep(Math.min(bounds.pollIntervalMillis ?? 2_000, remaining));\n }\n });\n\n return BrowserbaseAgents.of({\n create,\n list,\n retrieve,\n update,\n delete: remove,\n run: start,\n retrieveRun,\n listRuns,\n stopRun,\n messages,\n waitForRun,\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,EAAE,CAAC;AAC5D,MAAM,SAAS,OAAO,eAAe,MAAM,OAAO,YAAY,IAAI,CAAC;AACnE,MAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI;AAC3D,MAAM,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY,GAAO,CAAC;AAE9D,MAAa,iBAAiB,OAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAa,4BAA4B,WACvC,WAAW,aAAa,WAAW;AAErC,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C,WAC3D,OACA,SACA;GACA,MAAM,SAAS,OAAO,IAAI,MAAM,qBAAqB,SAAS,gBAAgB;GAC9E,MAAM,YAAY,OAAO,OAAO,OAAO;GAEvC,SAAS;IACP,MAAM,UAAU,OAAO,YAAY,KAAK;IAExC,IAAI,yBAAyB,QAAQ,MAAM,GAAG,OAAO;IACrD,MAAM,YAAY,YAAY,OAAO;IAErC,IAAI,aAAa,GACf,OAAO,OAAO,IAAI,KAAK;KAAE,WAAW;KAAkB,QAAQ;IAAU,CAAC;IAC3E,OAAO,OAAO,MAAM,KAAK,IAAI,OAAO,sBAAsB,KAAO,SAAS,CAAC;GAC7E;EACF,CAAC;EAED,OAAO,kBAAkB,GAAG;GAC1B;GACA;GACA;GACA;GACA,QAAQ;GACR,KAAK;GACL;GACA;GACA;GACA;GACA;EACF,CAAC;CACH,CAAC,CACH;AACF"}
@@ -1,14 +1,12 @@
1
- import { n as ContextReference, o as SessionReference, r as ExtensionReference, t as AllocationAttempt } from "./References-URDAtapt.mjs";
2
- import { AllocationError, BrowserError, ContextError } from "./Errors.mjs";
3
- import { t as BrowserbaseClient } from "./Client-Ca0zSg1n.mjs";
4
- import { t as BrowserbaseSessions } from "./Sessions-B8E4kMxo.mjs";
5
- import { n as CleanupResult } from "./Cleanup-G2YpTCuU.mjs";
6
- import { n as ContextWriterPermit } from "./WriterFacts-osvYAsIx.mjs";
1
+ import { a as SessionReference, n as ContextReference, r as ExtensionReference, t as AllocationAttempt } from "./References-DOH3Wu44.mjs";
2
+ import { AllocationError, ContextError } from "./Errors.mjs";
3
+ import { t as BrowserbaseClient } from "./Client-B_f6bBLT.mjs";
4
+ import { t as BrowserbaseSessions } from "./Sessions-BpZgjteE.mjs";
5
+ import { n as CleanupResult } from "./Cleanup-DMTDBir8.mjs";
6
+ import { n as ContextWriterPermit } from "./WriterFacts-BBJRDZYY.mjs";
7
7
  import "./ContextCoordination.mjs";
8
8
  import { Effect, Option } from "effect";
9
- declare namespace Allocation_d_exports {
10
- export { AllocatedSession, AllocationOptions, scoped };
11
- }
9
+ //#region src/Allocation.d.ts
12
10
  /** A session this process allocated and owns, with no browser connected to it. */
13
11
  export interface AllocatedSession {
14
12
  readonly reference: SessionReference;
@@ -93,7 +91,7 @@ export declare const scoped: (launch: {
93
91
  readonly [x: string]: import("effect/Schema").Json;
94
92
  } | undefined;
95
93
  };
96
- }, options?: AllocationOptions | undefined) => Effect.Effect<AllocatedSession, AllocationError | BrowserError | ContextError, BrowserbaseClient | BrowserbaseSessions | import("effect/Scope").Scope>;
94
+ }, options?: AllocationOptions | undefined) => Effect.Effect<AllocatedSession, AllocationError | import("effect-browser/errors").BrowserError | ContextError, BrowserbaseClient | BrowserbaseSessions | import("effect/Crypto").Crypto | import("effect/Scope").Scope>;
97
95
  //#endregion
98
- export { Allocation_d_exports as t };
96
+ export {};
99
97
  //# sourceMappingURL=Allocation.d.mts.map
@@ -1,8 +1,6 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { t as acquireRemote } from "./Acquisition-WBafHwXH.mjs";
1
+ import { t as acquireRemote } from "./Acquisition-CAsTTXp4.mjs";
3
2
  import { Effect } from "effect";
4
3
  //#region src/Allocation.ts
5
- var Allocation_exports = /* @__PURE__ */ __exportAll({ scoped: () => scoped });
6
4
  /**
7
5
  * Allocate a session without connecting a browser, for a caller that drives the remote
8
6
  * session with its own automation client. This is the allocation path the browser owner
@@ -24,6 +22,6 @@ const scoped = Effect.fnUntraced(function* (launch, options = {}) {
24
22
  };
25
23
  });
26
24
  //#endregion
27
- export { scoped, Allocation_exports as t };
25
+ export { scoped };
28
26
 
29
27
  //# sourceMappingURL=Allocation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Allocation.mjs","names":[],"sources":["../src/Allocation.ts"],"sourcesContent":["import { Effect, type Option } from \"effect\";\n\nimport type { CleanupResult } from \"./Cleanup.ts\";\nimport type { ContextWriterPermit } from \"./ContextCoordination.ts\";\nimport { acquireRemote } from \"./internal/session/Acquisition.ts\";\nimport type { LaunchRecipe } from \"./Launch.ts\";\nimport type { AllocationAttempt, SessionReference } from \"./References.ts\";\n\n/** A session this process allocated and owns, with no browser connected to it. */\nexport interface AllocatedSession {\n readonly reference: SessionReference;\n /** The creation attempt, retained so an unknown provider outcome stays attributable. */\n readonly attempt: AllocationAttempt;\n /**\n * Release now and read the cleanup evidence. The scope finalizer performs the same\n * release, so an uncalled `release` is a scope that has not closed yet, not a leak.\n */\n readonly release: Effect.Effect<CleanupResult>;\n /** The cleanup evidence once it exists, and `None` while the session is still held. */\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n}\n\nexport interface AllocationOptions {\n /** Required exactly when the recipe persists a Context, and refused when it does not. */\n readonly contextWriter?: ContextWriterPermit;\n readonly allocationDeadline?: number;\n /** Bounded host notification of the canonical facts. Reporting never changes them. */\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n /** Exactly one notification when a creation attempt's effect on the provider is unknown. */\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\n/**\n * Allocate a session without connecting a browser, for a caller that drives the remote\n * session with its own automation client. This is the allocation path the browser owner\n * uses, so release, unknown-outcome reporting and Context writer authority keep a single\n * owner: the creation request is never retried, a foreign project is refused before it is\n * sent, and no native peer is loaded. The scope owns the release; closing it releases the\n * session whether or not the caller ever connected to it.\n */\nexport const scoped = Effect.fnUntraced(function* (\n launch: LaunchRecipe,\n options: AllocationOptions = {},\n) {\n const acquisition = yield* acquireRemote({ launch, ...options });\n\n const allocated: AllocatedSession = {\n reference: acquisition.reference,\n attempt: acquisition.attempt,\n release: acquisition.release,\n cleanupResult: acquisition.cleanupResult,\n };\n\n return allocated;\n});\n"],"mappings":";;;;;;;;;;;;;AAwCA,MAAa,SAAS,OAAO,WAAW,WACtC,QACA,UAA6B,CAAC,GAC9B;CACA,MAAM,cAAc,OAAO,cAAc;EAAE;EAAQ,GAAG;CAAQ,CAAC;CAS/D,OAAO;EANL,WAAW,YAAY;EACvB,SAAS,YAAY;EACrB,SAAS,YAAY;EACrB,eAAe,YAAY;CAGd;AACjB,CAAC"}
1
+ {"version":3,"file":"Allocation.mjs","names":[],"sources":["../src/Allocation.ts"],"sourcesContent":["import { Effect, type Option } from \"effect\";\n\nimport type { CleanupResult } from \"./Cleanup.ts\";\nimport type { ContextWriterPermit } from \"./ContextCoordination.ts\";\nimport { acquireRemote } from \"./internal/session/Acquisition.ts\";\nimport type { LaunchRecipe } from \"./Launch.ts\";\nimport type { AllocationAttempt, SessionReference } from \"./References.ts\";\n\n/** A session this process allocated and owns, with no browser connected to it. */\nexport interface AllocatedSession {\n readonly reference: SessionReference;\n /** The creation attempt, retained so an unknown provider outcome stays attributable. */\n readonly attempt: AllocationAttempt;\n /**\n * Release now and read the cleanup evidence. The scope finalizer performs the same\n * release, so an uncalled `release` is a scope that has not closed yet, not a leak.\n */\n readonly release: Effect.Effect<CleanupResult>;\n /** The cleanup evidence once it exists, and `None` while the session is still held. */\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n}\n\nexport interface AllocationOptions {\n /** Required exactly when the recipe persists a Context, and refused when it does not. */\n readonly contextWriter?: ContextWriterPermit;\n readonly allocationDeadline?: number;\n /** Bounded host notification of the canonical facts. Reporting never changes them. */\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n /** Exactly one notification when a creation attempt's effect on the provider is unknown. */\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\n/**\n * Allocate a session without connecting a browser, for a caller that drives the remote\n * session with its own automation client. This is the allocation path the browser owner\n * uses, so release, unknown-outcome reporting and Context writer authority keep a single\n * owner: the creation request is never retried, a foreign project is refused before it is\n * sent, and no native peer is loaded. The scope owns the release; closing it releases the\n * session whether or not the caller ever connected to it.\n */\nexport const scoped = Effect.fnUntraced(function* (\n launch: LaunchRecipe,\n options: AllocationOptions = {},\n) {\n const acquisition = yield* acquireRemote({ launch, ...options });\n\n const allocated: AllocatedSession = {\n reference: acquisition.reference,\n attempt: acquisition.attempt,\n release: acquisition.release,\n cleanupResult: acquisition.cleanupResult,\n };\n\n return allocated;\n});\n"],"mappings":";;;;;;;;;;;AAwCA,MAAa,SAAS,OAAO,WAAW,WACtC,QACA,UAA6B,CAAC,GAC9B;CACA,MAAM,cAAc,OAAO,cAAc;EAAE;EAAQ,GAAG;CAAQ,CAAC;CAS/D,OAAO;EANL,WAAW,YAAY;EACvB,SAAS,YAAY;EACrB,SAAS,YAAY;EACrB,eAAe,YAAY;CAGd;AACjB,CAAC"}
@@ -0,0 +1,270 @@
1
+ import { SessionError } from "./Errors.mjs";
2
+ import { DownloadObservation } from "./Transfers.mjs";
3
+ import { t as BrowserbaseClient } from "./Client-4RMKIpL2.mjs";
4
+ import { r as isList } from "./Launch-cAdE2rrZ.mjs";
5
+ import { isTerminalSessionStatus } from "./SessionData.mjs";
6
+ import { a as issueLiveView, o as browserRequestFailure, t as BrowserbaseSessions } from "./Sessions-suOLSym9.mjs";
7
+ import { t as issuedUpload } from "./Issued-DejqoMYL.mjs";
8
+ import { t as connectionAddress } from "./Connection-sxyxtwlk.mjs";
9
+ import { a as reported, i as noLocalConnection, n as reportCleanup, r as makeCleanup, t as acquireRemote } from "./Acquisition-CAsTTXp4.mjs";
10
+ import { BrowserbaseBrowserBinding } from "./BrowserBinding.mjs";
11
+ import { Context, Crypto, Effect, Exit, Layer, Option, Schema, Scope } from "effect";
12
+ import { BrowserError, Reasons } from "effect-browser/errors";
13
+ import * as BrowserRuntime from "effect-browser/browser-runtime";
14
+ //#region src/internal/session/Attachment.ts
15
+ const failure = (reason) => SessionError.make({
16
+ operation: "session-attach",
17
+ reason,
18
+ outcome: "undispatched"
19
+ });
20
+ /**
21
+ * Borrowing an already running session. This scope owns its local connection and nothing
22
+ * else: no allocation attempt is made, no release is requested, and no Context-writer
23
+ * authority is claimed. Whoever allocated the session keeps all three.
24
+ */
25
+ const attachRemote = Effect.fnUntraced(function* (options, local = noLocalConnection, limits) {
26
+ const client = yield* BrowserbaseClient;
27
+ const sessions = yield* BrowserbaseSessions;
28
+ const parent = yield* Scope.Scope;
29
+ const pendingWaitMillis = options.pendingWaitMillis ?? 0;
30
+ if (!Number.isSafeInteger(pendingWaitMillis) || pendingWaitMillis < 0 || pendingWaitMillis > 6e5) return yield* failure("configuration");
31
+ const observed = yield* sessions.retrieve(options.reference);
32
+ if (isTerminalSessionStatus(observed.status)) return yield* failure("expired");
33
+ if (observed.status !== "RUNNING") {
34
+ if (pendingWaitMillis === 0) return yield* failure("active");
35
+ yield* sessions.waitUntilRunning(observed.reference, { timeoutMillis: pendingWaitMillis });
36
+ }
37
+ const reference = observed.reference;
38
+ return yield* Effect.uninterruptible(Effect.gen(function* () {
39
+ const resourceScope = yield* Scope.make();
40
+ let closing = false;
41
+ let cleanup;
42
+ const terminate = yield* Effect.cached(Effect.uninterruptible(Effect.gen(function* () {
43
+ closing = true;
44
+ yield* (yield* makeCleanup(reference, "borrowed", sessions, local, (result) => {
45
+ cleanup = result;
46
+ }, limits)).close;
47
+ const result = cleanup;
48
+ const notify = options.onCleanup;
49
+ if (result !== void 0) {
50
+ yield* reported(Effect.suspend(() => reportCleanup(result)));
51
+ if (notify !== void 0) yield* reported(Effect.suspend(() => notify(result)));
52
+ }
53
+ })));
54
+ const closeScope = yield* Effect.cached(Scope.close(resourceScope, Exit.void));
55
+ yield* Scope.addFinalizer(resourceScope, terminate);
56
+ yield* Scope.addFinalizer(parent, closeScope);
57
+ return {
58
+ reference,
59
+ status: observed,
60
+ connection: (timeoutMillis) => Effect.suspend(() => closing ? Effect.fail(SessionError.make({
61
+ operation: "session-connect",
62
+ reason: "expired",
63
+ outcome: "undispatched"
64
+ })) : connectionAddress(client, sessions, reference, timeoutMillis)),
65
+ release: closeScope.pipe(Effect.andThen(Effect.suspend(() => cleanup === void 0 ? Effect.die(/* @__PURE__ */ new Error("Borrowed session closed without cleanup evidence")) : Effect.succeed(cleanup)))),
66
+ cleanupResult: Effect.sync(() => Option.fromNullishOr(cleanup))
67
+ };
68
+ }));
69
+ });
70
+ //#endregion
71
+ //#region src/internal/session/Browser.ts
72
+ /** A borrowed connection closes without requiring or requesting remote termination. */
73
+ const checkedCleanup = (close) => close.pipe(Effect.filterOrFail((result) => result.local === "closed" && result.issues.length === 0 && (result.ownership === "borrowed" ? result.remote === "not-owned" : result.remote === "confirmed"), () => BrowserError.make({
74
+ operation: "close",
75
+ reason: Reasons.Provider.make({}),
76
+ outcome: "unknown"
77
+ })));
78
+ const withConnection = (acquired) => ({
79
+ ...acquired,
80
+ connection: (timeoutMillis) => acquired.connection(timeoutMillis).pipe(Effect.mapError((error) => browserRequestFailure("connect", error))),
81
+ closeChecked: checkedCleanup(acquired.release),
82
+ controlRetired: acquired.cleanupResult.pipe(Effect.map((result) => Option.isSome(result) && result.value.ownership === "owned" && result.value.remote === "confirmed"))
83
+ });
84
+ /** Allocates the session, and therefore owns releasing it. */
85
+ const providerControls = (client, sessions, reference) => ({
86
+ liveView: (ttl) => issueLiveView(client, reference, ttl),
87
+ verifyReconnect: sessions.retrieve(reference).pipe(Effect.mapError((error) => browserRequestFailure("reconnect", error)), Effect.flatMap((status) => status.status === "RUNNING" ? Effect.void : Effect.fail(BrowserError.make({
88
+ operation: "reconnect",
89
+ reason: Reasons.Expired.make({}),
90
+ outcome: "undispatched"
91
+ }))))
92
+ });
93
+ const ownedRemote = (options) => (local, lifetimeDeadline) => Effect.gen(function* () {
94
+ const client = yield* BrowserbaseClient;
95
+ const sessions = yield* BrowserbaseSessions;
96
+ const acquired = yield* acquireRemote({
97
+ launch: options.launch,
98
+ ...options.contextWriter === void 0 ? {} : { contextWriter: options.contextWriter },
99
+ allocationDeadline: lifetimeDeadline,
100
+ ...options.onCleanup === void 0 ? {} : { onCleanup: options.onCleanup },
101
+ ...options.onAllocationUncertain === void 0 ? {} : { onAllocationUncertain: options.onAllocationUncertain }
102
+ }, local);
103
+ return {
104
+ ...withConnection(acquired),
105
+ ...providerControls(client, sessions, acquired.reference)
106
+ };
107
+ });
108
+ /** Borrows a running session: local connection only, and never a release request. */
109
+ const borrowedRemote = (options) => (local) => Effect.gen(function* () {
110
+ const client = yield* BrowserbaseClient;
111
+ const sessions = yield* BrowserbaseSessions;
112
+ const acquired = yield* attachRemote(options, local);
113
+ return {
114
+ ...withConnection(acquired),
115
+ ...providerControls(client, sessions, acquired.reference)
116
+ };
117
+ });
118
+ //#endregion
119
+ //#region src/Browser.ts
120
+ /** Only receipts issued for this exact provider session may resolve to stored paths. */
121
+ const selection = (request, reference, operation) => Effect.suspend(() => {
122
+ if (request.selection._tag === "Inline") return Effect.succeed({
123
+ _tag: "Inline",
124
+ files: request.selection.files
125
+ });
126
+ const uploads = request.selection.uploads;
127
+ if (!isList(uploads) || uploads.length < 1 || uploads.length > 8) return Effect.fail(BrowserError.make({
128
+ operation,
129
+ reason: Reasons.Configuration.make({}),
130
+ outcome: "undispatched"
131
+ }));
132
+ const paths = [];
133
+ for (const receipt of uploads) {
134
+ const issued = issuedUpload(receipt);
135
+ if (issued === void 0 || issued.reference.projectId !== reference.projectId || issued.reference.sessionId !== reference.sessionId) return Effect.fail(BrowserError.make({
136
+ operation,
137
+ reason: Reasons.Authorization.make({}),
138
+ outcome: "undispatched"
139
+ }));
140
+ paths.push(issued.remotePath);
141
+ }
142
+ return Effect.succeed({
143
+ _tag: "Stored",
144
+ paths
145
+ });
146
+ });
147
+ const makeSession = (connection, lifetime) => {
148
+ const { session, operations } = connection;
149
+ return Object.assign(session, {
150
+ reference: lifetime.reference,
151
+ closeChecked: session.closeChecked.pipe(Effect.andThen(lifetime.closeChecked)),
152
+ clickForDownload: (request) => operations.clickForDownload(request).pipe(Effect.flatMap((event) => Schema.decodeEffect(DownloadObservation)({
153
+ ...event,
154
+ reference: lifetime.reference
155
+ }).pipe(Effect.mapError(() => BrowserError.make({
156
+ operation: "download-action",
157
+ reason: Reasons.Malformed.make({}),
158
+ outcome: "unknown"
159
+ }))))),
160
+ selectFiles: (request) => selection(request, lifetime.reference, "select-files").pipe(Effect.flatMap((files) => operations.selectFiles({
161
+ selector: request.selector,
162
+ selection: files
163
+ }))),
164
+ clickForFileSelection: (request) => selection(request, lifetime.reference, "file-chooser").pipe(Effect.flatMap((files) => operations.clickForFileSelection({
165
+ selector: request.selector,
166
+ selection: files
167
+ }))),
168
+ liveView: (ttl = 60) => operations.liveView(lifetime.liveView(ttl)),
169
+ beginHandoff: (ttl = 60) => operations.beginHandoff(lifetime.liveView(ttl)),
170
+ resume: operations.resume,
171
+ detach: operations.detach,
172
+ reconnect: operations.reconnect,
173
+ close: lifetime.release,
174
+ cleanupResult: lifetime.cleanupResult
175
+ });
176
+ };
177
+ var BrowserbaseBrowser = class BrowserbaseBrowser extends Context.Service()("effect-browserbase/Browser") {
178
+ /** Open through the configured account and browser service, in the caller's scope. */
179
+ static open(policy, request) {
180
+ return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.open(policy, request));
181
+ }
182
+ /** Allocate the provider lifetime before connecting, preserving its attempt and cleanup. */
183
+ static acquire(policy, request) {
184
+ return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.acquire(policy, request));
185
+ }
186
+ /** Borrow a provider session without acquiring release authority over it. */
187
+ static attach(reference, request) {
188
+ return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.attach(reference, request));
189
+ }
190
+ /** Allocation attempts, connection ids and handoff tokens come from the required `Crypto`. */
191
+ static layer(options) {
192
+ return Layer.effect(BrowserbaseBrowser, Effect.gen(function* () {
193
+ const client = yield* BrowserbaseClient;
194
+ const sessions = yield* BrowserbaseSessions;
195
+ const crypto = yield* Crypto.Crypto;
196
+ const binding = yield* BrowserbaseBrowserBinding;
197
+ if (options.launch.context?.persist === true && options.contextWriter === void 0) return yield* BrowserError.make({
198
+ operation: "configure",
199
+ reason: Reasons.ContextLease.make({}),
200
+ outcome: "undispatched"
201
+ });
202
+ if (Object.prototype.hasOwnProperty.call(options, "bootstrap")) return yield* BrowserError.make({
203
+ operation: "configure",
204
+ reason: Reasons.Configuration.make({}),
205
+ outcome: "undispatched"
206
+ });
207
+ const runtime = yield* BrowserRuntime.make({
208
+ implementation: "browserbase-playwright-cdp",
209
+ binding,
210
+ automation: projected(options),
211
+ viewport: options.launch.viewport._tag === "Fixed" ? {
212
+ width: options.launch.viewport.width,
213
+ height: options.launch.viewport.height
214
+ } : {
215
+ width: 1280,
216
+ height: 720
217
+ },
218
+ preserveViewport: options.launch.viewport._tag !== "Fixed",
219
+ keepAlive: options.launch.keepAlive === true
220
+ });
221
+ const source = (remote) => (cleanup, deadline) => remote(cleanup, deadline).pipe(Effect.provideService(BrowserbaseClient, client), Effect.provideService(BrowserbaseSessions, sessions), Effect.provideService(Crypto.Crypto, crypto));
222
+ const acquire = Effect.fnUntraced(function* (policy, request = {}) {
223
+ const acquired = yield* runtime.acquire(policy, source(ownedRemote({
224
+ launch: options.launch,
225
+ ...options.contextWriter === void 0 ? {} : { contextWriter: options.contextWriter },
226
+ ...options.onCleanup === void 0 ? {} : { onCleanup: options.onCleanup },
227
+ ...options.onAllocationUncertain === void 0 ? {} : { onAllocationUncertain: options.onAllocationUncertain }
228
+ })), request);
229
+ const connected = yield* Effect.cached(acquired.connect.pipe(Effect.map((connection) => makeSession(connection, acquired.lifetime))));
230
+ return {
231
+ reference: acquired.reference,
232
+ attempt: acquired.lifetime.attempt,
233
+ failure: acquired.failure,
234
+ close: acquired.close,
235
+ connect: acquired.connect.pipe(Effect.andThen(connected))
236
+ };
237
+ });
238
+ const attach = Effect.fnUntraced(function* (reference, request) {
239
+ const acquired = yield* runtime.acquire(request.policy, source(borrowedRemote({
240
+ reference,
241
+ ...request.pendingWaitMillis === void 0 ? {} : { pendingWaitMillis: request.pendingWaitMillis },
242
+ ...options.onCleanup === void 0 ? {} : { onCleanup: options.onCleanup }
243
+ })), {
244
+ ...request.bootstrap === void 0 ? {} : { bootstrap: request.bootstrap },
245
+ existingTarget: request.target ?? {}
246
+ });
247
+ return yield* acquired.connect.pipe(Effect.map((connection) => makeSession(connection, acquired.lifetime)));
248
+ });
249
+ return BrowserbaseBrowser.of({
250
+ acquire,
251
+ attach,
252
+ open: (policy, request) => acquire(policy, request).pipe(Effect.flatMap((acquired) => acquired.connect))
253
+ });
254
+ }));
255
+ }
256
+ };
257
+ /** Only the automation fields cross the schema boundary; launch and callbacks are separate. */
258
+ const projected = (options) => ({
259
+ ...options.maxHostReads === void 0 ? {} : { maxHostReads: options.maxHostReads },
260
+ ...options.actionTimeoutMillis === void 0 ? {} : { actionTimeoutMillis: options.actionTimeoutMillis },
261
+ ...options.maxPages === void 0 ? {} : { maxPages: options.maxPages },
262
+ ...options.initialPage === void 0 ? {} : { initialPage: options.initialPage },
263
+ ...options.popupPolicy === void 0 ? {} : { popupPolicy: options.popupPolicy },
264
+ ...options.dialogPolicy === void 0 ? {} : { dialogPolicy: options.dialogPolicy },
265
+ ...options.pageControl === void 0 ? {} : { pageControl: options.pageControl }
266
+ });
267
+ //#endregion
268
+ export { BrowserbaseBrowser as t };
269
+
270
+ //# sourceMappingURL=Browser-DpSajNai.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Browser-DpSajNai.mjs","names":[],"sources":["../src/internal/session/Attachment.ts","../src/internal/session/Browser.ts","../src/Browser.ts"],"sourcesContent":["import { Effect, Exit, Option, Scope } from \"effect\";\n\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport { BrowserbaseClient } from \"../../Client.ts\";\nimport { SessionError } from \"../../Errors.ts\";\nimport type { SessionReference } from \"../../References.ts\";\nimport { isTerminalSessionStatus } from \"../../SessionData.ts\";\nimport { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { connectionAddress } from \"../provider/Connection.ts\";\nimport {\n makeCleanup,\n noLocalConnection,\n reported,\n type CleanupLimits,\n type LocalCleanup,\n} from \"./Cleanup.ts\";\nimport { reportCleanup } from \"./Diagnostics.ts\";\n\nexport interface AttachmentOptions {\n readonly reference: SessionReference;\n /** Bounded admission of a session the provider has not finished starting. */\n readonly pendingWaitMillis?: number;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n}\n\nconst failure = (reason: SessionError[\"reason\"]) =>\n SessionError.make({ operation: \"session-attach\", reason, outcome: \"undispatched\" });\n\n/**\n * Borrowing an already running session. This scope owns its local connection and nothing\n * else: no allocation attempt is made, no release is requested, and no Context-writer\n * authority is claimed. Whoever allocated the session keeps all three.\n */\nexport const attachRemote = Effect.fnUntraced(function* (\n options: AttachmentOptions,\n local: LocalCleanup = noLocalConnection,\n limits?: CleanupLimits,\n) {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n const parent = yield* Scope.Scope;\n const pendingWaitMillis = options.pendingWaitMillis ?? 0;\n\n if (\n !Number.isSafeInteger(pendingWaitMillis) ||\n pendingWaitMillis < 0 ||\n pendingWaitMillis > 600_000\n )\n return yield* failure(\"configuration\");\n\n // The status read validates project authority before anything is borrowed. A terminal\n // session needs a fresh allocation from durable state, never a reattachment.\n const observed = yield* sessions.retrieve(options.reference);\n\n if (isTerminalSessionStatus(observed.status)) return yield* failure(\"expired\");\n if (observed.status !== \"RUNNING\") {\n if (pendingWaitMillis === 0) return yield* failure(\"active\");\n yield* sessions.waitUntilRunning(observed.reference, { timeoutMillis: pendingWaitMillis });\n }\n const reference = observed.reference;\n\n return yield* Effect.uninterruptible(\n Effect.gen(function* () {\n const resourceScope = yield* Scope.make();\n let closing = false;\n let cleanup: CleanupResult | undefined;\n\n const terminate = yield* Effect.cached(\n Effect.uninterruptible(\n Effect.gen(function* () {\n closing = true;\n\n const coordinator = yield* makeCleanup(\n reference,\n \"borrowed\",\n sessions,\n local,\n (result) => {\n cleanup = result;\n },\n limits,\n );\n\n yield* coordinator.close;\n const result = cleanup;\n const notify = options.onCleanup;\n\n if (result !== undefined) {\n yield* reported(Effect.suspend(() => reportCleanup(result)));\n if (notify !== undefined) yield* reported(Effect.suspend(() => notify(result)));\n }\n }),\n ),\n );\n\n const closeScope = yield* Effect.cached(Scope.close(resourceScope, Exit.void));\n\n // Teardown is registered before the first connection, exactly as an owned scope does.\n yield* Scope.addFinalizer(resourceScope, terminate);\n yield* Scope.addFinalizer(parent, closeScope);\n\n return {\n reference,\n status: observed,\n connection: (timeoutMillis: number) =>\n Effect.suspend(() =>\n closing\n ? Effect.fail(\n SessionError.make({\n operation: \"session-connect\",\n reason: \"expired\",\n outcome: \"undispatched\",\n }),\n )\n : // Credentials are fetched fresh: an expiry can race the caller's own read.\n connectionAddress(client, sessions, reference, timeoutMillis),\n ),\n release: closeScope.pipe(\n Effect.andThen(\n Effect.suspend(() =>\n cleanup === undefined\n ? Effect.die(new Error(\"Borrowed session closed without cleanup evidence\"))\n : Effect.succeed(cleanup),\n ),\n ),\n ),\n cleanupResult: Effect.sync(() => Option.fromNullishOr(cleanup)),\n };\n }),\n );\n});\n","import { type Crypto, Effect, Option, type Redacted } from \"effect\";\nimport type { Lifetime, Source } from \"effect-browser/browser-runtime\";\nimport { BrowserError, Reasons } from \"effect-browser/errors\";\n\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport { BrowserbaseClient } from \"../../Client.ts\";\nimport type { AllocationError, ContextError, SessionError } from \"../../Errors.ts\";\nimport type { LaunchRecipe } from \"../../Launch.ts\";\nimport type { AllocationAttempt, SessionReference } from \"../../References.ts\";\nimport { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { issueLiveView, type LiveView } from \"../browser/LiveView.ts\";\nimport { browserRequestFailure } from \"../browser/RequestFailure.ts\";\nimport { acquireRemote } from \"./Acquisition.ts\";\nimport { attachRemote } from \"./Attachment.ts\";\nimport type { ContextWriterPermit } from \"./WriterFacts.ts\";\n\nexport interface RemoteLease extends Lifetime {\n readonly reference: SessionReference;\n readonly closeChecked: Effect.Effect<CleanupResult, BrowserError>;\n readonly attempt?: AllocationAttempt;\n readonly release: Effect.Effect<CleanupResult>;\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n readonly liveView: (ttl: number) => Effect.Effect<LiveView, BrowserError>;\n}\n\ntype RemoteSource<L extends Lifetime, E> = Source<\n L,\n E,\n BrowserbaseClient | BrowserbaseSessions | Crypto.Crypto\n>;\n\n/** A borrowed connection closes without requiring or requesting remote termination. */\nconst checkedCleanup = (\n close: Effect.Effect<CleanupResult>,\n): Effect.Effect<CleanupResult, BrowserError> =>\n close.pipe(\n Effect.filterOrFail(\n (result) =>\n result.local === \"closed\" &&\n result.issues.length === 0 &&\n (result.ownership === \"borrowed\"\n ? result.remote === \"not-owned\"\n : result.remote === \"confirmed\"),\n () =>\n BrowserError.make({\n operation: \"close\",\n reason: Reasons.Provider.make({}),\n outcome: \"unknown\",\n }),\n ),\n );\n\nconst withConnection = <\n A extends {\n readonly reference: SessionReference;\n readonly connection: (\n timeoutMillis: number,\n ) => Effect.Effect<Redacted.Redacted<string>, SessionError>;\n readonly release: Effect.Effect<CleanupResult>;\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n },\n>(\n acquired: A,\n) => ({\n ...acquired,\n connection: (timeoutMillis: number) =>\n acquired\n .connection(timeoutMillis)\n .pipe(Effect.mapError((error) => browserRequestFailure(\"connect\", error))),\n closeChecked: checkedCleanup(acquired.release),\n controlRetired: acquired.cleanupResult.pipe(\n Effect.map(\n (result) =>\n Option.isSome(result) &&\n result.value.ownership === \"owned\" &&\n result.value.remote === \"confirmed\",\n ),\n ),\n});\n\nexport interface OwnedLease extends RemoteLease {\n readonly attempt: AllocationAttempt;\n}\n\nexport interface OwnedOptions {\n /** The single provider-faithful launch description; the owner adds no second default body. */\n readonly launch: LaunchRecipe;\n /** Required for a persistent context; the writer permit, not this owner, holds that authority. */\n readonly contextWriter?: ContextWriterPermit;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\n/** Allocates the session, and therefore owns releasing it. */\nconst providerControls = (\n client: BrowserbaseClient[\"Service\"],\n sessions: BrowserbaseSessions[\"Service\"],\n reference: SessionReference,\n) => ({\n liveView: (ttl: number) => issueLiveView(client, reference, ttl),\n verifyReconnect: sessions.retrieve(reference).pipe(\n Effect.mapError((error) => browserRequestFailure(\"reconnect\", error)),\n Effect.flatMap((status) =>\n status.status === \"RUNNING\"\n ? Effect.void\n : Effect.fail(\n BrowserError.make({\n operation: \"reconnect\",\n reason: Reasons.Expired.make({}),\n outcome: \"undispatched\",\n }),\n ),\n ),\n ),\n});\n\nexport const ownedRemote =\n (\n options: OwnedOptions,\n ): RemoteSource<OwnedLease, AllocationError | BrowserError | ContextError> =>\n (local, lifetimeDeadline) =>\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n\n const acquired = yield* acquireRemote(\n {\n launch: options.launch,\n ...(options.contextWriter === undefined ? {} : { contextWriter: options.contextWriter }),\n allocationDeadline: lifetimeDeadline,\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n ...(options.onAllocationUncertain === undefined\n ? {}\n : { onAllocationUncertain: options.onAllocationUncertain }),\n },\n local,\n );\n\n return {\n ...withConnection(acquired),\n ...providerControls(client, sessions, acquired.reference),\n };\n });\n\n/** Borrows a running session: local connection only, and never a release request. */\nexport const borrowedRemote =\n (options: {\n readonly reference: SessionReference;\n readonly pendingWaitMillis?: number;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n }): RemoteSource<RemoteLease, SessionError> =>\n (local) =>\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n const acquired = yield* attachRemote(options, local);\n\n return {\n ...withConnection(acquired),\n ...providerControls(client, sessions, acquired.reference),\n };\n });\n","import {\n Context,\n Crypto,\n Effect,\n Layer,\n type Option,\n type Redacted,\n Schema,\n type Scope,\n} from \"effect\";\nimport type { BrowserSession, OpenOptions } from \"effect-browser/browser\";\nimport type {\n ActionResult,\n AutomationOptions,\n BrowserPolicy,\n ClickRequest,\n Observation,\n} from \"effect-browser/browser-data\";\nimport * as BrowserRuntime from \"effect-browser/browser-runtime\";\nimport {\n BrowserError,\n Reasons,\n type BrowserOperation,\n type InitializationError,\n} from \"effect-browser/errors\";\n\nimport { BrowserbaseBrowserBinding } from \"./BrowserBinding.ts\";\nimport type { CleanupResult } from \"./Cleanup.ts\";\nimport { BrowserbaseClient } from \"./Client.ts\";\nimport type { AllocationError, ContextError, SessionError } from \"./Errors.ts\";\nimport type { LiveView } from \"./internal/browser/LiveView.ts\";\nimport { isList } from \"./internal/List.ts\";\nimport { borrowedRemote, ownedRemote, type RemoteLease } from \"./internal/session/Browser.ts\";\nimport type { ContextWriterPermit } from \"./internal/session/WriterFacts.ts\";\nimport { issuedUpload } from \"./internal/upload/Issued.ts\";\nimport type { LaunchRecipe } from \"./Launch.ts\";\nimport type { AllocationAttempt, SessionReference } from \"./References.ts\";\nimport { BrowserbaseSessions } from \"./Sessions.ts\";\nimport { DownloadObservation, type SelectFilesRequest } from \"./Transfers.ts\";\n\nexport type { LiveView } from \"./internal/browser/LiveView.ts\";\nexport type { FileSelection, SelectFilesRequest } from \"./Transfers.ts\";\n\n/** Host configuration. Credentials live in the Client; a model never selects these values. */\nexport interface BrowserOptions extends AutomationOptions {\n readonly launch: LaunchRecipe;\n /** Required whenever the launch recipe persists a context. */\n readonly contextWriter?: ContextWriterPermit;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\nexport interface Handoff {\n readonly token: Redacted.Redacted<string>;\n readonly view: LiveView;\n}\n\n/** Browserbase identity, remote artifacts and provider cleanup remain hosted capabilities. */\nexport interface BrowserbaseSession<E = never> extends BrowserSession<E> {\n readonly reference: SessionReference;\n readonly closeChecked: Effect.Effect<CleanupResult, BrowserError>;\n readonly clickForDownload: (\n request: ClickRequest,\n ) => Effect.Effect<DownloadObservation, BrowserError>;\n /** Attaches to an existing file input; an uploaded branch needs a receipt for this session. */\n readonly selectFiles: (request: SelectFilesRequest) => Effect.Effect<ActionResult, BrowserError>;\n /** Registers the chooser observation before the single click that opens it. */\n readonly clickForFileSelection: (\n request: SelectFilesRequest,\n ) => Effect.Effect<ActionResult, BrowserError>;\n readonly liveView: (expiresInSeconds?: number) => Effect.Effect<LiveView, BrowserError>;\n readonly beginHandoff: (expiresInSeconds?: number) => Effect.Effect<Handoff, BrowserError>;\n readonly resume: (\n token: Redacted.Redacted<string>,\n operatorReleasedControl: boolean,\n ) => Effect.Effect<Observation, BrowserError>;\n readonly detach: Effect.Effect<\n { readonly reference: SessionReference; readonly targetId: string },\n BrowserError\n >;\n readonly reconnect: (\n operatorReleasedControl: boolean,\n ) => Effect.Effect<Observation, BrowserError | InitializationError>;\n readonly close: Effect.Effect<CleanupResult>;\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n}\n\nexport interface AttachRequest<E = never, R = never> extends OpenOptions<E, R> {\n readonly policy: BrowserPolicy;\n /** The exact page to resume; without it the session must have exactly one page. */\n readonly target?: { readonly targetId: string };\n /** Bounded admission of a session the provider has not finished starting. */\n readonly pendingWaitMillis?: number;\n}\n\nexport interface BrowserAcquisition<E = never> {\n readonly reference: SessionReference;\n readonly attempt: AllocationAttempt;\n readonly failure: Effect.Effect<never, E | InitializationError>;\n readonly connect: Effect.Effect<BrowserbaseSession<E>, BrowserError | E | InitializationError>;\n readonly close: Effect.Effect<CleanupResult>;\n}\n\n/** Only receipts issued for this exact provider session may resolve to stored paths. */\nconst selection = (\n request: SelectFilesRequest,\n reference: SessionReference,\n operation: BrowserOperation,\n): Effect.Effect<BrowserRuntime.ResolvedFileSelection, BrowserError> =>\n Effect.suspend(() => {\n if (request.selection._tag === \"Inline\")\n return Effect.succeed<BrowserRuntime.ResolvedFileSelection>({\n _tag: \"Inline\",\n files: request.selection.files,\n });\n\n const uploads = request.selection.uploads;\n\n if (!isList(uploads) || uploads.length < 1 || uploads.length > 8)\n return Effect.fail(\n BrowserError.make({\n operation,\n reason: Reasons.Configuration.make({}),\n outcome: \"undispatched\",\n }),\n );\n const paths: string[] = [];\n\n for (const receipt of uploads) {\n const issued = issuedUpload(receipt);\n\n if (\n issued === undefined ||\n issued.reference.projectId !== reference.projectId ||\n issued.reference.sessionId !== reference.sessionId\n )\n return Effect.fail(\n BrowserError.make({\n operation,\n reason: Reasons.Authorization.make({}),\n outcome: \"undispatched\",\n }),\n );\n paths.push(issued.remotePath);\n }\n\n return Effect.succeed<BrowserRuntime.ResolvedFileSelection>({ _tag: \"Stored\", paths });\n });\n\nconst makeSession = <E>(\n connection: BrowserRuntime.Connection<SessionReference, E>,\n lifetime: RemoteLease,\n): BrowserbaseSession<E> => {\n const { session, operations } = connection;\n\n // Decorating the same object preserves its private capture and page-control associations.\n return Object.assign(session, {\n reference: lifetime.reference,\n closeChecked: session.closeChecked.pipe(Effect.andThen(lifetime.closeChecked)),\n clickForDownload: (request) =>\n operations.clickForDownload(request).pipe(\n Effect.flatMap((event) =>\n Schema.decodeEffect(DownloadObservation)({\n ...event,\n reference: lifetime.reference,\n }).pipe(\n Effect.mapError(() =>\n BrowserError.make({\n operation: \"download-action\",\n reason: Reasons.Malformed.make({}),\n outcome: \"unknown\",\n }),\n ),\n ),\n ),\n ),\n selectFiles: (request) =>\n selection(request, lifetime.reference, \"select-files\").pipe(\n Effect.flatMap((files) =>\n operations.selectFiles({ selector: request.selector, selection: files }),\n ),\n ),\n clickForFileSelection: (request) =>\n selection(request, lifetime.reference, \"file-chooser\").pipe(\n Effect.flatMap((files) =>\n operations.clickForFileSelection({ selector: request.selector, selection: files }),\n ),\n ),\n liveView: (ttl = 60) => operations.liveView(lifetime.liveView(ttl)),\n beginHandoff: (ttl = 60) => operations.beginHandoff(lifetime.liveView(ttl)),\n resume: operations.resume,\n detach: operations.detach,\n reconnect: operations.reconnect,\n close: lifetime.release,\n cleanupResult: lifetime.cleanupResult,\n } satisfies Omit<BrowserbaseSession<E>, Exclude<keyof BrowserSession<E>, \"closeChecked\">>);\n};\n\nexport class BrowserbaseBrowser extends Context.Service<\n BrowserbaseBrowser,\n {\n readonly acquire: <E = never, R = never>(\n policy: BrowserPolicy,\n request?: OpenOptions<E, R>,\n ) => Effect.Effect<\n BrowserAcquisition<E>,\n AllocationError | BrowserError | ContextError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n /** Borrowed control of a session this process did not allocate and will not release. */\n readonly attach: <E = never, R = never>(\n reference: SessionReference,\n request: AttachRequest<E, R>,\n ) => Effect.Effect<\n BrowserbaseSession<E>,\n BrowserError | SessionError | E | InitializationError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n readonly open: <E = never, R = never>(\n policy: BrowserPolicy,\n request?: OpenOptions<E, R>,\n ) => Effect.Effect<\n BrowserbaseSession<E>,\n AllocationError | BrowserError | ContextError | E | InitializationError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n }\n>()(\"effect-browserbase/Browser\") {\n /** Open through the configured account and browser service, in the caller's scope. */\n static open<E = never, R = never>(policy: BrowserPolicy, request?: OpenOptions<E, R>) {\n return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.open(policy, request));\n }\n\n /** Allocate the provider lifetime before connecting, preserving its attempt and cleanup. */\n static acquire<E = never, R = never>(policy: BrowserPolicy, request?: OpenOptions<E, R>) {\n return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.acquire(policy, request));\n }\n\n /** Borrow a provider session without acquiring release authority over it. */\n static attach<E = never, R = never>(reference: SessionReference, request: AttachRequest<E, R>) {\n return Effect.flatMap(BrowserbaseBrowser, (browser) => browser.attach(reference, request));\n }\n\n /** Allocation attempts, connection ids and handoff tokens come from the required `Crypto`. */\n static layer(\n options: BrowserOptions,\n ): Layer.Layer<\n BrowserbaseBrowser,\n BrowserError,\n BrowserbaseClient | BrowserbaseSessions | Crypto.Crypto\n > {\n return Layer.effect(\n BrowserbaseBrowser,\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n const crypto = yield* Crypto.Crypto;\n const binding = yield* BrowserbaseBrowserBinding;\n\n if (options.launch.context?.persist === true && options.contextWriter === undefined)\n return yield* BrowserError.make({\n operation: \"configure\",\n reason: Reasons.ContextLease.make({}),\n outcome: \"undispatched\",\n });\n if (Object.prototype.hasOwnProperty.call(options, \"bootstrap\"))\n return yield* BrowserError.make({\n operation: \"configure\",\n reason: Reasons.Configuration.make({}),\n outcome: \"undispatched\",\n });\n\n const runtime = yield* BrowserRuntime.make({\n implementation: \"browserbase-playwright-cdp\",\n binding,\n automation: projected(options),\n viewport:\n options.launch.viewport._tag === \"Fixed\"\n ? { width: options.launch.viewport.width, height: options.launch.viewport.height }\n : { width: 1280, height: 720 },\n preserveViewport: options.launch.viewport._tag !== \"Fixed\",\n keepAlive: options.launch.keepAlive === true,\n });\n\n const source =\n <L extends BrowserRuntime.Lifetime, E>(\n remote: BrowserRuntime.Source<\n L,\n E,\n BrowserbaseClient | BrowserbaseSessions | Crypto.Crypto\n >,\n ): BrowserRuntime.Source<L, E> =>\n (cleanup, deadline) =>\n remote(cleanup, deadline).pipe(\n Effect.provideService(BrowserbaseClient, client),\n Effect.provideService(BrowserbaseSessions, sessions),\n Effect.provideService(Crypto.Crypto, crypto),\n );\n\n const acquire = Effect.fnUntraced(function* <E = never, R = never>(\n policy: BrowserPolicy,\n request: OpenOptions<E, R> = {},\n ) {\n const acquired = yield* runtime.acquire(\n policy,\n source(\n ownedRemote({\n launch: options.launch,\n ...(options.contextWriter === undefined\n ? {}\n : { contextWriter: options.contextWriter }),\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n ...(options.onAllocationUncertain === undefined\n ? {}\n : { onAllocationUncertain: options.onAllocationUncertain }),\n }),\n ),\n request,\n );\n\n const connected = yield* Effect.cached(\n acquired.connect.pipe(\n Effect.map((connection) => makeSession(connection, acquired.lifetime)),\n ),\n );\n\n return {\n reference: acquired.reference,\n attempt: acquired.lifetime.attempt,\n failure: acquired.failure,\n close: acquired.close,\n connect: acquired.connect.pipe(Effect.andThen(connected)),\n } satisfies BrowserAcquisition<E>;\n });\n\n const attach = Effect.fnUntraced(function* <E = never, R = never>(\n reference: SessionReference,\n request: AttachRequest<E, R>,\n ) {\n const acquired = yield* runtime.acquire(\n request.policy,\n source(\n borrowedRemote({\n reference,\n ...(request.pendingWaitMillis === undefined\n ? {}\n : { pendingWaitMillis: request.pendingWaitMillis }),\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n }),\n ),\n {\n ...(request.bootstrap === undefined ? {} : { bootstrap: request.bootstrap }),\n existingTarget: request.target ?? {},\n },\n );\n\n return yield* acquired.connect.pipe(\n Effect.map((connection) => makeSession(connection, acquired.lifetime)),\n );\n });\n\n return BrowserbaseBrowser.of({\n acquire,\n attach,\n open: (policy, request) =>\n acquire(policy, request).pipe(Effect.flatMap((acquired) => acquired.connect)),\n });\n }),\n );\n }\n}\n\n/** Only the automation fields cross the schema boundary; launch and callbacks are separate. */\nconst projected = (options: BrowserOptions) => ({\n ...(options.maxHostReads === undefined ? {} : { maxHostReads: options.maxHostReads }),\n ...(options.actionTimeoutMillis === undefined\n ? {}\n : { actionTimeoutMillis: options.actionTimeoutMillis }),\n ...(options.maxPages === undefined ? {} : { maxPages: options.maxPages }),\n ...(options.initialPage === undefined ? {} : { initialPage: options.initialPage }),\n ...(options.popupPolicy === undefined ? {} : { popupPolicy: options.popupPolicy }),\n ...(options.dialogPolicy === undefined ? {} : { dialogPolicy: options.dialogPolicy }),\n ...(options.pageControl === undefined ? {} : { pageControl: options.pageControl }),\n});\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,WAAW,WACf,aAAa,KAAK;CAAE,WAAW;CAAkB;CAAQ,SAAS;AAAe,CAAC;;;;;;AAOpF,MAAa,eAAe,OAAO,WAAW,WAC5C,SACA,QAAsB,mBACtB,QACA;CACA,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,OAAO;CACxB,MAAM,SAAS,OAAO,MAAM;CAC5B,MA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