@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.
@@ -3750,6 +3750,190 @@ export declare abstract class Performance {
3750
3750
  get timeOrigin(): number;
3751
3751
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3752
3752
  now(): number;
3753
+ /**
3754
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3755
+ *
3756
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3757
+ */
3758
+ toJSON(): object;
3759
+ }
3760
+ // AI Search V2 API Error Interfaces
3761
+ export interface AiSearchInternalError extends Error {}
3762
+ export interface AiSearchNotFoundError extends Error {}
3763
+ export interface AiSearchNameNotSetError extends Error {}
3764
+ // Filter types (shared with AutoRAG for compatibility)
3765
+ export type ComparisonFilter = {
3766
+ key: string;
3767
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3768
+ value: string | number | boolean;
3769
+ };
3770
+ export type CompoundFilter = {
3771
+ type: "and" | "or";
3772
+ filters: ComparisonFilter[];
3773
+ };
3774
+ // AI Search V2 Request Types
3775
+ export type AiSearchSearchRequest = {
3776
+ messages: Array<{
3777
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3778
+ content: string | null;
3779
+ }>;
3780
+ ai_search_options?: {
3781
+ retrieval?: {
3782
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3783
+ /** Match threshold (0-1, default 0.4) */
3784
+ match_threshold?: number;
3785
+ /** Maximum number of results (1-50, default 10) */
3786
+ max_num_results?: number;
3787
+ filters?: CompoundFilter | ComparisonFilter;
3788
+ /** Context expansion (0-3, default 0) */
3789
+ context_expansion?: number;
3790
+ [key: string]: unknown;
3791
+ };
3792
+ query_rewrite?: {
3793
+ enabled?: boolean;
3794
+ model?: string;
3795
+ rewrite_prompt?: string;
3796
+ [key: string]: unknown;
3797
+ };
3798
+ reranking?: {
3799
+ /** Enable reranking (default false) */
3800
+ enabled?: boolean;
3801
+ model?: "@cf/baai/bge-reranker-base" | "";
3802
+ /** Match threshold (0-1, default 0.4) */
3803
+ match_threshold?: number;
3804
+ [key: string]: unknown;
3805
+ };
3806
+ [key: string]: unknown;
3807
+ };
3808
+ };
3809
+ export type AiSearchChatCompletionsRequest = {
3810
+ messages: Array<{
3811
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3812
+ content: string | null;
3813
+ }>;
3814
+ model?: string;
3815
+ stream?: boolean;
3816
+ ai_search_options?: {
3817
+ retrieval?: {
3818
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3819
+ match_threshold?: number;
3820
+ max_num_results?: number;
3821
+ filters?: CompoundFilter | ComparisonFilter;
3822
+ context_expansion?: number;
3823
+ [key: string]: unknown;
3824
+ };
3825
+ query_rewrite?: {
3826
+ enabled?: boolean;
3827
+ model?: string;
3828
+ rewrite_prompt?: string;
3829
+ [key: string]: unknown;
3830
+ };
3831
+ reranking?: {
3832
+ enabled?: boolean;
3833
+ model?: "@cf/baai/bge-reranker-base" | "";
3834
+ match_threshold?: number;
3835
+ [key: string]: unknown;
3836
+ };
3837
+ [key: string]: unknown;
3838
+ };
3839
+ [key: string]: unknown;
3840
+ };
3841
+ // AI Search V2 Response Types
3842
+ export type AiSearchSearchResponse = {
3843
+ search_query: string;
3844
+ chunks: Array<{
3845
+ id: string;
3846
+ type: string;
3847
+ /** Match score (0-1) */
3848
+ score: number;
3849
+ text: string;
3850
+ item: {
3851
+ timestamp?: number;
3852
+ key: string;
3853
+ metadata?: Record<string, unknown>;
3854
+ };
3855
+ scoring_details?: {
3856
+ /** Keyword match score (0-1) */
3857
+ keyword_score?: number;
3858
+ /** Vector similarity score (0-1) */
3859
+ vector_score?: number;
3860
+ };
3861
+ }>;
3862
+ };
3863
+ export type AiSearchListResponse = Array<{
3864
+ id: string;
3865
+ internal_id?: string;
3866
+ account_id?: string;
3867
+ account_tag?: string;
3868
+ /** Whether the instance is enabled (default true) */
3869
+ enable?: boolean;
3870
+ type?: "r2" | "web-crawler";
3871
+ source?: string;
3872
+ [key: string]: unknown;
3873
+ }>;
3874
+ export type AiSearchConfig = {
3875
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3876
+ id: string;
3877
+ type: "r2" | "web-crawler";
3878
+ source: string;
3879
+ source_params?: object;
3880
+ /** Token ID (UUID format) */
3881
+ token_id?: string;
3882
+ ai_gateway_id?: string;
3883
+ /** Enable query rewriting (default false) */
3884
+ rewrite_query?: boolean;
3885
+ /** Enable reranking (default false) */
3886
+ reranking?: boolean;
3887
+ embedding_model?: string;
3888
+ ai_search_model?: string;
3889
+ };
3890
+ export type AiSearchInstance = {
3891
+ id: string;
3892
+ enable?: boolean;
3893
+ type?: "r2" | "web-crawler";
3894
+ source?: string;
3895
+ [key: string]: unknown;
3896
+ };
3897
+ // AI Search Instance Service - Instance-level operations
3898
+ export declare abstract class AiSearchInstanceService {
3899
+ /**
3900
+ * Search the AI Search instance for relevant chunks.
3901
+ * @param params Search request with messages and AI search options
3902
+ * @returns Search response with matching chunks
3903
+ */
3904
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3905
+ /**
3906
+ * Generate chat completions with AI Search context.
3907
+ * @param params Chat completions request with optional streaming
3908
+ * @returns Response object (if streaming) or chat completion result
3909
+ */
3910
+ chatCompletions(
3911
+ params: AiSearchChatCompletionsRequest,
3912
+ ): Promise<Response | object>;
3913
+ /**
3914
+ * Delete this AI Search instance.
3915
+ */
3916
+ delete(): Promise<void>;
3917
+ }
3918
+ // AI Search Account Service - Account-level operations
3919
+ export declare abstract class AiSearchAccountService {
3920
+ /**
3921
+ * List all AI Search instances in the account.
3922
+ * @returns Array of AI Search instances
3923
+ */
3924
+ list(): Promise<AiSearchListResponse>;
3925
+ /**
3926
+ * Get an AI Search instance by ID.
3927
+ * @param name Instance ID
3928
+ * @returns Instance service for performing operations
3929
+ */
3930
+ get(name: string): AiSearchInstanceService;
3931
+ /**
3932
+ * Create a new AI Search instance.
3933
+ * @param config Instance configuration
3934
+ * @returns Instance service for performing operations
3935
+ */
3936
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3753
3937
  }
3754
3938
  export type AiImageClassificationInput = {
3755
3939
  image: number[];
@@ -9251,6 +9435,48 @@ export declare abstract class Ai<
9251
9435
  > {
9252
9436
  aiGatewayLogId: string | null;
9253
9437
  gateway(gatewayId: string): AiGateway;
9438
+ /**
9439
+ * Access the AI Search API for managing AI-powered search instances.
9440
+ *
9441
+ * This is the new API that replaces AutoRAG with better namespace separation:
9442
+ * - Account-level operations: `list()`, `create()`
9443
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9444
+ *
9445
+ * @example
9446
+ * ```typescript
9447
+ * // List all AI Search instances
9448
+ * const instances = await env.AI.aiSearch.list();
9449
+ *
9450
+ * // Search an instance
9451
+ * const results = await env.AI.aiSearch.get('my-search').search({
9452
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9453
+ * ai_search_options: {
9454
+ * retrieval: { max_num_results: 10 }
9455
+ * }
9456
+ * });
9457
+ *
9458
+ * // Generate chat completions with AI Search context
9459
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9460
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9461
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9462
+ * });
9463
+ * ```
9464
+ */
9465
+ aiSearch(): AiSearchAccountService;
9466
+ /**
9467
+ * @deprecated AutoRAG has been replaced by AI Search.
9468
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9469
+ *
9470
+ * Migration guide:
9471
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9472
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9473
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9474
+ *
9475
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9476
+ *
9477
+ * @see AiSearchAccountService
9478
+ * @param autoragId Optional instance ID (omit for account-level operations)
9479
+ */
9254
9480
  autorag(autoragId: string): AutoRAG;
9255
9481
  run<
9256
9482
  Name extends keyof AiModelList,
@@ -9407,19 +9633,30 @@ export declare abstract class AiGateway {
9407
9633
  ): Promise<Response>;
9408
9634
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9409
9635
  }
9636
+ /**
9637
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9638
+ * @see AiSearchInternalError
9639
+ */
9410
9640
  export interface AutoRAGInternalError extends Error {}
9641
+ /**
9642
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9643
+ * @see AiSearchNotFoundError
9644
+ */
9411
9645
  export interface AutoRAGNotFoundError extends Error {}
9646
+ /**
9647
+ * @deprecated This error type is no longer used in the AI Search API.
9648
+ */
9412
9649
  export interface AutoRAGUnauthorizedError extends Error {}
9650
+ /**
9651
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9652
+ * @see AiSearchNameNotSetError
9653
+ */
9413
9654
  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
- };
9655
+ /**
9656
+ * @deprecated AutoRAG has been replaced by AI Search.
9657
+ * Use AiSearchSearchRequest with the new API instead.
9658
+ * @see AiSearchSearchRequest
9659
+ */
9423
9660
  export type AutoRagSearchRequest = {
9424
9661
  query: string;
9425
9662
  filters?: CompoundFilter | ComparisonFilter;
@@ -9434,16 +9671,31 @@ export type AutoRagSearchRequest = {
9434
9671
  };
9435
9672
  rewrite_query?: boolean;
9436
9673
  };
9674
+ /**
9675
+ * @deprecated AutoRAG has been replaced by AI Search.
9676
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9677
+ * @see AiSearchChatCompletionsRequest
9678
+ */
9437
9679
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9438
9680
  stream?: boolean;
9439
9681
  system_prompt?: string;
9440
9682
  };
9683
+ /**
9684
+ * @deprecated AutoRAG has been replaced by AI Search.
9685
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9686
+ * @see AiSearchChatCompletionsRequest
9687
+ */
9441
9688
  export type AutoRagAiSearchRequestStreaming = Omit<
9442
9689
  AutoRagAiSearchRequest,
9443
9690
  "stream"
9444
9691
  > & {
9445
9692
  stream: true;
9446
9693
  };
9694
+ /**
9695
+ * @deprecated AutoRAG has been replaced by AI Search.
9696
+ * Use AiSearchSearchResponse with the new API instead.
9697
+ * @see AiSearchSearchResponse
9698
+ */
9447
9699
  export type AutoRagSearchResponse = {
9448
9700
  object: "vector_store.search_results.page";
9449
9701
  search_query: string;
@@ -9460,6 +9712,11 @@ export type AutoRagSearchResponse = {
9460
9712
  has_more: boolean;
9461
9713
  next_page: string | null;
9462
9714
  };
9715
+ /**
9716
+ * @deprecated AutoRAG has been replaced by AI Search.
9717
+ * Use AiSearchListResponse with the new API instead.
9718
+ * @see AiSearchListResponse
9719
+ */
9463
9720
  export type AutoRagListResponse = {
9464
9721
  id: string;
9465
9722
  enable: boolean;
@@ -9469,14 +9726,51 @@ export type AutoRagListResponse = {
9469
9726
  paused: boolean;
9470
9727
  status: string;
9471
9728
  }[];
9729
+ /**
9730
+ * @deprecated AutoRAG has been replaced by AI Search.
9731
+ * The new API returns different response formats for chat completions.
9732
+ */
9472
9733
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9473
9734
  response: string;
9474
9735
  };
9736
+ /**
9737
+ * @deprecated AutoRAG has been replaced by AI Search.
9738
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9739
+ *
9740
+ * Migration guide:
9741
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9742
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9743
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9744
+ *
9745
+ * @see AiSearchAccountService
9746
+ * @see AiSearchInstanceService
9747
+ */
9475
9748
  export declare abstract class AutoRAG {
9749
+ /**
9750
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9751
+ * @see AiSearchAccountService.list
9752
+ */
9476
9753
  list(): Promise<AutoRagListResponse>;
9754
+ /**
9755
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9756
+ * Note: The new API uses a messages array instead of a query string.
9757
+ * @see AiSearchInstanceService.search
9758
+ */
9477
9759
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9760
+ /**
9761
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9762
+ * @see AiSearchInstanceService.chatCompletions
9763
+ */
9478
9764
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9765
+ /**
9766
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9767
+ * @see AiSearchInstanceService.chatCompletions
9768
+ */
9479
9769
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9770
+ /**
9771
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9772
+ * @see AiSearchInstanceService.chatCompletions
9773
+ */
9480
9774
  aiSearch(
9481
9775
  params: AutoRagAiSearchRequest,
9482
9776
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10878,6 +11172,86 @@ export type ImageOutputOptions = {
10878
11172
  background?: string;
10879
11173
  anim?: boolean;
10880
11174
  };
11175
+ export interface ImageMetadata {
11176
+ id: string;
11177
+ filename?: string;
11178
+ uploaded?: string;
11179
+ requireSignedURLs: boolean;
11180
+ meta?: Record<string, unknown>;
11181
+ variants: string[];
11182
+ draft?: boolean;
11183
+ creator?: string;
11184
+ }
11185
+ export interface ImageUploadOptions {
11186
+ id?: string;
11187
+ filename?: string;
11188
+ requireSignedURLs?: boolean;
11189
+ metadata?: Record<string, unknown>;
11190
+ creator?: string;
11191
+ encoding?: "base64";
11192
+ }
11193
+ export interface ImageUpdateOptions {
11194
+ requireSignedURLs?: boolean;
11195
+ metadata?: Record<string, unknown>;
11196
+ creator?: string;
11197
+ }
11198
+ export interface ImageListOptions {
11199
+ limit?: number;
11200
+ cursor?: string;
11201
+ sortOrder?: "asc" | "desc";
11202
+ creator?: string;
11203
+ }
11204
+ export interface ImageList {
11205
+ images: ImageMetadata[];
11206
+ cursor?: string;
11207
+ listComplete: boolean;
11208
+ }
11209
+ export interface HostedImagesBinding {
11210
+ /**
11211
+ * Get detailed metadata for a hosted image
11212
+ * @param imageId The ID of the image (UUID or custom ID)
11213
+ * @returns Image metadata, or null if not found
11214
+ */
11215
+ details(imageId: string): Promise<ImageMetadata | null>;
11216
+ /**
11217
+ * Get the raw image data for a hosted image
11218
+ * @param imageId The ID of the image (UUID or custom ID)
11219
+ * @returns ReadableStream of image bytes, or null if not found
11220
+ */
11221
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11222
+ /**
11223
+ * Upload a new hosted image
11224
+ * @param image The image file to upload
11225
+ * @param options Upload configuration
11226
+ * @returns Metadata for the uploaded image
11227
+ * @throws {@link ImagesError} if upload fails
11228
+ */
11229
+ upload(
11230
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11231
+ options?: ImageUploadOptions,
11232
+ ): Promise<ImageMetadata>;
11233
+ /**
11234
+ * Update hosted image metadata
11235
+ * @param imageId The ID of the image
11236
+ * @param options Properties to update
11237
+ * @returns Updated image metadata
11238
+ * @throws {@link ImagesError} if update fails
11239
+ */
11240
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11241
+ /**
11242
+ * Delete a hosted image
11243
+ * @param imageId The ID of the image
11244
+ * @returns True if deleted, false if not found
11245
+ */
11246
+ delete(imageId: string): Promise<boolean>;
11247
+ /**
11248
+ * List hosted images with pagination
11249
+ * @param options List configuration
11250
+ * @returns List of images with pagination info
11251
+ * @throws {@link ImagesError} if list fails
11252
+ */
11253
+ list(options?: ImageListOptions): Promise<ImageList>;
11254
+ }
10881
11255
  export interface ImagesBinding {
10882
11256
  /**
10883
11257
  * Get image metadata (type, width and height)
@@ -10897,6 +11271,10 @@ export interface ImagesBinding {
10897
11271
  stream: ReadableStream<Uint8Array>,
10898
11272
  options?: ImageInputOptions,
10899
11273
  ): ImageTransformer;
11274
+ /**
11275
+ * Access hosted images CRUD operations
11276
+ */
11277
+ readonly hosted: HostedImagesBinding;
10900
11278
  }
10901
11279
  export interface ImageTransformer {
10902
11280
  /**
@@ -10967,8 +11345,14 @@ export interface MediaTransformer {
10967
11345
  * @returns A generator for producing the transformed media output
10968
11346
  */
10969
11347
  transform(
10970
- transform: MediaTransformationInputOptions,
11348
+ transform?: MediaTransformationInputOptions,
10971
11349
  ): MediaTransformationGenerator;
11350
+ /**
11351
+ * Generates the final media output with specified options.
11352
+ * @param output - Configuration for the output format and parameters
11353
+ * @returns The final transformation result containing the transformed media
11354
+ */
11355
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10972
11356
  }
10973
11357
  /**
10974
11358
  * Generator for producing media transformation results.
@@ -10980,7 +11364,7 @@ export interface MediaTransformationGenerator {
10980
11364
  * @param output - Configuration for the output format and parameters
10981
11365
  * @returns The final transformation result containing the transformed media
10982
11366
  */
10983
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11367
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10984
11368
  }
10985
11369
  /**
10986
11370
  * Result of a media transformation operation.
@@ -10989,19 +11373,19 @@ export interface MediaTransformationGenerator {
10989
11373
  export interface MediaTransformationResult {
10990
11374
  /**
10991
11375
  * Returns the transformed media as a readable stream of bytes.
10992
- * @returns A stream containing the transformed media data
11376
+ * @returns A promise containing a readable stream with the transformed media
10993
11377
  */
10994
- media(): ReadableStream<Uint8Array>;
11378
+ media(): Promise<ReadableStream<Uint8Array>>;
10995
11379
  /**
10996
11380
  * 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
11381
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
10998
11382
  */
10999
- response(): Response;
11383
+ response(): Promise<Response>;
11000
11384
  /**
11001
11385
  * Returns the MIME type of the transformed media.
11002
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11386
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11003
11387
  */
11004
- contentType(): string;
11388
+ contentType(): Promise<string>;
11005
11389
  }
11006
11390
  /**
11007
11391
  * Configuration options for transforming media input.