@mux/ai 0.46.0 → 0.47.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.
@@ -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, options?: {
266
- keepTrackIds?: string[];
267
- }): TextTrackReplacementPlan;
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 ReplaceAndCreateTextTrackInput {
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 and any other text track in the same
842
- * language or with the same name as the edited track. Defaults to
843
- * `"replace_all"`: the edited track takes the source track's place.
844
- * `"fail"` keeps the source and requires `trackName`.
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?: ReplaceExistingTracksPolicy;
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
- /** Existing text tracks deleted before the edited track was created. Includes the source track when it was replaced. */
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 Chapter as $, toISO639_1 as A, toISO639_3 as B, validateTrackPassthrough as C, index as D, ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH as E, ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH as F, ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL as G, ASK_QUESTIONS_MAX_QUESTION_LENGTH as H, type ISO639_1 as I, type AskQuestionsOptions as J, type AskQuestionsResult as K, type LanguageCodePair as L, MUX_TRACK_PASSTHROUGH_MAX_CHARS as M, type AskQuestionsType as N, type AudioTranslationOptions as O, type AudioTranslationResult as P, type AutoCensorProfanityOptions as Q, type ReplaceAndCreateTextTrackInput as R, type SupportedISO639_1 as S, type TextTrackReplacementPlan as T, type BurnedInCaptionsAnalysis as U, type BurnedInCaptionsOptions as V, type BurnedInCaptionsPromptOverrides as W, type BurnedInCaptionsPromptSections as X, type BurnedInCaptionsResult as Y, type CaptionReplacement as Z, type CensorMode as _, type ISO639_3 as a, type TranslationOptions as a$, type ChapterSystemPromptSections as a0, type ChaptersOptions as a1, type ChaptersPromptOverrides as a2, type ChaptersPromptSections as a3, type ChaptersResult as a4, type ChaptersType as a5, type EditCaptionsOptions as a6, type EditCaptionsResult as a7, type EmbeddingsOptions as a8, type EmbeddingsResult as a9, type GenerateTextVariant as aA, type GenerateTextVoice as aB, type GeneratedTextArtifact as aC, type GeneratedTextVariant as aD, HIVE_SEXUAL_CATEGORIES as aE, HIVE_VIOLENCE_CATEGORIES as aF, type HiveModerationOutput as aG, type HiveModerationSource as aH, type ModerationOptions as aI, type ModerationProvider as aJ, type ModerationResult as aK, type MomentInsight as aL, type OverallInsight as aM, type ProfanityDetectionPayload as aN, type Question as aO, type QuestionAnswer as aP, type QuestionAnswerType as aQ, type ReplacementRecord as aR, type SpeakerReplacement as aS, type StaticRenditionCleanupOutcome as aT, type SummarizationOptions as aU, type SummarizationPromptOverrides as aV, type SummarizationPromptSections as aW, type SummaryAndTagsResult as aX, type SummaryType as aY, type ThumbnailModerationScore as aZ, type TranslationChunkingOptions as a_, type EngagementInsightsOptions as aa, type EngagementInsightsResult as ab, GENERATE_TEXT_CALLS_TO_ACTION as ac, GENERATE_TEXT_CHANNELS as ad, GENERATE_TEXT_CHANNEL_CEILINGS as ae, GENERATE_TEXT_FORMATS as af, GENERATE_TEXT_LENGTH_BOUNDS as ag, GENERATE_TEXT_MAX_ARTIFACTS as ah, GENERATE_TEXT_MAX_AUDIENCE_CHARS as ai, GENERATE_TEXT_MAX_BRAND_TERMS as aj, GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS as ak, GENERATE_TEXT_MAX_BRAND_TERM_CHARS as al, GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS as am, GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS as an, GENERATE_TEXT_MAX_SHOT_FRAMES as ao, GENERATE_TEXT_MAX_VARIANTS as ap, GENERATE_TEXT_VOICES as aq, GOOGLE_VISION_LIKELIHOOD_TO_SCORE as ar, type GenerateTextArtifact as as, type GenerateTextCallToAction as at, type GenerateTextChannel as au, type GenerateTextFormat as av, type GenerateTextKeyedItem as aw, type GenerateTextLengthLimit as ax, type GenerateTextOptions as ay, type GenerateTextResult as az, type ReplaceAndCreateTextTrackResult as b, type TranslationPayload as b0, type TranslationResult as b1, aggregateTokenUsage as b2, applyOverrideLists as b3, applyReplacements as b4, applySpeakerReplacements as b5, askQuestions as b6, buildReplacementRegex as b7, burnedInCaptionsSchema as b8, censorVttContent as b9, translateAudio as bA, translateCaptions as bB, translationSchema as bC, validateNeverTranslateTerms as bD, verifyNeverTranslateTerms as bE, chapterSchema as ba, chaptersSchema as bb, createReplacer as bc, editCaptions as bd, extractTranscriptSegmentsForHotspots as be, findGenerateTextLengthViolation as bf, generateChapters as bg, generateEmbeddings as bh, generateEngagementInsights as bi, generateText as bj, generateVideoEmbeddings as bk, getModerationScores as bl, getSummaryAndTags as bm, hasBurnedInCaptions as bn, mapShotsToHotspots as bo, measureGenerateTextLength as bp, normalizeTranslatedVtt as bq, profanityDetectionSchema as br, questionAnswerSchema as bs, resolveGenerateTextLengthLimit as bt, resolveGenerateTextLengthLimits as bu, resolveGenerateTextOptions as bv, selectGenerateTextShotFrames as bw, shouldSplitChunkTranslationError as bx, summarySchema as by, transformCueText as bz, type ReplaceAndCreateTrackInput as c, type ReplaceExistingTracksPolicy as d, type ReplaceableTrackType as e, type SupportedISO639_3 as f, type TextTrackSummary as g, type TextTrackTarget as h, type TrackSummary as i, type TrackTarget as j, buildMuxAiTrackPassthrough as k, findNameCollisionTextTracks as l, findSameLanguageTextTracks as m, getLanguageCodePair as n, getLanguageName as o, isDuplicateTrackNameError as p, isMuxGeneratedTextTrack as q, isUndeterminedLanguageCode as r, isValidISO639_1 as s, isValidISO639_3 as t, normalizeTrackLanguageCode as u, normalizeTrackName as v, planTextTrackReplacement as w, replaceAndCreateTextTrack as x, replaceAndCreateTrack as y, summarizeTextTrack as z };
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, f as SupportedISO639_3, T as TextTrackReplacementPlan, g as TextTrackSummary, h as TextTrackTarget, i as TrackSummary, j as TrackTarget, k as buildMuxAiTrackPassthrough, l as findNameCollisionTextTracks, m as findSameLanguageTextTracks, n as getLanguageCodePair, o as getLanguageName, p as isDuplicateTrackNameError, q as isMuxGeneratedTextTrack, r as isUndeterminedLanguageCode, s as isValidISO639_1, t as isValidISO639_3, u as normalizeTrackLanguageCode, v as normalizeTrackName, w as planTextTrackReplacement, x as replaceAndCreateTextTrack, y as replaceAndCreateTrack, z as summarizeTextTrack, A as toISO639_1, B as toISO639_3, C as validateTrackPassthrough, D as workflows } from './index-CIcGZD3x.js';
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.46.0";
13
+ var version = "0.47.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.46.0";
8
+ var version = "0.47.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, options = {}) {
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
- if (!keep.has(track.id)) {
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} track(s) already exist for language '${target.languageCode}' or name '${target.name}': ${describeTracks(conflicting)}. Set replaceExistingTracks to replace them.`,
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} track(s) that are not Mux-generated exist for language '${target.languageCode}' or name '${target.name}': ${describeTracks(notGenerated)}. Use replaceExistingTracks: "replace_all" to replace them.`,
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 plan = planTextTrackReplacement(asset, input.target, input.policy, { keepTrackIds: input.keepTrackIds });
1316
- if (plan.kind === "blocked") {
1317
- return { ...plan, deleted };
1343
+ const planned = plan(asset);
1344
+ if (planned.kind === "blocked") {
1345
+ return { ...planned, deleted };
1318
1346
  }
1319
- if (plan.kind === "replace") {
1320
- for (const track of plan.toDelete) {
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);
@@ -5496,7 +5524,13 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5496
5524
  { type: "validation_error" }
5497
5525
  );
5498
5526
  }
5499
- const replaceExistingTracks = replaceExistingTracksOption ?? "replace_all";
5527
+ if (replaceExistingTracksOption !== void 0 && replaceExistingTracksOption !== "replace" && replaceExistingTracksOption !== "fail") {
5528
+ throw new MuxAiError(
5529
+ `replaceExistingTracks must be "replace" or "fail" for editCaptions (received "${String(replaceExistingTracksOption)}").`,
5530
+ { type: "validation_error" }
5531
+ );
5532
+ }
5533
+ const replaceExistingTracks = replaceExistingTracksOption ?? "replace";
5500
5534
  if (!legacyTrackNaming && replaceExistingTracks === "fail" && !providedTrackName) {
5501
5535
  throw new MuxAiError(
5502
5536
  `trackName is required when replaceExistingTracks is "fail": the edited track cannot reuse the source track's name while the source is kept.`,
@@ -5552,15 +5586,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5552
5586
  languageCode: sourceLanguageCode,
5553
5587
  name: providedTrackName ?? sourceName
5554
5588
  };
5555
- const keepTrackIds = replaceExistingTracks === "fail" ? [trackId] : [];
5556
5589
  if (replaceExistingTracks === "fail" && normalizeTrackName(outputTrack.name) === normalizeTrackName(sourceName)) {
5557
5590
  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: "replace_all" to replace the source.`,
5591
+ `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
5592
  { type: "validation_error" }
5560
5593
  );
5561
5594
  }
5562
5595
  if (uploadToMux && !legacyTrackNaming) {
5563
- const plan = planTextTrackReplacement(assetData, outputTrack, replaceExistingTracks, { keepTrackIds });
5596
+ const plan = planSourceTrackReplacement(assetData, trackId, outputTrack, replaceExistingTracks);
5564
5597
  if (plan.kind === "blocked") {
5565
5598
  throw new MuxAiError(plan.reason, { type: "validation_error" });
5566
5599
  }
@@ -5682,14 +5715,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5682
5715
  } else if (uploadToMux) {
5683
5716
  let outcome;
5684
5717
  try {
5685
- outcome = await replaceAndCreateTextTrack({
5718
+ outcome = await replaceSourceTrack({
5686
5719
  assetId,
5720
+ sourceTrackId: trackId,
5687
5721
  target: outputTrack,
5688
5722
  policy: replaceExistingTracks,
5689
5723
  presignedUrl,
5690
5724
  closedCaptions: sourceTrack.closed_captions,
5691
5725
  passthrough: trackPassthrough,
5692
- keepTrackIds,
5693
5726
  credentials
5694
5727
  });
5695
5728
  } catch (error) {
@@ -9889,10 +9922,12 @@ export {
9889
9922
  isValidISO639_3,
9890
9923
  normalizeTrackLanguageCode,
9891
9924
  normalizeTrackName,
9925
+ planSourceTrackReplacement,
9892
9926
  planTextTrackReplacement,
9893
9927
  primitives_exports as primitives,
9894
9928
  replaceAndCreateTextTrack,
9895
9929
  replaceAndCreateTrack,
9930
+ replaceSourceTrack,
9896
9931
  setWorkflowCredentialsProvider,
9897
9932
  summarizeTextTrack,
9898
9933
  toISO639_1,