@cloudflare/workers-types 4.20260227.0 → 4.20260228.1

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.
@@ -3817,6 +3817,190 @@ export declare abstract class Performance {
3817
3817
  get timeOrigin(): number;
3818
3818
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3819
3819
  now(): number;
3820
+ /**
3821
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3822
+ *
3823
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3824
+ */
3825
+ toJSON(): object;
3826
+ }
3827
+ // AI Search V2 API Error Interfaces
3828
+ export interface AiSearchInternalError extends Error {}
3829
+ export interface AiSearchNotFoundError extends Error {}
3830
+ export interface AiSearchNameNotSetError extends Error {}
3831
+ // Filter types (shared with AutoRAG for compatibility)
3832
+ export type ComparisonFilter = {
3833
+ key: string;
3834
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3835
+ value: string | number | boolean;
3836
+ };
3837
+ export type CompoundFilter = {
3838
+ type: "and" | "or";
3839
+ filters: ComparisonFilter[];
3840
+ };
3841
+ // AI Search V2 Request Types
3842
+ export type AiSearchSearchRequest = {
3843
+ messages: Array<{
3844
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3845
+ content: string | null;
3846
+ }>;
3847
+ ai_search_options?: {
3848
+ retrieval?: {
3849
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3850
+ /** Match threshold (0-1, default 0.4) */
3851
+ match_threshold?: number;
3852
+ /** Maximum number of results (1-50, default 10) */
3853
+ max_num_results?: number;
3854
+ filters?: CompoundFilter | ComparisonFilter;
3855
+ /** Context expansion (0-3, default 0) */
3856
+ context_expansion?: number;
3857
+ [key: string]: unknown;
3858
+ };
3859
+ query_rewrite?: {
3860
+ enabled?: boolean;
3861
+ model?: string;
3862
+ rewrite_prompt?: string;
3863
+ [key: string]: unknown;
3864
+ };
3865
+ reranking?: {
3866
+ /** Enable reranking (default false) */
3867
+ enabled?: boolean;
3868
+ model?: "@cf/baai/bge-reranker-base" | "";
3869
+ /** Match threshold (0-1, default 0.4) */
3870
+ match_threshold?: number;
3871
+ [key: string]: unknown;
3872
+ };
3873
+ [key: string]: unknown;
3874
+ };
3875
+ };
3876
+ export type AiSearchChatCompletionsRequest = {
3877
+ messages: Array<{
3878
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3879
+ content: string | null;
3880
+ }>;
3881
+ model?: string;
3882
+ stream?: boolean;
3883
+ ai_search_options?: {
3884
+ retrieval?: {
3885
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3886
+ match_threshold?: number;
3887
+ max_num_results?: number;
3888
+ filters?: CompoundFilter | ComparisonFilter;
3889
+ context_expansion?: number;
3890
+ [key: string]: unknown;
3891
+ };
3892
+ query_rewrite?: {
3893
+ enabled?: boolean;
3894
+ model?: string;
3895
+ rewrite_prompt?: string;
3896
+ [key: string]: unknown;
3897
+ };
3898
+ reranking?: {
3899
+ enabled?: boolean;
3900
+ model?: "@cf/baai/bge-reranker-base" | "";
3901
+ match_threshold?: number;
3902
+ [key: string]: unknown;
3903
+ };
3904
+ [key: string]: unknown;
3905
+ };
3906
+ [key: string]: unknown;
3907
+ };
3908
+ // AI Search V2 Response Types
3909
+ export type AiSearchSearchResponse = {
3910
+ search_query: string;
3911
+ chunks: Array<{
3912
+ id: string;
3913
+ type: string;
3914
+ /** Match score (0-1) */
3915
+ score: number;
3916
+ text: string;
3917
+ item: {
3918
+ timestamp?: number;
3919
+ key: string;
3920
+ metadata?: Record<string, unknown>;
3921
+ };
3922
+ scoring_details?: {
3923
+ /** Keyword match score (0-1) */
3924
+ keyword_score?: number;
3925
+ /** Vector similarity score (0-1) */
3926
+ vector_score?: number;
3927
+ };
3928
+ }>;
3929
+ };
3930
+ export type AiSearchListResponse = Array<{
3931
+ id: string;
3932
+ internal_id?: string;
3933
+ account_id?: string;
3934
+ account_tag?: string;
3935
+ /** Whether the instance is enabled (default true) */
3936
+ enable?: boolean;
3937
+ type?: "r2" | "web-crawler";
3938
+ source?: string;
3939
+ [key: string]: unknown;
3940
+ }>;
3941
+ export type AiSearchConfig = {
3942
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3943
+ id: string;
3944
+ type: "r2" | "web-crawler";
3945
+ source: string;
3946
+ source_params?: object;
3947
+ /** Token ID (UUID format) */
3948
+ token_id?: string;
3949
+ ai_gateway_id?: string;
3950
+ /** Enable query rewriting (default false) */
3951
+ rewrite_query?: boolean;
3952
+ /** Enable reranking (default false) */
3953
+ reranking?: boolean;
3954
+ embedding_model?: string;
3955
+ ai_search_model?: string;
3956
+ };
3957
+ export type AiSearchInstance = {
3958
+ id: string;
3959
+ enable?: boolean;
3960
+ type?: "r2" | "web-crawler";
3961
+ source?: string;
3962
+ [key: string]: unknown;
3963
+ };
3964
+ // AI Search Instance Service - Instance-level operations
3965
+ export declare abstract class AiSearchInstanceService {
3966
+ /**
3967
+ * Search the AI Search instance for relevant chunks.
3968
+ * @param params Search request with messages and AI search options
3969
+ * @returns Search response with matching chunks
3970
+ */
3971
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3972
+ /**
3973
+ * Generate chat completions with AI Search context.
3974
+ * @param params Chat completions request with optional streaming
3975
+ * @returns Response object (if streaming) or chat completion result
3976
+ */
3977
+ chatCompletions(
3978
+ params: AiSearchChatCompletionsRequest,
3979
+ ): Promise<Response | object>;
3980
+ /**
3981
+ * Delete this AI Search instance.
3982
+ */
3983
+ delete(): Promise<void>;
3984
+ }
3985
+ // AI Search Account Service - Account-level operations
3986
+ export declare abstract class AiSearchAccountService {
3987
+ /**
3988
+ * List all AI Search instances in the account.
3989
+ * @returns Array of AI Search instances
3990
+ */
3991
+ list(): Promise<AiSearchListResponse>;
3992
+ /**
3993
+ * Get an AI Search instance by ID.
3994
+ * @param name Instance ID
3995
+ * @returns Instance service for performing operations
3996
+ */
3997
+ get(name: string): AiSearchInstanceService;
3998
+ /**
3999
+ * Create a new AI Search instance.
4000
+ * @param config Instance configuration
4001
+ * @returns Instance service for performing operations
4002
+ */
4003
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3820
4004
  }
3821
4005
  export type AiImageClassificationInput = {
3822
4006
  image: number[];
@@ -9318,6 +9502,48 @@ export declare abstract class Ai<
9318
9502
  > {
9319
9503
  aiGatewayLogId: string | null;
9320
9504
  gateway(gatewayId: string): AiGateway;
9505
+ /**
9506
+ * Access the AI Search API for managing AI-powered search instances.
9507
+ *
9508
+ * This is the new API that replaces AutoRAG with better namespace separation:
9509
+ * - Account-level operations: `list()`, `create()`
9510
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9511
+ *
9512
+ * @example
9513
+ * ```typescript
9514
+ * // List all AI Search instances
9515
+ * const instances = await env.AI.aiSearch.list();
9516
+ *
9517
+ * // Search an instance
9518
+ * const results = await env.AI.aiSearch.get('my-search').search({
9519
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9520
+ * ai_search_options: {
9521
+ * retrieval: { max_num_results: 10 }
9522
+ * }
9523
+ * });
9524
+ *
9525
+ * // Generate chat completions with AI Search context
9526
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9527
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9528
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9529
+ * });
9530
+ * ```
9531
+ */
9532
+ aiSearch(): AiSearchAccountService;
9533
+ /**
9534
+ * @deprecated AutoRAG has been replaced by AI Search.
9535
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9536
+ *
9537
+ * Migration guide:
9538
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9539
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9540
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9541
+ *
9542
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9543
+ *
9544
+ * @see AiSearchAccountService
9545
+ * @param autoragId Optional instance ID (omit for account-level operations)
9546
+ */
9321
9547
  autorag(autoragId: string): AutoRAG;
9322
9548
  run<
9323
9549
  Name extends keyof AiModelList,
@@ -9474,19 +9700,30 @@ export declare abstract class AiGateway {
9474
9700
  ): Promise<Response>;
9475
9701
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9476
9702
  }
9703
+ /**
9704
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9705
+ * @see AiSearchInternalError
9706
+ */
9477
9707
  export interface AutoRAGInternalError extends Error {}
9708
+ /**
9709
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9710
+ * @see AiSearchNotFoundError
9711
+ */
9478
9712
  export interface AutoRAGNotFoundError extends Error {}
9713
+ /**
9714
+ * @deprecated This error type is no longer used in the AI Search API.
9715
+ */
9479
9716
  export interface AutoRAGUnauthorizedError extends Error {}
9717
+ /**
9718
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9719
+ * @see AiSearchNameNotSetError
9720
+ */
9480
9721
  export interface AutoRAGNameNotSetError extends Error {}
9481
- export type ComparisonFilter = {
9482
- key: string;
9483
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9484
- value: string | number | boolean;
9485
- };
9486
- export type CompoundFilter = {
9487
- type: "and" | "or";
9488
- filters: ComparisonFilter[];
9489
- };
9722
+ /**
9723
+ * @deprecated AutoRAG has been replaced by AI Search.
9724
+ * Use AiSearchSearchRequest with the new API instead.
9725
+ * @see AiSearchSearchRequest
9726
+ */
9490
9727
  export type AutoRagSearchRequest = {
9491
9728
  query: string;
9492
9729
  filters?: CompoundFilter | ComparisonFilter;
@@ -9501,16 +9738,31 @@ export type AutoRagSearchRequest = {
9501
9738
  };
9502
9739
  rewrite_query?: boolean;
9503
9740
  };
9741
+ /**
9742
+ * @deprecated AutoRAG has been replaced by AI Search.
9743
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9744
+ * @see AiSearchChatCompletionsRequest
9745
+ */
9504
9746
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9505
9747
  stream?: boolean;
9506
9748
  system_prompt?: string;
9507
9749
  };
9750
+ /**
9751
+ * @deprecated AutoRAG has been replaced by AI Search.
9752
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9753
+ * @see AiSearchChatCompletionsRequest
9754
+ */
9508
9755
  export type AutoRagAiSearchRequestStreaming = Omit<
9509
9756
  AutoRagAiSearchRequest,
9510
9757
  "stream"
9511
9758
  > & {
9512
9759
  stream: true;
9513
9760
  };
9761
+ /**
9762
+ * @deprecated AutoRAG has been replaced by AI Search.
9763
+ * Use AiSearchSearchResponse with the new API instead.
9764
+ * @see AiSearchSearchResponse
9765
+ */
9514
9766
  export type AutoRagSearchResponse = {
9515
9767
  object: "vector_store.search_results.page";
9516
9768
  search_query: string;
@@ -9527,6 +9779,11 @@ export type AutoRagSearchResponse = {
9527
9779
  has_more: boolean;
9528
9780
  next_page: string | null;
9529
9781
  };
9782
+ /**
9783
+ * @deprecated AutoRAG has been replaced by AI Search.
9784
+ * Use AiSearchListResponse with the new API instead.
9785
+ * @see AiSearchListResponse
9786
+ */
9530
9787
  export type AutoRagListResponse = {
9531
9788
  id: string;
9532
9789
  enable: boolean;
@@ -9536,14 +9793,51 @@ export type AutoRagListResponse = {
9536
9793
  paused: boolean;
9537
9794
  status: string;
9538
9795
  }[];
9796
+ /**
9797
+ * @deprecated AutoRAG has been replaced by AI Search.
9798
+ * The new API returns different response formats for chat completions.
9799
+ */
9539
9800
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9540
9801
  response: string;
9541
9802
  };
9803
+ /**
9804
+ * @deprecated AutoRAG has been replaced by AI Search.
9805
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9806
+ *
9807
+ * Migration guide:
9808
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9809
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9810
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9811
+ *
9812
+ * @see AiSearchAccountService
9813
+ * @see AiSearchInstanceService
9814
+ */
9542
9815
  export declare abstract class AutoRAG {
9816
+ /**
9817
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9818
+ * @see AiSearchAccountService.list
9819
+ */
9543
9820
  list(): Promise<AutoRagListResponse>;
9821
+ /**
9822
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9823
+ * Note: The new API uses a messages array instead of a query string.
9824
+ * @see AiSearchInstanceService.search
9825
+ */
9544
9826
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9827
+ /**
9828
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9829
+ * @see AiSearchInstanceService.chatCompletions
9830
+ */
9545
9831
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9832
+ /**
9833
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9834
+ * @see AiSearchInstanceService.chatCompletions
9835
+ */
9546
9836
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9837
+ /**
9838
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9839
+ * @see AiSearchInstanceService.chatCompletions
9840
+ */
9547
9841
  aiSearch(
9548
9842
  params: AutoRagAiSearchRequest,
9549
9843
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10945,6 +11239,86 @@ export type ImageOutputOptions = {
10945
11239
  background?: string;
10946
11240
  anim?: boolean;
10947
11241
  };
11242
+ export interface ImageMetadata {
11243
+ id: string;
11244
+ filename?: string;
11245
+ uploaded?: string;
11246
+ requireSignedURLs: boolean;
11247
+ meta?: Record<string, unknown>;
11248
+ variants: string[];
11249
+ draft?: boolean;
11250
+ creator?: string;
11251
+ }
11252
+ export interface ImageUploadOptions {
11253
+ id?: string;
11254
+ filename?: string;
11255
+ requireSignedURLs?: boolean;
11256
+ metadata?: Record<string, unknown>;
11257
+ creator?: string;
11258
+ encoding?: "base64";
11259
+ }
11260
+ export interface ImageUpdateOptions {
11261
+ requireSignedURLs?: boolean;
11262
+ metadata?: Record<string, unknown>;
11263
+ creator?: string;
11264
+ }
11265
+ export interface ImageListOptions {
11266
+ limit?: number;
11267
+ cursor?: string;
11268
+ sortOrder?: "asc" | "desc";
11269
+ creator?: string;
11270
+ }
11271
+ export interface ImageList {
11272
+ images: ImageMetadata[];
11273
+ cursor?: string;
11274
+ listComplete: boolean;
11275
+ }
11276
+ export interface HostedImagesBinding {
11277
+ /**
11278
+ * Get detailed metadata for a hosted image
11279
+ * @param imageId The ID of the image (UUID or custom ID)
11280
+ * @returns Image metadata, or null if not found
11281
+ */
11282
+ details(imageId: string): Promise<ImageMetadata | null>;
11283
+ /**
11284
+ * Get the raw image data for a hosted image
11285
+ * @param imageId The ID of the image (UUID or custom ID)
11286
+ * @returns ReadableStream of image bytes, or null if not found
11287
+ */
11288
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11289
+ /**
11290
+ * Upload a new hosted image
11291
+ * @param image The image file to upload
11292
+ * @param options Upload configuration
11293
+ * @returns Metadata for the uploaded image
11294
+ * @throws {@link ImagesError} if upload fails
11295
+ */
11296
+ upload(
11297
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11298
+ options?: ImageUploadOptions,
11299
+ ): Promise<ImageMetadata>;
11300
+ /**
11301
+ * Update hosted image metadata
11302
+ * @param imageId The ID of the image
11303
+ * @param options Properties to update
11304
+ * @returns Updated image metadata
11305
+ * @throws {@link ImagesError} if update fails
11306
+ */
11307
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11308
+ /**
11309
+ * Delete a hosted image
11310
+ * @param imageId The ID of the image
11311
+ * @returns True if deleted, false if not found
11312
+ */
11313
+ delete(imageId: string): Promise<boolean>;
11314
+ /**
11315
+ * List hosted images with pagination
11316
+ * @param options List configuration
11317
+ * @returns List of images with pagination info
11318
+ * @throws {@link ImagesError} if list fails
11319
+ */
11320
+ list(options?: ImageListOptions): Promise<ImageList>;
11321
+ }
10948
11322
  export interface ImagesBinding {
10949
11323
  /**
10950
11324
  * Get image metadata (type, width and height)
@@ -10964,6 +11338,10 @@ export interface ImagesBinding {
10964
11338
  stream: ReadableStream<Uint8Array>,
10965
11339
  options?: ImageInputOptions,
10966
11340
  ): ImageTransformer;
11341
+ /**
11342
+ * Access hosted images CRUD operations
11343
+ */
11344
+ readonly hosted: HostedImagesBinding;
10967
11345
  }
10968
11346
  export interface ImageTransformer {
10969
11347
  /**
@@ -11034,8 +11412,14 @@ export interface MediaTransformer {
11034
11412
  * @returns A generator for producing the transformed media output
11035
11413
  */
11036
11414
  transform(
11037
- transform: MediaTransformationInputOptions,
11415
+ transform?: MediaTransformationInputOptions,
11038
11416
  ): MediaTransformationGenerator;
11417
+ /**
11418
+ * Generates the final media output with specified options.
11419
+ * @param output - Configuration for the output format and parameters
11420
+ * @returns The final transformation result containing the transformed media
11421
+ */
11422
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11039
11423
  }
11040
11424
  /**
11041
11425
  * Generator for producing media transformation results.
@@ -11047,7 +11431,7 @@ export interface MediaTransformationGenerator {
11047
11431
  * @param output - Configuration for the output format and parameters
11048
11432
  * @returns The final transformation result containing the transformed media
11049
11433
  */
11050
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11434
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11051
11435
  }
11052
11436
  /**
11053
11437
  * Result of a media transformation operation.
@@ -11056,19 +11440,19 @@ export interface MediaTransformationGenerator {
11056
11440
  export interface MediaTransformationResult {
11057
11441
  /**
11058
11442
  * Returns the transformed media as a readable stream of bytes.
11059
- * @returns A stream containing the transformed media data
11443
+ * @returns A promise containing a readable stream with the transformed media
11060
11444
  */
11061
- media(): ReadableStream<Uint8Array>;
11445
+ media(): Promise<ReadableStream<Uint8Array>>;
11062
11446
  /**
11063
11447
  * Returns the transformed media as an HTTP response object.
11064
- * @returns The transformed media as a Response, ready to store in cache or return to users
11448
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11065
11449
  */
11066
- response(): Response;
11450
+ response(): Promise<Response>;
11067
11451
  /**
11068
11452
  * Returns the MIME type of the transformed media.
11069
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11453
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11070
11454
  */
11071
- contentType(): string;
11455
+ contentType(): Promise<string>;
11072
11456
  }
11073
11457
  /**
11074
11458
  * Configuration options for transforming media input.