@cloudflare/workers-types 4.20260227.0 → 4.20260228.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.
@@ -3825,6 +3825,190 @@ export declare abstract class Performance {
3825
3825
  get timeOrigin(): number;
3826
3826
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3827
3827
  now(): number;
3828
+ /**
3829
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3830
+ *
3831
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3832
+ */
3833
+ toJSON(): object;
3834
+ }
3835
+ // AI Search V2 API Error Interfaces
3836
+ export interface AiSearchInternalError extends Error {}
3837
+ export interface AiSearchNotFoundError extends Error {}
3838
+ export interface AiSearchNameNotSetError extends Error {}
3839
+ // Filter types (shared with AutoRAG for compatibility)
3840
+ export type ComparisonFilter = {
3841
+ key: string;
3842
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3843
+ value: string | number | boolean;
3844
+ };
3845
+ export type CompoundFilter = {
3846
+ type: "and" | "or";
3847
+ filters: ComparisonFilter[];
3848
+ };
3849
+ // AI Search V2 Request Types
3850
+ export type AiSearchSearchRequest = {
3851
+ messages: Array<{
3852
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3853
+ content: string | null;
3854
+ }>;
3855
+ ai_search_options?: {
3856
+ retrieval?: {
3857
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3858
+ /** Match threshold (0-1, default 0.4) */
3859
+ match_threshold?: number;
3860
+ /** Maximum number of results (1-50, default 10) */
3861
+ max_num_results?: number;
3862
+ filters?: CompoundFilter | ComparisonFilter;
3863
+ /** Context expansion (0-3, default 0) */
3864
+ context_expansion?: number;
3865
+ [key: string]: unknown;
3866
+ };
3867
+ query_rewrite?: {
3868
+ enabled?: boolean;
3869
+ model?: string;
3870
+ rewrite_prompt?: string;
3871
+ [key: string]: unknown;
3872
+ };
3873
+ reranking?: {
3874
+ /** Enable reranking (default false) */
3875
+ enabled?: boolean;
3876
+ model?: "@cf/baai/bge-reranker-base" | "";
3877
+ /** Match threshold (0-1, default 0.4) */
3878
+ match_threshold?: number;
3879
+ [key: string]: unknown;
3880
+ };
3881
+ [key: string]: unknown;
3882
+ };
3883
+ };
3884
+ export type AiSearchChatCompletionsRequest = {
3885
+ messages: Array<{
3886
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3887
+ content: string | null;
3888
+ }>;
3889
+ model?: string;
3890
+ stream?: boolean;
3891
+ ai_search_options?: {
3892
+ retrieval?: {
3893
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3894
+ match_threshold?: number;
3895
+ max_num_results?: number;
3896
+ filters?: CompoundFilter | ComparisonFilter;
3897
+ context_expansion?: number;
3898
+ [key: string]: unknown;
3899
+ };
3900
+ query_rewrite?: {
3901
+ enabled?: boolean;
3902
+ model?: string;
3903
+ rewrite_prompt?: string;
3904
+ [key: string]: unknown;
3905
+ };
3906
+ reranking?: {
3907
+ enabled?: boolean;
3908
+ model?: "@cf/baai/bge-reranker-base" | "";
3909
+ match_threshold?: number;
3910
+ [key: string]: unknown;
3911
+ };
3912
+ [key: string]: unknown;
3913
+ };
3914
+ [key: string]: unknown;
3915
+ };
3916
+ // AI Search V2 Response Types
3917
+ export type AiSearchSearchResponse = {
3918
+ search_query: string;
3919
+ chunks: Array<{
3920
+ id: string;
3921
+ type: string;
3922
+ /** Match score (0-1) */
3923
+ score: number;
3924
+ text: string;
3925
+ item: {
3926
+ timestamp?: number;
3927
+ key: string;
3928
+ metadata?: Record<string, unknown>;
3929
+ };
3930
+ scoring_details?: {
3931
+ /** Keyword match score (0-1) */
3932
+ keyword_score?: number;
3933
+ /** Vector similarity score (0-1) */
3934
+ vector_score?: number;
3935
+ };
3936
+ }>;
3937
+ };
3938
+ export type AiSearchListResponse = Array<{
3939
+ id: string;
3940
+ internal_id?: string;
3941
+ account_id?: string;
3942
+ account_tag?: string;
3943
+ /** Whether the instance is enabled (default true) */
3944
+ enable?: boolean;
3945
+ type?: "r2" | "web-crawler";
3946
+ source?: string;
3947
+ [key: string]: unknown;
3948
+ }>;
3949
+ export type AiSearchConfig = {
3950
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3951
+ id: string;
3952
+ type: "r2" | "web-crawler";
3953
+ source: string;
3954
+ source_params?: object;
3955
+ /** Token ID (UUID format) */
3956
+ token_id?: string;
3957
+ ai_gateway_id?: string;
3958
+ /** Enable query rewriting (default false) */
3959
+ rewrite_query?: boolean;
3960
+ /** Enable reranking (default false) */
3961
+ reranking?: boolean;
3962
+ embedding_model?: string;
3963
+ ai_search_model?: string;
3964
+ };
3965
+ export type AiSearchInstance = {
3966
+ id: string;
3967
+ enable?: boolean;
3968
+ type?: "r2" | "web-crawler";
3969
+ source?: string;
3970
+ [key: string]: unknown;
3971
+ };
3972
+ // AI Search Instance Service - Instance-level operations
3973
+ export declare abstract class AiSearchInstanceService {
3974
+ /**
3975
+ * Search the AI Search instance for relevant chunks.
3976
+ * @param params Search request with messages and AI search options
3977
+ * @returns Search response with matching chunks
3978
+ */
3979
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3980
+ /**
3981
+ * Generate chat completions with AI Search context.
3982
+ * @param params Chat completions request with optional streaming
3983
+ * @returns Response object (if streaming) or chat completion result
3984
+ */
3985
+ chatCompletions(
3986
+ params: AiSearchChatCompletionsRequest,
3987
+ ): Promise<Response | object>;
3988
+ /**
3989
+ * Delete this AI Search instance.
3990
+ */
3991
+ delete(): Promise<void>;
3992
+ }
3993
+ // AI Search Account Service - Account-level operations
3994
+ export declare abstract class AiSearchAccountService {
3995
+ /**
3996
+ * List all AI Search instances in the account.
3997
+ * @returns Array of AI Search instances
3998
+ */
3999
+ list(): Promise<AiSearchListResponse>;
4000
+ /**
4001
+ * Get an AI Search instance by ID.
4002
+ * @param name Instance ID
4003
+ * @returns Instance service for performing operations
4004
+ */
4005
+ get(name: string): AiSearchInstanceService;
4006
+ /**
4007
+ * Create a new AI Search instance.
4008
+ * @param config Instance configuration
4009
+ * @returns Instance service for performing operations
4010
+ */
4011
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3828
4012
  }
3829
4013
  export type AiImageClassificationInput = {
3830
4014
  image: number[];
@@ -9326,6 +9510,48 @@ export declare abstract class Ai<
9326
9510
  > {
9327
9511
  aiGatewayLogId: string | null;
9328
9512
  gateway(gatewayId: string): AiGateway;
9513
+ /**
9514
+ * Access the AI Search API for managing AI-powered search instances.
9515
+ *
9516
+ * This is the new API that replaces AutoRAG with better namespace separation:
9517
+ * - Account-level operations: `list()`, `create()`
9518
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9519
+ *
9520
+ * @example
9521
+ * ```typescript
9522
+ * // List all AI Search instances
9523
+ * const instances = await env.AI.aiSearch.list();
9524
+ *
9525
+ * // Search an instance
9526
+ * const results = await env.AI.aiSearch.get('my-search').search({
9527
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9528
+ * ai_search_options: {
9529
+ * retrieval: { max_num_results: 10 }
9530
+ * }
9531
+ * });
9532
+ *
9533
+ * // Generate chat completions with AI Search context
9534
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9535
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9536
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9537
+ * });
9538
+ * ```
9539
+ */
9540
+ aiSearch(): AiSearchAccountService;
9541
+ /**
9542
+ * @deprecated AutoRAG has been replaced by AI Search.
9543
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9544
+ *
9545
+ * Migration guide:
9546
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9547
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9548
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9549
+ *
9550
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9551
+ *
9552
+ * @see AiSearchAccountService
9553
+ * @param autoragId Optional instance ID (omit for account-level operations)
9554
+ */
9329
9555
  autorag(autoragId: string): AutoRAG;
9330
9556
  run<
9331
9557
  Name extends keyof AiModelList,
@@ -9482,19 +9708,30 @@ export declare abstract class AiGateway {
9482
9708
  ): Promise<Response>;
9483
9709
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9484
9710
  }
9711
+ /**
9712
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9713
+ * @see AiSearchInternalError
9714
+ */
9485
9715
  export interface AutoRAGInternalError extends Error {}
9716
+ /**
9717
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9718
+ * @see AiSearchNotFoundError
9719
+ */
9486
9720
  export interface AutoRAGNotFoundError extends Error {}
9721
+ /**
9722
+ * @deprecated This error type is no longer used in the AI Search API.
9723
+ */
9487
9724
  export interface AutoRAGUnauthorizedError extends Error {}
9725
+ /**
9726
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9727
+ * @see AiSearchNameNotSetError
9728
+ */
9488
9729
  export interface AutoRAGNameNotSetError extends Error {}
9489
- export type ComparisonFilter = {
9490
- key: string;
9491
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9492
- value: string | number | boolean;
9493
- };
9494
- export type CompoundFilter = {
9495
- type: "and" | "or";
9496
- filters: ComparisonFilter[];
9497
- };
9730
+ /**
9731
+ * @deprecated AutoRAG has been replaced by AI Search.
9732
+ * Use AiSearchSearchRequest with the new API instead.
9733
+ * @see AiSearchSearchRequest
9734
+ */
9498
9735
  export type AutoRagSearchRequest = {
9499
9736
  query: string;
9500
9737
  filters?: CompoundFilter | ComparisonFilter;
@@ -9509,16 +9746,31 @@ export type AutoRagSearchRequest = {
9509
9746
  };
9510
9747
  rewrite_query?: boolean;
9511
9748
  };
9749
+ /**
9750
+ * @deprecated AutoRAG has been replaced by AI Search.
9751
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9752
+ * @see AiSearchChatCompletionsRequest
9753
+ */
9512
9754
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9513
9755
  stream?: boolean;
9514
9756
  system_prompt?: string;
9515
9757
  };
9758
+ /**
9759
+ * @deprecated AutoRAG has been replaced by AI Search.
9760
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9761
+ * @see AiSearchChatCompletionsRequest
9762
+ */
9516
9763
  export type AutoRagAiSearchRequestStreaming = Omit<
9517
9764
  AutoRagAiSearchRequest,
9518
9765
  "stream"
9519
9766
  > & {
9520
9767
  stream: true;
9521
9768
  };
9769
+ /**
9770
+ * @deprecated AutoRAG has been replaced by AI Search.
9771
+ * Use AiSearchSearchResponse with the new API instead.
9772
+ * @see AiSearchSearchResponse
9773
+ */
9522
9774
  export type AutoRagSearchResponse = {
9523
9775
  object: "vector_store.search_results.page";
9524
9776
  search_query: string;
@@ -9535,6 +9787,11 @@ export type AutoRagSearchResponse = {
9535
9787
  has_more: boolean;
9536
9788
  next_page: string | null;
9537
9789
  };
9790
+ /**
9791
+ * @deprecated AutoRAG has been replaced by AI Search.
9792
+ * Use AiSearchListResponse with the new API instead.
9793
+ * @see AiSearchListResponse
9794
+ */
9538
9795
  export type AutoRagListResponse = {
9539
9796
  id: string;
9540
9797
  enable: boolean;
@@ -9544,14 +9801,51 @@ export type AutoRagListResponse = {
9544
9801
  paused: boolean;
9545
9802
  status: string;
9546
9803
  }[];
9804
+ /**
9805
+ * @deprecated AutoRAG has been replaced by AI Search.
9806
+ * The new API returns different response formats for chat completions.
9807
+ */
9547
9808
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9548
9809
  response: string;
9549
9810
  };
9811
+ /**
9812
+ * @deprecated AutoRAG has been replaced by AI Search.
9813
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9814
+ *
9815
+ * Migration guide:
9816
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9817
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9818
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9819
+ *
9820
+ * @see AiSearchAccountService
9821
+ * @see AiSearchInstanceService
9822
+ */
9550
9823
  export declare abstract class AutoRAG {
9824
+ /**
9825
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9826
+ * @see AiSearchAccountService.list
9827
+ */
9551
9828
  list(): Promise<AutoRagListResponse>;
9829
+ /**
9830
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9831
+ * Note: The new API uses a messages array instead of a query string.
9832
+ * @see AiSearchInstanceService.search
9833
+ */
9552
9834
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9835
+ /**
9836
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9837
+ * @see AiSearchInstanceService.chatCompletions
9838
+ */
9553
9839
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9840
+ /**
9841
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9842
+ * @see AiSearchInstanceService.chatCompletions
9843
+ */
9554
9844
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9845
+ /**
9846
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9847
+ * @see AiSearchInstanceService.chatCompletions
9848
+ */
9555
9849
  aiSearch(
9556
9850
  params: AutoRagAiSearchRequest,
9557
9851
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10953,6 +11247,86 @@ export type ImageOutputOptions = {
10953
11247
  background?: string;
10954
11248
  anim?: boolean;
10955
11249
  };
11250
+ export interface ImageMetadata {
11251
+ id: string;
11252
+ filename?: string;
11253
+ uploaded?: string;
11254
+ requireSignedURLs: boolean;
11255
+ meta?: Record<string, unknown>;
11256
+ variants: string[];
11257
+ draft?: boolean;
11258
+ creator?: string;
11259
+ }
11260
+ export interface ImageUploadOptions {
11261
+ id?: string;
11262
+ filename?: string;
11263
+ requireSignedURLs?: boolean;
11264
+ metadata?: Record<string, unknown>;
11265
+ creator?: string;
11266
+ encoding?: "base64";
11267
+ }
11268
+ export interface ImageUpdateOptions {
11269
+ requireSignedURLs?: boolean;
11270
+ metadata?: Record<string, unknown>;
11271
+ creator?: string;
11272
+ }
11273
+ export interface ImageListOptions {
11274
+ limit?: number;
11275
+ cursor?: string;
11276
+ sortOrder?: "asc" | "desc";
11277
+ creator?: string;
11278
+ }
11279
+ export interface ImageList {
11280
+ images: ImageMetadata[];
11281
+ cursor?: string;
11282
+ listComplete: boolean;
11283
+ }
11284
+ export interface HostedImagesBinding {
11285
+ /**
11286
+ * Get detailed metadata for a hosted image
11287
+ * @param imageId The ID of the image (UUID or custom ID)
11288
+ * @returns Image metadata, or null if not found
11289
+ */
11290
+ details(imageId: string): Promise<ImageMetadata | null>;
11291
+ /**
11292
+ * Get the raw image data for a hosted image
11293
+ * @param imageId The ID of the image (UUID or custom ID)
11294
+ * @returns ReadableStream of image bytes, or null if not found
11295
+ */
11296
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11297
+ /**
11298
+ * Upload a new hosted image
11299
+ * @param image The image file to upload
11300
+ * @param options Upload configuration
11301
+ * @returns Metadata for the uploaded image
11302
+ * @throws {@link ImagesError} if upload fails
11303
+ */
11304
+ upload(
11305
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11306
+ options?: ImageUploadOptions,
11307
+ ): Promise<ImageMetadata>;
11308
+ /**
11309
+ * Update hosted image metadata
11310
+ * @param imageId The ID of the image
11311
+ * @param options Properties to update
11312
+ * @returns Updated image metadata
11313
+ * @throws {@link ImagesError} if update fails
11314
+ */
11315
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11316
+ /**
11317
+ * Delete a hosted image
11318
+ * @param imageId The ID of the image
11319
+ * @returns True if deleted, false if not found
11320
+ */
11321
+ delete(imageId: string): Promise<boolean>;
11322
+ /**
11323
+ * List hosted images with pagination
11324
+ * @param options List configuration
11325
+ * @returns List of images with pagination info
11326
+ * @throws {@link ImagesError} if list fails
11327
+ */
11328
+ list(options?: ImageListOptions): Promise<ImageList>;
11329
+ }
10956
11330
  export interface ImagesBinding {
10957
11331
  /**
10958
11332
  * Get image metadata (type, width and height)
@@ -10972,6 +11346,10 @@ export interface ImagesBinding {
10972
11346
  stream: ReadableStream<Uint8Array>,
10973
11347
  options?: ImageInputOptions,
10974
11348
  ): ImageTransformer;
11349
+ /**
11350
+ * Access hosted images CRUD operations
11351
+ */
11352
+ readonly hosted: HostedImagesBinding;
10975
11353
  }
10976
11354
  export interface ImageTransformer {
10977
11355
  /**
@@ -11042,8 +11420,14 @@ export interface MediaTransformer {
11042
11420
  * @returns A generator for producing the transformed media output
11043
11421
  */
11044
11422
  transform(
11045
- transform: MediaTransformationInputOptions,
11423
+ transform?: MediaTransformationInputOptions,
11046
11424
  ): MediaTransformationGenerator;
11425
+ /**
11426
+ * Generates the final media output with specified options.
11427
+ * @param output - Configuration for the output format and parameters
11428
+ * @returns The final transformation result containing the transformed media
11429
+ */
11430
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11047
11431
  }
11048
11432
  /**
11049
11433
  * Generator for producing media transformation results.
@@ -11055,7 +11439,7 @@ export interface MediaTransformationGenerator {
11055
11439
  * @param output - Configuration for the output format and parameters
11056
11440
  * @returns The final transformation result containing the transformed media
11057
11441
  */
11058
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11442
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11059
11443
  }
11060
11444
  /**
11061
11445
  * Result of a media transformation operation.
@@ -11064,19 +11448,19 @@ export interface MediaTransformationGenerator {
11064
11448
  export interface MediaTransformationResult {
11065
11449
  /**
11066
11450
  * Returns the transformed media as a readable stream of bytes.
11067
- * @returns A stream containing the transformed media data
11451
+ * @returns A promise containing a readable stream with the transformed media
11068
11452
  */
11069
- media(): ReadableStream<Uint8Array>;
11453
+ media(): Promise<ReadableStream<Uint8Array>>;
11070
11454
  /**
11071
11455
  * Returns the transformed media as an HTTP response object.
11072
- * @returns The transformed media as a Response, ready to store in cache or return to users
11456
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11073
11457
  */
11074
- response(): Response;
11458
+ response(): Promise<Response>;
11075
11459
  /**
11076
11460
  * Returns the MIME type of the transformed media.
11077
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11461
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11078
11462
  */
11079
- contentType(): string;
11463
+ contentType(): Promise<string>;
11080
11464
  }
11081
11465
  /**
11082
11466
  * Configuration options for transforming media input.