@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.
@@ -3741,6 +3741,190 @@ declare abstract class Performance {
3741
3741
  get timeOrigin(): number;
3742
3742
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3743
3743
  now(): number;
3744
+ /**
3745
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3746
+ *
3747
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3748
+ */
3749
+ toJSON(): object;
3750
+ }
3751
+ // AI Search V2 API Error Interfaces
3752
+ interface AiSearchInternalError extends Error {}
3753
+ interface AiSearchNotFoundError extends Error {}
3754
+ interface AiSearchNameNotSetError extends Error {}
3755
+ // Filter types (shared with AutoRAG for compatibility)
3756
+ type ComparisonFilter = {
3757
+ key: string;
3758
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
3759
+ value: string | number | boolean;
3760
+ };
3761
+ type CompoundFilter = {
3762
+ type: "and" | "or";
3763
+ filters: ComparisonFilter[];
3764
+ };
3765
+ // AI Search V2 Request Types
3766
+ type AiSearchSearchRequest = {
3767
+ messages: Array<{
3768
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3769
+ content: string | null;
3770
+ }>;
3771
+ ai_search_options?: {
3772
+ retrieval?: {
3773
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3774
+ /** Match threshold (0-1, default 0.4) */
3775
+ match_threshold?: number;
3776
+ /** Maximum number of results (1-50, default 10) */
3777
+ max_num_results?: number;
3778
+ filters?: CompoundFilter | ComparisonFilter;
3779
+ /** Context expansion (0-3, default 0) */
3780
+ context_expansion?: number;
3781
+ [key: string]: unknown;
3782
+ };
3783
+ query_rewrite?: {
3784
+ enabled?: boolean;
3785
+ model?: string;
3786
+ rewrite_prompt?: string;
3787
+ [key: string]: unknown;
3788
+ };
3789
+ reranking?: {
3790
+ /** Enable reranking (default false) */
3791
+ enabled?: boolean;
3792
+ model?: "@cf/baai/bge-reranker-base" | "";
3793
+ /** Match threshold (0-1, default 0.4) */
3794
+ match_threshold?: number;
3795
+ [key: string]: unknown;
3796
+ };
3797
+ [key: string]: unknown;
3798
+ };
3799
+ };
3800
+ type AiSearchChatCompletionsRequest = {
3801
+ messages: Array<{
3802
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3803
+ content: string | null;
3804
+ }>;
3805
+ model?: string;
3806
+ stream?: boolean;
3807
+ ai_search_options?: {
3808
+ retrieval?: {
3809
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3810
+ match_threshold?: number;
3811
+ max_num_results?: number;
3812
+ filters?: CompoundFilter | ComparisonFilter;
3813
+ context_expansion?: number;
3814
+ [key: string]: unknown;
3815
+ };
3816
+ query_rewrite?: {
3817
+ enabled?: boolean;
3818
+ model?: string;
3819
+ rewrite_prompt?: string;
3820
+ [key: string]: unknown;
3821
+ };
3822
+ reranking?: {
3823
+ enabled?: boolean;
3824
+ model?: "@cf/baai/bge-reranker-base" | "";
3825
+ match_threshold?: number;
3826
+ [key: string]: unknown;
3827
+ };
3828
+ [key: string]: unknown;
3829
+ };
3830
+ [key: string]: unknown;
3831
+ };
3832
+ // AI Search V2 Response Types
3833
+ type AiSearchSearchResponse = {
3834
+ search_query: string;
3835
+ chunks: Array<{
3836
+ id: string;
3837
+ type: string;
3838
+ /** Match score (0-1) */
3839
+ score: number;
3840
+ text: string;
3841
+ item: {
3842
+ timestamp?: number;
3843
+ key: string;
3844
+ metadata?: Record<string, unknown>;
3845
+ };
3846
+ scoring_details?: {
3847
+ /** Keyword match score (0-1) */
3848
+ keyword_score?: number;
3849
+ /** Vector similarity score (0-1) */
3850
+ vector_score?: number;
3851
+ };
3852
+ }>;
3853
+ };
3854
+ type AiSearchListResponse = Array<{
3855
+ id: string;
3856
+ internal_id?: string;
3857
+ account_id?: string;
3858
+ account_tag?: string;
3859
+ /** Whether the instance is enabled (default true) */
3860
+ enable?: boolean;
3861
+ type?: "r2" | "web-crawler";
3862
+ source?: string;
3863
+ [key: string]: unknown;
3864
+ }>;
3865
+ type AiSearchConfig = {
3866
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3867
+ id: string;
3868
+ type: "r2" | "web-crawler";
3869
+ source: string;
3870
+ source_params?: object;
3871
+ /** Token ID (UUID format) */
3872
+ token_id?: string;
3873
+ ai_gateway_id?: string;
3874
+ /** Enable query rewriting (default false) */
3875
+ rewrite_query?: boolean;
3876
+ /** Enable reranking (default false) */
3877
+ reranking?: boolean;
3878
+ embedding_model?: string;
3879
+ ai_search_model?: string;
3880
+ };
3881
+ type AiSearchInstance = {
3882
+ id: string;
3883
+ enable?: boolean;
3884
+ type?: "r2" | "web-crawler";
3885
+ source?: string;
3886
+ [key: string]: unknown;
3887
+ };
3888
+ // AI Search Instance Service - Instance-level operations
3889
+ declare abstract class AiSearchInstanceService {
3890
+ /**
3891
+ * Search the AI Search instance for relevant chunks.
3892
+ * @param params Search request with messages and AI search options
3893
+ * @returns Search response with matching chunks
3894
+ */
3895
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
3896
+ /**
3897
+ * Generate chat completions with AI Search context.
3898
+ * @param params Chat completions request with optional streaming
3899
+ * @returns Response object (if streaming) or chat completion result
3900
+ */
3901
+ chatCompletions(
3902
+ params: AiSearchChatCompletionsRequest,
3903
+ ): Promise<Response | object>;
3904
+ /**
3905
+ * Delete this AI Search instance.
3906
+ */
3907
+ delete(): Promise<void>;
3908
+ }
3909
+ // AI Search Account Service - Account-level operations
3910
+ declare abstract class AiSearchAccountService {
3911
+ /**
3912
+ * List all AI Search instances in the account.
3913
+ * @returns Array of AI Search instances
3914
+ */
3915
+ list(): Promise<AiSearchListResponse>;
3916
+ /**
3917
+ * Get an AI Search instance by ID.
3918
+ * @param name Instance ID
3919
+ * @returns Instance service for performing operations
3920
+ */
3921
+ get(name: string): AiSearchInstanceService;
3922
+ /**
3923
+ * Create a new AI Search instance.
3924
+ * @param config Instance configuration
3925
+ * @returns Instance service for performing operations
3926
+ */
3927
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3744
3928
  }
3745
3929
  type AiImageClassificationInput = {
3746
3930
  image: number[];
@@ -9239,6 +9423,48 @@ type AiModelListType = Record<string, any>;
9239
9423
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9240
9424
  aiGatewayLogId: string | null;
9241
9425
  gateway(gatewayId: string): AiGateway;
9426
+ /**
9427
+ * Access the AI Search API for managing AI-powered search instances.
9428
+ *
9429
+ * This is the new API that replaces AutoRAG with better namespace separation:
9430
+ * - Account-level operations: `list()`, `create()`
9431
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9432
+ *
9433
+ * @example
9434
+ * ```typescript
9435
+ * // List all AI Search instances
9436
+ * const instances = await env.AI.aiSearch.list();
9437
+ *
9438
+ * // Search an instance
9439
+ * const results = await env.AI.aiSearch.get('my-search').search({
9440
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9441
+ * ai_search_options: {
9442
+ * retrieval: { max_num_results: 10 }
9443
+ * }
9444
+ * });
9445
+ *
9446
+ * // Generate chat completions with AI Search context
9447
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9448
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9449
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9450
+ * });
9451
+ * ```
9452
+ */
9453
+ aiSearch(): AiSearchAccountService;
9454
+ /**
9455
+ * @deprecated AutoRAG has been replaced by AI Search.
9456
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9457
+ *
9458
+ * Migration guide:
9459
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9460
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9461
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9462
+ *
9463
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9464
+ *
9465
+ * @see AiSearchAccountService
9466
+ * @param autoragId Optional instance ID (omit for account-level operations)
9467
+ */
9242
9468
  autorag(autoragId: string): AutoRAG;
9243
9469
  run<
9244
9470
  Name extends keyof AiModelList,
@@ -9395,19 +9621,30 @@ declare abstract class AiGateway {
9395
9621
  ): Promise<Response>;
9396
9622
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9397
9623
  }
9624
+ /**
9625
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9626
+ * @see AiSearchInternalError
9627
+ */
9398
9628
  interface AutoRAGInternalError extends Error {}
9629
+ /**
9630
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9631
+ * @see AiSearchNotFoundError
9632
+ */
9399
9633
  interface AutoRAGNotFoundError extends Error {}
9634
+ /**
9635
+ * @deprecated This error type is no longer used in the AI Search API.
9636
+ */
9400
9637
  interface AutoRAGUnauthorizedError extends Error {}
9638
+ /**
9639
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9640
+ * @see AiSearchNameNotSetError
9641
+ */
9401
9642
  interface AutoRAGNameNotSetError extends Error {}
9402
- type ComparisonFilter = {
9403
- key: string;
9404
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9405
- value: string | number | boolean;
9406
- };
9407
- type CompoundFilter = {
9408
- type: "and" | "or";
9409
- filters: ComparisonFilter[];
9410
- };
9643
+ /**
9644
+ * @deprecated AutoRAG has been replaced by AI Search.
9645
+ * Use AiSearchSearchRequest with the new API instead.
9646
+ * @see AiSearchSearchRequest
9647
+ */
9411
9648
  type AutoRagSearchRequest = {
9412
9649
  query: string;
9413
9650
  filters?: CompoundFilter | ComparisonFilter;
@@ -9422,16 +9659,31 @@ type AutoRagSearchRequest = {
9422
9659
  };
9423
9660
  rewrite_query?: boolean;
9424
9661
  };
9662
+ /**
9663
+ * @deprecated AutoRAG has been replaced by AI Search.
9664
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9665
+ * @see AiSearchChatCompletionsRequest
9666
+ */
9425
9667
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9426
9668
  stream?: boolean;
9427
9669
  system_prompt?: string;
9428
9670
  };
9671
+ /**
9672
+ * @deprecated AutoRAG has been replaced by AI Search.
9673
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9674
+ * @see AiSearchChatCompletionsRequest
9675
+ */
9429
9676
  type AutoRagAiSearchRequestStreaming = Omit<
9430
9677
  AutoRagAiSearchRequest,
9431
9678
  "stream"
9432
9679
  > & {
9433
9680
  stream: true;
9434
9681
  };
9682
+ /**
9683
+ * @deprecated AutoRAG has been replaced by AI Search.
9684
+ * Use AiSearchSearchResponse with the new API instead.
9685
+ * @see AiSearchSearchResponse
9686
+ */
9435
9687
  type AutoRagSearchResponse = {
9436
9688
  object: "vector_store.search_results.page";
9437
9689
  search_query: string;
@@ -9448,6 +9700,11 @@ type AutoRagSearchResponse = {
9448
9700
  has_more: boolean;
9449
9701
  next_page: string | null;
9450
9702
  };
9703
+ /**
9704
+ * @deprecated AutoRAG has been replaced by AI Search.
9705
+ * Use AiSearchListResponse with the new API instead.
9706
+ * @see AiSearchListResponse
9707
+ */
9451
9708
  type AutoRagListResponse = {
9452
9709
  id: string;
9453
9710
  enable: boolean;
@@ -9457,14 +9714,51 @@ type AutoRagListResponse = {
9457
9714
  paused: boolean;
9458
9715
  status: string;
9459
9716
  }[];
9717
+ /**
9718
+ * @deprecated AutoRAG has been replaced by AI Search.
9719
+ * The new API returns different response formats for chat completions.
9720
+ */
9460
9721
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9461
9722
  response: string;
9462
9723
  };
9724
+ /**
9725
+ * @deprecated AutoRAG has been replaced by AI Search.
9726
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9727
+ *
9728
+ * Migration guide:
9729
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9730
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9731
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9732
+ *
9733
+ * @see AiSearchAccountService
9734
+ * @see AiSearchInstanceService
9735
+ */
9463
9736
  declare abstract class AutoRAG {
9737
+ /**
9738
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9739
+ * @see AiSearchAccountService.list
9740
+ */
9464
9741
  list(): Promise<AutoRagListResponse>;
9742
+ /**
9743
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9744
+ * Note: The new API uses a messages array instead of a query string.
9745
+ * @see AiSearchInstanceService.search
9746
+ */
9465
9747
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9748
+ /**
9749
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9750
+ * @see AiSearchInstanceService.chatCompletions
9751
+ */
9466
9752
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9753
+ /**
9754
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9755
+ * @see AiSearchInstanceService.chatCompletions
9756
+ */
9467
9757
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9758
+ /**
9759
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9760
+ * @see AiSearchInstanceService.chatCompletions
9761
+ */
9468
9762
  aiSearch(
9469
9763
  params: AutoRagAiSearchRequest,
9470
9764
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10861,6 +11155,86 @@ type ImageOutputOptions = {
10861
11155
  background?: string;
10862
11156
  anim?: boolean;
10863
11157
  };
11158
+ interface ImageMetadata {
11159
+ id: string;
11160
+ filename?: string;
11161
+ uploaded?: string;
11162
+ requireSignedURLs: boolean;
11163
+ meta?: Record<string, unknown>;
11164
+ variants: string[];
11165
+ draft?: boolean;
11166
+ creator?: string;
11167
+ }
11168
+ interface ImageUploadOptions {
11169
+ id?: string;
11170
+ filename?: string;
11171
+ requireSignedURLs?: boolean;
11172
+ metadata?: Record<string, unknown>;
11173
+ creator?: string;
11174
+ encoding?: "base64";
11175
+ }
11176
+ interface ImageUpdateOptions {
11177
+ requireSignedURLs?: boolean;
11178
+ metadata?: Record<string, unknown>;
11179
+ creator?: string;
11180
+ }
11181
+ interface ImageListOptions {
11182
+ limit?: number;
11183
+ cursor?: string;
11184
+ sortOrder?: "asc" | "desc";
11185
+ creator?: string;
11186
+ }
11187
+ interface ImageList {
11188
+ images: ImageMetadata[];
11189
+ cursor?: string;
11190
+ listComplete: boolean;
11191
+ }
11192
+ interface HostedImagesBinding {
11193
+ /**
11194
+ * Get detailed metadata for a hosted image
11195
+ * @param imageId The ID of the image (UUID or custom ID)
11196
+ * @returns Image metadata, or null if not found
11197
+ */
11198
+ details(imageId: string): Promise<ImageMetadata | null>;
11199
+ /**
11200
+ * Get the raw image data for a hosted image
11201
+ * @param imageId The ID of the image (UUID or custom ID)
11202
+ * @returns ReadableStream of image bytes, or null if not found
11203
+ */
11204
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11205
+ /**
11206
+ * Upload a new hosted image
11207
+ * @param image The image file to upload
11208
+ * @param options Upload configuration
11209
+ * @returns Metadata for the uploaded image
11210
+ * @throws {@link ImagesError} if upload fails
11211
+ */
11212
+ upload(
11213
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11214
+ options?: ImageUploadOptions,
11215
+ ): Promise<ImageMetadata>;
11216
+ /**
11217
+ * Update hosted image metadata
11218
+ * @param imageId The ID of the image
11219
+ * @param options Properties to update
11220
+ * @returns Updated image metadata
11221
+ * @throws {@link ImagesError} if update fails
11222
+ */
11223
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11224
+ /**
11225
+ * Delete a hosted image
11226
+ * @param imageId The ID of the image
11227
+ * @returns True if deleted, false if not found
11228
+ */
11229
+ delete(imageId: string): Promise<boolean>;
11230
+ /**
11231
+ * List hosted images with pagination
11232
+ * @param options List configuration
11233
+ * @returns List of images with pagination info
11234
+ * @throws {@link ImagesError} if list fails
11235
+ */
11236
+ list(options?: ImageListOptions): Promise<ImageList>;
11237
+ }
10864
11238
  interface ImagesBinding {
10865
11239
  /**
10866
11240
  * Get image metadata (type, width and height)
@@ -10880,6 +11254,10 @@ interface ImagesBinding {
10880
11254
  stream: ReadableStream<Uint8Array>,
10881
11255
  options?: ImageInputOptions,
10882
11256
  ): ImageTransformer;
11257
+ /**
11258
+ * Access hosted images CRUD operations
11259
+ */
11260
+ readonly hosted: HostedImagesBinding;
10883
11261
  }
10884
11262
  interface ImageTransformer {
10885
11263
  /**
@@ -10950,8 +11328,14 @@ interface MediaTransformer {
10950
11328
  * @returns A generator for producing the transformed media output
10951
11329
  */
10952
11330
  transform(
10953
- transform: MediaTransformationInputOptions,
11331
+ transform?: MediaTransformationInputOptions,
10954
11332
  ): MediaTransformationGenerator;
11333
+ /**
11334
+ * Generates the final media output with specified options.
11335
+ * @param output - Configuration for the output format and parameters
11336
+ * @returns The final transformation result containing the transformed media
11337
+ */
11338
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10955
11339
  }
10956
11340
  /**
10957
11341
  * Generator for producing media transformation results.
@@ -10963,7 +11347,7 @@ interface MediaTransformationGenerator {
10963
11347
  * @param output - Configuration for the output format and parameters
10964
11348
  * @returns The final transformation result containing the transformed media
10965
11349
  */
10966
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11350
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
10967
11351
  }
10968
11352
  /**
10969
11353
  * Result of a media transformation operation.
@@ -10972,19 +11356,19 @@ interface MediaTransformationGenerator {
10972
11356
  interface MediaTransformationResult {
10973
11357
  /**
10974
11358
  * Returns the transformed media as a readable stream of bytes.
10975
- * @returns A stream containing the transformed media data
11359
+ * @returns A promise containing a readable stream with the transformed media
10976
11360
  */
10977
- media(): ReadableStream<Uint8Array>;
11361
+ media(): Promise<ReadableStream<Uint8Array>>;
10978
11362
  /**
10979
11363
  * Returns the transformed media as an HTTP response object.
10980
- * @returns The transformed media as a Response, ready to store in cache or return to users
11364
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
10981
11365
  */
10982
- response(): Response;
11366
+ response(): Promise<Response>;
10983
11367
  /**
10984
11368
  * Returns the MIME type of the transformed media.
10985
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11369
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
10986
11370
  */
10987
- contentType(): string;
11371
+ contentType(): Promise<string>;
10988
11372
  }
10989
11373
  /**
10990
11374
  * Configuration options for transforming media input.