@moltium/core 0.1.13 → 0.1.14

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
@@ -525,6 +525,25 @@ import axios from "axios";
525
525
 
526
526
  // src/social/SocialAdapter.ts
527
527
  var SocialAdapter = class {
528
+ // Optional methods with defaults — override in platform adapters as needed
529
+ async downvote(_id) {
530
+ throw new Error(`downvote() is not supported on ${this.platform}`);
531
+ }
532
+ async unfollow(_userId) {
533
+ throw new Error(`unfollow() is not supported on ${this.platform}`);
534
+ }
535
+ async getPost(_id) {
536
+ throw new Error(`getPost() is not supported on ${this.platform}`);
537
+ }
538
+ async deletePost(_id) {
539
+ throw new Error(`deletePost() is not supported on ${this.platform}`);
540
+ }
541
+ async getComments(_postId, _sort) {
542
+ throw new Error(`getComments() is not supported on ${this.platform}`);
543
+ }
544
+ async search(_query, _options) {
545
+ throw new Error(`search() is not supported on ${this.platform}`);
546
+ }
528
547
  };
529
548
 
530
549
  // src/social/moltbook.ts
@@ -543,11 +562,61 @@ var MoltbookAdapter = class extends SocialAdapter {
543
562
  }
544
563
  });
545
564
  }
565
+ // ── Connection ──
546
566
  async connect() {
547
567
  await this.client.get("/agents/me");
548
568
  }
549
569
  async disconnect() {
550
570
  }
571
+ // ── Registration & Status ──
572
+ async register(name, description) {
573
+ const response = await this.client.post("/agents/register", { name, description });
574
+ const agent = response.data.agent || response.data;
575
+ return {
576
+ apiKey: agent.api_key,
577
+ claimUrl: agent.claim_url,
578
+ verificationCode: agent.verification_code
579
+ };
580
+ }
581
+ async getStatus() {
582
+ const response = await this.client.get("/agents/status");
583
+ return { status: response.data.status };
584
+ }
585
+ // ── Profile ──
586
+ async getProfile(agentName) {
587
+ const response = await this.client.get("/agents/profile", {
588
+ params: { name: agentName }
589
+ });
590
+ const agent = response.data.agent || response.data;
591
+ return {
592
+ id: agent.id || agent.name,
593
+ name: agent.name,
594
+ bio: agent.description,
595
+ followers: agent.follower_count,
596
+ following: agent.following_count,
597
+ platform: "moltbook"
598
+ };
599
+ }
600
+ async getMyProfile() {
601
+ const response = await this.client.get("/agents/me");
602
+ return response.data;
603
+ }
604
+ async updateProfile(data) {
605
+ await this.client.patch("/agents/me", data);
606
+ }
607
+ async uploadAvatar(filePath) {
608
+ const fs = await import("fs");
609
+ const FormData = (await import("form-data")).default;
610
+ const form = new FormData();
611
+ form.append("file", fs.createReadStream(filePath));
612
+ await this.client.post("/agents/me/avatar", form, {
613
+ headers: { ...form.getHeaders(), Authorization: `Bearer ${this.config.apiKey}` }
614
+ });
615
+ }
616
+ async deleteAvatar() {
617
+ await this.client.delete("/agents/me/avatar");
618
+ }
619
+ // ── Posts ──
551
620
  async post(content) {
552
621
  const submolt = this.config.defaultSubmolt || "general";
553
622
  const title = extractTitle(content);
@@ -562,6 +631,35 @@ var MoltbookAdapter = class extends SocialAdapter {
562
631
  timestamp: new Date(response.data.created_at)
563
632
  };
564
633
  }
634
+ async postLink(submolt, title, url) {
635
+ const response = await this.client.post("/posts", { submolt, title, url });
636
+ return {
637
+ id: response.data.id,
638
+ url: response.data.url,
639
+ timestamp: new Date(response.data.created_at)
640
+ };
641
+ }
642
+ async getPost(postId) {
643
+ const response = await this.client.get(`/posts/${postId}`);
644
+ const p = response.data.post || response.data;
645
+ return {
646
+ id: p.id,
647
+ authorId: p.author_id || p.author?.id || "",
648
+ authorName: p.author_name || p.author?.name || "",
649
+ content: p.content,
650
+ title: p.title,
651
+ timestamp: new Date(p.created_at),
652
+ platform: "moltbook",
653
+ likes: p.upvotes ?? p.likes_count,
654
+ replies: p.comment_count ?? p.replies_count,
655
+ url: p.url,
656
+ submolt: p.submolt?.name || p.submolt
657
+ };
658
+ }
659
+ async deletePost(postId) {
660
+ await this.client.delete(`/posts/${postId}`);
661
+ }
662
+ // ── Comments ──
565
663
  async reply(postId, content) {
566
664
  const response = await this.client.post(`/posts/${postId}/comments`, { content });
567
665
  return {
@@ -571,12 +669,43 @@ var MoltbookAdapter = class extends SocialAdapter {
571
669
  timestamp: new Date(response.data.created_at)
572
670
  };
573
671
  }
672
+ async replyToComment(postId, content, parentId) {
673
+ const response = await this.client.post(`/posts/${postId}/comments`, {
674
+ content,
675
+ parent_id: parentId
676
+ });
677
+ return {
678
+ id: response.data.id,
679
+ parentId,
680
+ url: response.data.url,
681
+ timestamp: new Date(response.data.created_at)
682
+ };
683
+ }
684
+ async getComments(postId, sort = "top") {
685
+ const response = await this.client.get(`/posts/${postId}/comments`, {
686
+ params: { sort }
687
+ });
688
+ const items = response.data.comments || response.data || [];
689
+ return items.map((c) => mapComment(c, postId));
690
+ }
691
+ async upvoteComment(commentId) {
692
+ await this.client.post(`/comments/${commentId}/upvote`);
693
+ }
694
+ // ── Voting ──
574
695
  async like(postId) {
575
696
  await this.client.post(`/posts/${postId}/upvote`);
576
697
  }
698
+ async downvote(postId) {
699
+ await this.client.post(`/posts/${postId}/downvote`);
700
+ }
701
+ // ── Following ──
577
702
  async follow(agentName) {
578
703
  await this.client.post(`/agents/${agentName}/follow`);
579
704
  }
705
+ async unfollow(agentName) {
706
+ await this.client.delete(`/agents/${agentName}/follow`);
707
+ }
708
+ // ── Feed ──
580
709
  async getMentions() {
581
710
  const response = await this.client.get("/feed", {
582
711
  params: { sort: "new", limit: 20 }
@@ -591,38 +720,225 @@ var MoltbookAdapter = class extends SocialAdapter {
591
720
  }));
592
721
  }
593
722
  async getFeed(options) {
594
- const params = { sort: "hot" };
723
+ const params = { sort: options?.sort || "hot" };
595
724
  if (options?.limit) params.limit = options.limit;
596
725
  if (options?.cursor) params.cursor = options.cursor;
597
726
  if (options?.since) params.since = options.since.toISOString();
727
+ if (options?.submolt) params.submolt = options.submolt;
598
728
  const response = await this.client.get("/feed", { params });
599
- return (response.data.posts || []).map((p) => ({
600
- id: p.id,
601
- authorId: p.author_id || p.author?.id || "",
602
- authorName: p.author_name || p.author?.name || "",
603
- content: p.content,
604
- timestamp: new Date(p.created_at),
605
- platform: "moltbook",
606
- likes: p.upvotes ?? p.likes_count,
607
- replies: p.comment_count ?? p.replies_count,
608
- reposts: p.reposts_count,
609
- mentions: p.mentions || [],
610
- url: p.url
729
+ return (response.data.posts || []).map((p) => mapPost(p));
730
+ }
731
+ async getGlobalFeed(options) {
732
+ const params = { sort: options?.sort || "hot" };
733
+ if (options?.limit) params.limit = options.limit;
734
+ if (options?.submolt) params.submolt = options.submolt;
735
+ const response = await this.client.get("/posts", { params });
736
+ return (response.data.posts || []).map((p) => mapPost(p));
737
+ }
738
+ // ── Search ──
739
+ async search(query, options) {
740
+ const params = { q: query };
741
+ if (options?.type) params.type = options.type;
742
+ if (options?.limit) params.limit = options.limit;
743
+ const response = await this.client.get("/search", { params });
744
+ return (response.data.results || []).map((r) => ({
745
+ id: r.id,
746
+ type: r.type,
747
+ title: r.title,
748
+ content: r.content,
749
+ upvotes: r.upvotes ?? 0,
750
+ downvotes: r.downvotes ?? 0,
751
+ similarity: r.similarity,
752
+ author: { name: r.author?.name || "" },
753
+ submolt: r.submolt,
754
+ postId: r.post_id || r.id,
755
+ timestamp: new Date(r.created_at)
611
756
  }));
612
757
  }
613
- async getProfile(agentName) {
614
- const response = await this.client.get("/agents/profile", {
615
- params: { name: agentName }
758
+ // ── Submolts (Communities) ──
759
+ async createSubmolt(name, displayName, description) {
760
+ const response = await this.client.post("/submolts", {
761
+ name,
762
+ display_name: displayName,
763
+ description
616
764
  });
765
+ const s = response.data.submolt || response.data;
766
+ return mapSubmolt(s);
767
+ }
768
+ async listSubmolts() {
769
+ const response = await this.client.get("/submolts");
770
+ const items = response.data.submolts || response.data || [];
771
+ return items.map((s) => mapSubmolt(s));
772
+ }
773
+ async getSubmolt(name) {
774
+ const response = await this.client.get(`/submolts/${name}`);
775
+ const s = response.data.submolt || response.data;
776
+ return mapSubmolt(s);
777
+ }
778
+ async subscribe(submoltName) {
779
+ await this.client.post(`/submolts/${submoltName}/subscribe`);
780
+ }
781
+ async unsubscribe(submoltName) {
782
+ await this.client.delete(`/submolts/${submoltName}/subscribe`);
783
+ }
784
+ async getSubmoltFeed(submoltName, sort = "hot", limit = 25) {
785
+ const response = await this.client.get(`/submolts/${submoltName}/feed`, {
786
+ params: { sort, limit }
787
+ });
788
+ return (response.data.posts || []).map((p) => mapPost(p));
789
+ }
790
+ // ── Moderation ──
791
+ async pinPost(postId) {
792
+ await this.client.post(`/posts/${postId}/pin`);
793
+ }
794
+ async unpinPost(postId) {
795
+ await this.client.delete(`/posts/${postId}/pin`);
796
+ }
797
+ async updateSubmoltSettings(submoltName, settings) {
798
+ const payload = {};
799
+ if (settings.description !== void 0) payload.description = settings.description;
800
+ if (settings.bannerColor !== void 0) payload.banner_color = settings.bannerColor;
801
+ if (settings.themeColor !== void 0) payload.theme_color = settings.themeColor;
802
+ await this.client.patch(`/submolts/${submoltName}/settings`, payload);
803
+ }
804
+ async uploadSubmoltAvatar(submoltName, filePath) {
805
+ const fs = await import("fs");
806
+ const FormData = (await import("form-data")).default;
807
+ const form = new FormData();
808
+ form.append("file", fs.createReadStream(filePath));
809
+ form.append("type", "avatar");
810
+ await this.client.post(`/submolts/${submoltName}/settings`, form, {
811
+ headers: { ...form.getHeaders(), Authorization: `Bearer ${this.config.apiKey}` }
812
+ });
813
+ }
814
+ async uploadSubmoltBanner(submoltName, filePath) {
815
+ const fs = await import("fs");
816
+ const FormData = (await import("form-data")).default;
817
+ const form = new FormData();
818
+ form.append("file", fs.createReadStream(filePath));
819
+ form.append("type", "banner");
820
+ await this.client.post(`/submolts/${submoltName}/settings`, form, {
821
+ headers: { ...form.getHeaders(), Authorization: `Bearer ${this.config.apiKey}` }
822
+ });
823
+ }
824
+ async addModerator(submoltName, agentName, role = "moderator") {
825
+ await this.client.post(`/submolts/${submoltName}/moderators`, {
826
+ agent_name: agentName,
827
+ role
828
+ });
829
+ }
830
+ async removeModerator(submoltName, agentName) {
831
+ await this.client.delete(`/submolts/${submoltName}/moderators`, {
832
+ data: { agent_name: agentName }
833
+ });
834
+ }
835
+ async listModerators(submoltName) {
836
+ const response = await this.client.get(`/submolts/${submoltName}/moderators`);
837
+ return response.data.moderators || response.data || [];
838
+ }
839
+ // ── DM / Private Messaging ──
840
+ async checkDMs() {
841
+ const response = await this.client.get("/agents/dm/check");
842
+ const d = response.data;
617
843
  return {
618
- id: response.data.id,
619
- name: response.data.name,
620
- bio: response.data.bio,
621
- followers: response.data.followers_count,
622
- following: response.data.following_count,
623
- platform: "moltbook"
844
+ hasActivity: d.has_activity,
845
+ summary: d.summary || "",
846
+ requests: {
847
+ count: d.requests?.count || 0,
848
+ items: (d.requests?.items || []).map((r) => ({
849
+ conversationId: r.conversation_id,
850
+ from: {
851
+ name: r.from?.name || "",
852
+ owner: r.from?.owner ? {
853
+ xHandle: r.from.owner.x_handle,
854
+ xName: r.from.owner.x_name
855
+ } : void 0
856
+ },
857
+ messagePreview: r.message_preview || "",
858
+ createdAt: new Date(r.created_at)
859
+ }))
860
+ },
861
+ messages: {
862
+ totalUnread: d.messages?.total_unread || 0,
863
+ conversationsWithUnread: d.messages?.conversations_with_unread || 0,
864
+ latest: d.messages?.latest || []
865
+ }
624
866
  };
625
867
  }
868
+ async sendDMRequest(to, message, byOwner = false) {
869
+ const payload = { message };
870
+ if (byOwner) {
871
+ payload.to_owner = to;
872
+ } else {
873
+ payload.to = to;
874
+ }
875
+ const response = await this.client.post("/agents/dm/request", payload);
876
+ return { conversationId: response.data.conversation_id || response.data.id };
877
+ }
878
+ async getDMRequests() {
879
+ const response = await this.client.get("/agents/dm/requests");
880
+ const items = response.data.requests || response.data || [];
881
+ return items.map((r) => ({
882
+ conversationId: r.conversation_id,
883
+ from: {
884
+ name: r.from?.name || "",
885
+ owner: r.from?.owner ? {
886
+ xHandle: r.from.owner.x_handle,
887
+ xName: r.from.owner.x_name
888
+ } : void 0
889
+ },
890
+ messagePreview: r.message_preview || r.message || "",
891
+ createdAt: new Date(r.created_at)
892
+ }));
893
+ }
894
+ async approveDMRequest(conversationId) {
895
+ await this.client.post(`/agents/dm/requests/${conversationId}/approve`);
896
+ }
897
+ async rejectDMRequest(conversationId, block = false) {
898
+ const payload = block ? { block: true } : void 0;
899
+ await this.client.post(`/agents/dm/requests/${conversationId}/reject`, payload);
900
+ }
901
+ async listConversations() {
902
+ const response = await this.client.get("/agents/dm/conversations");
903
+ const items = response.data.conversations?.items || response.data.conversations || [];
904
+ return items.map((c) => ({
905
+ conversationId: c.conversation_id,
906
+ withAgent: {
907
+ name: c.with_agent?.name || "",
908
+ description: c.with_agent?.description,
909
+ karma: c.with_agent?.karma,
910
+ owner: c.with_agent?.owner ? {
911
+ xHandle: c.with_agent.owner.x_handle,
912
+ xName: c.with_agent.owner.x_name
913
+ } : void 0
914
+ },
915
+ unreadCount: c.unread_count || 0,
916
+ lastMessageAt: new Date(c.last_message_at),
917
+ youInitiated: c.you_initiated ?? false
918
+ }));
919
+ }
920
+ async readConversation(conversationId) {
921
+ const response = await this.client.get(`/agents/dm/conversations/${conversationId}`);
922
+ const d = response.data;
923
+ return {
924
+ conversationId: d.conversation_id || conversationId,
925
+ withAgent: { name: d.with_agent?.name || "" },
926
+ messages: (d.messages || []).map((m) => ({
927
+ id: m.id,
928
+ sender: m.sender || m.from || "",
929
+ content: m.content || m.message || "",
930
+ timestamp: new Date(m.created_at || m.timestamp),
931
+ needsHumanInput: m.needs_human_input
932
+ }))
933
+ };
934
+ }
935
+ async sendDM(conversationId, message, needsHumanInput = false) {
936
+ const payload = { message };
937
+ if (needsHumanInput) {
938
+ payload.needs_human_input = true;
939
+ }
940
+ await this.client.post(`/agents/dm/conversations/${conversationId}/send`, payload);
941
+ }
626
942
  };
627
943
  function extractTitle(content) {
628
944
  const firstLine = content.split("\n")[0].trim();
@@ -632,6 +948,47 @@ function extractTitle(content) {
632
948
  const truncated = raw.slice(0, 80).replace(/\s+\S*$/, "");
633
949
  return truncated + "...";
634
950
  }
951
+ function mapPost(p) {
952
+ return {
953
+ id: p.id,
954
+ authorId: p.author_id || p.author?.id || "",
955
+ authorName: p.author_name || p.author?.name || "",
956
+ content: p.content,
957
+ title: p.title,
958
+ timestamp: new Date(p.created_at),
959
+ platform: "moltbook",
960
+ likes: p.upvotes ?? p.likes_count,
961
+ replies: p.comment_count ?? p.replies_count,
962
+ reposts: p.reposts_count,
963
+ mentions: p.mentions || [],
964
+ url: p.url,
965
+ submolt: p.submolt?.name || p.submolt
966
+ };
967
+ }
968
+ function mapComment(c, postId) {
969
+ return {
970
+ id: c.id,
971
+ postId,
972
+ parentId: c.parent_id,
973
+ authorName: c.author?.name || c.author_name || "",
974
+ content: c.content,
975
+ upvotes: c.upvotes ?? 0,
976
+ downvotes: c.downvotes ?? 0,
977
+ timestamp: new Date(c.created_at),
978
+ replies: c.replies?.map((r) => mapComment(r, postId))
979
+ };
980
+ }
981
+ function mapSubmolt(s) {
982
+ return {
983
+ name: s.name,
984
+ displayName: s.display_name || s.name,
985
+ description: s.description || "",
986
+ subscriberCount: s.subscriber_count || 0,
987
+ postCount: s.post_count,
988
+ yourRole: s.your_role || null,
989
+ createdAt: new Date(s.created_at)
990
+ };
991
+ }
635
992
 
636
993
  // src/social/twitter.ts
637
994
  var TwitterAdapter = class extends SocialAdapter {