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