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