@mux/ai 0.23.0 → 0.24.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.
@@ -834,12 +834,14 @@ declare function censorVttContent(rawVtt: string, profanity: string[], mode: Cen
834
834
  */
835
835
  declare function applyOverrideLists(detected: string[], alwaysCensor: string[], neverCensor: string[]): string[];
836
836
  /**
837
- * Applies static find/replace pairs to cue text lines in raw VTT content
838
- * using word-boundary regex. Defaults to case-sensitive matching since static
839
- * replacements typically target specific known strings; each entry may opt
840
- * into case-insensitive matching via `caseSensitive: false`. Headers,
841
- * timestamps, and cue identifiers are untouched. Returns the edited VTT and
842
- * the total number of replacements.
837
+ * Applies static find/replace pairs to cue text blocks in raw VTT content.
838
+ * Whitespace in the find string can match VTT line wrapping, and word-character
839
+ * edges are constrained to avoid replacing substrings inside words.
840
+ * Defaults to case-sensitive matching since static replacements typically
841
+ * target specific known strings; each entry may opt into case-insensitive
842
+ * matching via `caseSensitive: false`. Headers, timestamps, and cue
843
+ * identifiers are untouched. Returns the edited VTT and the total number of
844
+ * replacements.
843
845
  */
844
846
  declare function applyReplacements(rawVtt: string, replacements: CaptionReplacement[]): {
845
847
  editedVtt: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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-ePt2EMpB.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-C5zhbQHK.js';
2
2
  import { W as WorkflowCredentials, S as StoragePutObjectInput, a as StoragePresignGetObjectInput } from './shots-mGJfYGiO.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 StorageAdapter, T as TextChunk, g as TokenChunkingConfig, h as TokenUsage, i as ToneType, U as UsageMetadata, V as VTTChunkingConfig, j as VideoEmbeddingsResult, k as WorkflowCredentialsInput, l as WorkflowMuxClient, m as decryptFromWorkflow, n as encryptForWorkflow } from './shots-mGJfYGiO.js';
4
4
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
@@ -9,7 +9,7 @@ import '@ai-sdk/google';
9
9
  import '@ai-sdk/openai';
10
10
  import '@mux/mux-node';
11
11
 
12
- var version = "0.23.0";
12
+ var version = "0.24.0";
13
13
 
14
14
  type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_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.23.0";
8
+ var version = "0.24.0";
9
9
 
10
10
  // src/lib/language-codes.ts
11
11
  var ISO639_1_TO_3 = {
@@ -2180,7 +2180,8 @@ function getReliableLanguageCode(track, confidenceThreshold = LOW_CONFIDENCE_THR
2180
2180
  return void 0;
2181
2181
  if (isUndeterminedLanguageCode(track.language_code))
2182
2182
  return void 0;
2183
- if (track.auto_language_confidence !== void 0 && track.auto_language_confidence < confidenceThreshold) {
2183
+ const { auto_language_confidence: autoLanguageConfidence } = track;
2184
+ if (autoLanguageConfidence !== void 0 && autoLanguageConfidence < confidenceThreshold) {
2184
2185
  return void 0;
2185
2186
  }
2186
2187
  return track.language_code;
@@ -4128,12 +4129,64 @@ function transformCueText(rawVtt, transform) {
4128
4129
  });
4129
4130
  return transformed.join("\n");
4130
4131
  }
4132
+ function transformCueTextBlocks(rawVtt, transform) {
4133
+ const lines = rawVtt.split("\n");
4134
+ const transformed = [];
4135
+ let cueTextLines;
4136
+ let currentCueStartTime = 0;
4137
+ const flushCueText = () => {
4138
+ if (!cueTextLines)
4139
+ return;
4140
+ if (cueTextLines.length > 0) {
4141
+ transformed.push(...transform(cueTextLines.join("\n"), currentCueStartTime).split("\n"));
4142
+ }
4143
+ cueTextLines = void 0;
4144
+ };
4145
+ for (const line of lines) {
4146
+ if (line.includes("-->")) {
4147
+ flushCueText();
4148
+ const startTimestamp = line.split("-->")[0].trim();
4149
+ currentCueStartTime = vttTimestampToSeconds(startTimestamp);
4150
+ transformed.push(line);
4151
+ cueTextLines = [];
4152
+ continue;
4153
+ }
4154
+ if (cueTextLines) {
4155
+ if (line.trim() === "") {
4156
+ flushCueText();
4157
+ transformed.push(line);
4158
+ } else {
4159
+ cueTextLines.push(line);
4160
+ }
4161
+ continue;
4162
+ }
4163
+ transformed.push(line);
4164
+ }
4165
+ flushCueText();
4166
+ return transformed.join("\n");
4167
+ }
4168
+ function escapeRegex(text) {
4169
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4170
+ }
4171
+ function buildStaticReplacementRegex(find, caseSensitive) {
4172
+ const pattern = find.split(/(\s+)/).map((part) => /\s+/.test(part) ? "\\s+" : escapeRegex(part)).join("");
4173
+ const firstNonWhitespaceIndex = find.search(/\S/);
4174
+ const firstNonWhitespace = firstNonWhitespaceIndex >= 0 ? find[firstNonWhitespaceIndex] : void 0;
4175
+ const lastNonWhitespaceMatch = /\S(?=\s*$)/.exec(find);
4176
+ const lastNonWhitespace = lastNonWhitespaceMatch?.[0];
4177
+ const startsAtTextBoundary = firstNonWhitespaceIndex === 0 && !!firstNonWhitespace && /\w/.test(firstNonWhitespace);
4178
+ const endsAtTextBoundary = !!lastNonWhitespace && find.trimEnd().length === find.length && /\w/.test(lastNonWhitespace);
4179
+ const prefix = startsAtTextBoundary ? "(?<!\\w)" : "";
4180
+ const suffix = endsAtTextBoundary ? "(?!\\w)" : "";
4181
+ const flags = caseSensitive === false ? "gi" : "g";
4182
+ return new RegExp(`${prefix}${pattern}${suffix}`, flags);
4183
+ }
4131
4184
  function buildReplacementRegex(words) {
4132
4185
  const filtered = words.filter((w) => w.length > 0);
4133
4186
  if (filtered.length === 0)
4134
4187
  return null;
4135
4188
  filtered.sort((a, b) => b.length - a.length);
4136
- const escaped = filtered.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
4189
+ const escaped = filtered.map(escapeRegex);
4137
4190
  const pattern = escaped.join("|");
4138
4191
  return new RegExp(`\\b(?:${pattern})\\b`, "gi");
4139
4192
  }
@@ -4185,12 +4238,10 @@ function applyReplacements(rawVtt, replacements) {
4185
4238
  return { editedVtt: rawVtt, replacements: [] };
4186
4239
  }
4187
4240
  const records = [];
4188
- const editedVtt = transformCueText(rawVtt, (line, cueStartTime) => {
4189
- let result = line;
4241
+ const editedVtt = transformCueTextBlocks(rawVtt, (cueText, cueStartTime) => {
4242
+ let result = cueText;
4190
4243
  for (const { find, replace, caseSensitive } of filtered) {
4191
- const escaped = find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4192
- const flags = caseSensitive === false ? "gi" : "g";
4193
- const regex = new RegExp(`\\b${escaped}\\b`, flags);
4244
+ const regex = buildStaticReplacementRegex(find, caseSensitive);
4194
4245
  result = result.replace(regex, (match) => {
4195
4246
  records.push({ cueStartTime, before: match, after: replace });
4196
4247
  return replace;