@mux/ai 0.7.3 → 0.7.5

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, b as Hotspot, c as HotspotOptions, d as HotspotResponse, T as ThumbnailOptions, e as TranscriptFetchOptions, f as TranscriptResult, V as VTTCue, g as buildTranscriptUrl, h as chunkByTokens, j as chunkText, k as chunkVTTCues, l as estimateTokenCount, m as extractTextFromVTT, n as extractTimestampedTranscript, o as fetchTranscriptForAsset, p as findCaptionTrack, q as getHeatmapForAsset, r as getHeatmapForPlaybackId, s as getHeatmapForVideo, t as getHotspotsForAsset, u as getHotspotsForPlaybackId, v as getHotspotsForVideo, w as getReadyTextTracks, x as getStoryboardUrl, y as getThumbnailUrls, z as parseVTTCues, A as secondsToTimestamp, B as vttTimestampToSeconds } from '../index-DZlygsvb.js';
2
- import '../types-BQVi_wnh.js';
1
+ export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, b as Hotspot, c as HotspotOptions, d as HotspotResponse, T as ThumbnailOptions, e as TranscriptFetchOptions, f as TranscriptResult, V as VTTCue, g as buildTranscriptUrl, h as chunkByTokens, j as chunkText, k as chunkVTTCues, l as estimateTokenCount, m as extractTextFromVTT, n as extractTimestampedTranscript, o as fetchTranscriptForAsset, p as findCaptionTrack, q as getHeatmapForAsset, r as getHeatmapForPlaybackId, s as getHeatmapForVideo, t as getHotspotsForAsset, u as getHotspotsForPlaybackId, v as getHotspotsForVideo, w as getReadyTextTracks, x as getStoryboardUrl, y as getThumbnailUrls, z as parseVTTCues, A as secondsToTimestamp, B as vttTimestampToSeconds } from '../index-Nxf6BaBO.js';
2
+ import '../types-BRbaGW3t.js';
3
3
  import '@mux/mux-node';
@@ -44,6 +44,9 @@ var EnvSchema = z.object({
44
44
  ),
45
45
  MUX_TEST_ASSET_ID_AUDIO_ONLY: optionalString("Mux test asset ID for audio-only assets.", "Mux test asset id for audio-only assets for testing"),
46
46
  MUX_TEST_ASSET_ID_VIOLENT_AUDIO_ONLY: optionalString("Mux test asset ID for audio-only assets with violent content.", "Mux test asset id for audio-only assets with violent content for testing"),
47
+ // Eval config
48
+ MUX_AI_EVAL_MODEL_SET: optionalString("Eval model selection mode.", "Choose between 'default' (provider defaults only) or 'all' (all configured models)"),
49
+ MUX_AI_EVAL_MODELS: optionalString("Comma-separated eval model pairs.", "Comma-separated provider:model pairs (e.g. 'openai:gpt-5.1,anthropic:claude-sonnet-4-5,google:gemini-3-flash-preview')"),
47
50
  // AI Providers
48
51
  OPENAI_API_KEY: optionalString("OpenAI API key for OpenAI-backed workflows.", "OpenAI API key"),
49
52
  ANTHROPIC_API_KEY: optionalString("Anthropic API key for Claude-backed workflows.", "Anthropic API key"),
@@ -309,12 +312,13 @@ function readString(record, key) {
309
312
  function resolveDirectMuxCredentials(record) {
310
313
  const tokenId = readString(record, "muxTokenId");
311
314
  const tokenSecret = readString(record, "muxTokenSecret");
315
+ const authorizationToken = readString(record, "muxAuthorizationToken");
312
316
  const signingKey = readString(record, "muxSigningKey");
313
317
  const privateKey = readString(record, "muxPrivateKey");
314
- if (!tokenId && !tokenSecret && !signingKey && !privateKey) {
318
+ if (!tokenId && !tokenSecret && !authorizationToken && !signingKey && !privateKey) {
315
319
  return void 0;
316
320
  }
317
- if (!tokenId || !tokenSecret) {
321
+ if ((!tokenId || !tokenSecret) && !authorizationToken) {
318
322
  throw new Error(
319
323
  "Both muxTokenId and muxTokenSecret are required when passing direct Mux workflow credentials."
320
324
  );
@@ -322,6 +326,7 @@ function resolveDirectMuxCredentials(record) {
322
326
  return {
323
327
  tokenId,
324
328
  tokenSecret,
329
+ authorizationToken,
325
330
  signingKey,
326
331
  privateKey
327
332
  };
@@ -332,7 +337,8 @@ function createWorkflowMuxClient(options) {
332
337
  const { default: MuxClient } = await import("@mux/mux-node");
333
338
  return new MuxClient({
334
339
  tokenId: options.tokenId,
335
- tokenSecret: options.tokenSecret
340
+ tokenSecret: options.tokenSecret,
341
+ authorizationToken: options.authorizationToken
336
342
  });
337
343
  },
338
344
  getSigningKey() {
@@ -375,6 +381,88 @@ async function resolveMuxSigningContext(credentials) {
375
381
  return { keyId, keySecret };
376
382
  }
377
383
 
384
+ // src/lib/providers.ts
385
+ var DEFAULT_LANGUAGE_MODELS = {
386
+ openai: "gpt-5.1",
387
+ anthropic: "claude-sonnet-4-5",
388
+ google: "gemini-3-flash-preview"
389
+ };
390
+ var LANGUAGE_MODELS = {
391
+ openai: ["gpt-5.1", "gpt-5-mini"],
392
+ anthropic: ["claude-sonnet-4-5"],
393
+ google: ["gemini-3-flash-preview", "gemini-2.5-flash"]
394
+ };
395
+ function getDefaultEvalModelConfigs() {
396
+ return Object.entries(DEFAULT_LANGUAGE_MODELS).map(([provider, modelId]) => ({ provider, modelId }));
397
+ }
398
+ function getAllEvalModelConfigs() {
399
+ return Object.entries(LANGUAGE_MODELS).flatMap(([provider, models]) => models.map((modelId) => ({ provider, modelId })));
400
+ }
401
+ function isSupportedProvider(value) {
402
+ return value === "openai" || value === "anthropic" || value === "google";
403
+ }
404
+ function parseEvalModelPair(value) {
405
+ const trimmed = value.trim();
406
+ const [providerRaw, modelIdRaw] = trimmed.split(":", 2);
407
+ const provider = providerRaw?.trim();
408
+ const modelId = modelIdRaw?.trim();
409
+ if (!provider || !modelId) {
410
+ throw new Error(
411
+ `Invalid eval model pair "${value}". Use "provider:model" (example: "openai:gpt-5.1").`
412
+ );
413
+ }
414
+ if (!isSupportedProvider(provider)) {
415
+ throw new Error(
416
+ `Unsupported eval provider "${provider}" in "${value}". Supported providers: ${Object.keys(LANGUAGE_MODELS).join(", ")}.`
417
+ );
418
+ }
419
+ const supportedModels = LANGUAGE_MODELS[provider];
420
+ if (!supportedModels.includes(modelId)) {
421
+ throw new Error(
422
+ `Unsupported eval model "${modelId}" for provider "${provider}". Supported models: ${supportedModels.join(", ")}.`
423
+ );
424
+ }
425
+ return {
426
+ provider,
427
+ modelId
428
+ };
429
+ }
430
+ function resolveEvalModelConfigs(options = {}) {
431
+ const explicitPairs = options.modelPairs?.map((value) => value.trim()).filter(Boolean) ?? [];
432
+ if (explicitPairs.length > 0) {
433
+ const dedupedPairs = Array.from(new Set(explicitPairs));
434
+ return dedupedPairs.map(parseEvalModelPair);
435
+ }
436
+ const selection = options.selection ?? "default";
437
+ if (selection === "all") {
438
+ return getAllEvalModelConfigs();
439
+ }
440
+ return getDefaultEvalModelConfigs();
441
+ }
442
+ function resolveEvalModelConfigsFromEnv(environment = env_default) {
443
+ const rawSelection = environment.MUX_AI_EVAL_MODEL_SET?.trim();
444
+ const rawModelPairs = environment.MUX_AI_EVAL_MODELS?.trim();
445
+ let selection;
446
+ if (!rawSelection || rawSelection === "default") {
447
+ selection = "default";
448
+ } else if (rawSelection === "all") {
449
+ selection = "all";
450
+ } else {
451
+ throw new Error(
452
+ `Invalid MUX_AI_EVAL_MODEL_SET="${rawSelection}". Expected "default" or "all".`
453
+ );
454
+ }
455
+ let modelPairs;
456
+ if (rawModelPairs) {
457
+ modelPairs = rawModelPairs.split(",").map((value) => value.trim()).filter(Boolean);
458
+ }
459
+ return resolveEvalModelConfigs({
460
+ selection,
461
+ modelPairs
462
+ });
463
+ }
464
+ var EVAL_MODEL_CONFIGS = resolveEvalModelConfigsFromEnv();
465
+
378
466
  // src/lib/client-factory.ts
379
467
  async function getMuxClientFromEnv(credentials) {
380
468
  return resolveMuxClient(credentials);
@@ -487,9 +575,9 @@ async function signPlaybackId(playbackId, context, type = "video", params) {
487
575
  params: stringParams
488
576
  });
489
577
  }
490
- async function signUrl(url, playbackId, context, type = "video", params, credentials) {
578
+ async function signUrl(url, playbackId, type = "video", params, credentials) {
491
579
  "use step";
492
- const resolvedContext = context ?? await resolveMuxSigningContext(credentials);
580
+ const resolvedContext = await resolveMuxSigningContext(credentials);
493
581
  if (!resolvedContext) {
494
582
  throw new Error(
495
583
  "Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables."
@@ -506,7 +594,7 @@ async function getStoryboardUrl(playbackId, width = DEFAULT_STORYBOARD_WIDTH, sh
506
594
  "use step";
507
595
  const baseUrl = `https://image.mux.com/${playbackId}/storyboard.png`;
508
596
  if (shouldSign) {
509
- return signUrl(baseUrl, playbackId, void 0, "storyboard", { width }, credentials);
597
+ return signUrl(baseUrl, playbackId, "storyboard", { width }, credentials);
510
598
  }
511
599
  return `${baseUrl}?width=${width}`;
512
600
  }
@@ -626,7 +714,7 @@ async function getThumbnailUrls(playbackId, duration, options = {}) {
626
714
  const baseUrl = `https://image.mux.com/${playbackId}/thumbnail.png`;
627
715
  const urlPromises = timestamps.map(async (time) => {
628
716
  if (shouldSign) {
629
- return signUrl(baseUrl, playbackId, void 0, "thumbnail", { time, width }, credentials);
717
+ return signUrl(baseUrl, playbackId, "thumbnail", { time, width }, credentials);
630
718
  }
631
719
  return `${baseUrl}?time=${time}&width=${width}`;
632
720
  });
@@ -755,7 +843,7 @@ async function buildTranscriptUrl(playbackId, trackId, shouldSign = false, crede
755
843
  "use step";
756
844
  const baseUrl = `https://stream.mux.com/${playbackId}/text/${trackId}.vtt`;
757
845
  if (shouldSign) {
758
- return signUrl(baseUrl, playbackId, void 0, "video", void 0, credentials);
846
+ return signUrl(baseUrl, playbackId, "video", void 0, credentials);
759
847
  }
760
848
  return baseUrl;
761
849
  }