@mux/ai 0.25.0 → 0.27.1

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.
@@ -414,7 +414,7 @@ var DEFAULT_LANGUAGE_MODELS = {
414
414
  var LANGUAGE_MODELS = {
415
415
  openai: ["gpt-5.1", "gpt-5-mini"],
416
416
  anthropic: ["claude-sonnet-4-5"],
417
- google: ["gemini-3-flash-preview", "gemini-3.1-flash-lite", "gemini-3.1-flash-lite-preview", "gemini-2.5-flash"]
417
+ google: ["gemini-3-flash-preview", "gemini-3.1-flash-lite", "gemini-2.5-flash"]
418
418
  };
419
419
  var LANGUAGE_MODEL_DEPRECATIONS = [
420
420
  {
@@ -430,10 +430,10 @@ var LANGUAGE_MODEL_DEPRECATIONS = [
430
430
  provider: "google",
431
431
  modelId: "gemini-3.1-flash-lite-preview",
432
432
  replacementModelId: "gemini-3.1-flash-lite",
433
- phase: "warn",
433
+ phase: "blocked",
434
434
  deprecatedOn: "2026-05-12",
435
435
  sunsetOn: "2026-05-25",
436
- reason: "Preview model graduated to the stable Gemini 3.1 Flash-Lite release."
436
+ reason: "Google shut down Gemini 3.1 Flash-Lite Preview on 2026-05-25."
437
437
  }
438
438
  ];
439
439
  var warnedDeprecatedLanguageModels = /* @__PURE__ */ new Set();
@@ -792,6 +792,45 @@ function detectLeakReason(text) {
792
792
  return null;
793
793
  }
794
794
 
795
+ // src/lib/token-usage.ts
796
+ var TOKEN_USAGE_FIELDS = [
797
+ "inputTokens",
798
+ "outputTokens",
799
+ "totalTokens",
800
+ "reasoningTokens",
801
+ "cachedInputTokens"
802
+ ];
803
+ function getErrorTokenUsage(error) {
804
+ if (typeof error !== "object" || error === null) {
805
+ return void 0;
806
+ }
807
+ const usage = error.usage;
808
+ if (typeof usage !== "object" || usage === null) {
809
+ return void 0;
810
+ }
811
+ const source = usage;
812
+ const extracted = {};
813
+ for (const field of TOKEN_USAGE_FIELDS) {
814
+ const value = source[field];
815
+ if (typeof value === "number") {
816
+ extracted[field] = value;
817
+ }
818
+ }
819
+ if (extracted.reasoningTokens === void 0) {
820
+ const reasoningTokens = source.outputTokenDetails?.reasoningTokens;
821
+ if (typeof reasoningTokens === "number") {
822
+ extracted.reasoningTokens = reasoningTokens;
823
+ }
824
+ }
825
+ if (extracted.cachedInputTokens === void 0) {
826
+ const cacheReadTokens = source.inputTokenDetails?.cacheReadTokens;
827
+ if (typeof cacheReadTokens === "number") {
828
+ extracted.cachedInputTokens = cacheReadTokens;
829
+ }
830
+ }
831
+ return Object.keys(extracted).length > 0 ? extracted : void 0;
832
+ }
833
+
795
834
  // src/lib/mux-ai-error.ts
796
835
  var MuxAiError = class extends Error {
797
836
  constructor(message, opts) {
@@ -804,18 +843,38 @@ var MuxAiError = class extends Error {
804
843
  this.retryable = opts?.retryable ?? false;
805
844
  }
806
845
  };
846
+ function extractErrorDetail(error) {
847
+ if (error instanceof Error && error.message) {
848
+ return error.message;
849
+ }
850
+ if (typeof error === "string" && error.length > 0) {
851
+ return error;
852
+ }
853
+ if (typeof error === "object" && error !== null) {
854
+ const message = error.message;
855
+ if (typeof message === "string" && message.length > 0) {
856
+ return message;
857
+ }
858
+ }
859
+ return "Unknown error";
860
+ }
807
861
  function wrapError(error, message) {
808
862
  if (error instanceof MuxAiError) {
809
863
  throw error;
810
864
  }
811
- const rawDetail = error instanceof Error ? error.message : "Unknown error";
865
+ const rawDetail = extractErrorDetail(error);
812
866
  const leakReason = detectLeakReason(rawDetail);
813
867
  const shouldSuppress = leakReason === "canary" || leakReason === "prompt_tag";
814
868
  const detail = shouldSuppress ? "Upstream error details suppressed by safety filter" : rawDetail;
815
869
  if (shouldSuppress) {
816
870
  console.warn(`[@mux/ai] Suppressed suspected prompt leak in wrapped error (context: ${message}, reason: ${leakReason}).`);
817
871
  }
818
- throw new Error(`${message}: ${detail}`);
872
+ const wrapped = new Error(`${message}: ${detail}`);
873
+ const usage = getErrorTokenUsage(error);
874
+ if (usage) {
875
+ wrapped.usage = usage;
876
+ }
877
+ throw wrapped;
819
878
  }
820
879
 
821
880
  // src/primitives/shots.ts