@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.
package/latest/index.d.ts CHANGED
@@ -2342,11 +2342,34 @@ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
2342
2342
  }
2343
2343
  type QueueContentType = "text" | "bytes" | "json" | "v8";
2344
2344
  interface Queue<Body = unknown> {
2345
- send(message: Body, options?: QueueSendOptions): Promise<void>;
2345
+ metrics(): Promise<QueueMetrics>;
2346
+ send(message: Body, options?: QueueSendOptions): Promise<QueueSendResponse>;
2346
2347
  sendBatch(
2347
2348
  messages: Iterable<MessageSendRequest<Body>>,
2348
2349
  options?: QueueSendBatchOptions,
2349
- ): Promise<void>;
2350
+ ): Promise<QueueSendBatchResponse>;
2351
+ }
2352
+ interface QueueSendMetrics {
2353
+ backlogCount: number;
2354
+ backlogBytes: number;
2355
+ oldestMessageTimestamp?: Date;
2356
+ }
2357
+ interface QueueSendMetadata {
2358
+ metrics: QueueSendMetrics;
2359
+ }
2360
+ interface QueueSendResponse {
2361
+ metadata: QueueSendMetadata;
2362
+ }
2363
+ interface QueueSendBatchMetrics {
2364
+ backlogCount: number;
2365
+ backlogBytes: number;
2366
+ oldestMessageTimestamp?: Date;
2367
+ }
2368
+ interface QueueSendBatchMetadata {
2369
+ metrics: QueueSendBatchMetrics;
2370
+ }
2371
+ interface QueueSendBatchResponse {
2372
+ metadata: QueueSendBatchMetadata;
2350
2373
  }
2351
2374
  interface QueueSendOptions {
2352
2375
  contentType?: QueueContentType;
@@ -2360,6 +2383,19 @@ interface MessageSendRequest<Body = unknown> {
2360
2383
  contentType?: QueueContentType;
2361
2384
  delaySeconds?: number;
2362
2385
  }
2386
+ interface QueueMetrics {
2387
+ backlogCount: number;
2388
+ backlogBytes: number;
2389
+ oldestMessageTimestamp?: Date;
2390
+ }
2391
+ interface MessageBatchMetrics {
2392
+ backlogCount: number;
2393
+ backlogBytes: number;
2394
+ oldestMessageTimestamp?: Date;
2395
+ }
2396
+ interface MessageBatchMetadata {
2397
+ metrics: MessageBatchMetrics;
2398
+ }
2363
2399
  interface QueueRetryOptions {
2364
2400
  delaySeconds?: number;
2365
2401
  }
@@ -2374,12 +2410,14 @@ interface Message<Body = unknown> {
2374
2410
  interface QueueEvent<Body = unknown> extends ExtendableEvent {
2375
2411
  readonly messages: readonly Message<Body>[];
2376
2412
  readonly queue: string;
2413
+ readonly metadata: MessageBatchMetadata;
2377
2414
  retryAll(options?: QueueRetryOptions): void;
2378
2415
  ackAll(): void;
2379
2416
  }
2380
2417
  interface MessageBatch<Body = unknown> {
2381
2418
  readonly messages: readonly Message<Body>[];
2382
2419
  readonly queue: string;
2420
+ readonly metadata: MessageBatchMetadata;
2383
2421
  retryAll(options?: QueueRetryOptions): void;
2384
2422
  ackAll(): void;
2385
2423
  }
@@ -4018,73 +4056,145 @@ declare abstract class Performance {
4018
4056
  // ============ AI Search Error Interfaces ============
4019
4057
  interface AiSearchInternalError extends Error {}
4020
4058
  interface AiSearchNotFoundError extends Error {}
4021
- // ============ AI Search Request Types ============
4022
- type AiSearchSearchRequest = {
4023
- messages: Array<{
4024
- role: "system" | "developer" | "user" | "assistant" | "tool";
4025
- content: string | null;
4026
- }>;
4027
- ai_search_options?: {
4028
- retrieval?: {
4029
- retrieval_type?: "vector" | "keyword" | "hybrid";
4030
- /** Match threshold (0-1, default 0.4) */
4031
- match_threshold?: number;
4032
- /** Maximum number of results (1-50, default 10) */
4033
- max_num_results?: number;
4034
- filters?: VectorizeVectorMetadataFilter;
4035
- /** Context expansion (0-3, default 0) */
4036
- context_expansion?: number;
4037
- [key: string]: unknown;
4038
- };
4039
- query_rewrite?: {
4040
- enabled?: boolean;
4041
- model?: string;
4042
- rewrite_prompt?: string;
4043
- [key: string]: unknown;
4044
- };
4045
- reranking?: {
4046
- enabled?: boolean;
4047
- model?: "@cf/baai/bge-reranker-base" | string;
4048
- /** Match threshold (0-1, default 0.4) */
4049
- match_threshold?: number;
4050
- [key: string]: unknown;
4051
- };
4059
+ // ============ AI Search Common Types ============
4060
+ /** A single message in a conversation-style search or chat request. */
4061
+ type AiSearchMessage = {
4062
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4063
+ content: string | null;
4064
+ };
4065
+ /**
4066
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
4067
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
4068
+ */
4069
+ type AiSearchOptions = {
4070
+ retrieval?: {
4071
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
4072
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4073
+ /** Fusion method for combining vector + keyword results. */
4074
+ fusion_method?: "max" | "rrf";
4075
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4076
+ keyword_match_mode?: "and" | "or";
4077
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4078
+ match_threshold?: number;
4079
+ /** Maximum number of results to return (1-50). Default 10. */
4080
+ max_num_results?: number;
4081
+ /** Vectorize metadata filters applied to the search. */
4082
+ filters?: VectorizeVectorMetadataFilter;
4083
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4084
+ context_expansion?: number;
4085
+ /** If true, return only item metadata without chunk text. */
4086
+ metadata_only?: boolean;
4087
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4088
+ return_on_failure?: boolean;
4089
+ /** Boost results by metadata field values. Max 3 entries. */
4090
+ boost_by?: Array<{
4091
+ field: string;
4092
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4093
+ }>;
4094
+ [key: string]: unknown;
4095
+ };
4096
+ query_rewrite?: {
4097
+ enabled?: boolean;
4098
+ model?: string;
4099
+ rewrite_prompt?: string;
4100
+ [key: string]: unknown;
4101
+ };
4102
+ reranking?: {
4103
+ enabled?: boolean;
4104
+ model?: string;
4105
+ /** Match threshold (0-1, default 0.4) */
4106
+ match_threshold?: number;
4052
4107
  [key: string]: unknown;
4053
4108
  };
4109
+ cache?: {
4110
+ enabled?: boolean;
4111
+ cache_threshold?:
4112
+ | "super_strict_match"
4113
+ | "close_enough"
4114
+ | "flexible_friend"
4115
+ | "anything_goes";
4116
+ };
4117
+ [key: string]: unknown;
4054
4118
  };
4119
+ // ============ AI Search Request Types ============
4120
+ /**
4121
+ * Request body for single-instance search.
4122
+ * Exactly one of `query` or `messages` must be provided.
4123
+ */
4124
+ type AiSearchSearchRequest =
4125
+ | {
4126
+ /** Simple query string. */
4127
+ query: string;
4128
+ messages?: never;
4129
+ ai_search_options?: AiSearchOptions;
4130
+ }
4131
+ | {
4132
+ query?: never;
4133
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4134
+ messages: AiSearchMessage[];
4135
+ ai_search_options?: AiSearchOptions;
4136
+ };
4055
4137
  type AiSearchChatCompletionsRequest = {
4056
- messages: Array<{
4057
- role: "system" | "developer" | "user" | "assistant" | "tool";
4058
- content: string | null;
4059
- [key: string]: unknown;
4060
- }>;
4138
+ messages: AiSearchMessage[];
4061
4139
  model?: string;
4062
4140
  stream?: boolean;
4063
- ai_search_options?: {
4064
- retrieval?: {
4065
- retrieval_type?: "vector" | "keyword" | "hybrid";
4066
- match_threshold?: number;
4067
- max_num_results?: number;
4068
- filters?: VectorizeVectorMetadataFilter;
4069
- context_expansion?: number;
4070
- [key: string]: unknown;
4071
- };
4072
- query_rewrite?: {
4073
- enabled?: boolean;
4074
- model?: string;
4075
- rewrite_prompt?: string;
4076
- [key: string]: unknown;
4077
- };
4078
- reranking?: {
4079
- enabled?: boolean;
4080
- model?: "@cf/baai/bge-reranker-base" | string;
4081
- match_threshold?: number;
4082
- [key: string]: unknown;
4083
- };
4084
- [key: string]: unknown;
4085
- };
4141
+ ai_search_options?: AiSearchOptions;
4086
4142
  [key: string]: unknown;
4087
4143
  };
4144
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4145
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4146
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4147
+ /** Instance IDs to search across (1-10). */
4148
+ instance_ids: string[];
4149
+ };
4150
+ /**
4151
+ * Request for searching across multiple instances within a namespace.
4152
+ * `ai_search_options` is required and must include `instance_ids`.
4153
+ * Exactly one of `query` or `messages` must be provided.
4154
+ */
4155
+ type AiSearchMultiSearchRequest =
4156
+ | {
4157
+ /** Simple query string. */
4158
+ query: string;
4159
+ messages?: never;
4160
+ ai_search_options: AiSearchMultiSearchOptions;
4161
+ }
4162
+ | {
4163
+ query?: never;
4164
+ /** Conversation-style input. */
4165
+ messages: AiSearchMessage[];
4166
+ ai_search_options: AiSearchMultiSearchOptions;
4167
+ };
4168
+ /** A search result chunk tagged with the instance it originated from. */
4169
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4170
+ instance_id: string;
4171
+ };
4172
+ /** Describes a per-instance error during a multi-instance operation. */
4173
+ type AiSearchMultiSearchError = {
4174
+ instance_id: string;
4175
+ message: string;
4176
+ };
4177
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4178
+ type AiSearchMultiSearchResponse = {
4179
+ search_query: string;
4180
+ chunks: AiSearchMultiSearchChunk[];
4181
+ errors?: AiSearchMultiSearchError[];
4182
+ };
4183
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4184
+ type AiSearchMultiChatCompletionsRequest = Omit<
4185
+ AiSearchChatCompletionsRequest,
4186
+ "ai_search_options"
4187
+ > & {
4188
+ ai_search_options: AiSearchMultiSearchOptions;
4189
+ };
4190
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4191
+ type AiSearchMultiChatCompletionsResponse = Omit<
4192
+ AiSearchChatCompletionsResponse,
4193
+ "chunks"
4194
+ > & {
4195
+ chunks: AiSearchMultiSearchChunk[];
4196
+ errors?: AiSearchMultiSearchError[];
4197
+ };
4088
4198
  // ============ AI Search Response Types ============
4089
4199
  type AiSearchSearchResponse = {
4090
4200
  search_query: string;
@@ -4104,6 +4214,14 @@ type AiSearchSearchResponse = {
4104
4214
  keyword_score?: number;
4105
4215
  /** Vector similarity score (0-1) */
4106
4216
  vector_score?: number;
4217
+ /** Keyword rank position */
4218
+ keyword_rank?: number;
4219
+ /** Vector rank position */
4220
+ vector_rank?: number;
4221
+ /** Reranking model score */
4222
+ reranking_score?: number;
4223
+ /** Fusion method used to combine results */
4224
+ fusion_method?: "rrf" | "max";
4107
4225
  [key: string]: unknown;
4108
4226
  };
4109
4227
  }>;
@@ -4132,19 +4250,88 @@ type AiSearchStatsResponse = {
4132
4250
  skipped?: number;
4133
4251
  outdated?: number;
4134
4252
  last_activity?: string;
4253
+ /** Storage engine statistics. */
4254
+ engine?: {
4255
+ vectorize?: {
4256
+ vectorsCount: number;
4257
+ dimensions: number;
4258
+ };
4259
+ r2?: {
4260
+ payloadSizeBytes: number;
4261
+ metadataSizeBytes: number;
4262
+ objectCount: number;
4263
+ };
4264
+ };
4135
4265
  };
4136
4266
  // ============ AI Search Instance Info Types ============
4137
4267
  type AiSearchInstanceInfo = {
4138
4268
  id: string;
4139
4269
  type?: "r2" | "web-crawler" | string;
4140
4270
  source?: string;
4271
+ source_params?: unknown;
4141
4272
  paused?: boolean;
4142
4273
  status?: string;
4143
4274
  namespace?: string;
4144
4275
  created_at?: string;
4145
4276
  modified_at?: string;
4277
+ token_id?: string;
4278
+ ai_gateway_id?: string;
4279
+ rewrite_query?: boolean;
4280
+ reranking?: boolean;
4281
+ embedding_model?: string;
4282
+ ai_search_model?: string;
4283
+ rewrite_model?: string;
4284
+ reranking_model?: string;
4285
+ /** @deprecated Use index_method instead. */
4286
+ hybrid_search_enabled?: boolean;
4287
+ /** Controls which storage backends are active. */
4288
+ index_method?: {
4289
+ vector?: boolean;
4290
+ keyword?: boolean;
4291
+ };
4292
+ /** Fusion method for combining vector and keyword results. */
4293
+ fusion_method?: "max" | "rrf";
4294
+ indexing_options?: {
4295
+ keyword_tokenizer?: "porter" | "trigram";
4296
+ } | null;
4297
+ retrieval_options?: {
4298
+ keyword_match_mode?: "and" | "or";
4299
+ boost_by?: Array<{
4300
+ field: string;
4301
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4302
+ }>;
4303
+ } | null;
4304
+ chunk?: boolean;
4305
+ chunk_size?: number;
4306
+ chunk_overlap?: number;
4307
+ score_threshold?: number;
4308
+ max_num_results?: number;
4309
+ cache?: boolean;
4310
+ cache_threshold?:
4311
+ | "super_strict_match"
4312
+ | "close_enough"
4313
+ | "flexible_friend"
4314
+ | "anything_goes";
4315
+ custom_metadata?: Array<{
4316
+ field_name: string;
4317
+ data_type: "text" | "number" | "boolean" | "datetime";
4318
+ }>;
4319
+ /** Sync interval in seconds. */
4320
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4321
+ metadata?: Record<string, unknown>;
4146
4322
  [key: string]: unknown;
4147
4323
  };
4324
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4325
+ type AiSearchListInstancesParams = {
4326
+ page?: number;
4327
+ per_page?: number;
4328
+ /** Search instances by ID. */
4329
+ search?: string;
4330
+ /** Field to sort by. */
4331
+ order_by?: "created_at";
4332
+ /** Sort direction. */
4333
+ order_by_direction?: "asc" | "desc";
4334
+ };
4148
4335
  type AiSearchListResponse = {
4149
4336
  result: AiSearchInstanceInfo[];
4150
4337
  result_info?: {
@@ -4172,19 +4359,64 @@ type AiSearchConfig = {
4172
4359
  reranking?: boolean;
4173
4360
  embedding_model?: string;
4174
4361
  ai_search_model?: string;
4362
+ rewrite_model?: string;
4363
+ reranking_model?: string;
4364
+ /** @deprecated Use index_method instead. */
4365
+ hybrid_search_enabled?: boolean;
4366
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4367
+ index_method?: {
4368
+ vector?: boolean;
4369
+ keyword?: boolean;
4370
+ };
4371
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4372
+ fusion_method?: "max" | "rrf";
4373
+ indexing_options?: {
4374
+ keyword_tokenizer?: "porter" | "trigram";
4375
+ } | null;
4376
+ retrieval_options?: {
4377
+ keyword_match_mode?: "and" | "or";
4378
+ boost_by?: Array<{
4379
+ field: string;
4380
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4381
+ }>;
4382
+ } | null;
4383
+ chunk?: boolean;
4384
+ chunk_size?: number;
4385
+ chunk_overlap?: number;
4386
+ /** Minimum similarity score (0-1) for a result to be included. */
4387
+ score_threshold?: number;
4388
+ max_num_results?: number;
4389
+ cache?: boolean;
4390
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4391
+ cache_threshold?:
4392
+ | "super_strict_match"
4393
+ | "close_enough"
4394
+ | "flexible_friend"
4395
+ | "anything_goes";
4396
+ custom_metadata?: Array<{
4397
+ field_name: string;
4398
+ data_type: "text" | "number" | "boolean" | "datetime";
4399
+ }>;
4400
+ namespace?: string;
4401
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4402
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4403
+ metadata?: Record<string, unknown>;
4175
4404
  [key: string]: unknown;
4176
4405
  };
4177
4406
  // ============ AI Search Item Types ============
4178
4407
  type AiSearchItemInfo = {
4179
4408
  id: string;
4180
4409
  key: string;
4181
- status:
4182
- | "completed"
4183
- | "error"
4184
- | "skipped"
4185
- | "queued"
4186
- | "processing"
4187
- | "outdated";
4410
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4411
+ next_action?: "INDEX" | "DELETE" | null;
4412
+ error?: string;
4413
+ checksum?: string;
4414
+ namespace?: string;
4415
+ chunks_count?: number | null;
4416
+ file_size?: number | null;
4417
+ source_id?: string | null;
4418
+ last_seen_at?: string;
4419
+ created_at?: string;
4188
4420
  metadata?: Record<string, unknown>;
4189
4421
  [key: string]: unknown;
4190
4422
  };
@@ -4200,6 +4432,22 @@ type AiSearchUploadItemOptions = {
4200
4432
  type AiSearchListItemsParams = {
4201
4433
  page?: number;
4202
4434
  per_page?: number;
4435
+ /** Search items by key name. */
4436
+ search?: string;
4437
+ /** Sort order for results. */
4438
+ sort_by?: "status" | "modified_at";
4439
+ /** Filter items by processing status. */
4440
+ status?:
4441
+ | "queued"
4442
+ | "running"
4443
+ | "completed"
4444
+ | "error"
4445
+ | "skipped"
4446
+ | "outdated";
4447
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4448
+ source?: string;
4449
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4450
+ metadata_filter?: string;
4203
4451
  };
4204
4452
  type AiSearchListItemsResponse = {
4205
4453
  result: AiSearchItemInfo[];
@@ -4210,6 +4458,61 @@ type AiSearchListItemsResponse = {
4210
4458
  total_count: number;
4211
4459
  };
4212
4460
  };
4461
+ // ============ AI Search Item Logs Types ============
4462
+ type AiSearchItemLogsParams = {
4463
+ /** Maximum number of log entries to return (1-100, default 50). */
4464
+ limit?: number;
4465
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4466
+ cursor?: string;
4467
+ };
4468
+ type AiSearchItemLog = {
4469
+ timestamp: string;
4470
+ action: string;
4471
+ message: string;
4472
+ fileKey?: string;
4473
+ chunkCount?: number;
4474
+ processingTimeMs?: number;
4475
+ errorType?: string;
4476
+ };
4477
+ /** Paginated response for item processing logs (cursor-based). */
4478
+ type AiSearchItemLogsResponse = {
4479
+ result: AiSearchItemLog[];
4480
+ result_info: {
4481
+ count: number;
4482
+ per_page: number;
4483
+ cursor: string | null;
4484
+ truncated: boolean;
4485
+ };
4486
+ };
4487
+ // ============ AI Search Item Chunks Types ============
4488
+ type AiSearchItemChunksParams = {
4489
+ /** Maximum number of chunks to return (1-100, default 20). */
4490
+ limit?: number;
4491
+ /** Offset into the chunks list (default 0). */
4492
+ offset?: number;
4493
+ };
4494
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4495
+ type AiSearchItemChunk = {
4496
+ id: string;
4497
+ text: string;
4498
+ start_byte: number;
4499
+ end_byte: number;
4500
+ item?: {
4501
+ timestamp?: number;
4502
+ key: string;
4503
+ metadata?: Record<string, unknown>;
4504
+ };
4505
+ };
4506
+ /** Paginated response for item chunks (offset-based). */
4507
+ type AiSearchItemChunksResponse = {
4508
+ result: AiSearchItemChunk[];
4509
+ result_info: {
4510
+ count: number;
4511
+ total: number;
4512
+ limit: number;
4513
+ offset: number;
4514
+ };
4515
+ };
4213
4516
  // ============ AI Search Job Types ============
4214
4517
  type AiSearchJobInfo = {
4215
4518
  id: string;
@@ -4258,7 +4561,7 @@ type AiSearchJobLogsResponse = {
4258
4561
  // ============ AI Search Sub-Service Classes ============
4259
4562
  /**
4260
4563
  * Single item service for an AI Search instance.
4261
- * Provides info, delete, and download operations on a specific item.
4564
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4262
4565
  */
4263
4566
  declare abstract class AiSearchItem {
4264
4567
  /** Get metadata about this item. */
@@ -4268,6 +4571,25 @@ declare abstract class AiSearchItem {
4268
4571
  * @returns Object with body stream, content type, filename, and size.
4269
4572
  */
4270
4573
  download(): Promise<AiSearchItemContentResult>;
4574
+ /**
4575
+ * Trigger re-indexing of this item.
4576
+ * @returns The updated item info.
4577
+ */
4578
+ sync(): Promise<AiSearchItemInfo>;
4579
+ /**
4580
+ * Retrieve processing logs for this item (cursor-based pagination).
4581
+ * @param params Optional pagination parameters (limit, cursor).
4582
+ * @returns Paginated log entries for this item.
4583
+ */
4584
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4585
+ /**
4586
+ * List indexed chunks for this item (offset-based pagination).
4587
+ * @param params Optional pagination parameters (limit, offset).
4588
+ * @returns Paginated chunk entries for this item.
4589
+ */
4590
+ chunks(
4591
+ params?: AiSearchItemChunksParams,
4592
+ ): Promise<AiSearchItemChunksResponse>;
4271
4593
  }
4272
4594
  /**
4273
4595
  * Items collection service for an AI Search instance.
@@ -4277,49 +4599,64 @@ declare abstract class AiSearchItems {
4277
4599
  /** List items in this instance. */
4278
4600
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4279
4601
  /**
4280
- * Upload a file as an item.
4602
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4603
+ * filename already exists, it is overwritten and re-indexed.
4281
4604
  * @param name Filename for the uploaded item.
4282
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4605
+ * @param content File content as a ReadableStream, Blob, or string.
4283
4606
  * @param options Optional metadata to attach to the item.
4284
4607
  * @returns The created item info.
4285
4608
  */
4286
4609
  upload(
4287
4610
  name: string,
4288
- content: ReadableStream | ArrayBuffer | string,
4611
+ content: ReadableStream | Blob | string,
4289
4612
  options?: AiSearchUploadItemOptions,
4290
4613
  ): Promise<AiSearchItemInfo>;
4291
4614
  /**
4292
4615
  * Upload a file and poll until processing completes.
4616
+ * Behaves as an upsert: if an item with the same filename already exists,
4617
+ * it is overwritten and re-indexed.
4293
4618
  * @param name Filename for the uploaded item.
4294
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4295
- * @param options Optional metadata to attach to the item.
4619
+ * @param content File content as a ReadableStream, Blob, or string.
4620
+ * @param options Optional metadata and polling configuration.
4296
4621
  * @returns The item info after processing completes (or timeout).
4297
4622
  */
4298
4623
  uploadAndPoll(
4299
4624
  name: string,
4300
- content: ReadableStream | ArrayBuffer | string,
4301
- options?: AiSearchUploadItemOptions,
4625
+ content: ReadableStream | Blob | string,
4626
+ options?: AiSearchUploadItemOptions & {
4627
+ /** Polling interval in milliseconds (default 1000). */
4628
+ pollIntervalMs?: number;
4629
+ /** Maximum time to wait in milliseconds (default 30000). */
4630
+ timeoutMs?: number;
4631
+ },
4302
4632
  ): Promise<AiSearchItemInfo>;
4303
4633
  /**
4304
4634
  * Get an item by ID.
4305
4635
  * @param itemId The item identifier.
4306
- * @returns Item service for info, delete, and download operations.
4636
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4307
4637
  */
4308
4638
  get(itemId: string): AiSearchItem;
4309
- /** Delete this item from the instance.
4639
+ /**
4640
+ * Delete an item from the instance.
4310
4641
  * @param itemId The item identifier.
4311
4642
  */
4312
4643
  delete(itemId: string): Promise<void>;
4313
4644
  }
4314
4645
  /**
4315
4646
  * Single job service for an AI Search instance.
4316
- * Provides info and logs for a specific job.
4647
+ * Provides info, logs, and cancel operations for a specific job.
4317
4648
  */
4318
4649
  declare abstract class AiSearchJob {
4319
4650
  /** Get metadata about this job. */
4320
4651
  info(): Promise<AiSearchJobInfo>;
4321
4652
  /** Get logs for this job. */
4322
4653
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4654
+ /**
4655
+ * Cancel a running job.
4656
+ * @returns The updated job info.
4657
+ * @throws AiSearchNotFoundError if the job does not exist.
4658
+ */
4659
+ cancel(): Promise<AiSearchJobInfo>;
4323
4660
  }
4324
4661
  /**
4325
4662
  * Jobs collection service for an AI Search instance.
@@ -4337,7 +4674,7 @@ declare abstract class AiSearchJobs {
4337
4674
  /**
4338
4675
  * Get a job by ID.
4339
4676
  * @param jobId The job identifier.
4340
- * @returns Job service for info and logs operations.
4677
+ * @returns Job service for info, logs, and cancel operations.
4341
4678
  */
4342
4679
  get(jobId: string): AiSearchJob;
4343
4680
  }
@@ -4356,7 +4693,7 @@ declare abstract class AiSearchJobs {
4356
4693
  * // Via namespace binding
4357
4694
  * const instance = env.AI_SEARCH.get("blog");
4358
4695
  * const results = await instance.search({
4359
- * messages: [{ role: "user", content: "How does caching work?" }],
4696
+ * query: "How does caching work?",
4360
4697
  * });
4361
4698
  *
4362
4699
  * // Via single instance binding
@@ -4368,7 +4705,7 @@ declare abstract class AiSearchJobs {
4368
4705
  declare abstract class AiSearchInstance {
4369
4706
  /**
4370
4707
  * Search the AI Search instance for relevant chunks.
4371
- * @param params Search request with messages and optional AI search options.
4708
+ * @param params Search request with query or messages and optional AI search options.
4372
4709
  * @returns Search response with matching chunks and search query.
4373
4710
  */
4374
4711
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4400,7 +4737,7 @@ declare abstract class AiSearchInstance {
4400
4737
  info(): Promise<AiSearchInstanceInfo>;
4401
4738
  /**
4402
4739
  * Get instance statistics (item count, indexing status, etc.).
4403
- * @returns Statistics with counts per status and last activity time.
4740
+ * @returns Statistics with counts per status, last activity time, and engine details.
4404
4741
  */
4405
4742
  stats(): Promise<AiSearchStatsResponse>;
4406
4743
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4412,27 +4749,30 @@ declare abstract class AiSearchInstance {
4412
4749
  * Namespace-level AI Search service.
4413
4750
  *
4414
4751
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4415
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4752
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4753
+ * and multi-instance search/chat operations.
4416
4754
  *
4417
4755
  * @example
4418
4756
  * ```ts
4419
4757
  * // Access an instance within the namespace
4420
4758
  * const blog = env.AI_SEARCH.get("blog");
4421
- * const results = await blog.search({
4422
- * messages: [{ role: "user", content: "How does caching work?" }],
4423
- * });
4759
+ * const results = await blog.search({ query: "How does caching work?" });
4424
4760
  *
4425
4761
  * // List all instances in the namespace
4426
4762
  * const instances = await env.AI_SEARCH.list();
4427
4763
  *
4428
4764
  * // Create a new instance with built-in storage
4429
- * const tenant = await env.AI_SEARCH.create({
4430
- * id: "tenant-123",
4431
- * });
4765
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4432
4766
  *
4433
4767
  * // Upload items into the instance
4434
4768
  * await tenant.items.upload("doc.pdf", fileContent);
4435
4769
  *
4770
+ * // Search across multiple instances
4771
+ * const multi = await env.AI_SEARCH.search({
4772
+ * query: "caching",
4773
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4774
+ * });
4775
+ *
4436
4776
  * // Delete an instance
4437
4777
  * await env.AI_SEARCH.delete("tenant-123");
4438
4778
  * ```
@@ -4445,10 +4785,11 @@ declare abstract class AiSearchNamespace {
4445
4785
  */
4446
4786
  get(name: string): AiSearchInstance;
4447
4787
  /**
4448
- * List all instances in the bound namespace.
4449
- * @returns Array of instance metadata.
4788
+ * List instances in the bound namespace.
4789
+ * @param params Optional pagination, search, and ordering parameters.
4790
+ * @returns Array of instance metadata with pagination info.
4450
4791
  */
4451
- list(): Promise<AiSearchListResponse>;
4792
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4452
4793
  /**
4453
4794
  * Create a new instance within the bound namespace.
4454
4795
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4473,6 +4814,35 @@ declare abstract class AiSearchNamespace {
4473
4814
  * @param name Instance name to delete.
4474
4815
  */
4475
4816
  delete(name: string): Promise<void>;
4817
+ /**
4818
+ * Search across multiple instances within the bound namespace.
4819
+ * Fans out to the specified instance_ids and merges results.
4820
+ * @param params Search request with required `ai_search_options.instance_ids`.
4821
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4822
+ */
4823
+ search(
4824
+ params: AiSearchMultiSearchRequest,
4825
+ ): Promise<AiSearchMultiSearchResponse>;
4826
+ /**
4827
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4828
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4829
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4830
+ * @returns ReadableStream of server-sent events.
4831
+ */
4832
+ chatCompletions(
4833
+ params: AiSearchMultiChatCompletionsRequest & {
4834
+ stream: true;
4835
+ },
4836
+ ): Promise<ReadableStream>;
4837
+ /**
4838
+ * Generate chat completions across multiple instances within the bound namespace.
4839
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4840
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4841
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4842
+ */
4843
+ chatCompletions(
4844
+ params: AiSearchMultiChatCompletionsRequest,
4845
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4476
4846
  }
4477
4847
  type AiImageClassificationInput = {
4478
4848
  image: number[];
@@ -12124,8 +12494,8 @@ declare module "cloudflare:email" {
12124
12494
  * Evaluation context for targeting rules.
12125
12495
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12126
12496
  */
12127
- type EvaluationContext = Record<string, string | number | boolean>;
12128
- interface EvaluationDetails<T> {
12497
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12498
+ interface FlagshipEvaluationDetails<T> {
12129
12499
  flagKey: string;
12130
12500
  value: T;
12131
12501
  variant?: string | undefined;
@@ -12133,7 +12503,7 @@ interface EvaluationDetails<T> {
12133
12503
  errorCode?: string | undefined;
12134
12504
  errorMessage?: string | undefined;
12135
12505
  }
12136
- interface FlagEvaluationError extends Error {}
12506
+ interface FlagshipEvaluationError extends Error {}
12137
12507
  /**
12138
12508
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12139
12509
  *
@@ -12153,7 +12523,7 @@ interface FlagEvaluationError extends Error {}
12153
12523
  * console.log(details.variant, details.reason);
12154
12524
  * ```
12155
12525
  */
12156
- declare abstract class Flags {
12526
+ declare abstract class Flagship {
12157
12527
  /**
12158
12528
  * Get a flag value without type checking.
12159
12529
  * @param flagKey The key of the flag to evaluate.
@@ -12163,7 +12533,7 @@ declare abstract class Flags {
12163
12533
  get(
12164
12534
  flagKey: string,
12165
12535
  defaultValue?: unknown,
12166
- context?: EvaluationContext,
12536
+ context?: FlagshipEvaluationContext,
12167
12537
  ): Promise<unknown>;
12168
12538
  /**
12169
12539
  * Get a boolean flag value.
@@ -12174,7 +12544,7 @@ declare abstract class Flags {
12174
12544
  getBooleanValue(
12175
12545
  flagKey: string,
12176
12546
  defaultValue: boolean,
12177
- context?: EvaluationContext,
12547
+ context?: FlagshipEvaluationContext,
12178
12548
  ): Promise<boolean>;
12179
12549
  /**
12180
12550
  * Get a string flag value.
@@ -12185,7 +12555,7 @@ declare abstract class Flags {
12185
12555
  getStringValue(
12186
12556
  flagKey: string,
12187
12557
  defaultValue: string,
12188
- context?: EvaluationContext,
12558
+ context?: FlagshipEvaluationContext,
12189
12559
  ): Promise<string>;
12190
12560
  /**
12191
12561
  * Get a number flag value.
@@ -12196,7 +12566,7 @@ declare abstract class Flags {
12196
12566
  getNumberValue(
12197
12567
  flagKey: string,
12198
12568
  defaultValue: number,
12199
- context?: EvaluationContext,
12569
+ context?: FlagshipEvaluationContext,
12200
12570
  ): Promise<number>;
12201
12571
  /**
12202
12572
  * Get an object flag value.
@@ -12207,7 +12577,7 @@ declare abstract class Flags {
12207
12577
  getObjectValue<T extends object>(
12208
12578
  flagKey: string,
12209
12579
  defaultValue: T,
12210
- context?: EvaluationContext,
12580
+ context?: FlagshipEvaluationContext,
12211
12581
  ): Promise<T>;
12212
12582
  /**
12213
12583
  * Get a boolean flag value with full evaluation details.
@@ -12218,8 +12588,8 @@ declare abstract class Flags {
12218
12588
  getBooleanDetails(
12219
12589
  flagKey: string,
12220
12590
  defaultValue: boolean,
12221
- context?: EvaluationContext,
12222
- ): Promise<EvaluationDetails<boolean>>;
12591
+ context?: FlagshipEvaluationContext,
12592
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12223
12593
  /**
12224
12594
  * Get a string flag value with full evaluation details.
12225
12595
  * @param flagKey The key of the flag to evaluate.
@@ -12229,8 +12599,8 @@ declare abstract class Flags {
12229
12599
  getStringDetails(
12230
12600
  flagKey: string,
12231
12601
  defaultValue: string,
12232
- context?: EvaluationContext,
12233
- ): Promise<EvaluationDetails<string>>;
12602
+ context?: FlagshipEvaluationContext,
12603
+ ): Promise<FlagshipEvaluationDetails<string>>;
12234
12604
  /**
12235
12605
  * Get a number flag value with full evaluation details.
12236
12606
  * @param flagKey The key of the flag to evaluate.
@@ -12240,8 +12610,8 @@ declare abstract class Flags {
12240
12610
  getNumberDetails(
12241
12611
  flagKey: string,
12242
12612
  defaultValue: number,
12243
- context?: EvaluationContext,
12244
- ): Promise<EvaluationDetails<number>>;
12613
+ context?: FlagshipEvaluationContext,
12614
+ ): Promise<FlagshipEvaluationDetails<number>>;
12245
12615
  /**
12246
12616
  * Get an object flag value with full evaluation details.
12247
12617
  * @param flagKey The key of the flag to evaluate.
@@ -12251,8 +12621,8 @@ declare abstract class Flags {
12251
12621
  getObjectDetails<T extends object>(
12252
12622
  flagKey: string,
12253
12623
  defaultValue: T,
12254
- context?: EvaluationContext,
12255
- ): Promise<EvaluationDetails<T>>;
12624
+ context?: FlagshipEvaluationContext,
12625
+ ): Promise<FlagshipEvaluationDetails<T>>;
12256
12626
  }
12257
12627
  /**
12258
12628
  * Hello World binding to serve as an explanatory example. DO NOT USE