@moltium/core 0.1.19 → 0.1.20
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/README.md +231 -0
- package/dist/index.d.cts +157 -3
- package/dist/index.d.ts +157 -3
- package/dist/index.js +701 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +697 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npm install @moltium/core
|
|
|
18
18
|
- **Social adapters** for Moltbook and Twitter
|
|
19
19
|
- **Action system** with built-in actions, custom actions, and markdown-interpreted skills
|
|
20
20
|
- **HTTP server** (Express) with REST endpoints for monitoring and control
|
|
21
|
+
- **A2A Protocol support** for agent-to-agent communication (JSON-RPC, HTTP+JSON/REST)
|
|
21
22
|
- **Config loader** supporting both TypeScript and Markdown configurations
|
|
22
23
|
|
|
23
24
|
## Quick Start
|
|
@@ -60,6 +61,13 @@ const agent = new Agent(config);
|
|
|
60
61
|
startServer(agent, { port: 3000 });
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
The agent automatically exposes **A2A Protocol endpoints** for agent-to-agent communication:
|
|
65
|
+
- `/.well-known/agent-card.json` - Agent discovery
|
|
66
|
+
- `/a2a/jsonrpc` - JSON-RPC transport
|
|
67
|
+
- `/a2a/rest` - HTTP+JSON/REST transport (v0.3.0)
|
|
68
|
+
|
|
69
|
+
To enable A2A communication actions, add an `a2a` configuration section (see A2A Protocol Integration below).
|
|
70
|
+
|
|
63
71
|
## Agent Lifecycle
|
|
64
72
|
|
|
65
73
|
Agents follow a strict lifecycle: `idle` -> `initializing` -> `running` -> `stopping` -> `stopped`.
|
|
@@ -286,6 +294,220 @@ const { config, type } = await loader.load('./my-agent');
|
|
|
286
294
|
// type is 'code' or 'markdown'
|
|
287
295
|
```
|
|
288
296
|
|
|
297
|
+
## A2A Protocol Integration
|
|
298
|
+
|
|
299
|
+
Moltium includes full support for the [A2A Protocol](https://a2a.ai/) v0.3.0, enabling seamless agent-to-agent communication with automatic action registration and zero boilerplate.
|
|
300
|
+
|
|
301
|
+
### Quick Start
|
|
302
|
+
|
|
303
|
+
Add the `a2a` config section to automatically register communication actions:
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
export default {
|
|
307
|
+
name: 'My Agent',
|
|
308
|
+
// ... other config
|
|
309
|
+
|
|
310
|
+
a2a: {
|
|
311
|
+
enabled: true,
|
|
312
|
+
defaultPeerUrl: 'http://localhost:3001', // Optional default peer
|
|
313
|
+
verbose: true, // Enable detailed logging
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
actions: [
|
|
317
|
+
'talk_to_agent', // Automatically registered when a2a is enabled
|
|
318
|
+
],
|
|
319
|
+
} satisfies AgentConfig;
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Configure your server with A2A support:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
const port = parseInt(process.env.PORT || '3000', 10);
|
|
326
|
+
|
|
327
|
+
startServer(agent, {
|
|
328
|
+
port,
|
|
329
|
+
enableA2A: true,
|
|
330
|
+
a2aConfig: {
|
|
331
|
+
enabled: true,
|
|
332
|
+
baseUrl: `http://0.0.0.0:${port}`,
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Your agent now exposes:
|
|
338
|
+
- Agent Card at `/.well-known/agent-card.json`
|
|
339
|
+
- JSON-RPC endpoint at `/a2a/jsonrpc`
|
|
340
|
+
- Auto-registered `talk_to_agent` action
|
|
341
|
+
|
|
342
|
+
### Multiple Peer Agents
|
|
343
|
+
|
|
344
|
+
Define specific peer agents for targeted communication:
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
a2a: {
|
|
348
|
+
enabled: true,
|
|
349
|
+
peers: {
|
|
350
|
+
talk_to_analyst: 'http://localhost:3001',
|
|
351
|
+
talk_to_researcher: 'http://localhost:3002',
|
|
352
|
+
talk_to_trader: 'http://localhost:3003',
|
|
353
|
+
},
|
|
354
|
+
verbose: false,
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
actions: [
|
|
358
|
+
'talk_to_analyst', // Auto-registered with pre-configured URL
|
|
359
|
+
'talk_to_researcher', // Auto-registered
|
|
360
|
+
'talk_to_trader', // Auto-registered
|
|
361
|
+
],
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Programmatic A2A Client
|
|
365
|
+
|
|
366
|
+
For custom actions or advanced use cases:
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
import { createA2AClient, A2AClient } from '@moltium/core';
|
|
370
|
+
|
|
371
|
+
// Simple usage
|
|
372
|
+
const client = createA2AClient('http://localhost:3001');
|
|
373
|
+
const response = await client.sendMessage({
|
|
374
|
+
text: 'What are your thoughts on this strategy?',
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
if (response.success) {
|
|
378
|
+
console.log('Reply:', response.reply);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Advanced usage
|
|
382
|
+
const client = new A2AClient({
|
|
383
|
+
agentUrl: 'http://localhost:3001',
|
|
384
|
+
agentCardPath: '.well-known/agent-card.json',
|
|
385
|
+
timeout: 30000,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const response = await client.sendMessage({
|
|
389
|
+
text: 'Analyze this data',
|
|
390
|
+
contextId: 'analysis-session-123',
|
|
391
|
+
metadata: { priority: 'high' },
|
|
392
|
+
});
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Custom A2A Actions
|
|
396
|
+
|
|
397
|
+
Use action builders for maximum flexibility:
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { createA2ACommunicationAction, createMultipleA2AActions } from '@moltium/core';
|
|
401
|
+
|
|
402
|
+
// Single action
|
|
403
|
+
const talkToAnalyst = createA2ACommunicationAction({
|
|
404
|
+
actionName: 'consult_analyst',
|
|
405
|
+
defaultAgentUrl: 'http://localhost:3001',
|
|
406
|
+
description: 'Consult with the business analyst for strategic advice',
|
|
407
|
+
verbose: true,
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// Multiple actions at once
|
|
411
|
+
const a2aActions = createMultipleA2AActions({
|
|
412
|
+
ask_technical: {
|
|
413
|
+
defaultAgentUrl: 'http://localhost:3001',
|
|
414
|
+
description: 'Ask technical engineering questions',
|
|
415
|
+
},
|
|
416
|
+
ask_business: {
|
|
417
|
+
defaultAgentUrl: 'http://localhost:3002',
|
|
418
|
+
description: 'Ask business strategy questions',
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
export default {
|
|
423
|
+
customActions: [...a2aActions, talkToAnalyst],
|
|
424
|
+
actions: ['ask_technical', 'ask_business', 'consult_analyst'],
|
|
425
|
+
};
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### A2A API Reference
|
|
429
|
+
|
|
430
|
+
#### `A2AClient`
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
class A2AClient {
|
|
434
|
+
constructor(config: A2AClientConfig)
|
|
435
|
+
sendMessage(options: A2AMessageOptions): Promise<A2AMessageResponse>
|
|
436
|
+
getAgentCard(): Promise<AgentCard>
|
|
437
|
+
getAgentUrl(): string
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
interface A2AClientConfig {
|
|
441
|
+
agentUrl: string;
|
|
442
|
+
agentCardPath?: string; // Default: .well-known/agent-card.json
|
|
443
|
+
timeout?: number; // Default: 30000ms
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
interface A2AMessageOptions {
|
|
447
|
+
text: string;
|
|
448
|
+
contextId?: string;
|
|
449
|
+
metadata?: Record<string, unknown>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
interface A2AMessageResponse {
|
|
453
|
+
success: boolean;
|
|
454
|
+
reply?: string;
|
|
455
|
+
agentUrl?: string;
|
|
456
|
+
error?: string;
|
|
457
|
+
raw?: any;
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
#### Action Builders
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
// Single action builder
|
|
465
|
+
function createA2ACommunicationAction(config: {
|
|
466
|
+
defaultAgentUrl?: string;
|
|
467
|
+
actionName?: string; // Default: 'talk_to_agent'
|
|
468
|
+
description?: string;
|
|
469
|
+
verbose?: boolean;
|
|
470
|
+
}): Action
|
|
471
|
+
|
|
472
|
+
// Multiple actions builder
|
|
473
|
+
function createMultipleA2AActions(
|
|
474
|
+
configs: Record<string, A2ACommunicationActionConfig>
|
|
475
|
+
): Action[]
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Best Practices
|
|
479
|
+
|
|
480
|
+
**Use environment variables for URLs:**
|
|
481
|
+
```typescript
|
|
482
|
+
a2a: {
|
|
483
|
+
peers: {
|
|
484
|
+
talk_to_analyst: process.env.ANALYST_URL || 'http://localhost:3001',
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Enable verbose logging during development:**
|
|
490
|
+
```typescript
|
|
491
|
+
a2a: {
|
|
492
|
+
verbose: true, // Detailed A2A logs
|
|
493
|
+
},
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**Use 0.0.0.0 for local development:**
|
|
497
|
+
```typescript
|
|
498
|
+
a2aConfig: {
|
|
499
|
+
baseUrl: `http://0.0.0.0:${port}`, // Accessible from other agents
|
|
500
|
+
},
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
**Handle errors gracefully:**
|
|
504
|
+
```typescript
|
|
505
|
+
const response = await client.sendMessage({ text: 'Hello' });
|
|
506
|
+
if (!response.success) {
|
|
507
|
+
console.error('Communication failed:', response.error);
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
289
511
|
## AgentConfig Reference
|
|
290
512
|
|
|
291
513
|
```typescript
|
|
@@ -329,6 +551,15 @@ interface AgentConfig {
|
|
|
329
551
|
actions: string[]; // Built-in action names
|
|
330
552
|
customActions?: Action[]; // User-defined actions
|
|
331
553
|
plugins?: Plugin[];
|
|
554
|
+
|
|
555
|
+
// A2A Protocol configuration (optional)
|
|
556
|
+
a2a?: {
|
|
557
|
+
enabled?: boolean; // Enable A2A support
|
|
558
|
+
peers?: Record<string, string>; // Peer agents: { actionName: 'url' }
|
|
559
|
+
defaultPeerUrl?: string; // Default peer URL
|
|
560
|
+
verbose?: boolean; // Enable detailed logging
|
|
561
|
+
genericActionName?: string; // Custom name for generic action
|
|
562
|
+
};
|
|
332
563
|
}
|
|
333
564
|
```
|
|
334
565
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
2
|
-
import {
|
|
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';
|
|
@@ -739,15 +770,138 @@ declare const moltbookActions: Action[];
|
|
|
739
770
|
|
|
740
771
|
declare const builtInActions: Action[];
|
|
741
772
|
|
|
773
|
+
interface A2AConfig {
|
|
774
|
+
enabled: boolean;
|
|
775
|
+
baseUrl: string;
|
|
776
|
+
port?: number;
|
|
777
|
+
pushNotifications?: boolean;
|
|
778
|
+
streaming?: boolean;
|
|
779
|
+
stateTransitionHistory?: boolean;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Builds an A2A-compliant AgentCard from a Moltium AgentConfig.
|
|
783
|
+
*/
|
|
784
|
+
declare class AgentCardBuilder {
|
|
785
|
+
/**
|
|
786
|
+
* Creates an A2A AgentCard from Moltium configuration.
|
|
787
|
+
* @param config The Moltium agent configuration
|
|
788
|
+
* @param a2aConfig A2A-specific configuration (URLs, capabilities)
|
|
789
|
+
* @returns A2A-compliant AgentCard
|
|
790
|
+
*/
|
|
791
|
+
static build(config: AgentConfig, a2aConfig: A2AConfig): AgentCard;
|
|
792
|
+
/**
|
|
793
|
+
* Converts Moltium actions to A2A skills.
|
|
794
|
+
*/
|
|
795
|
+
private static buildSkills;
|
|
796
|
+
/**
|
|
797
|
+
* Updates an agent card with runtime information.
|
|
798
|
+
*/
|
|
799
|
+
static updateWithRuntime(agentCard: AgentCard, actualPort: number, actualHost?: string): AgentCard;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Adapts a Moltium Agent to the A2A AgentExecutor interface.
|
|
804
|
+
* This allows Moltium agents to respond to A2A protocol requests.
|
|
805
|
+
*/
|
|
806
|
+
declare class MoltiumExecutor implements AgentExecutor {
|
|
807
|
+
private agent;
|
|
808
|
+
private cancelledTasks;
|
|
809
|
+
constructor(agent: Agent);
|
|
810
|
+
/**
|
|
811
|
+
* Executes an A2A request using the Moltium agent.
|
|
812
|
+
* Converts A2A messages to Moltium actions and publishes results back via the event bus.
|
|
813
|
+
*/
|
|
814
|
+
execute(requestContext: RequestContext, eventBus: ExecutionEventBus): Promise<void>;
|
|
815
|
+
/**
|
|
816
|
+
* Handles task cancellation requests.
|
|
817
|
+
*/
|
|
818
|
+
cancelTask(taskId: string, eventBus: ExecutionEventBus): Promise<void>;
|
|
819
|
+
/**
|
|
820
|
+
* Extracts text content from an A2A message.
|
|
821
|
+
*/
|
|
822
|
+
private extractMessageContent;
|
|
823
|
+
/**
|
|
824
|
+
* Determines if the user message is requesting a specific action.
|
|
825
|
+
*/
|
|
826
|
+
private isActionRequest;
|
|
827
|
+
/**
|
|
828
|
+
* Executes a chat interaction using the agent's LLM.
|
|
829
|
+
*/
|
|
830
|
+
private executeChat;
|
|
831
|
+
/**
|
|
832
|
+
* Executes an action based on the user's request.
|
|
833
|
+
*/
|
|
834
|
+
private executeAction;
|
|
835
|
+
/**
|
|
836
|
+
* Publishes a successful result as an A2A artifact.
|
|
837
|
+
*/
|
|
838
|
+
private publishResult;
|
|
839
|
+
/**
|
|
840
|
+
* Publishes an error as an A2A artifact.
|
|
841
|
+
*/
|
|
842
|
+
private publishError;
|
|
843
|
+
/**
|
|
844
|
+
* Publishes a status update event.
|
|
845
|
+
*/
|
|
846
|
+
private publishStatusUpdate;
|
|
847
|
+
/**
|
|
848
|
+
* Publishes a cancellation status.
|
|
849
|
+
*/
|
|
850
|
+
private publishCancellation;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
interface A2AServerOptions {
|
|
854
|
+
a2aConfig: A2AConfig;
|
|
855
|
+
authToken?: string;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Creates A2A-compliant Express routes for a Moltium agent.
|
|
859
|
+
* These routes implement the Agent-to-Agent (A2A) protocol.
|
|
860
|
+
*/
|
|
861
|
+
declare class A2AIntegration {
|
|
862
|
+
private agent;
|
|
863
|
+
private agentCard;
|
|
864
|
+
private requestHandler;
|
|
865
|
+
private moltiumExecutor;
|
|
866
|
+
constructor(agent: Agent, options: A2AServerOptions);
|
|
867
|
+
/**
|
|
868
|
+
* Creates Express middleware handlers for A2A endpoints.
|
|
869
|
+
* Returns an object with individual handlers that can be mounted on specific routes.
|
|
870
|
+
*/
|
|
871
|
+
getHandlers(): {
|
|
872
|
+
agentCard: RequestHandler;
|
|
873
|
+
jsonRpc: RequestHandler;
|
|
874
|
+
rest: RequestHandler;
|
|
875
|
+
};
|
|
876
|
+
/**
|
|
877
|
+
* Updates the agent card with actual runtime information (host/port).
|
|
878
|
+
*/
|
|
879
|
+
updateAgentCard(actualPort: number, actualHost?: string): void;
|
|
880
|
+
/**
|
|
881
|
+
* Gets the current agent card.
|
|
882
|
+
*/
|
|
883
|
+
getAgentCard(): AgentCard;
|
|
884
|
+
/**
|
|
885
|
+
* Logs A2A endpoint information.
|
|
886
|
+
*/
|
|
887
|
+
logEndpoints(host: string, port: number): void;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Helper function to create and configure A2A integration for a Moltium agent.
|
|
891
|
+
*/
|
|
892
|
+
declare function createA2AIntegration(agent: Agent, options?: Partial<A2AServerOptions>): A2AIntegration;
|
|
893
|
+
|
|
742
894
|
interface ServerOptions {
|
|
743
895
|
port?: number;
|
|
744
896
|
host?: string;
|
|
897
|
+
enableA2A?: boolean;
|
|
898
|
+
a2aConfig?: A2AServerOptions['a2aConfig'];
|
|
745
899
|
}
|
|
746
|
-
declare function createApp(agent: Agent): express_serve_static_core.Express;
|
|
900
|
+
declare function createApp(agent: Agent, options?: ServerOptions): express_serve_static_core.Express;
|
|
747
901
|
declare function startServer(agent: Agent, options?: ServerOptions): Promise<void>;
|
|
748
902
|
|
|
749
903
|
declare function createRoutes(agent: Agent): Router;
|
|
750
904
|
|
|
751
905
|
declare function createLogger(label: string): winston.Logger;
|
|
752
906
|
|
|
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 };
|
|
907
|
+
export { type A2AConfig, A2AIntegration, 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, createA2AIntegration, createApp, createLogger, createMarkdownAction, createRoutes, moltbookActions, startServer, validateConfig };
|
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 {
|
|
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';
|
|
@@ -739,15 +770,138 @@ declare const moltbookActions: Action[];
|
|
|
739
770
|
|
|
740
771
|
declare const builtInActions: Action[];
|
|
741
772
|
|
|
773
|
+
interface A2AConfig {
|
|
774
|
+
enabled: boolean;
|
|
775
|
+
baseUrl: string;
|
|
776
|
+
port?: number;
|
|
777
|
+
pushNotifications?: boolean;
|
|
778
|
+
streaming?: boolean;
|
|
779
|
+
stateTransitionHistory?: boolean;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Builds an A2A-compliant AgentCard from a Moltium AgentConfig.
|
|
783
|
+
*/
|
|
784
|
+
declare class AgentCardBuilder {
|
|
785
|
+
/**
|
|
786
|
+
* Creates an A2A AgentCard from Moltium configuration.
|
|
787
|
+
* @param config The Moltium agent configuration
|
|
788
|
+
* @param a2aConfig A2A-specific configuration (URLs, capabilities)
|
|
789
|
+
* @returns A2A-compliant AgentCard
|
|
790
|
+
*/
|
|
791
|
+
static build(config: AgentConfig, a2aConfig: A2AConfig): AgentCard;
|
|
792
|
+
/**
|
|
793
|
+
* Converts Moltium actions to A2A skills.
|
|
794
|
+
*/
|
|
795
|
+
private static buildSkills;
|
|
796
|
+
/**
|
|
797
|
+
* Updates an agent card with runtime information.
|
|
798
|
+
*/
|
|
799
|
+
static updateWithRuntime(agentCard: AgentCard, actualPort: number, actualHost?: string): AgentCard;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Adapts a Moltium Agent to the A2A AgentExecutor interface.
|
|
804
|
+
* This allows Moltium agents to respond to A2A protocol requests.
|
|
805
|
+
*/
|
|
806
|
+
declare class MoltiumExecutor implements AgentExecutor {
|
|
807
|
+
private agent;
|
|
808
|
+
private cancelledTasks;
|
|
809
|
+
constructor(agent: Agent);
|
|
810
|
+
/**
|
|
811
|
+
* Executes an A2A request using the Moltium agent.
|
|
812
|
+
* Converts A2A messages to Moltium actions and publishes results back via the event bus.
|
|
813
|
+
*/
|
|
814
|
+
execute(requestContext: RequestContext, eventBus: ExecutionEventBus): Promise<void>;
|
|
815
|
+
/**
|
|
816
|
+
* Handles task cancellation requests.
|
|
817
|
+
*/
|
|
818
|
+
cancelTask(taskId: string, eventBus: ExecutionEventBus): Promise<void>;
|
|
819
|
+
/**
|
|
820
|
+
* Extracts text content from an A2A message.
|
|
821
|
+
*/
|
|
822
|
+
private extractMessageContent;
|
|
823
|
+
/**
|
|
824
|
+
* Determines if the user message is requesting a specific action.
|
|
825
|
+
*/
|
|
826
|
+
private isActionRequest;
|
|
827
|
+
/**
|
|
828
|
+
* Executes a chat interaction using the agent's LLM.
|
|
829
|
+
*/
|
|
830
|
+
private executeChat;
|
|
831
|
+
/**
|
|
832
|
+
* Executes an action based on the user's request.
|
|
833
|
+
*/
|
|
834
|
+
private executeAction;
|
|
835
|
+
/**
|
|
836
|
+
* Publishes a successful result as an A2A artifact.
|
|
837
|
+
*/
|
|
838
|
+
private publishResult;
|
|
839
|
+
/**
|
|
840
|
+
* Publishes an error as an A2A artifact.
|
|
841
|
+
*/
|
|
842
|
+
private publishError;
|
|
843
|
+
/**
|
|
844
|
+
* Publishes a status update event.
|
|
845
|
+
*/
|
|
846
|
+
private publishStatusUpdate;
|
|
847
|
+
/**
|
|
848
|
+
* Publishes a cancellation status.
|
|
849
|
+
*/
|
|
850
|
+
private publishCancellation;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
interface A2AServerOptions {
|
|
854
|
+
a2aConfig: A2AConfig;
|
|
855
|
+
authToken?: string;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Creates A2A-compliant Express routes for a Moltium agent.
|
|
859
|
+
* These routes implement the Agent-to-Agent (A2A) protocol.
|
|
860
|
+
*/
|
|
861
|
+
declare class A2AIntegration {
|
|
862
|
+
private agent;
|
|
863
|
+
private agentCard;
|
|
864
|
+
private requestHandler;
|
|
865
|
+
private moltiumExecutor;
|
|
866
|
+
constructor(agent: Agent, options: A2AServerOptions);
|
|
867
|
+
/**
|
|
868
|
+
* Creates Express middleware handlers for A2A endpoints.
|
|
869
|
+
* Returns an object with individual handlers that can be mounted on specific routes.
|
|
870
|
+
*/
|
|
871
|
+
getHandlers(): {
|
|
872
|
+
agentCard: RequestHandler;
|
|
873
|
+
jsonRpc: RequestHandler;
|
|
874
|
+
rest: RequestHandler;
|
|
875
|
+
};
|
|
876
|
+
/**
|
|
877
|
+
* Updates the agent card with actual runtime information (host/port).
|
|
878
|
+
*/
|
|
879
|
+
updateAgentCard(actualPort: number, actualHost?: string): void;
|
|
880
|
+
/**
|
|
881
|
+
* Gets the current agent card.
|
|
882
|
+
*/
|
|
883
|
+
getAgentCard(): AgentCard;
|
|
884
|
+
/**
|
|
885
|
+
* Logs A2A endpoint information.
|
|
886
|
+
*/
|
|
887
|
+
logEndpoints(host: string, port: number): void;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Helper function to create and configure A2A integration for a Moltium agent.
|
|
891
|
+
*/
|
|
892
|
+
declare function createA2AIntegration(agent: Agent, options?: Partial<A2AServerOptions>): A2AIntegration;
|
|
893
|
+
|
|
742
894
|
interface ServerOptions {
|
|
743
895
|
port?: number;
|
|
744
896
|
host?: string;
|
|
897
|
+
enableA2A?: boolean;
|
|
898
|
+
a2aConfig?: A2AServerOptions['a2aConfig'];
|
|
745
899
|
}
|
|
746
|
-
declare function createApp(agent: Agent): express_serve_static_core.Express;
|
|
900
|
+
declare function createApp(agent: Agent, options?: ServerOptions): express_serve_static_core.Express;
|
|
747
901
|
declare function startServer(agent: Agent, options?: ServerOptions): Promise<void>;
|
|
748
902
|
|
|
749
903
|
declare function createRoutes(agent: Agent): Router;
|
|
750
904
|
|
|
751
905
|
declare function createLogger(label: string): winston.Logger;
|
|
752
906
|
|
|
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 };
|
|
907
|
+
export { type A2AConfig, A2AIntegration, 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, createA2AIntegration, createApp, createLogger, createMarkdownAction, createRoutes, moltbookActions, startServer, validateConfig };
|