Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class AwsBedrockProvider extends BaseLLMProvider {

return (
models
?.filter((m) => m.modelId && /^anthropic.claude-[a-z0-9\-]+(:\d+)$/g.test(m.modelId))
?.filter((m) => m.modelId && /^anthropic.claude-[a-z0-9-]+(:\d+)$/g.test(m.modelId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Escape the dot in anthropic.claude and drop the g flag; also remove the unnecessary capturing group

  • . matches any character; the pattern anthropic.claude will also match strings like anthropicXclaude. Escape the dot to ensure we only match the literal ..
  • The global g flag is unnecessary with .test() and can be a footgun when a RegExp instance is reused; remove it.
  • The parentheses around :\d+ don’t serve a purpose (no back-reference); remove them.

Apply this minimal change in-place:

-?.filter((m) => m.modelId && /^anthropic.claude-[a-z0-9-]+(:\d+)$/g.test(m.modelId))
+?.filter((m) => m.modelId && /^anthropic\.claude-[a-z0-9-]+:\d+$/.test(m.modelId))

Optional: hoist the regex to a top-level constant to avoid re-instantiation and improve readability:

+// Match Bedrock Anthropic Claude model ids like:
+// anthopic.claude-3-5-sonnet-20240620-v1:0
+const CLAUDE_MODEL_ID_RE = /^anthropic\.claude-[a-z0-9-]+:\d+$/;
...
-?.filter((m) => m.modelId && /^anthropic.claude-[a-z0-9-]+(:\d+)$/g.test(m.modelId))
+?.filter((m) => m.modelId && CLAUDE_MODEL_ID_RE.test(m.modelId))

You can verify the mismatch caused by the unescaped dot with this quick check:


🏁 Script executed:

#!/bin/bash
python - <<'PY'
import re
current = re.compile(r'^anthropic.claude-[a-z0-9-]+:\d+$')
fixed   = re.compile(r'^anthropic\.claude-[a-z0-9-]+:\d+$')

samples = [
  "anthropic.claude-3-5-sonnet-20240620-v1:0",   # valid
  "anthropic-claude-3-5-sonnet-20240620-v1:0",   # invalid, but matches current due to dot
  "anthropicXclaude-3-5-sonnet-20240620-v1:0",   # invalid, but matches current due to dot
]

for s in samples:
  print(f"{s:55} current={bool(current.fullmatch(s))}  fixed={bool(fixed.fullmatch(s))}")
PY

Length of output: 255


Fix regex to correctly match anthropic.claude model IDs

The current pattern allows invalid model IDs (e.g. anthropic-claude…, anthropicXclaude…) due to an unescaped dot, unnecessary global flag, and an unneeded capturing group. Update as follows:

• File: src/main/presenter/llmProviderPresenter/providers/awsBedrockProvider.ts
Line 76

Suggested in-place change:

-?.filter((m) => m.modelId && /^anthropic.claude-[a-z0-9-]+(:\d+)$/g.test(m.modelId))
+?.filter((m) => m.modelId && /^anthropic\.claude-[a-z0-9-]+:\d+$/.test(m.modelId))

Optional: hoist the regex to a constant for readability and to avoid re-instantiation:

// Matches Bedrock Anthropic Claude model IDs, e.g.:
// "anthropic.claude-3-5-sonnet-20240620-v1:0"
const CLAUDE_MODEL_ID_RE = /^anthropic\.claude-[a-z0-9-]+:\d+$/;

// …
?.filter((m) => m.modelId && CLAUDE_MODEL_ID_RE.test(m.modelId))
🤖 Prompt for AI Agents
In src/main/presenter/llmProviderPresenter/providers/awsBedrockProvider.ts
around line 76, the regex used to filter Anthropic Claude model IDs is incorrect
(unescaped dot, unnecessary global flag, and unneeded capturing group) causing
false positives; replace it with a stricter pattern that escapes the dot,
removes the /g flag and capturing group (e.g. use a regex matching
^anthropic\.claude-[a-z0-9-]+:\d+$) and update the filter to use that regex;
optionally hoist the regex to a named constant (CLAUDE_MODEL_ID_RE) for
readability and to avoid recreating it on every call.

?.filter((m) => m.modelLifecycle?.status === 'ACTIVE')
?.filter((m) => m.inferenceTypesSupported && m.inferenceTypesSupported.length > 0)
.map<MODEL_META>((m) => ({
Expand Down