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