@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.mjs CHANGED
@@ -942,46 +942,104 @@ var Agent = class {
942
942
  }
943
943
  }
944
944
  async initSocialAdapters() {
945
- const { social } = this.config;
946
- if (social.moltbook?.enabled) {
947
- const baseUrl = social.moltbook.baseUrl || "https://www.moltbook.com/api/v1";
948
- if (!social.moltbook.apiKey || social.moltbook.apiKey === "your-moltbook-key-here") {
949
- logger4.error("Moltbook: SKIPPED \u2014 MOLTBOOK_API_KEY is missing or still a placeholder.");
950
- logger4.error(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
951
- } else {
952
- logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
953
- const adapter = new MoltbookAdapter(social.moltbook);
954
- try {
955
- await adapter.connect();
956
- this.socialAdapters["moltbook"] = adapter;
957
- logger4.info("Moltbook: Connected successfully (GET /agents/me OK)");
958
- } catch (error) {
959
- logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
960
- this.logPlatformError("Moltbook", error);
961
- }
945
+ const social = this.config.social;
946
+ await this.initMoltbook(social);
947
+ await this.initTwitter(social);
948
+ if (Object.keys(this.socialAdapters).length === 0) {
949
+ logger4.warn("Social: No adapters connected. Set MOLTBOOK_API_KEY or Twitter env vars in your .env to enable.");
950
+ }
951
+ }
952
+ async initMoltbook(social) {
953
+ const envKey = process.env.MOLTBOOK_API_KEY;
954
+ const configMoltbook = social.moltbook;
955
+ const apiKey = configMoltbook?.apiKey || envKey || "";
956
+ const isPlaceholder = !apiKey || apiKey === "your-moltbook-key-here";
957
+ const explicitlyDisabled = configMoltbook && configMoltbook.enabled === false;
958
+ const shouldConnect = !isPlaceholder && !explicitlyDisabled;
959
+ if (explicitlyDisabled) {
960
+ logger4.info("Moltbook: Disabled in config (enabled: false) \u2014 skipping");
961
+ return;
962
+ }
963
+ if (isPlaceholder) {
964
+ if (configMoltbook?.enabled || envKey) {
965
+ logger4.warn("Moltbook: MOLTBOOK_API_KEY is missing or still a placeholder.");
966
+ logger4.warn(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
962
967
  }
963
- } else if (social.moltbook) {
964
- logger4.info("Moltbook: Configured but disabled (enabled: false)");
965
- }
966
- if (social.twitter?.enabled) {
967
- const creds = social.twitter.credentials;
968
- if (!creds?.apiKey || creds.apiKey === "your-twitter-api-key") {
969
- logger4.error("Twitter: SKIPPED \u2014 credentials are missing or still placeholders.");
970
- logger4.error(" Fix: Set valid Twitter keys in your .env file.");
971
- } else {
972
- logger4.info("Twitter: Connecting...");
973
- const adapter = new TwitterAdapter(social.twitter);
974
- try {
975
- await adapter.connect();
976
- this.socialAdapters["twitter"] = adapter;
977
- logger4.info("Twitter: Connected successfully");
978
- } catch (error) {
979
- logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
980
- this.logPlatformError("Twitter", error);
981
- }
968
+ return;
969
+ }
970
+ if (!shouldConnect) return;
971
+ const source = configMoltbook?.apiKey ? "config" : "environment";
972
+ const baseUrl = configMoltbook?.baseUrl || process.env.MOLTBOOK_BASE_URL || "https://www.moltbook.com/api/v1";
973
+ const defaultSubmolt = configMoltbook?.defaultSubmolt || "general";
974
+ const effectiveConfig = {
975
+ enabled: true,
976
+ apiKey,
977
+ baseUrl,
978
+ defaultSubmolt,
979
+ ...configMoltbook,
980
+ // Ensure env-resolved values win when config didn't set them
981
+ ...configMoltbook?.apiKey ? {} : { apiKey },
982
+ ...configMoltbook?.baseUrl ? {} : { baseUrl }
983
+ };
984
+ logger4.info(`Moltbook: API key detected from ${source}`);
985
+ logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
986
+ const adapter = new MoltbookAdapter(effectiveConfig);
987
+ try {
988
+ await adapter.connect();
989
+ this.socialAdapters["moltbook"] = adapter;
990
+ social.moltbook = effectiveConfig;
991
+ logger4.info(`Moltbook: Connected successfully (submolt: ${defaultSubmolt})`);
992
+ } catch (error) {
993
+ logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
994
+ this.logPlatformError("Moltbook", error);
995
+ }
996
+ }
997
+ async initTwitter(social) {
998
+ const configTwitter = social.twitter;
999
+ const envApiKey = process.env.TWITTER_API_KEY;
1000
+ const envApiSecret = process.env.TWITTER_API_SECRET;
1001
+ const envAccessToken = process.env.TWITTER_ACCESS_TOKEN;
1002
+ const envAccessSecret = process.env.TWITTER_ACCESS_SECRET;
1003
+ const creds = configTwitter?.credentials;
1004
+ const apiKey = creds?.apiKey || envApiKey || "";
1005
+ const apiSecret = creds?.apiSecret || envApiSecret || "";
1006
+ const accessToken = creds?.accessToken || envAccessToken || "";
1007
+ const accessSecret = creds?.accessSecret || envAccessSecret || "";
1008
+ const hasKey = apiKey && apiKey !== "your-twitter-api-key";
1009
+ const hasAllCreds = hasKey && apiSecret && accessToken && accessSecret;
1010
+ const explicitlyDisabled = configTwitter && configTwitter.enabled === false;
1011
+ if (explicitlyDisabled) {
1012
+ logger4.info("Twitter: Disabled in config (enabled: false) \u2014 skipping");
1013
+ return;
1014
+ }
1015
+ if (!hasKey) {
1016
+ if (configTwitter?.enabled || envApiKey) {
1017
+ logger4.warn("Twitter: Credentials are missing or still placeholders.");
1018
+ logger4.warn(" Fix: Set valid Twitter keys in your .env file.");
982
1019
  }
983
- } else if (social.twitter) {
984
- logger4.info("Twitter: Configured but disabled (enabled: false)");
1020
+ return;
1021
+ }
1022
+ if (!hasAllCreds) {
1023
+ logger4.warn("Twitter: Some credentials are missing. Need: TWITTER_API_KEY, TWITTER_API_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET");
1024
+ return;
1025
+ }
1026
+ const source = creds?.apiKey ? "config" : "environment";
1027
+ logger4.info(`Twitter: Credentials detected from ${source}`);
1028
+ logger4.info("Twitter: Connecting...");
1029
+ const effectiveConfig = {
1030
+ enabled: true,
1031
+ ...configTwitter,
1032
+ credentials: { apiKey, apiSecret, accessToken, accessSecret }
1033
+ };
1034
+ const adapter = new TwitterAdapter(effectiveConfig);
1035
+ try {
1036
+ await adapter.connect();
1037
+ this.socialAdapters["twitter"] = adapter;
1038
+ social.twitter = effectiveConfig;
1039
+ logger4.info("Twitter: Connected successfully");
1040
+ } catch (error) {
1041
+ logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
1042
+ this.logPlatformError("Twitter", error);
985
1043
  }
986
1044
  }
987
1045
  async postStartupMessages() {
@@ -1180,8 +1238,10 @@ var MarkdownParser = class {
1180
1238
  for (const child of section.children) {
1181
1239
  const platform = child.title.toLowerCase();
1182
1240
  const fields = this.parseKeyValueLines(child.content);
1241
+ const enabled = fields["enabled"] === "true";
1242
+ delete fields["enabled"];
1183
1243
  social[platform] = {
1184
- enabled: fields["enabled"] === "true",
1244
+ enabled,
1185
1245
  ...fields
1186
1246
  };
1187
1247
  }