@effect-agent/platform-cloudflare 0.1.0-beta.120 → 0.1.0-beta.121

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.
@@ -1545,8 +1545,50 @@ export declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorde
1545
1545
  readonly message: string;
1546
1546
  readonly cause?: Schema.Json | undefined;
1547
1547
  } | {
1548
- readonly _tag: "ThreadNotMaterialized";
1548
+ readonly _tag: "HostProtocolError";
1549
+ readonly message: string;
1550
+ } | {
1551
+ readonly _tag: "AgentInputError";
1552
+ readonly message: string;
1553
+ } | {
1554
+ readonly _tag: "DigestError";
1555
+ readonly message: string;
1556
+ readonly cause?: Schema.Json | undefined;
1557
+ } | {
1558
+ readonly _tag: "AdmissionConflict";
1549
1559
  readonly threadId: string;
1560
+ readonly principal: string;
1561
+ readonly idempotencyKey: string;
1562
+ readonly existingInputDigest: string;
1563
+ readonly attemptedInputDigest: string;
1564
+ } | {
1565
+ readonly _tag: "AdmissionPolicyError";
1566
+ readonly reason: "occupied" | "refused" | "unavailable";
1567
+ readonly code: string;
1568
+ readonly cause?: import("effect-agent/failure-diagnostic").Diagnostic | undefined;
1569
+ readonly stack?: string | undefined;
1570
+ } | {
1571
+ readonly _tag: "SettlementConflict";
1572
+ readonly submissionId: string;
1573
+ readonly existingOutcome: "aborted" | "completed" | "failed";
1574
+ } | {
1575
+ readonly _tag: "ApprovalConflict";
1576
+ readonly submissionId: string;
1577
+ readonly toolCallId: string;
1578
+ readonly existingDecision: "approved" | "denied";
1579
+ } | {
1580
+ readonly _tag: "UnknownResolutionConflict";
1581
+ readonly submissionId: string;
1582
+ readonly toolCallId: string;
1583
+ } | {
1584
+ readonly _tag: "JoinedToHost";
1585
+ readonly submissionId: string;
1586
+ readonly hostSubmissionId: string;
1587
+ } | {
1588
+ readonly _tag: "LedgerError";
1589
+ readonly operation: string;
1590
+ readonly message: string;
1591
+ readonly cause?: import("effect-agent/failure-diagnostic").Diagnostic | undefined;
1550
1592
  } | {
1551
1593
  readonly _tag: "ThreadStoreError";
1552
1594
  readonly operation: string;
@@ -1560,10 +1602,8 @@ export declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorde
1560
1602
  readonly sequence?: number | undefined;
1561
1603
  } | undefined;
1562
1604
  } | {
1563
- readonly _tag: "LedgerError";
1564
- readonly operation: string;
1565
- readonly message: string;
1566
- readonly cause?: import("effect-agent/failure-diagnostic").Diagnostic | undefined;
1605
+ readonly _tag: "ThreadNotMaterialized";
1606
+ readonly threadId: string;
1567
1607
  } | {
1568
1608
  readonly _tag: "AppendConflict";
1569
1609
  readonly threadId: string;
@@ -1576,60 +1616,20 @@ export declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorde
1576
1616
  readonly threadId: string;
1577
1617
  readonly actualEpoch: number;
1578
1618
  readonly attemptedEpoch: number;
1579
- } | {
1580
- readonly _tag: "OperationDenied";
1581
- readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
1582
- readonly reason: string;
1583
- readonly threadId?: string | undefined;
1584
- readonly submissionId?: string | undefined;
1585
- } | {
1586
- readonly _tag: "AdmissionConflict";
1587
- readonly threadId: string;
1588
- readonly principal: string;
1589
- readonly idempotencyKey: string;
1590
- readonly existingInputDigest: string;
1591
- readonly attemptedInputDigest: string;
1592
- } | {
1593
- readonly _tag: "AdmissionPolicyError";
1594
- readonly reason: "occupied" | "refused" | "unavailable";
1595
- readonly code: string;
1596
- readonly cause?: import("effect-agent/failure-diagnostic").Diagnostic | undefined;
1597
- readonly stack?: string | undefined;
1598
- } | {
1599
- readonly _tag: "AgentInputError";
1600
- readonly message: string;
1601
- } | {
1602
- readonly _tag: "DigestError";
1603
- readonly message: string;
1604
- readonly cause?: Schema.Json | undefined;
1605
1619
  } | {
1606
1620
  readonly _tag: "DurableRuntimeFailpointError";
1607
1621
  readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "checkpoint:after-save" | "checkpoint:before-save" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-duration-append" | "run:after-start-append" | "run:before-duration-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "subagent:before-join-append" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:after-unavailable-append" | "tools:before-prepared-append" | "tools:before-unavailable-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append" | "update:after-canonical-append" | "update:after-delivery-insert" | "update:before-canonical-append" | "update:before-delivery-insert" | "worker:after-completion-append" | "worker:after-origin-append" | "worker:after-report-append" | "worker:after-report-delivery" | "worker:after-source-append" | "worker:after-stop-append" | "worker:after-stop-seal" | "worker:after-subtree-append" | "worker:before-completion-append" | "worker:before-origin-append" | "worker:before-report-append" | "worker:before-report-delivery" | "worker:before-source-append" | "worker:before-stop-append" | "worker:before-stop-seal" | "worker:before-subtree-append";
1608
- } | {
1609
- readonly _tag: "SettlementConflict";
1610
- readonly submissionId: string;
1611
- readonly existingOutcome: "aborted" | "completed" | "failed";
1612
- } | {
1613
- readonly _tag: "JoinedToHost";
1614
- readonly submissionId: string;
1615
- readonly hostSubmissionId: string;
1616
1622
  } | {
1617
1623
  readonly _tag: "AdmissionLimitExceeded";
1618
1624
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
1619
1625
  readonly actual: number;
1620
1626
  readonly maximum: number;
1621
1627
  } | {
1622
- readonly _tag: "HostProtocolError";
1623
- readonly message: string;
1624
- } | {
1625
- readonly _tag: "ApprovalConflict";
1626
- readonly submissionId: string;
1627
- readonly toolCallId: string;
1628
- readonly existingDecision: "approved" | "denied";
1629
- } | {
1630
- readonly _tag: "UnknownResolutionConflict";
1631
- readonly submissionId: string;
1632
- readonly toolCallId: string;
1628
+ readonly _tag: "OperationDenied";
1629
+ readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
1630
+ readonly reason: string;
1631
+ readonly threadId?: string | undefined;
1632
+ readonly submissionId?: string | undefined;
1633
1633
  };
1634
1634
  }, Schema.SchemaError, never>;
1635
1635
  export declare const decodeHostResponse: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<AbortRecorded | ApprovalRecorded | HostFailed | ObservedPage | ProgressCancelled | ProgressObserved | SettlementReached | SubmissionStatusResponse | SubmitSucceeded | UnknownResolutionRecorded, Schema.SchemaError, never>;
@@ -129,7 +129,7 @@ interface BrowserRunInteractiveBrowser {
129
129
  }
130
130
  declare const BrowserRunInteractiveBinding_base: Context.ServiceClass<BrowserRunInteractiveBinding, "@effect-agent/platform-cloudflare/BrowserRunInteractiveBinding", {
131
131
  readonly acquire: (keepAliveMillis: number) => Promise<unknown>;
132
- readonly connect: (sessionId: string) => Promise<BrowserRunInteractiveBrowser>;
132
+ readonly connect: (sessionId: string, signal?: AbortSignal) => Promise<BrowserRunInteractiveBrowser>;
133
133
  /** Success proves whole-browser termination or exact-session absence. */
134
134
  readonly closeSession: (sessionId: Redacted.Redacted<string>) => Effect.Effect<void, InteractiveBrowserError>;
135
135
  }>;
@@ -225,4 +225,4 @@ declare const CloudflareInteractiveBrowser: {
225
225
  };
226
226
  //#endregion
227
227
  export { CloudflareInteractiveBrowserOptions as C, isBrowserRunUndispatchedActionError as D, browserRunInteractiveLayer as E, BrowserRunCleanupError as O, CloudflareInteractiveBrowser as S, browserRunInteractiveImplementation as T, BrowserRunLiveViewRequest as _, BrowserRunInputState as a, BrowserRunPageObservation as b, BrowserRunInteractiveBrowser as c, BrowserRunInteractiveContext as d, BrowserRunInteractiveHost as f, BrowserRunInteractiveSession as g, BrowserRunInteractiveRequestListener as h, BrowserRunHandoffState as i, BrowserRunSessionLifecycle as k, BrowserRunInteractiveCdpSession as l, BrowserRunInteractiveRequest as m, BrowserRunHandoffRequest as n, BrowserRunInteractiveAcquisition as o, BrowserRunInteractivePage as p, BrowserRunHandoffResult as r, BrowserRunInteractiveBinding as s, BrowserRunCloudflareCommand as t, BrowserRunInteractiveCheckpoint as u, BrowserRunLiveViewResult as v, browserRunInteractiveHostLayer as w, BrowserRunViewport as x, BrowserRunPageIdentity as y };
228
- //# sourceMappingURL=InteractiveBrowser-BQo7QKaP.d.mts.map
228
+ //# sourceMappingURL=InteractiveBrowser-Cm4xgiGy.d.mts.map
@@ -2,8 +2,8 @@ import { Cause, Clock, Context, Data, Duration, Effect, Encoding, ErrorReporter,
2
2
  import { PageScreenshotResult } from "effect-agent/page-screenshot";
3
3
  import { SandboxImplementation } from "effect-agent/sandbox";
4
4
  import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
5
- import puppeteer from "@cloudflare/puppeteer";
6
5
  import { BrowserActionResult, BrowserExpectedTargetState, BrowserFileSelectionResult, BrowserNavigationResult, BrowserScreenshotRequest, BrowserScrollRequest, BrowserSelectFileRequest, BrowserTextResult, InteractiveBrowser, InteractiveBrowserActionError, InteractiveBrowserBusyError, InteractiveBrowserCapacityError, InteractiveBrowserExpiredError, InteractiveBrowserLimitError, InteractiveBrowserPolicy, InteractiveBrowserPolicyDeniedError, InteractiveBrowserProtocolError, InteractiveBrowserTargetUrl, InteractiveBrowserUnsupportedError } from "effect-agent/interactive-browser";
6
+ import puppeteer from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js";
7
7
  //#region src/internal/browser-failure.ts
8
8
  /** Source-authored stages and classifications only; never retain SDK text or session capabilities. */
9
9
  var BrowserRunFailure = class extends Data.TaggedError("BrowserRunFailure") {
@@ -68,29 +68,60 @@ var BrowserRunBinding = class extends Context.Service()("@effect-agent/platform-
68
68
  }
69
69
  return Schema.decodeUnknownSync(Acquired)(await response.json()).sessionId;
70
70
  },
71
- connect: async (sessionId, operation) => {
72
- let failure;
71
+ connect: async (sessionId, operation, signal) => {
72
+ let socket;
73
+ let closedByAbort = false;
73
74
  try {
74
- return await puppeteer.connect({ fetch: async (input, init) => {
75
+ const response = await browser.fetch(`https://browser-rendering.cloudflare.com/v1/devtools/browser/${sessionId}`, {
76
+ headers: { Upgrade: "websocket" },
77
+ ...signal === void 0 ? {} : { signal }
78
+ });
79
+ if (response.status !== 101) {
80
+ const failure = new BrowserRunFailure({
81
+ operation,
82
+ reason: "provider",
83
+ status: response.status
84
+ });
75
85
  try {
76
- const response = await browser.fetch(input, init);
77
- if (response.status !== 101) {
78
- failure = new BrowserRunFailure({
79
- operation,
80
- reason: "provider",
81
- status: response.status
82
- });
83
- await response.body?.cancel();
84
- throw failure;
85
- }
86
- return response;
87
- } catch (cause) {
88
- failure ??= browserFailure(operation, cause);
89
- throw failure;
90
- }
91
- } }, sessionId);
86
+ await response.body?.cancel();
87
+ } catch {}
88
+ throw failure;
89
+ }
90
+ const connected = response.webSocket;
91
+ if (connected === null) throw new BrowserRunFailure({
92
+ operation,
93
+ reason: "malformed"
94
+ });
95
+ socket = connected;
96
+ const transport = {
97
+ send: (message) => connected.send(message),
98
+ close: () => connected.close()
99
+ };
100
+ connected.addEventListener("message", (event) => {
101
+ transport.onmessage?.(event.data);
102
+ });
103
+ connected.addEventListener("close", () => transport.onclose?.());
104
+ connected.accept();
105
+ const abort = () => {
106
+ try {
107
+ const wasOpen = connected.readyState === WebSocket.OPEN;
108
+ connected.close();
109
+ closedByAbort = wasOpen;
110
+ } catch {}
111
+ };
112
+ signal?.addEventListener("abort", abort, { once: true });
113
+ try {
114
+ signal?.throwIfAborted();
115
+ return await puppeteer.connect({ transport });
116
+ } finally {
117
+ signal?.removeEventListener("abort", abort);
118
+ }
92
119
  } catch (cause) {
93
- throw failure ?? browserFailure(operation, cause);
120
+ try {
121
+ socket?.close();
122
+ } catch {}
123
+ const failure = browserFailure(operation, cause);
124
+ throw cause instanceof Error && signal?.aborted === true && (cause === signal.reason || closedByAbort && cause.name === "TargetCloseError") ? reportedBrowserError(failure) : failure;
94
125
  }
95
126
  }
96
127
  });
@@ -412,7 +443,7 @@ var BrowserRunInteractiveBinding = class BrowserRunInteractiveBinding extends Co
412
443
  const viewport = options.viewport === void 0 ? void 0 : yield* decodeViewport(options.viewport);
413
444
  return {
414
445
  acquire: async (keepAliveMillis) => binding.acquire(keepAliveMillis, "interactive.acquire"),
415
- connect: async (sessionId) => makeProductionBrowser(await binding.connect(sessionId, "interactive.connect"), viewport),
446
+ connect: async (sessionId, signal) => makeProductionBrowser(await binding.connect(sessionId, "interactive.connect", signal), sessionId, viewport),
416
447
  closeSession: (sessionId) => lifecycle.close(sessionId).pipe(Effect.mapError((cause) => actionError("close", cause)))
417
448
  };
418
449
  })).pipe(Layer.provide(BrowserRunBinding.layer(options.browser)));
@@ -952,7 +983,7 @@ const makeProductionContext = (context, viewport) => ({
952
983
  }
953
984
  }
954
985
  });
955
- const makeProductionBrowser = (browser, viewport) => ({
986
+ const makeProductionBrowser = (browser, sessionId, viewport) => ({
956
987
  detach: () => browser.disconnect(),
957
988
  reattach: async (identity) => {
958
989
  const context = browser.browserContexts().find((candidate) => candidate.id === identity.contextId);
@@ -976,7 +1007,7 @@ const makeProductionBrowser = (browser, viewport) => ({
976
1007
  if (!isRemoteClosure(cause)) throw cause;
977
1008
  }
978
1009
  },
979
- sessionId: () => browser.sessionId(),
1010
+ sessionId: () => sessionId,
980
1011
  isConnected: () => browser.isConnected(),
981
1012
  onDisconnected: (listener) => {
982
1013
  browser.on("disconnected", listener);
@@ -1548,7 +1579,7 @@ const makeHostService = (binding) => {
1548
1579
  if (!lifecycle.managedTeardownInstalled) releaseOwner();
1549
1580
  }));
1550
1581
  const browser = yield* Effect.acquireRelease(withinDeadline(Effect.tryPromise({
1551
- try: (signal) => observeLate(signal, closeLateAcquisition(signal, () => binding.connect(sessionIdValue), (acquired) => runCleanup(resume === void 0 ? closeAcquired(acquired) : closeEntry(acquired.detach ?? (async () => {}), "Detaching the browser failed").close))),
1582
+ try: (signal) => observeLate(signal, closeLateAcquisition(signal, () => binding.connect(sessionIdValue, signal), (acquired) => runCleanup(resume === void 0 ? closeAcquired(acquired) : closeEntry(acquired.detach ?? (async () => {}), "Detaching the browser failed").close))),
1552
1583
  catch: (cause) => resume !== void 0 && cause instanceof BrowserRunFailure && (cause.status === 404 || cause.status === 410) ? expiredError() : protocolError("Connecting to the Browser Run session failed", cause)
1553
1584
  }).pipe(Effect.timeoutOrElse({
1554
1585
  duration: "10 seconds",
@@ -1746,4 +1777,4 @@ const CloudflareInteractiveBrowser = {
1746
1777
  //#endregion
1747
1778
  export { reportBrowserCause as C, inheritBrowserReport as S, BrowserRunCleanupError as _, BrowserRunInteractiveCheckpoint as a, BrowserRunFailure as b, BrowserRunLiveViewResult as c, BrowserRunViewport as d, CloudflareInteractiveBrowser as f, isBrowserRunUndispatchedActionError as g, browserRunInteractiveLayer as h, BrowserRunInteractiveBinding as i, BrowserRunPageIdentity as l, browserRunInteractiveImplementation as m, BrowserRunHandoffResult as n, BrowserRunInteractiveHost as o, browserRunInteractiveHostLayer as p, BrowserRunHandoffState as r, BrowserRunLiveViewRequest as s, BrowserRunHandoffRequest as t, BrowserRunPageObservation as u, BrowserRunSessionLifecycle as v, reportedBrowserError as w, browserFailure as x, BrowserRunBinding as y };
1748
1779
 
1749
- //# sourceMappingURL=InteractiveBrowser-CBUFAECo.mjs.map
1780
+ //# sourceMappingURL=InteractiveBrowser-DhOkdUx9.mjs.map