@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.
@@ -3850,6 +3850,8 @@ export interface Container {
3850
3850
  signal(signo: number): void;
3851
3851
  getTcpPort(port: number): Fetcher;
3852
3852
  setInactivityTimeout(durationMs: number | bigint): Promise<void>;
3853
+ interceptOutboundHttp(addr: string, binding: Fetcher): Promise<void>;
3854
+ interceptAllOutboundHttp(binding: Fetcher): Promise<void>;
3853
3855
  }
3854
3856
  export interface ContainerStartupOptions {
3855
3857
  entrypoint?: string[];
@@ -4517,6 +4519,184 @@ export interface EventCounts {
4517
4519
  ): void;
4518
4520
  [Symbol.iterator](): IterableIterator<string[]>;
4519
4521
  }
4522
+ // AI Search V2 API Error Interfaces
4523
+ export interface AiSearchInternalError extends Error {}
4524
+ export interface AiSearchNotFoundError extends Error {}
4525
+ export interface AiSearchNameNotSetError extends Error {}
4526
+ // Filter types (shared with AutoRAG for compatibility)
4527
+ export type ComparisonFilter = {
4528
+ key: string;
4529
+ type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
4530
+ value: string | number | boolean;
4531
+ };
4532
+ export type CompoundFilter = {
4533
+ type: "and" | "or";
4534
+ filters: ComparisonFilter[];
4535
+ };
4536
+ // AI Search V2 Request Types
4537
+ export type AiSearchSearchRequest = {
4538
+ messages: Array<{
4539
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4540
+ content: string | null;
4541
+ }>;
4542
+ ai_search_options?: {
4543
+ retrieval?: {
4544
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4545
+ /** Match threshold (0-1, default 0.4) */
4546
+ match_threshold?: number;
4547
+ /** Maximum number of results (1-50, default 10) */
4548
+ max_num_results?: number;
4549
+ filters?: CompoundFilter | ComparisonFilter;
4550
+ /** Context expansion (0-3, default 0) */
4551
+ context_expansion?: number;
4552
+ [key: string]: unknown;
4553
+ };
4554
+ query_rewrite?: {
4555
+ enabled?: boolean;
4556
+ model?: string;
4557
+ rewrite_prompt?: string;
4558
+ [key: string]: unknown;
4559
+ };
4560
+ reranking?: {
4561
+ /** Enable reranking (default false) */
4562
+ enabled?: boolean;
4563
+ model?: "@cf/baai/bge-reranker-base" | "";
4564
+ /** Match threshold (0-1, default 0.4) */
4565
+ match_threshold?: number;
4566
+ [key: string]: unknown;
4567
+ };
4568
+ [key: string]: unknown;
4569
+ };
4570
+ };
4571
+ export type AiSearchChatCompletionsRequest = {
4572
+ messages: Array<{
4573
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4574
+ content: string | null;
4575
+ }>;
4576
+ model?: string;
4577
+ stream?: boolean;
4578
+ ai_search_options?: {
4579
+ retrieval?: {
4580
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4581
+ match_threshold?: number;
4582
+ max_num_results?: number;
4583
+ filters?: CompoundFilter | ComparisonFilter;
4584
+ context_expansion?: number;
4585
+ [key: string]: unknown;
4586
+ };
4587
+ query_rewrite?: {
4588
+ enabled?: boolean;
4589
+ model?: string;
4590
+ rewrite_prompt?: string;
4591
+ [key: string]: unknown;
4592
+ };
4593
+ reranking?: {
4594
+ enabled?: boolean;
4595
+ model?: "@cf/baai/bge-reranker-base" | "";
4596
+ match_threshold?: number;
4597
+ [key: string]: unknown;
4598
+ };
4599
+ [key: string]: unknown;
4600
+ };
4601
+ [key: string]: unknown;
4602
+ };
4603
+ // AI Search V2 Response Types
4604
+ export type AiSearchSearchResponse = {
4605
+ search_query: string;
4606
+ chunks: Array<{
4607
+ id: string;
4608
+ type: string;
4609
+ /** Match score (0-1) */
4610
+ score: number;
4611
+ text: string;
4612
+ item: {
4613
+ timestamp?: number;
4614
+ key: string;
4615
+ metadata?: Record<string, unknown>;
4616
+ };
4617
+ scoring_details?: {
4618
+ /** Keyword match score (0-1) */
4619
+ keyword_score?: number;
4620
+ /** Vector similarity score (0-1) */
4621
+ vector_score?: number;
4622
+ };
4623
+ }>;
4624
+ };
4625
+ export type AiSearchListResponse = Array<{
4626
+ id: string;
4627
+ internal_id?: string;
4628
+ account_id?: string;
4629
+ account_tag?: string;
4630
+ /** Whether the instance is enabled (default true) */
4631
+ enable?: boolean;
4632
+ type?: "r2" | "web-crawler";
4633
+ source?: string;
4634
+ [key: string]: unknown;
4635
+ }>;
4636
+ export type AiSearchConfig = {
4637
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
4638
+ id: string;
4639
+ type: "r2" | "web-crawler";
4640
+ source: string;
4641
+ source_params?: object;
4642
+ /** Token ID (UUID format) */
4643
+ token_id?: string;
4644
+ ai_gateway_id?: string;
4645
+ /** Enable query rewriting (default false) */
4646
+ rewrite_query?: boolean;
4647
+ /** Enable reranking (default false) */
4648
+ reranking?: boolean;
4649
+ embedding_model?: string;
4650
+ ai_search_model?: string;
4651
+ };
4652
+ export type AiSearchInstance = {
4653
+ id: string;
4654
+ enable?: boolean;
4655
+ type?: "r2" | "web-crawler";
4656
+ source?: string;
4657
+ [key: string]: unknown;
4658
+ };
4659
+ // AI Search Instance Service - Instance-level operations
4660
+ export declare abstract class AiSearchInstanceService {
4661
+ /**
4662
+ * Search the AI Search instance for relevant chunks.
4663
+ * @param params Search request with messages and AI search options
4664
+ * @returns Search response with matching chunks
4665
+ */
4666
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4667
+ /**
4668
+ * Generate chat completions with AI Search context.
4669
+ * @param params Chat completions request with optional streaming
4670
+ * @returns Response object (if streaming) or chat completion result
4671
+ */
4672
+ chatCompletions(
4673
+ params: AiSearchChatCompletionsRequest,
4674
+ ): Promise<Response | object>;
4675
+ /**
4676
+ * Delete this AI Search instance.
4677
+ */
4678
+ delete(): Promise<void>;
4679
+ }
4680
+ // AI Search Account Service - Account-level operations
4681
+ export declare abstract class AiSearchAccountService {
4682
+ /**
4683
+ * List all AI Search instances in the account.
4684
+ * @returns Array of AI Search instances
4685
+ */
4686
+ list(): Promise<AiSearchListResponse>;
4687
+ /**
4688
+ * Get an AI Search instance by ID.
4689
+ * @param name Instance ID
4690
+ * @returns Instance service for performing operations
4691
+ */
4692
+ get(name: string): AiSearchInstanceService;
4693
+ /**
4694
+ * Create a new AI Search instance.
4695
+ * @param config Instance configuration
4696
+ * @returns Instance service for performing operations
4697
+ */
4698
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
4699
+ }
4520
4700
  export type AiImageClassificationInput = {
4521
4701
  image: number[];
4522
4702
  };
@@ -10017,6 +10197,48 @@ export declare abstract class Ai<
10017
10197
  > {
10018
10198
  aiGatewayLogId: string | null;
10019
10199
  gateway(gatewayId: string): AiGateway;
10200
+ /**
10201
+ * Access the AI Search API for managing AI-powered search instances.
10202
+ *
10203
+ * This is the new API that replaces AutoRAG with better namespace separation:
10204
+ * - Account-level operations: `list()`, `create()`
10205
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
10206
+ *
10207
+ * @example
10208
+ * ```typescript
10209
+ * // List all AI Search instances
10210
+ * const instances = await env.AI.aiSearch.list();
10211
+ *
10212
+ * // Search an instance
10213
+ * const results = await env.AI.aiSearch.get('my-search').search({
10214
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
10215
+ * ai_search_options: {
10216
+ * retrieval: { max_num_results: 10 }
10217
+ * }
10218
+ * });
10219
+ *
10220
+ * // Generate chat completions with AI Search context
10221
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
10222
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
10223
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
10224
+ * });
10225
+ * ```
10226
+ */
10227
+ aiSearch: AiSearchAccountService;
10228
+ /**
10229
+ * @deprecated AutoRAG has been replaced by AI Search.
10230
+ * Use `env.AI.aiSearch` instead for better API design and new features.
10231
+ *
10232
+ * Migration guide:
10233
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
10234
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
10235
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
10236
+ *
10237
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
10238
+ *
10239
+ * @see AiSearchAccountService
10240
+ * @param autoragId Optional instance ID (omit for account-level operations)
10241
+ */
10020
10242
  autorag(autoragId: string): AutoRAG;
10021
10243
  run<
10022
10244
  Name extends keyof AiModelList,
@@ -10173,19 +10395,30 @@ export declare abstract class AiGateway {
10173
10395
  ): Promise<Response>;
10174
10396
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
10175
10397
  }
10398
+ /**
10399
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
10400
+ * @see AiSearchInternalError
10401
+ */
10176
10402
  export interface AutoRAGInternalError extends Error {}
10403
+ /**
10404
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
10405
+ * @see AiSearchNotFoundError
10406
+ */
10177
10407
  export interface AutoRAGNotFoundError extends Error {}
10408
+ /**
10409
+ * @deprecated This error type is no longer used in the AI Search API.
10410
+ */
10178
10411
  export interface AutoRAGUnauthorizedError extends Error {}
10412
+ /**
10413
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
10414
+ * @see AiSearchNameNotSetError
10415
+ */
10179
10416
  export interface AutoRAGNameNotSetError extends Error {}
10180
- export type ComparisonFilter = {
10181
- key: string;
10182
- type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
10183
- value: string | number | boolean;
10184
- };
10185
- export type CompoundFilter = {
10186
- type: "and" | "or";
10187
- filters: ComparisonFilter[];
10188
- };
10417
+ /**
10418
+ * @deprecated AutoRAG has been replaced by AI Search.
10419
+ * Use AiSearchSearchRequest with the new API instead.
10420
+ * @see AiSearchSearchRequest
10421
+ */
10189
10422
  export type AutoRagSearchRequest = {
10190
10423
  query: string;
10191
10424
  filters?: CompoundFilter | ComparisonFilter;
@@ -10200,16 +10433,31 @@ export type AutoRagSearchRequest = {
10200
10433
  };
10201
10434
  rewrite_query?: boolean;
10202
10435
  };
10436
+ /**
10437
+ * @deprecated AutoRAG has been replaced by AI Search.
10438
+ * Use AiSearchChatCompletionsRequest with the new API instead.
10439
+ * @see AiSearchChatCompletionsRequest
10440
+ */
10203
10441
  export type AutoRagAiSearchRequest = AutoRagSearchRequest & {
10204
10442
  stream?: boolean;
10205
10443
  system_prompt?: string;
10206
10444
  };
10445
+ /**
10446
+ * @deprecated AutoRAG has been replaced by AI Search.
10447
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
10448
+ * @see AiSearchChatCompletionsRequest
10449
+ */
10207
10450
  export type AutoRagAiSearchRequestStreaming = Omit<
10208
10451
  AutoRagAiSearchRequest,
10209
10452
  "stream"
10210
10453
  > & {
10211
10454
  stream: true;
10212
10455
  };
10456
+ /**
10457
+ * @deprecated AutoRAG has been replaced by AI Search.
10458
+ * Use AiSearchSearchResponse with the new API instead.
10459
+ * @see AiSearchSearchResponse
10460
+ */
10213
10461
  export type AutoRagSearchResponse = {
10214
10462
  object: "vector_store.search_results.page";
10215
10463
  search_query: string;
@@ -10226,6 +10474,11 @@ export type AutoRagSearchResponse = {
10226
10474
  has_more: boolean;
10227
10475
  next_page: string | null;
10228
10476
  };
10477
+ /**
10478
+ * @deprecated AutoRAG has been replaced by AI Search.
10479
+ * Use AiSearchListResponse with the new API instead.
10480
+ * @see AiSearchListResponse
10481
+ */
10229
10482
  export type AutoRagListResponse = {
10230
10483
  id: string;
10231
10484
  enable: boolean;
@@ -10235,14 +10488,51 @@ export type AutoRagListResponse = {
10235
10488
  paused: boolean;
10236
10489
  status: string;
10237
10490
  }[];
10491
+ /**
10492
+ * @deprecated AutoRAG has been replaced by AI Search.
10493
+ * The new API returns different response formats for chat completions.
10494
+ */
10238
10495
  export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
10239
10496
  response: string;
10240
10497
  };
10498
+ /**
10499
+ * @deprecated AutoRAG has been replaced by AI Search.
10500
+ * Use the new AI Search API instead: `env.AI.aiSearch`
10501
+ *
10502
+ * Migration guide:
10503
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
10504
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
10505
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
10506
+ *
10507
+ * @see AiSearchAccountService
10508
+ * @see AiSearchInstanceService
10509
+ */
10241
10510
  export declare abstract class AutoRAG {
10511
+ /**
10512
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
10513
+ * @see AiSearchAccountService.list
10514
+ */
10242
10515
  list(): Promise<AutoRagListResponse>;
10516
+ /**
10517
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
10518
+ * Note: The new API uses a messages array instead of a query string.
10519
+ * @see AiSearchInstanceService.search
10520
+ */
10243
10521
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
10522
+ /**
10523
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
10524
+ * @see AiSearchInstanceService.chatCompletions
10525
+ */
10244
10526
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
10527
+ /**
10528
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
10529
+ * @see AiSearchInstanceService.chatCompletions
10530
+ */
10245
10531
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
10532
+ /**
10533
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
10534
+ * @see AiSearchInstanceService.chatCompletions
10535
+ */
10246
10536
  aiSearch(
10247
10537
  params: AutoRagAiSearchRequest,
10248
10538
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -11733,8 +12023,14 @@ export interface MediaTransformer {
11733
12023
  * @returns A generator for producing the transformed media output
11734
12024
  */
11735
12025
  transform(
11736
- transform: MediaTransformationInputOptions,
12026
+ transform?: MediaTransformationInputOptions,
11737
12027
  ): MediaTransformationGenerator;
12028
+ /**
12029
+ * Generates the final media output with specified options.
12030
+ * @param output - Configuration for the output format and parameters
12031
+ * @returns The final transformation result containing the transformed media
12032
+ */
12033
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11738
12034
  }
11739
12035
  /**
11740
12036
  * Generator for producing media transformation results.
@@ -11746,7 +12042,7 @@ export interface MediaTransformationGenerator {
11746
12042
  * @param output - Configuration for the output format and parameters
11747
12043
  * @returns The final transformation result containing the transformed media
11748
12044
  */
11749
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
12045
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11750
12046
  }
11751
12047
  /**
11752
12048
  * Result of a media transformation operation.
@@ -11755,19 +12051,19 @@ export interface MediaTransformationGenerator {
11755
12051
  export interface MediaTransformationResult {
11756
12052
  /**
11757
12053
  * Returns the transformed media as a readable stream of bytes.
11758
- * @returns A stream containing the transformed media data
12054
+ * @returns A promise containing a readable stream with the transformed media
11759
12055
  */
11760
- media(): ReadableStream<Uint8Array>;
12056
+ media(): Promise<ReadableStream<Uint8Array>>;
11761
12057
  /**
11762
12058
  * Returns the transformed media as an HTTP response object.
11763
- * @returns The transformed media as a Response, ready to store in cache or return to users
12059
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11764
12060
  */
11765
- response(): Response;
12061
+ response(): Promise<Response>;
11766
12062
  /**
11767
12063
  * Returns the MIME type of the transformed media.
11768
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
12064
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11769
12065
  */
11770
- contentType(): string;
12066
+ contentType(): Promise<string>;
11771
12067
  }
11772
12068
  /**
11773
12069
  * Configuration options for transforming media input.