@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.
@@ -3858,6 +3858,184 @@ export declare abstract class Performance {
3858
3858
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3859
3859
  now(): number;
3860
3860
  }
3861
+ // AI Search V2 API Error Interfaces
3862
+ export interface AiSearchInternalError extends Error {}
3863
+ export interface AiSearchNotFoundError extends Error {}
3864
+ export interface AiSearchNameNotSetError extends Error {}
3865
+ // Filter types (shared with AutoRAG for compatibility)
3866
+ export type ComparisonFilter = {
3867
+ key: string;
3868
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3869
+ value: string | number | boolean;
3870
+ };
3871
+ export type CompoundFilter = {
3872
+ type: "and" | "or";
3873
+ filters: ComparisonFilter[];
3874
+ };
3875
+ // AI Search V2 Request Types
3876
+ export type AiSearchSearchRequest = {
3877
+ messages: Array<{
3878
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3879
+ content: string | null;
3880
+ }>;
3881
+ ai_search_options?: {
3882
+ retrieval?: {
3883
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3884
+ /** Match threshold (0-1, default 0.4) */
3885
+ match_threshold?: number;
3886
+ /** Maximum number of results (1-50, default 10) */
3887
+ max_num_results?: number;
3888
+ filters?: CompoundFilter | ComparisonFilter;
3889
+ /** Context expansion (0-3, default 0) */
3890
+ context_expansion?: number;
3891
+ [key: string]: unknown;
3892
+ };
3893
+ query_rewrite?: {
3894
+ enabled?: boolean;
3895
+ model?: string;
3896
+ rewrite_prompt?: string;
3897
+ [key: string]: unknown;
3898
+ };
3899
+ reranking?: {
3900
+ /** Enable reranking (default false) */
3901
+ enabled?: boolean;
3902
+ model?: "@cf/baai/bge-reranker-base" | "";
3903
+ /** Match threshold (0-1, default 0.4) */
3904
+ match_threshold?: number;
3905
+ [key: string]: unknown;
3906
+ };
3907
+ [key: string]: unknown;
3908
+ };
3909
+ };
3910
+ export type AiSearchChatCompletionsRequest = {
3911
+ messages: Array<{
3912
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3913
+ content: string | null;
3914
+ }>;
3915
+ model?: string;
3916
+ stream?: boolean;
3917
+ ai_search_options?: {
3918
+ retrieval?: {
3919
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3920
+ match_threshold?: number;
3921
+ max_num_results?: number;
3922
+ filters?: CompoundFilter | ComparisonFilter;
3923
+ context_expansion?: number;
3924
+ [key: string]: unknown;
3925
+ };
3926
+ query_rewrite?: {
3927
+ enabled?: boolean;
3928
+ model?: string;
3929
+ rewrite_prompt?: string;
3930
+ [key: string]: unknown;
3931
+ };
3932
+ reranking?: {
3933
+ enabled?: boolean;
3934
+ model?: "@cf/baai/bge-reranker-base" | "";
3935
+ match_threshold?: number;
3936
+ [key: string]: unknown;
3937
+ };
3938
+ [key: string]: unknown;
3939
+ };
3940
+ [key: string]: unknown;
3941
+ };
3942
+ // AI Search V2 Response Types
3943
+ export type AiSearchSearchResponse = {
3944
+ search_query: string;
3945
+ chunks: Array<{
3946
+ id: string;
3947
+ type: string;
3948
+ /** Match score (0-1) */
3949
+ score: number;
3950
+ text: string;
3951
+ item: {
3952
+ timestamp?: number;
3953
+ key: string;
3954
+ metadata?: Record<string, unknown>;
3955
+ };
3956
+ scoring_details?: {
3957
+ /** Keyword match score (0-1) */
3958
+ keyword_score?: number;
3959
+ /** Vector similarity score (0-1) */
3960
+ vector_score?: number;
3961
+ };
3962
+ }>;
3963
+ };
3964
+ export type AiSearchListResponse = Array<{
3965
+ id: string;
3966
+ internal_id?: string;
3967
+ account_id?: string;
3968
+ account_tag?: string;
3969
+ /** Whether the instance is enabled (default true) */
3970
+ enable?: boolean;
3971
+ type?: "r2" | "web-crawler";
3972
+ source?: string;
3973
+ [key: string]: unknown;
3974
+ }>;
3975
+ export type AiSearchConfig = {
3976
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3977
+ id: string;
3978
+ type: "r2" | "web-crawler";
3979
+ source: string;
3980
+ source_params?: object;
3981
+ /** Token ID (UUID format) */
3982
+ token_id?: string;
3983
+ ai_gateway_id?: string;
3984
+ /** Enable query rewriting (default false) */
3985
+ rewrite_query?: boolean;
3986
+ /** Enable reranking (default false) */
3987
+ reranking?: boolean;
3988
+ embedding_model?: string;
3989
+ ai_search_model?: string;
3990
+ };
3991
+ export type AiSearchInstance = {
3992
+ id: string;
3993
+ enable?: boolean;
3994
+ type?: "r2" | "web-crawler";
3995
+ source?: string;
3996
+ [key: string]: unknown;
3997
+ };
3998
+ // AI Search Instance Service - Instance-level operations
3999
+ export declare abstract class AiSearchInstanceService {
4000
+ /**
4001
+ * Search the AI Search instance for relevant chunks.
4002
+ * @param params Search request with messages and AI search options
4003
+ * @returns Search response with matching chunks
4004
+ */
4005
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4006
+ /**
4007
+ * Generate chat completions with AI Search context.
4008
+ * @param params Chat completions request with optional streaming
4009
+ * @returns Response object (if streaming) or chat completion result
4010
+ */
4011
+ chatCompletions(
4012
+ params: AiSearchChatCompletionsRequest,
4013
+ ): Promise<Response | object>;
4014
+ /**
4015
+ * Delete this AI Search instance.
4016
+ */
4017
+ delete(): Promise<void>;
4018
+ }
4019
+ // AI Search Account Service - Account-level operations
4020
+ export declare abstract class AiSearchAccountService {
4021
+ /**
4022
+ * List all AI Search instances in the account.
4023
+ * @returns Array of AI Search instances
4024
+ */
4025
+ list(): Promise<AiSearchListResponse>;
4026
+ /**
4027
+ * Get an AI Search instance by ID.
4028
+ * @param name Instance ID
4029
+ * @returns Instance service for performing operations
4030
+ */
4031
+ get(name: string): AiSearchInstanceService;
4032
+ /**
4033
+ * Create a new AI Search instance.
4034
+ * @param config Instance configuration
4035
+ * @returns Instance service for performing operations
4036
+ */
4037
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4038
+ }
3861
4039
  export type AiImageClassificationInput = {
3862
4040
  image: number[];
3863
4041
  };
@@ -9358,6 +9536,48 @@ export declare abstract class Ai<
9358
9536
  > {
9359
9537
  aiGatewayLogId: string | null;
9360
9538
  gateway(gatewayId: string): AiGateway;
9539
+ /**
9540
+ * Access the AI Search API for managing AI-powered search instances.
9541
+ *
9542
+ * This is the new API that replaces AutoRAG with better namespace separation:
9543
+ * - Account-level operations: `list()`, `create()`
9544
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9545
+ *
9546
+ * @example
9547
+ * ```typescript
9548
+ * // List all AI Search instances
9549
+ * const instances = await env.AI.aiSearch.list();
9550
+ *
9551
+ * // Search an instance
9552
+ * const results = await env.AI.aiSearch.get('my-search').search({
9553
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9554
+ * ai_search_options: {
9555
+ * retrieval: { max_num_results: 10 }
9556
+ * }
9557
+ * });
9558
+ *
9559
+ * // Generate chat completions with AI Search context
9560
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9561
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9562
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9563
+ * });
9564
+ * ```
9565
+ */
9566
+ aiSearch: AiSearchAccountService;
9567
+ /**
9568
+ * @deprecated AutoRAG has been replaced by AI Search.
9569
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9570
+ *
9571
+ * Migration guide:
9572
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9573
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9574
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9575
+ *
9576
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9577
+ *
9578
+ * @see AiSearchAccountService
9579
+ * @param autoragId Optional instance ID (omit for account-level operations)
9580
+ */
9361
9581
  autorag(autoragId: string): AutoRAG;
9362
9582
  run<
9363
9583
  Name extends keyof AiModelList,
@@ -9514,19 +9734,30 @@ export declare abstract class AiGateway {
9514
9734
  ): Promise<Response>;
9515
9735
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9516
9736
  }
9737
+ /**
9738
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9739
+ * @see AiSearchInternalError
9740
+ */
9517
9741
  export interface AutoRAGInternalError extends Error {}
9742
+ /**
9743
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9744
+ * @see AiSearchNotFoundError
9745
+ */
9518
9746
  export interface AutoRAGNotFoundError extends Error {}
9747
+ /**
9748
+ * @deprecated This error type is no longer used in the AI Search API.
9749
+ */
9519
9750
  export interface AutoRAGUnauthorizedError extends Error {}
9751
+ /**
9752
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9753
+ * @see AiSearchNameNotSetError
9754
+ */
9520
9755
  export interface AutoRAGNameNotSetError extends Error {}
9521
- export type ComparisonFilter = {
9522
- key: string;
9523
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9524
- value: string | number | boolean;
9525
- };
9526
- export type CompoundFilter = {
9527
- type: "and" | "or";
9528
- filters: ComparisonFilter[];
9529
- };
9756
+ /**
9757
+ * @deprecated AutoRAG has been replaced by AI Search.
9758
+ * Use AiSearchSearchRequest with the new API instead.
9759
+ * @see AiSearchSearchRequest
9760
+ */
9530
9761
  export type AutoRagSearchRequest = {
9531
9762
  query: string;
9532
9763
  filters?: CompoundFilter | ComparisonFilter;
@@ -9541,16 +9772,31 @@ export type AutoRagSearchRequest = {
9541
9772
  };
9542
9773
  rewrite_query?: boolean;
9543
9774
  };
9775
+ /**
9776
+ * @deprecated AutoRAG has been replaced by AI Search.
9777
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9778
+ * @see AiSearchChatCompletionsRequest
9779
+ */
9544
9780
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9545
9781
  stream?: boolean;
9546
9782
  system_prompt?: string;
9547
9783
  };
9784
+ /**
9785
+ * @deprecated AutoRAG has been replaced by AI Search.
9786
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9787
+ * @see AiSearchChatCompletionsRequest
9788
+ */
9548
9789
  export type AutoRagAiSearchRequestStreaming = Omit<
9549
9790
  AutoRagAiSearchRequest,
9550
9791
  "stream"
9551
9792
  > & {
9552
9793
  stream: true;
9553
9794
  };
9795
+ /**
9796
+ * @deprecated AutoRAG has been replaced by AI Search.
9797
+ * Use AiSearchSearchResponse with the new API instead.
9798
+ * @see AiSearchSearchResponse
9799
+ */
9554
9800
  export type AutoRagSearchResponse = {
9555
9801
  object: "vector_store.search_results.page";
9556
9802
  search_query: string;
@@ -9567,6 +9813,11 @@ export type AutoRagSearchResponse = {
9567
9813
  has_more: boolean;
9568
9814
  next_page: string | null;
9569
9815
  };
9816
+ /**
9817
+ * @deprecated AutoRAG has been replaced by AI Search.
9818
+ * Use AiSearchListResponse with the new API instead.
9819
+ * @see AiSearchListResponse
9820
+ */
9570
9821
  export type AutoRagListResponse = {
9571
9822
  id: string;
9572
9823
  enable: boolean;
@@ -9576,14 +9827,51 @@ export type AutoRagListResponse = {
9576
9827
  paused: boolean;
9577
9828
  status: string;
9578
9829
  }[];
9830
+ /**
9831
+ * @deprecated AutoRAG has been replaced by AI Search.
9832
+ * The new API returns different response formats for chat completions.
9833
+ */
9579
9834
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9580
9835
  response: string;
9581
9836
  };
9837
+ /**
9838
+ * @deprecated AutoRAG has been replaced by AI Search.
9839
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9840
+ *
9841
+ * Migration guide:
9842
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9843
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9844
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9845
+ *
9846
+ * @see AiSearchAccountService
9847
+ * @see AiSearchInstanceService
9848
+ */
9582
9849
  export declare abstract class AutoRAG {
9850
+ /**
9851
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9852
+ * @see AiSearchAccountService.list
9853
+ */
9583
9854
  list(): Promise<AutoRagListResponse>;
9855
+ /**
9856
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9857
+ * Note: The new API uses a messages array instead of a query string.
9858
+ * @see AiSearchInstanceService.search
9859
+ */
9584
9860
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9861
+ /**
9862
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9863
+ * @see AiSearchInstanceService.chatCompletions
9864
+ */
9585
9865
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9866
+ /**
9867
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9868
+ * @see AiSearchInstanceService.chatCompletions
9869
+ */
9586
9870
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9871
+ /**
9872
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9873
+ * @see AiSearchInstanceService.chatCompletions
9874
+ */
9587
9875
  aiSearch(
9588
9876
  params: AutoRagAiSearchRequest,
9589
9877
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11074,8 +11362,14 @@ export interface MediaTransformer {
11074
11362
  * @returns A generator for producing the transformed media output
11075
11363
  */
11076
11364
  transform(
11077
- transform: MediaTransformationInputOptions,
11365
+ transform?: MediaTransformationInputOptions,
11078
11366
  ): MediaTransformationGenerator;
11367
+ /**
11368
+ * Generates the final media output with specified options.
11369
+ * @param output - Configuration for the output format and parameters
11370
+ * @returns The final transformation result containing the transformed media
11371
+ */
11372
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11079
11373
  }
11080
11374
  /**
11081
11375
  * Generator for producing media transformation results.
@@ -11087,7 +11381,7 @@ export interface MediaTransformationGenerator {
11087
11381
  * @param output - Configuration for the output format and parameters
11088
11382
  * @returns The final transformation result containing the transformed media
11089
11383
  */
11090
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11384
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11091
11385
  }
11092
11386
  /**
11093
11387
  * Result of a media transformation operation.
@@ -11096,19 +11390,19 @@ export interface MediaTransformationGenerator {
11096
11390
  export interface MediaTransformationResult {
11097
11391
  /**
11098
11392
  * Returns the transformed media as a readable stream of bytes.
11099
- * @returns A stream containing the transformed media data
11393
+ * @returns A promise containing a readable stream with the transformed media
11100
11394
  */
11101
- media(): ReadableStream<Uint8Array>;
11395
+ media(): Promise<ReadableStream<Uint8Array>>;
11102
11396
  /**
11103
11397
  * Returns the transformed media as an HTTP response object.
11104
- * @returns The transformed media as a Response, ready to store in cache or return to users
11398
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11105
11399
  */
11106
- response(): Response;
11400
+ response(): Promise<Response>;
11107
11401
  /**
11108
11402
  * Returns the MIME type of the transformed media.
11109
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11403
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11110
11404
  */
11111
- contentType(): string;
11405
+ contentType(): Promise<string>;
11112
11406
  }
11113
11407
  /**
11114
11408
  * Configuration options for transforming media input.