@effect-agent/platform-cloudflare 0.1.0-beta.25 → 0.1.0-beta.27
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/browser-quick-action.d.mts +68 -0
- package/dist/browser-quick-action.mjs +303 -0
- package/dist/browser-quick-action.mjs.map +1 -0
- package/dist/index.d.mts +107 -35
- package/dist/index.mjs +43 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -9
- package/src/browser-quick-action.ts +514 -0
- package/src/code-mode-executor.ts +31 -82
- package/src/index.ts +1 -0
- package/src/layers.ts +6 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { PageCapture, PageCaptureRequest, SandboxImplementation } from "@effect-agent/sandbox";
|
|
3
|
+
//#region src/browser-quick-action.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Cloudflare Browser Run Quick Action `PageCapture` adapter (capability
|
|
6
|
+
* spec §9.2). Each capture is one stateless `quickAction()` RPC on the
|
|
7
|
+
* Wrangler `browser` binding: the platform renders the target in a managed
|
|
8
|
+
* headless browser and returns one bounded output; the adapter holds no
|
|
9
|
+
* session and no state between passes. The binding requires a Worker
|
|
10
|
+
* compatibility date of `2026-03-24` or later, and local `wrangler dev` needs
|
|
11
|
+
* remote mode (`"remote": true` on the binding) because `quickAction` has no
|
|
12
|
+
* local implementation.
|
|
13
|
+
*
|
|
14
|
+
* Rendered output is untrusted, attacker-influenced content; this adapter
|
|
15
|
+
* only bounds and types it. Deployment class `E` only: no durability claim.
|
|
16
|
+
*/
|
|
17
|
+
declare const browserQuickActionImplementation: SandboxImplementation;
|
|
18
|
+
/**
|
|
19
|
+
* Effect-native client captured by the binding service. Its option types come
|
|
20
|
+
* directly from the pinned Workers declarations rather than a local copy.
|
|
21
|
+
*/
|
|
22
|
+
interface BrowserQuickActionClient {
|
|
23
|
+
readonly content: (options: BrowserRunContentOptions) => Effect.Effect<Response, BrowserQuickActionRpcError>;
|
|
24
|
+
readonly markdown: (options: BrowserRunMarkdownOptions) => Effect.Effect<Response, BrowserQuickActionRpcError>;
|
|
25
|
+
readonly links: (options: BrowserRunLinksOptions) => Effect.Effect<Response, BrowserQuickActionRpcError>;
|
|
26
|
+
readonly json: (options: BrowserRunJsonOptions) => Effect.Effect<Response, BrowserQuickActionRpcError>;
|
|
27
|
+
}
|
|
28
|
+
declare const BrowserQuickActionRpcError_base: Schema.Class<BrowserQuickActionRpcError, Schema.TaggedStruct<"BrowserQuickActionRpcError", {
|
|
29
|
+
readonly action: Schema.Literals<readonly ["content", "markdown", "links", "json"]>;
|
|
30
|
+
readonly cause: Schema.Defect;
|
|
31
|
+
}>, import("effect/Cause").YieldableError>;
|
|
32
|
+
/** A native binding RPC rejected before it returned an HTTP response. */
|
|
33
|
+
declare class BrowserQuickActionRpcError extends BrowserQuickActionRpcError_base {}
|
|
34
|
+
interface BrowserQuickActionCaptureOptions {
|
|
35
|
+
/** The resolved Wrangler `browser` binding (DEPLOY-014: supplied, never ambient). */
|
|
36
|
+
readonly browser: BrowserRun;
|
|
37
|
+
}
|
|
38
|
+
declare const BrowserQuickActionBrowserBinding_base: Context.ServiceClass<BrowserQuickActionBrowserBinding, "@effect-agent/platform-cloudflare/BrowserQuickActionBrowserBinding", BrowserQuickActionClient>;
|
|
39
|
+
/** Host-owned browser binding authority, supplied explicitly at the composition root. */
|
|
40
|
+
declare class BrowserQuickActionBrowserBinding extends BrowserQuickActionBrowserBinding_base {
|
|
41
|
+
static layer(options: BrowserQuickActionCaptureOptions): Layer.Layer<BrowserQuickActionBrowserBinding>;
|
|
42
|
+
}
|
|
43
|
+
/** Host-owned authorization and accounting for one Workers AI extraction. */
|
|
44
|
+
interface BrowserQuickActionWorkersAiPolicy {
|
|
45
|
+
readonly authorizeAndAccount: (request: PageCaptureRequest) => Effect.Effect<void, BrowserQuickActionWorkersAiPolicyError>;
|
|
46
|
+
}
|
|
47
|
+
declare const BrowserQuickActionWorkersAiPolicyError_base: Schema.Class<BrowserQuickActionWorkersAiPolicyError, Schema.TaggedStruct<"BrowserQuickActionWorkersAiPolicyError", {
|
|
48
|
+
readonly reason: Schema.Literals<readonly ["authorization", "accounting"]>;
|
|
49
|
+
readonly message: Schema.String;
|
|
50
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
51
|
+
}>, import("effect/Cause").YieldableError>;
|
|
52
|
+
/** Host-only diagnostic for a denied or unaccounted Workers AI extraction. */
|
|
53
|
+
declare class BrowserQuickActionWorkersAiPolicyError extends BrowserQuickActionWorkersAiPolicyError_base {}
|
|
54
|
+
declare const BrowserQuickActionWorkersAi_base: Context.ServiceClass<BrowserQuickActionWorkersAi, "@effect-agent/platform-cloudflare/BrowserQuickActionWorkersAi", BrowserQuickActionWorkersAiPolicy>;
|
|
55
|
+
/** Explicit host-owned authority and accounting for separately billed Workers AI extraction. */
|
|
56
|
+
declare class BrowserQuickActionWorkersAi extends BrowserQuickActionWorkersAi_base {
|
|
57
|
+
static layer(policy: BrowserQuickActionWorkersAiPolicy): Layer.Layer<BrowserQuickActionWorkersAi>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ordinary Quick Actions require host-owned browser binding authority. Workers
|
|
61
|
+
* AI stays unavailable unless the host deliberately selects its separate Layer.
|
|
62
|
+
*/
|
|
63
|
+
declare const browserQuickActionCaptureLayer: () => Layer.Layer<PageCapture, never, BrowserQuickActionBrowserBinding>;
|
|
64
|
+
/** Structured Quick Actions require host-owned browser and Workers AI authority. */
|
|
65
|
+
declare const browserQuickActionWorkersAiCaptureLayer: () => Layer.Layer<PageCapture, never, BrowserQuickActionBrowserBinding | BrowserQuickActionWorkersAi>;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BrowserQuickActionBrowserBinding, BrowserQuickActionCaptureOptions, BrowserQuickActionClient, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicy, BrowserQuickActionWorkersAiPolicyError, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer };
|
|
68
|
+
//# sourceMappingURL=browser-quick-action.d.mts.map
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option, Schema } from "effect";
|
|
2
|
+
import { PageCapture, PageCaptureInferencePolicyError, PageCaptureInferenceUse, PageCaptureNavigationError, PageCaptureOutputLimitError, PageCaptureProtocolError, PageCaptureRateLimitedError, PageCaptureResourceUse, PageCaptureResult, PageCaptureUnsupportedError, PageContentCaptured, PageLinksCaptured, PageMarkdownCaptured, PageStructuredCaptured, SandboxImplementation } from "@effect-agent/sandbox";
|
|
3
|
+
//#region src/browser-quick-action.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Cloudflare Browser Run Quick Action `PageCapture` adapter (capability
|
|
6
|
+
* spec §9.2). Each capture is one stateless `quickAction()` RPC on the
|
|
7
|
+
* Wrangler `browser` binding: the platform renders the target in a managed
|
|
8
|
+
* headless browser and returns one bounded output; the adapter holds no
|
|
9
|
+
* session and no state between passes. The binding requires a Worker
|
|
10
|
+
* compatibility date of `2026-03-24` or later, and local `wrangler dev` needs
|
|
11
|
+
* remote mode (`"remote": true` on the binding) because `quickAction` has no
|
|
12
|
+
* local implementation.
|
|
13
|
+
*
|
|
14
|
+
* Rendered output is untrusted, attacker-influenced content; this adapter
|
|
15
|
+
* only bounds and types it. Deployment class `E` only: no durability claim.
|
|
16
|
+
*/
|
|
17
|
+
const browserQuickActionImplementation = SandboxImplementation.make({
|
|
18
|
+
isolation: "isolated",
|
|
19
|
+
identity: "cloudflare-browser-quick-action"
|
|
20
|
+
});
|
|
21
|
+
/** A native binding RPC rejected before it returned an HTTP response. */
|
|
22
|
+
var BrowserQuickActionRpcError = class extends Schema.TaggedError()("BrowserQuickActionRpcError", {
|
|
23
|
+
action: Schema.Literals([
|
|
24
|
+
"content",
|
|
25
|
+
"markdown",
|
|
26
|
+
"links",
|
|
27
|
+
"json"
|
|
28
|
+
]),
|
|
29
|
+
cause: Schema.Defect()
|
|
30
|
+
}) {};
|
|
31
|
+
/** Host-owned browser binding authority, supplied explicitly at the composition root. */
|
|
32
|
+
var BrowserQuickActionBrowserBinding = class BrowserQuickActionBrowserBinding extends Context.Service()("@effect-agent/platform-cloudflare/BrowserQuickActionBrowserBinding") {
|
|
33
|
+
static layer(options) {
|
|
34
|
+
const browser = options.browser;
|
|
35
|
+
const invoke = Effect.fn("BrowserQuickActionBrowserBinding.invoke")(function* (action, evaluate) {
|
|
36
|
+
return yield* Effect.tryPromise({
|
|
37
|
+
try: evaluate,
|
|
38
|
+
catch: (cause) => BrowserQuickActionRpcError.make({
|
|
39
|
+
action,
|
|
40
|
+
cause
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return Layer.succeed(BrowserQuickActionBrowserBinding)({
|
|
45
|
+
content: (request) => invoke("content", () => browser.quickAction("content", request)),
|
|
46
|
+
markdown: (request) => invoke("markdown", () => browser.quickAction("markdown", request)),
|
|
47
|
+
links: (request) => invoke("links", () => browser.quickAction("links", request)),
|
|
48
|
+
json: (request) => invoke("json", () => browser.quickAction("json", request))
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/** Host-only diagnostic for a denied or unaccounted Workers AI extraction. */
|
|
53
|
+
var BrowserQuickActionWorkersAiPolicyError = class extends Schema.TaggedError()("BrowserQuickActionWorkersAiPolicyError", {
|
|
54
|
+
reason: Schema.Literals(["authorization", "accounting"]),
|
|
55
|
+
message: Schema.String.check(Schema.isMaxLength(8e3)),
|
|
56
|
+
cause: Schema.optionalKey(Schema.Defect())
|
|
57
|
+
}) {};
|
|
58
|
+
/** Explicit host-owned authority and accounting for separately billed Workers AI extraction. */
|
|
59
|
+
var BrowserQuickActionWorkersAi = class BrowserQuickActionWorkersAi extends Context.Service()("@effect-agent/platform-cloudflare/BrowserQuickActionWorkersAi") {
|
|
60
|
+
static layer(policy) {
|
|
61
|
+
return Layer.succeed(BrowserQuickActionWorkersAi)(policy);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const MAX_DIAGNOSTIC_LENGTH = 8e3;
|
|
65
|
+
const boundedDiagnostic = (message) => message.slice(0, MAX_DIAGNOSTIC_LENGTH);
|
|
66
|
+
const QuickActionSuccessEnvelope = Schema.Struct({
|
|
67
|
+
success: Schema.Literal(true),
|
|
68
|
+
result: Schema.Json
|
|
69
|
+
});
|
|
70
|
+
const QuickActionErrorEnvelope = Schema.Struct({
|
|
71
|
+
success: Schema.Literal(false),
|
|
72
|
+
errors: Schema.Array(Schema.Struct({
|
|
73
|
+
message: Schema.String,
|
|
74
|
+
code: Schema.optionalKey(Schema.Number),
|
|
75
|
+
detail: Schema.optionalKey(Schema.String),
|
|
76
|
+
path: Schema.optionalKey(Schema.String)
|
|
77
|
+
})),
|
|
78
|
+
rawAiResponse: Schema.optionalKey(Schema.String)
|
|
79
|
+
});
|
|
80
|
+
const QuickActionEnvelope = Schema.Union([QuickActionSuccessEnvelope, QuickActionErrorEnvelope]);
|
|
81
|
+
const decodeEnvelope = Schema.decodeUnknownOption(Schema.fromJsonString(QuickActionEnvelope));
|
|
82
|
+
/** Project the schema-validated request onto Cloudflare's native common options. */
|
|
83
|
+
const quickActionCommonOptions = (request) => {
|
|
84
|
+
const options = {};
|
|
85
|
+
const navigation = request.navigation;
|
|
86
|
+
if (navigation !== void 0) {
|
|
87
|
+
const goto = {};
|
|
88
|
+
if (navigation.waitUntil !== void 0) goto.waitUntil = navigation.waitUntil;
|
|
89
|
+
if (navigation.timeoutMillis !== void 0) goto.timeout = navigation.timeoutMillis;
|
|
90
|
+
if (Object.keys(goto).length > 0) options.gotoOptions = goto;
|
|
91
|
+
if (navigation.waitForSelector !== void 0) options.waitForSelector = {
|
|
92
|
+
selector: navigation.waitForSelector.selector,
|
|
93
|
+
...navigation.waitForSelector.timeoutMillis === void 0 ? {} : { timeout: navigation.waitForSelector.timeoutMillis }
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (request.viewport !== void 0) options.viewport = {
|
|
97
|
+
width: request.viewport.width,
|
|
98
|
+
height: request.viewport.height
|
|
99
|
+
};
|
|
100
|
+
if (request.resourcePolicy !== void 0) {
|
|
101
|
+
if (request.resourcePolicy.rejectResourceTypes !== void 0) options.rejectResourceTypes = [...request.resourcePolicy.rejectResourceTypes];
|
|
102
|
+
if (request.resourcePolicy.allowRequestPatterns !== void 0) options.allowRequestPattern = [...request.resourcePolicy.allowRequestPatterns];
|
|
103
|
+
}
|
|
104
|
+
return request.target._tag === "PageUrlTarget" ? {
|
|
105
|
+
...options,
|
|
106
|
+
url: request.target.url
|
|
107
|
+
} : {
|
|
108
|
+
...options,
|
|
109
|
+
html: request.target.html
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** Dispatch through Cloudflare's native action-specific overloads. */
|
|
113
|
+
const executeQuickAction = (browser, request) => {
|
|
114
|
+
const options = quickActionCommonOptions(request);
|
|
115
|
+
switch (request.action._tag) {
|
|
116
|
+
case "CapturePageContent": return browser.content(options);
|
|
117
|
+
case "CapturePageMarkdown": return browser.markdown(options);
|
|
118
|
+
case "CapturePageLinks": return browser.links({
|
|
119
|
+
...options,
|
|
120
|
+
...request.action.visibleLinksOnly === void 0 ? {} : { visibleLinksOnly: request.action.visibleLinksOnly }
|
|
121
|
+
});
|
|
122
|
+
case "CapturePageStructured": return browser.json({
|
|
123
|
+
...options,
|
|
124
|
+
response_format: {
|
|
125
|
+
type: "json_schema",
|
|
126
|
+
json_schema: request.action.responseFormat
|
|
127
|
+
},
|
|
128
|
+
...request.action.prompt === void 0 ? {} : { prompt: request.action.prompt }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const protocolError = (message, cause) => PageCaptureProtocolError.make({
|
|
133
|
+
implementation: browserQuickActionImplementation,
|
|
134
|
+
message: boundedDiagnostic(message),
|
|
135
|
+
...cause === void 0 ? {} : { cause }
|
|
136
|
+
});
|
|
137
|
+
const navigationError = (message, cause) => PageCaptureNavigationError.make({
|
|
138
|
+
implementation: browserQuickActionImplementation,
|
|
139
|
+
message: boundedDiagnostic(message),
|
|
140
|
+
...cause === void 0 ? {} : { cause }
|
|
141
|
+
});
|
|
142
|
+
/** Preserve bounded remote diagnostics for the host without exposing their text to a model. */
|
|
143
|
+
const privateResponseCause = (bodyText) => bodyText.length === 0 ? void 0 : new Error(boundedDiagnostic(bodyText));
|
|
144
|
+
const releaseResponseReader = (reader) => Effect.tryPromise({
|
|
145
|
+
try: () => reader.cancel(),
|
|
146
|
+
catch: (cause) => protocolError("Canceling the Quick Action response failed", cause)
|
|
147
|
+
}).pipe(Effect.catch((error) => Effect.logWarning(error.message)), Effect.ensuring(Effect.try({
|
|
148
|
+
try: () => reader.releaseLock(),
|
|
149
|
+
catch: (cause) => protocolError("Releasing the Quick Action response failed", cause)
|
|
150
|
+
}).pipe(Effect.catch((error) => Effect.logWarning(error.message)))));
|
|
151
|
+
const readBoundedResponse = Effect.fn("BrowserQuickActionCapture.readResponse")(function* (response, request) {
|
|
152
|
+
const body = response.body;
|
|
153
|
+
if (body === null) return "";
|
|
154
|
+
const reader = yield* Effect.acquireRelease(Effect.try({
|
|
155
|
+
try: () => body.getReader(),
|
|
156
|
+
catch: (cause) => protocolError("Opening the Quick Action response failed", cause)
|
|
157
|
+
}), releaseResponseReader);
|
|
158
|
+
const decoder = new TextDecoder("utf-8", {
|
|
159
|
+
fatal: true,
|
|
160
|
+
ignoreBOM: false
|
|
161
|
+
});
|
|
162
|
+
let observedBytes = 0;
|
|
163
|
+
let bodyText = "";
|
|
164
|
+
while (true) {
|
|
165
|
+
const chunk = yield* Effect.tryPromise({
|
|
166
|
+
try: () => reader.read(),
|
|
167
|
+
catch: (cause) => protocolError("Reading the Quick Action response failed", cause)
|
|
168
|
+
});
|
|
169
|
+
if (chunk.done) break;
|
|
170
|
+
observedBytes += chunk.value.byteLength;
|
|
171
|
+
if (observedBytes > request.limits.maxOutputBytes) return yield* PageCaptureOutputLimitError.make({
|
|
172
|
+
implementation: browserQuickActionImplementation,
|
|
173
|
+
limit: request.limits.maxOutputBytes,
|
|
174
|
+
observed: observedBytes
|
|
175
|
+
});
|
|
176
|
+
bodyText += yield* Effect.try({
|
|
177
|
+
try: () => decoder.decode(chunk.value, { stream: true }),
|
|
178
|
+
catch: (cause) => protocolError("Decoding the Quick Action response failed", cause)
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return bodyText + (yield* Effect.try({
|
|
182
|
+
try: () => decoder.decode(),
|
|
183
|
+
catch: (cause) => protocolError("Decoding the Quick Action response failed", cause)
|
|
184
|
+
}));
|
|
185
|
+
}, Effect.scoped);
|
|
186
|
+
/**
|
|
187
|
+
* Retry-After arrives in whole seconds; a non-integer form (an HTTP date) is
|
|
188
|
+
* dropped rather than guessed at.
|
|
189
|
+
*/
|
|
190
|
+
const retryAfterMillis = (response) => {
|
|
191
|
+
const header = response.headers.get("Retry-After");
|
|
192
|
+
if (header === null) return void 0;
|
|
193
|
+
const seconds = Number(header);
|
|
194
|
+
if (!Number.isSafeInteger(seconds) || seconds < 0) return void 0;
|
|
195
|
+
const millis = seconds * 1e3;
|
|
196
|
+
return Number.isSafeInteger(millis) ? millis : void 0;
|
|
197
|
+
};
|
|
198
|
+
const browserMillis = (response) => {
|
|
199
|
+
const header = response.headers.get("X-Browser-Ms-Used");
|
|
200
|
+
if (header === null) return void 0;
|
|
201
|
+
const millis = Number(header);
|
|
202
|
+
return Number.isSafeInteger(millis) && millis >= 0 ? millis : void 0;
|
|
203
|
+
};
|
|
204
|
+
/** Only trusted response metadata chooses transport framing; page text never does. */
|
|
205
|
+
const isJsonResponse = (response) => {
|
|
206
|
+
const contentType = response.headers.get("Content-Type");
|
|
207
|
+
if (contentType === null) return false;
|
|
208
|
+
const mediaType = contentType.split(";", 1)[0]?.trim().toLowerCase();
|
|
209
|
+
return mediaType === "application/json" || mediaType?.endsWith("+json") === true;
|
|
210
|
+
};
|
|
211
|
+
const parseOutput = (action, bodyText, response) => {
|
|
212
|
+
if (!isJsonResponse(response)) return protocolError("The Quick Action success response was not a JSON response envelope", privateResponseCause(bodyText));
|
|
213
|
+
const envelope = decodeEnvelope(bodyText);
|
|
214
|
+
if (Option.isNone(envelope)) return protocolError("The JSON Quick Action response did not carry a valid response envelope", privateResponseCause(bodyText));
|
|
215
|
+
if (!envelope.value.success) return navigationError("The Quick Action reported a navigation failure", privateResponseCause(bodyText));
|
|
216
|
+
switch (action._tag) {
|
|
217
|
+
case "CapturePageContent":
|
|
218
|
+
case "CapturePageMarkdown":
|
|
219
|
+
if (typeof envelope.value.result !== "string") return protocolError("The Quick Action envelope carried a non-text result");
|
|
220
|
+
return action._tag === "CapturePageContent" ? PageContentCaptured.make({ html: envelope.value.result }) : PageMarkdownCaptured.make({ markdown: envelope.value.result });
|
|
221
|
+
case "CapturePageLinks": {
|
|
222
|
+
const decoded = Schema.decodeUnknownOption(PageLinksCaptured)({
|
|
223
|
+
_tag: "PageLinksCaptured",
|
|
224
|
+
links: envelope.value.result
|
|
225
|
+
});
|
|
226
|
+
if (Option.isNone(decoded)) return protocolError("The links Quick Action did not return a bounded array of valid URLs");
|
|
227
|
+
return decoded.value;
|
|
228
|
+
}
|
|
229
|
+
case "CapturePageStructured": return PageStructuredCaptured.make({ value: envelope.value.result });
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const isQuotaMessage = (text) => /time limit|daily|quota/i.test(text);
|
|
233
|
+
const makeCapture = (browser, workersAi) => Effect.fn("BrowserQuickActionCapture.capture")(function* (request) {
|
|
234
|
+
if (request.engine !== "chromium") return yield* PageCaptureUnsupportedError.make({
|
|
235
|
+
implementation: browserQuickActionImplementation,
|
|
236
|
+
feature: "engine",
|
|
237
|
+
message: "The browser binding's quickAction() exposes no engine selector; kitesurf requires the REST or CDP surface"
|
|
238
|
+
});
|
|
239
|
+
const usesWorkersAi = request.action._tag === "CapturePageStructured";
|
|
240
|
+
if (usesWorkersAi) {
|
|
241
|
+
if (workersAi === void 0) return yield* PageCaptureUnsupportedError.make({
|
|
242
|
+
implementation: browserQuickActionImplementation,
|
|
243
|
+
feature: "action",
|
|
244
|
+
message: "Structured capture invokes separately billed Workers AI and requires an explicit authorization and accounting policy"
|
|
245
|
+
});
|
|
246
|
+
yield* workersAi.authorizeAndAccount(request).pipe(Effect.mapError((cause) => PageCaptureInferencePolicyError.make({
|
|
247
|
+
implementation: browserQuickActionImplementation,
|
|
248
|
+
provider: "cloudflare-workers-ai",
|
|
249
|
+
reason: cause.reason,
|
|
250
|
+
message: cause.reason === "authorization" ? "Workers AI extraction was not authorized" : "Workers AI extraction could not be accounted for",
|
|
251
|
+
cause
|
|
252
|
+
})));
|
|
253
|
+
}
|
|
254
|
+
const response = yield* executeQuickAction(browser, request).pipe(Effect.mapError((error) => protocolError("The browser binding rejected the Quick Action", error.cause)));
|
|
255
|
+
const bodyText = yield* readBoundedResponse(response, request);
|
|
256
|
+
if (response.status === 429) {
|
|
257
|
+
const retryAfter = retryAfterMillis(response);
|
|
258
|
+
const reason = isQuotaMessage(bodyText) ? "quota" : "rate";
|
|
259
|
+
const cause = privateResponseCause(bodyText);
|
|
260
|
+
return yield* PageCaptureRateLimitedError.make({
|
|
261
|
+
implementation: browserQuickActionImplementation,
|
|
262
|
+
reason,
|
|
263
|
+
...retryAfter === void 0 ? {} : { retryAfterMillis: retryAfter },
|
|
264
|
+
...cause === void 0 ? {} : { cause },
|
|
265
|
+
message: reason === "quota" ? "The Quick Action exceeded its browser quota" : "The Quick Action was rate limited"
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
if (!response.ok) {
|
|
269
|
+
const message = `The Quick Action answered HTTP ${response.status}`;
|
|
270
|
+
const cause = privateResponseCause(bodyText);
|
|
271
|
+
if (response.status >= 500) return yield* protocolError(message, cause);
|
|
272
|
+
return yield* navigationError(message, cause);
|
|
273
|
+
}
|
|
274
|
+
const output = parseOutput(request.action, bodyText, response);
|
|
275
|
+
if (output._tag === "PageCaptureNavigationError" || output._tag === "PageCaptureProtocolError") return yield* output;
|
|
276
|
+
const millis = browserMillis(response);
|
|
277
|
+
return PageCaptureResult.make({
|
|
278
|
+
implementation: browserQuickActionImplementation,
|
|
279
|
+
output,
|
|
280
|
+
resourceUse: PageCaptureResourceUse.make({
|
|
281
|
+
...millis === void 0 ? {} : { browserMillis: millis },
|
|
282
|
+
...usesWorkersAi ? { inference: PageCaptureInferenceUse.make({
|
|
283
|
+
provider: "cloudflare-workers-ai",
|
|
284
|
+
modelCalls: 1
|
|
285
|
+
}) } : {}
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
/**
|
|
290
|
+
* Ordinary Quick Actions require host-owned browser binding authority. Workers
|
|
291
|
+
* AI stays unavailable unless the host deliberately selects its separate Layer.
|
|
292
|
+
*/
|
|
293
|
+
const browserQuickActionCaptureLayer = () => Layer.effect(PageCapture, Effect.map(BrowserQuickActionBrowserBinding, (browser) => PageCapture.of({ capture: makeCapture(browser) })));
|
|
294
|
+
/** Structured Quick Actions require host-owned browser and Workers AI authority. */
|
|
295
|
+
const browserQuickActionWorkersAiCaptureLayer = () => Layer.effect(PageCapture, Effect.gen(function* () {
|
|
296
|
+
const browser = yield* BrowserQuickActionBrowserBinding;
|
|
297
|
+
const workersAi = yield* BrowserQuickActionWorkersAi;
|
|
298
|
+
return PageCapture.of({ capture: makeCapture(browser, workersAi) });
|
|
299
|
+
}));
|
|
300
|
+
//#endregion
|
|
301
|
+
export { BrowserQuickActionBrowserBinding, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicyError, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer };
|
|
302
|
+
|
|
303
|
+
//# sourceMappingURL=browser-quick-action.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-quick-action.mjs","names":[],"sources":["../src/browser-quick-action.ts"],"sourcesContent":["/// <reference types=\"@cloudflare/workers-types\" />\n\nimport {\n PageCapture,\n PageCaptureInferenceUse,\n PageCaptureInferencePolicyError,\n PageCaptureNavigationError,\n PageCaptureOutputLimitError,\n PageCaptureProtocolError,\n PageCaptureRateLimitedError,\n PageCaptureResourceUse,\n PageCaptureResult,\n PageCaptureUnsupportedError,\n PageContentCaptured,\n PageLinksCaptured,\n PageMarkdownCaptured,\n PageStructuredCaptured,\n SandboxImplementation,\n type PageCaptureAction,\n type PageCaptureCapture,\n type PageCaptureError,\n type PageCaptureOutput,\n type PageCaptureRequest,\n} from \"@effect-agent/sandbox\";\nimport { Context, Effect, Layer, Option, Schema } from \"effect\";\n\n/**\n * The Cloudflare Browser Run Quick Action `PageCapture` adapter (capability\n * spec §9.2). Each capture is one stateless `quickAction()` RPC on the\n * Wrangler `browser` binding: the platform renders the target in a managed\n * headless browser and returns one bounded output; the adapter holds no\n * session and no state between passes. The binding requires a Worker\n * compatibility date of `2026-03-24` or later, and local `wrangler dev` needs\n * remote mode (`\"remote\": true` on the binding) because `quickAction` has no\n * local implementation.\n *\n * Rendered output is untrusted, attacker-influenced content; this adapter\n * only bounds and types it. Deployment class `E` only: no durability claim.\n */\nexport const browserQuickActionImplementation = SandboxImplementation.make({\n isolation: \"isolated\",\n identity: \"cloudflare-browser-quick-action\",\n});\n\n/**\n * Effect-native client captured by the binding service. Its option types come\n * directly from the pinned Workers declarations rather than a local copy.\n */\nexport interface BrowserQuickActionClient {\n readonly content: (\n options: BrowserRunContentOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly markdown: (\n options: BrowserRunMarkdownOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly links: (\n options: BrowserRunLinksOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly json: (\n options: BrowserRunJsonOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n}\n\n/** A native binding RPC rejected before it returned an HTTP response. */\nexport class BrowserQuickActionRpcError extends Schema.TaggedError<BrowserQuickActionRpcError>()(\n \"BrowserQuickActionRpcError\",\n {\n action: Schema.Literals([\"content\", \"markdown\", \"links\", \"json\"]),\n cause: Schema.Defect(),\n },\n) {}\n\nexport interface BrowserQuickActionCaptureOptions {\n /** The resolved Wrangler `browser` binding (DEPLOY-014: supplied, never ambient). */\n readonly browser: BrowserRun;\n}\n\n/** Host-owned browser binding authority, supplied explicitly at the composition root. */\nexport class BrowserQuickActionBrowserBinding extends Context.Service<\n BrowserQuickActionBrowserBinding,\n BrowserQuickActionClient\n>()(\"@effect-agent/platform-cloudflare/BrowserQuickActionBrowserBinding\") {\n static layer(\n options: BrowserQuickActionCaptureOptions,\n ): Layer.Layer<BrowserQuickActionBrowserBinding> {\n const browser = options.browser;\n const invoke = Effect.fn(\"BrowserQuickActionBrowserBinding.invoke\")(function* (\n action: \"content\" | \"markdown\" | \"links\" | \"json\",\n evaluate: () => Promise<Response>,\n ): Effect.fn.Return<Response, BrowserQuickActionRpcError> {\n return yield* Effect.tryPromise({\n try: evaluate,\n catch: (cause) => BrowserQuickActionRpcError.make({ action, cause }),\n });\n });\n return Layer.succeed(BrowserQuickActionBrowserBinding)({\n content: (request) => invoke(\"content\", () => browser.quickAction(\"content\", request)),\n markdown: (request) => invoke(\"markdown\", () => browser.quickAction(\"markdown\", request)),\n links: (request) => invoke(\"links\", () => browser.quickAction(\"links\", request)),\n json: (request) => invoke(\"json\", () => browser.quickAction(\"json\", request)),\n });\n }\n}\n\n/** Host-owned authorization and accounting for one Workers AI extraction. */\nexport interface BrowserQuickActionWorkersAiPolicy {\n readonly authorizeAndAccount: (\n request: PageCaptureRequest,\n ) => Effect.Effect<void, BrowserQuickActionWorkersAiPolicyError>;\n}\n\n/** Host-only diagnostic for a denied or unaccounted Workers AI extraction. */\nexport class BrowserQuickActionWorkersAiPolicyError extends Schema.TaggedError<BrowserQuickActionWorkersAiPolicyError>()(\n \"BrowserQuickActionWorkersAiPolicyError\",\n {\n reason: Schema.Literals([\"authorization\", \"accounting\"]),\n message: Schema.String.check(Schema.isMaxLength(8_000)),\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\n/** Explicit host-owned authority and accounting for separately billed Workers AI extraction. */\nexport class BrowserQuickActionWorkersAi extends Context.Service<\n BrowserQuickActionWorkersAi,\n BrowserQuickActionWorkersAiPolicy\n>()(\"@effect-agent/platform-cloudflare/BrowserQuickActionWorkersAi\") {\n static layer(\n policy: BrowserQuickActionWorkersAiPolicy,\n ): Layer.Layer<BrowserQuickActionWorkersAi> {\n return Layer.succeed(BrowserQuickActionWorkersAi)(policy);\n }\n}\n\nconst MAX_DIAGNOSTIC_LENGTH = 8_000;\nconst boundedDiagnostic = (message: string): string => message.slice(0, MAX_DIAGNOSTIC_LENGTH);\n\nconst QuickActionSuccessEnvelope = Schema.Struct({\n success: Schema.Literal(true),\n result: Schema.Json,\n});\n\nconst QuickActionErrorEnvelope = Schema.Struct({\n success: Schema.Literal(false),\n errors: Schema.Array(\n Schema.Struct({\n message: Schema.String,\n code: Schema.optionalKey(Schema.Number),\n detail: Schema.optionalKey(Schema.String),\n path: Schema.optionalKey(Schema.String),\n }),\n ),\n rawAiResponse: Schema.optionalKey(Schema.String),\n});\n\nconst QuickActionEnvelope = Schema.Union([QuickActionSuccessEnvelope, QuickActionErrorEnvelope]);\nconst decodeEnvelope = Schema.decodeUnknownOption(Schema.fromJsonString(QuickActionEnvelope));\n\n/** Project the schema-validated request onto Cloudflare's native common options. */\nconst quickActionCommonOptions = (request: PageCaptureRequest): BrowserRunCommonOptions => {\n const options: BrowserRunBaseOptions = {};\n const navigation = request.navigation;\n if (navigation !== undefined) {\n const goto: NonNullable<BrowserRunBaseOptions[\"gotoOptions\"]> = {};\n if (navigation.waitUntil !== undefined) goto.waitUntil = navigation.waitUntil;\n if (navigation.timeoutMillis !== undefined) goto.timeout = navigation.timeoutMillis;\n if (Object.keys(goto).length > 0) options.gotoOptions = goto;\n if (navigation.waitForSelector !== undefined) {\n options.waitForSelector = {\n selector: navigation.waitForSelector.selector,\n ...(navigation.waitForSelector.timeoutMillis === undefined\n ? {}\n : { timeout: navigation.waitForSelector.timeoutMillis }),\n };\n }\n }\n if (request.viewport !== undefined) {\n options.viewport = { width: request.viewport.width, height: request.viewport.height };\n }\n if (request.resourcePolicy !== undefined) {\n if (request.resourcePolicy.rejectResourceTypes !== undefined) {\n options.rejectResourceTypes = [...request.resourcePolicy.rejectResourceTypes];\n }\n if (request.resourcePolicy.allowRequestPatterns !== undefined) {\n options.allowRequestPattern = [...request.resourcePolicy.allowRequestPatterns];\n }\n }\n return request.target._tag === \"PageUrlTarget\"\n ? { ...options, url: request.target.url }\n : { ...options, html: request.target.html };\n};\n\n/** Dispatch through Cloudflare's native action-specific overloads. */\nconst executeQuickAction = (\n browser: BrowserQuickActionClient,\n request: PageCaptureRequest,\n): Effect.Effect<Response, BrowserQuickActionRpcError> => {\n const options = quickActionCommonOptions(request);\n switch (request.action._tag) {\n case \"CapturePageContent\": {\n return browser.content(options);\n }\n case \"CapturePageMarkdown\": {\n return browser.markdown(options);\n }\n case \"CapturePageLinks\": {\n return browser.links({\n ...options,\n ...(request.action.visibleLinksOnly === undefined\n ? {}\n : { visibleLinksOnly: request.action.visibleLinksOnly }),\n });\n }\n case \"CapturePageStructured\": {\n return browser.json({\n ...options,\n response_format: {\n type: \"json_schema\",\n json_schema: request.action.responseFormat,\n },\n ...(request.action.prompt === undefined ? {} : { prompt: request.action.prompt }),\n });\n }\n }\n};\n\nconst protocolError = (message: string, cause?: unknown): PageCaptureProtocolError =>\n PageCaptureProtocolError.make({\n implementation: browserQuickActionImplementation,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst navigationError = (message: string, cause?: unknown): PageCaptureNavigationError =>\n PageCaptureNavigationError.make({\n implementation: browserQuickActionImplementation,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\n/** Preserve bounded remote diagnostics for the host without exposing their text to a model. */\nconst privateResponseCause = (bodyText: string): Error | undefined =>\n bodyText.length === 0 ? undefined : new Error(boundedDiagnostic(bodyText));\n\nconst releaseResponseReader = (\n reader: ReadableStreamDefaultReader<Uint8Array>,\n): Effect.Effect<void> =>\n Effect.tryPromise({\n try: () => reader.cancel(),\n catch: (cause) => protocolError(\"Canceling the Quick Action response failed\", cause),\n }).pipe(\n Effect.catch((error) => Effect.logWarning(error.message)),\n Effect.ensuring(\n Effect.try({\n try: () => reader.releaseLock(),\n catch: (cause) => protocolError(\"Releasing the Quick Action response failed\", cause),\n }).pipe(Effect.catch((error) => Effect.logWarning(error.message))),\n ),\n );\n\nconst readBoundedResponse = Effect.fn(\"BrowserQuickActionCapture.readResponse\")(function* (\n response: Response,\n request: PageCaptureRequest,\n) {\n const body = response.body;\n if (body === null) return \"\";\n\n const reader = yield* Effect.acquireRelease(\n Effect.try({\n try: () => body.getReader(),\n catch: (cause) => protocolError(\"Opening the Quick Action response failed\", cause),\n }),\n releaseResponseReader,\n );\n const decoder = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: false });\n let observedBytes = 0;\n let bodyText = \"\";\n\n while (true) {\n const chunk = yield* Effect.tryPromise({\n try: () => reader.read(),\n catch: (cause) => protocolError(\"Reading the Quick Action response failed\", cause),\n });\n if (chunk.done) break;\n\n observedBytes += chunk.value.byteLength;\n if (observedBytes > request.limits.maxOutputBytes) {\n return yield* PageCaptureOutputLimitError.make({\n implementation: browserQuickActionImplementation,\n limit: request.limits.maxOutputBytes,\n observed: observedBytes,\n });\n }\n\n bodyText += yield* Effect.try({\n try: () => decoder.decode(chunk.value, { stream: true }),\n catch: (cause) => protocolError(\"Decoding the Quick Action response failed\", cause),\n });\n }\n\n return (\n bodyText +\n (yield* Effect.try({\n try: () => decoder.decode(),\n catch: (cause) => protocolError(\"Decoding the Quick Action response failed\", cause),\n }))\n );\n}, Effect.scoped);\n\n/**\n * Retry-After arrives in whole seconds; a non-integer form (an HTTP date) is\n * dropped rather than guessed at.\n */\nconst retryAfterMillis = (response: Response): number | undefined => {\n const header = response.headers.get(\"Retry-After\");\n if (header === null) return undefined;\n const seconds = Number(header);\n if (!Number.isSafeInteger(seconds) || seconds < 0) return undefined;\n const millis = seconds * 1_000;\n return Number.isSafeInteger(millis) ? millis : undefined;\n};\n\nconst browserMillis = (response: Response): number | undefined => {\n const header = response.headers.get(\"X-Browser-Ms-Used\");\n if (header === null) return undefined;\n const millis = Number(header);\n return Number.isSafeInteger(millis) && millis >= 0 ? millis : undefined;\n};\n\n/** Only trusted response metadata chooses transport framing; page text never does. */\nconst isJsonResponse = (response: Response): boolean => {\n const contentType = response.headers.get(\"Content-Type\");\n if (contentType === null) return false;\n const mediaType = contentType.split(\";\", 1)[0]?.trim().toLowerCase();\n return mediaType === \"application/json\" || mediaType?.endsWith(\"+json\") === true;\n};\n\nconst parseOutput = (\n action: PageCaptureAction,\n bodyText: string,\n response: Response,\n): PageCaptureOutput | PageCaptureNavigationError | PageCaptureProtocolError => {\n if (!isJsonResponse(response)) {\n return protocolError(\n \"The Quick Action success response was not a JSON response envelope\",\n privateResponseCause(bodyText),\n );\n }\n const envelope = decodeEnvelope(bodyText);\n if (Option.isNone(envelope)) {\n return protocolError(\n \"The JSON Quick Action response did not carry a valid response envelope\",\n privateResponseCause(bodyText),\n );\n }\n if (!envelope.value.success) {\n return navigationError(\n \"The Quick Action reported a navigation failure\",\n privateResponseCause(bodyText),\n );\n }\n switch (action._tag) {\n case \"CapturePageContent\":\n case \"CapturePageMarkdown\": {\n if (typeof envelope.value.result !== \"string\") {\n return protocolError(\"The Quick Action envelope carried a non-text result\");\n }\n return action._tag === \"CapturePageContent\"\n ? PageContentCaptured.make({ html: envelope.value.result })\n : PageMarkdownCaptured.make({ markdown: envelope.value.result });\n }\n case \"CapturePageLinks\": {\n const decoded = Schema.decodeUnknownOption(PageLinksCaptured)({\n _tag: \"PageLinksCaptured\",\n links: envelope.value.result,\n });\n if (Option.isNone(decoded)) {\n return protocolError(\"The links Quick Action did not return a bounded array of valid URLs\");\n }\n return decoded.value;\n }\n case \"CapturePageStructured\": {\n return PageStructuredCaptured.make({ value: envelope.value.result });\n }\n }\n};\n\nconst isQuotaMessage = (text: string): boolean => /time limit|daily|quota/i.test(text);\n\nconst makeCapture = (\n browser: BrowserQuickActionClient,\n workersAi?: BrowserQuickActionWorkersAiPolicy,\n): PageCaptureCapture =>\n Effect.fn(\"BrowserQuickActionCapture.capture\")(function* (\n request: PageCaptureRequest,\n ): Effect.fn.Return<PageCaptureResult, PageCaptureError> {\n if (request.engine !== \"chromium\") {\n return yield* PageCaptureUnsupportedError.make({\n implementation: browserQuickActionImplementation,\n feature: \"engine\",\n message:\n \"The browser binding's quickAction() exposes no engine selector; kitesurf requires the REST or CDP surface\",\n });\n }\n\n const usesWorkersAi = request.action._tag === \"CapturePageStructured\";\n if (usesWorkersAi) {\n if (workersAi === undefined) {\n return yield* PageCaptureUnsupportedError.make({\n implementation: browserQuickActionImplementation,\n feature: \"action\",\n message:\n \"Structured capture invokes separately billed Workers AI and requires an explicit authorization and accounting policy\",\n });\n }\n yield* workersAi.authorizeAndAccount(request).pipe(\n Effect.mapError((cause) =>\n PageCaptureInferencePolicyError.make({\n implementation: browserQuickActionImplementation,\n provider: \"cloudflare-workers-ai\",\n reason: cause.reason,\n message:\n cause.reason === \"authorization\"\n ? \"Workers AI extraction was not authorized\"\n : \"Workers AI extraction could not be accounted for\",\n cause,\n }),\n ),\n );\n }\n\n const response = yield* executeQuickAction(browser, request).pipe(\n Effect.mapError((error) =>\n protocolError(\"The browser binding rejected the Quick Action\", error.cause),\n ),\n );\n const bodyText = yield* readBoundedResponse(response, request);\n if (response.status === 429) {\n const retryAfter = retryAfterMillis(response);\n const reason = isQuotaMessage(bodyText) ? \"quota\" : \"rate\";\n const cause = privateResponseCause(bodyText);\n return yield* PageCaptureRateLimitedError.make({\n implementation: browserQuickActionImplementation,\n reason,\n ...(retryAfter === undefined ? {} : { retryAfterMillis: retryAfter }),\n ...(cause === undefined ? {} : { cause }),\n message:\n reason === \"quota\"\n ? \"The Quick Action exceeded its browser quota\"\n : \"The Quick Action was rate limited\",\n });\n }\n if (!response.ok) {\n const message = `The Quick Action answered HTTP ${response.status}`;\n const cause = privateResponseCause(bodyText);\n if (response.status >= 500) {\n return yield* protocolError(message, cause);\n }\n return yield* navigationError(message, cause);\n }\n const output = parseOutput(request.action, bodyText, response);\n if (\n output._tag === \"PageCaptureNavigationError\" ||\n output._tag === \"PageCaptureProtocolError\"\n ) {\n return yield* output;\n }\n const millis = browserMillis(response);\n return PageCaptureResult.make({\n implementation: browserQuickActionImplementation,\n output,\n resourceUse: PageCaptureResourceUse.make({\n ...(millis === undefined ? {} : { browserMillis: millis }),\n ...(usesWorkersAi\n ? {\n inference: PageCaptureInferenceUse.make({\n provider: \"cloudflare-workers-ai\",\n modelCalls: 1,\n }),\n }\n : {}),\n }),\n });\n });\n\n/**\n * Ordinary Quick Actions require host-owned browser binding authority. Workers\n * AI stays unavailable unless the host deliberately selects its separate Layer.\n */\nexport const browserQuickActionCaptureLayer = (): Layer.Layer<\n PageCapture,\n never,\n BrowserQuickActionBrowserBinding\n> =>\n Layer.effect(\n PageCapture,\n Effect.map(BrowserQuickActionBrowserBinding, (browser) =>\n PageCapture.of({ capture: makeCapture(browser) }),\n ),\n );\n\n/** Structured Quick Actions require host-owned browser and Workers AI authority. */\nexport const browserQuickActionWorkersAiCaptureLayer = (): Layer.Layer<\n PageCapture,\n never,\n BrowserQuickActionBrowserBinding | BrowserQuickActionWorkersAi\n> =>\n Layer.effect(\n PageCapture,\n Effect.gen(function* () {\n const browser = yield* BrowserQuickActionBrowserBinding;\n const workersAi = yield* BrowserQuickActionWorkersAi;\n return PageCapture.of({ capture: makeCapture(browser, workersAi) });\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAa,mCAAmC,sBAAsB,KAAK;CACzE,WAAW;CACX,UAAU;AACZ,CAAC;;AAsBD,IAAa,6BAAb,c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