@mux/ai 0.35.0 → 0.37.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
@@ -124,6 +124,9 @@ const result = await editCaptions("your-asset-id", "track-id", {
124
124
  replacements: [
125
125
  { find: "Mucks", replace: "Mux" },
126
126
  ],
127
+ speakerReplacements: [
128
+ { find: "speaker_0", replace: "Alice" },
129
+ ],
127
130
  });
128
131
 
129
132
  console.log(result.totalReplacementCount); // 8
@@ -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 { f as ScopedMuxAIOptions, I as ImageSubmissionMode, i as TokenUsage, M as MuxAIOptions, b as ChunkingStrategy, k as VideoEmbeddingsResult, H as Hotspot, v as Shot, j as ToneType, g as StorageAdapter } from './shots-BMbViFbZ.js';
5
+ import { f as ScopedMuxAIOptions, I as ImageSubmissionMode, i as TokenUsage, M as MuxAIOptions, b as ChunkingStrategy, k as VideoEmbeddingsResult, H as Hotspot, v as Shot, j as ToneType, g as StorageAdapter } from './shots-CUI09Ohe.js';
6
6
 
7
7
  /**
8
8
  * Language Code Conversion Utilities
@@ -740,6 +740,12 @@ interface CaptionReplacement {
740
740
  /** Match `find` with case-sensitivity. Defaults to `true`. */
741
741
  caseSensitive?: boolean;
742
742
  }
743
+ interface SpeakerReplacement {
744
+ /** Current speaker label, without the surrounding square brackets. */
745
+ find: string;
746
+ /** New speaker label, without the surrounding square brackets. */
747
+ replace: string;
748
+ }
743
749
  interface ReplacementRecord {
744
750
  cueStartTime: number;
745
751
  before: string;
@@ -755,6 +761,8 @@ interface EditCaptionsOptions<P extends SupportedProvider = SupportedProvider> e
755
761
  autoCensorProfanity?: AutoCensorProfanityOptions;
756
762
  /** Static find/replace pairs (no LLM needed). */
757
763
  replacements?: CaptionReplacement[];
764
+ /** Replacements applied only to bracketed speaker labels at the start of cues. */
765
+ speakerReplacements?: SpeakerReplacement[];
758
766
  /** Delete the original track after creating the edited one. Defaults to true. */
759
767
  deleteOriginalTrack?: boolean;
760
768
  /**
@@ -795,6 +803,9 @@ interface EditCaptionsResult {
795
803
  replacements?: {
796
804
  replacements: ReplacementRecord[];
797
805
  };
806
+ speakerReplacements?: {
807
+ replacements: ReplacementRecord[];
808
+ };
798
809
  uploadedTrackId?: string;
799
810
  presignedUrl?: string;
800
811
  usage?: TokenUsage;
@@ -880,6 +891,14 @@ declare function applyReplacements(rawVtt: string, replacements: CaptionReplacem
880
891
  editedVtt: string;
881
892
  replacements: ReplacementRecord[];
882
893
  };
894
+ /**
895
+ * Replaces bracketed speaker labels only when they appear at the start of a cue.
896
+ * Spoken text that happens to contain the same value is left unchanged.
897
+ */
898
+ declare function applySpeakerReplacements(rawVtt: string, speakerReplacements: SpeakerReplacement[]): {
899
+ editedVtt: string;
900
+ replacements: ReplacementRecord[];
901
+ };
883
902
  declare function editCaptions<P extends SupportedProvider = SupportedProvider>(assetId: string, trackId: string, options: EditCaptionsOptions<P>): Promise<EditCaptionsResult>;
884
903
 
885
904
  /** Configuration accepted by `generateEmbeddings`. */
@@ -1545,6 +1564,7 @@ type index_Question = Question;
1545
1564
  type index_QuestionAnswer = QuestionAnswer;
1546
1565
  type index_QuestionAnswerType = QuestionAnswerType;
1547
1566
  type index_ReplacementRecord = ReplacementRecord;
1567
+ type index_SpeakerReplacement = SpeakerReplacement;
1548
1568
  type index_StaticRenditionCleanupOutcome = StaticRenditionCleanupOutcome;
1549
1569
  type index_SummarizationOptions = SummarizationOptions;
1550
1570
  type index_SummarizationPromptOverrides = SummarizationPromptOverrides;
@@ -1559,6 +1579,7 @@ type index_TranslationResult = TranslationResult;
1559
1579
  declare const index_aggregateTokenUsage: typeof aggregateTokenUsage;
1560
1580
  declare const index_applyOverrideLists: typeof applyOverrideLists;
1561
1581
  declare const index_applyReplacements: typeof applyReplacements;
1582
+ declare const index_applySpeakerReplacements: typeof applySpeakerReplacements;
1562
1583
  declare const index_askQuestions: typeof askQuestions;
1563
1584
  declare const index_buildReplacementRegex: typeof buildReplacementRegex;
1564
1585
  declare const index_burnedInCaptionsSchema: typeof burnedInCaptionsSchema;
@@ -1588,7 +1609,7 @@ declare const index_translationSchema: typeof translationSchema;
1588
1609
  declare const index_validateNeverTranslateTerms: typeof validateNeverTranslateTerms;
1589
1610
  declare const index_verifyNeverTranslateTerms: typeof verifyNeverTranslateTerms;
1590
1611
  declare namespace index {
1591
- 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_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_GOOGLE_VISION_LIKELIHOOD_TO_SCORE as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, 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_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_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_generateChapters as generateChapters, index_generateEmbeddings as generateEmbeddings, index_generateEngagementInsights as generateEngagementInsights, index_generateVideoEmbeddings as generateVideoEmbeddings, index_getModerationScores as getModerationScores, index_getSummaryAndTags as getSummaryAndTags, index_hasBurnedInCaptions as hasBurnedInCaptions, index_mapShotsToHotspots as mapShotsToHotspots, index_normalizeTranslatedVtt as normalizeTranslatedVtt, index_profanityDetectionSchema as profanityDetectionSchema, index_questionAnswerSchema as questionAnswerSchema, 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 };
1612
+ 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_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_GOOGLE_VISION_LIKELIHOOD_TO_SCORE as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, 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_generateChapters as generateChapters, index_generateEmbeddings as generateEmbeddings, index_generateEngagementInsights as generateEngagementInsights, index_generateVideoEmbeddings as generateVideoEmbeddings, index_getModerationScores as getModerationScores, index_getSummaryAndTags as getSummaryAndTags, index_hasBurnedInCaptions as hasBurnedInCaptions, index_mapShotsToHotspots as mapShotsToHotspots, index_normalizeTranslatedVtt as normalizeTranslatedVtt, index_profanityDetectionSchema as profanityDetectionSchema, index_questionAnswerSchema as questionAnswerSchema, 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 };
1592
1613
  }
1593
1614
 
1594
- export { type MomentInsight as $, ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH as A, type BurnedInCaptionsAnalysis as B, type CaptionReplacement as C, type ChaptersPromptOverrides as D, type ChaptersPromptSections as E, type ChaptersResult as F, type ChaptersType as G, DEFAULT_DESCRIPTION_LENGTH as H, type ISO639_1 as I, DEFAULT_SUMMARY_KEYWORD_LIMIT as J, DEFAULT_TITLE_LENGTH as K, type LanguageCodePair as L, type EditCaptionsOptions as M, type EditCaptionsResult as N, type EmbeddingsOptions as O, type EmbeddingsResult as P, type EngagementInsightsOptions as Q, type EngagementInsightsResult as R, type SupportedISO639_1 as S, GOOGLE_VISION_LIKELIHOOD_TO_SCORE as T, HIVE_SEXUAL_CATEGORIES as U, HIVE_VIOLENCE_CATEGORIES as V, type HiveModerationOutput as W, type HiveModerationSource as X, type ModerationOptions as Y, type ModerationProvider as Z, type ModerationResult as _, type ISO639_3 as a, type OverallInsight as a0, type ProfanityDetectionPayload as a1, type Question as a2, type QuestionAnswer as a3, type QuestionAnswerType as a4, type ReplacementRecord as a5, type StaticRenditionCleanupOutcome as a6, type SummarizationOptions as a7, type SummarizationPromptOverrides as a8, type SummarizationPromptSections as a9, mapShotsToHotspots as aA, normalizeTranslatedVtt as aB, profanityDetectionSchema as aC, questionAnswerSchema as aD, shouldSplitChunkTranslationError as aE, summarySchema as aF, transformCueText as aG, translateAudio as aH, translateCaptions as aI, translationSchema as aJ, validateNeverTranslateTerms as aK, verifyNeverTranslateTerms as aL, type SummaryAndTagsResult as aa, type SummaryType as ab, type ThumbnailModerationScore as ac, type TranslationChunkingOptions as ad, type TranslationOptions as ae, type TranslationPayload as af, type TranslationResult as ag, aggregateTokenUsage as ah, applyOverrideLists as ai, applyReplacements as aj, askQuestions as ak, buildReplacementRegex as al, burnedInCaptionsSchema as am, censorVttContent as an, chapterSchema as ao, chaptersSchema as ap, createReplacer as aq, editCaptions as ar, extractTranscriptSegmentsForHotspots as as, generateChapters as at, generateEmbeddings as au, generateEngagementInsights as av, generateVideoEmbeddings as aw, getModerationScores as ax, getSummaryAndTags as ay, hasBurnedInCaptions as az, type SupportedISO639_3 as b, getLanguageName as c, isValidISO639_1 as d, isValidISO639_3 as e, toISO639_3 as f, getLanguageCodePair as g, index as h, isUndeterminedLanguageCode as i, ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH as j, ASK_QUESTIONS_MAX_QUESTION_LENGTH as k, type AskQuestionsOptions as l, type AskQuestionsResult as m, type AskQuestionsType as n, type AudioTranslationOptions as o, type AudioTranslationResult as p, type AutoCensorProfanityOptions as q, type BurnedInCaptionsOptions as r, type BurnedInCaptionsPromptOverrides as s, toISO639_1 as t, type BurnedInCaptionsPromptSections as u, type BurnedInCaptionsResult as v, type CensorMode as w, type Chapter as x, type ChapterSystemPromptSections as y, type ChaptersOptions as z };
1615
+ export { type MomentInsight as $, ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH as A, type BurnedInCaptionsAnalysis as B, type CaptionReplacement as C, type ChaptersPromptOverrides as D, type ChaptersPromptSections as E, type ChaptersResult as F, type ChaptersType as G, DEFAULT_DESCRIPTION_LENGTH as H, type ISO639_1 as I, DEFAULT_SUMMARY_KEYWORD_LIMIT as J, DEFAULT_TITLE_LENGTH as K, type LanguageCodePair as L, type EditCaptionsOptions as M, type EditCaptionsResult as N, type EmbeddingsOptions as O, type EmbeddingsResult as P, type EngagementInsightsOptions as Q, type EngagementInsightsResult as R, type SupportedISO639_1 as S, GOOGLE_VISION_LIKELIHOOD_TO_SCORE as T, HIVE_SEXUAL_CATEGORIES as U, HIVE_VIOLENCE_CATEGORIES as V, type HiveModerationOutput as W, type HiveModerationSource as X, type ModerationOptions as Y, type ModerationProvider as Z, type ModerationResult as _, type ISO639_3 as a, type OverallInsight as a0, type ProfanityDetectionPayload as a1, type Question as a2, type QuestionAnswer as a3, type QuestionAnswerType as a4, type ReplacementRecord as a5, type SpeakerReplacement as a6, type StaticRenditionCleanupOutcome as a7, type SummarizationOptions as a8, type SummarizationPromptOverrides as a9, getSummaryAndTags as aA, hasBurnedInCaptions as aB, mapShotsToHotspots as aC, normalizeTranslatedVtt as aD, profanityDetectionSchema as aE, questionAnswerSchema as aF, shouldSplitChunkTranslationError as aG, summarySchema as aH, transformCueText as aI, translateAudio as aJ, translateCaptions as aK, translationSchema as aL, validateNeverTranslateTerms as aM, verifyNeverTranslateTerms as aN, type SummarizationPromptSections as aa, type SummaryAndTagsResult as ab, type SummaryType as ac, type ThumbnailModerationScore as ad, type TranslationChunkingOptions as ae, type TranslationOptions as af, type TranslationPayload as ag, type TranslationResult as ah, aggregateTokenUsage as ai, applyOverrideLists as aj, applyReplacements as ak, applySpeakerReplacements as al, askQuestions as am, buildReplacementRegex as an, burnedInCaptionsSchema as ao, censorVttContent as ap, chapterSchema as aq, chaptersSchema as ar, createReplacer as as, editCaptions as at, extractTranscriptSegmentsForHotspots as au, generateChapters as av, generateEmbeddings as aw, generateEngagementInsights as ax, generateVideoEmbeddings as ay, getModerationScores as az, type SupportedISO639_3 as b, getLanguageName as c, isValidISO639_1 as d, isValidISO639_3 as e, toISO639_3 as f, getLanguageCodePair as g, index as h, isUndeterminedLanguageCode as i, ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH as j, ASK_QUESTIONS_MAX_QUESTION_LENGTH as k, type AskQuestionsOptions as l, type AskQuestionsResult as m, type AskQuestionsType as n, type AudioTranslationOptions as o, type AudioTranslationResult as p, type AutoCensorProfanityOptions as q, type BurnedInCaptionsOptions as r, type BurnedInCaptionsPromptOverrides as s, toISO639_1 as t, type BurnedInCaptionsPromptSections as u, type BurnedInCaptionsResult as v, type CensorMode as w, type Chapter as x, type ChapterSystemPromptSections as y, type ChaptersOptions as z };
@@ -1,4 +1,4 @@
1
- import { l as WorkflowCredentialsInput, n as WorkflowScope, A as AssetTextTrack, d as MuxAsset, T as TextChunk, b as ChunkingStrategy, q as CompletedShotsResult, r as ErroredShotsResult, H as Hotspot, s as HotspotOptions, t as HotspotResponse, u as PendingShotsResult, v as Shot, w as ShotRequestOptions, x as ShotsResult, y as WaitForShotsOptions, z as getHotspotsForAsset, B as getHotspotsForPlaybackId, D as getHotspotsForVideo, F as getShotsForAsset, G as requestShotsForAsset, J as waitForShotsForAsset } from './shots-BMbViFbZ.js';
1
+ import { l as WorkflowCredentialsInput, n as WorkflowScope, A as AssetTextTrack, d as MuxAsset, T as TextChunk, b as ChunkingStrategy, q as CompletedShotsResult, r as ErroredShotsResult, H as Hotspot, s as HotspotOptions, t as HotspotResponse, u as PendingShotsResult, v as Shot, w as ShotRequestOptions, x as ShotsResult, y as WaitForShotsOptions, z as getHotspotsForAsset, B as getHotspotsForPlaybackId, D as getHotspotsForVideo, F as getShotsForAsset, G as requestShotsForAsset, J as waitForShotsForAsset } from './shots-CUI09Ohe.js';
2
2
 
3
3
  interface HeatmapOptions {
4
4
  /** Time window for results, e.g., '7:days' (default: '7:days') */
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, S as SupportedISO639_1, b as SupportedISO639_3, g as getLanguageCodePair, c as getLanguageName, i as isUndeterminedLanguageCode, d as isValidISO639_1, e as isValidISO639_3, t as toISO639_1, f as toISO639_3, h as workflows } from './index-fU3hmKZu.js';
2
- import { W as WorkflowCredentials, S as StoragePutObjectInput, a as StoragePresignGetObjectInput } from './shots-BMbViFbZ.js';
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-BMbViFbZ.js';
1
+ export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, S as SupportedISO639_1, b as SupportedISO639_3, g as getLanguageCodePair, c as getLanguageName, i as isUndeterminedLanguageCode, d as isValidISO639_1, e as isValidISO639_3, t as toISO639_1, f as toISO639_3, h as workflows } from './index-BupL84pY.js';
2
+ import { W as WorkflowCredentials, S as StoragePutObjectInput, a as StoragePresignGetObjectInput } from './shots-CUI09Ohe.js';
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-CUI09Ohe.js';
4
4
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
5
- export { i as primitives } from './index-SjpXUdXl.js';
5
+ export { i as primitives } from './index-C2Pk7bbF.js';
6
6
  import 'zod';
7
7
  import '@ai-sdk/anthropic';
8
8
  import '@ai-sdk/google';
9
9
  import '@ai-sdk/openai';
10
10
  import '@mux/mux-node';
11
11
 
12
- var version = "0.35.0";
12
+ var version = "0.37.0";
13
13
 
14
14
  type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_error" | "content_policy_error";
15
15
  /**
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.35.0";
8
+ var version = "0.37.0";
9
9
 
10
10
  // src/lib/language-codes.ts
11
11
  var ISO639_1_TO_3 = {
@@ -2534,9 +2534,12 @@ function toPlaybackAsset(asset) {
2534
2534
  const { id: playbackId, policy } = getPlaybackId(asset);
2535
2535
  return { asset, playbackId, policy };
2536
2536
  }
2537
- async function getPlaybackIdForAsset(assetId, credentials) {
2537
+ async function getPlaybackIdForAsset(assetId, credentials, assetSnapshot) {
2538
2538
  "use step";
2539
- const asset = await getMuxAsset(assetId, credentials);
2539
+ const asset = assetSnapshot ?? await getMuxAsset(assetId, credentials);
2540
+ if (asset.id !== assetId) {
2541
+ throw new MuxAiError("Asset snapshot does not match the requested asset ID.", { type: "validation_error" });
2542
+ }
2540
2543
  return toPlaybackAsset(asset);
2541
2544
  }
2542
2545
  async function getMuxAsset(assetId, credentials) {
@@ -3019,6 +3022,7 @@ __export(workflows_exports, {
3019
3022
  aggregateTokenUsage: () => aggregateTokenUsage,
3020
3023
  applyOverrideLists: () => applyOverrideLists,
3021
3024
  applyReplacements: () => applyReplacements,
3025
+ applySpeakerReplacements: () => applySpeakerReplacements,
3022
3026
  askQuestions: () => askQuestions,
3023
3027
  buildReplacementRegex: () => buildReplacementRegex,
3024
3028
  burnedInCaptionsSchema: () => burnedInCaptionsSchema,
@@ -3990,7 +3994,7 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
3990
3994
  model,
3991
3995
  provider
3992
3996
  });
3993
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
3997
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options?.assetSnapshot);
3994
3998
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
3995
3999
  const isAudioOnly = isAudioOnlyAsset(assetData);
3996
4000
  const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
@@ -4344,7 +4348,7 @@ async function hasBurnedInCaptionsInternal(assetId, options, collectedUsage) {
4344
4348
  model,
4345
4349
  provider
4346
4350
  });
4347
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
4351
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
4348
4352
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
4349
4353
  const storyboardScope = resolveRenderableVideoScope(
4350
4354
  scope,
@@ -4609,7 +4613,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
4609
4613
  model,
4610
4614
  provider
4611
4615
  });
4612
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
4616
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
4613
4617
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
4614
4618
  const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
4615
4619
  const resolvedScope = effectiveScope ? resolveWorkflowScope(effectiveScope, assetDurationSeconds) : void 0;
@@ -4959,6 +4963,27 @@ function applyReplacements(rawVtt, replacements) {
4959
4963
  });
4960
4964
  return { editedVtt, replacements: records };
4961
4965
  }
4966
+ function applySpeakerReplacements(rawVtt, speakerReplacements) {
4967
+ const replacementsByLabel = new Map(
4968
+ speakerReplacements.filter((replacement) => replacement.find.length > 0).map((replacement) => [replacement.find, replacement.replace])
4969
+ );
4970
+ if (replacementsByLabel.size === 0) {
4971
+ return { editedVtt: rawVtt, replacements: [] };
4972
+ }
4973
+ const records = [];
4974
+ const editedVtt = transformCueTextBlocks(rawVtt, (cueText, cueStartTime) => {
4975
+ return cueText.replace(/^(\s*)\[([^\]\r\n]+)\](?=\s|$)/, (marker, leadingWhitespace, label) => {
4976
+ const replacement = replacementsByLabel.get(label);
4977
+ if (replacement === void 0)
4978
+ return marker;
4979
+ const before = `[${label}]`;
4980
+ const after = `[${replacement}]`;
4981
+ records.push({ cueStartTime, before, after });
4982
+ return `${leadingWhitespace}${after}`;
4983
+ });
4984
+ });
4985
+ return { editedVtt, replacements: records };
4986
+ }
4962
4987
  async function identifyProfanityWithAI({
4963
4988
  plainText,
4964
4989
  provider,
@@ -5061,6 +5086,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5061
5086
  model,
5062
5087
  autoCensorProfanity: autoCensorOption,
5063
5088
  replacements: replacementsOption,
5089
+ speakerReplacements: speakerReplacementsOption,
5064
5090
  deleteOriginalTrack,
5065
5091
  uploadToS3: uploadToS3Option,
5066
5092
  uploadToMux: uploadToMuxOption,
@@ -5073,8 +5099,9 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5073
5099
  } = options;
5074
5100
  const hasAutoCensor = !!autoCensorOption;
5075
5101
  const hasReplacements = !!replacementsOption && replacementsOption.length > 0;
5076
- if (!hasAutoCensor && !hasReplacements) {
5077
- throw new MuxAiError("At least one of autoCensorProfanity or replacements must be provided.", { type: "validation_error" });
5102
+ const hasSpeakerReplacements = !!speakerReplacementsOption && speakerReplacementsOption.length > 0;
5103
+ if (!hasAutoCensor && !hasReplacements && !hasSpeakerReplacements) {
5104
+ throw new MuxAiError("At least one of autoCensorProfanity, replacements, or speakerReplacements must be provided.", { type: "validation_error" });
5078
5105
  }
5079
5106
  if (autoCensorOption && !provider) {
5080
5107
  throw new MuxAiError("provider is required when using autoCensorProfanity.", { type: "validation_error" });
@@ -5082,6 +5109,16 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5082
5109
  const deleteOriginal = deleteOriginalTrack !== false;
5083
5110
  const uploadToMux = uploadToMuxOption !== false;
5084
5111
  const uploadToS3 = uploadToS3Option || uploadToMux;
5112
+ for (const replacement of speakerReplacementsOption ?? []) {
5113
+ const hasInvalidFindCharacter = replacement.find.includes("[") || replacement.find.includes("]") || /[\r\n]/.test(replacement.find);
5114
+ const hasInvalidReplaceCharacter = replacement.replace.includes("[") || replacement.replace.includes("]") || /[\r\n]/.test(replacement.replace);
5115
+ if (!replacement.find || !replacement.replace || hasInvalidFindCharacter || hasInvalidReplaceCharacter) {
5116
+ throw new MuxAiError(
5117
+ "Speaker replacement labels must be non-empty and must not contain square brackets or newlines.",
5118
+ { type: "validation_error" }
5119
+ );
5120
+ }
5121
+ }
5085
5122
  const s3Endpoint = providedS3Endpoint ?? env_default.S3_ENDPOINT;
5086
5123
  const s3Region = providedS3Region ?? env_default.S3_REGION ?? "auto";
5087
5124
  const s3Bucket = providedS3Bucket ?? env_default.S3_BUCKET;
@@ -5093,7 +5130,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5093
5130
  { type: "validation_error" }
5094
5131
  );
5095
5132
  }
5096
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
5133
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
5097
5134
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
5098
5135
  const signingContext = await resolveMuxSigningContext(credentials);
5099
5136
  if (policy === "signed" && !signingContext) {
@@ -5163,6 +5200,16 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5163
5200
  totalReplacementCount += censorReplacements.length;
5164
5201
  autoCensorResult = { replacements: censorReplacements };
5165
5202
  }
5203
+ let speakerReplacementsResult;
5204
+ if (speakerReplacementsOption && speakerReplacementsOption.length > 0) {
5205
+ const { editedVtt: afterSpeakerReplacements, replacements: speakerReplacements } = applySpeakerReplacements(
5206
+ editedVtt,
5207
+ speakerReplacementsOption
5208
+ );
5209
+ editedVtt = afterSpeakerReplacements;
5210
+ totalReplacementCount += speakerReplacements.length;
5211
+ speakerReplacementsResult = { replacements: speakerReplacements };
5212
+ }
5166
5213
  let replacementsResult;
5167
5214
  if (replacementsOption && replacementsOption.length > 0) {
5168
5215
  const { editedVtt: afterReplacements, replacements: staticReplacements } = applyReplacements(editedVtt, replacementsOption);
@@ -5225,6 +5272,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
5225
5272
  totalReplacementCount,
5226
5273
  autoCensorProfanity: autoCensorResult,
5227
5274
  replacements: replacementsResult,
5275
+ speakerReplacements: speakerReplacementsResult,
5228
5276
  uploadedTrackId,
5229
5277
  presignedUrl,
5230
5278
  usage: usageWithMetadata,
@@ -5289,7 +5337,7 @@ async function generateEmbeddingsInternal(assetId, options, collectedUsage) {
5289
5337
  scope
5290
5338
  } = options;
5291
5339
  const embeddingModel = resolveEmbeddingModelConfig({ ...options, provider, model });
5292
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
5340
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
5293
5341
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
5294
5342
  const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
5295
5343
  if (effectiveScope) {
@@ -5763,7 +5811,7 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
5763
5811
  model,
5764
5812
  provider
5765
5813
  });
5766
- const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
5814
+ const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
5767
5815
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(asset);
5768
5816
  if (!assetDurationSeconds) {
5769
5817
  throw new MuxAiError(`Asset ${assetId} has no valid duration.`, { type: "validation_error" });
@@ -6480,7 +6528,7 @@ async function getModerationScores(assetId, options = {}) {
6480
6528
  scope
6481
6529
  } = options;
6482
6530
  const credentials = providedCredentials;
6483
- const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
6531
+ const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
6484
6532
  const videoTrackDurationSeconds = getVideoTrackDurationSecondsFromAsset(asset);
6485
6533
  const videoTrackFps = getVideoTrackMaxFrameRateFromAsset(asset);
6486
6534
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(asset);
@@ -7094,7 +7142,7 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
7094
7142
  provider
7095
7143
  });
7096
7144
  const workflowCredentials = credentials;
7097
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, workflowCredentials);
7145
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, workflowCredentials, options?.assetSnapshot);
7098
7146
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
7099
7147
  const isAudioOnly = isAudioOnlyAsset(assetData);
7100
7148
  const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
@@ -7541,7 +7589,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
7541
7589
  if (uploadToS3 && (!s3Endpoint || !s3Bucket || !effectiveStorageAdapter && (!s3AccessKeyId || !s3SecretAccessKey))) {
7542
7590
  throw new MuxAiError("Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket. If no storageAdapter is supplied, also provide s3AccessKeyId and s3SecretAccessKey in options or set S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, and S3_SECRET_ACCESS_KEY environment variables.", { type: "validation_error" });
7543
7591
  }
7544
- const { asset: initialAsset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
7592
+ const { asset: initialAsset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
7545
7593
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(initialAsset);
7546
7594
  let currentAsset = initialAsset;
7547
7595
  let createdStaticRenditionId;
@@ -8411,7 +8459,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
8411
8459
  if (uploadToS3 && (!s3Endpoint || !s3Bucket || !effectiveStorageAdapter && (!s3AccessKeyId || !s3SecretAccessKey))) {
8412
8460
  throw new MuxAiError("Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket. If no storageAdapter is supplied, also provide s3AccessKeyId and s3SecretAccessKey in options or set S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, and S3_SECRET_ACCESS_KEY environment variables.", { type: "validation_error" });
8413
8461
  }
8414
- const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials);
8462
+ const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
8415
8463
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
8416
8464
  const signingContext = await resolveMuxSigningContext(credentials);
8417
8465
  if (policy === "signed" && !signingContext) {