@cloudflare/workers-types 4.20260219.0 → 4.20260228.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.
@@ -3843,6 +3843,184 @@ declare abstract class Performance {
3843
3843
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3844
3844
  now(): number;
3845
3845
  }
3846
+ // AI Search V2 API Error Interfaces
3847
+ interface AiSearchInternalError extends Error {}
3848
+ interface AiSearchNotFoundError extends Error {}
3849
+ interface AiSearchNameNotSetError extends Error {}
3850
+ // Filter types (shared with AutoRAG for compatibility)
3851
+ type ComparisonFilter = {
3852
+ key: string;
3853
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3854
+ value: string | number | boolean;
3855
+ };
3856
+ type CompoundFilter = {
3857
+ type: "and" | "or";
3858
+ filters: ComparisonFilter[];
3859
+ };
3860
+ // AI Search V2 Request Types
3861
+ type AiSearchSearchRequest = {
3862
+ messages: Array<{
3863
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3864
+ content: string | null;
3865
+ }>;
3866
+ ai_search_options?: {
3867
+ retrieval?: {
3868
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3869
+ /** Match threshold (0-1, default 0.4) */
3870
+ match_threshold?: number;
3871
+ /** Maximum number of results (1-50, default 10) */
3872
+ max_num_results?: number;
3873
+ filters?: CompoundFilter | ComparisonFilter;
3874
+ /** Context expansion (0-3, default 0) */
3875
+ context_expansion?: number;
3876
+ [key: string]: unknown;
3877
+ };
3878
+ query_rewrite?: {
3879
+ enabled?: boolean;
3880
+ model?: string;
3881
+ rewrite_prompt?: string;
3882
+ [key: string]: unknown;
3883
+ };
3884
+ reranking?: {
3885
+ /** Enable reranking (default false) */
3886
+ enabled?: boolean;
3887
+ model?: "@cf/baai/bge-reranker-base" | "";
3888
+ /** Match threshold (0-1, default 0.4) */
3889
+ match_threshold?: number;
3890
+ [key: string]: unknown;
3891
+ };
3892
+ [key: string]: unknown;
3893
+ };
3894
+ };
3895
+ type AiSearchChatCompletionsRequest = {
3896
+ messages: Array<{
3897
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3898
+ content: string | null;
3899
+ }>;
3900
+ model?: string;
3901
+ stream?: boolean;
3902
+ ai_search_options?: {
3903
+ retrieval?: {
3904
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3905
+ match_threshold?: number;
3906
+ max_num_results?: number;
3907
+ filters?: CompoundFilter | ComparisonFilter;
3908
+ context_expansion?: number;
3909
+ [key: string]: unknown;
3910
+ };
3911
+ query_rewrite?: {
3912
+ enabled?: boolean;
3913
+ model?: string;
3914
+ rewrite_prompt?: string;
3915
+ [key: string]: unknown;
3916
+ };
3917
+ reranking?: {
3918
+ enabled?: boolean;
3919
+ model?: "@cf/baai/bge-reranker-base" | "";
3920
+ match_threshold?: number;
3921
+ [key: string]: unknown;
3922
+ };
3923
+ [key: string]: unknown;
3924
+ };
3925
+ [key: string]: unknown;
3926
+ };
3927
+ // AI Search V2 Response Types
3928
+ type AiSearchSearchResponse = {
3929
+ search_query: string;
3930
+ chunks: Array<{
3931
+ id: string;
3932
+ type: string;
3933
+ /** Match score (0-1) */
3934
+ score: number;
3935
+ text: string;
3936
+ item: {
3937
+ timestamp?: number;
3938
+ key: string;
3939
+ metadata?: Record<string, unknown>;
3940
+ };
3941
+ scoring_details?: {
3942
+ /** Keyword match score (0-1) */
3943
+ keyword_score?: number;
3944
+ /** Vector similarity score (0-1) */
3945
+ vector_score?: number;
3946
+ };
3947
+ }>;
3948
+ };
3949
+ type AiSearchListResponse = Array<{
3950
+ id: string;
3951
+ internal_id?: string;
3952
+ account_id?: string;
3953
+ account_tag?: string;
3954
+ /** Whether the instance is enabled (default true) */
3955
+ enable?: boolean;
3956
+ type?: "r2" | "web-crawler";
3957
+ source?: string;
3958
+ [key: string]: unknown;
3959
+ }>;
3960
+ type AiSearchConfig = {
3961
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3962
+ id: string;
3963
+ type: "r2" | "web-crawler";
3964
+ source: string;
3965
+ source_params?: object;
3966
+ /** Token ID (UUID format) */
3967
+ token_id?: string;
3968
+ ai_gateway_id?: string;
3969
+ /** Enable query rewriting (default false) */
3970
+ rewrite_query?: boolean;
3971
+ /** Enable reranking (default false) */
3972
+ reranking?: boolean;
3973
+ embedding_model?: string;
3974
+ ai_search_model?: string;
3975
+ };
3976
+ type AiSearchInstance = {
3977
+ id: string;
3978
+ enable?: boolean;
3979
+ type?: "r2" | "web-crawler";
3980
+ source?: string;
3981
+ [key: string]: unknown;
3982
+ };
3983
+ // AI Search Instance Service - Instance-level operations
3984
+ declare abstract class AiSearchInstanceService {
3985
+ /**
3986
+ * Search the AI Search instance for relevant chunks.
3987
+ * @param params Search request with messages and AI search options
3988
+ * @returns Search response with matching chunks
3989
+ */
3990
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3991
+ /**
3992
+ * Generate chat completions with AI Search context.
3993
+ * @param params Chat completions request with optional streaming
3994
+ * @returns Response object (if streaming) or chat completion result
3995
+ */
3996
+ chatCompletions(
3997
+ params: AiSearchChatCompletionsRequest,
3998
+ ): Promise<Response | object>;
3999
+ /**
4000
+ * Delete this AI Search instance.
4001
+ */
4002
+ delete(): Promise<void>;
4003
+ }
4004
+ // AI Search Account Service - Account-level operations
4005
+ declare abstract class AiSearchAccountService {
4006
+ /**
4007
+ * List all AI Search instances in the account.
4008
+ * @returns Array of AI Search instances
4009
+ */
4010
+ list(): Promise<AiSearchListResponse>;
4011
+ /**
4012
+ * Get an AI Search instance by ID.
4013
+ * @param name Instance ID
4014
+ * @returns Instance service for performing operations
4015
+ */
4016
+ get(name: string): AiSearchInstanceService;
4017
+ /**
4018
+ * Create a new AI Search instance.
4019
+ * @param config Instance configuration
4020
+ * @returns Instance service for performing operations
4021
+ */
4022
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4023
+ }
3846
4024
  type AiImageClassificationInput = {
3847
4025
  image: number[];
3848
4026
  };
@@ -9340,6 +9518,48 @@ type AiModelListType = Record<string, any>;
9340
9518
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9341
9519
  aiGatewayLogId: string | null;
9342
9520
  gateway(gatewayId: string): AiGateway;
9521
+ /**
9522
+ * Access the AI Search API for managing AI-powered search instances.
9523
+ *
9524
+ * This is the new API that replaces AutoRAG with better namespace separation:
9525
+ * - Account-level operations: `list()`, `create()`
9526
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9527
+ *
9528
+ * @example
9529
+ * ```typescript
9530
+ * // List all AI Search instances
9531
+ * const instances = await env.AI.aiSearch.list();
9532
+ *
9533
+ * // Search an instance
9534
+ * const results = await env.AI.aiSearch.get('my-search').search({
9535
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9536
+ * ai_search_options: {
9537
+ * retrieval: { max_num_results: 10 }
9538
+ * }
9539
+ * });
9540
+ *
9541
+ * // Generate chat completions with AI Search context
9542
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9543
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9544
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9545
+ * });
9546
+ * ```
9547
+ */
9548
+ aiSearch: AiSearchAccountService;
9549
+ /**
9550
+ * @deprecated AutoRAG has been replaced by AI Search.
9551
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9552
+ *
9553
+ * Migration guide:
9554
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9555
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9556
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9557
+ *
9558
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9559
+ *
9560
+ * @see AiSearchAccountService
9561
+ * @param autoragId Optional instance ID (omit for account-level operations)
9562
+ */
9343
9563
  autorag(autoragId: string): AutoRAG;
9344
9564
  run<
9345
9565
  Name extends keyof AiModelList,
@@ -9496,19 +9716,30 @@ declare abstract class AiGateway {
9496
9716
  ): Promise<Response>;
9497
9717
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9498
9718
  }
9719
+ /**
9720
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9721
+ * @see AiSearchInternalError
9722
+ */
9499
9723
  interface AutoRAGInternalError extends Error {}
9724
+ /**
9725
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9726
+ * @see AiSearchNotFoundError
9727
+ */
9500
9728
  interface AutoRAGNotFoundError extends Error {}
9729
+ /**
9730
+ * @deprecated This error type is no longer used in the AI Search API.
9731
+ */
9501
9732
  interface AutoRAGUnauthorizedError extends Error {}
9733
+ /**
9734
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9735
+ * @see AiSearchNameNotSetError
9736
+ */
9502
9737
  interface AutoRAGNameNotSetError extends Error {}
9503
- type ComparisonFilter = {
9504
- key: string;
9505
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9506
- value: string | number | boolean;
9507
- };
9508
- type CompoundFilter = {
9509
- type: "and" | "or";
9510
- filters: ComparisonFilter[];
9511
- };
9738
+ /**
9739
+ * @deprecated AutoRAG has been replaced by AI Search.
9740
+ * Use AiSearchSearchRequest with the new API instead.
9741
+ * @see AiSearchSearchRequest
9742
+ */
9512
9743
  type AutoRagSearchRequest = {
9513
9744
  query: string;
9514
9745
  filters?: CompoundFilter | ComparisonFilter;
@@ -9523,16 +9754,31 @@ type AutoRagSearchRequest = {
9523
9754
  };
9524
9755
  rewrite_query?: boolean;
9525
9756
  };
9757
+ /**
9758
+ * @deprecated AutoRAG has been replaced by AI Search.
9759
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9760
+ * @see AiSearchChatCompletionsRequest
9761
+ */
9526
9762
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9527
9763
  stream?: boolean;
9528
9764
  system_prompt?: string;
9529
9765
  };
9766
+ /**
9767
+ * @deprecated AutoRAG has been replaced by AI Search.
9768
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9769
+ * @see AiSearchChatCompletionsRequest
9770
+ */
9530
9771
  type AutoRagAiSearchRequestStreaming = Omit<
9531
9772
  AutoRagAiSearchRequest,
9532
9773
  "stream"
9533
9774
  > & {
9534
9775
  stream: true;
9535
9776
  };
9777
+ /**
9778
+ * @deprecated AutoRAG has been replaced by AI Search.
9779
+ * Use AiSearchSearchResponse with the new API instead.
9780
+ * @see AiSearchSearchResponse
9781
+ */
9536
9782
  type AutoRagSearchResponse = {
9537
9783
  object: "vector_store.search_results.page";
9538
9784
  search_query: string;
@@ -9549,6 +9795,11 @@ type AutoRagSearchResponse = {
9549
9795
  has_more: boolean;
9550
9796
  next_page: string | null;
9551
9797
  };
9798
+ /**
9799
+ * @deprecated AutoRAG has been replaced by AI Search.
9800
+ * Use AiSearchListResponse with the new API instead.
9801
+ * @see AiSearchListResponse
9802
+ */
9552
9803
  type AutoRagListResponse = {
9553
9804
  id: string;
9554
9805
  enable: boolean;
@@ -9558,14 +9809,51 @@ type AutoRagListResponse = {
9558
9809
  paused: boolean;
9559
9810
  status: string;
9560
9811
  }[];
9812
+ /**
9813
+ * @deprecated AutoRAG has been replaced by AI Search.
9814
+ * The new API returns different response formats for chat completions.
9815
+ */
9561
9816
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9562
9817
  response: string;
9563
9818
  };
9819
+ /**
9820
+ * @deprecated AutoRAG has been replaced by AI Search.
9821
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9822
+ *
9823
+ * Migration guide:
9824
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9825
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9826
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9827
+ *
9828
+ * @see AiSearchAccountService
9829
+ * @see AiSearchInstanceService
9830
+ */
9564
9831
  declare abstract class AutoRAG {
9832
+ /**
9833
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9834
+ * @see AiSearchAccountService.list
9835
+ */
9565
9836
  list(): Promise<AutoRagListResponse>;
9837
+ /**
9838
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9839
+ * Note: The new API uses a messages array instead of a query string.
9840
+ * @see AiSearchInstanceService.search
9841
+ */
9566
9842
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9843
+ /**
9844
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9845
+ * @see AiSearchInstanceService.chatCompletions
9846
+ */
9567
9847
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9848
+ /**
9849
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9850
+ * @see AiSearchInstanceService.chatCompletions
9851
+ */
9568
9852
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9853
+ /**
9854
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9855
+ * @see AiSearchInstanceService.chatCompletions
9856
+ */
9569
9857
  aiSearch(
9570
9858
  params: AutoRagAiSearchRequest,
9571
9859
  ): Promise<AutoRagAiSearchResponse | Response>;