@mux/ai 0.46.0 → 0.48.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 +5 -0
- package/dist/{index-CIcGZD3x.d.ts → index-DxAt9Jq8.d.ts} +34 -18
- package/dist/index.d.ts +2 -2
- package/dist/index.js +57 -24
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.js +3 -5
- package/dist/primitives/index.js.map +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js +54 -23
- package/dist/workflows/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ Easy to use, purpose-driven, cost effective, configurable **_workflow functions_
|
|
|
10
10
|
|
|
11
11
|
Turn your Mux video and audio assets into structured, actionable data — summaries, chapters, moderation scores, translations, embeddings, and more — with a single function call. `@mux/ai` handles fetching media data from Mux, formatting it for AI providers, and returning typed results so you can focus on building your product instead of wrangling prompts and media pipelines.
|
|
12
12
|
|
|
13
|
+
> [!TIP]
|
|
14
|
+
> **🤖 Beep boop! And now a word from our sponsors:** [Mux Robots](https://www.mux.com/robots) gives you hosted versions of these workflows behind a single API request, with no pipeline to build or run and no need to BYO LLM. It also goes further than this SDK, with premium caption generation, key moment detection, thumbnail ranking, scene segmentation and more. The first 100,000 units each month are free.
|
|
15
|
+
>
|
|
16
|
+
> `@mux/ai` is the open-source part. We develop and maintain it in public, and it's the right choice when you want full control over prompts, providers and models, or need to build your own workflows from the primitives.
|
|
17
|
+
|
|
13
18
|
## Quick Start
|
|
14
19
|
|
|
15
20
|
### Install
|
|
@@ -180,6 +180,15 @@ declare function getLanguageName(code: string): string | undefined;
|
|
|
180
180
|
* Audio tracks are never Mux-generated, so for audio this behaves like `fail`.
|
|
181
181
|
*/
|
|
182
182
|
type ReplaceExistingTracksPolicy = "fail" | "replace_all" | "replace_generated";
|
|
183
|
+
/**
|
|
184
|
+
* How a workflow that edits an existing track treats that source track.
|
|
185
|
+
*
|
|
186
|
+
* - `replace`: delete the source and create the new track in its place. No other track is deleted.
|
|
187
|
+
* - `fail`: delete nothing; the new track is added alongside the source and must have a different name.
|
|
188
|
+
*
|
|
189
|
+
* Only name collisions count: the new track is always in the source's language.
|
|
190
|
+
*/
|
|
191
|
+
type SourceTrackReplacementPolicy = "replace" | "fail";
|
|
183
192
|
/** Mux track types that share a name-uniqueness group among themselves. */
|
|
184
193
|
type ReplaceableTrackType = "text" | "audio";
|
|
185
194
|
/** The `(type, language_code, name)` a workflow is about to write to Mux. `type` defaults to `text`. */
|
|
@@ -255,34 +264,35 @@ declare function findNameCollisionTextTracks(asset: MuxAsset, target: TextTrackT
|
|
|
255
264
|
* Decides which existing tracks stand in the way of `target` and what `policy`
|
|
256
265
|
* says to do about them. Pure: pass the freshest asset you have.
|
|
257
266
|
*
|
|
258
|
-
* `keepTrackIds` marks tracks that are allowed to coexist with the new one and
|
|
259
|
-
* are never treated as conflicts. edit-captions uses it under `fail` to keep
|
|
260
|
-
* the source track it is editing.
|
|
261
|
-
*
|
|
262
267
|
* A conflicting primary audio track always blocks: Mux refuses to delete it and
|
|
263
268
|
* it is the customer's original audio.
|
|
264
269
|
*/
|
|
265
|
-
declare function planTextTrackReplacement(asset: MuxAsset, target: TextTrackTarget, policy: ReplaceExistingTracksPolicy
|
|
266
|
-
|
|
267
|
-
|
|
270
|
+
declare function planTextTrackReplacement(asset: MuxAsset, target: TextTrackTarget, policy: ReplaceExistingTracksPolicy): TextTrackReplacementPlan;
|
|
271
|
+
/** Plans an edit of `sourceTrackId` into `target`: deletes at most the source, and blocks if any other track has the target's name. */
|
|
272
|
+
declare function planSourceTrackReplacement(asset: MuxAsset, sourceTrackId: string, target: TextTrackTarget, policy: SourceTrackReplacementPolicy): TextTrackReplacementPlan;
|
|
268
273
|
/** True for Mux's `400 invalid_parameters` "Track name 'X' is not unique" rejection. */
|
|
269
274
|
declare function isDuplicateTrackNameError(error: unknown): boolean;
|
|
270
275
|
/** Default audit tag written to `passthrough` on tracks created by `@mux/ai`. */
|
|
271
276
|
declare function buildMuxAiTrackPassthrough(workflow: string): string;
|
|
272
277
|
declare function validateTrackPassthrough(passthrough: string | undefined): string | undefined;
|
|
273
|
-
interface
|
|
278
|
+
interface CreateTrackWriteInput {
|
|
274
279
|
assetId: string;
|
|
275
280
|
target: TextTrackTarget;
|
|
276
|
-
policy: ReplaceExistingTracksPolicy;
|
|
277
281
|
presignedUrl: string;
|
|
278
282
|
/** Text tracks only. */
|
|
279
283
|
closedCaptions?: boolean;
|
|
280
284
|
passthrough?: string;
|
|
281
|
-
/** Tracks that may coexist with the new one; see `planTextTrackReplacement`. */
|
|
282
|
-
keepTrackIds?: string[];
|
|
283
285
|
credentials?: WorkflowCredentialsInput;
|
|
284
286
|
}
|
|
287
|
+
interface ReplaceAndCreateTextTrackInput extends CreateTrackWriteInput {
|
|
288
|
+
policy: ReplaceExistingTracksPolicy;
|
|
289
|
+
}
|
|
285
290
|
type ReplaceAndCreateTrackInput = ReplaceAndCreateTextTrackInput;
|
|
291
|
+
interface ReplaceSourceTrackInput extends CreateTrackWriteInput {
|
|
292
|
+
/** The track being edited; see `planSourceTrackReplacement`. */
|
|
293
|
+
sourceTrackId: string;
|
|
294
|
+
policy: SourceTrackReplacementPolicy;
|
|
295
|
+
}
|
|
286
296
|
/**
|
|
287
297
|
* Fetches the asset fresh, deletes whatever `policy` allows, then creates the
|
|
288
298
|
* new track of `target.type` (default `text`). Known outcomes come back as
|
|
@@ -299,6 +309,12 @@ type ReplaceAndCreateTrackInput = ReplaceAndCreateTextTrackInput;
|
|
|
299
309
|
* the create.
|
|
300
310
|
*/
|
|
301
311
|
declare function replaceAndCreateTrack(input: ReplaceAndCreateTextTrackInput): Promise<ReplaceAndCreateTextTrackResult>;
|
|
312
|
+
/**
|
|
313
|
+
* `replaceAndCreateTrack` for a workflow that edits an existing text track: plans
|
|
314
|
+
* with `planSourceTrackReplacement`, so at most the source itself is deleted.
|
|
315
|
+
* Same outcomes and retry behaviour.
|
|
316
|
+
*/
|
|
317
|
+
declare function replaceSourceTrack(input: ReplaceSourceTrackInput): Promise<ReplaceAndCreateTextTrackResult>;
|
|
302
318
|
/** `replaceAndCreateTrack` pinned to text tracks. */
|
|
303
319
|
declare function replaceAndCreateTextTrack(input: ReplaceAndCreateTextTrackInput): Promise<ReplaceAndCreateTextTrackResult>;
|
|
304
320
|
|
|
@@ -838,12 +854,12 @@ interface EditCaptionsOptions<P extends SupportedProvider = SupportedProvider> e
|
|
|
838
854
|
/** Replacements applied only to bracketed speaker labels at the start of cues. */
|
|
839
855
|
speakerReplacements?: SpeakerReplacement[];
|
|
840
856
|
/**
|
|
841
|
-
* What to do with the source track
|
|
842
|
-
*
|
|
843
|
-
* `"
|
|
844
|
-
* `
|
|
857
|
+
* What to do with the source track. Defaults to `"replace"`: the source is
|
|
858
|
+
* deleted and the edited track takes its place; no other track is touched.
|
|
859
|
+
* `"fail"` deletes nothing and adds the edited track alongside the source,
|
|
860
|
+
* so it requires a `trackName` different from the source's.
|
|
845
861
|
*/
|
|
846
|
-
replaceExistingTracks?:
|
|
862
|
+
replaceExistingTracks?: SourceTrackReplacementPolicy;
|
|
847
863
|
/** Name for the edited Mux text track. Defaults to the source track's name. */
|
|
848
864
|
trackName?: string;
|
|
849
865
|
/**
|
|
@@ -903,7 +919,7 @@ interface EditCaptionsResult {
|
|
|
903
919
|
replacements: ReplacementRecord[];
|
|
904
920
|
};
|
|
905
921
|
uploadedTrackId?: string;
|
|
906
|
-
/**
|
|
922
|
+
/** Tracks deleted before the edited track was created: the source track, when it was replaced. */
|
|
907
923
|
replacedTracks?: TextTrackSummary[];
|
|
908
924
|
presignedUrl?: string;
|
|
909
925
|
usage?: TokenUsage;
|
|
@@ -1962,4 +1978,4 @@ declare namespace index {
|
|
|
1962
1978
|
export { index_ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH as ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH, index_ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH as ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH, index_ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL as ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL, index_ASK_QUESTIONS_MAX_QUESTION_LENGTH as ASK_QUESTIONS_MAX_QUESTION_LENGTH, type index_AskQuestionsOptions as AskQuestionsOptions, type index_AskQuestionsResult as AskQuestionsResult, type index_AskQuestionsType as AskQuestionsType, type index_AudioTranslationOptions as AudioTranslationOptions, type index_AudioTranslationResult as AudioTranslationResult, type index_AutoCensorProfanityOptions as AutoCensorProfanityOptions, type index_BurnedInCaptionsAnalysis as BurnedInCaptionsAnalysis, type index_BurnedInCaptionsOptions as BurnedInCaptionsOptions, type index_BurnedInCaptionsPromptOverrides as BurnedInCaptionsPromptOverrides, type index_BurnedInCaptionsPromptSections as BurnedInCaptionsPromptSections, type index_BurnedInCaptionsResult as BurnedInCaptionsResult, type index_CaptionReplacement as CaptionReplacement, type index_CensorMode as CensorMode, type index_Chapter as Chapter, type index_ChapterSystemPromptSections as ChapterSystemPromptSections, type index_ChaptersOptions as ChaptersOptions, type index_ChaptersPromptOverrides as ChaptersPromptOverrides, type index_ChaptersPromptSections as ChaptersPromptSections, type index_ChaptersResult as ChaptersResult, type index_ChaptersType as ChaptersType, index_DEFAULT_DESCRIPTION_LENGTH as DEFAULT_DESCRIPTION_LENGTH, index_DEFAULT_SUMMARY_KEYWORD_LIMIT as DEFAULT_SUMMARY_KEYWORD_LIMIT, index_DEFAULT_TITLE_LENGTH as DEFAULT_TITLE_LENGTH, type index_EditCaptionsOptions as EditCaptionsOptions, type index_EditCaptionsResult as EditCaptionsResult, type index_EmbeddingsOptions as EmbeddingsOptions, type index_EmbeddingsResult as EmbeddingsResult, type index_EngagementInsightsOptions as EngagementInsightsOptions, type index_EngagementInsightsResult as EngagementInsightsResult, index_GENERATE_TEXT_CALLS_TO_ACTION as GENERATE_TEXT_CALLS_TO_ACTION, index_GENERATE_TEXT_CHANNELS as GENERATE_TEXT_CHANNELS, index_GENERATE_TEXT_CHANNEL_CEILINGS as GENERATE_TEXT_CHANNEL_CEILINGS, index_GENERATE_TEXT_FORMATS as GENERATE_TEXT_FORMATS, index_GENERATE_TEXT_LENGTH_BOUNDS as GENERATE_TEXT_LENGTH_BOUNDS, index_GENERATE_TEXT_MAX_ARTIFACTS as GENERATE_TEXT_MAX_ARTIFACTS, index_GENERATE_TEXT_MAX_AUDIENCE_CHARS as GENERATE_TEXT_MAX_AUDIENCE_CHARS, index_GENERATE_TEXT_MAX_BRAND_TERMS as GENERATE_TEXT_MAX_BRAND_TERMS, index_GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS as GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS, index_GENERATE_TEXT_MAX_BRAND_TERM_CHARS as GENERATE_TEXT_MAX_BRAND_TERM_CHARS, index_GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS as GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS, index_GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS as GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, index_GENERATE_TEXT_MAX_SHOT_FRAMES as GENERATE_TEXT_MAX_SHOT_FRAMES, index_GENERATE_TEXT_MAX_VARIANTS as GENERATE_TEXT_MAX_VARIANTS, index_GENERATE_TEXT_VOICES as GENERATE_TEXT_VOICES, index_GOOGLE_VISION_LIKELIHOOD_TO_SCORE as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, type index_GenerateTextArtifact as GenerateTextArtifact, type index_GenerateTextCallToAction as GenerateTextCallToAction, type index_GenerateTextChannel as GenerateTextChannel, type index_GenerateTextFormat as GenerateTextFormat, type index_GenerateTextKeyedItem as GenerateTextKeyedItem, type index_GenerateTextLengthLimit as GenerateTextLengthLimit, type index_GenerateTextOptions as GenerateTextOptions, type index_GenerateTextResult as GenerateTextResult, type index_GenerateTextVariant as GenerateTextVariant, type index_GenerateTextVoice as GenerateTextVoice, type index_GeneratedTextArtifact as GeneratedTextArtifact, type index_GeneratedTextVariant as GeneratedTextVariant, index_HIVE_SEXUAL_CATEGORIES as HIVE_SEXUAL_CATEGORIES, index_HIVE_VIOLENCE_CATEGORIES as HIVE_VIOLENCE_CATEGORIES, type index_HiveModerationOutput as HiveModerationOutput, type index_HiveModerationSource as HiveModerationSource, type index_ModerationOptions as ModerationOptions, type index_ModerationProvider as ModerationProvider, type index_ModerationResult as ModerationResult, type index_MomentInsight as MomentInsight, type index_OverallInsight as OverallInsight, type index_ProfanityDetectionPayload as ProfanityDetectionPayload, type index_Question as Question, type index_QuestionAnswer as QuestionAnswer, type index_QuestionAnswerType as QuestionAnswerType, type index_ReplacementRecord as ReplacementRecord, type index_SpeakerReplacement as SpeakerReplacement, type index_StaticRenditionCleanupOutcome as StaticRenditionCleanupOutcome, type index_SummarizationOptions as SummarizationOptions, type index_SummarizationPromptOverrides as SummarizationPromptOverrides, type index_SummarizationPromptSections as SummarizationPromptSections, type index_SummaryAndTagsResult as SummaryAndTagsResult, type index_SummaryType as SummaryType, type index_ThumbnailModerationScore as ThumbnailModerationScore, type index_TranslationChunkingOptions as TranslationChunkingOptions, type index_TranslationOptions as TranslationOptions, type index_TranslationPayload as TranslationPayload, type index_TranslationResult as TranslationResult, index_aggregateTokenUsage as aggregateTokenUsage, index_applyOverrideLists as applyOverrideLists, index_applyReplacements as applyReplacements, index_applySpeakerReplacements as applySpeakerReplacements, index_askQuestions as askQuestions, index_buildReplacementRegex as buildReplacementRegex, index_burnedInCaptionsSchema as burnedInCaptionsSchema, index_censorVttContent as censorVttContent, index_chapterSchema as chapterSchema, index_chaptersSchema as chaptersSchema, index_createReplacer as createReplacer, index_editCaptions as editCaptions, index_extractTranscriptSegmentsForHotspots as extractTranscriptSegmentsForHotspots, index_findGenerateTextLengthViolation as findGenerateTextLengthViolation, index_generateChapters as generateChapters, index_generateEmbeddings as generateEmbeddings, index_generateEngagementInsights as generateEngagementInsights, index_generateText as generateText, index_generateVideoEmbeddings as generateVideoEmbeddings, index_getModerationScores as getModerationScores, index_getSummaryAndTags as getSummaryAndTags, index_hasBurnedInCaptions as hasBurnedInCaptions, index_mapShotsToHotspots as mapShotsToHotspots, index_measureGenerateTextLength as measureGenerateTextLength, index_normalizeTranslatedVtt as normalizeTranslatedVtt, index_profanityDetectionSchema as profanityDetectionSchema, index_questionAnswerSchema as questionAnswerSchema, index_resolveGenerateTextLengthLimit as resolveGenerateTextLengthLimit, index_resolveGenerateTextLengthLimits as resolveGenerateTextLengthLimits, index_resolveGenerateTextOptions as resolveGenerateTextOptions, index_selectGenerateTextShotFrames as selectGenerateTextShotFrames, index_shouldSplitChunkTranslationError as shouldSplitChunkTranslationError, index_summarySchema as summarySchema, index_transformCueText as transformCueText, index_translateAudio as translateAudio, index_translateCaptions as translateCaptions, index_translationSchema as translationSchema, index_validateNeverTranslateTerms as validateNeverTranslateTerms, index_verifyNeverTranslateTerms as verifyNeverTranslateTerms };
|
|
1963
1979
|
}
|
|
1964
1980
|
|
|
1965
|
-
export { type
|
|
1981
|
+
export { type BurnedInCaptionsPromptSections as $, replaceAndCreateTextTrack as A, replaceAndCreateTrack as B, replaceSourceTrack as C, summarizeTextTrack as D, toISO639_1 as E, toISO639_3 as F, validateTrackPassthrough as G, index as H, type ISO639_1 as I, ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH as J, ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH as K, type LanguageCodePair as L, MUX_TRACK_PASSTHROUGH_MAX_CHARS as M, ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL as N, ASK_QUESTIONS_MAX_QUESTION_LENGTH as O, type AskQuestionsOptions as P, type AskQuestionsResult as Q, type ReplaceAndCreateTextTrackInput as R, type SourceTrackReplacementPolicy as S, type TextTrackReplacementPlan as T, type AskQuestionsType as U, type AudioTranslationOptions as V, type AudioTranslationResult as W, type AutoCensorProfanityOptions as X, type BurnedInCaptionsAnalysis as Y, type BurnedInCaptionsOptions as Z, type BurnedInCaptionsPromptOverrides as _, type ISO639_3 as a, type SummaryAndTagsResult as a$, type BurnedInCaptionsResult as a0, type CaptionReplacement as a1, type CensorMode as a2, type Chapter as a3, type ChapterSystemPromptSections as a4, type ChaptersOptions as a5, type ChaptersPromptOverrides as a6, type ChaptersPromptSections as a7, type ChaptersResult as a8, type ChaptersType as a9, type GenerateTextKeyedItem as aA, type GenerateTextLengthLimit as aB, type GenerateTextOptions as aC, type GenerateTextResult as aD, type GenerateTextVariant as aE, type GenerateTextVoice as aF, type GeneratedTextArtifact as aG, type GeneratedTextVariant as aH, HIVE_SEXUAL_CATEGORIES as aI, HIVE_VIOLENCE_CATEGORIES as aJ, type HiveModerationOutput as aK, type HiveModerationSource as aL, type ModerationOptions as aM, type ModerationProvider as aN, type ModerationResult as aO, type MomentInsight as aP, type OverallInsight as aQ, type ProfanityDetectionPayload as aR, type Question as aS, type QuestionAnswer as aT, type QuestionAnswerType as aU, type ReplacementRecord as aV, type SpeakerReplacement as aW, type StaticRenditionCleanupOutcome as aX, type SummarizationOptions as aY, type SummarizationPromptOverrides as aZ, type SummarizationPromptSections as a_, type EditCaptionsOptions as aa, type EditCaptionsResult as ab, type EmbeddingsOptions as ac, type EmbeddingsResult as ad, type EngagementInsightsOptions as ae, type EngagementInsightsResult as af, GENERATE_TEXT_CALLS_TO_ACTION as ag, GENERATE_TEXT_CHANNELS as ah, GENERATE_TEXT_CHANNEL_CEILINGS as ai, GENERATE_TEXT_FORMATS as aj, GENERATE_TEXT_LENGTH_BOUNDS as ak, GENERATE_TEXT_MAX_ARTIFACTS as al, GENERATE_TEXT_MAX_AUDIENCE_CHARS as am, GENERATE_TEXT_MAX_BRAND_TERMS as an, GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS as ao, GENERATE_TEXT_MAX_BRAND_TERM_CHARS as ap, GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS as aq, GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS as ar, GENERATE_TEXT_MAX_SHOT_FRAMES as as, GENERATE_TEXT_MAX_VARIANTS as at, GENERATE_TEXT_VOICES as au, GOOGLE_VISION_LIKELIHOOD_TO_SCORE as av, type GenerateTextArtifact as aw, type GenerateTextCallToAction as ax, type GenerateTextChannel as ay, type GenerateTextFormat as az, type ReplaceAndCreateTextTrackResult as b, type SummaryType as b0, type ThumbnailModerationScore as b1, type TranslationChunkingOptions as b2, type TranslationOptions as b3, type TranslationPayload as b4, type TranslationResult as b5, aggregateTokenUsage as b6, applyOverrideLists as b7, applyReplacements as b8, applySpeakerReplacements as b9, selectGenerateTextShotFrames as bA, shouldSplitChunkTranslationError as bB, summarySchema as bC, transformCueText as bD, translateAudio as bE, translateCaptions as bF, translationSchema as bG, validateNeverTranslateTerms as bH, verifyNeverTranslateTerms as bI, askQuestions as ba, buildReplacementRegex as bb, burnedInCaptionsSchema as bc, censorVttContent as bd, chapterSchema as be, chaptersSchema as bf, createReplacer as bg, editCaptions as bh, extractTranscriptSegmentsForHotspots as bi, findGenerateTextLengthViolation as bj, generateChapters as bk, generateEmbeddings as bl, generateEngagementInsights as bm, generateText as bn, generateVideoEmbeddings as bo, getModerationScores as bp, getSummaryAndTags as bq, hasBurnedInCaptions as br, mapShotsToHotspots as bs, measureGenerateTextLength as bt, normalizeTranslatedVtt as bu, profanityDetectionSchema as bv, questionAnswerSchema as bw, resolveGenerateTextLengthLimit as bx, resolveGenerateTextLengthLimits as by, resolveGenerateTextOptions as bz, type ReplaceAndCreateTrackInput as c, type ReplaceExistingTracksPolicy as d, type ReplaceSourceTrackInput as e, type ReplaceableTrackType as f, type SupportedISO639_1 as g, type SupportedISO639_3 as h, type TextTrackSummary as i, type TextTrackTarget as j, type TrackSummary as k, type TrackTarget as l, buildMuxAiTrackPassthrough as m, findNameCollisionTextTracks as n, findSameLanguageTextTracks as o, getLanguageCodePair as p, getLanguageName as q, isDuplicateTrackNameError as r, isMuxGeneratedTextTrack as s, isUndeterminedLanguageCode as t, isValidISO639_1 as u, isValidISO639_3 as v, normalizeTrackLanguageCode as w, normalizeTrackName as x, planSourceTrackReplacement as y, planTextTrackReplacement as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, M as MUX_TRACK_PASSTHROUGH_MAX_CHARS, R as ReplaceAndCreateTextTrackInput, b as ReplaceAndCreateTextTrackResult, c as ReplaceAndCreateTrackInput, d as ReplaceExistingTracksPolicy, e as ReplaceableTrackType, S as SupportedISO639_1,
|
|
1
|
+
export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, M as MUX_TRACK_PASSTHROUGH_MAX_CHARS, R as ReplaceAndCreateTextTrackInput, b as ReplaceAndCreateTextTrackResult, c as ReplaceAndCreateTrackInput, d as ReplaceExistingTracksPolicy, e as ReplaceSourceTrackInput, f as ReplaceableTrackType, S as SourceTrackReplacementPolicy, g as SupportedISO639_1, h as SupportedISO639_3, T as TextTrackReplacementPlan, i as TextTrackSummary, j as TextTrackTarget, k as TrackSummary, l as TrackTarget, m as buildMuxAiTrackPassthrough, n as findNameCollisionTextTracks, o as findSameLanguageTextTracks, p as getLanguageCodePair, q as getLanguageName, r as isDuplicateTrackNameError, s as isMuxGeneratedTextTrack, t as isUndeterminedLanguageCode, u as isValidISO639_1, v as isValidISO639_3, w as normalizeTrackLanguageCode, x as normalizeTrackName, y as planSourceTrackReplacement, z as planTextTrackReplacement, A as replaceAndCreateTextTrack, B as replaceAndCreateTrack, C as replaceSourceTrack, D as summarizeTextTrack, E as toISO639_1, F as toISO639_3, G as validateTrackPassthrough, H as workflows } from './index-DxAt9Jq8.js';
|
|
2
2
|
import { W as WorkflowCredentials, S as StoragePutObjectInput, a as StoragePresignGetObjectInput } from './shots-BwpjZDpr.js';
|
|
3
3
|
export { A as AssetTextTrack, C as ChunkEmbedding, b as ChunkingStrategy, E as Encrypted, c as EncryptedPayload, I as ImageSubmissionMode, M as MuxAIOptions, d as MuxAsset, P as PlaybackAsset, e as PlaybackPolicy, f as ScopedMuxAIOptions, g as StorageAdapter, T as TextChunk, h as TokenChunkingConfig, i as TokenUsage, j as ToneType, U as UsageMetadata, V as VTTChunkingConfig, k as VideoEmbeddingsResult, l as WorkflowCredentialsInput, m as WorkflowMuxClient, n as WorkflowScope, o as decryptFromWorkflow, p as encryptForWorkflow } from './shots-BwpjZDpr.js';
|
|
4
4
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
@@ -10,7 +10,7 @@ import '@ai-sdk/google';
|
|
|
10
10
|
import '@ai-sdk/openai';
|
|
11
11
|
import '@mux/ts';
|
|
12
12
|
|
|
13
|
-
var version = "0.
|
|
13
|
+
var version = "0.48.0";
|
|
14
14
|
|
|
15
15
|
type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_error" | "content_policy_error";
|
|
16
16
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.48.0";
|
|
9
9
|
|
|
10
10
|
// src/lib/language-codes.ts
|
|
11
11
|
var ISO639_1_TO_3 = {
|
|
@@ -1195,17 +1195,24 @@ function findNameCollisionTextTracks(asset, target) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
return listTracks(asset, targetType(target)).filter((track) => normalizeTrackName(track.name) === targetName);
|
|
1197
1197
|
}
|
|
1198
|
+
function countTracks(tracks, label, singularVerb, pluralVerb) {
|
|
1199
|
+
const kind = label.toLowerCase();
|
|
1200
|
+
if (tracks.length === 1) {
|
|
1201
|
+
return `${kind === "audio" ? "An" : "A"} ${kind} track ${singularVerb}`;
|
|
1202
|
+
}
|
|
1203
|
+
return `${tracks.length} ${kind} tracks ${pluralVerb}`;
|
|
1204
|
+
}
|
|
1205
|
+
function itOrThem(tracks) {
|
|
1206
|
+
return tracks.length === 1 ? "it" : "them";
|
|
1207
|
+
}
|
|
1198
1208
|
function describeTracks(tracks) {
|
|
1199
1209
|
return tracks.map((track) => `${track.name ?? "(unnamed)"} [${track.language_code ?? "?"}, ${track.type === "audio" ? track.primary ? "primary audio" : "audio" : track.text_source ?? "unknown source"}, ${track.status ?? "ready"}]`).join("; ");
|
|
1200
1210
|
}
|
|
1201
|
-
function planTextTrackReplacement(asset, target, policy
|
|
1211
|
+
function planTextTrackReplacement(asset, target, policy) {
|
|
1202
1212
|
const label = targetType(target) === "audio" ? "Audio" : "Text";
|
|
1203
|
-
const keep = new Set(options.keepTrackIds ?? []);
|
|
1204
1213
|
const conflicts = /* @__PURE__ */ new Map();
|
|
1205
1214
|
for (const track of [...findSameLanguageTextTracks(asset, target), ...findNameCollisionTextTracks(asset, target)]) {
|
|
1206
|
-
|
|
1207
|
-
conflicts.set(track.id, track);
|
|
1208
|
-
}
|
|
1215
|
+
conflicts.set(track.id, track);
|
|
1209
1216
|
}
|
|
1210
1217
|
const conflicting = [...conflicts.values()];
|
|
1211
1218
|
if (conflicting.length === 0) {
|
|
@@ -1214,7 +1221,7 @@ function planTextTrackReplacement(asset, target, policy, options = {}) {
|
|
|
1214
1221
|
if (policy === "fail") {
|
|
1215
1222
|
return {
|
|
1216
1223
|
kind: "blocked",
|
|
1217
|
-
reason: `${label
|
|
1224
|
+
reason: `${countTracks(conflicting, label, "already exists", "already exist")} for language '${target.languageCode}' or name '${target.name}': ${describeTracks(conflicting)}. Set replaceExistingTracks to replace ${itOrThem(conflicting)}.`,
|
|
1218
1225
|
tracks: conflicting.map(summarizeTextTrack)
|
|
1219
1226
|
};
|
|
1220
1227
|
}
|
|
@@ -1231,13 +1238,26 @@ function planTextTrackReplacement(asset, target, policy, options = {}) {
|
|
|
1231
1238
|
if (notGenerated.length > 0) {
|
|
1232
1239
|
return {
|
|
1233
1240
|
kind: "blocked",
|
|
1234
|
-
reason: `${label
|
|
1241
|
+
reason: `${countTracks(notGenerated, label, "that is not Mux-generated exists", "that are not Mux-generated exist")} for language '${target.languageCode}' or name '${target.name}': ${describeTracks(notGenerated)}. Use replaceExistingTracks: "replace_all" to replace ${itOrThem(notGenerated)}.`,
|
|
1235
1242
|
tracks: notGenerated.map(summarizeTextTrack)
|
|
1236
1243
|
};
|
|
1237
1244
|
}
|
|
1238
1245
|
}
|
|
1239
1246
|
return { kind: "replace", toDelete: conflicting.map(summarizeTextTrack) };
|
|
1240
1247
|
}
|
|
1248
|
+
function planSourceTrackReplacement(asset, sourceTrackId, target, policy) {
|
|
1249
|
+
const colliding = findNameCollisionTextTracks(asset, target);
|
|
1250
|
+
const blocking = policy === "fail" ? colliding : colliding.filter((track) => track.id !== sourceTrackId);
|
|
1251
|
+
if (blocking.length > 0) {
|
|
1252
|
+
return {
|
|
1253
|
+
kind: "blocked",
|
|
1254
|
+
reason: `${countTracks(blocking, "Text", "already has", "already have")} the name '${target.name}': ${describeTracks(blocking)}. Choose a different trackName.`,
|
|
1255
|
+
tracks: blocking.map(summarizeTextTrack)
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
const source = policy === "replace" ? listTracks(asset, targetType(target)).find((track) => track.id === sourceTrackId) : void 0;
|
|
1259
|
+
return source ? { kind: "replace", toDelete: [summarizeTextTrack(source)] } : { kind: "clear" };
|
|
1260
|
+
}
|
|
1241
1261
|
function isDuplicateTrackNameError(error) {
|
|
1242
1262
|
if (typeof error !== "object" || error === null) {
|
|
1243
1263
|
return false;
|
|
@@ -1293,6 +1313,14 @@ async function createTextTrackOnMux(assetId, languageCode, trackName, presignedU
|
|
|
1293
1313
|
}
|
|
1294
1314
|
async function replaceAndCreateTrack(input) {
|
|
1295
1315
|
"use step";
|
|
1316
|
+
return writeTrack(input, (asset) => planTextTrackReplacement(asset, input.target, input.policy));
|
|
1317
|
+
}
|
|
1318
|
+
async function replaceSourceTrack(input) {
|
|
1319
|
+
"use step";
|
|
1320
|
+
const target = { ...input.target, type: "text" };
|
|
1321
|
+
return writeTrack({ ...input, target }, (asset) => planSourceTrackReplacement(asset, input.sourceTrackId, target, input.policy));
|
|
1322
|
+
}
|
|
1323
|
+
async function writeTrack(input, plan) {
|
|
1296
1324
|
const muxClient = await resolveMuxClient(input.credentials);
|
|
1297
1325
|
const mux = await muxClient.createClient();
|
|
1298
1326
|
const type = targetType(input.target);
|
|
@@ -1312,12 +1340,12 @@ async function replaceAndCreateTrack(input) {
|
|
|
1312
1340
|
}
|
|
1313
1341
|
return failed(error);
|
|
1314
1342
|
}
|
|
1315
|
-
const
|
|
1316
|
-
if (
|
|
1317
|
-
return { ...
|
|
1343
|
+
const planned = plan(asset);
|
|
1344
|
+
if (planned.kind === "blocked") {
|
|
1345
|
+
return { ...planned, deleted };
|
|
1318
1346
|
}
|
|
1319
|
-
if (
|
|
1320
|
-
for (const track of
|
|
1347
|
+
if (planned.kind === "replace") {
|
|
1348
|
+
for (const track of planned.toDelete) {
|
|
1321
1349
|
try {
|
|
1322
1350
|
await mux.video.assets.deleteTrack(input.assetId, track.id);
|
|
1323
1351
|
deleted.push(track);
|
|
@@ -2297,17 +2325,15 @@ async function transformShotsResponse(data) {
|
|
|
2297
2325
|
status: "pending",
|
|
2298
2326
|
createdAt: data.created_at
|
|
2299
2327
|
};
|
|
2300
|
-
case "errored":
|
|
2301
|
-
const details = data.errors ?? data.error;
|
|
2328
|
+
case "errored":
|
|
2302
2329
|
return {
|
|
2303
2330
|
status: "errored",
|
|
2304
2331
|
createdAt: data.created_at,
|
|
2305
2332
|
error: {
|
|
2306
|
-
type:
|
|
2307
|
-
messages:
|
|
2333
|
+
type: data.errors?.type ?? "unknown",
|
|
2334
|
+
messages: data.errors?.messages ?? []
|
|
2308
2335
|
}
|
|
2309
2336
|
};
|
|
2310
|
-
}
|
|
2311
2337
|
case "completed":
|
|
2312
2338
|
if (!data.shots_manifest_url) {
|
|
2313
2339
|
throw new Error("Completed shots response is missing shots_manifest_url");
|
|
@@ -5496,7 +5522,13 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
5496
5522
|
{ type: "validation_error" }
|
|
5497
5523
|
);
|
|
5498
5524
|
}
|
|
5499
|
-
|
|
5525
|
+
if (replaceExistingTracksOption !== void 0 && replaceExistingTracksOption !== "replace" && replaceExistingTracksOption !== "fail") {
|
|
5526
|
+
throw new MuxAiError(
|
|
5527
|
+
`replaceExistingTracks must be "replace" or "fail" for editCaptions (received "${String(replaceExistingTracksOption)}").`,
|
|
5528
|
+
{ type: "validation_error" }
|
|
5529
|
+
);
|
|
5530
|
+
}
|
|
5531
|
+
const replaceExistingTracks = replaceExistingTracksOption ?? "replace";
|
|
5500
5532
|
if (!legacyTrackNaming && replaceExistingTracks === "fail" && !providedTrackName) {
|
|
5501
5533
|
throw new MuxAiError(
|
|
5502
5534
|
`trackName is required when replaceExistingTracks is "fail": the edited track cannot reuse the source track's name while the source is kept.`,
|
|
@@ -5552,15 +5584,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
5552
5584
|
languageCode: sourceLanguageCode,
|
|
5553
5585
|
name: providedTrackName ?? sourceName
|
|
5554
5586
|
};
|
|
5555
|
-
const keepTrackIds = replaceExistingTracks === "fail" ? [trackId] : [];
|
|
5556
5587
|
if (replaceExistingTracks === "fail" && normalizeTrackName(outputTrack.name) === normalizeTrackName(sourceName)) {
|
|
5557
5588
|
throw new MuxAiError(
|
|
5558
|
-
`trackName "${outputTrack.name}" matches the source track's name. Mux track names must be unique; choose a different trackName or use replaceExistingTracks: "
|
|
5589
|
+
`trackName "${outputTrack.name}" matches the source track's name. Mux track names must be unique; choose a different trackName or use replaceExistingTracks: "replace" to replace the source.`,
|
|
5559
5590
|
{ type: "validation_error" }
|
|
5560
5591
|
);
|
|
5561
5592
|
}
|
|
5562
5593
|
if (uploadToMux && !legacyTrackNaming) {
|
|
5563
|
-
const plan =
|
|
5594
|
+
const plan = planSourceTrackReplacement(assetData, trackId, outputTrack, replaceExistingTracks);
|
|
5564
5595
|
if (plan.kind === "blocked") {
|
|
5565
5596
|
throw new MuxAiError(plan.reason, { type: "validation_error" });
|
|
5566
5597
|
}
|
|
@@ -5682,14 +5713,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
5682
5713
|
} else if (uploadToMux) {
|
|
5683
5714
|
let outcome;
|
|
5684
5715
|
try {
|
|
5685
|
-
outcome = await
|
|
5716
|
+
outcome = await replaceSourceTrack({
|
|
5686
5717
|
assetId,
|
|
5718
|
+
sourceTrackId: trackId,
|
|
5687
5719
|
target: outputTrack,
|
|
5688
5720
|
policy: replaceExistingTracks,
|
|
5689
5721
|
presignedUrl,
|
|
5690
5722
|
closedCaptions: sourceTrack.closed_captions,
|
|
5691
5723
|
passthrough: trackPassthrough,
|
|
5692
|
-
keepTrackIds,
|
|
5693
5724
|
credentials
|
|
5694
5725
|
});
|
|
5695
5726
|
} catch (error) {
|
|
@@ -9889,10 +9920,12 @@ export {
|
|
|
9889
9920
|
isValidISO639_3,
|
|
9890
9921
|
normalizeTrackLanguageCode,
|
|
9891
9922
|
normalizeTrackName,
|
|
9923
|
+
planSourceTrackReplacement,
|
|
9892
9924
|
planTextTrackReplacement,
|
|
9893
9925
|
primitives_exports as primitives,
|
|
9894
9926
|
replaceAndCreateTextTrack,
|
|
9895
9927
|
replaceAndCreateTrack,
|
|
9928
|
+
replaceSourceTrack,
|
|
9896
9929
|
setWorkflowCredentialsProvider,
|
|
9897
9930
|
summarizeTextTrack,
|
|
9898
9931
|
toISO639_1,
|