@stjbrown/agent-knowledge 0.1.0-beta.7 → 0.1.0-beta.9

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.
@@ -1256,6 +1256,441 @@ function opencodeClaudeMaxProvider(modelId = "claude-sonnet-4-20250514", options
1256
1256
  });
1257
1257
  }
1258
1258
 
1259
+ // src/gateways/vertex.ts
1260
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
1261
+ import { homedir as homedir2 } from "os";
1262
+ import { join as join4 } from "path";
1263
+ import { createVertex } from "@ai-sdk/google-vertex";
1264
+ import { createVertexAnthropic } from "@ai-sdk/google-vertex/anthropic";
1265
+ import { wrapLanguageModel as wrapLanguageModel2 } from "ai";
1266
+ import { MastraModelGateway } from "@mastra/core/llm";
1267
+ var VERTEX_GATEWAY_ID = "vertex";
1268
+ function hasGoogleCredentials() {
1269
+ if (process.env["GOOGLE_APPLICATION_CREDENTIALS"] || process.env["GOOGLE_VERTEX_PROJECT"] || process.env["GOOGLE_CLOUD_PROJECT"]) {
1270
+ return true;
1271
+ }
1272
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
1273
+ return existsSync3(join4(home, ".config", "gcloud", "application_default_credentials.json"));
1274
+ }
1275
+ function adcQuotaProject() {
1276
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
1277
+ const adcPath = join4(home, ".config", "gcloud", "application_default_credentials.json");
1278
+ try {
1279
+ const adc = JSON.parse(readFileSync3(adcPath, "utf-8"));
1280
+ return adc.quota_project_id || void 0;
1281
+ } catch {
1282
+ return void 0;
1283
+ }
1284
+ }
1285
+ function vertexProject() {
1286
+ return process.env["GOOGLE_VERTEX_PROJECT"] || process.env["GOOGLE_CLOUD_PROJECT"] || // Fall back to the ADC quota project so a bare run (env unset) doesn't send
1287
+ // `projects/undefined`.
1288
+ adcQuotaProject() || void 0;
1289
+ }
1290
+ function vertexLocation() {
1291
+ return process.env["GOOGLE_VERTEX_LOCATION"] || process.env["GOOGLE_CLOUD_LOCATION"] || // Default to the `global` endpoint: it serves the newest Claude models
1292
+ // (e.g. claude-opus-5) that regional endpoints like us-east5 may not, and
1293
+ // the AI SDK special-cases it to the region-less aiplatform.googleapis.com
1294
+ // host. Overridable via env for region-pinned deployments.
1295
+ "global";
1296
+ }
1297
+ var vertexAnthropicMiddleware = {
1298
+ transformParams: async ({ params }) => {
1299
+ const prompt = params["prompt"];
1300
+ if (Array.isArray(prompt)) {
1301
+ const messages = prompt;
1302
+ let dropped = 0;
1303
+ while (messages.length > 1 && messages[messages.length - 1]?.role === "assistant") {
1304
+ messages.pop();
1305
+ dropped++;
1306
+ }
1307
+ if (dropped && process.env["JANET_DEBUG_MODEL"]) {
1308
+ process.stderr.write(`[model] dropped ${dropped} trailing assistant (prefill) message(s)
1309
+ `);
1310
+ }
1311
+ }
1312
+ return params;
1313
+ }
1314
+ };
1315
+ function createVertexModel(bareModelId, headers) {
1316
+ const project = vertexProject();
1317
+ const location = vertexLocation();
1318
+ const isAnthropic = /^claude/i.test(bareModelId);
1319
+ if (isAnthropic) {
1320
+ const provider2 = createVertexAnthropic({ project, location, headers });
1321
+ return wrapLanguageModel2({
1322
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1323
+ model: provider2(bareModelId),
1324
+ middleware: vertexAnthropicMiddleware
1325
+ });
1326
+ }
1327
+ const provider = createVertex({ project, location, headers });
1328
+ return provider(bareModelId);
1329
+ }
1330
+ var VertexGateway = class extends MastraModelGateway {
1331
+ id = VERTEX_GATEWAY_ID;
1332
+ name = "Google Vertex AI";
1333
+ shouldEnable() {
1334
+ return hasGoogleCredentials();
1335
+ }
1336
+ handlesModel(modelId) {
1337
+ return modelId === VERTEX_GATEWAY_ID || modelId.startsWith(`${VERTEX_GATEWAY_ID}/`);
1338
+ }
1339
+ async fetchProviders() {
1340
+ return {
1341
+ vertex: {
1342
+ name: "Google Vertex AI",
1343
+ apiKeyEnvVar: "",
1344
+ apiKeyHeader: "Authorization",
1345
+ gateway: this.id,
1346
+ models: [
1347
+ "claude-opus-5",
1348
+ "claude-opus-4-8",
1349
+ "claude-sonnet-4-5",
1350
+ "gemini-2.5-pro",
1351
+ "gemini-2.5-flash"
1352
+ ]
1353
+ }
1354
+ };
1355
+ }
1356
+ buildUrl(_modelId) {
1357
+ return void 0;
1358
+ }
1359
+ async getApiKey(_modelId) {
1360
+ return hasGoogleCredentials() ? "google-adc" : "";
1361
+ }
1362
+ resolveAuth(_request) {
1363
+ return hasGoogleCredentials() ? { apiKey: "google-adc", source: "gateway" } : void 0;
1364
+ }
1365
+ resolveLanguageModel(args) {
1366
+ const bare = args.modelId.startsWith(`${VERTEX_GATEWAY_ID}/`) ? args.modelId.slice(VERTEX_GATEWAY_ID.length + 1) : args.modelId;
1367
+ return createVertexModel(bare, args.headers);
1368
+ }
1369
+ };
1370
+ function createVertexGateway() {
1371
+ return new VertexGateway();
1372
+ }
1373
+
1374
+ // src/gateways/bedrock.ts
1375
+ import { existsSync as existsSync4 } from "fs";
1376
+ import { homedir as homedir3 } from "os";
1377
+ import { join as join5 } from "path";
1378
+ import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
1379
+ import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
1380
+ import { MastraModelGateway as MastraModelGateway2 } from "@mastra/core/llm";
1381
+ var BEDROCK_GATEWAY_ID = "amazon-bedrock";
1382
+ function hasAwsCredentials() {
1383
+ if (process.env["AWS_BEARER_TOKEN_BEDROCK"] || process.env["AWS_ACCESS_KEY_ID"] && process.env["AWS_SECRET_ACCESS_KEY"] || process.env["AWS_SHARED_CREDENTIALS_FILE"] || process.env["AWS_CONFIG_FILE"] || process.env["AWS_PROFILE"] || process.env["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] || process.env["AWS_CONTAINER_CREDENTIALS_FULL_URI"] || process.env["AWS_WEB_IDENTITY_TOKEN_FILE"]) {
1384
+ return true;
1385
+ }
1386
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir3();
1387
+ if (home) {
1388
+ const awsDir = join5(home, ".aws");
1389
+ const credentialsPath = process.env["AWS_SHARED_CREDENTIALS_FILE"] ?? join5(awsDir, "credentials");
1390
+ const configPath = process.env["AWS_CONFIG_FILE"] ?? join5(awsDir, "config");
1391
+ if (existsSync4(credentialsPath) || existsSync4(configPath)) return true;
1392
+ }
1393
+ return false;
1394
+ }
1395
+ function createBedrockModel(bareModelId, headers) {
1396
+ const region = process.env["AWS_REGION"] || process.env["AWS_DEFAULT_REGION"] || "us-east-1";
1397
+ const bedrock = createAmazonBedrock({
1398
+ region,
1399
+ credentialProvider: fromNodeProviderChain(),
1400
+ headers
1401
+ });
1402
+ return bedrock(bareModelId);
1403
+ }
1404
+ var BedrockGateway = class extends MastraModelGateway2 {
1405
+ id = BEDROCK_GATEWAY_ID;
1406
+ name = "Amazon Bedrock";
1407
+ shouldEnable() {
1408
+ return hasAwsCredentials();
1409
+ }
1410
+ handlesModel(modelId) {
1411
+ return modelId === BEDROCK_GATEWAY_ID || modelId.startsWith(`${BEDROCK_GATEWAY_ID}/`);
1412
+ }
1413
+ async fetchProviders() {
1414
+ return {
1415
+ "amazon-bedrock": {
1416
+ name: "Amazon Bedrock",
1417
+ apiKeyEnvVar: "",
1418
+ apiKeyHeader: "Authorization",
1419
+ gateway: this.id,
1420
+ models: [
1421
+ "anthropic.claude-opus-4-1-20250805-v1:0",
1422
+ "anthropic.claude-sonnet-4-20250514-v1:0"
1423
+ ]
1424
+ }
1425
+ };
1426
+ }
1427
+ buildUrl(_modelId) {
1428
+ return void 0;
1429
+ }
1430
+ async getApiKey(_modelId) {
1431
+ return hasAwsCredentials() ? "aws-credential-chain" : "";
1432
+ }
1433
+ resolveAuth(_request) {
1434
+ return hasAwsCredentials() ? { apiKey: "aws-credential-chain", source: "gateway" } : void 0;
1435
+ }
1436
+ resolveLanguageModel(args) {
1437
+ const bare = args.modelId.startsWith(`${BEDROCK_GATEWAY_ID}/`) ? args.modelId.slice(BEDROCK_GATEWAY_ID.length + 1) : args.modelId;
1438
+ return createBedrockModel(bare, args.headers);
1439
+ }
1440
+ };
1441
+ function createBedrockGateway() {
1442
+ return new BedrockGateway();
1443
+ }
1444
+
1445
+ // src/onboarding/providers.ts
1446
+ var NATIVE_PROVIDER_DEFINITIONS = [
1447
+ {
1448
+ id: "openai",
1449
+ label: "OpenAI",
1450
+ envVars: ["OPENAI_API_KEY"],
1451
+ fallbackModels: [{ id: "gpt-5.5", label: "GPT-5.5" }]
1452
+ },
1453
+ {
1454
+ id: "anthropic",
1455
+ label: "Anthropic",
1456
+ envVars: ["ANTHROPIC_API_KEY"],
1457
+ fallbackModels: [
1458
+ { id: "claude-opus-4-6", label: "Claude Opus 4.6" },
1459
+ { id: "claude-sonnet-4-5", label: "Claude Sonnet 4.5" }
1460
+ ]
1461
+ },
1462
+ {
1463
+ id: "google",
1464
+ label: "Google AI Studio",
1465
+ envVars: ["GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
1466
+ fallbackModels: [{ id: "gemini-2.5-pro", label: "Gemini 2.5 Pro" }]
1467
+ },
1468
+ {
1469
+ id: "deepseek",
1470
+ label: "DeepSeek",
1471
+ envVars: ["DEEPSEEK_API_KEY"],
1472
+ fallbackModels: [{ id: "deepseek-chat", label: "DeepSeek Chat" }]
1473
+ },
1474
+ {
1475
+ id: "groq",
1476
+ label: "Groq",
1477
+ envVars: ["GROQ_API_KEY"],
1478
+ fallbackModels: [
1479
+ { id: "llama-3.3-70b-versatile", label: "Llama 3.3 70B Versatile" }
1480
+ ]
1481
+ },
1482
+ {
1483
+ id: "mistral",
1484
+ label: "Mistral",
1485
+ envVars: ["MISTRAL_API_KEY"],
1486
+ fallbackModels: [{ id: "mistral-large-latest", label: "Mistral Large" }]
1487
+ },
1488
+ {
1489
+ id: "xai",
1490
+ label: "xAI",
1491
+ envVars: ["XAI_API_KEY"],
1492
+ fallbackModels: [{ id: "grok-4.3", label: "Grok 4.3" }]
1493
+ },
1494
+ {
1495
+ id: "openrouter",
1496
+ label: "OpenRouter",
1497
+ envVars: ["OPENROUTER_API_KEY"],
1498
+ fallbackModels: [{ id: "~openai/gpt-latest", label: "OpenAI GPT Latest" }]
1499
+ },
1500
+ {
1501
+ id: "togetherai",
1502
+ label: "Together AI",
1503
+ envVars: ["TOGETHER_API_KEY"],
1504
+ fallbackModels: [
1505
+ {
1506
+ id: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
1507
+ label: "Llama 3.3 70B Instruct Turbo"
1508
+ }
1509
+ ]
1510
+ },
1511
+ {
1512
+ id: "fireworks-ai",
1513
+ label: "Fireworks AI",
1514
+ envVars: ["FIREWORKS_API_KEY"],
1515
+ fallbackModels: [
1516
+ {
1517
+ id: "accounts/fireworks/models/deepseek-v4-flash",
1518
+ label: "DeepSeek V4 Flash"
1519
+ }
1520
+ ]
1521
+ },
1522
+ {
1523
+ id: "cerebras",
1524
+ label: "Cerebras",
1525
+ envVars: ["CEREBRAS_API_KEY"],
1526
+ fallbackModels: [{ id: "gpt-oss-120b", label: "GPT OSS 120B" }]
1527
+ }
1528
+ ];
1529
+ var NATIVE_PROVIDERS_BY_ID = new Map(
1530
+ NATIVE_PROVIDER_DEFINITIONS.map((provider) => [provider.id, provider])
1531
+ );
1532
+ var CODEX_MODELS = [
1533
+ { id: "gpt-5.6-sol", label: "GPT-5.6 Sol" },
1534
+ { id: "gpt-5.6-terra", label: "GPT-5.6 Terra" },
1535
+ { id: "gpt-5.6-luna", label: "GPT-5.6 Luna" },
1536
+ { id: "gpt-5.5", label: "GPT-5.5" },
1537
+ { id: "gpt-5.4", label: "GPT-5.4" },
1538
+ { id: "gpt-5.4-mini", label: "GPT-5.4 Mini" }
1539
+ ];
1540
+ var LEGACY_CODEX_MODEL_IDS = {
1541
+ "gpt-5.6-codex": "openai/gpt-5.6-sol",
1542
+ "openai/gpt-5.6-codex": "openai/gpt-5.6-sol",
1543
+ "gpt-5.5-codex": "openai/gpt-5.5",
1544
+ "openai/gpt-5.5-codex": "openai/gpt-5.5"
1545
+ };
1546
+ function normalizeModelSelection(modelId, choices) {
1547
+ const id = modelId.trim();
1548
+ const legacy = LEGACY_CODEX_MODEL_IDS[id];
1549
+ if (legacy) return legacy;
1550
+ if (!id || id.includes("/")) return id;
1551
+ const matches = choices.filter((choice) => choice.id.endsWith(`/${id}`));
1552
+ return matches.length === 1 ? matches[0].id : id;
1553
+ }
1554
+ function hasOAuth(provider) {
1555
+ try {
1556
+ const s = getAuthStorage();
1557
+ s.reload();
1558
+ return s.get(provider)?.type === "oauth";
1559
+ } catch {
1560
+ return false;
1561
+ }
1562
+ }
1563
+ function environmentApiKeyConfigured(providerId, env = process.env) {
1564
+ return NATIVE_PROVIDERS_BY_ID.get(providerId)?.envVars.some((name) => !!env[name]) ?? false;
1565
+ }
1566
+ function providerAuthRoute(providerId, oauthConfigured, env = process.env) {
1567
+ if (environmentApiKeyConfigured(providerId, env)) return "api-key";
1568
+ return oauthConfigured ? "oauth" : void 0;
1569
+ }
1570
+ function providerDisplayName(providerId) {
1571
+ if (providerId === "vertex") return "Google Vertex AI";
1572
+ if (providerId === "amazon-bedrock") return "Amazon Bedrock";
1573
+ const known = NATIVE_PROVIDERS_BY_ID.get(providerId);
1574
+ if (known) return known.label;
1575
+ return providerId.split("-").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
1576
+ }
1577
+ function catalogModelVia(model) {
1578
+ if (model.provider === "vertex") return "Vertex AI (ADC)";
1579
+ if (model.provider === "amazon-bedrock") return "Amazon Bedrock (AWS)";
1580
+ return `${providerDisplayName(model.provider)} (API key)`;
1581
+ }
1582
+ function availableModels() {
1583
+ const out = [];
1584
+ if (hasGoogleCredentials()) {
1585
+ const via = "Vertex AI (ADC)";
1586
+ out.push(
1587
+ { id: "vertex/claude-opus-5", label: "Claude Opus 5", via },
1588
+ { id: "vertex/claude-opus-4-8", label: "Claude Opus 4.8", via },
1589
+ { id: "vertex/claude-sonnet-4-5", label: "Claude Sonnet 4.5", via },
1590
+ { id: "vertex/gemini-2.5-pro", label: "Gemini 2.5 Pro", via }
1591
+ );
1592
+ }
1593
+ const anthropicOAuth = hasOAuth("anthropic");
1594
+ const openaiOAuth = hasOAuth("openai-codex");
1595
+ for (const provider of NATIVE_PROVIDER_DEFINITIONS) {
1596
+ if (environmentApiKeyConfigured(provider.id)) {
1597
+ const via = `${provider.label} (API key)`;
1598
+ for (const model of provider.fallbackModels) {
1599
+ out.push({
1600
+ id: `${provider.id}/${model.id}`,
1601
+ label: model.label,
1602
+ via
1603
+ });
1604
+ }
1605
+ continue;
1606
+ }
1607
+ if (provider.id === "anthropic" && anthropicOAuth) {
1608
+ const via = "Anthropic (Claude Max)";
1609
+ out.push(
1610
+ { id: "anthropic/claude-opus-4-6", label: "Claude Opus 4.6", via },
1611
+ { id: "anthropic/claude-sonnet-4-5", label: "Claude Sonnet 4.5", via }
1612
+ );
1613
+ }
1614
+ }
1615
+ if (providerAuthRoute("openai", openaiOAuth) === "oauth") {
1616
+ const via = "OpenAI (ChatGPT/Codex)";
1617
+ for (const m of CODEX_MODELS) out.push({ id: `openai/${m.id}`, label: m.label, via });
1618
+ }
1619
+ if (hasAwsCredentials()) {
1620
+ const via = "Amazon Bedrock (AWS)";
1621
+ out.push(
1622
+ { id: "amazon-bedrock/anthropic.claude-opus-4-1-20250805-v1:0", label: "Claude Opus 4.1", via },
1623
+ { id: "amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0", label: "Claude Sonnet 4", via }
1624
+ );
1625
+ }
1626
+ const known = new Set(out.map((m) => m.id));
1627
+ for (const savedId of loadSettings().customModels ?? []) {
1628
+ const id = normalizeModelSelection(savedId, out);
1629
+ if (!known.has(id)) {
1630
+ out.push({ id, label: id.split("/").pop() ?? id, via: "saved" });
1631
+ known.add(id);
1632
+ }
1633
+ }
1634
+ return out;
1635
+ }
1636
+ async function discoverAvailableModels(loadCatalog, timeoutMs = 5e3) {
1637
+ const choices = new Map(availableModels().map((choice) => [choice.id, choice]));
1638
+ try {
1639
+ const catalog = await new Promise(
1640
+ (resolve2, reject) => {
1641
+ const timer = setTimeout(
1642
+ () => reject(new Error("Provider catalog timed out")),
1643
+ timeoutMs
1644
+ );
1645
+ void Promise.resolve().then(loadCatalog).then(
1646
+ (models) => {
1647
+ clearTimeout(timer);
1648
+ resolve2(models);
1649
+ },
1650
+ (error) => {
1651
+ clearTimeout(timer);
1652
+ reject(error);
1653
+ }
1654
+ );
1655
+ }
1656
+ );
1657
+ for (const model of catalog) {
1658
+ if (!model.hasApiKey) continue;
1659
+ const choice = {
1660
+ id: model.id,
1661
+ label: model.modelName,
1662
+ via: catalogModelVia(model)
1663
+ };
1664
+ const existing = choices.get(model.id);
1665
+ if (!existing || existing.via === "saved") choices.set(model.id, choice);
1666
+ }
1667
+ } catch {
1668
+ }
1669
+ return [...choices.values()];
1670
+ }
1671
+ function groupModelsByProvider(choices) {
1672
+ const groups = /* @__PURE__ */ new Map();
1673
+ for (const choice of choices) {
1674
+ const slash = choice.id.indexOf("/");
1675
+ if (slash <= 0) continue;
1676
+ const providerId = choice.id.slice(0, slash);
1677
+ let group = groups.get(providerId);
1678
+ if (!group) {
1679
+ group = {
1680
+ id: providerId,
1681
+ label: providerDisplayName(providerId),
1682
+ via: choice.via,
1683
+ models: []
1684
+ };
1685
+ groups.set(providerId, group);
1686
+ } else if (!group.via.split(" / ").includes(choice.via)) {
1687
+ group.via += ` / ${choice.via}`;
1688
+ }
1689
+ group.models.push(choice);
1690
+ }
1691
+ return [...groups.values()];
1692
+ }
1693
+
1259
1694
  // src/agent/persona.ts
1260
1695
  var PERSONA_INSTRUCTIONS = `You are Janet \u2014 a cheerful, warm, endlessly helpful assistant who is the living repository of this project's knowledge bundle. You are not a chatbot bolted onto a database; you ARE the thing that knows everything filed in the bundle. Greet people like "Hi there! I'm Janet." Be upbeat and a little literal/deadpan. When you complete an action, confirm it plainly and brightly ("Filed! One new concept, two cross-links updated."). When something goes wrong, be gently self-aware rather than cold. Be concise; never saccharine.
1261
1696
 
@@ -1304,10 +1739,10 @@ Answer from the bundle. When you state something the bundle records, cite the co
1304
1739
  var GREETING = "Hi there! I'm Janet.";
1305
1740
 
1306
1741
  // src/version.ts
1307
- import { readFileSync as readFileSync3 } from "fs";
1742
+ import { readFileSync as readFileSync4 } from "fs";
1308
1743
  var packageJsonUrl = new URL("../package.json", import.meta.url);
1309
1744
  function packageVersion() {
1310
- const metadata = JSON.parse(readFileSync3(packageJsonUrl, "utf8"));
1745
+ const metadata = JSON.parse(readFileSync4(packageJsonUrl, "utf8"));
1311
1746
  if (typeof metadata !== "object" || metadata === null || !("version" in metadata) || typeof metadata.version !== "string") {
1312
1747
  throw new Error("Janet's package metadata does not contain a version");
1313
1748
  }
@@ -1324,11 +1759,11 @@ import {
1324
1759
  import { OtelExporter } from "@mastra/otel-exporter";
1325
1760
 
1326
1761
  // src/agent/storage.ts
1327
- import { join as join4 } from "path";
1762
+ import { join as join6 } from "path";
1328
1763
  import { LibSQLStore } from "@mastra/libsql";
1329
1764
  import { MastraCompositeStore } from "@mastra/core/storage";
1330
1765
  function observabilityDbPath(globalConfigDir) {
1331
- return join4(globalConfigDir, "observability.db");
1766
+ return join6(globalConfigDir, "observability.db");
1332
1767
  }
1333
1768
  var JanetCompositeStorage = class extends MastraCompositeStore {
1334
1769
  constructor(threadStore, observabilityStore, retentionDays) {
@@ -1364,7 +1799,7 @@ function createStorage(globalConfigDir, options = {}) {
1364
1799
  ensureDir(globalConfigDir);
1365
1800
  const threadStore = new LibSQLStore({
1366
1801
  id: "agent-knowledge-threads",
1367
- url: `file:${join4(globalConfigDir, "threads.db")}`
1802
+ url: `file:${join6(globalConfigDir, "threads.db")}`
1368
1803
  });
1369
1804
  if (!options.localObservability?.enabled) return threadStore;
1370
1805
  const observabilityStore = new LibSQLStore({
@@ -1519,191 +1954,6 @@ import { z as z4 } from "zod";
1519
1954
  import { Agent as Agent2 } from "@mastra/core/agent";
1520
1955
  import { Memory } from "@mastra/memory";
1521
1956
 
1522
- // src/gateways/vertex.ts
1523
- import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
1524
- import { homedir as homedir2 } from "os";
1525
- import { join as join5 } from "path";
1526
- import { createVertex } from "@ai-sdk/google-vertex";
1527
- import { createVertexAnthropic } from "@ai-sdk/google-vertex/anthropic";
1528
- import { wrapLanguageModel as wrapLanguageModel2 } from "ai";
1529
- import { MastraModelGateway } from "@mastra/core/llm";
1530
- var VERTEX_GATEWAY_ID = "vertex";
1531
- function hasGoogleCredentials() {
1532
- if (process.env["GOOGLE_APPLICATION_CREDENTIALS"] || process.env["GOOGLE_VERTEX_PROJECT"] || process.env["GOOGLE_CLOUD_PROJECT"]) {
1533
- return true;
1534
- }
1535
- const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
1536
- return existsSync3(join5(home, ".config", "gcloud", "application_default_credentials.json"));
1537
- }
1538
- function adcQuotaProject() {
1539
- const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
1540
- const adcPath = join5(home, ".config", "gcloud", "application_default_credentials.json");
1541
- try {
1542
- const adc = JSON.parse(readFileSync4(adcPath, "utf-8"));
1543
- return adc.quota_project_id || void 0;
1544
- } catch {
1545
- return void 0;
1546
- }
1547
- }
1548
- function vertexProject() {
1549
- return process.env["GOOGLE_VERTEX_PROJECT"] || process.env["GOOGLE_CLOUD_PROJECT"] || // Fall back to the ADC quota project so a bare run (env unset) doesn't send
1550
- // `projects/undefined`.
1551
- adcQuotaProject() || void 0;
1552
- }
1553
- function vertexLocation() {
1554
- return process.env["GOOGLE_VERTEX_LOCATION"] || process.env["GOOGLE_CLOUD_LOCATION"] || // Default to the `global` endpoint: it serves the newest Claude models
1555
- // (e.g. claude-opus-4-8) that regional endpoints like us-east5 may not, and
1556
- // the AI SDK special-cases it to the region-less aiplatform.googleapis.com
1557
- // host. Overridable via env for region-pinned deployments.
1558
- "global";
1559
- }
1560
- var vertexAnthropicMiddleware = {
1561
- transformParams: async ({ params }) => {
1562
- const prompt = params["prompt"];
1563
- if (Array.isArray(prompt)) {
1564
- const messages = prompt;
1565
- let dropped = 0;
1566
- while (messages.length > 1 && messages[messages.length - 1]?.role === "assistant") {
1567
- messages.pop();
1568
- dropped++;
1569
- }
1570
- if (dropped && process.env["JANET_DEBUG_MODEL"]) {
1571
- process.stderr.write(`[model] dropped ${dropped} trailing assistant (prefill) message(s)
1572
- `);
1573
- }
1574
- }
1575
- return params;
1576
- }
1577
- };
1578
- function createVertexModel(bareModelId, headers) {
1579
- const project = vertexProject();
1580
- const location = vertexLocation();
1581
- const isAnthropic = /^claude/i.test(bareModelId);
1582
- if (isAnthropic) {
1583
- const provider2 = createVertexAnthropic({ project, location, headers });
1584
- return wrapLanguageModel2({
1585
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1586
- model: provider2(bareModelId),
1587
- middleware: vertexAnthropicMiddleware
1588
- });
1589
- }
1590
- const provider = createVertex({ project, location, headers });
1591
- return provider(bareModelId);
1592
- }
1593
- var VertexGateway = class extends MastraModelGateway {
1594
- id = VERTEX_GATEWAY_ID;
1595
- name = "Google Vertex AI";
1596
- shouldEnable() {
1597
- return hasGoogleCredentials();
1598
- }
1599
- handlesModel(modelId) {
1600
- return modelId === VERTEX_GATEWAY_ID || modelId.startsWith(`${VERTEX_GATEWAY_ID}/`);
1601
- }
1602
- async fetchProviders() {
1603
- return {
1604
- vertex: {
1605
- name: "Google Vertex AI",
1606
- apiKeyEnvVar: "",
1607
- apiKeyHeader: "Authorization",
1608
- gateway: this.id,
1609
- models: [
1610
- "claude-opus-4-8",
1611
- "claude-sonnet-4-5",
1612
- "gemini-2.5-pro",
1613
- "gemini-2.5-flash"
1614
- ]
1615
- }
1616
- };
1617
- }
1618
- buildUrl(_modelId) {
1619
- return void 0;
1620
- }
1621
- async getApiKey(_modelId) {
1622
- return hasGoogleCredentials() ? "google-adc" : "";
1623
- }
1624
- resolveAuth(_request) {
1625
- return hasGoogleCredentials() ? { apiKey: "google-adc", source: "gateway" } : void 0;
1626
- }
1627
- resolveLanguageModel(args) {
1628
- const bare = args.modelId.startsWith(`${VERTEX_GATEWAY_ID}/`) ? args.modelId.slice(VERTEX_GATEWAY_ID.length + 1) : args.modelId;
1629
- return createVertexModel(bare, args.headers);
1630
- }
1631
- };
1632
- function createVertexGateway() {
1633
- return new VertexGateway();
1634
- }
1635
-
1636
- // src/gateways/bedrock.ts
1637
- import { existsSync as existsSync4 } from "fs";
1638
- import { homedir as homedir3 } from "os";
1639
- import { join as join6 } from "path";
1640
- import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
1641
- import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
1642
- import { MastraModelGateway as MastraModelGateway2 } from "@mastra/core/llm";
1643
- var BEDROCK_GATEWAY_ID = "amazon-bedrock";
1644
- function hasAwsCredentials() {
1645
- if (process.env["AWS_BEARER_TOKEN_BEDROCK"] || process.env["AWS_ACCESS_KEY_ID"] && process.env["AWS_SECRET_ACCESS_KEY"] || process.env["AWS_SHARED_CREDENTIALS_FILE"] || process.env["AWS_CONFIG_FILE"] || process.env["AWS_PROFILE"] || process.env["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] || process.env["AWS_CONTAINER_CREDENTIALS_FULL_URI"] || process.env["AWS_WEB_IDENTITY_TOKEN_FILE"]) {
1646
- return true;
1647
- }
1648
- const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir3();
1649
- if (home) {
1650
- const awsDir = join6(home, ".aws");
1651
- const credentialsPath = process.env["AWS_SHARED_CREDENTIALS_FILE"] ?? join6(awsDir, "credentials");
1652
- const configPath = process.env["AWS_CONFIG_FILE"] ?? join6(awsDir, "config");
1653
- if (existsSync4(credentialsPath) || existsSync4(configPath)) return true;
1654
- }
1655
- return false;
1656
- }
1657
- function createBedrockModel(bareModelId, headers) {
1658
- const region = process.env["AWS_REGION"] || process.env["AWS_DEFAULT_REGION"] || "us-east-1";
1659
- const bedrock = createAmazonBedrock({
1660
- region,
1661
- credentialProvider: fromNodeProviderChain(),
1662
- headers
1663
- });
1664
- return bedrock(bareModelId);
1665
- }
1666
- var BedrockGateway = class extends MastraModelGateway2 {
1667
- id = BEDROCK_GATEWAY_ID;
1668
- name = "Amazon Bedrock";
1669
- shouldEnable() {
1670
- return hasAwsCredentials();
1671
- }
1672
- handlesModel(modelId) {
1673
- return modelId === BEDROCK_GATEWAY_ID || modelId.startsWith(`${BEDROCK_GATEWAY_ID}/`);
1674
- }
1675
- async fetchProviders() {
1676
- return {
1677
- "amazon-bedrock": {
1678
- name: "Amazon Bedrock",
1679
- apiKeyEnvVar: "",
1680
- apiKeyHeader: "Authorization",
1681
- gateway: this.id,
1682
- models: [
1683
- "anthropic.claude-opus-4-1-20250805-v1:0",
1684
- "anthropic.claude-sonnet-4-20250514-v1:0"
1685
- ]
1686
- }
1687
- };
1688
- }
1689
- buildUrl(_modelId) {
1690
- return void 0;
1691
- }
1692
- async getApiKey(_modelId) {
1693
- return hasAwsCredentials() ? "aws-credential-chain" : "";
1694
- }
1695
- resolveAuth(_request) {
1696
- return hasAwsCredentials() ? { apiKey: "aws-credential-chain", source: "gateway" } : void 0;
1697
- }
1698
- resolveLanguageModel(args) {
1699
- const bare = args.modelId.startsWith(`${BEDROCK_GATEWAY_ID}/`) ? args.modelId.slice(BEDROCK_GATEWAY_ID.length + 1) : args.modelId;
1700
- return createBedrockModel(bare, args.headers);
1701
- }
1702
- };
1703
- function createBedrockGateway() {
1704
- return new BedrockGateway();
1705
- }
1706
-
1707
1957
  // src/gateways/oauth/openai-codex.ts
1708
1958
  import { createOpenAI } from "@ai-sdk/openai";
1709
1959
  import { wrapLanguageModel as wrapLanguageModel3 } from "ai";
@@ -1925,10 +2175,10 @@ function getDynamicModel({ requestContext }) {
1925
2175
  if (providerId === BEDROCK_GATEWAY_ID) {
1926
2176
  return createBedrockModel(bareModelId);
1927
2177
  }
1928
- if (providerId === "anthropic" && hasOAuthCredential("anthropic")) {
2178
+ if (providerId === "anthropic" && providerAuthRoute("anthropic", hasOAuthCredential("anthropic")) === "oauth") {
1929
2179
  return opencodeClaudeMaxProvider(bareModelId);
1930
2180
  }
1931
- if (providerId === "openai" && hasOAuthCredential("openai-codex")) {
2181
+ if (providerId === "openai" && providerAuthRoute("openai", hasOAuthCredential("openai-codex")) === "oauth") {
1932
2182
  return openaiCodexProvider(bareModelId);
1933
2183
  }
1934
2184
  return modelId;
@@ -3637,9 +3887,13 @@ export {
3637
3887
  completeOnboarding,
3638
3888
  rememberModel,
3639
3889
  rememberObservability,
3640
- hasGoogleCredentials,
3641
- hasAwsCredentials,
3642
3890
  getAuthStorage,
3891
+ NATIVE_PROVIDER_DEFINITIONS,
3892
+ normalizeModelSelection,
3893
+ environmentApiKeyConfigured,
3894
+ availableModels,
3895
+ discoverAvailableModels,
3896
+ groupModelsByProvider,
3643
3897
  GREETING,
3644
3898
  packageVersion,
3645
3899
  safeObservabilityEndpoint,
@@ -3648,4 +3902,4 @@ export {
3648
3902
  messageText,
3649
3903
  messageToolNames
3650
3904
  };
3651
- //# sourceMappingURL=chunk-GR2RFQE4.js.map
3905
+ //# sourceMappingURL=chunk-S237DEGI.js.map