@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.
@@ -3751,6 +3751,184 @@ export declare abstract class Performance {
3751
3751
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3752
3752
  now(): number;
3753
3753
  }
3754
+ // AI Search V2 API Error Interfaces
3755
+ export interface AiSearchInternalError extends Error {}
3756
+ export interface AiSearchNotFoundError extends Error {}
3757
+ export interface AiSearchNameNotSetError extends Error {}
3758
+ // Filter types (shared with AutoRAG for compatibility)
3759
+ export type ComparisonFilter = {
3760
+ key: string;
3761
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3762
+ value: string | number | boolean;
3763
+ };
3764
+ export type CompoundFilter = {
3765
+ type: "and" | "or";
3766
+ filters: ComparisonFilter[];
3767
+ };
3768
+ // AI Search V2 Request Types
3769
+ export type AiSearchSearchRequest = {
3770
+ messages: Array<{
3771
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3772
+ content: string | null;
3773
+ }>;
3774
+ ai_search_options?: {
3775
+ retrieval?: {
3776
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3777
+ /** Match threshold (0-1, default 0.4) */
3778
+ match_threshold?: number;
3779
+ /** Maximum number of results (1-50, default 10) */
3780
+ max_num_results?: number;
3781
+ filters?: CompoundFilter | ComparisonFilter;
3782
+ /** Context expansion (0-3, default 0) */
3783
+ context_expansion?: number;
3784
+ [key: string]: unknown;
3785
+ };
3786
+ query_rewrite?: {
3787
+ enabled?: boolean;
3788
+ model?: string;
3789
+ rewrite_prompt?: string;
3790
+ [key: string]: unknown;
3791
+ };
3792
+ reranking?: {
3793
+ /** Enable reranking (default false) */
3794
+ enabled?: boolean;
3795
+ model?: "@cf/baai/bge-reranker-base" | "";
3796
+ /** Match threshold (0-1, default 0.4) */
3797
+ match_threshold?: number;
3798
+ [key: string]: unknown;
3799
+ };
3800
+ [key: string]: unknown;
3801
+ };
3802
+ };
3803
+ export type AiSearchChatCompletionsRequest = {
3804
+ messages: Array<{
3805
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3806
+ content: string | null;
3807
+ }>;
3808
+ model?: string;
3809
+ stream?: boolean;
3810
+ ai_search_options?: {
3811
+ retrieval?: {
3812
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3813
+ match_threshold?: number;
3814
+ max_num_results?: number;
3815
+ filters?: CompoundFilter | ComparisonFilter;
3816
+ context_expansion?: number;
3817
+ [key: string]: unknown;
3818
+ };
3819
+ query_rewrite?: {
3820
+ enabled?: boolean;
3821
+ model?: string;
3822
+ rewrite_prompt?: string;
3823
+ [key: string]: unknown;
3824
+ };
3825
+ reranking?: {
3826
+ enabled?: boolean;
3827
+ model?: "@cf/baai/bge-reranker-base" | "";
3828
+ match_threshold?: number;
3829
+ [key: string]: unknown;
3830
+ };
3831
+ [key: string]: unknown;
3832
+ };
3833
+ [key: string]: unknown;
3834
+ };
3835
+ // AI Search V2 Response Types
3836
+ export type AiSearchSearchResponse = {
3837
+ search_query: string;
3838
+ chunks: Array<{
3839
+ id: string;
3840
+ type: string;
3841
+ /** Match score (0-1) */
3842
+ score: number;
3843
+ text: string;
3844
+ item: {
3845
+ timestamp?: number;
3846
+ key: string;
3847
+ metadata?: Record<string, unknown>;
3848
+ };
3849
+ scoring_details?: {
3850
+ /** Keyword match score (0-1) */
3851
+ keyword_score?: number;
3852
+ /** Vector similarity score (0-1) */
3853
+ vector_score?: number;
3854
+ };
3855
+ }>;
3856
+ };
3857
+ export type AiSearchListResponse = Array<{
3858
+ id: string;
3859
+ internal_id?: string;
3860
+ account_id?: string;
3861
+ account_tag?: string;
3862
+ /** Whether the instance is enabled (default true) */
3863
+ enable?: boolean;
3864
+ type?: "r2" | "web-crawler";
3865
+ source?: string;
3866
+ [key: string]: unknown;
3867
+ }>;
3868
+ export type AiSearchConfig = {
3869
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3870
+ id: string;
3871
+ type: "r2" | "web-crawler";
3872
+ source: string;
3873
+ source_params?: object;
3874
+ /** Token ID (UUID format) */
3875
+ token_id?: string;
3876
+ ai_gateway_id?: string;
3877
+ /** Enable query rewriting (default false) */
3878
+ rewrite_query?: boolean;
3879
+ /** Enable reranking (default false) */
3880
+ reranking?: boolean;
3881
+ embedding_model?: string;
3882
+ ai_search_model?: string;
3883
+ };
3884
+ export type AiSearchInstance = {
3885
+ id: string;
3886
+ enable?: boolean;
3887
+ type?: "r2" | "web-crawler";
3888
+ source?: string;
3889
+ [key: string]: unknown;
3890
+ };
3891
+ // AI Search Instance Service - Instance-level operations
3892
+ export declare abstract class AiSearchInstanceService {
3893
+ /**
3894
+ * Search the AI Search instance for relevant chunks.
3895
+ * @param params Search request with messages and AI search options
3896
+ * @returns Search response with matching chunks
3897
+ */
3898
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3899
+ /**
3900
+ * Generate chat completions with AI Search context.
3901
+ * @param params Chat completions request with optional streaming
3902
+ * @returns Response object (if streaming) or chat completion result
3903
+ */
3904
+ chatCompletions(
3905
+ params: AiSearchChatCompletionsRequest,
3906
+ ): Promise<Response | object>;
3907
+ /**
3908
+ * Delete this AI Search instance.
3909
+ */
3910
+ delete(): Promise<void>;
3911
+ }
3912
+ // AI Search Account Service - Account-level operations
3913
+ export declare abstract class AiSearchAccountService {
3914
+ /**
3915
+ * List all AI Search instances in the account.
3916
+ * @returns Array of AI Search instances
3917
+ */
3918
+ list(): Promise<AiSearchListResponse>;
3919
+ /**
3920
+ * Get an AI Search instance by ID.
3921
+ * @param name Instance ID
3922
+ * @returns Instance service for performing operations
3923
+ */
3924
+ get(name: string): AiSearchInstanceService;
3925
+ /**
3926
+ * Create a new AI Search instance.
3927
+ * @param config Instance configuration
3928
+ * @returns Instance service for performing operations
3929
+ */
3930
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3931
+ }
3754
3932
  export type AiImageClassificationInput = {
3755
3933
  image: number[];
3756
3934
  };
@@ -9251,6 +9429,48 @@ export declare abstract class Ai<
9251
9429
  > {
9252
9430
  aiGatewayLogId: string | null;
9253
9431
  gateway(gatewayId: string): AiGateway;
9432
+ /**
9433
+ * Access the AI Search API for managing AI-powered search instances.
9434
+ *
9435
+ * This is the new API that replaces AutoRAG with better namespace separation:
9436
+ * - Account-level operations: `list()`, `create()`
9437
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9438
+ *
9439
+ * @example
9440
+ * ```typescript
9441
+ * // List all AI Search instances
9442
+ * const instances = await env.AI.aiSearch.list();
9443
+ *
9444
+ * // Search an instance
9445
+ * const results = await env.AI.aiSearch.get('my-search').search({
9446
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9447
+ * ai_search_options: {
9448
+ * retrieval: { max_num_results: 10 }
9449
+ * }
9450
+ * });
9451
+ *
9452
+ * // Generate chat completions with AI Search context
9453
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9454
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9455
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9456
+ * });
9457
+ * ```
9458
+ */
9459
+ aiSearch(): AiSearchAccountService;
9460
+ /**
9461
+ * @deprecated AutoRAG has been replaced by AI Search.
9462
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9463
+ *
9464
+ * Migration guide:
9465
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9466
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9467
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9468
+ *
9469
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9470
+ *
9471
+ * @see AiSearchAccountService
9472
+ * @param autoragId Optional instance ID (omit for account-level operations)
9473
+ */
9254
9474
  autorag(autoragId: string): AutoRAG;
9255
9475
  run<
9256
9476
  Name extends keyof AiModelList,
@@ -9407,19 +9627,30 @@ export declare abstract class AiGateway {
9407
9627
  ): Promise<Response>;
9408
9628
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9409
9629
  }
9630
+ /**
9631
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9632
+ * @see AiSearchInternalError
9633
+ */
9410
9634
  export interface AutoRAGInternalError extends Error {}
9635
+ /**
9636
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9637
+ * @see AiSearchNotFoundError
9638
+ */
9411
9639
  export interface AutoRAGNotFoundError extends Error {}
9640
+ /**
9641
+ * @deprecated This error type is no longer used in the AI Search API.
9642
+ */
9412
9643
  export interface AutoRAGUnauthorizedError extends Error {}
9644
+ /**
9645
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9646
+ * @see AiSearchNameNotSetError
9647
+ */
9413
9648
  export interface AutoRAGNameNotSetError extends Error {}
9414
- export type ComparisonFilter = {
9415
- key: string;
9416
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9417
- value: string | number | boolean;
9418
- };
9419
- export type CompoundFilter = {
9420
- type: "and" | "or";
9421
- filters: ComparisonFilter[];
9422
- };
9649
+ /**
9650
+ * @deprecated AutoRAG has been replaced by AI Search.
9651
+ * Use AiSearchSearchRequest with the new API instead.
9652
+ * @see AiSearchSearchRequest
9653
+ */
9423
9654
  export type AutoRagSearchRequest = {
9424
9655
  query: string;
9425
9656
  filters?: CompoundFilter | ComparisonFilter;
@@ -9434,16 +9665,31 @@ export type AutoRagSearchRequest = {
9434
9665
  };
9435
9666
  rewrite_query?: boolean;
9436
9667
  };
9668
+ /**
9669
+ * @deprecated AutoRAG has been replaced by AI Search.
9670
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9671
+ * @see AiSearchChatCompletionsRequest
9672
+ */
9437
9673
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9438
9674
  stream?: boolean;
9439
9675
  system_prompt?: string;
9440
9676
  };
9677
+ /**
9678
+ * @deprecated AutoRAG has been replaced by AI Search.
9679
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9680
+ * @see AiSearchChatCompletionsRequest
9681
+ */
9441
9682
  export type AutoRagAiSearchRequestStreaming = Omit<
9442
9683
  AutoRagAiSearchRequest,
9443
9684
  "stream"
9444
9685
  > & {
9445
9686
  stream: true;
9446
9687
  };
9688
+ /**
9689
+ * @deprecated AutoRAG has been replaced by AI Search.
9690
+ * Use AiSearchSearchResponse with the new API instead.
9691
+ * @see AiSearchSearchResponse
9692
+ */
9447
9693
  export type AutoRagSearchResponse = {
9448
9694
  object: "vector_store.search_results.page";
9449
9695
  search_query: string;
@@ -9460,6 +9706,11 @@ export type AutoRagSearchResponse = {
9460
9706
  has_more: boolean;
9461
9707
  next_page: string | null;
9462
9708
  };
9709
+ /**
9710
+ * @deprecated AutoRAG has been replaced by AI Search.
9711
+ * Use AiSearchListResponse with the new API instead.
9712
+ * @see AiSearchListResponse
9713
+ */
9463
9714
  export type AutoRagListResponse = {
9464
9715
  id: string;
9465
9716
  enable: boolean;
@@ -9469,14 +9720,51 @@ export type AutoRagListResponse = {
9469
9720
  paused: boolean;
9470
9721
  status: string;
9471
9722
  }[];
9723
+ /**
9724
+ * @deprecated AutoRAG has been replaced by AI Search.
9725
+ * The new API returns different response formats for chat completions.
9726
+ */
9472
9727
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9473
9728
  response: string;
9474
9729
  };
9730
+ /**
9731
+ * @deprecated AutoRAG has been replaced by AI Search.
9732
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9733
+ *
9734
+ * Migration guide:
9735
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9736
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9737
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9738
+ *
9739
+ * @see AiSearchAccountService
9740
+ * @see AiSearchInstanceService
9741
+ */
9475
9742
  export declare abstract class AutoRAG {
9743
+ /**
9744
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9745
+ * @see AiSearchAccountService.list
9746
+ */
9476
9747
  list(): Promise<AutoRagListResponse>;
9748
+ /**
9749
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9750
+ * Note: The new API uses a messages array instead of a query string.
9751
+ * @see AiSearchInstanceService.search
9752
+ */
9477
9753
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9754
+ /**
9755
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9756
+ * @see AiSearchInstanceService.chatCompletions
9757
+ */
9478
9758
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9759
+ /**
9760
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9761
+ * @see AiSearchInstanceService.chatCompletions
9762
+ */
9479
9763
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9764
+ /**
9765
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9766
+ * @see AiSearchInstanceService.chatCompletions
9767
+ */
9480
9768
  aiSearch(
9481
9769
  params: AutoRagAiSearchRequest,
9482
9770
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10878,6 +11166,86 @@ export type ImageOutputOptions = {
10878
11166
  background?: string;
10879
11167
  anim?: boolean;
10880
11168
  };
11169
+ export interface ImageMetadata {
11170
+ id: string;
11171
+ filename?: string;
11172
+ uploaded?: string;
11173
+ requireSignedURLs: boolean;
11174
+ meta?: Record<string, unknown>;
11175
+ variants: string[];
11176
+ draft?: boolean;
11177
+ creator?: string;
11178
+ }
11179
+ export interface ImageUploadOptions {
11180
+ id?: string;
11181
+ filename?: string;
11182
+ requireSignedURLs?: boolean;
11183
+ metadata?: Record<string, unknown>;
11184
+ creator?: string;
11185
+ encoding?: "base64";
11186
+ }
11187
+ export interface ImageUpdateOptions {
11188
+ requireSignedURLs?: boolean;
11189
+ metadata?: Record<string, unknown>;
11190
+ creator?: string;
11191
+ }
11192
+ export interface ImageListOptions {
11193
+ limit?: number;
11194
+ cursor?: string;
11195
+ sortOrder?: "asc" | "desc";
11196
+ creator?: string;
11197
+ }
11198
+ export interface ImageList {
11199
+ images: ImageMetadata[];
11200
+ cursor?: string;
11201
+ listComplete: boolean;
11202
+ }
11203
+ export interface HostedImagesBinding {
11204
+ /**
11205
+ * Get detailed metadata for a hosted image
11206
+ * @param imageId The ID of the image (UUID or custom ID)
11207
+ * @returns Image metadata, or null if not found
11208
+ */
11209
+ details(imageId: string): Promise<ImageMetadata | null>;
11210
+ /**
11211
+ * Get the raw image data for a hosted image
11212
+ * @param imageId The ID of the image (UUID or custom ID)
11213
+ * @returns ReadableStream of image bytes, or null if not found
11214
+ */
11215
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11216
+ /**
11217
+ * Upload a new hosted image
11218
+ * @param image The image file to upload
11219
+ * @param options Upload configuration
11220
+ * @returns Metadata for the uploaded image
11221
+ * @throws {@link ImagesError} if upload fails
11222
+ */
11223
+ upload(
11224
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11225
+ options?: ImageUploadOptions,
11226
+ ): Promise<ImageMetadata>;
11227
+ /**
11228
+ * Update hosted image metadata
11229
+ * @param imageId The ID of the image
11230
+ * @param options Properties to update
11231
+ * @returns Updated image metadata
11232
+ * @throws {@link ImagesError} if update fails
11233
+ */
11234
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11235
+ /**
11236
+ * Delete a hosted image
11237
+ * @param imageId The ID of the image
11238
+ * @returns True if deleted, false if not found
11239
+ */
11240
+ delete(imageId: string): Promise<boolean>;
11241
+ /**
11242
+ * List hosted images with pagination
11243
+ * @param options List configuration
11244
+ * @returns List of images with pagination info
11245
+ * @throws {@link ImagesError} if list fails
11246
+ */
11247
+ list(options?: ImageListOptions): Promise<ImageList>;
11248
+ }
10881
11249
  export interface ImagesBinding {
10882
11250
  /**
10883
11251
  * Get image metadata (type, width and height)
@@ -10897,6 +11265,10 @@ export interface ImagesBinding {
10897
11265
  stream: ReadableStream<Uint8Array>,
10898
11266
  options?: ImageInputOptions,
10899
11267
  ): ImageTransformer;
11268
+ /**
11269
+ * Access hosted images CRUD operations
11270
+ */
11271
+ readonly hosted: HostedImagesBinding;
10900
11272
  }
10901
11273
  export interface ImageTransformer {
10902
11274
  /**
@@ -10967,8 +11339,14 @@ export interface MediaTransformer {
10967
11339
  * @returns A generator for producing the transformed media output
10968
11340
  */
10969
11341
  transform(
10970
- transform: MediaTransformationInputOptions,
11342
+ transform?: MediaTransformationInputOptions,
10971
11343
  ): MediaTransformationGenerator;
11344
+ /**
11345
+ * Generates the final media output with specified options.
11346
+ * @param output - Configuration for the output format and parameters
11347
+ * @returns The final transformation result containing the transformed media
11348
+ */
11349
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10972
11350
  }
10973
11351
  /**
10974
11352
  * Generator for producing media transformation results.
@@ -10980,7 +11358,7 @@ export interface MediaTransformationGenerator {
10980
11358
  * @param output - Configuration for the output format and parameters
10981
11359
  * @returns The final transformation result containing the transformed media
10982
11360
  */
10983
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11361
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10984
11362
  }
10985
11363
  /**
10986
11364
  * Result of a media transformation operation.
@@ -10989,19 +11367,19 @@ export interface MediaTransformationGenerator {
10989
11367
  export interface MediaTransformationResult {
10990
11368
  /**
10991
11369
  * Returns the transformed media as a readable stream of bytes.
10992
- * @returns A stream containing the transformed media data
11370
+ * @returns A promise containing a readable stream with the transformed media
10993
11371
  */
10994
- media(): ReadableStream<Uint8Array>;
11372
+ media(): Promise<ReadableStream<Uint8Array>>;
10995
11373
  /**
10996
11374
  * Returns the transformed media as an HTTP response object.
10997
- * @returns The transformed media as a Response, ready to store in cache or return to users
11375
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
10998
11376
  */
10999
- response(): Response;
11377
+ response(): Promise<Response>;
11000
11378
  /**
11001
11379
  * Returns the MIME type of the transformed media.
11002
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11380
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11003
11381
  */
11004
- contentType(): string;
11382
+ contentType(): Promise<string>;
11005
11383
  }
11006
11384
  /**
11007
11385
  * Configuration options for transforming media input.