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