@moltium/core 0.1.6 → 0.1.8

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,56 +942,104 @@ var Agent = class {
942
942
  }
943
943
  }
944
944
  async initSocialAdapters() {
945
- const { social } = this.config;
946
- const configuredPlatforms = Object.keys(social).filter(
947
- (k) => social[k] && typeof social[k] === "object"
948
- );
949
- if (configuredPlatforms.length === 0) {
950
- logger4.warn("Social: No platforms configured. To post on startup, add a social platform to your config.");
951
- logger4.warn(' Code-based: Add a moltbook or twitter section to agent.config.ts under "social".');
952
- logger4.warn(' Markdown: Add a "### Moltbook" section under "## Social Platforms" in agent.md with "enabled: true".');
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");
953
961
  return;
954
962
  }
955
- logger4.info(`Social: Found platforms in config: ${configuredPlatforms.join(", ")}`);
956
- if (social.moltbook?.enabled) {
957
- const baseUrl = social.moltbook.baseUrl || "https://www.moltbook.com/api/v1";
958
- if (!social.moltbook.apiKey || social.moltbook.apiKey === "your-moltbook-key-here") {
959
- logger4.error("Moltbook: SKIPPED \u2014 MOLTBOOK_API_KEY is missing or still a placeholder.");
960
- logger4.error(" Fix: Set a valid MOLTBOOK_API_KEY in your .env file.");
961
- } else {
962
- logger4.info(`Moltbook: Connecting to ${baseUrl} ...`);
963
- const adapter = new MoltbookAdapter(social.moltbook);
964
- try {
965
- await adapter.connect();
966
- this.socialAdapters["moltbook"] = adapter;
967
- logger4.info("Moltbook: Connected successfully (GET /agents/me OK)");
968
- } catch (error) {
969
- logger4.error(`Moltbook: Connection FAILED \u2014 ${error.message || error}`);
970
- this.logPlatformError("Moltbook", error);
971
- }
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.");
972
967
  }
973
- } else if (social.moltbook) {
974
- logger4.warn('Moltbook: Present in config but disabled (enabled: false). Set "enabled: true" to activate.');
975
- }
976
- if (social.twitter?.enabled) {
977
- const creds = social.twitter.credentials;
978
- if (!creds?.apiKey || creds.apiKey === "your-twitter-api-key") {
979
- logger4.error("Twitter: SKIPPED \u2014 credentials are missing or still placeholders.");
980
- logger4.error(" Fix: Set valid Twitter keys in your .env file.");
981
- } else {
982
- logger4.info("Twitter: Connecting...");
983
- const adapter = new TwitterAdapter(social.twitter);
984
- try {
985
- await adapter.connect();
986
- this.socialAdapters["twitter"] = adapter;
987
- logger4.info("Twitter: Connected successfully");
988
- } catch (error) {
989
- logger4.error(`Twitter: Connection FAILED \u2014 ${error.message || error}`);
990
- this.logPlatformError("Twitter", error);
991
- }
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.");
992
1019
  }
993
- } else if (social.twitter) {
994
- logger4.warn('Twitter: Present in config but disabled (enabled: false). Set "enabled: true" to activate.');
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);
995
1043
  }
996
1044
  }
997
1045
  async postStartupMessages() {