@effect-agent/platform-cloudflare 0.1.0-beta.41 → 0.1.0-beta.44

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 (44) hide show
  1. package/dist/browser-quick-action.mjs.map +1 -1
  2. package/dist/browser-rest-capture.mjs.map +1 -1
  3. package/dist/browser-rest-crawl.mjs.map +1 -1
  4. package/dist/browser-session-lifecycle-DqntvG-Y.d.mts +21 -0
  5. package/dist/browser-session-lifecycle-ZGgb3pnK.mjs +84 -0
  6. package/dist/browser-session-lifecycle-ZGgb3pnK.mjs.map +1 -0
  7. package/dist/index.d.mts +85 -65
  8. package/dist/index.mjs +7 -2
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/interactive-browser.d.mts +1 -18
  11. package/dist/interactive-browser.mjs +2 -81
  12. package/dist/interactive-browser.mjs.map +1 -1
  13. package/dist/prepared-admission-BKp_Upw2.mjs.map +1 -1
  14. package/dist/protected-browser.d.mts +62 -0
  15. package/dist/protected-browser.mjs +714 -0
  16. package/dist/protected-browser.mjs.map +1 -0
  17. package/dist/scheduling.mjs.map +1 -1
  18. package/dist/subscriptions.mjs.map +1 -1
  19. package/package.json +1 -81
  20. package/src/alarm.ts +41 -0
  21. package/src/bindings.ts +5 -0
  22. package/src/boundary.ts +4 -0
  23. package/src/browser-quick-action.ts +52 -0
  24. package/src/browser-rest-capture.ts +30 -0
  25. package/src/browser-rest-crawl.ts +43 -0
  26. package/src/browser-session-lifecycle.ts +18 -0
  27. package/src/client.ts +40 -0
  28. package/src/code-mode-executor.ts +50 -0
  29. package/src/index.ts +1 -1
  30. package/src/interactive-browser.ts +176 -0
  31. package/src/layers.ts +16 -1
  32. package/src/memory.ts +42 -3
  33. package/src/prepared-admission.ts +1 -0
  34. package/src/progress-wait.ts +14 -0
  35. package/src/protected-browser/binding.ts +185 -0
  36. package/src/protected-browser/inspect-frame.ts +82 -0
  37. package/src/protected-browser/native.ts +384 -0
  38. package/src/protected-browser/policy.ts +594 -0
  39. package/src/protected-browser.ts +2 -0
  40. package/src/scheduling.ts +34 -0
  41. package/src/subscriptions.ts +50 -0
  42. package/src/thread-object.ts +55 -1
  43. package/src/transport.ts +1 -0
  44. package/src/wake-scheduler.ts +1 -0
@@ -1,23 +1,6 @@
1
+ import { n as BrowserRunLifecycleOptions, r as BrowserRunSessionLifecycle, t as BrowserRunCleanupError } from "./browser-session-lifecycle-DqntvG-Y.mjs";
1
2
  import { Context, Effect, Layer, Redacted, Schema, Scope } from "effect";
2
3
  import { BrowserHandle, InteractiveBrowser, InteractiveBrowserError, InteractiveBrowserPolicy, InteractiveBrowserPolicyDeniedError, SandboxImplementation } from "@effect-agent/sandbox";
3
- import { HttpClient } from "effect/unstable/http";
4
- //#region src/browser-session-lifecycle.d.ts
5
- declare const BrowserRunCleanupError_base: Schema.Class<BrowserRunCleanupError, Schema.TaggedStruct<"BrowserRunCleanupError", {
6
- readonly reason: Schema.Literals<readonly ["configuration", "authorization", "rate-limited", "provider", "malformed", "timeout", "pending"]>;
7
- readonly status: Schema.optionalKey<Schema.Int>;
8
- }>, import("effect/Cause").YieldableError>;
9
- declare class BrowserRunCleanupError extends BrowserRunCleanupError_base {}
10
- interface BrowserRunLifecycleOptions {
11
- readonly accountId: string;
12
- readonly apiToken: Redacted.Redacted<string>;
13
- }
14
- declare const BrowserRunSessionLifecycle_base: Context.ServiceClass<BrowserRunSessionLifecycle, "@effect-agent/platform-cloudflare/BrowserRunSessionLifecycle", {
15
- readonly close: (sessionId: Redacted.Redacted<string>) => Effect.Effect<void, BrowserRunCleanupError>;
16
- }>;
17
- declare class BrowserRunSessionLifecycle extends BrowserRunSessionLifecycle_base {
18
- static layer(options: BrowserRunLifecycleOptions): Layer.Layer<BrowserRunSessionLifecycle, BrowserRunCleanupError, HttpClient.HttpClient>;
19
- }
20
- //#endregion
21
4
  //#region src/interactive-browser.d.ts
22
5
  declare const browserRunInteractiveImplementation: SandboxImplementation;
23
6
  declare const BrowserRunViewport_base: Schema.Class<BrowserRunViewport, Schema.Struct<{
@@ -1,86 +1,7 @@
1
- import { Clock, Context, Duration, Effect, Layer, Option, Redacted, Ref, Schema, Semaphore, Stream } from "effect";
1
+ import { n as BrowserRunSessionLifecycle, t as BrowserRunCleanupError } from "./browser-session-lifecycle-ZGgb3pnK.mjs";
2
+ import { Clock, Context, Duration, Effect, Layer, Option, Redacted, Ref, Schema, Semaphore } from "effect";
2
3
  import { BrowserActionResult, BrowserNavigationResult, BrowserScreenshotRequest, BrowserScrollRequest, BrowserTextResult, InteractiveBrowser, InteractiveBrowserActionError, InteractiveBrowserBusyError, InteractiveBrowserCapacityError, InteractiveBrowserExpiredError, InteractiveBrowserLimitError, InteractiveBrowserPolicy, InteractiveBrowserPolicyDeniedError, InteractiveBrowserProtocolError, InteractiveBrowserTargetUrl, InteractiveBrowserUnsupportedError, PageScreenshotResult, SandboxImplementation } from "@effect-agent/sandbox";
3
4
  import puppeteer from "@cloudflare/puppeteer";
4
- import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
5
- //#region src/browser-session-lifecycle.ts
6
- var BrowserRunCleanupError = class extends Schema.TaggedError()("BrowserRunCleanupError", {
7
- reason: Schema.Literals([
8
- "configuration",
9
- "authorization",
10
- "rate-limited",
11
- "provider",
12
- "malformed",
13
- "timeout",
14
- "pending"
15
- ]),
16
- status: Schema.optionalKey(Schema.Int)
17
- }) {};
18
- const Identity = Schema.String.check(Schema.isUUID());
19
- const Account = Schema.String.check(Schema.isPattern(/^[a-f0-9]{32}$/));
20
- const Closed = Schema.Struct({ status: Schema.Literals(["closing", "closed"]) });
21
- const Metadata = Schema.Struct({
22
- sessionId: Identity,
23
- endTime: Schema.optionalKey(Schema.Finite)
24
- });
25
- const Absent = Schema.Struct({ error: Schema.Literal("Session not found") });
26
- var BrowserRunSessionLifecycle = class extends Context.Service()("@effect-agent/platform-cloudflare/BrowserRunSessionLifecycle") {
27
- static layer(options) {
28
- return Layer.effect(this, Effect.gen(function* () {
29
- if (!Schema.is(Account)(options.accountId) || Redacted.value(options.apiToken).length === 0) return yield* new BrowserRunCleanupError({ reason: "configuration" });
30
- const client = yield* HttpClient.HttpClient;
31
- const request = Effect.fn("BrowserRunSessionLifecycle.request")(function* (method, sessionId) {
32
- const path = method === "DELETE" ? "browser" : "session";
33
- const response = yield* client.execute(HttpClientRequest.make(method)(`https://api.cloudflare.com/client/v4/accounts/${options.accountId}/browser-rendering/devtools/${path}/${sessionId}`).pipe(HttpClientRequest.bearerToken(options.apiToken))).pipe(Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }), Effect.mapError(() => new BrowserRunCleanupError({ reason: "provider" })));
34
- if (response.status === 401 || response.status === 403) return yield* new BrowserRunCleanupError({
35
- reason: "authorization",
36
- status: response.status
37
- });
38
- if (response.status === 429) return yield* new BrowserRunCleanupError({
39
- reason: "rate-limited",
40
- status: response.status
41
- });
42
- if (response.status !== 200 && response.status !== 404) return yield* new BrowserRunCleanupError({
43
- reason: "provider",
44
- status: response.status
45
- });
46
- if (response.headers["content-type"]?.split(";", 1)[0]?.trim() !== "application/json") return yield* new BrowserRunCleanupError({ reason: "malformed" });
47
- const bytes = yield* Stream.runFoldEffect(response.stream, () => /* @__PURE__ */ new Uint8Array(), (body, chunk) => {
48
- if (body.byteLength + chunk.byteLength > 16384) return Effect.fail(new BrowserRunCleanupError({ reason: "malformed" }));
49
- const combined = new Uint8Array(body.byteLength + chunk.byteLength);
50
- combined.set(body);
51
- combined.set(chunk, body.byteLength);
52
- return Effect.succeed(combined);
53
- }).pipe(Effect.mapError(() => new BrowserRunCleanupError({ reason: "malformed" })));
54
- const body = yield* Effect.try({
55
- try: () => new TextDecoder("utf-8", {
56
- fatal: true,
57
- ignoreBOM: false
58
- }).decode(bytes),
59
- catch: () => new BrowserRunCleanupError({ reason: "malformed" })
60
- });
61
- if (response.status === 404) {
62
- const absent = Schema.decodeUnknownOption(Schema.fromJsonString(Absent))(body, { onExcessProperty: "error" });
63
- if (Option.isSome(absent)) return true;
64
- return yield* new BrowserRunCleanupError({ reason: "malformed" });
65
- }
66
- if (method === "DELETE") return (yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Closed))(body).pipe(Effect.mapError(() => new BrowserRunCleanupError({ reason: "malformed" })))).status === "closed";
67
- const result = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Metadata))(body).pipe(Effect.mapError(() => new BrowserRunCleanupError({ reason: "malformed" })));
68
- if (result.sessionId !== sessionId) return yield* new BrowserRunCleanupError({ reason: "malformed" });
69
- return result.endTime !== void 0 && result.endTime > 0;
70
- });
71
- return { close: Effect.fn("BrowserRunSessionLifecycle.close")(function* (sessionId) {
72
- const id = yield* Schema.decodeUnknownEffect(Identity)(Redacted.value(sessionId)).pipe(Effect.mapError(() => new BrowserRunCleanupError({ reason: "configuration" })));
73
- if (yield* request("DELETE", id)) return;
74
- for (let read = 0; read < 2; read++) if (yield* request("GET", id)) return;
75
- return yield* new BrowserRunCleanupError({ reason: "pending" });
76
- }, Effect.timeoutOrElse({
77
- duration: "10 seconds",
78
- orElse: () => Effect.fail(new BrowserRunCleanupError({ reason: "timeout" }))
79
- }), Effect.withTracerEnabled(false)) };
80
- }));
81
- }
82
- };
83
- //#endregion
84
5
  //#region src/interactive-browser.ts
85
6
  const browserRunInteractiveImplementation = SandboxImplementation.make({
86
7
  isolation: "isolated",