@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 +61 -16
- package/dist/{index-DyTSka2R.d.ts → index-BcNDGOI6.d.ts} +12 -24
- package/dist/{index-CMZYZcj6.d.ts → index-D3fZHu0h.d.ts} +2 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +149 -160
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +19 -8
- package/dist/primitives/index.js.map +1 -1
- package/dist/{types-ktXDZ93V.d.ts → types-DzOQNn9R.d.ts} +3 -25
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +149 -160
- package/dist/workflows/index.js.map +1 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@mux/ai)
|
|
4
4
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
5
|
|
|
6
|
-
> **A TypeScript
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
23
|
-
* @returns Storyboard URL (signed if
|
|
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,
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
/**
|
|
108
|
-
|
|
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
|
|
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
|
|
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 {
|
|
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 '
|
|
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-
|
|
2
|
-
export { A as AssetTextTrack,
|
|
3
|
-
export { i as workflows } from './index-
|
|
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';
|