@mux/ai 0.67.0 → 0.68.0-canary.112

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.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // package.json
8
- var version = "0.67.0";
8
+ var version = "0.68.0-canary.112";
9
9
 
10
10
  // node_modules/@workflow/serde/dist/index.js
11
11
  var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
@@ -576,9 +576,9 @@ 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`, `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). */
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`, `invalid_format`, `duplicate`) 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), `format` (what the value must look like). `duplicate` is a list of keyed entries that repeats a key (`value`). */
580
580
  INVALID_PARAMETER: "invalid_parameter",
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. */
581
+ /** A numeric option is outside its allowed range. Facts: `parameter` (the caller's option name), `value`, `min`, `max`, `integer` when it must be a whole number, and `unit` when the bounds have one. The public wording names the bound that was crossed. */
582
582
  PARAMETER_OUT_OF_RANGE: "parameter_out_of_range",
583
583
  /** No ready caption track matches the requested track or language. Facts: `trackId` or `languageCode`, and what is available. */
584
584
  CAPTION_TRACK_NOT_FOUND: "caption_track_not_found",
@@ -2514,6 +2514,17 @@ var MUX_AI_ERROR_GENERIC_MESSAGES = {
2514
2514
  function text(value) {
2515
2515
  return value === void 0 || value === null ? "" : String(value);
2516
2516
  }
2517
+ function outOfRangeBound(facts) {
2518
+ const unit = facts.unit === void 0 ? "" : ` ${text(facts.unit)}`;
2519
+ const { value, min, max } = facts;
2520
+ if (typeof value === "number" && typeof min === "number" && value < min) {
2521
+ return `at least ${min}${unit}`;
2522
+ }
2523
+ if (typeof value === "number" && typeof max === "number" && value > max) {
2524
+ return `at most ${max}${unit}`;
2525
+ }
2526
+ return `${facts.integer ? "an integer " : ""}between ${text(min)} and ${text(max)}${unit}`;
2527
+ }
2517
2528
  function wording(table, value) {
2518
2529
  const key = text(value);
2519
2530
  return Object.prototype.hasOwnProperty.call(table, key) ? table[key] : void 0;
@@ -2607,6 +2618,10 @@ function invalidParameterMessage(facts) {
2607
2618
  return `Provide at least one of ${names(facts.parameters)}.`;
2608
2619
  case "audio_only":
2609
2620
  return `${parameter} must be ${quotedList(facts.allowed)} for an audio-only asset, which is processed from its transcript and needs a ready caption or subtitle track.`;
2621
+ case "invalid_format":
2622
+ return `${subject} must be ${text(facts.format) || "in the expected format"}${entry}.`;
2623
+ case "duplicate":
2624
+ return `${parameter} has the key '${text(facts.value)}' more than once; each key must be unique.`;
2610
2625
  default:
2611
2626
  return `${parameter} has a value that can't be used.`;
2612
2627
  }
@@ -2651,12 +2666,12 @@ var MUX_AI_ERROR_PUBLIC_MAPPINGS = {
2651
2666
  },
2652
2667
  // Names the caller's own option; a consumer that exposes different names overrides the wording.
2653
2668
  [MUX_AI_ERROR_CODES.INVALID_PARAMETER]: {
2654
- facts: ["parameter", "reason", "count", "max", "index", "length", "maxLength", "characters", "with", "withValue", "allowed", "value", "parameters"],
2669
+ facts: ["parameter", "reason", "count", "max", "index", "length", "maxLength", "characters", "with", "withValue", "allowed", "value", "parameters", "format"],
2655
2670
  message: invalidParameterMessage
2656
2671
  },
2657
2672
  [MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE]: {
2658
- facts: ["parameter", "value", "min", "max", "integer"],
2659
- message: (facts) => `${text(facts.parameter) || "A parameter"} must be ${facts.integer ? "an integer " : ""}between ${text(facts.min)} and ${text(facts.max)}${facts.value === void 0 ? "" : ` (received ${text(facts.value)})`}.`
2673
+ facts: ["parameter", "value", "min", "max", "integer", "unit"],
2674
+ message: (facts) => `${text(facts.parameter) || "A parameter"} must be ${outOfRangeBound(facts)}${facts.value === void 0 ? "" : ` (received ${text(facts.value)})`}.`
2660
2675
  },
2661
2676
  [MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE]: {
2662
2677
  facts: ["assetId"],
@@ -5335,6 +5350,15 @@ function classifyModelCallError(error, context) {
5335
5350
  if (unusable) {
5336
5351
  return unusable;
5337
5352
  }
5353
+ if (isClientTimeout(last)) {
5354
+ return withUsage(dependencyError(`${context.call} timed out`, {
5355
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
5356
+ call: context.call,
5357
+ timedOut: true,
5358
+ facts: modelCallFacts(context),
5359
+ cause: error
5360
+ }), getErrorTokenUsage(error));
5361
+ }
5338
5362
  const apiError = findProviderCallError(error);
5339
5363
  if (!apiError) {
5340
5364
  return void 0;
@@ -5349,6 +5373,9 @@ function classifyModelCallError(error, context) {
5349
5373
  return void 0;
5350
5374
  }
5351
5375
  }
5376
+ function isClientTimeout(error) {
5377
+ return typeof error === "object" && error !== null && error.name === "TimeoutError";
5378
+ }
5352
5379
  function classifyUnusableOutput(last, error, context) {
5353
5380
  const parse = NoObjectGeneratedError.isInstance(last);
5354
5381
  if (!parse && !NoOutputGeneratedError2.isInstance(last)) {
@@ -5594,7 +5621,6 @@ function modelStepError(error, message, facts) {
5594
5621
  }
5595
5622
 
5596
5623
  // src/lib/model-call-diagnostics.ts
5597
- import { APICallError as APICallError3 } from "ai";
5598
5624
  function recordModelCallFailure(error, diagnostics, observedUsage = getErrorTokenUsage(error)) {
5599
5625
  if (typeof error !== "object" || error === null) {
5600
5626
  return;
@@ -5604,12 +5630,14 @@ function recordModelCallFailure(error, diagnostics, observedUsage = getErrorToke
5604
5630
  return;
5605
5631
  }
5606
5632
  failure.diagnostics = { ...diagnostics };
5633
+ const providerError = findProviderServiceError(error);
5634
+ const reported = providerError ?? error;
5607
5635
  console.warn("[@mux/ai] Model call failed.", {
5608
5636
  ...diagnostics,
5609
5637
  finishReason: failure.finishReason,
5610
- statusCode: failure.statusCode,
5611
- errorName: error instanceof Error ? error.name : void 0,
5612
- requestId: APICallError3.isInstance(error) ? error.responseHeaders?.["x-request-id"] ?? error.responseHeaders?.["request-id"] : void 0,
5638
+ statusCode: providerError?.statusCode ?? failure.statusCode,
5639
+ errorName: reported instanceof Error ? reported.name : void 0,
5640
+ requestId: providerError?.responseHeaders?.["x-request-id"] ?? providerError?.responseHeaders?.["request-id"],
5613
5641
  usage: observedUsage
5614
5642
  });
5615
5643
  }
@@ -5725,25 +5753,32 @@ function repairJsonSchema(plan) {
5725
5753
  properties: Object.fromEntries(plan.spans.map((span) => [span.id, { type: "string" }]))
5726
5754
  };
5727
5755
  }
5756
+ function rejected(code, reason) {
5757
+ return { accepted: false, code, reason };
5758
+ }
5728
5759
  function applyTextRepair(content, plan, replacements) {
5729
5760
  if (!replacements || typeof replacements !== "object" || Array.isArray(replacements))
5730
- return { accepted: false, reason: "Invalid replacement object" };
5761
+ return rejected("invalid_object", "Invalid replacement object");
5731
5762
  const values = replacements;
5732
5763
  if (Object.keys(values).length !== plan.spans.length || Object.keys(values).some((key) => !plan.spans.some((span) => span.id === key)))
5733
- return { accepted: false, reason: "Unexpected or missing span IDs" };
5764
+ return rejected("span_ids", "Unexpected or missing span IDs");
5734
5765
  const parts = split(content);
5735
5766
  for (const span of plan.spans) {
5736
5767
  const index = Number(span.id.slice(2));
5737
5768
  const replacement = values[span.id];
5738
5769
  if (parts[index] !== span.text)
5739
- return { accepted: false, reason: "Stale repair plan" };
5740
- if (typeof replacement !== "string" || !replacement.trim() || INVALID_REPLACEMENT.test(replacement) || introducesLiteralEscapes(span.text, replacement))
5741
- return { accepted: false, reason: "Empty or incompatible paragraph replacement" };
5770
+ return rejected("stale_plan", "Stale repair plan");
5771
+ if (typeof replacement !== "string" || !replacement.trim())
5772
+ return rejected("empty_replacement", "Empty or incompatible paragraph replacement");
5773
+ if (INVALID_REPLACEMENT.test(replacement))
5774
+ return rejected("split_paragraph", "Empty or incompatible paragraph replacement");
5775
+ if (introducesLiteralEscapes(span.text, replacement))
5776
+ return rejected("literal_escapes", "Empty or incompatible paragraph replacement");
5742
5777
  parts[index] = replacement;
5743
5778
  }
5744
5779
  const editedText = plan.spans.map((span) => values[span.id]).join("\n\n");
5745
5780
  if (plan.protectedTerms.some((term) => !editedText.includes(term)))
5746
- return { accepted: false, reason: "Protected term removed from edited spans" };
5781
+ return rejected("protected_term", "Protected term removed from edited spans");
5747
5782
  return { accepted: true, content: parts.join("") };
5748
5783
  }
5749
5784
  function introducesLiteralEscapes(source, replacement) {
@@ -5758,24 +5793,30 @@ async function runTextRepairLoop(options) {
5758
5793
  let content = options.content;
5759
5794
  const attempts = [];
5760
5795
  if (!content.trim())
5761
- return { status: "failed", attempts, reason: "Empty draft has no substance to preserve" };
5796
+ return { status: "failed", attempts, reason: "Empty draft has no substance to preserve", outcome: "empty_draft" };
5762
5797
  for (let index = 0; index < maxAttempts; index++) {
5763
5798
  if (!findGenerateTextLengthViolation(content, options.limits))
5764
5799
  return { status: "valid", content, attempts };
5765
5800
  const plan = planTextRepair(content, options.limits, options.protectedTerms);
5766
5801
  if (!plan)
5767
- return { status: "failed", attempts, reason: "No feasible span budget" };
5802
+ return { status: "failed", attempts, reason: "No feasible span budget", outcome: "no_plan" };
5768
5803
  const call = await options.generate(plan);
5769
5804
  const applied = applyTextRepair(content, plan, call.replacements);
5770
- attempts.push({ plan, call, rejection: applied.accepted ? void 0 : applied.reason });
5805
+ const overLimit = applied.accepted ? findGenerateTextLengthViolation(applied.content, options.limits) : void 0;
5806
+ attempts.push({
5807
+ plan,
5808
+ call,
5809
+ ...!applied.accepted && { rejection: applied.reason, rejectionCode: applied.code },
5810
+ ...overLimit && { overLimit }
5811
+ });
5771
5812
  if (call.error)
5772
- return { status: "failed", attempts, reason: call.error };
5773
- if (applied.accepted && !findGenerateTextLengthViolation(applied.content, options.limits))
5813
+ return { status: "failed", attempts, reason: call.error, outcome: "call_failed" };
5814
+ if (applied.accepted && !overLimit)
5774
5815
  return { status: "valid", content: applied.content, attempts };
5775
5816
  if (applied.accepted && options.limits.every((limit) => measureGenerateTextLength(applied.content, limit.unit) <= measureGenerateTextLength(content, limit.unit)))
5776
5817
  content = applied.content;
5777
5818
  }
5778
- return !findGenerateTextLengthViolation(content, options.limits) ? { status: "valid", content, attempts } : { status: "failed", attempts, reason: "Repair budget exhausted without a valid output" };
5819
+ return !findGenerateTextLengthViolation(content, options.limits) ? { status: "valid", content, attempts } : { status: "failed", attempts, reason: "Repair budget exhausted without a valid output", outcome: "exhausted" };
5779
5820
  }
5780
5821
 
5781
5822
  // src/lib/text-repair-model.ts
@@ -5809,15 +5850,15 @@ function createTextRepairGenerator(options) {
5809
5850
  onStepFinish: (step) => {
5810
5851
  usage = getErrorTokenUsage(step);
5811
5852
  }
5812
- }));
5853
+ }), options.context);
5813
5854
  usage = getErrorTokenUsage(response);
5814
- const output = getGeneratedOutputWithContentPolicyHandling(response);
5855
+ const output = getGeneratedOutputWithContentPolicyHandling(response, options.context);
5815
5856
  if (!output) {
5816
5857
  return { usage, elapsedMs: Date.now() - started, error: "Repair output missing" };
5817
5858
  }
5818
5859
  return { replacements: output, usage, elapsedMs: Date.now() - started };
5819
5860
  } catch (error) {
5820
- const cause = NoObjectGeneratedError2.isInstance(error) && error.finishReason && error.finishReason !== "stop" ? new IncompleteGenerationError(error.finishReason, void 0, getErrorTokenUsage(error)) : error;
5861
+ const cause = NoObjectGeneratedError2.isInstance(error) && error.finishReason && error.finishReason !== "stop" ? options.context ? incompleteGenerationError(error.finishReason, void 0, getErrorTokenUsage(error), options.context) : new IncompleteGenerationError(error.finishReason, void 0, getErrorTokenUsage(error)) : error;
5821
5862
  recordModelCallFailure(cause, {
5822
5863
  phase: "length_repair",
5823
5864
  provider: typeof options.model === "object" ? options.model.provider : "gateway",
@@ -8808,7 +8849,7 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
8808
8849
  }
8809
8850
 
8810
8851
  // src/workflows/generate-text.ts
8811
- import { APICallError as APICallError4, generateText as generateTextWithModel, Output as Output7 } from "ai";
8852
+ import { generateText as generateTextWithModel, Output as Output7 } from "ai";
8812
8853
  import { z as z11 } from "zod";
8813
8854
  var GENERATE_TEXT_MAX_VARIANTS = 5;
8814
8855
  var GENERATE_TEXT_MAX_ARTIFACTS = 5;
@@ -8831,96 +8872,151 @@ var GENERATE_TEXT_CHANNEL_CEILINGS = {
8831
8872
  x: { unit: "characters", value: 280 }
8832
8873
  };
8833
8874
  var KEY_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
8875
+ var KEY_FORMAT = "lowercase snake_case beginning with a letter, up to 64 characters";
8834
8876
  var LANGUAGE_TAG_PATTERN = /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i;
8877
+ var LANGUAGE_TAG_FORMAT = "a BCP 47 language tag such as 'en' or 'pt-BR'";
8835
8878
  var LENGTH_UNITS = ["characters", "words"];
8836
- function validationError(message) {
8837
- return new LegacyMuxAiError(message, { type: "validation_error" });
8879
+ function invalidOptionError3(message, facts, inputs) {
8880
+ return new MuxAiError(message, {
8881
+ code: MUX_AI_ERROR_CODES.INVALID_PARAMETER,
8882
+ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
8883
+ source: MUX_AI_ERROR_SOURCES.REQUEST,
8884
+ facts: { ...facts, inputs }
8885
+ });
8838
8886
  }
8839
- function assertOneOf(value, allowed, label) {
8887
+ function outOfRangeError(message, facts, inputs) {
8888
+ return new MuxAiError(message, {
8889
+ code: MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE,
8890
+ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
8891
+ source: MUX_AI_ERROR_SOURCES.REQUEST,
8892
+ facts: { ...facts, inputs }
8893
+ });
8894
+ }
8895
+ var ECHOABLE_VALUE = /^[\w.-]{1,40}$/;
8896
+ function echoableValue(value) {
8897
+ return typeof value === "string" && ECHOABLE_VALUE.test(value) ? { value } : {};
8898
+ }
8899
+ function assertOneOf(value, allowed, label, parameter, input) {
8840
8900
  if (!allowed.includes(value)) {
8841
- throw validationError(`Invalid ${label} "${value}". Valid values are: ${allowed.join(", ")}.`);
8901
+ throw invalidOptionError3(
8902
+ `Invalid ${label} "${value}". Valid values are: ${allowed.join(", ")}.`,
8903
+ { parameter, reason: "not_allowed", allowed: [...allowed], ...echoableValue(value) },
8904
+ [input]
8905
+ );
8842
8906
  }
8843
8907
  }
8844
- function assertBoundedText(value, max, label) {
8908
+ function assertBoundedText(value, max, label, parameter, input) {
8845
8909
  const length = value.trim().length;
8846
8910
  if (length === 0 || length > max) {
8847
- throw validationError(`${label} must be 1-${max} characters.`);
8911
+ throw invalidOptionError3(
8912
+ `${label} must be 1-${max} characters.`,
8913
+ length === 0 ? { parameter, reason: "empty" } : { parameter, reason: "too_long", length, maxLength: max },
8914
+ [input]
8915
+ );
8848
8916
  }
8849
8917
  return length;
8850
8918
  }
8851
- function assertKeyedItems(items, noun, max) {
8919
+ function assertKeyedItems(items, noun, parameter, max) {
8852
8920
  if (items.length === 0) {
8853
- throw validationError(`At least one ${noun} is required.`);
8921
+ throw invalidOptionError3(`At least one ${noun} is required.`, { parameter, reason: "empty" }, [parameter]);
8854
8922
  }
8855
8923
  if (items.length > max) {
8856
- throw validationError(`At most ${max} ${noun}s are supported (received ${items.length}).`);
8924
+ throw invalidOptionError3(
8925
+ `At most ${max} ${noun}s are supported (received ${items.length}).`,
8926
+ { parameter, reason: "too_many", count: items.length, max },
8927
+ [parameter]
8928
+ );
8857
8929
  }
8858
8930
  const seen = /* @__PURE__ */ new Set();
8859
- for (const { key, instructions } of items) {
8931
+ items.forEach(({ key, instructions }, index) => {
8860
8932
  if (!KEY_PATTERN.test(key ?? "")) {
8861
- throw validationError(`${noun} key "${key}" must be lowercase snake_case beginning with a letter, up to 64 characters.`);
8933
+ throw invalidOptionError3(
8934
+ `${noun} key "${key}" must be lowercase snake_case beginning with a letter, up to 64 characters.`,
8935
+ { parameter: `${parameter}[${index}].key`, reason: "invalid_format", format: KEY_FORMAT },
8936
+ [parameter]
8937
+ );
8862
8938
  }
8863
8939
  if (seen.has(key)) {
8864
- throw validationError(`Duplicate ${noun} key "${key}".`);
8940
+ throw invalidOptionError3(`Duplicate ${noun} key "${key}".`, { parameter, reason: "duplicate", value: key, index }, [parameter]);
8865
8941
  }
8866
8942
  seen.add(key);
8867
8943
  if (instructions !== void 0) {
8868
- assertBoundedText(instructions, GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, `${noun} "${key}" instructions`);
8944
+ assertBoundedText(instructions, GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS, `${noun} "${key}" instructions`, `${parameter}[${index}].instructions`, parameter);
8869
8945
  }
8870
- }
8946
+ });
8871
8947
  }
8872
- function assertArtifact(artifact) {
8948
+ function assertArtifact(artifact, index) {
8949
+ const parameter = `artifacts[${index}]`;
8873
8950
  if (artifact.channel !== void 0) {
8874
- assertOneOf(artifact.channel, GENERATE_TEXT_CHANNELS, `artifact "${artifact.key}" channel`);
8951
+ assertOneOf(artifact.channel, GENERATE_TEXT_CHANNELS, `artifact "${artifact.key}" channel`, `${parameter}.channel`, "artifacts");
8875
8952
  }
8876
8953
  if (artifact.format !== void 0) {
8877
- assertOneOf(artifact.format, GENERATE_TEXT_FORMATS, `artifact "${artifact.key}" format`);
8954
+ assertOneOf(artifact.format, GENERATE_TEXT_FORMATS, `artifact "${artifact.key}" format`, `${parameter}.format`, "artifacts");
8878
8955
  }
8879
8956
  if (artifact.maxLength === void 0) {
8880
8957
  return;
8881
8958
  }
8882
8959
  const { unit, value } = artifact.maxLength;
8883
- assertOneOf(unit, LENGTH_UNITS, `artifact "${artifact.key}" maxLength.unit`);
8960
+ assertOneOf(unit, LENGTH_UNITS, `artifact "${artifact.key}" maxLength.unit`, `${parameter}.maxLength.unit`, "artifacts");
8884
8961
  const bounds = GENERATE_TEXT_LENGTH_BOUNDS[unit];
8885
8962
  if (!Number.isInteger(value) || value < bounds.min || value > bounds.max) {
8886
- throw validationError(`Artifact "${artifact.key}" maxLength.value must be an integer between ${bounds.min} and ${bounds.max} (received ${value}).`);
8963
+ throw outOfRangeError(
8964
+ `Artifact "${artifact.key}" maxLength.value must be an integer between ${bounds.min} and ${bounds.max} ${unit} (received ${value}).`,
8965
+ { parameter: `${parameter}.maxLength.value`, ...typeof value === "number" ? { value: Number.isFinite(value) ? value : String(value) } : echoableValue(value), min: bounds.min, max: bounds.max, integer: true, unit },
8966
+ ["artifacts"]
8967
+ );
8887
8968
  }
8888
8969
  const ceiling = artifact.channel ? GENERATE_TEXT_CHANNEL_CEILINGS[artifact.channel] : void 0;
8889
8970
  if (ceiling && ceiling.unit === unit && value > ceiling.value) {
8890
- throw validationError(`Artifact "${artifact.key}" targets ${artifact.channel} and supports at most ${ceiling.value} ${ceiling.unit}.`);
8971
+ throw outOfRangeError(
8972
+ `Artifact "${artifact.key}" targets ${artifact.channel} and supports at most ${ceiling.value} ${ceiling.unit}.`,
8973
+ { parameter: `${parameter}.maxLength.value`, value, min: bounds.min, max: ceiling.value, integer: true, unit, channel: artifact.channel },
8974
+ ["artifacts"]
8975
+ );
8891
8976
  }
8892
8977
  }
8893
- function assertLanguageTag(value, label) {
8978
+ function assertLanguageTag(value, parameter) {
8894
8979
  if (value.length > 35 || !LANGUAGE_TAG_PATTERN.test(value)) {
8895
- throw validationError(`${label} must be a BCP 47 language tag such as "en" or "pt-BR".`);
8980
+ throw invalidOptionError3(
8981
+ `${parameter} must be a BCP 47 language tag such as "en" or "pt-BR".`,
8982
+ { parameter, reason: "invalid_format", format: LANGUAGE_TAG_FORMAT },
8983
+ [parameter]
8984
+ );
8896
8985
  }
8897
8986
  }
8898
8987
  function resolveGenerateTextOptions(options) {
8899
8988
  const variants = options.variants ?? [{ key: "default" }];
8900
- assertKeyedItems(variants, "variant", GENERATE_TEXT_MAX_VARIANTS);
8901
- assertKeyedItems(options.artifacts, "artifact", GENERATE_TEXT_MAX_ARTIFACTS);
8902
- for (const artifact of options.artifacts) {
8903
- assertArtifact(artifact);
8904
- }
8989
+ assertKeyedItems(variants, "variant", "variants", GENERATE_TEXT_MAX_VARIANTS);
8990
+ assertKeyedItems(options.artifacts, "artifact", "artifacts", GENERATE_TEXT_MAX_ARTIFACTS);
8991
+ options.artifacts.forEach(assertArtifact);
8905
8992
  if (options.audience !== void 0) {
8906
- assertBoundedText(options.audience, GENERATE_TEXT_MAX_AUDIENCE_CHARS, "audience");
8993
+ assertBoundedText(options.audience, GENERATE_TEXT_MAX_AUDIENCE_CHARS, "audience", "audience", "audience");
8907
8994
  }
8908
8995
  if (options.voice !== void 0) {
8909
- assertOneOf(options.voice, GENERATE_TEXT_VOICES, "voice");
8996
+ assertOneOf(options.voice, GENERATE_TEXT_VOICES, "voice", "voice", "voice");
8910
8997
  }
8911
8998
  if (options.callToAction !== void 0) {
8912
- assertOneOf(options.callToAction, GENERATE_TEXT_CALLS_TO_ACTION, "callToAction");
8999
+ assertOneOf(options.callToAction, GENERATE_TEXT_CALLS_TO_ACTION, "callToAction", "callToAction", "callToAction");
8913
9000
  }
8914
9001
  if (options.brandTerms !== void 0) {
8915
- if (options.brandTerms.length === 0 || options.brandTerms.length > GENERATE_TEXT_MAX_BRAND_TERMS) {
8916
- throw validationError(`brandTerms must contain 1-${GENERATE_TEXT_MAX_BRAND_TERMS} terms.`);
9002
+ const count = options.brandTerms.length;
9003
+ if (count === 0 || count > GENERATE_TEXT_MAX_BRAND_TERMS) {
9004
+ throw invalidOptionError3(
9005
+ `brandTerms must contain 1-${GENERATE_TEXT_MAX_BRAND_TERMS} terms.`,
9006
+ count === 0 ? { parameter: "brandTerms", reason: "empty" } : { parameter: "brandTerms", reason: "too_many", count, max: GENERATE_TEXT_MAX_BRAND_TERMS },
9007
+ ["brandTerms"]
9008
+ );
8917
9009
  }
8918
9010
  const total = options.brandTerms.reduce(
8919
- (sum, term) => sum + assertBoundedText(term, GENERATE_TEXT_MAX_BRAND_TERM_CHARS, "Each brand term"),
9011
+ (sum, term, index) => sum + assertBoundedText(term, GENERATE_TEXT_MAX_BRAND_TERM_CHARS, "Each brand term", `brandTerms[${index}]`, "brandTerms"),
8920
9012
  0
8921
9013
  );
8922
9014
  if (total > GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS) {
8923
- throw validationError(`Combined brandTerms must be ${GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS} characters or fewer.`);
9015
+ throw invalidOptionError3(
9016
+ `Combined brandTerms must be ${GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS} characters or fewer.`,
9017
+ { parameter: "brandTerms", reason: "too_long", length: total, maxLength: GENERATE_TEXT_MAX_BRAND_TERMS_TOTAL_CHARS },
9018
+ ["brandTerms"]
9019
+ );
8924
9020
  }
8925
9021
  }
8926
9022
  if (options.languageCode !== void 0) {
@@ -9014,14 +9110,20 @@ function clampBriefArrays(brief) {
9014
9110
  }
9015
9111
  return clamped;
9016
9112
  }
9017
- function scrubBrief(brief, safety) {
9113
+ function scrubBrief(brief, safety, facts) {
9018
9114
  const centralIdea = safety.scrubDetailed(brief.centralIdea, "editorial_brief.centralIdea");
9019
9115
  const readerValue = safety.scrubDetailed(brief.readerValue, "editorial_brief.readerValue");
9020
9116
  if (centralIdea.leaked || readerValue.leaked || !centralIdea.text.trim()) {
9021
- throw new LegacyMuxAiError(
9022
- "The editorial brief was suppressed by the output safety filter.",
9023
- { type: "processing_error", retryable: true }
9024
- );
9117
+ throw new MuxAiError("The editorial brief was suppressed by the output safety filter.", {
9118
+ code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_SUPPRESSED,
9119
+ type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
9120
+ source: MUX_AI_ERROR_SOURCES.UPSTREAM,
9121
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
9122
+ facts,
9123
+ // Resubmittable, as before classification: a new brief may not trip the filter.
9124
+ transient: false,
9125
+ retryable: true
9126
+ });
9025
9127
  }
9026
9128
  const scrubbed = { ...brief, centralIdea: centralIdea.text, readerValue: readerValue.text };
9027
9129
  for (const field of Object.keys(BRIEF_LIST_LIMITS)) {
@@ -9218,10 +9320,65 @@ function describeLengthRevision({ limit, actual }) {
9218
9320
  function readUsage(response) {
9219
9321
  return getErrorTokenUsage(response) ?? {};
9220
9322
  }
9323
+ function invalidModelOutputError(context, cause) {
9324
+ return new MuxAiError(`${context.call} returned output that doesn't match its schema`, {
9325
+ code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
9326
+ type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
9327
+ source: MUX_AI_ERROR_SOURCES.UPSTREAM,
9328
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
9329
+ facts: { call: context.call, provider: context.provider, ...context.model && { model: context.model } },
9330
+ transient: true,
9331
+ cause
9332
+ });
9333
+ }
9334
+ function lengthRepairError(repaired, context, draft) {
9335
+ const cause = repaired.attempts.at(-1)?.call.errorCause;
9336
+ const facts = { call: context.call, provider: context.provider, ...context.model && { model: context.model } };
9337
+ if (cause === void 0) {
9338
+ return new MuxAiError("Unable to bring the generated text within its length limit.", {
9339
+ code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
9340
+ type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
9341
+ source: MUX_AI_ERROR_SOURCES.UPSTREAM,
9342
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
9343
+ // The draft's own length, then why the repair stopped (no feasible plan, or its calls
9344
+ // used up) and what each call produced: rejected replacements, or text still over a limit.
9345
+ facts: {
9346
+ ...facts,
9347
+ reason: "over_length",
9348
+ limitUnit: draft.limit.unit,
9349
+ limit: draft.limit.value,
9350
+ actual: draft.actual,
9351
+ ...repaired.outcome && { repairOutcome: repaired.outcome },
9352
+ repairAttempts: repaired.attempts.map((attempt) => attempt.rejectionCode ? { rejection: attempt.rejectionCode } : attempt.overLimit ? { limitUnit: attempt.overLimit.limit.unit, limit: attempt.overLimit.limit.value, actual: attempt.overLimit.actual } : {})
9353
+ },
9354
+ transient: false,
9355
+ retryable: true
9356
+ });
9357
+ }
9358
+ const classified = MuxAiError.is(cause) ? cause : modelStepError(cause, "Unable to complete text generation.", { ...context });
9359
+ const retryable = classified.dependency ? classified.retryable : findProviderServiceError(cause)?.isRetryable ?? true;
9360
+ const failure = classified.transient || classified.retryable !== retryable ? new MuxAiError(classified.message, {
9361
+ ...classified.code && { code: classified.code },
9362
+ type: classified.type,
9363
+ source: classified.source,
9364
+ ...classified.dependency && { dependency: classified.dependency },
9365
+ facts: classified.facts,
9366
+ transient: false,
9367
+ retryable,
9368
+ // The raw failure, so the cause chain stays the provider's own error, not a second wrapper of it.
9369
+ cause: MuxAiError.is(cause) ? classified.cause ?? classified : cause
9370
+ }) : classified;
9371
+ delete failure.usage;
9372
+ if (typeof cause === "object" && cause !== null && "diagnostics" in cause) {
9373
+ failure.diagnostics = cause.diagnostics;
9374
+ }
9375
+ return failure;
9376
+ }
9221
9377
  async function extractBriefWithModel(args) {
9222
9378
  "use step";
9223
9379
  return withModelCallDiagnostics({ phase: "brief", provider: args.provider, modelId: args.modelId }, async () => {
9224
9380
  const model = await createLanguageModelFromConfig(args.provider, args.modelId, args.credentials);
9381
+ const context = { call: "extract_brief", provider: args.provider, model: args.modelId };
9225
9382
  const response = await withContentPolicyAwareRetry(() => generateTextWithModel({
9226
9383
  model,
9227
9384
  maxRetries: 0,
@@ -9240,13 +9397,16 @@ async function extractBriefWithModel(args) {
9240
9397
  ]
9241
9398
  }
9242
9399
  ]
9243
- }));
9244
- const output = getGeneratedOutputWithContentPolicyHandling(response);
9245
- if (!output) {
9246
- throw new Error("Editorial brief output missing");
9400
+ }), void 0, context).catch((error) => {
9401
+ throw modelStepError(error, "Editorial brief model call failed", { ...context });
9402
+ });
9403
+ const output = getGeneratedOutputWithContentPolicyHandling(response, context);
9404
+ const parsed = briefSchema.safeParse(output);
9405
+ if (!parsed.success) {
9406
+ throw invalidModelOutputError(context, parsed.error);
9247
9407
  }
9248
9408
  return {
9249
- brief: clampBriefArrays(briefSchema.parse(output)),
9409
+ brief: clampBriefArrays(parsed.data),
9250
9410
  usage: readUsage(response),
9251
9411
  unexpectedKeys: detectUnexpectedKeysFromRawText(response.text, briefSchema.keyof().options)
9252
9412
  };
@@ -9258,6 +9418,7 @@ async function generateArtifactWithModel(args) {
9258
9418
  const diagnostics = { phase: "draft", provider: args.provider, modelId: args.modelId };
9259
9419
  return withModelCallDiagnostics(diagnostics, async () => {
9260
9420
  const model = await createLanguageModelFromConfig(args.provider, args.modelId, args.credentials);
9421
+ const context = { call: "generate_artifact", provider: args.provider, model: args.modelId };
9261
9422
  const attempt = async (messages) => {
9262
9423
  const response = await withContentPolicyAwareRetry(() => generateTextWithModel({
9263
9424
  model,
@@ -9269,13 +9430,16 @@ async function generateArtifactWithModel(args) {
9269
9430
  }),
9270
9431
  system: args.systemPrompt,
9271
9432
  messages
9272
- }));
9273
- const output = getGeneratedOutputWithContentPolicyHandling(response);
9274
- if (!output) {
9275
- throw new Error("Generated text output missing");
9433
+ }), void 0, context).catch((error) => {
9434
+ throw modelStepError(error, "Text generation model call failed", { ...context });
9435
+ });
9436
+ const output = getGeneratedOutputWithContentPolicyHandling(response, context);
9437
+ const parsed = artifactSchema.safeParse(output);
9438
+ if (!parsed.success) {
9439
+ throw invalidModelOutputError(context, parsed.error);
9276
9440
  }
9277
9441
  return {
9278
- content: artifactSchema.parse(output).content.trim(),
9442
+ content: parsed.data.content.trim(),
9279
9443
  usage: readUsage(response),
9280
9444
  unexpectedKeys: detectUnexpectedKeysFromRawText(response.text, artifactSchema.keyof().options)
9281
9445
  };
@@ -9313,28 +9477,12 @@ ${renderSection({ tag: "revision_request", content: "The previous draft was empt
9313
9477
  content: candidate.content,
9314
9478
  limits: args.limits,
9315
9479
  protectedTerms: args.protectedTerms,
9316
- model
9480
+ model,
9481
+ context
9317
9482
  });
9318
9483
  usages.push(...repaired.attempts.flatMap((item) => item.call.usage ? [item.call.usage] : []));
9319
9484
  if (repaired.status !== "valid") {
9320
- const cause = repaired.attempts.at(-1)?.call.errorCause;
9321
- let failure;
9322
- if (isIncompleteGenerationError(cause)) {
9323
- failure = new IncompleteGenerationError(cause.finishReason, cause.rawFinishReason);
9324
- } else if (isLegacyMuxAiError(cause)) {
9325
- failure = new LegacyMuxAiError(cause.publicMessage, { type: cause.publicType, retryable: cause.retryable });
9326
- } else {
9327
- const apiError = APICallError4.isInstance(cause) ? cause : void 0;
9328
- failure = new LegacyMuxAiError("Unable to complete text generation.", {
9329
- type: "processing_error",
9330
- retryable: apiError?.isRetryable ?? true,
9331
- cause
9332
- });
9333
- }
9334
- if (typeof cause === "object" && cause !== null && "diagnostics" in cause) {
9335
- failure.diagnostics = cause.diagnostics;
9336
- }
9337
- rethrowWithTokenUsage(failure, usages);
9485
+ rethrowWithTokenUsage(lengthRepairError(repaired, context, violation), usages);
9338
9486
  }
9339
9487
  return { content: repaired.content, usages, unexpectedKeys };
9340
9488
  });
@@ -9348,7 +9496,7 @@ async function generateText7(assetId, options) {
9348
9496
  rethrowWithTokenUsage(error, collectedUsage);
9349
9497
  }
9350
9498
  }
9351
- async function generateArtifactsInBatches(requests, collectedUsage, provider) {
9499
+ async function generateArtifactsInBatches(requests, collectedUsage, provider, model, assetId) {
9352
9500
  const results = [];
9353
9501
  for (let start = 0; start < requests.length; start += GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS) {
9354
9502
  const batch = requests.slice(start, start + GENERATE_TEXT_MAX_CONCURRENT_GENERATIONS);
@@ -9369,7 +9517,7 @@ async function generateArtifactsInBatches(requests, collectedUsage, provider) {
9369
9517
  collectedUsage.push(usage);
9370
9518
  }
9371
9519
  }
9372
- legacyWrapError(failures[0], `Failed to generate text with ${provider}`);
9520
+ wrapError(failures[0], `Failed to generate text with ${provider}`, { call: "generate_artifact", provider, model, assetId });
9373
9521
  }
9374
9522
  }
9375
9523
  return results;
@@ -9396,28 +9544,35 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9396
9544
  model,
9397
9545
  provider
9398
9546
  });
9399
- const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
9547
+ const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot, { classifiedErrors: true });
9400
9548
  const assetDurationSeconds = getAssetDurationSecondsFromAsset(asset);
9401
9549
  const isAudioOnly = isAudioOnlyAsset(asset);
9402
9550
  const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
9403
- const resolvedScope = effectiveScope ? resolveWorkflowScope(effectiveScope, assetDurationSeconds) : void 0;
9551
+ const resolvedScope = effectiveScope ? resolveWorkflowScope(effectiveScope, assetDurationSeconds, { classifiedErrors: true, assetId }) : void 0;
9404
9552
  const storyboardScope = isAudioOnly ? void 0 : resolveRenderableVideoScope(
9405
9553
  effectiveScope,
9406
9554
  assetDurationSeconds,
9407
- getVideoTrackDurationSecondsFromAsset(asset)
9555
+ getVideoTrackDurationSecondsFromAsset(asset),
9556
+ { classifiedErrors: true, assetId }
9408
9557
  );
9409
9558
  if (useShots && isAudioOnly) {
9410
- throw new LegacyMuxAiError("useShots is not supported for audio-only assets.", { type: "validation_error" });
9559
+ throw invalidOptionError3(
9560
+ "useShots is not supported for audio-only assets.",
9561
+ { parameter: "useShots", reason: "audio_only", allowed: [false], value: true, assetId },
9562
+ ["useShots"]
9563
+ );
9411
9564
  }
9412
9565
  if (useShots && assetDurationSeconds === void 0) {
9413
- throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
9566
+ throw new MuxAiError("Asset has no valid duration.", {
9567
+ code: MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE,
9568
+ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
9569
+ source: MUX_AI_ERROR_SOURCES.ASSET,
9570
+ facts: { assetId }
9571
+ });
9414
9572
  }
9415
9573
  const signingContext = await resolveMuxSigningContext(credentials);
9416
9574
  if (policy === "signed" && !signingContext) {
9417
- throw new LegacyMuxAiError(
9418
- "Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
9419
- { type: "validation_error" }
9420
- );
9575
+ throw signingCredentialsMissingError();
9421
9576
  }
9422
9577
  const shouldSign = policy === "signed";
9423
9578
  const [transcriptResult, storyboardUrl, shotsResult] = await Promise.all([
@@ -9427,17 +9582,28 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9427
9582
  shouldSign,
9428
9583
  credentials,
9429
9584
  required: true,
9430
- scope: effectiveScope
9585
+ scope: effectiveScope,
9586
+ classifiedErrors: true
9431
9587
  }),
9432
9588
  isAudioOnly ? void 0 : getStoryboardUrl(playbackId, 640, shouldSign, credentials, storyboardScope),
9433
9589
  useShots ? getCompletedShots(assetId, credentials) : void 0
9434
9590
  ]);
9435
9591
  const transcriptText = transcriptResult.transcriptText.trim();
9436
9592
  if (!transcriptText) {
9437
- throw new LegacyMuxAiError(
9438
- effectiveScope ? "Transcript has no usable content in the requested scope." : "Transcript has no usable content.",
9439
- { type: "validation_error" }
9440
- );
9593
+ const trackId = transcriptResult.track?.id;
9594
+ if (effectiveScope) {
9595
+ throw invalidScopeError(
9596
+ "Transcript has no usable content in the requested scope.",
9597
+ { reason: "no_transcript", ...trackId && { trackId }, ...effectiveScope.startTime !== void 0 && { startTime: effectiveScope.startTime }, ...effectiveScope.endTime !== void 0 && { endTime: effectiveScope.endTime } },
9598
+ ["scope"]
9599
+ );
9600
+ }
9601
+ throw new MuxAiError("Transcript has no usable content.", {
9602
+ code: MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY,
9603
+ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
9604
+ source: MUX_AI_ERROR_SOURCES.ASSET,
9605
+ facts: { assetId, ...trackId && { trackId } }
9606
+ });
9441
9607
  }
9442
9608
  const resolvedLanguageCode = outputLanguageCode && outputLanguageCode !== "auto" ? outputLanguageCode : getReliableLanguageCode(transcriptResult.track);
9443
9609
  const languageName = resolvedLanguageCode ? getLanguageName(resolvedLanguageCode) : void 0;
@@ -9447,6 +9613,7 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9447
9613
  }
9448
9614
  const steering = { audience, voice, callToAction, brandTerms };
9449
9615
  const safety = createSafetyReporter();
9616
+ const briefFacts = { call: "extract_brief", provider: modelConfig.provider, model: modelConfig.modelId, assetId };
9450
9617
  const briefStep = await extractBriefWithModel({
9451
9618
  provider: modelConfig.provider,
9452
9619
  modelId: modelConfig.modelId,
@@ -9454,12 +9621,12 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9454
9621
  userPrompt: buildBriefUserPrompt({ transcriptText, imageCount: imageUrls.length, audience, languageName }),
9455
9622
  imageUrls,
9456
9623
  credentials
9457
- }).catch((error) => legacyWrapError(error, `Failed to extract editorial brief with ${provider}`));
9624
+ }).catch((error) => wrapError(error, `Failed to extract editorial brief with ${provider}`, { ...briefFacts }));
9458
9625
  collectedUsage.push(briefStep.usage);
9459
9626
  for (const key of briefStep.unexpectedKeys) {
9460
9627
  safety.record(`editorial_brief.${key}`, "unexpected_key");
9461
9628
  }
9462
- const brief = scrubBrief(briefStep.brief, safety);
9629
+ const brief = scrubBrief(briefStep.brief, safety, briefFacts);
9463
9630
  const matrix = variants.flatMap((variant) => artifacts.map((artifact) => ({
9464
9631
  variant,
9465
9632
  artifact,
@@ -9473,7 +9640,7 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9473
9640
  limits,
9474
9641
  protectedTerms: brandTerms,
9475
9642
  credentials
9476
- })), collectedUsage, provider);
9643
+ })), collectedUsage, provider, modelConfig.modelId, assetId);
9477
9644
  const groupedVariants = variants.map((variant, variantIndex) => ({
9478
9645
  key: variant.key,
9479
9646
  artifacts: artifacts.map((artifact, artifactIndex) => {
@@ -9482,13 +9649,30 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
9482
9649
  for (const key of item.unexpectedKeys) {
9483
9650
  safety.record(`${field}.${key}`, "unexpected_key");
9484
9651
  }
9652
+ const artifactFacts = { call: "generate_artifact", provider: modelConfig.provider, model: modelConfig.modelId, assetId, variant: variant.key, artifact: artifact.key };
9485
9653
  if (item.violation === "empty") {
9486
- throw new LegacyMuxAiError(`Generated text for ${field} was empty after a retry.`, { type: "processing_error", retryable: true });
9654
+ throw new MuxAiError(`Generated text for ${field} was empty after a retry.`, {
9655
+ code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING,
9656
+ type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
9657
+ source: MUX_AI_ERROR_SOURCES.UPSTREAM,
9658
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
9659
+ facts: artifactFacts,
9660
+ transient: false,
9661
+ retryable: true
9662
+ });
9487
9663
  }
9488
9664
  if (item.violation) {
9489
- throw new LegacyMuxAiError(
9665
+ throw new MuxAiError(
9490
9666
  `Generated text for ${field} exceeded the ${item.violation.limit.value} ${item.violation.limit.unit} limit after a retry (${item.violation.actual} returned).`,
9491
- { type: "processing_error", retryable: true }
9667
+ {
9668
+ code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
9669
+ type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
9670
+ source: MUX_AI_ERROR_SOURCES.UPSTREAM,
9671
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
9672
+ facts: { ...artifactFacts, reason: "over_length", limitUnit: item.violation.limit.unit, limit: item.violation.limit.value, actual: item.violation.actual },
9673
+ transient: false,
9674
+ retryable: true
9675
+ }
9492
9676
  );
9493
9677
  }
9494
9678
  return {