@mux/ai 0.53.0 → 0.55.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/dist/{index-cbaPe-aE.d.ts → index-B-rLy1do.d.ts} +1 -1
- package/dist/{index-BbxJ0X25.d.ts → index-BBk0AcY1.d.ts} +11 -3
- package/dist/index.d.ts +28 -9
- package/dist/index.js +236 -118
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +31 -1
- package/dist/primitives/index.js.map +1 -1
- package/dist/{transcripts-BCtzC8hZ.d.ts → transcripts-DxSHvTk9.d.ts} +1 -1
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +235 -113
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -604,4 +604,4 @@ interface TranscriptFetchStepResult {
|
|
|
604
604
|
declare function fetchTranscriptDataForUrl(transcriptUrl: string, options?: Pick<TranscriptFetchOptions, "cleanTranscript" | "scope">): Promise<TranscriptFetchStepResult>;
|
|
605
605
|
declare function fetchTranscriptForAsset(asset: MuxAsset, playbackId: string, options?: TranscriptFetchOptions): Promise<TranscriptResult>;
|
|
606
606
|
|
|
607
|
-
export { fetchTranscriptDataForUrl as $, type AssetTextTrack as A, type ShotsResult as B, type ChunkEmbedding as C, type DeletedShotsResult as D, type Encrypted as E, type SkippedShotsResult as F, type TranscriptEmptyReason as G, type Hotspot as H, type ImageSubmissionMode as I, type TranscriptFetchOptions as J, type TranscriptFetchStepResult as K, LOW_CONFIDENCE_THRESHOLD as L, type MuxAsset as M, type TranscriptResult as N, type WaitForShotsOptions as O, type PlaybackAsset as P, buildTranscriptUrl as Q, buildVttFromCueBlocks as R, type StoragePutObjectInput as S, type
|
|
607
|
+
export { fetchTranscriptDataForUrl as $, type AssetTextTrack as A, type ShotsResult as B, type ChunkEmbedding as C, type DeletedShotsResult as D, type Encrypted as E, type SkippedShotsResult as F, type TranscriptEmptyReason as G, type Hotspot as H, type ImageSubmissionMode as I, type TranscriptFetchOptions as J, type TranscriptFetchStepResult as K, LOW_CONFIDENCE_THRESHOLD as L, type MuxAsset as M, type TranscriptResult as N, type WaitForShotsOptions as O, type PlaybackAsset as P, buildTranscriptUrl as Q, buildVttFromCueBlocks as R, type StoragePutObjectInput as S, type TokenUsage as T, type UsageMetadata as U, type VTTChunkingConfig as V, type WorkflowCredentials as W, buildVttFromTranslatedCueBlocks as X, concatenateVttSegments as Y, extractTextFromVTT as Z, extractTimestampedTranscript as _, type StoragePresignGetObjectInput as a, fetchTranscriptForAsset as a0, filterVttByScope as a1, findCaptionTrack as a2, getHotspotsForAsset as a3, getHotspotsForPlaybackId as a4, getHotspotsForVideo as a5, getReadyTextTracks as a6, getReliableLanguageCode as a7, getShotsForAsset as a8, parseVTTCues as a9, replaceCueText as aa, requestShotsForAsset as ab, sanitizeUntrustedText as ac, secondsToTimestamp as ad, splitVttPreambleAndCueBlocks as ae, stripVttMetadataBlocks as af, vttTimestampToSeconds as ag, waitForShotsForAsset as ah, type ChunkingStrategy as b, type EncryptedPayload as c, type MuxAIOptions as d, type PlaybackPolicy as e, type ScopedMuxAIOptions as f, type StorageAdapter as g, type TextChunk as h, type TokenChunkingConfig as i, type ToneType as j, type VideoEmbeddingsResult as k, type WorkflowCredentialsInput as l, type WorkflowMuxClient as m, type WorkflowScope as n, decryptFromWorkflow as o, encryptForWorkflow as p, type VTTCue as q, type CompletedShotsResult as r, type ErroredShotsResult as s, type HotspotOptions as t, type HotspotResponse as u, MAX_CUE_TEXT_CHARS as v, type ParseVTTCuesOptions as w, type PendingShotsResult as x, type Shot as y, type ShotRequestOptions as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { J as ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH, K as ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH, N as ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL, O as ASK_QUESTIONS_MAX_QUESTION_LENGTH, P as AskQuestionsOptions, Q as AskQuestionsResult, U as AskQuestionsType, V as AudioTranslationOptions, W as AudioTranslationResult, X as AutoCensorProfanityOptions, Y as BurnedInCaptionsAnalysis, Z as BurnedInCaptionsOptions, _ as BurnedInCaptionsPromptOverrides, $ as BurnedInCaptionsPromptSections, a0 as BurnedInCaptionsResult, a1 as CaptionReplacement, a2 as CensorMode, a3 as Chapter, a4 as ChapterSystemPromptSections, a5 as ChaptersOptions, a6 as ChaptersPromptOverrides, a7 as ChaptersPromptSections, a8 as ChaptersResult, a9 as ChaptersType, aa as DEFAULT_TRANSCRIPT_WINDOWING, ab as EditCaptionsOptions, ac as EditCaptionsResult, ad as EmbeddingsOptions, ae as EmbeddingsResult, af as EngagementInsightsOptions, ag as EngagementInsightsResult, ah as GENERATE_TEXT_CALLS_TO_ACTION, ai as GENERATE_TEXT_CHANNELS, aj as GENERATE_TEXT_CHANNEL_CEILINGS, ak as GENERATE_TEXT_FORMATS, al as GENERATE_TEXT_LENGTH_BOUNDS, am as GENERATE_TEXT_MAX_ARTIFACTS, an as GENERATE_TEXT_MAX_AUDIENCE_CHARS, ao as GENERATE_TEXT_MAX_BRAND_TERMS, ap as GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS, aq as GENERATE_TEXT_MAX_BRAND_TERM_CHARS, ar as GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS, as as GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, at as GENERATE_TEXT_MAX_SHOT_FRAMES, au as GENERATE_TEXT_MAX_VARIANTS, av as GENERATE_TEXT_VOICES, aw as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, ax as GenerateTextArtifact, ay as GenerateTextCallToAction, az as GenerateTextChannel, aA as GenerateTextFormat, aB as GenerateTextKeyedItem, aC as GenerateTextLengthLimit, aD as GenerateTextOptions, aE as GenerateTextResult, aF as GenerateTextVariant, aG as GenerateTextVoice, aH as GeneratedTextArtifact, aI as GeneratedTextVariant, aJ as HIVE_SEXUAL_CATEGORIES, aK as HIVE_VIOLENCE_CATEGORIES, aL as HiveModerationOutput, aM as HiveModerationSource, aN as ModerationOptions, aO as ModerationProvider, aP as ModerationResult, aQ as ModerationSurfaceStatus, aR as MomentInsight, aS as OverallInsight, aT as ProfanityDetectionPayload, aU as Question, aV as QuestionAnswer, aW as QuestionAnswerType, aX as RepairAttempt, aY as RepairCall, aZ as RepairOptions, a_ as RepairPlan, a$ as RepairResult, b0 as RepairSpan, b1 as ReplacementRecord, b2 as SpeakerReplacement, b3 as StaticRenditionCleanupOutcome, b4 as SummarizationOptions, b5 as SummarizationPromptOverrides, b6 as SummarizationPromptSections, b7 as SummaryAndTagsResult, b8 as SummaryType, b9 as TextLengthLimit, ba as TextRepairModelOptions, bb as ThumbnailModerationScore, bc as ThumbnailModerationSkipReason, bd as ThumbnailModerationStatus, be as TranscriptModerationScore, bf as TranscriptModerationSkipReason, bg as TranscriptModerationStatus, bh as TranslationChunkingOptions, bi as TranslationOptions, bj as TranslationPayload, bk as TranslationResult, bl as aggregateTokenUsage, bm as applyOverrideLists, bn as applyReplacements, bo as applySpeakerReplacements, bp as applyTextRepair, bq as askQuestions, br as buildReplacementRegex, bs as buildTranscriptWindows, bt as burnedInCaptionsSchema, bu as censorVttContent, bv as chapterSchema, bw as chaptersSchema, bx as createReplacer, by as createTextRepairGenerator, bz as editCaptions, bA as extractTranscriptSegmentsForHotspots, bB as findGenerateTextLengthViolation, bC as generateChapters, bD as generateEmbeddings, bE as generateEngagementInsights, bF as generateText, bG as generateVideoEmbeddings, bH as getModerationScores, bI as getSummaryAndTags, bJ as hasBurnedInCaptions, bK as mapShotsToHotspots, bL as measureGenerateTextLength, bM as normalizeTranslatedVtt, bN as planTextRepair, bO as profanityDetectionSchema, bP as questionAnswerSchema, bQ as repairJsonSchema, bR as repairText, bS as resolveGenerateTextLengthLimit, bT as resolveGenerateTextLengthLimits, bU as resolveGenerateTextOptions, bV as runTextRepairLoop, bW as selectGenerateTextShotFrames, bX as shouldSplitChunkTranslationError, bY as summarySchema, bZ as transformCueText, b_ as translateAudio, b$ as translateCaptions, c0 as translationSchema, c1 as validateNeverTranslateTerms, c2 as verifyNeverTranslateTerms } from '../index-
|
|
1
|
+
export { J as ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH, K as ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH, N as ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL, O as ASK_QUESTIONS_MAX_QUESTION_LENGTH, P as AskQuestionsOptions, Q as AskQuestionsResult, U as AskQuestionsType, V as AudioTranslationOptions, W as AudioTranslationResult, X as AutoCensorProfanityOptions, Y as BurnedInCaptionsAnalysis, Z as BurnedInCaptionsOptions, _ as BurnedInCaptionsPromptOverrides, $ as BurnedInCaptionsPromptSections, a0 as BurnedInCaptionsResult, a1 as CaptionReplacement, a2 as CensorMode, a3 as Chapter, a4 as ChapterSystemPromptSections, a5 as ChaptersOptions, a6 as ChaptersPromptOverrides, a7 as ChaptersPromptSections, a8 as ChaptersResult, a9 as ChaptersType, aa as DEFAULT_TRANSCRIPT_WINDOWING, ab as EditCaptionsOptions, ac as EditCaptionsResult, ad as EmbeddingsOptions, ae as EmbeddingsResult, af as EngagementInsightsOptions, ag as EngagementInsightsResult, ah as GENERATE_TEXT_CALLS_TO_ACTION, ai as GENERATE_TEXT_CHANNELS, aj as GENERATE_TEXT_CHANNEL_CEILINGS, ak as GENERATE_TEXT_FORMATS, al as GENERATE_TEXT_LENGTH_BOUNDS, am as GENERATE_TEXT_MAX_ARTIFACTS, an as GENERATE_TEXT_MAX_AUDIENCE_CHARS, ao as GENERATE_TEXT_MAX_BRAND_TERMS, ap as GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS, aq as GENERATE_TEXT_MAX_BRAND_TERM_CHARS, ar as GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS, as as GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, at as GENERATE_TEXT_MAX_SHOT_FRAMES, au as GENERATE_TEXT_MAX_VARIANTS, av as GENERATE_TEXT_VOICES, aw as GOOGLE_VISION_LIKELIHOOD_TO_SCORE, ax as GenerateTextArtifact, ay as GenerateTextCallToAction, az as GenerateTextChannel, aA as GenerateTextFormat, aB as GenerateTextKeyedItem, aC as GenerateTextLengthLimit, aD as GenerateTextOptions, aE as GenerateTextResult, aF as GenerateTextVariant, aG as GenerateTextVoice, aH as GeneratedTextArtifact, aI as GeneratedTextVariant, aJ as HIVE_SEXUAL_CATEGORIES, aK as HIVE_VIOLENCE_CATEGORIES, aL as HiveModerationOutput, aM as HiveModerationSource, aN as ModerationOptions, aO as ModerationProvider, aP as ModerationResult, aQ as ModerationSurfaceStatus, aR as MomentInsight, aS as OverallInsight, aT as ProfanityDetectionPayload, aU as Question, aV as QuestionAnswer, aW as QuestionAnswerType, aX as RepairAttempt, aY as RepairCall, aZ as RepairOptions, a_ as RepairPlan, a$ as RepairResult, b0 as RepairSpan, b1 as ReplacementRecord, b2 as SpeakerReplacement, b3 as StaticRenditionCleanupOutcome, b4 as SummarizationOptions, b5 as SummarizationPromptOverrides, b6 as SummarizationPromptSections, b7 as SummaryAndTagsResult, b8 as SummaryType, b9 as TextLengthLimit, ba as TextRepairModelOptions, bb as ThumbnailModerationScore, bc as ThumbnailModerationSkipReason, bd as ThumbnailModerationStatus, be as TranscriptModerationScore, bf as TranscriptModerationSkipReason, bg as TranscriptModerationStatus, bh as TranslationChunkingOptions, bi as TranslationOptions, bj as TranslationPayload, bk as TranslationResult, bl as aggregateTokenUsage, bm as applyOverrideLists, bn as applyReplacements, bo as applySpeakerReplacements, bp as applyTextRepair, bq as askQuestions, br as buildReplacementRegex, bs as buildTranscriptWindows, bt as burnedInCaptionsSchema, bu as censorVttContent, bv as chapterSchema, bw as chaptersSchema, bx as createReplacer, by as createTextRepairGenerator, bz as editCaptions, bA as extractTranscriptSegmentsForHotspots, bB as findGenerateTextLengthViolation, bC as generateChapters, bD as generateEmbeddings, bE as generateEngagementInsights, bF as generateText, bG as generateVideoEmbeddings, bH as getModerationScores, bI as getSummaryAndTags, bJ as hasBurnedInCaptions, bK as mapShotsToHotspots, bL as measureGenerateTextLength, bM as normalizeTranslatedVtt, bN as planTextRepair, bO as profanityDetectionSchema, bP as questionAnswerSchema, bQ as repairJsonSchema, bR as repairText, bS as resolveGenerateTextLengthLimit, bT as resolveGenerateTextLengthLimits, bU as resolveGenerateTextOptions, bV as runTextRepairLoop, bW as selectGenerateTextShotFrames, bX as shouldSplitChunkTranslationError, bY as summarySchema, bZ as transformCueText, b_ as translateAudio, b$ as translateCaptions, c0 as translationSchema, c1 as validateNeverTranslateTerms, c2 as verifyNeverTranslateTerms } from '../index-BBk0AcY1.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-
|
|
4
|
+
import '../transcripts-DxSHvTk9.js';
|
|
5
5
|
import '@mux/ts';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import '@ai-sdk/anthropic';
|
package/dist/workflows/index.js
CHANGED
|
@@ -5,6 +5,10 @@ import { generateText, jsonSchema, NoObjectGeneratedError as NoObjectGeneratedEr
|
|
|
5
5
|
import { APICallError as APICallError2, NoObjectGeneratedError, RetryError } from "ai";
|
|
6
6
|
import { z as z2 } from "zod";
|
|
7
7
|
|
|
8
|
+
// node_modules/@workflow/serde/dist/index.js
|
|
9
|
+
var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
|
|
10
|
+
var WORKFLOW_DESERIALIZE = /* @__PURE__ */ Symbol.for("workflow-deserialize");
|
|
11
|
+
|
|
8
12
|
// src/lib/prompt-fragments.ts
|
|
9
13
|
import dedent from "dedent";
|
|
10
14
|
|
|
@@ -526,7 +530,7 @@ function rethrowWithTokenUsage(error, collectedUsage) {
|
|
|
526
530
|
}
|
|
527
531
|
|
|
528
532
|
// src/lib/mux-ai-error.ts
|
|
529
|
-
var MuxAiError = class extends Error {
|
|
533
|
+
var MuxAiError = class _MuxAiError extends Error {
|
|
530
534
|
constructor(message, opts) {
|
|
531
535
|
super(message);
|
|
532
536
|
/** Structural brand for duck-type identification. */
|
|
@@ -542,6 +546,32 @@ var MuxAiError = class extends Error {
|
|
|
542
546
|
static is(value) {
|
|
543
547
|
return typeof value === "object" && value !== null && "__robots_error" in value && value.__robots_error === true;
|
|
544
548
|
}
|
|
549
|
+
static [WORKFLOW_SERIALIZE](instance) {
|
|
550
|
+
const incomplete = instance;
|
|
551
|
+
return {
|
|
552
|
+
message: instance.publicMessage,
|
|
553
|
+
publicType: instance.publicType,
|
|
554
|
+
retryable: instance.retryable,
|
|
555
|
+
stack: instance.stack,
|
|
556
|
+
usage: getErrorTokenUsage(instance),
|
|
557
|
+
finishReason: incomplete.finishReason,
|
|
558
|
+
rawFinishReason: incomplete.rawFinishReason,
|
|
559
|
+
diagnostics: instance.diagnostics
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
static [WORKFLOW_DESERIALIZE](value) {
|
|
563
|
+
const error = new _MuxAiError(value.message, { type: value.publicType, retryable: value.retryable });
|
|
564
|
+
Object.assign(error, {
|
|
565
|
+
usage: value.usage,
|
|
566
|
+
diagnostics: value.diagnostics,
|
|
567
|
+
...value.finishReason !== void 0 && { finishReason: value.finishReason },
|
|
568
|
+
...value.rawFinishReason !== void 0 && { rawFinishReason: value.rawFinishReason }
|
|
569
|
+
});
|
|
570
|
+
if (value.stack !== void 0) {
|
|
571
|
+
error.stack = value.stack;
|
|
572
|
+
}
|
|
573
|
+
return error;
|
|
574
|
+
}
|
|
545
575
|
};
|
|
546
576
|
function extractErrorDetail(error) {
|
|
547
577
|
if (error instanceof Error && error.message) {
|
|
@@ -615,7 +645,8 @@ async function withRetry(fn, {
|
|
|
615
645
|
maxRetries = DEFAULT_RETRY_OPTIONS.maxRetries,
|
|
616
646
|
baseDelay = DEFAULT_RETRY_OPTIONS.baseDelay,
|
|
617
647
|
maxDelay = DEFAULT_RETRY_OPTIONS.maxDelay,
|
|
618
|
-
shouldRetry = defaultShouldRetry
|
|
648
|
+
shouldRetry = defaultShouldRetry,
|
|
649
|
+
onRetry
|
|
619
650
|
} = {}) {
|
|
620
651
|
let lastError;
|
|
621
652
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
@@ -628,6 +659,7 @@ async function withRetry(fn, {
|
|
|
628
659
|
if (isLastAttempt || !shouldRetry(retryError, attempt + 1)) {
|
|
629
660
|
throw error;
|
|
630
661
|
}
|
|
662
|
+
onRetry?.(error, attempt + 1);
|
|
631
663
|
const delay = calculateDelay(attempt + 1, baseDelay, maxDelay);
|
|
632
664
|
console.warn(
|
|
633
665
|
`Attempt ${attempt + 1} failed: ${retryError.message}. Retrying in ${Math.round(delay)}ms...`
|
|
@@ -721,10 +753,54 @@ async function withContentPolicyErrorHandling(operation) {
|
|
|
721
753
|
}
|
|
722
754
|
}
|
|
723
755
|
async function withContentPolicyAwareRetry(operation, retryOptions) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
756
|
+
const retriedUsage = [];
|
|
757
|
+
try {
|
|
758
|
+
const response = await withRetry(
|
|
759
|
+
() => withContentPolicyErrorHandling(operation),
|
|
760
|
+
{
|
|
761
|
+
...retryOptions,
|
|
762
|
+
onRetry: (error, attempt) => {
|
|
763
|
+
const usage = getErrorTokenUsage(error);
|
|
764
|
+
if (usage) {
|
|
765
|
+
retriedUsage.push(usage);
|
|
766
|
+
}
|
|
767
|
+
retryOptions?.onRetry?.(error, attempt);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
);
|
|
771
|
+
return includeRetriedUsage(response, retriedUsage);
|
|
772
|
+
} catch (error) {
|
|
773
|
+
rethrowWithTokenUsage(error, retriedUsage);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function includeRetriedUsage(response, retriedUsage) {
|
|
777
|
+
if (!retriedUsage.length || typeof response !== "object" || response === null) {
|
|
778
|
+
return response;
|
|
779
|
+
}
|
|
780
|
+
const result = response;
|
|
781
|
+
const merge = (usage) => {
|
|
782
|
+
const combined = aggregateTokenUsage([...retriedUsage, getErrorTokenUsage({ usage }) ?? {}]);
|
|
783
|
+
return {
|
|
784
|
+
...usage,
|
|
785
|
+
...combined,
|
|
786
|
+
...combined.cachedInputTokens !== void 0 || combined.cacheWriteTokens !== void 0 ? {
|
|
787
|
+
inputTokenDetails: {
|
|
788
|
+
...usage?.inputTokenDetails,
|
|
789
|
+
...combined.cachedInputTokens !== void 0 && { cacheReadTokens: combined.cachedInputTokens },
|
|
790
|
+
...combined.cacheWriteTokens !== void 0 && { cacheWriteTokens: combined.cacheWriteTokens }
|
|
791
|
+
}
|
|
792
|
+
} : {},
|
|
793
|
+
...combined.reasoningTokens !== void 0 ? {
|
|
794
|
+
outputTokenDetails: { ...usage?.outputTokenDetails, reasoningTokens: combined.reasoningTokens }
|
|
795
|
+
} : {}
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
const descriptors = Object.getOwnPropertyDescriptors(response);
|
|
799
|
+
descriptors.usage = { value: merge(result.usage), enumerable: true, configurable: true };
|
|
800
|
+
if ("totalUsage" in result) {
|
|
801
|
+
descriptors.totalUsage = { value: merge(result.totalUsage), enumerable: true, configurable: true };
|
|
802
|
+
}
|
|
803
|
+
return Object.create(Object.getPrototypeOf(response), descriptors);
|
|
728
804
|
}
|
|
729
805
|
function rethrowContentPolicyError(error) {
|
|
730
806
|
const block = extractContentPolicyBlock(error);
|
|
@@ -860,6 +936,35 @@ function findBlockedCategory(ratings) {
|
|
|
860
936
|
return ratings?.find((rating) => rating.blocked === true)?.category ?? void 0;
|
|
861
937
|
}
|
|
862
938
|
|
|
939
|
+
// src/lib/model-call-diagnostics.ts
|
|
940
|
+
import { APICallError as APICallError3 } from "ai";
|
|
941
|
+
function recordModelCallFailure(error, diagnostics, observedUsage = getErrorTokenUsage(error)) {
|
|
942
|
+
if (typeof error !== "object" || error === null) {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const failure = error;
|
|
946
|
+
if (failure.diagnostics) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
failure.diagnostics = { ...diagnostics };
|
|
950
|
+
console.warn("[@mux/ai] Model call failed.", {
|
|
951
|
+
...diagnostics,
|
|
952
|
+
finishReason: failure.finishReason,
|
|
953
|
+
statusCode: failure.statusCode,
|
|
954
|
+
errorName: error instanceof Error ? error.name : void 0,
|
|
955
|
+
requestId: APICallError3.isInstance(error) ? error.responseHeaders?.["x-request-id"] ?? error.responseHeaders?.["request-id"] : void 0,
|
|
956
|
+
usage: observedUsage
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
async function withModelCallDiagnostics(diagnostics, operation) {
|
|
960
|
+
try {
|
|
961
|
+
return await operation();
|
|
962
|
+
} catch (error) {
|
|
963
|
+
recordModelCallFailure(error, diagnostics);
|
|
964
|
+
throw error;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
863
968
|
// src/lib/text-repair-capabilities.ts
|
|
864
969
|
var OPENAI_REPAIR_CAPABILITIES = {
|
|
865
970
|
"gpt-5.1": { supportsReasoningNone: true },
|
|
@@ -1021,13 +1126,14 @@ function createTextRepairGenerator(options) {
|
|
|
1021
1126
|
return async (plan) => {
|
|
1022
1127
|
let usage;
|
|
1023
1128
|
const started = Date.now();
|
|
1129
|
+
const maxOutputTokens = options.maxOutputTokens ?? Math.min(32768, Math.max(1024, plan.spans.reduce((total, span) => total + Math.min(...span.budgets.map((limit) => limit.value * (limit.unit === "words" ? 4 : 2))), 0) + 128));
|
|
1024
1130
|
try {
|
|
1025
1131
|
const response = await withContentPolicyErrorHandling(() => generateText({
|
|
1026
1132
|
model: options.model,
|
|
1027
1133
|
providerOptions: options.providerOptions ?? getTextRepairProviderOptions(options.model),
|
|
1028
1134
|
maxRetries: 0,
|
|
1029
1135
|
abortSignal: AbortSignal.timeout(options.timeoutMs ?? 3e4),
|
|
1030
|
-
maxOutputTokens
|
|
1136
|
+
maxOutputTokens,
|
|
1031
1137
|
output: Output.object({ schema: jsonSchema(repairJsonSchema(plan)), name: "paragraph_replacements" }),
|
|
1032
1138
|
system: promptDedent`
|
|
1033
1139
|
${NON_DISCLOSURE_CONSTRAINT}
|
|
@@ -1055,6 +1161,12 @@ function createTextRepairGenerator(options) {
|
|
|
1055
1161
|
return { replacements: output, usage, elapsedMs: Date.now() - started };
|
|
1056
1162
|
} catch (error) {
|
|
1057
1163
|
const cause = NoObjectGeneratedError2.isInstance(error) && error.finishReason && error.finishReason !== "stop" ? new IncompleteGenerationError(error.finishReason, void 0, getErrorTokenUsage(error)) : error;
|
|
1164
|
+
recordModelCallFailure(cause, {
|
|
1165
|
+
phase: "length_repair",
|
|
1166
|
+
provider: typeof options.model === "object" ? options.model.provider : "gateway",
|
|
1167
|
+
modelId: typeof options.model === "object" ? options.model.modelId : options.model,
|
|
1168
|
+
maxOutputTokens
|
|
1169
|
+
}, usage ?? getErrorTokenUsage(cause));
|
|
1058
1170
|
return { usage: usage ?? getErrorTokenUsage(cause), elapsedMs: Date.now() - started, error: cause instanceof Error ? cause.message : String(cause), errorCause: cause };
|
|
1059
1171
|
}
|
|
1060
1172
|
};
|
|
@@ -6348,7 +6460,7 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6348
6460
|
}
|
|
6349
6461
|
|
|
6350
6462
|
// src/workflows/generate-text.ts
|
|
6351
|
-
import { APICallError as
|
|
6463
|
+
import { APICallError as APICallError4, generateText as generateTextWithModel, Output as Output7 } from "ai";
|
|
6352
6464
|
import { z as z8 } from "zod";
|
|
6353
6465
|
var GENERATE_TEXT_MAX_VARIANTS = 5;
|
|
6354
6466
|
var GENERATE_TEXT_MAX_ARTIFACTS = 5;
|
|
@@ -6471,7 +6583,7 @@ function resolveGenerateTextOptions(options) {
|
|
|
6471
6583
|
}
|
|
6472
6584
|
return { ...options, variants };
|
|
6473
6585
|
}
|
|
6474
|
-
var LENGTH_TARGET_RATIO = 0.
|
|
6586
|
+
var LENGTH_TARGET_RATIO = 0.85;
|
|
6475
6587
|
function resolveLengthTarget(limit) {
|
|
6476
6588
|
return Math.max(1, Math.floor(limit.value * LENGTH_TARGET_RATIO));
|
|
6477
6589
|
}
|
|
@@ -6760,122 +6872,124 @@ function readUsage(response) {
|
|
|
6760
6872
|
}
|
|
6761
6873
|
async function extractBriefWithModel(args) {
|
|
6762
6874
|
"use step";
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
model,
|
|
6766
|
-
maxRetries: 0,
|
|
6767
|
-
output: Output7.object({
|
|
6768
|
-
name: "editorial_brief",
|
|
6769
|
-
description: "Source-grounded editorial brief used to write every requested artifact.",
|
|
6770
|
-
schema: briefSchema
|
|
6771
|
-
}),
|
|
6772
|
-
system: args.systemPrompt,
|
|
6773
|
-
messages: [
|
|
6774
|
-
{
|
|
6775
|
-
role: "user",
|
|
6776
|
-
content: [
|
|
6777
|
-
{ type: "text", text: args.userPrompt },
|
|
6778
|
-
...args.imageUrls.map((url) => ({ type: "image", image: url }))
|
|
6779
|
-
]
|
|
6780
|
-
}
|
|
6781
|
-
]
|
|
6782
|
-
}));
|
|
6783
|
-
const output = getGeneratedOutputWithContentPolicyHandling(response);
|
|
6784
|
-
if (!output) {
|
|
6785
|
-
throw new Error("Editorial brief output missing");
|
|
6786
|
-
}
|
|
6787
|
-
return {
|
|
6788
|
-
brief: clampBriefArrays(briefSchema.parse(output)),
|
|
6789
|
-
usage: readUsage(response),
|
|
6790
|
-
unexpectedKeys: detectUnexpectedKeysFromRawText(response.text, briefSchema.keyof().options)
|
|
6791
|
-
};
|
|
6792
|
-
}
|
|
6793
|
-
var artifactSchema = z8.object({ content: z8.string() });
|
|
6794
|
-
async function generateArtifactWithModel(args) {
|
|
6795
|
-
"use step";
|
|
6796
|
-
const model = await createLanguageModelFromConfig(args.provider, args.modelId, args.credentials);
|
|
6797
|
-
const attempt = async (messages) => {
|
|
6875
|
+
return withModelCallDiagnostics({ phase: "brief", provider: args.provider, modelId: args.modelId }, async () => {
|
|
6876
|
+
const model = await createLanguageModelFromConfig(args.provider, args.modelId, args.credentials);
|
|
6798
6877
|
const response = await withContentPolicyAwareRetry(() => generateTextWithModel({
|
|
6799
6878
|
model,
|
|
6800
6879
|
maxRetries: 0,
|
|
6801
6880
|
output: Output7.object({
|
|
6802
|
-
name: "
|
|
6803
|
-
description: "
|
|
6804
|
-
schema:
|
|
6881
|
+
name: "editorial_brief",
|
|
6882
|
+
description: "Source-grounded editorial brief used to write every requested artifact.",
|
|
6883
|
+
schema: briefSchema
|
|
6805
6884
|
}),
|
|
6806
6885
|
system: args.systemPrompt,
|
|
6807
|
-
messages
|
|
6886
|
+
messages: [
|
|
6887
|
+
{
|
|
6888
|
+
role: "user",
|
|
6889
|
+
content: [
|
|
6890
|
+
{ type: "text", text: args.userPrompt },
|
|
6891
|
+
...args.imageUrls.map((url) => ({ type: "image", image: url }))
|
|
6892
|
+
]
|
|
6893
|
+
}
|
|
6894
|
+
]
|
|
6808
6895
|
}));
|
|
6809
6896
|
const output = getGeneratedOutputWithContentPolicyHandling(response);
|
|
6810
6897
|
if (!output) {
|
|
6811
|
-
throw new Error("
|
|
6898
|
+
throw new Error("Editorial brief output missing");
|
|
6812
6899
|
}
|
|
6813
6900
|
return {
|
|
6814
|
-
|
|
6901
|
+
brief: clampBriefArrays(briefSchema.parse(output)),
|
|
6815
6902
|
usage: readUsage(response),
|
|
6816
|
-
unexpectedKeys: detectUnexpectedKeysFromRawText(response.text,
|
|
6903
|
+
unexpectedKeys: detectUnexpectedKeysFromRawText(response.text, briefSchema.keyof().options)
|
|
6817
6904
|
};
|
|
6818
|
-
};
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
const
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6905
|
+
});
|
|
6906
|
+
}
|
|
6907
|
+
var artifactSchema = z8.object({ content: z8.string() });
|
|
6908
|
+
async function generateArtifactWithModel(args) {
|
|
6909
|
+
"use step";
|
|
6910
|
+
const diagnostics = { phase: "draft", provider: args.provider, modelId: args.modelId };
|
|
6911
|
+
return withModelCallDiagnostics(diagnostics, async () => {
|
|
6912
|
+
const model = await createLanguageModelFromConfig(args.provider, args.modelId, args.credentials);
|
|
6913
|
+
const attempt = async (messages) => {
|
|
6914
|
+
const response = await withContentPolicyAwareRetry(() => generateTextWithModel({
|
|
6915
|
+
model,
|
|
6916
|
+
maxRetries: 0,
|
|
6917
|
+
output: Output7.object({
|
|
6918
|
+
name: "generated_text",
|
|
6919
|
+
description: "One finished artifact written from the editorial brief.",
|
|
6920
|
+
schema: artifactSchema
|
|
6921
|
+
}),
|
|
6922
|
+
system: args.systemPrompt,
|
|
6923
|
+
messages
|
|
6924
|
+
}));
|
|
6925
|
+
const output = getGeneratedOutputWithContentPolicyHandling(response);
|
|
6926
|
+
if (!output) {
|
|
6927
|
+
throw new Error("Generated text output missing");
|
|
6928
|
+
}
|
|
6929
|
+
return {
|
|
6930
|
+
content: artifactSchema.parse(output).content.trim(),
|
|
6931
|
+
usage: readUsage(response),
|
|
6932
|
+
unexpectedKeys: detectUnexpectedKeysFromRawText(response.text, artifactSchema.keyof().options)
|
|
6933
|
+
};
|
|
6934
|
+
};
|
|
6935
|
+
const judge = (content) => content ? findGenerateTextLengthViolation(content, args.limits) : "empty";
|
|
6936
|
+
const initialMessages = [{ role: "user", content: args.userPrompt }];
|
|
6937
|
+
const first = await attempt(initialMessages);
|
|
6938
|
+
const firstViolation = judge(first.content);
|
|
6939
|
+
const firstEscaped = hasEscapedLineBreaks(first.content);
|
|
6940
|
+
if (!firstViolation && !firstEscaped) {
|
|
6941
|
+
return { content: first.content, usages: [first.usage], unexpectedKeys: first.unexpectedKeys };
|
|
6942
|
+
}
|
|
6943
|
+
let candidate = first;
|
|
6944
|
+
const usages = [first.usage];
|
|
6945
|
+
const unexpectedKeys = [...first.unexpectedKeys];
|
|
6946
|
+
if (firstViolation === "empty" || firstEscaped) {
|
|
6947
|
+
const feedback = [
|
|
6948
|
+
firstViolation && firstViolation !== "empty" ? describeLengthRevision(firstViolation) : void 0,
|
|
6949
|
+
firstEscaped ? ESCAPED_TEXT_REVISION : void 0
|
|
6950
|
+
].filter((line) => Boolean(line)).join("\n");
|
|
6951
|
+
const revisionMessages = firstViolation === "empty" ? [{ role: "user", content: `${args.userPrompt}
|
|
6836
6952
|
|
|
6837
6953
|
${renderSection({ tag: "revision_request", content: "The previous draft was empty. Write the complete artifact." })}` }] : [...initialMessages, { role: "assistant", content: JSON.stringify({ content: first.content }) }, { role: "user", content: renderSection({ tag: "revision_request", content: feedback }) }];
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
failure
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
}
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
});
|
|
6954
|
+
diagnostics.phase = "format_repair";
|
|
6955
|
+
candidate = await attempt(revisionMessages).catch((error) => rethrowWithTokenUsage(error, usages));
|
|
6956
|
+
usages.push(candidate.usage);
|
|
6957
|
+
unexpectedKeys.push(...candidate.unexpectedKeys);
|
|
6958
|
+
}
|
|
6959
|
+
const violation = judge(candidate.content);
|
|
6960
|
+
if (!violation || violation === "empty") {
|
|
6961
|
+
return { content: candidate.content, usages, unexpectedKeys, violation };
|
|
6962
|
+
}
|
|
6963
|
+
diagnostics.phase = "length_repair";
|
|
6964
|
+
const repaired = await repairText({
|
|
6965
|
+
content: candidate.content,
|
|
6966
|
+
limits: args.limits,
|
|
6967
|
+
protectedTerms: args.protectedTerms,
|
|
6968
|
+
model
|
|
6969
|
+
});
|
|
6970
|
+
usages.push(...repaired.attempts.flatMap((item) => item.call.usage ? [item.call.usage] : []));
|
|
6971
|
+
if (repaired.status !== "valid") {
|
|
6972
|
+
const cause = repaired.attempts.at(-1)?.call.errorCause;
|
|
6973
|
+
let failure;
|
|
6974
|
+
if (isIncompleteGenerationError(cause)) {
|
|
6975
|
+
failure = new IncompleteGenerationError(cause.finishReason, cause.rawFinishReason);
|
|
6976
|
+
} else if (MuxAiError.is(cause)) {
|
|
6977
|
+
failure = new MuxAiError(cause.publicMessage, { type: cause.publicType, retryable: cause.retryable });
|
|
6978
|
+
} else {
|
|
6979
|
+
const apiError = APICallError4.isInstance(cause) ? cause : void 0;
|
|
6980
|
+
failure = new MuxAiError("Unable to complete text generation.", {
|
|
6981
|
+
type: "processing_error",
|
|
6982
|
+
retryable: apiError?.isRetryable ?? true,
|
|
6983
|
+
cause
|
|
6984
|
+
});
|
|
6985
|
+
}
|
|
6986
|
+
if (typeof cause === "object" && cause !== null && "diagnostics" in cause) {
|
|
6987
|
+
failure.diagnostics = cause.diagnostics;
|
|
6988
|
+
}
|
|
6989
|
+
rethrowWithTokenUsage(failure, usages);
|
|
6875
6990
|
}
|
|
6876
|
-
|
|
6877
|
-
}
|
|
6878
|
-
return { content: repaired.content, usages, unexpectedKeys };
|
|
6991
|
+
return { content: repaired.content, usages, unexpectedKeys };
|
|
6992
|
+
});
|
|
6879
6993
|
}
|
|
6880
6994
|
async function generateText7(assetId, options) {
|
|
6881
6995
|
"use workflow";
|
|
@@ -7799,6 +7913,7 @@ async function getModerationScores(assetId, options = {}) {
|
|
|
7799
7913
|
provider = DEFAULT_PROVIDER2,
|
|
7800
7914
|
model = provider === "openai" ? "omni-moderation-latest" : void 0,
|
|
7801
7915
|
languageCode,
|
|
7916
|
+
includeTranscript = true,
|
|
7802
7917
|
thresholds = DEFAULT_THRESHOLDS,
|
|
7803
7918
|
thumbnailInterval = 10,
|
|
7804
7919
|
thumbnailWidth = 640,
|
|
@@ -7879,8 +7994,15 @@ async function getModerationScores(assetId, options = {}) {
|
|
|
7879
7994
|
let transcriptModeration = { status: "completed" };
|
|
7880
7995
|
let transcriptCues = [];
|
|
7881
7996
|
let shouldRunTranscript = false;
|
|
7882
|
-
const
|
|
7883
|
-
|
|
7997
|
+
const transcriptEnabled = includeTranscript || isAudioOnly;
|
|
7998
|
+
const captionTrack = transcriptEnabled && provider === "openai" ? findCaptionTrack(asset, languageCode) : void 0;
|
|
7999
|
+
if (!transcriptEnabled) {
|
|
8000
|
+
transcriptModeration = {
|
|
8001
|
+
status: "skipped",
|
|
8002
|
+
skipReason: "disabled",
|
|
8003
|
+
skipMessage: "Transcript moderation was disabled with includeTranscript: false."
|
|
8004
|
+
};
|
|
8005
|
+
} else if (provider !== "openai") {
|
|
7884
8006
|
transcriptModeration = {
|
|
7885
8007
|
status: "skipped",
|
|
7886
8008
|
skipReason: "unsupported_provider",
|
|
@@ -9346,7 +9468,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9346
9468
|
|
|
9347
9469
|
// src/workflows/translate-captions.ts
|
|
9348
9470
|
import {
|
|
9349
|
-
APICallError as
|
|
9471
|
+
APICallError as APICallError5,
|
|
9350
9472
|
generateText as generateText9,
|
|
9351
9473
|
NoObjectGeneratedError as NoObjectGeneratedError3,
|
|
9352
9474
|
NoOutputGeneratedError as NoOutputGeneratedError2,
|
|
@@ -9501,7 +9623,7 @@ function isProviderServiceError(error) {
|
|
|
9501
9623
|
if (RetryError2.isInstance(error)) {
|
|
9502
9624
|
return isProviderServiceError(error.lastError);
|
|
9503
9625
|
}
|
|
9504
|
-
if (
|
|
9626
|
+
if (APICallError5.isInstance(error)) {
|
|
9505
9627
|
return true;
|
|
9506
9628
|
}
|
|
9507
9629
|
if (error instanceof Error && "cause" in error) {
|