@elizaos/plugin-bootstrap 1.6.2-alpha.9 → 1.6.2-beta.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/dist/index.js +32 -638
- package/dist/index.js.map +4 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -80,7 +80,6 @@ Length provided: ${this.length}. Number of dictionaries provided: ${this.diction
|
|
|
80
80
|
|
|
81
81
|
// src/index.ts
|
|
82
82
|
import {
|
|
83
|
-
asUUID as asUUID2,
|
|
84
83
|
ChannelType as ChannelType9,
|
|
85
84
|
composePromptFromState as composePromptFromState10,
|
|
86
85
|
ContentType as ContentType2,
|
|
@@ -92,13 +91,8 @@ import {
|
|
|
92
91
|
ModelType as ModelType15,
|
|
93
92
|
parseKeyValueXml as parseKeyValueXml9,
|
|
94
93
|
postCreationTemplate,
|
|
95
|
-
parseBooleanFromText as parseBooleanFromText2,
|
|
96
94
|
Role as Role2,
|
|
97
|
-
|
|
98
|
-
truncateToCompleteSentence,
|
|
99
|
-
getLocalServerUrl,
|
|
100
|
-
multiStepDecisionTemplate,
|
|
101
|
-
multiStepSummaryTemplate
|
|
95
|
+
getLocalServerUrl
|
|
102
96
|
} from "@elizaos/core";
|
|
103
97
|
|
|
104
98
|
// ../../node_modules/uuid/dist-node/stringify.js
|
|
@@ -6930,18 +6924,34 @@ class EmbeddingGenerationService extends Service2 {
|
|
|
6930
6924
|
maxQueueSize = 1000;
|
|
6931
6925
|
batchSize = 10;
|
|
6932
6926
|
processingIntervalMs = 100;
|
|
6927
|
+
isDisabled = false;
|
|
6933
6928
|
static async start(runtime) {
|
|
6934
6929
|
logger21.info("[EmbeddingService] Starting embedding generation service");
|
|
6930
|
+
const embeddingModel = runtime.getModel(ModelType14.TEXT_EMBEDDING);
|
|
6931
|
+
if (!embeddingModel) {
|
|
6932
|
+
logger21.warn("[EmbeddingService] No TEXT_EMBEDDING model registered. Embedding service will not be initialized.");
|
|
6933
|
+
const noOpService = new EmbeddingGenerationService(runtime);
|
|
6934
|
+
noOpService.isDisabled = true;
|
|
6935
|
+
return noOpService;
|
|
6936
|
+
}
|
|
6935
6937
|
const service = new EmbeddingGenerationService(runtime);
|
|
6936
6938
|
await service.initialize();
|
|
6937
6939
|
return service;
|
|
6938
6940
|
}
|
|
6939
6941
|
async initialize() {
|
|
6942
|
+
if (this.isDisabled) {
|
|
6943
|
+
logger21.debug("[EmbeddingService] Service is disabled, skipping initialization");
|
|
6944
|
+
return;
|
|
6945
|
+
}
|
|
6940
6946
|
logger21.info("[EmbeddingService] Initializing embedding generation service");
|
|
6941
6947
|
this.runtime.registerEvent(EventType.EMBEDDING_GENERATION_REQUESTED, this.handleEmbeddingRequest.bind(this));
|
|
6942
6948
|
this.startProcessing();
|
|
6943
6949
|
}
|
|
6944
6950
|
async handleEmbeddingRequest(payload) {
|
|
6951
|
+
if (this.isDisabled) {
|
|
6952
|
+
logger21.debug("[EmbeddingService] Service is disabled, skipping embedding request");
|
|
6953
|
+
return;
|
|
6954
|
+
}
|
|
6945
6955
|
const { memory, priority = "normal", retryCount = 0, maxRetries = 3, runId } = payload;
|
|
6946
6956
|
if (memory.embedding) {
|
|
6947
6957
|
logger21.debug("[EmbeddingService] Memory already has embeddings, skipping");
|
|
@@ -7010,6 +7020,10 @@ class EmbeddingGenerationService extends Service2 {
|
|
|
7010
7020
|
}
|
|
7011
7021
|
}
|
|
7012
7022
|
startProcessing() {
|
|
7023
|
+
if (this.isDisabled) {
|
|
7024
|
+
logger21.debug("[EmbeddingService] Service is disabled, not starting processing loop");
|
|
7025
|
+
return;
|
|
7026
|
+
}
|
|
7013
7027
|
if (this.processingInterval) {
|
|
7014
7028
|
return;
|
|
7015
7029
|
}
|
|
@@ -7107,6 +7121,10 @@ class EmbeddingGenerationService extends Service2 {
|
|
|
7107
7121
|
}
|
|
7108
7122
|
async stop() {
|
|
7109
7123
|
logger21.info("[EmbeddingService] Stopping embedding generation service");
|
|
7124
|
+
if (this.isDisabled) {
|
|
7125
|
+
logger21.debug("[EmbeddingService] Service is disabled, nothing to stop");
|
|
7126
|
+
return;
|
|
7127
|
+
}
|
|
7110
7128
|
if (this.processingInterval) {
|
|
7111
7129
|
clearInterval(this.processingInterval);
|
|
7112
7130
|
this.processingInterval = null;
|
|
@@ -7147,7 +7165,6 @@ class EmbeddingGenerationService extends Service2 {
|
|
|
7147
7165
|
}
|
|
7148
7166
|
|
|
7149
7167
|
// src/index.ts
|
|
7150
|
-
var latestResponseIds = new Map;
|
|
7151
7168
|
async function fetchMediaData(attachments) {
|
|
7152
7169
|
return Promise.all(attachments.map(async (attachment) => {
|
|
7153
7170
|
if (/^(http|https):\/\//.test(attachment.url)) {
|
|
@@ -7253,7 +7270,7 @@ function shouldRespond(runtime, message, room, mentionContext) {
|
|
|
7253
7270
|
function normalizeEnvList(value) {
|
|
7254
7271
|
if (!value || typeof value !== "string")
|
|
7255
7272
|
return [];
|
|
7256
|
-
const cleaned = value.trim().replace(
|
|
7273
|
+
const cleaned = value.trim().replace(/^[\[]|[\]]$/g, "");
|
|
7257
7274
|
return cleaned.split(",").map((v) => v.trim()).filter(Boolean);
|
|
7258
7275
|
}
|
|
7259
7276
|
const alwaysRespondChannels = [
|
|
@@ -7273,7 +7290,11 @@ function shouldRespond(runtime, message, room, mentionContext) {
|
|
|
7273
7290
|
return { shouldRespond: true, skipEvaluation: true, reason: `private channel: ${roomType}` };
|
|
7274
7291
|
}
|
|
7275
7292
|
if (respondSources.some((pattern) => sourceStr.includes(pattern))) {
|
|
7276
|
-
return {
|
|
7293
|
+
return {
|
|
7294
|
+
shouldRespond: true,
|
|
7295
|
+
skipEvaluation: true,
|
|
7296
|
+
reason: `whitelisted source: ${sourceStr}`
|
|
7297
|
+
};
|
|
7277
7298
|
}
|
|
7278
7299
|
const hasPlatformMention = !!(mentionContext?.isMention || mentionContext?.isReply);
|
|
7279
7300
|
if (hasPlatformMention) {
|
|
@@ -7282,556 +7303,6 @@ function shouldRespond(runtime, message, room, mentionContext) {
|
|
|
7282
7303
|
}
|
|
7283
7304
|
return { shouldRespond: false, skipEvaluation: false, reason: "needs LLM evaluation" };
|
|
7284
7305
|
}
|
|
7285
|
-
var messageReceivedHandler = async ({
|
|
7286
|
-
runtime,
|
|
7287
|
-
message,
|
|
7288
|
-
callback,
|
|
7289
|
-
onComplete
|
|
7290
|
-
}) => {
|
|
7291
|
-
const useMultiStep = runtime.getSetting("USE_MULTI_STEP");
|
|
7292
|
-
const timeoutDuration = 60 * 60 * 1000;
|
|
7293
|
-
let timeoutId = undefined;
|
|
7294
|
-
try {
|
|
7295
|
-
runtime.logger.info(`[Bootstrap] Message received from ${message.entityId} in room ${message.roomId}`);
|
|
7296
|
-
const responseId = v4_default();
|
|
7297
|
-
if (!latestResponseIds.has(runtime.agentId)) {
|
|
7298
|
-
latestResponseIds.set(runtime.agentId, new Map);
|
|
7299
|
-
}
|
|
7300
|
-
const agentResponses = latestResponseIds.get(runtime.agentId);
|
|
7301
|
-
if (!agentResponses)
|
|
7302
|
-
throw new Error("Agent responses map not found");
|
|
7303
|
-
const previousResponseId = agentResponses.get(message.roomId);
|
|
7304
|
-
if (previousResponseId) {
|
|
7305
|
-
logger22.warn(`[Bootstrap] Updating response ID for room ${message.roomId} from ${previousResponseId} to ${responseId} - this may discard in-progress responses`);
|
|
7306
|
-
}
|
|
7307
|
-
agentResponses.set(message.roomId, responseId);
|
|
7308
|
-
const runId = runtime.startRun();
|
|
7309
|
-
const startTime = Date.now();
|
|
7310
|
-
await runtime.emitEvent(EventType2.RUN_STARTED, {
|
|
7311
|
-
runtime,
|
|
7312
|
-
runId,
|
|
7313
|
-
messageId: message.id,
|
|
7314
|
-
roomId: message.roomId,
|
|
7315
|
-
entityId: message.entityId,
|
|
7316
|
-
startTime,
|
|
7317
|
-
status: "started",
|
|
7318
|
-
source: "messageHandler",
|
|
7319
|
-
metadata: message.content
|
|
7320
|
-
});
|
|
7321
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
7322
|
-
timeoutId = setTimeout(async () => {
|
|
7323
|
-
await runtime.emitEvent(EventType2.RUN_TIMEOUT, {
|
|
7324
|
-
runtime,
|
|
7325
|
-
runId,
|
|
7326
|
-
messageId: message.id,
|
|
7327
|
-
roomId: message.roomId,
|
|
7328
|
-
entityId: message.entityId,
|
|
7329
|
-
startTime,
|
|
7330
|
-
status: "timeout",
|
|
7331
|
-
endTime: Date.now(),
|
|
7332
|
-
duration: Date.now() - startTime,
|
|
7333
|
-
error: "Run exceeded 60 minute timeout",
|
|
7334
|
-
source: "messageHandler"
|
|
7335
|
-
});
|
|
7336
|
-
reject(new Error("Run exceeded 60 minute timeout"));
|
|
7337
|
-
}, timeoutDuration);
|
|
7338
|
-
});
|
|
7339
|
-
const processingPromise = (async () => {
|
|
7340
|
-
try {
|
|
7341
|
-
if (message.entityId === runtime.agentId) {
|
|
7342
|
-
runtime.logger.debug(`[Bootstrap] Skipping message from self (${runtime.agentId})`);
|
|
7343
|
-
throw new Error("Message is from the agent itself");
|
|
7344
|
-
}
|
|
7345
|
-
runtime.logger.debug(`[Bootstrap] Processing message: ${truncateToCompleteSentence(message.content.text || "", 50)}...`);
|
|
7346
|
-
runtime.logger.debug("[Bootstrap] Saving message to memory and queueing embeddings");
|
|
7347
|
-
let memoryToQueue;
|
|
7348
|
-
if (message.id) {
|
|
7349
|
-
const existingMemory = await runtime.getMemoryById(message.id);
|
|
7350
|
-
if (existingMemory) {
|
|
7351
|
-
runtime.logger.debug("[Bootstrap] Memory already exists, skipping creation");
|
|
7352
|
-
memoryToQueue = existingMemory;
|
|
7353
|
-
} else {
|
|
7354
|
-
const createdMemoryId = await runtime.createMemory(message, "messages");
|
|
7355
|
-
memoryToQueue = { ...message, id: createdMemoryId };
|
|
7356
|
-
}
|
|
7357
|
-
await runtime.queueEmbeddingGeneration(memoryToQueue, "high");
|
|
7358
|
-
} else {
|
|
7359
|
-
const memoryId = await runtime.createMemory(message, "messages");
|
|
7360
|
-
message.id = memoryId;
|
|
7361
|
-
memoryToQueue = { ...message, id: memoryId };
|
|
7362
|
-
await runtime.queueEmbeddingGeneration(memoryToQueue, "normal");
|
|
7363
|
-
}
|
|
7364
|
-
const agentUserState = await runtime.getParticipantUserState(message.roomId, runtime.agentId);
|
|
7365
|
-
const defLllmOff = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_DEFLLMOFF"));
|
|
7366
|
-
if (defLllmOff && agentUserState === null) {
|
|
7367
|
-
runtime.logger.debug("bootstrap - LLM is off by default");
|
|
7368
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7369
|
-
runtime,
|
|
7370
|
-
runId,
|
|
7371
|
-
messageId: message.id,
|
|
7372
|
-
roomId: message.roomId,
|
|
7373
|
-
entityId: message.entityId,
|
|
7374
|
-
startTime,
|
|
7375
|
-
status: "off",
|
|
7376
|
-
endTime: Date.now(),
|
|
7377
|
-
duration: Date.now() - startTime,
|
|
7378
|
-
source: "messageHandler"
|
|
7379
|
-
});
|
|
7380
|
-
return;
|
|
7381
|
-
}
|
|
7382
|
-
if (agentUserState === "MUTED" && !message.content.text?.toLowerCase().includes(runtime.character.name.toLowerCase())) {
|
|
7383
|
-
runtime.logger.debug(`[Bootstrap] Ignoring muted room ${message.roomId}`);
|
|
7384
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7385
|
-
runtime,
|
|
7386
|
-
runId,
|
|
7387
|
-
messageId: message.id,
|
|
7388
|
-
roomId: message.roomId,
|
|
7389
|
-
entityId: message.entityId,
|
|
7390
|
-
startTime,
|
|
7391
|
-
status: "muted",
|
|
7392
|
-
endTime: Date.now(),
|
|
7393
|
-
duration: Date.now() - startTime,
|
|
7394
|
-
source: "messageHandler"
|
|
7395
|
-
});
|
|
7396
|
-
return;
|
|
7397
|
-
}
|
|
7398
|
-
let state = await runtime.composeState(message, ["ANXIETY", "ENTITIES", "CHARACTER", "RECENT_MESSAGES", "ACTIONS"], true);
|
|
7399
|
-
const mentionContext = message.content.mentionContext;
|
|
7400
|
-
const room = await runtime.getRoom(message.roomId);
|
|
7401
|
-
if (message.content.attachments && message.content.attachments.length > 0) {
|
|
7402
|
-
message.content.attachments = await processAttachments(message.content.attachments, runtime);
|
|
7403
|
-
if (message.id) {
|
|
7404
|
-
await runtime.updateMemory({ id: message.id, content: message.content });
|
|
7405
|
-
}
|
|
7406
|
-
}
|
|
7407
|
-
const responseDecision = shouldRespond(runtime, message, room ?? undefined, mentionContext);
|
|
7408
|
-
runtime.logger.debug(`[Bootstrap] Response decision: ${JSON.stringify(responseDecision)}`);
|
|
7409
|
-
let shouldRespondToMessage = true;
|
|
7410
|
-
if (responseDecision.skipEvaluation) {
|
|
7411
|
-
runtime.logger.debug(`[Bootstrap] Skipping evaluation for ${runtime.character.name} (${responseDecision.reason})`);
|
|
7412
|
-
shouldRespondToMessage = responseDecision.shouldRespond;
|
|
7413
|
-
} else {
|
|
7414
|
-
const shouldRespondPrompt = composePromptFromState10({
|
|
7415
|
-
state,
|
|
7416
|
-
template: runtime.character.templates?.shouldRespondTemplate || shouldRespondTemplate
|
|
7417
|
-
});
|
|
7418
|
-
runtime.logger.debug(`[Bootstrap] Using LLM evaluation for ${runtime.character.name} (${responseDecision.reason})`);
|
|
7419
|
-
const response = await runtime.useModel(ModelType15.TEXT_SMALL, {
|
|
7420
|
-
prompt: shouldRespondPrompt
|
|
7421
|
-
});
|
|
7422
|
-
runtime.logger.debug(`[Bootstrap] LLM evaluation result:
|
|
7423
|
-
${response}`);
|
|
7424
|
-
const responseObject = parseKeyValueXml9(response);
|
|
7425
|
-
runtime.logger.debug({ responseObject }, "[Bootstrap] Parsed evaluation result:");
|
|
7426
|
-
const nonResponseActions = ["IGNORE", "NONE"];
|
|
7427
|
-
shouldRespondToMessage = responseObject?.action && !nonResponseActions.includes(responseObject.action.toUpperCase());
|
|
7428
|
-
}
|
|
7429
|
-
let responseContent = null;
|
|
7430
|
-
let responseMessages = [];
|
|
7431
|
-
const keepResp = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_KEEP_RESP"));
|
|
7432
|
-
if (shouldRespondToMessage) {
|
|
7433
|
-
const result = useMultiStep ? await runMultiStepCore({ runtime, message, state, callback }) : await runSingleShotCore({ runtime, message, state });
|
|
7434
|
-
responseContent = result.responseContent;
|
|
7435
|
-
responseMessages = result.responseMessages;
|
|
7436
|
-
state = result.state;
|
|
7437
|
-
const currentResponseId = agentResponses.get(message.roomId);
|
|
7438
|
-
if (currentResponseId !== responseId && !keepResp) {
|
|
7439
|
-
runtime.logger.info(`Response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`);
|
|
7440
|
-
return;
|
|
7441
|
-
}
|
|
7442
|
-
if (responseContent && message.id) {
|
|
7443
|
-
responseContent.inReplyTo = createUniqueUuid3(runtime, message.id);
|
|
7444
|
-
}
|
|
7445
|
-
if (responseContent?.providers?.length && responseContent.providers.length > 0) {
|
|
7446
|
-
state = await runtime.composeState(message, responseContent.providers || []);
|
|
7447
|
-
}
|
|
7448
|
-
if (responseContent) {
|
|
7449
|
-
const mode = result.mode ?? "actions";
|
|
7450
|
-
if (mode === "simple") {
|
|
7451
|
-
if (responseContent.providers && responseContent.providers.length > 0) {
|
|
7452
|
-
runtime.logger.debug({ providers: responseContent.providers }, "[Bootstrap] Simple response used providers");
|
|
7453
|
-
}
|
|
7454
|
-
if (callback) {
|
|
7455
|
-
await callback(responseContent);
|
|
7456
|
-
}
|
|
7457
|
-
} else if (mode === "actions") {
|
|
7458
|
-
await runtime.processActions(message, responseMessages, state, async (content) => {
|
|
7459
|
-
runtime.logger.debug({ content }, "action callback");
|
|
7460
|
-
responseContent.actionCallbacks = content;
|
|
7461
|
-
if (callback) {
|
|
7462
|
-
return callback(content);
|
|
7463
|
-
}
|
|
7464
|
-
return [];
|
|
7465
|
-
});
|
|
7466
|
-
}
|
|
7467
|
-
}
|
|
7468
|
-
} else {
|
|
7469
|
-
runtime.logger.debug("[Bootstrap] Agent decided not to respond (shouldRespond is false).");
|
|
7470
|
-
const currentResponseId = agentResponses.get(message.roomId);
|
|
7471
|
-
if (currentResponseId !== responseId && !keepResp) {
|
|
7472
|
-
runtime.logger.info(`Ignore response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`);
|
|
7473
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7474
|
-
runtime,
|
|
7475
|
-
runId,
|
|
7476
|
-
messageId: message.id,
|
|
7477
|
-
roomId: message.roomId,
|
|
7478
|
-
entityId: message.entityId,
|
|
7479
|
-
startTime,
|
|
7480
|
-
status: "replaced",
|
|
7481
|
-
endTime: Date.now(),
|
|
7482
|
-
duration: Date.now() - startTime,
|
|
7483
|
-
source: "messageHandler"
|
|
7484
|
-
});
|
|
7485
|
-
return;
|
|
7486
|
-
}
|
|
7487
|
-
if (!message.id) {
|
|
7488
|
-
runtime.logger.error("[Bootstrap] Message ID is missing, cannot create ignore response.");
|
|
7489
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7490
|
-
runtime,
|
|
7491
|
-
runId,
|
|
7492
|
-
messageId: message.id,
|
|
7493
|
-
roomId: message.roomId,
|
|
7494
|
-
entityId: message.entityId,
|
|
7495
|
-
startTime,
|
|
7496
|
-
status: "noMessageId",
|
|
7497
|
-
endTime: Date.now(),
|
|
7498
|
-
duration: Date.now() - startTime,
|
|
7499
|
-
source: "messageHandler"
|
|
7500
|
-
});
|
|
7501
|
-
return;
|
|
7502
|
-
}
|
|
7503
|
-
const ignoreContent = {
|
|
7504
|
-
thought: "Agent decided not to respond to this message.",
|
|
7505
|
-
actions: ["IGNORE"],
|
|
7506
|
-
simple: true,
|
|
7507
|
-
inReplyTo: createUniqueUuid3(runtime, message.id)
|
|
7508
|
-
};
|
|
7509
|
-
if (callback) {
|
|
7510
|
-
await callback(ignoreContent);
|
|
7511
|
-
}
|
|
7512
|
-
const ignoreMemory = {
|
|
7513
|
-
id: asUUID2(v4_default()),
|
|
7514
|
-
entityId: runtime.agentId,
|
|
7515
|
-
agentId: runtime.agentId,
|
|
7516
|
-
content: ignoreContent,
|
|
7517
|
-
roomId: message.roomId,
|
|
7518
|
-
createdAt: Date.now()
|
|
7519
|
-
};
|
|
7520
|
-
await runtime.createMemory(ignoreMemory, "messages");
|
|
7521
|
-
runtime.logger.debug("[Bootstrap] Saved ignore response to memory", `memoryId: ${ignoreMemory.id}`);
|
|
7522
|
-
}
|
|
7523
|
-
agentResponses.delete(message.roomId);
|
|
7524
|
-
if (agentResponses.size === 0) {
|
|
7525
|
-
latestResponseIds.delete(runtime.agentId);
|
|
7526
|
-
}
|
|
7527
|
-
await runtime.evaluate(message, state, shouldRespondToMessage, async (content) => {
|
|
7528
|
-
runtime.logger.debug({ content }, "evaluate callback");
|
|
7529
|
-
if (responseContent) {
|
|
7530
|
-
responseContent.evalCallbacks = content;
|
|
7531
|
-
}
|
|
7532
|
-
if (callback) {
|
|
7533
|
-
return callback(content);
|
|
7534
|
-
}
|
|
7535
|
-
return [];
|
|
7536
|
-
}, responseMessages);
|
|
7537
|
-
let entityName = "noname";
|
|
7538
|
-
if (message.metadata && "entityName" in message.metadata) {
|
|
7539
|
-
entityName = message.metadata.entityName;
|
|
7540
|
-
}
|
|
7541
|
-
const isDM = message.content?.channelType === ChannelType9.DM;
|
|
7542
|
-
let roomName = entityName;
|
|
7543
|
-
if (!isDM) {
|
|
7544
|
-
const roomDatas = await runtime.getRoomsByIds([message.roomId]);
|
|
7545
|
-
if (roomDatas?.length) {
|
|
7546
|
-
const roomData = roomDatas[0];
|
|
7547
|
-
if (roomData.name) {
|
|
7548
|
-
roomName = roomData.name;
|
|
7549
|
-
}
|
|
7550
|
-
if (roomData.worldId) {
|
|
7551
|
-
const worldData = await runtime.getWorld(roomData.worldId);
|
|
7552
|
-
if (worldData) {
|
|
7553
|
-
roomName = worldData.name + "-" + roomName;
|
|
7554
|
-
}
|
|
7555
|
-
}
|
|
7556
|
-
}
|
|
7557
|
-
}
|
|
7558
|
-
const date = new Date;
|
|
7559
|
-
const availableActions = state.data?.providers?.ACTIONS?.data?.actionsData?.map((a) => a.name) || [-1];
|
|
7560
|
-
const logData = {
|
|
7561
|
-
at: date.toString(),
|
|
7562
|
-
timestamp: parseInt("" + date.getTime() / 1000),
|
|
7563
|
-
messageId: message.id,
|
|
7564
|
-
userEntityId: message.entityId,
|
|
7565
|
-
input: message.content.text,
|
|
7566
|
-
thought: responseContent?.thought,
|
|
7567
|
-
simple: responseContent?.simple,
|
|
7568
|
-
availableActions,
|
|
7569
|
-
actions: responseContent?.actions,
|
|
7570
|
-
providers: responseContent?.providers,
|
|
7571
|
-
irt: responseContent?.inReplyTo,
|
|
7572
|
-
output: responseContent?.text,
|
|
7573
|
-
entityName,
|
|
7574
|
-
source: message.content.source,
|
|
7575
|
-
channelType: message.content.channelType,
|
|
7576
|
-
roomName
|
|
7577
|
-
};
|
|
7578
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7579
|
-
runtime,
|
|
7580
|
-
runId,
|
|
7581
|
-
messageId: message.id,
|
|
7582
|
-
roomId: message.roomId,
|
|
7583
|
-
entityId: message.entityId,
|
|
7584
|
-
startTime,
|
|
7585
|
-
status: "completed",
|
|
7586
|
-
endTime: Date.now(),
|
|
7587
|
-
duration: Date.now() - startTime,
|
|
7588
|
-
source: "messageHandler",
|
|
7589
|
-
entityName,
|
|
7590
|
-
responseContent,
|
|
7591
|
-
metadata: logData
|
|
7592
|
-
});
|
|
7593
|
-
} catch (error) {
|
|
7594
|
-
console.error("error is", error);
|
|
7595
|
-
await runtime.emitEvent(EventType2.RUN_ENDED, {
|
|
7596
|
-
runtime,
|
|
7597
|
-
runId,
|
|
7598
|
-
messageId: message.id,
|
|
7599
|
-
roomId: message.roomId,
|
|
7600
|
-
entityId: message.entityId,
|
|
7601
|
-
startTime,
|
|
7602
|
-
status: "error",
|
|
7603
|
-
endTime: Date.now(),
|
|
7604
|
-
duration: Date.now() - startTime,
|
|
7605
|
-
error: error.message,
|
|
7606
|
-
source: "messageHandler"
|
|
7607
|
-
});
|
|
7608
|
-
}
|
|
7609
|
-
})();
|
|
7610
|
-
await Promise.race([processingPromise, timeoutPromise]);
|
|
7611
|
-
} finally {
|
|
7612
|
-
clearTimeout(timeoutId);
|
|
7613
|
-
onComplete?.();
|
|
7614
|
-
}
|
|
7615
|
-
};
|
|
7616
|
-
async function runSingleShotCore({ runtime, message, state }) {
|
|
7617
|
-
state = await runtime.composeState(message, ["ACTIONS"]);
|
|
7618
|
-
if (!state.values?.actionNames) {
|
|
7619
|
-
runtime.logger.warn("actionNames data missing from state, even though it was requested");
|
|
7620
|
-
}
|
|
7621
|
-
const prompt = composePromptFromState10({
|
|
7622
|
-
state,
|
|
7623
|
-
template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
|
|
7624
|
-
});
|
|
7625
|
-
let responseContent = null;
|
|
7626
|
-
let retries = 0;
|
|
7627
|
-
const maxRetries = 3;
|
|
7628
|
-
while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
|
|
7629
|
-
const response = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt });
|
|
7630
|
-
runtime.logger.debug({ response }, "[Bootstrap] *** Raw LLM Response ***");
|
|
7631
|
-
const parsedXml = parseKeyValueXml9(response);
|
|
7632
|
-
runtime.logger.debug({ parsedXml }, "[Bootstrap] *** Parsed XML Content ***");
|
|
7633
|
-
if (parsedXml) {
|
|
7634
|
-
responseContent = {
|
|
7635
|
-
...parsedXml,
|
|
7636
|
-
thought: parsedXml.thought || "",
|
|
7637
|
-
actions: parsedXml.actions || ["IGNORE"],
|
|
7638
|
-
providers: parsedXml.providers || [],
|
|
7639
|
-
text: parsedXml.text || "",
|
|
7640
|
-
simple: parsedXml.simple || false
|
|
7641
|
-
};
|
|
7642
|
-
} else {
|
|
7643
|
-
responseContent = null;
|
|
7644
|
-
}
|
|
7645
|
-
retries++;
|
|
7646
|
-
if (!responseContent?.thought || !responseContent?.actions) {
|
|
7647
|
-
runtime.logger.warn({ response, parsedXml, responseContent }, "[Bootstrap] *** Missing required fields (thought or actions), retrying... ***");
|
|
7648
|
-
}
|
|
7649
|
-
}
|
|
7650
|
-
if (!responseContent) {
|
|
7651
|
-
return { responseContent: null, responseMessages: [], state, mode: "none" };
|
|
7652
|
-
}
|
|
7653
|
-
if (responseContent.actions && responseContent.actions.length > 1) {
|
|
7654
|
-
const isIgnore = (a) => typeof a === "string" && a.toUpperCase() === "IGNORE";
|
|
7655
|
-
const hasIgnore = responseContent.actions.some(isIgnore);
|
|
7656
|
-
if (hasIgnore) {
|
|
7657
|
-
if (!responseContent.text || responseContent.text.trim() === "") {
|
|
7658
|
-
responseContent.actions = ["IGNORE"];
|
|
7659
|
-
} else {
|
|
7660
|
-
const filtered = responseContent.actions.filter((a) => !isIgnore(a));
|
|
7661
|
-
responseContent.actions = filtered.length ? filtered : ["REPLY"];
|
|
7662
|
-
}
|
|
7663
|
-
}
|
|
7664
|
-
}
|
|
7665
|
-
const isSimple = responseContent.actions?.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
|
|
7666
|
-
responseContent.simple = isSimple;
|
|
7667
|
-
const responseMessages = [
|
|
7668
|
-
{
|
|
7669
|
-
id: asUUID2(v4_default()),
|
|
7670
|
-
entityId: runtime.agentId,
|
|
7671
|
-
agentId: runtime.agentId,
|
|
7672
|
-
content: responseContent,
|
|
7673
|
-
roomId: message.roomId,
|
|
7674
|
-
createdAt: Date.now()
|
|
7675
|
-
}
|
|
7676
|
-
];
|
|
7677
|
-
return {
|
|
7678
|
-
responseContent,
|
|
7679
|
-
responseMessages,
|
|
7680
|
-
state,
|
|
7681
|
-
mode: isSimple && responseContent.text ? "simple" : "actions"
|
|
7682
|
-
};
|
|
7683
|
-
}
|
|
7684
|
-
async function runMultiStepCore({ runtime, message, state, callback }) {
|
|
7685
|
-
const traceActionResult = [];
|
|
7686
|
-
let accumulatedState = state;
|
|
7687
|
-
const maxIterations = parseInt(runtime.getSetting("MAX_MULTISTEP_ITERATIONS") || "6");
|
|
7688
|
-
let iterationCount = 0;
|
|
7689
|
-
while (iterationCount < maxIterations) {
|
|
7690
|
-
iterationCount++;
|
|
7691
|
-
runtime.logger.debug(`[MultiStep] Starting iteration ${iterationCount}/${maxIterations}`);
|
|
7692
|
-
accumulatedState = await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE"]);
|
|
7693
|
-
accumulatedState.data.actionResults = traceActionResult;
|
|
7694
|
-
const prompt = composePromptFromState10({
|
|
7695
|
-
state: accumulatedState,
|
|
7696
|
-
template: runtime.character.templates?.multiStepDecisionTemplate || multiStepDecisionTemplate
|
|
7697
|
-
});
|
|
7698
|
-
const stepResultRaw = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt });
|
|
7699
|
-
const parsedStep = parseKeyValueXml9(stepResultRaw);
|
|
7700
|
-
if (!parsedStep) {
|
|
7701
|
-
runtime.logger.warn(`[MultiStep] Failed to parse step result at iteration ${iterationCount}`);
|
|
7702
|
-
traceActionResult.push({
|
|
7703
|
-
data: { actionName: "parse_error" },
|
|
7704
|
-
success: false,
|
|
7705
|
-
error: "Failed to parse step result"
|
|
7706
|
-
});
|
|
7707
|
-
break;
|
|
7708
|
-
}
|
|
7709
|
-
const { thought, providers: providers2 = [], action, isFinish } = parsedStep;
|
|
7710
|
-
if (isFinish === "true" || isFinish === true) {
|
|
7711
|
-
runtime.logger.info(`[MultiStep] Task marked as complete at iteration ${iterationCount}`);
|
|
7712
|
-
if (callback) {
|
|
7713
|
-
await callback({
|
|
7714
|
-
text: "",
|
|
7715
|
-
thought: thought ?? ""
|
|
7716
|
-
});
|
|
7717
|
-
}
|
|
7718
|
-
break;
|
|
7719
|
-
}
|
|
7720
|
-
if ((!providers2 || providers2.length === 0) && !action) {
|
|
7721
|
-
runtime.logger.warn(`[MultiStep] No providers or action specified at iteration ${iterationCount}, forcing completion`);
|
|
7722
|
-
break;
|
|
7723
|
-
}
|
|
7724
|
-
try {
|
|
7725
|
-
for (const providerName of providers2) {
|
|
7726
|
-
const provider = runtime.providers.find((p) => p.name === providerName);
|
|
7727
|
-
if (!provider) {
|
|
7728
|
-
runtime.logger.warn(`[MultiStep] Provider not found: ${providerName}`);
|
|
7729
|
-
traceActionResult.push({
|
|
7730
|
-
data: { actionName: providerName },
|
|
7731
|
-
success: false,
|
|
7732
|
-
error: `Provider not found: ${providerName}`
|
|
7733
|
-
});
|
|
7734
|
-
continue;
|
|
7735
|
-
}
|
|
7736
|
-
const providerResult = await provider.get(runtime, message, state);
|
|
7737
|
-
if (!providerResult) {
|
|
7738
|
-
runtime.logger.warn(`[MultiStep] Provider returned no result: ${providerName}`);
|
|
7739
|
-
traceActionResult.push({
|
|
7740
|
-
data: { actionName: providerName },
|
|
7741
|
-
success: false,
|
|
7742
|
-
error: `Provider returned no result`
|
|
7743
|
-
});
|
|
7744
|
-
continue;
|
|
7745
|
-
}
|
|
7746
|
-
const success = !!providerResult.text;
|
|
7747
|
-
traceActionResult.push({
|
|
7748
|
-
data: { actionName: providerName },
|
|
7749
|
-
success,
|
|
7750
|
-
text: success ? providerResult.text : undefined,
|
|
7751
|
-
error: success ? undefined : providerResult?.text
|
|
7752
|
-
});
|
|
7753
|
-
if (callback) {
|
|
7754
|
-
await callback({
|
|
7755
|
-
text: `\uD83D\uDD0E Provider executed: ${providerName}`,
|
|
7756
|
-
actions: [providerName],
|
|
7757
|
-
thought: thought ?? ""
|
|
7758
|
-
});
|
|
7759
|
-
}
|
|
7760
|
-
}
|
|
7761
|
-
if (action) {
|
|
7762
|
-
const actionContent = {
|
|
7763
|
-
text: `\uD83D\uDD0E Executing action: ${action}`,
|
|
7764
|
-
actions: [action],
|
|
7765
|
-
thought: thought ?? ""
|
|
7766
|
-
};
|
|
7767
|
-
await runtime.processActions(message, [
|
|
7768
|
-
{
|
|
7769
|
-
id: v4_default(),
|
|
7770
|
-
entityId: runtime.agentId,
|
|
7771
|
-
roomId: message.roomId,
|
|
7772
|
-
createdAt: Date.now(),
|
|
7773
|
-
content: actionContent
|
|
7774
|
-
}
|
|
7775
|
-
], state, async () => {
|
|
7776
|
-
return [];
|
|
7777
|
-
});
|
|
7778
|
-
const cachedState = runtime.stateCache.get(`${message.id}_action_results`);
|
|
7779
|
-
const actionResults = cachedState?.values?.actionResults || [];
|
|
7780
|
-
const result = actionResults.length > 0 ? actionResults[0] : null;
|
|
7781
|
-
const success = result?.success ?? false;
|
|
7782
|
-
traceActionResult.push({
|
|
7783
|
-
data: { actionName: action },
|
|
7784
|
-
success,
|
|
7785
|
-
text: result?.text,
|
|
7786
|
-
values: result?.values,
|
|
7787
|
-
error: success ? undefined : result?.text
|
|
7788
|
-
});
|
|
7789
|
-
}
|
|
7790
|
-
} catch (err) {
|
|
7791
|
-
runtime.logger.error({ err }, "[MultiStep] Error executing step");
|
|
7792
|
-
traceActionResult.push({
|
|
7793
|
-
data: { actionName: action || "unknown" },
|
|
7794
|
-
success: false,
|
|
7795
|
-
error: err instanceof Error ? err.message : String(err)
|
|
7796
|
-
});
|
|
7797
|
-
}
|
|
7798
|
-
}
|
|
7799
|
-
if (iterationCount >= maxIterations) {
|
|
7800
|
-
runtime.logger.warn(`[MultiStep] Reached maximum iterations (${maxIterations}), forcing completion`);
|
|
7801
|
-
}
|
|
7802
|
-
accumulatedState = await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE"]);
|
|
7803
|
-
const summaryPrompt = composePromptFromState10({
|
|
7804
|
-
state: accumulatedState,
|
|
7805
|
-
template: runtime.character.templates?.multiStepSummaryTemplate || multiStepSummaryTemplate
|
|
7806
|
-
});
|
|
7807
|
-
const finalOutput = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt: summaryPrompt });
|
|
7808
|
-
const summary = parseKeyValueXml9(finalOutput);
|
|
7809
|
-
let responseContent = null;
|
|
7810
|
-
if (summary?.text) {
|
|
7811
|
-
responseContent = {
|
|
7812
|
-
actions: ["MULTI_STEP_SUMMARY"],
|
|
7813
|
-
text: summary.text,
|
|
7814
|
-
thought: summary.thought || "Final user-facing message after task completion.",
|
|
7815
|
-
simple: true
|
|
7816
|
-
};
|
|
7817
|
-
}
|
|
7818
|
-
const responseMessages = responseContent ? [
|
|
7819
|
-
{
|
|
7820
|
-
id: asUUID2(v4_default()),
|
|
7821
|
-
entityId: runtime.agentId,
|
|
7822
|
-
agentId: runtime.agentId,
|
|
7823
|
-
content: responseContent,
|
|
7824
|
-
roomId: message.roomId,
|
|
7825
|
-
createdAt: Date.now()
|
|
7826
|
-
}
|
|
7827
|
-
] : [];
|
|
7828
|
-
return {
|
|
7829
|
-
responseContent,
|
|
7830
|
-
responseMessages,
|
|
7831
|
-
state: accumulatedState,
|
|
7832
|
-
mode: responseContent ? "simple" : "none"
|
|
7833
|
-
};
|
|
7834
|
-
}
|
|
7835
7306
|
var reactionReceivedHandler = async ({
|
|
7836
7307
|
runtime,
|
|
7837
7308
|
message
|
|
@@ -7846,50 +7317,6 @@ var reactionReceivedHandler = async ({
|
|
|
7846
7317
|
runtime.logger.error({ error }, "[Bootstrap] Error in reaction handler:");
|
|
7847
7318
|
}
|
|
7848
7319
|
};
|
|
7849
|
-
var messageDeletedHandler = async ({
|
|
7850
|
-
runtime,
|
|
7851
|
-
message
|
|
7852
|
-
}) => {
|
|
7853
|
-
try {
|
|
7854
|
-
if (!message.id) {
|
|
7855
|
-
runtime.logger.error("[Bootstrap] Cannot delete memory: message ID is missing");
|
|
7856
|
-
return;
|
|
7857
|
-
}
|
|
7858
|
-
runtime.logger.info("[Bootstrap] Deleting memory for message", message.id, "from room", message.roomId);
|
|
7859
|
-
await runtime.deleteMemory(message.id);
|
|
7860
|
-
runtime.logger.debug({ messageId: message.id }, "[Bootstrap] Successfully deleted memory for message");
|
|
7861
|
-
} catch (error) {
|
|
7862
|
-
runtime.logger.error({ error }, "[Bootstrap] Error in message deleted handler:");
|
|
7863
|
-
}
|
|
7864
|
-
};
|
|
7865
|
-
var channelClearedHandler = async ({
|
|
7866
|
-
runtime,
|
|
7867
|
-
roomId,
|
|
7868
|
-
channelId,
|
|
7869
|
-
memoryCount
|
|
7870
|
-
}) => {
|
|
7871
|
-
try {
|
|
7872
|
-
runtime.logger.info(`[Bootstrap] Clearing ${memoryCount} message memories from channel ${channelId} -> room ${roomId}`);
|
|
7873
|
-
const memories = await runtime.getMemoriesByRoomIds({
|
|
7874
|
-
tableName: "messages",
|
|
7875
|
-
roomIds: [roomId]
|
|
7876
|
-
});
|
|
7877
|
-
let deletedCount = 0;
|
|
7878
|
-
for (const memory of memories) {
|
|
7879
|
-
if (memory.id) {
|
|
7880
|
-
try {
|
|
7881
|
-
await runtime.deleteMemory(memory.id);
|
|
7882
|
-
deletedCount++;
|
|
7883
|
-
} catch (error) {
|
|
7884
|
-
runtime.logger.warn({ error, memoryId: memory.id }, `[Bootstrap] Failed to delete message memory ${memory.id}:`);
|
|
7885
|
-
}
|
|
7886
|
-
}
|
|
7887
|
-
}
|
|
7888
|
-
runtime.logger.info(`[Bootstrap] Successfully cleared ${deletedCount}/${memories.length} message memories from channel ${channelId}`);
|
|
7889
|
-
} catch (error) {
|
|
7890
|
-
runtime.logger.error({ error }, "[Bootstrap] Error in channel cleared handler:");
|
|
7891
|
-
}
|
|
7892
|
-
};
|
|
7893
7320
|
var postGeneratedHandler = async ({
|
|
7894
7321
|
runtime,
|
|
7895
7322
|
callback,
|
|
@@ -8131,24 +7558,6 @@ var controlMessageHandler = async ({
|
|
|
8131
7558
|
}
|
|
8132
7559
|
};
|
|
8133
7560
|
var events = {
|
|
8134
|
-
[EventType2.MESSAGE_RECEIVED]: [
|
|
8135
|
-
async (payload) => {
|
|
8136
|
-
if (!payload.callback) {
|
|
8137
|
-
payload.runtime.logger.error("No callback provided for message");
|
|
8138
|
-
return;
|
|
8139
|
-
}
|
|
8140
|
-
await messageReceivedHandler(payload);
|
|
8141
|
-
}
|
|
8142
|
-
],
|
|
8143
|
-
[EventType2.VOICE_MESSAGE_RECEIVED]: [
|
|
8144
|
-
async (payload) => {
|
|
8145
|
-
if (!payload.callback) {
|
|
8146
|
-
payload.runtime.logger.error("No callback provided for voice message");
|
|
8147
|
-
return;
|
|
8148
|
-
}
|
|
8149
|
-
await messageReceivedHandler(payload);
|
|
8150
|
-
}
|
|
8151
|
-
],
|
|
8152
7561
|
[EventType2.REACTION_RECEIVED]: [
|
|
8153
7562
|
async (payload) => {
|
|
8154
7563
|
await reactionReceivedHandler(payload);
|
|
@@ -8164,21 +7573,6 @@ var events = {
|
|
|
8164
7573
|
payload.runtime.logger.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
|
|
8165
7574
|
}
|
|
8166
7575
|
],
|
|
8167
|
-
[EventType2.MESSAGE_DELETED]: [
|
|
8168
|
-
async (payload) => {
|
|
8169
|
-
await messageDeletedHandler(payload);
|
|
8170
|
-
}
|
|
8171
|
-
],
|
|
8172
|
-
[EventType2.CHANNEL_CLEARED]: [
|
|
8173
|
-
async (payload) => {
|
|
8174
|
-
await channelClearedHandler({
|
|
8175
|
-
runtime: payload.runtime,
|
|
8176
|
-
roomId: payload.roomId,
|
|
8177
|
-
channelId: payload.channelId,
|
|
8178
|
-
memoryCount: payload.memoryCount
|
|
8179
|
-
});
|
|
8180
|
-
}
|
|
8181
|
-
],
|
|
8182
7576
|
[EventType2.WORLD_JOINED]: [
|
|
8183
7577
|
async (payload) => {
|
|
8184
7578
|
await handleServerSync(payload);
|
|
@@ -8443,5 +7837,5 @@ export {
|
|
|
8443
7837
|
actionStateProvider
|
|
8444
7838
|
};
|
|
8445
7839
|
|
|
8446
|
-
//# debugId=
|
|
7840
|
+
//# debugId=AFB990BB999AB3A964756E2164756E21
|
|
8447
7841
|
//# sourceMappingURL=index.js.map
|