@mux/ai 0.45.0 → 0.46.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.
@@ -1,3 +1,3 @@
1
- export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, L as LOW_CONFIDENCE_THRESHOLD, M as MAX_CUE_TEXT_CHARS, T as ThumbnailOptions, b as TranscriptFetchOptions, c as TranscriptResult, V as VTTCue, d as VTTCueBudgetChunkingOptions, e as VTTDurationChunk, f as VTTDurationChunkingOptions, g as buildTranscriptUrl, h as buildVttFromCueBlocks, j as buildVttFromTranslatedCueBlocks, k as chunkByTokens, l as chunkText, m as chunkVTTCues, n as chunkVTTCuesByBudget, o as chunkVTTCuesByDuration, p as concatenateVttSegments, q as estimateTokenCount, r as extractTextFromVTT, s as extractTimestampedTranscript, t as fetchTranscriptForAsset, u as filterVttByScope, v as findCaptionTrack, w as getHeatmapForAsset, x as getHeatmapForPlaybackId, y as getHeatmapForVideo, z as getReadyTextTracks, A as getReliableLanguageCode, B as getStoryboardUrl, C as getThumbnailUrls, E as parseVTTCues, F as replaceCueText, G as sanitizeUntrustedText, I as secondsToTimestamp, J as splitVttPreambleAndCueBlocks, K as stripVttMetadataBlocks, N as vttTimestampToSeconds } from '../index-D6VGaoPm.js';
2
- export { q as CompletedShotsResult, r as ErroredShotsResult, H as Hotspot, s as HotspotOptions, t as HotspotResponse, u as PendingShotsResult, v as Shot, w as ShotRequestOptions, x as ShotsResult, y as WaitForShotsOptions, z as getHotspotsForAsset, B as getHotspotsForPlaybackId, D as getHotspotsForVideo, F as getShotsForAsset, G as requestShotsForAsset, J as waitForShotsForAsset } from '../shots-B7G0IIF1.js';
3
- import '@mux/mux-node';
1
+ export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, L as LOW_CONFIDENCE_THRESHOLD, M as MAX_CUE_TEXT_CHARS, T as ThumbnailOptions, b as TranscriptFetchOptions, c as TranscriptResult, V as VTTCue, d as VTTCueBudgetChunkingOptions, e as VTTDurationChunk, f as VTTDurationChunkingOptions, g as buildTranscriptUrl, h as buildVttFromCueBlocks, j as buildVttFromTranslatedCueBlocks, k as chunkByTokens, l as chunkText, m as chunkVTTCues, n as chunkVTTCuesByBudget, o as chunkVTTCuesByDuration, p as concatenateVttSegments, q as estimateTokenCount, r as extractTextFromVTT, s as extractTimestampedTranscript, t as fetchTranscriptForAsset, u as filterVttByScope, v as findCaptionTrack, w as getHeatmapForAsset, x as getHeatmapForPlaybackId, y as getHeatmapForVideo, z as getReadyTextTracks, A as getReliableLanguageCode, B as getStoryboardUrl, C as getThumbnailUrls, E as parseVTTCues, F as replaceCueText, G as sanitizeUntrustedText, I as secondsToTimestamp, J as splitVttPreambleAndCueBlocks, K as stripVttMetadataBlocks, N as vttTimestampToSeconds } from '../index-DAuzEXly.js';
2
+ export { q as CompletedShotsResult, r as ErroredShotsResult, H as Hotspot, s as HotspotOptions, t as HotspotResponse, u as PendingShotsResult, v as Shot, w as ShotRequestOptions, x as ShotsResult, y as WaitForShotsOptions, z as getHotspotsForAsset, B as getHotspotsForPlaybackId, D as getHotspotsForVideo, F as getShotsForAsset, G as requestShotsForAsset, J as waitForShotsForAsset } from '../shots-BwpjZDpr.js';
3
+ import '@mux/ts';
@@ -415,7 +415,7 @@ function resolveDirectMuxCredentials(record) {
415
415
  function createWorkflowMuxClient(options) {
416
416
  return {
417
417
  async createClient() {
418
- const { default: MuxClient } = await import("@mux/mux-node");
418
+ const { default: MuxClient } = await import("@mux/ts");
419
419
  return new MuxClient({
420
420
  tokenId: options.tokenId,
421
421
  tokenSecret: options.tokenSecret,
@@ -621,25 +621,22 @@ async function getHeatmapForPlaybackId(playbackId, options = {}) {
621
621
  "use step";
622
622
  return fetchHeatmap("playback-ids", playbackId, options);
623
623
  }
624
- function transformHeatmapResponse(response) {
625
- return {
626
- assetId: response.data.asset_id,
627
- videoId: response.data.video_id,
628
- playbackId: response.data.playback_id,
629
- heatmap: response.data.heatmap,
630
- timeframe: response.timeframe
631
- };
632
- }
633
624
  async function fetchHeatmap(identifierType, id, options) {
634
625
  "use step";
635
626
  const { timeframe = "7:days", credentials } = options;
636
627
  const muxClient = await getMuxClientFromEnv(credentials);
637
628
  const mux = await muxClient.createClient();
638
- const queryParams = new URLSearchParams();
639
- queryParams.append("timeframe[]", timeframe);
640
- const path = `/data/v1/engagement/${identifierType}/${id}/heatmap?${queryParams.toString()}`;
641
- const response = await mux.get(path);
642
- return transformHeatmapResponse(response);
629
+ const query = { timeframe: [timeframe] };
630
+ const resource = identifierType === "playback-ids" ? mux.data.engagement.playbackIds : mux.data.engagement[identifierType];
631
+ const response = await resource.heatmap(id, query);
632
+ const { data } = response;
633
+ return {
634
+ assetId: data.asset_id ?? (identifierType === "assets" ? id : void 0),
635
+ videoId: data.video_id ?? (identifierType === "videos" ? id : void 0),
636
+ playbackId: data.playback_id ?? (identifierType === "playback-ids" ? id : void 0),
637
+ heatmap: data.heatmap,
638
+ timeframe: response.timeframe
639
+ };
643
640
  }
644
641
 
645
642
  // src/primitives/hotspots.ts
@@ -658,37 +655,34 @@ async function getHotspotsForPlaybackId(playbackId, options = {}) {
658
655
  const response = await fetchHotspots("playback-ids", playbackId, options);
659
656
  return response.hotspots;
660
657
  }
661
- function transformHotspotResponse(response) {
662
- return {
663
- assetId: response.data.asset_id,
664
- videoId: response.data.video_id,
665
- playbackId: response.data.playback_id,
666
- hotspots: response.data.hotspots.map((h) => ({
667
- startMs: h.start_ms,
668
- endMs: h.end_ms,
669
- score: h.score
670
- }))
671
- };
672
- }
673
658
  async function fetchHotspots(identifierType, id, options) {
674
659
  "use step";
675
660
  const {
676
661
  limit = 5,
677
662
  orderDirection = "desc",
678
- orderBy = "score",
679
663
  timeframe = "7:days",
680
664
  credentials
681
665
  } = options;
682
666
  const muxClient = await getMuxClientFromEnv(credentials);
683
667
  const mux = await muxClient.createClient();
684
- const queryParams = new URLSearchParams();
685
- queryParams.append("limit", String(limit));
686
- queryParams.append("order_direction", orderDirection);
687
- queryParams.append("order_by", orderBy);
688
- queryParams.append("timeframe[]", timeframe);
689
- const path = `/data/v1/engagement/${identifierType}/${id}/hotspots?${queryParams.toString()}`;
690
- const response = await mux.get(path);
691
- return transformHotspotResponse(response);
668
+ const query = {
669
+ limit,
670
+ order_direction: orderDirection,
671
+ timeframe: [timeframe]
672
+ };
673
+ const resource = identifierType === "playback-ids" ? mux.data.engagement.playbackIds : mux.data.engagement[identifierType];
674
+ const response = await resource.hotspots(id, query);
675
+ const { data } = response;
676
+ return {
677
+ assetId: data.asset_id ?? (identifierType === "assets" ? id : void 0),
678
+ videoId: data.video_id ?? (identifierType === "videos" ? id : void 0),
679
+ playbackId: data.playback_id ?? (identifierType === "playback-ids" ? id : void 0),
680
+ hotspots: data.hotspots.map((h) => ({
681
+ startMs: h.start_ms,
682
+ endMs: h.end_ms,
683
+ score: h.score
684
+ }))
685
+ };
692
686
  }
693
687
 
694
688
  // src/lib/prompt-fragments.ts
@@ -975,9 +969,6 @@ var DEFAULT_POLL_INTERVAL_MS = 2e3;
975
969
  var MIN_POLL_INTERVAL_MS = 1e3;
976
970
  var DEFAULT_MAX_ATTEMPTS = 60;
977
971
  var SHOTS_ALREADY_REQUESTED_MESSAGE = "shots generation has already been requested";
978
- function getShotsPath(assetId) {
979
- return `/video/v1/assets/${assetId}/shots`;
980
- }
981
972
  function mapManifestShots(shots) {
982
973
  let usedDeprecatedField = false;
983
974
  const mapped = shots.map((shot, index) => {
@@ -1017,29 +1008,35 @@ async function fetchShotsFromManifest(shotsManifestUrl) {
1017
1008
  }
1018
1009
  return mapManifestShots(manifest.shots);
1019
1010
  }
1020
- async function transformShotsResponse(response) {
1021
- switch (response.data.status) {
1011
+ async function transformShotsResponse(data) {
1012
+ switch (data.status) {
1022
1013
  case "pending":
1023
1014
  return {
1024
1015
  status: "pending",
1025
- createdAt: response.data.created_at
1016
+ createdAt: data.created_at
1026
1017
  };
1027
- case "errored":
1018
+ case "errored": {
1019
+ const details = data.errors ?? data.error;
1028
1020
  return {
1029
1021
  status: "errored",
1030
- createdAt: response.data.created_at,
1031
- error: response.data.error
1022
+ createdAt: data.created_at,
1023
+ error: {
1024
+ type: details?.type ?? "unknown",
1025
+ messages: details?.messages ?? []
1026
+ }
1032
1027
  };
1028
+ }
1033
1029
  case "completed":
1030
+ if (!data.shots_manifest_url) {
1031
+ throw new Error("Completed shots response is missing shots_manifest_url");
1032
+ }
1034
1033
  return {
1035
1034
  status: "completed",
1036
- createdAt: response.data.created_at,
1037
- shots: await fetchShotsFromManifest(response.data.shots_manifest_url)
1035
+ createdAt: data.created_at,
1036
+ shots: await fetchShotsFromManifest(data.shots_manifest_url)
1038
1037
  };
1039
- default: {
1040
- const exhaustiveCheck = response.data;
1041
- throw new Error(`Unsupported shots response: ${JSON.stringify(exhaustiveCheck)}`);
1042
- }
1038
+ default:
1039
+ throw new Error(`Unsupported shots status '${data.status}'`);
1043
1040
  }
1044
1041
  }
1045
1042
  function sleep(ms) {
@@ -1047,7 +1044,8 @@ function sleep(ms) {
1047
1044
  }
1048
1045
  function isShotsAlreadyRequestedError(error) {
1049
1046
  const statusCode = error?.status ?? error?.statusCode;
1050
- const messages = error?.error?.messages;
1047
+ const body = error?.error;
1048
+ const messages = body?.error?.messages ?? body?.messages;
1051
1049
  const lowerCaseMessages = messages?.map((message) => message.toLowerCase()) ?? [];
1052
1050
  const errorMessage = error instanceof Error ? error.message.toLowerCase() : "";
1053
1051
  return statusCode === 400 && (lowerCaseMessages.some((message) => message.includes(SHOTS_ALREADY_REQUESTED_MESSAGE)) || errorMessage.includes(SHOTS_ALREADY_REQUESTED_MESSAGE));
@@ -1057,11 +1055,8 @@ async function requestShotsForAsset(assetId, options = {}) {
1057
1055
  const { credentials } = options;
1058
1056
  const muxClient = await getMuxClientFromEnv(credentials);
1059
1057
  const mux = await muxClient.createClient();
1060
- const response = await mux.post(
1061
- getShotsPath(assetId),
1062
- { body: {} }
1063
- );
1064
- const result = await transformShotsResponse(response);
1058
+ const data = await mux.video.assets.generateShots(assetId, {});
1059
+ const result = await transformShotsResponse(data);
1065
1060
  if (result.status !== "pending") {
1066
1061
  throw new Error(
1067
1062
  `Expected pending status after requesting shots for asset '${assetId}', received '${result.status}'`
@@ -1074,10 +1069,8 @@ async function getShotsForAsset(assetId, options = {}) {
1074
1069
  const { credentials } = options;
1075
1070
  const muxClient = await getMuxClientFromEnv(credentials);
1076
1071
  const mux = await muxClient.createClient();
1077
- const response = await mux.get(
1078
- getShotsPath(assetId)
1079
- );
1080
- return await transformShotsResponse(response);
1072
+ const data = await mux.video.assets.retrieveShots(assetId);
1073
+ return await transformShotsResponse(data);
1081
1074
  }
1082
1075
  async function waitForShotsForAsset(assetId, options = {}) {
1083
1076
  "use step";
@@ -1193,12 +1186,8 @@ async function getMuxThumbnailBaseUrl(playbackId, credentials) {
1193
1186
 
1194
1187
  // src/lib/url-signing.ts
1195
1188
  async function createSigningClient(context) {
1196
- const { default: MuxClient } = await import("@mux/mux-node");
1189
+ const { default: MuxClient } = await import("@mux/ts");
1197
1190
  return new MuxClient({
1198
- // These are not needed for signing, but the SDK requires them
1199
- // Using empty strings as we only need the jwt functionality
1200
- tokenId: env_default.MUX_TOKEN_ID || "",
1201
- tokenSecret: env_default.MUX_TOKEN_SECRET || "",
1202
1191
  jwtSigningKey: context.keyId,
1203
1192
  jwtPrivateKey: context.keySecret
1204
1193
  });