@moltium/core 0.1.18 → 0.1.19
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.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +263 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +262 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -216,12 +216,221 @@ var scheduleTaskAction = {
|
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
+
// src/actions/built-in/moltbook.ts
|
|
220
|
+
function getMoltbook(context) {
|
|
221
|
+
return context.agent?.socialAdapters?.["moltbook"] || null;
|
|
222
|
+
}
|
|
223
|
+
var checkFeedAction = {
|
|
224
|
+
name: "check_feed",
|
|
225
|
+
description: "Browse the moltbook feed (personalized or global) to find posts to engage with",
|
|
226
|
+
async execute(context) {
|
|
227
|
+
const mb = getMoltbook(context);
|
|
228
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
229
|
+
const { sort, limit, global: useGlobal } = context.parameters;
|
|
230
|
+
try {
|
|
231
|
+
const posts = useGlobal ? await mb.getGlobalFeed({ sort: sort || "hot", limit: limit || 15 }) : await mb.getFeed({ sort: sort || "new", limit: limit || 15 });
|
|
232
|
+
return { success: true, data: { posts, count: posts.length } };
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return { success: false, error: error.message };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var checkDMsAction = {
|
|
239
|
+
name: "check_dms",
|
|
240
|
+
description: "Check for new DM requests and unread messages from other agents",
|
|
241
|
+
async execute(context) {
|
|
242
|
+
const mb = getMoltbook(context);
|
|
243
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
244
|
+
try {
|
|
245
|
+
const result = await mb.checkDMs();
|
|
246
|
+
return { success: true, data: result };
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return { success: false, error: error.message };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var searchMoltbookAction = {
|
|
253
|
+
name: "search_moltbook",
|
|
254
|
+
description: 'Search moltbook for posts and comments by meaning (semantic search). Params: { "query": "..." }',
|
|
255
|
+
async execute(context) {
|
|
256
|
+
const mb = getMoltbook(context);
|
|
257
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
258
|
+
const { query, limit } = context.parameters;
|
|
259
|
+
if (!query) return { success: false, error: "Missing required parameter: query" };
|
|
260
|
+
try {
|
|
261
|
+
const results = await mb.search(query, { limit: limit || 10 });
|
|
262
|
+
return { success: true, data: { results, count: results.length } };
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return { success: false, error: error.message };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var commentOnPostAction = {
|
|
269
|
+
name: "comment_on_post",
|
|
270
|
+
description: 'Reply to a post with a comment. Params: { "post_id": "...", "content": "..." }',
|
|
271
|
+
async execute(context) {
|
|
272
|
+
const mb = getMoltbook(context);
|
|
273
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
274
|
+
const { post_id, content } = context.parameters;
|
|
275
|
+
if (!post_id || !content) return { success: false, error: "Missing required parameters: post_id, content" };
|
|
276
|
+
try {
|
|
277
|
+
const result = await mb.reply(post_id, content);
|
|
278
|
+
return { success: true, data: result };
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return { success: false, error: error.message };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
var upvotePostAction = {
|
|
285
|
+
name: "upvote_post",
|
|
286
|
+
description: 'Upvote a post you find valuable. Params: { "post_id": "..." }',
|
|
287
|
+
async execute(context) {
|
|
288
|
+
const mb = getMoltbook(context);
|
|
289
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
290
|
+
const { post_id } = context.parameters;
|
|
291
|
+
if (!post_id) return { success: false, error: "Missing required parameter: post_id" };
|
|
292
|
+
try {
|
|
293
|
+
await mb.like(post_id);
|
|
294
|
+
return { success: true, data: { post_id, action: "upvoted" } };
|
|
295
|
+
} catch (error) {
|
|
296
|
+
return { success: false, error: error.message };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
var downvotePostAction = {
|
|
301
|
+
name: "downvote_post",
|
|
302
|
+
description: 'Downvote a post you disagree with. Params: { "post_id": "..." }',
|
|
303
|
+
async execute(context) {
|
|
304
|
+
const mb = getMoltbook(context);
|
|
305
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
306
|
+
const { post_id } = context.parameters;
|
|
307
|
+
if (!post_id) return { success: false, error: "Missing required parameter: post_id" };
|
|
308
|
+
try {
|
|
309
|
+
await mb.downvote(post_id);
|
|
310
|
+
return { success: true, data: { post_id, action: "downvoted" } };
|
|
311
|
+
} catch (error) {
|
|
312
|
+
return { success: false, error: error.message };
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var browseSubmoltsAction = {
|
|
317
|
+
name: "browse_submolts",
|
|
318
|
+
description: "Discover moltbook communities (submolts) to subscribe to",
|
|
319
|
+
async execute(context) {
|
|
320
|
+
const mb = getMoltbook(context);
|
|
321
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
322
|
+
try {
|
|
323
|
+
const submolts = await mb.listSubmolts();
|
|
324
|
+
return { success: true, data: { submolts, count: submolts.length } };
|
|
325
|
+
} catch (error) {
|
|
326
|
+
return { success: false, error: error.message };
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var followAgentAction = {
|
|
331
|
+
name: "follow_agent",
|
|
332
|
+
description: 'Follow another agent whose posts you enjoy. Params: { "agent_name": "..." }',
|
|
333
|
+
async execute(context) {
|
|
334
|
+
const mb = getMoltbook(context);
|
|
335
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
336
|
+
const { agent_name } = context.parameters;
|
|
337
|
+
if (!agent_name) return { success: false, error: "Missing required parameter: agent_name" };
|
|
338
|
+
try {
|
|
339
|
+
await mb.follow(agent_name);
|
|
340
|
+
return { success: true, data: { agent_name, action: "followed" } };
|
|
341
|
+
} catch (error) {
|
|
342
|
+
return { success: false, error: error.message };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var sendDMRequestAction = {
|
|
347
|
+
name: "send_dm_request",
|
|
348
|
+
description: 'Request to start a private conversation with another agent. Params: { "to": "...", "message": "..." }',
|
|
349
|
+
async execute(context) {
|
|
350
|
+
const mb = getMoltbook(context);
|
|
351
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
352
|
+
const { to, to_owner, message } = context.parameters;
|
|
353
|
+
if (!to && !to_owner || !message) return { success: false, error: "Missing required parameters: (to or to_owner), message" };
|
|
354
|
+
try {
|
|
355
|
+
const target = to || to_owner || "";
|
|
356
|
+
const byOwner = !to && !!to_owner;
|
|
357
|
+
const result = await mb.sendDMRequest(target, message, byOwner);
|
|
358
|
+
return { success: true, data: result };
|
|
359
|
+
} catch (error) {
|
|
360
|
+
return { success: false, error: error.message };
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
var sendDMAction = {
|
|
365
|
+
name: "send_dm",
|
|
366
|
+
description: 'Send a message in an existing DM conversation. Params: { "conversation_id": "...", "message": "..." }',
|
|
367
|
+
async execute(context) {
|
|
368
|
+
const mb = getMoltbook(context);
|
|
369
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
370
|
+
const { conversation_id, message, needs_human_input } = context.parameters;
|
|
371
|
+
if (!conversation_id || !message) return { success: false, error: "Missing required parameters: conversation_id, message" };
|
|
372
|
+
try {
|
|
373
|
+
const result = await mb.sendDM(conversation_id, message, needs_human_input);
|
|
374
|
+
return { success: true, data: result };
|
|
375
|
+
} catch (error) {
|
|
376
|
+
return { success: false, error: error.message };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
var approveDMRequestAction = {
|
|
381
|
+
name: "approve_dm_request",
|
|
382
|
+
description: 'Approve a pending DM request from another agent. Params: { "conversation_id": "..." }',
|
|
383
|
+
async execute(context) {
|
|
384
|
+
const mb = getMoltbook(context);
|
|
385
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
386
|
+
const { conversation_id } = context.parameters;
|
|
387
|
+
if (!conversation_id) return { success: false, error: "Missing required parameter: conversation_id" };
|
|
388
|
+
try {
|
|
389
|
+
await mb.approveDMRequest(conversation_id);
|
|
390
|
+
return { success: true, data: { conversation_id, action: "approved" } };
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return { success: false, error: error.message };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
var readConversationAction = {
|
|
397
|
+
name: "read_conversation",
|
|
398
|
+
description: 'Read messages in a DM conversation (marks as read). Params: { "conversation_id": "..." }',
|
|
399
|
+
async execute(context) {
|
|
400
|
+
const mb = getMoltbook(context);
|
|
401
|
+
if (!mb) return { success: false, error: "Moltbook not connected" };
|
|
402
|
+
const { conversation_id } = context.parameters;
|
|
403
|
+
if (!conversation_id) return { success: false, error: "Missing required parameter: conversation_id" };
|
|
404
|
+
try {
|
|
405
|
+
const detail = await mb.readConversation(conversation_id);
|
|
406
|
+
return { success: true, data: detail };
|
|
407
|
+
} catch (error) {
|
|
408
|
+
return { success: false, error: error.message };
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var moltbookActions = [
|
|
413
|
+
checkFeedAction,
|
|
414
|
+
checkDMsAction,
|
|
415
|
+
searchMoltbookAction,
|
|
416
|
+
commentOnPostAction,
|
|
417
|
+
upvotePostAction,
|
|
418
|
+
downvotePostAction,
|
|
419
|
+
browseSubmoltsAction,
|
|
420
|
+
followAgentAction,
|
|
421
|
+
sendDMRequestAction,
|
|
422
|
+
sendDMAction,
|
|
423
|
+
approveDMRequestAction,
|
|
424
|
+
readConversationAction
|
|
425
|
+
];
|
|
426
|
+
|
|
219
427
|
// src/actions/built-in/index.ts
|
|
220
428
|
var builtInActions = [
|
|
221
429
|
postSocialUpdateAction,
|
|
222
430
|
respondToMentionAction,
|
|
223
431
|
dmUserAction,
|
|
224
|
-
scheduleTaskAction
|
|
432
|
+
scheduleTaskAction,
|
|
433
|
+
...moltbookActions
|
|
225
434
|
];
|
|
226
435
|
|
|
227
436
|
// src/llm/prompt.ts
|
|
@@ -248,18 +457,33 @@ ${config.llm.systemPrompt}`);
|
|
|
248
457
|
}
|
|
249
458
|
function buildDecisionPrompt(context, availableActions) {
|
|
250
459
|
const actionList = availableActions.map((a) => `- ${a.name}: ${a.description}`).join("\n");
|
|
251
|
-
|
|
460
|
+
const recent = context.recentActions || [];
|
|
461
|
+
const recentNames = recent.map((r) => r.action);
|
|
462
|
+
const lastAction = recentNames.length > 0 ? recentNames[recentNames.length - 1] : "none";
|
|
463
|
+
let varietyHint = "";
|
|
464
|
+
if (recentNames.length > 0) {
|
|
465
|
+
varietyHint = `
|
|
466
|
+
Your recent actions (most recent last): ${recentNames.join(" \u2192 ")}
|
|
467
|
+
IMPORTANT: Do NOT repeat "${lastAction}" again. Choose a DIFFERENT action to keep your behavior varied and interesting.
|
|
468
|
+
Vary between: posting content, checking your feed, replying to others, checking DMs, browsing communities, searching for topics, and following interesting agents.`;
|
|
469
|
+
}
|
|
470
|
+
return `You are an autonomous AI agent on moltbook (a social network for AI agents).
|
|
471
|
+
Decide what action to take next based on the current context and your personality.
|
|
252
472
|
|
|
253
473
|
Available actions:
|
|
254
474
|
${actionList}
|
|
255
475
|
|
|
256
476
|
Current context:
|
|
257
477
|
${JSON.stringify(context, null, 2)}
|
|
478
|
+
${varietyHint}
|
|
479
|
+
|
|
480
|
+
Think about what would be most natural and valuable right now.
|
|
481
|
+
If the action generates content (post, comment, DM), include the actual content in parameters.
|
|
258
482
|
|
|
259
483
|
Respond with a JSON object:
|
|
260
484
|
{
|
|
261
485
|
"action": "<action_name>",
|
|
262
|
-
"reasoning": "<brief explanation>",
|
|
486
|
+
"reasoning": "<brief explanation of why you chose this>",
|
|
263
487
|
"parameters": { <any parameters for the action> }
|
|
264
488
|
}`;
|
|
265
489
|
}
|
|
@@ -1135,6 +1359,8 @@ var Agent = class {
|
|
|
1135
1359
|
tickTimer;
|
|
1136
1360
|
systemPrompt;
|
|
1137
1361
|
socialAdapters = {};
|
|
1362
|
+
recentActions = [];
|
|
1363
|
+
tickCount = 0;
|
|
1138
1364
|
constructor(config, hooks) {
|
|
1139
1365
|
this.config = config;
|
|
1140
1366
|
this.hooks = hooks || {};
|
|
@@ -1269,13 +1495,29 @@ var Agent = class {
|
|
|
1269
1495
|
}
|
|
1270
1496
|
async tick() {
|
|
1271
1497
|
if (this.state !== "running") return;
|
|
1498
|
+
this.tickCount++;
|
|
1272
1499
|
try {
|
|
1273
1500
|
if (this.hooks.onTick) {
|
|
1274
1501
|
await this.hooks.onTick(this);
|
|
1275
1502
|
}
|
|
1276
|
-
if (this.isSleeping())
|
|
1503
|
+
if (this.isSleeping()) {
|
|
1504
|
+
logger4.info(`Tick #${this.tickCount}: Sleeping \u2014 skipped`);
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
logger4.info(`Tick #${this.tickCount}: Thinking...`);
|
|
1277
1508
|
const decision = await this.think();
|
|
1509
|
+
logger4.info(`Tick #${this.tickCount}: Decision \u2192 ${decision.action} | Reasoning: ${decision.reasoning}`);
|
|
1510
|
+
if (decision.parameters && Object.keys(decision.parameters).length > 0) {
|
|
1511
|
+
logger4.info(`Tick #${this.tickCount}: Parameters \u2192 ${JSON.stringify(decision.parameters)}`);
|
|
1512
|
+
}
|
|
1278
1513
|
const result = await this.act(decision.action, decision.parameters);
|
|
1514
|
+
logger4.info(`Tick #${this.tickCount}: Result \u2192 success=${result.success}${result.data ? ` data=${JSON.stringify(result.data).slice(0, 200)}` : ""}`);
|
|
1515
|
+
this.recentActions.push({
|
|
1516
|
+
action: decision.action,
|
|
1517
|
+
reasoning: decision.reasoning,
|
|
1518
|
+
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
1519
|
+
});
|
|
1520
|
+
if (this.recentActions.length > 10) this.recentActions.shift();
|
|
1279
1521
|
await this.learn({
|
|
1280
1522
|
type: "action",
|
|
1281
1523
|
action: decision.action,
|
|
@@ -1287,7 +1529,7 @@ var Agent = class {
|
|
|
1287
1529
|
await this.fireWebhook("onAction", decision, result);
|
|
1288
1530
|
}
|
|
1289
1531
|
} catch (error) {
|
|
1290
|
-
logger4.error(`Tick error: ${error instanceof Error ? error.message : error}`);
|
|
1532
|
+
logger4.error(`Tick #${this.tickCount} error: ${error instanceof Error ? error.message : error}`);
|
|
1291
1533
|
if (this.hooks.onError && error instanceof Error) {
|
|
1292
1534
|
await this.hooks.onError(error, this);
|
|
1293
1535
|
}
|
|
@@ -1320,6 +1562,15 @@ var Agent = class {
|
|
|
1320
1562
|
this.actionRegistry.register(action);
|
|
1321
1563
|
}
|
|
1322
1564
|
}
|
|
1565
|
+
const mb = this.config.social.moltbook;
|
|
1566
|
+
if (mb && mb.enabled !== false) {
|
|
1567
|
+
for (const action of moltbookActions) {
|
|
1568
|
+
if (!this.actionRegistry.has(action.name)) {
|
|
1569
|
+
this.actionRegistry.register(action);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
logger4.info(`Registered ${moltbookActions.length} Moltbook actions`);
|
|
1573
|
+
}
|
|
1323
1574
|
if (this.config.customActions) {
|
|
1324
1575
|
for (const action of this.config.customActions) {
|
|
1325
1576
|
this.actionRegistry.register(action);
|
|
@@ -1628,7 +1879,11 @@ Decide what action to take. Respond with JSON:
|
|
|
1628
1879
|
agentType: this.config.type,
|
|
1629
1880
|
currentTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1630
1881
|
state: this.state,
|
|
1631
|
-
|
|
1882
|
+
tickNumber: this.tickCount,
|
|
1883
|
+
personality: this.config.personality.traits,
|
|
1884
|
+
connectedPlatforms: Object.keys(this.socialAdapters),
|
|
1885
|
+
recentActions: this.recentActions.slice(-5),
|
|
1886
|
+
scheduledTasks: (this.config.scheduling || []).map((t) => t.name)
|
|
1632
1887
|
};
|
|
1633
1888
|
}
|
|
1634
1889
|
async fireWebhook(event, ...args) {
|
|
@@ -2356,6 +2611,7 @@ export {
|
|
|
2356
2611
|
createLogger,
|
|
2357
2612
|
createMarkdownAction,
|
|
2358
2613
|
createRoutes,
|
|
2614
|
+
moltbookActions,
|
|
2359
2615
|
startServer,
|
|
2360
2616
|
validateConfig
|
|
2361
2617
|
};
|