@openclaw/amazon-bedrock-provider 2026.6.5 → 2026.6.6-beta.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/dist/bedrock-options.js +1 -0
- package/dist/discovery.js +19 -12
- package/dist/provider-policy-api.js +1 -1
- package/dist/register.sync.runtime.js +58 -21
- package/dist/stream.runtime.js +110 -48
- package/dist/thinking-policy.js +81 -7
- package/node_modules/@aws-sdk/credential-provider-env/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-http/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +14 -14
- package/node_modules/@aws-sdk/credential-provider-login/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js +12 -1
- package/node_modules/@aws-sdk/credential-provider-node/dist-es/runtime/memoize-chain.js +12 -1
- package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/LICENSE +201 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/README.md +62 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +156 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/constants.js +2 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +16 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +80 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +8 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +11 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +10 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/index.js +4 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +7 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +7 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +8 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/constants.d.ts +8 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromEnvSigningName.d.ts +18 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromSso.d.ts +12 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromStatic.d.ts +9 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getNewSsoOidcToken.d.ts +8 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getSsoOidcClient.d.ts +7 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/index.d.ts +4 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/nodeProvider.d.ts +18 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/constants.d.ts +3 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromEnvSigningName.d.ts +11 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromSso.d.ts +14 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromStatic.d.ts +12 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getNewSsoOidcToken.d.ts +11 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getSsoOidcClient.d.ts +7 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/index.d.ts +4 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/nodeProvider.d.ts +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenExpiry.d.ts +2 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenKey.d.ts +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/writeSSOTokenToFile.d.ts +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenExpiry.d.ts +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenKey.d.ts +4 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/writeSSOTokenToFile.d.ts +5 -0
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +69 -0
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +7 -7
- package/node_modules/@aws-sdk/eventstream-handler-node/package.json +5 -5
- package/node_modules/@aws-sdk/middleware-eventstream/package.json +5 -5
- package/node_modules/@aws-sdk/middleware-websocket/package.json +8 -8
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +99 -106
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +62 -120
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +55 -86
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +73 -104
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +102 -185
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/auth/httpAuthSchemeProvider.js +4 -5
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/endpoint/bdd.js +21 -57
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.browser.js +1 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.js +2 -4
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/schemas/schemas_0.js +73 -41
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/auth/httpAuthSchemeProvider.js +4 -5
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/endpoint/bdd.js +20 -52
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.browser.js +1 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.js +2 -4
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/schemas/schemas_0.js +36 -59
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/auth/httpAuthSchemeProvider.js +4 -5
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/endpoint/bdd.js +17 -45
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.browser.js +1 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.js +2 -4
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/schemas/schemas_0.js +32 -32
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/auth/httpAuthSchemeProvider.js +4 -5
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/endpoint/bdd.js +17 -45
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.browser.js +1 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.js +2 -4
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/schemas/schemas_0.js +50 -50
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/auth/httpAuthSchemeProvider.js +4 -5
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/defaultRoleAssumers.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/endpoint/bdd.js +34 -96
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.browser.js +1 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.js +3 -6
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/schemas/schemas_0.js +63 -80
- package/node_modules/@aws-sdk/nested-clients/package.json +9 -9
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +5 -5
- package/node_modules/@aws-sdk/types/package.json +3 -3
- package/node_modules/@aws-sdk/util-locate-window/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +39 -22
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +39 -22
- package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/configurations.js +19 -6
- package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +4 -5
- package/node_modules/@smithy/core/dist-es/submodules/retry/service-error-classification/constants.js +1 -1
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/ConfiguredRetryStrategy.js +4 -5
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/DefaultRetryToken.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +9 -5
- package/node_modules/@smithy/core/dist-types/submodules/retry/middleware-retry/configurations.d.ts +4 -1
- package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/ConfiguredRetryStrategy.d.ts +1 -2
- package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/DefaultRetryToken.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/StandardRetryStrategy.d.ts +1 -1
- package/node_modules/@smithy/core/package.json +2 -2
- package/node_modules/@smithy/credential-provider-imds/dist-cjs/index.js +14 -13
- package/node_modules/@smithy/credential-provider-imds/dist-es/fromContainerMetadata.js +14 -13
- package/node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/httpRequest.js +2 -2
- package/node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/node-http.js +2 -0
- package/node_modules/@smithy/credential-provider-imds/dist-types/remoteProvider/httpRequest.d.ts +1 -1
- package/node_modules/@smithy/credential-provider-imds/dist-types/remoteProvider/node-http.d.ts +2 -0
- package/node_modules/@smithy/credential-provider-imds/package.json +3 -3
- package/node_modules/@smithy/fetch-http-handler/package.json +4 -4
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +6 -4
- package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +7 -6
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +2 -1
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2.js +2 -0
- package/node_modules/@smithy/node-http-handler/dist-es/node-https.js +2 -0
- package/node_modules/@smithy/node-http-handler/dist-types/node-http-handler.d.ts +2 -2
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +1 -1
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2.d.ts +2 -0
- package/node_modules/@smithy/node-http-handler/dist-types/node-https.d.ts +2 -0
- package/node_modules/@smithy/node-http-handler/package.json +4 -4
- package/node_modules/@smithy/signature-v4/package.json +3 -3
- package/node_modules/@smithy/types/dist-types/retry.d.ts +25 -0
- package/node_modules/@smithy/types/package.json +1 -1
- package/npm-shrinkwrap.json +169 -152
- package/package.json +7 -7
package/dist/bedrock-options.js
CHANGED
|
@@ -13,6 +13,7 @@ function supportsBedrockPromptCaching(modelId, modelName) {
|
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
if (candidates.some((s) => s.includes("-4-"))) return true;
|
|
16
|
+
if (candidates.some((s) => s.includes("claude-fable-5"))) return true;
|
|
16
17
|
if (candidates.some((s) => s.includes("claude-3-7-sonnet"))) return true;
|
|
17
18
|
if (candidates.some((s) => s.includes("claude-3-5-haiku"))) return true;
|
|
18
19
|
return false;
|
package/dist/discovery.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { refreshAwsSharedConfigCacheForBedrock } from "./aws-credential-refresh.js";
|
|
2
2
|
import { resolveBedrockConfigApiKey } from "./discovery-shared.js";
|
|
3
|
+
import { resolveBedrockNativeThinkingLevelMap } from "./thinking-policy.js";
|
|
4
|
+
import { resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, supportsClaudeAdaptiveThinking } from "openclaw/plugin-sdk/provider-model-shared";
|
|
3
5
|
import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
6
|
import { createSubsystemLogger } from "openclaw/plugin-sdk/core";
|
|
5
7
|
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
@@ -26,6 +28,7 @@ const DEFAULT_MAX_TOKENS = 4096;
|
|
|
26
28
|
* https://platform.claude.com/docs/en/about-claude/models
|
|
27
29
|
*/
|
|
28
30
|
const KNOWN_CONTEXT_WINDOWS = {
|
|
31
|
+
"anthropic.claude-fable-5": 1e6,
|
|
29
32
|
"anthropic.claude-3-7-sonnet-20250219-v1:0": 2e5,
|
|
30
33
|
"anthropic.claude-opus-4-8": 1e6,
|
|
31
34
|
"anthropic.claude-opus-4-7": 1e6,
|
|
@@ -89,21 +92,21 @@ const KNOWN_CONTEXT_WINDOWS = {
|
|
|
89
92
|
function resolveKnownContextWindow(modelId) {
|
|
90
93
|
const candidates = [modelId, modelId.replace(/^(?:us|eu|ap|apac|au|jp|global)\./, "")];
|
|
91
94
|
for (const candidate of candidates) {
|
|
95
|
+
if (resolveClaudeFable5ModelIdentity({ id: candidate })) return 1e6;
|
|
92
96
|
if (/(?:^|[/.:])anthropic\.claude-opus-4[.-]8(?:$|[-.:/])/i.test(candidate)) return 1e6;
|
|
93
97
|
if (KNOWN_CONTEXT_WINDOWS[candidate] !== void 0) return KNOWN_CONTEXT_WINDOWS[candidate];
|
|
94
98
|
const withoutVersionSuffix = candidate.replace(/:0$/, "");
|
|
95
99
|
if (withoutVersionSuffix !== candidate && KNOWN_CONTEXT_WINDOWS[withoutVersionSuffix] !== void 0) return KNOWN_CONTEXT_WINDOWS[withoutVersionSuffix];
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
function
|
|
99
|
-
return [modelId, modelId.replace(/^(?:us|eu|ap|apac|au|jp|global)\./, "")].some((candidate) => /(?:^|[/.:])anthropic\.claude-
|
|
102
|
+
function isKnownClaudeMythosPreviewModelId(modelId) {
|
|
103
|
+
return [modelId, modelId.replace(/^(?:us|eu|ap|apac|au|jp|global)\./, "")].some((candidate) => /(?:^|[/.:])anthropic\.claude-mythos-preview(?:$|[-.:/])/i.test(candidate));
|
|
100
104
|
}
|
|
101
105
|
function resolveKnownThinkingLevelMap(modelId) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
106
|
+
return resolveBedrockNativeThinkingLevelMap(modelId);
|
|
107
|
+
}
|
|
108
|
+
function resolveKnownMaxTokens(modelId) {
|
|
109
|
+
return resolveClaudeFable5ModelIdentity({ id: modelId }) ? 128e3 : void 0;
|
|
107
110
|
}
|
|
108
111
|
const DEFAULT_COST = {
|
|
109
112
|
input: 0,
|
|
@@ -167,7 +170,7 @@ function mapInputModalities(summary) {
|
|
|
167
170
|
return Array.from(mapped);
|
|
168
171
|
}
|
|
169
172
|
function inferReasoningSupport(summary) {
|
|
170
|
-
if (
|
|
173
|
+
if (supportsClaudeAdaptiveThinking({ id: summary.modelId })) return true;
|
|
171
174
|
const haystack = normalizeLowercaseStringOrEmpty(`${summary.modelId ?? ""} ${summary.modelName ?? ""}`);
|
|
172
175
|
return haystack.includes("reasoning") || haystack.includes("thinking");
|
|
173
176
|
}
|
|
@@ -189,6 +192,7 @@ function shouldIncludeSummary(summary, filter) {
|
|
|
189
192
|
if (!summary.modelId?.trim()) return false;
|
|
190
193
|
if (!matchesProviderFilter(summary, filter)) return false;
|
|
191
194
|
if (summary.responseStreamingSupported !== true) return false;
|
|
195
|
+
if (isKnownClaudeMythosPreviewModelId(summary.modelId)) return false;
|
|
192
196
|
if (!includesTextModalities(summary.outputModalities)) return false;
|
|
193
197
|
if (!isActive(summary)) return false;
|
|
194
198
|
return true;
|
|
@@ -203,7 +207,7 @@ function toModelDefinition(summary, defaults) {
|
|
|
203
207
|
input: mapInputModalities(summary),
|
|
204
208
|
cost: DEFAULT_COST,
|
|
205
209
|
contextWindow: resolveKnownContextWindow(id) ?? defaults.contextWindow,
|
|
206
|
-
maxTokens: defaults.maxTokens,
|
|
210
|
+
maxTokens: resolveKnownMaxTokens(id) ?? defaults.maxTokens,
|
|
207
211
|
...thinkingLevelMap ? { thinkingLevelMap } : {}
|
|
208
212
|
};
|
|
209
213
|
}
|
|
@@ -273,17 +277,20 @@ function resolveInferenceProfiles(profiles, defaults, providerFilter, foundation
|
|
|
273
277
|
})) continue;
|
|
274
278
|
}
|
|
275
279
|
const baseModelId = resolveBaseModelId(profile);
|
|
280
|
+
if (isKnownClaudeMythosPreviewModelId(baseModelId ?? profile.inferenceProfileId)) continue;
|
|
276
281
|
const baseModel = baseModelId ? foundationModels.get(normalizeLowercaseStringOrEmpty(baseModelId)) : void 0;
|
|
277
282
|
const knownThinkingLevelMap = resolveKnownThinkingLevelMap(baseModelId ?? profile.inferenceProfileId);
|
|
283
|
+
const canonicalClaudeId = resolveClaudeModelIdentity({ id: baseModelId });
|
|
278
284
|
discovered.push({
|
|
279
285
|
id: profile.inferenceProfileId,
|
|
280
286
|
name: profile.inferenceProfileName?.trim() || profile.inferenceProfileId,
|
|
281
|
-
reasoning: baseModel?.reasoning ??
|
|
287
|
+
reasoning: baseModel?.reasoning ?? supportsClaudeAdaptiveThinking({ id: baseModelId ?? profile.inferenceProfileId }),
|
|
282
288
|
input: baseModel?.input ?? ["text"],
|
|
283
289
|
cost: baseModel?.cost ?? DEFAULT_COST,
|
|
284
290
|
contextWindow: baseModel?.contextWindow ?? resolveKnownContextWindow(baseModelId ?? profile.inferenceProfileId ?? "") ?? defaults.contextWindow,
|
|
285
|
-
maxTokens: baseModel?.maxTokens ?? defaults.maxTokens,
|
|
286
|
-
...baseModel?.thinkingLevelMap || knownThinkingLevelMap ? { thinkingLevelMap: baseModel?.thinkingLevelMap ?? knownThinkingLevelMap } : {}
|
|
291
|
+
maxTokens: baseModel?.maxTokens ?? resolveKnownMaxTokens(baseModelId ?? profile.inferenceProfileId) ?? defaults.maxTokens,
|
|
292
|
+
...baseModel?.thinkingLevelMap || knownThinkingLevelMap ? { thinkingLevelMap: baseModel?.thinkingLevelMap ?? knownThinkingLevelMap } : {},
|
|
293
|
+
...canonicalClaudeId.startsWith("claude-") ? { params: { canonicalModelId: canonicalClaudeId } } : {}
|
|
287
294
|
});
|
|
288
295
|
}
|
|
289
296
|
return discovered;
|
|
@@ -8,7 +8,7 @@ import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
|
8
8
|
/** Resolve the Bedrock thinking profile for a provider/model pair. */
|
|
9
9
|
function resolveThinkingProfile(params) {
|
|
10
10
|
if (normalizeProviderId(params.provider) !== "amazon-bedrock") return null;
|
|
11
|
-
return resolveBedrockClaudeThinkingProfile(params.modelId);
|
|
11
|
+
return resolveBedrockClaudeThinkingProfile(params.modelId, params.params);
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
14
|
export { resolveThinkingProfile };
|
|
@@ -2,13 +2,32 @@ import { refreshAwsSharedConfigCacheForBedrock } from "./aws-credential-refresh.
|
|
|
2
2
|
import { supportsBedrockPromptCaching } from "./bedrock-options.js";
|
|
3
3
|
import { mergeImplicitBedrockProvider, resolveBedrockConfigApiKey } from "./discovery-shared.js";
|
|
4
4
|
import { bedrockMemoryEmbeddingProviderAdapter } from "./memory-embedding-adapter.js";
|
|
5
|
+
import { isLatestAdaptiveBedrockModelRef, isOpus47OrNewerBedrockModelRef, resolveBedrockClaudeThinkingProfile, resolveBedrockNativeThinkingLevelMap, supportsBedrockNativeMaxEffort } from "./thinking-policy.js";
|
|
5
6
|
import { streamBedrock, streamSimpleBedrock } from "./stream.runtime.js";
|
|
6
|
-
import { isOpus47OrNewerBedrockModelRef, resolveBedrockClaudeThinkingProfile } from "./thinking-policy.js";
|
|
7
7
|
import { registerApiProvider, streamSimple } from "openclaw/plugin-sdk/llm";
|
|
8
8
|
import { resolvePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
9
|
-
import { ANTHROPIC_BY_MODEL_REPLAY_HOOKS, normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
9
|
+
import { ANTHROPIC_BY_MODEL_REPLAY_HOOKS, normalizeProviderId, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity } from "openclaw/plugin-sdk/provider-model-shared";
|
|
10
10
|
import { streamWithPayloadPatch } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
11
11
|
//#region extensions/amazon-bedrock/register.sync.runtime.ts
|
|
12
|
+
function normalizeBedrockResolvedModel({ modelId, model }) {
|
|
13
|
+
const thinkingLevelMap = resolveBedrockNativeThinkingLevelMap(modelId, model.params);
|
|
14
|
+
if (!thinkingLevelMap) return;
|
|
15
|
+
const reasoning = model.reasoning || resolveClaudeFable5ModelIdentity({
|
|
16
|
+
id: modelId,
|
|
17
|
+
params: model.params
|
|
18
|
+
}) !== void 0;
|
|
19
|
+
const current = model.thinkingLevelMap;
|
|
20
|
+
const currentEfforts = current;
|
|
21
|
+
if (reasoning === model.reasoning && Object.entries(thinkingLevelMap).every(([level, effort]) => currentEfforts?.[level] === effort)) return;
|
|
22
|
+
return {
|
|
23
|
+
...model,
|
|
24
|
+
reasoning,
|
|
25
|
+
thinkingLevelMap: {
|
|
26
|
+
...thinkingLevelMap,
|
|
27
|
+
...current
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
12
31
|
const BEDROCK_SERVICE_TIER_VALUES = [
|
|
13
32
|
"flex",
|
|
14
33
|
"priority",
|
|
@@ -170,7 +189,7 @@ function injectBedrockCachePoints(payload, cacheRetention) {
|
|
|
170
189
|
}
|
|
171
190
|
}
|
|
172
191
|
}
|
|
173
|
-
function
|
|
192
|
+
function patchMaxThinkingEffort(payload) {
|
|
174
193
|
const fieldsValue = payload.additionalModelRequestFields;
|
|
175
194
|
const fields = fieldsValue && typeof fieldsValue === "object" && !Array.isArray(fieldsValue) ? fieldsValue : {};
|
|
176
195
|
const outputConfigValue = fields.output_config;
|
|
@@ -200,18 +219,23 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
200
219
|
return resolvePluginConfigObject(config, providerId) ?? (config ? void 0 : startupPluginConfig);
|
|
201
220
|
}
|
|
202
221
|
api.registerMemoryEmbeddingProvider(bedrockMemoryEmbeddingProviderAdapter);
|
|
203
|
-
const baseWrapStreamFn = ({ modelId, streamFn }) => {
|
|
204
|
-
|
|
222
|
+
const baseWrapStreamFn = ({ modelId, model, streamFn }) => {
|
|
223
|
+
const modelRef = {
|
|
224
|
+
id: modelId,
|
|
225
|
+
params: model?.params
|
|
226
|
+
};
|
|
227
|
+
if (isAnthropicBedrockModel(modelId) || resolveClaudeModelIdentity(modelRef).startsWith("claude-")) return streamFn;
|
|
205
228
|
if (isBedrockAppInferenceProfile(modelId)) return streamFn;
|
|
206
229
|
return createBedrockNoCacheWrapper(streamFn);
|
|
207
230
|
};
|
|
208
|
-
function
|
|
209
|
-
|
|
231
|
+
function omitUnsupportedClaudeTemperature(modelRef, options) {
|
|
232
|
+
const canonicalModelId = resolveClaudeModelIdentity(modelRef);
|
|
233
|
+
if (!(isOpus47OrNewerBedrockModelRef(modelRef.id) || isOpus47OrNewerBedrockModelRef(canonicalModelId) || resolveClaudeFable5ModelIdentity(modelRef) !== void 0) || !("temperature" in options)) return options;
|
|
210
234
|
const next = { ...options };
|
|
211
235
|
delete next.temperature;
|
|
212
236
|
return next;
|
|
213
237
|
}
|
|
214
|
-
function
|
|
238
|
+
function omitUnsupportedClaudePayloadTemperature(payload) {
|
|
215
239
|
const inferenceConfig = payload.inferenceConfig;
|
|
216
240
|
if (!inferenceConfig || typeof inferenceConfig !== "object") return;
|
|
217
241
|
delete inferenceConfig.temperature;
|
|
@@ -272,37 +296,50 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
272
296
|
}
|
|
273
297
|
},
|
|
274
298
|
resolveConfigApiKey: ({ env }) => resolveBedrockConfigApiKey(env),
|
|
299
|
+
normalizeResolvedModel: normalizeBedrockResolvedModel,
|
|
275
300
|
...anthropicByModelReplayHooks,
|
|
276
301
|
wrapStreamFn: ({ modelId, config, model, streamFn, thinkingLevel, extraParams }) => {
|
|
277
302
|
const currentPluginConfig = resolveCurrentPluginConfig(config);
|
|
278
303
|
const currentGuardrail = currentPluginConfig?.guardrail;
|
|
304
|
+
const modelRef = {
|
|
305
|
+
id: modelId,
|
|
306
|
+
params: model?.params
|
|
307
|
+
};
|
|
308
|
+
const fable5 = resolveClaudeFable5ModelIdentity(modelRef) !== void 0;
|
|
309
|
+
const canonicalModelId = resolveClaudeModelIdentity(modelRef);
|
|
310
|
+
const opus47OrNewer = isOpus47OrNewerBedrockModelRef(modelId) || isOpus47OrNewerBedrockModelRef(canonicalModelId);
|
|
311
|
+
const supportsNativeMax = supportsBedrockNativeMaxEffort(modelId, model?.params);
|
|
279
312
|
let wrapped = (currentGuardrail?.guardrailIdentifier && currentGuardrail?.guardrailVersion ? createGuardrailWrapStreamFn(baseWrapStreamFn, currentGuardrail)({
|
|
280
313
|
modelId,
|
|
314
|
+
model,
|
|
281
315
|
streamFn
|
|
282
316
|
}) : baseWrapStreamFn({
|
|
283
317
|
modelId,
|
|
318
|
+
model,
|
|
284
319
|
streamFn
|
|
285
320
|
})) ?? void 0;
|
|
286
321
|
const serviceTier = resolveBedrockServiceTier(extraParams, (message) => api.logger.warn(message));
|
|
287
|
-
if (serviceTier && wrapped)
|
|
322
|
+
if (serviceTier && wrapped) if (fable5 && serviceTier !== "default") api.logger.warn(`ignoring unsupported Fable 5 Bedrock service tier: ${serviceTier}`);
|
|
323
|
+
else wrapped = createBedrockServiceTierWrapper(wrapped, serviceTier);
|
|
288
324
|
const region = resolveBedrockRegion(config) ?? extractRegionFromBaseUrl(model?.baseUrl) ?? currentPluginConfig?.discovery?.region;
|
|
289
325
|
const mayNeedCacheInjection = isBedrockAppInferenceProfile(modelId) && !sharedRuntimeWouldInjectCachePoints(modelId);
|
|
290
|
-
const shouldOmitTemperature =
|
|
291
|
-
const shouldPatchMaxThinking =
|
|
326
|
+
const shouldOmitTemperature = opus47OrNewer || fable5 || isLatestAdaptiveBedrockModelRef(modelId, model?.params);
|
|
327
|
+
const shouldPatchMaxThinking = supportsNativeMax && thinkingLevel === "max";
|
|
328
|
+
const shouldPatchPayload = shouldOmitTemperature || shouldPatchMaxThinking;
|
|
292
329
|
const heuristicMatch = needsCachePointInjection(modelId);
|
|
293
330
|
if (!region && !mayNeedCacheInjection && !shouldOmitTemperature && !shouldPatchMaxThinking) return createAwsCredentialRefreshStreamWrapper(wrapped);
|
|
294
331
|
const underlying = wrapped ?? streamFn;
|
|
295
332
|
if (!underlying) return wrapped;
|
|
296
333
|
return (streamModel, context, options) => {
|
|
297
|
-
const merged =
|
|
334
|
+
const merged = omitUnsupportedClaudeTemperature(modelRef, Object.assign({}, options, region ? { region } : {}));
|
|
298
335
|
const originalOnPayload = merged.onPayload;
|
|
299
336
|
if (!mayNeedCacheInjection) return underlying(streamModel, context, withAwsCredentialRefreshOnPayload({
|
|
300
337
|
...merged,
|
|
301
|
-
...
|
|
338
|
+
...shouldPatchPayload ? { onPayload: (payload, payloadModel) => {
|
|
302
339
|
if (payload && typeof payload === "object") {
|
|
303
340
|
const payloadRecord = payload;
|
|
304
|
-
|
|
305
|
-
|
|
341
|
+
if (shouldPatchMaxThinking) patchMaxThinkingEffort(payloadRecord);
|
|
342
|
+
if (shouldOmitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
306
343
|
}
|
|
307
344
|
return originalOnPayload?.(payload, payloadModel);
|
|
308
345
|
} } : {}
|
|
@@ -316,10 +353,10 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
316
353
|
if (payload && typeof payload === "object") {
|
|
317
354
|
const payloadRecord = payload;
|
|
318
355
|
injectBedrockCachePoints(payloadRecord, cacheRetention);
|
|
319
|
-
if (shouldPatchMaxThinking)
|
|
320
|
-
if (shouldOmitTemperature)
|
|
356
|
+
if (shouldPatchMaxThinking) patchMaxThinkingEffort(payloadRecord);
|
|
357
|
+
if (shouldOmitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
321
358
|
else if (mayNeedTemperatureTrait) {
|
|
322
|
-
if ((await resolveAppProfileTraits(modelId, region)).omitTemperature)
|
|
359
|
+
if ((await resolveAppProfileTraits(modelId, region)).omitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
323
360
|
}
|
|
324
361
|
}
|
|
325
362
|
return originalOnPayload?.(payload, payloadModel);
|
|
@@ -333,8 +370,8 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
333
370
|
if (payload && typeof payload === "object") {
|
|
334
371
|
const payloadRecord = payload;
|
|
335
372
|
if (traits.cacheEligible) injectBedrockCachePoints(payloadRecord, cacheRetention);
|
|
336
|
-
if (shouldPatchMaxThinking)
|
|
337
|
-
if (traits.omitTemperature)
|
|
373
|
+
if (shouldPatchMaxThinking) patchMaxThinkingEffort(payloadRecord);
|
|
374
|
+
if (traits.omitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
338
375
|
}
|
|
339
376
|
return originalOnPayload?.(payload, payloadModel);
|
|
340
377
|
}
|
|
@@ -347,7 +384,7 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
347
384
|
if (/ModelNotReadyException/i.test(errorMessage)) return "overloaded";
|
|
348
385
|
if (deprecatedTemperatureValidationRe.test(errorMessage)) return "format";
|
|
349
386
|
},
|
|
350
|
-
resolveThinkingProfile: ({ modelId }) => resolveBedrockClaudeThinkingProfile(modelId)
|
|
387
|
+
resolveThinkingProfile: ({ modelId, params }) => resolveBedrockClaudeThinkingProfile(modelId, params)
|
|
351
388
|
});
|
|
352
389
|
}
|
|
353
390
|
//#endregion
|
package/dist/stream.runtime.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { supportsBedrockPromptCaching } from "./bedrock-options.js";
|
|
2
|
+
import { supportsBedrockNativeMaxEffort } from "./thinking-policy.js";
|
|
2
3
|
import { AssistantMessageEventStream, adjustMaxTokensForThinking, buildBaseOptions, calculateCost, clampReasoning, createHttpProxyAgentsForTarget, parseStreamingJson, sanitizeSurrogates, transformMessages } from "openclaw/plugin-sdk/llm";
|
|
4
|
+
import { resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, supportsClaudeAdaptiveThinking, supportsClaudeNativeXhighEffort } from "openclaw/plugin-sdk/provider-model-shared";
|
|
5
|
+
import { applyAnthropicRefusal, createDeferredEventBuffer, notifyLlmRequestActivity } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
3
6
|
import { BedrockRuntimeClient, BedrockRuntimeServiceException, CachePointType, CacheTTL, ConversationRole, ConverseStreamCommand, ImageFormat, StopReason, ToolResultStatus } from "@aws-sdk/client-bedrock-runtime";
|
|
4
7
|
import { NodeHttpHandler } from "@smithy/node-http-handler";
|
|
5
8
|
//#region extensions/amazon-bedrock/stream.runtime.ts
|
|
@@ -7,6 +10,18 @@ import { NodeHttpHandler } from "@smithy/node-http-handler";
|
|
|
7
10
|
* Amazon Bedrock Converse streaming runtime. It maps OpenClaw messages/tools,
|
|
8
11
|
* thinking, cache points, images, and usage into Bedrock Converse Stream calls.
|
|
9
12
|
*/
|
|
13
|
+
function usesClaudeFable5BedrockContract(model) {
|
|
14
|
+
return resolveClaudeFable5ModelIdentity(model) !== void 0;
|
|
15
|
+
}
|
|
16
|
+
function readBedrockStopDetails(fields) {
|
|
17
|
+
if (!fields || typeof fields !== "object" || Array.isArray(fields)) return;
|
|
18
|
+
const record = fields;
|
|
19
|
+
return record.stop_details ?? record.stopDetails;
|
|
20
|
+
}
|
|
21
|
+
function normalizeFableToolChoice(toolChoice) {
|
|
22
|
+
if (toolChoice === "any" || typeof toolChoice === "object" && toolChoice?.type === "tool") return "auto";
|
|
23
|
+
return toolChoice;
|
|
24
|
+
}
|
|
10
25
|
/** Stream a Bedrock Converse request using Bedrock-specific options. */
|
|
11
26
|
const streamBedrock = (model, context, options = {}) => {
|
|
12
27
|
const stream = new AssistantMessageEventStream();
|
|
@@ -35,6 +50,9 @@ const streamBedrock = (model, context, options = {}) => {
|
|
|
35
50
|
timestamp: Date.now()
|
|
36
51
|
};
|
|
37
52
|
const blocks = output.content;
|
|
53
|
+
const fable5 = usesClaudeFable5BedrockContract(model);
|
|
54
|
+
const refusalBuffer = fable5 ? createDeferredEventBuffer(stream, () => notifyLlmRequestActivity(options.signal)) : void 0;
|
|
55
|
+
const eventSink = refusalBuffer ?? stream;
|
|
38
56
|
const config = { profile: options.profile };
|
|
39
57
|
const configuredRegion = getConfiguredBedrockRegion(options);
|
|
40
58
|
const hasConfiguredProfile = hasConfiguredBedrockProfile(options);
|
|
@@ -62,16 +80,20 @@ const streamBedrock = (model, context, options = {}) => {
|
|
|
62
80
|
try {
|
|
63
81
|
const client = new BedrockRuntimeClient(config);
|
|
64
82
|
const cacheRetention = resolveCacheRetention(options.cacheRetention);
|
|
83
|
+
const additionalModelRequestFields = buildAdditionalModelRequestFields(model, options);
|
|
84
|
+
const thinking = additionalModelRequestFields?.thinking;
|
|
85
|
+
const sendsAdaptiveThinking = thinking !== null && typeof thinking === "object" && thinking.type === "adaptive";
|
|
65
86
|
let commandInput = {
|
|
66
87
|
modelId: model.id,
|
|
67
88
|
messages: convertMessages(context, model, cacheRetention),
|
|
68
89
|
system: buildSystemPrompt(context.systemPrompt, model, cacheRetention),
|
|
69
90
|
inferenceConfig: {
|
|
70
91
|
...options.maxTokens !== void 0 && { maxTokens: options.maxTokens },
|
|
71
|
-
...options.temperature !== void 0 && { temperature: options.temperature }
|
|
92
|
+
...options.temperature !== void 0 && !sendsAdaptiveThinking && { temperature: options.temperature }
|
|
72
93
|
},
|
|
73
|
-
toolConfig: convertToolConfig(context.tools, options.toolChoice),
|
|
74
|
-
additionalModelRequestFields
|
|
94
|
+
toolConfig: convertToolConfig(context.tools, fable5 ? normalizeFableToolChoice(options.toolChoice) : options.toolChoice),
|
|
95
|
+
additionalModelRequestFields,
|
|
96
|
+
...fable5 ? { additionalModelResponseFieldPaths: ["/stop_details"] } : {},
|
|
75
97
|
...options.requestMetadata !== void 0 && { requestMetadata: options.requestMetadata }
|
|
76
98
|
};
|
|
77
99
|
const nextCommandInput = await options?.onPayload?.(commandInput, model);
|
|
@@ -86,24 +108,30 @@ const streamBedrock = (model, context, options = {}) => {
|
|
|
86
108
|
headers: responseHeaders
|
|
87
109
|
}, model);
|
|
88
110
|
}
|
|
111
|
+
let sawMessageStop = false;
|
|
89
112
|
for await (const item of response.stream) if (item.messageStart) {
|
|
90
113
|
if (item.messageStart.role !== ConversationRole.ASSISTANT) throw new Error("Unexpected assistant message start but got user message start instead");
|
|
91
|
-
|
|
114
|
+
eventSink.push({
|
|
92
115
|
type: "start",
|
|
93
116
|
partial: output
|
|
94
117
|
});
|
|
95
|
-
} else if (item.contentBlockStart) handleContentBlockStart(item.contentBlockStart, blocks, output,
|
|
96
|
-
else if (item.contentBlockDelta) handleContentBlockDelta(item.contentBlockDelta, blocks, output,
|
|
97
|
-
else if (item.contentBlockStop) handleContentBlockStop(item.contentBlockStop, blocks, output,
|
|
98
|
-
else if (item.messageStop)
|
|
99
|
-
|
|
118
|
+
} else if (item.contentBlockStart) handleContentBlockStart(item.contentBlockStart, blocks, output, eventSink);
|
|
119
|
+
else if (item.contentBlockDelta) handleContentBlockDelta(item.contentBlockDelta, blocks, output, eventSink);
|
|
120
|
+
else if (item.contentBlockStop) handleContentBlockStop(item.contentBlockStop, blocks, output, eventSink);
|
|
121
|
+
else if (item.messageStop) {
|
|
122
|
+
sawMessageStop = true;
|
|
123
|
+
if (item.messageStop.stopReason === "refusal") applyAnthropicRefusal(output, readBedrockStopDetails(item.messageStop.additionalModelResponseFields), model.provider);
|
|
124
|
+
else output.stopReason = mapStopReason(item.messageStop.stopReason);
|
|
125
|
+
} else if (item.metadata) handleMetadata(item.metadata, model, output);
|
|
100
126
|
else if (item.internalServerException) throw item.internalServerException;
|
|
101
127
|
else if (item.modelStreamErrorException) throw item.modelStreamErrorException;
|
|
102
128
|
else if (item.validationException) throw item.validationException;
|
|
103
129
|
else if (item.throttlingException) throw item.throttlingException;
|
|
104
130
|
else if (item.serviceUnavailableException) throw item.serviceUnavailableException;
|
|
131
|
+
if (refusalBuffer && !sawMessageStop) throw new Error("Bedrock stream ended before messageStop");
|
|
105
132
|
if (options.signal?.aborted) throw new Error("Request was aborted");
|
|
106
|
-
if (output.stopReason === "error" || output.stopReason === "aborted") throw new Error("An unknown error occurred");
|
|
133
|
+
if (output.stopReason === "error" || output.stopReason === "aborted") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
134
|
+
refusalBuffer?.flush();
|
|
107
135
|
stream.push({
|
|
108
136
|
type: "done",
|
|
109
137
|
reason: output.stopReason,
|
|
@@ -115,6 +143,10 @@ const streamBedrock = (model, context, options = {}) => {
|
|
|
115
143
|
delete block.index;
|
|
116
144
|
delete block.partialJson;
|
|
117
145
|
}
|
|
146
|
+
if (refusalBuffer) {
|
|
147
|
+
refusalBuffer.discard();
|
|
148
|
+
output.content = [];
|
|
149
|
+
}
|
|
118
150
|
output.stopReason = options.signal?.aborted ? "aborted" : "error";
|
|
119
151
|
output.errorMessage = formatBedrockError(error);
|
|
120
152
|
stream.push({
|
|
@@ -153,20 +185,29 @@ function formatBedrockError(error) {
|
|
|
153
185
|
return message;
|
|
154
186
|
}
|
|
155
187
|
/** Stream a Bedrock Converse request from the generic OpenClaw stream options. */
|
|
156
|
-
const streamSimpleBedrock = (model, context, options) =>
|
|
188
|
+
const streamSimpleBedrock = (model, context, options) => streamBedrock(model, context, resolveSimpleBedrockOptions(model, options));
|
|
189
|
+
function resolveSimpleBedrockOptions(model, options) {
|
|
157
190
|
const base = buildBaseOptions(model, options, void 0);
|
|
158
|
-
if (
|
|
191
|
+
if (usesClaudeFable5BedrockContract(model)) return {
|
|
159
192
|
...base,
|
|
160
|
-
reasoning:
|
|
161
|
-
|
|
193
|
+
reasoning: options?.reasoning ?? "high",
|
|
194
|
+
thinkingBudgets: options?.thinkingBudgets
|
|
195
|
+
};
|
|
196
|
+
if (!options?.reasoning) {
|
|
197
|
+
const reasoning = isAnthropicClaudeModel(model) && requiresMandatoryAdaptiveThinking(model) ? "high" : void 0;
|
|
198
|
+
return {
|
|
199
|
+
...base,
|
|
200
|
+
reasoning
|
|
201
|
+
};
|
|
202
|
+
}
|
|
162
203
|
if (isAnthropicClaudeModel(model)) {
|
|
163
|
-
if (supportsAdaptiveThinking(model
|
|
204
|
+
if (supportsAdaptiveThinking(model)) return {
|
|
164
205
|
...base,
|
|
165
206
|
reasoning: options.reasoning,
|
|
166
207
|
thinkingBudgets: options.thinkingBudgets
|
|
167
|
-
}
|
|
208
|
+
};
|
|
168
209
|
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
169
|
-
return
|
|
210
|
+
return {
|
|
170
211
|
...base,
|
|
171
212
|
maxTokens: adjusted.maxTokens,
|
|
172
213
|
reasoning: options.reasoning,
|
|
@@ -174,14 +215,14 @@ const streamSimpleBedrock = (model, context, options) => {
|
|
|
174
215
|
...options.thinkingBudgets,
|
|
175
216
|
[clampReasoning(options.reasoning)]: adjusted.thinkingBudget
|
|
176
217
|
}
|
|
177
|
-
}
|
|
218
|
+
};
|
|
178
219
|
}
|
|
179
|
-
return
|
|
220
|
+
return {
|
|
180
221
|
...base,
|
|
181
222
|
reasoning: options.reasoning,
|
|
182
223
|
thinkingBudgets: options.thinkingBudgets
|
|
183
|
-
}
|
|
184
|
-
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
185
226
|
function handleContentBlockStart(event, blocks, output, stream) {
|
|
186
227
|
const index = event.contentBlockIndex;
|
|
187
228
|
const start = event.start;
|
|
@@ -318,33 +359,43 @@ function handleContentBlockStop(event, blocks, output, stream) {
|
|
|
318
359
|
break;
|
|
319
360
|
}
|
|
320
361
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
function getModelMatchCandidates(modelId, modelName) {
|
|
327
|
-
return (modelName ? [modelId, modelName] : [modelId]).flatMap((value) => {
|
|
328
|
-
const lower = value.toLowerCase();
|
|
329
|
-
return [lower, lower.replace(/[\s_.:]+/g, "-")];
|
|
330
|
-
});
|
|
362
|
+
function resolveClaudeProfileNameModelId(modelName) {
|
|
363
|
+
const normalized = modelName?.trim().toLowerCase().replace(/[\s_.:]+/g, "-") ?? "";
|
|
364
|
+
if (!normalized.includes("claude")) return;
|
|
365
|
+
const family = /(?:fable-5|mythos-preview|opus-4-(?:6|7|8)|sonnet-4-6)(?:$|-)/.exec(normalized)?.[0];
|
|
366
|
+
return family ? `claude-${family.replace(/-$/, "")}` : void 0;
|
|
331
367
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
368
|
+
function isClaudeMythosPreviewModelId(modelId) {
|
|
369
|
+
return /(?:^|-)claude-mythos-preview(?=$|[^a-z0-9])/.test(modelId?.trim().toLowerCase().replace(/[\s_.:]+/g, "-") ?? "");
|
|
370
|
+
}
|
|
371
|
+
/** Check canonical metadata and profile names for adaptive Claude support. */
|
|
372
|
+
function supportsAdaptiveThinking(model) {
|
|
373
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
374
|
+
return supportsClaudeAdaptiveThinking(model) || supportsClaudeAdaptiveThinking({ id: profileModelId }) || isClaudeMythosPreviewModelId(resolveClaudeModelIdentity(model)) || isClaudeMythosPreviewModelId(profileModelId);
|
|
375
|
+
}
|
|
376
|
+
function requiresMandatoryAdaptiveThinking(model) {
|
|
377
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
378
|
+
return isClaudeMythosPreviewModelId(resolveClaudeModelIdentity(model)) || isClaudeMythosPreviewModelId(profileModelId);
|
|
334
379
|
}
|
|
335
380
|
function supportsNativeXhighEffort(model) {
|
|
336
|
-
|
|
381
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
382
|
+
return supportsClaudeNativeXhighEffort(model) || supportsClaudeNativeXhighEffort({ id: profileModelId });
|
|
383
|
+
}
|
|
384
|
+
function supportsNativeMaxEffort(model) {
|
|
385
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
386
|
+
return supportsBedrockNativeMaxEffort(model.id, model.params) || supportsBedrockNativeMaxEffort(profileModelId ?? "");
|
|
337
387
|
}
|
|
338
388
|
function mapThinkingLevelToEffort(model, level) {
|
|
339
|
-
if (level === "xhigh" && supportsNativeXhighEffort(model)) return "xhigh";
|
|
340
389
|
const mapped = level ? model.thinkingLevelMap?.[level] : void 0;
|
|
341
390
|
if (typeof mapped === "string") return mapped;
|
|
391
|
+
if ((level === "xhigh" || level === "max") && mapped === null) return "high";
|
|
342
392
|
switch (level) {
|
|
343
393
|
case "minimal":
|
|
344
394
|
case "low": return "low";
|
|
345
395
|
case "medium": return "medium";
|
|
346
396
|
case "high": return "high";
|
|
347
|
-
case "
|
|
397
|
+
case "xhigh": return supportsNativeXhighEffort(model) ? "xhigh" : "high";
|
|
398
|
+
case "max": return supportsNativeMaxEffort(model) ? "max" : "high";
|
|
348
399
|
default: return "high";
|
|
349
400
|
}
|
|
350
401
|
}
|
|
@@ -363,12 +414,14 @@ function resolveCacheRetention(cacheRetention) {
|
|
|
363
414
|
* whose ARNs don't contain the model name.
|
|
364
415
|
*/
|
|
365
416
|
function isAnthropicClaudeModel(model) {
|
|
417
|
+
if (usesClaudeFable5BedrockContract(model)) return true;
|
|
418
|
+
if (resolveClaudeModelIdentity(model).startsWith("claude-")) return true;
|
|
366
419
|
const id = model.id.toLowerCase();
|
|
367
420
|
const name = model.name?.toLowerCase() ?? "";
|
|
368
421
|
return id.includes("anthropic.claude") || id.includes("anthropic/claude") || name.includes("anthropic.claude") || name.includes("anthropic/claude") || name.includes("claude");
|
|
369
422
|
}
|
|
370
423
|
function supportsPromptCaching(model) {
|
|
371
|
-
return supportsBedrockPromptCaching(model.id, model.name);
|
|
424
|
+
return usesClaudeFable5BedrockContract(model) || supportsBedrockPromptCaching(model.id, model.name) || supportsBedrockPromptCaching(resolveClaudeModelIdentity(model), model.name);
|
|
372
425
|
}
|
|
373
426
|
/**
|
|
374
427
|
* Check if the model supports thinking signatures in reasoningContent.
|
|
@@ -434,15 +487,22 @@ function convertMessages(context, model, cacheRetention) {
|
|
|
434
487
|
input: c.arguments
|
|
435
488
|
} });
|
|
436
489
|
break;
|
|
437
|
-
case "thinking":
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
490
|
+
case "thinking": {
|
|
491
|
+
const thinkingSignature = c.thinkingSignature;
|
|
492
|
+
const normalizedThinkingSignature = thinkingSignature?.trim();
|
|
493
|
+
const supportsSignature = supportsThinkingSignature(model);
|
|
494
|
+
const hasNativeThinkingSignature = supportsSignature && Boolean(normalizedThinkingSignature) && normalizedThinkingSignature !== "reasoning_content";
|
|
495
|
+
if (c.thinking.trim().length === 0 && !hasNativeThinkingSignature) continue;
|
|
496
|
+
if (supportsSignature) {
|
|
497
|
+
if (normalizedThinkingSignature === "reasoning_content") continue;
|
|
498
|
+
if (!thinkingSignature || !normalizedThinkingSignature) contentBlocks.push({ text: sanitizeSurrogates(c.thinking) });
|
|
499
|
+
else contentBlocks.push({ reasoningContent: { reasoningText: {
|
|
500
|
+
text: c.thinking,
|
|
501
|
+
signature: thinkingSignature
|
|
502
|
+
} } });
|
|
503
|
+
} else contentBlocks.push({ text: sanitizeSurrogates(c.thinking) });
|
|
445
504
|
break;
|
|
505
|
+
}
|
|
446
506
|
default: continue;
|
|
447
507
|
}
|
|
448
508
|
if (contentBlocks.length === 0) continue;
|
|
@@ -548,10 +608,10 @@ function isGovCloudBedrockTarget(model, options) {
|
|
|
548
608
|
return modelId.startsWith("us-gov.") || modelId.startsWith("arn:aws-us-gov:");
|
|
549
609
|
}
|
|
550
610
|
function buildAdditionalModelRequestFields(model, options) {
|
|
551
|
-
if (!options.reasoning || !model.reasoning) return;
|
|
611
|
+
if (!options.reasoning || !model.reasoning && !usesClaudeFable5BedrockContract(model) && !supportsAdaptiveThinking(model)) return;
|
|
552
612
|
if (isAnthropicClaudeModel(model)) {
|
|
553
613
|
const display = isGovCloudBedrockTarget(model, options) ? void 0 : options.thinkingDisplay ?? "summarized";
|
|
554
|
-
const result = supportsAdaptiveThinking(model
|
|
614
|
+
const result = supportsAdaptiveThinking(model) ? {
|
|
555
615
|
thinking: {
|
|
556
616
|
type: "adaptive",
|
|
557
617
|
...display !== void 0 ? { display } : {}
|
|
@@ -573,7 +633,7 @@ function buildAdditionalModelRequestFields(model, options) {
|
|
|
573
633
|
...display !== void 0 ? { display } : {}
|
|
574
634
|
} };
|
|
575
635
|
})();
|
|
576
|
-
if (!supportsAdaptiveThinking(model
|
|
636
|
+
if (!supportsAdaptiveThinking(model) && (options.interleavedThinking ?? true)) result.anthropic_beta = ["interleaved-thinking-2025-05-14"];
|
|
577
637
|
return result;
|
|
578
638
|
}
|
|
579
639
|
}
|
|
@@ -605,10 +665,12 @@ function createImageBlock(mimeType, data) {
|
|
|
605
665
|
}
|
|
606
666
|
/** Test-only hooks for Bedrock runtime conversion and endpoint policy. */
|
|
607
667
|
const testing = {
|
|
668
|
+
buildAdditionalModelRequestFields,
|
|
608
669
|
convertMessages,
|
|
609
670
|
getConfiguredBedrockRegion,
|
|
610
671
|
hasConfiguredBedrockProfile,
|
|
611
672
|
mapThinkingLevelToEffort,
|
|
673
|
+
resolveSimpleBedrockOptions,
|
|
612
674
|
shouldUseExplicitBedrockEndpoint
|
|
613
675
|
};
|
|
614
676
|
//#endregion
|