@cloudflare/workers-types 0.20240712.0 → 0.20250124.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.
@@ -14,6 +14,7 @@ and limitations under the License.
14
14
  ***************************************************************************** */
15
15
  /* eslint-disable */
16
16
  // noinspection JSUnusedGlobalSymbols
17
+ declare var onmessage: never;
17
18
  /**
18
19
  * An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API.
19
20
  *
@@ -227,7 +228,7 @@ interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
227
228
  structuredClone<T>(value: T, options?: StructuredSerializeOptions): T;
228
229
  reportError(error: any): void;
229
230
  fetch(
230
- input: RequestInfo,
231
+ input: RequestInfo | URL,
231
232
  init?: RequestInit<RequestInitCfProperties>,
232
233
  ): Promise<Response>;
233
234
  self: ServiceWorkerGlobalScope;
@@ -235,6 +236,7 @@ interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
235
236
  caches: CacheStorage;
236
237
  scheduler: Scheduler;
237
238
  performance: Performance;
239
+ Cloudflare: Cloudflare;
238
240
  readonly origin: string;
239
241
  Event: typeof Event;
240
242
  ExtendableEvent: typeof ExtendableEvent;
@@ -359,7 +361,7 @@ declare function structuredClone<T>(
359
361
  declare function reportError(error: any): void;
360
362
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/fetch) */
361
363
  declare function fetch(
362
- input: RequestInfo,
364
+ input: RequestInfo | URL,
363
365
  init?: RequestInit<RequestInitCfProperties>,
364
366
  ): Promise<Response>;
365
367
  declare const self: ServiceWorkerGlobalScope;
@@ -386,12 +388,14 @@ declare const scheduler: Scheduler;
386
388
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
387
389
  */
388
390
  declare const performance: Performance;
391
+ declare const Cloudflare: Cloudflare;
389
392
  declare const origin: string;
390
393
  declare const navigator: Navigator;
391
394
  interface TestController {}
392
395
  interface ExecutionContext {
393
396
  waitUntil(promise: Promise<any>): void;
394
397
  passThroughOnException(): void;
398
+ props: any;
395
399
  }
396
400
  type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
397
401
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
@@ -408,6 +412,11 @@ type ExportedHandlerTraceHandler<Env = unknown> = (
408
412
  env: Env,
409
413
  ctx: ExecutionContext,
410
414
  ) => void | Promise<void>;
415
+ type ExportedHandlerTailStreamHandler<Env = unknown> = (
416
+ event: TailStream.TailEvent,
417
+ env: Env,
418
+ ctx: ExecutionContext,
419
+ ) => TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>;
411
420
  type ExportedHandlerScheduledHandler<Env = unknown> = (
412
421
  controller: ScheduledController,
413
422
  env: Env,
@@ -431,6 +440,7 @@ interface ExportedHandler<
431
440
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
432
441
  tail?: ExportedHandlerTailHandler<Env>;
433
442
  trace?: ExportedHandlerTraceHandler<Env>;
443
+ tailStream?: ExportedHandlerTailStreamHandler<Env>;
434
444
  scheduled?: ExportedHandlerScheduledHandler<Env>;
435
445
  test?: ExportedHandlerTestHandler<Env>;
436
446
  email?: EmailExportedHandler<Env>;
@@ -454,8 +464,9 @@ declare abstract class Navigator {
454
464
  | string
455
465
  | (ArrayBuffer | ArrayBufferView)
456
466
  | Blob
467
+ | FormData
457
468
  | URLSearchParams
458
- | FormData,
469
+ | URLSearchParams,
459
470
  ): boolean;
460
471
  readonly userAgent: string;
461
472
  readonly gpu: GPU;
@@ -476,9 +487,12 @@ interface AlarmInvocationInfo {
476
487
  readonly isRetry: boolean;
477
488
  readonly retryCount: number;
478
489
  }
490
+ interface Cloudflare {
491
+ readonly compatibilityFlags: Record<string, boolean>;
492
+ }
479
493
  interface DurableObject {
480
494
  fetch(request: Request): Response | Promise<Response>;
481
- alarm?(): void | Promise<void>;
495
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
482
496
  webSocketMessage?(
483
497
  ws: WebSocket,
484
498
  message: string | ArrayBuffer,
@@ -551,6 +565,7 @@ interface DurableObjectState {
551
565
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): void;
552
566
  getHibernatableWebSocketEventTimeout(): number | null;
553
567
  getTags(ws: WebSocket): string[];
568
+ abort(reason?: string): void;
554
569
  }
555
570
  interface DurableObjectTransaction {
556
571
  get<T = unknown>(
@@ -617,7 +632,11 @@ interface DurableObjectStorage {
617
632
  ): Promise<void>;
618
633
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
619
634
  sync(): Promise<void>;
635
+ sql: SqlStorage;
620
636
  transactionSync<T>(closure: () => T): T;
637
+ getCurrentBookmark(): Promise<string>;
638
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
639
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
621
640
  }
622
641
  interface DurableObjectListOptions {
623
642
  start?: string;
@@ -988,14 +1007,17 @@ declare abstract class CacheStorage {
988
1007
  */
989
1008
  declare abstract class Cache {
990
1009
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#delete) */
991
- delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
1010
+ delete(
1011
+ request: RequestInfo | URL,
1012
+ options?: CacheQueryOptions,
1013
+ ): Promise<boolean>;
992
1014
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#match) */
993
1015
  match(
994
- request: RequestInfo,
1016
+ request: RequestInfo | URL,
995
1017
  options?: CacheQueryOptions,
996
1018
  ): Promise<Response | undefined>;
997
1019
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#put) */
998
- put(request: RequestInfo, response: Response): Promise<void>;
1020
+ put(request: RequestInfo | URL, response: Response): Promise<void>;
999
1021
  }
1000
1022
  interface CacheQueryOptions {
1001
1023
  ignoreMethod?: boolean;
@@ -1418,20 +1440,44 @@ interface Element {
1418
1440
  hasAttribute(name: string): boolean;
1419
1441
  setAttribute(name: string, value: string): Element;
1420
1442
  removeAttribute(name: string): Element;
1421
- before(content: string, options?: ContentOptions): Element;
1422
- after(content: string, options?: ContentOptions): Element;
1423
- prepend(content: string, options?: ContentOptions): Element;
1424
- append(content: string, options?: ContentOptions): Element;
1425
- replace(content: string, options?: ContentOptions): Element;
1443
+ before(
1444
+ content: string | ReadableStream | Response,
1445
+ options?: ContentOptions,
1446
+ ): Element;
1447
+ after(
1448
+ content: string | ReadableStream | Response,
1449
+ options?: ContentOptions,
1450
+ ): Element;
1451
+ prepend(
1452
+ content: string | ReadableStream | Response,
1453
+ options?: ContentOptions,
1454
+ ): Element;
1455
+ append(
1456
+ content: string | ReadableStream | Response,
1457
+ options?: ContentOptions,
1458
+ ): Element;
1459
+ replace(
1460
+ content: string | ReadableStream | Response,
1461
+ options?: ContentOptions,
1462
+ ): Element;
1426
1463
  remove(): Element;
1427
1464
  removeAndKeepContent(): Element;
1428
- setInnerContent(content: string, options?: ContentOptions): Element;
1465
+ setInnerContent(
1466
+ content: string | ReadableStream | Response,
1467
+ options?: ContentOptions,
1468
+ ): Element;
1429
1469
  onEndTag(handler: (tag: EndTag) => void | Promise<void>): void;
1430
1470
  }
1431
1471
  interface EndTag {
1432
1472
  name: string;
1433
- before(content: string, options?: ContentOptions): EndTag;
1434
- after(content: string, options?: ContentOptions): EndTag;
1473
+ before(
1474
+ content: string | ReadableStream | Response,
1475
+ options?: ContentOptions,
1476
+ ): EndTag;
1477
+ after(
1478
+ content: string | ReadableStream | Response,
1479
+ options?: ContentOptions,
1480
+ ): EndTag;
1435
1481
  remove(): EndTag;
1436
1482
  }
1437
1483
  interface Comment {
@@ -1446,9 +1492,18 @@ interface Text {
1446
1492
  readonly text: string;
1447
1493
  readonly lastInTextNode: boolean;
1448
1494
  readonly removed: boolean;
1449
- before(content: string, options?: ContentOptions): Text;
1450
- after(content: string, options?: ContentOptions): Text;
1451
- replace(content: string, options?: ContentOptions): Text;
1495
+ before(
1496
+ content: string | ReadableStream | Response,
1497
+ options?: ContentOptions,
1498
+ ): Text;
1499
+ after(
1500
+ content: string | ReadableStream | Response,
1501
+ options?: ContentOptions,
1502
+ ): Text;
1503
+ replace(
1504
+ content: string | ReadableStream | Response,
1505
+ options?: ContentOptions,
1506
+ ): Text;
1452
1507
  remove(): Text;
1453
1508
  }
1454
1509
  interface DocumentEnd {
@@ -1530,28 +1585,34 @@ declare abstract class Body {
1530
1585
  *
1531
1586
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1532
1587
  */
1533
- declare class Response extends Body {
1534
- constructor(body?: BodyInit | null, init?: ResponseInit);
1535
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
1536
- static redirect(url: string, status?: number): Response;
1537
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
1538
- static json(any: any, maybeInit?: ResponseInit | Response): Response;
1588
+ declare var Response: {
1589
+ prototype: Response;
1590
+ new (body?: BodyInit | null, init?: ResponseInit): Response;
1591
+ redirect(url: string, status?: number): Response;
1592
+ json(any: any, maybeInit?: ResponseInit | Response): Response;
1593
+ };
1594
+ /**
1595
+ * This Fetch API interface represents the response to a request.
1596
+ *
1597
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1598
+ */
1599
+ interface Response extends Body {
1539
1600
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
1540
1601
  clone(): Response;
1541
1602
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status) */
1542
- get status(): number;
1603
+ status: number;
1543
1604
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText) */
1544
- get statusText(): string;
1605
+ statusText: string;
1545
1606
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
1546
- get headers(): Headers;
1607
+ headers: Headers;
1547
1608
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/ok) */
1548
- get ok(): boolean;
1609
+ ok: boolean;
1549
1610
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirected) */
1550
- get redirected(): boolean;
1611
+ redirected: boolean;
1551
1612
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
1552
- get url(): string;
1553
- get webSocket(): WebSocket | null;
1554
- get cf(): any | undefined;
1613
+ url: string;
1614
+ webSocket: WebSocket | null;
1615
+ cf: any | undefined;
1555
1616
  }
1556
1617
  interface ResponseInit {
1557
1618
  status?: number;
@@ -1563,18 +1624,26 @@ interface ResponseInit {
1563
1624
  }
1564
1625
  type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> =
1565
1626
  | Request<CfHostMetadata, Cf>
1566
- | string
1567
- | URL;
1627
+ | string;
1568
1628
  /**
1569
1629
  * This Fetch API interface represents a resource request.
1570
1630
  *
1571
1631
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
1572
1632
  */
1573
- declare class Request<
1574
- CfHostMetadata = unknown,
1575
- Cf = CfProperties<CfHostMetadata>,
1576
- > extends Body {
1577
- constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1633
+ declare var Request: {
1634
+ prototype: Request;
1635
+ new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>(
1636
+ input: RequestInfo<CfProperties> | URL,
1637
+ init?: RequestInit<Cf>,
1638
+ ): Request<CfHostMetadata, Cf>;
1639
+ };
1640
+ /**
1641
+ * This Fetch API interface represents a resource request.
1642
+ *
1643
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
1644
+ */
1645
+ interface Request<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>
1646
+ extends Body {
1578
1647
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/clone) */
1579
1648
  clone(): Request<CfHostMetadata, Cf>;
1580
1649
  /**
@@ -1582,45 +1651,45 @@ declare class Request<
1582
1651
  *
1583
1652
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/method)
1584
1653
  */
1585
- get method(): string;
1654
+ method: string;
1586
1655
  /**
1587
1656
  * Returns the URL of request as a string.
1588
1657
  *
1589
1658
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url)
1590
1659
  */
1591
- get url(): string;
1660
+ url: string;
1592
1661
  /**
1593
1662
  * Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header.
1594
1663
  *
1595
1664
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/headers)
1596
1665
  */
1597
- get headers(): Headers;
1666
+ headers: Headers;
1598
1667
  /**
1599
1668
  * Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default.
1600
1669
  *
1601
1670
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/redirect)
1602
1671
  */
1603
- get redirect(): string;
1604
- get fetcher(): Fetcher | null;
1672
+ redirect: string;
1673
+ fetcher: Fetcher | null;
1605
1674
  /**
1606
1675
  * Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
1607
1676
  *
1608
1677
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/signal)
1609
1678
  */
1610
- get signal(): AbortSignal;
1611
- get cf(): Cf | undefined;
1679
+ signal: AbortSignal;
1680
+ cf: Cf | undefined;
1612
1681
  /**
1613
1682
  * Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI]
1614
1683
  *
1615
1684
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/integrity)
1616
1685
  */
1617
- get integrity(): string;
1686
+ integrity: string;
1618
1687
  /**
1619
1688
  * Returns a boolean indicating whether or not request can outlive the global in which it was created.
1620
1689
  *
1621
1690
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/keepalive)
1622
1691
  */
1623
- get keepalive(): boolean;
1692
+ keepalive: boolean;
1624
1693
  }
1625
1694
  interface RequestInit<Cf = CfProperties> {
1626
1695
  /* A string to set request's method. */
@@ -1646,7 +1715,7 @@ type Fetcher<
1646
1715
  > = (T extends Rpc.EntrypointBranded
1647
1716
  ? Rpc.Provider<T, Reserved | "fetch" | "connect">
1648
1717
  : unknown) & {
1649
- fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1718
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
1650
1719
  connect(address: SocketAddress | string, options?: SocketOptions): Socket;
1651
1720
  };
1652
1721
  interface FetcherPutOptions {
@@ -1868,6 +1937,7 @@ interface R2MultipartUpload {
1868
1937
  uploadPart(
1869
1938
  partNumber: number,
1870
1939
  value: ReadableStream | (ArrayBuffer | ArrayBufferView) | string | Blob,
1940
+ options?: R2UploadPartOptions,
1871
1941
  ): Promise<R2UploadedPart>;
1872
1942
  abort(): Promise<void>;
1873
1943
  complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>;
@@ -1888,6 +1958,7 @@ declare abstract class R2Object {
1888
1958
  readonly customMetadata?: Record<string, string>;
1889
1959
  readonly range?: R2Range;
1890
1960
  readonly storageClass: string;
1961
+ readonly ssecKeyMd5?: string;
1891
1962
  writeHttpMetadata(headers: Headers): void;
1892
1963
  }
1893
1964
  interface R2ObjectBody extends R2Object {
@@ -1920,6 +1991,7 @@ interface R2Conditional {
1920
1991
  interface R2GetOptions {
1921
1992
  onlyIf?: R2Conditional | Headers;
1922
1993
  range?: R2Range | Headers;
1994
+ ssecKey?: ArrayBuffer | string;
1923
1995
  }
1924
1996
  interface R2PutOptions {
1925
1997
  onlyIf?: R2Conditional | Headers;
@@ -1931,11 +2003,13 @@ interface R2PutOptions {
1931
2003
  sha384?: ArrayBuffer | string;
1932
2004
  sha512?: ArrayBuffer | string;
1933
2005
  storageClass?: string;
2006
+ ssecKey?: ArrayBuffer | string;
1934
2007
  }
1935
2008
  interface R2MultipartOptions {
1936
2009
  httpMetadata?: R2HTTPMetadata | Headers;
1937
2010
  customMetadata?: Record<string, string>;
1938
2011
  storageClass?: string;
2012
+ ssecKey?: ArrayBuffer | string;
1939
2013
  }
1940
2014
  interface R2Checksums {
1941
2015
  readonly md5?: ArrayBuffer;
@@ -1972,6 +2046,9 @@ type R2Objects = {
1972
2046
  truncated: false;
1973
2047
  }
1974
2048
  );
2049
+ interface R2UploadPartOptions {
2050
+ ssecKey?: ArrayBuffer | string;
2051
+ }
1975
2052
  declare abstract class ScheduledEvent extends ExtendableEvent {
1976
2053
  readonly scheduledTime: number;
1977
2054
  readonly cron: string;
@@ -2382,6 +2459,8 @@ interface TraceItem {
2382
2459
  readonly dispatchNamespace?: string;
2383
2460
  readonly scriptTags?: string[];
2384
2461
  readonly outcome: string;
2462
+ readonly executionModel: string;
2463
+ readonly truncated: boolean;
2385
2464
  }
2386
2465
  interface TraceItemAlarmEventInfo {
2387
2466
  readonly scheduledTime: Date;
@@ -2695,8 +2774,24 @@ type WebSocketEventMap = {
2695
2774
  *
2696
2775
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
2697
2776
  */
2698
- declare class WebSocket extends EventTarget<WebSocketEventMap> {
2699
- constructor(url: string, protocols?: string[] | string);
2777
+ declare var WebSocket: {
2778
+ prototype: WebSocket;
2779
+ new (url: string, protocols?: string[] | string): WebSocket;
2780
+ readonly READY_STATE_CONNECTING: number;
2781
+ readonly CONNECTING: number;
2782
+ readonly READY_STATE_OPEN: number;
2783
+ readonly OPEN: number;
2784
+ readonly READY_STATE_CLOSING: number;
2785
+ readonly CLOSING: number;
2786
+ readonly READY_STATE_CLOSED: number;
2787
+ readonly CLOSED: number;
2788
+ };
2789
+ /**
2790
+ * Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
2791
+ *
2792
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
2793
+ */
2794
+ interface WebSocket extends EventTarget<WebSocketEventMap> {
2700
2795
  accept(): void;
2701
2796
  /**
2702
2797
  * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
@@ -2712,38 +2807,30 @@ declare class WebSocket extends EventTarget<WebSocketEventMap> {
2712
2807
  close(code?: number, reason?: string): void;
2713
2808
  serializeAttachment(attachment: any): void;
2714
2809
  deserializeAttachment(): any | null;
2715
- static readonly READY_STATE_CONNECTING: number;
2716
- static readonly CONNECTING: number;
2717
- static readonly READY_STATE_OPEN: number;
2718
- static readonly OPEN: number;
2719
- static readonly READY_STATE_CLOSING: number;
2720
- static readonly CLOSING: number;
2721
- static readonly READY_STATE_CLOSED: number;
2722
- static readonly CLOSED: number;
2723
2810
  /**
2724
2811
  * Returns the state of the WebSocket object's connection. It can have the values described below.
2725
2812
  *
2726
2813
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
2727
2814
  */
2728
- get readyState(): number;
2815
+ readyState: number;
2729
2816
  /**
2730
2817
  * Returns the URL that was used to establish the WebSocket connection.
2731
2818
  *
2732
2819
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
2733
2820
  */
2734
- get url(): string | null;
2821
+ url: string | null;
2735
2822
  /**
2736
2823
  * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
2737
2824
  *
2738
2825
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
2739
2826
  */
2740
- get protocol(): string | null;
2827
+ protocol: string | null;
2741
2828
  /**
2742
2829
  * Returns the extensions selected by the server, if any.
2743
2830
  *
2744
2831
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
2745
2832
  */
2746
- get extensions(): string | null;
2833
+ extensions: string | null;
2747
2834
  }
2748
2835
  declare const WebSocketPair: {
2749
2836
  new (): {
@@ -2751,6 +2838,37 @@ declare const WebSocketPair: {
2751
2838
  1: WebSocket;
2752
2839
  };
2753
2840
  };
2841
+ interface SqlStorage {
2842
+ exec<T extends Record<string, SqlStorageValue>>(
2843
+ query: string,
2844
+ ...bindings: any[]
2845
+ ): SqlStorageCursor<T>;
2846
+ get databaseSize(): number;
2847
+ Cursor: typeof SqlStorageCursor;
2848
+ Statement: typeof SqlStorageStatement;
2849
+ }
2850
+ declare abstract class SqlStorageStatement {}
2851
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2852
+ declare abstract class SqlStorageCursor<
2853
+ T extends Record<string, SqlStorageValue>,
2854
+ > {
2855
+ next():
2856
+ | {
2857
+ done?: false;
2858
+ value: T;
2859
+ }
2860
+ | {
2861
+ done: true;
2862
+ value?: never;
2863
+ };
2864
+ toArray(): T[];
2865
+ one(): T;
2866
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2867
+ columnNames: string[];
2868
+ get rowsRead(): number;
2869
+ get rowsWritten(): number;
2870
+ [Symbol.iterator](): IterableIterator<T>;
2871
+ }
2754
2872
  interface Socket {
2755
2873
  get readable(): ReadableStream;
2756
2874
  get writable(): WritableStream;
@@ -3288,7 +3406,7 @@ interface GPUOrigin3DDict {
3288
3406
  z?: number;
3289
3407
  }
3290
3408
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3291
- declare class EventSource {
3409
+ declare class EventSource extends EventTarget {
3292
3410
  constructor(url: string, init?: EventSourceEventSourceInit);
3293
3411
  /**
3294
3412
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -3387,10 +3505,10 @@ declare abstract class BaseAiSentenceSimilarity {
3387
3505
  inputs: AiSentenceSimilarityInput;
3388
3506
  postProcessedOutputs: AiSentenceSimilarityOutput;
3389
3507
  }
3390
- type AiSpeechRecognitionInput = {
3508
+ type AiAutomaticSpeechRecognitionInput = {
3391
3509
  audio: number[];
3392
3510
  };
3393
- type AiSpeechRecognitionOutput = {
3511
+ type AiAutomaticSpeechRecognitionOutput = {
3394
3512
  text?: string;
3395
3513
  words?: {
3396
3514
  word: string;
@@ -3399,9 +3517,9 @@ type AiSpeechRecognitionOutput = {
3399
3517
  }[];
3400
3518
  vtt?: string;
3401
3519
  };
3402
- declare abstract class BaseAiSpeechRecognition {
3403
- inputs: AiSpeechRecognitionInput;
3404
- postProcessedOutputs: AiSpeechRecognitionOutput;
3520
+ declare abstract class BaseAiAutomaticSpeechRecognition {
3521
+ inputs: AiAutomaticSpeechRecognitionInput;
3522
+ postProcessedOutputs: AiAutomaticSpeechRecognitionOutput;
3405
3523
  }
3406
3524
  type AiSummarizationInput = {
3407
3525
  input_text: string;
@@ -3437,16 +3555,36 @@ declare abstract class BaseAiTextEmbeddings {
3437
3555
  postProcessedOutputs: AiTextEmbeddingsOutput;
3438
3556
  }
3439
3557
  type RoleScopedChatInput = {
3440
- role: "user" | "assistant" | "system" | "tool";
3558
+ role:
3559
+ | "user"
3560
+ | "assistant"
3561
+ | "system"
3562
+ | "tool"
3563
+ | (string & NonNullable<unknown>);
3441
3564
  content: string;
3565
+ name?: string;
3566
+ };
3567
+ type AiTextGenerationToolLegacyInput = {
3568
+ name: string;
3569
+ description: string;
3570
+ parameters?: {
3571
+ type: "object" | (string & NonNullable<unknown>);
3572
+ properties: {
3573
+ [key: string]: {
3574
+ type: string;
3575
+ description?: string;
3576
+ };
3577
+ };
3578
+ required: string[];
3579
+ };
3442
3580
  };
3443
3581
  type AiTextGenerationToolInput = {
3444
- type: "function";
3582
+ type: "function" | (string & NonNullable<unknown>);
3445
3583
  function: {
3446
3584
  name: string;
3447
3585
  description: string;
3448
3586
  parameters?: {
3449
- type: "object";
3587
+ type: "object" | (string & NonNullable<unknown>);
3450
3588
  properties: {
3451
3589
  [key: string]: {
3452
3590
  type: string;
@@ -3457,6 +3595,10 @@ type AiTextGenerationToolInput = {
3457
3595
  };
3458
3596
  };
3459
3597
  };
3598
+ type AiTextGenerationFunctionsInput = {
3599
+ name: string;
3600
+ code: string;
3601
+ };
3460
3602
  type AiTextGenerationInput = {
3461
3603
  prompt?: string;
3462
3604
  raw?: boolean;
@@ -3470,7 +3612,11 @@ type AiTextGenerationInput = {
3470
3612
  frequency_penalty?: number;
3471
3613
  presence_penalty?: number;
3472
3614
  messages?: RoleScopedChatInput[];
3473
- tools?: AiTextGenerationToolInput[];
3615
+ tools?:
3616
+ | AiTextGenerationToolInput[]
3617
+ | AiTextGenerationToolLegacyInput[]
3618
+ | (object & NonNullable<unknown>);
3619
+ functions?: AiTextGenerationFunctionsInput[];
3474
3620
  };
3475
3621
  type AiTextGenerationOutput =
3476
3622
  | {
@@ -3485,15 +3631,33 @@ declare abstract class BaseAiTextGeneration {
3485
3631
  inputs: AiTextGenerationInput;
3486
3632
  postProcessedOutputs: AiTextGenerationOutput;
3487
3633
  }
3634
+ type AiTextToSpeechInput = {
3635
+ prompt: string;
3636
+ lang?: string;
3637
+ };
3638
+ type AiTextToSpeechOutput =
3639
+ | Uint8Array
3640
+ | {
3641
+ audio: string;
3642
+ };
3643
+ declare abstract class BaseAiTextToSpeech {
3644
+ inputs: AiTextToSpeechInput;
3645
+ postProcessedOutputs: AiTextToSpeechOutput;
3646
+ }
3488
3647
  type AiTextToImageInput = {
3489
3648
  prompt: string;
3649
+ negative_prompt?: string;
3650
+ height?: number;
3651
+ width?: number;
3490
3652
  image?: number[];
3653
+ image_b64?: string;
3491
3654
  mask?: number[];
3492
3655
  num_steps?: number;
3493
3656
  strength?: number;
3494
3657
  guidance?: number;
3658
+ seed?: number;
3495
3659
  };
3496
- type AiTextToImageOutput = Uint8Array;
3660
+ type AiTextToImageOutput = ReadableStream<Uint8Array>;
3497
3661
  declare abstract class BaseAiTextToImage {
3498
3662
  inputs: AiTextToImageInput;
3499
3663
  postProcessedOutputs: AiTextToImageOutput;
@@ -3510,126 +3674,613 @@ declare abstract class BaseAiTranslation {
3510
3674
  inputs: AiTranslationInput;
3511
3675
  postProcessedOutputs: AiTranslationOutput;
3512
3676
  }
3677
+ type Ai_Cf_Openai_Whisper_Input =
3678
+ | string
3679
+ | {
3680
+ /**
3681
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3682
+ */
3683
+ audio: number[];
3684
+ };
3685
+ interface Ai_Cf_Openai_Whisper_Output {
3686
+ /**
3687
+ * The transcription
3688
+ */
3689
+ text: string;
3690
+ word_count?: number;
3691
+ words?: {
3692
+ word?: string;
3693
+ /**
3694
+ * The second this word begins in the recording
3695
+ */
3696
+ start?: number;
3697
+ /**
3698
+ * The ending second when the word completes
3699
+ */
3700
+ end?: number;
3701
+ }[];
3702
+ vtt?: string;
3703
+ }
3704
+ declare abstract class Base_Ai_Cf_Openai_Whisper {
3705
+ inputs: Ai_Cf_Openai_Whisper_Input;
3706
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Output;
3707
+ }
3708
+ type Ai_Cf_Openai_Whisper_Tiny_En_Input =
3709
+ | string
3710
+ | {
3711
+ /**
3712
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3713
+ */
3714
+ audio: number[];
3715
+ };
3716
+ interface Ai_Cf_Openai_Whisper_Tiny_En_Output {
3717
+ /**
3718
+ * The transcription
3719
+ */
3720
+ text: string;
3721
+ word_count?: number;
3722
+ words?: {
3723
+ word?: string;
3724
+ /**
3725
+ * The second this word begins in the recording
3726
+ */
3727
+ start?: number;
3728
+ /**
3729
+ * The ending second when the word completes
3730
+ */
3731
+ end?: number;
3732
+ }[];
3733
+ vtt?: string;
3734
+ }
3735
+ declare abstract class Base_Ai_Cf_Openai_Whisper_Tiny_En {
3736
+ inputs: Ai_Cf_Openai_Whisper_Tiny_En_Input;
3737
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Tiny_En_Output;
3738
+ }
3739
+ interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input {
3740
+ /**
3741
+ * Base64 encoded value of the audio data.
3742
+ */
3743
+ audio: string;
3744
+ /**
3745
+ * Supported tasks are 'translate' or 'transcribe'.
3746
+ */
3747
+ task?: string;
3748
+ /**
3749
+ * The language of the audio being transcribed or translated.
3750
+ */
3751
+ language?: string;
3752
+ /**
3753
+ * Preprocess the audio with a voice activity detection model.
3754
+ */
3755
+ vad_filter?: string;
3756
+ /**
3757
+ * A text prompt to help provide context to the model on the contents of the audio.
3758
+ */
3759
+ initial_prompt?: string;
3760
+ /**
3761
+ * The prefix it appended the the beginning of the output of the transcription and can guide the transcription result.
3762
+ */
3763
+ prefix?: string;
3764
+ }
3765
+ interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output {
3766
+ transcription_info?: {
3767
+ /**
3768
+ * The language of the audio being transcribed or translated.
3769
+ */
3770
+ language?: string;
3771
+ /**
3772
+ * The confidence level or probability of the detected language being accurate, represented as a decimal between 0 and 1.
3773
+ */
3774
+ language_probability?: number;
3775
+ /**
3776
+ * The total duration of the original audio file, in seconds.
3777
+ */
3778
+ duration?: number;
3779
+ /**
3780
+ * The duration of the audio after applying Voice Activity Detection (VAD) to remove silent or irrelevant sections, in seconds.
3781
+ */
3782
+ duration_after_vad?: number;
3783
+ };
3784
+ /**
3785
+ * The complete transcription of the audio.
3786
+ */
3787
+ text: string;
3788
+ /**
3789
+ * The total number of words in the transcription.
3790
+ */
3791
+ word_count?: number;
3792
+ segments?: {
3793
+ /**
3794
+ * The starting time of the segment within the audio, in seconds.
3795
+ */
3796
+ start?: number;
3797
+ /**
3798
+ * The ending time of the segment within the audio, in seconds.
3799
+ */
3800
+ end?: number;
3801
+ /**
3802
+ * The transcription of the segment.
3803
+ */
3804
+ text?: string;
3805
+ /**
3806
+ * The temperature used in the decoding process, controlling randomness in predictions. Lower values result in more deterministic outputs.
3807
+ */
3808
+ temperature?: number;
3809
+ /**
3810
+ * The average log probability of the predictions for the words in this segment, indicating overall confidence.
3811
+ */
3812
+ avg_logprob?: number;
3813
+ /**
3814
+ * The compression ratio of the input to the output, measuring how much the text was compressed during the transcription process.
3815
+ */
3816
+ compression_ratio?: number;
3817
+ /**
3818
+ * The probability that the segment contains no speech, represented as a decimal between 0 and 1.
3819
+ */
3820
+ no_speech_prob?: number;
3821
+ words?: {
3822
+ /**
3823
+ * The individual word transcribed from the audio.
3824
+ */
3825
+ word?: string;
3826
+ /**
3827
+ * The starting time of the word within the audio, in seconds.
3828
+ */
3829
+ start?: number;
3830
+ /**
3831
+ * The ending time of the word within the audio, in seconds.
3832
+ */
3833
+ end?: number;
3834
+ }[];
3835
+ };
3836
+ /**
3837
+ * The transcription in WebVTT format, which includes timing and text information for use in subtitles.
3838
+ */
3839
+ vtt?: string;
3840
+ }
3841
+ declare abstract class Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo {
3842
+ inputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input;
3843
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output;
3844
+ }
3845
+ interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input {
3846
+ /**
3847
+ * A text description of the image you want to generate.
3848
+ */
3849
+ prompt: string;
3850
+ /**
3851
+ * The number of diffusion steps; higher values can improve quality but take longer.
3852
+ */
3853
+ steps?: number;
3854
+ }
3855
+ interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output {
3856
+ /**
3857
+ * The generated image in Base64 format.
3858
+ */
3859
+ image?: string;
3860
+ }
3861
+ declare abstract class Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell {
3862
+ inputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input;
3863
+ postProcessedOutputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output;
3864
+ }
3865
+ type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input = Prompt | Messages;
3866
+ interface Prompt {
3867
+ /**
3868
+ * The input text prompt for the model to generate a response.
3869
+ */
3870
+ prompt: string;
3871
+ image?: number[] | (string & NonNullable<unknown>);
3872
+ /**
3873
+ * If true, a chat template is not applied and you must adhere to the specific model's expected formatting.
3874
+ */
3875
+ raw?: boolean;
3876
+ /**
3877
+ * If true, the response will be streamed back incrementally using SSE, Server Sent Events.
3878
+ */
3879
+ stream?: boolean;
3880
+ /**
3881
+ * The maximum number of tokens to generate in the response.
3882
+ */
3883
+ max_tokens?: number;
3884
+ /**
3885
+ * Controls the randomness of the output; higher values produce more random results.
3886
+ */
3887
+ temperature?: number;
3888
+ /**
3889
+ * Adjusts the creativity of the AI's responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses.
3890
+ */
3891
+ top_p?: number;
3892
+ /**
3893
+ * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises.
3894
+ */
3895
+ top_k?: number;
3896
+ /**
3897
+ * Random seed for reproducibility of the generation.
3898
+ */
3899
+ seed?: number;
3900
+ /**
3901
+ * Penalty for repeated tokens; higher values discourage repetition.
3902
+ */
3903
+ repetition_penalty?: number;
3904
+ /**
3905
+ * Decreases the likelihood of the model repeating the same lines verbatim.
3906
+ */
3907
+ frequency_penalty?: number;
3908
+ /**
3909
+ * Increases the likelihood of the model introducing new topics.
3910
+ */
3911
+ presence_penalty?: number;
3912
+ /**
3913
+ * Name of the LoRA (Low-Rank Adaptation) model to fine-tune the base model.
3914
+ */
3915
+ lora?: string;
3916
+ }
3917
+ interface Messages {
3918
+ /**
3919
+ * An array of message objects representing the conversation history.
3920
+ */
3921
+ messages: {
3922
+ /**
3923
+ * The role of the message sender (e.g., 'user', 'assistant', 'system', 'tool').
3924
+ */
3925
+ role: string;
3926
+ /**
3927
+ * The content of the message as a string.
3928
+ */
3929
+ content: string;
3930
+ }[];
3931
+ image?: number[] | string;
3932
+ functions?: {
3933
+ name: string;
3934
+ code: string;
3935
+ }[];
3936
+ /**
3937
+ * A list of tools available for the assistant to use.
3938
+ */
3939
+ tools?: (
3940
+ | {
3941
+ /**
3942
+ * The name of the tool. More descriptive the better.
3943
+ */
3944
+ name: string;
3945
+ /**
3946
+ * A brief description of what the tool does.
3947
+ */
3948
+ description: string;
3949
+ /**
3950
+ * Schema defining the parameters accepted by the tool.
3951
+ */
3952
+ parameters: {
3953
+ /**
3954
+ * The type of the parameters object (usually 'object').
3955
+ */
3956
+ type: string;
3957
+ /**
3958
+ * List of required parameter names.
3959
+ */
3960
+ required?: string[];
3961
+ /**
3962
+ * Definitions of each parameter.
3963
+ */
3964
+ properties: {
3965
+ [k: string]: {
3966
+ /**
3967
+ * The data type of the parameter.
3968
+ */
3969
+ type: string;
3970
+ /**
3971
+ * A description of the expected parameter.
3972
+ */
3973
+ description: string;
3974
+ };
3975
+ };
3976
+ };
3977
+ }
3978
+ | {
3979
+ /**
3980
+ * Specifies the type of tool (e.g., 'function').
3981
+ */
3982
+ type: string;
3983
+ /**
3984
+ * Details of the function tool.
3985
+ */
3986
+ function: {
3987
+ /**
3988
+ * The name of the function.
3989
+ */
3990
+ name: string;
3991
+ /**
3992
+ * A brief description of what the function does.
3993
+ */
3994
+ description: string;
3995
+ /**
3996
+ * Schema defining the parameters accepted by the function.
3997
+ */
3998
+ parameters: {
3999
+ /**
4000
+ * The type of the parameters object (usually 'object').
4001
+ */
4002
+ type: string;
4003
+ /**
4004
+ * List of required parameter names.
4005
+ */
4006
+ required?: string[];
4007
+ /**
4008
+ * Definitions of each parameter.
4009
+ */
4010
+ properties: {
4011
+ [k: string]: {
4012
+ /**
4013
+ * The data type of the parameter.
4014
+ */
4015
+ type: string;
4016
+ /**
4017
+ * A description of the expected parameter.
4018
+ */
4019
+ description: string;
4020
+ };
4021
+ };
4022
+ };
4023
+ };
4024
+ }
4025
+ )[];
4026
+ /**
4027
+ * If true, the response will be streamed back incrementally.
4028
+ */
4029
+ stream?: boolean;
4030
+ /**
4031
+ * The maximum number of tokens to generate in the response.
4032
+ */
4033
+ max_tokens?: number;
4034
+ /**
4035
+ * Controls the randomness of the output; higher values produce more random results.
4036
+ */
4037
+ temperature?: number;
4038
+ /**
4039
+ * Controls the creativity of the AI's responses by adjusting how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses.
4040
+ */
4041
+ top_p?: number;
4042
+ /**
4043
+ * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises.
4044
+ */
4045
+ top_k?: number;
4046
+ /**
4047
+ * Random seed for reproducibility of the generation.
4048
+ */
4049
+ seed?: number;
4050
+ /**
4051
+ * Penalty for repeated tokens; higher values discourage repetition.
4052
+ */
4053
+ repetition_penalty?: number;
4054
+ /**
4055
+ * Decreases the likelihood of the model repeating the same lines verbatim.
4056
+ */
4057
+ frequency_penalty?: number;
4058
+ /**
4059
+ * Increases the likelihood of the model introducing new topics.
4060
+ */
4061
+ presence_penalty?: number;
4062
+ }
4063
+ type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output =
4064
+ | {
4065
+ /**
4066
+ * The generated text response from the model
4067
+ */
4068
+ response?: string;
4069
+ /**
4070
+ * An array of tool calls requests made during the response generation
4071
+ */
4072
+ tool_calls?: {
4073
+ /**
4074
+ * The arguments passed to be passed to the tool call request
4075
+ */
4076
+ arguments?: object;
4077
+ /**
4078
+ * The name of the tool to be called
4079
+ */
4080
+ name?: string;
4081
+ }[];
4082
+ }
4083
+ | ReadableStream;
4084
+ declare abstract class Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct {
4085
+ inputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input;
4086
+ postProcessedOutputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output;
4087
+ }
4088
+ interface AiModels {
4089
+ "@cf/huggingface/distilbert-sst-2-int8": BaseAiTextClassification;
4090
+ "@cf/stabilityai/stable-diffusion-xl-base-1.0": BaseAiTextToImage;
4091
+ "@cf/runwayml/stable-diffusion-v1-5-inpainting": BaseAiTextToImage;
4092
+ "@cf/runwayml/stable-diffusion-v1-5-img2img": BaseAiTextToImage;
4093
+ "@cf/lykon/dreamshaper-8-lcm": BaseAiTextToImage;
4094
+ "@cf/bytedance/stable-diffusion-xl-lightning": BaseAiTextToImage;
4095
+ "@cf/baai/bge-base-en-v1.5": BaseAiTextEmbeddings;
4096
+ "@cf/baai/bge-small-en-v1.5": BaseAiTextEmbeddings;
4097
+ "@cf/baai/bge-large-en-v1.5": BaseAiTextEmbeddings;
4098
+ "@cf/microsoft/resnet-50": BaseAiImageClassification;
4099
+ "@cf/facebook/detr-resnet-50": BaseAiObjectDetection;
4100
+ "@cf/meta/llama-2-7b-chat-int8": BaseAiTextGeneration;
4101
+ "@cf/mistral/mistral-7b-instruct-v0.1": BaseAiTextGeneration;
4102
+ "@cf/meta/llama-2-7b-chat-fp16": BaseAiTextGeneration;
4103
+ "@hf/thebloke/llama-2-13b-chat-awq": BaseAiTextGeneration;
4104
+ "@hf/thebloke/mistral-7b-instruct-v0.1-awq": BaseAiTextGeneration;
4105
+ "@hf/thebloke/zephyr-7b-beta-awq": BaseAiTextGeneration;
4106
+ "@hf/thebloke/openhermes-2.5-mistral-7b-awq": BaseAiTextGeneration;
4107
+ "@hf/thebloke/neural-chat-7b-v3-1-awq": BaseAiTextGeneration;
4108
+ "@hf/thebloke/llamaguard-7b-awq": BaseAiTextGeneration;
4109
+ "@hf/thebloke/deepseek-coder-6.7b-base-awq": BaseAiTextGeneration;
4110
+ "@hf/thebloke/deepseek-coder-6.7b-instruct-awq": BaseAiTextGeneration;
4111
+ "@cf/deepseek-ai/deepseek-math-7b-instruct": BaseAiTextGeneration;
4112
+ "@cf/defog/sqlcoder-7b-2": BaseAiTextGeneration;
4113
+ "@cf/openchat/openchat-3.5-0106": BaseAiTextGeneration;
4114
+ "@cf/tiiuae/falcon-7b-instruct": BaseAiTextGeneration;
4115
+ "@cf/thebloke/discolm-german-7b-v1-awq": BaseAiTextGeneration;
4116
+ "@cf/qwen/qwen1.5-0.5b-chat": BaseAiTextGeneration;
4117
+ "@cf/qwen/qwen1.5-7b-chat-awq": BaseAiTextGeneration;
4118
+ "@cf/qwen/qwen1.5-14b-chat-awq": BaseAiTextGeneration;
4119
+ "@cf/tinyllama/tinyllama-1.1b-chat-v1.0": BaseAiTextGeneration;
4120
+ "@cf/microsoft/phi-2": BaseAiTextGeneration;
4121
+ "@cf/qwen/qwen1.5-1.8b-chat": BaseAiTextGeneration;
4122
+ "@cf/mistral/mistral-7b-instruct-v0.2-lora": BaseAiTextGeneration;
4123
+ "@hf/nousresearch/hermes-2-pro-mistral-7b": BaseAiTextGeneration;
4124
+ "@hf/nexusflow/starling-lm-7b-beta": BaseAiTextGeneration;
4125
+ "@hf/google/gemma-7b-it": BaseAiTextGeneration;
4126
+ "@cf/meta-llama/llama-2-7b-chat-hf-lora": BaseAiTextGeneration;
4127
+ "@cf/google/gemma-2b-it-lora": BaseAiTextGeneration;
4128
+ "@cf/google/gemma-7b-it-lora": BaseAiTextGeneration;
4129
+ "@hf/mistral/mistral-7b-instruct-v0.2": BaseAiTextGeneration;
4130
+ "@cf/meta/llama-3-8b-instruct": BaseAiTextGeneration;
4131
+ "@cf/fblgit/una-cybertron-7b-v2-bf16": BaseAiTextGeneration;
4132
+ "@cf/meta/llama-3-8b-instruct-awq": BaseAiTextGeneration;
4133
+ "@hf/meta-llama/meta-llama-3-8b-instruct": BaseAiTextGeneration;
4134
+ "@cf/meta/llama-3.1-8b-instruct": BaseAiTextGeneration;
4135
+ "@cf/meta/llama-3.1-8b-instruct-fp8": BaseAiTextGeneration;
4136
+ "@cf/meta/llama-3.1-8b-instruct-awq": BaseAiTextGeneration;
4137
+ "@cf/meta/llama-3.2-3b-instruct": BaseAiTextGeneration;
4138
+ "@cf/meta/llama-3.2-1b-instruct": BaseAiTextGeneration;
4139
+ "@cf/meta/llama-3.3-70b-instruct-fp8-fast": BaseAiTextGeneration;
4140
+ "@cf/meta/m2m100-1.2b": BaseAiTranslation;
4141
+ "@cf/facebook/bart-large-cnn": BaseAiSummarization;
4142
+ "@cf/unum/uform-gen2-qwen-500m": BaseAiImageToText;
4143
+ "@cf/llava-hf/llava-1.5-7b-hf": BaseAiImageToText;
4144
+ "@cf/openai/whisper": Base_Ai_Cf_Openai_Whisper;
4145
+ "@cf/openai/whisper-tiny-en": Base_Ai_Cf_Openai_Whisper_Tiny_En;
4146
+ "@cf/openai/whisper-large-v3-turbo": Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo;
4147
+ "@cf/black-forest-labs/flux-1-schnell": Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell;
4148
+ "@cf/meta/llama-3.2-11b-vision-instruct": Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct;
4149
+ }
4150
+ type AiOptions = {
4151
+ gateway?: GatewayOptions;
4152
+ prefix?: string;
4153
+ extraHeaders?: object;
4154
+ };
4155
+ type AiModelsSearchParams = {
4156
+ author?: string;
4157
+ hide_experimental?: boolean;
4158
+ page?: number;
4159
+ per_page?: number;
4160
+ search?: string;
4161
+ source?: number;
4162
+ task?: string;
4163
+ };
4164
+ type AiModelsSearchObject = {
4165
+ id: string;
4166
+ source: number;
4167
+ name: string;
4168
+ description: string;
4169
+ task: {
4170
+ id: string;
4171
+ name: string;
4172
+ description: string;
4173
+ };
4174
+ tags: string[];
4175
+ properties: {
4176
+ property_id: string;
4177
+ value: string;
4178
+ }[];
4179
+ };
4180
+ interface InferenceUpstreamError extends Error {}
4181
+ interface AiInternalError extends Error {}
4182
+ type AiModelListType = Record<string, any>;
4183
+ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
4184
+ aiGatewayLogId: string | null;
4185
+ gateway(gatewayId: string): AiGateway;
4186
+ run<Name extends keyof AiModelList>(
4187
+ model: Name,
4188
+ inputs: AiModelList[Name]["inputs"],
4189
+ options?: AiOptions,
4190
+ ): Promise<AiModelList[Name]["postProcessedOutputs"]>;
4191
+ public models(params?: AiModelsSearchParams): Promise<AiModelsSearchObject[]>;
4192
+ }
3513
4193
  type GatewayOptions = {
3514
4194
  id: string;
4195
+ cacheKey?: string;
3515
4196
  cacheTtl?: number;
3516
4197
  skipCache?: boolean;
3517
4198
  metadata?: Record<string, number | string | boolean | null | bigint>;
4199
+ collectLog?: boolean;
3518
4200
  };
3519
- type AiOptions = {
3520
- gateway?: GatewayOptions;
3521
- prefix?: string;
3522
- extraHeaders?: object;
4201
+ type AiGatewayPatchLog = {
4202
+ score?: number | null;
4203
+ feedback?: -1 | 1 | null;
4204
+ metadata?: Record<string, number | string | boolean | null | bigint> | null;
3523
4205
  };
3524
- type BaseAiTextClassificationModels = "@cf/huggingface/distilbert-sst-2-int8";
3525
- type BaseAiTextToImageModels =
3526
- | "@cf/stabilityai/stable-diffusion-xl-base-1.0"
3527
- | "@cf/runwayml/stable-diffusion-v1-5-inpainting"
3528
- | "@cf/runwayml/stable-diffusion-v1-5-img2img"
3529
- | "@cf/lykon/dreamshaper-8-lcm"
3530
- | "@cf/bytedance/stable-diffusion-xl-lightning";
3531
- type BaseAiTextEmbeddingsModels =
3532
- | "@cf/baai/bge-small-en-v1.5"
3533
- | "@cf/baai/bge-base-en-v1.5"
3534
- | "@cf/baai/bge-large-en-v1.5";
3535
- type BaseAiSpeechRecognitionModels =
3536
- | "@cf/openai/whisper"
3537
- | "@cf/openai/whisper-tiny-en"
3538
- | "@cf/openai/whisper-sherpa";
3539
- type BaseAiImageClassificationModels = "@cf/microsoft/resnet-50";
3540
- type BaseAiObjectDetectionModels = "@cf/facebook/detr-resnet-50";
3541
- type BaseAiTextGenerationModels =
3542
- | "@cf/meta/llama-3-8b-instruct"
3543
- | "@cf/meta/llama-3-8b-instruct-awq"
3544
- | "@cf/meta/llama-2-7b-chat-int8"
3545
- | "@cf/mistral/mistral-7b-instruct-v0.1"
3546
- | "@cf/mistral/mistral-7b-instruct-v0.2-lora"
3547
- | "@cf/meta/llama-2-7b-chat-fp16"
3548
- | "@hf/thebloke/llama-2-13b-chat-awq"
3549
- | "@hf/thebloke/zephyr-7b-beta-awq"
3550
- | "@hf/thebloke/mistral-7b-instruct-v0.1-awq"
3551
- | "@hf/thebloke/codellama-7b-instruct-awq"
3552
- | "@hf/thebloke/openhermes-2.5-mistral-7b-awq"
3553
- | "@hf/thebloke/neural-chat-7b-v3-1-awq"
3554
- | "@hf/thebloke/llamaguard-7b-awq"
3555
- | "@hf/thebloke/deepseek-coder-6.7b-base-awq"
3556
- | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq"
3557
- | "@hf/nousresearch/hermes-2-pro-mistral-7b"
3558
- | "@hf/mistral/mistral-7b-instruct-v0.2"
3559
- | "@hf/google/gemma-7b-it"
3560
- | "@hf/nexusflow/starling-lm-7b-beta"
3561
- | "@cf/deepseek-ai/deepseek-math-7b-instruct"
3562
- | "@cf/defog/sqlcoder-7b-2"
3563
- | "@cf/openchat/openchat-3.5-0106"
3564
- | "@cf/tiiuae/falcon-7b-instruct"
3565
- | "@cf/thebloke/discolm-german-7b-v1-awq"
3566
- | "@cf/qwen/qwen1.5-0.5b-chat"
3567
- | "@cf/qwen/qwen1.5-1.8b-chat"
3568
- | "@cf/qwen/qwen1.5-7b-chat-awq"
3569
- | "@cf/qwen/qwen1.5-14b-chat-awq"
3570
- | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0"
3571
- | "@cf/microsoft/phi-2"
3572
- | "@cf/google/gemma-2b-it-lora"
3573
- | "@cf/google/gemma-7b-it-lora"
3574
- | "@cf/meta-llama/llama-2-7b-chat-hf-lora"
3575
- | "@cf/fblgit/una-cybertron-7b-v2-bf16"
3576
- | "@cf/fblgit/una-cybertron-7b-v2-awq";
3577
- type BaseAiTranslationModels = "@cf/meta/m2m100-1.2b";
3578
- type BaseAiSummarizationModels = "@cf/facebook/bart-large-cnn";
3579
- type BaseAiImageToTextModels =
3580
- | "@cf/unum/uform-gen2-qwen-500m"
3581
- | "@cf/llava-hf/llava-1.5-7b-hf";
3582
- declare abstract class Ai {
3583
- run(
3584
- model: BaseAiTextClassificationModels,
3585
- inputs: BaseAiTextClassification["inputs"],
3586
- options?: AiOptions,
3587
- ): Promise<BaseAiTextClassification["postProcessedOutputs"]>;
3588
- run(
3589
- model: BaseAiTextToImageModels,
3590
- inputs: BaseAiTextToImage["inputs"],
3591
- options?: AiOptions,
3592
- ): Promise<BaseAiTextToImage["postProcessedOutputs"]>;
3593
- run(
3594
- model: BaseAiTextEmbeddingsModels,
3595
- inputs: BaseAiTextEmbeddings["inputs"],
3596
- options?: AiOptions,
3597
- ): Promise<BaseAiTextEmbeddings["postProcessedOutputs"]>;
3598
- run(
3599
- model: BaseAiSpeechRecognitionModels,
3600
- inputs: BaseAiSpeechRecognition["inputs"],
3601
- options?: AiOptions,
3602
- ): Promise<BaseAiSpeechRecognition["postProcessedOutputs"]>;
3603
- run(
3604
- model: BaseAiImageClassificationModels,
3605
- inputs: BaseAiImageClassification["inputs"],
3606
- options?: AiOptions,
3607
- ): Promise<BaseAiImageClassification["postProcessedOutputs"]>;
3608
- run(
3609
- model: BaseAiObjectDetectionModels,
3610
- inputs: BaseAiObjectDetection["inputs"],
3611
- options?: AiOptions,
3612
- ): Promise<BaseAiObjectDetection["postProcessedOutputs"]>;
3613
- run(
3614
- model: BaseAiTextGenerationModels,
3615
- inputs: BaseAiTextGeneration["inputs"],
3616
- options?: AiOptions,
3617
- ): Promise<BaseAiTextGeneration["postProcessedOutputs"]>;
3618
- run(
3619
- model: BaseAiTranslationModels,
3620
- inputs: BaseAiTranslation["inputs"],
3621
- options?: AiOptions,
3622
- ): Promise<BaseAiTranslation["postProcessedOutputs"]>;
3623
- run(
3624
- model: BaseAiSummarizationModels,
3625
- inputs: BaseAiSummarization["inputs"],
3626
- options?: AiOptions,
3627
- ): Promise<BaseAiSummarization["postProcessedOutputs"]>;
4206
+ type AiGatewayLog = {
4207
+ id: string;
4208
+ provider: string;
4209
+ model: string;
4210
+ model_type?: string;
4211
+ path: string;
4212
+ duration: number;
4213
+ request_type?: string;
4214
+ request_content_type?: string;
4215
+ status_code: number;
4216
+ response_content_type?: string;
4217
+ success: boolean;
4218
+ cached: boolean;
4219
+ tokens_in?: number;
4220
+ tokens_out?: number;
4221
+ metadata?: Record<string, number | string | boolean | null | bigint>;
4222
+ step?: number;
4223
+ cost?: number;
4224
+ custom_cost?: boolean;
4225
+ request_size: number;
4226
+ request_head?: string;
4227
+ request_head_complete: boolean;
4228
+ response_size: number;
4229
+ response_head?: string;
4230
+ response_head_complete: boolean;
4231
+ created_at: Date;
4232
+ };
4233
+ type AIGatewayProviders =
4234
+ | "workers-ai"
4235
+ | "anthropic"
4236
+ | "aws-bedrock"
4237
+ | "azure-openai"
4238
+ | "google-vertex-ai"
4239
+ | "huggingface"
4240
+ | "openai"
4241
+ | "perplexity-ai"
4242
+ | "replicate"
4243
+ | "groq"
4244
+ | "cohere"
4245
+ | "google-ai-studio"
4246
+ | "mistral"
4247
+ | "grok"
4248
+ | "openrouter";
4249
+ type AIGatewayHeaders = {
4250
+ "cf-aig-metadata":
4251
+ | Record<string, number | string | boolean | null | bigint>
4252
+ | string;
4253
+ "cf-aig-custom-cost":
4254
+ | {
4255
+ per_token_in?: number;
4256
+ per_token_out?: number;
4257
+ }
4258
+ | {
4259
+ total_cost?: number;
4260
+ }
4261
+ | string;
4262
+ "cf-aig-cache-ttl": number | string;
4263
+ "cf-aig-skip-cache": boolean | string;
4264
+ "cf-aig-cache-key": string;
4265
+ "cf-aig-collect-log": boolean | string;
4266
+ Authorization: string;
4267
+ "Content-Type": string;
4268
+ [key: string]: string | number | boolean | object;
4269
+ };
4270
+ type AIGatewayUniversalRequest = {
4271
+ provider: AIGatewayProviders | string; // eslint-disable-line
4272
+ endpoint: string;
4273
+ headers: Partial<AIGatewayHeaders>;
4274
+ query: unknown;
4275
+ };
4276
+ interface AiGatewayInternalError extends Error {}
4277
+ interface AiGatewayLogNotFound extends Error {}
4278
+ declare abstract class AiGateway {
4279
+ patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>;
4280
+ getLog(logId: string): Promise<AiGatewayLog>;
3628
4281
  run(
3629
- model: BaseAiImageToTextModels,
3630
- inputs: BaseAiImageToText["inputs"],
3631
- options?: AiOptions,
3632
- ): Promise<BaseAiImageToText["postProcessedOutputs"]>;
4282
+ data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[],
4283
+ ): Promise<Response>;
3633
4284
  }
3634
4285
  interface BasicImageTransformations {
3635
4286
  /**
@@ -4635,7 +5286,7 @@ declare abstract class D1PreparedStatement {
4635
5286
  bind(...values: unknown[]): D1PreparedStatement;
4636
5287
  first<T = unknown>(colName: string): Promise<T | null>;
4637
5288
  first<T = Record<string, unknown>>(): Promise<T | null>;
4638
- run(): Promise<D1Response>;
5289
+ run<T = Record<string, unknown>>(): Promise<D1Result<T>>;
4639
5290
  all<T = Record<string, unknown>>(): Promise<D1Result<T>>;
4640
5291
  raw<T = unknown[]>(options: {
4641
5292
  columnNames: true;
@@ -4691,6 +5342,12 @@ interface ForwardableEmailMessage extends EmailMessage {
4691
5342
  * @returns A promise that resolves when the email message is forwarded.
4692
5343
  */
4693
5344
  forward(rcptTo: string, headers?: Headers): Promise<void>;
5345
+ /**
5346
+ * Reply to the sender of this email message with a new EmailMessage object.
5347
+ * @param message The reply message.
5348
+ * @returns A promise that resolves when the email message is replied.
5349
+ */
5350
+ reply(message: EmailMessage): Promise<void>;
4694
5351
  }
4695
5352
  /**
4696
5353
  * A binding that allows a Worker to send email messages.
@@ -4760,6 +5417,128 @@ interface Hyperdrive {
4760
5417
  */
4761
5418
  readonly database: string;
4762
5419
  }
5420
+ // Copyright (c) 2024 Cloudflare, Inc.
5421
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5422
+ // https://opensource.org/licenses/Apache-2.0
5423
+ type ImageInfoResponse =
5424
+ | {
5425
+ format: "image/svg+xml";
5426
+ }
5427
+ | {
5428
+ format: string;
5429
+ fileSize: number;
5430
+ width: number;
5431
+ height: number;
5432
+ };
5433
+ type ImageTransform = {
5434
+ fit?: "scale-down" | "contain" | "pad" | "squeeze" | "cover" | "crop";
5435
+ gravity?:
5436
+ | "left"
5437
+ | "right"
5438
+ | "top"
5439
+ | "bottom"
5440
+ | "center"
5441
+ | "auto"
5442
+ | "entropy"
5443
+ | "face"
5444
+ | {
5445
+ x?: number;
5446
+ y?: number;
5447
+ mode: "remainder" | "box-center";
5448
+ };
5449
+ trim?: {
5450
+ top?: number;
5451
+ bottom?: number;
5452
+ left?: number;
5453
+ right?: number;
5454
+ width?: number;
5455
+ height?: number;
5456
+ border?:
5457
+ | boolean
5458
+ | {
5459
+ color?: string;
5460
+ tolerance?: number;
5461
+ keep?: number;
5462
+ };
5463
+ };
5464
+ width?: number;
5465
+ height?: number;
5466
+ background?: string;
5467
+ rotate?: number;
5468
+ sharpen?: number;
5469
+ blur?: number;
5470
+ contrast?: number;
5471
+ brightness?: number;
5472
+ gamma?: number;
5473
+ border?: {
5474
+ color?: string;
5475
+ width?: number;
5476
+ top?: number;
5477
+ bottom?: number;
5478
+ left?: number;
5479
+ right?: number;
5480
+ };
5481
+ zoom?: number;
5482
+ };
5483
+ type ImageOutputOptions = {
5484
+ format:
5485
+ | "image/jpeg"
5486
+ | "image/png"
5487
+ | "image/gif"
5488
+ | "image/webp"
5489
+ | "image/avif"
5490
+ | "rgb"
5491
+ | "rgba";
5492
+ quality?: number;
5493
+ background?: string;
5494
+ };
5495
+ interface ImagesBinding {
5496
+ /**
5497
+ * Get image metadata (type, width and height)
5498
+ * @throws {@link ImagesError} with code 9412 if input is not an image
5499
+ * @param stream The image bytes
5500
+ */
5501
+ info(stream: ReadableStream<Uint8Array>): Promise<ImageInfoResponse>;
5502
+ /**
5503
+ * Begin applying a series of transformations to an image
5504
+ * @param stream The image bytes
5505
+ * @returns A transform handle
5506
+ */
5507
+ input(stream: ReadableStream<Uint8Array>): ImageTransformer;
5508
+ }
5509
+ interface ImageTransformer {
5510
+ /**
5511
+ * Apply transform next, returning a transform handle.
5512
+ * You can then apply more transformations or retrieve the output.
5513
+ * @param transform
5514
+ */
5515
+ transform(transform: ImageTransform): ImageTransformer;
5516
+ /**
5517
+ * Retrieve the image that results from applying the transforms to the
5518
+ * provided input
5519
+ * @param options Options that apply to the output e.g. output format
5520
+ */
5521
+ output(options: ImageOutputOptions): Promise<ImageTransformationResult>;
5522
+ }
5523
+ interface ImageTransformationResult {
5524
+ /**
5525
+ * The image as a response, ready to store in cache or return to users
5526
+ */
5527
+ response(): Response;
5528
+ /**
5529
+ * The content type of the returned image
5530
+ */
5531
+ contentType(): string;
5532
+ /**
5533
+ * The bytes of the response
5534
+ */
5535
+ image(): ReadableStream<Uint8Array>;
5536
+ }
5537
+ interface ImagesError extends Error {
5538
+ readonly code: number;
5539
+ readonly message: string;
5540
+ readonly stack?: string;
5541
+ }
4763
5542
  type Params<P extends string = any> = Record<P, string | string[]>;
4764
5543
  type EventContext<Env, P extends string, Data> = {
4765
5544
  request: Request<unknown, IncomingRequestCfProperties<unknown>>;
@@ -4806,6 +5585,30 @@ type PagesPluginFunction<
4806
5585
  declare module "assets:*" {
4807
5586
  export const onRequest: PagesFunction;
4808
5587
  }
5588
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
5589
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5590
+ // https://opensource.org/licenses/Apache-2.0
5591
+ declare abstract class PipelineTransform {
5592
+ /**
5593
+ * transformJson recieves an array of javascript objects which can be
5594
+ * mutated and returned to the pipeline
5595
+ * @param data The data to be mutated
5596
+ * @returns A promise containing the mutated data
5597
+ */
5598
+ public transformJson(data: object[]): Promise<object[]>;
5599
+ }
5600
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
5601
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5602
+ // https://opensource.org/licenses/Apache-2.0
5603
+ interface Pipeline {
5604
+ /**
5605
+ * send takes an array of javascript objects which are
5606
+ * then received by the pipeline for processing
5607
+ *
5608
+ * @param data The data to be sent
5609
+ */
5610
+ send(data: object[]): Promise<void>;
5611
+ }
4809
5612
  // PubSubMessage represents an incoming PubSub message.
4810
5613
  // The message includes metadata about the broker, the client, and the payload
4811
5614
  // itself.
@@ -4866,6 +5669,7 @@ declare namespace Rpc {
4866
5669
  export const __RPC_TARGET_BRAND: "__RPC_TARGET_BRAND";
4867
5670
  export const __WORKER_ENTRYPOINT_BRAND: "__WORKER_ENTRYPOINT_BRAND";
4868
5671
  export const __DURABLE_OBJECT_BRAND: "__DURABLE_OBJECT_BRAND";
5672
+ export const __WORKFLOW_ENTRYPOINT_BRAND: "__WORKFLOW_ENTRYPOINT_BRAND";
4869
5673
  export interface RpcTargetBranded {
4870
5674
  [__RPC_TARGET_BRAND]: never;
4871
5675
  }
@@ -4875,13 +5679,20 @@ declare namespace Rpc {
4875
5679
  export interface DurableObjectBranded {
4876
5680
  [__DURABLE_OBJECT_BRAND]: never;
4877
5681
  }
5682
+ export interface WorkflowEntrypointBranded {
5683
+ [__WORKFLOW_ENTRYPOINT_BRAND]: never;
5684
+ }
4878
5685
  export type EntrypointBranded =
4879
5686
  | WorkerEntrypointBranded
4880
- | DurableObjectBranded;
5687
+ | DurableObjectBranded
5688
+ | WorkflowEntrypointBranded;
4881
5689
  // Types that can be used through `Stub`s
4882
5690
  export type Stubable = RpcTargetBranded | ((...args: any[]) => any);
4883
5691
  // Types that can be passed over RPC
4884
- type Serializable =
5692
+ // The reason for using a generic type here is to build a serializable subset of structured
5693
+ // cloneable composite types. This allows types defined with the "interface" keyword to pass the
5694
+ // serializable check as well. Otherwise, only types defined with the "type" keyword would pass.
5695
+ type Serializable<T> =
4885
5696
  // Structured cloneables
4886
5697
  | void
4887
5698
  | undefined
@@ -4897,11 +5708,14 @@ declare namespace Rpc {
4897
5708
  | Error
4898
5709
  | RegExp
4899
5710
  // Structured cloneable composites
4900
- | Map<Serializable, Serializable>
4901
- | Set<Serializable>
4902
- | ReadonlyArray<Serializable>
5711
+ | Map<
5712
+ T extends Map<infer U, unknown> ? Serializable<U> : never,
5713
+ T extends Map<unknown, infer U> ? Serializable<U> : never
5714
+ >
5715
+ | Set<T extends Set<infer U> ? Serializable<U> : never>
5716
+ | ReadonlyArray<T extends ReadonlyArray<infer U> ? Serializable<U> : never>
4903
5717
  | {
4904
- [key: string | number]: Serializable;
5718
+ [K in keyof T]: K extends number | string ? Serializable<T[K]> : never;
4905
5719
  }
4906
5720
  // Special types
4907
5721
  | ReadableStream<Uint8Array>
@@ -4931,7 +5745,7 @@ declare namespace Rpc {
4931
5745
  : T extends ReadonlyArray<infer V>
4932
5746
  ? ReadonlyArray<Stubify<V>>
4933
5747
  : T extends {
4934
- [key: string | number]: unknown;
5748
+ [key: string | number]: any;
4935
5749
  }
4936
5750
  ? {
4937
5751
  [K in keyof T]: Stubify<T[K]>;
@@ -4974,7 +5788,7 @@ declare namespace Rpc {
4974
5788
  // Intersecting with `(Maybe)Provider` allows pipelining.
4975
5789
  type Result<R> = R extends Stubable
4976
5790
  ? Promise<Stub<R>> & Provider<R>
4977
- : R extends Serializable
5791
+ : R extends Serializable<R>
4978
5792
  ? Promise<Stubify<R> & MaybeDisposable<R>> & MaybeProvider<R>
4979
5793
  : never;
4980
5794
  // Type for method or property on an RPC interface.
@@ -5034,7 +5848,7 @@ declare module "cloudflare:workers" {
5034
5848
  protected env: Env;
5035
5849
  constructor(ctx: DurableObjectState, env: Env);
5036
5850
  fetch?(request: Request): Response | Promise<Response>;
5037
- alarm?(): void | Promise<void>;
5851
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
5038
5852
  webSocketMessage?(
5039
5853
  ws: WebSocket,
5040
5854
  message: string | ArrayBuffer,
@@ -5047,6 +5861,60 @@ declare module "cloudflare:workers" {
5047
5861
  ): void | Promise<void>;
5048
5862
  webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
5049
5863
  }
5864
+ export type WorkflowDurationLabel =
5865
+ | "second"
5866
+ | "minute"
5867
+ | "hour"
5868
+ | "day"
5869
+ | "week"
5870
+ | "month"
5871
+ | "year";
5872
+ export type WorkflowSleepDuration =
5873
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
5874
+ | number;
5875
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
5876
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
5877
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
5878
+ export type WorkflowStepConfig = {
5879
+ retries?: {
5880
+ limit: number;
5881
+ delay: WorkflowDelayDuration | number;
5882
+ backoff?: WorkflowBackoff;
5883
+ };
5884
+ timeout?: WorkflowTimeoutDuration | number;
5885
+ };
5886
+ export type WorkflowEvent<T> = {
5887
+ payload: Readonly<T>;
5888
+ timestamp: Date;
5889
+ instanceId: string;
5890
+ };
5891
+ export abstract class WorkflowStep {
5892
+ do<T extends Rpc.Serializable<T>>(
5893
+ name: string,
5894
+ callback: () => Promise<T>,
5895
+ ): Promise<T>;
5896
+ do<T extends Rpc.Serializable<T>>(
5897
+ name: string,
5898
+ config: WorkflowStepConfig,
5899
+ callback: () => Promise<T>,
5900
+ ): Promise<T>;
5901
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
5902
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
5903
+ }
5904
+ export abstract class WorkflowEntrypoint<
5905
+ Env = unknown,
5906
+ T extends Rpc.Serializable<T> | unknown = unknown,
5907
+ > implements Rpc.WorkflowEntrypointBranded
5908
+ {
5909
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
5910
+ protected ctx: ExecutionContext;
5911
+ protected env: Env;
5912
+ constructor(ctx: ExecutionContext, env: Env);
5913
+ run(
5914
+ event: Readonly<WorkflowEvent<T>>,
5915
+ step: WorkflowStep,
5916
+ ): Promise<unknown>;
5917
+ }
5050
5918
  }
5051
5919
  declare module "cloudflare:sockets" {
5052
5920
  function _connect(
@@ -5055,6 +5923,198 @@ declare module "cloudflare:sockets" {
5055
5923
  ): Socket;
5056
5924
  export { _connect as connect };
5057
5925
  }
5926
+ declare namespace TailStream {
5927
+ interface Header {
5928
+ readonly name: string;
5929
+ readonly value: string;
5930
+ }
5931
+ interface FetchEventInfo {
5932
+ readonly type: "fetch";
5933
+ readonly method: string;
5934
+ readonly url: string;
5935
+ readonly cfJson: string;
5936
+ readonly headers: Header[];
5937
+ }
5938
+ interface JsRpcEventInfo {
5939
+ readonly type: "jsrpc";
5940
+ readonly methodName: string;
5941
+ }
5942
+ interface ScheduledEventInfo {
5943
+ readonly type: "scheduled";
5944
+ readonly scheduledTime: Date;
5945
+ readonly cron: string;
5946
+ }
5947
+ interface AlarmEventInfo {
5948
+ readonly type: "alarm";
5949
+ readonly scheduledTime: Date;
5950
+ }
5951
+ interface QueueEventInfo {
5952
+ readonly type: "queue";
5953
+ readonly queueName: string;
5954
+ readonly batchSize: number;
5955
+ }
5956
+ interface EmailEventInfo {
5957
+ readonly type: "email";
5958
+ readonly mailFrom: string;
5959
+ readonly rcptTo: string;
5960
+ readonly rawSize: number;
5961
+ }
5962
+ interface TraceEventInfo {
5963
+ readonly type: "trace";
5964
+ readonly traces: (string | null)[];
5965
+ }
5966
+ interface HibernatableWebSocketEventInfoMessage {
5967
+ readonly type: "message";
5968
+ }
5969
+ interface HibernatableWebSocketEventInfoError {
5970
+ readonly type: "error";
5971
+ }
5972
+ interface HibernatableWebSocketEventInfoClose {
5973
+ readonly type: "close";
5974
+ readonly code: number;
5975
+ readonly wasClean: boolean;
5976
+ }
5977
+ interface HibernatableWebSocketEventInfo {
5978
+ readonly type: "hibernatableWebSocket";
5979
+ readonly info:
5980
+ | HibernatableWebSocketEventInfoClose
5981
+ | HibernatableWebSocketEventInfoError
5982
+ | HibernatableWebSocketEventInfoMessage;
5983
+ }
5984
+ interface Resume {
5985
+ readonly type: "resume";
5986
+ readonly attachment?: any;
5987
+ }
5988
+ interface CustomEventInfo {
5989
+ readonly type: "custom";
5990
+ }
5991
+ interface FetchResponseInfo {
5992
+ readonly type: "fetch";
5993
+ readonly statusCode: number;
5994
+ }
5995
+ type EventOutcome =
5996
+ | "ok"
5997
+ | "canceled"
5998
+ | "exception"
5999
+ | "unknown"
6000
+ | "killSwitch"
6001
+ | "daemonDown"
6002
+ | "exceededCpu"
6003
+ | "exceededMemory"
6004
+ | "loadShed"
6005
+ | "responseStreamDisconnected"
6006
+ | "scriptNotFound";
6007
+ interface ScriptVersion {
6008
+ readonly id: string;
6009
+ readonly tag?: string;
6010
+ readonly message?: string;
6011
+ }
6012
+ interface Trigger {
6013
+ readonly traceId: string;
6014
+ readonly invocationId: string;
6015
+ readonly spanId: string;
6016
+ }
6017
+ interface Onset {
6018
+ readonly type: "onset";
6019
+ readonly dispatchNamespace?: string;
6020
+ readonly entrypoint?: string;
6021
+ readonly scriptName?: string;
6022
+ readonly scriptTags?: string[];
6023
+ readonly scriptVersion?: ScriptVersion;
6024
+ readonly trigger?: Trigger;
6025
+ readonly info:
6026
+ | FetchEventInfo
6027
+ | JsRpcEventInfo
6028
+ | ScheduledEventInfo
6029
+ | AlarmEventInfo
6030
+ | QueueEventInfo
6031
+ | EmailEventInfo
6032
+ | TraceEventInfo
6033
+ | HibernatableWebSocketEventInfo
6034
+ | Resume
6035
+ | CustomEventInfo;
6036
+ }
6037
+ interface Outcome {
6038
+ readonly type: "outcome";
6039
+ readonly outcome: EventOutcome;
6040
+ readonly cpuTime: number;
6041
+ readonly wallTime: number;
6042
+ }
6043
+ interface Hibernate {
6044
+ readonly type: "hibernate";
6045
+ }
6046
+ interface SpanOpen {
6047
+ readonly type: "spanOpen";
6048
+ readonly op?: string;
6049
+ readonly info?: FetchEventInfo | JsRpcEventInfo | Attribute[];
6050
+ }
6051
+ interface SpanClose {
6052
+ readonly type: "spanClose";
6053
+ readonly outcome: EventOutcome;
6054
+ }
6055
+ interface DiagnosticChannelEvent {
6056
+ readonly type: "diagnosticChannel";
6057
+ readonly channel: string;
6058
+ readonly message: any;
6059
+ }
6060
+ interface Exception {
6061
+ readonly type: "exception";
6062
+ readonly name: string;
6063
+ readonly message: string;
6064
+ readonly stack?: string;
6065
+ }
6066
+ interface Log {
6067
+ readonly type: "log";
6068
+ readonly level: "debug" | "error" | "info" | "log" | "warn";
6069
+ readonly message: string;
6070
+ }
6071
+ interface Return {
6072
+ readonly type: "return";
6073
+ readonly info?: FetchResponseInfo | Attribute[];
6074
+ }
6075
+ interface Link {
6076
+ readonly type: "link";
6077
+ readonly label?: string;
6078
+ readonly traceId: string;
6079
+ readonly invocationId: string;
6080
+ readonly spanId: string;
6081
+ }
6082
+ interface Attribute {
6083
+ readonly type: "attribute";
6084
+ readonly name: string;
6085
+ readonly value: string | string[] | boolean | boolean[] | number | number[];
6086
+ }
6087
+ type Mark =
6088
+ | DiagnosticChannelEvent
6089
+ | Exception
6090
+ | Log
6091
+ | Return
6092
+ | Link
6093
+ | Attribute[];
6094
+ interface TailEvent {
6095
+ readonly traceId: string;
6096
+ readonly invocationId: string;
6097
+ readonly spanId: string;
6098
+ readonly timestamp: Date;
6099
+ readonly sequence: number;
6100
+ readonly event: Onset | Outcome | Hibernate | SpanOpen | SpanClose | Mark;
6101
+ }
6102
+ type TailEventHandler = (event: TailEvent) => void | Promise<void>;
6103
+ type TailEventHandlerName =
6104
+ | "onset"
6105
+ | "outcome"
6106
+ | "hibernate"
6107
+ | "spanOpen"
6108
+ | "spanClose"
6109
+ | "diagnosticChannel"
6110
+ | "exception"
6111
+ | "log"
6112
+ | "return"
6113
+ | "link"
6114
+ | "attribute";
6115
+ type TailEventHandlerObject = Record<TailEventHandlerName, TailEventHandler>;
6116
+ type TailEventHandlerType = TailEventHandler | TailEventHandlerObject;
6117
+ }
5058
6118
  // Copyright (c) 2022-2023 Cloudflare, Inc.
5059
6119
  // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5060
6120
  // https://opensource.org/licenses/Apache-2.0
@@ -5098,11 +6158,21 @@ type VectorizeVectorMetadataFilter = {
5098
6158
  * Distance metrics determine how other "similar" vectors are determined.
5099
6159
  */
5100
6160
  type VectorizeDistanceMetric = "euclidean" | "cosine" | "dot-product";
6161
+ /**
6162
+ * Metadata return levels for a Vectorize query.
6163
+ *
6164
+ * Default to "none".
6165
+ *
6166
+ * @property all Full metadata for the vector return set, including all fields (including those un-indexed) without truncation. This is a more expensive retrieval, as it requires additional fetching & reading of un-indexed data.
6167
+ * @property indexed Return all metadata fields configured for indexing in the vector return set. This level of retrieval is "free" in that no additional overhead is incurred returning this data. However, note that indexed metadata is subject to truncation (especially for larger strings).
6168
+ * @property none No indexed metadata will be returned.
6169
+ */
6170
+ type VectorizeMetadataRetrievalLevel = "all" | "indexed" | "none";
5101
6171
  interface VectorizeQueryOptions {
5102
6172
  topK?: number;
5103
6173
  namespace?: string;
5104
6174
  returnValues?: boolean;
5105
- returnMetadata?: boolean;
6175
+ returnMetadata?: boolean | VectorizeMetadataRetrievalLevel;
5106
6176
  filter?: VectorizeVectorMetadataFilter;
5107
6177
  }
5108
6178
  /**
@@ -5118,6 +6188,9 @@ type VectorizeIndexConfig =
5118
6188
  };
5119
6189
  /**
5120
6190
  * Metadata about an existing index.
6191
+ *
6192
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6193
+ * See {@link VectorizeIndexInfo} for its post-beta equivalent.
5121
6194
  */
5122
6195
  interface VectorizeIndexDetails {
5123
6196
  /** The unique ID of the index */
@@ -5131,6 +6204,19 @@ interface VectorizeIndexDetails {
5131
6204
  /** The number of records containing vectors within the index. */
5132
6205
  vectorsCount: number;
5133
6206
  }
6207
+ /**
6208
+ * Metadata about an existing index.
6209
+ */
6210
+ interface VectorizeIndexInfo {
6211
+ /** The number of records containing vectors within the index. */
6212
+ vectorCount: number;
6213
+ /** Number of dimensions the index has been configured for. */
6214
+ dimensions: number;
6215
+ /** ISO 8601 datetime of the last processed mutation on in the index. All changes before this mutation will be reflected in the index state. */
6216
+ processedUpToDatetime: number;
6217
+ /** UUIDv4 of the last mutation processed by the index. All changes before this mutation will be reflected in the index state. */
6218
+ processedUpToMutation: number;
6219
+ }
5134
6220
  /**
5135
6221
  * Represents a single vector value set along with its associated metadata.
5136
6222
  */
@@ -5141,7 +6227,7 @@ interface VectorizeVector {
5141
6227
  values: VectorFloatArray | number[];
5142
6228
  /** The namespace this vector belongs to. */
5143
6229
  namespace?: string;
5144
- /** Metadata associated with the vector. Includes the values of the other fields and potentially additional details. */
6230
+ /** Metadata associated with the vector. Includes the values of other fields and potentially additional details. */
5145
6231
  metadata?: Record<string, VectorizeVectorMetadata>;
5146
6232
  }
5147
6233
  /**
@@ -5153,7 +6239,7 @@ type VectorizeMatch = Pick<Partial<VectorizeVector>, "values"> &
5153
6239
  score: number;
5154
6240
  };
5155
6241
  /**
5156
- * A set of vector {@link VectorizeMatch} for a particular query.
6242
+ * A set of matching {@link VectorizeMatch} for a particular query.
5157
6243
  */
5158
6244
  interface VectorizeMatches {
5159
6245
  matches: VectorizeMatch[];
@@ -5162,6 +6248,9 @@ interface VectorizeMatches {
5162
6248
  /**
5163
6249
  * Results of an operation that performed a mutation on a set of vectors.
5164
6250
  * Here, `ids` is a list of vectors that were successfully processed.
6251
+ *
6252
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6253
+ * See {@link VectorizeAsyncMutation} for its post-beta equivalent.
5165
6254
  */
5166
6255
  interface VectorizeVectorMutation {
5167
6256
  /* List of ids of vectors that were successfully processed. */
@@ -5170,14 +6259,19 @@ interface VectorizeVectorMutation {
5170
6259
  count: number;
5171
6260
  }
5172
6261
  /**
5173
- * Results of an operation that performed a mutation on a set of vectors
5174
- * with the v2 version of Vectorize.
5175
- * Here, `mutationId` is the identifier for the last mutation processed by Vectorize.
6262
+ * Result type indicating a mutation on the Vectorize Index.
6263
+ * Actual mutations are processed async where the `mutationId` is the unique identifier for the operation.
5176
6264
  */
5177
- interface VectorizeVectorMutationV2 {
5178
- /* The identifier for the last mutation processed by Vectorize. */
6265
+ interface VectorizeAsyncMutation {
6266
+ /** The unique identifier for the async mutation operation containing the changeset. */
5179
6267
  mutationId: string;
5180
6268
  }
6269
+ /**
6270
+ * A Vectorize Vector Search Index for querying vectors/embeddings.
6271
+ *
6272
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6273
+ * See {@link Vectorize} for its new implementation.
6274
+ */
5181
6275
  declare abstract class VectorizeIndex {
5182
6276
  /**
5183
6277
  * Get information about the currently bound index.
@@ -5192,7 +6286,7 @@ declare abstract class VectorizeIndex {
5192
6286
  */
5193
6287
  public query(
5194
6288
  vector: VectorFloatArray | number[],
5195
- options: VectorizeQueryOptions,
6289
+ options?: VectorizeQueryOptions,
5196
6290
  ): Promise<VectorizeMatches>;
5197
6291
  /**
5198
6292
  * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
@@ -5219,6 +6313,62 @@ declare abstract class VectorizeIndex {
5219
6313
  */
5220
6314
  public getByIds(ids: string[]): Promise<VectorizeVector[]>;
5221
6315
  }
6316
+ /**
6317
+ * A Vectorize Vector Search Index for querying vectors/embeddings.
6318
+ *
6319
+ * Mutations in this version are async, returning a mutation id.
6320
+ */
6321
+ declare abstract class Vectorize {
6322
+ /**
6323
+ * Get information about the currently bound index.
6324
+ * @returns A promise that resolves with information about the current index.
6325
+ */
6326
+ public describe(): Promise<VectorizeIndexInfo>;
6327
+ /**
6328
+ * Use the provided vector to perform a similarity search across the index.
6329
+ * @param vector Input vector that will be used to drive the similarity search.
6330
+ * @param options Configuration options to massage the returned data.
6331
+ * @returns A promise that resolves with matched and scored vectors.
6332
+ */
6333
+ public query(
6334
+ vector: VectorFloatArray | number[],
6335
+ options?: VectorizeQueryOptions,
6336
+ ): Promise<VectorizeMatches>;
6337
+ /**
6338
+ * Use the provided vector-id to perform a similarity search across the index.
6339
+ * @param vectorId Id for a vector in the index against which the index should be queried.
6340
+ * @param options Configuration options to massage the returned data.
6341
+ * @returns A promise that resolves with matched and scored vectors.
6342
+ */
6343
+ public queryById(
6344
+ vectorId: string,
6345
+ options?: VectorizeQueryOptions,
6346
+ ): Promise<VectorizeMatches>;
6347
+ /**
6348
+ * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
6349
+ * @param vectors List of vectors that will be inserted.
6350
+ * @returns A promise that resolves with a unique identifier of a mutation containing the insert changeset.
6351
+ */
6352
+ public insert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>;
6353
+ /**
6354
+ * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values.
6355
+ * @param vectors List of vectors that will be upserted.
6356
+ * @returns A promise that resolves with a unique identifier of a mutation containing the upsert changeset.
6357
+ */
6358
+ public upsert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>;
6359
+ /**
6360
+ * Delete a list of vectors with a matching id.
6361
+ * @param ids List of vector ids that should be deleted.
6362
+ * @returns A promise that resolves with a unique identifier of a mutation containing the delete changeset.
6363
+ */
6364
+ public deleteByIds(ids: string[]): Promise<VectorizeAsyncMutation>;
6365
+ /**
6366
+ * Get a list of vectors with a matching id.
6367
+ * @param ids List of vector ids that should be returned.
6368
+ * @returns A promise that resolves with the raw unscored vectors matching the id set.
6369
+ */
6370
+ public getByIds(ids: string[]): Promise<VectorizeVector[]>;
6371
+ }
5222
6372
  /**
5223
6373
  * The interface for "version_metadata" binding
5224
6374
  * providing metadata about the Worker Version using this binding.
@@ -5269,3 +6419,79 @@ interface DispatchNamespace {
5269
6419
  options?: DynamicDispatchOptions,
5270
6420
  ): Fetcher;
5271
6421
  }
6422
+ declare module "cloudflare:workflows" {
6423
+ /**
6424
+ * NonRetryableError allows for a user to throw a fatal error
6425
+ * that makes a Workflow instance fail immediately without triggering a retry
6426
+ */
6427
+ export class NonRetryableError extends Error {
6428
+ public constructor(message: string, name?: string);
6429
+ }
6430
+ }
6431
+ declare abstract class Workflow<PARAMS = unknown> {
6432
+ /**
6433
+ * Get a handle to an existing instance of the Workflow.
6434
+ * @param id Id for the instance of this Workflow
6435
+ * @returns A promise that resolves with a handle for the Instance
6436
+ */
6437
+ public get(id: string): Promise<WorkflowInstance>;
6438
+ /**
6439
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
6440
+ * @param options Options when creating an instance including id and params
6441
+ * @returns A promise that resolves with a handle for the Instance
6442
+ */
6443
+ public create(
6444
+ options?: WorkflowInstanceCreateOptions<PARAMS>,
6445
+ ): Promise<WorkflowInstance>;
6446
+ }
6447
+ interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6448
+ /**
6449
+ * An id for your Workflow instance. Must be unique within the Workflow.
6450
+ */
6451
+ id?: string;
6452
+ /**
6453
+ * The event payload the Workflow instance is triggered with
6454
+ */
6455
+ params?: PARAMS;
6456
+ }
6457
+ type InstanceStatus = {
6458
+ status:
6459
+ | "queued" // means that instance is waiting to be started (see concurrency limits)
6460
+ | "running"
6461
+ | "paused"
6462
+ | "errored"
6463
+ | "terminated" // user terminated the instance while it was running
6464
+ | "complete"
6465
+ | "waiting" // instance is hibernating and waiting for sleep or event to finish
6466
+ | "waitingForPause" // instance is finishing the current work to pause
6467
+ | "unknown";
6468
+ error?: string;
6469
+ output?: object;
6470
+ };
6471
+ interface WorkflowError {
6472
+ code?: number;
6473
+ message: string;
6474
+ }
6475
+ declare abstract class WorkflowInstance {
6476
+ public id: string;
6477
+ /**
6478
+ * Pause the instance.
6479
+ */
6480
+ public pause(): Promise<void>;
6481
+ /**
6482
+ * Resume the instance. If it is already running, an error will be thrown.
6483
+ */
6484
+ public resume(): Promise<void>;
6485
+ /**
6486
+ * Terminate the instance. If it is errored, terminated or complete, an error will be thrown.
6487
+ */
6488
+ public terminate(): Promise<void>;
6489
+ /**
6490
+ * Restart the instance.
6491
+ */
6492
+ public restart(): Promise<void>;
6493
+ /**
6494
+ * Returns the current status of the instance.
6495
+ */
6496
+ public status(): Promise<InstanceStatus>;
6497
+ }