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