ai 5.0.27 → 5.0.28

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.mjs CHANGED
@@ -40,6 +40,56 @@ var NoOutputSpecifiedError = class extends AISDKError {
40
40
  };
41
41
  _a = symbol;
42
42
 
43
+ // src/logger/log-warnings.ts
44
+ function formatWarning(warning) {
45
+ const prefix = "AI SDK Warning:";
46
+ switch (warning.type) {
47
+ case "unsupported-setting": {
48
+ let message = `${prefix} The "${warning.setting}" setting is not supported by this model`;
49
+ if (warning.details) {
50
+ message += ` - ${warning.details}`;
51
+ }
52
+ return message;
53
+ }
54
+ case "unsupported-tool": {
55
+ const toolName = "name" in warning.tool ? warning.tool.name : "unknown tool";
56
+ let message = `${prefix} The tool "${toolName}" is not supported by this model`;
57
+ if (warning.details) {
58
+ message += ` - ${warning.details}`;
59
+ }
60
+ return message;
61
+ }
62
+ case "other": {
63
+ return `${prefix} ${warning.message}`;
64
+ }
65
+ default: {
66
+ return `${prefix} ${JSON.stringify(warning, null, 2)}`;
67
+ }
68
+ }
69
+ }
70
+ var FIRST_WARNING_INFO_MESSAGE = "AI SDK Warning System: To turn off warning logging, set the AI_SDK_LOG_WARNINGS global to false.";
71
+ var hasLoggedBefore = false;
72
+ var logWarnings = (warnings) => {
73
+ if (warnings.length === 0) {
74
+ return;
75
+ }
76
+ const logger = globalThis.AI_SDK_LOG_WARNINGS;
77
+ if (logger === false) {
78
+ return;
79
+ }
80
+ if (typeof logger === "function") {
81
+ logger(warnings);
82
+ return;
83
+ }
84
+ if (!hasLoggedBefore) {
85
+ hasLoggedBefore = true;
86
+ console.info(FIRST_WARNING_INFO_MESSAGE);
87
+ }
88
+ for (const warning of warnings) {
89
+ console.warn(formatWarning(warning));
90
+ }
91
+ };
92
+
43
93
  // src/model/resolve-model.ts
44
94
  import { gateway } from "@ai-sdk/gateway";
45
95
 
@@ -2104,7 +2154,7 @@ async function generateText({
2104
2154
  }),
2105
2155
  tracer,
2106
2156
  fn: async (span) => {
2107
- var _a17, _b, _c, _d, _e, _f;
2157
+ var _a17, _b, _c, _d, _e, _f, _g;
2108
2158
  const callSettings2 = prepareCallSettings(settings);
2109
2159
  let currentModelResponse;
2110
2160
  let clientToolCalls = [];
@@ -2179,7 +2229,7 @@ async function generateText({
2179
2229
  }),
2180
2230
  tracer,
2181
2231
  fn: async (span2) => {
2182
- var _a19, _b2, _c2, _d2, _e2, _f2, _g, _h;
2232
+ var _a19, _b2, _c2, _d2, _e2, _f2, _g2, _h;
2183
2233
  const result = await stepModel.doGenerate({
2184
2234
  ...callSettings2,
2185
2235
  tools: stepTools,
@@ -2194,7 +2244,7 @@ async function generateText({
2194
2244
  id: (_b2 = (_a19 = result.response) == null ? void 0 : _a19.id) != null ? _b2 : generateId3(),
2195
2245
  timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
2196
2246
  modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
2197
- headers: (_g = result.response) == null ? void 0 : _g.headers,
2247
+ headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
2198
2248
  body: (_h = result.response) == null ? void 0 : _h.body
2199
2249
  };
2200
2250
  span2.setAttributes(
@@ -2318,6 +2368,7 @@ async function generateText({
2318
2368
  messages: structuredClone(responseMessages)
2319
2369
  }
2320
2370
  });
2371
+ logWarnings((_g = currentModelResponse.warnings) != null ? _g : []);
2321
2372
  steps.push(currentStepResult);
2322
2373
  await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
2323
2374
  } while (
@@ -4612,6 +4663,7 @@ var DefaultStreamTextResult = class {
4612
4663
  providerMetadata: part.providerMetadata
4613
4664
  });
4614
4665
  await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
4666
+ logWarnings(recordedWarnings);
4615
4667
  recordedSteps.push(currentStepResult);
4616
4668
  recordedContent = [];
4617
4669
  activeReasoningContent = {};
@@ -6079,6 +6131,7 @@ async function generateImage({
6079
6131
  }
6080
6132
  responses.push(result.response);
6081
6133
  }
6134
+ logWarnings(warnings);
6082
6135
  if (!images.length) {
6083
6136
  throw new NoImageGeneratedError({ responses });
6084
6137
  }
@@ -6758,6 +6811,7 @@ async function generateObject(options) {
6758
6811
  request = (_a17 = generateResult.request) != null ? _a17 : {};
6759
6812
  response = generateResult.responseData;
6760
6813
  reasoning = generateResult.reasoning;
6814
+ logWarnings(warnings);
6761
6815
  const object2 = await parseAndValidateObjectResultWithRepair(
6762
6816
  result,
6763
6817
  outputStrategy,
@@ -7272,6 +7326,7 @@ var DefaultStreamObjectResult = class {
7272
7326
  usage,
7273
7327
  response: fullResponse
7274
7328
  });
7329
+ logWarnings(warnings != null ? warnings : []);
7275
7330
  self._usage.resolve(usage);
7276
7331
  self._providerMetadata.resolve(providerMetadata);
7277
7332
  self._warnings.resolve(warnings);
@@ -7557,6 +7612,7 @@ async function generateSpeech({
7557
7612
  if (!result.audio || result.audio.length === 0) {
7558
7613
  throw new NoSpeechGeneratedError({ responses: [result.response] });
7559
7614
  }
7615
+ logWarnings(result.warnings);
7560
7616
  return new DefaultSpeechResult({
7561
7617
  audio: new DefaultGeneratedAudioFile({
7562
7618
  data: result.audio,
@@ -8887,6 +8943,7 @@ async function transcribe({
8887
8943
  });
8888
8944
  }
8889
8945
  );
8946
+ logWarnings(result.warnings);
8890
8947
  if (!result.text) {
8891
8948
  throw new NoTranscriptGeneratedError({ responses: [result.response] });
8892
8949
  }