@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.
@@ -3742,6 +3742,184 @@ declare abstract class Performance {
3742
3742
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3743
3743
  now(): number;
3744
3744
  }
3745
+ // AI Search V2 API Error Interfaces
3746
+ interface AiSearchInternalError extends Error {}
3747
+ interface AiSearchNotFoundError extends Error {}
3748
+ interface AiSearchNameNotSetError extends Error {}
3749
+ // Filter types (shared with AutoRAG for compatibility)
3750
+ type ComparisonFilter = {
3751
+ key: string;
3752
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3753
+ value: string | number | boolean;
3754
+ };
3755
+ type CompoundFilter = {
3756
+ type: "and" | "or";
3757
+ filters: ComparisonFilter[];
3758
+ };
3759
+ // AI Search V2 Request Types
3760
+ type AiSearchSearchRequest = {
3761
+ messages: Array<{
3762
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3763
+ content: string | null;
3764
+ }>;
3765
+ ai_search_options?: {
3766
+ retrieval?: {
3767
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3768
+ /** Match threshold (0-1, default 0.4) */
3769
+ match_threshold?: number;
3770
+ /** Maximum number of results (1-50, default 10) */
3771
+ max_num_results?: number;
3772
+ filters?: CompoundFilter | ComparisonFilter;
3773
+ /** Context expansion (0-3, default 0) */
3774
+ context_expansion?: number;
3775
+ [key: string]: unknown;
3776
+ };
3777
+ query_rewrite?: {
3778
+ enabled?: boolean;
3779
+ model?: string;
3780
+ rewrite_prompt?: string;
3781
+ [key: string]: unknown;
3782
+ };
3783
+ reranking?: {
3784
+ /** Enable reranking (default false) */
3785
+ enabled?: boolean;
3786
+ model?: "@cf/baai/bge-reranker-base" | "";
3787
+ /** Match threshold (0-1, default 0.4) */
3788
+ match_threshold?: number;
3789
+ [key: string]: unknown;
3790
+ };
3791
+ [key: string]: unknown;
3792
+ };
3793
+ };
3794
+ type AiSearchChatCompletionsRequest = {
3795
+ messages: Array<{
3796
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3797
+ content: string | null;
3798
+ }>;
3799
+ model?: string;
3800
+ stream?: boolean;
3801
+ ai_search_options?: {
3802
+ retrieval?: {
3803
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3804
+ match_threshold?: number;
3805
+ max_num_results?: number;
3806
+ filters?: CompoundFilter | ComparisonFilter;
3807
+ context_expansion?: number;
3808
+ [key: string]: unknown;
3809
+ };
3810
+ query_rewrite?: {
3811
+ enabled?: boolean;
3812
+ model?: string;
3813
+ rewrite_prompt?: string;
3814
+ [key: string]: unknown;
3815
+ };
3816
+ reranking?: {
3817
+ enabled?: boolean;
3818
+ model?: "@cf/baai/bge-reranker-base" | "";
3819
+ match_threshold?: number;
3820
+ [key: string]: unknown;
3821
+ };
3822
+ [key: string]: unknown;
3823
+ };
3824
+ [key: string]: unknown;
3825
+ };
3826
+ // AI Search V2 Response Types
3827
+ type AiSearchSearchResponse = {
3828
+ search_query: string;
3829
+ chunks: Array<{
3830
+ id: string;
3831
+ type: string;
3832
+ /** Match score (0-1) */
3833
+ score: number;
3834
+ text: string;
3835
+ item: {
3836
+ timestamp?: number;
3837
+ key: string;
3838
+ metadata?: Record<string, unknown>;
3839
+ };
3840
+ scoring_details?: {
3841
+ /** Keyword match score (0-1) */
3842
+ keyword_score?: number;
3843
+ /** Vector similarity score (0-1) */
3844
+ vector_score?: number;
3845
+ };
3846
+ }>;
3847
+ };
3848
+ type AiSearchListResponse = Array<{
3849
+ id: string;
3850
+ internal_id?: string;
3851
+ account_id?: string;
3852
+ account_tag?: string;
3853
+ /** Whether the instance is enabled (default true) */
3854
+ enable?: boolean;
3855
+ type?: "r2" | "web-crawler";
3856
+ source?: string;
3857
+ [key: string]: unknown;
3858
+ }>;
3859
+ type AiSearchConfig = {
3860
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3861
+ id: string;
3862
+ type: "r2" | "web-crawler";
3863
+ source: string;
3864
+ source_params?: object;
3865
+ /** Token ID (UUID format) */
3866
+ token_id?: string;
3867
+ ai_gateway_id?: string;
3868
+ /** Enable query rewriting (default false) */
3869
+ rewrite_query?: boolean;
3870
+ /** Enable reranking (default false) */
3871
+ reranking?: boolean;
3872
+ embedding_model?: string;
3873
+ ai_search_model?: string;
3874
+ };
3875
+ type AiSearchInstance = {
3876
+ id: string;
3877
+ enable?: boolean;
3878
+ type?: "r2" | "web-crawler";
3879
+ source?: string;
3880
+ [key: string]: unknown;
3881
+ };
3882
+ // AI Search Instance Service - Instance-level operations
3883
+ declare abstract class AiSearchInstanceService {
3884
+ /**
3885
+ * Search the AI Search instance for relevant chunks.
3886
+ * @param params Search request with messages and AI search options
3887
+ * @returns Search response with matching chunks
3888
+ */
3889
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3890
+ /**
3891
+ * Generate chat completions with AI Search context.
3892
+ * @param params Chat completions request with optional streaming
3893
+ * @returns Response object (if streaming) or chat completion result
3894
+ */
3895
+ chatCompletions(
3896
+ params: AiSearchChatCompletionsRequest,
3897
+ ): Promise<Response | object>;
3898
+ /**
3899
+ * Delete this AI Search instance.
3900
+ */
3901
+ delete(): Promise<void>;
3902
+ }
3903
+ // AI Search Account Service - Account-level operations
3904
+ declare abstract class AiSearchAccountService {
3905
+ /**
3906
+ * List all AI Search instances in the account.
3907
+ * @returns Array of AI Search instances
3908
+ */
3909
+ list(): Promise<AiSearchListResponse>;
3910
+ /**
3911
+ * Get an AI Search instance by ID.
3912
+ * @param name Instance ID
3913
+ * @returns Instance service for performing operations
3914
+ */
3915
+ get(name: string): AiSearchInstanceService;
3916
+ /**
3917
+ * Create a new AI Search instance.
3918
+ * @param config Instance configuration
3919
+ * @returns Instance service for performing operations
3920
+ */
3921
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3922
+ }
3745
3923
  type AiImageClassificationInput = {
3746
3924
  image: number[];
3747
3925
  };
@@ -9239,6 +9417,48 @@ type AiModelListType = Record<string, any>;
9239
9417
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9240
9418
  aiGatewayLogId: string | null;
9241
9419
  gateway(gatewayId: string): AiGateway;
9420
+ /**
9421
+ * Access the AI Search API for managing AI-powered search instances.
9422
+ *
9423
+ * This is the new API that replaces AutoRAG with better namespace separation:
9424
+ * - Account-level operations: `list()`, `create()`
9425
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9426
+ *
9427
+ * @example
9428
+ * ```typescript
9429
+ * // List all AI Search instances
9430
+ * const instances = await env.AI.aiSearch.list();
9431
+ *
9432
+ * // Search an instance
9433
+ * const results = await env.AI.aiSearch.get('my-search').search({
9434
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9435
+ * ai_search_options: {
9436
+ * retrieval: { max_num_results: 10 }
9437
+ * }
9438
+ * });
9439
+ *
9440
+ * // Generate chat completions with AI Search context
9441
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9442
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9443
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9444
+ * });
9445
+ * ```
9446
+ */
9447
+ aiSearch: AiSearchAccountService;
9448
+ /**
9449
+ * @deprecated AutoRAG has been replaced by AI Search.
9450
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9451
+ *
9452
+ * Migration guide:
9453
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9454
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9455
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9456
+ *
9457
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9458
+ *
9459
+ * @see AiSearchAccountService
9460
+ * @param autoragId Optional instance ID (omit for account-level operations)
9461
+ */
9242
9462
  autorag(autoragId: string): AutoRAG;
9243
9463
  run<
9244
9464
  Name extends keyof AiModelList,
@@ -9395,19 +9615,30 @@ declare abstract class AiGateway {
9395
9615
  ): Promise<Response>;
9396
9616
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9397
9617
  }
9618
+ /**
9619
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9620
+ * @see AiSearchInternalError
9621
+ */
9398
9622
  interface AutoRAGInternalError extends Error {}
9623
+ /**
9624
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9625
+ * @see AiSearchNotFoundError
9626
+ */
9399
9627
  interface AutoRAGNotFoundError extends Error {}
9628
+ /**
9629
+ * @deprecated This error type is no longer used in the AI Search API.
9630
+ */
9400
9631
  interface AutoRAGUnauthorizedError extends Error {}
9632
+ /**
9633
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9634
+ * @see AiSearchNameNotSetError
9635
+ */
9401
9636
  interface AutoRAGNameNotSetError extends Error {}
9402
- type ComparisonFilter = {
9403
- key: string;
9404
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9405
- value: string | number | boolean;
9406
- };
9407
- type CompoundFilter = {
9408
- type: "and" | "or";
9409
- filters: ComparisonFilter[];
9410
- };
9637
+ /**
9638
+ * @deprecated AutoRAG has been replaced by AI Search.
9639
+ * Use AiSearchSearchRequest with the new API instead.
9640
+ * @see AiSearchSearchRequest
9641
+ */
9411
9642
  type AutoRagSearchRequest = {
9412
9643
  query: string;
9413
9644
  filters?: CompoundFilter | ComparisonFilter;
@@ -9422,16 +9653,31 @@ type AutoRagSearchRequest = {
9422
9653
  };
9423
9654
  rewrite_query?: boolean;
9424
9655
  };
9656
+ /**
9657
+ * @deprecated AutoRAG has been replaced by AI Search.
9658
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9659
+ * @see AiSearchChatCompletionsRequest
9660
+ */
9425
9661
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9426
9662
  stream?: boolean;
9427
9663
  system_prompt?: string;
9428
9664
  };
9665
+ /**
9666
+ * @deprecated AutoRAG has been replaced by AI Search.
9667
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9668
+ * @see AiSearchChatCompletionsRequest
9669
+ */
9429
9670
  type AutoRagAiSearchRequestStreaming = Omit<
9430
9671
  AutoRagAiSearchRequest,
9431
9672
  "stream"
9432
9673
  > & {
9433
9674
  stream: true;
9434
9675
  };
9676
+ /**
9677
+ * @deprecated AutoRAG has been replaced by AI Search.
9678
+ * Use AiSearchSearchResponse with the new API instead.
9679
+ * @see AiSearchSearchResponse
9680
+ */
9435
9681
  type AutoRagSearchResponse = {
9436
9682
  object: "vector_store.search_results.page";
9437
9683
  search_query: string;
@@ -9448,6 +9694,11 @@ type AutoRagSearchResponse = {
9448
9694
  has_more: boolean;
9449
9695
  next_page: string | null;
9450
9696
  };
9697
+ /**
9698
+ * @deprecated AutoRAG has been replaced by AI Search.
9699
+ * Use AiSearchListResponse with the new API instead.
9700
+ * @see AiSearchListResponse
9701
+ */
9451
9702
  type AutoRagListResponse = {
9452
9703
  id: string;
9453
9704
  enable: boolean;
@@ -9457,14 +9708,51 @@ type AutoRagListResponse = {
9457
9708
  paused: boolean;
9458
9709
  status: string;
9459
9710
  }[];
9711
+ /**
9712
+ * @deprecated AutoRAG has been replaced by AI Search.
9713
+ * The new API returns different response formats for chat completions.
9714
+ */
9460
9715
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9461
9716
  response: string;
9462
9717
  };
9718
+ /**
9719
+ * @deprecated AutoRAG has been replaced by AI Search.
9720
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9721
+ *
9722
+ * Migration guide:
9723
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9724
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9725
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9726
+ *
9727
+ * @see AiSearchAccountService
9728
+ * @see AiSearchInstanceService
9729
+ */
9463
9730
  declare abstract class AutoRAG {
9731
+ /**
9732
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9733
+ * @see AiSearchAccountService.list
9734
+ */
9464
9735
  list(): Promise<AutoRagListResponse>;
9736
+ /**
9737
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9738
+ * Note: The new API uses a messages array instead of a query string.
9739
+ * @see AiSearchInstanceService.search
9740
+ */
9465
9741
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9742
+ /**
9743
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9744
+ * @see AiSearchInstanceService.chatCompletions
9745
+ */
9466
9746
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9747
+ /**
9748
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9749
+ * @see AiSearchInstanceService.chatCompletions
9750
+ */
9467
9751
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9752
+ /**
9753
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9754
+ * @see AiSearchInstanceService.chatCompletions
9755
+ */
9468
9756
  aiSearch(
9469
9757
  params: AutoRagAiSearchRequest,
9470
9758
  ): Promise<AutoRagAiSearchResponse | Response>;