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