@moltium/core 0.1.19 → 0.1.21

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.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as express_serve_static_core from 'express-serve-static-core';
2
- import { Router } from 'express';
2
+ import { AgentCard } from '@a2a-js/sdk';
3
+ import { RequestHandler, Router } from 'express';
4
+ import { AgentExecutor, RequestContext, ExecutionEventBus } from '@a2a-js/sdk/server';
3
5
  import winston from 'winston';
4
6
 
5
7
  interface MoltbookConfig {
@@ -82,6 +84,35 @@ interface AgentConfig {
82
84
  systemPrompt?: string;
83
85
  };
84
86
  social: SocialConfig;
87
+ /**
88
+ * A2A Protocol Configuration
89
+ * When enabled, automatically registers A2A communication actions
90
+ * @optional
91
+ */
92
+ a2a?: {
93
+ /**
94
+ * Enable A2A protocol support (defaults to true when a2a config exists)
95
+ */
96
+ enabled?: boolean;
97
+ /**
98
+ * Peer agents this agent can communicate with
99
+ * Key is the action name, value is the agent URL
100
+ * @example { talk_to_analyst: 'http://localhost:3001' }
101
+ */
102
+ peers?: Record<string, string>;
103
+ /**
104
+ * Default peer agent URL (used when peers not specified)
105
+ */
106
+ defaultPeerUrl?: string;
107
+ /**
108
+ * Enable verbose A2A logging
109
+ */
110
+ verbose?: boolean;
111
+ /**
112
+ * Custom action name for generic A2A communication (defaults to 'talk_to_agent')
113
+ */
114
+ genericActionName?: string;
115
+ };
85
116
  behaviors: {
86
117
  autonomous: boolean;
87
118
  decisionMaking: 'llm-driven' | 'rule-based' | 'hybrid';
@@ -102,6 +133,15 @@ interface AgentConfig {
102
133
  actions: string[];
103
134
  customActions?: Action[];
104
135
  scheduling?: ScheduledTask[];
136
+ /** World SDK integration — connect this agent to a world */
137
+ world?: {
138
+ /** URL of the world to join */
139
+ url: string;
140
+ /** Wallet address for blockchain-enabled worlds */
141
+ walletAddress?: string;
142
+ /** Auto-join the world when agent starts (default: true) */
143
+ autoJoin?: boolean;
144
+ };
105
145
  webhooks?: {
106
146
  onAction?: string | ((action: any, result: any) => Promise<void>);
107
147
  onError?: string;
@@ -507,6 +547,7 @@ declare class Agent {
507
547
  private scheduledPost;
508
548
  private executeScheduledTask;
509
549
  private logPlatformError;
550
+ private autoJoinWorld;
510
551
  private startAutonomousLoop;
511
552
  private isSleeping;
512
553
  private gatherContext;
@@ -554,6 +595,7 @@ declare class MarkdownParser {
554
595
  private parseSocial;
555
596
  private parseBehaviors;
556
597
  private parseMemory;
598
+ private parseWorld;
557
599
  private parseSleepSchedule;
558
600
  private parseKeyValueLines;
559
601
  private parseScheduling;
@@ -737,17 +779,302 @@ declare function createMarkdownAction(name: string, description: string, llmProv
737
779
  /** All Moltbook-specific actions */
738
780
  declare const moltbookActions: Action[];
739
781
 
782
+ /**
783
+ * ============================================================================
784
+ * WORLD SDK BUILT-IN ACTIONS
785
+ * ============================================================================
786
+ *
787
+ * Built-in actions for agents to interact with worlds created using
788
+ * @moltium/world-core. These use plain HTTP to call the world's REST endpoints.
789
+ */
790
+ /**
791
+ * Creates a join_world action that POSTs to a world's /world/join endpoint
792
+ */
793
+ declare function createJoinWorldAction(config?: {
794
+ defaultWorldUrl?: string;
795
+ }): Action;
796
+ /**
797
+ * Creates a leave_world action that DELETEs from a world's /world/agents endpoint
798
+ */
799
+ declare function createLeaveWorldAction(config?: {
800
+ defaultWorldUrl?: string;
801
+ }): Action;
802
+ /**
803
+ * Creates a query_world action that GETs world state and info
804
+ */
805
+ declare function createQueryWorldAction(config?: {
806
+ defaultWorldUrl?: string;
807
+ }): Action;
808
+ /**
809
+ * Creates a send_world_message action for agent-to-agent messaging through a world
810
+ */
811
+ declare function createSendWorldMessageAction(config?: {
812
+ defaultWorldUrl?: string;
813
+ }): Action;
814
+ /**
815
+ * All world actions as a convenience array
816
+ */
817
+ declare const worldActions: {
818
+ createJoinWorldAction: typeof createJoinWorldAction;
819
+ createLeaveWorldAction: typeof createLeaveWorldAction;
820
+ createQueryWorldAction: typeof createQueryWorldAction;
821
+ createSendWorldMessageAction: typeof createSendWorldMessageAction;
822
+ };
823
+
740
824
  declare const builtInActions: Action[];
741
825
 
826
+ interface A2AConfig {
827
+ enabled: boolean;
828
+ baseUrl: string;
829
+ port?: number;
830
+ pushNotifications?: boolean;
831
+ streaming?: boolean;
832
+ stateTransitionHistory?: boolean;
833
+ }
834
+ /**
835
+ * Builds an A2A-compliant AgentCard from a Moltium AgentConfig.
836
+ */
837
+ declare class AgentCardBuilder {
838
+ /**
839
+ * Creates an A2A AgentCard from Moltium configuration.
840
+ * @param config The Moltium agent configuration
841
+ * @param a2aConfig A2A-specific configuration (URLs, capabilities)
842
+ * @returns A2A-compliant AgentCard
843
+ */
844
+ static build(config: AgentConfig, a2aConfig: A2AConfig): AgentCard;
845
+ /**
846
+ * Converts Moltium actions to A2A skills.
847
+ */
848
+ private static buildSkills;
849
+ /**
850
+ * Updates an agent card with runtime information.
851
+ */
852
+ static updateWithRuntime(agentCard: AgentCard, actualPort: number, actualHost?: string): AgentCard;
853
+ }
854
+
855
+ /**
856
+ * Adapts a Moltium Agent to the A2A AgentExecutor interface.
857
+ * This allows Moltium agents to respond to A2A protocol requests.
858
+ */
859
+ declare class MoltiumExecutor implements AgentExecutor {
860
+ private agent;
861
+ private cancelledTasks;
862
+ constructor(agent: Agent);
863
+ /**
864
+ * Executes an A2A request using the Moltium agent.
865
+ * Converts A2A messages to Moltium actions and publishes results back via the event bus.
866
+ */
867
+ execute(requestContext: RequestContext, eventBus: ExecutionEventBus): Promise<void>;
868
+ /**
869
+ * Handles task cancellation requests.
870
+ */
871
+ cancelTask(taskId: string, eventBus: ExecutionEventBus): Promise<void>;
872
+ /**
873
+ * Extracts text content from an A2A message.
874
+ */
875
+ private extractMessageContent;
876
+ /**
877
+ * Determines if the user message is requesting a specific action.
878
+ */
879
+ private isActionRequest;
880
+ /**
881
+ * Executes a chat interaction using the agent's LLM.
882
+ */
883
+ private executeChat;
884
+ /**
885
+ * Executes an action based on the user's request.
886
+ */
887
+ private executeAction;
888
+ /**
889
+ * Publishes a successful result as an A2A artifact.
890
+ */
891
+ private publishResult;
892
+ /**
893
+ * Publishes an error as an A2A artifact.
894
+ */
895
+ private publishError;
896
+ /**
897
+ * Publishes a status update event.
898
+ */
899
+ private publishStatusUpdate;
900
+ /**
901
+ * Publishes a cancellation status.
902
+ */
903
+ private publishCancellation;
904
+ }
905
+
906
+ interface A2AServerOptions {
907
+ a2aConfig: A2AConfig;
908
+ authToken?: string;
909
+ }
910
+ /**
911
+ * Creates A2A-compliant Express routes for a Moltium agent.
912
+ * These routes implement the Agent-to-Agent (A2A) protocol.
913
+ */
914
+ declare class A2AIntegration {
915
+ private agent;
916
+ private agentCard;
917
+ private requestHandler;
918
+ private moltiumExecutor;
919
+ constructor(agent: Agent, options: A2AServerOptions);
920
+ /**
921
+ * Creates Express middleware handlers for A2A endpoints.
922
+ * Returns an object with individual handlers that can be mounted on specific routes.
923
+ */
924
+ getHandlers(): {
925
+ agentCard: RequestHandler;
926
+ jsonRpc: RequestHandler;
927
+ rest: RequestHandler;
928
+ };
929
+ /**
930
+ * Updates the agent card with actual runtime information (host/port).
931
+ */
932
+ updateAgentCard(actualPort: number, actualHost?: string): void;
933
+ /**
934
+ * Gets the current agent card.
935
+ */
936
+ getAgentCard(): AgentCard;
937
+ /**
938
+ * Logs A2A endpoint information.
939
+ */
940
+ logEndpoints(host: string, port: number): void;
941
+ }
942
+ /**
943
+ * Helper function to create and configure A2A integration for a Moltium agent.
944
+ */
945
+ declare function createA2AIntegration(agent: Agent, options?: Partial<A2AServerOptions>): A2AIntegration;
946
+
947
+ /**
948
+ * Configuration for A2A client operations
949
+ */
950
+ interface A2AClientConfig {
951
+ /**
952
+ * The base URL of the target agent
953
+ * @example 'http://localhost:3001'
954
+ */
955
+ agentUrl: string;
956
+ /**
957
+ * Path to the agent card (defaults to '.well-known/agent-card.json')
958
+ */
959
+ agentCardPath?: string;
960
+ /**
961
+ * Timeout for requests in milliseconds (optional)
962
+ */
963
+ timeout?: number;
964
+ }
965
+ /**
966
+ * Options for sending messages via A2A
967
+ */
968
+ interface A2AMessageOptions {
969
+ /**
970
+ * The text message to send
971
+ */
972
+ text: string;
973
+ /**
974
+ * Optional context ID to group related messages
975
+ */
976
+ contextId?: string;
977
+ /**
978
+ * Optional metadata for extensions
979
+ */
980
+ metadata?: Record<string, unknown>;
981
+ }
982
+ /**
983
+ * Response from an A2A message
984
+ */
985
+ interface A2AMessageResponse {
986
+ /**
987
+ * Whether the message was successfully sent and received
988
+ */
989
+ success: boolean;
990
+ /**
991
+ * The reply text from the agent (if successful)
992
+ */
993
+ reply?: string;
994
+ /**
995
+ * The agent URL that responded
996
+ */
997
+ agentUrl?: string;
998
+ /**
999
+ * Error message (if failed)
1000
+ */
1001
+ error?: string;
1002
+ /**
1003
+ * Raw response from the A2A protocol (for advanced use)
1004
+ */
1005
+ raw?: any;
1006
+ }
1007
+ /**
1008
+ * Wrapper around A2A Client SDK with improved developer experience
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const client = new A2AClient({ agentUrl: 'http://localhost:3001' });
1013
+ * const response = await client.sendMessage({ text: 'Hello!' });
1014
+ * console.log(response.reply);
1015
+ * ```
1016
+ */
1017
+ declare class A2AClient {
1018
+ private sdkClient;
1019
+ private config;
1020
+ constructor(config: A2AClientConfig);
1021
+ /**
1022
+ * Send a text message to the agent and get a response
1023
+ *
1024
+ * @param options Message options including text content
1025
+ * @returns Promise resolving to the agent's response
1026
+ *
1027
+ * @example
1028
+ * ```typescript
1029
+ * const response = await client.sendMessage({
1030
+ * text: 'What are your thoughts on AI?',
1031
+ * contextId: 'conversation-123'
1032
+ * });
1033
+ *
1034
+ * if (response.success) {
1035
+ * console.log('Agent replied:', response.reply);
1036
+ * }
1037
+ * ```
1038
+ */
1039
+ sendMessage(options: A2AMessageOptions): Promise<A2AMessageResponse>;
1040
+ /**
1041
+ * Extract text reply from A2A protocol response
1042
+ * Handles both Message and Task response types
1043
+ */
1044
+ private extractReply;
1045
+ /**
1046
+ * Get the agent card information
1047
+ *
1048
+ * @returns Promise resolving to the agent card
1049
+ */
1050
+ getAgentCard(): Promise<any>;
1051
+ /**
1052
+ * Get the base URL of the agent
1053
+ */
1054
+ getAgentUrl(): string;
1055
+ }
1056
+ /**
1057
+ * Factory function to create A2A clients easily
1058
+ *
1059
+ * @example
1060
+ * ```typescript
1061
+ * const client = createA2AClient('http://localhost:3001');
1062
+ * const response = await client.sendMessage({ text: 'Hello!' });
1063
+ * ```
1064
+ */
1065
+ declare function createA2AClient(agentUrlOrConfig: string | A2AClientConfig): A2AClient;
1066
+
742
1067
  interface ServerOptions {
743
1068
  port?: number;
744
1069
  host?: string;
1070
+ enableA2A?: boolean;
1071
+ a2aConfig?: A2AServerOptions['a2aConfig'];
745
1072
  }
746
- declare function createApp(agent: Agent): express_serve_static_core.Express;
1073
+ declare function createApp(agent: Agent, options?: ServerOptions): express_serve_static_core.Express;
747
1074
  declare function startServer(agent: Agent, options?: ServerOptions): Promise<void>;
748
1075
 
749
1076
  declare function createRoutes(agent: Agent): Router;
750
1077
 
751
1078
  declare function createLogger(label: string): winston.Logger;
752
1079
 
753
- export { type Action, type ActionContext, ActionHandler, ActionRegistry, type ActionResult, Agent, type AgentConfig, type AgentState, AnthropicProvider, type BehaviorTrigger, type Comment, ConfigLoader, type ConfigType, type Conversation, type ConversationDetail, type CustomAPIConfig, type CustomCLIConfig, type CustomDeploymentConfig, type CustomDockerConfig, type CustomSSHConfig, type DMCheckResult, type DMRequest, type Decision, type DeploymentConfig, type DeploymentResult, type DeploymentStatus, type DirectMessage, type Experience, type FeedOptions, type GenerateOptions, LLMProvider, type LifecycleEvent, type LifecycleHooks, LongTermMemory, MarkdownParser, Memory, type Mention, type Message, MoltbookAdapter, type MoltbookConfig, type MoltbookRegistration, type MoltbookStatus, OpenAIProvider, type Plugin, type Post, type PostResult, type PostgresConfig, type Profile, type RedisConfig, type ReplyResult, type ScheduledJob, type ScheduledTask, Scheduler, type SearchOptions, type SearchResult, ShortTermMemory, SocialAdapter, type SocialConfig, type SocialPlatformConfig, type StructuredSchema, type Submolt, type SubmoltSettings, type TimelineOptions, TwitterAdapter, type TwitterConfig, buildDecisionPrompt, buildSkillPrompt, buildSystemPrompt, builtInActions, createApp, createLogger, createMarkdownAction, createRoutes, moltbookActions, startServer, validateConfig };
1080
+ export { A2AClient, type A2AClientConfig, type A2AConfig, A2AIntegration, type A2AMessageOptions, type A2AMessageResponse, type A2AServerOptions, type Action, type ActionContext, ActionHandler, ActionRegistry, type ActionResult, Agent, AgentCardBuilder, type AgentConfig, type AgentState, AnthropicProvider, type BehaviorTrigger, type Comment, ConfigLoader, type ConfigType, type Conversation, type ConversationDetail, type CustomAPIConfig, type CustomCLIConfig, type CustomDeploymentConfig, type CustomDockerConfig, type CustomSSHConfig, type DMCheckResult, type DMRequest, type Decision, type DeploymentConfig, type DeploymentResult, type DeploymentStatus, type DirectMessage, type Experience, type FeedOptions, type GenerateOptions, LLMProvider, type LifecycleEvent, type LifecycleHooks, LongTermMemory, MarkdownParser, Memory, type Mention, type Message, MoltbookAdapter, type MoltbookConfig, type MoltbookRegistration, type MoltbookStatus, MoltiumExecutor, OpenAIProvider, type Plugin, type Post, type PostResult, type PostgresConfig, type Profile, type RedisConfig, type ReplyResult, type ScheduledJob, type ScheduledTask, Scheduler, type SearchOptions, type SearchResult, type ServerOptions, ShortTermMemory, SocialAdapter, type SocialConfig, type SocialPlatformConfig, type StructuredSchema, type Submolt, type SubmoltSettings, type TimelineOptions, TwitterAdapter, type TwitterConfig, buildDecisionPrompt, buildSkillPrompt, buildSystemPrompt, builtInActions, createA2AClient, createA2AIntegration, createApp, createJoinWorldAction, createLeaveWorldAction, createLogger, createMarkdownAction, createQueryWorldAction, createRoutes, createSendWorldMessageAction, moltbookActions, startServer, validateConfig, worldActions };