@moltium/core 0.1.6 → 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,56 +1002,104 @@ var Agent = class {
1002
1002
  }
1003
1003
  }
1004
1004
  async initSocialAdapters() {
1005
- const { social } = this.config;
1006
- const configuredPlatforms = Object.keys(social).filter(
1007
- (k) => social[k] && typeof social[k] === "object"
1008
- );
1009
- if (configuredPlatforms.length === 0) {
1010
- logger4.warn("Social: No platforms configured. To post on startup, add a social platform to your config.");
1011
- logger4.warn(' Code-based: Add a moltbook or twitter section to agent.config.ts under "social".');
1012
- logger4.warn(' Markdown: Add a "### Moltbook" section under "## Social Platforms" in agent.md with "enabled: true".');
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");
1013
1021
  return;
1014
1022
  }
1015
- logger4.info(`Social: Found platforms in config: ${configuredPlatforms.join(", ")}`);
1016
- if (social.moltbook?.enabled) {
1017
- const baseUrl = social.moltbook.baseUrl || "https://www.moltbook.com/api/v1";
1018
- if (!social.moltbook.apiKey || social.moltbook.apiKey === "your-moltbook-key-here") {
1019
- logger4.error("Moltbook: SKIPPED \u2014 MOLTBOOK_API_KEY is missing or still a placeholder.");
1020
- logger4.error(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
1021
- } else {
1022
- logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
1023
- const adapter = new MoltbookAdapter(social.moltbook);
1024
- try {
1025
- await adapter.connect();
1026
- this.socialAdapters["moltbook"] = adapter;
1027
- logger4.info("Moltbook: Connected successfully (GET /agents/me OK)");
1028
- } catch (error) {
1029
- logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
1030
- this.logPlatformError("Moltbook", error);
1031
- }
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.");
1032
1027
  }
1033
- } else if (social.moltbook) {
1034
- logger4.warn('Moltbook: Present in config but disabled (enabled: false). Set "enabled: true" to activate.');
1035
- }
1036
- if (social.twitter?.enabled) {
1037
- const creds = social.twitter.credentials;
1038
- if (!creds?.apiKey || creds.apiKey === "your-twitter-api-key") {
1039
- logger4.error("Twitter: SKIPPED \u2014 credentials are missing or still placeholders.");
1040
- logger4.error(" Fix: Set valid Twitter keys in your .env file.");
1041
- } else {
1042
- logger4.info("Twitter: Connecting...");
1043
- const adapter = new TwitterAdapter(social.twitter);
1044
- try {
1045
- await adapter.connect();
1046
- this.socialAdapters["twitter"] = adapter;
1047
- logger4.info("Twitter: Connected successfully");
1048
- } catch (error) {
1049
- logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
1050
- this.logPlatformError("Twitter", error);
1051
- }
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.");
1052
1079
  }
1053
- } else if (social.twitter) {
1054
- logger4.warn('Twitter: Present in config but disabled (enabled: false). Set "enabled: true" to activate.');
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);
1055
1103
  }
1056
1104
  }
1057
1105
  async postStartupMessages() {