@bonginkan/maria 4.2.3 → 4.2.5

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/cli.cjs CHANGED
@@ -7,7 +7,7 @@ var dotenv = require('dotenv');
7
7
  var chalk17 = require('chalk');
8
8
  var os = require('os');
9
9
  var fsp = require('fs/promises');
10
- var crypto = require('crypto');
10
+ var crypto2 = require('crypto');
11
11
  var http = require('http');
12
12
  var url = require('url');
13
13
  var open = require('open');
@@ -55,7 +55,7 @@ var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
55
55
  var chalk17__default = /*#__PURE__*/_interopDefault(chalk17);
56
56
  var os__namespace = /*#__PURE__*/_interopNamespace(os);
57
57
  var fsp__namespace = /*#__PURE__*/_interopNamespace(fsp);
58
- var crypto__default = /*#__PURE__*/_interopDefault(crypto);
58
+ var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
59
59
  var http__default = /*#__PURE__*/_interopDefault(http);
60
60
  var open__default = /*#__PURE__*/_interopDefault(open);
61
61
  var Stream__default = /*#__PURE__*/_interopDefault(Stream);
@@ -600,8 +600,8 @@ var init_TokenStorage = __esm({
600
600
  async saveToFile(tokens) {
601
601
  await fsp__namespace.default.mkdir(this.CONFIG_DIR, { recursive: true });
602
602
  const key2 = await this.getEncryptionKey();
603
- const iv = crypto__default.default.randomBytes(16);
604
- const cipher = crypto__default.default.createCipheriv("aes-256-gcm", key2, iv);
603
+ const iv = crypto2__default.default.randomBytes(16);
604
+ const cipher = crypto2__default.default.createCipheriv("aes-256-gcm", key2, iv);
605
605
  const tokenData = JSON.stringify(tokens);
606
606
  let encrypted = cipher.update(tokenData, "utf8", "hex");
607
607
  encrypted += cipher.final("hex");
@@ -643,7 +643,7 @@ var init_TokenStorage = __esm({
643
643
  const key2 = await this.getEncryptionKey();
644
644
  const iv = Buffer.from(fileData.iv, "hex");
645
645
  const authTag = Buffer.from(fileData.authTag, "hex");
646
- const decipher = crypto__default.default.createDecipheriv("aes-256-gcm", key2, iv);
646
+ const decipher = crypto2__default.default.createDecipheriv("aes-256-gcm", key2, iv);
647
647
  decipher.setAuthTag(authTag);
648
648
  let decrypted = decipher.update(fileData.data, "hex", "utf8");
649
649
  decrypted += decipher.final("utf8");
@@ -659,7 +659,7 @@ var init_TokenStorage = __esm({
659
659
  try {
660
660
  const key2 = await this.getEncryptionKey();
661
661
  const keyBuffer = Buffer.from(key2.slice(0, 32));
662
- const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", keyBuffer, Buffer.alloc(16, 0));
662
+ const decipher = crypto2__default.default.createDecipheriv("aes-256-cbc", keyBuffer, Buffer.alloc(16, 0));
663
663
  let decrypted = decipher.update(fileData.data, "hex", "utf8");
664
664
  decrypted += decipher.final("utf8");
665
665
  const tokens = JSON.parse(decrypted);
@@ -674,7 +674,7 @@ var init_TokenStorage = __esm({
674
674
  */
675
675
  async getEncryptionKey() {
676
676
  const machineId = `maria-cli:${os__namespace.default.hostname()}:${os__namespace.default.platform()}:${os__namespace.default.arch()}:${os__namespace.default.userInfo().username}`;
677
- return crypto__default.default.createHash("sha256").update(machineId).digest().slice(0, 32);
677
+ return crypto2__default.default.createHash("sha256").update(machineId).digest().slice(0, 32);
678
678
  }
679
679
  /**
680
680
  * Check if secure storage is available
@@ -701,14 +701,33 @@ var init_AuthenticationManager = __esm({
701
701
  // 2 minutes clock skew tolerance
702
702
  constructor() {
703
703
  this.tokenStorage = new TokenStorage();
704
- this.authBase = process.env.MARIA_AUTH_BASE || "https://auth.maria-code.ai";
705
- if (this.authBase === "https://auth.maria-code.ai") {
706
- this.authBase = "https://auth-server-1098737975582.us-central1.run.app";
707
- console.debug("Using Cloud Run URL for auth (DNS pending for auth.maria-code.ai)");
708
- }
709
- this.apiBase = process.env.MARIA_API_BASE || "https://api.maria-code.ai";
704
+ this.authBase = process.env.MARIA_AUTH_BASE || this.getAuthBaseUrl();
705
+ this.apiBase = process.env.MARIA_API_BASE || this.getApiBaseUrl();
710
706
  this.clientId = process.env.MARIA_CLIENT_ID || "maria-cli";
711
707
  }
708
+ getAuthBaseUrl() {
709
+ if (process.env.MARIA_AUTH_MODE === "local") {
710
+ console.debug("Using local auth server (development mode)");
711
+ return "http://localhost:3001";
712
+ }
713
+ const cloudRunUrl = "https://auth-server-i227ftjidq-uc.a.run.app";
714
+ if (process.env.MARIA_USE_CUSTOM_DOMAIN === "true") {
715
+ console.debug("Attempting to use custom domain auth.maria-code.ai");
716
+ return "https://auth.maria-code.ai";
717
+ }
718
+ console.debug("Using Cloud Run URL for auth:", cloudRunUrl);
719
+ return cloudRunUrl;
720
+ }
721
+ getApiBaseUrl() {
722
+ if (process.env.MARIA_AUTH_MODE === "local") {
723
+ return "http://localhost:3000/api";
724
+ }
725
+ const cloudRunApiUrl = "https://maria-code-i227ftjidq-uc.a.run.app";
726
+ if (process.env.MARIA_USE_CUSTOM_DOMAIN === "true") {
727
+ return "https://api.maria-code.ai";
728
+ }
729
+ return cloudRunApiUrl;
730
+ }
712
731
  /**
713
732
  * Check if user is authenticated
714
733
  */
@@ -737,6 +756,27 @@ var init_AuthenticationManager = __esm({
737
756
  * Get current authenticated user
738
757
  */
739
758
  async getCurrentUser() {
759
+ if (process.env.MARIA_AUTH_MODE === "local") {
760
+ const tokens2 = await this.tokenStorage.load();
761
+ if (!tokens2) {
762
+ throw new AuthenticationRequiredError(ERROR_MESSAGES.AUTH_REQUIRED);
763
+ }
764
+ return {
765
+ id: "local-dev-user",
766
+ email: "developer@localhost",
767
+ name: "Local Developer",
768
+ plan: "ultra",
769
+ usage: {
770
+ requests: Math.floor(Math.random() * 100),
771
+ // Random usage for testing
772
+ requestLimit: 999999,
773
+ requestsRemaining: 999999,
774
+ resetAt: Date.now() + 30 * 24 * 60 * 60 * 1e3
775
+ },
776
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
777
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
778
+ };
779
+ }
740
780
  const tokens = await this.getValidTokens();
741
781
  if (!tokens) {
742
782
  throw new AuthenticationRequiredError(ERROR_MESSAGES.AUTH_REQUIRED);
@@ -774,6 +814,9 @@ var init_AuthenticationManager = __esm({
774
814
  const user2 = await this.getCurrentUser();
775
815
  return { success: true, user: user2 };
776
816
  }
817
+ if (process.env.MARIA_AUTH_MODE === "local") {
818
+ return await this.loginWithLocalMock();
819
+ }
777
820
  let tokens;
778
821
  if (options.device) {
779
822
  tokens = await this.loginWithDeviceFlow();
@@ -781,6 +824,19 @@ var init_AuthenticationManager = __esm({
781
824
  try {
782
825
  tokens = await this.loginWithPKCEFlow();
783
826
  } catch (error2) {
827
+ if (error2.message?.includes("ECONNREFUSED") || error2.message?.includes("fetch failed")) {
828
+ console.error("\n\u274C Authentication service is currently unavailable");
829
+ console.error("Please try one of the following:");
830
+ console.error("1. Set MARIA_AUTH_MODE=local for local development");
831
+ console.error("2. Check your internet connection");
832
+ console.error("3. Visit https://status.maria-code.ai for service status\n");
833
+ if (!process.env.MARIA_AUTH_MODE) {
834
+ console.log("\u{1F4A1} Tip: Run with local auth mode:");
835
+ console.log(" export MARIA_AUTH_MODE=local");
836
+ console.log(" maria /login\n");
837
+ }
838
+ throw new Error("Authentication service unavailable. See above for alternatives.");
839
+ }
784
840
  console.warn("PKCE flow failed, falling back to device flow");
785
841
  tokens = await this.loginWithDeviceFlow();
786
842
  }
@@ -795,6 +851,43 @@ var init_AuthenticationManager = __esm({
795
851
  };
796
852
  }
797
853
  }
854
+ /**
855
+ * Local mock authentication for development
856
+ */
857
+ async loginWithLocalMock() {
858
+ console.log("\u{1F510} Local Development Mode - Mock Authentication");
859
+ const mockTokens = {
860
+ idToken: "mock-id-token-" + crypto2__default.default.randomBytes(16).toString("hex"),
861
+ accessToken: "mock-access-token-" + crypto2__default.default.randomBytes(16).toString("hex"),
862
+ refreshToken: "mock-refresh-token-" + crypto2__default.default.randomBytes(16).toString("hex"),
863
+ expiresAt: Date.now() + 24 * 60 * 60 * 1e3
864
+ // 24 hours
865
+ };
866
+ await this.tokenStorage.save(mockTokens);
867
+ const mockUser = {
868
+ id: "local-dev-user",
869
+ email: "developer@localhost",
870
+ name: "Local Developer",
871
+ plan: "ultra",
872
+ // Give full access in dev mode
873
+ usage: {
874
+ requests: 0,
875
+ requestLimit: 999999,
876
+ requestsRemaining: 999999,
877
+ resetAt: Date.now() + 30 * 24 * 60 * 60 * 1e3
878
+ },
879
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
880
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
881
+ };
882
+ console.log("\u2705 Logged in as developer@localhost (Local Mode)");
883
+ console.log(" Plan: Ultra (Development)");
884
+ console.log(" All features enabled for testing\n");
885
+ return {
886
+ success: true,
887
+ user: mockUser,
888
+ tokens: mockTokens
889
+ };
890
+ }
798
891
  /**
799
892
  * Logout and clean up
800
893
  */
@@ -956,9 +1049,9 @@ var init_AuthenticationManager = __esm({
956
1049
  * Generate PKCE parameters
957
1050
  */
958
1051
  generatePKCEParams() {
959
- const codeVerifier = crypto__default.default.randomBytes(32).toString("base64url");
960
- const codeChallenge = crypto__default.default.createHash("sha256").update(codeVerifier).digest("base64url");
961
- const state = crypto__default.default.randomBytes(16).toString("hex");
1052
+ const codeVerifier = crypto2__default.default.randomBytes(32).toString("base64url");
1053
+ const codeChallenge = crypto2__default.default.createHash("sha256").update(codeVerifier).digest("base64url");
1054
+ const state = crypto2__default.default.randomBytes(16).toString("hex");
962
1055
  return { codeVerifier, codeChallenge, state };
963
1056
  }
964
1057
  /**
@@ -1121,7 +1214,7 @@ var init_AuthenticationManager = __esm({
1121
1214
  */
1122
1215
  secureCompare(a2, b) {
1123
1216
  if (a2.length !== b.length) return false;
1124
- return crypto__default.default.timingSafeEqual(Buffer.from(a2), Buffer.from(b));
1217
+ return crypto2__default.default.timingSafeEqual(Buffer.from(a2), Buffer.from(b));
1125
1218
  }
1126
1219
  /**
1127
1220
  * HTML page for successful authentication
@@ -1260,7 +1353,7 @@ var init_withAuth = __esm({
1260
1353
  });
1261
1354
  function rng() {
1262
1355
  if (poolPtr > rnds8Pool.length - 16) {
1263
- crypto__default.default.randomFillSync(rnds8Pool);
1356
+ crypto2__default.default.randomFillSync(rnds8Pool);
1264
1357
  poolPtr = 0;
1265
1358
  }
1266
1359
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -1290,7 +1383,7 @@ var native_default;
1290
1383
  var init_native = __esm({
1291
1384
  "node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/native.js"() {
1292
1385
  native_default = {
1293
- randomUUID: crypto__default.default.randomUUID
1386
+ randomUUID: crypto2__default.default.randomUUID
1294
1387
  };
1295
1388
  }
1296
1389
  });
@@ -9387,6 +9480,7 @@ var init_groq_provider = __esm({
9387
9480
  "src/providers/groq-provider.ts"() {
9388
9481
  init_base_provider();
9389
9482
  GroqProvider = class extends UnifiedBaseProvider {
9483
+ id = "groq";
9390
9484
  name = "groq";
9391
9485
  modelsCache;
9392
9486
  constructor(apiKey) {
@@ -9412,6 +9506,15 @@ var init_groq_provider = __esm({
9412
9506
  }
9413
9507
  }
9414
9508
  async getModels() {
9509
+ const models = [
9510
+ "llama-3.3-70b-versatile",
9511
+ "llama-3.2-90b-vision-preview",
9512
+ "mixtral-8x7b-32768",
9513
+ "gemma2-9b-it"
9514
+ ];
9515
+ return models;
9516
+ }
9517
+ async getModelInfo() {
9415
9518
  if (this.modelsCache) {
9416
9519
  return this.modelsCache;
9417
9520
  }
@@ -9464,33 +9567,102 @@ var init_groq_provider = __esm({
9464
9567
  this.modelsCache = models;
9465
9568
  return models;
9466
9569
  }
9570
+ async complete(prompt, req) {
9571
+ if (!await this.isAvailable()) {
9572
+ throw new Error("Groq API not available");
9573
+ }
9574
+ const model = req.model || "mixtral-8x7b-32768";
9575
+ const payload = {
9576
+ model,
9577
+ messages: [{ role: "user", content: prompt }],
9578
+ temperature: req.temperature || 0.7,
9579
+ max_tokens: req.maxTokens || 4e3,
9580
+ stream: false
9581
+ };
9582
+ const response2 = await this.makeRequest(
9583
+ `${this.apiBase}/chat/completions`,
9584
+ {
9585
+ method: "POST",
9586
+ headers: {
9587
+ Authorization: `Bearer ${this.apiKey}`,
9588
+ ...req.headers
9589
+ },
9590
+ body: payload,
9591
+ timeout: req.timeoutMs
9592
+ }
9593
+ );
9594
+ return {
9595
+ content: response2.choices[0]?.message?.content || "",
9596
+ model,
9597
+ usage: {
9598
+ promptTokens: response2.usage?.prompt_tokens || 0,
9599
+ completionTokens: response2.usage?.completion_tokens || 0,
9600
+ totalTokens: response2.usage?.total_tokens || 0
9601
+ },
9602
+ finishReason: response2.choices[0]?.finish_reason || "stop"
9603
+ };
9604
+ }
9605
+ async stream(prompt, req) {
9606
+ if (!await this.isAvailable()) {
9607
+ throw new Error("Groq API not available");
9608
+ }
9609
+ const model = req.model || "mixtral-8x7b-32768";
9610
+ const payload = {
9611
+ model,
9612
+ messages: [{ role: "user", content: prompt }],
9613
+ temperature: req.temperature || 0.7,
9614
+ max_tokens: req.maxTokens || 4e3,
9615
+ stream: true
9616
+ };
9617
+ const stream = await this.makeStreamRequest(
9618
+ `${this.apiBase}/chat/completions`,
9619
+ {
9620
+ method: "POST",
9621
+ headers: {
9622
+ Authorization: `Bearer ${this.apiKey}`,
9623
+ ...req.headers
9624
+ },
9625
+ body: payload,
9626
+ timeout: req.timeoutMs
9627
+ }
9628
+ );
9629
+ async function* chunkGenerator() {
9630
+ for await (const chunk of stream) {
9631
+ yield {
9632
+ content: chunk,
9633
+ delta: chunk
9634
+ };
9635
+ }
9636
+ }
9637
+ return chunkGenerator();
9638
+ }
9467
9639
  async chat(request) {
9468
9640
  if (!await this.isAvailable()) {
9469
9641
  throw new Error("Groq API not available");
9470
9642
  }
9471
- const _model = request._model || "mixtral-8x7b-32768";
9643
+ const model = request.model || "mixtral-8x7b-32768";
9472
9644
  const _startTime = Date.now();
9473
9645
  const _payload = {
9474
- _model,
9646
+ model,
9475
9647
  messages: request.messages,
9476
9648
  temperature: request.temperature || 0.7,
9477
- maxtokens: request.maxTokens || 4e3,
9478
- _stream: request._stream || false
9649
+ max_tokens: request.maxTokens || 4e3,
9650
+ stream: request.stream || false
9479
9651
  };
9480
- if (request._stream) {
9481
- const _stream = await this.makeStreamRequest(
9652
+ if (request.stream) {
9653
+ const stream = await this.makeStreamRequest(
9482
9654
  `${this.apiBase}/chat/completions`,
9483
9655
  {
9484
9656
  method: "POST",
9485
9657
  headers: {
9486
9658
  Authorization: `Bearer ${this.apiKey}`
9487
9659
  },
9488
- body: JSON.stringify(_payload)
9660
+ body: _payload
9489
9661
  }
9490
9662
  );
9491
9663
  return {
9492
- _stream,
9493
- _model,
9664
+ stream,
9665
+ model,
9494
9666
  provider: this.name,
9495
9667
  responseTime: Date.now() - _startTime
9496
9668
  };
@@ -9502,12 +9674,12 @@ var init_groq_provider = __esm({
9502
9674
  headers: {
9503
9675
  Authorization: `Bearer ${this.apiKey}`
9504
9676
  },
9505
- body: JSON.stringify(_payload)
9677
+ body: _payload
9506
9678
  }
9507
9679
  );
9508
9680
  return {
9509
9681
  content: _response.choices[0]?.message?.content || "",
9510
- _model,
9682
+ model,
9511
9683
  provider: this.name,
9512
9684
  usage: {
9513
9685
  promptTokens: _response.usage?.prompt_tokens || 0,
@@ -9524,7 +9696,7 @@ var init_groq_provider = __esm({
9524
9696
  const _base64Image = _image.toString("base64");
9525
9697
  const _startTime = Date.now();
9526
9698
  const _payload = {
9527
- _model: "llama-3.2-90b-vision-preview",
9699
+ model: "llama-3.2-90b-vision-preview",
9528
9700
  messages: [
9529
9701
  {
9530
9702
  role: "user",
@@ -9539,7 +9711,7 @@ var init_groq_provider = __esm({
9539
9711
  ]
9540
9712
  }
9541
9713
  ],
9542
- maxtokens: 4e3
9714
+ max_tokens: 4e3
9543
9715
  };
9544
9716
  const _response = await this.makeRequest(
9545
9717
  `${this.apiBase}/chat/completions`,
@@ -9548,12 +9720,12 @@ var init_groq_provider = __esm({
9548
9720
  headers: {
9549
9721
  Authorization: `Bearer ${this.apiKey}`
9550
9722
  },
9551
- body: JSON.stringify(_payload)
9723
+ body: _payload
9552
9724
  }
9553
9725
  );
9554
9726
  return {
9555
9727
  content: _response.choices[0]?.message?.content || "",
9556
- _model: "llama-3.2-90b-vision-preview",
9728
+ model: "llama-3.2-90b-vision-preview",
9557
9729
  provider: this.name,
9558
9730
  usage: {
9559
9731
  promptTokens: _response.usage?.prompt_tokens || 0,
@@ -13533,7 +13705,7 @@ var init_quick_persistence = __esm({
13533
13705
  }
13534
13706
  }
13535
13707
  static hash(text) {
13536
- return crypto.createHash("sha256").update(text).digest("hex");
13708
+ return crypto2.createHash("sha256").update(text).digest("hex");
13537
13709
  }
13538
13710
  static async save(mem) {
13539
13711
  await this.init();
@@ -13761,7 +13933,6 @@ var init_bigquery_telemetry = __esm({
13761
13933
  this.httpEndpoint = process.env.TELEMETRY_ENDPOINT || null;
13762
13934
  if (this.isEnabled) {
13763
13935
  this.initialize().catch((error2) => {
13764
- console.error("[Telemetry] Initialization error:", error2);
13765
13936
  });
13766
13937
  }
13767
13938
  }
@@ -13786,7 +13957,6 @@ var init_bigquery_telemetry = __esm({
13786
13957
  keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
13787
13958
  });
13788
13959
  } catch (error2) {
13789
- console.error("[Telemetry] Failed to initialize BigQuery:", error2);
13790
13960
  }
13791
13961
  }
13792
13962
  this.startFlushTimer();
@@ -13828,7 +13998,6 @@ var init_bigquery_telemetry = __esm({
13828
13998
  } else {
13829
13999
  }
13830
14000
  } catch (error2) {
13831
- console.error("[Telemetry] Flush failed:", error2);
13832
14001
  if (this.telemetryQueue.length < this.config.batchSize * 2) {
13833
14002
  this.telemetryQueue = [...dataToFlush, ...this.telemetryQueue];
13834
14003
  }
@@ -13892,7 +14061,6 @@ var init_bigquery_telemetry = __esm({
13892
14061
  }
13893
14062
  })
13894
14063
  }).catch((error2) => {
13895
- console.error("[Telemetry] HTTP flush failed:", error2);
13896
14064
  throw error2;
13897
14065
  });
13898
14066
  if (!response2.ok) {
@@ -13906,7 +14074,6 @@ var init_bigquery_telemetry = __esm({
13906
14074
  if (this.flushTimer) return;
13907
14075
  this.flushTimer = setInterval(() => {
13908
14076
  this.flush().catch((error2) => {
13909
- console.error("[Telemetry] Timer flush failed:", error2);
13910
14077
  });
13911
14078
  }, this.config.flushIntervalMs);
13912
14079
  }
@@ -32187,7 +32354,7 @@ var init_package = __esm({
32187
32354
  "package.json"() {
32188
32355
  package_default = {
32189
32356
  name: "@bonginkan/maria",
32190
- version: "4.2.3",
32357
+ version: "4.2.5",
32191
32358
  description: "\u{1F680} MARIA v4.2.0 - Enterprise AI Development Platform with 100% Command Availability. Features 74 production-ready commands with comprehensive fallback implementation, local LLM support, and zero external dependencies. Includes natural language coding, AI safety evaluation, intelligent evolution system, episodic memory with PII masking, and real-time monitoring dashboard. Built with TypeScript AST-powered code generation, OAuth2.0 + PKCE authentication, quantum-resistant cryptography, and enterprise-grade performance.",
32192
32359
  keywords: [
32193
32360
  "ai",