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,332 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { ContextReference, Identifier } from "./References.mjs";
3
+ import { PlatformError } from "./Errors.mjs";
4
+ import { t as BrowserbaseClient } from "./Client-D1_xYM9o.mjs";
5
+ import { t as resource } from "./Resource-DBksC4zB.mjs";
6
+ import { ProxyRule } from "./Launch.mjs";
7
+ import { n as proxy } from "./Launch-BHcAEq05.mjs";
8
+ import { n as isContextWriterBusy } from "./ContextWriter-BrQmoXRg.mjs";
9
+ import { Clock, Context, Effect, Layer, Schema } from "effect";
10
+ //#region src/Functions.ts
11
+ var Functions_exports = /* @__PURE__ */ __exportAll({
12
+ BrowserbaseFunctions: () => BrowserbaseFunctions,
13
+ FunctionBuild: () => FunctionBuild,
14
+ FunctionInvocation: () => FunctionInvocation,
15
+ FunctionInvokeRequest: () => FunctionInvokeRequest,
16
+ FunctionLogLine: () => FunctionLogLine,
17
+ FunctionMetadata: () => FunctionMetadata,
18
+ FunctionPageQuery: () => FunctionPageQuery,
19
+ FunctionSessionParams: () => FunctionSessionParams,
20
+ FunctionStatusQuery: () => FunctionStatusQuery,
21
+ FunctionVersion: () => FunctionVersion,
22
+ FunctionWaitOptions: () => FunctionWaitOptions
23
+ });
24
+ const Timestamp = Schema.String.check(Schema.isMaxLength(64));
25
+ const JsonObject = Schema.Record(Schema.String, Schema.Json);
26
+ const Name = Schema.String.check(Schema.isMaxLength(1024));
27
+ const Status = Schema.Literals([
28
+ "PENDING",
29
+ "RUNNING",
30
+ "COMPLETED",
31
+ "FAILED"
32
+ ]);
33
+ var FunctionMetadata = class extends Schema.Class("BrowserbaseFunctionMetadata")({
34
+ id: Identifier,
35
+ projectId: Identifier,
36
+ name: Name,
37
+ createdAt: Timestamp,
38
+ updatedAt: Timestamp
39
+ }) {};
40
+ var FunctionVersion = class extends Schema.Class("BrowserbaseFunctionVersion")({
41
+ id: Identifier,
42
+ projectId: Identifier,
43
+ functionId: Identifier,
44
+ functionBuildId: Identifier,
45
+ sessionCreateParams: Schema.optionalKey(JsonObject),
46
+ userParamsSchema: Schema.optionalKey(JsonObject),
47
+ createdAt: Timestamp,
48
+ updatedAt: Timestamp
49
+ }) {};
50
+ var FunctionBuild = class extends Schema.Class("BrowserbaseFunctionBuild")({
51
+ id: Identifier,
52
+ projectId: Identifier,
53
+ request: Schema.Struct({
54
+ entrypoint: Name,
55
+ functionNames: Schema.optionalKey(Schema.Array(Name).check(Schema.isMaxLength(1024)))
56
+ }),
57
+ status: Status,
58
+ createdAt: Timestamp,
59
+ updatedAt: Timestamp,
60
+ startedAt: Timestamp,
61
+ endedAt: Schema.optionalKey(Timestamp),
62
+ expiresAt: Timestamp,
63
+ cause: Schema.optionalKey(Schema.Struct({
64
+ code: Schema.String.check(Schema.isMaxLength(64)),
65
+ message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(4096)))
66
+ }))
67
+ }) {};
68
+ var FunctionInvocation = class extends Schema.Class("BrowserbaseFunctionInvocation")({
69
+ id: Identifier,
70
+ projectId: Identifier,
71
+ functionId: Identifier,
72
+ versionId: Identifier,
73
+ sessionId: Identifier,
74
+ region: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(64))),
75
+ params: Schema.optionalKey(JsonObject),
76
+ status: Status,
77
+ results: Schema.optionalKey(Schema.Json),
78
+ cause: Schema.optionalKey(Schema.Struct({
79
+ code: Schema.String.check(Schema.isMaxLength(64)),
80
+ message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(4096)))
81
+ })),
82
+ createdAt: Timestamp,
83
+ updatedAt: Timestamp,
84
+ startedAt: Timestamp,
85
+ endedAt: Schema.optionalKey(Timestamp),
86
+ expiresAt: Timestamp
87
+ }) {};
88
+ var FunctionLogLine = class extends Schema.Class("BrowserbaseFunctionLogLine")({
89
+ message: Schema.String.check(Schema.isMaxLength(65536)),
90
+ timestamp: Schema.Finite
91
+ }) {};
92
+ /** The session a Function invocation runs in; the provider's invoke-time subset. */
93
+ const FunctionSessionParams = Schema.Struct({
94
+ /** Seconds, 60–900; the provider defaults to 900. */
95
+ timeout: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
96
+ minimum: 60,
97
+ maximum: 900
98
+ }))),
99
+ extensionId: Schema.optionalKey(Identifier),
100
+ context: Schema.optionalKey(Schema.Struct({
101
+ reference: ContextReference,
102
+ persist: Schema.Boolean
103
+ })),
104
+ proxies: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Array(ProxyRule).check(Schema.isMaxLength(64))])),
105
+ proxySettings: Schema.optionalKey(Schema.Struct({ caCertificates: Schema.optionalKey(Schema.Array(Identifier).check(Schema.isMaxLength(64), Schema.isUnique())) })),
106
+ userMetadata: Schema.optionalKey(Schema.Record(Schema.String.check(Schema.isMaxLength(128)), Schema.Json)),
107
+ browserSettings: Schema.optionalKey(Schema.Struct({
108
+ viewport: Schema.optionalKey(Schema.Struct({
109
+ width: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
110
+ minimum: 1,
111
+ maximum: 8192
112
+ }))),
113
+ height: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
114
+ minimum: 1,
115
+ maximum: 8192
116
+ })))
117
+ })),
118
+ blockAds: Schema.optionalKey(Schema.Boolean),
119
+ solveCaptchas: Schema.optionalKey(Schema.Boolean),
120
+ recordSession: Schema.optionalKey(Schema.Boolean),
121
+ logSession: Schema.optionalKey(Schema.Boolean),
122
+ verified: Schema.optionalKey(Schema.Boolean),
123
+ captchaImageSelector: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(1024))),
124
+ captchaInputSelector: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(1024))),
125
+ os: Schema.optionalKey(Schema.Literals([
126
+ "windows",
127
+ "mac",
128
+ "linux",
129
+ "mobile",
130
+ "tablet"
131
+ ])),
132
+ size: Schema.optionalKey(Schema.Literals([
133
+ "small",
134
+ "medium",
135
+ "large"
136
+ ])),
137
+ enableNativeSelectPolyfill: Schema.optionalKey(Schema.Boolean),
138
+ enablePdfViewer: Schema.optionalKey(Schema.Boolean),
139
+ extensions: Schema.optionalKey(Schema.Array(Schema.Literals(["onepassword", "browser-events"])).check(Schema.isUnique())),
140
+ allowedDomains: Schema.optionalKey(Schema.Array(Schema.NonEmptyString.check(Schema.isMaxLength(1024))).check(Schema.isMaxLength(64), Schema.isUnique())),
141
+ ignoreCertificateErrors: Schema.optionalKey(Schema.Boolean)
142
+ }))
143
+ });
144
+ const FunctionInvokeRequest = Schema.Struct({
145
+ params: Schema.optionalKey(JsonObject),
146
+ session: Schema.optionalKey(FunctionSessionParams)
147
+ });
148
+ const Offset = {
149
+ offset: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
150
+ minimum: 0,
151
+ maximum: 1e6
152
+ }))),
153
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
154
+ minimum: 1,
155
+ maximum: 100
156
+ })))
157
+ };
158
+ const FunctionPageQuery = Schema.Struct(Offset);
159
+ const FunctionStatusQuery = Schema.Struct({
160
+ ...Offset,
161
+ status: Schema.optionalKey(Status)
162
+ });
163
+ const FunctionWaitOptions = Schema.Struct({
164
+ timeoutMillis: Schema.Int.check(Schema.isBetween({
165
+ minimum: 1,
166
+ maximum: 36e5
167
+ })),
168
+ pollIntervalMillis: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
169
+ minimum: 250,
170
+ maximum: 6e4
171
+ })))
172
+ });
173
+ const DataPage = (item) => Schema.Struct({
174
+ data: Schema.Array(item).check(Schema.isMaxLength(100)),
175
+ total: Schema.Natural
176
+ });
177
+ const ResultsPage = (item) => Schema.Struct({
178
+ results: Schema.Array(item).check(Schema.isMaxLength(100)),
179
+ total: Schema.Natural
180
+ });
181
+ const Logs = Schema.Struct({
182
+ logs: Schema.Array(FunctionLogLine).check(Schema.isMaxLength(1e5)),
183
+ total: Schema.Natural
184
+ });
185
+ const now = Clock.monotonicTimeNanos.pipe(Effect.map((value) => Number(value) / 1e6));
186
+ /**
187
+ * Browserbase Functions: deployed code invoked in a provider-allocated session. Deployment
188
+ * happens through Browserbase's CLI; this service reads, invokes and observes. `invoke` is
189
+ * never retried, and a lost reply is `outcome: "unknown"`.
190
+ */
191
+ var BrowserbaseFunctions = class BrowserbaseFunctions extends Context.Service()("effect-browserbase/Functions") {
192
+ static layer = Layer.effect(BrowserbaseFunctions, Effect.gen(function* () {
193
+ const client = yield* BrowserbaseClient;
194
+ const api = resource(client, (failure) => PlatformError.make({
195
+ ...failure,
196
+ service: "functions"
197
+ }));
198
+ /** Every record names its project; a foreign or mismatched one is malformed. */
199
+ const owned = (operation, mutation, expected) => (value) => value.projectId === client.projectId && (expected === void 0 || value.id === expected) ? Effect.succeed(value) : Effect.fail(api.malformed(operation, mutation));
200
+ const id = (value, operation) => api.input(Identifier, value, operation);
201
+ const list = Effect.fn("BrowserbaseFunctions.list")(function* (query = {}) {
202
+ const value = yield* api.input(FunctionPageQuery, query, "function-list");
203
+ const page = yield* api.request("GET", `/v1/functions${api.query(value)}`, DataPage(FunctionMetadata), "function-list");
204
+ return {
205
+ items: yield* Effect.forEach(page.data, owned("function-list", false)),
206
+ total: page.total
207
+ };
208
+ });
209
+ const retrieve = Effect.fn("BrowserbaseFunctions.retrieve")(function* (functionId) {
210
+ const checked = yield* id(functionId, "function-retrieve");
211
+ return yield* api.request("GET", `/v1/functions/${api.segment(checked)}`, FunctionMetadata, "function-retrieve").pipe(Effect.flatMap(owned("function-retrieve", false, checked)));
212
+ });
213
+ const invoke = Effect.fn("BrowserbaseFunctions.invoke")(function* (functionId, request = {}) {
214
+ const checked = yield* id(functionId, "function-invoke");
215
+ const value = yield* api.input(FunctionInvokeRequest, request, "function-invoke");
216
+ const session = value.session;
217
+ const context = session?.context;
218
+ if (context !== void 0) {
219
+ if (context.reference.projectId !== client.projectId) return yield* api.make({
220
+ operation: "function-invoke",
221
+ reason: "authorization",
222
+ outcome: "undispatched"
223
+ });
224
+ if (context.persist && isContextWriterBusy(context.reference)) return yield* api.make({
225
+ operation: "function-invoke",
226
+ reason: "active",
227
+ outcome: "undispatched"
228
+ });
229
+ }
230
+ const sessionCreateParams = session === void 0 ? void 0 : {
231
+ ...session.timeout === void 0 ? {} : { timeout: session.timeout },
232
+ ...session.extensionId === void 0 ? {} : { extensionId: session.extensionId },
233
+ ...session.proxies === void 0 ? {} : { proxies: typeof session.proxies === "boolean" ? session.proxies : session.proxies.map(proxy) },
234
+ ...session.proxySettings === void 0 ? {} : { proxySettings: session.proxySettings },
235
+ ...session.userMetadata === void 0 ? {} : { userMetadata: session.userMetadata },
236
+ ...session.browserSettings === void 0 && context === void 0 ? {} : { browserSettings: {
237
+ ...session.browserSettings,
238
+ ...context === void 0 ? {} : { context: {
239
+ id: context.reference.contextId,
240
+ persist: context.persist
241
+ } }
242
+ } }
243
+ };
244
+ return yield* api.request("POST", `/v1/functions/${api.segment(checked)}/invoke`, FunctionInvocation, "function-invoke", {
245
+ ...value.params === void 0 ? {} : { params: value.params },
246
+ ...sessionCreateParams === void 0 ? {} : { sessionCreateParams }
247
+ }).pipe(Effect.flatMap(owned("function-invoke", true)));
248
+ });
249
+ const versions = Effect.fn("BrowserbaseFunctions.versions")(function* (functionId, query = {}) {
250
+ const checked = yield* id(functionId, "function-versions");
251
+ const value = yield* api.input(FunctionPageQuery, query, "function-versions");
252
+ const page = yield* api.request("GET", `/v1/functions/${api.segment(checked)}/versions${api.query(value)}`, ResultsPage(FunctionVersion), "function-versions");
253
+ return {
254
+ items: yield* Effect.forEach(page.results, owned("function-versions", false)),
255
+ total: page.total
256
+ };
257
+ });
258
+ const version = Effect.fn("BrowserbaseFunctions.version")(function* (versionId) {
259
+ const checked = yield* id(versionId, "function-version");
260
+ return yield* api.request("GET", `/v1/functions/versions/${api.segment(checked)}`, FunctionVersion, "function-version").pipe(Effect.flatMap(owned("function-version", false, checked)));
261
+ });
262
+ const invocations = Effect.fn("BrowserbaseFunctions.invocations")(function* (versionId, query = {}) {
263
+ const checked = yield* id(versionId, "function-invocations");
264
+ const value = yield* api.input(FunctionStatusQuery, query, "function-invocations");
265
+ const page = yield* api.request("GET", `/v1/functions/versions/${api.segment(checked)}/invocations${api.query(value)}`, ResultsPage(FunctionInvocation), "function-invocations");
266
+ return {
267
+ items: yield* Effect.forEach(page.results, owned("function-invocations", false)),
268
+ total: page.total
269
+ };
270
+ });
271
+ const invocation = Effect.fn("BrowserbaseFunctions.invocation")(function* (invocationId) {
272
+ const checked = yield* id(invocationId, "function-invocation");
273
+ return yield* api.request("GET", `/v1/functions/invocations/${api.segment(checked)}`, FunctionInvocation, "function-invocation").pipe(Effect.flatMap(owned("function-invocation", false, checked)));
274
+ });
275
+ const logs = (path, operation) => api.request("GET", path, Logs, operation).pipe(Effect.map((value) => ({
276
+ items: value.logs,
277
+ total: value.total
278
+ })));
279
+ const invocationLogs = Effect.fn("BrowserbaseFunctions.invocationLogs")(function* (invocationId) {
280
+ const checked = yield* id(invocationId, "function-invocation-logs");
281
+ return yield* logs(`/v1/functions/invocations/${api.segment(checked)}/logs`, "function-invocation-logs");
282
+ });
283
+ const builds = Effect.fn("BrowserbaseFunctions.builds")(function* (query = {}) {
284
+ const value = yield* api.input(FunctionStatusQuery, query, "function-builds");
285
+ const page = yield* api.request("GET", `/v1/functions/builds${api.query(value)}`, DataPage(FunctionBuild), "function-builds");
286
+ return {
287
+ items: yield* Effect.forEach(page.data, owned("function-builds", false)),
288
+ total: page.total
289
+ };
290
+ });
291
+ const build = Effect.fn("BrowserbaseFunctions.build")(function* (buildId) {
292
+ const checked = yield* id(buildId, "function-build");
293
+ return yield* api.request("GET", `/v1/functions/builds/${api.segment(checked)}`, FunctionBuild, "function-build").pipe(Effect.flatMap(owned("function-build", false, checked)));
294
+ });
295
+ const buildLogs = Effect.fn("BrowserbaseFunctions.buildLogs")(function* (buildId) {
296
+ const checked = yield* id(buildId, "function-build-logs");
297
+ return yield* logs(`/v1/functions/builds/${api.segment(checked)}/logs`, "function-build-logs");
298
+ });
299
+ const waitForInvocation = Effect.fn("BrowserbaseFunctions.waitForInvocation")(function* (invocationId, options) {
300
+ const bounds = yield* api.input(FunctionWaitOptions, options, "function-wait");
301
+ const deadline = (yield* now) + bounds.timeoutMillis;
302
+ for (;;) {
303
+ const current = yield* invocation(invocationId);
304
+ if (current.status === "COMPLETED" || current.status === "FAILED") return current;
305
+ const remaining = deadline - (yield* now);
306
+ if (remaining <= 0) return yield* api.make({
307
+ operation: "function-wait",
308
+ reason: "timeout"
309
+ });
310
+ yield* Effect.sleep(Math.min(bounds.pollIntervalMillis ?? 1e3, remaining));
311
+ }
312
+ });
313
+ return BrowserbaseFunctions.of({
314
+ list,
315
+ retrieve,
316
+ invoke,
317
+ versions,
318
+ version,
319
+ invocations,
320
+ invocation,
321
+ invocationLogs,
322
+ builds,
323
+ build,
324
+ buildLogs,
325
+ waitForInvocation
326
+ });
327
+ }));
328
+ };
329
+ //#endregion
330
+ export { BrowserbaseFunctions, FunctionBuild, FunctionInvocation, FunctionInvokeRequest, FunctionLogLine, FunctionMetadata, FunctionPageQuery, FunctionSessionParams, FunctionStatusQuery, FunctionVersion, FunctionWaitOptions, Functions_exports as t };
331
+
332
+ //# sourceMappingURL=Functions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Functions.mjs","names":[],"sources":["../src/Functions.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 JsonObject = Schema.Record(Schema.String, Schema.Json);\nconst Name = Schema.String.check(Schema.isMaxLength(1024));\nconst Status = Schema.Literals([\"PENDING\", \"RUNNING\", \"COMPLETED\", \"FAILED\"]);\n\nexport type FunctionStatus = typeof Status.Type;\n\nexport class FunctionMetadata extends Schema.Class<FunctionMetadata>(\"BrowserbaseFunctionMetadata\")(\n {\n id: Identifier,\n projectId: Identifier,\n name: Name,\n createdAt: Timestamp,\n updatedAt: Timestamp,\n },\n) {}\n\nexport class FunctionVersion extends Schema.Class<FunctionVersion>(\"BrowserbaseFunctionVersion\")({\n id: Identifier,\n projectId: Identifier,\n functionId: Identifier,\n functionBuildId: Identifier,\n sessionCreateParams: Schema.optionalKey(JsonObject),\n userParamsSchema: Schema.optionalKey(JsonObject),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n}) {}\n\nexport class FunctionBuild extends Schema.Class<FunctionBuild>(\"BrowserbaseFunctionBuild\")({\n id: Identifier,\n projectId: Identifier,\n request: Schema.Struct({\n entrypoint: Name,\n functionNames: Schema.optionalKey(Schema.Array(Name).check(Schema.isMaxLength(1024))),\n }),\n status: Status,\n createdAt: Timestamp,\n updatedAt: Timestamp,\n startedAt: Timestamp,\n endedAt: Schema.optionalKey(Timestamp),\n expiresAt: Timestamp,\n cause: Schema.optionalKey(\n Schema.Struct({\n code: Schema.String.check(Schema.isMaxLength(64)),\n message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(4096))),\n }),\n ),\n}) {}\n\nexport class FunctionInvocation extends Schema.Class<FunctionInvocation>(\n \"BrowserbaseFunctionInvocation\",\n)({\n id: Identifier,\n projectId: Identifier,\n functionId: Identifier,\n versionId: Identifier,\n sessionId: Identifier,\n region: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(64))),\n params: Schema.optionalKey(JsonObject),\n status: Status,\n results: Schema.optionalKey(Schema.Json),\n cause: Schema.optionalKey(\n Schema.Struct({\n code: Schema.String.check(Schema.isMaxLength(64)),\n message: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(4096))),\n }),\n ),\n createdAt: Timestamp,\n updatedAt: Timestamp,\n startedAt: Timestamp,\n endedAt: Schema.optionalKey(Timestamp),\n expiresAt: Timestamp,\n}) {}\n\nexport class FunctionLogLine extends Schema.Class<FunctionLogLine>(\"BrowserbaseFunctionLogLine\")({\n message: Schema.String.check(Schema.isMaxLength(65_536)),\n timestamp: Schema.Finite,\n}) {}\n\n/** The session a Function invocation runs in; the provider's invoke-time subset. */\nexport const FunctionSessionParams = Schema.Struct({\n /** Seconds, 60–900; the provider defaults to 900. */\n timeout: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 60, maximum: 900 }))),\n extensionId: Schema.optionalKey(Identifier),\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 proxySettings: Schema.optionalKey(\n Schema.Struct({\n caCertificates: Schema.optionalKey(\n Schema.Array(Identifier).check(Schema.isMaxLength(64), Schema.isUnique()),\n ),\n }),\n ),\n userMetadata: Schema.optionalKey(\n Schema.Record(Schema.String.check(Schema.isMaxLength(128)), Schema.Json),\n ),\n browserSettings: Schema.optionalKey(\n Schema.Struct({\n viewport: Schema.optionalKey(\n Schema.Struct({\n width: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 8192 })),\n ),\n height: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 8192 })),\n ),\n }),\n ),\n blockAds: Schema.optionalKey(Schema.Boolean),\n solveCaptchas: Schema.optionalKey(Schema.Boolean),\n recordSession: Schema.optionalKey(Schema.Boolean),\n logSession: Schema.optionalKey(Schema.Boolean),\n verified: Schema.optionalKey(Schema.Boolean),\n captchaImageSelector: Schema.optionalKey(\n Schema.NonEmptyString.check(Schema.isMaxLength(1024)),\n ),\n captchaInputSelector: Schema.optionalKey(\n Schema.NonEmptyString.check(Schema.isMaxLength(1024)),\n ),\n os: Schema.optionalKey(Schema.Literals([\"windows\", \"mac\", \"linux\", \"mobile\", \"tablet\"])),\n size: Schema.optionalKey(Schema.Literals([\"small\", \"medium\", \"large\"])),\n enableNativeSelectPolyfill: Schema.optionalKey(Schema.Boolean),\n enablePdfViewer: Schema.optionalKey(Schema.Boolean),\n extensions: Schema.optionalKey(\n Schema.Array(Schema.Literals([\"onepassword\", \"browser-events\"])).check(Schema.isUnique()),\n ),\n allowedDomains: Schema.optionalKey(\n Schema.Array(Schema.NonEmptyString.check(Schema.isMaxLength(1024))).check(\n Schema.isMaxLength(64),\n Schema.isUnique(),\n ),\n ),\n ignoreCertificateErrors: Schema.optionalKey(Schema.Boolean),\n }),\n ),\n});\n\nexport type FunctionSessionParams = typeof FunctionSessionParams.Type;\n\nexport const FunctionInvokeRequest = Schema.Struct({\n params: Schema.optionalKey(JsonObject),\n session: Schema.optionalKey(FunctionSessionParams),\n});\n\nexport type FunctionInvokeRequest = typeof FunctionInvokeRequest.Type;\n\nconst Offset = {\n offset: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 1_000_000 })),\n ),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),\n};\n\nexport const FunctionPageQuery = Schema.Struct(Offset);\nexport type FunctionPageQuery = typeof FunctionPageQuery.Type;\n\nexport const FunctionStatusQuery = Schema.Struct({ ...Offset, status: Schema.optionalKey(Status) });\nexport type FunctionStatusQuery = typeof FunctionStatusQuery.Type;\n\nexport const FunctionWaitOptions = Schema.Struct({\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 3_600_000 })),\n pollIntervalMillis: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 250, maximum: 60_000 })),\n ),\n});\n\nexport type FunctionWaitOptions = typeof FunctionWaitOptions.Type;\n\nexport interface OffsetPage<A> {\n readonly items: ReadonlyArray<A>;\n readonly total: number;\n}\n\nconst DataPage = <S extends Schema.Top>(item: S) =>\n Schema.Struct({ data: Schema.Array(item).check(Schema.isMaxLength(100)), total: Schema.Natural });\n\nconst ResultsPage = <S extends Schema.Top>(item: S) =>\n Schema.Struct({\n results: Schema.Array(item).check(Schema.isMaxLength(100)),\n total: Schema.Natural,\n });\n\nconst Logs = Schema.Struct({\n logs: Schema.Array(FunctionLogLine).check(Schema.isMaxLength(100_000)),\n total: Schema.Natural,\n});\n\nconst now = Clock.monotonicTimeNanos.pipe(Effect.map((value) => Number(value) / 1_000_000));\n\n/**\n * Browserbase Functions: deployed code invoked in a provider-allocated session. Deployment\n * happens through Browserbase's CLI; this service reads, invokes and observes. `invoke` is\n * never retried, and a lost reply is `outcome: \"unknown\"`.\n */\nexport class BrowserbaseFunctions extends Context.Service<\n BrowserbaseFunctions,\n {\n readonly list: (\n query?: FunctionPageQuery,\n ) => Effect.Effect<OffsetPage<FunctionMetadata>, PlatformError>;\n readonly retrieve: (functionId: string) => Effect.Effect<FunctionMetadata, PlatformError>;\n readonly invoke: (\n functionId: string,\n request?: FunctionInvokeRequest,\n ) => Effect.Effect<FunctionInvocation, PlatformError>;\n readonly versions: (\n functionId: string,\n query?: FunctionPageQuery,\n ) => Effect.Effect<OffsetPage<FunctionVersion>, PlatformError>;\n readonly version: (versionId: string) => Effect.Effect<FunctionVersion, PlatformError>;\n readonly invocations: (\n versionId: string,\n query?: FunctionStatusQuery,\n ) => Effect.Effect<OffsetPage<FunctionInvocation>, PlatformError>;\n readonly invocation: (invocationId: string) => Effect.Effect<FunctionInvocation, PlatformError>;\n readonly invocationLogs: (\n invocationId: string,\n ) => Effect.Effect<OffsetPage<FunctionLogLine>, PlatformError>;\n readonly builds: (\n query?: FunctionStatusQuery,\n ) => Effect.Effect<OffsetPage<FunctionBuild>, PlatformError>;\n readonly build: (buildId: string) => Effect.Effect<FunctionBuild, PlatformError>;\n readonly buildLogs: (\n buildId: string,\n ) => Effect.Effect<OffsetPage<FunctionLogLine>, PlatformError>;\n /** Polls until the invocation is terminal. Interrupting the wait does not cancel it. */\n readonly waitForInvocation: (\n invocationId: string,\n options: FunctionWaitOptions,\n ) => Effect.Effect<FunctionInvocation, PlatformError>;\n }\n>()(\"effect-browserbase/Functions\") {\n static readonly layer: Layer.Layer<BrowserbaseFunctions, never, BrowserbaseClient> = Layer.effect(\n BrowserbaseFunctions,\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n\n const api = resource<PlatformError>(client, (failure) =>\n PlatformError.make({ ...failure, service: \"functions\" }),\n );\n\n /** Every record names its project; a foreign or mismatched one is malformed. */\n const owned =\n <A extends { readonly id: string; readonly projectId: string }>(\n operation: PlatformError[\"operation\"],\n mutation: boolean,\n expected?: string,\n ) =>\n (value: A): Effect.Effect<A, PlatformError> =>\n value.projectId === client.projectId && (expected === undefined || value.id === expected)\n ? Effect.succeed(value)\n : Effect.fail(api.malformed(operation, mutation));\n\n const id = (value: string, operation: PlatformError[\"operation\"]) =>\n api.input(Identifier, value, operation);\n\n const list = Effect.fn(\"BrowserbaseFunctions.list\")(function* (\n query: FunctionPageQuery = {},\n ) {\n const value = yield* api.input(FunctionPageQuery, query, \"function-list\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/functions${api.query(value)}`,\n DataPage(FunctionMetadata),\n \"function-list\",\n );\n\n return {\n items: yield* Effect.forEach(page.data, owned(\"function-list\", false)),\n total: page.total,\n };\n });\n\n const retrieve = Effect.fn(\"BrowserbaseFunctions.retrieve\")(function* (functionId: string) {\n const checked = yield* id(functionId, \"function-retrieve\");\n\n return yield* api\n .request(\n \"GET\",\n `/v1/functions/${api.segment(checked)}`,\n FunctionMetadata,\n \"function-retrieve\",\n )\n .pipe(Effect.flatMap(owned(\"function-retrieve\", false, checked)));\n });\n\n const invoke = Effect.fn(\"BrowserbaseFunctions.invoke\")(function* (\n functionId: string,\n request: FunctionInvokeRequest = {},\n ) {\n const checked = yield* id(functionId, \"function-invoke\");\n const value = yield* api.input(FunctionInvokeRequest, request, \"function-invoke\");\n const session = value.session;\n const context = session?.context;\n\n if (context !== undefined) {\n if (context.reference.projectId !== client.projectId)\n return yield* api.make({\n operation: \"function-invoke\",\n reason: \"authorization\",\n outcome: \"undispatched\",\n });\n if (context.persist && isContextWriterBusy(context.reference))\n return yield* api.make({\n operation: \"function-invoke\",\n reason: \"active\",\n outcome: \"undispatched\",\n });\n }\n\n const sessionCreateParams: Schema.Json | undefined =\n session === undefined\n ? undefined\n : {\n ...(session.timeout === undefined ? {} : { timeout: session.timeout }),\n ...(session.extensionId === undefined ? {} : { extensionId: session.extensionId }),\n ...(session.proxies === undefined\n ? {}\n : {\n proxies:\n typeof session.proxies === \"boolean\"\n ? session.proxies\n : session.proxies.map(proxy),\n }),\n ...(session.proxySettings === undefined\n ? {}\n : { proxySettings: session.proxySettings }),\n ...(session.userMetadata === undefined\n ? {}\n : { userMetadata: session.userMetadata }),\n ...(session.browserSettings === undefined && context === undefined\n ? {}\n : {\n browserSettings: {\n ...session.browserSettings,\n ...(context === undefined\n ? {}\n : {\n context: {\n id: context.reference.contextId,\n persist: context.persist,\n },\n }),\n },\n }),\n };\n\n return yield* api\n .request(\n \"POST\",\n `/v1/functions/${api.segment(checked)}/invoke`,\n FunctionInvocation,\n \"function-invoke\",\n {\n ...(value.params === undefined ? {} : { params: value.params }),\n ...(sessionCreateParams === undefined ? {} : { sessionCreateParams }),\n },\n )\n .pipe(Effect.flatMap(owned(\"function-invoke\", true)));\n });\n\n const versions = Effect.fn(\"BrowserbaseFunctions.versions\")(function* (\n functionId: string,\n query: FunctionPageQuery = {},\n ) {\n const checked = yield* id(functionId, \"function-versions\");\n const value = yield* api.input(FunctionPageQuery, query, \"function-versions\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/functions/${api.segment(checked)}/versions${api.query(value)}`,\n ResultsPage(FunctionVersion),\n \"function-versions\",\n );\n\n return {\n items: yield* Effect.forEach(page.results, owned(\"function-versions\", false)),\n total: page.total,\n };\n });\n\n const version = Effect.fn(\"BrowserbaseFunctions.version\")(function* (versionId: string) {\n const checked = yield* id(versionId, \"function-version\");\n\n return yield* api\n .request(\n \"GET\",\n `/v1/functions/versions/${api.segment(checked)}`,\n FunctionVersion,\n \"function-version\",\n )\n .pipe(Effect.flatMap(owned(\"function-version\", false, checked)));\n });\n\n const invocations = Effect.fn(\"BrowserbaseFunctions.invocations\")(function* (\n versionId: string,\n query: FunctionStatusQuery = {},\n ) {\n const checked = yield* id(versionId, \"function-invocations\");\n const value = yield* api.input(FunctionStatusQuery, query, \"function-invocations\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/functions/versions/${api.segment(checked)}/invocations${api.query(value)}`,\n ResultsPage(FunctionInvocation),\n \"function-invocations\",\n );\n\n return {\n items: yield* Effect.forEach(page.results, owned(\"function-invocations\", false)),\n total: page.total,\n };\n });\n\n const invocation = Effect.fn(\"BrowserbaseFunctions.invocation\")(function* (\n invocationId: string,\n ) {\n const checked = yield* id(invocationId, \"function-invocation\");\n\n return yield* api\n .request(\n \"GET\",\n `/v1/functions/invocations/${api.segment(checked)}`,\n FunctionInvocation,\n \"function-invocation\",\n )\n .pipe(Effect.flatMap(owned(\"function-invocation\", false, checked)));\n });\n\n const logs = (path: string, operation: PlatformError[\"operation\"]) =>\n api\n .request(\"GET\", path, Logs, operation)\n .pipe(Effect.map((value) => ({ items: value.logs, total: value.total })));\n\n const invocationLogs = Effect.fn(\"BrowserbaseFunctions.invocationLogs\")(function* (\n invocationId: string,\n ) {\n const checked = yield* id(invocationId, \"function-invocation-logs\");\n\n return yield* logs(\n `/v1/functions/invocations/${api.segment(checked)}/logs`,\n \"function-invocation-logs\",\n );\n });\n\n const builds = Effect.fn(\"BrowserbaseFunctions.builds\")(function* (\n query: FunctionStatusQuery = {},\n ) {\n const value = yield* api.input(FunctionStatusQuery, query, \"function-builds\");\n\n const page = yield* api.request(\n \"GET\",\n `/v1/functions/builds${api.query(value)}`,\n DataPage(FunctionBuild),\n \"function-builds\",\n );\n\n return {\n items: yield* Effect.forEach(page.data, owned(\"function-builds\", false)),\n total: page.total,\n };\n });\n\n const build = Effect.fn(\"BrowserbaseFunctions.build\")(function* (buildId: string) {\n const checked = yield* id(buildId, \"function-build\");\n\n return yield* api\n .request(\n \"GET\",\n `/v1/functions/builds/${api.segment(checked)}`,\n FunctionBuild,\n \"function-build\",\n )\n .pipe(Effect.flatMap(owned(\"function-build\", false, checked)));\n });\n\n const buildLogs = Effect.fn(\"BrowserbaseFunctions.buildLogs\")(function* (buildId: string) {\n const checked = yield* id(buildId, \"function-build-logs\");\n\n return yield* logs(\n `/v1/functions/builds/${api.segment(checked)}/logs`,\n \"function-build-logs\",\n );\n });\n\n const waitForInvocation = Effect.fn(\"BrowserbaseFunctions.waitForInvocation\")(function* (\n invocationId: string,\n options: FunctionWaitOptions,\n ) {\n const bounds = yield* api.input(FunctionWaitOptions, options, \"function-wait\");\n const deadline = (yield* now) + bounds.timeoutMillis;\n\n for (;;) {\n const current = yield* invocation(invocationId);\n\n if (current.status === \"COMPLETED\" || current.status === \"FAILED\") return current;\n const remaining = deadline - (yield* now);\n\n if (remaining <= 0)\n return yield* api.make({ operation: \"function-wait\", reason: \"timeout\" });\n yield* Effect.sleep(Math.min(bounds.pollIntervalMillis ?? 1_000, remaining));\n }\n });\n\n return BrowserbaseFunctions.of({\n list,\n retrieve,\n invoke,\n versions,\n version,\n invocations,\n invocation,\n invocationLogs,\n builds,\n build,\n buildLogs,\n waitForInvocation,\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,EAAE,CAAC;AAC5D,MAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI;AAC3D,MAAM,OAAO,OAAO,OAAO,MAAM,OAAO,YAAY,IAAI,CAAC;AACzD,MAAM,SAAS,OAAO,SAAS;CAAC;CAAW;CAAW;CAAa;AAAQ,CAAC;AAI5E,IAAa,mBAAb,cAAsC,OAAO,MAAwB,6BAA6B,CAAC,CACjG;CACE,IAAI;CACJ,WAAW;CACX,MAAM;CACN,WAAW;CACX,WAAW;AACb,CACF,CAAC,CAAC,CAAC;AAEH,IAAa,kBAAb,cAAqC,OAAO,MAAuB,4BAA4B,CAAC,CAAC;CAC/F,IAAI;CACJ,WAAW;CACX,YAAY;CACZ,iBAAiB;CACjB,qBAAqB,OAAO,YAAY,UAAU;CAClD,kBAAkB,OAAO,YAAY,UAAU;CAC/C,WAAW;CACX,WAAW;AACb,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,gBAAb,cAAmC,OAAO,MAAqB,0BAA0B,CAAC,CAAC;CACzF,IAAI;CACJ,WAAW;CACX,SAAS,OAAO,OAAO;EACrB,YAAY;EACZ,eAAe,OAAO,YAAY,OAAO,MAAM,IAAI,CAAC,CAAC,MAAM,OAAO,YAAY,IAAI,CAAC,CAAC;CACtF,CAAC;CACD,QAAQ;CACR,WAAW;CACX,WAAW;CACX,WAAW;CACX,SAAS,OAAO,YAAY,SAAS;CACrC,WAAW;CACX,OAAO,OAAO,YACZ,OAAO,OAAO;EACZ,MAAM,OAAO,OAAO,MAAM,OAAO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O,GAAG,4BAA4B,CAAC,CAAC,WAAW,SAAiB;GAChF,MAAM,UAAU,OAAO,GAAG,SAAS,gBAAgB;GAEnD,OAAO,OAAO,IACX,QACC,OACA,wBAAwB,IAAI,QAAQ,OAAO,KAC3C,eACA,gBACF,CAAC,CACA,KAAK,OAAO,QAAQ,MAAM,kBAAkB,OAAO,OAAO,CAAC,CAAC;EACjE,CAAC;EAED,MAAM,YAAY,OAAO,GAAG,gCAAgC,CAAC,CAAC,WAAW,SAAiB;GACxF,MAAM,UAAU,OAAO,GAAG,SAAS,qBAAqB;GAExD,OAAO,OAAO,KACZ,wBAAwB,IAAI,QAAQ,OAAO,EAAE,QAC7C,qBACF;EACF,CAAC;EAED,MAAM,oBAAoB,OAAO,GAAG,wCAAwC,CAAC,CAAC,WAC5E,cACA,SACA;GACA,MAAM,SAAS,OAAO,IAAI,MAAM,qBAAqB,SAAS,eAAe;GAC7E,MAAM,YAAY,OAAO,OAAO,OAAO;GAEvC,SAAS;IACP,MAAM,UAAU,OAAO,WAAW,YAAY;IAE9C,IAAI,QAAQ,WAAW,eAAe,QAAQ,WAAW,UAAU,OAAO;IAC1E,MAAM,YAAY,YAAY,OAAO;IAErC,IAAI,aAAa,GACf,OAAO,OAAO,IAAI,KAAK;KAAE,WAAW;KAAiB,QAAQ;IAAU,CAAC;IAC1E,OAAO,OAAO,MAAM,KAAK,IAAI,OAAO,sBAAsB,KAAO,SAAS,CAAC;GAC7E;EACF,CAAC;EAED,OAAO,qBAAqB,GAAG;GAC7B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;CACH,CAAC,CACH;AACF"}
@@ -0,0 +1,127 @@
1
+ import { BrowserError } from "./Errors.mjs";
2
+ import { Schema } from "effect";
3
+ //#region src/internal/browser/NativeCalls.ts
4
+ /**
5
+ * A native step failed. It names no operation: the owner stamps the one the caller asked for
6
+ * when it admits the work, so a step's own vocabulary can never become public API.
7
+ */
8
+ var NativeFailure = class extends Schema.TaggedError()("NativeFailure", {
9
+ reason: BrowserError.fields.reason,
10
+ outcome: BrowserError.fields.outcome
11
+ }) {};
12
+ /**
13
+ * The only way a native failure becomes public. A fenced ticket already speaks publicly and
14
+ * passes through with the operation the owner gave it; a native failure keeps its reason and
15
+ * takes the caller's operation; anything else is the caller's fallback.
16
+ */
17
+ const publicError = (error, operation, fallback) => {
18
+ if (Schema.is(BrowserError)(error)) return error;
19
+ const known = Schema.is(NativeFailure)(error) ? error : fallback;
20
+ return BrowserError.make({
21
+ operation,
22
+ reason: known.reason,
23
+ ...known.outcome === void 0 ? {} : { outcome: known.outcome }
24
+ });
25
+ };
26
+ /** Shared by the Playwright driver's seams, so every native call fails in the same vocabulary. */
27
+ const failure = (reason, outcome) => NativeFailure.make({
28
+ reason,
29
+ ...outcome === void 0 ? {} : { outcome }
30
+ });
31
+ const safeDecode = (codec, raw) => {
32
+ try {
33
+ return Schema.decodeUnknownSync(codec)(raw);
34
+ } catch {
35
+ throw failure("malformed");
36
+ }
37
+ };
38
+ /**
39
+ * No raw exception from Playwright crosses this private boundary. A ticket's own fence is
40
+ * already a public error and passes through with the operation the owner gave it.
41
+ */
42
+ const sanitize = (action) => Promise.resolve().then(action).catch((error) => {
43
+ throw Schema.is(BrowserError)(error) || Schema.is(NativeFailure)(error) ? error : failure("provider");
44
+ });
45
+ const closeWithin = async (action, milliseconds = 2e3) => {
46
+ let timer;
47
+ try {
48
+ await Promise.race([Promise.resolve().then(action), new Promise((_, reject) => {
49
+ timer = setTimeout(() => reject(failure("timeout")), milliseconds);
50
+ })]);
51
+ } finally {
52
+ clearTimeout(timer);
53
+ }
54
+ };
55
+ const timeout = (ticket) => {
56
+ ticket.check();
57
+ return ticket.remainingMillis();
58
+ };
59
+ //#endregion
60
+ //#region src/internal/capture/Images.ts
61
+ const malformed = () => failure("malformed");
62
+ /** Parse framing only; a caller decoding media must still validate its complete bitstream. */
63
+ const pngGeometry = (bytes) => {
64
+ if (bytes.length < 33 || [
65
+ 137,
66
+ 80,
67
+ 78,
68
+ 71,
69
+ 13,
70
+ 10,
71
+ 26,
72
+ 10
73
+ ].some((b, i) => bytes[i] !== b) || bytes[12] !== 73 || bytes[13] !== 72 || bytes[14] !== 68 || bytes[15] !== 82) throw malformed();
74
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
75
+ if (view.getUint32(8) !== 13) throw malformed();
76
+ const width = view.getUint32(16), height = view.getUint32(20);
77
+ if (width === 0 || height === 0) throw malformed();
78
+ return {
79
+ width,
80
+ height
81
+ };
82
+ };
83
+ /** JPEG SOF dimensions avoid trusting the requested size or CSS viewport dimensions. */
84
+ const jpegGeometry = (bytes) => {
85
+ if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) throw malformed();
86
+ let offset = 2;
87
+ while (offset + 3 < bytes.length) {
88
+ if (bytes[offset++] !== 255) throw malformed();
89
+ while (bytes[offset] === 255) offset++;
90
+ const marker = bytes[offset++];
91
+ if (marker === void 0 || marker === 217 || marker === 218) break;
92
+ if (marker === 1 || marker >= 208 && marker <= 215) continue;
93
+ if (offset + 1 >= bytes.length) throw malformed();
94
+ const size = bytes[offset] * 256 + bytes[offset + 1];
95
+ if (size < 2 || offset + size > bytes.length) throw malformed();
96
+ if ([
97
+ 192,
98
+ 193,
99
+ 194,
100
+ 195,
101
+ 197,
102
+ 198,
103
+ 199,
104
+ 201,
105
+ 202,
106
+ 203,
107
+ 205,
108
+ 206,
109
+ 207
110
+ ].includes(marker)) {
111
+ if (size < 8) throw malformed();
112
+ const height = bytes[offset + 3] * 256 + bytes[offset + 4];
113
+ const width = bytes[offset + 5] * 256 + bytes[offset + 6];
114
+ if (width === 0 || height === 0) throw malformed();
115
+ return {
116
+ width,
117
+ height
118
+ };
119
+ }
120
+ offset += size;
121
+ }
122
+ throw malformed();
123
+ };
124
+ //#endregion
125
+ export { failure as a, sanitize as c, closeWithin as i, timeout as l, pngGeometry as n, publicError as o, NativeFailure as r, safeDecode as s, jpegGeometry as t };
126
+
127
+ //# sourceMappingURL=Images-DgscEfSf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Images-DgscEfSf.mjs","names":[],"sources":["../src/internal/browser/NativeCalls.ts","../src/internal/capture/Images.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nimport { BrowserError, type BrowserOperation } from \"../../Errors.ts\";\nimport type { Ticket } from \"./Owner.ts\";\n\n/**\n * A native step failed. It names no operation: the owner stamps the one the caller asked for\n * when it admits the work, so a step's own vocabulary can never become public API.\n */\nexport class NativeFailure extends Schema.TaggedError<NativeFailure>()(\"NativeFailure\", {\n reason: BrowserError.fields.reason,\n outcome: BrowserError.fields.outcome,\n}) {}\n\n/**\n * The only way a native failure becomes public. A fenced ticket already speaks publicly and\n * passes through with the operation the owner gave it; a native failure keeps its reason and\n * takes the caller's operation; anything else is the caller's fallback.\n */\nexport const publicError = (\n error: unknown,\n operation: BrowserOperation,\n fallback: Pick<BrowserError, \"reason\" | \"outcome\">,\n): BrowserError => {\n if (Schema.is(BrowserError)(error)) return error;\n const known = Schema.is(NativeFailure)(error) ? error : fallback;\n\n return BrowserError.make({\n operation,\n reason: known.reason,\n ...(known.outcome === undefined ? {} : { outcome: known.outcome }),\n });\n};\n\n/** Shared by the Playwright driver's seams, so every native call fails in the same vocabulary. */\nexport const failure = (reason: BrowserError[\"reason\"], outcome?: BrowserError[\"outcome\"]) =>\n NativeFailure.make({ reason, ...(outcome === undefined ? {} : { outcome }) });\n\nexport const safeDecode = <A>(codec: Schema.Codec<A, unknown, never, never>, raw: unknown): A => {\n try {\n return Schema.decodeUnknownSync(codec)(raw);\n } catch {\n throw failure(\"malformed\");\n }\n};\n\n/**\n * No raw exception from Playwright crosses this private boundary. A ticket's own fence is\n * already a public error and passes through with the operation the owner gave it.\n */\nexport const sanitize = <A>(action: () => Promise<A>): Promise<A> =>\n Promise.resolve()\n .then(action)\n .catch((error: unknown) => {\n throw Schema.is(BrowserError)(error) || Schema.is(NativeFailure)(error)\n ? error\n : failure(\"provider\");\n });\n\nexport const closeWithin = async (\n action: () => Promise<unknown>,\n milliseconds = 2000,\n): Promise<void> => {\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n try {\n await Promise.race([\n Promise.resolve().then(action),\n new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(failure(\"timeout\")), milliseconds);\n }),\n ]);\n } finally {\n clearTimeout(timer);\n }\n};\n\n// The native timeout is finite as well as Effect's authoritative deadline. It cannot undo dispatch.\nexport const timeout = (ticket: Ticket) => {\n ticket.check();\n\n return ticket.remainingMillis();\n};\n","import { failure } from \"../browser/NativeCalls.ts\";\n\nconst malformed = () => failure(\"malformed\");\n\n/** Parse framing only; a caller decoding media must still validate its complete bitstream. */\nexport const pngGeometry = (bytes: Uint8Array): { width: number; height: number } => {\n const signature = [137, 80, 78, 71, 13, 10, 26, 10];\n\n if (\n bytes.length < 33 ||\n signature.some((b, i) => bytes[i] !== b) ||\n bytes[12] !== 73 ||\n bytes[13] !== 72 ||\n bytes[14] !== 68 ||\n bytes[15] !== 82\n )\n throw malformed();\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\n if (view.getUint32(8) !== 13) throw malformed();\n\n const width = view.getUint32(16),\n height = view.getUint32(20);\n\n if (width === 0 || height === 0) throw malformed();\n\n return { width, height };\n};\n\n/** JPEG SOF dimensions avoid trusting the requested size or CSS viewport dimensions. */\nexport const jpegGeometry = (bytes: Uint8Array): { width: number; height: number } => {\n if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) throw malformed();\n let offset = 2;\n\n while (offset + 3 < bytes.length) {\n if (bytes[offset++] !== 255) throw malformed();\n while (bytes[offset] === 255) offset++;\n const marker = bytes[offset++];\n\n if (marker === undefined || marker === 217 || marker === 218) break;\n if (marker === 1 || (marker >= 208 && marker <= 215)) continue;\n if (offset + 1 >= bytes.length) throw malformed();\n const size = bytes[offset] * 256 + bytes[offset + 1];\n\n if (size < 2 || offset + size > bytes.length) throw malformed();\n if ([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207].includes(marker)) {\n if (size < 8) throw malformed();\n const height = bytes[offset + 3] * 256 + bytes[offset + 4];\n const width = bytes[offset + 5] * 256 + bytes[offset + 6];\n\n if (width === 0 || height === 0) throw malformed();\n\n return { width, height };\n }\n offset += size;\n }\n throw malformed();\n};\n"],"mappings":";;;;;;;AASA,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CAAC,iBAAiB;CACtF,QAAQ,aAAa,OAAO;CAC5B,SAAS,aAAa,OAAO;AAC/B,CAAC,CAAC,CAAC,CAAC;;;;;;AAOJ,MAAa,eACX,OACA,WACA,aACiB;CACjB,IAAI,OAAO,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,OAAO;CAC3C,MAAM,QAAQ,OAAO,GAAG,aAAa,CAAC,CAAC,KAAK,IAAI,QAAQ;CAExD,OAAO,aAAa,KAAK;EACvB;EACA,QAAQ,MAAM;EACd,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;CAClE,CAAC;AACH;;AAGA,MAAa,WAAW,QAAgC,YACtD,cAAc,KAAK;CAAE;CAAQ,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;AAAG,CAAC;AAE9E,MAAa,cAAiB,OAA+C,QAAoB;CAC/F,IAAI;EACF,OAAO,OAAO,kBAAkB,KAAK,CAAC,CAAC,GAAG;CAC5C,QAAQ;EACN,MAAM,QAAQ,WAAW;CAC3B;AACF;;;;;AAMA,MAAa,YAAe,WAC1B,QAAQ,QAAQ,CAAC,CACd,KAAK,MAAM,CAAC,CACZ,OAAO,UAAmB;CACzB,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,KAAK,KAAK,OAAO,GAAG,aAAa,CAAC,CAAC,KAAK,IAClE,QACA,QAAQ,UAAU;AACxB,CAAC;AAEL,MAAa,cAAc,OACzB,QACA,eAAe,QACG;CAClB,IAAI;CAEJ,IA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;EACtD,IAAI,SAAS,KAAK,MAAM,QAAQ,MAAM,UAAU;EAChD,MAAM,OAAO,MAAM,UAAU,MAAM,MAAM,SAAS;EAElD,IAAI,OAAO,KAAK,SAAS,OAAO,MAAM,QAAQ,MAAM,UAAU;EAC9D,IAAI;GAAC;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;GAAK;EAAG,CAAC,CAAC,SAAS,MAAM,GAAG;GACtF,IAAI,OAAO,GAAG,MAAM,UAAU;GAC9B,MAAM,SAAS,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS;GACxD,MAAM,QAAQ,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS;GAEvD,IAAI,UAAU,KAAK,WAAW,GAAG,MAAM,UAAU;GAEjD,OAAO;IAAE;IAAO;GAAO;EACzB;EACA,UAAU;CACZ;CACA,MAAM,UAAU;AAClB"}
@@ -0,0 +1,15 @@
1
+ //#region src/internal/upload/Issued.ts
2
+ /**
3
+ * Attachment authority belongs to the receipt this package actually issued, not to a value
4
+ * that merely has the right shape. A fabricated look-alike has no entry here, so no caller
5
+ * and no model can turn an arbitrary server pathname into an attached file.
6
+ */
7
+ const issued = /* @__PURE__ */ new WeakMap();
8
+ const recordIssuedUpload = (receipt, upload) => {
9
+ issued.set(receipt, Object.freeze({ ...upload }));
10
+ };
11
+ const issuedUpload = (receipt) => issued.get(receipt);
12
+ //#endregion
13
+ export { recordIssuedUpload as n, issuedUpload as t };
14
+
15
+ //# sourceMappingURL=Issued-DejqoMYL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Issued-DejqoMYL.mjs","names":[],"sources":["../src/internal/upload/Issued.ts"],"sourcesContent":["import type { SessionReference } from \"../../References.ts\";\nimport type { UploadReceipt } from \"../../Transfers.ts\";\n\nexport interface IssuedUpload {\n readonly reference: SessionReference;\n readonly remotePath: string;\n}\n\n/**\n * Attachment authority belongs to the receipt this package actually issued, not to a value\n * that merely has the right shape. A fabricated look-alike has no entry here, so no caller\n * and no model can turn an arbitrary server pathname into an attached file.\n */\nconst issued = new WeakMap<UploadReceipt, IssuedUpload>();\n\nexport const recordIssuedUpload = (receipt: UploadReceipt, upload: IssuedUpload): void => {\n issued.set(receipt, Object.freeze({ ...upload }));\n};\n\nexport const issuedUpload = (receipt: UploadReceipt): IssuedUpload | undefined =>\n issued.get(receipt);\n"],"mappings":";;;;;;AAaA,MAAM,yBAAS,IAAI,QAAqC;AAExD,MAAa,sBAAsB,SAAwB,WAA+B;CACxF,OAAO,IAAI,SAAS,OAAO,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;AAClD;AAEA,MAAa,gBAAgB,YAC3B,OAAO,IAAI,OAAO"}