@mux/ai 0.63.0 → 0.63.1-canary.101

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.
@@ -436,7 +436,7 @@ declare const MUX_AI_ERROR_CODES: {
436
436
  readonly ASSET_ID_MISMATCH: "asset_id_mismatch";
437
437
  /** Translation needed to split a chunk of fewer than two cues: a bug in the SDK's chunking. Facts: `chunkId`, `cueCount`. */
438
438
  readonly TRANSLATION_CHUNK_UNSPLITTABLE: "translation_chunk_unsplittable";
439
- /** The model provider refused the content. Facts: `reason` and `category`. */
439
+ /** The model provider refused the content. Facts: `reason` and `category`. `reason` `PROMPT_FLAGGED` is OpenAI's intermittent up-front prompt flag: step-retried, unlike every other reason. */
440
440
  readonly CONTENT_POLICY_BLOCKED: "content_policy_blocked";
441
441
  /** The model returned no output, or a required field was empty. Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
442
442
  readonly MODEL_OUTPUT_MISSING: "model_output_missing";
@@ -1,7 +1,7 @@
1
- export { P as ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH, Q as ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH, U as ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL, V as ASK_QUESTIONS_MAX_QUESTION_LENGTH, W as AskQuestionsOptions, X as AskQuestionsResult, Y as AskQuestionsType, Z as AudioTranslationOptions, _ as AudioTranslationResult, $ as AutoCensorProfanityOptions, a0 as BurnedInCaptionsAnalysis, a1 as BurnedInCaptionsOptions, a2 as BurnedInCaptionsPromptOverrides, a3 as BurnedInCaptionsPromptSections, a4 as BurnedInCaptionsResult, a5 as CaptionReplacement, a6 as CensorMode, a7 as Chapter, a8 as ChapterSystemPromptSections, a9 as ChaptersOptions, aa as ChaptersPromptOverrides, ab as ChaptersPromptSections, ac as ChaptersResult, ad as ChaptersType, ae as DEFAULT_TRANSCRIPT_WINDOWING, af as DubbedCaptionsOutcome, ag as EditCaptionsOptions, ah as EditCaptionsResult, ai as EmbeddingsOptions, aj as EmbeddingsResult, ak as EngagementInsightsOptions, al as EngagementInsightsResult, am as GENERATE_TEXT_CALLS_TO_ACTION, an as GENERATE_TEXT_CHANNELS, ao as GENERATE_TEXT_CHANNEL_CEILINGS, ap as GENERATE_TEXT_FORMATS, aq as GENERATE_TEXT_LENGTH_BOUNDS, ar as GENERATE_TEXT_MAX_ARTIFACTS, as as GENERATE_TEXT_MAX_AUDIENCE_CHARS, at as GENERATE_TEXT_MAX_BRAND_TERMS, au as GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS, av as GENERATE_TEXT_MAX_BRAND_TERM_CHARS, aw as GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS, ax as GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, ay as GENERATE_TEXT_MAX_SHOT_FRAMES, az as GENERATE_TEXT_MAX_VARIANTS, aA as GENERATE_TEXT_VOICES, aB as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, aC as GenerateTextArtifact, aD as GenerateTextCallToAction, aE as GenerateTextChannel, aF as GenerateTextFormat, aG as GenerateTextKeyedItem, aH as GenerateTextLengthLimit, aI as GenerateTextOptions, aJ as GenerateTextResult, aK as GenerateTextVariant, aL as GenerateTextVoice, aM as GeneratedTextArtifact, aN as GeneratedTextVariant, aO as HIVE_SEXUAL_CATEGORIES, aP as HIVE_VIOLENCE_CATEGORIES, aQ as HiveModerationOutput, aR as HiveModerationSource, aS as ModerationOptions, aT as ModerationProvider, aU as ModerationResult, aV as ModerationSurfaceStatus, aW as MomentInsight, aX as OverallInsight, aY as ProfanityDetectionPayload, aZ as Question, a_ as QuestionAnswer, a$ as QuestionAnswerType, b0 as RepairAttempt, b1 as RepairCall, b2 as RepairOptions, b3 as RepairPlan, b4 as RepairResult, b5 as RepairSpan, b6 as ReplacementRecord, b7 as SpeakerReplacement, b8 as StaticRenditionCleanupOutcome, b9 as SummarizationOptions, ba as SummarizationPromptOverrides, bb as SummarizationPromptSections, bc as SummaryAndTagsResult, bd as SummaryType, be as TextLengthLimit, bf as TextRepairModelOptions, bg as ThumbnailModerationScore, bh as ThumbnailModerationSkipReason, bi as ThumbnailModerationStatus, bj as TranscriptModerationScore, bk as TranscriptModerationSkipReason, bl as TranscriptModerationStatus, bm as TranslationChunkingOptions, bn as TranslationOptions, bo as TranslationPayload, bp as TranslationResult, bq as aggregateTokenUsage, br as applyOverrideLists, bs as applyReplacements, bt as applySpeakerReplacements, bu as applyTextRepair, bv as askQuestions, bw as buildReplacementRegex, bx as buildTranscriptWindows, by as burnedInCaptionsSchema, bz as censorVttContent, bA as chapterSchema, bB as chaptersSchema, bC as createReplacer, bD as createTextRepairGenerator, bE as editCaptions, bF as extractTranscriptSegmentsForHotspots, bG as findGenerateTextLengthViolation, bH as generateChapters, bI as generateEmbeddings, bJ as generateEngagementInsights, bK as generateText, bL as generateVideoEmbeddings, bM as getModerationScores, bN as getSummaryAndTags, bO as hasBurnedInCaptions, bP as mapShotsToHotspots, bQ as measureGenerateTextLength, bR as normalizeTranslatedVtt, bS as planTextRepair, bT as profanityDetectionSchema, bU as questionAnswerSchema, bV as repairJsonSchema, bW as repairText, bX as resolveGenerateTextLengthLimit, bY as resolveGenerateTextLengthLimits, bZ as resolveGenerateTextOptions, b_ as runTextRepairLoop, b$ as selectGenerateTextShotFrames, c0 as shouldSplitChunkTranslationError, c1 as summarySchema, c2 as transformCueText, c3 as translateAudio, c4 as translateCaptions, c5 as translationSchema, c6 as validateNeverTranslateTerms, c7 as verifyNeverTranslateTerms } from '../index-CA8sRSVJ.js';
1
+ export { P as ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH, Q as ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH, U as ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL, V as ASK_QUESTIONS_MAX_QUESTION_LENGTH, W as AskQuestionsOptions, X as AskQuestionsResult, Y as AskQuestionsType, Z as AudioTranslationOptions, _ as AudioTranslationResult, $ as AutoCensorProfanityOptions, a0 as BurnedInCaptionsAnalysis, a1 as BurnedInCaptionsOptions, a2 as BurnedInCaptionsPromptOverrides, a3 as BurnedInCaptionsPromptSections, a4 as BurnedInCaptionsResult, a5 as CaptionReplacement, a6 as CensorMode, a7 as Chapter, a8 as ChapterSystemPromptSections, a9 as ChaptersOptions, aa as ChaptersPromptOverrides, ab as ChaptersPromptSections, ac as ChaptersResult, ad as ChaptersType, ae as DEFAULT_TRANSCRIPT_WINDOWING, af as DubbedCaptionsOutcome, ag as EditCaptionsOptions, ah as EditCaptionsResult, ai as EmbeddingsOptions, aj as EmbeddingsResult, ak as EngagementInsightsOptions, al as EngagementInsightsResult, am as GENERATE_TEXT_CALLS_TO_ACTION, an as GENERATE_TEXT_CHANNELS, ao as GENERATE_TEXT_CHANNEL_CEILINGS, ap as GENERATE_TEXT_FORMATS, aq as GENERATE_TEXT_LENGTH_BOUNDS, ar as GENERATE_TEXT_MAX_ARTIFACTS, as as GENERATE_TEXT_MAX_AUDIENCE_CHARS, at as GENERATE_TEXT_MAX_BRAND_TERMS, au as GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS, av as GENERATE_TEXT_MAX_BRAND_TERM_CHARS, aw as GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS, ax as GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, ay as GENERATE_TEXT_MAX_SHOT_FRAMES, az as GENERATE_TEXT_MAX_VARIANTS, aA as GENERATE_TEXT_VOICES, aB as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, aC as GenerateTextArtifact, aD as GenerateTextCallToAction, aE as GenerateTextChannel, aF as GenerateTextFormat, aG as GenerateTextKeyedItem, aH as GenerateTextLengthLimit, aI as GenerateTextOptions, aJ as GenerateTextResult, aK as GenerateTextVariant, aL as GenerateTextVoice, aM as GeneratedTextArtifact, aN as GeneratedTextVariant, aO as HIVE_SEXUAL_CATEGORIES, aP as HIVE_VIOLENCE_CATEGORIES, aQ as HiveModerationOutput, aR as HiveModerationSource, aS as ModerationOptions, aT as ModerationProvider, aU as ModerationResult, aV as ModerationSurfaceStatus, aW as MomentInsight, aX as OverallInsight, aY as ProfanityDetectionPayload, aZ as Question, a_ as QuestionAnswer, a$ as QuestionAnswerType, b0 as RepairAttempt, b1 as RepairCall, b2 as RepairOptions, b3 as RepairPlan, b4 as RepairResult, b5 as RepairSpan, b6 as ReplacementRecord, b7 as SpeakerReplacement, b8 as StaticRenditionCleanupOutcome, b9 as SummarizationOptions, ba as SummarizationPromptOverrides, bb as SummarizationPromptSections, bc as SummaryAndTagsResult, bd as SummaryType, be as TextLengthLimit, bf as TextRepairModelOptions, bg as ThumbnailModerationScore, bh as ThumbnailModerationSkipReason, bi as ThumbnailModerationStatus, bj as TranscriptModerationScore, bk as TranscriptModerationSkipReason, bl as TranscriptModerationStatus, bm as TranslationChunkingOptions, bn as TranslationOptions, bo as TranslationPayload, bp as TranslationResult, bq as aggregateTokenUsage, br as applyOverrideLists, bs as applyReplacements, bt as applySpeakerReplacements, bu as applyTextRepair, bv as askQuestions, bw as buildReplacementRegex, bx as buildTranscriptWindows, by as burnedInCaptionsSchema, bz as censorVttContent, bA as chapterSchema, bB as chaptersSchema, bC as createReplacer, bD as createTextRepairGenerator, bE as editCaptions, bF as extractTranscriptSegmentsForHotspots, bG as findGenerateTextLengthViolation, bH as generateChapters, bI as generateEmbeddings, bJ as generateEngagementInsights, bK as generateText, bL as generateVideoEmbeddings, bM as getModerationScores, bN as getSummaryAndTags, bO as hasBurnedInCaptions, bP as mapShotsToHotspots, bQ as measureGenerateTextLength, bR as normalizeTranslatedVtt, bS as planTextRepair, bT as profanityDetectionSchema, bU as questionAnswerSchema, bV as repairJsonSchema, bW as repairText, bX as resolveGenerateTextLengthLimit, bY as resolveGenerateTextLengthLimits, bZ as resolveGenerateTextOptions, b_ as runTextRepairLoop, b$ as selectGenerateTextShotFrames, c0 as shouldSplitChunkTranslationError, c1 as summarySchema, c2 as transformCueText, c3 as translateAudio, c4 as translateCaptions, c5 as translationSchema, c6 as validateNeverTranslateTerms, c7 as verifyNeverTranslateTerms } from '../index-DJ6j4-nM.js';
2
2
  export { D as DEFAULT_DESCRIPTION_LENGTH, a as DEFAULT_SUMMARY_KEYWORD_LIMIT, b as DEFAULT_TITLE_LENGTH } from '../summarization-BFmhXeAu.js';
3
3
  import 'ai';
4
- import '../transcripts-So1KIXSI.js';
4
+ import '../transcripts-CFZM111v.js';
5
5
  import '@workflow/serde';
6
6
  import '@mux/ts';
7
7
  import 'zod';
@@ -613,7 +613,7 @@ var MUX_AI_ERROR_CODES = {
613
613
  ASSET_ID_MISMATCH: "asset_id_mismatch",
614
614
  /** Translation needed to split a chunk of fewer than two cues: a bug in the SDK's chunking. Facts: `chunkId`, `cueCount`. */
615
615
  TRANSLATION_CHUNK_UNSPLITTABLE: "translation_chunk_unsplittable",
616
- /** The model provider refused the content. Facts: `reason` and `category`. */
616
+ /** The model provider refused the content. Facts: `reason` and `category`. `reason` `PROMPT_FLAGGED` is OpenAI's intermittent up-front prompt flag: step-retried, unlike every other reason. */
617
617
  CONTENT_POLICY_BLOCKED: "content_policy_blocked",
618
618
  /** The model returned no output, or a required field was empty. Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
619
619
  MODEL_OUTPUT_MISSING: "model_output_missing",
@@ -1198,6 +1198,8 @@ var OpenAIUsageResponseSchema = z3.object({
1198
1198
  var OpenAIPolicyErrorSchema = z3.object({
1199
1199
  error: z3.object({ code: z3.enum(["content_policy_violation", "content_filter"]) })
1200
1200
  });
1201
+ var OPENAI_PROMPT_FLAG = /invalid prompt:.*flagged as potentially violating/i;
1202
+ var OPENAI_PROMPT_FLAGGED = "PROMPT_FLAGGED";
1201
1203
  var CONTENT_POLICY_REASONS = /* @__PURE__ */ new Set([
1202
1204
  "BLOCKLIST",
1203
1205
  "ESCALATION",
@@ -1323,12 +1325,27 @@ function includeRetriedUsage(response, retriedUsage) {
1323
1325
  return Object.create(Object.getPrototypeOf(response), descriptors);
1324
1326
  }
1325
1327
  function rethrowContentPolicyError(error, context) {
1328
+ if (context?.provider === "openai" && isOpenAIPromptFlag(error)) {
1329
+ throwContentPolicyError({ reason: OPENAI_PROMPT_FLAGGED }, getContentPolicyTokenUsage(error), context, { intermittent: true, cause: error });
1330
+ }
1326
1331
  const block = extractContentPolicyBlock(error);
1327
1332
  if (!block) {
1328
1333
  throw error;
1329
1334
  }
1330
1335
  throwContentPolicyError(block, getContentPolicyTokenUsage(error), context);
1331
1336
  }
1337
+ function isOpenAIPromptFlag(error) {
1338
+ const apiError = findProviderCallError(error);
1339
+ if (apiError?.statusCode !== 400) {
1340
+ return false;
1341
+ }
1342
+ let bodyMessage;
1343
+ try {
1344
+ bodyMessage = JSON.parse(apiError.responseBody ?? "").error?.message;
1345
+ } catch {
1346
+ }
1347
+ return [apiError.message, bodyMessage].some((message) => typeof message === "string" && OPENAI_PROMPT_FLAG.test(message));
1348
+ }
1332
1349
  function findProviderCallError(error) {
1333
1350
  let current = RetryError.isInstance(error) ? error.lastError : error;
1334
1351
  for (let depth = 0; depth < 3 && current; depth++) {
@@ -1417,7 +1434,7 @@ function getGeneratedOutputWithContentPolicyHandling(response, context) {
1417
1434
  }
1418
1435
  return output;
1419
1436
  }
1420
- function throwContentPolicyError(block, usage, context) {
1437
+ function throwContentPolicyError(block, usage, context, options) {
1421
1438
  const category = block.category ? `; category: ${block.category}` : "";
1422
1439
  if (context) {
1423
1440
  throw withUsage(new MuxAiError(`The supplied content was blocked by a content policy (reason: ${block.reason}${category}).`, {
@@ -1425,7 +1442,13 @@ function throwContentPolicyError(block, usage, context) {
1425
1442
  type: MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR,
1426
1443
  source: MUX_AI_ERROR_SOURCES.ASSET,
1427
1444
  dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
1428
- facts: { ...modelCallFacts(context), reason: block.reason, ...block.category && { category: block.category } }
1445
+ facts: { ...modelCallFacts(context), reason: block.reason, ...block.category && { category: block.category } },
1446
+ // An intermittent block (OpenAI's prompt flag) usually passes on a later, identical attempt,
1447
+ // so the step runner retries it, as it did before classification; once those retries are
1448
+ // spent it fails as a content-policy block. Every other block is final.
1449
+ ...options?.intermittent && { transient: true, retryable: true },
1450
+ // Kept so the provider's status and message survive in the error's `causes`.
1451
+ ...options?.cause !== void 0 && { cause: options.cause }
1429
1452
  }), usage);
1430
1453
  }
1431
1454
  const contentPolicyError = new LegacyMuxAiError(