@workers-community/workers-types 4.20260414.1 → 4.20260416.2

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.
Files changed (3) hide show
  1. package/index.d.ts +481 -110
  2. package/index.ts +484 -109
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -549,6 +549,7 @@ declare abstract class Navigator {
549
549
  sendBeacon(url: string, body?: BodyInit): boolean;
550
550
  readonly userAgent: string;
551
551
  readonly hardwareConcurrency: number;
552
+ readonly platform: string;
552
553
  }
553
554
  interface AlarmInvocationInfo {
554
555
  readonly isRetry: boolean;
@@ -2330,11 +2331,34 @@ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
2330
2331
  }
2331
2332
  type QueueContentType = "text" | "bytes" | "json" | "v8";
2332
2333
  interface Queue<Body = unknown> {
2333
- send(message: Body, options?: QueueSendOptions): Promise<void>;
2334
+ metrics(): Promise<QueueMetrics>;
2335
+ send(message: Body, options?: QueueSendOptions): Promise<QueueSendResponse>;
2334
2336
  sendBatch(
2335
2337
  messages: Iterable<MessageSendRequest<Body>>,
2336
2338
  options?: QueueSendBatchOptions,
2337
- ): Promise<void>;
2339
+ ): Promise<QueueSendBatchResponse>;
2340
+ }
2341
+ interface QueueSendMetrics {
2342
+ backlogCount: number;
2343
+ backlogBytes: number;
2344
+ oldestMessageTimestamp?: Date;
2345
+ }
2346
+ interface QueueSendMetadata {
2347
+ metrics: QueueSendMetrics;
2348
+ }
2349
+ interface QueueSendResponse {
2350
+ metadata: QueueSendMetadata;
2351
+ }
2352
+ interface QueueSendBatchMetrics {
2353
+ backlogCount: number;
2354
+ backlogBytes: number;
2355
+ oldestMessageTimestamp?: Date;
2356
+ }
2357
+ interface QueueSendBatchMetadata {
2358
+ metrics: QueueSendBatchMetrics;
2359
+ }
2360
+ interface QueueSendBatchResponse {
2361
+ metadata: QueueSendBatchMetadata;
2338
2362
  }
2339
2363
  interface QueueSendOptions {
2340
2364
  contentType?: QueueContentType;
@@ -2348,6 +2372,19 @@ interface MessageSendRequest<Body = unknown> {
2348
2372
  contentType?: QueueContentType;
2349
2373
  delaySeconds?: number;
2350
2374
  }
2375
+ interface QueueMetrics {
2376
+ backlogCount: number;
2377
+ backlogBytes: number;
2378
+ oldestMessageTimestamp?: Date;
2379
+ }
2380
+ interface MessageBatchMetrics {
2381
+ backlogCount: number;
2382
+ backlogBytes: number;
2383
+ oldestMessageTimestamp?: Date;
2384
+ }
2385
+ interface MessageBatchMetadata {
2386
+ metrics: MessageBatchMetrics;
2387
+ }
2351
2388
  interface QueueRetryOptions {
2352
2389
  delaySeconds?: number;
2353
2390
  }
@@ -2362,12 +2399,14 @@ interface Message<Body = unknown> {
2362
2399
  interface QueueEvent<Body = unknown> extends ExtendableEvent {
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
  }
2368
2406
  interface MessageBatch<Body = unknown> {
2369
2407
  readonly messages: readonly Message<Body>[];
2370
2408
  readonly queue: string;
2409
+ readonly metadata: MessageBatchMetadata;
2371
2410
  retryAll(options?: QueueRetryOptions): void;
2372
2411
  ackAll(): void;
2373
2412
  }
@@ -3985,73 +4024,145 @@ declare abstract class Performance {
3985
4024
  // ============ AI Search Error Interfaces ============
3986
4025
  interface AiSearchInternalError extends Error {}
3987
4026
  interface AiSearchNotFoundError extends Error {}
3988
- // ============ AI Search Request Types ============
3989
- type AiSearchSearchRequest = {
3990
- messages: Array<{
3991
- role: "system" | "developer" | "user" | "assistant" | "tool";
3992
- content: string | null;
3993
- }>;
3994
- ai_search_options?: {
3995
- retrieval?: {
3996
- retrieval_type?: "vector" | "keyword" | "hybrid";
3997
- /** Match threshold (0-1, default 0.4) */
3998
- match_threshold?: number;
3999
- /** Maximum number of results (1-50, default 10) */
4000
- max_num_results?: number;
4001
- filters?: VectorizeVectorMetadataFilter;
4002
- /** Context expansion (0-3, default 0) */
4003
- context_expansion?: number;
4004
- [key: string]: unknown;
4005
- };
4006
- query_rewrite?: {
4007
- enabled?: boolean;
4008
- model?: string;
4009
- rewrite_prompt?: string;
4010
- [key: string]: unknown;
4011
- };
4012
- reranking?: {
4013
- enabled?: boolean;
4014
- model?: "@cf/baai/bge-reranker-base" | string;
4015
- /** Match threshold (0-1, default 0.4) */
4016
- match_threshold?: number;
4017
- [key: string]: unknown;
4018
- };
4027
+ // ============ AI Search Common Types ============
4028
+ /** A single message in a conversation-style search or chat request. */
4029
+ type AiSearchMessage = {
4030
+ role: "system" | "developer" | "user" | "assistant" | "tool";
4031
+ content: string | null;
4032
+ };
4033
+ /**
4034
+ * Common shape for `ai_search_options` used by both single-instance and multi-instance requests.
4035
+ * Contains retrieval, query rewrite, reranking, and cache sub-options.
4036
+ */
4037
+ type AiSearchOptions = {
4038
+ retrieval?: {
4039
+ /** Which retrieval backend to use. Defaults to the instance's configured index_method. */
4040
+ retrieval_type?: "vector" | "keyword" | "hybrid";
4041
+ /** Fusion method for combining vector + keyword results. */
4042
+ fusion_method?: "max" | "rrf";
4043
+ /** How keyword terms are combined: "and" = all terms must match, "or" = any term matches. */
4044
+ keyword_match_mode?: "and" | "or";
4045
+ /** Minimum similarity score (0-1) for a result to be included. Default 0.4. */
4046
+ match_threshold?: number;
4047
+ /** Maximum number of results to return (1-50). Default 10. */
4048
+ max_num_results?: number;
4049
+ /** Vectorize metadata filters applied to the search. */
4050
+ filters?: VectorizeVectorMetadataFilter;
4051
+ /** Number of surrounding chunks to include for context (0-3). Default 0. */
4052
+ context_expansion?: number;
4053
+ /** If true, return only item metadata without chunk text. */
4054
+ metadata_only?: boolean;
4055
+ /** If true (default), return empty results on retrieval failure instead of throwing. */
4056
+ return_on_failure?: boolean;
4057
+ /** Boost results by metadata field values. Max 3 entries. */
4058
+ boost_by?: Array<{
4059
+ field: string;
4060
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4061
+ }>;
4062
+ [key: string]: unknown;
4063
+ };
4064
+ query_rewrite?: {
4065
+ enabled?: boolean;
4066
+ model?: string;
4067
+ rewrite_prompt?: string;
4068
+ [key: string]: unknown;
4069
+ };
4070
+ reranking?: {
4071
+ enabled?: boolean;
4072
+ model?: string;
4073
+ /** Match threshold (0-1, default 0.4) */
4074
+ match_threshold?: number;
4019
4075
  [key: string]: unknown;
4020
4076
  };
4077
+ cache?: {
4078
+ enabled?: boolean;
4079
+ cache_threshold?:
4080
+ | "super_strict_match"
4081
+ | "close_enough"
4082
+ | "flexible_friend"
4083
+ | "anything_goes";
4084
+ };
4085
+ [key: string]: unknown;
4021
4086
  };
4087
+ // ============ AI Search Request Types ============
4088
+ /**
4089
+ * Request body for single-instance search.
4090
+ * Exactly one of `query` or `messages` must be provided.
4091
+ */
4092
+ type AiSearchSearchRequest =
4093
+ | {
4094
+ /** Simple query string. */
4095
+ query: string;
4096
+ messages?: never;
4097
+ ai_search_options?: AiSearchOptions;
4098
+ }
4099
+ | {
4100
+ query?: never;
4101
+ /** Conversation-style input. At least one user message with non-empty content is required. */
4102
+ messages: AiSearchMessage[];
4103
+ ai_search_options?: AiSearchOptions;
4104
+ };
4022
4105
  type AiSearchChatCompletionsRequest = {
4023
- messages: Array<{
4024
- role: "system" | "developer" | "user" | "assistant" | "tool";
4025
- content: string | null;
4026
- [key: string]: unknown;
4027
- }>;
4106
+ messages: AiSearchMessage[];
4028
4107
  model?: string;
4029
4108
  stream?: boolean;
4030
- ai_search_options?: {
4031
- retrieval?: {
4032
- retrieval_type?: "vector" | "keyword" | "hybrid";
4033
- match_threshold?: number;
4034
- max_num_results?: number;
4035
- filters?: VectorizeVectorMetadataFilter;
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?: number;
4049
- [key: string]: unknown;
4050
- };
4051
- [key: string]: unknown;
4052
- };
4109
+ ai_search_options?: AiSearchOptions;
4053
4110
  [key: string]: unknown;
4054
4111
  };
4112
+ // ============ AI Search Multi-Instance Types (Namespace-Scoped) ============
4113
+ /** `ai_search_options` shape for multi-instance requests — requires `instance_ids`. */
4114
+ type AiSearchMultiSearchOptions = AiSearchOptions & {
4115
+ /** Instance IDs to search across (1-10). */
4116
+ instance_ids: string[];
4117
+ };
4118
+ /**
4119
+ * Request for searching across multiple instances within a namespace.
4120
+ * `ai_search_options` is required and must include `instance_ids`.
4121
+ * Exactly one of `query` or `messages` must be provided.
4122
+ */
4123
+ type AiSearchMultiSearchRequest =
4124
+ | {
4125
+ /** Simple query string. */
4126
+ query: string;
4127
+ messages?: never;
4128
+ ai_search_options: AiSearchMultiSearchOptions;
4129
+ }
4130
+ | {
4131
+ query?: never;
4132
+ /** Conversation-style input. */
4133
+ messages: AiSearchMessage[];
4134
+ ai_search_options: AiSearchMultiSearchOptions;
4135
+ };
4136
+ /** A search result chunk tagged with the instance it originated from. */
4137
+ type AiSearchMultiSearchChunk = AiSearchSearchResponse["chunks"][number] & {
4138
+ instance_id: string;
4139
+ };
4140
+ /** Describes a per-instance error during a multi-instance operation. */
4141
+ type AiSearchMultiSearchError = {
4142
+ instance_id: string;
4143
+ message: string;
4144
+ };
4145
+ /** Response from a multi-instance search, with chunks tagged by instance and optional partial-failure errors. */
4146
+ type AiSearchMultiSearchResponse = {
4147
+ search_query: string;
4148
+ chunks: AiSearchMultiSearchChunk[];
4149
+ errors?: AiSearchMultiSearchError[];
4150
+ };
4151
+ /** Request for chat completions across multiple instances within a namespace. `ai_search_options` is required and must include `instance_ids`. */
4152
+ type AiSearchMultiChatCompletionsRequest = Omit<
4153
+ AiSearchChatCompletionsRequest,
4154
+ "ai_search_options"
4155
+ > & {
4156
+ ai_search_options: AiSearchMultiSearchOptions;
4157
+ };
4158
+ /** Response from multi-instance chat completions, with chunks tagged by instance and optional partial-failure errors. */
4159
+ type AiSearchMultiChatCompletionsResponse = Omit<
4160
+ AiSearchChatCompletionsResponse,
4161
+ "chunks"
4162
+ > & {
4163
+ chunks: AiSearchMultiSearchChunk[];
4164
+ errors?: AiSearchMultiSearchError[];
4165
+ };
4055
4166
  // ============ AI Search Response Types ============
4056
4167
  type AiSearchSearchResponse = {
4057
4168
  search_query: string;
@@ -4071,6 +4182,14 @@ type AiSearchSearchResponse = {
4071
4182
  keyword_score?: number;
4072
4183
  /** Vector similarity score (0-1) */
4073
4184
  vector_score?: number;
4185
+ /** Keyword rank position */
4186
+ keyword_rank?: number;
4187
+ /** Vector rank position */
4188
+ vector_rank?: number;
4189
+ /** Reranking model score */
4190
+ reranking_score?: number;
4191
+ /** Fusion method used to combine results */
4192
+ fusion_method?: "rrf" | "max";
4074
4193
  [key: string]: unknown;
4075
4194
  };
4076
4195
  }>;
@@ -4099,19 +4218,88 @@ type AiSearchStatsResponse = {
4099
4218
  skipped?: number;
4100
4219
  outdated?: number;
4101
4220
  last_activity?: string;
4221
+ /** Storage engine statistics. */
4222
+ engine?: {
4223
+ vectorize?: {
4224
+ vectorsCount: number;
4225
+ dimensions: number;
4226
+ };
4227
+ r2?: {
4228
+ payloadSizeBytes: number;
4229
+ metadataSizeBytes: number;
4230
+ objectCount: number;
4231
+ };
4232
+ };
4102
4233
  };
4103
4234
  // ============ AI Search Instance Info Types ============
4104
4235
  type AiSearchInstanceInfo = {
4105
4236
  id: string;
4106
4237
  type?: "r2" | "web-crawler" | string;
4107
4238
  source?: string;
4239
+ source_params?: unknown;
4108
4240
  paused?: boolean;
4109
4241
  status?: string;
4110
4242
  namespace?: string;
4111
4243
  created_at?: string;
4112
4244
  modified_at?: string;
4245
+ token_id?: string;
4246
+ ai_gateway_id?: string;
4247
+ rewrite_query?: boolean;
4248
+ reranking?: boolean;
4249
+ embedding_model?: string;
4250
+ ai_search_model?: string;
4251
+ rewrite_model?: string;
4252
+ reranking_model?: string;
4253
+ /** @deprecated Use index_method instead. */
4254
+ hybrid_search_enabled?: boolean;
4255
+ /** Controls which storage backends are active. */
4256
+ index_method?: {
4257
+ vector?: boolean;
4258
+ keyword?: boolean;
4259
+ };
4260
+ /** Fusion method for combining vector and keyword results. */
4261
+ fusion_method?: "max" | "rrf";
4262
+ indexing_options?: {
4263
+ keyword_tokenizer?: "porter" | "trigram";
4264
+ } | null;
4265
+ retrieval_options?: {
4266
+ keyword_match_mode?: "and" | "or";
4267
+ boost_by?: Array<{
4268
+ field: string;
4269
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4270
+ }>;
4271
+ } | null;
4272
+ chunk?: boolean;
4273
+ chunk_size?: number;
4274
+ chunk_overlap?: number;
4275
+ score_threshold?: number;
4276
+ max_num_results?: number;
4277
+ cache?: boolean;
4278
+ cache_threshold?:
4279
+ | "super_strict_match"
4280
+ | "close_enough"
4281
+ | "flexible_friend"
4282
+ | "anything_goes";
4283
+ custom_metadata?: Array<{
4284
+ field_name: string;
4285
+ data_type: "text" | "number" | "boolean" | "datetime";
4286
+ }>;
4287
+ /** Sync interval in seconds. */
4288
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4289
+ metadata?: Record<string, unknown>;
4113
4290
  [key: string]: unknown;
4114
4291
  };
4292
+ /** Pagination, search, and ordering parameters for listing instances within a namespace. */
4293
+ type AiSearchListInstancesParams = {
4294
+ page?: number;
4295
+ per_page?: number;
4296
+ /** Search instances by ID. */
4297
+ search?: string;
4298
+ /** Field to sort by. */
4299
+ order_by?: "created_at";
4300
+ /** Sort direction. */
4301
+ order_by_direction?: "asc" | "desc";
4302
+ };
4115
4303
  type AiSearchListResponse = {
4116
4304
  result: AiSearchInstanceInfo[];
4117
4305
  result_info?: {
@@ -4139,19 +4327,64 @@ type AiSearchConfig = {
4139
4327
  reranking?: boolean;
4140
4328
  embedding_model?: string;
4141
4329
  ai_search_model?: string;
4330
+ rewrite_model?: string;
4331
+ reranking_model?: string;
4332
+ /** @deprecated Use index_method instead. */
4333
+ hybrid_search_enabled?: boolean;
4334
+ /** Controls which storage backends are used during indexing. Defaults to vector-only. */
4335
+ index_method?: {
4336
+ vector?: boolean;
4337
+ keyword?: boolean;
4338
+ };
4339
+ /** Fusion method for combining vector and keyword results. "rrf" = reciprocal rank fusion (default), "max" = maximum score. */
4340
+ fusion_method?: "max" | "rrf";
4341
+ indexing_options?: {
4342
+ keyword_tokenizer?: "porter" | "trigram";
4343
+ } | null;
4344
+ retrieval_options?: {
4345
+ keyword_match_mode?: "and" | "or";
4346
+ boost_by?: Array<{
4347
+ field: string;
4348
+ direction?: "asc" | "desc" | "exists" | "not_exists";
4349
+ }>;
4350
+ } | null;
4351
+ chunk?: boolean;
4352
+ chunk_size?: number;
4353
+ chunk_overlap?: number;
4354
+ /** Minimum similarity score (0-1) for a result to be included. */
4355
+ score_threshold?: number;
4356
+ max_num_results?: number;
4357
+ cache?: boolean;
4358
+ /** Similarity threshold for cache hits. Stricter = fewer cache hits but higher relevance. */
4359
+ cache_threshold?:
4360
+ | "super_strict_match"
4361
+ | "close_enough"
4362
+ | "flexible_friend"
4363
+ | "anything_goes";
4364
+ custom_metadata?: Array<{
4365
+ field_name: string;
4366
+ data_type: "text" | "number" | "boolean" | "datetime";
4367
+ }>;
4368
+ namespace?: string;
4369
+ /** Sync interval in seconds. 3600=1h, 7200=2h, 14400=4h, 21600=6h, 43200=12h, 86400=24h. */
4370
+ sync_interval?: 3600 | 7200 | 14400 | 21600 | 43200 | 86400;
4371
+ metadata?: Record<string, unknown>;
4142
4372
  [key: string]: unknown;
4143
4373
  };
4144
4374
  // ============ AI Search Item Types ============
4145
4375
  type AiSearchItemInfo = {
4146
4376
  id: string;
4147
4377
  key: string;
4148
- status:
4149
- | "completed"
4150
- | "error"
4151
- | "skipped"
4152
- | "queued"
4153
- | "processing"
4154
- | "outdated";
4378
+ status: "completed" | "error" | "skipped" | "queued" | "running" | "outdated";
4379
+ next_action?: "INDEX" | "DELETE" | null;
4380
+ error?: string;
4381
+ checksum?: string;
4382
+ namespace?: string;
4383
+ chunks_count?: number | null;
4384
+ file_size?: number | null;
4385
+ source_id?: string | null;
4386
+ last_seen_at?: string;
4387
+ created_at?: string;
4155
4388
  metadata?: Record<string, unknown>;
4156
4389
  [key: string]: unknown;
4157
4390
  };
@@ -4167,6 +4400,22 @@ type AiSearchUploadItemOptions = {
4167
4400
  type AiSearchListItemsParams = {
4168
4401
  page?: number;
4169
4402
  per_page?: number;
4403
+ /** Search items by key name. */
4404
+ search?: string;
4405
+ /** Sort order for results. */
4406
+ sort_by?: "status" | "modified_at";
4407
+ /** Filter items by processing status. */
4408
+ status?:
4409
+ | "queued"
4410
+ | "running"
4411
+ | "completed"
4412
+ | "error"
4413
+ | "skipped"
4414
+ | "outdated";
4415
+ /** Filter items by source (e.g. "builtin" or "web-crawler:https://example.com"). */
4416
+ source?: string;
4417
+ /** JSON-encoded Vectorize filter for metadata filtering. */
4418
+ metadata_filter?: string;
4170
4419
  };
4171
4420
  type AiSearchListItemsResponse = {
4172
4421
  result: AiSearchItemInfo[];
@@ -4177,6 +4426,61 @@ type AiSearchListItemsResponse = {
4177
4426
  total_count: number;
4178
4427
  };
4179
4428
  };
4429
+ // ============ AI Search Item Logs Types ============
4430
+ type AiSearchItemLogsParams = {
4431
+ /** Maximum number of log entries to return (1-100, default 50). */
4432
+ limit?: number;
4433
+ /** Opaque cursor for pagination. Pass the `cursor` value from a previous response. */
4434
+ cursor?: string;
4435
+ };
4436
+ type AiSearchItemLog = {
4437
+ timestamp: string;
4438
+ action: string;
4439
+ message: string;
4440
+ fileKey?: string;
4441
+ chunkCount?: number;
4442
+ processingTimeMs?: number;
4443
+ errorType?: string;
4444
+ };
4445
+ /** Paginated response for item processing logs (cursor-based). */
4446
+ type AiSearchItemLogsResponse = {
4447
+ result: AiSearchItemLog[];
4448
+ result_info: {
4449
+ count: number;
4450
+ per_page: number;
4451
+ cursor: string | null;
4452
+ truncated: boolean;
4453
+ };
4454
+ };
4455
+ // ============ AI Search Item Chunks Types ============
4456
+ type AiSearchItemChunksParams = {
4457
+ /** Maximum number of chunks to return (1-100, default 20). */
4458
+ limit?: number;
4459
+ /** Offset into the chunks list (default 0). */
4460
+ offset?: number;
4461
+ };
4462
+ /** A single indexed chunk belonging to an item, including its text content and byte range. */
4463
+ type AiSearchItemChunk = {
4464
+ id: string;
4465
+ text: string;
4466
+ start_byte: number;
4467
+ end_byte: number;
4468
+ item?: {
4469
+ timestamp?: number;
4470
+ key: string;
4471
+ metadata?: Record<string, unknown>;
4472
+ };
4473
+ };
4474
+ /** Paginated response for item chunks (offset-based). */
4475
+ type AiSearchItemChunksResponse = {
4476
+ result: AiSearchItemChunk[];
4477
+ result_info: {
4478
+ count: number;
4479
+ total: number;
4480
+ limit: number;
4481
+ offset: number;
4482
+ };
4483
+ };
4180
4484
  // ============ AI Search Job Types ============
4181
4485
  type AiSearchJobInfo = {
4182
4486
  id: string;
@@ -4225,7 +4529,7 @@ type AiSearchJobLogsResponse = {
4225
4529
  // ============ AI Search Sub-Service Classes ============
4226
4530
  /**
4227
4531
  * Single item service for an AI Search instance.
4228
- * Provides info, delete, and download operations on a specific item.
4532
+ * Provides info, download, sync, logs, and chunks operations on a specific item.
4229
4533
  */
4230
4534
  declare abstract class AiSearchItem {
4231
4535
  /** Get metadata about this item. */
@@ -4235,6 +4539,25 @@ declare abstract class AiSearchItem {
4235
4539
  * @returns Object with body stream, content type, filename, and size.
4236
4540
  */
4237
4541
  download(): Promise<AiSearchItemContentResult>;
4542
+ /**
4543
+ * Trigger re-indexing of this item.
4544
+ * @returns The updated item info.
4545
+ */
4546
+ sync(): Promise<AiSearchItemInfo>;
4547
+ /**
4548
+ * Retrieve processing logs for this item (cursor-based pagination).
4549
+ * @param params Optional pagination parameters (limit, cursor).
4550
+ * @returns Paginated log entries for this item.
4551
+ */
4552
+ logs(params?: AiSearchItemLogsParams): Promise<AiSearchItemLogsResponse>;
4553
+ /**
4554
+ * List indexed chunks for this item (offset-based pagination).
4555
+ * @param params Optional pagination parameters (limit, offset).
4556
+ * @returns Paginated chunk entries for this item.
4557
+ */
4558
+ chunks(
4559
+ params?: AiSearchItemChunksParams,
4560
+ ): Promise<AiSearchItemChunksResponse>;
4238
4561
  }
4239
4562
  /**
4240
4563
  * Items collection service for an AI Search instance.
@@ -4244,49 +4567,64 @@ declare abstract class AiSearchItems {
4244
4567
  /** List items in this instance. */
4245
4568
  list(params?: AiSearchListItemsParams): Promise<AiSearchListItemsResponse>;
4246
4569
  /**
4247
- * Upload a file as an item.
4570
+ * Upload a file as an item. Behaves as an upsert: if an item with the same
4571
+ * filename already exists, it is overwritten and re-indexed.
4248
4572
  * @param name Filename for the uploaded item.
4249
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4573
+ * @param content File content as a ReadableStream, Blob, or string.
4250
4574
  * @param options Optional metadata to attach to the item.
4251
4575
  * @returns The created item info.
4252
4576
  */
4253
4577
  upload(
4254
4578
  name: string,
4255
- content: ReadableStream | ArrayBuffer | string,
4579
+ content: ReadableStream | Blob | string,
4256
4580
  options?: AiSearchUploadItemOptions,
4257
4581
  ): Promise<AiSearchItemInfo>;
4258
4582
  /**
4259
4583
  * Upload a file and poll until processing completes.
4584
+ * Behaves as an upsert: if an item with the same filename already exists,
4585
+ * it is overwritten and re-indexed.
4260
4586
  * @param name Filename for the uploaded item.
4261
- * @param content File content as a ReadableStream, ArrayBuffer, or string.
4262
- * @param options Optional metadata to attach to the item.
4587
+ * @param content File content as a ReadableStream, Blob, or string.
4588
+ * @param options Optional metadata and polling configuration.
4263
4589
  * @returns The item info after processing completes (or timeout).
4264
4590
  */
4265
4591
  uploadAndPoll(
4266
4592
  name: string,
4267
- content: ReadableStream | ArrayBuffer | string,
4268
- options?: AiSearchUploadItemOptions,
4593
+ content: ReadableStream | Blob | string,
4594
+ options?: AiSearchUploadItemOptions & {
4595
+ /** Polling interval in milliseconds (default 1000). */
4596
+ pollIntervalMs?: number;
4597
+ /** Maximum time to wait in milliseconds (default 30000). */
4598
+ timeoutMs?: number;
4599
+ },
4269
4600
  ): Promise<AiSearchItemInfo>;
4270
4601
  /**
4271
4602
  * Get an item by ID.
4272
4603
  * @param itemId The item identifier.
4273
- * @returns Item service for info, delete, and download operations.
4604
+ * @returns Item service for info, download, sync, logs, and chunks operations.
4274
4605
  */
4275
4606
  get(itemId: string): AiSearchItem;
4276
- /** Delete this item from the instance.
4607
+ /**
4608
+ * Delete an item from the instance.
4277
4609
  * @param itemId The item identifier.
4278
4610
  */
4279
4611
  delete(itemId: string): Promise<void>;
4280
4612
  }
4281
4613
  /**
4282
4614
  * Single job service for an AI Search instance.
4283
- * Provides info and logs for a specific job.
4615
+ * Provides info, logs, and cancel operations for a specific job.
4284
4616
  */
4285
4617
  declare abstract class AiSearchJob {
4286
4618
  /** Get metadata about this job. */
4287
4619
  info(): Promise<AiSearchJobInfo>;
4288
4620
  /** Get logs for this job. */
4289
4621
  logs(params?: AiSearchJobLogsParams): Promise<AiSearchJobLogsResponse>;
4622
+ /**
4623
+ * Cancel a running job.
4624
+ * @returns The updated job info.
4625
+ * @throws AiSearchNotFoundError if the job does not exist.
4626
+ */
4627
+ cancel(): Promise<AiSearchJobInfo>;
4290
4628
  }
4291
4629
  /**
4292
4630
  * Jobs collection service for an AI Search instance.
@@ -4304,7 +4642,7 @@ declare abstract class AiSearchJobs {
4304
4642
  /**
4305
4643
  * Get a job by ID.
4306
4644
  * @param jobId The job identifier.
4307
- * @returns Job service for info and logs operations.
4645
+ * @returns Job service for info, logs, and cancel operations.
4308
4646
  */
4309
4647
  get(jobId: string): AiSearchJob;
4310
4648
  }
@@ -4323,7 +4661,7 @@ declare abstract class AiSearchJobs {
4323
4661
  * // Via namespace binding
4324
4662
  * const instance = env.AI_SEARCH.get("blog");
4325
4663
  * const results = await instance.search({
4326
- * messages: [{ role: "user", content: "How does caching work?" }],
4664
+ * query: "How does caching work?",
4327
4665
  * });
4328
4666
  *
4329
4667
  * // Via single instance binding
@@ -4335,7 +4673,7 @@ declare abstract class AiSearchJobs {
4335
4673
  declare abstract class AiSearchInstance {
4336
4674
  /**
4337
4675
  * Search the AI Search instance for relevant chunks.
4338
- * @param params Search request with messages and optional AI search options.
4676
+ * @param params Search request with query or messages and optional AI search options.
4339
4677
  * @returns Search response with matching chunks and search query.
4340
4678
  */
4341
4679
  search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
@@ -4367,7 +4705,7 @@ declare abstract class AiSearchInstance {
4367
4705
  info(): Promise<AiSearchInstanceInfo>;
4368
4706
  /**
4369
4707
  * Get instance statistics (item count, indexing status, etc.).
4370
- * @returns Statistics with counts per status and last activity time.
4708
+ * @returns Statistics with counts per status, last activity time, and engine details.
4371
4709
  */
4372
4710
  stats(): Promise<AiSearchStatsResponse>;
4373
4711
  /** Items collection — list, upload, and manage items in this instance. */
@@ -4379,27 +4717,30 @@ declare abstract class AiSearchInstance {
4379
4717
  * Namespace-level AI Search service.
4380
4718
  *
4381
4719
  * Used as the type of `env.AI_SEARCH` (namespace binding via `ai_search_namespaces`).
4382
- * Scoped to a single namespace. Provides dynamic instance access, creation, and deletion.
4720
+ * Scoped to a single namespace. Provides dynamic instance access, creation, deletion,
4721
+ * and multi-instance search/chat operations.
4383
4722
  *
4384
4723
  * @example
4385
4724
  * ```ts
4386
4725
  * // Access an instance within the namespace
4387
4726
  * const blog = env.AI_SEARCH.get("blog");
4388
- * const results = await blog.search({
4389
- * messages: [{ role: "user", content: "How does caching work?" }],
4390
- * });
4727
+ * const results = await blog.search({ query: "How does caching work?" });
4391
4728
  *
4392
4729
  * // List all instances in the namespace
4393
4730
  * const instances = await env.AI_SEARCH.list();
4394
4731
  *
4395
4732
  * // Create a new instance with built-in storage
4396
- * const tenant = await env.AI_SEARCH.create({
4397
- * id: "tenant-123",
4398
- * });
4733
+ * const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });
4399
4734
  *
4400
4735
  * // Upload items into the instance
4401
4736
  * await tenant.items.upload("doc.pdf", fileContent);
4402
4737
  *
4738
+ * // Search across multiple instances
4739
+ * const multi = await env.AI_SEARCH.search({
4740
+ * query: "caching",
4741
+ * ai_search_options: { instance_ids: ["blog", "docs"] },
4742
+ * });
4743
+ *
4403
4744
  * // Delete an instance
4404
4745
  * await env.AI_SEARCH.delete("tenant-123");
4405
4746
  * ```
@@ -4412,10 +4753,11 @@ declare abstract class AiSearchNamespace {
4412
4753
  */
4413
4754
  get(name: string): AiSearchInstance;
4414
4755
  /**
4415
- * List all instances in the bound namespace.
4416
- * @returns Array of instance metadata.
4756
+ * List instances in the bound namespace.
4757
+ * @param params Optional pagination, search, and ordering parameters.
4758
+ * @returns Array of instance metadata with pagination info.
4417
4759
  */
4418
- list(): Promise<AiSearchListResponse>;
4760
+ list(params?: AiSearchListInstancesParams): Promise<AiSearchListResponse>;
4419
4761
  /**
4420
4762
  * Create a new instance within the bound namespace.
4421
4763
  * @param config Instance configuration. Only `id` is required — omit `type` and `source` to create with built-in storage.
@@ -4440,6 +4782,35 @@ declare abstract class AiSearchNamespace {
4440
4782
  * @param name Instance name to delete.
4441
4783
  */
4442
4784
  delete(name: string): Promise<void>;
4785
+ /**
4786
+ * Search across multiple instances within the bound namespace.
4787
+ * Fans out to the specified instance_ids and merges results.
4788
+ * @param params Search request with required `ai_search_options.instance_ids`.
4789
+ * @returns Search response with chunks tagged by instance_id and optional partial-failure errors.
4790
+ */
4791
+ search(
4792
+ params: AiSearchMultiSearchRequest,
4793
+ ): Promise<AiSearchMultiSearchResponse>;
4794
+ /**
4795
+ * Generate chat completions across multiple instances within the bound namespace (streaming).
4796
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4797
+ * @param params Chat completions request with stream: true and required `ai_search_options.instance_ids`.
4798
+ * @returns ReadableStream of server-sent events.
4799
+ */
4800
+ chatCompletions(
4801
+ params: AiSearchMultiChatCompletionsRequest & {
4802
+ stream: true;
4803
+ },
4804
+ ): Promise<ReadableStream>;
4805
+ /**
4806
+ * Generate chat completions across multiple instances within the bound namespace.
4807
+ * Fans out to the specified instance_ids, merges context, and generates a response.
4808
+ * @param params Chat completions request with required `ai_search_options.instance_ids`.
4809
+ * @returns Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.
4810
+ */
4811
+ chatCompletions(
4812
+ params: AiSearchMultiChatCompletionsRequest,
4813
+ ): Promise<AiSearchMultiChatCompletionsResponse>;
4443
4814
  }
4444
4815
  type AiImageClassificationInput = {
4445
4816
  image: number[];
@@ -12091,8 +12462,8 @@ declare module "cloudflare:email" {
12091
12462
  * Evaluation context for targeting rules.
12092
12463
  * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12093
12464
  */
12094
- type EvaluationContext = Record<string, string | number | boolean>;
12095
- interface EvaluationDetails<T> {
12465
+ type FlagshipEvaluationContext = Record<string, string | number | boolean>;
12466
+ interface FlagshipEvaluationDetails<T> {
12096
12467
  flagKey: string;
12097
12468
  value: T;
12098
12469
  variant?: string | undefined;
@@ -12100,7 +12471,7 @@ interface EvaluationDetails<T> {
12100
12471
  errorCode?: string | undefined;
12101
12472
  errorMessage?: string | undefined;
12102
12473
  }
12103
- interface FlagEvaluationError extends Error {}
12474
+ interface FlagshipEvaluationError extends Error {}
12104
12475
  /**
12105
12476
  * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12106
12477
  *
@@ -12120,7 +12491,7 @@ interface FlagEvaluationError extends Error {}
12120
12491
  * console.log(details.variant, details.reason);
12121
12492
  * ```
12122
12493
  */
12123
- declare abstract class Flags {
12494
+ declare abstract class Flagship {
12124
12495
  /**
12125
12496
  * Get a flag value without type checking.
12126
12497
  * @param flagKey The key of the flag to evaluate.
@@ -12130,7 +12501,7 @@ declare abstract class Flags {
12130
12501
  get(
12131
12502
  flagKey: string,
12132
12503
  defaultValue?: unknown,
12133
- context?: EvaluationContext,
12504
+ context?: FlagshipEvaluationContext,
12134
12505
  ): Promise<unknown>;
12135
12506
  /**
12136
12507
  * Get a boolean flag value.
@@ -12141,7 +12512,7 @@ declare abstract class Flags {
12141
12512
  getBooleanValue(
12142
12513
  flagKey: string,
12143
12514
  defaultValue: boolean,
12144
- context?: EvaluationContext,
12515
+ context?: FlagshipEvaluationContext,
12145
12516
  ): Promise<boolean>;
12146
12517
  /**
12147
12518
  * Get a string flag value.
@@ -12152,7 +12523,7 @@ declare abstract class Flags {
12152
12523
  getStringValue(
12153
12524
  flagKey: string,
12154
12525
  defaultValue: string,
12155
- context?: EvaluationContext,
12526
+ context?: FlagshipEvaluationContext,
12156
12527
  ): Promise<string>;
12157
12528
  /**
12158
12529
  * Get a number flag value.
@@ -12163,7 +12534,7 @@ declare abstract class Flags {
12163
12534
  getNumberValue(
12164
12535
  flagKey: string,
12165
12536
  defaultValue: number,
12166
- context?: EvaluationContext,
12537
+ context?: FlagshipEvaluationContext,
12167
12538
  ): Promise<number>;
12168
12539
  /**
12169
12540
  * Get an object flag value.
@@ -12174,7 +12545,7 @@ declare abstract class Flags {
12174
12545
  getObjectValue<T extends object>(
12175
12546
  flagKey: string,
12176
12547
  defaultValue: T,
12177
- context?: EvaluationContext,
12548
+ context?: FlagshipEvaluationContext,
12178
12549
  ): Promise<T>;
12179
12550
  /**
12180
12551
  * Get a boolean flag value with full evaluation details.
@@ -12185,8 +12556,8 @@ declare abstract class Flags {
12185
12556
  getBooleanDetails(
12186
12557
  flagKey: string,
12187
12558
  defaultValue: boolean,
12188
- context?: EvaluationContext,
12189
- ): Promise<EvaluationDetails<boolean>>;
12559
+ context?: FlagshipEvaluationContext,
12560
+ ): Promise<FlagshipEvaluationDetails<boolean>>;
12190
12561
  /**
12191
12562
  * Get a string flag value with full evaluation details.
12192
12563
  * @param flagKey The key of the flag to evaluate.
@@ -12196,8 +12567,8 @@ declare abstract class Flags {
12196
12567
  getStringDetails(
12197
12568
  flagKey: string,
12198
12569
  defaultValue: string,
12199
- context?: EvaluationContext,
12200
- ): Promise<EvaluationDetails<string>>;
12570
+ context?: FlagshipEvaluationContext,
12571
+ ): Promise<FlagshipEvaluationDetails<string>>;
12201
12572
  /**
12202
12573
  * Get a number flag value with full evaluation details.
12203
12574
  * @param flagKey The key of the flag to evaluate.
@@ -12207,8 +12578,8 @@ declare abstract class Flags {
12207
12578
  getNumberDetails(
12208
12579
  flagKey: string,
12209
12580
  defaultValue: number,
12210
- context?: EvaluationContext,
12211
- ): Promise<EvaluationDetails<number>>;
12581
+ context?: FlagshipEvaluationContext,
12582
+ ): Promise<FlagshipEvaluationDetails<number>>;
12212
12583
  /**
12213
12584
  * Get an object flag value with full evaluation details.
12214
12585
  * @param flagKey The key of the flag to evaluate.
@@ -12218,8 +12589,8 @@ declare abstract class Flags {
12218
12589
  getObjectDetails<T extends object>(
12219
12590
  flagKey: string,
12220
12591
  defaultValue: T,
12221
- context?: EvaluationContext,
12222
- ): Promise<EvaluationDetails<T>>;
12592
+ context?: FlagshipEvaluationContext,
12593
+ ): Promise<FlagshipEvaluationDetails<T>>;
12223
12594
  }
12224
12595
  /**
12225
12596
  * Hello World binding to serve as an explanatory example. DO NOT USE