@agent-relay/daemon 0.1.0

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.
Files changed (109) hide show
  1. package/dist/agent-manager.d.ts +134 -0
  2. package/dist/agent-manager.d.ts.map +1 -0
  3. package/dist/agent-manager.js +578 -0
  4. package/dist/agent-manager.js.map +1 -0
  5. package/dist/agent-registry.d.ts +99 -0
  6. package/dist/agent-registry.d.ts.map +1 -0
  7. package/dist/agent-registry.js +213 -0
  8. package/dist/agent-registry.js.map +1 -0
  9. package/dist/agent-signing.d.ts +158 -0
  10. package/dist/agent-signing.d.ts.map +1 -0
  11. package/dist/agent-signing.js +523 -0
  12. package/dist/agent-signing.js.map +1 -0
  13. package/dist/api.d.ts +106 -0
  14. package/dist/api.d.ts.map +1 -0
  15. package/dist/api.js +876 -0
  16. package/dist/api.js.map +1 -0
  17. package/dist/auth.d.ts +94 -0
  18. package/dist/auth.d.ts.map +1 -0
  19. package/dist/auth.js +197 -0
  20. package/dist/auth.js.map +1 -0
  21. package/dist/channel-membership-store.d.ts +55 -0
  22. package/dist/channel-membership-store.d.ts.map +1 -0
  23. package/dist/channel-membership-store.js +176 -0
  24. package/dist/channel-membership-store.js.map +1 -0
  25. package/dist/cli-auth.d.ts +89 -0
  26. package/dist/cli-auth.d.ts.map +1 -0
  27. package/dist/cli-auth.js +792 -0
  28. package/dist/cli-auth.js.map +1 -0
  29. package/dist/cloud-sync.d.ts +150 -0
  30. package/dist/cloud-sync.d.ts.map +1 -0
  31. package/dist/cloud-sync.js +446 -0
  32. package/dist/cloud-sync.js.map +1 -0
  33. package/dist/connection.d.ts +130 -0
  34. package/dist/connection.d.ts.map +1 -0
  35. package/dist/connection.js +438 -0
  36. package/dist/connection.js.map +1 -0
  37. package/dist/consensus-integration.d.ts +167 -0
  38. package/dist/consensus-integration.d.ts.map +1 -0
  39. package/dist/consensus-integration.js +371 -0
  40. package/dist/consensus-integration.js.map +1 -0
  41. package/dist/consensus.d.ts +271 -0
  42. package/dist/consensus.d.ts.map +1 -0
  43. package/dist/consensus.js +632 -0
  44. package/dist/consensus.js.map +1 -0
  45. package/dist/delivery-tracker.d.ts +34 -0
  46. package/dist/delivery-tracker.d.ts.map +1 -0
  47. package/dist/delivery-tracker.js +104 -0
  48. package/dist/delivery-tracker.js.map +1 -0
  49. package/dist/enhanced-features.d.ts +118 -0
  50. package/dist/enhanced-features.d.ts.map +1 -0
  51. package/dist/enhanced-features.js +176 -0
  52. package/dist/enhanced-features.js.map +1 -0
  53. package/dist/index.d.ts +31 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +37 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/migrations/index.d.ts +73 -0
  58. package/dist/migrations/index.d.ts.map +1 -0
  59. package/dist/migrations/index.js +241 -0
  60. package/dist/migrations/index.js.map +1 -0
  61. package/dist/orchestrator.d.ts +217 -0
  62. package/dist/orchestrator.d.ts.map +1 -0
  63. package/dist/orchestrator.js +1143 -0
  64. package/dist/orchestrator.js.map +1 -0
  65. package/dist/rate-limiter.d.ts +68 -0
  66. package/dist/rate-limiter.d.ts.map +1 -0
  67. package/dist/rate-limiter.js +130 -0
  68. package/dist/rate-limiter.js.map +1 -0
  69. package/dist/registry.d.ts +9 -0
  70. package/dist/registry.d.ts.map +1 -0
  71. package/dist/registry.js +9 -0
  72. package/dist/registry.js.map +1 -0
  73. package/dist/relay-ledger.d.ts +261 -0
  74. package/dist/relay-ledger.d.ts.map +1 -0
  75. package/dist/relay-ledger.js +532 -0
  76. package/dist/relay-ledger.js.map +1 -0
  77. package/dist/relay-watchdog.d.ts +125 -0
  78. package/dist/relay-watchdog.d.ts.map +1 -0
  79. package/dist/relay-watchdog.js +611 -0
  80. package/dist/relay-watchdog.js.map +1 -0
  81. package/dist/repo-manager.d.ts +116 -0
  82. package/dist/repo-manager.d.ts.map +1 -0
  83. package/dist/repo-manager.js +384 -0
  84. package/dist/repo-manager.js.map +1 -0
  85. package/dist/router.d.ts +370 -0
  86. package/dist/router.d.ts.map +1 -0
  87. package/dist/router.js +1437 -0
  88. package/dist/router.js.map +1 -0
  89. package/dist/server.d.ts +174 -0
  90. package/dist/server.d.ts.map +1 -0
  91. package/dist/server.js +1001 -0
  92. package/dist/server.js.map +1 -0
  93. package/dist/spawn-manager.d.ts +78 -0
  94. package/dist/spawn-manager.d.ts.map +1 -0
  95. package/dist/spawn-manager.js +165 -0
  96. package/dist/spawn-manager.js.map +1 -0
  97. package/dist/sync-queue.d.ts +116 -0
  98. package/dist/sync-queue.d.ts.map +1 -0
  99. package/dist/sync-queue.js +361 -0
  100. package/dist/sync-queue.js.map +1 -0
  101. package/dist/types.d.ts +133 -0
  102. package/dist/types.d.ts.map +1 -0
  103. package/dist/types.js +6 -0
  104. package/dist/types.js.map +1 -0
  105. package/dist/workspace-manager.d.ts +80 -0
  106. package/dist/workspace-manager.d.ts.map +1 -0
  107. package/dist/workspace-manager.js +314 -0
  108. package/dist/workspace-manager.js.map +1 -0
  109. package/package.json +52 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Consensus Integration for Agent Relay
3
+ *
4
+ * Integrates the consensus mechanism with the router/daemon.
5
+ * This is an optional feature that can be enabled to allow agents
6
+ * to participate in distributed decision-making.
7
+ *
8
+ * Usage:
9
+ * 1. Create a ConsensusIntegration with the router and optional config
10
+ * 2. Call processIncomingMessage() on each received message to detect votes
11
+ * 3. Use createProposal() to start a new consensus vote
12
+ *
13
+ * Example:
14
+ * ```typescript
15
+ * const consensus = new ConsensusIntegration(router, { enabled: true });
16
+ *
17
+ * // Create a proposal
18
+ * consensus.createProposal({
19
+ * title: 'Approve API design',
20
+ * description: 'Should we proceed with the REST API design?',
21
+ * proposer: 'Architect',
22
+ * participants: ['Developer', 'Reviewer', 'Lead'],
23
+ * consensusType: 'majority',
24
+ * });
25
+ *
26
+ * // Process incoming messages to detect votes
27
+ * consensus.processIncomingMessage(from, body);
28
+ * ```
29
+ */
30
+ import { ConsensusEngine, createConsensusEngine, formatProposalMessage, formatResultMessage, parseVoteCommand, parseProposalCommand, isConsensusCommand, type Proposal, type ConsensusResult, type ConsensusConfig, type VoteValue, type ConsensusType, type ParsedProposalCommand } from './consensus.js';
31
+ import type { Router } from './router.js';
32
+ export interface CloudSyncConfig {
33
+ /** Cloud API base URL (defaults to AGENT_RELAY_CLOUD_URL or https://agent-relay.com) */
34
+ url?: string;
35
+ /** Daemon API key for authentication (defaults to AGENT_RELAY_API_KEY) */
36
+ apiKey?: string;
37
+ /** Workspace ID for self-hosted setups (optional - cloud can derive from API key) */
38
+ workspaceId?: string;
39
+ }
40
+ export interface ConsensusIntegrationConfig {
41
+ /** Enable consensus feature (default: true) */
42
+ enabled: boolean;
43
+ /** Consensus engine configuration */
44
+ consensus?: Partial<ConsensusConfig>;
45
+ /** Auto-broadcast proposals to participants (default: true) */
46
+ autoBroadcast?: boolean;
47
+ /** Auto-broadcast results when resolved (default: true) */
48
+ autoResultBroadcast?: boolean;
49
+ /** Log consensus events (default: true) */
50
+ logEvents?: boolean;
51
+ /** Cloud sync configuration (optional) */
52
+ cloudSync?: CloudSyncConfig;
53
+ }
54
+ export interface ProposalOptions {
55
+ title: string;
56
+ description: string;
57
+ proposer: string;
58
+ participants: string[];
59
+ consensusType?: ConsensusType;
60
+ timeoutMs?: number;
61
+ quorum?: number;
62
+ threshold?: number;
63
+ metadata?: Record<string, unknown>;
64
+ }
65
+ /**
66
+ * Integrates consensus mechanism with the relay router.
67
+ * Provides automatic proposal broadcasting and vote detection.
68
+ */
69
+ export declare class ConsensusIntegration {
70
+ private config;
71
+ private engine;
72
+ private router;
73
+ private log;
74
+ constructor(router: Router, config?: Partial<ConsensusIntegrationConfig>);
75
+ /**
76
+ * Check if consensus is enabled.
77
+ */
78
+ get enabled(): boolean;
79
+ /**
80
+ * Get the underlying consensus engine.
81
+ */
82
+ getEngine(): ConsensusEngine;
83
+ /**
84
+ * Create a new proposal and optionally broadcast to participants.
85
+ */
86
+ createProposal(options: ProposalOptions): Proposal;
87
+ /**
88
+ * Process an incoming message to detect and handle consensus commands.
89
+ * Handles both PROPOSE and VOTE commands.
90
+ */
91
+ processIncomingMessage(from: string, body: string): {
92
+ isConsensusCommand: boolean;
93
+ type?: 'propose' | 'vote';
94
+ result?: {
95
+ success: boolean;
96
+ error?: string;
97
+ proposal?: Proposal;
98
+ };
99
+ };
100
+ /**
101
+ * Check if a message is a consensus command without processing it.
102
+ */
103
+ isConsensusMessage(body: string): boolean;
104
+ /**
105
+ * Get pending proposals for an agent.
106
+ */
107
+ getPendingVotes(agentName: string): Proposal[];
108
+ /**
109
+ * Get all proposals for an agent.
110
+ */
111
+ getProposals(agentName: string): Proposal[];
112
+ /**
113
+ * Get a specific proposal by ID.
114
+ */
115
+ getProposal(proposalId: string): Proposal | null;
116
+ /**
117
+ * Cancel a proposal.
118
+ */
119
+ cancelProposal(proposalId: string, agentName: string): {
120
+ success: boolean;
121
+ error?: string;
122
+ };
123
+ /**
124
+ * Get consensus statistics.
125
+ */
126
+ getStats(): {
127
+ total: number;
128
+ pending: number;
129
+ approved: number;
130
+ rejected: number;
131
+ expired: number;
132
+ cancelled: number;
133
+ avgParticipation: number;
134
+ };
135
+ /**
136
+ * Cleanup resources.
137
+ */
138
+ cleanup(): void;
139
+ /**
140
+ * Sync a proposal to the cloud dashboard.
141
+ *
142
+ * Auto-detects cloud settings from workspace env vars:
143
+ * - CLOUD_API_URL / AGENT_RELAY_CLOUD_URL - cloud URL
144
+ * - WORKSPACE_ID / AGENT_RELAY_WORKSPACE_ID - workspace ID
145
+ * - WORKSPACE_TOKEN / AGENT_RELAY_API_KEY - auth token
146
+ */
147
+ private syncToCloud;
148
+ private setupEventHandlers;
149
+ /**
150
+ * Broadcast a proposal to all participants via the router.
151
+ */
152
+ private broadcastProposal;
153
+ /**
154
+ * Broadcast the result of a proposal to all participants.
155
+ */
156
+ private broadcastResult;
157
+ /**
158
+ * Send a message to an agent via the router.
159
+ */
160
+ private sendToAgent;
161
+ }
162
+ /**
163
+ * Create a consensus integration instance.
164
+ */
165
+ export declare function createConsensusIntegration(router: Router, config?: Partial<ConsensusIntegrationConfig>): ConsensusIntegration;
166
+ export { ConsensusEngine, createConsensusEngine, formatProposalMessage, formatResultMessage, parseVoteCommand, parseProposalCommand, isConsensusCommand, type Proposal, type ConsensusResult, type ConsensusConfig, type VoteValue, type ConsensusType, type ParsedProposalCommand, };
167
+ //# sourceMappingURL=consensus-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consensus-integration.d.ts","sourceRoot":"","sources":["../src/consensus-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAO1C,MAAM,WAAW,eAAe;IAC9B,wFAAwF;IACxF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACrC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0CAA0C;IAC1C,SAAS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AEG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE;IAI3C;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IAIhD;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAI3F;;OAEG;IACH,QAAQ;;;;;;;;;IAIR;;OAEG;IACH,OAAO,IAAI,IAAI;IAQf;;;;;;;OAOG;YACW,WAAW;IAsDzB,OAAO,CAAC,kBAAkB;IAqD1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,WAAW;CAuCpB;AAMD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAC3C,oBAAoB,CAEtB;AAMD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,GAC3B,CAAC"}
@@ -0,0 +1,371 @@
1
+ /**
2
+ * Consensus Integration for Agent Relay
3
+ *
4
+ * Integrates the consensus mechanism with the router/daemon.
5
+ * This is an optional feature that can be enabled to allow agents
6
+ * to participate in distributed decision-making.
7
+ *
8
+ * Usage:
9
+ * 1. Create a ConsensusIntegration with the router and optional config
10
+ * 2. Call processIncomingMessage() on each received message to detect votes
11
+ * 3. Use createProposal() to start a new consensus vote
12
+ *
13
+ * Example:
14
+ * ```typescript
15
+ * const consensus = new ConsensusIntegration(router, { enabled: true });
16
+ *
17
+ * // Create a proposal
18
+ * consensus.createProposal({
19
+ * title: 'Approve API design',
20
+ * description: 'Should we proceed with the REST API design?',
21
+ * proposer: 'Architect',
22
+ * participants: ['Developer', 'Reviewer', 'Lead'],
23
+ * consensusType: 'majority',
24
+ * });
25
+ *
26
+ * // Process incoming messages to detect votes
27
+ * consensus.processIncomingMessage(from, body);
28
+ * ```
29
+ */
30
+ import { generateId } from '@agent-relay/wrapper';
31
+ import { ConsensusEngine, createConsensusEngine, formatProposalMessage, formatResultMessage, parseVoteCommand, parseProposalCommand, isConsensusCommand, } from './consensus.js';
32
+ import { PROTOCOL_VERSION } from '@agent-relay/protocol/types';
33
+ const DEFAULT_CONFIG = {
34
+ enabled: true,
35
+ autoBroadcast: true,
36
+ autoResultBroadcast: true,
37
+ logEvents: true,
38
+ };
39
+ // =============================================================================
40
+ // Consensus Integration
41
+ // =============================================================================
42
+ /**
43
+ * Integrates consensus mechanism with the relay router.
44
+ * Provides automatic proposal broadcasting and vote detection.
45
+ */
46
+ export class ConsensusIntegration {
47
+ config;
48
+ engine;
49
+ router;
50
+ log;
51
+ constructor(router, config = {}) {
52
+ this.config = { ...DEFAULT_CONFIG, ...config };
53
+ this.router = router;
54
+ this.engine = createConsensusEngine(config.consensus);
55
+ // Setup logging
56
+ this.log = this.config.logEvents
57
+ ? (msg, data) => console.log(`[consensus] ${msg}`, data ?? '')
58
+ : () => { };
59
+ // Subscribe to engine events
60
+ this.setupEventHandlers();
61
+ }
62
+ /**
63
+ * Check if consensus is enabled.
64
+ */
65
+ get enabled() {
66
+ return this.config.enabled;
67
+ }
68
+ /**
69
+ * Get the underlying consensus engine.
70
+ */
71
+ getEngine() {
72
+ return this.engine;
73
+ }
74
+ /**
75
+ * Create a new proposal and optionally broadcast to participants.
76
+ */
77
+ createProposal(options) {
78
+ if (!this.config.enabled) {
79
+ throw new Error('Consensus is not enabled');
80
+ }
81
+ const proposal = this.engine.createProposal({
82
+ ...options,
83
+ thread: `consensus-${options.title.toLowerCase().replace(/\s+/g, '-')}`,
84
+ });
85
+ this.log('Proposal created', { id: proposal.id, title: proposal.title });
86
+ return proposal;
87
+ }
88
+ /**
89
+ * Process an incoming message to detect and handle consensus commands.
90
+ * Handles both PROPOSE and VOTE commands.
91
+ */
92
+ processIncomingMessage(from, body) {
93
+ if (!this.config.enabled) {
94
+ return { isConsensusCommand: false };
95
+ }
96
+ // Check for PROPOSE command
97
+ const proposeCmd = parseProposalCommand(body);
98
+ if (proposeCmd) {
99
+ try {
100
+ const proposal = this.createProposal({
101
+ ...proposeCmd,
102
+ proposer: from,
103
+ });
104
+ this.log('Proposal created via command', {
105
+ from,
106
+ proposalId: proposal.id,
107
+ title: proposal.title,
108
+ });
109
+ return {
110
+ isConsensusCommand: true,
111
+ type: 'propose',
112
+ result: { success: true, proposal },
113
+ };
114
+ }
115
+ catch (err) {
116
+ return {
117
+ isConsensusCommand: true,
118
+ type: 'propose',
119
+ result: {
120
+ success: false,
121
+ error: err instanceof Error ? err.message : 'Failed to create proposal',
122
+ },
123
+ };
124
+ }
125
+ }
126
+ // Check for VOTE command
127
+ const voteCmd = parseVoteCommand(body);
128
+ if (voteCmd) {
129
+ const result = this.engine.vote(voteCmd.proposalId, from, voteCmd.value, voteCmd.reason);
130
+ this.log('Vote received', {
131
+ from,
132
+ proposalId: voteCmd.proposalId,
133
+ value: voteCmd.value,
134
+ success: result.success,
135
+ });
136
+ return { isConsensusCommand: true, type: 'vote', result };
137
+ }
138
+ return { isConsensusCommand: false };
139
+ }
140
+ /**
141
+ * Check if a message is a consensus command without processing it.
142
+ */
143
+ isConsensusMessage(body) {
144
+ return isConsensusCommand(body);
145
+ }
146
+ /**
147
+ * Get pending proposals for an agent.
148
+ */
149
+ getPendingVotes(agentName) {
150
+ return this.engine.getPendingVotesForAgent(agentName);
151
+ }
152
+ /**
153
+ * Get all proposals for an agent.
154
+ */
155
+ getProposals(agentName) {
156
+ return this.engine.getProposalsForAgent(agentName);
157
+ }
158
+ /**
159
+ * Get a specific proposal by ID.
160
+ */
161
+ getProposal(proposalId) {
162
+ return this.engine.getProposal(proposalId);
163
+ }
164
+ /**
165
+ * Cancel a proposal.
166
+ */
167
+ cancelProposal(proposalId, agentName) {
168
+ return this.engine.cancelProposal(proposalId, agentName);
169
+ }
170
+ /**
171
+ * Get consensus statistics.
172
+ */
173
+ getStats() {
174
+ return this.engine.getStats();
175
+ }
176
+ /**
177
+ * Cleanup resources.
178
+ */
179
+ cleanup() {
180
+ this.engine.cleanup();
181
+ }
182
+ // ===========================================================================
183
+ // Private Methods
184
+ // ===========================================================================
185
+ /**
186
+ * Sync a proposal to the cloud dashboard.
187
+ *
188
+ * Auto-detects cloud settings from workspace env vars:
189
+ * - CLOUD_API_URL / AGENT_RELAY_CLOUD_URL - cloud URL
190
+ * - WORKSPACE_ID / AGENT_RELAY_WORKSPACE_ID - workspace ID
191
+ * - WORKSPACE_TOKEN / AGENT_RELAY_API_KEY - auth token
192
+ */
193
+ async syncToCloud(proposal, event) {
194
+ // Get cloud sync settings - check workspace env vars first, then agent-relay vars
195
+ const cloudUrl = this.config.cloudSync?.url
196
+ || process.env.CLOUD_API_URL
197
+ || process.env.AGENT_RELAY_CLOUD_URL;
198
+ const workspaceId = this.config.cloudSync?.workspaceId
199
+ || process.env.WORKSPACE_ID
200
+ || process.env.AGENT_RELAY_WORKSPACE_ID;
201
+ const token = this.config.cloudSync?.apiKey
202
+ || process.env.WORKSPACE_TOKEN
203
+ || process.env.AGENT_RELAY_API_KEY;
204
+ // Skip if no cloud URL configured
205
+ if (!cloudUrl) {
206
+ return;
207
+ }
208
+ // Skip if no workspace ID
209
+ if (!workspaceId) {
210
+ return;
211
+ }
212
+ try {
213
+ const url = `${cloudUrl}/api/daemons/consensus/sync`;
214
+ // Build headers - token is optional for localhost
215
+ const headers = {
216
+ 'Content-Type': 'application/json',
217
+ };
218
+ if (token) {
219
+ headers['Authorization'] = `Bearer ${token}`;
220
+ }
221
+ const response = await fetch(url, {
222
+ method: 'POST',
223
+ headers,
224
+ body: JSON.stringify({ proposal, event, workspaceId }),
225
+ });
226
+ if (!response.ok) {
227
+ const errorText = await response.text();
228
+ this.log(`Cloud sync failed: ${response.status} ${errorText}`);
229
+ }
230
+ else {
231
+ this.log(`Cloud sync: ${event} for proposal ${proposal.id}`);
232
+ }
233
+ }
234
+ catch (err) {
235
+ // Don't fail on cloud sync errors - just log them
236
+ this.log(`Cloud sync error: ${err instanceof Error ? err.message : String(err)}`);
237
+ }
238
+ }
239
+ setupEventHandlers() {
240
+ // Broadcast new proposals to participants
241
+ this.engine.on('proposal:created', (proposal) => {
242
+ if (this.config.autoBroadcast) {
243
+ this.broadcastProposal(proposal);
244
+ }
245
+ // Sync to cloud dashboard
246
+ this.syncToCloud(proposal, 'created');
247
+ });
248
+ // Notify participants when someone votes
249
+ this.engine.on('proposal:voted', (proposal, vote) => {
250
+ this.log('Vote recorded', {
251
+ proposalId: proposal.id,
252
+ voter: vote.agent,
253
+ value: vote.value,
254
+ });
255
+ // Sync updated proposal to cloud dashboard
256
+ this.syncToCloud(proposal, 'voted');
257
+ });
258
+ // Broadcast results when resolved
259
+ this.engine.on('proposal:resolved', (proposal, result) => {
260
+ this.log('Proposal resolved', {
261
+ id: proposal.id,
262
+ decision: result.decision,
263
+ participation: `${(result.participation * 100).toFixed(1)}%`,
264
+ });
265
+ if (this.config.autoResultBroadcast) {
266
+ this.broadcastResult(proposal, result);
267
+ }
268
+ // Sync resolved proposal to cloud dashboard
269
+ this.syncToCloud(proposal, 'resolved');
270
+ });
271
+ // Log expired proposals
272
+ this.engine.on('proposal:expired', (proposal) => {
273
+ this.log('Proposal expired', { id: proposal.id, title: proposal.title });
274
+ // Sync expired proposal to cloud dashboard
275
+ this.syncToCloud(proposal, 'expired');
276
+ });
277
+ // Log cancelled proposals
278
+ this.engine.on('proposal:cancelled', (proposal) => {
279
+ this.log('Proposal cancelled', { id: proposal.id, title: proposal.title });
280
+ // Sync cancelled proposal to cloud dashboard
281
+ this.syncToCloud(proposal, 'cancelled');
282
+ });
283
+ }
284
+ /**
285
+ * Broadcast a proposal to all participants via the router.
286
+ */
287
+ broadcastProposal(proposal) {
288
+ const message = formatProposalMessage(proposal);
289
+ for (const participant of proposal.participants) {
290
+ this.sendToAgent(proposal.proposer, participant, message, proposal.thread);
291
+ }
292
+ this.log('Proposal broadcast', {
293
+ id: proposal.id,
294
+ recipients: proposal.participants.length,
295
+ });
296
+ }
297
+ /**
298
+ * Broadcast the result of a proposal to all participants.
299
+ */
300
+ broadcastResult(proposal, result) {
301
+ const message = formatResultMessage(proposal, result);
302
+ // Send to proposer
303
+ this.sendToAgent('_consensus', proposal.proposer, message, proposal.thread);
304
+ // Send to all participants
305
+ for (const participant of proposal.participants) {
306
+ if (participant !== proposal.proposer) {
307
+ this.sendToAgent('_consensus', participant, message, proposal.thread);
308
+ }
309
+ }
310
+ this.log('Result broadcast', {
311
+ id: proposal.id,
312
+ decision: result.decision,
313
+ recipients: proposal.participants.length,
314
+ });
315
+ }
316
+ /**
317
+ * Send a message to an agent via the router.
318
+ */
319
+ sendToAgent(from, to, body, thread) {
320
+ // Create a SEND envelope
321
+ const envelope = {
322
+ v: PROTOCOL_VERSION,
323
+ type: 'SEND',
324
+ id: generateId(),
325
+ ts: Date.now(),
326
+ from,
327
+ to,
328
+ payload: {
329
+ kind: 'action',
330
+ body,
331
+ thread,
332
+ data: {
333
+ _isConsensusMessage: true,
334
+ _consensusAction: 'proposal',
335
+ },
336
+ },
337
+ };
338
+ // Get the target connection and route
339
+ const target = this.router.getConnection(to);
340
+ if (target) {
341
+ // Use a mock connection for system messages
342
+ const mockFrom = {
343
+ id: `consensus-${generateId()}`,
344
+ agentName: from,
345
+ sessionId: 'consensus-system',
346
+ close: () => { },
347
+ send: () => true,
348
+ getNextSeq: () => 0,
349
+ };
350
+ // Route the message
351
+ this.router.route(mockFrom, envelope);
352
+ }
353
+ else {
354
+ this.log(`Target agent not connected: ${to}`);
355
+ }
356
+ }
357
+ }
358
+ // =============================================================================
359
+ // Factory Function
360
+ // =============================================================================
361
+ /**
362
+ * Create a consensus integration instance.
363
+ */
364
+ export function createConsensusIntegration(router, config) {
365
+ return new ConsensusIntegration(router, config);
366
+ }
367
+ // =============================================================================
368
+ // Re-exports for convenience
369
+ // =============================================================================
370
+ export { ConsensusEngine, createConsensusEngine, formatProposalMessage, formatResultMessage, parseVoteCommand, parseProposalCommand, isConsensusCommand, };
371
+ //# sourceMappingURL=consensus-integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consensus-integration.js","sourceRoot":"","sources":["../src/consensus-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,GAOnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAqB,MAAM,6BAA6B,CAAC;AA0ClF,MAAM,cAAc,GAA+B;IACjD,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,IAAI;IACzB,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAA6B;IACnC,MAAM,CAAkB;IACxB,MAAM,CAAS;IACf,GAAG,CAAwD;IAEnE,YACE,MAAc,EACd,SAA8C,EAAE;QAEhD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAEtD,gBAAgB;QAChB,IAAI,CAAC,GA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