@workers-community/workers-types 4.20260131.0 → 4.20260317.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +1225 -36
  2. package/index.ts +1221 -35
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -477,54 +477,63 @@ interface ExecutionContext<Props = unknown> {
477
477
  passThroughOnException(): void;
478
478
  readonly props: Props;
479
479
  }
480
- type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
480
+ type ExportedHandlerFetchHandler<
481
+ Env = unknown,
482
+ CfHostMetadata = unknown,
483
+ Props = unknown,
484
+ > = (
481
485
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
482
486
  env: Env,
483
- ctx: ExecutionContext,
487
+ ctx: ExecutionContext<Props>,
484
488
  ) => Response | Promise<Response>;
485
- type ExportedHandlerTailHandler<Env = unknown> = (
489
+ type ExportedHandlerTailHandler<Env = unknown, Props = unknown> = (
486
490
  events: TraceItem[],
487
491
  env: Env,
488
- ctx: ExecutionContext,
492
+ ctx: ExecutionContext<Props>,
489
493
  ) => void | Promise<void>;
490
- type ExportedHandlerTraceHandler<Env = unknown> = (
494
+ type ExportedHandlerTraceHandler<Env = unknown, Props = unknown> = (
491
495
  traces: TraceItem[],
492
496
  env: Env,
493
- ctx: ExecutionContext,
497
+ ctx: ExecutionContext<Props>,
494
498
  ) => void | Promise<void>;
495
- type ExportedHandlerTailStreamHandler<Env = unknown> = (
499
+ type ExportedHandlerTailStreamHandler<Env = unknown, Props = unknown> = (
496
500
  event: TailStream.TailEvent<TailStream.Onset>,
497
501
  env: Env,
498
- ctx: ExecutionContext,
502
+ ctx: ExecutionContext<Props>,
499
503
  ) => TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>;
500
- type ExportedHandlerScheduledHandler<Env = unknown> = (
504
+ type ExportedHandlerScheduledHandler<Env = unknown, Props = unknown> = (
501
505
  controller: ScheduledController,
502
506
  env: Env,
503
- ctx: ExecutionContext,
507
+ ctx: ExecutionContext<Props>,
504
508
  ) => void | Promise<void>;
505
- type ExportedHandlerQueueHandler<Env = unknown, Message = unknown> = (
509
+ type ExportedHandlerQueueHandler<
510
+ Env = unknown,
511
+ Message = unknown,
512
+ Props = unknown,
513
+ > = (
506
514
  batch: MessageBatch<Message>,
507
515
  env: Env,
508
- ctx: ExecutionContext,
516
+ ctx: ExecutionContext<Props>,
509
517
  ) => void | Promise<void>;
510
- type ExportedHandlerTestHandler<Env = unknown> = (
518
+ type ExportedHandlerTestHandler<Env = unknown, Props = unknown> = (
511
519
  controller: TestController,
512
520
  env: Env,
513
- ctx: ExecutionContext,
521
+ ctx: ExecutionContext<Props>,
514
522
  ) => void | Promise<void>;
515
523
  interface ExportedHandler<
516
524
  Env = unknown,
517
525
  QueueHandlerMessage = unknown,
518
526
  CfHostMetadata = unknown,
527
+ Props = unknown,
519
528
  > {
520
- fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
521
- tail?: ExportedHandlerTailHandler<Env>;
522
- trace?: ExportedHandlerTraceHandler<Env>;
523
- tailStream?: ExportedHandlerTailStreamHandler<Env>;
524
- scheduled?: ExportedHandlerScheduledHandler<Env>;
525
- test?: ExportedHandlerTestHandler<Env>;
526
- email?: EmailExportedHandler<Env>;
527
- queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>;
529
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata, Props>;
530
+ tail?: ExportedHandlerTailHandler<Env, Props>;
531
+ trace?: ExportedHandlerTraceHandler<Env, Props>;
532
+ tailStream?: ExportedHandlerTailStreamHandler<Env, Props>;
533
+ scheduled?: ExportedHandlerScheduledHandler<Env, Props>;
534
+ test?: ExportedHandlerTestHandler<Env, Props>;
535
+ email?: EmailExportedHandler<Env, Props>;
536
+ queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage, Props>;
528
537
  }
529
538
  interface StructuredSerializeOptions {
530
539
  transfer?: any[];
@@ -3561,7 +3570,7 @@ declare var WebSocket: {
3561
3570
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
3562
3571
  */
3563
3572
  interface WebSocket extends EventTarget<WebSocketEventMap> {
3564
- accept(): void;
3573
+ accept(options?: WebSocketAcceptOptions): void;
3565
3574
  /**
3566
3575
  * The **`WebSocket.send()`** method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of `bufferedAmount` by the number of bytes needed to contain the data.
3567
3576
  *
@@ -3600,6 +3609,22 @@ interface WebSocket extends EventTarget<WebSocketEventMap> {
3600
3609
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
3601
3610
  */
3602
3611
  extensions: string | null;
3612
+ /**
3613
+ * The **`WebSocket.binaryType`** property controls the type of binary data being received over the WebSocket connection.
3614
+ *
3615
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
3616
+ */
3617
+ binaryType: "blob" | "arraybuffer";
3618
+ }
3619
+ interface WebSocketAcceptOptions {
3620
+ /**
3621
+ * When set to `true`, receiving a server-initiated WebSocket Close frame will not
3622
+ * automatically send a reciprocal Close frame, leaving the connection in a half-open
3623
+ * state. This is useful for proxying scenarios where you need to coordinate closing
3624
+ * both sides independently. Defaults to `false` when the
3625
+ * `no_web_socket_half_open_by_default` compatibility flag is enabled.
3626
+ */
3627
+ allowHalfOpen?: boolean;
3603
3628
  }
3604
3629
  declare const WebSocketPair: {
3605
3630
  new (): {
@@ -3724,6 +3749,8 @@ interface Container {
3724
3749
  signal(signo: number): void;
3725
3750
  getTcpPort(port: number): Fetcher;
3726
3751
  setInactivityTimeout(durationMs: number | bigint): Promise<void>;
3752
+ interceptOutboundHttp(addr: string, binding: Fetcher): Promise<void>;
3753
+ interceptAllOutboundHttp(binding: Fetcher): Promise<void>;
3727
3754
  }
3728
3755
  interface ContainerStartupOptions {
3729
3756
  entrypoint?: string[];
@@ -3736,7 +3763,7 @@ interface ContainerStartupOptions {
3736
3763
  *
3737
3764
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessagePort)
3738
3765
  */
3739
- interface MessagePort extends EventTarget {
3766
+ declare abstract class MessagePort extends EventTarget {
3740
3767
  /**
3741
3768
  * The **`postMessage()`** method of the transfers ownership of objects to other browsing contexts.
3742
3769
  *
@@ -3816,6 +3843,7 @@ interface WorkerLoader {
3816
3843
  name: string | null,
3817
3844
  getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3818
3845
  ): WorkerStub;
3846
+ load(code: WorkerLoaderWorkerCode): WorkerStub;
3819
3847
  }
3820
3848
  interface WorkerLoaderModule {
3821
3849
  js?: string;
@@ -3848,6 +3876,180 @@ declare abstract class Performance {
3848
3876
  get timeOrigin(): number;
3849
3877
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3850
3878
  now(): number;
3879
+ /**
3880
+ * The **`toJSON()`** method of the Performance interface is a Serialization; it returns a JSON representation of the Performance object.
3881
+ *
3882
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/toJSON)
3883
+ */
3884
+ toJSON(): object;
3885
+ }
3886
+ // AI Search V2 API Error Interfaces
3887
+ interface AiSearchInternalError extends Error {}
3888
+ interface AiSearchNotFoundError extends Error {}
3889
+ interface AiSearchNameNotSetError extends Error {}
3890
+ // AI Search V2 Request Types
3891
+ type AiSearchSearchRequest = {
3892
+ messages: Array<{
3893
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3894
+ content: string | null;
3895
+ }>;
3896
+ ai_search_options?: {
3897
+ retrieval?: {
3898
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3899
+ /** Match threshold (0-1, default 0.4) */
3900
+ match_threshold?: number;
3901
+ /** Maximum number of results (1-50, default 10) */
3902
+ max_num_results?: number;
3903
+ filters?: VectorizeVectorMetadataFilter;
3904
+ /** Context expansion (0-3, default 0) */
3905
+ context_expansion?: number;
3906
+ [key: string]: unknown;
3907
+ };
3908
+ query_rewrite?: {
3909
+ enabled?: boolean;
3910
+ model?: string;
3911
+ rewrite_prompt?: string;
3912
+ [key: string]: unknown;
3913
+ };
3914
+ reranking?: {
3915
+ /** Enable reranking (default false) */
3916
+ enabled?: boolean;
3917
+ model?: "@cf/baai/bge-reranker-base" | "";
3918
+ /** Match threshold (0-1, default 0.4) */
3919
+ match_threshold?: number;
3920
+ [key: string]: unknown;
3921
+ };
3922
+ [key: string]: unknown;
3923
+ };
3924
+ };
3925
+ type AiSearchChatCompletionsRequest = {
3926
+ messages: Array<{
3927
+ role: "system" | "developer" | "user" | "assistant" | "tool";
3928
+ content: string | null;
3929
+ }>;
3930
+ model?: string;
3931
+ stream?: boolean;
3932
+ ai_search_options?: {
3933
+ retrieval?: {
3934
+ retrieval_type?: "vector" | "keyword" | "hybrid";
3935
+ match_threshold?: number;
3936
+ max_num_results?: number;
3937
+ filters?: VectorizeVectorMetadataFilter;
3938
+ context_expansion?: number;
3939
+ [key: string]: unknown;
3940
+ };
3941
+ query_rewrite?: {
3942
+ enabled?: boolean;
3943
+ model?: string;
3944
+ rewrite_prompt?: string;
3945
+ [key: string]: unknown;
3946
+ };
3947
+ reranking?: {
3948
+ enabled?: boolean;
3949
+ model?: "@cf/baai/bge-reranker-base" | "";
3950
+ match_threshold?: number;
3951
+ [key: string]: unknown;
3952
+ };
3953
+ [key: string]: unknown;
3954
+ };
3955
+ [key: string]: unknown;
3956
+ };
3957
+ // AI Search V2 Response Types
3958
+ type AiSearchSearchResponse = {
3959
+ search_query: string;
3960
+ chunks: Array<{
3961
+ id: string;
3962
+ type: string;
3963
+ /** Match score (0-1) */
3964
+ score: number;
3965
+ text: string;
3966
+ item: {
3967
+ timestamp?: number;
3968
+ key: string;
3969
+ metadata?: Record<string, unknown>;
3970
+ };
3971
+ scoring_details?: {
3972
+ /** Keyword match score (0-1) */
3973
+ keyword_score?: number;
3974
+ /** Vector similarity score (0-1) */
3975
+ vector_score?: number;
3976
+ };
3977
+ }>;
3978
+ };
3979
+ type AiSearchListResponse = Array<{
3980
+ id: string;
3981
+ internal_id?: string;
3982
+ account_id?: string;
3983
+ account_tag?: string;
3984
+ /** Whether the instance is enabled (default true) */
3985
+ enable?: boolean;
3986
+ type?: "r2" | "web-crawler";
3987
+ source?: string;
3988
+ [key: string]: unknown;
3989
+ }>;
3990
+ type AiSearchConfig = {
3991
+ /** Instance ID (1-32 chars, pattern: ^[a-z0-9_]+(?:-[a-z0-9_]+)*$) */
3992
+ id: string;
3993
+ type: "r2" | "web-crawler";
3994
+ source: string;
3995
+ source_params?: object;
3996
+ /** Token ID (UUID format) */
3997
+ token_id?: string;
3998
+ ai_gateway_id?: string;
3999
+ /** Enable query rewriting (default false) */
4000
+ rewrite_query?: boolean;
4001
+ /** Enable reranking (default false) */
4002
+ reranking?: boolean;
4003
+ embedding_model?: string;
4004
+ ai_search_model?: string;
4005
+ };
4006
+ type AiSearchInstance = {
4007
+ id: string;
4008
+ enable?: boolean;
4009
+ type?: "r2" | "web-crawler";
4010
+ source?: string;
4011
+ [key: string]: unknown;
4012
+ };
4013
+ // AI Search Instance Service - Instance-level operations
4014
+ declare abstract class AiSearchInstanceService {
4015
+ /**
4016
+ * Search the AI Search instance for relevant chunks.
4017
+ * @param params Search request with messages and AI search options
4018
+ * @returns Search response with matching chunks
4019
+ */
4020
+ search(params: AiSearchSearchRequest): Promise<AiSearchSearchResponse>;
4021
+ /**
4022
+ * Generate chat completions with AI Search context.
4023
+ * @param params Chat completions request with optional streaming
4024
+ * @returns Response object (if streaming) or chat completion result
4025
+ */
4026
+ chatCompletions(
4027
+ params: AiSearchChatCompletionsRequest,
4028
+ ): Promise<Response | object>;
4029
+ /**
4030
+ * Delete this AI Search instance.
4031
+ */
4032
+ delete(): Promise<void>;
4033
+ }
4034
+ // AI Search Account Service - Account-level operations
4035
+ declare abstract class AiSearchAccountService {
4036
+ /**
4037
+ * List all AI Search instances in the account.
4038
+ * @returns Array of AI Search instances
4039
+ */
4040
+ list(): Promise<AiSearchListResponse>;
4041
+ /**
4042
+ * Get an AI Search instance by ID.
4043
+ * @param name Instance ID
4044
+ * @returns Instance service for performing operations
4045
+ */
4046
+ get(name: string): AiSearchInstanceService;
4047
+ /**
4048
+ * Create a new AI Search instance.
4049
+ * @param config Instance configuration
4050
+ * @returns Instance service for performing operations
4051
+ */
4052
+ create(config: AiSearchConfig): Promise<AiSearchInstanceService>;
3851
4053
  }
3852
4054
  type AiImageClassificationInput = {
3853
4055
  image: number[];
@@ -9346,6 +9548,48 @@ type AiModelListType = Record<string, any>;
9346
9548
  declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
9347
9549
  aiGatewayLogId: string | null;
9348
9550
  gateway(gatewayId: string): AiGateway;
9551
+ /**
9552
+ * Access the AI Search API for managing AI-powered search instances.
9553
+ *
9554
+ * This is the new API that replaces AutoRAG with better namespace separation:
9555
+ * - Account-level operations: `list()`, `create()`
9556
+ * - Instance-level operations: `get(id).search()`, `get(id).chatCompletions()`, `get(id).delete()`
9557
+ *
9558
+ * @example
9559
+ * ```typescript
9560
+ * // List all AI Search instances
9561
+ * const instances = await env.AI.aiSearch.list();
9562
+ *
9563
+ * // Search an instance
9564
+ * const results = await env.AI.aiSearch.get('my-search').search({
9565
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9566
+ * ai_search_options: {
9567
+ * retrieval: { max_num_results: 10 }
9568
+ * }
9569
+ * });
9570
+ *
9571
+ * // Generate chat completions with AI Search context
9572
+ * const response = await env.AI.aiSearch.get('my-search').chatCompletions({
9573
+ * messages: [{ role: 'user', content: 'What is the policy?' }],
9574
+ * model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast'
9575
+ * });
9576
+ * ```
9577
+ */
9578
+ aiSearch(): AiSearchAccountService;
9579
+ /**
9580
+ * @deprecated AutoRAG has been replaced by AI Search.
9581
+ * Use `env.AI.aiSearch` instead for better API design and new features.
9582
+ *
9583
+ * Migration guide:
9584
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9585
+ * - `env.AI.autorag('id').search({ query: '...' })` → `env.AI.aiSearch.get('id').search({ messages: [{ role: 'user', content: '...' }] })`
9586
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9587
+ *
9588
+ * Note: The old API continues to work for backwards compatibility, but new projects should use AI Search.
9589
+ *
9590
+ * @see AiSearchAccountService
9591
+ * @param autoragId Optional instance ID (omit for account-level operations)
9592
+ */
9349
9593
  autorag(autoragId: string): AutoRAG;
9350
9594
  run<
9351
9595
  Name extends keyof AiModelList,
@@ -9502,9 +9746,24 @@ declare abstract class AiGateway {
9502
9746
  ): Promise<Response>;
9503
9747
  getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
9504
9748
  }
9749
+ /**
9750
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchInternalError instead.
9751
+ * @see AiSearchInternalError
9752
+ */
9505
9753
  interface AutoRAGInternalError extends Error {}
9754
+ /**
9755
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNotFoundError instead.
9756
+ * @see AiSearchNotFoundError
9757
+ */
9506
9758
  interface AutoRAGNotFoundError extends Error {}
9759
+ /**
9760
+ * @deprecated This error type is no longer used in the AI Search API.
9761
+ */
9507
9762
  interface AutoRAGUnauthorizedError extends Error {}
9763
+ /**
9764
+ * @deprecated AutoRAG has been replaced by AI Search. Use AiSearchNameNotSetError instead.
9765
+ * @see AiSearchNameNotSetError
9766
+ */
9508
9767
  interface AutoRAGNameNotSetError extends Error {}
9509
9768
  type ComparisonFilter = {
9510
9769
  key: string;
@@ -9515,6 +9774,11 @@ type CompoundFilter = {
9515
9774
  type: "and" | "or";
9516
9775
  filters: ComparisonFilter[];
9517
9776
  };
9777
+ /**
9778
+ * @deprecated AutoRAG has been replaced by AI Search.
9779
+ * Use AiSearchSearchRequest with the new API instead.
9780
+ * @see AiSearchSearchRequest
9781
+ */
9518
9782
  type AutoRagSearchRequest = {
9519
9783
  query: string;
9520
9784
  filters?: CompoundFilter | ComparisonFilter;
@@ -9529,16 +9793,31 @@ type AutoRagSearchRequest = {
9529
9793
  };
9530
9794
  rewrite_query?: boolean;
9531
9795
  };
9796
+ /**
9797
+ * @deprecated AutoRAG has been replaced by AI Search.
9798
+ * Use AiSearchChatCompletionsRequest with the new API instead.
9799
+ * @see AiSearchChatCompletionsRequest
9800
+ */
9532
9801
  type AutoRagAiSearchRequest = AutoRagSearchRequest & {
9533
9802
  stream?: boolean;
9534
9803
  system_prompt?: string;
9535
9804
  };
9805
+ /**
9806
+ * @deprecated AutoRAG has been replaced by AI Search.
9807
+ * Use AiSearchChatCompletionsRequest with stream: true instead.
9808
+ * @see AiSearchChatCompletionsRequest
9809
+ */
9536
9810
  type AutoRagAiSearchRequestStreaming = Omit<
9537
9811
  AutoRagAiSearchRequest,
9538
9812
  "stream"
9539
9813
  > & {
9540
9814
  stream: true;
9541
9815
  };
9816
+ /**
9817
+ * @deprecated AutoRAG has been replaced by AI Search.
9818
+ * Use AiSearchSearchResponse with the new API instead.
9819
+ * @see AiSearchSearchResponse
9820
+ */
9542
9821
  type AutoRagSearchResponse = {
9543
9822
  object: "vector_store.search_results.page";
9544
9823
  search_query: string;
@@ -9555,6 +9834,11 @@ type AutoRagSearchResponse = {
9555
9834
  has_more: boolean;
9556
9835
  next_page: string | null;
9557
9836
  };
9837
+ /**
9838
+ * @deprecated AutoRAG has been replaced by AI Search.
9839
+ * Use AiSearchListResponse with the new API instead.
9840
+ * @see AiSearchListResponse
9841
+ */
9558
9842
  type AutoRagListResponse = {
9559
9843
  id: string;
9560
9844
  enable: boolean;
@@ -9564,14 +9848,51 @@ type AutoRagListResponse = {
9564
9848
  paused: boolean;
9565
9849
  status: string;
9566
9850
  }[];
9851
+ /**
9852
+ * @deprecated AutoRAG has been replaced by AI Search.
9853
+ * The new API returns different response formats for chat completions.
9854
+ */
9567
9855
  type AutoRagAiSearchResponse = AutoRagSearchResponse & {
9568
9856
  response: string;
9569
9857
  };
9858
+ /**
9859
+ * @deprecated AutoRAG has been replaced by AI Search.
9860
+ * Use the new AI Search API instead: `env.AI.aiSearch`
9861
+ *
9862
+ * Migration guide:
9863
+ * - `env.AI.autorag().list()` → `env.AI.aiSearch.list()`
9864
+ * - `env.AI.autorag('id').search(...)` → `env.AI.aiSearch.get('id').search(...)`
9865
+ * - `env.AI.autorag('id').aiSearch(...)` → `env.AI.aiSearch.get('id').chatCompletions(...)`
9866
+ *
9867
+ * @see AiSearchAccountService
9868
+ * @see AiSearchInstanceService
9869
+ */
9570
9870
  declare abstract class AutoRAG {
9871
+ /**
9872
+ * @deprecated Use `env.AI.aiSearch.list()` instead.
9873
+ * @see AiSearchAccountService.list
9874
+ */
9571
9875
  list(): Promise<AutoRagListResponse>;
9876
+ /**
9877
+ * @deprecated Use `env.AI.aiSearch.get(id).search(...)` instead.
9878
+ * Note: The new API uses a messages array instead of a query string.
9879
+ * @see AiSearchInstanceService.search
9880
+ */
9572
9881
  search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
9882
+ /**
9883
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9884
+ * @see AiSearchInstanceService.chatCompletions
9885
+ */
9573
9886
  aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
9887
+ /**
9888
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9889
+ * @see AiSearchInstanceService.chatCompletions
9890
+ */
9574
9891
  aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
9892
+ /**
9893
+ * @deprecated Use `env.AI.aiSearch.get(id).chatCompletions(...)` instead.
9894
+ * @see AiSearchInstanceService.chatCompletions
9895
+ */
9575
9896
  aiSearch(
9576
9897
  params: AutoRagAiSearchRequest,
9577
9898
  ): Promise<AutoRagAiSearchResponse | Response>;
@@ -10799,10 +11120,10 @@ interface SendEmail {
10799
11120
  declare abstract class EmailEvent extends ExtendableEvent {
10800
11121
  readonly message: ForwardableEmailMessage;
10801
11122
  }
10802
- declare type EmailExportedHandler<Env = unknown> = (
11123
+ declare type EmailExportedHandler<Env = unknown, Props = unknown> = (
10803
11124
  message: ForwardableEmailMessage,
10804
11125
  env: Env,
10805
- ctx: ExecutionContext,
11126
+ ctx: ExecutionContext<Props>,
10806
11127
  ) => void | Promise<void>;
10807
11128
  declare module "cloudflare:email" {
10808
11129
  let _EmailMessage: {
@@ -10968,6 +11289,86 @@ type ImageOutputOptions = {
10968
11289
  background?: string;
10969
11290
  anim?: boolean;
10970
11291
  };
11292
+ interface ImageMetadata {
11293
+ id: string;
11294
+ filename?: string;
11295
+ uploaded?: string;
11296
+ requireSignedURLs: boolean;
11297
+ meta?: Record<string, unknown>;
11298
+ variants: string[];
11299
+ draft?: boolean;
11300
+ creator?: string;
11301
+ }
11302
+ interface ImageUploadOptions {
11303
+ id?: string;
11304
+ filename?: string;
11305
+ requireSignedURLs?: boolean;
11306
+ metadata?: Record<string, unknown>;
11307
+ creator?: string;
11308
+ encoding?: "base64";
11309
+ }
11310
+ interface ImageUpdateOptions {
11311
+ requireSignedURLs?: boolean;
11312
+ metadata?: Record<string, unknown>;
11313
+ creator?: string;
11314
+ }
11315
+ interface ImageListOptions {
11316
+ limit?: number;
11317
+ cursor?: string;
11318
+ sortOrder?: "asc" | "desc";
11319
+ creator?: string;
11320
+ }
11321
+ interface ImageList {
11322
+ images: ImageMetadata[];
11323
+ cursor?: string;
11324
+ listComplete: boolean;
11325
+ }
11326
+ interface HostedImagesBinding {
11327
+ /**
11328
+ * Get detailed metadata for a hosted image
11329
+ * @param imageId The ID of the image (UUID or custom ID)
11330
+ * @returns Image metadata, or null if not found
11331
+ */
11332
+ details(imageId: string): Promise<ImageMetadata | null>;
11333
+ /**
11334
+ * Get the raw image data for a hosted image
11335
+ * @param imageId The ID of the image (UUID or custom ID)
11336
+ * @returns ReadableStream of image bytes, or null if not found
11337
+ */
11338
+ image(imageId: string): Promise<ReadableStream<Uint8Array> | null>;
11339
+ /**
11340
+ * Upload a new hosted image
11341
+ * @param image The image file to upload
11342
+ * @param options Upload configuration
11343
+ * @returns Metadata for the uploaded image
11344
+ * @throws {@link ImagesError} if upload fails
11345
+ */
11346
+ upload(
11347
+ image: ReadableStream<Uint8Array> | ArrayBuffer,
11348
+ options?: ImageUploadOptions,
11349
+ ): Promise<ImageMetadata>;
11350
+ /**
11351
+ * Update hosted image metadata
11352
+ * @param imageId The ID of the image
11353
+ * @param options Properties to update
11354
+ * @returns Updated image metadata
11355
+ * @throws {@link ImagesError} if update fails
11356
+ */
11357
+ update(imageId: string, options: ImageUpdateOptions): Promise<ImageMetadata>;
11358
+ /**
11359
+ * Delete a hosted image
11360
+ * @param imageId The ID of the image
11361
+ * @returns True if deleted, false if not found
11362
+ */
11363
+ delete(imageId: string): Promise<boolean>;
11364
+ /**
11365
+ * List hosted images with pagination
11366
+ * @param options List configuration
11367
+ * @returns List of images with pagination info
11368
+ * @throws {@link ImagesError} if list fails
11369
+ */
11370
+ list(options?: ImageListOptions): Promise<ImageList>;
11371
+ }
10971
11372
  interface ImagesBinding {
10972
11373
  /**
10973
11374
  * Get image metadata (type, width and height)
@@ -10987,6 +11388,10 @@ interface ImagesBinding {
10987
11388
  stream: ReadableStream<Uint8Array>,
10988
11389
  options?: ImageInputOptions,
10989
11390
  ): ImageTransformer;
11391
+ /**
11392
+ * Access hosted images CRUD operations
11393
+ */
11394
+ readonly hosted: HostedImagesBinding;
10990
11395
  }
10991
11396
  interface ImageTransformer {
10992
11397
  /**
@@ -11057,8 +11462,14 @@ interface MediaTransformer {
11057
11462
  * @returns A generator for producing the transformed media output
11058
11463
  */
11059
11464
  transform(
11060
- transform: MediaTransformationInputOptions,
11465
+ transform?: MediaTransformationInputOptions,
11061
11466
  ): MediaTransformationGenerator;
11467
+ /**
11468
+ * Generates the final media output with specified options.
11469
+ * @param output - Configuration for the output format and parameters
11470
+ * @returns The final transformation result containing the transformed media
11471
+ */
11472
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11062
11473
  }
11063
11474
  /**
11064
11475
  * Generator for producing media transformation results.
@@ -11070,7 +11481,7 @@ interface MediaTransformationGenerator {
11070
11481
  * @param output - Configuration for the output format and parameters
11071
11482
  * @returns The final transformation result containing the transformed media
11072
11483
  */
11073
- output(output: MediaTransformationOutputOptions): MediaTransformationResult;
11484
+ output(output?: MediaTransformationOutputOptions): MediaTransformationResult;
11074
11485
  }
11075
11486
  /**
11076
11487
  * Result of a media transformation operation.
@@ -11079,19 +11490,19 @@ interface MediaTransformationGenerator {
11079
11490
  interface MediaTransformationResult {
11080
11491
  /**
11081
11492
  * Returns the transformed media as a readable stream of bytes.
11082
- * @returns A stream containing the transformed media data
11493
+ * @returns A promise containing a readable stream with the transformed media
11083
11494
  */
11084
- media(): ReadableStream<Uint8Array>;
11495
+ media(): Promise<ReadableStream<Uint8Array>>;
11085
11496
  /**
11086
11497
  * Returns the transformed media as an HTTP response object.
11087
- * @returns The transformed media as a Response, ready to store in cache or return to users
11498
+ * @returns The transformed media as a Promise<Response>, ready to store in cache or return to users
11088
11499
  */
11089
- response(): Response;
11500
+ response(): Promise<Response>;
11090
11501
  /**
11091
11502
  * Returns the MIME type of the transformed media.
11092
- * @returns The content type string (e.g., 'image/jpeg', 'video/mp4')
11503
+ * @returns A promise containing the content type string (e.g., 'image/jpeg', 'video/mp4')
11093
11504
  */
11094
- contentType(): string;
11505
+ contentType(): Promise<string>;
11095
11506
  }
11096
11507
  /**
11097
11508
  * Configuration options for transforming media input.
@@ -11582,15 +11993,18 @@ declare namespace CloudflareWorkersModule {
11582
11993
  timestamp: Date;
11583
11994
  type: string;
11584
11995
  };
11996
+ export type WorkflowStepContext = {
11997
+ attempt: number;
11998
+ };
11585
11999
  export abstract class WorkflowStep {
11586
12000
  do<T extends Rpc.Serializable<T>>(
11587
12001
  name: string,
11588
- callback: () => Promise<T>,
12002
+ callback: (ctx: WorkflowStepContext) => Promise<T>,
11589
12003
  ): Promise<T>;
11590
12004
  do<T extends Rpc.Serializable<T>>(
11591
12005
  name: string,
11592
12006
  config: WorkflowStepConfig,
11593
- callback: () => Promise<T>,
12007
+ callback: (ctx: WorkflowStepContext) => Promise<T>,
11594
12008
  ): Promise<T>;
11595
12009
  sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
11596
12010
  sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
@@ -11602,6 +12016,16 @@ declare namespace CloudflareWorkersModule {
11602
12016
  },
11603
12017
  ): Promise<WorkflowStepEvent<T>>;
11604
12018
  }
12019
+ export type WorkflowInstanceStatus =
12020
+ | "queued"
12021
+ | "running"
12022
+ | "paused"
12023
+ | "errored"
12024
+ | "terminated"
12025
+ | "complete"
12026
+ | "waiting"
12027
+ | "waitingForPause"
12028
+ | "unknown";
11605
12029
  export abstract class WorkflowEntrypoint<
11606
12030
  Env = unknown,
11607
12031
  T extends Rpc.Serializable<T> | unknown = unknown,
@@ -11645,12 +12069,774 @@ declare module "cloudflare:sockets" {
11645
12069
  ): Socket;
11646
12070
  export { _connect as connect };
11647
12071
  }
12072
+ /**
12073
+ * Binding entrypoint for Cloudflare Stream.
12074
+ *
12075
+ * Usage:
12076
+ * - Binding-level operations:
12077
+ * `await env.STREAM.videos.upload`
12078
+ * `await env.STREAM.videos.createDirectUpload`
12079
+ * `await env.STREAM.videos.*`
12080
+ * `await env.STREAM.watermarks.*`
12081
+ * - Per-video operations:
12082
+ * `await env.STREAM.video(id).downloads.*`
12083
+ * `await env.STREAM.video(id).captions.*`
12084
+ *
12085
+ * Example usage:
12086
+ * ```ts
12087
+ * await env.STREAM.video(id).downloads.generate();
12088
+ *
12089
+ * const video = env.STREAM.video(id)
12090
+ * const captions = video.captions.list();
12091
+ * const videoDetails = video.details()
12092
+ * ```
12093
+ */
12094
+ interface StreamBinding {
12095
+ /**
12096
+ * Returns a handle scoped to a single video for per-video operations.
12097
+ * @param id The unique identifier for the video.
12098
+ * @returns A handle for per-video operations.
12099
+ */
12100
+ video(id: string): StreamVideoHandle;
12101
+ /**
12102
+ * Uploads a new video from a File.
12103
+ * @param file The video file to upload.
12104
+ * @returns The uploaded video details.
12105
+ * @throws {BadRequestError} if the upload parameter is invalid
12106
+ * @throws {QuotaReachedError} if the account storage capacity is exceeded
12107
+ * @throws {MaxFileSizeError} if the file size is too large
12108
+ * @throws {RateLimitedError} if the server received too many requests
12109
+ * @throws {InternalError} if an unexpected error occurs
12110
+ */
12111
+ upload(file: File): Promise<StreamVideo>;
12112
+ /**
12113
+ * Uploads a new video from a provided URL.
12114
+ * @param url The URL to upload from.
12115
+ * @param params Optional upload parameters.
12116
+ * @returns The uploaded video details.
12117
+ * @throws {BadRequestError} if the upload parameter is invalid or the URL is invalid
12118
+ * @throws {QuotaReachedError} if the account storage capacity is exceeded
12119
+ * @throws {MaxFileSizeError} if the file size is too large
12120
+ * @throws {RateLimitedError} if the server received too many requests
12121
+ * @throws {AlreadyUploadedError} if a video was already uploaded to this URL
12122
+ * @throws {InternalError} if an unexpected error occurs
12123
+ */
12124
+ upload(url: string, params?: StreamUrlUploadParams): Promise<StreamVideo>;
12125
+ /**
12126
+ * Creates a direct upload that allows video uploads without an API key.
12127
+ * @param params Parameters for the direct upload
12128
+ * @returns The direct upload details.
12129
+ * @throws {BadRequestError} if the parameters are invalid
12130
+ * @throws {RateLimitedError} if the server received too many requests
12131
+ * @throws {InternalError} if an unexpected error occurs
12132
+ */
12133
+ createDirectUpload(
12134
+ params: StreamDirectUploadCreateParams,
12135
+ ): Promise<StreamDirectUpload>;
12136
+ videos: StreamVideos;
12137
+ watermarks: StreamWatermarks;
12138
+ }
12139
+ /**
12140
+ * Handle for operations scoped to a single Stream video.
12141
+ */
12142
+ interface StreamVideoHandle {
12143
+ /**
12144
+ * The unique identifier for the video.
12145
+ */
12146
+ id: string;
12147
+ /**
12148
+ * Get a full videos details
12149
+ * @returns The full video details.
12150
+ * @throws {NotFoundError} if the video is not found
12151
+ * @throws {InternalError} if an unexpected error occurs
12152
+ */
12153
+ details(): Promise<StreamVideo>;
12154
+ /**
12155
+ * Update details for a single video.
12156
+ * @param params The fields to update for the video.
12157
+ * @returns The updated video details.
12158
+ * @throws {NotFoundError} if the video is not found
12159
+ * @throws {BadRequestError} if the parameters are invalid
12160
+ * @throws {InternalError} if an unexpected error occurs
12161
+ */
12162
+ update(params: StreamUpdateVideoParams): Promise<StreamVideo>;
12163
+ /**
12164
+ * Deletes a video and its copies from Cloudflare Stream.
12165
+ * @returns A promise that resolves when deletion completes.
12166
+ * @throws {NotFoundError} if the video is not found
12167
+ * @throws {InternalError} if an unexpected error occurs
12168
+ */
12169
+ delete(): Promise<void>;
12170
+ /**
12171
+ * Creates a signed URL token for a video.
12172
+ * @returns The signed token that was created.
12173
+ * @throws {InternalError} if the signing key cannot be retrieved or the token cannot be signed
12174
+ */
12175
+ generateToken(): Promise<string>;
12176
+ downloads: StreamScopedDownloads;
12177
+ captions: StreamScopedCaptions;
12178
+ }
12179
+ interface StreamVideo {
12180
+ /**
12181
+ * The unique identifier for the video.
12182
+ */
12183
+ id: string;
12184
+ /**
12185
+ * A user-defined identifier for the media creator.
12186
+ */
12187
+ creator: string | null;
12188
+ /**
12189
+ * The thumbnail URL for the video.
12190
+ */
12191
+ thumbnail: string;
12192
+ /**
12193
+ * The thumbnail timestamp percentage.
12194
+ */
12195
+ thumbnailTimestampPct: number;
12196
+ /**
12197
+ * Indicates whether the video is ready to stream.
12198
+ */
12199
+ readyToStream: boolean;
12200
+ /**
12201
+ * The date and time the video became ready to stream.
12202
+ */
12203
+ readyToStreamAt: string | null;
12204
+ /**
12205
+ * Processing status information.
12206
+ */
12207
+ status: StreamVideoStatus;
12208
+ /**
12209
+ * A user modifiable key-value store.
12210
+ */
12211
+ meta: Record<string, string>;
12212
+ /**
12213
+ * The date and time the video was created.
12214
+ */
12215
+ created: string;
12216
+ /**
12217
+ * The date and time the video was last modified.
12218
+ */
12219
+ modified: string;
12220
+ /**
12221
+ * The date and time at which the video will be deleted.
12222
+ */
12223
+ scheduledDeletion: string | null;
12224
+ /**
12225
+ * The size of the video in bytes.
12226
+ */
12227
+ size: number;
12228
+ /**
12229
+ * The preview URL for the video.
12230
+ */
12231
+ preview?: string;
12232
+ /**
12233
+ * Origins allowed to display the video.
12234
+ */
12235
+ allowedOrigins: Array<string>;
12236
+ /**
12237
+ * Indicates whether signed URLs are required.
12238
+ */
12239
+ requireSignedURLs: boolean | null;
12240
+ /**
12241
+ * The date and time the video was uploaded.
12242
+ */
12243
+ uploaded: string | null;
12244
+ /**
12245
+ * The date and time when the upload URL expires.
12246
+ */
12247
+ uploadExpiry: string | null;
12248
+ /**
12249
+ * The maximum size in bytes for direct uploads.
12250
+ */
12251
+ maxSizeBytes: number | null;
12252
+ /**
12253
+ * The maximum duration in seconds for direct uploads.
12254
+ */
12255
+ maxDurationSeconds: number | null;
12256
+ /**
12257
+ * The video duration in seconds. -1 indicates unknown.
12258
+ */
12259
+ duration: number;
12260
+ /**
12261
+ * Input metadata for the original upload.
12262
+ */
12263
+ input: StreamVideoInput;
12264
+ /**
12265
+ * Playback URLs for the video.
12266
+ */
12267
+ hlsPlaybackUrl: string;
12268
+ dashPlaybackUrl: string;
12269
+ /**
12270
+ * The watermark applied to the video, if any.
12271
+ */
12272
+ watermark: StreamWatermark | null;
12273
+ /**
12274
+ * The live input id associated with the video, if any.
12275
+ */
12276
+ liveInputId?: string | null;
12277
+ /**
12278
+ * The source video id if this is a clip.
12279
+ */
12280
+ clippedFromId: string | null;
12281
+ /**
12282
+ * Public details associated with the video.
12283
+ */
12284
+ publicDetails: StreamPublicDetails | null;
12285
+ }
12286
+ type StreamVideoStatus = {
12287
+ /**
12288
+ * The current processing state.
12289
+ */
12290
+ state: string;
12291
+ /**
12292
+ * The current processing step.
12293
+ */
12294
+ step?: string;
12295
+ /**
12296
+ * The percent complete as a string.
12297
+ */
12298
+ pctComplete?: string;
12299
+ /**
12300
+ * An error reason code, if applicable.
12301
+ */
12302
+ errorReasonCode: string;
12303
+ /**
12304
+ * An error reason text, if applicable.
12305
+ */
12306
+ errorReasonText: string;
12307
+ };
12308
+ type StreamVideoInput = {
12309
+ /**
12310
+ * The input width in pixels.
12311
+ */
12312
+ width: number;
12313
+ /**
12314
+ * The input height in pixels.
12315
+ */
12316
+ height: number;
12317
+ };
12318
+ type StreamPublicDetails = {
12319
+ /**
12320
+ * The public title for the video.
12321
+ */
12322
+ title: string | null;
12323
+ /**
12324
+ * The public share link.
12325
+ */
12326
+ share_link: string | null;
12327
+ /**
12328
+ * The public channel link.
12329
+ */
12330
+ channel_link: string | null;
12331
+ /**
12332
+ * The public logo URL.
12333
+ */
12334
+ logo: string | null;
12335
+ };
12336
+ type StreamDirectUpload = {
12337
+ /**
12338
+ * The URL an unauthenticated upload can use for a single multipart request.
12339
+ */
12340
+ uploadURL: string;
12341
+ /**
12342
+ * A Cloudflare-generated unique identifier for a media item.
12343
+ */
12344
+ id: string;
12345
+ /**
12346
+ * The watermark profile applied to the upload.
12347
+ */
12348
+ watermark: StreamWatermark | null;
12349
+ /**
12350
+ * The scheduled deletion time, if any.
12351
+ */
12352
+ scheduledDeletion: string | null;
12353
+ };
12354
+ type StreamDirectUploadCreateParams = {
12355
+ /**
12356
+ * The maximum duration in seconds for a video upload.
12357
+ */
12358
+ maxDurationSeconds: number;
12359
+ /**
12360
+ * The date and time after upload when videos will not be accepted.
12361
+ */
12362
+ expiry?: string;
12363
+ /**
12364
+ * A user-defined identifier for the media creator.
12365
+ */
12366
+ creator?: string;
12367
+ /**
12368
+ * A user modifiable key-value store used to reference other systems of record for
12369
+ * managing videos.
12370
+ */
12371
+ meta?: Record<string, string>;
12372
+ /**
12373
+ * Lists the origins allowed to display the video.
12374
+ */
12375
+ allowedOrigins?: Array<string>;
12376
+ /**
12377
+ * Indicates whether the video can be accessed using the id. When set to `true`,
12378
+ * a signed token must be generated with a signing key to view the video.
12379
+ */
12380
+ requireSignedURLs?: boolean;
12381
+ /**
12382
+ * The thumbnail timestamp percentage.
12383
+ */
12384
+ thumbnailTimestampPct?: number;
12385
+ /**
12386
+ * The date and time at which the video will be deleted. Include `null` to remove
12387
+ * a scheduled deletion.
12388
+ */
12389
+ scheduledDeletion?: string | null;
12390
+ /**
12391
+ * The watermark profile to apply.
12392
+ */
12393
+ watermark?: StreamDirectUploadWatermark;
12394
+ };
12395
+ type StreamDirectUploadWatermark = {
12396
+ /**
12397
+ * The unique identifier for the watermark profile.
12398
+ */
12399
+ id: string;
12400
+ };
12401
+ type StreamUrlUploadParams = {
12402
+ /**
12403
+ * Lists the origins allowed to display the video. Enter allowed origin
12404
+ * domains in an array and use `*` for wildcard subdomains. Empty arrays allow the
12405
+ * video to be viewed on any origin.
12406
+ */
12407
+ allowedOrigins?: Array<string>;
12408
+ /**
12409
+ * A user-defined identifier for the media creator.
12410
+ */
12411
+ creator?: string;
12412
+ /**
12413
+ * A user modifiable key-value store used to reference other systems of
12414
+ * record for managing videos.
12415
+ */
12416
+ meta?: Record<string, string>;
12417
+ /**
12418
+ * Indicates whether the video can be a accessed using the id. When
12419
+ * set to `true`, a signed token must be generated with a signing key to view the
12420
+ * video.
12421
+ */
12422
+ requireSignedURLs?: boolean;
12423
+ /**
12424
+ * Indicates the date and time at which the video will be deleted. Omit
12425
+ * the field to indicate no change, or include with a `null` value to remove an
12426
+ * existing scheduled deletion. If specified, must be at least 30 days from upload
12427
+ * time.
12428
+ */
12429
+ scheduledDeletion?: string | null;
12430
+ /**
12431
+ * The timestamp for a thumbnail image calculated as a percentage value
12432
+ * of the video's duration. To convert from a second-wise timestamp to a
12433
+ * percentage, divide the desired timestamp by the total duration of the video. If
12434
+ * this value is not set, the default thumbnail image is taken from 0s of the
12435
+ * video.
12436
+ */
12437
+ thumbnailTimestampPct?: number;
12438
+ /**
12439
+ * The identifier for the watermark profile
12440
+ */
12441
+ watermarkId?: string;
12442
+ };
12443
+ interface StreamScopedCaptions {
12444
+ /**
12445
+ * Uploads the caption or subtitle file to the endpoint for a specific BCP47 language.
12446
+ * One caption or subtitle file per language is allowed.
12447
+ * @param language The BCP 47 language tag for the caption or subtitle.
12448
+ * @param file The caption or subtitle file to upload.
12449
+ * @returns The created caption entry.
12450
+ * @throws {NotFoundError} if the video is not found
12451
+ * @throws {BadRequestError} if the language or file is invalid
12452
+ * @throws {MaxFileSizeError} if the file size is too large
12453
+ * @throws {InternalError} if an unexpected error occurs
12454
+ */
12455
+ upload(language: string, file: File): Promise<StreamCaption>;
12456
+ /**
12457
+ * Generate captions or subtitles for the provided language via AI.
12458
+ * @param language The BCP 47 language tag to generate.
12459
+ * @returns The generated caption entry.
12460
+ * @throws {NotFoundError} if the video is not found
12461
+ * @throws {BadRequestError} if the language is invalid
12462
+ * @throws {StreamError} if a generated caption already exists
12463
+ * @throws {StreamError} if the video duration is too long
12464
+ * @throws {StreamError} if the video is missing audio
12465
+ * @throws {StreamError} if the requested language is not supported
12466
+ * @throws {InternalError} if an unexpected error occurs
12467
+ */
12468
+ generate(language: string): Promise<StreamCaption>;
12469
+ /**
12470
+ * Lists the captions or subtitles.
12471
+ * Use the language parameter to filter by a specific language.
12472
+ * @param language The optional BCP 47 language tag to filter by.
12473
+ * @returns The list of captions or subtitles.
12474
+ * @throws {NotFoundError} if the video or caption is not found
12475
+ * @throws {InternalError} if an unexpected error occurs
12476
+ */
12477
+ list(language?: string): Promise<StreamCaption[]>;
12478
+ /**
12479
+ * Removes the captions or subtitles from a video.
12480
+ * @param language The BCP 47 language tag to remove.
12481
+ * @returns A promise that resolves when deletion completes.
12482
+ * @throws {NotFoundError} if the video or caption is not found
12483
+ * @throws {InternalError} if an unexpected error occurs
12484
+ */
12485
+ delete(language: string): Promise<void>;
12486
+ }
12487
+ interface StreamScopedDownloads {
12488
+ /**
12489
+ * Generates a download for a video when a video is ready to view. Available
12490
+ * types are `default` and `audio`. Defaults to `default` when omitted.
12491
+ * @param downloadType The download type to create.
12492
+ * @returns The current downloads for the video.
12493
+ * @throws {NotFoundError} if the video is not found
12494
+ * @throws {BadRequestError} if the download type is invalid
12495
+ * @throws {StreamError} if the video duration is too long to generate a download
12496
+ * @throws {StreamError} if the video is not ready to stream
12497
+ * @throws {InternalError} if an unexpected error occurs
12498
+ */
12499
+ generate(
12500
+ downloadType?: StreamDownloadType,
12501
+ ): Promise<StreamDownloadGetResponse>;
12502
+ /**
12503
+ * Lists the downloads created for a video.
12504
+ * @returns The current downloads for the video.
12505
+ * @throws {NotFoundError} if the video or downloads are not found
12506
+ * @throws {InternalError} if an unexpected error occurs
12507
+ */
12508
+ get(): Promise<StreamDownloadGetResponse>;
12509
+ /**
12510
+ * Delete the downloads for a video. Available types are `default` and `audio`.
12511
+ * Defaults to `default` when omitted.
12512
+ * @param downloadType The download type to delete.
12513
+ * @returns A promise that resolves when deletion completes.
12514
+ * @throws {NotFoundError} if the video or downloads are not found
12515
+ * @throws {InternalError} if an unexpected error occurs
12516
+ */
12517
+ delete(downloadType?: StreamDownloadType): Promise<void>;
12518
+ }
12519
+ interface StreamVideos {
12520
+ /**
12521
+ * Lists all videos in a users account.
12522
+ * @returns The list of videos.
12523
+ * @throws {BadRequestError} if the parameters are invalid
12524
+ * @throws {InternalError} if an unexpected error occurs
12525
+ */
12526
+ list(params?: StreamVideosListParams): Promise<StreamVideo[]>;
12527
+ }
12528
+ interface StreamWatermarks {
12529
+ /**
12530
+ * Generate a new watermark profile
12531
+ * @param file The image file to upload
12532
+ * @param params The watermark creation parameters.
12533
+ * @returns The created watermark profile.
12534
+ * @throws {BadRequestError} if the parameters are invalid
12535
+ * @throws {InvalidURLError} if the URL is invalid
12536
+ * @throws {MaxFileSizeError} if the file size is too large
12537
+ * @throws {TooManyWatermarksError} if the number of allowed watermarks is reached
12538
+ * @throws {InternalError} if an unexpected error occurs
12539
+ */
12540
+ generate(
12541
+ file: File,
12542
+ params: StreamWatermarkCreateParams,
12543
+ ): Promise<StreamWatermark>;
12544
+ /**
12545
+ * Generate a new watermark profile
12546
+ * @param url The image url to upload
12547
+ * @param params The watermark creation parameters.
12548
+ * @returns The created watermark profile.
12549
+ * @throws {BadRequestError} if the parameters are invalid
12550
+ * @throws {InvalidURLError} if the URL is invalid
12551
+ * @throws {MaxFileSizeError} if the file size is too large
12552
+ * @throws {TooManyWatermarksError} if the number of allowed watermarks is reached
12553
+ * @throws {InternalError} if an unexpected error occurs
12554
+ */
12555
+ generate(
12556
+ url: string,
12557
+ params: StreamWatermarkCreateParams,
12558
+ ): Promise<StreamWatermark>;
12559
+ /**
12560
+ * Lists all watermark profiles for an account.
12561
+ * @returns The list of watermark profiles.
12562
+ * @throws {InternalError} if an unexpected error occurs
12563
+ */
12564
+ list(): Promise<StreamWatermark[]>;
12565
+ /**
12566
+ * Retrieves details for a single watermark profile.
12567
+ * @param watermarkId The watermark profile identifier.
12568
+ * @returns The watermark profile details.
12569
+ * @throws {NotFoundError} if the watermark is not found
12570
+ * @throws {InternalError} if an unexpected error occurs
12571
+ */
12572
+ get(watermarkId: string): Promise<StreamWatermark>;
12573
+ /**
12574
+ * Deletes a watermark profile.
12575
+ * @param watermarkId The watermark profile identifier.
12576
+ * @returns A promise that resolves when deletion completes.
12577
+ * @throws {NotFoundError} if the watermark is not found
12578
+ * @throws {InternalError} if an unexpected error occurs
12579
+ */
12580
+ delete(watermarkId: string): Promise<void>;
12581
+ }
12582
+ type StreamUpdateVideoParams = {
12583
+ /**
12584
+ * Lists the origins allowed to display the video. Enter allowed origin
12585
+ * domains in an array and use `*` for wildcard subdomains. Empty arrays allow the
12586
+ * video to be viewed on any origin.
12587
+ */
12588
+ allowedOrigins?: Array<string>;
12589
+ /**
12590
+ * A user-defined identifier for the media creator.
12591
+ */
12592
+ creator?: string;
12593
+ /**
12594
+ * The maximum duration in seconds for a video upload. Can be set for a
12595
+ * video that is not yet uploaded to limit its duration. Uploads that exceed the
12596
+ * specified duration will fail during processing. A value of `-1` means the value
12597
+ * is unknown.
12598
+ */
12599
+ maxDurationSeconds?: number;
12600
+ /**
12601
+ * A user modifiable key-value store used to reference other systems of
12602
+ * record for managing videos.
12603
+ */
12604
+ meta?: Record<string, string>;
12605
+ /**
12606
+ * Indicates whether the video can be a accessed using the id. When
12607
+ * set to `true`, a signed token must be generated with a signing key to view the
12608
+ * video.
12609
+ */
12610
+ requireSignedURLs?: boolean;
12611
+ /**
12612
+ * Indicates the date and time at which the video will be deleted. Omit
12613
+ * the field to indicate no change, or include with a `null` value to remove an
12614
+ * existing scheduled deletion. If specified, must be at least 30 days from upload
12615
+ * time.
12616
+ */
12617
+ scheduledDeletion?: string | null;
12618
+ /**
12619
+ * The timestamp for a thumbnail image calculated as a percentage value
12620
+ * of the video's duration. To convert from a second-wise timestamp to a
12621
+ * percentage, divide the desired timestamp by the total duration of the video. If
12622
+ * this value is not set, the default thumbnail image is taken from 0s of the
12623
+ * video.
12624
+ */
12625
+ thumbnailTimestampPct?: number;
12626
+ };
12627
+ type StreamCaption = {
12628
+ /**
12629
+ * Whether the caption was generated via AI.
12630
+ */
12631
+ generated?: boolean;
12632
+ /**
12633
+ * The language label displayed in the native language to users.
12634
+ */
12635
+ label: string;
12636
+ /**
12637
+ * The language tag in BCP 47 format.
12638
+ */
12639
+ language: string;
12640
+ /**
12641
+ * The status of a generated caption.
12642
+ */
12643
+ status?: "ready" | "inprogress" | "error";
12644
+ };
12645
+ type StreamDownloadStatus = "ready" | "inprogress" | "error";
12646
+ type StreamDownloadType = "default" | "audio";
12647
+ type StreamDownload = {
12648
+ /**
12649
+ * Indicates the progress as a percentage between 0 and 100.
12650
+ */
12651
+ percentComplete: number;
12652
+ /**
12653
+ * The status of a generated download.
12654
+ */
12655
+ status: StreamDownloadStatus;
12656
+ /**
12657
+ * The URL to access the generated download.
12658
+ */
12659
+ url?: string;
12660
+ };
12661
+ /**
12662
+ * An object with download type keys. Each key is optional and only present if that
12663
+ * download type has been created.
12664
+ */
12665
+ type StreamDownloadGetResponse = {
12666
+ /**
12667
+ * The audio-only download. Only present if this download type has been created.
12668
+ */
12669
+ audio?: StreamDownload;
12670
+ /**
12671
+ * The default video download. Only present if this download type has been created.
12672
+ */
12673
+ default?: StreamDownload;
12674
+ };
12675
+ type StreamWatermarkPosition =
12676
+ | "upperRight"
12677
+ | "upperLeft"
12678
+ | "lowerLeft"
12679
+ | "lowerRight"
12680
+ | "center";
12681
+ type StreamWatermark = {
12682
+ /**
12683
+ * The unique identifier for a watermark profile.
12684
+ */
12685
+ id: string;
12686
+ /**
12687
+ * The size of the image in bytes.
12688
+ */
12689
+ size: number;
12690
+ /**
12691
+ * The height of the image in pixels.
12692
+ */
12693
+ height: number;
12694
+ /**
12695
+ * The width of the image in pixels.
12696
+ */
12697
+ width: number;
12698
+ /**
12699
+ * The date and a time a watermark profile was created.
12700
+ */
12701
+ created: string;
12702
+ /**
12703
+ * The source URL for a downloaded image. If the watermark profile was created via
12704
+ * direct upload, this field is null.
12705
+ */
12706
+ downloadedFrom: string | null;
12707
+ /**
12708
+ * A short description of the watermark profile.
12709
+ */
12710
+ name: string;
12711
+ /**
12712
+ * The translucency of the image. A value of `0.0` makes the image completely
12713
+ * transparent, and `1.0` makes the image completely opaque. Note that if the image
12714
+ * is already semi-transparent, setting this to `1.0` will not make the image
12715
+ * completely opaque.
12716
+ */
12717
+ opacity: number;
12718
+ /**
12719
+ * The whitespace between the adjacent edges (determined by position) of the video
12720
+ * and the image. `0.0` indicates no padding, and `1.0` indicates a fully padded
12721
+ * video width or length, as determined by the algorithm.
12722
+ */
12723
+ padding: number;
12724
+ /**
12725
+ * The size of the image relative to the overall size of the video. This parameter
12726
+ * will adapt to horizontal and vertical videos automatically. `0.0` indicates no
12727
+ * scaling (use the size of the image as-is), and `1.0 `fills the entire video.
12728
+ */
12729
+ scale: number;
12730
+ /**
12731
+ * The location of the image. Valid positions are: `upperRight`, `upperLeft`,
12732
+ * `lowerLeft`, `lowerRight`, and `center`. Note that `center` ignores the
12733
+ * `padding` parameter.
12734
+ */
12735
+ position: StreamWatermarkPosition;
12736
+ };
12737
+ type StreamWatermarkCreateParams = {
12738
+ /**
12739
+ * A short description of the watermark profile.
12740
+ */
12741
+ name?: string;
12742
+ /**
12743
+ * The translucency of the image. A value of `0.0` makes the image completely
12744
+ * transparent, and `1.0` makes the image completely opaque. Note that if the
12745
+ * image is already semi-transparent, setting this to `1.0` will not make the
12746
+ * image completely opaque.
12747
+ */
12748
+ opacity?: number;
12749
+ /**
12750
+ * The whitespace between the adjacent edges (determined by position) of the
12751
+ * video and the image. `0.0` indicates no padding, and `1.0` indicates a fully
12752
+ * padded video width or length, as determined by the algorithm.
12753
+ */
12754
+ padding?: number;
12755
+ /**
12756
+ * The size of the image relative to the overall size of the video. This
12757
+ * parameter will adapt to horizontal and vertical videos automatically. `0.0`
12758
+ * indicates no scaling (use the size of the image as-is), and `1.0 `fills the
12759
+ * entire video.
12760
+ */
12761
+ scale?: number;
12762
+ /**
12763
+ * The location of the image.
12764
+ */
12765
+ position?: StreamWatermarkPosition;
12766
+ };
12767
+ type StreamVideosListParams = {
12768
+ /**
12769
+ * The maximum number of videos to return.
12770
+ */
12771
+ limit?: number;
12772
+ /**
12773
+ * Return videos created before this timestamp.
12774
+ * (RFC3339/RFC3339Nano)
12775
+ */
12776
+ before?: string;
12777
+ /**
12778
+ * Comparison operator for the `before` field.
12779
+ * @default 'lt'
12780
+ */
12781
+ beforeComp?: StreamPaginationComparison;
12782
+ /**
12783
+ * Return videos created after this timestamp.
12784
+ * (RFC3339/RFC3339Nano)
12785
+ */
12786
+ after?: string;
12787
+ /**
12788
+ * Comparison operator for the `after` field.
12789
+ * @default 'gte'
12790
+ */
12791
+ afterComp?: StreamPaginationComparison;
12792
+ };
12793
+ type StreamPaginationComparison = "eq" | "gt" | "gte" | "lt" | "lte";
12794
+ /**
12795
+ * Error object for Stream binding operations.
12796
+ */
12797
+ interface StreamError extends Error {
12798
+ readonly code: number;
12799
+ readonly statusCode: number;
12800
+ readonly message: string;
12801
+ readonly stack?: string;
12802
+ }
12803
+ interface InternalError extends StreamError {
12804
+ name: "InternalError";
12805
+ }
12806
+ interface BadRequestError extends StreamError {
12807
+ name: "BadRequestError";
12808
+ }
12809
+ interface NotFoundError extends StreamError {
12810
+ name: "NotFoundError";
12811
+ }
12812
+ interface ForbiddenError extends StreamError {
12813
+ name: "ForbiddenError";
12814
+ }
12815
+ interface RateLimitedError extends StreamError {
12816
+ name: "RateLimitedError";
12817
+ }
12818
+ interface QuotaReachedError extends StreamError {
12819
+ name: "QuotaReachedError";
12820
+ }
12821
+ interface MaxFileSizeError extends StreamError {
12822
+ name: "MaxFileSizeError";
12823
+ }
12824
+ interface InvalidURLError extends StreamError {
12825
+ name: "InvalidURLError";
12826
+ }
12827
+ interface AlreadyUploadedError extends StreamError {
12828
+ name: "AlreadyUploadedError";
12829
+ }
12830
+ interface TooManyWatermarksError extends StreamError {
12831
+ name: "TooManyWatermarksError";
12832
+ }
11648
12833
  type MarkdownDocument = {
11649
12834
  name: string;
11650
12835
  blob: Blob;
11651
12836
  };
11652
12837
  type ConversionResponse =
11653
12838
  | {
12839
+ id: string;
11654
12840
  name: string;
11655
12841
  mimeType: string;
11656
12842
  format: "markdown";
@@ -11658,6 +12844,7 @@ type ConversionResponse =
11658
12844
  data: string;
11659
12845
  }
11660
12846
  | {
12847
+ id: string;
11661
12848
  name: string;
11662
12849
  mimeType: string;
11663
12850
  format: "error";
@@ -11675,6 +12862,8 @@ type ConversionOptions = {
11675
12862
  images?: EmbeddedImageConversionOptions & {
11676
12863
  convertOGImage?: boolean;
11677
12864
  };
12865
+ hostname?: string;
12866
+ cssSelector?: string;
11678
12867
  };
11679
12868
  docx?: {
11680
12869
  images?: EmbeddedImageConversionOptions;