@yielded/agent-platform-cloudflare 0.1.0-beta.166 → 0.1.0-beta.168
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.
- package/dist/{Alarm-B0ODr1NE.mjs → Alarm-DxODgAZZ.mjs} +259 -159
- package/dist/Alarm-DxODgAZZ.mjs.map +1 -0
- package/dist/Alarm.d.mts +27 -36
- package/dist/Alarm.mjs +2 -2
- package/dist/BrowserCredentials-C5IWfi7f.d.mts +91 -0
- package/dist/BrowserCredentials.d.mts +2 -91
- package/dist/BrowserRestCapture.mjs +3 -3
- package/dist/BrowserRestCapture.mjs.map +1 -1
- package/dist/BrowserRestCrawl.mjs +6 -6
- package/dist/BrowserRestCrawl.mjs.map +1 -1
- package/dist/{BrowserSession-RfIzxGCH.mjs → BrowserSession-BfNmyayH.mjs} +5 -5
- package/dist/BrowserSession-BfNmyayH.mjs.map +1 -0
- package/dist/{BrowserSession-B969Xg-2.d.mts → BrowserSession-Bx0V1-6_.d.mts} +6 -3
- package/dist/BrowserSession.d.mts +1 -1
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse-AstK0jKX.mjs +1467 -0
- package/dist/BrowserUse-AstK0jKX.mjs.map +1 -0
- package/dist/BrowserUse.d.mts +83 -0
- package/dist/BrowserUse.mjs +2 -0
- package/dist/CloudflareBindings.d.mts +8 -1
- package/dist/CloudflareBindings.mjs +2 -2
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/{CloudflareBrowser-5an6m-Qb.mjs → CloudflareBrowser-Vt8qTdYW.mjs} +11 -13
- package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +1 -0
- package/dist/CloudflareBrowser.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs.map +1 -1
- package/dist/{CloudflareConfig-qDrRLofL.d.mts → CloudflareConfig-C9MvPbX8.d.mts} +9 -11
- package/dist/CloudflareConfig.d.mts +1 -1
- package/dist/CloudflareConfig.mjs +9 -12
- package/dist/CloudflareConfig.mjs.map +1 -1
- package/dist/CloudflareMemory.d.mts +3 -25
- package/dist/CloudflareMemory.mjs +33 -31
- package/dist/CloudflareMemory.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +8 -15
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.mjs +9 -16
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/CloudflareThreadClient-CZm0TvUe.mjs +588 -0
- package/dist/CloudflareThreadClient-CZm0TvUe.mjs.map +1 -0
- package/dist/CloudflareThreadClient-QsVzLGGZ.d.mts +2033 -0
- package/dist/CloudflareThreadClient.d.mts +2 -1796
- package/dist/CloudflareThreadClient.mjs +2 -382
- package/dist/{InteractiveBrowser-BbG3kGA9.mjs → InteractiveBrowser-LdKzQeLR.mjs} +18 -19
- package/dist/InteractiveBrowser-LdKzQeLR.mjs.map +1 -0
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/{ThreadObject-BcfXbzSO.d.mts → ThreadObject-7s5XnlH-.d.mts} +103 -79
- package/dist/{ThreadObject-DHjrnlX4.mjs → ThreadObject-C0vrcDrw.mjs} +265 -66
- package/dist/ThreadObject-C0vrcDrw.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +2 -2
- package/dist/ThreadObject.mjs +2 -3
- package/dist/WakeScheduler.d.mts +6 -5
- package/dist/WakeScheduler.mjs +15 -11
- package/dist/WakeScheduler.mjs.map +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +7 -6
- package/dist/page-function-CmUCcyNP.mjs +11 -0
- package/dist/page-function-CmUCcyNP.mjs.map +1 -0
- package/dist/{prepared-admission-DMX5p9dC.mjs → prepared-admission-3UUq0zth.mjs} +3 -3
- package/dist/{prepared-admission-DMX5p9dC.mjs.map → prepared-admission-3UUq0zth.mjs.map} +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +510 -279
- package/src/BrowserRestCapture.ts +2 -2
- package/src/BrowserRestCrawl.ts +10 -14
- package/src/BrowserSession.ts +10 -2
- package/src/BrowserUse.ts +1541 -0
- package/src/CloudflareBindings.ts +13 -4
- package/src/CloudflareCodeMode.ts +1 -1
- package/src/CloudflareConfig.ts +9 -12
- package/src/CloudflareMemory.ts +21 -28
- package/src/CloudflareScheduling.ts +7 -15
- package/src/CloudflareSubscriptions.ts +11 -20
- package/src/CloudflareThreadClient.ts +289 -9
- package/src/InteractiveBrowser.ts +325 -323
- package/src/ThreadObject.ts +172 -52
- package/src/WakeScheduler.ts +29 -18
- package/src/index.ts +1 -0
- package/src/internal/browser-dom.ts +845 -0
- package/src/internal/browser-file-selection.ts +8 -1
- package/src/internal/browser-jev-dom.ts +344 -0
- package/src/internal/browser-quick-action.ts +7 -8
- package/src/internal/browser-session-lifecycle.ts +2 -5
- package/src/internal/crypto.ts +41 -0
- package/src/internal/due-queue.ts +5 -69
- package/src/internal/layers.ts +100 -17
- package/src/internal/live-text-protocol.ts +51 -0
- package/src/internal/live-text.ts +256 -0
- package/src/internal/page-function.ts +12 -0
- package/src/internal/prepared-admission.ts +1 -1
- package/src/internal/progress-wait.ts +19 -24
- package/src/internal/transport.ts +1 -1
- package/dist/Alarm-B0ODr1NE.mjs.map +0 -1
- package/dist/BrowserSession-RfIzxGCH.mjs.map +0 -1
- package/dist/CloudflareBrowser-5an6m-Qb.mjs.map +0 -1
- package/dist/CloudflareThreadClient.mjs.map +0 -1
- package/dist/InteractiveBrowser-BbG3kGA9.mjs.map +0 -1
- package/dist/ThreadObject-DHjrnlX4.mjs.map +0 -1
|
@@ -1,382 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { AdmissionLimitExceeded } from "./CloudflareConfig.mjs";
|
|
4
|
-
import { r as safeCauseMessage, t as cloudflareFailureSignals } from "./boundary-BguazVkh.mjs";
|
|
5
|
-
import { n as DurableAlarmError } from "./Alarm-B0ODr1NE.mjs";
|
|
6
|
-
import { Receipt } from "@yielded/agent/durable-agent-runtime";
|
|
7
|
-
import { AgentId } from "@yielded/agent/identifiers";
|
|
8
|
-
import { AbortCommand, AbortIntent, AdmissionConflict, AdmissionFence, AdmissionGroup, AdmissionPolicyError, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, IdempotencyKey, JoinedToHost, LedgerError, Principal, Settlement, SettlementConflict, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent } from "@yielded/agent/submission-ledger";
|
|
9
|
-
import { Context, Crypto, Duration, Effect, Layer, Schema } from "effect";
|
|
10
|
-
import { RpcTracing } from "effect-cf";
|
|
11
|
-
import { CanonicalRecordEnvelope, CanonicalSequence, DefinitionDigests, PersistedJson, WorkerAdmission } from "@yielded/agent/records";
|
|
12
|
-
import { BrowserCrypto } from "@effect/platform-browser";
|
|
13
|
-
import { AgentInputError } from "@yielded/agent/agent-error";
|
|
14
|
-
import { DigestError } from "@yielded/agent/digest";
|
|
15
|
-
import { DurableRuntimeFailpointError } from "@yielded/agent/durable-failpoint";
|
|
16
|
-
import { InputMessage } from "@yielded/agent/messaging";
|
|
17
|
-
import { OperationDenied } from "@yielded/agent/operation-authorizer";
|
|
18
|
-
import { SubmissionStatus } from "@yielded/agent/submission-status";
|
|
19
|
-
import { AppendConflict, FenceRejected, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
|
|
20
|
-
//#region src/CloudflareThreadClient.ts
|
|
21
|
-
var CloudflareThreadClient_exports = /* @__PURE__ */ __exportAll({
|
|
22
|
-
AbortRecorded: () => AbortRecorded,
|
|
23
|
-
ApprovalRecorded: () => ApprovalRecorded,
|
|
24
|
-
AwaitProgressRequest: () => AwaitProgressRequest,
|
|
25
|
-
CancelProgressRequest: () => CancelProgressRequest,
|
|
26
|
-
CloudflareThreadClient: () => CloudflareThreadClient,
|
|
27
|
-
HostFailed: () => HostFailed,
|
|
28
|
-
HostFailure: () => HostFailure,
|
|
29
|
-
HostProtocolError: () => HostProtocolError,
|
|
30
|
-
HostResponse: () => HostResponse,
|
|
31
|
-
ObservePageRequest: () => ObservePageRequest,
|
|
32
|
-
ObservedPage: () => ObservedPage,
|
|
33
|
-
ProgressCancelled: () => ProgressCancelled,
|
|
34
|
-
ProgressObserved: () => ProgressObserved,
|
|
35
|
-
SettlementReached: () => SettlementReached,
|
|
36
|
-
SubmissionStatusResponse: () => SubmissionStatusResponse,
|
|
37
|
-
SubmitRequest: () => SubmitRequest,
|
|
38
|
-
SubmitSucceeded: () => SubmitSucceeded,
|
|
39
|
-
ThreadClientError: () => ThreadClientError,
|
|
40
|
-
UnknownResolutionRecorded: () => UnknownResolutionRecorded,
|
|
41
|
-
boundHostDiagnostic: () => boundHostDiagnostic,
|
|
42
|
-
decodeAbortCommand: () => decodeAbortCommand,
|
|
43
|
-
decodeApprovalDecisionCommand: () => decodeApprovalDecisionCommand,
|
|
44
|
-
decodeAwaitProgressRequest: () => decodeAwaitProgressRequest,
|
|
45
|
-
decodeCancelProgressRequest: () => decodeCancelProgressRequest,
|
|
46
|
-
decodeHostResponse: () => decodeHostResponse,
|
|
47
|
-
decodeObservePageRequest: () => decodeObservePageRequest,
|
|
48
|
-
decodeReceipt: () => decodeReceipt,
|
|
49
|
-
decodeSubmitRequest: () => decodeSubmitRequest,
|
|
50
|
-
decodeUnknownResolutionCommand: () => decodeUnknownResolutionCommand,
|
|
51
|
-
encodeAbortCommand: () => encodeAbortCommand,
|
|
52
|
-
encodeApprovalDecisionCommand: () => encodeApprovalDecisionCommand,
|
|
53
|
-
encodeAwaitProgressRequest: () => encodeAwaitProgressRequest,
|
|
54
|
-
encodeCancelProgressRequest: () => encodeCancelProgressRequest,
|
|
55
|
-
encodeHostResponse: () => encodeHostResponse,
|
|
56
|
-
encodeObservePageRequest: () => encodeObservePageRequest,
|
|
57
|
-
encodeReceipt: () => encodeReceipt,
|
|
58
|
-
encodeSubmitRequest: () => encodeSubmitRequest,
|
|
59
|
-
encodeUnknownResolutionCommand: () => encodeUnknownResolutionCommand
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* The Worker↔Thread-Object host protocol (plan §1.4): Schema envelopes for the host
|
|
63
|
-
* entry points (`submitEncoded`, `awaitSettlementEncoded`, `observePage`, `abortEncoded`,
|
|
64
|
-
* `resolveApprovalEncoded`, `resolveUnknownEncoded`) plus the Worker-side client that speaks
|
|
65
|
-
* it. Mirrors the WP2 port protocol: requests and responses are closed Schema unions, typed
|
|
66
|
-
* failures travel as their own tagged classes and RE-DECODE to identical tags on the caller
|
|
67
|
-
* (error-tag fidelity), and protocol anomalies are answered typed instead of thrown.
|
|
68
|
-
*/
|
|
69
|
-
/** Ceiling for host protocol diagnostic strings. */
|
|
70
|
-
const MAX_HOST_DIAGNOSTIC_LENGTH = 4096;
|
|
71
|
-
const PROGRESS_CANCELLATION_TIMEOUT = "1 second";
|
|
72
|
-
const BoundedDiagnostic = Schema.String.check(Schema.isMaxLength(MAX_HOST_DIAGNOSTIC_LENGTH));
|
|
73
|
-
/** Truncate a diagnostic string to the host protocol's bounded length. */
|
|
74
|
-
const boundHostDiagnostic = (value) => value.length > MAX_HOST_DIAGNOSTIC_LENGTH ? `${value.slice(0, 4093)}...` : value;
|
|
75
|
-
/**
|
|
76
|
-
* The envelope itself could not be honored: the Object could not decode the request, or a
|
|
77
|
-
* response could not be encoded/decoded. Never carries operation semantics.
|
|
78
|
-
*/
|
|
79
|
-
var HostProtocolError = class extends Schema.TaggedError()("HostProtocolError", { message: BoundedDiagnostic }) {};
|
|
80
|
-
/** The Worker-side stub call itself failed (RPC rejection, overload, eviction mid-call). */
|
|
81
|
-
var ThreadClientError = class extends Schema.TaggedError()("ThreadClientError", {
|
|
82
|
-
threadId: Schema.String,
|
|
83
|
-
message: Schema.String,
|
|
84
|
-
cause: Schema.optionalKey(Schema.Defect()),
|
|
85
|
-
/** Cloudflare's own classification for a failure safe to retry with a fresh stub. */
|
|
86
|
-
retryable: Schema.optionalKey(Schema.Boolean),
|
|
87
|
-
/** Cloudflare overloads are surfaced immediately instead of adding retry pressure. */
|
|
88
|
-
overloaded: Schema.optionalKey(Schema.Boolean)
|
|
89
|
-
}) {};
|
|
90
|
-
/**
|
|
91
|
-
* One durable submission, input ALREADY encoded by the caller through the Agent Binding's
|
|
92
|
-
* input schema (the Worker bundles the same Agent definitions as the Object, so schema
|
|
93
|
-
* validation happens client-side; the resolved Binding re-validates at claim time). The
|
|
94
|
-
* Thread identity is deliberately absent — the addressed Object IS the lane.
|
|
95
|
-
*/
|
|
96
|
-
var SubmitRequest = class extends Schema.Class("@effect-agent/platform-cloudflare/SubmitRequest")({
|
|
97
|
-
agentId: AgentId,
|
|
98
|
-
principal: Principal,
|
|
99
|
-
idempotencyKey: IdempotencyKey,
|
|
100
|
-
admissionGroup: Schema.optionalKey(AdmissionGroup),
|
|
101
|
-
admissionFence: Schema.optionalKey(AdmissionFence),
|
|
102
|
-
workerAdmission: Schema.optionalKey(WorkerAdmission),
|
|
103
|
-
messageAdmission: Schema.optionalKey(InputMessage),
|
|
104
|
-
definitions: DefinitionDigests,
|
|
105
|
-
inputPayload: PersistedJson
|
|
106
|
-
}) {};
|
|
107
|
-
/** One bounded page of canonical records after an optional sequence. */
|
|
108
|
-
var ObservePageRequest = class extends Schema.Class("@effect-agent/platform-cloudflare/ObservePageRequest")({
|
|
109
|
-
afterSequence: Schema.optionalKey(CanonicalSequence),
|
|
110
|
-
limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1024))
|
|
111
|
-
}) {};
|
|
112
|
-
/** One event-driven wait for canonical progress strictly after this sequence. */
|
|
113
|
-
var AwaitProgressRequest = class extends Schema.Class("@effect-agent/platform-cloudflare/AwaitProgressRequest")({
|
|
114
|
-
afterSequence: CanonicalSequence,
|
|
115
|
-
waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256))
|
|
116
|
-
}) {};
|
|
117
|
-
/** Best-effort cancellation of one in-flight progress RPC. */
|
|
118
|
-
var CancelProgressRequest = class extends Schema.Class("@effect-agent/platform-cloudflare/CancelProgressRequest")({ waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)) }) {};
|
|
119
|
-
/**
|
|
120
|
-
* Every typed failure a host entry point can produce, plus the protocol's own errors. Same
|
|
121
|
-
* closed-union discipline as the WP2 `PortFailure`: members re-decode to the SAME tagged
|
|
122
|
-
* classes on the Worker side; `cause` chains travel as Schema defects without instance
|
|
123
|
-
* fidelity (plan §2.8).
|
|
124
|
-
*/
|
|
125
|
-
const HostFailure = Schema.Union([
|
|
126
|
-
AgentInputError,
|
|
127
|
-
DigestError,
|
|
128
|
-
AdmissionConflict,
|
|
129
|
-
AdmissionPolicyError,
|
|
130
|
-
SettlementConflict,
|
|
131
|
-
ApprovalConflict,
|
|
132
|
-
UnknownResolutionConflict,
|
|
133
|
-
JoinedToHost,
|
|
134
|
-
LedgerError,
|
|
135
|
-
ThreadStoreError,
|
|
136
|
-
ThreadNotMaterialized,
|
|
137
|
-
AppendConflict,
|
|
138
|
-
FenceRejected,
|
|
139
|
-
DurableRuntimeFailpointError,
|
|
140
|
-
AdmissionLimitExceeded,
|
|
141
|
-
DurableAlarmError,
|
|
142
|
-
OperationDenied,
|
|
143
|
-
HostProtocolError
|
|
144
|
-
]);
|
|
145
|
-
var SubmitSucceeded = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/SubmitSucceeded")("SubmitSucceeded", { receipt: Receipt }) {};
|
|
146
|
-
var SubmissionStatusResponse = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/SubmissionStatusResponse")("SubmissionStatusResponse", { status: SubmissionStatus }) {};
|
|
147
|
-
var SettlementReached = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/SettlementReached")("SettlementReached", { settlement: Settlement }) {};
|
|
148
|
-
var ObservedPage = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/ObservedPage")("ObservedPage", { records: Schema.Array(CanonicalRecordEnvelope).check(Schema.isMaxLength(1024)) }) {};
|
|
149
|
-
/** A record was already committed or an incarnation-local hint says the caller should re-read. */
|
|
150
|
-
var ProgressObserved = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/ProgressObserved")("ProgressObserved", {}) {};
|
|
151
|
-
var ProgressCancelled = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/ProgressCancelled")("ProgressCancelled", {}) {};
|
|
152
|
-
var AbortRecorded = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/AbortRecorded")("AbortRecorded", { intent: AbortIntent }) {};
|
|
153
|
-
var ApprovalRecorded = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/ApprovalRecorded")("ApprovalRecorded", { intent: ApprovalDecisionIntent }) {};
|
|
154
|
-
var UnknownResolutionRecorded = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/UnknownResolutionRecorded")("UnknownResolutionRecorded", { intent: UnknownResolutionIntent }) {};
|
|
155
|
-
/** The entry point failed TYPED on the Object; the failure re-decodes verbatim. */
|
|
156
|
-
var HostFailed = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/HostFailed")("HostFailed", { failure: HostFailure }) {};
|
|
157
|
-
/** The uniform answer of one host entry point. Callers narrow by the tag their call implies. */
|
|
158
|
-
const HostResponse = Schema.Union([
|
|
159
|
-
SubmitSucceeded,
|
|
160
|
-
SettlementReached,
|
|
161
|
-
SubmissionStatusResponse,
|
|
162
|
-
ObservedPage,
|
|
163
|
-
ProgressObserved,
|
|
164
|
-
ProgressCancelled,
|
|
165
|
-
AbortRecorded,
|
|
166
|
-
ApprovalRecorded,
|
|
167
|
-
UnknownResolutionRecorded,
|
|
168
|
-
HostFailed
|
|
169
|
-
]);
|
|
170
|
-
const decodeSubmitRequest = Schema.decodeUnknownEffect(SubmitRequest);
|
|
171
|
-
const encodeSubmitRequest = Schema.encodeEffect(SubmitRequest);
|
|
172
|
-
const decodeReceipt = Schema.decodeUnknownEffect(Receipt);
|
|
173
|
-
const encodeReceipt = Schema.encodeEffect(Receipt);
|
|
174
|
-
const decodeObservePageRequest = Schema.decodeUnknownEffect(ObservePageRequest);
|
|
175
|
-
const encodeObservePageRequest = Schema.encodeEffect(ObservePageRequest);
|
|
176
|
-
const decodeAwaitProgressRequest = Schema.decodeUnknownEffect(AwaitProgressRequest);
|
|
177
|
-
const encodeAwaitProgressRequest = Schema.encodeEffect(AwaitProgressRequest);
|
|
178
|
-
const decodeCancelProgressRequest = Schema.decodeUnknownEffect(CancelProgressRequest);
|
|
179
|
-
const encodeCancelProgressRequest = Schema.encodeEffect(CancelProgressRequest);
|
|
180
|
-
const decodeAbortCommand = Schema.decodeUnknownEffect(AbortCommand);
|
|
181
|
-
const encodeAbortCommand = Schema.encodeEffect(AbortCommand);
|
|
182
|
-
const decodeApprovalDecisionCommand = Schema.decodeUnknownEffect(ApprovalDecisionCommand);
|
|
183
|
-
const encodeApprovalDecisionCommand = Schema.encodeEffect(ApprovalDecisionCommand);
|
|
184
|
-
const decodeUnknownResolutionCommand = Schema.decodeUnknownEffect(UnknownResolutionCommand);
|
|
185
|
-
const encodeUnknownResolutionCommand = Schema.encodeEffect(UnknownResolutionCommand);
|
|
186
|
-
const encodeHostResponse = Schema.encodeEffect(HostResponse);
|
|
187
|
-
const decodeHostResponse = Schema.decodeUnknownEffect(HostResponse);
|
|
188
|
-
/** Failure surface of `CloudflareThreadClient.submit`. */
|
|
189
|
-
const ClientSubmitHostFailure = Schema.Union([
|
|
190
|
-
AgentInputError,
|
|
191
|
-
DigestError,
|
|
192
|
-
AdmissionConflict,
|
|
193
|
-
AdmissionPolicyError,
|
|
194
|
-
LedgerError,
|
|
195
|
-
ThreadStoreError,
|
|
196
|
-
ThreadNotMaterialized,
|
|
197
|
-
AppendConflict,
|
|
198
|
-
FenceRejected,
|
|
199
|
-
DurableRuntimeFailpointError,
|
|
200
|
-
AdmissionLimitExceeded,
|
|
201
|
-
DurableAlarmError,
|
|
202
|
-
HostProtocolError
|
|
203
|
-
]);
|
|
204
|
-
const ClientAwaitHostFailure = Schema.Union([
|
|
205
|
-
LedgerError,
|
|
206
|
-
SettlementConflict,
|
|
207
|
-
OperationDenied,
|
|
208
|
-
HostProtocolError
|
|
209
|
-
]);
|
|
210
|
-
const ClientObserveHostFailure = Schema.Union([
|
|
211
|
-
ThreadStoreError,
|
|
212
|
-
ThreadNotMaterialized,
|
|
213
|
-
OperationDenied,
|
|
214
|
-
HostProtocolError
|
|
215
|
-
]);
|
|
216
|
-
const ClientAbortHostFailure = Schema.Union([
|
|
217
|
-
OperationDenied,
|
|
218
|
-
LedgerError,
|
|
219
|
-
SettlementConflict,
|
|
220
|
-
JoinedToHost,
|
|
221
|
-
DurableRuntimeFailpointError,
|
|
222
|
-
DurableAlarmError,
|
|
223
|
-
HostProtocolError
|
|
224
|
-
]);
|
|
225
|
-
const ClientApprovalHostFailure = Schema.Union([
|
|
226
|
-
LedgerError,
|
|
227
|
-
SettlementConflict,
|
|
228
|
-
ApprovalConflict,
|
|
229
|
-
OperationDenied,
|
|
230
|
-
DurableAlarmError,
|
|
231
|
-
HostProtocolError
|
|
232
|
-
]);
|
|
233
|
-
const ClientUnknownHostFailure = Schema.Union([
|
|
234
|
-
LedgerError,
|
|
235
|
-
SettlementConflict,
|
|
236
|
-
UnknownResolutionConflict,
|
|
237
|
-
JoinedToHost,
|
|
238
|
-
DurableRuntimeFailpointError,
|
|
239
|
-
OperationDenied,
|
|
240
|
-
DurableAlarmError,
|
|
241
|
-
HostProtocolError
|
|
242
|
-
]);
|
|
243
|
-
const outOfContract = (threadId, operation, observed) => ThreadClientError.make({
|
|
244
|
-
threadId,
|
|
245
|
-
message: boundHostDiagnostic(`The Thread Object answered ${operation} with the out-of-contract ${observed}.`)
|
|
246
|
-
});
|
|
247
|
-
const hostRpcMethods = {
|
|
248
|
-
submit: "submitEncoded",
|
|
249
|
-
awaitSettlement: "awaitSettlementEncoded",
|
|
250
|
-
submissionStatus: "submissionStatusEncoded",
|
|
251
|
-
awaitProgress: "awaitProgressEncoded",
|
|
252
|
-
cancelProgress: "cancelProgressEncoded",
|
|
253
|
-
observePage: "observePage",
|
|
254
|
-
abort: "abortEncoded",
|
|
255
|
-
resolveApproval: "resolveApprovalEncoded",
|
|
256
|
-
resolveUnknown: "resolveUnknownEncoded"
|
|
257
|
-
};
|
|
258
|
-
/** Worker-side client over the Thread Object namespace (DEPLOY-010). */
|
|
259
|
-
var CloudflareThreadClient = class CloudflareThreadClient extends Context.Service()("@effect-agent/platform-cloudflare/CloudflareThreadClient") {
|
|
260
|
-
/**
|
|
261
|
-
* Assemble the client from a resolved namespace and the platform Crypto implementation.
|
|
262
|
-
* rpcTracing is the binding name and remains opt-in. Caller authentication, principals,
|
|
263
|
-
* idempotency keys, and definition digests are still explicit submission inputs.
|
|
264
|
-
*/
|
|
265
|
-
static layerFromBinding(options) {
|
|
266
|
-
return CloudflareThreadClient.layer.pipe(Layer.provide([ThreadObjectNamespace.layer(options.namespace, options), BrowserCrypto.layer]));
|
|
267
|
-
}
|
|
268
|
-
static layer = Layer.effect(CloudflareThreadClient)(Effect.gen(function* () {
|
|
269
|
-
const namespace = yield* ThreadObjectNamespace;
|
|
270
|
-
const { rpcTracing } = namespace;
|
|
271
|
-
const crypto = yield* Crypto.Crypto;
|
|
272
|
-
const call = Effect.fn(function* (threadId, operation, encoded) {
|
|
273
|
-
const traceArgs = rpcTracing === void 0 ? [] : yield* RpcTracing.withRpcTraceContext([]);
|
|
274
|
-
const raw = yield* callThreadObject(threadId, (stub) => stub[hostRpcMethods[operation]](encoded, ...traceArgs), (cause) => ThreadClientError.make({
|
|
275
|
-
threadId,
|
|
276
|
-
message: boundHostDiagnostic(`${operation} did not reach the Thread Object: ${safeCauseMessage(cause, "the RPC failed without a diagnostic")}`),
|
|
277
|
-
cause,
|
|
278
|
-
...cloudflareFailureSignals(cause)
|
|
279
|
-
})).pipe(Effect.provideService(ThreadObjectNamespace, namespace));
|
|
280
|
-
return yield* decodeHostResponse(raw).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`The ${operation} answer could not be decoded: ${error.message}`) })));
|
|
281
|
-
}, (effect, threadId, operation) => rpcTracing === void 0 ? Effect.withSpan(effect, "CloudflareThreadClient.call", { attributes: {
|
|
282
|
-
threadId,
|
|
283
|
-
operation
|
|
284
|
-
} }) : RpcTracing.withRpcClientSpan(effect, rpcTracing, hostRpcMethods[operation]));
|
|
285
|
-
const expect = (threadId, operation, resultSchema, failureSchema) => {
|
|
286
|
-
const isExpectedResult = Schema.is(resultSchema);
|
|
287
|
-
const isExpectedFailure = Schema.is(failureSchema);
|
|
288
|
-
return (response) => {
|
|
289
|
-
if (response._tag === "HostFailed") {
|
|
290
|
-
const failure = response.failure;
|
|
291
|
-
return isExpectedFailure(failure) ? Effect.fail(failure) : Effect.fail(outOfContract(threadId, operation, `failure ${failure._tag}`));
|
|
292
|
-
}
|
|
293
|
-
if (!isExpectedResult(response)) return Effect.fail(outOfContract(threadId, operation, `result ${response._tag}`));
|
|
294
|
-
return Effect.succeed(response);
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
const readPage = (threadId, options) => Effect.gen(function* () {
|
|
298
|
-
const request = ObservePageRequest.make({
|
|
299
|
-
...options?.afterSequence === void 0 ? {} : { afterSequence: options.afterSequence },
|
|
300
|
-
limit: options?.limit ?? 256
|
|
301
|
-
});
|
|
302
|
-
const encoded = yield* encodeObservePageRequest(request).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`observePage request encode failed: ${error.message}`) })));
|
|
303
|
-
const response = yield* call(threadId, "observePage", encoded);
|
|
304
|
-
return (yield* expect(threadId, "observePage", ObservedPage, ClientObserveHostFailure)(response)).records;
|
|
305
|
-
});
|
|
306
|
-
const cancelProgress = (threadId, waiterId) => encodeCancelProgressRequest(CancelProgressRequest.make({ waiterId })).pipe(Effect.mapError(() => void 0), Effect.flatMap((encoded) => call(threadId, "cancelProgress", encoded)), Effect.interruptible, Effect.timeout(PROGRESS_CANCELLATION_TIMEOUT), Effect.asVoid, Effect.ignore);
|
|
307
|
-
return CloudflareThreadClient.of({
|
|
308
|
-
submit: (agent, input, options) => Effect.gen(function* () {
|
|
309
|
-
const encodedInput = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(Effect.mapError((cause) => AgentInputError.make({ message: `Unable to encode Agent input: ${cause.message}` })));
|
|
310
|
-
const inputPayload = yield* Schema.decodeUnknownEffect(PersistedJson)(encodedInput).pipe(Effect.mapError(() => AgentInputError.make({ message: "Agent input does not satisfy the canonical persistence bounds" })));
|
|
311
|
-
const request = SubmitRequest.make({
|
|
312
|
-
agentId: agent.definition.id,
|
|
313
|
-
principal: options.principal,
|
|
314
|
-
idempotencyKey: options.idempotencyKey,
|
|
315
|
-
...options.admissionGroup === void 0 ? {} : { admissionGroup: options.admissionGroup },
|
|
316
|
-
...options.admissionFence === void 0 ? {} : { admissionFence: options.admissionFence },
|
|
317
|
-
...options.workerAdmission === void 0 ? {} : { workerAdmission: options.workerAdmission },
|
|
318
|
-
...options.messageAdmission === void 0 ? {} : { messageAdmission: options.messageAdmission },
|
|
319
|
-
definitions: options.definitions,
|
|
320
|
-
inputPayload
|
|
321
|
-
});
|
|
322
|
-
const encoded = yield* encodeSubmitRequest(request).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`submit request encode failed: ${error.message}`) })));
|
|
323
|
-
const response = yield* call(options.threadId, "submit", encoded);
|
|
324
|
-
return (yield* expect(options.threadId, "submit", SubmitSucceeded, ClientSubmitHostFailure)(response)).receipt;
|
|
325
|
-
}),
|
|
326
|
-
submissionStatus: (receipt) => Effect.gen(function* () {
|
|
327
|
-
const encoded = yield* encodeReceipt(receipt).pipe(Effect.mapError(() => HostProtocolError.make({ message: "Invalid receipt" })));
|
|
328
|
-
const response = yield* call(receipt.threadId, "submissionStatus", encoded);
|
|
329
|
-
return (yield* expect(receipt.threadId, "submissionStatus", SubmissionStatusResponse, ClientAwaitHostFailure)(response)).status;
|
|
330
|
-
}),
|
|
331
|
-
awaitSettlement: (receipt) => Effect.gen(function* () {
|
|
332
|
-
const encoded = yield* encodeReceipt(receipt).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`receipt encode failed: ${error.message}`) })));
|
|
333
|
-
const response = yield* call(receipt.threadId, "awaitSettlement", encoded);
|
|
334
|
-
return (yield* expect(receipt.threadId, "awaitSettlement", SettlementReached, ClientAwaitHostFailure)(response)).settlement;
|
|
335
|
-
}),
|
|
336
|
-
awaitProgress: (threadId, afterSequence) => Effect.gen(function* () {
|
|
337
|
-
const waiterId = yield* crypto.randomUUIDv4.pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`awaitProgress cancellation identity generation failed: ${error.message}`) })));
|
|
338
|
-
const request = AwaitProgressRequest.make({
|
|
339
|
-
afterSequence,
|
|
340
|
-
waiterId
|
|
341
|
-
});
|
|
342
|
-
const encoded = yield* encodeAwaitProgressRequest(request).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`awaitProgress request encode failed: ${error.message}`) })));
|
|
343
|
-
const attempt = (retry) => call(threadId, "awaitProgress", encoded).pipe(Effect.flatMap(expect(threadId, "awaitProgress", ProgressObserved, ClientObserveHostFailure)), Effect.asVoid, Effect.catchTag("ThreadClientError", (error) => error.retryable === true && error.overloaded !== true && retry < 5 ? Effect.sleep(Duration.millis(10 * 2 ** retry)).pipe(Effect.andThen(attempt(retry + 1))) : Effect.fail(error)));
|
|
344
|
-
yield* attempt(0).pipe(Effect.onInterrupt(() => cancelProgress(threadId, waiterId)));
|
|
345
|
-
}),
|
|
346
|
-
readPage,
|
|
347
|
-
readAll: (threadId) => Effect.gen(function* () {
|
|
348
|
-
const all = [];
|
|
349
|
-
let after;
|
|
350
|
-
for (;;) {
|
|
351
|
-
const page = yield* readPage(threadId, {
|
|
352
|
-
afterSequence: after,
|
|
353
|
-
limit: 1024
|
|
354
|
-
});
|
|
355
|
-
all.push(...page);
|
|
356
|
-
const last = page.at(-1);
|
|
357
|
-
if (page.length < 1024 || last === void 0) return all;
|
|
358
|
-
after = last.sequence;
|
|
359
|
-
}
|
|
360
|
-
}),
|
|
361
|
-
abort: (threadId, command) => Effect.gen(function* () {
|
|
362
|
-
const encoded = yield* encodeAbortCommand(command).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`abort command encode failed: ${error.message}`) })));
|
|
363
|
-
const response = yield* call(threadId, "abort", encoded);
|
|
364
|
-
return (yield* expect(threadId, "abort", AbortRecorded, ClientAbortHostFailure)(response)).intent;
|
|
365
|
-
}),
|
|
366
|
-
resolveApproval: (threadId, command) => Effect.gen(function* () {
|
|
367
|
-
const encoded = yield* encodeApprovalDecisionCommand(command).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`approval command encode failed: ${error.message}`) })));
|
|
368
|
-
const response = yield* call(threadId, "resolveApproval", encoded);
|
|
369
|
-
return (yield* expect(threadId, "resolveApproval", ApprovalRecorded, ClientApprovalHostFailure)(response)).intent;
|
|
370
|
-
}),
|
|
371
|
-
resolveUnknown: (threadId, command) => Effect.gen(function* () {
|
|
372
|
-
const encoded = yield* encodeUnknownResolutionCommand(command).pipe(Effect.mapError((error) => HostProtocolError.make({ message: boundHostDiagnostic(`resolution command encode failed: ${error.message}`) })));
|
|
373
|
-
const response = yield* call(threadId, "resolveUnknown", encoded);
|
|
374
|
-
return (yield* expect(threadId, "resolveUnknown", UnknownResolutionRecorded, ClientUnknownHostFailure)(response)).intent;
|
|
375
|
-
})
|
|
376
|
-
});
|
|
377
|
-
}));
|
|
378
|
-
};
|
|
379
|
-
//#endregion
|
|
380
|
-
export { AbortRecorded, ApprovalRecorded, AwaitProgressRequest, CancelProgressRequest, CloudflareThreadClient, HostFailed, HostFailure, HostProtocolError, HostResponse, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, SettlementReached, SubmissionStatusResponse, SubmitRequest, SubmitSucceeded, ThreadClientError, UnknownResolutionRecorded, boundHostDiagnostic, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, CloudflareThreadClient_exports as t };
|
|
381
|
-
|
|
382
|
-
//# sourceMappingURL=CloudflareThreadClient.mjs.map
|
|
1
|
+
import { A as decodeSubmitRequest, B as encodeUnknownResolutionCommand, C as decodeAbortCommand, D as decodeHostResponse, E as decodeCancelProgressRequest, F as encodeCancelProgressRequest, I as encodeHostResponse, L as encodeObservePageRequest, M as encodeAbortCommand, N as encodeApprovalDecisionCommand, O as decodeObservePageRequest, P as encodeAwaitProgressRequest, R as encodeReceipt, S as boundHostDiagnostic, T as decodeAwaitProgressRequest, V as Frame, _ as SubmissionStatusResponse, a as CloudflareThreadClient, b as ThreadClientError, c as HostFailure, d as ObservePageRequest, f as ObservedPage, g as SettlementRecordReached, h as SettlementReached, i as CancelProgressRequest, j as decodeUnknownResolutionCommand, k as decodeReceipt, l as HostProtocolError, m as ProgressObserved, n as ApprovalRecorded, p as ProgressCancelled, r as AwaitProgressRequest, s as HostFailed, t as AbortRecorded, u as HostResponse, v as SubmitRequest, w as decodeApprovalDecisionCommand, x as UnknownResolutionRecorded, y as SubmitSucceeded, z as encodeSubmitRequest } from "./CloudflareThreadClient-CZm0TvUe.mjs";
|
|
2
|
+
export { AbortRecorded, ApprovalRecorded, AwaitProgressRequest, CancelProgressRequest, CloudflareThreadClient, HostFailed, HostFailure, HostProtocolError, HostResponse, Frame as LiveTextFrame, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, SettlementReached, SettlementRecordReached, SubmissionStatusResponse, SubmitRequest, SubmitSucceeded, ThreadClientError, UnknownResolutionRecorded, boundHostDiagnostic, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as pageFunction } from "./page-function-CmUCcyNP.mjs";
|
|
1
2
|
import { Cause, Clock, Context, Data, Duration, Effect, ErrorReporter, Layer, Option, Predicate, Redacted, Schema, Scope, Semaphore, Stream } from "effect";
|
|
2
3
|
import { PageScreenshotResult } from "@yielded/agent/page-screenshot";
|
|
3
4
|
import { SandboxImplementation } from "@yielded/agent/sandbox";
|
|
@@ -296,7 +297,7 @@ const makeFileSelection = (page) => async (request, signal) => {
|
|
|
296
297
|
throw cause;
|
|
297
298
|
}
|
|
298
299
|
const select = async (element) => {
|
|
299
|
-
if (session === void 0) return element.evaluate(setFileSelection, encoded, request.fileName, request.mediaType);
|
|
300
|
+
if (session === void 0) return element.evaluate(pageFunction(setFileSelection), encoded, request.fileName, request.mediaType);
|
|
300
301
|
let onOpened = () => {};
|
|
301
302
|
let onAbort = () => {};
|
|
302
303
|
let timer;
|
|
@@ -370,7 +371,7 @@ var BrowserRunSessionLifecycle = class extends Context.Service()("@effect-agent/
|
|
|
370
371
|
return Layer.effect(this, Effect.gen(function* () {
|
|
371
372
|
if (!Schema.is(Account)(options.accountId) || Redacted.value(options.apiToken).length === 0) return yield* new BrowserRunCleanupError({ reason: "configuration" });
|
|
372
373
|
const client = yield* HttpClient.HttpClient;
|
|
373
|
-
const request = Effect.
|
|
374
|
+
const request = Effect.fnUntraced(function* (method, sessionId) {
|
|
374
375
|
const path = method === "DELETE" ? "browser" : "session";
|
|
375
376
|
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((cause) => new BrowserRunCleanupError({
|
|
376
377
|
reason: "provider",
|
|
@@ -425,7 +426,7 @@ var BrowserRunSessionLifecycle = class extends Context.Service()("@effect-agent/
|
|
|
425
426
|
if (result.sessionId !== sessionId) return yield* new BrowserRunCleanupError({ reason: "malformed" });
|
|
426
427
|
return result.endTime !== void 0 && result.endTime > 0;
|
|
427
428
|
});
|
|
428
|
-
return { close: Effect.
|
|
429
|
+
return { close: Effect.fnUntraced(function* (sessionId) {
|
|
429
430
|
const id = yield* Schema.decodeEffect(Identity)(Redacted.value(sessionId)).pipe(Effect.mapError(() => new BrowserRunCleanupError({ reason: "configuration" })));
|
|
430
431
|
if (yield* request("DELETE", id)) return;
|
|
431
432
|
for (let read = 0; read < 2; read++) if (yield* request("GET", id)) return;
|
|
@@ -785,7 +786,7 @@ const disposeActionHandles = async (handles) => {
|
|
|
785
786
|
await boundedBestEffort(Promise.allSettled(handles.map(async (handle) => handle.dispose())), ACTION_POST_STATE_MILLIS);
|
|
786
787
|
};
|
|
787
788
|
/** Runs entirely in the page realm for both observations and the last bound-element guard. */
|
|
788
|
-
const observePage = (target, requestedSelector, maximum, maximumControls, input) => {
|
|
789
|
+
const observePage = pageFunction((target, requestedSelector, maximum, maximumControls, input) => {
|
|
789
790
|
const pageDocument = Reflect.get(globalThis, "document");
|
|
790
791
|
const matches = requestedSelector === void 0 ? void 0 : Reflect.apply(Reflect.get(pageDocument, "querySelectorAll"), pageDocument, [requestedSelector]);
|
|
791
792
|
const selectorMatchCount = matches === void 0 || matches === null ? 1 : Math.min(1e4, Reflect.get(matches, "length"));
|
|
@@ -962,7 +963,7 @@ const observePage = (target, requestedSelector, maximum, maximumControls, input)
|
|
|
962
963
|
_tag: "Text",
|
|
963
964
|
text
|
|
964
965
|
};
|
|
965
|
-
};
|
|
966
|
+
});
|
|
966
967
|
const runObservedPageAction = async (page, selector, signal, onDispatch, action, validate, onComplete) => {
|
|
967
968
|
if (signal.aborted) throw new BrowserRunActionUndispatched(0);
|
|
968
969
|
const before = Schema.decodeUnknownSync(ActionTargetState)(await readActionTarget(page, selector));
|
|
@@ -1219,7 +1220,7 @@ const causeText = (cause) => {
|
|
|
1219
1220
|
const isCapacityRefusal = (cause) => cause instanceof BrowserRunFailure && cause.status === 429;
|
|
1220
1221
|
const isRemoteClosure = (cause) => /target closed|browser.*closed|session.*closed|connection.*closed|not connected|websocket.*closed/i.test(causeText(cause));
|
|
1221
1222
|
const inputMayStillRun = (cause) => isRemoteClosure(cause) || cause instanceof Error && cause.name === "TimeoutError" || cause instanceof BrowserRunFailure && cause.reason === "timeout";
|
|
1222
|
-
const snapshotPolicy = Effect.
|
|
1223
|
+
const snapshotPolicy = Effect.fnUntraced(function* (input) {
|
|
1223
1224
|
const decoded = yield* Schema.decodeEffect(InteractiveBrowserPolicy, { onExcessProperty: "error" })(input).pipe(Effect.mapError(() => policyError("The interactive browser policy is malformed")));
|
|
1224
1225
|
if (decoded.network._tag === "PublicWeb") return yield* InteractiveBrowserUnsupportedError.make({
|
|
1225
1226
|
implementation: browserRunInteractiveImplementation,
|
|
@@ -1262,7 +1263,7 @@ const closeWithWarning = (close, warning) => Effect.tryPromise({
|
|
|
1262
1263
|
duration: Duration.millis(CLEANUP_STEP_TIMEOUT_MILLIS),
|
|
1263
1264
|
orElse: () => Effect.fail(protocolError(warning))
|
|
1264
1265
|
}), Effect.catchCause((cause) => reportBrowserCause("interactive.cleanup", cause).pipe(Effect.andThen(Effect.logWarning(warning)))));
|
|
1265
|
-
const deadlineError = Effect.
|
|
1266
|
+
const deadlineError = Effect.fnUntraced(function* (policy, startedAt) {
|
|
1266
1267
|
const now = yield* Effect.clockWith((clock) => clock.currentTimeMillis);
|
|
1267
1268
|
return yield* InteractiveBrowserLimitError.make({
|
|
1268
1269
|
implementation: browserRunInteractiveImplementation,
|
|
@@ -1272,7 +1273,7 @@ const deadlineError = Effect.fn("BrowserRunInteractive.deadlineError")(function*
|
|
|
1272
1273
|
message: "The browser elapsed-time limit was reached"
|
|
1273
1274
|
});
|
|
1274
1275
|
});
|
|
1275
|
-
const withinDeadline = Effect.
|
|
1276
|
+
const withinDeadline = Effect.fnUntraced(function* (effect, policy, startedAt, onTimeout) {
|
|
1276
1277
|
const now = yield* Effect.clockWith((clock) => clock.currentTimeMillis);
|
|
1277
1278
|
const elapsed = Math.max(0, now - startedAt);
|
|
1278
1279
|
const remaining = policy.maxElapsedMillis - elapsed;
|
|
@@ -1315,7 +1316,7 @@ const awaitPendingRequests = (state) => Effect.suspend(() => {
|
|
|
1315
1316
|
const pending = [...state.pendingRequests];
|
|
1316
1317
|
return pending.length === 0 ? Effect.void : Effect.promise(() => Promise.all(pending)).pipe(Effect.asVoid, Effect.andThen(awaitPendingRequests(state)));
|
|
1317
1318
|
});
|
|
1318
|
-
const decodeNavigationResult = Effect.
|
|
1319
|
+
const decodeNavigationResult = Effect.fnUntraced(function* (page, policy) {
|
|
1319
1320
|
const url = yield* Effect.try({
|
|
1320
1321
|
try: page.url,
|
|
1321
1322
|
catch: (cause) => protocolError("Reading the browser navigation URL failed", cause)
|
|
@@ -1324,7 +1325,7 @@ const decodeNavigationResult = Effect.fn("BrowserRunInteractive.decodeNavigation
|
|
|
1324
1325
|
if (!hostAllowed(policy, result.url)) return yield* policyError("The browser returned an off-policy page URL");
|
|
1325
1326
|
return result;
|
|
1326
1327
|
});
|
|
1327
|
-
const decodeActionResult = Effect.
|
|
1328
|
+
const decodeActionResult = Effect.fnUntraced(function* (page, policy) {
|
|
1328
1329
|
const url = yield* Effect.try({
|
|
1329
1330
|
try: page.url,
|
|
1330
1331
|
catch: (cause) => protocolError("Reading the browser page URL failed", cause)
|
|
@@ -1355,7 +1356,7 @@ const makeRequestListener = (policy, state) => (request) => {
|
|
|
1355
1356
|
});
|
|
1356
1357
|
state.pendingRequests.add(observed);
|
|
1357
1358
|
};
|
|
1358
|
-
const makeHandle = Effect.
|
|
1359
|
+
const makeHandle = Effect.fnUntraced(function* (page, policy, startedAt, state, close) {
|
|
1359
1360
|
const permits = yield* Semaphore.make(1);
|
|
1360
1361
|
let currentOperation;
|
|
1361
1362
|
let generation = 0;
|
|
@@ -1436,9 +1437,7 @@ const makeHandle = Effect.fn("BrowserRunInteractive.makeHandle")(function* (page
|
|
|
1436
1437
|
"browser.action_dispatched": evidence.dispatch !== "not-dispatched",
|
|
1437
1438
|
"browser.action_outcome_unknown": evidence.dispatch === "running" || evidence.dispatch === "unknown"
|
|
1438
1439
|
}))));
|
|
1439
|
-
const decodeActionObservation = Effect.
|
|
1440
|
-
return yield* Schema.decodeUnknownEffect(ActionObservation)(raw).pipe(Effect.mapError((cause) => protocolError("The browser returned a malformed action observation", cause)));
|
|
1441
|
-
});
|
|
1440
|
+
const decodeActionObservation = (raw) => Schema.decodeUnknownEffect(ActionObservation)(raw).pipe(Effect.mapError((cause) => protocolError("The browser returned a malformed action observation", cause)));
|
|
1442
1441
|
const logActionObservation = (operation, observation) => Effect.logInfo("Browser interactive action observed").pipe(Effect.annotateLogs({
|
|
1443
1442
|
"browser.action": operation,
|
|
1444
1443
|
"browser.input_millis": observation.inputMillis,
|
|
@@ -1605,7 +1604,7 @@ const makeHandle = Effect.fn("BrowserRunInteractive.makeHandle")(function* (page
|
|
|
1605
1604
|
run
|
|
1606
1605
|
};
|
|
1607
1606
|
});
|
|
1608
|
-
const remainingMillis = Effect.
|
|
1607
|
+
const remainingMillis = Effect.fnUntraced(function* (policy, startedAt) {
|
|
1609
1608
|
const now = yield* Effect.clockWith((clock) => clock.currentTimeMillis);
|
|
1610
1609
|
return Math.max(0, policy.maxElapsedMillis - Math.max(0, now - startedAt));
|
|
1611
1610
|
});
|
|
@@ -1663,7 +1662,7 @@ const makeHostService = (binding) => {
|
|
|
1663
1662
|
const closeSession = (sessionId) => binding.closeSession(sessionId).pipe(Effect.tap(() => Effect.sync(() => {
|
|
1664
1663
|
owners.delete(Redacted.value(sessionId));
|
|
1665
1664
|
})));
|
|
1666
|
-
const terminate = Effect.
|
|
1665
|
+
const terminate = Effect.fnUntraced(function* (sessionId, entries) {
|
|
1667
1666
|
const deadline = (yield* Clock.currentTimeMillis) + 1e4;
|
|
1668
1667
|
yield* closeSession(sessionId).pipe(Effect.interruptible, Effect.timeoutOrElse({
|
|
1669
1668
|
duration: "10 seconds",
|
|
@@ -1673,14 +1672,14 @@ const makeHostService = (binding) => {
|
|
|
1673
1672
|
if (remaining <= 0) return yield* Effect.logWarning("Local browser teardown skipped after confirmed termination deadline");
|
|
1674
1673
|
yield* runTeardown(entries).pipe(Effect.flatMap((failures) => Effect.forEach(failures, (failure) => reportBrowserCause("interactive.cleanup", Cause.fail(failure.error)).pipe(Effect.andThen(Effect.logWarning(failure.warning))), { discard: true })), Effect.interruptible, Effect.timeout(`${remaining} millis`), Effect.catchCause((cause) => reportBrowserCause("interactive.cleanup", cause).pipe(Effect.andThen(Effect.logWarning("Local browser teardown incomplete after confirmed termination")))));
|
|
1675
1674
|
});
|
|
1676
|
-
const closeAcquired = Effect.
|
|
1675
|
+
const closeAcquired = Effect.fnUntraced(function* (browser) {
|
|
1677
1676
|
const sessionId = yield* Effect.try({
|
|
1678
1677
|
try: browser.sessionId,
|
|
1679
1678
|
catch: (cause) => actionError("close", cause)
|
|
1680
1679
|
}).pipe(Effect.flatMap(Schema.decodeUnknownEffect(BrowserRunSessionId)), Effect.mapError((cause) => actionError("close", cause)), Effect.onError(() => closeWithWarning(browser.close, "Closing an unidentified browser failed")));
|
|
1681
1680
|
yield* terminate(Redacted.make(sessionId), [closeEntry(browser.close, "Closing the local browser connection failed")]);
|
|
1682
1681
|
});
|
|
1683
|
-
const acquire = Effect.
|
|
1682
|
+
const acquire = Effect.fnUntraced(function* (policy, resume, pendingInput = false) {
|
|
1684
1683
|
const scope = yield* Scope.Scope;
|
|
1685
1684
|
const fixedPolicy = yield* snapshotPolicy(policy);
|
|
1686
1685
|
const startedAt = resume?.startedAt ?? (yield* Clock.currentTimeMillis);
|
|
@@ -1931,4 +1930,4 @@ const CloudflareInteractiveBrowser = {
|
|
|
1931
1930
|
//#endregion
|
|
1932
1931
|
export { reportedBrowserError as C, reportBrowserCause 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, browserFailure as x, BrowserRunBinding as y };
|
|
1933
1932
|
|
|
1934
|
-
//# sourceMappingURL=InteractiveBrowser-
|
|
1933
|
+
//# sourceMappingURL=InteractiveBrowser-LdKzQeLR.mjs.map
|