@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.
package/latest/index.ts CHANGED
@@ -3891,6 +3891,184 @@ export declare abstract class Performance {
3891
3891
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3892
3892
  now(): number;
3893
3893
  }
3894
+ // AI Search V2 API Error Interfaces
3895
+ export interface AiSearchInternalError extends Error {}
3896
+ export interface AiSearchNotFoundError extends Error {}
3897
+ export interface AiSearchNameNotSetError extends Error {}
3898
+ // Filter types (shared with AutoRAG for compatibility)
3899
+ export type ComparisonFilter = {
3900
+ key: string;
3901
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3902
+ value: string | number | boolean;
3903
+ };
3904
+ export type CompoundFilter = {
3905
+ type: "and" | "or";
3906
+ filters: ComparisonFilter[];
3907
+ };
3908
+ // AI Search V2 Request Types
3909
+ export type AiSearchSearchRequest = {
3910
+ messages: Array<{
3911
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3912
+ content: string | null;
3913
+ }>;
3914
+ ai_search_options?: {
3915
+ retrieval?: {
3916
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3917
+ /** Match threshold (0-1, default 0.4) */
3918
+ match_threshold?: number;
3919
+ /** Maximum number of results (1-50, default 10) */
3920
+ max_num_results?: number;
3921
+ filters?: CompoundFilter | ComparisonFilter;
3922
+ /** Context expansion (0-3, default 0) */
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
+ /** Enable reranking (default false) */
3934
+ enabled?: boolean;
3935
+ model?: "@cf/baai/bge-reranker-base" | "";
3936
+ /** Match threshold (0-1, default 0.4) */
3937
+ match_threshold?: number;
3938
+ [key: string]: unknown;
3939
+ };
3940
+ [key: string]: unknown;
3941
+ };
3942
+ };
3943
+ export type AiSearchChatCompletionsRequest = {
3944
+ messages: Array<{
3945
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3946
+ content: string | null;
3947
+ }>;
3948
+ model?: string;
3949
+ stream?: boolean;
3950
+ ai_search_options?: {
3951
+ retrieval?: {
3952
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3953
+ match_threshold?: number;
3954
+ max_num_results?: number;
3955
+ filters?: CompoundFilter | ComparisonFilter;
3956
+ context_expansion?: number;
3957
+ [key: string]: unknown;
3958
+ };
3959
+ query_rewrite?: {
3960
+ enabled?: boolean;
3961
+ model?: string;
3962
+ rewrite_prompt?: string;
3963
+ [key: string]: unknown;
3964
+ };
3965
+ reranking?: {
3966
+ enabled?: boolean;
3967
+ model?: "@cf/baai/bge-reranker-base" | "";
3968
+ match_threshold?: number;
3969
+ [key: string]: unknown;
3970
+ };
3971
+ [key: string]: unknown;
3972
+ };
3973
+ [key: string]: unknown;
3974
+ };
3975
+ // AI Search V2 Response Types
3976
+ export type AiSearchSearchResponse = {
3977
+ search_query: string;
3978
+ chunks: Array<{
3979
+ id: string;
3980
+ type: string;
3981
+ /** Match score (0-1) */
3982
+ score: number;
3983
+ text: string;
3984
+ item: {
3985
+ timestamp?: number;
3986
+ key: string;
3987
+ metadata?: Record<string, unknown>;
3988
+ };
3989
+ scoring_details?: {
3990
+ /** Keyword match score (0-1) */
3991
+ keyword_score?: number;
3992
+ /** Vector similarity score (0-1) */
3993
+ vector_score?: number;
3994
+ };
3995
+ }>;
3996
+ };
3997
+ export type AiSearchListResponse = Array<{
3998
+ id: string;
3999
+ internal_id?: string;
4000
+ account_id?: string;
4001
+ account_tag?: string;
4002
+ /** Whether the instance is enabled (default true) */
4003
+ enable?: boolean;
4004
+ type?: "r2" | "web-crawler";
4005
+ source?: string;
4006
+ [key: string]: unknown;
4007
+ }>;
4008
+ export type AiSearchConfig = {
4009
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
4010
+ id: string;
4011
+ type: "r2" | "web-crawler";
4012
+ source: string;
4013
+ source_params?: object;
4014
+ /** Token ID (UUID format) */
4015
+ token_id?: string;
4016
+ ai_gateway_id?: string;
4017
+ /** Enable query rewriting (default false) */
4018
+ rewrite_query?: boolean;
4019
+ /** Enable reranking (default false) */
4020
+ reranking?: boolean;
4021
+ embedding_model?: string;
4022
+ ai_search_model?: string;
4023
+ };
4024
+ export type AiSearchInstance = {
4025
+ id: string;
4026
+ enable?: boolean;
4027
+ type?: "r2" | "web-crawler";
4028
+ source?: string;
4029
+ [key: string]: unknown;
4030
+ };
4031
+ // AI Search Instance Service - Instance-level operations
4032
+ export declare abstract class AiSearchInstanceService {
4033
+ /**
4034
+ * Search the AI Search instance for relevant chunks.
4035
+ * @param params Search request with messages and AI search options
4036
+ * @returns Search response with matching chunks
4037
+ */
4038
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4039
+ /**
4040
+ * Generate chat completions with AI Search context.
4041
+ * @param params Chat completions request with optional streaming
4042
+ * @returns Response object (if streaming) or chat completion result
4043
+ */
4044
+ chatCompletions(
4045
+ params: AiSearchChatCompletionsRequest,
4046
+ ): Promise<Response | object>;
4047
+ /**
4048
+ * Delete this AI Search instance.
4049
+ */
4050
+ delete(): Promise<void>;
4051
+ }
4052
+ // AI Search Account Service - Account-level operations
4053
+ export declare abstract class AiSearchAccountService {
4054
+ /**
4055
+ * List all AI Search instances in the account.
4056
+ * @returns Array of AI Search instances
4057
+ */
4058
+ list(): Promise<AiSearchListResponse>;
4059
+ /**
4060
+ * Get an AI Search instance by ID.
4061
+ * @param name Instance ID
4062
+ * @returns Instance service for performing operations
4063
+ */
4064
+ get(name: string): AiSearchInstanceService;
4065
+ /**
4066
+ * Create a new AI Search instance.
4067
+ * @param config Instance configuration
4068
+ * @returns Instance service for performing operations
4069
+ */
4070
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4071
+ }
3894
4072
  export type AiImageClassificationInput = {
3895
4073
  image: number[];
3896
4074
  };
@@ -9391,6 +9569,48 @@ export declare abstract class Ai<
9391
9569
  > {
9392
9570
  aiGatewayLogId: string | null;
9393
9571
  gateway(gatewayId: string): AiGateway;
9572
+ /**
9573
+ * Access the AI Search API for managing AI-powered search instances.
9574
+ *
9575
+ * This is the new API that replaces AutoRAG with better namespace separation:
9576
+ * - Account-level operations: `list()`, `create()`
9577
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9578
+ *
9579
+ * @example
9580
+ * ```typescript
9581
+ * // List all AI Search instances
9582
+ * const instances = await env.AI.aiSearch.list();
9583
+ *
9584
+ * // Search an instance
9585
+ * const results = await env.AI.aiSearch.get('my-search').search({
9586
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9587
+ * ai_search_options: {
9588
+ * retrieval: { max_num_results: 10 }
9589
+ * }
9590
+ * });
9591
+ *
9592
+ * // Generate chat completions with AI Search context
9593
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9594
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9595
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9596
+ * });
9597
+ * ```
9598
+ */
9599
+ aiSearch: AiSearchAccountService;
9600
+ /**
9601
+ * @deprecated AutoRAG has been replaced by AI Search.
9602
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9603
+ *
9604
+ * Migration guide:
9605
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9606
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9607
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9608
+ *
9609
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9610
+ *
9611
+ * @see AiSearchAccountService
9612
+ * @param autoragId Optional instance ID (omit for account-level operations)
9613
+ */
9394
9614
  autorag(autoragId: string): AutoRAG;
9395
9615
  run<
9396
9616
  Name extends keyof AiModelList,
@@ -9547,19 +9767,30 @@ export declare abstract class AiGateway {
9547
9767
  ): Promise<Response>;
9548
9768
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9549
9769
  }
9770
+ /**
9771
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9772
+ * @see AiSearchInternalError
9773
+ */
9550
9774
  export interface AutoRAGInternalError extends Error {}
9775
+ /**
9776
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9777
+ * @see AiSearchNotFoundError
9778
+ */
9551
9779
  export interface AutoRAGNotFoundError extends Error {}
9780
+ /**
9781
+ * @deprecated This error type is no longer used in the AI Search API.
9782
+ */
9552
9783
  export interface AutoRAGUnauthorizedError extends Error {}
9784
+ /**
9785
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9786
+ * @see AiSearchNameNotSetError
9787
+ */
9553
9788
  export interface AutoRAGNameNotSetError extends Error {}
9554
- export type ComparisonFilter = {
9555
- key: string;
9556
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9557
- value: string | number | boolean;
9558
- };
9559
- export type CompoundFilter = {
9560
- type: "and" | "or";
9561
- filters: ComparisonFilter[];
9562
- };
9789
+ /**
9790
+ * @deprecated AutoRAG has been replaced by AI Search.
9791
+ * Use AiSearchSearchRequest with the new API instead.
9792
+ * @see AiSearchSearchRequest
9793
+ */
9563
9794
  export type AutoRagSearchRequest = {
9564
9795
  query: string;
9565
9796
  filters?: CompoundFilter | ComparisonFilter;
@@ -9574,16 +9805,31 @@ export type AutoRagSearchRequest = {
9574
9805
  };
9575
9806
  rewrite_query?: boolean;
9576
9807
  };
9808
+ /**
9809
+ * @deprecated AutoRAG has been replaced by AI Search.
9810
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9811
+ * @see AiSearchChatCompletionsRequest
9812
+ */
9577
9813
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9578
9814
  stream?: boolean;
9579
9815
  system_prompt?: string;
9580
9816
  };
9817
+ /**
9818
+ * @deprecated AutoRAG has been replaced by AI Search.
9819
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9820
+ * @see AiSearchChatCompletionsRequest
9821
+ */
9581
9822
  export type AutoRagAiSearchRequestStreaming = Omit<
9582
9823
  AutoRagAiSearchRequest,
9583
9824
  "stream"
9584
9825
  > & {
9585
9826
  stream: true;
9586
9827
  };
9828
+ /**
9829
+ * @deprecated AutoRAG has been replaced by AI Search.
9830
+ * Use AiSearchSearchResponse with the new API instead.
9831
+ * @see AiSearchSearchResponse
9832
+ */
9587
9833
  export type AutoRagSearchResponse = {
9588
9834
  object: "vector_store.search_results.page";
9589
9835
  search_query: string;
@@ -9600,6 +9846,11 @@ export type AutoRagSearchResponse = {
9600
9846
  has_more: boolean;
9601
9847
  next_page: string | null;
9602
9848
  };
9849
+ /**
9850
+ * @deprecated AutoRAG has been replaced by AI Search.
9851
+ * Use AiSearchListResponse with the new API instead.
9852
+ * @see AiSearchListResponse
9853
+ */
9603
9854
  export type AutoRagListResponse = {
9604
9855
  id: string;
9605
9856
  enable: boolean;
@@ -9609,14 +9860,51 @@ export type AutoRagListResponse = {
9609
9860
  paused: boolean;
9610
9861
  status: string;
9611
9862
  }[];
9863
+ /**
9864
+ * @deprecated AutoRAG has been replaced by AI Search.
9865
+ * The new API returns different response formats for chat completions.
9866
+ */
9612
9867
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9613
9868
  response: string;
9614
9869
  };
9870
+ /**
9871
+ * @deprecated AutoRAG has been replaced by AI Search.
9872
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9873
+ *
9874
+ * Migration guide:
9875
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9876
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9877
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9878
+ *
9879
+ * @see AiSearchAccountService
9880
+ * @see AiSearchInstanceService
9881
+ */
9615
9882
  export declare abstract class AutoRAG {
9883
+ /**
9884
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9885
+ * @see AiSearchAccountService.list
9886
+ */
9616
9887
  list(): Promise<AutoRagListResponse>;
9888
+ /**
9889
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9890
+ * Note: The new API uses a messages array instead of a query string.
9891
+ * @see AiSearchInstanceService.search
9892
+ */
9617
9893
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9894
+ /**
9895
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9896
+ * @see AiSearchInstanceService.chatCompletions
9897
+ */
9618
9898
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9899
+ /**
9900
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9901
+ * @see AiSearchInstanceService.chatCompletions
9902
+ */
9619
9903
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9904
+ /**
9905
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9906
+ * @see AiSearchInstanceService.chatCompletions
9907
+ */
9620
9908
  aiSearch(
9621
9909
  params: AutoRagAiSearchRequest,
9622
9910
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11107,8 +11395,14 @@ export interface MediaTransformer {
11107
11395
  * @returns A generator for producing the transformed media output
11108
11396
  */
11109
11397
  transform(
11110
- transform: MediaTransformationInputOptions,
11398
+ transform?: MediaTransformationInputOptions,
11111
11399
  ): MediaTransformationGenerator;
11400
+ /**
11401
+ * Generates the final media output with specified options.
11402
+ * @param output - Configuration for the output format and parameters
11403
+ * @returns The final transformation result containing the transformed media
11404
+ */
11405
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11112
11406
  }
11113
11407
  /**
11114
11408
  * Generator for producing media transformation results.
@@ -11120,7 +11414,7 @@ export interface MediaTransformationGenerator {
11120
11414
  * @param output - Configuration for the output format and parameters
11121
11415
  * @returns The final transformation result containing the transformed media
11122
11416
  */
11123
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11417
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11124
11418
  }
11125
11419
  /**
11126
11420
  * Result of a media transformation operation.
@@ -11129,19 +11423,19 @@ export interface MediaTransformationGenerator {
11129
11423
  export interface MediaTransformationResult {
11130
11424
  /**
11131
11425
  * Returns the transformed media as a readable stream of bytes.
11132
- * @returns A stream containing the transformed media data
11426
+ * @returns A promise containing a readable stream with the transformed media
11133
11427
  */
11134
- media(): ReadableStream<Uint8Array>;
11428
+ media(): Promise<ReadableStream<Uint8Array>>;
11135
11429
  /**
11136
11430
  * Returns the transformed media as an HTTP response object.
11137
- * @returns The transformed media as a Response, ready to store in cache or return to users
11431
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11138
11432
  */
11139
- response(): Response;
11433
+ response(): Promise<Response>;
11140
11434
  /**
11141
11435
  * Returns the MIME type of the transformed media.
11142
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11436
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11143
11437
  */
11144
- contentType(): string;
11438
+ contentType(): Promise<string>;
11145
11439
  }
11146
11440
  /**
11147
11441
  * Configuration options for transforming media input.