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