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