@mux/ai 0.62.0 → 0.63.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-BN5yOn9o.d.ts → index-CA8sRSVJ.d.ts} +2 -534
- package/dist/{index-CHA2jigS.d.ts → index-eEZfpEP7.d.ts} +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +168 -78
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +3 -2
- package/dist/primitives/index.js +195 -30
- package/dist/primitives/index.js.map +1 -1
- package/dist/transcripts-So1KIXSI.d.ts +1152 -0
- package/dist/workflows/index.d.ts +3 -3
- package/dist/workflows/index.js +165 -77
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/transcripts-DuNI058z.d.ts +0 -613
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { M as MuxAiErrorDependency, a as MuxAiErrorFacts, b as MuxAiErrorSource, c as MuxAiErrorType, d as MuxAiError, e as
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export { A as AssetTextTrack, C as ChunkEmbedding, b as ChunkingStrategy, E as Encrypted, c as EncryptedPayload, I as ImageSubmissionMode, d as MuxAIOptions, 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 './transcripts-DuNI058z.js';
|
|
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-So1KIXSI.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-So1KIXSI.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-CA8sRSVJ.js';
|
|
5
4
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
6
|
-
export { i as primitives } from './index-
|
|
5
|
+
export { i as primitives } from './index-eEZfpEP7.js';
|
|
6
|
+
import '@mux/ts';
|
|
7
7
|
import 'ai';
|
|
8
8
|
import 'zod';
|
|
9
9
|
import './summarization-BFmhXeAu.js';
|
|
10
10
|
import '@ai-sdk/anthropic';
|
|
11
11
|
import '@ai-sdk/google';
|
|
12
12
|
import '@ai-sdk/openai';
|
|
13
|
-
import '@mux/ts';
|
|
14
13
|
|
|
15
|
-
var version = "0.
|
|
14
|
+
var version = "0.63.0";
|
|
16
15
|
|
|
17
16
|
interface DependencyErrorInit {
|
|
18
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.63.0";
|
|
9
9
|
|
|
10
10
|
// node_modules/@workflow/serde/dist/index.js
|
|
11
11
|
var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
|
|
@@ -572,7 +572,7 @@ var MUX_AI_ERROR_DEPENDENCIES = {
|
|
|
572
572
|
};
|
|
573
573
|
var MUX_AI_ERROR_DEPENDENCY_VALUES = Object.values(MUX_AI_ERROR_DEPENDENCIES);
|
|
574
574
|
var MUX_AI_ERROR_CODES = {
|
|
575
|
-
/** The requested time range is invalid, or has nothing to work with. Facts: `reason` (`invalid_start_time`, `invalid_end_time`, `exceeds_duration`, `empty_range`, `no_video`, `no_transcript`) and the bounds involved. */
|
|
575
|
+
/** The requested time range is invalid, or has nothing to work with. Facts: `reason` (`invalid_start_time`, `invalid_end_time`, `exceeds_duration`, `empty_range`, `no_video`, `no_transcript`, `no_scenes`) and the bounds involved. */
|
|
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",
|
|
@@ -604,6 +604,8 @@ var MUX_AI_ERROR_CODES = {
|
|
|
604
604
|
TRACK_WRITE_UNCLASSIFIED: "track_write_unclassified",
|
|
605
605
|
/** Mux answered a track create without a track id. The track may exist, so it isn't step-retried. Facts: `call`, `assetId`. */
|
|
606
606
|
TRACK_ID_MISSING: "track_id_missing",
|
|
607
|
+
/** The asset's ready caption track has no id, so its transcript can't be fetched. Facts: `assetId`, `languageCode`. */
|
|
608
|
+
CAPTION_TRACK_ID_MISSING: "caption_track_id_missing",
|
|
607
609
|
/** The asset snapshot the service running the SDK passed in is for a different asset than the one requested. Facts: `assetId`, `snapshotAssetId`. */
|
|
608
610
|
ASSET_SNAPSHOT_MISMATCH: "asset_snapshot_mismatch",
|
|
609
611
|
/** Mux answered an asset fetch with a different asset than the one requested. Facts: `assetId`, `returnedAssetId`. */
|
|
@@ -664,6 +666,7 @@ var MUX_AI_ERROR_CATALOG = {
|
|
|
664
666
|
[MUX_AI_ERROR_CODES.CAPTION_TRACK_LANGUAGE_MISSING]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
665
667
|
// The track may exist, so a step retry could duplicate it; the job stays retryable.
|
|
666
668
|
[MUX_AI_ERROR_CODES.TRACK_ID_MISSING]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
669
|
+
[MUX_AI_ERROR_CODES.CAPTION_TRACK_ID_MISSING]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
667
670
|
[MUX_AI_ERROR_CODES.ASSET_ID_MISMATCH]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
668
671
|
// Model calls.
|
|
669
672
|
[MUX_AI_ERROR_CODES.CONTENT_POLICY_BLOCKED]: { type: MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER },
|
|
@@ -2265,6 +2268,8 @@ function scopeMessage(facts) {
|
|
|
2265
2268
|
return "The requested time range doesn't include any video.";
|
|
2266
2269
|
case "no_transcript":
|
|
2267
2270
|
return "The transcript has no content in the requested time range.";
|
|
2271
|
+
case "no_scenes":
|
|
2272
|
+
return "The requested time range doesn't include the start of any scene.";
|
|
2268
2273
|
default:
|
|
2269
2274
|
return "The requested time range can't be used for this asset.";
|
|
2270
2275
|
}
|
|
@@ -3686,35 +3691,60 @@ function chunkText(text2, strategy) {
|
|
|
3686
3691
|
function hasWorkflowScopeBoundaries(scope) {
|
|
3687
3692
|
return scope?.startTime !== void 0 || scope?.endTime !== void 0;
|
|
3688
3693
|
}
|
|
3689
|
-
function
|
|
3694
|
+
function invalidScopeError(message, facts, inputs) {
|
|
3695
|
+
return new MuxAiError(message, {
|
|
3696
|
+
code: MUX_AI_ERROR_CODES.INVALID_SCOPE,
|
|
3697
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
3698
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
3699
|
+
facts: { ...facts, inputs }
|
|
3700
|
+
});
|
|
3701
|
+
}
|
|
3702
|
+
function boundFact(value) {
|
|
3703
|
+
return Number.isFinite(value) ? value : String(value);
|
|
3704
|
+
}
|
|
3705
|
+
function resolveWorkflowScope(scope, assetDurationSeconds, options = {}) {
|
|
3706
|
+
const classified = options.classifiedErrors === true;
|
|
3690
3707
|
if (assetDurationSeconds === void 0 || !Number.isFinite(assetDurationSeconds) || assetDurationSeconds <= 0) {
|
|
3708
|
+
if (classified) {
|
|
3709
|
+
throw new MuxAiError("Asset has no valid duration.", {
|
|
3710
|
+
code: MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE,
|
|
3711
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
3712
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
3713
|
+
facts: { ...options.assetId && { assetId: options.assetId } }
|
|
3714
|
+
});
|
|
3715
|
+
}
|
|
3691
3716
|
throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
|
|
3692
3717
|
}
|
|
3693
3718
|
const startTime = scope?.startTime ?? 0;
|
|
3694
3719
|
const endTime = scope?.endTime ?? assetDurationSeconds;
|
|
3695
3720
|
if (!Number.isFinite(startTime) || startTime < 0) {
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
{
|
|
3699
|
-
|
|
3721
|
+
const message = `scope.startTime must be a finite, non-negative number (received ${startTime}).`;
|
|
3722
|
+
if (classified) {
|
|
3723
|
+
throw invalidScopeError(message, { reason: "invalid_start_time", received: boundFact(startTime) }, ["scope.startTime"]);
|
|
3724
|
+
}
|
|
3725
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
3700
3726
|
}
|
|
3701
3727
|
if (!Number.isFinite(endTime) || endTime < 0) {
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
{
|
|
3705
|
-
|
|
3728
|
+
const message = `scope.endTime must be a finite, non-negative number (received ${endTime}).`;
|
|
3729
|
+
if (classified) {
|
|
3730
|
+
throw invalidScopeError(message, { reason: "invalid_end_time", received: boundFact(endTime) }, ["scope.endTime"]);
|
|
3731
|
+
}
|
|
3732
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
3706
3733
|
}
|
|
3707
3734
|
if (endTime > assetDurationSeconds) {
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
{
|
|
3711
|
-
|
|
3735
|
+
const message = `scope.endTime (${endTime}) cannot exceed the asset duration (${assetDurationSeconds}).`;
|
|
3736
|
+
if (classified) {
|
|
3737
|
+
throw invalidScopeError(message, { reason: "exceeds_duration", endTime, assetDurationSeconds }, ["scope.endTime"]);
|
|
3738
|
+
}
|
|
3739
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
3712
3740
|
}
|
|
3713
3741
|
if (startTime >= endTime) {
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3742
|
+
const message = `scope.startTime (${startTime}) must be less than scope.endTime (${endTime}).`;
|
|
3743
|
+
if (classified) {
|
|
3744
|
+
const inputs = scope?.endTime === void 0 ? ["scope.startTime"] : ["scope.startTime", "scope.endTime"];
|
|
3745
|
+
throw invalidScopeError(message, { reason: "empty_range", startTime, endTime }, inputs);
|
|
3746
|
+
}
|
|
3747
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
3718
3748
|
}
|
|
3719
3749
|
return { startTime, endTime };
|
|
3720
3750
|
}
|
|
@@ -4282,11 +4312,7 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
|
|
|
4282
4312
|
"use step";
|
|
4283
4313
|
const { cleanTranscript = true, scope } = options;
|
|
4284
4314
|
try {
|
|
4285
|
-
const
|
|
4286
|
-
if (!response.ok) {
|
|
4287
|
-
throw new Error(`Failed to fetch transcript (HTTP ${response.status})`);
|
|
4288
|
-
}
|
|
4289
|
-
const rawVtt = await response.text();
|
|
4315
|
+
const rawVtt = options.classifiedErrors ? await fetchTranscriptVtt(transcriptUrl) : await fetchTranscriptVttLegacy(transcriptUrl);
|
|
4290
4316
|
const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
|
|
4291
4317
|
const scopedVtt = filterVttByScope(rawVtt, effectiveScope);
|
|
4292
4318
|
const transcriptText = cleanTranscript ? extractTextFromVTT(scopedVtt) : scopedVtt;
|
|
@@ -4299,24 +4325,69 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
|
|
|
4299
4325
|
}
|
|
4300
4326
|
return { transcriptText };
|
|
4301
4327
|
} catch (error) {
|
|
4328
|
+
if (options.classifiedErrors) {
|
|
4329
|
+
wrapError(error, "Failed to fetch transcript");
|
|
4330
|
+
}
|
|
4302
4331
|
legacyWrapError(error, "Failed to fetch transcript");
|
|
4303
4332
|
}
|
|
4304
4333
|
}
|
|
4334
|
+
async function fetchTranscriptVttLegacy(transcriptUrl) {
|
|
4335
|
+
const response = await fetch(transcriptUrl);
|
|
4336
|
+
if (!response.ok) {
|
|
4337
|
+
throw new Error(`Failed to fetch transcript (HTTP ${response.status})`);
|
|
4338
|
+
}
|
|
4339
|
+
return response.text();
|
|
4340
|
+
}
|
|
4341
|
+
async function fetchTranscriptVtt(transcriptUrl) {
|
|
4342
|
+
let response;
|
|
4343
|
+
try {
|
|
4344
|
+
response = await fetch(transcriptUrl);
|
|
4345
|
+
} catch (error) {
|
|
4346
|
+
throw muxVideoError("Failed to fetch transcript from Mux", { call: "fetch_transcript", cause: error });
|
|
4347
|
+
}
|
|
4348
|
+
if (!response.ok) {
|
|
4349
|
+
throw muxVideoError(`Failed to fetch transcript from Mux (HTTP ${response.status})`, {
|
|
4350
|
+
call: "fetch_transcript",
|
|
4351
|
+
status: response.status,
|
|
4352
|
+
requestId: requestIdOf(response.headers)
|
|
4353
|
+
});
|
|
4354
|
+
}
|
|
4355
|
+
try {
|
|
4356
|
+
return await response.text();
|
|
4357
|
+
} catch (error) {
|
|
4358
|
+
throw muxVideoError("Failed to read transcript from Mux", { call: "fetch_transcript", cause: error });
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4305
4361
|
async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
4306
|
-
const { required = false, languageCode, cleanTranscript, scope, shouldSign, credentials } = options;
|
|
4362
|
+
const { required = false, languageCode, cleanTranscript, scope, shouldSign, credentials, classifiedErrors } = options;
|
|
4307
4363
|
const track = findCaptionTrack(asset, languageCode);
|
|
4308
4364
|
if (!track) {
|
|
4309
4365
|
if (required) {
|
|
4310
|
-
const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter(
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4366
|
+
const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter((code) => !!code);
|
|
4367
|
+
const message = `No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages.join(", ") || "none"}.`;
|
|
4368
|
+
if (classifiedErrors) {
|
|
4369
|
+
throw new MuxAiError(message, {
|
|
4370
|
+
code: MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND,
|
|
4371
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
4372
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
4373
|
+
facts: { assetId: asset.id, ...languageCode && { languageCode }, availableLanguages }
|
|
4374
|
+
});
|
|
4375
|
+
}
|
|
4376
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
4315
4377
|
}
|
|
4316
4378
|
return { transcriptText: "" };
|
|
4317
4379
|
}
|
|
4318
4380
|
if (!track.id) {
|
|
4319
4381
|
if (required) {
|
|
4382
|
+
if (classifiedErrors) {
|
|
4383
|
+
throw new MuxAiError("Transcript track is missing an id.", {
|
|
4384
|
+
code: MUX_AI_ERROR_CODES.CAPTION_TRACK_ID_MISSING,
|
|
4385
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
4386
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
4387
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
4388
|
+
facts: { assetId: asset.id, ...track.language_code && { languageCode: track.language_code } }
|
|
4389
|
+
});
|
|
4390
|
+
}
|
|
4320
4391
|
throw new LegacyMuxAiError("Transcript track is missing an id.", { type: "validation_error" });
|
|
4321
4392
|
}
|
|
4322
4393
|
return { transcriptText: "", track };
|
|
@@ -4324,7 +4395,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
4324
4395
|
const transcriptUrl = await buildTranscriptUrl(playbackId, track.id, shouldSign, credentials);
|
|
4325
4396
|
let result;
|
|
4326
4397
|
try {
|
|
4327
|
-
result = await fetchTranscriptDataForUrl(transcriptUrl, { cleanTranscript, scope });
|
|
4398
|
+
result = await fetchTranscriptDataForUrl(transcriptUrl, { cleanTranscript, scope, classifiedErrors });
|
|
4328
4399
|
} catch (error) {
|
|
4329
4400
|
if (required) {
|
|
4330
4401
|
throw error;
|
|
@@ -4337,8 +4408,23 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
4337
4408
|
}
|
|
4338
4409
|
switch (result.emptyReason) {
|
|
4339
4410
|
case "no_scoped_cues":
|
|
4411
|
+
if (classifiedErrors) {
|
|
4412
|
+
throw invalidScopeError(
|
|
4413
|
+
"Transcript has no cues in the requested scope.",
|
|
4414
|
+
{ reason: "no_transcript", trackId: track.id, ...scope?.startTime !== void 0 && { startTime: scope.startTime }, ...scope?.endTime !== void 0 && { endTime: scope.endTime } },
|
|
4415
|
+
["scope"]
|
|
4416
|
+
);
|
|
4417
|
+
}
|
|
4340
4418
|
throw new LegacyMuxAiError("Transcript has no cues in the requested scope.", { type: "validation_error" });
|
|
4341
4419
|
case "empty_body":
|
|
4420
|
+
if (classifiedErrors) {
|
|
4421
|
+
throw new MuxAiError("Transcript is empty.", {
|
|
4422
|
+
code: MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY,
|
|
4423
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
4424
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
4425
|
+
facts: { assetId: asset.id, trackId: track.id }
|
|
4426
|
+
});
|
|
4427
|
+
}
|
|
4342
4428
|
throw new LegacyMuxAiError("Transcript is empty.", { type: "validation_error" });
|
|
4343
4429
|
}
|
|
4344
4430
|
}
|
|
@@ -6395,6 +6481,7 @@ async function generateChaptersWithAI({
|
|
|
6395
6481
|
}) {
|
|
6396
6482
|
"use step";
|
|
6397
6483
|
const model = await createLanguageModelFromConfig(provider, modelId, credentials);
|
|
6484
|
+
const context = { call: "generate_chapters", provider, model: modelId };
|
|
6398
6485
|
const response = await withContentPolicyAwareRetry(() => generateText4({
|
|
6399
6486
|
model,
|
|
6400
6487
|
maxRetries: 0,
|
|
@@ -6406,8 +6493,10 @@ async function generateChaptersWithAI({
|
|
|
6406
6493
|
content: userPrompt
|
|
6407
6494
|
}
|
|
6408
6495
|
]
|
|
6409
|
-
}))
|
|
6410
|
-
|
|
6496
|
+
}), void 0, context).catch((error) => {
|
|
6497
|
+
throw modelStepError(error, "Chapter generation model call failed", { ...context });
|
|
6498
|
+
});
|
|
6499
|
+
const output = getGeneratedOutputWithContentPolicyHandling(response, context);
|
|
6411
6500
|
const unexpectedRootKeys = detectUnexpectedKeysFromRawText(
|
|
6412
6501
|
response.text,
|
|
6413
6502
|
chaptersSchema.keyof().options
|
|
@@ -6622,48 +6711,46 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
6622
6711
|
model,
|
|
6623
6712
|
provider
|
|
6624
6713
|
});
|
|
6625
|
-
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
|
|
6714
|
+
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot, { classifiedErrors: true });
|
|
6626
6715
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
|
|
6627
6716
|
const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
|
|
6628
|
-
const resolvedScope = effectiveScope ? resolveWorkflowScope(effectiveScope, assetDurationSeconds) : void 0;
|
|
6717
|
+
const resolvedScope = effectiveScope ? resolveWorkflowScope(effectiveScope, assetDurationSeconds, { classifiedErrors: true, assetId }) : void 0;
|
|
6629
6718
|
const isAudioOnly = isAudioOnlyAsset(assetData);
|
|
6630
6719
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
6631
6720
|
if (policy === "signed" && !signingContext) {
|
|
6632
|
-
throw
|
|
6633
|
-
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
6634
|
-
{ type: "validation_error" }
|
|
6635
|
-
);
|
|
6721
|
+
throw signingCredentialsMissingError();
|
|
6636
6722
|
}
|
|
6637
|
-
const readyTextTracks = getReadyTextTracks(assetData);
|
|
6638
6723
|
const transcriptResult = await fetchTranscriptForAsset(assetData, playbackId, {
|
|
6639
6724
|
languageCode,
|
|
6640
6725
|
cleanTranscript: false,
|
|
6641
6726
|
// keep timestamps for chapter segmentation
|
|
6642
6727
|
shouldSign: policy === "signed",
|
|
6643
6728
|
credentials,
|
|
6644
|
-
scope: effectiveScope
|
|
6729
|
+
scope: effectiveScope,
|
|
6730
|
+
required: true,
|
|
6731
|
+
classifiedErrors: true
|
|
6645
6732
|
});
|
|
6646
|
-
|
|
6647
|
-
const availableLanguages = readyTextTracks.map((t) => t.language_code).filter(Boolean).join(", ");
|
|
6648
|
-
throw new LegacyMuxAiError(
|
|
6649
|
-
`No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages || "none"}.`,
|
|
6650
|
-
{ type: "validation_error" }
|
|
6651
|
-
);
|
|
6652
|
-
}
|
|
6733
|
+
const transcriptTrack = transcriptResult.track;
|
|
6653
6734
|
const timestampedTranscript = extractTimestampedTranscript(transcriptResult.transcriptText);
|
|
6654
6735
|
if (!timestampedTranscript) {
|
|
6655
6736
|
const contentLabel = isAudioOnly ? "transcript" : "caption track";
|
|
6656
|
-
throw new
|
|
6737
|
+
throw new MuxAiError(`No usable content found in ${contentLabel}.`, {
|
|
6738
|
+
code: MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY,
|
|
6739
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
6740
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
6741
|
+
facts: { assetId, ...transcriptTrack.id && { trackId: transcriptTrack.id } }
|
|
6742
|
+
});
|
|
6657
6743
|
}
|
|
6658
|
-
const resolvedLanguageCode = outputLanguageCode && outputLanguageCode !== "auto" ? outputLanguageCode : getReliableLanguageCode(
|
|
6744
|
+
const resolvedLanguageCode = outputLanguageCode && outputLanguageCode !== "auto" ? outputLanguageCode : getReliableLanguageCode(transcriptTrack) ?? languageCode;
|
|
6659
6745
|
const languageName = resolvedLanguageCode ? getLanguageName(resolvedLanguageCode) : void 0;
|
|
6660
6746
|
const sceneBoundarySeconds = getSceneBoundarySeconds(sceneContext).filter(
|
|
6661
6747
|
(boundary) => resolvedScope ? boundary >= resolvedScope.startTime && boundary < resolvedScope.endTime : true
|
|
6662
6748
|
);
|
|
6663
6749
|
if (sceneContext?.length && sceneBoundarySeconds.length === 0) {
|
|
6664
|
-
throw
|
|
6750
|
+
throw invalidScopeError(
|
|
6665
6751
|
"Scene context has no chapter boundaries within the requested scope.",
|
|
6666
|
-
{
|
|
6752
|
+
{ reason: "no_scenes", ...resolvedScope && { startTime: resolvedScope.startTime, endTime: resolvedScope.endTime } },
|
|
6753
|
+
["scope", "sceneContext"]
|
|
6667
6754
|
);
|
|
6668
6755
|
}
|
|
6669
6756
|
const userPrompt = buildUserPrompt3({
|
|
@@ -6675,29 +6762,20 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
6675
6762
|
languageName,
|
|
6676
6763
|
scope: resolvedScope
|
|
6677
6764
|
});
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
} catch (error) {
|
|
6693
|
-
legacyWrapError(error, `Failed to generate chapters with ${provider}`);
|
|
6694
|
-
}
|
|
6695
|
-
if (chaptersData) {
|
|
6696
|
-
collectedUsage.push(chaptersData.usage);
|
|
6697
|
-
}
|
|
6698
|
-
if (!chaptersData || !chaptersData.chapters) {
|
|
6699
|
-
throw new LegacyMuxAiError(`Failed to generate chapters for asset ${assetId}.`);
|
|
6700
|
-
}
|
|
6765
|
+
const modelFacts = { call: "generate_chapters", provider: modelConfig.provider, model: modelConfig.modelId, assetId };
|
|
6766
|
+
const systemPromptOverrides = {
|
|
6767
|
+
...isAudioOnly ? AUDIO_ONLY_SYSTEM_PROMPT_OVERRIDES : {},
|
|
6768
|
+
...sceneContext?.length ? SCENE_CONTEXT_SYSTEM_PROMPT_OVERRIDES : {}
|
|
6769
|
+
};
|
|
6770
|
+
const systemPrompt = chapterSystemPromptBuilder.build(systemPromptOverrides);
|
|
6771
|
+
const chaptersData = await generateChaptersWithAI({
|
|
6772
|
+
provider: modelConfig.provider,
|
|
6773
|
+
modelId: modelConfig.modelId,
|
|
6774
|
+
userPrompt,
|
|
6775
|
+
systemPrompt,
|
|
6776
|
+
credentials
|
|
6777
|
+
}).catch((error) => wrapError(error, `Failed to generate chapters with ${modelConfig.provider}`, modelFacts));
|
|
6778
|
+
collectedUsage.push(chaptersData.usage);
|
|
6701
6779
|
const { chapters: chaptersPayload, usage } = chaptersData;
|
|
6702
6780
|
const scopedChapters = chaptersPayload.chapters.filter((chapter) => typeof chapter.startTime === "number" && typeof chapter.title === "string").filter(
|
|
6703
6781
|
(chapter) => resolvedScope ? chapter.startTime >= resolvedScope.startTime && chapter.startTime < resolvedScope.endTime : true
|
|
@@ -6707,7 +6785,13 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
6707
6785
|
sceneBoundarySeconds
|
|
6708
6786
|
);
|
|
6709
6787
|
if (validChapters.length === 0) {
|
|
6710
|
-
throw new
|
|
6788
|
+
throw new MuxAiError(`Failed to generate valid chapters for asset ${assetId}.`, {
|
|
6789
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
6790
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
6791
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
6792
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
6793
|
+
facts: { ...modelFacts, returnedChapterCount: chaptersPayload.chapters.length, ...resolvedScope && { scopeStartTime: resolvedScope.startTime, scopeEndTime: resolvedScope.endTime } }
|
|
6794
|
+
});
|
|
6711
6795
|
}
|
|
6712
6796
|
const safety = createSafetyReporter();
|
|
6713
6797
|
for (const key of chaptersData.unexpectedRootKeys) {
|
|
@@ -6729,7 +6813,13 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
6729
6813
|
return !scrub.leaked;
|
|
6730
6814
|
});
|
|
6731
6815
|
if (scrubbedChapters.length === 0) {
|
|
6732
|
-
throw new
|
|
6816
|
+
throw new MuxAiError(`Failed to generate valid chapters for asset ${assetId}: every chapter title was withheld by the output safety filter.`, {
|
|
6817
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_SUPPRESSED,
|
|
6818
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
6819
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
6820
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
6821
|
+
facts: { ...modelFacts, suppressedChapterCount: validChapters.length }
|
|
6822
|
+
});
|
|
6733
6823
|
}
|
|
6734
6824
|
if (sceneBoundarySeconds.length === 0) {
|
|
6735
6825
|
const firstChapterStartTime = resolvedScope?.startTime ?? 0;
|
|
@@ -6746,7 +6836,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
6746
6836
|
};
|
|
6747
6837
|
return {
|
|
6748
6838
|
assetId,
|
|
6749
|
-
languageCode: languageCode ?? getReliableLanguageCode(
|
|
6839
|
+
languageCode: languageCode ?? getReliableLanguageCode(transcriptTrack) ?? "en",
|
|
6750
6840
|
chapters: scrubbedChapters,
|
|
6751
6841
|
usage: usageWithMetadata,
|
|
6752
6842
|
safety: safety.report()
|