@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.
- package/README.md +2 -2
- package/dist/config.js +2 -0
- package/dist/endpoints/chat-completions/converters.d.ts +5 -1
- package/dist/endpoints/chat-completions/converters.js +61 -12
- package/dist/endpoints/chat-completions/schema.d.ts +54 -9
- package/dist/endpoints/chat-completions/schema.js +20 -13
- package/dist/models/anthropic/middleware.js +14 -13
- package/dist/providers/bedrock/middleware.d.ts +2 -1
- package/dist/providers/bedrock/middleware.js +29 -9
- package/dist/telemetry/ai-sdk.d.ts +2 -0
- package/dist/telemetry/ai-sdk.js +31 -0
- package/package.json +1 -1
- package/src/config.ts +3 -0
- package/src/endpoints/chat-completions/converters.test.ts +111 -0
- package/src/endpoints/chat-completions/converters.ts +71 -13
- package/src/endpoints/chat-completions/handler.ts +10 -3
- package/src/endpoints/chat-completions/schema.ts +22 -14
- package/src/endpoints/embeddings/handler.ts +5 -3
- package/src/middleware/debug.ts +37 -0
- package/src/middleware/matcher.ts +4 -0
- package/src/models/anthropic/middleware.test.ts +5 -1
- package/src/models/anthropic/middleware.ts +17 -13
- package/src/providers/bedrock/middleware.test.ts +118 -8
- package/src/providers/bedrock/middleware.ts +34 -9
- package/src/telemetry/ai-sdk.ts +46 -0
|
@@ -2,7 +2,30 @@ import type { LanguageModelMiddleware } from "ai";
|
|
|
2
2
|
|
|
3
3
|
import { modelMiddlewareMatcher } from "../../middleware/matcher";
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
15
|
-
const
|
|
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 = (
|
|
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
|
-
|
|
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
|
|
35
|
-
delete
|
|
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: [
|
|
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
|
+
};
|