@mastra/code-sdk 1.7.1 → 1.7.2-alpha.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/agents/prompts/agent-instructions.d.ts +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -1
- package/dist/agents/prompts/agent-instructions.js +39 -14
- package/dist/agents/prompts/agent-instructions.js.map +1 -1
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -1
- package/dist/providers/amazon-bedrock-gateway.js +3 -12
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -1
- package/package.json +12 -12
|
@@ -41,6 +41,7 @@ export declare function createGitRefReminderReader(projectPath: string, ref: str
|
|
|
41
41
|
pathExists: (path: string) => boolean;
|
|
42
42
|
isDirectory: (path: string) => boolean;
|
|
43
43
|
readFile: (path: string) => string;
|
|
44
|
+
getPathIdentity: (path: string) => string;
|
|
44
45
|
};
|
|
45
46
|
/**
|
|
46
47
|
* Load all agent instruction files from global and project locations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-instructions.d.ts","sourceRoot":"","sources":["../../../src/agents/prompts/agent-instructions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;
|
|
1
|
+
{"version":3,"file":"agent-instructions.d.ts","sourceRoot":"","sources":["../../../src/agents/prompts/agent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ED,kFAAkF;AAClF,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAIzE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAM5E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_CONFIG_DIR } from "../../constants.js";
|
|
2
|
-
import { existsSync, readFileSync, statSync } from "fs";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "fs";
|
|
3
3
|
import { homedir } from "os";
|
|
4
|
-
import { isAbsolute, join, normalize, relative, sep } from "path";
|
|
4
|
+
import { dirname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
5
5
|
import { execFileSync } from "child_process";
|
|
6
6
|
//#region src/agents/prompts/agent-instructions.ts
|
|
7
7
|
/**
|
|
@@ -24,6 +24,28 @@ const fsInstructionReader = {
|
|
|
24
24
|
exists: (path) => existsSync(path),
|
|
25
25
|
read: (path) => readFileSync(path, "utf-8")
|
|
26
26
|
};
|
|
27
|
+
function realpathOrResolved(path) {
|
|
28
|
+
try {
|
|
29
|
+
return realpathSync(path);
|
|
30
|
+
} catch {
|
|
31
|
+
return resolve(path);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function createProjectPathResolver(projectPath) {
|
|
35
|
+
const canonicalRoot = realpathOrResolved(projectPath);
|
|
36
|
+
return (path) => {
|
|
37
|
+
const rel = relative(projectPath, path);
|
|
38
|
+
if (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join("/");
|
|
39
|
+
let ancestor = resolve(path);
|
|
40
|
+
let projectRelativePath = null;
|
|
41
|
+
while (true) {
|
|
42
|
+
if (realpathOrResolved(ancestor) === canonicalRoot) projectRelativePath = relative(ancestor, path).split(sep).join("/");
|
|
43
|
+
const parent = dirname(ancestor);
|
|
44
|
+
if (parent === ancestor) return projectRelativePath;
|
|
45
|
+
ancestor = parent;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
27
49
|
/**
|
|
28
50
|
* Create a reader that serves instruction files from a git ref instead of the
|
|
29
51
|
* working tree. Paths are still addressed as working-tree paths under
|
|
@@ -33,14 +55,10 @@ const fsInstructionReader = {
|
|
|
33
55
|
* failure (missing ref, missing file, no repo) reports the file as absent.
|
|
34
56
|
*/
|
|
35
57
|
function createGitRefInstructionReader(projectPath, ref) {
|
|
36
|
-
const toRelative = (
|
|
37
|
-
const rel = relative(projectPath, path);
|
|
38
|
-
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
39
|
-
return rel.split(sep).join("/");
|
|
40
|
-
};
|
|
58
|
+
const toRelative = createProjectPathResolver(projectPath);
|
|
41
59
|
const show = (path) => {
|
|
42
60
|
const rel = toRelative(path);
|
|
43
|
-
if (rel
|
|
61
|
+
if (!rel) return null;
|
|
44
62
|
for (const candidate of [`origin/${ref}`, ref]) try {
|
|
45
63
|
return execFileSync("git", [
|
|
46
64
|
"-C",
|
|
@@ -78,11 +96,8 @@ function createGitRefInstructionReader(projectPath, ref) {
|
|
|
78
96
|
*/
|
|
79
97
|
function createGitRefReminderReader(projectPath, ref) {
|
|
80
98
|
const gitReader = createGitRefInstructionReader(projectPath, ref);
|
|
81
|
-
const toRelative = (
|
|
82
|
-
|
|
83
|
-
if (rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
84
|
-
return rel.split(sep).join("/");
|
|
85
|
-
};
|
|
99
|
+
const toRelative = createProjectPathResolver(projectPath);
|
|
100
|
+
const canonicalRoot = realpathOrResolved(projectPath);
|
|
86
101
|
const objectType = (rel) => {
|
|
87
102
|
if (rel === "") return "tree";
|
|
88
103
|
for (const candidate of [`origin/${ref}`, ref]) try {
|
|
@@ -121,6 +136,10 @@ function createGitRefReminderReader(projectPath, ref) {
|
|
|
121
136
|
readFile: (path) => {
|
|
122
137
|
if (toRelative(path) === null) return readFileSync(path, "utf-8");
|
|
123
138
|
return gitReader.read(path);
|
|
139
|
+
},
|
|
140
|
+
getPathIdentity: (path) => {
|
|
141
|
+
const rel = toRelative(path);
|
|
142
|
+
return rel === null ? realpathOrResolved(path) : join(canonicalRoot, rel);
|
|
124
143
|
}
|
|
125
144
|
};
|
|
126
145
|
}
|
|
@@ -184,7 +203,13 @@ function loadAgentInstructions(projectPath, configDirName = DEFAULT_CONFIG_DIR,
|
|
|
184
203
|
return sources;
|
|
185
204
|
}
|
|
186
205
|
function getStaticallyLoadedInstructionPaths(projectPath, configDirName = DEFAULT_CONFIG_DIR, projectReader) {
|
|
187
|
-
|
|
206
|
+
const canonicalRoot = realpathOrResolved(projectPath);
|
|
207
|
+
return loadAgentInstructions(projectPath, configDirName, projectReader).flatMap((source) => {
|
|
208
|
+
const path = normalize(source.path);
|
|
209
|
+
if (source.scope !== "project") return [path];
|
|
210
|
+
const canonicalPath = join(canonicalRoot, relative(projectPath, path));
|
|
211
|
+
return path === canonicalPath ? [path] : [path, canonicalPath];
|
|
212
|
+
});
|
|
188
213
|
}
|
|
189
214
|
/** Heading the agent-instructions block is introduced by in the system prompt. */
|
|
190
215
|
const AGENT_INSTRUCTIONS_HEADING = "# Agent Instructions";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-instructions.js","names":[],"sources":["../../../src/agents/prompts/agent-instructions.ts"],"sourcesContent":["/**\n * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).\n * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.\n */\n\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { isAbsolute, join, normalize, relative, sep } from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../../constants.js';\n\n// Filenames to check, in order of preference\nconst INSTRUCTION_FILES = ['AGENTS.md', 'CLAUDE.md'];\n\n// Locations to scan (relative to project root or home)\nconst PROJECT_LOCATIONS = [\n '', // project root\n '.claude',\n '.mastracode',\n];\n\nconst GLOBAL_LOCATIONS = ['.claude', '.mastracode', '.config/claude', '.config/mastracode'];\n\nexport interface InstructionSource {\n path: string;\n content: string;\n scope: 'global' | 'project';\n /** Git ref the content was read from, when not read off the working tree. */\n ref?: string;\n}\n\n/**\n * Reads project-scope instruction files. The default implementation reads the\n * working tree via `fs`; alternative readers can serve content from another\n * source (e.g. a trusted git ref) while keeping working-tree paths as the\n * addressing scheme.\n */\nexport interface InstructionFileReader {\n exists(path: string): boolean;\n read(path: string): string;\n /** Git ref backing this reader, recorded on the loaded sources. */\n ref?: string;\n}\n\nconst fsInstructionReader: InstructionFileReader = {\n exists: path => existsSync(path),\n read: path => readFileSync(path, 'utf-8'),\n};\n\n/**\n * Create a reader that serves instruction files from a git ref instead of the\n * working tree. Paths are still addressed as working-tree paths under\n * `projectPath`; content comes from `git show <ref>:<relpath>` so an untrusted\n * checkout (e.g. a PR branch under review) cannot influence what is loaded.\n * Tries `origin/<ref>` first (remote truth), then the local ref. Any git\n * failure (missing ref, missing file, no repo) reports the file as absent.\n */\nexport function createGitRefInstructionReader(projectPath: string, ref: string): InstructionFileReader {\n const toRelative = (path: string): string | null => {\n const rel = relative(projectPath, path);\n if (!rel || rel.startsWith('..') || isAbsolute(rel)) return null;\n return rel.split(sep).join('/');\n };\n const show = (path: string): string | null => {\n const rel = toRelative(path);\n if (rel === null) return null;\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'show', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n maxBuffer: 1024 * 1024,\n });\n } catch {\n // Ref or file missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n ref,\n exists: path => show(path) !== null,\n read: path => {\n const content = show(path);\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n };\n}\n\n/**\n * Reader for the reactive reminder channel (AgentsMDInjector) that serves\n * paths under `projectPath` from a trusted git ref. Paths outside the project\n * fall back to the operator machine's filesystem (those are trusted); paths\n * inside the project are only ever resolved against the ref, never the\n * working tree, so an untrusted checkout cannot feed content in.\n */\nexport function createGitRefReminderReader(\n projectPath: string,\n ref: string,\n): {\n pathExists: (path: string) => boolean;\n isDirectory: (path: string) => boolean;\n readFile: (path: string) => string;\n} {\n const gitReader = createGitRefInstructionReader(projectPath, ref);\n const toRelative = (path: string): string | null => {\n const rel = relative(projectPath, normalize(path));\n if (rel.startsWith('..') || isAbsolute(rel)) return null;\n return rel.split(sep).join('/');\n };\n const objectType = (rel: string): string | null => {\n if (rel === '') return 'tree'; // project root\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'cat-file', '-t', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim();\n } catch {\n // Ref or object missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n pathExists: path => {\n const rel = toRelative(path);\n if (rel === null) return existsSync(path);\n return objectType(rel) !== null;\n },\n isDirectory: path => {\n const rel = toRelative(path);\n if (rel === null) {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n }\n return objectType(rel) === 'tree';\n },\n readFile: path => {\n const rel = toRelative(path);\n if (rel === null) return readFileSync(path, 'utf-8');\n return gitReader.read(path);\n },\n };\n}\n\n/**\n * Find the first existing instruction file at a given base path.\n * Prefers AGENTS.md over CLAUDE.md.\n */\nfunction findInstructionFile(basePath: string, reader: InstructionFileReader = fsInstructionReader): string | null {\n for (const filename of INSTRUCTION_FILES) {\n const fullPath = join(basePath, filename);\n if (reader.exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Load all agent instruction files from global and project locations.\n * Returns an array of instruction sources, with global ones first.\n *\n * `projectReader` controls where project-scope content comes from (defaults to\n * the working tree). Global instructions read the operator machine's\n * filesystem, unless `skipGlobal` keeps them out entirely.\n */\nexport function loadAgentInstructions(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader: InstructionFileReader = fsInstructionReader,\n { skipGlobal = false }: { skipGlobal?: boolean } = {},\n): InstructionSource[] {\n const sources: InstructionSource[] = [];\n const home = homedir();\n\n // Derive location arrays from the base constants, substituting the config dir name\n const projectLocations = PROJECT_LOCATIONS.map(loc => (loc === '.mastracode' ? configDirName : loc));\n const globalLocations = skipGlobal\n ? []\n : GLOBAL_LOCATIONS.map(loc => {\n if (loc === '.mastracode') return configDirName;\n // XDG-style path (~/.config/<name>): strip the leading dot since the\n // .config/ prefix already signals a hidden/config directory.\n if (loc === '.config/mastracode') return '.config/' + configDirName.replace(/^\\./, '');\n return loc;\n });\n\n // Load global instructions first\n for (const location of globalLocations) {\n const basePath = join(home, location);\n const filePath = findInstructionFile(basePath);\n if (filePath) {\n try {\n const content = readFileSync(filePath, 'utf-8').trim();\n if (content) {\n sources.push({ path: filePath, content, scope: 'global' });\n break; // Only use first found global instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n // Load project instructions\n for (const location of projectLocations) {\n const basePath = location ? join(projectPath, location) : projectPath;\n const filePath = findInstructionFile(basePath, projectReader);\n if (filePath) {\n try {\n const content = projectReader.read(filePath).trim();\n if (content) {\n sources.push({\n path: filePath,\n content,\n scope: 'project',\n ...(projectReader.ref ? { ref: projectReader.ref } : {}),\n });\n break; // Only use first found project instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n return sources;\n}\n\nexport function getStaticallyLoadedInstructionPaths(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader?: InstructionFileReader,\n): string[] {\n return loadAgentInstructions(projectPath, configDirName, projectReader).map(source => normalize(source.path));\n}\n\n/** Heading the agent-instructions block is introduced by in the system prompt. */\nexport const AGENT_INSTRUCTIONS_HEADING = '# Agent Instructions';\n\n/**\n * Format a single instruction source as it appears in the system prompt.\n *\n * Exported so callers that attribute prompt cost per source (the `/context`\n * audit) measure the exact block that is sent rather than reconstructing it.\n */\nexport function formatInstructionSource(source: InstructionSource): string {\n const label = source.scope === 'global' ? 'Global' : 'Project';\n const origin = source.ref ? `${source.path} (at ref ${source.ref})` : source.path;\n return `<!-- ${label} instructions from ${origin} -->\\n${source.content}`;\n}\n\n/**\n * Format loaded instructions into a string for the system prompt.\n */\nexport function formatAgentInstructions(sources: InstructionSource[]): string {\n if (sources.length === 0) return '';\n\n const sections = sources.map(formatInstructionSource);\n\n return `\\n${AGENT_INSTRUCTIONS_HEADING}\\n\\n${sections.join('\\n\\n')}\\n`;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBAAoB,CAAC,aAAa,WAAW;AAGnD,MAAM,oBAAoB;CACxB;CACA;CACA;AACF;AAEA,MAAM,mBAAmB;CAAC;CAAW;CAAe;CAAkB;AAAoB;AAuB1F,MAAM,sBAA6C;CACjD,SAAQ,SAAQ,WAAW,IAAI;CAC/B,OAAM,SAAQ,aAAa,MAAM,OAAO;AAC1C;;;;;;;;;AAUA,SAAgB,8BAA8B,aAAqB,KAAoC;CACrG,MAAM,cAAc,SAAgC;EAClD,MAAM,MAAM,SAAS,aAAa,IAAI;EACtC,IAAI,CAAC,OAAO,IAAI,WAAW,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO;EAC5D,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;CAChC;CACA,MAAM,QAAQ,SAAgC;EAC5C,MAAM,MAAM,WAAW,IAAI;EAC3B,IAAI,QAAQ,MAAM,OAAO;EACzB,KAAK,MAAM,aAAa,CAAC,UAAU,OAAO,GAAG,GAC3C,IAAI;GACF,OAAO,aAAa,OAAO;IAAC;IAAM;IAAa;IAAQ,GAAG,UAAU,GAAG;GAAK,GAAG;IAC7E,UAAU;IACV,OAAO;KAAC;KAAU;KAAQ;IAAQ;IAClC,WAAW,OAAO;GACpB,CAAC;EACH,QAAQ,CAER;EAEF,OAAO;CACT;CACA,OAAO;EACL;E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,oBAChB,eACU;CACV,OAAO,sBAAsB,aAAa,eAAe,aAAa,CAAC,CAAC,KAAI,WAAU,UAAU,OAAO,IAAI,CAAC;AAC9G;;AAGA,MAAa,6BAA6B;;;;;;;AAQ1C,SAAgB,wBAAwB,QAAmC;CAGzE,OAAO,QAFO,OAAO,UAAU,WAAW,WAAW,UAEhC,qBADN,OAAO,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,IAAI,KAAK,OAAO,KAC5B,QAAQ,OAAO;AAClE;;;;AAKA,SAAgB,wBAAwB,SAAsC;CAC5E,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,WAAW,QAAQ,IAAI,uBAAuB;CAEpD,OAAO,KAAK,2BAA2B,MAAM,SAAS,KAAK,MAAM,EAAE;AACrE"}
|
|
1
|
+
{"version":3,"file":"agent-instructions.js","names":[],"sources":["../../../src/agents/prompts/agent-instructions.ts"],"sourcesContent":["/**\n * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).\n * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.\n */\n\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../../constants.js';\n\n// Filenames to check, in order of preference\nconst INSTRUCTION_FILES = ['AGENTS.md', 'CLAUDE.md'];\n\n// Locations to scan (relative to project root or home)\nconst PROJECT_LOCATIONS = [\n '', // project root\n '.claude',\n '.mastracode',\n];\n\nconst GLOBAL_LOCATIONS = ['.claude', '.mastracode', '.config/claude', '.config/mastracode'];\n\nexport interface InstructionSource {\n path: string;\n content: string;\n scope: 'global' | 'project';\n /** Git ref the content was read from, when not read off the working tree. */\n ref?: string;\n}\n\n/**\n * Reads project-scope instruction files. The default implementation reads the\n * working tree via `fs`; alternative readers can serve content from another\n * source (e.g. a trusted git ref) while keeping working-tree paths as the\n * addressing scheme.\n */\nexport interface InstructionFileReader {\n exists(path: string): boolean;\n read(path: string): string;\n /** Git ref backing this reader, recorded on the loaded sources. */\n ref?: string;\n}\n\nconst fsInstructionReader: InstructionFileReader = {\n exists: path => existsSync(path),\n read: path => readFileSync(path, 'utf-8'),\n};\n\nfunction realpathOrResolved(path: string): string {\n try {\n return realpathSync(path);\n } catch {\n return resolve(path);\n }\n}\n\nfunction createProjectPathResolver(projectPath: string): (path: string) => string | null {\n const canonicalRoot = realpathOrResolved(projectPath);\n return path => {\n const rel = relative(projectPath, path);\n if (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join('/');\n\n // Match an alias of the project root, not the target of a checkout-controlled\n // descendant symlink. Missing descendants must still resolve against the ref.\n let ancestor = resolve(path);\n let projectRelativePath: string | null = null;\n while (true) {\n if (realpathOrResolved(ancestor) === canonicalRoot) {\n projectRelativePath = relative(ancestor, path).split(sep).join('/');\n }\n const parent = dirname(ancestor);\n if (parent === ancestor) return projectRelativePath;\n ancestor = parent;\n }\n };\n}\n\n/**\n * Create a reader that serves instruction files from a git ref instead of the\n * working tree. Paths are still addressed as working-tree paths under\n * `projectPath`; content comes from `git show <ref>:<relpath>` so an untrusted\n * checkout (e.g. a PR branch under review) cannot influence what is loaded.\n * Tries `origin/<ref>` first (remote truth), then the local ref. Any git\n * failure (missing ref, missing file, no repo) reports the file as absent.\n */\nexport function createGitRefInstructionReader(projectPath: string, ref: string): InstructionFileReader {\n const toRelative = createProjectPathResolver(projectPath);\n const show = (path: string): string | null => {\n const rel = toRelative(path);\n if (!rel) return null;\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'show', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n maxBuffer: 1024 * 1024,\n });\n } catch {\n // Ref or file missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n ref,\n exists: path => show(path) !== null,\n read: path => {\n const content = show(path);\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n };\n}\n\n/**\n * Reader for the reactive reminder channel (AgentsMDInjector) that serves\n * paths under `projectPath` from a trusted git ref. Paths outside the project\n * fall back to the operator machine's filesystem (those are trusted); paths\n * inside the project are only ever resolved against the ref, never the\n * working tree, so an untrusted checkout cannot feed content in.\n */\nexport function createGitRefReminderReader(\n projectPath: string,\n ref: string,\n): {\n pathExists: (path: string) => boolean;\n isDirectory: (path: string) => boolean;\n readFile: (path: string) => string;\n getPathIdentity: (path: string) => string;\n} {\n const gitReader = createGitRefInstructionReader(projectPath, ref);\n const toRelative = createProjectPathResolver(projectPath);\n const canonicalRoot = realpathOrResolved(projectPath);\n const objectType = (rel: string): string | null => {\n if (rel === '') return 'tree'; // project root\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'cat-file', '-t', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim();\n } catch {\n // Ref or object missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n pathExists: path => {\n const rel = toRelative(path);\n if (rel === null) return existsSync(path);\n return objectType(rel) !== null;\n },\n isDirectory: path => {\n const rel = toRelative(path);\n if (rel === null) {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n }\n return objectType(rel) === 'tree';\n },\n readFile: path => {\n const rel = toRelative(path);\n if (rel === null) return readFileSync(path, 'utf-8');\n return gitReader.read(path);\n },\n getPathIdentity: path => {\n const rel = toRelative(path);\n // Only canonicalize the project root: checkout symlinks do not define\n // file identity in the trusted ref, including files missing on disk.\n return rel === null ? realpathOrResolved(path) : join(canonicalRoot, rel);\n },\n };\n}\n\n/**\n * Find the first existing instruction file at a given base path.\n * Prefers AGENTS.md over CLAUDE.md.\n */\nfunction findInstructionFile(basePath: string, reader: InstructionFileReader = fsInstructionReader): string | null {\n for (const filename of INSTRUCTION_FILES) {\n const fullPath = join(basePath, filename);\n if (reader.exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Load all agent instruction files from global and project locations.\n * Returns an array of instruction sources, with global ones first.\n *\n * `projectReader` controls where project-scope content comes from (defaults to\n * the working tree). Global instructions read the operator machine's\n * filesystem, unless `skipGlobal` keeps them out entirely.\n */\nexport function loadAgentInstructions(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader: InstructionFileReader = fsInstructionReader,\n { skipGlobal = false }: { skipGlobal?: boolean } = {},\n): InstructionSource[] {\n const sources: InstructionSource[] = [];\n const home = homedir();\n\n // Derive location arrays from the base constants, substituting the config dir name\n const projectLocations = PROJECT_LOCATIONS.map(loc => (loc === '.mastracode' ? configDirName : loc));\n const globalLocations = skipGlobal\n ? []\n : GLOBAL_LOCATIONS.map(loc => {\n if (loc === '.mastracode') return configDirName;\n // XDG-style path (~/.config/<name>): strip the leading dot since the\n // .config/ prefix already signals a hidden/config directory.\n if (loc === '.config/mastracode') return '.config/' + configDirName.replace(/^\\./, '');\n return loc;\n });\n\n // Load global instructions first\n for (const location of globalLocations) {\n const basePath = join(home, location);\n const filePath = findInstructionFile(basePath);\n if (filePath) {\n try {\n const content = readFileSync(filePath, 'utf-8').trim();\n if (content) {\n sources.push({ path: filePath, content, scope: 'global' });\n break; // Only use first found global instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n // Load project instructions\n for (const location of projectLocations) {\n const basePath = location ? join(projectPath, location) : projectPath;\n const filePath = findInstructionFile(basePath, projectReader);\n if (filePath) {\n try {\n const content = projectReader.read(filePath).trim();\n if (content) {\n sources.push({\n path: filePath,\n content,\n scope: 'project',\n ...(projectReader.ref ? { ref: projectReader.ref } : {}),\n });\n break; // Only use first found project instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n return sources;\n}\n\nexport function getStaticallyLoadedInstructionPaths(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader?: InstructionFileReader,\n): string[] {\n const canonicalRoot = realpathOrResolved(projectPath);\n return loadAgentInstructions(projectPath, configDirName, projectReader).flatMap(source => {\n const path = normalize(source.path);\n if (source.scope !== 'project') return [path];\n const canonicalPath = join(canonicalRoot, relative(projectPath, path));\n return path === canonicalPath ? [path] : [path, canonicalPath];\n });\n}\n\n/** Heading the agent-instructions block is introduced by in the system prompt. */\nexport const AGENT_INSTRUCTIONS_HEADING = '# Agent Instructions';\n\n/**\n * Format a single instruction source as it appears in the system prompt.\n *\n * Exported so callers that attribute prompt cost per source (the `/context`\n * audit) measure the exact block that is sent rather than reconstructing it.\n */\nexport function formatInstructionSource(source: InstructionSource): string {\n const label = source.scope === 'global' ? 'Global' : 'Project';\n const origin = source.ref ? `${source.path} (at ref ${source.ref})` : source.path;\n return `<!-- ${label} instructions from ${origin} -->\\n${source.content}`;\n}\n\n/**\n * Format loaded instructions into a string for the system prompt.\n */\nexport function formatAgentInstructions(sources: InstructionSource[]): string {\n if (sources.length === 0) return '';\n\n const sections = sources.map(formatInstructionSource);\n\n return `\\n${AGENT_INSTRUCTIONS_HEADING}\\n\\n${sections.join('\\n\\n')}\\n`;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBAAoB,CAAC,aAAa,WAAW;AAGnD,MAAM,oBAAoB;CACxB;CACA;CACA;AACF;AAEA,MAAM,mBAAmB;CAAC;CAAW;CAAe;CAAkB;AAAoB;AAuB1F,MAAM,sBAA6C;CACjD,SAAQ,SAAQ,WAAW,IAAI;CAC/B,OAAM,SAAQ,aAAa,MAAM,OAAO;AAC1C;AAEA,SAAS,mBAAmB,MAAsB;CAChD,IAAI;EACF,OAAO,aAAa,IAAI;CAC1B,QAAQ;EACN,OAAO,QAAQ,IAAI;CACrB;AACF;AAEA,SAAS,0BAA0B,aAAsD;CACvF,MAAM,gBAAgB,mBAAmB,WAAW;CACpD,QAAO,SAAQ;EACb,MAAM,MAAM,SAAS,aAAa,IAAI;EACtC,IAAI,QAAQ,QAAQ,CAAC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,UAAU,WAAW,WAAW,UAEhC,qBADN,OAAO,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,IAAI,KAAK,OAAO,KAC5B,QAAQ,OAAO;AAClE;;;;AAKA,SAAgB,wBAAwB,SAAsC;CAC5E,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,WAAW,QAAQ,IAAI,uBAAuB;CAEpD,OAAO,KAAK,2BAA2B,MAAM,SAAS,KAAK,MAAM,EAAE;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amazon-bedrock-gateway.d.ts","sourceRoot":"","sources":["../../src/providers/amazon-bedrock-gateway.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIpH,KAAK,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC;AACvE,KAAK,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"amazon-bedrock-gateway.d.ts","sourceRoot":"","sources":["../../src/providers/amazon-bedrock-gateway.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIpH,KAAK,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC;AACvE,KAAK,aAAa,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edrock } from "@ai-sdk/amazon-bedrock";
|
|
6
6
|
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
7
7
|
//#region src/providers/amazon-bedrock-gateway.ts
|
|
8
|
-
const
|
|
9
|
-
"anthropic.claude-3-5-haiku-",
|
|
10
|
-
"anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
11
|
-
"anthropic.claude-3-7-sonnet-",
|
|
12
|
-
"anthropic.claude-fable-5",
|
|
13
|
-
"anthropic.claude-haiku-4-5-",
|
|
14
|
-
"anthropic.claude-opus-4-",
|
|
15
|
-
"anthropic.claude-opus-5",
|
|
16
|
-
"anthropic.claude-sonnet-4-",
|
|
17
|
-
"anthropic.claude-sonnet-5"
|
|
18
|
-
];
|
|
8
|
+
const CLAUDE_3_CACHEABLE = /claude-3-7-sonnet|claude-3-5-sonnet-20241022|claude-3-5-haiku/;
|
|
19
9
|
function supportsBedrockPromptCaching(modelId) {
|
|
20
|
-
|
|
10
|
+
if (!modelId.includes("anthropic.claude")) return false;
|
|
11
|
+
return /anthropic\.claude-3-/.test(modelId) ? CLAUDE_3_CACHEABLE.test(modelId) : true;
|
|
21
12
|
}
|
|
22
13
|
function addBedrockCachePoints(prompt) {
|
|
23
14
|
const result = [...prompt];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amazon-bedrock-gateway.js","names":[],"sources":["../../src/providers/amazon-bedrock-gateway.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport path from 'node:path';\nimport { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\nimport { MastraModelGateway } from '@mastra/core/llm';\nimport type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';\nimport { getBedrockModelCatalog } from './amazon-bedrock.js';\n\ntype ModelRequestHeaders = Record<string, string>;\ntype BedrockModel = ReturnType<ReturnType<typeof createAmazonBedrock>>;\ntype BedrockPrompt = Parameters<BedrockModel['doGenerate']>[0]['prompt'];\n\nconst CACHEABLE_BEDROCK_MODEL_IDS = [\n 'anthropic.claude-3-5-haiku-',\n 'anthropic.claude-3-5-sonnet-20241022-v2:0',\n 'anthropic.claude-3-7-sonnet-',\n 'anthropic.claude-fable-5',\n 'anthropic.claude-haiku-4-5-',\n 'anthropic.claude-opus-4-',\n 'anthropic.claude-opus-5',\n 'anthropic.claude-sonnet-4-',\n 'anthropic.claude-sonnet-5',\n];\n\nexport function supportsBedrockPromptCaching(modelId: string): boolean {\n return CACHEABLE_BEDROCK_MODEL_IDS.some(cacheableModelId => modelId.includes(cacheableModelId));\n}\n\nexport function addBedrockCachePoints(prompt: BedrockPrompt): BedrockPrompt {\n const result = [...prompt];\n const markCachePoint = (message: (typeof result)[number]) => ({\n ...message,\n providerOptions: {\n ...message.providerOptions,\n bedrock: {\n ...message.providerOptions?.bedrock,\n cachePoint: { type: 'default' },\n },\n },\n });\n\n let lastSystemIndex = -1;\n for (let index = result.length - 1; index >= 0; index--) {\n if (result[index]!.role === 'system') {\n lastSystemIndex = index;\n break;\n }\n }\n\n if (lastSystemIndex >= 0) {\n result[lastSystemIndex] = markCachePoint(result[lastSystemIndex]!);\n }\n\n let lastNonSystemIndex = -1;\n for (let index = result.length - 1; index >= 0; index--) {\n if (result[index]!.role !== 'system') {\n lastNonSystemIndex = index;\n break;\n }\n }\n\n if (lastNonSystemIndex >= 0) {\n result[lastNonSystemIndex] = markCachePoint(result[lastNonSystemIndex]!);\n }\n\n return result;\n}\n\nexport function withBedrockCache(model: BedrockModel): BedrockModel {\n return new Proxy(model, {\n get(target, property, receiver) {\n if (property === 'doGenerate') {\n return (options: Parameters<BedrockModel['doGenerate']>[0]) =>\n target.doGenerate({ ...options, prompt: addBedrockCachePoints(options.prompt) });\n }\n if (property === 'doStream') {\n return (options: Parameters<BedrockModel['doStream']>[0]) =>\n target.doStream({ ...options, prompt: addBedrockCachePoints(options.prompt) });\n }\n return Reflect.get(target, property, receiver);\n },\n });\n}\n\nexport const AMAZON_BEDROCK_GATEWAY_ID = 'amazon-bedrock';\n\n/**\n * Whether AWS credentials look available for Bedrock.\n *\n * Amazon Bedrock authenticates with AWS SigV4 rather than a bearer API key, so\n * this only governs whether Bedrock models are offered as \"authenticated\" in the\n * picker. We look for the common signals (env vars, bearer token, a configured\n * profile, or a shared credentials/config file) rather than resolving\n * credentials here, since the auth checker must stay sync.\n */\nexport function hasAwsCredentials(): boolean {\n if (\n process.env.AWS_BEARER_TOKEN_BEDROCK ||\n (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) ||\n process.env.AWS_SHARED_CREDENTIALS_FILE ||\n process.env.AWS_CONFIG_FILE ||\n process.env.AWS_PROFILE ||\n process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ||\n process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI ||\n process.env.AWS_WEB_IDENTITY_TOKEN_FILE\n ) {\n return true;\n }\n const home = process.env.HOME || process.env.USERPROFILE;\n if (home) {\n const awsDir = path.join(home, '.aws');\n const credentialsPath = process.env.AWS_SHARED_CREDENTIALS_FILE ?? path.join(awsDir, 'credentials');\n const configPath = process.env.AWS_CONFIG_FILE ?? path.join(awsDir, 'config');\n if (existsSync(credentialsPath) || existsSync(configPath)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Create an Amazon Bedrock model.\n *\n * Bedrock authenticates with AWS SigV4 rather than a bearer API key, so this\n * resolves credentials through the standard AWS provider chain\n * (`fromNodeProviderChain`): environment variables, shared `~/.aws` config and\n * SSO profiles, and container/instance roles — the same resolution order the AWS\n * CLI uses. The region falls back to `us-east-1` to match the AWS SDK default.\n *\n * When `AWS_BEARER_TOKEN_BEDROCK` is set, `@ai-sdk/amazon-bedrock` uses bearer\n * auth instead and ignores the credential provider, so we leave that path to the\n * SDK and only wire up SigV4 here.\n */\nfunction bedrockProvider(modelId: string, headers?: ModelRequestHeaders) {\n const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';\n const bedrock = createAmazonBedrock({\n region,\n credentialProvider: fromNodeProviderChain(),\n headers,\n });\n const model = bedrock(modelId);\n return supportsBedrockPromptCaching(modelId) ? withBedrockCache(model) : model;\n}\n\n/**\n * Standalone Amazon Bedrock gateway.\n *\n * Bedrock is resolved directly via AWS SigV4 (not through the model router) and\n * its models are surfaced from the public models.dev catalog. It is exposed as\n * its own gateway/provider (`amazon-bedrock/...`) rather than nested under the\n * MastraCode gateway namespace.\n */\nexport class AmazonBedrockGateway extends MastraModelGateway {\n readonly id = AMAZON_BEDROCK_GATEWAY_ID;\n readonly name = 'Amazon Bedrock';\n\n shouldEnable(): boolean {\n return hasAwsCredentials();\n }\n\n async fetchProviders(): Promise<Record<string, ProviderConfig>> {\n const providers: Record<string, ProviderConfig> = {};\n try {\n const bedrockModels = await getBedrockModelCatalog();\n providers['amazon-bedrock'] = {\n name: 'Amazon Bedrock',\n apiKeyEnvVar: '',\n apiKeyHeader: 'Authorization',\n gateway: this.id,\n models: bedrockModels.map(model => model.id),\n };\n } catch (error) {\n console.warn('Failed to load Amazon Bedrock model catalog:', error);\n }\n return providers;\n }\n\n buildUrl(_modelId: string): string | undefined {\n return undefined;\n }\n\n async getApiKey(_modelId: string): Promise<string> {\n return hasAwsCredentials() ? 'aws-credential-chain' : '';\n }\n\n resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined {\n // Amazon Bedrock authenticates via the AWS credential chain rather than a\n // stored API key, so report it as authenticated whenever AWS credentials look\n // available. The actual SigV4 signing happens inside `bedrockProvider()`.\n if (hasAwsCredentials()) {\n return { apiKey: 'aws-credential-chain', source: 'gateway' };\n }\n return undefined;\n }\n\n resolveLanguageModel(args: {\n modelId: string;\n providerId: string;\n apiKey: string;\n headers?: Record<string, string>;\n transport?: any;\n responsesWebSocket?: any;\n }): GatewayLanguageModel {\n return bedrockProvider(args.modelId, args.headers) as unknown as GatewayLanguageModel;\n }\n}\n\nexport function createAmazonBedrockGate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E;EACA,OAAO;CACT;CAEA,SAAS,UAAsC,CAE/C;CAEA,MAAM,UAAU,UAAmC;EACjD,OAAO,kBAAkB,IAAI,yBAAyB;CACxD;CAEA,YAAY,UAA6D;EAIvE,IAAI,kBAAkB,GACpB,OAAO;GAAE,QAAQ;GAAwB,QAAQ;EAAU;CAG/D;CAEA,qBAAqB,MAOI;EACvB,OAAO,gBAAgB,KAAK,SAAS,KAAK,OAAO;CACnD;AACF;AAEA,SAAgB,6BAAmD;CACjE,OAAO,IAAI,qBAAqB;AAClC"}
|
|
1
|
+
{"version":3,"file":"amazon-bedrock-gateway.js","names":[],"sources":["../../src/providers/amazon-bedrock-gateway.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport path from 'node:path';\nimport { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\nimport { MastraModelGateway } from '@mastra/core/llm';\nimport type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';\nimport { getBedrockModelCatalog } from './amazon-bedrock.js';\n\ntype ModelRequestHeaders = Record<string, string>;\ntype BedrockModel = ReturnType<ReturnType<typeof createAmazonBedrock>>;\ntype BedrockPrompt = Parameters<BedrockModel['doGenerate']>[0]['prompt'];\n\n// Claude 3.x is a closed set: only these three variants support cachePoint on Bedrock.\n// claude-3-5-sonnet-20240620 is intentionally excluded (only the 20241022-v2:0 variant caches).\n// Every Claude 4+ and every named family (opus-5, sonnet-5, fable, mythos, …) supports it.\nconst CLAUDE_3_CACHEABLE = /claude-3-7-sonnet|claude-3-5-sonnet-20241022|claude-3-5-haiku/;\n\nexport function supportsBedrockPromptCaching(modelId: string): boolean {\n if (!modelId.includes('anthropic.claude')) return false;\n return /anthropic\\.claude-3-/.test(modelId) ? CLAUDE_3_CACHEABLE.test(modelId) : true;\n}\n\nexport function addBedrockCachePoints(prompt: BedrockPrompt): BedrockPrompt {\n const result = [...prompt];\n const markCachePoint = (message: (typeof result)[number]) => ({\n ...message,\n providerOptions: {\n ...message.providerOptions,\n bedrock: {\n ...message.providerOptions?.bedrock,\n cachePoint: { type: 'default' },\n },\n },\n });\n\n let lastSystemIndex = -1;\n for (let index = result.length - 1; index >= 0; index--) {\n if (result[index]!.role === 'system') {\n lastSystemIndex = index;\n break;\n }\n }\n\n if (lastSystemIndex >= 0) {\n result[lastSystemIndex] = markCachePoint(result[lastSystemIndex]!);\n }\n\n let lastNonSystemIndex = -1;\n for (let index = result.length - 1; index >= 0; index--) {\n if (result[index]!.role !== 'system') {\n lastNonSystemIndex = index;\n break;\n }\n }\n\n if (lastNonSystemIndex >= 0) {\n result[lastNonSystemIndex] = markCachePoint(result[lastNonSystemIndex]!);\n }\n\n return result;\n}\n\nexport function withBedrockCache(model: BedrockModel): BedrockModel {\n return new Proxy(model, {\n get(target, property, receiver) {\n if (property === 'doGenerate') {\n return (options: Parameters<BedrockModel['doGenerate']>[0]) =>\n target.doGenerate({ ...options, prompt: addBedrockCachePoints(options.prompt) });\n }\n if (property === 'doStream') {\n return (options: Parameters<BedrockModel['doStream']>[0]) =>\n target.doStream({ ...options, prompt: addBedrockCachePoints(options.prompt) });\n }\n return Reflect.get(target, property, receiver);\n },\n });\n}\n\nexport const AMAZON_BEDROCK_GATEWAY_ID = 'amazon-bedrock';\n\n/**\n * Whether AWS credentials look available for Bedrock.\n *\n * Amazon Bedrock authenticates with AWS SigV4 rather than a bearer API key, so\n * this only governs whether Bedrock models are offered as \"authenticated\" in the\n * picker. We look for the common signals (env vars, bearer token, a configured\n * profile, or a shared credentials/config file) rather than resolving\n * credentials here, since the auth checker must stay sync.\n */\nexport function hasAwsCredentials(): boolean {\n if (\n process.env.AWS_BEARER_TOKEN_BEDROCK ||\n (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) ||\n process.env.AWS_SHARED_CREDENTIALS_FILE ||\n process.env.AWS_CONFIG_FILE ||\n process.env.AWS_PROFILE ||\n process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ||\n process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI ||\n process.env.AWS_WEB_IDENTITY_TOKEN_FILE\n ) {\n return true;\n }\n const home = process.env.HOME || process.env.USERPROFILE;\n if (home) {\n const awsDir = path.join(home, '.aws');\n const credentialsPath = process.env.AWS_SHARED_CREDENTIALS_FILE ?? path.join(awsDir, 'credentials');\n const configPath = process.env.AWS_CONFIG_FILE ?? path.join(awsDir, 'config');\n if (existsSync(credentialsPath) || existsSync(configPath)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Create an Amazon Bedrock model.\n *\n * Bedrock authenticates with AWS SigV4 rather than a bearer API key, so this\n * resolves credentials through the standard AWS provider chain\n * (`fromNodeProviderChain`): environment variables, shared `~/.aws` config and\n * SSO profiles, and container/instance roles — the same resolution order the AWS\n * CLI uses. The region falls back to `us-east-1` to match the AWS SDK default.\n *\n * When `AWS_BEARER_TOKEN_BEDROCK` is set, `@ai-sdk/amazon-bedrock` uses bearer\n * auth instead and ignores the credential provider, so we leave that path to the\n * SDK and only wire up SigV4 here.\n */\nfunction bedrockProvider(modelId: string, headers?: ModelRequestHeaders) {\n const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';\n const bedrock = createAmazonBedrock({\n region,\n credentialProvider: fromNodeProviderChain(),\n headers,\n });\n const model = bedrock(modelId);\n return supportsBedrockPromptCaching(modelId) ? withBedrockCache(model) : model;\n}\n\n/**\n * Standalone Amazon Bedrock gateway.\n *\n * Bedrock is resolved directly via AWS SigV4 (not through the model router) and\n * its models are surfaced from the public models.dev catalog. It is exposed as\n * its own gateway/provider (`amazon-bedrock/...`) rather than nested under the\n * MastraCode gateway namespace.\n */\nexport class AmazonBedrockGateway extends MastraModelGateway {\n readonly id = AMAZON_BEDROCK_GATEWAY_ID;\n readonly name = 'Amazon Bedrock';\n\n shouldEnable(): boolean {\n return hasAwsCredentials();\n }\n\n async fetchProviders(): Promise<Record<string, ProviderConfig>> {\n const providers: Record<string, ProviderConfig> = {};\n try {\n const bedrockModels = await getBedrockModelCatalog();\n providers['amazon-bedrock'] = {\n name: 'Amazon Bedrock',\n apiKeyEnvVar: '',\n apiKeyHeader: 'Authorization',\n gateway: this.id,\n models: bedrockModels.map(model => model.id),\n };\n } catch (error) {\n console.warn('Failed to load Amazon Bedrock model catalog:', error);\n }\n return providers;\n }\n\n buildUrl(_modelId: string): string | undefined {\n return undefined;\n }\n\n async getApiKey(_modelId: string): Promise<string> {\n return hasAwsCredentials() ? 'aws-credential-chain' : '';\n }\n\n resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined {\n // Amazon Bedrock authenticates via the AWS credential chain rather than a\n // stored API key, so report it as authenticated whenever AWS credentials look\n // available. The actual SigV4 signing happens inside `bedrockProvider()`.\n if (hasAwsCredentials()) {\n return { apiKey: 'aws-credential-chain', source: 'gateway' };\n }\n return undefined;\n }\n\n resolveLanguageModel(args: {\n modelId: string;\n providerId: string;\n apiKey: string;\n headers?: Record<string, string>;\n transport?: any;\n responsesWebSocket?: any;\n }): GatewayLanguageModel {\n return bedrockProvider(args.modelId, args.headers) as unknown as GatewayLanguageModel;\n }\n}\n\nexport function createAmazonBedrockGateway(): AmazonBedrockGateway {\n return new AmazonBedrockGateway();\n}\n"],"mappings":";;;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,6BAA6B,SAA0B;CACrE,IAAI,CAAC,QAAQ,SAAS,kBAAkB,GAAG,OAAO;CAClD,OAAO,uBAAuB,KAAK,OAAO,IAAI,mBAAmB,KAAK,OAAO,IAAI;AACnF;AAEA,SAAgB,sBAAsB,QAAsC;CAC1E,MAAM,SAAS,CAAC,GAAG,MAAM;CACzB,MAAM,kBAAkB,aAAsC;EAC5D,GAAG;EACH,iBAAiB;GACf,GAAG,QAAQ;GACX,SAAS;IACP,GAAG,QAAQ,iBAAiB;IAC5B,YAAY,EAAE,MAAM,UAAU;GAChC;EACF;CACF;CAEA,IAAI,kB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"1.7.2-alpha.1",
|
|
4
4
|
"description": "Mastra Code SDK: the agent core behind Mastra Code (everything except the TUI) — build your own UIs and surfaces on top of it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -57,19 +57,19 @@
|
|
|
57
57
|
"yaml": "^2.7.1",
|
|
58
58
|
"zod": "^4.3.6",
|
|
59
59
|
"@mastra/agent-browser": "0.5.2",
|
|
60
|
-
"@mastra/
|
|
60
|
+
"@mastra/core": "1.67.0-alpha.1",
|
|
61
61
|
"@mastra/fastembed": "1.3.1",
|
|
62
|
-
"@mastra/memory": "1.29.0",
|
|
63
|
-
"@mastra/libsql": "1.22.5",
|
|
64
|
-
"@mastra/core": "1.66.0",
|
|
65
62
|
"@mastra/duckdb": "1.8.0",
|
|
66
|
-
"@mastra/observability": "1.17.7",
|
|
67
|
-
"@mastra/parallel": "0.1.1",
|
|
68
|
-
"@mastra/schema-compat": "1.3.9",
|
|
69
63
|
"@mastra/mcp": "1.17.3",
|
|
70
|
-
"@mastra/
|
|
64
|
+
"@mastra/github-signals": "0.4.0",
|
|
65
|
+
"@mastra/libsql": "1.22.6-alpha.0",
|
|
66
|
+
"@mastra/memory": "1.30.0-alpha.1",
|
|
67
|
+
"@mastra/parallel": "0.1.1",
|
|
68
|
+
"@mastra/pg": "1.24.1-alpha.0",
|
|
69
|
+
"@mastra/stagehand": "0.3.4",
|
|
70
|
+
"@mastra/schema-compat": "1.3.10-alpha.0",
|
|
71
71
|
"@mastra/tavily": "1.1.2",
|
|
72
|
-
"@mastra/
|
|
72
|
+
"@mastra/observability": "1.17.7"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@libsql/client": "^0.18.0",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"typescript": "^6.0.3",
|
|
81
81
|
"typescript-eslint": "^8.57.0",
|
|
82
82
|
"vitest": "4.1.10",
|
|
83
|
-
"@internal/lint": "0.0.132",
|
|
84
83
|
"@internal/types-builder": "0.0.107",
|
|
85
|
-
"@internal/workspace-test-utils": "0.0.76"
|
|
84
|
+
"@internal/workspace-test-utils": "0.0.76",
|
|
85
|
+
"@internal/lint": "0.0.132"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=22.19.0"
|