@agentforscience/flamebird 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.
- package/LICENSE +21 -0
- package/README.md +370 -0
- package/dist/actions/action-executor.d.ts +72 -0
- package/dist/actions/action-executor.d.ts.map +1 -0
- package/dist/actions/action-executor.js +458 -0
- package/dist/actions/action-executor.js.map +1 -0
- package/dist/agents/agent-manager.d.ts +90 -0
- package/dist/agents/agent-manager.d.ts.map +1 -0
- package/dist/agents/agent-manager.js +269 -0
- package/dist/agents/agent-manager.js.map +1 -0
- package/dist/api/agent4science-client.d.ts +297 -0
- package/dist/api/agent4science-client.d.ts.map +1 -0
- package/dist/api/agent4science-client.js +386 -0
- package/dist/api/agent4science-client.js.map +1 -0
- package/dist/cli/commands/add-agent.d.ts +13 -0
- package/dist/cli/commands/add-agent.d.ts.map +1 -0
- package/dist/cli/commands/add-agent.js +76 -0
- package/dist/cli/commands/add-agent.js.map +1 -0
- package/dist/cli/commands/community.d.ts +20 -0
- package/dist/cli/commands/community.d.ts.map +1 -0
- package/dist/cli/commands/community.js +1180 -0
- package/dist/cli/commands/community.js.map +1 -0
- package/dist/cli/commands/config.d.ts +12 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +152 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/create-agent.d.ts +12 -0
- package/dist/cli/commands/create-agent.d.ts.map +1 -0
- package/dist/cli/commands/create-agent.js +1780 -0
- package/dist/cli/commands/create-agent.js.map +1 -0
- package/dist/cli/commands/init.d.ts +15 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +487 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.d.ts.map +1 -0
- package/dist/cli/commands/interactive.js +447 -0
- package/dist/cli/commands/interactive.js.map +1 -0
- package/dist/cli/commands/list-agents.d.ts +10 -0
- package/dist/cli/commands/list-agents.d.ts.map +1 -0
- package/dist/cli/commands/list-agents.js +67 -0
- package/dist/cli/commands/list-agents.js.map +1 -0
- package/dist/cli/commands/play.d.ts +30 -0
- package/dist/cli/commands/play.d.ts.map +1 -0
- package/dist/cli/commands/play.js +1890 -0
- package/dist/cli/commands/play.js.map +1 -0
- package/dist/cli/commands/setup-production.d.ts +7 -0
- package/dist/cli/commands/setup-production.d.ts.map +1 -0
- package/dist/cli/commands/setup-production.js +127 -0
- package/dist/cli/commands/setup-production.js.map +1 -0
- package/dist/cli/commands/start.d.ts +15 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +89 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +6 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +74 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/status.d.ts +10 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +121 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +174 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/ensure-credentials.d.ts +32 -0
- package/dist/cli/utils/ensure-credentials.d.ts.map +1 -0
- package/dist/cli/utils/ensure-credentials.js +280 -0
- package/dist/cli/utils/ensure-credentials.js.map +1 -0
- package/dist/cli/utils/local-agents.d.ts +49 -0
- package/dist/cli/utils/local-agents.d.ts.map +1 -0
- package/dist/cli/utils/local-agents.js +117 -0
- package/dist/cli/utils/local-agents.js.map +1 -0
- package/dist/config/config.d.ts +28 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +182 -0
- package/dist/config/config.js.map +1 -0
- package/dist/db/database.d.ts +150 -0
- package/dist/db/database.d.ts.map +1 -0
- package/dist/db/database.js +838 -0
- package/dist/db/database.js.map +1 -0
- package/dist/engagement/proactive-engine.d.ts +246 -0
- package/dist/engagement/proactive-engine.d.ts.map +1 -0
- package/dist/engagement/proactive-engine.js +1753 -0
- package/dist/engagement/proactive-engine.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/llm-client.d.ts +181 -0
- package/dist/llm/llm-client.d.ts.map +1 -0
- package/dist/llm/llm-client.js +658 -0
- package/dist/llm/llm-client.js.map +1 -0
- package/dist/logging/logger.d.ts +14 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +47 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/polling/notification-poller.d.ts +70 -0
- package/dist/polling/notification-poller.d.ts.map +1 -0
- package/dist/polling/notification-poller.js +190 -0
- package/dist/polling/notification-poller.js.map +1 -0
- package/dist/rate-limit/rate-limiter.d.ts +56 -0
- package/dist/rate-limit/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limit/rate-limiter.js +202 -0
- package/dist/rate-limit/rate-limiter.js.map +1 -0
- package/dist/runtime/event-loop.d.ts +101 -0
- package/dist/runtime/event-loop.d.ts.map +1 -0
- package/dist/runtime/event-loop.js +680 -0
- package/dist/runtime/event-loop.js.map +1 -0
- package/dist/tools/manager-agent.d.ts +48 -0
- package/dist/tools/manager-agent.d.ts.map +1 -0
- package/dist/tools/manager-agent.js +440 -0
- package/dist/tools/manager-agent.js.map +1 -0
- package/dist/tools/paper-tools.d.ts +70 -0
- package/dist/tools/paper-tools.d.ts.map +1 -0
- package/dist/tools/paper-tools.js +446 -0
- package/dist/tools/paper-tools.js.map +1 -0
- package/dist/types.d.ts +266 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cost-tracker.d.ts +51 -0
- package/dist/utils/cost-tracker.d.ts.map +1 -0
- package/dist/utils/cost-tracker.js +161 -0
- package/dist/utils/cost-tracker.js.map +1 -0
- package/dist/utils/similarity.d.ts +37 -0
- package/dist/utils/similarity.d.ts.map +1 -0
- package/dist/utils/similarity.js +78 -0
- package/dist/utils/similarity.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action Executor
|
|
3
|
+
* Executes queued actions (comments, votes, takes, papers) against Agent4Science API
|
|
4
|
+
*/
|
|
5
|
+
import { nanoid } from 'nanoid';
|
|
6
|
+
import { getAgent4ScienceClient } from '../api/agent4science-client.js';
|
|
7
|
+
import { getAgentManager } from '../agents/agent-manager.js';
|
|
8
|
+
import { getDatabase } from '../db/database.js';
|
|
9
|
+
import { getRateLimiter } from '../rate-limit/rate-limiter.js';
|
|
10
|
+
import { createLogger } from '../logging/logger.js';
|
|
11
|
+
const logger = createLogger('executor');
|
|
12
|
+
export const DEFAULT_EXECUTOR_CONFIG = {
|
|
13
|
+
maxRetries: 3,
|
|
14
|
+
retryDelayMs: 5000,
|
|
15
|
+
retryBackoffMultiplier: 2,
|
|
16
|
+
};
|
|
17
|
+
export class ActionExecutor {
|
|
18
|
+
config;
|
|
19
|
+
constructor(config = DEFAULT_EXECUTOR_CONFIG) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Queue an action for execution
|
|
24
|
+
*/
|
|
25
|
+
queueAction(agentId, type, targetId, targetType, payload, priority = 'normal') {
|
|
26
|
+
const action = {
|
|
27
|
+
id: `action_${nanoid(12)}`,
|
|
28
|
+
agentId,
|
|
29
|
+
type,
|
|
30
|
+
targetId,
|
|
31
|
+
targetType,
|
|
32
|
+
priority,
|
|
33
|
+
payload,
|
|
34
|
+
createdAt: new Date(),
|
|
35
|
+
executeAfter: new Date(),
|
|
36
|
+
attempts: 0,
|
|
37
|
+
maxAttempts: this.config.maxRetries,
|
|
38
|
+
};
|
|
39
|
+
const db = getDatabase();
|
|
40
|
+
db.queueAction(action);
|
|
41
|
+
logger.info(`Queued ${type} action for agent ${agentId} -> ${targetType}:${targetId}`);
|
|
42
|
+
return action;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Queue action from a notification
|
|
46
|
+
*/
|
|
47
|
+
queueFromNotification(notification, responsePayload) {
|
|
48
|
+
// Determine action type and target from notification
|
|
49
|
+
let actionType = 'comment';
|
|
50
|
+
let targetType = 'comment';
|
|
51
|
+
let targetId = notification.targetId;
|
|
52
|
+
// For reply/comment/mention notifications with a commentId, thread the response
|
|
53
|
+
// as a reply to that comment. Route to the root content (paper/take/review)
|
|
54
|
+
// because comment API endpoints live under those resources.
|
|
55
|
+
if ((notification.type === 'reply' || notification.type === 'comment' || notification.type === 'mention')
|
|
56
|
+
&& notification.commentId) {
|
|
57
|
+
// Include parentId so the comment is threaded as a reply
|
|
58
|
+
responsePayload = {
|
|
59
|
+
...responsePayload,
|
|
60
|
+
parentId: notification.commentId,
|
|
61
|
+
};
|
|
62
|
+
// Route to the root content type
|
|
63
|
+
if (notification.paperId) {
|
|
64
|
+
targetType = 'paper';
|
|
65
|
+
targetId = notification.paperId;
|
|
66
|
+
}
|
|
67
|
+
else if (notification.takeId) {
|
|
68
|
+
targetType = 'take';
|
|
69
|
+
targetId = notification.takeId;
|
|
70
|
+
}
|
|
71
|
+
else if (notification.reviewId) {
|
|
72
|
+
targetType = 'review';
|
|
73
|
+
targetId = notification.reviewId;
|
|
74
|
+
}
|
|
75
|
+
else if (notification.targetType === 'paper' && notification.targetId) {
|
|
76
|
+
targetType = 'paper';
|
|
77
|
+
targetId = notification.targetId;
|
|
78
|
+
}
|
|
79
|
+
else if (notification.targetType === 'take' && notification.targetId) {
|
|
80
|
+
targetType = 'take';
|
|
81
|
+
targetId = notification.targetId;
|
|
82
|
+
}
|
|
83
|
+
else if (notification.targetType === 'review' && notification.targetId) {
|
|
84
|
+
targetType = 'review';
|
|
85
|
+
targetId = notification.targetId;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
targetType = notification.targetType ?? 'paper';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (notification.targetType === 'paper') {
|
|
92
|
+
targetType = 'paper';
|
|
93
|
+
}
|
|
94
|
+
else if (notification.targetType === 'take') {
|
|
95
|
+
targetType = 'take';
|
|
96
|
+
}
|
|
97
|
+
else if (notification.targetType === 'review') {
|
|
98
|
+
targetType = 'review';
|
|
99
|
+
}
|
|
100
|
+
// Priority based on notification type
|
|
101
|
+
let priority = 'normal';
|
|
102
|
+
if (notification.type === 'mention') {
|
|
103
|
+
priority = 'high';
|
|
104
|
+
}
|
|
105
|
+
else if (notification.type === 'reply') {
|
|
106
|
+
priority = 'high';
|
|
107
|
+
}
|
|
108
|
+
return this.queueAction(notification.agentId, actionType, targetId ?? '', targetType, {
|
|
109
|
+
...responsePayload,
|
|
110
|
+
notificationId: notification.id,
|
|
111
|
+
notificationType: notification.type,
|
|
112
|
+
}, priority);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the next action to execute (respecting rate limits)
|
|
116
|
+
* Loops through pending actions until it finds one that can be executed
|
|
117
|
+
*/
|
|
118
|
+
async getNextExecutableAction() {
|
|
119
|
+
const db = getDatabase();
|
|
120
|
+
const rateLimiter = getRateLimiter();
|
|
121
|
+
// Try up to 50 actions to find one that's not rate limited
|
|
122
|
+
const maxAttempts = 50;
|
|
123
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
124
|
+
// Get next pending action from queue
|
|
125
|
+
const action = db.getNextAction();
|
|
126
|
+
if (!action) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
// Check if rate limit allows this action
|
|
130
|
+
if (rateLimiter.canPerform(action.agentId, action.type)) {
|
|
131
|
+
return action;
|
|
132
|
+
}
|
|
133
|
+
// Rate limited - reschedule this action and try the next one
|
|
134
|
+
const waitTime = rateLimiter.getTimeUntilAllowed(action.agentId, action.type);
|
|
135
|
+
const newExecuteAfter = new Date(Date.now() + waitTime);
|
|
136
|
+
logger.debug(`Rate limited: ${action.type} for ${action.agentId}, retry in ${waitTime}ms`);
|
|
137
|
+
db.rescheduleAction(action.id, `Rate limited, waiting ${Math.round(waitTime / 1000)}s`, newExecuteAfter);
|
|
138
|
+
// Continue to try the next action in queue
|
|
139
|
+
}
|
|
140
|
+
logger.debug('No executable actions found after checking queue');
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Execute a single action
|
|
145
|
+
*/
|
|
146
|
+
async executeAction(action) {
|
|
147
|
+
const manager = getAgentManager();
|
|
148
|
+
const apiKey = manager.getApiKey(action.agentId);
|
|
149
|
+
if (!apiKey) {
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
actionId: action.id,
|
|
153
|
+
error: 'No API key for agent',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const client = getAgent4ScienceClient();
|
|
157
|
+
const rateLimiter = getRateLimiter();
|
|
158
|
+
const db = getDatabase();
|
|
159
|
+
try {
|
|
160
|
+
// Consume rate limit token
|
|
161
|
+
if (!rateLimiter.tryConsume(action.agentId, action.type)) {
|
|
162
|
+
throw new Error('Rate limit exceeded');
|
|
163
|
+
}
|
|
164
|
+
let result;
|
|
165
|
+
switch (action.type) {
|
|
166
|
+
case 'comment':
|
|
167
|
+
result = await this.executeComment(action, apiKey, client);
|
|
168
|
+
break;
|
|
169
|
+
case 'vote':
|
|
170
|
+
result = await this.executeVote(action, apiKey, client);
|
|
171
|
+
break;
|
|
172
|
+
case 'take':
|
|
173
|
+
result = await this.executeTake(action, apiKey, client);
|
|
174
|
+
break;
|
|
175
|
+
case 'review':
|
|
176
|
+
result = await this.executeReview(action, apiKey, client);
|
|
177
|
+
break;
|
|
178
|
+
case 'follow':
|
|
179
|
+
result = await this.executeFollow(action, apiKey, client);
|
|
180
|
+
break;
|
|
181
|
+
case 'paper':
|
|
182
|
+
result = await this.executePaper(action, apiKey, client);
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
result = {
|
|
186
|
+
success: false,
|
|
187
|
+
actionId: action.id,
|
|
188
|
+
error: `Unknown action type: ${action.type}`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (result.success) {
|
|
192
|
+
db.markActionComplete(action.id);
|
|
193
|
+
manager.recordAction(action.agentId);
|
|
194
|
+
// Log audit
|
|
195
|
+
db.logAction(action.agentId, action.type, action.targetId, action.targetType, true, undefined, action.payload);
|
|
196
|
+
logger.info(`Executed ${action.type}: ${action.agentId} -> ${action.targetId}`);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
throw new Error(result.error || 'Action failed');
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
205
|
+
// Don't retry on permanent errors (resource deleted, not found, policy violations, etc.)
|
|
206
|
+
const isPermanent = /not found|you follow|your own|duplicate|self.review|self.take/i.test(errorMessage);
|
|
207
|
+
const shouldRetry = !isPermanent && action.attempts < action.maxAttempts;
|
|
208
|
+
if (shouldRetry) {
|
|
209
|
+
const delay = this.config.retryDelayMs * Math.pow(this.config.retryBackoffMultiplier, action.attempts);
|
|
210
|
+
const retryAfter = new Date(Date.now() + delay);
|
|
211
|
+
db.markActionFailed(action.id, errorMessage, retryAfter);
|
|
212
|
+
logger.warn(`Action ${action.id} failed (attempt ${action.attempts + 1}/${action.maxAttempts}): ${errorMessage}`);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
db.markActionFailed(action.id, errorMessage);
|
|
216
|
+
logger.error(`Action ${action.id} permanently failed: ${errorMessage}`);
|
|
217
|
+
// Log audit
|
|
218
|
+
db.logAction(action.agentId, action.type, action.targetId, action.targetType, false, errorMessage, action.payload);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
actionId: action.id,
|
|
223
|
+
error: errorMessage,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Execute a comment action
|
|
229
|
+
*/
|
|
230
|
+
async executeComment(action, apiKey, client) {
|
|
231
|
+
const { body, intent, parentId, evidenceAnchor, confidence } = action.payload;
|
|
232
|
+
let result;
|
|
233
|
+
if (action.targetType === 'paper') {
|
|
234
|
+
result = await client.commentOnPaper(action.targetId, { intent, body, evidenceAnchor, confidence, parentId }, apiKey);
|
|
235
|
+
}
|
|
236
|
+
else if (action.targetType === 'take') {
|
|
237
|
+
result = await client.commentOnTake(action.targetId, { intent, body, evidenceAnchor, confidence, parentId }, apiKey);
|
|
238
|
+
}
|
|
239
|
+
else if (action.targetType === 'review') {
|
|
240
|
+
// 'review' targetType: comment on a peer review
|
|
241
|
+
result = await client.commentOnReview(action.targetId, { intent, body, evidenceAnchor, confidence, parentId }, apiKey);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return {
|
|
245
|
+
success: false,
|
|
246
|
+
actionId: action.id,
|
|
247
|
+
error: `Cannot comment on ${action.targetType}`,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (!result.success) {
|
|
251
|
+
return {
|
|
252
|
+
success: false,
|
|
253
|
+
actionId: action.id,
|
|
254
|
+
error: result.error,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
success: true,
|
|
259
|
+
actionId: action.id,
|
|
260
|
+
responseId: result.data?.id,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Execute a vote action
|
|
265
|
+
*/
|
|
266
|
+
async executeVote(action, apiKey, client) {
|
|
267
|
+
const { direction } = action.payload;
|
|
268
|
+
if (action.targetType !== 'paper' && action.targetType !== 'take' && action.targetType !== 'review') {
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
actionId: action.id,
|
|
272
|
+
error: `Cannot vote on ${action.targetType}`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
let result;
|
|
276
|
+
if (action.targetType === 'paper') {
|
|
277
|
+
result = await client.votePaper(action.targetId, { direction }, apiKey);
|
|
278
|
+
}
|
|
279
|
+
else if (action.targetType === 'take') {
|
|
280
|
+
result = await client.voteTake(action.targetId, { direction }, apiKey);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
result = await client.voteReview(action.targetId, { direction }, apiKey);
|
|
284
|
+
}
|
|
285
|
+
if (!result.success) {
|
|
286
|
+
return { success: false, actionId: action.id, error: result.error };
|
|
287
|
+
}
|
|
288
|
+
return { success: true, actionId: action.id };
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Execute a take (peer review) action
|
|
292
|
+
* Supports both paper-linked takes (targetType === 'paper') and standalone takes (targetType === 'take')
|
|
293
|
+
*/
|
|
294
|
+
async executeTake(action, apiKey, client) {
|
|
295
|
+
const takeData = action.payload;
|
|
296
|
+
// Standalone takes use targetType 'take' with a synthetic targetId
|
|
297
|
+
const isStandalone = action.targetType === 'take';
|
|
298
|
+
if (action.targetType !== 'paper' && !isStandalone) {
|
|
299
|
+
return {
|
|
300
|
+
success: false,
|
|
301
|
+
actionId: action.id,
|
|
302
|
+
error: 'Takes can only be written on papers or as standalone',
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
// Validate tags before sending — server requires at least one valid tag
|
|
306
|
+
if (!takeData.tags || !Array.isArray(takeData.tags) || takeData.tags.length === 0) {
|
|
307
|
+
return {
|
|
308
|
+
success: false,
|
|
309
|
+
actionId: action.id,
|
|
310
|
+
error: 'Take has no valid tags — server requires at least one sciencesub tag',
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const result = await client.createTake({
|
|
314
|
+
// Only include paperId for paper-linked takes
|
|
315
|
+
...(isStandalone ? {} : { paperId: action.targetId }),
|
|
316
|
+
...takeData,
|
|
317
|
+
}, apiKey);
|
|
318
|
+
if (!result.success) {
|
|
319
|
+
return {
|
|
320
|
+
success: false,
|
|
321
|
+
actionId: action.id,
|
|
322
|
+
error: result.error,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
success: true,
|
|
327
|
+
actionId: action.id,
|
|
328
|
+
responseId: result.data?.id,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Execute a peer review action
|
|
333
|
+
*/
|
|
334
|
+
async executeReview(action, apiKey, client) {
|
|
335
|
+
const reviewData = action.payload;
|
|
336
|
+
const result = await client.createReview(reviewData, apiKey);
|
|
337
|
+
if (!result.success) {
|
|
338
|
+
return { success: false, actionId: action.id, error: result.error };
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
success: true,
|
|
342
|
+
actionId: action.id,
|
|
343
|
+
responseId: result.data?.id,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Execute a follow action
|
|
348
|
+
*/
|
|
349
|
+
async executeFollow(action, apiKey, client) {
|
|
350
|
+
if (action.targetType !== 'agent') {
|
|
351
|
+
return {
|
|
352
|
+
success: false,
|
|
353
|
+
actionId: action.id,
|
|
354
|
+
error: 'Follow only works on agents',
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
const result = await client.followAgent(action.targetId, apiKey);
|
|
358
|
+
if (!result.success) {
|
|
359
|
+
return {
|
|
360
|
+
success: false,
|
|
361
|
+
actionId: action.id,
|
|
362
|
+
error: result.error,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
success: true,
|
|
367
|
+
actionId: action.id,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Execute a paper creation action
|
|
372
|
+
*/
|
|
373
|
+
async executePaper(action, apiKey, client) {
|
|
374
|
+
const paperData = action.payload;
|
|
375
|
+
// Validate required URLs before attempting paper creation
|
|
376
|
+
const githubUrl = paperData.githubUrl;
|
|
377
|
+
const pdfUrl = paperData.pdfUrl;
|
|
378
|
+
if (!githubUrl || !githubUrl.startsWith('https://')) {
|
|
379
|
+
return {
|
|
380
|
+
success: false,
|
|
381
|
+
actionId: action.id,
|
|
382
|
+
error: `Cannot create paper without valid githubUrl (got: ${githubUrl || 'empty'})`,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (!pdfUrl || !pdfUrl.startsWith('https://')) {
|
|
386
|
+
return {
|
|
387
|
+
success: false,
|
|
388
|
+
actionId: action.id,
|
|
389
|
+
error: `Cannot create paper without valid pdfUrl (got: ${pdfUrl || 'empty'})`,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const paperPayload = {
|
|
393
|
+
title: paperData.title,
|
|
394
|
+
abstract: paperData.abstract,
|
|
395
|
+
tldr: paperData.tldr || paperData.title,
|
|
396
|
+
hypothesis: paperData.hypothesis ?? paperData.claims?.[0] ?? 'This work investigates a novel approach',
|
|
397
|
+
experimentPlan: paperData.experimentPlan,
|
|
398
|
+
conclusion: paperData.conclusion ?? 'Results demonstrate the validity of the proposed approach',
|
|
399
|
+
tags: paperData.tags,
|
|
400
|
+
claims: paperData.claims,
|
|
401
|
+
githubUrl,
|
|
402
|
+
pdfUrl,
|
|
403
|
+
limitations: paperData.limitations,
|
|
404
|
+
inspirations: paperData.inspirations,
|
|
405
|
+
};
|
|
406
|
+
const result = await client.createPaper(paperPayload, apiKey);
|
|
407
|
+
if (!result.success) {
|
|
408
|
+
return {
|
|
409
|
+
success: false,
|
|
410
|
+
actionId: action.id,
|
|
411
|
+
error: result.error,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
logger.info(`Created paper: ${result.data?.id} - ${paperData.title}`);
|
|
415
|
+
return {
|
|
416
|
+
success: true,
|
|
417
|
+
actionId: action.id,
|
|
418
|
+
responseId: result.data?.id,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Process all pending actions
|
|
423
|
+
*/
|
|
424
|
+
async processQueue() {
|
|
425
|
+
let processed = 0;
|
|
426
|
+
while (true) {
|
|
427
|
+
const action = await this.getNextExecutableAction();
|
|
428
|
+
if (!action) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
await this.executeAction(action);
|
|
432
|
+
processed++;
|
|
433
|
+
// Small delay between actions to be nice to the API
|
|
434
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
435
|
+
}
|
|
436
|
+
return processed;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Get queue statistics
|
|
440
|
+
*/
|
|
441
|
+
getQueueStats() {
|
|
442
|
+
const db = getDatabase();
|
|
443
|
+
return db.getQueueStats();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// Singleton
|
|
447
|
+
let instance = null;
|
|
448
|
+
export function createActionExecutor(config) {
|
|
449
|
+
instance = new ActionExecutor(config);
|
|
450
|
+
return instance;
|
|
451
|
+
}
|
|
452
|
+
export function getActionExecutor() {
|
|
453
|
+
if (!instance) {
|
|
454
|
+
instance = new ActionExecutor();
|
|
455
|
+
}
|
|
456
|
+
return instance;
|
|
457
|
+
}
|
|
458
|
+
//# sourceMappingURL=action-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-executor.js","sourceRoot":"","sources":["../../src/actions/action-executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;AAQxC,MAAM,CAAC,MAAM,uBAAuB,GAAyB;I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,GAAG,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;YACpD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM;YACR,CAAC;YAED,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACjC,SAAS,EAAE,CAAC;YAEZ,oDAAoD;YACpD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;CACF;AAED,YAAY;AACZ,IAAI,QAAQ,GAA0B,IAAI,CAAC;AAE3C,MAAM,UAAU,oBAAoB,CAAC,MAA6B;IAChE,QAAQ,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Manager
|
|
3
|
+
* Manages the lifecycle of multiple AI agents in the runtime
|
|
4
|
+
*/
|
|
5
|
+
import type { AgentCapability, AgentConfig, AgentRuntime, AgentState } from '../types.js';
|
|
6
|
+
export declare function encryptApiKey(apiKey: string, encryptionKey: string): string;
|
|
7
|
+
export declare class AgentManager {
|
|
8
|
+
private agents;
|
|
9
|
+
private encryptionKey;
|
|
10
|
+
private apiKeys;
|
|
11
|
+
constructor(encryptionKey: string);
|
|
12
|
+
/**
|
|
13
|
+
* Load all enabled agents from database
|
|
14
|
+
*/
|
|
15
|
+
loadAgents(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Add a new agent to the runtime
|
|
18
|
+
*/
|
|
19
|
+
addAgent(apiKey: string, options?: {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
capability?: AgentCapability;
|
|
22
|
+
researchDomain?: string;
|
|
23
|
+
}): Promise<AgentConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Remove an agent from the runtime
|
|
26
|
+
*/
|
|
27
|
+
removeAgent(agentId: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Enable/disable an agent
|
|
30
|
+
*/
|
|
31
|
+
setAgentEnabled(agentId: string, enabled: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get all agents
|
|
34
|
+
*/
|
|
35
|
+
getAgents(): AgentRuntime[];
|
|
36
|
+
/**
|
|
37
|
+
* Get enabled agents only
|
|
38
|
+
*/
|
|
39
|
+
getEnabledAgents(): AgentRuntime[];
|
|
40
|
+
/**
|
|
41
|
+
* Get an agent by ID
|
|
42
|
+
*/
|
|
43
|
+
getAgent(agentId: string): AgentRuntime | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Alias for getAgent (for compatibility)
|
|
46
|
+
*/
|
|
47
|
+
getRuntime(agentId: string): AgentRuntime | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Get all agent IDs
|
|
50
|
+
*/
|
|
51
|
+
getAgentIds(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Get an agent's API key
|
|
54
|
+
*/
|
|
55
|
+
getApiKey(agentId: string): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Update agent state
|
|
58
|
+
*/
|
|
59
|
+
updateState(agentId: string, state: AgentState, error?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Record that agent polled for notifications
|
|
62
|
+
*/
|
|
63
|
+
recordPoll(agentId: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Record that agent took an action
|
|
66
|
+
*/
|
|
67
|
+
recordAction(agentId: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get status summary for all agents
|
|
70
|
+
*/
|
|
71
|
+
getStatus(): {
|
|
72
|
+
total: number;
|
|
73
|
+
enabled: number;
|
|
74
|
+
idle: number;
|
|
75
|
+
active: number;
|
|
76
|
+
errored: number;
|
|
77
|
+
agents: Array<{
|
|
78
|
+
id: string;
|
|
79
|
+
handle: string;
|
|
80
|
+
state: AgentState;
|
|
81
|
+
enabled: boolean;
|
|
82
|
+
errorCount: number;
|
|
83
|
+
lastPollTime: Date | null;
|
|
84
|
+
lastActionTime: Date | null;
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export declare function createAgentManager(encryptionKey: string): AgentManager;
|
|
89
|
+
export declare function getAgentManager(): AgentManager;
|
|
90
|
+
//# sourceMappingURL=agent-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-manager.d.ts","sourceRoot":"","sources":["../../src/agents/agent-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,YAAY,EACZ,UAAU,EAEX,MAAM,aAAa,CAAC;AAUrB,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAU3E;AAcD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAwC;IACtD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAkC;gBAErC,aAAa,EAAE,MAAM;IAIjC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA2CjC;;OAEG;IACG,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,eAAe,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GACrF,OAAO,CAAC,WAAW,CAAC;IAsDvB;;OAEG;IACH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