@cloudflare/workers-types 4.20260415.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.
@@ -2319,11 +2319,34 @@ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
2319
2319
  }
2320
2320
  type QueueContentType = "text" | "bytes" | "json" | "v8";
2321
2321
  interface Queue<Body = unknown> {
2322
- send(message: Body, options?: QueueSendOptions): Promise<void>;
2322
+ metrics(): Promise<QueueMetrics>;
2323
+ send(message: Body, options?: QueueSendOptions): Promise<QueueSendResponse>;
2323
2324
  sendBatch(
2324
2325
  messages: Iterable<MessageSendRequest<Body>>,
2325
2326
  options?: QueueSendBatchOptions,
2326
- ): Promise<void>;
2327
+ ): Promise<QueueSendBatchResponse>;
2328
+ }
2329
+ interface QueueSendMetrics {
2330
+ backlogCount: number;
2331
+ backlogBytes: number;
2332
+ oldestMessageTimestamp?: Date;
2333
+ }
2334
+ interface QueueSendMetadata {
2335
+ metrics: QueueSendMetrics;
2336
+ }
2337
+ interface QueueSendResponse {
2338
+ metadata: QueueSendMetadata;
2339
+ }
2340
+ interface QueueSendBatchMetrics {
2341
+ backlogCount: number;
2342
+ backlogBytes: number;
2343
+ oldestMessageTimestamp?: Date;
2344
+ }
2345
+ interface QueueSendBatchMetadata {
2346
+ metrics: QueueSendBatchMetrics;
2347
+ }
2348
+ interface QueueSendBatchResponse {
2349
+ metadata: QueueSendBatchMetadata;
2327
2350
  }
2328
2351
  interface QueueSendOptions {
2329
2352
  contentType?: QueueContentType;
@@ -2337,6 +2360,19 @@ interface MessageSendRequest<Body = unknown> {
2337
2360
  contentType?: QueueContentType;
2338
2361
  delaySeconds?: number;
2339
2362
  }
2363
+ interface QueueMetrics {
2364
+ backlogCount: number;
2365
+ backlogBytes: number;
2366
+ oldestMessageTimestamp?: Date;
2367
+ }
2368
+ interface MessageBatchMetrics {
2369
+ backlogCount: number;
2370
+ backlogBytes: number;
2371
+ oldestMessageTimestamp?: Date;
2372
+ }
2373
+ interface MessageBatchMetadata {
2374
+ metrics: MessageBatchMetrics;
2375
+ }
2340
2376
  interface QueueRetryOptions {
2341
2377
  delaySeconds?: number;
2342
2378
  }
@@ -2351,12 +2387,14 @@ interface Message<Body = unknown> {
2351
2387
  interface QueueEvent<Body = unknown> extends ExtendableEvent {
2352
2388
  readonly messages: readonly Message<Body>[];
2353
2389
  readonly queue: string;
2390
+ readonly metadata: MessageBatchMetadata;
2354
2391
  retryAll(options?: QueueRetryOptions): void;
2355
2392
  ackAll(): void;
2356
2393
  }
2357
2394
  interface MessageBatch<Body = unknown> {
2358
2395
  readonly messages: readonly Message<Body>[];
2359
2396
  readonly queue: string;
2397
+ readonly metadata: MessageBatchMetadata;
2360
2398
  retryAll(options?: QueueRetryOptions): void;
2361
2399
  ackAll(): void;
2362
2400
  }
@@ -3953,73 +3991,145 @@ declare abstract class Performance {
3953
3991
  // ============ AI Search Error Interfaces ============
3954
3992
  interface AiSearchInternalError extends Error {}
3955
3993
  interface AiSearchNotFoundError extends Error {}
3956
- // ============ AI Search Request Types ============
3957
- type AiSearchSearchRequest = {
3958
- messages: Array<{
3959
- role: "system" | "developer" | "user" | "assistant" | "tool";
3960
- content: string | null;
3961
- }>;
3962
- ai_search_options?: {
3963
- retrieval?: {
3964
- retrieval_type?: "vector" | "keyword" | "hybrid";
3965
- /** Match threshold (0-1, default 0.4) */
3966
- match_threshold?: number;
3967
- /** Maximum number of results (1-50, default 10) */
3968
- max_num_results?: number;
3969
- filters?: VectorizeVectorMetadataFilter;
3970
- /** Context expansion (0-3, default 0) */
3971
- context_expansion?: number;
3972
- [key: string]: unknown;
3973
- };
3974
- query_rewrite?: {
3975
- enabled?: boolean;
3976
- model?: string;
3977
- rewrite_prompt?: string;
3978
- [key: string]: unknown;
3979
- };
3980
- reranking?: {
3981
- enabled?: boolean;
3982
- model?: "@cf/baai/bge-reranker-base" | string;
3983
- /** Match threshold (0-1, default 0.4) */
3984
- match_threshold?: number;
3985
- [key: string]: unknown;
3986
- };
3994
+ // ============ AI Search Common Types ============
3995
+ /** A single message in a conversation-style search or chat request. */
3996
+ type AiSearchMessage = {
3997
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3998
+ content: string | null;
3999
+ };
4000
+ /**
4001
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
4002
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
4003
+ */
4004
+ type AiSearchOptions = {
4005
+ retrieval?: {
4006
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
4007
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4008
+ /** Fusion method for combining vector + keyword results. */
4009
+ fusion_method?: "max" | "rrf";
4010
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4011
+ keyword_match_mode?: "and" | "or";
4012
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4013
+ match_threshold?: number;
4014
+ /** Maximum number of results to return (1-50). Default 10. */
4015
+ max_num_results?: number;
4016
+ /** Vectorize metadata filters applied to the search. */
4017
+ filters?: VectorizeVectorMetadataFilter;
4018
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4019
+ context_expansion?: number;
4020
+ /** If true, return only item metadata without chunk text. */
4021
+ metadata_only?: boolean;
4022
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4023
+ return_on_failure?: boolean;
4024
+ /** Boost results by metadata field values. Max 3 entries. */
4025
+ boost_by?: Array<{
4026
+ field: string;
4027
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4028
+ }>;
4029
+ [key: string]: unknown;
4030
+ };
4031
+ query_rewrite?: {
4032
+ enabled?: boolean;
4033
+ model?: string;
4034
+ rewrite_prompt?: string;
4035
+ [key: string]: unknown;
4036
+ };
4037
+ reranking?: {
4038
+ enabled?: boolean;
4039
+ model?: string;
4040
+ /** Match threshold (0-1, default 0.4) */
4041
+ match_threshold?: number;
3987
4042
  [key: string]: unknown;
3988
4043
  };
4044
+ cache?: {
4045
+ enabled?: boolean;
4046
+ cache_threshold?:
4047
+ | "super_strict_match"
4048
+ | "close_enough"
4049
+ | "flexible_friend"
4050
+ | "anything_goes";
4051
+ };
4052
+ [key: string]: unknown;
3989
4053
  };
4054
+ // ============ AI Search Request Types ============
4055
+ /**
4056
+ * Request body for single-instance search.
4057
+ * Exactly one of `query` or `messages` must be provided.
4058
+ */
4059
+ type AiSearchSearchRequest =
4060
+ | {
4061
+ /** Simple query string. */
4062
+ query: string;
4063
+ messages?: never;
4064
+ ai_search_options?: AiSearchOptions;
4065
+ }
4066
+ | {
4067
+ query?: never;
4068
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4069
+ messages: AiSearchMessage[];
4070
+ ai_search_options?: AiSearchOptions;
4071
+ };
3990
4072
  type AiSearchChatCompletionsRequest = {
3991
- messages: Array<{
3992
- role: "system" | "developer" | "user" | "assistant" | "tool";
3993
- content: string | null;
3994
- [key: string]: unknown;
3995
- }>;
4073
+ messages: AiSearchMessage[];
3996
4074
  model?: string;
3997
4075
  stream?: boolean;
3998
- ai_search_options?: {
3999
- retrieval?: {
4000
- retrieval_type?: "vector" | "keyword" | "hybrid";
4001
- match_threshold?: number;
4002
- max_num_results?: number;
4003
- filters?: VectorizeVectorMetadataFilter;
4004
- context_expansion?: number;
4005
- [key: string]: unknown;
4006
- };
4007
- query_rewrite?: {
4008
- enabled?: boolean;
4009
- model?: string;
4010
- rewrite_prompt?: string;
4011
- [key: string]: unknown;
4012
- };
4013
- reranking?: {
4014
- enabled?: boolean;
4015
- model?: "@cf/baai/bge-reranker-base" | string;
4016
- match_threshold?: number;
4017
- [key: string]: unknown;
4018
- };
4019
- [key: string]: unknown;
4020
- };
4076
+ ai_search_options?: AiSearchOptions;
4021
4077
  [key: string]: unknown;
4022
4078
  };
4079
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4080
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4081
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4082
+ /** Instance IDs to search across (1-10). */
4083
+ instance_ids: string[];
4084
+ };
4085
+ /**
4086
+ * Request for searching across multiple instances within a namespace.
4087
+ * `ai_search_options` is required and must include `instance_ids`.
4088
+ * Exactly one of `query` or `messages` must be provided.
4089
+ */
4090
+ type AiSearchMultiSearchRequest =
4091
+ | {
4092
+ /** Simple query string. */
4093
+ query: string;
4094
+ messages?: never;
4095
+ ai_search_options: AiSearchMultiSearchOptions;
4096
+ }
4097
+ | {
4098
+ query?: never;
4099
+ /** Conversation-style input. */
4100
+ messages: AiSearchMessage[];
4101
+ ai_search_options: AiSearchMultiSearchOptions;
4102
+ };
4103
+ /** A search result chunk tagged with the instance it originated from. */
4104
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4105
+ instance_id: string;
4106
+ };
4107
+ /** Describes a per-instance error during a multi-instance operation. */
4108
+ type AiSearchMultiSearchError = {
4109
+ instance_id: string;
4110
+ message: string;
4111
+ };
4112
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4113
+ type AiSearchMultiSearchResponse = {
4114
+ search_query: string;
4115
+ chunks: AiSearchMultiSearchChunk[];
4116
+ errors?: AiSearchMultiSearchError[];
4117
+ };
4118
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4119
+ type AiSearchMultiChatCompletionsRequest = Omit<
4120
+ AiSearchChatCompletionsRequest,
4121
+ "ai_search_options"
4122
+ > & {
4123
+ ai_search_options: AiSearchMultiSearchOptions;
4124
+ };
4125
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4126
+ type AiSearchMultiChatCompletionsResponse = Omit<
4127
+ AiSearchChatCompletionsResponse,
4128
+ "chunks"
4129
+ > & {
4130
+ chunks: AiSearchMultiSearchChunk[];
4131
+ errors?: AiSearchMultiSearchError[];
4132
+ };
4023
4133
  // ============ AI Search Response Types ============
4024
4134
  type AiSearchSearchResponse = {
4025
4135
  search_query: string;
@@ -4039,6 +4149,14 @@ type AiSearchSearchResponse = {
4039
4149
  keyword_score?: number;
4040
4150
  /** Vector similarity score (0-1) */
4041
4151
  vector_score?: number;
4152
+ /** Keyword rank position */
4153
+ keyword_rank?: number;
4154
+ /** Vector rank position */
4155
+ vector_rank?: number;
4156
+ /** Reranking model score */
4157
+ reranking_score?: number;
4158
+ /** Fusion method used to combine results */
4159
+ fusion_method?: "rrf" | "max";
4042
4160
  [key: string]: unknown;
4043
4161
  };
4044
4162
  }>;
@@ -4067,19 +4185,88 @@ type AiSearchStatsResponse = {
4067
4185
  skipped?: number;
4068
4186
  outdated?: number;
4069
4187
  last_activity?: string;
4188
+ /** Storage engine statistics. */
4189
+ engine?: {
4190
+ vectorize?: {
4191
+ vectorsCount: number;
4192
+ dimensions: number;
4193
+ };
4194
+ r2?: {
4195
+ payloadSizeBytes: number;
4196
+ metadataSizeBytes: number;
4197
+ objectCount: number;
4198
+ };
4199
+ };
4070
4200
  };
4071
4201
  // ============ AI Search Instance Info Types ============
4072
4202
  type AiSearchInstanceInfo = {
4073
4203
  id: string;
4074
4204
  type?: "r2" | "web-crawler" | string;
4075
4205
  source?: string;
4206
+ source_params?: unknown;
4076
4207
  paused?: boolean;
4077
4208
  status?: string;
4078
4209
  namespace?: string;
4079
4210
  created_at?: string;
4080
4211
  modified_at?: string;
4212
+ token_id?: string;
4213
+ ai_gateway_id?: string;
4214
+ rewrite_query?: boolean;
4215
+ reranking?: boolean;
4216
+ embedding_model?: string;
4217
+ ai_search_model?: string;
4218
+ rewrite_model?: string;
4219
+ reranking_model?: string;
4220
+ /** @deprecated Use index_method instead. */
4221
+ hybrid_search_enabled?: boolean;
4222
+ /** Controls which storage backends are active. */
4223
+ index_method?: {
4224
+ vector?: boolean;
4225
+ keyword?: boolean;
4226
+ };
4227
+ /** Fusion method for combining vector and keyword results. */
4228
+ fusion_method?: "max" | "rrf";
4229
+ indexing_options?: {
4230
+ keyword_tokenizer?: "porter" | "trigram";
4231
+ } | null;
4232
+ retrieval_options?: {
4233
+ keyword_match_mode?: "and" | "or";
4234
+ boost_by?: Array<{
4235
+ field: string;
4236
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4237
+ }>;
4238
+ } | null;
4239
+ chunk?: boolean;
4240
+ chunk_size?: number;
4241
+ chunk_overlap?: number;
4242
+ score_threshold?: number;
4243
+ max_num_results?: number;
4244
+ cache?: boolean;
4245
+ cache_threshold?:
4246
+ | "super_strict_match"
4247
+ | "close_enough"
4248
+ | "flexible_friend"
4249
+ | "anything_goes";
4250
+ custom_metadata?: Array<{
4251
+ field_name: string;
4252
+ data_type: "text" | "number" | "boolean" | "datetime";
4253
+ }>;
4254
+ /** Sync interval in seconds. */
4255
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4256
+ metadata?: Record<string, unknown>;
4081
4257
  [key: string]: unknown;
4082
4258
  };
4259
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4260
+ type AiSearchListInstancesParams = {
4261
+ page?: number;
4262
+ per_page?: number;
4263
+ /** Search instances by ID. */
4264
+ search?: string;
4265
+ /** Field to sort by. */
4266
+ order_by?: "created_at";
4267
+ /** Sort direction. */
4268
+ order_by_direction?: "asc" | "desc";
4269
+ };
4083
4270
  type AiSearchListResponse = {
4084
4271
  result: AiSearchInstanceInfo[];
4085
4272
  result_info?: {
@@ -4107,19 +4294,64 @@ type AiSearchConfig = {
4107
4294
  reranking?: boolean;
4108
4295
  embedding_model?: string;
4109
4296
  ai_search_model?: string;
4297
+ rewrite_model?: string;
4298
+ reranking_model?: string;
4299
+ /** @deprecated Use index_method instead. */
4300
+ hybrid_search_enabled?: boolean;
4301
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4302
+ index_method?: {
4303
+ vector?: boolean;
4304
+ keyword?: boolean;
4305
+ };
4306
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4307
+ fusion_method?: "max" | "rrf";
4308
+ indexing_options?: {
4309
+ keyword_tokenizer?: "porter" | "trigram";
4310
+ } | null;
4311
+ retrieval_options?: {
4312
+ keyword_match_mode?: "and" | "or";
4313
+ boost_by?: Array<{
4314
+ field: string;
4315
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4316
+ }>;
4317
+ } | null;
4318
+ chunk?: boolean;
4319
+ chunk_size?: number;
4320
+ chunk_overlap?: number;
4321
+ /** Minimum similarity score (0-1) for a result to be included. */
4322
+ score_threshold?: number;
4323
+ max_num_results?: number;
4324
+ cache?: boolean;
4325
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4326
+ cache_threshold?:
4327
+ | "super_strict_match"
4328
+ | "close_enough"
4329
+ | "flexible_friend"
4330
+ | "anything_goes";
4331
+ custom_metadata?: Array<{
4332
+ field_name: string;
4333
+ data_type: "text" | "number" | "boolean" | "datetime";
4334
+ }>;
4335
+ namespace?: string;
4336
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4337
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4338
+ metadata?: Record<string, unknown>;
4110
4339
  [key: string]: unknown;
4111
4340
  };
4112
4341
  // ============ AI Search Item Types ============
4113
4342
  type AiSearchItemInfo = {
4114
4343
  id: string;
4115
4344
  key: string;
4116
- status:
4117
- | "completed"
4118
- | "error"
4119
- | "skipped"
4120
- | "queued"
4121
- | "processing"
4122
- | "outdated";
4345
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4346
+ next_action?: "INDEX" | "DELETE" | null;
4347
+ error?: string;
4348
+ checksum?: string;
4349
+ namespace?: string;
4350
+ chunks_count?: number | null;
4351
+ file_size?: number | null;
4352
+ source_id?: string | null;
4353
+ last_seen_at?: string;
4354
+ created_at?: string;
4123
4355
  metadata?: Record<string, unknown>;
4124
4356
  [key: string]: unknown;
4125
4357
  };
@@ -4135,6 +4367,22 @@ type AiSearchUploadItemOptions = {
4135
4367
  type AiSearchListItemsParams = {
4136
4368
  page?: number;
4137
4369
  per_page?: number;
4370
+ /** Search items by key name. */
4371
+ search?: string;
4372
+ /** Sort order for results. */
4373
+ sort_by?: "status" | "modified_at";
4374
+ /** Filter items by processing status. */
4375
+ status?:
4376
+ | "queued"
4377
+ | "running"
4378
+ | "completed"
4379
+ | "error"
4380
+ | "skipped"
4381
+ | "outdated";
4382
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4383
+ source?: string;
4384
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4385
+ metadata_filter?: string;
4138
4386
  };
4139
4387
  type AiSearchListItemsResponse = {
4140
4388
  result: AiSearchItemInfo[];
@@ -4145,6 +4393,61 @@ type AiSearchListItemsResponse = {
4145
4393
  total_count: number;
4146
4394
  };
4147
4395
  };
4396
+ // ============ AI Search Item Logs Types ============
4397
+ type AiSearchItemLogsParams = {
4398
+ /** Maximum number of log entries to return (1-100, default 50). */
4399
+ limit?: number;
4400
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4401
+ cursor?: string;
4402
+ };
4403
+ type AiSearchItemLog = {
4404
+ timestamp: string;
4405
+ action: string;
4406
+ message: string;
4407
+ fileKey?: string;
4408
+ chunkCount?: number;
4409
+ processingTimeMs?: number;
4410
+ errorType?: string;
4411
+ };
4412
+ /** Paginated response for item processing logs (cursor-based). */
4413
+ type AiSearchItemLogsResponse = {
4414
+ result: AiSearchItemLog[];
4415
+ result_info: {
4416
+ count: number;
4417
+ per_page: number;
4418
+ cursor: string | null;
4419
+ truncated: boolean;
4420
+ };
4421
+ };
4422
+ // ============ AI Search Item Chunks Types ============
4423
+ type AiSearchItemChunksParams = {
4424
+ /** Maximum number of chunks to return (1-100, default 20). */
4425
+ limit?: number;
4426
+ /** Offset into the chunks list (default 0). */
4427
+ offset?: number;
4428
+ };
4429
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4430
+ type AiSearchItemChunk = {
4431
+ id: string;
4432
+ text: string;
4433
+ start_byte: number;
4434
+ end_byte: number;
4435
+ item?: {
4436
+ timestamp?: number;
4437
+ key: string;
4438
+ metadata?: Record<string, unknown>;
4439
+ };
4440
+ };
4441
+ /** Paginated response for item chunks (offset-based). */
4442
+ type AiSearchItemChunksResponse = {
4443
+ result: AiSearchItemChunk[];
4444
+ result_info: {
4445
+ count: number;
4446
+ total: number;
4447
+ limit: number;
4448
+ offset: number;
4449
+ };
4450
+ };
4148
4451
  // ============ AI Search Job Types ============
4149
4452
  type AiSearchJobInfo = {
4150
4453
  id: string;
@@ -4193,7 +4496,7 @@ type AiSearchJobLogsResponse = {
4193
4496
  // ============ AI Search Sub-Service Classes ============
4194
4497
  /**
4195
4498
  * Single item service for an AI Search instance.
4196
- * Provides info, delete, and download operations on a specific item.
4499
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4197
4500
  */
4198
4501
  declare abstract class AiSearchItem {
4199
4502
  /** Get metadata about this item. */
@@ -4203,6 +4506,25 @@ declare abstract class AiSearchItem {
4203
4506
  * @returns Object with body stream, content type, filename, and size.
4204
4507
  */
4205
4508
  download(): Promise<AiSearchItemContentResult>;
4509
+ /**
4510
+ * Trigger re-indexing of this item.
4511
+ * @returns The updated item info.
4512
+ */
4513
+ sync(): Promise<AiSearchItemInfo>;
4514
+ /**
4515
+ * Retrieve processing logs for this item (cursor-based pagination).
4516
+ * @param params Optional pagination parameters (limit, cursor).
4517
+ * @returns Paginated log entries for this item.
4518
+ */
4519
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4520
+ /**
4521
+ * List indexed chunks for this item (offset-based pagination).
4522
+ * @param params Optional pagination parameters (limit, offset).
4523
+ * @returns Paginated chunk entries for this item.
4524
+ */
4525
+ chunks(
4526
+ params?: AiSearchItemChunksParams,
4527
+ ): Promise<AiSearchItemChunksResponse>;
4206
4528
  }
4207
4529
  /**
4208
4530
  * Items collection service for an AI Search instance.
@@ -4212,49 +4534,64 @@ declare abstract class AiSearchItems {
4212
4534
  /** List items in this instance. */
4213
4535
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4214
4536
  /**
4215
- * Upload a file as an item.
4537
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4538
+ * filename already exists, it is overwritten and re-indexed.
4216
4539
  * @param name Filename for the uploaded item.
4217
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4540
+ * @param content File content as a ReadableStream, Blob, or string.
4218
4541
  * @param options Optional metadata to attach to the item.
4219
4542
  * @returns The created item info.
4220
4543
  */
4221
4544
  upload(
4222
4545
  name: string,
4223
- content: ReadableStream | ArrayBuffer | string,
4546
+ content: ReadableStream | Blob | string,
4224
4547
  options?: AiSearchUploadItemOptions,
4225
4548
  ): Promise<AiSearchItemInfo>;
4226
4549
  /**
4227
4550
  * Upload a file and poll until processing completes.
4551
+ * Behaves as an upsert: if an item with the same filename already exists,
4552
+ * it is overwritten and re-indexed.
4228
4553
  * @param name Filename for the uploaded item.
4229
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4230
- * @param options Optional metadata to attach to the item.
4554
+ * @param content File content as a ReadableStream, Blob, or string.
4555
+ * @param options Optional metadata and polling configuration.
4231
4556
  * @returns The item info after processing completes (or timeout).
4232
4557
  */
4233
4558
  uploadAndPoll(
4234
4559
  name: string,
4235
- content: ReadableStream | ArrayBuffer | string,
4236
- options?: AiSearchUploadItemOptions,
4560
+ content: ReadableStream | Blob | string,
4561
+ options?: AiSearchUploadItemOptions & {
4562
+ /** Polling interval in milliseconds (default 1000). */
4563
+ pollIntervalMs?: number;
4564
+ /** Maximum time to wait in milliseconds (default 30000). */
4565
+ timeoutMs?: number;
4566
+ },
4237
4567
  ): Promise<AiSearchItemInfo>;
4238
4568
  /**
4239
4569
  * Get an item by ID.
4240
4570
  * @param itemId The item identifier.
4241
- * @returns Item service for info, delete, and download operations.
4571
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4242
4572
  */
4243
4573
  get(itemId: string): AiSearchItem;
4244
- /** Delete this item from the instance.
4574
+ /**
4575
+ * Delete an item from the instance.
4245
4576
  * @param itemId The item identifier.
4246
4577
  */
4247
4578
  delete(itemId: string): Promise<void>;
4248
4579
  }
4249
4580
  /**
4250
4581
  * Single job service for an AI Search instance.
4251
- * Provides info and logs for a specific job.
4582
+ * Provides info, logs, and cancel operations for a specific job.
4252
4583
  */
4253
4584
  declare abstract class AiSearchJob {
4254
4585
  /** Get metadata about this job. */
4255
4586
  info(): Promise<AiSearchJobInfo>;
4256
4587
  /** Get logs for this job. */
4257
4588
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4589
+ /**
4590
+ * Cancel a running job.
4591
+ * @returns The updated job info.
4592
+ * @throws AiSearchNotFoundError if the job does not exist.
4593
+ */
4594
+ cancel(): Promise<AiSearchJobInfo>;
4258
4595
  }
4259
4596
  /**
4260
4597
  * Jobs collection service for an AI Search instance.
@@ -4272,7 +4609,7 @@ declare abstract class AiSearchJobs {
4272
4609
  /**
4273
4610
  * Get a job by ID.
4274
4611
  * @param jobId The job identifier.
4275
- * @returns Job service for info and logs operations.
4612
+ * @returns Job service for info, logs, and cancel operations.
4276
4613
  */
4277
4614
  get(jobId: string): AiSearchJob;
4278
4615
  }
@@ -4291,7 +4628,7 @@ declare abstract class AiSearchJobs {
4291
4628
  * // Via namespace binding
4292
4629
  * const instance = env.AI_SEARCH.get("blog");
4293
4630
  * const results = await instance.search({
4294
- * messages: [{ role: "user", content: "How does caching work?" }],
4631
+ * query: "How does caching work?",
4295
4632
  * });
4296
4633
  *
4297
4634
  * // Via single instance binding
@@ -4303,7 +4640,7 @@ declare abstract class AiSearchJobs {
4303
4640
  declare abstract class AiSearchInstance {
4304
4641
  /**
4305
4642
  * Search the AI Search instance for relevant chunks.
4306
- * @param params Search request with messages and optional AI search options.
4643
+ * @param params Search request with query or messages and optional AI search options.
4307
4644
  * @returns Search response with matching chunks and search query.
4308
4645
  */
4309
4646
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4335,7 +4672,7 @@ declare abstract class AiSearchInstance {
4335
4672
  info(): Promise<AiSearchInstanceInfo>;
4336
4673
  /**
4337
4674
  * Get instance statistics (item count, indexing status, etc.).
4338
- * @returns Statistics with counts per status and last activity time.
4675
+ * @returns Statistics with counts per status, last activity time, and engine details.
4339
4676
  */
4340
4677
  stats(): Promise<AiSearchStatsResponse>;
4341
4678
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4347,27 +4684,30 @@ declare abstract class AiSearchInstance {
4347
4684
  * Namespace-level AI Search service.
4348
4685
  *
4349
4686
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4350
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4687
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4688
+ * and multi-instance search/chat operations.
4351
4689
  *
4352
4690
  * @example
4353
4691
  * ```ts
4354
4692
  * // Access an instance within the namespace
4355
4693
  * const blog = env.AI_SEARCH.get("blog");
4356
- * const results = await blog.search({
4357
- * messages: [{ role: "user", content: "How does caching work?" }],
4358
- * });
4694
+ * const results = await blog.search({ query: "How does caching work?" });
4359
4695
  *
4360
4696
  * // List all instances in the namespace
4361
4697
  * const instances = await env.AI_SEARCH.list();
4362
4698
  *
4363
4699
  * // Create a new instance with built-in storage
4364
- * const tenant = await env.AI_SEARCH.create({
4365
- * id: "tenant-123",
4366
- * });
4700
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4367
4701
  *
4368
4702
  * // Upload items into the instance
4369
4703
  * await tenant.items.upload("doc.pdf", fileContent);
4370
4704
  *
4705
+ * // Search across multiple instances
4706
+ * const multi = await env.AI_SEARCH.search({
4707
+ * query: "caching",
4708
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4709
+ * });
4710
+ *
4371
4711
  * // Delete an instance
4372
4712
  * await env.AI_SEARCH.delete("tenant-123");
4373
4713
  * ```
@@ -4380,10 +4720,11 @@ declare abstract class AiSearchNamespace {
4380
4720
  */
4381
4721
  get(name: string): AiSearchInstance;
4382
4722
  /**
4383
- * List all instances in the bound namespace.
4384
- * @returns Array of instance metadata.
4723
+ * List instances in the bound namespace.
4724
+ * @param params Optional pagination, search, and ordering parameters.
4725
+ * @returns Array of instance metadata with pagination info.
4385
4726
  */
4386
- list(): Promise<AiSearchListResponse>;
4727
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4387
4728
  /**
4388
4729
  * Create a new instance within the bound namespace.
4389
4730
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4408,6 +4749,35 @@ declare abstract class AiSearchNamespace {
4408
4749
  * @param name Instance name to delete.
4409
4750
  */
4410
4751
  delete(name: string): Promise<void>;
4752
+ /**
4753
+ * Search across multiple instances within the bound namespace.
4754
+ * Fans out to the specified instance_ids and merges results.
4755
+ * @param params Search request with required `ai_search_options.instance_ids`.
4756
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4757
+ */
4758
+ search(
4759
+ params: AiSearchMultiSearchRequest,
4760
+ ): Promise<AiSearchMultiSearchResponse>;
4761
+ /**
4762
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4763
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4764
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4765
+ * @returns ReadableStream of server-sent events.
4766
+ */
4767
+ chatCompletions(
4768
+ params: AiSearchMultiChatCompletionsRequest & {
4769
+ stream: true;
4770
+ },
4771
+ ): Promise<ReadableStream>;
4772
+ /**
4773
+ * Generate chat completions across multiple instances within the bound namespace.
4774
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4775
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4776
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4777
+ */
4778
+ chatCompletions(
4779
+ params: AiSearchMultiChatCompletionsRequest,
4780
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4411
4781
  }
4412
4782
  type AiImageClassificationInput = {
4413
4783
  image: number[];
@@ -12059,8 +12429,8 @@ declare module "cloudflare:email" {
12059
12429
  * Evaluation context for targeting rules.
12060
12430
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12061
12431
  */
12062
- type EvaluationContext = Record<string, string | number | boolean>;
12063
- interface EvaluationDetails<T> {
12432
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12433
+ interface FlagshipEvaluationDetails<T> {
12064
12434
  flagKey: string;
12065
12435
  value: T;
12066
12436
  variant?: string | undefined;
@@ -12068,7 +12438,7 @@ interface EvaluationDetails<T> {
12068
12438
  errorCode?: string | undefined;
12069
12439
  errorMessage?: string | undefined;
12070
12440
  }
12071
- interface FlagEvaluationError extends Error {}
12441
+ interface FlagshipEvaluationError extends Error {}
12072
12442
  /**
12073
12443
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12074
12444
  *
@@ -12088,7 +12458,7 @@ interface FlagEvaluationError extends Error {}
12088
12458
  * console.log(details.variant, details.reason);
12089
12459
  * ```
12090
12460
  */
12091
- declare abstract class Flags {
12461
+ declare abstract class Flagship {
12092
12462
  /**
12093
12463
  * Get a flag value without type checking.
12094
12464
  * @param flagKey The key of the flag to evaluate.
@@ -12098,7 +12468,7 @@ declare abstract class Flags {
12098
12468
  get(
12099
12469
  flagKey: string,
12100
12470
  defaultValue?: unknown,
12101
- context?: EvaluationContext,
12471
+ context?: FlagshipEvaluationContext,
12102
12472
  ): Promise<unknown>;
12103
12473
  /**
12104
12474
  * Get a boolean flag value.
@@ -12109,7 +12479,7 @@ declare abstract class Flags {
12109
12479
  getBooleanValue(
12110
12480
  flagKey: string,
12111
12481
  defaultValue: boolean,
12112
- context?: EvaluationContext,
12482
+ context?: FlagshipEvaluationContext,
12113
12483
  ): Promise<boolean>;
12114
12484
  /**
12115
12485
  * Get a string flag value.
@@ -12120,7 +12490,7 @@ declare abstract class Flags {
12120
12490
  getStringValue(
12121
12491
  flagKey: string,
12122
12492
  defaultValue: string,
12123
- context?: EvaluationContext,
12493
+ context?: FlagshipEvaluationContext,
12124
12494
  ): Promise<string>;
12125
12495
  /**
12126
12496
  * Get a number flag value.
@@ -12131,7 +12501,7 @@ declare abstract class Flags {
12131
12501
  getNumberValue(
12132
12502
  flagKey: string,
12133
12503
  defaultValue: number,
12134
- context?: EvaluationContext,
12504
+ context?: FlagshipEvaluationContext,
12135
12505
  ): Promise<number>;
12136
12506
  /**
12137
12507
  * Get an object flag value.
@@ -12142,7 +12512,7 @@ declare abstract class Flags {
12142
12512
  getObjectValue<T extends object>(
12143
12513
  flagKey: string,
12144
12514
  defaultValue: T,
12145
- context?: EvaluationContext,
12515
+ context?: FlagshipEvaluationContext,
12146
12516
  ): Promise<T>;
12147
12517
  /**
12148
12518
  * Get a boolean flag value with full evaluation details.
@@ -12153,8 +12523,8 @@ declare abstract class Flags {
12153
12523
  getBooleanDetails(
12154
12524
  flagKey: string,
12155
12525
  defaultValue: boolean,
12156
- context?: EvaluationContext,
12157
- ): Promise<EvaluationDetails<boolean>>;
12526
+ context?: FlagshipEvaluationContext,
12527
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12158
12528
  /**
12159
12529
  * Get a string flag value with full evaluation details.
12160
12530
  * @param flagKey The key of the flag to evaluate.
@@ -12164,8 +12534,8 @@ declare abstract class Flags {
12164
12534
  getStringDetails(
12165
12535
  flagKey: string,
12166
12536
  defaultValue: string,
12167
- context?: EvaluationContext,
12168
- ): Promise<EvaluationDetails<string>>;
12537
+ context?: FlagshipEvaluationContext,
12538
+ ): Promise<FlagshipEvaluationDetails<string>>;
12169
12539
  /**
12170
12540
  * Get a number flag value with full evaluation details.
12171
12541
  * @param flagKey The key of the flag to evaluate.
@@ -12175,8 +12545,8 @@ declare abstract class Flags {
12175
12545
  getNumberDetails(
12176
12546
  flagKey: string,
12177
12547
  defaultValue: number,
12178
- context?: EvaluationContext,
12179
- ): Promise<EvaluationDetails<number>>;
12548
+ context?: FlagshipEvaluationContext,
12549
+ ): Promise<FlagshipEvaluationDetails<number>>;
12180
12550
  /**
12181
12551
  * Get an object flag value with full evaluation details.
12182
12552
  * @param flagKey The key of the flag to evaluate.
@@ -12186,8 +12556,8 @@ declare abstract class Flags {
12186
12556
  getObjectDetails<T extends object>(
12187
12557
  flagKey: string,
12188
12558
  defaultValue: T,
12189
- context?: EvaluationContext,
12190
- ): Promise<EvaluationDetails<T>>;
12559
+ context?: FlagshipEvaluationContext,
12560
+ ): Promise<FlagshipEvaluationDetails<T>>;
12191
12561
  }
12192
12562
  /**
12193
12563
  * Hello World binding to serve as an explanatory example. DO NOT USE