@cloudflare/workers-types 4.20260227.0 → 4.20260302.0

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.
@@ -3818,6 +3818,184 @@ export declare abstract class Performance {
3818
3818
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3819
3819
  now(): number;
3820
3820
  }
3821
+ // AI Search V2 API Error Interfaces
3822
+ export interface AiSearchInternalError extends Error {}
3823
+ export interface AiSearchNotFoundError extends Error {}
3824
+ export interface AiSearchNameNotSetError extends Error {}
3825
+ // Filter types (shared with AutoRAG for compatibility)
3826
+ export type ComparisonFilter = {
3827
+ key: string;
3828
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3829
+ value: string | number | boolean;
3830
+ };
3831
+ export type CompoundFilter = {
3832
+ type: "and" | "or";
3833
+ filters: ComparisonFilter[];
3834
+ };
3835
+ // AI Search V2 Request Types
3836
+ export type AiSearchSearchRequest = {
3837
+ messages: Array<{
3838
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3839
+ content: string | null;
3840
+ }>;
3841
+ ai_search_options?: {
3842
+ retrieval?: {
3843
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3844
+ /** Match threshold (0-1, default 0.4) */
3845
+ match_threshold?: number;
3846
+ /** Maximum number of results (1-50, default 10) */
3847
+ max_num_results?: number;
3848
+ filters?: CompoundFilter | ComparisonFilter;
3849
+ /** Context expansion (0-3, default 0) */
3850
+ context_expansion?: number;
3851
+ [key: string]: unknown;
3852
+ };
3853
+ query_rewrite?: {
3854
+ enabled?: boolean;
3855
+ model?: string;
3856
+ rewrite_prompt?: string;
3857
+ [key: string]: unknown;
3858
+ };
3859
+ reranking?: {
3860
+ /** Enable reranking (default false) */
3861
+ enabled?: boolean;
3862
+ model?: "@cf/baai/bge-reranker-base" | "";
3863
+ /** Match threshold (0-1, default 0.4) */
3864
+ match_threshold?: number;
3865
+ [key: string]: unknown;
3866
+ };
3867
+ [key: string]: unknown;
3868
+ };
3869
+ };
3870
+ export type AiSearchChatCompletionsRequest = {
3871
+ messages: Array<{
3872
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3873
+ content: string | null;
3874
+ }>;
3875
+ model?: string;
3876
+ stream?: boolean;
3877
+ ai_search_options?: {
3878
+ retrieval?: {
3879
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3880
+ match_threshold?: number;
3881
+ max_num_results?: number;
3882
+ filters?: CompoundFilter | ComparisonFilter;
3883
+ context_expansion?: number;
3884
+ [key: string]: unknown;
3885
+ };
3886
+ query_rewrite?: {
3887
+ enabled?: boolean;
3888
+ model?: string;
3889
+ rewrite_prompt?: string;
3890
+ [key: string]: unknown;
3891
+ };
3892
+ reranking?: {
3893
+ enabled?: boolean;
3894
+ model?: "@cf/baai/bge-reranker-base" | "";
3895
+ match_threshold?: number;
3896
+ [key: string]: unknown;
3897
+ };
3898
+ [key: string]: unknown;
3899
+ };
3900
+ [key: string]: unknown;
3901
+ };
3902
+ // AI Search V2 Response Types
3903
+ export type AiSearchSearchResponse = {
3904
+ search_query: string;
3905
+ chunks: Array<{
3906
+ id: string;
3907
+ type: string;
3908
+ /** Match score (0-1) */
3909
+ score: number;
3910
+ text: string;
3911
+ item: {
3912
+ timestamp?: number;
3913
+ key: string;
3914
+ metadata?: Record<string, unknown>;
3915
+ };
3916
+ scoring_details?: {
3917
+ /** Keyword match score (0-1) */
3918
+ keyword_score?: number;
3919
+ /** Vector similarity score (0-1) */
3920
+ vector_score?: number;
3921
+ };
3922
+ }>;
3923
+ };
3924
+ export type AiSearchListResponse = Array<{
3925
+ id: string;
3926
+ internal_id?: string;
3927
+ account_id?: string;
3928
+ account_tag?: string;
3929
+ /** Whether the instance is enabled (default true) */
3930
+ enable?: boolean;
3931
+ type?: "r2" | "web-crawler";
3932
+ source?: string;
3933
+ [key: string]: unknown;
3934
+ }>;
3935
+ export type AiSearchConfig = {
3936
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3937
+ id: string;
3938
+ type: "r2" | "web-crawler";
3939
+ source: string;
3940
+ source_params?: object;
3941
+ /** Token ID (UUID format) */
3942
+ token_id?: string;
3943
+ ai_gateway_id?: string;
3944
+ /** Enable query rewriting (default false) */
3945
+ rewrite_query?: boolean;
3946
+ /** Enable reranking (default false) */
3947
+ reranking?: boolean;
3948
+ embedding_model?: string;
3949
+ ai_search_model?: string;
3950
+ };
3951
+ export type AiSearchInstance = {
3952
+ id: string;
3953
+ enable?: boolean;
3954
+ type?: "r2" | "web-crawler";
3955
+ source?: string;
3956
+ [key: string]: unknown;
3957
+ };
3958
+ // AI Search Instance Service - Instance-level operations
3959
+ export declare abstract class AiSearchInstanceService {
3960
+ /**
3961
+ * Search the AI Search instance for relevant chunks.
3962
+ * @param params Search request with messages and AI search options
3963
+ * @returns Search response with matching chunks
3964
+ */
3965
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3966
+ /**
3967
+ * Generate chat completions with AI Search context.
3968
+ * @param params Chat completions request with optional streaming
3969
+ * @returns Response object (if streaming) or chat completion result
3970
+ */
3971
+ chatCompletions(
3972
+ params: AiSearchChatCompletionsRequest,
3973
+ ): Promise<Response | object>;
3974
+ /**
3975
+ * Delete this AI Search instance.
3976
+ */
3977
+ delete(): Promise<void>;
3978
+ }
3979
+ // AI Search Account Service - Account-level operations
3980
+ export declare abstract class AiSearchAccountService {
3981
+ /**
3982
+ * List all AI Search instances in the account.
3983
+ * @returns Array of AI Search instances
3984
+ */
3985
+ list(): Promise<AiSearchListResponse>;
3986
+ /**
3987
+ * Get an AI Search instance by ID.
3988
+ * @param name Instance ID
3989
+ * @returns Instance service for performing operations
3990
+ */
3991
+ get(name: string): AiSearchInstanceService;
3992
+ /**
3993
+ * Create a new AI Search instance.
3994
+ * @param config Instance configuration
3995
+ * @returns Instance service for performing operations
3996
+ */
3997
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3998
+ }
3821
3999
  export type AiImageClassificationInput = {
3822
4000
  image: number[];
3823
4001
  };
@@ -9318,6 +9496,48 @@ export declare abstract class Ai<
9318
9496
  > {
9319
9497
  aiGatewayLogId: string | null;
9320
9498
  gateway(gatewayId: string): AiGateway;
9499
+ /**
9500
+ * Access the AI Search API for managing AI-powered search instances.
9501
+ *
9502
+ * This is the new API that replaces AutoRAG with better namespace separation:
9503
+ * - Account-level operations: `list()`, `create()`
9504
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9505
+ *
9506
+ * @example
9507
+ * ```typescript
9508
+ * // List all AI Search instances
9509
+ * const instances = await env.AI.aiSearch.list();
9510
+ *
9511
+ * // Search an instance
9512
+ * const results = await env.AI.aiSearch.get('my-search').search({
9513
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9514
+ * ai_search_options: {
9515
+ * retrieval: { max_num_results: 10 }
9516
+ * }
9517
+ * });
9518
+ *
9519
+ * // Generate chat completions with AI Search context
9520
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9521
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9522
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9523
+ * });
9524
+ * ```
9525
+ */
9526
+ aiSearch: AiSearchAccountService;
9527
+ /**
9528
+ * @deprecated AutoRAG has been replaced by AI Search.
9529
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9530
+ *
9531
+ * Migration guide:
9532
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9533
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9534
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9535
+ *
9536
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9537
+ *
9538
+ * @see AiSearchAccountService
9539
+ * @param autoragId Optional instance ID (omit for account-level operations)
9540
+ */
9321
9541
  autorag(autoragId: string): AutoRAG;
9322
9542
  run<
9323
9543
  Name extends keyof AiModelList,
@@ -9474,19 +9694,30 @@ export declare abstract class AiGateway {
9474
9694
  ): Promise<Response>;
9475
9695
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9476
9696
  }
9697
+ /**
9698
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9699
+ * @see AiSearchInternalError
9700
+ */
9477
9701
  export interface AutoRAGInternalError extends Error {}
9702
+ /**
9703
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9704
+ * @see AiSearchNotFoundError
9705
+ */
9478
9706
  export interface AutoRAGNotFoundError extends Error {}
9707
+ /**
9708
+ * @deprecated This error type is no longer used in the AI Search API.
9709
+ */
9479
9710
  export interface AutoRAGUnauthorizedError extends Error {}
9711
+ /**
9712
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9713
+ * @see AiSearchNameNotSetError
9714
+ */
9480
9715
  export interface AutoRAGNameNotSetError extends Error {}
9481
- export type ComparisonFilter = {
9482
- key: string;
9483
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9484
- value: string | number | boolean;
9485
- };
9486
- export type CompoundFilter = {
9487
- type: "and" | "or";
9488
- filters: ComparisonFilter[];
9489
- };
9716
+ /**
9717
+ * @deprecated AutoRAG has been replaced by AI Search.
9718
+ * Use AiSearchSearchRequest with the new API instead.
9719
+ * @see AiSearchSearchRequest
9720
+ */
9490
9721
  export type AutoRagSearchRequest = {
9491
9722
  query: string;
9492
9723
  filters?: CompoundFilter | ComparisonFilter;
@@ -9501,16 +9732,31 @@ export type AutoRagSearchRequest = {
9501
9732
  };
9502
9733
  rewrite_query?: boolean;
9503
9734
  };
9735
+ /**
9736
+ * @deprecated AutoRAG has been replaced by AI Search.
9737
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9738
+ * @see AiSearchChatCompletionsRequest
9739
+ */
9504
9740
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9505
9741
  stream?: boolean;
9506
9742
  system_prompt?: string;
9507
9743
  };
9744
+ /**
9745
+ * @deprecated AutoRAG has been replaced by AI Search.
9746
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9747
+ * @see AiSearchChatCompletionsRequest
9748
+ */
9508
9749
  export type AutoRagAiSearchRequestStreaming = Omit<
9509
9750
  AutoRagAiSearchRequest,
9510
9751
  "stream"
9511
9752
  > & {
9512
9753
  stream: true;
9513
9754
  };
9755
+ /**
9756
+ * @deprecated AutoRAG has been replaced by AI Search.
9757
+ * Use AiSearchSearchResponse with the new API instead.
9758
+ * @see AiSearchSearchResponse
9759
+ */
9514
9760
  export type AutoRagSearchResponse = {
9515
9761
  object: "vector_store.search_results.page";
9516
9762
  search_query: string;
@@ -9527,6 +9773,11 @@ export type AutoRagSearchResponse = {
9527
9773
  has_more: boolean;
9528
9774
  next_page: string | null;
9529
9775
  };
9776
+ /**
9777
+ * @deprecated AutoRAG has been replaced by AI Search.
9778
+ * Use AiSearchListResponse with the new API instead.
9779
+ * @see AiSearchListResponse
9780
+ */
9530
9781
  export type AutoRagListResponse = {
9531
9782
  id: string;
9532
9783
  enable: boolean;
@@ -9536,14 +9787,51 @@ export type AutoRagListResponse = {
9536
9787
  paused: boolean;
9537
9788
  status: string;
9538
9789
  }[];
9790
+ /**
9791
+ * @deprecated AutoRAG has been replaced by AI Search.
9792
+ * The new API returns different response formats for chat completions.
9793
+ */
9539
9794
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9540
9795
  response: string;
9541
9796
  };
9797
+ /**
9798
+ * @deprecated AutoRAG has been replaced by AI Search.
9799
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9800
+ *
9801
+ * Migration guide:
9802
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9803
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9804
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9805
+ *
9806
+ * @see AiSearchAccountService
9807
+ * @see AiSearchInstanceService
9808
+ */
9542
9809
  export declare abstract class AutoRAG {
9810
+ /**
9811
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9812
+ * @see AiSearchAccountService.list
9813
+ */
9543
9814
  list(): Promise<AutoRagListResponse>;
9815
+ /**
9816
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9817
+ * Note: The new API uses a messages array instead of a query string.
9818
+ * @see AiSearchInstanceService.search
9819
+ */
9544
9820
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9821
+ /**
9822
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9823
+ * @see AiSearchInstanceService.chatCompletions
9824
+ */
9545
9825
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9826
+ /**
9827
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9828
+ * @see AiSearchInstanceService.chatCompletions
9829
+ */
9546
9830
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9831
+ /**
9832
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9833
+ * @see AiSearchInstanceService.chatCompletions
9834
+ */
9547
9835
  aiSearch(
9548
9836
  params: AutoRagAiSearchRequest,
9549
9837
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11034,8 +11322,14 @@ export interface MediaTransformer {
11034
11322
  * @returns A generator for producing the transformed media output
11035
11323
  */
11036
11324
  transform(
11037
- transform: MediaTransformationInputOptions,
11325
+ transform?: MediaTransformationInputOptions,
11038
11326
  ): MediaTransformationGenerator;
11327
+ /**
11328
+ * Generates the final media output with specified options.
11329
+ * @param output - Configuration for the output format and parameters
11330
+ * @returns The final transformation result containing the transformed media
11331
+ */
11332
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11039
11333
  }
11040
11334
  /**
11041
11335
  * Generator for producing media transformation results.
@@ -11047,7 +11341,7 @@ export interface MediaTransformationGenerator {
11047
11341
  * @param output - Configuration for the output format and parameters
11048
11342
  * @returns The final transformation result containing the transformed media
11049
11343
  */
11050
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11344
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11051
11345
  }
11052
11346
  /**
11053
11347
  * Result of a media transformation operation.
@@ -11056,19 +11350,19 @@ export interface MediaTransformationGenerator {
11056
11350
  export interface MediaTransformationResult {
11057
11351
  /**
11058
11352
  * Returns the transformed media as a readable stream of bytes.
11059
- * @returns A stream containing the transformed media data
11353
+ * @returns A promise containing a readable stream with the transformed media
11060
11354
  */
11061
- media(): ReadableStream<Uint8Array>;
11355
+ media(): Promise<ReadableStream<Uint8Array>>;
11062
11356
  /**
11063
11357
  * Returns the transformed media as an HTTP response object.
11064
- * @returns The transformed media as a Response, ready to store in cache or return to users
11358
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11065
11359
  */
11066
- response(): Response;
11360
+ response(): Promise<Response>;
11067
11361
  /**
11068
11362
  * Returns the MIME type of the transformed media.
11069
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11363
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11070
11364
  */
11071
- contentType(): string;
11365
+ contentType(): Promise<string>;
11072
11366
  }
11073
11367
  /**
11074
11368
  * Configuration options for transforming media input.