@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;
@@ -364,7 +366,7 @@ declare function structuredClone<T>(
364
366
  declare function reportError(error: any): void;
365
367
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/fetch) */
366
368
  declare function fetch(
367
- input: RequestInfo,
369
+ input: RequestInfo | URL,
368
370
  init?: RequestInit<RequestInitCfProperties>,
369
371
  ): Promise<Response>;
370
372
  declare const self: ServiceWorkerGlobalScope;
@@ -391,12 +393,14 @@ declare const scheduler: Scheduler;
391
393
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
392
394
  */
393
395
  declare const performance: Performance;
396
+ declare const Cloudflare: Cloudflare;
394
397
  declare const origin: string;
395
398
  declare const navigator: Navigator;
396
399
  interface TestController {}
397
400
  interface ExecutionContext {
398
401
  waitUntil(promise: Promise<any>): void;
399
402
  passThroughOnException(): void;
403
+ props: any;
400
404
  }
401
405
  type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
402
406
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
@@ -413,6 +417,11 @@ type ExportedHandlerTraceHandler<Env = unknown> = (
413
417
  env: Env,
414
418
  ctx: ExecutionContext,
415
419
  ) => void | Promise<void>;
420
+ type ExportedHandlerTailStreamHandler<Env = unknown> = (
421
+ event: TailStream.TailEvent,
422
+ env: Env,
423
+ ctx: ExecutionContext,
424
+ ) => TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>;
416
425
  type ExportedHandlerScheduledHandler<Env = unknown> = (
417
426
  controller: ScheduledController,
418
427
  env: Env,
@@ -436,6 +445,7 @@ interface ExportedHandler<
436
445
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
437
446
  tail?: ExportedHandlerTailHandler<Env>;
438
447
  trace?: ExportedHandlerTraceHandler<Env>;
448
+ tailStream?: ExportedHandlerTailStreamHandler<Env>;
439
449
  scheduled?: ExportedHandlerScheduledHandler<Env>;
440
450
  test?: ExportedHandlerTestHandler<Env>;
441
451
  email?: EmailExportedHandler<Env>;
@@ -459,8 +469,9 @@ declare abstract class Navigator {
459
469
  | string
460
470
  | (ArrayBuffer | ArrayBufferView)
461
471
  | Blob
472
+ | FormData
462
473
  | URLSearchParams
463
- | FormData,
474
+ | URLSearchParams,
464
475
  ): boolean;
465
476
  readonly userAgent: string;
466
477
  readonly gpu: GPU;
@@ -481,9 +492,12 @@ interface AlarmInvocationInfo {
481
492
  readonly isRetry: boolean;
482
493
  readonly retryCount: number;
483
494
  }
495
+ interface Cloudflare {
496
+ readonly compatibilityFlags: Record<string, boolean>;
497
+ }
484
498
  interface DurableObject {
485
499
  fetch(request: Request): Response | Promise<Response>;
486
- alarm?(): void | Promise<void>;
500
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
487
501
  webSocketMessage?(
488
502
  ws: WebSocket,
489
503
  message: string | ArrayBuffer,
@@ -556,6 +570,7 @@ interface DurableObjectState {
556
570
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): void;
557
571
  getHibernatableWebSocketEventTimeout(): number | null;
558
572
  getTags(ws: WebSocket): string[];
573
+ abort(reason?: string): void;
559
574
  }
560
575
  interface DurableObjectTransaction {
561
576
  get<T = unknown>(
@@ -622,7 +637,11 @@ interface DurableObjectStorage {
622
637
  ): Promise<void>;
623
638
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
624
639
  sync(): Promise<void>;
640
+ sql: SqlStorage;
625
641
  transactionSync<T>(closure: () => T): T;
642
+ getCurrentBookmark(): Promise<string>;
643
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
644
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
626
645
  }
627
646
  interface DurableObjectListOptions {
628
647
  start?: string;
@@ -993,14 +1012,17 @@ declare abstract class CacheStorage {
993
1012
  */
994
1013
  declare abstract class Cache {
995
1014
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#delete) */
996
- delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
1015
+ delete(
1016
+ request: RequestInfo | URL,
1017
+ options?: CacheQueryOptions,
1018
+ ): Promise<boolean>;
997
1019
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#match) */
998
1020
  match(
999
- request: RequestInfo,
1021
+ request: RequestInfo | URL,
1000
1022
  options?: CacheQueryOptions,
1001
1023
  ): Promise<Response | undefined>;
1002
1024
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#put) */
1003
- put(request: RequestInfo, response: Response): Promise<void>;
1025
+ put(request: RequestInfo | URL, response: Response): Promise<void>;
1004
1026
  }
1005
1027
  interface CacheQueryOptions {
1006
1028
  ignoreMethod?: boolean;
@@ -1423,20 +1445,44 @@ interface Element {
1423
1445
  hasAttribute(name: string): boolean;
1424
1446
  setAttribute(name: string, value: string): Element;
1425
1447
  removeAttribute(name: string): Element;
1426
- before(content: string, options?: ContentOptions): Element;
1427
- after(content: string, options?: ContentOptions): Element;
1428
- prepend(content: string, options?: ContentOptions): Element;
1429
- append(content: string, options?: ContentOptions): Element;
1430
- replace(content: string, options?: ContentOptions): Element;
1448
+ before(
1449
+ content: string | ReadableStream | Response,
1450
+ options?: ContentOptions,
1451
+ ): Element;
1452
+ after(
1453
+ content: string | ReadableStream | Response,
1454
+ options?: ContentOptions,
1455
+ ): Element;
1456
+ prepend(
1457
+ content: string | ReadableStream | Response,
1458
+ options?: ContentOptions,
1459
+ ): Element;
1460
+ append(
1461
+ content: string | ReadableStream | Response,
1462
+ options?: ContentOptions,
1463
+ ): Element;
1464
+ replace(
1465
+ content: string | ReadableStream | Response,
1466
+ options?: ContentOptions,
1467
+ ): Element;
1431
1468
  remove(): Element;
1432
1469
  removeAndKeepContent(): Element;
1433
- setInnerContent(content: string, options?: ContentOptions): Element;
1470
+ setInnerContent(
1471
+ content: string | ReadableStream | Response,
1472
+ options?: ContentOptions,
1473
+ ): Element;
1434
1474
  onEndTag(handler: (tag: EndTag) => void | Promise<void>): void;
1435
1475
  }
1436
1476
  interface EndTag {
1437
1477
  name: string;
1438
- before(content: string, options?: ContentOptions): EndTag;
1439
- after(content: string, options?: ContentOptions): EndTag;
1478
+ before(
1479
+ content: string | ReadableStream | Response,
1480
+ options?: ContentOptions,
1481
+ ): EndTag;
1482
+ after(
1483
+ content: string | ReadableStream | Response,
1484
+ options?: ContentOptions,
1485
+ ): EndTag;
1440
1486
  remove(): EndTag;
1441
1487
  }
1442
1488
  interface Comment {
@@ -1451,9 +1497,18 @@ interface Text {
1451
1497
  readonly text: string;
1452
1498
  readonly lastInTextNode: boolean;
1453
1499
  readonly removed: boolean;
1454
- before(content: string, options?: ContentOptions): Text;
1455
- after(content: string, options?: ContentOptions): Text;
1456
- replace(content: string, options?: ContentOptions): Text;
1500
+ before(
1501
+ content: string | ReadableStream | Response,
1502
+ options?: ContentOptions,
1503
+ ): Text;
1504
+ after(
1505
+ content: string | ReadableStream | Response,
1506
+ options?: ContentOptions,
1507
+ ): Text;
1508
+ replace(
1509
+ content: string | ReadableStream | Response,
1510
+ options?: ContentOptions,
1511
+ ): Text;
1457
1512
  remove(): Text;
1458
1513
  }
1459
1514
  interface DocumentEnd {
@@ -1537,28 +1592,34 @@ declare abstract class Body {
1537
1592
  *
1538
1593
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1539
1594
  */
1540
- declare class Response extends Body {
1541
- constructor(body?: BodyInit | null, init?: ResponseInit);
1542
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
1543
- static redirect(url: string, status?: number): Response;
1544
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
1545
- static json(any: any, maybeInit?: ResponseInit | Response): Response;
1595
+ declare var Response: {
1596
+ prototype: Response;
1597
+ new (body?: BodyInit | null, init?: ResponseInit): Response;
1598
+ redirect(url: string, status?: number): Response;
1599
+ json(any: any, maybeInit?: ResponseInit | Response): Response;
1600
+ };
1601
+ /**
1602
+ * This Fetch API interface represents the response to a request.
1603
+ *
1604
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1605
+ */
1606
+ interface Response extends Body {
1546
1607
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
1547
1608
  clone(): Response;
1548
1609
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status) */
1549
- get status(): number;
1610
+ status: number;
1550
1611
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText) */
1551
- get statusText(): string;
1612
+ statusText: string;
1552
1613
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
1553
- get headers(): Headers;
1614
+ headers: Headers;
1554
1615
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/ok) */
1555
- get ok(): boolean;
1616
+ ok: boolean;
1556
1617
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirected) */
1557
- get redirected(): boolean;
1618
+ redirected: boolean;
1558
1619
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
1559
- get url(): string;
1560
- get webSocket(): WebSocket | null;
1561
- get cf(): any | undefined;
1620
+ url: string;
1621
+ webSocket: WebSocket | null;
1622
+ cf: any | undefined;
1562
1623
  }
1563
1624
  interface ResponseInit {
1564
1625
  status?: number;
@@ -1570,18 +1631,26 @@ interface ResponseInit {
1570
1631
  }
1571
1632
  type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> =
1572
1633
  | Request<CfHostMetadata, Cf>
1573
- | string
1574
- | URL;
1634
+ | string;
1575
1635
  /**
1576
1636
  * This Fetch API interface represents a resource request.
1577
1637
  *
1578
1638
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
1579
1639
  */
1580
- declare class Request<
1581
- CfHostMetadata = unknown,
1582
- Cf = CfProperties<CfHostMetadata>,
1583
- > extends Body {
1584
- constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1640
+ declare var Request: {
1641
+ prototype: Request;
1642
+ new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>(
1643
+ input: RequestInfo<CfProperties> | URL,
1644
+ init?: RequestInit<Cf>,
1645
+ ): Request<CfHostMetadata, Cf>;
1646
+ };
1647
+ /**
1648
+ * This Fetch API interface represents a resource request.
1649
+ *
1650
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
1651
+ */
1652
+ interface Request<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>
1653
+ extends Body {
1585
1654
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/clone) */
1586
1655
  clone(): Request<CfHostMetadata, Cf>;
1587
1656
  /**
@@ -1589,45 +1658,45 @@ declare class Request<
1589
1658
  *
1590
1659
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/method)
1591
1660
  */
1592
- get method(): string;
1661
+ method: string;
1593
1662
  /**
1594
1663
  * Returns the URL of request as a string.
1595
1664
  *
1596
1665
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url)
1597
1666
  */
1598
- get url(): string;
1667
+ url: string;
1599
1668
  /**
1600
1669
  * 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.
1601
1670
  *
1602
1671
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/headers)
1603
1672
  */
1604
- get headers(): Headers;
1673
+ headers: Headers;
1605
1674
  /**
1606
1675
  * 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.
1607
1676
  *
1608
1677
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/redirect)
1609
1678
  */
1610
- get redirect(): string;
1611
- get fetcher(): Fetcher | null;
1679
+ redirect: string;
1680
+ fetcher: Fetcher | null;
1612
1681
  /**
1613
1682
  * Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
1614
1683
  *
1615
1684
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/signal)
1616
1685
  */
1617
- get signal(): AbortSignal;
1618
- get cf(): Cf | undefined;
1686
+ signal: AbortSignal;
1687
+ cf: Cf | undefined;
1619
1688
  /**
1620
1689
  * 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]
1621
1690
  *
1622
1691
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/integrity)
1623
1692
  */
1624
- get integrity(): string;
1693
+ integrity: string;
1625
1694
  /**
1626
1695
  * Returns a boolean indicating whether or not request can outlive the global in which it was created.
1627
1696
  *
1628
1697
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/keepalive)
1629
1698
  */
1630
- get keepalive(): boolean;
1699
+ keepalive: boolean;
1631
1700
  }
1632
1701
  interface RequestInit<Cf = CfProperties> {
1633
1702
  /* A string to set request's method. */
@@ -1653,7 +1722,7 @@ type Fetcher<
1653
1722
  > = (T extends Rpc.EntrypointBranded
1654
1723
  ? Rpc.Provider<T, Reserved | "fetch" | "connect">
1655
1724
  : unknown) & {
1656
- fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1725
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
1657
1726
  connect(address: SocketAddress | string, options?: SocketOptions): Socket;
1658
1727
  };
1659
1728
  interface FetcherPutOptions {
@@ -1875,6 +1944,7 @@ interface R2MultipartUpload {
1875
1944
  uploadPart(
1876
1945
  partNumber: number,
1877
1946
  value: ReadableStream | (ArrayBuffer | ArrayBufferView) | string | Blob,
1947
+ options?: R2UploadPartOptions,
1878
1948
  ): Promise<R2UploadedPart>;
1879
1949
  abort(): Promise<void>;
1880
1950
  complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>;
@@ -1895,6 +1965,7 @@ declare abstract class R2Object {
1895
1965
  readonly customMetadata?: Record<string, string>;
1896
1966
  readonly range?: R2Range;
1897
1967
  readonly storageClass: string;
1968
+ readonly ssecKeyMd5?: string;
1898
1969
  writeHttpMetadata(headers: Headers): void;
1899
1970
  }
1900
1971
  interface R2ObjectBody extends R2Object {
@@ -1927,6 +1998,7 @@ interface R2Conditional {
1927
1998
  interface R2GetOptions {
1928
1999
  onlyIf?: R2Conditional | Headers;
1929
2000
  range?: R2Range | Headers;
2001
+ ssecKey?: ArrayBuffer | string;
1930
2002
  }
1931
2003
  interface R2PutOptions {
1932
2004
  onlyIf?: R2Conditional | Headers;
@@ -1938,11 +2010,13 @@ interface R2PutOptions {
1938
2010
  sha384?: ArrayBuffer | string;
1939
2011
  sha512?: ArrayBuffer | string;
1940
2012
  storageClass?: string;
2013
+ ssecKey?: ArrayBuffer | string;
1941
2014
  }
1942
2015
  interface R2MultipartOptions {
1943
2016
  httpMetadata?: R2HTTPMetadata | Headers;
1944
2017
  customMetadata?: Record<string, string>;
1945
2018
  storageClass?: string;
2019
+ ssecKey?: ArrayBuffer | string;
1946
2020
  }
1947
2021
  interface R2Checksums {
1948
2022
  readonly md5?: ArrayBuffer;
@@ -1979,6 +2053,9 @@ type R2Objects = {
1979
2053
  truncated: false;
1980
2054
  }
1981
2055
  );
2056
+ interface R2UploadPartOptions {
2057
+ ssecKey?: ArrayBuffer | string;
2058
+ }
1982
2059
  declare abstract class ScheduledEvent extends ExtendableEvent {
1983
2060
  readonly scheduledTime: number;
1984
2061
  readonly cron: string;
@@ -2389,6 +2466,8 @@ interface TraceItem {
2389
2466
  readonly dispatchNamespace?: string;
2390
2467
  readonly scriptTags?: string[];
2391
2468
  readonly outcome: string;
2469
+ readonly executionModel: string;
2470
+ readonly truncated: boolean;
2392
2471
  }
2393
2472
  interface TraceItemAlarmEventInfo {
2394
2473
  readonly scheduledTime: Date;
@@ -2528,6 +2607,10 @@ declare class URL {
2528
2607
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */
2529
2608
  static canParse(url: string, base?: string): boolean;
2530
2609
  static parse(url: string, base?: string): URL | null;
2610
+ /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) */
2611
+ static createObjectURL(object: File | Blob): string;
2612
+ /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) */
2613
+ static revokeObjectURL(object_url: string): void;
2531
2614
  }
2532
2615
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams) */
2533
2616
  declare class URLSearchParams {
@@ -2701,8 +2784,24 @@ type WebSocketEventMap = {
2701
2784
  *
2702
2785
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
2703
2786
  */
2704
- declare class WebSocket extends EventTarget<WebSocketEventMap> {
2705
- constructor(url: string, protocols?: string[] | string);
2787
+ declare var WebSocket: {
2788
+ prototype: WebSocket;
2789
+ new (url: string, protocols?: string[] | string): WebSocket;
2790
+ readonly READY_STATE_CONNECTING: number;
2791
+ readonly CONNECTING: number;
2792
+ readonly READY_STATE_OPEN: number;
2793
+ readonly OPEN: number;
2794
+ readonly READY_STATE_CLOSING: number;
2795
+ readonly CLOSING: number;
2796
+ readonly READY_STATE_CLOSED: number;
2797
+ readonly CLOSED: number;
2798
+ };
2799
+ /**
2800
+ * Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
2801
+ *
2802
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
2803
+ */
2804
+ interface WebSocket extends EventTarget<WebSocketEventMap> {
2706
2805
  accept(): void;
2707
2806
  /**
2708
2807
  * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
@@ -2718,38 +2817,30 @@ declare class WebSocket extends EventTarget<WebSocketEventMap> {
2718
2817
  close(code?: number, reason?: string): void;
2719
2818
  serializeAttachment(attachment: any): void;
2720
2819
  deserializeAttachment(): any | null;
2721
- static readonly READY_STATE_CONNECTING: number;
2722
- static readonly CONNECTING: number;
2723
- static readonly READY_STATE_OPEN: number;
2724
- static readonly OPEN: number;
2725
- static readonly READY_STATE_CLOSING: number;
2726
- static readonly CLOSING: number;
2727
- static readonly READY_STATE_CLOSED: number;
2728
- static readonly CLOSED: number;
2729
2820
  /**
2730
2821
  * Returns the state of the WebSocket object's connection. It can have the values described below.
2731
2822
  *
2732
2823
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
2733
2824
  */
2734
- get readyState(): number;
2825
+ readyState: number;
2735
2826
  /**
2736
2827
  * Returns the URL that was used to establish the WebSocket connection.
2737
2828
  *
2738
2829
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
2739
2830
  */
2740
- get url(): string | null;
2831
+ url: string | null;
2741
2832
  /**
2742
2833
  * 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.
2743
2834
  *
2744
2835
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
2745
2836
  */
2746
- get protocol(): string | null;
2837
+ protocol: string | null;
2747
2838
  /**
2748
2839
  * Returns the extensions selected by the server, if any.
2749
2840
  *
2750
2841
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
2751
2842
  */
2752
- get extensions(): string | null;
2843
+ extensions: string | null;
2753
2844
  }
2754
2845
  declare const WebSocketPair: {
2755
2846
  new (): {
@@ -2757,6 +2848,37 @@ declare const WebSocketPair: {
2757
2848
  1: WebSocket;
2758
2849
  };
2759
2850
  };
2851
+ interface SqlStorage {
2852
+ exec<T extends Record<string, SqlStorageValue>>(
2853
+ query: string,
2854
+ ...bindings: any[]
2855
+ ): SqlStorageCursor<T>;
2856
+ get databaseSize(): number;
2857
+ Cursor: typeof SqlStorageCursor;
2858
+ Statement: typeof SqlStorageStatement;
2859
+ }
2860
+ declare abstract class SqlStorageStatement {}
2861
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2862
+ declare abstract class SqlStorageCursor<
2863
+ T extends Record<string, SqlStorageValue>,
2864
+ > {
2865
+ next():
2866
+ | {
2867
+ done?: false;
2868
+ value: T;
2869
+ }
2870
+ | {
2871
+ done: true;
2872
+ value?: never;
2873
+ };
2874
+ toArray(): T[];
2875
+ one(): T;
2876
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2877
+ columnNames: string[];
2878
+ get rowsRead(): number;
2879
+ get rowsWritten(): number;
2880
+ [Symbol.iterator](): IterableIterator<T>;
2881
+ }
2760
2882
  interface Socket {
2761
2883
  get readable(): ReadableStream;
2762
2884
  get writable(): WritableStream;
@@ -3294,7 +3416,7 @@ interface GPUOrigin3DDict {
3294
3416
  z?: number;
3295
3417
  }
3296
3418
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3297
- declare class EventSource {
3419
+ declare class EventSource extends EventTarget {
3298
3420
  constructor(url: string, init?: EventSourceEventSourceInit);
3299
3421
  /**
3300
3422
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -3393,10 +3515,10 @@ declare abstract class BaseAiSentenceSimilarity {
3393
3515
  inputs: AiSentenceSimilarityInput;
3394
3516
  postProcessedOutputs: AiSentenceSimilarityOutput;
3395
3517
  }
3396
- type AiSpeechRecognitionInput = {
3518
+ type AiAutomaticSpeechRecognitionInput = {
3397
3519
  audio: number[];
3398
3520
  };
3399
- type AiSpeechRecognitionOutput = {
3521
+ type AiAutomaticSpeechRecognitionOutput = {
3400
3522
  text?: string;
3401
3523
  words?: {
3402
3524
  word: string;
@@ -3405,9 +3527,9 @@ type AiSpeechRecognitionOutput = {
3405
3527
  }[];
3406
3528
  vtt?: string;
3407
3529
  };
3408
- declare abstract class BaseAiSpeechRecognition {
3409
- inputs: AiSpeechRecognitionInput;
3410
- postProcessedOutputs: AiSpeechRecognitionOutput;
3530
+ declare abstract class BaseAiAutomaticSpeechRecognition {
3531
+ inputs: AiAutomaticSpeechRecognitionInput;
3532
+ postProcessedOutputs: AiAutomaticSpeechRecognitionOutput;
3411
3533
  }
3412
3534
  type AiSummarizationInput = {
3413
3535
  input_text: string;
@@ -3443,16 +3565,36 @@ declare abstract class BaseAiTextEmbeddings {
3443
3565
  postProcessedOutputs: AiTextEmbeddingsOutput;
3444
3566
  }
3445
3567
  type RoleScopedChatInput = {
3446
- role: "user" | "assistant" | "system" | "tool";
3568
+ role:
3569
+ | "user"
3570
+ | "assistant"
3571
+ | "system"
3572
+ | "tool"
3573
+ | (string & NonNullable<unknown>);
3447
3574
  content: string;
3575
+ name?: string;
3576
+ };
3577
+ type AiTextGenerationToolLegacyInput = {
3578
+ name: string;
3579
+ description: string;
3580
+ parameters?: {
3581
+ type: "object" | (string & NonNullable<unknown>);
3582
+ properties: {
3583
+ [key: string]: {
3584
+ type: string;
3585
+ description?: string;
3586
+ };
3587
+ };
3588
+ required: string[];
3589
+ };
3448
3590
  };
3449
3591
  type AiTextGenerationToolInput = {
3450
- type: "function";
3592
+ type: "function" | (string & NonNullable<unknown>);
3451
3593
  function: {
3452
3594
  name: string;
3453
3595
  description: string;
3454
3596
  parameters?: {
3455
- type: "object";
3597
+ type: "object" | (string & NonNullable<unknown>);
3456
3598
  properties: {
3457
3599
  [key: string]: {
3458
3600
  type: string;
@@ -3463,6 +3605,10 @@ type AiTextGenerationToolInput = {
3463
3605
  };
3464
3606
  };
3465
3607
  };
3608
+ type AiTextGenerationFunctionsInput = {
3609
+ name: string;
3610
+ code: string;
3611
+ };
3466
3612
  type AiTextGenerationInput = {
3467
3613
  prompt?: string;
3468
3614
  raw?: boolean;
@@ -3476,7 +3622,11 @@ type AiTextGenerationInput = {
3476
3622
  frequency_penalty?: number;
3477
3623
  presence_penalty?: number;
3478
3624
  messages?: RoleScopedChatInput[];
3479
- tools?: AiTextGenerationToolInput[];
3625
+ tools?:
3626
+ | AiTextGenerationToolInput[]
3627
+ | AiTextGenerationToolLegacyInput[]
3628
+ | (object & NonNullable<unknown>);
3629
+ functions?: AiTextGenerationFunctionsInput[];
3480
3630
  };
3481
3631
  type AiTextGenerationOutput =
3482
3632
  | {
@@ -3491,15 +3641,33 @@ declare abstract class BaseAiTextGeneration {
3491
3641
  inputs: AiTextGenerationInput;
3492
3642
  postProcessedOutputs: AiTextGenerationOutput;
3493
3643
  }
3644
+ type AiTextToSpeechInput = {
3645
+ prompt: string;
3646
+ lang?: string;
3647
+ };
3648
+ type AiTextToSpeechOutput =
3649
+ | Uint8Array
3650
+ | {
3651
+ audio: string;
3652
+ };
3653
+ declare abstract class BaseAiTextToSpeech {
3654
+ inputs: AiTextToSpeechInput;
3655
+ postProcessedOutputs: AiTextToSpeechOutput;
3656
+ }
3494
3657
  type AiTextToImageInput = {
3495
3658
  prompt: string;
3659
+ negative_prompt?: string;
3660
+ height?: number;
3661
+ width?: number;
3496
3662
  image?: number[];
3663
+ image_b64?: string;
3497
3664
  mask?: number[];
3498
3665
  num_steps?: number;
3499
3666
  strength?: number;
3500
3667
  guidance?: number;
3668
+ seed?: number;
3501
3669
  };
3502
- type AiTextToImageOutput = Uint8Array;
3670
+ type AiTextToImageOutput = ReadableStream<Uint8Array>;
3503
3671
  declare abstract class BaseAiTextToImage {
3504
3672
  inputs: AiTextToImageInput;
3505
3673
  postProcessedOutputs: AiTextToImageOutput;
@@ -3516,126 +3684,613 @@ declare abstract class BaseAiTranslation {
3516
3684
  inputs: AiTranslationInput;
3517
3685
  postProcessedOutputs: AiTranslationOutput;
3518
3686
  }
3687
+ type Ai_Cf_Openai_Whisper_Input =
3688
+ | string
3689
+ | {
3690
+ /**
3691
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3692
+ */
3693
+ audio: number[];
3694
+ };
3695
+ interface Ai_Cf_Openai_Whisper_Output {
3696
+ /**
3697
+ * The transcription
3698
+ */
3699
+ text: string;
3700
+ word_count?: number;
3701
+ words?: {
3702
+ word?: string;
3703
+ /**
3704
+ * The second this word begins in the recording
3705
+ */
3706
+ start?: number;
3707
+ /**
3708
+ * The ending second when the word completes
3709
+ */
3710
+ end?: number;
3711
+ }[];
3712
+ vtt?: string;
3713
+ }
3714
+ declare abstract class Base_Ai_Cf_Openai_Whisper {
3715
+ inputs: Ai_Cf_Openai_Whisper_Input;
3716
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Output;
3717
+ }
3718
+ type Ai_Cf_Openai_Whisper_Tiny_En_Input =
3719
+ | string
3720
+ | {
3721
+ /**
3722
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3723
+ */
3724
+ audio: number[];
3725
+ };
3726
+ interface Ai_Cf_Openai_Whisper_Tiny_En_Output {
3727
+ /**
3728
+ * The transcription
3729
+ */
3730
+ text: string;
3731
+ word_count?: number;
3732
+ words?: {
3733
+ word?: string;
3734
+ /**
3735
+ * The second this word begins in the recording
3736
+ */
3737
+ start?: number;
3738
+ /**
3739
+ * The ending second when the word completes
3740
+ */
3741
+ end?: number;
3742
+ }[];
3743
+ vtt?: string;
3744
+ }
3745
+ declare abstract class Base_Ai_Cf_Openai_Whisper_Tiny_En {
3746
+ inputs: Ai_Cf_Openai_Whisper_Tiny_En_Input;
3747
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Tiny_En_Output;
3748
+ }
3749
+ interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input {
3750
+ /**
3751
+ * Base64 encoded value of the audio data.
3752
+ */
3753
+ audio: string;
3754
+ /**
3755
+ * Supported tasks are 'translate' or 'transcribe'.
3756
+ */
3757
+ task?: string;
3758
+ /**
3759
+ * The language of the audio being transcribed or translated.
3760
+ */
3761
+ language?: string;
3762
+ /**
3763
+ * Preprocess the audio with a voice activity detection model.
3764
+ */
3765
+ vad_filter?: string;
3766
+ /**
3767
+ * A text prompt to help provide context to the model on the contents of the audio.
3768
+ */
3769
+ initial_prompt?: string;
3770
+ /**
3771
+ * The prefix it appended the the beginning of the output of the transcription and can guide the transcription result.
3772
+ */
3773
+ prefix?: string;
3774
+ }
3775
+ interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output {
3776
+ transcription_info?: {
3777
+ /**
3778
+ * The language of the audio being transcribed or translated.
3779
+ */
3780
+ language?: string;
3781
+ /**
3782
+ * The confidence level or probability of the detected language being accurate, represented as a decimal between 0 and 1.
3783
+ */
3784
+ language_probability?: number;
3785
+ /**
3786
+ * The total duration of the original audio file, in seconds.
3787
+ */
3788
+ duration?: number;
3789
+ /**
3790
+ * The duration of the audio after applying Voice Activity Detection (VAD) to remove silent or irrelevant sections, in seconds.
3791
+ */
3792
+ duration_after_vad?: number;
3793
+ };
3794
+ /**
3795
+ * The complete transcription of the audio.
3796
+ */
3797
+ text: string;
3798
+ /**
3799
+ * The total number of words in the transcription.
3800
+ */
3801
+ word_count?: number;
3802
+ segments?: {
3803
+ /**
3804
+ * The starting time of the segment within the audio, in seconds.
3805
+ */
3806
+ start?: number;
3807
+ /**
3808
+ * The ending time of the segment within the audio, in seconds.
3809
+ */
3810
+ end?: number;
3811
+ /**
3812
+ * The transcription of the segment.
3813
+ */
3814
+ text?: string;
3815
+ /**
3816
+ * The temperature used in the decoding process, controlling randomness in predictions. Lower values result in more deterministic outputs.
3817
+ */
3818
+ temperature?: number;
3819
+ /**
3820
+ * The average log probability of the predictions for the words in this segment, indicating overall confidence.
3821
+ */
3822
+ avg_logprob?: number;
3823
+ /**
3824
+ * The compression ratio of the input to the output, measuring how much the text was compressed during the transcription process.
3825
+ */
3826
+ compression_ratio?: number;
3827
+ /**
3828
+ * The probability that the segment contains no speech, represented as a decimal between 0 and 1.
3829
+ */
3830
+ no_speech_prob?: number;
3831
+ words?: {
3832
+ /**
3833
+ * The individual word transcribed from the audio.
3834
+ */
3835
+ word?: string;
3836
+ /**
3837
+ * The starting time of the word within the audio, in seconds.
3838
+ */
3839
+ start?: number;
3840
+ /**
3841
+ * The ending time of the word within the audio, in seconds.
3842
+ */
3843
+ end?: number;
3844
+ }[];
3845
+ };
3846
+ /**
3847
+ * The transcription in WebVTT format, which includes timing and text information for use in subtitles.
3848
+ */
3849
+ vtt?: string;
3850
+ }
3851
+ declare abstract class Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo {
3852
+ inputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input;
3853
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output;
3854
+ }
3855
+ interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input {
3856
+ /**
3857
+ * A text description of the image you want to generate.
3858
+ */
3859
+ prompt: string;
3860
+ /**
3861
+ * The number of diffusion steps; higher values can improve quality but take longer.
3862
+ */
3863
+ steps?: number;
3864
+ }
3865
+ interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output {
3866
+ /**
3867
+ * The generated image in Base64 format.
3868
+ */
3869
+ image?: string;
3870
+ }
3871
+ declare abstract class Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell {
3872
+ inputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input;
3873
+ postProcessedOutputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output;
3874
+ }
3875
+ type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input = Prompt | Messages;
3876
+ interface Prompt {
3877
+ /**
3878
+ * The input text prompt for the model to generate a response.
3879
+ */
3880
+ prompt: string;
3881
+ image?: number[] | (string & NonNullable<unknown>);
3882
+ /**
3883
+ * If true, a chat template is not applied and you must adhere to the specific model's expected formatting.
3884
+ */
3885
+ raw?: boolean;
3886
+ /**
3887
+ * If true, the response will be streamed back incrementally using SSE, Server Sent Events.
3888
+ */
3889
+ stream?: boolean;
3890
+ /**
3891
+ * The maximum number of tokens to generate in the response.
3892
+ */
3893
+ max_tokens?: number;
3894
+ /**
3895
+ * Controls the randomness of the output; higher values produce more random results.
3896
+ */
3897
+ temperature?: number;
3898
+ /**
3899
+ * 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.
3900
+ */
3901
+ top_p?: number;
3902
+ /**
3903
+ * 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.
3904
+ */
3905
+ top_k?: number;
3906
+ /**
3907
+ * Random seed for reproducibility of the generation.
3908
+ */
3909
+ seed?: number;
3910
+ /**
3911
+ * Penalty for repeated tokens; higher values discourage repetition.
3912
+ */
3913
+ repetition_penalty?: number;
3914
+ /**
3915
+ * Decreases the likelihood of the model repeating the same lines verbatim.
3916
+ */
3917
+ frequency_penalty?: number;
3918
+ /**
3919
+ * Increases the likelihood of the model introducing new topics.
3920
+ */
3921
+ presence_penalty?: number;
3922
+ /**
3923
+ * Name of the LoRA (Low-Rank Adaptation) model to fine-tune the base model.
3924
+ */
3925
+ lora?: string;
3926
+ }
3927
+ interface Messages {
3928
+ /**
3929
+ * An array of message objects representing the conversation history.
3930
+ */
3931
+ messages: {
3932
+ /**
3933
+ * The role of the message sender (e.g., 'user', 'assistant', 'system', 'tool').
3934
+ */
3935
+ role: string;
3936
+ /**
3937
+ * The content of the message as a string.
3938
+ */
3939
+ content: string;
3940
+ }[];
3941
+ image?: number[] | string;
3942
+ functions?: {
3943
+ name: string;
3944
+ code: string;
3945
+ }[];
3946
+ /**
3947
+ * A list of tools available for the assistant to use.
3948
+ */
3949
+ tools?: (
3950
+ | {
3951
+ /**
3952
+ * The name of the tool. More descriptive the better.
3953
+ */
3954
+ name: string;
3955
+ /**
3956
+ * A brief description of what the tool does.
3957
+ */
3958
+ description: string;
3959
+ /**
3960
+ * Schema defining the parameters accepted by the tool.
3961
+ */
3962
+ parameters: {
3963
+ /**
3964
+ * The type of the parameters object (usually 'object').
3965
+ */
3966
+ type: string;
3967
+ /**
3968
+ * List of required parameter names.
3969
+ */
3970
+ required?: string[];
3971
+ /**
3972
+ * Definitions of each parameter.
3973
+ */
3974
+ properties: {
3975
+ [k: string]: {
3976
+ /**
3977
+ * The data type of the parameter.
3978
+ */
3979
+ type: string;
3980
+ /**
3981
+ * A description of the expected parameter.
3982
+ */
3983
+ description: string;
3984
+ };
3985
+ };
3986
+ };
3987
+ }
3988
+ | {
3989
+ /**
3990
+ * Specifies the type of tool (e.g., 'function').
3991
+ */
3992
+ type: string;
3993
+ /**
3994
+ * Details of the function tool.
3995
+ */
3996
+ function: {
3997
+ /**
3998
+ * The name of the function.
3999
+ */
4000
+ name: string;
4001
+ /**
4002
+ * A brief description of what the function does.
4003
+ */
4004
+ description: string;
4005
+ /**
4006
+ * Schema defining the parameters accepted by the function.
4007
+ */
4008
+ parameters: {
4009
+ /**
4010
+ * The type of the parameters object (usually 'object').
4011
+ */
4012
+ type: string;
4013
+ /**
4014
+ * List of required parameter names.
4015
+ */
4016
+ required?: string[];
4017
+ /**
4018
+ * Definitions of each parameter.
4019
+ */
4020
+ properties: {
4021
+ [k: string]: {
4022
+ /**
4023
+ * The data type of the parameter.
4024
+ */
4025
+ type: string;
4026
+ /**
4027
+ * A description of the expected parameter.
4028
+ */
4029
+ description: string;
4030
+ };
4031
+ };
4032
+ };
4033
+ };
4034
+ }
4035
+ )[];
4036
+ /**
4037
+ * If true, the response will be streamed back incrementally.
4038
+ */
4039
+ stream?: boolean;
4040
+ /**
4041
+ * The maximum number of tokens to generate in the response.
4042
+ */
4043
+ max_tokens?: number;
4044
+ /**
4045
+ * Controls the randomness of the output; higher values produce more random results.
4046
+ */
4047
+ temperature?: number;
4048
+ /**
4049
+ * 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.
4050
+ */
4051
+ top_p?: number;
4052
+ /**
4053
+ * 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.
4054
+ */
4055
+ top_k?: number;
4056
+ /**
4057
+ * Random seed for reproducibility of the generation.
4058
+ */
4059
+ seed?: number;
4060
+ /**
4061
+ * Penalty for repeated tokens; higher values discourage repetition.
4062
+ */
4063
+ repetition_penalty?: number;
4064
+ /**
4065
+ * Decreases the likelihood of the model repeating the same lines verbatim.
4066
+ */
4067
+ frequency_penalty?: number;
4068
+ /**
4069
+ * Increases the likelihood of the model introducing new topics.
4070
+ */
4071
+ presence_penalty?: number;
4072
+ }
4073
+ type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output =
4074
+ | {
4075
+ /**
4076
+ * The generated text response from the model
4077
+ */
4078
+ response?: string;
4079
+ /**
4080
+ * An array of tool calls requests made during the response generation
4081
+ */
4082
+ tool_calls?: {
4083
+ /**
4084
+ * The arguments passed to be passed to the tool call request
4085
+ */
4086
+ arguments?: object;
4087
+ /**
4088
+ * The name of the tool to be called
4089
+ */
4090
+ name?: string;
4091
+ }[];
4092
+ }
4093
+ | ReadableStream;
4094
+ declare abstract class Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct {
4095
+ inputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input;
4096
+ postProcessedOutputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output;
4097
+ }
4098
+ interface AiModels {
4099
+ "@cf/huggingface/distilbert-sst-2-int8": BaseAiTextClassification;
4100
+ "@cf/stabilityai/stable-diffusion-xl-base-1.0": BaseAiTextToImage;
4101
+ "@cf/runwayml/stable-diffusion-v1-5-inpainting": BaseAiTextToImage;
4102
+ "@cf/runwayml/stable-diffusion-v1-5-img2img": BaseAiTextToImage;
4103
+ "@cf/lykon/dreamshaper-8-lcm": BaseAiTextToImage;
4104
+ "@cf/bytedance/stable-diffusion-xl-lightning": BaseAiTextToImage;
4105
+ "@cf/baai/bge-base-en-v1.5": BaseAiTextEmbeddings;
4106
+ "@cf/baai/bge-small-en-v1.5": BaseAiTextEmbeddings;
4107
+ "@cf/baai/bge-large-en-v1.5": BaseAiTextEmbeddings;
4108
+ "@cf/microsoft/resnet-50": BaseAiImageClassification;
4109
+ "@cf/facebook/detr-resnet-50": BaseAiObjectDetection;
4110
+ "@cf/meta/llama-2-7b-chat-int8": BaseAiTextGeneration;
4111
+ "@cf/mistral/mistral-7b-instruct-v0.1": BaseAiTextGeneration;
4112
+ "@cf/meta/llama-2-7b-chat-fp16": BaseAiTextGeneration;
4113
+ "@hf/thebloke/llama-2-13b-chat-awq": BaseAiTextGeneration;
4114
+ "@hf/thebloke/mistral-7b-instruct-v0.1-awq": BaseAiTextGeneration;
4115
+ "@hf/thebloke/zephyr-7b-beta-awq": BaseAiTextGeneration;
4116
+ "@hf/thebloke/openhermes-2.5-mistral-7b-awq": BaseAiTextGeneration;
4117
+ "@hf/thebloke/neural-chat-7b-v3-1-awq": BaseAiTextGeneration;
4118
+ "@hf/thebloke/llamaguard-7b-awq": BaseAiTextGeneration;
4119
+ "@hf/thebloke/deepseek-coder-6.7b-base-awq": BaseAiTextGeneration;
4120
+ "@hf/thebloke/deepseek-coder-6.7b-instruct-awq": BaseAiTextGeneration;
4121
+ "@cf/deepseek-ai/deepseek-math-7b-instruct": BaseAiTextGeneration;
4122
+ "@cf/defog/sqlcoder-7b-2": BaseAiTextGeneration;
4123
+ "@cf/openchat/openchat-3.5-0106": BaseAiTextGeneration;
4124
+ "@cf/tiiuae/falcon-7b-instruct": BaseAiTextGeneration;
4125
+ "@cf/thebloke/discolm-german-7b-v1-awq": BaseAiTextGeneration;
4126
+ "@cf/qwen/qwen1.5-0.5b-chat": BaseAiTextGeneration;
4127
+ "@cf/qwen/qwen1.5-7b-chat-awq": BaseAiTextGeneration;
4128
+ "@cf/qwen/qwen1.5-14b-chat-awq": BaseAiTextGeneration;
4129
+ "@cf/tinyllama/tinyllama-1.1b-chat-v1.0": BaseAiTextGeneration;
4130
+ "@cf/microsoft/phi-2": BaseAiTextGeneration;
4131
+ "@cf/qwen/qwen1.5-1.8b-chat": BaseAiTextGeneration;
4132
+ "@cf/mistral/mistral-7b-instruct-v0.2-lora": BaseAiTextGeneration;
4133
+ "@hf/nousresearch/hermes-2-pro-mistral-7b": BaseAiTextGeneration;
4134
+ "@hf/nexusflow/starling-lm-7b-beta": BaseAiTextGeneration;
4135
+ "@hf/google/gemma-7b-it": BaseAiTextGeneration;
4136
+ "@cf/meta-llama/llama-2-7b-chat-hf-lora": BaseAiTextGeneration;
4137
+ "@cf/google/gemma-2b-it-lora": BaseAiTextGeneration;
4138
+ "@cf/google/gemma-7b-it-lora": BaseAiTextGeneration;
4139
+ "@hf/mistral/mistral-7b-instruct-v0.2": BaseAiTextGeneration;
4140
+ "@cf/meta/llama-3-8b-instruct": BaseAiTextGeneration;
4141
+ "@cf/fblgit/una-cybertron-7b-v2-bf16": BaseAiTextGeneration;
4142
+ "@cf/meta/llama-3-8b-instruct-awq": BaseAiTextGeneration;
4143
+ "@hf/meta-llama/meta-llama-3-8b-instruct": BaseAiTextGeneration;
4144
+ "@cf/meta/llama-3.1-8b-instruct": BaseAiTextGeneration;
4145
+ "@cf/meta/llama-3.1-8b-instruct-fp8": BaseAiTextGeneration;
4146
+ "@cf/meta/llama-3.1-8b-instruct-awq": BaseAiTextGeneration;
4147
+ "@cf/meta/llama-3.2-3b-instruct": BaseAiTextGeneration;
4148
+ "@cf/meta/llama-3.2-1b-instruct": BaseAiTextGeneration;
4149
+ "@cf/meta/llama-3.3-70b-instruct-fp8-fast": BaseAiTextGeneration;
4150
+ "@cf/meta/m2m100-1.2b": BaseAiTranslation;
4151
+ "@cf/facebook/bart-large-cnn": BaseAiSummarization;
4152
+ "@cf/unum/uform-gen2-qwen-500m": BaseAiImageToText;
4153
+ "@cf/llava-hf/llava-1.5-7b-hf": BaseAiImageToText;
4154
+ "@cf/openai/whisper": Base_Ai_Cf_Openai_Whisper;
4155
+ "@cf/openai/whisper-tiny-en": Base_Ai_Cf_Openai_Whisper_Tiny_En;
4156
+ "@cf/openai/whisper-large-v3-turbo": Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo;
4157
+ "@cf/black-forest-labs/flux-1-schnell": Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell;
4158
+ "@cf/meta/llama-3.2-11b-vision-instruct": Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct;
4159
+ }
4160
+ type AiOptions = {
4161
+ gateway?: GatewayOptions;
4162
+ prefix?: string;
4163
+ extraHeaders?: object;
4164
+ };
4165
+ type AiModelsSearchParams = {
4166
+ author?: string;
4167
+ hide_experimental?: boolean;
4168
+ page?: number;
4169
+ per_page?: number;
4170
+ search?: string;
4171
+ source?: number;
4172
+ task?: string;
4173
+ };
4174
+ type AiModelsSearchObject = {
4175
+ id: string;
4176
+ source: number;
4177
+ name: string;
4178
+ description: string;
4179
+ task: {
4180
+ id: string;
4181
+ name: string;
4182
+ description: string;
4183
+ };
4184
+ tags: string[];
4185
+ properties: {
4186
+ property_id: string;
4187
+ value: string;
4188
+ }[];
4189
+ };
4190
+ interface InferenceUpstreamError extends Error {}
4191
+ interface AiInternalError extends Error {}
4192
+ type AiModelListType = Record<string, any>;
4193
+ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
4194
+ aiGatewayLogId: string | null;
4195
+ gateway(gatewayId: string): AiGateway;
4196
+ run<Name extends keyof AiModelList>(
4197
+ model: Name,
4198
+ inputs: AiModelList[Name]["inputs"],
4199
+ options?: AiOptions,
4200
+ ): Promise<AiModelList[Name]["postProcessedOutputs"]>;
4201
+ public models(params?: AiModelsSearchParams): Promise<AiModelsSearchObject[]>;
4202
+ }
3519
4203
  type GatewayOptions = {
3520
4204
  id: string;
4205
+ cacheKey?: string;
3521
4206
  cacheTtl?: number;
3522
4207
  skipCache?: boolean;
3523
4208
  metadata?: Record<string, number | string | boolean | null | bigint>;
4209
+ collectLog?: boolean;
3524
4210
  };
3525
- type AiOptions = {
3526
- gateway?: GatewayOptions;
3527
- prefix?: string;
3528
- extraHeaders?: object;
4211
+ type AiGatewayPatchLog = {
4212
+ score?: number | null;
4213
+ feedback?: -1 | 1 | null;
4214
+ metadata?: Record<string, number | string | boolean | null | bigint> | null;
3529
4215
  };
3530
- type BaseAiTextClassificationModels = "@cf/huggingface/distilbert-sst-2-int8";
3531
- type BaseAiTextToImageModels =
3532
- | "@cf/stabilityai/stable-diffusion-xl-base-1.0"
3533
- | "@cf/runwayml/stable-diffusion-v1-5-inpainting"
3534
- | "@cf/runwayml/stable-diffusion-v1-5-img2img"
3535
- | "@cf/lykon/dreamshaper-8-lcm"
3536
- | "@cf/bytedance/stable-diffusion-xl-lightning";
3537
- type BaseAiTextEmbeddingsModels =
3538
- | "@cf/baai/bge-small-en-v1.5"
3539
- | "@cf/baai/bge-base-en-v1.5"
3540
- | "@cf/baai/bge-large-en-v1.5";
3541
- type BaseAiSpeechRecognitionModels =
3542
- | "@cf/openai/whisper"
3543
- | "@cf/openai/whisper-tiny-en"
3544
- | "@cf/openai/whisper-sherpa";
3545
- type BaseAiImageClassificationModels = "@cf/microsoft/resnet-50";
3546
- type BaseAiObjectDetectionModels = "@cf/facebook/detr-resnet-50";
3547
- type BaseAiTextGenerationModels =
3548
- | "@cf/meta/llama-3-8b-instruct"
3549
- | "@cf/meta/llama-3-8b-instruct-awq"
3550
- | "@cf/meta/llama-2-7b-chat-int8"
3551
- | "@cf/mistral/mistral-7b-instruct-v0.1"
3552
- | "@cf/mistral/mistral-7b-instruct-v0.2-lora"
3553
- | "@cf/meta/llama-2-7b-chat-fp16"
3554
- | "@hf/thebloke/llama-2-13b-chat-awq"
3555
- | "@hf/thebloke/zephyr-7b-beta-awq"
3556
- | "@hf/thebloke/mistral-7b-instruct-v0.1-awq"
3557
- | "@hf/thebloke/codellama-7b-instruct-awq"
3558
- | "@hf/thebloke/openhermes-2.5-mistral-7b-awq"
3559
- | "@hf/thebloke/neural-chat-7b-v3-1-awq"
3560
- | "@hf/thebloke/llamaguard-7b-awq"
3561
- | "@hf/thebloke/deepseek-coder-6.7b-base-awq"
3562
- | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq"
3563
- | "@hf/nousresearch/hermes-2-pro-mistral-7b"
3564
- | "@hf/mistral/mistral-7b-instruct-v0.2"
3565
- | "@hf/google/gemma-7b-it"
3566
- | "@hf/nexusflow/starling-lm-7b-beta"
3567
- | "@cf/deepseek-ai/deepseek-math-7b-instruct"
3568
- | "@cf/defog/sqlcoder-7b-2"
3569
- | "@cf/openchat/openchat-3.5-0106"
3570
- | "@cf/tiiuae/falcon-7b-instruct"
3571
- | "@cf/thebloke/discolm-german-7b-v1-awq"
3572
- | "@cf/qwen/qwen1.5-0.5b-chat"
3573
- | "@cf/qwen/qwen1.5-1.8b-chat"
3574
- | "@cf/qwen/qwen1.5-7b-chat-awq"
3575
- | "@cf/qwen/qwen1.5-14b-chat-awq"
3576
- | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0"
3577
- | "@cf/microsoft/phi-2"
3578
- | "@cf/google/gemma-2b-it-lora"
3579
- | "@cf/google/gemma-7b-it-lora"
3580
- | "@cf/meta-llama/llama-2-7b-chat-hf-lora"
3581
- | "@cf/fblgit/una-cybertron-7b-v2-bf16"
3582
- | "@cf/fblgit/una-cybertron-7b-v2-awq";
3583
- type BaseAiTranslationModels = "@cf/meta/m2m100-1.2b";
3584
- type BaseAiSummarizationModels = "@cf/facebook/bart-large-cnn";
3585
- type BaseAiImageToTextModels =
3586
- | "@cf/unum/uform-gen2-qwen-500m"
3587
- | "@cf/llava-hf/llava-1.5-7b-hf";
3588
- declare abstract class Ai {
3589
- run(
3590
- model: BaseAiTextClassificationModels,
3591
- inputs: BaseAiTextClassification["inputs"],
3592
- options?: AiOptions,
3593
- ): Promise<BaseAiTextClassification["postProcessedOutputs"]>;
3594
- run(
3595
- model: BaseAiTextToImageModels,
3596
- inputs: BaseAiTextToImage["inputs"],
3597
- options?: AiOptions,
3598
- ): Promise<BaseAiTextToImage["postProcessedOutputs"]>;
3599
- run(
3600
- model: BaseAiTextEmbeddingsModels,
3601
- inputs: BaseAiTextEmbeddings["inputs"],
3602
- options?: AiOptions,
3603
- ): Promise<BaseAiTextEmbeddings["postProcessedOutputs"]>;
3604
- run(
3605
- model: BaseAiSpeechRecognitionModels,
3606
- inputs: BaseAiSpeechRecognition["inputs"],
3607
- options?: AiOptions,
3608
- ): Promise<BaseAiSpeechRecognition["postProcessedOutputs"]>;
3609
- run(
3610
- model: BaseAiImageClassificationModels,
3611
- inputs: BaseAiImageClassification["inputs"],
3612
- options?: AiOptions,
3613
- ): Promise<BaseAiImageClassification["postProcessedOutputs"]>;
3614
- run(
3615
- model: BaseAiObjectDetectionModels,
3616
- inputs: BaseAiObjectDetection["inputs"],
3617
- options?: AiOptions,
3618
- ): Promise<BaseAiObjectDetection["postProcessedOutputs"]>;
3619
- run(
3620
- model: BaseAiTextGenerationModels,
3621
- inputs: BaseAiTextGeneration["inputs"],
3622
- options?: AiOptions,
3623
- ): Promise<BaseAiTextGeneration["postProcessedOutputs"]>;
3624
- run(
3625
- model: BaseAiTranslationModels,
3626
- inputs: BaseAiTranslation["inputs"],
3627
- options?: AiOptions,
3628
- ): Promise<BaseAiTranslation["postProcessedOutputs"]>;
3629
- run(
3630
- model: BaseAiSummarizationModels,
3631
- inputs: BaseAiSummarization["inputs"],
3632
- options?: AiOptions,
3633
- ): Promise<BaseAiSummarization["postProcessedOutputs"]>;
4216
+ type AiGatewayLog = {
4217
+ id: string;
4218
+ provider: string;
4219
+ model: string;
4220
+ model_type?: string;
4221
+ path: string;
4222
+ duration: number;
4223
+ request_type?: string;
4224
+ request_content_type?: string;
4225
+ status_code: number;
4226
+ response_content_type?: string;
4227
+ success: boolean;
4228
+ cached: boolean;
4229
+ tokens_in?: number;
4230
+ tokens_out?: number;
4231
+ metadata?: Record<string, number | string | boolean | null | bigint>;
4232
+ step?: number;
4233
+ cost?: number;
4234
+ custom_cost?: boolean;
4235
+ request_size: number;
4236
+ request_head?: string;
4237
+ request_head_complete: boolean;
4238
+ response_size: number;
4239
+ response_head?: string;
4240
+ response_head_complete: boolean;
4241
+ created_at: Date;
4242
+ };
4243
+ type AIGatewayProviders =
4244
+ | "workers-ai"
4245
+ | "anthropic"
4246
+ | "aws-bedrock"
4247
+ | "azure-openai"
4248
+ | "google-vertex-ai"
4249
+ | "huggingface"
4250
+ | "openai"
4251
+ | "perplexity-ai"
4252
+ | "replicate"
4253
+ | "groq"
4254
+ | "cohere"
4255
+ | "google-ai-studio"
4256
+ | "mistral"
4257
+ | "grok"
4258
+ | "openrouter";
4259
+ type AIGatewayHeaders = {
4260
+ "cf-aig-metadata":
4261
+ | Record<string, number | string | boolean | null | bigint>
4262
+ | string;
4263
+ "cf-aig-custom-cost":
4264
+ | {
4265
+ per_token_in?: number;
4266
+ per_token_out?: number;
4267
+ }
4268
+ | {
4269
+ total_cost?: number;
4270
+ }
4271
+ | string;
4272
+ "cf-aig-cache-ttl": number | string;
4273
+ "cf-aig-skip-cache": boolean | string;
4274
+ "cf-aig-cache-key": string;
4275
+ "cf-aig-collect-log": boolean | string;
4276
+ Authorization: string;
4277
+ "Content-Type": string;
4278
+ [key: string]: string | number | boolean | object;
4279
+ };
4280
+ type AIGatewayUniversalRequest = {
4281
+ provider: AIGatewayProviders | string; // eslint-disable-line
4282
+ endpoint: string;
4283
+ headers: Partial<AIGatewayHeaders>;
4284
+ query: unknown;
4285
+ };
4286
+ interface AiGatewayInternalError extends Error {}
4287
+ interface AiGatewayLogNotFound extends Error {}
4288
+ declare abstract class AiGateway {
4289
+ patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>;
4290
+ getLog(logId: string): Promise<AiGatewayLog>;
3634
4291
  run(
3635
- model: BaseAiImageToTextModels,
3636
- inputs: BaseAiImageToText["inputs"],
3637
- options?: AiOptions,
3638
- ): Promise<BaseAiImageToText["postProcessedOutputs"]>;
4292
+ data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[],
4293
+ ): Promise<Response>;
3639
4294
  }
3640
4295
  interface BasicImageTransformations {
3641
4296
  /**
@@ -4641,7 +5296,7 @@ declare abstract class D1PreparedStatement {
4641
5296
  bind(...values: unknown[]): D1PreparedStatement;
4642
5297
  first<T = unknown>(colName: string): Promise<T | null>;
4643
5298
  first<T = Record<string, unknown>>(): Promise<T | null>;
4644
- run(): Promise<D1Response>;
5299
+ run<T = Record<string, unknown>>(): Promise<D1Result<T>>;
4645
5300
  all<T = Record<string, unknown>>(): Promise<D1Result<T>>;
4646
5301
  raw<T = unknown[]>(options: {
4647
5302
  columnNames: true;
@@ -4697,6 +5352,12 @@ interface ForwardableEmailMessage extends EmailMessage {
4697
5352
  * @returns A promise that resolves when the email message is forwarded.
4698
5353
  */
4699
5354
  forward(rcptTo: string, headers?: Headers): Promise<void>;
5355
+ /**
5356
+ * Reply to the sender of this email message with a new EmailMessage object.
5357
+ * @param message The reply message.
5358
+ * @returns A promise that resolves when the email message is replied.
5359
+ */
5360
+ reply(message: EmailMessage): Promise<void>;
4700
5361
  }
4701
5362
  /**
4702
5363
  * A binding that allows a Worker to send email messages.
@@ -4766,6 +5427,128 @@ interface Hyperdrive {
4766
5427
  */
4767
5428
  readonly database: string;
4768
5429
  }
5430
+ // Copyright (c) 2024 Cloudflare, Inc.
5431
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5432
+ // https://opensource.org/licenses/Apache-2.0
5433
+ type ImageInfoResponse =
5434
+ | {
5435
+ format: "image/svg+xml";
5436
+ }
5437
+ | {
5438
+ format: string;
5439
+ fileSize: number;
5440
+ width: number;
5441
+ height: number;
5442
+ };
5443
+ type ImageTransform = {
5444
+ fit?: "scale-down" | "contain" | "pad" | "squeeze" | "cover" | "crop";
5445
+ gravity?:
5446
+ | "left"
5447
+ | "right"
5448
+ | "top"
5449
+ | "bottom"
5450
+ | "center"
5451
+ | "auto"
5452
+ | "entropy"
5453
+ | "face"
5454
+ | {
5455
+ x?: number;
5456
+ y?: number;
5457
+ mode: "remainder" | "box-center";
5458
+ };
5459
+ trim?: {
5460
+ top?: number;
5461
+ bottom?: number;
5462
+ left?: number;
5463
+ right?: number;
5464
+ width?: number;
5465
+ height?: number;
5466
+ border?:
5467
+ | boolean
5468
+ | {
5469
+ color?: string;
5470
+ tolerance?: number;
5471
+ keep?: number;
5472
+ };
5473
+ };
5474
+ width?: number;
5475
+ height?: number;
5476
+ background?: string;
5477
+ rotate?: number;
5478
+ sharpen?: number;
5479
+ blur?: number;
5480
+ contrast?: number;
5481
+ brightness?: number;
5482
+ gamma?: number;
5483
+ border?: {
5484
+ color?: string;
5485
+ width?: number;
5486
+ top?: number;
5487
+ bottom?: number;
5488
+ left?: number;
5489
+ right?: number;
5490
+ };
5491
+ zoom?: number;
5492
+ };
5493
+ type ImageOutputOptions = {
5494
+ format:
5495
+ | "image/jpeg"
5496
+ | "image/png"
5497
+ | "image/gif"
5498
+ | "image/webp"
5499
+ | "image/avif"
5500
+ | "rgb"
5501
+ | "rgba";
5502
+ quality?: number;
5503
+ background?: string;
5504
+ };
5505
+ interface ImagesBinding {
5506
+ /**
5507
+ * Get image metadata (type, width and height)
5508
+ * @throws {@link ImagesError} with code 9412 if input is not an image
5509
+ * @param stream The image bytes
5510
+ */
5511
+ info(stream: ReadableStream<Uint8Array>): Promise<ImageInfoResponse>;
5512
+ /**
5513
+ * Begin applying a series of transformations to an image
5514
+ * @param stream The image bytes
5515
+ * @returns A transform handle
5516
+ */
5517
+ input(stream: ReadableStream<Uint8Array>): ImageTransformer;
5518
+ }
5519
+ interface ImageTransformer {
5520
+ /**
5521
+ * Apply transform next, returning a transform handle.
5522
+ * You can then apply more transformations or retrieve the output.
5523
+ * @param transform
5524
+ */
5525
+ transform(transform: ImageTransform): ImageTransformer;
5526
+ /**
5527
+ * Retrieve the image that results from applying the transforms to the
5528
+ * provided input
5529
+ * @param options Options that apply to the output e.g. output format
5530
+ */
5531
+ output(options: ImageOutputOptions): Promise<ImageTransformationResult>;
5532
+ }
5533
+ interface ImageTransformationResult {
5534
+ /**
5535
+ * The image as a response, ready to store in cache or return to users
5536
+ */
5537
+ response(): Response;
5538
+ /**
5539
+ * The content type of the returned image
5540
+ */
5541
+ contentType(): string;
5542
+ /**
5543
+ * The bytes of the response
5544
+ */
5545
+ image(): ReadableStream<Uint8Array>;
5546
+ }
5547
+ interface ImagesError extends Error {
5548
+ readonly code: number;
5549
+ readonly message: string;
5550
+ readonly stack?: string;
5551
+ }
4769
5552
  type Params<P extends string = any> = Record<P, string | string[]>;
4770
5553
  type EventContext<Env, P extends string, Data> = {
4771
5554
  request: Request<unknown, IncomingRequestCfProperties<unknown>>;
@@ -4812,6 +5595,30 @@ type PagesPluginFunction<
4812
5595
  declare module "assets:*" {
4813
5596
  export const onRequest: PagesFunction;
4814
5597
  }
5598
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
5599
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5600
+ // https://opensource.org/licenses/Apache-2.0
5601
+ declare abstract class PipelineTransform {
5602
+ /**
5603
+ * transformJson recieves an array of javascript objects which can be
5604
+ * mutated and returned to the pipeline
5605
+ * @param data The data to be mutated
5606
+ * @returns A promise containing the mutated data
5607
+ */
5608
+ public transformJson(data: object[]): Promise<object[]>;
5609
+ }
5610
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
5611
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5612
+ // https://opensource.org/licenses/Apache-2.0
5613
+ interface Pipeline {
5614
+ /**
5615
+ * send takes an array of javascript objects which are
5616
+ * then received by the pipeline for processing
5617
+ *
5618
+ * @param data The data to be sent
5619
+ */
5620
+ send(data: object[]): Promise<void>;
5621
+ }
4815
5622
  // PubSubMessage represents an incoming PubSub message.
4816
5623
  // The message includes metadata about the broker, the client, and the payload
4817
5624
  // itself.
@@ -4872,6 +5679,7 @@ declare namespace Rpc {
4872
5679
  export const __RPC_TARGET_BRAND: "__RPC_TARGET_BRAND";
4873
5680
  export const __WORKER_ENTRYPOINT_BRAND: "__WORKER_ENTRYPOINT_BRAND";
4874
5681
  export const __DURABLE_OBJECT_BRAND: "__DURABLE_OBJECT_BRAND";
5682
+ export const __WORKFLOW_ENTRYPOINT_BRAND: "__WORKFLOW_ENTRYPOINT_BRAND";
4875
5683
  export interface RpcTargetBranded {
4876
5684
  [__RPC_TARGET_BRAND]: never;
4877
5685
  }
@@ -4881,13 +5689,20 @@ declare namespace Rpc {
4881
5689
  export interface DurableObjectBranded {
4882
5690
  [__DURABLE_OBJECT_BRAND]: never;
4883
5691
  }
5692
+ export interface WorkflowEntrypointBranded {
5693
+ [__WORKFLOW_ENTRYPOINT_BRAND]: never;
5694
+ }
4884
5695
  export type EntrypointBranded =
4885
5696
  | WorkerEntrypointBranded
4886
- | DurableObjectBranded;
5697
+ | DurableObjectBranded
5698
+ | WorkflowEntrypointBranded;
4887
5699
  // Types that can be used through `Stub`s
4888
5700
  export type Stubable = RpcTargetBranded | ((...args: any[]) => any);
4889
5701
  // Types that can be passed over RPC
4890
- type Serializable =
5702
+ // The reason for using a generic type here is to build a serializable subset of structured
5703
+ // cloneable composite types. This allows types defined with the "interface" keyword to pass the
5704
+ // serializable check as well. Otherwise, only types defined with the "type" keyword would pass.
5705
+ type Serializable<T> =
4891
5706
  // Structured cloneables
4892
5707
  | void
4893
5708
  | undefined
@@ -4903,11 +5718,14 @@ declare namespace Rpc {
4903
5718
  | Error
4904
5719
  | RegExp
4905
5720
  // Structured cloneable composites
4906
- | Map<Serializable, Serializable>
4907
- | Set<Serializable>
4908
- | ReadonlyArray<Serializable>
5721
+ | Map<
5722
+ T extends Map<infer U, unknown> ? Serializable<U> : never,
5723
+ T extends Map<unknown, infer U> ? Serializable<U> : never
5724
+ >
5725
+ | Set<T extends Set<infer U> ? Serializable<U> : never>
5726
+ | ReadonlyArray<T extends ReadonlyArray<infer U> ? Serializable<U> : never>
4909
5727
  | {
4910
- [key: string | number]: Serializable;
5728
+ [K in keyof T]: K extends number | string ? Serializable<T[K]> : never;
4911
5729
  }
4912
5730
  // Special types
4913
5731
  | ReadableStream<Uint8Array>
@@ -4937,7 +5755,7 @@ declare namespace Rpc {
4937
5755
  : T extends ReadonlyArray<infer V>
4938
5756
  ? ReadonlyArray<Stubify<V>>
4939
5757
  : T extends {
4940
- [key: string | number]: unknown;
5758
+ [key: string | number]: any;
4941
5759
  }
4942
5760
  ? {
4943
5761
  [K in keyof T]: Stubify<T[K]>;
@@ -4980,7 +5798,7 @@ declare namespace Rpc {
4980
5798
  // Intersecting with `(Maybe)Provider` allows pipelining.
4981
5799
  type Result<R> = R extends Stubable
4982
5800
  ? Promise<Stub<R>> & Provider<R>
4983
- : R extends Serializable
5801
+ : R extends Serializable<R>
4984
5802
  ? Promise<Stubify<R> & MaybeDisposable<R>> & MaybeProvider<R>
4985
5803
  : never;
4986
5804
  // Type for method or property on an RPC interface.
@@ -5040,7 +5858,7 @@ declare module "cloudflare:workers" {
5040
5858
  protected env: Env;
5041
5859
  constructor(ctx: DurableObjectState, env: Env);
5042
5860
  fetch?(request: Request): Response | Promise<Response>;
5043
- alarm?(): void | Promise<void>;
5861
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
5044
5862
  webSocketMessage?(
5045
5863
  ws: WebSocket,
5046
5864
  message: string | ArrayBuffer,
@@ -5053,6 +5871,60 @@ declare module "cloudflare:workers" {
5053
5871
  ): void | Promise<void>;
5054
5872
  webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
5055
5873
  }
5874
+ export type WorkflowDurationLabel =
5875
+ | "second"
5876
+ | "minute"
5877
+ | "hour"
5878
+ | "day"
5879
+ | "week"
5880
+ | "month"
5881
+ | "year";
5882
+ export type WorkflowSleepDuration =
5883
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
5884
+ | number;
5885
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
5886
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
5887
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
5888
+ export type WorkflowStepConfig = {
5889
+ retries?: {
5890
+ limit: number;
5891
+ delay: WorkflowDelayDuration | number;
5892
+ backoff?: WorkflowBackoff;
5893
+ };
5894
+ timeout?: WorkflowTimeoutDuration | number;
5895
+ };
5896
+ export type WorkflowEvent<T> = {
5897
+ payload: Readonly<T>;
5898
+ timestamp: Date;
5899
+ instanceId: string;
5900
+ };
5901
+ export abstract class WorkflowStep {
5902
+ do<T extends Rpc.Serializable<T>>(
5903
+ name: string,
5904
+ callback: () => Promise<T>,
5905
+ ): Promise<T>;
5906
+ do<T extends Rpc.Serializable<T>>(
5907
+ name: string,
5908
+ config: WorkflowStepConfig,
5909
+ callback: () => Promise<T>,
5910
+ ): Promise<T>;
5911
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
5912
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
5913
+ }
5914
+ export abstract class WorkflowEntrypoint<
5915
+ Env = unknown,
5916
+ T extends Rpc.Serializable<T> | unknown = unknown,
5917
+ > implements Rpc.WorkflowEntrypointBranded
5918
+ {
5919
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
5920
+ protected ctx: ExecutionContext;
5921
+ protected env: Env;
5922
+ constructor(ctx: ExecutionContext, env: Env);
5923
+ run(
5924
+ event: Readonly<WorkflowEvent<T>>,
5925
+ step: WorkflowStep,
5926
+ ): Promise<unknown>;
5927
+ }
5056
5928
  }
5057
5929
  declare module "cloudflare:sockets" {
5058
5930
  function _connect(
@@ -5061,6 +5933,198 @@ declare module "cloudflare:sockets" {
5061
5933
  ): Socket;
5062
5934
  export { _connect as connect };
5063
5935
  }
5936
+ declare namespace TailStream {
5937
+ interface Header {
5938
+ readonly name: string;
5939
+ readonly value: string;
5940
+ }
5941
+ interface FetchEventInfo {
5942
+ readonly type: "fetch";
5943
+ readonly method: string;
5944
+ readonly url: string;
5945
+ readonly cfJson: string;
5946
+ readonly headers: Header[];
5947
+ }
5948
+ interface JsRpcEventInfo {
5949
+ readonly type: "jsrpc";
5950
+ readonly methodName: string;
5951
+ }
5952
+ interface ScheduledEventInfo {
5953
+ readonly type: "scheduled";
5954
+ readonly scheduledTime: Date;
5955
+ readonly cron: string;
5956
+ }
5957
+ interface AlarmEventInfo {
5958
+ readonly type: "alarm";
5959
+ readonly scheduledTime: Date;
5960
+ }
5961
+ interface QueueEventInfo {
5962
+ readonly type: "queue";
5963
+ readonly queueName: string;
5964
+ readonly batchSize: number;
5965
+ }
5966
+ interface EmailEventInfo {
5967
+ readonly type: "email";
5968
+ readonly mailFrom: string;
5969
+ readonly rcptTo: string;
5970
+ readonly rawSize: number;
5971
+ }
5972
+ interface TraceEventInfo {
5973
+ readonly type: "trace";
5974
+ readonly traces: (string | null)[];
5975
+ }
5976
+ interface HibernatableWebSocketEventInfoMessage {
5977
+ readonly type: "message";
5978
+ }
5979
+ interface HibernatableWebSocketEventInfoError {
5980
+ readonly type: "error";
5981
+ }
5982
+ interface HibernatableWebSocketEventInfoClose {
5983
+ readonly type: "close";
5984
+ readonly code: number;
5985
+ readonly wasClean: boolean;
5986
+ }
5987
+ interface HibernatableWebSocketEventInfo {
5988
+ readonly type: "hibernatableWebSocket";
5989
+ readonly info:
5990
+ | HibernatableWebSocketEventInfoClose
5991
+ | HibernatableWebSocketEventInfoError
5992
+ | HibernatableWebSocketEventInfoMessage;
5993
+ }
5994
+ interface Resume {
5995
+ readonly type: "resume";
5996
+ readonly attachment?: any;
5997
+ }
5998
+ interface CustomEventInfo {
5999
+ readonly type: "custom";
6000
+ }
6001
+ interface FetchResponseInfo {
6002
+ readonly type: "fetch";
6003
+ readonly statusCode: number;
6004
+ }
6005
+ type EventOutcome =
6006
+ | "ok"
6007
+ | "canceled"
6008
+ | "exception"
6009
+ | "unknown"
6010
+ | "killSwitch"
6011
+ | "daemonDown"
6012
+ | "exceededCpu"
6013
+ | "exceededMemory"
6014
+ | "loadShed"
6015
+ | "responseStreamDisconnected"
6016
+ | "scriptNotFound";
6017
+ interface ScriptVersion {
6018
+ readonly id: string;
6019
+ readonly tag?: string;
6020
+ readonly message?: string;
6021
+ }
6022
+ interface Trigger {
6023
+ readonly traceId: string;
6024
+ readonly invocationId: string;
6025
+ readonly spanId: string;
6026
+ }
6027
+ interface Onset {
6028
+ readonly type: "onset";
6029
+ readonly dispatchNamespace?: string;
6030
+ readonly entrypoint?: string;
6031
+ readonly scriptName?: string;
6032
+ readonly scriptTags?: string[];
6033
+ readonly scriptVersion?: ScriptVersion;
6034
+ readonly trigger?: Trigger;
6035
+ readonly info:
6036
+ | FetchEventInfo
6037
+ | JsRpcEventInfo
6038
+ | ScheduledEventInfo
6039
+ | AlarmEventInfo
6040
+ | QueueEventInfo
6041
+ | EmailEventInfo
6042
+ | TraceEventInfo
6043
+ | HibernatableWebSocketEventInfo
6044
+ | Resume
6045
+ | CustomEventInfo;
6046
+ }
6047
+ interface Outcome {
6048
+ readonly type: "outcome";
6049
+ readonly outcome: EventOutcome;
6050
+ readonly cpuTime: number;
6051
+ readonly wallTime: number;
6052
+ }
6053
+ interface Hibernate {
6054
+ readonly type: "hibernate";
6055
+ }
6056
+ interface SpanOpen {
6057
+ readonly type: "spanOpen";
6058
+ readonly op?: string;
6059
+ readonly info?: FetchEventInfo | JsRpcEventInfo | Attribute[];
6060
+ }
6061
+ interface SpanClose {
6062
+ readonly type: "spanClose";
6063
+ readonly outcome: EventOutcome;
6064
+ }
6065
+ interface DiagnosticChannelEvent {
6066
+ readonly type: "diagnosticChannel";
6067
+ readonly channel: string;
6068
+ readonly message: any;
6069
+ }
6070
+ interface Exception {
6071
+ readonly type: "exception";
6072
+ readonly name: string;
6073
+ readonly message: string;
6074
+ readonly stack?: string;
6075
+ }
6076
+ interface Log {
6077
+ readonly type: "log";
6078
+ readonly level: "debug" | "error" | "info" | "log" | "warn";
6079
+ readonly message: string;
6080
+ }
6081
+ interface Return {
6082
+ readonly type: "return";
6083
+ readonly info?: FetchResponseInfo | Attribute[];
6084
+ }
6085
+ interface Link {
6086
+ readonly type: "link";
6087
+ readonly label?: string;
6088
+ readonly traceId: string;
6089
+ readonly invocationId: string;
6090
+ readonly spanId: string;
6091
+ }
6092
+ interface Attribute {
6093
+ readonly type: "attribute";
6094
+ readonly name: string;
6095
+ readonly value: string | string[] | boolean | boolean[] | number | number[];
6096
+ }
6097
+ type Mark =
6098
+ | DiagnosticChannelEvent
6099
+ | Exception
6100
+ | Log
6101
+ | Return
6102
+ | Link
6103
+ | Attribute[];
6104
+ interface TailEvent {
6105
+ readonly traceId: string;
6106
+ readonly invocationId: string;
6107
+ readonly spanId: string;
6108
+ readonly timestamp: Date;
6109
+ readonly sequence: number;
6110
+ readonly event: Onset | Outcome | Hibernate | SpanOpen | SpanClose | Mark;
6111
+ }
6112
+ type TailEventHandler = (event: TailEvent) => void | Promise<void>;
6113
+ type TailEventHandlerName =
6114
+ | "onset"
6115
+ | "outcome"
6116
+ | "hibernate"
6117
+ | "spanOpen"
6118
+ | "spanClose"
6119
+ | "diagnosticChannel"
6120
+ | "exception"
6121
+ | "log"
6122
+ | "return"
6123
+ | "link"
6124
+ | "attribute";
6125
+ type TailEventHandlerObject = Record<TailEventHandlerName, TailEventHandler>;
6126
+ type TailEventHandlerType = TailEventHandler | TailEventHandlerObject;
6127
+ }
5064
6128
  // Copyright (c) 2022-2023 Cloudflare, Inc.
5065
6129
  // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5066
6130
  // https://opensource.org/licenses/Apache-2.0
@@ -5104,11 +6168,21 @@ type VectorizeVectorMetadataFilter = {
5104
6168
  * Distance metrics determine how other "similar" vectors are determined.
5105
6169
  */
5106
6170
  type VectorizeDistanceMetric = "euclidean" | "cosine" | "dot-product";
6171
+ /**
6172
+ * Metadata return levels for a Vectorize query.
6173
+ *
6174
+ * Default to "none".
6175
+ *
6176
+ * @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.
6177
+ * @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).
6178
+ * @property none No indexed metadata will be returned.
6179
+ */
6180
+ type VectorizeMetadataRetrievalLevel = "all" | "indexed" | "none";
5107
6181
  interface VectorizeQueryOptions {
5108
6182
  topK?: number;
5109
6183
  namespace?: string;
5110
6184
  returnValues?: boolean;
5111
- returnMetadata?: boolean;
6185
+ returnMetadata?: boolean | VectorizeMetadataRetrievalLevel;
5112
6186
  filter?: VectorizeVectorMetadataFilter;
5113
6187
  }
5114
6188
  /**
@@ -5124,6 +6198,9 @@ type VectorizeIndexConfig =
5124
6198
  };
5125
6199
  /**
5126
6200
  * Metadata about an existing index.
6201
+ *
6202
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6203
+ * See {@link VectorizeIndexInfo} for its post-beta equivalent.
5127
6204
  */
5128
6205
  interface VectorizeIndexDetails {
5129
6206
  /** The unique ID of the index */
@@ -5137,6 +6214,19 @@ interface VectorizeIndexDetails {
5137
6214
  /** The number of records containing vectors within the index. */
5138
6215
  vectorsCount: number;
5139
6216
  }
6217
+ /**
6218
+ * Metadata about an existing index.
6219
+ */
6220
+ interface VectorizeIndexInfo {
6221
+ /** The number of records containing vectors within the index. */
6222
+ vectorCount: number;
6223
+ /** Number of dimensions the index has been configured for. */
6224
+ dimensions: number;
6225
+ /** ISO 8601 datetime of the last processed mutation on in the index. All changes before this mutation will be reflected in the index state. */
6226
+ processedUpToDatetime: number;
6227
+ /** UUIDv4 of the last mutation processed by the index. All changes before this mutation will be reflected in the index state. */
6228
+ processedUpToMutation: number;
6229
+ }
5140
6230
  /**
5141
6231
  * Represents a single vector value set along with its associated metadata.
5142
6232
  */
@@ -5147,7 +6237,7 @@ interface VectorizeVector {
5147
6237
  values: VectorFloatArray | number[];
5148
6238
  /** The namespace this vector belongs to. */
5149
6239
  namespace?: string;
5150
- /** Metadata associated with the vector. Includes the values of the other fields and potentially additional details. */
6240
+ /** Metadata associated with the vector. Includes the values of other fields and potentially additional details. */
5151
6241
  metadata?: Record<string, VectorizeVectorMetadata>;
5152
6242
  }
5153
6243
  /**
@@ -5159,7 +6249,7 @@ type VectorizeMatch = Pick<Partial<VectorizeVector>, "values"> &
5159
6249
  score: number;
5160
6250
  };
5161
6251
  /**
5162
- * A set of vector {@link VectorizeMatch} for a particular query.
6252
+ * A set of matching {@link VectorizeMatch} for a particular query.
5163
6253
  */
5164
6254
  interface VectorizeMatches {
5165
6255
  matches: VectorizeMatch[];
@@ -5168,6 +6258,9 @@ interface VectorizeMatches {
5168
6258
  /**
5169
6259
  * Results of an operation that performed a mutation on a set of vectors.
5170
6260
  * Here, `ids` is a list of vectors that were successfully processed.
6261
+ *
6262
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6263
+ * See {@link VectorizeAsyncMutation} for its post-beta equivalent.
5171
6264
  */
5172
6265
  interface VectorizeVectorMutation {
5173
6266
  /* List of ids of vectors that were successfully processed. */
@@ -5176,14 +6269,19 @@ interface VectorizeVectorMutation {
5176
6269
  count: number;
5177
6270
  }
5178
6271
  /**
5179
- * Results of an operation that performed a mutation on a set of vectors
5180
- * with the v2 version of Vectorize.
5181
- * Here, `mutationId` is the identifier for the last mutation processed by Vectorize.
6272
+ * Result type indicating a mutation on the Vectorize Index.
6273
+ * Actual mutations are processed async where the `mutationId` is the unique identifier for the operation.
5182
6274
  */
5183
- interface VectorizeVectorMutationV2 {
5184
- /* The identifier for the last mutation processed by Vectorize. */
6275
+ interface VectorizeAsyncMutation {
6276
+ /** The unique identifier for the async mutation operation containing the changeset. */
5185
6277
  mutationId: string;
5186
6278
  }
6279
+ /**
6280
+ * A Vectorize Vector Search Index for querying vectors/embeddings.
6281
+ *
6282
+ * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
6283
+ * See {@link Vectorize} for its new implementation.
6284
+ */
5187
6285
  declare abstract class VectorizeIndex {
5188
6286
  /**
5189
6287
  * Get information about the currently bound index.
@@ -5198,7 +6296,7 @@ declare abstract class VectorizeIndex {
5198
6296
  */
5199
6297
  public query(
5200
6298
  vector: VectorFloatArray | number[],
5201
- options: VectorizeQueryOptions,
6299
+ options?: VectorizeQueryOptions,
5202
6300
  ): Promise<VectorizeMatches>;
5203
6301
  /**
5204
6302
  * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
@@ -5225,6 +6323,62 @@ declare abstract class VectorizeIndex {
5225
6323
  */
5226
6324
  public getByIds(ids: string[]): Promise<VectorizeVector[]>;
5227
6325
  }
6326
+ /**
6327
+ * A Vectorize Vector Search Index for querying vectors/embeddings.
6328
+ *
6329
+ * Mutations in this version are async, returning a mutation id.
6330
+ */
6331
+ declare abstract class Vectorize {
6332
+ /**
6333
+ * Get information about the currently bound index.
6334
+ * @returns A promise that resolves with information about the current index.
6335
+ */
6336
+ public describe(): Promise<VectorizeIndexInfo>;
6337
+ /**
6338
+ * Use the provided vector to perform a similarity search across the index.
6339
+ * @param vector Input vector that will be used to drive the similarity search.
6340
+ * @param options Configuration options to massage the returned data.
6341
+ * @returns A promise that resolves with matched and scored vectors.
6342
+ */
6343
+ public query(
6344
+ vector: VectorFloatArray | number[],
6345
+ options?: VectorizeQueryOptions,
6346
+ ): Promise<VectorizeMatches>;
6347
+ /**
6348
+ * Use the provided vector-id to perform a similarity search across the index.
6349
+ * @param vectorId Id for a vector in the index against which the index should be queried.
6350
+ * @param options Configuration options to massage the returned data.
6351
+ * @returns A promise that resolves with matched and scored vectors.
6352
+ */
6353
+ public queryById(
6354
+ vectorId: string,
6355
+ options?: VectorizeQueryOptions,
6356
+ ): Promise<VectorizeMatches>;
6357
+ /**
6358
+ * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
6359
+ * @param vectors List of vectors that will be inserted.
6360
+ * @returns A promise that resolves with a unique identifier of a mutation containing the insert changeset.
6361
+ */
6362
+ public insert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>;
6363
+ /**
6364
+ * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values.
6365
+ * @param vectors List of vectors that will be upserted.
6366
+ * @returns A promise that resolves with a unique identifier of a mutation containing the upsert changeset.
6367
+ */
6368
+ public upsert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>;
6369
+ /**
6370
+ * Delete a list of vectors with a matching id.
6371
+ * @param ids List of vector ids that should be deleted.
6372
+ * @returns A promise that resolves with a unique identifier of a mutation containing the delete changeset.
6373
+ */
6374
+ public deleteByIds(ids: string[]): Promise<VectorizeAsyncMutation>;
6375
+ /**
6376
+ * Get a list of vectors with a matching id.
6377
+ * @param ids List of vector ids that should be returned.
6378
+ * @returns A promise that resolves with the raw unscored vectors matching the id set.
6379
+ */
6380
+ public getByIds(ids: string[]): Promise<VectorizeVector[]>;
6381
+ }
5228
6382
  /**
5229
6383
  * The interface for "version_metadata" binding
5230
6384
  * providing metadata about the Worker Version using this binding.
@@ -5275,3 +6429,79 @@ interface DispatchNamespace {
5275
6429
  options?: DynamicDispatchOptions,
5276
6430
  ): Fetcher;
5277
6431
  }
6432
+ declare module "cloudflare:workflows" {
6433
+ /**
6434
+ * NonRetryableError allows for a user to throw a fatal error
6435
+ * that makes a Workflow instance fail immediately without triggering a retry
6436
+ */
6437
+ export class NonRetryableError extends Error {
6438
+ public constructor(message: string, name?: string);
6439
+ }
6440
+ }
6441
+ declare abstract class Workflow<PARAMS = unknown> {
6442
+ /**
6443
+ * Get a handle to an existing instance of the Workflow.
6444
+ * @param id Id for the instance of this Workflow
6445
+ * @returns A promise that resolves with a handle for the Instance
6446
+ */
6447
+ public get(id: string): Promise<WorkflowInstance>;
6448
+ /**
6449
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
6450
+ * @param options Options when creating an instance including id and params
6451
+ * @returns A promise that resolves with a handle for the Instance
6452
+ */
6453
+ public create(
6454
+ options?: WorkflowInstanceCreateOptions<PARAMS>,
6455
+ ): Promise<WorkflowInstance>;
6456
+ }
6457
+ interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6458
+ /**
6459
+ * An id for your Workflow instance. Must be unique within the Workflow.
6460
+ */
6461
+ id?: string;
6462
+ /**
6463
+ * The event payload the Workflow instance is triggered with
6464
+ */
6465
+ params?: PARAMS;
6466
+ }
6467
+ type InstanceStatus = {
6468
+ status:
6469
+ | "queued" // means that instance is waiting to be started (see concurrency limits)
6470
+ | "running"
6471
+ | "paused"
6472
+ | "errored"
6473
+ | "terminated" // user terminated the instance while it was running
6474
+ | "complete"
6475
+ | "waiting" // instance is hibernating and waiting for sleep or event to finish
6476
+ | "waitingForPause" // instance is finishing the current work to pause
6477
+ | "unknown";
6478
+ error?: string;
6479
+ output?: object;
6480
+ };
6481
+ interface WorkflowError {
6482
+ code?: number;
6483
+ message: string;
6484
+ }
6485
+ declare abstract class WorkflowInstance {
6486
+ public id: string;
6487
+ /**
6488
+ * Pause the instance.
6489
+ */
6490
+ public pause(): Promise<void>;
6491
+ /**
6492
+ * Resume the instance. If it is already running, an error will be thrown.
6493
+ */
6494
+ public resume(): Promise<void>;
6495
+ /**
6496
+ * Terminate the instance. If it is errored, terminated or complete, an error will be thrown.
6497
+ */
6498
+ public terminate(): Promise<void>;
6499
+ /**
6500
+ * Restart the instance.
6501
+ */
6502
+ public restart(): Promise<void>;
6503
+ /**
6504
+ * Returns the current status of the instance.
6505
+ */
6506
+ public status(): Promise<InstanceStatus>;
6507
+ }