@openclaw/amazon-bedrock-provider 2026.6.5-beta.6 → 2026.6.6-beta.1
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 +15 -13
- package/dist/provider-policy-api.js +1 -1
- package/dist/register.sync.runtime.js +56 -20
- package/dist/stream.runtime.js +87 -38
- package/dist/thinking-policy.js +65 -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,18 @@ 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 isKnownClaudeOpus47OrNewerModelId(modelId) {
|
|
99
|
-
return [modelId, modelId.replace(/^(?:us|eu|ap|apac|au|jp|global)\./, "")].some((candidate) => /(?:^|[/.:])anthropic\.claude-opus-4[.-][78](?:$|[-.:/])/i.test(candidate));
|
|
100
|
-
}
|
|
101
102
|
function resolveKnownThinkingLevelMap(modelId) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
103
|
+
return resolveBedrockNativeThinkingLevelMap(modelId);
|
|
104
|
+
}
|
|
105
|
+
function resolveKnownMaxTokens(modelId) {
|
|
106
|
+
return resolveClaudeFable5ModelIdentity({ id: modelId }) ? 128e3 : void 0;
|
|
107
107
|
}
|
|
108
108
|
const DEFAULT_COST = {
|
|
109
109
|
input: 0,
|
|
@@ -167,7 +167,7 @@ function mapInputModalities(summary) {
|
|
|
167
167
|
return Array.from(mapped);
|
|
168
168
|
}
|
|
169
169
|
function inferReasoningSupport(summary) {
|
|
170
|
-
if (
|
|
170
|
+
if (supportsClaudeAdaptiveThinking({ id: summary.modelId })) return true;
|
|
171
171
|
const haystack = normalizeLowercaseStringOrEmpty(`${summary.modelId ?? ""} ${summary.modelName ?? ""}`);
|
|
172
172
|
return haystack.includes("reasoning") || haystack.includes("thinking");
|
|
173
173
|
}
|
|
@@ -203,7 +203,7 @@ function toModelDefinition(summary, defaults) {
|
|
|
203
203
|
input: mapInputModalities(summary),
|
|
204
204
|
cost: DEFAULT_COST,
|
|
205
205
|
contextWindow: resolveKnownContextWindow(id) ?? defaults.contextWindow,
|
|
206
|
-
maxTokens: defaults.maxTokens,
|
|
206
|
+
maxTokens: resolveKnownMaxTokens(id) ?? defaults.maxTokens,
|
|
207
207
|
...thinkingLevelMap ? { thinkingLevelMap } : {}
|
|
208
208
|
};
|
|
209
209
|
}
|
|
@@ -275,15 +275,17 @@ function resolveInferenceProfiles(profiles, defaults, providerFilter, foundation
|
|
|
275
275
|
const baseModelId = resolveBaseModelId(profile);
|
|
276
276
|
const baseModel = baseModelId ? foundationModels.get(normalizeLowercaseStringOrEmpty(baseModelId)) : void 0;
|
|
277
277
|
const knownThinkingLevelMap = resolveKnownThinkingLevelMap(baseModelId ?? profile.inferenceProfileId);
|
|
278
|
+
const canonicalClaudeId = resolveClaudeModelIdentity({ id: baseModelId });
|
|
278
279
|
discovered.push({
|
|
279
280
|
id: profile.inferenceProfileId,
|
|
280
281
|
name: profile.inferenceProfileName?.trim() || profile.inferenceProfileId,
|
|
281
|
-
reasoning: baseModel?.reasoning ??
|
|
282
|
+
reasoning: baseModel?.reasoning ?? supportsClaudeAdaptiveThinking({ id: baseModelId ?? profile.inferenceProfileId }),
|
|
282
283
|
input: baseModel?.input ?? ["text"],
|
|
283
284
|
cost: baseModel?.cost ?? DEFAULT_COST,
|
|
284
285
|
contextWindow: baseModel?.contextWindow ?? resolveKnownContextWindow(baseModelId ?? profile.inferenceProfileId ?? "") ?? defaults.contextWindow,
|
|
285
|
-
maxTokens: baseModel?.maxTokens ?? defaults.maxTokens,
|
|
286
|
-
...baseModel?.thinkingLevelMap || knownThinkingLevelMap ? { thinkingLevelMap: baseModel?.thinkingLevelMap ?? knownThinkingLevelMap } : {}
|
|
286
|
+
maxTokens: baseModel?.maxTokens ?? resolveKnownMaxTokens(baseModelId ?? profile.inferenceProfileId) ?? defaults.maxTokens,
|
|
287
|
+
...baseModel?.thinkingLevelMap || knownThinkingLevelMap ? { thinkingLevelMap: baseModel?.thinkingLevelMap ?? knownThinkingLevelMap } : {},
|
|
288
|
+
...canonicalClaudeId.startsWith("claude-") ? { params: { canonicalModelId: canonicalClaudeId } } : {}
|
|
287
289
|
});
|
|
288
290
|
}
|
|
289
291
|
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 { 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,49 @@ 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;
|
|
327
|
+
const shouldPatchMaxThinking = supportsNativeMax && thinkingLevel === "max";
|
|
292
328
|
const heuristicMatch = needsCachePointInjection(modelId);
|
|
293
329
|
if (!region && !mayNeedCacheInjection && !shouldOmitTemperature && !shouldPatchMaxThinking) return createAwsCredentialRefreshStreamWrapper(wrapped);
|
|
294
330
|
const underlying = wrapped ?? streamFn;
|
|
295
331
|
if (!underlying) return wrapped;
|
|
296
332
|
return (streamModel, context, options) => {
|
|
297
|
-
const merged =
|
|
333
|
+
const merged = omitUnsupportedClaudeTemperature(modelRef, Object.assign({}, options, region ? { region } : {}));
|
|
298
334
|
const originalOnPayload = merged.onPayload;
|
|
299
335
|
if (!mayNeedCacheInjection) return underlying(streamModel, context, withAwsCredentialRefreshOnPayload({
|
|
300
336
|
...merged,
|
|
301
337
|
...shouldPatchMaxThinking ? { onPayload: (payload, payloadModel) => {
|
|
302
338
|
if (payload && typeof payload === "object") {
|
|
303
339
|
const payloadRecord = payload;
|
|
304
|
-
|
|
305
|
-
|
|
340
|
+
patchMaxThinkingEffort(payloadRecord);
|
|
341
|
+
omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
306
342
|
}
|
|
307
343
|
return originalOnPayload?.(payload, payloadModel);
|
|
308
344
|
} } : {}
|
|
@@ -316,10 +352,10 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
316
352
|
if (payload && typeof payload === "object") {
|
|
317
353
|
const payloadRecord = payload;
|
|
318
354
|
injectBedrockCachePoints(payloadRecord, cacheRetention);
|
|
319
|
-
if (shouldPatchMaxThinking)
|
|
320
|
-
if (shouldOmitTemperature)
|
|
355
|
+
if (shouldPatchMaxThinking) patchMaxThinkingEffort(payloadRecord);
|
|
356
|
+
if (shouldOmitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
321
357
|
else if (mayNeedTemperatureTrait) {
|
|
322
|
-
if ((await resolveAppProfileTraits(modelId, region)).omitTemperature)
|
|
358
|
+
if ((await resolveAppProfileTraits(modelId, region)).omitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
323
359
|
}
|
|
324
360
|
}
|
|
325
361
|
return originalOnPayload?.(payload, payloadModel);
|
|
@@ -333,8 +369,8 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
333
369
|
if (payload && typeof payload === "object") {
|
|
334
370
|
const payloadRecord = payload;
|
|
335
371
|
if (traits.cacheEligible) injectBedrockCachePoints(payloadRecord, cacheRetention);
|
|
336
|
-
if (shouldPatchMaxThinking)
|
|
337
|
-
if (traits.omitTemperature)
|
|
372
|
+
if (shouldPatchMaxThinking) patchMaxThinkingEffort(payloadRecord);
|
|
373
|
+
if (traits.omitTemperature) omitUnsupportedClaudePayloadTemperature(payloadRecord);
|
|
338
374
|
}
|
|
339
375
|
return originalOnPayload?.(payload, payloadModel);
|
|
340
376
|
}
|
|
@@ -347,7 +383,7 @@ function registerAmazonBedrockPlugin(api) {
|
|
|
347
383
|
if (/ModelNotReadyException/i.test(errorMessage)) return "overloaded";
|
|
348
384
|
if (deprecatedTemperatureValidationRe.test(errorMessage)) return "format";
|
|
349
385
|
},
|
|
350
|
-
resolveThinkingProfile: ({ modelId }) => resolveBedrockClaudeThinkingProfile(modelId)
|
|
386
|
+
resolveThinkingProfile: ({ modelId, params }) => resolveBedrockClaudeThinkingProfile(modelId, params)
|
|
351
387
|
});
|
|
352
388
|
}
|
|
353
389
|
//#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({
|
|
@@ -155,12 +187,17 @@ function formatBedrockError(error) {
|
|
|
155
187
|
/** Stream a Bedrock Converse request from the generic OpenClaw stream options. */
|
|
156
188
|
const streamSimpleBedrock = (model, context, options) => {
|
|
157
189
|
const base = buildBaseOptions(model, options, void 0);
|
|
190
|
+
if (usesClaudeFable5BedrockContract(model)) return streamBedrock(model, context, {
|
|
191
|
+
...base,
|
|
192
|
+
reasoning: options?.reasoning ?? "high",
|
|
193
|
+
thinkingBudgets: options?.thinkingBudgets
|
|
194
|
+
});
|
|
158
195
|
if (!options?.reasoning) return streamBedrock(model, context, {
|
|
159
196
|
...base,
|
|
160
197
|
reasoning: void 0
|
|
161
198
|
});
|
|
162
199
|
if (isAnthropicClaudeModel(model)) {
|
|
163
|
-
if (supportsAdaptiveThinking(model
|
|
200
|
+
if (supportsAdaptiveThinking(model)) return streamBedrock(model, context, {
|
|
164
201
|
...base,
|
|
165
202
|
reasoning: options.reasoning,
|
|
166
203
|
thinkingBudgets: options.thinkingBudgets
|
|
@@ -318,33 +355,36 @@ function handleContentBlockStop(event, blocks, output, stream) {
|
|
|
318
355
|
break;
|
|
319
356
|
}
|
|
320
357
|
}
|
|
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
|
-
});
|
|
358
|
+
function resolveClaudeProfileNameModelId(modelName) {
|
|
359
|
+
const normalized = modelName?.trim().toLowerCase().replace(/[\s_.:]+/g, "-") ?? "";
|
|
360
|
+
if (!normalized.includes("claude")) return;
|
|
361
|
+
const family = /(?:fable-5|opus-4-(?:6|7|8)|sonnet-4-6)(?:$|-)/.exec(normalized)?.[0];
|
|
362
|
+
return family ? `claude-${family.replace(/-$/, "")}` : void 0;
|
|
331
363
|
}
|
|
332
|
-
|
|
333
|
-
|
|
364
|
+
/** Check canonical metadata and profile names for adaptive Claude support. */
|
|
365
|
+
function supportsAdaptiveThinking(model) {
|
|
366
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
367
|
+
return supportsClaudeAdaptiveThinking(model) || supportsClaudeAdaptiveThinking({ id: profileModelId });
|
|
334
368
|
}
|
|
335
369
|
function supportsNativeXhighEffort(model) {
|
|
336
|
-
|
|
370
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
371
|
+
return supportsClaudeNativeXhighEffort(model) || supportsClaudeNativeXhighEffort({ id: profileModelId });
|
|
372
|
+
}
|
|
373
|
+
function supportsNativeMaxEffort(model) {
|
|
374
|
+
const profileModelId = resolveClaudeProfileNameModelId(model.name);
|
|
375
|
+
return supportsBedrockNativeMaxEffort(model.id, model.params) || supportsBedrockNativeMaxEffort(profileModelId ?? "");
|
|
337
376
|
}
|
|
338
377
|
function mapThinkingLevelToEffort(model, level) {
|
|
339
|
-
if (level === "xhigh" && supportsNativeXhighEffort(model)) return "xhigh";
|
|
340
378
|
const mapped = level ? model.thinkingLevelMap?.[level] : void 0;
|
|
341
379
|
if (typeof mapped === "string") return mapped;
|
|
380
|
+
if ((level === "xhigh" || level === "max") && mapped === null) return "high";
|
|
342
381
|
switch (level) {
|
|
343
382
|
case "minimal":
|
|
344
383
|
case "low": return "low";
|
|
345
384
|
case "medium": return "medium";
|
|
346
385
|
case "high": return "high";
|
|
347
|
-
case "
|
|
386
|
+
case "xhigh": return supportsNativeXhighEffort(model) ? "xhigh" : "high";
|
|
387
|
+
case "max": return supportsNativeMaxEffort(model) ? "max" : "high";
|
|
348
388
|
default: return "high";
|
|
349
389
|
}
|
|
350
390
|
}
|
|
@@ -363,12 +403,14 @@ function resolveCacheRetention(cacheRetention) {
|
|
|
363
403
|
* whose ARNs don't contain the model name.
|
|
364
404
|
*/
|
|
365
405
|
function isAnthropicClaudeModel(model) {
|
|
406
|
+
if (usesClaudeFable5BedrockContract(model)) return true;
|
|
407
|
+
if (resolveClaudeModelIdentity(model).startsWith("claude-")) return true;
|
|
366
408
|
const id = model.id.toLowerCase();
|
|
367
409
|
const name = model.name?.toLowerCase() ?? "";
|
|
368
410
|
return id.includes("anthropic.claude") || id.includes("anthropic/claude") || name.includes("anthropic.claude") || name.includes("anthropic/claude") || name.includes("claude");
|
|
369
411
|
}
|
|
370
412
|
function supportsPromptCaching(model) {
|
|
371
|
-
return supportsBedrockPromptCaching(model.id, model.name);
|
|
413
|
+
return usesClaudeFable5BedrockContract(model) || supportsBedrockPromptCaching(model.id, model.name) || supportsBedrockPromptCaching(resolveClaudeModelIdentity(model), model.name);
|
|
372
414
|
}
|
|
373
415
|
/**
|
|
374
416
|
* Check if the model supports thinking signatures in reasoningContent.
|
|
@@ -434,15 +476,22 @@ function convertMessages(context, model, cacheRetention) {
|
|
|
434
476
|
input: c.arguments
|
|
435
477
|
} });
|
|
436
478
|
break;
|
|
437
|
-
case "thinking":
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
479
|
+
case "thinking": {
|
|
480
|
+
const thinkingSignature = c.thinkingSignature;
|
|
481
|
+
const normalizedThinkingSignature = thinkingSignature?.trim();
|
|
482
|
+
const supportsSignature = supportsThinkingSignature(model);
|
|
483
|
+
const hasNativeThinkingSignature = supportsSignature && Boolean(normalizedThinkingSignature) && normalizedThinkingSignature !== "reasoning_content";
|
|
484
|
+
if (c.thinking.trim().length === 0 && !hasNativeThinkingSignature) continue;
|
|
485
|
+
if (supportsSignature) {
|
|
486
|
+
if (normalizedThinkingSignature === "reasoning_content") continue;
|
|
487
|
+
if (!thinkingSignature || !normalizedThinkingSignature) contentBlocks.push({ text: sanitizeSurrogates(c.thinking) });
|
|
488
|
+
else contentBlocks.push({ reasoningContent: { reasoningText: {
|
|
489
|
+
text: c.thinking,
|
|
490
|
+
signature: thinkingSignature
|
|
491
|
+
} } });
|
|
492
|
+
} else contentBlocks.push({ text: sanitizeSurrogates(c.thinking) });
|
|
445
493
|
break;
|
|
494
|
+
}
|
|
446
495
|
default: continue;
|
|
447
496
|
}
|
|
448
497
|
if (contentBlocks.length === 0) continue;
|
|
@@ -548,10 +597,10 @@ function isGovCloudBedrockTarget(model, options) {
|
|
|
548
597
|
return modelId.startsWith("us-gov.") || modelId.startsWith("arn:aws-us-gov:");
|
|
549
598
|
}
|
|
550
599
|
function buildAdditionalModelRequestFields(model, options) {
|
|
551
|
-
if (!options.reasoning || !model.reasoning) return;
|
|
600
|
+
if (!options.reasoning || !model.reasoning && !usesClaudeFable5BedrockContract(model) && !supportsAdaptiveThinking(model)) return;
|
|
552
601
|
if (isAnthropicClaudeModel(model)) {
|
|
553
602
|
const display = isGovCloudBedrockTarget(model, options) ? void 0 : options.thinkingDisplay ?? "summarized";
|
|
554
|
-
const result = supportsAdaptiveThinking(model
|
|
603
|
+
const result = supportsAdaptiveThinking(model) ? {
|
|
555
604
|
thinking: {
|
|
556
605
|
type: "adaptive",
|
|
557
606
|
...display !== void 0 ? { display } : {}
|
|
@@ -573,7 +622,7 @@ function buildAdditionalModelRequestFields(model, options) {
|
|
|
573
622
|
...display !== void 0 ? { display } : {}
|
|
574
623
|
} };
|
|
575
624
|
})();
|
|
576
|
-
if (!supportsAdaptiveThinking(model
|
|
625
|
+
if (!supportsAdaptiveThinking(model) && (options.interleavedThinking ?? true)) result.anthropic_beta = ["interleaved-thinking-2025-05-14"];
|
|
577
626
|
return result;
|
|
578
627
|
}
|
|
579
628
|
}
|
package/dist/thinking-policy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity } from "openclaw/plugin-sdk/provider-model-shared";
|
|
1
2
|
//#region extensions/amazon-bedrock/thinking-policy.ts
|
|
2
3
|
const BASE_CLAUDE_THINKING_LEVELS = [
|
|
3
4
|
{ id: "off" },
|
|
@@ -7,20 +8,69 @@ const BASE_CLAUDE_THINKING_LEVELS = [
|
|
|
7
8
|
{ id: "high" }
|
|
8
9
|
];
|
|
9
10
|
function isOpus48BedrockModelRef(modelRef) {
|
|
10
|
-
return /(?:^|[/.:])(?:(?:us|eu|ap|apac|au|jp|global)\.)?anthropic\.claude-opus-4[.-]8(?:$|[-.:/])/i.test(modelRef);
|
|
11
|
+
return /(?:^|[/.:])(?:(?:us|eu|ap|apac|au|jp|global)\.)?(?:anthropic\.)?claude-opus-4[.-]8(?:$|[-.:/])/i.test(modelRef);
|
|
12
|
+
}
|
|
13
|
+
function isOpus46BedrockModelRef(modelRef) {
|
|
14
|
+
return /(?:^|[/.:])(?:(?:us|eu|ap|apac|au|jp|global)\.)?(?:anthropic\.)?claude-opus-4[.-]6(?:$|[-.:/])/i.test(modelRef);
|
|
11
15
|
}
|
|
12
16
|
/** Return whether a Bedrock model ref names Claude Opus 4.7. */
|
|
13
17
|
function isOpus47BedrockModelRef(modelRef) {
|
|
14
|
-
return /(?:^|[/.:])(?:(?:us|eu|ap|apac|au|jp|global)\.)?anthropic\.claude-opus-4[.-]7(?:$|[-.:/])/i.test(modelRef);
|
|
18
|
+
return /(?:^|[/.:])(?:(?:us|eu|ap|apac|au|jp|global)\.)?(?:anthropic\.)?claude-opus-4[.-]7(?:$|[-.:/])/i.test(modelRef);
|
|
15
19
|
}
|
|
16
20
|
/** Return whether a Bedrock model ref names Claude Opus 4.7 or newer. */
|
|
17
21
|
function isOpus47OrNewerBedrockModelRef(modelRef) {
|
|
18
22
|
return isOpus47BedrockModelRef(modelRef) || isOpus48BedrockModelRef(modelRef);
|
|
19
23
|
}
|
|
24
|
+
/** Return whether a Bedrock Claude ref supports max effort. */
|
|
25
|
+
function supportsBedrockNativeMaxEffort(modelId, params) {
|
|
26
|
+
if (resolveClaudeFable5ModelIdentity({
|
|
27
|
+
id: modelId,
|
|
28
|
+
params
|
|
29
|
+
})) return true;
|
|
30
|
+
return [modelId, resolveClaudeModelIdentity({
|
|
31
|
+
id: modelId,
|
|
32
|
+
params
|
|
33
|
+
})].some((modelRef) => isOpus46BedrockModelRef(modelRef) || isOpus47OrNewerBedrockModelRef(modelRef));
|
|
34
|
+
}
|
|
35
|
+
/** Resolve route-specific native effort mappings for Bedrock Claude models. */
|
|
36
|
+
function resolveBedrockNativeThinkingLevelMap(modelId, params) {
|
|
37
|
+
const modelRef = {
|
|
38
|
+
id: modelId,
|
|
39
|
+
params
|
|
40
|
+
};
|
|
41
|
+
if (resolveClaudeFable5ModelIdentity(modelRef)) return {
|
|
42
|
+
off: "low",
|
|
43
|
+
minimal: "low",
|
|
44
|
+
xhigh: "xhigh",
|
|
45
|
+
max: "max"
|
|
46
|
+
};
|
|
47
|
+
if (!supportsBedrockNativeMaxEffort(modelId, params)) return;
|
|
48
|
+
return {
|
|
49
|
+
xhigh: [modelId, resolveClaudeModelIdentity(modelRef)].some(isOpus47OrNewerBedrockModelRef) ? "xhigh" : null,
|
|
50
|
+
max: "max"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
20
53
|
/** Resolve supported Claude thinking levels for a Bedrock model id. */
|
|
21
|
-
function resolveBedrockClaudeThinkingProfile(modelId) {
|
|
54
|
+
function resolveBedrockClaudeThinkingProfile(modelId, params) {
|
|
22
55
|
const trimmed = modelId.trim();
|
|
23
|
-
|
|
56
|
+
const modelRefs = [trimmed, resolveClaudeModelIdentity({
|
|
57
|
+
id: trimmed,
|
|
58
|
+
params
|
|
59
|
+
})];
|
|
60
|
+
if (resolveClaudeFable5ModelIdentity({
|
|
61
|
+
id: trimmed,
|
|
62
|
+
params
|
|
63
|
+
})) return {
|
|
64
|
+
levels: [
|
|
65
|
+
...BASE_CLAUDE_THINKING_LEVELS,
|
|
66
|
+
{ id: "xhigh" },
|
|
67
|
+
{ id: "adaptive" },
|
|
68
|
+
{ id: "max" }
|
|
69
|
+
],
|
|
70
|
+
defaultLevel: "high",
|
|
71
|
+
preserveWhenCatalogReasoningFalse: true
|
|
72
|
+
};
|
|
73
|
+
if (modelRefs.some(isOpus48BedrockModelRef)) return {
|
|
24
74
|
levels: [
|
|
25
75
|
...BASE_CLAUDE_THINKING_LEVELS,
|
|
26
76
|
{ id: "xhigh" },
|
|
@@ -29,7 +79,7 @@ function resolveBedrockClaudeThinkingProfile(modelId) {
|
|
|
29
79
|
],
|
|
30
80
|
defaultLevel: "off"
|
|
31
81
|
};
|
|
32
|
-
if (isOpus47BedrockModelRef
|
|
82
|
+
if (modelRefs.some(isOpus47BedrockModelRef)) return {
|
|
33
83
|
levels: [
|
|
34
84
|
...BASE_CLAUDE_THINKING_LEVELS,
|
|
35
85
|
{ id: "xhigh" },
|
|
@@ -38,11 +88,19 @@ function resolveBedrockClaudeThinkingProfile(modelId) {
|
|
|
38
88
|
],
|
|
39
89
|
defaultLevel: "off"
|
|
40
90
|
};
|
|
41
|
-
if (
|
|
91
|
+
if (modelRefs.some(isOpus46BedrockModelRef)) return {
|
|
92
|
+
levels: [
|
|
93
|
+
...BASE_CLAUDE_THINKING_LEVELS,
|
|
94
|
+
{ id: "adaptive" },
|
|
95
|
+
{ id: "max" }
|
|
96
|
+
],
|
|
97
|
+
defaultLevel: "adaptive"
|
|
98
|
+
};
|
|
99
|
+
if (modelRefs.some((modelRef) => /claude-sonnet-4(?:\.|-)6(?:$|[-.])/i.test(modelRef))) return {
|
|
42
100
|
levels: [...BASE_CLAUDE_THINKING_LEVELS, { id: "adaptive" }],
|
|
43
101
|
defaultLevel: "adaptive"
|
|
44
102
|
};
|
|
45
103
|
return { levels: BASE_CLAUDE_THINKING_LEVELS };
|
|
46
104
|
}
|
|
47
105
|
//#endregion
|
|
48
|
-
export { isOpus47BedrockModelRef, isOpus47OrNewerBedrockModelRef, resolveBedrockClaudeThinkingProfile };
|
|
106
|
+
export { isOpus47BedrockModelRef, isOpus47OrNewerBedrockModelRef, resolveBedrockClaudeThinkingProfile, resolveBedrockNativeThinkingLevelMap, supportsBedrockNativeMaxEffort };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/credential-provider-env",
|
|
3
|
-
"version": "3.972.
|
|
3
|
+
"version": "3.972.44",
|
|
4
4
|
"description": "AWS credential provider that sources credentials from known environment variables",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"author": {
|
|
24
24
|
"name": "AWS SDK for JavaScript Team",
|
|
25
|
-
"url": "https://aws.amazon.com/javascript/"
|
|
25
|
+
"url": "https://aws.amazon.com/sdk-for-javascript/"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aws-sdk/core": "^3.974.
|
|
30
|
-
"@aws-sdk/types": "^3.973.
|
|
31
|
-
"@smithy/core": "^3.24.
|
|
32
|
-
"@smithy/types": "^4.14.
|
|
29
|
+
"@aws-sdk/core": "^3.974.18",
|
|
30
|
+
"@aws-sdk/types": "^3.973.11",
|
|
31
|
+
"@smithy/core": "^3.24.6",
|
|
32
|
+
"@smithy/types": "^4.14.3",
|
|
33
33
|
"tslib": "^2.6.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|