@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.
@@ -3848,6 +3848,190 @@ declare abstract class Performance {
3848
3848
  get timeOrigin(): number;
3849
3849
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3850
3850
  now(): number;
3851
+ /**
3852
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3853
+ *
3854
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3855
+ */
3856
+ toJSON(): object;
3857
+ }
3858
+ // AI Search V2 API Error Interfaces
3859
+ interface AiSearchInternalError extends Error {}
3860
+ interface AiSearchNotFoundError extends Error {}
3861
+ interface AiSearchNameNotSetError extends Error {}
3862
+ // Filter types (shared with AutoRAG for compatibility)
3863
+ type ComparisonFilter = {
3864
+ key: string;
3865
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3866
+ value: string | number | boolean;
3867
+ };
3868
+ type CompoundFilter = {
3869
+ type: "and" | "or";
3870
+ filters: ComparisonFilter[];
3871
+ };
3872
+ // AI Search V2 Request Types
3873
+ type AiSearchSearchRequest = {
3874
+ messages: Array<{
3875
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3876
+ content: string | null;
3877
+ }>;
3878
+ ai_search_options?: {
3879
+ retrieval?: {
3880
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3881
+ /** Match threshold (0-1, default 0.4) */
3882
+ match_threshold?: number;
3883
+ /** Maximum number of results (1-50, default 10) */
3884
+ max_num_results?: number;
3885
+ filters?: CompoundFilter | ComparisonFilter;
3886
+ /** Context expansion (0-3, default 0) */
3887
+ context_expansion?: number;
3888
+ [key: string]: unknown;
3889
+ };
3890
+ query_rewrite?: {
3891
+ enabled?: boolean;
3892
+ model?: string;
3893
+ rewrite_prompt?: string;
3894
+ [key: string]: unknown;
3895
+ };
3896
+ reranking?: {
3897
+ /** Enable reranking (default false) */
3898
+ enabled?: boolean;
3899
+ model?: "@cf/baai/bge-reranker-base" | "";
3900
+ /** Match threshold (0-1, default 0.4) */
3901
+ match_threshold?: number;
3902
+ [key: string]: unknown;
3903
+ };
3904
+ [key: string]: unknown;
3905
+ };
3906
+ };
3907
+ type AiSearchChatCompletionsRequest = {
3908
+ messages: Array<{
3909
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3910
+ content: string | null;
3911
+ }>;
3912
+ model?: string;
3913
+ stream?: boolean;
3914
+ ai_search_options?: {
3915
+ retrieval?: {
3916
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3917
+ match_threshold?: number;
3918
+ max_num_results?: number;
3919
+ filters?: CompoundFilter | ComparisonFilter;
3920
+ context_expansion?: number;
3921
+ [key: string]: unknown;
3922
+ };
3923
+ query_rewrite?: {
3924
+ enabled?: boolean;
3925
+ model?: string;
3926
+ rewrite_prompt?: string;
3927
+ [key: string]: unknown;
3928
+ };
3929
+ reranking?: {
3930
+ enabled?: boolean;
3931
+ model?: "@cf/baai/bge-reranker-base" | "";
3932
+ match_threshold?: number;
3933
+ [key: string]: unknown;
3934
+ };
3935
+ [key: string]: unknown;
3936
+ };
3937
+ [key: string]: unknown;
3938
+ };
3939
+ // AI Search V2 Response Types
3940
+ type AiSearchSearchResponse = {
3941
+ search_query: string;
3942
+ chunks: Array<{
3943
+ id: string;
3944
+ type: string;
3945
+ /** Match score (0-1) */
3946
+ score: number;
3947
+ text: string;
3948
+ item: {
3949
+ timestamp?: number;
3950
+ key: string;
3951
+ metadata?: Record<string, unknown>;
3952
+ };
3953
+ scoring_details?: {
3954
+ /** Keyword match score (0-1) */
3955
+ keyword_score?: number;
3956
+ /** Vector similarity score (0-1) */
3957
+ vector_score?: number;
3958
+ };
3959
+ }>;
3960
+ };
3961
+ type AiSearchListResponse = Array<{
3962
+ id: string;
3963
+ internal_id?: string;
3964
+ account_id?: string;
3965
+ account_tag?: string;
3966
+ /** Whether the instance is enabled (default true) */
3967
+ enable?: boolean;
3968
+ type?: "r2" | "web-crawler";
3969
+ source?: string;
3970
+ [key: string]: unknown;
3971
+ }>;
3972
+ type AiSearchConfig = {
3973
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3974
+ id: string;
3975
+ type: "r2" | "web-crawler";
3976
+ source: string;
3977
+ source_params?: object;
3978
+ /** Token ID (UUID format) */
3979
+ token_id?: string;
3980
+ ai_gateway_id?: string;
3981
+ /** Enable query rewriting (default false) */
3982
+ rewrite_query?: boolean;
3983
+ /** Enable reranking (default false) */
3984
+ reranking?: boolean;
3985
+ embedding_model?: string;
3986
+ ai_search_model?: string;
3987
+ };
3988
+ type AiSearchInstance = {
3989
+ id: string;
3990
+ enable?: boolean;
3991
+ type?: "r2" | "web-crawler";
3992
+ source?: string;
3993
+ [key: string]: unknown;
3994
+ };
3995
+ // AI Search Instance Service - Instance-level operations
3996
+ declare abstract class AiSearchInstanceService {
3997
+ /**
3998
+ * Search the AI Search instance for relevant chunks.
3999
+ * @param params Search request with messages and AI search options
4000
+ * @returns Search response with matching chunks
4001
+ */
4002
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4003
+ /**
4004
+ * Generate chat completions with AI Search context.
4005
+ * @param params Chat completions request with optional streaming
4006
+ * @returns Response object (if streaming) or chat completion result
4007
+ */
4008
+ chatCompletions(
4009
+ params: AiSearchChatCompletionsRequest,
4010
+ ): Promise<Response | object>;
4011
+ /**
4012
+ * Delete this AI Search instance.
4013
+ */
4014
+ delete(): Promise<void>;
4015
+ }
4016
+ // AI Search Account Service - Account-level operations
4017
+ declare abstract class AiSearchAccountService {
4018
+ /**
4019
+ * List all AI Search instances in the account.
4020
+ * @returns Array of AI Search instances
4021
+ */
4022
+ list(): Promise<AiSearchListResponse>;
4023
+ /**
4024
+ * Get an AI Search instance by ID.
4025
+ * @param name Instance ID
4026
+ * @returns Instance service for performing operations
4027
+ */
4028
+ get(name: string): AiSearchInstanceService;
4029
+ /**
4030
+ * Create a new AI Search instance.
4031
+ * @param config Instance configuration
4032
+ * @returns Instance service for performing operations
4033
+ */
4034
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3851
4035
  }
3852
4036
  type AiImageClassificationInput = {
3853
4037
  image: number[];
@@ -9346,6 +9530,48 @@ type AiModelListType = Record<string, any>;
9346
9530
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9347
9531
  aiGatewayLogId: string | null;
9348
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
+ */
9349
9575
  autorag(autoragId: string): AutoRAG;
9350
9576
  run<
9351
9577
  Name extends keyof AiModelList,
@@ -9502,19 +9728,30 @@ declare abstract class AiGateway {
9502
9728
  ): Promise<Response>;
9503
9729
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9504
9730
  }
9731
+ /**
9732
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9733
+ * @see AiSearchInternalError
9734
+ */
9505
9735
  interface AutoRAGInternalError extends Error {}
9736
+ /**
9737
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9738
+ * @see AiSearchNotFoundError
9739
+ */
9506
9740
  interface AutoRAGNotFoundError extends Error {}
9741
+ /**
9742
+ * @deprecated This error type is no longer used in the AI Search API.
9743
+ */
9507
9744
  interface AutoRAGUnauthorizedError extends Error {}
9745
+ /**
9746
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9747
+ * @see AiSearchNameNotSetError
9748
+ */
9508
9749
  interface AutoRAGNameNotSetError extends Error {}
9509
- type ComparisonFilter = {
9510
- key: string;
9511
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9512
- value: string | number | boolean;
9513
- };
9514
- type CompoundFilter = {
9515
- type: "and" | "or";
9516
- filters: ComparisonFilter[];
9517
- };
9750
+ /**
9751
+ * @deprecated AutoRAG has been replaced by AI Search.
9752
+ * Use AiSearchSearchRequest with the new API instead.
9753
+ * @see AiSearchSearchRequest
9754
+ */
9518
9755
  type AutoRagSearchRequest = {
9519
9756
  query: string;
9520
9757
  filters?: CompoundFilter | ComparisonFilter;
@@ -9529,16 +9766,31 @@ type AutoRagSearchRequest = {
9529
9766
  };
9530
9767
  rewrite_query?: boolean;
9531
9768
  };
9769
+ /**
9770
+ * @deprecated AutoRAG has been replaced by AI Search.
9771
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9772
+ * @see AiSearchChatCompletionsRequest
9773
+ */
9532
9774
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9533
9775
  stream?: boolean;
9534
9776
  system_prompt?: string;
9535
9777
  };
9778
+ /**
9779
+ * @deprecated AutoRAG has been replaced by AI Search.
9780
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9781
+ * @see AiSearchChatCompletionsRequest
9782
+ */
9536
9783
  type AutoRagAiSearchRequestStreaming = Omit<
9537
9784
  AutoRagAiSearchRequest,
9538
9785
  "stream"
9539
9786
  > & {
9540
9787
  stream: true;
9541
9788
  };
9789
+ /**
9790
+ * @deprecated AutoRAG has been replaced by AI Search.
9791
+ * Use AiSearchSearchResponse with the new API instead.
9792
+ * @see AiSearchSearchResponse
9793
+ */
9542
9794
  type AutoRagSearchResponse = {
9543
9795
  object: "vector_store.search_results.page";
9544
9796
  search_query: string;
@@ -9555,6 +9807,11 @@ type AutoRagSearchResponse = {
9555
9807
  has_more: boolean;
9556
9808
  next_page: string | null;
9557
9809
  };
9810
+ /**
9811
+ * @deprecated AutoRAG has been replaced by AI Search.
9812
+ * Use AiSearchListResponse with the new API instead.
9813
+ * @see AiSearchListResponse
9814
+ */
9558
9815
  type AutoRagListResponse = {
9559
9816
  id: string;
9560
9817
  enable: boolean;
@@ -9564,14 +9821,51 @@ type AutoRagListResponse = {
9564
9821
  paused: boolean;
9565
9822
  status: string;
9566
9823
  }[];
9824
+ /**
9825
+ * @deprecated AutoRAG has been replaced by AI Search.
9826
+ * The new API returns different response formats for chat completions.
9827
+ */
9567
9828
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9568
9829
  response: string;
9569
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
+ */
9570
9843
  declare abstract class AutoRAG {
9844
+ /**
9845
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9846
+ * @see AiSearchAccountService.list
9847
+ */
9571
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
+ */
9572
9854
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9855
+ /**
9856
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9857
+ * @see AiSearchInstanceService.chatCompletions
9858
+ */
9573
9859
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9860
+ /**
9861
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9862
+ * @see AiSearchInstanceService.chatCompletions
9863
+ */
9574
9864
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9865
+ /**
9866
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9867
+ * @see AiSearchInstanceService.chatCompletions
9868
+ */
9575
9869
  aiSearch(
9576
9870
  params: AutoRagAiSearchRequest,
9577
9871
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10968,6 +11262,86 @@ type ImageOutputOptions = {
10968
11262
  background?: string;
10969
11263
  anim?: boolean;
10970
11264
  };
11265
+ interface ImageMetadata {
11266
+ id: string;
11267
+ filename?: string;
11268
+ uploaded?: string;
11269
+ requireSignedURLs: boolean;
11270
+ meta?: Record<string, unknown>;
11271
+ variants: string[];
11272
+ draft?: boolean;
11273
+ creator?: string;
11274
+ }
11275
+ interface ImageUploadOptions {
11276
+ id?: string;
11277
+ filename?: string;
11278
+ requireSignedURLs?: boolean;
11279
+ metadata?: Record<string, unknown>;
11280
+ creator?: string;
11281
+ encoding?: "base64";
11282
+ }
11283
+ interface ImageUpdateOptions {
11284
+ requireSignedURLs?: boolean;
11285
+ metadata?: Record<string, unknown>;
11286
+ creator?: string;
11287
+ }
11288
+ interface ImageListOptions {
11289
+ limit?: number;
11290
+ cursor?: string;
11291
+ sortOrder?: "asc" | "desc";
11292
+ creator?: string;
11293
+ }
11294
+ interface ImageList {
11295
+ images: ImageMetadata[];
11296
+ cursor?: string;
11297
+ listComplete: boolean;
11298
+ }
11299
+ interface HostedImagesBinding {
11300
+ /**
11301
+ * Get detailed metadata for a hosted image
11302
+ * @param imageId The ID of the image (UUID or custom ID)
11303
+ * @returns Image metadata, or null if not found
11304
+ */
11305
+ details(imageId: string): Promise<ImageMetadata | null>;
11306
+ /**
11307
+ * Get the raw image data for a hosted image
11308
+ * @param imageId The ID of the image (UUID or custom ID)
11309
+ * @returns ReadableStream of image bytes, or null if not found
11310
+ */
11311
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11312
+ /**
11313
+ * Upload a new hosted image
11314
+ * @param image The image file to upload
11315
+ * @param options Upload configuration
11316
+ * @returns Metadata for the uploaded image
11317
+ * @throws {@link ImagesError} if upload fails
11318
+ */
11319
+ upload(
11320
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11321
+ options?: ImageUploadOptions,
11322
+ ): Promise<ImageMetadata>;
11323
+ /**
11324
+ * Update hosted image metadata
11325
+ * @param imageId The ID of the image
11326
+ * @param options Properties to update
11327
+ * @returns Updated image metadata
11328
+ * @throws {@link ImagesError} if update fails
11329
+ */
11330
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11331
+ /**
11332
+ * Delete a hosted image
11333
+ * @param imageId The ID of the image
11334
+ * @returns True if deleted, false if not found
11335
+ */
11336
+ delete(imageId: string): Promise<boolean>;
11337
+ /**
11338
+ * List hosted images with pagination
11339
+ * @param options List configuration
11340
+ * @returns List of images with pagination info
11341
+ * @throws {@link ImagesError} if list fails
11342
+ */
11343
+ list(options?: ImageListOptions): Promise<ImageList>;
11344
+ }
10971
11345
  interface ImagesBinding {
10972
11346
  /**
10973
11347
  * Get image metadata (type, width and height)
@@ -10987,6 +11361,10 @@ interface ImagesBinding {
10987
11361
  stream: ReadableStream<Uint8Array>,
10988
11362
  options?: ImageInputOptions,
10989
11363
  ): ImageTransformer;
11364
+ /**
11365
+ * Access hosted images CRUD operations
11366
+ */
11367
+ readonly hosted: HostedImagesBinding;
10990
11368
  }
10991
11369
  interface ImageTransformer {
10992
11370
  /**
@@ -11057,8 +11435,14 @@ interface MediaTransformer {
11057
11435
  * @returns A generator for producing the transformed media output
11058
11436
  */
11059
11437
  transform(
11060
- transform: MediaTransformationInputOptions,
11438
+ transform?: MediaTransformationInputOptions,
11061
11439
  ): MediaTransformationGenerator;
11440
+ /**
11441
+ * Generates the final media output with specified options.
11442
+ * @param output - Configuration for the output format and parameters
11443
+ * @returns The final transformation result containing the transformed media
11444
+ */
11445
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11062
11446
  }
11063
11447
  /**
11064
11448
  * Generator for producing media transformation results.
@@ -11070,7 +11454,7 @@ interface MediaTransformationGenerator {
11070
11454
  * @param output - Configuration for the output format and parameters
11071
11455
  * @returns The final transformation result containing the transformed media
11072
11456
  */
11073
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11457
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11074
11458
  }
11075
11459
  /**
11076
11460
  * Result of a media transformation operation.
@@ -11079,19 +11463,19 @@ interface MediaTransformationGenerator {
11079
11463
  interface MediaTransformationResult {
11080
11464
  /**
11081
11465
  * Returns the transformed media as a readable stream of bytes.
11082
- * @returns A stream containing the transformed media data
11466
+ * @returns A promise containing a readable stream with the transformed media
11083
11467
  */
11084
- media(): ReadableStream<Uint8Array>;
11468
+ media(): Promise<ReadableStream<Uint8Array>>;
11085
11469
  /**
11086
11470
  * Returns the transformed media as an HTTP response object.
11087
- * @returns The transformed media as a Response, ready to store in cache or return to users
11471
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11088
11472
  */
11089
- response(): Response;
11473
+ response(): Promise<Response>;
11090
11474
  /**
11091
11475
  * Returns the MIME type of the transformed media.
11092
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11476
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11093
11477
  */
11094
- contentType(): string;
11478
+ contentType(): Promise<string>;
11095
11479
  }
11096
11480
  /**
11097
11481
  * Configuration options for transforming media input.