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