@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 43 lines 1.62 KB
Raw
1 /**
2 * Cross-region inference profile geo prefixes. A model id beginning with one
3 * of these (e.g. `us.amazon.nova-micro-v1:0`) is a system-defined inference
4 * profile id, not a foundation-model id.
5 */
6 const INFERENCE_PROFILE_GEO_PREFIXES = new Set([
7 "us",
8 "us-gov",
9 "eu",
10 "apac",
11 "jp",
12 "au",
13 "global",
14 ]);
15
16 /**
17 * Resolve the IAM policy `Resource` ARNs required to invoke a Bedrock model.
18 *
19 * Accepts any of the model reference forms `Converse`/`InvokeModel` accept:
20 *
21 * - a foundation-model id (`anthropic.claude-sonnet-4-20250514-v1:0`) —
22 * resolves to `arn:aws:bedrock:{region}::foundation-model/{modelId}`
23 * - a cross-region inference profile id (`us.amazon.nova-micro-v1:0`) —
24 * resolves to the account's inference-profile ARN *plus* the underlying
25 * foundation-model ARN in every region the profile can route to
26 * (`arn:aws:bedrock:*::foundation-model/{baseModelId}`), which Bedrock
27 * requires for cross-region invocation
28 * - a full ARN (foundation model, inference profile, application inference
29 * profile, imported/custom model, or prompt ARN) — passed through as-is
30 */
31 export const bedrockModelArns = (region: string, accountId: string, modelId: string): string[] => {
32 if (modelId.startsWith("arn:")) {
33 return [modelId];
34 }
35 const geoPrefix = modelId.split(".", 1)[0];
36 if (geoPrefix && INFERENCE_PROFILE_GEO_PREFIXES.has(geoPrefix)) {
37 return [
38 `arn:aws:bedrock:${region}:${accountId}:inference-profile/${modelId}`,
39 `arn:aws:bedrock:*::foundation-model/${modelId.slice(geoPrefix.length + 1)}`,
40 ];
41 }
42 return [`arn:aws:bedrock:${region}::foundation-model/${modelId}`];
43 };