@mux/ai 0.64.0-canary.103 → 0.65.0-canary.105
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-DxCv-w74.d.ts → index-BUM1MVpR.d.ts} +1 -1
- package/dist/{index-C0BdM1ob.d.ts → index-DtZUwuCb.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +98 -100
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +1 -1
- package/dist/primitives/index.js.map +1 -1
- package/dist/{transcripts-CGRjxn_g.d.ts → transcripts-qZm-RokR.d.ts} +1 -1
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +132 -136
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModel, generateText as generateText$1 } from 'ai';
|
|
2
|
-
import { aO as ClassifiedErrorsOption, O as WorkflowCredentialsInput, d as MuxAiError, e as MuxAsset, A as AssetTextTrack, a as MuxAiErrorFacts, K as TokenUsage, D as ScopedMuxAIOptions, I as ImageSubmissionMode, y as MuxAIOptions, j as ChunkingStrategy, N as VideoEmbeddingsResult, a9 as Hotspot, ag as Shot, a5 as VTTCue, L as ToneType, H as StorageAdapter } from './transcripts-
|
|
2
|
+
import { aO as ClassifiedErrorsOption, O as WorkflowCredentialsInput, d as MuxAiError, e as MuxAsset, A as AssetTextTrack, a as MuxAiErrorFacts, K as TokenUsage, D as ScopedMuxAIOptions, I as ImageSubmissionMode, y as MuxAIOptions, j as ChunkingStrategy, N as VideoEmbeddingsResult, a9 as Hotspot, ag as Shot, a5 as VTTCue, L as ToneType, H as StorageAdapter } from './transcripts-qZm-RokR.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { S as SafetyReport, e as PromptOverrides, h as SceneContextItemV1, D as DEFAULT_DESCRIPTION_LENGTH, a as DEFAULT_SUMMARY_KEYWORD_LIMIT, b as DEFAULT_TITLE_LENGTH } from './summarization-BFmhXeAu.js';
|
|
5
5
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as WorkflowCredentialsInput, R as WorkflowScope, T as TextChunk, j as ChunkingStrategy, a5 as VTTCue, a6 as CompletedShotsResult, a7 as DeletedShotsResult, a8 as ErroredShotsResult, a9 as Hotspot, aa as HotspotOptions, ab as HotspotResponse, ac as LOW_CONFIDENCE_THRESHOLD, ad as MAX_CUE_TEXT_CHARS, ae as ParseVTTCuesOptions, af as PendingShotsResult, ag as Shot, ah as ShotRequestOptions, ai as ShotsResult, aj as SkippedShotsResult, ak as TranscriptEmptyReason, al as TranscriptFetchOptions, am as TranscriptFetchStepResult, an as TranscriptResult, ao as WaitForShotsOptions, ap as buildTranscriptUrl, aq as buildVttFromCueBlocks, ar as buildVttFromTranslatedCueBlocks, as as concatenateVttSegments, at as extractTextFromVTT, au as extractTimestampedTranscript, av as fetchTranscriptDataForUrl, aw as fetchTranscriptForAsset, ax as filterVttByScope, ay as findCaptionTrack, az as getHotspotsForAsset, aA as getHotspotsForPlaybackId, aB as getHotspotsForVideo, aC as getReadyTextTracks, aD as getReliableLanguageCode, aE as getShotsForAsset, aF as parseVTTCues, aG as replaceCueText, aH as requestShotsForAsset, aI as sanitizeUntrustedText, aJ as secondsToTimestamp, aK as splitVttPreambleAndCueBlocks, aL as stripVttMetadataBlocks, aM as vttTimestampToSeconds, aN as waitForShotsForAsset } from './transcripts-
|
|
1
|
+
import { O as WorkflowCredentialsInput, R as WorkflowScope, T as TextChunk, j as ChunkingStrategy, a5 as VTTCue, a6 as CompletedShotsResult, a7 as DeletedShotsResult, a8 as ErroredShotsResult, a9 as Hotspot, aa as HotspotOptions, ab as HotspotResponse, ac as LOW_CONFIDENCE_THRESHOLD, ad as MAX_CUE_TEXT_CHARS, ae as ParseVTTCuesOptions, af as PendingShotsResult, ag as Shot, ah as ShotRequestOptions, ai as ShotsResult, aj as SkippedShotsResult, ak as TranscriptEmptyReason, al as TranscriptFetchOptions, am as TranscriptFetchStepResult, an as TranscriptResult, ao as WaitForShotsOptions, ap as buildTranscriptUrl, aq as buildVttFromCueBlocks, ar as buildVttFromTranslatedCueBlocks, as as concatenateVttSegments, at as extractTextFromVTT, au as extractTimestampedTranscript, av as fetchTranscriptDataForUrl, aw as fetchTranscriptForAsset, ax as filterVttByScope, ay as findCaptionTrack, az as getHotspotsForAsset, aA as getHotspotsForPlaybackId, aB as getHotspotsForVideo, aC as getReadyTextTracks, aD as getReliableLanguageCode, aE as getShotsForAsset, aF as parseVTTCues, aG as replaceCueText, aH as requestShotsForAsset, aI as sanitizeUntrustedText, aJ as secondsToTimestamp, aK as splitVttPreambleAndCueBlocks, aL as stripVttMetadataBlocks, aM as vttTimestampToSeconds, aN as waitForShotsForAsset } from './transcripts-qZm-RokR.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,8 +1,8 @@
|
|
|
1
|
-
import { M as MuxAiErrorDependency, a as MuxAiErrorFacts, b as MuxAiErrorSource, c as MuxAiErrorType, d as MuxAiError, e as MuxAsset, f as MuxAiErrorFactValue, g as MuxAiErrorCode, C as ClassifiedError, W as WorkflowCredentials, S as StoragePutObjectInput, h as StoragePresignGetObjectInput } from './transcripts-
|
|
2
|
-
export { A as AssetTextTrack, i as ChunkEmbedding, j as ChunkingStrategy, k as ClassifiedErrorInit, l as CodedClassification, E as Encrypted, m as EncryptedPayload, n as ErrorCatalogEntry, o as ErrorCauseSummary, I as ImageSubmissionMode, p as MUX_AI_ERROR_CATALOG, q as MUX_AI_ERROR_CODES, r as MUX_AI_ERROR_CODE_VALUES, s as MUX_AI_ERROR_DEPENDENCIES, t as MUX_AI_ERROR_DEPENDENCY_VALUES, u as MUX_AI_ERROR_SOURCES, v as MUX_AI_ERROR_SOURCE_VALUES, w as MUX_AI_ERROR_TYPES, x as MUX_AI_ERROR_TYPE_VALUES, y as MuxAIOptions, z as MuxAiErrorInit, P as PlaybackAsset, B as PlaybackPolicy, D as ScopedMuxAIOptions, F as SerializedClassification, G as SourceAndDependency, H as StorageAdapter, T as TextChunk, J as TokenChunkingConfig, K as TokenUsage, L as ToneType, U as UsageMetadata, V as VTTChunkingConfig, N as VideoEmbeddingsResult, O as WorkflowCredentialsInput, Q as WorkflowMuxClient, R as WorkflowScope, X as assertNever, Y as classificationInit, Z as decryptFromWorkflow, _ as encryptForWorkflow, $ as errorDetailFact, a0 as internalError, a1 as isTransientStatus, a2 as restoreClassification, a3 as serializeClassification, a4 as wrapError } from './transcripts-
|
|
3
|
-
export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, M as MUX_TRACK_PASSTHROUGH_MAX_CHARS, R as ReplaceAndCreateTextTrackInput, b as ReplaceAndCreateTextTrackResult, c as ReplaceAndCreateTrackInput, d as ReplaceExistingTracksPolicy, e as ReplaceSourceTrackInput, f as ReplaceableTrackType, S as SourceTrackReplacementPolicy, g as SupportedISO639_1, h as SupportedISO639_3, T as TextTrackReplacementPlan, i as TextTrackSummary, j as TextTrackTarget, k as TrackReplacementBlocked, l as TrackReplacementBlockedReason, m as TrackSummary, n as TrackTarget, o as buildMuxAiTrackPassthrough, p as findNameCollisionTextTracks, q as findSameLanguageTextTracks, r as getLanguageCodePair, s as getLanguageName, t as isDuplicateTrackNameError, u as isMuxGeneratedTextTrack, v as isUndeterminedLanguageCode, w as isValidISO639_1, x as isValidISO639_3, y as normalizeTrackLanguageCode, z as normalizeTrackName, A as planSourceTrackReplacement, B as planTextTrackReplacement, C as replaceAndCreateTextTrack, D as replaceAndCreateTrack, E as replaceSourceTrack, F as summarizeTextTrack, G as toISO639_1, H as toISO639_3, J as trackReplacementBlockedError, K as trackTargetFacts, N as validateTrackPassthrough, O as workflows } from './index-
|
|
1
|
+
import { M as MuxAiErrorDependency, a as MuxAiErrorFacts, b as MuxAiErrorSource, c as MuxAiErrorType, d as MuxAiError, e as MuxAsset, f as MuxAiErrorFactValue, g as MuxAiErrorCode, C as ClassifiedError, W as WorkflowCredentials, S as StoragePutObjectInput, h as StoragePresignGetObjectInput } from './transcripts-qZm-RokR.js';
|
|
2
|
+
export { A as AssetTextTrack, i as ChunkEmbedding, j as ChunkingStrategy, k as ClassifiedErrorInit, l as CodedClassification, E as Encrypted, m as EncryptedPayload, n as ErrorCatalogEntry, o as ErrorCauseSummary, I as ImageSubmissionMode, p as MUX_AI_ERROR_CATALOG, q as MUX_AI_ERROR_CODES, r as MUX_AI_ERROR_CODE_VALUES, s as MUX_AI_ERROR_DEPENDENCIES, t as MUX_AI_ERROR_DEPENDENCY_VALUES, u as MUX_AI_ERROR_SOURCES, v as MUX_AI_ERROR_SOURCE_VALUES, w as MUX_AI_ERROR_TYPES, x as MUX_AI_ERROR_TYPE_VALUES, y as MuxAIOptions, z as MuxAiErrorInit, P as PlaybackAsset, B as PlaybackPolicy, D as ScopedMuxAIOptions, F as SerializedClassification, G as SourceAndDependency, H as StorageAdapter, T as TextChunk, J as TokenChunkingConfig, K as TokenUsage, L as ToneType, U as UsageMetadata, V as VTTChunkingConfig, N as VideoEmbeddingsResult, O as WorkflowCredentialsInput, Q as WorkflowMuxClient, R as WorkflowScope, X as assertNever, Y as classificationInit, Z as decryptFromWorkflow, _ as encryptForWorkflow, $ as errorDetailFact, a0 as internalError, a1 as isTransientStatus, a2 as restoreClassification, a3 as serializeClassification, a4 as wrapError } from './transcripts-qZm-RokR.js';
|
|
3
|
+
export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, M as MUX_TRACK_PASSTHROUGH_MAX_CHARS, R as ReplaceAndCreateTextTrackInput, b as ReplaceAndCreateTextTrackResult, c as ReplaceAndCreateTrackInput, d as ReplaceExistingTracksPolicy, e as ReplaceSourceTrackInput, f as ReplaceableTrackType, S as SourceTrackReplacementPolicy, g as SupportedISO639_1, h as SupportedISO639_3, T as TextTrackReplacementPlan, i as TextTrackSummary, j as TextTrackTarget, k as TrackReplacementBlocked, l as TrackReplacementBlockedReason, m as TrackSummary, n as TrackTarget, o as buildMuxAiTrackPassthrough, p as findNameCollisionTextTracks, q as findSameLanguageTextTracks, r as getLanguageCodePair, s as getLanguageName, t as isDuplicateTrackNameError, u as isMuxGeneratedTextTrack, v as isUndeterminedLanguageCode, w as isValidISO639_1, x as isValidISO639_3, y as normalizeTrackLanguageCode, z as normalizeTrackName, A as planSourceTrackReplacement, B as planTextTrackReplacement, C as replaceAndCreateTextTrack, D as replaceAndCreateTrack, E as replaceSourceTrack, F as summarizeTextTrack, G as toISO639_1, H as toISO639_3, J as trackReplacementBlockedError, K as trackTargetFacts, N as validateTrackPassthrough, O as workflows } from './index-BUM1MVpR.js';
|
|
4
4
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
5
|
-
export { i as primitives } from './index-
|
|
5
|
+
export { i as primitives } from './index-DtZUwuCb.js';
|
|
6
6
|
import '@mux/ts';
|
|
7
7
|
import 'ai';
|
|
8
8
|
import 'zod';
|
|
@@ -11,7 +11,7 @@ import '@ai-sdk/anthropic';
|
|
|
11
11
|
import '@ai-sdk/google';
|
|
12
12
|
import '@ai-sdk/openai';
|
|
13
13
|
|
|
14
|
-
var version = "0.
|
|
14
|
+
var version = "0.65.0-canary.105";
|
|
15
15
|
|
|
16
16
|
interface DependencyErrorInit {
|
|
17
17
|
dependency: MuxAiErrorDependency;
|
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.
|
|
8
|
+
var version = "0.65.0-canary.105";
|
|
9
9
|
|
|
10
10
|
// node_modules/@workflow/serde/dist/index.js
|
|
11
11
|
var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
|
|
@@ -576,7 +576,7 @@ var MUX_AI_ERROR_CODES = {
|
|
|
576
576
|
INVALID_SCOPE: "invalid_scope",
|
|
577
577
|
/** Existing tracks block writing the output track under the chosen replacement policy. Facts: `reason` (`policy_fail`, `not_generated`, `name_collision`, `primary_audio`), `conflictingTracks` and the target track, plus `sourceRestored` and `restoredTrackId` when a source track was deleted first. */
|
|
578
578
|
TRACK_REPLACEMENT_BLOCKED: "track_replacement_blocked",
|
|
579
|
-
/** An option's value can't be used. Facts: `parameter` (the caller's option name), `reason` (`too_many`, `empty`, `too_long`, `disallowed_characters`, `not_normalized`, `multiline`, `required_with`, `conflicts_with`, `not_allowed`, `one_of_required`, `audio_only`) and the values the reason names: `count` and `max`, `index` (0-based entry), `length` and `maxLength`, `characters`, `with` and `withValue` (the other option), `allowed` and `value`, `parameters` (the options to choose from). */
|
|
579
|
+
/** An option's value can't be used. Facts: `parameter` (the caller's option name), `reason` (`too_many`, `empty`, `too_long`, `disallowed_characters`, `not_normalized`, `multiline`, `required_with`, `conflicts_with`, `not_allowed`, `one_of_required`, `audio_only`, `not_positive`) and the values the reason names: `count` and `max`, `index` (0-based entry), `length` and `maxLength`, `characters`, `with` and `withValue` (the other option), `allowed` and `value`, `parameters` (the options to choose from). */
|
|
580
580
|
INVALID_PARAMETER: "invalid_parameter",
|
|
581
581
|
/** A numeric option is outside its allowed range. Facts: `parameter` (the caller's option name), `value`, `min`, `max`, and `integer` when it must be a whole number. */
|
|
582
582
|
PARAMETER_OUT_OF_RANGE: "parameter_out_of_range",
|
|
@@ -2309,6 +2309,8 @@ function invalidParameterMessage(facts) {
|
|
|
2309
2309
|
return `${parameter} can't be combined with ${names(facts.with)}.`;
|
|
2310
2310
|
case "not_allowed":
|
|
2311
2311
|
return `${parameter} must be ${quotedList(facts.allowed)}${facts.value === void 0 ? "" : ` (received '${text(facts.value)}')`}.`;
|
|
2312
|
+
case "not_positive":
|
|
2313
|
+
return `${parameter} must be a positive number${facts.value === void 0 ? "" : ` (received ${text(facts.value)})`}.`;
|
|
2312
2314
|
case "one_of_required":
|
|
2313
2315
|
return `Provide at least one of ${names(facts.parameters)}.`;
|
|
2314
2316
|
case "audio_only":
|
|
@@ -5838,13 +5840,25 @@ function allowedAnswersForQuestion(q) {
|
|
|
5838
5840
|
return [];
|
|
5839
5841
|
}
|
|
5840
5842
|
}
|
|
5843
|
+
function numberFact(value) {
|
|
5844
|
+
return Number.isFinite(value) ? value : String(value);
|
|
5845
|
+
}
|
|
5846
|
+
function invalidOptionError(message, facts, inputs) {
|
|
5847
|
+
return new MuxAiError(message, {
|
|
5848
|
+
code: MUX_AI_ERROR_CODES.INVALID_PARAMETER,
|
|
5849
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
5850
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
5851
|
+
facts: { ...facts, inputs }
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5841
5854
|
function normalizeQuestion(q, idx) {
|
|
5842
5855
|
const hasOptions = Array.isArray(q.answerOptions);
|
|
5843
5856
|
const isFreeForm = q.freeFormReply === true;
|
|
5844
5857
|
if (hasOptions && isFreeForm) {
|
|
5845
|
-
throw
|
|
5858
|
+
throw invalidOptionError(
|
|
5846
5859
|
`Question at index ${idx} sets both answerOptions and freeFormReply: true. These are mutually exclusive \u2014 pick one.`,
|
|
5847
|
-
{
|
|
5860
|
+
{ parameter: `questions[${idx}].answerOptions`, reason: "conflicts_with", with: `questions[${idx}].freeFormReply` },
|
|
5861
|
+
["questions"]
|
|
5848
5862
|
);
|
|
5849
5863
|
}
|
|
5850
5864
|
if (isFreeForm) {
|
|
@@ -5857,9 +5871,10 @@ function normalizeQuestion(q, idx) {
|
|
|
5857
5871
|
)
|
|
5858
5872
|
);
|
|
5859
5873
|
if (!options.length) {
|
|
5860
|
-
throw
|
|
5874
|
+
throw invalidOptionError(
|
|
5861
5875
|
`Question at index ${idx} has invalid answerOptions: must include at least one non-empty value.`,
|
|
5862
|
-
{
|
|
5876
|
+
{ parameter: `questions[${idx}].answerOptions`, reason: "empty" },
|
|
5877
|
+
["questions"]
|
|
5863
5878
|
);
|
|
5864
5879
|
}
|
|
5865
5880
|
return {
|
|
@@ -5930,7 +5945,7 @@ ${questionBlocks}
|
|
|
5930
5945
|
}
|
|
5931
5946
|
async function fetchImageAsBase64(imageUrl, imageDownloadOptions) {
|
|
5932
5947
|
"use step";
|
|
5933
|
-
const downloadResult = await downloadImageAsBase64(imageUrl, imageDownloadOptions);
|
|
5948
|
+
const downloadResult = await downloadImageAsBase64(imageUrl, imageDownloadOptions, { classifiedErrors: true, call: "fetch_storyboard" });
|
|
5934
5949
|
return downloadResult.base64Data;
|
|
5935
5950
|
}
|
|
5936
5951
|
function buildResponseSchemaForQuestions(normalizedQuestions, maxFreeFormAnswerLength) {
|
|
@@ -5968,6 +5983,7 @@ async function analyzeQuestions({
|
|
|
5968
5983
|
normalizedQuestions,
|
|
5969
5984
|
maxFreeFormAnswerLength
|
|
5970
5985
|
);
|
|
5986
|
+
const context = { call: "answer_questions", provider, model: modelId };
|
|
5971
5987
|
const response = await withContentPolicyAwareRetry(() => generateText2({
|
|
5972
5988
|
model,
|
|
5973
5989
|
maxRetries: 0,
|
|
@@ -5983,11 +5999,10 @@ async function analyzeQuestions({
|
|
|
5983
5999
|
] : userPrompt
|
|
5984
6000
|
}
|
|
5985
6001
|
]
|
|
5986
|
-
}))
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
}
|
|
6002
|
+
}), void 0, context).catch((error) => {
|
|
6003
|
+
throw modelStepError(error, "Ask-questions model call failed", { ...context });
|
|
6004
|
+
});
|
|
6005
|
+
const output = getGeneratedOutputWithContentPolicyHandling(response, context);
|
|
5991
6006
|
const parsed = responseSchema.parse(output);
|
|
5992
6007
|
const unexpectedRootKeys = detectUnexpectedKeysFromRawText(
|
|
5993
6008
|
response.text,
|
|
@@ -6028,33 +6043,37 @@ async function askQuestions(assetId, questions, options) {
|
|
|
6028
6043
|
}
|
|
6029
6044
|
async function askQuestionsInternal(assetId, questions, options, collectedUsage) {
|
|
6030
6045
|
if (!questions || questions.length === 0) {
|
|
6031
|
-
throw
|
|
6046
|
+
throw invalidOptionError("At least one question must be provided.", { parameter: "questions", reason: "empty" }, ["questions"]);
|
|
6032
6047
|
}
|
|
6033
6048
|
if (questions.length > ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL) {
|
|
6034
|
-
throw
|
|
6049
|
+
throw invalidOptionError(
|
|
6035
6050
|
`Too many questions: received ${questions.length}, but at most ${ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL} are allowed per call.`,
|
|
6036
|
-
{
|
|
6051
|
+
{ parameter: "questions", reason: "too_many", count: questions.length, max: ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL },
|
|
6052
|
+
["questions"]
|
|
6037
6053
|
);
|
|
6038
6054
|
}
|
|
6039
6055
|
questions.forEach((q, idx) => {
|
|
6040
6056
|
if (!q.question || typeof q.question !== "string" || !q.question.trim()) {
|
|
6041
|
-
throw
|
|
6057
|
+
throw invalidOptionError(
|
|
6042
6058
|
`Question at index ${idx} is invalid: must have a non-empty question field.`,
|
|
6043
|
-
{
|
|
6059
|
+
{ parameter: `questions[${idx}].question`, reason: "empty" },
|
|
6060
|
+
["questions"]
|
|
6044
6061
|
);
|
|
6045
6062
|
}
|
|
6046
6063
|
if (q.question.length > ASK_QUESTIONS_MAX_QUESTION_LENGTH) {
|
|
6047
|
-
throw
|
|
6064
|
+
throw invalidOptionError(
|
|
6048
6065
|
`Question at index ${idx} exceeds the ${ASK_QUESTIONS_MAX_QUESTION_LENGTH}-character limit (received ${q.question.length}).`,
|
|
6049
|
-
{
|
|
6066
|
+
{ parameter: `questions[${idx}].question`, reason: "too_long", length: q.question.length, maxLength: ASK_QUESTIONS_MAX_QUESTION_LENGTH },
|
|
6067
|
+
["questions"]
|
|
6050
6068
|
);
|
|
6051
6069
|
}
|
|
6052
6070
|
});
|
|
6053
6071
|
const maxAnswerOptionLength = options?.maxAnswerOptionLength ?? ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH;
|
|
6054
6072
|
if (!Number.isFinite(maxAnswerOptionLength) || maxAnswerOptionLength <= 0) {
|
|
6055
|
-
throw
|
|
6073
|
+
throw invalidOptionError(
|
|
6056
6074
|
`maxAnswerOptionLength must be a positive number (received ${maxAnswerOptionLength}).`,
|
|
6057
|
-
{
|
|
6075
|
+
{ parameter: "maxAnswerOptionLength", reason: "not_positive", value: numberFact(maxAnswerOptionLength) },
|
|
6076
|
+
["maxAnswerOptionLength"]
|
|
6058
6077
|
);
|
|
6059
6078
|
}
|
|
6060
6079
|
questions.forEach((q, idx) => {
|
|
@@ -6062,18 +6081,20 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
6062
6081
|
return;
|
|
6063
6082
|
for (const opt of q.answerOptions ?? []) {
|
|
6064
6083
|
if (typeof opt === "string" && opt.length > maxAnswerOptionLength) {
|
|
6065
|
-
throw
|
|
6084
|
+
throw invalidOptionError(
|
|
6066
6085
|
`Question at index ${idx} has an answerOption exceeding the ${maxAnswerOptionLength}-character limit (received ${opt.length}). Answer options should be short labels, not sentences.`,
|
|
6067
|
-
{
|
|
6086
|
+
{ parameter: `questions[${idx}].answerOptions`, reason: "too_long", length: opt.length, maxLength: maxAnswerOptionLength },
|
|
6087
|
+
["questions", "maxAnswerOptionLength"]
|
|
6068
6088
|
);
|
|
6069
6089
|
}
|
|
6070
6090
|
}
|
|
6071
6091
|
});
|
|
6072
6092
|
const maxFreeFormAnswerLength = options?.maxFreeFormAnswerLength ?? ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH;
|
|
6073
6093
|
if (!Number.isFinite(maxFreeFormAnswerLength) || maxFreeFormAnswerLength <= 0) {
|
|
6074
|
-
throw
|
|
6094
|
+
throw invalidOptionError(
|
|
6075
6095
|
`maxFreeFormAnswerLength must be a positive number (received ${maxFreeFormAnswerLength}).`,
|
|
6076
|
-
{
|
|
6096
|
+
{ parameter: "maxFreeFormAnswerLength", reason: "not_positive", value: numberFact(maxFreeFormAnswerLength) },
|
|
6097
|
+
["maxFreeFormAnswerLength"]
|
|
6077
6098
|
);
|
|
6078
6099
|
}
|
|
6079
6100
|
const {
|
|
@@ -6095,30 +6116,29 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
6095
6116
|
model,
|
|
6096
6117
|
provider
|
|
6097
6118
|
});
|
|
6098
|
-
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options?.assetSnapshot);
|
|
6119
|
+
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options?.assetSnapshot, { classifiedErrors: true });
|
|
6099
6120
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
|
|
6100
6121
|
const isAudioOnly = isAudioOnlyAsset(assetData);
|
|
6101
6122
|
const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
|
|
6102
6123
|
const storyboardScope = isAudioOnly ? void 0 : resolveRenderableVideoScope(
|
|
6103
6124
|
effectiveScope,
|
|
6104
6125
|
assetDurationSeconds,
|
|
6105
|
-
getVideoTrackDurationSecondsFromAsset(assetData)
|
|
6126
|
+
getVideoTrackDurationSecondsFromAsset(assetData),
|
|
6127
|
+
{ classifiedErrors: true, assetId }
|
|
6106
6128
|
);
|
|
6107
6129
|
if (isAudioOnly && effectiveScope) {
|
|
6108
|
-
resolveWorkflowScope(effectiveScope, assetDurationSeconds);
|
|
6130
|
+
resolveWorkflowScope(effectiveScope, assetDurationSeconds, { classifiedErrors: true, assetId });
|
|
6109
6131
|
}
|
|
6110
6132
|
if (isAudioOnly && !includeTranscript) {
|
|
6111
|
-
throw
|
|
6133
|
+
throw invalidOptionError(
|
|
6112
6134
|
"Audio-only assets require a transcript. Set includeTranscript: true and ensure the asset has a ready text track (captions/subtitles).",
|
|
6113
|
-
{
|
|
6135
|
+
{ parameter: "includeTranscript", reason: "audio_only", allowed: [true], value: false, assetId },
|
|
6136
|
+
["includeTranscript"]
|
|
6114
6137
|
);
|
|
6115
6138
|
}
|
|
6116
6139
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
6117
6140
|
if (policy === "signed" && !signingContext) {
|
|
6118
|
-
throw
|
|
6119
|
-
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
6120
|
-
{ type: "validation_error" }
|
|
6121
|
-
);
|
|
6141
|
+
throw signingCredentialsMissingError();
|
|
6122
6142
|
}
|
|
6123
6143
|
const transcriptResult = includeTranscript ? await fetchTranscriptForAsset(assetData, playbackId, {
|
|
6124
6144
|
languageCode,
|
|
@@ -6126,7 +6146,8 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
6126
6146
|
shouldSign: policy === "signed",
|
|
6127
6147
|
credentials,
|
|
6128
6148
|
required: isAudioOnly,
|
|
6129
|
-
scope: effectiveScope
|
|
6149
|
+
scope: effectiveScope,
|
|
6150
|
+
classifiedErrors: true
|
|
6130
6151
|
}) : void 0;
|
|
6131
6152
|
const transcriptText = transcriptResult?.transcriptText ?? "";
|
|
6132
6153
|
const userPrompt = buildUserPrompt({
|
|
@@ -6137,65 +6158,38 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
6137
6158
|
maxFreeFormAnswerLength
|
|
6138
6159
|
});
|
|
6139
6160
|
const systemPrompt = buildSystemPrompt(isAudioOnly, hasFreeForm, maxFreeFormAnswerLength);
|
|
6140
|
-
let analysisResponse;
|
|
6141
6161
|
let imageUrl;
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
});
|
|
6153
|
-
} else {
|
|
6154
|
-
const storyboardUrl = await getStoryboardUrl(
|
|
6155
|
-
playbackId,
|
|
6156
|
-
storyboardWidth,
|
|
6157
|
-
policy === "signed",
|
|
6158
|
-
credentials,
|
|
6159
|
-
storyboardScope
|
|
6160
|
-
);
|
|
6161
|
-
imageUrl = storyboardUrl;
|
|
6162
|
-
if (imageSubmissionMode === "base64") {
|
|
6163
|
-
const base64Data = await fetchImageAsBase64(storyboardUrl, imageDownloadOptions);
|
|
6164
|
-
analysisResponse = await analyzeQuestions({
|
|
6165
|
-
provider: modelConfig.provider,
|
|
6166
|
-
modelId: modelConfig.modelId,
|
|
6167
|
-
userPrompt,
|
|
6168
|
-
systemPrompt,
|
|
6169
|
-
normalizedQuestions,
|
|
6170
|
-
maxFreeFormAnswerLength,
|
|
6171
|
-
imageDataUrl: base64Data,
|
|
6172
|
-
credentials
|
|
6173
|
-
});
|
|
6174
|
-
} else {
|
|
6175
|
-
analysisResponse = await analyzeQuestions({
|
|
6176
|
-
provider: modelConfig.provider,
|
|
6177
|
-
modelId: modelConfig.modelId,
|
|
6178
|
-
userPrompt,
|
|
6179
|
-
systemPrompt,
|
|
6180
|
-
normalizedQuestions,
|
|
6181
|
-
maxFreeFormAnswerLength,
|
|
6182
|
-
imageDataUrl: storyboardUrl,
|
|
6183
|
-
credentials
|
|
6184
|
-
});
|
|
6185
|
-
}
|
|
6186
|
-
}
|
|
6187
|
-
} catch (error) {
|
|
6188
|
-
const contentType = isAudioOnly ? "audio" : "video";
|
|
6189
|
-
legacyWrapError(error, `Failed to analyze ${contentType} questions with ${provider}`);
|
|
6162
|
+
let imageDataUrl;
|
|
6163
|
+
if (!isAudioOnly) {
|
|
6164
|
+
imageUrl = await getStoryboardUrl(
|
|
6165
|
+
playbackId,
|
|
6166
|
+
storyboardWidth,
|
|
6167
|
+
policy === "signed",
|
|
6168
|
+
credentials,
|
|
6169
|
+
storyboardScope
|
|
6170
|
+
);
|
|
6171
|
+
imageDataUrl = imageSubmissionMode === "base64" ? await fetchImageAsBase64(imageUrl, imageDownloadOptions) : imageUrl;
|
|
6190
6172
|
}
|
|
6173
|
+
const modelFacts = { call: "answer_questions", provider: modelConfig.provider, model: modelConfig.modelId, assetId };
|
|
6174
|
+
const analysisResponse = await analyzeQuestions({
|
|
6175
|
+
provider: modelConfig.provider,
|
|
6176
|
+
modelId: modelConfig.modelId,
|
|
6177
|
+
userPrompt,
|
|
6178
|
+
systemPrompt,
|
|
6179
|
+
normalizedQuestions,
|
|
6180
|
+
maxFreeFormAnswerLength,
|
|
6181
|
+
imageDataUrl,
|
|
6182
|
+
credentials
|
|
6183
|
+
}).catch((error) => wrapError(error, `Failed to analyze ${isAudioOnly ? "audio" : "video"} questions with ${modelConfig.provider}`, modelFacts));
|
|
6191
6184
|
collectedUsage.push(analysisResponse.usage);
|
|
6192
|
-
if (!analysisResponse.result?.answers) {
|
|
6193
|
-
throw new LegacyMuxAiError(`Failed to generate answers for asset ${assetId}.`);
|
|
6194
|
-
}
|
|
6195
6185
|
if (analysisResponse.result.answers.length !== questions.length) {
|
|
6196
|
-
throw new
|
|
6197
|
-
|
|
6198
|
-
|
|
6186
|
+
throw new MuxAiError(`Failed to generate answers for all questions for asset ${assetId}.`, {
|
|
6187
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
6188
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
6189
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
6190
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
6191
|
+
facts: { ...modelFacts, questionCount: questions.length, returnedAnswerCount: analysisResponse.result.answers.length }
|
|
6192
|
+
});
|
|
6199
6193
|
}
|
|
6200
6194
|
const safety = createSafetyReporter();
|
|
6201
6195
|
for (const key of analysisResponse.unexpectedRootKeys) {
|
|
@@ -6228,9 +6222,13 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
6228
6222
|
if (!isSkipped && !isFreeForm) {
|
|
6229
6223
|
const allowed = allowedAnswersForQuestion(question);
|
|
6230
6224
|
if (!allowed.includes(raw.answer)) {
|
|
6231
|
-
throw new
|
|
6232
|
-
|
|
6233
|
-
|
|
6225
|
+
throw new MuxAiError(`Answer "${raw.answer}" for question ${idx} is not in allowed options: ${allowed.join(", ")}`, {
|
|
6226
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
6227
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
6228
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
6229
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
6230
|
+
facts: { ...modelFacts, questionIndex: idx }
|
|
6231
|
+
});
|
|
6234
6232
|
}
|
|
6235
6233
|
}
|
|
6236
6234
|
let finalAnswer;
|
|
@@ -7266,7 +7264,7 @@ function restoreFailureFacts(error) {
|
|
|
7266
7264
|
restoreFailure: error.facts
|
|
7267
7265
|
};
|
|
7268
7266
|
}
|
|
7269
|
-
function
|
|
7267
|
+
function invalidOptionError2(message, facts, inputs) {
|
|
7270
7268
|
return new MuxAiError(message, {
|
|
7271
7269
|
code: MUX_AI_ERROR_CODES.INVALID_PARAMETER,
|
|
7272
7270
|
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
@@ -7325,14 +7323,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
7325
7323
|
const hasSpeakerReplacements = !!speakerReplacementsOption && speakerReplacementsOption.length > 0;
|
|
7326
7324
|
if (!hasAutoCensor && !hasReplacements && !hasSpeakerReplacements) {
|
|
7327
7325
|
const parameters = ["autoCensorProfanity", "replacements", "speakerReplacements"];
|
|
7328
|
-
throw
|
|
7326
|
+
throw invalidOptionError2(
|
|
7329
7327
|
"At least one of autoCensorProfanity, replacements, or speakerReplacements must be provided.",
|
|
7330
7328
|
{ reason: "one_of_required", parameters },
|
|
7331
7329
|
parameters
|
|
7332
7330
|
);
|
|
7333
7331
|
}
|
|
7334
7332
|
if (autoCensorOption && !provider) {
|
|
7335
|
-
throw
|
|
7333
|
+
throw invalidOptionError2(
|
|
7336
7334
|
"provider is required when using autoCensorProfanity.",
|
|
7337
7335
|
{ parameter: "provider", reason: "required_with", with: "autoCensorProfanity" },
|
|
7338
7336
|
["provider", "autoCensorProfanity"]
|
|
@@ -7345,14 +7343,14 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
7345
7343
|
...replaceExistingTracksOption !== void 0 ? ["replaceExistingTracks"] : [],
|
|
7346
7344
|
...providedTrackName !== void 0 ? ["trackName"] : []
|
|
7347
7345
|
];
|
|
7348
|
-
throw
|
|
7346
|
+
throw invalidOptionError2(
|
|
7349
7347
|
"deleteOriginalTrack and trackNameSuffix are deprecated and cannot be combined with replaceExistingTracks or trackName.",
|
|
7350
7348
|
{ parameter: legacy, reason: "conflicts_with", with: conflicting },
|
|
7351
7349
|
[legacy, ...conflicting]
|
|
7352
7350
|
);
|
|
7353
7351
|
}
|
|
7354
7352
|
if (replaceExistingTracksOption !== void 0 && replaceExistingTracksOption !== "replace" && replaceExistingTracksOption !== "fail") {
|
|
7355
|
-
throw
|
|
7353
|
+
throw invalidOptionError2(
|
|
7356
7354
|
`replaceExistingTracks must be "replace" or "fail" for editCaptions (received "${String(replaceExistingTracksOption)}").`,
|
|
7357
7355
|
{
|
|
7358
7356
|
parameter: "replaceExistingTracks",
|
|
@@ -7365,7 +7363,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
7365
7363
|
}
|
|
7366
7364
|
const replaceExistingTracks = replaceExistingTracksOption ?? "replace";
|
|
7367
7365
|
if (!legacyTrackNaming && replaceExistingTracks === "fail" && !providedTrackName) {
|
|
7368
|
-
throw
|
|
7366
|
+
throw invalidOptionError2(
|
|
7369
7367
|
`trackName is required when replaceExistingTracks is "fail": the edited track cannot reuse the source track's name while the source is kept.`,
|
|
7370
7368
|
{ parameter: "trackName", reason: "required_with", with: "replaceExistingTracks", withValue: "fail" },
|
|
7371
7369
|
["trackName", "replaceExistingTracks"]
|
|
@@ -7378,7 +7376,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
7378
7376
|
for (const [index, replacement] of (speakerReplacementsOption ?? []).entries()) {
|
|
7379
7377
|
const reason = speakerLabelProblem(replacement.find) ?? speakerLabelProblem(replacement.replace);
|
|
7380
7378
|
if (reason) {
|
|
7381
|
-
throw
|
|
7379
|
+
throw invalidOptionError2(
|
|
7382
7380
|
"Speaker replacement labels must be non-empty and must not contain square brackets or newlines.",
|
|
7383
7381
|
{ parameter: "speakerReplacements", reason, index, ...reason === "disallowed_characters" && { characters: ["[", "]"] } },
|
|
7384
7382
|
["speakerReplacements"]
|