@bonginkan/maria 4.2.5 → 4.2.6

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.
@@ -7135,16 +7135,12 @@ var init_SecretManagerIntegration = __esm({
7135
7135
  const [version] = await this.client.accessSecretVersion({ name: name2 });
7136
7136
  const payload = version.payload?.data;
7137
7137
  if (!payload) {
7138
- console.error(`Secret ${secretName} has no payload`);
7139
7138
  return void 0;
7140
7139
  }
7141
7140
  const secret = payload.toString();
7142
7141
  this.cacheSecret(secretName, secret);
7143
7142
  return secret;
7144
7143
  } catch (error2) {
7145
- if (error2.code !== 5) {
7146
- console.error(`Failed to access secret ${secretName}:`, error2);
7147
- }
7148
7144
  return this.getFallbackFromEnv(provider);
7149
7145
  }
7150
7146
  }
@@ -7227,7 +7223,6 @@ var init_SecretManagerIntegration = __esm({
7227
7223
  this.cacheExpiry.delete(secretName);
7228
7224
  return true;
7229
7225
  } catch (error2) {
7230
- console.error(`Failed to create/update secret ${secretName}:`, error2);
7231
7226
  return false;
7232
7227
  }
7233
7228
  }
@@ -21846,7 +21841,7 @@ var init_package = __esm({
21846
21841
  "package.json"() {
21847
21842
  package_default = {
21848
21843
  name: "@bonginkan/maria",
21849
- version: "4.2.5",
21844
+ version: "4.2.6",
21850
21845
  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.",
21851
21846
  keywords: [
21852
21847
  "ai",
@@ -22854,42 +22849,203 @@ var init_TokenStorage = __esm({
22854
22849
  }
22855
22850
  });
22856
22851
 
22852
+ // src/services/cli-auth/AuthSecretManager.ts
22853
+ var import_secret_manager2, AuthSecretManager, authSecretManager;
22854
+ var init_AuthSecretManager = __esm({
22855
+ "src/services/cli-auth/AuthSecretManager.ts"() {
22856
+ import_secret_manager2 = require("@google-cloud/secret-manager");
22857
+ AuthSecretManager = class {
22858
+ client;
22859
+ cache = /* @__PURE__ */ new Map();
22860
+ cacheExpiry = /* @__PURE__ */ new Map();
22861
+ CACHE_TTL = 36e5;
22862
+ // 1 hour
22863
+ projectId;
22864
+ constructor() {
22865
+ this.projectId = process.env.GCLOUD_PROJECT || "maria-code-470602";
22866
+ this.client = new import_secret_manager2.SecretManagerServiceClient();
22867
+ }
22868
+ /**
22869
+ * Get authentication configuration from Secret Manager
22870
+ */
22871
+ async getAuthConfig() {
22872
+ const [authBase, apiBase, clientId] = await Promise.all([
22873
+ this.getSecret("maria-auth-server-url").catch(() => null),
22874
+ this.getSecret("maria-api-server-url").catch(() => null),
22875
+ this.getSecret("maria-cli-client-id").catch(() => null)
22876
+ ]);
22877
+ return {
22878
+ authBase: authBase || this.getAuthBaseUrlFallback(),
22879
+ apiBase: apiBase || this.getApiBaseUrlFallback(),
22880
+ clientId: clientId || process.env.MARIA_CLIENT_ID || "maria-cli"
22881
+ };
22882
+ }
22883
+ /**
22884
+ * Get a specific secret from Secret Manager
22885
+ */
22886
+ async getSecret(secretName) {
22887
+ const cached = this.getCachedSecret(secretName);
22888
+ if (cached) {
22889
+ return cached;
22890
+ }
22891
+ try {
22892
+ const name2 = `projects/${this.projectId}/secrets/${secretName}/versions/latest`;
22893
+ const [version] = await this.client.accessSecretVersion({ name: name2 });
22894
+ const payload = version.payload?.data;
22895
+ if (!payload) {
22896
+ return null;
22897
+ }
22898
+ const secret = payload.toString();
22899
+ this.cacheSecret(secretName, secret);
22900
+ return secret;
22901
+ } catch (error2) {
22902
+ return null;
22903
+ }
22904
+ }
22905
+ /**
22906
+ * Get all OAuth configuration secrets
22907
+ */
22908
+ async getOAuthSecrets() {
22909
+ const secretNames = [
22910
+ "google-client-id",
22911
+ "google-client-secret",
22912
+ "github-client-id",
22913
+ "github-client-secret",
22914
+ "nextauth-secret",
22915
+ "firebase-project-id",
22916
+ "session-keys"
22917
+ ];
22918
+ const results = await Promise.allSettled(
22919
+ secretNames.map((name2) => this.getSecret(name2))
22920
+ );
22921
+ return {
22922
+ googleClientId: results[0].status === "fulfilled" ? results[0].value || void 0 : void 0,
22923
+ googleClientSecret: results[1].status === "fulfilled" ? results[1].value || void 0 : void 0,
22924
+ githubClientId: results[2].status === "fulfilled" ? results[2].value || void 0 : void 0,
22925
+ githubClientSecret: results[3].status === "fulfilled" ? results[3].value || void 0 : void 0,
22926
+ nextAuthSecret: results[4].status === "fulfilled" ? results[4].value || void 0 : void 0,
22927
+ firebaseProjectId: results[5].status === "fulfilled" ? results[5].value || void 0 : void 0,
22928
+ sessionKeys: results[6].status === "fulfilled" ? results[6].value || void 0 : void 0
22929
+ };
22930
+ }
22931
+ /**
22932
+ * Cache a secret value
22933
+ */
22934
+ cacheSecret(name2, value) {
22935
+ this.cache.set(name2, value);
22936
+ this.cacheExpiry.set(name2, Date.now() + this.CACHE_TTL);
22937
+ }
22938
+ /**
22939
+ * Get cached secret if not expired
22940
+ */
22941
+ getCachedSecret(name2) {
22942
+ const expiry = this.cacheExpiry.get(name2);
22943
+ if (!expiry || Date.now() > expiry) {
22944
+ this.cache.delete(name2);
22945
+ this.cacheExpiry.delete(name2);
22946
+ return null;
22947
+ }
22948
+ return this.cache.get(name2) || null;
22949
+ }
22950
+ /**
22951
+ * Clear all cached secrets
22952
+ */
22953
+ clearCache() {
22954
+ this.cache.clear();
22955
+ this.cacheExpiry.clear();
22956
+ }
22957
+ /**
22958
+ * Fallback for auth base URL
22959
+ */
22960
+ getAuthBaseUrlFallback() {
22961
+ if (process.env.MARIA_AUTH_MODE === "local") {
22962
+ return "http://localhost:3001";
22963
+ }
22964
+ if (process.env.MARIA_AUTH_BASE) {
22965
+ return process.env.MARIA_AUTH_BASE;
22966
+ }
22967
+ const cloudRunUrl = "https://auth-server-i227ftjidq-uc.a.run.app";
22968
+ return cloudRunUrl;
22969
+ }
22970
+ /**
22971
+ * Fallback for API base URL
22972
+ */
22973
+ getApiBaseUrlFallback() {
22974
+ if (process.env.MARIA_AUTH_MODE === "local") {
22975
+ return "http://localhost:3000/api";
22976
+ }
22977
+ if (process.env.MARIA_API_BASE) {
22978
+ return process.env.MARIA_API_BASE;
22979
+ }
22980
+ const cloudRunApiUrl = "https://maria-code-i227ftjidq-uc.a.run.app";
22981
+ return cloudRunApiUrl;
22982
+ }
22983
+ };
22984
+ authSecretManager = new AuthSecretManager();
22985
+ }
22986
+ });
22987
+
22857
22988
  // src/services/cli-auth/AuthenticationManager.ts
22858
22989
  var import_crypto4, import_http, import_url, import_open, AuthenticationManager, authManager;
22859
22990
  var init_AuthenticationManager = __esm({
22860
22991
  "src/services/cli-auth/AuthenticationManager.ts"() {
22861
22992
  init_types();
22862
22993
  init_TokenStorage();
22994
+ init_AuthSecretManager();
22863
22995
  import_crypto4 = __toESM(require("crypto"), 1);
22864
22996
  import_http = require("http");
22865
22997
  import_url = require("url");
22866
22998
  import_open = __toESM(require("open"), 1);
22867
22999
  AuthenticationManager = class {
22868
23000
  tokenStorage;
22869
- authBase;
22870
- apiBase;
22871
- clientId;
23001
+ secretManager;
23002
+ authBase = "";
23003
+ apiBase = "";
23004
+ clientId = "";
23005
+ initialized = false;
23006
+ initPromise = null;
22872
23007
  REFRESH_THRESHOLD = 5 * 60 * 1e3;
22873
23008
  // 5 minutes
22874
23009
  CLOCK_SKEW = 2 * 60 * 1e3;
22875
23010
  // 2 minutes clock skew tolerance
22876
23011
  constructor() {
22877
23012
  this.tokenStorage = new TokenStorage();
22878
- this.authBase = process.env.MARIA_AUTH_BASE || this.getAuthBaseUrl();
22879
- this.apiBase = process.env.MARIA_API_BASE || this.getApiBaseUrl();
22880
- this.clientId = process.env.MARIA_CLIENT_ID || "maria-cli";
23013
+ this.secretManager = new AuthSecretManager();
23014
+ this.initPromise = this.initialize();
23015
+ }
23016
+ /**
23017
+ * Initialize configuration from Secret Manager
23018
+ */
23019
+ async initialize() {
23020
+ try {
23021
+ const config2 = await this.secretManager.getAuthConfig();
23022
+ this.authBase = config2.authBase;
23023
+ this.apiBase = config2.apiBase;
23024
+ this.clientId = config2.clientId;
23025
+ this.initialized = true;
23026
+ } catch (error2) {
23027
+ this.authBase = this.getAuthBaseUrl();
23028
+ this.apiBase = this.getApiBaseUrl();
23029
+ this.clientId = process.env.MARIA_CLIENT_ID || "maria-cli";
23030
+ this.initialized = true;
23031
+ }
23032
+ }
23033
+ /**
23034
+ * Ensure the manager is initialized before use
23035
+ */
23036
+ async ensureInitialized() {
23037
+ if (!this.initialized && this.initPromise) {
23038
+ await this.initPromise;
23039
+ }
22881
23040
  }
22882
23041
  getAuthBaseUrl() {
22883
23042
  if (process.env.MARIA_AUTH_MODE === "local") {
22884
- console.debug("Using local auth server (development mode)");
22885
23043
  return "http://localhost:3001";
22886
23044
  }
22887
23045
  const cloudRunUrl = "https://auth-server-i227ftjidq-uc.a.run.app";
22888
23046
  if (process.env.MARIA_USE_CUSTOM_DOMAIN === "true") {
22889
- console.debug("Attempting to use custom domain auth.maria-code.ai");
22890
23047
  return "https://auth.maria-code.ai";
22891
23048
  }
22892
- console.debug("Using Cloud Run URL for auth:", cloudRunUrl);
22893
23049
  return cloudRunUrl;
22894
23050
  }
22895
23051
  getApiBaseUrl() {
@@ -22906,6 +23062,7 @@ var init_AuthenticationManager = __esm({
22906
23062
  * Check if user is authenticated
22907
23063
  */
22908
23064
  async isAuthenticated() {
23065
+ await this.ensureInitialized();
22909
23066
  try {
22910
23067
  const tokens = await this.tokenStorage.load();
22911
23068
  if (!tokens) return false;
@@ -22921,6 +23078,7 @@ var init_AuthenticationManager = __esm({
22921
23078
  * Require authenticated user (throws if not authenticated)
22922
23079
  */
22923
23080
  async requireUser() {
23081
+ await this.ensureInitialized();
22924
23082
  if (!await this.isAuthenticated()) {
22925
23083
  throw new AuthenticationRequiredError(ERROR_MESSAGES.AUTH_REQUIRED);
22926
23084
  }
@@ -22930,6 +23088,7 @@ var init_AuthenticationManager = __esm({
22930
23088
  * Get current authenticated user
22931
23089
  */
22932
23090
  async getCurrentUser() {
23091
+ await this.ensureInitialized();
22933
23092
  if (process.env.MARIA_AUTH_MODE === "local") {
22934
23093
  const tokens2 = await this.tokenStorage.load();
22935
23094
  if (!tokens2) {
@@ -22939,16 +23098,14 @@ var init_AuthenticationManager = __esm({
22939
23098
  id: "local-dev-user",
22940
23099
  email: "developer@localhost",
22941
23100
  name: "Local Developer",
22942
- plan: "ultra",
23101
+ plan: "ULTRA",
22943
23102
  usage: {
22944
23103
  requests: Math.floor(Math.random() * 100),
22945
23104
  // Random usage for testing
22946
23105
  requestLimit: 999999,
22947
- requestsRemaining: 999999,
22948
23106
  resetAt: Date.now() + 30 * 24 * 60 * 60 * 1e3
22949
23107
  },
22950
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
22951
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
23108
+ models: []
22952
23109
  };
22953
23110
  }
22954
23111
  const tokens = await this.getValidTokens();
@@ -22971,7 +23128,8 @@ var init_AuthenticationManager = __esm({
22971
23128
  if (!response2.ok) {
22972
23129
  throw new Error(`Failed to fetch user profile: ${response2.statusText}`);
22973
23130
  }
22974
- return await response2.json();
23131
+ const userData = await response2.json();
23132
+ return userData;
22975
23133
  } catch (error2) {
22976
23134
  if (error2 instanceof AuthenticationRequiredError || error2 instanceof QuotaExceededError) {
22977
23135
  throw error2;
@@ -22983,6 +23141,7 @@ var init_AuthenticationManager = __esm({
22983
23141
  * Login with OAuth2 PKCE flow
22984
23142
  */
22985
23143
  async login(options = {}) {
23144
+ await this.ensureInitialized();
22986
23145
  try {
22987
23146
  if (await this.isAuthenticated() && !options.force) {
22988
23147
  const user2 = await this.getCurrentUser();
@@ -23042,16 +23201,14 @@ var init_AuthenticationManager = __esm({
23042
23201
  id: "local-dev-user",
23043
23202
  email: "developer@localhost",
23044
23203
  name: "Local Developer",
23045
- plan: "ultra",
23204
+ plan: "ULTRA",
23046
23205
  // Give full access in dev mode
23047
23206
  usage: {
23048
23207
  requests: 0,
23049
23208
  requestLimit: 999999,
23050
- requestsRemaining: 999999,
23051
23209
  resetAt: Date.now() + 30 * 24 * 60 * 60 * 1e3
23052
23210
  },
23053
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
23054
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
23211
+ models: []
23055
23212
  };
23056
23213
  console.log("\u2705 Logged in as developer@localhost (Local Mode)");
23057
23214
  console.log(" Plan: Ultra (Development)");
@@ -23066,6 +23223,7 @@ var init_AuthenticationManager = __esm({
23066
23223
  * Logout and clean up
23067
23224
  */
23068
23225
  async logout(options = {}) {
23226
+ await this.ensureInitialized();
23069
23227
  try {
23070
23228
  const tokens = await this.tokenStorage.load();
23071
23229
  if (tokens && !options.force) {
@@ -23087,6 +23245,7 @@ var init_AuthenticationManager = __esm({
23087
23245
  * Refresh authentication token
23088
23246
  */
23089
23247
  async refreshToken() {
23248
+ await this.ensureInitialized();
23090
23249
  try {
23091
23250
  const tokens = await this.tokenStorage.load();
23092
23251
  if (!tokens?.refreshToken) return false;
@@ -23130,7 +23289,6 @@ var init_AuthenticationManager = __esm({
23130
23289
  */
23131
23290
  async checkPlanAccess(feature) {
23132
23291
  const user = await this.getCurrentUser();
23133
- const freeFeatures = ["chat", "code", "help", "status", "version"];
23134
23292
  const restrictedFeatures = ["image", "video", "voice", "advanced-search"];
23135
23293
  if (user.plan === "FREE" && restrictedFeatures.includes(feature)) {
23136
23294
  throw new PlanRestrictedError(ERROR_MESSAGES.PLAN_RESTRICTED);