@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.
@@ -3849,6 +3849,184 @@ declare abstract class Performance {
3849
3849
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3850
3850
  now(): number;
3851
3851
  }
3852
+ // AI Search V2 API Error Interfaces
3853
+ interface AiSearchInternalError extends Error {}
3854
+ interface AiSearchNotFoundError extends Error {}
3855
+ interface AiSearchNameNotSetError extends Error {}
3856
+ // Filter types (shared with AutoRAG for compatibility)
3857
+ type ComparisonFilter = {
3858
+ key: string;
3859
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3860
+ value: string | number | boolean;
3861
+ };
3862
+ type CompoundFilter = {
3863
+ type: "and" | "or";
3864
+ filters: ComparisonFilter[];
3865
+ };
3866
+ // AI Search V2 Request Types
3867
+ type AiSearchSearchRequest = {
3868
+ messages: Array<{
3869
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3870
+ content: string | null;
3871
+ }>;
3872
+ ai_search_options?: {
3873
+ retrieval?: {
3874
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3875
+ /** Match threshold (0-1, default 0.4) */
3876
+ match_threshold?: number;
3877
+ /** Maximum number of results (1-50, default 10) */
3878
+ max_num_results?: number;
3879
+ filters?: CompoundFilter | ComparisonFilter;
3880
+ /** Context expansion (0-3, default 0) */
3881
+ context_expansion?: number;
3882
+ [key: string]: unknown;
3883
+ };
3884
+ query_rewrite?: {
3885
+ enabled?: boolean;
3886
+ model?: string;
3887
+ rewrite_prompt?: string;
3888
+ [key: string]: unknown;
3889
+ };
3890
+ reranking?: {
3891
+ /** Enable reranking (default false) */
3892
+ enabled?: boolean;
3893
+ model?: "@cf/baai/bge-reranker-base" | "";
3894
+ /** Match threshold (0-1, default 0.4) */
3895
+ match_threshold?: number;
3896
+ [key: string]: unknown;
3897
+ };
3898
+ [key: string]: unknown;
3899
+ };
3900
+ };
3901
+ type AiSearchChatCompletionsRequest = {
3902
+ messages: Array<{
3903
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3904
+ content: string | null;
3905
+ }>;
3906
+ model?: string;
3907
+ stream?: boolean;
3908
+ ai_search_options?: {
3909
+ retrieval?: {
3910
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3911
+ match_threshold?: number;
3912
+ max_num_results?: number;
3913
+ filters?: CompoundFilter | ComparisonFilter;
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
+ enabled?: boolean;
3925
+ model?: "@cf/baai/bge-reranker-base" | "";
3926
+ match_threshold?: number;
3927
+ [key: string]: unknown;
3928
+ };
3929
+ [key: string]: unknown;
3930
+ };
3931
+ [key: string]: unknown;
3932
+ };
3933
+ // AI Search V2 Response Types
3934
+ type AiSearchSearchResponse = {
3935
+ search_query: string;
3936
+ chunks: Array<{
3937
+ id: string;
3938
+ type: string;
3939
+ /** Match score (0-1) */
3940
+ score: number;
3941
+ text: string;
3942
+ item: {
3943
+ timestamp?: number;
3944
+ key: string;
3945
+ metadata?: Record<string, unknown>;
3946
+ };
3947
+ scoring_details?: {
3948
+ /** Keyword match score (0-1) */
3949
+ keyword_score?: number;
3950
+ /** Vector similarity score (0-1) */
3951
+ vector_score?: number;
3952
+ };
3953
+ }>;
3954
+ };
3955
+ type AiSearchListResponse = Array<{
3956
+ id: string;
3957
+ internal_id?: string;
3958
+ account_id?: string;
3959
+ account_tag?: string;
3960
+ /** Whether the instance is enabled (default true) */
3961
+ enable?: boolean;
3962
+ type?: "r2" | "web-crawler";
3963
+ source?: string;
3964
+ [key: string]: unknown;
3965
+ }>;
3966
+ type AiSearchConfig = {
3967
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3968
+ id: string;
3969
+ type: "r2" | "web-crawler";
3970
+ source: string;
3971
+ source_params?: object;
3972
+ /** Token ID (UUID format) */
3973
+ token_id?: string;
3974
+ ai_gateway_id?: string;
3975
+ /** Enable query rewriting (default false) */
3976
+ rewrite_query?: boolean;
3977
+ /** Enable reranking (default false) */
3978
+ reranking?: boolean;
3979
+ embedding_model?: string;
3980
+ ai_search_model?: string;
3981
+ };
3982
+ type AiSearchInstance = {
3983
+ id: string;
3984
+ enable?: boolean;
3985
+ type?: "r2" | "web-crawler";
3986
+ source?: string;
3987
+ [key: string]: unknown;
3988
+ };
3989
+ // AI Search Instance Service - Instance-level operations
3990
+ declare abstract class AiSearchInstanceService {
3991
+ /**
3992
+ * Search the AI Search instance for relevant chunks.
3993
+ * @param params Search request with messages and AI search options
3994
+ * @returns Search response with matching chunks
3995
+ */
3996
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3997
+ /**
3998
+ * Generate chat completions with AI Search context.
3999
+ * @param params Chat completions request with optional streaming
4000
+ * @returns Response object (if streaming) or chat completion result
4001
+ */
4002
+ chatCompletions(
4003
+ params: AiSearchChatCompletionsRequest,
4004
+ ): Promise<Response | object>;
4005
+ /**
4006
+ * Delete this AI Search instance.
4007
+ */
4008
+ delete(): Promise<void>;
4009
+ }
4010
+ // AI Search Account Service - Account-level operations
4011
+ declare abstract class AiSearchAccountService {
4012
+ /**
4013
+ * List all AI Search instances in the account.
4014
+ * @returns Array of AI Search instances
4015
+ */
4016
+ list(): Promise<AiSearchListResponse>;
4017
+ /**
4018
+ * Get an AI Search instance by ID.
4019
+ * @param name Instance ID
4020
+ * @returns Instance service for performing operations
4021
+ */
4022
+ get(name: string): AiSearchInstanceService;
4023
+ /**
4024
+ * Create a new AI Search instance.
4025
+ * @param config Instance configuration
4026
+ * @returns Instance service for performing operations
4027
+ */
4028
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4029
+ }
3852
4030
  type AiImageClassificationInput = {
3853
4031
  image: number[];
3854
4032
  };
@@ -9346,6 +9524,48 @@ type AiModelListType = Record<string, any>;
9346
9524
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9347
9525
  aiGatewayLogId: string | null;
9348
9526
  gateway(gatewayId: string): AiGateway;
9527
+ /**
9528
+ * Access the AI Search API for managing AI-powered search instances.
9529
+ *
9530
+ * This is the new API that replaces AutoRAG with better namespace separation:
9531
+ * - Account-level operations: `list()`, `create()`
9532
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9533
+ *
9534
+ * @example
9535
+ * ```typescript
9536
+ * // List all AI Search instances
9537
+ * const instances = await env.AI.aiSearch.list();
9538
+ *
9539
+ * // Search an instance
9540
+ * const results = await env.AI.aiSearch.get('my-search').search({
9541
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9542
+ * ai_search_options: {
9543
+ * retrieval: { max_num_results: 10 }
9544
+ * }
9545
+ * });
9546
+ *
9547
+ * // Generate chat completions with AI Search context
9548
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9549
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9550
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9551
+ * });
9552
+ * ```
9553
+ */
9554
+ aiSearch: AiSearchAccountService;
9555
+ /**
9556
+ * @deprecated AutoRAG has been replaced by AI Search.
9557
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9558
+ *
9559
+ * Migration guide:
9560
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9561
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9562
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9563
+ *
9564
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9565
+ *
9566
+ * @see AiSearchAccountService
9567
+ * @param autoragId Optional instance ID (omit for account-level operations)
9568
+ */
9349
9569
  autorag(autoragId: string): AutoRAG;
9350
9570
  run<
9351
9571
  Name extends keyof AiModelList,
@@ -9502,19 +9722,30 @@ declare abstract class AiGateway {
9502
9722
  ): Promise<Response>;
9503
9723
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9504
9724
  }
9725
+ /**
9726
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9727
+ * @see AiSearchInternalError
9728
+ */
9505
9729
  interface AutoRAGInternalError extends Error {}
9730
+ /**
9731
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9732
+ * @see AiSearchNotFoundError
9733
+ */
9506
9734
  interface AutoRAGNotFoundError extends Error {}
9735
+ /**
9736
+ * @deprecated This error type is no longer used in the AI Search API.
9737
+ */
9507
9738
  interface AutoRAGUnauthorizedError extends Error {}
9739
+ /**
9740
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9741
+ * @see AiSearchNameNotSetError
9742
+ */
9508
9743
  interface AutoRAGNameNotSetError extends Error {}
9509
- type ComparisonFilter = {
9510
- key: string;
9511
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9512
- value: string | number | boolean;
9513
- };
9514
- type CompoundFilter = {
9515
- type: "and" | "or";
9516
- filters: ComparisonFilter[];
9517
- };
9744
+ /**
9745
+ * @deprecated AutoRAG has been replaced by AI Search.
9746
+ * Use AiSearchSearchRequest with the new API instead.
9747
+ * @see AiSearchSearchRequest
9748
+ */
9518
9749
  type AutoRagSearchRequest = {
9519
9750
  query: string;
9520
9751
  filters?: CompoundFilter | ComparisonFilter;
@@ -9529,16 +9760,31 @@ type AutoRagSearchRequest = {
9529
9760
  };
9530
9761
  rewrite_query?: boolean;
9531
9762
  };
9763
+ /**
9764
+ * @deprecated AutoRAG has been replaced by AI Search.
9765
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9766
+ * @see AiSearchChatCompletionsRequest
9767
+ */
9532
9768
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9533
9769
  stream?: boolean;
9534
9770
  system_prompt?: string;
9535
9771
  };
9772
+ /**
9773
+ * @deprecated AutoRAG has been replaced by AI Search.
9774
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9775
+ * @see AiSearchChatCompletionsRequest
9776
+ */
9536
9777
  type AutoRagAiSearchRequestStreaming = Omit<
9537
9778
  AutoRagAiSearchRequest,
9538
9779
  "stream"
9539
9780
  > & {
9540
9781
  stream: true;
9541
9782
  };
9783
+ /**
9784
+ * @deprecated AutoRAG has been replaced by AI Search.
9785
+ * Use AiSearchSearchResponse with the new API instead.
9786
+ * @see AiSearchSearchResponse
9787
+ */
9542
9788
  type AutoRagSearchResponse = {
9543
9789
  object: "vector_store.search_results.page";
9544
9790
  search_query: string;
@@ -9555,6 +9801,11 @@ type AutoRagSearchResponse = {
9555
9801
  has_more: boolean;
9556
9802
  next_page: string | null;
9557
9803
  };
9804
+ /**
9805
+ * @deprecated AutoRAG has been replaced by AI Search.
9806
+ * Use AiSearchListResponse with the new API instead.
9807
+ * @see AiSearchListResponse
9808
+ */
9558
9809
  type AutoRagListResponse = {
9559
9810
  id: string;
9560
9811
  enable: boolean;
@@ -9564,14 +9815,51 @@ type AutoRagListResponse = {
9564
9815
  paused: boolean;
9565
9816
  status: string;
9566
9817
  }[];
9818
+ /**
9819
+ * @deprecated AutoRAG has been replaced by AI Search.
9820
+ * The new API returns different response formats for chat completions.
9821
+ */
9567
9822
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9568
9823
  response: string;
9569
9824
  };
9825
+ /**
9826
+ * @deprecated AutoRAG has been replaced by AI Search.
9827
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9828
+ *
9829
+ * Migration guide:
9830
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9831
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9832
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9833
+ *
9834
+ * @see AiSearchAccountService
9835
+ * @see AiSearchInstanceService
9836
+ */
9570
9837
  declare abstract class AutoRAG {
9838
+ /**
9839
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9840
+ * @see AiSearchAccountService.list
9841
+ */
9571
9842
  list(): Promise<AutoRagListResponse>;
9843
+ /**
9844
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9845
+ * Note: The new API uses a messages array instead of a query string.
9846
+ * @see AiSearchInstanceService.search
9847
+ */
9572
9848
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9849
+ /**
9850
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9851
+ * @see AiSearchInstanceService.chatCompletions
9852
+ */
9573
9853
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9854
+ /**
9855
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9856
+ * @see AiSearchInstanceService.chatCompletions
9857
+ */
9574
9858
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9859
+ /**
9860
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9861
+ * @see AiSearchInstanceService.chatCompletions
9862
+ */
9575
9863
  aiSearch(
9576
9864
  params: AutoRagAiSearchRequest,
9577
9865
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11057,8 +11345,14 @@ interface MediaTransformer {
11057
11345
  * @returns A generator for producing the transformed media output
11058
11346
  */
11059
11347
  transform(
11060
- transform: MediaTransformationInputOptions,
11348
+ transform?: MediaTransformationInputOptions,
11061
11349
  ): MediaTransformationGenerator;
11350
+ /**
11351
+ * Generates the final media output with specified options.
11352
+ * @param output - Configuration for the output format and parameters
11353
+ * @returns The final transformation result containing the transformed media
11354
+ */
11355
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11062
11356
  }
11063
11357
  /**
11064
11358
  * Generator for producing media transformation results.
@@ -11070,7 +11364,7 @@ interface MediaTransformationGenerator {
11070
11364
  * @param output - Configuration for the output format and parameters
11071
11365
  * @returns The final transformation result containing the transformed media
11072
11366
  */
11073
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11367
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11074
11368
  }
11075
11369
  /**
11076
11370
  * Result of a media transformation operation.
@@ -11079,19 +11373,19 @@ interface MediaTransformationGenerator {
11079
11373
  interface MediaTransformationResult {
11080
11374
  /**
11081
11375
  * Returns the transformed media as a readable stream of bytes.
11082
- * @returns A stream containing the transformed media data
11376
+ * @returns A promise containing a readable stream with the transformed media
11083
11377
  */
11084
- media(): ReadableStream<Uint8Array>;
11378
+ media(): Promise<ReadableStream<Uint8Array>>;
11085
11379
  /**
11086
11380
  * Returns the transformed media as an HTTP response object.
11087
- * @returns The transformed media as a Response, ready to store in cache or return to users
11381
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11088
11382
  */
11089
- response(): Response;
11383
+ response(): Promise<Response>;
11090
11384
  /**
11091
11385
  * Returns the MIME type of the transformed media.
11092
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11386
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11093
11387
  */
11094
- contentType(): string;
11388
+ contentType(): Promise<string>;
11095
11389
  }
11096
11390
  /**
11097
11391
  * Configuration options for transforming media input.