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