@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.
@@ -3751,6 +3751,184 @@ export declare abstract class Performance {
3751
3751
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3752
3752
  now(): number;
3753
3753
  }
3754
+ // AI Search V2 API Error Interfaces
3755
+ export interface AiSearchInternalError extends Error {}
3756
+ export interface AiSearchNotFoundError extends Error {}
3757
+ export interface AiSearchNameNotSetError extends Error {}
3758
+ // Filter types (shared with AutoRAG for compatibility)
3759
+ export type ComparisonFilter = {
3760
+ key: string;
3761
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3762
+ value: string | number | boolean;
3763
+ };
3764
+ export type CompoundFilter = {
3765
+ type: "and" | "or";
3766
+ filters: ComparisonFilter[];
3767
+ };
3768
+ // AI Search V2 Request Types
3769
+ export type AiSearchSearchRequest = {
3770
+ messages: Array<{
3771
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3772
+ content: string | null;
3773
+ }>;
3774
+ ai_search_options?: {
3775
+ retrieval?: {
3776
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3777
+ /** Match threshold (0-1, default 0.4) */
3778
+ match_threshold?: number;
3779
+ /** Maximum number of results (1-50, default 10) */
3780
+ max_num_results?: number;
3781
+ filters?: CompoundFilter | ComparisonFilter;
3782
+ /** Context expansion (0-3, default 0) */
3783
+ context_expansion?: number;
3784
+ [key: string]: unknown;
3785
+ };
3786
+ query_rewrite?: {
3787
+ enabled?: boolean;
3788
+ model?: string;
3789
+ rewrite_prompt?: string;
3790
+ [key: string]: unknown;
3791
+ };
3792
+ reranking?: {
3793
+ /** Enable reranking (default false) */
3794
+ enabled?: boolean;
3795
+ model?: "@cf/baai/bge-reranker-base" | "";
3796
+ /** Match threshold (0-1, default 0.4) */
3797
+ match_threshold?: number;
3798
+ [key: string]: unknown;
3799
+ };
3800
+ [key: string]: unknown;
3801
+ };
3802
+ };
3803
+ export type AiSearchChatCompletionsRequest = {
3804
+ messages: Array<{
3805
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3806
+ content: string | null;
3807
+ }>;
3808
+ model?: string;
3809
+ stream?: boolean;
3810
+ ai_search_options?: {
3811
+ retrieval?: {
3812
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3813
+ match_threshold?: number;
3814
+ max_num_results?: number;
3815
+ filters?: CompoundFilter | ComparisonFilter;
3816
+ context_expansion?: number;
3817
+ [key: string]: unknown;
3818
+ };
3819
+ query_rewrite?: {
3820
+ enabled?: boolean;
3821
+ model?: string;
3822
+ rewrite_prompt?: string;
3823
+ [key: string]: unknown;
3824
+ };
3825
+ reranking?: {
3826
+ enabled?: boolean;
3827
+ model?: "@cf/baai/bge-reranker-base" | "";
3828
+ match_threshold?: number;
3829
+ [key: string]: unknown;
3830
+ };
3831
+ [key: string]: unknown;
3832
+ };
3833
+ [key: string]: unknown;
3834
+ };
3835
+ // AI Search V2 Response Types
3836
+ export type AiSearchSearchResponse = {
3837
+ search_query: string;
3838
+ chunks: Array<{
3839
+ id: string;
3840
+ type: string;
3841
+ /** Match score (0-1) */
3842
+ score: number;
3843
+ text: string;
3844
+ item: {
3845
+ timestamp?: number;
3846
+ key: string;
3847
+ metadata?: Record<string, unknown>;
3848
+ };
3849
+ scoring_details?: {
3850
+ /** Keyword match score (0-1) */
3851
+ keyword_score?: number;
3852
+ /** Vector similarity score (0-1) */
3853
+ vector_score?: number;
3854
+ };
3855
+ }>;
3856
+ };
3857
+ export type AiSearchListResponse = Array<{
3858
+ id: string;
3859
+ internal_id?: string;
3860
+ account_id?: string;
3861
+ account_tag?: string;
3862
+ /** Whether the instance is enabled (default true) */
3863
+ enable?: boolean;
3864
+ type?: "r2" | "web-crawler";
3865
+ source?: string;
3866
+ [key: string]: unknown;
3867
+ }>;
3868
+ export type AiSearchConfig = {
3869
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3870
+ id: string;
3871
+ type: "r2" | "web-crawler";
3872
+ source: string;
3873
+ source_params?: object;
3874
+ /** Token ID (UUID format) */
3875
+ token_id?: string;
3876
+ ai_gateway_id?: string;
3877
+ /** Enable query rewriting (default false) */
3878
+ rewrite_query?: boolean;
3879
+ /** Enable reranking (default false) */
3880
+ reranking?: boolean;
3881
+ embedding_model?: string;
3882
+ ai_search_model?: string;
3883
+ };
3884
+ export type AiSearchInstance = {
3885
+ id: string;
3886
+ enable?: boolean;
3887
+ type?: "r2" | "web-crawler";
3888
+ source?: string;
3889
+ [key: string]: unknown;
3890
+ };
3891
+ // AI Search Instance Service - Instance-level operations
3892
+ export declare abstract class AiSearchInstanceService {
3893
+ /**
3894
+ * Search the AI Search instance for relevant chunks.
3895
+ * @param params Search request with messages and AI search options
3896
+ * @returns Search response with matching chunks
3897
+ */
3898
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3899
+ /**
3900
+ * Generate chat completions with AI Search context.
3901
+ * @param params Chat completions request with optional streaming
3902
+ * @returns Response object (if streaming) or chat completion result
3903
+ */
3904
+ chatCompletions(
3905
+ params: AiSearchChatCompletionsRequest,
3906
+ ): Promise<Response | object>;
3907
+ /**
3908
+ * Delete this AI Search instance.
3909
+ */
3910
+ delete(): Promise<void>;
3911
+ }
3912
+ // AI Search Account Service - Account-level operations
3913
+ export declare abstract class AiSearchAccountService {
3914
+ /**
3915
+ * List all AI Search instances in the account.
3916
+ * @returns Array of AI Search instances
3917
+ */
3918
+ list(): Promise<AiSearchListResponse>;
3919
+ /**
3920
+ * Get an AI Search instance by ID.
3921
+ * @param name Instance ID
3922
+ * @returns Instance service for performing operations
3923
+ */
3924
+ get(name: string): AiSearchInstanceService;
3925
+ /**
3926
+ * Create a new AI Search instance.
3927
+ * @param config Instance configuration
3928
+ * @returns Instance service for performing operations
3929
+ */
3930
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3931
+ }
3754
3932
  export type AiImageClassificationInput = {
3755
3933
  image: number[];
3756
3934
  };
@@ -9251,6 +9429,48 @@ export declare abstract class Ai<
9251
9429
  > {
9252
9430
  aiGatewayLogId: string | null;
9253
9431
  gateway(gatewayId: string): AiGateway;
9432
+ /**
9433
+ * Access the AI Search API for managing AI-powered search instances.
9434
+ *
9435
+ * This is the new API that replaces AutoRAG with better namespace separation:
9436
+ * - Account-level operations: `list()`, `create()`
9437
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9438
+ *
9439
+ * @example
9440
+ * ```typescript
9441
+ * // List all AI Search instances
9442
+ * const instances = await env.AI.aiSearch.list();
9443
+ *
9444
+ * // Search an instance
9445
+ * const results = await env.AI.aiSearch.get('my-search').search({
9446
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9447
+ * ai_search_options: {
9448
+ * retrieval: { max_num_results: 10 }
9449
+ * }
9450
+ * });
9451
+ *
9452
+ * // Generate chat completions with AI Search context
9453
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9454
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9455
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9456
+ * });
9457
+ * ```
9458
+ */
9459
+ aiSearch: AiSearchAccountService;
9460
+ /**
9461
+ * @deprecated AutoRAG has been replaced by AI Search.
9462
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9463
+ *
9464
+ * Migration guide:
9465
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9466
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9467
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9468
+ *
9469
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9470
+ *
9471
+ * @see AiSearchAccountService
9472
+ * @param autoragId Optional instance ID (omit for account-level operations)
9473
+ */
9254
9474
  autorag(autoragId: string): AutoRAG;
9255
9475
  run<
9256
9476
  Name extends keyof AiModelList,
@@ -9407,19 +9627,30 @@ export declare abstract class AiGateway {
9407
9627
  ): Promise<Response>;
9408
9628
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9409
9629
  }
9630
+ /**
9631
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9632
+ * @see AiSearchInternalError
9633
+ */
9410
9634
  export interface AutoRAGInternalError extends Error {}
9635
+ /**
9636
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9637
+ * @see AiSearchNotFoundError
9638
+ */
9411
9639
  export interface AutoRAGNotFoundError extends Error {}
9640
+ /**
9641
+ * @deprecated This error type is no longer used in the AI Search API.
9642
+ */
9412
9643
  export interface AutoRAGUnauthorizedError extends Error {}
9644
+ /**
9645
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9646
+ * @see AiSearchNameNotSetError
9647
+ */
9413
9648
  export interface AutoRAGNameNotSetError extends Error {}
9414
- export type ComparisonFilter = {
9415
- key: string;
9416
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9417
- value: string | number | boolean;
9418
- };
9419
- export type CompoundFilter = {
9420
- type: "and" | "or";
9421
- filters: ComparisonFilter[];
9422
- };
9649
+ /**
9650
+ * @deprecated AutoRAG has been replaced by AI Search.
9651
+ * Use AiSearchSearchRequest with the new API instead.
9652
+ * @see AiSearchSearchRequest
9653
+ */
9423
9654
  export type AutoRagSearchRequest = {
9424
9655
  query: string;
9425
9656
  filters?: CompoundFilter | ComparisonFilter;
@@ -9434,16 +9665,31 @@ export type AutoRagSearchRequest = {
9434
9665
  };
9435
9666
  rewrite_query?: boolean;
9436
9667
  };
9668
+ /**
9669
+ * @deprecated AutoRAG has been replaced by AI Search.
9670
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9671
+ * @see AiSearchChatCompletionsRequest
9672
+ */
9437
9673
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9438
9674
  stream?: boolean;
9439
9675
  system_prompt?: string;
9440
9676
  };
9677
+ /**
9678
+ * @deprecated AutoRAG has been replaced by AI Search.
9679
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9680
+ * @see AiSearchChatCompletionsRequest
9681
+ */
9441
9682
  export type AutoRagAiSearchRequestStreaming = Omit<
9442
9683
  AutoRagAiSearchRequest,
9443
9684
  "stream"
9444
9685
  > & {
9445
9686
  stream: true;
9446
9687
  };
9688
+ /**
9689
+ * @deprecated AutoRAG has been replaced by AI Search.
9690
+ * Use AiSearchSearchResponse with the new API instead.
9691
+ * @see AiSearchSearchResponse
9692
+ */
9447
9693
  export type AutoRagSearchResponse = {
9448
9694
  object: "vector_store.search_results.page";
9449
9695
  search_query: string;
@@ -9460,6 +9706,11 @@ export type AutoRagSearchResponse = {
9460
9706
  has_more: boolean;
9461
9707
  next_page: string | null;
9462
9708
  };
9709
+ /**
9710
+ * @deprecated AutoRAG has been replaced by AI Search.
9711
+ * Use AiSearchListResponse with the new API instead.
9712
+ * @see AiSearchListResponse
9713
+ */
9463
9714
  export type AutoRagListResponse = {
9464
9715
  id: string;
9465
9716
  enable: boolean;
@@ -9469,14 +9720,51 @@ export type AutoRagListResponse = {
9469
9720
  paused: boolean;
9470
9721
  status: string;
9471
9722
  }[];
9723
+ /**
9724
+ * @deprecated AutoRAG has been replaced by AI Search.
9725
+ * The new API returns different response formats for chat completions.
9726
+ */
9472
9727
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9473
9728
  response: string;
9474
9729
  };
9730
+ /**
9731
+ * @deprecated AutoRAG has been replaced by AI Search.
9732
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9733
+ *
9734
+ * Migration guide:
9735
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9736
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9737
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9738
+ *
9739
+ * @see AiSearchAccountService
9740
+ * @see AiSearchInstanceService
9741
+ */
9475
9742
  export declare abstract class AutoRAG {
9743
+ /**
9744
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9745
+ * @see AiSearchAccountService.list
9746
+ */
9476
9747
  list(): Promise<AutoRagListResponse>;
9748
+ /**
9749
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9750
+ * Note: The new API uses a messages array instead of a query string.
9751
+ * @see AiSearchInstanceService.search
9752
+ */
9477
9753
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9754
+ /**
9755
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9756
+ * @see AiSearchInstanceService.chatCompletions
9757
+ */
9478
9758
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9759
+ /**
9760
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9761
+ * @see AiSearchInstanceService.chatCompletions
9762
+ */
9479
9763
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9764
+ /**
9765
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9766
+ * @see AiSearchInstanceService.chatCompletions
9767
+ */
9480
9768
  aiSearch(
9481
9769
  params: AutoRagAiSearchRequest,
9482
9770
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10967,8 +11255,14 @@ export interface MediaTransformer {
10967
11255
  * @returns A generator for producing the transformed media output
10968
11256
  */
10969
11257
  transform(
10970
- transform: MediaTransformationInputOptions,
11258
+ transform?: MediaTransformationInputOptions,
10971
11259
  ): MediaTransformationGenerator;
11260
+ /**
11261
+ * Generates the final media output with specified options.
11262
+ * @param output - Configuration for the output format and parameters
11263
+ * @returns The final transformation result containing the transformed media
11264
+ */
11265
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10972
11266
  }
10973
11267
  /**
10974
11268
  * Generator for producing media transformation results.
@@ -10980,7 +11274,7 @@ export interface MediaTransformationGenerator {
10980
11274
  * @param output - Configuration for the output format and parameters
10981
11275
  * @returns The final transformation result containing the transformed media
10982
11276
  */
10983
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11277
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10984
11278
  }
10985
11279
  /**
10986
11280
  * Result of a media transformation operation.
@@ -10989,19 +11283,19 @@ export interface MediaTransformationGenerator {
10989
11283
  export interface MediaTransformationResult {
10990
11284
  /**
10991
11285
  * Returns the transformed media as a readable stream of bytes.
10992
- * @returns A stream containing the transformed media data
11286
+ * @returns A promise containing a readable stream with the transformed media
10993
11287
  */
10994
- media(): ReadableStream<Uint8Array>;
11288
+ media(): Promise<ReadableStream<Uint8Array>>;
10995
11289
  /**
10996
11290
  * Returns the transformed media as an HTTP response object.
10997
- * @returns The transformed media as a Response, ready to store in cache or return to users
11291
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
10998
11292
  */
10999
- response(): Response;
11293
+ response(): Promise<Response>;
11000
11294
  /**
11001
11295
  * Returns the MIME type of the transformed media.
11002
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11296
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11003
11297
  */
11004
- contentType(): string;
11298
+ contentType(): Promise<string>;
11005
11299
  }
11006
11300
  /**
11007
11301
  * Configuration options for transforming media input.