@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.
@@ -3816,6 +3816,190 @@ declare abstract class Performance {
3816
3816
  get timeOrigin(): number;
3817
3817
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3818
3818
  now(): number;
3819
+ /**
3820
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3821
+ *
3822
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3823
+ */
3824
+ toJSON(): object;
3825
+ }
3826
+ // AI Search V2 API Error Interfaces
3827
+ interface AiSearchInternalError extends Error {}
3828
+ interface AiSearchNotFoundError extends Error {}
3829
+ interface AiSearchNameNotSetError extends Error {}
3830
+ // Filter types (shared with AutoRAG for compatibility)
3831
+ type ComparisonFilter = {
3832
+ key: string;
3833
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3834
+ value: string | number | boolean;
3835
+ };
3836
+ type CompoundFilter = {
3837
+ type: "and" | "or";
3838
+ filters: ComparisonFilter[];
3839
+ };
3840
+ // AI Search V2 Request Types
3841
+ type AiSearchSearchRequest = {
3842
+ messages: Array<{
3843
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3844
+ content: string | null;
3845
+ }>;
3846
+ ai_search_options?: {
3847
+ retrieval?: {
3848
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3849
+ /** Match threshold (0-1, default 0.4) */
3850
+ match_threshold?: number;
3851
+ /** Maximum number of results (1-50, default 10) */
3852
+ max_num_results?: number;
3853
+ filters?: CompoundFilter | ComparisonFilter;
3854
+ /** Context expansion (0-3, default 0) */
3855
+ context_expansion?: number;
3856
+ [key: string]: unknown;
3857
+ };
3858
+ query_rewrite?: {
3859
+ enabled?: boolean;
3860
+ model?: string;
3861
+ rewrite_prompt?: string;
3862
+ [key: string]: unknown;
3863
+ };
3864
+ reranking?: {
3865
+ /** Enable reranking (default false) */
3866
+ enabled?: boolean;
3867
+ model?: "@cf/baai/bge-reranker-base" | "";
3868
+ /** Match threshold (0-1, default 0.4) */
3869
+ match_threshold?: number;
3870
+ [key: string]: unknown;
3871
+ };
3872
+ [key: string]: unknown;
3873
+ };
3874
+ };
3875
+ type AiSearchChatCompletionsRequest = {
3876
+ messages: Array<{
3877
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3878
+ content: string | null;
3879
+ }>;
3880
+ model?: string;
3881
+ stream?: boolean;
3882
+ ai_search_options?: {
3883
+ retrieval?: {
3884
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3885
+ match_threshold?: number;
3886
+ max_num_results?: number;
3887
+ filters?: CompoundFilter | ComparisonFilter;
3888
+ context_expansion?: number;
3889
+ [key: string]: unknown;
3890
+ };
3891
+ query_rewrite?: {
3892
+ enabled?: boolean;
3893
+ model?: string;
3894
+ rewrite_prompt?: string;
3895
+ [key: string]: unknown;
3896
+ };
3897
+ reranking?: {
3898
+ enabled?: boolean;
3899
+ model?: "@cf/baai/bge-reranker-base" | "";
3900
+ match_threshold?: number;
3901
+ [key: string]: unknown;
3902
+ };
3903
+ [key: string]: unknown;
3904
+ };
3905
+ [key: string]: unknown;
3906
+ };
3907
+ // AI Search V2 Response Types
3908
+ type AiSearchSearchResponse = {
3909
+ search_query: string;
3910
+ chunks: Array<{
3911
+ id: string;
3912
+ type: string;
3913
+ /** Match score (0-1) */
3914
+ score: number;
3915
+ text: string;
3916
+ item: {
3917
+ timestamp?: number;
3918
+ key: string;
3919
+ metadata?: Record<string, unknown>;
3920
+ };
3921
+ scoring_details?: {
3922
+ /** Keyword match score (0-1) */
3923
+ keyword_score?: number;
3924
+ /** Vector similarity score (0-1) */
3925
+ vector_score?: number;
3926
+ };
3927
+ }>;
3928
+ };
3929
+ type AiSearchListResponse = Array<{
3930
+ id: string;
3931
+ internal_id?: string;
3932
+ account_id?: string;
3933
+ account_tag?: string;
3934
+ /** Whether the instance is enabled (default true) */
3935
+ enable?: boolean;
3936
+ type?: "r2" | "web-crawler";
3937
+ source?: string;
3938
+ [key: string]: unknown;
3939
+ }>;
3940
+ type AiSearchConfig = {
3941
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3942
+ id: string;
3943
+ type: "r2" | "web-crawler";
3944
+ source: string;
3945
+ source_params?: object;
3946
+ /** Token ID (UUID format) */
3947
+ token_id?: string;
3948
+ ai_gateway_id?: string;
3949
+ /** Enable query rewriting (default false) */
3950
+ rewrite_query?: boolean;
3951
+ /** Enable reranking (default false) */
3952
+ reranking?: boolean;
3953
+ embedding_model?: string;
3954
+ ai_search_model?: string;
3955
+ };
3956
+ type AiSearchInstance = {
3957
+ id: string;
3958
+ enable?: boolean;
3959
+ type?: "r2" | "web-crawler";
3960
+ source?: string;
3961
+ [key: string]: unknown;
3962
+ };
3963
+ // AI Search Instance Service - Instance-level operations
3964
+ declare abstract class AiSearchInstanceService {
3965
+ /**
3966
+ * Search the AI Search instance for relevant chunks.
3967
+ * @param params Search request with messages and AI search options
3968
+ * @returns Search response with matching chunks
3969
+ */
3970
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3971
+ /**
3972
+ * Generate chat completions with AI Search context.
3973
+ * @param params Chat completions request with optional streaming
3974
+ * @returns Response object (if streaming) or chat completion result
3975
+ */
3976
+ chatCompletions(
3977
+ params: AiSearchChatCompletionsRequest,
3978
+ ): Promise<Response | object>;
3979
+ /**
3980
+ * Delete this AI Search instance.
3981
+ */
3982
+ delete(): Promise<void>;
3983
+ }
3984
+ // AI Search Account Service - Account-level operations
3985
+ declare abstract class AiSearchAccountService {
3986
+ /**
3987
+ * List all AI Search instances in the account.
3988
+ * @returns Array of AI Search instances
3989
+ */
3990
+ list(): Promise<AiSearchListResponse>;
3991
+ /**
3992
+ * Get an AI Search instance by ID.
3993
+ * @param name Instance ID
3994
+ * @returns Instance service for performing operations
3995
+ */
3996
+ get(name: string): AiSearchInstanceService;
3997
+ /**
3998
+ * Create a new AI Search instance.
3999
+ * @param config Instance configuration
4000
+ * @returns Instance service for performing operations
4001
+ */
4002
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3819
4003
  }
3820
4004
  type AiImageClassificationInput = {
3821
4005
  image: number[];
@@ -9314,6 +9498,48 @@ type AiModelListType = Record<string, any>;
9314
9498
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9315
9499
  aiGatewayLogId: string | null;
9316
9500
  gateway(gatewayId: string): AiGateway;
9501
+ /**
9502
+ * Access the AI Search API for managing AI-powered search instances.
9503
+ *
9504
+ * This is the new API that replaces AutoRAG with better namespace separation:
9505
+ * - Account-level operations: `list()`, `create()`
9506
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9507
+ *
9508
+ * @example
9509
+ * ```typescript
9510
+ * // List all AI Search instances
9511
+ * const instances = await env.AI.aiSearch.list();
9512
+ *
9513
+ * // Search an instance
9514
+ * const results = await env.AI.aiSearch.get('my-search').search({
9515
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9516
+ * ai_search_options: {
9517
+ * retrieval: { max_num_results: 10 }
9518
+ * }
9519
+ * });
9520
+ *
9521
+ * // Generate chat completions with AI Search context
9522
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9523
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9524
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9525
+ * });
9526
+ * ```
9527
+ */
9528
+ aiSearch(): AiSearchAccountService;
9529
+ /**
9530
+ * @deprecated AutoRAG has been replaced by AI Search.
9531
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9532
+ *
9533
+ * Migration guide:
9534
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9535
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9536
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9537
+ *
9538
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9539
+ *
9540
+ * @see AiSearchAccountService
9541
+ * @param autoragId Optional instance ID (omit for account-level operations)
9542
+ */
9317
9543
  autorag(autoragId: string): AutoRAG;
9318
9544
  run<
9319
9545
  Name extends keyof AiModelList,
@@ -9470,19 +9696,30 @@ declare abstract class AiGateway {
9470
9696
  ): Promise<Response>;
9471
9697
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9472
9698
  }
9699
+ /**
9700
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9701
+ * @see AiSearchInternalError
9702
+ */
9473
9703
  interface AutoRAGInternalError extends Error {}
9704
+ /**
9705
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9706
+ * @see AiSearchNotFoundError
9707
+ */
9474
9708
  interface AutoRAGNotFoundError extends Error {}
9709
+ /**
9710
+ * @deprecated This error type is no longer used in the AI Search API.
9711
+ */
9475
9712
  interface AutoRAGUnauthorizedError extends Error {}
9713
+ /**
9714
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9715
+ * @see AiSearchNameNotSetError
9716
+ */
9476
9717
  interface AutoRAGNameNotSetError extends Error {}
9477
- type ComparisonFilter = {
9478
- key: string;
9479
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9480
- value: string | number | boolean;
9481
- };
9482
- type CompoundFilter = {
9483
- type: "and" | "or";
9484
- filters: ComparisonFilter[];
9485
- };
9718
+ /**
9719
+ * @deprecated AutoRAG has been replaced by AI Search.
9720
+ * Use AiSearchSearchRequest with the new API instead.
9721
+ * @see AiSearchSearchRequest
9722
+ */
9486
9723
  type AutoRagSearchRequest = {
9487
9724
  query: string;
9488
9725
  filters?: CompoundFilter | ComparisonFilter;
@@ -9497,16 +9734,31 @@ type AutoRagSearchRequest = {
9497
9734
  };
9498
9735
  rewrite_query?: boolean;
9499
9736
  };
9737
+ /**
9738
+ * @deprecated AutoRAG has been replaced by AI Search.
9739
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9740
+ * @see AiSearchChatCompletionsRequest
9741
+ */
9500
9742
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9501
9743
  stream?: boolean;
9502
9744
  system_prompt?: string;
9503
9745
  };
9746
+ /**
9747
+ * @deprecated AutoRAG has been replaced by AI Search.
9748
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9749
+ * @see AiSearchChatCompletionsRequest
9750
+ */
9504
9751
  type AutoRagAiSearchRequestStreaming = Omit<
9505
9752
  AutoRagAiSearchRequest,
9506
9753
  "stream"
9507
9754
  > & {
9508
9755
  stream: true;
9509
9756
  };
9757
+ /**
9758
+ * @deprecated AutoRAG has been replaced by AI Search.
9759
+ * Use AiSearchSearchResponse with the new API instead.
9760
+ * @see AiSearchSearchResponse
9761
+ */
9510
9762
  type AutoRagSearchResponse = {
9511
9763
  object: "vector_store.search_results.page";
9512
9764
  search_query: string;
@@ -9523,6 +9775,11 @@ type AutoRagSearchResponse = {
9523
9775
  has_more: boolean;
9524
9776
  next_page: string | null;
9525
9777
  };
9778
+ /**
9779
+ * @deprecated AutoRAG has been replaced by AI Search.
9780
+ * Use AiSearchListResponse with the new API instead.
9781
+ * @see AiSearchListResponse
9782
+ */
9526
9783
  type AutoRagListResponse = {
9527
9784
  id: string;
9528
9785
  enable: boolean;
@@ -9532,14 +9789,51 @@ type AutoRagListResponse = {
9532
9789
  paused: boolean;
9533
9790
  status: string;
9534
9791
  }[];
9792
+ /**
9793
+ * @deprecated AutoRAG has been replaced by AI Search.
9794
+ * The new API returns different response formats for chat completions.
9795
+ */
9535
9796
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9536
9797
  response: string;
9537
9798
  };
9799
+ /**
9800
+ * @deprecated AutoRAG has been replaced by AI Search.
9801
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9802
+ *
9803
+ * Migration guide:
9804
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9805
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9806
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9807
+ *
9808
+ * @see AiSearchAccountService
9809
+ * @see AiSearchInstanceService
9810
+ */
9538
9811
  declare abstract class AutoRAG {
9812
+ /**
9813
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9814
+ * @see AiSearchAccountService.list
9815
+ */
9539
9816
  list(): Promise<AutoRagListResponse>;
9817
+ /**
9818
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9819
+ * Note: The new API uses a messages array instead of a query string.
9820
+ * @see AiSearchInstanceService.search
9821
+ */
9540
9822
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9823
+ /**
9824
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9825
+ * @see AiSearchInstanceService.chatCompletions
9826
+ */
9541
9827
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9828
+ /**
9829
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9830
+ * @see AiSearchInstanceService.chatCompletions
9831
+ */
9542
9832
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9833
+ /**
9834
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9835
+ * @see AiSearchInstanceService.chatCompletions
9836
+ */
9543
9837
  aiSearch(
9544
9838
  params: AutoRagAiSearchRequest,
9545
9839
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10936,6 +11230,86 @@ type ImageOutputOptions = {
10936
11230
  background?: string;
10937
11231
  anim?: boolean;
10938
11232
  };
11233
+ interface ImageMetadata {
11234
+ id: string;
11235
+ filename?: string;
11236
+ uploaded?: string;
11237
+ requireSignedURLs: boolean;
11238
+ meta?: Record<string, unknown>;
11239
+ variants: string[];
11240
+ draft?: boolean;
11241
+ creator?: string;
11242
+ }
11243
+ interface ImageUploadOptions {
11244
+ id?: string;
11245
+ filename?: string;
11246
+ requireSignedURLs?: boolean;
11247
+ metadata?: Record<string, unknown>;
11248
+ creator?: string;
11249
+ encoding?: "base64";
11250
+ }
11251
+ interface ImageUpdateOptions {
11252
+ requireSignedURLs?: boolean;
11253
+ metadata?: Record<string, unknown>;
11254
+ creator?: string;
11255
+ }
11256
+ interface ImageListOptions {
11257
+ limit?: number;
11258
+ cursor?: string;
11259
+ sortOrder?: "asc" | "desc";
11260
+ creator?: string;
11261
+ }
11262
+ interface ImageList {
11263
+ images: ImageMetadata[];
11264
+ cursor?: string;
11265
+ listComplete: boolean;
11266
+ }
11267
+ interface HostedImagesBinding {
11268
+ /**
11269
+ * Get detailed metadata for a hosted image
11270
+ * @param imageId The ID of the image (UUID or custom ID)
11271
+ * @returns Image metadata, or null if not found
11272
+ */
11273
+ details(imageId: string): Promise<ImageMetadata | null>;
11274
+ /**
11275
+ * Get the raw image data for a hosted image
11276
+ * @param imageId The ID of the image (UUID or custom ID)
11277
+ * @returns ReadableStream of image bytes, or null if not found
11278
+ */
11279
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11280
+ /**
11281
+ * Upload a new hosted image
11282
+ * @param image The image file to upload
11283
+ * @param options Upload configuration
11284
+ * @returns Metadata for the uploaded image
11285
+ * @throws {@link ImagesError} if upload fails
11286
+ */
11287
+ upload(
11288
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11289
+ options?: ImageUploadOptions,
11290
+ ): Promise<ImageMetadata>;
11291
+ /**
11292
+ * Update hosted image metadata
11293
+ * @param imageId The ID of the image
11294
+ * @param options Properties to update
11295
+ * @returns Updated image metadata
11296
+ * @throws {@link ImagesError} if update fails
11297
+ */
11298
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11299
+ /**
11300
+ * Delete a hosted image
11301
+ * @param imageId The ID of the image
11302
+ * @returns True if deleted, false if not found
11303
+ */
11304
+ delete(imageId: string): Promise<boolean>;
11305
+ /**
11306
+ * List hosted images with pagination
11307
+ * @param options List configuration
11308
+ * @returns List of images with pagination info
11309
+ * @throws {@link ImagesError} if list fails
11310
+ */
11311
+ list(options?: ImageListOptions): Promise<ImageList>;
11312
+ }
10939
11313
  interface ImagesBinding {
10940
11314
  /**
10941
11315
  * Get image metadata (type, width and height)
@@ -10955,6 +11329,10 @@ interface ImagesBinding {
10955
11329
  stream: ReadableStream<Uint8Array>,
10956
11330
  options?: ImageInputOptions,
10957
11331
  ): ImageTransformer;
11332
+ /**
11333
+ * Access hosted images CRUD operations
11334
+ */
11335
+ readonly hosted: HostedImagesBinding;
10958
11336
  }
10959
11337
  interface ImageTransformer {
10960
11338
  /**
@@ -11025,8 +11403,14 @@ interface MediaTransformer {
11025
11403
  * @returns A generator for producing the transformed media output
11026
11404
  */
11027
11405
  transform(
11028
- transform: MediaTransformationInputOptions,
11406
+ transform?: MediaTransformationInputOptions,
11029
11407
  ): MediaTransformationGenerator;
11408
+ /**
11409
+ * Generates the final media output with specified options.
11410
+ * @param output - Configuration for the output format and parameters
11411
+ * @returns The final transformation result containing the transformed media
11412
+ */
11413
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11030
11414
  }
11031
11415
  /**
11032
11416
  * Generator for producing media transformation results.
@@ -11038,7 +11422,7 @@ interface MediaTransformationGenerator {
11038
11422
  * @param output - Configuration for the output format and parameters
11039
11423
  * @returns The final transformation result containing the transformed media
11040
11424
  */
11041
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11425
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11042
11426
  }
11043
11427
  /**
11044
11428
  * Result of a media transformation operation.
@@ -11047,19 +11431,19 @@ interface MediaTransformationGenerator {
11047
11431
  interface MediaTransformationResult {
11048
11432
  /**
11049
11433
  * Returns the transformed media as a readable stream of bytes.
11050
- * @returns A stream containing the transformed media data
11434
+ * @returns A promise containing a readable stream with the transformed media
11051
11435
  */
11052
- media(): ReadableStream<Uint8Array>;
11436
+ media(): Promise<ReadableStream<Uint8Array>>;
11053
11437
  /**
11054
11438
  * Returns the transformed media as an HTTP response object.
11055
- * @returns The transformed media as a Response, ready to store in cache or return to users
11439
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11056
11440
  */
11057
- response(): Response;
11441
+ response(): Promise<Response>;
11058
11442
  /**
11059
11443
  * Returns the MIME type of the transformed media.
11060
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11444
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11061
11445
  */
11062
- contentType(): string;
11446
+ contentType(): Promise<string>;
11063
11447
  }
11064
11448
  /**
11065
11449
  * Configuration options for transforming media input.