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