@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.
@@ -2324,11 +2324,34 @@ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
2324
2324
  }
2325
2325
  type QueueContentType = "text" | "bytes" | "json" | "v8";
2326
2326
  interface Queue<Body = unknown> {
2327
- send(message: Body, options?: QueueSendOptions): Promise<void>;
2327
+ metrics(): Promise<QueueMetrics>;
2328
+ send(message: Body, options?: QueueSendOptions): Promise<QueueSendResponse>;
2328
2329
  sendBatch(
2329
2330
  messages: Iterable<MessageSendRequest<Body>>,
2330
2331
  options?: QueueSendBatchOptions,
2331
- ): Promise<void>;
2332
+ ): Promise<QueueSendBatchResponse>;
2333
+ }
2334
+ interface QueueSendMetrics {
2335
+ backlogCount: number;
2336
+ backlogBytes: number;
2337
+ oldestMessageTimestamp?: Date;
2338
+ }
2339
+ interface QueueSendMetadata {
2340
+ metrics: QueueSendMetrics;
2341
+ }
2342
+ interface QueueSendResponse {
2343
+ metadata: QueueSendMetadata;
2344
+ }
2345
+ interface QueueSendBatchMetrics {
2346
+ backlogCount: number;
2347
+ backlogBytes: number;
2348
+ oldestMessageTimestamp?: Date;
2349
+ }
2350
+ interface QueueSendBatchMetadata {
2351
+ metrics: QueueSendBatchMetrics;
2352
+ }
2353
+ interface QueueSendBatchResponse {
2354
+ metadata: QueueSendBatchMetadata;
2332
2355
  }
2333
2356
  interface QueueSendOptions {
2334
2357
  contentType?: QueueContentType;
@@ -2342,6 +2365,19 @@ interface MessageSendRequest<Body = unknown> {
2342
2365
  contentType?: QueueContentType;
2343
2366
  delaySeconds?: number;
2344
2367
  }
2368
+ interface QueueMetrics {
2369
+ backlogCount: number;
2370
+ backlogBytes: number;
2371
+ oldestMessageTimestamp?: Date;
2372
+ }
2373
+ interface MessageBatchMetrics {
2374
+ backlogCount: number;
2375
+ backlogBytes: number;
2376
+ oldestMessageTimestamp?: Date;
2377
+ }
2378
+ interface MessageBatchMetadata {
2379
+ metrics: MessageBatchMetrics;
2380
+ }
2345
2381
  interface QueueRetryOptions {
2346
2382
  delaySeconds?: number;
2347
2383
  }
@@ -2356,12 +2392,14 @@ interface Message<Body = unknown> {
2356
2392
  interface QueueEvent<Body = unknown> extends ExtendableEvent {
2357
2393
  readonly messages: readonly Message<Body>[];
2358
2394
  readonly queue: string;
2395
+ readonly metadata: MessageBatchMetadata;
2359
2396
  retryAll(options?: QueueRetryOptions): void;
2360
2397
  ackAll(): void;
2361
2398
  }
2362
2399
  interface MessageBatch<Body = unknown> {
2363
2400
  readonly messages: readonly Message<Body>[];
2364
2401
  readonly queue: string;
2402
+ readonly metadata: MessageBatchMetadata;
2365
2403
  retryAll(options?: QueueRetryOptions): void;
2366
2404
  ackAll(): void;
2367
2405
  }
@@ -3979,73 +4017,145 @@ declare abstract class Performance {
3979
4017
  // ============ AI Search Error Interfaces ============
3980
4018
  interface AiSearchInternalError extends Error {}
3981
4019
  interface AiSearchNotFoundError extends Error {}
3982
- // ============ AI Search Request Types ============
3983
- type AiSearchSearchRequest = {
3984
- messages: Array<{
3985
- role: "system" | "developer" | "user" | "assistant" | "tool";
3986
- content: string | null;
3987
- }>;
3988
- ai_search_options?: {
3989
- retrieval?: {
3990
- retrieval_type?: "vector" | "keyword" | "hybrid";
3991
- /** Match threshold (0-1, default 0.4) */
3992
- match_threshold?: number;
3993
- /** Maximum number of results (1-50, default 10) */
3994
- max_num_results?: number;
3995
- filters?: VectorizeVectorMetadataFilter;
3996
- /** Context expansion (0-3, default 0) */
3997
- context_expansion?: number;
3998
- [key: string]: unknown;
3999
- };
4000
- query_rewrite?: {
4001
- enabled?: boolean;
4002
- model?: string;
4003
- rewrite_prompt?: string;
4004
- [key: string]: unknown;
4005
- };
4006
- reranking?: {
4007
- enabled?: boolean;
4008
- model?: "@cf/baai/bge-reranker-base" | string;
4009
- /** Match threshold (0-1, default 0.4) */
4010
- match_threshold?: number;
4011
- [key: string]: unknown;
4012
- };
4020
+ // ============ AI Search Common Types ============
4021
+ /** A single message in a conversation-style search or chat request. */
4022
+ type AiSearchMessage = {
4023
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4024
+ content: string | null;
4025
+ };
4026
+ /**
4027
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
4028
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
4029
+ */
4030
+ type AiSearchOptions = {
4031
+ retrieval?: {
4032
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
4033
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4034
+ /** Fusion method for combining vector + keyword results. */
4035
+ fusion_method?: "max" | "rrf";
4036
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4037
+ keyword_match_mode?: "and" | "or";
4038
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4039
+ match_threshold?: number;
4040
+ /** Maximum number of results to return (1-50). Default 10. */
4041
+ max_num_results?: number;
4042
+ /** Vectorize metadata filters applied to the search. */
4043
+ filters?: VectorizeVectorMetadataFilter;
4044
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4045
+ context_expansion?: number;
4046
+ /** If true, return only item metadata without chunk text. */
4047
+ metadata_only?: boolean;
4048
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4049
+ return_on_failure?: boolean;
4050
+ /** Boost results by metadata field values. Max 3 entries. */
4051
+ boost_by?: Array<{
4052
+ field: string;
4053
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4054
+ }>;
4055
+ [key: string]: unknown;
4056
+ };
4057
+ query_rewrite?: {
4058
+ enabled?: boolean;
4059
+ model?: string;
4060
+ rewrite_prompt?: string;
4061
+ [key: string]: unknown;
4062
+ };
4063
+ reranking?: {
4064
+ enabled?: boolean;
4065
+ model?: string;
4066
+ /** Match threshold (0-1, default 0.4) */
4067
+ match_threshold?: number;
4013
4068
  [key: string]: unknown;
4014
4069
  };
4070
+ cache?: {
4071
+ enabled?: boolean;
4072
+ cache_threshold?:
4073
+ | "super_strict_match"
4074
+ | "close_enough"
4075
+ | "flexible_friend"
4076
+ | "anything_goes";
4077
+ };
4078
+ [key: string]: unknown;
4015
4079
  };
4080
+ // ============ AI Search Request Types ============
4081
+ /**
4082
+ * Request body for single-instance search.
4083
+ * Exactly one of `query` or `messages` must be provided.
4084
+ */
4085
+ type AiSearchSearchRequest =
4086
+ | {
4087
+ /** Simple query string. */
4088
+ query: string;
4089
+ messages?: never;
4090
+ ai_search_options?: AiSearchOptions;
4091
+ }
4092
+ | {
4093
+ query?: never;
4094
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4095
+ messages: AiSearchMessage[];
4096
+ ai_search_options?: AiSearchOptions;
4097
+ };
4016
4098
  type AiSearchChatCompletionsRequest = {
4017
- messages: Array<{
4018
- role: "system" | "developer" | "user" | "assistant" | "tool";
4019
- content: string | null;
4020
- [key: string]: unknown;
4021
- }>;
4099
+ messages: AiSearchMessage[];
4022
4100
  model?: string;
4023
4101
  stream?: boolean;
4024
- ai_search_options?: {
4025
- retrieval?: {
4026
- retrieval_type?: "vector" | "keyword" | "hybrid";
4027
- match_threshold?: number;
4028
- max_num_results?: number;
4029
- filters?: VectorizeVectorMetadataFilter;
4030
- context_expansion?: number;
4031
- [key: string]: unknown;
4032
- };
4033
- query_rewrite?: {
4034
- enabled?: boolean;
4035
- model?: string;
4036
- rewrite_prompt?: string;
4037
- [key: string]: unknown;
4038
- };
4039
- reranking?: {
4040
- enabled?: boolean;
4041
- model?: "@cf/baai/bge-reranker-base" | string;
4042
- match_threshold?: number;
4043
- [key: string]: unknown;
4044
- };
4045
- [key: string]: unknown;
4046
- };
4102
+ ai_search_options?: AiSearchOptions;
4047
4103
  [key: string]: unknown;
4048
4104
  };
4105
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4106
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4107
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4108
+ /** Instance IDs to search across (1-10). */
4109
+ instance_ids: string[];
4110
+ };
4111
+ /**
4112
+ * Request for searching across multiple instances within a namespace.
4113
+ * `ai_search_options` is required and must include `instance_ids`.
4114
+ * Exactly one of `query` or `messages` must be provided.
4115
+ */
4116
+ type AiSearchMultiSearchRequest =
4117
+ | {
4118
+ /** Simple query string. */
4119
+ query: string;
4120
+ messages?: never;
4121
+ ai_search_options: AiSearchMultiSearchOptions;
4122
+ }
4123
+ | {
4124
+ query?: never;
4125
+ /** Conversation-style input. */
4126
+ messages: AiSearchMessage[];
4127
+ ai_search_options: AiSearchMultiSearchOptions;
4128
+ };
4129
+ /** A search result chunk tagged with the instance it originated from. */
4130
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4131
+ instance_id: string;
4132
+ };
4133
+ /** Describes a per-instance error during a multi-instance operation. */
4134
+ type AiSearchMultiSearchError = {
4135
+ instance_id: string;
4136
+ message: string;
4137
+ };
4138
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4139
+ type AiSearchMultiSearchResponse = {
4140
+ search_query: string;
4141
+ chunks: AiSearchMultiSearchChunk[];
4142
+ errors?: AiSearchMultiSearchError[];
4143
+ };
4144
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4145
+ type AiSearchMultiChatCompletionsRequest = Omit<
4146
+ AiSearchChatCompletionsRequest,
4147
+ "ai_search_options"
4148
+ > & {
4149
+ ai_search_options: AiSearchMultiSearchOptions;
4150
+ };
4151
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4152
+ type AiSearchMultiChatCompletionsResponse = Omit<
4153
+ AiSearchChatCompletionsResponse,
4154
+ "chunks"
4155
+ > & {
4156
+ chunks: AiSearchMultiSearchChunk[];
4157
+ errors?: AiSearchMultiSearchError[];
4158
+ };
4049
4159
  // ============ AI Search Response Types ============
4050
4160
  type AiSearchSearchResponse = {
4051
4161
  search_query: string;
@@ -4065,6 +4175,14 @@ type AiSearchSearchResponse = {
4065
4175
  keyword_score?: number;
4066
4176
  /** Vector similarity score (0-1) */
4067
4177
  vector_score?: number;
4178
+ /** Keyword rank position */
4179
+ keyword_rank?: number;
4180
+ /** Vector rank position */
4181
+ vector_rank?: number;
4182
+ /** Reranking model score */
4183
+ reranking_score?: number;
4184
+ /** Fusion method used to combine results */
4185
+ fusion_method?: "rrf" | "max";
4068
4186
  [key: string]: unknown;
4069
4187
  };
4070
4188
  }>;
@@ -4093,19 +4211,88 @@ type AiSearchStatsResponse = {
4093
4211
  skipped?: number;
4094
4212
  outdated?: number;
4095
4213
  last_activity?: string;
4214
+ /** Storage engine statistics. */
4215
+ engine?: {
4216
+ vectorize?: {
4217
+ vectorsCount: number;
4218
+ dimensions: number;
4219
+ };
4220
+ r2?: {
4221
+ payloadSizeBytes: number;
4222
+ metadataSizeBytes: number;
4223
+ objectCount: number;
4224
+ };
4225
+ };
4096
4226
  };
4097
4227
  // ============ AI Search Instance Info Types ============
4098
4228
  type AiSearchInstanceInfo = {
4099
4229
  id: string;
4100
4230
  type?: "r2" | "web-crawler" | string;
4101
4231
  source?: string;
4232
+ source_params?: unknown;
4102
4233
  paused?: boolean;
4103
4234
  status?: string;
4104
4235
  namespace?: string;
4105
4236
  created_at?: string;
4106
4237
  modified_at?: string;
4238
+ token_id?: string;
4239
+ ai_gateway_id?: string;
4240
+ rewrite_query?: boolean;
4241
+ reranking?: boolean;
4242
+ embedding_model?: string;
4243
+ ai_search_model?: string;
4244
+ rewrite_model?: string;
4245
+ reranking_model?: string;
4246
+ /** @deprecated Use index_method instead. */
4247
+ hybrid_search_enabled?: boolean;
4248
+ /** Controls which storage backends are active. */
4249
+ index_method?: {
4250
+ vector?: boolean;
4251
+ keyword?: boolean;
4252
+ };
4253
+ /** Fusion method for combining vector and keyword results. */
4254
+ fusion_method?: "max" | "rrf";
4255
+ indexing_options?: {
4256
+ keyword_tokenizer?: "porter" | "trigram";
4257
+ } | null;
4258
+ retrieval_options?: {
4259
+ keyword_match_mode?: "and" | "or";
4260
+ boost_by?: Array<{
4261
+ field: string;
4262
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4263
+ }>;
4264
+ } | null;
4265
+ chunk?: boolean;
4266
+ chunk_size?: number;
4267
+ chunk_overlap?: number;
4268
+ score_threshold?: number;
4269
+ max_num_results?: number;
4270
+ cache?: boolean;
4271
+ cache_threshold?:
4272
+ | "super_strict_match"
4273
+ | "close_enough"
4274
+ | "flexible_friend"
4275
+ | "anything_goes";
4276
+ custom_metadata?: Array<{
4277
+ field_name: string;
4278
+ data_type: "text" | "number" | "boolean" | "datetime";
4279
+ }>;
4280
+ /** Sync interval in seconds. */
4281
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4282
+ metadata?: Record<string, unknown>;
4107
4283
  [key: string]: unknown;
4108
4284
  };
4285
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4286
+ type AiSearchListInstancesParams = {
4287
+ page?: number;
4288
+ per_page?: number;
4289
+ /** Search instances by ID. */
4290
+ search?: string;
4291
+ /** Field to sort by. */
4292
+ order_by?: "created_at";
4293
+ /** Sort direction. */
4294
+ order_by_direction?: "asc" | "desc";
4295
+ };
4109
4296
  type AiSearchListResponse = {
4110
4297
  result: AiSearchInstanceInfo[];
4111
4298
  result_info?: {
@@ -4133,19 +4320,64 @@ type AiSearchConfig = {
4133
4320
  reranking?: boolean;
4134
4321
  embedding_model?: string;
4135
4322
  ai_search_model?: string;
4323
+ rewrite_model?: string;
4324
+ reranking_model?: string;
4325
+ /** @deprecated Use index_method instead. */
4326
+ hybrid_search_enabled?: boolean;
4327
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4328
+ index_method?: {
4329
+ vector?: boolean;
4330
+ keyword?: boolean;
4331
+ };
4332
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4333
+ fusion_method?: "max" | "rrf";
4334
+ indexing_options?: {
4335
+ keyword_tokenizer?: "porter" | "trigram";
4336
+ } | null;
4337
+ retrieval_options?: {
4338
+ keyword_match_mode?: "and" | "or";
4339
+ boost_by?: Array<{
4340
+ field: string;
4341
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4342
+ }>;
4343
+ } | null;
4344
+ chunk?: boolean;
4345
+ chunk_size?: number;
4346
+ chunk_overlap?: number;
4347
+ /** Minimum similarity score (0-1) for a result to be included. */
4348
+ score_threshold?: number;
4349
+ max_num_results?: number;
4350
+ cache?: boolean;
4351
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4352
+ cache_threshold?:
4353
+ | "super_strict_match"
4354
+ | "close_enough"
4355
+ | "flexible_friend"
4356
+ | "anything_goes";
4357
+ custom_metadata?: Array<{
4358
+ field_name: string;
4359
+ data_type: "text" | "number" | "boolean" | "datetime";
4360
+ }>;
4361
+ namespace?: string;
4362
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4363
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4364
+ metadata?: Record<string, unknown>;
4136
4365
  [key: string]: unknown;
4137
4366
  };
4138
4367
  // ============ AI Search Item Types ============
4139
4368
  type AiSearchItemInfo = {
4140
4369
  id: string;
4141
4370
  key: string;
4142
- status:
4143
- | "completed"
4144
- | "error"
4145
- | "skipped"
4146
- | "queued"
4147
- | "processing"
4148
- | "outdated";
4371
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4372
+ next_action?: "INDEX" | "DELETE" | null;
4373
+ error?: string;
4374
+ checksum?: string;
4375
+ namespace?: string;
4376
+ chunks_count?: number | null;
4377
+ file_size?: number | null;
4378
+ source_id?: string | null;
4379
+ last_seen_at?: string;
4380
+ created_at?: string;
4149
4381
  metadata?: Record<string, unknown>;
4150
4382
  [key: string]: unknown;
4151
4383
  };
@@ -4161,6 +4393,22 @@ type AiSearchUploadItemOptions = {
4161
4393
  type AiSearchListItemsParams = {
4162
4394
  page?: number;
4163
4395
  per_page?: number;
4396
+ /** Search items by key name. */
4397
+ search?: string;
4398
+ /** Sort order for results. */
4399
+ sort_by?: "status" | "modified_at";
4400
+ /** Filter items by processing status. */
4401
+ status?:
4402
+ | "queued"
4403
+ | "running"
4404
+ | "completed"
4405
+ | "error"
4406
+ | "skipped"
4407
+ | "outdated";
4408
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4409
+ source?: string;
4410
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4411
+ metadata_filter?: string;
4164
4412
  };
4165
4413
  type AiSearchListItemsResponse = {
4166
4414
  result: AiSearchItemInfo[];
@@ -4171,6 +4419,61 @@ type AiSearchListItemsResponse = {
4171
4419
  total_count: number;
4172
4420
  };
4173
4421
  };
4422
+ // ============ AI Search Item Logs Types ============
4423
+ type AiSearchItemLogsParams = {
4424
+ /** Maximum number of log entries to return (1-100, default 50). */
4425
+ limit?: number;
4426
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4427
+ cursor?: string;
4428
+ };
4429
+ type AiSearchItemLog = {
4430
+ timestamp: string;
4431
+ action: string;
4432
+ message: string;
4433
+ fileKey?: string;
4434
+ chunkCount?: number;
4435
+ processingTimeMs?: number;
4436
+ errorType?: string;
4437
+ };
4438
+ /** Paginated response for item processing logs (cursor-based). */
4439
+ type AiSearchItemLogsResponse = {
4440
+ result: AiSearchItemLog[];
4441
+ result_info: {
4442
+ count: number;
4443
+ per_page: number;
4444
+ cursor: string | null;
4445
+ truncated: boolean;
4446
+ };
4447
+ };
4448
+ // ============ AI Search Item Chunks Types ============
4449
+ type AiSearchItemChunksParams = {
4450
+ /** Maximum number of chunks to return (1-100, default 20). */
4451
+ limit?: number;
4452
+ /** Offset into the chunks list (default 0). */
4453
+ offset?: number;
4454
+ };
4455
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4456
+ type AiSearchItemChunk = {
4457
+ id: string;
4458
+ text: string;
4459
+ start_byte: number;
4460
+ end_byte: number;
4461
+ item?: {
4462
+ timestamp?: number;
4463
+ key: string;
4464
+ metadata?: Record<string, unknown>;
4465
+ };
4466
+ };
4467
+ /** Paginated response for item chunks (offset-based). */
4468
+ type AiSearchItemChunksResponse = {
4469
+ result: AiSearchItemChunk[];
4470
+ result_info: {
4471
+ count: number;
4472
+ total: number;
4473
+ limit: number;
4474
+ offset: number;
4475
+ };
4476
+ };
4174
4477
  // ============ AI Search Job Types ============
4175
4478
  type AiSearchJobInfo = {
4176
4479
  id: string;
@@ -4219,7 +4522,7 @@ type AiSearchJobLogsResponse = {
4219
4522
  // ============ AI Search Sub-Service Classes ============
4220
4523
  /**
4221
4524
  * Single item service for an AI Search instance.
4222
- * Provides info, delete, and download operations on a specific item.
4525
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4223
4526
  */
4224
4527
  declare abstract class AiSearchItem {
4225
4528
  /** Get metadata about this item. */
@@ -4229,6 +4532,25 @@ declare abstract class AiSearchItem {
4229
4532
  * @returns Object with body stream, content type, filename, and size.
4230
4533
  */
4231
4534
  download(): Promise<AiSearchItemContentResult>;
4535
+ /**
4536
+ * Trigger re-indexing of this item.
4537
+ * @returns The updated item info.
4538
+ */
4539
+ sync(): Promise<AiSearchItemInfo>;
4540
+ /**
4541
+ * Retrieve processing logs for this item (cursor-based pagination).
4542
+ * @param params Optional pagination parameters (limit, cursor).
4543
+ * @returns Paginated log entries for this item.
4544
+ */
4545
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4546
+ /**
4547
+ * List indexed chunks for this item (offset-based pagination).
4548
+ * @param params Optional pagination parameters (limit, offset).
4549
+ * @returns Paginated chunk entries for this item.
4550
+ */
4551
+ chunks(
4552
+ params?: AiSearchItemChunksParams,
4553
+ ): Promise<AiSearchItemChunksResponse>;
4232
4554
  }
4233
4555
  /**
4234
4556
  * Items collection service for an AI Search instance.
@@ -4238,49 +4560,64 @@ declare abstract class AiSearchItems {
4238
4560
  /** List items in this instance. */
4239
4561
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4240
4562
  /**
4241
- * Upload a file as an item.
4563
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4564
+ * filename already exists, it is overwritten and re-indexed.
4242
4565
  * @param name Filename for the uploaded item.
4243
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4566
+ * @param content File content as a ReadableStream, Blob, or string.
4244
4567
  * @param options Optional metadata to attach to the item.
4245
4568
  * @returns The created item info.
4246
4569
  */
4247
4570
  upload(
4248
4571
  name: string,
4249
- content: ReadableStream | ArrayBuffer | string,
4572
+ content: ReadableStream | Blob | string,
4250
4573
  options?: AiSearchUploadItemOptions,
4251
4574
  ): Promise<AiSearchItemInfo>;
4252
4575
  /**
4253
4576
  * Upload a file and poll until processing completes.
4577
+ * Behaves as an upsert: if an item with the same filename already exists,
4578
+ * it is overwritten and re-indexed.
4254
4579
  * @param name Filename for the uploaded item.
4255
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4256
- * @param options Optional metadata to attach to the item.
4580
+ * @param content File content as a ReadableStream, Blob, or string.
4581
+ * @param options Optional metadata and polling configuration.
4257
4582
  * @returns The item info after processing completes (or timeout).
4258
4583
  */
4259
4584
  uploadAndPoll(
4260
4585
  name: string,
4261
- content: ReadableStream | ArrayBuffer | string,
4262
- options?: AiSearchUploadItemOptions,
4586
+ content: ReadableStream | Blob | string,
4587
+ options?: AiSearchUploadItemOptions & {
4588
+ /** Polling interval in milliseconds (default 1000). */
4589
+ pollIntervalMs?: number;
4590
+ /** Maximum time to wait in milliseconds (default 30000). */
4591
+ timeoutMs?: number;
4592
+ },
4263
4593
  ): Promise<AiSearchItemInfo>;
4264
4594
  /**
4265
4595
  * Get an item by ID.
4266
4596
  * @param itemId The item identifier.
4267
- * @returns Item service for info, delete, and download operations.
4597
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4268
4598
  */
4269
4599
  get(itemId: string): AiSearchItem;
4270
- /** Delete this item from the instance.
4600
+ /**
4601
+ * Delete an item from the instance.
4271
4602
  * @param itemId The item identifier.
4272
4603
  */
4273
4604
  delete(itemId: string): Promise<void>;
4274
4605
  }
4275
4606
  /**
4276
4607
  * Single job service for an AI Search instance.
4277
- * Provides info and logs for a specific job.
4608
+ * Provides info, logs, and cancel operations for a specific job.
4278
4609
  */
4279
4610
  declare abstract class AiSearchJob {
4280
4611
  /** Get metadata about this job. */
4281
4612
  info(): Promise<AiSearchJobInfo>;
4282
4613
  /** Get logs for this job. */
4283
4614
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4615
+ /**
4616
+ * Cancel a running job.
4617
+ * @returns The updated job info.
4618
+ * @throws AiSearchNotFoundError if the job does not exist.
4619
+ */
4620
+ cancel(): Promise<AiSearchJobInfo>;
4284
4621
  }
4285
4622
  /**
4286
4623
  * Jobs collection service for an AI Search instance.
@@ -4298,7 +4635,7 @@ declare abstract class AiSearchJobs {
4298
4635
  /**
4299
4636
  * Get a job by ID.
4300
4637
  * @param jobId The job identifier.
4301
- * @returns Job service for info and logs operations.
4638
+ * @returns Job service for info, logs, and cancel operations.
4302
4639
  */
4303
4640
  get(jobId: string): AiSearchJob;
4304
4641
  }
@@ -4317,7 +4654,7 @@ declare abstract class AiSearchJobs {
4317
4654
  * // Via namespace binding
4318
4655
  * const instance = env.AI_SEARCH.get("blog");
4319
4656
  * const results = await instance.search({
4320
- * messages: [{ role: "user", content: "How does caching work?" }],
4657
+ * query: "How does caching work?",
4321
4658
  * });
4322
4659
  *
4323
4660
  * // Via single instance binding
@@ -4329,7 +4666,7 @@ declare abstract class AiSearchJobs {
4329
4666
  declare abstract class AiSearchInstance {
4330
4667
  /**
4331
4668
  * Search the AI Search instance for relevant chunks.
4332
- * @param params Search request with messages and optional AI search options.
4669
+ * @param params Search request with query or messages and optional AI search options.
4333
4670
  * @returns Search response with matching chunks and search query.
4334
4671
  */
4335
4672
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4361,7 +4698,7 @@ declare abstract class AiSearchInstance {
4361
4698
  info(): Promise<AiSearchInstanceInfo>;
4362
4699
  /**
4363
4700
  * Get instance statistics (item count, indexing status, etc.).
4364
- * @returns Statistics with counts per status and last activity time.
4701
+ * @returns Statistics with counts per status, last activity time, and engine details.
4365
4702
  */
4366
4703
  stats(): Promise<AiSearchStatsResponse>;
4367
4704
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4373,27 +4710,30 @@ declare abstract class AiSearchInstance {
4373
4710
  * Namespace-level AI Search service.
4374
4711
  *
4375
4712
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4376
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4713
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4714
+ * and multi-instance search/chat operations.
4377
4715
  *
4378
4716
  * @example
4379
4717
  * ```ts
4380
4718
  * // Access an instance within the namespace
4381
4719
  * const blog = env.AI_SEARCH.get("blog");
4382
- * const results = await blog.search({
4383
- * messages: [{ role: "user", content: "How does caching work?" }],
4384
- * });
4720
+ * const results = await blog.search({ query: "How does caching work?" });
4385
4721
  *
4386
4722
  * // List all instances in the namespace
4387
4723
  * const instances = await env.AI_SEARCH.list();
4388
4724
  *
4389
4725
  * // Create a new instance with built-in storage
4390
- * const tenant = await env.AI_SEARCH.create({
4391
- * id: "tenant-123",
4392
- * });
4726
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4393
4727
  *
4394
4728
  * // Upload items into the instance
4395
4729
  * await tenant.items.upload("doc.pdf", fileContent);
4396
4730
  *
4731
+ * // Search across multiple instances
4732
+ * const multi = await env.AI_SEARCH.search({
4733
+ * query: "caching",
4734
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4735
+ * });
4736
+ *
4397
4737
  * // Delete an instance
4398
4738
  * await env.AI_SEARCH.delete("tenant-123");
4399
4739
  * ```
@@ -4406,10 +4746,11 @@ declare abstract class AiSearchNamespace {
4406
4746
  */
4407
4747
  get(name: string): AiSearchInstance;
4408
4748
  /**
4409
- * List all instances in the bound namespace.
4410
- * @returns Array of instance metadata.
4749
+ * List instances in the bound namespace.
4750
+ * @param params Optional pagination, search, and ordering parameters.
4751
+ * @returns Array of instance metadata with pagination info.
4411
4752
  */
4412
- list(): Promise<AiSearchListResponse>;
4753
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4413
4754
  /**
4414
4755
  * Create a new instance within the bound namespace.
4415
4756
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4434,6 +4775,35 @@ declare abstract class AiSearchNamespace {
4434
4775
  * @param name Instance name to delete.
4435
4776
  */
4436
4777
  delete(name: string): Promise<void>;
4778
+ /**
4779
+ * Search across multiple instances within the bound namespace.
4780
+ * Fans out to the specified instance_ids and merges results.
4781
+ * @param params Search request with required `ai_search_options.instance_ids`.
4782
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4783
+ */
4784
+ search(
4785
+ params: AiSearchMultiSearchRequest,
4786
+ ): Promise<AiSearchMultiSearchResponse>;
4787
+ /**
4788
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4789
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4790
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4791
+ * @returns ReadableStream of server-sent events.
4792
+ */
4793
+ chatCompletions(
4794
+ params: AiSearchMultiChatCompletionsRequest & {
4795
+ stream: true;
4796
+ },
4797
+ ): Promise<ReadableStream>;
4798
+ /**
4799
+ * Generate chat completions across multiple instances within the bound namespace.
4800
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4801
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4802
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4803
+ */
4804
+ chatCompletions(
4805
+ params: AiSearchMultiChatCompletionsRequest,
4806
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4437
4807
  }
4438
4808
  type AiImageClassificationInput = {
4439
4809
  image: number[];
@@ -12085,8 +12455,8 @@ declare module "cloudflare:email" {
12085
12455
  * Evaluation context for targeting rules.
12086
12456
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12087
12457
  */
12088
- type EvaluationContext = Record<string, string | number | boolean>;
12089
- interface EvaluationDetails<T> {
12458
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12459
+ interface FlagshipEvaluationDetails<T> {
12090
12460
  flagKey: string;
12091
12461
  value: T;
12092
12462
  variant?: string | undefined;
@@ -12094,7 +12464,7 @@ interface EvaluationDetails<T> {
12094
12464
  errorCode?: string | undefined;
12095
12465
  errorMessage?: string | undefined;
12096
12466
  }
12097
- interface FlagEvaluationError extends Error {}
12467
+ interface FlagshipEvaluationError extends Error {}
12098
12468
  /**
12099
12469
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12100
12470
  *
@@ -12114,7 +12484,7 @@ interface FlagEvaluationError extends Error {}
12114
12484
  * console.log(details.variant, details.reason);
12115
12485
  * ```
12116
12486
  */
12117
- declare abstract class Flags {
12487
+ declare abstract class Flagship {
12118
12488
  /**
12119
12489
  * Get a flag value without type checking.
12120
12490
  * @param flagKey The key of the flag to evaluate.
@@ -12124,7 +12494,7 @@ declare abstract class Flags {
12124
12494
  get(
12125
12495
  flagKey: string,
12126
12496
  defaultValue?: unknown,
12127
- context?: EvaluationContext,
12497
+ context?: FlagshipEvaluationContext,
12128
12498
  ): Promise<unknown>;
12129
12499
  /**
12130
12500
  * Get a boolean flag value.
@@ -12135,7 +12505,7 @@ declare abstract class Flags {
12135
12505
  getBooleanValue(
12136
12506
  flagKey: string,
12137
12507
  defaultValue: boolean,
12138
- context?: EvaluationContext,
12508
+ context?: FlagshipEvaluationContext,
12139
12509
  ): Promise<boolean>;
12140
12510
  /**
12141
12511
  * Get a string flag value.
@@ -12146,7 +12516,7 @@ declare abstract class Flags {
12146
12516
  getStringValue(
12147
12517
  flagKey: string,
12148
12518
  defaultValue: string,
12149
- context?: EvaluationContext,
12519
+ context?: FlagshipEvaluationContext,
12150
12520
  ): Promise<string>;
12151
12521
  /**
12152
12522
  * Get a number flag value.
@@ -12157,7 +12527,7 @@ declare abstract class Flags {
12157
12527
  getNumberValue(
12158
12528
  flagKey: string,
12159
12529
  defaultValue: number,
12160
- context?: EvaluationContext,
12530
+ context?: FlagshipEvaluationContext,
12161
12531
  ): Promise<number>;
12162
12532
  /**
12163
12533
  * Get an object flag value.
@@ -12168,7 +12538,7 @@ declare abstract class Flags {
12168
12538
  getObjectValue<T extends object>(
12169
12539
  flagKey: string,
12170
12540
  defaultValue: T,
12171
- context?: EvaluationContext,
12541
+ context?: FlagshipEvaluationContext,
12172
12542
  ): Promise<T>;
12173
12543
  /**
12174
12544
  * Get a boolean flag value with full evaluation details.
@@ -12179,8 +12549,8 @@ declare abstract class Flags {
12179
12549
  getBooleanDetails(
12180
12550
  flagKey: string,
12181
12551
  defaultValue: boolean,
12182
- context?: EvaluationContext,
12183
- ): Promise<EvaluationDetails<boolean>>;
12552
+ context?: FlagshipEvaluationContext,
12553
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12184
12554
  /**
12185
12555
  * Get a string flag value with full evaluation details.
12186
12556
  * @param flagKey The key of the flag to evaluate.
@@ -12190,8 +12560,8 @@ declare abstract class Flags {
12190
12560
  getStringDetails(
12191
12561
  flagKey: string,
12192
12562
  defaultValue: string,
12193
- context?: EvaluationContext,
12194
- ): Promise<EvaluationDetails<string>>;
12563
+ context?: FlagshipEvaluationContext,
12564
+ ): Promise<FlagshipEvaluationDetails<string>>;
12195
12565
  /**
12196
12566
  * Get a number flag value with full evaluation details.
12197
12567
  * @param flagKey The key of the flag to evaluate.
@@ -12201,8 +12571,8 @@ declare abstract class Flags {
12201
12571
  getNumberDetails(
12202
12572
  flagKey: string,
12203
12573
  defaultValue: number,
12204
- context?: EvaluationContext,
12205
- ): Promise<EvaluationDetails<number>>;
12574
+ context?: FlagshipEvaluationContext,
12575
+ ): Promise<FlagshipEvaluationDetails<number>>;
12206
12576
  /**
12207
12577
  * Get an object flag value with full evaluation details.
12208
12578
  * @param flagKey The key of the flag to evaluate.
@@ -12212,8 +12582,8 @@ declare abstract class Flags {
12212
12582
  getObjectDetails<T extends object>(
12213
12583
  flagKey: string,
12214
12584
  defaultValue: T,
12215
- context?: EvaluationContext,
12216
- ): Promise<EvaluationDetails<T>>;
12585
+ context?: FlagshipEvaluationContext,
12586
+ ): Promise<FlagshipEvaluationDetails<T>>;
12217
12587
  }
12218
12588
  /**
12219
12589
  * Hello World binding to serve as an explanatory example. DO NOT USE