@hebo-ai/gateway 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.
@@ -2,7 +2,30 @@ import type { LanguageModelMiddleware } from "ai";
2
2
 
3
3
  import { modelMiddlewareMatcher } from "../../middleware/matcher";
4
4
 
5
- export const bedrockAnthropicReasoningMiddleware: LanguageModelMiddleware = {
5
+ const isClaude46 = (modelId: string) => modelId.includes("-4-6");
6
+
7
+ export const bedrockGptReasoningMiddleware: LanguageModelMiddleware = {
8
+ specificationVersion: "v3",
9
+ // eslint-disable-next-line require-await
10
+ transformParams: async ({ params, model }) => {
11
+ if (!model.modelId.includes("gpt")) return params;
12
+
13
+ const bedrock = params.providerOptions?.["bedrock"];
14
+ if (!bedrock || typeof bedrock !== "object") return params;
15
+
16
+ const effort = bedrock["reasoningEffort"];
17
+ if (effort === undefined) return params;
18
+
19
+ const target = (bedrock["reasoningConfig"] ??= {}) as Record<string, unknown>;
20
+ target["maxReasoningEffort"] = effort;
21
+
22
+ delete bedrock["reasoningEffort"];
23
+
24
+ return params;
25
+ },
26
+ };
27
+
28
+ export const bedrockClaudeReasoningMiddleware: LanguageModelMiddleware = {
6
29
  specificationVersion: "v3",
7
30
  // eslint-disable-next-line require-await
8
31
  transformParams: async ({ params, model }) => {
@@ -11,13 +34,12 @@ export const bedrockAnthropicReasoningMiddleware: LanguageModelMiddleware = {
11
34
  const bedrock = params.providerOptions?.["bedrock"];
12
35
  if (!bedrock || typeof bedrock !== "object") return params;
13
36
 
14
- const bedrockOptions = bedrock as Record<string, unknown>;
15
- const thinking = bedrockOptions["thinking"];
16
- const effort = bedrockOptions["effort"];
37
+ const thinking = bedrock["thinking"];
38
+ const effort = bedrock["effort"];
17
39
 
18
40
  if (!thinking && effort === undefined) return params;
19
41
 
20
- const target = (bedrockOptions["reasoningConfig"] ??= {}) as Record<string, unknown>;
42
+ const target = (bedrock["reasoningConfig"] ??= {}) as Record<string, unknown>;
21
43
 
22
44
  if (thinking && typeof thinking === "object") {
23
45
  const thinkingOptions = thinking as Record<string, unknown>;
@@ -29,15 +51,18 @@ export const bedrockAnthropicReasoningMiddleware: LanguageModelMiddleware = {
29
51
  }
30
52
  }
31
53
 
32
- if (effort !== undefined) target["maxReasoningEffort"] = effort;
54
+ // FUTURE: bedrock currently does not support "effort" for other 4.x models
55
+ if (effort !== undefined && isClaude46(model.modelId)) {
56
+ target["maxReasoningEffort"] = effort;
57
+ }
33
58
 
34
- delete bedrockOptions["thinking"];
35
- delete bedrockOptions["effort"];
59
+ delete bedrock["thinking"];
60
+ delete bedrock["effort"];
36
61
 
37
62
  return params;
38
63
  },
39
64
  };
40
65
 
41
66
  modelMiddlewareMatcher.useForProvider("amazon-bedrock", {
42
- language: [bedrockAnthropicReasoningMiddleware],
67
+ language: [bedrockGptReasoningMiddleware, bedrockClaudeReasoningMiddleware],
43
68
  });
@@ -0,0 +1,46 @@
1
+ import type { LogWarningsFunction } from "ai";
2
+
3
+ import type { TelemetrySignalLevel } from "../types";
4
+
5
+ import { logger } from "../logger";
6
+ import { addSpanEvent, setSpanAttributes } from "./span";
7
+
8
+ type GlobalWithAiSdkWarningLogger = typeof globalThis & {
9
+ AI_SDK_LOG_WARNINGS?: LogWarningsFunction | false;
10
+ };
11
+
12
+ export const installAiSdkWarningLogger = (genAiSignalLevel?: TelemetrySignalLevel) => {
13
+ const logWarnings: LogWarningsFunction = ({ warnings, provider, model }) => {
14
+ if (warnings.length === 0) return;
15
+
16
+ for (const warning of warnings) {
17
+ logger.warn(
18
+ {
19
+ provider,
20
+ model,
21
+ warning,
22
+ },
23
+ `[ai-sdk] ${warning.type}`,
24
+ );
25
+ }
26
+
27
+ if (!(genAiSignalLevel === "recommended" || genAiSignalLevel === "full")) return;
28
+
29
+ setSpanAttributes({
30
+ "gen_ai.response.warning_count": warnings.length,
31
+ });
32
+
33
+ for (const warning of warnings) {
34
+ addSpanEvent("gen_ai.warning", {
35
+ "gen_ai.provider.name": provider,
36
+ "gen_ai.response.model": model,
37
+ "gen_ai.warning.type": warning.type,
38
+ "gen_ai.warning.feature": "feature" in warning ? warning.feature : undefined,
39
+ "gen_ai.warning.details": "details" in warning ? warning.details : undefined,
40
+ "gen_ai.warning.message": "message" in warning ? warning.message : undefined,
41
+ });
42
+ }
43
+ };
44
+
45
+ (globalThis as GlobalWithAiSdkWarningLogger).AI_SDK_LOG_WARNINGS = logWarnings;
46
+ };