@cloudflare/workers-types 4.20260414.1 → 4.20260416.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.
@@ -2311,11 +2311,34 @@ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
2311
2311
  }
2312
2312
  type QueueContentType = "text" | "bytes" | "json" | "v8";
2313
2313
  interface Queue<Body = unknown> {
2314
- send(message: Body, options?: QueueSendOptions): Promise<void>;
2314
+ metrics(): Promise<QueueMetrics>;
2315
+ send(message: Body, options?: QueueSendOptions): Promise<QueueSendResponse>;
2315
2316
  sendBatch(
2316
2317
  messages: Iterable<MessageSendRequest<Body>>,
2317
2318
  options?: QueueSendBatchOptions,
2318
- ): Promise<void>;
2319
+ ): Promise<QueueSendBatchResponse>;
2320
+ }
2321
+ interface QueueSendMetrics {
2322
+ backlogCount: number;
2323
+ backlogBytes: number;
2324
+ oldestMessageTimestamp?: Date;
2325
+ }
2326
+ interface QueueSendMetadata {
2327
+ metrics: QueueSendMetrics;
2328
+ }
2329
+ interface QueueSendResponse {
2330
+ metadata: QueueSendMetadata;
2331
+ }
2332
+ interface QueueSendBatchMetrics {
2333
+ backlogCount: number;
2334
+ backlogBytes: number;
2335
+ oldestMessageTimestamp?: Date;
2336
+ }
2337
+ interface QueueSendBatchMetadata {
2338
+ metrics: QueueSendBatchMetrics;
2339
+ }
2340
+ interface QueueSendBatchResponse {
2341
+ metadata: QueueSendBatchMetadata;
2319
2342
  }
2320
2343
  interface QueueSendOptions {
2321
2344
  contentType?: QueueContentType;
@@ -2329,6 +2352,19 @@ interface MessageSendRequest<Body = unknown> {
2329
2352
  contentType?: QueueContentType;
2330
2353
  delaySeconds?: number;
2331
2354
  }
2355
+ interface QueueMetrics {
2356
+ backlogCount: number;
2357
+ backlogBytes: number;
2358
+ oldestMessageTimestamp?: Date;
2359
+ }
2360
+ interface MessageBatchMetrics {
2361
+ backlogCount: number;
2362
+ backlogBytes: number;
2363
+ oldestMessageTimestamp?: Date;
2364
+ }
2365
+ interface MessageBatchMetadata {
2366
+ metrics: MessageBatchMetrics;
2367
+ }
2332
2368
  interface QueueRetryOptions {
2333
2369
  delaySeconds?: number;
2334
2370
  }
@@ -2343,12 +2379,14 @@ interface Message<Body = unknown> {
2343
2379
  interface QueueEvent<Body = unknown> extends ExtendableEvent {
2344
2380
  readonly messages: readonly Message<Body>[];
2345
2381
  readonly queue: string;
2382
+ readonly metadata: MessageBatchMetadata;
2346
2383
  retryAll(options?: QueueRetryOptions): void;
2347
2384
  ackAll(): void;
2348
2385
  }
2349
2386
  interface MessageBatch<Body = unknown> {
2350
2387
  readonly messages: readonly Message<Body>[];
2351
2388
  readonly queue: string;
2389
+ readonly metadata: MessageBatchMetadata;
2352
2390
  retryAll(options?: QueueRetryOptions): void;
2353
2391
  ackAll(): void;
2354
2392
  }
@@ -3945,73 +3983,145 @@ declare abstract class Performance {
3945
3983
  // ============ AI Search Error Interfaces ============
3946
3984
  interface AiSearchInternalError extends Error {}
3947
3985
  interface AiSearchNotFoundError extends Error {}
3948
- // ============ AI Search Request Types ============
3949
- type AiSearchSearchRequest = {
3950
- messages: Array<{
3951
- role: "system" | "developer" | "user" | "assistant" | "tool";
3952
- content: string | null;
3953
- }>;
3954
- ai_search_options?: {
3955
- retrieval?: {
3956
- retrieval_type?: "vector" | "keyword" | "hybrid";
3957
- /** Match threshold (0-1, default 0.4) */
3958
- match_threshold?: number;
3959
- /** Maximum number of results (1-50, default 10) */
3960
- max_num_results?: number;
3961
- filters?: VectorizeVectorMetadataFilter;
3962
- /** Context expansion (0-3, default 0) */
3963
- context_expansion?: number;
3964
- [key: string]: unknown;
3965
- };
3966
- query_rewrite?: {
3967
- enabled?: boolean;
3968
- model?: string;
3969
- rewrite_prompt?: string;
3970
- [key: string]: unknown;
3971
- };
3972
- reranking?: {
3973
- enabled?: boolean;
3974
- model?: "@cf/baai/bge-reranker-base" | string;
3975
- /** Match threshold (0-1, default 0.4) */
3976
- match_threshold?: number;
3977
- [key: string]: unknown;
3978
- };
3986
+ // ============ AI Search Common Types ============
3987
+ /** A single message in a conversation-style search or chat request. */
3988
+ type AiSearchMessage = {
3989
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3990
+ content: string | null;
3991
+ };
3992
+ /**
3993
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
3994
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
3995
+ */
3996
+ type AiSearchOptions = {
3997
+ retrieval?: {
3998
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
3999
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4000
+ /** Fusion method for combining vector + keyword results. */
4001
+ fusion_method?: "max" | "rrf";
4002
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4003
+ keyword_match_mode?: "and" | "or";
4004
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4005
+ match_threshold?: number;
4006
+ /** Maximum number of results to return (1-50). Default 10. */
4007
+ max_num_results?: number;
4008
+ /** Vectorize metadata filters applied to the search. */
4009
+ filters?: VectorizeVectorMetadataFilter;
4010
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4011
+ context_expansion?: number;
4012
+ /** If true, return only item metadata without chunk text. */
4013
+ metadata_only?: boolean;
4014
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4015
+ return_on_failure?: boolean;
4016
+ /** Boost results by metadata field values. Max 3 entries. */
4017
+ boost_by?: Array<{
4018
+ field: string;
4019
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4020
+ }>;
4021
+ [key: string]: unknown;
4022
+ };
4023
+ query_rewrite?: {
4024
+ enabled?: boolean;
4025
+ model?: string;
4026
+ rewrite_prompt?: string;
4027
+ [key: string]: unknown;
4028
+ };
4029
+ reranking?: {
4030
+ enabled?: boolean;
4031
+ model?: string;
4032
+ /** Match threshold (0-1, default 0.4) */
4033
+ match_threshold?: number;
3979
4034
  [key: string]: unknown;
3980
4035
  };
4036
+ cache?: {
4037
+ enabled?: boolean;
4038
+ cache_threshold?:
4039
+ | "super_strict_match"
4040
+ | "close_enough"
4041
+ | "flexible_friend"
4042
+ | "anything_goes";
4043
+ };
4044
+ [key: string]: unknown;
3981
4045
  };
4046
+ // ============ AI Search Request Types ============
4047
+ /**
4048
+ * Request body for single-instance search.
4049
+ * Exactly one of `query` or `messages` must be provided.
4050
+ */
4051
+ type AiSearchSearchRequest =
4052
+ | {
4053
+ /** Simple query string. */
4054
+ query: string;
4055
+ messages?: never;
4056
+ ai_search_options?: AiSearchOptions;
4057
+ }
4058
+ | {
4059
+ query?: never;
4060
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4061
+ messages: AiSearchMessage[];
4062
+ ai_search_options?: AiSearchOptions;
4063
+ };
3982
4064
  type AiSearchChatCompletionsRequest = {
3983
- messages: Array<{
3984
- role: "system" | "developer" | "user" | "assistant" | "tool";
3985
- content: string | null;
3986
- [key: string]: unknown;
3987
- }>;
4065
+ messages: AiSearchMessage[];
3988
4066
  model?: string;
3989
4067
  stream?: boolean;
3990
- ai_search_options?: {
3991
- retrieval?: {
3992
- retrieval_type?: "vector" | "keyword" | "hybrid";
3993
- match_threshold?: number;
3994
- max_num_results?: number;
3995
- filters?: VectorizeVectorMetadataFilter;
3996
- context_expansion?: number;
3997
- [key: string]: unknown;
3998
- };
3999
- query_rewrite?: {
4000
- enabled?: boolean;
4001
- model?: string;
4002
- rewrite_prompt?: string;
4003
- [key: string]: unknown;
4004
- };
4005
- reranking?: {
4006
- enabled?: boolean;
4007
- model?: "@cf/baai/bge-reranker-base" | string;
4008
- match_threshold?: number;
4009
- [key: string]: unknown;
4010
- };
4011
- [key: string]: unknown;
4012
- };
4068
+ ai_search_options?: AiSearchOptions;
4013
4069
  [key: string]: unknown;
4014
4070
  };
4071
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4072
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4073
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4074
+ /** Instance IDs to search across (1-10). */
4075
+ instance_ids: string[];
4076
+ };
4077
+ /**
4078
+ * Request for searching across multiple instances within a namespace.
4079
+ * `ai_search_options` is required and must include `instance_ids`.
4080
+ * Exactly one of `query` or `messages` must be provided.
4081
+ */
4082
+ type AiSearchMultiSearchRequest =
4083
+ | {
4084
+ /** Simple query string. */
4085
+ query: string;
4086
+ messages?: never;
4087
+ ai_search_options: AiSearchMultiSearchOptions;
4088
+ }
4089
+ | {
4090
+ query?: never;
4091
+ /** Conversation-style input. */
4092
+ messages: AiSearchMessage[];
4093
+ ai_search_options: AiSearchMultiSearchOptions;
4094
+ };
4095
+ /** A search result chunk tagged with the instance it originated from. */
4096
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4097
+ instance_id: string;
4098
+ };
4099
+ /** Describes a per-instance error during a multi-instance operation. */
4100
+ type AiSearchMultiSearchError = {
4101
+ instance_id: string;
4102
+ message: string;
4103
+ };
4104
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4105
+ type AiSearchMultiSearchResponse = {
4106
+ search_query: string;
4107
+ chunks: AiSearchMultiSearchChunk[];
4108
+ errors?: AiSearchMultiSearchError[];
4109
+ };
4110
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4111
+ type AiSearchMultiChatCompletionsRequest = Omit<
4112
+ AiSearchChatCompletionsRequest,
4113
+ "ai_search_options"
4114
+ > & {
4115
+ ai_search_options: AiSearchMultiSearchOptions;
4116
+ };
4117
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4118
+ type AiSearchMultiChatCompletionsResponse = Omit<
4119
+ AiSearchChatCompletionsResponse,
4120
+ "chunks"
4121
+ > & {
4122
+ chunks: AiSearchMultiSearchChunk[];
4123
+ errors?: AiSearchMultiSearchError[];
4124
+ };
4015
4125
  // ============ AI Search Response Types ============
4016
4126
  type AiSearchSearchResponse = {
4017
4127
  search_query: string;
@@ -4031,6 +4141,14 @@ type AiSearchSearchResponse = {
4031
4141
  keyword_score?: number;
4032
4142
  /** Vector similarity score (0-1) */
4033
4143
  vector_score?: number;
4144
+ /** Keyword rank position */
4145
+ keyword_rank?: number;
4146
+ /** Vector rank position */
4147
+ vector_rank?: number;
4148
+ /** Reranking model score */
4149
+ reranking_score?: number;
4150
+ /** Fusion method used to combine results */
4151
+ fusion_method?: "rrf" | "max";
4034
4152
  [key: string]: unknown;
4035
4153
  };
4036
4154
  }>;
@@ -4059,19 +4177,88 @@ type AiSearchStatsResponse = {
4059
4177
  skipped?: number;
4060
4178
  outdated?: number;
4061
4179
  last_activity?: string;
4180
+ /** Storage engine statistics. */
4181
+ engine?: {
4182
+ vectorize?: {
4183
+ vectorsCount: number;
4184
+ dimensions: number;
4185
+ };
4186
+ r2?: {
4187
+ payloadSizeBytes: number;
4188
+ metadataSizeBytes: number;
4189
+ objectCount: number;
4190
+ };
4191
+ };
4062
4192
  };
4063
4193
  // ============ AI Search Instance Info Types ============
4064
4194
  type AiSearchInstanceInfo = {
4065
4195
  id: string;
4066
4196
  type?: "r2" | "web-crawler" | string;
4067
4197
  source?: string;
4198
+ source_params?: unknown;
4068
4199
  paused?: boolean;
4069
4200
  status?: string;
4070
4201
  namespace?: string;
4071
4202
  created_at?: string;
4072
4203
  modified_at?: string;
4204
+ token_id?: string;
4205
+ ai_gateway_id?: string;
4206
+ rewrite_query?: boolean;
4207
+ reranking?: boolean;
4208
+ embedding_model?: string;
4209
+ ai_search_model?: string;
4210
+ rewrite_model?: string;
4211
+ reranking_model?: string;
4212
+ /** @deprecated Use index_method instead. */
4213
+ hybrid_search_enabled?: boolean;
4214
+ /** Controls which storage backends are active. */
4215
+ index_method?: {
4216
+ vector?: boolean;
4217
+ keyword?: boolean;
4218
+ };
4219
+ /** Fusion method for combining vector and keyword results. */
4220
+ fusion_method?: "max" | "rrf";
4221
+ indexing_options?: {
4222
+ keyword_tokenizer?: "porter" | "trigram";
4223
+ } | null;
4224
+ retrieval_options?: {
4225
+ keyword_match_mode?: "and" | "or";
4226
+ boost_by?: Array<{
4227
+ field: string;
4228
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4229
+ }>;
4230
+ } | null;
4231
+ chunk?: boolean;
4232
+ chunk_size?: number;
4233
+ chunk_overlap?: number;
4234
+ score_threshold?: number;
4235
+ max_num_results?: number;
4236
+ cache?: boolean;
4237
+ cache_threshold?:
4238
+ | "super_strict_match"
4239
+ | "close_enough"
4240
+ | "flexible_friend"
4241
+ | "anything_goes";
4242
+ custom_metadata?: Array<{
4243
+ field_name: string;
4244
+ data_type: "text" | "number" | "boolean" | "datetime";
4245
+ }>;
4246
+ /** Sync interval in seconds. */
4247
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4248
+ metadata?: Record<string, unknown>;
4073
4249
  [key: string]: unknown;
4074
4250
  };
4251
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4252
+ type AiSearchListInstancesParams = {
4253
+ page?: number;
4254
+ per_page?: number;
4255
+ /** Search instances by ID. */
4256
+ search?: string;
4257
+ /** Field to sort by. */
4258
+ order_by?: "created_at";
4259
+ /** Sort direction. */
4260
+ order_by_direction?: "asc" | "desc";
4261
+ };
4075
4262
  type AiSearchListResponse = {
4076
4263
  result: AiSearchInstanceInfo[];
4077
4264
  result_info?: {
@@ -4099,19 +4286,64 @@ type AiSearchConfig = {
4099
4286
  reranking?: boolean;
4100
4287
  embedding_model?: string;
4101
4288
  ai_search_model?: string;
4289
+ rewrite_model?: string;
4290
+ reranking_model?: string;
4291
+ /** @deprecated Use index_method instead. */
4292
+ hybrid_search_enabled?: boolean;
4293
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4294
+ index_method?: {
4295
+ vector?: boolean;
4296
+ keyword?: boolean;
4297
+ };
4298
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4299
+ fusion_method?: "max" | "rrf";
4300
+ indexing_options?: {
4301
+ keyword_tokenizer?: "porter" | "trigram";
4302
+ } | null;
4303
+ retrieval_options?: {
4304
+ keyword_match_mode?: "and" | "or";
4305
+ boost_by?: Array<{
4306
+ field: string;
4307
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4308
+ }>;
4309
+ } | null;
4310
+ chunk?: boolean;
4311
+ chunk_size?: number;
4312
+ chunk_overlap?: number;
4313
+ /** Minimum similarity score (0-1) for a result to be included. */
4314
+ score_threshold?: number;
4315
+ max_num_results?: number;
4316
+ cache?: boolean;
4317
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4318
+ cache_threshold?:
4319
+ | "super_strict_match"
4320
+ | "close_enough"
4321
+ | "flexible_friend"
4322
+ | "anything_goes";
4323
+ custom_metadata?: Array<{
4324
+ field_name: string;
4325
+ data_type: "text" | "number" | "boolean" | "datetime";
4326
+ }>;
4327
+ namespace?: string;
4328
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4329
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4330
+ metadata?: Record<string, unknown>;
4102
4331
  [key: string]: unknown;
4103
4332
  };
4104
4333
  // ============ AI Search Item Types ============
4105
4334
  type AiSearchItemInfo = {
4106
4335
  id: string;
4107
4336
  key: string;
4108
- status:
4109
- | "completed"
4110
- | "error"
4111
- | "skipped"
4112
- | "queued"
4113
- | "processing"
4114
- | "outdated";
4337
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4338
+ next_action?: "INDEX" | "DELETE" | null;
4339
+ error?: string;
4340
+ checksum?: string;
4341
+ namespace?: string;
4342
+ chunks_count?: number | null;
4343
+ file_size?: number | null;
4344
+ source_id?: string | null;
4345
+ last_seen_at?: string;
4346
+ created_at?: string;
4115
4347
  metadata?: Record<string, unknown>;
4116
4348
  [key: string]: unknown;
4117
4349
  };
@@ -4127,6 +4359,22 @@ type AiSearchUploadItemOptions = {
4127
4359
  type AiSearchListItemsParams = {
4128
4360
  page?: number;
4129
4361
  per_page?: number;
4362
+ /** Search items by key name. */
4363
+ search?: string;
4364
+ /** Sort order for results. */
4365
+ sort_by?: "status" | "modified_at";
4366
+ /** Filter items by processing status. */
4367
+ status?:
4368
+ | "queued"
4369
+ | "running"
4370
+ | "completed"
4371
+ | "error"
4372
+ | "skipped"
4373
+ | "outdated";
4374
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4375
+ source?: string;
4376
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4377
+ metadata_filter?: string;
4130
4378
  };
4131
4379
  type AiSearchListItemsResponse = {
4132
4380
  result: AiSearchItemInfo[];
@@ -4137,6 +4385,61 @@ type AiSearchListItemsResponse = {
4137
4385
  total_count: number;
4138
4386
  };
4139
4387
  };
4388
+ // ============ AI Search Item Logs Types ============
4389
+ type AiSearchItemLogsParams = {
4390
+ /** Maximum number of log entries to return (1-100, default 50). */
4391
+ limit?: number;
4392
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4393
+ cursor?: string;
4394
+ };
4395
+ type AiSearchItemLog = {
4396
+ timestamp: string;
4397
+ action: string;
4398
+ message: string;
4399
+ fileKey?: string;
4400
+ chunkCount?: number;
4401
+ processingTimeMs?: number;
4402
+ errorType?: string;
4403
+ };
4404
+ /** Paginated response for item processing logs (cursor-based). */
4405
+ type AiSearchItemLogsResponse = {
4406
+ result: AiSearchItemLog[];
4407
+ result_info: {
4408
+ count: number;
4409
+ per_page: number;
4410
+ cursor: string | null;
4411
+ truncated: boolean;
4412
+ };
4413
+ };
4414
+ // ============ AI Search Item Chunks Types ============
4415
+ type AiSearchItemChunksParams = {
4416
+ /** Maximum number of chunks to return (1-100, default 20). */
4417
+ limit?: number;
4418
+ /** Offset into the chunks list (default 0). */
4419
+ offset?: number;
4420
+ };
4421
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4422
+ type AiSearchItemChunk = {
4423
+ id: string;
4424
+ text: string;
4425
+ start_byte: number;
4426
+ end_byte: number;
4427
+ item?: {
4428
+ timestamp?: number;
4429
+ key: string;
4430
+ metadata?: Record<string, unknown>;
4431
+ };
4432
+ };
4433
+ /** Paginated response for item chunks (offset-based). */
4434
+ type AiSearchItemChunksResponse = {
4435
+ result: AiSearchItemChunk[];
4436
+ result_info: {
4437
+ count: number;
4438
+ total: number;
4439
+ limit: number;
4440
+ offset: number;
4441
+ };
4442
+ };
4140
4443
  // ============ AI Search Job Types ============
4141
4444
  type AiSearchJobInfo = {
4142
4445
  id: string;
@@ -4185,7 +4488,7 @@ type AiSearchJobLogsResponse = {
4185
4488
  // ============ AI Search Sub-Service Classes ============
4186
4489
  /**
4187
4490
  * Single item service for an AI Search instance.
4188
- * Provides info, delete, and download operations on a specific item.
4491
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4189
4492
  */
4190
4493
  declare abstract class AiSearchItem {
4191
4494
  /** Get metadata about this item. */
@@ -4195,6 +4498,25 @@ declare abstract class AiSearchItem {
4195
4498
  * @returns Object with body stream, content type, filename, and size.
4196
4499
  */
4197
4500
  download(): Promise<AiSearchItemContentResult>;
4501
+ /**
4502
+ * Trigger re-indexing of this item.
4503
+ * @returns The updated item info.
4504
+ */
4505
+ sync(): Promise<AiSearchItemInfo>;
4506
+ /**
4507
+ * Retrieve processing logs for this item (cursor-based pagination).
4508
+ * @param params Optional pagination parameters (limit, cursor).
4509
+ * @returns Paginated log entries for this item.
4510
+ */
4511
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4512
+ /**
4513
+ * List indexed chunks for this item (offset-based pagination).
4514
+ * @param params Optional pagination parameters (limit, offset).
4515
+ * @returns Paginated chunk entries for this item.
4516
+ */
4517
+ chunks(
4518
+ params?: AiSearchItemChunksParams,
4519
+ ): Promise<AiSearchItemChunksResponse>;
4198
4520
  }
4199
4521
  /**
4200
4522
  * Items collection service for an AI Search instance.
@@ -4204,49 +4526,64 @@ declare abstract class AiSearchItems {
4204
4526
  /** List items in this instance. */
4205
4527
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4206
4528
  /**
4207
- * Upload a file as an item.
4529
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4530
+ * filename already exists, it is overwritten and re-indexed.
4208
4531
  * @param name Filename for the uploaded item.
4209
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4532
+ * @param content File content as a ReadableStream, Blob, or string.
4210
4533
  * @param options Optional metadata to attach to the item.
4211
4534
  * @returns The created item info.
4212
4535
  */
4213
4536
  upload(
4214
4537
  name: string,
4215
- content: ReadableStream | ArrayBuffer | string,
4538
+ content: ReadableStream | Blob | string,
4216
4539
  options?: AiSearchUploadItemOptions,
4217
4540
  ): Promise<AiSearchItemInfo>;
4218
4541
  /**
4219
4542
  * Upload a file and poll until processing completes.
4543
+ * Behaves as an upsert: if an item with the same filename already exists,
4544
+ * it is overwritten and re-indexed.
4220
4545
  * @param name Filename for the uploaded item.
4221
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4222
- * @param options Optional metadata to attach to the item.
4546
+ * @param content File content as a ReadableStream, Blob, or string.
4547
+ * @param options Optional metadata and polling configuration.
4223
4548
  * @returns The item info after processing completes (or timeout).
4224
4549
  */
4225
4550
  uploadAndPoll(
4226
4551
  name: string,
4227
- content: ReadableStream | ArrayBuffer | string,
4228
- options?: AiSearchUploadItemOptions,
4552
+ content: ReadableStream | Blob | string,
4553
+ options?: AiSearchUploadItemOptions & {
4554
+ /** Polling interval in milliseconds (default 1000). */
4555
+ pollIntervalMs?: number;
4556
+ /** Maximum time to wait in milliseconds (default 30000). */
4557
+ timeoutMs?: number;
4558
+ },
4229
4559
  ): Promise<AiSearchItemInfo>;
4230
4560
  /**
4231
4561
  * Get an item by ID.
4232
4562
  * @param itemId The item identifier.
4233
- * @returns Item service for info, delete, and download operations.
4563
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4234
4564
  */
4235
4565
  get(itemId: string): AiSearchItem;
4236
- /** Delete this item from the instance.
4566
+ /**
4567
+ * Delete an item from the instance.
4237
4568
  * @param itemId The item identifier.
4238
4569
  */
4239
4570
  delete(itemId: string): Promise<void>;
4240
4571
  }
4241
4572
  /**
4242
4573
  * Single job service for an AI Search instance.
4243
- * Provides info and logs for a specific job.
4574
+ * Provides info, logs, and cancel operations for a specific job.
4244
4575
  */
4245
4576
  declare abstract class AiSearchJob {
4246
4577
  /** Get metadata about this job. */
4247
4578
  info(): Promise<AiSearchJobInfo>;
4248
4579
  /** Get logs for this job. */
4249
4580
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4581
+ /**
4582
+ * Cancel a running job.
4583
+ * @returns The updated job info.
4584
+ * @throws AiSearchNotFoundError if the job does not exist.
4585
+ */
4586
+ cancel(): Promise<AiSearchJobInfo>;
4250
4587
  }
4251
4588
  /**
4252
4589
  * Jobs collection service for an AI Search instance.
@@ -4264,7 +4601,7 @@ declare abstract class AiSearchJobs {
4264
4601
  /**
4265
4602
  * Get a job by ID.
4266
4603
  * @param jobId The job identifier.
4267
- * @returns Job service for info and logs operations.
4604
+ * @returns Job service for info, logs, and cancel operations.
4268
4605
  */
4269
4606
  get(jobId: string): AiSearchJob;
4270
4607
  }
@@ -4283,7 +4620,7 @@ declare abstract class AiSearchJobs {
4283
4620
  * // Via namespace binding
4284
4621
  * const instance = env.AI_SEARCH.get("blog");
4285
4622
  * const results = await instance.search({
4286
- * messages: [{ role: "user", content: "How does caching work?" }],
4623
+ * query: "How does caching work?",
4287
4624
  * });
4288
4625
  *
4289
4626
  * // Via single instance binding
@@ -4295,7 +4632,7 @@ declare abstract class AiSearchJobs {
4295
4632
  declare abstract class AiSearchInstance {
4296
4633
  /**
4297
4634
  * Search the AI Search instance for relevant chunks.
4298
- * @param params Search request with messages and optional AI search options.
4635
+ * @param params Search request with query or messages and optional AI search options.
4299
4636
  * @returns Search response with matching chunks and search query.
4300
4637
  */
4301
4638
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4327,7 +4664,7 @@ declare abstract class AiSearchInstance {
4327
4664
  info(): Promise<AiSearchInstanceInfo>;
4328
4665
  /**
4329
4666
  * Get instance statistics (item count, indexing status, etc.).
4330
- * @returns Statistics with counts per status and last activity time.
4667
+ * @returns Statistics with counts per status, last activity time, and engine details.
4331
4668
  */
4332
4669
  stats(): Promise<AiSearchStatsResponse>;
4333
4670
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4339,27 +4676,30 @@ declare abstract class AiSearchInstance {
4339
4676
  * Namespace-level AI Search service.
4340
4677
  *
4341
4678
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4342
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4679
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4680
+ * and multi-instance search/chat operations.
4343
4681
  *
4344
4682
  * @example
4345
4683
  * ```ts
4346
4684
  * // Access an instance within the namespace
4347
4685
  * const blog = env.AI_SEARCH.get("blog");
4348
- * const results = await blog.search({
4349
- * messages: [{ role: "user", content: "How does caching work?" }],
4350
- * });
4686
+ * const results = await blog.search({ query: "How does caching work?" });
4351
4687
  *
4352
4688
  * // List all instances in the namespace
4353
4689
  * const instances = await env.AI_SEARCH.list();
4354
4690
  *
4355
4691
  * // Create a new instance with built-in storage
4356
- * const tenant = await env.AI_SEARCH.create({
4357
- * id: "tenant-123",
4358
- * });
4692
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4359
4693
  *
4360
4694
  * // Upload items into the instance
4361
4695
  * await tenant.items.upload("doc.pdf", fileContent);
4362
4696
  *
4697
+ * // Search across multiple instances
4698
+ * const multi = await env.AI_SEARCH.search({
4699
+ * query: "caching",
4700
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4701
+ * });
4702
+ *
4363
4703
  * // Delete an instance
4364
4704
  * await env.AI_SEARCH.delete("tenant-123");
4365
4705
  * ```
@@ -4372,10 +4712,11 @@ declare abstract class AiSearchNamespace {
4372
4712
  */
4373
4713
  get(name: string): AiSearchInstance;
4374
4714
  /**
4375
- * List all instances in the bound namespace.
4376
- * @returns Array of instance metadata.
4715
+ * List instances in the bound namespace.
4716
+ * @param params Optional pagination, search, and ordering parameters.
4717
+ * @returns Array of instance metadata with pagination info.
4377
4718
  */
4378
- list(): Promise<AiSearchListResponse>;
4719
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4379
4720
  /**
4380
4721
  * Create a new instance within the bound namespace.
4381
4722
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4400,6 +4741,35 @@ declare abstract class AiSearchNamespace {
4400
4741
  * @param name Instance name to delete.
4401
4742
  */
4402
4743
  delete(name: string): Promise<void>;
4744
+ /**
4745
+ * Search across multiple instances within the bound namespace.
4746
+ * Fans out to the specified instance_ids and merges results.
4747
+ * @param params Search request with required `ai_search_options.instance_ids`.
4748
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4749
+ */
4750
+ search(
4751
+ params: AiSearchMultiSearchRequest,
4752
+ ): Promise<AiSearchMultiSearchResponse>;
4753
+ /**
4754
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4755
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4756
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4757
+ * @returns ReadableStream of server-sent events.
4758
+ */
4759
+ chatCompletions(
4760
+ params: AiSearchMultiChatCompletionsRequest & {
4761
+ stream: true;
4762
+ },
4763
+ ): Promise<ReadableStream>;
4764
+ /**
4765
+ * Generate chat completions across multiple instances within the bound namespace.
4766
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4767
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4768
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4769
+ */
4770
+ chatCompletions(
4771
+ params: AiSearchMultiChatCompletionsRequest,
4772
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4403
4773
  }
4404
4774
  type AiImageClassificationInput = {
4405
4775
  image: number[];
@@ -12051,8 +12421,8 @@ declare module "cloudflare:email" {
12051
12421
  * Evaluation context for targeting rules.
12052
12422
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12053
12423
  */
12054
- type EvaluationContext = Record<string, string | number | boolean>;
12055
- interface EvaluationDetails<T> {
12424
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12425
+ interface FlagshipEvaluationDetails<T> {
12056
12426
  flagKey: string;
12057
12427
  value: T;
12058
12428
  variant?: string | undefined;
@@ -12060,7 +12430,7 @@ interface EvaluationDetails<T> {
12060
12430
  errorCode?: string | undefined;
12061
12431
  errorMessage?: string | undefined;
12062
12432
  }
12063
- interface FlagEvaluationError extends Error {}
12433
+ interface FlagshipEvaluationError extends Error {}
12064
12434
  /**
12065
12435
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12066
12436
  *
@@ -12080,7 +12450,7 @@ interface FlagEvaluationError extends Error {}
12080
12450
  * console.log(details.variant, details.reason);
12081
12451
  * ```
12082
12452
  */
12083
- declare abstract class Flags {
12453
+ declare abstract class Flagship {
12084
12454
  /**
12085
12455
  * Get a flag value without type checking.
12086
12456
  * @param flagKey The key of the flag to evaluate.
@@ -12090,7 +12460,7 @@ declare abstract class Flags {
12090
12460
  get(
12091
12461
  flagKey: string,
12092
12462
  defaultValue?: unknown,
12093
- context?: EvaluationContext,
12463
+ context?: FlagshipEvaluationContext,
12094
12464
  ): Promise<unknown>;
12095
12465
  /**
12096
12466
  * Get a boolean flag value.
@@ -12101,7 +12471,7 @@ declare abstract class Flags {
12101
12471
  getBooleanValue(
12102
12472
  flagKey: string,
12103
12473
  defaultValue: boolean,
12104
- context?: EvaluationContext,
12474
+ context?: FlagshipEvaluationContext,
12105
12475
  ): Promise<boolean>;
12106
12476
  /**
12107
12477
  * Get a string flag value.
@@ -12112,7 +12482,7 @@ declare abstract class Flags {
12112
12482
  getStringValue(
12113
12483
  flagKey: string,
12114
12484
  defaultValue: string,
12115
- context?: EvaluationContext,
12485
+ context?: FlagshipEvaluationContext,
12116
12486
  ): Promise<string>;
12117
12487
  /**
12118
12488
  * Get a number flag value.
@@ -12123,7 +12493,7 @@ declare abstract class Flags {
12123
12493
  getNumberValue(
12124
12494
  flagKey: string,
12125
12495
  defaultValue: number,
12126
- context?: EvaluationContext,
12496
+ context?: FlagshipEvaluationContext,
12127
12497
  ): Promise<number>;
12128
12498
  /**
12129
12499
  * Get an object flag value.
@@ -12134,7 +12504,7 @@ declare abstract class Flags {
12134
12504
  getObjectValue<T extends object>(
12135
12505
  flagKey: string,
12136
12506
  defaultValue: T,
12137
- context?: EvaluationContext,
12507
+ context?: FlagshipEvaluationContext,
12138
12508
  ): Promise<T>;
12139
12509
  /**
12140
12510
  * Get a boolean flag value with full evaluation details.
@@ -12145,8 +12515,8 @@ declare abstract class Flags {
12145
12515
  getBooleanDetails(
12146
12516
  flagKey: string,
12147
12517
  defaultValue: boolean,
12148
- context?: EvaluationContext,
12149
- ): Promise<EvaluationDetails<boolean>>;
12518
+ context?: FlagshipEvaluationContext,
12519
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12150
12520
  /**
12151
12521
  * Get a string flag value with full evaluation details.
12152
12522
  * @param flagKey The key of the flag to evaluate.
@@ -12156,8 +12526,8 @@ declare abstract class Flags {
12156
12526
  getStringDetails(
12157
12527
  flagKey: string,
12158
12528
  defaultValue: string,
12159
- context?: EvaluationContext,
12160
- ): Promise<EvaluationDetails<string>>;
12529
+ context?: FlagshipEvaluationContext,
12530
+ ): Promise<FlagshipEvaluationDetails<string>>;
12161
12531
  /**
12162
12532
  * Get a number flag value with full evaluation details.
12163
12533
  * @param flagKey The key of the flag to evaluate.
@@ -12167,8 +12537,8 @@ declare abstract class Flags {
12167
12537
  getNumberDetails(
12168
12538
  flagKey: string,
12169
12539
  defaultValue: number,
12170
- context?: EvaluationContext,
12171
- ): Promise<EvaluationDetails<number>>;
12540
+ context?: FlagshipEvaluationContext,
12541
+ ): Promise<FlagshipEvaluationDetails<number>>;
12172
12542
  /**
12173
12543
  * Get an object flag value with full evaluation details.
12174
12544
  * @param flagKey The key of the flag to evaluate.
@@ -12178,8 +12548,8 @@ declare abstract class Flags {
12178
12548
  getObjectDetails<T extends object>(
12179
12549
  flagKey: string,
12180
12550
  defaultValue: T,
12181
- context?: EvaluationContext,
12182
- ): Promise<EvaluationDetails<T>>;
12551
+ context?: FlagshipEvaluationContext,
12552
+ ): Promise<FlagshipEvaluationDetails<T>>;
12183
12553
  }
12184
12554
  /**
12185
12555
  * Hello World binding to serve as an explanatory example. DO NOT USE