@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.
@@ -3809,6 +3809,184 @@ declare abstract class Performance {
3809
3809
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3810
3810
  now(): number;
3811
3811
  }
3812
+ // AI Search V2 API Error Interfaces
3813
+ interface AiSearchInternalError extends Error {}
3814
+ interface AiSearchNotFoundError extends Error {}
3815
+ interface AiSearchNameNotSetError extends Error {}
3816
+ // Filter types (shared with AutoRAG for compatibility)
3817
+ type ComparisonFilter = {
3818
+ key: string;
3819
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3820
+ value: string | number | boolean;
3821
+ };
3822
+ type CompoundFilter = {
3823
+ type: "and" | "or";
3824
+ filters: ComparisonFilter[];
3825
+ };
3826
+ // AI Search V2 Request Types
3827
+ type AiSearchSearchRequest = {
3828
+ messages: Array<{
3829
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3830
+ content: string | null;
3831
+ }>;
3832
+ ai_search_options?: {
3833
+ retrieval?: {
3834
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3835
+ /** Match threshold (0-1, default 0.4) */
3836
+ match_threshold?: number;
3837
+ /** Maximum number of results (1-50, default 10) */
3838
+ max_num_results?: number;
3839
+ filters?: CompoundFilter | ComparisonFilter;
3840
+ /** Context expansion (0-3, default 0) */
3841
+ context_expansion?: number;
3842
+ [key: string]: unknown;
3843
+ };
3844
+ query_rewrite?: {
3845
+ enabled?: boolean;
3846
+ model?: string;
3847
+ rewrite_prompt?: string;
3848
+ [key: string]: unknown;
3849
+ };
3850
+ reranking?: {
3851
+ /** Enable reranking (default false) */
3852
+ enabled?: boolean;
3853
+ model?: "@cf/baai/bge-reranker-base" | "";
3854
+ /** Match threshold (0-1, default 0.4) */
3855
+ match_threshold?: number;
3856
+ [key: string]: unknown;
3857
+ };
3858
+ [key: string]: unknown;
3859
+ };
3860
+ };
3861
+ type AiSearchChatCompletionsRequest = {
3862
+ messages: Array<{
3863
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3864
+ content: string | null;
3865
+ }>;
3866
+ model?: string;
3867
+ stream?: boolean;
3868
+ ai_search_options?: {
3869
+ retrieval?: {
3870
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3871
+ match_threshold?: number;
3872
+ max_num_results?: number;
3873
+ filters?: CompoundFilter | ComparisonFilter;
3874
+ context_expansion?: number;
3875
+ [key: string]: unknown;
3876
+ };
3877
+ query_rewrite?: {
3878
+ enabled?: boolean;
3879
+ model?: string;
3880
+ rewrite_prompt?: string;
3881
+ [key: string]: unknown;
3882
+ };
3883
+ reranking?: {
3884
+ enabled?: boolean;
3885
+ model?: "@cf/baai/bge-reranker-base" | "";
3886
+ match_threshold?: number;
3887
+ [key: string]: unknown;
3888
+ };
3889
+ [key: string]: unknown;
3890
+ };
3891
+ [key: string]: unknown;
3892
+ };
3893
+ // AI Search V2 Response Types
3894
+ type AiSearchSearchResponse = {
3895
+ search_query: string;
3896
+ chunks: Array<{
3897
+ id: string;
3898
+ type: string;
3899
+ /** Match score (0-1) */
3900
+ score: number;
3901
+ text: string;
3902
+ item: {
3903
+ timestamp?: number;
3904
+ key: string;
3905
+ metadata?: Record<string, unknown>;
3906
+ };
3907
+ scoring_details?: {
3908
+ /** Keyword match score (0-1) */
3909
+ keyword_score?: number;
3910
+ /** Vector similarity score (0-1) */
3911
+ vector_score?: number;
3912
+ };
3913
+ }>;
3914
+ };
3915
+ type AiSearchListResponse = Array<{
3916
+ id: string;
3917
+ internal_id?: string;
3918
+ account_id?: string;
3919
+ account_tag?: string;
3920
+ /** Whether the instance is enabled (default true) */
3921
+ enable?: boolean;
3922
+ type?: "r2" | "web-crawler";
3923
+ source?: string;
3924
+ [key: string]: unknown;
3925
+ }>;
3926
+ type AiSearchConfig = {
3927
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3928
+ id: string;
3929
+ type: "r2" | "web-crawler";
3930
+ source: string;
3931
+ source_params?: object;
3932
+ /** Token ID (UUID format) */
3933
+ token_id?: string;
3934
+ ai_gateway_id?: string;
3935
+ /** Enable query rewriting (default false) */
3936
+ rewrite_query?: boolean;
3937
+ /** Enable reranking (default false) */
3938
+ reranking?: boolean;
3939
+ embedding_model?: string;
3940
+ ai_search_model?: string;
3941
+ };
3942
+ type AiSearchInstance = {
3943
+ id: string;
3944
+ enable?: boolean;
3945
+ type?: "r2" | "web-crawler";
3946
+ source?: string;
3947
+ [key: string]: unknown;
3948
+ };
3949
+ // AI Search Instance Service - Instance-level operations
3950
+ declare abstract class AiSearchInstanceService {
3951
+ /**
3952
+ * Search the AI Search instance for relevant chunks.
3953
+ * @param params Search request with messages and AI search options
3954
+ * @returns Search response with matching chunks
3955
+ */
3956
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3957
+ /**
3958
+ * Generate chat completions with AI Search context.
3959
+ * @param params Chat completions request with optional streaming
3960
+ * @returns Response object (if streaming) or chat completion result
3961
+ */
3962
+ chatCompletions(
3963
+ params: AiSearchChatCompletionsRequest,
3964
+ ): Promise<Response | object>;
3965
+ /**
3966
+ * Delete this AI Search instance.
3967
+ */
3968
+ delete(): Promise<void>;
3969
+ }
3970
+ // AI Search Account Service - Account-level operations
3971
+ declare abstract class AiSearchAccountService {
3972
+ /**
3973
+ * List all AI Search instances in the account.
3974
+ * @returns Array of AI Search instances
3975
+ */
3976
+ list(): Promise<AiSearchListResponse>;
3977
+ /**
3978
+ * Get an AI Search instance by ID.
3979
+ * @param name Instance ID
3980
+ * @returns Instance service for performing operations
3981
+ */
3982
+ get(name: string): AiSearchInstanceService;
3983
+ /**
3984
+ * Create a new AI Search instance.
3985
+ * @param config Instance configuration
3986
+ * @returns Instance service for performing operations
3987
+ */
3988
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3989
+ }
3812
3990
  type AiImageClassificationInput = {
3813
3991
  image: number[];
3814
3992
  };
@@ -9306,6 +9484,48 @@ type AiModelListType = Record<string, any>;
9306
9484
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9307
9485
  aiGatewayLogId: string | null;
9308
9486
  gateway(gatewayId: string): AiGateway;
9487
+ /**
9488
+ * Access the AI Search API for managing AI-powered search instances.
9489
+ *
9490
+ * This is the new API that replaces AutoRAG with better namespace separation:
9491
+ * - Account-level operations: `list()`, `create()`
9492
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9493
+ *
9494
+ * @example
9495
+ * ```typescript
9496
+ * // List all AI Search instances
9497
+ * const instances = await env.AI.aiSearch.list();
9498
+ *
9499
+ * // Search an instance
9500
+ * const results = await env.AI.aiSearch.get('my-search').search({
9501
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9502
+ * ai_search_options: {
9503
+ * retrieval: { max_num_results: 10 }
9504
+ * }
9505
+ * });
9506
+ *
9507
+ * // Generate chat completions with AI Search context
9508
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9509
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9510
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9511
+ * });
9512
+ * ```
9513
+ */
9514
+ aiSearch: AiSearchAccountService;
9515
+ /**
9516
+ * @deprecated AutoRAG has been replaced by AI Search.
9517
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9518
+ *
9519
+ * Migration guide:
9520
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9521
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9522
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9523
+ *
9524
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9525
+ *
9526
+ * @see AiSearchAccountService
9527
+ * @param autoragId Optional instance ID (omit for account-level operations)
9528
+ */
9309
9529
  autorag(autoragId: string): AutoRAG;
9310
9530
  run<
9311
9531
  Name extends keyof AiModelList,
@@ -9462,19 +9682,30 @@ declare abstract class AiGateway {
9462
9682
  ): Promise<Response>;
9463
9683
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9464
9684
  }
9685
+ /**
9686
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9687
+ * @see AiSearchInternalError
9688
+ */
9465
9689
  interface AutoRAGInternalError extends Error {}
9690
+ /**
9691
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9692
+ * @see AiSearchNotFoundError
9693
+ */
9466
9694
  interface AutoRAGNotFoundError extends Error {}
9695
+ /**
9696
+ * @deprecated This error type is no longer used in the AI Search API.
9697
+ */
9467
9698
  interface AutoRAGUnauthorizedError extends Error {}
9699
+ /**
9700
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9701
+ * @see AiSearchNameNotSetError
9702
+ */
9468
9703
  interface AutoRAGNameNotSetError extends Error {}
9469
- type ComparisonFilter = {
9470
- key: string;
9471
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9472
- value: string | number | boolean;
9473
- };
9474
- type CompoundFilter = {
9475
- type: "and" | "or";
9476
- filters: ComparisonFilter[];
9477
- };
9704
+ /**
9705
+ * @deprecated AutoRAG has been replaced by AI Search.
9706
+ * Use AiSearchSearchRequest with the new API instead.
9707
+ * @see AiSearchSearchRequest
9708
+ */
9478
9709
  type AutoRagSearchRequest = {
9479
9710
  query: string;
9480
9711
  filters?: CompoundFilter | ComparisonFilter;
@@ -9489,16 +9720,31 @@ type AutoRagSearchRequest = {
9489
9720
  };
9490
9721
  rewrite_query?: boolean;
9491
9722
  };
9723
+ /**
9724
+ * @deprecated AutoRAG has been replaced by AI Search.
9725
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9726
+ * @see AiSearchChatCompletionsRequest
9727
+ */
9492
9728
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9493
9729
  stream?: boolean;
9494
9730
  system_prompt?: string;
9495
9731
  };
9732
+ /**
9733
+ * @deprecated AutoRAG has been replaced by AI Search.
9734
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9735
+ * @see AiSearchChatCompletionsRequest
9736
+ */
9496
9737
  type AutoRagAiSearchRequestStreaming = Omit<
9497
9738
  AutoRagAiSearchRequest,
9498
9739
  "stream"
9499
9740
  > & {
9500
9741
  stream: true;
9501
9742
  };
9743
+ /**
9744
+ * @deprecated AutoRAG has been replaced by AI Search.
9745
+ * Use AiSearchSearchResponse with the new API instead.
9746
+ * @see AiSearchSearchResponse
9747
+ */
9502
9748
  type AutoRagSearchResponse = {
9503
9749
  object: "vector_store.search_results.page";
9504
9750
  search_query: string;
@@ -9515,6 +9761,11 @@ type AutoRagSearchResponse = {
9515
9761
  has_more: boolean;
9516
9762
  next_page: string | null;
9517
9763
  };
9764
+ /**
9765
+ * @deprecated AutoRAG has been replaced by AI Search.
9766
+ * Use AiSearchListResponse with the new API instead.
9767
+ * @see AiSearchListResponse
9768
+ */
9518
9769
  type AutoRagListResponse = {
9519
9770
  id: string;
9520
9771
  enable: boolean;
@@ -9524,14 +9775,51 @@ type AutoRagListResponse = {
9524
9775
  paused: boolean;
9525
9776
  status: string;
9526
9777
  }[];
9778
+ /**
9779
+ * @deprecated AutoRAG has been replaced by AI Search.
9780
+ * The new API returns different response formats for chat completions.
9781
+ */
9527
9782
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9528
9783
  response: string;
9529
9784
  };
9785
+ /**
9786
+ * @deprecated AutoRAG has been replaced by AI Search.
9787
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9788
+ *
9789
+ * Migration guide:
9790
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9791
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9792
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9793
+ *
9794
+ * @see AiSearchAccountService
9795
+ * @see AiSearchInstanceService
9796
+ */
9530
9797
  declare abstract class AutoRAG {
9798
+ /**
9799
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9800
+ * @see AiSearchAccountService.list
9801
+ */
9531
9802
  list(): Promise<AutoRagListResponse>;
9803
+ /**
9804
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9805
+ * Note: The new API uses a messages array instead of a query string.
9806
+ * @see AiSearchInstanceService.search
9807
+ */
9532
9808
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9809
+ /**
9810
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9811
+ * @see AiSearchInstanceService.chatCompletions
9812
+ */
9533
9813
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9814
+ /**
9815
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9816
+ * @see AiSearchInstanceService.chatCompletions
9817
+ */
9534
9818
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9819
+ /**
9820
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9821
+ * @see AiSearchInstanceService.chatCompletions
9822
+ */
9535
9823
  aiSearch(
9536
9824
  params: AutoRagAiSearchRequest,
9537
9825
  ): Promise<AutoRagAiSearchResponse | Response>;