@mux/ai 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,13 +3,16 @@
3
3
  [![npm version](https://badge.fury.io/js/@mux%2Fai.svg)](https://www.npmjs.com/package/@mux/ai)
4
4
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
5
 
6
- > **A TypeScript SDK for building AI-driven video workflows on the server, powered by [Mux](https://www.mux.com)!**
6
+ > **A TypeScript toolkit for building AI-driven video workflows on the server, powered by [Mux](https://www.mux.com)!**
7
7
 
8
8
  `@mux/ai` does this by providing:
9
- - Easy to use, purpose-driven, cost effective, configurable **_workflow functions_** that integrate with a variety of popular AI/LLM providers (OpenAI, Anthropic, Google).
10
- - **Examples:** [`generateChapters`](#chapter-generation), [`getModerationScores`](#content-moderation), [`generateVideoEmbeddings`](#video-search-with-embeddings), [`getSummaryAndTags`](#video-summarization)
11
- - Convenient, parameterized, commonly needed **_primitive functions_** backed by [Mux Video](https://www.mux.com/video-api) for building your own media-based AI workflows and integrations.
12
- - **Examples:** `getStoryboardUrl`, `chunkVTTCues`, `fetchTranscriptForAsset`
9
+
10
+ Easy to use, purpose-driven, cost effective, configurable **_workflow functions_** that integrate with a variety of popular AI/LLM providers (OpenAI, Anthropic, Google).
11
+ - **Examples:** [`getSummaryAndTags`](#video-summarization), [`getModerationScores`](#content-moderation), [`hasBurnedInCaptions`](#burned-in-caption-detection), [`generateChapters`](#chapter-generation), [`generateVideoEmbeddings`](#video-search-with-embeddings), [`translateCaptions`](#caption-translation), [`translateAudio`](#audio-dubbing)
12
+ - Workflows automatically ship with `"use workflow"` [compatability with Workflow DevKit](#compatability-with-workflow-devkit)
13
+
14
+ Convenient, parameterized, commonly needed **_primitive functions_** backed by [Mux Video](https://www.mux.com/video-api) for building your own media-based AI workflows and integrations.
15
+ - **Examples:** `getStoryboardUrl`, `chunkVTTCues`, `fetchTranscriptForAsset`
13
16
 
14
17
  # Usage
15
18
 
@@ -72,16 +75,6 @@ S3_ACCESS_KEY_ID=your-access-key
72
75
  S3_SECRET_ACCESS_KEY=your-secret-key
73
76
  ```
74
77
 
75
- Or pass credentials directly to each function:
76
-
77
- ```typescript
78
- const result = await getSummaryAndTags(assetId, {
79
- muxTokenId: "your-token-id",
80
- muxTokenSecret: "your-token-secret",
81
- openaiApiKey: "your-openai-key"
82
- });
83
- ```
84
-
85
78
  > **💡 Tip:** If you're using `.env` in a repository or version tracking system, make sure you add this file to your `.gitignore` or equivalent to avoid unintentionally committing secure credentials.
86
79
 
87
80
  # Workflows
@@ -98,6 +91,58 @@ const result = await getSummaryAndTags(assetId, {
98
91
  | [`translateCaptions`](./docs/WORKFLOWS.md#caption-translation)<br/>[API](./docs/API.md#translatecaptionsassetid-fromlanguagecode-tolanguagecode-options) · [Source](./src/workflows/translate-captions.ts) | Translate an asset's captions into different languages | OpenAI, Anthropic, Google | `gpt-5.1` (OpenAI), `claude-sonnet-4-5` (Anthropic), `gemini-2.5-flash` (Google) | Video (required), Captions (required) | AWS S3 (if `uploadToMux=true`) |
99
92
  | [`translateAudio`](./docs/WORKFLOWS.md#audio-dubbing)<br/>[API](./docs/API.md#translateaudioassetid-tolanguagecode-options) · [Source](./src/workflows/translate-audio.ts) | Create AI-dubbed audio tracks in different languages for an asset | ElevenLabs only | ElevenLabs Dubbing API | Video (required), Audio (required) | AWS S3 (if `uploadToMux=true`) |
100
93
 
94
+ ## Compatability with Workflow DevKit
95
+
96
+ All workflows are compatible with [Workflow DevKit](https://useworkflow.dev). The workflows in this SDK are exported with `"use workflow"` directives and `"use step"` directives in the code.
97
+
98
+ If you are using Workflow DevKit in your project, then you must call workflow functions like this:
99
+
100
+ ```ts
101
+ import { start } from 'workflow/api';
102
+ import { getSummaryAndTags } from '@mux/ai/workflows';
103
+
104
+ const assetId = 'YOUR_ASSET_ID';
105
+ const run = await start(getSummaryAndTags, [assetId]);
106
+
107
+ // optionally, wait for the workflow run return value:
108
+ // const result = await run.returnValue
109
+ ```
110
+
111
+ ### Features of Workflow DevKit
112
+
113
+ - [Observability Dashboard](https://useworkflow.dev/docs/observability)
114
+ - [Control Flow Patterns](https://useworkflow.dev/docs/foundations/control-flow-patterns) like Parallel Execution.
115
+ - [Errors and Retrying](https://useworkflow.dev/docs/foundations/errors-and-retries)
116
+ - [Hooks and Webhooks](https://useworkflow.dev/docs/foundations/hooks)
117
+ - Patterns for building Agents with [Human in the Loop](https://useworkflow.dev/docs/ai/human-in-the-loop)
118
+
119
+ **Workflows can be nested**
120
+
121
+ ```ts
122
+ import { start } from "workflow/api";
123
+ import { getSummaryAndTags } from '@mux/ai/workflows';
124
+
125
+ async function processVideoSummary (assetId: string) {
126
+ 'use workflow'
127
+
128
+ const summary = await getSummaryAndTags(assetId);
129
+ const emailResp = await emailSummaryToAdmins(summary: summary);
130
+
131
+ return { assetId, summary, emailResp }
132
+ }
133
+
134
+ async function emailSummaryToAdmins (assetId: string) {
135
+ 'use step';
136
+ return { sent: true }
137
+ }
138
+
139
+ //
140
+ // this will call the processVideoSummary workflow that is defined above
141
+ // in that workflow, it calls `getSummaryAndTags()` workflow
142
+ //
143
+ const run = await start(processVideoSummary, [assetId]);
144
+ ```
145
+
101
146
  ## Example Workflows
102
147
 
103
148
  ### Video Summarization
@@ -190,7 +235,7 @@ for (const chunk of result.chunks) {
190
235
 
191
236
  - **Cost-Effective by Default**: Uses affordable frontier models like `gpt-5.1`, `claude-sonnet-4-5`, and `gemini-2.5-flash` to keep analysis costs low while maintaining high quality results
192
237
  - **Multi-modal Analysis**: Combines storyboard images with video transcripts for richer understanding
193
- - **Tone Control**: Choose between normal, sassy, or professional analysis styles for summarization
238
+ - **Tone Control**: Choose between neutral, playful, or professional analysis styles for summarization
194
239
  - **Prompt Customization**: Override specific prompt sections to tune workflows to your exact use case
195
240
  - **Configurable Thresholds**: Set custom sensitivity levels for content moderation
196
241
  - **Full TypeScript Support**: Comprehensive types for excellent developer experience and IDE autocomplete
@@ -1,28 +1,16 @@
1
- import { A as AssetTextTrack, b as MuxAsset, e as TextChunk, C as ChunkingStrategy } from './types-ktXDZ93V.js';
2
-
3
- /**
4
- * Context required to sign URLs for signed playback IDs.
5
- */
6
- interface SigningContext {
7
- /** The signing key ID from Mux dashboard. */
8
- keyId: string;
9
- /** The base64-encoded private key from Mux dashboard. */
10
- keySecret: string;
11
- /** Token expiration time (e.g. '1h', '1d'). Defaults to '1h'. */
12
- expiration?: string;
13
- }
1
+ import { A as AssetTextTrack, a as MuxAsset, d as TextChunk, C as ChunkingStrategy } from './types-DzOQNn9R.js';
14
2
 
15
3
  declare const DEFAULT_STORYBOARD_WIDTH = 640;
16
4
  /**
17
5
  * Generates a storyboard URL for the given playback ID.
18
- * If a signing context is provided, the URL will be signed with a token.
6
+ * If shouldSign is true, the URL will be signed with a token using credentials from environment variables.
19
7
  *
20
8
  * @param playbackId - The Mux playback ID
21
9
  * @param width - Width of the storyboard in pixels (default: 640)
22
- * @param signingContext - Optional signing context for signed playback IDs
23
- * @returns Storyboard URL (signed if context provided)
10
+ * @param shouldSign - Flag for whether or not to use signed playback IDs (default: false)
11
+ * @returns Storyboard URL (signed if shouldSign is true)
24
12
  */
25
- declare function getStoryboardUrl(playbackId: string, width?: number, signingContext?: SigningContext): Promise<string>;
13
+ declare function getStoryboardUrl(playbackId: string, width?: number, shouldSign?: boolean): Promise<string>;
26
14
 
27
15
  /** A single cue from a VTT file with timing info. */
28
16
  interface VTTCue {
@@ -34,7 +22,7 @@ interface TranscriptFetchOptions {
34
22
  languageCode?: string;
35
23
  cleanTranscript?: boolean;
36
24
  /** Optional signing context for signed playback IDs */
37
- signingContext?: SigningContext;
25
+ shouldSign?: boolean;
38
26
  }
39
27
  interface TranscriptResult {
40
28
  transcriptText: string;
@@ -59,10 +47,10 @@ declare function parseVTTCues(vttContent: string): VTTCue[];
59
47
  *
60
48
  * @param playbackId - The Mux playback ID
61
49
  * @param trackId - The text track ID
62
- * @param signingContext - Optional signing context for signed playback IDs
50
+ * @param shouldSign - Flag for whether or not to use signed playback IDs
63
51
  * @returns Transcript URL (signed if context provided)
64
52
  */
65
- declare function buildTranscriptUrl(playbackId: string, trackId: string, signingContext?: SigningContext): Promise<string>;
53
+ declare function buildTranscriptUrl(playbackId: string, trackId: string, shouldSign?: boolean): Promise<string>;
66
54
  declare function fetchTranscriptForAsset(asset: MuxAsset, playbackId: string, options?: TranscriptFetchOptions): Promise<TranscriptResult>;
67
55
 
68
56
  /**
@@ -104,17 +92,17 @@ interface ThumbnailOptions {
104
92
  interval?: number;
105
93
  /** Width of the thumbnail in pixels (default: 640) */
106
94
  width?: number;
107
- /** Optional signing context for signed playback IDs */
108
- signingContext?: SigningContext;
95
+ /** Flag for whether or not to use signed playback IDs (default: false) */
96
+ shouldSign?: boolean;
109
97
  }
110
98
  /**
111
99
  * Generates thumbnail URLs at regular intervals based on video duration.
112
- * If a signing context is provided, the URLs will be signed with tokens.
100
+ * If shouldSign is true, the URLs will be signed with tokens using credentials from environment variables.
113
101
  *
114
102
  * @param playbackId - The Mux playback ID
115
103
  * @param duration - Video duration in seconds
116
104
  * @param options - Thumbnail generation options
117
- * @returns Array of thumbnail URLs (signed if context provided)
105
+ * @returns Array of thumbnail URLs (signed if shouldSign is true)
118
106
  */
119
107
  declare function getThumbnailUrls(playbackId: string, duration: number, options?: ThumbnailOptions): Promise<string[]>;
120
108
 
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { createAnthropic } from '@ai-sdk/anthropic';
3
3
  import { createGoogleGenerativeAI } from '@ai-sdk/google';
4
4
  import { createOpenAI } from '@ai-sdk/openai';
5
- import { h as TokenUsage, a as MuxAIOptions, I as ImageSubmissionMode, C as ChunkingStrategy, g as VideoEmbeddingsResult, T as ToneType } from './types-ktXDZ93V.js';
5
+ import { g as TokenUsage, M as MuxAIOptions, I as ImageSubmissionMode, C as ChunkingStrategy, f as VideoEmbeddingsResult, T as ToneType } from './types-DzOQNn9R.js';
6
6
  import { Buffer } from 'node:buffer';
7
7
 
8
8
  interface ImageDownloadOptions {
@@ -339,7 +339,7 @@ interface SummarizationOptions extends MuxAIOptions {
339
339
  provider?: SupportedProvider;
340
340
  /** Provider-specific chat model identifier. */
341
341
  model?: ModelIdByProvider[SupportedProvider];
342
- /** Prompt tone shim applied to the system instruction (defaults to 'normal'). */
342
+ /** Prompt tone shim applied to the system instruction (defaults to 'neutral'). */
343
343
  tone?: ToneType;
344
344
  /** Fetch the transcript and send it alongside the storyboard (defaults to true). */
345
345
  includeTranscript?: boolean;
@@ -478,10 +478,6 @@ interface AudioTranslationOptions extends MuxAIOptions {
478
478
  s3Region?: string;
479
479
  /** Bucket that will store dubbed audio files. */
480
480
  s3Bucket?: string;
481
- /** Access key ID used for uploads. */
482
- s3AccessKeyId?: string;
483
- /** Secret access key used for uploads. */
484
- s3SecretAccessKey?: string;
485
481
  /**
486
482
  * When true (default) the dubbed audio file is uploaded to the configured
487
483
  * bucket and attached to the Mux asset.
@@ -528,10 +524,6 @@ interface TranslationOptions<P extends SupportedProvider = SupportedProvider> ex
528
524
  s3Region?: string;
529
525
  /** Bucket that will store translated VTT files. */
530
526
  s3Bucket?: string;
531
- /** Access key ID used for uploads. */
532
- s3AccessKeyId?: string;
533
- /** Secret access key used for uploads. */
534
- s3SecretAccessKey?: string;
535
527
  /**
536
528
  * When true (default) the translated VTT is uploaded to the configured
537
529
  * bucket and attached to the Mux asset.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { i as primitives } from './index-DyTSka2R.js';
2
- export { A as AssetTextTrack, f as ChunkEmbedding, C as ChunkingStrategy, I as ImageSubmissionMode, M as MuxAIConfig, a as MuxAIOptions, b as MuxAsset, c as PlaybackAsset, P as PlaybackPolicy, e as TextChunk, d as TokenChunkingConfig, h as TokenUsage, T as ToneType, V as VTTChunkingConfig, g as VideoEmbeddingsResult } from './types-ktXDZ93V.js';
3
- export { i as workflows } from './index-CMZYZcj6.js';
1
+ export { i as primitives } from './index-BcNDGOI6.js';
2
+ export { A as AssetTextTrack, e as ChunkEmbedding, C as ChunkingStrategy, I as ImageSubmissionMode, M as MuxAIOptions, a as MuxAsset, b as PlaybackAsset, P as PlaybackPolicy, d as TextChunk, c as TokenChunkingConfig, g as TokenUsage, T as ToneType, V as VTTChunkingConfig, f as VideoEmbeddingsResult } from './types-DzOQNn9R.js';
3
+ export { i as workflows } from './index-D3fZHu0h.js';
4
4
  import '@mux/mux-node';
5
5
  import 'zod';
6
6
  import '@ai-sdk/anthropic';