@mux/ai 0.5.0 → 0.5.2

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,4 +1,4 @@
1
- import { b as WorkflowCredentialsInput, A as AssetTextTrack, c as MuxAsset, h as TextChunk, C as ChunkingStrategy } from './types-KcVfWtUl.js';
1
+ import { b as WorkflowCredentialsInput, A as AssetTextTrack, c as MuxAsset, h as TextChunk, C as ChunkingStrategy } from './types-BhVuLeSp.js';
2
2
 
3
3
  declare const DEFAULT_STORYBOARD_WIDTH = 640;
4
4
  /**
@@ -110,6 +110,8 @@ interface ThumbnailOptions {
110
110
  width?: number;
111
111
  /** Flag for whether or not to use signed playback IDs (default: false) */
112
112
  shouldSign?: boolean;
113
+ /** Maximum number of thumbnails to generate. When set, samples are evenly distributed with first and last frames pinned. */
114
+ maxSamples?: number;
113
115
  /** Workflow credentials for signing (optional). */
114
116
  credentials?: WorkflowCredentialsInput;
115
117
  }
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { createAnthropic } from '@ai-sdk/anthropic';
3
3
  import { createGoogleGenerativeAI } from '@ai-sdk/google';
4
4
  import { createOpenAI } from '@ai-sdk/openai';
5
- import { k as TokenUsage, M as MuxAIOptions, I as ImageSubmissionMode, C as ChunkingStrategy, j as VideoEmbeddingsResult, T as ToneType } from './types-KcVfWtUl.js';
5
+ import { k as TokenUsage, M as MuxAIOptions, I as ImageSubmissionMode, C as ChunkingStrategy, j as VideoEmbeddingsResult, T as ToneType } from './types-BhVuLeSp.js';
6
6
 
7
7
  interface ImageDownloadOptions {
8
8
  /** Request timeout in milliseconds (default: 10000) */
@@ -124,11 +124,11 @@ declare const chapterSchema: z.ZodObject<{
124
124
  startTime: z.ZodNumber;
125
125
  title: z.ZodString;
126
126
  }, "strip", z.ZodTypeAny, {
127
- startTime: number;
128
127
  title: string;
129
- }, {
130
128
  startTime: number;
129
+ }, {
131
130
  title: string;
131
+ startTime: number;
132
132
  }>;
133
133
  type Chapter = z.infer<typeof chapterSchema>;
134
134
  declare const chaptersSchema: z.ZodObject<{
@@ -136,21 +136,21 @@ declare const chaptersSchema: z.ZodObject<{
136
136
  startTime: z.ZodNumber;
137
137
  title: z.ZodString;
138
138
  }, "strip", z.ZodTypeAny, {
139
- startTime: number;
140
139
  title: string;
141
- }, {
142
140
  startTime: number;
141
+ }, {
143
142
  title: string;
143
+ startTime: number;
144
144
  }>, "many">;
145
145
  }, "strip", z.ZodTypeAny, {
146
146
  chapters: {
147
- startTime: number;
148
147
  title: string;
148
+ startTime: number;
149
149
  }[];
150
150
  }, {
151
151
  chapters: {
152
- startTime: number;
153
152
  title: string;
153
+ startTime: number;
154
154
  }[];
155
155
  }>;
156
156
  type ChaptersType = z.infer<typeof chaptersSchema>;
@@ -292,6 +292,8 @@ interface ModerationOptions extends MuxAIOptions {
292
292
  thumbnailInterval?: number;
293
293
  /** Width of storyboard thumbnails in pixels (defaults to 640). */
294
294
  thumbnailWidth?: number;
295
+ /** Maximum number of thumbnails to sample (defaults to unlimited). When set, samples are evenly distributed with first and last frames pinned. */
296
+ maxSamples?: number;
295
297
  /** Max concurrent moderation requests (defaults to 5). */
296
298
  maxConcurrent?: number;
297
299
  /** Transport used for thumbnails (defaults to 'url'). */
@@ -318,12 +320,12 @@ declare const summarySchema: z.ZodObject<{
318
320
  description: z.ZodString;
319
321
  }, "strip", z.ZodTypeAny, {
320
322
  title: string;
321
- keywords: string[];
322
323
  description: string;
324
+ keywords: string[];
323
325
  }, {
324
326
  title: string;
325
- keywords: string[];
326
327
  description: string;
328
+ keywords: string[];
327
329
  }>;
328
330
  type SummaryType = z.infer<typeof summarySchema>;
329
331
  /** Structured return payload for `getSummaryAndTags`. */
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { W as WorkflowCredentials } from './types-KcVfWtUl.js';
2
- export { A as AssetTextTrack, i as ChunkEmbedding, C as ChunkingStrategy, E as Encrypted, a as EncryptedPayload, I as ImageSubmissionMode, M as MuxAIOptions, c as MuxAsset, f as PlaybackAsset, P as PlaybackPolicy, h as TextChunk, g as TokenChunkingConfig, k as TokenUsage, T as ToneType, V as VTTChunkingConfig, j as VideoEmbeddingsResult, b as WorkflowCredentialsInput, d as decryptFromWorkflow, e as encryptForWorkflow } from './types-KcVfWtUl.js';
3
- export { i as primitives } from './index-Dmo55n-5.js';
4
- export { i as workflows } from './index-BdpEVCbj.js';
1
+ import { W as WorkflowCredentials } from './types-BhVuLeSp.js';
2
+ export { A as AssetTextTrack, i as ChunkEmbedding, C as ChunkingStrategy, E as Encrypted, a as EncryptedPayload, I as ImageSubmissionMode, M as MuxAIOptions, c as MuxAsset, f as PlaybackAsset, P as PlaybackPolicy, h as TextChunk, g as TokenChunkingConfig, k as TokenUsage, T as ToneType, V as VTTChunkingConfig, j as VideoEmbeddingsResult, b as WorkflowCredentialsInput, d as decryptFromWorkflow, e as encryptForWorkflow } from './types-BhVuLeSp.js';
3
+ export { i as primitives } from './index-2oUwgWsE.js';
4
+ export { i as workflows } from './index-DgCfxP4T.js';
5
5
  import '@mux/mux-node';
6
6
  import 'zod';
7
7
  import '@ai-sdk/anthropic';
8
8
  import '@ai-sdk/google';
9
9
  import '@ai-sdk/openai';
10
10
 
11
- var version = "0.5.0";
11
+ var version = "0.5.2";
12
12
 
13
13
  /**
14
14
  * A function that returns workflow credentials, either synchronously or asynchronously.
package/dist/index.js CHANGED
@@ -28018,7 +28018,7 @@ var init_dist10 = __esm({
28018
28018
  });
28019
28019
 
28020
28020
  // package.json
28021
- var version = "0.5.0";
28021
+ var version = "0.5.2";
28022
28022
 
28023
28023
  // src/env.ts
28024
28024
  import { z } from "zod";
@@ -28534,8 +28534,8 @@ function chunkText(text, strategy) {
28534
28534
  // src/primitives/thumbnails.ts
28535
28535
  async function getThumbnailUrls(playbackId, duration, options = {}) {
28536
28536
  "use step";
28537
- const { interval = 10, width = 640, shouldSign = false, credentials } = options;
28538
- const timestamps = [];
28537
+ const { interval = 10, width = 640, shouldSign = false, maxSamples, credentials } = options;
28538
+ let timestamps = [];
28539
28539
  if (duration <= 50) {
28540
28540
  const spacing = duration / 6;
28541
28541
  for (let i = 1; i <= 5; i++) {
@@ -28546,6 +28546,18 @@ async function getThumbnailUrls(playbackId, duration, options = {}) {
28546
28546
  timestamps.push(time);
28547
28547
  }
28548
28548
  }
28549
+ if (maxSamples !== void 0 && timestamps.length > maxSamples) {
28550
+ const newTimestamps = [];
28551
+ newTimestamps.push(0);
28552
+ if (maxSamples >= 2) {
28553
+ const spacing = duration / (maxSamples - 1);
28554
+ for (let i = 1; i < maxSamples - 1; i++) {
28555
+ newTimestamps.push(spacing * i);
28556
+ }
28557
+ newTimestamps.push(duration);
28558
+ }
28559
+ timestamps = newTimestamps;
28560
+ }
28549
28561
  const baseUrl = `https://image.mux.com/${playbackId}/thumbnail.png`;
28550
28562
  const urlPromises = timestamps.map(async (time) => {
28551
28563
  if (shouldSign) {
@@ -28753,7 +28765,7 @@ __export(workflows_exports, {
28753
28765
  });
28754
28766
 
28755
28767
  // src/workflows/burned-in-captions.ts
28756
- import { generateObject } from "ai";
28768
+ import { generateText, Output } from "ai";
28757
28769
  import dedent from "dedent";
28758
28770
  import { z as z21 } from "zod";
28759
28771
 
@@ -29049,7 +29061,7 @@ function createToneSection(instruction) {
29049
29061
  // src/workflows/burned-in-captions.ts
29050
29062
  var burnedInCaptionsSchema = z21.object({
29051
29063
  hasBurnedInCaptions: z21.boolean(),
29052
- confidence: z21.number().min(0).max(1),
29064
+ confidence: z21.number(),
29053
29065
  detectedLanguage: z21.string().nullable()
29054
29066
  });
29055
29067
  var SYSTEM_PROMPT = dedent`
@@ -29150,9 +29162,9 @@ async function analyzeStoryboard({
29150
29162
  }) {
29151
29163
  "use step";
29152
29164
  const model = await createLanguageModelFromConfig(provider, modelId, credentials);
29153
- const response = await generateObject({
29165
+ const response = await generateText({
29154
29166
  model,
29155
- schema: burnedInCaptionsSchema,
29167
+ output: Output.object({ schema: burnedInCaptionsSchema }),
29156
29168
  experimental_telemetry: { isEnabled: true },
29157
29169
  messages: [
29158
29170
  {
@@ -29169,7 +29181,10 @@ async function analyzeStoryboard({
29169
29181
  ]
29170
29182
  });
29171
29183
  return {
29172
- result: response.object,
29184
+ result: {
29185
+ ...response.output,
29186
+ confidence: Math.min(1, Math.max(0, response.output.confidence))
29187
+ },
29173
29188
  usage: {
29174
29189
  inputTokens: response.usage.inputTokens,
29175
29190
  outputTokens: response.usage.outputTokens,
@@ -29233,7 +29248,7 @@ async function hasBurnedInCaptions(assetId, options = {}) {
29233
29248
  }
29234
29249
 
29235
29250
  // src/workflows/chapters.ts
29236
- import { generateObject as generateObject2 } from "ai";
29251
+ import { generateText as generateText2, Output as Output2 } from "ai";
29237
29252
  import dedent2 from "dedent";
29238
29253
  import { z as z22 } from "zod";
29239
29254
 
@@ -29295,9 +29310,9 @@ async function generateChaptersWithAI({
29295
29310
  "use step";
29296
29311
  const model = await createLanguageModelFromConfig(provider, modelId, credentials);
29297
29312
  const response = await withRetry(
29298
- () => generateObject2({
29313
+ () => generateText2({
29299
29314
  model,
29300
- schema: chaptersSchema,
29315
+ output: Output2.object({ schema: chaptersSchema }),
29301
29316
  messages: [
29302
29317
  {
29303
29318
  role: "system",
@@ -29311,7 +29326,7 @@ async function generateChaptersWithAI({
29311
29326
  })
29312
29327
  );
29313
29328
  return {
29314
- chapters: response.object,
29329
+ chapters: response.output,
29315
29330
  usage: {
29316
29331
  inputTokens: response.usage.inputTokens,
29317
29332
  outputTokens: response.usage.outputTokens,
@@ -29910,6 +29925,7 @@ async function getModerationScores(assetId, options = {}) {
29910
29925
  thresholds = DEFAULT_THRESHOLDS,
29911
29926
  thumbnailInterval = 10,
29912
29927
  thumbnailWidth = 640,
29928
+ maxSamples,
29913
29929
  maxConcurrent = 5,
29914
29930
  imageSubmissionMode = "url",
29915
29931
  imageDownloadOptions,
@@ -29961,6 +29977,7 @@ async function getModerationScores(assetId, options = {}) {
29961
29977
  interval: thumbnailInterval,
29962
29978
  width: thumbnailWidth,
29963
29979
  shouldSign: policy === "signed",
29980
+ maxSamples,
29964
29981
  credentials
29965
29982
  });
29966
29983
  if (provider === "openai") {
@@ -30002,7 +30019,7 @@ async function getModerationScores(assetId, options = {}) {
30002
30019
  }
30003
30020
 
30004
30021
  // src/workflows/summarization.ts
30005
- import { generateObject as generateObject3 } from "ai";
30022
+ import { generateText as generateText3, Output as Output3 } from "ai";
30006
30023
  import dedent3 from "dedent";
30007
30024
  import { z as z23 } from "zod";
30008
30025
  var SUMMARY_KEYWORD_LIMIT = 10;
@@ -30232,9 +30249,9 @@ function buildUserPrompt3({
30232
30249
  async function analyzeStoryboard2(imageDataUrl, provider, modelId, userPrompt, systemPrompt, credentials) {
30233
30250
  "use step";
30234
30251
  const model = await createLanguageModelFromConfig(provider, modelId, credentials);
30235
- const response = await generateObject3({
30252
+ const response = await generateText3({
30236
30253
  model,
30237
- schema: summarySchema,
30254
+ output: Output3.object({ schema: summarySchema }),
30238
30255
  messages: [
30239
30256
  {
30240
30257
  role: "system",
@@ -30250,7 +30267,7 @@ async function analyzeStoryboard2(imageDataUrl, provider, modelId, userPrompt, s
30250
30267
  ]
30251
30268
  });
30252
30269
  return {
30253
- result: response.object,
30270
+ result: response.output,
30254
30271
  usage: {
30255
30272
  inputTokens: response.usage.inputTokens,
30256
30273
  outputTokens: response.usage.outputTokens,
@@ -30263,9 +30280,9 @@ async function analyzeStoryboard2(imageDataUrl, provider, modelId, userPrompt, s
30263
30280
  async function analyzeAudioOnly(provider, modelId, userPrompt, systemPrompt, credentials) {
30264
30281
  "use step";
30265
30282
  const model = await createLanguageModelFromConfig(provider, modelId, credentials);
30266
- const response = await generateObject3({
30283
+ const response = await generateText3({
30267
30284
  model,
30268
- schema: summarySchema,
30285
+ output: Output3.object({ schema: summarySchema }),
30269
30286
  messages: [
30270
30287
  {
30271
30288
  role: "system",
@@ -30278,7 +30295,7 @@ async function analyzeAudioOnly(provider, modelId, userPrompt, systemPrompt, cre
30278
30295
  ]
30279
30296
  });
30280
30297
  return {
30281
- result: response.object,
30298
+ result: response.output,
30282
30299
  usage: {
30283
30300
  inputTokens: response.usage.inputTokens,
30284
30301
  outputTokens: response.usage.outputTokens,
@@ -30321,7 +30338,6 @@ async function getSummaryAndTags(assetId, options) {
30321
30338
  cleanTranscript = true,
30322
30339
  imageSubmissionMode = "url",
30323
30340
  imageDownloadOptions,
30324
- abortSignal: _abortSignal,
30325
30341
  promptOverrides,
30326
30342
  credentials
30327
30343
  } = options ?? {};
@@ -30982,7 +30998,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
30982
30998
 
30983
30999
  // src/workflows/translate-captions.ts
30984
31000
  import Mux4 from "@mux/mux-node";
30985
- import { generateObject as generateObject4 } from "ai";
31001
+ import { generateText as generateText4, Output as Output4 } from "ai";
30986
31002
  import { z as z24 } from "zod";
30987
31003
  var translationSchema = z24.object({
30988
31004
  translation: z24.string()
@@ -31001,15 +31017,13 @@ async function translateVttWithAI({
31001
31017
  toLanguageCode,
31002
31018
  provider,
31003
31019
  modelId,
31004
- abortSignal,
31005
31020
  credentials
31006
31021
  }) {
31007
31022
  "use step";
31008
- const languageModel = await createLanguageModelFromConfig(provider, modelId, credentials);
31009
- const response = await generateObject4({
31010
- model: languageModel,
31011
- schema: translationSchema,
31012
- abortSignal,
31023
+ const model = await createLanguageModelFromConfig(provider, modelId, credentials);
31024
+ const response = await generateText4({
31025
+ model,
31026
+ output: Output4.object({ schema: translationSchema }),
31013
31027
  messages: [
31014
31028
  {
31015
31029
  role: "user",
@@ -31020,7 +31034,7 @@ ${vttContent}`
31020
31034
  ]
31021
31035
  });
31022
31036
  return {
31023
- translatedVtt: response.object.translation,
31037
+ translatedVtt: response.output.translation,
31024
31038
  usage: {
31025
31039
  inputTokens: response.usage.inputTokens,
31026
31040
  outputTokens: response.usage.outputTokens,
@@ -31167,7 +31181,6 @@ async function translateCaptions(assetId, fromLanguageCode, toLanguageCode, opti
31167
31181
  toLanguageCode,
31168
31182
  provider: modelConfig.provider,
31169
31183
  modelId: modelConfig.modelId,
31170
- abortSignal: options.abortSignal,
31171
31184
  credentials
31172
31185
  });
31173
31186
  translatedVtt = result.translatedVtt;