@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.
package/latest/index.d.ts CHANGED
@@ -3882,6 +3882,184 @@ declare abstract class Performance {
3882
3882
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3883
3883
  now(): number;
3884
3884
  }
3885
+ // AI Search V2 API Error Interfaces
3886
+ interface AiSearchInternalError extends Error {}
3887
+ interface AiSearchNotFoundError extends Error {}
3888
+ interface AiSearchNameNotSetError extends Error {}
3889
+ // Filter types (shared with AutoRAG for compatibility)
3890
+ type ComparisonFilter = {
3891
+ key: string;
3892
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3893
+ value: string | number | boolean;
3894
+ };
3895
+ type CompoundFilter = {
3896
+ type: "and" | "or";
3897
+ filters: ComparisonFilter[];
3898
+ };
3899
+ // AI Search V2 Request Types
3900
+ type AiSearchSearchRequest = {
3901
+ messages: Array<{
3902
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3903
+ content: string | null;
3904
+ }>;
3905
+ ai_search_options?: {
3906
+ retrieval?: {
3907
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3908
+ /** Match threshold (0-1, default 0.4) */
3909
+ match_threshold?: number;
3910
+ /** Maximum number of results (1-50, default 10) */
3911
+ max_num_results?: number;
3912
+ filters?: CompoundFilter | ComparisonFilter;
3913
+ /** Context expansion (0-3, default 0) */
3914
+ context_expansion?: number;
3915
+ [key: string]: unknown;
3916
+ };
3917
+ query_rewrite?: {
3918
+ enabled?: boolean;
3919
+ model?: string;
3920
+ rewrite_prompt?: string;
3921
+ [key: string]: unknown;
3922
+ };
3923
+ reranking?: {
3924
+ /** Enable reranking (default false) */
3925
+ enabled?: boolean;
3926
+ model?: "@cf/baai/bge-reranker-base" | "";
3927
+ /** Match threshold (0-1, default 0.4) */
3928
+ match_threshold?: number;
3929
+ [key: string]: unknown;
3930
+ };
3931
+ [key: string]: unknown;
3932
+ };
3933
+ };
3934
+ type AiSearchChatCompletionsRequest = {
3935
+ messages: Array<{
3936
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3937
+ content: string | null;
3938
+ }>;
3939
+ model?: string;
3940
+ stream?: boolean;
3941
+ ai_search_options?: {
3942
+ retrieval?: {
3943
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3944
+ match_threshold?: number;
3945
+ max_num_results?: number;
3946
+ filters?: CompoundFilter | ComparisonFilter;
3947
+ context_expansion?: number;
3948
+ [key: string]: unknown;
3949
+ };
3950
+ query_rewrite?: {
3951
+ enabled?: boolean;
3952
+ model?: string;
3953
+ rewrite_prompt?: string;
3954
+ [key: string]: unknown;
3955
+ };
3956
+ reranking?: {
3957
+ enabled?: boolean;
3958
+ model?: "@cf/baai/bge-reranker-base" | "";
3959
+ match_threshold?: number;
3960
+ [key: string]: unknown;
3961
+ };
3962
+ [key: string]: unknown;
3963
+ };
3964
+ [key: string]: unknown;
3965
+ };
3966
+ // AI Search V2 Response Types
3967
+ type AiSearchSearchResponse = {
3968
+ search_query: string;
3969
+ chunks: Array<{
3970
+ id: string;
3971
+ type: string;
3972
+ /** Match score (0-1) */
3973
+ score: number;
3974
+ text: string;
3975
+ item: {
3976
+ timestamp?: number;
3977
+ key: string;
3978
+ metadata?: Record<string, unknown>;
3979
+ };
3980
+ scoring_details?: {
3981
+ /** Keyword match score (0-1) */
3982
+ keyword_score?: number;
3983
+ /** Vector similarity score (0-1) */
3984
+ vector_score?: number;
3985
+ };
3986
+ }>;
3987
+ };
3988
+ type AiSearchListResponse = Array<{
3989
+ id: string;
3990
+ internal_id?: string;
3991
+ account_id?: string;
3992
+ account_tag?: string;
3993
+ /** Whether the instance is enabled (default true) */
3994
+ enable?: boolean;
3995
+ type?: "r2" | "web-crawler";
3996
+ source?: string;
3997
+ [key: string]: unknown;
3998
+ }>;
3999
+ type AiSearchConfig = {
4000
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
4001
+ id: string;
4002
+ type: "r2" | "web-crawler";
4003
+ source: string;
4004
+ source_params?: object;
4005
+ /** Token ID (UUID format) */
4006
+ token_id?: string;
4007
+ ai_gateway_id?: string;
4008
+ /** Enable query rewriting (default false) */
4009
+ rewrite_query?: boolean;
4010
+ /** Enable reranking (default false) */
4011
+ reranking?: boolean;
4012
+ embedding_model?: string;
4013
+ ai_search_model?: string;
4014
+ };
4015
+ type AiSearchInstance = {
4016
+ id: string;
4017
+ enable?: boolean;
4018
+ type?: "r2" | "web-crawler";
4019
+ source?: string;
4020
+ [key: string]: unknown;
4021
+ };
4022
+ // AI Search Instance Service - Instance-level operations
4023
+ declare abstract class AiSearchInstanceService {
4024
+ /**
4025
+ * Search the AI Search instance for relevant chunks.
4026
+ * @param params Search request with messages and AI search options
4027
+ * @returns Search response with matching chunks
4028
+ */
4029
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4030
+ /**
4031
+ * Generate chat completions with AI Search context.
4032
+ * @param params Chat completions request with optional streaming
4033
+ * @returns Response object (if streaming) or chat completion result
4034
+ */
4035
+ chatCompletions(
4036
+ params: AiSearchChatCompletionsRequest,
4037
+ ): Promise<Response | object>;
4038
+ /**
4039
+ * Delete this AI Search instance.
4040
+ */
4041
+ delete(): Promise<void>;
4042
+ }
4043
+ // AI Search Account Service - Account-level operations
4044
+ declare abstract class AiSearchAccountService {
4045
+ /**
4046
+ * List all AI Search instances in the account.
4047
+ * @returns Array of AI Search instances
4048
+ */
4049
+ list(): Promise<AiSearchListResponse>;
4050
+ /**
4051
+ * Get an AI Search instance by ID.
4052
+ * @param name Instance ID
4053
+ * @returns Instance service for performing operations
4054
+ */
4055
+ get(name: string): AiSearchInstanceService;
4056
+ /**
4057
+ * Create a new AI Search instance.
4058
+ * @param config Instance configuration
4059
+ * @returns Instance service for performing operations
4060
+ */
4061
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4062
+ }
3885
4063
  type AiImageClassificationInput = {
3886
4064
  image: number[];
3887
4065
  };
@@ -9379,6 +9557,48 @@ type AiModelListType = Record<string, any>;
9379
9557
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9380
9558
  aiGatewayLogId: string | null;
9381
9559
  gateway(gatewayId: string): AiGateway;
9560
+ /**
9561
+ * Access the AI Search API for managing AI-powered search instances.
9562
+ *
9563
+ * This is the new API that replaces AutoRAG with better namespace separation:
9564
+ * - Account-level operations: `list()`, `create()`
9565
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9566
+ *
9567
+ * @example
9568
+ * ```typescript
9569
+ * // List all AI Search instances
9570
+ * const instances = await env.AI.aiSearch.list();
9571
+ *
9572
+ * // Search an instance
9573
+ * const results = await env.AI.aiSearch.get('my-search').search({
9574
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9575
+ * ai_search_options: {
9576
+ * retrieval: { max_num_results: 10 }
9577
+ * }
9578
+ * });
9579
+ *
9580
+ * // Generate chat completions with AI Search context
9581
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9582
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9583
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9584
+ * });
9585
+ * ```
9586
+ */
9587
+ aiSearch: AiSearchAccountService;
9588
+ /**
9589
+ * @deprecated AutoRAG has been replaced by AI Search.
9590
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9591
+ *
9592
+ * Migration guide:
9593
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9594
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9595
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9596
+ *
9597
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9598
+ *
9599
+ * @see AiSearchAccountService
9600
+ * @param autoragId Optional instance ID (omit for account-level operations)
9601
+ */
9382
9602
  autorag(autoragId: string): AutoRAG;
9383
9603
  run<
9384
9604
  Name extends keyof AiModelList,
@@ -9535,19 +9755,30 @@ declare abstract class AiGateway {
9535
9755
  ): Promise<Response>;
9536
9756
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9537
9757
  }
9758
+ /**
9759
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9760
+ * @see AiSearchInternalError
9761
+ */
9538
9762
  interface AutoRAGInternalError extends Error {}
9763
+ /**
9764
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9765
+ * @see AiSearchNotFoundError
9766
+ */
9539
9767
  interface AutoRAGNotFoundError extends Error {}
9768
+ /**
9769
+ * @deprecated This error type is no longer used in the AI Search API.
9770
+ */
9540
9771
  interface AutoRAGUnauthorizedError extends Error {}
9772
+ /**
9773
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9774
+ * @see AiSearchNameNotSetError
9775
+ */
9541
9776
  interface AutoRAGNameNotSetError extends Error {}
9542
- type ComparisonFilter = {
9543
- key: string;
9544
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9545
- value: string | number | boolean;
9546
- };
9547
- type CompoundFilter = {
9548
- type: "and" | "or";
9549
- filters: ComparisonFilter[];
9550
- };
9777
+ /**
9778
+ * @deprecated AutoRAG has been replaced by AI Search.
9779
+ * Use AiSearchSearchRequest with the new API instead.
9780
+ * @see AiSearchSearchRequest
9781
+ */
9551
9782
  type AutoRagSearchRequest = {
9552
9783
  query: string;
9553
9784
  filters?: CompoundFilter | ComparisonFilter;
@@ -9562,16 +9793,31 @@ type AutoRagSearchRequest = {
9562
9793
  };
9563
9794
  rewrite_query?: boolean;
9564
9795
  };
9796
+ /**
9797
+ * @deprecated AutoRAG has been replaced by AI Search.
9798
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9799
+ * @see AiSearchChatCompletionsRequest
9800
+ */
9565
9801
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9566
9802
  stream?: boolean;
9567
9803
  system_prompt?: string;
9568
9804
  };
9805
+ /**
9806
+ * @deprecated AutoRAG has been replaced by AI Search.
9807
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9808
+ * @see AiSearchChatCompletionsRequest
9809
+ */
9569
9810
  type AutoRagAiSearchRequestStreaming = Omit<
9570
9811
  AutoRagAiSearchRequest,
9571
9812
  "stream"
9572
9813
  > & {
9573
9814
  stream: true;
9574
9815
  };
9816
+ /**
9817
+ * @deprecated AutoRAG has been replaced by AI Search.
9818
+ * Use AiSearchSearchResponse with the new API instead.
9819
+ * @see AiSearchSearchResponse
9820
+ */
9575
9821
  type AutoRagSearchResponse = {
9576
9822
  object: "vector_store.search_results.page";
9577
9823
  search_query: string;
@@ -9588,6 +9834,11 @@ type AutoRagSearchResponse = {
9588
9834
  has_more: boolean;
9589
9835
  next_page: string | null;
9590
9836
  };
9837
+ /**
9838
+ * @deprecated AutoRAG has been replaced by AI Search.
9839
+ * Use AiSearchListResponse with the new API instead.
9840
+ * @see AiSearchListResponse
9841
+ */
9591
9842
  type AutoRagListResponse = {
9592
9843
  id: string;
9593
9844
  enable: boolean;
@@ -9597,14 +9848,51 @@ type AutoRagListResponse = {
9597
9848
  paused: boolean;
9598
9849
  status: string;
9599
9850
  }[];
9851
+ /**
9852
+ * @deprecated AutoRAG has been replaced by AI Search.
9853
+ * The new API returns different response formats for chat completions.
9854
+ */
9600
9855
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9601
9856
  response: string;
9602
9857
  };
9858
+ /**
9859
+ * @deprecated AutoRAG has been replaced by AI Search.
9860
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9861
+ *
9862
+ * Migration guide:
9863
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9864
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9865
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9866
+ *
9867
+ * @see AiSearchAccountService
9868
+ * @see AiSearchInstanceService
9869
+ */
9603
9870
  declare abstract class AutoRAG {
9871
+ /**
9872
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9873
+ * @see AiSearchAccountService.list
9874
+ */
9604
9875
  list(): Promise<AutoRagListResponse>;
9876
+ /**
9877
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9878
+ * Note: The new API uses a messages array instead of a query string.
9879
+ * @see AiSearchInstanceService.search
9880
+ */
9605
9881
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9882
+ /**
9883
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9884
+ * @see AiSearchInstanceService.chatCompletions
9885
+ */
9606
9886
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9887
+ /**
9888
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9889
+ * @see AiSearchInstanceService.chatCompletions
9890
+ */
9607
9891
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9892
+ /**
9893
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9894
+ * @see AiSearchInstanceService.chatCompletions
9895
+ */
9608
9896
  aiSearch(
9609
9897
  params: AutoRagAiSearchRequest,
9610
9898
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11090,8 +11378,14 @@ interface MediaTransformer {
11090
11378
  * @returns A generator for producing the transformed media output
11091
11379
  */
11092
11380
  transform(
11093
- transform: MediaTransformationInputOptions,
11381
+ transform?: MediaTransformationInputOptions,
11094
11382
  ): MediaTransformationGenerator;
11383
+ /**
11384
+ * Generates the final media output with specified options.
11385
+ * @param output - Configuration for the output format and parameters
11386
+ * @returns The final transformation result containing the transformed media
11387
+ */
11388
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11095
11389
  }
11096
11390
  /**
11097
11391
  * Generator for producing media transformation results.
@@ -11103,7 +11397,7 @@ interface MediaTransformationGenerator {
11103
11397
  * @param output - Configuration for the output format and parameters
11104
11398
  * @returns The final transformation result containing the transformed media
11105
11399
  */
11106
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11400
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11107
11401
  }
11108
11402
  /**
11109
11403
  * Result of a media transformation operation.
@@ -11112,19 +11406,19 @@ interface MediaTransformationGenerator {
11112
11406
  interface MediaTransformationResult {
11113
11407
  /**
11114
11408
  * Returns the transformed media as a readable stream of bytes.
11115
- * @returns A stream containing the transformed media data
11409
+ * @returns A promise containing a readable stream with the transformed media
11116
11410
  */
11117
- media(): ReadableStream<Uint8Array>;
11411
+ media(): Promise<ReadableStream<Uint8Array>>;
11118
11412
  /**
11119
11413
  * Returns the transformed media as an HTTP response object.
11120
- * @returns The transformed media as a Response, ready to store in cache or return to users
11414
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11121
11415
  */
11122
- response(): Response;
11416
+ response(): Promise<Response>;
11123
11417
  /**
11124
11418
  * Returns the MIME type of the transformed media.
11125
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11419
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11126
11420
  */
11127
- contentType(): string;
11421
+ contentType(): Promise<string>;
11128
11422
  }
11129
11423
  /**
11130
11424
  * Configuration options for transforming media input.