ai 5.0.112 → 5.0.114

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.114
4
+
5
+ ### Patch Changes
6
+
7
+ - fc633bd: fix header loss when statusText is undefined in writeHead
8
+
9
+ ## 5.0.113
10
+
11
+ ### Patch Changes
12
+
13
+ - 7e6fb4d: fix(gateway): throw error with user-friendly message in non-production environments if `AI_GATEWAY_API_KEY` is not configured
14
+
3
15
  ## 5.0.112
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -777,7 +777,7 @@ function detectMediaType({
777
777
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
778
778
 
779
779
  // src/version.ts
780
- var VERSION = true ? "5.0.112" : "0.0.0-test";
780
+ var VERSION = true ? "5.0.114" : "0.0.0-test";
781
781
 
782
782
  // src/util/download/download.ts
783
783
  var download = async ({ url }) => {
@@ -1496,14 +1496,28 @@ async function standardizePrompt(prompt) {
1496
1496
  var import_gateway2 = require("@ai-sdk/gateway");
1497
1497
  var import_provider20 = require("@ai-sdk/provider");
1498
1498
  function wrapGatewayError(error) {
1499
- if (import_gateway2.GatewayAuthenticationError.isInstance(error) || import_gateway2.GatewayModelNotFoundError.isInstance(error)) {
1499
+ if (!import_gateway2.GatewayAuthenticationError.isInstance(error))
1500
+ return error;
1501
+ const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
1502
+ const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
1503
+ if (isProductionEnv) {
1500
1504
  return new import_provider20.AISDKError({
1501
1505
  name: "GatewayError",
1502
- message: "Unauthenticated. Configure AI_GATEWAY_API_KEY or configure and use a provider module. Learn more: https://vercel.link/unauthenticated-ai-gateway",
1503
- cause: error
1506
+ message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
1504
1507
  });
1505
1508
  }
1506
- return error;
1509
+ return Object.assign(
1510
+ new Error(`\x1B[1m\x1B[31mUnauthenticated request to AI Gateway.\x1B[0m
1511
+
1512
+ To authenticate, set the \x1B[33mAI_GATEWAY_API_KEY\x1B[0m environment variable with your API key.
1513
+
1514
+ Alternatively, you can use a provider module instead of the AI Gateway.
1515
+
1516
+ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
1517
+
1518
+ `),
1519
+ { name: "GatewayAuthenticationError" }
1520
+ );
1507
1521
  }
1508
1522
 
1509
1523
  // src/telemetry/assemble-operation-name.ts
@@ -2834,7 +2848,12 @@ function writeToServerResponse({
2834
2848
  headers,
2835
2849
  stream
2836
2850
  }) {
2837
- response.writeHead(status != null ? status : 200, statusText, headers);
2851
+ const statusCode = status != null ? status : 200;
2852
+ if (statusText !== void 0) {
2853
+ response.writeHead(statusCode, statusText, headers);
2854
+ } else {
2855
+ response.writeHead(statusCode, headers);
2856
+ }
2838
2857
  const reader = stream.getReader();
2839
2858
  const read = async () => {
2840
2859
  try {