@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.
@@ -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
  }
@@ -3974,73 +4012,145 @@ declare abstract class Performance {
3974
4012
  // ============ AI Search Error Interfaces ============
3975
4013
  interface AiSearchInternalError extends Error {}
3976
4014
  interface AiSearchNotFoundError extends Error {}
3977
- // ============ AI Search Request Types ============
3978
- type AiSearchSearchRequest = {
3979
- messages: Array<{
3980
- role: "system" | "developer" | "user" | "assistant" | "tool";
3981
- content: string | null;
3982
- }>;
3983
- ai_search_options?: {
3984
- retrieval?: {
3985
- retrieval_type?: "vector" | "keyword" | "hybrid";
3986
- /** Match threshold (0-1, default 0.4) */
3987
- match_threshold?: number;
3988
- /** Maximum number of results (1-50, default 10) */
3989
- max_num_results?: number;
3990
- filters?: VectorizeVectorMetadataFilter;
3991
- /** Context expansion (0-3, default 0) */
3992
- context_expansion?: number;
3993
- [key: string]: unknown;
3994
- };
3995
- query_rewrite?: {
3996
- enabled?: boolean;
3997
- model?: string;
3998
- rewrite_prompt?: string;
3999
- [key: string]: unknown;
4000
- };
4001
- reranking?: {
4002
- enabled?: boolean;
4003
- model?: "@cf/baai/bge-reranker-base" | string;
4004
- /** Match threshold (0-1, default 0.4) */
4005
- match_threshold?: number;
4006
- [key: string]: unknown;
4007
- };
4015
+ // ============ AI Search Common Types ============
4016
+ /** A single message in a conversation-style search or chat request. */
4017
+ type AiSearchMessage = {
4018
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4019
+ content: string | null;
4020
+ };
4021
+ /**
4022
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
4023
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
4024
+ */
4025
+ type AiSearchOptions = {
4026
+ retrieval?: {
4027
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
4028
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4029
+ /** Fusion method for combining vector + keyword results. */
4030
+ fusion_method?: "max" | "rrf";
4031
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4032
+ keyword_match_mode?: "and" | "or";
4033
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4034
+ match_threshold?: number;
4035
+ /** Maximum number of results to return (1-50). Default 10. */
4036
+ max_num_results?: number;
4037
+ /** Vectorize metadata filters applied to the search. */
4038
+ filters?: VectorizeVectorMetadataFilter;
4039
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4040
+ context_expansion?: number;
4041
+ /** If true, return only item metadata without chunk text. */
4042
+ metadata_only?: boolean;
4043
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4044
+ return_on_failure?: boolean;
4045
+ /** Boost results by metadata field values. Max 3 entries. */
4046
+ boost_by?: Array<{
4047
+ field: string;
4048
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4049
+ }>;
4050
+ [key: string]: unknown;
4051
+ };
4052
+ query_rewrite?: {
4053
+ enabled?: boolean;
4054
+ model?: string;
4055
+ rewrite_prompt?: string;
4056
+ [key: string]: unknown;
4057
+ };
4058
+ reranking?: {
4059
+ enabled?: boolean;
4060
+ model?: string;
4061
+ /** Match threshold (0-1, default 0.4) */
4062
+ match_threshold?: number;
4008
4063
  [key: string]: unknown;
4009
4064
  };
4065
+ cache?: {
4066
+ enabled?: boolean;
4067
+ cache_threshold?:
4068
+ | "super_strict_match"
4069
+ | "close_enough"
4070
+ | "flexible_friend"
4071
+ | "anything_goes";
4072
+ };
4073
+ [key: string]: unknown;
4010
4074
  };
4075
+ // ============ AI Search Request Types ============
4076
+ /**
4077
+ * Request body for single-instance search.
4078
+ * Exactly one of `query` or `messages` must be provided.
4079
+ */
4080
+ type AiSearchSearchRequest =
4081
+ | {
4082
+ /** Simple query string. */
4083
+ query: string;
4084
+ messages?: never;
4085
+ ai_search_options?: AiSearchOptions;
4086
+ }
4087
+ | {
4088
+ query?: never;
4089
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4090
+ messages: AiSearchMessage[];
4091
+ ai_search_options?: AiSearchOptions;
4092
+ };
4011
4093
  type AiSearchChatCompletionsRequest = {
4012
- messages: Array<{
4013
- role: "system" | "developer" | "user" | "assistant" | "tool";
4014
- content: string | null;
4015
- [key: string]: unknown;
4016
- }>;
4094
+ messages: AiSearchMessage[];
4017
4095
  model?: string;
4018
4096
  stream?: boolean;
4019
- ai_search_options?: {
4020
- retrieval?: {
4021
- retrieval_type?: "vector" | "keyword" | "hybrid";
4022
- match_threshold?: number;
4023
- max_num_results?: number;
4024
- filters?: VectorizeVectorMetadataFilter;
4025
- context_expansion?: number;
4026
- [key: string]: unknown;
4027
- };
4028
- query_rewrite?: {
4029
- enabled?: boolean;
4030
- model?: string;
4031
- rewrite_prompt?: string;
4032
- [key: string]: unknown;
4033
- };
4034
- reranking?: {
4035
- enabled?: boolean;
4036
- model?: "@cf/baai/bge-reranker-base" | string;
4037
- match_threshold?: number;
4038
- [key: string]: unknown;
4039
- };
4040
- [key: string]: unknown;
4041
- };
4097
+ ai_search_options?: AiSearchOptions;
4042
4098
  [key: string]: unknown;
4043
4099
  };
4100
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4101
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4102
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4103
+ /** Instance IDs to search across (1-10). */
4104
+ instance_ids: string[];
4105
+ };
4106
+ /**
4107
+ * Request for searching across multiple instances within a namespace.
4108
+ * `ai_search_options` is required and must include `instance_ids`.
4109
+ * Exactly one of `query` or `messages` must be provided.
4110
+ */
4111
+ type AiSearchMultiSearchRequest =
4112
+ | {
4113
+ /** Simple query string. */
4114
+ query: string;
4115
+ messages?: never;
4116
+ ai_search_options: AiSearchMultiSearchOptions;
4117
+ }
4118
+ | {
4119
+ query?: never;
4120
+ /** Conversation-style input. */
4121
+ messages: AiSearchMessage[];
4122
+ ai_search_options: AiSearchMultiSearchOptions;
4123
+ };
4124
+ /** A search result chunk tagged with the instance it originated from. */
4125
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4126
+ instance_id: string;
4127
+ };
4128
+ /** Describes a per-instance error during a multi-instance operation. */
4129
+ type AiSearchMultiSearchError = {
4130
+ instance_id: string;
4131
+ message: string;
4132
+ };
4133
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4134
+ type AiSearchMultiSearchResponse = {
4135
+ search_query: string;
4136
+ chunks: AiSearchMultiSearchChunk[];
4137
+ errors?: AiSearchMultiSearchError[];
4138
+ };
4139
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4140
+ type AiSearchMultiChatCompletionsRequest = Omit<
4141
+ AiSearchChatCompletionsRequest,
4142
+ "ai_search_options"
4143
+ > & {
4144
+ ai_search_options: AiSearchMultiSearchOptions;
4145
+ };
4146
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4147
+ type AiSearchMultiChatCompletionsResponse = Omit<
4148
+ AiSearchChatCompletionsResponse,
4149
+ "chunks"
4150
+ > & {
4151
+ chunks: AiSearchMultiSearchChunk[];
4152
+ errors?: AiSearchMultiSearchError[];
4153
+ };
4044
4154
  // ============ AI Search Response Types ============
4045
4155
  type AiSearchSearchResponse = {
4046
4156
  search_query: string;
@@ -4060,6 +4170,14 @@ type AiSearchSearchResponse = {
4060
4170
  keyword_score?: number;
4061
4171
  /** Vector similarity score (0-1) */
4062
4172
  vector_score?: number;
4173
+ /** Keyword rank position */
4174
+ keyword_rank?: number;
4175
+ /** Vector rank position */
4176
+ vector_rank?: number;
4177
+ /** Reranking model score */
4178
+ reranking_score?: number;
4179
+ /** Fusion method used to combine results */
4180
+ fusion_method?: "rrf" | "max";
4063
4181
  [key: string]: unknown;
4064
4182
  };
4065
4183
  }>;
@@ -4088,19 +4206,88 @@ type AiSearchStatsResponse = {
4088
4206
  skipped?: number;
4089
4207
  outdated?: number;
4090
4208
  last_activity?: string;
4209
+ /** Storage engine statistics. */
4210
+ engine?: {
4211
+ vectorize?: {
4212
+ vectorsCount: number;
4213
+ dimensions: number;
4214
+ };
4215
+ r2?: {
4216
+ payloadSizeBytes: number;
4217
+ metadataSizeBytes: number;
4218
+ objectCount: number;
4219
+ };
4220
+ };
4091
4221
  };
4092
4222
  // ============ AI Search Instance Info Types ============
4093
4223
  type AiSearchInstanceInfo = {
4094
4224
  id: string;
4095
4225
  type?: "r2" | "web-crawler" | string;
4096
4226
  source?: string;
4227
+ source_params?: unknown;
4097
4228
  paused?: boolean;
4098
4229
  status?: string;
4099
4230
  namespace?: string;
4100
4231
  created_at?: string;
4101
4232
  modified_at?: string;
4233
+ token_id?: string;
4234
+ ai_gateway_id?: string;
4235
+ rewrite_query?: boolean;
4236
+ reranking?: boolean;
4237
+ embedding_model?: string;
4238
+ ai_search_model?: string;
4239
+ rewrite_model?: string;
4240
+ reranking_model?: string;
4241
+ /** @deprecated Use index_method instead. */
4242
+ hybrid_search_enabled?: boolean;
4243
+ /** Controls which storage backends are active. */
4244
+ index_method?: {
4245
+ vector?: boolean;
4246
+ keyword?: boolean;
4247
+ };
4248
+ /** Fusion method for combining vector and keyword results. */
4249
+ fusion_method?: "max" | "rrf";
4250
+ indexing_options?: {
4251
+ keyword_tokenizer?: "porter" | "trigram";
4252
+ } | null;
4253
+ retrieval_options?: {
4254
+ keyword_match_mode?: "and" | "or";
4255
+ boost_by?: Array<{
4256
+ field: string;
4257
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4258
+ }>;
4259
+ } | null;
4260
+ chunk?: boolean;
4261
+ chunk_size?: number;
4262
+ chunk_overlap?: number;
4263
+ score_threshold?: number;
4264
+ max_num_results?: number;
4265
+ cache?: boolean;
4266
+ cache_threshold?:
4267
+ | "super_strict_match"
4268
+ | "close_enough"
4269
+ | "flexible_friend"
4270
+ | "anything_goes";
4271
+ custom_metadata?: Array<{
4272
+ field_name: string;
4273
+ data_type: "text" | "number" | "boolean" | "datetime";
4274
+ }>;
4275
+ /** Sync interval in seconds. */
4276
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4277
+ metadata?: Record<string, unknown>;
4102
4278
  [key: string]: unknown;
4103
4279
  };
4280
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4281
+ type AiSearchListInstancesParams = {
4282
+ page?: number;
4283
+ per_page?: number;
4284
+ /** Search instances by ID. */
4285
+ search?: string;
4286
+ /** Field to sort by. */
4287
+ order_by?: "created_at";
4288
+ /** Sort direction. */
4289
+ order_by_direction?: "asc" | "desc";
4290
+ };
4104
4291
  type AiSearchListResponse = {
4105
4292
  result: AiSearchInstanceInfo[];
4106
4293
  result_info?: {
@@ -4128,19 +4315,64 @@ type AiSearchConfig = {
4128
4315
  reranking?: boolean;
4129
4316
  embedding_model?: string;
4130
4317
  ai_search_model?: string;
4318
+ rewrite_model?: string;
4319
+ reranking_model?: string;
4320
+ /** @deprecated Use index_method instead. */
4321
+ hybrid_search_enabled?: boolean;
4322
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4323
+ index_method?: {
4324
+ vector?: boolean;
4325
+ keyword?: boolean;
4326
+ };
4327
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4328
+ fusion_method?: "max" | "rrf";
4329
+ indexing_options?: {
4330
+ keyword_tokenizer?: "porter" | "trigram";
4331
+ } | null;
4332
+ retrieval_options?: {
4333
+ keyword_match_mode?: "and" | "or";
4334
+ boost_by?: Array<{
4335
+ field: string;
4336
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4337
+ }>;
4338
+ } | null;
4339
+ chunk?: boolean;
4340
+ chunk_size?: number;
4341
+ chunk_overlap?: number;
4342
+ /** Minimum similarity score (0-1) for a result to be included. */
4343
+ score_threshold?: number;
4344
+ max_num_results?: number;
4345
+ cache?: boolean;
4346
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4347
+ cache_threshold?:
4348
+ | "super_strict_match"
4349
+ | "close_enough"
4350
+ | "flexible_friend"
4351
+ | "anything_goes";
4352
+ custom_metadata?: Array<{
4353
+ field_name: string;
4354
+ data_type: "text" | "number" | "boolean" | "datetime";
4355
+ }>;
4356
+ namespace?: string;
4357
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4358
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4359
+ metadata?: Record<string, unknown>;
4131
4360
  [key: string]: unknown;
4132
4361
  };
4133
4362
  // ============ AI Search Item Types ============
4134
4363
  type AiSearchItemInfo = {
4135
4364
  id: string;
4136
4365
  key: string;
4137
- status:
4138
- | "completed"
4139
- | "error"
4140
- | "skipped"
4141
- | "queued"
4142
- | "processing"
4143
- | "outdated";
4366
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4367
+ next_action?: "INDEX" | "DELETE" | null;
4368
+ error?: string;
4369
+ checksum?: string;
4370
+ namespace?: string;
4371
+ chunks_count?: number | null;
4372
+ file_size?: number | null;
4373
+ source_id?: string | null;
4374
+ last_seen_at?: string;
4375
+ created_at?: string;
4144
4376
  metadata?: Record<string, unknown>;
4145
4377
  [key: string]: unknown;
4146
4378
  };
@@ -4156,6 +4388,22 @@ type AiSearchUploadItemOptions = {
4156
4388
  type AiSearchListItemsParams = {
4157
4389
  page?: number;
4158
4390
  per_page?: number;
4391
+ /** Search items by key name. */
4392
+ search?: string;
4393
+ /** Sort order for results. */
4394
+ sort_by?: "status" | "modified_at";
4395
+ /** Filter items by processing status. */
4396
+ status?:
4397
+ | "queued"
4398
+ | "running"
4399
+ | "completed"
4400
+ | "error"
4401
+ | "skipped"
4402
+ | "outdated";
4403
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4404
+ source?: string;
4405
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4406
+ metadata_filter?: string;
4159
4407
  };
4160
4408
  type AiSearchListItemsResponse = {
4161
4409
  result: AiSearchItemInfo[];
@@ -4166,6 +4414,61 @@ type AiSearchListItemsResponse = {
4166
4414
  total_count: number;
4167
4415
  };
4168
4416
  };
4417
+ // ============ AI Search Item Logs Types ============
4418
+ type AiSearchItemLogsParams = {
4419
+ /** Maximum number of log entries to return (1-100, default 50). */
4420
+ limit?: number;
4421
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4422
+ cursor?: string;
4423
+ };
4424
+ type AiSearchItemLog = {
4425
+ timestamp: string;
4426
+ action: string;
4427
+ message: string;
4428
+ fileKey?: string;
4429
+ chunkCount?: number;
4430
+ processingTimeMs?: number;
4431
+ errorType?: string;
4432
+ };
4433
+ /** Paginated response for item processing logs (cursor-based). */
4434
+ type AiSearchItemLogsResponse = {
4435
+ result: AiSearchItemLog[];
4436
+ result_info: {
4437
+ count: number;
4438
+ per_page: number;
4439
+ cursor: string | null;
4440
+ truncated: boolean;
4441
+ };
4442
+ };
4443
+ // ============ AI Search Item Chunks Types ============
4444
+ type AiSearchItemChunksParams = {
4445
+ /** Maximum number of chunks to return (1-100, default 20). */
4446
+ limit?: number;
4447
+ /** Offset into the chunks list (default 0). */
4448
+ offset?: number;
4449
+ };
4450
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4451
+ type AiSearchItemChunk = {
4452
+ id: string;
4453
+ text: string;
4454
+ start_byte: number;
4455
+ end_byte: number;
4456
+ item?: {
4457
+ timestamp?: number;
4458
+ key: string;
4459
+ metadata?: Record<string, unknown>;
4460
+ };
4461
+ };
4462
+ /** Paginated response for item chunks (offset-based). */
4463
+ type AiSearchItemChunksResponse = {
4464
+ result: AiSearchItemChunk[];
4465
+ result_info: {
4466
+ count: number;
4467
+ total: number;
4468
+ limit: number;
4469
+ offset: number;
4470
+ };
4471
+ };
4169
4472
  // ============ AI Search Job Types ============
4170
4473
  type AiSearchJobInfo = {
4171
4474
  id: string;
@@ -4214,7 +4517,7 @@ type AiSearchJobLogsResponse = {
4214
4517
  // ============ AI Search Sub-Service Classes ============
4215
4518
  /**
4216
4519
  * Single item service for an AI Search instance.
4217
- * Provides info, delete, and download operations on a specific item.
4520
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4218
4521
  */
4219
4522
  declare abstract class AiSearchItem {
4220
4523
  /** Get metadata about this item. */
@@ -4224,6 +4527,25 @@ declare abstract class AiSearchItem {
4224
4527
  * @returns Object with body stream, content type, filename, and size.
4225
4528
  */
4226
4529
  download(): Promise<AiSearchItemContentResult>;
4530
+ /**
4531
+ * Trigger re-indexing of this item.
4532
+ * @returns The updated item info.
4533
+ */
4534
+ sync(): Promise<AiSearchItemInfo>;
4535
+ /**
4536
+ * Retrieve processing logs for this item (cursor-based pagination).
4537
+ * @param params Optional pagination parameters (limit, cursor).
4538
+ * @returns Paginated log entries for this item.
4539
+ */
4540
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4541
+ /**
4542
+ * List indexed chunks for this item (offset-based pagination).
4543
+ * @param params Optional pagination parameters (limit, offset).
4544
+ * @returns Paginated chunk entries for this item.
4545
+ */
4546
+ chunks(
4547
+ params?: AiSearchItemChunksParams,
4548
+ ): Promise<AiSearchItemChunksResponse>;
4227
4549
  }
4228
4550
  /**
4229
4551
  * Items collection service for an AI Search instance.
@@ -4233,49 +4555,64 @@ declare abstract class AiSearchItems {
4233
4555
  /** List items in this instance. */
4234
4556
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4235
4557
  /**
4236
- * Upload a file as an item.
4558
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4559
+ * filename already exists, it is overwritten and re-indexed.
4237
4560
  * @param name Filename for the uploaded item.
4238
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4561
+ * @param content File content as a ReadableStream, Blob, or string.
4239
4562
  * @param options Optional metadata to attach to the item.
4240
4563
  * @returns The created item info.
4241
4564
  */
4242
4565
  upload(
4243
4566
  name: string,
4244
- content: ReadableStream | ArrayBuffer | string,
4567
+ content: ReadableStream | Blob | string,
4245
4568
  options?: AiSearchUploadItemOptions,
4246
4569
  ): Promise<AiSearchItemInfo>;
4247
4570
  /**
4248
4571
  * Upload a file and poll until processing completes.
4572
+ * Behaves as an upsert: if an item with the same filename already exists,
4573
+ * it is overwritten and re-indexed.
4249
4574
  * @param name Filename for the uploaded item.
4250
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4251
- * @param options Optional metadata to attach to the item.
4575
+ * @param content File content as a ReadableStream, Blob, or string.
4576
+ * @param options Optional metadata and polling configuration.
4252
4577
  * @returns The item info after processing completes (or timeout).
4253
4578
  */
4254
4579
  uploadAndPoll(
4255
4580
  name: string,
4256
- content: ReadableStream | ArrayBuffer | string,
4257
- options?: AiSearchUploadItemOptions,
4581
+ content: ReadableStream | Blob | string,
4582
+ options?: AiSearchUploadItemOptions & {
4583
+ /** Polling interval in milliseconds (default 1000). */
4584
+ pollIntervalMs?: number;
4585
+ /** Maximum time to wait in milliseconds (default 30000). */
4586
+ timeoutMs?: number;
4587
+ },
4258
4588
  ): Promise<AiSearchItemInfo>;
4259
4589
  /**
4260
4590
  * Get an item by ID.
4261
4591
  * @param itemId The item identifier.
4262
- * @returns Item service for info, delete, and download operations.
4592
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4263
4593
  */
4264
4594
  get(itemId: string): AiSearchItem;
4265
- /** Delete this item from the instance.
4595
+ /**
4596
+ * Delete an item from the instance.
4266
4597
  * @param itemId The item identifier.
4267
4598
  */
4268
4599
  delete(itemId: string): Promise<void>;
4269
4600
  }
4270
4601
  /**
4271
4602
  * Single job service for an AI Search instance.
4272
- * Provides info and logs for a specific job.
4603
+ * Provides info, logs, and cancel operations for a specific job.
4273
4604
  */
4274
4605
  declare abstract class AiSearchJob {
4275
4606
  /** Get metadata about this job. */
4276
4607
  info(): Promise<AiSearchJobInfo>;
4277
4608
  /** Get logs for this job. */
4278
4609
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4610
+ /**
4611
+ * Cancel a running job.
4612
+ * @returns The updated job info.
4613
+ * @throws AiSearchNotFoundError if the job does not exist.
4614
+ */
4615
+ cancel(): Promise<AiSearchJobInfo>;
4279
4616
  }
4280
4617
  /**
4281
4618
  * Jobs collection service for an AI Search instance.
@@ -4293,7 +4630,7 @@ declare abstract class AiSearchJobs {
4293
4630
  /**
4294
4631
  * Get a job by ID.
4295
4632
  * @param jobId The job identifier.
4296
- * @returns Job service for info and logs operations.
4633
+ * @returns Job service for info, logs, and cancel operations.
4297
4634
  */
4298
4635
  get(jobId: string): AiSearchJob;
4299
4636
  }
@@ -4312,7 +4649,7 @@ declare abstract class AiSearchJobs {
4312
4649
  * // Via namespace binding
4313
4650
  * const instance = env.AI_SEARCH.get("blog");
4314
4651
  * const results = await instance.search({
4315
- * messages: [{ role: "user", content: "How does caching work?" }],
4652
+ * query: "How does caching work?",
4316
4653
  * });
4317
4654
  *
4318
4655
  * // Via single instance binding
@@ -4324,7 +4661,7 @@ declare abstract class AiSearchJobs {
4324
4661
  declare abstract class AiSearchInstance {
4325
4662
  /**
4326
4663
  * Search the AI Search instance for relevant chunks.
4327
- * @param params Search request with messages and optional AI search options.
4664
+ * @param params Search request with query or messages and optional AI search options.
4328
4665
  * @returns Search response with matching chunks and search query.
4329
4666
  */
4330
4667
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4356,7 +4693,7 @@ declare abstract class AiSearchInstance {
4356
4693
  info(): Promise<AiSearchInstanceInfo>;
4357
4694
  /**
4358
4695
  * Get instance statistics (item count, indexing status, etc.).
4359
- * @returns Statistics with counts per status and last activity time.
4696
+ * @returns Statistics with counts per status, last activity time, and engine details.
4360
4697
  */
4361
4698
  stats(): Promise<AiSearchStatsResponse>;
4362
4699
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4368,27 +4705,30 @@ declare abstract class AiSearchInstance {
4368
4705
  * Namespace-level AI Search service.
4369
4706
  *
4370
4707
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4371
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4708
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4709
+ * and multi-instance search/chat operations.
4372
4710
  *
4373
4711
  * @example
4374
4712
  * ```ts
4375
4713
  * // Access an instance within the namespace
4376
4714
  * const blog = env.AI_SEARCH.get("blog");
4377
- * const results = await blog.search({
4378
- * messages: [{ role: "user", content: "How does caching work?" }],
4379
- * });
4715
+ * const results = await blog.search({ query: "How does caching work?" });
4380
4716
  *
4381
4717
  * // List all instances in the namespace
4382
4718
  * const instances = await env.AI_SEARCH.list();
4383
4719
  *
4384
4720
  * // Create a new instance with built-in storage
4385
- * const tenant = await env.AI_SEARCH.create({
4386
- * id: "tenant-123",
4387
- * });
4721
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4388
4722
  *
4389
4723
  * // Upload items into the instance
4390
4724
  * await tenant.items.upload("doc.pdf", fileContent);
4391
4725
  *
4726
+ * // Search across multiple instances
4727
+ * const multi = await env.AI_SEARCH.search({
4728
+ * query: "caching",
4729
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4730
+ * });
4731
+ *
4392
4732
  * // Delete an instance
4393
4733
  * await env.AI_SEARCH.delete("tenant-123");
4394
4734
  * ```
@@ -4401,10 +4741,11 @@ declare abstract class AiSearchNamespace {
4401
4741
  */
4402
4742
  get(name: string): AiSearchInstance;
4403
4743
  /**
4404
- * List all instances in the bound namespace.
4405
- * @returns Array of instance metadata.
4744
+ * List instances in the bound namespace.
4745
+ * @param params Optional pagination, search, and ordering parameters.
4746
+ * @returns Array of instance metadata with pagination info.
4406
4747
  */
4407
- list(): Promise<AiSearchListResponse>;
4748
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4408
4749
  /**
4409
4750
  * Create a new instance within the bound namespace.
4410
4751
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4429,6 +4770,35 @@ declare abstract class AiSearchNamespace {
4429
4770
  * @param name Instance name to delete.
4430
4771
  */
4431
4772
  delete(name: string): Promise<void>;
4773
+ /**
4774
+ * Search across multiple instances within the bound namespace.
4775
+ * Fans out to the specified instance_ids and merges results.
4776
+ * @param params Search request with required `ai_search_options.instance_ids`.
4777
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4778
+ */
4779
+ search(
4780
+ params: AiSearchMultiSearchRequest,
4781
+ ): Promise<AiSearchMultiSearchResponse>;
4782
+ /**
4783
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4784
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4785
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4786
+ * @returns ReadableStream of server-sent events.
4787
+ */
4788
+ chatCompletions(
4789
+ params: AiSearchMultiChatCompletionsRequest & {
4790
+ stream: true;
4791
+ },
4792
+ ): Promise<ReadableStream>;
4793
+ /**
4794
+ * Generate chat completions across multiple instances within the bound namespace.
4795
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4796
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4797
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4798
+ */
4799
+ chatCompletions(
4800
+ params: AiSearchMultiChatCompletionsRequest,
4801
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4432
4802
  }
4433
4803
  type AiImageClassificationInput = {
4434
4804
  image: number[];
@@ -12080,8 +12450,8 @@ declare module "cloudflare:email" {
12080
12450
  * Evaluation context for targeting rules.
12081
12451
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12082
12452
  */
12083
- type EvaluationContext = Record<string, string | number | boolean>;
12084
- interface EvaluationDetails<T> {
12453
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12454
+ interface FlagshipEvaluationDetails<T> {
12085
12455
  flagKey: string;
12086
12456
  value: T;
12087
12457
  variant?: string | undefined;
@@ -12089,7 +12459,7 @@ interface EvaluationDetails<T> {
12089
12459
  errorCode?: string | undefined;
12090
12460
  errorMessage?: string | undefined;
12091
12461
  }
12092
- interface FlagEvaluationError extends Error {}
12462
+ interface FlagshipEvaluationError extends Error {}
12093
12463
  /**
12094
12464
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12095
12465
  *
@@ -12109,7 +12479,7 @@ interface FlagEvaluationError extends Error {}
12109
12479
  * console.log(details.variant, details.reason);
12110
12480
  * ```
12111
12481
  */
12112
- declare abstract class Flags {
12482
+ declare abstract class Flagship {
12113
12483
  /**
12114
12484
  * Get a flag value without type checking.
12115
12485
  * @param flagKey The key of the flag to evaluate.
@@ -12119,7 +12489,7 @@ declare abstract class Flags {
12119
12489
  get(
12120
12490
  flagKey: string,
12121
12491
  defaultValue?: unknown,
12122
- context?: EvaluationContext,
12492
+ context?: FlagshipEvaluationContext,
12123
12493
  ): Promise<unknown>;
12124
12494
  /**
12125
12495
  * Get a boolean flag value.
@@ -12130,7 +12500,7 @@ declare abstract class Flags {
12130
12500
  getBooleanValue(
12131
12501
  flagKey: string,
12132
12502
  defaultValue: boolean,
12133
- context?: EvaluationContext,
12503
+ context?: FlagshipEvaluationContext,
12134
12504
  ): Promise<boolean>;
12135
12505
  /**
12136
12506
  * Get a string flag value.
@@ -12141,7 +12511,7 @@ declare abstract class Flags {
12141
12511
  getStringValue(
12142
12512
  flagKey: string,
12143
12513
  defaultValue: string,
12144
- context?: EvaluationContext,
12514
+ context?: FlagshipEvaluationContext,
12145
12515
  ): Promise<string>;
12146
12516
  /**
12147
12517
  * Get a number flag value.
@@ -12152,7 +12522,7 @@ declare abstract class Flags {
12152
12522
  getNumberValue(
12153
12523
  flagKey: string,
12154
12524
  defaultValue: number,
12155
- context?: EvaluationContext,
12525
+ context?: FlagshipEvaluationContext,
12156
12526
  ): Promise<number>;
12157
12527
  /**
12158
12528
  * Get an object flag value.
@@ -12163,7 +12533,7 @@ declare abstract class Flags {
12163
12533
  getObjectValue<T extends object>(
12164
12534
  flagKey: string,
12165
12535
  defaultValue: T,
12166
- context?: EvaluationContext,
12536
+ context?: FlagshipEvaluationContext,
12167
12537
  ): Promise<T>;
12168
12538
  /**
12169
12539
  * Get a boolean flag value with full evaluation details.
@@ -12174,8 +12544,8 @@ declare abstract class Flags {
12174
12544
  getBooleanDetails(
12175
12545
  flagKey: string,
12176
12546
  defaultValue: boolean,
12177
- context?: EvaluationContext,
12178
- ): Promise<EvaluationDetails<boolean>>;
12547
+ context?: FlagshipEvaluationContext,
12548
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12179
12549
  /**
12180
12550
  * Get a string flag value with full evaluation details.
12181
12551
  * @param flagKey The key of the flag to evaluate.
@@ -12185,8 +12555,8 @@ declare abstract class Flags {
12185
12555
  getStringDetails(
12186
12556
  flagKey: string,
12187
12557
  defaultValue: string,
12188
- context?: EvaluationContext,
12189
- ): Promise<EvaluationDetails<string>>;
12558
+ context?: FlagshipEvaluationContext,
12559
+ ): Promise<FlagshipEvaluationDetails<string>>;
12190
12560
  /**
12191
12561
  * Get a number flag value with full evaluation details.
12192
12562
  * @param flagKey The key of the flag to evaluate.
@@ -12196,8 +12566,8 @@ declare abstract class Flags {
12196
12566
  getNumberDetails(
12197
12567
  flagKey: string,
12198
12568
  defaultValue: number,
12199
- context?: EvaluationContext,
12200
- ): Promise<EvaluationDetails<number>>;
12569
+ context?: FlagshipEvaluationContext,
12570
+ ): Promise<FlagshipEvaluationDetails<number>>;
12201
12571
  /**
12202
12572
  * Get an object flag value with full evaluation details.
12203
12573
  * @param flagKey The key of the flag to evaluate.
@@ -12207,8 +12577,8 @@ declare abstract class Flags {
12207
12577
  getObjectDetails<T extends object>(
12208
12578
  flagKey: string,
12209
12579
  defaultValue: T,
12210
- context?: EvaluationContext,
12211
- ): Promise<EvaluationDetails<T>>;
12580
+ context?: FlagshipEvaluationContext,
12581
+ ): Promise<FlagshipEvaluationDetails<T>>;
12212
12582
  }
12213
12583
  /**
12214
12584
  * Hello World binding to serve as an explanatory example. DO NOT USE