@moltium/core 0.1.5 → 0.1.7

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/index.d.cts CHANGED
@@ -371,6 +371,8 @@ declare class Agent {
371
371
  private initLLM;
372
372
  private registerActions;
373
373
  private initSocialAdapters;
374
+ private initMoltbook;
375
+ private initTwitter;
374
376
  private postStartupMessages;
375
377
  private logPlatformError;
376
378
  private startAutonomousLoop;
package/dist/index.d.ts CHANGED
@@ -371,6 +371,8 @@ declare class Agent {
371
371
  private initLLM;
372
372
  private registerActions;
373
373
  private initSocialAdapters;
374
+ private initMoltbook;
375
+ private initTwitter;
374
376
  private postStartupMessages;
375
377
  private logPlatformError;
376
378
  private startAutonomousLoop;
package/dist/index.js CHANGED
@@ -1002,46 +1002,104 @@ var Agent = class {
1002
1002
  }
1003
1003
  }
1004
1004
  async initSocialAdapters() {
1005
- const { social } = this.config;
1006
- if (social.moltbook?.enabled) {
1007
- const baseUrl = social.moltbook.baseUrl || "https://www.moltbook.com/api/v1";
1008
- if (!social.moltbook.apiKey || social.moltbook.apiKey === "your-moltbook-key-here") {
1009
- logger4.error("Moltbook: SKIPPED \u2014 MOLTBOOK_API_KEY is missing or still a placeholder.");
1010
- logger4.error(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
1011
- } else {
1012
- logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
1013
- const adapter = new MoltbookAdapter(social.moltbook);
1014
- try {
1015
- await adapter.connect();
1016
- this.socialAdapters["moltbook"] = adapter;
1017
- logger4.info("Moltbook: Connected successfully (GET /agents/me OK)");
1018
- } catch (error) {
1019
- logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
1020
- this.logPlatformError("Moltbook", error);
1021
- }
1005
+ const social = this.config.social;
1006
+ await this.initMoltbook(social);
1007
+ await this.initTwitter(social);
1008
+ if (Object.keys(this.socialAdapters).length === 0) {
1009
+ logger4.warn("Social: No adapters connected. Set MOLTBOOK_API_KEY or Twitter env vars in your .env to enable.");
1010
+ }
1011
+ }
1012
+ async initMoltbook(social) {
1013
+ const envKey = process.env.MOLTBOOK_API_KEY;
1014
+ const configMoltbook = social.moltbook;
1015
+ const apiKey = configMoltbook?.apiKey || envKey || "";
1016
+ const isPlaceholder = !apiKey || apiKey === "your-moltbook-key-here";
1017
+ const explicitlyDisabled = configMoltbook && configMoltbook.enabled === false;
1018
+ const shouldConnect = !isPlaceholder && !explicitlyDisabled;
1019
+ if (explicitlyDisabled) {
1020
+ logger4.info("Moltbook: Disabled in config (enabled: false) \u2014 skipping");
1021
+ return;
1022
+ }
1023
+ if (isPlaceholder) {
1024
+ if (configMoltbook?.enabled || envKey) {
1025
+ logger4.warn("Moltbook: MOLTBOOK_API_KEY is missing or still a placeholder.");
1026
+ logger4.warn(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
1022
1027
  }
1023
- } else if (social.moltbook) {
1024
- logger4.info("Moltbook: Configured but disabled (enabled: false)");
1025
- }
1026
- if (social.twitter?.enabled) {
1027
- const creds = social.twitter.credentials;
1028
- if (!creds?.apiKey || creds.apiKey === "your-twitter-api-key") {
1029
- logger4.error("Twitter: SKIPPED \u2014 credentials are missing or still placeholders.");
1030
- logger4.error(" Fix: Set valid Twitter keys in your .env file.");
1031
- } else {
1032
- logger4.info("Twitter: Connecting...");
1033
- const adapter = new TwitterAdapter(social.twitter);
1034
- try {
1035
- await adapter.connect();
1036
- this.socialAdapters["twitter"] = adapter;
1037
- logger4.info("Twitter: Connected successfully");
1038
- } catch (error) {
1039
- logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
1040
- this.logPlatformError("Twitter", error);
1041
- }
1028
+ return;
1029
+ }
1030
+ if (!shouldConnect) return;
1031
+ const source = configMoltbook?.apiKey ? "config" : "environment";
1032
+ const baseUrl = configMoltbook?.baseUrl || process.env.MOLTBOOK_BASE_URL || "https://www.moltbook.com/api/v1";
1033
+ const defaultSubmolt = configMoltbook?.defaultSubmolt || "general";
1034
+ const effectiveConfig = {
1035
+ enabled: true,
1036
+ apiKey,
1037
+ baseUrl,
1038
+ defaultSubmolt,
1039
+ ...configMoltbook,
1040
+ // Ensure env-resolved values win when config didn't set them
1041
+ ...configMoltbook?.apiKey ? {} : { apiKey },
1042
+ ...configMoltbook?.baseUrl ? {} : { baseUrl }
1043
+ };
1044
+ logger4.info(`Moltbook: API key detected from ${source}`);
1045
+ logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
1046
+ const adapter = new MoltbookAdapter(effectiveConfig);
1047
+ try {
1048
+ await adapter.connect();
1049
+ this.socialAdapters["moltbook"] = adapter;
1050
+ social.moltbook = effectiveConfig;
1051
+ logger4.info(`Moltbook: Connected successfully (submolt: ${defaultSubmolt})`);
1052
+ } catch (error) {
1053
+ logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
1054
+ this.logPlatformError("Moltbook", error);
1055
+ }
1056
+ }
1057
+ async initTwitter(social) {
1058
+ const configTwitter = social.twitter;
1059
+ const envApiKey = process.env.TWITTER_API_KEY;
1060
+ const envApiSecret = process.env.TWITTER_API_SECRET;
1061
+ const envAccessToken = process.env.TWITTER_ACCESS_TOKEN;
1062
+ const envAccessSecret = process.env.TWITTER_ACCESS_SECRET;
1063
+ const creds = configTwitter?.credentials;
1064
+ const apiKey = creds?.apiKey || envApiKey || "";
1065
+ const apiSecret = creds?.apiSecret || envApiSecret || "";
1066
+ const accessToken = creds?.accessToken || envAccessToken || "";
1067
+ const accessSecret = creds?.accessSecret || envAccessSecret || "";
1068
+ const hasKey = apiKey && apiKey !== "your-twitter-api-key";
1069
+ const hasAllCreds = hasKey && apiSecret && accessToken && accessSecret;
1070
+ const explicitlyDisabled = configTwitter && configTwitter.enabled === false;
1071
+ if (explicitlyDisabled) {
1072
+ logger4.info("Twitter: Disabled in config (enabled: false) \u2014 skipping");
1073
+ return;
1074
+ }
1075
+ if (!hasKey) {
1076
+ if (configTwitter?.enabled || envApiKey) {
1077
+ logger4.warn("Twitter: Credentials are missing or still placeholders.");
1078
+ logger4.warn(" Fix: Set valid Twitter keys in your .env file.");
1042
1079
  }
1043
- } else if (social.twitter) {
1044
- logger4.info("Twitter: Configured but disabled (enabled: false)");
1080
+ return;
1081
+ }
1082
+ if (!hasAllCreds) {
1083
+ logger4.warn("Twitter: Some credentials are missing. Need: TWITTER_API_KEY, TWITTER_API_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET");
1084
+ return;
1085
+ }
1086
+ const source = creds?.apiKey ? "config" : "environment";
1087
+ logger4.info(`Twitter: Credentials detected from ${source}`);
1088
+ logger4.info("Twitter: Connecting...");
1089
+ const effectiveConfig = {
1090
+ enabled: true,
1091
+ ...configTwitter,
1092
+ credentials: { apiKey, apiSecret, accessToken, accessSecret }
1093
+ };
1094
+ const adapter = new TwitterAdapter(effectiveConfig);
1095
+ try {
1096
+ await adapter.connect();
1097
+ this.socialAdapters["twitter"] = adapter;
1098
+ social.twitter = effectiveConfig;
1099
+ logger4.info("Twitter: Connected successfully");
1100
+ } catch (error) {
1101
+ logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
1102
+ this.logPlatformError("Twitter", error);
1045
1103
  }
1046
1104
  }
1047
1105
  async postStartupMessages() {
@@ -1240,8 +1298,10 @@ var MarkdownParser = class {
1240
1298
  for (const child of section.children) {
1241
1299
  const platform = child.title.toLowerCase();
1242
1300
  const fields = this.parseKeyValueLines(child.content);
1301
+ const enabled = fields["enabled"] === "true";
1302
+ delete fields["enabled"];
1243
1303
  social[platform] = {
1244
- enabled: fields["enabled"] === "true",
1304
+ enabled,
1245
1305
  ...fields
1246
1306
  };
1247
1307
  }