@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.
@@ -3817,6 +3817,184 @@ declare abstract class Performance {
3817
3817
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3818
3818
  now(): number;
3819
3819
  }
3820
+ // AI Search V2 API Error Interfaces
3821
+ interface AiSearchInternalError extends Error {}
3822
+ interface AiSearchNotFoundError extends Error {}
3823
+ interface AiSearchNameNotSetError extends Error {}
3824
+ // Filter types (shared with AutoRAG for compatibility)
3825
+ type ComparisonFilter = {
3826
+ key: string;
3827
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3828
+ value: string | number | boolean;
3829
+ };
3830
+ type CompoundFilter = {
3831
+ type: "and" | "or";
3832
+ filters: ComparisonFilter[];
3833
+ };
3834
+ // AI Search V2 Request Types
3835
+ type AiSearchSearchRequest = {
3836
+ messages: Array<{
3837
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3838
+ content: string | null;
3839
+ }>;
3840
+ ai_search_options?: {
3841
+ retrieval?: {
3842
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3843
+ /** Match threshold (0-1, default 0.4) */
3844
+ match_threshold?: number;
3845
+ /** Maximum number of results (1-50, default 10) */
3846
+ max_num_results?: number;
3847
+ filters?: CompoundFilter | ComparisonFilter;
3848
+ /** Context expansion (0-3, default 0) */
3849
+ context_expansion?: number;
3850
+ [key: string]: unknown;
3851
+ };
3852
+ query_rewrite?: {
3853
+ enabled?: boolean;
3854
+ model?: string;
3855
+ rewrite_prompt?: string;
3856
+ [key: string]: unknown;
3857
+ };
3858
+ reranking?: {
3859
+ /** Enable reranking (default false) */
3860
+ enabled?: boolean;
3861
+ model?: "@cf/baai/bge-reranker-base" | "";
3862
+ /** Match threshold (0-1, default 0.4) */
3863
+ match_threshold?: number;
3864
+ [key: string]: unknown;
3865
+ };
3866
+ [key: string]: unknown;
3867
+ };
3868
+ };
3869
+ type AiSearchChatCompletionsRequest = {
3870
+ messages: Array<{
3871
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3872
+ content: string | null;
3873
+ }>;
3874
+ model?: string;
3875
+ stream?: boolean;
3876
+ ai_search_options?: {
3877
+ retrieval?: {
3878
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3879
+ match_threshold?: number;
3880
+ max_num_results?: number;
3881
+ filters?: CompoundFilter | ComparisonFilter;
3882
+ context_expansion?: number;
3883
+ [key: string]: unknown;
3884
+ };
3885
+ query_rewrite?: {
3886
+ enabled?: boolean;
3887
+ model?: string;
3888
+ rewrite_prompt?: string;
3889
+ [key: string]: unknown;
3890
+ };
3891
+ reranking?: {
3892
+ enabled?: boolean;
3893
+ model?: "@cf/baai/bge-reranker-base" | "";
3894
+ match_threshold?: number;
3895
+ [key: string]: unknown;
3896
+ };
3897
+ [key: string]: unknown;
3898
+ };
3899
+ [key: string]: unknown;
3900
+ };
3901
+ // AI Search V2 Response Types
3902
+ type AiSearchSearchResponse = {
3903
+ search_query: string;
3904
+ chunks: Array<{
3905
+ id: string;
3906
+ type: string;
3907
+ /** Match score (0-1) */
3908
+ score: number;
3909
+ text: string;
3910
+ item: {
3911
+ timestamp?: number;
3912
+ key: string;
3913
+ metadata?: Record<string, unknown>;
3914
+ };
3915
+ scoring_details?: {
3916
+ /** Keyword match score (0-1) */
3917
+ keyword_score?: number;
3918
+ /** Vector similarity score (0-1) */
3919
+ vector_score?: number;
3920
+ };
3921
+ }>;
3922
+ };
3923
+ type AiSearchListResponse = Array<{
3924
+ id: string;
3925
+ internal_id?: string;
3926
+ account_id?: string;
3927
+ account_tag?: string;
3928
+ /** Whether the instance is enabled (default true) */
3929
+ enable?: boolean;
3930
+ type?: "r2" | "web-crawler";
3931
+ source?: string;
3932
+ [key: string]: unknown;
3933
+ }>;
3934
+ type AiSearchConfig = {
3935
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3936
+ id: string;
3937
+ type: "r2" | "web-crawler";
3938
+ source: string;
3939
+ source_params?: object;
3940
+ /** Token ID (UUID format) */
3941
+ token_id?: string;
3942
+ ai_gateway_id?: string;
3943
+ /** Enable query rewriting (default false) */
3944
+ rewrite_query?: boolean;
3945
+ /** Enable reranking (default false) */
3946
+ reranking?: boolean;
3947
+ embedding_model?: string;
3948
+ ai_search_model?: string;
3949
+ };
3950
+ type AiSearchInstance = {
3951
+ id: string;
3952
+ enable?: boolean;
3953
+ type?: "r2" | "web-crawler";
3954
+ source?: string;
3955
+ [key: string]: unknown;
3956
+ };
3957
+ // AI Search Instance Service - Instance-level operations
3958
+ declare abstract class AiSearchInstanceService {
3959
+ /**
3960
+ * Search the AI Search instance for relevant chunks.
3961
+ * @param params Search request with messages and AI search options
3962
+ * @returns Search response with matching chunks
3963
+ */
3964
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3965
+ /**
3966
+ * Generate chat completions with AI Search context.
3967
+ * @param params Chat completions request with optional streaming
3968
+ * @returns Response object (if streaming) or chat completion result
3969
+ */
3970
+ chatCompletions(
3971
+ params: AiSearchChatCompletionsRequest,
3972
+ ): Promise<Response | object>;
3973
+ /**
3974
+ * Delete this AI Search instance.
3975
+ */
3976
+ delete(): Promise<void>;
3977
+ }
3978
+ // AI Search Account Service - Account-level operations
3979
+ declare abstract class AiSearchAccountService {
3980
+ /**
3981
+ * List all AI Search instances in the account.
3982
+ * @returns Array of AI Search instances
3983
+ */
3984
+ list(): Promise<AiSearchListResponse>;
3985
+ /**
3986
+ * Get an AI Search instance by ID.
3987
+ * @param name Instance ID
3988
+ * @returns Instance service for performing operations
3989
+ */
3990
+ get(name: string): AiSearchInstanceService;
3991
+ /**
3992
+ * Create a new AI Search instance.
3993
+ * @param config Instance configuration
3994
+ * @returns Instance service for performing operations
3995
+ */
3996
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3997
+ }
3820
3998
  type AiImageClassificationInput = {
3821
3999
  image: number[];
3822
4000
  };
@@ -9314,6 +9492,48 @@ type AiModelListType = Record<string, any>;
9314
9492
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9315
9493
  aiGatewayLogId: string | null;
9316
9494
  gateway(gatewayId: string): AiGateway;
9495
+ /**
9496
+ * Access the AI Search API for managing AI-powered search instances.
9497
+ *
9498
+ * This is the new API that replaces AutoRAG with better namespace separation:
9499
+ * - Account-level operations: `list()`, `create()`
9500
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9501
+ *
9502
+ * @example
9503
+ * ```typescript
9504
+ * // List all AI Search instances
9505
+ * const instances = await env.AI.aiSearch.list();
9506
+ *
9507
+ * // Search an instance
9508
+ * const results = await env.AI.aiSearch.get('my-search').search({
9509
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9510
+ * ai_search_options: {
9511
+ * retrieval: { max_num_results: 10 }
9512
+ * }
9513
+ * });
9514
+ *
9515
+ * // Generate chat completions with AI Search context
9516
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9517
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9518
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9519
+ * });
9520
+ * ```
9521
+ */
9522
+ aiSearch: AiSearchAccountService;
9523
+ /**
9524
+ * @deprecated AutoRAG has been replaced by AI Search.
9525
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9526
+ *
9527
+ * Migration guide:
9528
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9529
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9530
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9531
+ *
9532
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9533
+ *
9534
+ * @see AiSearchAccountService
9535
+ * @param autoragId Optional instance ID (omit for account-level operations)
9536
+ */
9317
9537
  autorag(autoragId: string): AutoRAG;
9318
9538
  run<
9319
9539
  Name extends keyof AiModelList,
@@ -9470,19 +9690,30 @@ declare abstract class AiGateway {
9470
9690
  ): Promise<Response>;
9471
9691
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9472
9692
  }
9693
+ /**
9694
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9695
+ * @see AiSearchInternalError
9696
+ */
9473
9697
  interface AutoRAGInternalError extends Error {}
9698
+ /**
9699
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9700
+ * @see AiSearchNotFoundError
9701
+ */
9474
9702
  interface AutoRAGNotFoundError extends Error {}
9703
+ /**
9704
+ * @deprecated This error type is no longer used in the AI Search API.
9705
+ */
9475
9706
  interface AutoRAGUnauthorizedError extends Error {}
9707
+ /**
9708
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9709
+ * @see AiSearchNameNotSetError
9710
+ */
9476
9711
  interface AutoRAGNameNotSetError extends Error {}
9477
- type ComparisonFilter = {
9478
- key: string;
9479
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9480
- value: string | number | boolean;
9481
- };
9482
- type CompoundFilter = {
9483
- type: "and" | "or";
9484
- filters: ComparisonFilter[];
9485
- };
9712
+ /**
9713
+ * @deprecated AutoRAG has been replaced by AI Search.
9714
+ * Use AiSearchSearchRequest with the new API instead.
9715
+ * @see AiSearchSearchRequest
9716
+ */
9486
9717
  type AutoRagSearchRequest = {
9487
9718
  query: string;
9488
9719
  filters?: CompoundFilter | ComparisonFilter;
@@ -9497,16 +9728,31 @@ type AutoRagSearchRequest = {
9497
9728
  };
9498
9729
  rewrite_query?: boolean;
9499
9730
  };
9731
+ /**
9732
+ * @deprecated AutoRAG has been replaced by AI Search.
9733
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9734
+ * @see AiSearchChatCompletionsRequest
9735
+ */
9500
9736
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9501
9737
  stream?: boolean;
9502
9738
  system_prompt?: string;
9503
9739
  };
9740
+ /**
9741
+ * @deprecated AutoRAG has been replaced by AI Search.
9742
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9743
+ * @see AiSearchChatCompletionsRequest
9744
+ */
9504
9745
  type AutoRagAiSearchRequestStreaming = Omit<
9505
9746
  AutoRagAiSearchRequest,
9506
9747
  "stream"
9507
9748
  > & {
9508
9749
  stream: true;
9509
9750
  };
9751
+ /**
9752
+ * @deprecated AutoRAG has been replaced by AI Search.
9753
+ * Use AiSearchSearchResponse with the new API instead.
9754
+ * @see AiSearchSearchResponse
9755
+ */
9510
9756
  type AutoRagSearchResponse = {
9511
9757
  object: "vector_store.search_results.page";
9512
9758
  search_query: string;
@@ -9523,6 +9769,11 @@ type AutoRagSearchResponse = {
9523
9769
  has_more: boolean;
9524
9770
  next_page: string | null;
9525
9771
  };
9772
+ /**
9773
+ * @deprecated AutoRAG has been replaced by AI Search.
9774
+ * Use AiSearchListResponse with the new API instead.
9775
+ * @see AiSearchListResponse
9776
+ */
9526
9777
  type AutoRagListResponse = {
9527
9778
  id: string;
9528
9779
  enable: boolean;
@@ -9532,14 +9783,51 @@ type AutoRagListResponse = {
9532
9783
  paused: boolean;
9533
9784
  status: string;
9534
9785
  }[];
9786
+ /**
9787
+ * @deprecated AutoRAG has been replaced by AI Search.
9788
+ * The new API returns different response formats for chat completions.
9789
+ */
9535
9790
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9536
9791
  response: string;
9537
9792
  };
9793
+ /**
9794
+ * @deprecated AutoRAG has been replaced by AI Search.
9795
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9796
+ *
9797
+ * Migration guide:
9798
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9799
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9800
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9801
+ *
9802
+ * @see AiSearchAccountService
9803
+ * @see AiSearchInstanceService
9804
+ */
9538
9805
  declare abstract class AutoRAG {
9806
+ /**
9807
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9808
+ * @see AiSearchAccountService.list
9809
+ */
9539
9810
  list(): Promise<AutoRagListResponse>;
9811
+ /**
9812
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9813
+ * Note: The new API uses a messages array instead of a query string.
9814
+ * @see AiSearchInstanceService.search
9815
+ */
9540
9816
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9817
+ /**
9818
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9819
+ * @see AiSearchInstanceService.chatCompletions
9820
+ */
9541
9821
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9822
+ /**
9823
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9824
+ * @see AiSearchInstanceService.chatCompletions
9825
+ */
9542
9826
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9827
+ /**
9828
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9829
+ * @see AiSearchInstanceService.chatCompletions
9830
+ */
9543
9831
  aiSearch(
9544
9832
  params: AutoRagAiSearchRequest,
9545
9833
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11025,8 +11313,14 @@ interface MediaTransformer {
11025
11313
  * @returns A generator for producing the transformed media output
11026
11314
  */
11027
11315
  transform(
11028
- transform: MediaTransformationInputOptions,
11316
+ transform?: MediaTransformationInputOptions,
11029
11317
  ): MediaTransformationGenerator;
11318
+ /**
11319
+ * Generates the final media output with specified options.
11320
+ * @param output - Configuration for the output format and parameters
11321
+ * @returns The final transformation result containing the transformed media
11322
+ */
11323
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11030
11324
  }
11031
11325
  /**
11032
11326
  * Generator for producing media transformation results.
@@ -11038,7 +11332,7 @@ interface MediaTransformationGenerator {
11038
11332
  * @param output - Configuration for the output format and parameters
11039
11333
  * @returns The final transformation result containing the transformed media
11040
11334
  */
11041
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11335
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11042
11336
  }
11043
11337
  /**
11044
11338
  * Result of a media transformation operation.
@@ -11047,19 +11341,19 @@ interface MediaTransformationGenerator {
11047
11341
  interface MediaTransformationResult {
11048
11342
  /**
11049
11343
  * Returns the transformed media as a readable stream of bytes.
11050
- * @returns A stream containing the transformed media data
11344
+ * @returns A promise containing a readable stream with the transformed media
11051
11345
  */
11052
- media(): ReadableStream<Uint8Array>;
11346
+ media(): Promise<ReadableStream<Uint8Array>>;
11053
11347
  /**
11054
11348
  * Returns the transformed media as an HTTP response object.
11055
- * @returns The transformed media as a Response, ready to store in cache or return to users
11349
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11056
11350
  */
11057
- response(): Response;
11351
+ response(): Promise<Response>;
11058
11352
  /**
11059
11353
  * Returns the MIME type of the transformed media.
11060
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11354
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11061
11355
  */
11062
- contentType(): string;
11356
+ contentType(): Promise<string>;
11063
11357
  }
11064
11358
  /**
11065
11359
  * Configuration options for transforming media input.