effect-browserbase 0.1.0-beta.102

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 (136) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +441 -0
  3. package/dist/Account.d.mts +34 -0
  4. package/dist/Account.mjs +41 -0
  5. package/dist/Account.mjs.map +1 -0
  6. package/dist/Acquisition-WBafHwXH.mjs +280 -0
  7. package/dist/Acquisition-WBafHwXH.mjs.map +1 -0
  8. package/dist/Agents.d.mts +156 -0
  9. package/dist/Agents.mjs +307 -0
  10. package/dist/Agents.mjs.map +1 -0
  11. package/dist/Allocation.d.mts +99 -0
  12. package/dist/Allocation.mjs +29 -0
  13. package/dist/Allocation.mjs.map +1 -0
  14. package/dist/Association-CEps4hYP.mjs +10 -0
  15. package/dist/Association-CEps4hYP.mjs.map +1 -0
  16. package/dist/Authorization-Ll5f_XNM.mjs +12 -0
  17. package/dist/Authorization-Ll5f_XNM.mjs.map +1 -0
  18. package/dist/Bootstrap-BXuzZojd.mjs +194 -0
  19. package/dist/Bootstrap-BXuzZojd.mjs.map +1 -0
  20. package/dist/Bootstrap-m7lHgj0D.d.mts +177 -0
  21. package/dist/Bootstrap.d.mts +2 -0
  22. package/dist/Bootstrap.mjs +2 -0
  23. package/dist/Browser-joE4Zgys.mjs +1557 -0
  24. package/dist/Browser-joE4Zgys.mjs.map +1 -0
  25. package/dist/Browser.d.mts +195 -0
  26. package/dist/Browser.mjs +2 -0
  27. package/dist/BrowserBinding-qbQA6JhH.mjs +2452 -0
  28. package/dist/BrowserBinding-qbQA6JhH.mjs.map +1 -0
  29. package/dist/BrowserBinding.d.mts +40 -0
  30. package/dist/BrowserBinding.mjs +2 -0
  31. package/dist/BrowserData-LpcAuAub.d.mts +369 -0
  32. package/dist/BrowserData.d.mts +2 -0
  33. package/dist/BrowserData.mjs +442 -0
  34. package/dist/BrowserData.mjs.map +1 -0
  35. package/dist/Capture-CZJPuD7b.mjs +532 -0
  36. package/dist/Capture-CZJPuD7b.mjs.map +1 -0
  37. package/dist/Capture-Dr5MkIJb.d.mts +125 -0
  38. package/dist/Capture.d.mts +2 -0
  39. package/dist/Capture.mjs +2 -0
  40. package/dist/Certificates.d.mts +35 -0
  41. package/dist/Certificates.mjs +90 -0
  42. package/dist/Certificates.mjs.map +1 -0
  43. package/dist/Cleanup-G2YpTCuU.d.mts +24 -0
  44. package/dist/Cleanup.d.mts +2 -0
  45. package/dist/Cleanup.mjs +48 -0
  46. package/dist/Cleanup.mjs.map +1 -0
  47. package/dist/Client-Ca0zSg1n.d.mts +53 -0
  48. package/dist/Client-D1_xYM9o.mjs +424 -0
  49. package/dist/Client-D1_xYM9o.mjs.map +1 -0
  50. package/dist/Client.d.mts +2 -0
  51. package/dist/Client.mjs +2 -0
  52. package/dist/ContextCoordination.d.mts +16 -0
  53. package/dist/ContextCoordination.mjs +67 -0
  54. package/dist/ContextCoordination.mjs.map +1 -0
  55. package/dist/ContextWriter-BrQmoXRg.mjs +187 -0
  56. package/dist/ContextWriter-BrQmoXRg.mjs.map +1 -0
  57. package/dist/Contexts.d.mts +32 -0
  58. package/dist/Contexts.mjs +103 -0
  59. package/dist/Contexts.mjs.map +1 -0
  60. package/dist/Deadline-CrViaogr.mjs +13 -0
  61. package/dist/Deadline-CrViaogr.mjs.map +1 -0
  62. package/dist/Downloads.d.mts +44 -0
  63. package/dist/Downloads.mjs +142 -0
  64. package/dist/Downloads.mjs.map +1 -0
  65. package/dist/Errors.d.mts +123 -0
  66. package/dist/Errors.mjs +329 -0
  67. package/dist/Errors.mjs.map +1 -0
  68. package/dist/Extensions-ClZbYb1H.mjs +237 -0
  69. package/dist/Extensions-ClZbYb1H.mjs.map +1 -0
  70. package/dist/Extensions.d.mts +44 -0
  71. package/dist/Extensions.mjs +2 -0
  72. package/dist/Functions.d.mts +227 -0
  73. package/dist/Functions.mjs +332 -0
  74. package/dist/Functions.mjs.map +1 -0
  75. package/dist/Images-DgscEfSf.mjs +127 -0
  76. package/dist/Images-DgscEfSf.mjs.map +1 -0
  77. package/dist/Issued-DejqoMYL.mjs +15 -0
  78. package/dist/Issued-DejqoMYL.mjs.map +1 -0
  79. package/dist/Launch-BHcAEq05.mjs +111 -0
  80. package/dist/Launch-BHcAEq05.mjs.map +1 -0
  81. package/dist/Launch-C8CfaYxb.d.mts +132 -0
  82. package/dist/Launch.d.mts +2 -0
  83. package/dist/Launch.mjs +105 -0
  84. package/dist/Launch.mjs.map +1 -0
  85. package/dist/PageControl.d.mts +16 -0
  86. package/dist/PageControl.mjs +36 -0
  87. package/dist/PageControl.mjs.map +1 -0
  88. package/dist/PageControlAssociation-DabEg5AR.mjs +10 -0
  89. package/dist/PageControlAssociation-DabEg5AR.mjs.map +1 -0
  90. package/dist/PageFetch.d.mts +40 -0
  91. package/dist/PageFetch.mjs +64 -0
  92. package/dist/PageFetch.mjs.map +1 -0
  93. package/dist/Projects.d.mts +39 -0
  94. package/dist/Projects.mjs +71 -0
  95. package/dist/Projects.mjs.map +1 -0
  96. package/dist/Recordings.d.mts +28 -0
  97. package/dist/Recordings.mjs +131 -0
  98. package/dist/Recordings.mjs.map +1 -0
  99. package/dist/References-URDAtapt.d.mts +35 -0
  100. package/dist/References.d.mts +2 -0
  101. package/dist/References.mjs +41 -0
  102. package/dist/References.mjs.map +1 -0
  103. package/dist/Replays.d.mts +28 -0
  104. package/dist/Replays.mjs +109 -0
  105. package/dist/Replays.mjs.map +1 -0
  106. package/dist/Resource-DBksC4zB.mjs +50 -0
  107. package/dist/Resource-DBksC4zB.mjs.map +1 -0
  108. package/dist/Search.d.mts +38 -0
  109. package/dist/Search.mjs +53 -0
  110. package/dist/Search.mjs.map +1 -0
  111. package/dist/SessionData-DRKcKCqw.d.mts +39 -0
  112. package/dist/SessionData.d.mts +2 -0
  113. package/dist/SessionData.mjs +55 -0
  114. package/dist/SessionData.mjs.map +1 -0
  115. package/dist/Sessions-B8E4kMxo.d.mts +68 -0
  116. package/dist/Sessions-CtbseWEh.mjs +244 -0
  117. package/dist/Sessions-CtbseWEh.mjs.map +1 -0
  118. package/dist/Sessions.d.mts +3 -0
  119. package/dist/Sessions.mjs +3 -0
  120. package/dist/TransferPolicy-DQ06i7SZ.mjs +25 -0
  121. package/dist/TransferPolicy-DQ06i7SZ.mjs.map +1 -0
  122. package/dist/Transfers-Czv5IZzJ.d.mts +76 -0
  123. package/dist/Transfers.d.mts +2 -0
  124. package/dist/Transfers.mjs +101 -0
  125. package/dist/Transfers.mjs.map +1 -0
  126. package/dist/Uploads.d.mts +29 -0
  127. package/dist/Uploads.mjs +107 -0
  128. package/dist/Uploads.mjs.map +1 -0
  129. package/dist/Webhooks.d.mts +60 -0
  130. package/dist/Webhooks.mjs +143 -0
  131. package/dist/Webhooks.mjs.map +1 -0
  132. package/dist/WriterFacts-osvYAsIx.d.mts +61 -0
  133. package/dist/index.d.mts +30 -0
  134. package/dist/index.mjs +30 -0
  135. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  136. package/package.json +163 -0
@@ -0,0 +1,280 @@
1
+ import { Identifier, SessionReference } from "./References.mjs";
2
+ import { AllocationError, ContextError, SessionError } from "./Errors.mjs";
3
+ import { t as BrowserbaseClient } from "./Client-D1_xYM9o.mjs";
4
+ import { t as compileLaunch } from "./Launch-BHcAEq05.mjs";
5
+ import { ProviderSession } from "./SessionData.mjs";
6
+ import { CleanupIssue, CleanupResult } from "./Cleanup.mjs";
7
+ import { i as requireContextWriterPermit } from "./ContextWriter-BrQmoXRg.mjs";
8
+ import { n as nowMillis, r as until, t as deadlineAfter } from "./Deadline-CrViaogr.mjs";
9
+ import { t as BrowserbaseSessions } from "./Sessions-CtbseWEh.mjs";
10
+ import { Cause, Clock, Data, Effect, ErrorReporter, Exit, Option, Redacted, Schema, Scope } from "effect";
11
+ //#region src/internal/provider/Connection.ts
12
+ const Connection = Schema.Struct({
13
+ ...ProviderSession.fields,
14
+ connectUrl: Schema.String.check(Schema.isMaxLength(16384))
15
+ });
16
+ /** A provider-issued endpoint is authority, not a persisted session identifier. */
17
+ const connectionUrl = Schema.String.check(Schema.isMaxLength(16384), Schema.makeFilter((value) => {
18
+ try {
19
+ const url = new URL(value);
20
+ return url.protocol === "wss:" && !url.username && !url.password && !url.port && !url.hash && url.hostname.endsWith(".browserbase.com");
21
+ } catch {
22
+ return false;
23
+ }
24
+ }));
25
+ const connectionAddress = Effect.fnUntraced(function* (client, sessions, reference, timeoutMillis) {
26
+ const fail = (reason) => SessionError.make({
27
+ operation: "session-connect",
28
+ reason
29
+ });
30
+ const ref = yield* Schema.decodeEffect(SessionReference)(reference).pipe(Effect.mapError(() => fail("configuration")));
31
+ if (ref.projectId !== client.projectId) return yield* fail("authorization");
32
+ const deadline = yield* deadlineAfter(timeoutMillis);
33
+ yield* sessions.waitUntilRunning(ref, { timeoutMillis });
34
+ if ((yield* nowMillis) >= deadline) return yield* fail("timeout");
35
+ const raw = yield* until(client.json("GET", `/v1/sessions/${encodeURIComponent(ref.sessionId)}`, void 0, deadline), deadline, () => fail("timeout")).pipe(Effect.mapError((error) => fail(error.reason)));
36
+ const value = yield* Schema.decodeUnknownEffect(Connection)(raw).pipe(Effect.mapError(() => fail("malformed")));
37
+ if (value.id !== ref.sessionId || value.projectId !== ref.projectId) return yield* fail("malformed");
38
+ if (value.status !== "RUNNING") return yield* fail("expired");
39
+ const url = yield* Schema.decodeEffect(connectionUrl)(value.connectUrl).pipe(Effect.mapError(() => fail("unsafe-url")));
40
+ return Redacted.make(url);
41
+ });
42
+ //#endregion
43
+ //#region src/internal/session/Cleanup.ts
44
+ const noLocalConnection = {
45
+ fence: Effect.void,
46
+ capture: Effect.void,
47
+ initialization: Effect.void,
48
+ disconnect: Effect.succeed("not-connected")
49
+ };
50
+ /** Bounded host notification of canonical facts. Reporting never changes them. */
51
+ const reported = (effect) => effect.pipe(Effect.interruptible, Effect.timeoutOrElse({
52
+ duration: 2e3,
53
+ orElse: () => Effect.void
54
+ }), Effect.ignore);
55
+ const defaultCleanupLimits = {
56
+ localStepMillis: 3e3,
57
+ releaseMillis: 4e3,
58
+ terminalMillis: 4e3
59
+ };
60
+ /**
61
+ * Close is one uninterruptible, bounded transaction over *local cleanup evidence*, not
62
+ * a transaction over the remote browser. Each step observes its own Exit so failures
63
+ * cannot suppress a later disconnect, release request, or exact-session status read.
64
+ */
65
+ const makeCleanup = Effect.fnUntraced(function* (reference, ownership, sessions, local, report, limits = defaultCleanupLimits) {
66
+ let latest;
67
+ return {
68
+ close: yield* Effect.cached(Effect.uninterruptible(Effect.gen(function* () {
69
+ const issues = [];
70
+ const step = (name, action, milliseconds) => action.pipe(Effect.interruptible, Effect.timeoutOrElse({
71
+ duration: milliseconds,
72
+ orElse: () => Effect.fail(CleanupIssue.make({
73
+ step: name,
74
+ reason: "timeout"
75
+ }))
76
+ }), Effect.exit, Effect.tap((exit) => Effect.sync(() => {
77
+ if (Exit.isSuccess(exit)) return;
78
+ const reason = Cause.findErrorOption(exit.cause);
79
+ issues.push(CleanupIssue.make({
80
+ step: name,
81
+ reason: Option.isSome(reason) && reason.value instanceof CleanupIssue ? reason.value.reason : Cause.hasInterrupts(exit.cause) ? "interrupted" : "failed"
82
+ }));
83
+ })));
84
+ yield* step("fence", local.fence, limits.localStepMillis);
85
+ yield* step("capture", local.capture, limits.localStepMillis);
86
+ yield* step("initialization", local.initialization, limits.localStepMillis);
87
+ const disconnected = yield* step("disconnect", local.disconnect, limits.localStepMillis);
88
+ const localState = Exit.isSuccess(disconnected) ? disconnected.value : "failed";
89
+ let releaseRequested = false;
90
+ let remote = ownership === "borrowed" ? "not-owned" : "unknown";
91
+ let observedStatus;
92
+ if (ownership === "owned") {
93
+ const requested = yield* step("release", sessions.requestRelease(reference), limits.releaseMillis);
94
+ releaseRequested = Exit.isSuccess(requested);
95
+ const terminal = yield* step("status", sessions.waitForTerminal(reference, { timeoutMillis: limits.terminalMillis }), limits.terminalMillis);
96
+ if (Exit.isSuccess(terminal)) {
97
+ remote = "confirmed";
98
+ observedStatus = terminal.value.status;
99
+ } else if (Exit.isSuccess(requested)) remote = "pending";
100
+ }
101
+ const result = CleanupResult.make({
102
+ reference,
103
+ ownership,
104
+ releaseRequested,
105
+ remote,
106
+ local: localState,
107
+ ...observedStatus === void 0 ? {} : { observedStatus },
108
+ issues
109
+ });
110
+ Object.freeze(result.issues);
111
+ latest = Object.freeze(result);
112
+ report(latest);
113
+ return latest;
114
+ }))),
115
+ result: Effect.sync(() => Option.fromNullishOr(latest))
116
+ };
117
+ });
118
+ //#endregion
119
+ //#region src/internal/session/Diagnostics.ts
120
+ /**
121
+ * Operator-visible evidence that a session's fate was not settled. It carries identity and
122
+ * outcome labels only: no provider body, connection URL, credential or page content. The
123
+ * transport deliberately disables tracing where credentials travel, so without this an
124
+ * unconfirmed release or an allocation of unknown outcome would leave no trace for anyone who
125
+ * did not register a callback.
126
+ */
127
+ var SessionUnsettled = class extends Data.TaggedError("BrowserbaseSessionUnsettled") {
128
+ [ErrorReporter.severity] = "Warn";
129
+ get [ErrorReporter.attributes]() {
130
+ return this.details;
131
+ }
132
+ };
133
+ const surface = (message, details) => Effect.logWarning(message).pipe(Effect.annotateLogs(details), Effect.andThen(ErrorReporter.report(Cause.fail(new SessionUnsettled({
134
+ message,
135
+ details
136
+ })))));
137
+ /** A borrowed scope never owns release, so only its local teardown can be unsettled. */
138
+ const reportCleanup = (result) => {
139
+ if (!(result.ownership === "owned" && (result.remote !== "confirmed" || !result.releaseRequested)) && result.local !== "failed" && result.issues.length === 0) return Effect.void;
140
+ return surface("Browserbase session cleanup ended without confirmation", {
141
+ projectId: result.reference.projectId,
142
+ sessionId: result.reference.sessionId,
143
+ ownership: result.ownership,
144
+ remote: result.remote,
145
+ local: result.local,
146
+ observedStatus: result.observedStatus ?? "unobserved",
147
+ issues: result.issues.map((issue) => `${issue.step}:${issue.reason}`).join(",") || "none"
148
+ });
149
+ };
150
+ /** The provider may have allocated a session this process has no reference for. */
151
+ const reportAllocationUncertain = (attempt) => surface("Browserbase allocation outcome is unknown", {
152
+ projectId: attempt.projectId,
153
+ attemptId: attempt.attemptId,
154
+ requestedAtMillis: attempt.requestedAtMillis
155
+ });
156
+ //#endregion
157
+ //#region src/internal/session/Acquisition.ts
158
+ const AllocatedIdentity = Schema.Struct({
159
+ id: Identifier,
160
+ projectId: Identifier
161
+ });
162
+ /**
163
+ * The remote lease is registered before POST. Local connection work is supplied by
164
+ * the same browser owner; the control plane never invents a second operation owner.
165
+ */
166
+ const acquireRemote = Effect.fnUntraced(function* (options, local = noLocalConnection, limits) {
167
+ const client = yield* BrowserbaseClient;
168
+ const sessions = yield* BrowserbaseSessions;
169
+ const parent = yield* Scope.Scope;
170
+ const launch = yield* compileLaunch(options.launch, {
171
+ projectId: client.projectId,
172
+ attemptId: globalThis.crypto.randomUUID(),
173
+ requestedAtMillis: yield* Clock.currentTimeMillis
174
+ });
175
+ const attempt = launch.attempt;
176
+ let writer;
177
+ if (launch.context?.persist) {
178
+ if (options.contextWriter === void 0) return yield* ContextError.make({
179
+ operation: "writer-authority",
180
+ reason: "authorization",
181
+ outcome: "undispatched"
182
+ });
183
+ writer = yield* requireContextWriterPermit(options.contextWriter, {
184
+ provider: "browserbase",
185
+ projectId: client.projectId,
186
+ contextId: launch.context.id
187
+ });
188
+ } else if (options.contextWriter !== void 0) return yield* ContextError.make({
189
+ operation: "writer-authority",
190
+ reason: "configuration",
191
+ outcome: "undispatched"
192
+ });
193
+ return yield* Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
194
+ const resourceScope = yield* Scope.make();
195
+ let reference;
196
+ let admitted = false;
197
+ let knownRejection = false;
198
+ let closing = false;
199
+ let cleanup;
200
+ let uncertainReported = false;
201
+ const allocationUncertain = Effect.suspend(() => {
202
+ if (uncertainReported) return Effect.void;
203
+ uncertainReported = true;
204
+ return reportAllocationUncertain(attempt).pipe(Effect.andThen(options.onAllocationUncertain === void 0 ? Effect.void : reported(options.onAllocationUncertain(attempt))));
205
+ });
206
+ const terminate = yield* Effect.cached(Effect.uninterruptible(Effect.gen(function* () {
207
+ closing = true;
208
+ if (reference === void 0) {
209
+ if (admitted && !knownRejection) {
210
+ writer?.uncertain(attempt);
211
+ yield* allocationUncertain;
212
+ }
213
+ return;
214
+ }
215
+ yield* (yield* makeCleanup(reference, "owned", sessions, local, (result) => {
216
+ cleanup = result;
217
+ writer?.completed(attempt, result);
218
+ }, limits)).close;
219
+ if (cleanup !== void 0) yield* reportCleanup(cleanup);
220
+ if (cleanup !== void 0 && options.onCleanup !== void 0) yield* reported(options.onCleanup(cleanup));
221
+ })));
222
+ const closeScope = yield* Effect.cached(Scope.close(resourceScope, Exit.void));
223
+ yield* Scope.addFinalizer(resourceScope, terminate);
224
+ yield* Scope.addFinalizer(parent, closeScope);
225
+ const failedAllocation = (error) => {
226
+ knownRejection = error.outcome === "rejected" || error.outcome === "undispatched";
227
+ if (knownRejection) writer?.rejected(attempt);
228
+ else writer?.uncertain(attempt);
229
+ const reason = error.reason;
230
+ return AllocationError.make({
231
+ attempt,
232
+ outcome: knownRejection ? "rejected" : "unknown",
233
+ reason: reason === "authorization" || reason === "rate-limited" || reason === "configuration" || reason === "transport" || reason === "timeout" || reason === "malformed" ? reason : "provider",
234
+ ...error.status === void 0 ? {} : { status: error.status },
235
+ ...error.retryAfterMillis === void 0 ? {} : { retryAfterMillis: error.retryAfterMillis }
236
+ });
237
+ };
238
+ return yield* Effect.gen(function* () {
239
+ if (writer !== void 0) yield* writer.recordAttempt(attempt);
240
+ admitted = true;
241
+ const raw = yield* restore(client.json("POST", "/v1/sessions", launch.body, options.allocationDeadline)).pipe(Effect.mapError(failedAllocation));
242
+ const identity = yield* Schema.decodeUnknownEffect(AllocatedIdentity)(raw).pipe(Effect.mapError(() => AllocationError.make({
243
+ attempt,
244
+ outcome: "unknown",
245
+ reason: "malformed"
246
+ })));
247
+ reference = Object.freeze(SessionReference.make({
248
+ provider: "browserbase",
249
+ projectId: identity.projectId,
250
+ sessionId: identity.id
251
+ }));
252
+ writer?.recordSession(attempt, reference);
253
+ if (reference.projectId !== client.projectId) return yield* AllocationError.make({
254
+ attempt,
255
+ reference,
256
+ outcome: "unknown",
257
+ reason: "malformed"
258
+ });
259
+ const ref = reference;
260
+ return {
261
+ reference: ref,
262
+ attempt,
263
+ launch,
264
+ resourceScope,
265
+ isClosed: () => closing,
266
+ connection: (timeoutMillis) => Effect.suspend(() => closing ? Effect.fail(SessionError.make({
267
+ operation: "session-connect",
268
+ reason: "expired",
269
+ outcome: "undispatched"
270
+ })) : connectionAddress(client, sessions, ref, timeoutMillis)),
271
+ release: closeScope.pipe(Effect.andThen(Effect.suspend(() => cleanup === void 0 ? Effect.die(/* @__PURE__ */ new Error("Owned session closed without cleanup evidence")) : Effect.succeed(cleanup)))),
272
+ cleanupResult: Effect.sync(() => Option.fromNullishOr(cleanup))
273
+ };
274
+ }).pipe(Effect.onError(() => closeScope), Effect.onInterrupt(() => closeScope));
275
+ }));
276
+ });
277
+ //#endregion
278
+ export { reported as a, noLocalConnection as i, reportCleanup as n, connectionAddress as o, makeCleanup as r, acquireRemote as t };
279
+
280
+ //# sourceMappingURL=Acquisition-WBafHwXH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Acquisition-WBafHwXH.mjs","names":[],"sources":["../src/internal/provider/Connection.ts","../src/internal/session/Cleanup.ts","../src/internal/session/Diagnostics.ts","../src/internal/session/Acquisition.ts"],"sourcesContent":["import { Effect, Redacted, Schema } from \"effect\";\n\nimport type { BrowserbaseClient } from \"../../Client.ts\";\nimport { SessionError } from \"../../Errors.ts\";\nimport { SessionReference } from \"../../References.ts\";\nimport { ProviderSession } from \"../../SessionData.ts\";\nimport type { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { deadlineAfter, nowMillis, until } from \"../Deadline.ts\";\n\nconst Connection = Schema.Struct({\n ...ProviderSession.fields,\n connectUrl: Schema.String.check(Schema.isMaxLength(16384)),\n});\n\n/** A provider-issued endpoint is authority, not a persisted session identifier. */\nexport const connectionUrl = Schema.String.check(\n Schema.isMaxLength(16384),\n Schema.makeFilter((value) => {\n try {\n const url = new URL(value);\n\n return (\n url.protocol === \"wss:\" &&\n !url.username &&\n !url.password &&\n !url.port &&\n !url.hash &&\n url.hostname.endsWith(\".browserbase.com\")\n );\n } catch {\n return false;\n }\n }),\n);\n\nexport const connectionAddress = Effect.fnUntraced(function* (\n client: BrowserbaseClient[\"Service\"],\n sessions: BrowserbaseSessions[\"Service\"],\n reference: SessionReference,\n timeoutMillis: number,\n) {\n const fail = (reason: SessionError[\"reason\"]) =>\n SessionError.make({ operation: \"session-connect\", reason });\n\n const ref = yield* Schema.decodeEffect(SessionReference)(reference).pipe(\n Effect.mapError(() => fail(\"configuration\")),\n );\n\n if (ref.projectId !== client.projectId) return yield* fail(\"authorization\");\n const deadline = yield* deadlineAfter(timeoutMillis);\n\n yield* sessions.waitUntilRunning(ref, { timeoutMillis });\n if ((yield* nowMillis) >= deadline) return yield* fail(\"timeout\");\n\n const raw = yield* until(\n client.json(\"GET\", `/v1/sessions/${encodeURIComponent(ref.sessionId)}`, undefined, deadline),\n deadline,\n () => fail(\"timeout\"),\n ).pipe(Effect.mapError((error) => fail(error.reason)));\n\n const value = yield* Schema.decodeUnknownEffect(Connection)(raw).pipe(\n Effect.mapError(() => fail(\"malformed\")),\n );\n\n if (value.id !== ref.sessionId || value.projectId !== ref.projectId)\n return yield* fail(\"malformed\");\n if (value.status !== \"RUNNING\") return yield* fail(\"expired\");\n\n const url = yield* Schema.decodeEffect(connectionUrl)(value.connectUrl).pipe(\n Effect.mapError(() => fail(\"unsafe-url\")),\n );\n\n return Redacted.make(url);\n});\n","import { Cause, Effect, Exit, Option } from \"effect\";\n\nimport { CleanupIssue, CleanupResult } from \"../../Cleanup.ts\";\nimport type { BrowserError, InitializationError } from \"../../Errors.ts\";\nimport type { SessionReference } from \"../../References.ts\";\nimport type { SessionStatus } from \"../../SessionData.ts\";\nimport type { BrowserbaseSessions } from \"../../Sessions.ts\";\n\n/** All effects are captured by the owning connection; no native value is exported. */\nexport interface LocalCleanup {\n readonly fence: Effect.Effect<void>;\n readonly capture: Effect.Effect<void, BrowserError>;\n readonly initialization: Effect.Effect<void, BrowserError | InitializationError>;\n readonly disconnect: Effect.Effect<CleanupResult[\"local\"], BrowserError>;\n}\n\nexport const noLocalConnection: LocalCleanup = {\n fence: Effect.void,\n capture: Effect.void,\n initialization: Effect.void,\n disconnect: Effect.succeed(\"not-connected\"),\n};\n\n/** Bounded host notification of canonical facts. Reporting never changes them. */\nexport const reported = <A, E>(effect: Effect.Effect<A, E>) =>\n effect.pipe(\n Effect.interruptible,\n Effect.timeoutOrElse({ duration: 2000, orElse: () => Effect.void }),\n Effect.ignore,\n );\n\n/** Internal limits, also injectable by deterministic failure tests. */\nexport interface CleanupLimits {\n readonly localStepMillis: number;\n readonly releaseMillis: number;\n readonly terminalMillis: number;\n}\n\nexport const defaultCleanupLimits: CleanupLimits = {\n localStepMillis: 3000,\n releaseMillis: 4000,\n terminalMillis: 4000,\n};\n\n/**\n * Close is one uninterruptible, bounded transaction over *local cleanup evidence*, not\n * a transaction over the remote browser. Each step observes its own Exit so failures\n * cannot suppress a later disconnect, release request, or exact-session status read.\n */\nexport const makeCleanup = Effect.fnUntraced(function* (\n reference: SessionReference,\n ownership: CleanupResult[\"ownership\"],\n sessions: BrowserbaseSessions[\"Service\"],\n local: LocalCleanup,\n report: (result: CleanupResult) => void,\n limits: CleanupLimits = defaultCleanupLimits,\n) {\n let latest: CleanupResult | undefined;\n\n const close = yield* Effect.cached(\n Effect.uninterruptible(\n Effect.gen(function* () {\n const issues: CleanupIssue[] = [];\n\n const step = <A, E>(\n name: CleanupIssue[\"step\"],\n action: Effect.Effect<A, E>,\n milliseconds: number,\n ) =>\n action.pipe(\n Effect.interruptible,\n Effect.timeoutOrElse({\n duration: milliseconds,\n orElse: () => Effect.fail(CleanupIssue.make({ step: name, reason: \"timeout\" })),\n }),\n Effect.exit,\n Effect.tap((exit) =>\n Effect.sync(() => {\n if (Exit.isSuccess(exit)) return;\n const reason = Cause.findErrorOption(exit.cause);\n\n issues.push(\n CleanupIssue.make({\n step: name,\n reason:\n Option.isSome(reason) && reason.value instanceof CleanupIssue\n ? reason.value.reason\n : Cause.hasInterrupts(exit.cause)\n ? \"interrupted\"\n : \"failed\",\n }),\n );\n }),\n ),\n );\n\n // The fence runs synchronously before interruptible native teardown begins.\n yield* step(\"fence\", local.fence, limits.localStepMillis);\n yield* step(\"capture\", local.capture, limits.localStepMillis);\n yield* step(\"initialization\", local.initialization, limits.localStepMillis);\n const disconnected = yield* step(\"disconnect\", local.disconnect, limits.localStepMillis);\n const localState = Exit.isSuccess(disconnected) ? disconnected.value : \"failed\";\n\n let releaseRequested = false;\n let remote: CleanupResult[\"remote\"] = ownership === \"borrowed\" ? \"not-owned\" : \"unknown\";\n let observedStatus: SessionStatus | undefined;\n\n if (ownership === \"owned\") {\n const requested = yield* step(\n \"release\",\n sessions.requestRelease(reference),\n limits.releaseMillis,\n );\n\n releaseRequested = Exit.isSuccess(requested);\n\n // A POST response is never substituted for a passive terminal-state observation.\n const terminal = yield* step(\n \"status\",\n sessions.waitForTerminal(reference, { timeoutMillis: limits.terminalMillis }),\n limits.terminalMillis,\n );\n\n if (Exit.isSuccess(terminal)) {\n remote = \"confirmed\";\n observedStatus = terminal.value.status;\n } else if (Exit.isSuccess(requested)) {\n remote = \"pending\";\n }\n }\n\n const result = CleanupResult.make({\n reference,\n ownership,\n releaseRequested,\n remote,\n local: localState,\n ...(observedStatus === undefined ? {} : { observedStatus }),\n issues,\n });\n\n Object.freeze(result.issues);\n latest = Object.freeze(result);\n report(latest);\n\n return latest;\n }),\n ),\n );\n\n return {\n close,\n result: Effect.sync(() => Option.fromNullishOr(latest)),\n };\n});\n","import { Cause, Data, Effect, ErrorReporter } from \"effect\";\n\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport type { AllocationAttempt } from \"../../References.ts\";\n\n/**\n * Operator-visible evidence that a session's fate was not settled. It carries identity and\n * outcome labels only: no provider body, connection URL, credential or page content. The\n * transport deliberately disables tracing where credentials travel, so without this an\n * unconfirmed release or an allocation of unknown outcome would leave no trace for anyone who\n * did not register a callback.\n */\nclass SessionUnsettled extends Data.TaggedError(\"BrowserbaseSessionUnsettled\")<{\n readonly message: string;\n readonly details: Readonly<Record<string, string | number>>;\n}> {\n readonly [ErrorReporter.severity] = \"Warn\" as const;\n\n get [ErrorReporter.attributes]() {\n return this.details;\n }\n}\n\nconst surface = (message: string, details: Readonly<Record<string, string | number>>) =>\n Effect.logWarning(message).pipe(\n Effect.annotateLogs(details),\n Effect.andThen(ErrorReporter.report(Cause.fail(new SessionUnsettled({ message, details })))),\n );\n\n/** A borrowed scope never owns release, so only its local teardown can be unsettled. */\nexport const reportCleanup = (result: CleanupResult): Effect.Effect<void> => {\n const remoteUnsettled =\n result.ownership === \"owned\" && (result.remote !== \"confirmed\" || !result.releaseRequested);\n\n if (!remoteUnsettled && result.local !== \"failed\" && result.issues.length === 0)\n return Effect.void;\n\n return surface(\"Browserbase session cleanup ended without confirmation\", {\n projectId: result.reference.projectId,\n sessionId: result.reference.sessionId,\n ownership: result.ownership,\n remote: result.remote,\n local: result.local,\n observedStatus: result.observedStatus ?? \"unobserved\",\n issues: result.issues.map((issue) => `${issue.step}:${issue.reason}`).join(\",\") || \"none\",\n });\n};\n\n/** The provider may have allocated a session this process has no reference for. */\nexport const reportAllocationUncertain = (attempt: AllocationAttempt): Effect.Effect<void> =>\n surface(\"Browserbase allocation outcome is unknown\", {\n projectId: attempt.projectId,\n attemptId: attempt.attemptId,\n requestedAtMillis: attempt.requestedAtMillis,\n });\n","import { Clock, Effect, Exit, Option, Schema, Scope } from \"effect\";\n\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport { BrowserbaseClient } from \"../../Client.ts\";\nimport { AllocationError, ContextError, type ClientError, SessionError } from \"../../Errors.ts\";\nimport type { LaunchRecipe } from \"../../Launch.ts\";\nimport { type AllocationAttempt, Identifier, SessionReference } from \"../../References.ts\";\nimport { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { connectionAddress } from \"../provider/Connection.ts\";\nimport { compileLaunch } from \"../provider/Launch.ts\";\nimport {\n makeCleanup,\n noLocalConnection,\n reported,\n type CleanupLimits,\n type LocalCleanup,\n} from \"./Cleanup.ts\";\nimport { requireContextWriterPermit, type ContextWriterPermitInternal } from \"./ContextWriter.ts\";\nimport { reportAllocationUncertain, reportCleanup } from \"./Diagnostics.ts\";\nimport type { ContextWriterPermit } from \"./WriterFacts.ts\";\n\nconst AllocatedIdentity = Schema.Struct({ id: Identifier, projectId: Identifier });\n\nexport interface AcquisitionOptions {\n readonly launch: LaunchRecipe;\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 * The remote lease is registered before POST. Local connection work is supplied by\n * the same browser owner; the control plane never invents a second operation owner.\n */\nexport const acquireRemote = Effect.fnUntraced(function* (\n options: AcquisitionOptions,\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\n const launch = yield* compileLaunch(options.launch, {\n projectId: client.projectId,\n attemptId: globalThis.crypto.randomUUID(),\n requestedAtMillis: yield* Clock.currentTimeMillis,\n });\n\n const attempt = launch.attempt;\n let writer: ContextWriterPermitInternal | undefined;\n\n if (launch.context?.persist) {\n if (options.contextWriter === undefined) {\n return yield* ContextError.make({\n operation: \"writer-authority\",\n reason: \"authorization\",\n outcome: \"undispatched\",\n });\n }\n writer = yield* requireContextWriterPermit(options.contextWriter, {\n provider: \"browserbase\",\n projectId: client.projectId,\n contextId: launch.context.id,\n });\n } else if (options.contextWriter !== undefined) {\n return yield* ContextError.make({\n operation: \"writer-authority\",\n reason: \"configuration\",\n outcome: \"undispatched\",\n });\n }\n\n return yield* Effect.uninterruptibleMask((restore) =>\n Effect.gen(function* () {\n const resourceScope = yield* Scope.make();\n let reference: SessionReference | undefined;\n let admitted = false;\n let knownRejection = false;\n let closing = false;\n let cleanup: CleanupResult | undefined;\n\n let uncertainReported = false;\n\n const allocationUncertain = Effect.suspend(() => {\n if (uncertainReported) return Effect.void;\n uncertainReported = true;\n\n return reportAllocationUncertain(attempt).pipe(\n Effect.andThen(\n options.onAllocationUncertain === undefined\n ? Effect.void\n : reported(options.onAllocationUncertain(attempt)),\n ),\n );\n });\n\n const terminate = yield* Effect.cached(\n Effect.uninterruptible(\n Effect.gen(function* () {\n closing = true;\n if (reference === undefined) {\n if (admitted && !knownRejection) {\n writer?.uncertain(attempt);\n yield* allocationUncertain;\n }\n\n return;\n }\n\n const coordinator = yield* makeCleanup(\n reference,\n \"owned\",\n sessions,\n local,\n (result) => {\n cleanup = result;\n writer?.completed(attempt, result);\n },\n limits,\n );\n\n yield* coordinator.close;\n if (cleanup !== undefined) yield* reportCleanup(cleanup);\n if (cleanup !== undefined && options.onCleanup !== undefined)\n yield* reported(options.onCleanup(cleanup));\n }),\n ),\n );\n\n const closeScope = yield* Effect.cached(Scope.close(resourceScope, Exit.void));\n\n yield* Scope.addFinalizer(resourceScope, terminate);\n yield* Scope.addFinalizer(parent, closeScope);\n\n const failedAllocation = (error: ClientError): AllocationError => {\n knownRejection = error.outcome === \"rejected\" || error.outcome === \"undispatched\";\n if (knownRejection) writer?.rejected(attempt);\n else writer?.uncertain(attempt);\n const reason = error.reason;\n\n return AllocationError.make({\n attempt,\n outcome: knownRejection ? \"rejected\" : \"unknown\",\n reason:\n reason === \"authorization\" ||\n reason === \"rate-limited\" ||\n reason === \"configuration\" ||\n reason === \"transport\" ||\n reason === \"timeout\" ||\n reason === \"malformed\"\n ? reason\n : \"provider\",\n ...(error.status === undefined ? {} : { status: error.status }),\n ...(error.retryAfterMillis === undefined\n ? {}\n : { retryAfterMillis: error.retryAfterMillis }),\n });\n };\n\n const allocate = Effect.gen(function* () {\n if (writer !== undefined) yield* writer.recordAttempt(attempt);\n admitted = true;\n\n const raw = yield* restore(\n client.json(\"POST\", \"/v1/sessions\", launch.body, options.allocationDeadline),\n ).pipe(Effect.mapError(failedAllocation));\n\n const identity = yield* Schema.decodeUnknownEffect(AllocatedIdentity)(raw).pipe(\n Effect.mapError(() =>\n AllocationError.make({ attempt, outcome: \"unknown\", reason: \"malformed\" }),\n ),\n );\n\n // Save identity before interpreting any connection credentials or provider metadata.\n reference = Object.freeze(\n SessionReference.make({\n provider: \"browserbase\",\n projectId: identity.projectId,\n sessionId: identity.id,\n }),\n );\n writer?.recordSession(attempt, reference);\n if (reference.projectId !== client.projectId) {\n return yield* AllocationError.make({\n attempt,\n reference,\n outcome: \"unknown\",\n reason: \"malformed\",\n });\n }\n const ref = reference;\n\n return {\n reference: ref,\n attempt,\n launch,\n resourceScope,\n isClosed: () => closing,\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 : connectionAddress(client, sessions, ref, timeoutMillis),\n ),\n release: closeScope.pipe(\n Effect.andThen(\n Effect.suspend(() =>\n cleanup === undefined\n ? Effect.die(new Error(\"Owned session closed without cleanup evidence\"))\n : Effect.succeed(cleanup),\n ),\n ),\n ),\n cleanupResult: Effect.sync(() => Option.fromNullishOr(cleanup)),\n };\n });\n\n return yield* allocate.pipe(\n Effect.onError(() => closeScope),\n Effect.onInterrupt(() => closeScope),\n );\n }),\n );\n});\n\nexport type RemoteAcquisition = Effect.Success<ReturnType<typeof acquireRemote>>;\n"],"mappings":";;;;;;;;;;;AASA,MAAM,aAAa,OAAO,OAAO;CAC/B,GAAG,gBAAgB;CACnB,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,KAAK,CAAC;AAC3D,CAAC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B,QAAQ,UAAU,KAAK,aAAa,CAC5D;IACF,SAAS,WAAW,KAClB,OAAO,QACL,OAAO,cACL,YAAY,KAAA,IACR,OAAO,oBAAI,IAAI,MAAM,+CAA+C,CAAC,IACrE,OAAO,QAAQ,OAAO,CAC5B,CACF,CACF;IACA,eAAe,OAAO,WAAW,OAAO,cAAc,OAAO,CAAC;GAChE;EACF,CAEqB,CAAC,CAAC,KACrB,OAAO,cAAc,UAAU,GAC/B,OAAO,kBAAkB,UAAU,CACrC;CACF,CAAC,CACH;AACF,CAAC"}
@@ -0,0 +1,156 @@
1
+ import { n as ContextReference } from "./References-URDAtapt.mjs";
2
+ import { PlatformError } from "./Errors.mjs";
3
+ import { t as BrowserbaseClient } from "./Client-Ca0zSg1n.mjs";
4
+ import { Context, Effect, Layer, Schema } from "effect";
5
+ declare namespace Agents_d_exports {
6
+ export { AgentDefinition, AgentListQuery, AgentMessageQuery, AgentMessages, AgentMetadata, AgentRun, AgentRunListQuery, AgentRunMessage, AgentRunRequest, AgentRunStatus, AgentRunWaitOptions, AgentUpdate, BrowserbaseAgents, Page, isTerminalAgentRunStatus };
7
+ }
8
+ export declare const AgentRunStatus: Schema.Literals<readonly ["PENDING", "RUNNING", "COMPLETED", "FAILED", "STOPPED", "TIMED_OUT"]>;
9
+ export type AgentRunStatus = typeof AgentRunStatus.Type;
10
+ export declare const isTerminalAgentRunStatus: (status: AgentRunStatus) => boolean;
11
+ declare const AgentMetadata_base: Schema.Class<AgentMetadata, Schema.Struct<{
12
+ readonly agentId: Schema.NonEmptyString;
13
+ readonly name: Schema.String;
14
+ readonly systemPrompt: Schema.optionalKey<Schema.String>;
15
+ readonly resultSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
16
+ readonly createdAt: Schema.String;
17
+ readonly updatedAt: Schema.String;
18
+ }>, {}>;
19
+ export declare class AgentMetadata extends AgentMetadata_base {}
20
+ declare const AgentRun_base: Schema.Class<AgentRun, Schema.Struct<{
21
+ readonly runId: Schema.NonEmptyString;
22
+ readonly agentId: Schema.optionalKey<Schema.NonEmptyString>;
23
+ readonly task: Schema.String;
24
+ readonly status: Schema.Literals<readonly ["PENDING", "RUNNING", "COMPLETED", "FAILED", "STOPPED", "TIMED_OUT"]>;
25
+ readonly sessionId: Schema.optionalKey<Schema.NonEmptyString>;
26
+ readonly sandboxId: Schema.optionalKey<Schema.String>;
27
+ readonly resultSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
28
+ readonly result: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
29
+ readonly cause: Schema.optionalKey<Schema.Struct<{
30
+ readonly code: Schema.String;
31
+ readonly message: Schema.optionalKey<Schema.String>;
32
+ }>>;
33
+ readonly startedAt: Schema.optionalKey<Schema.String>;
34
+ readonly endedAt: Schema.optionalKey<Schema.String>;
35
+ readonly createdAt: Schema.String;
36
+ readonly updatedAt: Schema.String;
37
+ }>, {}>;
38
+ export declare class AgentRun extends AgentRun_base {}
39
+ declare const AgentRunMessage_base: Schema.Class<AgentRunMessage, Schema.Struct<{
40
+ readonly id: Schema.String;
41
+ readonly createdAt: Schema.String;
42
+ readonly role: Schema.Literals<readonly ["assistant", "tool"]>;
43
+ readonly content: Schema.Codec<Schema.Json, Schema.Json, never, never>;
44
+ }>, {}>;
45
+ export declare class AgentRunMessage extends AgentRunMessage_base {}
46
+ export declare const AgentDefinition: Schema.Struct<{
47
+ readonly name: Schema.NonEmptyString;
48
+ readonly systemPrompt: Schema.optionalKey<Schema.String>;
49
+ readonly resultSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
50
+ }>;
51
+ export type AgentDefinition = typeof AgentDefinition.Type;
52
+ export declare const AgentUpdate: Schema.Struct<{
53
+ readonly name: Schema.optionalKey<Schema.NonEmptyString>;
54
+ readonly systemPrompt: Schema.optionalKey<Schema.String>;
55
+ readonly resultSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
56
+ }>;
57
+ export type AgentUpdate = typeof AgentUpdate.Type;
58
+ export declare const AgentRunRequest: Schema.Struct<{
59
+ readonly task: Schema.NonEmptyString;
60
+ readonly agentId: Schema.optionalKey<Schema.NonEmptyString>;
61
+ readonly resultSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
62
+ readonly variables: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
63
+ readonly value: Schema.String;
64
+ readonly description: Schema.optionalKey<Schema.String>;
65
+ }>>>;
66
+ readonly browserSettings: Schema.optionalKey<Schema.Struct<{
67
+ /**
68
+ * A persisting run writes the Context from Browserbase's side, outside
69
+ * `ContextCoordination.withWriter`. It is refused while a local writer holds the
70
+ * Context, but nothing stops a later local writer from racing the hosted run.
71
+ */
72
+ readonly context: Schema.optionalKey<Schema.Struct<{
73
+ readonly reference: typeof ContextReference;
74
+ readonly persist: Schema.Boolean;
75
+ }>>;
76
+ readonly proxies: Schema.optionalKey<Schema.Union<readonly [Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
77
+ readonly type: Schema.Literal<"browserbase">;
78
+ readonly domainPattern: Schema.optionalKey<Schema.NonEmptyString>;
79
+ readonly geolocation: Schema.optionalKey<Schema.Struct<{
80
+ readonly country: Schema.String;
81
+ readonly state: Schema.optionalKey<Schema.String>;
82
+ readonly city: Schema.optionalKey<Schema.NonEmptyString>;
83
+ }>>;
84
+ }>, Schema.Struct<{
85
+ readonly type: Schema.Literal<"external">;
86
+ readonly server: Schema.NonEmptyString;
87
+ readonly domainPattern: Schema.optionalKey<Schema.NonEmptyString>;
88
+ readonly username: Schema.optionalKey<Schema.Redacted<Schema.String>>;
89
+ readonly password: Schema.optionalKey<Schema.Redacted<Schema.String>>;
90
+ }>, Schema.Struct<{
91
+ readonly type: Schema.Literal<"none">;
92
+ readonly domainPattern: Schema.optionalKey<Schema.NonEmptyString>;
93
+ }>]>>]>>;
94
+ readonly verified: Schema.optionalKey<Schema.Boolean>;
95
+ }>>;
96
+ }>;
97
+ export type AgentRunRequest = typeof AgentRunRequest.Type;
98
+ export declare const AgentListQuery: Schema.Struct<{
99
+ readonly startAt: Schema.optionalKey<Schema.String>;
100
+ readonly endAt: Schema.optionalKey<Schema.String>;
101
+ readonly cursor: Schema.optionalKey<Schema.NonEmptyString>;
102
+ readonly limit: Schema.optionalKey<Schema.Int>;
103
+ }>;
104
+ export type AgentListQuery = typeof AgentListQuery.Type;
105
+ export declare const AgentRunListQuery: Schema.Struct<{
106
+ readonly startAt: Schema.optionalKey<Schema.String>;
107
+ readonly endAt: Schema.optionalKey<Schema.String>;
108
+ readonly cursor: Schema.optionalKey<Schema.NonEmptyString>;
109
+ readonly status: Schema.optionalKey<Schema.Literals<readonly ["PENDING", "RUNNING", "COMPLETED", "FAILED", "STOPPED", "TIMED_OUT"]>>;
110
+ readonly agentId: Schema.optionalKey<Schema.NonEmptyString>;
111
+ readonly limit: Schema.optionalKey<Schema.Int>;
112
+ }>;
113
+ export type AgentRunListQuery = typeof AgentRunListQuery.Type;
114
+ export declare const AgentMessageQuery: Schema.Struct<{
115
+ readonly since: Schema.optionalKey<Schema.NonEmptyString>;
116
+ readonly limit: Schema.optionalKey<Schema.Int>;
117
+ readonly all: Schema.optionalKey<Schema.Boolean>;
118
+ }>;
119
+ export type AgentMessageQuery = typeof AgentMessageQuery.Type;
120
+ export declare const AgentRunWaitOptions: Schema.Struct<{
121
+ readonly timeoutMillis: Schema.Int;
122
+ readonly pollIntervalMillis: Schema.optionalKey<Schema.Int>;
123
+ }>;
124
+ export type AgentRunWaitOptions = typeof AgentRunWaitOptions.Type;
125
+ export interface Page<A> {
126
+ readonly items: ReadonlyArray<A>;
127
+ readonly nextCursor: string | undefined;
128
+ }
129
+ export interface AgentMessages {
130
+ readonly messages: ReadonlyArray<AgentRunMessage>;
131
+ readonly nextSince: string | undefined;
132
+ }
133
+ declare const BrowserbaseAgents_base: Context.ServiceClass<BrowserbaseAgents, "effect-browserbase/Agents", {
134
+ readonly create: (definition: AgentDefinition) => Effect.Effect<AgentMetadata, PlatformError>;
135
+ readonly list: (query?: AgentListQuery) => Effect.Effect<Page<AgentMetadata>, PlatformError>;
136
+ readonly retrieve: (agentId: string) => Effect.Effect<AgentMetadata, PlatformError>;
137
+ readonly update: (agentId: string, update: AgentUpdate) => Effect.Effect<AgentMetadata, PlatformError>;
138
+ readonly delete: (agentId: string) => Effect.Effect<void, PlatformError>;
139
+ readonly run: (request: AgentRunRequest) => Effect.Effect<AgentRun, PlatformError>;
140
+ readonly retrieveRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;
141
+ readonly listRuns: (query?: AgentRunListQuery) => Effect.Effect<Page<AgentRun>, PlatformError>;
142
+ readonly stopRun: (runId: string) => Effect.Effect<AgentRun, PlatformError>;
143
+ readonly messages: (runId: string, query?: AgentMessageQuery) => Effect.Effect<AgentMessages, PlatformError>;
144
+ /** Polls until the run is terminal. Interrupting the wait does not stop the run. */
145
+ readonly waitForRun: (runId: string, options: AgentRunWaitOptions) => Effect.Effect<AgentRun, PlatformError>;
146
+ }>;
147
+ /**
148
+ * Browserbase Agents: hosted autonomous runs that allocate their own browser sessions and
149
+ * bill inference. Creating or stopping a run is never retried; a lost reply is `unknown`.
150
+ */
151
+ export declare class BrowserbaseAgents extends BrowserbaseAgents_base {
152
+ static readonly layer: Layer.Layer<BrowserbaseAgents, never, BrowserbaseClient>;
153
+ }
154
+ //#endregion
155
+ export { Agents_d_exports as t };
156
+ //# sourceMappingURL=Agents.d.mts.map