@cloudflare/workers-types 4.20260527.1 → 4.20260529.1

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.
@@ -4039,6 +4039,239 @@ export declare abstract class Span {
4039
4039
  get isTraced(): boolean;
4040
4040
  setAttribute(key: string, value?: boolean | number | string): void;
4041
4041
  }
4042
+ // ============================================================================
4043
+ // Agent Memory
4044
+ //
4045
+ // Public type surface for user Workers binding to an Agent Memory namespace.
4046
+ // ============================================================================
4047
+ /** Memory type — every memory is classified into exactly one. */
4048
+ export type AgentMemoryMemoryType = "fact" | "event" | "instruction" | "task";
4049
+ /** Search intensity for recall. */
4050
+ export type AgentMemoryThinkingLevel = "low" | "medium" | "high";
4051
+ /** Response verbosity for recall. */
4052
+ export type AgentMemoryResponseLength = "short" | "medium" | "long";
4053
+ /** A conversation message passed to ingest(). */
4054
+ export interface AgentMemoryMessage {
4055
+ role: "system" | "user" | "assistant";
4056
+ content: string;
4057
+ /** Optional message timestamp. */
4058
+ timestamp?: Date;
4059
+ }
4060
+ /** Raw memory content passed to remember(). */
4061
+ export interface AgentMemoryIncomingMemory {
4062
+ /** Raw memory content. The service classifies and summarizes automatically. */
4063
+ content: string;
4064
+ /** Optional session identifier to associate with this memory. */
4065
+ sessionId?: string | null | undefined;
4066
+ }
4067
+ /** A stored memory returned from remember(), get(), and delete(). */
4068
+ export interface AgentMemoryMemory {
4069
+ /** Memory ID. */
4070
+ id: string;
4071
+ /** Memory type. */
4072
+ type: AgentMemoryMemoryType;
4073
+ /** Text summary. */
4074
+ summary: string;
4075
+ /** Memory text. */
4076
+ content: string;
4077
+ /** Session that created this memory. */
4078
+ sessionId: string | null;
4079
+ /** Memory creation time. */
4080
+ createdAt: Date;
4081
+ /** Memory last-update time. */
4082
+ updatedAt: Date;
4083
+ }
4084
+ /** Single entry in a list() response. Same shape as Memory minus full content. */
4085
+ export type AgentMemoryMemoryListEntry = Omit<AgentMemoryMemory, "content">;
4086
+ /** A scored memory candidate in a recall result. */
4087
+ export interface AgentMemoryScoredCandidate {
4088
+ /** Candidate ID. */
4089
+ id: string;
4090
+ /** Text summary. */
4091
+ summary: string;
4092
+ /** Session that created this candidate, when known. */
4093
+ sessionId: string | null;
4094
+ /** Relevance score (higher is better). Comparable only within a single query. */
4095
+ score: number;
4096
+ }
4097
+ /** Options for the ingest() method. */
4098
+ export interface AgentMemoryIngestOptions {
4099
+ /** Session identifier to associate with memories created during ingestion. */
4100
+ sessionId?: string | null | undefined;
4101
+ }
4102
+ /** Options for the getSummary() method. */
4103
+ export interface AgentMemoryGetSummaryOptions {
4104
+ /** Session identifier to retrieve session summary for. */
4105
+ sessionId?: string | null | undefined;
4106
+ }
4107
+ /** Response from the getSummary() method. */
4108
+ export interface AgentMemoryGetSummaryResponse {
4109
+ /** Markdown summary. */
4110
+ summary: string;
4111
+ }
4112
+ /**
4113
+ * Options for the recall() method.
4114
+ *
4115
+ * `referenceDate` accepts a Date object, an ISO-8601 date string
4116
+ * (YYYY-MM-DD), or a full ISO-8601 datetime string. When provided, this
4117
+ * date is used as "today" for resolving relative time references
4118
+ * ("how many days ago", "last week") instead of the server's wall-clock time.
4119
+ */
4120
+ export interface AgentMemoryRecallOptions {
4121
+ /** Recall intensity: "low" (default), "medium", or "high". */
4122
+ thinkingLevel?: AgentMemoryThinkingLevel;
4123
+ /** Response verbosity: "short", "medium" (default), or "long". */
4124
+ responseLength?: AgentMemoryResponseLength;
4125
+ /** Temporal anchor for date arithmetic. */
4126
+ referenceDate?: Date | string;
4127
+ }
4128
+ /** Response from the recall() method. */
4129
+ export interface AgentMemoryRecallResult {
4130
+ /** Number of memories retrieved. */
4131
+ count: number;
4132
+ /** LLM-generated answer synthesizing the matching memories. */
4133
+ answer: string;
4134
+ /** Matching memories ranked by relevance. */
4135
+ candidates: AgentMemoryScoredCandidate[];
4136
+ }
4137
+ /**
4138
+ * Options for the list() method.
4139
+ *
4140
+ * `cursor` is the opaque continuation token returned by the previous page;
4141
+ * pass it back unchanged to fetch the next page. `sessionId` and `type`
4142
+ * are exact-match filters; combining them is allowed.
4143
+ */
4144
+ export interface AgentMemoryListMemoriesOptions {
4145
+ /** Maximum number of memories to return. Default 20, max 500. */
4146
+ limit?: number;
4147
+ /** Opaque cursor from a previous page. */
4148
+ cursor?: string;
4149
+ /** Exact-match session filter. */
4150
+ sessionId?: string;
4151
+ /** Exact-match memory-type filter. */
4152
+ type?: AgentMemoryMemoryType;
4153
+ }
4154
+ /** Response from the list() method. */
4155
+ export interface AgentMemoryListMemoriesResult {
4156
+ memories: AgentMemoryMemoryListEntry[];
4157
+ /** Continuation cursor; absent when this page exhausted the result set. */
4158
+ cursor?: string;
4159
+ }
4160
+ /**
4161
+ * A single Agent Memory profile, scoped to a profile name.
4162
+ *
4163
+ * Returned by {@link AgentMemoryNamespace.getProfile}.
4164
+ */
4165
+ export declare abstract class AgentMemoryProfile {
4166
+ /**
4167
+ * Retrieve a memory by ID.
4168
+ *
4169
+ * @param memoryId - ULID of the memory to retrieve.
4170
+ * @throws if the memory does not exist.
4171
+ */
4172
+ get(memoryId: string): Promise<AgentMemoryMemory>;
4173
+ /**
4174
+ * Delete a memory by ID.
4175
+ *
4176
+ * Removes the memory and any source messages linked by the memory's
4177
+ * source message IDs.
4178
+ *
4179
+ * @param memoryId - ULID of the memory to delete.
4180
+ * @throws if the memory does not exist.
4181
+ */
4182
+ delete(memoryId: string): Promise<AgentMemoryMemory>;
4183
+ /**
4184
+ * Store a memory in this profile. The content is automatically classified,
4185
+ * summarized, and indexed.
4186
+ *
4187
+ * @param memory - Raw memory content to persist.
4188
+ */
4189
+ remember(memory: AgentMemoryIncomingMemory): Promise<AgentMemoryMemory>;
4190
+ /**
4191
+ * Extract memories from a conversation.
4192
+ *
4193
+ * @param messages - Conversation messages to extract memories from.
4194
+ * @param options - Optional ingest options.
4195
+ */
4196
+ ingest(
4197
+ messages: Iterable<AgentMemoryMessage>,
4198
+ options?: AgentMemoryIngestOptions,
4199
+ ): Promise<void>;
4200
+ /**
4201
+ * Get a profile summary.
4202
+ *
4203
+ * @param options - Optional getSummary options.
4204
+ */
4205
+ getSummary(
4206
+ options?: AgentMemoryGetSummaryOptions,
4207
+ ): Promise<AgentMemoryGetSummaryResponse>;
4208
+ /**
4209
+ * Recall memories in this profile.
4210
+ *
4211
+ * @param query - Recall query matched against memory content and keywords.
4212
+ * @param options - Optional recall parameters.
4213
+ * @returns Matching memories with relevance scores and a synthesized answer.
4214
+ */
4215
+ recall(
4216
+ query: string,
4217
+ options?: AgentMemoryRecallOptions,
4218
+ ): Promise<AgentMemoryRecallResult>;
4219
+ /**
4220
+ * List active memories in this profile.
4221
+ *
4222
+ * Returns a paginated, filterable view of stored memories. Superseded
4223
+ * versions are excluded. Use the returned `cursor` (when present) to
4224
+ * fetch the next page.
4225
+ *
4226
+ * @param options - Optional pagination and filter options.
4227
+ */
4228
+ list(
4229
+ options?: AgentMemoryListMemoriesOptions,
4230
+ ): Promise<AgentMemoryListMemoriesResult>;
4231
+ /**
4232
+ * Soft-delete every memory and message in this profile that is tagged
4233
+ * with `sessionId`.
4234
+ *
4235
+ * Idempotent: deleting a sessionId that has no rows is a no-op.
4236
+ *
4237
+ * @param sessionId - Session to delete.
4238
+ */
4239
+ deleteSession(sessionId: string): Promise<void>;
4240
+ }
4241
+ /**
4242
+ * Namespace-level Agent Memory binding.
4243
+ *
4244
+ * Used as the type of an `env.MEMORY`-style binding backed by the Agent
4245
+ * Memory product.
4246
+ *
4247
+ * @example
4248
+ * ```ts
4249
+ * export default {
4250
+ * async fetch(_request: Request, env: Env): Promise<Response> {
4251
+ * const profile = await env.MEMORY.getProfile("wrangler-e2e");
4252
+ * const summary = await profile.getSummary();
4253
+ * return Response.json(summary);
4254
+ * },
4255
+ * };
4256
+ * ```
4257
+ */
4258
+ export declare abstract class AgentMemoryNamespace {
4259
+ /**
4260
+ * Get a memory profile by name. Profiles are isolated by namespace and
4261
+ * addressed by a compound key (namespaceId:profileName).
4262
+ *
4263
+ * @param profileName - Profile name (validated against naming rules).
4264
+ * @returns RPC target for interacting with the profile.
4265
+ */
4266
+ getProfile(profileName: string): Promise<AgentMemoryProfile>;
4267
+ /**
4268
+ * Soft-delete a profile and schedule deferred purge. Marks all
4269
+ * memories and messages as deleted.
4270
+ *
4271
+ * @param profileName - Name of the profile to delete.
4272
+ */
4273
+ deleteProfile(profileName: string): Promise<void>;
4274
+ }
4042
4275
  // ============ AI Search Error Interfaces ============
4043
4276
  export interface AiSearchInternalError extends Error {}
4044
4277
  export interface AiSearchNotFoundError extends Error {}
@@ -11454,6 +11687,513 @@ export declare abstract class AutoRAG {
11454
11687
  params: AutoRagAiSearchRequest,
11455
11688
  ): Promise<AutoRagAiSearchResponse | Response>;
11456
11689
  }
11690
+ export type BrowserRunLifecycleEvent =
11691
+ | "load"
11692
+ | "domcontentloaded"
11693
+ | "networkidle0"
11694
+ | "networkidle2";
11695
+ export type BrowserRunResourceType =
11696
+ | "document"
11697
+ | "stylesheet"
11698
+ | "image"
11699
+ | "media"
11700
+ | "font"
11701
+ | "script"
11702
+ | "texttrack"
11703
+ | "xhr"
11704
+ | "fetch"
11705
+ | "prefetch"
11706
+ | "eventsource"
11707
+ | "websocket"
11708
+ | "manifest"
11709
+ | "signedexchange"
11710
+ | "ping"
11711
+ | "cspviolationreport"
11712
+ | "preflight"
11713
+ | "other";
11714
+ /** Options fields shared by all quick actions. */
11715
+ export interface BrowserRunBaseOptions {
11716
+ /** Adds `<script>` tags into the page with the desired URL or content.
11717
+ * @see https://pptr.dev/api/puppeteer.frameaddscripttagoptions
11718
+ */
11719
+ addScriptTag?: Array<{
11720
+ content?: string;
11721
+ url?: string;
11722
+ type?: string;
11723
+ id?: string;
11724
+ }>;
11725
+ /** Adds `<link rel="stylesheet">` or `<style>` tags into the page.
11726
+ * @see https://pptr.dev/api/puppeteer.frameaddstyletagoptions
11727
+ */
11728
+ addStyleTag?: Array<{
11729
+ content?: string;
11730
+ url?: string;
11731
+ }>;
11732
+ /** Provide credentials for HTTP authentication. @see https://pptr.dev/api/puppeteer.credentials */
11733
+ authenticate?: {
11734
+ username: string;
11735
+ password: string;
11736
+ };
11737
+ /** Set cookies before navigating. @see https://pptr.dev/api/puppeteer.cookieparam */
11738
+ cookies?: Array<{
11739
+ name: string;
11740
+ value: string;
11741
+ url?: string;
11742
+ domain?: string;
11743
+ path?: string;
11744
+ secure?: boolean;
11745
+ httpOnly?: boolean;
11746
+ sameSite?: "Strict" | "Lax" | "None";
11747
+ expires?: number;
11748
+ priority?: "Low" | "Medium" | "High";
11749
+ sameParty?: boolean;
11750
+ sourceScheme?: "Unset" | "NonSecure" | "Secure";
11751
+ sourcePort?: number;
11752
+ partitionKey?: string;
11753
+ }>;
11754
+ /** Emulate a specific CSS media type (e.g. `"screen"`, `"print"`). */
11755
+ emulateMediaType?: string;
11756
+ /** Navigation options. @see https://pptr.dev/api/puppeteer.gotooptions */
11757
+ gotoOptions?: {
11758
+ /** Navigation timeout in milliseconds (max 60 000). @default 30000 */
11759
+ timeout?: number;
11760
+ /** When to consider navigation complete. @default "domcontentloaded" */
11761
+ waitUntil?: BrowserRunLifecycleEvent | BrowserRunLifecycleEvent[];
11762
+ referer?: string;
11763
+ referrerPolicy?: string;
11764
+ };
11765
+ /** Block requests matching these regex patterns. Mutually exclusive with `allowRequestPattern`. */
11766
+ rejectRequestPattern?: string[];
11767
+ /** Only allow requests matching these regex patterns. Mutually exclusive with `rejectRequestPattern`. */
11768
+ allowRequestPattern?: string[];
11769
+ /** Block requests of these resource types. Mutually exclusive with `allowResourceTypes`. */
11770
+ rejectResourceTypes?: BrowserRunResourceType[];
11771
+ /** Only allow requests of these resource types. Mutually exclusive with `rejectResourceTypes`. */
11772
+ allowResourceTypes?: BrowserRunResourceType[];
11773
+ /** Additional HTTP headers sent with every request. */
11774
+ setExtraHTTPHeaders?: Record<string, string>;
11775
+ /** Whether JavaScript is enabled on the page. */
11776
+ setJavaScriptEnabled?: boolean;
11777
+ /** Override the default user agent string.
11778
+ * @default "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
11779
+ * */
11780
+ userAgent?: string;
11781
+ /** Set the browser viewport size.
11782
+ * @see https://pptr.dev/api/puppeteer.viewport
11783
+ * @default {width:1920,height:1080}
11784
+ * */
11785
+ viewport?: {
11786
+ width: number;
11787
+ height: number;
11788
+ deviceScaleFactor?: number;
11789
+ isMobile?: boolean;
11790
+ isLandscape?: boolean;
11791
+ hasTouch?: boolean;
11792
+ };
11793
+ /** Wait for a CSS selector to appear in the page before proceeding.
11794
+ * @see https://pptr.dev/api/puppeteer.waitforselectoroptions
11795
+ */
11796
+ waitForSelector?: {
11797
+ selector: string;
11798
+ hidden?: true;
11799
+ visible?: true;
11800
+ /** Timeout in milliseconds. Max 120000 */
11801
+ timeout?: number;
11802
+ };
11803
+ /** Wait for a fixed delay in milliseconds before proceeding. Max 120000 */
11804
+ waitForTimeout?: number;
11805
+ /** When true, continue on best-effort when awaited events fail or timeout. */
11806
+ bestAttempt?: boolean;
11807
+ /** Maximum duration in milliseconds for the browser action after page load. Max 120000 */
11808
+ actionTimeout?: number;
11809
+ /** Cache time to live in seconds (0-86400). Set to 0 to disable.
11810
+ * @default 5
11811
+ */
11812
+ cacheTTL?: number;
11813
+ }
11814
+ /** Common options shared by all quick actions. Exactly one of `url` or `html` must be provided.*/
11815
+ export type BrowserRunCommonOptions =
11816
+ | (BrowserRunBaseOptions & {
11817
+ /** URL to navigate to, e.g. `"https://example.com"`. */
11818
+ url: string;
11819
+ })
11820
+ | (BrowserRunBaseOptions & {
11821
+ /** Set the HTML content of the page directly. */
11822
+ html: string;
11823
+ });
11824
+ export type BrowserRunPuppeteerScreenshotOptions = {
11825
+ /** @default "png" */
11826
+ type?: "png" | "jpeg" | "webp";
11827
+ /** @default "binary" */
11828
+ encoding?: "binary" | "base64";
11829
+ quality?: number;
11830
+ fullPage?: boolean;
11831
+ clip?: {
11832
+ x: number;
11833
+ y: number;
11834
+ width: number;
11835
+ height: number;
11836
+ scale?: number;
11837
+ };
11838
+ omitBackground?: boolean;
11839
+ optimizeForSpeed?: boolean;
11840
+ captureBeyondViewport?: boolean;
11841
+ fromSurface?: boolean;
11842
+ };
11843
+ export type BrowserRunScreenshotOptions = BrowserRunCommonOptions & {
11844
+ /** CSS selector of the element to screenshot. */
11845
+ selector?: string;
11846
+ /** When true, scroll the entire page before taking the screenshot. */
11847
+ scrollPage?: boolean;
11848
+ /** @see https://pptr.dev/api/puppeteer.screenshotoptions */
11849
+ screenshotOptions?: BrowserRunPuppeteerScreenshotOptions;
11850
+ };
11851
+ export type BrowserRunPDFOptions = BrowserRunCommonOptions & {
11852
+ /** @see https://pptr.dev/api/puppeteer.pdfoptions */
11853
+ pdfOptions?: {
11854
+ /** @default 1 */
11855
+ scale?: number;
11856
+ /** @default false */
11857
+ displayHeaderFooter?: boolean;
11858
+ headerTemplate?: string;
11859
+ footerTemplate?: string;
11860
+ /** @default false */
11861
+ printBackground?: boolean;
11862
+ /** @default false */
11863
+ landscape?: boolean;
11864
+ pageRanges?: string;
11865
+ /** @default "letter" */
11866
+ format?:
11867
+ | "letter"
11868
+ | "legal"
11869
+ | "tabloid"
11870
+ | "ledger"
11871
+ | "a0"
11872
+ | "a1"
11873
+ | "a2"
11874
+ | "a3"
11875
+ | "a4"
11876
+ | "a5"
11877
+ | "a6";
11878
+ width?: string | number;
11879
+ height?: string | number;
11880
+ /** @default false */
11881
+ preferCSSPageSize?: boolean;
11882
+ margin?: {
11883
+ top?: string | number;
11884
+ right?: string | number;
11885
+ bottom?: string | number;
11886
+ left?: string | number;
11887
+ };
11888
+ /** @default false */
11889
+ omitBackground?: boolean;
11890
+ /** @default true */
11891
+ tagged?: boolean;
11892
+ /** @default false */
11893
+ outline?: boolean;
11894
+ /** @default 30000 */
11895
+ timeout?: number;
11896
+ };
11897
+ };
11898
+ export type BrowserRunScrapeOptions = BrowserRunCommonOptions & {
11899
+ /** CSS selectors to scrape. At least one element is required. */
11900
+ elements: Array<{
11901
+ selector: string;
11902
+ }>;
11903
+ };
11904
+ export type BrowserRunLinksOptions = BrowserRunCommonOptions & {
11905
+ /** When true, only return links that are visible on the page. @default false */
11906
+ visibleLinksOnly?: boolean;
11907
+ /** When true, exclude links pointing to external domains. @default false */
11908
+ excludeExternalLinks?: boolean;
11909
+ };
11910
+ export type BrowserRunSnapshotOptions = BrowserRunCommonOptions & {
11911
+ /** @see https://pptr.dev/api/puppeteer.screenshotoptions */
11912
+ screenshotOptions?: Omit<BrowserRunPuppeteerScreenshotOptions, "encoding">;
11913
+ };
11914
+ export interface BrowserRunJsonBaseOptions {
11915
+ /** Custom AI models to try in order. Max 3. Falls back to next on error. */
11916
+ custom_ai?: Array<{
11917
+ /** Model ID in `<provider>/<model_name>` format, e.g. `"workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast"`. */
11918
+ model: string;
11919
+ /** Bearer token. Not needed for workers-ai models. */
11920
+ authorization?: string;
11921
+ }>;
11922
+ }
11923
+ /**
11924
+ * Options for the `json` quick action.
11925
+ * At least one of `prompt` or `response_format` must be provided.
11926
+ */
11927
+ export type BrowserRunJsonOptions = BrowserRunCommonOptions &
11928
+ BrowserRunJsonBaseOptions &
11929
+ (
11930
+ | {
11931
+ /** Natural-language prompt describing what data to extract. */
11932
+ prompt: string;
11933
+ /** Structured output schema for the AI model. @see https://developers.cloudflare.com/workers-ai/json-mode/ */
11934
+ response_format?: AiTextGenerationResponseFormat;
11935
+ }
11936
+ | {
11937
+ /** Natural-language prompt describing what data to extract. */
11938
+ prompt?: string;
11939
+ /** Structured output schema for the AI model. @see https://developers.cloudflare.com/workers-ai/json-mode/ */
11940
+ response_format: AiTextGenerationResponseFormat;
11941
+ }
11942
+ );
11943
+ export type BrowserRunContentOptions = BrowserRunCommonOptions;
11944
+ export type BrowserRunMarkdownOptions = BrowserRunCommonOptions;
11945
+ export type BrowserRunResponseMeta = {
11946
+ /** HTTP status code of the rendered page */
11947
+ status: number;
11948
+ /** Page title */
11949
+ title: string;
11950
+ };
11951
+ /** Success response for `content` action. */
11952
+ export type BrowserRunContentSuccessResponse = {
11953
+ success: true;
11954
+ /** Extracted HTML content */
11955
+ result: string;
11956
+ meta: BrowserRunResponseMeta;
11957
+ };
11958
+ /** Success response for `links` action. */
11959
+ export type BrowserRunLinksSuccessResponse = {
11960
+ success: true;
11961
+ /** Extracted links */
11962
+ result: string[];
11963
+ };
11964
+ /** Success response for `scrape` action. */
11965
+ export type BrowserRunScrapeSuccessResponse = {
11966
+ success: true;
11967
+ result: Array<{
11968
+ /** The CSS selector used to find elements. */
11969
+ selector: string;
11970
+ /** Array of elements matching the selector. */
11971
+ results: Array<{
11972
+ /** Outer HTML of the element. */
11973
+ html: string;
11974
+ /** Text content of the element. */
11975
+ text: string;
11976
+ /** Width of the element in pixels. */
11977
+ width: number;
11978
+ /** Height of the element in pixels. */
11979
+ height: number;
11980
+ /** Top position of the element relative to the viewport in pixels. */
11981
+ top: number;
11982
+ /** Left position of the element relative to the viewport in pixels. */
11983
+ left: number;
11984
+ /** Array of HTML attributes on the element. */
11985
+ attributes: Array<{
11986
+ /** Attribute name. */
11987
+ name: string;
11988
+ /** Attribute value. */
11989
+ value: string;
11990
+ }>;
11991
+ }>;
11992
+ }>;
11993
+ };
11994
+ /** Success response for `snapshot` action. */
11995
+ export type BrowserRunSnapshotSuccessResponse = {
11996
+ success: true;
11997
+ result: {
11998
+ /** HTML content of the page. */
11999
+ content: string;
12000
+ /** Base64-encoded screenshot image. */
12001
+ screenshot: string;
12002
+ };
12003
+ meta: BrowserRunResponseMeta;
12004
+ };
12005
+ /** Success response for `json` action. */
12006
+ export type BrowserRunJsonSuccessResponse = {
12007
+ success: true;
12008
+ /** JSON data extracted from the page using an AI model */
12009
+ result: Record<string, unknown>;
12010
+ };
12011
+ /** Success response for `markdown` action. */
12012
+ export type BrowserRunMarkdownSuccessResponse = {
12013
+ success: true;
12014
+ /** Extracted markdown content */
12015
+ result: string;
12016
+ };
12017
+ /** Error response for BrowserRun actions. */
12018
+ export type BrowserRunErrorResponse = {
12019
+ success: false;
12020
+ errors: {
12021
+ message: string;
12022
+ code?: number;
12023
+ detail?: string;
12024
+ path?: string;
12025
+ }[];
12026
+ };
12027
+ /** Error response for BrowserRun `json` action. */
12028
+ export type BrowserRunJsonErrorResponse = BrowserRunErrorResponse & {
12029
+ /** Raw AI response text for debugging */
12030
+ rawAiResponse?: string;
12031
+ };
12032
+ /**
12033
+ * Browser Run API binding for automating headless browsers.
12034
+ * @see https://developers.cloudflare.com/browser-run/
12035
+ */
12036
+ export declare abstract class BrowserRun {
12037
+ /**
12038
+ * Send a raw HTTP request to the Browser Run API.
12039
+ * Used by libraries like `@cloudflare/puppeteer` to acquire and connect to a browser instance.
12040
+ * @see https://developers.cloudflare.com/browser-run/
12041
+ */
12042
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
12043
+ /**
12044
+ * Take a screenshot of a web page.
12045
+ * @param action - Must be `'screenshot'`.
12046
+ * @param options - Screenshot options including viewport, selectors, and image format.
12047
+ * @returns A `Response` containing one of:
12048
+ *
12049
+ * **Success (HTTP 200):**
12050
+ * - Binary image data with `Content-Type: image/png`, `image/jpeg`, or `image/webp` (when `encoding: 'binary'`, the default)
12051
+ * - Data URI string with `Content-Type: text/plain` (when `encoding: 'base64'`)
12052
+ *
12053
+ * **Error:**
12054
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12055
+ *
12056
+ * **Headers:**
12057
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12058
+ */
12059
+ quickAction(
12060
+ action: "screenshot",
12061
+ options: BrowserRunScreenshotOptions,
12062
+ ): Promise<Response>;
12063
+ /**
12064
+ * Generate a PDF of a web page.
12065
+ * @param action - Must be `'pdf'`.
12066
+ * @param options - PDF generation options including page size, margins, and headers/footers.
12067
+ * @returns A `Response` containing one of:
12068
+ *
12069
+ * **Success (HTTP 200):**
12070
+ * - Binary PDF data with `Content-Type: application/pdf`
12071
+ *
12072
+ * **Error:**
12073
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12074
+ *
12075
+ * **Headers:**
12076
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12077
+ */
12078
+ quickAction(action: "pdf", options: BrowserRunPDFOptions): Promise<Response>;
12079
+ /**
12080
+ * Get the HTML content of a web page.
12081
+ * @param action - Must be `'content'`.
12082
+ * @param options - Navigation and page interaction options.
12083
+ * @returns A `Response` containing one of:
12084
+ *
12085
+ * **Success (HTTP 200):**
12086
+ * - `BrowserRunContentSuccessResponse` JSON with `Content-Type: application/json`
12087
+ *
12088
+ * **Error:**
12089
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12090
+ *
12091
+ * **Headers:**
12092
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12093
+ */
12094
+ quickAction(
12095
+ action: "content",
12096
+ options: BrowserRunContentOptions,
12097
+ ): Promise<Response>;
12098
+ /**
12099
+ * Scrape elements from a web page by CSS selector.
12100
+ * @param action - Must be `'scrape'`.
12101
+ * @param options - Scrape options with CSS selectors for elements to extract.
12102
+ * @returns A `Response` containing one of:
12103
+ *
12104
+ * **Success (HTTP 200):**
12105
+ * - `BrowserRunScrapeSuccessResponse` JSON with `Content-Type: application/json`
12106
+ *
12107
+ * **Error:**
12108
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12109
+ *
12110
+ * **Headers:**
12111
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12112
+ */
12113
+ quickAction(
12114
+ action: "scrape",
12115
+ options: BrowserRunScrapeOptions,
12116
+ ): Promise<Response>;
12117
+ /**
12118
+ * Extract all links from a web page.
12119
+ * @param action - Must be `'links'`.
12120
+ * @param options - Options to filter visible or internal links only.
12121
+ * @returns A `Response` containing one of:
12122
+ *
12123
+ * **Success (HTTP 200):**
12124
+ * - `BrowserRunLinksSuccessResponse` JSON with `Content-Type: application/json`
12125
+ *
12126
+ * **Error:**
12127
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12128
+ *
12129
+ * **Headers:**
12130
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12131
+ */
12132
+ quickAction(
12133
+ action: "links",
12134
+ options: BrowserRunLinksOptions,
12135
+ ): Promise<Response>;
12136
+ /**
12137
+ * Get both the HTML content and a base64-encoded screenshot of a web page.
12138
+ * @param action - Must be `'snapshot'`.
12139
+ * @param options - Snapshot options including screenshot settings (encoding is always base64).
12140
+ * @returns A `Response` containing one of:
12141
+ *
12142
+ * **Success (HTTP 200):**
12143
+ * - `BrowserRunSnapshotSuccessResponse` JSON with `Content-Type: application/json`
12144
+ *
12145
+ * **Error:**
12146
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12147
+ *
12148
+ * **Headers:**
12149
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12150
+ */
12151
+ quickAction(
12152
+ action: "snapshot",
12153
+ options: BrowserRunSnapshotOptions,
12154
+ ): Promise<Response>;
12155
+ /**
12156
+ * Extract structured JSON data from a web page using AI.
12157
+ * @param action - Must be `'json'`.
12158
+ * @param options - JSON extraction options with prompt or response_format schema.
12159
+ * @returns A `Response` containing one of:
12160
+ *
12161
+ * **Success (HTTP 200):**
12162
+ * - `BrowserRunJsonSuccessResponse` JSON with `Content-Type: application/json`
12163
+ *
12164
+ * **Error:**
12165
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12166
+ * - HTTP 422 with code `2012` for HTML-to-markdown conversion failures
12167
+ * - HTTP 422/500 for AI extraction failures (may include `rawAiResponse` field)
12168
+ *
12169
+ * **Headers:**
12170
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12171
+ */
12172
+ quickAction(
12173
+ action: "json",
12174
+ options: BrowserRunJsonOptions,
12175
+ ): Promise<Response>;
12176
+ /**
12177
+ * Convert a web page to Markdown.
12178
+ * @param action - Must be `'markdown'`.
12179
+ * @param options - Navigation and page interaction options.
12180
+ * @returns A `Response` containing one of:
12181
+ *
12182
+ * **Success (HTTP 200):**
12183
+ * - `BrowserRunMarkdownSuccessResponse` JSON with `Content-Type: application/json`
12184
+ *
12185
+ * **Error:**
12186
+ * - `BrowserRunErrorResponse` JSON with appropriate HTTP status code (400, 422, 429, 500, 503)
12187
+ * - HTTP 422 with code `2012` for HTML-to-markdown conversion failures
12188
+ *
12189
+ * **Headers:**
12190
+ * - `X-Browser-Ms-Used`: Browser time consumed in milliseconds (set when status < 500)
12191
+ */
12192
+ quickAction(
12193
+ action: "markdown",
12194
+ options: BrowserRunMarkdownOptions,
12195
+ ): Promise<Response>;
12196
+ }
11457
12197
  export interface BasicImageTransformations {
11458
12198
  /**
11459
12199
  * Maximum width in image pixels. The value must be an integer.