@workers-community/workers-types 4.20250311.0 → 4.20250317.0

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 +123 -27
  2. package/index.ts +91 -31
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1714,6 +1714,7 @@ interface RequestInit<Cf = CfProperties> {
1714
1714
  integrity?: string;
1715
1715
  /* An AbortSignal to set request's signal. */
1716
1716
  signal?: AbortSignal | null;
1717
+ encodeResponseBody?: "automatic" | "manual";
1717
1718
  }
1718
1719
  type Service<T extends Rpc.WorkerEntrypointBranded | undefined = undefined> =
1719
1720
  Fetcher<T>;
@@ -4340,6 +4341,7 @@ type AiModelListType = Record<string, any>;
4340
4341
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
4341
4342
  aiGatewayLogId: string | null;
4342
4343
  gateway(gatewayId: string): AiGateway;
4344
+ autorag(autoragId: string): AutoRAG;
4343
4345
  run<Name extends keyof AiModelList, Options extends AiOptions>(
4344
4346
  model: Name,
4345
4347
  inputs: AiModelList[Name]["inputs"],
@@ -4359,6 +4361,7 @@ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
4359
4361
  }[],
4360
4362
  options?: {
4361
4363
  gateway?: GatewayOptions;
4364
+ extraHeaders?: object;
4362
4365
  },
4363
4366
  ): Promise<ConversionResponse[]>;
4364
4367
  public toMarkdown(
@@ -4368,6 +4371,7 @@ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
4368
4371
  },
4369
4372
  options?: {
4370
4373
  gateway?: GatewayOptions;
4374
+ extraHeaders?: object;
4371
4375
  },
4372
4376
  ): Promise<ConversionResponse>;
4373
4377
  }
@@ -4426,7 +4430,12 @@ type AIGatewayProviders =
4426
4430
  | "google-ai-studio"
4427
4431
  | "mistral"
4428
4432
  | "grok"
4429
- | "openrouter";
4433
+ | "openrouter"
4434
+ | "deepseek"
4435
+ | "cerebras"
4436
+ | "cartesia"
4437
+ | "elevenlabs"
4438
+ | "adobe-firefly";
4430
4439
  type AIGatewayHeaders = {
4431
4440
  "cf-aig-metadata":
4432
4441
  | Record<string, number | string | boolean | null | bigint>
@@ -4462,6 +4471,42 @@ declare abstract class AiGateway {
4462
4471
  run(
4463
4472
  data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[],
4464
4473
  ): Promise<Response>;
4474
+ getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
4475
+ }
4476
+ interface AutoRAGInternalError extends Error {}
4477
+ interface AutoRAGNotFoundError extends Error {}
4478
+ interface AutoRAGUnauthorizedError extends Error {}
4479
+ type AutoRagSearchRequest = {
4480
+ query: string;
4481
+ max_num_results?: number;
4482
+ ranking_options?: {
4483
+ ranker?: string;
4484
+ score_threshold?: number;
4485
+ };
4486
+ rewrite_query?: boolean;
4487
+ };
4488
+ type AutoRagSearchResponse = {
4489
+ object: "vector_store.search_results.page";
4490
+ search_query: string;
4491
+ data: {
4492
+ file_id: string;
4493
+ filename: string;
4494
+ score: number;
4495
+ attributes: Record<string, string | number | boolean | null>;
4496
+ content: {
4497
+ type: "text";
4498
+ text: string;
4499
+ }[];
4500
+ }[];
4501
+ has_more: boolean;
4502
+ next_page: string | null;
4503
+ };
4504
+ type AutoRagAiSearchResponse = AutoRagSearchResponse & {
4505
+ response: string;
4506
+ };
4507
+ declare abstract class AutoRAG {
4508
+ search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
4509
+ aiSearch(params: AutoRagSearchRequest): Promise<AutoRagAiSearchResponse>;
4465
4510
  }
4466
4511
  interface BasicImageTransformations {
4467
4512
  /**
@@ -5457,11 +5502,43 @@ interface D1ExecResult {
5457
5502
  count: number;
5458
5503
  duration: number;
5459
5504
  }
5505
+ type D1SessionConstraint =
5506
+ // Indicates that the first query should go to the primary, and the rest queries
5507
+ // using the same D1DatabaseSession will go to any replica that is consistent with
5508
+ // the bookmark maintained by the session (returned by the first query).
5509
+ | "first-primary"
5510
+ // Indicates that the first query can go anywhere (primary or replica), and the rest queries
5511
+ // using the same D1DatabaseSession will go to any replica that is consistent with
5512
+ // the bookmark maintained by the session (returned by the first query).
5513
+ | "first-unconstrained";
5514
+ type D1SessionBookmark = string;
5460
5515
  declare abstract class D1Database {
5461
5516
  prepare(query: string): D1PreparedStatement;
5462
- dump(): Promise<ArrayBuffer>;
5463
5517
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
5464
5518
  exec(query: string): Promise<D1ExecResult>;
5519
+ /**
5520
+ * Creates a new D1 Session anchored at the given constraint or the bookmark.
5521
+ * All queries executed using the created session will have sequential consistency,
5522
+ * meaning that all writes done through the session will be visible in subsequent reads.
5523
+ *
5524
+ * @param constraintOrBookmark Either the session constraint or the explicit bookmark to anchor the created session.
5525
+ */
5526
+ withSession(
5527
+ constraintOrBookmark?: D1SessionBookmark | D1SessionConstraint,
5528
+ ): D1DatabaseSession;
5529
+ /**
5530
+ * @deprecated dump() will be removed soon, only applies to deprecated alpha v1 databases.
5531
+ */
5532
+ dump(): Promise<ArrayBuffer>;
5533
+ }
5534
+ declare abstract class D1DatabaseSession {
5535
+ prepare(query: string): D1PreparedStatement;
5536
+ batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
5537
+ /**
5538
+ * @returns The latest session bookmark across all executed queries on the session.
5539
+ * If no query has been executed yet, `null` is returned.
5540
+ */
5541
+ getBookmark(): D1SessionBookmark | null;
5465
5542
  }
5466
5543
  declare abstract class D1PreparedStatement {
5467
5544
  bind(...values: unknown[]): D1PreparedStatement;
@@ -5787,31 +5864,37 @@ declare module "assets:*" {
5787
5864
  // Copyright (c) 2022-2023 Cloudflare, Inc.
5788
5865
  // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5789
5866
  // https://opensource.org/licenses/Apache-2.0
5790
- type PipelineRecord = Record<string, unknown>;
5791
- type PipelineBatchMetadata = {
5792
- pipelineId: string;
5793
- pipelineName: string;
5794
- };
5795
- declare abstract class PipelineTransformationEntrypoint<
5796
- I extends PipelineRecord,
5797
- O extends PipelineRecord,
5798
- > {
5799
- /**
5800
- * run recieves an array of PipelineRecord which can be
5801
- * mutated and returned to the pipeline
5802
- * @param records Incoming records from the pipeline to be transformed
5803
- * @param metadata Information about the specific pipeline calling the transformation entrypoint
5804
- * @returns A promise containing the transformed PipelineRecord array
5805
- */
5806
- public run(records: I[], metadata: PipelineBatchMetadata): Promise<O[]>;
5807
- }
5808
- interface Pipeline<T extends PipelineRecord> {
5809
- /**
5810
- * The Pipeline interface represents the type of a binding to a Pipeline
5811
- *
5812
- * @param records The records to send to the pipeline
5813
- */
5814
- send(records: T[]): Promise<void>;
5867
+ declare module "cloudflare:pipelines" {
5868
+ export abstract class PipelineTransformationEntrypoint<
5869
+ Env = unknown,
5870
+ I extends PipelineRecord = {},
5871
+ O extends PipelineRecord = {},
5872
+ > {
5873
+ /**
5874
+ * run recieves an array of PipelineRecord which can be
5875
+ * mutated and returned to the pipeline
5876
+ * @param records Incoming records from the pipeline to be transformed
5877
+ * @param metadata Information about the specific pipeline calling the transformation entrypoint
5878
+ * @returns A promise containing the transformed PipelineRecord array
5879
+ */
5880
+ protected env: Env;
5881
+ protected ctx: ExecutionContext;
5882
+ constructor(ctx: ExecutionContext, env: Env);
5883
+ public run(records: I[], metadata: PipelineBatchMetadata): Promise<O[]>;
5884
+ }
5885
+ export type PipelineRecord = Record<string, unknown>;
5886
+ export type PipelineBatchMetadata = {
5887
+ pipelineId: string;
5888
+ pipelineName: string;
5889
+ };
5890
+ export interface Pipeline<T extends PipelineRecord> {
5891
+ /**
5892
+ * The Pipeline interface represents the type of a binding to a Pipeline
5893
+ *
5894
+ * @param records The records to send to the pipeline
5895
+ */
5896
+ send(records: T[]): Promise<void>;
5897
+ }
5815
5898
  }
5816
5899
  // PubSubMessage represents an incoming PubSub message.
5817
5900
  // The message includes metadata about the broker, the client, and the payload
@@ -6021,6 +6104,9 @@ declare namespace Rpc {
6021
6104
  >]: MethodOrProperty<T[K]>;
6022
6105
  };
6023
6106
  }
6107
+ declare namespace Cloudflare {
6108
+ interface Env {}
6109
+ }
6024
6110
  declare module "cloudflare:workers" {
6025
6111
  export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
6026
6112
  export const RpcStub: {
@@ -6119,6 +6205,7 @@ declare module "cloudflare:workers" {
6119
6205
  step: WorkflowStep,
6120
6206
  ): Promise<unknown>;
6121
6207
  }
6208
+ export const env: Cloudflare.Env;
6122
6209
  }
6123
6210
  declare module "cloudflare:sockets" {
6124
6211
  function _connect(
@@ -6647,6 +6734,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6647
6734
  public create(
6648
6735
  options?: WorkflowInstanceCreateOptions<PARAMS>,
6649
6736
  ): Promise<WorkflowInstance>;
6737
+ /**
6738
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6739
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6740
+ * @param batch List of Options when creating an instance including name and params
6741
+ * @returns A promise that resolves with a list of handles for the created instances.
6742
+ */
6743
+ public createBatch(
6744
+ batch: WorkflowInstanceCreateOptions<PARAMS>[],
6745
+ ): Promise<WorkflowInstance[]>;
6650
6746
  }
6651
6747
  interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6652
6748
  /**
package/index.ts CHANGED
@@ -1722,6 +1722,7 @@ export interface RequestInit<Cf = CfProperties> {
1722
1722
  integrity?: string;
1723
1723
  /* An AbortSignal to set request's signal. */
1724
1724
  signal?: AbortSignal | null;
1725
+ encodeResponseBody?: "automatic" | "manual";
1725
1726
  }
1726
1727
  export type Service<
1727
1728
  T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
@@ -4354,6 +4355,7 @@ export declare abstract class Ai<
4354
4355
  > {
4355
4356
  aiGatewayLogId: string | null;
4356
4357
  gateway(gatewayId: string): AiGateway;
4358
+ autorag(autoragId: string): AutoRAG;
4357
4359
  run<Name extends keyof AiModelList, Options extends AiOptions>(
4358
4360
  model: Name,
4359
4361
  inputs: AiModelList[Name]["inputs"],
@@ -4373,6 +4375,7 @@ export declare abstract class Ai<
4373
4375
  }[],
4374
4376
  options?: {
4375
4377
  gateway?: GatewayOptions;
4378
+ extraHeaders?: object;
4376
4379
  },
4377
4380
  ): Promise<ConversionResponse[]>;
4378
4381
  public toMarkdown(
@@ -4382,6 +4385,7 @@ export declare abstract class Ai<
4382
4385
  },
4383
4386
  options?: {
4384
4387
  gateway?: GatewayOptions;
4388
+ extraHeaders?: object;
4385
4389
  },
4386
4390
  ): Promise<ConversionResponse>;
4387
4391
  }
@@ -4440,7 +4444,12 @@ export type AIGatewayProviders =
4440
4444
  | "google-ai-studio"
4441
4445
  | "mistral"
4442
4446
  | "grok"
4443
- | "openrouter";
4447
+ | "openrouter"
4448
+ | "deepseek"
4449
+ | "cerebras"
4450
+ | "cartesia"
4451
+ | "elevenlabs"
4452
+ | "adobe-firefly";
4444
4453
  export type AIGatewayHeaders = {
4445
4454
  "cf-aig-metadata":
4446
4455
  | Record<string, number | string | boolean | null | bigint>
@@ -4476,6 +4485,42 @@ export declare abstract class AiGateway {
4476
4485
  run(
4477
4486
  data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[],
4478
4487
  ): Promise<Response>;
4488
+ getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
4489
+ }
4490
+ export interface AutoRAGInternalError extends Error {}
4491
+ export interface AutoRAGNotFoundError extends Error {}
4492
+ export interface AutoRAGUnauthorizedError extends Error {}
4493
+ export type AutoRagSearchRequest = {
4494
+ query: string;
4495
+ max_num_results?: number;
4496
+ ranking_options?: {
4497
+ ranker?: string;
4498
+ score_threshold?: number;
4499
+ };
4500
+ rewrite_query?: boolean;
4501
+ };
4502
+ export type AutoRagSearchResponse = {
4503
+ object: "vector_store.search_results.page";
4504
+ search_query: string;
4505
+ data: {
4506
+ file_id: string;
4507
+ filename: string;
4508
+ score: number;
4509
+ attributes: Record<string, string | number | boolean | null>;
4510
+ content: {
4511
+ type: "text";
4512
+ text: string;
4513
+ }[];
4514
+ }[];
4515
+ has_more: boolean;
4516
+ next_page: string | null;
4517
+ };
4518
+ export type AutoRagAiSearchResponse = AutoRagSearchResponse & {
4519
+ response: string;
4520
+ };
4521
+ export declare abstract class AutoRAG {
4522
+ search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
4523
+ aiSearch(params: AutoRagSearchRequest): Promise<AutoRagAiSearchResponse>;
4479
4524
  }
4480
4525
  export interface BasicImageTransformations {
4481
4526
  /**
@@ -5483,11 +5528,43 @@ export interface D1ExecResult {
5483
5528
  count: number;
5484
5529
  duration: number;
5485
5530
  }
5531
+ export type D1SessionConstraint =
5532
+ // Indicates that the first query should go to the primary, and the rest queries
5533
+ // using the same D1DatabaseSession will go to any replica that is consistent with
5534
+ // the bookmark maintained by the session (returned by the first query).
5535
+ | "first-primary"
5536
+ // Indicates that the first query can go anywhere (primary or replica), and the rest queries
5537
+ // using the same D1DatabaseSession will go to any replica that is consistent with
5538
+ // the bookmark maintained by the session (returned by the first query).
5539
+ | "first-unconstrained";
5540
+ export type D1SessionBookmark = string;
5486
5541
  export declare abstract class D1Database {
5487
5542
  prepare(query: string): D1PreparedStatement;
5488
- dump(): Promise<ArrayBuffer>;
5489
5543
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
5490
5544
  exec(query: string): Promise<D1ExecResult>;
5545
+ /**
5546
+ * Creates a new D1 Session anchored at the given constraint or the bookmark.
5547
+ * All queries executed using the created session will have sequential consistency,
5548
+ * meaning that all writes done through the session will be visible in subsequent reads.
5549
+ *
5550
+ * @param constraintOrBookmark Either the session constraint or the explicit bookmark to anchor the created session.
5551
+ */
5552
+ withSession(
5553
+ constraintOrBookmark?: D1SessionBookmark | D1SessionConstraint,
5554
+ ): D1DatabaseSession;
5555
+ /**
5556
+ * @deprecated dump() will be removed soon, only applies to deprecated alpha v1 databases.
5557
+ */
5558
+ dump(): Promise<ArrayBuffer>;
5559
+ }
5560
+ export declare abstract class D1DatabaseSession {
5561
+ prepare(query: string): D1PreparedStatement;
5562
+ batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
5563
+ /**
5564
+ * @returns The latest session bookmark across all executed queries on the session.
5565
+ * If no query has been executed yet, `null` is returned.
5566
+ */
5567
+ getBookmark(): D1SessionBookmark | null;
5491
5568
  }
5492
5569
  export declare abstract class D1PreparedStatement {
5493
5570
  bind(...values: unknown[]): D1PreparedStatement;
@@ -5800,35 +5877,6 @@ export type PagesPluginFunction<
5800
5877
  > = (
5801
5878
  context: EventPluginContext<Env, Params, Data, PluginArgs>,
5802
5879
  ) => Response | Promise<Response>;
5803
- // Copyright (c) 2022-2023 Cloudflare, Inc.
5804
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5805
- // https://opensource.org/licenses/Apache-2.0
5806
- export type PipelineRecord = Record<string, unknown>;
5807
- export type PipelineBatchMetadata = {
5808
- pipelineId: string;
5809
- pipelineName: string;
5810
- };
5811
- export declare abstract class PipelineTransformationEntrypoint<
5812
- I extends PipelineRecord,
5813
- O extends PipelineRecord,
5814
- > {
5815
- /**
5816
- * run recieves an array of PipelineRecord which can be
5817
- * mutated and returned to the pipeline
5818
- * @param records Incoming records from the pipeline to be transformed
5819
- * @param metadata Information about the specific pipeline calling the transformation entrypoint
5820
- * @returns A promise containing the transformed PipelineRecord array
5821
- */
5822
- public run(records: I[], metadata: PipelineBatchMetadata): Promise<O[]>;
5823
- }
5824
- export interface Pipeline<T extends PipelineRecord> {
5825
- /**
5826
- * The Pipeline interface represents the type of a binding to a Pipeline
5827
- *
5828
- * @param records The records to send to the pipeline
5829
- */
5830
- send(records: T[]): Promise<void>;
5831
- }
5832
5880
  // PubSubMessage represents an incoming PubSub message.
5833
5881
  // The message includes metadata about the broker, the client, and the payload
5834
5882
  // itself.
@@ -6037,6 +6085,9 @@ export declare namespace Rpc {
6037
6085
  >]: MethodOrProperty<T[K]>;
6038
6086
  };
6039
6087
  }
6088
+ export declare namespace Cloudflare {
6089
+ interface Env {}
6090
+ }
6040
6091
  export declare namespace TailStream {
6041
6092
  interface Header {
6042
6093
  readonly name: string;
@@ -6548,6 +6599,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6548
6599
  public create(
6549
6600
  options?: WorkflowInstanceCreateOptions<PARAMS>,
6550
6601
  ): Promise<WorkflowInstance>;
6602
+ /**
6603
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6604
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6605
+ * @param batch List of Options when creating an instance including name and params
6606
+ * @returns A promise that resolves with a list of handles for the created instances.
6607
+ */
6608
+ public createBatch(
6609
+ batch: WorkflowInstanceCreateOptions<PARAMS>[],
6610
+ ): Promise<WorkflowInstance[]>;
6551
6611
  }
6552
6612
  export interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6553
6613
  /**
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "author": "Workers Community",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20250311.0",
10
+ "version": "4.20250317.0",
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./index.d.ts",